Skip to content

Commit 6fbed01

Browse files
XHawk87jwrober
authored andcommitted
#2307 Moved city looting to default.lua
1 parent 73117ba commit 6fbed01

File tree

4 files changed

+58
-58
lines changed

4 files changed

+58
-58
lines changed

data/default/default.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,37 @@ function _deflua_harmless_disaster_message(disaster, city, had_internal_effect)
227227
end
228228

229229
signal.connect("disaster_occurred", "_deflua_harmless_disaster_message")
230+
231+
function _deflua_city_conquer_gold_loot(city, looterunit)
232+
local treasury = city.owner:gold()
233+
local loot = math.min(
234+
treasury,
235+
math.floor(random(0, (treasury / 20) + 1)) +
236+
math.floor((treasury * city.size) / 200)
237+
)
238+
if loot <= 0 then
239+
return false
240+
end
241+
looterunit.owner:change_gold(loot)
242+
city.owner:change_gold(-loot)
243+
notify.event(looterunit.owner, city.tile, E.UNIT_WIN_ATT,
244+
string.format(
245+
PL_("Your lootings from %s accumulate to %d gold!",
246+
"Your lootings from %s accumulate to %d gold!",
247+
loot),
248+
city:link_text(), loot
249+
)
250+
)
251+
notify.event(city.owner, city.tile, E.CITY_LOST,
252+
string.format(
253+
PL_("%s looted %d gold from %s.",
254+
"%s looted %d gold from %s.",
255+
loot),
256+
looterunit.owner.name, loot, city:link_text()
257+
)
258+
)
259+
return true
260+
end
261+
262+
signal.connect("city_loot", "_deflua_city_conquer_gold_loot")
263+

server/citytools.cpp

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ void remove_city(struct city *pcity)
19691969
bool unit_conquer_city(struct unit *punit, struct city *pcity)
19701970
{
19711971
bool try_civil_war = false;
1972-
bool city_remains;
1972+
int pcity_id = pcity->id;
19731973
struct player *pplayer = unit_owner(punit);
19741974
struct player *cplayer = city_owner(pcity);
19751975

@@ -2013,8 +2013,6 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity)
20132013
* the city will be destroyed.
20142014
*/
20152015
if (city_size_get(pcity) <= 1) {
2016-
int saved_id = pcity->id;
2017-
20182016
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
20192017
_("You destroy %s completely."), city_tile_link(pcity));
20202018
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
@@ -2023,7 +2021,7 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity)
20232021
script_server_signal_emit("city_destroyed", pcity, cplayer, pplayer);
20242022

20252023
// We cant't be sure of city existence after running some script
2026-
if (city_exist(saved_id)) {
2024+
if (city_exist(pcity_id)) {
20272025
remove_city(pcity);
20282026
}
20292027

@@ -2033,62 +2031,25 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity)
20332031
return true;
20342032
}
20352033

2036-
auto coins = cplayer->economic.gold;
2037-
coins = MIN(coins, int(fc_rand((coins / 20) + 1))
2038-
+ (coins * (city_size_get(pcity))) / 200);
2039-
pplayer->economic.gold += coins;
2040-
cplayer->economic.gold -= coins;
2041-
send_player_info_c(pplayer, pplayer->connections);
2042-
send_player_info_c(cplayer, cplayer->connections);
20432034
if (pcity->original != pplayer) {
2044-
if (coins > 0) {
2045-
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2046-
PL_("You conquer %s; your lootings accumulate"
2047-
" to %d gold!",
2048-
"You conquer %s; your lootings accumulate"
2049-
" to %d gold!",
2050-
coins),
2051-
city_link(pcity), coins);
2052-
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2053-
PL_("%s conquered %s and looted %d gold"
2054-
" from the city.",
2055-
"%s conquered %s and looted %d gold"
2056-
" from the city.",
2057-
coins),
2058-
player_name(pplayer), city_link(pcity), coins);
2059-
} else {
2060-
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2061-
_("You conquer %s."), city_link(pcity));
2062-
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2063-
_("%s conquered %s."), player_name(pplayer),
2064-
city_link(pcity));
2065-
}
2035+
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2036+
_("You conquer %s."), city_link(pcity));
2037+
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2038+
_("%s conquered %s."), player_name(pplayer),
2039+
city_link(pcity));
20662040
} else {
2067-
if (coins > 0) {
2068-
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2069-
PL_("You have liberated %s!"
2070-
" Lootings accumulate to %d gold.",
2071-
"You have liberated %s!"
2072-
" Lootings accumulate to %d gold.",
2073-
coins),
2074-
city_link(pcity), coins);
2075-
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2076-
PL_("%s liberated %s and looted %d gold"
2077-
" from the city.",
2078-
"%s liberated %s and looted %d gold"
2079-
" from the city.",
2080-
coins),
2081-
player_name(pplayer), city_link(pcity), coins);
2082-
} else {
2083-
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2084-
_("You have liberated %s!"), city_link(pcity));
2085-
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2086-
_("%s liberated %s."), player_name(pplayer),
2087-
city_link(pcity));
2088-
}
2041+
notify_player(pplayer, city_tile(pcity), E_UNIT_WIN_ATT, ftc_server,
2042+
_("You have liberated %s!"), city_link(pcity));
2043+
notify_player(cplayer, city_tile(pcity), E_CITY_LOST, ftc_server,
2044+
_("%s liberated %s."), player_name(pplayer),
2045+
city_link(pcity));
20892046
}
20902047

2091-
if (fc_rand(100) < get_unit_bonus(punit, EFT_CONQUEST_TECH_PCT)) {
2048+
int conquestTechPct = get_unit_bonus(punit, EFT_CONQUEST_TECH_PCT);
2049+
script_server_signal_emit("city_loot", pcity, punit);
2050+
bool city_remains = city_exist(pcity_id);
2051+
2052+
if (fc_rand(100) < conquestTechPct) {
20922053
// Just try to steal. Ignore failures to get tech
20932054
steal_a_tech(pplayer, cplayer, A_UNSET);
20942055
}
@@ -2097,8 +2058,9 @@ bool unit_conquer_city(struct unit *punit, struct city *pcity)
20972058
* the size is reduced. */
20982059
/* FIXME: maybe it should be a ruleset option whether barbarians get
20992060
* free buildings such as palaces? */
2100-
city_remains = transfer_city(pplayer, pcity, 0, true, true, true,
2101-
!is_barbarian(pplayer));
2061+
city_remains = city_remains
2062+
&& transfer_city(pplayer, pcity, 0, true, true, true,
2063+
!is_barbarian(pplayer));
21022064

21032065
if (city_remains) {
21042066
// reduce size should not destroy this city

server/scripting/api_server_edit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ void api_edit_change_gold(lua_State *L, Player *pplayer, int amount)
349349
LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player);
350350

351351
pplayer->economic.gold = MAX(0, pplayer->economic.gold + amount);
352+
353+
send_player_info_c(pplayer, pplayer->connections);
352354
}
353355

354356
/**

server/scripting/script_server.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,8 @@ static void script_server_signals_create()
451451
// First player is city owner, second is enemy.
452452
luascript_signal_create(fcl_main, "city_destroyed", 3, API_TYPE_CITY,
453453
API_TYPE_PLAYER, API_TYPE_PLAYER);
454+
luascript_signal_create(fcl_main, "city_loot", 2, API_TYPE_CITY,
455+
API_TYPE_UNIT);
454456

455457
// First player is former owner, second new one.
456458
luascript_signal_create(fcl_main, "city_transferred", 4, API_TYPE_CITY,

0 commit comments

Comments
 (0)