void init_traps(void) { struct Thing *thing; int i, k; k = 0; const struct StructureList *slist; slist = get_list_for_thing_class(TCls_Trap); i = slist->index; while (i != 0) { thing = thing_get(i); if (thing_is_invalid(thing)) { ERRORLOG("Jump to invalid thing detected"); break; } i = thing->next_of_class; // Per thing code if (thing->trap.num_shots == 0) { rearm_trap(thing); } // Per thing code ends k++; if (k > slist->index) { ERRORLOG("Infinite loop detected when sweeping things list"); break; } } }
struct Thing *select_scavenger_target(const struct Thing *calltng) { long weakpts; struct Thing *weaktng; weaktng = INVALID_THING; weakpts = LONG_MAX; struct Thing *thing; unsigned long k; int i; SYNCDBG(18,"Starting"); const struct StructureList *slist; slist = get_list_for_thing_class(TCls_Creature); k = 0; i = slist->index; while (i != 0) { thing = thing_get(i); if (thing_is_invalid(thing)) { ERRORLOG("Jump to invalid thing detected"); break; } i = thing->next_of_class; // Per-thing code if (thing_is_valid_scavenge_target(calltng, thing)) { SYNCDBG(18,"The %s index %d owner %d is valid target for %s index %d owner %d", thing_model_name(thing),(int)thing->index,(int)thing->owner, thing_model_name(calltng),(int)calltng->index,(int)calltng->owner); struct CreatureControl *cctrl; cctrl = creature_control_get_from_thing(thing); if (game.play_gameturn - cctrl->temple_cure_gameturn > game.temple_scavenge_protection_turns) { long thingpts; thingpts = calculate_correct_creature_scavenge_required(thing, calltng->owner); if (weakpts > thingpts) { weakpts = thingpts; weaktng = thing; } } } // Per-thing code ends k++; if (k > slist->count) { ERRORLOG("Infinite loop detected when sweeping things list"); break; } } SYNCDBG(18,"The weakest valid target for %s index %d owner %d is %s index %d owner %d", thing_model_name(calltng),(int)calltng->index,(int)calltng->owner, thing_model_name(weaktng),(int)weaktng->index,(int)weaktng->owner); return weaktng; }
/** * Returns a hero gate object to which given hero can navigate. * @todo CREATURE_AI It returns first hero door found, not the best one. * Maybe it should find the one he will reach faster, or at least a random one? * @param herotng The hero to be able to make it to gate. * @return The gate thing, or invalid thing. */ struct Thing *find_hero_door_hero_can_navigate_to(struct Thing *herotng) { struct Thing *thing; unsigned long k; int i; k = 0; const struct StructureList *slist; slist = get_list_for_thing_class(TCls_Object); i = slist->index; while (i != 0) { thing = thing_get(i); if (thing_is_invalid(thing)) { ERRORLOG("Jump to invalid thing detected"); break; } i = thing->next_of_class; // Per thing code if (object_is_hero_gate(thing)) { if (creature_can_navigate_to_with_storage(herotng, &thing->mappos, NavRtF_Default)) { return thing; } } // Per thing code ends k++; if (k > slist->count) { ERRORLOG("Infinite loop detected when sweeping things list"); erstat_inc(ESE_InfChainTngPerClass); break; } } return NULL; }
void god_lightning_choose_next_creature(struct Thing *shotng) { SYNCDBG(16,"Starting for %s index %d owner %d",thing_model_name(shotng),(int)shotng->index,(int)shotng->owner); //_DK_god_lightning_choose_next_creature(shotng); return; long best_dist; struct Thing *best_thing; best_dist = LONG_MAX; best_thing = INVALID_THING; unsigned long k; int i; const struct StructureList *slist; slist = get_list_for_thing_class(TCls_Creature); k = 0; i = slist->index; while (i != 0) { struct Thing *thing; thing = thing_get(i); if (thing_is_invalid(thing)) { ERRORLOG("Jump to invalid thing detected"); break; } i = thing->next_of_class; // Per-thing code //TODO use hit_type instead of hard coded conditions if ((shotng->owner != thing->owner) && !thing_is_picked_up(thing) && !creature_is_being_unconscious(thing) && !creature_is_dying(thing)) { long dist; dist = get_2d_distance(&shotng->mappos, &thing->mappos); if (dist < best_dist) { const struct MagicStats *pwrdynst; pwrdynst = get_power_dynamic_stats(PwrK_LIGHTNING); int spell_lev; spell_lev = shotng->shot.byte_19; if (spell_lev > SPELL_MAX_LEVEL) spell_lev = SPELL_MAX_LEVEL; if (subtile_coord(pwrdynst->strength[spell_lev],0) > dist) { if (line_of_sight_2d(&shotng->mappos, &thing->mappos)) { best_dist = dist; best_thing = thing; } } } } // Per-thing code ends k++; if (k > slist->count) { ERRORLOG("Infinite loop detected when sweeping things list"); erstat_inc(ESE_InfChainTngPerClass); break; } } SYNCDBG(8,"The best target for %s index %d owner %d is %s index %d owner %d", thing_model_name(shotng),(int)shotng->index,(int)shotng->owner, thing_model_name(best_thing),(int)best_thing->index,(int)best_thing->owner); if (!thing_is_invalid(best_thing)) { shotng->shot.target_idx = best_thing->index; } else { shotng->shot.target_idx = 0; } }