]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/lndsub.c
Update copyright notice.
[empserver] / src / lib / subs / lndsub.c
index 80f9230a4158d3cf522cdf821cd27136aec16c2a..ad120be637b285cc2cbe704bc87ffd60af654a11 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 #include "optlist.h"
 #include "prototypes.h"
 
-extern int etu_per_update;
-
 int
 attack_val(int combat_mode, struct lndstr *lp)
 {
-    extern double assault_penalty;
     int men;
     int value;
     struct lchrstr *lcp;
@@ -102,7 +99,6 @@ attack_val(int combat_mode, struct lndstr *lp)
 int
 defense_val(struct lndstr *lp)
 {
-    extern int land_mob_max;
     int men;
     double value;
     struct lchrstr *lcp;
@@ -260,7 +256,7 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
                if (sect.sct_type == SCT_MOUNT)
                    continue;
                ++nowned;
-               civs = getvar(V_CIVIL, (s_char *)&sect, EF_SECTOR);
+               civs = sect.sct_item[I_CIVIL];
                if (civs > biggest) {
                    biggest = civs;
                    bx = sect.sct_x;
@@ -315,7 +311,6 @@ lnd_take_casualty(int combat_mode, struct llist *llp, int cas)
 void
 lnd_takemob(struct emp_qelem *list, double loss)
 {
-    extern double combat_mob;
     struct emp_qelem *qp, *next;
     struct llist *llp;
     int new;
@@ -340,22 +335,14 @@ lnd_takemob(struct emp_qelem *list, double loss)
 int
 lnd_getmil(struct lndstr *lp)
 {
-    int vec[I_MAX + 1];
-
-    getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
-    return vec[I_MILIT];
+    return lp->lnd_item[I_MILIT];
 }
 
 void
 lnd_submil(struct lndstr *lp, int num)
 {
-    int vec[I_MAX + 1];
-
-    getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
-    vec[I_MILIT] -= num;
-    if (vec[I_MILIT] < 0)
-       vec[I_MILIT] = 0;
-    putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND);
+    int new = lp->lnd_item[I_MILIT] - num;
+    lp->lnd_item[I_MILIT] = new < 0 ? 0 : new;
 }
 
 int
@@ -713,27 +700,27 @@ lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob,
                               techfact(llp->land.lnd_tech, mobcost));
            llp->mobil -= mobcost;
            llp->land.lnd_mobil = (int)llp->mobil;
+           llp->land.lnd_harden = 0;
        }
        putland(llp->land.lnd_uid, &llp->land);
-       if (!(mines = getvar(V_MINE, (s_char *)&sect, EF_SECTOR)))
+       if (!(mines = sect.sct_mines))
            continue;
-       max = vl_find(V_SHELL, llp->lcp->l_vtype,
-                     llp->lcp->l_vamt, (int)llp->lcp->l_nv);
-       lshells = getvar(V_SHELL, (s_char *)&llp->land, EF_LAND);
-       sshells = getvar(V_SHELL, (s_char *)&sect, EF_SECTOR);
+       max = llp->lcp->l_item[I_SHELL];
+       lshells = llp->land.lnd_item[I_SHELL];
+       sshells = sect.sct_item[I_SHELL];
        for (m = 0; mines > 0 && m < max * 2; m++) {
            if (chance(0.5 * llp->lcp->l_att)) {
                mpr(actor, "Sweep...\n");
                mines--;
                if (lshells < max)
                    ++lshells;
-               else
+               else if (sshells < ITEM_MAX)
                    ++sshells;
            }
        }
-       putvar(V_MINE, mines, (s_char *)&sect, EF_SECTOR);
-       putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND);
-       putvar(V_SHELL, sshells, (s_char *)&sect, EF_SECTOR);
+       sect.sct_mines = mines;
+       llp->land.lnd_item[I_SHELL] = lshells;
+       sect.sct_item[I_SHELL] = sshells;
        putland(llp->land.lnd_uid, &llp->land);
        putsect(&sect);
     }
@@ -762,9 +749,8 @@ lnd_check_mines(struct emp_qelem *land_list)
     struct emp_qelem *next;
     struct llist *llp;
     struct sctstr sect;
