Project

General

Profile

Bug #853935

Unit built by disbanding city doesn't emit "unit_built" Lua signal

Added by Jacob Nevins 7 months ago. Updated 6 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Scripting API
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Noticed in passing:

In the special case where city_build_unit() disbands the city (calls disband_city()), I think the "unit_built" signal is not emitted.

m-unit-build-script.patch (11 KB) m-unit-build-script.patch Jacob Nevins, 2019-12-27 03:53 PM
30-unit-build-script.patch (9.35 KB) 30-unit-build-script.patch Jacob Nevins, 2019-12-27 03:53 PM
26-unit-build-script.patch (9.77 KB) 26-unit-build-script.patch Jacob Nevins, 2019-12-27 03:53 PM

History

#1 Updated by Jacob Nevins 7 months ago

Predictably, this turned out to be a can of worms. I've fixed various other script-related issues, and also issues with rally points on master only. Master branch commit message:

Script / rally point fixes at unit build time
  • A unit whose creation disbanded its city now emits the "unit_built" signal, and honours city's rally point.
  • Fix trouble in city_build_stuff() if script "unit_built" or "unit_cant_be_built" handlers destroyed city.
  • Fix trouble in city_build_unit() for pop_cost units if script "city_size_change" handler destroyed city.
  • Fix trouble in rally point code if "unit_built" or "city_size_change" destroyed city.

The precise sequence of events around unit building has changed slightly.

Here's how the sequence of events has changed:

Before patch After patch
Non-disband case create unit
[city_reduce_size() => emit signal "city_size_change"]
charge shield cost
"Paris is finished building Warriors"
["Warriors cost 1 population"]
emit signal "unit_built"
create unit
emit signal "unit_built"
"Paris is finished building Warriors" (unless unit died)
[city_reduce_size() => emit signal "city_size_change"]
charge shield cost
["Warriors cost 1 population"]
City disband case create unit
rehome city units
"Paris is disbanded into Warriors"
emit signal "city_destroyed"
remove city
create unit
emit signal "unit_built"
[if city still exists:]
rehome city units
"Paris is disbanded into Warriors"
emit signal "city_destroyed"
remove city

I've tested the rally point fix and general unit building, but not the scripting fixes, beyond checking for no regressions in the tutorial scenario (which uses "unit_built").

#2 Updated by Jacob Nevins 6 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF