/* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002 Mark Wedel & Crossfire Development Team * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . * * The authors can be reached via e-mail to */ #include #include /* given that 'pet' is a friendly object, this function returns a * monster the pet should attack, NULL if nothing appropriate is * found. it basically looks for nasty things around the owner * of the pet to attack. * this is now tilemap aware. */ object * get_pet_enemy (object *pet, rv_vector * rv) { object *tmp, *attacker, *tmp3; int i; sint16 x, y; maptile *nm; int search_arr[SIZEOFFREE]; int mflags; attacker = pet->attacked_by; /*pointer to attacking enemy */ pet->attacked_by = NULL; /*clear this, since we are dealing with it */ object *owner = pet->owner; if (!owner) { /* the owner is no longer around, so the * pet no longer needs to be friendly. */ remove_friendly_object (pet); pet->attack_movement &= ~PETMOVE; return 0; } /* If the owner has turned on the pet, make the pet * unfriendly. */ if (check_enemy (owner, rv) == pet) { remove_friendly_object (pet); pet->attack_movement &= ~PETMOVE; return owner; } /* If they are not on the same map, the pet won't be agressive */ //if (!on_same_map (pet, owner)) // return 0; /* See if the pet has an existing enemy. If so, don't start a new one */ if (tmp = check_enemy (pet, rv)) { if (tmp == owner && !pet->flag [FLAG_CONFUSED] && pet->flag [FLAG_FRIENDLY]) /* without this check, you can actually get pets with * enemy set to owner! */ pet->enemy = 0; else return tmp; } get_search_arr (search_arr); if (owner->type == PLAYER && owner->contr->petmode > pet_normal) { if (owner->contr->petmode == pet_sad) { tmp = find_nearest_living_creature (pet); if (tmp != 0) { get_rangevector (pet, tmp, rv, 0); if (check_enemy (pet, rv) != 0) return tmp; else pet->enemy = 0; } /* if we got here we have no enemy */ /* we return 0 to avoid heading back to the owner */ pet->enemy = 0; return 0; } } /* Since the pet has no existing enemy, look for anything nasty * around the owner that it should go and attack. (if the owner is * still on a map) */ // owners sometimes are not on a map but in the inventory of somehting else if (!owner->flag [FLAG_REMOVED] && owner->map) { tmp3 = 0; for (i = 0; i < SIZEOFFREE; i++) { x = owner->x + freearr_x[search_arr[i]]; y = owner->y + freearr_y[search_arr[i]]; nm = owner->map; /* Only look on the space if there is something alive there. */ mflags = get_map_flags (nm, &nm, x, y, &x, &y); if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) { for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) { object *tmp2 = tmp->head == 0 ? tmp : tmp->head; if (tmp2->flag [FLAG_ALIVE] && ((!tmp2->flag [FLAG_FRIENDLY] && (tmp2->type != PLAYER)) || should_arena_attack (pet, owner, tmp2)) && !tmp2->flag [FLAG_UNAGGRESSIVE] && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) { if (!can_see_enemy (pet, tmp2)) { if (tmp3 != 0) tmp3 = tmp2; } else { pet->enemy = tmp2; if (check_enemy (pet, rv) != 0) return tmp2; else pet->enemy = 0; } } /* if this is a valid enemy */ } /* for objects on this space */ } /* if there is something living on this space */ } /* for loop of spaces around the owner */ /* fine, we went through the whole loop and didn't find one we could see, take what we have */ if (tmp3 != 0) { pet->enemy = tmp3; if (check_enemy (pet, rv) != 0) return tmp3; else pet->enemy = 0; } } /* No threat to owner, check to see if the pet has an attacker */ if (attacker) { /* also need to check to make sure it is not freindly */ /* or otherwise non-hostile, and is an appropriate target */ if (!attacker->flag [FLAG_FRIENDLY] && on_same_map (pet, attacker)) { pet->enemy = attacker; if (check_enemy (pet, rv) != 0) return attacker; else pet->enemy = 0; } } /* Don't have an attacker or legal enemy, so look for a new one!. * This looks for one around where the pet is. Thus, you could lead * a pet to danger, then take a few steps back. This code is basically * the same as the code that looks around the owner. */ if (owner->type == PLAYER && owner->contr->petmode != pet_defend) { tmp3 = 0; for (i = 0; i < SIZEOFFREE; i++) { x = pet->x + freearr_x[search_arr[i]]; y = pet->y + freearr_y[search_arr[i]]; nm = pet->map; /* Only look on the space if there is something alive there. */ mflags = get_map_flags (nm, &nm, x, y, &x, &y); if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) { for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) { object *tmp2 = tmp->head == 0 ? tmp : tmp->head; if (tmp2->flag [FLAG_ALIVE] && ((!tmp2->flag [FLAG_FRIENDLY] && (tmp2->type != PLAYER)) || should_arena_attack (pet, owner, tmp2)) && !tmp2->flag [FLAG_UNAGGRESSIVE] && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) { if (!can_see_enemy (pet, tmp2)) { if (tmp3 != 0) tmp3 = tmp2; } else { pet->enemy = tmp2; if (check_enemy (pet, rv) != 0) return tmp2; else pet->enemy = 0; } } /* make sure we can get to the bugger */ } /* for objects on this space */ } /* if there is something living on this space */ } /* for loop of spaces around the pet */ /* fine, we went through the whole loop and didn't find one we could see, take what we have */ if (tmp3 != 0) { pet->enemy = tmp3; if (check_enemy (pet, rv) != 0) return tmp3; else pet->enemy = 0; } } /* pet in defence mode */ object *enemy = check_enemy (pet, rv); // we have a summoned pet here and the owners enemy isn't set or can't // be reached => search for a player around us and set it as our new enemy!! if (!enemy && pet->owner && pet->owner->type != PLAYER) enemy = get_nearest_player (pet); /* Didn't find anything - return the owner's enemy or 0 */ return enemy; } void terminate_all_pets (object *owner) { objectlink *obl, *next; for (obl = first_friendly_object; obl; obl = next) { object *ob = obl->ob; next = obl->next; if (ob->owner == owner) ob->drop_and_destroy (); } } /* * Unfortunately, sometimes, the owner of a pet is in the * process of entering a new map when this is called. * Interesting enough, we don't use the passed map structure in * this function. */ void move_all_pets () { objectlink *obl, *next; object *owner; for (obl = first_friendly_object; obl; obl = next) { next = obl->next; if (obl->ob->type != PLAYER && obl->ob->flag [FLAG_FRIENDLY] && (owner = obl->ob->owner) && !on_same_map (owner, obl->ob)) { /* follow owner checks map status for us */ follow_owner (obl->ob, owner); } } } int follow_owner (object *ob, object *owner) { if (owner->flag [FLAG_REMOVED]) return 0; // do nothing if the owner is removed else if (!owner->map || owner->map->state != MAP_ACTIVE) LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); else { int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); if (dir >= 0) { owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]); if (owner->type == PLAYER) /* Uh, I hope this is always true... */ new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); return 0; } } ob->drop_and_destroy (); return 1; } void pet_move (object *ob) { int dir = 0, i; sint16 dx, dy; object *ob2, *owner; maptile *m; /* Check to see if player pulled out */ if ((owner = ob->owner) == NULL) { ob->drop_and_destroy (); LOG (llevTrace, "Pet: no owner, leaving.\n"); return; } /* move monster into the owners map if not in the same map * except when the owner is removed. */ if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) { follow_owner (ob, owner); return; } /* Calculate Direction */ if (owner->type == PLAYER && owner->contr->petmode == pet_sad) { /* in S&D mode, if we have no enemy, run randomly about. */ for (i = 0; i < 15; i++) { dir = rndm (1, 8); dx = ob->x + freearr_x[dir]; dy = ob->y + freearr_y[dir]; m = ob->map; if (get_map_flags (ob->map, &m, dx, dy, &dx, &dy) & P_OUT_OF_MAP) continue; else if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m, dx, dy))) continue; else break; } } else if (!owner->flag [FLAG_REMOVED]) // only get vector to owner when owner not removed { struct rv_vector rv; get_rangevector (ob, ob->owner, &rv, 0); dir = rv.direction; } ob->direction = dir; /* move_ob returns 0 if the object couldn't move. If that is the * case, lets do some other work. */ if (!(ob->move (dir))) { object *part; /* the failed move_ob above may destroy the pet, so check here */ if (ob->destroyed ()) return; for (part = ob; part != NULL; part = part->more) { dx = part->x + freearr_x[dir]; dy = part->y + freearr_y[dir]; m = get_map_from_coord (part->map, &dx, &dy); if (!m) continue; for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) { object *new_ob; new_ob = ob2->head ? ob2->head : ob2; if (new_ob == ob) break; if (new_ob == ob->owner) return; if (new_ob->owner == ob->owner) break; /* Hmm. Did we try to move into an enemy monster? If so, * make it our enemy. */ if (new_ob->flag [FLAG_ALIVE] && !ob->flag [FLAG_UNAGGRESSIVE] && !new_ob->flag [FLAG_UNAGGRESSIVE] && !new_ob->flag [FLAG_FRIENDLY]) { ob->enemy = new_ob; if (new_ob->enemy == NULL) new_ob->enemy = ob; return; } else if (new_ob->type == PLAYER) { new_draw_info (NDI_UNIQUE, 0, new_ob, "You stand in the way of someones pet."); return; } } } /* Try a different course */ dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); ob->move (dir); } } /**************************************************************************** * * GOLEM SPELL CODE * ****************************************************************************/ /* fix_summon_pet() - this makes multisquare/single square monsters * proper for map insertion. * at is the archetype, op is the caster of the spell, dir is the * direction the monster should be placed in. * is_golem is to note that this is a golem spell. */ static object * fix_summon_pet (archetype *at, object *op, int dir, int is_golem) { object *tmp = NULL, *prev = NULL, *head = NULL; for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) { tmp = atmp->instance (); if (atmp == at) { if (!is_golem) tmp->set_flag (FLAG_MONSTER); tmp->set_owner (op); if (op->type == PLAYER) { tmp->stats.exp = 0; add_friendly_object (tmp); if (is_golem) tmp->clr_flag (FLAG_MONSTER); } else { if (op->flag [FLAG_FRIENDLY]) { object *owner = op->owner; if (owner) { /* For now, we transfer ownership */ tmp->set_owner (owner); tmp->attack_movement = PETMOVE; add_friendly_object (tmp); } } } if (op->type != PLAYER || !is_golem) { tmp->attack_movement = PETMOVE; tmp->speed_left = -1; tmp->type = 0; tmp->enemy = op->enemy; } else tmp->type = GOLEM; } if (!head) head = tmp; tmp->x = op->x + freearr_x[dir] + tmp->arch->x; tmp->y = op->y + freearr_y[dir] + tmp->arch->y; tmp->map = op->map; if (tmp->invisible) tmp->invisible = 0; if (head != tmp) tmp->head = head, prev->more = tmp; prev = tmp; } head->direction = dir; /* need to change some monster attr to prevent problems/crashing */ head->last_heal = 0; head->last_eat = 0; head->last_grace = 0; head->last_sp = 0; head->other_arch = NULL; head->stats.exp = 0; head->clr_flag (FLAG_CHANGING); head->clr_flag (FLAG_STAND_STILL); head->clr_flag (FLAG_GENERATOR); head->clr_flag (FLAG_SPLITTING); if (head->attacktype & AT_GHOSTHIT) head->attacktype = (AT_PHYSICAL | AT_DRAIN); return head; } /* updated this to allow more than the golem 'head' to attack */ /* op is the golem to be moved. */ void move_golem (object *op) { int made_attack = 0; object *tmp; if (op->flag [FLAG_MONSTER]) return; /* Has already been moved */ if (!op->owner) { LOG (llevDebug, "Golem without owner destructed.\n"); op->drop_and_destroy (); return; } /* It would be nice to have a cleaner way of what message to print * when the golem expires than these hard coded entries. * Note it is intentional that a golems duration is based on its * hp, and not duration */ if (--op->stats.hp < 0) { if (op->msg) new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); op->drop_and_destroy (); return; } /* Do golem attacks/movement for single & multisq golems. * Assuming here that op is the 'head' object. Pass only op to * ->move (makes recursive calls to other parts) * move_ob returns 0 if the creature was not able to move. */ if (op->move (op->direction, op)) return; if (op->destroyed ()) return; for (tmp = op; tmp; tmp = tmp->more) { sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; object *victim; maptile *m; int mflags; m = op->map; mflags = get_map_flags (m, &m, x, y, &x, &y); if (mflags & P_OUT_OF_MAP) continue; for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above) if (victim->flag [FLAG_ALIVE]) break; /* We used to call will_hit_self to make sure we don't * hit ourselves, but that didn't work, and I don't really * know if that was more efficient anyways than this. * This at least works. Note that victim->head can be NULL, * but since we are not trying to dereferance that pointer, * that isn't a problem. */ if (victim && victim != op && victim->head != op) { /* for golems with race fields, we don't attack * aligned races */ if (victim->race && op->race && op->race.contains (victim->race)) { if (op->owner) new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); } else if (victim == op->owner) { if (op->owner) new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging you.", &op->name); } else { attack_ob (victim, op); made_attack = 1; } } /* If victim */ } if (made_attack) update_object (op, UP_OBJ_FACE); } /* this is a really stupid function when you get down and * look at it. Keep it here for the time being - makes life * easier if we ever decide to do more interesting thing with * controlled golems. */ void control_golem (object *op, int dir) { op->direction = dir; } /* summon golem: summons a monster for 'op'. caster is the object * casting the spell, dir is the direction to place the monster, * at is the archetype of the monster, and spob is the spell * object. At this stage, all spob is really used for is to * adjust some values in the monster. */ int summon_golem (object *op, object *caster, int dir, object *spob) { object *tmp, *god = NULL; archetype *at; /* Because there can be different golem spells, player may want to * 'lose' their old golem. */ if (op->type == PLAYER && op->contr->golem) { new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); op->contr->golem->drop_and_destroy (); op->contr->golem = 0; } if (spob->other_arch) at = spob->other_arch; else if (spob->race) { god = find_god (determine_god (caster)); if (!god) { new_draw_info_format (NDI_UNIQUE, 0, op, "You must worship a god to cast %s.", &spob->name); return 0; } at = determine_holy_arch (god, spob->race); if (!at) { new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no %s for you to call.", &god->name, &spob->race); return 0; } } else { LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); return 0; } if (!dir) dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) { new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); return 0; } /* basically want to get proper map/coordinates for this object */ if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) { new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); return 0; } if (op->type == PLAYER) { tmp->type = GOLEM; op->contr->golem = tmp; /* give the player control of the golem */ set_spell_skill (op, caster, spob, tmp); } /* This sets the level dependencies on dam and hp for monsters */ /* players can't cope with too strong summonings. */ /* but monsters can. reserve these for players. */ if (op->type == PLAYER) { tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); if (!spob->stats.dam) tmp->stats.dam += SP_level_dam_adjust (caster, spob); else tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); tmp->set_speed (min (1.f, tmp->speed + .02f * SP_level_range_adjust (caster, spob))); if (spob->attacktype) tmp->attacktype = spob->attacktype; } tmp->stats.wc -= SP_level_range_adjust (caster, spob); /* limit the speed to 0.3 for non-players, 1 for players. */ /* make experience increase in proportion to the strength. * this is a bit simplistic - we are basically just looking at how * often the sp doubles and use that as the ratio. */ tmp->stats.exp *= 1 + max (spob->stats.maxgrace, spob->stats.sp) / casting_level (caster, spob); tmp->speed_left = 0; tmp->direction = dir; /* Holy spell - some additional tailoring */ if (god) { char *buf = format ("%s of %s", &spob->name, &god->name); buf[0] = toupper (buf[0]); for (object *tmp2 = tmp; tmp2; tmp2 = tmp2->more) tmp2->name = buf; tmp->attacktype |= god->attacktype; memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); tmp->race = god->race; tmp->slaying = god->slaying; /* safety, we must allow a god's servants some reasonable attack */ if (!(tmp->attacktype & AT_PHYSICAL)) tmp->attacktype |= AT_PHYSICAL; } insert_ob_in_map (tmp, tmp->map, op, 0); return 1; } /*************************************************************************** * * Summon monster/pet/other object code * ***************************************************************************/ /* Returns a monster (chosen at random) that this particular player (and his * god) find acceptable. This checks level, races allowed by god, etc * to determine what is acceptable. * This returns NULL if no match was found. */ static object * choose_cult_monster (object *pl, object *god, int summon_level) { char buf[MAX_BUF]; const char *race; int racenr, mon_nr, i; racelink *list; objectlink *tobl; object *otmp; /* Determine the number of races available */ racenr = 0; strcpy (buf, god->race); race = strtok (buf, ","); while (race) { racenr++; race = strtok (NULL, ","); } /* next, randomly select a race from the aligned_races string */ if (racenr > 1) { racenr = rndm (0, racenr - 1); strcpy (buf, god->race); race = strtok (buf, ","); for (i = 0; i < racenr; i++) race = strtok (NULL, ","); } else race = god->race; /* see if a we can match a race list of monsters. This should not * happen, so graceful recovery isn't really needed, but this sanity * checking is good for cases where the god archetypes mismatch the * race file */ if ((list = find_racelink (race)) == NULL) { new_draw_info_format (NDI_UNIQUE, 0, pl, "The spell fails! %s's creatures are beyond the range of your summons", &god->name); LOG (llevDebug, "choose_cult_monster() requested non-existent aligned race!\n"); return 0; } /* search for an apprplritate monster on this race list */ mon_nr = 0; for (tobl = list->member; tobl; tobl = tobl->next) { otmp = tobl->ob; if (!otmp || !otmp->flag [FLAG_MONSTER]) continue; if (otmp->level <= summon_level) mon_nr++; } /* If this god has multiple race entries, we should really choose another. * But then we either need to track which ones we have tried, or just * make so many calls to this function, and if we get so many without * a valid entry, assuming nothing is available and quit. */ if (!mon_nr) return NULL; mon_nr = rndm (mon_nr - 1); for (tobl = list->member; tobl; tobl = tobl->next) { otmp = tobl->ob; if (!otmp || !otmp->flag [FLAG_MONSTER]) continue; if (otmp->level <= summon_level && !mon_nr--) return otmp; } /* This should not happen */ LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); return NULL; } int summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) { int nrof = 1; archetype *summon_arch; int ndir; if (spell_ob->other_arch) summon_arch = spell_ob->other_arch; else if (spell_ob->randomitems) { int level = casting_level (caster, spell_ob); treasure *tr, *lasttr = NULL; shstr_cmp sparam (stringarg); /* In old code, this was a very convoluted for statement, * with all the checks in the 'for' portion itself. Much * more readable to break some of the conditions out. */ for (tr = spell_ob->randomitems->items; tr; tr = tr->next) { if (!tr->item) continue; if (level < tr->magic) break; lasttr = tr; if (tr->item->archname == sparam) break; } if (!lasttr) { LOG (llevError, "Treasurelist %s did not generate a valid entry in summon_object\n", &spell_ob->randomitems->name); new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); return 0; } summon_arch = lasttr->item; nrof = lasttr->nrof; } else if (spell_ob->race == shstr_GODCULTMON) { object *god = find_god (determine_god (op)), *mon, *owner; int summon_level, tries; if (!god && ((owner = op->owner) != NULL)) god = find_god (determine_god (owner)); /* If we can't find a god, can't get what monster to summon */ if (!god) return 0; if (!god->race) { new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); return 0; } /* the summon level */ summon_level = casting_level (caster, spell_ob); if (summon_level == 0) summon_level = 1; tries = 0; do { mon = choose_cult_monster (op, god, summon_level); if (!mon) { new_draw_info_format (NDI_UNIQUE, 0, op, "%s fails to send anything.", &god->name); return 0; } ndir = dir; if (!ndir) ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) { ndir = -1; if (++tries == 5) { new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); return 0; } } } while (ndir == -1); if (mon->level > (summon_level / 2)) nrof = random_roll (1, 2, op, PREFER_HIGH); else nrof = die_roll (2, 2, op, PREFER_HIGH); summon_arch = mon->arch; } else summon_arch = 0; if (spell_ob->stats.dam) nrof += spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob); if (!summon_arch) { new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); return 0; } for (int i = 1; i <= nrof; i++) { object *prev = NULL, *head = NULL, *tmp; if (dir) { ndir = dir; dir = absdir (dir + 1); } else ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); sint16 x = freearr_x [ndir]; sint16 y = freearr_y [ndir]; if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y)) { new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); if (nrof > 1) new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); return nrof > 1; } for (archetype *atmp = summon_arch; atmp; atmp = (archetype *)atmp->more) { tmp = atmp->instance (); if (atmp == summon_arch) { if (tmp->flag [FLAG_MONSTER]) { tmp->set_owner (op); set_spell_skill (op, caster, spell_ob, tmp); tmp->enemy = op->enemy; tmp->type = 0; tmp->clr_flag (FLAG_SLEEP); if (op->type == PLAYER || op->flag [FLAG_FRIENDLY]) { /* If this is not set, we make it friendly */ if (!spell_ob->flag [FLAG_MONSTER]) { add_friendly_object (tmp); tmp->stats.exp = 0; if (spell_ob->attack_movement) tmp->attack_movement = spell_ob->attack_movement; if (op->owner) tmp->set_owner (op->owner); } } } if (tmp->has_active_speed ()) tmp->speed_left = -1; } if (head == NULL) head = tmp; else { tmp->head = head; prev->more = tmp; } prev = tmp; tmp->x = op->x + x + tmp->arch->x; tmp->y = op->y + y + tmp->arch->y; tmp->map = op->map; } head->direction = freedir[ndir]; head->stats.exp = 0; head = insert_ob_in_map (head, head->map, op, 0); if (head && head->randomitems) { create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); for (object *tmp = head->inv; tmp; tmp = tmp->below) tmp->set_flag (FLAG_DESTROY_ON_DEATH); } } /* for i < nrof */ return 1; } /* determines if checks so pets don't attack players or other pets should be overruled by the arena petmode */ int should_arena_attack (object *pet, object *owner, object *target) { object *rowner, *towner; /* exit if the target, pet, or owner is null. */ if ((target == NULL) || (pet == NULL) || (owner == NULL)) return 0; /* get the owners of itself and the target, this is to deal with pets of pets */ rowner = owner->outer_owner (); towner = target->is_player () ? 0 : target->outer_owner (); /* if the pet has now owner, exit with error */ if (!rowner) { LOG (llevError, "Pet has no owner.\n"); return 0; } /* if the target is not a player, and has no owner, we shouldn't be here */ if (!towner && !target->is_player ()) { LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); return 0; } /* make sure that the owner is a player */ if (!rowner->is_player ()) return 0; /* abort if the petmode is not arena */ if (rowner->contr->petmode != pet_arena) return 0; /* abort if the pet, it's owner, or the target is not on battleground */ if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) return 0; /* if the target is a monster, make sure it's owner is not the same */ if (!target->is_player () && rowner == towner) return 0; /* check if the target is a player which affects how it will handle parties */ if (!target->is_player ()) { /* if the target is owned by a player make sure than make sure it's not in the same party */ if (towner->is_player () && rowner->contr->party) if (rowner->contr->party == towner->contr->party) return 0; } else { /* if the target is a player make sure than make sure it's not in the same party */ if (rowner->contr->party) if (rowner->contr->party == target->contr->party) return 0; } return 1; }