--- deliantra/server/server/spell_attack.C 2006/12/26 08:55:00 1.24 +++ deliantra/server/server/spell_attack.C 2006/12/26 20:04:09 1.25 @@ -149,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, @@ -171,7 +169,7 @@ sint16 x, y; maptile *m; - if (--(op->duration) < 0) + if (--op->duration < 0) { op->destroy (); return; @@ -183,9 +181,7 @@ return; if (--op->range < 0) - { - op->range = 0; - } + op->range = 0; else { x = op->x + DIRX (op); @@ -203,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; @@ -243,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 = op->clone (); + 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. */ @@ -338,7 +333,7 @@ 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; @@ -359,11 +354,10 @@ void explosion (object *op) { - object *tmp; maptile *m = op->map; int i; - if (--(op->duration) < 0) + if (--op->duration < 0) { op->destroy (); return; @@ -379,19 +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 = op->clone (); + 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); } } } @@ -416,9 +411,7 @@ 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"); @@ -426,10 +419,7 @@ return; } - 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); + op->insert_at (env, op, INS_NO_MERGE | INS_NO_WALK_ON); } else if (out_of_map (op->map, op->x, op->y)) { @@ -468,9 +458,6 @@ 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) { @@ -483,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; @@ -500,20 +488,14 @@ /* Prevent recursion */ op->move_on = 0; - insert_ob_in_map (tmp, op->map, op, 0); + tmp->insert_at (op, op); /* remove the firebullet */ - if (!op->destroyed ()) - { - op->destroy (); - } + 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) { @@ -612,10 +594,7 @@ return; } - op->remove (); - 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)) @@ -700,7 +679,7 @@ tmp->map = op->map; } - if ((tmp = insert_ob_in_map (tmp, tmp->map, op, 0))) + if ((tmp = tmp->insert_at (tmp, op))) check_bullet (tmp); return 1; @@ -722,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; 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 */ @@ -805,14 +780,13 @@ { object *tmp = op->clone (); - tmp->x = x; - tmp->y = y; - 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); } @@ -901,8 +875,6 @@ 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 */ @@ -949,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. @@ -982,7 +952,6 @@ { int i; object *env, *tmp; - archetype *at; if (op->state != NUM_ANIMATIONS (op) - 1) return; @@ -997,10 +966,7 @@ if (env->type == PLAYER) esrv_del_item (env->contr, op->count); - op->remove (); - 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; } @@ -1017,13 +983,13 @@ * but using the cast_bullet isn't really feasible, * so just set up the appropriate values. */ - at = archetype::find (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; @@ -1032,14 +998,12 @@ tmp->attacktype = op->attacktype; 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); } } @@ -1072,9 +1036,8 @@ 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; } @@ -1227,9 +1190,7 @@ 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; } @@ -1294,17 +1255,14 @@ return; } - op->x = new_x; - op->y = new_y; - op->map = m; - i = spell_find_dir (op->map, op->x, op->y, op->owner); + 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,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; - } + if (QUERY_FLAG (tmp, FLAG_ALIVE) || tmp->type == PLAYER) + break; + if (tmp) { if (tmp->head) @@ -1414,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; } @@ -1700,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; @@ -1766,10 +1710,7 @@ m = op->map; } - op->remove (); - 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 */ @@ -1805,12 +1746,7 @@ /* 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 */ @@ -1823,9 +1759,8 @@ /* 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; } } @@ -1965,8 +1900,6 @@ return 0; tmp = get_archetype (SWARM_SPELL); - tmp->x = op->x; - tmp->y = op->y; tmp->set_owner (op); /* needed so that if swarm elements kill, caster gets xp. */ set_spell_skill (op, caster, spell, tmp); @@ -1976,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; } @@ -2056,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; } @@ -2181,11 +2113,7 @@ new_draw_info_format (NDI_UNIQUE, 0, op, "You inflict %s on %s!", &disease->name, &walk->name); disease->destroy (); /* 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); + walk->map->insert (get_archetype (ARCH_DETECT_MAGIC), x, y, op); return 1; } @@ -2193,6 +2121,7 @@ } } /* if living creature */ } /* for range of spaces */ + new_draw_info (NDI_UNIQUE, 0, op, "No one caught anything!"); return 1; }