AmbushProcess.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2006 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "AmbushProcess.h"
00022 #include "MainActor.h"
00023 #include "CombatProcess.h"
00024 #include "getObject.h"
00025 
00026 #include "IDataSource.h"
00027 #include "ODataSource.h"
00028 
00029 // p_dynamic_cast stuff
00030 DEFINE_RUNTIME_CLASSTYPE_CODE(AmbushProcess,Process);
00031 
00032 AmbushProcess::AmbushProcess() : Process()
00033 {
00034 
00035 }
00036 
00037 AmbushProcess::AmbushProcess(Actor* actor_)
00038 {
00039         assert(actor_);
00040         item_num = actor_->getObjId();
00041         type = 0x21E; // CONSTANT !
00042 
00043         delaycount = 0;
00044 }
00045 
00046 bool AmbushProcess::run(const uint32 /*framenum*/)
00047 {
00048         if (delaycount > 0) {
00049                 delaycount--;
00050                 return false;
00051         }
00052         delaycount = 10;
00053 
00054         Actor *a = getActor(item_num);
00055         CombatProcess* cp = a->getCombatProcess();
00056         if (!cp) {
00057                 // this shouldn't have happened
00058                 terminate();
00059                 return false;
00060         }
00061 
00062         ObjId targetid = cp->seekTarget();
00063         Item* target = getItem(targetid);
00064 
00065         // no target in range yet, continue waiting
00066         if (!target || a->getRange(*target) > 192)
00067                 return false;
00068 
00069         // target in range, so terminate and let parent take over
00070         terminate();
00071 
00072         return false;
00073 }
00074 
00075 void AmbushProcess::saveData(ODataSource* ods)
00076 {
00077         Process::saveData(ods);
00078 
00079         ods->write4(delaycount);
00080 }
00081 
00082 bool AmbushProcess::loadData(IDataSource* ids, uint32 version)
00083 {
00084         if (!Process::loadData(ids, version)) return false;
00085 
00086         delaycount = ids->read4();
00087 
00088         return true;
00089 }

Generated on Fri Jul 27 22:27:09 2007 for pentagram by  doxygen 1.4.7