void player_domestic_trade(gint player_num, gint partner_num, gint * supply, gint * receive) { gchar *supply_desc; gchar *receive_desc; gint diff; gint idx; diff = resource_count(receive) - resource_count(supply); player_modify_statistic(player_num, STAT_RESOURCES, -diff); player_modify_statistic(partner_num, STAT_RESOURCES, diff); if (player_num == my_player_num()) { for (idx = 0; idx < NO_RESOURCE; idx++) { resource_modify(idx, supply[idx]); resource_modify(idx, -receive[idx]); } } else if (partner_num == my_player_num()) { for (idx = 0; idx < NO_RESOURCE; idx++) { resource_modify(idx, -supply[idx]); resource_modify(idx, receive[idx]); } } if (!resource_count(supply)) { if (!resource_count(receive)) { log_message(MSG_TRADE, _("%s gave %s nothing!?\n"), player_name(player_num, TRUE), player_name(partner_num, FALSE)); } else { receive_desc = resource_format_num(receive); log_message(MSG_TRADE, _("%s gave %s %s for free.\n"), player_name(player_num, TRUE), player_name(partner_num, FALSE), receive_desc); g_free(receive_desc); } } else if (!resource_count(receive)) { supply_desc = resource_format_num(supply); log_message(MSG_TRADE, _("%s gave %s %s for free.\n"), player_name(partner_num, TRUE), player_name(player_num, FALSE), supply_desc); g_free(supply_desc); } else { supply_desc = resource_format_num(supply); receive_desc = resource_format_num(receive); log_message(MSG_TRADE, _("%s gave %s %s in exchange for %s.\n"), player_name(player_num, TRUE), player_name(partner_num, FALSE), receive_desc, supply_desc); g_free(supply_desc); g_free(receive_desc); } }
void player_set_current(gint player_num) { turn_player = player_num; if (player_num != my_player_num()) { gchar *buffer; buffer = g_strdup_printf(_("Waiting for %s."), player_name(player_num, FALSE)); callbacks.instructions(buffer); g_free(buffer); return; } build_new_turn(); }
void player_stole_from(gint player_num, gint victim_num, Resource resource) { player_modify_statistic(player_num, STAT_RESOURCES, 1); player_modify_statistic(victim_num, STAT_RESOURCES, -1); if (resource == NO_RESOURCE) { /* CHECK THIS: Since anonymous players (NULL) no longer exist, * player_name doesn't use its static buffer anymore, and * two calls can be safely combined. If not: ai/player.c should also be fixed */ /* FIXME: in the client, anonymous players can exist. * I prefer changing that instead of this function */ log_message(MSG_STEAL, /* We are not in on the action someone stole a resource from someone else */ _("%s stole a resource from %s.\n"), player_name(player_num, TRUE), player_name(victim_num, FALSE)); } else { gchar *buf; buf = resource_cards(1, resource); if (player_num == my_player_num()) { /* We stole a card :-) */ log_message(MSG_STEAL, _("You stole %s from %s.\n"), buf, player_name(victim_num, FALSE)); resource_modify(resource, 1); } else { /* Someone stole our card :-( */ log_message(MSG_STEAL, _("%s stole %s from you.\n"), player_name(player_num, TRUE), buf); resource_modify(resource, -1); } g_free(buf); } callbacks.player_robbed(player_num, victim_num, resource); }
/************************************************************************** Log player messages, they will appear like this where ti is timer, co countdown and lo love for target, who is e. **************************************************************************/ void DIPLO_LOG(int level, const struct player *pplayer, const struct player *aplayer, const char *msg, ...) { char buffer[500]; char buffer2[500]; va_list ap; int minlevel = MIN(LOGLEVEL_PLAYER, level); const struct ai_dip_intel *adip; if (BV_ISSET(pplayer->debug, PLAYER_DEBUG_DIPLOMACY)) { minlevel = LOG_TEST; } else if (minlevel > fc_log_level) { return; } /* Don't use ai_data_get since it can have side effects. */ adip = ai_diplomacy_get(pplayer, aplayer); my_snprintf(buffer, sizeof(buffer), "%s->%s(l%d,c%d,d%d%s): ", player_name(pplayer), player_name(aplayer), pplayer->ai_data.love[player_index(aplayer)], adip->countdown, adip->distance, adip->is_allied_with_enemy ? "?" : (adip->at_war_with_ally ? "!" : "")); va_start(ap, msg); my_vsnprintf(buffer2, sizeof(buffer2), msg, ap); va_end(ap); cat_snprintf(buffer, sizeof(buffer), "%s", buffer2); if (BV_ISSET(pplayer->debug, PLAYER_DEBUG_DIPLOMACY)) { notify_conn(NULL, NULL, E_AI_DEBUG, ftc_log, "%s", buffer); } freelog(minlevel, "%s", buffer); }
void player_build_move(gint player_num, gint sx, gint sy, gint spos, gint dx, gint dy, gint dpos, gint isundo) { Edge *from = map_edge(callbacks.get_map(), sx, sy, spos), *to = map_edge(callbacks.get_map(), dx, dy, dpos); if (isundo) { Edge *tmp = from; from = to; to = tmp; } from->owner = -1; callbacks.draw_edge(from); from->type = BUILD_NONE; to->owner = player_num; to->type = BUILD_SHIP; callbacks.draw_edge(to); if (isundo) log_message(MSG_BUILD, _("%s has cancelled a ship's movement.\n"), player_name(player_num, TRUE)); else log_message(MSG_BUILD, _("%s moved a ship.\n"), player_name(player_num, TRUE)); }
bool const reader::verify () { VERIFY(is_valid()); shared_str const tmp_sign = m_info_section->r_string( ss_info_secion, ss_digital_sign_key); char* jpeg_info_start = static_cast<char*>((void*)(m_jpeg_data + m_info_pos)); jpeg_info_start[0] = 0; strcat_s(jpeg_info_start, m_info_size, player_name().c_str()); strcat_s(jpeg_info_start, m_info_size, player_cdkey_digest().c_str()); //strcat_s(jpeg_info_start, m_info_size, admin_name().c_str()); strcat_s(jpeg_info_start, m_info_size, creation_date().c_str()); u32 jpeg_info_size = xr_strlen(jpeg_info_start) + 1; //ending zero u32 jpeg_full_size = m_info_pos + jpeg_info_size; return m_verifyer.verify (m_jpeg_data, jpeg_full_size, tmp_sign); }
void player_largest_army(gint player_num) { gint idx; if (player_num < 0) log_message(MSG_LARGESTARMY, _("There is no largest army.\n")); else log_message(MSG_LARGESTARMY, _("%s has the largest army.\n"), player_name(player_num, TRUE)); for (idx = 0; idx < num_total_players; idx++) { Player *player = player_get(idx); if (player->statistics[STAT_LARGEST_ARMY] != 0 && idx != player_num) player_modify_statistic(idx, STAT_LARGEST_ARMY, -1); if (player->statistics[STAT_LARGEST_ARMY] == 0 && idx == player_num) player_modify_statistic(idx, STAT_LARGEST_ARMY, 1); } }
void discard_player_must(gint player_num, gint num) { GtkTreeIter iter; GdkPixbuf *pixbuf; enum TFindResult found; /* Search for a place to add information about the player */ found = find_integer_in_tree(GTK_TREE_MODEL(discard_store), &iter, DISCARD_COLUMN_PLAYER_NUM, player_num); switch (found) { case FIND_NO_MATCH: gtk_list_store_append(discard_store, &iter); break; case FIND_MATCH_INSERT_BEFORE: gtk_list_store_insert_before(discard_store, &iter, &iter); break; case FIND_MATCH_EXACT: break; default: g_error("unknown case in discard_player_must"); }; pixbuf = player_create_icon(discard_widget, player_num, TRUE); gtk_list_store_set(discard_store, &iter, DISCARD_COLUMN_PLAYER_ICON, pixbuf, DISCARD_COLUMN_PLAYER_NUM, player_num, DISCARD_COLUMN_PLAYER_NAME, player_name(player_num, TRUE), DISCARD_COLUMN_AMOUNT, num, -1); g_object_unref(pixbuf); if (player_num != my_player_num()) return; discard_create_dlg(num); }
void player_longest_road(gint player_num) { gint idx; if (player_num < 0) log_message(MSG_LONGESTROAD, _("There is no longest road.\n")); else log_message(MSG_LONGESTROAD, _("%s has the longest road.\n"), player_name(player_num, TRUE)); for (idx = 0; idx < num_total_players; idx++) { Player *player = player_get(idx); if (player->statistics[STAT_LONGEST_ROAD] != 0 && idx != player_num) player_modify_statistic(idx, STAT_LONGEST_ROAD, -1); if (player->statistics[STAT_LONGEST_ROAD] == 0 && idx == player_num) player_modify_statistic(idx, STAT_LONGEST_ROAD, 1); } }
/************************************************************************** Place a spaceship part **************************************************************************/ bool do_spaceship_place(struct player *pplayer, bool user_initiated, enum spaceship_place_type type, int num) { struct player_spaceship *ship = &pplayer->spaceship; if (ship->state == SSHIP_NONE) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("Spaceship action received," " but you don't have a spaceship!")); } return FALSE; } if (ship->state >= SSHIP_LAUNCHED) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You can't modify your spaceship after launch!")); } return FALSE; } if (type == SSHIP_PLACE_STRUCTURAL) { if (num < 0 || num >= NUM_SS_STRUCTURALS || BV_ISSET(ship->structure, num)) { return FALSE; } if (num_spaceship_structurals_placed(ship) >= ship->structurals) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You don't have any unplaced Space Structurals!")); } return FALSE; } if (num != 0 && !BV_ISSET(ship->structure, structurals_info[num].required)) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("That Space Structural would not be connected!")); } return FALSE; } BV_SET(ship->structure, num); spaceship_calc_derived(ship); send_spaceship_info(pplayer, NULL); return TRUE; } if (type == SSHIP_PLACE_FUEL) { if (ship->fuel != num - 1) { return FALSE; } if (ship->fuel + ship->propulsion >= ship->components) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You don't have any unplaced Space Components!")); } return FALSE; } if (num > NUM_SS_COMPONENTS/2) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("Your spaceship already has" " the maximum number of Fuel Components!")); } return FALSE; } ship->fuel++; spaceship_calc_derived(ship); send_spaceship_info(pplayer, NULL); return TRUE; } if (type == SSHIP_PLACE_PROPULSION) { if (ship->propulsion != num - 1) { return FALSE; } if (ship->fuel + ship->propulsion >= ship->components) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You don't have any unplaced" " Space Components!")); } return FALSE; } if (num > NUM_SS_COMPONENTS/2) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("Your spaceship already has the" " maximum number of Propulsion Components!")); } return FALSE; } ship->propulsion++; spaceship_calc_derived(ship); send_spaceship_info(pplayer, NULL); return TRUE; } if (type == SSHIP_PLACE_HABITATION) { if (ship->habitation != num - 1) { return FALSE; } if (ship->habitation + ship->life_support + ship->solar_panels >= ship->modules) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You don't have any unplaced Space Modules!")); } return FALSE; } if (num > NUM_SS_MODULES / 3) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("Your spaceship already has the" " maximum number of Habitation Modules!")); } return FALSE; } ship->habitation++; spaceship_calc_derived(ship); send_spaceship_info(pplayer, NULL); return TRUE; } if (type == SSHIP_PLACE_LIFE_SUPPORT) { if (ship->life_support != num - 1) { return FALSE; } if (ship->habitation + ship->life_support + ship->solar_panels >= ship->modules) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You don't have any unplaced Space Modules!")); } return FALSE; } if (num > NUM_SS_MODULES / 3) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("Your spaceship already has the" " maximum number of Life Support Modules!")); } return FALSE; } ship->life_support++; spaceship_calc_derived(ship); send_spaceship_info(pplayer, NULL); return TRUE; } if (type == SSHIP_PLACE_SOLAR_PANELS) { if (ship->solar_panels != num - 1) { return FALSE; } if (ship->habitation + ship->life_support + ship->solar_panels >= ship->modules) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("You don't have any unplaced Space Modules!")); } return FALSE; } if (num > NUM_SS_MODULES / 3) { if (user_initiated) { notify_player(pplayer, NULL, E_SPACESHIP, ftc_server, _("Your spaceship already has the" " maximum number of Solar Panel Modules!")); } return FALSE; } ship->solar_panels++; spaceship_calc_derived(ship); send_spaceship_info(pplayer, NULL); return TRUE; } log_error("Received unknown spaceship place type %d from %s", type, player_name(pplayer)); return FALSE; }
/************************************************************************** Updates the player list dialog. FIXME: use plrdlg_common.c **************************************************************************/ void real_players_dialog_update(void) { if (players_dialog_shell) { int j = 0; Dimension width; static char *namelist_ptrs[MAX_NUM_PLAYERS]; static char namelist_text[MAX_NUM_PLAYERS][256]; const struct player_diplstate *pds; players_iterate(pplayer) { char idlebuf[32], statebuf[32], namebuf[32], dsbuf[32]; /* skip barbarians */ if(is_barbarian(pplayer)) continue; /* text for state */ sz_strlcpy(statebuf, plrdlg_col_state(pplayer)); /* text for idleness */ if(pplayer->nturns_idle>3) { fc_snprintf(idlebuf, sizeof(idlebuf), PL_("(idle %d turn)", "(idle %d turns)", pplayer->nturns_idle - 1), pplayer->nturns_idle - 1); } else { idlebuf[0]='\0'; } /* text for name, plus AI marker */ if (pplayer->ai_controlled) { fc_snprintf(namebuf, sizeof(namebuf), "*%-15s",player_name(pplayer)); } else { fc_snprintf(namebuf, sizeof(namebuf), "%-16s",player_name(pplayer)); } namebuf[16] = '\0'; /* text for diplstate type and turns -- not applicable if this is me */ if (NULL == client.conn.playing || pplayer == client.conn.playing) { strcpy(dsbuf, "-"); } else { pds = player_diplstate_get(client.conn.playing, pplayer); if (pds->type == DS_CEASEFIRE) { fc_snprintf(dsbuf, sizeof(dsbuf), "%s (%d)", diplstate_text(pds->type), pds->turns_left); } else { fc_snprintf(dsbuf, sizeof(dsbuf), "%s", diplstate_text(pds->type)); } } /* assemble the whole lot */ fc_snprintf(namelist_text[j], sizeof(namelist_text[j]), "%-16s %-12s %-8s %-15s %-8s %-6s %-15s%s", namebuf, nation_adjective_for_player(pplayer), get_embassy_status(client.conn.playing, pplayer), dsbuf, get_vision_status(client.conn.playing, pplayer), statebuf, player_addr_hack(pplayer), /* Fixme for multi-conn */ idlebuf); namelist_ptrs[j]=namelist_text[j]; list_index_to_player_index[j] = player_number(pplayer); j++; } players_iterate_end; XawListChange(players_list, namelist_ptrs, j, 0, True); XtVaGetValues(players_list, XtNwidth, &width, NULL); XtVaSetValues(players_label, XtNwidth, width, NULL); } }
int main(int argc, char* argv[]) { struct deck thisDeck; struct player thisPlayer; struct game thisGame; int inputValidity; int menu; int game; int load = 0; //Not Working!!! card_init_deck(&thisDeck); //This is the exact same algorithm used in card.c and it works great here!!! Why!!! for (int k = 0; k < 4; k++) { for (int i = 0; i < 13; i++) { for (int j = 0; j < 4; j++) { strcpy(thisDeck.oneCard[k*52+i*4+j].rank, ranks[i]); strcpy(thisDeck.oneCard[k*52+i*4+j].suit, suits[j]); thisDeck.oneCard[k*52+i*4+j].value = value[i]; } } } card_shuffle(&thisDeck); thisPlayer.chip = 0; system("clear"); while (1) { printf("\n\n**********BlackJack**********\n\n"); printf(" 1. Play\n"); printf(" 2. Load\n"); printf(" 3. Player status\n"); printf(" 4. Exit\n\n"); printf("*****************************\n\n"); while(1) { printf("Please enter menu number: "); inputValidity = scanf("%d", &menu); while(getchar()!='\n'){} if (inputValidity) { if (menu < 1 || menu > 4) { printf("Please select from menu!\n"); } else { break; } } else { printf("Please enter a NUMBER!\n"); } } if (menu == 4) { player_save(&thisPlayer); printf("Thanks for playing! Bye!\n"); break; } else if (menu == 3) { if (thisPlayer.name == NULL) { printf("No player record.\n"); continue; } player_status(&thisPlayer); continue; } else if (menu == 2) { player_load(&thisPlayer); continue; } else { if (thisPlayer.chip == 0) { player_name(&thisPlayer); player_chip(&thisPlayer); } printf("Welcome %s!\nHave fun!\n\n", thisPlayer.name); while(1) { //Deal initial cards game_init(&thisGame); if (thisDeck.cardNow > 180) { printf("\n\nShuffling...\n\n"); card_shuffle(&thisDeck); } if (thisPlayer.chip <= 0) { printf("You are penniless!\n"); thisPlayer.win = 0; thisPlayer.lose = 0; thisPlayer.push = 0; break; } game_bet(1, &thisPlayer, &thisGame); printf("\nDealer is dealing the cards...\n\n"); game_deal_card(2, &thisGame, &thisDeck); game_deal_card(1, &thisGame, &thisDeck); game_deal_card(2, &thisGame, &thisDeck); game_deal_card(1, &thisGame, &thisDeck); printf("Dealer shows %s of %s\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].rank, thisDeck.oneCard[thisGame.dealer_inhand[0]].suit); printf("Dealer\'s point is %d\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].value); printf("Your cards: "); game_print_card(2, &thisGame, &thisDeck); printf("\n"); printf("Your point is %d\n", game_totalvalue(2, &thisGame, &thisDeck)); //Check if dealer shows an Ace if (thisDeck.oneCard[thisGame.dealer_inhand[0]].value == 11) { game_bet(2, &thisPlayer, &thisGame); if (game_totalvalue(1, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) != 4) { if (thisGame.is_insured) { thisPlayer.chip += thisGame.bet; } thisPlayer.lose++; printf("Dealer\'s cards: "); game_print_card(1, &thisGame, &thisDeck); printf("\n"); printf("Dealer\'s point is %d\n", game_totalvalue(1, &thisGame, &thisDeck)); printf("Dealer is BlackJack!\n"); if (game_end()) { break; } else { continue; } } else if (game_totalvalue(2, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) == 4) { thisPlayer.chip += thisGame.bet; thisPlayer.push++; printf("Push!\n"); } } game_play(&thisPlayer, &thisDeck, &thisGame); if (game_end()) { break; } continue; } continue; } } return 0; }
const gchar *my_player_name(void) { return player_name(my_player_num(), TRUE); }
void player_build_remove(gint player_num, BuildType type, gint x, gint y, gint pos) { Edge *edge; Node *node; switch (type) { case BUILD_ROAD: edge = map_edge(callbacks.get_map(), x, y, pos); edge->owner = -1; callbacks.draw_edge(edge); edge->type = BUILD_NONE; log_message(MSG_BUILD, _("%s removed a road.\n"), player_name(player_num, TRUE)); if (player_num == my_player_num()) stock_replace_road(); break; case BUILD_SHIP: edge = map_edge(callbacks.get_map(), x, y, pos); edge->owner = -1; callbacks.draw_edge(edge); edge->type = BUILD_NONE; log_message(MSG_BUILD, _("%s removed a ship.\n"), player_name(player_num, TRUE)); if (player_num == my_player_num()) stock_replace_ship(); break; case BUILD_SETTLEMENT: node = map_node(callbacks.get_map(), x, y, pos); node->type = BUILD_NONE; node->owner = -1; callbacks.draw_node(node); log_message(MSG_BUILD, _("%s removed a settlement.\n"), player_name(player_num, TRUE)); player_modify_statistic(player_num, STAT_SETTLEMENTS, -1); if (player_num == my_player_num()) stock_replace_settlement(); break; case BUILD_CITY: node = map_node(callbacks.get_map(), x, y, pos); node->type = BUILD_SETTLEMENT; node->owner = player_num; callbacks.draw_node(node); log_message(MSG_BUILD, _("%s removed a city.\n"), player_name(player_num, TRUE)); player_modify_statistic(player_num, STAT_SETTLEMENTS, 1); player_modify_statistic(player_num, STAT_CITIES, -1); if (player_num == my_player_num()) { stock_use_settlement(); stock_replace_city(); } break; case BUILD_CITY_WALL: node = map_node(callbacks.get_map(), x, y, pos); node->city_wall = FALSE; node->owner = player_num; callbacks.draw_node(node); log_message(MSG_BUILD, _("%s removed a city wall.\n"), player_name(player_num, TRUE)); player_modify_statistic(player_num, STAT_CITY_WALLS, -1); if (player_num == my_player_num()) stock_replace_city_wall(); break; case BUILD_NONE: log_message(MSG_ERROR, _("" "player_build_remove called with BUILD_NONE for user %s\n"), player_name(player_num, TRUE)); break; case BUILD_BRIDGE: edge = map_edge(callbacks.get_map(), x, y, pos); edge->owner = -1; callbacks.draw_edge(edge); edge->type = BUILD_NONE; log_message(MSG_BUILD, _("%s removed a bridge.\n"), player_name(player_num, TRUE)); if (player_num == my_player_num()) stock_replace_bridge(); break; case BUILD_MOVE_SHIP: /* This clause here to remove a compiler warning. It should not be possible to reach this case. */ g_error("Bug: unreachable code reached"); break; } }
/**************************************************************************** Compares the names of two players in players dialog. ****************************************************************************/ static int cmp_name(const struct player *pplayer1, const struct player *pplayer2) { return fc_stricoll(player_name(pplayer1), player_name(pplayer2)); }
/****************************************************************** The player-name (aka nation leader) column of the plrdlg. *******************************************************************/ static const char *col_name(const struct player *player) { return player_name(player); }