Author: cazfi Date: Sat Jan 10 11:13:36 2015 New Revision: 27602 URL: http://svn.gna.org/viewcvs/freeciv?rev=27602&view=rev Log: Added autosettler activity iterator as_transform_activity_iterate(). Unlike activity_type_iterate() it goes through only the activities autosettler really is interested about, excluding road and base building activities that are handled in their own loops.
See patch #5673 Modified: branches/S2_6/ai/threaded/taicity.c branches/S2_6/common/unit.h branches/S2_6/server/advisors/autosettlers.c branches/S2_6/server/advisors/autosettlers.h branches/S2_6/server/advisors/infracache.c branches/S2_6/server/srv_main.c Modified: branches/S2_6/ai/threaded/taicity.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/ai/threaded/taicity.c?rev=27602&r1=27601&r2=27602&view=diff ============================================================================== --- branches/S2_6/ai/threaded/taicity.c (original) +++ branches/S2_6/ai/threaded/taicity.c Sat Jan 10 11:13:36 2015 @@ -123,8 +123,11 @@ potential_worst_worked = TRUE; } - activity_type_iterate(act) { + as_transform_activity_iterate(act) { bool consider = TRUE; + bool possible = FALSE; + enum extra_cause cause; + enum extra_rmcause rmcause; /* Do not request activities that already are under way. */ unit_list_iterate(ptile->units, punit) { @@ -140,57 +143,51 @@ continue; } - if (act == ACTIVITY_IRRIGATE - || act == ACTIVITY_MINE - || act == ACTIVITY_POLLUTION - || act == ACTIVITY_FALLOUT) { - bool possible = FALSE; - enum extra_cause cause = activity_to_extra_cause(act); - enum extra_rmcause rmcause = activity_to_extra_rmcause(act); - - unit_list_iterate(units, punit) { - struct extra_type *tgt = NULL; - - if (cause != EC_NONE) { - tgt = next_extra_for_tile(ptile, cause, pplayer, punit); - } else if (rmcause != ERM_NONE) { - tgt = prev_extra_in_tile(ptile, rmcause, pplayer, punit); - } - - if (can_unit_do_activity_targeted_at(punit, act, tgt, ptile)) { - possible = TRUE; - break; - } - } unit_list_iterate_end; - - if (possible) { - int value = adv_city_worker_act_get(pcity, cindex, act); - - if (tile_worked(ptile) == pcity) { - if ((value - orig_value) * TWMP > worked.want) { - worked.want = TWMP * (value - orig_value); - worked.ptile = ptile; - worked.act = act; - worked.tgt = NULL; - } - if (value > old_worst_worked) { - /* After improvement it would not be the worst */ - potential_worst_worked = FALSE; - } else { - worst_worked = value; - } + cause = activity_to_extra_cause(act); + rmcause = activity_to_extra_rmcause(act); + + unit_list_iterate(units, punit) { + struct extra_type *tgt = NULL; + + if (cause != EC_NONE) { + tgt = next_extra_for_tile(ptile, cause, pplayer, punit); + } else if (rmcause != ERM_NONE) { + tgt = prev_extra_in_tile(ptile, rmcause, pplayer, punit); + } + + if (can_unit_do_activity_targeted_at(punit, act, tgt, ptile)) { + possible = TRUE; + break; + } + } unit_list_iterate_end; + + if (possible) { + int value = adv_city_worker_act_get(pcity, cindex, act); + + if (tile_worked(ptile) == pcity) { + if ((value - orig_value) * TWMP > worked.want) { + worked.want = TWMP * (value - orig_value); + worked.ptile = ptile; + worked.act = act; + worked.tgt = NULL; + } + if (value > old_worst_worked) { + /* After improvement it would not be the worst */ + potential_worst_worked = FALSE; } else { - if (value > orig_value && value > uw_max) { - uw_max = value; - unworked.want = TWMP * (value - orig_value); - unworked.ptile = ptile; - unworked.act = act; - unworked.tgt = NULL; - } - } - } - } - } activity_type_iterate_end; + worst_worked = value; + } + } else { + if (value > orig_value && value > uw_max) { + uw_max = value; + unworked.want = TWMP * (value - orig_value); + unworked.ptile = ptile; + unworked.act = act; + unworked.tgt = NULL; + } + } + } + } as_transform_activity_iterate_end; road_type_iterate(proad) { bool possible = FALSE; Modified: branches/S2_6/common/unit.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/common/unit.h?rev=27602&r1=27601&r2=27602&view=diff ============================================================================== --- branches/S2_6/common/unit.h (original) +++ branches/S2_6/common/unit.h Sat Jan 10 11:13:36 2015 @@ -223,16 +223,23 @@ extern Activity_type_id real_activities[ACTIVITY_LAST]; +#define activity_type_list_iterate(_act_list_, _act_) \ +{ \ + int _act_i_; \ + for (_act_i_ = 0; _act_list_[_act_i_] != ACTIVITY_LAST; _act_i_++) { \ + Activity_type_id _act_ = _act_list_[_act_i_]; + +#define activity_type_list_iterate_end \ + } \ +} + /* Iterates over the types of unit activity. */ -#define activity_type_iterate(act) \ +#define activity_type_iterate(_act_) \ { \ - int _act_i_; \ - \ - for (_act_i_ = 0; real_activities[_act_i_] != ACTIVITY_LAST; _act_i_++) { \ - Activity_type_id act = real_activities[_act_i_]; - -#define activity_type_iterate_end \ - } \ + activity_type_list_iterate(real_activities, _act_) + +#define activity_type_iterate_end \ + activity_type_list_iterate_end \ } bool unit_can_help_build_wonder(const struct unit *punit, Modified: branches/S2_6/server/advisors/autosettlers.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/autosettlers.c?rev=27602&r1=27601&r2=27602&view=diff ============================================================================== --- branches/S2_6/server/advisors/autosettlers.c (original) +++ branches/S2_6/server/advisors/autosettlers.c Sat Jan 10 11:13:36 2015 @@ -71,6 +71,27 @@ int enroute; /* unit ID of settler en route to this tile */ int eta; /* estimated number of turns until enroute arrives */ }; + +Activity_type_id as_activities_transform[ACTIVITY_LAST]; + +/************************************************************************** + Initialize advisor systems. +**************************************************************************/ +void advisors_init(void) +{ + int i = 0; + + as_activities_transform[i++] = ACTIVITY_IRRIGATE; + as_activities_transform[i++] = ACTIVITY_MINE; + as_activities_transform[i++] = ACTIVITY_TRANSFORM; + + /* TODO: Pollution and Fallout are not transform type of activities, + * but the autosettlers code currently expects them to be in this list */ + as_activities_transform[i++] = ACTIVITY_POLLUTION; + as_activities_transform[i++] = ACTIVITY_FALLOUT; + + as_activities_transform[i++] = ACTIVITY_LAST; +} /************************************************************************** Calculate the attractiveness of building a road/rail at the given tile. @@ -451,7 +472,7 @@ oldv = city_tile_value(pcity, ptile, 0, 0); /* Now, consider various activities... */ - activity_type_iterate(act) { + as_transform_activity_iterate(act) { struct extra_type *target = NULL; enum extra_cause cause = activity_to_extra_cause(act); enum extra_rmcause rmcause = activity_to_extra_rmcause(act); @@ -466,8 +487,6 @@ if (adv_city_worker_act_get(pcity, cindex, act) >= 0 /* These need separate implementations. */ - && act != ACTIVITY_BASE - && act != ACTIVITY_GEN_ROAD && can_unit_do_activity_targeted_at(punit, act, target, ptile)) { int extra = 0; @@ -496,7 +515,7 @@ best_tile, ptile); } /* endif: can the worker perform this action */ - } activity_type_iterate_end; + } as_transform_activity_iterate_end; road_type_iterate(proad) { struct extra_type *target = road_extra_get(proad); Modified: branches/S2_6/server/advisors/autosettlers.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/autosettlers.h?rev=27602&r1=27601&r2=27602&view=diff ============================================================================== --- branches/S2_6/server/advisors/autosettlers.h (original) +++ branches/S2_6/server/advisors/autosettlers.h Sat Jan 10 11:13:36 2015 @@ -16,6 +16,8 @@ /* common */ #include "fc_types.h" #include "map.h" + +void advisors_init(void); struct settlermap; struct pf_path; @@ -57,4 +59,14 @@ int adv_settlers_road_bonus(struct tile *ptile, struct road_type *proad); +extern Activity_type_id as_activities_transform[ACTIVITY_LAST]; + +#define as_transform_activity_iterate(_act_) \ +{ \ + activity_type_list_iterate(as_activities_transform, _act_) + +#define as_transform_activity_iterate_end \ + activity_type_list_iterate_end \ +} + #endif /* FC__AUTOSETTLERS_H */ Modified: branches/S2_6/server/advisors/infracache.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/advisors/infracache.c?rev=27602&r1=27601&r2=27602&view=diff ============================================================================== --- branches/S2_6/server/advisors/infracache.c (original) +++ branches/S2_6/server/advisors/infracache.c Sat Jan 10 11:13:36 2015 @@ -27,6 +27,7 @@ /* server/advisors */ #include "advbuilding.h" +#include "autosettlers.h" #include "infracache.h" @@ -414,9 +415,9 @@ int best = best_worker_tile_value(pcity); city_map_iterate(radius_sq, city_index, city_x, city_y) { - activity_type_iterate(act) { + as_transform_activity_iterate(act) { adv_city_worker_act_set(pcity, city_index, act, -1); - } activity_type_iterate_end; + } as_transform_activity_iterate_end; } city_map_iterate_end; city_tile_iterate_index(radius_sq, pcenter, ptile, cindex) { Modified: branches/S2_6/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/srv_main.c?rev=27602&r1=27601&r2=27602&view=diff ============================================================================== --- branches/S2_6/server/srv_main.c (original) +++ branches/S2_6/server/srv_main.c Sat Jan 10 11:13:36 2015 @@ -2960,6 +2960,7 @@ void srv_main(void) { fc_interface_init_server(); + advisors_init(); srv_prepare(); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits