/************************************************************************** Creates the land/sea barbarian player and inits some stuff. If barbarian player already exists, return player pointer. If barbarians are dead, revive them with a new leader :-) Dead barbarians forget the map and lose the money. **************************************************************************/ static struct player *create_barbarian_player(enum barbarian_type type) { struct player *barbarians; struct nation_type *nation; players_iterate(barbarians) { if ((type == LAND_BARBARIAN && is_land_barbarian(barbarians)) || (type == SEA_BARBARIAN && is_sea_barbarian(barbarians))) { if (!barbarians->is_alive) { barbarians->economic.gold = 0; barbarians->is_alive = TRUE; player_status_reset(barbarians); /* Free old name so pick_random_player_name() can select it again. * This is needed in case ruleset defines just one leader for * barbarian nation. */ barbarians->name[0] = '\0'; sz_strlcpy(barbarians->name, pick_random_player_name(nation_of_player(barbarians))); sz_strlcpy(barbarians->username, ANON_USER_NAME); /* I need to make them to forget the map, I think */ whole_map_iterate(ptile) { map_clear_known(ptile, barbarians); } whole_map_iterate_end; } barbarians->economic.gold += 100; /* New leader, new money */ return barbarians; } } players_iterate_end;
/************************************************************************** Returns data from item **************************************************************************/ QVariant plr_item::data(int column, int role) const { QPixmap *pix; struct player_dlg_column *pdc; if (role == Qt::UserRole) { return QVariant::fromValue((void *)ipplayer); } if (role != Qt::DisplayRole) { return QVariant(); } pdc = &player_dlg_columns[column]; switch (player_dlg_columns[column].type) { case COL_FLAG: pix = get_nation_flag_sprite(tileset, nation_of_player(ipplayer))->pm; return *pix; break; case COL_COLOR: return get_player_color(tileset, ipplayer)->qcolor; break; case COL_BOOLEAN: return pdc->bool_func(ipplayer); break; case COL_TEXT: case COL_RIGHT_TEXT: return pdc->func(ipplayer); default: return QVariant(); } return QVariant(); }
/*************************************************************************** ... ***************************************************************************/ Pixmap create_overlay_unit(const struct unit_type *punittype) { Pixmap pm; enum color_std bg_color; pm=XCreatePixmap(display, root_window, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset), display_depth); /* Give tile a background color, based on the type of unit */ /* Should there be colors like COLOR_MAPVIEW_LAND etc? -ev */ switch (unit_color_type(punittype)) { case UNIT_BG_LAND: bg_color = COLOR_OVERVIEW_LAND; break; case UNIT_BG_SEA: bg_color = COLOR_OVERVIEW_OCEAN; break; case UNIT_BG_HP_LOSS: case UNIT_BG_AMPHIBIOUS: bg_color = COLOR_OVERVIEW_MY_UNIT; break; case UNIT_BG_FLYING: bg_color = COLOR_OVERVIEW_ENEMY_CITY; break; default: bg_color = COLOR_OVERVIEW_UNKNOWN; break; } XSetForeground(display, fill_bg_gc, get_color(tileset, bg_color)->color.pixel); XFillRectangle(display, pm, fill_bg_gc, 0,0, tileset_full_tile_width(tileset), tileset_full_tile_height(tileset)); /* If we're using flags, put one on the tile */ if(!solid_color_behind_units) { struct sprite *flag = get_nation_flag_sprite(tileset, nation_of_player(client.conn.playing)); XSetClipOrigin(display, civ_gc, 0,0); XSetClipMask(display, civ_gc, flag->mask); XCopyArea(display, flag->pixmap, pm, civ_gc, 0,0, flag->width,flag->height, 0,0); XSetClipMask(display, civ_gc, None); } /* Finally, put a picture of the unit in the tile */ /* if(i<utype_count()) */ { struct sprite *s = get_unittype_sprite(tileset, punittype, direction8_invalid()); XSetClipOrigin(display,civ_gc,0,0); XSetClipMask(display,civ_gc,s->mask); XCopyArea(display, s->pixmap, pm, civ_gc, 0,0, s->width,s->height, 0,0 ); XSetClipMask(display,civ_gc,None); } return(pm); }
/************************************************************************** Creates the land/sea barbarian player and inits some stuff. If barbarian player already exists, return player pointer. If barbarians are dead, revive them with a new leader :-) Dead barbarians forget the map and lose the money. **************************************************************************/ static struct player *create_barbarian_player(enum barbarian_type type) { struct player *barbarians; struct nation_type *nation; players_iterate(barbarians) { if ((type == LAND_BARBARIAN && is_land_barbarian(barbarians)) || (type == SEA_BARBARIAN && is_sea_barbarian(barbarians))) { if (!barbarians->is_alive) { barbarians->economic.gold = 0; barbarians->is_alive = TRUE; barbarians->is_dying = FALSE; pick_random_player_name(nation_of_player(barbarians), barbarians->name); sz_strlcpy(barbarians->username, ANON_USER_NAME); /* I need to make them to forget the map, I think */ whole_map_iterate(ptile) { map_clear_known(ptile, barbarians); } whole_map_iterate_end; } barbarians->economic.gold += 100; /* New leader, new money */ return barbarians; } } players_iterate_end;
/************************************************************************** Popup (or raise) the short player list dialog version. **************************************************************************/ void popup_players_nations_dialog(void) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_Surface *pLogo = NULL; SDL_String16 *pStr; char cBuf[128], *state; int n = 0, w = 0, units_h = 0; const struct player_diplstate *pDS; SDL_Rect area; if (pShort_Players_Dlg) { return; } pShort_Players_Dlg = fc_calloc(1, sizeof(struct ADVANCED_DLG)); /* TRANS: Nations report title */ pStr = create_str16_from_char(_("Nations") , adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = players_nations_window_dlg_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_WINDOW, pWindow); pShort_Players_Dlg->pEndWidgetList = pWindow; area = pWindow->area; /* ---------- */ /* exit button */ pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"), adj_font(12)); area.w = MAX(area.w, pBuf->size.w + adj_size(10)); pBuf->action = exit_players_nations_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BUTTON, pBuf); /* ---------- */ players_iterate(pPlayer) { if (pPlayer != client.conn.playing) { if(!pPlayer->is_alive || is_barbarian(pPlayer)) { continue; } pDS = player_diplstate_get(client.conn.playing, pPlayer); if(pPlayer->ai_controlled) { state = _("AI"); } else { if (pPlayer->is_connected) { if (pPlayer->phase_done) { state = _("done"); } else { state = _("moving"); } } else { state = _("disconnected"); } } if(pDS->type == DS_CEASEFIRE) { fc_snprintf(cBuf, sizeof(cBuf), "%s(%s) - %d %s", nation_adjective_for_player(pPlayer), state, pDS->turns_left, PL_("turn", "turns", pDS->turns_left)); } else { fc_snprintf(cBuf, sizeof(cBuf), "%s(%s)", nation_adjective_for_player(pPlayer), state); } pStr = create_str16_from_char(cBuf, adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pLogo = get_nation_flag_surface(nation_of_player(pPlayer)); pBuf = create_iconlabel(pLogo, pWindow->dst, pStr, (/*WF_FREE_THEME|*/WF_RESTORE_BACKGROUND|WF_DRAW_TEXT_LABEL_WITH_SPACE)); /* now add some eye candy ... */ switch (pDS->type) { case DS_ARMISTICE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_WAR: if(can_meet_with_player(pPlayer) || can_intel_with_player(pPlayer)) { set_wstate(pBuf, FC_WS_NORMAL); pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR); } else { pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_PLRDLG_WAR_RESTRICTED)); } break; case DS_CEASEFIRE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_PEACE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_ALLIANCE: pBuf->string16->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE); set_wstate(pBuf, FC_WS_NORMAL); break; case DS_NO_CONTACT: pBuf->string16->fgcol = *(get_theme_color(COLOR_THEME_WIDGET_DISABLED_TEXT)); break; default: set_wstate(pBuf, FC_WS_NORMAL); break; } pBuf->string16->bgcol = (SDL_Color) {0, 0, 0, 0}; pBuf->data.player = pPlayer; pBuf->action = player_nation_callback; add_to_gui_list(ID_LABEL, pBuf); area.w = MAX(w, pBuf->size.w); area.h += pBuf->size.h; if (n > 19) { set_wflag(pBuf, WF_HIDDEN); } n++; } } players_iterate_end; pShort_Players_Dlg->pBeginWidgetList = pBuf; pShort_Players_Dlg->pBeginActiveWidgetList = pShort_Players_Dlg->pBeginWidgetList; pShort_Players_Dlg->pEndActiveWidgetList = pWindow->prev->prev; pShort_Players_Dlg->pActiveWidgetList = pShort_Players_Dlg->pEndActiveWidgetList; /* ---------- */ if (n > 20) { units_h = create_vertical_scrollbar(pShort_Players_Dlg, 1, 20, TRUE, TRUE); pShort_Players_Dlg->pScroll->count = n; n = units_h; area.w += n; units_h = 20 * pBuf->size.h; } else { units_h = area.h; } /* ---------- */ area.h = units_h; resize_window(pWindow, NULL, NULL, (pWindow->size.w - pWindow->area.w) + area.w, (pWindow->size.h + pWindow->area.h) + area.h); area = pWindow->area; widget_set_position(pWindow, ((Main.event.motion.x + pWindow->size.w + adj_size(10) < Main.screen->w) ? (Main.event.motion.x + adj_size(10)) : (Main.screen->w - pWindow->size.w - adj_size(10))), ((Main.event.motion.y - adj_size(2) + pWindow->size.h < Main.screen->h) ? (Main.event.motion.y - adj_size(2)) : (Main.screen->h - pWindow->size.h - adj_size(10)))); w = area.w; if (pShort_Players_Dlg->pScroll) { w -= n; } /* exit button */ pBuf = pWindow->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); /* cities */ pBuf = pBuf->prev; setup_vertical_widgets_position(1, area.x, area.y, w, 0, pShort_Players_Dlg->pBeginActiveWidgetList, pBuf); if (pShort_Players_Dlg->pScroll) { setup_vertical_scrollbar_area(pShort_Players_Dlg->pScroll, area.x + area.w, area.y, area.h, TRUE); } /* -------------------- */ /* redraw */ redraw_group(pShort_Players_Dlg->pBeginWidgetList, pWindow, 0); widget_mark_dirty(pWindow); flush_dirty(); }
/************************************************************************** Popup (or raise) the player list dialog. **************************************************************************/ void popup_players_dialog(bool raise) { struct widget *pWindow = NULL, *pBuf = NULL; SDL_Surface *pLogo = NULL, *pZoomed = NULL; SDL_String16 *pStr; SDL_Rect dst; int i, n, h; double a, b, r; SDL_Rect area; if (pPlayers_Dlg) { return; } n = 0; players_iterate(pPlayer) { if(is_barbarian(pPlayer)) { continue; } n++; } players_iterate_end; if(n < 2) { return; } pPlayers_Dlg = fc_calloc(1, sizeof(struct SMALL_DLG)); pStr = create_str16_from_char(_("Players"), adj_font(12)); pStr->style |= TTF_STYLE_BOLD; pWindow = create_window_skeleton(NULL, pStr, 0); pWindow->action = players_window_dlg_callback; set_wstate(pWindow, FC_WS_NORMAL); add_to_gui_list(ID_WINDOW, pWindow); pPlayers_Dlg->pEndWidgetList = pWindow; /* ---------- */ /* exit button */ pBuf = create_themeicon(pTheme->Small_CANCEL_Icon, pWindow->dst, WF_WIDGET_HAS_INFO_LABEL | WF_RESTORE_BACKGROUND); pBuf->info_label = create_str16_from_char(_("Close Dialog (Esc)"), adj_font(12)); pBuf->action = exit_players_dlg_callback; set_wstate(pBuf, FC_WS_NORMAL); pBuf->key = SDLK_ESCAPE; add_to_gui_list(ID_BUTTON, pBuf); /* ---------- */ for(i = 0; i<DS_LAST; i++) { switch (i) { case DS_ARMISTICE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_NEUTRAL_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_neutral_status_callback; pBuf->key = SDLK_n; break; case DS_WAR: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_WAR_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_war_status_callback; pBuf->key = SDLK_w; break; case DS_CEASEFIRE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_CEASEFIRE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_ceasefire_status_callback; pBuf->key = SDLK_c; break; case DS_PEACE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_PEACE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_pease_status_callback; pBuf->key = SDLK_p; break; case DS_ALLIANCE: pBuf = create_checkbox(pWindow->dst, (SDL_Client_Flags & CF_DRAW_PLAYERS_ALLIANCE_STATUS), WF_RESTORE_BACKGROUND); pBuf->action = toggle_draw_alliance_status_callback; pBuf->key = SDLK_a; break; default: /* no contact */ continue; break; } set_wstate(pBuf, FC_WS_NORMAL); add_to_gui_list(ID_CHECKBOX, pBuf); } /* ---------- */ players_iterate(pPlayer) { if(is_barbarian(pPlayer)) { continue; } pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= (TTF_STYLE_BOLD|SF_CENTER); pLogo = get_nation_flag_surface(nation_of_player(pPlayer)); { /* Aim for a flag height of 60 pixels, but draw smaller flags if there * are more players */ double zoom = DEFAULT_ZOOM * (60.0 - n) / pLogo->h; pZoomed = zoomSurface(pLogo, zoom, zoom, 1); } pBuf = create_icon2(pZoomed, pWindow->dst, WF_RESTORE_BACKGROUND | WF_WIDGET_HAS_INFO_LABEL | WF_FREE_THEME); pBuf->info_label = pStr; if(!pPlayer->is_alive) { pStr = create_str16_from_char(_("R.I.P.") , adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_TEXT); pLogo = create_text_surf_from_str16(pStr); FREESTRING16(pStr); dst.x = (pZoomed->w - pLogo->w) / 2; dst.y = (pZoomed->h - pLogo->h) / 2; alphablit(pLogo, NULL, pZoomed, &dst); FREESURFACE(pLogo); } if(pPlayer->is_alive) { set_wstate(pBuf, FC_WS_NORMAL); } pBuf->data.player = pPlayer; pBuf->action = player_callback; add_to_gui_list(ID_LABEL, pBuf); } players_iterate_end; pPlayers_Dlg->pBeginWidgetList = pBuf; resize_window(pWindow, NULL, NULL, adj_size(500), adj_size(400)); area = pWindow->area; r = MIN(area.w, area.h); r -= ((MAX(pBuf->size.w, pBuf->size.h) * 2)); r /= 2; a = (2.0 * M_PI) / n; widget_set_position(pWindow, (Main.screen->w - pWindow->size.w) / 2, (Main.screen->h - pWindow->size.h) / 2); /* exit button */ pBuf = pWindow->prev; pBuf->size.x = area.x + area.w - pBuf->size.w - 1; pBuf->size.y = pWindow->size.y + adj_size(2); n = area.y; pStr = create_string16(NULL, 0, adj_font(10)); pStr->style |= TTF_STYLE_BOLD; pStr->bgcol = (SDL_Color) {0, 0, 0, 0}; for(i = 0; i<DS_LAST; i++) { switch (i) { case DS_ARMISTICE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ARMISTICE); break; case DS_WAR: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_WAR); break; case DS_CEASEFIRE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_CEASEFIRE); break; case DS_PEACE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_PEACE); break; case DS_ALLIANCE: pStr->fgcol = *get_theme_color(COLOR_THEME_PLRDLG_ALLIANCE); break; default: /* no contact */ continue; break; } copy_chars_to_string16(pStr, diplstate_type_translated_name(i)); pLogo = create_text_surf_from_str16(pStr); pBuf = pBuf->prev; h = MAX(pBuf->size.h, pLogo->h); pBuf->size.x = area.x + adj_size(5); pBuf->size.y = n + (h - pBuf->size.h) / 2; dst.x = adj_size(5) + pBuf->size.w + adj_size(6); dst.y = n + (h - pLogo->h) / 2; alphablit(pLogo, NULL, pWindow->theme, &dst); n += h; FREESURFACE(pLogo); } FREESTRING16(pStr); /* first player shield */ pBuf = pBuf->prev; pBuf->size.x = area.x + area.w / 2 - pBuf->size.w / 2; pBuf->size.y = area.y + area.h / 2 - r - pBuf->size.h / 2; n = 1; if(pBuf != pPlayers_Dlg->pBeginWidgetList) { do{ pBuf = pBuf->prev; b = M_PI_2 + n * a; pBuf->size.x = area.x + area.w / 2 - r * cos(b) - pBuf->size.w / 2; pBuf->size.y = area.y + area.h / 2 - r * sin(b) - pBuf->size.h / 2; n++; } while(pBuf != pPlayers_Dlg->pBeginWidgetList); } players_dialog_update(); }