2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, 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 * work.c: Implementation of the work command
29 * Known contributors to this file:
30 * Markus Armbruster, 2009-2016
48 int work_amt, eff_amt, w, sect_avail;
52 struct natstr *natp = getnatp(player->cnum);
54 if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
56 p = getstarg(player->argp[2], "Amount: ", buf);
60 if ((work_amt < 0) || (work_amt > land_mob_max)) {
61 pr("Mobility used must be from 0 to %d\n", land_mob_max);
65 while (nxtitem(&ni, &land)) {
66 if (!player->owner || land.lnd_own == 0)
68 if (!(lchr[(int)land.lnd_type].l_flags & L_ENGINEER))
70 if (land.lnd_ship >= 0 || land.lnd_land >= 0) {
72 prland(&land), land.lnd_ship >= 0 ? "ship" : "land unit");
75 if (land.lnd_mobil <= 0) {
76 pr("%s has no mobility!\n", prland(&land));
79 getsect(land.lnd_x, land.lnd_y, §);
80 if (sect.sct_effic >= 100 && sect.sct_type == sect.sct_newtype) {
81 pr("Nothing to do for %s in %s\n",
82 prland(&land), xyas(sect.sct_x, sect.sct_y, player->cnum));
85 eff_amt = MIN(land.lnd_mobil, work_amt);
86 w = (eff_amt * land.lnd_effic) / 600;
88 pr("%s doesn't work enough to change efficiency (try increasing amount)\n",
92 sect_avail = sect.sct_avail;
94 cost = buildeff(§);
95 w = sect.sct_avail - sect_avail;
96 sect.sct_avail = sect_avail;
98 pr("%s can't change efficiency in %s\n",
99 prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum));
102 if (player->dolcost + cost > natp->nat_money) {
103 pr("You can't afford to work that much in %s!\n",
104 xyas(land.lnd_x, land.lnd_y, player->cnum));
107 player->dolcost += cost;
108 land.lnd_mission = 0;
109 land.lnd_mobil -= roundavg(w * 600.0 / land.lnd_effic);
111 pr("%s %s efficiency at %s to %d\n",
113 sect.sct_type == sect.sct_newtype ? "raised" : "lowered",
114 xyas(land.lnd_x, land.lnd_y, player->cnum),
116 putland(land.lnd_uid, &land);
121 pr("%s: No unit(s)\n", player->argp[1]);
123 pr("%s: No unit(s)\n", "");
126 pr("%d unit%s\n", nunits, splur(nunits));