edit: Fix tech and range adjustment for edit p key 'T'

It sets the new type, then falls through to setting tech if the new
type requires more than the plane currently has.  Two problems with
that:

* If we fall through, the plane is invalid: it has less tech than
  required.  Its only use before it gets overwritten is pln_set_tech()
  calling pln_range_max() to find out whether the range is limited.
  Passes a negative number to log().  Not fatal, but pln_set_tech()'s
  range adjustment is unlikely to work.

* If we don't fall through, the range may still need adjustment,
  either up (to keep it unlimited if the new type has more range), or
  down (to keep it within the new type's shorter range).

Screwed up when the key was added in commit 6b0b6f17.  Fix by
adjusting tech first, then setting the type, then adjusting the range.
The latter relies on pln_set_tech() coping with ranges exceeding the
type's maximum, which it does.

Change the other type edits similarly for consistency.

When a type edit triggers a tech change, the tech change is now
silent.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2015-01-06 15:22:01 +01:00
parent efec4417d3
commit 0a012a3ed5
4 changed files with 23 additions and 35 deletions

View file

@ -31,7 +31,7 @@
* Chad Zabel, 1994 * Chad Zabel, 1994
* Steve McClure, 1998-2000 * Steve McClure, 1998-2000
* Ron Koenderink, 2003-2009 * Ron Koenderink, 2003-2009
* Markus Armbruster, 2003-2014 * Markus Armbruster, 2003-2015
*/ */
#include <config.h> #include <config.h>
@ -905,12 +905,12 @@ edit_ship(struct shpstr *ship, char *key, char *p)
divine_unit_change((struct empobj *)ship, "Type", divine_unit_change((struct empobj *)ship, "Type",
arg != ship->shp_type, 0, arg != ship->shp_type, 0,
"to %s", mchr[arg].m_name); "to %s", mchr[arg].m_name);
if (ship->shp_tech < mchr[arg].m_tech)
shp_set_tech(ship, mchr[arg].m_tech);
ship->shp_type = arg; ship->shp_type = arg;
shp_set_tech(ship, ship->shp_tech);
limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item); limit_item((struct empobj *)ship, ship->shp_item, mchr[arg].m_item);
if (ship->shp_tech >= mchr[arg].m_tech) break;
break;
arg = mchr[arg].m_tech;
/* fall through */
case 'T': case 'T':
arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX); arg = LIMIT_TO(arg, mcp->m_tech, SHRT_MAX);
divine_unit_change((struct empobj *)ship, "Tech level", divine_unit_change((struct empobj *)ship, "Tech level",
@ -992,12 +992,12 @@ edit_land(struct lndstr *land, char *key, char *p)
divine_unit_change((struct empobj *)land, "Type", divine_unit_change((struct empobj *)land, "Type",
arg != land->lnd_type, 0, arg != land->lnd_type, 0,
"to %s", lchr[arg].l_name); "to %s", lchr[arg].l_name);
if (land->lnd_tech < lchr[arg].l_tech)
lnd_set_tech(land, lchr[arg].l_tech);
land->lnd_type = arg; land->lnd_type = arg;
lnd_set_tech(land, land->lnd_tech);
limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item); limit_item((struct empobj *)land, land->lnd_item, lchr[arg].l_item);
if (land->lnd_tech >= lchr[arg].l_tech) break;
break;
arg = lchr[arg].l_tech;
/* fall through */
case 't': case 't':
arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX); arg = LIMIT_TO(arg, lcp->l_tech, SHRT_MAX);
divine_unit_change((struct empobj *)land, "Tech level", divine_unit_change((struct empobj *)land, "Tech level",
@ -1109,11 +1109,14 @@ edit_plane(struct plnstr *plane, char *key, char *p)
divine_unit_change((struct empobj *)plane, "Type", divine_unit_change((struct empobj *)plane, "Type",
arg != plane->pln_type, 0, arg != plane->pln_type, 0,
"to %s", plchr[arg].pl_name); "to %s", plchr[arg].pl_name);
if (plane->pln_tech < plchr[arg].pl_tech)
pln_set_tech(plane, plchr[arg].pl_tech);
if (plane->pln_range >= pln_range_max(plane))
/* preserve unlimited range, pln_set_tech() will adjust */
plane->pln_range = UCHAR_MAX;
plane->pln_type = arg; plane->pln_type = arg;
if (plane->pln_tech >= plchr[arg].pl_tech) pln_set_tech(plane, plane->pln_tech);
break; break;
arg = plchr[arg].pl_tech;
/* fall through */
case 't': case 't':
arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX); arg = LIMIT_TO(arg, pcp->pl_tech, SHRT_MAX);
divine_unit_change((struct empobj *)plane, "Tech level", divine_unit_change((struct empobj *)plane, "Tech level",
@ -1192,11 +1195,10 @@ edit_nuke(struct nukstr *nuke, char *key, char *p)
divine_unit_change((struct empobj *)nuke, "Type", divine_unit_change((struct empobj *)nuke, "Type",
arg != nuke->nuk_type, 0, arg != nuke->nuk_type, 0,
"to %s", nchr[arg].n_name); "to %s", nchr[arg].n_name);
if (nuke->nuk_tech < nchr[arg].n_tech)
nuke->nuk_tech = nchr[arg].n_tech;
nuke->nuk_type = arg; nuke->nuk_type = arg;
if (nuke->nuk_tech >= nchr[arg].n_tech) break;
break;
arg = nchr[arg].n_tech;
/* fall through */
case 'T': case 'T':
arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX); arg = LIMIT_TO(arg, ncp->n_tech, SHRT_MAX);
divine_unit_change((struct empobj *)nuke, "Tech level", divine_unit_change((struct empobj *)nuke, "Tech level",

View file

@ -187,8 +187,8 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius wing range
4 3 3 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 4 () 0 0.00000 4 3 3 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 4 () 0 0.00000
5 3 1 -1 0 100 127 0 32767 1 -1 air\040defense 4 "" 18 0 -1 -1 () 0 0.00000 5 3 1 -1 0 100 127 0 32767 1 -1 air\040defense 4 "" 18 0 -1 -1 () 0 0.00000
6 1 0 0 9 10 0 0 90 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 6 1 0 0 9 10 0 0 90 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
7 0 0 0 9 0 0 0 90 0 0 none 0 "" 4 0 -1 -1 () 0 0.00000 7 0 0 0 9 0 0 0 90 0 0 none 0 "" 17 0 -1 -1 () 0 0.00000
8 0 0 0 0 0 0 0 90 0 0 none 0 "" 15 0 -1 -1 () 0 0.00000 8 0 0 0 0 0 0 0 90 0 0 none 0 "" 9 0 -1 -1 () 0 0.00000
49 0 0 0 0 0 0 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 49 0 0 0 0 0 0 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
/config /config
config land config land
@ -218,7 +218,7 @@ actor action victim times duration time
0 44 1 32 0 0 0 44 1 32 0 0
0 43 2 6 0 0 0 43 2 6 0 0
0 44 3 28 0 0 0 44 3 28 0 0
0 43 1 81 0 0 0 43 1 77 0 0
0 42 1 6 0 0 0 42 1 6 0 0
1 45 0 3 0 0 1 45 0 3 0 0
0 43 3 38 0 0 0 43 3 38 0 0

View file

@ -1041,12 +1041,10 @@
Play#0 input edit s 6 t lc O 1 t lc t hc g 8 t lc Play#0 input edit s 6 t lc O 1 t lc t hc g 8 t lc
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Type of fb fishing boat (#6) changed to lc light cruiser Play#0 output Play#0 1 Type of fb fishing boat (#6) changed to lc light cruiser
Play#0 output Play#0 1 Tech level of lc light cruiser (#6) changed from 0 to 45
Play#0 output Play#0 1 Owner of lc light cruiser (#6) changed from POGO (#0) to 1 (#1) Play#0 output Play#0 1 Owner of lc light cruiser (#6) changed from POGO (#0) to 1 (#1)
Play#0 output Play#0 1 Efficiency of lc light cruiser (#6) changed from 0 to 20 Play#0 output Play#0 1 Efficiency of lc light cruiser (#6) changed from 0 to 20
Play#0 output Play#0 1 Type of lc light cruiser (#6) unchanged Play#0 output Play#0 1 Type of lc light cruiser (#6) unchanged
Play#0 output Play#0 1 Type of lc light cruiser (#6) changed to hc heavy cruiser Play#0 output Play#0 1 Type of lc light cruiser (#6) changed to hc heavy cruiser
Play#0 output Play#0 1 Tech level of hc heavy cruiser (#6) changed from 45 to 50
Play#0 output Play#0 1 guns of hc heavy cruiser (#6) changed from 0 to 8 Play#0 output Play#0 1 guns of hc heavy cruiser (#6) changed from 0 to 8
Play#0 output Play#0 1 Type of hc heavy cruiser (#6) changed to lc light cruiser Play#0 output Play#0 1 Type of hc heavy cruiser (#6) changed to lc light cruiser
Play#0 output Play#0 1 guns of lc light cruiser (#6) changed from 8 to 5 Play#0 output Play#0 1 guns of lc light cruiser (#6) changed from 8 to 5
@ -1150,25 +1148,21 @@
Play#0 input edit p 6 T mb O 1 T mb T hb T mb Play#0 input edit p 6 T mb O 1 T mb T hb T mb
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Type of f1 Sopwith Camel #6 changed to mb medium bomber Play#0 output Play#0 1 Type of f1 Sopwith Camel #6 changed to mb medium bomber
Play#0 output Play#0 1 Tech level of mb medium bomber #6 changed from 0 to 80
Play#0 output Play#0 1 Owner of mb medium bomber #6 changed from POGO (#0) to 1 (#1) Play#0 output Play#0 1 Owner of mb medium bomber #6 changed from POGO (#0) to 1 (#1)
Play#0 output Play#0 1 Efficiency of mb medium bomber #6 changed from 0 to 10 Play#0 output Play#0 1 Efficiency of mb medium bomber #6 changed from 0 to 10
Play#0 output Play#0 1 Type of mb medium bomber #6 unchanged Play#0 output Play#0 1 Type of mb medium bomber #6 unchanged
Play#0 output Play#0 1 Type of mb medium bomber #6 changed to hb B-26B Marauder Play#0 output Play#0 1 Type of mb medium bomber #6 changed to hb B-26B Marauder
Play#0 output Play#0 1 Tech level of hb B-26B Marauder #6 changed from 80 to 90
Play#0 output Play#0 1 Type of hb B-26B Marauder #6 changed to mb medium bomber Play#0 output Play#0 1 Type of hb B-26B Marauder #6 changed to mb medium bomber
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit p 7 r 255 T hb T mb Play#0 input edit p 7 r 255 T hb T mb
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Range of f1 Sopwith Camel #7 changed from 0 to 4 Play#0 output Play#0 1 Range of f1 Sopwith Camel #7 changed from 0 to 4
Play#0 output Play#0 1 Type of f1 Sopwith Camel #7 changed to hb B-26B Marauder Play#0 output Play#0 1 Type of f1 Sopwith Camel #7 changed to hb B-26B Marauder
Play#0 output Play#0 1 Tech level of hb B-26B Marauder #7 changed from 0 to 90
Play#0 output Play#0 1 Type of hb B-26B Marauder #7 changed to mb medium bomber Play#0 output Play#0 1 Type of hb B-26B Marauder #7 changed to mb medium bomber
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit p 8 T hb r 255 T f1 Play#0 input edit p 8 T hb r 255 T f1
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Type of f1 Sopwith Camel #8 changed to hb B-26B Marauder Play#0 output Play#0 1 Type of f1 Sopwith Camel #8 changed to hb B-26B Marauder
Play#0 output Play#0 1 Tech level of hb B-26B Marauder #8 changed from 0 to 90
Play#0 output Play#0 1 Range of hb B-26B Marauder #8 changed from 0 to 15 Play#0 output Play#0 1 Range of hb B-26B Marauder #8 changed from 0 to 15
Play#0 output Play#0 1 Type of hb B-26B Marauder #8 changed to f1 Sopwith Camel Play#0 output Play#0 1 Type of hb B-26B Marauder #8 changed to f1 Sopwith Camel
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
@ -1239,12 +1233,10 @@
Play#0 input edit u 6 T art O 1 T art T hat g 12 T art Play#0 input edit u 6 T art O 1 T art T hat g 12 T art
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Type of cav cavalry #6 changed to art artillery Play#0 output Play#0 1 Type of cav cavalry #6 changed to art artillery
Play#0 output Play#0 1 Tech level of art artillery #6 changed from 0 to 35
Play#0 output Play#0 1 Owner of art artillery #6 changed from POGO (#0) to 1 (#1) Play#0 output Play#0 1 Owner of art artillery #6 changed from POGO (#0) to 1 (#1)
Play#0 output Play#0 1 Efficiency of art artillery #6 changed from 0 to 10 Play#0 output Play#0 1 Efficiency of art artillery #6 changed from 0 to 10
Play#0 output Play#0 1 Type of art artillery #6 unchanged Play#0 output Play#0 1 Type of art artillery #6 unchanged
Play#0 output Play#0 1 Type of art artillery #6 changed to hat hvy artillery Play#0 output Play#0 1 Type of art artillery #6 changed to hat hvy artillery
Play#0 output Play#0 1 Tech level of hat hvy artillery #6 changed from 35 to 100
Play#0 output Play#0 1 guns of hat hvy artillery #6 changed from 0 to 12 Play#0 output Play#0 1 guns of hat hvy artillery #6 changed from 0 to 12
Play#0 output Play#0 1 Type of hat hvy artillery #6 changed to art artillery Play#0 output Play#0 1 Type of hat hvy artillery #6 changed to art artillery
Play#0 output Play#0 1 guns of art artillery #6 changed from 12 to 10 Play#0 output Play#0 1 guns of art artillery #6 changed from 12 to 10
@ -1348,12 +1340,10 @@
Play#0 input edit n 6 t 15kt O 1 t 15kt t 50kt t 15kt Play#0 input edit n 6 t 15kt O 1 t 15kt t 50kt t 15kt
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Type of 10kt fission warhead #6 changed to 15kt fission Play#0 output Play#0 1 Type of 10kt fission warhead #6 changed to 15kt fission
Play#0 output Play#0 1 Tech level of 15kt fission warhead #6 changed from 0 to 290
Play#0 output Play#0 1 Owner of 15kt fission warhead #6 changed from POGO (#0) to 1 (#1) Play#0 output Play#0 1 Owner of 15kt fission warhead #6 changed from POGO (#0) to 1 (#1)
Play#0 output Play#0 1 Efficiency of 15kt fission warhead #6 changed from 0 to 100 Play#0 output Play#0 1 Efficiency of 15kt fission warhead #6 changed from 0 to 100
Play#0 output Play#0 1 Type of 15kt fission warhead #6 unchanged Play#0 output Play#0 1 Type of 15kt fission warhead #6 unchanged
Play#0 output Play#0 1 Type of 15kt fission warhead #6 changed to 50kt fission Play#0 output Play#0 1 Type of 15kt fission warhead #6 changed to 50kt fission
Play#0 output Play#0 1 Tech level of 50kt fission warhead #6 changed from 290 to 300
Play#0 output Play#0 1 Type of 50kt fission warhead #6 changed to 15kt fission Play#0 output Play#0 1 Type of 50kt fission warhead #6 changed to 15kt fission
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit n 2 T 280 Play#0 input edit n 2 T 280
@ -1896,23 +1886,19 @@
Play#0 output Play#0 1 POGO stole 1 civilians from 8,6 Play#0 output Play#0 1 POGO stole 1 civilians from 8,6
Play#0 output Play#0 1 lc light cruiser (#6) given to you by an act of POGO! Play#0 output Play#0 1 lc light cruiser (#6) given to you by an act of POGO!
Play#0 output Play#0 1 Type of lc light cruiser (#6) changed to hc heavy cruiser by an act of POGO Play#0 output Play#0 1 Type of lc light cruiser (#6) changed to hc heavy cruiser by an act of POGO
Play#0 output Play#0 1 Tech level of hc heavy cruiser (#6) changed from 45 to 50 by an act of POGO
Play#0 output Play#0 1 POGO gave you 8 guns in hc heavy cruiser (#6) Play#0 output Play#0 1 POGO gave you 8 guns in hc heavy cruiser (#6)
Play#0 output Play#0 1 Type of hc heavy cruiser (#6) changed to lc light cruiser by an act of POGO Play#0 output Play#0 1 Type of hc heavy cruiser (#6) changed to lc light cruiser by an act of POGO
Play#0 output Play#0 1 POGO stole 3 guns from lc light cruiser (#6) Play#0 output Play#0 1 POGO stole 3 guns from lc light cruiser (#6)
Play#0 output Play#0 1 mb medium bomber #6 given to you by an act of POGO! Play#0 output Play#0 1 mb medium bomber #6 given to you by an act of POGO!
Play#0 output Play#0 1 Type of mb medium bomber #6 changed to hb B-26B Marauder by an act of POGO Play#0 output Play#0 1 Type of mb medium bomber #6 changed to hb B-26B Marauder by an act of POGO
Play#0 output Play#0 1 Tech level of hb B-26B Marauder #6 changed from 80 to 90 by an act of POGO
Play#0 output Play#0 1 Type of hb B-26B Marauder #6 changed to mb medium bomber by an act of POGO Play#0 output Play#0 1 Type of hb B-26B Marauder #6 changed to mb medium bomber by an act of POGO
Play#0 output Play#0 1 art artillery #6 given to you by an act of POGO! Play#0 output Play#0 1 art artillery #6 given to you by an act of POGO!
Play#0 output Play#0 1 Type of art artillery #6 changed to hat hvy artillery by an act of POGO Play#0 output Play#0 1 Type of art artillery #6 changed to hat hvy artillery by an act of POGO
Play#0 output Play#0 1 Tech level of hat hvy artillery #6 changed from 35 to 100 by an act of POGO
Play#0 output Play#0 1 POGO gave you 12 guns in hat hvy artillery #6 Play#0 output Play#0 1 POGO gave you 12 guns in hat hvy artillery #6
Play#0 output Play#0 1 Type of hat hvy artillery #6 changed to art artillery by an act of POGO Play#0 output Play#0 1 Type of hat hvy artillery #6 changed to art artillery by an act of POGO
Play#0 output Play#0 1 POGO stole 2 guns from art artillery #6 Play#0 output Play#0 1 POGO stole 2 guns from art artillery #6
Play#0 output Play#0 1 15kt fission warhead #6 given to you by an act of POGO! Play#0 output Play#0 1 15kt fission warhead #6 given to you by an act of POGO!
Play#0 output Play#0 1 Type of 15kt fission warhead #6 changed to 50kt fission by an act of POGO Play#0 output Play#0 1 Type of 15kt fission warhead #6 changed to 50kt fission by an act of POGO
Play#0 output Play#0 1 Tech level of 50kt fission warhead #6 changed from 290 to 300 by an act of POGO
Play#0 output Play#0 1 Type of 50kt fission warhead #6 changed to 15kt fission by an act of POGO Play#0 output Play#0 1 Type of 50kt fission warhead #6 changed to 15kt fission by an act of POGO
Play#0 output Play#0 1 Money changed from 0 to -2147483648 by an act of POGO! Play#0 output Play#0 1 Money changed from 0 to -2147483648 by an act of POGO!
Play#0 output Play#0 1 Technology changed from 0.00 to 3.14 by an act of POGO! Play#0 output Play#0 1 Technology changed from 0.00 to 3.14 by an act of POGO!

View file

@ -208,7 +208,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius wing range
27 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 27 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
28 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 28 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
29 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 29 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
30 1 -2 2 17 100 19 0 400 0 0 none 0 "" 7 0 -1 -1 () 0 0.00000 30 1 -2 2 17 100 19 0 400 0 0 none 0 "" 18 0 -1 -1 () 0 0.00000
31 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 31 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
32 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 32 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000
33 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 33 0 0 0 0 0 127 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000