Author: sveinung Date: Fri Aug 14 15:04:50 2015 New Revision: 29495 URL: http://svn.gna.org/viewcvs/freeciv?rev=29495&view=rev Log: Tell if the actions are ready for use
Add the new function actions_are_ready() to make it easy to test if the actions are completely initialized. See patch #6224 Modified: trunk/common/actions.c trunk/common/actions.h Modified: trunk/common/actions.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.c?rev=29495&r1=29494&r2=29495&view=diff ============================================================================== --- trunk/common/actions.c (original) +++ trunk/common/actions.c Fri Aug 14 15:04:50 2015 @@ -29,6 +29,8 @@ #include "tile.h" static struct action *actions[ACTION_COUNT]; +static bool actions_initialized = FALSE; + static struct action_enabler_list *action_enablers_by_action[ACTION_COUNT]; static struct action *action_new(enum gen_action id, @@ -130,6 +132,9 @@ action_iterate(act) { action_enablers_by_action[act] = action_enabler_list_new(); } action_iterate_end; + + /* The actions them self are now initialized. */ + actions_initialized = TRUE; } /************************************************************************** @@ -137,6 +142,9 @@ **************************************************************************/ void actions_free(void) { + /* Don't consider the actions to be initialized any longer. */ + actions_initialized = FALSE; + action_iterate(act) { action_enabler_list_iterate(action_enablers_by_action[act], enabler) { requirement_vector_free(&enabler->actor_reqs); @@ -151,6 +159,32 @@ } /************************************************************************** + Returns TRUE iff the actions are initialized. + + Doesn't care about action enablers. +**************************************************************************/ +bool actions_are_ready(void) +{ + if (!actions_initialized) { + /* The actions them self aren't initialized yet. */ + return FALSE; + } + + action_iterate(act) { + if (actions[act]->ui_name[0] == '\0') { + /* An action without a UI name exists means that the ruleset haven't + * loaded yet. The ruleset loading will assign a default name to + * any actions not named by the ruleset. The client will get this + * name from the server. */ + return FALSE; + } + } action_iterate_end; + + /* The actions should be ready for use. */ + return TRUE; +} + +/************************************************************************** Create a new action. **************************************************************************/ static struct action *action_new(enum gen_action id, @@ -168,6 +202,7 @@ /* The ui_name is loaded from the ruleset. Until generalized actions * are ready it has to be defined seperatly from other action data. */ + action->ui_name[0] = '\0'; return action; } @@ -289,7 +324,7 @@ /* Text representation of the probability. */ const char* probtxt; - if (actions[action_id] == NULL) { + if (!actions_are_ready()) { /* Could be a client who haven't gotten the ruleset yet */ /* so there shouldn't be any action probability to show */ Modified: trunk/common/actions.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/actions.h?rev=29495&r1=29494&r2=29495&view=diff ============================================================================== --- trunk/common/actions.h (original) +++ trunk/common/actions.h Fri Aug 14 15:04:50 2015 @@ -189,6 +189,8 @@ void actions_init(void); void actions_free(void); +bool actions_are_ready(void); + struct action *action_by_number(int action_id); struct action *action_by_rule_name(const char *name); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits