Exemplo n.º 1
0
struct Room *get_hated_room_for_quick_attack(struct Computer2 *comp, long min_hate)
{
    struct THate hates[PLAYERS_COUNT];
    long i;
    SYNCDBG(8,"Starting for player %d",(int)comp->dungeon->owner);
    get_opponent(comp, hates);
    // note that 'i' is not player index, player index is inside THate struct
    for (i=0; i < PLAYERS_COUNT; i++)
    {
        struct THate *hate;
        hate = &hates[i];
        if (players_are_enemies(comp->dungeon->owner, hate->plyr_idx))
        {
            if ((hate->pos_near != NULL) && (hate->amount > min_hate))
            {
                struct Room *room;
                room = get_opponent_room(comp, hate->plyr_idx);
                if (!room_is_invalid(room)) {
                    return room;
                }
            }
        }
    }
    return INVALID_ROOM;
}
Exemplo n.º 2
0
TbBool update_trap_trigger_line_of_sight_90_on_subtile(struct Thing *traptng, MapSubtlCoord stl_x, MapSubtlCoord stl_y)
{
    struct Thing *thing;
    struct Map *mapblk;
    long i;
    unsigned long k;
    mapblk = get_map_block_at(stl_x,stl_y);
    k = 0;
    i = get_mapwho_thing_index(mapblk);
    while (i != 0)
    {
        thing = thing_get(i);
        TRACE_THING(thing);
        if (thing_is_invalid(thing))
        {
            ERRORLOG("Jump to invalid thing detected");
            break;
        }
        i = thing->next_on_mapblk;
        // Per thing code start
        if (thing_is_creature(thing) && (thing->owner != traptng->owner))
        {
            // Trigger for enemy player, or any player for neutral traps (otherwise neutral traps would be useless)
            if (players_are_enemies(traptng->owner,thing->owner) || is_neutral_thing(traptng))
            {
                if (!creature_is_being_unconscious(thing) && !thing_is_dragged_or_pulled(thing)
                 && !creature_is_kept_in_custody_by_enemy(thing) && !creature_is_dying(thing)
                 && ((get_creature_model_flags(thing) & CMF_IsSpectator) == 0)) {
                    activate_trap(traptng, thing);
                    return true;
                }
            }
        }
        // Per thing code end
        k++;
        if (k > THINGS_COUNT)
        {
            ERRORLOG("Infinite loop detected when sweeping things list");
            break;
        }
    }
    return false;
}
Exemplo n.º 3
0
TbBool thing_is_valid_scavenge_target(const struct Thing *calltng, const struct Thing *scavtng)
{
    if (!thing_is_creature(scavtng) || (scavtng->model != calltng->model)) {
        return false;
    }
    if (!is_neutral_thing(scavtng))
    {
        if (!players_are_enemies(calltng->owner, scavtng->owner)) {
            return false;
        }
    }
    if (thing_is_picked_up(scavtng)) {
        return false;
    }
    if (is_thing_passenger_controlled(scavtng) || creature_is_kept_in_custody(scavtng)) {
        return false;
    }
    if (is_hero_thing(scavtng) && (!gameadd.scavenge_good_allowed)) {
        return false;
    }
    if (is_neutral_thing(scavtng) && (!gameadd.scavenge_neutral_allowed)) {
        return false;
    }
    struct PlayerInfo *scavplyr;
    scavplyr = INVALID_PLAYER;
    if (!is_neutral_thing(scavtng)) {
        scavplyr = get_player(scavtng->owner);
    }
    if (scavplyr->controlled_thing_idx != scavtng->index)
    {
        struct CreatureControl *cctrl;
        cctrl = creature_control_get_from_thing(scavtng);
        if (game.play_gameturn - cctrl->temple_cure_gameturn > game.temple_scavenge_protection_turns)
        {
            return true;
        }
    }
    return false;
}
Exemplo n.º 4
0
/**
 * Return index of a dungeon which the hero may attack.
 * @todo CREATURE_AI Shouldn't we support allies with heroes?
 *
 * @param thing The hero searching for target.
 * @return Player index, or -1 if no dungeon to attack found.
 */
long good_find_enemy_dungeon(struct Thing *thing)
{
    struct CreatureControl *cctrl;
    long i;
    SYNCDBG(18,"Starting");
    cctrl = creature_control_get_from_thing(thing);
    if ((cctrl->byte_8C != 0) || (cctrl->byte_8B != 0))
    {
        cctrl->byte_8C = 0;
        cctrl->byte_8B = 0;
        // Try accessing dungeon heart of undefeated enemy players
        for (i = 0; i < PLAYERS_COUNT; i++)
        {
            if (player_is_friendly_or_defeated(i, thing->owner)) {
                continue;
            }
            if (creature_can_get_to_dungeon(thing, i))
            {
                SYNCDBG(8,"The %s index %d can get to enemy player %d",thing_model_name(thing),(int)thing->index,(int)i);
                return i;
            }
        }
        // Try accessing any room of any non allied players
        for (i = 0; i < PLAYERS_COUNT; i++)
        {
            if (!players_are_enemies(thing->owner, i)) {
                continue;
            }
            if (creature_can_get_to_any_of_players_rooms(thing, i))
            {
                SYNCDBG(8,"The %s index %d can get to room of player %d",thing_model_name(thing),(int)thing->index,(int)i);
                return i;
            }
        }
    }
    SYNCDBG(8,"The %s index %d cannot find an enemy",thing_model_name(thing),(int)thing->index);
    return -1;
}