From 7aabb887d4b613d02addf5b705d15c5f2c329208 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 31 Jul 2010 21:43:07 +0000 Subject: (svn r20269) -Codechange: Use IsLocalCompany() everywhere, document the function and two company globals. --- src/company_cmd.cpp | 6 +++--- src/company_func.h | 4 ++++ src/network/network_command.cpp | 2 +- src/openttd.cpp | 2 +- src/window.cpp | 8 ++++---- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 7605a563b..414363aed 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -39,8 +39,8 @@ #include "table/strings.h" -CompanyByte _local_company; -CompanyByte _current_company; +CompanyByte _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR. +CompanyByte _current_company; ///< Company currently doing an action. /* NOSAVE: can be determined from company structs */ Colours _company_colours[MAX_COMPANIES]; CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg @@ -97,7 +97,7 @@ void SetLocalCompany(CompanyID new_company) InvalidateWindowData(WC_SEND_NETWORK_MSG, DESTTYPE_TEAM, _local_company); #endif - assert(_current_company == _local_company); + assert(IsLocalCompany()); _current_company = _local_company = new_company; diff --git a/src/company_func.h b/src/company_func.h index 4b520ce7b..8dcdffbe8 100644 --- a/src/company_func.h +++ b/src/company_func.h @@ -27,6 +27,10 @@ extern CompanyByte _current_company; extern Colours _company_colours[MAX_COMPANIES]; ///< NOSAVE: can be determined from company structs extern CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg +/** + * Is the current company the local company? + * @return \c true of the current company is the local company, \c false otherwise. + */ static inline bool IsLocalCompany() { return _local_company == _current_company; diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp index 5e0ca4323..39eae0f94 100644 --- a/src/network/network_command.cpp +++ b/src/network/network_command.cpp @@ -154,7 +154,7 @@ void NetworkSyncCommandQueue(NetworkClientSocket *cs) */ void NetworkExecuteLocalCommandQueue() { - assert(_current_company == _local_company); + assert(IsLocalCompany()); while (_local_command_queue != NULL) { diff --git a/src/openttd.cpp b/src/openttd.cpp index 0d8bead6b..0d3916ff2 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1269,7 +1269,7 @@ void StateGameLoop() cur_company.Restore(); } - assert(_current_company == _local_company); + assert(IsLocalCompany()); } /** Create an autosave. The default name is "autosave#.sav". However with diff --git a/src/window.cpp b/src/window.cpp index 6bbc140f9..a0e1c4c54 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1974,7 +1974,7 @@ void HandleKeypress(uint32 raw_key) { /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ - assert(IsGeneratingWorld() || _local_company == _current_company); + assert(IsGeneratingWorld() || IsLocalCompany()); /* Setup event */ uint16 key = GB(raw_key, 0, 16); @@ -2135,7 +2135,7 @@ static void MouseLoop(MouseClick click, int mousewheel) { /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ - assert(IsGeneratingWorld() || _local_company == _current_company); + assert(IsGeneratingWorld() || IsLocalCompany()); HandlePlacePresize(); UpdateTileSelection(); @@ -2241,7 +2241,7 @@ void HandleMouseEvents() { /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ - assert(IsGeneratingWorld() || _local_company == _current_company); + assert(IsGeneratingWorld() || IsLocalCompany()); static int double_click_time = 0; static Point double_click_pos = {0, 0}; @@ -2348,7 +2348,7 @@ void InputLoop() { /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ - assert(IsGeneratingWorld() || _local_company == _current_company); + assert(IsGeneratingWorld() || IsLocalCompany()); CheckSoftLimit(); HandleKeyScrolling(); -- cgit v1.2.3-70-g09d2