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
00035
00036 #include <config.h>
00037
00038 #include "empobj.h"
00039 #include "file.h"
00040 #include "item.h"
00041 #include "land.h"
00042 #include "loan.h"
00043 #include "misc.h"
00044 #include "nat.h"
00045 #include "nsc.h"
00046 #include "nuke.h"
00047 #include "optlist.h"
00048 #include "plane.h"
00049 #include "player.h"
00050 #include "prototypes.h"
00051 #include "sect.h"
00052 #include "ship.h"
00053 #include "trade.h"
00054 #include "xy.h"
00055
00056 int
00057 trade_check_ok(struct trdstr *tp, union empobj_storage *tgp)
00058 {
00059 return check_trade_ok(tp) && trade_check_item_ok(tgp);
00060 }
00061
00062 int
00063 trade_check_item_ok(union empobj_storage *tgp)
00064 {
00065 if (tgp->gen.ef_type == EF_LAND)
00066 return check_land_ok(&tgp->land);
00067 if (tgp->gen.ef_type == EF_PLANE)
00068 return check_plane_ok(&tgp->plane);
00069 if (tgp->gen.ef_type == EF_SHIP)
00070 return check_ship_ok(&tgp->ship);
00071 if (tgp->gen.ef_type == EF_NUKE)
00072 return check_nuke_ok(&tgp->nuke);
00073 CANT_REACH();
00074 pr("Trade lot went bad!\n");
00075 return 0;
00076 }
00077
00078 char *
00079 trade_nameof(struct trdstr *tp, union empobj_storage *tgp)
00080 {
00081 switch (tp->trd_type) {
00082 case EF_NUKE:
00083 return nchr[(int)tgp->nuke.nuk_type].n_name;
00084 case EF_PLANE:
00085 return plchr[(int)tgp->plane.pln_type].pl_name;
00086 case EF_SHIP:
00087 return mchr[(int)tgp->ship.shp_type].m_name;
00088 case EF_LAND:
00089 return lchr[(int)tgp->land.lnd_type].l_name;
00090 }
00091 return "Bad trade type, get help";
00092 }
00093
00094
00095
00096
00097
00098
00099 int
00100 trade_desc(struct trdstr *tp, union empobj_storage *tgp)
00101 {
00102 i_type it;
00103 struct sctstr sect;
00104 struct nukstr *np;
00105 struct shpstr *sp;
00106 struct plnstr *pp;
00107 struct lndstr *lp;
00108 struct nstr_item ni;
00109 struct plnstr plane;
00110 struct lndstr land;
00111
00112 switch (tp->trd_type) {
00113 case EF_NUKE:
00114 np = &tgp->nuke;
00115 tp->trd_owner = np->nuk_own;
00116 pr("(%3d) tech %d %d%% %s #%d",
00117 tp->trd_owner, np->nuk_tech, np->nuk_effic,
00118 nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
00119 break;
00120 case EF_SHIP:
00121 sp = &tgp->ship;
00122 tp->trd_owner = sp->shp_own;
00123 pr("(%3d) tech %d %d%% %s [",
00124 tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
00125
00126 for (it = I_NONE + 1; it <= I_MAX; ++it) {
00127 if (sp->shp_item[it])
00128 pr("%c:%d ", ichr[it].i_mnem, sp->shp_item[it]);
00129 }
00130 pr("] #%d", tp->trd_unitid);
00131 if (opt_SHOWPLANE) {
00132 snxtitem_all(&ni, EF_PLANE);
00133 while (nxtitem(&ni, &plane)) {
00134 if (plane.pln_ship == sp->shp_uid && plane.pln_own != 0) {
00135 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
00136 plane.pln_tech,
00137 plane.pln_effic,
00138 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
00139 if (plane.pln_nuketype != -1) {
00140 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
00141 }
00142 }
00143 }
00144 snxtitem_all(&ni, EF_LAND);
00145 while (nxtitem(&ni, &land)) {
00146 if (land.lnd_ship == sp->shp_uid && land.lnd_own != 0) {
00147 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
00148 land.lnd_tech,
00149 land.lnd_effic,
00150 lchr[(int)land.lnd_type].l_name, land.lnd_uid);
00151 if (land.lnd_nxlight) {
00152 snxtitem_all(&ni, EF_PLANE);
00153 while (nxtitem(&ni, &plane)) {
00154 if (plane.pln_land == land.lnd_uid) {
00155 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
00156 plane.pln_tech,
00157 plane.pln_effic,
00158 plchr[(int)plane.pln_type].pl_name,
00159 plane.pln_uid);
00160 if (plane.pln_nuketype != -1) {
00161 pr("(%s)",
00162 nchr[(int)plane.pln_nuketype].n_name);
00163 }
00164 }
00165 }
00166 }
00167 }
00168 }
00169 }
00170 getsect(sp->shp_x, sp->shp_y, §);
00171 if (sect.sct_type != SCT_WATER)
00172 pr(" in a %s %s",
00173 cname(sect.sct_own), dchr[sect.sct_type].d_name);
00174 else
00175 pr(" at sea");
00176 break;
00177 case EF_LAND:
00178 lp = &tgp->land;
00179 tp->trd_owner = lp->lnd_own;
00180 pr("(%3d) tech %d %d%% %s [",
00181 tp->trd_owner,
00182 lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
00183 for (it = I_NONE + 1; it <= I_MAX; ++it) {
00184 if (lp->lnd_item[it])
00185 pr("%c:%d ", ichr[it].i_mnem, lp->lnd_item[it]);
00186 }
00187 pr("] #%d", tp->trd_unitid);
00188 if (opt_SHOWPLANE) {
00189 snxtitem_all(&ni, EF_PLANE);
00190 while (nxtitem(&ni, &plane)) {
00191 if (plane.pln_land == lp->lnd_uid && plane.pln_own != 0) {
00192 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
00193 plane.pln_tech,
00194 plane.pln_effic,
00195 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
00196 if (plane.pln_nuketype != -1) {
00197 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
00198 }
00199 }
00200 }
00201 }
00202 getsect(lp->lnd_x, lp->lnd_y, §);
00203 break;
00204 case EF_PLANE:
00205 pp = &tgp->plane;
00206 tp->trd_owner = pp->pln_own;
00207 pr("(%3d) tech %d %d%% %s #%d",
00208 tp->trd_owner,
00209 pp->pln_tech,
00210 pp->pln_effic,
00211 plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
00212 if (pp->pln_nuketype != -1) {
00213 pr("(%s)", nchr[(int)pp->pln_nuketype].n_name);
00214 }
00215 break;
00216 default:
00217 pr("flaky unit type %d", tp->trd_type);
00218 break;
00219 }
00220 return 1;
00221 }
00222
00223 int
00224 trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
00225 {
00226 if (!ef_read(tp->trd_type, tp->trd_unitid, tgp))
00227 return 0;
00228 return 1;
00229 }
00230
00231
00232
00233
00234 double
00235 loan_owed(struct lonstr *loan, time_t paytime)
00236 {
00237 time_t rtime;
00238 time_t xtime;
00239 double rate;
00240 int dur;
00241
00242
00243
00244
00245
00246 rtime = loan->l_duedate - loan->l_lastpay;
00247 xtime = paytime - loan->l_duedate;
00248 if (rtime < 0) {
00249 xtime += rtime;
00250 rtime = 0;
00251 }
00252 if (xtime < 0) {
00253 rtime += xtime;
00254 xtime = 0;
00255 }
00256 if (CANT_HAPPEN(rtime < 0))
00257 rtime = 0;
00258
00259 dur = loan->l_ldur;
00260 if (CANT_HAPPEN(dur <= 0))
00261 dur = 1;
00262 rate = loan->l_irate / 100.0 / (dur * SECS_PER_DAY);
00263
00264 return loan->l_amtdue * (1.0 + (rtime + xtime * 2) * rate);
00265 }