2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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
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 (getrel(getnatp(land.lnd_own), sect.sct_own) < FRIENDLY
104 && sect.sct_own != land.lnd_own) {
105 pr("You are not on friendly terms with the owner of unit %d!\n",
110 lp = &lchr[(int)land.lnd_type];
111 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * UPGR_COST + 99) / 100;
112 if (sect.sct_avail < avail) {
113 pr("Not enough available work in %s to upgrade a %s\n",
114 xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name);
115 pr(" (%d available work required)\n", avail);
118 if (land.lnd_effic < 60) {
119 pr("%s is too damaged to upgrade!\n", prland(&land));
122 if (land.lnd_tech >= tlev) {
123 pr("%s tech: %d, yours is only %d\n",
124 prland(&land), land.lnd_tech, tlev);
127 cost = lp->l_cost * UPGR_COST / 100;
128 if (cost + player->dolcost > cash) {
129 pr("You don't have enough money to upgrade %s!\n",
134 sect.sct_avail -= avail;
135 land.lnd_effic -= UPGR_EFF;
136 lnd_set_tech(&land, tlev);
138 land.lnd_mission = 0;
140 putland(land.lnd_uid, &land);
142 player->dolcost += cost;
143 pr("%s upgraded to tech %d, at a cost of %d\n",
144 prland(&land), land.lnd_tech, cost);
145 if (land.lnd_own != player->cnum)
147 "%s upgraded by %s to tech %d, at a cost of %d\n",
148 prland(&land), cname(player->cnum), land.lnd_tech, cost);
151 pr("No land units\n");
170 if (!snxtitem(&ni, EF_SHIP, player->argp[2], NULL))
172 natp = getnatp(player->cnum);
173 cash = natp->nat_money;
174 tlev = (int)natp->nat_level[NAT_TLEV];
176 while (nxtitem(&ni, &ship)) {
177 if (ship.shp_own == 0)
179 getsect(ship.shp_x, ship.shp_y, §);
180 if (sect.sct_own != player->cnum)
182 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
184 if (getrel(getnatp(ship.shp_own), sect.sct_own) < FRIENDLY
185 && sect.sct_own != ship.shp_own) {
186 pr("You are not on friendly terms with the owner of ship %d!\n",
191 mp = &mchr[(int)ship.shp_type];
192 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100;
193 if (sect.sct_avail < avail) {
194 pr("Not enough available work in %s to upgrade a %s\n",
195 xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name);
196 pr(" (%d available work required)\n", avail);
199 if (ship.shp_effic < 60) {
200 pr("%s is too damaged to upgrade!\n", prship(&ship));
203 if (ship.shp_tech >= tlev) {
204 pr("%s tech: %d, yours is only %d\n",
205 prship(&ship), ship.shp_tech, tlev);
208 cost = mp->m_cost * UPGR_COST / 100;
209 if (cost + player->dolcost > cash) {
210 pr("You don't have enough money to upgrade %s!\n",
215 sect.sct_avail -= avail;
216 ship.shp_effic -= UPGR_EFF;
217 shp_set_tech(&ship, tlev);
218 ship.shp_mission = 0;
220 putship(ship.shp_uid, &ship);
222 player->dolcost += cost;
223 pr("%s upgraded to tech %d, at a cost of %d\n",
224 prship(&ship), ship.shp_tech, cost);
225 if (ship.shp_own != player->cnum)
227 "%s upgraded by %s to tech %d, at a cost of %d\n",
228 prship(&ship), cname(player->cnum), ship.shp_tech, cost);
250 if (!snxtitem(&ni, EF_PLANE, player->argp[2], NULL))
252 natp = getnatp(player->cnum);
253 cash = natp->nat_money;
254 tlev = (int)natp->nat_level[NAT_TLEV];
256 while (nxtitem(&ni, &plane)) {
257 if (plane.pln_own == 0)
259 getsect(plane.pln_x, plane.pln_y, §);
260 if (sect.sct_own != player->cnum)
262 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
264 if (getrel(getnatp(plane.pln_own), sect.sct_own) < FRIENDLY
265 && sect.sct_own != plane.pln_own) {
266 pr("You are not on friendly terms with the owner of plane %d!\n",
270 if (pln_is_in_orbit(&plane)) {
271 pr("Plane %s is in orbit!\n", prplane(&plane));
274 if (plane.pln_flags & PLN_LAUNCHED)
277 pp = &plchr[(int)plane.pln_type];
278 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100;
279 if (sect.sct_avail < avail) {
280 pr("Not enough available work in %s to upgrade a %s\n",
281 xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name);
282 pr(" (%d available work required)\n", avail);
285 if (plane.pln_effic < 60) {
286 pr("%s is too damaged to upgrade!\n", prplane(&plane));
289 if (plane.pln_tech >= tlev) {
290 pr("%s tech: %d, yours is only %d\n",
291 prplane(&plane), plane.pln_tech, tlev);
294 cost = pp->pl_cost * UPGR_COST / 100;
295 if (cost + player->dolcost > cash) {
296 pr("You don't have enough money to upgrade %s!\n",
301 sect.sct_avail -= avail;
302 plane.pln_effic -= UPGR_EFF;
303 pln_set_tech(&plane, tlev);
304 plane.pln_harden = 0;
305 plane.pln_mission = 0;
307 putplane(plane.pln_uid, &plane);
309 player->dolcost += cost;
310 pr("%s upgraded to tech %d, at a cost of %d\n",
311 prplane(&plane), plane.pln_tech, cost);
312 if (plane.pln_own != player->cnum)
314 "%s upgraded by %s to tech %d, at a cost of %d\n",
315 prplane(&plane), cname(player->cnum), plane.pln_tech, cost);