Author: cazfi
Date: Mon Dec 28 21:56:49 2015
New Revision: 31248
URL: http://svn.gna.org/viewcvs/freeciv?rev=31248&view=rev
Log:
Deprecated "city_growth" lua signal and added "city_size_change" as an
replacement for it.
Requested by Alexander Fretheim <ahfretheim>
See bug #24115
Modified:
branches/S2_6/server/citytools.c
branches/S2_6/server/cityturn.c
branches/S2_6/server/cityturn.h
branches/S2_6/server/diplomats.c
branches/S2_6/server/edithand.c
branches/S2_6/server/scripting/script_server.c
branches/S2_6/server/unithand.c
branches/S2_6/server/unittools.c
Modified: branches/S2_6/server/citytools.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/citytools.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/citytools.c (original)
+++ branches/S2_6/server/citytools.c Mon Dec 28 21:56:49 2015
@@ -1949,7 +1949,7 @@
if (city_remains) {
/* reduce size should not destroy this city */
fc_assert(city_size_get(pcity) > 1);
- city_reduce_size(pcity, 1, pplayer);
+ city_reduce_size(pcity, 1, pplayer, "conquest");
}
if (try_civil_war) {
Modified: branches/S2_6/server/cityturn.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/cityturn.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/cityturn.c (original)
+++ branches/S2_6/server/cityturn.c Mon Dec 28 21:56:49 2015
@@ -675,13 +675,20 @@
loss.
**************************************************************************/
bool city_reduce_size(struct city *pcity, citizens pop_loss,
- struct player *destroyer)
+ struct player *destroyer, const char *reason)
{
citizens loss_remain;
int old_radius_sq;
if (pop_loss == 0) {
return TRUE;
+ }
+
+ if (reason != NULL) {
+ script_server_signal_emit("city_size_change", 3,
+ API_TYPE_CITY, pcity,
+ API_TYPE_INT, -pop_loss,
+ API_TYPE_STRING, reason);
}
if (city_size_get(pcity) <= pop_loss) {
@@ -880,6 +887,10 @@
notify_player(powner, city_tile(pcity), E_CITY_GROWTH, ftc_server,
_("%s grows to size %d."),
city_link(pcity), city_size_get(pcity));
+ script_server_signal_emit("city_size_change", 3,
+ API_TYPE_CITY, pcity,
+ API_TYPE_INT, 1,
+ API_TYPE_STRING, "growth");
script_server_signal_emit("city_growth", 2,
API_TYPE_CITY, pcity,
API_TYPE_INT, city_size_get(pcity));
@@ -896,21 +907,30 @@
Change the city size. Return TRUE iff the city is still alive afterwards.
****************************************************************************/
bool city_change_size(struct city *pcity, citizens size,
- struct player *nationality)
-{
+ struct player *nationality, const char *reason)
+{
+ int change = size - city_size_get(pcity);
+
fc_assert_ret_val(size >= 0 && size <= MAX_CITY_SIZE, TRUE);
- if (size > city_size_get(pcity)) {
+ if (change != 0 && reason != NULL) {
+ script_server_signal_emit("city_size_change", 3,
+ API_TYPE_CITY, pcity,
+ API_TYPE_INT, size - city_size_get(pcity),
+ API_TYPE_STRING, reason);
+ }
+
+ if (change > 0) {
/* Increase city size until size reached, or increase fails */
while (size > city_size_get(pcity)
&& city_increase_size(pcity, nationality)) {
/* city_increase_size() does all the work. */
}
- } else if (size < city_size_get(pcity)) {
+ } else if (change < 0) {
/* We assume that city_change_size() is never called because
* of enemy actions. If that changes, enemy must be passed
* to city_reduce_size() */
- return city_reduce_size(pcity, city_size_get(pcity) - size, NULL);
+ return city_reduce_size(pcity, -change, NULL, NULL);
}
map_claim_border(pcity->tile, pcity->owner, -1);
@@ -939,6 +959,10 @@
} else {
city_increase_size(pcity, nationality);
map_claim_border(pcity->tile, pcity->owner, -1);
+ script_server_signal_emit("city_size_change", 3,
+ API_TYPE_CITY, pcity,
+ API_TYPE_INT, 1,
+ API_TYPE_STRING, "growth");
}
} else if (pcity->food_stock < 0) {
/* FIXME: should this depend on units with ability to build
@@ -977,7 +1001,7 @@
city_link(pcity));
}
city_reset_foodbox(pcity, city_size_get(pcity) - 1);
- city_reduce_size(pcity, 1, NULL);
+ city_reduce_size(pcity, 1, NULL, "famine");
}
}
@@ -2019,7 +2043,7 @@
_("Citizens in %s perish for their failure to "
"upkeep %s!"),
city_link(pcity), unit_link(punit));
- if (!city_reduce_size(pcity, 1, NULL)) {
+ if (!city_reduce_size(pcity, 1, NULL, "upkeep_failure")) {
return FALSE;
}
@@ -2264,7 +2288,7 @@
* rearrange the worker to take into account the extra resources
* (food) needed. */
if (pop_cost > 0) {
- city_reduce_size(pcity, pop_cost, NULL);
+ city_reduce_size(pcity, pop_cost, NULL, "unit_built");
}
/* to eliminate micromanagement, we only subtract the unit's cost */
@@ -2883,7 +2907,7 @@
notify_player(pplayer, city_tile(pcity), E_CITY_PLAGUE, ftc_server,
_("%s has been struck by a plague! Population lost!"),
city_link(pcity));
- city_reduce_size(pcity, 1, NULL);
+ city_reduce_size(pcity, 1, NULL, "plague");
pcity->turn_plague = game.info.turn;
/* recalculate illness */
@@ -3301,6 +3325,10 @@
-1, TRUE);
sz_strlcpy(name_from, city_tile_link(pcity_from));
+ script_server_signal_emit("city_size_change", 3,
+ API_TYPE_CITY, pcity_from,
+ API_TYPE_INT, -1,
+ API_TYPE_STRING, "migration_from");
script_server_signal_emit("city_destroyed", 3,
API_TYPE_CITY, pcity_from,
API_TYPE_PLAYER, pcity_from->owner,
@@ -3334,7 +3362,7 @@
/* This should be followed by city_reduce_size(). */
citizens_nation_add(pcity_from, pplayer_citizen->slot, -1);
}
- city_reduce_size(pcity_from, 1, pplayer_from);
+ city_reduce_size(pcity_from, 1, pplayer_from, "migration_from");
city_refresh_vision(pcity_from);
if (city_refresh(pcity_from)) {
auto_arrange_workers(pcity_from);
@@ -3369,6 +3397,10 @@
if (city_refresh(pcity_to)) {
auto_arrange_workers(pcity_to);
}
+ script_server_signal_emit("city_size_change", 3,
+ API_TYPE_CITY, pcity_to,
+ API_TYPE_INT, 1,
+ API_TYPE_STRING, "migration_to");
log_debug("[M] T%d migration successful (%s -> %s)",
game.info.turn, name_from, name_to);
@@ -3453,7 +3485,7 @@
if (disaster_has_effect(pdis, DE_REDUCE_DESTROY)
|| (disaster_has_effect(pdis, DE_REDUCE_POP)
&& pcity->size > 1)) {
- if (!city_reduce_size(pcity, 1, NULL)) {
+ if (!city_reduce_size(pcity, 1, NULL, "disaster")) {
notify_player(pplayer, ptile, E_DISASTER, ftc_server,
/* TRANS: "Industrial Accident destroys Bogota entirely" */
_("%s destroys %s entirely."),
Modified: branches/S2_6/server/cityturn.h
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/cityturn.h?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/cityturn.h (original)
+++ branches/S2_6/server/cityturn.h Mon Dec 28 21:56:49 2015
@@ -31,9 +31,9 @@
void apply_cmresult_to_city(struct city *pcity, const struct cm_result *cmr);
bool city_change_size(struct city *pcity, citizens new_size,
- struct player *nationality);
+ struct player *nationality, const char *reason);
bool city_reduce_size(struct city *pcity, citizens pop_loss,
- struct player *destroyer);
+ struct player *destroyer, const char *reason);
void city_repair_size(struct city *pcity, int change);
void send_city_turn_notifications(struct connection *pconn);
Modified: branches/S2_6/server/diplomats.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/diplomats.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/diplomats.c (original)
+++ branches/S2_6/server/diplomats.c Mon Dec 28 21:56:49 2015
@@ -111,7 +111,7 @@
log_debug("poison: succeeded");
/* Poison people! */
- if (city_reduce_size(pcity, 1, pplayer)) {
+ if (city_reduce_size(pcity, 1, pplayer, "poison")) {
/* Notify everybody involved. */
notify_player(pplayer, ctile, E_MY_DIPLOMAT_POISON, ftc_server,
_("Your %s poisoned the water supply of %s."),
@@ -784,7 +784,7 @@
/* City loses some population. */
if (city_size_get(pcity) > 1) {
- city_reduce_size(pcity, 1, pplayer);
+ city_reduce_size(pcity, 1, pplayer, "incited");
}
/* This costs! */
Modified: branches/S2_6/server/edithand.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/edithand.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/edithand.c (original)
+++ branches/S2_6/server/edithand.c Mon Dec 28 21:56:49 2015
@@ -881,7 +881,7 @@
if (size > 1) {
/* FIXME: Slow and inefficient for large size changes. */
- city_change_size(pcity, CLIP(1, size, MAX_CITY_SIZE), pplayer);
+ city_change_size(pcity, CLIP(1, size, MAX_CITY_SIZE), pplayer, NULL);
send_city_info(NULL, pcity);
}
@@ -939,7 +939,7 @@
packet->size, city_link(pcity));
} else {
/* FIXME: Slow and inefficient for large size changes. */
- city_change_size(pcity, packet->size, NULL);
+ city_change_size(pcity, packet->size, NULL, NULL);
changed = TRUE;
}
}
Modified: branches/S2_6/server/scripting/script_server.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/scripting/script_server.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/scripting/script_server.c (original)
+++ branches/S2_6/server/scripting/script_server.c Mon Dec 28 21:56:49 2015
@@ -353,6 +353,10 @@
luascript_signal_create(fcl_main, "city_built", 1,
API_TYPE_CITY);
+ luascript_signal_create(fcl_main, "city_size_change", 3,
+ API_TYPE_CITY, API_TYPE_INT, API_TYPE_STRING);
+
+ /* Deprecated form of the 'city_size_change' signal for the case of growth.
*/
luascript_signal_create(fcl_main, "city_growth", 2,
API_TYPE_CITY, API_TYPE_INT);
Modified: branches/S2_6/server/unithand.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unithand.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/unithand.c (original)
+++ branches/S2_6/server/unithand.c Mon Dec 28 21:56:49 2015
@@ -1639,7 +1639,7 @@
fc_assert_ret(pcity != NULL);
- city_change_size(pcity, size, nationality);
+ city_change_size(pcity, size, nationality, NULL);
}
wipe_unit(punit, ULR_USED, NULL);
}
@@ -1921,7 +1921,7 @@
&& city_size_get(pcity) > 1
&& get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0
&& kills_citizen_after_attack(punit)) {
- city_reduce_size(pcity, 1, pplayer);
+ city_reduce_size(pcity, 1, pplayer, "bombard");
city_refresh(pcity);
send_city_info(NULL, pcity);
}
@@ -2036,7 +2036,7 @@
&& city_size_get(pcity) > 1
&& get_city_bonus(pcity, EFT_UNIT_NO_LOSE_POP) <= 0
&& kills_citizen_after_attack(punit)) {
- city_reduce_size(pcity, 1, pplayer);
+ city_reduce_size(pcity, 1, pplayer, "attack");
city_refresh(pcity);
send_city_info(NULL, pcity);
}
Modified: branches/S2_6/server/unittools.c
URL:
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/unittools.c?rev=31248&r1=31247&r2=31248&view=diff
==============================================================================
--- branches/S2_6/server/unittools.c (original)
+++ branches/S2_6/server/unittools.c Mon Dec 28 21:56:49 2015
@@ -2498,7 +2498,7 @@
city_link(pcity));
}
- city_reduce_size(pcity, city_size_get(pcity) / 2, pplayer);
+ city_reduce_size(pcity, city_size_get(pcity) / 2, pplayer, "nuke");
}
if (fc_rand(2) == 1) {
_______________________________________________
Freeciv-commits mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-commits