Ejemplo n.º 1
0
static void getpreviouscb(RDArmem *member,RDATData *previous)
{
	short keyno=(-1);

	keyno=KEYNUMBER(MASTER->passkey->fileno,(member->rscrname+9));
	if(keyno==(-1)) keyno=MASTER->passkey->keyno;
	GET_PREVIOUS(member->parent,MASTER,previous,SCRNvirtualSubData,member->parent,keyno);
}
Ejemplo n.º 2
0
void init_player(int player, int option) {
    int i, num;
    struct action_node *next;

    if (option != INIT_PLAYER_INACTIVE)
        players[player].active = 1;
    else
        players[player].active = 0;

    if (option != INIT_PLAYER_RESET) {
        switch (option) {
        case INIT_PLAYER_HUMAN:
            sprintf(GET_NAME(player), "Player %d", get_active_players());
            players[player].ai = 0;
            players[player].portrait = LEADER_RONNIE;
            break;
        case INIT_PLAYER_AI:
            players[player].ai = 1;
            while (1) {
                /* select a random leader but check so it doesn't exist already */
                num = randomize(0, NUM_LEADERS - 1);
                if (player_name_available((char *)leader_names[num]))
                    break;	/*	end while-loop	*/
            }
            strcpy(GET_NAME(player), leader_names[num]);
            players[player].portrait = num;
            break;
        }
        memset(players[player].msg, 0, MAX_MESSAGE_LENGTH+1);
        players[player].msg_timer = 0;
    }

    /* population */
    if (option != INIT_PLAYER_RESET || server) {
        for (i = 0; i < NUM_CITIES; i++) {
            if (option == INIT_PLAYER_INACTIVE)
                GET_POPULATION(player, i) = 0;
            else
                GET_POPULATION(player, i) = randomize(10, 35);
            GET_WORLD(player, i) = GET_POPULATION(player, i);	/*	world state	*/
        }
    }

    /* weapons */
    for (i = 0; i < NUM_WEAPONS; i++)
        GET_STOCK(player, i) = 0;
    GET_STOCK(player, WEAPON_MISSILE_10MT) = 1;
    GET_STOCK(player, WEAPON_WARHEAD_10MT) = 1;
    GET_STOCK(player, WEAPON_LNDS) = 1;

    /* free action list */
    while (players[player].action_list != NULL) {
        next = players[player].action_list->next;
        free(players[player].action_list);
        players[player].action_list = next;
    }

    GET_PREVIOUS(player) = ACTION_NOTHING;
    GET_MISSILE(player) = -1;
    GET_BOMBER(player) = -1;

    GET_WORLD_MISSILE(player) = 0;
    GET_WORLD_BOMBER(player) = 0;
}
Ejemplo n.º 3
0
/* execute selected actions */
void do_actions() {
    int i, missile, bomber, i2;
    struct action_node *action;

    for (i = 0; i < NUM_PLAYERS; i++) {
        if (IS_ACTIVE(i)) {
            action = find_action(i, current_turn);
            if (action) {
                missile = -1;
                bomber = -1;
                switch (action->action) {
                case ACTION_BUILD:
                    if (has_cities(i, 0))
                        do_build(i);
                    break;
                case ACTION_PROPAGANDA:
                    if (has_cities(i, 0)) {
                        do_propaganda(i);
                        /* random message */
                        if (i == me && players[action->target_player].ai)
                            ai_random_message(action->target_player);
                    }
                    break;
                case ACTION_MISSILE_10MT:
                case ACTION_MISSILE_20MT:
                case ACTION_MISSILE_50MT:
                case ACTION_MISSILE_100MT:
                    if (has_cities(i, 0)) {
                        do_missile(i);
                        missile = action->action - ACTION_MISSILE_10MT;
                    }
                    break;
                case ACTION_WARHEAD_10MT:
                case ACTION_WARHEAD_20MT:
                case ACTION_WARHEAD_50MT:
                case ACTION_WARHEAD_100MT:
                    do_nuke(i);
                    if (!players[i].ai)
                        bomber = GET_BOMBER(i);	/*	don't unset so we can reuse the bomber	*/
                    else {
                        if (players[i].mt_left) {
                            /* check if the ai player has a warhead and enough capacity to reuse the bomber */
                            for (i2 = 0; i2 < 4; i2++) {
                                if (GET_STOCK(i, WEAPON_WARHEAD_10MT + i2) && megatons[i2] <= players[i].mt_left)
                                    bomber = GET_BOMBER(i);
                            }
                        }
                    }
                    /* random message */
                    if (i == me && players[action->target_player].ai && has_cities(me, 0))
                        ai_random_message(action->target_player);
                    break;
                case ACTION_NP1:
                case ACTION_GR2:
                    if (has_cities(i, 0)) {
                        do_bomber(i);
                        bomber = action->action - ACTION_NP1;
                    }
                    break;
                case ACTION_LNDS:
                case ACTION_MEGA:
                    if (has_cities(i, 0))
                        do_defense(i);
                    break;
                }

                GET_PREVIOUS(i) = action->action;	/*	remember action for next turn	*/
                GET_MISSILE(i) = missile;
                GET_BOMBER(i) = bomber;
            }
        }
    }
}