forked from townforge/townforge
game: add crop/yield to building screen
This commit is contained in:
parent
99400c0b07
commit
1698244761
@ -22,6 +22,9 @@ TBLayout: axis: x, distribution-position: "left top", size: "available"
|
||||
TBTextField: id: "repair", text: "Repair", squeezable: 1, text-align: "left"
|
||||
lp: min-width: 60
|
||||
data: "numeric"
|
||||
TBTextField: id: "crop", text: "Crop", squeezable: 1, text-align: "left"
|
||||
lp: min-width: 60
|
||||
data: "numeric"
|
||||
TBTextField: id: "land_tax", text: "Land tax", squeezable: 1, text-align: "left"
|
||||
lp: min-width: 80
|
||||
data: "money"
|
||||
|
@ -565,6 +565,20 @@ const char *get_discovery_name(uint32_t discovery)
|
||||
return discovery_data[discovery].name;
|
||||
}
|
||||
|
||||
uint32_t get_discovery_item(uint32_t discovery)
|
||||
{
|
||||
if (discovery >= NUM_DISCOVERIES)
|
||||
return ITEM_NONE;
|
||||
return discovery_data[discovery].item;
|
||||
}
|
||||
|
||||
uint64_t get_discovery_patent_time(uint32_t discovery)
|
||||
{
|
||||
if (discovery >= NUM_DISCOVERIES)
|
||||
return 0;
|
||||
return discovery_data[discovery].patent_time;
|
||||
}
|
||||
|
||||
std::vector<uint32_t> get_dependent_discoveries(uint32_t discovery)
|
||||
{
|
||||
std::vector<uint32_t> discoveries;
|
||||
|
@ -77,6 +77,8 @@ namespace cc
|
||||
|
||||
bool get_discovery_data(uint32_t discovery, const char *&name, const char *&icon, const char *&desc, std::vector<uint32_t> &prerequisites, uint64_t &difficulty, uint32_t &item, uint64_t &patent_time);
|
||||
const char *get_discovery_name(uint32_t discovery);
|
||||
uint32_t get_discovery_item(uint32_t discovery);
|
||||
uint64_t get_discovery_patent_time(uint32_t discovery);
|
||||
std::vector<uint32_t> get_dependent_discoveries(uint32_t discovery);
|
||||
bool get_discovery_for_item(uint32_t item, uint32_t &discovery);
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "cc/cc_city_specialization.h"
|
||||
#include "cc/cc_palette.h"
|
||||
#include "cc/cc_food.h"
|
||||
#include "cc/cc_discoveries.h"
|
||||
#include "map.h"
|
||||
#include "game-util.h"
|
||||
#include "game-wallet.h"
|
||||
@ -140,6 +141,34 @@ void GameState::set_city_ignore(uint32_t id, bool ignore)
|
||||
}
|
||||
}
|
||||
|
||||
bool GameState::has_discovery(int discovery) const
|
||||
{
|
||||
if (discovery < 0 || discovery >= NUM_DISCOVERIES || (size_t)discovery > discoveries.size())
|
||||
return false;
|
||||
const cryptonote::discovery_t &d = discoveries[discovery];
|
||||
if (d.discoverer == 0)
|
||||
return false;
|
||||
|
||||
const uint64_t patent_time = cc::get_discovery_patent_time(discovery);
|
||||
if (d.discovery_height + patent_time <= top_height)
|
||||
return true;
|
||||
|
||||
const uint32_t item = cc::get_discovery_item(discovery);
|
||||
if (item == 0)
|
||||
{
|
||||
if (d.discoverer == playerState.id)
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto i = playerState.item_balances.find(item);
|
||||
if (i != playerState.item_balances.end() && i->second > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameState::update(const std::shared_ptr<GameWallet> &wallet, uint64_t top_height, const std::string &top_hash)
|
||||
{
|
||||
std::shared_ptr<tools::wallet2> w = wallet->wallet();
|
||||
|
@ -153,6 +153,7 @@ public:
|
||||
void on_new_wallet(const std::shared_ptr<GameWallet> &wallet);
|
||||
void get_ignore_recommendations(tools::cc_ignore_t *ignore);
|
||||
void set_ignore_recommendations(const tools::cc_ignore_t *ignore, std::vector<uint32_t> &ignore_players, std::vector<uint32_t> &unignore_players, std::vector<uint32_t> &ignore_flags, std::vector<uint32_t> &unignore_flags, std::vector<uint32_t> &ignore_items, std::vector<uint32_t> &unignore_items, std::vector<uint32_t> &ignore_cities, std::vector<uint32_t> &unignore_cities);
|
||||
bool has_discovery(int discovery) const;
|
||||
|
||||
private:
|
||||
bool process_add_city_specialization(const cryptonote::cc_command_add_city_specialization_t &cmd, const std::shared_ptr<GameWallet> &w);
|
||||
|
@ -2,7 +2,10 @@
|
||||
#include "cc/cc_discoveries.h"
|
||||
#include "cc/cc_food.h"
|
||||
#include "cc/cc_script.h"
|
||||
#include "cc/cc_special_events.h"
|
||||
#include "cc/cc_city_specialization.h"
|
||||
#include "game-state.h"
|
||||
#include "game-wallet.h"
|
||||
#include "game-util.h"
|
||||
|
||||
namespace game_util
|
||||
@ -157,4 +160,22 @@ std::string get_command_string(const GameState *game, const cryptonote::cc_comma
|
||||
return boost::apply_visitor(visitor(game), cmd);
|
||||
}
|
||||
|
||||
int32_t get_crop_yield(const GameState *game, const std::shared_ptr<GameWallet> &w, uint8_t crop, uint64_t sow_height, uint8_t geothermal_heating, bool frost_resistant_vegetables, bool fast_frost_damage_recovery)
|
||||
{
|
||||
const bool cold_snap = game->cityState.special_event == cc::SPECIAL_EVENT_COLD_SNAP;
|
||||
const bool heat_wave = game->cityState.special_event == cc::SPECIAL_EVENT_HEAT_WAVE;
|
||||
const bool microclimate = (game->cityState.specializations >> cc::CITY_SPECIALIZATION_MICRO_CLIMATE) & 1;
|
||||
const uint64_t db_height = game->top_height + 1;
|
||||
std::vector<int32_t> temperatures;
|
||||
temperatures.reserve(db_height - sow_height);
|
||||
for (uint64_t height = sow_height; height < db_height; ++height)
|
||||
{
|
||||
int32_t temperature;
|
||||
w->get_actual_temperature(height, cold_snap, heat_wave, microclimate, temperature);
|
||||
temperature += geothermal_heating / 32;
|
||||
temperatures.push_back(temperature);
|
||||
}
|
||||
return cc::get_crop_yield(crop, CROP_START_YIELD, temperatures, frost_resistant_vegetables, fast_frost_damage_recovery);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "cryptonote_basic/cc_command_defs.h"
|
||||
|
||||
class GameState;
|
||||
class GameWallet;
|
||||
class Flag;
|
||||
|
||||
namespace game_util
|
||||
@ -15,5 +16,6 @@ const char *get_possessive(const std::string &s);
|
||||
std::string get_building_name(const GameState *game, const std::shared_ptr<Flag> &flag);
|
||||
std::string get_building_name(const GameState *game, uint32_t flag_id);
|
||||
std::string get_command_string(const GameState *game, const cryptonote::cc_command_t &cmd);
|
||||
int32_t get_crop_yield(const GameState *game, const std::shared_ptr<GameWallet> &w, uint8_t crop, uint64_t sow_height, uint8_t geothermal_heating, bool frost_resistant_vegetables, bool fast_frost_damage_recovery);
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "cc/cc_discoveries.h"
|
||||
#include "cc/cc_city_specialization.h"
|
||||
#include "cc/cc_special_events.h"
|
||||
#include "game-util.h"
|
||||
#include "game-wallet.h"
|
||||
#include "game-state.h"
|
||||
#include "ui-tb-message-box.h"
|
||||
@ -20,24 +21,6 @@
|
||||
using namespace Urho3D;
|
||||
using namespace tb;
|
||||
|
||||
static int32_t get_crop_yield(const GameState *game, const std::shared_ptr<GameWallet> &w, uint8_t crop, uint64_t sow_height, uint8_t geothermal_heating, bool frost_resistant_vegetables, bool fast_frost_damage_recovery)
|
||||
{
|
||||
const bool cold_snap = game->cityState.special_event == cc::SPECIAL_EVENT_COLD_SNAP;
|
||||
const bool heat_wave = game->cityState.special_event == cc::SPECIAL_EVENT_HEAT_WAVE;
|
||||
const bool microclimate = (game->cityState.specializations >> cc::CITY_SPECIALIZATION_MICRO_CLIMATE) & 1;
|
||||
const uint64_t db_height = game->top_height + 1;
|
||||
std::vector<int32_t> temperatures;
|
||||
temperatures.reserve(db_height - sow_height);
|
||||
for (uint64_t height = sow_height; height < db_height; ++height)
|
||||
{
|
||||
int32_t temperature;
|
||||
w->get_actual_temperature(height, cold_snap, heat_wave, microclimate, temperature);
|
||||
temperature += geothermal_heating / 32;
|
||||
temperatures.push_back(temperature);
|
||||
}
|
||||
return cc::get_crop_yield(crop, CROP_START_YIELD, temperatures, frost_resistant_vegetables, fast_frost_damage_recovery);
|
||||
}
|
||||
|
||||
UIHarvestDialog::UIHarvestDialog(Context *ctx, const GameState *game, const std::shared_ptr<Flag> &flag):
|
||||
UITBWindow(ctx, "cc/harvest.tb.txt"),
|
||||
game(game),
|
||||
@ -153,7 +136,7 @@ void UIHarvestDialog::UpdateData(const std::shared_ptr<GameWallet> &w)
|
||||
|
||||
sownWidget->SetText(std::to_string(game->top_height - flag->sow_height).c_str());
|
||||
|
||||
uint32_t crop_yield = get_crop_yield(game, w, flag->crop, flag->sow_height, flag->potential[POTENTIAL_GEOTHERMAL], has_frost_resistant_vegetables, has_fast_frost_damage_recovery);
|
||||
uint32_t crop_yield = game_util::get_crop_yield(game, w, flag->crop, flag->sow_height, flag->potential[POTENTIAL_GEOTHERMAL], has_frost_resistant_vegetables, has_fast_frost_damage_recovery);
|
||||
yieldWidget->SetText(cc::print_crop_yield(crop_yield).c_str());
|
||||
|
||||
const uint8_t nutrients = flag->crop == CROP_VEGETABLES ? flag->vegetables_nutrients : flag->grain_nutrients;
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "cc/cc_city_specialization.h"
|
||||
#include "cc/cc_food.h"
|
||||
#include "cc/cc_temperature.h"
|
||||
#include "cc/cc_discoveries.h"
|
||||
#include "wallet/wallet2.h"
|
||||
#include "game/game-state.h"
|
||||
#include "game/game-wallet.h"
|
||||
@ -61,6 +62,7 @@ enum FlagColumn
|
||||
FC_GEOTHERMAL,
|
||||
FC_GEMSTONE,
|
||||
FC_REPAIR,
|
||||
FC_CROP,
|
||||
FC_LAND_TAX,
|
||||
FC_DELTA_PINE,
|
||||
FC_DELTA_OAK,
|
||||
@ -446,7 +448,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static std::vector<std::string> get_flag_data(const GameState *game, const std::shared_ptr<Flag> &flag)
|
||||
static std::vector<std::string> get_flag_data(const GameState *game, const std::shared_ptr<GameWallet> &w, const std::shared_ptr<Flag> &flag)
|
||||
{
|
||||
std::vector<std::string> contents;
|
||||
char s[256];
|
||||
@ -467,6 +469,16 @@ static std::vector<std::string> get_flag_data(const GameState *game, const std::
|
||||
|
||||
contents[FC_REPAIR] = cc::print_repair_percentage(flag->repair);
|
||||
|
||||
if (flag->role == ROLE_AGRICULTURAL && flag->crop != CROP_NONE)
|
||||
{
|
||||
const bool has_frost_resistant_vegetables = game->has_discovery(DISCOVERY_FROST_RESISTANT_VEGETABLES);
|
||||
const bool has_fast_frost_damage_recovery = game->has_discovery(DISCOVERY_FAST_FROST_DAMAGE_RECOVERY);
|
||||
uint32_t crop_yield = game_util::get_crop_yield(game, w, flag->crop, flag->sow_height, flag->potential[POTENTIAL_GEOTHERMAL], has_frost_resistant_vegetables, has_fast_frost_damage_recovery);
|
||||
contents[FC_CROP] = cc::print_crop_yield(crop_yield) + " (" + cc::get_crop_name(flag->crop) + ")";
|
||||
}
|
||||
else
|
||||
contents[FC_CROP] = "";
|
||||
|
||||
uint64_t tax;
|
||||
if (cc::get_land_tax(flag->x0, flag->y0, flag->x1, flag->y1, game->cityState.ox, game->cityState.oy, flag->economic_power, tax))
|
||||
contents[FC_LAND_TAX] = cryptonote::print_money(tax).c_str();
|
||||
@ -581,6 +593,9 @@ UIPlayerInfoDialog::FlagWidget::FlagWidget(const std::vector<std::string> &conte
|
||||
TBTextField *repair = GetWidgetByIDAndType<TBTextField>(TBIDC("repair"));
|
||||
repair->SetText(contents[FC_REPAIR]);
|
||||
|
||||
TBTextField *crop = GetWidgetByIDAndType<TBTextField>(TBIDC("crop"));
|
||||
crop->SetText(contents[FC_CROP]);
|
||||
|
||||
TBTextField *land_tax = GetWidgetByIDAndType<TBTextField>(TBIDC("land_tax"));
|
||||
land_tax->SetText(contents[FC_LAND_TAX]);
|
||||
|
||||
@ -640,6 +655,7 @@ UIPlayerInfoDialog::FlagWidget::FlagWidget(const std::vector<std::string> &conte
|
||||
size->SetTextColor(inactive_color);
|
||||
economic_power->SetTextColor(inactive_color);
|
||||
repair->SetTextColor(inactive_color);
|
||||
crop->SetTextColor(inactive_color);
|
||||
land_tax->SetTextColor(inactive_color);
|
||||
influence->SetTextColor(inactive_color);
|
||||
primary_potential->SetTextColor(inactive_color);
|
||||
@ -673,6 +689,7 @@ TBWidget *UIPlayerInfoDialog::FlagSource::CreateItemWidget(int index, TBSelectIt
|
||||
contents[FC_SIZE] = std::to_string(running_area) + " tiles"; running_area = 0;
|
||||
contents[FC_ECONOMIC_POWER] = "";
|
||||
contents[FC_REPAIR] = "";
|
||||
contents[FC_CROP] = "";
|
||||
contents[FC_LAND_TAX] = cryptonote::print_money(running_land_tax); running_land_tax = 0;
|
||||
contents[FC_INFLUENCE] = "";
|
||||
contents[FC_PRIMARY_POTENTIAL] = "";
|
||||
@ -980,7 +997,7 @@ void UIPlayerInfoDialog::FillData(const std::shared_ptr<GameWallet> &w, uint32_t
|
||||
const uint32_t flag_id = e["id"]->GetUInt();
|
||||
const std::shared_ptr<Flag> flag = game->map.get_flag(flag_id);
|
||||
if (flag)
|
||||
builder.AddItem(new FlagItem(flag, game, get_flag_data(game, flag), flag->active, false));
|
||||
builder.AddItem(new FlagItem(flag, game, get_flag_data(game, w, flag), flag->active, false));
|
||||
}
|
||||
|
||||
// footer with totals
|
||||
|
Loading…
Reference in New Issue
Block a user