Beispiel #1
0
void process_armageddon(void)
{
    struct PlayerInfo *player;
    struct Dungeon *dungeon;
    struct Thing *heartng;
    long i;
    SYNCDBG(6,"Starting");
    //_DK_process_armageddon(); return;
    if (game.armageddon_cast_turn == 0)
        return;
    if (game.armageddon.count_down+game.armageddon_cast_turn > game.play_gameturn)
    {
        if (player_cannot_win(game.armageddon_caster_idx))
        {
            // Stop the armageddon if its originator is just losing
            game.armageddon_cast_turn = 0;
        }
    } else
    if (game.armageddon.count_down+game.armageddon_cast_turn == game.play_gameturn)
    {
        for (i=0; i < PLAYERS_COUNT; i++)
        {
            player = get_player(i);
            if (player_exists(player))
            {
              if (player->field_2C == 1)
                reveal_whole_map(player);
            }
        }
    } else
    if (game.armageddon.count_down+game.armageddon_cast_turn < game.play_gameturn)
    {
        for (i=0; i < PLAYERS_COUNT; i++)
        {
            player = get_player(i);
            if ( (player_exists(player)) && (player->field_2C == 1) )
            {
                dungeon = get_dungeon(player->id_number);
                if ((player->victory_state == VicS_Undecided) && (dungeon->num_active_creatrs == 0))
                {
                    event_kill_all_players_events(i);
                    set_player_as_lost_level(player);
                    if (is_my_player_number(i))
                        LbPaletteSet(engine_palette);
                    heartng = get_player_soul_container(player->id_number);
                    if (thing_exists(heartng)) {
                        heartng->health = -1;
                    }
                }
            }
        }
    }
}
PerPlayerFlags action_point_get_players_within(long apt_idx)
{
    //return _DK_action_point_get_players_within(apt_idx);
    struct ActionPoint *apt;
    apt = action_point_get(apt_idx);
    PerPlayerFlags activated;
    activated = apt->activated;
    PlayerNumber plyr_idx;
    for (plyr_idx=0; plyr_idx < PLAYERS_COUNT; plyr_idx++)
    {
        struct PlayerInfo *player;
        player = get_player(plyr_idx);
        if (player_exists(player))
        {
            if ((activated & (1 << plyr_idx)) == 0)
            {
                struct Dungeon *dungeon;
                dungeon = get_players_dungeon(player);
                if (dungeon_invalid(dungeon)) {
                    continue;
                }
                SYNCDBG(16,"Checking player %d",(int)plyr_idx);
                if (action_point_is_creature_from_list_within(apt, dungeon->digger_list_start)) {
                    activated |= (1 << plyr_idx);
                    continue;
                }
                if (action_point_is_creature_from_list_within(apt, dungeon->creatr_list_start)) {
                    activated |= (1 << plyr_idx);
                    continue;
                }
            }
        }
    }
    return activated;
}
struct Thing *create_crate_in_workshop(struct Room *room, ThingModel cratngmodel, MapSubtlCoord stl_x, MapSubtlCoord stl_y)
{
    struct Coord3d pos;
    struct Thing *cratetng;
    if (!room_role_matches(room->kind, RoRoF_CratesStorage)) {
        SYNCDBG(4,"Crate %s cannot be created in a %s owned by player %d, wrong room",object_code_name(cratngmodel),room_code_name(room->kind),(int)room->owner);
        return INVALID_THING;
    }
    pos.x.val = subtile_coord_center(stl_x);
    pos.y.val = subtile_coord_center(stl_y);
    pos.z.val = 0;
    cratetng = create_object(&pos, cratngmodel, room->owner, -1);
    if (thing_is_invalid(cratetng))
    {
        return INVALID_THING;
    }
    // Neutral thing do not need any more processing
    if (is_neutral_thing(cratetng) || !player_exists(get_player(room->owner))) {
        return cratetng;
    }
    if (!add_workshop_object_to_workshop(room, cratetng)) {
        ERRORLOG("Could not fit %s in %s index %d",
            thing_model_name(cratetng),room_code_name(room->kind),(int)room->index);
        //remove_item_from_room_capacity(room); -- no need, it was not added
        destroy_object(cratetng);
        return INVALID_THING;
    }
    ThingClass tngclass;
    ThingModel tngmodel;
    tngclass = crate_thing_to_workshop_item_class(cratetng);
    tngmodel = crate_thing_to_workshop_item_model(cratetng);
    add_workshop_item_to_amounts(cratetng->owner, tngclass, tngmodel);
    return cratetng;
}
TbBool good_setup_wander_to_dungeon_heart(struct Thing *creatng, PlayerNumber plyr_idx)
{
    struct PlayerInfo *player;
    SYNCDBG(18,"Starting");
    TRACE_THING(creatng);
    if (creatng->owner == plyr_idx)
    {
        ERRORLOG("The %s tried to wander to own (%d) heart", thing_model_name(creatng), (int)plyr_idx);
        return false;
    }
    player = get_player(plyr_idx);
    if (!player_exists(player))
    {
        WARNLOG("The %s tried to wander to inactive player (%d) heart", thing_model_name(creatng), (int)plyr_idx);
        return false;
    }
    struct Thing *heartng;
    heartng = get_player_soul_container(plyr_idx);
    TRACE_THING(heartng);
    if (thing_is_invalid(heartng))
    {
        WARNLOG("The %s tried to wander to player %d which has no heart", thing_model_name(creatng), (int)plyr_idx);
        return false;
    }
    set_creature_object_combat(creatng, heartng);
    return true;
}
Beispiel #5
0
TbBool attempt_anger_job_join_enemy(struct Thing *creatng)
{
    struct Thing *heartng;
    int i, n;
    n = ACTION_RANDOM(PLAYERS_COUNT);
    for (i=0; i < PLAYERS_COUNT; i++, n=(n+1)%PLAYERS_COUNT)
    {
        if ((n == game.neutral_player_num) || (n == creatng->owner))
            continue;
        struct PlayerInfo *player;
        player = get_player(n);
        if (!player_exists(player) || (player->field_2C != 1))
            continue;
        heartng = get_player_soul_container(n);
        if (thing_exists(heartng) && (heartng->active_state != 3))
        {
            TRACE_THING(heartng);
            if (creature_can_navigate_to(creatng, &heartng->mappos, NavRtF_Default)) {
                change_creature_owner(creatng, n);
                anger_set_creature_anger_all_types(creatng, 0);
            }
        }
    }
    return false;
}
Beispiel #6
0
/**
 * Informs if players plyr1_idx and plyr2_idx are mutual allies.
 * If the players are not mutual allies, one side can still consider they're friends.
 * @param plyr1_idx Index of the first player.
 * @param plyr2_idx Index of the second player.
 * @return True if the players are mutual allies; false otherwise.
 */
