[Freeciv-Dev] (PR#40374) [Editor] build city improvements in the cityreport dialog
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40374 Hi, This feature may have been in the editor previously but is probably commented out now, so I tried to implement it the proper way. With this patch you can let cities build items like improvements and units while in editor mode by clicking on the buy button of the general cityreport dialog (Hotkey F4 in the GTK GUI, where you get a list of all cities of one player). This will cost nothing for the player owning the city and the improvements/units will be immediately added to the given city without having to wait one turn like in the usual context of this button. This feature should work with any clients supporting the Editor mode however, it won't affect the buy button you get in the normal city dialog when double clicking on a city (either on the map or in the general cityreport). That's what I'm currently looking after to change, but it looks like this button and it's callback is implemented GUI specific, but that is just guessing of mine. As you may have thought I'm completely new to this project and am just mostly busy trying to learn to look through the existing code and guessing how I could work with it. So any further contributions may take some time. ;) Greetings Nico diff -Nur -Xdiff_ignore trunk/client/climisc.c changed/client/climisc.c --- trunk/client/climisc.c 2008-07-05 19:58:11.0 +0200 +++ changed/client/climisc.c 2008-07-13 22:47:33.0 +0200 @@ -1023,25 +1023,36 @@ **/ void cityrep_buy(struct city *pcity) { - int value; - - if (city_production_has_flag(pcity, IF_GOLD)) { -create_event(pcity-tile, E_BAD_COMMAND, - _(You don't buy %s in %s!), - improvement_name_translation(pcity-production.value.building), - city_name(pcity)); -return; - } - value = city_production_buy_gold_cost(pcity); - - if (city_owner(pcity)-economic.gold = value) { -city_buy_production(pcity); + if (!can_conn_edit(client.conn)) { +int value; + +if (city_production_has_flag(pcity, IF_GOLD)) { + create_event(pcity-tile, E_BAD_COMMAND, + _(You don't buy %s in %s!), + improvement_name_translation( + pcity-production.value.building), + city_name(pcity)); + return; +} +value = city_production_buy_gold_cost(pcity); + +if (city_owner(pcity)-economic.gold = value) { + city_buy_production(pcity); +} else { + create_event(NULL, E_BAD_COMMAND, + _(%s costs %d gold and you only have %d gold.), + city_production_name_translation(pcity), + value, + city_owner(pcity)-economic.gold); +} } else { -create_event(NULL, E_BAD_COMMAND, - _(%s costs %d gold and you only have %d gold.), - city_production_name_translation(pcity), - value, - city_owner(pcity)-economic.gold); +/* Editor mode can build without any cost or waiting for next turn */ +if (client.conn.playing != NULL) { + /* Not a global observer */ + dsend_packet_edit_city_build(client.conn, + player_number(client.conn.playing), + pcity-id); +} } } diff -Nur -Xdiff_ignore trunk/common/packets.def changed/common/packets.def --- trunk/common/packets.def 2008-07-11 21:46:56.0 +0200 +++ changed/common/packets.def 2008-07-13 22:32:38.0 +0200 @@ -1551,10 +1551,15 @@ UINT8 size; end +PACKET_EDIT_CITY_BUILD=168;cs,handle-per-conn,dsend + PLAYER playerno; + CITY cityID; +end + /* Always keep this as the last edit type packet, * so that the test in server/srv_main.c +1203 * is easy to write. */ -PACKET_EDIT_PLAYER_TECH=168;cs,handle-per-conn,dsend +PACKET_EDIT_PLAYER_TECH=169;cs,handle-per-conn,dsend PLAYER playerno; TECHtech; EDIT_TECH_MODE mode; diff -Nur -Xdiff_ignore trunk/server/edithand.c changed/server/edithand.c --- trunk/server/edithand.c 2008-07-05 19:56:36.0 +0200 +++ changed/server/edithand.c 2008-07-13 22:42:53.0 +0200 @@ -627,6 +627,43 @@ #endif / + Build the item currently in production of a given city immediately +/ +void handle_edit_city_build(struct connection *pc, int playerno, int cityID) +{ + if (!can_conn_edit(pc)) { +notify_conn(pc-self, NULL, E_BAD_COMMAND, +_(You are not allowed to edit.)); +return; + } + struct city *pcity = game_find_city_by_number(cityID); + struct player *pplayer = player_by_number(playerno); + if (city_production_has_flag(pcity, IF_GOLD)) { +notify_conn(pc-self, pcity-tile, E_CITY_CANTBUILD, + _(Cannot \build\ coinage in %s),
[Freeciv-Dev] (PR#40374) [Editor] build city improvements in the cityreport dialog
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40374 [EMAIL PROTECTED] - Sun Jul 13 21:31:15 2008]: This feature may have been in the editor previously but is probably commented out now, so I tried to implement it the proper way. With this patch you can let cities build items like improvements and units while in editor mode by clicking on the buy button of the general cityreport dialog (Hotkey F4 in the GTK GUI, where you get a list of all cities of one player). This will cost nothing for the player owning the city and the improvements/units will be immediately added to the given city without having to wait one turn like in the usual context of this button. This feature should work with any clients supporting the Editor mode however, it won't affect the buy button you get in the normal city dialog when double clicking on a city (either on the map or in the general cityreport). That's what I'm currently looking after to change, but it looks like this button and it's callback is implemented GUI specific, but that is just guessing of mine. Ah I now understand what you were getting at when you mentioned this patch to me before. It was my mistake really, in that I should have understood that you meant that this would be the way it works in edit mode. Actually I have opted for a different design with respect to the editing of the internal state of game entities (e.g. the city improvements in a city). Instead of adding a huge amount of heterogeneous editor-mode-checking code in the player GUI (e.g. the city dialog or city overview list) and similarly in the in-game packet handlers in the server, I want to have all the state editing code in one place, namely in the property editor code in client/gui-gtk-2.0/editprop.c (and the corresponding server-side handlers in server/edithand.c). I am actually in the process of posting a patch implementing the general framework for this right now, so you should be able to read more about it in that post (if you have subscribed to freeciv-dev mailing list at https://mail.gna.org/listinfo/freeciv-dev/). As you may have thought I'm completely new to this project and am just mostly busy trying to learn to look through the existing code and guessing how I could work with it. So any further contributions may take some time. No problem, it takes a while to get familiarized with the freeciv code base and conventions anyway. :) -- 昨日からまだ書いているほど長いですよ。 ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] (PR#40374) [Editor] build city improvements in the cityreport dialog
URL: http://bugs.freeciv.org/Ticket/Display.html?id=40374 Nicolas R. Wadhwani wrote: URL: http://bugs.freeciv.org/Ticket/Display.html?id=40374 Hi, This feature may have been in the editor previously but is probably commented out now, so I tried to implement it the proper way. With this patch you can let cities build items like improvements and units while in editor mode by clicking on the buy button of the general cityreport dialog (Hotkey F4 in the GTK GUI, where you get a list of all cities of one player). This will cost nothing for the player owning the city and the improvements/units will be immediately added to the given city without having to wait one turn like in the usual context of this button. This feature should work with any clients supporting the Editor mode however, it won't affect the buy button you get in the normal city dialog when double clicking on a city (either on the map or in the general cityreport). That's what I'm currently looking after to change, but it looks like this button and it's callback is implemented GUI specific, but that is just guessing of mine. As you may have thought I'm completely new to this project and am just mostly busy trying to learn to look through the existing code and guessing how I could work with it. So any further contributions may take some time. ;) Would it be simpler just to change the buy costs when in editor mode to 0? Then any buying action would simply grant the improvement. Other restrictions can be removed as well. Some client updates might be needed (if the buy cost is 0 the buy button should be renamed as Add; this could be useful for some modpacks potentially) but wouldn't be necessary for full functionality. -jason ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev