00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020
00021 #include "LoiterProcess.h"
00022 #include "Actor.h"
00023 #include "PathfinderProcess.h"
00024 #include "Kernel.h"
00025 #include "DelayProcess.h"
00026 #include "getObject.h"
00027
00028 #include "IDataSource.h"
00029 #include "ODataSource.h"
00030
00031
00032 DEFINE_RUNTIME_CLASSTYPE_CODE(LoiterProcess,Process);
00033
00034 LoiterProcess::LoiterProcess() : Process()
00035 {
00036
00037 }
00038
00039 LoiterProcess::LoiterProcess(Actor* actor_, sint32 c)
00040 {
00041 assert(actor_);
00042 item_num = actor_->getObjId();
00043 count = c;
00044
00045 type = 0x205;
00046 }
00047
00048 bool LoiterProcess::run(const uint32 )
00049 {
00050 if (!count) {
00051 terminate();
00052 return false;
00053 }
00054 if (count > 0)
00055 count--;
00056
00057 Actor *a = getActor(item_num);
00058
00059 if (!a || a->isDead()) {
00060
00061 terminate();
00062 return false;
00063 }
00064
00065 sint32 x,y,z;
00066 a->getLocation(x,y,z);
00067
00068 x += 32 * ((std::rand() % 20) - 10);
00069 y += 32 * ((std::rand() % 20) - 10);
00070
00071 PathfinderProcess* pfp = new PathfinderProcess(a,x,y,z);
00072 Kernel::get_instance()->addProcess(pfp);
00073
00074 bool hasidle1 = a->hasAnim(Animation::idle1);
00075 bool hasidle2 = a->hasAnim(Animation::idle2);
00076
00077 if ((hasidle1 || hasidle2) && ((std::rand()%3) == 0))
00078 {
00079 Animation::Sequence idleanim;
00080
00081 if (!hasidle1) {
00082 idleanim = Animation::idle2;
00083 } else if (!hasidle2) {
00084 idleanim = Animation::idle1;
00085 } else {
00086 if (std::rand()%2)
00087 idleanim = Animation::idle1;
00088 else
00089 idleanim = Animation::idle2;
00090 }
00091 uint16 idlepid = a->doAnim(idleanim, 8);
00092 Process* idlep = Kernel::get_instance()->getProcess(idlepid);
00093 idlep->waitFor(pfp);
00094
00095 waitFor(idlep);
00096
00097 } else {
00098
00099 DelayProcess* dp = new DelayProcess(30 * (4 + (std::rand()%3)));
00100 Kernel::get_instance()->addProcess(dp);
00101 dp->waitFor(pfp);
00102
00103 waitFor(dp);
00104 }
00105
00106
00107 return false;
00108 }
00109
00110 void LoiterProcess::saveData(ODataSource* ods)
00111 {
00112 Process::saveData(ods);
00113
00114 ods->write4(count);
00115 }
00116
00117 bool LoiterProcess::loadData(IDataSource* ids, uint32 version)
00118 {
00119 if (!Process::loadData(ids, version)) return false;
00120
00121 if (version >= 3)
00122 count = ids->read4();
00123 else
00124 count = 0;
00125
00126 return true;
00127 }