TbBool players_are_mutual_allies(PlayerNumber plyr1_idx, PlayerNumber plyr2_idx)
{
    struct PlayerInfo *player1,*player2;
    // Player is always his own ally
    if (plyr1_idx == plyr2_idx)
        return true;
    // And neutral player can't be allied
    if ((plyr1_idx == game.neutral_player_num) || (plyr2_idx == game.neutral_player_num))
        return false;
    player1 = get_player(plyr1_idx);
    player2 = get_player(plyr2_idx);
    // Inactive or invalid players are not allies
    if (!player_exists(player1))
        return false;
    if (!player_exists(player2))
        return false;
    return ((player1->allied_players & (1<<plyr2_idx)) != 0)
        && ((player2->allied_players & (1<<plyr1_idx)) != 0);
}
Beispiel #7
0
TbBool player_uses_power_sight(PlayerNumber plyr_idx)
{
    struct PlayerInfo *player;
    player = get_player(plyr_idx);
    if (!player_exists(player)) {
        return false;
    }
    struct Dungeon *dungeon;
    dungeon = get_players_dungeon(player);
    return (dungeon->sight_casted_thing_idx > 0);
}
Beispiel #8
0
TbBool player_uses_power_obey(PlayerNumber plyr_idx)
{
    struct PlayerInfo *player;
    player = get_player(plyr_idx);
    if (!player_exists(player)) {
        return false;
    }
    struct Dungeon *dungeon;
    dungeon = get_players_dungeon(player);
    return (dungeon->must_obey_turn != 0);
}
Beispiel #9
0
/**
 * Informs if player plyr1_idx considers player plyr2_idx as enemy.
 * Note that if the players are not enemies, it doesn't necessarily mean they're friends.
 * @param origin_plyr_idx Index of the player who asks for an enemy.
 * @param check_plyr_idx Index of the player who could be enemy.
 * @return True if the players are enemies; false otherwise.
 */
