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 * work.c: Implementation of the work command
30 * Known contributors to this file:
47 static int buildeff(struct sctstr *, int, double *);
56 int work_amt, eff_amt, w;
58 extern int land_mob_max;
59 coord donex = 0, doney = 1;
62 if (!snxtitem(&ni, EF_LAND, player->argp[1]))
64 p = getstarg(player->argp[2], "Amount: ", buf);
65 if (p == 0 || *p == 0)
68 if ((work_amt < 0) || (work_amt > land_mob_max)) {
69 pr("Mobility used must be from 0 to %d\n", land_mob_max);
73 while (nxtitem(&ni, (s_char *)&land)) {
74 if (!player->owner || land.lnd_own == 0)
76 if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) {
77 pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur);
80 if (!(lchr[(int)land.lnd_type].l_flags & L_ENGINEER))
82 if (land.lnd_mobil <= 0) {
83 pr("%s has no mobility!\n", prland(&land));
86 getsect(land.lnd_x, land.lnd_y, §);
87 if (sect.sct_effic >= 100 && sect.sct_type == sect.sct_newtype) {
88 if (sect.sct_x != donex || sect.sct_y != doney)
89 pr("%s is %d%% efficient\n",
90 xyas(sect.sct_x, sect.sct_y, player->cnum),
92 /* not perfect, but it'll do -KHS */
97 eff_amt = min(land.lnd_mobil, work_amt);
98 w = ldround(((double)eff_amt * land.lnd_effic / 600.0), 1);
100 pr("%s doesn't work enough to change efficiency (try increasing amount)\n", prland(&land));
104 eff_amt = ((6 * buildeff(§, w, &player->dolcost)) /
105 (land.lnd_effic / 100.0));
106 land.lnd_mission = 0;
107 land.lnd_mobil -= eff_amt;
108 pr("%s %s efficiency at %s to %d\n",
110 sect.sct_type == sect.sct_newtype ? "raised" : "lowered",
111 xyas(land.lnd_x, land.lnd_y, player->cnum),
112 (int)sect.sct_effic);
113 putland(land.lnd_uid, &land);
118 pr("%s: No unit(s)\n", player->argp[1]);
120 pr("%s: No unit(s)\n", "");
123 pr("%d unit%s\n", nunits, splur(nunits));
128 buildeff(struct sctstr *sp, int work, double *money)
131 register int work_cost;
135 getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);
138 if (sp->sct_type != sp->sct_newtype) {
140 * Tear down existing sector.
141 * Easier to destroy than to build.
143 work_cost = (sp->sct_effic + 3) / 4;
144 if (work_cost > work)
146 n = sp->sct_effic - work_cost * 4;
149 sp->sct_type = sp->sct_newtype;
152 if (!opt_DEFENSE_INFRA)
153 sp->sct_defense = sp->sct_effic;
156 effdone += work_cost;
158 if (sp->sct_type == sp->sct_newtype) {
159 work_cost = 100 - sp->sct_effic;
160 if (work_cost > work)
163 if (dchr[sp->sct_type].d_lcms > 0) {
165 lcms /= dchr[sp->sct_type].d_lcms;
166 if (work_cost > lcms)
169 if (dchr[sp->sct_type].d_hcms > 0) {
171 hcms /= dchr[sp->sct_type].d_hcms;
172 if (work_cost > hcms)
176 sp->sct_effic += work_cost;
177 *money += work_cost * dchr[sp->sct_type].d_build;
179 if ((dchr[sp->sct_type].d_lcms > 0) ||
180 (dchr[sp->sct_type].d_hcms > 0)) {
181 vec[I_LCM] -= work_cost * dchr[sp->sct_type].d_lcms;
182 vec[I_HCM] -= work_cost * dchr[sp->sct_type].d_hcms;
184 effdone += work_cost;
186 putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR);