Author: cazfi Date: Sun Jun 26 17:06:00 2016 New Revision: 33040 URL: http://svn.gna.org/viewcvs/freeciv?rev=33040&view=rev Log: Adding base in the editor now handles also the side-effects, such as removing conflicting bases.
Reported by Kumar <kumar> See bug #23106 Modified: trunk/client/client_main.c trunk/common/fc_interface.h trunk/common/tile.c trunk/server/maphand.c trunk/server/maphand.h trunk/server/scripting/api_server_edit.c trunk/server/srv_main.c trunk/server/unittools.c Modified: trunk/client/client_main.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/client/client_main.c?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/client/client_main.c (original) +++ trunk/client/client_main.c Sun Jun 26 17:06:00 2016 @@ -1341,6 +1341,7 @@ { struct functions *funcs = fc_interface_funcs(); + funcs->create_extra = NULL; funcs->destroy_extra = NULL; funcs->player_tile_vision_get = client_map_is_known_and_seen; funcs->gui_color_free = color_free; Modified: trunk/common/fc_interface.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/fc_interface.h?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/common/fc_interface.h (original) +++ trunk/common/fc_interface.h Sun Jun 26 17:06:00 2016 @@ -30,6 +30,8 @@ /* The existence of each function should be checked in interface_init()! */ struct functions { + void (*create_extra)(struct tile *ptile, struct extra_type *pextra, + struct player *pplayer); void (*destroy_extra)(struct tile *ptile, struct extra_type *pextra); /* Returns iff the player 'pplayer' has the vision in the layer 'vision' at tile given by 'ptile'. */ Modified: trunk/common/tile.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/tile.c?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/common/tile.c (original) +++ trunk/common/tile.c Sun Jun 26 17:06:00 2016 @@ -458,6 +458,19 @@ } /**************************************************************************** + Create extra to tile. +****************************************************************************/ +static void tile_create_extra(struct tile *ptile, struct extra_type *pextra) +{ + if (fc_funcs->create_extra != NULL) { + /* Assume callback calls tile_add_extra() itself. */ + fc_funcs->create_extra(ptile, pextra, NULL); + } else { + tile_add_extra(ptile, pextra); + } +} + +/**************************************************************************** Destroy extra from tile. ****************************************************************************/ static void tile_destroy_extra(struct tile *ptile, struct extra_type *pextra) @@ -512,7 +525,7 @@ return FALSE; } - tile_add_extra(ptile, pextra); + tile_create_extra(ptile, pextra); return TRUE; } Modified: trunk/server/maphand.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/maphand.c?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/server/maphand.c (original) +++ trunk/server/maphand.c Sun Jun 26 17:06:00 2016 @@ -2228,10 +2228,10 @@ } /**************************************************************************** - Create base to tile. -****************************************************************************/ -void create_base(struct tile *ptile, struct extra_type *pextra, - struct player *pplayer) + Create extra to tile. +****************************************************************************/ +void create_extra(struct tile *ptile, struct extra_type *pextra, + struct player *pplayer) { bool extras_removed = FALSE; @@ -2245,55 +2245,32 @@ tile_add_extra(ptile, pextra); - /* Watchtower might become effective - * FIXME: Reqs on other specials will not be updated immediately. */ + /* Watchtower might become effective. */ unit_list_refresh_vision(ptile->units); - /* Claim bases on tile */ - if (pplayer) { - struct player *old_owner = extra_owner(ptile); - - /* Created base from NULL -> pplayer */ - map_claim_base(ptile, pextra, pplayer, NULL); - - if (old_owner != pplayer) { - /* Existing bases from old_owner -> pplayer */ - extra_type_by_cause_iterate(EC_BASE, oldbase) { - if (oldbase != pextra) { - map_claim_base(ptile, oldbase, pplayer, old_owner); - } - } extra_type_by_cause_iterate_end; - - ptile->extras_owner = pplayer; - } - } else { - /* Player who already owns bases on tile claims new base */ - map_claim_base(ptile, pextra, extra_owner(ptile), NULL); - } - - if (extras_removed) { - /* Maybe conflicting extra that was removed was the only thing - * making tile native to some unit. */ - bounce_units_on_terrain_change(ptile); - } -} - -/**************************************************************************** - Create road to tile. -****************************************************************************/ -void create_road(struct tile *ptile, struct extra_type *pextra) -{ - bool extras_removed = FALSE; - - extra_type_iterate(old_extra) { - if (tile_has_extra(ptile, old_extra) - && !can_extras_coexist(old_extra, pextra)) { - tile_remove_extra(ptile, old_extra); - extras_removed = TRUE; - } - } extra_type_iterate_end; - - tile_add_extra(ptile, pextra); + if (pextra->data.base != NULL) { + /* Claim bases on tile */ + if (pplayer) { + struct player *old_owner = extra_owner(ptile); + + /* Created base from NULL -> pplayer */ + map_claim_base(ptile, pextra, pplayer, NULL); + + if (old_owner != pplayer) { + /* Existing bases from old_owner -> pplayer */ + extra_type_by_cause_iterate(EC_BASE, oldbase) { + if (oldbase != pextra) { + map_claim_base(ptile, oldbase, pplayer, old_owner); + } + } extra_type_by_cause_iterate_end; + + ptile->extras_owner = pplayer; + } + } else { + /* Player who already owns bases on tile claims new base */ + map_claim_base(ptile, pextra, extra_owner(ptile), NULL); + } + } if (extras_removed) { /* Maybe conflicting extra that was removed was the only thing Modified: trunk/server/maphand.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/maphand.h?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/server/maphand.h (original) +++ trunk/server/maphand.h Sun Jun 26 17:06:00 2016 @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -134,11 +134,9 @@ void change_playertile_site(struct player_tile *ptile, struct vision_site *new_site); -void create_base(struct tile *ptile, struct extra_type *pextra, - struct player *pplayer); +void create_extra(struct tile *ptile, struct extra_type *pextra, + struct player *pplayer); void destroy_extra(struct tile *ptile, struct extra_type *pextra); - -void create_road(struct tile *ptile, struct extra_type *pextra); void give_distorted_map(struct player *pfrom, struct player *pto, int good, int bad, bool reveal_cities); Modified: trunk/server/scripting/api_server_edit.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/api_server_edit.c?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/server/scripting/api_server_edit.c (original) +++ trunk/server/scripting/api_server_edit.c Sun Jun 26 17:06:00 2016 @@ -384,7 +384,7 @@ pextra = extra_type_by_rule_name(name); if (pextra) { - tile_add_extra(ptile, pextra); + create_extra(ptile, pextra, NULL); update_tile_knowledge(ptile); } } @@ -407,7 +407,7 @@ pextra = extra_type_by_rule_name(name); if (pextra != NULL && is_extra_caused_by(pextra, EC_BASE)) { - create_base(ptile, pextra, pplayer); + create_extra(ptile, pextra, pplayer); update_tile_knowledge(ptile); } } @@ -417,21 +417,7 @@ *****************************************************************************/ void api_edit_create_road(lua_State *L, Tile *ptile, const char *name) { - struct extra_type *pextra; - - LUASCRIPT_CHECK_STATE(L); - LUASCRIPT_CHECK_ARG_NIL(L, ptile, 2, Tile); - - if (!name) { - return; - } - - pextra = extra_type_by_rule_name(name); - - if (pextra != NULL && is_extra_caused_by(pextra, EC_ROAD)) { - create_road(ptile, pextra); - update_tile_knowledge(ptile); - } + api_edit_create_extra(L, ptile, name); } /***************************************************************************** Modified: trunk/server/srv_main.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/srv_main.c?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/server/srv_main.c (original) +++ trunk/server/srv_main.c Sun Jun 26 17:06:00 2016 @@ -3214,6 +3214,7 @@ { struct functions *funcs = fc_interface_funcs(); + funcs->create_extra = create_extra; funcs->destroy_extra = destroy_extra; funcs->player_tile_vision_get = map_is_known_and_seen; funcs->gui_color_free = server_gui_color_free; Modified: trunk/server/unittools.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=33040&r1=33039&r2=33040&view=diff ============================================================================== --- trunk/server/unittools.c (original) +++ trunk/server/unittools.c Sun Jun 26 17:06:00 2016 @@ -885,7 +885,7 @@ { if (total_activity(ptile, ACTIVITY_BASE, punit->activity_target) >= tile_activity_time(ACTIVITY_BASE, ptile, punit->activity_target)) { - create_base(ptile, punit->activity_target, unit_owner(punit)); + create_extra(ptile, punit->activity_target, unit_owner(punit)); unit_activity_done = TRUE; } } @@ -895,7 +895,7 @@ { if (total_activity(ptile, ACTIVITY_GEN_ROAD, punit->activity_target) >= tile_activity_time(ACTIVITY_GEN_ROAD, ptile, punit->activity_target)) { - create_road(ptile, punit->activity_target); + create_extra(ptile, punit->activity_target, unit_owner(punit)); unit_activity_done = TRUE; } } _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits