From 2936e07f41c80b8b6c51d4e51b81e1a4887a43a5 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 29 Dec 2013 10:37:11 +0100 Subject: [PATCH] edit: Make unit owner change away from POGO work Units owned by POGO are not in use. Giving a unit to POGO destroys it. The opposite doesn't work, however: the unit prewrite hooks give it right back to POGO, because efficiency is below the minimum. Make it work by also increasing efficiency to minimum. Note that you can't use this to create a unit that doesn't already exist in the respective file. That's because edit's second argument selects from existing objects only. Signed-off-by: Markus Armbruster --- src/lib/commands/edit.c | 5 +++++ tests/actofgod/actofgod.xdump | 5 +++-- tests/actofgod/geninput.pl | 1 + tests/actofgod/journal.log | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 894cd2c9..e13cf1c8 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -759,6 +759,11 @@ edit_unit(struct empobj *unit, char *key, char *p, report_god_takes("", unit_nameof(unit), unit->own); report_god_gives("", unit_nameof(unit), arg); } + if (arg && unit->effic < mineff) { + divine_unit_change_quiet(unit, "Efficiency", 1, + "from %d to %d", unit->effic, mineff); + unit->effic = mineff; + } unit->own = arg; break; case 'L': diff --git a/tests/actofgod/actofgod.xdump b/tests/actofgod/actofgod.xdump index 24d8d48d..b808384c 100644 --- a/tests/actofgod/actofgod.xdump +++ b/tests/actofgod/actofgod.xdump @@ -366,11 +366,11 @@ actor action victim times duration time 0 44 3 1 0 0 0 44 1 32 0 0 0 43 2 5 0 0 -0 44 3 19 0 0 +0 44 3 22 0 0 0 43 1 73 0 0 0 42 1 4 0 0 1 45 0 1 0 0 -0 43 3 30 0 0 +0 43 3 33 0 0 0 44 2 6 0 0 0 42 3 4 0 0 0 43 4 2 0 0 @@ -505,6 +505,7 @@ timestamp owner type id x y 0 3 3 0 1 -1 0 3 3 1 1 -1 0 3 3 2 1 -1 +0 0 3 4 1 -1 /config config realm cnum realm xl xh yl yh diff --git a/tests/actofgod/geninput.pl b/tests/actofgod/geninput.pl index 2620c0fb..56bb4bd3 100755 --- a/tests/actofgod/geninput.pl +++ b/tests/actofgod/geninput.pl @@ -238,6 +238,7 @@ for my $ef ('ship', 'plane', 'land') { edit($ef, 1, 'O', $MAXNOC - 1); edit($ef, 1, 'O', $MAXNOC); edit($ef, 2, 'O', 2); + edit($ef, 4, 'O', 0, 'O', '3'); # uid (copy) edit($ef, 3, 'U', 5, 'U', 3); edit($ef, 0, 'U', 0, 'U', -1); diff --git a/tests/actofgod/journal.log b/tests/actofgod/journal.log index 43a6a93a..a36565ee 100644 --- a/tests/actofgod/journal.log +++ b/tests/actofgod/journal.log @@ -860,6 +860,12 @@ Play#0 command edit Play#0 output Play#0 1 Owner of cs cargo ship (#2) changed from 3 (#3) to 2 (#2) Play#0 output Play#0 6 0 640 + Play#0 input edit s 4 O 0 O 3 + Play#0 command edit + Play#0 output Play#0 1 Owner of cs cargo ship (#4) changed from 3 (#3) to POGO (#0) + Play#0 output Play#0 1 Owner of cs cargo ship (#4) changed from POGO (#0) to 3 (#3) + Play#0 output Play#0 1 Efficiency of cs cargo ship (#4) changed from 0 to 20 + Play#0 output Play#0 6 0 640 Play#0 input edit s 3 U 5 U 3 Play#0 command edit Play#0 output Play#0 1 cs cargo ship (#3) duplicated to (#5) @@ -904,6 +910,12 @@ Play#0 command edit Play#0 output Play#0 1 Owner of f1 Sopwith Camel #2 changed from 3 (#3) to 2 (#2) Play#0 output Play#0 6 0 640 + Play#0 input edit p 4 O 0 O 3 + Play#0 command edit + Play#0 output Play#0 1 Owner of f1 Sopwith Camel #4 changed from 3 (#3) to POGO (#0) + Play#0 output Play#0 1 Owner of f1 Sopwith Camel #4 changed from POGO (#0) to 3 (#3) + Play#0 output Play#0 1 Efficiency of f1 Sopwith Camel #4 changed from 0 to 10 + Play#0 output Play#0 6 0 640 Play#0 input edit p 3 U 5 U 3 Play#0 command edit Play#0 output Play#0 1 f1 Sopwith Camel #3 duplicated to (#5) @@ -948,6 +960,12 @@ Play#0 command edit Play#0 output Play#0 1 Owner of sup supply #2 changed from 3 (#3) to 2 (#2) Play#0 output Play#0 6 0 640 + Play#0 input edit u 4 O 0 O 3 + Play#0 command edit + Play#0 output Play#0 1 Owner of sup supply #4 changed from 3 (#3) to POGO (#0) + Play#0 output Play#0 1 Owner of sup supply #4 changed from POGO (#0) to 3 (#3) + Play#0 output Play#0 1 Efficiency of sup supply #4 changed from 0 to 10 + Play#0 output Play#0 6 0 640 Play#0 input edit u 3 U 5 U 3 Play#0 command edit Play#0 output Play#0 1 sup supply #3 duplicated to (#5) @@ -1767,6 +1785,8 @@ Play#0 output Play#0 1 cs cargo ship (#0) taken from you by an act of POGO! Play#0 output Play#0 1 cs cargo ship (#1) taken from you by an act of POGO! Play#0 output Play#0 1 cs cargo ship (#2) taken from you by an act of POGO! + Play#0 output Play#0 1 cs cargo ship (#4) taken from you by an act of POGO! + Play#0 output Play#0 1 cs cargo ship (#4) given to you by an act of POGO! Play#0 output Play#0 1 cs cargo ship (#5) given to you by an act of POGO! Play#0 output Play#0 1 cs cargo ship (#3) taken from you by an act of POGO! Play#0 output Play#0 1 cs cargo ship (#3) given to you by an act of POGO! @@ -1774,6 +1794,8 @@ Play#0 output Play#0 1 f1 Sopwith Camel #0 taken from you by an act of POGO! Play#0 output Play#0 1 f1 Sopwith Camel #1 taken from you by an act of POGO! Play#0 output Play#0 1 f1 Sopwith Camel #2 taken from you by an act of POGO! + Play#0 output Play#0 1 f1 Sopwith Camel #4 taken from you by an act of POGO! + Play#0 output Play#0 1 f1 Sopwith Camel #4 given to you by an act of POGO! Play#0 output Play#0 1 f1 Sopwith Camel #5 given to you by an act of POGO! Play#0 output Play#0 1 f1 Sopwith Camel #3 taken from you by an act of POGO! Play#0 output Play#0 1 f1 Sopwith Camel #3 given to you by an act of POGO! @@ -1781,6 +1803,8 @@ Play#0 output Play#0 1 sup supply #0 taken from you by an act of POGO! Play#0 output Play#0 1 sup supply #1 taken from you by an act of POGO! Play#0 output Play#0 1 sup supply #2 taken from you by an act of POGO! + Play#0 output Play#0 1 sup supply #4 taken from you by an act of POGO! + Play#0 output Play#0 1 sup supply #4 given to you by an act of POGO! Play#0 output Play#0 1 sup supply #5 given to you by an act of POGO! Play#0 output Play#0 1 sup supply #3 taken from you by an act of POGO! Play#0 output Play#0 1 sup supply #3 given to you by an act of POGO!