void TradeManager::UpdateAdviceWindow() { Assert(m_adviceWindow); if(!m_adviceWindow) return; ctp2_Button *showButton = (ctp2_Button *)aui_Ldl::GetObject(s_tradeManagerBlock, "ShowAdviceButton"); if(showButton) { if(g_c3ui->GetWindow(m_adviceWindow->Id())) { showButton->SetText(g_theStringDB->GetNameStr("str_ldl_TradeHideAdvisor")); } else { showButton->SetText(g_theStringDB->GetNameStr("str_ldl_TradeShowAdvisor")); } } MBCHAR buf[20]; sint32 pl = g_selected_item->GetVisiblePlayer(); if(!g_player[pl]) return; ctp2_Static *child = (ctp2_Static *)aui_Ldl::GetObject(s_tradeAdviceBlock, "Available"); if(child) { sprintf(buf, "%d", g_player[pl]->m_tradeTransportPoints - g_player[pl]->m_usedTradeTransportPoints); child->SetText(buf); } child = (ctp2_Static *)aui_Ldl::GetObject(s_tradeAdviceBlock, "InUse"); if(child) { sprintf(buf, "%d", g_player[pl]->m_usedTradeTransportPoints); child->SetText(buf); } sint32 i, totalProfit = 0, totalRoutes = 0; for(i = 0; i < g_player[pl]->m_all_cities->Num(); i++) { Unit city = g_player[pl]->m_all_cities->Access(i); totalRoutes += city.CD()->GetTradeSourceList()->Num(); sint32 r; for(r = 0; r < city.CD()->GetTradeSourceList()->Num(); r++) { totalProfit += city.CD()->GetTradeSourceList()->Access(r)->GetValue(); } } child = (ctp2_Static *)aui_Ldl::GetObject(s_tradeAdviceBlock, "Profit"); if(child) { sprintf(buf, "%d", totalProfit); child->SetText(buf); } child = (ctp2_Static *)aui_Ldl::GetObject(s_tradeAdviceBlock, "Routes"); if(child) { sprintf(buf, "%d", totalRoutes); child->SetText(buf); } UpdateAdviceText(); }
void MapAnalysis::BeginTurn() { MapPoint pos; Army army; Unit city; Unit unit; sint32 i; m_piracyIncomeMatrix.assign(m_piracyIncomeMatrix.size(), 0); m_cityOnContinent.Reset(FALSE); m_armyOnContinent.Reset(FALSE); m_worldPopulation = 0; ComputeHandicapRatios(); size_t player; for (player = 0; player < m_threatGrid.size(); ++player) { m_threatGrid [player].Clear(); m_attackGrid [player].Clear(); m_defenseGrid [player].Clear(); m_rangedGrid [player].Clear(); m_bombardLandGrid [player].Clear(); m_bombardSeaGrid [player].Clear(); m_bombardAirGrid [player].Clear(); m_valueGrid [player].Clear(); m_tradeAtRiskGrid [player].Clear(); m_piracyLossGrid [player].Clear(); m_minCityThreat [player] = std::numeric_limits<sint32>::max(); m_maxCityThreat [player] = std::numeric_limits<sint32>::min(); m_movementTypeUnion[player] = 0x0; m_nuclearWeapons [player] = 0; m_bioWeapons [player] = 0; m_nanoWeapons [player] = 0; m_specialAttackers [player] = 0; m_continentSize [player] = 0; m_totalPopulation [player] = 0; m_landArea [player] = 0; m_totalTrade [player] = 0; Player * player_ptr = g_player[player]; if (player_ptr == NULL) continue; RecalcCityRanks(player); m_projectedScience[player] = player_ptr->m_advances->GetProjectedScience(); m_totalPopulation[player] = static_cast<sint16>(player_ptr->GetTotalPopulation()); m_landArea[player] = static_cast<sint16>(player_ptr->GetLandArea()); m_worldPopulation += m_totalPopulation[player]; sint32 num_units = player_ptr->m_all_units->Num(); for (i = 0; i < num_units; i++) { unit = player_ptr->m_all_units->Access(i); Assert(unit.IsValid()); if ( unit.IsValid() && unit.GetDBRec() && unit.GetDBRec()->GetNumSpecialAttacks() > 0 ) { m_specialAttackers[player]++; } } sint32 num_armies = player_ptr->m_all_armies->Num(); for (i = 0; i < num_armies; i++) { army = player_ptr->m_all_armies->Access(i); Assert(army.IsValid()); army->GetPos(pos); sint8 defense_count; sint8 ranged_count; float attack_strength; float defense_strength; float ranged_strength; float bombard_land_strength; float bombard_sea_strength; float bombard_air_strength; float total_value; army->ComputeStrength(attack_strength, defense_strength, ranged_strength, defense_count, ranged_count, bombard_land_strength, bombard_sea_strength, bombard_air_strength, total_value, false ); Assert(total_value >= 0); m_nuclearWeapons[player] += army->CountNuclearUnits(); m_bioWeapons[player] += army->CountBioUnits(); m_nanoWeapons[player] += army->CountNanoUnits(); if(m_empireCenter[player] == MapPoint()) { CalcEmpireCenter(player); } if(!m_empireBoundingRect[player].IsValid()) { UpdateBoundingRectangle(army); } m_threatGrid [player].AddValue(pos, static_cast<sint32>(attack_strength + ranged_strength)); m_attackGrid [player].AddValue(pos, static_cast<sint32>(attack_strength)); m_defenseGrid [player].AddValue(pos, static_cast<sint32>(defense_strength)); m_rangedGrid [player].AddValue(pos, static_cast<sint32>(ranged_strength)); m_bombardLandGrid [player].AddValue(pos, static_cast<sint32>(bombard_land_strength)); m_bombardSeaGrid [player].AddValue(pos, static_cast<sint32>(bombard_sea_strength)); m_bombardAirGrid [player].AddValue(pos, static_cast<sint32>(bombard_air_strength)); m_valueGrid [player].AddValue(pos, static_cast<sint32>(total_value)); bool is_land; sint16 cont; g_theWorld->GetContinent(pos, cont, is_land); if(is_land) { bool is_military = (attack_strength > 0 || ranged_strength > 0) && !army->IsCivilian(); if(is_military) { m_armyOnContinent.Set(player, cont, TRUE); } } m_movementTypeUnion[player] |= army.GetMovementType(); Assert(m_threatGrid [player].GetTotalValue() >= 0); Assert(m_attackGrid [player].GetTotalValue() >= 0); Assert(m_defenseGrid [player].GetTotalValue() >= 0); Assert(m_rangedGrid [player].GetTotalValue() >= 0); Assert(m_bombardLandGrid [player].GetTotalValue() >= 0); Assert(m_bombardSeaGrid [player].GetTotalValue() >= 0); Assert(m_bombardAirGrid [player].GetTotalValue() >= 0); Assert(m_valueGrid [player].GetTotalValue() >= 0); Assert(m_nuclearWeapons [player] >= 0); Assert(m_bioWeapons [player] >= 0); Assert(m_nanoWeapons [player] >= 0); Assert(m_specialAttackers[player] >= 0); Assert(m_continentSize [player] >= 0); Assert(m_totalPopulation [player] >= 0); Assert(m_landArea [player] >= 0); Assert(m_totalTrade [player] >= 0); } sint32 num_cities = player_ptr->m_all_cities->Num(); for (i = 0; i < num_cities; i++) { city = player_ptr->m_all_cities->Access(i); Assert(city.IsValid() && city->GetCityData()); city.GetPos(pos); sint32 total_value = city->GetCityData()->GetValue(); m_totalTrade[player] += city->GetCityData()->GetGoldFromTradeRoutes(); m_valueGrid[player].AddValue(pos, total_value); TradeDynamicArray * trade_routes = city.CD()->GetTradeSourceList(); Assert(trade_routes != NULL); sint32 tradeRouteCount = trade_routes ? trade_routes->Num() : 0; for (sint32 j = 0; j < tradeRouteCount; j++) { sint32 route_value = trade_routes->Get(j)->GetValue(); Army pirate_army = trade_routes->Get(j)->GetPiratingArmy(); if (pirate_army.IsValid()) { m_piracyLossGrid[player]. AddValue(pirate_army->RetPos(), route_value); AddPiracyIncome(pirate_army.GetOwner(), player, static_cast<sint16>(route_value)); m_valueGrid[pirate_army.GetOwner()]. AddValue(pirate_army->RetPos(), route_value); } const DynamicArray < MapPoint > * path = trade_routes->Get(j)->GetPath(); sint32 per_cell_value = (sint32)(((double)route_value / path->Num()) * 1000.0); for (sint32 k = 0; k < path->Num(); k++) { m_tradeAtRiskGrid[player].AddValue(path->Get(k), per_cell_value); } } bool is_land; sint16 cont; g_theWorld->GetContinent(pos, cont, is_land); if (is_land) { m_cityOnContinent.Set(player, cont, TRUE); m_continentSize[player] += g_theWorld->GetLandContinentSize(cont) / num_cities; } } } DPRINTF(k_DBG_MAPANALYSIS, ("BEFORE RELAX:\n")); DebugLog(); DPRINTF(k_DBG_MAPANALYSIS, ("\n")); const sint8 cycles = 1; const float coef = 0.95f; for (player = 0; player < m_threatGrid.size(); player++) { m_threatGrid [player].Relax(cycles, coef); m_attackGrid [player].Relax(cycles, coef); m_defenseGrid [player].Relax(cycles, coef); m_rangedGrid [player].Relax(cycles, coef); m_bombardLandGrid [player].Relax(cycles, coef); m_bombardSeaGrid [player].Relax(cycles, coef); m_bombardAirGrid [player].Relax(cycles, coef); m_valueGrid [player].Relax(cycles, coef); } for (player = 0; player < m_threatGrid.size(); player++) { if(Diplomat::HasDiplomat(player)) { Diplomat::GetDiplomat(player).ComputeAllDesireWarWith(); Diplomat::GetDiplomat(player).ComputeIncursionPermission(); } } for (player = 0; player < m_threatGrid.size(); player++) { Player * player_ptr = g_player[player]; if (player_ptr == NULL) continue; sint32 num_cities = player_ptr->m_all_cities->Num(); for (i = 0; i < num_cities; i++) { city = player_ptr->m_all_cities->Access(i); // Threat has to be calculated after relax sint32 threat = GetThreat(player, city.RetPos()); if (threat < m_minCityThreat[player]) m_minCityThreat[player] = threat; if (threat > m_maxCityThreat[player]) m_maxCityThreat[player] = threat; } } DPRINTF(k_DBG_MAPANALYSIS, ("RELAXED:\n")); DebugLog(); DPRINTF(k_DBG_MAPANALYSIS, ("\n")); }
//---------------------------------------------------------------------------- // // Name : UnseenCell::UnseenCell // // Description: Constructor // // Parameters : point : The point (RC coordinate) // // Globals : g_theWorld : World information // // Returns : - // // Remark(s) : The constructor to use normally. // //---------------------------------------------------------------------------- UnseenCell::UnseenCell(const MapPoint & point) : m_env (0), m_terrain_type (TERRAIN_UNKNOWN), m_move_cost (MOVECOST_UNKNOWN), m_flags (0x0000), m_bioInfectedOwner (0x00), /// @todo Check PLAYER_UNASSIGNED? m_nanoInfectedOwner (0x00), m_convertedOwner (0x00), m_franchiseOwner (0x00), m_injoinedOwner (0x00), m_happinessAttackOwner (0x00), m_citySize (0), m_cityOwner (0), m_citySpriteIndex (-1), m_cell_owner (PLAYER_UNASSIGNED), m_slaveBits (0x0000), #ifdef BATTLE_FLAGS m_battleFlags (0), #endif m_tileInfo (NULL), m_point (point), m_installations (new PointerList<UnseenInstallationInfo>), m_improvements (new PointerList<UnseenImprovementInfo>), m_cityName (NULL), m_actor (NULL), m_poolIndex (-1), m_visibleCityOwner (0) { if (g_theWorld->GetTileInfo(point)) { m_tileInfo = new TileInfo(g_theWorld->GetTileInfo(point)); } Cell * cell = g_theWorld->GetCell(point); if (cell) { m_env = cell->GetEnv(); m_move_cost = sint16(cell->GetMoveCost()); m_terrain_type = (sint8)TERRAIN_TYPES(cell->GetTerrain()); #ifdef BATTLE_FLAGS m_battleFlags = cell->GetBattleFlags(); #endif sint32 i; // Same as well information about existing // tile improvments, except roadlike ones, // so that this information is available // later as well. // And in order not to break anythink use the existing // list for unfinished tile improvements. for(i = 0; i < cell->GetNumDBImprovements(); i++) { sint32 imp = cell->GetDBImprovement(i); m_improvements->AddTail(new UnseenImprovementInfo(imp, 100)); } for(i = 0; i < cell->GetNumImprovements(); i++) { TerrainImprovement imp = cell->AccessImprovement(i); if (imp.IsValid()) { m_improvements->AddTail(new UnseenImprovementInfo(imp.GetType(), imp.PercentComplete())); } } DynamicArray<Installation> instArray; g_theInstallationTree->GetAt(point, instArray); for(i = 0; i < instArray.Num(); i++) { m_installations->AddTail(new UnseenInstallationInfo(instArray[i].GetType(), instArray[i].GetVisibility())); } m_cell_owner = (sint8) cell->GetOwner(); // Store the city that controlls this tile. m_visibleCityOwner = cell->GetCityOwner().m_id; Unit city = cell->GetCity(); if (city.IsValid()) { m_citySize = (sint16)city.PopCount(); m_citySpriteIndex = (sint16)city.CD()->GetDesiredSpriteIndex(); const MBCHAR *name = city.GetName(); m_cityName = new MBCHAR[strlen(name) + 1]; strcpy(m_cityName, name); m_cityOwner = static_cast<sint16>(city.GetCityData()->GetOwner()); CityData *cityData = city.GetData()->GetCityData(); UnitActor *actor = city.GetActor(); if (actor) { SpriteState *newSS = new SpriteState(city.GetSpriteState()->GetIndex()); UnitActor *newActor = new UnitActor(newSS, city, city.GetType(), point, city.GetOwner(), TRUE, city.GetVisionRange(), city.CD()->GetDesiredSpriteIndex()); newActor->SetUnitVisibility((1 << g_selected_item->GetVisiblePlayer()) | actor->GetUnitVisibility()); newActor->SetPos(point); newActor->SetIsFortified(actor->IsFortified()); newActor->SetIsFortifying(actor->IsFortifying()); newActor->SetHasCityWalls(actor->HasCityWalls()); newActor->SetHasForceField(actor->HasForceField()); newActor->SetSize(m_citySize); newActor->ChangeImage(newSS, city.GetType(), city); newActor->AddIdle(); newActor->GetNextAction(); m_actor = newActor; } // actor SetIsBioInfected(cityData->IsBioInfected()); SetIsNanoInfected(cityData->IsNanoInfected()); SetIsConverted(cityData->IsConverted()); SetIsFranchised(cityData->IsFranchised()); SetIsInjoined(cityData->IsInjoined()); SetWasHappinessAttacked(cityData->WasHappinessAttacked()); SetIsRioting(cityData->GetIsRioting()); SetHasAirport(cityData->HasAirport()); SetHasSleepingUnits(cityData->HasSleepingUnits()); SetIsWatchful(cityData->IsWatchful()); SetIsCapitol(cityData->IsCapitol()); //emod SetIsReligionIcon(cityData->HasReligionIcon()); //emod m_bioInfectedOwner = (sint8)cityData->GetBioInfectedBy(); m_nanoInfectedOwner = (sint8)cityData->GetNanoInfectedBy(); m_convertedOwner = (sint8)cityData->IsConvertedTo(); m_franchiseOwner = (sint8)cityData->GetFranchiseOwner(); m_injoinedOwner = (sint8)cityData->InjoinedBy(); m_happinessAttackOwner = (sint8)cityData->GetHappinessAttackedBy(); m_slaveBits = cityData->GetSlaveBits(); SetIsSpecialIcon(cityData->HasSpecialIcon()); //emod sint32 pollution = cityData->GetPollution(); SetIsPollutionRisk(pollution > g_theConstDB->Get(0)->GetLocalPollutionLevel()); } // city.IsValid } // cell SetHasHut(NULL != g_theWorld->GetGoodyHut(point)); }
void TradeManager::UpdateSummaryList() { sint32 pl = g_selected_item->GetVisiblePlayer(); Assert(pl >= 0 && pl < k_MAX_PLAYERS); if(pl < 0 || pl >= k_MAX_PLAYERS) return; Assert(g_player[pl]); if(!g_player[pl]) return; Player *p = g_player[pl]; Unit maxCity; m_summaryList->Clear(); for (sint32 c = 0; c < p->m_all_cities->Num(); c++) { Unit city = p->m_all_cities->Access(c); for (sint32 r = 0; r < city.CD()->GetTradeSourceList()->Num(); r++) { ctp2_ListItem * item = (ctp2_ListItem *) aui_Ldl::BuildHierarchyFromRoot("TradeSummaryItem"); Assert(item); if(!item) break; TradeRoute route = city.CD()->GetTradeSourceList()->Access(r); if (ctp2_Static * origin = (ctp2_Static *)item->GetChildByIndex(k_CITY_COL_SUM_INDEX)) { MBCHAR name[k_MAX_NAME_LEN + 1]; strncpy(name, city.GetName(), k_MAX_NAME_LEN); name[k_MAX_NAME_LEN] = 0; origin->TextReloadFont(); origin->GetTextFont()->TruncateString(name, origin->Width()); origin->SetText(name); } ROUTE_TYPE rtype; sint32 resource; route.GetSourceResource(rtype, resource); if (ctp2_Static * icon = (ctp2_Static *)item->GetChildByIndex(k_GOODICON_COL_SUM_INDEX)) { if (rtype == ROUTE_TYPE_RESOURCE) { const MBCHAR *imageName = g_theResourceDB->Get(resource)->GetIcon()->GetIcon(); if (stricmp(imageName, "NULL") == 0) { icon->SetImage(NULL); } else { icon->SetImage(g_theResourceDB->Get(resource)->GetIcon()->GetIcon()); } } } if (ctp2_Static * good = (ctp2_Static *)item->GetChildByIndex(k_GOOD_COL_SUM_INDEX)) { if (rtype == ROUTE_TYPE_RESOURCE) { good->SetText(g_theResourceDB->Get(resource)->GetNameText()); } else { good->SetText(g_theStringDB->GetNameStr("ROUTE_TYPE_FOOD")); } } if (ctp2_Static * dest = (ctp2_Static *)item->GetChildByIndex(k_TOCITY_COL_SUM_INDEX)) { MBCHAR name[k_MAX_NAME_LEN + 1]; Unit dCity = route.GetDestination(); strncpy(name, dCity.GetName(), k_MAX_NAME_LEN); name[k_MAX_NAME_LEN] = 0; dest->TextReloadFont(); dest->GetTextFont()->TruncateString(name, dest->Width()); dest->SetText(name); } if (ctp2_Static * piracy = (ctp2_Static *)item->GetChildByIndex(k_PIRACY_COL_SUM_INDEX)) { piracy->SetDrawCallbackAndCookie(DrawPiracyColumn, (void *)route.m_id); } MBCHAR buf[20]; if(rtype == ROUTE_TYPE_RESOURCE) { sprintf(buf, "%d", route->GetValue()); } else { strcpy(buf, "---"); } if (ctp2_Static * price = (ctp2_Static *)item->GetChildByIndex(k_PRICE_COL_SUM_INDEX)) { price->SetText(buf); } if (ctp2_Static * count = (ctp2_Static *)item->GetChildByIndex(k_CARAVANS_COL_SUM_INDEX)) { sprintf(buf, "%.0f", route.GetCost()); count->SetText(buf); } if (ctp2_Static * nation = (ctp2_Static *)item->GetChildByIndex(k_NATION_COL_SUM_INDEX)) { nation->SetDrawCallbackAndCookie (DrawNationColumn, (void *)route.GetDestination().GetOwner()); } item->SetUserData((void *)route.m_id); item->SetCompareCallback(CompareSummaryItems); m_summaryList->AddItem(item); } } m_breakButton->Enable(FALSE); }
void TradeManager::UpdateCreateList(const PLAYER_INDEX & player_id) { Assert(player_id >= 0 && player_id < k_MAX_PLAYERS); if(player_id < 0 || player_id >= k_MAX_PLAYERS) return; Player * p = g_player[player_id]; Assert(p); if (!p) return; sint32 d; Unit maxCity[k_MAX_CITIES_PER_GOOD]; m_createList->Clear(); m_createData.DeleteAll(); for (sint32 c = 0; c < p->m_all_cities->Num(); c++) { Unit city = p->m_all_cities->Access(c); for (sint32 g = 0; g < g_theResourceDB->NumRecords(); g++) { if(city.CD()->IsLocalResource(g)) { sint32 op; sint32 maxPrice[k_MAX_CITIES_PER_GOOD]; sint32 sellingPrice = -1; Unit curDestCity; sint32 i,j; for(i = 0; i < k_MAX_CITIES_PER_GOOD; i++) { maxCity[i].m_id = 0; maxPrice[i] = 0; } if(!city.CD()->HasResource(g) && city.CD()->IsSellingResourceTo(g, curDestCity) ) { sellingPrice = tradeutil_GetTradeValue(player_id, curDestCity, g); //need to add something here where cities that have an improvement that needs a good will demand the good. May be increase the value of selling that good? } else { curDestCity.m_id = 0; sellingPrice = -1; } for(op = 1; op < k_MAX_PLAYERS; op++) { if(!g_player[op]) continue; if(player_id != op && !p->HasContactWith(op)) continue; if(m_showCities == TRADE_CITIES_OWN && op != g_selected_item->GetVisiblePlayer()) continue; if ((m_showCities == TRADE_CITIES_ALL) && (op != g_selected_item->GetVisiblePlayer()) && (AgreementMatrix::s_agreements.TurnsAtWar(player_id, op) >= 0) ) continue; if ((m_showCities == TRADE_CITIES_FRIENDLY) && (op != g_selected_item->GetVisiblePlayer()) && (!AgreementMatrix::s_agreements.HasAgreement (player_id, op, PROPOSAL_TREATY_PEACE) ) ) continue; if(Diplomat::GetDiplomat(op).GetEmbargo(player_id)) continue; for(d = 0; d < g_player[op]->m_all_cities->Num(); d++) { Unit destCity = g_player[op]->m_all_cities->Access(d); if(!(destCity.IsValid())) continue; if(!(destCity.GetVisibility() & (1 << player_id))) continue; if(destCity.m_id == city.m_id) continue; if(curDestCity.m_id == destCity.m_id) continue; sint32 price = tradeutil_GetTradeValue(player_id, destCity, g); for(i = 0; i < m_numCities; i++) { if(price > maxPrice[i]) { for(j = m_numCities - 1; j>= i; j--) { maxPrice[j] = maxPrice[j - 1]; maxCity[j].m_id = maxCity[j - 1].m_id; } maxPrice[i] = price; maxCity[i] = destCity; break; } } } } for(i = 0; i < k_MAX_CITIES_PER_GOOD; i++) { if(maxPrice[i] > 0) { if(maxCity[i].m_id == curDestCity.m_id) continue; ctp2_ListItem * item = (ctp2_ListItem *) aui_Ldl::BuildHierarchyFromRoot("CreateRouteItem"); Assert(item); if(!item) break; CreateListData *data = new CreateListData; data->m_source = city; data->m_resource = g; data->m_destination = maxCity[i]; data->m_price = maxPrice[i]; data->m_caravans = tradeutil_GetAccurateTradeDistance(city, maxCity[i]); data->m_curDestination.m_id = curDestCity.m_id; m_createData.AddTail(data); item->SetUserData(data); if (ctp2_Static * origin = (ctp2_Static *)item->GetChildByIndex(k_CITY_COL_INDEX)) { MBCHAR name[k_MAX_NAME_LEN + 1]; strncpy(name, city.GetName(), k_MAX_NAME_LEN); name[k_MAX_NAME_LEN] = 0; origin->TextReloadFont(); origin->GetTextFont()->TruncateString(name, origin->Width()); origin->SetText(name); } if (ctp2_Static * icon = (ctp2_Static *)item->GetChildByIndex(k_GOODICON_COL_INDEX)) { const char *iconname = g_theResourceDB->Get(g)->GetIcon()->GetIcon(); if (stricmp(iconname, "NULL") == 0) { iconname = NULL; } icon->SetImage(iconname); } if (ctp2_Static * good = (ctp2_Static *)item->GetChildByIndex(k_GOOD_COL_INDEX)) { good->SetText(g_theResourceDB->Get(g)->GetNameText()); if (curDestCity.m_id != 0) { good->SetTextColor(g_colorSet->GetColorRef(COLOR_RED)); } } if (ctp2_Static * dest = (ctp2_Static *)item->GetChildByIndex(k_TOCITY_COL_INDEX)) { MBCHAR name[k_MAX_NAME_LEN + 1]; strncpy(name, maxCity[i].GetName(), k_MAX_NAME_LEN); name[k_MAX_NAME_LEN] = 0; dest->TextReloadFont(); dest->GetTextFont()->TruncateString(name, dest->Width()); dest->SetText(name); } MBCHAR buf[20]; sprintf(buf, "%d", maxPrice[i]); if (ctp2_Static * price = (ctp2_Static *)item->GetChildByIndex(k_PRICE_COL_INDEX)) { price->SetText(buf); } if (ctp2_Static * count = (ctp2_Static *)item->GetChildByIndex(k_CARAVANS_COL_INDEX)) { sprintf(buf, "%d", data->m_caravans); count->SetText(buf); } if (ctp2_Static * nation = (ctp2_Static *)item->GetChildByIndex(k_NATION_COL_INDEX)) { nation->SetDrawCallbackAndCookie (DrawNationColumn, (void *)data->m_destination.GetOwner()); } item->SetCompareCallback(CompareCreateItems); m_createList->AddItem(item); } } } } } m_createButton->Enable(FALSE); }
void WonderTab::AddWonderItem(sint32 wonder, sint32 player, sint32 turn) { Unit curCity; if(!g_theWonderTracker->GetCityWithWonder(wonder, curCity)) curCity.m_id = 0; const WonderRecord *rec = wonderutil_Get(wonder, player); ctp2_ListItem *item = (ctp2_ListItem *)aui_Ldl::BuildHierarchyFromRoot("WonderTabListItem"); Assert(item); if(item) { ctp2_Static *box = (ctp2_Static *)item->GetChildByIndex(0); Assert(box); if(box) { ctp2_Static *st = (ctp2_Static *)box->GetChildByIndex(0); Assert(st); if(st) { st->SetImage((char *)rec->GetDefaultIcon()->GetFirstFrame()); } st = (ctp2_Static *)box->GetChildByIndex(1); Assert(st); if(st) { st->SetText(rec->GetNameText()); } st = (ctp2_Static *)box->GetChildByIndex(2); Assert(st); if(st) { const char *year = diffutil_GetYearStringFromTurn(g_theGameSettings->GetDifficulty(), turn); if(year) { st->SetText(year); } else { st->SetText("error"); } item->SetUserData((void*)turn); } st = (ctp2_Static *)box->GetChildByIndex(3); Assert(st); if(st) { if(curCity.IsValid()) { st->SetText(curCity.CD()->GetName()); st->SetTextColor(g_colorSet->GetColorRef(g_colorSet->ComputePlayerColor(curCity.GetOwner()))); } else { st->SetText("---"); } } st = (ctp2_Static *)box->GetChildByIndex(4); Assert(st); if(st) { Player *p = g_player[player]; if(!p) { PointerList<Player>::Walker walk(g_deadPlayer); for(; walk.IsValid(); walk.Next()) { if(walk.GetObj()->m_owner == player) { p = walk.GetObj(); break; } } } if(!p) { st->SetText("---"); } else { MBCHAR buf[k_MAX_NAME_LEN]; p->m_civilisation->GetCountryName(buf); st->SetText(buf); } } } item->SetCompareCallback(CompareWonderItems); m_list->AddItem(item); } }