-    int mines;
     int stopping = 0;
-    int has_engineers = contains_engineer(land_list);
+    int with_eng = contains_engineer(land_list);
 
     for (qp = land_list->q_back; qp != land_list; qp = next) {
        next = qp->q_back;
@@ -774,12 +760,11 @@ lnd_check_mines(struct emp_qelem *land_list)
            continue;
        if (sect.sct_type == SCT_BSPAN)
            continue;
-       if (!(mines = getvar(V_MINE, (s_char *)&sect, EF_SECTOR)))
+       if (!sect.sct_mines)
            continue;
-       if (chance(DMINE_LHITCHANCE(mines) / (1 + 2 * has_engineers))) {
+       if (chance(DMINE_LHITCHANCE(sect.sct_mines) / (1 + 2 * with_eng))) {
            lnd_hit_mine(&llp->land, llp->lcp);
-           mines--;
-           putvar(V_MINE, mines, (s_char *)&sect, EF_SECTOR);
+           sect.sct_mines--;
            putsect(&sect);
            putland(llp->land.lnd_uid, (s_char *)&llp->land);
            if (!llp->land.lnd_own) {
@@ -799,7 +784,6 @@ lnd_list(struct emp_qelem *land_list)
     struct emp_qelem *next;
     struct llist *llp;
     struct lndstr *lnd;
-    int vec[I_MAX + 1];
 
     pr("lnd#     land type       x,y    a  eff  sh gun xl  mu tech retr fuel\n");
 
@@ -812,9 +796,8 @@ lnd_list(struct emp_qelem *land_list)
        prxy("%4d,%-4d ", lnd->lnd_x, lnd->lnd_y, llp->land.lnd_own);
        pr("%1c", lnd->lnd_army);
        pr("%4d%%", lnd->lnd_effic);
-       getvec(VT_ITEM, vec, (s_char *)lnd, EF_LAND);
-       pr("%4d", vec[I_SHELL]);
-       pr("%4d", vec[I_GUN]);
+       pr("%4d", lnd->lnd_item[I_SHELL]);
+       pr("%4d", lnd->lnd_item[I_GUN]);
        count_land_planes(lnd);
        pr("%3d", lnd->lnd_nxlight);
        pr("%4d", lnd->lnd_mobil);
@@ -936,7 +919,6 @@ static int
 lnd_fort_interdiction(struct emp_qelem *list,
                      coord newx, coord newy, natid victim)
 {
-    extern int fort_max_interdiction_range;
     struct nstr_sect ns;
     struct sctstr fsect;
     int trange;
@@ -956,7 +938,7 @@ lnd_fort_interdiction(struct emp_qelem *list,
            continue;
        if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL)
            continue;
-       gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR);
+       gun = fsect.sct_item[I_GUN];
        if (gun < 1)
            continue;
        range = tfactfire(fsect.sct_own, (double)min(gun, 7));
@@ -966,16 +948,16 @@ lnd_fort_interdiction(struct emp_qelem *list,
        trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
        if (trange > range2)
            continue;
-       if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5)
+       if (fsect.sct_item[I_MILIT] < 5)
            continue;
-       shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR);
+       shell = fsect.sct_item[I_SHELL];
        if (shell < 1)
            shell += supply_commod(fsect.sct_own,
                                   fsect.sct_x, fsect.sct_y, I_SHELL, 1);
        if (shell < 1)
            continue;
        shell--;
-       putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR);
+       fsect.sct_item[I_SHELL] = shell;
        putsect(&fsect);
        if (gun > 7)
            gun = 7;
@@ -1152,9 +1134,9 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
        }
        /* Note we check would_abandon first because we don't want
           to always have to do these checks */
-       if (would_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
+       if (would_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
            stop = 0;
-           if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) {
+           if (!want_to_abandon(&osect, I_CIVIL, 0, &(llp->land))) {
                stop = 1;
            }
            /* now check stuff */
@@ -1183,6 +1165,7 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor,
            llp->mobil -= lnd_mobcost(&llp->land, &sect, MOB_ROAD);
        }
        llp->land.lnd_mobil = (int)llp->mobil;
+       llp->land.lnd_harden = 0;
        putland(llp->land.lnd_uid, &llp->land);
        putsect(&osect);
        getsect(osect.sct_x, osect.sct_y, &osect);
@@ -1256,7 +1239,7 @@ lnd_support(natid victim, natid attacker, coord x, coord y)
        if (land.lnd_effic < LAND_MINFIREEFF)
            continue;
        /* Do we have mil? */
-       if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0)
+       if (land.lnd_item[I_MILIT] <= 0)
            continue;
        rel = getrel(getnatp(land.lnd_own), attacker);
        rel2 = getrel(getnatp(land.lnd_own), victim);
@@ -1277,8 +1260,8 @@ lnd_support(natid victim, natid attacker, coord x, coord y)
        if (dist > range2)
            continue;
 
-       shell = getvar(V_SHELL, (s_char *)&land, EF_LAND);
-       gun = getvar(V_GUN, (s_char *)&land, EF_LAND);
+       shell = land.lnd_item[I_SHELL];
+       gun = land.lnd_item[I_GUN];
 
        if (shell == 0 || gun == 0)
            continue;
@@ -1358,16 +1341,18 @@ lnd_can_attack(struct lndstr *lp)
 int
 lnd_fortify (struct lndstr *lp, int hard_amt)
 {
-    extern int land_mob_max;
     int mob_used;
     int eng;
 
+    if ((lp->lnd_ship >= 0) || lp->lnd_land >= 0)
+       return 0;
+
     hard_amt = min(lp->lnd_mobil, hard_amt);
 
     if ((lp->lnd_harden + hard_amt) > land_mob_max)
        hard_amt = land_mob_max - lp->lnd_harden;
 
-    eng = is_engineer(lp->lnd_x, lp->lnd_y);
+    eng = has_helpful_engineer(lp->lnd_x, lp->lnd_y, lp->lnd_own);
 
     if (eng)
        hard_amt = ((float)hard_amt * 1.5);
@@ -1397,3 +1382,36 @@ lnd_fortify (struct lndstr *lp, int hard_amt)
 
     return hard_amt;
 }
+
+/*
+ * Set LP's tech to TLEV along with everything else that depends on it.
+ */
+void
+lnd_set_tech(struct lndstr *lp, int tlev)
+{
+    struct lchrstr *lcp = lchr + lp->lnd_type;
+    int tech_diff = tlev - lcp->l_tech;
+
+    if (CANT_HAPPEN(tech_diff < 0)) {
+      tlev -= tech_diff;
+      tech_diff = 0;
+    }
+
+    lp->lnd_tech = tlev;
+    lp->lnd_att = (float)LND_ATTDEF(lcp->l_att, tech_diff);
+    lp->lnd_def = (float)LND_ATTDEF(lcp->l_def, tech_diff);
+    lp->lnd_vul = (int)LND_VUL(lcp->l_vul, tech_diff);
+    lp->lnd_spd = (int)LND_SPD(lcp->l_spd, tech_diff);
+    lp->lnd_vis = (int)LND_VIS(lcp->l_vis, tech_diff);
+    lp->lnd_spy = (int)LND_SPY(lcp->l_spy, tech_diff);
+    lp->lnd_rad = (int)LND_RAD(lcp->l_rad, tech_diff);
+    lp->lnd_frg = (int)LND_FRG(lcp->l_frg, tech_diff);
+    lp->lnd_acc = (int)LND_ACC(lcp->l_acc, tech_diff);
+    lp->lnd_dam = (int)LND_DAM(lcp->l_dam, tech_diff);
+    lp->lnd_ammo = (int)LND_AMM(lcp->l_ammo, lcp->l_dam, tech_diff);
+    lp->lnd_aaf = (int)LND_AAF(lcp->l_aaf, tech_diff);
+    lp->lnd_fuelc = (int)LND_FC(lcp->l_fuelc, tech_diff);
+    lp->lnd_fuelu = (int)LND_FU(lcp->l_fuelu, tech_diff);
+    lp->lnd_maxlight = (int)LND_XPL(lcp->l_nxlight, tech_diff);
+    lp->lnd_maxland = (int)LND_MXL(lcp->l_mxland, tech_diff);
+}