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 * plane.c: Do production for planes
30 * Known contributors to this file:
52 #define MIN(x,y) ((x) > (y) ? (y) : (x))
56 prod_plane(int etus, int natnum, int *bp, int buildem)
60 /* Build = 1, maintain =0 */
62 extern long air_money[MAXNOC];
63 register struct plnstr *pp;
64 register struct plchrstr *plp;
68 int lcm_needed, hcm_needed;
74 struct plchrstr *desc;
83 int start_money, onship = 0;
85 for (n = 0; NULL != (pp = getplanep(n)); n++) {
88 if (pp->pln_own != natnum)
90 if (pp->pln_effic < PLANE_MINEFF) {
91 makelost(EF_PLANE, pp->pln_own, pp->pln_uid,
92 pp->pln_x, pp->pln_y);
97 plp = &plchr[(int)pp->pln_type];
98 if (pp->pln_flags & PLN_LAUNCHED) {
99 if (opt_ORBIT && (buildem == 0)) {
100 if ((!player->simulation) &&
101 (plp->pl_flags & P_O) &&
102 (pp->pln_flags & PLN_LAUNCHED) &&
103 !(plp->pl_flags & P_M) &&
104 !(pp->pln_flags & PLN_SYNCHRONOUS))
111 shp = (struct shpstr *)0;
112 if (pp->pln_ship >= 0 && (buildem == 1)) {
113 if (pp->pln_effic >= 80)
116 shp = getshipp(pp->pln_ship);
117 if (shp == 0 || shp->shp_own != pp->pln_own) {
118 /* nplane is unsigned... */
119 if (shp->shp_nplane > 0)
121 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
127 np = getnatp(pp->pln_own);
128 desc = &plchr[(int)pp->pln_type];
129 sp = getsectp(pp->pln_x, pp->pln_y);
130 getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR);
132 if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85)
136 /* flight pay is 5x the pay received by other military */
137 start_money = np->nat_money;
138 cost = -(mult * etus * dmin(0.0, desc->pl_cost * money_plane));
139 if ((np->nat_priorities[PRI_PMAINT] == 0 ||
140 np->nat_money < cost) && !player->simulation) {
141 if ((eff = pp->pln_effic - etus / 5) < PLANE_MINEFF) {
143 "%s lost to lack of maintenance\n", prplane(pp));
144 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x,
150 "%s lost %d%% to lack of maintenance\n",
151 prplane(pp), pp->pln_effic - eff);
154 np->nat_money -= cost;
157 np->nat_money += (etus * plp->pl_crew * money_mil * 5);
159 air_money[pp->pln_own] += np->nat_money - start_money;
161 if (player->simulation)
162 np->nat_money = start_money;
163 if ((pp->pln_flags & PLN_LAUNCHED) == PLN_LAUNCHED)
168 if (np->nat_priorities[PRI_PBUILD] == 0 || np->nat_money < 0)
171 start_money = np->nat_money;
172 left = 100 - pp->pln_effic;
176 if (!player->simulation)
177 avail = sp->sct_avail * 100;
179 avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
181 if (pp->pln_ship >= 0) {
183 shp = getshipp(pp->pln_ship);
184 getvec(VT_ITEM, vec, (s_char *)shp, EF_SHIP);
185 avail += (etus * vec[I_MILIT] / 2);
187 w_p_eff = 20 + (desc->pl_lcm + 2 * desc->pl_hcm);
188 delta = roundavg((double)avail / w_p_eff);
191 if (delta > etus * plane_grow_scale)
192 delta = etus * plane_grow_scale;
196 /* delta is the max amount we can grow */
198 left = 100 - pp->pln_effic;
202 leftp = ((float)left / 100.0);
203 memset(mvec, 0, sizeof(mvec));
204 mvec[I_MILIT] = mil_needed =
205 ldround((double)(plp->pl_crew * leftp), 1);
206 mvec[I_LCM] = lcm_needed =
207 ldround((double)(plp->pl_lcm * leftp), 1);
208 mvec[I_HCM] = hcm_needed =
209 ldround((double)(plp->pl_hcm * leftp), 1);
211 get_materials(sp, bp, mvec, 0);
213 if (mvec[I_MILIT] >= mil_needed)
216 buildp = ((float)mvec[I_MILIT] / (float)plp->pl_crew);
218 if (mvec[I_LCM] < lcm_needed)
219 buildp = MIN(buildp, ((float)mvec[I_LCM] /
220 (float)plp->pl_lcm));
222 if (mvec[I_HCM] < hcm_needed)
223 buildp = MIN(buildp, ((float)mvec[I_HCM] /
224 (float)plp->pl_hcm));
226 build = ldround((double)(buildp * 100.0), 1);
227 memset(mvec, 0, sizeof(mvec));
228 mvec[I_MILIT] = mil_needed =
229 roundavg((double)(plp->pl_crew * buildp));
230 mvec[I_LCM] = lcm_needed =
231 roundavg((double)(plp->pl_lcm * buildp));
232 mvec[I_HCM] = hcm_needed =
233 roundavg((double)(plp->pl_hcm * buildp));
235 get_materials(sp, bp, mvec, 1);
239 used = build * w_p_eff;
242 * I didn't use roundavg here, because I want to
243 * penalize the player with a large number of planes.
245 if (!player->simulation)
246 avail = (sp->sct_avail * 100 - used) / 100;
248 avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 - used) / 100;
252 if (!player->simulation)
253 sp->sct_avail = avail;
255 pt_bg_nmbr(bp, sp, I_MAX + 1, avail);
257 if (sp->sct_type != SCT_AIRPT)
260 if ((pp->pln_effic + build) > 80)
261 build = 80 - pp->pln_effic;
263 np->nat_money -= roundavg(mult * build *
264 desc->pl_cost / 100.0);
265 air_money[pp->pln_own] += np->nat_money - start_money;
267 if (!player->simulation)
268 pp->pln_effic += (s_char)build;
270 np->nat_money = start_money;