2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * upgr.c: Upgrade tech of ships/planes/units
29 * Known contributors to this file:
31 * Steve McClure, 1996-2000
42 UPGR_COST = 15, /* how much avail and money to charge */
43 UPGR_EFF = 35 /* efficiency reduction */
46 static int lupgr(void);
47 static int pupgr(void);
48 static int supgr(void);
56 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
71 pr("Ships, land units or planes only!\n");
88 if (!snxtitem(&ni, EF_LAND, player->argp[2], NULL))
90 natp = getnatp(player->cnum);
91 cash = natp->nat_money;
92 tlev = (int)natp->nat_level[NAT_TLEV];
94 while (nxtitem(&ni, &land)) {
95 if (land.lnd_own == 0)
97 getsect(land.lnd_x, land.lnd_y, §);
98 if (sect.sct_own != player->cnum)
100 if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60)
102 if (relations_with(land.lnd_own, sect.sct_own) < FRIENDLY) {
103 pr("You are not on friendly terms with the owner of unit %d!\n",
108 lp = &lchr[(int)land.lnd_type];
109 avail = (LND_BLD_WORK(lp->l_lcm, lp->l_hcm) * UPGR_COST + 99) / 100;
110 if (sect.sct_avail < avail) {
111 pr("Not enough available work in %s to upgrade a %s\n",
112 xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name);
113 pr(" (%d available work required)\n", avail);
116 if (land.lnd_effic < 60) {
117 pr("%s is too damaged to upgrade!\n", prland(&land));
120 if (land.lnd_tech >= tlev) {
121 pr("%s tech: %d, yours is only %d\n",
122 prland(&land), land.lnd_tech, tlev);
125 cost = lp->l_cost * UPGR_COST / 100;
126 if (cost + player->dolcost > cash) {
127 pr("You don't have enough money to upgrade %s!\n",
132 sect.sct_avail -= avail;
133 land.lnd_effic -= UPGR_EFF;
134 lnd_set_tech(&land, tlev);
136 land.lnd_mission = 0;
138 putland(land.lnd_uid, &land);
140 player->dolcost += cost;
141 pr("%s upgraded to tech %d, at a cost of %d\n",
142 prland(&land), land.lnd_tech, cost);
143 if (land.lnd_own != player->cnum)
145 "%s upgraded by %s to tech %d, at a cost of %d\n",
146 prland(&land), cname(player->cnum), land.lnd_tech, cost);
149 pr("No land units\n");
168 if (!snxtitem(&ni, EF_SHIP, player->argp[2], NULL))
170 natp = getnatp(player->cnum);
171 cash = natp->nat_money;
172 tlev = (int)natp->nat_level[NAT_TLEV];
174 while (nxtitem(&ni, &ship)) {
175 if (ship.shp_own == 0)
177 getsect(ship.shp_x, ship.shp_y, §);
178 if (sect.sct_own != player->cnum)
180 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60)
182 if (relations_with(ship.shp_own, sect.sct_own) < FRIENDLY) {
183 pr("You are not on friendly terms with the owner of ship %d!\n",
188 mp = &mchr[(int)ship.shp_type];
189 avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100;
190 if (sect.sct_avail < avail) {
191 pr("Not enough available work in %s to upgrade a %s\n",
192 xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name);
193 pr(" (%d available work required)\n", avail);
196 if (ship.shp_effic < 60) {
197 pr("%s is too damaged to upgrade!\n", prship(&ship));
200 if (ship.shp_tech >= tlev) {
201 pr("%s tech: %d, yours is only %d\n",
202 prship(&ship), ship.shp_tech, tlev);
205 cost = mp->m_cost * UPGR_COST / 100;
206 if (cost + player->dolcost > cash) {
207 pr("You don't have enough money to upgrade %s!\n",
212 sect.sct_avail -= avail;
213 ship.shp_effic -= UPGR_EFF;
214 shp_set_tech(&ship, tlev);
215 ship.shp_mission = 0;
217 putship(ship.shp_uid, &ship);
219 player->dolcost += cost;
220 pr("%s upgraded to tech %d, at a cost of %d\n",
221 prship(&ship), ship.shp_tech, cost);
222 if (ship.shp_own != player->cnum)
224 "%s upgraded by %s to tech %d, at a cost of %d\n",
225 prship(&ship), cname(player->cnum), ship.shp_tech, cost);
247 if (!snxtitem(&ni, EF_PLANE, player->argp[2], NULL))
249 natp = getnatp(player->cnum);
250 cash = natp->nat_money;
251 tlev = (int)natp->nat_level[NAT_TLEV];
253 while (nxtitem(&ni, &plane)) {
254 if (plane.pln_own == 0)
256 getsect(plane.pln_x, plane.pln_y, §);
257 if (sect.sct_own != player->cnum)
259 if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)
261 if (relations_with(plane.pln_own, sect.sct_own) < FRIENDLY) {
262 pr("You are not on friendly terms with the owner of plane %d!\n",
266 if (pln_is_in_orbit(&plane)) {
267 pr("Plane %s is in orbit!\n", prplane(&plane));
270 if (plane.pln_flags & PLN_LAUNCHED)
273 pp = &plchr[(int)plane.pln_type];
274 avail = (PLN_BLD_WORK(pp->pl_lcm, pp->pl_hcm) * UPGR_COST + 99) / 100;
275 if (sect.sct_avail < avail) {
276 pr("Not enough available work in %s to upgrade a %s\n",
277 xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name);
278 pr(" (%d available work required)\n", avail);
281 if (plane.pln_effic < 60) {
282 pr("%s is too damaged to upgrade!\n", prplane(&plane));
285 if (plane.pln_tech >= tlev) {
286 pr("%s tech: %d, yours is only %d\n",
287 prplane(&plane), plane.pln_tech, tlev);
290 cost = pp->pl_cost * UPGR_COST / 100;
291 if (cost + player->dolcost > cash) {
292 pr("You don't have enough money to upgrade %s!\n",
297 sect.sct_avail -= avail;
298 plane.pln_effic -= UPGR_EFF;
299 pln_set_tech(&plane, tlev);
300 plane.pln_harden = 0;
301 plane.pln_mission = 0;
303 putplane(plane.pln_uid, &plane);
305 player->dolcost += cost;
306 pr("%s upgraded to tech %d, at a cost of %d\n",
307 prplane(&plane), plane.pln_tech, cost);
308 if (plane.pln_own != player->cnum)
310 "%s upgraded by %s to tech %d, at a cost of %d\n",
311 prplane(&plane), cname(player->cnum), plane.pln_tech, cost);