TbBool players_are_enemies(long origin_plyr_idx, long check_plyr_idx)
{
    struct PlayerInfo *origin_player,*check_player;
    // Player can't be his own enemy
    if (origin_plyr_idx == check_plyr_idx)
        return false;
    // And neutral player can't be enemy
    if ((origin_plyr_idx == game.neutral_player_num) || (check_plyr_idx == game.neutral_player_num))
        return false;
    origin_player = get_player(origin_plyr_idx);
    check_player = get_player(check_plyr_idx);
    // Inactive or invalid players are not enemies, as long as they're not heroes
    // (heroes are normally NOT existing keepers)
    if (!player_exists(origin_player) && (origin_plyr_idx != game.hero_player_num))
        return false;
    if (!player_exists(check_player) && (check_plyr_idx != game.hero_player_num))
        return false;
    // And if they're valid, living players - get result from alliances table
    return ((origin_player->allied_players & (1<<check_plyr_idx)) == 0);
}
Beispiel #10
0
TbBool player_uses_power_hold_audience(PlayerNumber plyr_idx)
{
    struct PlayerInfo *player;
    player = get_player(plyr_idx);
    if (!player_exists(player)) {
        return false;
    }
    struct Dungeon *dungeon;
    dungeon = get_players_dungeon(player);
    return (dungeon->hold_audience_cast_turn != 0);
}
Beispiel #11
0
void setup_alliances(void)
{
  int i;
  struct PlayerInfo *player;
  for (i=0; i<PLAYERS_COUNT; i++)
  {
      player = get_player(i);
      if (!is_my_player_number(i) && player_exists(player))
      {
          if (frontend_is_player_allied(my_player_number, i))
          {
              set_ally_with_player(my_player_number, i, true);
              set_ally_with_player(i, my_player_number, true);
          }
      }
  }
}
Beispiel #12
0
/**
 * Checks if given player is either friendly to origin player or defeated.
 * @param check_plyr_idx
 * @param origin_plyr_idx
 * @return
 */
TbBool player_is_friendly_or_defeated(PlayerNumber check_plyr_idx, PlayerNumber origin_plyr_idx)
{
    struct PlayerInfo *player;
    struct PlayerInfo *win_player;
    // Handle neutral player at first, because we can't get PlayerInfo nor Dungeon for it
    if ((origin_plyr_idx == game.neutral_player_num) || (check_plyr_idx == game.neutral_player_num))
        return true;
    player = get_player(check_plyr_idx);
    win_player = get_player(origin_plyr_idx);
    if (player_exists(player))
    {
        if ( (!player_allied_with(win_player, check_plyr_idx)) || (!player_allied_with(player, origin_plyr_idx)) )
        {
            if (player_has_heart(check_plyr_idx))
              return false;
        }
    }
    return true;
}
Beispiel #13
0
/**
 * Updates scores for existing players.
 * @return Gives the amount of players for which stats were set successfully.
 */
