/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
#include <math.h>
#include "chance.h"
-#include "file.h"
#include "land.h"
#include "lost.h"
#include "nat.h"
#include "update.h"
static void upd_ship(struct shpstr *, int, struct bp *, int);
+static void plague_ship(struct shpstr *, int);
static void shiprepair(struct shpstr *, struct natstr *, struct bp *,
int, struct budget *);
+static void ship_produce(struct shpstr *, int, struct budget *);
static int feed_ship(struct shpstr *, int);
-void
-prod_ship(int etus, int natnum, struct bp *bp, int build)
- /* build = 1, maintain = 0 */
+void prep_ships(int etus, struct bp *bp)
{
+ int mil, i, n;
+ double mil_pay;
struct shpstr *sp;
- int i;
for (i = 0; (sp = getshipp(i)); i++) {
if (sp->shp_own == 0)
continue;
- if (sp->shp_own != natnum)
- continue;
- if (sp->shp_effic < SHIP_MINEFF) {
+ if (CANT_HAPPEN(sp->shp_effic < SHIP_MINEFF)) {
makelost(EF_SHIP, sp->shp_own, sp->shp_uid,
sp->shp_x, sp->shp_y);
sp->shp_own = 0;
continue;
}
+ bp_consider_unit(bp, (struct empobj *)sp);
+ mil = sp->shp_item[I_MILIT];
+ mil_pay = mil * etus * money_mil;
+ nat_budget[sp->shp_own].mil.count += mil;
+ nat_budget[sp->shp_own].mil.money += mil_pay;
+ nat_budget[sp->shp_own].money += mil_pay;
+
+ if (!player->simulation) {
+ if ((n = feed_ship(sp, etus)) > 0) {
+ wu(0, sp->shp_own, "%d starved on %s\n", n, prship(sp));
+ if (n > 10)
+ nreport(sp->shp_own, N_DIE_FAMINE, 0, 1);
+ }
+ plague_ship(sp, etus);
+ }
+ }
+}
+
+void
+prod_ship(int etus, struct bp *bp, int build)
+ /* build = 1, maintain = 0 */
+{
+ struct shpstr *sp;
+ int i;
+
+ for (i = 0; (sp = getshipp(i)); i++) {
+ if (sp->shp_own == 0)
+ continue;
+ if (bp_skip_unit(bp, (struct empobj *)sp))
+ continue;
upd_ship(sp, etus, bp, build);
}
}
struct budget *budget = &nat_budget[sp->shp_own];
struct mchrstr *mp = &mchr[sp->shp_type];
struct natstr *np = getnatp(sp->shp_own);
- struct sctstr *sectp;
- int pstage, ptime;
- int oil_gained;
- int max_oil;
- int max_food;
- struct pchrstr *product;
- unsigned char *resource;
- int dep;
- int n, mult, eff_lost;
+ int mult, eff_lost;
double cost;
if (build == 1) {
if (!sp->shp_off && budget->money >= 0)
shiprepair(sp, np, bp, etus, budget);
+ ship_produce(sp, etus, budget);
if (!player->simulation)
sp->shp_off = 0;
} else {
+ budget->oldowned_civs += sp->shp_item[I_CIVIL];
mult = 1;
if (np->nat_level[NAT_TLEV] < sp->shp_tech * 0.85)
mult = 2;
budget->bm[BUDG_SHP_MAINT].money -= cost;
budget->money -= cost;
}
+ }
+}
- if (!player->simulation) {
- sectp = getsectp(sp->shp_x, sp->shp_y);
-
- /* produce oil */
- if (budget->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_CIVIL],
- sp->shp_item[I_MILIT],
- sp->shp_item[I_UW],
- ITEM_MAX)
- * sp->shp_effic / 100.0
- * sectp->sct_oil / 100.0
- * prod_eff(SCT_OIL, sp->shp_tech));
- max_oil = mp->m_item[I_OIL];
- if (sp->shp_item[I_OIL] + oil_gained > max_oil)
- oil_gained = max_oil - sp->shp_item[I_OIL];
- if (product->p_nrdep != 0 && oil_gained > 0) {
- resource = (unsigned char *)sectp + product->p_nrndx;
- if (*resource * 100 < product->p_nrdep * oil_gained)
- oil_gained = *resource * 100 / product->p_nrdep;
- dep = roundavg(oil_gained * product->p_nrdep / 100.0);
- if (CANT_HAPPEN(dep > *resource))
- dep = *resource;
- *resource -= dep;
- }
- sp->shp_item[I_OIL] += oil_gained;
- }
- /* produce fish */
- if (budget->money >= 0
- && (mp->m_flags & M_FOOD) && sectp->sct_type == SCT_WATER) {
- sp->shp_item[I_FOOD]
- += roundavg(total_work(100, etus,
- sp->shp_item[I_CIVIL],
- sp->shp_item[I_MILIT],
- sp->shp_item[I_UW],
- ITEM_MAX)
- * sp->shp_effic / 100.0
- * sectp->sct_fertil / 100.0
- * prod_eff(SCT_AGRI, sp->shp_tech));
- }
- /* feed */
- if ((n = feed_ship(sp, etus)) > 0) {
- wu(0, sp->shp_own, "%d starved on %s\n", n, prship(sp));
- if (n > 10)
- nreport(sp->shp_own, N_DIE_FAMINE, 0, 1);
- }
- max_food = mp->m_item[I_FOOD];
- if (sp->shp_item[I_FOOD] > max_food)
- sp->shp_item[I_FOOD] = max_food;
- /*
- * do plague stuff. plague can't break out on ships,
- * but it can still kill people.
- */
- pstage = sp->shp_pstage;
- ptime = sp->shp_ptime;
- if (pstage != PLG_HEALTHY) {
- n = plague_people(np, sp->shp_item, &pstage, &ptime, etus);
- switch (n) {
- case PLG_DYING:
- wu(0, sp->shp_own,
- "PLAGUE deaths reported on %s\n", prship(sp));
- nreport(sp->shp_own, N_DIE_PLAGUE, 0, 1);
- break;
- case PLG_INFECT:
- wu(0, sp->shp_own, "%s battling PLAGUE\n", prship(sp));
- break;
- case PLG_INCUBATE:
- /* Are we still incubating? */
- if (n == pstage) {
- /* Yes. Will it turn "infectious" next time? */
- if (ptime <= etus) {
- /* Yes. Report an outbreak. */
- wu(0, sp->shp_own,
- "Outbreak of PLAGUE on %s!\n", prship(sp));
- nreport(sp->shp_own, N_OUT_PLAGUE, 0, 1);
- }
- } else {
- /* It has already moved on to "infectious" */
- wu(0, sp->shp_own,
- "%s battling PLAGUE\n", prship(sp));
- }
- break;
- case PLG_EXPOSED:
- /* Has the plague moved to "incubation" yet? */
- if (n != pstage) {
- /* Yes. Will it turn "infectious" next time? */
- if (ptime <= etus) {
- /* Yes. Report an outbreak. */
- wu(0, sp->shp_own,
- "Outbreak of PLAGUE on %s!\n", prship(sp));
- nreport(sp->shp_own, N_OUT_PLAGUE, 0, 1);
- }
- }
- break;
- default:
- break;
- }
-
- sp->shp_pstage = pstage;
- sp->shp_ptime = ptime;
- }
- budget->oldowned_civs += sp->shp_item[I_CIVIL];
- }
+static void
+plague_ship(struct shpstr *sp, int etus)
+{
+ struct natstr *np = getnatp(sp->shp_own);
+ int pstage, ptime;
+ int n;
+
+ /* Plague can't break out on ships, but it can still kill people */
+ pstage = sp->shp_pstage;
+ ptime = sp->shp_ptime;
+ if (pstage != PLG_HEALTHY) {
+ n = plague_people(np, sp->shp_item, &pstage, &ptime, etus);
+ if (n != PLG_HEALTHY)
+ plague_report(sp->shp_own, n, pstage, ptime, etus,
+ "on", prship(sp));
+ sp->shp_pstage = pstage;
+ sp->shp_ptime = ptime;
}
}
ship->shp_effic += (signed char)build;
}
+static void
+ship_produce(struct shpstr *sp, int etus, struct budget *budget)
+{
+ struct mchrstr *mp = &mchr[sp->shp_type];
+ struct sctstr *sectp = getsectp(sp->shp_x, sp->shp_y);
+ int oil_gained;
+ int max_oil;
+ int max_food;
+ struct pchrstr *product;
+ unsigned char *resource;
+ int dep;
+
+ if (player->simulation)
+ return;
+
+ /* produce oil */
+ if (!sp->shp_off && budget->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_CIVIL],
+ sp->shp_item[I_MILIT],
+ sp->shp_item[I_UW],
+ ITEM_MAX)
+ * sp->shp_effic / 100.0
+ * sectp->sct_oil / 100.0
+ * prod_eff(SCT_OIL, sp->shp_tech));
+ max_oil = mp->m_item[I_OIL];
+ if (sp->shp_item[I_OIL] + oil_gained > max_oil)
+ oil_gained = max_oil - sp->shp_item[I_OIL];
+ if (product->p_nrdep != 0 && oil_gained > 0) {
+ resource = (unsigned char *)sectp + product->p_nrndx;
+ if (*resource * 100 < product->p_nrdep * oil_gained)
+ oil_gained = *resource * 100 / product->p_nrdep;
+ dep = roundavg(oil_gained * product->p_nrdep / 100.0);
+ if (CANT_HAPPEN(dep > *resource))
+ dep = *resource;
+ *resource -= dep;
+ }
+ sp->shp_item[I_OIL] += oil_gained;
+ }
+ /* produce fish */
+ if (!sp->shp_off && budget->money >= 0
+ && (mp->m_flags & M_FOOD) && sectp->sct_type == SCT_WATER) {
+ sp->shp_item[I_FOOD]
+ += roundavg(total_work(100, etus,
+ sp->shp_item[I_CIVIL],
+ sp->shp_item[I_MILIT],
+ sp->shp_item[I_UW],
+ ITEM_MAX)
+ * sp->shp_effic / 100.0
+ * sectp->sct_fertil / 100.0
+ * prod_eff(SCT_AGRI, sp->shp_tech));
+ }
+ max_food = mp->m_item[I_FOOD];
+ if (sp->shp_item[I_FOOD] > max_food)
+ sp->shp_item[I_FOOD] = max_food;
+}
+
/*
* returns the number who starved, if any.
*/