Mercurial > hg > openttd
comparison src/economy.cpp @ 10696:7edccbb67398 draft
(svn r15027) -Merge: tomatos and bananas left to be, here is NoAI for all to see.
NoAI is an API (a framework) to build your own AIs in. See:
http://wiki.openttd.org/wiki/index.php/AI:Main_Page
With many thanks to:
- glx and Rubidium for their syncing, feedback and hard work
- Yexo for his feedback, patches, and AIs which tested the system very deep
- Morloth for his feedback and patches
- TJIP for hosting a challenge which kept NoAI on track
- All AI authors for testing our AI API, and all other people who helped in one way or another
-Remove: all old AIs and their cheats/hacks
author | truebrain <truebrain@openttd.org> |
---|---|
date | Mon, 12 Jan 2009 17:11:45 +0000 |
parents | 592ae9307430 |
children | a4e5b5d2837c |
comparison
equal
deleted
inserted
replaced
10695:bc69b6508e53 | 10696:7edccbb67398 |
---|---|
15 #include "news_func.h" | 15 #include "news_func.h" |
16 #include "network/network.h" | 16 #include "network/network.h" |
17 #include "network/network_func.h" | 17 #include "network/network_func.h" |
18 #include "variables.h" | 18 #include "variables.h" |
19 #include "vehicle_gui.h" | 19 #include "vehicle_gui.h" |
20 #include "ai/ai.h" | 20 #include "ai/ai.hpp" |
21 #include "train.h" | 21 #include "train.h" |
22 #include "roadveh.h" | 22 #include "roadveh.h" |
23 #include "aircraft.h" | 23 #include "aircraft.h" |
24 #include "newgrf_engine.h" | 24 #include "newgrf_engine.h" |
25 #include "newgrf_sound.h" | 25 #include "newgrf_sound.h" |
478 case 2: | 478 case 2: |
479 SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE); | 479 SetDParam(0, STR_7056_TRANSPORT_COMPANY_IN_TROUBLE); |
480 SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED); | 480 SetDParam(1, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED); |
481 SetDParamStr(2, cni->company_name); | 481 SetDParamStr(2, cni->company_name); |
482 AddNewsItem(STR_02B6, NS_COMPANY_TROUBLE, 0, 0, cni); | 482 AddNewsItem(STR_02B6, NS_COMPANY_TROUBLE, 0, 0, cni); |
483 AI::BroadcastNewEvent(new AIEventCompanyInTrouble(c->index)); | |
483 break; | 484 break; |
484 case 3: { | 485 case 3: { |
485 /* XXX - In multiplayer, should we ask other companies if it wants to take | 486 /* XXX - In multiplayer, should we ask other companies if it wants to take |
486 over when it is a human company? -- TrueLight */ | 487 over when it is a human company? -- TrueLight */ |
487 if (IsHumanCompany(c->index)) { | 488 if (IsHumanCompany(c->index)) { |
527 | 528 |
528 /* Remove the company */ | 529 /* Remove the company */ |
529 ChangeNetworkOwner(c->index, COMPANY_SPECTATOR); | 530 ChangeNetworkOwner(c->index, COMPANY_SPECTATOR); |
530 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER); | 531 ChangeOwnershipOfCompanyItems(c->index, INVALID_OWNER); |
531 | 532 |
532 /* Register the company as not-active */ | 533 if (!IsHumanCompany(c->index)) AI::Stop(c->index); |
533 if (!IsHumanCompany(c->index) && (!_networking || _network_server) && _ai.enabled) { | 534 |
534 AI_CompanyDied(c->index); | 535 CompanyID c_index = c->index; |
535 } | |
536 | |
537 delete c; | 536 delete c; |
537 AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index)); | |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 static void CompaniesGenStatistics() | 541 static void CompaniesGenStatistics() |
542 { | 542 { |
1063 if (s->age == 12-1) { | 1063 if (s->age == 12-1) { |
1064 pair = SetupSubsidyDecodeParam(s, 1); | 1064 pair = SetupSubsidyDecodeParam(s, 1); |
1065 AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, pair.a, pair.b); | 1065 AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NS_SUBSIDIES, pair.a, pair.b); |
1066 s->cargo_type = CT_INVALID; | 1066 s->cargo_type = CT_INVALID; |
1067 modified = true; | 1067 modified = true; |
1068 AI::BroadcastNewEvent(new AIEventSubsidyOfferExpired(s - _subsidies)); | |
1068 } else if (s->age == 2*12-1) { | 1069 } else if (s->age == 2*12-1) { |
1069 st = GetStation(s->to); | 1070 st = GetStation(s->to); |
1070 if (st->owner == _local_company) { | 1071 if (st->owner == _local_company) { |
1071 pair = SetupSubsidyDecodeParam(s, 1); | 1072 pair = SetupSubsidyDecodeParam(s, 1); |
1072 AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, pair.a, pair.b); | 1073 AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NS_SUBSIDIES, pair.a, pair.b); |
1073 } | 1074 } |
1074 s->cargo_type = CT_INVALID; | 1075 s->cargo_type = CT_INVALID; |
1075 modified = true; | 1076 modified = true; |
1077 AI::BroadcastNewEvent(new AIEventSubsidyExpired(s - _subsidies)); | |
1076 } else { | 1078 } else { |
1077 s->age++; | 1079 s->age++; |
1078 } | 1080 } |
1079 } | 1081 } |
1080 | 1082 |
1107 add_subsidy: | 1109 add_subsidy: |
1108 if (!CheckSubsidyDuplicate(s)) { | 1110 if (!CheckSubsidyDuplicate(s)) { |
1109 s->age = 0; | 1111 s->age = 0; |
1110 pair = SetupSubsidyDecodeParam(s, 0); | 1112 pair = SetupSubsidyDecodeParam(s, 0); |
1111 AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, pair.a, pair.b); | 1113 AddNewsItem(STR_2030_SERVICE_SUBSIDY_OFFERED, NS_SUBSIDIES, pair.a, pair.b); |
1114 AI::BroadcastNewEvent(new AIEventSubsidyOffer(s - _subsidies)); | |
1112 modified = true; | 1115 modified = true; |
1113 break; | 1116 break; |
1114 } | 1117 } |
1115 } | 1118 } |
1116 } while (n--); | 1119 } while (n--); |
1324 AddNewsItem( | 1327 AddNewsItem( |
1325 STR_2031_SERVICE_SUBSIDY_AWARDED + _settings_game.difficulty.subsidy_multiplier, | 1328 STR_2031_SERVICE_SUBSIDY_AWARDED + _settings_game.difficulty.subsidy_multiplier, |
1326 NS_SUBSIDIES, | 1329 NS_SUBSIDIES, |
1327 pair.a, pair.b | 1330 pair.a, pair.b |
1328 ); | 1331 ); |
1332 AI::BroadcastNewEvent(new AIEventSubsidyAwarded(s - _subsidies)); | |
1329 | 1333 |
1330 InvalidateWindow(WC_SUBSIDIES_LIST, 0); | 1334 InvalidateWindow(WC_SUBSIDIES_LIST, 0); |
1331 return true; | 1335 return true; |
1332 } | 1336 } |
1333 } | 1337 } |
1815 static void DoAcquireCompany(Company *c) | 1819 static void DoAcquireCompany(Company *c) |
1816 { | 1820 { |
1817 Company *owner; | 1821 Company *owner; |
1818 int i; | 1822 int i; |
1819 Money value; | 1823 Money value; |
1824 CompanyID ci = c->index; | |
1820 | 1825 |
1821 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); | 1826 CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1); |
1822 cni->FillData(c, GetCompany(_current_company)); | 1827 cni->FillData(c, GetCompany(_current_company)); |
1823 | 1828 |
1824 SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER); | 1829 SetDParam(0, STR_7059_TRANSPORT_COMPANY_MERGER); |
1825 SetDParam(1, c->bankrupt_value == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR); | 1830 SetDParam(1, c->bankrupt_value == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR); |
1826 SetDParamStr(2, cni->company_name); | 1831 SetDParamStr(2, cni->company_name); |
1827 SetDParamStr(3, cni->other_company_name); | 1832 SetDParamStr(3, cni->other_company_name); |
1828 SetDParam(4, c->bankrupt_value); | 1833 SetDParam(4, c->bankrupt_value); |
1829 AddNewsItem(STR_02B6, NS_COMPANY_MERGER, 0, 0, cni); | 1834 AddNewsItem(STR_02B6, NS_COMPANY_MERGER, 0, 0, cni); |
1835 AI::BroadcastNewEvent(new AIEventCompanyMerger(ci, _current_company)); | |
1830 | 1836 |
1831 /* original code does this a little bit differently */ | 1837 /* original code does this a little bit differently */ |
1832 CompanyID ci = c->index; | |
1833 ChangeNetworkOwner(ci, _current_company); | 1838 ChangeNetworkOwner(ci, _current_company); |
1834 ChangeOwnershipOfCompanyItems(ci, _current_company); | 1839 ChangeOwnershipOfCompanyItems(ci, _current_company); |
1835 | 1840 |
1836 if (c->bankrupt_value == 0) { | 1841 if (c->bankrupt_value == 0) { |
1837 owner = GetCompany(_current_company); | 1842 owner = GetCompany(_current_company); |
1845 _current_company = c->share_owners[i]; | 1850 _current_company = c->share_owners[i]; |
1846 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value)); | 1851 SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -value)); |
1847 } | 1852 } |
1848 } | 1853 } |
1849 _current_company = old_company; | 1854 _current_company = old_company; |
1855 | |
1856 if (!IsHumanCompany(c->index)) AI::Stop(c->index); | |
1850 | 1857 |
1851 DeleteCompanyWindows(ci); | 1858 DeleteCompanyWindows(ci); |
1852 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); | 1859 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
1853 InvalidateWindowClassesData(WC_SHIPS_LIST, 0); | 1860 InvalidateWindowClassesData(WC_SHIPS_LIST, 0); |
1854 InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); | 1861 InvalidateWindowClassesData(WC_ROADVEH_LIST, 0); |