2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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
48 UPGR_COST = 15, /* how much avail and money to charge */
49 UPGR_EFF = 35 /* efficiency reduction */
52 static int lupgr(void);
53 static int pupgr(void);
54 static int supgr(void);
62 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
77 pr("Ships, land units or planes only!\n");
95 if (!snxtitem(&ni, EF_LAND, player->argp[2]))
97 natp = getnatp(player->cnum);
98 cash = natp->nat_money;
99 tlev = (int)natp->nat_level[NAT_TLEV];
101 while (nxtitem(&ni, (s_char *)&land)) {
102 if (land.lnd_own == 0)
104 getsect(land.lnd_x, land.lnd_y, §);
105 if (sect.sct_own != player->cnum)
107 if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
109 rel = getrel(getnatp(land.lnd_own), sect.sct_own);
110 if ((rel < FRIENDLY) && (sect.sct_own != land.lnd_own)) {
111 pr("You are not on friendly terms with the owner of unit %d!\n", land.lnd_uid);
115 lp = &lchr[(int)land.lnd_type];
116 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * UPGR_COST + 99) / 100;
117 if (sect.sct_avail < avail) {
118 pr("Not enough available work in %s to upgrade a %s\n",
119 xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name);
120 pr(" (%d available work required)\n", avail);
123 if (land.lnd_effic < 60) {
124 pr("%s is too damaged to upgrade!\n", prland(&land));
127 if (land.lnd_tech >= tlev) {
128 pr("%s tech: %d, yours is only %d\n", prland(&land),
129 land.lnd_tech, tlev);
132 cost = lp->l_cost * UPGR_COST / 100;
133 if (cost + player->dolcost > cash) {
134 pr("You don't have enough money to upgrade %s!\n",
139 sect.sct_avail -= avail;
140 land.lnd_effic -= UPGR_EFF;
141 lnd_set_tech(&land, tlev);
143 land.lnd_mission = 0;
144 time(&land.lnd_access);
146 putland(land.lnd_uid, &land);
148 player->dolcost += cost;
149 pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land),
150 land.lnd_tech, cost);
151 if (land.lnd_own != player->cnum)
153 "%s upgraded by %s to tech %d, at a cost of %d\n",
154 prland(&land), cname(player->cnum), land.lnd_tech,
158 pr("No land units\n");
178 if (!snxtitem(&ni, EF_SHIP, player->argp[2]))
180 natp = getnatp(player->cnum);
181 cash = natp->nat_money;
182 tlev = (int)natp->nat_level[NAT_TLEV];
184 while (nxtitem(&ni, (s_char *)&ship)) {
185 if (ship.shp_own == 0)
187 getsect(ship.shp_x, ship.shp_y, §);
188 if (sect.sct_own != player->cnum)
190 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
192 rel = getrel(getnatp(ship.shp_own), sect.sct_own);
193 if ((rel < FRIENDLY) && (sect.sct_own != ship.shp_own)) {
194 pr("You are not on friendly terms with the owner of ship %d!\n", ship.shp_uid);
198 mp = &mchr[(int)ship.shp_type];
199 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100;
200 if (sect.sct_avail < avail) {
201 pr("Not enough available work in %s to upgrade a %s\n",
202 xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name);
203 pr(" (%d available work required)\n", avail);
206 if (ship.shp_effic < 60) {
207 pr("%s is too damaged to upgrade!\n", prship(&ship));
210 if (ship.shp_tech >= tlev) {
211 pr("%s tech: %d, yours is only %d\n", prship(&ship),
212 ship.shp_tech, tlev);
215 cost = mp->m_cost * UPGR_COST / 100;
216 if (cost + player->dolcost > cash) {
217 pr("You don't have enough money to upgrade %s!\n",
222 sect.sct_avail -= avail;
223 ship.shp_effic -= UPGR_EFF;
224 shp_set_tech(&ship, tlev);
225 ship.shp_mission = 0;
226 time(&ship.shp_access);
228 putship(ship.shp_uid, &ship);
230 player->dolcost += cost;
231 pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship),
232 ship.shp_tech, cost);
233 if (ship.shp_own != player->cnum)
235 "%s upgraded by %s to tech %d, at a cost of %d\n",
236 prship(&ship), cname(player->cnum), ship.shp_tech,
260 if (!snxtitem(&ni, EF_PLANE, player->argp[2]))
262 natp = getnatp(player->cnum);
263 cash = natp->nat_money;
264 tlev = (int)natp->nat_level[NAT_TLEV];
266 while (nxtitem(&ni, (s_char *)&plane)) {
267 if (plane.pln_own == 0)
269 getsect(plane.pln_x, plane.pln_y, §);
270 if (sect.sct_own != player->cnum)
272 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
274 rel = getrel(getnatp(plane.pln_own), sect.sct_own);
275 if ((rel < FRIENDLY) && (sect.sct_own != plane.pln_own)) {
276 pr("You are not on friendly terms with the owner of plane %d!\n", plane.pln_uid);
280 pp = &plchr[(int)plane.pln_type];
281 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100;
282 if (sect.sct_avail < avail) {
283 pr("Not enough available work in %s to upgrade a %s\n",
284 xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name);
285 pr(" (%d available work required)\n", avail);
288 if (plane.pln_effic < 60) {
289 pr("%s is too damaged to upgrade!\n", prplane(&plane));
292 if (plane.pln_tech >= tlev) {
293 pr("%s tech: %d, yours is only %d\n", prplane(&plane),
294 plane.pln_tech, tlev);
297 cost = pp->pl_cost * UPGR_COST / 100;
298 if (cost + player->dolcost > cash) {
299 pr("You don't have enough money to upgrade %s!\n",
303 if (plane.pln_flags & PLN_LAUNCHED) {
304 pr("Plane %s is in orbit!\n", prplane(&plane));
308 sect.sct_avail -= avail;
309 plane.pln_effic -= UPGR_EFF;
310 pln_set_tech(&plane, tlev);
311 plane.pln_harden = 0;
312 plane.pln_mission = 0;
313 time(&plane.pln_access);
315 putplane(plane.pln_uid, &plane);
317 player->dolcost += cost;
318 pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane),
319 plane.pln_tech, cost);
320 if (plane.pln_own != player->cnum)
322 "%s upgraded by %s to tech %d, at a cost of %d\n",
323 prplane(&plane), cname(player->cnum), plane.pln_tech,