2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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
54 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
67 pr("Ships, land units or planes only!\n");
89 if (!snxtitem(&ni, EF_LAND, player->argp[2]))
91 ni.flags &= ~(EFF_OWNER);
92 natp = getnatp(player->cnum);
93 cash = natp->nat_money;
94 tlev = (int) natp->nat_level[NAT_TLEV];
96 while (nxtitem(&ni, (s_char *) &land)) {
97 if (land.lnd_own == 0)
99 getsect(land.lnd_x, land.lnd_y, §);
100 if (sect.sct_own != player->cnum)
102 if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
104 rel=getrel(getnatp(land.lnd_own),sect.sct_own);
105 if ((rel < FRIENDLY) && (sect.sct_own != land.lnd_own)){
106 pr("You are not on friendly terms with the owner of unit %d!\n",
111 lp = &lchr[(int)land.lnd_type];
112 w_p_eff = ((lp->l_lcm / 2) + lp->l_hcm);
113 points = sect.sct_avail * 100 / w_p_eff;
115 pr("Not enough available work in %s to upgrade a %s\n",
116 xyas(sect.sct_x, sect.sct_y, player->cnum),
118 pr(" (%d available work required)\n",
119 1 + (w_p_eff * 20)/100);
122 if (land.lnd_effic < 60) {
123 pr("%s is too damaged to upgrade!\n", prland(&land));
126 if (land.lnd_tech >= tlev) {
127 pr("%s tech: %d, yours is only %d\n", prland(&land),
128 land.lnd_tech, tlev);
131 if (lp->l_cost * .15 + player->dolcost > cash) {
132 pr("You don't have enough money to upgrade %s!\n",
137 sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100;
138 land.lnd_effic -= 35;
140 land.lnd_tech = tlev;
141 techdiff = (int)(tlev - lp->l_tech);
144 land.lnd_mission = 0;
146 land.lnd_att = (float)LND_ATTDEF(lp->l_att, techdiff);
147 land.lnd_def = (float)LND_ATTDEF(lp->l_def, techdiff);
148 land.lnd_vul = (int)LND_VUL(lp->l_vul, techdiff);
149 land.lnd_spd = (int)LND_SPD(lp->l_spd, techdiff);
150 land.lnd_vis = (int)LND_VIS(lp->l_vis, techdiff);
151 land.lnd_spy = (int)LND_SPY(lp->l_spy, techdiff);
152 land.lnd_rad = (int)LND_RAD(lp->l_rad, techdiff);
153 land.lnd_frg = (int)LND_FRG(lp->l_frg, techdiff);
154 land.lnd_acc = (int)LND_ACC(lp->l_acc, techdiff);
155 land.lnd_dam = (int)LND_DAM(lp->l_dam, techdiff);
156 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, techdiff);
157 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, techdiff);
158 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, techdiff);
159 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, techdiff);
160 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, techdiff);
161 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, techdiff);
163 time(&land.lnd_access);
165 putland(land.lnd_uid, &land);
167 player->dolcost += (double) lp->l_cost * .15;
168 pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land),
170 (int)(lp->l_cost * .15));
171 if (land.lnd_own != player->cnum)
172 wu(0,land.lnd_own,"%s upgraded by %s to tech %d, at a cost of %d\n", prland(&land),
174 land.lnd_tech, (int)(lp->l_cost * .15));
177 pr("No land units\n");
199 if (!snxtitem(&ni, EF_SHIP, player->argp[2]))
201 ni.flags &= ~(EFF_OWNER);
202 natp = getnatp(player->cnum);
203 cash = natp->nat_money;
204 tlev = (int) natp->nat_level[NAT_TLEV];
206 while (nxtitem(&ni, (s_char *) &ship)) {
207 if (ship.shp_own == 0)
209 getsect(ship.shp_x, ship.shp_y, §);
210 if (sect.sct_own != player->cnum)
212 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
214 rel=getrel(getnatp(ship.shp_own),sect.sct_own);
215 if ((rel < FRIENDLY) && (sect.sct_own != ship.shp_own)){
216 pr("You are not on friendly terms with the owner of ship %d!\n",
221 mp = &mchr[(int)ship.shp_type];
222 w_p_eff = ((mp->m_lcm / 2) + mp->m_hcm);
223 points = sect.sct_avail * 100 / w_p_eff;
225 pr("Not enough available work in %s to upgrade a %s\n",
226 xyas(sect.sct_x, sect.sct_y, player->cnum),
228 pr(" (%d available work required)\n",
229 1 + (w_p_eff * 20)/100);
232 if (ship.shp_effic < 60) {
233 pr("%s is too damaged to upgrade!\n", prship(&ship));
236 if (ship.shp_tech >= tlev) {
237 pr("%s tech: %d, yours is only %d\n", prship(&ship),
238 ship.shp_tech, tlev);
241 if (mp->m_cost * .15 + player->dolcost > cash) {
242 pr("You don't have enough money to upgrade %s!\n",
247 sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100;
248 ship.shp_effic -= 35;
249 ship.shp_tech = tlev;
251 techdiff = (int)(tlev - mp->m_tech);
252 ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
253 ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
254 ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
255 ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
256 ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
258 ship.shp_mission = 0;
259 time(&ship.shp_access);
261 putship(ship.shp_uid, &ship);
263 player->dolcost += (double) mp->m_cost * .15;
264 pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship),
266 (int)(mp->m_cost * .15));
267 if (ship.shp_own != player->cnum)
268 wu(0,ship.shp_own,"%s upgraded by %s to tech %d, at a cost of %d\n", prship(&ship),
270 ship.shp_tech, (int)(mp->m_cost * .15));
295 if (!snxtitem(&ni, EF_PLANE, player->argp[2]))
297 ni.flags &= ~(EFF_OWNER);
298 natp = getnatp(player->cnum);
299 cash = natp->nat_money;
300 tlev = (int) natp->nat_level[NAT_TLEV];
302 while (nxtitem(&ni, (s_char *) &plane)) {
303 if (plane.pln_own == 0)
305 getsect(plane.pln_x, plane.pln_y, §);
306 if (sect.sct_own != player->cnum)
308 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
310 rel=getrel(getnatp(plane.pln_own),sect.sct_own);
311 if ((rel < FRIENDLY) && (sect.sct_own != plane.pln_own)){
312 pr("You are not on friendly terms with the owner of plane %d!\n",
317 pp = &plchr[(int)plane.pln_type];
318 w_p_eff = ((pp->pl_lcm / 2) + pp->pl_hcm);
319 points = sect.sct_avail * 100 / w_p_eff;
321 pr("Not enough available work in %s to upgrade a %s\n",
322 xyas(sect.sct_x, sect.sct_y, player->cnum),
324 pr(" (%d available work required)\n",
325 1 + (w_p_eff * 20)/100);
328 if (plane.pln_effic < 60) {
329 pr("%s is too damaged to upgrade!\n", prplane(&plane));
332 if (plane.pln_tech >= tlev) {
333 pr("%s tech: %d, yours is only %d\n", prplane(&plane),
334 plane.pln_tech, tlev);
337 if (pp->pl_cost * .15 + player->dolcost > cash) {
338 pr("You don't have enough money to upgrade %s!\n",
342 if (plane.pln_flags & PLN_LAUNCHED) {
343 pr("Plane %s is in orbit!\n", prplane(&plane));
347 sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100;
348 plane.pln_effic -= 35;
350 plane.pln_tech = tlev;
351 techdiff = (int)(tlev - pp->pl_tech);
353 plane.pln_mission = 0;
356 plane.pln_radius = 0;
357 plane.pln_harden = 0;
358 plane.pln_mission = 0;
360 plane.pln_att = PLN_ATTDEF(pp->pl_att, techdiff);
361 plane.pln_def = PLN_ATTDEF(pp->pl_def, techdiff);
362 plane.pln_acc = PLN_ACC(pp->pl_acc, techdiff);
363 plane.pln_range = PLN_RAN(pp->pl_range, techdiff);
364 plane.pln_range_max = plane.pln_range;
365 plane.pln_load = PLN_LOAD(pp->pl_load, techdiff);
367 time(&plane.pln_access);
369 putplane(plane.pln_uid, &plane);
371 player->dolcost += (double) pp->pl_cost * .15;
372 pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane),
374 (int)(pp->pl_cost * .15));
375 if (plane.pln_own != player->cnum)
376 wu(0,plane.pln_own,"%s upgraded by %s to tech %d, at a cost of %d\n", prplane(&plane),
378 plane.pln_tech, (int)(pp->pl_cost * .15));