long update_dungeons_scores(void)
{
    int i,k;
    k = 0;
    for (i=0; i < PLAYERS_COUNT; i++)
    {
        struct PlayerInfo *player;
        player = get_player(i);
        if (!player_exists(player))
            continue;
        if (player->field_2C == 1)
        {
            if (update_dungeon_scores_for_player(player)) {
                k++;
            }
        }
    }
    return k;
}
TbBool good_can_move_to_dungeon_heart(struct Thing *creatng, PlayerNumber plyr_idx)
{
    struct PlayerInfo *player;
    SYNCDBG(18,"Starting");
    TRACE_THING(creatng);
    player = get_player(plyr_idx);
    if (!player_exists(player))
    {
        SYNCDBG(3,"The %s cannot move to inactive player %d heart", thing_model_name(creatng), (int)plyr_idx);
        return false;
    }
    struct Thing *heartng;
    heartng = get_player_soul_container(plyr_idx);
    TRACE_THING(heartng);
    if (thing_is_invalid(heartng))
    {
        SYNCDBG(3,"The %s cannot move to player %d which has no heart", thing_model_name(creatng), (int)plyr_idx);
        return false;
    }
    return creature_can_navigate_to(creatng, &heartng->mappos, NavRtF_Default);
}
/**
 * Returns if a creature can get to given players dungeon.
 * @param thing
 * @param plyr_idx
 * @return
 * @see creature_can_get_to_any_of_players_rooms() is a function used in similar manner.
 */
