2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * upgr.c: Upgrade tech of ships/planes/units
29 * Known contributors to this file:
31 * Steve McClure, 1996-2000
32 * Markus Armbruster, 2004-2016
43 UPGR_COST = 15, /* how much avail and money to charge */
44 UPGR_EFF = 35 /* efficiency reduction */
47 static int lupgr(void);
48 static int pupgr(void);
49 static int supgr(void);
57 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
72 pr("Ships, land units or planes only!\n");
89 if (!snxtitem(&ni, EF_LAND, player->argp[2], NULL))
91 natp = getnatp(player->cnum);
92 cash = natp->nat_money;
93 tlev = (int)natp->nat_level[NAT_TLEV];
95 while (nxtitem(&ni, &land)) {
96 if (land.lnd_own == 0)
98 getsect(land.lnd_x, land.lnd_y, §);
99 if (sect.sct_own != player->cnum)
101 if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
103 if (relations_with(land.lnd_own, sect.sct_own) < FRIENDLY) {
104 pr("You are not on friendly terms with the owner of unit %d!\n",
109 lp = &lchr[(int)land.lnd_type];
110 avail = (lp->l_bwork * UPGR_COST + 99) / 100;
111 if (sect.sct_avail < avail) {
112 pr("Not enough available work in %s to upgrade a %s\n",
113 xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name);
114 pr(" (%d available work required)\n", avail);
117 if (land.lnd_effic < 60) {
118 pr("%s is too damaged to upgrade!\n", prland(&land));
121 if (land.lnd_tech >= tlev) {
122 pr("%s tech: %d, yours is only %d\n",
123 prland(&land), land.lnd_tech, tlev);
126 cost = lp->l_cost * UPGR_COST / 100;
127 if (cost + player->dolcost > cash) {
128 pr("You don't have enough money to upgrade %s!\n",
133 sect.sct_avail -= avail;
134 land.lnd_effic -= UPGR_EFF;
135 lnd_set_tech(&land, tlev);
137 land.lnd_mission = 0;
139 putland(land.lnd_uid, &land);
141 player->dolcost += cost;
142 pr("%s upgraded to tech %d, at a cost of %d\n",
143 prland(&land), land.lnd_tech, cost);
144 if (land.lnd_own != player->cnum)
146 "%s upgraded by %s to tech %d, at a cost of %d\n",
147 prland(&land), cname(player->cnum), land.lnd_tech, cost);
150 pr("No land units\n");
169 if (!snxtitem(&ni, EF_SHIP, player->argp[2], NULL))
171 natp = getnatp(player->cnum);
172 cash = natp->nat_money;
173 tlev = (int)natp->nat_level[NAT_TLEV];
175 while (nxtitem(&ni, &ship)) {
176 if (ship.shp_own == 0)
178 getsect(ship.shp_x, ship.shp_y, §);
179 if (sect.sct_own != player->cnum)
181 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
183 if (relations_with(ship.shp_own, sect.sct_own) < FRIENDLY) {
184 pr("You are not on friendly terms with the owner of ship %d!\n",
189 mp = &mchr[(int)ship.shp_type];
190 avail = (mp->m_bwork * UPGR_COST + 99) / 100;
191 if (sect.sct_avail < avail) {
192 pr("Not enough available work in %s to upgrade a %s\n",
193 xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name);
194 pr(" (%d available work required)\n", avail);
197 if (ship.shp_effic < 60) {
198 pr("%s is too damaged to upgrade!\n", prship(&ship));
201 if (ship.shp_tech >= tlev) {
202 pr("%s tech: %d, yours is only %d\n",
203 prship(&ship), ship.shp_tech, tlev);
206 cost = mp->m_cost * UPGR_COST / 100;
207 if (cost + player->dolcost > cash) {
208 pr("You don't have enough money to upgrade %s!\n",
213 sect.sct_avail -= avail;
214 ship.shp_effic -= UPGR_EFF;
215 shp_set_tech(&ship, tlev);
216 ship.shp_mission = 0;
218 putship(ship.shp_uid, &ship);
220 player->dolcost += cost;
221 pr("%s upgraded to tech %d, at a cost of %d\n",
222 prship(&ship), ship.shp_tech, cost);
223 if (ship.shp_own != player->cnum)
225 "%s upgraded by %s to tech %d, at a cost of %d\n",
226 prship(&ship), cname(player->cnum), ship.shp_tech, cost);
248 if (!snxtitem(&ni, EF_PLANE, player->argp[2], NULL))
250 natp = getnatp(player->cnum);
251 cash = natp->nat_money;
252 tlev = (int)natp->nat_level[NAT_TLEV];
254 while (nxtitem(&ni, &plane)) {
255 if (plane.pln_own == 0)
257 getsect(plane.pln_x, plane.pln_y, §);
258 if (sect.sct_own != player->cnum)
260 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
262 if (relations_with(plane.pln_own, sect.sct_own) < FRIENDLY) {
263 pr("You are not on friendly terms with the owner of plane %d!\n",
267 if (pln_is_in_orbit(&plane)) {
268 pr("Plane %s is in orbit!\n", prplane(&plane));
271 if (plane.pln_flags & PLN_LAUNCHED)
274 pp = &plchr[(int)plane.pln_type];
275 avail = (pp->pl_bwork * UPGR_COST + 99) / 100;
276 if (sect.sct_avail < avail) {
277 pr("Not enough available work in %s to upgrade a %s\n",
278 xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name);
279 pr(" (%d available work required)\n", avail);
282 if (plane.pln_effic < 60) {
283 pr("%s is too damaged to upgrade!\n", prplane(&plane));
286 if (plane.pln_tech >= tlev) {
287 pr("%s tech: %d, yours is only %d\n",
288 prplane(&plane), plane.pln_tech, tlev);
291 cost = pp->pl_cost * UPGR_COST / 100;
292 if (cost + player->dolcost > cash) {
293 pr("You don't have enough money to upgrade %s!\n",
298 sect.sct_avail -= avail;
299 plane.pln_effic -= UPGR_EFF;
300 pln_set_tech(&plane, tlev);
301 plane.pln_harden = 0;
302 plane.pln_mission = 0;
304 putplane(plane.pln_uid, &plane);
306 player->dolcost += cost;
307 pr("%s upgraded to tech %d, at a cost of %d\n",
308 prplane(&plane), plane.pln_tech, cost);
309 if (plane.pln_own != player->cnum)
311 "%s upgraded by %s to tech %d, at a cost of %d\n",
312 prplane(&plane), cname(player->cnum), plane.pln_tech, cost);