2 // nazghul - an old-school RPG engine
3 // Copyright (C) 2002, 2003 Gordon McNutt
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 2 of the License, or (at your option)
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 // Suite 330, Boston, MA 02111-1307 USA
20 // gmcnutt@users.sourceforge.net
25 #include "character.h"
37 MissileType::MissileType()
39 // Don't ever expect to call this. Defining it to override the default
40 // one c++ automatically creates.
46 MissileType::MissileType(const char *tag, const char *name, struct sprite *sprite, bool isBeam, bool isFixedRange, struct mmode *mmode)
47 : ObjectType(tag, name, sprite, item_layer),
49 fixedrange(isFixedRange)
51 setMovementMode(mmode);
54 MissileType::~MissileType()
56 //dont think theres anything here that needs cleaning up?
59 bool MissileType::isType(int classID)
61 if (classID == MISSILE_TYPE_ID)
63 return ObjectType::isType(classID);
66 int MissileType::getType()
68 return MISSILE_TYPE_ID;
71 bool MissileType::isBeam()
76 // A fixed range missile always fires to its maximum range (LOS allowing).
77 // target selection merely affects the angle it travels at
78 bool MissileType::isFixedRange()
83 void MissileType::fireHitLoc(Object *attacker, Object *target, struct place *place, int x, int y, int dam)
86 hitLocation(NULL, attacker, target, place, x, y, dam);
89 bool MissileType::fireEnterTile(Missile *missile, struct place *place, int x, int y)
91 if (closure_exec(gifc, "yppdd", "enter", missile, place, x, y))
101 Missile::Missile(MissileType* type)
111 class MissileType *Missile::getObjectType()
113 return (class MissileType *) Object::getObjectType();
116 /* set hit=true if a party or object has been struck
117 return true if the missile has not been interupted */
118 bool Missile::enterTile(struct place *place, int x, int y)
120 if (! (flags & MISSILE_IGNORE_LOS))
122 int obstruction = place_get_movement_cost(place, x, y, this,0);
123 //int opacity = place_visibility(place, x, y);
124 return ((obstruction != 20) && (dice_roll_numeric(1,100,0)>obstruction));
127 if (! (flags & MISSILE_HIT_PARTY))
130 struck = place_get_Party(place, x, y);
132 if (struck != NULL) {
138 if (player_party->getPlace() == place &&
139 player_party->getX() == x &&
140 player_party->getY() == y) {
141 struck = player_party;
146 /* Allow wilderness-scale weapons to destroy empty vehicles. */
147 struck = place_get_vehicle(place, x, y);
148 if (struck != NULL) {
157 triggers a hit-loc ifc event if appropriate
159 void Missile::fireHitLoc(Object *attacker, Object *target, struct place *place, int x, int y, int dam)
161 if (getObjectType()->canHitLocation())
162 getObjectType()->hitLocation(this, attacker, target, place, x, y, dam);
166 Calculates & animates trajectory, returns true if the missile reached the target location
167 alters Bx, By to be where it reached (so you can tell where it wound up if blocked)
169 void Missile::animate(int Ax, int Ay, int *Bx, int *By, int _flags, float fixedrange)
178 struct sprite *tmpSprite = sprite_clone(getSprite(), 0);
179 mapAnimateProjectile(Ax, Ay, Bx, By, tmpSprite, getPlace(), this, fixedrange);
180 sprite_del(tmpSprite);
182 hit = (hit || (origBx == *Bx && origBy == *By));
185 bool Missile::hitTarget()
190 class Object * Missile::getStruck()