--- deliantra/server/server/spell_attack.C 2006/09/10 23:24:12 1.10 +++ deliantra/server/server/spell_attack.C 2006/12/26 20:04:09 1.25 @@ -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 @@ -36,9 +29,7 @@ #include #include #include -#ifndef __CEXTRACT__ -# include -#endif +#include #include #include @@ -66,7 +57,7 @@ /*LOG (llevDebug, "DEBUG: arch weighs %d and masses %d (%s,level %d)\n", op->weight,weight_move,op->name,op->level); */ } - for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) + for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) { int num_sections = 1; @@ -126,7 +117,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 +140,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; @@ -159,14 +149,12 @@ new_bolt->speed_left = -0.1; new_bolt->direction = t_dir; new_bolt->duration++; - new_bolt->x = sx; - new_bolt->y = sy; new_bolt->stats.dam /= 2; /* reduce daughter bolt damage */ new_bolt->stats.dam++; tmp->stats.dam /= 2; /* reduce father bolt damage */ tmp->stats.dam++; - new_bolt = insert_ob_in_map (new_bolt, m, op, 0); - update_turn_face (new_bolt); + if ((new_bolt = m->insert (new_bolt, sx, sy, op))) + update_turn_face (new_bolt); } /* move_bolt: moves bolt 'op'. Basically, it just advances a space, @@ -179,23 +167,21 @@ object *tmp; int mflags; sint16 x, y; - mapstruct *m; + maptile *m; - if (--(op->duration) < 0) + if (--op->duration < 0) { - remove_ob (op); - free_object (op); + op->destroy (); return; } + hit_map (op, 0, op->attacktype, 1); if (!op->direction) return; if (--op->range < 0) - { - op->range = 0; - } + op->range = 0; else { x = op->x + DIRX (op); @@ -213,7 +199,6 @@ */ if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, x, y)) || ((mflags & P_IS_ALIVE) && reflwall (m, x, y, op))) { - if (!QUERY_FLAG (op, FLAG_REFLECTING)) return; @@ -253,27 +238,27 @@ else if (right) op->direction = absdir (op->direction - 2); } + update_turn_face (op); /* A bolt *must* be IS_TURNABLE */ return; } else { /* Create a copy of this object and put it ahead */ - tmp = get_object (); - copy_object (op, tmp); + object *tmp = op->clone (); + + m->insert (tmp, x, y, op); tmp->speed_left = -0.1; - tmp->x += DIRX (tmp), tmp->y += DIRY (tmp); - tmp = insert_ob_in_map (tmp, op->map, op, 0); /* To make up for the decrease at the top of the function */ tmp->duration++; /* New forking code. Possibly create forks of this object * going off in other directions. */ - if (rndm (0, 99) < tmp->stats.Dex) { /* stats.Dex % of forking */ forklightning (op, tmp); } + /* In this way, the object left behind sticks on the space, but * doesn't create any bolts that continue to move onward. */ @@ -290,7 +275,6 @@ * This function sets up the appropriate owner and skill * pointers. */ - int fire_bolt (object *op, object *caster, int dir, object *spob, object *skill) { @@ -318,33 +302,40 @@ if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) SET_ANIMATION (tmp, dir); - set_owner (tmp, op); + tmp->set_owner (op); set_spell_skill (op, caster, spob, tmp); tmp->x = op->x + DIRX (tmp); tmp->y = op->y + DIRY (tmp); tmp->map = op->map; - mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); + maptile *newmap; + mflags = get_map_flags (tmp->map, &newmap, tmp->x, tmp->y, &tmp->x, &tmp->y); if (mflags & P_OUT_OF_MAP) { - free_object (tmp); + tmp->destroy (); return 0; } + + tmp->map = newmap; + 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) + + if ((tmp = tmp->insert_at (tmp, op))) move_bolt (tmp); + return 1; } @@ -363,16 +354,15 @@ void explosion (object *op) { - object *tmp; - mapstruct *m = op->map; + maptile *m = op->map; int i; - if (--(op->duration) < 0) + if (--op->duration < 0) { - remove_ob (op); - free_object (op); + op->destroy (); return; } + hit_map (op, 0, op->attacktype, 0); if (op->range > 0) @@ -383,20 +373,20 @@ dx = op->x + freearr_x[i]; dy = op->y + freearr_y[i]; + /* ok_to_put_more already does things like checks for walls, * out of map, etc. */ if (ok_to_put_more (op->map, dx, dy, op, op->attacktype)) { - tmp = get_object (); - copy_object (op, tmp); + object *tmp = op->clone (); + tmp->state = 0; tmp->speed_left = -0.21; tmp->range--; tmp->value = 0; - tmp->x = dx; - tmp->y = dy; - insert_ob_in_map (tmp, m, op, 0); + + m->insert (tmp, dx, dy, op); } } } @@ -410,39 +400,31 @@ 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; } if (op->env) { - object *env; - - env = object_get_env_recursive (op); + object *env = object_get_env_recursive (op); 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->x = env->x; - op->y = env->y; - insert_ob_in_map (op, env->map, op, INS_NO_MERGE | INS_NO_WALK_ON); + + op->insert_at (env, op, INS_NO_MERGE | INS_NO_WALK_ON); } 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,36 +433,31 @@ // 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; } /* other_arch contains what this explodes into */ tmp = arch_to_object (op->other_arch); - copy_owner (tmp, op); + tmp->set_owner (op); tmp->skill = op->skill; - owner = get_owner (op); + owner = op->owner; if ((tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) && owner && !tailor_god_spell (tmp, owner)) { - remove_ob (op); - free_object (op); + op->destroy (); return; } - tmp->x = op->x; - tmp->y = op->y; - /* special for bombs - it actually has sane values for these */ if (op->type == SPELL_EFFECT && op->subtype == SP_BOMB) { @@ -493,6 +470,7 @@ { if (op->attacktype & AT_MAGIC) tmp->attacktype |= AT_MAGIC; + /* Spell doc describes what is going on here */ tmp->stats.dam = op->dam_modifier; tmp->range = op->stats.maxhp; @@ -510,28 +488,20 @@ /* Prevent recursion */ op->move_on = 0; - insert_ob_in_map (tmp, op->map, op, 0); + tmp->insert_at (op, op); /* remove the firebullet */ - if (!was_destroyed (op, op_tag)) - { - remove_ob (op); - free_object (op); - } + op->destroy (); } - - /* checks to see what op should do, given the space it is on * (eg, explode, damage player, etc) */ - 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); @@ -550,18 +520,16 @@ if (!(mflags & P_IS_ALIVE)) return; - for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) + for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) { 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; } } @@ -569,19 +537,17 @@ } } - /* Basically, we move 'op' one square, and if it hits something, * call check_bullet. * This function is only applicable to bullets, but not to all * fired arches (eg, bolts). */ - void move_bullet (object *op) { 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 +557,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 +566,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,29 +580,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->x = new_x; - op->y = new_y; - if ((op = insert_ob_in_map (op, m, op, 0)) == NULL) + if (!(op = m->insert (op, new_x, new_y, op))) return; if (reflwall (op->map, op->x, op->y, op)) @@ -649,9 +603,7 @@ update_turn_face (op); } else - { - check_bullet (op); - } + check_bullet (op); } @@ -696,35 +648,40 @@ if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) SET_ANIMATION (tmp, dir); - set_owner (tmp, op); + tmp->set_owner (op); set_spell_skill (op, caster, spob, tmp); tmp->x = op->x + freearr_x[dir]; tmp->y = op->y + freearr_y[dir]; tmp->map = op->map; - mflags = get_map_flags (tmp->map, &tmp->map, tmp->x, tmp->y, &tmp->x, &tmp->y); + maptile *newmap; + mflags = get_map_flags (tmp->map, &newmap, tmp->x, tmp->y, &tmp->x, &tmp->y); if (mflags & P_OUT_OF_MAP) { - free_object (tmp); + tmp->destroy (); return 0; } + + tmp->map = newmap; + 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); - } + + if ((tmp = tmp->insert_at (tmp, op))) + check_bullet (tmp); + return 1; } @@ -744,18 +701,14 @@ { object *new_ob = arch_to_object (op->other_arch); - new_ob->x = op->x; - new_ob->y = op->y; new_ob->level = op->level; - set_owner (new_ob, op->owner); + new_ob->set_owner (op->owner); /* preserve skill ownership */ if (op->skill && op->skill != new_ob->skill) - { - new_ob->skill = op->skill; - } - insert_ob_in_map (new_ob, op->map, op, 0); + new_ob->skill = op->skill; + new_ob->insert_at (op, op); } /* move_cone: causes cone object 'op' to move a space/hit creatures */ @@ -764,14 +717,12 @@ move_cone (object *op) { int i; - tag_t tag; /* if no map then hit_map will crash so just ignore object */ if (!op->map) { LOG (llevError, "Tried to move_cone object %s without a map.\n", op->name ? &op->name : "unknown"); - op->speed = 0; - update_ob_speed (op); + op->set_speed (0); return; } @@ -787,15 +738,13 @@ * when their cone dies when they die. */ /* If no owner left, the spell dies out. */ - if (get_owner (op) == NULL) + if (op->owner == 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 +754,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,17 +778,15 @@ if (ok_to_put_more (op->map, x, y, op, op->attacktype)) { - object *tmp = get_object (); - - copy_object (op, tmp); - tmp->x = x; - tmp->y = y; + object *tmp = op->clone (); tmp->duration = op->duration + 1; /* Use for spell tracking - see ok_to_put_more() */ tmp->stats.maxhp = op->stats.maxhp; - insert_ob_in_map (tmp, op->map, op, 0); + + op->map->insert (tmp, x, y, op); + if (tmp->other_arch) cone_drop (tmp); } @@ -860,7 +806,7 @@ { object *tmp; int i, success = 0, range_min = -1, range_max = 1; - mapstruct *m; + maptile *m; sint16 sx, sy; MoveType movetype; @@ -926,11 +872,9 @@ success = 1; tmp = arch_to_object (spell->other_arch); - set_owner (tmp, op); + tmp->set_owner (op); set_spell_skill (op, caster, spell, tmp); tmp->level = caster_level (caster, spell); - tmp->x = sx; - tmp->y = sy; tmp->attacktype = spell->attacktype; /* holy word stuff */ @@ -977,11 +921,9 @@ LOG (llevDebug, "cast_cone(): arch %s doesn't have flying 1\n", &spell->other_arch->name); if (!tmp->move_on && tmp->stats.dam) - { - LOG (llevDebug, "cast_cone(): arch %s doesn't have move_on set\n", &spell->other_arch->name); - } + LOG (llevDebug, "cast_cone(): arch %s doesn't have move_on set\n", &spell->other_arch->name); - insert_ob_in_map (tmp, m, op, 0); + m->insert (tmp, sx, sy, op); /* This is used for tracking spells so that one effect doesn't hit * a single space too many times. @@ -1010,7 +952,6 @@ { int i; object *env, *tmp; - archetype *at; if (op->state != NUM_ANIMATIONS (op) - 1) return; @@ -1025,10 +966,7 @@ if (env->type == PLAYER) esrv_del_item (env->contr, op->count); - remove_ob (op); - op->x = env->x; - op->y = env->y; - if ((op = insert_ob_in_map (op, env->map, op, 0)) == NULL) + if (!(op = op->insert_at (env, op))) return; } @@ -1037,8 +975,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,29 +983,27 @@ * but using the cast_bullet isn't really feasible, * so just set up the appropriate values. */ - at = find_archetype (SPLINT); - if (at) + if (archetype *at = archetype::find (SPLINT)) { for (i = 1; i < 9; i++) { if (out_of_map (op->map, op->x + freearr_x[i], op->y + freearr_x[i])) continue; + tmp = arch_to_object (at); tmp->direction = i; tmp->range = op->range; tmp->stats.dam = op->stats.dam; tmp->duration = op->duration; tmp->attacktype = op->attacktype; - copy_owner (tmp, op); + tmp->set_owner (op); if (op->skill && op->skill != tmp->skill) - { - tmp->skill = op->skill; - } + tmp->skill = op->skill; + if (QUERY_FLAG (tmp, FLAG_IS_TURNABLE)) SET_ANIMATION (tmp, i); - tmp->x = op->x + freearr_x[i]; - tmp->y = op->y + freearr_x[i]; - insert_ob_in_map (tmp, op->map, op, 0); + + op->map->insert (tmp, op->x + freearr_x[i], op->y + freearr_x[i], op); move_bullet (tmp); } } @@ -1083,7 +1018,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)) @@ -1099,11 +1034,10 @@ tmp->duration = spell->duration + SP_level_duration_adjust (caster, spell); tmp->attacktype = spell->attacktype; - set_owner (tmp, op); + tmp->set_owner (op); set_spell_skill (op, caster, spell, tmp); - tmp->x = dx; - tmp->y = dy; - insert_ob_in_map (tmp, m, op, 0); + + m->insert (tmp, dx, dy, op); return 1; } @@ -1129,7 +1063,7 @@ object *target; sint16 x, y; int dist, mflags; - mapstruct *mp; + maptile *mp; if (dir == 0) return NULL; @@ -1152,7 +1086,7 @@ if (mflags & P_IS_ALIVE) { - for (target = get_map_ob (mp, x, y); target; target = target->above) + for (target = GET_MAP_OB (mp, x, y); target; target = target->above) { if (QUERY_FLAG (target->head ? target->head : target, FLAG_MONSTER)) { @@ -1229,8 +1163,7 @@ effect->level = spell->stats.dam + SP_level_dam_adjust (caster, spell); /* casting death spells at undead isn't a good thing */ - if QUERY_FLAG - (target, FLAG_UNDEAD) + if (QUERY_FLAG (target, FLAG_UNDEAD)) { if (random_roll (0, 2, op, PREFER_LOW)) { @@ -1242,7 +1175,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; } } @@ -1253,13 +1186,11 @@ effect->stats.dam = spell->stats.dam + SP_level_dam_adjust (caster, spell); } - set_owner (effect, op); + effect->set_owner (op); set_spell_skill (op, caster, spell, effect); /* ok, tell it where to be, and insert! */ - effect->x = target->x; - effect->y = target->y; - insert_ob_in_map (effect, target->map, op, 0); + effect->insert_at (target, op); return 1; } @@ -1279,24 +1210,22 @@ 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; } - owner = get_owner (op); + owner = op->owner; #if 0 /* It'd make things nastier if this wasn't here - spells cast by * monster that are then killed would continue to survive */ if (owner == NULL) { - remove_ob (op); - free_object (op); + op->destroy (); return; } #endif @@ -1308,36 +1237,32 @@ 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; - i = spell_find_dir (op->map, op->x, op->y, get_owner (op)); + + i = spell_find_dir (m, new_x, new_y, op->owner); if (i > 0 && i != op->direction) { op->direction = i; SET_ANIMATION (op, op->direction); } - insert_ob_in_map (op, op->map, op, 0); + + m->insert (op, new_x, new_y, op); } /**************************************************************************** @@ -1392,7 +1317,7 @@ { int i, j, range, mflags, friendly = 0, dam, dur; sint16 sx, sy; - mapstruct *m; + maptile *m; object *tmp; const char *skill; @@ -1425,16 +1350,17 @@ m = op->map; sx = op->x + i; sy = op->y + j; + mflags = get_map_flags (m, &m, sx, sy, &sx, &sy); if (mflags & P_OUT_OF_MAP) continue; + if (mflags & P_IS_ALIVE) { - for (tmp = get_map_ob (m, sx, sy); tmp; tmp = tmp->above) - { - if (QUERY_FLAG (tmp, FLAG_ALIVE) || tmp->type == PLAYER) - break; - } + for (tmp = GET_MAP_OB (m, sx, sy); tmp; tmp = tmp->above) + if (QUERY_FLAG (tmp, FLAG_ALIVE) || tmp->type == PLAYER) + break; + if (tmp) { if (tmp->head) @@ -1447,29 +1373,19 @@ { hit_player (tmp, dam, op, spell_ob->attacktype, 0); if (spell_ob->other_arch) - { - tmp = arch_to_object (spell_ob->other_arch); - tmp->x = sx; - tmp->y = sy; - insert_ob_in_map (tmp, m, op, 0); - } + m->insert (arch_to_object (spell_ob->other_arch), sx, sy, op); } else if (spell_ob->subtype == SP_FAERY_FIRE && tmp->resist[ATNR_MAGIC] != 100) { if (make_object_glow (tmp, 1, dur) && spell_ob->other_arch) - { - object *effect = arch_to_object (spell_ob->other_arch); - - effect->x = sx; - effect->y = sy; - insert_ob_in_map (effect, m, op, 0); - } + m->insert (arch_to_object (spell_ob->other_arch), sx, sy, op); } } } } } } + op->skill = skill; return 1; } @@ -1563,7 +1479,7 @@ change_abil (tmp, force); /* Mostly to display any messages */ insert_ob_in_ob (force, tmp); - fix_player (tmp); + tmp->update_stats (); return 1; } @@ -1584,7 +1500,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 @@ -1624,7 +1540,7 @@ if (!(mflags & P_IS_ALIVE)) continue; - for (tmp = get_map_ob (m, nx, ny); tmp; tmp = tmp->above) + for (tmp = GET_MAP_OB (m, nx, ny); tmp; tmp = tmp->above) if (QUERY_FLAG (tmp, FLAG_MONSTER)) break; @@ -1722,7 +1638,7 @@ Typical use case is charm, go somwhere, use aggravation to make hostile. This could lead to fun stuff like mice outbreak in bigworld and server crawl. */ CLEAR_FLAG (head, FLAG_GENERATOR); - set_owner (head, op); + head->set_owner (op); set_spell_skill (op, caster, spell, head); add_friendly_object (head); head->attack_movement = PETMOVE; @@ -1733,12 +1649,7 @@ /* If a monster was effected, put an effect in */ if (done_one && spell->other_arch) - { - tmp = arch_to_object (spell->other_arch); - tmp->x = nx; - tmp->y = ny; - insert_ob_in_map (tmp, m, op, 0); - } + m->insert (arch_to_object (spell->other_arch), nx, ny, op); } /* for y */ return 1; @@ -1758,9 +1669,9 @@ int i, j, dam_save, dir, mflags; sint16 nx, ny, hx, hy; object *owner; - mapstruct *m; + maptile *m; - owner = get_owner (op); + owner = op->owner; /* the following logic makes sure that the ball doesn't move into a wall, * and makes sure that it will move along a wall to try and get at it's @@ -1799,10 +1710,7 @@ m = op->map; } - remove_ob (op); - op->y = ny; - op->x = nx; - insert_ob_in_map (op, m, op, 0); + m->insert (op, nx, ny, op); dam_save = op->stats.dam; /* save the original dam: we do halfdam on surrounding squares */ @@ -1838,27 +1746,21 @@ /* insert the other arch */ if (op->other_arch && !(OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, hx, hy)))) - { - new_ob = arch_to_object (op->other_arch); - new_ob->x = hx; - new_ob->y = hy; - insert_ob_in_map (new_ob, m, op, 0); - } + m->insert (arch_to_object (op->other_arch), hx, hy, op); } /* restore to the center location and damage */ op->stats.dam = dam_save; - i = spell_find_dir (op->map, op->x, op->y, get_owner (op)); + i = spell_find_dir (op->map, op->x, op->y, op->owner); if (i >= 0) { /* we have a preferred direction! */ /* pick another direction if the preferred dir is blocked. */ if (get_map_flags (op->map, &m, nx + freearr_x[i], ny + freearr_y[i], &hx, &hy) & P_OUT_OF_MAP || OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, hx, hy))) - { - i = absdir (i + rndm (0, 2) - 1); /* -1, 0, +1 */ - } + i = absdir (i + rndm (0, 2) - 1); /* -1, 0, +1 */ + op->direction = i; } } @@ -1880,18 +1782,18 @@ 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; - owner = get_owner (op); + owner = op->owner; if (op->duration == 0 || owner == NULL) { - remove_ob (op); - free_object (op); + op->destroy (); return; } + op->duration--; basedir = op->direction; @@ -1998,9 +1900,7 @@ return 0; tmp = get_archetype (SWARM_SPELL); - tmp->x = op->x; - tmp->y = op->y; - set_owner (tmp, op); /* needed so that if swarm elements kill, caster gets xp. */ + tmp->set_owner (op); /* needed so that if swarm elements kill, caster gets xp. */ set_spell_skill (op, caster, spell, tmp); tmp->level = caster_level (caster, spell); /*needed later, to get level dep. right. */ @@ -2009,17 +1909,17 @@ tmp->attacktype = tmp->spell->attacktype; if (tmp->attacktype & AT_HOLYWORD || tmp->attacktype & AT_GODPOWER) - { - if (!tailor_god_spell (tmp, op)) - return 1; - } + if (!tailor_god_spell (tmp, op)) + return 1; + tmp->duration = SP_level_duration_adjust (caster, spell); for (i = 0; i < spell->duration; i++) tmp->duration += die_roll (1, 3, op, PREFER_HIGH); tmp->direction = dir; tmp->invisible = 1; - insert_ob_in_map (tmp, op->map, op, 0); + + tmp->insert_at (op, op); return 1; } @@ -2033,7 +1933,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); @@ -2057,7 +1957,7 @@ if (mflags & P_IS_ALIVE && spell->attacktype) { - for (target = get_map_ob (m, x, y); target; target = target->above) + for (target = GET_MAP_OB (m, x, y); target; target = target->above) if (QUERY_FLAG (target, FLAG_MONSTER)) { /* oky doky. got a target monster. Lets make a blinding attack */ @@ -2089,9 +1989,8 @@ if (tmp->glow_radius > MAX_LIGHT_RADII) tmp->glow_radius = MAX_LIGHT_RADII; } - tmp->x = x; - tmp->y = y; - insert_ob_in_map (tmp, m, op, 0); + + m->insert (tmp, x, y, op); return 1; } @@ -2111,7 +2010,7 @@ sint16 x, y; int i, mflags, range, dam_mod, dur_mod; object *walk; - mapstruct *m; + maptile *m; x = op->x; y = op->y; @@ -2149,12 +2048,12 @@ if (mflags & P_IS_ALIVE) { /* search this square for a victim */ - for (walk = get_map_ob (m, x, y); walk; walk = walk->above) + for (walk = GET_MAP_OB (m, x, y); walk; walk = walk->above) if (QUERY_FLAG (walk, FLAG_MONSTER) || (walk->type == PLAYER)) { /* found a victim */ object *disease = arch_to_object (spell->other_arch); - set_owner (disease, op); + disease->set_owner (op); set_spell_skill (op, caster, spell, disease); disease->stats.exp = 0; disease->level = caster_level (caster, spell); @@ -2213,18 +2112,16 @@ 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 */ - flash = get_archetype (ARCH_DETECT_MAGIC); - flash->x = x; - flash->y = y; - flash->map = walk->map; - insert_ob_in_map (flash, walk->map, op, 0); + disease->destroy (); /* don't need this one anymore */ + walk->map->insert (get_archetype (ARCH_DETECT_MAGIC), x, y, op); return 1; } - free_object (disease); + + disease->destroy (); } } /* if living creature */ } /* for range of spaces */ + new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!"); return 1; }