summaryrefslogtreecommitdiff
path: root/src/company_cmd.cpp
diff options
context:
space:
mode:
authorSamu <dj_samu@hotmail.com>2019-01-31 14:35:13 +0000
committerPeterN <peter@fuzzle.org>2019-02-02 16:37:11 +0000
commit011257dc8804175dd7d1e839e97e796c0a88aee6 (patch)
tree97f0da59d87fda8935d741722b76ea64819160a8 /src/company_cmd.cpp
parentfa53abe864a6939dc4dac8a6c61443e486e0eb04 (diff)
downloadopenttd-011257dc8804175dd7d1e839e97e796c0a88aee6.tar.xz
Change: Allow AI companies to start immediately.
Allow multiple AIs to possibly start in the same tick. start_date = 0 becomes a special case, where random deviation does not occur. If start_date was not already 0, then a minimum value of 1 must apply.
Diffstat (limited to 'src/company_cmd.cpp')
-rw-r--r--src/company_cmd.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index be75d94c8..cf66690f4 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -595,10 +595,10 @@ void StartupCompanies()
}
/** Start a new competitor company if possible. */
-static void MaybeStartNewCompany()
+static bool MaybeStartNewCompany()
{
#ifdef ENABLE_NETWORK
- if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return;
+ if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return false;
#endif /* ENABLE_NETWORK */
Company *c;
@@ -612,8 +612,10 @@ static void MaybeStartNewCompany()
if (n < (uint)_settings_game.difficulty.max_no_competitors) {
/* Send a command to all clients to start up a new AI.
* Works fine for Multiplayer and Singleplayer */
- DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
+ return DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
}
+
+ return false;
}
/** Initialize the pool of companies. */
@@ -714,11 +716,15 @@ void OnTick_Companies()
}
if (_next_competitor_start == 0) {
- _next_competitor_start = AI::GetStartNextTime() * DAY_TICKS;
+ /* AI::GetStartNextTime() can return 0. */
+ _next_competitor_start = max(1, AI::GetStartNextTime() * DAY_TICKS);
}
- if (AI::CanStartNew() && _game_mode != GM_MENU && --_next_competitor_start == 0) {
- MaybeStartNewCompany();
+ if (_game_mode != GM_MENU && AI::CanStartNew() && --_next_competitor_start == 0) {
+ /* Allow multiple AIs to possibly start in the same tick. */
+ do {
+ if (!MaybeStartNewCompany()) break;
+ } while (AI::GetStartNextTime() == 0);
}
_cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES;