changeset 17833:22216d88b87b draft

(svn r22624) -Fix [FS#4654]: When closing an AI company the local player cheated to, we need to cheat him to another company.
author frosch <frosch@openttd.org>
date Sat, 02 Jul 2011 19:31:01 +0000
parents 96058cf233f7
children 371333fd42a2
files src/economy.cpp
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -296,6 +296,21 @@
 	/* In all cases, make spectators of clients connected to that company */
 	if (_networking) NetworkClientsToSpectators(old_owner);
 #endif /* ENABLE_NETWORK */
+	if (old_owner == _local_company) {
+		/* Single player cheated to AI company.
+		 * There are no specatators in single player, so we must pick some other company. */
+		assert(!_networking);
+		Backup<CompanyByte> cur_company(_current_company, FILE_LINE);
+		Company *c;
+		FOR_ALL_COMPANIES(c) {
+			if (c->index != old_owner) {
+				SetLocalCompany(c->index);
+				break;
+			}
+		}
+		cur_company.Restore();
+		assert(old_owner != _local_company);
+	}
 
 	Town *t;