00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "item.h"
00037 #include "land.h"
00038 #include "nsc.h"
00039 #include "path.h"
00040 #include "plague.h"
00041 #include "plane.h"
00042 #include "ship.h"
00043 #include "update.h"
00044
00045
00046
00047
00048
00049
00050 int
00051 load_it(struct shpstr *sp, struct sctstr *psect, int i)
00052 {
00053 int shipown, amount, ship_amt, sect_amt;
00054 int abs_max, max_amt, transfer;
00055 i_type comm;
00056 struct mchrstr *vship;
00057
00058 amount = sp->shp_lend[i];
00059 shipown = sp->shp_own;
00060 comm = sp->shp_tend[i];
00061 if (CANT_HAPPEN(comm <= I_NONE || comm > I_MAX))
00062 return 0;
00063
00064 ship_amt = sp->shp_item[comm];
00065 sect_amt = psect->sct_item[comm];
00066
00067
00068 if (psect->sct_oldown != shipown && comm == I_CIVIL) {
00069 wu(0, shipown,
00070 "Ship #%d - unable to load disloyal civilians at %s.",
00071 sp->shp_uid, xyas(psect->sct_x, psect->sct_y, psect->sct_own));
00072 return 0;
00073 }
00074 if (comm == I_CIVIL || comm == I_MILIT)
00075 sect_amt--;
00076 vship = &mchr[(int)sp->shp_type];
00077 abs_max = max_amt = vship->m_item[comm];
00078
00079 if (!abs_max)
00080 return 0;
00081
00082 max_amt = MIN(sect_amt, max_amt - ship_amt);
00083 if (max_amt <= 0 && (ship_amt != abs_max)) {
00084 sp->shp_autonav |= AN_LOADING;
00085 return 0;
00086 }
00087
00088
00089 transfer = amount - ship_amt;
00090 if (transfer > sect_amt) {
00091 transfer = sect_amt;
00092 sp->shp_autonav |= AN_LOADING;
00093 }
00094 if (ship_amt + transfer > abs_max)
00095 transfer = abs_max - ship_amt;
00096
00097
00098 if (transfer <= 0)
00099 return 0;
00100
00101
00102 sp->shp_item[comm] = ship_amt + transfer;
00103 if (comm == I_CIVIL || comm == I_MILIT)
00104 sect_amt++;
00105 psect->sct_item[comm] = sect_amt - transfer;
00106
00107
00108 if (psect->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
00109 sp->shp_pstage = PLG_EXPOSED;
00110 if (sp->shp_pstage == PLG_INFECT && psect->sct_pstage == PLG_HEALTHY)
00111 psect->sct_pstage = PLG_EXPOSED;
00112
00113 return 1;
00114
00115
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void
00127 unload_it(struct shpstr *sp)
00128 {
00129 struct sctstr *sectp;
00130 int i;
00131 int landowner;
00132 int shipown;
00133 i_type comm;
00134 int sect_amt;
00135 int ship_amt;
00136 int max_amt;
00137
00138 sectp = getsectp(sp->shp_x, sp->shp_y);
00139
00140 landowner = sectp->sct_own;
00141 shipown = sp->shp_own;
00142
00143 for (i = 0; i < TMAX; ++i) {
00144 if (sp->shp_tend[i] == I_NONE || sp->shp_lend[i] == 0)
00145 continue;
00146 if (landowner == 0)
00147 continue;
00148 if (sectp->sct_type != SCT_HARBR)
00149 continue;
00150
00151 comm = sp->shp_tend[i];
00152 if (CANT_HAPPEN(comm <= I_NONE || comm > I_MAX))
00153 continue;
00154 ship_amt = sp->shp_item[comm];
00155 sect_amt = sectp->sct_item[comm];
00156
00157
00158 if (sectp->sct_oldown != shipown && comm == I_CIVIL) {
00159 wu(0, sp->shp_own,
00160 "Ship #%d - unable to unload civilians into a disloyal sector at %s.",
00161 sp->shp_uid, xyas(sectp->sct_x, sectp->sct_y,
00162 sectp->sct_own));
00163 continue;
00164 }
00165 if (comm == I_CIVIL)
00166 ship_amt--;
00167
00168 max_amt = MIN(ship_amt, ITEM_MAX - sect_amt);
00169 if (max_amt <= 0)
00170 continue;
00171
00172 sp->shp_item[comm] = ship_amt - max_amt;
00173 sectp->sct_item[comm] = sect_amt + max_amt;
00174
00175 if (sectp->sct_pstage == PLG_INFECT && sp->shp_pstage == PLG_HEALTHY)
00176 sp->shp_pstage = PLG_EXPOSED;
00177 if (sp->shp_pstage == PLG_INFECT && sectp->sct_pstage == PLG_HEALTHY)
00178 sectp->sct_pstage = PLG_EXPOSED;
00179 }
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 void
00191 auto_fuel_ship(struct shpstr *sp)
00192 {
00193 double d;
00194 int totalfuel = 0;
00195 int need;
00196 int maxfuel;
00197 int newfuel = 0;
00198 int add_fuel = 0;
00199
00200 if (opt_FUEL == 0)
00201 return;
00202 getship(sp->shp_uid, sp);
00203
00204 maxfuel = mchr[(int)sp->shp_type].m_fuelc;
00205 d = maxfuel / 5.0;
00206 if (d - (int)d > 0.0)
00207 d++;
00208 need = (int)d;
00209
00210 newfuel = supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
00211 I_PETROL, need);
00212 add_fuel += newfuel * 5;
00213 if (add_fuel > maxfuel)
00214 add_fuel = maxfuel;
00215 sp->shp_fuel += add_fuel;
00216 totalfuel += add_fuel;
00217
00218 if (totalfuel == maxfuel) {
00219 putship(sp->shp_uid, sp);
00220 return;
00221 }
00222 add_fuel = 0;
00223
00224 d = (maxfuel - totalfuel) / 50.0;
00225 if (d - (int)d > 0.0)
00226 d++;
00227 need = (int)d;
00228
00229 newfuel = supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
00230 I_OIL, need);
00231 add_fuel = newfuel * 50;
00232 if (add_fuel > maxfuel)
00233 add_fuel = maxfuel;
00234 sp->shp_fuel += add_fuel;
00235 putship(sp->shp_uid, sp);
00236 }