OpenTTD
company_cmd.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD 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, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "company_base.h"
14 #include "company_func.h"
15 #include "company_gui.h"
16 #include "town.h"
17 #include "news_func.h"
18 #include "cmd_helper.h"
19 #include "command_func.h"
20 #include "network/network.h"
21 #include "network/network_func.h"
22 #include "network/network_base.h"
23 #include "network/network_admin.h"
24 #include "ai/ai.hpp"
25 #include "company_manager_face.h"
26 #include "window_func.h"
27 #include "strings_func.h"
28 #include "date_func.h"
29 #include "sound_func.h"
30 #include "rail.h"
31 #include "core/pool_func.hpp"
32 #include "settings_func.h"
33 #include "vehicle_base.h"
34 #include "vehicle_func.h"
35 #include "smallmap_gui.h"
36 #include "game/game.hpp"
37 #include "goal_base.h"
38 #include "story_base.h"
39 
40 #include "table/strings.h"
41 
42 #include "safeguards.h"
43 
45 
52 
53 CompanyPool _company_pool("Company");
55 
56 
61 Company::Company(uint16 name_1, bool is_ai)
62 {
63  this->name_1 = name_1;
64  this->location_of_HQ = INVALID_TILE;
65  this->is_ai = is_ai;
66  this->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
67  this->clear_limit = _settings_game.construction.clear_frame_burst << 16;
68  this->tree_limit = _settings_game.construction.tree_frame_burst << 16;
69 
70  for (uint j = 0; j < 4; j++) this->share_owners[j] = COMPANY_SPECTATOR;
72 }
73 
76 {
77  if (CleaningPool()) return;
78 
80 }
81 
87 {
88  InvalidateWindowData(WC_GRAPH_LEGEND, 0, (int)index);
92  /* If the currently shown error message has this company in it, then close it. */
94 }
95 
102 void SetLocalCompany(CompanyID new_company)
103 {
104  /* company could also be COMPANY_SPECTATOR or OWNER_NONE */
105  assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
106 
107 #ifdef ENABLE_NETWORK
108  /* Delete the chat window, if you were team chatting. */
110 #endif
111 
112  assert(IsLocalCompany());
113 
114  _current_company = _local_company = new_company;
115 
116  /* Delete any construction windows... */
118 
119  /* ... and redraw the whole screen. */
122 }
123 
130 {
131  if (!Company::IsValidID(company)) return (TextColour)_colour_gradient[COLOUR_WHITE][4] | TC_IS_PALETTE_COLOUR;
133 }
134 
141 void DrawCompanyIcon(CompanyID c, int x, int y)
142 {
143  DrawSprite(SPR_COMPANY_ICON, COMPANY_SPRITE_COLOUR(c), x, y);
144 }
145 
153 {
154  if (!AreCompanyManagerFaceBitsValid(cmf, CMFV_GEN_ETHN, GE_WM)) return false;
155 
157  bool has_moustache = !HasBit(ge, GENDER_FEMALE) && GetCompanyManagerFaceBits(cmf, CMFV_HAS_MOUSTACHE, ge) != 0;
158  bool has_tie_earring = !HasBit(ge, GENDER_FEMALE) || GetCompanyManagerFaceBits(cmf, CMFV_HAS_TIE_EARRING, ge) != 0;
159  bool has_glasses = GetCompanyManagerFaceBits(cmf, CMFV_HAS_GLASSES, ge) != 0;
160 
161  if (!AreCompanyManagerFaceBitsValid(cmf, CMFV_EYE_COLOUR, ge)) return false;
162  for (CompanyManagerFaceVariable cmfv = CMFV_CHEEKS; cmfv < CMFV_END; cmfv++) {
163  switch (cmfv) {
164  case CMFV_MOUSTACHE: if (!has_moustache) continue; break;
165  case CMFV_LIPS:
166  case CMFV_NOSE: if (has_moustache) continue; break;
167  case CMFV_TIE_EARRING: if (!has_tie_earring) continue; break;
168  case CMFV_GLASSES: if (!has_glasses) continue; break;
169  default: break;
170  }
171  if (!AreCompanyManagerFaceBitsValid(cmf, cmfv, ge)) return false;
172  }
173 
174  return true;
175 }
176 
181 void InvalidateCompanyWindows(const Company *company)
182 {
183  CompanyID cid = company->index;
184 
185  if (cid == _local_company) SetWindowDirty(WC_STATUS_BAR, 0);
187 }
188 
195 {
196  if (cost.GetCost() > 0) {
197  const Company *c = Company::GetIfValid(_current_company);
198  if (c != NULL && cost.GetCost() > c->money) {
199  SetDParam(0, cost.GetCost());
200  cost.MakeError(STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY);
201  return false;
202  }
203  }
204  return true;
205 }
206 
213 {
214  if (cost.GetCost() == 0) return;
215  assert(cost.GetExpensesType() != INVALID_EXPENSES);
216 
217  c->money -= cost.GetCost();
218  c->yearly_expenses[0][cost.GetExpensesType()] += cost.GetCost();
219 
220  if (HasBit(1 << EXPENSES_TRAIN_INC |
221  1 << EXPENSES_ROADVEH_INC |
222  1 << EXPENSES_AIRCRAFT_INC |
223  1 << EXPENSES_SHIP_INC, cost.GetExpensesType())) {
224  c->cur_economy.income -= cost.GetCost();
225  } else if (HasBit(1 << EXPENSES_TRAIN_RUN |
226  1 << EXPENSES_ROADVEH_RUN |
227  1 << EXPENSES_AIRCRAFT_RUN |
228  1 << EXPENSES_SHIP_RUN |
229  1 << EXPENSES_PROPERTY |
230  1 << EXPENSES_LOAN_INT, cost.GetExpensesType())) {
231  c->cur_economy.expenses -= cost.GetCost();
232  }
233 
235 }
236 
242 {
243  Company *c = Company::GetIfValid(_current_company);
244  if (c != NULL) SubtractMoneyFromAnyCompany(c, cost);
245 }
246 
253 {
254  Company *c = Company::Get(company);
255  byte m = c->money_fraction;
256  Money cost = cst.GetCost();
257 
258  c->money_fraction = m - (byte)cost;
259  cost >>= 8;
260  if (c->money_fraction > m) cost++;
261  if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost));
262 }
263 
266 {
267  Company *c;
268  FOR_ALL_COMPANIES(c) {
272  }
273 }
274 
281 void GetNameOfOwner(Owner owner, TileIndex tile)
282 {
283  SetDParam(2, owner);
284 
285  if (owner != OWNER_TOWN) {
286  if (!Company::IsValidID(owner)) {
287  SetDParam(0, STR_COMPANY_SOMEONE);
288  } else {
289  SetDParam(0, STR_COMPANY_NAME);
290  SetDParam(1, owner);
291  }
292  } else {
293  assert(tile != 0);
294  const Town *t = ClosestTownFromTile(tile, UINT_MAX);
295 
296  SetDParam(0, STR_TOWN_NAME);
297  SetDParam(1, t->index);
298  }
299 }
300 
301 
311 {
312  assert(owner < OWNER_END);
313  assert(owner != OWNER_TOWN || tile != 0);
314 
315  if (owner == _current_company) return CommandCost();
316 
317  GetNameOfOwner(owner, tile);
318  return_cmd_error(STR_ERROR_OWNED_BY);
319 }
320 
329 {
330  Owner owner = GetTileOwner(tile);
331 
332  assert(owner < OWNER_END);
333 
334  if (owner == _current_company) return CommandCost();
335 
336  /* no need to get the name of the owner unless we're the local company (saves some time) */
337  if (IsLocalCompany()) GetNameOfOwner(owner, tile);
338  return_cmd_error(STR_ERROR_OWNED_BY);
339 }
340 
346 {
347  /* Reserve space for extra unicode character. We need to do this to be able
348  * to detect too long company name. */
349  char buffer[(MAX_LENGTH_COMPANY_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
350 
351  if (c->name_1 != STR_SV_UNNAMED) return;
352  if (c->last_build_coordinate == 0) return;
353 
355 
356  StringID str;
357  uint32 strp;
358  if (t->name == NULL && IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1)) {
359  str = t->townnametype - SPECSTR_TOWNNAME_START + SPECSTR_COMPANY_NAME_START;
360  strp = t->townnameparts;
361 
362 verify_name:;
363  /* No companies must have this name already */
364  Company *cc;
365  FOR_ALL_COMPANIES(cc) {
366  if (cc->name_1 == str && cc->name_2 == strp) goto bad_town_name;
367  }
368 
369  GetString(buffer, str, lastof(buffer));
370  if (Utf8StringLength(buffer) >= MAX_LENGTH_COMPANY_NAME_CHARS) goto bad_town_name;
371 
372 set_name:;
373  c->name_1 = str;
374  c->name_2 = strp;
375 
377 
378  if (c->is_ai) {
379  CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
380  cni->FillData(c);
381  SetDParam(0, STR_NEWS_COMPANY_LAUNCH_TITLE);
382  SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
383  SetDParamStr(2, cni->company_name);
384  SetDParam(3, t->index);
385  AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate, NR_NONE, UINT32_MAX, cni);
386  }
387  return;
388  }
389 bad_town_name:;
390 
391  if (c->president_name_1 == SPECSTR_PRESIDENT_NAME) {
392  str = SPECSTR_ANDCO_NAME;
393  strp = c->president_name_2;
394  goto set_name;
395  } else {
396  str = SPECSTR_ANDCO_NAME;
397  strp = Random();
398  goto verify_name;
399  }
400 }
401 
403 static const byte _colour_sort[COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1};
405 static const Colours _similar_colour[COLOUR_END][2] = {
406  { COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_DARK_BLUE
407  { COLOUR_GREEN, COLOUR_DARK_GREEN }, // COLOUR_PALE_GREEN
408  { INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_PINK
409  { COLOUR_ORANGE, INVALID_COLOUR }, // COLOUR_YELLOW
410  { INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_RED
411  { COLOUR_DARK_BLUE, COLOUR_BLUE }, // COLOUR_LIGHT_BLUE
412  { COLOUR_PALE_GREEN, COLOUR_DARK_GREEN }, // COLOUR_GREEN
413  { COLOUR_PALE_GREEN, COLOUR_GREEN }, // COLOUR_DARK_GREEN
414  { COLOUR_DARK_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_BLUE
415  { COLOUR_BROWN, COLOUR_ORANGE }, // COLOUR_CREAM
416  { COLOUR_PURPLE, INVALID_COLOUR }, // COLOUR_MAUVE
417  { COLOUR_MAUVE, INVALID_COLOUR }, // COLOUR_PURPLE
418  { COLOUR_YELLOW, COLOUR_CREAM }, // COLOUR_ORANGE
419  { COLOUR_CREAM, INVALID_COLOUR }, // COLOUR_BROWN
420  { COLOUR_WHITE, INVALID_COLOUR }, // COLOUR_GREY
421  { COLOUR_GREY, INVALID_COLOUR }, // COLOUR_WHITE
422 };
423 
428 static Colours GenerateCompanyColour()
429 {
430  Colours colours[COLOUR_END];
431 
432  /* Initialize array */
433  for (uint i = 0; i < COLOUR_END; i++) colours[i] = (Colours)i;
434 
435  /* And randomize it */
436  for (uint i = 0; i < 100; i++) {
437  uint r = Random();
438  Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]);
439  }
440 
441  /* Bubble sort it according to the values in table 1 */
442  for (uint i = 0; i < COLOUR_END; i++) {
443  for (uint j = 1; j < COLOUR_END; j++) {
444  if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) {
445  Swap(colours[j - 1], colours[j]);
446  }
447  }
448  }
449 
450  /* Move the colours that look similar to each company's colour to the side */
451  Company *c;
452  FOR_ALL_COMPANIES(c) {
453  Colours pcolour = (Colours)c->colour;
454 
455  for (uint i = 0; i < COLOUR_END; i++) {
456  if (colours[i] == pcolour) {
457  colours[i] = INVALID_COLOUR;
458  break;
459  }
460  }
461 
462  for (uint j = 0; j < 2; j++) {
463  Colours similar = _similar_colour[pcolour][j];
464  if (similar == INVALID_COLOUR) break;
465 
466  for (uint i = 1; i < COLOUR_END; i++) {
467  if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]);
468  }
469  }
470  }
471 
472  /* Return the first available colour */
473  for (uint i = 0; i < COLOUR_END; i++) {
474  if (colours[i] != INVALID_COLOUR) return colours[i];
475  }
476 
477  NOT_REACHED();
478 }
479 
485 {
486  for (;;) {
487 restart:;
488  c->president_name_2 = Random();
489  c->president_name_1 = SPECSTR_PRESIDENT_NAME;
490 
491  /* Reserve space for extra unicode character. We need to do this to be able
492  * to detect too long president name. */
494  SetDParam(0, c->index);
495  GetString(buffer, STR_PRESIDENT_NAME, lastof(buffer));
496  if (Utf8StringLength(buffer) >= MAX_LENGTH_PRESIDENT_NAME_CHARS) continue;
497 
498  Company *cc;
499  FOR_ALL_COMPANIES(cc) {
500  if (c != cc) {
501  /* Reserve extra space so even overlength president names can be compared. */
502  char buffer2[(MAX_LENGTH_PRESIDENT_NAME_CHARS + 1) * MAX_CHAR_LENGTH];
503  SetDParam(0, cc->index);
504  GetString(buffer2, STR_PRESIDENT_NAME, lastof(buffer2));
505  if (strcmp(buffer2, buffer) == 0) goto restart;
506  }
507  }
508  return;
509  }
510 }
511 
518 {
519  for (LiveryScheme scheme = LS_BEGIN; scheme < LS_END; scheme++) {
520  c->livery[scheme].in_use = 0;
521  c->livery[scheme].colour1 = c->colour;
522  c->livery[scheme].colour2 = c->colour;
523  }
524 
525  Group *g;
526  FOR_ALL_GROUPS(g) {
527  if (g->owner == c->index) {
528  g->livery.in_use = 0;
529  g->livery.colour1 = c->colour;
530  g->livery.colour2 = c->colour;
531  }
532  }
533 }
534 
543 {
544  if (!Company::CanAllocateItem()) return NULL;
545 
546  /* we have to generate colour before this company is valid */
547  Colours colour = GenerateCompanyColour();
548 
549  Company *c;
550  if (company == INVALID_COMPANY) {
551  c = new Company(STR_SV_UNNAMED, is_ai);
552  } else {
553  if (Company::IsValidID(company)) return NULL;
554  c = new (company) Company(STR_SV_UNNAMED, is_ai);
555  }
556 
557  c->colour = colour;
558 
560  _company_colours[c->index] = (Colours)c->colour;
561 
562  c->money = c->current_loan = (100000ll * _economy.inflation_prices >> 16) / 50000 * 50000;
563 
564  c->share_owners[0] = c->share_owners[1] = c->share_owners[2] = c->share_owners[3] = INVALID_OWNER;
565 
569  RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, false); // create a random company manager face
570 
573 
575 
582 
583  if (is_ai && (!_networking || _network_server)) AI::StartNew(c->index);
584 
585  AI::BroadcastNewEvent(new ScriptEventCompanyNew(c->index), c->index);
586  Game::NewEvent(new ScriptEventCompanyNew(c->index));
587 
588  return c;
589 }
590 
593 {
595 }
596 
598 static bool MaybeStartNewCompany()
599 {
600 #ifdef ENABLE_NETWORK
602 #endif /* ENABLE_NETWORK */
603 
604  Company *c;
605 
606  /* count number of competitors */
607  uint n = 0;
608  FOR_ALL_COMPANIES(c) {
609  if (c->is_ai) n++;
610  }
611 
613  /* Send a command to all clients to start up a new AI.
614  * Works fine for Multiplayer and Singleplayer */
615  return DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
616  }
617 
618  return false;
619 }
620 
623 {
625 }
626 
634 {
635  const Company *c1 = Company::Get(cbig);
636  const Company *c2 = Company::Get(csmall);
637 
638  /* Do the combined vehicle counts stay within the limits? */
643 }
644 
655 {
656  /* Amount of time out for each company to take over a company;
657  * Timeout is a quarter (3 months of 30 days) divided over the
658  * number of companies. The minimum number of days in a quarter
659  * is 90: 31 in January, 28 in February and 31 in March.
660  * Note that the company going bankrupt can't buy itself. */
661  static const int TAKE_OVER_TIMEOUT = 3 * 30 * DAY_TICKS / (MAX_COMPANIES - 1);
662 
663  assert(c->bankrupt_asked != 0);
664 
665  /* We're currently asking some company to buy 'us' */
666  if (c->bankrupt_timeout != 0) {
668  if (c->bankrupt_timeout > 0) return;
669  c->bankrupt_timeout = 0;
670 
671  return;
672  }
673 
674  /* Did we ask everyone for bankruptcy? If so, bail out. */
675  if (c->bankrupt_asked == MAX_UVALUE(CompanyMask)) return;
676 
677  Company *c2, *best = NULL;
678  int32 best_performance = -1;
679 
680  /* Ask the company with the highest performance history first */
681  FOR_ALL_COMPANIES(c2) {
682  if (c2->bankrupt_asked == 0 && // Don't ask companies going bankrupt themselves
683  !HasBit(c->bankrupt_asked, c2->index) &&
684  best_performance < c2->old_economy[1].performance_history &&
685  MayCompanyTakeOver(c2->index, c->index)) {
686  best_performance = c2->old_economy[1].performance_history;
687  best = c2;
688  }
689  }
690 
691  /* Asked all companies? */
692  if (best_performance == -1) {
693  c->bankrupt_asked = MAX_UVALUE(CompanyMask);
694  return;
695  }
696 
697  SetBit(c->bankrupt_asked, best->index);
698 
699  c->bankrupt_timeout = TAKE_OVER_TIMEOUT;
700  if (best->is_ai) {
701  AI::NewEvent(best->index, new ScriptEventCompanyAskMerger(c->index, ClampToI32(c->bankrupt_value)));
702  } else if (IsInteractiveCompany(best->index)) {
704  }
705 }
706 
709 {
710  if (_game_mode == GM_EDITOR) return;
711 
713  if (c != NULL) {
714  if (c->name_1 != 0) GenerateCompanyName(c);
716  }
717 
718  if (_next_competitor_start == 0) {
719  /* AI::GetStartNextTime() can return 0. */
721  }
722 
723  if (_game_mode != GM_MENU && AI::CanStartNew() && --_next_competitor_start == 0) {
724  /* Allow multiple AIs to possibly start in the same tick. */
725  do {
726  if (!MaybeStartNewCompany()) break;
727 
728  /* In networking mode, we can only send a command to start but it
729  * didn't execute yet, so we cannot loop. */
730  if (_networking) break;
731  } while (AI::GetStartNextTime() == 0);
732  }
733 
735 }
736 
742 {
743  Company *c;
744 
745  /* Copy statistics */
746  FOR_ALL_COMPANIES(c) {
747  memmove(&c->yearly_expenses[1], &c->yearly_expenses[0], sizeof(c->yearly_expenses) - sizeof(c->yearly_expenses[0]));
748  memset(&c->yearly_expenses[0], 0, sizeof(c->yearly_expenses[0]));
750  }
751 
752  if (_settings_client.gui.show_finances && _local_company != COMPANY_SPECTATOR) {
753  ShowCompanyFinances(_local_company);
754  c = Company::Get(_local_company);
756  if (_settings_client.sound.new_year) SndPlayFx(SND_01_BAD_YEAR);
757  } else {
758  if (_settings_client.sound.new_year) SndPlayFx(SND_00_GOOD_YEAR);
759  }
760  }
761 }
762 
769 {
770  SetDParam(0, c->index);
771  GetString(this->company_name, STR_COMPANY_NAME, lastof(this->company_name));
772 
773  if (other == NULL) {
774  *this->other_company_name = '\0';
775  } else {
776  SetDParam(0, other->index);
777  GetString(this->other_company_name, STR_COMPANY_NAME, lastof(this->other_company_name));
778  c = other;
779  }
780 
781  SetDParam(0, c->index);
782  GetString(this->president_name, STR_PRESIDENT_NAME_MANAGER, lastof(this->president_name));
783 
784  this->colour = c->colour;
785  this->face = c->face;
786 
787 }
788 
793 void CompanyAdminUpdate(const Company *company)
794 {
795 #ifdef ENABLE_NETWORK
797 #endif /* ENABLE_NETWORK */
798 }
799 
806 {
807 #ifdef ENABLE_NETWORK
809 #endif /* ENABLE_NETWORK */
810 }
811 
825 CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
826 {
828  CompanyID company_id = (CompanyID)GB(p1, 16, 8);
829 
830  switch ((CompanyCtrlAction)GB(p1, 0, 16)) {
831  case CCA_NEW: { // Create a new company
832  /* This command is only executed in a multiplayer game */
833  if (!_networking) return CMD_ERROR;
834 
835 #ifdef ENABLE_NETWORK
836  /* Has the network client a correct ClientIndex? */
837  if (!(flags & DC_EXEC)) return CommandCost();
838 
839  ClientID client_id = (ClientID)p2;
841 #ifndef DEBUG_DUMP_COMMANDS
842  /* When replaying the client ID is not a valid client; there
843  * are actually no clients at all. However, the company has to
844  * be created, otherwise we cannot rerun the game properly.
845  * So only allow a NULL client info in that case. */
846  if (ci == NULL) return CommandCost();
847 #endif /* NOT DEBUG_DUMP_COMMANDS */
848 
849  /* Delete multiplayer progress bar */
851 
852  Company *c = DoStartupNewCompany(false);
853 
854  /* A new company could not be created, revert to being a spectator */
855  if (c == NULL) {
856  if (_network_server) {
859  }
860  break;
861  }
862 
863  /* This is the client (or non-dedicated server) who wants a new company */
864  if (client_id == _network_own_client_id) {
865  assert(_local_company == COMPANY_SPECTATOR);
869  }
870 
871  /* Now that we have a new company, broadcast our company settings to
872  * all clients so everything is in sync */
874 
876  }
877 
879 #endif /* ENABLE_NETWORK */
880  break;
881  }
882 
883  case CCA_NEW_AI: { // Make a new AI company
884  if (!(flags & DC_EXEC)) return CommandCost();
885 
886  if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
887  Company *c = DoStartupNewCompany(true, company_id);
888 #ifdef ENABLE_NETWORK
889  if (c != NULL) NetworkServerNewCompany(c, NULL);
890 #endif /* ENABLE_NETWORK */
891  break;
892  }
893 
894  case CCA_DELETE: { // Delete a company
895  CompanyRemoveReason reason = (CompanyRemoveReason)GB(p2, 0, 2);
896  if (reason >= CRR_END) return CMD_ERROR;
897 
898  Company *c = Company::GetIfValid(company_id);
899  if (c == NULL) return CMD_ERROR;
900 
901  if (!(flags & DC_EXEC)) return CommandCost();
902 
903  /* Delete any open window of the company */
905  CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
906  cni->FillData(c);
907 
908  /* Show the bankrupt news */
909  SetDParam(0, STR_NEWS_COMPANY_BANKRUPT_TITLE);
910  SetDParam(1, STR_NEWS_COMPANY_BANKRUPT_DESCRIPTION);
911  SetDParamStr(2, cni->company_name);
912  AddCompanyNewsItem(STR_MESSAGE_NEWS_FORMAT, cni);
913 
914  /* Remove the company */
916  if (c->is_ai) AI::Stop(c->index);
917 
918  CompanyID c_index = c->index;
919  delete c;
920  AI::BroadcastNewEvent(new ScriptEventCompanyBankrupt(c_index));
921  Game::NewEvent(new ScriptEventCompanyBankrupt(c_index));
922  CompanyAdminRemove(c_index, (CompanyRemoveReason)reason);
923 
925  break;
926  }
927 
928  default: return CMD_ERROR;
929  }
930 
934 
935  return CommandCost();
936 }
937 
947 CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
948 {
950 
951  if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
952 
953  if (flags & DC_EXEC) {
954  Company::Get(_current_company)->face = cmf;
956  }
957  return CommandCost();
958 }
959 
971 CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
972 {
973  Colours colour = Extract<Colours, 0, 8>(p2);
974  LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1);
975  bool second = HasBit(p1, 8);
976 
977  if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR;
978 
979  /* Default scheme can't be reset to invalid. */
980  if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
981 
982  Company *c = Company::Get(_current_company);
983 
984  /* Ensure no two companies have the same primary colour */
985  if (scheme == LS_DEFAULT && !second) {
986  const Company *cc;
987  FOR_ALL_COMPANIES(cc) {
988  if (cc != c && cc->colour == colour) return CMD_ERROR;
989  }
990  }
991 
992  if (flags & DC_EXEC) {
993  if (!second) {
994  if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 0, 1, colour != INVALID_COLOUR);
995  if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour1;
996  c->livery[scheme].colour1 = colour;
997 
998  /* If setting the first colour of the default scheme, adjust the
999  * original and cached company colours too. */
1000  if (scheme == LS_DEFAULT) {
1001  for (int i = 1; i < LS_END; i++) {
1002  if (!HasBit(c->livery[i].in_use, 0)) c->livery[i].colour1 = colour;
1003  }
1005  c->colour = colour;
1006  CompanyAdminUpdate(c);
1007  }
1008  } else {
1009  if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 1, 1, colour != INVALID_COLOUR);
1010  if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour2;
1011  c->livery[scheme].colour2 = colour;
1012 
1013  if (scheme == LS_DEFAULT) {
1014  for (int i = 1; i < LS_END; i++) {
1015  if (!HasBit(c->livery[i].in_use, 1)) c->livery[i].colour2 = colour;
1016  }
1017  }
1018  }
1019 
1020  if (c->livery[scheme].in_use != 0) {
1021  /* If enabling a scheme, set the default scheme to be in use too */
1022  c->livery[LS_DEFAULT].in_use = 1;
1023  } else {
1024  /* Else loop through all schemes to see if any are left enabled.
1025  * If not, disable the default scheme too. */
1026  c->livery[LS_DEFAULT].in_use = 0;
1027  for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1028  if (c->livery[scheme].in_use != 0) {
1029  c->livery[LS_DEFAULT].in_use = 1;
1030  break;
1031  }
1032  }
1033  }
1034 
1035  ResetVehicleColourMap();
1037 
1038  /* All graph related to companies use the company colour. */
1045  /* The smallmap owner view also stores the company colours. */
1046  BuildOwnerLegend();
1048 
1049  /* Company colour data is indirectly cached. */
1050  Vehicle *v;
1051  FOR_ALL_VEHICLES(v) {
1052  if (v->owner == _current_company) v->InvalidateNewGRFCache();
1053  }
1054 
1055  extern void UpdateObjectColours(const Company *c);
1057  }
1058  return CommandCost();
1059 }
1060 
1066 static bool IsUniqueCompanyName(const char *name)
1067 {
1068  const Company *c;
1069 
1070  FOR_ALL_COMPANIES(c) {
1071  if (c->name != NULL && strcmp(c->name, name) == 0) return false;
1072  }
1073 
1074  return true;
1075 }
1076 
1086 CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1087 {
1088  bool reset = StrEmpty(text);
1089 
1090  if (!reset) {
1092  if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1093  }
1094 
1095  if (flags & DC_EXEC) {
1096  Company *c = Company::Get(_current_company);
1097  free(c->name);
1098  c->name = reset ? NULL : stredup(text);
1100  CompanyAdminUpdate(c);
1101  }
1102 
1103  return CommandCost();
1104 }
1105 
1111 static bool IsUniquePresidentName(const char *name)
1112 {
1113  const Company *c;
1114 
1115  FOR_ALL_COMPANIES(c) {
1116  if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false;
1117  }
1118 
1119  return true;
1120 }
1121 
1131 CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
1132 {
1133  bool reset = StrEmpty(text);
1134 
1135  if (!reset) {
1137  if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
1138  }
1139 
1140  if (flags & DC_EXEC) {
1141  Company *c = Company::Get(_current_company);
1142  free(c->president_name);
1143 
1144  if (reset) {
1145  c->president_name = NULL;
1146  } else {
1147  c->president_name = stredup(text);
1148 
1149  if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
1150  char buf[80];
1151 
1152  seprintf(buf, lastof(buf), "%s Transport", text);
1153  DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, buf);
1154  }
1155  }
1156 
1158  CompanyAdminUpdate(c);
1159  }
1160 
1161  return CommandCost();
1162 }
1163 
1171 {
1172  const VehicleDefaultSettings *vds = (c == NULL) ? &_settings_client.company.vehicle : &c->settings.vehicle;
1173  switch (type) {
1174  default: NOT_REACHED();
1175  case VEH_TRAIN: return vds->servint_trains;
1176  case VEH_ROAD: return vds->servint_roadveh;
1177  case VEH_AIRCRAFT: return vds->servint_aircraft;
1178  case VEH_SHIP: return vds->servint_ships;
1179  }
1180 }
static void PostDestructor(size_t index)
Invalidating some stuff after removing item from the pool.
Definition: company_cmd.cpp:86
Last + 1 owner.
Definition: company_type.h:30
void InvalidateCompanyWindows(const Company *company)
Refresh all windows owned by a company.
Functions related to OTTD&#39;s strings.
void UpdateLandscapingLimits()
Update the landscaping limits per company.
VehicleSettings vehicle
options for vehicles
uint32 tree_per_64k_frames
how many trees may, over a long period, be planted per 65536 frames?
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:277
void NetworkAdminCompanyUpdate(const Company *company)
Notify the admin network of company updates.
static bool IsLocalCompany()
Is the current company the local company?
Definition: company_func.h:45
int CompanyServiceInterval(const Company *c, VehicleType type)
Get the service interval for the given company and vehicle type.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
static void NewEvent(class ScriptEvent *event)
Queue a new event for a Game Script.
Definition: game_core.cpp:143
used in multiplayer to create a new companies etc.
Definition: command_type.h:279
Definition of stuff that is very close to a company, like the company struct itself.
static void StartNew(CompanyID company, bool rerandomise_ai=true)
Start a new AI company.
Definition: ai_core.cpp:38
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:257
bool _networking
are we in networking mode?
Definition: network.cpp:56
void FillData(const struct Company *c, const struct Company *other=NULL)
Fill the CompanyNewsInformation struct with the required data.
Default settings for vehicles.
Container for all information known about a client.
Definition: network_base.h:27
char * name
Name of the company if the user changed it.
Definition: company_base.h:56
LiveryScheme
List of different livery schemes.
Definition: livery.h:22
AdminCompanyRemoveReason
Reasons for removing a company - communicated to admins.
Definition: tcp_admin.h:105
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3199
TextColour GetDrawStringCompanyColour(CompanyID company)
Get the colour for DrawString-subroutines which matches the colour of the company.
void InitializeCompanies()
Initialize the pool of companies.
void BuildOwnerLegend()
Completes the array for the owned property legend.
Client list; Window numbers:
Definition: window_type.h:474
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
int32 performance_history
Company score (scale 0-1000)
Definition: company_base.h:27
Functions related to dates.
static bool IsInsideMM(const T x, const uint min, const uint max)
Checks if a value is in an interval.
Definition: math_func.hpp:266
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Definition: string.cpp:409
byte money_fraction
Fraction of money of the company, too small to represent in money.
Definition: company_base.h:65
CompanyManagerFace _company_manager_face
for company manager face storage in openttd.cfg
Definition: company_cmd.cpp:49
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the company manager&#39;s face.
void ClearEnginesHiddenFlagOfCompany(CompanyID cid)
Clear the &#39;hidden&#39; flag for all engines of a new company.
Definition: engine.cpp:843
Year inaugurated_year
Year of starting the company.
Definition: company_base.h:77
static bool IsUniqueCompanyName(const char *name)
Is the given name in use as name of a company?
void DeleteConstructionWindows()
Delete all windows that are used for construction of vehicle etc.
Definition: window.cpp:3408
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
This bit set means a female, otherwise male.
ExpensesType GetExpensesType() const
The expense type of the cost.
Definition: command_type.h:93
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:53
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
ClientID client_id
Client identifier (same as ClientState->client_id)
Definition: network_base.h:28
uint64 inflation_prices
Cumulated inflation of prices since game start; 16 bit fractional part.
Definition: economy_type.h:29
Rail specific functions.
bool CheckCompanyHasMoney(CommandCost &cost)
Verify whether the company can pay the bill.
Popup for the client list; Window numbers:
Definition: window_type.h:480
Sign list; Window numbers:
Definition: window_type.h:273
void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
Change the ownership of all the items of a company.
Definition: economy.cpp:289
CompanyMask bankrupt_asked
which companies were asked about buying it?
Definition: company_base.h:80
uint _cur_company_tick_index
used to generate a name for one company that doesn&#39;t have a name yet per tick
Definition: company_cmd.cpp:51
Functions related to vehicles.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Vehicle data structure.
Definition: vehicle_base.h:212
CompanyPool _company_pool("Company")
Pool of companies.
UnitID max_aircraft
max planes in game per company
void NetworkUpdateClientInfo(ClientID client_id)
Send updated client info of a particular client.
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
DifficultySettings difficulty
settings related to the difficulty
static void BroadcastNewEvent(ScriptEvent *event, CompanyID skip_company=MAX_COMPANIES)
Broadcast a new event to all active AIs.
Definition: ai_core.cpp:263
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
char * president_name
Name of the president if the user changed it.
Definition: company_base.h:60
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
Definition: date_type.h:30
Company value graph; Window numbers:
Definition: window_type.h:548
bool new_year
Play sound on new year, summarising the performance during the last year.
Helper functions to extract data from command parameters.
static const uint MAX_LENGTH_PRESIDENT_NAME_CHARS
The maximum length of a president name in characters including &#39;\0&#39;.
Definition: company_type.h:41
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:50
The client is spectating.
Definition: company_type.h:37
static int GetStartNextTime()
Get the number of days before the next AI should start.
Definition: ai_core.cpp:311
Data that needs to be stored for company news messages.
Definition: news_type.h:150
uint16 tree_frame_burst
how many trees may, over a short period, be planted?
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:84
Base core network types and some helper functions to access them.
uint32 name_2
Parameter of name_1.
Definition: company_base.h:54
RoadTypes GetCompanyRoadtypes(CompanyID company)
Get the road types the given company can build.
Definition: road.cpp:139
static bool IsValidCompanyManagerFace(CompanyManagerFace cmf)
Checks whether a company manager&#39;s face is a valid encoding.
A male of Caucasian origin (white)
Common return value for all commands.
Definition: command_type.h:25
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
CompanySettings settings
settings specific for each company
Definition: company_base.h:126
void DeleteCompanyWindows(CompanyID company)
Delete all windows of a company.
Definition: window.cpp:1179
Running costs trains.
Definition: economy_type.h:153
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
void MakeError(StringID message)
Makes this CommandCost behave like an error command.
Definition: command_type.h:102
uint16 servint_ships
service interval for ships
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
char company_name[64]
The name of the company.
Definition: news_type.h:151
Income graph; Window numbers:
Definition: window_type.h:524
Money expenses
The amount of expenses.
Definition: company_base.h:25
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3317
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
Definition: town_cmd.cpp:3329
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
Aircraft vehicle type.
Definition: vehicle_type.h:29
uint32 clear_per_64k_frames
how many tiles may, over a long period, be cleared per 65536 frames?
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the name of the company.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
NetworkSettings network
settings related to the network
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:20
uint32 CompanyManagerFace
Company manager face bits, info see in company_manager_face.h.
Definition: company_type.h:55
void SetDefaultCompanySettings(CompanyID cid)
Set the company settings for a new company to their default values.
Definition: settings.cpp:1985
CompanyID client_playas
As which company is this client playing (CompanyID)
Definition: network_base.h:31
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
Subtract money from a company, including the money fraction.
uint32 terraform_limit
Amount of tileheights we can (still) terraform (times 65536).
Definition: company_base.h:84
~Company()
Destructor.
Definition: company_cmd.cpp:75
byte num_valid_stat_ent
Number of valid statistical entries in old_economy.
Definition: company_base.h:97
bool MayCompanyTakeOver(CompanyID cbig, CompanyID csmall)
May company cbig buy company csmall?
void GetNameOfOwner(Owner owner, TileIndex tile)
Set the right DParams to get the name of an owner.
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:440
Error message; Window numbers:
Definition: window_type.h:105
CompanySettings company
default values for per-company settings
Income from road vehicles.
Definition: economy_type.h:159
SoundSettings sound
sound effect settings
UnitID max_roadveh
max trucks in game per company
Chatbox; Window numbers:
Definition: window_type.h:493
VehicleDefaultSettings vehicle
default settings for vehicles
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
static const byte _colour_sort[COLOUR_END]
Sorting weights for the company colours.
Small map; Window numbers:
Definition: window_type.h:99
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:180
void SyncCompanySettings()
Sync all company settings in a multiplayer game.
Definition: settings.cpp:1999
static void HandleBankruptcyTakeover(Company *c)
Handle the bankruptcy take over of a company.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:343
Money current_loan
Amount of money borrowed from the bank.
Definition: company_base.h:66
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the company&#39;s company-colour.
static void SubtractMoneyFromAnyCompany(Company *c, CommandCost cost)
Deduct costs of a command from the money of a company.
Create a new AI company.
Definition: company_type.h:70
Functions related to setting/changing the settings.
Linkgraph legend; Window numbers:
Definition: window_type.h:676
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:63
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
Definition of base types and functions in a cross-platform compatible way.
static const uint MAX_LENGTH_COMPANY_NAME_CHARS
The maximum length of a company name in characters including &#39;\0&#39;.
Definition: company_type.h:42
Reference tile. Scroll to tile when clicking on the news.
Definition: news_type.h:53
A number of safeguards to prevent using unsafe methods.
void SetLocalCompany(CompanyID new_company)
Sets the local company and updates the settings that are set on a per-company basis to reflect the co...
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
uint32 clear_limit
Amount of tiles we can (still) clear (times 65536).
Definition: company_base.h:85
static Colours GenerateCompanyColour()
Generate a company colour.
static void RandomCompanyManagerFaceBits(CompanyManagerFace &cmf, GenderEthnicity ge, bool adv, bool interactive=true)
Make a random new face.
void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
Called whenever a company is removed in order to notify admins.
Operating profit graph; Window numbers:
Definition: window_type.h:530
Company league window; Window numbers:
Definition: window_type.h:554
Empty reference.
Definition: news_type.h:52
Finances of a company; Window numbers:
Definition: window_type.h:518
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:138
GUI Functions related to companies.
uint32 terraform_per_64k_frames
how many tile heights may, over a long period, be terraformed per 65536 frames?
GroupStatistics group_all[VEH_COMPANY_END]
NOSAVE: Statistics for the ALL_GROUP group.
Definition: company_base.h:127
change the company name
Definition: command_type.h:245
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
void CompaniesYearlyLoop()
A year has passed, update the economic data of all companies, and perhaps show the financial overview...
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
Definition: company_base.h:92
The tile has no ownership.
Definition: company_type.h:27
Money money
Money owned by the company.
Definition: company_base.h:64
Basic functions/variables used all over the place.
Sentinel for end.
Definition: company_type.h:64
uint16 num_vehicle
Number of vehicles.
Definition: group.h:27
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:531
uint16 clear_frame_burst
how many tiles may, over a short period, be cleared?
bool show_finances
show finances at end of year
Definition: settings_type.h:89
Road vehicle type.
Definition: vehicle_type.h:27
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
Definition: stdafx.h:491
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
Running costs ships.
Definition: economy_type.h:156
void CompanyAdminUpdate(const Company *company)
Called whenever company related information changes in order to notify admins.
RailTypes GetCompanyRailtypes(CompanyID company)
Get the rail types the given company can build.
Definition: rail.cpp:267
Delete a company.
Definition: company_type.h:71
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:83
static bool MaybeStartNewCompany()
Start a new competitor company if possible.
static void Stop(CompanyID company)
Stop a company to be controlled by an AI.
Definition: ai_core.cpp:105
CompanyManagerFace face
Face description of the president.
Definition: company_base.h:62
Maximum number of companies.
Definition: company_type.h:25
uint _next_competitor_start
the number of ticks before the next AI is started
Definition: company_cmd.cpp:50
int16 bankrupt_timeout
If bigger than 0, amount of time to wait for an answer on an offer to buy this company.
Definition: company_base.h:81
uint32 tree_limit
Amount of trees we can (still) plant (times 65536).
Definition: company_base.h:86
Income from aircraft.
Definition: economy_type.h:160
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:35
void NetworkAdminCompanyRemove(CompanyID company_id, AdminCompanyRemoveReason bcrr)
Notify the admin network of a company to be removed (including the reason why).
Base class for all pools.
Definition: pool_type.hpp:83
uint8 max_companies
maximum amount of companies
Ship vehicle type.
Definition: vehicle_type.h:28
static void NewEvent(CompanyID company, ScriptEvent *event)
Queue a new event for an AI.
Definition: ai_core.cpp:238
static const Colours _similar_colour[COLOUR_END][2]
Similar colours, so we can try to prevent same coloured companies.
Company news item. (Newspaper with face)
Definition: news_type.h:82
uint32 president_name_2
Parameter of president_name_1.
Definition: company_base.h:59
Performance detail window; Window numbers:
Definition: window_type.h:566
Network status window; Window numbers:
Definition: window_type.h:487
Livery livery
Custom colour scheme for vehicles in this group.
Definition: group.h:73
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don&#39;t get linker errors.
Definition: pool_func.hpp:226
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1144
static bool IsInteractiveCompany(CompanyID company)
Is the user representing company?
Definition: company_func.h:55
execute the given command
Definition: command_type.h:345
UnitID max_ships
max ships in game per company
static bool CleaningPool()
Returns current state of pool cleaning - yes or no.
Definition: pool_type.hpp:225
Smallmap GUI functions.
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:203
Functions related to companies.
Network join status.
Definition: window_type.h:34
void ShowBuyCompanyDialog(CompanyID company)
Show the query to buy another company.
Company(uint16 name_1=0, bool is_ai=false)
Constructor.
Definition: company_cmd.cpp:61
Running costs road vehicles.
Definition: economy_type.h:154
Functionality related to the company manager&#39;s face.
CompanyCtrlAction
The action to do with CMD_COMPANY_CTRL.
Definition: company_type.h:68
GUISettings gui
settings related to the GUI
void StartupCompanies()
Start the next competitor now.
Base class for all vehicles.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
Definition: string.cpp:312
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Change the name of the president.
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
OwnerByte share_owners[4]
Owners of the 4 shares of the company. INVALID_OWNER if nobody has bought them yet.
Definition: company_base.h:75
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:276
uint16 servint_trains
service interval for trains
A town owns the tile, or a town is expanding.
Definition: company_type.h:26
void AddNewsItem(StringID string, NewsType type, NewsFlag flags, NewsReferenceType reftype1=NR_NONE, uint32 ref1=UINT32_MAX, NewsReferenceType reftype2=NR_NONE, uint32 ref2=UINT32_MAX, void *free_data=NULL)
Add a new newsitem to be shown.
Definition: news_gui.cpp:654
static void GenerateCompanyName(Company *c)
Generate the name of a company from the last build coordinate.
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:55
Company info (new companies, bankruptcy messages)
Definition: news_type.h:27
void NetworkServerNewCompany(const Company *company, NetworkClientInfo *ci)
Perform all the server specific administration of a new company.
byte colour
Company colour.
Definition: company_base.h:68
StringID president_name_1
Name of the president if the user did not change it.
Definition: company_base.h:58
ClientID
&#39;Unique&#39; identifier to be given to clients
Definition: network_type.h:43
Property costs.
Definition: economy_type.h:157
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
static bool AreCompanyManagerFaceBitsValid(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
Checks whether the company manager&#39;s face bits have a valid range.
uint16 terraform_frame_burst
how many tile heights may, over a short period, be terraformed?
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:120
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
TileIndex last_build_coordinate
Coordinate of the last build thing by this company.
Definition: company_base.h:73
CompanyEconomyEntry old_economy[MAX_HISTORY_QUARTERS]
Economic data of the company of the last MAX_HISTORY_QUARTERS quarters.
Definition: company_base.h:96
void SubtractMoneyFromCompany(CommandCost cost)
Subtract money from the _current_company, if the company is valid.
Goal base class.
Running costs aircraft.
Definition: economy_type.h:155
Town data structure.
Definition: town.h:55
uint16 servint_aircraft
service interval for aircraft
Group data.
Definition: group.h:67
char default_company_pass[NETWORK_PASSWORD_LENGTH]
default password for new companies in encrypted form
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:216
Statusbar (at the bottom of your screen); Window numbers:
Definition: window_type.h:59
Base functions for all Games.
Functions related to commands.
Network functions used by other parts of OpenTTD.
byte in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
Definition: livery.h:81
char * name
Custom town name. If NULL, the town was not renamed and uses the generated name.
Definition: town.h:64
bool _network_server
network-server is active
Definition: network.cpp:57
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:53
AI list; Window numbers:
Definition: window_type.h:279
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
Colours _company_colours[MAX_COMPANIES]
NOSAVE: can be determined from company structs.
Definition: company_cmd.cpp:48
CompanyRemoveReason
The reason why the company was removed.
Definition: company_type.h:59
byte max_no_competitors
the number of competitors (AIs)
Definition: settings_type.h:56
Income from trains.
Definition: economy_type.h:158
UnitID max_trains
max trains in game per company
ConstructionSettings construction
construction of things in-game
Colour value is already a real palette colour index, not an index of a StringColour.
Definition: gfx_type.h:270
StoryPage base class.
Delivered cargo graph; Window numbers:
Definition: window_type.h:536
Income from ships.
Definition: economy_type.h:161
AI settings; Window numbers:
Definition: window_type.h:170
Money yearly_expenses[3][EXPENSES_END]
Expenses of the company for the last three years, in every ExpensesType category. ...
Definition: company_base.h:94
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
GenderEthnicity
The gender/race combinations that we have faces for.
OwnerByte owner
Group Owner.
Definition: group.h:69
static bool CanStartNew()
Is it possible to start a new AI company?
Definition: ai_core.cpp:32
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:119
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Create a new company.
Definition: company_type.h:69
Base functions for all AIs.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:987
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Base of the town class.
byte colour1
First colour, for all vehicles.
Definition: livery.h:82
Invalid expense type.
Definition: economy_type.h:165
uint16 servint_roadveh
service interval for road vehicles
Money income
The amount of income.
Definition: company_base.h:24
Owner
Enum for all companies/owners.
Definition: company_type.h:20
static void GeneratePresidentName(Company *c)
Generate a random president name of a company.
Window functions not directly related to making/drawing windows.
static NetworkClientInfo * GetByClientID(ClientID client_id)
Return the CI given it&#39;s client-identifier.
Definition: network.cpp:126
static bool IsUniquePresidentName(const char *name)
Is the given name in use as president name of a company?
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
Definition: object_cmd.cpp:177
const char * NetworkChangeCompanyPassword(CompanyID company_id, const char *password)
Change the company password of a given company.
Definition: network.cpp:174
Legend for graphs; Window numbers:
Definition: window_type.h:512
CompanyEconomyEntry cur_economy
Economic data of the company of this quarter.
Definition: company_base.h:95
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting)
Definition: window.cpp:3227
Functions related to news.
Company * DoStartupNewCompany(bool is_ai, CompanyID company=INVALID_COMPANY)
Create a new company and sets all company variables default values.
void ResetCompanyLivery(Company *c)
Reset the livery schemes to the company&#39;s primary colour.
static uint GetCompanyManagerFaceBits(CompanyManagerFace cmf, CompanyManagerFaceVariable cmfv, GenderEthnicity ge)
Gets the company manager&#39;s face bits for the given company manager&#39;s face variable.
An invalid company.
Definition: company_type.h:32
Send message/notice to everyone playing the same company (Team)
Definition: network_type.h:84
Game options window; Window numbers:
Definition: window_type.h:608
void InvalidateNewGRFCache()
Invalidates cached NewGRF variables.
Definition: vehicle_base.h:451
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:834
void OnTick_Companies()
Called every tick for updating some company info.
Performance history graph; Window numbers:
Definition: window_type.h:542
An invalid owner.
Definition: company_type.h:31
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition: window.cpp:3299
Server part of the admin network protocol.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1463
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Control the companies: add, delete, etc.
Train vehicle type.
Definition: vehicle_type.h:26
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201
Interest payments over the loan.
Definition: economy_type.h:162