Author: sveinung Date: Fri Aug 14 15:08:51 2015 New Revision: 29500 URL: http://svn.gna.org/viewcvs/freeciv?rev=29500&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: branches/S2_6/common/actions.c branches/S2_6/common/actions.h Modified: branches/S2_6/common/actions.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/actions.c?rev=29500&r1=29499&r2=29500&view=diff ============================================================================== --- branches/S2_6/common/actions.c (original) +++ branches/S2_6/common/actions.c Fri Aug 14 15:08:51 2015 @@ -28,6 +28,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, @@ -104,6 +106,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; } /************************************************************************** @@ -111,6 +116,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); @@ -125,6 +133,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, @@ -142,6 +176,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; } @@ -221,7 +256,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: branches/S2_6/common/actions.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/actions.h?rev=29500&r1=29499&r2=29500&view=diff ============================================================================== --- branches/S2_6/common/actions.h (original) +++ branches/S2_6/common/actions.h Fri Aug 14 15:08:51 2015 @@ -171,6 +171,8 @@ void actions_init(void); void actions_free(void); +bool actions_are_ready(void); + struct action *action_by_number(int action_id); enum action_actor_kind action_get_actor_kind(int action_id); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits