From 16e565ed5f4dcde567e4fa3d8d95b7c7f2df46ee Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 27 Aug 2017 13:28:20 +0200 Subject: [PATCH] edit: Implement editing bars on ships and land units The edit command doesn't support editing bars on ships and land units. Has always been that way. The stock game's ships have always been unable to load bars. Not the case for land units. Unfortunately, the obvious key 'b' for bars was burned on plague time in 4.0.17. Use key 'B' instead. Signed-off-by: Markus Armbruster --- src/lib/commands/edit.c | 28 +++++++++++++++++++++------- tests/actofgod/final.xdump | 4 ++-- tests/actofgod/geninput.pl | 2 +- tests/actofgod/journal.log | 27 ++++++++++++++++++--------- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 33da32cb..78124648 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -267,9 +267,9 @@ print_plane(struct plnstr *plane) static void print_items(short item[]) { - pr(" civ mil uw food sh gun pet iron dust oil lcm hcm rad\n" - " c m u f s g p i d o l h r\n" - "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d\n", + pr(" civ mil uw food sh gun pet iron dust bar oil lcm hcm rad\n" + " c m u f s g p i d B o l h r\n" + "%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d%5d\n", item[I_CIVIL], item[I_MILIT], item[I_UW], @@ -279,6 +279,7 @@ print_items(short item[]) item[I_PETROL], item[I_IRON], item[I_DUST], + item[I_BAR], item[I_OIL], item[I_LCM], item[I_HCM], @@ -849,6 +850,17 @@ edit_item(struct empobj *unit, short item[], struct ichrstr *ip, int arg, item[ip->i_uid] = arg; } +static void +edit_unit_item(struct empobj *unit, short item[], char *key, int arg, + short lim[]) +{ + char lowkey[2]; + + lowkey[0] = tolower(*key); + lowkey[1] = 0; + edit_item(unit, item, item_by_name(lowkey), arg, lim); +} + static void limit_item(struct empobj *unit, short item[], short lim[]) { @@ -934,12 +946,13 @@ edit_ship(struct shpstr *ship, char *key, char *p) case 'p': case 'i': case 'd': + case 'B': case 'o': case 'l': case 'h': case 'r': - edit_item((struct empobj *)ship, ship->shp_item, item_by_name(key), - arg, mcp->m_item); + edit_unit_item((struct empobj *)ship, ship->shp_item, key, arg, + mcp->m_item); break; default: pr("huh? (%s)\n", key); @@ -1065,12 +1078,13 @@ edit_land(struct lndstr *land, char *key, char *p) case 'p': case 'i': case 'd': + case 'B': case 'o': case 'l': case 'h': case 'r': - edit_item((struct empobj *)land, land->lnd_item, item_by_name(key), - arg, lcp->l_item); + edit_unit_item((struct empobj *)land, land->lnd_item, key, arg, + lcp->l_item); break; default: pr("huh? (%s)\n", key); diff --git a/tests/actofgod/final.xdump b/tests/actofgod/final.xdump index 198c9af1..bef7475e 100644 --- a/tests/actofgod/final.xdump +++ b/tests/actofgod/final.xdump @@ -195,7 +195,7 @@ config land uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship harden retreat rflags rpath civil milit shell gun petrol iron dust bar food oil lcm hcm uw rad pstage ptime land access 0 0 1 -1 6 0 2 0 100 0 0 none 0 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 1 98 1 -1 6 10 0 0 100 0 0 none 0 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -2 2 3 -1 6 10 -127 0 50 0 0 none 0 "" -1 0 0 (group) "" 0 1 1 1 1 1 1 0 1 0 1 1 0 0 healthy 0 -1 0 +2 2 3 -1 6 10 -127 0 50 0 0 none 0 "" -1 0 0 (group) "" 0 1 1 1 1 1 1 1 1 0 1 1 0 0 healthy 0 -1 0 3 3 1 -1 6 10 -127 0 50 0 0 none 0 "a" 3 0 0 (injured) "jj" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 4 3 3 -1 6 100 127 0 32767 0 0 none 0 "" 2 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 5 3 1 -1 6 100 127 0 32767 0 0 none 0 "" -1 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 @@ -224,7 +224,7 @@ actor action victim times duration time 0 43 3 38 0 0 0 44 2 7 0 0 0 42 3 4 0 0 -0 42 2 17 0 0 +0 42 2 18 0 0 0 43 4 2 0 0 0 44 1 1 0 0 0 43 2 4 0 0 diff --git a/tests/actofgod/geninput.pl b/tests/actofgod/geninput.pl index 7f822358..0a18cf19 100755 --- a/tests/actofgod/geninput.pl +++ b/tests/actofgod/geninput.pl @@ -309,7 +309,7 @@ for my $ef ('ship', 'land') { # items for my $ef ('ship', 'land') { - for my $key (split(//, 'cmsgpidfolhur')) { + for my $key (split(//, 'cmsgpidBfolhur')) { edit($ef, 2, $key, 1); } } diff --git a/tests/actofgod/journal.log b/tests/actofgod/journal.log index 32175423..531bc62e 100644 --- a/tests/actofgod/journal.log +++ b/tests/actofgod/journal.log @@ -1508,6 +1508,10 @@ Play#0 command edit Play#0 output Play#0 1 dust (gold) of cs cargo ship (#2) unchanged Play#0 output Play#0 6 0 640 + Play#0 input edit s 2 B 1 + Play#0 command edit + Play#0 output Play#0 1 bars of gold of cs cargo ship (#2) unchanged + Play#0 output Play#0 6 0 640 Play#0 input edit s 2 f 1 Play#0 command edit Play#0 output Play#0 1 food of cs cargo ship (#2) changed from 0 to 1 @@ -1560,6 +1564,10 @@ Play#0 command edit Play#0 output Play#0 1 dust (gold) of sup supply #2 changed from 0 to 1 Play#0 output Play#0 6 0 640 + Play#0 input edit u 2 B 1 + Play#0 command edit + Play#0 output Play#0 1 bars of gold of sup supply #2 changed from 0 to 1 + Play#0 output Play#0 6 0 640 Play#0 input edit u 2 f 1 Play#0 command edit Play#0 output Play#0 1 food of sup supply #2 changed from 0 to 1 @@ -1647,9 +1655,9 @@ Play#0 output Play#0 1 Mobility : 0 Fleet : Play#0 output Play#0 1 Retreat path : '' Retreat Flags : 0 Play#0 output Play#0 1 Plague Stage : 0 Plague Time : 0 - Play#0 output Play#0 1 civ mil uw food sh gun pet iron dust oil lcm hcm rad - Play#0 output Play#0 1 c m u f s g p i d o l h r - Play#0 output Play#0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + Play#0 output Play#0 1 civ mil uw food sh gun pet iron dust bar oil lcm hcm rad + Play#0 output Play#0 1 c m u f s g p i d B o l h r + Play#0 output Play#0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Play#0 output Play#0 4 %c xxxxx -- thing value : Play#0 input M 2 Play#0 output Play#0 1 Mobility of cs cargo ship (#0) changed from 0 to 2 @@ -1671,9 +1679,9 @@ Play#0 output Play#0 1 Mobility : 2 Fleet : Play#0 output Play#0 1 Retreat path : '' Retreat Flags : 0 Play#0 output Play#0 1 Plague Stage : 0 Plague Time : 0 - Play#0 output Play#0 1 civ mil uw food sh gun pet iron dust oil lcm hcm rad - Play#0 output Play#0 1 c m u f s g p i d o l h r - Play#0 output Play#0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 + Play#0 output Play#0 1 civ mil uw food sh gun pet iron dust bar oil lcm hcm rad + Play#0 output Play#0 1 c m u f s g p i d B o l h r + Play#0 output Play#0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 Play#0 output Play#0 4 %c xxxxx -- thing value : Play#0 input R n Play#0 output Play#0 1 Retreat path of cs cargo ship (#0) changed from to n @@ -1712,9 +1720,9 @@ Play#0 output Play#0 1 Fortification : 0 Land unit : -1 Play#0 output Play#0 1 Ship : -1 Retreat percentage : 42 Play#0 output Play#0 1 Retreat path : '' Retreat Flags : 0 - Play#0 output Play#0 1 civ mil uw food sh gun pet iron dust oil lcm hcm rad - Play#0 output Play#0 1 c m u f s g p i d o l h r - Play#0 output Play#0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 + Play#0 output Play#0 1 civ mil uw food sh gun pet iron dust bar oil lcm hcm rad + Play#0 output Play#0 1 c m u f s g p i d B o l h r + Play#0 output Play#0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Play#0 output Play#0 4 %c xxxxx -- thing value : Play#0 input M 2 Play#0 output Play#0 1 Mobility of sup supply #0 changed from 0 to 2 @@ -2120,6 +2128,7 @@ Play#0 output Play#0 1 POGO gave you 1 petrol in sup supply #2 Play#0 output Play#0 1 POGO gave you 1 iron ore in sup supply #2 Play#0 output Play#0 1 POGO gave you 1 dust (gold) in sup supply #2 + Play#0 output Play#0 1 POGO gave you 1 bars of gold in sup supply #2 Play#0 output Play#0 1 POGO gave you 1 food in sup supply #2 Play#0 output Play#0 1 POGO gave you 1 light products in sup supply #2 Play#0 output Play#0 1 POGO gave you 1 heavy products in sup supply #2