Author: sveinung Date: Wed Aug 27 11:49:02 2014 New Revision: 26075 URL: http://svn.gna.org/viewcvs/freeciv?rev=26075&view=rev Log: Infer if a unit type is an actor from the action enablers, not Diplomat
Up until now a unit have been seen as a potential actor if it has the Diplomat unit type flag. It is possible to have a unit with the Diplomat unit type that can't perform any actions. In the future it should be possible to have actors without the Diplomat unit type flag. Stop relying on the Diplomat unit flag to determine if the unit type can perform generalized actions. Check if at least one action controlled by generalized (ruleset) action enablers is possible in stead. See patch #5102 Modified: trunk/common/unittype.c Modified: trunk/common/unittype.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/unittype.c?rev=26075&r1=26074&r2=26075&view=diff ============================================================================== --- trunk/common/unittype.c (original) +++ trunk/common/unittype.c Wed Aug 27 11:49:02 2014 @@ -258,6 +258,38 @@ uclass_index(utype_class(ptranstype))); } +/* Cache if a unit can perform any actions at all. */ +static bv_unit_types unit_can_act_cache; + +/************************************************************************** + Cache if a unit of the given type can perform any action controlled by + generalized (ruleset defined) action enablers. +**************************************************************************/ +static void unit_can_act_cache_set(struct unit_type *putype) +{ + /* Clear old value */ + BV_CLR(unit_can_act_cache, utype_index(putype)); + + /* See if the unit type can do an action controlled by generalized action + * enablers */ + action_enablers_iterate(enabler) { + if (requirement_fulfilled_by_unit_type(putype, + &(enabler->actor_reqs))) { + BV_SET(unit_can_act_cache, utype_index(putype)); + return; + } + } action_enablers_iterate_end; +} + +/************************************************************************** + Return TRUE iff units of this type can do actions controlled by + generalized (ruleset defined) action enablers. +**************************************************************************/ +bool is_actor_unit_type(const struct unit_type *putype) +{ + return BV_ISSET(unit_can_act_cache, utype_index(putype)); +} + /* Cache if any action at all may be possible when the actor unit's state * is... * bit 0 to USP_COUNT - 1: Possible when the corresponding property is TRUE @@ -321,16 +353,7 @@ void unit_type_action_cache_set(struct unit_type *ptype) { unit_state_action_cache_set(ptype); -} - -/************************************************************************** - Return TRUE iff units of this type can do actions controlled by - generalized (ruleset defined) action enablers. -**************************************************************************/ -bool is_actor_unit_type(const struct unit_type *putype) -{ - /* All units that can do generalized actions are diplomats */ - return utype_has_flag(putype, UTYF_DIPLOMAT); + unit_can_act_cache_set(ptype); } /************************************************************************** _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits