--- deliantra/server/server/spell_attack.C 2006/09/10 23:24:12 1.10 +++ deliantra/server/server/spell_attack.C 2006/12/13 00:42:04 1.18 @@ -1,10 +1,3 @@ - -/* - * static char *rcsid_spell_attack_c = - * "$Id: spell_attack.C,v 1.10 2006/09/10 23:24:12 root Exp $"; - */ - - /* CrossFire, A Multiplayer game for X-windows @@ -25,7 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - The authors can be reached via e-mail at crossfire-devel@real-time.com + The authors can be reached via e-mail at */ /* This file contains all the spell attack code. Grouping this code @@ -126,7 +119,7 @@ { int new_dir = 1; /* direction or -1 for left, +1 for right 0 if no new bolt */ int t_dir; /* stores temporary dir calculation */ - mapstruct *m; + maptile *m; sint16 sx, sy; object *new_bolt; @@ -149,8 +142,7 @@ return; /* OK, we made a fork */ - new_bolt = get_object (); - copy_object (tmp, new_bolt); + new_bolt = tmp->clone (); /* reduce chances of subsequent forking */ new_bolt->stats.Dex -= 10; @@ -179,14 +171,14 @@ object *tmp; int mflags; sint16 x, y; - mapstruct *m; + maptile *m; if (--(op->duration) < 0) { - remove_ob (op); - free_object (op); + op->destroy (); return; } + hit_map (op, 0, op->attacktype, 1); if (!op->direction) @@ -258,8 +250,8 @@ } else { /* Create a copy of this object and put it ahead */ - tmp = get_object (); - copy_object (op, tmp); + tmp = op->clone (); + tmp->speed_left = -0.1; tmp->x += DIRX (tmp), tmp->y += DIRY (tmp); tmp = insert_ob_in_map (tmp, op->map, op, 0); @@ -328,23 +320,27 @@ mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); if (mflags & P_OUT_OF_MAP) { - free_object (tmp); + tmp->destroy (); return 0; } + if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) { if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) { - free_object (tmp); + tmp->destroy (); return 0; } + tmp->x = op->x; tmp->y = op->y; tmp->direction = absdir (tmp->direction + 4); tmp->map = op->map; } + if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) move_bolt (tmp); + return 1; } @@ -364,15 +360,15 @@ explosion (object *op) { object *tmp; - mapstruct *m = op->map; + maptile *m = op->map; int i; if (--(op->duration) < 0) { - remove_ob (op); - free_object (op); + op->destroy (); return; } + hit_map (op, 0, op->attacktype, 0); if (op->range > 0) @@ -388,8 +384,7 @@ */ if (ok_to_put_more (op->map, dx, dy, op, op->attacktype)) { - tmp = get_object (); - copy_object (op, tmp); + tmp = op->clone (); tmp->state = 0; tmp->speed_left = -0.21; tmp->range--; @@ -410,14 +405,12 @@ void explode_bullet (object *op) { - tag_t op_tag = op->count; object *tmp, *owner; if (op->other_arch == NULL) { LOG (llevError, "BUG: explode_bullet(): op without other_arch\n"); - remove_ob (op); - free_object (op); + op->destroy (); return; } @@ -429,11 +422,11 @@ if (env->map == NULL || out_of_map (env->map, env->x, env->y)) { LOG (llevError, "BUG: explode_bullet(): env out of map\n"); - remove_ob (op); - free_object (op); + op->destroy (); return; } - remove_ob (op); + + op->remove (); op->x = env->x; op->y = env->y; insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON); @@ -441,8 +434,7 @@ else if (out_of_map (op->map, op->x, op->y)) { LOG (llevError, "BUG: explode_bullet(): op out of map\n"); - remove_ob (op); - free_object (op); + op->destroy (); return; } @@ -451,15 +443,14 @@ // bad at the moment that might happen from this. if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) { - remove_ob (op); - free_object (op); + op->destroy (); return; } if (op->attacktype) { hit_map (op, 0, op->attacktype, 1); - if (was_destroyed (op, op_tag)) + if (op->destroyed ()) return; } @@ -473,8 +464,7 @@ if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner)) { - remove_ob (op); - free_object (op); + op->destroy (); return; } @@ -512,10 +502,9 @@ insert_ob_in_map (tmp, op->map, op, 0); /* remove the firebullet */ - if (!was_destroyed (op, op_tag)) + if (!op->destroyed ()) { - remove_ob (op); - free_object (op); + op->destroy (); } } @@ -528,10 +517,9 @@ void check_bullet (object *op) { - tag_t op_tag = op->count, tmp_tag; object *tmp; int dam, mflags; - mapstruct *m; + maptile *m; sint16 sx, sy; mflags = get_map_flags (op->map, &m, op->x, op->y, &sx, &sy); @@ -554,14 +542,12 @@ { if (QUERY_FLAG (tmp, FLAG_ALIVE)) { - tmp_tag = tmp->count; dam = hit_player (tmp, op->stats.dam, op, op->attacktype, 1); - if (was_destroyed (op, op_tag) || !was_destroyed (tmp, tmp_tag) || (op->stats.dam -= dam) < 0) + if (op->destroyed () || !tmp->destroyed () || (op->stats.dam -= dam) < 0) { if (!QUERY_FLAG (op, FLAG_REMOVED)) { - remove_ob (op); - free_object (op); + op->destroy (); return; } } @@ -581,7 +567,7 @@ { sint16 new_x, new_y; int mflags; - mapstruct *m; + maptile *m; #if 0 /* We need a better general purpose way to do this */ @@ -591,7 +577,7 @@ if (op->stats.sp == SP_METEOR) { replace_insert_ob_in_map ("fire_trail", op); - if (was_destroyed (op, op_tag)) + if (op->destroyed ()) return; } /* end addition. */ #endif @@ -600,14 +586,10 @@ if (--op->range <= 0) { if (op->other_arch) - { - explode_bullet (op); - } + explode_bullet (op); else - { - remove_ob (op); - free_object (op); - } + op->destroy (); + return; } @@ -618,26 +600,21 @@ if (mflags & P_OUT_OF_MAP) { - remove_ob (op); - free_object (op); + op->destroy (); return; } if (!op->direction || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) { if (op->other_arch) - { - explode_bullet (op); - } + explode_bullet (op); else - { - remove_ob (op); - free_object (op); - } + op->destroy (); + return; } - remove_ob (op); + op->remove (); op->x = new_x; op->y = new_y; if ((op = insert_ob_in_map (op, m, op, 0)) == NULL) @@ -706,25 +683,27 @@ mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); if (mflags & P_OUT_OF_MAP) { - free_object (tmp); + tmp->destroy (); return 0; } + if (OB_TYPE_MOVE_BLOCK (tmp, GET_MAP_MOVE_BLOCK (tmp->map, tmp->x, tmp->y))) { if (!QUERY_FLAG (tmp, FLAG_REFLECTING)) { - free_object (tmp); + tmp->destroy (); return 0; } + tmp->x = op->x; tmp->y = op->y; tmp->direction = absdir (tmp->direction + 4); tmp->map = op->map; } + if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0)) != NULL) - { - check_bullet (tmp); - } + check_bullet (tmp); + return 1; } @@ -764,7 +743,6 @@ move_cone (object *op) { int i; - tag_t tag; /* if no map then hit_map will crash so just ignore object */ if (!op->map) @@ -789,13 +767,11 @@ /* If no owner left, the spell dies out. */ if (get_owner (op) == NULL) { - remove_ob (op); - free_object (op); + op->destroy (); return; } #endif - tag = op->count; hit_map (op, 0, op->attacktype, 0); /* Check to see if we should push anything. @@ -805,13 +781,12 @@ if (op->weight) check_spell_knockback (op); - if (was_destroyed (op, tag)) + if (op->destroyed ()) return; if ((op->duration--) < 0) { - remove_ob (op); - free_object (op); + op->destroy (); return; } /* Object has hit maximum range, so don't have it move @@ -830,9 +805,8 @@ if (ok_to_put_more (op->map, x, y, op, op->attacktype)) { - object *tmp = get_object (); + object *tmp = op->clone (); - copy_object (op, tmp); tmp->x = x; tmp->y = y; @@ -860,7 +834,7 @@ { object *tmp; int i, success = 0, range_min = -1, range_max = 1; - mapstruct *m; + maptile *m; sint16 sx, sy; MoveType movetype; @@ -1025,7 +999,7 @@ if (env->type == PLAYER) esrv_del_item (env->contr, op->count); - remove_ob (op); + op->remove (); op->x = env->x; op->y = env->y; if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL) @@ -1037,8 +1011,7 @@ // as bombs can be carried. if (get_map_flags (op->map, NULL, op->x, op->y, NULL, NULL) & P_SAFE) { - remove_ob (op); - free_object (op); + op->destroy (); return; } @@ -1046,7 +1019,7 @@ * but using the cast_bullet isn't really feasible, * so just set up the appropriate values. */ - at = find_archetype (SPLINT); + at = archetype::find (SPLINT); if (at) { for (i = 1; i < 9; i++) @@ -1083,7 +1056,7 @@ object *tmp; int mflags; sint16 dx = op->x + freearr_x[dir], dy = op->y + freearr_y[dir]; - mapstruct *m; + maptile *m; mflags = get_map_flags (op->map, &m, dx, dy, &dx, &dy); if ((mflags & P_OUT_OF_MAP) || (GET_MAP_MOVE_BLOCK (m, dx, dy) & MOVE_WALK)) @@ -1129,7 +1102,7 @@ object *target; sint16 x, y; int dist, mflags; - mapstruct *mp; + maptile *mp; if (dir == 0) return NULL; @@ -1242,7 +1215,7 @@ { new_draw_info_format (NDI_UNIQUE, 0, op, "The %s looks stronger!", query_name (target)); target->stats.hp = target->stats.maxhp * 2; - free_object (effect); + effect->destroy (); return 0; } } @@ -1279,12 +1252,11 @@ int i, mflags; object *owner; sint16 new_x, new_y; - mapstruct *m; + maptile *m; if (op->range-- <= 0) { - remove_ob (op); - free_object (op); + op->destroy (); return; } @@ -1295,8 +1267,7 @@ */ if (owner == NULL) { - remove_ob (op); - free_object (op); + op->destroy (); return; } #endif @@ -1308,26 +1279,24 @@ if (!(mflags & P_OUT_OF_MAP) && ((mflags & P_IS_ALIVE) || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y)))) { - tag_t tag = op->count; - hit_map (op, op->direction, AT_MAGIC, 1); /* Basically, missile only hits one thing then goes away. * we need to remove it if someone hasn't already done so. */ - if (!was_destroyed (op, tag)) - { - remove_ob (op); - free_object (op); - } + if (!op->destroyed ()) + op->destroy (); + return; } - remove_ob (op); + op->remove (); + if (!op->direction || (mflags & P_OUT_OF_MAP)) { - free_object (op); + op->destroy (); return; } + op->x = new_x; op->y = new_y; op->map = m; @@ -1337,6 +1306,7 @@ op->direction = i; SET_ANIMATION (op, op->direction); } + insert_ob_in_map (op, op->map, op, 0); } @@ -1392,7 +1362,7 @@ { int i, j, range, mflags, friendly = 0, dam, dur; sint16 sx, sy; - mapstruct *m; + maptile *m; object *tmp; const char *skill; @@ -1584,7 +1554,7 @@ object *tmp, *god, *head; int done_one, range, mflags, level, at, best_at; sint16 x, y, nx, ny; - mapstruct *m; + maptile *m; const char *race; /* We precompute some values here so that we don't have to keep @@ -1758,7 +1728,7 @@ int i, j, dam_save, dir, mflags; sint16 nx, ny, hx, hy; object *owner; - mapstruct *m; + maptile *m; owner = get_owner (op); @@ -1799,7 +1769,7 @@ m = op->map; } - remove_ob (op); + op->remove (); op->y = ny; op->x = nx; insert_ob_in_map (op, m, op, 0); @@ -1880,7 +1850,7 @@ static int diagonal_adjust[10] = { -3, -2, -2, -1, 0, 0, 1, 2, 2, 3 }; sint16 target_x, target_y, origin_x, origin_y; int adjustdir; - mapstruct *m; + maptile *m; #endif int basedir; object *owner; @@ -1888,10 +1858,10 @@ owner = get_owner (op); if (op->duration == 0 || owner == NULL) { - remove_ob (op); - free_object (op); + op->destroy (); return; } + op->duration--; basedir = op->direction; @@ -2033,7 +2003,7 @@ object *target = NULL, *tmp = NULL; sint16 x, y; int dam, mflags; - mapstruct *m; + maptile *m; dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); @@ -2111,7 +2081,7 @@ sint16 x, y; int i, mflags, range, dam_mod, dur_mod; object *walk; - mapstruct *m; + maptile *m; x = op->x; y = op->y; @@ -2213,7 +2183,7 @@ new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name); - free_object (disease); /* don't need this one anymore */ + disease->destroy (); /* don't need this one anymore */ flash = get_archetype (ARCH_DETECT_MAGIC); flash->x = x; flash->y = y; @@ -2221,7 +2191,8 @@ insert_ob_in_map (flash, walk->map, op, 0); return 1; } - free_object (disease); + + disease->destroy (); } } /* if living creature */ } /* for range of spaces */