2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * upgr.c: Upgrade tech of ships/planes/units
30 * Known contributors to this file:
32 * Steve McClure, 1996-2000
50 UPGR_COST = 15, /* how much avail and money to charge */
51 UPGR_EFF = 35 /* efficiency reduction */
54 static int lupgr(void);
55 static int pupgr(void);
56 static int supgr(void);
64 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
79 pr("Ships, land units or planes only!\n");
97 if (!snxtitem(&ni, EF_LAND, player->argp[2]))
99 natp = getnatp(player->cnum);
100 cash = natp->nat_money;
101 tlev = (int)natp->nat_level[NAT_TLEV];
103 while (nxtitem(&ni, &land)) {
104 if (land.lnd_own == 0)
106 getsect(land.lnd_x, land.lnd_y, §);
107 if (sect.sct_own != player->cnum)
109 if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
111 rel = getrel(getnatp(land.lnd_own), sect.sct_own);
112 if ((rel < FRIENDLY) && (sect.sct_own != land.lnd_own)) {
113 pr("You are not on friendly terms with the owner of unit %d!\n", land.lnd_uid);
117 lp = &lchr[(int)land.lnd_type];
118 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * UPGR_COST + 99) / 100;
119 if (sect.sct_avail < avail) {
120 pr("Not enough available work in %s to upgrade a %s\n",
121 xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name);
122 pr(" (%d available work required)\n", avail);
125 if (land.lnd_effic < 60) {
126 pr("%s is too damaged to upgrade!\n", prland(&land));
129 if (land.lnd_tech >= tlev) {
130 pr("%s tech: %d, yours is only %d\n", prland(&land),
131 land.lnd_tech, tlev);
134 cost = lp->l_cost * UPGR_COST / 100;
135 if (cost + player->dolcost > cash) {
136 pr("You don't have enough money to upgrade %s!\n",
141 sect.sct_avail -= avail;
142 land.lnd_effic -= UPGR_EFF;
143 lnd_set_tech(&land, tlev);
145 land.lnd_mission = 0;
146 time(&land.lnd_access);
148 putland(land.lnd_uid, &land);
150 player->dolcost += cost;
151 pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land),
152 land.lnd_tech, cost);
153 if (land.lnd_own != player->cnum)
155 "%s upgraded by %s to tech %d, at a cost of %d\n",
156 prland(&land), cname(player->cnum), land.lnd_tech,
160 pr("No land units\n");
180 if (!snxtitem(&ni, EF_SHIP, player->argp[2]))
182 natp = getnatp(player->cnum);
183 cash = natp->nat_money;
184 tlev = (int)natp->nat_level[NAT_TLEV];
186 while (nxtitem(&ni, &ship)) {
187 if (ship.shp_own == 0)
189 getsect(ship.shp_x, ship.shp_y, §);
190 if (sect.sct_own != player->cnum)
192 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
194 rel = getrel(getnatp(ship.shp_own), sect.sct_own);
195 if ((rel < FRIENDLY) && (sect.sct_own != ship.shp_own)) {
196 pr("You are not on friendly terms with the owner of ship %d!\n", ship.shp_uid);
200 mp = &mchr[(int)ship.shp_type];
201 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100;
202 if (sect.sct_avail < avail) {
203 pr("Not enough available work in %s to upgrade a %s\n",
204 xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name);
205 pr(" (%d available work required)\n", avail);
208 if (ship.shp_effic < 60) {
209 pr("%s is too damaged to upgrade!\n", prship(&ship));
212 if (ship.shp_tech >= tlev) {
213 pr("%s tech: %d, yours is only %d\n", prship(&ship),
214 ship.shp_tech, tlev);
217 cost = mp->m_cost * UPGR_COST / 100;
218 if (cost + player->dolcost > cash) {
219 pr("You don't have enough money to upgrade %s!\n",
224 sect.sct_avail -= avail;
225 ship.shp_effic -= UPGR_EFF;
226 shp_set_tech(&ship, tlev);
227 ship.shp_mission = 0;
228 time(&ship.shp_access);
230 putship(ship.shp_uid, &ship);
232 player->dolcost += cost;
233 pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship),
234 ship.shp_tech, cost);
235 if (ship.shp_own != player->cnum)
237 "%s upgraded by %s to tech %d, at a cost of %d\n",
238 prship(&ship), cname(player->cnum), ship.shp_tech,
262 if (!snxtitem(&ni, EF_PLANE, player->argp[2]))
264 natp = getnatp(player->cnum);
265 cash = natp->nat_money;
266 tlev = (int)natp->nat_level[NAT_TLEV];
268 while (nxtitem(&ni, &plane)) {
269 if (plane.pln_own == 0)
271 getsect(plane.pln_x, plane.pln_y, §);
272 if (sect.sct_own != player->cnum)
274 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
276 rel = getrel(getnatp(plane.pln_own), sect.sct_own);
277 if ((rel < FRIENDLY) && (sect.sct_own != plane.pln_own)) {
278 pr("You are not on friendly terms with the owner of plane %d!\n", plane.pln_uid);
282 pp = &plchr[(int)plane.pln_type];
283 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100;
284 if (sect.sct_avail < avail) {
285 pr("Not enough available work in %s to upgrade a %s\n",
286 xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name);
287 pr(" (%d available work required)\n", avail);
290 if (plane.pln_effic < 60) {
291 pr("%s is too damaged to upgrade!\n", prplane(&plane));
294 if (plane.pln_tech >= tlev) {
295 pr("%s tech: %d, yours is only %d\n", prplane(&plane),
296 plane.pln_tech, tlev);
299 cost = pp->pl_cost * UPGR_COST / 100;
300 if (cost + player->dolcost > cash) {
301 pr("You don't have enough money to upgrade %s!\n",
305 if (plane.pln_flags & PLN_LAUNCHED) {
306 pr("Plane %s is in orbit!\n", prplane(&plane));
310 sect.sct_avail -= avail;
311 plane.pln_effic -= UPGR_EFF;
312 pln_set_tech(&plane, tlev);
313 plane.pln_harden = 0;
314 plane.pln_mission = 0;
315 time(&plane.pln_access);
317 putplane(plane.pln_uid, &plane);
319 player->dolcost += cost;
320 pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane),
321 plane.pln_tech, cost);
322 if (plane.pln_own != player->cnum)
324 "%s upgraded by %s to tech %d, at a cost of %d\n",
325 prplane(&plane), cname(player->cnum), plane.pln_tech,