GrantPeaceProcess.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2004-2007 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 "GrantPeaceProcess.h"
00022 #include "World.h"
00023 #include "Actor.h"
00024 #include "CurrentMap.h"
00025 #include "TargetGump.h"
00026 #include "WeaponInfo.h"
00027 #include "PaletteFaderProcess.h"
00028 #include "UCList.h"
00029 #include "LoopScript.h"
00030 #include "Direction.h"
00031 #include "Kernel.h"
00032 #include "GumpNotifyProcess.h"
00033 #include "MainActor.h"
00034 #include "SpriteProcess.h"
00035 #include "AudioProcess.h"
00036 #include "getObject.h"
00037 
00038 #include "IDataSource.h"
00039 #include "ODataSource.h"
00040 
00041 // p_dynamic_cast stuff
00042 DEFINE_RUNTIME_CLASSTYPE_CODE(GrantPeaceProcess,Process);
00043 
00044 GrantPeaceProcess::GrantPeaceProcess() : Process()
00045 {
00046 
00047 }
00048 
00049 GrantPeaceProcess::GrantPeaceProcess(Actor* caster)
00050 {
00051         assert(caster);
00052         item_num = caster->getObjId();
00053 
00054         type = 0x21d; // CONSTANT !
00055 
00056         havetarget = false;
00057 }
00058 
00059 bool GrantPeaceProcess::run(const uint32 /*framenum*/)
00060 {
00061         Actor* caster = getActor(item_num);
00062         if (!caster) {
00063                 terminate();
00064                 return false;
00065         }
00066 
00067         if (!havetarget) {
00068                 TargetGump* targetgump = new TargetGump(0, 0);
00069                 targetgump->InitGump(0);
00070 
00071                 waitFor(targetgump->GetNotifyProcess()->getPid());
00072 
00073                 havetarget = true;
00074 
00075                 return false;
00076         }
00077 
00078         // get target result
00079         ObjId targetid = static_cast<ObjId>(result);
00080         Actor* target = getActor(targetid);
00081 
00082         if (targetid == 1 || !target ) {
00083                 // targeting the avatar, no target or not an Actor
00084                 terminate();
00085                 return false;
00086         }
00087 
00088         bool hit = false;
00089 
00090         if (target->getDefenseType() & WeaponInfo::DMG_UNDEAD) {
00091                 // undead
00092 
00093                 // first see if we're near Khumash-Gor
00094                 CurrentMap* currentmap = World::get_instance()->getCurrentMap();
00095                 UCList KGlist(2);
00096                 LOOPSCRIPT(script, LS_SHAPE_EQUAL(289));
00097                 currentmap->areaSearch(&KGlist, script, sizeof(script),
00098                                                            caster, 2048, false);
00099                 bool khumash = (KGlist.getSize() > 0);
00100 
00101                 // then find all the undead in the area
00102                 UCList itemlist(2);
00103                 LOOPSCRIPT(script2, LS_TOKEN_TRUE);
00104                 currentmap->areaSearch(&itemlist, script2, sizeof(script2),
00105                                                            caster, 768, false);
00106 
00107                 for (unsigned int i = 0; i < itemlist.getSize(); ++i) {
00108                         Actor *t = getActor(itemlist.getuint16(i));
00109                         if (!t) continue;
00110                         if (t == caster) continue;
00111 
00112                         if (t->isDead()) continue;
00113 
00114                         // undead?
00115                         if (t->getDefenseType() & WeaponInfo::DMG_UNDEAD) {
00116                                 t->receiveHit(item_num, 8, target->getHP(),
00117                                                           (WeaponInfo::DMG_MAGIC |
00118                                                            WeaponInfo::DMG_PIERCE |
00119                                                            WeaponInfo::DMG_FIRE));
00120                                 hit = true;
00121 
00122                                 if (t->getShape() == 411 && khumash) { // CONSTANT!
00123                                         sint32 tx,ty,tz;
00124                                         t->getLocation(tx,ty,tz);
00125 
00126                                         // CONSTANT! (shape 480, frame 0-9, repeat 1, delay 1)
00127                                         Process *sp = new SpriteProcess(480,0,9,1,1, tx, ty, tz);
00128                                         Kernel::get_instance()->addProcess(sp);
00129 
00130                                         Item* throne = getItem(KGlist.getuint16(0));
00131                                         if (throne) {
00132                                                 throne->setFrame(1); // CONSTANT!
00133                                         }
00134                                 }
00135 
00136 #if 0
00137                                 // FIXME: this seems to screw up the death animation; why?
00138 
00139                                 int dir = caster->getDirToItemCentre(*t);
00140 
00141                                 t->hurl(((std::rand() % 5) + 5) * x_fact[dir],
00142                                                 ((std::rand() % 5) + 5) * y_fact[dir],
00143                                                 ((std::rand() % 5) + 5),
00144                                                 4);
00145 #endif
00146                         }
00147 
00148                 }
00149 
00150         } else {
00151                 // not undead
00152 
00153                 if (!(target->getActorFlags() & (Actor::ACT_DEAD |
00154                                                                                  Actor::ACT_IMMORTAL |
00155                                                                                  Actor::ACT_INVINCIBLE)))
00156                 {
00157                         if (std::rand() % 10 == 0) {
00158                                 target->receiveHit(item_num, 8, target->getHP(),
00159                                                                    (WeaponInfo::DMG_MAGIC |
00160                                                                         WeaponInfo::DMG_PIERCE |
00161                                                                         WeaponInfo::DMG_FIRE));
00162                                 hit = true;
00163                         }
00164                 }
00165 
00166         }
00167 
00168 
00169         if (hit) {
00170                 // lightning
00171 
00172                 // calling intrinsic...
00173                 PaletteFaderProcess::I_lightningBolt(0, 0);
00174                 int sfx;
00175                 switch (std::rand() % 3) {
00176                 case 0: sfx = 91; break;
00177                 case 1: sfx = 94; break;
00178                 default: sfx = 96; break;
00179                 }
00180 
00181                 AudioProcess* audioproc = AudioProcess::get_instance();
00182                 if (audioproc) audioproc->playSFX(sfx, 0x60, 1, 0); //constants!!
00183         }
00184 
00185 
00186         // done
00187         terminate();
00188 
00189         return true;
00190 }
00191 
00192 uint32 GrantPeaceProcess::I_castGrantPeace(const uint8* args,
00193                                                                                    unsigned int /*argsize*/)
00194 {
00195         MainActor* avatar = getMainActor();
00196 
00197         GrantPeaceProcess* gpp = new GrantPeaceProcess(avatar);
00198         Kernel::get_instance()->addProcess(gpp);
00199 
00200         // start casting
00201         ProcId anim1 = avatar->doAnim(Animation::cast1, 8);
00202 
00203         // cast
00204         ProcId anim2 = avatar->doAnim(Animation::cast3, 8);
00205         Process* anim2p = Kernel::get_instance()->getProcess(anim2);
00206 
00207         // end casting
00208         ProcId anim3 = avatar->doAnim(Animation::cast2, 8);
00209         Process* anim3p = Kernel::get_instance()->getProcess(anim3);
00210 
00211         anim2p->waitFor(anim1);
00212         anim3p->waitFor(anim2);
00213         gpp->waitFor(anim2);
00214 
00215         return 0;
00216 }
00217 
00218 void GrantPeaceProcess::saveData(ODataSource* ods)
00219 {
00220         Process::saveData(ods);
00221 
00222         uint8 ht = havetarget ? 1 : 0;
00223         ods->write1(ht);
00224 }
00225 
00226 bool GrantPeaceProcess::loadData(IDataSource* ids, uint32 version)
00227 {
00228         if (!Process::loadData(ids, version)) return false;
00229 
00230         havetarget = (ids->read1() != 0);
00231 
00232         return true;
00233 }

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