/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* Dave Pare, 1986
* Steve McClure, 1996
* Ron Koenderink, 2004
- * Markus Armbruster, 2006
+ * Markus Armbruster, 2006-2007
*/
#include <config.h>
#include "ship.h"
#include "update.h"
-static void shiprepair(struct shpstr *, struct natstr *, int *, int);
-static void upd_ship(struct shpstr *, int, struct natstr *, int *, int);
+static void shiprepair(struct shpstr *, struct natstr *, struct bp *, int);
+static void upd_ship(struct shpstr *, int, struct natstr *, struct bp *, int);
static int feed_ship(struct shpstr *, int);
int
-prod_ship(int etus, int natnum, int *bp, int build)
+prod_ship(int etus, int natnum, struct bp *bp, int build)
/* build = 1, maintain = 0 */
{
struct shpstr *sp;
static void
upd_ship(struct shpstr *sp, int etus,
- struct natstr *np, int *bp, int build)
+ struct natstr *np, struct bp *bp, int build)
/* build = 1, maintain = 0 */
{
struct sctstr *sectp;
sectp = getsectp(sp->shp_x, sp->shp_y);
/* produce oil */
- if (np->nat_money > 0
+ if (np->nat_money >= 0
&& (mp->m_flags & M_OIL) && sectp->sct_type == SCT_WATER) {
product = &pchr[dchr[SCT_OIL].d_prd];
oil_gained = roundavg(total_work(100, etus,
sp->shp_item[I_OIL] += oil_gained;
}
/* produce fish */
- if (np->nat_money > 0
+ if (np->nat_money >= 0
&& (mp->m_flags & M_FOOD) && sectp->sct_type == SCT_WATER) {
sp->shp_item[I_FOOD]
+= roundavg(total_work(100, etus,
* 8 * 8 * $40 = $2560!
*/
static void
-shiprepair(struct shpstr *ship, struct natstr *np, int *bp, int etus)
+shiprepair(struct shpstr *ship, struct natstr *np, struct bp *bp, int etus)
{
int delta;
struct sctstr *sp;
struct mchrstr *mp;
- float leftp, buildp;
- int left, build;
- int lcm_needed, hcm_needed;
+ int build;
int wf;
int avail;
int w_p_eff;
if (!player->simulation)
avail = wf + sp->sct_avail * 100;
else
- avail = wf + gt_bg_nmbr(bp, sp, I_MAX + 1) * 100;
+ avail = wf + bp_get_avail(bp, sp) * 100;
}
w_p_eff = SHP_BLD_WORK(mp->m_lcm, mp->m_hcm);
return;
}
- left = 100 - ship->shp_effic;
delta = roundavg((double)avail / w_p_eff);
if (delta <= 0)
return;
if (delta > (int)((float)etus * ship_grow_scale))
delta = (int)((float)etus * ship_grow_scale);
- if (delta > left)
- delta = left;
+ if (delta > 100 - ship->shp_effic)
+ delta = 100 - ship->shp_effic;
- /* delta is the max amount we can grow */
-
- left = 100 - ship->shp_effic;
- if (left > delta)
- left = delta;
-
- leftp = left / 100.0;
- memset(mvec, 0, sizeof(mvec));
- mvec[I_LCM] = lcm_needed = ldround(mp->m_lcm * leftp, 1);
- mvec[I_HCM] = hcm_needed = ldround(mp->m_hcm * leftp, 1);
- get_materials(sp, bp, mvec, 0);
-
- buildp = leftp;
- if (mvec[I_LCM] < lcm_needed)
- buildp = MIN(buildp, (float)mvec[I_LCM] / (float)mp->m_lcm);
- if (mvec[I_HCM] < hcm_needed)
- buildp = MIN(buildp, (float)mvec[I_HCM] / (float)mp->m_hcm);
-
- build = ldround(buildp * 100.0, 1);
memset(mvec, 0, sizeof(mvec));
- mvec[I_LCM] = roundavg(mp->m_lcm * buildp);
- mvec[I_HCM] = roundavg(mp->m_hcm * buildp);
- get_materials(sp, bp, mvec, 1);
+ mvec[I_LCM] = mp->m_lcm;
+ mvec[I_HCM] = mp->m_hcm;
+ build = get_materials(sp, bp, mvec, delta);
if (sp->sct_type != SCT_HARBR)
build = delta;
+
wf -= build * w_p_eff;
if (wf < 0) {
/*
if (!player->simulation)
avail = (sp->sct_avail * 100 + wf) / 100;
else
- avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 + wf) / 100;
+ avail = (bp_get_avail(bp, sp) * 100 + wf) / 100;
if (avail < 0)
avail = 0;
if (!player->simulation)
sp->sct_avail = avail;
else
- pt_bg_nmbr(bp, sp, I_MAX + 1, avail);
+ bp_put_avail(bp, sp, avail);
}
if (sp->sct_type != SCT_HARBR)
if ((build + ship->shp_effic) > 80) {