move carryover message to new file
This will in particular make future refactors of that code easier.
This commit is contained in:
parent
8710ae0ee6
commit
d954d307bc
6 changed files with 191 additions and 126 deletions
|
@ -230,6 +230,8 @@
|
|||
<Unit filename="../../src/campaign_type.hpp" />
|
||||
<Unit filename="../../src/carryover.cpp" />
|
||||
<Unit filename="../../src/carryover.hpp" />
|
||||
<Unit filename="../../src/carryover_show_gold.cpp" />
|
||||
<Unit filename="../../src/carryover_show_gold.hpp" />
|
||||
<Unit filename="../../src/chat_command_handler.cpp" />
|
||||
<Unit filename="../../src/chat_command_handler.hpp" />
|
||||
<Unit filename="../../src/chat_events.cpp" />
|
||||
|
|
|
@ -642,6 +642,7 @@
|
|||
62D24F2F1519982500350848 /* editor_toolkit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F2B1519982500350848 /* editor_toolkit.cpp */; };
|
||||
62D24F321519987400350848 /* context_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F311519987400350848 /* context_manager.cpp */; };
|
||||
62D24F351519995200350848 /* palette_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 62D24F341519995200350848 /* palette_manager.cpp */; };
|
||||
867141839BDB89BFE876E310 /* carryover_show_gold.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09A440B1A671C45BE2924FB4 /* carryover_show_gold.cpp */; };
|
||||
87744447951D17AA38BE5F48 /* mp_report.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 58C649488B3014E6F7254B62 /* mp_report.cpp */; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
900000000000000000000009 /* match_history.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4685A5F925B4501E006FD3A1 /* match_history.cpp */; };
|
||||
|
@ -1088,6 +1089,7 @@
|
|||
95EB8A55287A02EC00B09F95 /* top_level_drawable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95EB8A54287A02EC00B09F95 /* top_level_drawable.cpp */; };
|
||||
95EB8A58287B138700B09F95 /* draw_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95EB8A50287A02B800B09F95 /* draw_manager.cpp */; };
|
||||
95EB8A59287B139800B09F95 /* top_level_drawable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95EB8A54287A02EC00B09F95 /* top_level_drawable.cpp */; };
|
||||
97714C7A9FF444E29DCEF0BA /* carryover_show_gold.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 09A440B1A671C45BE2924FB4 /* carryover_show_gold.cpp */; };
|
||||
B508D193100146E300B12852 /* engine_fai.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B508D191100146E300B12852 /* engine_fai.cpp */; };
|
||||
B513B2290ED36BFB0006E551 /* libcairo.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = B513B2270ED36BFB0006E551 /* libcairo.2.dylib */; };
|
||||
B52EE8841213585300CFBDAB /* tod_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B52EE8821213585300CFBDAB /* tod_manager.cpp */; };
|
||||
|
@ -1513,6 +1515,7 @@
|
|||
000000000000000000000004 /* achievements_dialog.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = achievements_dialog.hpp; sourceTree = "<group>"; };
|
||||
000000000000000000000009 /* network_download_file.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = network_download_file.cpp; sourceTree = "<group>"; };
|
||||
000000000000000000000010 /* network_download_file.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = network_download_file.hpp; sourceTree = "<group>"; };
|
||||
09A440B1A671C45BE2924FB4 /* carryover_show_gold.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = carryover_show_gold.cpp; path = carryover_show_gold.cpp; sourceTree = "<group>"; };
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
|
||||
1234567890ABCDEF12345680 /* file_progress.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_progress.cpp; sourceTree = "<group>"; };
|
||||
1234567890ABCDEF12345681 /* file_progress.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_progress.hpp; sourceTree = "<group>"; };
|
||||
|
@ -3396,6 +3399,7 @@
|
|||
B55999420EC62181008DD061 /* wml_exception.hpp */,
|
||||
9197972726199F54001E8133 /* wml_separators.hpp */,
|
||||
91B621AC1B76B05700B00E0F /* xBRZ */,
|
||||
09A440B1A671C45BE2924FB4 /* carryover_show_gold.cpp */,
|
||||
);
|
||||
name = src;
|
||||
path = ../../src;
|
||||
|
@ -5749,6 +5753,7 @@
|
|||
46F92E212174F6A400602C1C /* mp_change_control.cpp in Sources */,
|
||||
36B146FAA79A55E9F43723B1 /* general.cpp in Sources */,
|
||||
3C254DF5B7DF196F2041955F /* mp_report.cpp in Sources */,
|
||||
97714C7A9FF444E29DCEF0BA /* carryover_show_gold.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -6417,6 +6422,7 @@
|
|||
915C68EC1DF1DCB000594B07 /* color.cpp in Sources */,
|
||||
4291489DA38012477DA3BA7C /* general.cpp in Sources */,
|
||||
87744447951D17AA38BE5F48 /* mp_report.cpp in Sources */,
|
||||
867141839BDB89BFE876E310 /* carryover_show_gold.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -61,6 +61,7 @@ animated.cpp
|
|||
attack_prediction.cpp
|
||||
build_info.cpp
|
||||
carryover.cpp
|
||||
carryover_show_gold.cpp
|
||||
chat_command_handler.cpp
|
||||
chat_events.cpp
|
||||
chat_log.cpp
|
||||
|
@ -167,13 +168,13 @@ gui/core/widget_definition.cpp
|
|||
gui/core/window_builder.cpp
|
||||
gui/core/window_builder/helper.cpp
|
||||
gui/core/window_builder/instance.cpp
|
||||
gui/dialogs/achievements_dialog.cpp
|
||||
gui/dialogs/addon/addon_auth.cpp
|
||||
gui/dialogs/addon/connect.cpp
|
||||
gui/dialogs/addon/install_dependencies.cpp
|
||||
gui/dialogs/addon/license_prompt.cpp
|
||||
gui/dialogs/addon/manager.cpp
|
||||
gui/dialogs/addon/uninstall_list.cpp
|
||||
gui/dialogs/achievements_dialog.cpp
|
||||
gui/dialogs/attack_predictions.cpp
|
||||
gui/dialogs/campaign_difficulty.cpp
|
||||
gui/dialogs/campaign_selection.cpp
|
||||
|
|
159
src/carryover_show_gold.cpp
Normal file
159
src/carryover_show_gold.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
Copyright (C) 2003 - 2022
|
||||
by David White <dave@whitevine.net>
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "carryover_show_gold.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "team.hpp"
|
||||
#include "game_state.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/message.hpp"
|
||||
#include "gui/dialogs/outro.hpp"
|
||||
#include "gui/dialogs/transient_message.hpp"
|
||||
#include "gui/widgets/retval.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "map/map.hpp"
|
||||
#include <cassert>
|
||||
|
||||
static lg::log_domain log_engine("engine");
|
||||
#define LOG_NG LOG_STREAM(info, log_engine)
|
||||
#define ERR_NG LOG_STREAM(err, log_engine)
|
||||
|
||||
|
||||
void carryover_show_gold(game_state& state, bool is_observer, bool is_test)
|
||||
{
|
||||
assert(state.end_level_data_);
|
||||
game_board& board = state.board_;
|
||||
const end_level_data& end_level = *state.end_level_data_;
|
||||
const bool is_victory = end_level.is_victory;
|
||||
// We need to write the carryover amount to the team that's why we need non const
|
||||
std::vector<team>& teams = board.teams();
|
||||
|
||||
// maybe this can be the case for scenario that only contain a story and end during the prestart event ?
|
||||
if(teams.size() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostringstream report;
|
||||
std::string title;
|
||||
|
||||
|
||||
if(is_observer) {
|
||||
title = _("Scenario Report");
|
||||
} else if(is_victory) {
|
||||
title = _("Victory");
|
||||
report << "<b>" << _("You have emerged victorious!") << "</b>";
|
||||
} else {
|
||||
title = _("Defeat");
|
||||
report << _("You have been defeated!");
|
||||
}
|
||||
|
||||
const std::string& next_scenario = state.get_game_data()->next_scenario();
|
||||
const bool has_next_scenario = !next_scenario.empty() && next_scenario != "null";
|
||||
|
||||
int persistent_teams = 0;
|
||||
for(const team& t : teams) {
|
||||
if(t.persistent()) {
|
||||
++persistent_teams;
|
||||
}
|
||||
}
|
||||
|
||||
if(persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level) || is_test)) {
|
||||
const gamemap& map = board.map();
|
||||
const tod_manager& tod = state.get_tod_man();
|
||||
|
||||
const int turns_left = std::max<int>(0, tod.number_of_turns() - tod.turn());
|
||||
for(team& t : teams) {
|
||||
if(!t.persistent() || t.lost()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int finishing_bonus_per_turn = map.villages().size() * t.village_gold() + t.base_income();
|
||||
const int finishing_bonus = t.carryover_bonus() * finishing_bonus_per_turn * turns_left;
|
||||
|
||||
t.set_carryover_gold(div100rounded((t.gold() + finishing_bonus) * t.carryover_percentage()));
|
||||
|
||||
if(!t.is_local_human()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(persistent_teams > 1) {
|
||||
report << "\n\n<b>" << t.side_name() << "</b>";
|
||||
}
|
||||
|
||||
report << "<small>\n" << _("Remaining gold: ") << utils::half_signed_value(t.gold()) << "</small>";
|
||||
|
||||
if(t.carryover_bonus() != 0) {
|
||||
if(turns_left > -1) {
|
||||
report << "\n\n<b>" << _("Turns finished early: ") << turns_left << "</b>\n"
|
||||
<< "<small>" << _("Early finish bonus: ") << finishing_bonus_per_turn << _(" per turn") << "</small>\n"
|
||||
<< "<small>" << _("Total bonus: ") << finishing_bonus << "</small>\n";
|
||||
}
|
||||
|
||||
report << "<small>" << _("Total gold: ") << utils::half_signed_value(t.gold() + finishing_bonus) << "</small>";
|
||||
}
|
||||
|
||||
if(t.gold() > 0) {
|
||||
report << "\n<small>" << _("Carryover percentage: ") << t.carryover_percentage() << "</small>";
|
||||
}
|
||||
|
||||
if(t.carryover_add()) {
|
||||
report << "\n\n<big><b>" << _("Bonus gold: ") << utils::half_signed_value(t.carryover_gold()) << "</b></big>";
|
||||
} else {
|
||||
report << "\n\n<big><b>" << _("Retained gold: ") << utils::half_signed_value(t.carryover_gold()) << "</b></big>";
|
||||
}
|
||||
|
||||
std::string goldmsg;
|
||||
utils::string_map symbols;
|
||||
|
||||
symbols["gold"] = lexical_cast_default<std::string>(t.carryover_gold());
|
||||
|
||||
// Note that both strings are the same in English, but some languages will
|
||||
// want to translate them differently.
|
||||
if(t.carryover_add()) {
|
||||
if(t.carryover_gold() > 0) {
|
||||
goldmsg = VNGETTEXT(
|
||||
"You will start the next scenario with $gold on top of the defined minimum starting gold.",
|
||||
"You will start the next scenario with $gold on top of the defined minimum starting gold.",
|
||||
t.carryover_gold(), symbols
|
||||
);
|
||||
|
||||
} else {
|
||||
goldmsg = VNGETTEXT(
|
||||
"You will start the next scenario with the defined minimum starting gold.",
|
||||
"You will start the next scenario with the defined minimum starting gold.",
|
||||
t.carryover_gold(), symbols
|
||||
);
|
||||
}
|
||||
} else {
|
||||
goldmsg = VNGETTEXT(
|
||||
"You will start the next scenario with $gold or its defined minimum starting gold, "
|
||||
"whichever is higher.",
|
||||
"You will start the next scenario with $gold or its defined minimum starting gold, "
|
||||
"whichever is higher.",
|
||||
t.carryover_gold(), symbols
|
||||
);
|
||||
}
|
||||
|
||||
// xgettext:no-c-format
|
||||
report << "\n" << goldmsg;
|
||||
}
|
||||
}
|
||||
|
||||
if(end_level.transient.carryover_report) {
|
||||
gui2::show_transient_message(title, report.str(), "", true);
|
||||
}
|
||||
}
|
19
src/carryover_show_gold.hpp
Normal file
19
src/carryover_show_gold.hpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright (C) 2022 - 2022
|
||||
Part of the Battle for Wesnoth Project https://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
class game_state;
|
||||
/// calculates the amount of gold carried over for each team,
|
||||
/// stores the data in the team object and shows the carryover message
|
||||
void carryover_show_gold(game_state& state, bool is_observer, bool is_test);
|
|
@ -22,6 +22,7 @@
|
|||
#include "game_initialization/playcampaign.hpp"
|
||||
|
||||
#include "carryover.hpp"
|
||||
#include "carryover_show_gold.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "game_errors.hpp"
|
||||
|
@ -57,129 +58,6 @@ static lg::log_domain log_engine("engine");
|
|||
static lg::log_domain log_enginerefac("enginerefac");
|
||||
#define LOG_RG LOG_STREAM(info, log_enginerefac)
|
||||
|
||||
void campaign_controller::show_carryover_message(
|
||||
playsingle_controller& playcontroller, const end_level_data& end_level, const level_result::type res)
|
||||
{
|
||||
// We need to write the carryover amount to the team that's why we need non const
|
||||
std::vector<team>& teams = playcontroller.get_teams();
|
||||
|
||||
// maybe this can be the case for scenario that only contain a story and end during the prestart event ?
|
||||
if(teams.size() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostringstream report;
|
||||
std::string title;
|
||||
|
||||
bool obs = playcontroller.is_observer();
|
||||
|
||||
if(obs) {
|
||||
title = _("Scenario Report");
|
||||
} else if(res == level_result::type::victory) {
|
||||
title = _("Victory");
|
||||
report << "<b>" << _("You have emerged victorious!") << "</b>";
|
||||
} else {
|
||||
title = _("Defeat");
|
||||
report << _("You have been defeated!");
|
||||
}
|
||||
|
||||
const std::string& next_scenario = playcontroller.gamestate().get_game_data()->next_scenario();
|
||||
const bool has_next_scenario = !next_scenario.empty() && next_scenario != "null";
|
||||
|
||||
int persistent_teams = 0;
|
||||
for(const team& t : teams) {
|
||||
if(t.persistent()) {
|
||||
++persistent_teams;
|
||||
}
|
||||
}
|
||||
|
||||
if(persistent_teams > 0 && ((has_next_scenario && end_level.proceed_to_next_level) || state_.classification().is_test())) {
|
||||
const gamemap& map = playcontroller.get_map();
|
||||
const tod_manager& tod = playcontroller.get_tod_manager();
|
||||
|
||||
const int turns_left = std::max<int>(0, tod.number_of_turns() - tod.turn());
|
||||
for(team& t : teams) {
|
||||
if(!t.persistent() || t.lost()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const int finishing_bonus_per_turn = map.villages().size() * t.village_gold() + t.base_income();
|
||||
const int finishing_bonus = t.carryover_bonus() * finishing_bonus_per_turn * turns_left;
|
||||
|
||||
t.set_carryover_gold(div100rounded((t.gold() + finishing_bonus) * t.carryover_percentage()));
|
||||
|
||||
if(!t.is_local_human()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(persistent_teams > 1) {
|
||||
report << "\n\n<b>" << t.side_name() << "</b>";
|
||||
}
|
||||
|
||||
report << "<small>\n" << _("Remaining gold: ") << utils::half_signed_value(t.gold()) << "</small>";
|
||||
|
||||
if(t.carryover_bonus() != 0) {
|
||||
if(turns_left > -1) {
|
||||
report << "\n\n<b>" << _("Turns finished early: ") << turns_left << "</b>\n"
|
||||
<< "<small>" << _("Early finish bonus: ") << finishing_bonus_per_turn << _(" per turn") << "</small>\n"
|
||||
<< "<small>" << _("Total bonus: ") << finishing_bonus << "</small>\n";
|
||||
}
|
||||
|
||||
report << "<small>" << _("Total gold: ") << utils::half_signed_value(t.gold() + finishing_bonus) << "</small>";
|
||||
}
|
||||
|
||||
if(t.gold() > 0) {
|
||||
report << "\n<small>" << _("Carryover percentage: ") << t.carryover_percentage() << "</small>";
|
||||
}
|
||||
|
||||
if(t.carryover_add()) {
|
||||
report << "\n\n<big><b>" << _("Bonus gold: ") << utils::half_signed_value(t.carryover_gold()) << "</b></big>";
|
||||
} else {
|
||||
report << "\n\n<big><b>" << _("Retained gold: ") << utils::half_signed_value(t.carryover_gold()) << "</b></big>";
|
||||
}
|
||||
|
||||
std::string goldmsg;
|
||||
utils::string_map symbols;
|
||||
|
||||
symbols["gold"] = lexical_cast_default<std::string>(t.carryover_gold());
|
||||
|
||||
// Note that both strings are the same in English, but some languages will
|
||||
// want to translate them differently.
|
||||
if(t.carryover_add()) {
|
||||
if(t.carryover_gold() > 0) {
|
||||
goldmsg = VNGETTEXT(
|
||||
"You will start the next scenario with $gold on top of the defined minimum starting gold.",
|
||||
"You will start the next scenario with $gold on top of the defined minimum starting gold.",
|
||||
t.carryover_gold(), symbols
|
||||
);
|
||||
|
||||
} else {
|
||||
goldmsg = VNGETTEXT(
|
||||
"You will start the next scenario with the defined minimum starting gold.",
|
||||
"You will start the next scenario with the defined minimum starting gold.",
|
||||
t.carryover_gold(), symbols
|
||||
);
|
||||
}
|
||||
} else {
|
||||
goldmsg = VNGETTEXT(
|
||||
"You will start the next scenario with $gold or its defined minimum starting gold, "
|
||||
"whichever is higher.",
|
||||
"You will start the next scenario with $gold or its defined minimum starting gold, "
|
||||
"whichever is higher.",
|
||||
t.carryover_gold(), symbols
|
||||
);
|
||||
}
|
||||
|
||||
// xgettext:no-c-format
|
||||
report << "\n" << goldmsg;
|
||||
}
|
||||
}
|
||||
|
||||
if(end_level.transient.carryover_report) {
|
||||
gui2::show_transient_message(title, report.str(), "", true);
|
||||
}
|
||||
}
|
||||
|
||||
level_result::type campaign_controller::playsingle_scenario(end_level_data &end_level)
|
||||
{
|
||||
const config& starting_point = is_replay_
|
||||
|
@ -207,7 +85,7 @@ level_result::type campaign_controller::playsingle_scenario(end_level_data &end_
|
|||
}
|
||||
|
||||
end_level = playcontroller.get_end_level_data();
|
||||
show_carryover_message(playcontroller, end_level, res);
|
||||
carryover_show_gold(playcontroller.gamestate(), playcontroller.is_observer(), is_unit_test_);
|
||||
|
||||
if(!video::headless()) {
|
||||
playcontroller.maybe_linger();
|
||||
|
@ -232,7 +110,7 @@ level_result::type campaign_controller::playmp_scenario(end_level_data &end_leve
|
|||
if(res != level_result::type::observer_end) {
|
||||
// We need to call this before linger because it prints the defeated/victory message.
|
||||
//(we want to see that message before entering the linger mode)
|
||||
show_carryover_message(playcontroller, end_level, res);
|
||||
carryover_show_gold(playcontroller.gamestate(), playcontroller.is_observer(), is_unit_test_);
|
||||
}
|
||||
|
||||
playcontroller.maybe_linger();
|
||||
|
|
Loading…
Add table
Reference in a new issue