TbBool creature_can_get_to_dungeon(struct Thing *creatng, PlayerNumber plyr_idx)
{
    struct PlayerInfo *player;
    struct Thing *heartng;
    SYNCDBG(18,"Starting");
    player = get_player(plyr_idx);
    if (!player_exists(player) || (player->field_2C != 1))
    {
        SYNCDBG(18,"The %s index %d cannot get to inactive player %d",thing_model_name(creatng),(int)creatng->index,(int)plyr_idx);
        return false;
    }
    heartng = get_player_soul_container(player->id_number);
    if (thing_is_invalid(heartng))
    {
        SYNCDBG(18,"The %s index %d cannot get to player %d without heart",thing_model_name(creatng),(int)creatng->index,(int)plyr_idx);
        return false;
    }
    if (heartng->active_state == ObSt_BeingDestroyed)
    {
        SYNCDBG(18,"The %s index %d cannot get to player %d due to heart state",thing_model_name(creatng),(int)creatng->index,(int)plyr_idx);
        return false;
    }
    return creature_can_navigate_to(creatng, &heartng->mappos, NavRtF_Default);
}
Beispiel #16
0
long computer_checks_hates(struct Computer2 *comp, struct ComputerCheck * check)
{
    struct Dungeon *compdngn;
    SYNCDBG(8,"Starting");
    //return _DK_computer_checks_hates(comp, check);
    compdngn = comp->dungeon;
    // Reference values for checking hate
    int cdngn_creatrs, cdngn_spdiggrs, cdngn_enrancs;
    cdngn_creatrs = count_creatures_in_dungeon(compdngn);
    cdngn_spdiggrs = count_diggers_in_dungeon(compdngn);
    cdngn_enrancs = count_entrances(comp, compdngn->owner);
    // Now check hate for every player
    int i;
    for (i=0; i < PLAYERS_COUNT; i++)
    {
        struct PlayerInfo *player;
        struct Dungeon *dungeon;
        struct Comp2_UnkStr1 *rel;
        player = get_player(i);
        dungeon = get_players_dungeon(player);
        rel = &comp->unkarr_A10[i];
        if (!player_exists(player) || (player->id_number == compdngn->owner)
         || (player->id_number == game.neutral_player_num))
            continue;
        if (player->field_2C != 1)
            continue;
        if (players_are_mutual_allies(compdngn->owner, i))
            continue;
        int hdngn_creatrs, hdngn_spdiggrs, hdngn_enrancs;
        int hate_reasons;
        hate_reasons = 0;
        hdngn_creatrs = count_creatures_in_dungeon(dungeon);
        hdngn_spdiggrs = count_diggers_in_dungeon(dungeon);
        // Computers hate players who have more creatures than them
        if (hdngn_creatrs >= cdngn_creatrs)
        {
            hate_reasons++;
            rel->hate_amount++;
        }
        // Computers hate players who have more special diggers than them
        if (cdngn_spdiggrs / 6 + cdngn_spdiggrs < hdngn_spdiggrs)
        {
            hate_reasons++;
            rel->hate_amount++;
        }
        // Computers hate players who can build more rooms than them
        if (((int)compdngn->total_rooms + (int)compdngn->total_rooms / 6) < (int)dungeon->total_rooms)
        {
            hate_reasons++;
            rel->hate_amount++;
        }
        // Computers highly hate players who claimed more entrances than them
        hdngn_enrancs = count_entrances(comp, i);
        if (hdngn_enrancs > cdngn_enrancs)
        {
            hate_reasons++;
            rel->hate_amount += 5;
        }
        // If no reason to hate the player - hate him randomly for just surviving that long
        if ((hate_reasons <= 0) && (check->param1 < game.play_gameturn))
        {
            if (ACTION_RANDOM(100) < 20) {
                rel->hate_amount++;
            }
        }
    }
    return 4;
}
Beispiel #17
0
int main(int argc, char *argv[])
{
    // An array of 4 players, may need to be a pointer if you want it set dynamically
    player players[NUM_PLAYERS];
    
    // Input buffer and and commands
    //char buffer[BUFFER_LEN] = { 0 };

    // Display the game introduction and initialize the questions
    initialize_game();

    // Prompt for players names
    printf("This is Jeopardy \n");

    // initialize each of the players in the array
    for(int i = 0; i < 4; i++) {
        players[i].score = 0;

        printf("Enter player name: ");
        scanf("%s", (char *) &players[i].name);
    }

    // Perform an infinite loop getting command input from users until game ends
    //while (fgets(buffer, BUFFER_LEN, stdin) != NULL)
    while(!answered_status())
    {
        system("clear");

        char selected_player[MAX_LEN] = "";
        char selected_category[MAX_LEN] = "";
        int selected_val = 0;

        do {
            if(strcmp(selected_player, "") != 0)
                printf("The player %s was not found", selected_player);

            printf("Enter first player's name: ");
            scanf("%s", (char *) &selected_player);
        } while(!player_exists(players, 4, selected_player));

        do {
            if(selected_val != 0)
                printf("Invalid selection");

            printf("Enter category: ");
            getchar();
            fgets((char *) selected_category, MAX_LEN, stdin);
            strtok(selected_category, "\n");

            printf("Enter: ");
            scanf("%d", (int *) &selected_val);
        } while(already_answered(selected_category, selected_val));


        system("clear");
        display_question(selected_category, selected_val);

        char *answer[MAX_LEN] = {0};
        getchar();
        fgets((char *) answer, MAX_LEN, stdin);

        char *tokenize_answer;
        tokenize((char *) answer, &tokenize_answer);

        if(tokenize_answer == NULL)
            printf("Try again");
        else if(valid_answer(selected_category, selected_val, tokenize_answer)) {
            printf("Correct Answer!");
            printf("%s gains %d points \n", selected_player, selected_val);
            update_score(players, 4, selected_player, selected_val);
        } else {
            printf("Wrong Answer!");
            int num = get_question_number(selected_category, selected_val);
            printf("Correct answer was: %s", questions[num].answer);
        }

        track_answered(selected_category, selected_val);

        // Call functansions from the questions and players source files

        // Execute the game until all questions are answered

        // Display the final results and exit
    }

    show_results(players, 4);
    getchar();

    return EXIT_SUCCESS;
}