2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 * work.c: Implementation of the work command
30 * Known contributors to this file:
31 * Markus Armbruster, 2009
40 static int buildeff(struct sctstr *, int, double *);
49 int work_amt, eff_amt, w;
53 struct natstr *natp = getnatp(player->cnum);
55 if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
57 p = getstarg(player->argp[2], "Amount: ", buf);
61 if ((work_amt < 0) || (work_amt > land_mob_max)) {
62 pr("Mobility used must be from 0 to %d\n", land_mob_max);
66 while (nxtitem(&ni, &land)) {
67 if (!player->owner || land.lnd_own == 0)
69 if (!(lchr[(int)land.lnd_type].l_flags & L_ENGINEER))
71 if (land.lnd_mobil <= 0) {
72 pr("%s has no mobility!\n", prland(&land));
75 getsect(land.lnd_x, land.lnd_y, §);
76 if (sect.sct_effic >= 100 && sect.sct_type == sect.sct_newtype) {
77 pr("Nothing to do for %s in %s\n",
78 prland(&land), xyas(sect.sct_x, sect.sct_y, player->cnum));
81 eff_amt = MIN(land.lnd_mobil, work_amt);
82 w = (eff_amt * land.lnd_effic) / 600;
84 pr("%s doesn't work enough to change efficiency (try increasing amount)\n",
89 w = buildeff(§, w, &cost);
91 pr("%s can't change efficiency in %s\n",
92 prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum));
95 if (player->dolcost + cost > natp->nat_money) {
96 pr("You can't afford to work that much in %s!\n",
97 xyas(land.lnd_x, land.lnd_y, player->cnum));
100 player->dolcost += cost;
101 land.lnd_mission = 0;
102 land.lnd_mobil -= roundavg(w * 600.0 / land.lnd_effic);
104 pr("%s %s efficiency at %s to %d\n",
106 sect.sct_type == sect.sct_newtype ? "raised" : "lowered",
107 xyas(land.lnd_x, land.lnd_y, player->cnum),
109 putland(land.lnd_uid, &land);
114 pr("%s: No unit(s)\n", player->argp[1]);
116 pr("%s: No unit(s)\n", "");
119 pr("%d unit%s\n", nunits, splur(nunits));
124 buildeff(struct sctstr *sp, int work, double *money)
131 if (sp->sct_type != sp->sct_newtype) {
133 * Tear down existing sector.
134 * Easier to destroy than to build.
136 work_cost = (sp->sct_effic + 3) / 4;
137 if (work_cost > work)
139 n = sp->sct_effic - work_cost * 4;
142 sp->sct_type = sp->sct_newtype;
147 effdone += work_cost;
149 if (sp->sct_type == sp->sct_newtype) {
150 work_cost = 100 - sp->sct_effic;
151 if (work_cost > work)
154 if (dchr[sp->sct_type].d_lcms > 0) {
155 lcms = sp->sct_item[I_LCM];
156 lcms /= dchr[sp->sct_type].d_lcms;
157 if (work_cost > lcms)
160 if (dchr[sp->sct_type].d_hcms > 0) {
161 hcms = sp->sct_item[I_HCM];
162 hcms /= dchr[sp->sct_type].d_hcms;
163 if (work_cost > hcms)
167 sp->sct_effic += work_cost;
168 *money += work_cost * dchr[sp->sct_type].d_build;
170 if ((dchr[sp->sct_type].d_lcms > 0) ||
171 (dchr[sp->sct_type].d_hcms > 0)) {
172 sp->sct_item[I_LCM] -= work_cost * dchr[sp->sct_type].d_lcms;
173 sp->sct_item[I_HCM] -= work_cost * dchr[sp->sct_type].d_hcms;
175 effdone += work_cost;