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
51 UPGR_COST = 15, /* how much avail and money to charge */
52 UPGR_EFF = 35 /* efficiency reduction */
55 static int lupgr(void);
56 static int pupgr(void);
57 static int supgr(void);
65 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
80 pr("Ships, land units or planes only!\n");
99 if (!snxtitem(&ni, EF_LAND, player->argp[2]))
101 ni.flags &= ~(EFF_OWNER);
102 natp = getnatp(player->cnum);
103 cash = natp->nat_money;
104 tlev = (int)natp->nat_level[NAT_TLEV];
106 while (nxtitem(&ni, (s_char *)&land)) {
107 if (land.lnd_own == 0)
109 getsect(land.lnd_x, land.lnd_y, §);
110 if (sect.sct_own != player->cnum)
112 if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
114 rel = getrel(getnatp(land.lnd_own), sect.sct_own);
115 if ((rel < FRIENDLY) && (sect.sct_own != land.lnd_own)) {
116 pr("You are not on friendly terms with the owner of unit %d!\n", land.lnd_uid);
120 lp = &lchr[(int)land.lnd_type];
121 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * UPGR_COST + 99) / 100;
122 if (sect.sct_avail < avail) {
123 pr("Not enough available work in %s to upgrade a %s\n",
124 xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name);
125 pr(" (%d available work required)\n", avail);
128 if (land.lnd_effic < 60) {
129 pr("%s is too damaged to upgrade!\n", prland(&land));
132 if (land.lnd_tech >= tlev) {
133 pr("%s tech: %d, yours is only %d\n", prland(&land),
134 land.lnd_tech, tlev);
137 cost = lp->l_cost * UPGR_COST / 100;
138 if (cost + player->dolcost > cash) {
139 pr("You don't have enough money to upgrade %s!\n",
144 sect.sct_avail -= avail;
145 land.lnd_effic -= UPGR_EFF;
147 land.lnd_tech = tlev;
148 techdiff = (int)(tlev - lp->l_tech);
151 land.lnd_mission = 0;
153 land.lnd_att = (float)LND_ATTDEF(lp->l_att, techdiff);
154 land.lnd_def = (float)LND_ATTDEF(lp->l_def, techdiff);
155 land.lnd_vul = (int)LND_VUL(lp->l_vul, techdiff);
156 land.lnd_spd = (int)LND_SPD(lp->l_spd, techdiff);
157 land.lnd_vis = (int)LND_VIS(lp->l_vis, techdiff);
158 land.lnd_spy = (int)LND_SPY(lp->l_spy, techdiff);
159 land.lnd_rad = (int)LND_RAD(lp->l_rad, techdiff);
160 land.lnd_frg = (int)LND_FRG(lp->l_frg, techdiff);
161 land.lnd_acc = (int)LND_ACC(lp->l_acc, techdiff);
162 land.lnd_dam = (int)LND_DAM(lp->l_dam, techdiff);
163 land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, techdiff);
164 land.lnd_aaf = (int)LND_AAF(lp->l_aaf, techdiff);
165 land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, techdiff);
166 land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, techdiff);
167 land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, techdiff);
168 land.lnd_maxland = (int)LND_MXL(lp->l_mxland, techdiff);
170 time(&land.lnd_access);
172 putland(land.lnd_uid, &land);
174 player->dolcost += cost;
175 pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land),
176 land.lnd_tech, cost);
177 if (land.lnd_own != player->cnum)
179 "%s upgraded by %s to tech %d, at a cost of %d\n",
180 prland(&land), cname(player->cnum), land.lnd_tech,
184 pr("No land units\n");
205 if (!snxtitem(&ni, EF_SHIP, player->argp[2]))
207 ni.flags &= ~(EFF_OWNER);
208 natp = getnatp(player->cnum);
209 cash = natp->nat_money;
210 tlev = (int)natp->nat_level[NAT_TLEV];
212 while (nxtitem(&ni, (s_char *)&ship)) {
213 if (ship.shp_own == 0)
215 getsect(ship.shp_x, ship.shp_y, §);
216 if (sect.sct_own != player->cnum)
218 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
220 rel = getrel(getnatp(ship.shp_own), sect.sct_own);
221 if ((rel < FRIENDLY) && (sect.sct_own != ship.shp_own)) {
222 pr("You are not on friendly terms with the owner of ship %d!\n", ship.shp_uid);
226 mp = &mchr[(int)ship.shp_type];
227 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100;
228 if (sect.sct_avail < avail) {
229 pr("Not enough available work in %s to upgrade a %s\n",
230 xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name);
231 pr(" (%d available work required)\n", avail);
234 if (ship.shp_effic < 60) {
235 pr("%s is too damaged to upgrade!\n", prship(&ship));
238 if (ship.shp_tech >= tlev) {
239 pr("%s tech: %d, yours is only %d\n", prship(&ship),
240 ship.shp_tech, tlev);
243 cost = mp->m_cost * UPGR_COST / 100;
244 if (cost + player->dolcost > cash) {
245 pr("You don't have enough money to upgrade %s!\n",
250 sect.sct_avail -= avail;
251 ship.shp_effic -= UPGR_EFF;
252 ship.shp_tech = tlev;
254 techdiff = (int)(tlev - mp->m_tech);
255 ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff);
256 ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff);
257 ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff);
258 ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff);
259 ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff);
261 ship.shp_mission = 0;
262 time(&ship.shp_access);
264 putship(ship.shp_uid, &ship);
266 player->dolcost += cost;
267 pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship),
268 ship.shp_tech, cost);
269 if (ship.shp_own != player->cnum)
271 "%s upgraded by %s to tech %d, at a cost of %d\n",
272 prship(&ship), cname(player->cnum), ship.shp_tech,
297 if (!snxtitem(&ni, EF_PLANE, player->argp[2]))
299 ni.flags &= ~(EFF_OWNER);
300 natp = getnatp(player->cnum);
301 cash = natp->nat_money;
302 tlev = (int)natp->nat_level[NAT_TLEV];
304 while (nxtitem(&ni, (s_char *)&plane)) {
305 if (plane.pln_own == 0)
307 getsect(plane.pln_x, plane.pln_y, §);
308 if (sect.sct_own != player->cnum)
310 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
312 rel = getrel(getnatp(plane.pln_own), sect.sct_own);
313 if ((rel < FRIENDLY) && (sect.sct_own != plane.pln_own)) {
314 pr("You are not on friendly terms with the owner of plane %d!\n", plane.pln_uid);
318 pp = &plchr[(int)plane.pln_type];
319 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100;
320 if (sect.sct_avail < avail) {
321 pr("Not enough available work in %s to upgrade a %s\n",
322 xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name);
323 pr(" (%d available work required)\n", avail);
326 if (plane.pln_effic < 60) {
327 pr("%s is too damaged to upgrade!\n", prplane(&plane));
330 if (plane.pln_tech >= tlev) {
331 pr("%s tech: %d, yours is only %d\n", prplane(&plane),
332 plane.pln_tech, tlev);
335 cost = pp->pl_cost * UPGR_COST / 100;
336 if (cost + player->dolcost > cash) {
337 pr("You don't have enough money to upgrade %s!\n",
341 if (plane.pln_flags & PLN_LAUNCHED) {
342 pr("Plane %s is in orbit!\n", prplane(&plane));
346 sect.sct_avail -= avail;
347 plane.pln_effic -= UPGR_EFF;
349 plane.pln_tech = tlev;
350 techdiff = (int)(tlev - pp->pl_tech);
352 plane.pln_mission = 0;
355 plane.pln_radius = 0;
356 plane.pln_harden = 0;
357 plane.pln_mission = 0;
359 plane.pln_att = PLN_ATTDEF(pp->pl_att, techdiff);
360 plane.pln_def = PLN_ATTDEF(pp->pl_def, techdiff);
361 plane.pln_acc = PLN_ACC(pp->pl_acc, techdiff);
362 plane.pln_range = PLN_RAN(pp->pl_range, techdiff);
363 plane.pln_range_max = plane.pln_range;
364 plane.pln_load = PLN_LOAD(pp->pl_load, techdiff);
366 time(&plane.pln_access);
368 putplane(plane.pln_uid, &plane);
370 player->dolcost += cost;
371 pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane),
372 plane.pln_tech, cost);
373 if (plane.pln_own != player->cnum)
375 "%s upgraded by %s to tech %d, at a cost of %d\n",
376 prplane(&plane), cname(player->cnum), plane.pln_tech,