From 9b7adfbecc6b6916999adf65302af61f6b0d28cb Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 2 Sep 2003 20:48:48 +0000 Subject: [PATCH] Indented with src/scripts/indent-emp. --- include/bit.h | 24 +- include/com.h | 14 +- include/combat.h | 95 +- include/commands.h | 2 +- include/commodity.h | 26 +- include/common.h | 22 +- include/deity.h | 6 +- include/empio.h | 46 +- include/empthread.h | 37 +- include/event.h | 18 +- include/file.h | 90 +- include/gen.h | 10 +- include/genitem.h | 38 +- include/global.h | 2 +- include/io_mask.h | 24 +- include/ioqueue.h | 16 +- include/item.h | 24 +- include/keyword.h | 10 +- include/land.h | 245 +- include/loan.h | 26 +- include/lost.h | 23 +- include/lwp.h | 98 +- include/map.h | 22 +- include/misc.h | 77 +- include/mission.h | 28 +- include/nat.h | 162 +- include/news.h | 30 +- include/nsc.h | 120 +- include/nuke.h | 48 +- include/options.h | 108 +- include/optlist.h | 22 +- include/path.h | 43 +- include/plane.h | 218 +- include/player.h | 72 +- include/power.h | 36 +- include/product.h | 34 +- include/prototypes.h | 1450 ++++++------ include/queue.h | 10 +- include/sect.h | 140 +- include/ship.h | 183 +- include/subs.h | 2 +- include/tel.h | 16 +- include/trade.h | 48 +- include/treaty.h | 32 +- include/update.h | 2 +- include/user.h | 14 +- include/xy.h | 25 +- src/client/bit.c | 228 +- src/client/bit.h | 6 +- src/client/dtable.c | 26 +- src/client/expect.c | 185 +- src/client/fnlist.h | 11 +- src/client/globals.c | 20 +- src/client/handle.c | 18 +- src/client/host.c | 108 +- src/client/hpux.c | 62 +- src/client/ioqueue.c | 304 +-- src/client/ioqueue.h | 15 +- src/client/login.c | 141 +- src/client/main.c | 412 ++-- src/client/misc.h | 58 +- src/client/queue.c | 42 +- src/client/queue.h | 6 +- src/client/saveargv.c | 26 +- src/client/servcmd.c | 505 ++-- src/client/serverio.c | 55 +- src/client/tags.c | 49 +- src/client/tags.h | 4 +- src/client/termio.c | 350 +-- src/client/termlib.c | 72 +- src/doconfig/doconfig.c | 164 +- src/lib/as/as.h | 149 +- src/lib/as/as_cache.c | 8 +- src/lib/as/as_costcomp.c | 30 +- src/lib/as/as_delete.c | 54 +- src/lib/as/as_extend.c | 68 +- src/lib/as/as_hash.c | 52 +- src/lib/as/as_init.c | 46 +- src/lib/as/as_merge.c | 97 +- src/lib/as/as_search.c | 155 +- src/lib/as/as_stats.c | 82 +- src/lib/as/as_winnow.c | 195 +- src/lib/commands/acce.c | 74 +- src/lib/commands/add.c | 339 +-- src/lib/commands/anti.c | 63 +- src/lib/commands/arm.c | 206 +- src/lib/commands/army.c | 75 +- src/lib/commands/assa.c | 318 +-- src/lib/commands/atta.c | 215 +- src/lib/commands/bdes.c | 52 +- src/lib/commands/best.c | 66 +- src/lib/commands/boar.c | 226 +- src/lib/commands/bomb.c | 1720 +++++++------- src/lib/commands/brea.c | 24 +- src/lib/commands/budg.c | 596 ++--- src/lib/commands/buil.c | 556 ++--- src/lib/commands/buy.c | 130 +- src/lib/commands/capi.c | 56 +- src/lib/commands/carg.c | 184 +- src/lib/commands/cede.c | 612 +++-- src/lib/commands/cens.c | 215 +- src/lib/commands/chan.c | 167 +- src/lib/commands/coas.c | 220 +- src/lib/commands/coll.c | 236 +- src/lib/commands/comm.c | 26 +- src/lib/commands/cons.c | 485 ++-- src/lib/commands/conv.c | 231 +- src/lib/commands/coun.c | 96 +- src/lib/commands/cuto.c | 132 +- src/lib/commands/decl.c | 134 +- src/lib/commands/deli.c | 31 +- src/lib/commands/demo.c | 158 +- src/lib/commands/desi.c | 356 +-- src/lib/commands/disa.c | 14 +- src/lib/commands/diss.c | 405 ++-- src/lib/commands/dist.c | 159 +- src/lib/commands/drop.c | 199 +- src/lib/commands/dump.c | 1136 +++++---- src/lib/commands/echo.c | 4 +- src/lib/commands/edit.c | 1998 ++++++++-------- src/lib/commands/enab.c | 8 +- src/lib/commands/enli.c | 189 +- src/lib/commands/expl.c | 531 +++-- src/lib/commands/fina.c | 120 +- src/lib/commands/flash.c | 256 +-- src/lib/commands/flee.c | 74 +- src/lib/commands/fly.c | 199 +- src/lib/commands/foll.c | 119 +- src/lib/commands/forc.c | 56 +- src/lib/commands/fort.c | 201 +- src/lib/commands/fuel.c | 883 +++---- src/lib/commands/give.c | 96 +- src/lib/commands/grin.c | 89 +- src/lib/commands/hard.c | 129 +- src/lib/commands/head.c | 357 +-- src/lib/commands/hidd.c | 79 +- src/lib/commands/improve.c | 34 +- src/lib/commands/info.c | 746 +++--- src/lib/commands/land.c | 127 +- src/lib/commands/laun.c | 687 +++--- src/lib/commands/lboard.c | 62 +- src/lib/commands/ldump.c | 631 +++-- src/lib/commands/ledg.c | 40 +- src/lib/commands/leve.c | 94 +- src/lib/commands/load.c | 1800 +++++++-------- src/lib/commands/look.c | 470 ++-- src/lib/commands/lost.c | 2 +- src/lib/commands/lstat.c | 96 +- src/lib/commands/lten.c | 215 +- src/lib/commands/map.c | 189 +- src/lib/commands/marc.c | 262 ++- src/lib/commands/mark.c | 41 +- src/lib/commands/mfir.c | 1757 +++++++------- src/lib/commands/mine.c | 216 +- src/lib/commands/miss.c | 523 +++-- src/lib/commands/mobq.c | 131 +- src/lib/commands/mobu.c | 118 +- src/lib/commands/mora.c | 64 +- src/lib/commands/move.c | 637 +++-- src/lib/commands/mult.c | 120 +- src/lib/commands/name.c | 53 +- src/lib/commands/nati.c | 143 +- src/lib/commands/navi.c | 119 +- src/lib/commands/ndump.c | 81 +- src/lib/commands/new.c | 586 ++--- src/lib/commands/newe.c | 232 +- src/lib/commands/news.c | 298 +-- src/lib/commands/nuke.c | 110 +- src/lib/commands/offe.c | 362 +-- src/lib/commands/offs.c | 68 +- src/lib/commands/orde.c | 853 +++---- src/lib/commands/orig.c | 39 +- src/lib/commands/para.c | 295 +-- src/lib/commands/path.c | 146 +- src/lib/commands/payo.c | 140 +- src/lib/commands/pboa.c | 8 +- src/lib/commands/pdump.c | 406 ++-- src/lib/commands/plan.c | 107 +- src/lib/commands/play.c | 123 +- src/lib/commands/powe.c | 625 ++--- src/lib/commands/prod.c | 245 +- src/lib/commands/pstat.c | 79 +- src/lib/commands/rada.c | 186 +- src/lib/commands/rang.c | 97 +- src/lib/commands/rea.c | 335 ++- src/lib/commands/real.c | 93 +- src/lib/commands/reco.c | 185 +- src/lib/commands/reje.c | 140 +- src/lib/commands/rela.c | 88 +- src/lib/commands/repa.c | 194 +- src/lib/commands/repo.c | 351 +-- src/lib/commands/rese.c | 28 +- src/lib/commands/reso.c | 98 +- src/lib/commands/retr.c | 478 ++-- src/lib/commands/rout.c | 172 +- src/lib/commands/sabo.c | 132 +- src/lib/commands/sail.c | 212 +- src/lib/commands/sate.c | 106 +- src/lib/commands/scra.c | 520 ++--- src/lib/commands/scut.c | 409 ++-- src/lib/commands/sdump.c | 562 +++-- src/lib/commands/sect.c | 162 +- src/lib/commands/sell.c | 259 ++- src/lib/commands/set.c | 246 +- src/lib/commands/setres.c | 215 +- src/lib/commands/setsect.c | 611 +++-- src/lib/commands/shar.c | 57 +- src/lib/commands/shark.c | 151 +- src/lib/commands/shi.c | 129 +- src/lib/commands/shoo.c | 159 +- src/lib/commands/show.c | 150 +- src/lib/commands/shut.c | 103 +- src/lib/commands/sinf.c | 18 +- src/lib/commands/skyw.c | 216 +- src/lib/commands/sona.c | 595 +++-- src/lib/commands/spy.c | 431 ++-- src/lib/commands/sstat.c | 80 +- src/lib/commands/star.c | 82 +- src/lib/commands/stop.c | 82 +- src/lib/commands/stre.c | 177 +- src/lib/commands/strv.c | 328 ++- src/lib/commands/supp.c | 52 +- src/lib/commands/surv.c | 199 +- src/lib/commands/swap.c | 97 +- src/lib/commands/tele.c | 154 +- src/lib/commands/tend.c | 570 ++--- src/lib/commands/terr.c | 36 +- src/lib/commands/thre.c | 27 +- src/lib/commands/togg.c | 138 +- src/lib/commands/torp.c | 704 +++--- src/lib/commands/trad.c | 381 +-- src/lib/commands/tran.c | 473 ++-- src/lib/commands/trea.c | 32 +- src/lib/commands/turn.c | 70 +- src/lib/commands/upda.c | 251 +- src/lib/commands/upgr.c | 559 +++-- src/lib/commands/vers.c | 383 ++- src/lib/commands/wai.c | 32 +- src/lib/commands/wing.c | 52 +- src/lib/commands/wipe.c | 30 +- src/lib/commands/work.c | 246 +- src/lib/commands/zdon.c | 139 +- src/lib/common/bestpath.c | 330 ++- src/lib/common/bridgefall.c | 215 +- src/lib/common/check.c | 6 +- src/lib/common/damage.c | 180 +- src/lib/common/file.c | 585 ++--- src/lib/common/fsize.c | 30 +- src/lib/common/getvar.c | 112 +- src/lib/common/hap_fact.c | 21 +- src/lib/common/hours.c | 76 +- src/lib/common/keyword.c | 229 +- src/lib/common/land.c | 68 +- src/lib/common/log.c | 140 +- src/lib/common/mailbox.c | 6 +- src/lib/common/maps.c | 564 ++--- src/lib/common/move.c | 11 +- src/lib/common/nat.c | 126 +- src/lib/common/nstr_subs.c | 173 +- src/lib/common/path.c | 517 ++--- src/lib/common/res_pop.c | 36 +- src/lib/common/sectdamage.c | 133 +- src/lib/common/snxtit_subs.c | 157 +- src/lib/common/snxtsct_subs.c | 150 +- src/lib/common/stmtch.c | 46 +- src/lib/common/tfact.c | 36 +- src/lib/common/type.c | 96 +- src/lib/common/vlist.c | 375 +-- src/lib/common/wantupd.c | 500 ++-- src/lib/common/xy.c | 175 +- src/lib/empthread/lwp.c | 31 +- src/lib/empthread/ntthread.c | 347 ++- src/lib/empthread/pthread.c | 241 +- src/lib/gen/atoip.c | 39 +- src/lib/gen/atopi.c | 18 +- src/lib/gen/bit.c | 198 +- src/lib/gen/chance.c | 34 +- src/lib/gen/copy.c | 31 +- src/lib/gen/disassoc.c | 30 +- src/lib/gen/dtable.c | 22 +- src/lib/gen/emp_config.c | 916 ++++---- src/lib/gen/getstarg.c | 18 +- src/lib/gen/getstring.c | 8 +- src/lib/gen/hpux.c | 60 +- src/lib/gen/iceil.c | 12 +- src/lib/gen/inet.c | 12 +- src/lib/gen/io.c | 556 +++-- src/lib/gen/io_mask.c | 99 +- src/lib/gen/ioqueue.c | 473 ++-- src/lib/gen/lock.c | 80 +- src/lib/gen/mapdist.c | 82 +- src/lib/gen/minmax.c | 24 +- src/lib/gen/numstr.c | 44 +- src/lib/gen/onearg.c | 22 +- src/lib/gen/parse.c | 93 +- src/lib/gen/plur.c | 8 +- src/lib/gen/queue.c | 29 +- src/lib/gen/round.c | 12 +- src/lib/gen/same.c | 10 +- src/lib/gen/scthash.c | 10 +- src/lib/gen/signal.c | 74 +- src/lib/gen/strdup.c | 12 +- src/lib/gen/strscan.c | 26 +- src/lib/gen/vsprintf.c | 161 +- src/lib/global/constants.c | 219 +- src/lib/global/dir.c | 46 +- src/lib/global/file.c | 84 +- src/lib/global/init.c | 36 +- src/lib/global/item.c | 36 +- src/lib/global/land.c | 375 +-- src/lib/global/misc.c | 51 +- src/lib/global/news.c | 378 +-- src/lib/global/nsc.c | 471 ++-- src/lib/global/nuke.c | 34 +- src/lib/global/numnames.c | 20 +- src/lib/global/options.c | 102 +- src/lib/global/path.c | 40 +- src/lib/global/plane.c | 552 ++--- src/lib/global/product.c | 110 +- src/lib/global/sect.c | 89 +- src/lib/global/ship.c | 560 ++--- src/lib/global/treaty.c | 28 +- src/lib/lwp/arch.c | 405 ++-- src/lib/lwp/lwp.c | 822 +++---- src/lib/lwp/lwpint.h | 37 +- src/lib/lwp/misc/echo.c | 163 +- src/lib/lwp/misc/lwp.h | 69 +- src/lib/lwp/queue.c | 32 +- src/lib/lwp/sel.c | 339 +-- src/lib/lwp/sem.c | 65 +- src/lib/lwp/status.c | 43 +- src/lib/player/accept.c | 279 +-- src/lib/player/dispatch.c | 116 +- src/lib/player/empdis.c | 235 +- src/lib/player/empmod.c | 778 ++++--- src/lib/player/init_nats.c | 146 +- src/lib/player/login.c | 374 ++- src/lib/player/nat.c | 32 +- src/lib/player/player.c | 593 +++-- src/lib/player/recvclient.c | 48 +- src/lib/subs/aircombat.c | 1992 ++++++++-------- src/lib/subs/askyn.c | 38 +- src/lib/subs/aswplnsubs.c | 172 +- src/lib/subs/attsub.c | 4091 +++++++++++++++++---------------- src/lib/subs/bigmap.c | 68 +- src/lib/subs/border.c | 98 +- src/lib/subs/bsanct.c | 52 +- src/lib/subs/caploss.c | 136 +- src/lib/subs/chkmoney.c | 60 +- src/lib/subs/cnumb.c | 42 +- src/lib/subs/comsub.c | 105 +- src/lib/subs/control.c | 26 +- src/lib/subs/detonate.c | 485 ++-- src/lib/subs/disloan.c | 112 +- src/lib/subs/distrea.c | 92 +- src/lib/subs/fileinit.c | 80 +- src/lib/subs/fortdef.c | 348 +-- src/lib/subs/getbit.c | 150 +- src/lib/subs/getele.c | 124 +- src/lib/subs/land.c | 182 +- src/lib/subs/landgun.c | 52 +- src/lib/subs/list.c | 407 ++-- src/lib/subs/lndsub.c | 1992 ++++++++-------- src/lib/subs/lostsub.c | 12 +- src/lib/subs/mission.c | 2593 ++++++++++----------- src/lib/subs/move.c | 593 ++--- src/lib/subs/mslsub.c | 644 +++--- src/lib/subs/mtch.c | 54 +- src/lib/subs/natarg.c | 62 +- src/lib/subs/neigh.c | 16 +- src/lib/subs/nreport.c | 206 +- src/lib/subs/nstr.c | 182 +- src/lib/subs/nuke.c | 142 +- src/lib/subs/nxtitem.c | 130 +- src/lib/subs/nxtsct.c | 60 +- src/lib/subs/paths.c | 397 ++-- src/lib/subs/plane.c | 140 +- src/lib/subs/plnsub.c | 1939 ++++++++-------- src/lib/subs/pr.c | 336 +-- src/lib/subs/radmap.c | 242 +- src/lib/subs/rej.c | 200 +- src/lib/subs/retreat.c | 917 ++++---- src/lib/subs/sarg.c | 252 +- src/lib/subs/satmap.c | 528 +++-- src/lib/subs/sect.c | 155 +- src/lib/subs/ship.c | 105 +- src/lib/subs/show.c | 1053 +++++---- src/lib/subs/shpsub.c | 964 ++++---- src/lib/subs/snxtitem.c | 147 +- src/lib/subs/snxtsct.c | 80 +- src/lib/subs/supply.c | 557 ++--- src/lib/subs/takeover.c | 122 +- src/lib/subs/trdsub.c | 319 ++- src/lib/subs/trechk.c | 154 +- src/lib/subs/whatitem.c | 22 +- src/lib/subs/wire.c | 75 +- src/lib/subs/wu.c | 218 +- src/lib/update/age.c | 105 +- src/lib/update/anno.c | 151 +- src/lib/update/bp.c | 68 +- src/lib/update/deliver.c | 145 +- src/lib/update/distribute.c | 329 +-- src/lib/update/finish.c | 186 +- src/lib/update/human.c | 168 +- src/lib/update/land.c | 660 +++--- src/lib/update/main.c | 344 ++- src/lib/update/material.c | 74 +- src/lib/update/mobility.c | 647 +++--- src/lib/update/move_sat.c | 21 +- src/lib/update/nat.c | 381 ++- src/lib/update/nav_ship.c | 415 ++-- src/lib/update/nav_util.c | 409 ++-- src/lib/update/nxtitemp.c | 126 +- src/lib/update/nxtsctp.c | 50 +- src/lib/update/plague.c | 244 +- src/lib/update/plane.c | 398 ++-- src/lib/update/populace.c | 162 +- src/lib/update/prepare.c | 150 +- src/lib/update/produce.c | 333 +-- src/lib/update/removewants.c | 18 +- src/lib/update/revolt.c | 701 +++--- src/lib/update/sail.c | 466 ++-- src/lib/update/sect.c | 742 +++--- src/lib/update/ship.c | 841 ++++--- src/server/idle.c | 68 +- src/server/lostitem.c | 15 +- src/server/main.c | 357 ++- src/server/marketup.c | 13 +- src/server/shutdown.c | 82 +- src/server/timestamp.c | 152 +- src/server/update.c | 185 +- src/util/fairland.c | 1619 ++++++------- src/util/files.c | 269 +-- src/util/land.c | 529 +++-- src/util/ore.c | 560 ++--- src/util/pconfig.c | 13 +- src/util/perfect.c | 366 +-- 437 files changed, 52678 insertions(+), 51519 deletions(-) diff --git a/include/bit.h b/include/bit.h index de0eaf68d..079b12eea 100644 --- a/include/bit.h +++ b/include/bit.h @@ -34,8 +34,8 @@ #ifndef _BIT_H_ #define _BIT_H_ -typedef unsigned int bit_mask; -typedef bit_mask *bit_fdmask; +typedef unsigned int bit_mask; +typedef bit_mask *bit_fdmask; #ifndef bit #define bit(x) (1 << (x)) @@ -56,16 +56,16 @@ typedef bit_mask *bit_fdmask; #define BIT_ISCLRB(a,b) \ (((b)[(a)/BIT_BITSPERMASK] & (1<<((a) % BIT_BITSPERMASK))) == 0) -extern bit_fdmask bit_newfdmask(); +extern bit_fdmask bit_newfdmask(); -extern bit_fdmask bit_newfdmask(void ); -extern void bit_zero(bit_fdmask ); -extern void bit_not(bit_fdmask ); -extern void bit_copy(bit_fdmask , bit_fdmask ); -extern void bit_or(bit_fdmask , bit_fdmask ); -extern void bit_or3(bit_fdmask , bit_fdmask , bit_fdmask ); -extern void bit_and(bit_fdmask , bit_fdmask ); -extern void bit_and3(bit_fdmask , bit_fdmask , bit_fdmask ); -extern int bit_fd(bit_fdmask ); +extern bit_fdmask bit_newfdmask(void); +extern void bit_zero(bit_fdmask); +extern void bit_not(bit_fdmask); +extern void bit_copy(bit_fdmask, bit_fdmask); +extern void bit_or(bit_fdmask, bit_fdmask); +extern void bit_or3(bit_fdmask, bit_fdmask, bit_fdmask); +extern void bit_and(bit_fdmask, bit_fdmask); +extern void bit_and3(bit_fdmask, bit_fdmask, bit_fdmask); +extern int bit_fd(bit_fdmask); #endif /* _BIT_H_ */ diff --git a/include/com.h b/include/com.h index ab56d63dc..4c6ef1e17 100644 --- a/include/com.h +++ b/include/com.h @@ -34,18 +34,18 @@ #ifndef _COM_H_ #define _COM_H_ -struct cmndstr { - s_char *c_form; /* prototype of command */ - int c_cost; /* btu cost of command */ - int (*c_addr)(); /* core addr of appropriate routine */ - int c_flags; - int c_permit; /* who is allowed to "do" this command */ +struct cmndstr { + s_char *c_form; /* prototype of command */ + int c_cost; /* btu cost of command */ + int (*c_addr) (); /* core addr of appropriate routine */ + int c_flags; + int c_permit; /* who is allowed to "do" this command */ }; #define C_MOD 0x1 /* modifies database */ /* variables associated with this stuff */ -extern struct cmndstr coms[]; +extern struct cmndstr coms[]; #endif /* _COM_H_ */ diff --git a/include/combat.h b/include/combat.h index d99404fe0..856d9fd87 100644 --- a/include/combat.h +++ b/include/combat.h @@ -37,27 +37,27 @@ #include "sect.h" #include "queue.h" -struct combat { - int type; /* EF_BAD, EF_SECTOR, EF_SHIP, or EF_PLANE */ - int set; /* Has the struct been initialized? */ - int last; /* The index of the last element in off array */ - coord x; /* location of attacking sector/ship/plane */ - coord y; - natid own; - int eff; - int mob; - int mobcost; - int mil; /* mil in the sector/ship/unit */ - int troops; /* mil in the combat */ - int plague; - int sct_type; - int shp_uid; - int lnd_uid; - struct dchrstr *sct_dcp; - struct mchrstr *shp_mcp; - struct lchrstr *lnd_lcp; - s_char shp_name[MAXSHPNAMLEN]; - int relations_checked; +struct combat { + int type; /* EF_BAD, EF_SECTOR, EF_SHIP, or EF_PLANE */ + int set; /* Has the struct been initialized? */ + int last; /* The index of the last element in off array */ + coord x; /* location of attacking sector/ship/plane */ + coord y; + natid own; + int eff; + int mob; + int mobcost; + int mil; /* mil in the sector/ship/unit */ + int troops; /* mil in the combat */ + int plague; + int sct_type; + int shp_uid; + int lnd_uid; + struct dchrstr *sct_dcp; + struct mchrstr *shp_mcp; + struct lchrstr *lnd_lcp; + s_char shp_name[MAXSHPNAMLEN]; + int relations_checked; }; /* Types of combat for use by attack routines */ @@ -69,32 +69,32 @@ struct combat { #define A_LBOARD 5 /* src/lib/subs/attsub.c */ -extern double att_calcodds(int , int ); -extern double att_combat_eff(struct combat * ); -extern void att_move_in_off(int , struct combat * , struct emp_qelem * , - struct combat * ); -extern int att_combat_init(struct combat * , int ); -extern int att_get_combat(struct combat * , int ); -extern int att_abort(int , struct combat * , struct combat * ); -extern int att_approach(struct combat * , struct combat * ); -extern int att_show(struct combat * ); -extern int att_ask_support(int , int * , int * , int * , int * ); -extern int att_ask_offense(int , struct combat * , struct combat * , - struct emp_qelem * , int * , int * ); -extern double sector_strength(struct sctstr * ); -extern int att_estimate_defense(int , struct combat * , struct emp_qelem *, - struct combat * , int ); -extern int att_empty_attack(int , int , struct combat * ); -extern int att_get_defense(struct emp_qelem * , struct combat * , - struct emp_qelem * , int , int ); -extern int att_reacting_units(struct combat * , struct emp_qelem * , int , - int * , int ); -extern int att_get_support(int , int , int , int , int, struct emp_qelem *, - struct combat * , struct emp_qelem * , - struct combat * , double * , double * , int ); -extern int att_fight(int , struct combat * , struct emp_qelem * , double , - struct combat * , struct emp_qelem * , double ); -extern int att_free_lists(struct emp_qelem * , struct emp_qelem * ); +extern double att_calcodds(int, int); +extern double att_combat_eff(struct combat *); +extern void att_move_in_off(int, struct combat *, struct emp_qelem *, + struct combat *); +extern int att_combat_init(struct combat *, int); +extern int att_get_combat(struct combat *, int); +extern int att_abort(int, struct combat *, struct combat *); +extern int att_approach(struct combat *, struct combat *); +extern int att_show(struct combat *); +extern int att_ask_support(int, int *, int *, int *, int *); +extern int att_ask_offense(int, struct combat *, struct combat *, + struct emp_qelem *, int *, int *); +extern double sector_strength(struct sctstr *); +extern int att_estimate_defense(int, struct combat *, struct emp_qelem *, + struct combat *, int); +extern int att_empty_attack(int, int, struct combat *); +extern int att_get_defense(struct emp_qelem *, struct combat *, + struct emp_qelem *, int, int); +extern int att_reacting_units(struct combat *, struct emp_qelem *, int, + int *, int); +extern int att_get_support(int, int, int, int, int, struct emp_qelem *, + struct combat *, struct emp_qelem *, + struct combat *, double *, double *, int); +extern int att_fight(int, struct combat *, struct emp_qelem *, double, + struct combat *, struct emp_qelem *, double); +extern int att_free_lists(struct emp_qelem *, struct emp_qelem *); extern double att_asupport(); @@ -104,4 +104,3 @@ extern double combat_mob; extern s_char *att_mode[]; #endif /* _COMBAT_H_ */ - diff --git a/include/commands.h b/include/commands.h index 87df3e126..31c07d6e1 100644 --- a/include/commands.h +++ b/include/commands.h @@ -55,6 +55,6 @@ #include "map.h" #include "update.h" -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _COMMANDS_H_ */ diff --git a/include/commodity.h b/include/commodity.h index b3f05c905..b5dfa76e1 100644 --- a/include/commodity.h +++ b/include/commodity.h @@ -37,19 +37,19 @@ #define _COMMODITY_H_ struct comstr { - short ef_type; - natid com_owner; - short com_uid; - char com_type; - int com_amount; - float com_price; - int com_maxbidder; - float com_maxprice; - time_t com_markettime; - coord com_x; - coord com_y; - coord sell_x; - coord sell_y; + short ef_type; + natid com_owner; + short com_uid; + char com_type; + int com_amount; + float com_price; + int com_maxbidder; + float com_maxprice; + time_t com_markettime; + coord com_x; + coord com_y; + coord sell_x; + coord sell_y; }; #define getcomm(n, p) \ diff --git a/include/common.h b/include/common.h index 2271ec4c1..ef5550531 100644 --- a/include/common.h +++ b/include/common.h @@ -34,16 +34,16 @@ #ifndef _COMMON_H_ #define _COMMON_H_ -#include /* FILE */ -#include /* caddr_t */ -#include "misc.h" /* s_char coord natid */ -#include "sect.h" /* struct sctstr */ -#include "ship.h" /* struct shpstr */ -#include "land.h" /* struct lndstr */ -#include "plane.h" /* struct plnstr */ -#include "nuke.h" /* struct nchrstr */ -#include "nsc.h" /* struct castr struct nstr_sect struct nstr_item */ -#include "xy.h" /* struct range */ -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include /* FILE */ +#include /* caddr_t */ +#include "misc.h" /* s_char coord natid */ +#include "sect.h" /* struct sctstr */ +#include "ship.h" /* struct shpstr */ +#include "land.h" /* struct lndstr */ +#include "plane.h" /* struct plnstr */ +#include "nuke.h" /* struct nchrstr */ +#include "nsc.h" /* struct castr struct nstr_sect struct nstr_item */ +#include "xy.h" /* struct range */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _COMMON_H_ */ diff --git a/include/deity.h b/include/deity.h index c0f1d6d52..b98b32424 100644 --- a/include/deity.h +++ b/include/deity.h @@ -34,8 +34,8 @@ #ifndef _DEITY_H_ #define _DEITY_H_ -extern s_char *privname; -extern s_char *privlog; -extern int privuid; +extern s_char *privname; +extern s_char *privlog; +extern int privuid; #endif /* _DEITY_H_ */ diff --git a/include/empio.h b/include/empio.h index cad53004c..3858102bc 100644 --- a/include/empio.h +++ b/include/empio.h @@ -34,7 +34,7 @@ #ifndef _EMPIO_H_ #define _EMPIO_H_ -#include /* struct timeval */ +#include /* struct timeval */ typedef struct iop *iop_t; @@ -51,27 +51,27 @@ typedef struct iop *iop_t; #define IO_NOWAIT 0 #define IO_WAIT 1 -extern struct iop * io_open(int , int , int , int (* )(void) , s_char * ); -extern void io_init(void ); -extern int io_noblocking(struct iop * , int ); -extern void io_close(struct iop * ); -extern int io_input(struct iop * , int ); -extern int io_inputwaiting(struct iop * ); -extern int io_outputwaiting(struct iop * ); -extern int io_output(struct iop * , int ); -extern int io_select(struct timeval * ); -extern void io_flush(int ); -extern int io_peek(struct iop * , s_char * , int ); -extern int io_read(struct iop * , s_char * , int ); -extern int io_write(struct iop * , s_char * , int , int ); -extern int io_output_all(struct iop * ); -extern int io_gets(struct iop * , s_char * , int ); -extern int io_puts(struct iop * , s_char * ); -extern int io_shutdown(struct iop * , int ); -extern int io_conn(struct iop * ); -extern int io_error(struct iop * ); -extern int io_eof(struct iop * ); -extern int io_fileno(struct iop * ); -extern struct iop * io_iopfromfd(int ); +extern struct iop *io_open(int, int, int, int (*)(void), s_char *); +extern void io_init(void); +extern int io_noblocking(struct iop *, int); +extern void io_close(struct iop *); +extern int io_input(struct iop *, int); +extern int io_inputwaiting(struct iop *); +extern int io_outputwaiting(struct iop *); +extern int io_output(struct iop *, int); +extern int io_select(struct timeval *); +extern void io_flush(int); +extern int io_peek(struct iop *, s_char *, int); +extern int io_read(struct iop *, s_char *, int); +extern int io_write(struct iop *, s_char *, int, int); +extern int io_output_all(struct iop *); +extern int io_gets(struct iop *, s_char *, int); +extern int io_puts(struct iop *, s_char *); +extern int io_shutdown(struct iop *, int); +extern int io_conn(struct iop *); +extern int io_error(struct iop *); +extern int io_eof(struct iop *); +extern int io_fileno(struct iop *); +extern struct iop *io_iopfromfd(int); #endif /* _EMPIO_H_ */ diff --git a/include/empthread.h b/include/empthread.h index 2ca7e5b13..116a36115 100644 --- a/include/empthread.h +++ b/include/empthread.h @@ -66,30 +66,30 @@ typedef struct lwpSem empth_sem_t; #define EMPTH_PRINT 0x1 #define EMPTH_STACKCHECK 0x2 -typedef void (*vf_ptr)(); +typedef void (*vf_ptr) (); #define EMPTH_KILLED 1 typedef struct empth_ctx_t { - char *name; /* thread name */ - char *desc; /* description */ - void *ud; /* user data */ - int state; /* my state */ - vf_ptr ep; /* entry point */ - pthread_t id; /* thread id */ -}empth_t; + char *name; /* thread name */ + char *desc; /* description */ + void *ud; /* user data */ + int state; /* my state */ + vf_ptr ep; /* entry point */ + pthread_t id; /* thread id */ +} empth_t; typedef struct { - pthread_mutex_t mtx_update; /* use it to update count */ + pthread_mutex_t mtx_update; /* use it to update count */ int count; char name[80]; pthread_mutex_t mtx_sem; pthread_cond_t cnd_sem; -}empth_sem_t; +} empth_sem_t; #endif /* DEC has slightly different names for whatever reason... */ #ifdef _DECTHREADS_ -#define pthread_key_create pthread_keycreate +#define pthread_key_create pthread_keycreate #define pthread_attr_init pthread_attr_create #define pthread_attr_destroy pthread_attr_delete @@ -112,26 +112,19 @@ typedef void empth_sem_t; int empth_init _PROTO((char **ctx, int flags)); empth_t *empth_create _PROTO((int, void (*)(), int, - int, char *, char *, void *)); + int, char *, char *, void *)); empth_t *empth_self(); void empth_exit _PROTO((void)); void empth_yield _PROTO((void)); void empth_terminate _PROTO((empth_t *)); void empth_select _PROTO((int fd, int flags)); void empth_wakeup _PROTO((empth_t *)); -void empth_sleep _PROTO((long until)); +void empth_sleep _PROTO((long until)); empth_sem_t *empth_sem_create _PROTO((char *name, int count)); void empth_sem_signal _PROTO((empth_sem_t *)); void empth_sem_wait _PROTO((empth_sem_t *)); emp_sig_t empth_alarm _PROTO((int)); -#include "prototypes.h" /* must come at end, after defines and typedefs */ -#endif - - - - - - - +#include "prototypes.h" /* must come at end, after defines and typedefs */ +#endif diff --git a/include/event.h b/include/event.h index 90993221d..c03ff22b3 100644 --- a/include/event.h +++ b/include/event.h @@ -37,15 +37,15 @@ /* country #1's battleship #2 hit your battleship #3 for 30% damage */ /* actor's from_type #from_id hit your to_type #to_id for data% damage */ struct event { - short verb; - natid actor; - natid victim; - short from_type; - short data; - int from_id; - short to_type; - int to_id; - time_t time; + short verb; + natid actor; + natid victim; + short from_type; + short data; + int from_id; + short to_type; + int to_id; + time_t time; }; #endif /* _EVENT_H_ */ diff --git a/include/file.h b/include/file.h index e9045c227..4adc033dc 100644 --- a/include/file.h +++ b/include/file.h @@ -35,23 +35,23 @@ #define _FILE_H_ struct empfile { - s_char *name; /* file name (e.g., "treaty") */ - s_char *file; /* file path */ - int flags; /* misc stuff */ - int mode; /* O_flags */ - int size; /* size of object */ - void (*init)(int , s_char *);/* call this when object is created */ - int (*postread)(int, s_char *); /* specific massage routines for items */ - int (*prewrite)(int , s_char *); - int varoffs[3]; /* struct offs for nv, vtype, vamt */ - int maxvars; /* max # vars for type */ - int fd; /* file descriptor */ - int baseid; /* starting item in cache */ - int cids; /* # ids in cache */ - int csize; /* size of cache in bytes */ - caddr_t cache; /* pointer to cache */ - int fids; /* # of ids in file */ - struct castr *cadef; /* ca defs selection list */ + s_char *name; /* file name (e.g., "treaty") */ + s_char *file; /* file path */ + int flags; /* misc stuff */ + int mode; /* O_flags */ + int size; /* size of object */ + void (*init) (int, s_char *); /* call this when object is created */ + int (*postread) (int, s_char *); /* specific massage routines for items */ + int (*prewrite) (int, s_char *); + int varoffs[3]; /* struct offs for nv, vtype, vamt */ + int maxvars; /* max # vars for type */ + int fd; /* file descriptor */ + int baseid; /* starting item in cache */ + int cids; /* # ids in cache */ + int csize; /* size of cache in bytes */ + caddr_t cache; /* pointer to cache */ + int fids; /* # of ids in file */ + struct castr *cadef; /* ca defs selection list */ }; #define EFF_COM bit(0) /* item has commodities attached */ @@ -78,40 +78,40 @@ struct empfile { #define EF_LOST 14 #define EF_MAX 15 -#define EF_NMAP 222 /* Kinda bogus, but used to describe a newdesmap - instead of bmap or map. */ +#define EF_NMAP 222 /* Kinda bogus, but used to describe a newdesmap + instead of bmap or map. */ -typedef void (*ef_fileinit)(int, s_char *); +typedef void (*ef_fileinit) (int, s_char *); struct fileinit { - void (*init)(int , s_char *); - int (*postread)(int, s_char *); - int (*prewrite)(int, s_char *); - struct castr *cadef; + void (*init) (int, s_char *); + int (*postread) (int, s_char *); + int (*prewrite) (int, s_char *); + struct castr *cadef; }; -extern struct castr * ef_cadef(int ); -extern int ef_read(int , int , caddr_t ); -extern s_char * ef_ptr(int , int ); -extern s_char * ef_nameof(int ); -extern time_t ef_mtime(int ); -extern int ef_open(int , int , int ); -extern int ef_check(int ); -extern int ef_close(int ); -extern int ef_flush(int ); -extern int ef_write(int , int , caddr_t ); -extern int ef_extend(int , int ); -extern void ef_zapcache(int ); -extern int ef_nelem(int ); -extern int ef_flags(int ); -extern int ef_lock(int ); -extern int ef_unlock(int ); -extern int ef_vars(int , register s_char * , u_char * * , - u_char * * , u_short * * ); -extern int ef_byname(s_char * ); +extern struct castr *ef_cadef(int); +extern int ef_read(int, int, caddr_t); +extern s_char *ef_ptr(int, int); +extern s_char *ef_nameof(int); +extern time_t ef_mtime(int); +extern int ef_open(int, int, int); +extern int ef_check(int); +extern int ef_close(int); +extern int ef_flush(int); +extern int ef_write(int, int, caddr_t); +extern int ef_extend(int, int); +extern void ef_zapcache(int); +extern int ef_nelem(int); +extern int ef_flags(int); +extern int ef_lock(int); +extern int ef_unlock(int); +extern int ef_vars(int, register s_char *, u_char **, + u_char **, u_short **); +extern int ef_byname(s_char *); -extern int ef_nbread(); -extern struct empfile empfile[]; +extern int ef_nbread(); +extern struct empfile empfile[]; #endif /* _FILE_H_ */ diff --git a/include/gen.h b/include/gen.h index ad9380e0d..03aa1639d 100644 --- a/include/gen.h +++ b/include/gen.h @@ -35,11 +35,11 @@ #define _GEN_H_ #include #if !defined(_WIN32) -#include /* struct in_addr */ +#include /* struct in_addr */ #endif -#include /* atoi etc. */ -#include "misc.h" /* s_char etc */ -#include "xy.h" /* struct range */ -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include /* atoi etc. */ +#include "misc.h" /* s_char etc */ +#include "xy.h" /* struct range */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _GEN_H_ */ diff --git a/include/genitem.h b/include/genitem.h index 1a9282073..6f02cb66e 100644 --- a/include/genitem.h +++ b/include/genitem.h @@ -42,31 +42,31 @@ #define _GENITEM_H_ struct genitem { - short ef_type; - natid own; - short uid; - coord x; - coord y; - s_char type; - s_char effic; - s_char mobil; - short sell; - short tech; - s_char group; - coord opx,opy; - short mission; - short radius; + short ef_type; + natid own; + short uid; + coord x; + coord y; + s_char type; + s_char effic; + s_char mobil; + short sell; + short tech; + s_char group; + coord opx, opy; + short mission; + short radius; }; struct genobject { - short ef_type; - natid own; + short ef_type; + natid own; }; struct genchrstr { - u_char nv; /* current number of variables */ - u_char vtype[MAXCHRNV]; - u_short vamt[MAXCHRNV]; + u_char nv; /* current number of variables */ + u_char vtype[MAXCHRNV]; + u_short vamt[MAXCHRNV]; }; #endif /* _GENITEM_H_ */ diff --git a/include/global.h b/include/global.h index e61a3425d..0703c1784 100644 --- a/include/global.h +++ b/include/global.h @@ -33,6 +33,6 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _GLOBAL_H_ */ diff --git a/include/io_mask.h b/include/io_mask.h index 425f38f1a..850d9817f 100644 --- a/include/io_mask.h +++ b/include/io_mask.h @@ -35,19 +35,19 @@ #define _IO_MASK_H_ struct io_mask { - int what; - int maxfd; - bit_fdmask readmask; - bit_fdmask user_readmask; - bit_fdmask writemask; - bit_fdmask user_writemask; + int what; + int maxfd; + bit_fdmask readmask; + bit_fdmask user_readmask; + bit_fdmask writemask; + bit_fdmask user_writemask; }; -extern struct io_mask * iom_create(int ); -extern void iom_getmask(struct io_mask * , int * , bit_fdmask * , - bit_fdmask * ); -extern void iom_set(struct io_mask * , int , int ); -extern void iom_clear(struct io_mask * , int , int ); -extern void iom_zero(struct io_mask * , int ); +extern struct io_mask *iom_create(int); +extern void iom_getmask(struct io_mask *, int *, bit_fdmask *, + bit_fdmask *); +extern void iom_set(struct io_mask *, int, int); +extern void iom_clear(struct io_mask *, int, int); +extern void iom_zero(struct io_mask *, int); #endif /* _IO_MASK_H_ */ diff --git a/include/ioqueue.h b/include/ioqueue.h index b92909df5..3dddafc8f 100644 --- a/include/ioqueue.h +++ b/include/ioqueue.h @@ -38,17 +38,17 @@ #define MAXIOV 16 struct io { - struct emp_qelem queue; - int size; - int nbytes; - int offset; - s_char *data; + struct emp_qelem queue; + int size; + int nbytes; + int offset; + s_char *data; }; struct ioqueue { - struct io list; - int bufsize; - int cc; + struct io list; + int bufsize; + int cc; }; extern struct ioqueue *ioq_create(int size); diff --git a/include/item.h b/include/item.h index c9ca0c96b..888677b74 100644 --- a/include/item.h +++ b/include/item.h @@ -36,25 +36,25 @@ #define NUMPKG 4 /* number of different kinds of packaging */ -struct ichrstr { - int i_mnem; /* usually the initial letter */ - int i_vtype; /* var type */ - int i_value; /* mortgage value */ - int i_sell; /* can this be sold? */ - int i_lbs; /* how hard to move */ - int i_pkg[NUMPKG]; /* units for reg, ware, urb, bank */ - s_char *i_name; /* full name of item */ +struct ichrstr { + int i_mnem; /* usually the initial letter */ + int i_vtype; /* var type */ + int i_value; /* mortgage value */ + int i_sell; /* can this be sold? */ + int i_lbs; /* how hard to move */ + int i_pkg[NUMPKG]; /* units for reg, ware, urb, bank */ + s_char *i_name; /* full name of item */ }; /* variables using this structure */ -extern struct ichrstr ichr[]; -extern int maxitem; +extern struct ichrstr ichr[]; +extern int maxitem; /* procedures using/returning this struct */ -extern struct ichrstr *whatitem(); +extern struct ichrstr *whatitem(); -extern int itm_maxno; +extern int itm_maxno; #endif /* _ITEM_H_ */ diff --git a/include/keyword.h b/include/keyword.h index 620fbcbba..49316830b 100644 --- a/include/keyword.h +++ b/include/keyword.h @@ -42,10 +42,10 @@ #define CF_TIMERANGE 3 #define CF_WEEKDAY 4 -extern s_char * kw_find(s_char * ); -extern s_char * kw_parse(int , s_char * , int * ); -extern int kw_read(FILE * ); -extern s_char * get_time(s_char * , int * ); -extern s_char * weekday(s_char * , int * ); +extern s_char *kw_find(s_char *); +extern s_char *kw_parse(int, s_char *, int *); +extern int kw_read(FILE *); +extern s_char *get_time(s_char *, int *); +extern s_char *weekday(s_char *, int *); #endif /* _KEYWORD_H_ */ diff --git a/include/land.h b/include/land.h index d60999dbf..9fe638b6a 100644 --- a/include/land.h +++ b/include/land.h @@ -43,91 +43,91 @@ #include "retreat.h" #define LAND_MINEFF 10 -#define LAND_MINFIREEFF 40 /* arty must be this effic to fire */ +#define LAND_MINFIREEFF 40 /* arty must be this effic to fire */ #define MAXLNDV 14 #define LND_MINMOBCOST 0.200 -struct lndstr { - short ef_type; - natid lnd_own; /* owner's country num */ - short lnd_uid; /* unit id (land unit) */ - coord lnd_x; /* x location in abs coords */ - coord lnd_y; /* y location in abs coords */ - s_char lnd_type; /* ship type */ - s_char lnd_effic; /* 0% to 100% */ - s_char lnd_mobil; /* mobility units made int for RS/6000 */ - short lnd_sell; /* pointer to trade file */ - short lnd_tech; /* tech level ship was built at */ - s_char lnd_army; /* group membership */ - coord lnd_opx,lnd_opy;/* Op sector coords */ - short lnd_mission; /* mission code */ - short lnd_radius; /* mission radius */ - s_char lnd_flags; /* unit flags */ - short lnd_ship; /* pointer to transporting ship */ - s_char lnd_harden; /* for missiles */ - short lnd_retreat; /* retreat percentage */ - u_char lnd_fuel; /* How much fuel do we have */ - u_char lnd_nxlight; /* How many xlight planes on board? */ - int lnd_rflags; /* When do I retreat? */ - s_char lnd_rpath[RET_LEN]; /* retreat path */ - u_char lnd_rad_max; /* max radius for this unit */ - u_char lnd_scar; /* how experienced the unit is (not used) */ - s_char lnd_nv; /* current number of variables */ - u_char lnd_vtype[MAXLNDV]; - u_short lnd_vamt[MAXLNDV]; - short lnd_land; /* pointer to transporting unit */ - u_char lnd_nland; - time_t lnd_access; /* Last time mob was updated (MOB_ACCESS) */ - float lnd_att; /* attack multiplier */ - float lnd_def; /* defense multiplier */ - int lnd_vul; /* vulnerability (0-100) */ - int lnd_spd; /* speed */ - int lnd_vis; /* visibility */ - int lnd_spy; /* Seeing distance */ - int lnd_rad; /* reaction radius */ - int lnd_frg; /* firing range */ - int lnd_acc; /* firing accuracy */ - int lnd_dam; /* # of guns firing */ - int lnd_ammo; /* firing ammu used per shot */ - int lnd_aaf; /* aa fire */ - u_char lnd_fuelc; /* fuel capacity */ - u_char lnd_fuelu; /* fuel used per 10 mob */ - u_char lnd_maxlight; /* maximum number of xlight planes */ - u_char lnd_maxland; /* maximum number of units */ - time_t lnd_timestamp; /* Last time this unit was touched */ +struct lndstr { + short ef_type; + natid lnd_own; /* owner's country num */ + short lnd_uid; /* unit id (land unit) */ + coord lnd_x; /* x location in abs coords */ + coord lnd_y; /* y location in abs coords */ + s_char lnd_type; /* ship type */ + s_char lnd_effic; /* 0% to 100% */ + s_char lnd_mobil; /* mobility units made int for RS/6000 */ + short lnd_sell; /* pointer to trade file */ + short lnd_tech; /* tech level ship was built at */ + s_char lnd_army; /* group membership */ + coord lnd_opx, lnd_opy; /* Op sector coords */ + short lnd_mission; /* mission code */ + short lnd_radius; /* mission radius */ + s_char lnd_flags; /* unit flags */ + short lnd_ship; /* pointer to transporting ship */ + s_char lnd_harden; /* for missiles */ + short lnd_retreat; /* retreat percentage */ + u_char lnd_fuel; /* How much fuel do we have */ + u_char lnd_nxlight; /* How many xlight planes on board? */ + int lnd_rflags; /* When do I retreat? */ + s_char lnd_rpath[RET_LEN]; /* retreat path */ + u_char lnd_rad_max; /* max radius for this unit */ + u_char lnd_scar; /* how experienced the unit is (not used) */ + s_char lnd_nv; /* current number of variables */ + u_char lnd_vtype[MAXLNDV]; + u_short lnd_vamt[MAXLNDV]; + short lnd_land; /* pointer to transporting unit */ + u_char lnd_nland; + time_t lnd_access; /* Last time mob was updated (MOB_ACCESS) */ + float lnd_att; /* attack multiplier */ + float lnd_def; /* defense multiplier */ + int lnd_vul; /* vulnerability (0-100) */ + int lnd_spd; /* speed */ + int lnd_vis; /* visibility */ + int lnd_spy; /* Seeing distance */ + int lnd_rad; /* reaction radius */ + int lnd_frg; /* firing range */ + int lnd_acc; /* firing accuracy */ + int lnd_dam; /* # of guns firing */ + int lnd_ammo; /* firing ammu used per shot */ + int lnd_aaf; /* aa fire */ + u_char lnd_fuelc; /* fuel capacity */ + u_char lnd_fuelu; /* fuel used per 10 mob */ + u_char lnd_maxlight; /* maximum number of xlight planes */ + u_char lnd_maxland; /* maximum number of units */ + time_t lnd_timestamp; /* Last time this unit was touched */ }; -#define LND_NOTANY bit(0) /* Just a placeholder, not used */ - -struct lchrstr { - u_char l_nv; /* number of variables it can hold */ - u_char l_vtype[MAXCHRNV]; - u_short l_vamt[MAXCHRNV]; - s_char *l_name; /* full name of type of land unit */ - int l_lcm; /* units of lcm to build */ - int l_hcm; /* units of hcm to build */ - int l_mil; /* how many mil it takes to build */ - int l_gun; /* how many guns it takes to build */ - int l_shell; /* how many shells it takes to build */ - int l_tech; /* tech required to build */ - int l_cost; /* how much it costs to build */ - float l_att; /* attack multiplier */ - float l_def; /* defense multiplier */ - int l_vul; /* vulnerability (0-100) */ - int l_spd; /* speed */ - int l_vis; /* visibility */ - int l_spy; /* Seeing distance */ - int l_rad; /* reaction radius */ - int l_frg; /* firing range */ - int l_acc; /* firing accuracy */ - int l_dam; /* # of guns firing */ - int l_ammo; /* firing ammu used per shot */ - int l_aaf; /* aa fire */ - u_char l_fuelc; /* fuel capacity */ - u_char l_fuelu; /* fuel used per 10 mob */ - u_char l_nxlight; /* maximum number of xlight planes */ - u_char l_mxland; /* maximum number of units */ - long l_flags; /* what special things can this unit do */ +#define LND_NOTANY bit(0) /* Just a placeholder, not used */ + +struct lchrstr { + u_char l_nv; /* number of variables it can hold */ + u_char l_vtype[MAXCHRNV]; + u_short l_vamt[MAXCHRNV]; + s_char *l_name; /* full name of type of land unit */ + int l_lcm; /* units of lcm to build */ + int l_hcm; /* units of hcm to build */ + int l_mil; /* how many mil it takes to build */ + int l_gun; /* how many guns it takes to build */ + int l_shell; /* how many shells it takes to build */ + int l_tech; /* tech required to build */ + int l_cost; /* how much it costs to build */ + float l_att; /* attack multiplier */ + float l_def; /* defense multiplier */ + int l_vul; /* vulnerability (0-100) */ + int l_spd; /* speed */ + int l_vis; /* visibility */ + int l_spy; /* Seeing distance */ + int l_rad; /* reaction radius */ + int l_frg; /* firing range */ + int l_acc; /* firing accuracy */ + int l_dam; /* # of guns firing */ + int l_ammo; /* firing ammu used per shot */ + int l_aaf; /* aa fire */ + u_char l_fuelc; /* fuel capacity */ + u_char l_fuelu; /* fuel used per 10 mob */ + u_char l_nxlight; /* maximum number of xlight planes */ + u_char l_mxland; /* maximum number of units */ + long l_flags; /* what special things can this unit do */ }; /* Land unit ability flags */ @@ -141,9 +141,9 @@ struct lchrstr { #define L_RADAR bit(7) /* radar unit */ #define L_ASSAULT bit(8) /* can assault */ #define L_FLAK bit(9) /* flak unit */ -#define L_SPY bit(10) /* spy unit - way cool */ -#define L_TRAIN bit(11) /* train unit - neato */ -#define L_HEAVY bit(12) /* heavy unit - can't go on trains */ +#define L_SPY bit(10) /* spy unit - way cool */ +#define L_TRAIN bit(11) /* train unit - neato */ +#define L_HEAVY bit(12) /* heavy unit - can't go on trains */ #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((double)(t)) / 100.0) * 4.0))) \ > 127 ? 127 : \ @@ -179,51 +179,50 @@ struct lchrstr { #define getlandp(n) \ (struct lndstr *) ef_ptr(EF_LAND, n) -extern struct lchrstr lchr[]; -extern int lnd_maxno; +extern struct lchrstr lchr[]; +extern int lnd_maxno; struct llist { - struct emp_qelem queue; /* list of units */ - coord x,y; /* x,y it came from */ - struct lchrstr *lcp; /* pointer to desc of land unit */ - struct lndstr land; /* struct land unit */ - int eff; - double mobil; - int supplied; + struct emp_qelem queue; /* list of units */ + coord x, y; /* x,y it came from */ + struct lchrstr *lcp; /* pointer to desc of land unit */ + struct lndstr land; /* struct land unit */ + int eff; + double mobil; + int supplied; }; /* src/lib/subs/lndsub.c */ -extern void lnd_sweep(struct emp_qelem * , int , int , natid ); -extern int lnd_interdict(struct emp_qelem * , coord , coord , natid ); -extern void lnd_sel(struct nstr_item * , struct emp_qelem * ); -extern void lnd_mess(s_char * , struct llist * ); -extern int lnd_check_mines(struct emp_qelem * ); -extern double lnd_mobcost(struct lndstr * , struct sctstr * , int ); -extern s_char * lnd_path(int , struct lndstr * , s_char * ); - -extern int attack_val(int , struct lndstr * ); -extern int total_mil(struct lndstr * ); -extern int defense_val(struct lndstr * ); -extern int lnd_getmil(struct lndstr * ); -extern void lnd_print(struct llist * , s_char * ); -extern void lnd_delete(struct llist * , s_char * ); -extern int lnd_take_casualty(int , struct llist * , int ); -extern void lnd_submil(struct lndstr * , int ); -extern void lnd_takemob(struct emp_qelem * , double ); -extern int lnd_spyval(struct lndstr * ); -extern int intelligence_report(int , struct lndstr * , int , s_char * ); -extern int count_sect_units(struct sctstr * ); -extern void count_units(struct shpstr * ); -extern void lnd_count_units(struct lndstr * ); -extern void lnd_mar(struct emp_qelem * , double * , double * , int * , - natid ); -extern void lnd_put(struct emp_qelem * , natid ); -extern int lnd_hit_mine(struct lndstr * , struct lchrstr * ); -extern void lnd_list(struct emp_qelem * ); -extern int lnd_hardtarget(struct lndstr * ); -extern int lnd_mar_one_sector(struct emp_qelem * , int , natid , int ); -extern int lnd_support(natid , natid , coord , coord ); -extern int lnd_can_attack(struct lndstr * ); +extern void lnd_sweep(struct emp_qelem *, int, int, natid); +extern int lnd_interdict(struct emp_qelem *, coord, coord, natid); +extern void lnd_sel(struct nstr_item *, struct emp_qelem *); +extern void lnd_mess(s_char *, struct llist *); +extern int lnd_check_mines(struct emp_qelem *); +extern double lnd_mobcost(struct lndstr *, struct sctstr *, int); +extern s_char *lnd_path(int, struct lndstr *, s_char *); + +extern int attack_val(int, struct lndstr *); +extern int total_mil(struct lndstr *); +extern int defense_val(struct lndstr *); +extern int lnd_getmil(struct lndstr *); +extern void lnd_print(struct llist *, s_char *); +extern void lnd_delete(struct llist *, s_char *); +extern int lnd_take_casualty(int, struct llist *, int); +extern void lnd_submil(struct lndstr *, int); +extern void lnd_takemob(struct emp_qelem *, double); +extern int lnd_spyval(struct lndstr *); +extern int intelligence_report(int, struct lndstr *, int, s_char *); +extern int count_sect_units(struct sctstr *); +extern void count_units(struct shpstr *); +extern void lnd_count_units(struct lndstr *); +extern void lnd_mar(struct emp_qelem *, double *, double *, int *, natid); +extern void lnd_put(struct emp_qelem *, natid); +extern int lnd_hit_mine(struct lndstr *, struct lchrstr *); +extern void lnd_list(struct emp_qelem *); +extern int lnd_hardtarget(struct lndstr *); +extern int lnd_mar_one_sector(struct emp_qelem *, int, natid, int); +extern int lnd_support(natid, natid, coord, coord); +extern int lnd_can_attack(struct lndstr *); void landdamage(); diff --git a/include/loan.h b/include/loan.h index 7cd1844c3..6407a28ba 100644 --- a/include/loan.h +++ b/include/loan.h @@ -37,19 +37,19 @@ #define MAXLOAN 100000 #define SECS_PER_DAY (60*60*24) -struct lonstr { - short ef_type; - natid l_loner; /* loan shark */ - short l_uid; - natid l_lonee; /* sucker */ - s_char l_status; /* loan status */ - short l_sell; /* pointer to trade file */ - int l_irate; /* interest rate */ - int l_ldur; /* intended duration */ - long l_amtpaid; /* amount paid so far */ - long l_amtdue; /* amount still owed */ - time_t l_lastpay; /* date of most recent payment */ - time_t l_duedate; /* date after which interest doubles, etc */ +struct lonstr { + short ef_type; + natid l_loner; /* loan shark */ + short l_uid; + natid l_lonee; /* sucker */ + s_char l_status; /* loan status */ + short l_sell; /* pointer to trade file */ + int l_irate; /* interest rate */ + int l_ldur; /* intended duration */ + long l_amtpaid; /* amount paid so far */ + long l_amtdue; /* amount still owed */ + time_t l_lastpay; /* date of most recent payment */ + time_t l_duedate; /* date after which interest doubles, etc */ }; #define LS_FREE 0 diff --git a/include/lost.h b/include/lost.h index e0a53270b..adfec5bc8 100644 --- a/include/lost.h +++ b/include/lost.h @@ -34,22 +34,21 @@ #ifndef _LOST_H_ #define _LOST_H_ struct loststr { - short ef_type; - natid lost_owner; /* Who lost it */ - int lost_uid; /* This lost # */ - char lost_type; /* Type of thing (ship, plane, nuke, land, sector) */ - short lost_id; /* ID of thing */ - coord lost_x; - coord lost_y; - time_t lost_timestamp; /* When it was lost */ + short ef_type; + natid lost_owner; /* Who lost it */ + int lost_uid; /* This lost # */ + char lost_type; /* Type of thing (ship, plane, nuke, land, sector) */ + short lost_id; /* ID of thing */ + coord lost_x; + coord lost_y; + time_t lost_timestamp; /* When it was lost */ }; #define getlost(n, p) ef_read(EF_LOST, n, (caddr_t)p) #define putlost(n, p) ef_write(EF_LOST, n, (caddr_t)p) /* src/lib/subs/lostsub.c */ -extern int findlost(char , natid , short , coord , coord , int ); -extern void makelost(char , natid , short , coord , coord ); -extern void makenotlost(char , natid , short , coord , coord ); +extern int findlost(char, natid, short, coord, coord, int); +extern void makelost(char, natid, short, coord, coord); +extern void makenotlost(char, natid, short, coord, coord); #endif /* _LOST_H_ */ - diff --git a/include/lwp.h b/include/lwp.h index 61395a559..f29a0d4aa 100644 --- a/include/lwp.h +++ b/include/lwp.h @@ -25,7 +25,7 @@ #include "prototype.h" #ifdef UCONTEXT #include -#else /* UCONTEXT */ +#else /* UCONTEXT */ #include #endif /* UCONTEXT */ #include @@ -36,39 +36,39 @@ /* process control block. do *not* change the position of context */ struct lwpProc { #ifdef UCONTEXT - ucontext_t context; /* context structure */ -#else /* UCONTEXT */ - jmp_buf context; /* processor context area */ -#endif /* UCONTEXT */ - void *sbtm; /* bottom of stack attached to it */ - int size; /* size of stack */ - void (*entry)(); /* entry point */ - int dead; /* whether the process can be rescheduled */ - int pri; /* which scheduling queue we're on */ - long runtime; /* time at which process is restarted */ - int fd; /* fd we're blocking on */ - int argc; /* initial arguments */ - char **argv; - void *ud; /* user data */ - void *lowmark; /* start of low buffer around stack */ - void *himark; /* start of upper buffer around stack */ - char *name; /* process name and description */ - char *desc; - int flags; - struct lwpProc *next; + ucontext_t context; /* context structure */ +#else /* UCONTEXT */ + jmp_buf context; /* processor context area */ +#endif /* UCONTEXT */ + void *sbtm; /* bottom of stack attached to it */ + int size; /* size of stack */ + void (*entry) (); /* entry point */ + int dead; /* whether the process can be rescheduled */ + int pri; /* which scheduling queue we're on */ + long runtime; /* time at which process is restarted */ + int fd; /* fd we're blocking on */ + int argc; /* initial arguments */ + char **argv; + void *ud; /* user data */ + void *lowmark; /* start of low buffer around stack */ + void *himark; /* start of upper buffer around stack */ + char *name; /* process name and description */ + char *desc; + int flags; + struct lwpProc *next; }; /* queue */ struct lwpQueue { - struct lwpProc *head; - struct lwpProc *tail; + struct lwpProc *head; + struct lwpProc *tail; }; /* semaphore */ struct lwpSem { - int count; - struct lwpQueue q; - char *name; + int count; + struct lwpQueue q; + char *name; }; #define LWP_FD_READ 0x1 @@ -76,30 +76,30 @@ struct lwpSem { #define LWP_MAX_PRIO 8 -struct lwpProc *lwpInitSystem _PROTO((int prio, char **ctxp, int flags)); -struct lwpProc *lwpCreate _PROTO((int prio, void (*)(), int size, - int flags, char *name, char *desc, int argc, - char **argv, void *ud)); -void lwpExit _PROTO((void)); -void lwpTerminate _PROTO((struct lwpProc *p)); -void lwpYield _PROTO((void)); -void lwpSleepFd _PROTO((int fd, int flags)); -void lwpSleepUntil _PROTO((long until)); -void lwpWakeupFd _PROTO((struct lwpProc *p)); -void *lwpGetUD _PROTO((struct lwpProc *p)); -void lwpSetUD _PROTO((struct lwpProc *p, char *ud)); -void lwpSetDesc _PROTO((struct lwpProc *p, char *name, char *desc)); -int lwpSetPriority _PROTO((int prio)); -void lwpReschedule _PROTO((void)); +struct lwpProc *lwpInitSystem _PROTO((int prio, char **ctxp, int flags)); +struct lwpProc *lwpCreate _PROTO((int prio, void (*)(), int size, + int flags, char *name, char *desc, + int argc, char **argv, void *ud)); +void lwpExit _PROTO((void)); +void lwpTerminate _PROTO((struct lwpProc * p)); +void lwpYield _PROTO((void)); +void lwpSleepFd _PROTO((int fd, int flags)); +void lwpSleepUntil _PROTO((long until)); +void lwpWakeupFd _PROTO((struct lwpProc * p)); +void *lwpGetUD _PROTO((struct lwpProc * p)); +void lwpSetUD _PROTO((struct lwpProc * p, char *ud)); +void lwpSetDesc _PROTO((struct lwpProc * p, char *name, char *desc)); +int lwpSetPriority _PROTO((int prio)); +void lwpReschedule _PROTO((void)); -struct lwpSem *lwpCreateSem _PROTO((char *name, int count)); -void lwpSignal _PROTO((struct lwpSem *)); -void lwpWait _PROTO((struct lwpSem *)); -void lwpSelect _PROTO((int argc, char **argv)); -void lwpStatus _PROTO((struct lwpProc *proc, char *format, ...)); +struct lwpSem *lwpCreateSem _PROTO((char *name, int count)); +void lwpSignal _PROTO((struct lwpSem *)); +void lwpWait _PROTO((struct lwpSem *)); +void lwpSelect _PROTO((int argc, char **argv)); +void lwpStatus _PROTO((struct lwpProc * proc, char *format, ...)); -extern struct lwpProc *LwpCurrent; +extern struct lwpProc *LwpCurrent; -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ -#endif /* _LWP_H_ */ +#endif /* _LWP_H_ */ diff --git a/include/map.h b/include/map.h index b627904b9..9eba30091 100644 --- a/include/map.h +++ b/include/map.h @@ -39,26 +39,26 @@ #define MAPWIDTH(persec) ((WORLD_X/2)*(persec + 1)+1) -extern s_char *routech[7][2]; +extern s_char *routech[7][2]; -extern void blankfill(s_char * , register struct range * , int ); +extern void blankfill(s_char *, register struct range *, int); /* src/lib/subs/border.c */ -extern int map_set(natid , coord , coord , s_char , int ); -extern void writebmap(natid ); -extern void writemap(natid ); +extern int map_set(natid, coord, coord, s_char, int); +extern void writebmap(natid); +extern void writemap(natid); /* src/lib/subs/border.c */ -extern void border(struct range * , s_char * , s_char * ); +extern void border(struct range *, s_char *, s_char *); #define MAP_SHIP bit(0) #define MAP_LAND bit(1) #define MAP_PLANE bit(2) #define MAP_ALL MAP_SHIP | MAP_LAND | MAP_PLANE -struct mapstr { - short ef_type; - coord map_x; - coord map_y; - s_char map_des; +struct mapstr { + short ef_type; + coord map_x; + coord map_y; + s_char map_des; }; #endif /* _MAP_H_ */ diff --git a/include/misc.h b/include/misc.h index dcfb7f929..ce704d1a8 100644 --- a/include/misc.h +++ b/include/misc.h @@ -48,7 +48,7 @@ #if defined(_WIN32) typedef unsigned char u_char; typedef unsigned short u_short; -typedef char * caddr_t; +typedef char *caddr_t; typedef unsigned int u_int; /* Promote warning to error - undefined function. assuming eternal int */ @@ -87,12 +87,12 @@ typedef unsigned int u_int; mobility and the timestamp of when the game was last up. These times are in seconds. */ struct mob_acc_globals { - time_t timestamp; /* Last timestamp of when the game was up */ - time_t starttime; /* When we should start updating mobility again. */ + time_t timestamp; /* Last timestamp of when the game was up */ + time_t starttime; /* When we should start updating mobility again. */ }; - -#define ANNO_KEEP_DAYS 7 /* Keep announcements around for this many days */ -#define RESOLVE_IPADDRESS /* resolve ip addresses into hostnames */ + +#define ANNO_KEEP_DAYS 7 /* Keep announcements around for this many days */ +#define RESOLVE_IPADDRESS /* resolve ip addresses into hostnames */ typedef u_char natid; /* also change NSC_NATID in nsc.h */ @@ -102,7 +102,7 @@ typedef u_char natid; /* also change NSC_NATID in nsc.h */ #if !defined (_EMPTH_LWP) && !defined (_EMPTH_POSIX) #define _EMPTH_LWP 1 -#endif +#endif #if defined(_EMPTH_POSIX) && !defined(POSIXSIGNALS) #define POSIXSIGNALS @@ -122,7 +122,7 @@ typedef char s_char; /* change to signed char for aix */ #else typedef signed char s_char; #endif /* !aix && !sgi */ -typedef short coord; /* also change NSC_COORD in nsc.h */ +typedef short coord; /* also change NSC_COORD in nsc.h */ /* * watch it; your compiler might not like this. * If you think this is bogus, look at /usr/include/struct.h @@ -138,14 +138,14 @@ typedef short coord; /* also change NSC_COORD in nsc.h */ #define hours(x) (60*60*(x)) #define days(x) (60*60*24*(x)) -typedef void (*voidfunc)(); -typedef int(*qsort_func_t)(const void *, const void *); +typedef void (*voidfunc) (); +typedef int (*qsort_func_t) (const void *, const void *); /* return codes from command routines */ -#define RET_OK 0 /* command completed sucessfully */ -#define RET_FAIL 1 /* command completed unsucessfully [?] */ -#define RET_SYN 2 /* syntax error in command */ -#define RET_SYS 3 /* system error (missing file, etc) */ +#define RET_OK 0 /* command completed sucessfully */ +#define RET_FAIL 1 /* command completed unsucessfully [?] */ +#define RET_SYN 2 /* syntax error in command */ +#define RET_SYS 3 /* system error (missing file, etc) */ #define MAX_DISTPATH_LEN 10 /* Has to go somewhere */ @@ -154,20 +154,21 @@ typedef int(*qsort_func_t)(const void *, const void *); * particular object, and are of general interest */ #if !defined(ALPHA) && !defined(__osf__) && !defined(__linux__) && !defined(_WIN32) -extern long random(); +extern long random(); #endif double dmax _PROTO((double n1, double n2)); double dmin _PROTO((double n1, double n2)); -extern s_char *copy _PROTO((s_char *s1, s_char *s2)); -extern s_char *numstr _PROTO((s_char buf[], int n)); -extern s_char *esplur _PROTO((int n)); -extern s_char *splur _PROTO((int n)); -extern s_char *iesplur _PROTO((int n)); -extern s_char *plur _PROTO((int n, s_char *no, s_char *yes)); -extern s_char *getstarg _PROTO((s_char *input, s_char *prompt, s_char buf[])); -extern s_char *getstring _PROTO((s_char *prompt, s_char buf[])); +extern s_char *copy _PROTO((s_char *s1, s_char *s2)); +extern s_char *numstr _PROTO((s_char buf[], int n)); +extern s_char *esplur _PROTO((int n)); +extern s_char *splur _PROTO((int n)); +extern s_char *iesplur _PROTO((int n)); +extern s_char *plur _PROTO((int n, s_char *no, s_char *yes)); +extern s_char *getstarg +_PROTO((s_char *input, s_char *prompt, s_char buf[])); +extern s_char *getstring _PROTO((s_char *prompt, s_char buf[])); extern s_char *prbuf(s_char *format, ...); /* @@ -177,46 +178,46 @@ extern s_char *prbuf(s_char *format, ...); #if !defined(_WIN32) #if defined(linux) #ifndef __STDC__ -extern char *malloc(); -extern char *calloc(); +extern char *malloc(); +extern char *calloc(); #endif #else #if !defined(ALPHA) && !defined(__osf__) && !defined(ultrix) && !defined(hpux) && !defined(FBSD) -extern char *malloc(); -extern char *calloc(); +extern char *malloc(); +extern char *calloc(); #endif #endif #endif #if (!defined (aix) && !defined (sgi)) -extern char *ctime(); -extern char *strncpy(); -extern char *strcpy(); +extern char *ctime(); +extern char *strncpy(); +extern char *strcpy(); #ifndef NeXT -extern char *index(); -extern char *rindex(); +extern char *index(); +extern char *rindex(); #endif /* NeXT */ -#endif /* !aix && !sgi*/ +#endif /* !aix && !sgi */ -extern time_t time(); +extern time_t time(); #if !defined(_WIN32) #ifdef linux #ifndef atof -extern double atof(); +extern double atof(); #endif #else -extern double atof(); +extern double atof(); #endif #endif #if !defined(_WIN32) #if !defined (__ppc__) && !defined (hpux) && !defined (aix) && !defined (linux) && !defined(ALPHA) && !defined(__osf__) && !defined(SUN4) && !defined (Rel4) && !(defined (ultrix) && (defined (__STDC__) || defined (__SYSTEMFIVE) || defined (__POSIX))) -extern char *sprintf(); +extern char *sprintf(); #endif /* aix */ #endif #define MAXCHRNV 12 -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _MISC_H_ */ diff --git a/include/mission.h b/include/mission.h index a2a5d2b80..52adb3c03 100644 --- a/include/mission.h +++ b/include/mission.h @@ -40,29 +40,29 @@ #define MI_SUPPORT 2 #define MI_RESERVE 3 #define MI_ESCORT 4 -#define MI_SINTERDICT 5 /* sub interdiction */ +#define MI_SINTERDICT 5 /* sub interdiction */ #define MI_AIR_DEFENSE 6 #define MI_DSUPPORT 7 #define MI_OSUPPORT 8 /* The following "missions" do not need to be set--they are automatic */ -#define MI_FINTERDICT 9 /* forts interdicting ships */ -#define MI_MINTERDICT 10 /* missiles interdicting ships or land units */ -#define MI_MINTERCEPT 11 /* missile interception */ -#define MI_SINTERCEPT 12 /* sattelite interception */ -#define MI_PINTERCEPT 13 /* intercept planes */ -#define MI_SAM 14 /* SAM interception */ -#define MI_LREACT 15 /* land units react */ +#define MI_FINTERDICT 9 /* forts interdicting ships */ +#define MI_MINTERDICT 10 /* missiles interdicting ships or land units */ +#define MI_MINTERCEPT 11 /* missile interception */ +#define MI_SINTERCEPT 12 /* sattelite interception */ +#define MI_PINTERCEPT 13 /* intercept planes */ +#define MI_SAM 14 /* SAM interception */ +#define MI_LREACT 15 /* land units react */ #define MI_MAX 15 struct genlist { - struct emp_qelem queue; /* list of units */ - int type; /* type of unit */ - int x,y; /* x,y it came from */ - s_char *cp; /* pointer to desc of thing */ - s_char *thing; /* thing's struct */ + struct emp_qelem queue; /* list of units */ + int type; /* type of unit */ + int x, y; /* x,y it came from */ + s_char *cp; /* pointer to desc of thing */ + s_char *thing; /* thing's struct */ }; -#define SECT_HARDTARGET (-92917) /* a very low number that no-one might pick */ +#define SECT_HARDTARGET (-92917) /* a very low number that no-one might pick */ #endif /* _MISSION_H_ */ diff --git a/include/nat.h b/include/nat.h index cbb4200dc..242f3bb74 100644 --- a/include/nat.h +++ b/include/nat.h @@ -39,47 +39,47 @@ #include "mission.h" #include "sect.h" -#define MAXNOR 50 /* max # realms */ +#define MAXNOR 50 /* max # realms */ -struct boundstr { - short b_xl, b_xh; /* horizontal bounds */ - short b_yl, b_yh; /* vertical bounds */ +struct boundstr { + short b_xl, b_xh; /* horizontal bounds */ + short b_yl, b_yh; /* vertical bounds */ }; -struct natstr { - short ef_type; - s_char nat_cnam[20]; /* country name */ - s_char nat_pnam[20]; /* representative */ - s_char nat_hostaddr[32]; /* host addr of last user */ - s_char nat_hostname[512]; /* hostname of last user */ - s_char nat_userid[32]; /* userid of last user */ - coord nat_xstart, nat_ystart; /* cap location at start */ - coord nat_xcap, nat_ycap; /* cap location in abs coords */ - coord nat_xorg, nat_yorg; /* origin location in abs coords */ - natid nat_cnum; /* our country number */ - s_char nat_stat; /* inuse, norm, god, abs */ - s_char nat_dayno; /* day of the year mod 128 */ - s_char nat_connected; /* connected or not? */ - s_char nat_update; /* Want an update or not. */ - u_char nat_missed; /* How many updates missed */ - u_short nat_tgms; /* # of telegrams to be announced */ - u_short nat_ann; /* # of annos pending */ - u_short nat_minused; /* number of minutes used today */ - short nat_btu; /* bureaucratic time units */ - long nat_reserve; /* military reserves */ - long nat_money; /* moola */ - time_t nat_last_login; /* time of last login */ - time_t nat_last_logout; /* time of last logout */ - time_t nat_newstim; /* date news last read */ - time_t nat_annotim; /* date annos last read */ - float nat_level[4]; /* technology, etc */ - struct boundstr nat_b[MAXNOR]; /* realm bounds */ - short nat_relate[MAXNOC]; - short nat_contact[MAXNOC]; /* short for everyone */ - short nat_rejects[(MAXNOC+3)/4]; /* four bits for each country */ - s_char nat_priorities[SCT_MAXDEF+8]; /* priority for each SCT_MAXDEF+8*/ - long nat_flags; /* nation flags */ - s_char nat_mission_trigger[MI_MAX]; /* not used -- relation to trig */ +struct natstr { + short ef_type; + s_char nat_cnam[20]; /* country name */ + s_char nat_pnam[20]; /* representative */ + s_char nat_hostaddr[32]; /* host addr of last user */ + s_char nat_hostname[512]; /* hostname of last user */ + s_char nat_userid[32]; /* userid of last user */ + coord nat_xstart, nat_ystart; /* cap location at start */ + coord nat_xcap, nat_ycap; /* cap location in abs coords */ + coord nat_xorg, nat_yorg; /* origin location in abs coords */ + natid nat_cnum; /* our country number */ + s_char nat_stat; /* inuse, norm, god, abs */ + s_char nat_dayno; /* day of the year mod 128 */ + s_char nat_connected; /* connected or not? */ + s_char nat_update; /* Want an update or not. */ + u_char nat_missed; /* How many updates missed */ + u_short nat_tgms; /* # of telegrams to be announced */ + u_short nat_ann; /* # of annos pending */ + u_short nat_minused; /* number of minutes used today */ + short nat_btu; /* bureaucratic time units */ + long nat_reserve; /* military reserves */ + long nat_money; /* moola */ + time_t nat_last_login; /* time of last login */ + time_t nat_last_logout; /* time of last logout */ + time_t nat_newstim; /* date news last read */ + time_t nat_annotim; /* date annos last read */ + float nat_level[4]; /* technology, etc */ + struct boundstr nat_b[MAXNOR]; /* realm bounds */ + short nat_relate[MAXNOC]; + short nat_contact[MAXNOC]; /* short for everyone */ + short nat_rejects[(MAXNOC + 3) / 4]; /* four bits for each country */ + s_char nat_priorities[SCT_MAXDEF + 8]; /* priority for each SCT_MAXDEF+8 */ + long nat_flags; /* nation flags */ + s_char nat_mission_trigger[MI_MAX]; /* not used -- relation to trig */ }; /* Priorities */ @@ -91,12 +91,12 @@ struct natstr { #define PRI_LBUILD SCT_MAXDEF+7 /* nation status types */ -#define STAT_INUSE bit(0) /* cnum in use */ -#define STAT_SANCT bit(1) /* country in sanctuary */ -#define STAT_NORM bit(2) /* normal country */ -#define STAT_GOD bit(3) /* deity powers */ -#define STAT_ABS bit(4) /* abs coords */ -#define STAT_NEW bit(5) /* just initialized */ +#define STAT_INUSE bit(0) /* cnum in use */ +#define STAT_SANCT bit(1) /* country in sanctuary */ +#define STAT_NORM bit(2) /* normal country */ +#define STAT_GOD bit(3) /* deity powers */ +#define STAT_ABS bit(4) /* abs coords */ +#define STAT_NEW bit(5) /* just initialized */ /* Update fields. */ #define WUPD_WANT bit(0) @@ -119,10 +119,10 @@ struct natstr { #define ALLIED 6 /* nation reject codes */ -#define REJ_TELE bit(0) /* dont allow telegrams to be sent */ -#define REJ_TREA bit(1) /* dont allow treaties to be offered */ -#define REJ_ANNO bit(2) /* don't receive announcements */ -#define REJ_LOAN bit(3) /* don't allow loans to be offered */ +#define REJ_TELE bit(0) /* dont allow telegrams to be sent */ +#define REJ_TREA bit(1) /* dont allow treaties to be offered */ +#define REJ_ANNO bit(2) /* don't receive announcements */ +#define REJ_LOAN bit(3) /* don't allow loans to be offered */ #define NAT_TLEV 0 #define NAT_RLEV 1 @@ -144,19 +144,19 @@ struct natstr { #define NF_NATID NF_UCHAR #define NF_COORD NF_SHORT -#define FOUND_FLY 3 /* Number of updates contact lasts */ -#define FOUND_LOOK 5 /* These are only useful with the */ -#define FOUND_SPY 6 /* LOSE_CONTACT option (and HIDDEN) */ +#define FOUND_FLY 3 /* Number of updates contact lasts */ +#define FOUND_LOOK 5 /* These are only useful with the */ +#define FOUND_SPY 6 /* LOSE_CONTACT option (and HIDDEN) */ #define FOUND_MAP 6 #define FOUND_TELE 3 #define FOUND_COAST 3 struct fixnat { - s_char *name; - int type; - int index; - int notify; - int offset; + s_char *name; + int type; + int index; + int notify; + int offset; }; /* procedures relating to nation stuff */ @@ -172,35 +172,35 @@ extern double techfact(int level, double mult); extern double techfactfire(int level, double mult); extern double reltech(int level1, int level2, double mult); /* src/lib/subs/comsub.c */ -extern double multread(natid , natid ); -extern int commread(void ); -extern int commwrite(void ); -extern int commlock(void ); -extern int communlock(void ); -extern int commamt(natid , int , float * ); -extern void commset(natid , int , int ); -extern void multset(natid , float ); -extern void commprice(int , float * ); +extern double multread(natid, natid); +extern int commread(void); +extern int commwrite(void); +extern int commlock(void); +extern int communlock(void); +extern int commamt(natid, int, float *); +extern void commset(natid, int, int); +extern void multset(natid, float); +extern void commprice(int, float *); extern s_char *cname(natid n); extern s_char *relatename(struct natstr *np, natid other); extern s_char *rejectname(struct natstr *np, natid other); extern s_char *natstate(struct natstr *np); -extern int getrel(struct natstr *np, natid them); -extern int getrejects(natid them, struct natstr *np); -extern int getcontact(struct natstr *np, natid them); -extern void putrel(struct natstr *np, natid them, int relate); -extern void putreject(struct natstr *np, natid them, int how, int what); -extern void putcontact(struct natstr *np, natid them, int contact); -extern void agecontact(struct natstr *np); -extern struct fixnat *natfield(); - -#define NF_INFORM bit(0) /* Inform me of telegrams right away */ -#define NF_FLASH bit(1) /* Allow other players to flash me (sicko :) */ -#define NF_BEEP bit(2) /* Make beeping sounds when appropriate */ -#define NF_COASTWATCH bit(3) /* Turn auto-coastwatch on */ -#define NF_SONAR bit(4) /* Turn auto-sonar on */ -#define NF_TECHLISTS bit(5) /* Sort lists by tech not type */ -#define NF_SACKED bit(6) /* Capital was sacked, and hasn't been reset yet */ +extern int getrel(struct natstr *np, natid them); +extern int getrejects(natid them, struct natstr *np); +extern int getcontact(struct natstr *np, natid them); +extern void putrel(struct natstr *np, natid them, int relate); +extern void putreject(struct natstr *np, natid them, int how, int what); +extern void putcontact(struct natstr *np, natid them, int contact); +extern void agecontact(struct natstr *np); +extern struct fixnat *natfield(); + +#define NF_INFORM bit(0) /* Inform me of telegrams right away */ +#define NF_FLASH bit(1) /* Allow other players to flash me (sicko :) */ +#define NF_BEEP bit(2) /* Make beeping sounds when appropriate */ +#define NF_COASTWATCH bit(3) /* Turn auto-coastwatch on */ +#define NF_SONAR bit(4) /* Turn auto-sonar on */ +#define NF_TECHLISTS bit(5) /* Sort lists by tech not type */ +#define NF_SACKED bit(6) /* Capital was sacked, and hasn't been reset yet */ #endif /* _NAT_H_ */ diff --git a/include/news.h b/include/news.h index f933e717c..1443c5be6 100644 --- a/include/news.h +++ b/include/news.h @@ -41,22 +41,22 @@ #ifndef _NEWS_H_ #define _NEWS_H_ -struct nwsstr { - short ef_type; - natid nws_ano; /* "actor" country # */ - short nws_uid; - s_char nws_vrb; /* action (verb) */ - natid nws_vno; /* "victim" country # */ - s_char nws_ntm; /* number of times */ - time_t nws_when; /* time of action */ +struct nwsstr { + short ef_type; + natid nws_ano; /* "actor" country # */ + short nws_uid; + s_char nws_vrb; /* action (verb) */ + natid nws_vno; /* "victim" country # */ + s_char nws_ntm; /* number of times */ + time_t nws_when; /* time of action */ }; #define NUM_RPTS 2 /* number of story alternates */ -struct rptstr { - int r_good_will; /* how "nice" the action is */ - int r_newspage; /* which page this item belongs on */ - s_char *r_newstory[NUM_RPTS]; /* texts for fmt( */ +struct rptstr { + int r_good_will; /* how "nice" the action is */ + int r_newspage; /* which page this item belongs on */ + s_char *r_newstory[NUM_RPTS]; /* texts for fmt( */ }; /* news verbs */ @@ -157,7 +157,7 @@ struct rptstr { #define N_TELE 11 #define N_MAX_PAGE 11 -#define NEWS_PERIOD days(10) +#define NEWS_PERIOD days(10) #define getnews(n, p) \ ef_read(EF_NEWS, n, (caddr_t)p) @@ -166,8 +166,8 @@ struct rptstr { #define getnewsp(n) \ (struct nwsstr *) ef_ptr(EF_NEWS, n) -extern struct rptstr rpt[]; +extern struct rptstr rpt[]; -extern int nws_maxno; +extern int nws_maxno; #endif /* _NEWS_H_ */ diff --git a/include/nsc.h b/include/nsc.h index d323b7947..aea2ad146 100644 --- a/include/nsc.h +++ b/include/nsc.h @@ -40,42 +40,42 @@ #define NS_LSIZE 128 #define NS_NCOND 16 -struct nscstr { - long fld1; /* first commodity or number */ - long fld2; /* second commodity or number */ - int oper; /* required relationship operator */ +struct nscstr { + long fld1; /* first commodity or number */ + long fld2; /* second commodity or number */ + int oper; /* required relationship operator */ }; struct nstr_sect { - coord x, y; /* current x-y */ - coord dx, dy; /* accumlated x,y travel */ - int id; /* return value of sctoff */ - int type; /* type of query */ - int curdist; /* dist query: current range */ - struct range range; /* area of coverage */ - int dist; /* dist query: range */ - coord cx, cy; /* dist query: center x-y */ - int (*read)(); /* read function */ - int ncond; /* # of selection conditions */ - struct nscstr cond[NS_NCOND]; /* selection conditions */ + coord x, y; /* current x-y */ + coord dx, dy; /* accumlated x,y travel */ + int id; /* return value of sctoff */ + int type; /* type of query */ + int curdist; /* dist query: current range */ + struct range range; /* area of coverage */ + int dist; /* dist query: range */ + coord cx, cy; /* dist query: center x-y */ + int (*read) (); /* read function */ + int ncond; /* # of selection conditions */ + struct nscstr cond[NS_NCOND]; /* selection conditions */ }; struct nstr_item { - int cur; /* current item */ - int sel; /* selection type */ - int type; /* item type being selected */ - int curdist; /* if NS_DIST, current item's dist */ - struct range range; /* NS_AREA/NS_DIST: range selector */ - int dist; /* NS_DIST: distance selector */ - coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */ - int group; /* NS_GROUP: fleet/wing match */ - int size; /* NS_LIST: size of list */ - int index; /* NS_LIST: index */ - int list[NS_LSIZE]; /* NS_LIST: item list */ - int (*read)(); /* read function */ - int flags; /* EFF_ flags */ - int ncond; /* # of selection conditions */ - struct nscstr cond[NS_NCOND]; /* selection conditions */ + int cur; /* current item */ + int sel; /* selection type */ + int type; /* item type being selected */ + int curdist; /* if NS_DIST, current item's dist */ + struct range range; /* NS_AREA/NS_DIST: range selector */ + int dist; /* NS_DIST: distance selector */ + coord cx, cy; /* NS_DIST: center x-y, NS_XY: xy */ + int group; /* NS_GROUP: fleet/wing match */ + int size; /* NS_LIST: size of list */ + int index; /* NS_LIST: index */ + int list[NS_LSIZE]; /* NS_LIST: item list */ + int (*read) (); /* read function */ + int flags; /* EFF_ flags */ + int ncond; /* # of selection conditions */ + struct nscstr cond[NS_NCOND]; /* selection conditions */ }; #define NS_UNDEF 0 @@ -105,7 +105,7 @@ struct nstr_item { */ #define NSC_VAL (0) /* normal number */ #define NSC_VAR (1<<16) /* is a vtype */ -#define NSC_OFF (2<<16) /* is an offset */ +#define NSC_OFF (2<<16) /* is an offset */ #define NSC_CMASK (3<<16) /* @@ -117,11 +117,11 @@ struct nstr_item { #define NSC_USHORT (4<<18) /* pointer to unsigned short */ #define NSC_INT (5<<18) /* pointer to int */ #define NSC_LONG (6<<18) /* pointer to long */ -#define NSC_XCOORD (7<<18) /* pointer to short that needs x conversion */ -#define NSC_YCOORD (8<<18) /* pointer to short that needs y conversion */ -#define NSC_FLOAT (9<<18) /* pointer to float */ -#define NSC_CHARP (10<<18) /* pointer to string pointer */ -#define NSC_TIME (11<<18) /* pointer to time_t */ +#define NSC_XCOORD (7<<18) /* pointer to short that needs x conversion */ +#define NSC_YCOORD (8<<18) /* pointer to short that needs y conversion */ +#define NSC_FLOAT (9<<18) /* pointer to float */ +#define NSC_CHARP (10<<18) /* pointer to string pointer */ +#define NSC_TIME (11<<18) /* pointer to time_t */ #define NSC_TMASK (15<<18) #define NSC_NATID NSC_UCHAR /* change if natid typedef changes */ @@ -131,37 +131,37 @@ struct nstr_item { #define NSC_ROUND (1<<22) #define NSC_DEITY (1<<23) -struct castr { - long ca_code; /* encoded form */ - s_char *ca_name; /* name used for matches */ - u_short ca_len; /* Used for arrays */ - long ca_edv; /* which commands is this field visible to? */ +struct castr { + long ca_code; /* encoded form */ + s_char *ca_name; /* name used for matches */ + u_short ca_len; /* Used for arrays */ + long ca_edv; /* which commands is this field visible to? */ }; /* variables using the above */ -extern struct castr var_ca[]; -extern struct castr sect_ca[]; -extern struct castr ship_ca[]; -extern struct castr plane_ca[]; -extern struct castr land_ca[]; -extern struct castr nuke_ca[]; -extern struct castr news_ca[]; -extern struct castr nat_ca[]; -extern struct castr treaty_ca[]; -extern struct castr trade_ca[]; -extern struct castr loan_ca[]; -extern struct castr genitem_ca[]; -extern struct castr map_ca[]; -extern struct castr bmp_ca[]; -extern struct castr ca[]; -extern struct castr commodity_ca[]; +extern struct castr var_ca[]; +extern struct castr sect_ca[]; +extern struct castr ship_ca[]; +extern struct castr plane_ca[]; +extern struct castr land_ca[]; +extern struct castr nuke_ca[]; +extern struct castr news_ca[]; +extern struct castr nat_ca[]; +extern struct castr treaty_ca[]; +extern struct castr trade_ca[]; +extern struct castr loan_ca[]; +extern struct castr genitem_ca[]; +extern struct castr map_ca[]; +extern struct castr bmp_ca[]; +extern struct castr ca[]; +extern struct castr commodity_ca[]; /* src/lib/subs/nstr.c */ -extern s_char * nstr_comp(struct nscstr * , int * , int , s_char * ); -extern int encode(register s_char * , long * , int ); +extern s_char *nstr_comp(struct nscstr *, int *, int, s_char *); +extern int encode(register s_char *, long *, int); -extern s_char *decodep _PROTO((register long code, register void *addr)); +extern s_char *decodep _PROTO((register long code, register void *addr)); #endif /* _NSC_H_ */ diff --git a/include/nuke.h b/include/nuke.h index 2c86e085b..bd05fbbc4 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -36,31 +36,31 @@ #define N_MAXNUKE 15 -struct nukstr { - short ef_type; - natid nuk_own; - short nuk_uid; - coord nuk_x; /* current loc of device */ - coord nuk_y; - s_char nuk_n; /* number of nukes in list */ - short nuk_ship; /* currently aboard ship */ - short nuk_trade; /* index into trade file */ - short nuk_types[N_MAXNUKE]; /* # of nukes in sector of given type */ - time_t nuk_timestamp; /* Last time this nuke was touched */ +struct nukstr { + short ef_type; + natid nuk_own; + short nuk_uid; + coord nuk_x; /* current loc of device */ + coord nuk_y; + s_char nuk_n; /* number of nukes in list */ + short nuk_ship; /* currently aboard ship */ + short nuk_trade; /* index into trade file */ + short nuk_types[N_MAXNUKE]; /* # of nukes in sector of given type */ + time_t nuk_timestamp; /* Last time this nuke was touched */ }; struct nchrstr { - s_char *n_name; /* warhead unit name */ - int n_lcm; /* costs to build */ - int n_hcm; - int n_oil; - int n_rad; - int n_blast; /* blast radius */ - int n_dam; /* damage at center */ - int n_cost; - int n_tech; /* tech needed to build */ - int n_weight; - int n_flags; /* description of capability */ + s_char *n_name; /* warhead unit name */ + int n_lcm; /* costs to build */ + int n_hcm; + int n_oil; + int n_rad; + int n_blast; /* blast radius */ + int n_dam; /* damage at center */ + int n_cost; + int n_tech; /* tech needed to build */ + int n_weight; + int n_flags; /* description of capability */ }; #define N_NEUT bit(0) /* Neutron bomb (low damage, high fallout) */ @@ -72,8 +72,8 @@ struct nchrstr { #define getnukep(n) \ (struct nukstr *) ef_ptr(EF_NUKE, n) -extern struct nchrstr nchr[]; +extern struct nchrstr nchr[]; -extern int nuk_maxno; +extern int nuk_maxno; #endif /* _NUKE_H_ */ diff --git a/include/options.h b/include/options.h index dc081f936..18b06c733 100644 --- a/include/options.h +++ b/include/options.h @@ -41,87 +41,83 @@ #include "gamesdef.h" -/* #define NO_LCMS */ /* No lcms needed */ -/* #define NO_HCMS */ /* No hcms needed */ +/* #define NO_LCMS *//* No lcms needed */ +/* #define NO_HCMS *//* No hcms needed */ -/* #define NO_FORT_FIRE */ /* Forts cannot fire */ +/* #define NO_FORT_FIRE *//* Forts cannot fire */ -#define BRIDGETOWERS /* Bridge towers are enabled */ +#define BRIDGETOWERS /* Bridge towers are enabled */ -#define GODNEWS /* We inform the world when deities give/take away */ +#define GODNEWS /* We inform the world when deities give/take away */ -#define LANDSPIES /* Enable the land unit type spies */ +#define LANDSPIES /* Enable the land unit type spies */ -#define START_CASH 25000 /* set starting cash when capitol created */ +#define START_CASH 25000 /* set starting cash when capitol created */ - /* Setting BLITZ sets a couple of things. + /* Setting BLITZ sets a couple of things. 1. BTU's always max when you login. 2. Changing name doesn't take any btus or $$ enables BLITZ updates, also turns on NOFOOD, below */ /*#define START_UNITS 2 *//* How many free start units you get. Types are - specified in src/lib/global/constants.c */ + specified in src/lib/global/constants.c */ -/* #define SHIP_DECAY */ /* Allows ships at sea to decay */ -#define PLANENAMES /* Use real names for planes, not the boring ones :) */ +/* #define SHIP_DECAY *//* Allows ships at sea to decay */ +#define PLANENAMES /* Use real names for planes, not the boring ones :) */ -/* #define GO_RENEW */ /* Gold and Oil are renewable resources */ +/* #define GO_RENEW *//* Gold and Oil are renewable resources */ -/* #define DEFENSE_INFRA */ /* Allow the improvement of defensive infrastructure */ +/* #define DEFENSE_INFRA *//* Allow the improvement of defensive infrastructure */ -/*#define MOB_ACCESS */ /* Mobility updates real-time */ -/*#define TECH_POP */ /* Technology costs more as population rises */ - -/*#define MARKET */ /* Time-based MARKET and TRADING */ -#define LOANS /* Bail out other countries via S&L scandals */ -#define TREATIES /* Sign treaties with your friends and enemies */ +/*#define MOB_ACCESS *//* Mobility updates real-time */ +/*#define TECH_POP *//* Technology costs more as population rises */ -/*#define HIDDEN*/ /* Hides information between players */ -/*#define LOSE_CONTACT*/ /* Allows contact to be lost after a few updates */ +/*#define MARKET *//* Time-based MARKET and TRADING */ +#define LOANS /* Bail out other countries via S&L scandals */ +#define TREATIES /* Sign treaties with your friends and enemies */ + +/*#define HIDDEN*//* Hides information between players */ +/*#define LOSE_CONTACT*//* Allows contact to be lost after a few updates */ /* Chainsaw Mods */ -/*#define NONUKES*/ /* Eliminates nukes */ -#ifndef NO_OIL /* Can't have fuel with no oil! */ -/*#define FUEL*/ /* Ships use fuel to move */ +/*#define NONUKES*//* Eliminates nukes */ +#ifndef NO_OIL /* Can't have fuel with no oil! */ +/*#define FUEL*//* Ships use fuel to move */ #endif -/*#define TRADESHIPS*/ /* Use Tradeships */ -/*#define SLOW_WAR*/ /* Declaring war takes time */ -/*#define SNEAK_ATTACK*/ /* Allows sneak attacks */ -#define ORBIT /* Satalites will orbit each update */ -#define PINPOINTMISSILE /**/ -#define FALLOUT /* Enables secondary effects caused by radiation */ -#define SAIL /* A update routine to move ships */ -#define SHIPNAMES /* Name your ships, removing this option saves space */ -#define NEUTRON /* Enables Neurton Warheads */ -#define NEWPOWER /* Better power formula */ -#define NOMOBCOST /* No mob cost for firing from ships */ -/*#define SUPER_BARS */ /* Bars can't be destroyed by fire */ -#define EASY_BRIDGES /* Bridges can be built anywhere */ -#define ALL_BLEED /* Tech bleeds to everyone */ -/*#define DRNUKE*/ /* Need research to make nukes */ -#define NO_PLAGUE /* Plague is disabled */ -#define NEW_STARVE /* UW's starve, then civs, then mil */ -#define NEW_WORK /* Work is changed in proportion to the # of civs mvd */ -/*#define RES_POP*/ /* population is limited by research */ -/*#define GRAB_THINGS*/ /* units will grab things they need to build */ -/*#define BIG_CITY */ /* allow 10x civs in 'c' sectors */ -#define INTERDICT_ATT /* interdict post-attack move in */ - -#define SHOWPLANE /**/ +/*#define TRADESHIPS*//* Use Tradeships */ +/*#define SLOW_WAR*//* Declaring war takes time */ +/*#define SNEAK_ATTACK*//* Allows sneak attacks */ +#define ORBIT /* Satalites will orbit each update */ +#define PINPOINTMISSILE /**/ +#define FALLOUT /* Enables secondary effects caused by radiation */ +#define SAIL /* A update routine to move ships */ +#define SHIPNAMES /* Name your ships, removing this option saves space */ +#define NEUTRON /* Enables Neurton Warheads */ +#define NEWPOWER /* Better power formula */ +#define NOMOBCOST /* No mob cost for firing from ships */ +/*#define SUPER_BARS *//* Bars can't be destroyed by fire */ +#define EASY_BRIDGES /* Bridges can be built anywhere */ +#define ALL_BLEED /* Tech bleeds to everyone */ +/*#define DRNUKE*//* Need research to make nukes */ +#define NO_PLAGUE /* Plague is disabled */ +#define NEW_STARVE /* UW's starve, then civs, then mil */ +#define NEW_WORK /* Work is changed in proportion to the # of civs mvd */ +/*#define RES_POP*//* population is limited by research */ +/*#define GRAB_THINGS*//* units will grab things they need to build */ +/*#define BIG_CITY *//* allow 10x civs in 'c' sectors */ +#define INTERDICT_ATT /* interdict post-attack move in */ +#define SHOWPLANE /**/ #define NUKEFAILDETONATE /**/ -#define MISSINGMISSILES /* Missiles have a change to miss the target */ -#define UPDATESCHED /* Used to controle update times and should always */ -#ifdef UPDATESCHED /* be used */ -#define DEMANDUPDATE /* NOTE! Depends on UPDATESCHED! Don't use without it! */ +#define MISSINGMISSILES /* Missiles have a change to miss the target */ +#define UPDATESCHED /* Used to controle update times and should always */ +#ifdef UPDATESCHED /* be used */ +#define DEMANDUPDATE /* NOTE! Depends on UPDATESCHED! Don't use without it! */ #endif /* UPDATESCHED */ - #ifdef BLITZ #define NOFOOD /* automatically have no food for blitzes */ #endif /* BLITZ */ /*#define NOFOOD*/ /**/ - #ifndef SLOW_WAR -#undef SNEAK_ATTACK /* SNEAK_ATTACK is only useful with SLOW_WAR */ +#undef SNEAK_ATTACK /* SNEAK_ATTACK is only useful with SLOW_WAR */ #endif /* SLOW_WAR */ - #endif /* _OPTIONS_H_ */ diff --git a/include/optlist.h b/include/optlist.h index eff0ad14b..477735ed4 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -39,7 +39,7 @@ struct option_list { char *opt_key; - int *opt_valuep; + int *opt_valuep; }; extern struct option_list Options[]; @@ -103,24 +103,24 @@ extern int opt_TECH_POP; struct keymatch; /* forward decl */ /* function prototype for variable setting routines */ -typedef void KmFunc _PROTO((struct keymatch *kp, s_char **av)); +typedef void KmFunc _PROTO((struct keymatch * kp, s_char **av)); /* current known routines */ #if defined(__cplusplus) || (defined(__STDC__) &&__STDC__) -KmFunc optstrset, intset, floatset, doubleset, longset, - optionset, optiondel, worldxset; +KmFunc optstrset, intset, floatset, doubleset, longset, + optionset, optiondel, worldxset; #else -void optstrset(), intset(), floatset(), doubleset(), longset(), - optionset(), optiondel(), worldxset(); +void optstrset(), intset(), floatset(), doubleset(), longset(), +optionset(), optiondel(), worldxset(); #endif struct keymatch { - s_char *km_key; /* the key */ - KmFunc *km_func; /* the function to call if matches */ - caddr_t km_data; /* associated data */ - int km_flags; /* useful flags */ + s_char *km_key; /* the key */ + KmFunc *km_func; /* the function to call if matches */ + caddr_t km_data; /* associated data */ + int km_flags; /* useful flags */ #define KM_ALLOC 0x01 /* memory allocated */ - s_char *km_comment; /* Comment (hopefully useful) */ + s_char *km_comment; /* Comment (hopefully useful) */ }; extern struct keymatch configkeys[]; diff --git a/include/path.h b/include/path.h index 1c0e6841c..b990bc3e5 100644 --- a/include/path.h +++ b/include/path.h @@ -34,8 +34,8 @@ #ifndef _PATH_H_ #define _PATH_H_ -#include "misc.h" /* s_char coord etc. */ -#include "sect.h" /* struct sctstr */ +#include "misc.h" /* s_char coord etc. */ +#include "sect.h" /* struct sctstr */ #include "xy.h" /* direction indices */ @@ -51,30 +51,31 @@ #define DIR_FIRST 1 #define DIR_LAST 6 -#define SELL_NOT_DELIV 7 /* in "_use" field => contract */ +#define SELL_NOT_DELIV 7 /* in "_use" field => contract */ -extern int dirindex[]; -extern int diroff[][2]; -extern s_char dirch[]; +extern int dirindex[]; +extern int diroff[][2]; +extern s_char dirch[]; /* src/lib/subs/paths.c */ -extern s_char * getpath(s_char * , s_char * , coord , coord , int , int, - int , int ); -extern double fcost(struct sctstr * , natid ); -extern double ncost(struct sctstr * , natid ); -extern double pathtoxy(s_char * , coord * , coord * , double (* )(struct sctstr *sp, natid own)); -extern int chkdir(s_char , int , int ); -extern int getdir(s_char * , s_char * , s_char * , s_char * ); -extern void direrr(s_char * , s_char * , s_char * ); -extern double mcost(struct sctstr * , int ); -extern int chkpath(natid , s_char * , coord , coord ); -extern void pathrange(register coord , register coord , register s_char *, - int , struct range * ); +extern s_char *getpath(s_char *, s_char *, coord, coord, int, int, + int, int); +extern double fcost(struct sctstr *, natid); +extern double ncost(struct sctstr *, natid); +extern double pathtoxy(s_char *, coord *, coord *, + double (*)(struct sctstr * sp, natid own)); +extern int chkdir(s_char, int, int); +extern int getdir(s_char *, s_char *, s_char *, s_char *); +extern void direrr(s_char *, s_char *, s_char *); +extern double mcost(struct sctstr *, int); +extern int chkpath(natid, s_char *, coord, coord); +extern void pathrange(register coord, register coord, register s_char *, + int, struct range *); -extern s_char *masktopath(); -extern long pathtomask(); +extern s_char *masktopath(); +extern long pathtomask(); -extern double sector_mcost(); +extern double sector_mcost(); #define P_NONE 0 /* NO destinations allowed */ #define P_WALKING 1 /* use BestLandPath, only owned */ diff --git a/include/plane.h b/include/plane.h index e7bdbc18b..3becdf3a2 100644 --- a/include/plane.h +++ b/include/plane.h @@ -46,36 +46,36 @@ * exactly equivalent with shp_x to shp_fleet */ struct plnstr { - short ef_type; - natid pln_own; /* owning country */ - short pln_uid; /* plane unit id */ - coord pln_x; /* plane x-y */ - coord pln_y; - s_char pln_type; /* fighter, bomber, etc */ - s_char pln_effic; /* actually "training" */ - s_char pln_mobil; /* plane mobility */ - short pln_sell; /* index into trade file */ - short pln_tech; /* plane's tech level */ - s_char pln_wing; /* like fleet */ - coord pln_opx; /* Op sector coords */ - coord pln_opy; /* Op sector coords */ - short pln_mission; /* mission code */ - short pln_radius; /* mission radius */ - u_char pln_range; /* total distance, not radius */ - u_char pln_range_max; /* max range for this plane */ - short pln_ship; /* pointer to carrier */ - short pln_land; /* pointer to carrier */ - int pln_att; /* plane air-air attack/defense values */ - int pln_def; - int pln_acc; - int pln_load; - int pln_fuel; - s_char pln_harden; /* for missiles */ - s_char pln_nuketype; /* type of nuclear armament (if any) */ - s_char pln_flags; /* State of the plane */ - time_t pln_access; /* Last time mob was updated (MOB_ACCESS) */ - time_t pln_timestamp; /* Last time this plane was touched */ - float pln_theta; /* position in orbital sine wave */ + short ef_type; + natid pln_own; /* owning country */ + short pln_uid; /* plane unit id */ + coord pln_x; /* plane x-y */ + coord pln_y; + s_char pln_type; /* fighter, bomber, etc */ + s_char pln_effic; /* actually "training" */ + s_char pln_mobil; /* plane mobility */ + short pln_sell; /* index into trade file */ + short pln_tech; /* plane's tech level */ + s_char pln_wing; /* like fleet */ + coord pln_opx; /* Op sector coords */ + coord pln_opy; /* Op sector coords */ + short pln_mission; /* mission code */ + short pln_radius; /* mission radius */ + u_char pln_range; /* total distance, not radius */ + u_char pln_range_max; /* max range for this plane */ + short pln_ship; /* pointer to carrier */ + short pln_land; /* pointer to carrier */ + int pln_att; /* plane air-air attack/defense values */ + int pln_def; + int pln_acc; + int pln_load; + int pln_fuel; + s_char pln_harden; /* for missiles */ + s_char pln_nuketype; /* type of nuclear armament (if any) */ + s_char pln_flags; /* State of the plane */ + time_t pln_access; /* Last time mob was updated (MOB_ACCESS) */ + time_t pln_timestamp; /* Last time this plane was touched */ + float pln_theta; /* position in orbital sine wave */ }; #define PLN_LAUNCHED bit(0) /* A satellite that's in orbit */ @@ -83,59 +83,59 @@ struct plnstr { #define PLN_AIRBURST bit(2) /* Airburst the nuke we're armed with */ struct plchrstr { - s_char *pl_name; /* plane vanilla unit name */ - s_char *pl_planename; /* plane real name */ - int pl_lcm; /* costs to build */ - int pl_hcm; - int pl_cost; - int pl_tech; /* tech needed to build */ - int pl_acc; /* bombing accuracy (higher the better) */ - int pl_load; /* bomb load, also for carrying cargo */ - int pl_att; /* air-air attack/defense strengths */ - int pl_def; - int pl_range; /* how many sectors it can fly */ - int pl_crew; /* number of mil to crew it */ - int pl_fuel; /* fuel consumption */ - int pl_stealth; /* how stealthy is it? */ - int pl_flags; /* description of capability */ + s_char *pl_name; /* plane vanilla unit name */ + s_char *pl_planename; /* plane real name */ + int pl_lcm; /* costs to build */ + int pl_hcm; + int pl_cost; + int pl_tech; /* tech needed to build */ + int pl_acc; /* bombing accuracy (higher the better) */ + int pl_load; /* bomb load, also for carrying cargo */ + int pl_att; /* air-air attack/defense strengths */ + int pl_def; + int pl_range; /* how many sectors it can fly */ + int pl_crew; /* number of mil to crew it */ + int pl_fuel; /* fuel consumption */ + int pl_stealth; /* how stealthy is it? */ + int pl_flags; /* description of capability */ }; -#define P_B bit(0) /* bombing factor only for bombing */ -#define P_T bit(1) /* tactical bombing ability */ -#define P_F bit(2) /* interceptor/escort */ -#define P_C bit(3) /* bombing factor for transport only */ -#define P_V bit(4) /* vtol ability */ -#define P_M bit(5) /* missile, used only once, can't be intercepted */ -#define P_L bit(6) /* light plane, lands on carriers */ -#define P_S bit(7) /* Spy ability */ -#define P_I bit(8) /* Imaging ability (advanced spying) */ -#define P_O bit(9) /* Orbital ability (a satellite) */ -#define P_X bit(10) /* Stealth ability */ -#define P_N bit(11) /* Nuclear RV interceptor (abm) */ -#define P_H bit(12) /* Half stealthy */ -#define P_E bit(13) /* extra light */ -#define P_K bit(14) /* chopper */ -#define P_A bit(15) /* ASW (Anti-Sub Warfare) */ -#define P_P bit(16) /* paradropping */ -#define P_ESC bit(17) /* escort */ -#define P_MINE bit(18) /* can lay mines */ -#define P_SWEEP bit(19) /* can sweep mines */ -#define P_MAR bit(20) /* missile can hit ships */ - -#define PM_R bit(0) /* Recon mission */ -#define PM_S bit(1) /* Mine-sweeping mission */ +#define P_B bit(0) /* bombing factor only for bombing */ +#define P_T bit(1) /* tactical bombing ability */ +#define P_F bit(2) /* interceptor/escort */ +#define P_C bit(3) /* bombing factor for transport only */ +#define P_V bit(4) /* vtol ability */ +#define P_M bit(5) /* missile, used only once, can't be intercepted */ +#define P_L bit(6) /* light plane, lands on carriers */ +#define P_S bit(7) /* Spy ability */ +#define P_I bit(8) /* Imaging ability (advanced spying) */ +#define P_O bit(9) /* Orbital ability (a satellite) */ +#define P_X bit(10) /* Stealth ability */ +#define P_N bit(11) /* Nuclear RV interceptor (abm) */ +#define P_H bit(12) /* Half stealthy */ +#define P_E bit(13) /* extra light */ +#define P_K bit(14) /* chopper */ +#define P_A bit(15) /* ASW (Anti-Sub Warfare) */ +#define P_P bit(16) /* paradropping */ +#define P_ESC bit(17) /* escort */ +#define P_MINE bit(18) /* can lay mines */ +#define P_SWEEP bit(19) /* can sweep mines */ +#define P_MAR bit(20) /* missile can hit ships */ + +#define PM_R bit(0) /* Recon mission */ +#define PM_S bit(1) /* Mine-sweeping mission */ #define PLN_MAXDEF 50 /* internal to "fly" module -- really shouldn't be here */ struct plist { - struct emp_qelem queue; /* list of planes */ - int state; /* state of plane */ - int bombs; /* bombs carried for bombing mission */ - int misc; /* amount of random item being transported */ - struct plchrstr *pcp; /* pointer to desc of plane */ - struct plnstr plane; /* struct plane */ + struct emp_qelem queue; /* list of planes */ + int state; /* state of plane */ + int bombs; /* bombs carried for bombing mission */ + int misc; /* amount of random item being transported */ + struct plchrstr *pcp; /* pointer to desc of plane */ + struct plnstr plane; /* struct plane */ }; #define P_OK 0 @@ -149,15 +149,15 @@ struct plist { #define getplanep(n) \ (struct plnstr *) ef_ptr(EF_PLANE, n) -extern struct plchrstr plchr[]; -extern int pln_maxno; +extern struct plchrstr plchr[]; +extern int pln_maxno; - struct shiplook{ - short uid; - u_char looked; - u_char found; - struct shiplook *next; - }; +struct shiplook { + short uid; + u_char looked; + u_char found; + struct shiplook *next; +}; #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20)))) #define PLN_ACC(b, t) (b * (1.0 - (sqrt((double)t) / 50.))) @@ -168,39 +168,39 @@ extern int pln_maxno; double sqrt(); double logx(); -float pln_damage_sect(); +float pln_damage_sect(); -void count_planes(); -double sqrt(); -s_char *prplane(); +void count_planes(); +double sqrt(); +s_char *prplane(); /* src/lib/subs/aircombat.c */ -extern void ac_planedamage(struct plist * , natid , int , natid , int , - int , s_char * ); -extern void ac_intercept(struct emp_qelem * , struct emp_qelem * , - struct emp_qelem * , natid , coord , coord); -extern void ac_combat_headers(natid , natid ); -extern void ac_airtoair(struct emp_qelem * , struct emp_qelem * , natid ); -extern void ac_doflak(struct emp_qelem * , struct sctstr * ); -extern void ac_shipflak(struct emp_qelem * , coord , coord ); -extern void ac_landflak(struct emp_qelem * , coord , coord ); -extern void ac_fireflak(struct emp_qelem * , natid , natid , int ); -extern void ac_encounter(struct emp_qelem * , struct emp_qelem * , coord , - coord , s_char * , int , int , +extern void ac_planedamage(struct plist *, natid, int, natid, int, + int, s_char *); +extern void ac_intercept(struct emp_qelem *, struct emp_qelem *, + struct emp_qelem *, natid, coord, coord); +extern void ac_combat_headers(natid, natid); +extern void ac_airtoair(struct emp_qelem *, struct emp_qelem *, natid); +extern void ac_doflak(struct emp_qelem *, struct sctstr *); +extern void ac_shipflak(struct emp_qelem *, coord, coord); +extern void ac_landflak(struct emp_qelem *, coord, coord); +extern void ac_fireflak(struct emp_qelem *, natid, natid, int); +extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord, + coord, s_char *, int, int, struct emp_qelem *, struct emp_qelem *); extern int ac_isflying(struct plnstr *, struct emp_qelem *); -extern int do_evade(struct emp_qelem * , struct emp_qelem * ); -extern void sam_intercept(struct emp_qelem * , struct emp_qelem * , - natid , natid , coord , coord , int ); -extern int all_missiles(struct emp_qelem * ); -extern int can_fly(int ); +extern int do_evade(struct emp_qelem *, struct emp_qelem *); +extern void sam_intercept(struct emp_qelem *, struct emp_qelem *, + natid, natid, coord, coord, int); +extern int all_missiles(struct emp_qelem *); +extern int can_fly(int); /* src/lib/subs/aswplnsubs.c */ -extern int have_looked(u_char , struct shiplook * ); -extern int have_found(u_char , struct shiplook * ); -extern void set_have_looked(u_char , struct shiplook * ); -extern void set_have_found(u_char , struct shiplook * ); -extern int print_found(struct shiplook * ); +extern int have_looked(u_char, struct shiplook *); +extern int have_found(u_char, struct shiplook *); +extern void set_have_looked(u_char, struct shiplook *); +extern void set_have_found(u_char, struct shiplook *); +extern int print_found(struct shiplook *); #endif /* _PLANE_H_ */ diff --git a/include/player.h b/include/player.h index cae5093aa..a1744fb2d 100644 --- a/include/player.h +++ b/include/player.h @@ -46,38 +46,38 @@ #include "empthread.h" struct player { - struct emp_qelem queue; - empth_t *proc; - s_char hostaddr[32]; - s_char hostname[512]; - s_char client[128]; - s_char userid[32]; - int validated; - natid cnum; - int state; - struct cmndstr *command; - struct iop *iop; - s_char combuf[1024]; - s_char *argp[128]; - s_char *condarg; - time_t lasttime; - int ncomstat; - int minleft; - int btused; - int visitor; - int god; - int owner; - int nstat; - int waiting; - int simulation; /* e.g. budget command */ - double dolcost; - int broke; - time_t curup; /* used in calc of minutes used */ - int aborted; - int curid; /* for pr, cur. line's id, -1 none */ - int blitz_time; - char *map; /* pointer to in-mem map */ - char *bmap; /* pointer to in-mem bmap */ + struct emp_qelem queue; + empth_t *proc; + s_char hostaddr[32]; + s_char hostname[512]; + s_char client[128]; + s_char userid[32]; + int validated; + natid cnum; + int state; + struct cmndstr *command; + struct iop *iop; + s_char combuf[1024]; + s_char *argp[128]; + s_char *condarg; + time_t lasttime; + int ncomstat; + int minleft; + int btused; + int visitor; + int god; + int owner; + int nstat; + int waiting; + int simulation; /* e.g. budget command */ + double dolcost; + int broke; + time_t curup; /* used in calc of minutes used */ + int aborted; + int curid; /* for pr, cur. line's id, -1 none */ + int blitz_time; + char *map; /* pointer to in-mem map */ + char *bmap; /* pointer to in-mem bmap */ }; #define PS_INIT 0 @@ -95,12 +95,6 @@ struct player { #define PP_ACCEPT 3 #define PP_KILLIDLE 2 -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _PLAYER_H_ */ - - - - - - diff --git a/include/power.h b/include/power.h index 43f414656..27339c21e 100644 --- a/include/power.h +++ b/include/power.h @@ -35,24 +35,24 @@ #define _POWER_H_ struct powstr { - natid p_nation; - float p_sects; - float p_effic; - float p_civil; - float p_milit; - float p_shell; - float p_guns; - float p_petrol; - float p_iron; - float p_dust; - float p_food; - float p_oil; - float p_bars; - float p_planes; - float p_ships; - float p_units; - float p_money; - float p_power; + natid p_nation; + float p_sects; + float p_effic; + float p_civil; + float p_milit; + float p_shell; + float p_guns; + float p_petrol; + float p_iron; + float p_dust; + float p_food; + float p_oil; + float p_bars; + float p_planes; + float p_ships; + float p_units; + float p_money; + float p_power; }; #define getpower(n, p) \ diff --git a/include/product.h b/include/product.h index 2b1b6ed6d..c0de4c4fd 100644 --- a/include/product.h +++ b/include/product.h @@ -34,21 +34,21 @@ #ifndef _PRODUCT_H_ #define _PRODUCT_H_ -struct pchrstr { - u_char p_nv; /* number of constituents */ - u_char p_vtype[MAXCHRNV];/* constituent types */ - u_short p_vamt[MAXCHRNV]; /* constituent amounts */ - int p_type; /* vtype if product is a variable */ - int p_level; /* index (NAT_?LEV) if product is not a var */ - int p_cost; /* dollars / product unit */ - int p_nrndx; /* index into sect of natural resource */ - int p_nrdep; /* depletion as a % of resource used */ - int p_nlndx; /* index (NAT_?LEV) affecting production */ - int p_nlmin; /* minimum lvl required */ - int p_nllag; /* lag, mul by (lvl-nlmin)/(lvl-nlmin+nllag) */ - int p_effic; /* process efficiency, mult by p_effic/100 */ - s_char *p_name; /* name of product */ - s_char *p_sname; /* short (7char or less) name of product */ +struct pchrstr { + u_char p_nv; /* number of constituents */ + u_char p_vtype[MAXCHRNV]; /* constituent types */ + u_short p_vamt[MAXCHRNV]; /* constituent amounts */ + int p_type; /* vtype if product is a variable */ + int p_level; /* index (NAT_?LEV) if product is not a var */ + int p_cost; /* dollars / product unit */ + int p_nrndx; /* index into sect of natural resource */ + int p_nrdep; /* depletion as a % of resource used */ + int p_nlndx; /* index (NAT_?LEV) affecting production */ + int p_nlmin; /* minimum lvl required */ + int p_nllag; /* lag, mul by (lvl-nlmin)/(lvl-nlmin+nllag) */ + int p_effic; /* process efficiency, mult by p_effic/100 */ + s_char *p_name; /* name of product */ + s_char *p_sname; /* short (7char or less) name of product */ }; #define P_SHELL 1 @@ -68,8 +68,8 @@ struct pchrstr { #define P_URAN 15 #define P_MDUST 16 -extern struct pchrstr pchr[]; +extern struct pchrstr pchr[]; -extern int prd_maxno; +extern int prd_maxno; #endif /* _PRODUCT_H_ */ diff --git a/include/prototypes.h b/include/prototypes.h index 9c1c70b93..a6ee30889 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -57,294 +57,297 @@ extern emp_sig_t shutdwn(int sig); /* src/lib/empthread/lwp.c */ #ifdef _EMPTH_LWP -extern int empth_init (char **ctx, int flags); -extern empth_t *empth_create (int prio, void (*entry)(), int size, - int flags, char *name, char *desc, void *ud); +extern int empth_init(char **ctx, int flags); +extern empth_t *empth_create(int prio, void (*entry) (), int size, + int flags, char *name, char *desc, void *ud); #if 0 extern void empth_setctx(void *ctx); #endif extern empth_t *empth_self(void); -extern void empth_exit (void); -extern void empth_yield (void); +extern void empth_exit(void); +extern void empth_yield(void); extern void empth_terminate(empth_t *a); extern void empth_select(int fd, int flags); extern void empth_wakeup(empth_t *a); extern void empth_sleep(long int until); extern empth_sem_t *empth_sem_create(char *name, int cnt); extern void empth_sem_signal(empth_sem_t *sm); -extern void empth_sem_wait (empth_sem_t *sm); +extern void empth_sem_wait(empth_sem_t *sm); extern emp_sig_t empth_alarm(int sig); #endif /* _EMPTH_LWP */ /* src/lib/empthread/pthread.c */ #ifdef _EMPTH_POSIX -extern void *empth_start(void *ctx); -extern int empth_init (char **ctx_ptr, int flags); -extern empth_t *empth_create (int prio, void (*entry)(), - int size, int flags, - char *name, char *desc, void *ud); -extern empth_t *empth_self(void); -extern void empth_exit (void); -extern void empth_yield (void); -extern void empth_terminate(empth_t *a); -extern void empth_select(int fd, int flags); -extern emp_sig_t empth_alarm(int sig); -extern void empth_wakeup(empth_t *a); -extern void empth_sleep(long until); +extern void *empth_start(void *ctx); +extern int empth_init(char **ctx_ptr, int flags); +extern empth_t *empth_create(int prio, void (*entry) (), + int size, int flags, + char *name, char *desc, void *ud); +extern empth_t *empth_self(void); +extern void empth_exit(void); +extern void empth_yield(void); +extern void empth_terminate(empth_t *a); +extern void empth_select(int fd, int flags); +extern emp_sig_t empth_alarm(int sig); +extern void empth_wakeup(empth_t *a); +extern void empth_sleep(long until); extern empth_sem_t *empth_sem_create(char *name, int cnt); -extern void empth_sem_signal(empth_sem_t *sm); -extern void empth_sem_wait (empth_sem_t *sm); +extern void empth_sem_signal(empth_sem_t *sm); +extern void empth_sem_wait(empth_sem_t *sm); #endif /* _EMPTH_POSIX */ - + /* * src/lib/commands/ *.c */ -extern int acce(void ); -extern int add(void ); -extern int anti(void ); -extern int arm(void ); -extern int army(void ); -extern int assa(void ); -extern int atta(void ); -extern int bdes(void ); -extern int best(void ); -extern int boar(void ); -extern int pinflak_planedamage(struct plnstr * , struct plchrstr * , natid , int ); -extern int bomb(void ); -extern int brea(void ); -extern s_char * dotsprintf(s_char * , s_char * , int ); -extern int goodsect(char ); -extern void prexpense(long , int * , s_char , int ); -extern int budg(void ); -extern int buil(void ); -extern int buy(void ); -extern int check_market(void ); -extern int capi(void ); -extern int carg(void ); -extern int lcarg(void ); -extern int cede_sect(struct nstr_sect * , natid ); -extern void grab_sect(register struct sctstr * , natid ); -extern int cede_ship(struct nstr_item * , natid ); -extern void grab_ship(register struct shpstr * , natid ); -extern int cede(void ); -extern int cens(void ); -extern void set_coastal(struct sctstr * ); -extern int chan(void ); -extern int coas(void ); -extern int coll(void ); -extern int comm(void ); -extern int cons(void ); -extern long do_conv(struct nstr_sect , int , int ); -extern int conv(void ); -extern int coun(void ); -extern int cuto(void ); -extern int decl(void ); -extern int deli(void ); -extern long do_demo(struct natstr * , struct nstr_sect , int , s_char * , int ); -extern int demo(void ); -extern long do_desi(struct natstr * , s_char * , s_char * , long , int ); -extern int desi(void ); -extern int disa(void ); -extern int diss(void ); -extern int dist(void ); -extern int drop(void ); -extern int dump(void ); -extern int echo(void ); -extern int doland(s_char , int , struct sctstr * ); -extern int docountry(s_char , int , s_char * , float , natid , struct natstr * ); -extern int doship(s_char , int , s_char * , struct shpstr * ); -extern int dounit(s_char , int , s_char * , struct lndstr * ); -extern int doplane(s_char , int , s_char * , struct plnstr * ); -extern int edit(void ); -extern int getin(s_char * * , s_char * * , int * , s_char *); -extern int errcheck(int , int , int ); -extern int enab(void ); -extern int enli(void ); -extern int explore(void ); -extern int fina(void ); -extern int flash(void ); -extern int sendmessage(struct natstr * , struct natstr * , char * , int ); -extern int wall(void ); -extern int flee(void ); -extern int fly(void ); -extern int foll(void ); -extern int force(void ); -extern int fort(void ); -extern int is_engineer(int , int ); -extern int fuel(void ); -extern int give(void ); -extern int grin(void ); -extern int hard(void ); -extern int head(void ); -extern int hidd(void ); -extern int improve(void ); -extern int info(void ); -extern int apro(void ); -extern int land(void ); -extern int laun(void ); -extern int ldump(void ); -extern int ledg(void ); -extern int leve(void ); -extern void gift(int , int , s_char * , int , s_char * ); -extern int load(void ); -extern int lload(void ); -extern int look(void ); -extern int llook(void ); -extern int lost(void ); -extern int lstats(void ); -extern int ltend(void ); -extern int map(void ); -extern int march(void ); -extern int mark(void ); -extern int display_mark(s_char * ); -extern int quiet_bigdef(int , struct emp_qelem * , natid , natid , coord , coord , int * ); -extern int multifire(void ); -extern void use_ammo(struct emp_qelem * ); -extern void do_defdam(struct emp_qelem * , double ); -extern void add_to_fired_queue(struct emp_qelem * , struct emp_qelem * ); -extern int mine(void ); -extern int landmine(void ); -extern int mission(void ); -extern int mobq(void ); +extern int acce(void); +extern int add(void); +extern int anti(void); +extern int arm(void); +extern int army(void); +extern int assa(void); +extern int atta(void); +extern int bdes(void); +extern int best(void); +extern int boar(void); +extern int pinflak_planedamage(struct plnstr *, struct plchrstr *, natid, + int); +extern int bomb(void); +extern int brea(void); +extern s_char *dotsprintf(s_char *, s_char *, int); +extern int goodsect(char); +extern void prexpense(long, int *, s_char, int); +extern int budg(void); +extern int buil(void); +extern int buy(void); +extern int check_market(void); +extern int capi(void); +extern int carg(void); +extern int lcarg(void); +extern int cede_sect(struct nstr_sect *, natid); +extern void grab_sect(register struct sctstr *, natid); +extern int cede_ship(struct nstr_item *, natid); +extern void grab_ship(register struct shpstr *, natid); +extern int cede(void); +extern int cens(void); +extern void set_coastal(struct sctstr *); +extern int chan(void); +extern int coas(void); +extern int coll(void); +extern int comm(void); +extern int cons(void); +extern long do_conv(struct nstr_sect, int, int); +extern int conv(void); +extern int coun(void); +extern int cuto(void); +extern int decl(void); +extern int deli(void); +extern long do_demo(struct natstr *, struct nstr_sect, int, s_char *, int); +extern int demo(void); +extern long do_desi(struct natstr *, s_char *, s_char *, long, int); +extern int desi(void); +extern int disa(void); +extern int diss(void); +extern int dist(void); +extern int drop(void); +extern int dump(void); +extern int echo(void); +extern int doland(s_char, int, struct sctstr *); +extern int docountry(s_char, int, s_char *, float, natid, struct natstr *); +extern int doship(s_char, int, s_char *, struct shpstr *); +extern int dounit(s_char, int, s_char *, struct lndstr *); +extern int doplane(s_char, int, s_char *, struct plnstr *); +extern int edit(void); +extern int getin(s_char **, s_char **, int *, s_char *); +extern int errcheck(int, int, int); +extern int enab(void); +extern int enli(void); +extern int explore(void); +extern int fina(void); +extern int flash(void); +extern int sendmessage(struct natstr *, struct natstr *, char *, int); +extern int wall(void); +extern int flee(void); +extern int fly(void); +extern int foll(void); +extern int force(void); +extern int fort(void); +extern int is_engineer(int, int); +extern int fuel(void); +extern int give(void); +extern int grin(void); +extern int hard(void); +extern int head(void); +extern int hidd(void); +extern int improve(void); +extern int info(void); +extern int apro(void); +extern int land(void); +extern int laun(void); +extern int ldump(void); +extern int ledg(void); +extern int leve(void); +extern void gift(int, int, s_char *, int, s_char *); +extern int load(void); +extern int lload(void); +extern int look(void); +extern int llook(void); +extern int lost(void); +extern int lstats(void); +extern int ltend(void); +extern int map(void); +extern int march(void); +extern int mark(void); +extern int display_mark(s_char *); +extern int quiet_bigdef(int, struct emp_qelem *, natid, natid, coord, + coord, int *); +extern int multifire(void); +extern void use_ammo(struct emp_qelem *); +extern void do_defdam(struct emp_qelem *, double); +extern void add_to_fired_queue(struct emp_qelem *, struct emp_qelem *); +extern int mine(void); +extern int landmine(void); +extern int mission(void); +extern int mobq(void); extern int mobupdate(void); -extern int morale(void ); -extern int move(void ); -extern int want_to_abandon(struct sctstr * , int , int, struct lndstr * ); -extern int would_abandon(struct sctstr * , int , int, struct lndstr * ); -extern int mult(void ); -extern int name(void ); -extern int nati(void ); -extern int navi(void ); -extern int nav_map(int , int , int ); -extern int ndump(void ); -extern int new(void ); -extern int deity_build_land(int , coord , coord , natid , int ); -extern int newe(void ); -extern int news(void ); -extern int nuke(void ); -extern int offe(void ); -extern int offs(void ); -extern int orde(void ); -extern int qorde(void ); -extern int sorde(void ); -extern int orig(void ); -extern int para(void ); -extern int path(void ); -extern int pdump(void ); -extern int plan(void ); -extern int play(void ); -extern int powe(void ); -extern int set_target(s_char * , int * ); -extern int count_pop(register int ); -extern int prod(void ); -extern int pstat(void ); -extern int rada(void ); -extern int range(void ); -extern int lrange(void ); -extern int rea(void ); -extern int real(void ); -extern int reco(void ); -extern int reje(void ); -extern int rela(void ); -extern int repa(void ); -extern int repo(void ); -extern int rese(void ); -extern int reso(void ); -extern int retr(void ); -extern int lretr(void ); -extern int rout(void ); -extern int sail(void ); -extern int sate(void ); -extern int scra(void ); +extern int morale(void); +extern int move(void); +extern int want_to_abandon(struct sctstr *, int, int, struct lndstr *); +extern int would_abandon(struct sctstr *, int, int, struct lndstr *); +extern int mult(void); +extern int name(void); +extern int nati(void); +extern int navi(void); +extern int nav_map(int, int, int); +extern int ndump(void); +extern int new(void); +extern int deity_build_land(int, coord, coord, natid, int); +extern int newe(void); +extern int news(void); +extern int nuke(void); +extern int offe(void); +extern int offs(void); +extern int orde(void); +extern int qorde(void); +extern int sorde(void); +extern int orig(void); +extern int para(void); +extern int path(void); +extern int pdump(void); +extern int plan(void); +extern int play(void); +extern int powe(void); +extern int set_target(s_char *, int *); +extern int count_pop(register int); +extern int prod(void); +extern int pstat(void); +extern int rada(void); +extern int range(void); +extern int lrange(void); +extern int rea(void); +extern int real(void); +extern int reco(void); +extern int reje(void); +extern int rela(void); +extern int repa(void); +extern int repo(void); +extern int rese(void); +extern int reso(void); +extern int retr(void); +extern int lretr(void); +extern int rout(void); +extern int sail(void); +extern int sate(void); +extern int scra(void); extern int scuttle_tradeship(struct shpstr *, int); -extern int scut(void ); -extern void scuttle_ship(struct shpstr * ); -extern void scuttle_land(struct lndstr * ); -extern int sdump(void ); -extern int sct(void ); -extern int sell(void ); -extern int set(void ); -extern int setres(void ); -extern int setsector(void ); -extern void resnoise(struct sctstr *sptr, int public_amt, s_char *name, int old, int new); -extern int shar(void ); -extern int shark(void ); -extern int shi(void ); -extern int shoo(void ); -extern int show(void ); -extern int shut(void ); -extern int sinfra(void ); -extern int skyw(void ); +extern int scut(void); +extern void scuttle_ship(struct shpstr *); +extern void scuttle_land(struct lndstr *); +extern int sdump(void); +extern int sct(void); +extern int sell(void); +extern int set(void); +extern int setres(void); +extern int setsector(void); +extern void resnoise(struct sctstr *sptr, int public_amt, s_char *name, + int old, int new); +extern int shar(void); +extern int shark(void); +extern int shi(void); +extern int shoo(void); +extern int show(void); +extern int shut(void); +extern int sinfra(void); +extern int skyw(void); extern int line_of_sight(s_char **rad, int ax, int ay, int bx, int by); -extern int sona(void ); -extern int blankrow(s_char * ); -extern void plane_sona(struct emp_qelem * , int , int , struct shiplook * ); -extern int spy(void ); -extern int num_units(int , int ); -extern void prunits(int , int ); -extern void prplanes(int , int ); -extern int sstat(void ); -extern int start(void ); -extern int stop(void ); -extern int stre(void ); -extern int starve(void ); -extern int supp(void ); -extern int surv(void ); -extern int swaps(void ); -extern void print_res(struct sctstr * ); -extern int tele(void ); -extern int tend(void ); -extern int tend_nxtitem(struct nstr_item * , caddr_t ); -extern int terr(void ); -extern int thre(void ); -extern int togg(void ); -extern void anti_torp(int , int , int ); -extern void fire_dchrg(struct shpstr * , struct shpstr * , int , int ); -extern s_char * prsub(struct shpstr * ); -extern int torp(void ); -extern int canshoot(struct shpstr * , struct shpstr * ); -extern int cantorp(struct shpstr * , struct shpstr * ); -extern int fire_torp(struct shpstr * , struct shpstr * , int , int ); -extern int candchrg(struct shpstr * , struct shpstr * ); -extern int trad(void ); -extern int check_trade(void ); -extern int ontradingblock(int , int * ); -extern void trdswitchown(int , int * , int ); -extern int tran(void ); -extern int trea(void ); -extern int turn(void ); -extern int upda(void ); -extern int upgr(void ); -extern int supgr(void ); -extern int pupgr(void ); -extern int lupgr(void ); -extern int vers(void ); -extern int wai(void ); -extern int wing(void ); -extern int wipe(void ); -extern int work(void ); -extern int buildeff(struct sctstr * , int , double * ); -extern int zdon(void ); +extern int sona(void); +extern int blankrow(s_char *); +extern void plane_sona(struct emp_qelem *, int, int, struct shiplook *); +extern int spy(void); +extern int num_units(int, int); +extern void prunits(int, int); +extern void prplanes(int, int); +extern int sstat(void); +extern int start(void); +extern int stop(void); +extern int stre(void); +extern int starve(void); +extern int supp(void); +extern int surv(void); +extern int swaps(void); +extern void print_res(struct sctstr *); +extern int tele(void); +extern int tend(void); +extern int tend_nxtitem(struct nstr_item *, caddr_t); +extern int terr(void); +extern int thre(void); +extern int togg(void); +extern void anti_torp(int, int, int); +extern void fire_dchrg(struct shpstr *, struct shpstr *, int, int); +extern s_char *prsub(struct shpstr *); +extern int torp(void); +extern int canshoot(struct shpstr *, struct shpstr *); +extern int cantorp(struct shpstr *, struct shpstr *); +extern int fire_torp(struct shpstr *, struct shpstr *, int, int); +extern int candchrg(struct shpstr *, struct shpstr *); +extern int trad(void); +extern int check_trade(void); +extern int ontradingblock(int, int *); +extern void trdswitchown(int, int *, int); +extern int tran(void); +extern int trea(void); +extern int turn(void); +extern int upda(void); +extern int upgr(void); +extern int supgr(void); +extern int pupgr(void); +extern int lupgr(void); +extern int vers(void); +extern int wai(void); +extern int wing(void); +extern int wipe(void); +extern int work(void); +extern int buildeff(struct sctstr *, int, double *); +extern int zdon(void); /* * src/lib/common/ *.c */ /* bestpath.c */ -extern s_char * bestownedpath(s_char * , s_char * , int , int , int , - int , s_char * , int ); +extern s_char *bestownedpath(s_char *, s_char *, int, int, int, + int, s_char *, int); /* bridgefall.c */ -extern void bridgefall(struct sctstr * , struct emp_qelem *); +extern void bridgefall(struct sctstr *, struct emp_qelem *); extern void knockdown(struct sctstr *, struct emp_qelem *); /* damage.c */ -extern void landdamage(struct lndstr * , int ); -extern void ship_damage(struct shpstr * , int ); -extern int damage(register int , int ); -extern void shipdamage(struct shpstr * , int ); -extern void land_damage(struct lndstr * , int ); -extern void planedamage(struct plnstr * , int ); -extern int nukedamage(struct nchrstr * , int , int ); -extern int effdamage(register int , int ); -extern int commdamage(register int , int , int ); +extern void landdamage(struct lndstr *, int); +extern void ship_damage(struct shpstr *, int); +extern int damage(register int, int); +extern void shipdamage(struct shpstr *, int); +extern void land_damage(struct lndstr *, int); +extern void planedamage(struct plnstr *, int); +extern int nukedamage(struct nchrstr *, int, int); +extern int effdamage(register int, int); +extern int commdamage(register int, int, int); /* check.c */ extern int check_sect_ok(struct sctstr *); extern int check_ship_ok(struct shpstr *); @@ -354,151 +357,150 @@ extern int check_plane_ok(struct plnstr *); extern int check_comm_ok(struct comstr *); extern int check_loan_ok(struct lonstr *); /* fsize.c */ -extern int fsize(int ); -extern int blksize(int ); -extern time_t fdate(int ); -extern void filetruncate(s_char * ); +extern int fsize(int); +extern int blksize(int); +extern time_t fdate(int); +extern void filetruncate(s_char *); /* getvar.c */ -extern int getvar(int , s_char * , int ); -extern int getvec(int , int * , s_char * , int ); -extern int putvar(int , int , s_char * , int ); -extern int putvec(int , int * , s_char * , int ); +extern int getvar(int, s_char *, int); +extern int getvec(int, int *, s_char *, int); +extern int putvar(int, int, s_char *, int); +extern int putvec(int, int *, s_char *, int); /* hap_fact.c */ -extern double hap_fact(struct natstr * , struct natstr * ); +extern double hap_fact(struct natstr *, struct natstr *); /* hours.c */ -extern int gamehours(time_t , int * ); +extern int gamehours(time_t, int *); /* land.c */ -extern int has_units(coord , coord , natid, struct lndstr * ); -extern int has_units_with_mob(coord , coord , natid ); -extern int adj_units(coord , coord , natid ); +extern int has_units(coord, coord, natid, struct lndstr *); +extern int has_units_with_mob(coord, coord, natid); +extern int adj_units(coord, coord, natid); /* log.c */ -extern void loginit(void ); -extern void logerror(s_char *, ...); +extern void loginit(void); +extern void logerror(s_char *, ...); extern void filelogerror(s_char *, ...); /* maps.c */ -extern int draw_map(int , s_char , int , struct nstr_sect * , int ); -extern int bmnxtsct(register struct nstr_sect * ); -extern void bitinit2(struct nstr_sect * , u_char * , int ); -extern int unit_map(int , int , struct nstr_sect * , s_char * ); -extern int bmaps_intersect(natid , natid ); -extern int share_bmap(natid , natid , struct nstr_sect * , s_char , - s_char * ); +extern int draw_map(int, s_char, int, struct nstr_sect *, int); +extern int bmnxtsct(register struct nstr_sect *); +extern void bitinit2(struct nstr_sect *, u_char *, int); +extern int unit_map(int, int, struct nstr_sect *, s_char *); +extern int bmaps_intersect(natid, natid); +extern int share_bmap(natid, natid, struct nstr_sect *, s_char, s_char *); /* move.c */ -extern double sector_mcost(struct sctstr * , int ); +extern double sector_mcost(struct sctstr *, int); /* nstr_subs.c */ -extern s_char * decodep(long , void * ); -extern int decode(natid , long , void * , int ); -extern int nstr_exec(struct nscstr * , register int , void * , int ); +extern s_char *decodep(long, void *); +extern int decode(natid, long, void *, int); +extern int nstr_exec(struct nscstr *, register int, void *, int); /* path.c */ -extern s_char * bp_init(void ); -extern int best_path(struct sctstr * , struct sctstr * , s_char * , int); +extern s_char *bp_init(void); +extern int best_path(struct sctstr *, struct sctstr *, s_char *, int); extern void bp_enable_cachepath(); extern void bp_disable_cachepath(); extern void bp_clear_cachepath(); -extern s_char * BestDistPath(s_char * , struct sctstr * , struct sctstr * , - double * , int ); -extern s_char * BestLandPath(s_char * , struct sctstr * , struct sctstr * , - double * , int ); -extern s_char * BestShipPath(s_char *, int, int, int, int, int); -extern s_char * BestAirPath(s_char *, int, int, int, int); -extern double pathcost(struct sctstr * , s_char * , int ); +extern s_char *BestDistPath(s_char *, struct sctstr *, struct sctstr *, + double *, int); +extern s_char *BestLandPath(s_char *, struct sctstr *, struct sctstr *, + double *, int); +extern s_char *BestShipPath(s_char *, int, int, int, int, int); +extern s_char *BestAirPath(s_char *, int, int, int, int); +extern double pathcost(struct sctstr *, s_char *, int); /* res_pop.c */ -extern int max_pop(float , struct sctstr * ); +extern int max_pop(float, struct sctstr *); /* sectdamage.c */ -extern int sect_damage(struct sctstr * , int, struct emp_qelem * ); -extern int sectdamage(struct sctstr * , int, struct emp_qelem * ); +extern int sect_damage(struct sctstr *, int, struct emp_qelem *); +extern int sectdamage(struct sctstr *, int, struct emp_qelem *); /* snxtit_subs.c */ -extern void snxtitem_area(register struct nstr_item * , int, struct range *); -extern void snxtitem_dist(register struct nstr_item * , int , int, int, int); -extern void snxtitem_xy(register struct nstr_item * , int , coord , coord ); -extern void snxtitem_all(register struct nstr_item * , int ); -extern void snxtitem_group(register struct nstr_item * , int , s_char ); -extern void snxtitem_rewind(struct nstr_item * ); -extern int snxtitem_list(register struct nstr_item * , int , int * , int ); +extern void snxtitem_area(register struct nstr_item *, int, + struct range *); +extern void snxtitem_dist(register struct nstr_item *, int, int, int, int); +extern void snxtitem_xy(register struct nstr_item *, int, coord, coord); +extern void snxtitem_all(register struct nstr_item *, int); +extern void snxtitem_group(register struct nstr_item *, int, s_char); +extern void snxtitem_rewind(struct nstr_item *); +extern int snxtitem_list(register struct nstr_item *, int, int *, int); /* snxtsect_subs.c */ -extern void snxtsct_area(register struct nstr_sect * , struct range * ); -extern void xydist_range(coord , coord , register int , struct range * ); -extern void xysize_range(register struct range * ); -extern void snxtsct_all(struct nstr_sect * ); -extern void snxtsct_rewind(struct nstr_sect * ); -extern void snxtsct_dist(register struct nstr_sect * , coord , coord , int); +extern void snxtsct_area(register struct nstr_sect *, struct range *); +extern void xydist_range(coord, coord, register int, struct range *); +extern void xysize_range(register struct range *); +extern void snxtsct_all(struct nstr_sect *); +extern void snxtsct_rewind(struct nstr_sect *); +extern void snxtsct_dist(register struct nstr_sect *, coord, coord, int); /* stmtch.c */ -extern int stmtch(register s_char * , s_char * , int , int ); -extern int mineq(register s_char * , register s_char * ); +extern int stmtch(register s_char *, s_char *, int, int); +extern int mineq(register s_char *, register s_char *); /* type.c */ -extern int typematch(s_char * , int ); +extern int typematch(s_char *, int); /* vlist.c */ -extern int vl_find(register int , u_char * , u_short * , int ); -extern int vl_set(register int , u_int , u_char * , u_short * , - u_char * , int ); -extern int vl_damage(register int , register u_char * , register u_short *, - register int ); -extern int vl_getvec(register u_char * , register u_short * , register int, - register int , register int * ); -extern int vl_setvec(register u_char * , register u_short * , u_char * , - int , register int , register int * ); +extern int vl_find(register int, u_char *, u_short *, int); +extern int vl_set(register int, u_int, u_char *, u_short *, u_char *, int); +extern int vl_damage(register int, register u_char *, register u_short *, + register int); +extern int vl_getvec(register u_char *, register u_short *, register int, + register int, register int *); +extern int vl_setvec(register u_char *, register u_short *, u_char *, + int, register int, register int *); /* wantupd.c */ -extern int demand_update_want(int * , int * , int ); -extern int update_maxmissed(void ); -extern int demandupdatecheck(void ); -extern int update_between(void ); -extern int updatetime(time_t * ); -extern void demand_update_info(int * , int * , int * , int * ); -extern void next_update_time(time_t * , time_t * , time_t * ); -extern void next_update_check_time(time_t * , time_t * , time_t * ); -extern int updates_disabled(void ); +extern int demand_update_want(int *, int *, int); +extern int update_maxmissed(void); +extern int demandupdatecheck(void); +extern int update_between(void); +extern int updatetime(time_t *); +extern void demand_update_info(int *, int *, int *, int *); +extern void next_update_time(time_t *, time_t *, time_t *); +extern void next_update_check_time(time_t *, time_t *, time_t *); +extern int updates_disabled(void); /* * src/lib/gen/ *.c */ /* emp_config.c */ -extern int emp_config (char *file); -extern void print_config (FILE *fp); +extern int emp_config(char *file); +extern void print_config(FILE * fp); -extern int atoip(s_char * * ); -extern int atopi(s_char * ); -extern int roll(int ); -extern int roundavg(double ); -extern int chance(double ); -extern s_char * copy(register s_char * , register s_char * ); -extern void disassoc(void ); -extern int getfdtablesize(void ); -extern void setfdtablesize(int , int ); -extern s_char * getstarg(s_char * , s_char * , s_char * ); -extern s_char * getstring(s_char * , s_char * ); -extern int ifloor(double ); -extern int iceil(double ); +extern int atoip(s_char **); +extern int atopi(s_char *); +extern int roll(int); +extern int roundavg(double); +extern int chance(double); +extern s_char *copy(register s_char *, register s_char *); +extern void disassoc(void); +extern int getfdtablesize(void); +extern void setfdtablesize(int, int); +extern s_char *getstarg(s_char *, s_char *, s_char *); +extern s_char *getstring(s_char *, s_char *); +extern int ifloor(double); +extern int iceil(double); #if !defined(_WIN32) -extern s_char * inet_ntoa(struct in_addr ); +extern s_char *inet_ntoa(struct in_addr); #endif -extern int file_lock(int ); -extern int file_unlock(int ); -extern int deltax(int , int ); -extern int deltay(int , int ); -extern int mapdist(int , int , int , int ); -extern int mapdsq(int , int , int , int ); -extern double dmin(double , double ); +extern int file_lock(int); +extern int file_unlock(int); +extern int deltax(int, int); +extern int deltay(int, int); +extern int mapdist(int, int, int, int); +extern int mapdsq(int, int, int, int); +extern double dmin(double, double); #if !defined(_WIN32) -extern int max(int , int ); -extern int min(int , int ); +extern int max(int, int); +extern int min(int, int); #endif -extern double dmax(double , double ); -extern s_char * numstr(s_char * , int ); -extern s_char * effadv(int ); -extern int onearg(s_char * , s_char * ); -extern int parse(register s_char * , s_char * * , s_char * * , s_char * , - s_char * * ); -extern s_char * esplur(int ); -extern s_char * splur(int ); -extern s_char * iesplur(int ); -extern s_char * plur(int , s_char * , s_char * ); -extern int ldround(double , int ); -extern int roundintby(int , int ); -extern int same(register s_char * , register s_char * ); -extern int scthash(register int , register int , int ); -extern void blocksig(void ); -extern void unblocksig(void ); -extern const s_char * signame(int ); +extern double dmax(double, double); +extern s_char *numstr(s_char *, int); +extern s_char *effadv(int); +extern int onearg(s_char *, s_char *); +extern int parse(register s_char *, s_char **, s_char **, s_char *, + s_char **); +extern s_char *esplur(int); +extern s_char *splur(int); +extern s_char *iesplur(int); +extern s_char *plur(int, s_char *, s_char *); +extern int ldround(double, int); +extern int roundintby(int, int); +extern int same(register s_char *, register s_char *); +extern int scthash(register int, register int, int); +extern void blocksig(void); +extern void unblocksig(void); +extern const s_char *signame(int); #ifdef NOSTRDUP extern char *strdup(char *x); #endif @@ -508,10 +510,10 @@ extern int strscan(s_char *target, s_char *string); /* * src/lib/global/ *.c */ -extern void global_init(void ); -extern void init_pchr(void ); -extern void init_mchr(void ); -extern void init_plchr(void ); +extern void global_init(void); +extern void init_pchr(void); +extern void init_mchr(void); +extern void init_plchr(void); @@ -519,211 +521,212 @@ extern void init_plchr(void ); * src/lib/player/ *.c */ /* accept.c */ -extern void player_init(void ); -extern struct player * player_new(int , struct sockaddr_in * ); -extern struct player * player_delete(struct player * ); -extern struct player * player_next(struct player * ); -extern struct player * player_prev(struct player * ); -extern struct player * getplayer(natid ); -extern struct player * player_find_other(struct player * , register natid ); -extern void player_wakeup_all(natid ); -extern void player_wakeup(struct player * ); -extern void player_accept(void * ); +extern void player_init(void); +extern struct player *player_new(int, struct sockaddr_in *); +extern struct player *player_delete(struct player *); +extern struct player *player_next(struct player *); +extern struct player *player_prev(struct player *); +extern struct player *getplayer(natid); +extern struct player *player_find_other(struct player *, register natid); +extern void player_wakeup_all(natid); +extern void player_wakeup(struct player *); +extern void player_accept(void *); /* dispatch.c */ -extern int dispatch(s_char * , s_char * ); +extern int dispatch(s_char *, s_char *); /* empdis.c */ -extern int getcommand(s_char * ); -extern void init_player_commands(void ); -extern void log_last_commands(void ); -extern int explain(void ); -extern int gamedown(void ); -extern void daychange(time_t ); -extern void getconstants(void ); -extern int getminleft(time_t , int * , int * ); +extern int getcommand(s_char *); +extern void init_player_commands(void); +extern void log_last_commands(void); +extern int explain(void); +extern int gamedown(void); +extern void daychange(time_t); +extern void getconstants(void); +extern int getminleft(time_t, int *, int *); /* empmod.c */ /* init_nats.c */ -extern int init_nats(void ); -extern int nat_cap(int ); +extern int init_nats(void); +extern int nat_cap(int); /* login.c */ -extern void player_login(void * ); -extern int client_cmd(struct player * , int , char * * ); -extern int user_cmd(struct player * , int , char * * ); -extern int sanc_cmd(struct player * , int , char * * ); -extern int coun_cmd(struct player * , int , char * * ); -extern int pass_cmd(struct player * , int , char * * ); -extern int play_cmd(struct player * , int , char * * ); -extern int kill_cmd(struct player * , int , char * * ); -extern int list_cmd(struct player * , int , char * * ); -extern int quit_cmd(struct player * , int , char * * ); +extern void player_login(void *); +extern int client_cmd(struct player *, int, char **); +extern int user_cmd(struct player *, int, char **); +extern int sanc_cmd(struct player *, int, char **); +extern int coun_cmd(struct player *, int, char **); +extern int pass_cmd(struct player *, int, char **); +extern int play_cmd(struct player *, int, char **); +extern int kill_cmd(struct player *, int, char **); +extern int list_cmd(struct player *, int, char **); +extern int quit_cmd(struct player *, int, char **); /* nat.c */ -extern int natbyname(s_char * , natid * ); -extern int natpass(int , s_char * ); +extern int natbyname(s_char *, natid *); +extern int natpass(int, s_char *); /* player.c */ -extern struct player *player; /* current player's context */ -extern s_char * praddr(struct player * ); -extern void player_main(struct player * ); -extern int show_motd(void ); -extern int match_user(char * , struct player * ); -extern int status(void ); -extern int command(void ); -extern int execute(void ); -extern int quit(void ); +extern struct player *player; /* current player's context */ +extern s_char *praddr(struct player *); +extern void player_main(struct player *); +extern int show_motd(void); +extern int match_user(char *, struct player *); +extern int status(void); +extern int command(void); +extern int execute(void); +extern int quit(void); /* recvclient.c */ -extern int recvclient(s_char * , int ); +extern int recvclient(s_char *, int); /* * src/lib/subs/ *.c */ /* askyn.c */ -extern int confirm(s_char * ); -extern int askyn(s_char * ); +extern int confirm(s_char *); +extern int askyn(s_char *); /* bsanct.c */ -extern void bsanct(void ); +extern void bsanct(void); /* caploss.c */ -extern void caploss(struct sctstr * , natid , s_char * ); +extern void caploss(struct sctstr *, natid, s_char *); /* chkmoney.c */ -extern int chkmoney(long , long , s_char * ); -extern int check_cost(int , int , long , int * , s_char * ); +extern int chkmoney(long, long, s_char *); +extern int check_cost(int, int, long, int *, s_char *); /* cnumb.c */ -extern int cnumb(s_char * ); +extern int cnumb(s_char *); /* control.c */ -extern int military_control(struct sctstr * ); +extern int military_control(struct sctstr *); /* detonate.c */ -extern int detonate(struct plnstr * , int , int ); +extern int detonate(struct plnstr *, int, int); /* disloan.c */ -extern int disloan(int , register struct lonstr * ); +extern int disloan(int, register struct lonstr *); /* distrea.c */ -extern int distrea(int , register struct trtstr * ); +extern int distrea(int, register struct trtstr *); /* fileinit.c */ -extern void ef_init(void ); +extern void ef_init(void); /* fortdef.c */ -extern int sd(natid , natid , coord , coord , int , int , int ); -extern int dd(natid , natid , coord , coord , int , int ); -extern int sb(natid , natid , struct sctstr * , coord , coord , int, int); -extern int shipdef(natid , natid , coord , coord ); +extern int sd(natid, natid, coord, coord, int, int, int); +extern int dd(natid, natid, coord, coord, int, int); +extern int sb(natid, natid, struct sctstr *, coord, coord, int, int); +extern int shipdef(natid, natid, coord, coord); /* getbit.c */ -extern int emp_getbit(int , int , u_char * ); -extern void emp_setbit(int , int , u_char * ); -extern void emp_setbitmap(int ,int, u_char *, int *); -extern void emp_bitinit(struct nstr_sect * , u_char * ); +extern int emp_getbit(int, int, u_char *); +extern void emp_setbit(int, int, u_char *); +extern void emp_setbitmap(int, int, u_char *, int *); +extern void emp_bitinit(struct nstr_sect *, u_char *); /* getele.c */ -extern int getele(s_char * , s_char * ); +extern int getele(s_char *, s_char *); /* land.c */ -extern s_char * prland(struct lndstr * ); -extern int lnd_postread(int, s_char * ); -extern int lnd_prewrite(int , s_char * ); -extern void lnd_init(int , s_char * ); +extern s_char *prland(struct lndstr *); +extern int lnd_postread(int, s_char *); +extern int lnd_prewrite(int, s_char *); +extern void lnd_init(int, s_char *); /* landgun.c */ -extern double seagun(int , int ); -extern double landgun(int , int ); -extern double landunitgun(int, int, int, int, int ); -extern int roundrange(double ); +extern double seagun(int, int); +extern double landgun(int, int); +extern double landunitgun(int, int, int, int, int); +extern int roundrange(double); /* list.c */ -extern int shipsatxy(coord , coord , int , int ); -extern int carriersatxy(coord , coord , int , int , natid ); -extern int unitsatxy(coord , coord , int , int ); -extern int planesatxy(coord , coord , int , int, struct emp_qelem * ); -extern int asw_shipsatxy(coord , coord , int , int , struct plnstr * , - struct shiplook * ); -extern int num_shipsatxy(coord , coord , int , int ); -extern int islist(s_char * ); +extern int shipsatxy(coord, coord, int, int); +extern int carriersatxy(coord, coord, int, int, natid); +extern int unitsatxy(coord, coord, int, int); +extern int planesatxy(coord, coord, int, int, struct emp_qelem *); +extern int asw_shipsatxy(coord, coord, int, int, struct plnstr *, + struct shiplook *); +extern int num_shipsatxy(coord, coord, int, int); +extern int islist(s_char *); /* src/lib/subs/mission.c */ -extern s_char * mission_name(short ); -extern s_char * nameofitem(s_char * , struct genitem * , int ); -extern int collateral_damage(coord , coord , int , struct emp_qelem *); -extern int dosupport(struct genlist * , coord , coord , natid , natid ); -extern void build_mission_list(struct genlist * , coord, coord, int, natid ); -extern void build_mission_list_type(struct genlist *, coord, coord, int, int, - natid); -extern int perform_mission(coord , coord , natid , struct emp_qelem * , - int , s_char * , int ); -extern void mission_pln_sel(struct emp_qelem * , int , int , int ); -extern int mission_pln_arm(struct emp_qelem * , coord , coord , int , - int , struct ichrstr * , int , int , int * ); -extern int mission_pln_equip(struct plist * , struct ichrstr *, int, s_char); -extern int find_airport(struct emp_qelem * , coord , coord ); -extern void add_airport(struct emp_qelem * , coord , coord ); -extern void divide(struct emp_qelem * , struct emp_qelem * , coord , coord); -extern int air_damage(struct emp_qelem * , coord , coord , int , natid , +extern s_char *mission_name(short); +extern s_char *nameofitem(s_char *, struct genitem *, int); +extern int collateral_damage(coord, coord, int, struct emp_qelem *); +extern int dosupport(struct genlist *, coord, coord, natid, natid); +extern void build_mission_list(struct genlist *, coord, coord, int, natid); +extern void build_mission_list_type(struct genlist *, coord, coord, int, + int, natid); +extern int perform_mission(coord, coord, natid, struct emp_qelem *, int, + s_char *, int); +extern void mission_pln_sel(struct emp_qelem *, int, int, int); +extern int mission_pln_arm(struct emp_qelem *, coord, coord, int, + int, struct ichrstr *, int, int, int *); +extern int mission_pln_equip(struct plist *, struct ichrstr *, int, + s_char); +extern int find_airport(struct emp_qelem *, coord, coord); +extern void add_airport(struct emp_qelem *, coord, coord); +extern void divide(struct emp_qelem *, struct emp_qelem *, coord, coord); +extern int air_damage(struct emp_qelem *, coord, coord, int, natid, s_char *, int); -extern int ground_interdict(coord , coord , natid , s_char * ); -extern int unit_interdict(coord , coord , natid , s_char * , int , int ); -extern int off_support(coord , coord , natid , natid ); -extern int def_support(coord , coord , natid , natid ); -extern int oprange(struct genitem * , int , int * ); -extern void find_escorts(coord , coord , natid , struct emp_qelem * ); -extern int cando(int , int ); -extern s_char * mission_short_name(int ); -extern void show_mission(int , struct nstr_item * ); -extern int air_defense(coord , coord , natid , struct emp_qelem * , - struct emp_qelem * ); +extern int ground_interdict(coord, coord, natid, s_char *); +extern int unit_interdict(coord, coord, natid, s_char *, int, int); +extern int off_support(coord, coord, natid, natid); +extern int def_support(coord, coord, natid, natid); +extern int oprange(struct genitem *, int, int *); +extern void find_escorts(coord, coord, natid, struct emp_qelem *); +extern int cando(int, int); +extern s_char *mission_short_name(int); +extern void show_mission(int, struct nstr_item *); +extern int air_defense(coord, coord, natid, struct emp_qelem *, + struct emp_qelem *); /* move.c */ -extern int move_map(s_char * , coord , coord , s_char * ); -extern int check_lmines(coord , coord , double ); -extern int move_ground(s_char * , struct sctstr * , struct sctstr * , - double , double , s_char * , - int (* )(s_char *, coord , coord , s_char *) , - int , int * ); -extern int fly_map(coord , coord ); +extern int move_map(s_char *, coord, coord, s_char *); +extern int check_lmines(coord, coord, double); +extern int move_ground(s_char *, struct sctstr *, struct sctstr *, + double, double, s_char *, + int (*)(s_char *, coord, coord, s_char *), + int, int *); +extern int fly_map(coord, coord); /* mslsub.c */ -extern int msl_intercept(coord , coord , natid , int , int , int , int ); -extern int msl_equip(struct plnstr * ); -extern int msl_hit(struct plnstr * , int , int , int , int , s_char * , - coord , coord , int ); -extern void msl_sel(struct emp_qelem * , coord , coord , natid , int , - int , int ); -extern int msl_launch_mindam(struct emp_qelem * , coord , coord , int , - int , int , s_char * , int , int ); +extern int msl_intercept(coord, coord, natid, int, int, int, int); +extern int msl_equip(struct plnstr *); +extern int msl_hit(struct plnstr *, int, int, int, int, s_char *, + coord, coord, int); +extern void msl_sel(struct emp_qelem *, coord, coord, natid, int, + int, int); +extern int msl_launch_mindam(struct emp_qelem *, coord, coord, int, + int, int, s_char *, int, int); /* mtch.c */ -extern int intmatch(register int , register int * , int ); -extern int comtch(register s_char * , struct cmndstr * , int , int ); +extern int intmatch(register int, register int *, int); +extern int comtch(register s_char *, struct cmndstr *, int, int); /* natarg.c */ -extern int natarg(s_char * , s_char * ); +extern int natarg(s_char *, s_char *); /* neigh.c */ -extern int neigh(coord , coord , natid ); +extern int neigh(coord, coord, natid); /* nreport.c */ -extern void nreport(natid , int , natid , int ); -extern void filereport(int , int , int , int ); +extern void nreport(natid, int, natid, int); +extern void filereport(int, int, int, int); /* nuke.c */ -extern int nuk_postread(int, s_char * ); -extern int nuk_prewrite(int , s_char * ); -extern void nuk_init(int , s_char * ); -extern void nuk_add(coord , coord , int , int ); -extern void nuk_delete(struct nukstr * , int , int ); +extern int nuk_postread(int, s_char *); +extern int nuk_prewrite(int, s_char *); +extern void nuk_init(int, s_char *); +extern void nuk_add(coord, coord, int, int); +extern void nuk_delete(struct nukstr *, int, int); /* nxtitem.c */ -extern int nxtitem(struct nstr_item * , caddr_t ); +extern int nxtitem(struct nstr_item *, caddr_t); /* nxtsct.c */ -extern int nxtsct(register struct nstr_sect * , struct sctstr * ); +extern int nxtsct(register struct nstr_sect *, struct sctstr *); /* plane.c */ -extern s_char * prplane(struct plnstr * ); -extern int pln_postread(int, s_char * ); -extern int pln_prewrite(int , s_char * ); -extern void pln_init(int , s_char * ); +extern s_char *prplane(struct plnstr *); +extern int pln_postread(int, s_char *); +extern int pln_prewrite(int, s_char *); +extern void pln_init(int, s_char *); /* plnsub.c */ -extern void count_planes(struct shpstr * ); -extern int pln_equip(struct plist * , struct ichrstr * , int , s_char ); -extern int pln_onewaymission(struct sctstr * , int * , int * ); -extern void pln_newlanding(struct emp_qelem * , coord , coord , int ); -extern int can_be_on_ship(int , int ); -extern int put_plane_on_ship(struct plnstr * , struct shpstr * ); -extern void pln_dropoff(struct emp_qelem * , struct ichrstr * , coord , - coord , s_char * , int ); -extern void pln_sel(struct nstr_item * , struct emp_qelem * , - struct sctstr * , int , int , int , int ); -extern int pln_arm(struct emp_qelem * , int , int , struct ichrstr * , - int , int , int * ); -extern int pln_mobcost(int , struct plnstr * , int ); -extern void pln_put(struct emp_qelem * ); -extern void pln_removedupes(struct emp_qelem * , struct emp_qelem * ); -extern int take_plane_off_ship(struct plnstr * , struct shpstr * ); -extern int take_plane_off_land(struct plnstr * , struct lndstr * ); -extern void plane_sweep(struct emp_qelem * , coord , coord ); -extern void count_land_planes(struct lndstr * ); -extern int count_sect_planes(struct sctstr * ); -extern int put_plane_on_land(struct plnstr * , struct lndstr * ); -extern int pln_hitchance(struct plnstr * , int , int ); -extern int pln_damage(struct plnstr * , coord , coord , s_char , int *, int ); -extern int pln_identchance(struct plnstr * , int , int ); +extern void count_planes(struct shpstr *); +extern int pln_equip(struct plist *, struct ichrstr *, int, s_char); +extern int pln_onewaymission(struct sctstr *, int *, int *); +extern void pln_newlanding(struct emp_qelem *, coord, coord, int); +extern int can_be_on_ship(int, int); +extern int put_plane_on_ship(struct plnstr *, struct shpstr *); +extern void pln_dropoff(struct emp_qelem *, struct ichrstr *, coord, + coord, s_char *, int); +extern void pln_sel(struct nstr_item *, struct emp_qelem *, + struct sctstr *, int, int, int, int); +extern int pln_arm(struct emp_qelem *, int, int, struct ichrstr *, + int, int, int *); +extern int pln_mobcost(int, struct plnstr *, int); +extern void pln_put(struct emp_qelem *); +extern void pln_removedupes(struct emp_qelem *, struct emp_qelem *); +extern int take_plane_off_ship(struct plnstr *, struct shpstr *); +extern int take_plane_off_land(struct plnstr *, struct lndstr *); +extern void plane_sweep(struct emp_qelem *, coord, coord); +extern void count_land_planes(struct lndstr *); +extern int count_sect_planes(struct sctstr *); +extern int put_plane_on_land(struct plnstr *, struct lndstr *); +extern int pln_hitchance(struct plnstr *, int, int); +extern int pln_damage(struct plnstr *, coord, coord, s_char, int *, int); +extern int pln_identchance(struct plnstr *, int, int); /* pr.c */ extern void pr(s_char *, ...); extern void prnf(s_char *buf); @@ -747,175 +750,179 @@ extern void pr_beep(void); extern void mpr(int, s_char *, ...); /* radmap.c */ -extern void radmap2(int, int , int , int , int , double , int ); -extern int deltx(struct range * , coord ); +extern void radmap2(int, int, int, int, int, double, int); +extern int deltx(struct range *, coord); /* Prototype include a typedef name. It should be moved after the typedef declaration */ -extern int delty(struct range * , coord ); +extern int delty(struct range *, coord); /* Prototype include a typedef name. It should be moved after the typedef declaration */ -extern void radmap(int , int , int , int , double ); -extern void radmapnopr(int , int , int , int , double ); -extern void radmapupd(int, int , int , int , int , double ); +extern void radmap(int, int, int, int, double); +extern void radmapnopr(int, int, int, int, double); +extern void radmapupd(int, int, int, int, int, double); /* rej.c */ -extern int setrel(natid , natid , int ); -extern int setcont(natid , natid , int ); -extern int setrej(natid , natid , int , int ); +extern int setrel(natid, natid, int); +extern int setcont(natid, natid, int); +extern int setrej(natid, natid, int, int); /* retreat.c */ -extern void retreat_ship(struct shpstr * , s_char ); -extern int retreat_ship1(struct shpstr * , s_char , int ); -extern int findcondition(s_char ); -extern void retreat_land(struct lndstr * , s_char ); -extern int retreat_land1(struct lndstr * , s_char , int ); -extern int check_retreat_and_do_shipdamage(struct shpstr * , int ); -extern int check_retreat_and_do_landdamage(struct lndstr * , int ); +extern void retreat_ship(struct shpstr *, s_char); +extern int retreat_ship1(struct shpstr *, s_char, int); +extern int findcondition(s_char); +extern void retreat_land(struct lndstr *, s_char); +extern int retreat_land1(struct lndstr *, s_char, int); +extern int check_retreat_and_do_shipdamage(struct shpstr *, int); +extern int check_retreat_and_do_landdamage(struct lndstr *, int); /* sarg.c */ -extern int sarg_type(s_char * ); -extern int sarg_xy(s_char * , coord * , coord * ); -extern int sarg_getrange(s_char * , register struct range * ); -extern int sarg_area(s_char * , register struct range * ); -extern int sarg_range(s_char * , coord * , coord * , int * ); -extern int sarg_list(s_char * , register int * , int ); +extern int sarg_type(s_char *); +extern int sarg_xy(s_char *, coord *, coord *); +extern int sarg_getrange(s_char *, register struct range *); +extern int sarg_area(s_char *, register struct range *); +extern int sarg_range(s_char *, coord *, coord *, int *); +extern int sarg_list(s_char *, register int *, int); /* satmap.c */ -extern void satdisp(struct sctstr * , int , int ); -extern void satmap(int , int , int , int , int , int ); -extern void sathead(void ); +extern void satdisp(struct sctstr *, int, int); +extern void satmap(int, int, int, int, int, int); +extern void sathead(void); /* sect.c */ -extern int sct_postread(int, s_char * ); -extern int checksect(struct sctstr * ); -extern int sct_prewrite(int , s_char * ); -extern int issector(s_char * ); -extern void sct_init(coord , coord , s_char * ); +extern int sct_postread(int, s_char *); +extern int checksect(struct sctstr *); +extern int sct_prewrite(int, s_char *); +extern int issector(s_char *); +extern void sct_init(coord, coord, s_char *); /* ship.c */ -extern s_char * prship(struct shpstr * ); -extern int shp_postread(int, s_char * ); -extern int shp_prewrite(int , s_char * ); -extern void shp_init(int , s_char * ); +extern s_char *prship(struct shpstr *); +extern int shp_postread(int, s_char *); +extern int shp_prewrite(int, s_char *); +extern void shp_init(int, s_char *); /* show.c */ -extern void sort_lookup_list(void ); -extern void show_bridge(int ); -extern void show_tower(int ); -extern void show_nuke_stats(int ); -extern void show_nuke_capab(int ); -extern void show_nuke_build(int ); -extern void show_ship_build(int ); -extern void show_ship_stats(int ); -extern void show_ship_capab(int ); -extern void show_plane_stats(int ); -extern void show_plane_capab(int ); -extern void show_plane_build(int ); -extern void show_land_build(int ); -extern void show_land_capab(int ); -extern void show_land_stats(int ); -extern void show_sect_build(int ); -extern void show_sect_stats(int ); -extern void show_sect_capab(int ); +extern void sort_lookup_list(void); +extern void show_bridge(int); +extern void show_tower(int); +extern void show_nuke_stats(int); +extern void show_nuke_capab(int); +extern void show_nuke_build(int); +extern void show_ship_build(int); +extern void show_ship_stats(int); +extern void show_ship_capab(int); +extern void show_plane_stats(int); +extern void show_plane_capab(int); +extern void show_plane_build(int); +extern void show_land_build(int); +extern void show_land_capab(int); +extern void show_land_stats(int); +extern void show_sect_build(int); +extern void show_sect_stats(int); +extern void show_sect_capab(int); /* shpsub.c */ -extern void shp_sel(struct nstr_item * , struct emp_qelem * ); -extern void shp_nav(struct emp_qelem * , double * , double * , int * , - natid ); +extern void shp_sel(struct nstr_item *, struct emp_qelem *); +extern void shp_nav(struct emp_qelem *, double *, double *, int *, natid); extern int shp_check_one_mines(struct mlist *); -extern int shp_sweep(struct emp_qelem * , int , natid ); -extern int shp_interdict(struct emp_qelem * , coord , coord , natid ); -extern void shp_mess(s_char * , struct mlist * ); -extern int shp_check_mines(struct emp_qelem * ); -extern int shp_check_nav(struct sctstr * ); -extern s_char * shp_path(int , struct shpstr * , s_char * ); -extern void shp_put(struct emp_qelem * , natid ); -extern int shp_hit_mine(struct shpstr * , struct mchrstr * ); -extern void shp_list(struct emp_qelem * ); -extern int shp_hardtarget(struct shpstr * ); -extern void shp_view(struct emp_qelem * ); -extern int shp_nav_one_sector(struct emp_qelem * , int , natid , int ); -extern int shp_missile_defense(coord , coord , natid , int ); -extern void shp_missdef(struct shpstr * , natid ); +extern int shp_sweep(struct emp_qelem *, int, natid); +extern int shp_interdict(struct emp_qelem *, coord, coord, natid); +extern void shp_mess(s_char *, struct mlist *); +extern int shp_check_mines(struct emp_qelem *); +extern int shp_check_nav(struct sctstr *); +extern s_char *shp_path(int, struct shpstr *, s_char *); +extern void shp_put(struct emp_qelem *, natid); +extern int shp_hit_mine(struct shpstr *, struct mchrstr *); +extern void shp_list(struct emp_qelem *); +extern int shp_hardtarget(struct shpstr *); +extern void shp_view(struct emp_qelem *); +extern int shp_nav_one_sector(struct emp_qelem *, int, natid, int); +extern int shp_missile_defense(coord, coord, natid, int); +extern void shp_missdef(struct shpstr *, natid); /* snxtitem.c */ -extern int snxtitem(register struct nstr_item * , int , s_char * ); +extern int snxtitem(register struct nstr_item *, int, s_char *); /* snxtsct.c */ -extern int snxtsct(register struct nstr_sect * , s_char * ); +extern int snxtsct(register struct nstr_sect *, s_char *); /* supply.c */ -extern void resupply_all(struct lndstr * ); -extern void resupply_commod(struct lndstr * , int ); -extern int get_minimum(struct lndstr * , int ); -extern int supply_commod(int , int , int , int , int ); -extern int s_commod(int , int , int , int , int , int ); -extern int try_supply_commod(int , int , int , int , int ); -extern s_char * itemname(int ); -extern int at_minimum(struct lndstr * , int ); -extern int has_supply(struct lndstr * ); -extern int use_supply(struct lndstr * ); +extern void resupply_all(struct lndstr *); +extern void resupply_commod(struct lndstr *, int); +extern int get_minimum(struct lndstr *, int); +extern int supply_commod(int, int, int, int, int); +extern int s_commod(int, int, int, int, int, int); +extern int try_supply_commod(int, int, int, int, int); +extern s_char *itemname(int); +extern int at_minimum(struct lndstr *, int); +extern int has_supply(struct lndstr *); +extern int use_supply(struct lndstr *); /* takeover.c */ -extern void takeover_land(register struct lndstr * , natid , int ); -extern void takeover(register struct sctstr * , natid ); -extern void takeover_ship(register struct shpstr * , natid , int ); +extern void takeover_land(register struct lndstr *, natid, int); +extern void takeover(register struct sctstr *, natid); +extern void takeover_ship(register struct shpstr *, natid, int); /* trdsub.c */ extern int trade_check_ok(int, struct trdstr *, union trdgenstr *); -extern s_char * trade_nameof(struct trdstr * , union trdgenstr * ); -extern int trade_desc(struct trdstr * , union trdgenstr * ); -extern int trade_getitem(struct trdstr * , union trdgenstr * ); -extern long get_couval(int ); -extern long get_outstand(int ); -extern struct ichrstr * whichitem(char ); +extern s_char *trade_nameof(struct trdstr *, union trdgenstr *); +extern int trade_desc(struct trdstr *, union trdgenstr *); +extern int trade_getitem(struct trdstr *, union trdgenstr *); +extern long get_couval(int); +extern long get_outstand(int); +extern struct ichrstr *whichitem(char); /* trechk.c */ -extern int trechk(register natid , register natid , int ); +extern int trechk(register natid, register natid, int); /* whatitem.c */ -extern struct ichrstr * whatitem(s_char * , s_char * ); +extern struct ichrstr *whatitem(s_char *, s_char *); /* wire.c */ -extern int typed_wire(natid , natid , s_char * , int ); +extern int typed_wire(natid, natid, s_char *, int); /* wu.c */ -extern void clear_telegram_is_new(natid ); -extern int typed_wu(natid , natid , s_char * , int ); +extern void clear_telegram_is_new(natid); +extern int typed_wu(natid, natid, s_char *, int); extern int wu(natid, natid, s_char *, ...); /* * src/lib/update/ *.c */ /* age.c */ -extern void age_levels(int ); +extern void age_levels(int); /* anno.c */ -extern void delete_old_announcements(void ); +extern void delete_old_announcements(void); /* bp.c */ -extern void fill_update_array(int * , struct sctstr * ); -extern int * get_wp(int * , struct sctstr * , int ); -extern int gt_bg_nmbr(int * , struct sctstr * , int ); -extern void pt_bg_nmbr(int * , struct sctstr * , int , int ); +extern void fill_update_array(int *, struct sctstr *); +extern int *get_wp(int *, struct sctstr *, int); +extern int gt_bg_nmbr(int *, struct sctstr *, int); +extern void pt_bg_nmbr(int *, struct sctstr *, int, int); /* deliver.c */ -extern int deliver(register struct sctstr * , struct ichrstr * , int , int , int , int ); +extern int deliver(register struct sctstr *, struct ichrstr *, int, int, + int, int); /* distribute.c */ -extern int dodistribute(struct sctstr * , int , s_char * , double , double ); +extern int dodistribute(struct sctstr *, int, s_char *, double, double); /* finish.c */ -extern void finish_sects(int ); +extern void finish_sects(int); /* human.c */ -extern int do_feed(register struct sctstr * , register struct natstr * , - int * , int * , int * , int ); -extern int growfood(struct sctstr * , register int * , int , int ); -extern int feed_people(register int * , int , int * ); -extern void starvation(struct sctstr * ); -extern int grow_people(struct sctstr * , register int , - register struct natstr * , int * , int , - register int * ); -extern void trunc_people(struct sctstr * , register struct natstr * , - register int * ); +extern int do_feed(register struct sctstr *, register struct natstr *, + int *, int *, int *, int); +extern int growfood(struct sctstr *, register int *, int, int); +extern int feed_people(register int *, int, int *); +extern void starvation(struct sctstr *); +extern int grow_people(struct sctstr *, register int, + register struct natstr *, int *, int, + register int *); +extern void trunc_people(struct sctstr *, register struct natstr *, + register int *); /* land.c */ -extern void upd_land(register struct lndstr * , int , register int , struct natstr * , int * , int ); -extern int prod_land(int , int , int * , int ); -extern int landrepair(register struct lndstr * , int * , struct natstr * , int * , int ); -extern int feed_land(struct lndstr * , register int * , int , int * , int ); -extern int plague_land(struct lndstr * , struct natstr * , register int * , register int * , int ); +extern void upd_land(register struct lndstr *, int, register int, + struct natstr *, int *, int); +extern int prod_land(int, int, int *, int); +extern int landrepair(register struct lndstr *, int *, struct natstr *, + int *, int); +extern int feed_land(struct lndstr *, register int *, int, int *, int); +extern int plague_land(struct lndstr *, struct natstr *, register int *, + register int *, int); /* main.c */ -extern void update_main(void * ); -extern void do_prod(int , int , int , int * , long int (*)[2] , int * , int * , int * , int * , int * , int * ); +extern void update_main(void *); +extern void do_prod(int, int, int, int *, long int (*)[2], int *, int *, + int *, int *, int *, int *); /* material.c */ -extern void get_materials(struct sctstr * , int * , int * , int ); +extern void get_materials(struct sctstr *, int *, int *, int); /* mobility.c */ -extern void mob_sect(register int ); -extern void do_mob_sect(register struct sctstr * , register int ); -extern void mob_ship(register int ); -extern void do_mob_ship(register struct shpstr * , register int ); -extern void mob_land(register int ); -extern void do_mob_land(register struct lndstr * , register int ); -extern void mob_plane(register int ); -extern void do_mob_plane(register struct plnstr * , register int ); +extern void mob_sect(register int); +extern void do_mob_sect(register struct sctstr *, register int); +extern void mob_ship(register int); +extern void do_mob_ship(register struct shpstr *, register int); +extern void mob_land(register int); +extern void do_mob_land(register struct lndstr *, register int); +extern void mob_plane(register int); +extern void do_mob_plane(register struct plnstr *, register int); extern void do_mob_sect(register struct sctstr *sp, register int etus); extern void update_all_mob(void); extern void update_timestamps(time_t offset); @@ -924,68 +931,79 @@ extern void shp_do_upd_mob(register struct shpstr *sp); extern void lnd_do_upd_mob(register struct lndstr *lp); extern void pln_do_upd_mob(register struct plnstr *pp); /* move_sat.c */ -extern void move_sat(register struct plnstr * ); +extern void move_sat(register struct plnstr *); /* nat.c */ -extern double logx(double , double ); -extern double limit_level(double , int , int ); -extern void prod_nat(int ); -extern void share_incr(register double * , register double * ); +extern double logx(double, double); +extern double limit_level(double, int, int); +extern void prod_nat(int); +extern void share_incr(register double *, register double *); /* nav_ship.c */ -extern void scuttle_it(register struct shpstr * ); -extern void swap(register struct shpstr * ); -extern int nav_ship(register struct shpstr * ); +extern void scuttle_it(register struct shpstr *); +extern void swap(register struct shpstr *); +extern int nav_ship(register struct shpstr *); /* nav_util.c */ -extern int check_nav(struct sctstr * ); -extern int load_it(register struct shpstr * , register struct sctstr * , int ); -extern int com_num(s_char * ); -extern void unload_it(register struct shpstr * ); -extern void auto_fuel_ship(register struct shpstr * ); +extern int check_nav(struct sctstr *); +extern int load_it(register struct shpstr *, register struct sctstr *, + int); +extern int com_num(s_char *); +extern void unload_it(register struct shpstr *); +extern void auto_fuel_ship(register struct shpstr *); /* nxtitemp.c */ -extern s_char * nxtitemp(struct nstr_item * , int ); +extern s_char *nxtitemp(struct nstr_item *, int); /* nxtsctp.c */ -extern struct sctstr * nxtsctp(register struct nstr_sect * ); +extern struct sctstr *nxtsctp(register struct nstr_sect *); /* plague.c */ -extern void do_plague(struct sctstr * , struct natstr * , int ); -extern int infect_people(struct natstr * , register int * , u_int , int , struct sctstr *); -extern int plague_people(struct natstr * , register int * , register int * , int ); +extern void do_plague(struct sctstr *, struct natstr *, int); +extern int infect_people(struct natstr *, register int *, u_int, int, + struct sctstr *); +extern int plague_people(struct natstr *, register int *, register int *, + int); /* plane.c */ -extern int prod_plane(int , int , int * , int ); +extern int prod_plane(int, int, int *, int); /* populace.c */ -extern void populace(struct natstr * , register struct sctstr * , register int * , int ); -extern int total_work(register int , register int , register int , register int , register int ); +extern void populace(struct natstr *, register struct sctstr *, + register int *, int); +extern int total_work(register int, register int, register int, + register int, register int); /* prepare.c */ -extern void tax(struct sctstr * , struct natstr * , int , long * , int * , int * , int * ); -extern int upd_slmilcosts(natid , int ); -extern void prepare_sects(int , int * ); -extern int bank_income(struct sctstr * , int ); +extern void tax(struct sctstr *, struct natstr *, int, long *, int *, + int *, int *); +extern int upd_slmilcosts(natid, int); +extern void prepare_sects(int, int *); +extern int bank_income(struct sctstr *, int); /* produce.c */ -extern int produce(struct natstr * , struct sctstr * , int * , int , int , int , int , int * , int * ); -extern int materials_cost(struct pchrstr * , register int * , int * ); -extern void materials_charge(struct pchrstr * , register int * , register int ); +extern int produce(struct natstr *, struct sctstr *, int *, int, int, int, + int, int *, int *); +extern int materials_cost(struct pchrstr *, register int *, int *); +extern void materials_charge(struct pchrstr *, register int *, + register int); /* removewants.c */ -extern int update_removewants(void ); +extern int update_removewants(void); /* revolt.c */ -extern void take_casualties(struct sctstr * , int ); -extern void revolt(struct sctstr * ); -extern void guerrilla(struct sctstr * ); +extern void take_casualties(struct sctstr *, int); +extern void revolt(struct sctstr *); +extern void guerrilla(struct sctstr *); /* sail.c */ -extern void fltp_to_list(struct fltheadstr * , struct emp_qelem * ); -extern void sail_ship(natid ); +extern void fltp_to_list(struct fltheadstr *, struct emp_qelem *); +extern void sail_ship(natid); /* sect.c */ -extern int dodeliver(struct sctstr * , int * ); -extern int upd_buildeff(struct natstr * , register struct sctstr * , int * , int * , int , int * , int , int * ); -extern int enlist(register int * , int , int * ); -extern void meltitems(int , int , int , int * , int , int , int , int ); -extern void do_fallout(register struct sctstr * , register int ); -extern void spread_fallout(struct sctstr * , int ); -extern void decay_fallout(struct sctstr * , int ); -extern void produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2], - int sector_type); +extern int dodeliver(struct sctstr *, int *); +extern int upd_buildeff(struct natstr *, register struct sctstr *, int *, + int *, int, int *, int, int *); +extern int enlist(register int *, int, int *); +extern void meltitems(int, int, int, int *, int, int, int, int); +extern void do_fallout(register struct sctstr *, register int); +extern void spread_fallout(struct sctstr *, int); +extern void decay_fallout(struct sctstr *, int); +extern void produce_sect(int natnum, int etu, int *bp, + long int (*p_sect)[2], int sector_type); /* ship.c */ -extern void upd_ship(register struct shpstr * , int , register int , struct natstr * , int * , int ); -extern int prod_ship(int , int , int * , int ); -extern int shiprepair(register struct shpstr * , int * , struct natstr * , int * , int ); -extern int feed_ship(struct shpstr * , register int * , int , int * , int ); +extern void upd_ship(register struct shpstr *, int, register int, + struct natstr *, int *, int); +extern int prod_ship(int, int, int *, int); +extern int shiprepair(register struct shpstr *, int *, struct natstr *, + int *, int); +extern int feed_ship(struct shpstr *, register int *, int, int *, int); /* * src/server diff --git a/include/queue.h b/include/queue.h index bbc9337f2..77d5d0805 100644 --- a/include/queue.h +++ b/include/queue.h @@ -37,12 +37,12 @@ #define QEMPTY(p) ((p)->q_forw == (p)) struct emp_qelem { - struct emp_qelem *q_forw; - struct emp_qelem *q_back; + struct emp_qelem *q_forw; + struct emp_qelem *q_back; }; -extern void emp_remque(struct emp_qelem * ); -extern void emp_initque(struct emp_qelem * ); -extern void emp_insque(struct emp_qelem * , struct emp_qelem * ); +extern void emp_remque(struct emp_qelem *); +extern void emp_initque(struct emp_qelem *); +extern void emp_insque(struct emp_qelem *, struct emp_qelem *); #endif /* _QUEUE_H_ */ diff --git a/include/sect.h b/include/sect.h index 49d398896..e4e512dd6 100644 --- a/include/sect.h +++ b/include/sect.h @@ -50,60 +50,60 @@ /* The order of the following elements is there to match up with genitem */ -struct sctstr { - short ef_type; - natid sct_own; /* owner's country num */ - short sct_elev; /* elevation/depth */ - coord sct_x; /* x coord of sector */ - coord sct_y; /* y coord of sector */ - u_char sct_type; /* sector type */ - u_char sct_effic; /* 0% to 100% */ - short sct_mobil; /* mobility units */ - u_char sct_loyal; /* updates until civilans "converted" */ - u_char sct_terr; /* territory 0 id # of sector */ - u_char sct_terr1; /* territory 1 id # of sector */ - u_char sct_terr2; /* territory 2 id # of sector */ - u_char sct_terr3; /* territory 3 id # of sector */ - coord sct_dist_x; /* Dist sector */ - coord sct_dist_y; - short sct_avail; /* available workforce for "other things" */ - short sct_flags; /* temporary flags */ - short sct_fill; /* gunk */ - u_char sct_work; /* pct of civ actually working */ - u_char sct_coastal; /* is this a coastal sector? */ - u_char sct_newtype; /* for changing designations */ - u_char sct_min; /* ease of mining ore */ - u_char sct_gmin; /* amount of gold ore */ - u_char sct_fertil; /* fertility of soil */ - u_char sct_oil; /* oil content */ - u_char sct_uran; /* uranium ore content */ - natid sct_oldown; /* old owner of sector (for liberation) */ - u_char sct_updated; /* Has this sect been updated? */ - u_char sct_off; /* Should this sector produce? */ - u_char sct_nv; /* current number of variables */ - u_char sct_vtype[MAXSCTV]; - u_short sct_vamt[MAXSCTV]; - time_t sct_access; /* Last time mob was updated (MOB_ACCESS) */ - u_char sct_road; /* Road value of a sector */ - u_char sct_rail; /* Rail value of a sector */ - u_char sct_defense; /* Defensive value of a sector */ - time_t sct_timestamp; /* Last time this sector was written to */ +struct sctstr { + short ef_type; + natid sct_own; /* owner's country num */ + short sct_elev; /* elevation/depth */ + coord sct_x; /* x coord of sector */ + coord sct_y; /* y coord of sector */ + u_char sct_type; /* sector type */ + u_char sct_effic; /* 0% to 100% */ + short sct_mobil; /* mobility units */ + u_char sct_loyal; /* updates until civilans "converted" */ + u_char sct_terr; /* territory 0 id # of sector */ + u_char sct_terr1; /* territory 1 id # of sector */ + u_char sct_terr2; /* territory 2 id # of sector */ + u_char sct_terr3; /* territory 3 id # of sector */ + coord sct_dist_x; /* Dist sector */ + coord sct_dist_y; + short sct_avail; /* available workforce for "other things" */ + short sct_flags; /* temporary flags */ + short sct_fill; /* gunk */ + u_char sct_work; /* pct of civ actually working */ + u_char sct_coastal; /* is this a coastal sector? */ + u_char sct_newtype; /* for changing designations */ + u_char sct_min; /* ease of mining ore */ + u_char sct_gmin; /* amount of gold ore */ + u_char sct_fertil; /* fertility of soil */ + u_char sct_oil; /* oil content */ + u_char sct_uran; /* uranium ore content */ + natid sct_oldown; /* old owner of sector (for liberation) */ + u_char sct_updated; /* Has this sect been updated? */ + u_char sct_off; /* Should this sector produce? */ + u_char sct_nv; /* current number of variables */ + u_char sct_vtype[MAXSCTV]; + u_short sct_vamt[MAXSCTV]; + time_t sct_access; /* Last time mob was updated (MOB_ACCESS) */ + u_char sct_road; /* Road value of a sector */ + u_char sct_rail; /* Rail value of a sector */ + u_char sct_defense; /* Defensive value of a sector */ + time_t sct_timestamp; /* Last time this sector was written to */ }; -struct dchrstr { - int d_mnem; /* map symbol */ - int d_prd; /* product vtype */ - int d_mcst; /* movement cost */ - int d_flg; /* movement cost */ - int d_pkg; /* type of packaging in these sects */ - float d_ostr; /* offensive strength */ - float d_dstr; /* defensive strength */ - int d_value; /* resale ("collect") value */ - int d_cost; /* cost to designate the sect */ - int d_build; /* cost multiplier for eff */ - int d_lcms; /* lcm's needed per point of eff */ - int d_hcms; /* hcm's needed per point of eff */ - s_char *d_name; /* full name of sector type */ +struct dchrstr { + int d_mnem; /* map symbol */ + int d_prd; /* product vtype */ + int d_mcst; /* movement cost */ + int d_flg; /* movement cost */ + int d_pkg; /* type of packaging in these sects */ + float d_ostr; /* offensive strength */ + float d_dstr; /* defensive strength */ + int d_value; /* resale ("collect") value */ + int d_cost; /* cost to designate the sect */ + int d_build; /* cost multiplier for eff */ + int d_lcms; /* lcm's needed per point of eff */ + int d_hcms; /* hcm's needed per point of eff */ + s_char *d_name; /* full name of sector type */ }; #define NPKG 0 /* no special packaging */ @@ -118,7 +118,7 @@ struct dchrstr { /* sector types (must agree with order in dchr, empglb.c) */ -#define SCT_WATER 0 /* basics */ +#define SCT_WATER 0 /* basics */ #define SCT_MOUNT 1 #define SCT_SANCT 2 #define SCT_WASTE 3 @@ -126,7 +126,7 @@ struct dchrstr { #define SCT_CAPIT 5 #define SCT_URAN 6 #define SCT_PARK 7 -#define SCT_ARMSF 8 /* industries */ +#define SCT_ARMSF 8 /* industries */ #define SCT_AMMOF 9 #define SCT_MINE 10 #define SCT_GMINE 11 @@ -137,23 +137,23 @@ struct dchrstr { #define SCT_OIL 16 #define SCT_LIGHT 17 #define SCT_HEAVY 18 -#define SCT_FORTR 19 /* military/scientific */ +#define SCT_FORTR 19 /* military/scientific */ #define SCT_TECH 20 #define SCT_RSRCH 21 #define SCT_NUKE 22 #define SCT_LIBR 23 -#define SCT_HIWAY 24 /* communications */ +#define SCT_HIWAY 24 /* communications */ #define SCT_RADAR 25 #define SCT_HEADQ 26 /* headquarters */ -#define SCT_BHEAD 27 /* Bridge head */ -#define SCT_BSPAN 28 /* Bridge span */ -#define SCT_BANK 29 /* financial */ +#define SCT_BHEAD 27 /* Bridge head */ +#define SCT_BSPAN 28 /* Bridge span */ +#define SCT_BANK 29 /* financial */ #define SCT_REFINE 30 /* refinery */ #define SCT_ENLIST 31 /* enlistment center */ -#define SCT_PLAINS 32 /* plains sector */ -#define SCT_BTOWER 33 /* Bridge tower */ +#define SCT_PLAINS 32 /* plains sector */ +#define SCT_BTOWER 33 /* Bridge tower */ -#define SCT_EFFIC 34 /* used in update & budget */ +#define SCT_EFFIC 34 /* used in update & budget */ #define SCT_MAXDEF 34 /* highest sector type in header files */ #define getsect(x, y, p) \ @@ -168,14 +168,14 @@ struct dchrstr { /* things relating to sectors */ extern int sctoff(coord x, coord y); -extern double landgun(); +extern double landgun(); -extern int sct_maxno; -extern struct dchrstr dchr[]; -extern struct dchrstr bigcity_dchr; +extern int sct_maxno; +extern struct dchrstr dchr[]; +extern struct dchrstr bigcity_dchr; -#define MIN_MOBCOST 0.001 /* lowest cost a sector can have to move into */ -#define FORTEFF 5 /* forts must be 5% efficient to fire. */ +#define MIN_MOBCOST 0.001 /* lowest cost a sector can have to move into */ +#define FORTEFF 5 /* forts must be 5% efficient to fire. */ #define MOB_NONE 0 #define MOB_ROAD 1 @@ -186,10 +186,10 @@ extern struct dchrstr bigcity_dchr; #define INT_DEF 2 /* Sector flags */ -#define MOVE_IN_PROGRESS bit(0) /* move in progress */ +#define MOVE_IN_PROGRESS bit(0) /* move in progress */ /* Each cost is per point of efficency */ -struct sctintrins { +struct sctintrins { char *in_name; u_char in_lcms; u_char in_hcms; diff --git a/include/ship.h b/include/ship.h index bebffbbd0..7eaceadc4 100644 --- a/include/ship.h +++ b/include/ship.h @@ -55,7 +55,7 @@ #define AN_AUTONAV bit(2) #define AN_STANDBY bit(3) #define AN_LOADING bit(4) -#define AN_SCUTTLE bit(5) /* Auto-scuttle of trade ships */ +#define AN_SCUTTLE bit(5) /* Auto-scuttle of trade ships */ /* TMAX is the number of cargo holds a ship use in the autonav code. */ #define TMAX 6 @@ -66,97 +66,97 @@ #define MAXSHPPATH 28 #define MAXSHPNAMLEN 24 -struct shpstr { - short ef_type; - natid shp_own; /* owner's country num */ - short shp_uid; /* unit id (ship #) */ - coord shp_x; /* x location in abs coords */ - coord shp_y; /* y location in abs coords */ - s_char shp_type; /* ship type */ - s_char shp_effic; /* 0% to 100% */ - s_char shp_mobil; /* mobility units */ - short shp_sell; /* pointer to trade file */ - short shp_tech; /* tech level ship was built at */ - s_char shp_fleet; /* group membership */ - coord shp_opx,shp_opy;/* Op sector coords */ - short shp_mission; /* mission code */ - short shp_radius; /* mission radius */ - u_char shp_nplane; /* number of planes on board */ - u_char shp_nland; /* number of land units on board */ - short shp_armor; - short shp_speed; - short shp_visib; - short shp_frnge; - short shp_glim; - coord shp_destx[2]; /* location for ship destination */ - coord shp_desty[2]; - s_char shp_tstart[TMAX]; /* what goods to pick up at start point */ - s_char shp_tend[TMAX]; /* what goods to pick up at end point */ - short shp_lstart[TMAX]; /* How much do we pick up at the start */ - short shp_lend[TMAX]; /* How much do we pick up at the end */ - u_char shp_autonav; /* autonavigation flags */ - s_char shp_nv; /* current number of variables */ - u_char shp_vtype[MAXSHPV]; - u_short shp_vamt[MAXSHPV]; - time_t shp_access; /* Last time mob was updated (MOB_ACCESS) */ - time_t shp_timestamp; /* Last time this ship was touched. */ - u_char shp_mobquota; /* mobility quota */ - s_char shp_path[MAXSHPPATH]; - short shp_follow; - s_char shp_name[MAXSHPNAMLEN]; /* name set with the "name" command */ - u_char shp_fuel; /* How much fuel do we have */ - u_char shp_nchoppers; /* How many choppers on board? */ - u_char shp_nxlight; /* How many xlight planes on board? */ - coord shp_orig_x; - coord shp_orig_y; /* Where we were built */ - natid shp_orig_own; /* Who built us */ - int shp_rflags; /* When do I retreat? */ - s_char shp_rpath[RET_LEN]; /* retreat path */ +struct shpstr { + short ef_type; + natid shp_own; /* owner's country num */ + short shp_uid; /* unit id (ship #) */ + coord shp_x; /* x location in abs coords */ + coord shp_y; /* y location in abs coords */ + s_char shp_type; /* ship type */ + s_char shp_effic; /* 0% to 100% */ + s_char shp_mobil; /* mobility units */ + short shp_sell; /* pointer to trade file */ + short shp_tech; /* tech level ship was built at */ + s_char shp_fleet; /* group membership */ + coord shp_opx, shp_opy; /* Op sector coords */ + short shp_mission; /* mission code */ + short shp_radius; /* mission radius */ + u_char shp_nplane; /* number of planes on board */ + u_char shp_nland; /* number of land units on board */ + short shp_armor; + short shp_speed; + short shp_visib; + short shp_frnge; + short shp_glim; + coord shp_destx[2]; /* location for ship destination */ + coord shp_desty[2]; + s_char shp_tstart[TMAX]; /* what goods to pick up at start point */ + s_char shp_tend[TMAX]; /* what goods to pick up at end point */ + short shp_lstart[TMAX]; /* How much do we pick up at the start */ + short shp_lend[TMAX]; /* How much do we pick up at the end */ + u_char shp_autonav; /* autonavigation flags */ + s_char shp_nv; /* current number of variables */ + u_char shp_vtype[MAXSHPV]; + u_short shp_vamt[MAXSHPV]; + time_t shp_access; /* Last time mob was updated (MOB_ACCESS) */ + time_t shp_timestamp; /* Last time this ship was touched. */ + u_char shp_mobquota; /* mobility quota */ + s_char shp_path[MAXSHPPATH]; + short shp_follow; + s_char shp_name[MAXSHPNAMLEN]; /* name set with the "name" command */ + u_char shp_fuel; /* How much fuel do we have */ + u_char shp_nchoppers; /* How many choppers on board? */ + u_char shp_nxlight; /* How many xlight planes on board? */ + coord shp_orig_x; + coord shp_orig_y; /* Where we were built */ + natid shp_orig_own; /* Who built us */ + int shp_rflags; /* When do I retreat? */ + s_char shp_rpath[RET_LEN]; /* retreat path */ }; struct fltelemstr { - int num; - int own; - double mobil,mobcost; - struct fltelemstr *next; + int num; + int own; + double mobil, mobcost; + struct fltelemstr *next; }; struct fltheadstr { - int leader; - s_char real_q; + int leader; + s_char real_q; /* defines for the real_q member */ #define LEADER_VIRTUAL 0 #define LEADER_REAL 1 #define LEADER_WRONGSECT 2 - coord x,y; - natid own; - unsigned maxmoves; - struct fltelemstr *head; - struct fltheadstr *next; + coord x, y; + natid own; + unsigned maxmoves; + struct fltelemstr *head; + struct fltheadstr *next; }; -struct mchrstr { - u_char m_nv; /* number of variables it can hold */ - u_char m_vtype[MAXCHRNV]; - u_short m_vamt[MAXCHRNV]; - int m_lcm; /* units of lcm to build */ - int m_hcm; /* units of hcm to build */ - int m_armor; /* how well armored it is */ - int m_speed; /* how fast it can go */ - int m_visib; /* how well it can be seen */ - int m_vrnge; /* how well it can see */ - int m_frnge; /* how far it can fire */ - int m_glim; /* how many guns it can fire */ - u_char m_nxlight; /* maximum number of xlight planes */ - u_char m_nchoppers; /* maximum number of choppers */ - u_char m_fuelc; /* fuel capacity */ - u_char m_fuelu; /* fuel used per 10 mob */ - s_char *m_name; /* full name of type of ship */ - int m_tech; /* tech required to build */ - int m_cost; /* how much it costs to build */ - long m_flags; /* what special things can this ship do */ - u_char m_nplanes; /* maximum number of planes this ship holds */ - u_char m_nland; /* maximum number of units this ship holds */ +struct mchrstr { + u_char m_nv; /* number of variables it can hold */ + u_char m_vtype[MAXCHRNV]; + u_short m_vamt[MAXCHRNV]; + int m_lcm; /* units of lcm to build */ + int m_hcm; /* units of hcm to build */ + int m_armor; /* how well armored it is */ + int m_speed; /* how fast it can go */ + int m_visib; /* how well it can be seen */ + int m_vrnge; /* how well it can see */ + int m_frnge; /* how far it can fire */ + int m_glim; /* how many guns it can fire */ + u_char m_nxlight; /* maximum number of xlight planes */ + u_char m_nchoppers; /* maximum number of choppers */ + u_char m_fuelc; /* fuel capacity */ + u_char m_fuelu; /* fuel used per 10 mob */ + s_char *m_name; /* full name of type of ship */ + int m_tech; /* tech required to build */ + int m_cost; /* how much it costs to build */ + long m_flags; /* what special things can this ship do */ + u_char m_nplanes; /* maximum number of planes this ship holds */ + u_char m_nland; /* maximum number of units this ship holds */ }; #define M_FOOD bit(0) /* catch that fish! */ @@ -174,8 +174,8 @@ struct mchrstr { #define M_SPY bit(10) /* gather intelligence info */ #define M_LAND bit(11) /* allows full landing ability */ #define M_SUBT bit(12) /* allows torping of other subs */ -#define M_TRADE bit(13) /* is a trade ship */ -#define M_SEMILAND bit(14) /* can land 1/4 */ +#define M_TRADE bit(13) /* is a trade ship */ +#define M_SEMILAND bit(14) /* can land 1/4 */ /* M_XLIGHT will be automatically set in init_global() if m_nxlight > 0 */ #define M_XLIGHT bit(15) /* can hold xlight planes */ /* M_CHOPPER will be automatically set in init_global() if m_nchoppers > 0 */ @@ -184,7 +184,7 @@ struct mchrstr { #define M_SUPPLY bit(18) /* Can supply units/sects/ships */ /* M_XUNIT will be automatically set in init_global() if m_nland > 0 */ #define M_UNIT bit(19) /* Can carry units */ -#define M_ANTIMISSILE bit(20) /* Shoot down missile */ +#define M_ANTIMISSILE bit(20) /* Shoot down missile */ #define getship(n, p) \ ef_read(EF_SHIP, n, (caddr_t)p) @@ -193,17 +193,17 @@ struct mchrstr { #define getshipp(n) \ (struct shpstr *) ef_ptr(EF_SHIP, n) -extern double seagun(); +extern double seagun(); -extern struct mchrstr mchr[]; -extern int shp_maxno; +extern struct mchrstr mchr[]; +extern int shp_maxno; struct mlist { - struct emp_qelem queue; /* list of ships */ - struct mchrstr *mcp; /* pointer to desc of ship */ - struct shpstr ship; /* struct ship */ - double mobil; /* how much mobility the ship has left */ - int done; /* has this ship been interdicted yet? */ + struct emp_qelem queue; /* list of ships */ + struct mchrstr *mcp; /* pointer to desc of ship */ + struct shpstr ship; /* struct ship */ + double mobil; /* how much mobility the ship has left */ + int done; /* has this ship been interdicted yet? */ }; #define SHP_DEF(b, t) (t ? (b * (logx((double)t, (double)40.0) < 1.0 ? 1.0 : \ @@ -226,4 +226,3 @@ double logx(); #define CN_ERROR (-1) #endif /* _SHIP_H_ */ - diff --git a/include/subs.h b/include/subs.h index 1a3539f15..4c480f428 100644 --- a/include/subs.h +++ b/include/subs.h @@ -50,6 +50,6 @@ #include "genitem.h" #include "trade.h" #include "player.h" -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _SUBS_H_ */ diff --git a/include/tel.h b/include/tel.h index 91883c7e5..866c1b37c 100644 --- a/include/tel.h +++ b/include/tel.h @@ -42,20 +42,20 @@ #define TEL_UPDATE 3 /* update message */ #define TEL_LAST 3 -#define TEL_SECONDS 5 /* how many seconds before starting a new telegram */ +#define TEL_SECONDS 5 /* how many seconds before starting a new telegram */ -struct telstr { - natid tel_from; /* sender */ - s_char tel_type; - long tel_length; /* how long */ - time_t tel_date; /* when sent */ +struct telstr { + natid tel_from; /* sender */ + s_char tel_type; + long tel_length; /* how long */ + time_t tel_date; /* when sent */ }; extern s_char *mailbox(s_char *buf, natid cn); -extern s_char *teldir, *telfil; +extern s_char *teldir, *telfil; -extern s_char *annfil; +extern s_char *annfil; #endif /* _TEL_H_ */ diff --git a/include/trade.h b/include/trade.h index 28be53fed..bca64db70 100644 --- a/include/trade.h +++ b/include/trade.h @@ -46,37 +46,37 @@ #include "prototype.h" struct trdstr { - short ef_type; - natid trd_owner; - short trd_uid; - char trd_type; - short trd_unitid; - long trd_price; - int trd_maxbidder; - int trd_maxprice; - time_t trd_markettime; - coord trd_x; - coord trd_y; + short ef_type; + natid trd_owner; + short trd_uid; + char trd_type; + short trd_unitid; + long trd_price; + int trd_maxbidder; + int trd_maxprice; + time_t trd_markettime; + coord trd_x; + coord trd_y; }; struct genstr { - short trg_ef_type; - natid trg_own; - short trg_uid; - coord trg_x; - coord trg_y; - s_char trg_type; + short trg_ef_type; + natid trg_own; + short trg_uid; + coord trg_x; + coord trg_y; + s_char trg_type; }; union trdgenstr { - struct genstr gen; - struct nukstr nuk; - struct plnstr pln; - struct lndstr lnd; - struct shpstr shp; + struct genstr gen; + struct nukstr nuk; + struct plnstr pln; + struct lndstr lnd; + struct shpstr shp; }; - -s_char *trade_nameof _PROTO((struct trdstr *tp, union trdgenstr *tgp)); + +s_char *trade_nameof _PROTO((struct trdstr * tp, union trdgenstr * tgp)); #define gettrade(n, p) \ ef_read(EF_TRADE, n, (caddr_t)p) diff --git a/include/treaty.h b/include/treaty.h index de6dcfc6d..c9a6caf03 100644 --- a/include/treaty.h +++ b/include/treaty.h @@ -35,20 +35,20 @@ #ifndef _TREATY_H_ #define _TREATY_H_ -struct trtstr { - natid trt_cna; /* proposer */ - natid trt_cnb; /* acceptor */ - s_char trt_status; /* treaty status */ - s_char trt_fill; - short trt_acond; /* conditions for proposer */ - short trt_bcond; /* conditions for accepter */ - float trt_bond; /* amount of bond involved */ - time_t trt_exp; /* expiration date */ +struct trtstr { + natid trt_cna; /* proposer */ + natid trt_cnb; /* acceptor */ + s_char trt_status; /* treaty status */ + s_char trt_fill; + short trt_acond; /* conditions for proposer */ + short trt_bcond; /* conditions for accepter */ + float trt_bond; /* amount of bond involved */ + time_t trt_exp; /* expiration date */ }; -struct tchrstr { - int t_cond; /* bit to indicate this clause */ - s_char *t_name; /* description of clause */ +struct tchrstr { + int t_cond; /* bit to indicate this clause */ + s_char *t_name; /* description of clause */ }; #define TS_FREE 0 @@ -64,9 +64,9 @@ struct tchrstr { #define NEWSHP bit(5) /* no new ships */ #define NEWNUK bit(6) /* no new nuclear weapons */ #define NEWPLN bit(7) /* no new planes */ -#define NEWLND bit(8) /* no new land units */ +#define NEWLND bit(8) /* no new land units */ #define TRTENL bit(9) /* no enlistment */ -#define SUBFIR bit(10) /* no depth-charging submarines */ +#define SUBFIR bit(10) /* no depth-charging submarines */ /* global treaty variables */ @@ -77,8 +77,8 @@ struct tchrstr { #define gettrep(n) \ (struct trtstr *) ef_ptr(EF_TREATY, n) -extern struct tchrstr tchr[]; +extern struct tchrstr tchr[]; -extern int trt_maxno; +extern int trt_maxno; #endif /* _TREATY_H_ */ diff --git a/include/update.h b/include/update.h index 4f5634e81..c93d4138a 100644 --- a/include/update.h +++ b/include/update.h @@ -44,6 +44,6 @@ #include "nat.h" #include "nsc.h" #include "product.h" -#include "prototypes.h" /* must come at end, after defines and typedefs */ +#include "prototypes.h" /* must come at end, after defines and typedefs */ #endif /* _UPDATE_H_ */ diff --git a/include/user.h b/include/user.h index f2bb00fa5..dedacf41b 100644 --- a/include/user.h +++ b/include/user.h @@ -37,17 +37,17 @@ #include "queue.h" struct user { - struct emp_qelem queue; - struct iop *u_iop; - int u_cnum; - int u_pid; + struct emp_qelem queue; + struct iop *u_iop; + int u_cnum; + int u_pid; }; /* * lock commandsx */ -#define L_UNLOCK bit(0) /* command to unlock */ -#define L_LOCK bit(1) /* command to lock */ -#define L_NOLOCK bit(3) /* allow no new locks */ +#define L_UNLOCK bit(0) /* command to unlock */ +#define L_LOCK bit(1) /* command to lock */ +#define L_NOLOCK bit(3) /* allow no new locks */ #endif /* _USER_H_ */ diff --git a/include/xy.h b/include/xy.h index 81ec32dd2..163859c86 100644 --- a/include/xy.h +++ b/include/xy.h @@ -45,21 +45,23 @@ #define YNORM(y) (((y)<0) ? ((WORLD_Y-(-(y)%WORLD_Y))%WORLD_Y) : ((y)%WORLD_Y)) struct range { - coord lx; /* low-range x,y */ - coord ly; - coord hx; /* high-range x,y */ - coord hy; - int width; /* range width, height */ - int height; + coord lx; /* low-range x,y */ + coord ly; + coord hx; /* high-range x,y */ + coord hy; + int width; /* range width, height */ + int height; }; -extern s_char *xyfmt(); +extern s_char *xyfmt(); extern s_char *xyas(coord x, coord y, natid country); extern s_char *ownxy(struct sctstr *sp); -extern coord xrel(struct natstr *np, coord absx); -extern coord yrel(struct natstr *np, coord absy); -extern void xyrelrange(struct natstr *np, struct range *src,struct range *dst); -extern void xyabsrange(struct natstr *np, struct range *src,struct range *dst); +extern coord xrel(struct natstr *np, coord absx); +extern coord yrel(struct natstr *np, coord absy); +extern void xyrelrange(struct natstr *np, struct range *src, + struct range *dst); +extern void xyabsrange(struct natstr *np, struct range *src, + struct range *dst); extern void inputxy(coord *xp, coord *yp, natid cn); extern coord xabs(struct natstr *np, coord relx); extern coord yabs(struct natstr *np, coord rely); @@ -68,4 +70,3 @@ extern coord ynorm(register coord y); extern int xyinrange(coord x, coord y, struct range *rp); #endif /* _XY_H_ */ - diff --git a/src/client/bit.c b/src/client/bit.c index 500b13dee..840af3c08 100644 --- a/src/client/bit.c +++ b/src/client/bit.c @@ -42,8 +42,8 @@ #include "bit.h" -int bit_nfile; -int bit_nbytes; +int bit_nfile; +int bit_nbytes; int getfdtablesize(); void bit_zero(bit_fdmask); @@ -51,16 +51,16 @@ void bit_zero(bit_fdmask); bit_fdmask bit_newfdmask() { - extern s_char *malloc(); - bit_fdmask mask; - - if (bit_nfile == 0) { - bit_nfile = getfdtablesize(); - bit_nbytes = (bit_nfile + (BIT_BITSPERMASK-1)) / BIT_NBBY; - } - mask = (bit_fdmask) malloc(bit_nbytes); - (void) bit_zero(mask); - return mask; + extern s_char *malloc(); + bit_fdmask mask; + + if (bit_nfile == 0) { + bit_nfile = getfdtablesize(); + bit_nbytes = (bit_nfile + (BIT_BITSPERMASK - 1)) / BIT_NBBY; + } + mask = (bit_fdmask)malloc(bit_nbytes); + (void)bit_zero(mask); + return mask; } /* @@ -68,16 +68,16 @@ bit_newfdmask() */ void bit_zero(bitp) - bit_fdmask bitp; +bit_fdmask bitp; { - bit_mask *mask; - register int i; - register int nwords; - - mask = bitp; - nwords = bit_nbytes / sizeof(*mask); - for (i=0; i= min) { - if (setdtablesize(start) < 0) - break; - start -= 16; - } - errno = 0; + while (start >= min) { + if (setdtablesize(start) < 0) + break; + start -= 16; + } + errno = 0; #endif } @@ -60,14 +60,14 @@ int getfdtablesize() { #ifdef hpux - return _NFILE; + return _NFILE; #else #ifdef _WIN32 - return _NFILE; + return _NFILE; #else - int getdtablesize(); + int getdtablesize(); - return getdtablesize(); + return getdtablesize(); #endif #endif } diff --git a/src/client/expect.c b/src/client/expect.c index 96dac3c9f..75233f8c6 100644 --- a/src/client/expect.c +++ b/src/client/expect.c @@ -47,129 +47,126 @@ int expect(s, match, buf) - int s; - int match; - s_char *buf; +int s; +int match; +s_char *buf; { - int size; - s_char *p; - int n; - int code; - int newline; - s_char *ptr; - int cc; + int size; + s_char *p; + int n; + int code; + int newline; + s_char *ptr; + int cc; - size = 1024; + size = 1024; #ifndef _WIN32 - (void) alarm(30); + (void)alarm(30); #endif - ptr = buf; - n = recv(s, ptr, size, MSG_PEEK); - if (n <= 0) { - fprintf(stderr, "Expecting code %d\n", match); + ptr = buf; + n = recv(s, ptr, size, MSG_PEEK); + if (n <= 0) { + fprintf(stderr, "Expecting code %d\n", match); #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("recv"); - return 0; - } - size -= n; - buf[n] = '\0'; - if ((p = strchr(ptr, '\n')) == 0) { - do { + perror("recv"); + return 0; + } + size -= n; + buf[n] = '\0'; + if ((p = strchr(ptr, '\n')) == 0) { + do { #ifndef _WIN32 - cc = read(s, ptr, n); + cc = read(s, ptr, n); #else - cc = recv(s, ptr, n, 0); + cc = recv(s, ptr, n, 0); #endif - if (cc < 0) { + if (cc < 0) { #ifdef _WIN32 errno = WSAGetLastError(); #endif - perror("expect: read"); - return 0; - } - if (cc != n) { - fprintf(stderr, - "expect: short read (%d not %d)\n", - cc, n); - return 0; - } - ptr += n; - if ((n = recv(s, ptr, size, MSG_PEEK)) <= 0) { - fprintf(stderr, "Expecting %d, got %s\n", - match, buf); - return 0; - } - size -= n; - ptr[n] = '\0'; - } while ((p = index(ptr, '\n')) == 0); - newline = 1 + p - buf; - *p = 0; - } else - newline = 1 + p - ptr; + perror("expect: read"); + return 0; + } + if (cc != n) { + fprintf(stderr, "expect: short read (%d not %d)\n", cc, n); + return 0; + } + ptr += n; + if ((n = recv(s, ptr, size, MSG_PEEK)) <= 0) { + fprintf(stderr, "Expecting %d, got %s\n", match, buf); + return 0; + } + size -= n; + ptr[n] = '\0'; + } while ((p = index(ptr, '\n')) == 0); + newline = 1 + p - buf; + *p = 0; + } else + newline = 1 + p - ptr; #ifndef _WIN32 - cc = read(s, buf, newline); + cc = read(s, buf, newline); #else - cc = recv(s, buf, newline, 0); + cc = recv(s, buf, newline, 0); #endif - if (cc < 0) { + if (cc < 0) { #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("expect: read #2"); - return 0; - } - if (cc != newline) { - fprintf(stderr, "expect: short read #2 (%d not %d)\n", - cc, newline); - return 0; - } - buf[newline] = '\0'; + perror("expect: read #2"); + return 0; + } + if (cc != newline) { + fprintf(stderr, "expect: short read #2 (%d not %d)\n", + cc, newline); + return 0; + } + buf[newline] = '\0'; #ifndef _WIN32 - (void) alarm(0); + (void)alarm(0); #endif - if (!isxdigit(*buf)) { - fprintf(stderr, "Expecting %d, got %s\n", match, buf); - return 0; - } - if (isdigit(*buf)) - code = *buf - '0'; - else { - if (isupper(*buf)) - *buf = tolower(*buf); - code = 10 + *buf - 'a'; - } - if (code == match) - return 1; + if (!isxdigit(*buf)) { + fprintf(stderr, "Expecting %d, got %s\n", match, buf); return 0; + } + if (isdigit(*buf)) + code = *buf - '0'; + else { + if (isupper(*buf)) + *buf = tolower(*buf); + code = 10 + *buf - 'a'; + } + if (code == match) + return 1; + return 0; } void sendcmd(s, cmd, arg) - int s; - int cmd; - s_char *arg; +int s; +int cmd; +s_char *arg; { - extern struct fn fnlist[]; - s_char buf[128]; - int cc; - int len; + extern struct fn fnlist[]; + s_char buf[128]; + int cc; + int len; - (void) sprintf(buf, "%s %s\n", fnlist[cmd].name, arg != 0 ? arg : ""); - len = strlen(buf); + (void)sprintf(buf, "%s %s\n", fnlist[cmd].name, arg != 0 ? arg : ""); + len = strlen(buf); #ifndef _WIN32 - cc = write(s, buf, len); + cc = write(s, buf, len); #else - cc = send(s, buf, len, 0); + cc = send(s, buf, len, 0); #endif - if (cc < 0) { + if (cc < 0) { #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("sendcmd: write"); - } - if (cc != len) { - fprintf(stderr, "sendcmd: short write (%d not %d)\n", cc, len); - } + perror("sendcmd: write"); + } + if (cc != len) { + fprintf(stderr, "sendcmd: short write (%d not %d)\n", cc, len); + } } diff --git a/src/client/fnlist.h b/src/client/fnlist.h index 5de583000..8fb8f7dd6 100644 --- a/src/client/fnlist.h +++ b/src/client/fnlist.h @@ -35,11 +35,10 @@ #ifndef _FNLIST_H_ #define _FNLIST_H_ -struct fn { - int (*func)(); - s_char *name; - int value; +struct fn { + int (*func) (); + s_char *name; + int value; }; -#endif _FNLIST_H_ - +#endif /* _FNLIST_H_ */ diff --git a/src/client/globals.c b/src/client/globals.c index 9f754f7f5..6098af04b 100644 --- a/src/client/globals.c +++ b/src/client/globals.c @@ -38,14 +38,14 @@ #include "proto.h" struct fn fnlist[] = { - { NULL, "user", USER,}, - { NULL, "coun", COUN,}, - { NULL, "quit", QUIT,}, - { NULL, "pass", PASS,}, - { NULL, "play", PLAY,}, - { NULL, "list", LIST,}, - { NULL, "cmd", CMD,}, - { NULL, "ctld", CTLD,}, - { NULL, "kill", KILL,}, - { NULL, "", 0,}, + {NULL, "user", USER,}, + {NULL, "coun", COUN,}, + {NULL, "quit", QUIT,}, + {NULL, "pass", PASS,}, + {NULL, "play", PLAY,}, + {NULL, "list", LIST,}, + {NULL, "cmd", CMD,}, + {NULL, "ctld", CTLD,}, + {NULL, "kill", KILL,}, + {NULL, "", 0,}, }; diff --git a/src/client/handle.c b/src/client/handle.c index e9e4ccd8f..ef3645f23 100644 --- a/src/client/handle.c +++ b/src/client/handle.c @@ -38,15 +38,15 @@ int handleintr(s) - int s; +int s; { - extern int interrupt; + extern int interrupt; - if (interrupt) { - /* tacky, but it works */ - if (write(s, "\naborted\n", 1+7+1) <= 0) - return 0; - interrupt = 0; - } - return 1; + if (interrupt) { + /* tacky, but it works */ + if (write(s, "\naborted\n", 1 + 7 + 1) <= 0) + return 0; + interrupt = 0; + } + return 1; } diff --git a/src/client/host.c b/src/client/host.c index ab3da133c..5f308315e 100644 --- a/src/client/host.c +++ b/src/client/host.c @@ -47,87 +47,87 @@ int hostaddr(name, addr) - s_char *name; - struct sockaddr_in *addr; +s_char *name; +struct sockaddr_in *addr; { #ifndef _WIN32 - extern u_long inet_addr(); + extern u_long inet_addr(); #endif - struct hostent *hp; + struct hostent *hp; - if (name == 0 || *name == 0) - return 0; - if (isdigit(*name)) { - addr->sin_addr.s_addr = inet_addr(name); - } else { - hp = gethostbyname(name); - if (hp == NULL) { - fprintf(stderr, "%s: No such host\n", name); - return 0; - } - bcopy(hp->h_addr, (s_char *)&addr->sin_addr, - sizeof(addr->sin_addr)); + if (name == 0 || *name == 0) + return 0; + if (isdigit(*name)) { + addr->sin_addr.s_addr = inet_addr(name); + } else { + hp = gethostbyname(name); + if (hp == NULL) { + fprintf(stderr, "%s: No such host\n", name); + return 0; + } + bcopy(hp->h_addr, (s_char *)&addr->sin_addr, + sizeof(addr->sin_addr)); #ifdef _WIN32 - printf("Trying to connect to '%s'\n", inet_ntoa(addr->sin_addr)); - fflush(stdout); + printf("Trying to connect to '%s'\n", inet_ntoa(addr->sin_addr)); + fflush(stdout); #endif - } - return 1; + } + return 1; } int hostport(name, addr) - s_char *name; - struct sockaddr_in *addr; +s_char *name; +struct sockaddr_in *addr; { - struct servent *sp; + struct servent *sp; #ifndef _WIN32 - int atoi(); + int atoi(); #endif - if (name == 0 || *name == 0) - return 0; - if (isdigit(*name)) { + if (name == 0 || *name == 0) + return 0; + if (isdigit(*name)) { #ifndef _WIN32 - addr->sin_port = htons(atoi(name)); + addr->sin_port = htons(atoi(name)); #else - addr->sin_port = atoi(name); - addr->sin_port = htons(addr->sin_port); + addr->sin_port = atoi(name); + addr->sin_port = htons(addr->sin_port); #endif - } else { - sp = getservbyname(name, "tcp"); - if (sp == NULL) - return 0; - addr->sin_port = sp->s_port; - } - return 1; + } else { + sp = getservbyname(name, "tcp"); + if (sp == NULL) + return 0; + addr->sin_port = sp->s_port; + } + return 1; } int hostconnect(addr) - struct sockaddr_in *addr; +struct sockaddr_in *addr; { - int s; + int s; - s = socket(AF_INET, SOCK_STREAM, 0); - if (s < 0) { + s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) { #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("socket"); - return -1; - } - addr->sin_family = AF_INET; - if (connect(s, (struct sockaddr *)addr, sizeof(*addr)) < 0) { + perror("socket"); + return -1; + } + addr->sin_family = AF_INET; + if (connect(s, (struct sockaddr *)addr, sizeof(*addr)) < 0) { #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("connect"); + perror("connect"); #ifdef _WIN32 - printf("Check that your EMPIREHOST and EMPIREPORT are correct.\n"); + printf("Check that your EMPIREHOST and EMPIREPORT are correct.\n"); #endif - (void) close(s); - return -1; - } - return s; + (void)close(s); + return -1; + } + return s; } diff --git a/src/client/hpux.c b/src/client/hpux.c index 422b20cba..23ad4d595 100644 --- a/src/client/hpux.c +++ b/src/client/hpux.c @@ -38,58 +38,58 @@ s_char * rindex(sp, c) - register s_char *sp; - register int c; +register s_char *sp; +register int c; { - register s_char *r; + register s_char *r; - r = NULL; - do { - if (*sp == c) - r = sp; - } while (*sp++); - return r; + r = NULL; + do { + if (*sp == c) + r = sp; + } while (*sp++); + return r; } s_char * index(sp, c) - register s_char *sp; - register int c; +register s_char *sp; +register int c; { - do { - if (*sp == c) - return (sp); - } while (*sp++); - return NULL; + do { + if (*sp == c) + return (sp); + } while (*sp++); + return NULL; } int ffs(marg) - register unsigned marg; +register unsigned marg; { - register unsigned bval; - register int i; + register unsigned bval; + register int i; - if (marg == 0) - return 0; - for (bval=1, i=1; i <= 32; i++, bval <<= 1) - if (marg & bval) - return i; + if (marg == 0) return 0; + for (bval = 1, i = 1; i <= 32; i++, bval <<= 1) + if (marg & bval) + return i; + return 0; } bzero(ptr, len) - s_char *ptr; - int len; +s_char *ptr; +int len; { - memset(ptr, 0, len); + memset(ptr, 0, len); } bcopy(src, dst, len) - s_char *src; - s_char *dst; - int len; +s_char *src; +s_char *dst; +int len; { - memcpy(dst, src, len); + memcpy(dst, src, len); } #endif diff --git a/src/client/ioqueue.c b/src/client/ioqueue.c index b1eecb332..7e084fb38 100644 --- a/src/client/ioqueue.c +++ b/src/client/ioqueue.c @@ -42,9 +42,9 @@ #include "ioqueue.h" #ifdef _WIN32 -typedef struct iovec { - char *iov_base; - int iov_len; +typedef struct iovec { + char *iov_base; + int iov_len; } iovec_t; #endif @@ -62,15 +62,15 @@ void free(); void ioq_init(ioq, bsize) - struct ioqueue *ioq; - int bsize; +struct ioqueue *ioq; +int bsize; { - extern s_char num_teles[]; + extern s_char num_teles[]; - initque(&ioq->queue); - ioq->cc = 0; - ioq->bsize = bsize; - *num_teles = '\0'; + initque(&ioq->queue); + ioq->cc = 0; + ioq->bsize = bsize; + *num_teles = '\0'; } /* @@ -80,13 +80,13 @@ ioq_init(ioq, bsize) */ int ioq_peekiov(ioq, iov, max) - struct ioqueue *ioq; - struct iovec *iov; - int max; +struct ioqueue *ioq; +struct iovec *iov; +int max; { - if (ioq->cc <= 0) - return 0; - return ioqtoiov(ioq, iov, max); + if (ioq->cc <= 0) + return 0; + return ioqtoiov(ioq, iov, max); } /* @@ -96,91 +96,91 @@ ioq_peekiov(ioq, iov, max) */ int ioq_peek(ioq, buf, cc) - struct ioqueue *ioq; - s_char *buf; - int cc; +struct ioqueue *ioq; +s_char *buf; +int cc; { - return ioqtobuf(ioq, buf, cc); + return ioqtobuf(ioq, buf, cc); } int ioq_dequeue(ioq, cc) - struct ioqueue *ioq; - int cc; +struct ioqueue *ioq; +int cc; { - if (dequeuecc(ioq, cc) != cc) - return 0; - return cc; + if (dequeuecc(ioq, cc) != cc) + return 0; + return cc; } int ioq_read(ioq, buf, cc) - struct ioqueue *ioq; - s_char *buf; - int cc; +struct ioqueue *ioq; +s_char *buf; +int cc; { - int n; + int n; - n = ioqtobuf(ioq, buf, cc); - if (n > 0) - dequeuecc(ioq, n); - return n; + n = ioqtobuf(ioq, buf, cc); + if (n > 0) + dequeuecc(ioq, n); + return n; } void ioq_write(ioq, buf, cc) - struct ioqueue *ioq; - s_char *buf; - int cc; +struct ioqueue *ioq; +s_char *buf; +int cc; { - enqueuecc(ioq, buf, cc); + enqueuecc(ioq, buf, cc); } int ioq_qsize(ioq) - struct ioqueue *ioq; +struct ioqueue *ioq; { - return ioq->cc; + return ioq->cc; } void ioq_drain(ioq) - struct ioqueue *ioq; +struct ioqueue *ioq; { - struct io *io; - struct qelem *qp; + struct io *io; + struct qelem *qp; - while ((qp = ioq->queue.q_forw) != &ioq->queue) { - io = (struct io *) qp; - free(io->data); - (void) remque(&io->queue); - (void) free(io); - } - ioq->cc = 0; + while ((qp = ioq->queue.q_forw) != &ioq->queue) { + io = (struct io *)qp; + free(io->data); + (void)remque(&io->queue); + (void)free(io); + } + ioq->cc = 0; } s_char * ioq_gets(ioq, buf, cc) - struct ioqueue *ioq; - s_char *buf; - int cc; +struct ioqueue *ioq; +s_char *buf; +int cc; { - register s_char *p; - register s_char *end; - int nbytes; + register s_char *p; + register s_char *end; + int nbytes; - nbytes = ioqtobuf(ioq, buf, cc); - if (nbytes < cc) - cc = nbytes; - end = &buf[cc]; - for (p = buf; p < end && *p; p++) { - if (*p == '\n') { - *p = '\0'; - dequeuecc(ioq, (p - buf) + 1); - return buf; - } + nbytes = ioqtobuf(ioq, buf, cc); + if (nbytes < cc) + cc = nbytes; + end = &buf[cc]; + for (p = buf; p < end && *p; p++) { + if (*p == '\n') { + *p = '\0'; + dequeuecc(ioq, (p - buf) + 1); + return buf; } - return 0; + } + return 0; } /* @@ -194,36 +194,36 @@ ioq_gets(ioq, buf, cc) * left for a higher level. */ static -int + int ioqtobuf(ioq, buf, cc) - register struct ioqueue *ioq; - s_char *buf; - int cc; +register struct ioqueue *ioq; +s_char *buf; +int cc; { - register struct io *io; - struct qelem *qp; - s_char *offset; - int nbytes; - int nleft; + register struct io *io; + struct qelem *qp; + s_char *offset; + int nbytes; + int nleft; - nleft = cc; - offset = buf; - for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) { - io = (struct io *) qp; - if ((nbytes = io->nbytes - io->offset) < 0) { - fprintf(stderr, "ioqtobuf: offset %d nbytes %d\n", - io->offset, io->nbytes); - continue; - } - if (nbytes > 0) { - if (nleft < nbytes) - nbytes = nleft; - bcopy(io->data + io->offset, offset, nbytes); - offset += nbytes; - nleft -= nbytes; - } + nleft = cc; + offset = buf; + for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) { + io = (struct io *)qp; + if ((nbytes = io->nbytes - io->offset) < 0) { + fprintf(stderr, "ioqtobuf: offset %d nbytes %d\n", + io->offset, io->nbytes); + continue; } - return offset - buf; + if (nbytes > 0) { + if (nleft < nbytes) + nbytes = nleft; + bcopy(io->data + io->offset, offset, nbytes); + offset += nbytes; + nleft -= nbytes; + } + } + return offset - buf; } /* @@ -235,31 +235,31 @@ ioqtobuf(ioq, buf, cc) * of a full ioqueue still be quick. */ static -int + int ioqtoiov(ioq, iov, max) - register struct ioqueue *ioq; - register struct iovec *iov; - register int max; +register struct ioqueue *ioq; +register struct iovec *iov; +register int max; { - register struct io *io; - register int cc; - register int niov; - struct qelem *qp; + register struct io *io; + register int cc; + register int niov; + struct qelem *qp; - cc = 0; - niov = 0; - qp = ioq->queue.q_forw; - for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) { - io = (struct io *) qp; - if (niov >= MAXIOV || cc >= max) - break; - iov->iov_base = io->data + io->offset; - iov->iov_len = io->nbytes - io->offset; - cc += io->nbytes - io->offset; - niov++; - iov++; - } - return niov; + cc = 0; + niov = 0; + qp = ioq->queue.q_forw; + for (qp = ioq->queue.q_forw; qp != &ioq->queue; qp = qp->q_forw) { + io = (struct io *)qp; + if (niov >= MAXIOV || cc >= max) + break; + iov->iov_base = io->data + io->offset; + iov->iov_len = io->nbytes - io->offset; + cc += io->nbytes - io->offset; + niov++; + iov++; + } + return niov; } /* @@ -267,18 +267,18 @@ ioqtoiov(ioq, iov, max) */ static void enqueuecc(ioq, buf, cc) - struct ioqueue *ioq; - s_char *buf; - int cc; +struct ioqueue *ioq; +s_char *buf; +int cc; { - struct io *io; + struct io *io; - io = (struct io *) malloc(sizeof(*io)); - io->nbytes = cc; - io->offset = 0; - io->data = buf; - insque(&io->queue, ioq->queue.q_back); - ioq->cc += cc; + io = (struct io *)malloc(sizeof(*io)); + io->nbytes = cc; + io->offset = 0; + io->data = buf; + insque(&io->queue, ioq->queue.q_back); + ioq->cc += cc; } /* @@ -287,36 +287,36 @@ enqueuecc(ioq, buf, cc) * which are no longer used. */ static -int + int dequeuecc(ioq, cc) - register struct ioqueue *ioq; - register int cc; +register struct ioqueue *ioq; +register int cc; { - register struct io *io; - register struct qelem *qp; - register int nbytes; - register int there; + register struct io *io; + register struct qelem *qp; + register int nbytes; + register int there; - nbytes = 0; - while ((qp = ioq->queue.q_forw) != &ioq->queue) { - io = (struct io *) qp; - there = io->nbytes - io->offset; - if (there < 0) { - fprintf(stderr, "dequeuecc: nbytes %d, offset %d\n", - io->nbytes, io->offset); - continue; - } - if (cc > there) { - cc -= there; - nbytes += there; - (void) remque(&io->queue); - free(io->data); - } else { - io->offset += cc; - nbytes += cc; - break; - } + nbytes = 0; + while ((qp = ioq->queue.q_forw) != &ioq->queue) { + io = (struct io *)qp; + there = io->nbytes - io->offset; + if (there < 0) { + fprintf(stderr, "dequeuecc: nbytes %d, offset %d\n", + io->nbytes, io->offset); + continue; + } + if (cc > there) { + cc -= there; + nbytes += there; + (void)remque(&io->queue); + free(io->data); + } else { + io->offset += cc; + nbytes += cc; + break; } - ioq->cc -= nbytes; - return nbytes; + } + ioq->cc -= nbytes; + return nbytes; } diff --git a/src/client/ioqueue.h b/src/client/ioqueue.h index 4fe67dc89..c5aeac9da 100644 --- a/src/client/ioqueue.h +++ b/src/client/ioqueue.h @@ -35,15 +35,14 @@ #define MAXIOV 16 struct ioqueue { - struct qelem queue; /* queue fwd/back */ - int bsize; /* basic block size */ - int cc; /* character count */ + struct qelem queue; /* queue fwd/back */ + int bsize; /* basic block size */ + int cc; /* character count */ }; struct io { - struct qelem queue; /* list of ioqueue elements */ - int nbytes; /* number of data bytes present */ - int offset; /* offset into current entry */ - s_char *data; /* pointer to start */ + struct qelem queue; /* list of ioqueue elements */ + int nbytes; /* number of data bytes present */ + int offset; /* offset into current entry */ + s_char *data; /* pointer to start */ }; - diff --git a/src/client/login.c b/src/client/login.c index b3ca3609f..db8d8a5b0 100644 --- a/src/client/login.c +++ b/src/client/login.c @@ -47,80 +47,79 @@ void sendcmd(); int login(s, uname, cname, cpass, kill_proc) - int s; - s_char *uname; - s_char *cname; - s_char *cpass; - int kill_proc; +int s; +s_char *uname; +s_char *cname; +s_char *cpass; +int kill_proc; { - s_char tmp[128]; - s_char buf[1024]; - s_char *ptr; - s_char *p; + s_char tmp[128]; + s_char buf[1024]; + s_char *ptr; + s_char *p; - if (!expect(s, C_INIT, buf)) - return 0; - (void) sendcmd(s, USER, uname); - if (!expect(s, C_CMDOK, buf)) - return 0; - if (cname == 0) { - (void) printf("Country name? "); - cname = fgets(tmp, 128, stdin); - if (cname == 0 || *cname == 0) - return 0; - } - if (cname[strlen(cname) - 1] == '\n') - cname[strlen(cname) - 1] = 0; - if (cname[strlen(cname) - 1] == '\r') - cname[strlen(cname) - 1] = 0; - (void) sendcmd(s, COUN, cname); - if (!expect(s, C_CMDOK, buf)) { - (void) fprintf(stderr, "empire: no such country\n"); - return 0; - } - if (cpass == 0) { + if (!expect(s, C_INIT, buf)) + return 0; + (void)sendcmd(s, USER, uname); + if (!expect(s, C_CMDOK, buf)) + return 0; + if (cname == 0) { + (void)printf("Country name? "); + cname = fgets(tmp, 128, stdin); + if (cname == 0 || *cname == 0) + return 0; + } + if (cname[strlen(cname) - 1] == '\n') + cname[strlen(cname) - 1] = 0; + if (cname[strlen(cname) - 1] == '\r') + cname[strlen(cname) - 1] = 0; + (void)sendcmd(s, COUN, cname); + if (!expect(s, C_CMDOK, buf)) { + (void)fprintf(stderr, "empire: no such country\n"); + return 0; + } + if (cpass == 0) { #ifndef _WIN32 - cpass = (s_char *)getpass("Your name? "); + cpass = (s_char *)getpass("Your name? "); #else - printf("Note: This is echoed to the screen\n"); - printf("Your name? "); - cpass = tmp; - *cpass = 0; - fgets(cpass, 128, stdin); + printf("Note: This is echoed to the screen\n"); + printf("Your name? "); + cpass = tmp; + *cpass = 0; + fgets(cpass, 128, stdin); #endif - if (cpass == 0 || *cpass == 0) - return 0; - } - (void) printf("\n"); - (void) sendcmd(s, PASS, cpass); - bzero(cpass, strlen(cpass)); /* for core dumps */ - if (!expect(s, C_CMDOK, buf)) { - (void) fprintf(stderr, "Bad password\n"); - return 0; - } - if (kill_proc) { - (void) sendcmd(s, KILL, (s_char *)0); - (void) printf("\n\t-=O=-\n"); - (void) expect(s, C_EXIT, buf); - fprintf(stderr, "%s\n", buf); - return 0; - } - (void) sendcmd(s, PLAY, (s_char *)0); - (void) printf("\n\t-=O=-\n"); - if (!expect(s, C_INIT, buf)) { - fprintf(stderr, "%s\n", buf); - return 0; - } - for (ptr = buf; !isspace(*ptr); ptr++) - ; - ptr++; - p = index(ptr, '\n'); - if (p != 0) - *p = 0; - if (atoi(ptr) != CLIENTPROTO) { - printf("Empire client out of date; get new version!\n"); - printf(" this version: %d, current version: %d\n", - CLIENTPROTO, atoi(ptr)); - } - return 1; + if (cpass == 0 || *cpass == 0) + return 0; + } + (void)printf("\n"); + (void)sendcmd(s, PASS, cpass); + bzero(cpass, strlen(cpass)); /* for core dumps */ + if (!expect(s, C_CMDOK, buf)) { + (void)fprintf(stderr, "Bad password\n"); + return 0; + } + if (kill_proc) { + (void)sendcmd(s, KILL, (s_char *)0); + (void)printf("\n\t-=O=-\n"); + (void)expect(s, C_EXIT, buf); + fprintf(stderr, "%s\n", buf); + return 0; + } + (void)sendcmd(s, PLAY, (s_char *)0); + (void)printf("\n\t-=O=-\n"); + if (!expect(s, C_INIT, buf)) { + fprintf(stderr, "%s\n", buf); + return 0; + } + for (ptr = buf; !isspace(*ptr); ptr++) ; + ptr++; + p = index(ptr, '\n'); + if (p != 0) + *p = 0; + if (atoi(ptr) != CLIENTPROTO) { + printf("Empire client out of date; get new version!\n"); + printf(" this version: %d, current version: %d\n", + CLIENTPROTO, atoi(ptr)); + } + return 1; } diff --git a/src/client/main.c b/src/client/main.c index cb539c60b..4b09a4323 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -67,8 +67,8 @@ extern int errno; #define RETRY 3 -int interrupt; -int sock; +int interrupt; +int sock; void saveargv(); void getsose(); @@ -92,260 +92,254 @@ index(str, c) s_char *str; char c; { - static s_char *p; + static s_char *p; - p = str; - while (p && *p) { - if (*p == c) - return (s_char *)p; - p++; - } - return (s_char *)0; + p = str; + while (p && *p) { + if (*p == c) + return (s_char *)p; + p++; + } + return (s_char *)0; } bzero(ptr, size) s_char *ptr; int size; { - int i; + int i; - for (i = 0; i < size; i++) - ptr[i] = 0; + for (i = 0; i < size; i++) + ptr[i] = 0; } bcopy(src, dest, size) unsigned char *src, *dest; int size; { - int i; - unsigned char *d = dest, - *s = src; + int i; + unsigned char *d = dest, *s = src; - for (i = 0; i < size; i++) - *d++ = *s++; + for (i = 0; i < size; i++) + *d++ = *s++; } #endif int main(ac, av) - int ac; - s_char *av[]; +int ac; +s_char *av[]; { #ifdef _WIN32 - WSADATA WsaData; - int err; - fd_set readfds; - struct timeval tm; - INPUT_RECORD InpBuffer[10]; - DWORD numevents; - DWORD stdinmode; - SECURITY_ATTRIBUTES security; - void intr(void); + WSADATA WsaData; + int err; + fd_set readfds; + struct timeval tm; + INPUT_RECORD InpBuffer[10]; + DWORD numevents; + DWORD stdinmode; + SECURITY_ATTRIBUTES security; + void intr(void); #endif - extern s_char *getenv(); - extern s_char empireport[]; - extern s_char empirehost[]; - bit_fdmask mask; - bit_fdmask savemask; - struct ioqueue server; - s_char *argv[128]; - int i, j; - s_char *ptr; - s_char *auxout_fname; - FILE *auxout_fp; + extern s_char *getenv(); + extern s_char empireport[]; + extern s_char empirehost[]; + bit_fdmask mask; + bit_fdmask savemask; + struct ioqueue server; + s_char *argv[128]; + int i, j; + s_char *ptr; + s_char *auxout_fname; + FILE *auxout_fp; #ifndef _WIN32 - struct passwd *pwd; - void intr(); + struct passwd *pwd; + void intr(); #endif - struct sockaddr_in sin; - int n; - s_char *cname; - s_char *pname; - int retry = 0; - int send_kill = 0; + struct sockaddr_in sin; + int n; + s_char *cname; + s_char *pname; + int retry = 0; + int send_kill = 0; #ifdef _WIN32 - err = WSAStartup (0x0101, &WsaData); - if (err == SOCKET_ERROR) { - printf ("WSAStartup Failed\n"); - return FALSE; - } + err = WSAStartup(0x0101, &WsaData); + if (err == SOCKET_ERROR) { + printf("WSAStartup Failed\n"); + return FALSE; + } #else - mask = bit_newfdmask(); - savemask = bit_newfdmask(); + mask = bit_newfdmask(); + savemask = bit_newfdmask(); #endif - bzero((s_char *)argv, sizeof(argv)); - saveargv(ac, av, argv); - auxout_fname = 0; - auxout_fp = 0; - for (i = j = 1; i < ac; ++i) { - ptr = argv[i]; - if (strcmp(ptr, "-2") == 0) { - if (i + 1 >= ac) { - fprintf(stderr, "-2: Missing filename!\n"); - exit(1); - } - auxout_fname = argv[i+1]; - ++i; - continue; - } - else if (strcmp(ptr, "-k") == 0) { - send_kill = 1; - continue; - } - argv[j] = argv[i]; - ++j; - } - ac = j; - if (auxout_fname && (auxout_fp = fopen(auxout_fname, "a")) == NULL) { - fprintf(stderr, "Unable to open %s for append\n", auxout_fname); + bzero((s_char *)argv, sizeof(argv)); + saveargv(ac, av, argv); + auxout_fname = 0; + auxout_fp = 0; + for (i = j = 1; i < ac; ++i) { + ptr = argv[i]; + if (strcmp(ptr, "-2") == 0) { + if (i + 1 >= ac) { + fprintf(stderr, "-2: Missing filename!\n"); exit(1); + } + auxout_fname = argv[i + 1]; + ++i; + continue; + } else if (strcmp(ptr, "-k") == 0) { + send_kill = 1; + continue; } + argv[j] = argv[i]; + ++j; + } + ac = j; + if (auxout_fname && (auxout_fp = fopen(auxout_fname, "a")) == NULL) { + fprintf(stderr, "Unable to open %s for append\n", auxout_fname); + exit(1); + } #ifndef _WIN32 - pwd = getpwuid(getuid()); - if (pwd == NULL) { - fprintf(stderr, "You don't exist. Go away\n"); - exit(1); - } + pwd = getpwuid(getuid()); + if (pwd == NULL) { + fprintf(stderr, "You don't exist. Go away\n"); + exit(1); + } #endif - getsose(); - if (!hostport(getenv("EMPIREPORT"), &sin) && - !hostport("empire", &sin) && - !hostport(empireport, &sin)) { - fprintf(stderr, "No empire port\n"); - exit(1); - } - if (!hostaddr(getenv("EMPIREHOST"), &sin) && - !hostaddr(empirehost, &sin)) { - fprintf(stderr, "No empire host\n"); - exit(1); - } - if ((sock = hostconnect(&sin)) < 0) - exit(1); - cname = getenv("COUNTRY"); - pname = getenv("PLAYER"); - if (ac > 1) - cname = argv[1]; - if (ac > 2) - pname = argv[2]; + getsose(); + if (!hostport(getenv("EMPIREPORT"), &sin) && + !hostport("empire", &sin) && !hostport(empireport, &sin)) { + fprintf(stderr, "No empire port\n"); + exit(1); + } + if (!hostaddr(getenv("EMPIREHOST"), &sin) && + !hostaddr(empirehost, &sin)) { + fprintf(stderr, "No empire host\n"); + exit(1); + } + if ((sock = hostconnect(&sin)) < 0) + exit(1); + cname = getenv("COUNTRY"); + pname = getenv("PLAYER"); + if (ac > 1) + cname = argv[1]; + if (ac > 2) + pname = argv[2]; #ifndef _WIN32 - if (!login(sock, pwd->pw_name, cname, pname, send_kill)) { + if (!login(sock, pwd->pw_name, cname, pname, send_kill)) { #else - if (!login(sock, "win-empcl2.8", cname, pname, send_kill)) { + if (!login(sock, "win-empcl2.8", cname, pname, send_kill)) { #endif - close(sock); - exit(1); - } - ioq_init(&server, 2048); - io_init(); - mask = bit_newfdmask(); + close(sock); + exit(1); + } + ioq_init(&server, 2048); + io_init(); + mask = bit_newfdmask(); #ifndef _WIN32 - BIT_SETB(0, savemask); - BIT_SETB(sock, savemask); + BIT_SETB(0, savemask); + BIT_SETB(sock, savemask); #endif - (void) signal(SIGINT, intr); + (void)signal(SIGINT, intr); #ifndef _WIN32 - (void) signal(SIGPIPE, SIG_IGN); - while (BIT_ISSETB(sock, savemask)) { - bit_copy(savemask, mask); - n = select(sock+1, (fd_set *)mask, (fd_set *)0, (fd_set *)0, - (struct timeval *)0); - if (interrupt) { - if (!handleintr(sock)) - break; - errno = 0; - } - if (n <= 0) { - if (errno == EINTR) { - perror("select"); - (void) close(sock); - BIT_CLRB(sock, savemask); - } + (void)signal(SIGPIPE, SIG_IGN); + while (BIT_ISSETB(sock, savemask)) { + bit_copy(savemask, mask); + n = select(sock + 1, (fd_set *) mask, (fd_set *) 0, (fd_set *) 0, + (struct timeval *)0); + if (interrupt) { + if (!handleintr(sock)) + break; + errno = 0; + } + if (n <= 0) { + if (errno == EINTR) { + perror("select"); + (void)close(sock); + BIT_CLRB(sock, savemask); + } + } else { + if (BIT_ISSETB(0, mask)) { + if (!termio(0, sock, auxout_fp)) { + if (retry++ >= RETRY) { + BIT_CLRB(0, savemask); + } } else { - if (BIT_ISSETB(0, mask)) { - if (!termio(0, sock, auxout_fp)) { - if (retry++ >= RETRY) { - BIT_CLRB(0, savemask); - } - } else { - retry = 0; - } - } - if (BIT_ISSETB(sock, mask)) { - if (!serverio(sock, &server)) - BIT_CLRB(sock, savemask); - else - servercmd(&server, auxout_fp); - } + retry = 0; } + } + if (BIT_ISSETB(sock, mask)) { + if (!serverio(sock, &server)) + BIT_CLRB(sock, savemask); + else + servercmd(&server, auxout_fp); + } } + } #else - tm.tv_sec = 0; - tm.tv_usec = 1000; + tm.tv_sec = 0; + tm.tv_usec = 1000; - security.nLength = sizeof(SECURITY_ATTRIBUTES); - security.lpSecurityDescriptor = NULL; - security.bInheritHandle = TRUE; - hStdIn = CreateFile("CONIN$", - GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ | FILE_SHARE_WRITE, - &security, - OPEN_EXISTING, - (DWORD)NULL, - NULL); + security.nLength = sizeof(SECURITY_ATTRIBUTES); + security.lpSecurityDescriptor = NULL; + security.bInheritHandle = TRUE; + hStdIn = CreateFile("CONIN$", + GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + &security, OPEN_EXISTING, (DWORD) NULL, NULL); - if (hStdIn == INVALID_HANDLE_VALUE) { - printf("Error getting hStdIn.\n"); - fflush(stdout); - } - err = GetConsoleMode(hStdIn, &stdinmode); - if (!err) { - printf("Error getting console mode.\n"); - fflush(stdout); - } - stdinmode |= ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT; - err = SetConsoleMode(hStdIn, stdinmode); - if (!err) { - printf("Error setting console mode.\n"); - fflush(stdout); - } - while (1) { - FD_ZERO(&readfds); - FD_SET(sock, &readfds); - n = select(sock+1, &readfds, (fd_set *)0, (fd_set *)0, - (struct timeval *)&tm); - if (n < 0) { - if (errno == EINTR) { - errno = WSAGetLastError(); - perror("select"); - (void) close(sock); - break; - } + if (hStdIn == INVALID_HANDLE_VALUE) { + printf("Error getting hStdIn.\n"); + fflush(stdout); + } + err = GetConsoleMode(hStdIn, &stdinmode); + if (!err) { + printf("Error getting console mode.\n"); + fflush(stdout); + } + stdinmode |= ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT; + err = SetConsoleMode(hStdIn, stdinmode); + if (!err) { + printf("Error setting console mode.\n"); + fflush(stdout); + } + while (1) { + FD_ZERO(&readfds); + FD_SET(sock, &readfds); + n = select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0, + (struct timeval *)&tm); + if (n < 0) { + if (errno == EINTR) { + errno = WSAGetLastError(); + perror("select"); + (void)close(sock); + break; + } + } else { + if (WaitForSingleObject(hStdIn, 10) != WAIT_TIMEOUT) { + if (!termio(-1, sock, auxout_fp)) { + if (retry++ >= RETRY) { + ; + } } else { - if (WaitForSingleObject(hStdIn, 10) != WAIT_TIMEOUT) { - if (!termio(-1, sock, auxout_fp)) { - if (retry++ >= RETRY) { - ; - } - } else { - retry = 0; - } - FlushConsoleInputBuffer(hStdIn); - } - if (FD_ISSET(sock, &readfds)) { - if (!serverio(sock, &server)) - break; - else - servercmd(&server, auxout_fp); - } + retry = 0; } + FlushConsoleInputBuffer(hStdIn); + } + if (FD_ISSET(sock, &readfds)) { + if (!serverio(sock, &server)) + break; + else + servercmd(&server, auxout_fp); + } } - CloseHandle(hStdIn); + } + CloseHandle(hStdIn); #endif - ioq_drain(&server); - (void) close(sock); - exit(0); - return 0; /* Shut the compiler up */ + ioq_drain(&server); + (void)close(sock); + exit(0); + return 0; /* Shut the compiler up */ } void @@ -355,8 +349,8 @@ intr(void) intr() #endif { - interrupt++; + interrupt++; #ifdef hpux - signal(SIGINT, intr); + signal(SIGINT, intr); #endif } diff --git a/src/client/misc.h b/src/client/misc.h index b5f3de6be..8290f9f8f 100644 --- a/src/client/misc.h +++ b/src/client/misc.h @@ -62,11 +62,11 @@ typedef u_char natid; /* also change NSC_NATID in nsc.h */ #if !defined(aix) && !defined(sgi) #ifndef ultrix /* already defined in ultrix */ typedef char s_char; /* change to signed char for aix */ -#endif ultrix +#endif /* ultrix */ #else typedef signed char s_char; #endif /* !aix && !sgi */ -typedef short coord; /* also change NSC_COORD in nsc.h */ +typedef short coord; /* also change NSC_COORD in nsc.h */ /* * watch it; your compiler might not like this. * If you think this is bogus, look at /usr/include/struct.h @@ -82,13 +82,13 @@ typedef short coord; /* also change NSC_COORD in nsc.h */ #define hours(x) (60*60*(x)) #define days(x) (60*60*24*(x)) -typedef void (*voidfunc)(); +typedef void (*voidfunc) (); /* return codes from command routines */ -#define RET_OK 0 /* command completed sucessfully */ -#define RET_FAIL 1 /* command completed unsucessfully [?] */ -#define RET_SYN 2 /* syntax error in command */ -#define RET_SYS 3 /* system error (missing file, etc) */ +#define RET_OK 0 /* command completed sucessfully */ +#define RET_FAIL 1 /* command completed unsucessfully [?] */ +#define RET_SYN 2 /* syntax error in command */ +#define RET_SYS 3 /* system error (missing file, etc) */ #define MAX_DISTPATH_LEN 10 /* Has to go somewhere */ @@ -96,41 +96,41 @@ typedef void (*voidfunc)(); * references to library functions which aren't related to any * particular object, and are of general interest */ -extern long random(); +extern long random(); -extern double dmax(); -extern double dmin(); +extern double dmax(); +extern double dmin(); -extern s_char *fmt(); -extern s_char *copy(); -extern s_char *numstr(); -extern s_char *esplur(); -extern s_char *splur(); -extern s_char *iesplur(); -extern s_char *plur(); -extern s_char *getstarg(); -extern s_char *getstring(); +extern s_char *fmt(); +extern s_char *copy(); +extern s_char *numstr(); +extern s_char *esplur(); +extern s_char *splur(); +extern s_char *iesplur(); +extern s_char *plur(); +extern s_char *getstarg(); +extern s_char *getstring(); /* * frequently used libc functions */ #ifndef _WIN32 -extern s_char *malloc(); -extern s_char *calloc(); +extern s_char *malloc(); +extern s_char *calloc(); #endif #if (!defined (aix) && !defined (sgi)) -extern s_char *ctime(); -extern s_char *strncpy(); -extern s_char *strcpy(); +extern s_char *ctime(); +extern s_char *strncpy(); +extern s_char *strcpy(); #ifndef NeXT -extern s_char *index(); -extern s_char *rindex(); +extern s_char *index(); +extern s_char *rindex(); #endif /* NeXT */ -#endif /* !aix && !sgi*/ +#endif /* !aix && !sgi */ -extern time_t time(); -extern double atof(); +extern time_t time(); +extern double atof(); #endif diff --git a/src/client/queue.c b/src/client/queue.c index 896035b88..82c9b6700 100644 --- a/src/client/queue.c +++ b/src/client/queue.c @@ -39,42 +39,42 @@ void insque(p, q) - struct qelem *p; - struct qelem *q; +struct qelem *p; +struct qelem *q; { - p->q_forw = q->q_forw; - p->q_back = q; - q->q_forw->q_back = p; - q->q_forw = p; + p->q_forw = q->q_forw; + p->q_back = q; + q->q_forw->q_back = p; + q->q_forw = p; } void remque(p) - struct qelem *p; +struct qelem *p; { - p->q_back->q_forw = p->q_forw; - p->q_forw->q_back = p->q_back; + p->q_back->q_forw = p->q_forw; + p->q_forw->q_back = p->q_back; } void initque(p) - struct qelem *p; +struct qelem *p; { - p->q_forw = p; - p->q_back = p; + p->q_forw = p; + p->q_back = p; } struct qelem * makeqt(nelem) - int nelem; +int nelem; { - extern s_char *malloc(); - struct qelem *table; - struct qelem *qp; - int i; + extern s_char *malloc(); + struct qelem *table; + struct qelem *qp; + int i; - table = (struct qelem *) malloc(sizeof(*table) * nelem); - for (i=0,qp=table; iq_forw == (p)) struct qelem { - struct qelem *q_forw; - struct qelem *q_back; + struct qelem *q_forw; + struct qelem *q_back; }; -#endif _QUEUE +#endif /* _QUEUE */ diff --git a/src/client/saveargv.c b/src/client/saveargv.c index 2d6fcc802..3d2750559 100644 --- a/src/client/saveargv.c +++ b/src/client/saveargv.c @@ -35,19 +35,19 @@ void saveargv(ac, src, dst) - int ac; - s_char **src; - s_char **dst; +int ac; +s_char **src; +s_char **dst; { - extern s_char *strcpy(); - extern s_char *malloc(); - register s_char *ptr; - register int i; + extern s_char *strcpy(); + extern s_char *malloc(); + register s_char *ptr; + register int i; - for (i = 0; i < ac; i++) { - dst[i] = strcpy(malloc(strlen(src[i])+1), src[i]); - ptr = src[i]; - while (*ptr) - *ptr++ = ' '; - } + for (i = 0; i < ac; i++) { + dst[i] = strcpy(malloc(strlen(src[i]) + 1), src[i]); + ptr = src[i]; + while (*ptr) + *ptr++ = ' '; + } } diff --git a/src/client/servcmd.c b/src/client/servcmd.c index d2d43adf3..f15341fcc 100644 --- a/src/client/servcmd.c +++ b/src/client/servcmd.c @@ -46,14 +46,14 @@ extern s_char *gettag(); -s_char num_teles[64]; -static s_char the_prompt[1024]; -static int mode; -static int nbtu; -static int nmin; -FILE *redir_fp; -FILE *pipe_fp; -int exec_fd; +s_char num_teles[64]; +static s_char the_prompt[1024]; +static int mode; +static int nbtu; +static int nmin; +FILE *redir_fp; +FILE *pipe_fp; +int exec_fd; void prompt(); void doredir(); @@ -66,100 +66,97 @@ int sendeof(); int termio(); void _noecho(); -extern s_char *SO; -extern s_char *SE; +extern s_char *SO; +extern s_char *SE; void servercmd(ioq, auxfi) - struct ioqueue *ioq; - FILE *auxfi; +struct ioqueue *ioq; +FILE *auxfi; { - s_char *ioq_gets(struct ioqueue *, s_char *, int); - s_char buf[1024]; - s_char *p; - int code; + s_char *ioq_gets(struct ioqueue *, s_char *, int); + s_char buf[1024]; + s_char *p; + int code; - while (ioq_gets(ioq, buf, sizeof(buf))) { - p = buf; - while (*p && !isspace(*p)) - p++; - *p++ = 0; - if (isalpha(*buf)) - code = 10 + (*buf - 'a'); - else - code = *buf - '0'; - switch (code) { - case C_PROMPT: - if (sscanf(p, "%d %d", &nbtu, &nmin) != 2) { - fprintf(stderr, "prompt: bad server prompt %s\n", p); - } - mode = code; - sprintf(the_prompt, "[%d:%d] Command : ", nbtu, nmin); - prompt(auxfi); - break; - case C_REDIR: - doredir(p); - break; - case C_PIPE: - dopipe(p); - break; - case C_FLUSH: - mode = code; - sprintf(the_prompt, "%s", p); - prompt(auxfi); - break; - case C_EXECUTE: - doexecute(p, auxfi); - break; - case C_INFORM: - if (*p) { - p[strlen(p)-1] = '\0'; - sprintf(num_teles, "(%s) ", p + 1); - if (!redir_fp && - !pipe_fp && - !exec_fd) { - putchar('\07'); - prompt(0); - } - } - else - *num_teles = '\0'; - break; - default: - output(code, p, auxfi); - break; + while (ioq_gets(ioq, buf, sizeof(buf))) { + p = buf; + while (*p && !isspace(*p)) + p++; + *p++ = 0; + if (isalpha(*buf)) + code = 10 + (*buf - 'a'); + else + code = *buf - '0'; + switch (code) { + case C_PROMPT: + if (sscanf(p, "%d %d", &nbtu, &nmin) != 2) { + fprintf(stderr, "prompt: bad server prompt %s\n", p); + } + mode = code; + sprintf(the_prompt, "[%d:%d] Command : ", nbtu, nmin); + prompt(auxfi); + break; + case C_REDIR: + doredir(p); + break; + case C_PIPE: + dopipe(p); + break; + case C_FLUSH: + mode = code; + sprintf(the_prompt, "%s", p); + prompt(auxfi); + break; + case C_EXECUTE: + doexecute(p, auxfi); + break; + case C_INFORM: + if (*p) { + p[strlen(p) - 1] = '\0'; + sprintf(num_teles, "(%s) ", p + 1); + if (!redir_fp && !pipe_fp && !exec_fd) { + putchar('\07'); + prompt(0); } + } else + *num_teles = '\0'; + break; + default: + output(code, p, auxfi); + break; } + } } void prompt(auxfi) - FILE *auxfi; +FILE *auxfi; { - if (mode == C_PROMPT) { - if (redir_fp) { - (void) fclose(redir_fp); - redir_fp = 0; - } else if (pipe_fp) { + if (mode == C_PROMPT) { + if (redir_fp) { + (void)fclose(redir_fp); + redir_fp = 0; + } else if (pipe_fp) { #ifndef _WIN32 - (void) pclose(pipe_fp); + (void)pclose(pipe_fp); #endif - pipe_fp = 0; - } else if (exec_fd > 0) { - close(exec_fd); - close(0); - exec_fd = -1; - open("/dev/tty", O_RDONLY, 0); - } - } - if (mode == C_PROMPT) - printf("\n"); - printf("%s%s", num_teles, the_prompt); - (void) fflush(stdout); - if (auxfi) { - fprintf(auxfi, "\n%s%s", num_teles, the_prompt); - (void)fflush(auxfi); + pipe_fp = 0; + } else if (exec_fd > 0) { + close(exec_fd); + close(0); + exec_fd = -1; + open("/dev/tty", O_RDONLY, 0); } + } + if (mode == C_PROMPT) + printf("\n"); + printf("%s%s", num_teles, the_prompt); + (void)fflush(stdout); + if (auxfi) { + fprintf(auxfi, "\n%s%s", num_teles, the_prompt); + (void)fflush(auxfi); + } } /* @@ -167,51 +164,52 @@ prompt(auxfi) */ void doredir(p) - s_char *p; +s_char *p; { - s_char *how; - s_char *name; - s_char *tag; - int mode; - int fd; + s_char *how; + s_char *name; + s_char *tag; + int mode; + int fd; - if (redir_fp) { - (void) fclose(redir_fp); - redir_fp = 0; - } - how = p++; - if (*p && ((*p == '>') || (*p == '!'))) - p++; - tag = gettag(p); - while (*p && isspace(*p)) - p++; - name = p; - while (*p && !isspace(*p)) - p++; - *p = 0; - if (tag == NULL) { - fprintf(stderr, "WARNING! Server redirected output to file %s\n",name); - return; - } - mode = O_WRONLY | O_CREAT; - if (how[1] == '>') - mode |= O_APPEND; - else if (how[1] == '!') - mode |= O_TRUNC; - else - mode |= O_EXCL; - if (*name == 0) { - fprintf(stderr, "Null file name after redirect\n"); - free(tag); - return; - } - if ((fd = open(name, mode, 0600)) < 0) { - fprintf(stderr, "Redirect open failed\n"); - perror(name); - } else { - redir_fp = fdopen(fd, "w"); - } + if (redir_fp) { + (void)fclose(redir_fp); + redir_fp = 0; + } + how = p++; + if (*p && ((*p == '>') || (*p == '!'))) + p++; + tag = gettag(p); + while (*p && isspace(*p)) + p++; + name = p; + while (*p && !isspace(*p)) + p++; + *p = 0; + if (tag == NULL) { + fprintf(stderr, "WARNING! Server redirected output to file %s\n", + name); + return; + } + mode = O_WRONLY | O_CREAT; + if (how[1] == '>') + mode |= O_APPEND; + else if (how[1] == '!') + mode |= O_TRUNC; + else + mode |= O_EXCL; + if (*name == 0) { + fprintf(stderr, "Null file name after redirect\n"); free(tag); + return; + } + if ((fd = open(name, mode, 0600)) < 0) { + fprintf(stderr, "Redirect open failed\n"); + perror(name); + } else { + redir_fp = fdopen(fd, "w"); + } + free(tag); } /* @@ -219,155 +217,156 @@ doredir(p) */ void dopipe(p) - s_char *p; +s_char *p; { - extern FILE *popen(); - s_char *tag; + extern FILE *popen(); + s_char *tag; - if (*p == '|') - p++; - tag = gettag(p); - while (*p && isspace(*p)) - p++; - if (tag == NULL) { - fprintf(stderr, "WARNING! Server attempted to run: %s\n",p); - return; - } - if (*p == 0) { - fprintf(stderr, "Null program name after redirect\n"); - free(tag); - return; - } + if (*p == '|') + p++; + tag = gettag(p); + while (*p && isspace(*p)) + p++; + if (tag == NULL) { + fprintf(stderr, "WARNING! Server attempted to run: %s\n", p); + return; + } + if (*p == 0) { + fprintf(stderr, "Null program name after redirect\n"); + free(tag); + return; + } #ifndef _WIN32 - if ((pipe_fp = popen(p, "w")) == 0) { + if ((pipe_fp = popen(p, "w")) == 0) { #else - if (1) { + if (1) { #endif - fprintf(stderr, "Pipe open failed\n"); - perror(p); - } - free(tag); + fprintf(stderr, "Pipe open failed\n"); + perror(p); + } + free(tag); } void doexecute(p, auxfi) - s_char *p; - FILE *auxfi; +s_char *p; +FILE *auxfi; { - extern int sock; - int fd; - s_char *tag; + extern int sock; + int fd; + s_char *tag; - tag = gettag(p); - while (*p && isspace(*p)) - p++; - if (tag == NULL) { - fprintf(stderr, "WARNING! Server attempted unauthorized read of file %s\n",p); - return; - } - if (p == 0) { - fprintf(stderr, "Null file to execute\n"); - free(tag); - return; - } + tag = gettag(p); + while (*p && isspace(*p)) + p++; + if (tag == NULL) { + fprintf(stderr, + "WARNING! Server attempted unauthorized read of file %s\n", + p); + return; + } + if (p == 0) { + fprintf(stderr, "Null file to execute\n"); + free(tag); + return; + } #if !defined(_WIN32) - if ((fd = open(p, O_RDONLY, 0)) < 0) { + if ((fd = open(p, O_RDONLY, 0)) < 0) { #else - if ((fd = open(p, O_RDONLY|O_BINARY, 0)) < 0) { + if ((fd = open(p, O_RDONLY | O_BINARY, 0)) < 0) { #endif - fprintf(stderr, "Can't open execute file\n"); - perror(p); - free(tag); - return; - } - /* copies 4k at a time to the socket */ - while (termio(fd, sock, auxfi)) /*do copy*/; - /* Some platforms don't send the eof (cntl-D) at the end of - copying a file. If emp_client hangs at the end of an - execute, include the following line and notify wolfpack - of the platform you are using. - sendeof(sock); - */ - close(fd); + fprintf(stderr, "Can't open execute file\n"); + perror(p); free(tag); + return; + } + /* copies 4k at a time to the socket */ + while (termio(fd, sock, auxfi)) /*do copy */ + ; + /* Some platforms don't send the eof (cntl-D) at the end of + copying a file. If emp_client hangs at the end of an + execute, include the following line and notify wolfpack + of the platform you are using. + sendeof(sock); + */ + close(fd); + free(tag); } void output(code, buf, auxfi) - int code; - s_char *buf; - FILE *auxfi; +int code; +s_char *buf; +FILE *auxfi; { - switch (code) { - case C_NOECHO: - _noecho(0); - break; - case C_FLUSH: - (void) fflush(stdout); - if (auxfi) - (void) fflush(auxfi); - break; - case C_ABORT: - printf("Aborted\n"); - if (auxfi) - fprintf(auxfi, "Aborted\n"); - break; - case C_CMDERR: - case C_BADCMD: - printf("Error; "); - if (auxfi) - fprintf(auxfi, "Error; "); - break; - case C_EXIT: - printf("Exit: "); - if (auxfi) - fprintf(auxfi, "Exit: "); - break; - case C_FLASH: - printf("\n"); - break; - default: - break; - } - if (auxfi) { - fprintf(auxfi, "%s", buf); - if (code == C_FLUSH) - (void) fflush(auxfi); - else - (void) putc('\n', auxfi); - } + switch (code) { + case C_NOECHO: + _noecho(0); + break; + case C_FLUSH: + (void)fflush(stdout); + if (auxfi) + (void)fflush(auxfi); + break; + case C_ABORT: + printf("Aborted\n"); + if (auxfi) + fprintf(auxfi, "Aborted\n"); + break; + case C_CMDERR: + case C_BADCMD: + printf("Error; "); + if (auxfi) + fprintf(auxfi, "Error; "); + break; + case C_EXIT: + printf("Exit: "); + if (auxfi) + fprintf(auxfi, "Exit: "); + break; + case C_FLASH: + printf("\n"); + break; + default: + break; + } + if (auxfi) { + fprintf(auxfi, "%s", buf); + if (code == C_FLUSH) + (void)fflush(auxfi); + else + (void)putc('\n', auxfi); + } - if (redir_fp) - fprintf(redir_fp, "%s\n", buf); - else if (pipe_fp) - fprintf(pipe_fp, "%s\n", buf); - else { - if (SO && SE) - screen(buf); - else - fputs(buf, stdout); - if (code == C_FLUSH) - (void) fflush(stdout); - else - (void) putc('\n', stdout); - } + if (redir_fp) + fprintf(redir_fp, "%s\n", buf); + else if (pipe_fp) + fprintf(pipe_fp, "%s\n", buf); + else { + if (SO && SE) + screen(buf); + else + fputs(buf, stdout); + if (code == C_FLUSH) + (void)fflush(stdout); + else + (void)putc('\n', stdout); + } } void screen(buf) - register s_char *buf; +register s_char *buf; { - register s_char *sop; - register s_char c; + register s_char *sop; + register s_char c; - while ((c = *buf++)) { - if (c & 0x80) { - for (sop = SO; putc(*sop, stdout); sop++) - ; - (void) putc(c & 0x7f, stdout); - for (sop = SE; putc(*sop, stdout); sop++) - ; - } else - (void) putc(c, stdout); - } + while ((c = *buf++)) { + if (c & 0x80) { + for (sop = SO; putc(*sop, stdout); sop++) ; + (void)putc(c & 0x7f, stdout); + for (sop = SE; putc(*sop, stdout); sop++) ; + } else + (void)putc(c, stdout); + } } diff --git a/src/client/serverio.c b/src/client/serverio.c index 919950e24..e08e183b2 100644 --- a/src/client/serverio.c +++ b/src/client/serverio.c @@ -51,42 +51,41 @@ void ioq_write(); int serverio(s, ioq) - int s; - struct ioqueue *ioq; +int s; +struct ioqueue *ioq; { #ifndef _WIN32 - extern s_char *realloc(); + extern s_char *realloc(); #else - extern void *realloc(); + extern void *realloc(); #endif - s_char *buf; - int n; + s_char *buf; + int n; - if ((buf = malloc(ioq->bsize)) == 0) { - fprintf(stderr, "malloc server i/o failed\n"); - return 0; - } + if ((buf = malloc(ioq->bsize)) == 0) { + fprintf(stderr, "malloc server i/o failed\n"); + return 0; + } #ifdef _WIN32 - n = recv(s, buf, ioq->bsize, 0); + n = recv(s, buf, ioq->bsize, 0); #else - n = read(s, buf, ioq->bsize); + n = read(s, buf, ioq->bsize); #endif - if (n < 0) { + if (n < 0) { #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("server i/o read"); - free(buf); - return 0; - } - if (n == 0) { - fprintf(stderr, "Server EOF\n"); - (void) close(s); - return 0; - } - if (n != ioq->bsize) - buf = (s_char *)realloc(buf, n); - ioq_write(ioq, buf, n); - return 1; + perror("server i/o read"); + free(buf); + return 0; + } + if (n == 0) { + fprintf(stderr, "Server EOF\n"); + (void)close(s); + return 0; + } + if (n != ioq->bsize) + buf = (s_char *)realloc(buf, n); + ioq_write(ioq, buf, n); + return 1; } - diff --git a/src/client/tags.c b/src/client/tags.c index f6fb8abec..fd5e59e1e 100644 --- a/src/client/tags.c +++ b/src/client/tags.c @@ -55,35 +55,36 @@ void free(); void io_init() { - taglist = NULL; - buf[0] = 0; - tagnum = 0; - sprintf(exec,"execute"); + taglist = NULL; + buf[0] = 0; + tagnum = 0; + sprintf(exec, "execute"); } s_char * gettag(p) - s_char *p; +s_char *p; { - struct tagstruct *tag1,*tag2; + struct tagstruct *tag1, *tag2; - if (taglist == NULL) return NULL; - tag1 = taglist; - if (!strncmp(tag1->item,p,strlen(tag1->item))) { - p = tag1->item; - taglist = taglist->next; - free(tag1); - return p; - } - while (tag1->next != NULL) { - tag2 = tag1->next; - if (!strncmp(tag2->item,p,strlen(tag2->item))) { - p = tag2->item; - tag1->next = tag2->next; - free(tag2); - return p; - } - tag1 = tag1->next; - } + if (taglist == NULL) return NULL; + tag1 = taglist; + if (!strncmp(tag1->item, p, strlen(tag1->item))) { + p = tag1->item; + taglist = taglist->next; + free(tag1); + return p; + } + while (tag1->next != NULL) { + tag2 = tag1->next; + if (!strncmp(tag2->item, p, strlen(tag2->item))) { + p = tag2->item; + tag1->next = tag2->next; + free(tag2); + return p; + } + tag1 = tag1->next; + } + return NULL; } diff --git a/src/client/tags.h b/src/client/tags.h index 0d79835bc..806fd606a 100644 --- a/src/client/tags.h +++ b/src/client/tags.h @@ -35,8 +35,8 @@ #define _TAGS_H_ struct tagstruct { - s_char *item; - struct tagstruct *next; + s_char *item; + struct tagstruct *next; }; #endif diff --git a/src/client/termio.c b/src/client/termio.c index 2296f18b9..54c44c652 100644 --- a/src/client/termio.c +++ b/src/client/termio.c @@ -61,206 +61,210 @@ int sendeof(); int termio(fd, sock, auxfi) - int fd; - int sock; - FILE *auxfi; +int fd; +int sock; +FILE *auxfi; { - s_char out[4096]; - int i,n; - s_char *ptr; - s_char *p,*q,*r,*s,*t; - int nbytes; - int numarg,prespace,exec_com,inarg,quoted,tagging; - struct tagstruct *tag; + s_char out[4096]; + int i, n; + s_char *ptr; + s_char *p, *q, *r, *s, *t; + int nbytes; + int numarg, prespace, exec_com, inarg, quoted, tagging; + struct tagstruct *tag; #ifdef _WIN32 - char c; - INPUT_RECORD InpBuffer[2]; - int err; + char c; + INPUT_RECORD InpBuffer[2]; + int err; #endif - i = strlen(buf); - p = buf + i; + i = strlen(buf); + p = buf + i; #ifndef _WIN32 - n = read(fd, p, sizeof(buf) - i); + n = read(fd, p, sizeof(buf) - i); #else /* The keyboard is sometimes generating both keydown and keyup * events for the same key. Thus, we only want to grab keydown * events. */ - if (fd == -1) { - err = PeekConsoleInput(hStdIn, InpBuffer, 1, &n); - if (InpBuffer[0].EventType != KEY_EVENT) { - ReadConsoleInput(hStdIn, InpBuffer, 1, &n); - return 1; - } - if (!InpBuffer[0].Event.KeyEvent.bKeyDown) { - ReadConsoleInput(hStdIn, InpBuffer, 1, &n); - return 1; - } - c = InpBuffer[0].Event.KeyEvent.uChar.AsciiChar; - - if (c == 13) - c = 10; - n = 1; - p[0] = c; - p[1] = '\0'; - if (c != 10) - ReadConsole(hStdIn, &p[0], sizeof(buf) - i , &n, NULL); - else - putchar(c); + if (fd == -1) { + err = PeekConsoleInput(hStdIn, InpBuffer, 1, &n); + if (InpBuffer[0].EventType != KEY_EVENT) { + ReadConsoleInput(hStdIn, InpBuffer, 1, &n); + return 1; + } + if (!InpBuffer[0].Event.KeyEvent.bKeyDown) { + ReadConsoleInput(hStdIn, InpBuffer, 1, &n); + return 1; + } + c = InpBuffer[0].Event.KeyEvent.uChar.AsciiChar; + + if (c == 13) + c = 10; + n = 1; + p[0] = c; + p[1] = '\0'; + if (c != 10) + ReadConsole(hStdIn, &p[0], sizeof(buf) - i, &n, NULL); + else + putchar(c); /* Strip off the CRLF to just LF */ - if (n > 1) { - if (p[n-2] == 13 && p[n-1] == 10) { - p[n-2] = 10; - p[n-1] = 0; - n--; - } + if (n > 1) { + if (p[n - 2] == 13 && p[n - 1] == 10) { + p[n - 2] = 10; + p[n - 1] = 0; + n--; } - FlushConsoleInputBuffer(hStdIn); - } else { - n = read(fd, p, sizeof(buf) - i); } + FlushConsoleInputBuffer(hStdIn); + } else { + n = read(fd, p, sizeof(buf) - i); + } #endif - if (n == 0) { - sendeof(sock); - return 0; - } - if (n < 0) { - perror("read standard input"); - return 0; - } - n += i; - ptr = buf; - p = buf; - q = out; - r = out; - numarg = 0; - tagging = 0; - inarg = 0; - prespace = 1; - quoted = 0; - while (p < buf + n && q < out + 4000) { - if (*p == '\n') { - if (tagging) { - tag = (struct tagstruct *) malloc(sizeof(struct tagstruct)); - tag->item = (s_char *) malloc((1+p-s) * sizeof(s_char)); - tag->next = taglist; - taglist = tag; - t = tag->item; - while (s < p) *t++ = *s++; - *t = 0; - } - *q++ = *p++; - numarg = 0; - tagging = 0; - inarg = 0; - prespace = 1; - quoted = 0; - ptr = p; - r = q; - } else if (tagging) { - *q++ = *p++; - } else if (!quoted && isspace(*p)) { - *q++ = *p++; - prespace = 1; - if (numarg == 1 && exec_com && s > exec + 2) { - tagging = 1; - s = p; - } - } else if (prespace && *p == '|') { - tagging = 1; - *q++ = *p++; - s = p; - } else if (prespace && *p == '>') { - tagging = 1; - *q++ = *p++; - if (*p != '\n' && (*p == '!' || *p == '>')) *q++ = *p++; - s = p; - } else { - prespace = 0; - if (*p == '"') { - quoted = !quoted; - } else { - if (!inarg && *p != '?') { - s = exec; - exec_com = 1; - numarg++; - } - inarg = 1; - if (*s && *s++ != *p) exec_com = 0; - } - *q++ = *p++; + if (n == 0) { + sendeof(sock); + return 0; + } + if (n < 0) { + perror("read standard input"); + return 0; + } + n += i; + ptr = buf; + p = buf; + q = out; + r = out; + numarg = 0; + tagging = 0; + inarg = 0; + prespace = 1; + quoted = 0; + while (p < buf + n && q < out + 4000) { + if (*p == '\n') { + if (tagging) { + tag = (struct tagstruct *)malloc(sizeof(struct tagstruct)); + tag->item = (s_char *)malloc((1 + p - s) * sizeof(s_char)); + tag->next = taglist; + taglist = tag; + t = tag->item; + while (s < p) + *t++ = *s++; + *t = 0; + } + *q++ = *p++; + numarg = 0; + tagging = 0; + inarg = 0; + prespace = 1; + quoted = 0; + ptr = p; + r = q; + } else if (tagging) { + *q++ = *p++; + } else if (!quoted && isspace(*p)) { + *q++ = *p++; + prespace = 1; + if (numarg == 1 && exec_com && s > exec + 2) { + tagging = 1; + s = p; + } + } else if (prespace && *p == '|') { + tagging = 1; + *q++ = *p++; + s = p; + } else if (prespace && *p == '>') { + tagging = 1; + *q++ = *p++; + if (*p != '\n' && (*p == '!' || *p == '>')) + *q++ = *p++; + s = p; + } else { + prespace = 0; + if (*p == '"') { + quoted = !quoted; + } else { + if (!inarg && *p != '?') { + s = exec; + exec_com = 1; + numarg++; } + inarg = 1; + if (*s && *s++ != *p) + exec_com = 0; + } + *q++ = *p++; } - p = buf; - while (ptr < buf + n) *p++ = *ptr++; - *p = 0; - ptr = out; - n = r - out; - if (auxfi) { - fwrite(out, n, 1, auxfi); - } - while (n > 0) { + } + p = buf; + while (ptr < buf + n) + *p++ = *ptr++; + *p = 0; + ptr = out; + n = r - out; + if (auxfi) { + fwrite(out, n, 1, auxfi); + } + while (n > 0) { #ifndef _WIN32 - nbytes = write(sock, ptr, n); + nbytes = write(sock, ptr, n); #else - nbytes = send(sock, ptr, n, 0); + nbytes = send(sock, ptr, n, 0); #endif - if (nbytes <= 0) { + if (nbytes <= 0) { #ifdef _WIN32 - errno = WSAGetLastError(); + errno = WSAGetLastError(); #endif - perror("write server socket"); - return 0; - } - ptr += nbytes; - n -= nbytes; + perror("write server socket"); + return 0; } - return 1; + ptr += nbytes; + n -= nbytes; + } + return 1; } int sendeof(sock) - int sock; +int sock; { #ifndef _WIN32 - if (write(sock, "ctld\n", 5) < 5) { + if (write(sock, "ctld\n", 5) < 5) { #else - if (send(sock, "ctld\n", 5, 0) < 5) { + if (send(sock, "ctld\n", 5, 0) < 5) { #endif - fprintf(stderr, "sendeof: EOF send failed\n"); - close(sock); - return 0; - } - return 1; + fprintf(stderr, "sendeof: EOF send failed\n"); + close(sock); + return 0; + } + return 1; } -int echomode = 1; +int echomode = 1; #if defined(hpux) || defined(aix) || defined (sgi) || defined(linux) void _noecho(fd) - int fd; +int fd; { - struct termio io; + struct termio io; - echomode = 0; - (void) ioctl(fd, TCGETA, &io); - io.c_line |= ECHO; - (void) ioctl(fd, TCSETA, &io); + echomode = 0; + (void)ioctl(fd, TCGETA, &io); + io.c_line |= ECHO; + (void)ioctl(fd, TCSETA, &io); } void _echo(fd) - int fd; +int fd; { - struct termio io; + struct termio io; - if (echomode) - return; - (void) ioctl(fd, TCGETA, &io); - io.c_line &= ~ECHO; - (void) ioctl(fd, TCSETA, &io); - echomode++; + if (echomode) + return; + (void)ioctl(fd, TCGETA, &io); + io.c_line &= ~ECHO; + (void)ioctl(fd, TCSETA, &io); + echomode++; } #else @@ -268,42 +272,42 @@ _echo(fd) void _noecho(fd) - int fd; +int fd; { - struct sgttyb sgbuf; + struct sgttyb sgbuf; - echomode = 0; - (void) ioctl(fd, TIOCGETP, &sgbuf); - sgbuf.sg_flags &= ~ECHO; - (void) ioctl(fd, TIOCSETP, &sgbuf); + echomode = 0; + (void)ioctl(fd, TIOCGETP, &sgbuf); + sgbuf.sg_flags &= ~ECHO; + (void)ioctl(fd, TIOCSETP, &sgbuf); } void _echo(fd) - int fd; +int fd; { - struct sgttyb sgbuf; + struct sgttyb sgbuf; - if (echomode) - return; - (void) ioctl(fd, TIOCGETP, &sgbuf); - sgbuf.sg_flags |= ECHO; - (void) ioctl(0, TIOCSETP, &sgbuf); - echomode++; + if (echomode) + return; + (void)ioctl(fd, TIOCGETP, &sgbuf); + sgbuf.sg_flags |= ECHO; + (void)ioctl(0, TIOCSETP, &sgbuf); + echomode++; } #else void _noecho(fd) int fd; { - echomode = 0; + echomode = 0; } void _echo(fd) int fd; { - echomode++; + echomode++; } #endif /* _WIN32 */ diff --git a/src/client/termlib.c b/src/client/termlib.c index 822b4c8e0..71be68892 100644 --- a/src/client/termlib.c +++ b/src/client/termlib.c @@ -40,57 +40,57 @@ #include #endif -s_char *SO = 0; -s_char *SE = 0; +s_char *SO = 0; +s_char *SE = 0; int tgetent(); void parsedelay(r) - s_char *r; +s_char *r; { - s_char *s, *t; + s_char *s, *t; - s = r; - while (isdigit(*s) || (*s == '*') || (*s == '.')) { - s++; - } - for (t = r; *s != 0; (s++, t++)) { - *t = *s; - } - *t = 0; + s = r; + while (isdigit(*s) || (*s == '*') || (*s == '.')) { + s++; + } + for (t = r; *s != 0; (s++, t++)) { + *t = *s; + } + *t = 0; } void getsose() { #ifndef _WIN32 - extern s_char *getenv(); - extern s_char *tgetstr(); + extern s_char *getenv(); + extern s_char *tgetstr(); #endif - static s_char tbuf[1024]; - static s_char cbuf[20]; - s_char *cp; - s_char *term; + static s_char tbuf[1024]; + static s_char cbuf[20]; + s_char *cp; + s_char *term; #ifndef _WIN32 - memset((s_char *)&cbuf[0], 0, 20); - term = getenv("TERM"); - if (term == 0) { - fprintf(stderr, "warning: no TERM environment variable\n"); - return; - } - tgetent(tbuf, term); - cp = cbuf; - SO = tgetstr("so", &cp); - SE = tgetstr("se", &cp); - if (SO == 0) { - SO = tgetstr("us", &cp); - SE = tgetstr("ue", &cp); - } - if (SO != 0) { - parsedelay(SO); - parsedelay(SE); - } + memset((s_char *)&cbuf[0], 0, 20); + term = getenv("TERM"); + if (term == 0) { + fprintf(stderr, "warning: no TERM environment variable\n"); + return; + } + tgetent(tbuf, term); + cp = cbuf; + SO = tgetstr("so", &cp); + SE = tgetstr("se", &cp); + if (SO == 0) { + SO = tgetstr("us", &cp); + SE = tgetstr("ue", &cp); + } + if (SO != 0) { + parsedelay(SO); + parsedelay(SE); + } #endif } diff --git a/src/doconfig/doconfig.c b/src/doconfig/doconfig.c index 1e327f964..863fac754 100644 --- a/src/doconfig/doconfig.c +++ b/src/doconfig/doconfig.c @@ -46,45 +46,47 @@ void wripglob(char *filename); void wrauth(char *filename); void wrgamesdef(char *filename); -char *_c_copyright_header = "/*\n * Empire - A multi-player, client/server Internet based war game.\n * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,\n * Ken Stevens, Steve McClure\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n *\n * ---\n *\n * See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n * related information and legal notices. It is expected that any future\n * projects/authors will amend these files as needed.\n *\n * ---\n *\n * gamesdef.h: This is an auto-generated file.\n * \n * Known contributors to this file:\n * Automatically generated by doconfig.c\n */\n\n"; +char *_c_copyright_header = + "/*\n * Empire - A multi-player, client/server Internet based war game.\n * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,\n * Ken Stevens, Steve McClure\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n *\n * ---\n *\n * See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n * related information and legal notices. It is expected that any future\n * projects/authors will amend these files as needed.\n *\n * ---\n *\n * gamesdef.h: This is an auto-generated file.\n * \n * Known contributors to this file:\n * Automatically generated by doconfig.c\n */\n\n"; -char *_ipglob_copyright_header = "/*\n * Empire - A multi-player, client/server Internet based war game.\n * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,\n * Ken Stevens, Steve McClure\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n *\n * ---\n *\n * See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n * related information and legal notices. It is expected that any future\n * projects/authors will amend these files as needed.\n *\n * ---\n *\n * ipglob.c: This is an auto-generated file.\n * \n * Known contributors to this file:\n * Automatically generated by doconfig.c\n */\n\n"; +char *_ipglob_copyright_header = + "/*\n * Empire - A multi-player, client/server Internet based war game.\n * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,\n * Ken Stevens, Steve McClure\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 2 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software\n * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n *\n * ---\n *\n * See the \"LEGAL\", \"LICENSE\", \"CREDITS\" and \"README\" files for all the\n * related information and legal notices. It is expected that any future\n * projects/authors will amend these files as needed.\n *\n * ---\n *\n * ipglob.c: This is an auto-generated file.\n * \n * Known contributors to this file:\n * Automatically generated by doconfig.c\n */\n\n"; #if defined(_WIN32) char * rindex(char *path, char c) { - int i; - char *cp; + int i; + char *cp; - i = strlen(path); - cp = &path[i - 1]; + i = strlen(path); + cp = &path[i - 1]; - while (i) { - if (*cp == c) - return cp; - i--; - cp--; - } - return (char *)0; + while (i) { + if (*cp == c) + return cp; + i--; + cp--; + } + return (char *)0; } char * index(char *path, char c) { - int i; - char *cp; + int i; + char *cp; - cp = &path[0]; + cp = &path[0]; - i = 0; - while (path[i]) { - if (*cp == c) - return cp; - i++; - cp++; - } - return (char *)0; + i = 0; + while (path[i]) { + if (*cp == c) + return cp; + i++; + cp++; + } + return (char *)0; } #endif @@ -94,13 +96,12 @@ main() { char buf[256]; char *cp; - char *pathname; + char *pathname; if ((pathname = getcwd(NULL, 255)) == NULL) { - printf("Can't get current path!\n"); - exit(-1); + printf("Can't get current path!\n"); + exit(-1); } - #if !defined(_WIN32) cp = (char *)rindex(pathname, '/'); *cp = '\0'; @@ -120,19 +121,19 @@ main() wripglob(buf); if (access(EP, 0)) { - printf("making directory %s\n", EP); - if (mkdir(EP, 493)) { - printf("mkdir failed on %s, exiting.\n", EP); - exit(-1); - } + printf("making directory %s\n", EP); + if (mkdir(EP, 493)) { + printf("mkdir failed on %s, exiting.\n", EP); + exit(-1); + } } sprintf(buf, "%s/data", EP); if (access(buf, 0)) { - printf("making directory %s\n", buf); - if (mkdir(buf, 493)) { - printf("mkdir failed on %s, exiting.\n", buf); - exit(-1); - } + printf("making directory %s\n", buf); + if (mkdir(buf, 493)) { + printf("mkdir failed on %s, exiting.\n", buf); + exit(-1); + } } sprintf(buf, "%s/data/auth", EP); wrauth(buf); @@ -144,14 +145,15 @@ wrmakesrc(char *pathname) { FILE *fp; char buf[256]; - + sprintf(buf, "%s/src/make.src", pathname); if ((fp = fopen(buf, "w")) == NULL) { - printf("Cannot open %s for writing, exiting.\n", buf); - exit(-1); + printf("Cannot open %s for writing, exiting.\n", buf); + exit(-1); } fprintf(fp, "# make.src - Wolfpack, 1996-2000\n"); - fprintf(fp, "# Source tree absolute pathname - auto generated.\n\n"); + fprintf(fp, + "# Source tree absolute pathname - auto generated.\n\n"); fprintf(fp, "SRCDIR = %s\n", pathname); fclose(fp); } @@ -163,10 +165,10 @@ wripglob(char *filename) printf("Writing %s\n", filename); if ((fp = fopen(filename, "w")) == NULL) { - printf("Cannot open %s for writing, exiting.\n", filename); - exit(-1); + printf("Cannot open %s for writing, exiting.\n", filename); + exit(-1); } - fprintf(fp, _ipglob_copyright_header); + fprintf(fp, _ipglob_copyright_header); fprintf(fp, "#include \n"); fprintf(fp, "#include \n"); fprintf(fp, "#include \"misc.h\"\n"); @@ -184,12 +186,13 @@ wrauth(char *filename) printf("Writing %s\n", filename); if ((fp = fopen(filename, "w")) == NULL) { - printf("Cannot open %s for writing, exiting.\n", filename); - exit(-1); + printf("Cannot open %s for writing, exiting.\n", filename); + exit(-1); } - + fprintf(fp, "# Wolfpack, 1996-2000\n#\n"); - fprintf(fp, "# Empire Authorization File - Users listed will be allowed to log in as deities.\n#\n"); + fprintf(fp, + "# Empire Authorization File - Users listed will be allowed to log in as deities.\n#\n"); fprintf(fp, "# Format is:\n"); fprintf(fp, "# hostname that authorized user uses on a line\n"); fprintf(fp, "# username that authorized user uses on a line\n#\n"); @@ -206,62 +209,67 @@ void wrgamesdef(char *filename) { FILE *fp; - char path[512]; - char *cp; - unsigned int i; + char path[512]; + char *cp; + unsigned int i; int s_p_etu; char buf[40]; char c = 'b'; - cp = &path[0]; - for (i = 0; i < strlen(EP); i++) { - *cp++ = EP[i]; - if (EP[i] == '\\') - *cp++ = '\\'; - } - *cp = 0; + cp = &path[0]; + for (i = 0; i < strlen(EP); i++) { + *cp++ = EP[i]; + if (EP[i] == '\\') + *cp++ = '\\'; + } + *cp = 0; strcpy(buf, EF); if (strlen(buf) > 0) - c = buf[strlen(buf) - 1]; + c = buf[strlen(buf) - 1]; if (index("dhm", c) && strlen(buf) > 0) { - s_p_etu = atoi(buf); - if (c == 'd') - s_p_etu = (((double)s_p_etu * 60.0 * 60.0 * 24.0) / (double)ET); - else if (c == 'h') - s_p_etu = (((double)s_p_etu * 60.0 * 60.0) / (double)ET); - else if (c == 'm') - s_p_etu = (((double)s_p_etu * 60.0) / (double)ET); + s_p_etu = atoi(buf); + if (c == 'd') + s_p_etu = + (((double)s_p_etu * 60.0 * 60.0 * 24.0) / (double)ET); + else if (c == 'h') + s_p_etu = (((double)s_p_etu * 60.0 * 60.0) / (double)ET); + else if (c == 'm') + s_p_etu = (((double)s_p_etu * 60.0) / (double)ET); } else { - printf("ETU frequency is bad - using 10 minutes.\n"); - s_p_etu = 600 / ET; + printf("ETU frequency is bad - using 10 minutes.\n"); + s_p_etu = 600 / ET; } printf("Writing %s\n", filename); if ((fp = fopen(filename, "w")) == NULL) { - printf("Cannot open %s for writing, exiting.\n", filename); - exit(-1); + printf("Cannot open %s for writing, exiting.\n", filename); + exit(-1); } fprintf(fp, _c_copyright_header); fprintf(fp, "/*\n * Wolfpack, 1996-2000\n *\n"); - fprintf(fp, " * gamesdef.h - generated automatically by doconfig. Feel\n"); - fprintf(fp, " * free to change these, but if you rebuild with overwrite on\n"); + fprintf(fp, + " * gamesdef.h - generated automatically by doconfig. Feel\n"); + fprintf(fp, + " * free to change these, but if you rebuild with overwrite on\n"); fprintf(fp, " * this file will be overwritten again.\n"); fprintf(fp, " */\n\n"); fprintf(fp, "#ifndef _GAMESDEF_H_\n"); fprintf(fp, "#define _GAMESDEF_H_\n\n"); - fprintf(fp, "#if !defined(_WIN32)\n"); + fprintf(fp, "#if !defined(_WIN32)\n"); fprintf(fp, "#ifdef __STDC__\n"); fprintf(fp, "#define EMPPATH(xyz) \"%s/\" #xyz /* ANSI C */\n", EP); fprintf(fp, "#else\n"); fprintf(fp, "#define EMPPATH(xyz) \"%s/xyz\" /* traditional */\n", EP); fprintf(fp, "#endif /* __STDC__ */\n"); - fprintf(fp, "#else\n"); - fprintf(fp, "#define EMPPATH(xyz) \"%s\\\\\" #xyz /* ANSI C */\n", path); + fprintf(fp, "#else\n"); + fprintf(fp, "#define EMPPATH(xyz) \"%s\\\\\" #xyz /* ANSI C */\n", + path); fprintf(fp, "#endif /* _WIN32 */\n\n"); fprintf(fp, "#define PRVNAM \"%s\"\n", PV); fprintf(fp, "#define PRVLOG \"%s\"\n", EM); - fprintf(fp, "#define GET_SOURCE \"using:\\n ftp://ftp.wolfpackempire.com/pub/empire/server or \\n http://www.wolfpackempire.com/\"\n"); + fprintf(fp, + "#define GET_SOURCE \"using:\\n ftp://ftp.wolfpackempire.com/pub/empire/server or \\n http://www.wolfpackempire.com/\"\n"); fprintf(fp, "#define EMP_HOST \"%s\"\n", IP); fprintf(fp, "#define EMP_PORT \"%d\"\n\n", PN); fprintf(fp, "#define MAXNOC %d\n\n", MC); @@ -270,7 +278,7 @@ wrgamesdef(char *filename) fprintf(fp, "#define DEF_S_P_ETU %d\n", s_p_etu); fprintf(fp, "#define ETUS %d\n\n", ET); if (BL) - fprintf(fp, "#define BLITZ 1\n\n"); + fprintf(fp, "#define BLITZ 1\n\n"); fprintf(fp, "#endif /* _GAMESDEF_H_ */\n"); fclose(fp); } diff --git a/src/lib/as/as.h b/src/lib/as/as.h index 88362195c..cb95e316f 100644 --- a/src/lib/as/as.h +++ b/src/lib/as/as.h @@ -27,46 +27,46 @@ * Added path list caching structures */ -#include /* for FILE */ -#include "misc.h" /* for s_char */ +#include /* for FILE */ +#include "misc.h" /* for s_char */ /* * Coordinate. */ struct as_coord { - int x, y; + int x, y; }; /* * Path, made up of a linked list of coordinates. */ struct as_path { - struct as_coord c; - struct as_path *next; + struct as_coord c; + struct as_path *next; }; /* * Basic node, used internally by A* algorithm. */ struct as_node { - struct as_coord c; /* our coordinate */ - double knowncost; /* cost so far */ - double lbcost; /* lower bound on cost to dest */ - double inclbcost; /* incremental lower bound cost */ - double seccost; /* used to break ties */ - int step; - int flags; - struct as_node *back; + struct as_coord c; /* our coordinate */ + double knowncost; /* cost so far */ + double lbcost; /* lower bound on cost to dest */ + double inclbcost; /* incremental lower bound cost */ + double seccost; /* used to break ties */ + int step; + int flags; + struct as_node *back; }; -#define AS_TRIED 1 /* we've tried this node before */ +#define AS_TRIED 1 /* we've tried this node before */ /* * Linked list of nodes, used internally by A* algorithm. */ struct as_queue { - struct as_node *np; - struct as_queue *next; - struct as_queue *prev; + struct as_node *np; + struct as_queue *next; + struct as_queue *prev; }; /* @@ -74,9 +74,9 @@ struct as_queue { * coordinate before. */ struct as_hash { - struct as_coord c; - struct as_queue *qp; - struct as_hash *next; + struct as_coord c; + struct as_queue *qp; + struct as_hash *next; }; /* @@ -84,26 +84,26 @@ struct as_hash { * used by A* internals. */ struct as_data { - int maxneighbors; /* max # of neighbors a cell can have */ - int hashsize; /* size of internal hash table */ - - int (*hash)(struct as_coord); /* hash function (coord -> int) */ - int (*neighbor)(struct as_coord, struct as_coord *, s_char *); /* function to find neighbors */ - double (*lbcost)(struct as_coord, struct as_coord, s_char *); /* function to give lower bound cost */ - double (*realcost)(struct as_coord, struct as_coord, s_char *); /* function to give real cost */ - double (*seccost)(struct as_coord, struct as_coord, s_char *); /* function to secondary cost */ - char *userdata; /* user's data, passed to callbacks */ - struct as_coord from; /* from coordinate */ - struct as_coord to; /* to coordinate */ - struct as_path *path; /* solution */ - - /* below are "private" to as_ routines */ - struct as_queue *head; - struct as_queue *tried; - struct as_hash **hashtab; - struct as_queue *subsumed; - struct as_coord *neighbor_coords; - struct as_node **neighbor_nodes; + int maxneighbors; /* max # of neighbors a cell can have */ + int hashsize; /* size of internal hash table */ + + int (*hash) (struct as_coord); /* hash function (coord -> int) */ + int (*neighbor) (struct as_coord, struct as_coord *, s_char *); /* function to find neighbors */ + double (*lbcost) (struct as_coord, struct as_coord, s_char *); /* function to give lower bound cost */ + double (*realcost) (struct as_coord, struct as_coord, s_char *); /* function to give real cost */ + double (*seccost) (struct as_coord, struct as_coord, s_char *); /* function to secondary cost */ + char *userdata; /* user's data, passed to callbacks */ + struct as_coord from; /* from coordinate */ + struct as_coord to; /* to coordinate */ + struct as_path *path; /* solution */ + + /* below are "private" to as_ routines */ + struct as_queue *head; + struct as_queue *tried; + struct as_hash **hashtab; + struct as_queue *subsumed; + struct as_coord *neighbor_coords; + struct as_node **neighbor_nodes; }; /* @@ -112,14 +112,14 @@ struct as_data { struct as_topath { coord x; - struct as_path *path; /* Path from holder of this list to here */ + struct as_path *path; /* Path from holder of this list to here */ struct as_topath *next; }; struct as_frompath { coord x; - struct as_topath **tolist; /* List of nodes we have a path to */ - struct as_frompath *next; + struct as_topath **tolist; /* List of nodes we have a path to */ + struct as_frompath *next; }; /* @@ -140,22 +140,27 @@ struct as_frompath { /* Functions that the user can call. */ -extern struct as_data * -as_init(int maxneighbors, int hashsize, - int (*hashfunc) (struct as_coord), - int (*neighborfunc) (struct as_coord, struct as_coord *, s_char *), - double (*lbcostfunc) (struct as_coord, struct as_coord, s_char *), - double (*realcostfunc) (struct as_coord, struct as_coord, s_char *), - double (*seccostfunc) (struct as_coord, struct as_coord, s_char *), - s_char *userdata); -extern int as_search(struct as_data *adp); -extern void as_delete(struct as_data *adp); -extern void as_reset(struct as_data *adp); -extern void as_stats(struct as_data *adp, FILE *fp); +extern struct as_data *as_init(int maxneighbors, int hashsize, + int (*hashfunc) (struct as_coord), + int (*neighborfunc) (struct as_coord, + struct as_coord *, + s_char *), + double (*lbcostfunc) (struct as_coord, + struct as_coord, + s_char *), + double (*realcostfunc) (struct as_coord, + struct as_coord, + s_char *), + double (*seccostfunc) (struct as_coord, + struct as_coord, + s_char *), + s_char *userdata); +extern int as_search(struct as_data *adp); +extern void as_delete(struct as_data *adp); +extern void as_reset(struct as_data *adp); +extern void as_stats(struct as_data *adp, FILE * fp); extern struct as_path *as_find_cachepath(coord fx, - coord fy, - coord tx, - coord ty); + coord fy, coord tx, coord ty); /* Functions that are "private" to algorithm */ @@ -164,17 +169,17 @@ extern void as_clear_cachepath(); extern void as_enable_cachepath(); extern void as_disable_cachepath(); -extern void as_makepath(struct as_data *adp); -extern void as_free_path(struct as_path *pp); - -extern int as_costcomp(struct as_node **n1, struct as_node **n2); -extern struct as_queue *as_extend(struct as_data *adp); -extern struct as_queue *as_merge(struct as_data *adp, - struct as_queue *head, - struct as_node **neighbors); -extern struct as_queue *as_iscinq(struct as_data *adp, struct as_coord c); -extern void as_setcinq(struct as_data *adp, - struct as_coord c, struct as_queue *qp); -extern void as_free_hashtab(struct as_data *adp); -extern int as_winnow(struct as_data *adp, - struct as_coord *coords, int ncoords); +extern void as_makepath(struct as_data *adp); +extern void as_free_path(struct as_path *pp); + +extern int as_costcomp(struct as_node **n1, struct as_node **n2); +extern struct as_queue *as_extend(struct as_data *adp); +extern struct as_queue *as_merge(struct as_data *adp, + struct as_queue *head, + struct as_node **neighbors); +extern struct as_queue *as_iscinq(struct as_data *adp, struct as_coord c); +extern void as_setcinq(struct as_data *adp, + struct as_coord c, struct as_queue *qp); +extern void as_free_hashtab(struct as_data *adp); +extern int as_winnow(struct as_data *adp, + struct as_coord *coords, int ncoords); diff --git a/src/lib/as/as_cache.c b/src/lib/as/as_cache.c index 737300f98..dbfa266b5 100644 --- a/src/lib/as/as_cache.c +++ b/src/lib/as/as_cache.c @@ -52,7 +52,7 @@ static struct as_frompath **fromhead = (struct as_frompath **)0; /* Note that we only want to cache during updates. Other times, it * probably doesn't make much sense, but can be done. */ -static int as_cachepath_on = 0; /* Default to off */ +static int as_cachepath_on = 0; /* Default to off */ void as_enable_cachepath() @@ -107,9 +107,9 @@ as_add_cachepath(struct as_data *adp) /* And set some stuff */ from->x = adp->from.x; /* Here we malloc a whole bunch of tolist pointers. */ - from->tolist = (struct as_topath **)calloc(1, - sizeof(struct as_topath *) * - WORLD_Y); + from->tolist = (struct as_topath **)calloc(1, + sizeof(struct as_topath + *) * WORLD_Y); /* Now, add from to the global list */ from->next = fromhead[adp->from.y]; fromhead[adp->from.y] = from; diff --git a/src/lib/as/as_costcomp.c b/src/lib/as/as_costcomp.c index 7e50db9df..c0b86d95e 100644 --- a/src/lib/as/as_costcomp.c +++ b/src/lib/as/as_costcomp.c @@ -20,8 +20,8 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_costcomp.c 1.4 11/13/90"; -#endif /* not lint*/ +static char sccsid[] = "@(#)as_costcomp.c 1.4 11/13/90"; +#endif /* not lint */ /* * Compare the lower bound costs of two nodes. If the two nodes have @@ -31,19 +31,19 @@ static char sccsid[] = "@(#)as_costcomp.c 1.4 11/13/90"; int as_costcomp(struct as_node **n1, struct as_node **n2) { - double diff; + double diff; - diff = (*n1)->lbcost - (*n2)->lbcost; - if (diff < -0.0001) - return (-1); - if (diff > 0.0001) - return (1); + diff = (*n1)->lbcost - (*n2)->lbcost; + if (diff < -0.0001) + return (-1); + if (diff > 0.0001) + return (1); - /* equal, check secondary cost */ - diff = (*n1)->seccost - (*n2)->seccost; - if (diff < -0.0001) - return (-1); - if (diff > 0.0001) - return (1); - return (0); + /* equal, check secondary cost */ + diff = (*n1)->seccost - (*n2)->seccost; + if (diff < -0.0001) + return (-1); + if (diff > 0.0001) + return (1); + return (0); } diff --git a/src/lib/as/as_delete.c b/src/lib/as/as_delete.c index 24b7a193c..30efb6453 100644 --- a/src/lib/as/as_delete.c +++ b/src/lib/as/as_delete.c @@ -22,10 +22,10 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_delete.c 1.5 11/13/90"; +static char sccsid[] = "@(#)as_delete.c 1.5 11/13/90"; #endif /* not lint */ -static void as_free_queue(struct as_queue *queue); +static void as_free_queue(struct as_queue *queue); /* * Free any dynamically allocated data stored in the as_data structure. @@ -34,15 +34,15 @@ void as_reset(struct as_data *adp) { - as_free_queue(adp->head); - adp->head = NULL; - as_free_queue(adp->tried); - adp->tried = NULL; - as_free_queue(adp->subsumed); - adp->subsumed = NULL; - as_free_hashtab(adp); - as_free_path(adp->path); - adp->path = NULL; + as_free_queue(adp->head); + adp->head = NULL; + as_free_queue(adp->tried); + adp->tried = NULL; + as_free_queue(adp->subsumed); + adp->subsumed = NULL; + as_free_hashtab(adp); + as_free_path(adp->path); + adp->path = NULL; } /* @@ -51,13 +51,13 @@ as_reset(struct as_data *adp) static void as_free_queue(struct as_queue *queue) { - struct as_queue *qp, *qp2; + struct as_queue *qp, *qp2; - for (qp = queue; qp; qp = qp2) { - free((s_char *)qp->np); - qp2 = qp->next; - free((s_char *)qp); - } + for (qp = queue; qp; qp = qp2) { + free((s_char *)qp->np); + qp2 = qp->next; + free((s_char *)qp); + } } /* @@ -66,12 +66,12 @@ as_free_queue(struct as_queue *queue) void as_free_path(struct as_path *pp) { - struct as_path *pp2; + struct as_path *pp2; - for (; pp; pp = pp2) { - pp2 = pp->next; - free((s_char *)pp); - } + for (; pp; pp = pp2) { + pp2 = pp->next; + free((s_char *)pp); + } } /* @@ -80,9 +80,9 @@ as_free_path(struct as_path *pp) void as_delete(struct as_data *adp) { - as_reset(adp); - free((s_char *)adp->neighbor_coords); - free((s_char *)adp->neighbor_nodes); - free((s_char *)adp->hashtab); - free((s_char *)adp); + as_reset(adp); + free((s_char *)adp->neighbor_coords); + free((s_char *)adp->neighbor_nodes); + free((s_char *)adp->hashtab); + free((s_char *)adp); } diff --git a/src/lib/as/as_extend.c b/src/lib/as/as_extend.c index 8e097ef68..a51b89c25 100644 --- a/src/lib/as/as_extend.c +++ b/src/lib/as/as_extend.c @@ -22,7 +22,7 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_extend.c 1.2 11/13/90"; +static char sccsid[] = "@(#)as_extend.c 1.2 11/13/90"; #endif /* not lint */ /* @@ -34,41 +34,41 @@ static char sccsid[] = "@(#)as_extend.c 1.2 11/13/90"; struct as_queue * as_extend(struct as_data *adp) { - struct as_queue *qp; - int i; - struct as_queue *head; + struct as_queue *qp; + int i; + struct as_queue *head; - head = adp->head; + head = adp->head; - /* Find the neighboring coordinates. */ - i = (*adp->neighbor)(head->np->c, adp->neighbor_coords, adp->userdata); - if (i == 0) - return (NULL); - /* - * Get rid of neighbors that are more costly than ones we already have, - * and sort the rest into an array of as_nodes. - */ - i = as_winnow(adp, adp->neighbor_coords, i); - if (i < 0) - return (NULL); - if (i > 1) - qsort(adp->neighbor_nodes, i, - sizeof (*adp->neighbor_nodes), - (qsort_func_t) as_costcomp); + /* Find the neighboring coordinates. */ + i = (*adp->neighbor) (head->np->c, adp->neighbor_coords, + adp->userdata); + if (i == 0) + return (NULL); + /* + * Get rid of neighbors that are more costly than ones we already have, + * and sort the rest into an array of as_nodes. + */ + i = as_winnow(adp, adp->neighbor_coords, i); + if (i < 0) + return (NULL); + if (i > 1) + qsort(adp->neighbor_nodes, i, + sizeof(*adp->neighbor_nodes), (qsort_func_t)as_costcomp); - /* remove old coord from head of queue and add to list of tried */ - qp = head; - head = head->next; - if (head) - head->prev = NULL; - if (adp->tried) { - adp->tried->prev = qp; - qp->next = adp->tried; - adp->tried = qp; - } else - adp->tried = qp; - adp->tried->np->flags |= AS_TRIED; + /* remove old coord from head of queue and add to list of tried */ + qp = head; + head = head->next; + if (head) + head->prev = NULL; + if (adp->tried) { + adp->tried->prev = qp; + qp->next = adp->tried; + adp->tried = qp; + } else + adp->tried = qp; + adp->tried->np->flags |= AS_TRIED; - head = as_merge(adp, head, adp->neighbor_nodes); - return (head); + head = as_merge(adp, head, adp->neighbor_nodes); + return (head); } diff --git a/src/lib/as/as_hash.c b/src/lib/as/as_hash.c index 8e4b97135..030dd9147 100644 --- a/src/lib/as/as_hash.c +++ b/src/lib/as/as_hash.c @@ -22,7 +22,7 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_hash.c 1.2 11/13/90"; +static char sccsid[] = "@(#)as_hash.c 1.2 11/13/90"; #endif /* not lint */ /* @@ -32,16 +32,16 @@ static char sccsid[] = "@(#)as_hash.c 1.2 11/13/90"; struct as_queue * as_iscinq(struct as_data *adp, struct as_coord c) { - int hashval; - struct as_hash *hp; + int hashval; + struct as_hash *hp; - hashval = (*adp->hash)(c) % adp->hashsize; + hashval = (*adp->hash) (c) % adp->hashsize; - for (hp = adp->hashtab[hashval]; hp; hp = hp->next) - if (hp->c.x == c.x && hp->c.y == c.y) - return (hp->qp); + for (hp = adp->hashtab[hashval]; hp; hp = hp->next) + if (hp->c.x == c.x && hp->c.y == c.y) + return (hp->qp); - return (NULL); + return (NULL); } /* @@ -50,19 +50,19 @@ as_iscinq(struct as_data *adp, struct as_coord c) void as_setcinq(struct as_data *adp, struct as_coord c, struct as_queue *qp) { - int hashval; - struct as_hash *hp; - struct as_hash *new; + int hashval; + struct as_hash *hp; + struct as_hash *new; - new = (struct as_hash *)malloc(sizeof(struct as_hash)); - new->c = c; - new->qp = qp; + new = (struct as_hash *)malloc(sizeof(struct as_hash)); + new->c = c; + new->qp = qp; - hashval = (*adp->hash)(c) % adp->hashsize; - hp = adp->hashtab[hashval]; + hashval = (*adp->hash) (c) % adp->hashsize; + hp = adp->hashtab[hashval]; - new->next = (hp) ? hp : NULL; - adp->hashtab[hashval] = new; + new->next = (hp) ? hp : NULL; + adp->hashtab[hashval] = new; } /* @@ -72,14 +72,14 @@ as_setcinq(struct as_data *adp, struct as_coord c, struct as_queue *qp) void as_free_hashtab(struct as_data *adp) { - int i; - struct as_hash *hp, *hp2; + int i; + struct as_hash *hp, *hp2; - for (i = 0; i < adp->hashsize; i++) { - for (hp = adp->hashtab[i]; hp; hp = hp2) { - hp2 = hp->next; - free((char *)hp); - } - adp->hashtab[i] = NULL; + for (i = 0; i < adp->hashsize; i++) { + for (hp = adp->hashtab[i]; hp; hp = hp2) { + hp2 = hp->next; + free((char *)hp); } + adp->hashtab[i] = NULL; + } } diff --git a/src/lib/as/as_init.c b/src/lib/as/as_init.c index 926b3b15c..32ff719b6 100644 --- a/src/lib/as/as_init.c +++ b/src/lib/as/as_init.c @@ -22,7 +22,7 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_init.c 1.4 11/13/90"; +static char sccsid[] = "@(#)as_init.c 1.4 11/13/90"; #endif /* not lint */ /* @@ -32,31 +32,31 @@ static char sccsid[] = "@(#)as_init.c 1.4 11/13/90"; struct as_data * as_init(int maxneighbors, int hashsize, - int (*hashfunc) (struct as_coord), - int (*neighborfunc) (struct as_coord, struct as_coord *, s_char *), - double (*lbcostfunc) (struct as_coord, struct as_coord, s_char *), - double (*realcostfunc) (struct as_coord, struct as_coord, s_char *), - double (*seccostfunc) (struct as_coord, struct as_coord, s_char *), + int (*hashfunc) (struct as_coord), + int (*neighborfunc) (struct as_coord, struct as_coord *, s_char *), + double (*lbcostfunc) (struct as_coord, struct as_coord, s_char *), + double (*realcostfunc) (struct as_coord, struct as_coord, + s_char *), + double (*seccostfunc) (struct as_coord, struct as_coord, s_char *), s_char *userdata) { - struct as_data *adp; + struct as_data *adp; - AS_NEW(adp, struct as_data, NULL); - AS_NEW_ARRAY(adp->neighbor_coords, struct as_coord, - maxneighbors, NULL); - AS_NEW_ARRAY(adp->neighbor_nodes, struct as_node *, - maxneighbors + 1, NULL); - AS_NEW_ARRAY(adp->hashtab, struct as_hash *, - hashsize, NULL); + AS_NEW(adp, struct as_data, NULL); + AS_NEW_ARRAY(adp->neighbor_coords, struct as_coord, + maxneighbors, NULL); + AS_NEW_ARRAY(adp->neighbor_nodes, struct as_node *, + maxneighbors + 1, NULL); + AS_NEW_ARRAY(adp->hashtab, struct as_hash *, hashsize, NULL); - adp->maxneighbors = maxneighbors; - adp->hashsize = hashsize; - adp->hash = hashfunc; - adp->neighbor = neighborfunc; - adp->lbcost = lbcostfunc; - adp->realcost = realcostfunc; - adp->seccost = seccostfunc; - adp->userdata = userdata; + adp->maxneighbors = maxneighbors; + adp->hashsize = hashsize; + adp->hash = hashfunc; + adp->neighbor = neighborfunc; + adp->lbcost = lbcostfunc; + adp->realcost = realcostfunc; + adp->seccost = seccostfunc; + adp->userdata = userdata; - return (adp); + return (adp); } diff --git a/src/lib/as/as_merge.c b/src/lib/as/as_merge.c index 531b474cd..835495426 100644 --- a/src/lib/as/as_merge.c +++ b/src/lib/as/as_merge.c @@ -22,7 +22,7 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_merge.c 1.2 11/13/90"; +static char sccsid[] = "@(#)as_merge.c 1.2 11/13/90"; #endif /* not lint */ /* @@ -30,55 +30,56 @@ static char sccsid[] = "@(#)as_merge.c 1.2 11/13/90"; * both by lower bound cost and then by secondary cost. */ struct as_queue * -as_merge(struct as_data *adp, struct as_queue *head, struct as_node **neighbors) +as_merge(struct as_data *adp, struct as_queue *head, + struct as_node **neighbors) { - struct as_queue *qp; - struct as_queue *pp; /* previous pointer */ - struct as_queue *ip; /* insert pointer */ - struct as_node *np; - int i; + struct as_queue *qp; + struct as_queue *pp; /* previous pointer */ + struct as_queue *ip; /* insert pointer */ + struct as_node *np; + int i; - qp = head; - pp = NULL; - for (i = 0; neighbors[i]; i++) { - np = neighbors[i]; - /* scan until qp points to a node we should go in front of */ - while (qp && (qp->np->lbcost < np->lbcost)) { - pp = qp; - qp = qp->next; - } - /* check for equal lower bounds, and use secondary cost if = */ - if (qp && qp->np->lbcost == np->lbcost) { - while (qp && (qp->np->lbcost == np->lbcost) && - (qp->np->seccost < np->seccost)) { - pp = qp; - qp = qp->next; - } - } - AS_NEW_MALLOC(ip, struct as_queue, NULL); - /* if there was such a node, insert us in front of it */ - if (qp) { - ip->prev = qp->prev; - if (ip->prev) - ip->prev->next = ip; - ip->next = qp; - qp->prev = ip; - if (qp == head) - head = ip; - } else { /* otherwise add us to end of queue */ - ip->next = NULL; - ip->prev = pp; - if (ip->prev) - ip->prev->next = ip; - else { - head = ip; - } - pp = ip; - } - ip->np = np; - as_setcinq(adp, np->c, ip); - np->step++; + qp = head; + pp = NULL; + for (i = 0; neighbors[i]; i++) { + np = neighbors[i]; + /* scan until qp points to a node we should go in front of */ + while (qp && (qp->np->lbcost < np->lbcost)) { + pp = qp; + qp = qp->next; } + /* check for equal lower bounds, and use secondary cost if = */ + if (qp && qp->np->lbcost == np->lbcost) { + while (qp && (qp->np->lbcost == np->lbcost) && + (qp->np->seccost < np->seccost)) { + pp = qp; + qp = qp->next; + } + } + AS_NEW_MALLOC(ip, struct as_queue, NULL); + /* if there was such a node, insert us in front of it */ + if (qp) { + ip->prev = qp->prev; + if (ip->prev) + ip->prev->next = ip; + ip->next = qp; + qp->prev = ip; + if (qp == head) + head = ip; + } else { /* otherwise add us to end of queue */ + ip->next = NULL; + ip->prev = pp; + if (ip->prev) + ip->prev->next = ip; + else { + head = ip; + } + pp = ip; + } + ip->np = np; + as_setcinq(adp, np->c, ip); + np->step++; + } - return (head); + return (head); } diff --git a/src/lib/as/as_search.c b/src/lib/as/as_search.c index c81ed78a7..7f957b308 100644 --- a/src/lib/as/as_search.c +++ b/src/lib/as/as_search.c @@ -26,7 +26,7 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_search.c 1.2 11/13/90"; +static char sccsid[] = "@(#)as_search.c 1.2 11/13/90"; #endif /* not lint */ /* @@ -39,95 +39,94 @@ static char sccsid[] = "@(#)as_search.c 1.2 11/13/90"; int as_search(struct as_data *adp) { - int iter = 0; - struct as_queue *head; - struct as_node *np; + int iter = 0; + struct as_queue *head; + struct as_node *np; #ifdef DEBUG - int i; - struct as_queue *qp; - struct as_path *pp; + int i; + struct as_queue *qp; + struct as_path *pp; #endif /* DEBUG */ - struct as_queue *as_extend(struct as_data *adp); - - as_reset(adp); - - /* - * Jump start the queue by making first element the zero-cost - * node where we start. - */ - AS_NEW_MALLOC(head, struct as_queue, -2); - adp->head = head; - head->next = head->prev = NULL; - AS_NEW(np, struct as_node, -2); - np->c = adp->from; - head->np = np; - as_setcinq(adp, head->np->c, adp->head); - - for (;;) { - iter++; + struct as_queue *as_extend(struct as_data *adp); + + as_reset(adp); + + /* + * Jump start the queue by making first element the zero-cost + * node where we start. + */ + AS_NEW_MALLOC(head, struct as_queue, -2); + adp->head = head; + head->next = head->prev = NULL; + AS_NEW(np, struct as_node, -2); + np->c = adp->from; + head->np = np; + as_setcinq(adp, head->np->c, adp->head); + + for (;;) { + iter++; #ifdef DEBUG - fprintf(stderr, "Iteration %d, head at %d, %d\n", iter, - head->np->c.x, head->np->c.y); + fprintf(stderr, "Iteration %d, head at %d, %d\n", iter, + head->np->c.x, head->np->c.y); #endif /* DEBUG */ - /* see if we're done, one way or another */ - if (head == NULL) - break; + /* see if we're done, one way or another */ + if (head == NULL) + break; - /* Add it to the cache */ - as_add_cachepath(adp); + /* Add it to the cache */ + as_add_cachepath(adp); - if (head->np->c.x == adp->to.x && head->np->c.y == adp->to.y) - break; + if (head->np->c.x == adp->to.x && head->np->c.y == adp->to.y) + break; - /* extend queue by neighbors */ + /* extend queue by neighbors */ #ifdef DEBUG - fprintf(stderr, "\tExtending queue\n"); + fprintf(stderr, "\tExtending queue\n"); #endif /* DEBUG */ - adp->head = head = as_extend(adp); + adp->head = head = as_extend(adp); #ifdef DEBUG - fprintf(stderr, "queue:\n"); - i = 0; - for (qp = head; qp; qp = qp->next) { - fprintf(stderr, "\t%d, %d so far %f lb %f sec %f\n", - qp->np->c.x, qp->np->c.y, - qp->np->knowncost, - qp->np->lbcost, - qp->np->seccost); - i++; - } - fprintf(stderr, "\tqueue len %d\n", i); + fprintf(stderr, "queue:\n"); + i = 0; + for (qp = head; qp; qp = qp->next) { + fprintf(stderr, "\t%d, %d so far %f lb %f sec %f\n", + qp->np->c.x, qp->np->c.y, + qp->np->knowncost, qp->np->lbcost, qp->np->seccost); + i++; + } + fprintf(stderr, "\tqueue len %d\n", i); #endif /* DEBUG */ - } + } - if (head == NULL) { + if (head == NULL) { #ifdef DEBUG - fprintf(stderr, "Failed\n"); + fprintf(stderr, "Failed\n"); #endif /* DEBUG */ - return (-1); - } + return (-1); + } - as_makepath(adp); + as_makepath(adp); #ifdef DEBUG - fprintf(stderr, "Succeeded, iter %d, cost %f!\n", iter, head->np->knowncost); - fprintf(stderr, "Path:\n"); - for (pp = adp->path; pp; pp = pp->next) { - fprintf(stderr, "\t%d, %d\n", pp->c.x, pp->c.y); - } - fprintf(stderr, "Tried queue:\n"); - for (qp = adp->tried; qp; qp = qp->next) { - fprintf(stderr, "\t%d, %d\n", qp->np->c.x, qp->np->c.y); - } - fprintf(stderr, "Subsumed queue:\n"); - for (qp = adp->subsumed; qp; qp = qp->next) { - fprintf(stderr, "\t%d, %d\n", qp->np->c.x, qp->np->c.y); - } + fprintf(stderr, "Succeeded, iter %d, cost %f!\n", iter, + head->np->knowncost); + fprintf(stderr, "Path:\n"); + for (pp = adp->path; pp; pp = pp->next) { + fprintf(stderr, "\t%d, %d\n", pp->c.x, pp->c.y); + } + fprintf(stderr, "Tried queue:\n"); + for (qp = adp->tried; qp; qp = qp->next) { + fprintf(stderr, "\t%d, %d\n", qp->np->c.x, qp->np->c.y); + } + fprintf(stderr, "Subsumed queue:\n"); + for (qp = adp->subsumed; qp; qp = qp->next) { + fprintf(stderr, "\t%d, %d\n", qp->np->c.x, qp->np->c.y); + } #endif /* DEBUG */ - - return (0); + + return (0); } /* @@ -137,13 +136,13 @@ as_search(struct as_data *adp) void as_makepath(struct as_data *adp) { - struct as_path *pp; - struct as_node *np; - - for (np = adp->head->np; np; np = np->back) { - pp = (struct as_path *)malloc(sizeof(struct as_path)); - pp->c = np->c; - pp->next = adp->path; - adp->path = pp; - } + struct as_path *pp; + struct as_node *np; + + for (np = adp->head->np; np; np = np->back) { + pp = (struct as_path *)malloc(sizeof(struct as_path)); + pp->c = np->c; + pp->next = adp->path; + adp->path = pp; + } } diff --git a/src/lib/as/as_stats.c b/src/lib/as/as_stats.c index 6c93fd128..af47a26fa 100644 --- a/src/lib/as/as_stats.c +++ b/src/lib/as/as_stats.c @@ -21,53 +21,55 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_stats.c 1.2 11/13/90"; +static char sccsid[] = "@(#)as_stats.c 1.2 11/13/90"; #endif /* not lint */ /* * Print statistics on algorithm performance to the file pointer "fp". */ void -as_stats(struct as_data *adp, FILE *fp) +as_stats(struct as_data *adp, FILE * fp) { - int i; - int j; - int total_q; - int total_h; - struct as_queue *qp; - struct as_hash *hp; + int i; + int j; + int total_q; + int total_h; + struct as_queue *qp; + struct as_hash *hp; - fprintf(fp, "Statistics:\n"); + fprintf(fp, "Statistics:\n"); - fprintf(fp, "queue lengths:\n"); - total_q = 0; - total_h = 0; - for (i = 0, qp = adp->head; qp; qp = qp->next) - i++; - fprintf(fp, "\tmain:\t%d\n", i); - total_q += i; - for (i = 0, qp = adp->tried; qp; qp = qp->next) - i++; - fprintf(fp, "\ttried:\t%d\n", i); - total_q += i; - for (i = 0, qp = adp->subsumed; qp; qp = qp->next) - i++; - fprintf(fp, "\tsubsumed:\t%d\n", i); - total_q += i; - fprintf(fp, "hash table statistics (size %d):\n", adp->hashsize); - for (i = 0; i < adp->hashsize; i++) { - for (j = 0, hp = adp->hashtab[i]; hp; hp = hp->next) - j++; - fprintf(fp, "\t%d\t%d\n", i, j); - total_h += j; - } - fprintf(fp, "\ttotal\t%d\n", total_h); - fprintf(fp, "approximate memory usage (bytes):\n"); - fprintf(fp, "\tqueues\t%d\n", (int)(total_q * sizeof (struct as_queue))); - fprintf(fp, "\tnodes\t%d\n", (int)(total_q * sizeof (struct as_node))); - fprintf(fp, "\thash ents\t%d\n", (int)(total_h * sizeof (struct as_hash))); - fprintf(fp, "\ttotal\t%d\n", - (int)(total_q * sizeof (struct as_queue) + - total_q * sizeof (struct as_node) + - total_h * sizeof (struct as_hash))); + fprintf(fp, "queue lengths:\n"); + total_q = 0; + total_h = 0; + for (i = 0, qp = adp->head; qp; qp = qp->next) + i++; + fprintf(fp, "\tmain:\t%d\n", i); + total_q += i; + for (i = 0, qp = adp->tried; qp; qp = qp->next) + i++; + fprintf(fp, "\ttried:\t%d\n", i); + total_q += i; + for (i = 0, qp = adp->subsumed; qp; qp = qp->next) + i++; + fprintf(fp, "\tsubsumed:\t%d\n", i); + total_q += i; + fprintf(fp, "hash table statistics (size %d):\n", adp->hashsize); + for (i = 0; i < adp->hashsize; i++) { + for (j = 0, hp = adp->hashtab[i]; hp; hp = hp->next) + j++; + fprintf(fp, "\t%d\t%d\n", i, j); + total_h += j; + } + fprintf(fp, "\ttotal\t%d\n", total_h); + fprintf(fp, "approximate memory usage (bytes):\n"); + fprintf(fp, "\tqueues\t%d\n", + (int)(total_q * sizeof(struct as_queue))); + fprintf(fp, "\tnodes\t%d\n", (int)(total_q * sizeof(struct as_node))); + fprintf(fp, "\thash ents\t%d\n", + (int)(total_h * sizeof(struct as_hash))); + fprintf(fp, "\ttotal\t%d\n", + (int)(total_q * sizeof(struct as_queue) + + total_q * sizeof(struct as_node) + + total_h * sizeof(struct as_hash))); } diff --git a/src/lib/as/as_winnow.c b/src/lib/as/as_winnow.c index 03b01c64a..aa8c395a4 100644 --- a/src/lib/as/as_winnow.c +++ b/src/lib/as/as_winnow.c @@ -22,12 +22,12 @@ #include "as.h" #if !defined(lint) && !defined(SABER) -static char sccsid[] = "@(#)as_winnow.c 1.8 11/13/90"; +static char sccsid[] = "@(#)as_winnow.c 1.8 11/13/90"; #endif /* not lint */ -static struct as_node * -as_newnode(struct as_node *backp, struct as_coord c, - double inclbcost, double lbcost, double knowncost, double seccost); +static struct as_node *as_newnode(struct as_node *backp, struct as_coord c, + double inclbcost, double lbcost, + double knowncost, double seccost); /* * Take a list of neighbor coordinates and winnow them down into @@ -46,132 +46,133 @@ as_newnode(struct as_node *backp, struct as_coord c, int as_winnow(struct as_data *adp, struct as_coord *coords, int ncoords) { - int i = 0; - int fix_pointer; - double knowncost; - double incknowncost; - double lbcost; - double inclbcost; - double seccost; - struct as_coord *cp; - struct as_coord *end; - struct as_queue *qp; - struct as_node *np; + int i = 0; + int fix_pointer; + double knowncost; + double incknowncost; + double lbcost; + double inclbcost; + double seccost; + struct as_coord *cp; + struct as_coord *end; + struct as_queue *qp; + struct as_node *np; - for (cp = coords, end = coords + ncoords; cp < end; cp++) { - fix_pointer = 0; - incknowncost = (*adp->realcost)(adp->head->np->c, *cp, - adp->userdata); - knowncost = adp->head->np->knowncost + incknowncost; - /* - * If this neighbor is already in the queue, we can - * save some time. - */ - qp = as_iscinq(adp, *cp); - inclbcost = qp ? qp->np->inclbcost : - (*adp->lbcost)(*cp, adp->to, adp->userdata); - if (inclbcost < 0.0) /* skip bad cases */ - continue; - lbcost = knowncost + inclbcost; + for (cp = coords, end = coords + ncoords; cp < end; cp++) { + fix_pointer = 0; + incknowncost = (*adp->realcost) (adp->head->np->c, *cp, + adp->userdata); + knowncost = adp->head->np->knowncost + incknowncost; + /* + * If this neighbor is already in the queue, we can + * save some time. + */ + qp = as_iscinq(adp, *cp); + inclbcost = qp ? qp->np->inclbcost : + (*adp->lbcost) (*cp, adp->to, adp->userdata); + if (inclbcost < 0.0) /* skip bad cases */ + continue; + lbcost = knowncost + inclbcost; #ifdef DEBUG -fprintf(stderr, "\tneighbor %d, %d, lbcost %f ", cp->x, cp->y, lbcost); + fprintf(stderr, "\tneighbor %d, %d, lbcost %f ", cp->x, cp->y, + lbcost); #endif /* DEBUG */ - /* - * If this neighbor is already in the queue, check to - * see which has the lower cost. If the one already in - * the queue is cheaper, skip this neighbor as bad. If - * the neighbor does, delete the one in the queue. - */ - if (qp) { - if (qp->np->lbcost <= lbcost) { + /* + * If this neighbor is already in the queue, check to + * see which has the lower cost. If the one already in + * the queue is cheaper, skip this neighbor as bad. If + * the neighbor does, delete the one in the queue. + */ + if (qp) { + if (qp->np->lbcost <= lbcost) { #ifdef DEBUG -fprintf(stderr, "old, loses to %f\n", qp->np->lbcost); + fprintf(stderr, "old, loses to %f\n", qp->np->lbcost); #endif /* DEBUG */ - continue; - } else { + continue; + } else { #ifdef DEBUG -fprintf(stderr, "old, wins over %f\n", qp->np->lbcost); + fprintf(stderr, "old, wins over %f\n", qp->np->lbcost); #endif /* DEBUG */ - if (qp->np->flags & AS_TRIED) { - /* should "never happen" */ - return (0); - } + if (qp->np->flags & AS_TRIED) { + /* should "never happen" */ + return (0); + } /* * The neighbor is better than a previously visited coordinate; * remove the old coordinate from the queue and add it to * the subsumed nodes queue. To get here at * all we can't be the head, thus qp->prev is defined. */ - /* Delete from main queue */ - qp->prev->next = qp->next; - if (qp->next) - qp->next->prev = qp->prev; + /* Delete from main queue */ + qp->prev->next = qp->next; + if (qp->next) + qp->next->prev = qp->prev; - /* Add to subsumed queue */ - if (adp->subsumed) { - adp->subsumed->prev = qp; - qp->next = adp->subsumed; - } else { - qp->next = NULL; - } - adp->subsumed = qp; - adp->subsumed->prev = NULL; - fix_pointer = 1; + /* Add to subsumed queue */ + if (adp->subsumed) { + adp->subsumed->prev = qp; + qp->next = adp->subsumed; + } else { + qp->next = NULL; + } + adp->subsumed = qp; + adp->subsumed->prev = NULL; + fix_pointer = 1; /* * At this point, the as_iscinq code may contain bogus pointer * refs. They'll be fixed when as_merge merges the new * neighbors into the main queue. */ - } - } + } + } #ifdef DEBUG -else { -fprintf(stderr, "new\n"); -} + else { + fprintf(stderr, "new\n"); + } #endif /* DEBUG */ - if (qp) - seccost = qp->np->seccost; - else - seccost = (adp->seccost) ? - (*adp->seccost)(*cp, adp->to, adp->userdata) : - 0.0; - np = as_newnode(adp->head->np, *cp, inclbcost, lbcost, + if (qp) + seccost = qp->np->seccost; + else + seccost = (adp->seccost) ? + (*adp->seccost) (*cp, adp->to, adp->userdata) : 0.0; + np = as_newnode(adp->head->np, *cp, inclbcost, lbcost, knowncost, seccost); - if (np == NULL) - return (0); - if (fix_pointer) { + if (np == NULL) + return (0); + if (fix_pointer) { #ifdef DEBUG -fprintf(stderr, "Fixing pointer for %d, %d\n", adp->subsumed->np->c.x, -adp->subsumed->np->c.y); + fprintf(stderr, "Fixing pointer for %d, %d\n", + adp->subsumed->np->c.x, adp->subsumed->np->c.y); #endif - adp->subsumed->np->back = np; - } - adp->neighbor_nodes[i++] = np; - + adp->subsumed->np->back = np; } - adp->neighbor_nodes[i] = NULL; + adp->neighbor_nodes[i++] = np; + + } + adp->neighbor_nodes[i] = NULL; - return (i); + return (i); } static struct as_node * as_newnode(struct as_node *backp, struct as_coord c, - double inclbcost, double lbcost, double knowncost, double seccost) + double inclbcost, double lbcost, double knowncost, + double seccost) { - struct as_node *np; + struct as_node *np; - /* Got an interesting coordinate; make a node for it. */ - AS_NEW_MALLOC(np, struct as_node, NULL); - np->flags = 0; - np->c = c; - np->inclbcost = inclbcost; - np->lbcost = lbcost; - np->knowncost = knowncost; - np->seccost = seccost; - np->step = backp->step; - np->back = backp; + /* Got an interesting coordinate; make a node for it. */ + AS_NEW_MALLOC(np, struct as_node, NULL); + np->flags = 0; + np->c = c; + np->inclbcost = inclbcost; + np->lbcost = lbcost; + np->knowncost = knowncost; + np->seccost = seccost; + np->step = backp->step; + np->back = backp; - return (np); + return (np); } diff --git a/src/lib/commands/acce.c b/src/lib/commands/acce.c index 3c68874bf..1c5f0421d 100644 --- a/src/lib/commands/acce.c +++ b/src/lib/commands/acce.c @@ -49,44 +49,44 @@ int acce(void) { - struct natstr *natp; - struct natstr *np; - natid cn; - natid as; - int n; + struct natstr *natp; + struct natstr *np; + natid cn; + natid as; + int n; - if (player->argp[1] == 0) - as = player->cnum; - else { - if ((n = natarg(player->argp[1], "Which country? ")) < 0) { - pr("Bad country number\n"); - return RET_SYN; - } - as = (natid) n; + if (player->argp[1] == 0) + as = player->cnum; + else { + if ((n = natarg(player->argp[1], "Which country? ")) < 0) { + pr("Bad country number\n"); + return RET_SYN; } - if ((natp = getnatp(as)) == 0) { - pr("Bad country number %d\n", player->cnum); - return RET_SYN; + as = (natid)n; + } + if ((natp = getnatp(as)) == 0) { + pr("Bad country number %d\n", player->cnum); + return RET_SYN; + } + pr("\t%s Acceptance Status Report\t", cname(as)); + prdate(); + pr("\n Acceptance status %5s theirs\n", + player->cnum == as ? "yours" : " his"); + pr(" tel trty anno loan tel trty anno loan\n"); + for (cn = 1; cn < MAXNOC; cn++) { + if ((np = getnatp(cn)) == 0) + break; + if (cn == as) + continue; + if ((np->nat_stat & STAT_NORM) == 0 && + (np->nat_stat & STAT_SANCT) == 0) + continue; + if (opt_HIDDEN) { + if (!player->god && !getcontact(getnatp(player->cnum), cn)) + continue; } - pr("\t%s Acceptance Status Report\t", cname(as)); - prdate(); - pr("\n Acceptance status %5s theirs\n", - player->cnum == as ? "yours" : " his"); - pr(" tel trty anno loan tel trty anno loan\n"); - for (cn=1; cn < MAXNOC; cn++) { - if ((np = getnatp(cn)) == 0) - break; - if (cn == as) - continue; - if ((np->nat_stat & STAT_NORM) == 0 && - (np->nat_stat & STAT_SANCT) == 0) - continue; - if (opt_HIDDEN) { - if (!player->god && !getcontact(getnatp(player->cnum), cn)) - continue; - } - pr("%3d) %-14.14s ", cn, cname(cn)); - pr("%-9s %s\n", rejectname(natp, cn), rejectname(np, as)); - } - return RET_OK; + pr("%3d) %-14.14s ", cn, cname(cn)); + pr("%-9s %s\n", rejectname(natp, cn), rejectname(np, as)); + } + return RET_OK; } diff --git a/src/lib/commands/add.c b/src/lib/commands/add.c index 1d87bd1e4..91e736cd3 100644 --- a/src/lib/commands/add.c +++ b/src/lib/commands/add.c @@ -51,181 +51,184 @@ extern float start_technology, start_research; int add(void) { - struct natstr *natp; - struct sctstr sect; - struct nstr_sect nstr; - register int i; - s_char cntryname[21]; - s_char pname[21]; - natid coun; - natid freecn; - s_char prompt[128]; - s_char buf[1024]; - s_char *p; - s_char loopflag; - int stat; - struct nstr_item ni; - struct lndstr land; + struct natstr *natp; + struct sctstr sect; + struct nstr_sect nstr; + register int i; + s_char cntryname[21]; + s_char pname[21]; + natid coun; + natid freecn; + s_char prompt[128]; + s_char buf[1024]; + s_char *p; + s_char loopflag; + int stat; + struct nstr_item ni; + struct lndstr land; - for (freecn=0; NULL != (natp = getnatp(freecn)); freecn++) { - if ((natp->nat_stat & STAT_INUSE) == 0) - break; + for (freecn = 0; NULL != (natp = getnatp(freecn)); freecn++) { + if ((natp->nat_stat & STAT_INUSE) == 0) + break; + } + if (freecn < MAXNOC) + sprintf(prompt, "New country number? (%d is unused) ", freecn); + else + strcpy(prompt, "New country number? (they all seem to be used) "); + while ((p = getstarg(player->argp[1], prompt, buf)) && *p) { + coun = atoi(p); + if (coun < MAXNOC) + break; + pr("Max # countries is %d\n", MAXNOC); + player->argp[1] = 0; + } + if (p == 0 || *p == 0) + return RET_FAIL; + if (coun == 0) { + pr("Not allowed to add country #0\n"); + return RET_FAIL; + } + natp = getnatp(coun); + while ((p = getstarg(player->argp[2], "Country Name? ", buf)) && *p) { + if (strlen(p) < 20) { + (void)strcpy(cntryname, p); + break; } - if (freecn < MAXNOC) - sprintf(prompt, "New country number? (%d is unused) ", freecn); - else - strcpy(prompt, "New country number? (they all seem to be used) "); - while ((p = getstarg(player->argp[1], prompt, buf)) && *p) { - coun = atoi(p); - if (coun < MAXNOC) - break; - pr("Max # countries is %d\n", MAXNOC); - player->argp[1] = 0; + pr("Too long.\n"); + player->argp[2] = 0; + } + if (p == 0 || *p == 0) + return RET_OK; + while ((p = getstarg(player->argp[3], "Representative? ", buf)) && *p) { + if (strlen(p) < 20) { + (void)strcpy(pname, p); + break; } - if (p == 0 || *p == 0) - return RET_FAIL; - if (coun == 0) { - pr("Not allowed to add country #0\n"); - return RET_FAIL; + pr("Too long.\n"); + player->argp[3] = 0; + } + if (p == 0 || *p == 0) + return RET_OK; + loopflag = 1; + stat = natp->nat_stat; + strcpy(prompt, "Status? (visitor, new, active, god, delete) "); + while (loopflag && (p = getstarg(player->argp[4], prompt, buf))) { + loopflag = 0; + switch (*p) { + case 'v': + stat = STAT_INUSE; + break; + case 'n': + stat = STAT_NEW | STAT_INUSE; + break; + case 'a': + stat = STAT_NORM | STAT_INUSE; + break; + case 'g': + stat = STAT_GOD | STAT_NORM | STAT_INUSE; + break; + case 'd': + stat = 0; + break; + default: + pr("Illegal selection\n"); + loopflag = 1; + break; } - natp = getnatp(coun); - while ((p = getstarg(player->argp[2], "Country Name? ", buf)) && *p) { - if (strlen(p) < 20) { - (void) strcpy(cntryname, p); - break; - } - pr("Too long.\n"); - player->argp[2] = 0; - } - if (p == 0 || *p == 0) - return RET_OK; - while ((p = getstarg(player->argp[3], "Representative? ", buf)) && *p) { - if (strlen(p) < 20) { - (void) strcpy(pname, p); - break; - } - pr("Too long.\n"); - player->argp[3] = 0; - } - if (p == 0 || *p == 0) - return RET_OK; - loopflag = 1; - stat = natp->nat_stat; - strcpy(prompt, "Status? (visitor, new, active, god, delete) "); - while (loopflag && (p = getstarg(player->argp[4], prompt, buf))) { - loopflag = 0; - switch (*p) { - case 'v': - stat = STAT_INUSE; - break; - case 'n': - stat = STAT_NEW|STAT_INUSE; - break; - case 'a': - stat = STAT_NORM|STAT_INUSE; - break; - case 'g': - stat = STAT_GOD|STAT_NORM|STAT_INUSE; - break; - case 'd': - stat = 0; - break; - default: - pr("Illegal selection\n"); - loopflag = 1; - break; - } - player->argp[4] = 0; - } - if (p == 0) - return RET_OK; - p = getstarg(player->argp[5], - "Check, wipe, or ignore existing sectors (c|w|i) ", buf); - if (p == 0) - return RET_OK; - snxtitem_all(&ni,EF_LAND); - while(nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own == coun){ - makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_own = 0; - pr("Land unit %d wiped\n",land.lnd_uid); - putland(land.lnd_uid,&land); - } + player->argp[4] = 0; + } + if (p == 0) + return RET_OK; + p = getstarg(player->argp[5], + "Check, wipe, or ignore existing sectors (c|w|i) ", buf); + if (p == 0) + return RET_OK; + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == coun) { + makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_own = 0; + pr("Land unit %d wiped\n", land.lnd_uid); + putland(land.lnd_uid, &land); } - natp->nat_stat = stat; - strcpy(natp->nat_cnam, cntryname); - strcpy(natp->nat_pnam, pname); - if (*p != 'w' && *p != 'c') { - pr("Any existing sectors ignored\n"); - } else { - pr("Checking sectors...\n"); - snxtsct_all(&nstr); - while (nxtsct(&nstr, §)) { - if (sect.sct_own != coun) - continue; - pr("%s ", xyas(nstr.x, nstr.y, player->cnum)); - if (*p == 'w') { - sect.sct_mobil = 0; - sect.sct_effic = 0; - sect.sct_road = 0; - sect.sct_rail = 0; - sect.sct_defense = 0; - sect.sct_own = 0; - sect.sct_oldown = 0; - if (sect.sct_type != SCT_MOUNT && - sect.sct_type != SCT_PLAINS) { - sect.sct_type = SCT_RURAL; - sect.sct_newtype = SCT_RURAL; - } - /* No dist path */ - sect.sct_dist_x = sect.sct_x; - sect.sct_dist_y = sect.sct_y; - sect.sct_nv = 0; - putsect(§); - pr("wiped\n"); - } else { - pr("\n"); - } + } + natp->nat_stat = stat; + strcpy(natp->nat_cnam, cntryname); + strcpy(natp->nat_pnam, pname); + if (*p != 'w' && *p != 'c') { + pr("Any existing sectors ignored\n"); + } else { + pr("Checking sectors...\n"); + snxtsct_all(&nstr); + while (nxtsct(&nstr, §)) { + if (sect.sct_own != coun) + continue; + pr("%s ", xyas(nstr.x, nstr.y, player->cnum)); + if (*p == 'w') { + sect.sct_mobil = 0; + sect.sct_effic = 0; + sect.sct_road = 0; + sect.sct_rail = 0; + sect.sct_defense = 0; + sect.sct_own = 0; + sect.sct_oldown = 0; + if (sect.sct_type != SCT_MOUNT && + sect.sct_type != SCT_PLAINS) { + sect.sct_type = SCT_RURAL; + sect.sct_newtype = SCT_RURAL; } + /* No dist path */ + sect.sct_dist_x = sect.sct_x; + sect.sct_dist_y = sect.sct_y; + sect.sct_nv = 0; + putsect(§); + pr("wiped\n"); + } else { + pr("\n"); + } } + } - if ((natp->nat_stat & (STAT_INUSE|STAT_NORM|STAT_GOD)) == STAT_INUSE) { - *natp->nat_hostaddr = '\0'; - *natp->nat_hostname = '\0'; - *natp->nat_userid = '\0'; - natp->nat_btu = 0; - natp->nat_connected = 0; - natp->nat_reserve = 0; - natp->nat_tgms = 0; - natp->nat_ystart = 0; - natp->nat_xstart = 0; - natp->nat_ycap = 0; - natp->nat_xcap = 0; - natp->nat_yorg = 0; - natp->nat_xorg = 0; - natp->nat_dayno = 0; - natp->nat_minused = 0; - bzero((s_char *)natp->nat_b, sizeof (natp->nat_b)); - (void) time(&natp->nat_last_login); - (void) time(&natp->nat_last_logout); - natp->nat_money = 0; - natp->nat_level[NAT_TLEV] = start_technology; - natp->nat_level[NAT_RLEV] = start_research; - natp->nat_level[NAT_ELEV] = start_education; - natp->nat_level[NAT_HLEV] = start_happiness; - for (i=0; inat_rejects[i] = 0; - natp->nat_newstim = 0; - natp->nat_annotim = 0; - (void) creat(mailbox(buf, coun), 0660); - } else - pr("No special initializations done...\n"); + if ((natp->nat_stat & (STAT_INUSE | STAT_NORM | STAT_GOD)) == + STAT_INUSE) { + *natp->nat_hostaddr = '\0'; + *natp->nat_hostname = '\0'; + *natp->nat_userid = '\0'; + natp->nat_btu = 0; + natp->nat_connected = 0; + natp->nat_reserve = 0; + natp->nat_tgms = 0; + natp->nat_ystart = 0; + natp->nat_xstart = 0; + natp->nat_ycap = 0; + natp->nat_xcap = 0; + natp->nat_yorg = 0; + natp->nat_xorg = 0; + natp->nat_dayno = 0; + natp->nat_minused = 0; + bzero((s_char *)natp->nat_b, sizeof(natp->nat_b)); + (void)time(&natp->nat_last_login); + (void)time(&natp->nat_last_logout); + natp->nat_money = 0; + natp->nat_level[NAT_TLEV] = start_technology; + natp->nat_level[NAT_RLEV] = start_research; + natp->nat_level[NAT_ELEV] = start_education; + natp->nat_level[NAT_HLEV] = start_happiness; + for (i = 0; i < MAXNOC / 4; i++) + natp->nat_rejects[i] = 0; + natp->nat_newstim = 0; + natp->nat_annotim = 0; + (void)creat(mailbox(buf, coun), 0660); + } else + pr("No special initializations done...\n"); - for (i=0; inat_priorities[i] = -1; - natp->nat_flags = NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS; - for (i=0; inat_relate[i] = NEUTRAL; - putnat(natp); - return 0; + for (i = 0; i < SCT_MAXDEF + 8; i++) + natp->nat_priorities[i] = -1; + natp->nat_flags = + NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS; + for (i = 0; i < MAXNOC; i++) + natp->nat_relate[i] = NEUTRAL; + putnat(natp); + return 0; } diff --git a/src/lib/commands/anti.c b/src/lib/commands/anti.c index 1d01d5528..981fe4bd0 100644 --- a/src/lib/commands/anti.c +++ b/src/lib/commands/anti.c @@ -56,19 +56,19 @@ extern int sect_mob_neg_factor; int anti(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; - int cond[I_MAX+1]; - int mil, che, target; - int avail_mil; - int amil, ache; - int milkilled, chekilled; - double odds, damil, dache; - int mob; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; + int cond[I_MAX + 1]; + int mil, che, target; + int avail_mil; + int amil, ache; + int milkilled, chekilled; + double odds, damil, dache; + int mob; int n_cheleft; - extern double hap_fact(); - + extern double hap_fact(); + if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; prdate(); @@ -84,17 +84,16 @@ anti(void) mil = getvar(V_MILIT, (char *)§, EF_SECTOR); che = get_che_value(cond[C_CHE]); target = get_che_cnum(cond[C_CHE]); - avail_mil = sect.sct_mobil/2; - if (mil <= avail_mil) + avail_mil = sect.sct_mobil / 2; + if (mil <= avail_mil) avail_mil = mil; prxy("%4d,%-4d ", sect.sct_x, sect.sct_y, player->cnum); if (avail_mil <= 0) { pr("No available mil or mob in sector.\n"); continue; } - pr("Sector mobility/troop strength will allow %d troops to engage.\n", - avail_mil); - + pr("Sector mobility/troop strength will allow %d troops to engage.\n", avail_mil); + if (target == player->cnum) { amil = mil; ache = che; @@ -105,7 +104,8 @@ anti(void) damil = amil; dache = ache; odds = (dache * 2.0 / (damil + dache)); - odds /= hap_fact(getnatp(sect.sct_own),getnatp(sect.sct_oldown)); + odds /= hap_fact(getnatp(sect.sct_own), + getnatp(sect.sct_oldown)); mob = mob - 2; if (chance(odds)) { amil = amil - 1; @@ -117,9 +117,8 @@ anti(void) } if (mil - milkilled > 0) { sect.sct_mobil = sect.sct_mobil - chekilled - milkilled; - putvar(V_MILIT, mil - milkilled, (char *)§, - EF_SECTOR); - if ( ache == 0 ) + putvar(V_MILIT, mil - milkilled, (char *)§, EF_SECTOR); + if (ache == 0) cond[C_CHE] = 0; set_che_value(cond[C_CHE], ache); putvar(V_CHE, cond[C_CHE], (char *)§, EF_SECTOR); @@ -132,11 +131,11 @@ anti(void) pr(" Partisans still active in this sector.\n"); } } else { - if (opt_MOB_ACCESS) { - sect.sct_mobil = - -(etu_per_update/sect_mob_neg_factor); + if (opt_MOB_ACCESS) { + sect.sct_mobil = + -(etu_per_update / sect_mob_neg_factor); } else { - sect.sct_mobil = 0; + sect.sct_mobil = 0; } sect.sct_loyal = sect.sct_loyal * 0.5; n_cheleft = (random() % 4); @@ -146,21 +145,23 @@ anti(void) n_cheleft = (ache / (n_cheleft + 3)); ache -= n_cheleft; set_che_value(cond[C_CHE], n_cheleft); - } else + } else cond[C_CHE] = 0; putvar(V_MILIT, ache, (char *)§, EF_SECTOR); putvar(V_CHE, cond[C_CHE], (char *)§, EF_SECTOR); if (sect.sct_own == sect.sct_oldown) sect.sct_oldown = 0; - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - makenotlost(EF_SECTOR, sect.sct_oldown, 0, sect.sct_x, sect.sct_y); + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, + sect.sct_y); + makenotlost(EF_SECTOR, sect.sct_oldown, 0, sect.sct_x, + sect.sct_y); sect.sct_own = sect.sct_oldown; - sect.sct_off = 1; /* Turn the sector off */ + sect.sct_off = 1; /* Turn the sector off */ putsect(§); pr(" Partisans take over the sector. You blew it.\n"); - wu(0, sect.sct_oldown, + wu(0, sect.sct_oldown, "Sector %s regained from Partisan activity.\n", - xyas(nstr.x,nstr.y,sect.sct_oldown)); + xyas(nstr.x, nstr.y, sect.sct_oldown)); } } else { pr(" Body count: Military 0 - Guerillas 0.\n"); diff --git a/src/lib/commands/arm.c b/src/lib/commands/arm.c index 30e6b6661..f9e48263d 100644 --- a/src/lib/commands/arm.c +++ b/src/lib/commands/arm.c @@ -52,113 +52,111 @@ int arm(void) { - struct nchrstr *ncp; - struct plchrstr *plc; - struct plnstr pl; - struct plnstr start; /* Used for sanity checking */ - struct nukstr nuke; - s_char *p; - int i; - int pno; - int nuketype; - int nukenum; - int len; - struct nstr_item ni; - s_char buf[1024]; - int disarm = **player->argp=='d'; - s_char *prompt = disarm?"Disarm plane: ":"Arm plane: "; + struct nchrstr *ncp; + struct plchrstr *plc; + struct plnstr pl; + struct plnstr start; /* Used for sanity checking */ + struct nukstr nuke; + s_char *p; + int i; + int pno; + int nuketype; + int nukenum; + int len; + struct nstr_item ni; + s_char buf[1024]; + int disarm = **player->argp == 'd'; + s_char *prompt = disarm ? "Disarm plane: " : "Arm plane: "; - if (!(p = getstarg(player->argp[1], prompt, buf)) || !*p) - return RET_SYN; - pno = atoi(p); - if (pno < 0 || !getplane(pno, &pl) || pl.pln_own != player->cnum) - return RET_FAIL; - memcpy(&start, &pl, sizeof(struct plnstr)); - plc = &plchr[(int)pl.pln_type]; - if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) { - pr("A %s cannot carry nuclear devices!\n",plc->pl_name); - return RET_FAIL; + if (!(p = getstarg(player->argp[1], prompt, buf)) || !*p) + return RET_SYN; + pno = atoi(p); + if (pno < 0 || !getplane(pno, &pl) || pl.pln_own != player->cnum) + return RET_FAIL; + memcpy(&start, &pl, sizeof(struct plnstr)); + plc = &plchr[(int)pl.pln_type]; + if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) { + pr("A %s cannot carry nuclear devices!\n", plc->pl_name); + return RET_FAIL; + } + if (opt_MARKET) { + if (ontradingblock(EF_PLANE, (int *)&pl)) { + pr("You cannot arm/disarm an item on the trading block!\n"); + return RET_FAIL; } - if (opt_MARKET) { - if (ontradingblock(EF_PLANE, (int *)&pl)) { - pr("You cannot arm/disarm an item on the trading block!\n"); - return RET_FAIL; - } + } + if (pl.pln_nuketype == -1) { + if (disarm) { + pr("%s is not carrying any nuclear devices\n", prplane(&pl)); + return RET_FAIL; } - if (pl.pln_nuketype == -1) { - if (disarm) { - pr("%s is not carrying any nuclear devices\n", - prplane(&pl)); - return RET_FAIL; - } - if ((p = getstarg(player->argp[2], "Device type: ", buf)) == 0) - return RET_SYN; - if (!check_plane_ok(&start)) - return RET_FAIL; - len = strlen(p); - for (i=0, ncp = nchr; in_name, p, len) == 0) - break; - } - if (i >= N_MAXNUKE) { - pr("No such nuke type!\n"); - return RET_SYN; - } - nuketype = i; - nukenum = -1; - snxtitem_all(&ni, EF_NUKE); - while (nxtitem(&ni, (s_char *)&nuke)) { - if (nuke.nuk_own != player->cnum) - continue; - if (nuke.nuk_x != pl.pln_x || nuke.nuk_y != pl.pln_y) - continue; - nukenum = ni.cur; - break; - } - if (nukenum < 0) { - pr("You don't own any nukes in that sector.\n"); - return RET_FAIL; - } - if (nuke.nuk_types[nuketype] == 0) { - pr("No nukes of that type in that sector.\n"); - return RET_FAIL; - } - if (pl.pln_load < ncp->n_weight) { - pr("A %s cannot carry %s devices!\n", plc->pl_name,ncp->n_name); - return RET_FAIL; - } - p = getstarg(player->argp[3], "Airburst [n]? ", buf); - - if (!check_plane_ok(&start)) - return RET_FAIL; - - if (p && (*p == 'y' || *p == 'Y')) - pl.pln_flags |= PLN_AIRBURST; - else - pl.pln_flags &= ~PLN_AIRBURST; - - pl.pln_nuketype = nuketype; - nuk_delete(&nuke, nuketype, 1); - } else if (!disarm) { - pr("%s already carrying a warhead.\n", prplane(&pl)); + if ((p = getstarg(player->argp[2], "Device type: ", buf)) == 0) + return RET_SYN; + if (!check_plane_ok(&start)) + return RET_FAIL; + len = strlen(p); + for (i = 0, ncp = nchr; i < N_MAXNUKE; i++, ncp++) { + if (strncmp(ncp->n_name, p, len) == 0) + break; } - if (disarm) { - pr("%s warhead removed from %s and added to %s\n", - nchr[(int)pl.pln_nuketype].n_name, - prplane(&pl), - xyas(pl.pln_x, pl.pln_y, player->cnum)); - nuk_add(pl.pln_x, pl.pln_y, pl.pln_nuketype, 1); - pl.pln_nuketype = -1; - pl.pln_flags &= ~PLN_AIRBURST; - } else { - pr("%s armed with a %s warhead.\n", prplane(&pl), - nchr[(int)pl.pln_nuketype].n_name); - pr("Warhead on %s is programmed to %s\n", - prplane(&pl), - pl.pln_flags & PLN_AIRBURST? - "airburst":"groundburst"); + if (i >= N_MAXNUKE) { + pr("No such nuke type!\n"); + return RET_SYN; + } + nuketype = i; + nukenum = -1; + snxtitem_all(&ni, EF_NUKE); + while (nxtitem(&ni, (s_char *)&nuke)) { + if (nuke.nuk_own != player->cnum) + continue; + if (nuke.nuk_x != pl.pln_x || nuke.nuk_y != pl.pln_y) + continue; + nukenum = ni.cur; + break; + } + if (nukenum < 0) { + pr("You don't own any nukes in that sector.\n"); + return RET_FAIL; } - - putplane(pl.pln_uid, &pl); - return RET_OK; + if (nuke.nuk_types[nuketype] == 0) { + pr("No nukes of that type in that sector.\n"); + return RET_FAIL; + } + if (pl.pln_load < ncp->n_weight) { + pr("A %s cannot carry %s devices!\n", plc->pl_name, + ncp->n_name); + return RET_FAIL; + } + p = getstarg(player->argp[3], "Airburst [n]? ", buf); + + if (!check_plane_ok(&start)) + return RET_FAIL; + + if (p && (*p == 'y' || *p == 'Y')) + pl.pln_flags |= PLN_AIRBURST; + else + pl.pln_flags &= ~PLN_AIRBURST; + + pl.pln_nuketype = nuketype; + nuk_delete(&nuke, nuketype, 1); + } else if (!disarm) { + pr("%s already carrying a warhead.\n", prplane(&pl)); + } + if (disarm) { + pr("%s warhead removed from %s and added to %s\n", + nchr[(int)pl.pln_nuketype].n_name, + prplane(&pl), xyas(pl.pln_x, pl.pln_y, player->cnum)); + nuk_add(pl.pln_x, pl.pln_y, pl.pln_nuketype, 1); + pl.pln_nuketype = -1; + pl.pln_flags &= ~PLN_AIRBURST; + } else { + pr("%s armed with a %s warhead.\n", prplane(&pl), + nchr[(int)pl.pln_nuketype].n_name); + pr("Warhead on %s is programmed to %s\n", + prplane(&pl), + pl.pln_flags & PLN_AIRBURST ? "airburst" : "groundburst"); + } + + putplane(pl.pln_uid, &pl); + return RET_OK; } diff --git a/src/lib/commands/army.c b/src/lib/commands/army.c index e5e087cf8..7da80b4f6 100644 --- a/src/lib/commands/army.c +++ b/src/lib/commands/army.c @@ -45,44 +45,43 @@ int army(void) { - struct lndstr land; - register int count; - s_char *cp; - s_char c; - struct nstr_item nstr; - struct nstr_item ni; - struct lndstr land2; - int r; - s_char buf[1024]; + struct lndstr land; + register int count; + s_char *cp; + s_char c; + struct nstr_item nstr; + struct nstr_item ni; + struct lndstr land2; + int r; + s_char buf[1024]; - cp = getstarg(player->argp[1], "army? ", buf); - if (cp == 0) - return RET_SYN; - c = *cp; - if (!isalpha(c) && c != '~') { - pr("Specify army, (1 alpha char or '~')\n"); - return RET_SYN; + cp = getstarg(player->argp[1], "army? ", buf); + if (cp == 0) + return RET_SYN; + c = *cp; + if (!isalpha(c) && c != '~') { + pr("Specify army, (1 alpha char or '~')\n"); + return RET_SYN; + } + if (c == '~') + c = ' '; + if (!snxtitem(&nstr, EF_LAND, player->argp[2])) + return RET_SYN; + count = 0; + while (nxtitem(&nstr, (s_char *)&land)) { + if (!player->owner) + continue; + land.lnd_army = c; + snxtitem(&ni, EF_LAND, cp); + while ((r = nxtitem(&ni, (s_char *)&land2)) && + (land2.lnd_army != c)) ; + if (r) { + bcopy(land2.lnd_rpath, land.lnd_rpath, 10); + land.lnd_rflags = land2.lnd_rflags; } - if (c == '~') - c = ' '; - if (!snxtitem(&nstr, EF_LAND, player->argp[2])) - return RET_SYN; - count = 0; - while (nxtitem(&nstr, (s_char *)&land)) { - if (!player->owner) - continue; - land.lnd_army = c; - snxtitem(&ni, EF_LAND, cp); - while ((r=nxtitem(&ni, (s_char *)&land2)) && - (land2.lnd_army != c)) - ; - if (r){ - bcopy(land2.lnd_rpath, land.lnd_rpath,10); - land.lnd_rflags = land2.lnd_rflags; - } - putland(land.lnd_uid, &land); - count++; - } - pr("%d unit%s added to army `%c'\n", count, splur(count), c); - return RET_OK; + putland(land.lnd_uid, &land); + count++; + } + pr("%d unit%s added to army `%c'\n", count, splur(count), c); + return RET_OK; } diff --git a/src/lib/commands/assa.c b/src/lib/commands/assa.c index 3351569d8..3870b242b 100644 --- a/src/lib/commands/assa.c +++ b/src/lib/commands/assa.c @@ -51,181 +51,185 @@ #include "commands.h" int -assa(void) { - struct combat off[1]; /* assaulting ship */ - struct combat def[1]; /* defending sector */ - int fort_sup, ship_sup, land_sup, plane_sup; - struct emp_qelem olist; /* assaulting units */ - struct emp_qelem dlist; /* defending units */ - int ototal; /* total assaulting strength */ - int a_engineer = 0; /* assaulter engineers are present */ - int a_spy = 0; /* the best assaulter scout */ - double osupport = 1.0; /* assault support */ - double dsupport = 1.0; /* defense support */ - s_char *p; - s_char buf[1024]; - int n; - int ourtotal; - struct emp_qelem *qp, *next; - struct llist *llp; - int rel; - - att_combat_init(off, EF_SHIP); - att_combat_init(def, EF_SECTOR); - /* - * Collect input from the assaulter - */ - - /* What are we assaulting? */ - - if (!(p = getstarg(player->argp[1], "Sector : ", buf))) - return RET_SYN; - if (!sarg_xy(p, &def->x, &def->y)) - return RET_SYN; - if (att_abort(A_ASSAULT, 0, def)) - return RET_FAIL; - - /* - * Ask the assaulter what he wants to assault with - */ - - if ((off->shp_uid = onearg(player->argp[2], "Assault from ship #")) < 0) { - pr("You may only assault from one ship!\n"); - return RET_FAIL; - } - if (att_abort(A_ASSAULT, off, def)) { - pr("Assault aborted\n"); - return RET_OK; - } - - /* Show what we're assaulting, and check treaties */ - - if (att_show(def)) - return RET_FAIL; - - /* Ask about offensive support */ - - att_ask_support(3, &fort_sup, &ship_sup, &land_sup, &plane_sup); - if (att_abort(A_ASSAULT, off, def)) { - att_empty_attack(A_ASSAULT, 0, def); - return RET_OK; - } - - /* Ask the player what he wants to assault with */ - - att_ask_offense(A_ASSAULT, off, def, &olist, &a_spy, &a_engineer); - if (att_abort(A_ASSAULT, off, def)) { - pr("Assault aborted\n"); - att_empty_attack(A_ASSAULT, 0, def); - return att_free_lists(&olist, 0); - } +assa(void) +{ + struct combat off[1]; /* assaulting ship */ + struct combat def[1]; /* defending sector */ + int fort_sup, ship_sup, land_sup, plane_sup; + struct emp_qelem olist; /* assaulting units */ + struct emp_qelem dlist; /* defending units */ + int ototal; /* total assaulting strength */ + int a_engineer = 0; /* assaulter engineers are present */ + int a_spy = 0; /* the best assaulter scout */ + double osupport = 1.0; /* assault support */ + double dsupport = 1.0; /* defense support */ + s_char *p; + s_char buf[1024]; + int n; + int ourtotal; + struct emp_qelem *qp, *next; + struct llist *llp; + int rel; + + att_combat_init(off, EF_SHIP); + att_combat_init(def, EF_SECTOR); + /* + * Collect input from the assaulter + */ + + /* What are we assaulting? */ + + if (!(p = getstarg(player->argp[1], "Sector : ", buf))) + return RET_SYN; + if (!sarg_xy(p, &def->x, &def->y)) + return RET_SYN; + if (att_abort(A_ASSAULT, 0, def)) + return RET_FAIL; + + /* + * Ask the assaulter what he wants to assault with + */ + + if ((off->shp_uid = + onearg(player->argp[2], "Assault from ship #")) < 0) { + pr("You may only assault from one ship!\n"); + return RET_FAIL; + } + if (att_abort(A_ASSAULT, off, def)) { + pr("Assault aborted\n"); + return RET_OK; + } - /* If we're assaulting our own sector, end here */ - if (def->own == player->cnum) { - if (off->troops) - pr("You reinforce %s with %d troops\n", - xyas(def->x, def->y, player->cnum), off->troops); - if (off->troops || !QEMPTY(&olist)) - att_move_in_off(A_ASSAULT, off, &olist, def); - return RET_OK; - } + /* Show what we're assaulting, and check treaties */ - /* - * Estimate the defense strength and give the player a chance to abort - */ + if (att_show(def)) + return RET_FAIL; - ototal = att_estimate_defense(A_ASSAULT, off, &olist, def, a_spy); - if (att_abort(A_ASSAULT, off, def)) { - pr("Assault aborted\n"); - att_empty_attack(A_ASSAULT, 0, def); - return att_free_lists(&olist, 0); - } + /* Ask about offensive support */ - /* - * We have now got all the answers from the assaulter. From this point - * forward, we can assume that this battle is the _only_ thing - * happening in the game. - */ - - /* First, we check to see if the only thing we have are spies - * assaulting. If so, we try to sneak them on land. If they - * make it, the defenders don't see a thing. If they fail, well, - * the spies die, and the defenders see them. */ - - ourtotal = 0; - for (n = 0; n <= off->last; n++) { - if (off[n].type == EF_BAD) - continue; - ourtotal += off[n].troops * att_combat_eff(off + n); - } - for (qp = olist.q_forw; qp != &olist; qp = next ) { + att_ask_support(3, &fort_sup, &ship_sup, &land_sup, &plane_sup); + if (att_abort(A_ASSAULT, off, def)) { + att_empty_attack(A_ASSAULT, 0, def); + return RET_OK; + } + + /* Ask the player what he wants to assault with */ + + att_ask_offense(A_ASSAULT, off, def, &olist, &a_spy, &a_engineer); + if (att_abort(A_ASSAULT, off, def)) { + pr("Assault aborted\n"); + att_empty_attack(A_ASSAULT, 0, def); + return att_free_lists(&olist, 0); + } + + /* If we're assaulting our own sector, end here */ + if (def->own == player->cnum) { + if (off->troops) + pr("You reinforce %s with %d troops\n", + xyas(def->x, def->y, player->cnum), off->troops); + if (off->troops || !QEMPTY(&olist)) + att_move_in_off(A_ASSAULT, off, &olist, def); + return RET_OK; + } + + /* + * Estimate the defense strength and give the player a chance to abort + */ + + ototal = att_estimate_defense(A_ASSAULT, off, &olist, def, a_spy); + if (att_abort(A_ASSAULT, off, def)) { + pr("Assault aborted\n"); + att_empty_attack(A_ASSAULT, 0, def); + return att_free_lists(&olist, 0); + } + + /* + * We have now got all the answers from the assaulter. From this point + * forward, we can assume that this battle is the _only_ thing + * happening in the game. + */ + + /* First, we check to see if the only thing we have are spies + * assaulting. If so, we try to sneak them on land. If they + * make it, the defenders don't see a thing. If they fail, well, + * the spies die, and the defenders see them. */ + + ourtotal = 0; + for (n = 0; n <= off->last; n++) { + if (off[n].type == EF_BAD) + continue; + ourtotal += off[n].troops * att_combat_eff(off + n); + } + for (qp = olist.q_forw; qp != &olist; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + if (lchr[(int)llp->land.lnd_type].l_flags & L_SPY) + continue; + ourtotal++; + } + + /* If no attacking forces (i.e. we got here with only spies) + * then try to sneak on-land. */ + + if (!ourtotal) { + pr("Trying to sneak on shore...\n"); + + for (qp = olist.q_forw; qp != &olist; qp = next) { next = qp->q_forw; llp = (struct llist *)qp; - if (lchr[(int)llp->land.lnd_type].l_flags & L_SPY) - continue; - ourtotal++; - } - - /* If no attacking forces (i.e. we got here with only spies) - * then try to sneak on-land. */ - - if (!ourtotal) { - pr("Trying to sneak on shore...\n"); - - for (qp = olist.q_forw; qp != &olist; qp = next ) { - next = qp->q_forw; - llp = (struct llist *)qp; - rel = getrel(getnatp(def->own), player->cnum); - if (chance(0.10) || rel == ALLIED || !def->own) { - pr("%s made it on shore safely.\n", prland(&llp->land)); + rel = getrel(getnatp(def->own), player->cnum); + if (chance(0.10) || rel == ALLIED || !def->own) { + pr("%s made it on shore safely.\n", prland(&llp->land)); + llp->land.lnd_x = def->x; + llp->land.lnd_y = def->y; + llp->land.lnd_ship = -1; + putland(llp->land.lnd_uid, &llp->land); + } else { + pr("%s was spotted", prland(&llp->land)); + if (rel == HOSTILE || rel == AT_WAR || rel == SITZKRIEG || + rel == MOBILIZATION) { + wu(0, def->own, "%s spy shot and killed in %s.\n", + cname(player->cnum), xyas(def->x, def->y, + def->own)); + pr(" and was killed in the attempt.\n"); + llp->land.lnd_effic = 0; + putland(llp->land.lnd_uid, &llp->land); + lnd_delete(llp, ""); + } else { + wu(0, def->own, "%s spy spotted in %s.\n", + cname(player->cnum), xyas(def->x, def->y, + def->own)); + pr(" but made it ok.\n"); llp->land.lnd_x = def->x; llp->land.lnd_y = def->y; llp->land.lnd_ship = -1; putland(llp->land.lnd_uid, &llp->land); - } else { - pr("%s was spotted", prland(&llp->land)); - if (rel == HOSTILE || rel == AT_WAR || rel == SITZKRIEG || - rel == MOBILIZATION) { - wu(0, def->own, "%s spy shot and killed in %s.\n", - cname(player->cnum), xyas(def->x, def->y, def->own)); - pr(" and was killed in the attempt.\n"); - llp->land.lnd_effic = 0; - putland(llp->land.lnd_uid, &llp->land); - lnd_delete(llp, ""); - } else { - wu(0, def->own, "%s spy spotted in %s.\n", - cname(player->cnum), xyas(def->x, def->y, def->own)); - pr(" but made it ok.\n"); - llp->land.lnd_x = def->x; - llp->land.lnd_y = def->y; - llp->land.lnd_ship = -1; - putland(llp->land.lnd_uid, &llp->land); - } } } - return RET_OK; } + return RET_OK; + } - /* Get the real defense */ + /* Get the real defense */ - att_get_defense(&olist, def, &dlist, a_spy, ototal); + att_get_defense(&olist, def, &dlist, a_spy, ototal); - /* Get assaulter and defender support */ + /* Get assaulter and defender support */ - att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup, - &olist, off, &dlist, def, &osupport, &dsupport, - a_engineer); - if (att_abort(A_ASSAULT, off, def)) { - pr("Assault aborted\n"); - att_empty_attack(A_ASSAULT, 0, def); - return att_free_lists(&olist, &dlist); - } + att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup, + &olist, off, &dlist, def, &osupport, &dsupport, + a_engineer); + if (att_abort(A_ASSAULT, off, def)) { + pr("Assault aborted\n"); + att_empty_attack(A_ASSAULT, 0, def); + return att_free_lists(&olist, &dlist); + } - /* - * Death, carnage, and destruction. - */ + /* + * Death, carnage, and destruction. + */ - att_fight(A_ASSAULT,off,&olist,osupport,def,&dlist,dsupport); + att_fight(A_ASSAULT, off, &olist, osupport, def, &dlist, dsupport); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/atta.c b/src/lib/commands/atta.c index 83fdfcfe2..8b51f0773 100644 --- a/src/lib/commands/atta.c +++ b/src/lib/commands/atta.c @@ -52,112 +52,113 @@ #include "commands.h" int -atta(void) { - struct combat off[6]; /* attacking sectors */ - struct combat def[1]; /* defending sector */ - coord newx, newy; - struct sctstr sect; - int fort_sup, ship_sup, land_sup, plane_sup; - struct emp_qelem olist; /* attacking units */ - struct emp_qelem dlist; /* defending units */ - int ototal; /* total attacking strength */ - int a_engineer = 0; /* attacker engineers are present */ - int a_spy = 0; /* the best attacker scout */ - double osupport = 1.0; /* attack support */ - double dsupport = 1.0; /* defense support */ - int last, n; - s_char *p; - s_char buf[1024]; - int rel; - - att_combat_init(def, EF_SECTOR); - /* - * Collect input from the attacker - */ - - /* What are we attacking? */ - - if (!(p = getstarg(player->argp[1], "Sector : ", buf))) - return RET_SYN; - if (!sarg_xy(p, &def->x, &def->y)) - return RET_SYN; - if (att_abort(A_ATTACK, 0, def)) - return RET_FAIL; - - /* Show what we're attacking, and check treaties */ - - if (att_show(def)) - return RET_FAIL; - - /* Ask about offensive support */ - - att_ask_support(2, &fort_sup, &ship_sup, &land_sup, &plane_sup); - if (att_abort(A_ATTACK, 0, def)) { - att_empty_attack(A_ATTACK, 0, def); - return RET_OK; - } - - /* initialize the off[] array */ - - for (n = 0, last = -1; n < 6; ++n) { /* Directions */ - newx = def->x + diroff[n+1][0]; - newy = def->y + diroff[n+1][1]; - getsect(newx,newy,§); /* incase cross world boundary */ - rel = getrel(getnatp(sect.sct_own), player->cnum); - if (!player->owner && rel != ALLIED) - continue; - att_combat_init(&off[++last], EF_SECTOR); - off[last].x = sect.sct_x; - off[last].y = sect.sct_y; - } - off->last = last; - - /* Ask the player what he wants to attack with */ - - att_ask_offense(A_ATTACK, off, def, &olist, &a_spy, &a_engineer); - if (att_abort(A_ATTACK, off, def)) { - pr("Attack aborted\n"); - att_empty_attack(A_ATTACK, 0, def); - return att_free_lists(&olist, 0); - } - - /* - * Estimate the defense strength and give the player a chance to abort - */ - - ototal = att_estimate_defense(A_ATTACK, off, &olist, def, a_spy); - if (att_abort(A_ATTACK, off, def)) { - pr("Attack aborted\n"); - att_empty_attack(A_ATTACK, 0, def); - return att_free_lists(&olist, 0); - } - - /* - * We have now got all the answers from the attacker. From this point - * forward, we can assume that this battle is the _only_ thing - * happening in the game. - */ - - /* Get the real defense */ - - att_get_defense(&olist, def, &dlist, a_spy, ototal); - - /* Get attacker and defender support */ - - att_get_support(A_ATTACK, fort_sup, ship_sup, land_sup, plane_sup, - &olist, off, &dlist, def, &osupport, &dsupport, - a_engineer); - if (att_abort(A_ATTACK, off, def)) { - pr("Attack aborted\n"); - att_empty_attack(A_ATTACK, 0, def); - return att_free_lists(&olist, &dlist); - } - - /* - * Death, carnage, and destruction. - */ - - att_fight(A_ATTACK,off,&olist,osupport,def,&dlist,dsupport); - +atta(void) +{ + struct combat off[6]; /* attacking sectors */ + struct combat def[1]; /* defending sector */ + coord newx, newy; + struct sctstr sect; + int fort_sup, ship_sup, land_sup, plane_sup; + struct emp_qelem olist; /* attacking units */ + struct emp_qelem dlist; /* defending units */ + int ototal; /* total attacking strength */ + int a_engineer = 0; /* attacker engineers are present */ + int a_spy = 0; /* the best attacker scout */ + double osupport = 1.0; /* attack support */ + double dsupport = 1.0; /* defense support */ + int last, n; + s_char *p; + s_char buf[1024]; + int rel; + + att_combat_init(def, EF_SECTOR); + /* + * Collect input from the attacker + */ + + /* What are we attacking? */ + + if (!(p = getstarg(player->argp[1], "Sector : ", buf))) + return RET_SYN; + if (!sarg_xy(p, &def->x, &def->y)) + return RET_SYN; + if (att_abort(A_ATTACK, 0, def)) + return RET_FAIL; + + /* Show what we're attacking, and check treaties */ + + if (att_show(def)) + return RET_FAIL; + + /* Ask about offensive support */ + + att_ask_support(2, &fort_sup, &ship_sup, &land_sup, &plane_sup); + if (att_abort(A_ATTACK, 0, def)) { + att_empty_attack(A_ATTACK, 0, def); return RET_OK; + } + + /* initialize the off[] array */ + + for (n = 0, last = -1; n < 6; ++n) { /* Directions */ + newx = def->x + diroff[n + 1][0]; + newy = def->y + diroff[n + 1][1]; + getsect(newx, newy, §); /* incase cross world boundary */ + rel = getrel(getnatp(sect.sct_own), player->cnum); + if (!player->owner && rel != ALLIED) + continue; + att_combat_init(&off[++last], EF_SECTOR); + off[last].x = sect.sct_x; + off[last].y = sect.sct_y; + } + off->last = last; + + /* Ask the player what he wants to attack with */ + + att_ask_offense(A_ATTACK, off, def, &olist, &a_spy, &a_engineer); + if (att_abort(A_ATTACK, off, def)) { + pr("Attack aborted\n"); + att_empty_attack(A_ATTACK, 0, def); + return att_free_lists(&olist, 0); + } + + /* + * Estimate the defense strength and give the player a chance to abort + */ + + ototal = att_estimate_defense(A_ATTACK, off, &olist, def, a_spy); + if (att_abort(A_ATTACK, off, def)) { + pr("Attack aborted\n"); + att_empty_attack(A_ATTACK, 0, def); + return att_free_lists(&olist, 0); + } + + /* + * We have now got all the answers from the attacker. From this point + * forward, we can assume that this battle is the _only_ thing + * happening in the game. + */ + + /* Get the real defense */ + + att_get_defense(&olist, def, &dlist, a_spy, ototal); + + /* Get attacker and defender support */ + + att_get_support(A_ATTACK, fort_sup, ship_sup, land_sup, plane_sup, + &olist, off, &dlist, def, &osupport, &dsupport, + a_engineer); + if (att_abort(A_ATTACK, off, def)) { + pr("Attack aborted\n"); + att_empty_attack(A_ATTACK, 0, def); + return att_free_lists(&olist, &dlist); + } + + /* + * Death, carnage, and destruction. + */ + + att_fight(A_ATTACK, off, &olist, osupport, def, &dlist, dsupport); + + return RET_OK; } diff --git a/src/lib/commands/bdes.c b/src/lib/commands/bdes.c index 4a2ae0e43..beee444f2 100644 --- a/src/lib/commands/bdes.c +++ b/src/lib/commands/bdes.c @@ -47,32 +47,30 @@ int bdes(void) { - s_char *p, d; - struct nstr_sect nstr; - struct sctstr sect; - s_char prompt[128]; - s_char buf[1024]; - int changed = 0; + s_char *p, d; + struct nstr_sect nstr; + struct sctstr sect; + s_char prompt[128]; + s_char buf[1024]; + int changed = 0; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - while (!player->aborted && nxtsct(&nstr, §)) { - if ((nstr.ncond > 0) && (sect.sct_own != player->cnum)) - continue; - d = player->map[sctoff(nstr.x, nstr.y)]; - sprintf(prompt, "%s '%c' desig? ", - xyas(nstr.x, nstr.y, player->cnum), d); - if ((p = getstarg(player->argp[2], prompt, buf)) == 0) - continue; - if (!isprint(*p)){ - pr("Bad character. Must be printable!\n"); - continue; - } - changed |= map_set(player->cnum, nstr.x, nstr.y, *p, 2); - } - if (changed) - writebmap(player->cnum); - return RET_OK; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + while (!player->aborted && nxtsct(&nstr, §)) { + if ((nstr.ncond > 0) && (sect.sct_own != player->cnum)) + continue; + d = player->map[sctoff(nstr.x, nstr.y)]; + sprintf(prompt, "%s '%c' desig? ", + xyas(nstr.x, nstr.y, player->cnum), d); + if ((p = getstarg(player->argp[2], prompt, buf)) == 0) + continue; + if (!isprint(*p)) { + pr("Bad character. Must be printable!\n"); + continue; + } + changed |= map_set(player->cnum, nstr.x, nstr.y, *p, 2); + } + if (changed) + writebmap(player->cnum); + return RET_OK; } - - diff --git a/src/lib/commands/best.c b/src/lib/commands/best.c index 9c02e211f..39fc8b813 100644 --- a/src/lib/commands/best.c +++ b/src/lib/commands/best.c @@ -47,42 +47,42 @@ int best(void) { - double cost; - s_char *BestDistPath(), *BestLandPath(), *s; - struct sctstr s1, s2; - struct nstr_sect nstr, nstr2; - int dist=0; - s_char buf[1024]; + double cost; + s_char *BestDistPath(), *BestLandPath(), *s; + struct sctstr s1, s2; + struct nstr_sect nstr, nstr2; + int dist = 0; + s_char buf[1024]; - dist = player->argp[0][4] == 'd'; + dist = player->argp[0][4] == 'd'; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; - if (!snxtsct(&nstr2, player->argp[2])) - return RET_SYN; + if (!snxtsct(&nstr2, player->argp[2])) + return RET_SYN; - while (!player->aborted && nxtsct(&nstr, &s1)){ - if (s1.sct_own != player->cnum) - continue; - snxtsct(&nstr2, player->argp[2]); - while (!player->aborted && nxtsct(&nstr2, &s2)){ - if (s2.sct_own != player->cnum) - continue; - if (dist) - s = BestDistPath(buf, &s1,&s2,&cost, MOB_ROAD); - else - s = BestLandPath(buf, &s1,&s2,&cost, MOB_ROAD); - if (s != (s_char *)0) - pr("Best %spath from %s to %s is %s (cost %1.3f)\n", - (dist ? "dist" : ""), - xyas(s1.sct_x,s1.sct_y,player->cnum), - xyas(s2.sct_x,s2.sct_y,player->cnum), s, cost); - else - pr("No owned path from %s to %s exists!\n", - xyas(s1.sct_x,s1.sct_y,player->cnum), - xyas(s2.sct_x,s2.sct_y,player->cnum)); - } + while (!player->aborted && nxtsct(&nstr, &s1)) { + if (s1.sct_own != player->cnum) + continue; + snxtsct(&nstr2, player->argp[2]); + while (!player->aborted && nxtsct(&nstr2, &s2)) { + if (s2.sct_own != player->cnum) + continue; + if (dist) + s = BestDistPath(buf, &s1, &s2, &cost, MOB_ROAD); + else + s = BestLandPath(buf, &s1, &s2, &cost, MOB_ROAD); + if (s != (s_char *)0) + pr("Best %spath from %s to %s is %s (cost %1.3f)\n", + (dist ? "dist" : ""), + xyas(s1.sct_x, s1.sct_y, player->cnum), + xyas(s2.sct_x, s2.sct_y, player->cnum), s, cost); + else + pr("No owned path from %s to %s exists!\n", + xyas(s1.sct_x, s1.sct_y, player->cnum), + xyas(s2.sct_x, s2.sct_y, player->cnum)); } - return 0; + } + return 0; } diff --git a/src/lib/commands/boar.c b/src/lib/commands/boar.c index 4352cc02c..2df694ea3 100644 --- a/src/lib/commands/boar.c +++ b/src/lib/commands/boar.c @@ -53,135 +53,133 @@ int boar(void) { - struct combat off[1]; /* boarding ship or sector */ - struct combat def[1]; /* defending ship */ - struct emp_qelem olist; /* boarding units */ - struct emp_qelem dlist; /* defending units */ - int ototal; /* total boarding strength */ - int a_engineer = 0; /* boarder engineers are present */ - int a_spy = 0; /* the best boarder scout */ - struct shpstr ship; /* for retreating */ - struct sctstr sect; - struct lndstr land; - struct nstr_item ni; - int foundland; - s_char *p; - s_char buf[1024]; - - att_combat_init(def, EF_SHIP); - /* - * Collect input from the boarder - */ - - /* What are we boarding? */ - - if (!(p = getstarg(player->argp[1], "Victim ship #? ", buf)) || - (def->shp_uid = atoi(p)) < 0) - return RET_SYN; - - /* - * Ask the boarder what he wants to board with - */ - - if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf))) - return RET_SYN; - if (issector(p)) { - att_combat_init(off, EF_SECTOR); - if (!sarg_xy(p, &off->x, &off->y)) - return RET_SYN; - getsect(off->x, off->y, §); - if (sect.sct_own != player->cnum) { - pr("You don't own %s!\n", - xyas(off->x, off->y, player->cnum)); - return RET_SYN; - } - if (sect.sct_mobil <= 0) { - /* Look for land units with mobility */ - snxtitem_xy(&ni, EF_LAND, off->x, off->y); - foundland = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own != player->cnum) - continue; - if (land.lnd_ship >= 0) - continue; - if (land.lnd_mobil <= 0) - continue; - /* Only land units with assault can board */ - if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) - continue; - foundland = 1; - } - if (!foundland) { - pr("You don't have any mobility (sector or land units) in %s!\n", - xyas(off->x, off->y, player->cnum)); - return RET_SYN; - } - } - } else { - att_combat_init(off, EF_SHIP); - if ((off->shp_uid = atoi(p)) < 0) - return RET_SYN; + struct combat off[1]; /* boarding ship or sector */ + struct combat def[1]; /* defending ship */ + struct emp_qelem olist; /* boarding units */ + struct emp_qelem dlist; /* defending units */ + int ototal; /* total boarding strength */ + int a_engineer = 0; /* boarder engineers are present */ + int a_spy = 0; /* the best boarder scout */ + struct shpstr ship; /* for retreating */ + struct sctstr sect; + struct lndstr land; + struct nstr_item ni; + int foundland; + s_char *p; + s_char buf[1024]; + + att_combat_init(def, EF_SHIP); + /* + * Collect input from the boarder + */ + + /* What are we boarding? */ + + if (!(p = getstarg(player->argp[1], "Victim ship #? ", buf)) || + (def->shp_uid = atoi(p)) < 0) + return RET_SYN; + + /* + * Ask the boarder what he wants to board with + */ + + if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf))) + return RET_SYN; + if (issector(p)) { + att_combat_init(off, EF_SECTOR); + if (!sarg_xy(p, &off->x, &off->y)) + return RET_SYN; + getsect(off->x, off->y, §); + if (sect.sct_own != player->cnum) { + pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum)); + return RET_SYN; } - if (att_abort(A_BOARD, off, def)) { - pr("Board aborted\n"); - return RET_OK; + if (sect.sct_mobil <= 0) { + /* Look for land units with mobility */ + snxtitem_xy(&ni, EF_LAND, off->x, off->y); + foundland = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own != player->cnum) + continue; + if (land.lnd_ship >= 0) + continue; + if (land.lnd_mobil <= 0) + continue; + /* Only land units with assault can board */ + if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) + continue; + foundland = 1; + } + if (!foundland) { + pr("You don't have any mobility (sector or land units) in %s!\n", xyas(off->x, off->y, player->cnum)); + return RET_SYN; + } } + } else { + att_combat_init(off, EF_SHIP); + if ((off->shp_uid = atoi(p)) < 0) + return RET_SYN; + } + if (att_abort(A_BOARD, off, def)) { + pr("Board aborted\n"); + return RET_OK; + } - /* Fire at the attacking ship */ + /* Fire at the attacking ship */ - att_approach(off, def); - if (att_abort(A_BOARD, off, def)) { - pr("Board aborted\n"); - att_empty_attack(A_BOARD, 0, def); - return RET_OK; - } + att_approach(off, def); + if (att_abort(A_BOARD, off, def)) { + pr("Board aborted\n"); + att_empty_attack(A_BOARD, 0, def); + return RET_OK; + } - /* Show what we're boarding, and check treaties */ + /* Show what we're boarding, and check treaties */ - if (att_show(def)) - return RET_FAIL; + if (att_show(def)) + return RET_FAIL; - /* Ask the player what he wants to board with */ + /* Ask the player what he wants to board with */ - att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer); - if (att_abort(A_BOARD, off, def)) { - pr("Board aborted\n"); - att_empty_attack(A_BOARD, 0, def); - return att_free_lists(&olist, 0); - } + att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer); + if (att_abort(A_BOARD, off, def)) { + pr("Board aborted\n"); + att_empty_attack(A_BOARD, 0, def); + return att_free_lists(&olist, 0); + } - /* - * Estimate the defense strength and give the player a chance to abort - */ + /* + * Estimate the defense strength and give the player a chance to abort + */ - ototal = att_estimate_defense(A_BOARD, off, &olist, def, a_spy); - if (att_abort(A_BOARD, off, def)) { - pr("Board aborted\n"); - att_empty_attack(A_BOARD, 0, def); - return att_free_lists(&olist, 0); - } + ototal = att_estimate_defense(A_BOARD, off, &olist, def, a_spy); + if (att_abort(A_BOARD, off, def)) { + pr("Board aborted\n"); + att_empty_attack(A_BOARD, 0, def); + return att_free_lists(&olist, 0); + } - /* - * We have now got all the answers from the boarder. From this point - * forward, we can assume that this battle is the _only_ thing - * happening in the game. - */ + /* + * We have now got all the answers from the boarder. From this point + * forward, we can assume that this battle is the _only_ thing + * happening in the game. + */ - /* Get the real defense */ + /* Get the real defense */ - att_get_defense(&olist, def, &dlist, a_spy, ototal); + att_get_defense(&olist, def, &dlist, a_spy, ototal); - /* - * Death, carnage, and destruction. - */ + /* + * Death, carnage, and destruction. + */ - if (!(att_fight(A_BOARD,off,&olist,1.0,def,&dlist,1.0))) { - getship(def->shp_uid, &ship); - if (ship.shp_rflags & RET_BOARDED) { - retreat_ship(&ship, 'u'); - putship(def->shp_uid, &ship); - } + if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) { + getship(def->shp_uid, &ship); + if (ship.shp_rflags & RET_BOARDED) { + retreat_ship(&ship, 'u'); + putship(def->shp_uid, &ship); } + } - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 1e62f4c9a..ceb5951eb 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -54,923 +54,949 @@ #include "damage.h" #include "commands.h" -static void pin_bomb(struct emp_qelem *list, struct sctstr *target); -static void strat_bomb(struct emp_qelem *list, struct sctstr *target); -static void comm_bomb(struct emp_qelem *list, struct sctstr *target); -static void eff_bomb(struct emp_qelem *list, struct sctstr *target); +static void pin_bomb(struct emp_qelem *list, struct sctstr *target); +static void strat_bomb(struct emp_qelem *list, struct sctstr *target); +static void comm_bomb(struct emp_qelem *list, struct sctstr *target); +static void eff_bomb(struct emp_qelem *list, struct sctstr *target); -static void plane_bomb(struct emp_qelem *list, struct sctstr *target); -static void land_bomb(struct emp_qelem *list, struct sctstr *target); -static void ship_bomb(struct emp_qelem *list, struct sctstr *target); -int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from, int flak); +static void plane_bomb(struct emp_qelem *list, struct sctstr *target); +static void land_bomb(struct emp_qelem *list, struct sctstr *target); +static void ship_bomb(struct emp_qelem *list, struct sctstr *target); +int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, + natid from, int flak); static int bombcomm[] = { - I_CIVIL, - I_MILIT, - I_SHELL, - I_GUN, - I_PETROL, - I_IRON, - I_DUST, - I_BAR, - I_FOOD, - I_OIL, - I_LCM, - I_HCM, - I_UW, - I_RAD + I_CIVIL, + I_MILIT, + I_SHELL, + I_GUN, + I_PETROL, + I_IRON, + I_DUST, + I_BAR, + I_FOOD, + I_OIL, + I_LCM, + I_HCM, + I_UW, + I_RAD }; static int nbomb = sizeof(bombcomm) / sizeof(int); int bomb(void) { - s_char *p; - int mission_flags; - int tech; - coord tx, ty; - coord ax, ay; - int ap_to_target; - struct ichrstr *ip; - s_char flightpath[MAX_PATH_LEN]; - struct nstr_item ni_bomb; - struct nstr_item ni_esc; - coord x, y; - struct sctstr target; - struct emp_qelem bomb_list; - struct emp_qelem esc_list; - int wantflags; - struct sctstr ap_sect; - s_char mission; - int rel; - struct natstr *natp; - s_char buf[1024]; - - wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) - return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); - if ((p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0) - return RET_SYN; - mission = *p; - if (index("ps", mission) == 0) - return RET_SYN; - if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0 || *p == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) - return RET_SYN; - if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && - getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { - pr("Assembly point not owned by you or an ally!\n"); - return RET_SYN; - } - ax = x; - ay = y; - if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, - 0, P_FLYING) == 0 || *flightpath == 0) - return RET_SYN; - tx = ax; - ty = ay; - (void) pathtoxy(flightpath, &tx, &ty, fcost); - pr("target sector is %s\n", xyas(tx, ty, player->cnum)); - getsect(tx, ty, &target); - if (target.sct_type == SCT_SANCT) { - pr("You can't bomb that sector!\n"); - return RET_SYN; - } - ip = 0; - ap_to_target = strlen(flightpath); - if (*(flightpath+strlen(flightpath)-1) == 'h') - ap_to_target--; - pr("range to target is %d\n", ap_to_target); - /* - * select planes within range - */ - mission_flags = 0; - pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, - 2, wantflags, P_M|P_O); - pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, - 2, wantflags|P_F|P_ESC, P_M|P_O); - /* - * now arm and equip the bombers, transports, whatever. - * tech is stored in high 16 bits of mission_flags. - * yuck. - */ - tech = 0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - mission_flags = pln_arm(&bomb_list, 2*ap_to_target, mission, ip, 0, mission_flags, &tech); - if (QEMPTY(&bomb_list)) { - pr("No planes could be equipped for the mission.\n"); - return RET_FAIL; - } - mission_flags = pln_arm(&esc_list, 2*ap_to_target, mission, ip,P_F|P_ESC,mission_flags,&tech); - ac_encounter(&bomb_list,&esc_list,ax,ay,flightpath,mission_flags,0,0,0); - if (QEMPTY(&bomb_list)) { - pr("No planes got through fighter defenses\n"); - } else { - switch (mission) { - case 'p': - pin_bomb(&bomb_list, &target); - break; - case 's': - if (opt_SLOW_WAR) { - natp = getnatp(player->cnum); - if (target.sct_own){ - rel = getrel(natp,target.sct_own); - if ((rel != AT_WAR) && (player->cnum != target.sct_own) - && (target.sct_own) && - (target.sct_oldown != player->cnum)){ - pr("You're not at war with them!\n"); - pln_put(&bomb_list); - pln_put(&esc_list); - return RET_FAIL; - } - } - } - nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1); - strat_bomb(&bomb_list, &target); - break; - default: - pr("Bad mission %c\n", mission); - break; + s_char *p; + int mission_flags; + int tech; + coord tx, ty; + coord ax, ay; + int ap_to_target; + struct ichrstr *ip; + s_char flightpath[MAX_PATH_LEN]; + struct nstr_item ni_bomb; + struct nstr_item ni_esc; + coord x, y; + struct sctstr target; + struct emp_qelem bomb_list; + struct emp_qelem esc_list; + int wantflags; + struct sctstr ap_sect; + s_char mission; + int rel; + struct natstr *natp; + s_char buf[1024]; + + wantflags = 0; + if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + return RET_SYN; + if (!snxtitem + (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) + pr("No escorts...\n"); + if ((p = + getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0) + return RET_SYN; + mission = *p; + if (index("ps", mission) == 0) + return RET_SYN; + if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0 + || *p == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) + return RET_SYN; + if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && + getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { + pr("Assembly point not owned by you or an ally!\n"); + return RET_SYN; + } + ax = x; + ay = y; + if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, + 0, P_FLYING) == 0 || *flightpath == 0) + return RET_SYN; + tx = ax; + ty = ay; + (void)pathtoxy(flightpath, &tx, &ty, fcost); + pr("target sector is %s\n", xyas(tx, ty, player->cnum)); + getsect(tx, ty, &target); + if (target.sct_type == SCT_SANCT) { + pr("You can't bomb that sector!\n"); + return RET_SYN; + } + ip = 0; + ap_to_target = strlen(flightpath); + if (*(flightpath + strlen(flightpath) - 1) == 'h') + ap_to_target--; + pr("range to target is %d\n", ap_to_target); + /* + * select planes within range + */ + mission_flags = 0; + pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, + 2, wantflags, P_M | P_O); + pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, + 2, wantflags | P_F | P_ESC, P_M | P_O); + /* + * now arm and equip the bombers, transports, whatever. + * tech is stored in high 16 bits of mission_flags. + * yuck. + */ + tech = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + mission_flags = + pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0, + mission_flags, &tech); + if (QEMPTY(&bomb_list)) { + pr("No planes could be equipped for the mission.\n"); + return RET_FAIL; + } + mission_flags = + pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC, + mission_flags, &tech); + ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, + 0, 0, 0); + if (QEMPTY(&bomb_list)) { + pr("No planes got through fighter defenses\n"); + } else { + switch (mission) { + case 'p': + pin_bomb(&bomb_list, &target); + break; + case 's': + if (opt_SLOW_WAR) { + natp = getnatp(player->cnum); + if (target.sct_own) { + rel = getrel(natp, target.sct_own); + if ((rel != AT_WAR) && (player->cnum != target.sct_own) + && (target.sct_own) && + (target.sct_oldown != player->cnum)) { + pr("You're not at war with them!\n"); + pln_put(&bomb_list); + pln_put(&esc_list); + return RET_FAIL; + } } + } + nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1); + strat_bomb(&bomb_list, &target); + break; + default: + pr("Bad mission %c\n", mission); + break; } - pln_put(&bomb_list); - pln_put(&esc_list); - return RET_OK; + } + pln_put(&bomb_list); + pln_put(&esc_list); + return RET_OK; } static void pin_bomb(struct emp_qelem *list, struct sctstr *target) { - extern s_char *effadv(); - struct dchrstr *dcp; - int nplanes; - int nships; - int type; - int bad; - s_char *p; - int vec[I_MAX+1]; - struct plist *plp; - struct emp_qelem *qp; - int bestacc; - int nsubs; - int nunits; - struct natstr *natp; - int rel; - s_char buf[1024]; - int i; - - bad = 0; - type = target->sct_type; - dcp = &dchr[type]; - pr("Target sector is a %s constructed %s\n", - effadv((int)target->sct_effic), dcp->d_name); - nsubs = 0; - plp = (struct plist *) list->q_forw; - if (plp->pcp->pl_flags & P_A){ - bestacc=0; - for (qp = list->q_forw; qp != list; qp = qp->q_forw) - plp = (struct plist *) qp; - if (plp->plane.pln_acc < bestacc) - bestacc = plp->plane.pln_acc; - nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0); - nsubs = nships - - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); - if (nsubs > 0) - pr("Some subs are present in the sector.\n"); - } else { - nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); + extern s_char *effadv(); + struct dchrstr *dcp; + int nplanes; + int nships; + int type; + int bad; + s_char *p; + int vec[I_MAX + 1]; + struct plist *plp; + struct emp_qelem *qp; + int bestacc; + int nsubs; + int nunits; + struct natstr *natp; + int rel; + s_char buf[1024]; + int i; + + bad = 0; + type = target->sct_type; + dcp = &dchr[type]; + pr("Target sector is a %s constructed %s\n", + effadv((int)target->sct_effic), dcp->d_name); + nsubs = 0; + plp = (struct plist *)list->q_forw; + if (plp->pcp->pl_flags & P_A) { + bestacc = 0; + for (qp = list->q_forw; qp != list; qp = qp->q_forw) + plp = (struct plist *)qp; + if (plp->plane.pln_acc < bestacc) + bestacc = plp->plane.pln_acc; + nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0); + nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); + if (nsubs > 0) + pr("Some subs are present in the sector.\n"); + } else { + nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); + } + nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); + nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0); + getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR); + retry: + p = getstring + ("Bomb what? (ship, plane, land unit, efficiency, commodities) ", + buf); + if (p == 0 || *p == 0) { + if (player->aborted) + return; + bad++; + if (bad > 2) + return; + goto retry; + } + switch (*p) { + case 'l': + if (opt_SLOW_WAR) { + natp = getnatp(player->cnum); + if (target->sct_own) { + rel = getrel(natp, target->sct_own); + if ((rel != AT_WAR) && (player->cnum != target->sct_own) + && (target->sct_own) && + (target->sct_oldown != player->cnum)) { + pr("You're not at war with them!\n"); + goto retry; + } + } } - nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); - nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0); - getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR); -retry: - p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ", buf); - if (p == 0 || *p == 0) { - if (player->aborted) - return; - bad++; - if (bad > 2) - return; - goto retry; + if (nunits == 0) { + pr("no units there\n"); + goto retry; } - switch (*p) { - case 'l': - if (opt_SLOW_WAR) { - natp = getnatp(player->cnum); - if (target->sct_own){ - rel = getrel(natp,target->sct_own); - if ((rel != AT_WAR) && (player->cnum != target->sct_own) - && (target->sct_own) && - (target->sct_oldown != player->cnum)){ - pr("You're not at war with them!\n"); - goto retry; - } - } - } - if (nunits == 0) { - pr("no units there\n"); - goto retry; - } - land_bomb(list, target); - break; - case 'p': - if (opt_SLOW_WAR) { - natp = getnatp(player->cnum); - if (target->sct_own){ - rel = getrel(natp,target->sct_own); - if ((rel != AT_WAR) && (player->cnum != target->sct_own) - && (target->sct_own) && - (target->sct_oldown != player->cnum)){ - pr("You're not at war with them!\n"); - goto retry; - } - } - } - if (nplanes == 0) { - pr("no planes there\n"); - goto retry; + land_bomb(list, target); + break; + case 'p': + if (opt_SLOW_WAR) { + natp = getnatp(player->cnum); + if (target->sct_own) { + rel = getrel(natp, target->sct_own); + if ((rel != AT_WAR) && (player->cnum != target->sct_own) + && (target->sct_own) && + (target->sct_oldown != player->cnum)) { + pr("You're not at war with them!\n"); + goto retry; } - plane_bomb(list, target); - break; - case 's': - if (nships == 0) { - if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A){ - if (nsubs == 0){ - pr("no ships there\n"); - goto retry; - } - }else{ - pr("no ships there\n"); - goto retry; - } + } + } + if (nplanes == 0) { + pr("no planes there\n"); + goto retry; + } + plane_bomb(list, target); + break; + case 's': + if (nships == 0) { + if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) { + if (nsubs == 0) { + pr("no ships there\n"); + goto retry; } - ship_bomb(list, target); - break; - case 'c': - if (opt_SLOW_WAR) { - natp = getnatp(player->cnum); - if (target->sct_own){ - rel = getrel(natp,target->sct_own); - if ((rel != AT_WAR) && (player->cnum != target->sct_own) - && (target->sct_own) && - (target->sct_oldown != player->cnum)){ - pr("You're not at war with them!\n"); - goto retry; - } - } + } else { + pr("no ships there\n"); + goto retry; + } + } + ship_bomb(list, target); + break; + case 'c': + if (opt_SLOW_WAR) { + natp = getnatp(player->cnum); + if (target->sct_own) { + rel = getrel(natp, target->sct_own); + if ((rel != AT_WAR) && (player->cnum != target->sct_own) + && (target->sct_own) && + (target->sct_oldown != player->cnum)) { + pr("You're not at war with them!\n"); + goto retry; } + } + } - for (i = 0; i < nbomb; i++) { - if (!vec[bombcomm[i]]) - continue; - break; - } - if (i >= nbomb) { - pr("No bombable commodities in %s\n", - xyas(target->sct_x, target->sct_y, player->cnum)); + for (i = 0; i < nbomb; i++) { + if (!vec[bombcomm[i]]) + continue; + break; + } + if (i >= nbomb) { + pr("No bombable commodities in %s\n", + xyas(target->sct_x, target->sct_y, player->cnum)); + goto retry; + } + comm_bomb(list, target); + break; + case 'e': + if (opt_SLOW_WAR) { + natp = getnatp(player->cnum); + if (target->sct_own) { + rel = getrel(natp, target->sct_own); + if ((rel != AT_WAR) && (player->cnum != target->sct_own) + && (target->sct_own) && + (target->sct_oldown != player->cnum)) { + pr("You're not at war with them!\n"); goto retry; } - comm_bomb(list, target); - break; - case 'e': - if (opt_SLOW_WAR) { - natp = getnatp(player->cnum); - if (target->sct_own){ - rel = getrel(natp,target->sct_own); - if ((rel != AT_WAR) && (player->cnum != target->sct_own) - && (target->sct_own) && - (target->sct_oldown != player->cnum)){ - pr("You're not at war with them!\n"); - goto retry; - } - } - } - eff_bomb(list, target); - break; - case 'q': - pr("Aborting mission.\n"); - return; - default: - pr("Bad target type.\n"); - goto retry; + } } + eff_bomb(list, target); + break; + case 'q': + pr("Aborting mission.\n"); + return; + default: + pr("Bad target type.\n"); + goto retry; + } } static void eff_bomb(struct emp_qelem *list, struct sctstr *target) { - register struct plist *plp; - struct emp_qelem *qp; - struct sctstr sect; - int oldeff, dam = 0; - int nukedam; - - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *) qp; - if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) - continue; - if (plp->bombs || plp->plane.pln_nuketype != -1) - dam += pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 1); - } - if (dam <= 0) /* dam == 0 if only nukes were delivered */ - return; - getsect(target->sct_x, target->sct_y, §); - target = § - oldeff = target->sct_effic; - target->sct_effic = effdamage(target->sct_effic, dam); - target->sct_road = effdamage(target->sct_road, dam); - target->sct_rail = effdamage(target->sct_rail, dam); - target->sct_defense = effdamage(target->sct_defense, dam); - if (!opt_DEFENSE_INFRA) - target->sct_defense = target->sct_effic; - pr("did %d%% damage to efficiency in %s\n", - oldeff - target->sct_effic, - xyas(target->sct_x, target->sct_y, player->cnum)); - if (target->sct_own) - wu(0, target->sct_own, - "%s bombing raid did %d%% damage in %s\n", - cname(player->cnum), oldeff - target->sct_effic, - xyas(target->sct_x, target->sct_y, target->sct_own)); - if (target->sct_effic < 20) { - if (target->sct_type == SCT_BSPAN) - knockdown(target, list); - else if (target->sct_type == SCT_BTOWER) { - knockdown(target, list); - bridgefall(target, list); - } + register struct plist *plp; + struct emp_qelem *qp; + struct sctstr sect; + int oldeff, dam = 0; + int nukedam; + + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) + continue; + if (plp->bombs || plp->plane.pln_nuketype != -1) + dam += + pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', + &nukedam, 1); + } + if (dam <= 0) /* dam == 0 if only nukes were delivered */ + return; + getsect(target->sct_x, target->sct_y, §); + target = § + oldeff = target->sct_effic; + target->sct_effic = effdamage(target->sct_effic, dam); + target->sct_road = effdamage(target->sct_road, dam); + target->sct_rail = effdamage(target->sct_rail, dam); + target->sct_defense = effdamage(target->sct_defense, dam); + if (!opt_DEFENSE_INFRA) + target->sct_defense = target->sct_effic; + pr("did %d%% damage to efficiency in %s\n", + oldeff - target->sct_effic, + xyas(target->sct_x, target->sct_y, player->cnum)); + if (target->sct_own) + wu(0, target->sct_own, + "%s bombing raid did %d%% damage in %s\n", + cname(player->cnum), oldeff - target->sct_effic, + xyas(target->sct_x, target->sct_y, target->sct_own)); + if (target->sct_effic < 20) { + if (target->sct_type == SCT_BSPAN) + knockdown(target, list); + else if (target->sct_type == SCT_BTOWER) { + knockdown(target, list); + bridgefall(target, list); } - putsect(§); - collateral_damage(target->sct_x, target->sct_y, dam, list); + } + putsect(§); + collateral_damage(target->sct_x, target->sct_y, dam, list); } static void comm_bomb(struct emp_qelem *list, struct sctstr *target) { - register struct plist *plp; - float b; - int i; - int amt, before; - struct ichrstr *ip; - int vec[I_MAX+1]; - struct emp_qelem *qp; - struct sctstr sect; - int dam = 0; - int nukedam; - - getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR); - for (i=0; ii_name); + } + for (;;) { + ip = whatitem((s_char *)0, "commodity to bomb? "); + if (player->aborted) + return; + if (!ip) + continue; + + for (i = 0; i < nbomb; i++) { + if (opt_SUPER_BARS && bombcomm[i] == I_BAR) + continue; + if (&ichr[bombcomm[i]] == ip) + break; + } + if (i == nbomb) { + pr("You can't bomb %s!\n", ip->i_name); + for (i = 0; i < nbomb; i++) { if (opt_SUPER_BARS && bombcomm[i] == I_BAR) - continue; - ip = &ichr[bombcomm[i]]; - pr("some %s\n", ip->i_name); - } - for(;;) { - ip = whatitem((s_char *) 0, "commodity to bomb? "); - if (player->aborted) - return; - if (!ip) - continue; - - for (i=0; ii_name); - for (i=0; iq_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *) qp; - if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) - continue; - if (plp->bombs || plp->plane.pln_nuketype != -1) - dam += pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 1); - } - if (dam <= 0) /* dam == 0 if only nukes were delivered */ - return; - getsect(target->sct_x, target->sct_y, §); - target = § - before = amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR); - putvar(ip->i_vtype, commdamage(amt, dam, ip->i_vtype), (s_char *)target, EF_SECTOR); - amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR); - if (before>0.0) - b = 100.0*(1.0 - ((float)amt/(float)before)); - else - b = 0.0; - pr("did %.2f%% damage to %s in %s\n", - b, ip->i_name, - xyas(target->sct_x, target->sct_y, player->cnum)); - nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1); - if(target->sct_own != 0) + continue; + pr(i == 0 ? "Bombable: " : ", "); + pr(ichr[bombcomm[i]].i_name); + } + pr("\n"); + } else + break; + } + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) + continue; + if (plp->bombs || plp->plane.pln_nuketype != -1) + dam += + pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', + &nukedam, 1); + } + if (dam <= 0) /* dam == 0 if only nukes were delivered */ + return; + getsect(target->sct_x, target->sct_y, §); + target = § + before = amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR); + putvar(ip->i_vtype, commdamage(amt, dam, ip->i_vtype), + (s_char *)target, EF_SECTOR); + amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR); + if (before > 0.0) + b = 100.0 * (1.0 - ((float)amt / (float)before)); + else + b = 0.0; + pr("did %.2f%% damage to %s in %s\n", + b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum)); + nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1); + if (target->sct_own != 0) wu(0, target->sct_own, - "%s precision bombing raid did %.2f%% damage to %s in %s\n", - cname(player->cnum), b, ip->i_name, - xyas(target->sct_x, target->sct_y, target->sct_own)); - putsect(§); - collateral_damage(target->sct_x, target->sct_y, dam, list); + "%s precision bombing raid did %.2f%% damage to %s in %s\n", + cname(player->cnum), b, ip->i_name, + xyas(target->sct_x, target->sct_y, target->sct_own)); + putsect(§); + collateral_damage(target->sct_x, target->sct_y, dam, list); } static void ship_bomb(struct emp_qelem *list, struct sctstr *target) { - struct plist *plp; - int onsea; - struct mchrstr *mcp; - int dam; - s_char *q; - int n; - struct emp_qelem *qp; - int shipno; - int ignore; - struct shpstr ship; - int nships=0; - struct shiplook head, *s, *s2; - s_char buf[1024]; - s_char prompt[128]; - s_char msg[128]; - int hitchance; - int nukedam; - int flak; - int gun; - int shell; - - bzero((s_char *)&head,sizeof(struct shiplook)); + struct plist *plp; + int onsea; + struct mchrstr *mcp; + int dam; + s_char *q; + int n; + struct emp_qelem *qp; + int shipno; + int ignore; + struct shpstr ship; + int nships = 0; + struct shiplook head, *s, *s2; + s_char buf[1024]; + s_char prompt[128]; + s_char msg[128]; + int hitchance; + int nukedam; + int flak; + int gun; + int shell; + + bzero((s_char *)&head, sizeof(struct shiplook)); + head.uid = -1; + onsea = (target->sct_type == SCT_WATER) ? 1 : 0; + for (qp = list->q_forw; qp != list && !player->aborted; + qp = qp->q_forw) { + if (head.uid != -1) { + s = head.next; + while (s != (struct shiplook *)0) { + s2 = s; + s = s->next; + free(s2); + } + } + bzero((s_char *)&head, sizeof(struct shiplook)); head.uid = -1; - onsea = (target->sct_type == SCT_WATER) ? 1 : 0; - for (qp = list->q_forw; qp != list && !player->aborted; qp = qp->q_forw) { - if (head.uid != -1){ - s=head.next; - while (s != (struct shiplook *)0){ - s2=s; - s=s->next; - free(s2); - } - } - bzero((s_char *)&head,sizeof(struct shiplook)); - head.uid = -1; - plp = (struct plist *) qp; - if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) - continue; + plp = (struct plist *)qp; + if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) + continue; + if (plp->pcp->pl_flags & P_A) + nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0, + &plp->plane, &head); + else + nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); + if (nships == 0) { + pr("%s could not find any ships!\n", prplane(&plp->plane)); + continue; + } + (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ", + prplane(&plp->plane), plp->bombs); + ignore = 0; + shipno = -1; + while (shipno < 0 && !player->aborted && !ignore) { + if ((q = getstring(prompt, buf)) == 0 || *q == 0) + continue; + if (*q == '~') { + ignore = 1; + continue; + } + if (*q == '?') { if (plp->pcp->pl_flags & P_A) - nships=asw_shipsatxy(target->sct_x, target->sct_y,0,0, - &plp->plane,&head); + print_found(&head); else - nships=shipsatxy(target->sct_x,target->sct_y,0,M_SUB); - if (nships == 0){ - pr("%s could not find any ships!\n", - prplane(&plp->plane)); - continue; - } - (void) sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ", - prplane(&plp->plane), - plp->bombs); - ignore=0; - shipno = -1; - while (shipno < 0 && !player->aborted && !ignore) { - if ((q = getstring(prompt, buf)) == 0 || *q == 0) - continue; - if (*q == '~'){ - ignore=1; - continue; - } - if (*q == '?') { - if (plp->pcp->pl_flags & P_A) - print_found(&head); - else - shipsatxy(target->sct_x, target->sct_y, - 0, M_SUB); - continue; - } - if (*q == 'd') - goto next; - if (!isdigit(*q)) - continue; - n = atoi(q); - if (n < 0) - continue; - if (getship(n, &ship) && ship.shp_x == target->sct_x && - ship.shp_y == target->sct_y) - shipno = n; - } - if (shipno < 0) - continue; - - shell = gun = 0; - gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim); - if (gun > 0) { - shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP); - if (shell <= 0) - shell = supply_commod(ship.shp_own, ship.shp_x, - ship.shp_y, I_SHELL, 1); - } - mcp = &mchr[(int)ship.shp_type]; - if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) { - flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0); - putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP); - putship(ship.shp_uid, &ship); - sprintf(msg, "Flak! Firing %d guns from ship %s\n", - flak, prship(&ship)); - PR(ship.shp_own, msg); - if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak)) - continue; - } + shipsatxy(target->sct_x, target->sct_y, 0, M_SUB); + continue; + } + if (*q == 'd') + goto next; + if (!isdigit(*q)) + continue; + n = atoi(q); + if (n < 0) + continue; + if (getship(n, &ship) && ship.shp_x == target->sct_x && + ship.shp_y == target->sct_y) + shipno = n; + } + if (shipno < 0) + continue; + + shell = gun = 0; + gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim); + if (gun > 0) { + shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP); + if (shell <= 0) + shell = supply_commod(ship.shp_own, ship.shp_x, + ship.shp_y, I_SHELL, 1); + } + mcp = &mchr[(int)ship.shp_type]; + if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) { + flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0); + putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP); + putship(ship.shp_uid, &ship); + sprintf(msg, "Flak! Firing %d guns from ship %s\n", + flak, prship(&ship)); + PR(ship.shp_own, msg); + if (pinflak_planedamage + (&plp->plane, plp->pcp, ship.shp_own, flak)) + continue; + } - dam = 0; - if (plp->plane.pln_nuketype != -1) - hitchance = 100; - else { - hitchance = pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP); - pr("%d%% hitchance...", hitchance); - } - if (roll(100) <= hitchance) { - /* pinbombing is more accurate than normal bombing */ - dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 1); - } else { - pr("splash\n"); - /* Bombs that miss have to land somewhere! */ - dam = pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', &nukedam, 0); - collateral_damage(target->sct_x, target->sct_y, dam, list); - dam = 0; - } - if (dam <= 0) /* dam == 0 if only nukes were delivered */ - continue; - if (mcp->m_flags & M_SUB) - nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1); - else - nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1); - if (ship.shp_own) { - wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n", - cname(player->cnum), dam, - prship(&ship), - xyas(target->sct_x, target->sct_y, ship.shp_own)); - } - pr("\n"); - check_retreat_and_do_shipdamage(&ship, dam); - if (ship.shp_rflags & RET_BOMBED) - if (((ship.shp_rflags & RET_INJURED) == 0) || !dam) - retreat_ship(&ship,'b'); - putship(ship.shp_uid, &ship); - getship(n, &ship); - if (!ship.shp_own) { - pr("%s at %s sunk!\n", - prship(&ship), - xyas(target->sct_x, target->sct_y, player->cnum)); - } - collateral_damage(target->sct_x, target->sct_y, dam/2, list); -next: - ; - } - s=head.next; - while (s != (struct shiplook *)0){ - s2=s; - s=s->next; - free(s2); + dam = 0; + if (plp->plane.pln_nuketype != -1) + hitchance = 100; + else { + hitchance = + pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP); + pr("%d%% hitchance...", hitchance); + } + if (roll(100) <= hitchance) { + /* pinbombing is more accurate than normal bombing */ + dam = + 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y, + 'p', &nukedam, 1); + } else { + pr("splash\n"); + /* Bombs that miss have to land somewhere! */ + dam = + pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', + &nukedam, 0); + collateral_damage(target->sct_x, target->sct_y, dam, list); + dam = 0; } + if (dam <= 0) /* dam == 0 if only nukes were delivered */ + continue; + if (mcp->m_flags & M_SUB) + nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1); + else + nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1); + if (ship.shp_own) { + wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n", + cname(player->cnum), dam, + prship(&ship), + xyas(target->sct_x, target->sct_y, ship.shp_own)); + } + pr("\n"); + check_retreat_and_do_shipdamage(&ship, dam); + if (ship.shp_rflags & RET_BOMBED) + if (((ship.shp_rflags & RET_INJURED) == 0) || !dam) + retreat_ship(&ship, 'b'); + putship(ship.shp_uid, &ship); + getship(n, &ship); + if (!ship.shp_own) { + pr("%s at %s sunk!\n", + prship(&ship), + xyas(target->sct_x, target->sct_y, player->cnum)); + } + collateral_damage(target->sct_x, target->sct_y, dam / 2, list); + next: + ; + } + s = head.next; + while (s != (struct shiplook *)0) { + s2 = s; + s = s->next; + free(s2); + } } static void plane_bomb(struct emp_qelem *list, struct sctstr *target) { - int dam; - s_char *q; - int n; - natid own; - struct plnstr plane; - struct emp_qelem *qp; - int planeno; - int ignore; - struct plist *plp; - s_char prompt[128]; - s_char buf[1024]; - int hitchance; - int nukedam; - int nplanes; - - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *) qp; - if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) - continue; - nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); - if (nplanes == 0) { - pr("%s could not find any planes!\n", - prplane(&plp->plane)); - continue; - } - (void) sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ", - prplane(&plp->plane), - plp->bombs); - planeno = -1; - ignore=0; - while (planeno < 0 && !player->aborted && !ignore) { - if ((q = getstring(prompt, buf)) == 0 || *q == 0) - continue; - if (*q == '~'){ - ignore=1; - continue; - } - if (*q == '?') { - planesatxy(target->sct_x, target->sct_y, 0, 0, list); - continue; - } - if (*q == 'd') - goto next; - n = atoi(q); - if (n < 0) - continue; - if (getplane(n, &plane) && - plane.pln_x == target->sct_x && - plane.pln_y == target->sct_y && - ((plane.pln_flags & PLN_LAUNCHED) == 0) && - (!ac_isflying(&plane, list))) - planeno = n; - else - pr("Plane #%d not spotted\n", n); - } - if (planeno < 0) - continue; - dam = 0; - if (plp->plane.pln_nuketype != -1) - hitchance = 100; - else { - hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE); - pr("%d%% hitchance...", hitchance); - } - if (roll(100) <= hitchance) { - /* pinbombing is more accurate than normal bombing */ - dam = 2 * pln_damage(&plp->plane,target->sct_x,target->sct_y, 'p', &nukedam, 1); - } else { - pr("thud\n"); - /* Bombs that miss have to land somewhere! */ - dam = pln_damage(&plp->plane,target->sct_x,target->sct_y, 'p', &nukedam, 0); - collateral_damage(target->sct_x, target->sct_y, dam, list); - dam = 0; - } - if (dam <= 0) /* dam == 0 if only nukes were delivered */ - continue; - if (dam > 100) - dam = 100; - own = plane.pln_own; - if (dam > plane.pln_effic) { - plane.pln_effic = 0; - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = 0; - } else - plane.pln_effic -= dam; - plane.pln_mobil = (dam * plane.pln_mobil / 100.0); - if (own == player->cnum) { - pr("%s reports %d%% damage\n", - prplane(&plane), - dam); - } else { - if(own != 0) - wu(0, own, - "%s pinpoint bombing raid did %d%% damage to %s\n", - cname(player->cnum), dam, prplane(&plane)); - } - nreport(player->cnum, N_DOWN_PLANE, own, 1); - if(own != 0) - wu(0, own, "%s bombs did %d%% damage to %s at %s\n", - cname(player->cnum), dam, prplane(&plane), - xyas(target->sct_x, target->sct_y, own)); - putplane(plane.pln_uid, &plane); - collateral_damage(plane.pln_x, plane.pln_y, dam, list); - next: - ; + int dam; + s_char *q; + int n; + natid own; + struct plnstr plane; + struct emp_qelem *qp; + int planeno; + int ignore; + struct plist *plp; + s_char prompt[128]; + s_char buf[1024]; + int hitchance; + int nukedam; + int nplanes; + + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) + continue; + nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list); + if (nplanes == 0) { + pr("%s could not find any planes!\n", prplane(&plp->plane)); + continue; + } + (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ", + prplane(&plp->plane), plp->bombs); + planeno = -1; + ignore = 0; + while (planeno < 0 && !player->aborted && !ignore) { + if ((q = getstring(prompt, buf)) == 0 || *q == 0) + continue; + if (*q == '~') { + ignore = 1; + continue; + } + if (*q == '?') { + planesatxy(target->sct_x, target->sct_y, 0, 0, list); + continue; + } + if (*q == 'd') + goto next; + n = atoi(q); + if (n < 0) + continue; + if (getplane(n, &plane) && + plane.pln_x == target->sct_x && + plane.pln_y == target->sct_y && + ((plane.pln_flags & PLN_LAUNCHED) == 0) && + (!ac_isflying(&plane, list))) + planeno = n; + else + pr("Plane #%d not spotted\n", n); + } + if (planeno < 0) + continue; + dam = 0; + if (plp->plane.pln_nuketype != -1) + hitchance = 100; + else { + hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE); + pr("%d%% hitchance...", hitchance); + } + if (roll(100) <= hitchance) { + /* pinbombing is more accurate than normal bombing */ + dam = + 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y, + 'p', &nukedam, 1); + } else { + pr("thud\n"); + /* Bombs that miss have to land somewhere! */ + dam = + pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', + &nukedam, 0); + collateral_damage(target->sct_x, target->sct_y, dam, list); + dam = 0; + } + if (dam <= 0) /* dam == 0 if only nukes were delivered */ + continue; + if (dam > 100) + dam = 100; + own = plane.pln_own; + if (dam > plane.pln_effic) { + plane.pln_effic = 0; + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, + plane.pln_y); + plane.pln_own = 0; + } else + plane.pln_effic -= dam; + plane.pln_mobil = (dam * plane.pln_mobil / 100.0); + if (own == player->cnum) { + pr("%s reports %d%% damage\n", prplane(&plane), dam); + } else { + if (own != 0) + wu(0, own, + "%s pinpoint bombing raid did %d%% damage to %s\n", + cname(player->cnum), dam, prplane(&plane)); } + nreport(player->cnum, N_DOWN_PLANE, own, 1); + if (own != 0) + wu(0, own, "%s bombs did %d%% damage to %s at %s\n", + cname(player->cnum), dam, prplane(&plane), + xyas(target->sct_x, target->sct_y, own)); + putplane(plane.pln_uid, &plane); + collateral_damage(plane.pln_x, plane.pln_y, dam, list); + next: + ; + } } static void land_bomb(struct emp_qelem *list, struct sctstr *target) { - int dam; - s_char *q; - int n; - natid own; - s_char prompt[128]; - s_char buf[1024]; - s_char msg[128]; - struct lndstr land; - struct lchrstr *lcp; - struct emp_qelem *qp; - int unitno; - int ignore, flak, hitchance; - struct plist *plp; - int nukedam; - int nunits; - - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *) qp; - if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) - continue; - nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0); - if (nunits == 0) { - pr("%s could not find any units!\n", - prplane(&plp->plane)); - continue; - } - (void) sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ", - prplane(&plp->plane), - plp->bombs); - unitno = -1; - ignore = 0; - while (unitno < 0 && !player->aborted && !ignore) { - if ((q = getstring(prompt, buf)) == 0 || *q == 0) - continue; - if (*q == '~') { - ignore=1; - continue; - } - if (*q == '?') { - unitsatxy(target->sct_x, target->sct_y, 0, 0); - continue; - } - if (*q == 'd') - goto next; - n = atoi(q); - if (n < 0) - continue; - if (getland(n, &land) && - land.lnd_x == target->sct_x && - land.lnd_y == target->sct_y) - unitno = n; - else - pr("Unit #%d not spotted\n", n); - } - if (unitno < 0) - continue; - - lcp = &lchr[(int)land.lnd_type]; - - flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0); - if (flak) { - sprintf(msg, "Flak! Firing flak guns from unit %s (aa rating %d)\n", - prland(&land), land.lnd_aaf); - PR(land.lnd_own, msg); - if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak)) - continue; - } - - dam = 0; - if (plp->plane.pln_nuketype != -1) - hitchance = 100; - else { - hitchance = pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND); - pr("%d%% hitchance...", hitchance); - } - if (roll(100) <= hitchance) { - dam = 2 * pln_damage(&plp->plane,target->sct_x,target->sct_y, 'p', &nukedam, 1); - } else { - pr("thud\n"); - /* Bombs that miss have to land somewhere! */ - dam = pln_damage(&plp->plane,target->sct_x,target->sct_y, 'p', &nukedam, 0); - collateral_damage(target->sct_x, target->sct_y, dam, list); - dam = 0; - } - if (dam <= 0) /* dam == 0 if only nukes were delivered */ - continue; - if (dam > 100) - dam = 100; - own = land.lnd_own; - if (own != 0) - mpr(own, - "%s pinpoint bombing raid did %d damage to %s\n", - cname(player->cnum), dam, prland(&land)); - check_retreat_and_do_landdamage(&land, dam); - - if (land.lnd_rflags & RET_BOMBED) - if (((land.lnd_rflags & RET_INJURED) == 0) || !dam) - retreat_land(&land,'b'); - nreport(player->cnum, N_UNIT_BOMB, own, 1); - putland(land.lnd_uid, &land); - collateral_damage(land.lnd_x, land.lnd_y, dam, list); -next: - ; + int dam; + s_char *q; + int n; + natid own; + s_char prompt[128]; + s_char buf[1024]; + s_char msg[128]; + struct lndstr land; + struct lchrstr *lcp; + struct emp_qelem *qp; + int unitno; + int ignore, flak, hitchance; + struct plist *plp; + int nukedam; + int nunits; + + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) + continue; + nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0); + if (nunits == 0) { + pr("%s could not find any units!\n", prplane(&plp->plane)); + continue; + } + (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ", + prplane(&plp->plane), plp->bombs); + unitno = -1; + ignore = 0; + while (unitno < 0 && !player->aborted && !ignore) { + if ((q = getstring(prompt, buf)) == 0 || *q == 0) + continue; + if (*q == '~') { + ignore = 1; + continue; + } + if (*q == '?') { + unitsatxy(target->sct_x, target->sct_y, 0, 0); + continue; + } + if (*q == 'd') + goto next; + n = atoi(q); + if (n < 0) + continue; + if (getland(n, &land) && + land.lnd_x == target->sct_x && land.lnd_y == target->sct_y) + unitno = n; + else + pr("Unit #%d not spotted\n", n); + } + if (unitno < 0) + continue; + + lcp = &lchr[(int)land.lnd_type]; + + flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0); + if (flak) { + sprintf(msg, + "Flak! Firing flak guns from unit %s (aa rating %d)\n", + prland(&land), land.lnd_aaf); + PR(land.lnd_own, msg); + if (pinflak_planedamage + (&plp->plane, plp->pcp, land.lnd_own, flak)) + continue; + } + + dam = 0; + if (plp->plane.pln_nuketype != -1) + hitchance = 100; + else { + hitchance = + pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND); + pr("%d%% hitchance...", hitchance); } + if (roll(100) <= hitchance) { + dam = + 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y, + 'p', &nukedam, 1); + } else { + pr("thud\n"); + /* Bombs that miss have to land somewhere! */ + dam = + pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p', + &nukedam, 0); + collateral_damage(target->sct_x, target->sct_y, dam, list); + dam = 0; + } + if (dam <= 0) /* dam == 0 if only nukes were delivered */ + continue; + if (dam > 100) + dam = 100; + own = land.lnd_own; + if (own != 0) + mpr(own, + "%s pinpoint bombing raid did %d damage to %s\n", + cname(player->cnum), dam, prland(&land)); + check_retreat_and_do_landdamage(&land, dam); + + if (land.lnd_rflags & RET_BOMBED) + if (((land.lnd_rflags & RET_INJURED) == 0) || !dam) + retreat_land(&land, 'b'); + nreport(player->cnum, N_UNIT_BOMB, own, 1); + putland(land.lnd_uid, &land); + collateral_damage(land.lnd_x, land.lnd_y, dam, list); + next: + ; + } } static void strat_bomb(struct emp_qelem *list, struct sctstr *target) { - register struct plist *plp; - int dam = 0; - struct emp_qelem *qp; - struct sctstr sect; - int nukedam; - - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *) qp; - if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) - continue; - if (plp->bombs || plp->plane.pln_nuketype != -1) - dam += pln_damage(&plp->plane, target->sct_x, target->sct_y, 's', &nukedam, 1); - } - if (dam <= 0) /* dam == 0 if only nukes were delivered */ - return; - getsect(target->sct_x, target->sct_y, §); - target = § - if (target->sct_own) - wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n", - cname(player->cnum), PERCENT_DAMAGE(dam), - xyas(target->sct_x, target->sct_y, target->sct_own)); - - sectdamage(target, dam, list); - - pr("did %d damage in %s\n", PERCENT_DAMAGE(dam), - xyas(target->sct_x, target->sct_y, player->cnum)); - putsect(§); + register struct plist *plp; + int dam = 0; + struct emp_qelem *qp; + struct sctstr sect; + int nukedam; + + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T))) + continue; + if (plp->bombs || plp->plane.pln_nuketype != -1) + dam += + pln_damage(&plp->plane, target->sct_x, target->sct_y, 's', + &nukedam, 1); + } + if (dam <= 0) /* dam == 0 if only nukes were delivered */ + return; + getsect(target->sct_x, target->sct_y, §); + target = § + if (target->sct_own) + wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n", + cname(player->cnum), PERCENT_DAMAGE(dam), + xyas(target->sct_x, target->sct_y, target->sct_own)); + + sectdamage(target, dam, list); + + pr("did %d damage in %s\n", PERCENT_DAMAGE(dam), + xyas(target->sct_x, target->sct_y, player->cnum)); + putsect(§); } #define FLAK_MAX 15 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, - 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, }; + 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, +}; int -pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from, int flak) +pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from, + int flak) { - extern double flakscale; - int disp; - s_char dmess[255]; - int eff; - s_char mesg[128]; - struct shpstr ship; - struct lndstr land; - natid plane_owner; - int dam; - float mult; - - flak -= (pp->pln_def+1); - if (pcp->pl_flags & P_X) - flak -= 2; - if (pcp->pl_flags & P_H) - flak -= 1; - if (flak > 8) - mult = lflaktable[FLAK_MAX] * 1.33; - else if (flak < -7) - mult = lflaktable[0] * 0.66; - else { - flak += 7; - mult = lflaktable[flak]; - } - mult *= flakscale; - dam = (int) ((roll(8) + 2) * mult); - if (dam > 100) - dam = 100; - - disp = 0; - plane_owner = pp->pln_own; - eff = pp->pln_effic; - if (dam <= 0) - return 0; - bzero(dmess,255); - eff -= dam; - if (eff < 0) - eff = 0; - if (eff < PLANE_MINEFF) { - sprintf(dmess," -- shot down"); - disp = 1; - } else if (chance((100-eff)/100.0)){ - sprintf(dmess," -- aborted with %d%%%% damage", 100-eff); - disp = 2; - } - sprintf(mesg, " Flak! %s %s takes %d%s.\n", - cname(pp->pln_own), prplane(pp), - dam, dmess); - PR(plane_owner, mesg); - - pp->pln_effic = eff; - if (disp == 1) { - if (from != 0) - nreport(from, N_DOWN_PLANE, pp->pln_own, 1); - if (pp->pln_ship >= 0) { - getship(pp->pln_ship,&ship); - take_plane_off_ship(pp,&ship); - } - if (pp->pln_land >= 0) { - getland(pp->pln_land,&land); - take_plane_off_land(pp,&land); - } - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - putplane(pp->pln_uid, pp); - } else - putplane(pp->pln_uid, pp); - - if (disp > 0) - return 1; + extern double flakscale; + int disp; + s_char dmess[255]; + int eff; + s_char mesg[128]; + struct shpstr ship; + struct lndstr land; + natid plane_owner; + int dam; + float mult; + + flak -= (pp->pln_def + 1); + if (pcp->pl_flags & P_X) + flak -= 2; + if (pcp->pl_flags & P_H) + flak -= 1; + if (flak > 8) + mult = lflaktable[FLAK_MAX] * 1.33; + else if (flak < -7) + mult = lflaktable[0] * 0.66; + else { + flak += 7; + mult = lflaktable[flak]; + } + mult *= flakscale; + dam = (int)((roll(8) + 2) * mult); + if (dam > 100) + dam = 100; + + disp = 0; + plane_owner = pp->pln_own; + eff = pp->pln_effic; + if (dam <= 0) return 0; + bzero(dmess, 255); + eff -= dam; + if (eff < 0) + eff = 0; + if (eff < PLANE_MINEFF) { + sprintf(dmess, " -- shot down"); + disp = 1; + } else if (chance((100 - eff) / 100.0)) { + sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff); + disp = 2; + } + sprintf(mesg, " Flak! %s %s takes %d%s.\n", + cname(pp->pln_own), prplane(pp), dam, dmess); + PR(plane_owner, mesg); + + pp->pln_effic = eff; + if (disp == 1) { + if (from != 0) + nreport(from, N_DOWN_PLANE, pp->pln_own, 1); + if (pp->pln_ship >= 0) { + getship(pp->pln_ship, &ship); + take_plane_off_ship(pp, &ship); + } + if (pp->pln_land >= 0) { + getland(pp->pln_land, &land); + take_plane_off_land(pp, &land); + } + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + pp->pln_own = 0; + putplane(pp->pln_uid, pp); + } else + putplane(pp->pln_uid, pp); + + if (disp > 0) + return 1; + return 0; } diff --git a/src/lib/commands/brea.c b/src/lib/commands/brea.c index fa03cdbb5..e4912470e 100644 --- a/src/lib/commands/brea.c +++ b/src/lib/commands/brea.c @@ -40,17 +40,17 @@ int brea(void) { - struct natstr *natp; + struct natstr *natp; - natp = getnatp(player->cnum); - if ((natp->nat_stat & STAT_SANCT) == 0) { - pr("You aren't in sanctuary!\n"); - return RET_SYN; - } - bsanct(); - natp->nat_stat &= ~STAT_SANCT; - natp->nat_stat |= STAT_NORM; - putnat(natp); - player->nstat |= NORM; - return RET_OK; + natp = getnatp(player->cnum); + if ((natp->nat_stat & STAT_SANCT) == 0) { + pr("You aren't in sanctuary!\n"); + return RET_SYN; + } + bsanct(); + natp->nat_stat &= ~STAT_SANCT; + natp->nat_stat |= STAT_NORM; + putnat(natp); + player->nstat |= NORM; + return RET_OK; } diff --git a/src/lib/commands/budg.c b/src/lib/commands/budg.c index 1f53961f2..0a0d00cee 100644 --- a/src/lib/commands/budg.c +++ b/src/lib/commands/budg.c @@ -58,273 +58,298 @@ #define MIN(x,y) ((x) > (y) ? (y) : (x)) #endif -extern int etu_per_update; -extern double bankint; -extern double money_civ; -extern double money_uw; -extern double money_mil; -extern double obrate, uwbrate; -extern int etu_per_update; -extern double money_res; +extern int etu_per_update; +extern double bankint; +extern double money_civ; +extern double money_uw; +extern double money_mil; +extern double obrate, uwbrate; +extern int etu_per_update; +extern double money_res; s_char *dotsprintf(s_char *buf, s_char *format, int data); int goodsect(char c); void prexpense(long int cash, int *expensesp, s_char priority, int amount); -static void calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars, int *mil, int *ships, int *sbuild, int *nsbuild, int *smaint, int *units, int *lbuild, int *nlbuild, int *lmaint, int *planes, int *pbuild, int *npbuild, int *pmaint); +static void calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, + int *Nuws, int *bars, int *Nbars, int *mil, + int *ships, int *sbuild, int *nsbuild, int *smaint, + int *units, int *lbuild, int *nlbuild, int *lmaint, + int *planes, int *pbuild, int *npbuild, int *pmaint); int budg(void) { - s_char stype=0, *pq; - int priority, x; - long p_sect[SCT_MAXDEF+1][2]; - int taxes=0, bars=0, mil=0; - int Ncivs=0, Nuws=0, Nbars=0; - int n, etu; - int income = 0, expenses = 0; - int sbuild=0,smaint=0,pbuild=0,pmaint=0, ships=0,planes=0; - int nsbuild=0,npbuild=0, which=0; - int lbuild=0,lmaint=0,units=0,nlbuild=0; - struct natstr *np; - s_char buf[1024]; - s_char in[80]; - - bzero((s_char *)p_sect,sizeof(p_sect)); - etu = etu_per_update; - - np=getnatp(player->cnum); - if (player->argp[1] != (s_char *)0){ - if (goodsect(player->argp[1][0])) - stype=player->argp[1][0]; - else switch(player->argp[1][0]){ - case 'P': - case 'S': - case 'L': - case 'A': - case 'M': - case 'N': - case 'C': stype = player->argp[1][0]; break; - default: return RET_SYN; + s_char stype = 0, *pq; + int priority, x; + long p_sect[SCT_MAXDEF + 1][2]; + int taxes = 0, bars = 0, mil = 0; + int Ncivs = 0, Nuws = 0, Nbars = 0; + int n, etu; + int income = 0, expenses = 0; + int sbuild = 0, smaint = 0, pbuild = 0, pmaint = 0, ships = 0, planes = + 0; + int nsbuild = 0, npbuild = 0, which = 0; + int lbuild = 0, lmaint = 0, units = 0, nlbuild = 0; + struct natstr *np; + s_char buf[1024]; + s_char in[80]; + + bzero((s_char *)p_sect, sizeof(p_sect)); + etu = etu_per_update; + + np = getnatp(player->cnum); + if (player->argp[1] != (s_char *)0) { + if (goodsect(player->argp[1][0])) + stype = player->argp[1][0]; + else + switch (player->argp[1][0]) { + case 'P': + case 'S': + case 'L': + case 'A': + case 'M': + case 'N': + case 'C': + stype = player->argp[1][0]; + break; + default: + return RET_SYN; + } + } + if ((stype != 0) && (stype != 'C')) { + pq = getstarg(player->argp[2], "Priority? ", buf); + } else { + pq = (s_char *)0; + } + if (pq != (s_char *)0) { + if (isdigit(*pq)) { + priority = (atoi(pq) < 0 ? -1 * atoi(pq) : atoi(pq)); + if (priority >= SCT_MAXDEF + 8) { + pr("Priorities must be less than %d!\n", SCT_MAXDEF + 8); + return RET_FAIL; + } + for (x = 0; x < SCT_MAXDEF + 8; x++) + if (priority && (np->nat_priorities[x] == priority)) { + pr("Priorities must be unique!\n"); + return RET_FAIL; } - } - if ((stype != 0) && (stype != 'C')) { - pq = getstarg(player->argp[2], "Priority? ", buf); + } else if (*pq == '~') + priority = -1; + else + return RET_SYN; + } + if ((stype) && !player->god) { + if (!isupper(stype)) { + which = 0; + while ((which < SCT_MAXDEF + 2) && + (stype != dchr[which].d_mnem)) + which++; + if (which == SCT_MAXDEF + 2) + return RET_SYN; } else { - pq = (s_char *)0; - } - if (pq != (s_char *)0) { - if (isdigit(*pq)){ - priority=(atoi(pq) < 0 ? -1*atoi(pq) : atoi(pq)); - if (priority >= SCT_MAXDEF+8){ - pr("Priorities must be less than %d!\n", - SCT_MAXDEF+8); - return RET_FAIL; - } - for(x=0;xnat_priorities[x] == priority)){ - pr("Priorities must be unique!\n"); - return RET_FAIL; - } - } else if (*pq == '~') - priority = -1; - else - return RET_SYN; + switch (stype) { + case 'P': + which = PRI_PBUILD; + break; + case 'S': + which = PRI_SBUILD; + break; + case 'L': + which = PRI_LBUILD; + break; + case 'A': + which = PRI_LMAINT; + break; + case 'M': + which = PRI_SMAINT; + break; + case 'N': + which = PRI_PMAINT; + break; + case 'C': + which = (-1); + break; + default: + return RET_SYN; + } } - if ((stype) && !player->god){ - if (!isupper(stype)){ - which=0; - while ((whichnat_priorities[x] = -1; - } - } else { - np->nat_priorities[which] = priority; - } - + if (which == -1) { + for (x = 0; x < SCT_MAXDEF + 8; x++) { + np->nat_priorities[x] = -1; + } + } else { + np->nat_priorities[which] = priority; } - putnat(np); - - player->simulation = 1; - calc_all(p_sect,&taxes,&Ncivs,&Nuws,&bars,&Nbars,&mil,&ships,&sbuild,&nsbuild, - &smaint,&units,&lbuild,&nlbuild,&lmaint,&planes,&pbuild, - &npbuild,&pmaint); - - income = taxes + bars; - pr("Sector Type\t\tAbbr\tProduction\tPriority\t Cost\n"); - for(x=0;xnat_priorities[x] == -1) - continue; - if (!pchr[dchr[x].d_prd].p_cost && - np->nat_priorities[x] == -1 && - x != SCT_ENLIST) { - continue; - } - - pr("%-17s\t%c\t",dchr[x].d_name,dchr[x].d_mnem); - if (x == SCT_ENLIST) - pr("%d mil \t",p_sect[x][0]); - else if (pchr[dchr[x].d_prd].p_cost != 0) - pr("%d %-7s\t",p_sect[x][0], - pchr[dchr[x].d_prd].p_sname); - else pr("\t\t"); - - if (np->nat_priorities[x] != -1){ - pr("%d",np->nat_priorities[x]); - } - pr("\t"); - pr("\t"); - if (np->nat_priorities[x] != 0){ - if ((np->nat_money+income-expenses) > 0){ - pr("%8d",p_sect[x][1]); - expenses += p_sect[x][1]; - } - else - pr("[%7d]",p_sect[x][1]); - }else{ - if ((np->nat_money+income-expenses) > 0) - pr("(%7d)",p_sect[x][1]); - else - pr("[(%7d)]",p_sect[x][1]); - } - pr("\n"); - } + } + putnat(np); - if (lbuild) { - sprintf(buf,"%d unit%s",nlbuild,splur(nlbuild)); - pr("Unit building\t\tL\t%-16s", buf); - if (np->nat_priorities[PRI_LBUILD] != -1) - pr("%d",np->nat_priorities[PRI_LBUILD]); - prexpense(np->nat_money+income, &expenses, np->nat_priorities[PRI_LBUILD], -1*lbuild); - } + player->simulation = 1; + calc_all(p_sect, &taxes, &Ncivs, &Nuws, &bars, &Nbars, &mil, &ships, + &sbuild, &nsbuild, &smaint, &units, &lbuild, &nlbuild, + &lmaint, &planes, &pbuild, &npbuild, &pmaint); - if (lmaint) { - sprintf(buf,"%d unit%s",units,splur(units)); - pr("Unit maintenance\tA\t%-16s",buf); - if (np->nat_priorities[PRI_LMAINT] != -1) - pr("%d",np->nat_priorities[PRI_LMAINT]); - prexpense(np->nat_money+income, &expenses, np->nat_priorities[PRI_LMAINT], -1*lmaint); + income = taxes + bars; + pr("Sector Type\t\tAbbr\tProduction\tPriority\t Cost\n"); + for (x = 0; x < SCT_MAXDEF + 1; x++) { + if (!p_sect[x][1] && np->nat_priorities[x] == -1) + continue; + if (!pchr[dchr[x].d_prd].p_cost && + np->nat_priorities[x] == -1 && x != SCT_ENLIST) { + continue; } - if (sbuild) { - sprintf(buf,"%d ship%s",nsbuild,splur(nsbuild)); - pr("Ship building\t\tS\t%-16s", buf); - if (np->nat_priorities[PRI_SBUILD] != -1) - pr("%d",np->nat_priorities[PRI_SBUILD]); - prexpense(np->nat_money+income, &expenses, np->nat_priorities[PRI_SBUILD], -1*sbuild); - } + pr("%-17s\t%c\t", dchr[x].d_name, dchr[x].d_mnem); + if (x == SCT_ENLIST) + pr("%d mil \t", p_sect[x][0]); + else if (pchr[dchr[x].d_prd].p_cost != 0) + pr("%d %-7s\t", p_sect[x][0], pchr[dchr[x].d_prd].p_sname); + else + pr("\t\t"); - if (smaint) { - sprintf(buf,"%d ship%s",ships,splur(ships)); - pr("Ship maintenance\tM\t%-16s",buf); - if (np->nat_priorities[PRI_SMAINT] != -1) - pr("%d",np->nat_priorities[PRI_SMAINT]); - prexpense(np->nat_money+income, &expenses, np->nat_priorities[PRI_SMAINT], -1*smaint); + if (np->nat_priorities[x] != -1) { + pr("%d", np->nat_priorities[x]); } - - if (pbuild) { - sprintf(buf,"%d plane%s",npbuild,splur(npbuild)); - pr("Plane building\t\tP\t%-16s",buf); - if (np->nat_priorities[PRI_PBUILD] != -1) - pr("%d",np->nat_priorities[PRI_PBUILD]); - prexpense(np->nat_money+income, &expenses, np->nat_priorities[PRI_PBUILD], -1*pbuild); + pr("\t"); + pr("\t"); + if (np->nat_priorities[x] != 0) { + if ((np->nat_money + income - expenses) > 0) { + pr("%8d", p_sect[x][1]); + expenses += p_sect[x][1]; + } else + pr("[%7d]", p_sect[x][1]); + } else { + if ((np->nat_money + income - expenses) > 0) + pr("(%7d)", p_sect[x][1]); + else + pr("[(%7d)]", p_sect[x][1]); } - if (pmaint) { - sprintf(buf,"%d plane%s",planes,splur(planes)); - pr("Plane maintenance\tN\t%-16s",buf); - if (np->nat_priorities[PRI_PMAINT] != -1) - pr("%d",np->nat_priorities[PRI_PMAINT]); - prexpense(np->nat_money+income, &expenses, np->nat_priorities[PRI_PMAINT], -1*pmaint); - } - if (p_sect[SCT_EFFIC][1]) { - pr("Sector building\t\t\t\t%8d sct(s)\t\t%8d\n",p_sect[SCT_EFFIC][0], p_sect[SCT_EFFIC][1]); - expenses += p_sect[SCT_EFFIC][1]; - } - if (mil) { - - n = (mil - np->nat_reserve * money_res * etu)/(etu*money_mil); - sprintf(in, "%d mil, %d res", n, (int)np->nat_reserve); - pr("Military payroll\t\t%-32s%8d\n", - in, -mil); - expenses -= mil; - } - if (p_sect[SCT_CAPIT][0]) { - n = p_sect[SCT_CAPIT][0]; - sprintf(in, "%d %s", - n, - n==1?opt_BIG_CITY?"city":"capital":opt_BIG_CITY?"cities":"capitals"); - pr("%s maintenance\t\t%-32s%8d\n", - opt_BIG_CITY?"City":"Capital", - in, - p_sect[SCT_CAPIT][1]); - expenses += p_sect[SCT_CAPIT][1]; - } - pr("Total expenses%s\n", dotsprintf(buf,"%58d", expenses)); - if (taxes) { - sprintf(in, "%d civ%s, %d uw%s", - Ncivs,splur(Ncivs), - Nuws,splur(Nuws)); - pr("Income from taxes\t\t%-32s%+8d\n", - in, - taxes); - } - if (bars) { - sprintf(in, "%d bar%s", Nbars, splur(Nbars)); - pr("Income from bars\t\t%-32s%+8d\n", - in, - bars); - } - pr("Total income%s\n", dotsprintf(buf,"%+60d", income)); - pr("Balance forward\t\t\t\t\t\t %10d\n", np->nat_money); - pr("Estimated delta\t\t\t\t\t\t %+10d\n",income-expenses); - pr("Estimated new treasury%s\n",dotsprintf(buf,"%50d",np->nat_money+income-expenses)); - if (((np->nat_money+income-expenses) < 0) && !player->god){ - pr("After processsing sectors, you will be broke!\n"); - pr("Sectors will not produce, distribute, or deliver!\n\n"); - } + pr("\n"); + } + + if (lbuild) { + sprintf(buf, "%d unit%s", nlbuild, splur(nlbuild)); + pr("Unit building\t\tL\t%-16s", buf); + if (np->nat_priorities[PRI_LBUILD] != -1) + pr("%d", np->nat_priorities[PRI_LBUILD]); + prexpense(np->nat_money + income, &expenses, + np->nat_priorities[PRI_LBUILD], -1 * lbuild); + } + + if (lmaint) { + sprintf(buf, "%d unit%s", units, splur(units)); + pr("Unit maintenance\tA\t%-16s", buf); + if (np->nat_priorities[PRI_LMAINT] != -1) + pr("%d", np->nat_priorities[PRI_LMAINT]); + prexpense(np->nat_money + income, &expenses, + np->nat_priorities[PRI_LMAINT], -1 * lmaint); + } + + if (sbuild) { + sprintf(buf, "%d ship%s", nsbuild, splur(nsbuild)); + pr("Ship building\t\tS\t%-16s", buf); + if (np->nat_priorities[PRI_SBUILD] != -1) + pr("%d", np->nat_priorities[PRI_SBUILD]); + prexpense(np->nat_money + income, &expenses, + np->nat_priorities[PRI_SBUILD], -1 * sbuild); + } + + if (smaint) { + sprintf(buf, "%d ship%s", ships, splur(ships)); + pr("Ship maintenance\tM\t%-16s", buf); + if (np->nat_priorities[PRI_SMAINT] != -1) + pr("%d", np->nat_priorities[PRI_SMAINT]); + prexpense(np->nat_money + income, &expenses, + np->nat_priorities[PRI_SMAINT], -1 * smaint); + } + + if (pbuild) { + sprintf(buf, "%d plane%s", npbuild, splur(npbuild)); + pr("Plane building\t\tP\t%-16s", buf); + if (np->nat_priorities[PRI_PBUILD] != -1) + pr("%d", np->nat_priorities[PRI_PBUILD]); + prexpense(np->nat_money + income, &expenses, + np->nat_priorities[PRI_PBUILD], -1 * pbuild); + } + + if (pmaint) { + sprintf(buf, "%d plane%s", planes, splur(planes)); + pr("Plane maintenance\tN\t%-16s", buf); + if (np->nat_priorities[PRI_PMAINT] != -1) + pr("%d", np->nat_priorities[PRI_PMAINT]); + prexpense(np->nat_money + income, &expenses, + np->nat_priorities[PRI_PMAINT], -1 * pmaint); + } + if (p_sect[SCT_EFFIC][1]) { + pr("Sector building\t\t\t\t%8d sct(s)\t\t%8d\n", + p_sect[SCT_EFFIC][0], p_sect[SCT_EFFIC][1]); + expenses += p_sect[SCT_EFFIC][1]; + } + if (mil) { - player->simulation = 0; - return RET_OK; + n = (mil - np->nat_reserve * money_res * etu) / (etu * money_mil); + sprintf(in, "%d mil, %d res", n, (int)np->nat_reserve); + pr("Military payroll\t\t%-32s%8d\n", in, -mil); + expenses -= mil; + } + if (p_sect[SCT_CAPIT][0]) { + n = p_sect[SCT_CAPIT][0]; + sprintf(in, "%d %s", + n, + n == + 1 ? opt_BIG_CITY ? "city" : "capital" : opt_BIG_CITY ? + "cities" : "capitals"); + pr("%s maintenance\t\t%-32s%8d\n", + opt_BIG_CITY ? "City" : "Capital", in, p_sect[SCT_CAPIT][1]); + expenses += p_sect[SCT_CAPIT][1]; + } + pr("Total expenses%s\n", dotsprintf(buf, "%58d", expenses)); + if (taxes) { + sprintf(in, "%d civ%s, %d uw%s", + Ncivs, splur(Ncivs), Nuws, splur(Nuws)); + pr("Income from taxes\t\t%-32s%+8d\n", in, taxes); + } + if (bars) { + sprintf(in, "%d bar%s", Nbars, splur(Nbars)); + pr("Income from bars\t\t%-32s%+8d\n", in, bars); + } + pr("Total income%s\n", dotsprintf(buf, "%+60d", income)); + pr("Balance forward\t\t\t\t\t\t %10d\n", np->nat_money); + pr("Estimated delta\t\t\t\t\t\t %+10d\n", income - expenses); + pr("Estimated new treasury%s\n", + dotsprintf(buf, "%50d", np->nat_money + income - expenses)); + if (((np->nat_money + income - expenses) < 0) && !player->god) { + pr("After processsing sectors, you will be broke!\n"); + pr("Sectors will not produce, distribute, or deliver!\n\n"); + } + + player->simulation = 0; + return RET_OK; } static void -calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, int *bars, int *Nbars, int *mil, int *ships, int *sbuild, int *nsbuild, int *smaint, int *units, int *lbuild, int *nlbuild, int *lmaint, int *planes, int *pbuild, int *npbuild, int *pmaint) +calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, + int *bars, int *Nbars, int *mil, int *ships, int *sbuild, + int *nsbuild, int *smaint, int *units, int *lbuild, int *nlbuild, + int *lmaint, int *planes, int *pbuild, int *npbuild, int *pmaint) { - register int y,z; - struct natstr *np; - int sm=0,sb=0,pm=0,pb=0,lm=0,lb=0; - int *bp; - long pop = 0; - int n, civ_tax, uw_tax, mil_pay; + register int y, z; + struct natstr *np; + int sm = 0, sb = 0, pm = 0, pb = 0, lm = 0, lb = 0; + int *bp; + long pop = 0; + int n, civ_tax, uw_tax, mil_pay; struct sctstr *sp; - int etu=etu_per_update; - int vec[I_MAX+1]; - long tmp_money; + int etu = etu_per_update; + int vec[I_MAX + 1]; + long tmp_money; extern long sea_money[MAXNOC]; extern long lnd_money[MAXNOC]; extern long air_money[MAXNOC]; extern long tpops[MAXNOC]; extern int mil_dbl_pay; - + lnd_money[player->cnum] = sea_money[player->cnum] = 0; air_money[player->cnum] = 0; mil_dbl_pay = 0; @@ -332,7 +357,7 @@ calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, int *bars, in *Ncivs = 0; np = getnatp(player->cnum); bp = (int *)calloc(WORLD_X * WORLD_Y * 8, sizeof(int)); - for (n=0; NULL != (sp = getsectid(n)) ;n++){ + for (n = 0; NULL != (sp = getsectid(n)); n++) { fill_update_array(bp, sp); if (sp->sct_own == player->cnum) { sp->sct_updated = 0; @@ -349,90 +374,90 @@ calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, int *bars, in } } tpops[player->cnum] = pop; - *mil += (int) (np->nat_reserve * money_res * etu); - - *mil += (int) upd_slmilcosts(np->nat_cnum, etu); - - for(y=1;ynat_reserve * money_res * etu); + + *mil += (int)upd_slmilcosts(np->nat_cnum, etu); + + for (y = 1; y < SCT_MAXDEF + 8; y++) { + for (z = 0; z < SCT_MAXDEF + 8; z++) if (np->nat_priorities[z] == y) - switch(z){ + switch (z) { case PRI_SMAINT: tmp_money = lnd_money[player->cnum]; - *ships=prod_ship(etu, player->cnum,bp,0); + *ships = prod_ship(etu, player->cnum, bp, 0); *smaint = lnd_money[player->cnum] - tmp_money; - sm=1; + sm = 1; break; case PRI_SBUILD: tmp_money = sea_money[player->cnum]; - *nsbuild=prod_ship(etu, player->cnum,bp,1); + *nsbuild = prod_ship(etu, player->cnum, bp, 1); *sbuild = sea_money[player->cnum] - tmp_money; - sb=1; + sb = 1; break; case PRI_LMAINT: tmp_money = lnd_money[player->cnum]; - *units=prod_land(etu, player->cnum,bp,0); + *units = prod_land(etu, player->cnum, bp, 0); *lmaint = lnd_money[player->cnum] - tmp_money; - lm=1; + lm = 1; break; case PRI_LBUILD: tmp_money = lnd_money[player->cnum]; - *nlbuild=prod_land(etu, player->cnum,bp,1); + *nlbuild = prod_land(etu, player->cnum, bp, 1); *lbuild = lnd_money[player->cnum] - tmp_money; - lb=1; + lb = 1; break; case PRI_PMAINT: tmp_money = air_money[player->cnum]; - *planes=prod_plane(etu, player->cnum,bp,0); + *planes = prod_plane(etu, player->cnum, bp, 0); *pmaint = air_money[player->cnum] - tmp_money; - pm=1; + pm = 1; break; case PRI_PBUILD: tmp_money = air_money[player->cnum]; - *npbuild=prod_plane(etu, player->cnum,bp,1); + *npbuild = prod_plane(etu, player->cnum, bp, 1); *pbuild = air_money[player->cnum] - tmp_money; - pb=1; + pb = 1; break; default: - produce_sect(player->cnum,etu,bp,p_sect,z); + produce_sect(player->cnum, etu, bp, p_sect, z); break; } } /* 0 is maintain, 1 is build */ if (!sm) { tmp_money = sea_money[player->cnum]; - *ships=prod_ship(etu,player->cnum,bp,0); + *ships = prod_ship(etu, player->cnum, bp, 0); *smaint = sea_money[player->cnum] - tmp_money; } if (!sb) { tmp_money = sea_money[player->cnum]; - *nsbuild=prod_ship(etu,player->cnum,bp,1); + *nsbuild = prod_ship(etu, player->cnum, bp, 1); *sbuild = sea_money[player->cnum] - tmp_money; } if (!lm) { tmp_money = lnd_money[player->cnum]; - *units=prod_land(etu,player->cnum,bp,0); + *units = prod_land(etu, player->cnum, bp, 0); *lmaint = lnd_money[player->cnum] - tmp_money; } if (!lb) { tmp_money = lnd_money[player->cnum]; - *nlbuild=prod_land(etu,player->cnum,bp,1); + *nlbuild = prod_land(etu, player->cnum, bp, 1); *lbuild = lnd_money[player->cnum] - tmp_money; } if (!pm) { tmp_money = air_money[player->cnum]; - *planes=prod_plane(etu,player->cnum,bp,0); + *planes = prod_plane(etu, player->cnum, bp, 0); *pmaint = air_money[player->cnum] - tmp_money; } if (!pb) { tmp_money = air_money[player->cnum]; - *npbuild=prod_plane(etu,player->cnum,bp,1); + *npbuild = prod_plane(etu, player->cnum, bp, 1); *pbuild = air_money[player->cnum] - tmp_money; } - + /* produce all sects that haven't produced yet */ - produce_sect(player->cnum,etu,bp,p_sect,-1); - + produce_sect(player->cnum, etu, bp, p_sect, -1); + lnd_money[player->cnum] = sea_money[player->cnum] = 0; air_money[player->cnum] = 0; free(bp); @@ -441,37 +466,36 @@ calc_all(long int (*p_sect)[2], int *taxes, int *Ncivs, int *Nuws, int *bars, in int goodsect(char c) { - register int x; + register int x; - for(x=4;x *expensesp) { - if (priority) { - pr("\t\t%8d\n",amount); - *expensesp += amount; - } else - pr("\t\t(%7d)\n",amount); - } else { - if (priority) { - pr("\t\t[%7d]\n", amount); - *expensesp += amount; - } else - pr("\t\t[(%6d)]\n", amount); - } + if (cash > *expensesp) { + if (priority) { + pr("\t\t%8d\n", amount); + *expensesp += amount; + } else + pr("\t\t(%7d)\n", amount); + } else { + if (priority) { + pr("\t\t[%7d]\n", amount); + *expensesp += amount; + } else + pr("\t\t[(%6d)]\n", amount); + } } - diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index 257593ed4..23e11fa7a 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -53,14 +53,21 @@ #include "optlist.h" #include "commands.h" -static int build_nuke(register struct sctstr *sp, register struct nchrstr *np, register int *vec); -static int build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int *vec, int tlev); -static int build_land(register struct sctstr *sp, register struct lchrstr *lp, register int *vec, int tlev); -static int build_bridge(register struct sctstr *sp, register int *vec); -static int build_tower(register struct sctstr *sp, register int *vec); -static int build_plane(register struct sctstr *sp, register struct plchrstr *pp, register int *vec, int tlev); +static int build_nuke(register struct sctstr *sp, + register struct nchrstr *np, register int *vec); +static int build_ship(register struct sctstr *sp, + register struct mchrstr *mp, register int *vec, + int tlev); +static int build_land(register struct sctstr *sp, + register struct lchrstr *lp, register int *vec, + int tlev); +static int build_bridge(register struct sctstr *sp, register int *vec); +static int build_tower(register struct sctstr *sp, register int *vec); +static int build_plane(register struct sctstr *sp, + register struct plchrstr *pp, register int *vec, + int tlev); -static int cash; /* static ok */ +static int cash; /* static ok */ double sqrt(double); double logx(); @@ -75,58 +82,62 @@ extern int etu_per_update; int buil(void) { - extern double buil_bt; - extern double buil_tower_bt; - struct sctstr sect; - struct nstr_sect nstr; - struct natstr *natp; - int rqtech; - int tlev; - int rlev; - int n; - int type; - int what; - struct lchrstr *lp; - struct mchrstr *mp; - struct plchrstr *pp; - struct nchrstr *np; - s_char *p; - int vec[I_MAX+1]; - int gotsect = 0; - int built; - int hold, found, number=1, x; - extern float drnuke_const; - int asked = 0; - s_char buf[1024]; - + extern double buil_bt; + extern double buil_tower_bt; + struct sctstr sect; + struct nstr_sect nstr; + struct natstr *natp; + int rqtech; + int tlev; + int rlev; + int n; + int type; + int what; + struct lchrstr *lp; + struct mchrstr *mp; + struct plchrstr *pp; + struct nchrstr *np; + s_char *p; + int vec[I_MAX + 1]; + int gotsect = 0; + int built; + int hold, found, number = 1, x; + extern float drnuke_const; + int asked = 0; + s_char buf[1024]; + natp = getnatp(player->cnum); - if ((p = getstarg(player->argp[1], "Build (ship, nuke, bridge, plane, land unit, tower)? ", buf)) == 0) + if ((p = + getstarg(player->argp[1], + "Build (ship, nuke, bridge, plane, land unit, tower)? ", + buf)) == 0) return RET_SYN; what = *p; - - for(x= 0 ; x < number; x++) { + + for (x = 0; x < number; x++) { if (!snxtsct(&nstr, player->argp[2])) { pr("Bad sector specification.\n"); return RET_SYN; } -ask_again: - tlev = (int) natp->nat_level[NAT_TLEV]; - rlev = (int) natp->nat_level[NAT_RLEV]; - + ask_again: + tlev = (int)natp->nat_level[NAT_TLEV]; + rlev = (int)natp->nat_level[NAT_RLEV]; + switch (what) { case 'p': p = getstarg(player->argp[3], "Plane type? ", buf); if (p == 0 || *p == 0) return RET_SYN; n = strlen(p); - while (n && iscntrl(p[n-1])) - n--; - if ( !n ) - return RET_SYN; - for (found=0,type=0,pp=plchr; type <= pln_maxno; type++,pp++) { + while (n && iscntrl(p[n - 1])) + n--; + if (!n) + return RET_SYN; + for (found = 0, type = 0, pp = plchr; type <= pln_maxno; + type++, pp++) { if (pp->pl_tech > tlev) continue; - if(pp->pl_name && strncmp(p, pp->pl_name, n) == 0) { + if (pp->pl_name && strncmp(p, pp->pl_name, n) == 0) { found++; hold = type; break; @@ -135,7 +146,7 @@ ask_again: if (found != 1) { pr("Illegal plane type: \"%s\"\n", p); if (confirm("List plane types? ")) - show_plane_build (tlev); + show_plane_build(tlev); player->argp[3] = 0; goto ask_again; } @@ -148,17 +159,18 @@ ask_again: if (p == 0 || *p == 0) return RET_SYN; n = strlen(p); - while (n && iscntrl(p[n-1])) - n--; - if ( !n ) - return RET_SYN; - for (found=0,mp=mchr,type=0; type <= shp_maxno; type++, mp++) { + while (n && iscntrl(p[n - 1])) + n--; + if (!n) + return RET_SYN; + for (found = 0, mp = mchr, type = 0; type <= shp_maxno; + type++, mp++) { if (mp->m_tech > tlev) continue; /* Can't build trade ships unless it's turned on */ if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) continue; - if(mp->m_name && strncmp(p, mp->m_name, n) == 0) { + if (mp->m_name && strncmp(p, mp->m_name, n) == 0) { found++; hold = type; break; @@ -167,7 +179,7 @@ ask_again: if (found != 1) { pr("Illegal ship type: \"%s\"\n", p); if (confirm("List ship types? ")) - show_ship_build (tlev); + show_ship_build(tlev); player->argp[3] = 0; goto ask_again; } @@ -180,16 +192,17 @@ ask_again: if (p == 0 || *p == 0) return RET_SYN; n = strlen(p); - while (n && iscntrl(p[n-1])) - n--; - if ( !n ) - return RET_SYN; - for (found=0,lp=lchr,type=0; type <= lnd_maxno; type++, lp++) { + while (n && iscntrl(p[n - 1])) + n--; + if (!n) + return RET_SYN; + for (found = 0, lp = lchr, type = 0; type <= lnd_maxno; + type++, lp++) { if (lp->l_tech > tlev) continue; if ((lp->l_flags & L_SPY) && !opt_LANDSPIES) continue; - if(lp->l_name && strncmp(p, lp->l_name, n) == 0) { + if (lp->l_name && strncmp(p, lp->l_name, n) == 0) { found++; hold = type; break; @@ -198,7 +211,7 @@ ask_again: if (found != 1) { pr("Illegal land unit type: \"%s\"\n", p); if (confirm("List unit types? ")) - show_land_build (tlev); + show_land_build(tlev); player->argp[3] = 0; goto ask_again; } @@ -207,9 +220,8 @@ ask_again: rqtech = lp->l_tech; break; case 'b': - if (natp->nat_level[NAT_TLEV]+0.005 < buil_bt) { - pr("Building a span requires a tech of %.0f\n", - buil_bt); + if (natp->nat_level[NAT_TLEV] + 0.005 < buil_bt) { + pr("Building a span requires a tech of %.0f\n", buil_bt); return 2; } break; @@ -218,45 +230,47 @@ ask_again: pr("Bridge tower building is disabled.\n"); return RET_FAIL; } - if (natp->nat_level[NAT_TLEV]+0.005 < buil_tower_bt) { + if (natp->nat_level[NAT_TLEV] + 0.005 < buil_tower_bt) { pr("Building a tower requires a tech of %.0f\n", buil_tower_bt); return 2; } break; case 'n': - if (opt_NONUKES) { - pr("There are no nukes in this game.\n"); + if (opt_NONUKES) { + pr("There are no nukes in this game.\n"); return RET_FAIL; } p = getstarg(player->argp[3], "Nuke type? ", buf); if (p == 0 || *p == 0) return RET_SYN; n = strlen(p); - while (n && iscntrl(p[n-1])) - n--; - if ( !n ) - return RET_SYN; - for (found=0,np=nchr,type=0; type < nuk_maxno; type++, np++) { - if ((np->n_tech > tlev) || - (opt_DRNUKE && ((np->n_tech*drnuke_const) > rlev))) + while (n && iscntrl(p[n - 1])) + n--; + if (!n) + return RET_SYN; + for (found = 0, np = nchr, type = 0; type < nuk_maxno; + type++, np++) { + if ((np->n_tech > tlev) + || (opt_DRNUKE + && ((np->n_tech * drnuke_const) > rlev))) continue; if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT)) continue; - - if(np->n_name && strncmp(p, np->n_name, n) == 0) { + + if (np->n_name && strncmp(p, np->n_name, n) == 0) { found++; hold = type; break; } } if (found != 1) { - int tt = tlev; + int tt = tlev; pr("Possible nuke types are:\n"); - if (opt_DRNUKE) - tt = (tlev < (rlev/drnuke_const) ? (int)tlev : - (int)(rlev/drnuke_const)); - + if (opt_DRNUKE) + tt = (tlev < (rlev / drnuke_const) ? (int)tlev : + (int)(rlev / drnuke_const)); + show_nuke_build(tt); player->argp[3] = 0; goto ask_again; @@ -274,12 +288,14 @@ ask_again: if (atoi(player->argp[4]) > 20 && !asked) { s_char bstr[80]; asked = 1; - (void) sprintf(bstr,"Are you sure that you want to build %s of them? ", player->argp[4]); + (void)sprintf(bstr, + "Are you sure that you want to build %s of them? ", + player->argp[4]); p = getstarg(player->argp[6], bstr, buf); if (p == 0 || *p != 'y') return RET_SYN; } - number=atoi(player->argp[4]); + number = atoi(player->argp[4]); } } if (what != 'b' && what != 'n' && what != 't') { @@ -291,7 +307,7 @@ ask_again: return RET_FAIL; } if (rqtech > tlev) { - pr("Required tech is %d.\n",rqtech); + pr("Required tech is %d.\n", rqtech); return RET_FAIL; } pr("building with tech level %d.\n", tlev); @@ -340,20 +356,21 @@ ask_again: } static int -build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int *vec, int tlev) +build_ship(register struct sctstr *sp, register struct mchrstr *mp, + register int *vec, int tlev) { - struct shpstr ship; - struct nstr_item nstr; - int cost, i; - int w_p_eff,x; - float eff=((float)SHIP_MINEFF/100.0); - int points, lcm, hcm; - int freeship = 0; + struct shpstr ship; + struct nstr_item nstr; + int cost, i; + int w_p_eff, x; + float eff = ((float)SHIP_MINEFF / 100.0); + int points, lcm, hcm; + int freeship = 0; int techdiff; - + hcm = roundavg(((double)mp->m_hcm * (double)eff)); lcm = roundavg(((double)mp->m_lcm * (double)eff)); - + if (sp->sct_type != SCT_HARBR) { pr("Ships must be built in harbours.\n"); return 0; @@ -374,7 +391,7 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int pr("Not enough available work in %s to build a %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum), mp->m_name); pr(" (%d available work required)\n", - 1 + (w_p_eff * SHIP_MINEFF)/100); + 1 + (w_p_eff * SHIP_MINEFF) / 100); return 0; } cost = mp->m_cost * eff; @@ -397,9 +414,9 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int } } if (freeship == 0) { - ef_extend(EF_SHIP, 50); + ef_extend(EF_SHIP, 50); } - bzero(&ship, sizeof(struct shpstr)); + bzero(&ship, sizeof(struct shpstr)); ship.shp_x = sp->sct_x; ship.shp_y = sp->sct_y; ship.shp_destx[0] = sp->sct_x; @@ -408,11 +425,11 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int ship.shp_desty[1] = sp->sct_y; ship.shp_autonav = 0; /* new code for autonav, Chad Zabel 1-15-94 */ - for (i=0;icnum; @@ -450,15 +467,16 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int ship.shp_orig_y = sp->sct_y; ship.shp_fuel = mchr[(int)ship.shp_type].m_fuelc; ship.shp_rflags = 0; - for(x=0;x<10;x++) - ship.shp_rpath[x]=0; - + for (x = 0; x < 10; x++) + ship.shp_rpath[x] = 0; + vec[I_LCM] -= lcm; vec[I_HCM] -= hcm; - + if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT) putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP); - makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x, ship.shp_y); + makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x, + ship.shp_y); putship(ship.shp_uid, &ship); pr("%s", prship(&ship)); pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); @@ -466,94 +484,95 @@ build_ship(register struct sctstr *sp, register struct mchrstr *mp, register int } static int -build_land(register struct sctstr *sp, register struct lchrstr *lp, register int *vec, int tlev) +build_land(register struct sctstr *sp, register struct lchrstr *lp, + register int *vec, int tlev) { - struct lndstr land; - struct nstr_item nstr; - int cost; - int w_p_eff; - int points; - struct natstr *natp; - float eff=((float)LAND_MINEFF/100.0); - double techfact(int, double); - int mil, lcm, hcm, gun, shell; - int freeland = 0; - + struct lndstr land; + struct nstr_item nstr; + int cost; + int w_p_eff; + int points; + struct natstr *natp; + float eff = ((float)LAND_MINEFF / 100.0); + double techfact(int, double); + int mil, lcm, hcm, gun, shell; + int freeland = 0; + /* mil = roundavg(((double)lp->l_mil * (double)eff)); shell = roundavg(((double)lp->l_shell * (double)eff)); - gun = roundavg(((double)lp->l_gun * (double)eff)); - */ + gun = roundavg(((double)lp->l_gun * (double)eff)); + */ mil = shell = gun = 0; hcm = roundavg(((double)lp->l_hcm * (double)eff)); lcm = roundavg(((double)lp->l_lcm * (double)eff)); - + natp = getnatp(player->cnum); - + if (sp->sct_type != SCT_HEADQ) { - pr("Land Units must be built in headquarters.\n"); - return 0; + pr("Land Units must be built in headquarters.\n"); + return 0; } if (sp->sct_effic < 60 && !player->god) { - pr("Sector %s is not 60%% efficient.\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + pr("Sector %s is not 60%% efficient.\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) { - pr("Not enough materials in %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + pr("Not enough materials in %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } #if 0 - if (vec[I_GUN] < gun || vec[I_GUN] == 0){ - pr("Not enough guns in %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + if (vec[I_GUN] < gun || vec[I_GUN] == 0) { + pr("Not enough guns in %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } - if (vec[I_SHELL] < shell){ - pr("Not enough shells in %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + if (vec[I_SHELL] < shell) { + pr("Not enough shells in %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } - if (vec[I_MILIT] < mil){ - pr("Not enough military in %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + if (vec[I_MILIT] < mil) { + pr("Not enough military in %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } #endif if (!trechk(player->cnum, 0, NEWLND)) - return 0; + return 0; if (!check_sect_ok(sp)) - return 0; + return 0; w_p_eff = (20 + lp->l_lcm + (lp->l_hcm * 2)); points = sp->sct_avail * 100 / w_p_eff; if (points < LAND_MINEFF) { - pr("Not enough available work in %s to build a %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * LAND_MINEFF)/100); - return 0; + pr("Not enough available work in %s to build a %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum), lp->l_name); + pr(" (%d available work required)\n", + 1 + (w_p_eff * LAND_MINEFF) / 100); + return 0; } cost = ((float)lp->l_cost * eff); - /* cost = (int)LND_COST(cost, tlev - lp->l_tech);*/ + /* cost = (int)LND_COST(cost, tlev - lp->l_tech); */ if (cash < cost) { - pr("Not enough money left to build a %s\n", lp->l_name); - return 0; + pr("Not enough money left to build a %s\n", lp->l_name); + return 0; } sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * LAND_MINEFF) / 100; player->dolcost += cost; cash -= cost; snxtitem_all(&nstr, EF_LAND); while (nxtitem(&nstr, (s_char *)&land)) { - if (land.lnd_own == 0) { - freeland++; - break; - } + if (land.lnd_own == 0) { + freeland++; + break; + } } if (freeland == 0) { - ef_extend(EF_LAND, 50); + ef_extend(EF_LAND, 50); } - bzero(&land, sizeof(struct lndstr)); + bzero(&land, sizeof(struct lndstr)); land.lnd_x = sp->sct_x; land.lnd_y = sp->sct_y; land.lnd_own = player->cnum; @@ -579,7 +598,7 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp, register int land.lnd_fuel = lp->l_fuelc; land.lnd_nxlight = 0; land.lnd_rflags = 0; - bzero(land.lnd_rpath,10); + bzero(land.lnd_rpath, 10); land.lnd_rad_max = 0; land.lnd_nv = 0; land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech); @@ -598,13 +617,13 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp, register int land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech); land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech); land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech); - + vec[I_LCM] -= lcm; vec[I_HCM] -= hcm; vec[I_MILIT] -= mil; vec[I_GUN] -= gun; vec[I_SHELL] -= shell; - + /* Disabled autoloading of food onto units max_amt = vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int) lp->l_nv); food_needed = (etu_per_update * eatrate) * @@ -622,32 +641,33 @@ build_land(register struct sctstr *sp, register struct lchrstr *lp, register int lvec[I_FOOD] += max_amt; putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); */ - + if (getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_INFECT) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND); + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND); putland(nstr.cur, &land); - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); pr("%s", prland(&land)); pr(" built in sector %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); return 1; } static -int + int build_bridge(register struct sctstr *sp, register int *vec) { - extern int buil_bh; - extern double buil_bc; - struct sctstr sect; - int val; - int newx, newy; - int w_p_eff; - int points; - int nx,ny,i,good=0; - s_char *p; - s_char buf[1024]; - - if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */ + extern int buil_bh; + extern double buil_bc; + struct sctstr sect; + int val; + int newx, newy; + int w_p_eff; + int points; + int nx, ny, i, good = 0; + s_char *p; + s_char buf[1024]; + + if (opt_EASY_BRIDGES == 0) { /* must have a bridge head or tower */ if (sp->sct_type != SCT_BTOWER) { if (sp->sct_type != SCT_BHEAD) return 0; @@ -656,8 +676,8 @@ build_bridge(register struct sctstr *sp, register int *vec) } } #if 0 - else { - + else { + for (i = 1; i <= 6; i++) { struct sctstr s2; nx = sp->sct_x + diroff[i][0]; @@ -669,25 +689,25 @@ build_bridge(register struct sctstr *sp, register int *vec) getsect(nx2, ny2, &s2); if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN)) - good=1; + good = 1; } - + } - - if (!good){ + + if (!good) { pr("Bridges must be built adjacent to land or bridge towers.\n"); pr("No eligible sectors adjacent to this sector.\n"); return 0; } - } /* end EASY_BRIDGES */ + } /* end EASY_BRIDGES */ #endif - + if (sp->sct_effic < 60 && !player->god) { pr("Sector %s is not 60%% efficient.\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); return 0; } - + if (!opt_NO_HCMS) { if (vec[I_HCM] < buil_bh) { pr("%s only has %d unit%s of hcm,\n", @@ -715,15 +735,18 @@ build_bridge(register struct sctstr *sp, register int *vec) if (points < 20) { pr("Not enough available work in %s to build a bridge\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20)/100); + pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100); return 0; } if (!player->argp[3]) { - pr("Bridge head at %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); + pr("Bridge head at %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); nav_map(sp->sct_x, sp->sct_y, 1); } - if (!(p = getstarg(player->argp[3], "build span in what direction? ", buf)) || !*p) { + if (! + (p = + getstarg(player->argp[3], "build span in what direction? ", buf)) + || !*p) { return 0; } /* Sanity check time */ @@ -738,28 +761,26 @@ build_bridge(register struct sctstr *sp, register int *vec) newx = sp->sct_x + diroff[val][0]; newy = sp->sct_y + diroff[val][1]; if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) { - pr("%s is not a water sector\n", - xyas(newx, newy, player->cnum)); + pr("%s is not a water sector\n", xyas(newx, newy, player->cnum)); return 0; } if (opt_EASY_BRIDGES) { - good=0; - + good = 0; + for (i = 1; i <= 6; i++) { struct sctstr s2; nx = sect.sct_x + diroff[i][0]; ny = sect.sct_y + diroff[i][1]; getsect(nx, ny, &s2); - if ((s2.sct_type != SCT_WATER) && - (s2.sct_type != SCT_BSPAN)) - good=1; + if ((s2.sct_type != SCT_WATER) && (s2.sct_type != SCT_BSPAN)) + good = 1; } - if (!good){ + if (!good) { pr("Bridges must be built adjacent to land or bridge towers.\n"); pr("That sector is not adjacent to land or a bridge tower.\n"); return 0; } - } /* end EASY_BRIDGES */ + } /* end EASY_BRIDGES */ sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * 20) / 100; player->dolcost += buil_bc; cash -= buil_bc; @@ -770,14 +791,14 @@ build_bridge(register struct sctstr *sp, register int *vec) sect.sct_rail = 0; sect.sct_defense = 0; if (!opt_DEFENSE_INFRA) - sect.sct_defense = sect.sct_effic; + sect.sct_defense = sect.sct_effic; if (opt_MOB_ACCESS) { time(§.sct_access); sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor); } else { sect.sct_mobil = 0; } - putvar(V_MINE,0,(s_char *)§,EF_SECTOR); + putvar(V_MINE, 0, (s_char *)§, EF_SECTOR); putsect(§); pr("Bridge span built over %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); @@ -789,12 +810,13 @@ build_bridge(register struct sctstr *sp, register int *vec) } static -int -build_nuke(register struct sctstr *sp, register struct nchrstr *np, register int *vec) + int +build_nuke(register struct sctstr *sp, register struct nchrstr *np, + register int *vec) { - int w_p_eff; - int points; - + int w_p_eff; + int points; + if (sp->sct_type != SCT_NUKE && !player->god) { pr("Nuclear weapons must be built in nuclear plants.\n"); return 0; @@ -826,8 +848,7 @@ build_nuke(register struct sctstr *sp, register struct nchrstr *np, register int if (points < 20) { pr("Not enough available work in %s to build a %s;\n", xyas(sp->sct_x, sp->sct_y, player->cnum), np->n_name); - pr(" (%d available work required)\n", - 1 + w_p_eff*20/100); + pr(" (%d available work required)\n", 1 + w_p_eff * 20 / 100); return 0; } if (!trechk(player->cnum, 0, NEWNUK)) @@ -848,18 +869,19 @@ build_nuke(register struct sctstr *sp, register struct nchrstr *np, register int } static -int -build_plane(register struct sctstr *sp, register struct plchrstr *pp, register int *vec, int tlev) + int +build_plane(register struct sctstr *sp, register struct plchrstr *pp, + register int *vec, int tlev) { - struct plnstr plane; - int cost; - struct nstr_item nstr; - float eff=((float)PLANE_MINEFF/100.0); - int points; - int w_p_eff; - int hcm, lcm, mil; - int freeplane = 0; - + struct plnstr plane; + int cost; + struct nstr_item nstr; + float eff = ((float)PLANE_MINEFF / 100.0); + int points; + int w_p_eff; + int hcm, lcm, mil; + int freeplane = 0; + mil = roundavg(((double)pp->pl_crew * (double)eff)); /* Always use at least 1 mil to build a plane */ if (mil == 0 && pp->pl_crew > 0) @@ -867,57 +889,57 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, register i hcm = roundavg(((double)pp->pl_hcm * (double)eff)); lcm = roundavg(((double)pp->pl_lcm * (double)eff)); if (sp->sct_type != SCT_AIRPT && !player->god) { - pr("Planes must be built in airports.\n"); - return 0; + pr("Planes must be built in airports.\n"); + return 0; } if (sp->sct_effic < 60 && !player->god) { - pr("Sector %s is not 60%% efficient.\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + pr("Sector %s is not 60%% efficient.\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } if (vec[I_LCM] < lcm || vec[I_HCM] < hcm) { - pr("Not enough materials in %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + pr("Not enough materials in %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } w_p_eff = (20 + pp->pl_lcm + (pp->pl_hcm * 2)); points = sp->sct_avail * 100 / w_p_eff; if (points < PLANE_MINEFF) { - pr("Not enough available work in %s to build a %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name); - pr(" (%d available work required)\n", - 1 + PLANE_MINEFF * w_p_eff/100); - return 0; + pr("Not enough available work in %s to build a %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum), pp->pl_name); + pr(" (%d available work required)\n", + 1 + PLANE_MINEFF * w_p_eff / 100); + return 0; } cost = pp->pl_cost * eff; if (cash < cost) { - pr("Not enough money left to build a %s\n", pp->pl_name); - return 0; + pr("Not enough money left to build a %s\n", pp->pl_name); + return 0; } if (vec[I_MILIT] < mil || (vec[I_MILIT] == 0 && pp->pl_crew > 0)) { - pr("Not enough military for crew in %s\n", - xyas(sp->sct_x, sp->sct_y, player->cnum)); - return 0; + pr("Not enough military for crew in %s\n", + xyas(sp->sct_x, sp->sct_y, player->cnum)); + return 0; } if (!trechk(player->cnum, 0, NEWPLN)) - return 0; + return 0; if (!check_sect_ok(sp)) - return 0; + return 0; sp->sct_avail = (sp->sct_avail * 100 - w_p_eff * PLANE_MINEFF) / 100; player->dolcost += cost; cash -= cost; snxtitem_all(&nstr, EF_PLANE); freeplane = 0; while (nxtitem(&nstr, (s_char *)&plane)) { - if (plane.pln_own == 0) { - freeplane++; - break; - } + if (plane.pln_own == 0) { + freeplane++; + break; + } } if (freeplane == 0) { - ef_extend(EF_PLANE, 50); + ef_extend(EF_PLANE, 50); } - bzero(&plane, sizeof(struct plnstr)); + bzero(&plane, sizeof(struct plnstr)); plane.pln_x = sp->sct_x; plane.pln_y = sp->sct_y; plane.pln_own = sp->sct_own; @@ -933,7 +955,7 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, register i plane.pln_opx = 0; plane.pln_opy = 0; plane.pln_radius = 0; - + /* Note that this next block of variables can be changed so that individual * planes may have their own stats (like based on tech maybe? :) ) Thus, * the code now checks the pln_acc, pln_load and pln_fuel instead of using @@ -965,7 +987,7 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, register i plane.pln_range_max = plane.pln_range; plane.pln_load = PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)); plane.pln_fuel = pp->pl_fuel; - + plane.pln_wing = ' '; plane.pln_tech = tlev; plane.pln_ship = -1; @@ -975,7 +997,8 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, register i plane.pln_harden = 0; plane.pln_sell = 0; plane.pln_flags = 0; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, + plane.pln_y); putplane(plane.pln_uid, &plane); pr("%s built in sector %s\n", prplane(&plane), xyas(sp->sct_x, sp->sct_y, player->cnum)); @@ -986,18 +1009,18 @@ build_plane(register struct sctstr *sp, register struct plchrstr *pp, register i } static -int + int build_tower(register struct sctstr *sp, register int *vec) { - extern int buil_tower_bh; - extern double buil_tower_bc; - struct sctstr sect; - int val; - int newx, newy; - int w_p_eff; - int points; - s_char *p; - s_char buf[1024]; + extern int buil_tower_bh; + extern double buil_tower_bc; + struct sctstr sect; + int val; + int newx, newy; + int w_p_eff; + int points; + s_char *p; + s_char buf[1024]; int good; int i; int nx; @@ -1013,7 +1036,7 @@ build_tower(register struct sctstr *sp, register int *vec) xyas(sp->sct_x, sp->sct_y, player->cnum)); return 0; } - + if (!opt_NO_HCMS) { if (vec[I_HCM] < buil_tower_bh) { pr("%s only has %d unit%s of hcm,\n", @@ -1041,15 +1064,17 @@ build_tower(register struct sctstr *sp, register int *vec) if (points < 20) { pr("Not enough available work in %s to build a bridge tower\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20)/100); + pr(" (%d available work required)\n", 1 + (w_p_eff * 20) / 100); return 0; } if (!player->argp[3]) { pr("Building from %s\n", xyas(sp->sct_x, sp->sct_y, player->cnum)); nav_map(sp->sct_x, sp->sct_y, 1); } - if (!(p = getstarg(player->argp[3], "build tower in what direction? ", buf)) || !*p) { + if (! + (p = + getstarg(player->argp[3], "build tower in what direction? ", buf)) + || !*p) { return 0; } /* Sanity check time */ @@ -1064,8 +1089,7 @@ build_tower(register struct sctstr *sp, register int *vec) newx = sp->sct_x + diroff[val][0]; newy = sp->sct_y + diroff[val][1]; if (getsect(newx, newy, §) == 0 || sect.sct_type != SCT_WATER) { - pr("%s is not a water sector\n", - xyas(newx, newy, player->cnum)); + pr("%s is not a water sector\n", xyas(newx, newy, player->cnum)); return 0; } @@ -1078,13 +1102,12 @@ build_tower(register struct sctstr *sp, register int *vec) ny = sect.sct_y + diroff[i][1]; getsect(nx, ny, &s2); if ((s2.sct_type != SCT_WATER) && - (s2.sct_type != SCT_BTOWER) && - (s2.sct_type != SCT_BSPAN)) { + (s2.sct_type != SCT_BTOWER) && (s2.sct_type != SCT_BSPAN)) { good = 1; break; } } - if (good){ + if (good) { pr("Bridge towers cannot be built adjacent to land.\n"); pr("That sector is adjacent to land.\n"); return 0; @@ -1106,8 +1129,8 @@ build_tower(register struct sctstr *sp, register int *vec) sect.sct_mobil = 0; } if (!opt_DEFENSE_INFRA) - sect.sct_defense = sect.sct_effic; - putvar(V_MINE,0,(s_char *)§,EF_SECTOR); + sect.sct_defense = sect.sct_effic; + putvar(V_MINE, 0, (s_char *)§, EF_SECTOR); putsect(§); pr("Bridge tower built in %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); @@ -1117,4 +1140,3 @@ build_tower(register struct sctstr *sp, register int *vec) vec[I_LCM] -= buil_tower_bh; return 1; } - diff --git a/src/lib/commands/buy.c b/src/lib/commands/buy.c index c891dec7d..7dee3c92f 100644 --- a/src/lib/commands/buy.c +++ b/src/lib/commands/buy.c @@ -54,7 +54,7 @@ #include "commands.h" #include "optlist.h" -extern int MARK_DELAY; +extern int MARK_DELAY; /* * format: buy @@ -70,18 +70,18 @@ buy(void) struct comstr comt; struct trdstr tmpt; struct ichrstr *ip; - int qty; - int o, n, q; - coord x, y; - char *p; - float bid; - time_t now; - double tally; - double canspend; - extern double buytax; - extern double tradetax; - s_char buf[1024]; - + int qty; + int o, n, q; + coord x, y; + char *p; + float bid; + time_t now; + double tally; + double canspend; + extern double buytax; + extern double tradetax; + s_char buf[1024]; + if (!opt_MARKET) { pr("The market is disabled.\n"); return RET_FAIL; @@ -91,13 +91,13 @@ buy(void) pr("\n"); p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf); if (p == 0) - return RET_SYN; + return RET_SYN; if (*p == 0) - return RET_SYN; + return RET_SYN; o = atoi(p); if (o < 0) return RET_SYN; - if(!getcomm(o, &comm) || comm.com_owner == 0){ + if (!getcomm(o, &comm) || comm.com_owner == 0) { pr("Invalid lot number.\n"); return RET_OK; } @@ -106,7 +106,7 @@ buy(void) pr("That lot is not of the type you specified.\n"); return RET_OK; } - if (comm.com_owner == player->cnum){ + if (comm.com_owner == player->cnum) { pr("You can't bid on your own lot.\n"); return RET_OK; } @@ -114,8 +114,8 @@ buy(void) pr(" bids than your treasury can cover at the time of sale,\n"); pr(" you can potentially go into financial ruin, and see no\n"); pr(" gains. You have been warned.\n\n"); - if ((p = getstarg(player->argp[3], "How much per unit: ",buf)) == 0) - return RET_SYN; + if ((p = getstarg(player->argp[3], "How much per unit: ", buf)) == 0) + return RET_SYN; bid = atof(p); if (bid <= 0) return RET_FAIL; @@ -131,15 +131,13 @@ buy(void) tally = 0.0; for (q = 0; gettrade(q, &tmpt); q++) { if (tmpt.trd_maxbidder == player->cnum && - tmpt.trd_unitid >= 0 && - tmpt.trd_owner != player->cnum) { + tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) { tally += tmpt.trd_maxprice * tradetax; } } for (q = 0; getcomm(q, &comt); q++) { if (comt.com_maxbidder == player->cnum && - comt.com_owner != 0 && - comt.com_owner != player->cnum) { + comt.com_owner != 0 && comt.com_owner != player->cnum) { tally += (comt.com_maxprice * comt.com_amount) * buytax; } } @@ -187,25 +185,25 @@ buy(void) return RET_FAIL; } if ((bid * comm.com_amount) > natp->nat_money) { - pr("You don't have that much to spend!\n"); - return RET_FAIL; + pr("You don't have that much to spend!\n"); + return RET_FAIL; } getcomm(o, &ncomm); if (!ncomm.com_owner) { - pr("That lot has been taken off the market.\n"); + pr("That lot has been taken off the market.\n"); return RET_FAIL; } - if (bid > 0.04 + comm.com_maxprice){ + if (bid > 0.04 + comm.com_maxprice) { comm.com_maxprice = bid; - /* Add five minutes to the time if less than 5 minutes */ + /* Add five minutes to the time if less than 5 minutes */ time(&now); if (((MARK_DELAY - (now - comm.com_markettime)) < 300) && comm.com_maxbidder != player->cnum) { - comm.com_markettime += 300; - /* Special case - what if so much time has gone by? Well, - Just reset the markettime so that only 5 minutes are left */ - if ((MARK_DELAY - (now - comm.com_markettime)) < 0) - comm.com_markettime = (now - (MARK_DELAY - 300)); + comm.com_markettime += 300; + /* Special case - what if so much time has gone by? Well, + Just reset the markettime so that only 5 minutes are left */ + if ((MARK_DELAY - (now - comm.com_markettime)) < 0) + comm.com_markettime = (now - (MARK_DELAY - 300)); } comm.com_maxbidder = player->cnum; comm.com_x = x; @@ -217,7 +215,7 @@ buy(void) pr("than the last bid.\n"); return RET_OK; } - + check_market(); return RET_OK; @@ -226,7 +224,7 @@ buy(void) int check_market(void) { - extern double buytax; + extern double buytax; struct comstr comm; struct sctstr *sect; struct ichrstr *ip; @@ -241,15 +239,14 @@ check_market(void) double gain; double price; struct lonstr loan; - long outstanding; /* Outstanding debt */ - long couval; /* Value of country's goods */ + long outstanding; /* Outstanding debt */ + long couval; /* Value of country's goods */ int foundloan; int j; /* logerror("Checking the market.\n");*/ for (n = 0; getcomm(n, &comm); n++) { - if (comm.com_maxbidder == comm.com_owner || - comm.com_owner == 0) + if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0) continue; (void)time(&now); tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0; @@ -269,7 +266,7 @@ check_market(void) natp = getnatp(comm.com_maxbidder); tmoney = natp->nat_money; if (tmoney <= 0) - monleft = price; + monleft = price; if (tmoney < price && tmoney > 0) { monleft = price - (tmoney - 1); tmoney = 1; @@ -286,7 +283,8 @@ check_market(void) /* Try to make a loan for the rest from the owner. */ if (monleft > 0 && tmoney > 0) { if ((float)((float)price / (float)(price + monleft)) < 0.1) { - wu(0, comm.com_maxbidder, "You need at least 10 percent down to purchase something on credit.\n"); + wu(0, comm.com_maxbidder, + "You need at least 10 percent down to purchase something on credit.\n"); } else { couval = get_couval(comm.com_maxbidder); outstanding = get_outstand(comm.com_maxbidder); @@ -310,57 +308,69 @@ check_market(void) loan.l_amtpaid = 0; loan.l_amtdue = monleft; time(&loan.l_lastpay); - loan.l_duedate = (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay; + loan.l_duedate = + (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay; loan.l_uid = j; if (!putloan(j, &loan)) logerror("Error writing to the loan file.\n"); else monleft = 0; - nreport(comm.com_maxbidder,N_FIN_TROUBLE, comm.com_owner, 1); - wu(0, comm.com_maxbidder, "You just took loan #%d for $%.2f to cover the cost of your purchase.\n", j, loan.l_amtdue); - wu(0, comm.com_owner, "You just extended loan #%d to %s to help with the purchase cose.\n", j, cname(comm.com_maxbidder)); + nreport(comm.com_maxbidder, N_FIN_TROUBLE, + comm.com_owner, 1); + wu(0, comm.com_maxbidder, + "You just took loan #%d for $%.2f to cover the cost of your purchase.\n", + j, loan.l_amtdue); + wu(0, comm.com_owner, + "You just extended loan #%d to %s to help with the purchase cose.\n", + j, cname(comm.com_maxbidder)); } else { - nreport(comm.com_maxbidder,N_CREDIT_JUNK, comm.com_owner, 1); - wu(0, comm.com_maxbidder, "You don't have enough credit to get a loan.\n"); - wu(0, comm.com_owner, "You just turned down a loan to %s.\n", cname(comm.com_maxbidder)); + nreport(comm.com_maxbidder, N_CREDIT_JUNK, + comm.com_owner, 1); + wu(0, comm.com_maxbidder, + "You don't have enough credit to get a loan.\n"); + wu(0, comm.com_owner, + "You just turned down a loan to %s.\n", + cname(comm.com_maxbidder)); } } } } - + if (monleft > 0) { nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1); wu(0, comm.com_maxbidder, "You didn't have enough cash/credit to cover the cost.\n"); - wu(0, comm.com_owner, + wu(0, comm.com_owner, "Sale #%d fell through. Goods remain on the market.\n", n); comm.com_maxbidder = comm.com_owner; - } else if (sect->sct_type != SCT_WAREH && sect->sct_type != SCT_HARBR) { - wu(0, comm.com_maxbidder, + } else if (sect->sct_type != SCT_WAREH + && sect->sct_type != SCT_HARBR) { + wu(0, comm.com_maxbidder, "Sector not a warehouse now, sale #%d fell though.\n", n); - wu(0, comm.com_owner, + wu(0, comm.com_owner, "Sale #%d fell through. Goods remain on the market.\n", n); comm.com_maxbidder = comm.com_owner; } else if (putvar(ip->i_vtype, m + comm.com_amount, (char *)sect, EF_SECTOR) <= 0) { - wu(0, comm.com_maxbidder, + wu(0, comm.com_maxbidder, "Warehouse full, sale #%d fell though.\n", n); - wu(0, comm.com_owner, + wu(0, comm.com_owner, "Sale #%d fell through. Goods remain on the market.\n", n); comm.com_maxbidder = comm.com_owner; } else { putsect(sect); nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1); wu(0, comm.com_owner, "%s bought %d %c's from you for $%.2f\n", - cname(comm.com_maxbidder), comm.com_amount, + cname(comm.com_maxbidder), comm.com_amount, comm.com_type, gain); - wu(0, comm.com_maxbidder, "You just bought %d %c's from %s for $%.2f\n", + wu(0, comm.com_maxbidder, + "You just bought %d %c's from %s for $%.2f\n", comm.com_amount, comm.com_type, cname(comm.com_owner), gain * buytax); - natp=getnatp(comm.com_owner); + natp = getnatp(comm.com_owner); /* Make sure we subtract the amount that came out in a loan */ natp->nat_money += (gain - subleft); - natp=getnatp(comm.com_maxbidder); + natp = getnatp(comm.com_maxbidder); natp->nat_money = tmoney; comm.com_owner = 0; } @@ -370,5 +380,3 @@ check_market(void) /* logerror("Done checking the market.\n");*/ return RET_OK; } - - diff --git a/src/lib/commands/capi.c b/src/lib/commands/capi.c index d351526d1..9f2f3ccdd 100644 --- a/src/lib/commands/capi.c +++ b/src/lib/commands/capi.c @@ -47,33 +47,33 @@ int capi(void) { - struct sctstr sect; - struct natstr *np; - struct nstr_sect nstr; - int found; + struct sctstr sect; + struct natstr *np; + struct nstr_sect nstr; + int found; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - np = getnatp(player->cnum); - found = 0; - while (!found && nxtsct(&nstr, §)) { - if (player->owner && (sect.sct_type == SCT_CAPIT || - sect.sct_type == SCT_MOUNT)) - found++; - } - if (!found) - return RET_FAIL; - if (sect.sct_x == np->nat_xcap && sect.sct_y == np->nat_ycap) { - pr("%s is already your capital.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_FAIL; - } - player->nstat |= CAP; - np->nat_xcap = sect.sct_x; - np->nat_ycap = sect.sct_y; - /* They have set a capital, so it wasn't sacked last. */ - np->nat_flags &= ~NF_SACKED; - putnat(np); - pr("Capital now at %s.\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); - return 0; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + np = getnatp(player->cnum); + found = 0; + while (!found && nxtsct(&nstr, §)) { + if (player->owner && (sect.sct_type == SCT_CAPIT || + sect.sct_type == SCT_MOUNT)) + found++; + } + if (!found) + return RET_FAIL; + if (sect.sct_x == np->nat_xcap && sect.sct_y == np->nat_ycap) { + pr("%s is already your capital.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_FAIL; + } + player->nstat |= CAP; + np->nat_xcap = sect.sct_x; + np->nat_ycap = sect.sct_y; + /* They have set a capital, so it wasn't sacked last. */ + np->nat_flags &= ~NF_SACKED; + putnat(np); + pr("Capital now at %s.\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); + return 0; } diff --git a/src/lib/commands/carg.c b/src/lib/commands/carg.c index 582839fa7..b0ab42b55 100644 --- a/src/lib/commands/carg.c +++ b/src/lib/commands/carg.c @@ -48,106 +48,104 @@ int carg(void) { - int nships; - struct nstr_item ni; - struct shpstr ship; - int vec[I_MAX+1]; + int nships; + struct nstr_item ni; + struct shpstr ship; + int vec[I_MAX + 1]; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; - nships = 0; - while (nxtitem(&ni, (s_char *)&ship)) { - if (ship.shp_own == 0) - continue; - if ((player->cnum != ship.shp_own) && !player->god) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", ship.shp_type, - ni.cur); - continue; - } - if (nships++ == 0) - pr("shp# ship type x,y flt eff sh gun pet irn dst bar oil lcm hcm rad\n"); - pr("%4d ", ni.cur); - pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); - pr(" %1c", ship.shp_fleet); - pr("%4d%%", ship.shp_effic); - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%4d", vec[I_PETROL]); - pr("%4d", vec[I_IRON]); - pr("%4d", vec[I_DUST]); - pr("%4d", vec[I_BAR]); - pr("%4d", vec[I_OIL]); - pr("%4d", vec[I_LCM]); - pr("%4d", vec[I_HCM]); - pr("%4d\n", vec[I_RAD]); - if (opt_SHIPNAMES) { - if (ship.shp_name[0] != 0) { - pr(" %s\n",ship.shp_name); - } - } + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; + nships = 0; + while (nxtitem(&ni, (s_char *)&ship)) { + if (ship.shp_own == 0) + continue; + if ((player->cnum != ship.shp_own) && !player->god) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur); + continue; } - if (nships == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + if (nships++ == 0) + pr("shp# ship type x,y flt eff sh gun pet irn dst bar oil lcm hcm rad\n"); + pr("%4d ", ni.cur); + pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + pr(" %1c", ship.shp_fleet); + pr("%4d%%", ship.shp_effic); + getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); + pr("%4d", vec[I_SHELL]); + pr("%4d", vec[I_GUN]); + pr("%4d", vec[I_PETROL]); + pr("%4d", vec[I_IRON]); + pr("%4d", vec[I_DUST]); + pr("%4d", vec[I_BAR]); + pr("%4d", vec[I_OIL]); + pr("%4d", vec[I_LCM]); + pr("%4d", vec[I_HCM]); + pr("%4d\n", vec[I_RAD]); + if (opt_SHIPNAMES) { + if (ship.shp_name[0] != 0) { + pr(" %s\n", ship.shp_name); + } + } + } + if (nships == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } int lcarg(void) { - int nunits; - struct nstr_item ni; - struct lndstr land; - int vec[I_MAX+1]; + int nunits; + struct nstr_item ni; + struct lndstr land; + int vec[I_MAX + 1]; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - nunits = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (!land.lnd_own) - continue; - if ((player->cnum != land.lnd_own) && !player->god) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", land.lnd_type, - ni.cur); - continue; - } - if (nunits++ == 0) - pr("lnd# unit type x,y a eff sh gun pet irn dst bar oil lcm hcm rad\n"); - pr("%4d ", ni.cur); - pr("%-16.16s ", lchr[(int)land.lnd_type].l_name); - prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum); - pr(" %1c", land.lnd_army); - pr("%4d%%", land.lnd_effic); - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%4d", vec[I_PETROL]); - pr("%4d", vec[I_IRON]); - pr("%4d", vec[I_DUST]); - pr("%4d", vec[I_BAR]); - pr("%4d", vec[I_OIL]); - pr("%4d", vec[I_LCM]); - pr("%4d", vec[I_HCM]); - pr("%4d\n", vec[I_RAD]); + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + nunits = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (!land.lnd_own) + continue; + if ((player->cnum != land.lnd_own) && !player->god) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("No unit(s)\n"); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + if (nunits++ == 0) + pr("lnd# unit type x,y a eff sh gun pet irn dst bar oil lcm hcm rad\n"); + pr("%4d ", ni.cur); + pr("%-16.16s ", lchr[(int)land.lnd_type].l_name); + prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum); + pr(" %1c", land.lnd_army); + pr("%4d%%", land.lnd_effic); + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); + pr("%4d", vec[I_SHELL]); + pr("%4d", vec[I_GUN]); + pr("%4d", vec[I_PETROL]); + pr("%4d", vec[I_IRON]); + pr("%4d", vec[I_DUST]); + pr("%4d", vec[I_BAR]); + pr("%4d", vec[I_OIL]); + pr("%4d", vec[I_LCM]); + pr("%4d", vec[I_HCM]); + pr("%4d\n", vec[I_RAD]); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("No unit(s)\n"); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } diff --git a/src/lib/commands/cede.c b/src/lib/commands/cede.c index 3439c8e55..b0a595280 100644 --- a/src/lib/commands/cede.c +++ b/src/lib/commands/cede.c @@ -49,144 +49,144 @@ #include "item.h" #include "commands.h" -static void cede_hdr(void); +static void cede_hdr(void); int cede(void) { - natid to; - int n; - int is_sector=0,is_ship=0; - s_char *p; - struct nstr_sect ns; - struct nstr_item ni; - struct natstr *natp; - s_char buf[1024]; - - if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0) - return RET_SYN; - if (snxtsct(&ns, p)) - is_sector = 1; - if (snxtitem(&ni, EF_SHIP, p)) - is_ship = 1; - if (!is_sector && !is_ship) - return RET_SYN; - if ((n = natarg(player->argp[2], "to which country? ")) < 0) - return RET_SYN; - if (is_sector && is_ship){ - int type; - - if ((p = getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ", buf)) == 0) - return RET_FAIL; - if (strlen(p) > 4) - p[2] = 0; - type = ef_byname(p); - - if (type == EF_SECTOR) - is_ship = 0; - else if (type == EF_SHIP) - is_sector = 0; - else{ - pr("Please type 'se' or 'sh'!\n"); - return RET_FAIL; - } + natid to; + int n; + int is_sector = 0, is_ship = 0; + s_char *p; + struct nstr_sect ns; + struct nstr_item ni; + struct natstr *natp; + s_char buf[1024]; + + if ((p = getstarg(player->argp[1], "Cede what? ", buf)) == 0) + return RET_SYN; + if (snxtsct(&ns, p)) + is_sector = 1; + if (snxtitem(&ni, EF_SHIP, p)) + is_ship = 1; + if (!is_sector && !is_ship) + return RET_SYN; + if ((n = natarg(player->argp[2], "to which country? ")) < 0) + return RET_SYN; + if (is_sector && is_ship) { + int type; + + if ((p = + getstarg(player->argp[3], "Cede sectors or ships (se, sh)? ", + buf)) == 0) + return RET_FAIL; + if (strlen(p) > 4) + p[2] = 0; + type = ef_byname(p); + + if (type == EF_SECTOR) + is_ship = 0; + else if (type == EF_SHIP) + is_sector = 0; + else { + pr("Please type 'se' or 'sh'!\n"); + return RET_FAIL; } - - - if (n == player->cnum){ - pr("Giving something to yourself?\n"); - return RET_FAIL; - } - natp = getnatp(n); - if (natp->nat_stat & STAT_GOD){ - pr("You can only give to normal countries...\n"); - return RET_FAIL; - } - if (getrel(natp, player->cnum) < FRIENDLY) { - pr("You can only cede to a country that is friendly towards you...\n"); - return RET_FAIL; - } - to = n; - - if (is_sector) - return cede_sect(&ns,to); - else - return cede_ship(&ni,to); + } + + + if (n == player->cnum) { + pr("Giving something to yourself?\n"); + return RET_FAIL; + } + natp = getnatp(n); + if (natp->nat_stat & STAT_GOD) { + pr("You can only give to normal countries...\n"); + return RET_FAIL; + } + if (getrel(natp, player->cnum) < FRIENDLY) { + pr("You can only cede to a country that is friendly towards you...\n"); + return RET_FAIL; + } + to = n; + + if (is_sector) + return cede_sect(&ns, to); + else + return cede_ship(&ni, to); } int cede_sect(struct nstr_sect *ns, natid to) { - struct sctstr sect, osect; - int nsect; - int n, bad; - s_char dirstr[20]; - int off_x, off_y; - struct nstr_item ni; - struct shpstr ship; - - prdate(); - for (n = 1; n <= 6; n++) - dirstr[n] = dirch[n]; - dirstr[0] = '.'; - dirstr[7] = '$'; - dirstr[8] = '\0'; - nsect = 0; - while (nxtsct(ns, §)) { - if (!player->owner) - continue; - if (sect.sct_mobil == 0){ - pr("%s has no mobility and cannot be ceded\n", - xyas(sect.sct_x,sect.sct_y,player->cnum)); - continue; - } - - bad = 1; - for (n = 1; n <= 6; n++) { /* Directions */ - off_x = sect.sct_x + diroff[n][0]; - off_y = sect.sct_y + diroff[n][1]; - - if (!getsect(off_x, off_y, &osect)) - continue; - if ((osect.sct_own == to) && (osect.sct_mobil)) - bad=0; - if ((osect.sct_own == to) && - has_units_with_mob(osect.sct_x, osect.sct_y,to)) - bad=0; - } - snxtitem_all(&ni,EF_SHIP); - while (nxtitem(&ni, (s_char *)&ship)){ - if ((ship.shp_own == to) && - ((ship.shp_x == sect.sct_x) && - (ship.shp_y == sect.sct_y))) - bad = 0; - } - if (bad){ - pr("%s has no sector with mobility adjacent to or ship in %s!\n", - cname(to), xyas(sect.sct_x,sect.sct_y,player->cnum)); - continue; - } - - if (nsect++ == 0) - cede_hdr(); - - grab_sect(§,to); - putsect(§); - pr(" %s %d%% ceded\n",xyas(sect.sct_x,sect.sct_y,player->cnum), - (int)sect.sct_effic); - wu(0,(natid)to,"%s ceded to you by %s\n", - xyas(sect.sct_x,sect.sct_y,to), cname(player->cnum)); + struct sctstr sect, osect; + int nsect; + int n, bad; + s_char dirstr[20]; + int off_x, off_y; + struct nstr_item ni; + struct shpstr ship; + + prdate(); + for (n = 1; n <= 6; n++) + dirstr[n] = dirch[n]; + dirstr[0] = '.'; + dirstr[7] = '$'; + dirstr[8] = '\0'; + nsect = 0; + while (nxtsct(ns, §)) { + if (!player->owner) + continue; + if (sect.sct_mobil == 0) { + pr("%s has no mobility and cannot be ceded\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; } - pr("%d sector%s\n", nsect, splur(nsect)); - return RET_OK; + + bad = 1; + for (n = 1; n <= 6; n++) { /* Directions */ + off_x = sect.sct_x + diroff[n][0]; + off_y = sect.sct_y + diroff[n][1]; + + if (!getsect(off_x, off_y, &osect)) + continue; + if ((osect.sct_own == to) && (osect.sct_mobil)) + bad = 0; + if ((osect.sct_own == to) && + has_units_with_mob(osect.sct_x, osect.sct_y, to)) + bad = 0; + } + snxtitem_all(&ni, EF_SHIP); + while (nxtitem(&ni, (s_char *)&ship)) { + if ((ship.shp_own == to) && + ((ship.shp_x == sect.sct_x) && (ship.shp_y == sect.sct_y))) + bad = 0; + } + if (bad) { + pr("%s has no sector with mobility adjacent to or ship in %s!\n", cname(to), xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; + } + + if (nsect++ == 0) + cede_hdr(); + + grab_sect(§, to); + putsect(§); + pr(" %s %d%% ceded\n", xyas(sect.sct_x, sect.sct_y, player->cnum), + (int)sect.sct_effic); + wu(0, (natid)to, "%s ceded to you by %s\n", + xyas(sect.sct_x, sect.sct_y, to), cname(player->cnum)); + } + pr("%d sector%s\n", nsect, splur(nsect)); + return RET_OK; } static void cede_hdr(void) { - if (player->god) - pr("own "); - pr(" sect eff\n"); + if (player->god) + pr("own "); + pr(" sect eff\n"); } @@ -194,200 +194,198 @@ cede_hdr(void) void grab_sect(register struct sctstr *sp, natid to) { - struct plnstr *pp; - struct lndstr *lp; - struct nukstr *np; - int oldche; - struct nstr_item ni; - struct plnstr p; - struct lndstr l; - struct nukstr nuk; - int vec[I_MAX+1]; - - /* Wipe all the distribution info */ - bzero((s_char *)vec, sizeof(vec)); - putvec(VT_DIST, vec, (s_char *)sp, EF_SECTOR); - putvec(VT_DEL, vec, (s_char *)sp, EF_SECTOR); - sp->sct_dist_x = sp->sct_x; - sp->sct_dist_y = sp->sct_y; - - pp = &p; - snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y); - while (nxtitem(&ni, (caddr_t)pp)) { - if (pp->pln_own == 0) - continue; - if (pp->pln_ship >= 0) - continue; - if (pp->pln_own != player->cnum) - continue; - if (pp->pln_flags & PLN_LAUNCHED) - continue; - - wu(0,to,"\t%s ceded to you by %s\n", - prplane(pp), - cname(player->cnum)); - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = to; - makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_mobil = 0; - pp->pln_mission = 0; - putplane(pp->pln_uid, pp); - } - - np = &nuk; - snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y); - while (nxtitem(&ni, (caddr_t)np)) { - if (np->nuk_own == 0) - continue; - - wu(0,to,"\tnuclear stockpile #%d ceded to you by %s\n", - np->nuk_uid, cname(player->cnum)); - makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y); - np->nuk_own = to; - makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y); - putnuke(ni.cur, np); - } - - lp = &l; - snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); - while (nxtitem(&ni, (caddr_t)lp)) { - if (lp->lnd_own == 0) - continue; - if (lp->lnd_ship == 0) - continue; - if (lp->lnd_own != player->cnum) - continue; - - wu(0,to,"\t%s ceded to you by %s\n", prland(lp), - cname(player->cnum)); - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own = to; - lp->lnd_mobil = 0; - lp->lnd_mission = 0; - putland(ni.cur, lp); - } - - sp->sct_avail = 0; - - if (sp->sct_oldown == to) { - oldche = get_che_value(getvar(V_CHE, (s_char *)sp, EF_SECTOR)); - set_che_value(oldche, 0); - set_che_cnum(oldche, 0); - (void) putvar(V_CHE, oldche, (s_char *)sp, EF_SECTOR); - sp->sct_loyal = 0; - } - - if (sp->sct_oldown == to) - sp->sct_loyal = 0; - else /* people don't like being given away */ - sp->sct_loyal = 50; - - sp->sct_dist_x = sp->sct_x; - sp->sct_dist_y = sp->sct_y; - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y); - if (sp->sct_oldown == sp->sct_own) - sp->sct_oldown = to; - sp->sct_own = to; - sp->sct_mobil = 0; + struct plnstr *pp; + struct lndstr *lp; + struct nukstr *np; + int oldche; + struct nstr_item ni; + struct plnstr p; + struct lndstr l; + struct nukstr nuk; + int vec[I_MAX + 1]; + + /* Wipe all the distribution info */ + bzero((s_char *)vec, sizeof(vec)); + putvec(VT_DIST, vec, (s_char *)sp, EF_SECTOR); + putvec(VT_DEL, vec, (s_char *)sp, EF_SECTOR); + sp->sct_dist_x = sp->sct_x; + sp->sct_dist_y = sp->sct_y; + + pp = &p; + snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (caddr_t)pp)) { + if (pp->pln_own == 0) + continue; + if (pp->pln_ship >= 0) + continue; + if (pp->pln_own != player->cnum) + continue; + if (pp->pln_flags & PLN_LAUNCHED) + continue; + + wu(0, to, "\t%s ceded to you by %s\n", + prplane(pp), cname(player->cnum)); + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + pp->pln_own = to; + makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_mobil = 0; + pp->pln_mission = 0; + putplane(pp->pln_uid, pp); + } + + np = &nuk; + snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (caddr_t)np)) { + if (np->nuk_own == 0) + continue; + + wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n", + np->nuk_uid, cname(player->cnum)); + makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y); + np->nuk_own = to; + makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, + np->nuk_y); + putnuke(ni.cur, np); + } + + lp = &l; + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (caddr_t)lp)) { + if (lp->lnd_own == 0) + continue; + if (lp->lnd_ship == 0) + continue; + if (lp->lnd_own != player->cnum) + continue; + + wu(0, to, "\t%s ceded to you by %s\n", prland(lp), + cname(player->cnum)); + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); + makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y); + lp->lnd_own = to; + lp->lnd_mobil = 0; + lp->lnd_mission = 0; + putland(ni.cur, lp); + } + + sp->sct_avail = 0; + + if (sp->sct_oldown == to) { + oldche = get_che_value(getvar(V_CHE, (s_char *)sp, EF_SECTOR)); + set_che_value(oldche, 0); + set_che_cnum(oldche, 0); + (void)putvar(V_CHE, oldche, (s_char *)sp, EF_SECTOR); + sp->sct_loyal = 0; + } + + if (sp->sct_oldown == to) + sp->sct_loyal = 0; + else /* people don't like being given away */ + sp->sct_loyal = 50; + + sp->sct_dist_x = sp->sct_x; + sp->sct_dist_y = sp->sct_y; + makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); + makenotlost(EF_SECTOR, to, 0, sp->sct_x, sp->sct_y); + if (sp->sct_oldown == sp->sct_own) + sp->sct_oldown = to; + sp->sct_own = to; + sp->sct_mobil = 0; } int cede_ship(struct nstr_item *ni, natid to) { - struct shpstr ship; - struct shpstr tship; - struct sctstr sect; - struct nstr_item tni; - int nships=0; - int bad=0; - - while (nxtitem(ni, (s_char *)&ship)) { - - if (!player->owner || ship.shp_own == 0) - continue; - - bad = 1; - snxtitem_xy(&tni,EF_SHIP,ship.shp_x,ship.shp_y); - while (nxtitem(&tni, (s_char *)&tship) && bad) - if (tship.shp_own == to) - bad = 0; - - getsect(ship.shp_x,ship.shp_y,§); - if (bad && (sect.sct_own != to)){ - pr("%s isn't in a %s sector, and is not with a %s ship!\n", prship(&ship), - cname(to), cname(to)); - continue; - } - grab_ship(&ship,to); - putship(ship.shp_uid,&ship); - nships++; - wu(0,to,"%s ceded to you by %s\n", - prship(&ship), - cname(player->cnum)); - pr("%s ceded to %s\n", - prship(&ship), - cname(to)); + struct shpstr ship; + struct shpstr tship; + struct sctstr sect; + struct nstr_item tni; + int nships = 0; + int bad = 0; + + while (nxtitem(ni, (s_char *)&ship)) { + + if (!player->owner || ship.shp_own == 0) + continue; + + bad = 1; + snxtitem_xy(&tni, EF_SHIP, ship.shp_x, ship.shp_y); + while (nxtitem(&tni, (s_char *)&tship) && bad) + if (tship.shp_own == to) + bad = 0; + + getsect(ship.shp_x, ship.shp_y, §); + if (bad && (sect.sct_own != to)) { + pr("%s isn't in a %s sector, and is not with a %s ship!\n", + prship(&ship), cname(to), cname(to)); + continue; } - pr(" %d ship%s\n", nships, splur(nships)); - - return RET_OK; + grab_ship(&ship, to); + putship(ship.shp_uid, &ship); + nships++; + wu(0, to, "%s ceded to you by %s\n", + prship(&ship), cname(player->cnum)); + pr("%s ceded to %s\n", prship(&ship), cname(to)); + } + pr(" %d ship%s\n", nships, splur(nships)); + + return RET_OK; } void grab_ship(register struct shpstr *sp, natid to) { - register struct plnstr *pp; - register struct lndstr *lp; - struct nstr_item ni; - struct plnstr p; - struct lndstr l; - - pp = &p; - snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y); - while (nxtitem(&ni, (caddr_t)pp)) { - if (pp->pln_own == 0) - continue; - if (pp->pln_flags & PLN_LAUNCHED) - continue; - if (pp->pln_ship != sp->shp_uid) - continue; - if (pp->pln_own != player->cnum) - continue; - - wu(0,to,"\t%s ceded to you by %s\n", - prplane(pp), - cname(player->cnum)); - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = to; - makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_mobil = 0; - pp->pln_mission = 0; - putplane(pp->pln_uid, pp); - } - - lp = &l; - snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y); - while (nxtitem(&ni, (caddr_t)lp)) { - if (lp->lnd_own == 0) - continue; - if (lp->lnd_ship != sp->shp_uid) - continue; - if (lp->lnd_own != player->cnum) - continue; - - wu(0,to,"\t%s ceded to you by %s\n", - prland(lp), cname(player->cnum)); - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own = to; - lp->lnd_mobil = 0; - lp->lnd_mission = 0; - putland(ni.cur, lp); - } - - makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); - sp->shp_own = to; - makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); + register struct plnstr *pp; + register struct lndstr *lp; + struct nstr_item ni; + struct plnstr p; + struct lndstr l; + + pp = &p; + snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y); + while (nxtitem(&ni, (caddr_t)pp)) { + if (pp->pln_own == 0) + continue; + if (pp->pln_flags & PLN_LAUNCHED) + continue; + if (pp->pln_ship != sp->shp_uid) + continue; + if (pp->pln_own != player->cnum) + continue; + + wu(0, to, "\t%s ceded to you by %s\n", + prplane(pp), cname(player->cnum)); + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + pp->pln_own = to; + makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_mobil = 0; + pp->pln_mission = 0; + putplane(pp->pln_uid, pp); + } + + lp = &l; + snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y); + while (nxtitem(&ni, (caddr_t)lp)) { + if (lp->lnd_own == 0) + continue; + if (lp->lnd_ship != sp->shp_uid) + continue; + if (lp->lnd_own != player->cnum) + continue; + + wu(0, to, "\t%s ceded to you by %s\n", + prland(lp), cname(player->cnum)); + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); + makenotlost(EF_LAND, to, lp->lnd_uid, lp->lnd_x, lp->lnd_y); + lp->lnd_own = to; + lp->lnd_mobil = 0; + lp->lnd_mission = 0; + putland(ni.cur, lp); + } + + makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); + sp->shp_own = to; + makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); } diff --git a/src/lib/commands/cens.c b/src/lib/commands/cens.c index f808e52d9..9d035cfae 100644 --- a/src/lib/commands/cens.c +++ b/src/lib/commands/cens.c @@ -45,135 +45,132 @@ #include "commands.h" #include "optlist.h" -static void cens_hdr(void); +static void cens_hdr(void); int cens(void) { - struct sctstr sect; - int nsect; - int n; - struct nstr_sect nstr; - s_char dirstr[20]; - int vec[I_MAX+1]; + struct sctstr sect; + int nsect; + int n; + struct nstr_sect nstr; + s_char dirstr[20]; + int vec[I_MAX + 1]; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - for (n = 1; n <= 6; n++) - dirstr[n] = dirch[n]; - dirstr[0] = '.'; - dirstr[7] = '$'; - dirstr[8] = '\0'; - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) - cens_hdr(); - if (player->god) - pr("%3d ", sect.sct_own); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sect.sct_effic); - if (sect.sct_off) - pr(" no "); - else - pr(" "); - pr("%4d", sect.sct_mobil); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + for (n = 1; n <= 6; n++) + dirstr[n] = dirch[n]; + dirstr[0] = '.'; + dirstr[7] = '$'; + dirstr[8] = '\0'; + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) + cens_hdr(); + if (player->god) + pr("%3d ", sect.sct_own); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sect.sct_effic); + if (sect.sct_off) + pr(" no "); + else + pr(" "); + pr("%4d", sect.sct_mobil); - getvec(VT_DEL, vec, (s_char *)§, EF_SECTOR); - pr(" %c", dirstr[vec[I_UW] & 0x7]); - pr("%c", dirstr[vec[I_FOOD] & 0x7]); + getvec(VT_DEL, vec, (s_char *)§, EF_SECTOR); + pr(" %c", dirstr[vec[I_UW] & 0x7]); + pr("%c", dirstr[vec[I_FOOD] & 0x7]); - getvec(VT_DIST, vec, (s_char *)§, EF_SECTOR); - n = vec[I_UW] % 1000; - pr(" %c", n == 0 ? '.' : '0'+ (n/100)); - n = vec[I_FOOD] % 1000; - pr("%c ", n == 0 ? '.' : '0'+ (n/100)); - pr("%c", sect.sct_own != sect.sct_oldown ? '*' : ' '); + getvec(VT_DIST, vec, (s_char *)§, EF_SECTOR); + n = vec[I_UW] % 1000; + pr(" %c", n == 0 ? '.' : '0' + (n / 100)); + n = vec[I_FOOD] % 1000; + pr("%c ", n == 0 ? '.' : '0' + (n / 100)); + pr("%c", sect.sct_own != sect.sct_oldown ? '*' : ' '); - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - pr("%5d", vec[I_CIVIL]); - pr("%5d", vec[I_MILIT]); - pr("%5d", vec[I_UW]); - pr("%5d", vec[I_FOOD]); - pr("%4d%%", sect.sct_work); - pr("%5d", sect.sct_avail); - if (!player->god) { - if (sect.sct_terr) - pr("%4d", sect.sct_terr); - else - pr(" "); - } - if (opt_FALLOUT) { - getvec(VT_COND, vec, (void *)§, EF_SECTOR); - pr("%5d",vec[C_FALLOUT]); - } - set_coastal(§); - if (sect.sct_coastal) - pr("%4d", sect.sct_coastal); - pr("\n"); + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + pr("%5d", vec[I_CIVIL]); + pr("%5d", vec[I_MILIT]); + pr("%5d", vec[I_UW]); + pr("%5d", vec[I_FOOD]); + pr("%4d%%", sect.sct_work); + pr("%5d", sect.sct_avail); + if (!player->god) { + if (sect.sct_terr) + pr("%4d", sect.sct_terr); + else + pr(" "); + } + if (opt_FALLOUT) { + getvec(VT_COND, vec, (void *)§, EF_SECTOR); + pr("%5d", vec[C_FALLOUT]); } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + set_coastal(§); + if (sect.sct_coastal) + pr("%4d", sect.sct_coastal); + pr("\n"); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } static void cens_hdr(void) { - if (player->god) - pr(" "); - pr("CENSUS del dst\n"); - if (player->god) - pr("own "); - pr(" sect eff "); - pr("prd "); - pr("mob uf uf * civ mil uw food work avail "); - if (!player->god) - pr("ter "); - if (opt_FALLOUT) - pr("fall "); - pr("coa"); - pr("\n"); + if (player->god) + pr(" "); + pr("CENSUS del dst\n"); + if (player->god) + pr("own "); + pr(" sect eff "); + pr("prd "); + pr("mob uf uf * civ mil uw food work avail "); + if (!player->god) + pr("ter "); + if (opt_FALLOUT) + pr("fall "); + pr("coa"); + pr("\n"); } void set_coastal(struct sctstr *sp) { - int n; - struct sctstr sect; - u_char start_flags = sp->sct_coastal; + int n; + struct sctstr sect; + u_char start_flags = sp->sct_coastal; - /* It's already been set, it didn't change (you can't fill - in water, even with bridge spans they are still coastal.) */ - if (sp->sct_coastal) + /* It's already been set, it didn't change (you can't fill + in water, even with bridge spans they are still coastal.) */ + if (sp->sct_coastal) + return; + for (n = 1; n <= 6; ++n) { /* Directions */ + getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], §); + if (sect.sct_type == SCT_WATER || + sect.sct_type == SCT_BTOWER || sect.sct_type == SCT_BSPAN) { + sp->sct_coastal = 1; + if (start_flags != sp->sct_coastal) + putsect(sp); return; - for (n = 1; n <= 6; ++n) { /* Directions */ - getsect(sp->sct_x + diroff[n][0], - sp->sct_y + diroff[n][1], - §); - if (sect.sct_type == SCT_WATER || - sect.sct_type == SCT_BTOWER || - sect.sct_type == SCT_BSPAN) { - sp->sct_coastal = 1; - if (start_flags != sp->sct_coastal) - putsect(sp); - return; - } } - sp->sct_coastal = 0; - if (start_flags != sp->sct_coastal) - putsect(sp); + } + sp->sct_coastal = 0; + if (start_flags != sp->sct_coastal) + putsect(sp); } diff --git a/src/lib/commands/chan.c b/src/lib/commands/chan.c index a1b452b5a..411cb7ab0 100644 --- a/src/lib/commands/chan.c +++ b/src/lib/commands/chan.c @@ -45,91 +45,92 @@ int chan(void) { - s_char *temp; - struct natstr *natp; - register s_char *p; - natid cn; - int charge; - int nonb; - int btucost; - s_char buf[1024]; - struct natstr *us; + s_char *temp; + struct natstr *natp; + register s_char *p; + natid cn; + int charge; + int nonb; + int btucost; + s_char buf[1024]; + struct natstr *us; - if ((p = getstarg(player->argp[1], "country name or representative? ", buf)) == 0) - return RET_SYN; - us = getnatp(player->cnum); - if (us->nat_stat == VIS) { - pr("Visitor countries can't change their country name or representative.\n"); + if ((p = + getstarg(player->argp[1], "country name or representative? ", + buf)) == 0) + return RET_SYN; + us = getnatp(player->cnum); + if (us->nat_stat == VIS) { + pr("Visitor countries can't change their country name or representative.\n"); + return RET_FAIL; + } + switch (*p) { + case 'n': + case 'c': + charge = 0; + btucost = 0; + if (!player->god && (us->nat_stat & STAT_NORM)) { + if (us->nat_btu < 254) { + pr("You need 254 btus to change your country name!\n"); + return RET_FAIL; + } + if (opt_BLITZ == 0) { + pr("This command costs 254 BTU's and 10%% of your money.\n"); + if (!confirm("Are you sure you want to do this? ")) + return RET_FAIL; + btucost = 254; + /* charge = 2000; */ + /*if (us->nat_money < charge*10) */ + /* charge = us->nat_money / 10; */ + if (us->nat_money <= 0) + charge = 0; + else + charge = us->nat_money / 10; + } + } + if ((p = + getstarg(player->argp[2], "New country name -- ", buf)) == 0) + return RET_SYN; + p[sizeof(us->nat_cnam) - 1] = 0; + for (cn = 0; NULL != (natp = getnatp(cn)); cn++) { + if (same(p, natp->nat_cnam)) { + pr("Country #%d is already called `%s'!\n", cn, p); + return RET_FAIL; + } + } + nonb = 0; + for (temp = p; *temp != '\0'; temp++) { + if (iscntrl(*temp)) { + pr("No control characters allowed in country names!\n"); + return RET_FAIL; + } else if (*temp != ' ') + nonb = 1; + } + if (!nonb) { + pr("Must have a non-blank name!\n"); return RET_FAIL; } - switch (*p) { - case 'n': - case 'c': - charge = 0; - btucost = 0; - if (!player->god && (us->nat_stat & STAT_NORM)) { - if (us->nat_btu < 254) { - pr("You need 254 btus to change your country name!\n"); - return RET_FAIL; - } - if (opt_BLITZ == 0) { - pr("This command costs 254 BTU's and 10%% of your money.\n"); - if (!confirm("Are you sure you want to do this? ")) - return RET_FAIL; - btucost = 254; - /* charge = 2000; */ - /*if (us->nat_money < charge*10)*/ - /* charge = us->nat_money / 10;*/ - if (us->nat_money <= 0) - charge = 0; - else - charge = us->nat_money / 10; - } - } - if ((p = getstarg(player->argp[2], "New country name -- ", buf)) == 0) - return RET_SYN; - p[sizeof(us->nat_cnam)-1] = 0; - for (cn = 0; NULL != (natp = getnatp(cn)); cn++) { - if (same(p, natp->nat_cnam)) { - pr("Country #%d is already called `%s'!\n", - cn, p); - return RET_FAIL; - } - } - nonb = 0; - for (temp = p; *temp != '\0'; temp++) { - if (iscntrl(*temp)) { - pr("No control characters allowed in country names!\n"); - return RET_FAIL; - } else if (*temp != ' ') - nonb = 1; - } - if (!nonb) { - pr("Must have a non-blank name!\n"); - return RET_FAIL; - } - if (opt_BLITZ == 0) { - player->dolcost += charge; - player->btused += btucost; - } - strcpy(us->nat_cnam, p); - putnat(us); - nreport(player->cnum, N_NAME_CHNG, 0, 1); - break; - case 'p': - case 'r': - pr("(note: these are stored in plain text.)\n"); - if ((p = getstarg(player->argp[2], - "New representative name -- ", buf)) == 0) - return RET_SYN; - p[8] = 0; - strcpy(us->nat_pnam, p); - putnat(us); - break; - default: - pr("Only \"country\" or \"representative\" can change.\n"); - return RET_SYN; + if (opt_BLITZ == 0) { + player->dolcost += charge; + player->btused += btucost; } - return RET_OK; + strcpy(us->nat_cnam, p); + putnat(us); + nreport(player->cnum, N_NAME_CHNG, 0, 1); + break; + case 'p': + case 'r': + pr("(note: these are stored in plain text.)\n"); + if ((p = getstarg(player->argp[2], + "New representative name -- ", buf)) == 0) + return RET_SYN; + p[8] = 0; + strcpy(us->nat_pnam, p); + putnat(us); + break; + default: + pr("Only \"country\" or \"representative\" can change.\n"); + return RET_SYN; + } + return RET_OK; } - diff --git a/src/lib/commands/coas.c b/src/lib/commands/coas.c index fab689ae8..ff56b568e 100644 --- a/src/lib/commands/coas.c +++ b/src/lib/commands/coas.c @@ -47,13 +47,13 @@ #define TSIZE 200 struct coast { - struct coast *c_next; - int c_spotted; - int c_number; - struct shpstr c_shp; + struct coast *c_next; + int c_spotted; + int c_number; + struct shpstr c_shp; }; -static int showship(struct coast **cpp, int x, int y); +static int showship(struct coast **cpp, int x, int y); /* * format: coastwatch [] @@ -61,119 +61,119 @@ static int showship(struct coast **cpp, int x, int y); int coas(void) { - struct sctstr sect; - struct nstr_sect nstr; - struct coast *cp; - struct coast *list[TSIZE]; - int i, k, j, n; - int vrange, see; - int x, y; - int mink, minj, maxk, maxj; - int nship = 0; - float tech; - struct nstr_item ni; + struct sctstr sect; + struct nstr_sect nstr; + struct coast *cp; + struct coast *list[TSIZE]; + int i, k, j, n; + int vrange, see; + int x, y; + int mink, minj, maxk, maxj; + int nship = 0; + float tech; + struct nstr_item ni; - if (snxtsct(&nstr, player->argp[1]) == 0) - return RET_SYN; - for (i = 0; i < TSIZE; i++) - list[i] = 0; + if (snxtsct(&nstr, player->argp[1]) == 0) + return RET_SYN; + for (i = 0; i < TSIZE; i++) + list[i] = 0; + cp = (struct coast *)malloc(sizeof(*cp)); + snxtitem_all(&ni, EF_SHIP); + while (nxtitem(&ni, (s_char *)&cp->c_shp)) { + if (cp->c_shp.shp_own == 0 || cp->c_shp.shp_own == player->cnum) + continue; + /* + * don't bother putting subs in the table... + * unless they're in a sector you own (harbor or such) + */ + getsect(cp->c_shp.shp_x, cp->c_shp.shp_y, §); + if ((mchr[(int)cp->c_shp.shp_type].m_flags & M_SUB) && + (sect.sct_own != player->cnum)) + continue; + n = scthash(cp->c_shp.shp_x, cp->c_shp.shp_y, TSIZE); + cp->c_spotted = 0; + cp->c_number = i; + cp->c_next = list[n]; + list[n] = cp; cp = (struct coast *)malloc(sizeof(*cp)); - snxtitem_all(&ni, EF_SHIP); - while (nxtitem(&ni, (s_char *) &cp->c_shp)) { - if (cp->c_shp.shp_own == 0 || cp->c_shp.shp_own == player->cnum) - continue; - /* - * don't bother putting subs in the table... - * unless they're in a sector you own (harbor or such) - */ - getsect(cp->c_shp.shp_x, cp->c_shp.shp_y, §); - if ((mchr[(int)cp->c_shp.shp_type].m_flags & M_SUB) && - (sect.sct_own != player->cnum)) - continue; - n = scthash(cp->c_shp.shp_x, cp->c_shp.shp_y, TSIZE); - cp->c_spotted = 0; - cp->c_number = i; - cp->c_next = list[n]; - list[n] = cp; - cp = (struct coast *)malloc(sizeof(*cp)); - nship++; + nship++; + } + /* get that last one! */ + free((s_char *)cp); + pr("- = [ Coastwatch report for %s ] = -\n", cname(player->cnum)); + pr(" Country Ship Location\n"); + tech = tfact(player->cnum, 1.0); + while (nxtsct(&nstr, §) && nship) { + if (sect.sct_own != player->cnum) + continue; + see = sect.sct_type == SCT_RADAR ? 14 : 4; + vrange = (int)(sect.sct_effic / 100.0 * see * tech); + if (vrange < 1) + vrange = 1; + maxk = vrange; + maxj = vrange * 2; + vrange *= vrange; + mink = -maxk; + minj = -maxj; + for (j = minj; j <= maxj && nship; j++) { + x = xnorm(sect.sct_x + j); + for (k = mink; k <= maxk && nship; k++) { + if ((j + k) & 01) + continue; + /* quick range check to save time... */ + if (vrange < (j * j + 3 * k * k) / 4) + continue; + y = ynorm(sect.sct_y + k); + n = scthash(x, y, TSIZE); + if (list[n] == 0) + continue; + nship -= showship(&list[n], x, y); + } } - /* get that last one! */ - free((s_char *)cp); - pr("- = [ Coastwatch report for %s ] = -\n", cname(player->cnum)); - pr(" Country Ship Location\n"); - tech = tfact(player->cnum, 1.0); - while (nxtsct(&nstr, §) && nship) { - if (sect.sct_own != player->cnum) - continue; - see = sect.sct_type == SCT_RADAR ? 14 : 4; - vrange = (int) (sect.sct_effic / 100.0 * see * tech); - if (vrange < 1) - vrange = 1; - maxk = vrange; - maxj = vrange * 2; - vrange *= vrange; - mink = -maxk; - minj = -maxj; - for (j = minj; j <= maxj && nship; j++) { - x = xnorm(sect.sct_x + j); - for (k = mink; k <= maxk && nship; k++) { - if ((j + k) & 01) - continue; - /* quick range check to save time... */ - if (vrange < (j * j + 3 * k * k) / 4) - continue; - y = ynorm(sect.sct_y + k); - n = scthash(x, y, TSIZE); - if (list[n] == 0) - continue; - nship -= showship(&list[n], x, y); - } - } + } + /* free up the coast structs calloc'ed above */ + for (i = 0; i < TSIZE; i++) { + while (NULL != (cp = list[i])) { + list[i] = cp->c_next; + free((s_char *)cp); } - /* free up the coast structs calloc'ed above */ - for (i = 0; i < TSIZE; i++) { - while (NULL != (cp = list[i])) { - list[i] = cp->c_next; - free((s_char *)cp); - } - } - return RET_OK; + } + return RET_OK; } static int showship(struct coast **cpp, int x, int y) { - register struct coast *cp; - register struct coast *todelete = 0; - register struct coast **prev; - int nship = 0; + register struct coast *cp; + register struct coast *todelete = 0; + register struct coast **prev; + int nship = 0; - prev = 0; - cp = *cpp; - prev = cpp; - do { - /* we delete it, we free it. */ - if (todelete) { - free((s_char *)todelete); - todelete = 0; - } - if (cp->c_shp.shp_x != x || cp->c_shp.shp_y != y) { - prev = &(*prev)->c_next; - continue; - } - pr(" %12.12s (#%3d) %s @ %s\n", - cname(cp->c_shp.shp_own), cp->c_shp.shp_own, - prship(&cp->c_shp), xyas(x, y, player->cnum)); - if (opt_HIDDEN) { - setcont(player->cnum, cp->c_shp.shp_own, FOUND_COAST); - } - *prev = cp->c_next; - todelete = cp; - nship++; - } while (NULL != (cp = cp->c_next)); - /* check that last one! */ - if (todelete) - free((s_char *)todelete); - return (nship); + prev = 0; + cp = *cpp; + prev = cpp; + do { + /* we delete it, we free it. */ + if (todelete) { + free((s_char *)todelete); + todelete = 0; + } + if (cp->c_shp.shp_x != x || cp->c_shp.shp_y != y) { + prev = &(*prev)->c_next; + continue; + } + pr(" %12.12s (#%3d) %s @ %s\n", + cname(cp->c_shp.shp_own), cp->c_shp.shp_own, + prship(&cp->c_shp), xyas(x, y, player->cnum)); + if (opt_HIDDEN) { + setcont(player->cnum, cp->c_shp.shp_own, FOUND_COAST); + } + *prev = cp->c_next; + todelete = cp; + nship++; + } while (NULL != (cp = cp->c_next)); + /* check that last one! */ + if (todelete) + free((s_char *)todelete); + return (nship); } diff --git a/src/lib/commands/coll.c b/src/lib/commands/coll.c index 496e23a63..532b4fb51 100644 --- a/src/lib/commands/coll.c +++ b/src/lib/commands/coll.c @@ -49,133 +49,135 @@ int coll(void) { - register int arg; - register int i; - register int val; - time_t now; - s_char *p; - struct lonstr loan; - struct sctstr sect; - coord x, y; - long due; - long last; - long rdur; - long xdur; - double rate; - double owed; - double pay; - s_char buf[1024]; - int vec[I_MAX+1]; + register int arg; + register int i; + register int val; + time_t now; + s_char *p; + struct lonstr loan; + struct sctstr sect; + coord x, y; + long due; + long last; + long rdur; + long xdur; + double rate; + double owed; + double pay; + s_char buf[1024]; + int vec[I_MAX + 1]; - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; - } - if ((arg = onearg(player->argp[1], "Collect on loan #")) < 0) - return RET_SYN; - /* Check if it's a valid loan. That means, is it a valid loan, - owed to this player, with a valid duration and it's been signed. */ - if (!getloan(arg,&loan) || (loan.l_loner != player->cnum) || - (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) { - pr("You aren't owed anything on that loan...\n"); - return RET_FAIL; - } - /* If we got here, we check to see if it's been defaulted on. We - already know it's owed to this player. */ - (void) time(&now); - due = loan.l_duedate; - if (now <= due) { - pr("There has been no default on loan %d\n", arg); - return RET_FAIL; - } - last = loan.l_lastpay; - if (last < due && due < now) { - rdur = due - last; - xdur = now - due; - } else if (due < last) { - rdur = 0; - xdur = now - last; - } - rate = loan.l_irate / (loan.l_ldur * 8.64e6); + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; + } + if ((arg = onearg(player->argp[1], "Collect on loan #")) < 0) + return RET_SYN; + /* Check if it's a valid loan. That means, is it a valid loan, + owed to this player, with a valid duration and it's been signed. */ + if (!getloan(arg, &loan) || (loan.l_loner != player->cnum) || + (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) { + pr("You aren't owed anything on that loan...\n"); + return RET_FAIL; + } + /* If we got here, we check to see if it's been defaulted on. We + already know it's owed to this player. */ + (void)time(&now); + due = loan.l_duedate; + if (now <= due) { + pr("There has been no default on loan %d\n", arg); + return RET_FAIL; + } + last = loan.l_lastpay; + if (last < due && due < now) { + rdur = due - last; + xdur = now - due; + } else if (due < last) { + rdur = 0; + xdur = now - last; + } + rate = loan.l_irate / (loan.l_ldur * 8.64e6); /* changed following to avoid overflow 3/27/89 bailey@math-cs.kent.edu owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0) * loan.l_amtdue; Begin overflow fix */ - owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0); - if (((1 << 30) / owed) < loan.l_amtdue) - owed = (1 << 30); - else - owed *= loan.l_amtdue; + owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0); + if (((1 << 30) / owed) < loan.l_amtdue) + owed = (1 << 30); + else + owed *= loan.l_amtdue; /* End overflow fix */ - pr("You are owed $%.2f on that loan.\n", owed); - if (!(p = getstarg(player->argp[2], "What sector do you wish to confiscate? ", buf))) - return RET_SYN; - if (!check_loan_ok(&loan)) - return RET_FAIL; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, §)) - return RET_SYN; - if (!neigh(x, y, player->cnum)) { - pr("You are not adjacent to %s\n", xyas(x, y, player->cnum)); - return RET_FAIL; - } - if (sect.sct_own != loan.l_lonee) { - pr("%s is not owned by %s.\n", - xyas(x, y, player->cnum), cname(loan.l_lonee)); - return RET_FAIL; - } - pay = dchr[sect.sct_type].d_value * ((float)sect.sct_effic + 100.0); - for (i = 0; ichr[i].i_name; i++) { - if (ichr[i].i_value == 0 || ichr[i].i_vtype == 0) - continue; - val = getvar(ichr[i].i_vtype, (s_char *)§, EF_SECTOR); - pay += val * ichr[i].i_value; - } - pr("That sector (and its contents) is valued at $%.2f\n", pay); - if (pay > owed * 1.2) { - pr("That is more than is owed!\n"); - return RET_FAIL; - } - if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT) - caploss(§, sect.sct_own, "that was %s's capital!\n"); - putvar(V_MILIT, 1, (s_char *)§, EF_SECTOR); + pr("You are owed $%.2f on that loan.\n", owed); + if (! + (p = + getstarg(player->argp[2], + "What sector do you wish to confiscate? ", buf))) + return RET_SYN; + if (!check_loan_ok(&loan)) + return RET_FAIL; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, §)) + return RET_SYN; + if (!neigh(x, y, player->cnum)) { + pr("You are not adjacent to %s\n", xyas(x, y, player->cnum)); + return RET_FAIL; + } + if (sect.sct_own != loan.l_lonee) { + pr("%s is not owned by %s.\n", + xyas(x, y, player->cnum), cname(loan.l_lonee)); + return RET_FAIL; + } + pay = dchr[sect.sct_type].d_value * ((float)sect.sct_effic + 100.0); + for (i = 0; ichr[i].i_name; i++) { + if (ichr[i].i_value == 0 || ichr[i].i_vtype == 0) + continue; + val = getvar(ichr[i].i_vtype, (s_char *)§, EF_SECTOR); + pay += val * ichr[i].i_value; + } + pr("That sector (and its contents) is valued at $%.2f\n", pay); + if (pay > owed * 1.2) { + pr("That is more than is owed!\n"); + return RET_FAIL; + } + if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT) + caploss(§, sect.sct_own, "that was %s's capital!\n"); + putvar(V_MILIT, 1, (s_char *)§, EF_SECTOR); /* Consider modifying takeover to take a "no che" argument and putting using it here again. */ /* (void) takeover(§, player->cnum);*/ - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - makenotlost(EF_SECTOR, player->cnum, 0, sect.sct_x, sect.sct_y); - sect.sct_own = player->cnum; + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); + makenotlost(EF_SECTOR, player->cnum, 0, sect.sct_x, sect.sct_y); + sect.sct_own = player->cnum; - bzero((s_char *)vec, sizeof(vec)); - putvec(VT_DIST, vec, (s_char *)§, EF_SECTOR); - putvec(VT_DEL, vec, (s_char *)§, EF_SECTOR); - sect.sct_off = 1; - sect.sct_dist_x = sect.sct_x; - sect.sct_dist_y = sect.sct_y; + bzero((s_char *)vec, sizeof(vec)); + putvec(VT_DIST, vec, (s_char *)§, EF_SECTOR); + putvec(VT_DEL, vec, (s_char *)§, EF_SECTOR); + sect.sct_off = 1; + sect.sct_dist_x = sect.sct_x; + sect.sct_dist_y = sect.sct_y; - putsect(§); - nreport(player->cnum, N_SEIZE_SECT, loan.l_lonee, 1); - if (pay >= owed) { - loan.l_ldur = 0; - nreport(loan.l_lonee, N_REPAY_LOAN, player->cnum, 1); - wu(0, loan.l_lonee, - "%s seized %s to satisfy loan #%d\n", - cname(player->cnum), - xyas(sect.sct_x, sect.sct_y, loan.l_lonee), - arg); - pr("That loan is now considered repaid.\n"); - } else { - (void) time(&loan.l_lastpay); - owed -= pay; - loan.l_amtdue = (long) owed; - pay += loan.l_amtpaid; - loan.l_amtpaid = pay; - wu(0, loan.l_lonee, - "%s seized %s in partial payment of loan %d.\n", - cname(player->cnum), - xyas(sect.sct_x, sect.sct_y, loan.l_lonee), arg); - pr("You are still owed $%.2f on loan %d.\n", owed, arg); - } - putloan(arg, &loan); - return RET_OK; + putsect(§); + nreport(player->cnum, N_SEIZE_SECT, loan.l_lonee, 1); + if (pay >= owed) { + loan.l_ldur = 0; + nreport(loan.l_lonee, N_REPAY_LOAN, player->cnum, 1); + wu(0, loan.l_lonee, + "%s seized %s to satisfy loan #%d\n", + cname(player->cnum), + xyas(sect.sct_x, sect.sct_y, loan.l_lonee), arg); + pr("That loan is now considered repaid.\n"); + } else { + (void)time(&loan.l_lastpay); + owed -= pay; + loan.l_amtdue = (long)owed; + pay += loan.l_amtpaid; + loan.l_amtpaid = pay; + wu(0, loan.l_lonee, + "%s seized %s in partial payment of loan %d.\n", + cname(player->cnum), + xyas(sect.sct_x, sect.sct_y, loan.l_lonee), arg); + pr("You are still owed $%.2f on loan %d.\n", owed, arg); + } + putloan(arg, &loan); + return RET_OK; } diff --git a/src/lib/commands/comm.c b/src/lib/commands/comm.c index 87c223cdb..6eeacd52b 100644 --- a/src/lib/commands/comm.c +++ b/src/lib/commands/comm.c @@ -43,24 +43,24 @@ #include "file.h" #include "commands.h" -static void prthresh(s_char *format, int val); +static void prthresh(s_char *format, int val); int comm(void) { - struct sctstr sect; - s_char dirstr[12]; - int nsect; - int n; - struct nstr_sect nstr; - int del[I_MAX+1]; - int dist[I_MAX+1]; - int item[I_MAX+1]; - + struct sctstr sect; + s_char dirstr[12]; + int nsect; + int n; + struct nstr_sect nstr; + int del[I_MAX + 1]; + int dist[I_MAX + 1]; + int item[I_MAX + 1]; + if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; prdate(); - (void) strcpy(dirstr, ". $"); + (void)strcpy(dirstr, ". $"); n = 1; for (n = 1; n <= 6; n++) dirstr[n] = dirch[n]; @@ -121,7 +121,7 @@ comm(void) else pr("%s: No sector(s)\n", ""); return RET_FAIL; - }else + } else pr("%d sector%s\n", nsect, splur(nsect)); return 0; } @@ -137,5 +137,3 @@ prthresh(s_char *format, int val) val = '.'; pr(format, val); } - - diff --git a/src/lib/commands/cons.c b/src/lib/commands/cons.c index 37bb99db2..b0b713e31 100644 --- a/src/lib/commands/cons.c +++ b/src/lib/commands/cons.c @@ -47,18 +47,18 @@ * Things common to a loan or treaty. */ struct ltcomstr { - int type; /* EF_LOAN or EF_TREATY */ - int num; /* number */ - s_char *name; /* "loan" or "treaty" */ - s_char *Name; /* "Loan" or "Treaty" */ - natid proposer; /* country offering */ - natid proposee; /* country offered to */ - natid mailee; /* who gets mail about it */ - s_char op; /* 'a', 'd', or 'p' */ - union { - struct lonstr l; /* the loan */ - struct trtstr t; /* the treaty */ - } u; + int type; /* EF_LOAN or EF_TREATY */ + int num; /* number */ + s_char *name; /* "loan" or "treaty" */ + s_char *Name; /* "Loan" or "Treaty" */ + natid proposer; /* country offering */ + natid proposee; /* country offered to */ + natid mailee; /* who gets mail about it */ + s_char op; /* 'a', 'd', or 'p' */ + union { + struct lonstr l; /* the loan */ + struct trtstr t; /* the treaty */ + } u; }; static int cons_choose(struct ltcomstr *ltcp); @@ -75,32 +75,31 @@ static void prev_signed(struct ltcomstr *ltcp); int cons(void) { - int rv; - struct ltcomstr ltc; + int rv; + struct ltcomstr ltc; - rv = cons_choose(<c); - if (rv != RET_OK) - return rv; + rv = cons_choose(<c); + if (rv != RET_OK) + return rv; - switch (ltc.op) { - case 'a': - rv = (ltc.type == EF_TREATY) ? treaty_accept(<c) - : loan_accept(<c); - break; - case 'd': - rv = (ltc.type == EF_TREATY) ? treaty_decline(<c) - : loan_decline(<c); - break; - case 'p': - rv = postpone(<c); - break; - default: - pr("Bad operation %c from cons_choose; get help!\n", - ltc.op); - break; - }; + switch (ltc.op) { + case 'a': + rv = (ltc.type == EF_TREATY) ? treaty_accept(<c) + : loan_accept(<c); + break; + case 'd': + rv = (ltc.type == EF_TREATY) ? treaty_decline(<c) + : loan_decline(<c); + break; + case 'p': + rv = postpone(<c); + break; + default: + pr("Bad operation %c from cons_choose; get help!\n", ltc.op); + break; + }; - return rv; + return rv; } /* @@ -111,83 +110,83 @@ cons(void) static int cons_choose(struct ltcomstr *ltcp) { - s_char *p; - extern int disloan(); - extern int distrea(); - int (*dis)(); - struct lonstr *lp; - struct trtstr *tp; - s_char prompt[128]; - s_char buf[1024]; + s_char *p; + extern int disloan(); + extern int distrea(); + int (*dis) (); + struct lonstr *lp; + struct trtstr *tp; + s_char prompt[128]; + s_char buf[1024]; - bzero((s_char *)ltcp, sizeof (*ltcp)); - if (getstarg(player->argp[1], "loan or treaty? ", buf) == 0) - return RET_SYN; - ltcp->type = ef_byname(buf); - switch (ltcp->type) { - case EF_TREATY: - if (!opt_TREATIES) { - pr("Treaties are not enabled.\n"); - return RET_FAIL; - } - ltcp->name = "treaty"; - ltcp->Name = "Treaty"; - dis = distrea; - break; - case EF_LOAN: - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; - } - ltcp->name = "loan"; - ltcp->Name = "Loan"; - dis = disloan; - break; - default: - pr("You must specify \"loan\" or \"treaty\".\n"); - return RET_SYN; + bzero((s_char *)ltcp, sizeof(*ltcp)); + if (getstarg(player->argp[1], "loan or treaty? ", buf) == 0) + return RET_SYN; + ltcp->type = ef_byname(buf); + switch (ltcp->type) { + case EF_TREATY: + if (!opt_TREATIES) { + pr("Treaties are not enabled.\n"); + return RET_FAIL; } - sprintf(prompt, "%s number? ", ltcp->Name); - if ((ltcp->num = onearg(player->argp[2], prompt)) < 0) - return RET_SYN; - if (!ef_read(ltcp->type, ltcp->num, (caddr_t)<cp->u) || - !(*dis)(ltcp->num, <cp->u)) { - pr("%s #%d is not being offered to you!\n", - ltcp->Name, ltcp->num); - return RET_SYN; + ltcp->name = "treaty"; + ltcp->Name = "Treaty"; + dis = distrea; + break; + case EF_LOAN: + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; } - switch (ltcp->type) { - case EF_LOAN: - lp = <cp->u.l; - if (lp->l_status == LS_SIGNED) { - pr("That loan has already been accepted!\n"); - return RET_FAIL; - } - ltcp->proposer = lp->l_loner; - ltcp->proposee = lp->l_lonee; - break; - case EF_TREATY: - tp = <cp->u.t; - if (tp->trt_status == TS_SIGNED) { - pr("That treaty has already been accepted!\n"); - return RET_FAIL; - } - ltcp->proposer = tp->trt_cna; - ltcp->proposee = tp->trt_cnb; - break; + ltcp->name = "loan"; + ltcp->Name = "Loan"; + dis = disloan; + break; + default: + pr("You must specify \"loan\" or \"treaty\".\n"); + return RET_SYN; + } + sprintf(prompt, "%s number? ", ltcp->Name); + if ((ltcp->num = onearg(player->argp[2], prompt)) < 0) + return RET_SYN; + if (!ef_read(ltcp->type, ltcp->num, (caddr_t)<cp->u) || + !(*dis) (ltcp->num, <cp->u)) { + pr("%s #%d is not being offered to you!\n", ltcp->Name, ltcp->num); + return RET_SYN; + } + switch (ltcp->type) { + case EF_LOAN: + lp = <cp->u.l; + if (lp->l_status == LS_SIGNED) { + pr("That loan has already been accepted!\n"); + return RET_FAIL; } - ltcp->mailee = (ltcp->proposer == player->cnum) - ? ltcp->proposee : ltcp->proposer; - while ((p = getstarg(player->argp[3], "Accept, decline or postpone? ", buf)) && *p) -{ - if (*p == 'a' || *p == 'd' || *p == 'p') - break; - player->argp[3] = 0; + ltcp->proposer = lp->l_loner; + ltcp->proposee = lp->l_lonee; + break; + case EF_TREATY: + tp = <cp->u.t; + if (tp->trt_status == TS_SIGNED) { + pr("That treaty has already been accepted!\n"); + return RET_FAIL; } - if (p == 0 || *p == 0) - return RET_SYN; - ltcp->op = *p; - return RET_OK; + ltcp->proposer = tp->trt_cna; + ltcp->proposee = tp->trt_cnb; + break; + } + ltcp->mailee = (ltcp->proposer == player->cnum) + ? ltcp->proposee : ltcp->proposer; + while ((p = + getstarg(player->argp[3], "Accept, decline or postpone? ", + buf)) && *p) { + if (*p == 'a' || *p == 'd' || *p == 'p') + break; + player->argp[3] = 0; + } + if (p == 0 || *p == 0) + return RET_SYN; + ltcp->op = *p; + return RET_OK; } /* @@ -198,60 +197,59 @@ cons_choose(struct ltcomstr *ltcp) static int loan_accept(struct ltcomstr *ltcp) { - struct lonstr *lp; - struct natstr *lender; - struct nstr_item nstr; - struct lonstr loan; + struct lonstr *lp; + struct natstr *lender; + struct nstr_item nstr; + struct lonstr loan; - lp = <cp->u.l; - if (ltcp->proposee != player->cnum) { - pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); - return RET_OK; - } - if (!getloan(ltcp->num, (caddr_t)lp)) { - pr("loan_accept: can't read loan; get help!\n"); - return RET_SYS; - } - if (lp->l_status == LS_FREE) { /* other guy retratcted already */ - late(ltcp); - return RET_OK; - } - if (lp->l_status == LS_SIGNED) { /* already signed somehow */ - prev_signed(ltcp); - return RET_OK; - } - /* check to see if a loan already exists */ - snxtitem_all(&nstr, EF_LOAN); - while (nxtitem(&nstr, (s_char *) &loan)) { - if (loan.l_status == LS_SIGNED && loan.l_lonee == lp->l_loner - && (loan.l_loner == lp->l_lonee)) { - pr("He already owes you money - make him repay his loan!\n"); - return RET_OK; - } - } - lender = getnatp(ltcp->proposer); - if (lender->nat_money < lp->l_amtdue) { /* other guy is poor */ - lp->l_amtdue = lender->nat_money - 100; - pr("%s no longer has the funds.\n", cname(ltcp->proposer)); - if (lp->l_amtdue <= 0) - return RET_FAIL; - pr("You may borrow $%d at the same terms.\n", - lp->l_amtdue); - } - lender->nat_money -= lp->l_amtdue; - putnat(lender); - player->dolcost -= lp->l_amtdue; - lp->l_amtpaid = 0; - (void) time(&lp->l_lastpay); - lp->l_duedate = lp->l_ldur * 86400 + lp->l_lastpay; - lp->l_status = LS_SIGNED; - if (!putloan(ltcp->num, (s_char *)lp)) { - pr("Problem writing lp->to disk; get help!\n"); - return RET_FAIL; - } - accpt(ltcp); - pr("You are now $%d richer (sort of).\n", lp->l_amtdue); + lp = <cp->u.l; + if (ltcp->proposee != player->cnum) { + pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); + return RET_OK; + } + if (!getloan(ltcp->num, (caddr_t)lp)) { + pr("loan_accept: can't read loan; get help!\n"); + return RET_SYS; + } + if (lp->l_status == LS_FREE) { /* other guy retratcted already */ + late(ltcp); + return RET_OK; + } + if (lp->l_status == LS_SIGNED) { /* already signed somehow */ + prev_signed(ltcp); return RET_OK; + } + /* check to see if a loan already exists */ + snxtitem_all(&nstr, EF_LOAN); + while (nxtitem(&nstr, (s_char *)&loan)) { + if (loan.l_status == LS_SIGNED && loan.l_lonee == lp->l_loner + && (loan.l_loner == lp->l_lonee)) { + pr("He already owes you money - make him repay his loan!\n"); + return RET_OK; + } + } + lender = getnatp(ltcp->proposer); + if (lender->nat_money < lp->l_amtdue) { /* other guy is poor */ + lp->l_amtdue = lender->nat_money - 100; + pr("%s no longer has the funds.\n", cname(ltcp->proposer)); + if (lp->l_amtdue <= 0) + return RET_FAIL; + pr("You may borrow $%d at the same terms.\n", lp->l_amtdue); + } + lender->nat_money -= lp->l_amtdue; + putnat(lender); + player->dolcost -= lp->l_amtdue; + lp->l_amtpaid = 0; + (void)time(&lp->l_lastpay); + lp->l_duedate = lp->l_ldur * 86400 + lp->l_lastpay; + lp->l_status = LS_SIGNED; + if (!putloan(ltcp->num, (s_char *)lp)) { + pr("Problem writing lp->to disk; get help!\n"); + return RET_FAIL; + } + accpt(ltcp); + pr("You are now $%d richer (sort of).\n", lp->l_amtdue); + return RET_OK; } /* @@ -260,25 +258,25 @@ loan_accept(struct ltcomstr *ltcp) static int loan_decline(struct ltcomstr *ltcp) { - struct lonstr *lp; + struct lonstr *lp; - lp = <cp->u.l; - if (!getloan(ltcp->num, lp)) { - pr("Decline: can't read loan; get help!\n"); - return RET_SYS; - } - /* loan got accepted somehow between now and last time we checked */ - if (lp->l_status == LS_SIGNED) { - late(ltcp); - return RET_OK; - } - lp->l_status = LS_FREE; - if (!putloan(ltcp->num, lp)) { - pr("loan_decline: can't write loan; get help!\n"); - return RET_SYS; - } - decline(ltcp); + lp = <cp->u.l; + if (!getloan(ltcp->num, lp)) { + pr("Decline: can't read loan; get help!\n"); + return RET_SYS; + } + /* loan got accepted somehow between now and last time we checked */ + if (lp->l_status == LS_SIGNED) { + late(ltcp); return RET_OK; + } + lp->l_status = LS_FREE; + if (!putloan(ltcp->num, lp)) { + pr("loan_decline: can't write loan; get help!\n"); + return RET_SYS; + } + decline(ltcp); + return RET_OK; } /* @@ -287,33 +285,33 @@ loan_decline(struct ltcomstr *ltcp) static int treaty_accept(struct ltcomstr *ltcp) { - struct trtstr *tp; + struct trtstr *tp; - tp = <cp->u.t; - if (ltcp->proposee != player->cnum) { - pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); - return RET_OK; - } - if (!gettre(ltcp->num, tp)) { - pr("Accept: can't read treaty; get help!\n"); - return RET_SYS; - } - if (tp->trt_status == TS_FREE) { /* treaty offer withdrawn */ - late(ltcp); - return RET_OK; - } - if (tp->trt_status == TS_SIGNED) { /* somehow got accepted */ - prev_signed(ltcp); - return RET_OK; - } - tp->trt_status = TS_SIGNED; - if (!puttre(ltcp->num, tp)) { - pr("Problem saving treaty; get help!\n"); - return RET_SYS; - } - accpt(ltcp); - pr("Treaty in effect until %s", ctime(&tp->trt_exp)); + tp = <cp->u.t; + if (ltcp->proposee != player->cnum) { + pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); return RET_OK; + } + if (!gettre(ltcp->num, tp)) { + pr("Accept: can't read treaty; get help!\n"); + return RET_SYS; + } + if (tp->trt_status == TS_FREE) { /* treaty offer withdrawn */ + late(ltcp); + return RET_OK; + } + if (tp->trt_status == TS_SIGNED) { /* somehow got accepted */ + prev_signed(ltcp); + return RET_OK; + } + tp->trt_status = TS_SIGNED; + if (!puttre(ltcp->num, tp)) { + pr("Problem saving treaty; get help!\n"); + return RET_SYS; + } + accpt(ltcp); + pr("Treaty in effect until %s", ctime(&tp->trt_exp)); + return RET_OK; } /* @@ -322,25 +320,25 @@ treaty_accept(struct ltcomstr *ltcp) static int treaty_decline(struct ltcomstr *ltcp) { - struct trtstr *tp; + struct trtstr *tp; - tp = <cp->u.t; - if (!gettre(ltcp->num, tp)) { - pr("Decline: can't read treaty; get help!\n"); - return RET_SYS; - } - /* treaty got signed somehow between now and last time we read it */ - if (tp->trt_status == TS_SIGNED) { - late(ltcp); - return RET_OK; - } - tp->trt_status = TS_FREE; - if (!puttre(ltcp->num, tp)) { - pr("Problem saving treaty; get help!\n"); - return RET_SYS; - } - decline(ltcp); + tp = <cp->u.t; + if (!gettre(ltcp->num, tp)) { + pr("Decline: can't read treaty; get help!\n"); + return RET_SYS; + } + /* treaty got signed somehow between now and last time we read it */ + if (tp->trt_status == TS_SIGNED) { + late(ltcp); return RET_OK; + } + tp->trt_status = TS_FREE; + if (!puttre(ltcp->num, tp)) { + pr("Problem saving treaty; get help!\n"); + return RET_SYS; + } + decline(ltcp); + return RET_OK; } /* @@ -349,11 +347,11 @@ treaty_decline(struct ltcomstr *ltcp) static int postpone(struct ltcomstr *ltcp) { - pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); - if (ltcp->proposee == player->cnum) - wu(0, ltcp->proposer, "%s %d considered by %s\n", - ltcp->name, ltcp->num, cname(player->cnum)); - return RET_OK; + pr("%s %d is still pending.\n", ltcp->Name, ltcp->num); + if (ltcp->proposee == player->cnum) + wu(0, ltcp->proposer, "%s %d considered by %s\n", + ltcp->name, ltcp->num, cname(player->cnum)); + return RET_OK; } /* @@ -363,9 +361,9 @@ postpone(struct ltcomstr *ltcp) static void late(struct ltcomstr *ltcp) { - pr("Too late; that %s %s!\n", ltcp->name, - (ltcp->op == 'a') ? "is no longer being offered" - : "has already been accepted"); + pr("Too late; that %s %s!\n", ltcp->name, + (ltcp->op == 'a') ? "is no longer being offered" + : "has already been accepted"); } /* @@ -374,7 +372,7 @@ late(struct ltcomstr *ltcp) static void prev_signed(struct ltcomstr *ltcp) { - pr("%s #%d is already in effect.\n", ltcp->Name, ltcp->num); + pr("%s #%d is already in effect.\n", ltcp->Name, ltcp->num); } /* @@ -384,17 +382,16 @@ prev_signed(struct ltcomstr *ltcp) static void decline(struct ltcomstr *ltcp) { - if (ltcp->proposee == player->cnum) { - wu(0, ltcp->proposer, "%s %d refused by %s\n", - ltcp->Name, ltcp->num, cname(player->cnum)); - pr("%s %d refused.\n", ltcp->Name, ltcp->num); - } else { - wu(0, ltcp->proposee, - "%s offer %d retracted by %s\n", - ltcp->Name, ltcp->num, cname(player->cnum)); - pr("%s offer %d retracted.\n", - ltcp->Name, ltcp->num); - } + if (ltcp->proposee == player->cnum) { + wu(0, ltcp->proposer, "%s %d refused by %s\n", + ltcp->Name, ltcp->num, cname(player->cnum)); + pr("%s %d refused.\n", ltcp->Name, ltcp->num); + } else { + wu(0, ltcp->proposee, + "%s offer %d retracted by %s\n", + ltcp->Name, ltcp->num, cname(player->cnum)); + pr("%s offer %d retracted.\n", ltcp->Name, ltcp->num); + } } /* @@ -405,10 +402,10 @@ decline(struct ltcomstr *ltcp) static void accpt(struct ltcomstr *ltcp) { - if (ltcp->type == EF_LOAN) - nreport(ltcp->proposer, N_MAKE_LOAN, player->cnum, 1); - else - nreport(player->cnum, N_SIGN_TRE, ltcp->mailee, 1); - wu(0, ltcp->mailee, "%s #%d accepted by %s\n", - ltcp->Name, ltcp->num, cname(player->cnum)); + if (ltcp->type == EF_LOAN) + nreport(ltcp->proposer, N_MAKE_LOAN, player->cnum, 1); + else + nreport(player->cnum, N_SIGN_TRE, ltcp->mailee, 1); + wu(0, ltcp->mailee, "%s #%d accepted by %s\n", + ltcp->Name, ltcp->num, cname(player->cnum)); } diff --git a/src/lib/commands/conv.c b/src/lib/commands/conv.c index f4ccdedf2..ddb265d29 100644 --- a/src/lib/commands/conv.c +++ b/src/lib/commands/conv.c @@ -51,137 +51,136 @@ long do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real); int conv(void) { - struct natstr *natp; - long cash; - long cost; - struct nstr_sect nstr; - int uwtoconvert; + struct natstr *natp; + long cash; + long cost; + struct nstr_sect nstr; + int uwtoconvert; - natp = getnatp(player->cnum); - cash = natp->nat_money; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - uwtoconvert = onearg(player->argp[2], "Number to convert: "); - if (uwtoconvert < 0) - return RET_SYN; - cost = do_conv(nstr, uwtoconvert, 0); - if (chkmoney(cost, cash, player->argp[3])) - return RET_SYN; - return (int)do_conv(nstr, uwtoconvert, 1); + natp = getnatp(player->cnum); + cash = natp->nat_money; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + uwtoconvert = onearg(player->argp[2], "Number to convert: "); + if (uwtoconvert < 0) + return RET_SYN; + cost = do_conv(nstr, uwtoconvert, 0); + if (chkmoney(cost, cash, player->argp[3])) + return RET_SYN; + return (int)do_conv(nstr, uwtoconvert, 1); } long do_conv(struct nstr_sect nstr, int uwtoconvert, int for_real) { - struct sctstr sect; - int newuw, totaluw, uw; - int civ, mil, adj_mob, mob; - double security_extra=1.0; - struct lndstr land; - struct nstr_item ni; - long cost = 0; + struct sctstr sect; + int newuw, totaluw, uw; + int civ, mil, adj_mob, mob; + double security_extra = 1.0; + struct lndstr land; + struct nstr_item ni; + long cost = 0; - totaluw = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (sect.sct_oldown == player->cnum) - continue; - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - if (civ == 0) - continue; - mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); + totaluw = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (sect.sct_oldown == player->cnum) + continue; + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + if (civ == 0) + continue; + mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); - /* - * Military units count according to the number of - * mil in them. (i.e. attack/defense modified don't - * count. - */ - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - mil += lnd_getmil(&land); + /* + * Military units count according to the number of + * mil in them. (i.e. attack/defense modified don't + * count. + */ + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + mil += lnd_getmil(&land); /* mil += (lnd_getmil(&land) * ((double)land.lnd_effic/100.0));*/ - /* Anti-terrorist units count double */ - if (lchr[(int)land.lnd_type].l_flags & L_SECURITY){ + /* Anti-terrorist units count double */ + if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) { - /* - * They also increase the efficiency of - * the conversion process by 10% each. - * (but they use 10 mobility doing it) - */ - security_extra += .1; - land.lnd_mobil -= 10; - if (for_real) - putland(land.lnd_uid,&land); - mil += lnd_getmil(&land); -/* mil += (lchr[land.lnd_type].l_mil * - ((double)land.lnd_effic/100.0));*/ - } - } - /* - * Must have military control to convert captured civs. - */ - if (mil * 10 < civ) - continue; - newuw = civ; - if (newuw > uwtoconvert) - newuw = uwtoconvert; - uw = getvar(V_UW, (s_char *)§, EF_SECTOR); - if (uw > 999) - continue; - if (newuw > 999 - uw) - newuw = 999 - uw; - if (newuw == 0) - continue; /* - * So entire civilian populations don't disappear immediately - * into re-education camps, charge a healthy mobility cost for - * conversions. + * They also increase the efficiency of + * the conversion process by 10% each. + * (but they use 10 mobility doing it) */ - mob = sect.sct_mobil * 5; + security_extra += .1; + land.lnd_mobil -= 10; + if (for_real) + putland(land.lnd_uid, &land); + mil += lnd_getmil(&land); +/* mil += (lchr[land.lnd_type].l_mil * + ((double)land.lnd_effic/100.0));*/ + } + } + /* + * Must have military control to convert captured civs. + */ + if (mil * 10 < civ) + continue; + newuw = civ; + if (newuw > uwtoconvert) + newuw = uwtoconvert; + uw = getvar(V_UW, (s_char *)§, EF_SECTOR); + if (uw > 999) + continue; + if (newuw > 999 - uw) + newuw = 999 - uw; + if (newuw == 0) + continue; + /* + * So entire civilian populations don't disappear immediately + * into re-education camps, charge a healthy mobility cost for + * conversions. + */ + mob = sect.sct_mobil * 5; - /* security troops make conversion more effective */ - adj_mob = ldround(((double)mob*security_extra),1); + /* security troops make conversion more effective */ + adj_mob = ldround(((double)mob * security_extra), 1); - if (adj_mob < newuw) - newuw = adj_mob; - if (newuw <= 0) - continue; - if (!for_real) { - cost += newuw * 1.5; - continue; - } - player->btused += (newuw - 1) / 100 + 1; - player->dolcost += newuw * 1.5; - if (newuw < mob) - mob = newuw; - if (putvar(V_UW, newuw + uw, (s_char *)§, EF_SECTOR) == 0) { - pr("No room for new uw in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - continue; - } - civ -= newuw; - putvar(V_CIVIL, civ, (s_char *)§, EF_SECTOR); - mob = roundavg(mob * 0.2); - if (mob > sect.sct_mobil) - mob = sect.sct_mobil; - sect.sct_mobil -= (u_char)mob; - pr("%3d conquered civilians converted in %s (%d)\n", - newuw, xyas(sect.sct_x, sect.sct_y, player->cnum), - uw + newuw); - if (civ == 0) { - sect.sct_oldown = sect.sct_own; - pr("%s is now completely yours.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - } - putsect(§); - totaluw += newuw; + if (adj_mob < newuw) + newuw = adj_mob; + if (newuw <= 0) + continue; + if (!for_real) { + cost += newuw * 1.5; + continue; + } + player->btused += (newuw - 1) / 100 + 1; + player->dolcost += newuw * 1.5; + if (newuw < mob) + mob = newuw; + if (putvar(V_UW, newuw + uw, (s_char *)§, EF_SECTOR) == 0) { + pr("No room for new uw in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; + } + civ -= newuw; + putvar(V_CIVIL, civ, (s_char *)§, EF_SECTOR); + mob = roundavg(mob * 0.2); + if (mob > sect.sct_mobil) + mob = sect.sct_mobil; + sect.sct_mobil -= (u_char)mob; + pr("%3d conquered civilians converted in %s (%d)\n", + newuw, xyas(sect.sct_x, sect.sct_y, player->cnum), uw + newuw); + if (civ == 0) { + sect.sct_oldown = sect.sct_own; + pr("%s is now completely yours.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); } - if (!for_real) - return cost; - pr("Total civilians converted: %d\n", totaluw); - pr("Paperwork at conversion places ... %d\n", player->btused); - return RET_OK; + putsect(§); + totaluw += newuw; + } + if (!for_real) + return cost; + pr("Total civilians converted: %d\n", totaluw); + pr("Paperwork at conversion places ... %d\n", player->btused); + return RET_OK; } diff --git a/src/lib/commands/coun.c b/src/lib/commands/coun.c index 2e2780439..49ce31789 100644 --- a/src/lib/commands/coun.c +++ b/src/lib/commands/coun.c @@ -50,67 +50,65 @@ static void coun_list(natid cn, struct natstr *natp); int coun(void) { - struct nstr_item ni; - struct natstr nat; - int first; + struct nstr_item ni; + struct natstr nat; + int first; - pr("The 'country' command is temporarily out of order.\n"); - pr("Please use the 'players' command instead.\n"); - if (!snxtitem(&ni, EF_NATION, player->argp[1])) - return RET_SYN; - first = 1; - while (nxtitem(&ni, (s_char *)&nat)) { - if ((nat.nat_stat & STAT_INUSE) == 0) - continue; - if (((nat.nat_stat & GOD) != GOD) && !player->god) - continue; - if (first) { - coun_header(); - first = 0; - } - coun_list((natid)ni.cur, &nat); + pr("The 'country' command is temporarily out of order.\n"); + pr("Please use the 'players' command instead.\n"); + if (!snxtitem(&ni, EF_NATION, player->argp[1])) + return RET_SYN; + first = 1; + while (nxtitem(&ni, (s_char *)&nat)) { + if ((nat.nat_stat & STAT_INUSE) == 0) + continue; + if (((nat.nat_stat & GOD) != GOD) && !player->god) + continue; + if (first) { + coun_header(); + first = 0; } - return RET_OK; + coun_list((natid)ni.cur, &nat); + } + return RET_OK; } static void coun_header(void) { - prdate(); - pr(" # last access time\tstatus\t\t country name\n"); + prdate(); + pr(" # last access time\tstatus\t\t country name\n"); } static void coun_list(natid cn, struct natstr *natp) { - s_char *status; - struct sctstr sect; + s_char *status; + struct sctstr sect; - if (natp->nat_connected) - pr("%3d %-16.16s [%d]",cn," Now logged on", - natp->nat_btu); - else - pr("%3d %-16.16s [%d]", cn, ctime(&natp->nat_last_login), - natp->nat_btu); + if (natp->nat_connected) + pr("%3d %-16.16s [%d]", cn, " Now logged on", natp->nat_btu); + else + pr("%3d %-16.16s [%d]", cn, ctime(&natp->nat_last_login), + natp->nat_btu); - if (natp->nat_stat & STAT_GOD) - status = "DEITY"; - else if (natp->nat_stat & STAT_NEW) - status = "New"; - else if (natp->nat_stat & STAT_SANCT) - status = "Sanctuary"; - else if (natp->nat_stat & STAT_NORM) { - getsect(natp->nat_xcap, natp->nat_ycap, §); - if (sect.sct_own != cn || - (sect.sct_type != SCT_CAPIT && - sect.sct_type != SCT_MOUNT)) - status = "In flux"; - else if (natp->nat_money < 0) - status = "Broke"; - else - status = "Active"; - } else { - status = "Visitor"; - } - pr("\t%-9.9s\t %s\n", status, natp->nat_cnam); + if (natp->nat_stat & STAT_GOD) + status = "DEITY"; + else if (natp->nat_stat & STAT_NEW) + status = "New"; + else if (natp->nat_stat & STAT_SANCT) + status = "Sanctuary"; + else if (natp->nat_stat & STAT_NORM) { + getsect(natp->nat_xcap, natp->nat_ycap, §); + if (sect.sct_own != cn || + (sect.sct_type != SCT_CAPIT && sect.sct_type != SCT_MOUNT)) + status = "In flux"; + else if (natp->nat_money < 0) + status = "Broke"; + else + status = "Active"; + } else { + status = "Visitor"; + } + pr("\t%-9.9s\t %s\n", status, natp->nat_cnam); } diff --git a/src/lib/commands/cuto.c b/src/lib/commands/cuto.c index 6afbc74d6..069b4d78d 100644 --- a/src/lib/commands/cuto.c +++ b/src/lib/commands/cuto.c @@ -46,72 +46,72 @@ int cuto(void) { - struct sctstr sect; - int nsect; - int n; - struct nstr_sect nstr; - s_char dirstr[12]; - int del[I_MAX+1]; + struct sctstr sect; + int nsect; + int n; + struct nstr_sect nstr; + s_char dirstr[12]; + int del[I_MAX + 1]; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - (void) strcpy(dirstr, ". $"); - n = 1; - for (n = 1; n <= 6; n++) - dirstr[n] = dirch[n]; - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) { - pr("DELIVERY CUTOFF LEVELS\n"); - if (player->god) - pr("own"); -pr(" sect cmufsgpidbolhr civ mil uw food sh gun pet irn dst bar oil lcm hcm rad\n"); - } - if (player->god) - pr("%3d", sect.sct_own); - getvec(VT_DEL, del, (s_char *)§, EF_SECTOR); - pr("%7s", xyas(nstr.x, nstr.y, player->cnum)); - pr(" %c ", dchr[sect.sct_type].d_mnem); - pr("%c", dirstr[del[I_CIVIL] & 0x7]); - pr("%c", dirstr[del[I_MILIT] & 0x7]); - pr("%c", dirstr[del[I_UW] & 0x7]); - pr("%c", dirstr[del[I_FOOD] & 0x7]); - pr("%c", dirstr[del[I_SHELL] & 0x7]); - pr("%c", dirstr[del[I_GUN] & 0x7]); - pr("%c", dirstr[del[I_PETROL] & 0x7]); - pr("%c", dirstr[del[I_IRON] & 0x7]); - pr("%c", dirstr[del[I_DUST] & 0x7]); - pr("%c", dirstr[del[I_BAR] & 0x7]); - pr("%c", dirstr[del[I_OIL] & 0x7]); - pr("%c", dirstr[del[I_LCM] & 0x7]); - pr("%c", dirstr[del[I_HCM] & 0x7]); - pr("%c", dirstr[del[I_RAD] & 0x7]); - pr("%4d", del[I_CIVIL] & ~0x7); - pr("%4d", del[I_MILIT] & ~0x7); - pr("%4d", del[I_UW] & ~0x7); - pr("%4d", del[I_FOOD] & ~0x7); - pr("%4d", del[I_SHELL] & ~0x7); - pr("%4d", del[I_GUN] & ~0x7); - pr("%4d", del[I_PETROL] & ~0x7); - pr("%4d", del[I_IRON] & ~0x7); - pr("%4d", del[I_DUST] & ~0x7); - pr("%4d", del[I_BAR] & ~0x7); - pr("%4d", del[I_OIL] & ~0x7); - pr("%4d", del[I_LCM] & ~0x7); - pr("%4d", del[I_HCM] & ~0x7); - pr("%4d", del[I_RAD] & ~0x7); - pr("\n"); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + (void)strcpy(dirstr, ". $"); + n = 1; + for (n = 1; n <= 6; n++) + dirstr[n] = dirch[n]; + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) { + pr("DELIVERY CUTOFF LEVELS\n"); + if (player->god) + pr("own"); + pr(" sect cmufsgpidbolhr civ mil uw food sh gun pet irn dst bar oil lcm hcm rad\n"); } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return RET_OK; + if (player->god) + pr("%3d", sect.sct_own); + getvec(VT_DEL, del, (s_char *)§, EF_SECTOR); + pr("%7s", xyas(nstr.x, nstr.y, player->cnum)); + pr(" %c ", dchr[sect.sct_type].d_mnem); + pr("%c", dirstr[del[I_CIVIL] & 0x7]); + pr("%c", dirstr[del[I_MILIT] & 0x7]); + pr("%c", dirstr[del[I_UW] & 0x7]); + pr("%c", dirstr[del[I_FOOD] & 0x7]); + pr("%c", dirstr[del[I_SHELL] & 0x7]); + pr("%c", dirstr[del[I_GUN] & 0x7]); + pr("%c", dirstr[del[I_PETROL] & 0x7]); + pr("%c", dirstr[del[I_IRON] & 0x7]); + pr("%c", dirstr[del[I_DUST] & 0x7]); + pr("%c", dirstr[del[I_BAR] & 0x7]); + pr("%c", dirstr[del[I_OIL] & 0x7]); + pr("%c", dirstr[del[I_LCM] & 0x7]); + pr("%c", dirstr[del[I_HCM] & 0x7]); + pr("%c", dirstr[del[I_RAD] & 0x7]); + pr("%4d", del[I_CIVIL] & ~0x7); + pr("%4d", del[I_MILIT] & ~0x7); + pr("%4d", del[I_UW] & ~0x7); + pr("%4d", del[I_FOOD] & ~0x7); + pr("%4d", del[I_SHELL] & ~0x7); + pr("%4d", del[I_GUN] & ~0x7); + pr("%4d", del[I_PETROL] & ~0x7); + pr("%4d", del[I_IRON] & ~0x7); + pr("%4d", del[I_DUST] & ~0x7); + pr("%4d", del[I_BAR] & ~0x7); + pr("%4d", del[I_OIL] & ~0x7); + pr("%4d", del[I_LCM] & ~0x7); + pr("%4d", del[I_HCM] & ~0x7); + pr("%4d", del[I_RAD] & ~0x7); + pr("\n"); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return RET_OK; } diff --git a/src/lib/commands/decl.c b/src/lib/commands/decl.c index 80340552f..3d6aba442 100644 --- a/src/lib/commands/decl.c +++ b/src/lib/commands/decl.c @@ -45,70 +45,80 @@ int decl(void) { - struct natstr nat, *natp; - int rel; - int who; - struct nstr_item ni; - s_char *p; - s_char buf[1024]; + struct natstr nat, *natp; + int rel; + int who; + struct nstr_item ni; + s_char *p; + s_char buf[1024]; - if (!(p = getstarg(player->argp[1], "alliance, friendly, neutrality, hostility, or war? ", buf))) - return RET_SYN; - switch (*p) { - case 'a': - rel = ALLIED; - break; - case 'f': - rel = FRIENDLY; - break; - case 'n': - rel = NEUTRAL; - break; - case 'h': - rel = HOSTILE; - break; - case 'm': - if (!opt_SLOW_WAR) return RET_SYN; - if (!player->god) return RET_SYN; - rel = MOBILIZATION; - break; - case 's': - if (!opt_SLOW_WAR) return RET_SYN; - if (!player->god) return RET_SYN; - rel = SITZKRIEG; - break; - case 'w': - rel = AT_WAR; - break; - default: - pr("That's no declaration!\n"); - return RET_SYN; - } + if (! + (p = + getstarg(player->argp[1], + "alliance, friendly, neutrality, hostility, or war? ", + buf))) + return RET_SYN; + switch (*p) { + case 'a': + rel = ALLIED; + break; + case 'f': + rel = FRIENDLY; + break; + case 'n': + rel = NEUTRAL; + break; + case 'h': + rel = HOSTILE; + break; + case 'm': + if (!opt_SLOW_WAR) + return RET_SYN; + if (!player->god) + return RET_SYN; + rel = MOBILIZATION; + break; + case 's': + if (!opt_SLOW_WAR) + return RET_SYN; + if (!player->god) + return RET_SYN; + rel = SITZKRIEG; + break; + case 'w': + rel = AT_WAR; + break; + default: + pr("That's no declaration!\n"); + return RET_SYN; + } - if (!snxtitem(&ni, EF_NATION, player->argp[2])) - return RET_SYN; - who = player->cnum; - if (player->god){ - who = natarg(player->argp[3], "for which country? "); - if (who < 0) return RET_SYN; - } - if (who == 255) return RET_SYN; + if (!snxtitem(&ni, EF_NATION, player->argp[2])) + return RET_SYN; + who = player->cnum; + if (player->god) { + who = natarg(player->argp[3], "for which country? "); + if (who < 0) + return RET_SYN; + } + if (who == 255) + return RET_SYN; - natp = getnatp(who); - while (nxtitem(&ni, (s_char *) &nat)) { - if (!(nat.nat_stat & STAT_INUSE)) - continue; - if (player->cnum == (natid)ni.cur) - continue; - if (opt_HIDDEN) { - if (!player->god && !getcontact(natp, ni.cur)) { - pr("You haven't contacted country #%d yet\n", ni.cur); - continue; - } - } - if (getrel(natp, (natid)ni.cur) == rel) - continue; - setrel(who, (natid)ni.cur, rel); + natp = getnatp(who); + while (nxtitem(&ni, (s_char *)&nat)) { + if (!(nat.nat_stat & STAT_INUSE)) + continue; + if (player->cnum == (natid)ni.cur) + continue; + if (opt_HIDDEN) { + if (!player->god && !getcontact(natp, ni.cur)) { + pr("You haven't contacted country #%d yet\n", ni.cur); + continue; + } } - return RET_OK; + if (getrel(natp, (natid)ni.cur) == rel) + continue; + setrel(who, (natid)ni.cur, rel); + } + return RET_OK; } diff --git a/src/lib/commands/deli.c b/src/lib/commands/deli.c index 0cb55b988..508c0141a 100644 --- a/src/lib/commands/deli.c +++ b/src/lib/commands/deli.c @@ -50,14 +50,14 @@ deli(void) register int dir, del; register struct ichrstr *ich; register int thresh = -1; - int i_del; - int sx, sy; - int status; + int i_del; + int sx, sy; + int status; struct nstr_sect nstr; - s_char buf[1024]; - s_char prompt[128]; + s_char buf[1024]; + s_char prompt[128]; s_char *p; - + if ((ich = whatitem(player->argp[1], "deliver what? ")) == 0) return RET_SYN; /* @@ -65,36 +65,37 @@ deli(void) pr("You cannot deliver people!\n"); return RET_FAIL; } - */ + */ if (!snxtsct(&nstr, player->argp[2])) return RET_SYN; - i_del = V_DEL(ich-ichr); - + i_del = V_DEL(ich - ichr); + while (nxtsct(&nstr, §) > 0) { if (!player->owner) continue; sprintf(prompt, "%s %s 'query' or %s threshold? ", xyas(nstr.x, nstr.y, player->cnum), - dchr[sect.sct_type].d_name, - ich->i_name); + dchr[sect.sct_type].d_name, ich->i_name); if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) - return RET_SYN; + return RET_SYN; del = getvar(i_del, (s_char *)§, EF_SECTOR); if (((*p >= '0') && (*p <= '9')) || *p == '+') { thresh = atoi(p) & ~0x7; - if (*p == '+' || !(p = getstarg(player->argp[4], "Direction? ", buf)) || !*p) + if (*p == '+' + || !(p = getstarg(player->argp[4], "Direction? ", buf)) + || !*p) dir = del & 0x7; else if ((dir = chkdir(*p, DIR_STOP, DIR_LAST)) < 0) return RET_SYN; } else if (*p != 'q') return RET_SYN; - + if (!check_sect_ok(§)) continue; if (thresh >= 0) { del = thresh + dir; - status = putvar(i_del, del,(s_char *)§,EF_SECTOR); + status = putvar(i_del, del, (s_char *)§, EF_SECTOR); if (status < 0) { pr("No room for delivery path in %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); diff --git a/src/lib/commands/demo.c b/src/lib/commands/demo.c index 515cdffe8..e49d7e43f 100644 --- a/src/lib/commands/demo.c +++ b/src/lib/commands/demo.c @@ -47,91 +47,97 @@ * */ -long do_demo(struct natstr *natp, struct nstr_sect nstr, int number, s_char *p, int for_real); +long do_demo(struct natstr *natp, struct nstr_sect nstr, int number, + s_char *p, int for_real); int demo(void) { - struct natstr *natp; - long cash; - long cost; - int number; - s_char *p; - s_char buf[1024]; - struct nstr_sect nstr; + struct natstr *natp; + long cash; + long cost; + int number; + s_char *p; + s_char buf[1024]; + struct nstr_sect nstr; - natp = getnatp(player->cnum); - cash = natp->nat_money; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - if ((p = getstarg(player->argp[2], "Number to de-mobilize : ", buf)) == 0) - return RET_SYN; - number = atoi(p); - if (!(p = getstarg(player->argp[3], "New civilians on active reserve? (y/n) ", buf))) - return RET_SYN; - if (*p != 'y' && *p != 'n') - return RET_SYN; - cost = do_demo(natp, nstr, number, p, 0); - if (chkmoney(cost, cash, player->argp[4])) - return RET_SYN; - return (int)do_demo(natp, nstr, number, p, 1); + natp = getnatp(player->cnum); + cash = natp->nat_money; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + if ((p = + getstarg(player->argp[2], "Number to de-mobilize : ", buf)) == 0) + return RET_SYN; + number = atoi(p); + if (! + (p = + getstarg(player->argp[3], + "New civilians on active reserve? (y/n) ", buf))) + return RET_SYN; + if (*p != 'y' && *p != 'n') + return RET_SYN; + cost = do_demo(natp, nstr, number, p, 0); + if (chkmoney(cost, cash, player->argp[4])) + return RET_SYN; + return (int)do_demo(natp, nstr, number, p, 1); } -long do_demo(struct natstr *natp, struct nstr_sect nstr, int number, s_char *p, int for_real) +long +do_demo(struct natstr *natp, struct nstr_sect nstr, int number, s_char *p, + int for_real) { - struct sctstr sect; - int mil_demob; - int mil; - int civ; - int deltamil; - int reserves; - long cost = 0; + struct sctstr sect; + int mil_demob; + int mil; + int civ; + int deltamil; + int reserves; + long cost = 0; - mil_demob = 0; - reserves = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner || sect.sct_effic < 60) - continue; - if ((mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR)) == 0) - continue; - if (sect.sct_own != sect.sct_oldown) - continue; - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - if (number < 0){ - if ((deltamil = mil + number) <= 0) - continue; - } - else if ((deltamil = min(mil, number)) <= 0) - continue; - civ += deltamil; - mil -= deltamil; - mil_demob += deltamil; - if (!for_real) { - cost += deltamil * 5; - continue; - } - player->dolcost += deltamil * 5; - pr("%d demobilized in %s (%d mil left)\n", - deltamil, xyas(sect.sct_x, sect.sct_y, player->cnum), mil); - if (*p == 'y') - reserves += deltamil; - putvar(V_MILIT, mil, (s_char *)§, EF_SECTOR); - putvar(V_CIVIL, civ, (s_char *)§, EF_SECTOR); - putsect(§); + mil_demob = 0; + reserves = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner || sect.sct_effic < 60) + continue; + if ((mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR)) == 0) + continue; + if (sect.sct_own != sect.sct_oldown) + continue; + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + if (number < 0) { + if ((deltamil = mil + number) <= 0) + continue; + } else if ((deltamil = min(mil, number)) <= 0) + continue; + civ += deltamil; + mil -= deltamil; + mil_demob += deltamil; + if (!for_real) { + cost += deltamil * 5; + continue; } - if (!for_real) - return cost; - if (!mil_demob) { - pr("No eligible sectors/military for demobilization\n"); - return (long)RET_FAIL; - } - pr("Total new civilians : %d\n", mil_demob); + player->dolcost += deltamil * 5; + pr("%d demobilized in %s (%d mil left)\n", + deltamil, xyas(sect.sct_x, sect.sct_y, player->cnum), mil); if (*p == 'y') - pr("Military reserve stands at %d (up %d)\n", - natp->nat_reserve + reserves, reserves); - if (reserves > 0) { - natp->nat_reserve += reserves; - putnat(natp); - } - return RET_OK; + reserves += deltamil; + putvar(V_MILIT, mil, (s_char *)§, EF_SECTOR); + putvar(V_CIVIL, civ, (s_char *)§, EF_SECTOR); + putsect(§); + } + if (!for_real) + return cost; + if (!mil_demob) { + pr("No eligible sectors/military for demobilization\n"); + return (long)RET_FAIL; + } + pr("Total new civilians : %d\n", mil_demob); + if (*p == 'y') + pr("Military reserve stands at %d (up %d)\n", + natp->nat_reserve + reserves, reserves); + if (reserves > 0) { + natp->nat_reserve += reserves; + putnat(natp); + } + return RET_OK; } diff --git a/src/lib/commands/desi.c b/src/lib/commands/desi.c index 1e03db675..e816cb3c0 100644 --- a/src/lib/commands/desi.c +++ b/src/lib/commands/desi.c @@ -45,195 +45,199 @@ #include "optlist.h" #include "commands.h" -long do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash, int for_real); +long do_desi(struct natstr *natp, s_char *sects, s_char *deschar, + long int cash, int for_real); int desi(void) { - long cash; - long cost; - struct natstr *natp; + long cash; + long cost; + struct natstr *natp; - natp = getnatp(player->cnum); - cash = natp->nat_money; - if (player->argp[2]) { - cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0); - if (cost < 0) - return (int)(-cost); - if (chkmoney(cost, cash, player->argp[3])) - return RET_SYN; - } - return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1); + natp = getnatp(player->cnum); + cash = natp->nat_money; + if (player->argp[2]) { + cost = do_desi(natp, player->argp[1], player->argp[2], cash, 0); + if (cost < 0) + return (int)(-cost); + if (chkmoney(cost, cash, player->argp[3])) + return RET_SYN; + } + return (int)do_desi(natp, player->argp[1], player->argp[2], cash, 1); } long -do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash, int for_real) +do_desi(struct natstr *natp, s_char *sects, s_char *deschar, long int cash, + int for_real) { - extern int opt_NO_LCMS; - extern int opt_NO_HCMS; - register int n; - s_char *p; - int breaksanct; - int cap_x; - int cap_y; - int des; - struct nstr_sect nstr; - struct sctstr sect; - struct sctstr check; - s_char prompt[128]; - s_char buf[1024]; - long cost = 0; - int changed = 0; - int warned = 0; + extern int opt_NO_LCMS; + extern int opt_NO_HCMS; + register int n; + s_char *p; + int breaksanct; + int cap_x; + int cap_y; + int des; + struct nstr_sect nstr; + struct sctstr sect; + struct sctstr check; + s_char prompt[128]; + s_char buf[1024]; + long cost = 0; + int changed = 0; + int warned = 0; - breaksanct = 0; - if (!snxtsct(&nstr, sects)) { - if (for_real) - return (long)RET_SYN; - else - return (long)-RET_SYN; + breaksanct = 0; + if (!snxtsct(&nstr, sects)) { + if (for_real) + return (long)RET_SYN; + else + return (long)-RET_SYN; + } + cap_x = natp->nat_xcap; + cap_y = natp->nat_ycap; + while (!player->aborted && nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (!player->god) { + if (sect.sct_type == SCT_MOUNT || + sect.sct_type == SCT_BTOWER || + sect.sct_type == SCT_BSPAN || + sect.sct_type == SCT_WASTE || + sect.sct_type == SCT_PLAINS || + (opt_NO_LCMS && sect.sct_type == SCT_LIGHT) || + (opt_NO_HCMS && sect.sct_type == SCT_HEAVY) || + (opt_NO_OIL && sect.sct_type == SCT_OIL) || + (opt_NO_OIL && sect.sct_type == SCT_REFINE)) + continue; } - cap_x = natp->nat_xcap; - cap_y = natp->nat_ycap; - while (!player->aborted && nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (!player->god) { - if (sect.sct_type == SCT_MOUNT || - sect.sct_type == SCT_BTOWER || - sect.sct_type == SCT_BSPAN || - sect.sct_type == SCT_WASTE || - sect.sct_type == SCT_PLAINS || - (opt_NO_LCMS && sect.sct_type == SCT_LIGHT) || - (opt_NO_HCMS && sect.sct_type == SCT_HEAVY) || - (opt_NO_OIL && sect.sct_type == SCT_OIL) || - (opt_NO_OIL && sect.sct_type == SCT_REFINE)) - continue; - } - sprintf(prompt, "%s %d%% %s desig? ", - xyas(sect.sct_x, sect.sct_y, player->cnum), - sect.sct_effic, dchr[sect.sct_type].d_name); - if ((p = getstarg(deschar, prompt, buf)) == 0) - continue; + sprintf(prompt, "%s %d%% %s desig? ", + xyas(sect.sct_x, sect.sct_y, player->cnum), + sect.sct_effic, dchr[sect.sct_type].d_name); + if ((p = getstarg(deschar, prompt, buf)) == 0) + continue; - if (!check_sect_ok(§)) - continue; + if (!check_sect_ok(§)) + continue; - des = typematch(p, EF_SECTOR); - if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) && - !player->god)) { - pr("See \"info Sector-types\"\n"); - if (for_real) - return (long)RET_FAIL; - else - return (long)-RET_FAIL; - } - if (!player->god) { - if (des == SCT_WATER || des == SCT_MOUNT || - des == SCT_SANCT || des == SCT_PLAINS || - (opt_NO_LCMS && des == SCT_LIGHT) || - (opt_NO_HCMS && des == SCT_HEAVY) || - (opt_NO_OIL && des == SCT_OIL) || - (opt_NO_OIL && des == SCT_REFINE)) { - pr("Only %s can make a %s!\n", cname(0), - dchr[des].d_name); - continue; - } - if (des == SCT_WASTE) { - pr("Only a nuclear device (or %s) can make a %s!\n", - cname(0), dchr[des].d_name); - continue; - } - } - if (sect.sct_type == des && sect.sct_newtype == des) - continue; - if (sect.sct_type == SCT_SANCT) - breaksanct++; - if (sect.sct_x == cap_x && sect.sct_y == cap_y && - des != SCT_CAPIT && des != SCT_SANCT && - des != SCT_MOUNT && for_real) - pr("You have redesignated your capital!\n"); - if (des == SCT_HARBR) { - for (n = 1; n <= 6; n++) { - getsect(nstr.x + diroff[n][0], - nstr.y + diroff[n][1], &check); - if (check.sct_type == SCT_WATER) - break; - if (check.sct_type == SCT_BSPAN) - break; - if (check.sct_type == SCT_BTOWER) - break; - } - if (n > 6) { - if (for_real) - pr("%s does not border on water.\n", - xyas(nstr.x, nstr.y, player->cnum)); - if (player->god) { - if (for_real) - pr("But if it's what you want ...\n"); - } else - continue; - } - } - if (des == SCT_BHEAD) { - for (n = 1; n <= 6; n++) { - getsect(nstr.x + diroff[n][0], - nstr.y + diroff[n][1], &check); - if (check.sct_type == SCT_WATER) - break; - if (check.sct_type == SCT_BSPAN) - break; - if (check.sct_type == SCT_BTOWER) - break; - } - if (n > 6) { - if (for_real) - pr("%s does not border on water.\n", - xyas(nstr.x, nstr.y,player->cnum)); - if (player->god) { - if (for_real) - pr("But if it's what you want...\n"); - } else - continue; - } - } - if (sect.sct_type == SCT_SANCT && !player->god) - continue; - n = sect.sct_type; - if ((sect.sct_newtype != des) && (sect.sct_type != des) && dchr[des].d_cost) { - if (for_real) { - if (check_cost(!deschar, dchr[des].d_cost, cash, &warned, player->argp[3])) - break; - } else { - cost += dchr[des].d_cost; - continue; - } - } - if (sect.sct_effic < 5 || player->god) { - sect.sct_type = des; - sect.sct_effic = 0; - /* No longer tear down infrasturcture - sect.sct_road = 0; - sect.sct_defense = 0; - */ - changed += map_set(player->cnum, sect.sct_x, sect.sct_y, - dchr[des].d_mnem, 0); - } - sect.sct_newtype = des; - putsect(§); - if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */ - if (n != SCT_BHEAD) - continue; - bridgefall(§, 0); - } + des = typematch(p, EF_SECTOR); + if (des < 0 || (((des == SCT_BSPAN) || (des == SCT_BTOWER)) && + !player->god)) { + pr("See \"info Sector-types\"\n"); + if (for_real) + return (long)RET_FAIL; + else + return (long)-RET_FAIL; + } + if (!player->god) { + if (des == SCT_WATER || des == SCT_MOUNT || + des == SCT_SANCT || des == SCT_PLAINS || + (opt_NO_LCMS && des == SCT_LIGHT) || + (opt_NO_HCMS && des == SCT_HEAVY) || + (opt_NO_OIL && des == SCT_OIL) || + (opt_NO_OIL && des == SCT_REFINE)) { + pr("Only %s can make a %s!\n", cname(0), dchr[des].d_name); + continue; + } + if (des == SCT_WASTE) { + pr("Only a nuclear device (or %s) can make a %s!\n", + cname(0), dchr[des].d_name); + continue; + } + } + if (sect.sct_type == des && sect.sct_newtype == des) + continue; + if (sect.sct_type == SCT_SANCT) + breaksanct++; + if (sect.sct_x == cap_x && sect.sct_y == cap_y && + des != SCT_CAPIT && des != SCT_SANCT && + des != SCT_MOUNT && for_real) + pr("You have redesignated your capital!\n"); + if (des == SCT_HARBR) { + for (n = 1; n <= 6; n++) { + getsect(nstr.x + diroff[n][0], + nstr.y + diroff[n][1], &check); + if (check.sct_type == SCT_WATER) + break; + if (check.sct_type == SCT_BSPAN) + break; + if (check.sct_type == SCT_BTOWER) + break; + } + if (n > 6) { + if (for_real) + pr("%s does not border on water.\n", + xyas(nstr.x, nstr.y, player->cnum)); + if (player->god) { + if (for_real) + pr("But if it's what you want ...\n"); + } else + continue; + } + } + if (des == SCT_BHEAD) { + for (n = 1; n <= 6; n++) { + getsect(nstr.x + diroff[n][0], + nstr.y + diroff[n][1], &check); + if (check.sct_type == SCT_WATER) + break; + if (check.sct_type == SCT_BSPAN) + break; + if (check.sct_type == SCT_BTOWER) + break; + } + if (n > 6) { + if (for_real) + pr("%s does not border on water.\n", + xyas(nstr.x, nstr.y, player->cnum)); + if (player->god) { + if (for_real) + pr("But if it's what you want...\n"); + } else + continue; + } + } + if (sect.sct_type == SCT_SANCT && !player->god) + continue; + n = sect.sct_type; + if ((sect.sct_newtype != des) && (sect.sct_type != des) + && dchr[des].d_cost) { + if (for_real) { + if (check_cost + (!deschar, dchr[des].d_cost, cash, &warned, + player->argp[3])) + break; + } else { + cost += dchr[des].d_cost; + continue; + } + } + if (sect.sct_effic < 5 || player->god) { + sect.sct_type = des; + sect.sct_effic = 0; + /* No longer tear down infrasturcture + sect.sct_road = 0; + sect.sct_defense = 0; + */ + changed += map_set(player->cnum, sect.sct_x, sect.sct_y, + dchr[des].d_mnem, 0); } - if (for_real) { - if (changed) - writemap(player->cnum); - if (breaksanct) - bsanct(); - return (long)RET_OK; - } else { - return cost; + sect.sct_newtype = des; + putsect(§); + if (opt_EASY_BRIDGES == 0) { /* may cause a bridge fall */ + if (n != SCT_BHEAD) + continue; + bridgefall(§, 0); } + } + if (for_real) { + if (changed) + writemap(player->cnum); + if (breaksanct) + bsanct(); + return (long)RET_OK; + } else { + return cost; + } } diff --git a/src/lib/commands/disa.c b/src/lib/commands/disa.c index a711a7ca5..6ba41b81f 100644 --- a/src/lib/commands/disa.c +++ b/src/lib/commands/disa.c @@ -38,12 +38,12 @@ int disa(void) { - extern s_char *disablefil; - int fd; + extern s_char *disablefil; + int fd; - if ((fd = open(disablefil, O_RDWR|O_CREAT|O_TRUNC, 0660)) < 0) - return RET_FAIL; - close(fd); - pr("Updates are disabled\n"); - return RET_OK; + if ((fd = open(disablefil, O_RDWR | O_CREAT | O_TRUNC, 0660)) < 0) + return RET_FAIL; + close(fd); + pr("Updates are disabled\n"); + return RET_OK; } diff --git a/src/lib/commands/diss.c b/src/lib/commands/diss.c index 4736d156a..f87586238 100644 --- a/src/lib/commands/diss.c +++ b/src/lib/commands/diss.c @@ -53,213 +53,218 @@ int diss(void) { - int quit(void); - struct sctstr sect; - struct lndstr land; - struct shpstr ship; - struct plnstr plane; - struct trtstr treaty; - struct trdstr trade; - struct lonstr loan; - struct nstr_item ni; - struct nstr_sect ns; - int sctnum; - int damage; - int annoyed; - int n; - s_char *p; - natid cn; - float dummy; - int val; - s_char buf[1024]; - struct natstr *np; + int quit(void); + struct sctstr sect; + struct lndstr land; + struct shpstr ship; + struct plnstr plane; + struct trtstr treaty; + struct trdstr trade; + struct lonstr loan; + struct nstr_item ni; + struct nstr_sect ns; + int sctnum; + int damage; + int annoyed; + int n; + s_char *p; + natid cn; + float dummy; + int val; + s_char buf[1024]; + struct natstr *np; - if (player->cnum == 0) { - /* Dissolve the Deity??? */ - /* Probably someone broke in. */ - /* Send a tele to deity, and abort the session. */ - wu(0, 0, "Diety dissolve attempted! Session was aborted.\n"); - quit(); - } - if (player->argp[1]) - *player->argp[1] = 0; - p = getstarg(player->argp[1], "Are you SURE you want to do this? (n) ", buf); - if (p == 0 || *p != 'y') - return RET_SYN; - pr("\nIf you want some problem fixed and hope to force the issue\n"); - pr("by dissolving, DON'T DO IT. Even if an earlier version of\n"); - pr("this game is brought up, YOU WILL BE GONE.\n"); - pr("Forcing the issue makes it less likely that it will be\n"); - pr("resolved the way you wish it.\n\n"); - pr("Be part of the solution, not part of the problem.\n\n"); - pr("If this is a test game, dissolving will not help the test.\n\n"); - pr("If you are down to 0 sectors, and a 25% fishing vessel with\n"); - pr("1 mil on it, well, I can see your point. Go ahead.\n\n"); - pr("But at least pay back your loans, if you can.\n\n"); + if (player->cnum == 0) { + /* Dissolve the Deity??? */ + /* Probably someone broke in. */ + /* Send a tele to deity, and abort the session. */ + wu(0, 0, "Diety dissolve attempted! Session was aborted.\n"); + quit(); + } + if (player->argp[1]) + *player->argp[1] = 0; + p = getstarg(player->argp[1], "Are you SURE you want to do this? (n) ", + buf); + if (p == 0 || *p != 'y') + return RET_SYN; + pr("\nIf you want some problem fixed and hope to force the issue\n"); + pr("by dissolving, DON'T DO IT. Even if an earlier version of\n"); + pr("this game is brought up, YOU WILL BE GONE.\n"); + pr("Forcing the issue makes it less likely that it will be\n"); + pr("resolved the way you wish it.\n\n"); + pr("Be part of the solution, not part of the problem.\n\n"); + pr("If this is a test game, dissolving will not help the test.\n\n"); + pr("If you are down to 0 sectors, and a 25% fishing vessel with\n"); + pr("1 mil on it, well, I can see your point. Go ahead.\n\n"); + pr("But at least pay back your loans, if you can.\n\n"); - if (player->argp[1]) - *player->argp[1] = 0; - p = getstarg(player->argp[1], "Once again, are you SURE you want to do this? (n) ", buf); - if (p == 0 || *p != 'y') - return RET_SYN; + if (player->argp[1]) + *player->argp[1] = 0; + p = getstarg(player->argp[1], + "Once again, are you SURE you want to do this? (n) ", + buf); + if (p == 0 || *p != 'y') + return RET_SYN; - np = getnatp(player->cnum); - np->nat_stat = VIS; - snxtsct_all(&ns); - sctnum = 0; - while (nxtsct(&ns, §)) { - if (!player->owner) - continue; - annoyed = 75 - (random() % (sect.sct_loyal+40)); - if (annoyed <= 0 || sect.sct_oldown != sect.sct_own) { - pr("Populace celebrates in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - if (sect.sct_oldown != sect.sct_own) { - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - makenotlost(EF_SECTOR, sect.sct_oldown, 0, sect.sct_x, sect.sct_y); - sect.sct_own = sect.sct_oldown; - if(sect.sct_own != 0) - wu(0, sect.sct_own, - "%s reverts back to you!\n", - xyas(sect.sct_x, sect.sct_y, - sect.sct_own)); - } - } else if (annoyed < 25) { - pr("Populace unmoved in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - sect.sct_own = 0; - sect.sct_oldown = 0; - } else { - pr("Rioting breaks out in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - sectdamage(§, annoyed, 0); - sctnum++; - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - sect.sct_own = 0; - sect.sct_oldown = 0; - } - putsect(§); + np = getnatp(player->cnum); + np->nat_stat = VIS; + snxtsct_all(&ns); + sctnum = 0; + while (nxtsct(&ns, §)) { + if (!player->owner) + continue; + annoyed = 75 - (random() % (sect.sct_loyal + 40)); + if (annoyed <= 0 || sect.sct_oldown != sect.sct_own) { + pr("Populace celebrates in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + if (sect.sct_oldown != sect.sct_own) { + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, + sect.sct_y); + makenotlost(EF_SECTOR, sect.sct_oldown, 0, sect.sct_x, + sect.sct_y); + sect.sct_own = sect.sct_oldown; + if (sect.sct_own != 0) + wu(0, sect.sct_own, + "%s reverts back to you!\n", + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + } + } else if (annoyed < 25) { + pr("Populace unmoved in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); + sect.sct_own = 0; + sect.sct_oldown = 0; + } else { + pr("Rioting breaks out in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + sectdamage(§, annoyed, 0); + sctnum++; + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); + sect.sct_own = 0; + sect.sct_oldown = 0; } - snxtitem_all(&ni, EF_LAND); - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner) - continue; + putsect(§); + } + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner) + continue; - pr("%s disbands!\n", prland(&land)); - land.lnd_effic = 0; - putland(land.lnd_uid, &land); - } - snxtitem_all(&ni, EF_SHIP); - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner) - continue; - pr("%s ", prship(&ship)); - switch (random() % 3) { - case 0: - pr("scuttled!\n"); - ship.shp_effic = 0; - break; - case 1: - pr("abandoned!\n"); - putvar(V_MILIT, 0, (s_char *)&ship, EF_SHIP); - putvar(V_CIVIL, 0, (s_char *)&ship, EF_SHIP); - putvar(V_UW, 0, (s_char *)&ship, EF_SHIP); - break; - case 2: - default: - damage = (random() % 80) + 10; - pr("crew has rioted! (%d damage)\n", damage); - shipdamage(&ship, damage); - sctnum++; - break; - } - putship(ship.shp_uid, &ship); - } - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) { - if (!player->owner) - continue; - pr("%s ", prplane(&plane)); - switch (random() % 2) { - case 0: - pr("blown up!\n"); - plane.pln_effic = 0; - break; - case 1: - default: - damage = (random() % 80) + 10; - pr("crew has rioted! (%d damage)\n", damage); - planedamage(&plane, damage); - sctnum++; - break; - } - putplane(plane.pln_uid, &plane); - } - snxtitem_all(&ni, EF_TREATY); - while (nxtitem(&ni, (s_char *)&treaty)) { - if (treaty.trt_status == TS_FREE) - continue; - if (treaty.trt_cna != player->cnum && - treaty.trt_cnb != player->cnum) - continue; - cn = treaty.trt_cna == player->cnum ? treaty.trt_cnb : treaty.trt_cna; - pr("No more treaty with %s\n", cname(cn)); - wu(0, cn, "Treaty #%d with %s voided\n", - ni.cur, cname(player->cnum)); - treaty.trt_status = TS_FREE; - puttre(ni.cur, &treaty); - } - snxtitem_all(&ni, EF_LOAN); - while (nxtitem(&ni, (s_char *)&loan)) { - if (loan.l_status == LS_FREE) - continue; - if (loan.l_loner != player->cnum && loan.l_lonee != player->cnum) - continue; - if (loan.l_loner == player->cnum) { - pr("Loan #%d to %s will never be repaid\n", - ni.cur, cname(loan.l_lonee)); - wu(0, loan.l_lonee, - "Loan #%d from %s has been voided\n", - ni.cur, cname(player->cnum)); - } else { - pr("Loan #%d from %s will never be repaid\n", - ni.cur, cname(loan.l_lonee)); - wu(0, loan.l_loner, - "Loan #%d to %s has been voided\n", - ni.cur, cname(player->cnum)); - } - loan.l_status = LS_FREE; - putloan(ni.cur, &loan); + pr("%s disbands!\n", prland(&land)); + land.lnd_effic = 0; + putland(land.lnd_uid, &land); + } + snxtitem_all(&ni, EF_SHIP); + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner) + continue; + pr("%s ", prship(&ship)); + switch (random() % 3) { + case 0: + pr("scuttled!\n"); + ship.shp_effic = 0; + break; + case 1: + pr("abandoned!\n"); + putvar(V_MILIT, 0, (s_char *)&ship, EF_SHIP); + putvar(V_CIVIL, 0, (s_char *)&ship, EF_SHIP); + putvar(V_UW, 0, (s_char *)&ship, EF_SHIP); + break; + case 2: + default: + damage = (random() % 80) + 10; + pr("crew has rioted! (%d damage)\n", damage); + shipdamage(&ship, damage); + sctnum++; + break; } - /* clean up commodity and trade for this nation. */ - commlock(); - commread(); - for (n=1; ncnum, n, &dummy); - commset(player->cnum, n, -val); + putship(ship.shp_uid, &ship); + } + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (!player->owner) + continue; + pr("%s ", prplane(&plane)); + switch (random() % 2) { + case 0: + pr("blown up!\n"); + plane.pln_effic = 0; + break; + case 1: + default: + damage = (random() % 80) + 10; + pr("crew has rioted! (%d damage)\n", damage); + planedamage(&plane, damage); + sctnum++; + break; } - commwrite(); - communlock(); - snxtitem_all(&ni, EF_TRADE); - while (nxtitem(&ni, (s_char *)&trade)) { - if (trade.trd_unitid >= 0 && trade.trd_owner == player->cnum) { - trade.trd_unitid = -1; - (void) puttrade(ni.cur, &trade); - } + putplane(plane.pln_uid, &plane); + } + snxtitem_all(&ni, EF_TREATY); + while (nxtitem(&ni, (s_char *)&treaty)) { + if (treaty.trt_status == TS_FREE) + continue; + if (treaty.trt_cna != player->cnum && + treaty.trt_cnb != player->cnum) + continue; + cn = treaty.trt_cna == + player->cnum ? treaty.trt_cnb : treaty.trt_cna; + pr("No more treaty with %s\n", cname(cn)); + wu(0, cn, "Treaty #%d with %s voided\n", + ni.cur, cname(player->cnum)); + treaty.trt_status = TS_FREE; + puttre(ni.cur, &treaty); + } + snxtitem_all(&ni, EF_LOAN); + while (nxtitem(&ni, (s_char *)&loan)) { + if (loan.l_status == LS_FREE) + continue; + if (loan.l_loner != player->cnum && loan.l_lonee != player->cnum) + continue; + if (loan.l_loner == player->cnum) { + pr("Loan #%d to %s will never be repaid\n", + ni.cur, cname(loan.l_lonee)); + wu(0, loan.l_lonee, + "Loan #%d from %s has been voided\n", + ni.cur, cname(player->cnum)); + } else { + pr("Loan #%d from %s will never be repaid\n", + ni.cur, cname(loan.l_lonee)); + wu(0, loan.l_loner, + "Loan #%d to %s has been voided\n", + ni.cur, cname(player->cnum)); } - while (sctnum > 0) { - n = sctnum > 127 ? 127 : sctnum; - nreport(player->cnum, N_RIOT, 0, n); - sctnum -= n; + loan.l_status = LS_FREE; + putloan(ni.cur, &loan); + } + /* clean up commodity and trade for this nation. */ + commlock(); + commread(); + for (n = 1; n < I_MAX + 1; n++) { + val = commamt(player->cnum, n, &dummy); + commset(player->cnum, n, -val); + } + commwrite(); + communlock(); + snxtitem_all(&ni, EF_TRADE); + while (nxtitem(&ni, (s_char *)&trade)) { + if (trade.trd_unitid >= 0 && trade.trd_owner == player->cnum) { + trade.trd_unitid = -1; + (void)puttrade(ni.cur, &trade); } - filetruncate(mailbox(buf, player->cnum)); - np->nat_stat = STAT_INUSE; - np->nat_btu = 0; - player->nstat = VIS; - wu(0, 0, "Country #%d (%s) has dissolved\n", - player->cnum, cname(player->cnum)); - nreport(player->cnum, N_DISS_GOV, 0, 1); - putnat(np); - return RET_OK; + } + while (sctnum > 0) { + n = sctnum > 127 ? 127 : sctnum; + nreport(player->cnum, N_RIOT, 0, n); + sctnum -= n; + } + filetruncate(mailbox(buf, player->cnum)); + np->nat_stat = STAT_INUSE; + np->nat_btu = 0; + player->nstat = VIS; + wu(0, 0, "Country #%d (%s) has dissolved\n", + player->cnum, cname(player->cnum)); + nreport(player->cnum, N_DISS_GOV, 0, 1); + putnat(np); + return RET_OK; } diff --git a/src/lib/commands/dist.c b/src/lib/commands/dist.c index e751245c9..596435fcf 100644 --- a/src/lib/commands/dist.c +++ b/src/lib/commands/dist.c @@ -50,87 +50,84 @@ int dist(void) { - struct sctstr sect, dsect, tsect; - struct nstr_sect nstr; - s_char *path, *p; - double move_cost=0.0; - coord dstx, dsty; - s_char buf[1024]; - - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - while (!player->aborted && nxtsct(&nstr, §)) { - if (!player->owner) - continue; - pr("%s at %s ", dchr[sect.sct_type].d_name, - xyas(nstr.x, nstr.y, player->cnum)); - if ((sect.sct_dist_x != sect.sct_x) || - (sect.sct_dist_y != sect.sct_y)) { - getsect(sect.sct_dist_x, sect.sct_dist_y, &tsect); - if (tsect.sct_own != player->cnum) - pr("distributes to %s, not owned by you.\n", - xyas(tsect.sct_x, tsect.sct_y, player->cnum)); - else - pr("distributes to %s. \n", - xyas(tsect.sct_x, tsect.sct_y, player->cnum)); - } else - pr("has no dist sector. \n"); - p = getstarg(player->argp[2], "Distribution sector? ", buf); - if (p && (*p == 0)) - continue; - - if (!check_sect_ok(§)) - continue; + struct sctstr sect, dsect, tsect; + struct nstr_sect nstr; + s_char *path, *p; + double move_cost = 0.0; + coord dstx, dsty; + s_char buf[1024]; - if (p && (*p != '.') && (*p != 'h') && - (!sarg_xy(p, &dstx, &dsty))) - return RET_SYN; - - if (p && ((*p == '.') || (*p == 'h'))){ - dstx = sect.sct_x; - dsty = sect.sct_y; - } - - if (!getsect(dstx,dsty,&dsect)){ - pr("Bad sector.\n"); - return RET_FAIL; - } - - if (dsect.sct_own != player->cnum) - pr("Warning: you don't own %s!\n", - xyas(dsect.sct_x,dsect.sct_y,player->cnum)); - - path = BestDistPath(buf, §,&dsect,&move_cost,MOB_ROAD); - - if (path == (s_char *)0){ - pr("No owned path from %s to %s.\n", - xyas(dsect.sct_x,dsect.sct_y,player->cnum), - xyas(sect.sct_x,sect.sct_y,player->cnum)); - continue; - } - - if ((dsect.sct_x == sect.sct_x) && - (dsect.sct_y == sect.sct_y)) { - pr("Distribution from and to %s %s terminated\n", - dchr[sect.sct_type].d_name, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - } else { - pr("%s %s now distributes to %s (cost %1.3f)\n", - dchr[sect.sct_type].d_name, - xyas(sect.sct_x, sect.sct_y, player->cnum), - xyas(dsect.sct_x, dsect.sct_y, player->cnum), - move_cost); - } - pr("\n"); - /* Only change and write out if we are really changing where it - distributes to. Otherwise, it's a waste of time (since nothing - changed.) */ - if ((sect.sct_dist_x != dsect.sct_x) || - (sect.sct_dist_y != dsect.sct_y)) { - sect.sct_dist_x = dsect.sct_x; - sect.sct_dist_y = dsect.sct_y; - putsect(§); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + while (!player->aborted && nxtsct(&nstr, §)) { + if (!player->owner) + continue; + pr("%s at %s ", dchr[sect.sct_type].d_name, + xyas(nstr.x, nstr.y, player->cnum)); + if ((sect.sct_dist_x != sect.sct_x) || + (sect.sct_dist_y != sect.sct_y)) { + getsect(sect.sct_dist_x, sect.sct_dist_y, &tsect); + if (tsect.sct_own != player->cnum) + pr("distributes to %s, not owned by you.\n", + xyas(tsect.sct_x, tsect.sct_y, player->cnum)); + else + pr("distributes to %s. \n", + xyas(tsect.sct_x, tsect.sct_y, player->cnum)); + } else + pr("has no dist sector. \n"); + p = getstarg(player->argp[2], "Distribution sector? ", buf); + if (p && (*p == 0)) + continue; + + if (!check_sect_ok(§)) + continue; + + if (p && (*p != '.') && (*p != 'h') && (!sarg_xy(p, &dstx, &dsty))) + return RET_SYN; + + if (p && ((*p == '.') || (*p == 'h'))) { + dstx = sect.sct_x; + dsty = sect.sct_y; + } + + if (!getsect(dstx, dsty, &dsect)) { + pr("Bad sector.\n"); + return RET_FAIL; + } + + if (dsect.sct_own != player->cnum) + pr("Warning: you don't own %s!\n", + xyas(dsect.sct_x, dsect.sct_y, player->cnum)); + + path = BestDistPath(buf, §, &dsect, &move_cost, MOB_ROAD); + + if (path == (s_char *)0) { + pr("No owned path from %s to %s.\n", + xyas(dsect.sct_x, dsect.sct_y, player->cnum), + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; + } + + if ((dsect.sct_x == sect.sct_x) && (dsect.sct_y == sect.sct_y)) { + pr("Distribution from and to %s %s terminated\n", + dchr[sect.sct_type].d_name, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + } else { + pr("%s %s now distributes to %s (cost %1.3f)\n", + dchr[sect.sct_type].d_name, + xyas(sect.sct_x, sect.sct_y, player->cnum), + xyas(dsect.sct_x, dsect.sct_y, player->cnum), move_cost); + } + pr("\n"); + /* Only change and write out if we are really changing where it + distributes to. Otherwise, it's a waste of time (since nothing + changed.) */ + if ((sect.sct_dist_x != dsect.sct_x) || + (sect.sct_dist_y != dsect.sct_y)) { + sect.sct_dist_x = dsect.sct_x; + sect.sct_dist_y = dsect.sct_y; + putsect(§); + } } - } - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/drop.c b/src/lib/commands/drop.c index 41236005f..20b97dc7d 100644 --- a/src/lib/commands/drop.c +++ b/src/lib/commands/drop.c @@ -50,103 +50,110 @@ int drop(void) { - int rel; - s_char *p; - int mission_flags; - int tech; - coord tx, ty; - coord ax, ay; - int ap_to_target; - struct ichrstr *ip; - s_char flightpath[MAX_PATH_LEN]; - struct nstr_item ni_bomb; - struct nstr_item ni_esc; - coord x, y; - struct sctstr target; - struct emp_qelem bomb_list; - struct emp_qelem esc_list; - int wantflags; - struct sctstr ap_sect; - s_char buf[1024]; + int rel; + s_char *p; + int mission_flags; + int tech; + coord tx, ty; + coord ax, ay; + int ap_to_target; + struct ichrstr *ip; + s_char flightpath[MAX_PATH_LEN]; + struct nstr_item ni_bomb; + struct nstr_item ni_esc; + coord x, y; + struct sctstr target; + struct emp_qelem bomb_list; + struct emp_qelem esc_list; + int wantflags; + struct sctstr ap_sect; + s_char buf[1024]; - wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) - return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); - if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 || *p == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) - return RET_SYN; - if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && - getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { - pr("Assembly point not owned by you or an ally!\n"); - return RET_SYN; - } - ax = x; - ay = y; - if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, - 0, P_FLYING) == 0 || *flightpath == 0) - return RET_SYN; - tx = ax; - ty = ay; - (void) pathtoxy(flightpath, &tx, &ty, fcost); - pr("target is %s\n", xyas(tx, ty, player->cnum)); - getsect(tx, ty, &target); + wantflags = 0; + if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + return RET_SYN; + if (!snxtitem + (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) + pr("No escorts...\n"); + if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 + || *p == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) + return RET_SYN; + if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && + getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { + pr("Assembly point not owned by you or an ally!\n"); + return RET_SYN; + } + ax = x; + ay = y; + if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, + 0, P_FLYING) == 0 || *flightpath == 0) + return RET_SYN; + tx = ax; + ty = ay; + (void)pathtoxy(flightpath, &tx, &ty, fcost); + pr("target is %s\n", xyas(tx, ty, player->cnum)); + getsect(tx, ty, &target); - rel = getrel(getnatp(target.sct_own), player->cnum); - if (rel != ALLIED && target.sct_own != player->cnum && target.sct_type != SCT_WATER) { - pr("You don't own %s!\n", xyas(tx,ty,player->cnum)); - return RET_FAIL; - } + rel = getrel(getnatp(target.sct_own), player->cnum); + if (rel != ALLIED && target.sct_own != player->cnum + && target.sct_type != SCT_WATER) { + pr("You don't own %s!\n", xyas(tx, ty, player->cnum)); + return RET_FAIL; + } - if ((ip = whatitem(player->argp[5], "Drop off what? ")) == 0) - return RET_SYN; - if (ip->i_vtype == V_CIVIL && target.sct_own != target.sct_oldown) { - pr("Can't drop civilians into occupied sectors.\n"); - return RET_FAIL; - } - ap_to_target = strlen(flightpath); - if (*(flightpath+strlen(flightpath)-1) == 'h') - ap_to_target--; - pr("range to target is %d\n", ap_to_target); - /* - * select planes within range - */ - mission_flags = 0; - pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, - 2, wantflags, P_M|P_O); - pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, - 2, P_ESC|P_F, P_M|P_O); - /* - * now arm and equip the bombers, transports, whatever. - * tech is stored in high 16 bits of mission_flags. - * yuck. - */ - tech=0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - mission_flags |= P_MINE; - mission_flags = pln_arm(&bomb_list, 2*ap_to_target, 'd', ip, 0, mission_flags,&tech); - if (rel != ALLIED && target.sct_own != player->cnum && - target.sct_type == SCT_WATER && !(mission_flags & P_MINE)) { - pr("You don't own %s!\n", xyas(tx,ty,player->cnum)); - return RET_FAIL; - } - if (QEMPTY(&bomb_list)) { - pr("No planes could be equipped for the mission.\n"); - return RET_FAIL; - } - mission_flags = pln_arm(&esc_list, 2*ap_to_target, 'd', ip, P_ESC|P_F, mission_flags,&tech); - ac_encounter(&bomb_list,&esc_list,ax,ay,flightpath,mission_flags,0,0,0); - if (QEMPTY(&bomb_list)) { - pr("No planes got through fighter defenses\n"); - } else { - getsect(tx, ty, &target); - pln_dropoff(&bomb_list, ip, tx, ty, (s_char *)&target, - EF_SECTOR); - } - pln_put(&bomb_list); - pln_put(&esc_list); - return RET_OK; + if ((ip = whatitem(player->argp[5], "Drop off what? ")) == 0) + return RET_SYN; + if (ip->i_vtype == V_CIVIL && target.sct_own != target.sct_oldown) { + pr("Can't drop civilians into occupied sectors.\n"); + return RET_FAIL; + } + ap_to_target = strlen(flightpath); + if (*(flightpath + strlen(flightpath) - 1) == 'h') + ap_to_target--; + pr("range to target is %d\n", ap_to_target); + /* + * select planes within range + */ + mission_flags = 0; + pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, + 2, wantflags, P_M | P_O); + pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, + 2, P_ESC | P_F, P_M | P_O); + /* + * now arm and equip the bombers, transports, whatever. + * tech is stored in high 16 bits of mission_flags. + * yuck. + */ + tech = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + mission_flags |= P_MINE; + mission_flags = + pln_arm(&bomb_list, 2 * ap_to_target, 'd', ip, 0, mission_flags, + &tech); + if (rel != ALLIED && target.sct_own != player->cnum + && target.sct_type == SCT_WATER && !(mission_flags & P_MINE)) { + pr("You don't own %s!\n", xyas(tx, ty, player->cnum)); + return RET_FAIL; + } + if (QEMPTY(&bomb_list)) { + pr("No planes could be equipped for the mission.\n"); + return RET_FAIL; + } + mission_flags = + pln_arm(&esc_list, 2 * ap_to_target, 'd', ip, P_ESC | P_F, + mission_flags, &tech); + ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, + 0, 0, 0); + if (QEMPTY(&bomb_list)) { + pr("No planes got through fighter defenses\n"); + } else { + getsect(tx, ty, &target); + pln_dropoff(&bomb_list, ip, tx, ty, (s_char *)&target, EF_SECTOR); + } + pln_put(&bomb_list); + pln_put(&esc_list); + return RET_OK; } diff --git a/src/lib/commands/dump.c b/src/lib/commands/dump.c index c1890caee..3a66f0535 100644 --- a/src/lib/commands/dump.c +++ b/src/lib/commands/dump.c @@ -48,427 +48,743 @@ int dump(void) { - struct sctstr sect; - s_char dirstr[20]; - int nsect; - int n,i; - struct nstr_sect nstr; - int del[I_MAX+1]; - int dist[I_MAX+1]; - int item[I_MAX+1]; - int cond[I_MAX+1]; - int field[128]; - struct natstr *np; - time_t now; + struct sctstr sect; + s_char dirstr[20]; + int nsect; + int n, i; + struct nstr_sect nstr; + int del[I_MAX + 1]; + int dist[I_MAX + 1]; + int item[I_MAX + 1]; + int cond[I_MAX + 1]; + int field[128]; + struct natstr *np; + time_t now; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - (void) strcpy(dirstr, ". $"); - n = 1; - for (n = 1; n <= 6; n++) - dirstr[n] = dirch[n]; - nsect = 0; - np = getnatp(player->cnum); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + (void)strcpy(dirstr, ". $"); + n = 1; + for (n = 1; n <= 6; n++) + dirstr[n] = dirch[n]; + nsect = 0; + np = getnatp(player->cnum); - if (!player->argp[2]) { - for (n = 1; n <= 80; n++) field[n-1] = n; - field[n-1] = 0; - } else { - n = 2; - i = 0; - while (player->argp[n]) { - if (!strcmp("des",player->argp[n])) { - field[i++] = 1; - } else if (!strcmp("sdes",player->argp[n])) { - field[i++] = 2; - } else if (!strcmp("eff",player->argp[n])) { - field[i++] = 3; - } else if (!strcmp("mob",player->argp[n])) { - field[i++] = 4; - } else if (!strcmp("*",player->argp[n])) { - field[i++] = 5; - } else if (!strcmp("off",player->argp[n])) { - field[i++] = 6; - } else if (!strcmp("min",player->argp[n])) { - field[i++] = 7; - } else if (!strcmp("gold",player->argp[n])) { - field[i++] = 8; - } else if (!strcmp("fert",player->argp[n])) { - field[i++] = 9; - } else if (!strcmp("ocontent",player->argp[n])) { - field[i++] = 10; - } else if (!strcmp("uran",player->argp[n])) { - field[i++] = 11; - } else if (!strcmp("work",player->argp[n])) { - field[i++] = 12; - } else if (!strcmp("avail",player->argp[n])) { - field[i++] = 13; - } else if (!strcmp("terr",player->argp[n])) { - field[i++] = 14; - } else if (!strcmp("civ",player->argp[n])) { - field[i++] = 15; - } else if (!strcmp("mil",player->argp[n])) { - field[i++] = 16; - } else if (!strcmp("uw",player->argp[n])) { - field[i++] = 17; - } else if (!strcmp("food",player->argp[n])) { - field[i++] = 18; - } else if (!strcmp("shell",player->argp[n])) { - field[i++] = 19; - } else if (!strcmp("gun",player->argp[n])) { - field[i++] = 20; - } else if (!strcmp("pet",player->argp[n])) { - field[i++] = 21; - } else if (!strcmp("iron",player->argp[n])) { - field[i++] = 22; - } else if (!strcmp("dust",player->argp[n])) { - field[i++] = 23; - } else if (!strcmp("bar",player->argp[n])) { - field[i++] = 24; - } else if (!strcmp("oil",player->argp[n])) { - field[i++] = 25; - } else if (!strcmp("lcm",player->argp[n])) { - field[i++] = 26; - } else if (!strcmp("hcm",player->argp[n])) { - field[i++] = 27; - } else if (!strcmp("rad",player->argp[n])) { - field[i++] = 28; - } else if (!strcmp("u_del",player->argp[n])) { - field[i++] = 29; - } else if (!strcmp("f_del",player->argp[n])) { - field[i++] = 30; - } else if (!strcmp("s_del",player->argp[n])) { - field[i++] = 31; - } else if (!strcmp("g_del",player->argp[n])) { - field[i++] = 32; - } else if (!strcmp("p_del",player->argp[n])) { - field[i++] = 33; - } else if (!strcmp("i_del",player->argp[n])) { - field[i++] = 34; - } else if (!strcmp("d_del",player->argp[n])) { - field[i++] = 35; - } else if (!strcmp("b_del",player->argp[n])) { - field[i++] = 36; - } else if (!strcmp("o_del",player->argp[n])) { - field[i++] = 37; - } else if (!strcmp("l_del",player->argp[n])) { - field[i++] = 38; - } else if (!strcmp("h_del",player->argp[n])) { - field[i++] = 39; - } else if (!strcmp("r_del",player->argp[n])) { - field[i++] = 40; - } else if (!strcmp("u_cut",player->argp[n])) { - field[i++] = 41; - } else if (!strcmp("f_cut",player->argp[n])) { - field[i++] = 42; - } else if (!strcmp("s_cut",player->argp[n])) { - field[i++] = 43; - } else if (!strcmp("g_cut",player->argp[n])) { - field[i++] = 44; - } else if (!strcmp("p_cut",player->argp[n])) { - field[i++] = 45; - } else if (!strcmp("i_cut",player->argp[n])) { - field[i++] = 46; - } else if (!strcmp("d_cut",player->argp[n])) { - field[i++] = 47; - } else if (!strcmp("b_cut",player->argp[n])) { - field[i++] = 48; - } else if (!strcmp("o_cut",player->argp[n])) { - field[i++] = 49; - } else if (!strcmp("l_cut",player->argp[n])) { - field[i++] = 50; - } else if (!strcmp("h_cut",player->argp[n])) { - field[i++] = 51; - } else if (!strcmp("r_cut",player->argp[n])) { - field[i++] = 52; - } else if (!strcmp("dist_x",player->argp[n])) { - field[i++] = 53; - } else if (!strcmp("dist_y",player->argp[n])) { - field[i++] = 54; - } else if (!strcmp("c_dist",player->argp[n])) { - field[i++] = 55; - } else if (!strcmp("m_dist",player->argp[n])) { - field[i++] = 56; - } else if (!strcmp("u_dist",player->argp[n])) { - field[i++] = 57; - } else if (!strcmp("f_dist",player->argp[n])) { - field[i++] = 58; - } else if (!strcmp("s_dist",player->argp[n])) { - field[i++] = 59; - } else if (!strcmp("g_dist",player->argp[n])) { - field[i++] = 60; - } else if (!strcmp("p_dist",player->argp[n])) { - field[i++] = 61; - } else if (!strcmp("i_dist",player->argp[n])) { - field[i++] = 62; - } else if (!strcmp("d_dist",player->argp[n])) { - field[i++] = 63; - } else if (!strcmp("b_dist",player->argp[n])) { - field[i++] = 64; - } else if (!strcmp("o_dist",player->argp[n])) { - field[i++] = 65; - } else if (!strcmp("l_dist",player->argp[n])) { - field[i++] = 66; - } else if (!strcmp("h_dist",player->argp[n])) { - field[i++] = 67; - } else if (!strcmp("r_dist",player->argp[n])) { - field[i++] = 68; - } else if (!strcmp("road",player->argp[n])) { - field[i++] = 69; - } else if (!strcmp("rail",player->argp[n])) { - field[i++] = 70; - } else if (!strcmp("defense",player->argp[n])) { - field[i++] = 71; - } else if (!strcmp("fallout",player->argp[n])) { - field[i++] = 72; - } else if (!strcmp("coast",player->argp[n])) { - field[i++] = 73; - } else if (!strcmp("c_del",player->argp[n])) { - field[i++] = 74; - } else if (!strcmp("m_del",player->argp[n])) { - field[i++] = 75; - } else if (!strcmp("c_cut",player->argp[n])) { - field[i++] = 76; - } else if (!strcmp("m_cut",player->argp[n])) { - field[i++] = 77; - } else if (!strcmp("terr1",player->argp[n])) { - field[i++] = 78; - } else if (!strcmp("terr2",player->argp[n])) { - field[i++] = 79; - } else if (!strcmp("terr3",player->argp[n])) { - field[i++] = 80; - } else { - pr("Unrecognized field %s\n",player->argp[n]); - } - if (n++ > 100) { - pr("Too many fields\n"); - return RET_FAIL; - } - } - field[i] = 0; + if (!player->argp[2]) { + for (n = 1; n <= 80; n++) + field[n - 1] = n; + field[n - 1] = 0; + } else { + n = 2; + i = 0; + while (player->argp[n]) { + if (!strcmp("des", player->argp[n])) { + field[i++] = 1; + } else if (!strcmp("sdes", player->argp[n])) { + field[i++] = 2; + } else if (!strcmp("eff", player->argp[n])) { + field[i++] = 3; + } else if (!strcmp("mob", player->argp[n])) { + field[i++] = 4; + } else if (!strcmp("*", player->argp[n])) { + field[i++] = 5; + } else if (!strcmp("off", player->argp[n])) { + field[i++] = 6; + } else if (!strcmp("min", player->argp[n])) { + field[i++] = 7; + } else if (!strcmp("gold", player->argp[n])) { + field[i++] = 8; + } else if (!strcmp("fert", player->argp[n])) { + field[i++] = 9; + } else if (!strcmp("ocontent", player->argp[n])) { + field[i++] = 10; + } else if (!strcmp("uran", player->argp[n])) { + field[i++] = 11; + } else if (!strcmp("work", player->argp[n])) { + field[i++] = 12; + } else if (!strcmp("avail", player->argp[n])) { + field[i++] = 13; + } else if (!strcmp("terr", player->argp[n])) { + field[i++] = 14; + } else if (!strcmp("civ", player->argp[n])) { + field[i++] = 15; + } else if (!strcmp("mil", player->argp[n])) { + field[i++] = 16; + } else if (!strcmp("uw", player->argp[n])) { + field[i++] = 17; + } else if (!strcmp("food", player->argp[n])) { + field[i++] = 18; + } else if (!strcmp("shell", player->argp[n])) { + field[i++] = 19; + } else if (!strcmp("gun", player->argp[n])) { + field[i++] = 20; + } else if (!strcmp("pet", player->argp[n])) { + field[i++] = 21; + } else if (!strcmp("iron", player->argp[n])) { + field[i++] = 22; + } else if (!strcmp("dust", player->argp[n])) { + field[i++] = 23; + } else if (!strcmp("bar", player->argp[n])) { + field[i++] = 24; + } else if (!strcmp("oil", player->argp[n])) { + field[i++] = 25; + } else if (!strcmp("lcm", player->argp[n])) { + field[i++] = 26; + } else if (!strcmp("hcm", player->argp[n])) { + field[i++] = 27; + } else if (!strcmp("rad", player->argp[n])) { + field[i++] = 28; + } else if (!strcmp("u_del", player->argp[n])) { + field[i++] = 29; + } else if (!strcmp("f_del", player->argp[n])) { + field[i++] = 30; + } else if (!strcmp("s_del", player->argp[n])) { + field[i++] = 31; + } else if (!strcmp("g_del", player->argp[n])) { + field[i++] = 32; + } else if (!strcmp("p_del", player->argp[n])) { + field[i++] = 33; + } else if (!strcmp("i_del", player->argp[n])) { + field[i++] = 34; + } else if (!strcmp("d_del", player->argp[n])) { + field[i++] = 35; + } else if (!strcmp("b_del", player->argp[n])) { + field[i++] = 36; + } else if (!strcmp("o_del", player->argp[n])) { + field[i++] = 37; + } else if (!strcmp("l_del", player->argp[n])) { + field[i++] = 38; + } else if (!strcmp("h_del", player->argp[n])) { + field[i++] = 39; + } else if (!strcmp("r_del", player->argp[n])) { + field[i++] = 40; + } else if (!strcmp("u_cut", player->argp[n])) { + field[i++] = 41; + } else if (!strcmp("f_cut", player->argp[n])) { + field[i++] = 42; + } else if (!strcmp("s_cut", player->argp[n])) { + field[i++] = 43; + } else if (!strcmp("g_cut", player->argp[n])) { + field[i++] = 44; + } else if (!strcmp("p_cut", player->argp[n])) { + field[i++] = 45; + } else if (!strcmp("i_cut", player->argp[n])) { + field[i++] = 46; + } else if (!strcmp("d_cut", player->argp[n])) { + field[i++] = 47; + } else if (!strcmp("b_cut", player->argp[n])) { + field[i++] = 48; + } else if (!strcmp("o_cut", player->argp[n])) { + field[i++] = 49; + } else if (!strcmp("l_cut", player->argp[n])) { + field[i++] = 50; + } else if (!strcmp("h_cut", player->argp[n])) { + field[i++] = 51; + } else if (!strcmp("r_cut", player->argp[n])) { + field[i++] = 52; + } else if (!strcmp("dist_x", player->argp[n])) { + field[i++] = 53; + } else if (!strcmp("dist_y", player->argp[n])) { + field[i++] = 54; + } else if (!strcmp("c_dist", player->argp[n])) { + field[i++] = 55; + } else if (!strcmp("m_dist", player->argp[n])) { + field[i++] = 56; + } else if (!strcmp("u_dist", player->argp[n])) { + field[i++] = 57; + } else if (!strcmp("f_dist", player->argp[n])) { + field[i++] = 58; + } else if (!strcmp("s_dist", player->argp[n])) { + field[i++] = 59; + } else if (!strcmp("g_dist", player->argp[n])) { + field[i++] = 60; + } else if (!strcmp("p_dist", player->argp[n])) { + field[i++] = 61; + } else if (!strcmp("i_dist", player->argp[n])) { + field[i++] = 62; + } else if (!strcmp("d_dist", player->argp[n])) { + field[i++] = 63; + } else if (!strcmp("b_dist", player->argp[n])) { + field[i++] = 64; + } else if (!strcmp("o_dist", player->argp[n])) { + field[i++] = 65; + } else if (!strcmp("l_dist", player->argp[n])) { + field[i++] = 66; + } else if (!strcmp("h_dist", player->argp[n])) { + field[i++] = 67; + } else if (!strcmp("r_dist", player->argp[n])) { + field[i++] = 68; + } else if (!strcmp("road", player->argp[n])) { + field[i++] = 69; + } else if (!strcmp("rail", player->argp[n])) { + field[i++] = 70; + } else if (!strcmp("defense", player->argp[n])) { + field[i++] = 71; + } else if (!strcmp("fallout", player->argp[n])) { + field[i++] = 72; + } else if (!strcmp("coast", player->argp[n])) { + field[i++] = 73; + } else if (!strcmp("c_del", player->argp[n])) { + field[i++] = 74; + } else if (!strcmp("m_del", player->argp[n])) { + field[i++] = 75; + } else if (!strcmp("c_cut", player->argp[n])) { + field[i++] = 76; + } else if (!strcmp("m_cut", player->argp[n])) { + field[i++] = 77; + } else if (!strcmp("terr1", player->argp[n])) { + field[i++] = 78; + } else if (!strcmp("terr2", player->argp[n])) { + field[i++] = 79; + } else if (!strcmp("terr3", player->argp[n])) { + field[i++] = 80; + } else { + pr("Unrecognized field %s\n", player->argp[n]); + } + if (n++ > 100) { + pr("Too many fields\n"); + return RET_FAIL; + } } + field[i] = 0; + } - if (player->god) - pr(" "); - time(&now); - pr("DUMP SECTOR %d\n", now); - if (player->god) - pr("own "); - pr("x y"); - n = 0; - while (field[n]) { - pr(" "); - switch (field[n]) { - case 1: pr("des"); break; - case 2: pr("sdes"); break; - case 3: pr("eff"); break; - case 4: pr("mob"); break; - case 5: pr("*"); break; - case 6: pr("off"); break; - case 7: pr("min"); break; - case 8: pr("gold"); break; - case 9: pr("fert"); break; - case 10: pr("ocontent"); break; - case 11: pr("uran"); break; - case 12: pr("work"); break; - case 13: pr("avail"); break; - case 14: pr("terr"); break; - case 15: pr("civ"); break; - case 16: pr("mil"); break; - case 17: pr("uw"); break; - case 18: pr("food"); break; - case 19: pr("shell"); break; - case 20: pr("gun"); break; - case 21: pr("pet"); break; - case 22: pr("iron"); break; - case 23: pr("dust"); break; - case 24: pr("bar"); break; - case 25: pr("oil"); break; - case 26: pr("lcm"); break; - case 27: pr("hcm"); break; - case 28: pr("rad"); break; - case 29: pr("u_del"); break; - case 30: pr("f_del"); break; - case 31: pr("s_del"); break; - case 32: pr("g_del"); break; - case 33: pr("p_del"); break; - case 34: pr("i_del"); break; - case 35: pr("d_del"); break; - case 36: pr("b_del"); break; - case 37: pr("o_del"); break; - case 38: pr("l_del"); break; - case 39: pr("h_del"); break; - case 40: pr("r_del"); break; - case 41: pr("u_cut"); break; - case 42: pr("f_cut"); break; - case 43: pr("s_cut"); break; - case 44: pr("g_cut"); break; - case 45: pr("p_cut"); break; - case 46: pr("i_cut"); break; - case 47: pr("d_cut"); break; - case 48: pr("b_cut"); break; - case 49: pr("o_cut"); break; - case 50: pr("l_cut"); break; - case 51: pr("h_cut"); break; - case 52: pr("r_cut"); break; - case 53: pr("dist_x"); break; - case 54: pr("dist_y"); break; - case 55: pr("c_dist"); break; - case 56: pr("m_dist"); break; - case 57: pr("u_dist"); break; - case 58: pr("f_dist"); break; - case 59: pr("s_dist"); break; - case 60: pr("g_dist"); break; - case 61: pr("p_dist"); break; - case 62: pr("i_dist"); break; - case 63: pr("d_dist"); break; - case 64: pr("b_dist"); break; - case 65: pr("o_dist"); break; - case 66: pr("l_dist"); break; - case 67: pr("h_dist"); break; - case 68: pr("r_dist"); break; - case 69: pr("road"); break; - case 70: pr("rail"); break; - case 71: pr("defense"); break; - case 72: pr("fallout"); break; - case 73: pr("coast"); break; - case 74: pr("c_del"); break; - case 75: pr("m_del"); break; - case 76: pr("c_cut"); break; - case 77: pr("m_cut"); break; - case 78: pr("terr1"); break; - case 79: pr("terr2"); break; - case 80: pr("terr3"); break; - } - n++; + if (player->god) + pr(" "); + time(&now); + pr("DUMP SECTOR %d\n", now); + if (player->god) + pr("own "); + pr("x y"); + n = 0; + while (field[n]) { + pr(" "); + switch (field[n]) { + case 1: + pr("des"); + break; + case 2: + pr("sdes"); + break; + case 3: + pr("eff"); + break; + case 4: + pr("mob"); + break; + case 5: + pr("*"); + break; + case 6: + pr("off"); + break; + case 7: + pr("min"); + break; + case 8: + pr("gold"); + break; + case 9: + pr("fert"); + break; + case 10: + pr("ocontent"); + break; + case 11: + pr("uran"); + break; + case 12: + pr("work"); + break; + case 13: + pr("avail"); + break; + case 14: + pr("terr"); + break; + case 15: + pr("civ"); + break; + case 16: + pr("mil"); + break; + case 17: + pr("uw"); + break; + case 18: + pr("food"); + break; + case 19: + pr("shell"); + break; + case 20: + pr("gun"); + break; + case 21: + pr("pet"); + break; + case 22: + pr("iron"); + break; + case 23: + pr("dust"); + break; + case 24: + pr("bar"); + break; + case 25: + pr("oil"); + break; + case 26: + pr("lcm"); + break; + case 27: + pr("hcm"); + break; + case 28: + pr("rad"); + break; + case 29: + pr("u_del"); + break; + case 30: + pr("f_del"); + break; + case 31: + pr("s_del"); + break; + case 32: + pr("g_del"); + break; + case 33: + pr("p_del"); + break; + case 34: + pr("i_del"); + break; + case 35: + pr("d_del"); + break; + case 36: + pr("b_del"); + break; + case 37: + pr("o_del"); + break; + case 38: + pr("l_del"); + break; + case 39: + pr("h_del"); + break; + case 40: + pr("r_del"); + break; + case 41: + pr("u_cut"); + break; + case 42: + pr("f_cut"); + break; + case 43: + pr("s_cut"); + break; + case 44: + pr("g_cut"); + break; + case 45: + pr("p_cut"); + break; + case 46: + pr("i_cut"); + break; + case 47: + pr("d_cut"); + break; + case 48: + pr("b_cut"); + break; + case 49: + pr("o_cut"); + break; + case 50: + pr("l_cut"); + break; + case 51: + pr("h_cut"); + break; + case 52: + pr("r_cut"); + break; + case 53: + pr("dist_x"); + break; + case 54: + pr("dist_y"); + break; + case 55: + pr("c_dist"); + break; + case 56: + pr("m_dist"); + break; + case 57: + pr("u_dist"); + break; + case 58: + pr("f_dist"); + break; + case 59: + pr("s_dist"); + break; + case 60: + pr("g_dist"); + break; + case 61: + pr("p_dist"); + break; + case 62: + pr("i_dist"); + break; + case 63: + pr("d_dist"); + break; + case 64: + pr("b_dist"); + break; + case 65: + pr("o_dist"); + break; + case 66: + pr("l_dist"); + break; + case 67: + pr("h_dist"); + break; + case 68: + pr("r_dist"); + break; + case 69: + pr("road"); + break; + case 70: + pr("rail"); + break; + case 71: + pr("defense"); + break; + case 72: + pr("fallout"); + break; + case 73: + pr("coast"); + break; + case 74: + pr("c_del"); + break; + case 75: + pr("m_del"); + break; + case 76: + pr("c_cut"); + break; + case 77: + pr("m_cut"); + break; + case 78: + pr("terr1"); + break; + case 79: + pr("terr2"); + break; + case 80: + pr("terr3"); + break; } - pr("\n"); + n++; + } + pr("\n"); - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - nsect++; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + nsect++; /* census */ - if (player->god) - pr("%d ", sect.sct_own); - getvec(VT_DEL, del, (s_char *)§, EF_SECTOR); - getvec(VT_DIST, dist, (s_char *)§, EF_SECTOR); - getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); - getvec(VT_COND, cond, (s_char *)§, EF_SECTOR); - pr("%d %d", xrel(np,nstr.x), yrel(np,nstr.y)); + if (player->god) + pr("%d ", sect.sct_own); + getvec(VT_DEL, del, (s_char *)§, EF_SECTOR); + getvec(VT_DIST, dist, (s_char *)§, EF_SECTOR); + getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); + getvec(VT_COND, cond, (s_char *)§, EF_SECTOR); + pr("%d %d", xrel(np, nstr.x), yrel(np, nstr.y)); - set_coastal(§); - n = 0; - while (field[n]) { - pr(" "); - switch (field[n++]) { - case 1: pr("%c", dchr[sect.sct_type].d_mnem); break; - case 2: if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr("_"); - break; - case 3: pr("%d", sect.sct_effic); break; - case 4: pr("%d", sect.sct_mobil); break; - case 5: pr("%c", sect.sct_own != sect.sct_oldown ? '*' : '.'); - break; - case 6: pr("%d", sect.sct_off); break; - case 7: pr("%d", sect.sct_min); break; - case 8: pr("%d", sect.sct_gmin); break; - case 9: pr("%d", sect.sct_fertil); break; - case 10: pr("%d", sect.sct_oil); break; - case 11: pr("%d", sect.sct_uran); break; - case 12: pr("%d", sect.sct_work); break; - case 13: pr("%d", sect.sct_avail); break; - case 14: pr("%d", sect.sct_terr); break; - case 15: pr("%d", item[I_CIVIL]); break; - case 16: pr("%d", item[I_MILIT]); break; - case 17: pr("%d", item[I_UW]); break; - case 18: pr("%d", item[I_FOOD]); break; + set_coastal(§); + n = 0; + while (field[n]) { + pr(" "); + switch (field[n++]) { + case 1: + pr("%c", dchr[sect.sct_type].d_mnem); + break; + case 2: + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr("_"); + break; + case 3: + pr("%d", sect.sct_effic); + break; + case 4: + pr("%d", sect.sct_mobil); + break; + case 5: + pr("%c", sect.sct_own != sect.sct_oldown ? '*' : '.'); + break; + case 6: + pr("%d", sect.sct_off); + break; + case 7: + pr("%d", sect.sct_min); + break; + case 8: + pr("%d", sect.sct_gmin); + break; + case 9: + pr("%d", sect.sct_fertil); + break; + case 10: + pr("%d", sect.sct_oil); + break; + case 11: + pr("%d", sect.sct_uran); + break; + case 12: + pr("%d", sect.sct_work); + break; + case 13: + pr("%d", sect.sct_avail); + break; + case 14: + pr("%d", sect.sct_terr); + break; + case 15: + pr("%d", item[I_CIVIL]); + break; + case 16: + pr("%d", item[I_MILIT]); + break; + case 17: + pr("%d", item[I_UW]); + break; + case 18: + pr("%d", item[I_FOOD]); + break; /* commodity */ - case 19: pr("%d", item[I_SHELL]); break; - case 20: pr("%d", item[I_GUN]); break; - case 21: pr("%d", item[I_PETROL]); break; - case 22: pr("%d", item[I_IRON]); break; - case 23: pr("%d", item[I_DUST]); break; - case 24: pr("%d", item[I_BAR]); break; - case 25: pr("%d", item[I_OIL]); break; - case 26: pr("%d", item[I_LCM]); break; - case 27: pr("%d", item[I_HCM]); break; - case 28: pr("%d", item[I_RAD]); break; + case 19: + pr("%d", item[I_SHELL]); + break; + case 20: + pr("%d", item[I_GUN]); + break; + case 21: + pr("%d", item[I_PETROL]); + break; + case 22: + pr("%d", item[I_IRON]); + break; + case 23: + pr("%d", item[I_DUST]); + break; + case 24: + pr("%d", item[I_BAR]); + break; + case 25: + pr("%d", item[I_OIL]); + break; + case 26: + pr("%d", item[I_LCM]); + break; + case 27: + pr("%d", item[I_HCM]); + break; + case 28: + pr("%d", item[I_RAD]); + break; /* cutoff */ - case 29: pr("%c", dirstr[del[I_UW] & 0x7]); break; - case 30: pr("%c", dirstr[del[I_FOOD] & 0x7]); break; - case 31: pr("%c", dirstr[del[I_SHELL] & 0x7]); break; - case 32: pr("%c", dirstr[del[I_GUN] & 0x7]); break; - case 33: pr("%c", dirstr[del[I_PETROL] & 0x7]); break; - case 34: pr("%c", dirstr[del[I_IRON] & 0x7]); break; - case 35: pr("%c", dirstr[del[I_DUST] & 0x7]); break; - case 36: pr("%c", dirstr[del[I_BAR] & 0x7]); break; - case 37: pr("%c", dirstr[del[I_OIL] & 0x7]); break; - case 38: pr("%c", dirstr[del[I_LCM] & 0x7]); break; - case 39: pr("%c", dirstr[del[I_HCM] & 0x7]); break; - case 40: pr("%c", dirstr[del[I_RAD] & 0x7]); break; - case 41: pr("%d", del[I_UW] & ~0x7); break; - case 42: pr("%d", del[I_FOOD] & ~0x7); break; - case 43: pr("%d", del[I_SHELL] & ~0x7); break; - case 44: pr("%d", del[I_GUN] & ~0x7); break; - case 45: pr("%d", del[I_PETROL] & ~0x7); break; - case 46: pr("%d", del[I_IRON] & ~0x7); break; - case 47: pr("%d", del[I_DUST] & ~0x7); break; - case 48: pr("%d", del[I_BAR] & ~0x7); break; - case 49: pr("%d", del[I_OIL] & ~0x7); break; - case 50: pr("%d", del[I_LCM] & ~0x7); break; - case 51: pr("%d", del[I_HCM] & ~0x7); break; - case 52: pr("%d", del[I_RAD] & ~0x7); break; + case 29: + pr("%c", dirstr[del[I_UW] & 0x7]); + break; + case 30: + pr("%c", dirstr[del[I_FOOD] & 0x7]); + break; + case 31: + pr("%c", dirstr[del[I_SHELL] & 0x7]); + break; + case 32: + pr("%c", dirstr[del[I_GUN] & 0x7]); + break; + case 33: + pr("%c", dirstr[del[I_PETROL] & 0x7]); + break; + case 34: + pr("%c", dirstr[del[I_IRON] & 0x7]); + break; + case 35: + pr("%c", dirstr[del[I_DUST] & 0x7]); + break; + case 36: + pr("%c", dirstr[del[I_BAR] & 0x7]); + break; + case 37: + pr("%c", dirstr[del[I_OIL] & 0x7]); + break; + case 38: + pr("%c", dirstr[del[I_LCM] & 0x7]); + break; + case 39: + pr("%c", dirstr[del[I_HCM] & 0x7]); + break; + case 40: + pr("%c", dirstr[del[I_RAD] & 0x7]); + break; + case 41: + pr("%d", del[I_UW] & ~0x7); + break; + case 42: + pr("%d", del[I_FOOD] & ~0x7); + break; + case 43: + pr("%d", del[I_SHELL] & ~0x7); + break; + case 44: + pr("%d", del[I_GUN] & ~0x7); + break; + case 45: + pr("%d", del[I_PETROL] & ~0x7); + break; + case 46: + pr("%d", del[I_IRON] & ~0x7); + break; + case 47: + pr("%d", del[I_DUST] & ~0x7); + break; + case 48: + pr("%d", del[I_BAR] & ~0x7); + break; + case 49: + pr("%d", del[I_OIL] & ~0x7); + break; + case 50: + pr("%d", del[I_LCM] & ~0x7); + break; + case 51: + pr("%d", del[I_HCM] & ~0x7); + break; + case 52: + pr("%d", del[I_RAD] & ~0x7); + break; /* level */ - case 53: pr("%d", xrel(getnatp(player->cnum),sect.sct_dist_x)); break; - case 54: pr("%d", yrel(getnatp(player->cnum),sect.sct_dist_y)); break; - case 55: pr("%d", dist[I_CIVIL]); break; - case 56: pr("%d", dist[I_MILIT]); break; - case 57: pr("%d", dist[I_UW]); break; - case 58: pr("%d", dist[I_FOOD]); break; - case 59: pr("%d", dist[I_SHELL]); break; - case 60: pr("%d", dist[I_GUN]); break; - case 61: pr("%d", dist[I_PETROL]); break; - case 62: pr("%d", dist[I_IRON]); break; - case 63: pr("%d", dist[I_DUST]); break; - case 64: pr("%d", dist[I_BAR]); break; - case 65: pr("%d", dist[I_OIL]); break; - case 66: pr("%d", dist[I_LCM]); break; - case 67: pr("%d", dist[I_HCM]); break; - case 68: pr("%d", dist[I_RAD]); break; - case 69: pr("%d", sect.sct_road); break; - case 70: pr("%d", sect.sct_rail); break; - case 71: pr("%d", sect.sct_defense); break; - case 72: - if (opt_FALLOUT) - pr("%d", cond[C_FALLOUT]); - else - pr("0"); - break; - case 73: pr("%d", sect.sct_coastal); break; - case 74: pr("%c", dirstr[del[I_CIVIL] & 0x7]); break; - case 75: pr("%c", dirstr[del[I_MILIT] & 0x7]); break; - case 76: pr("%d", del[I_CIVIL] & ~0x7); break; - case 77: pr("%d", del[I_MILIT] & ~0x7); break; - case 78: pr("%d", sect.sct_terr1); break; - case 79: pr("%d", sect.sct_terr2); break; - case 80: pr("%d", sect.sct_terr3); break; - } - } - pr("\n"); - } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); + case 53: + pr("%d", xrel(getnatp(player->cnum), sect.sct_dist_x)); + break; + case 54: + pr("%d", yrel(getnatp(player->cnum), sect.sct_dist_y)); + break; + case 55: + pr("%d", dist[I_CIVIL]); + break; + case 56: + pr("%d", dist[I_MILIT]); + break; + case 57: + pr("%d", dist[I_UW]); + break; + case 58: + pr("%d", dist[I_FOOD]); + break; + case 59: + pr("%d", dist[I_SHELL]); + break; + case 60: + pr("%d", dist[I_GUN]); + break; + case 61: + pr("%d", dist[I_PETROL]); + break; + case 62: + pr("%d", dist[I_IRON]); + break; + case 63: + pr("%d", dist[I_DUST]); + break; + case 64: + pr("%d", dist[I_BAR]); + break; + case 65: + pr("%d", dist[I_OIL]); + break; + case 66: + pr("%d", dist[I_LCM]); + break; + case 67: + pr("%d", dist[I_HCM]); + break; + case 68: + pr("%d", dist[I_RAD]); + break; + case 69: + pr("%d", sect.sct_road); + break; + case 70: + pr("%d", sect.sct_rail); + break; + case 71: + pr("%d", sect.sct_defense); + break; + case 72: + if (opt_FALLOUT) + pr("%d", cond[C_FALLOUT]); else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return RET_OK; + pr("0"); + break; + case 73: + pr("%d", sect.sct_coastal); + break; + case 74: + pr("%c", dirstr[del[I_CIVIL] & 0x7]); + break; + case 75: + pr("%c", dirstr[del[I_MILIT] & 0x7]); + break; + case 76: + pr("%d", del[I_CIVIL] & ~0x7); + break; + case 77: + pr("%d", del[I_MILIT] & ~0x7); + break; + case 78: + pr("%d", sect.sct_terr1); + break; + case 79: + pr("%d", sect.sct_terr2); + break; + case 80: + pr("%d", sect.sct_terr3); + break; + } + } + pr("\n"); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return RET_OK; } - diff --git a/src/lib/commands/echo.c b/src/lib/commands/echo.c index b0d58efaf..8e167afb2 100644 --- a/src/lib/commands/echo.c +++ b/src/lib/commands/echo.c @@ -38,7 +38,7 @@ int echo(void) { - pr("%s\n", player->argp[1]?player->argp[1]:(s_char *)""); + pr("%s\n", player->argp[1] ? player->argp[1] : (s_char *)""); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index fc7292d5d..1994633d0 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -55,19 +55,21 @@ #include "commands.h" #define END -1 -static void prnat(natid n); -static void pr_plane(struct plnstr *plane); -static void pr_land(struct lndstr *land); -static void pr_ship(struct shpstr *ship); +static void prnat(natid n); +static void pr_plane(struct plnstr *plane); +static void pr_land(struct lndstr *land); +static void pr_ship(struct shpstr *ship); static void prsect(struct sctstr *sect); -static void noise(struct sctstr *sptr, int public_amt, s_char *name, int old, int new); +static void noise(struct sctstr *sptr, int public_amt, s_char *name, + int old, int new); static void benefit(natid who, int good); int doland(s_char op, int arg, struct sctstr *sect); -int docountry(s_char op, int arg, s_char *p, float farg, natid nat, struct natstr *np); +int docountry(s_char op, int arg, s_char *p, float farg, natid nat, + struct natstr *np); int doship(s_char op, int arg, s_char *p, struct shpstr *ship); int dounit(s_char op, int arg, s_char *p, struct lndstr *land); int doplane(s_char op, int arg, s_char *p, struct plnstr *plane); - + /* * format: give c @@ -75,1102 +77,1100 @@ int doplane(s_char op, int arg, s_char *p, struct plnstr *plane); int edit(void) { - struct sctstr sect; - struct plnstr plane; - struct shpstr ship; - struct lndstr land; - s_char *what; - s_char *ptr; - s_char *thing; - int num; - int arg; - int err; - coord x, y; - float farg; - natid nat; - struct natstr *np; - s_char buf[1024]; - s_char ewhat; /* saves information from the command line - for use later on. */ + struct sctstr sect; + struct plnstr plane; + struct shpstr ship; + struct lndstr land; + s_char *what; + s_char *ptr; + s_char *thing; + int num; + int arg; + int err; + coord x, y; + float farg; + natid nat; + struct natstr *np; + s_char buf[1024]; + s_char ewhat; /* saves information from the command line + for use later on. */ - if ((what = getstarg(player->argp[1], - "Edit What (country, land, ship, plane, nuke, unit)? ", buf)) == 0) - return RET_SYN; - ewhat = what[0]; + if ((what = getstarg(player->argp[1], + "Edit What (country, land, ship, plane, nuke, unit)? ", + buf)) == 0) + return RET_SYN; + ewhat = what[0]; + switch (ewhat) { + case 'l': + if (!(ptr = getstarg(player->argp[2], "Sector : ", buf))) + return RET_FAIL; + if (!sarg_xy(ptr, &x, &y)) + return RET_FAIL; + if (!getsect(x, y, §)) + return RET_FAIL; + break; + case 'c': + if ((num = natarg(player->argp[2], "Country number? ")) < 0) + return RET_SYN; + nat = (natid)num; + np = getnatp(nat); + break; + case 'p': + if ((num = onearg(player->argp[2], "Plane number? ")) < 0) + return RET_SYN; + if (!getplane(num, &plane)) + return RET_SYN; + break; + case 's': + if ((num = onearg(player->argp[2], "Ship number? ")) < 0) + return RET_SYN; + if (!getship(num, &ship)) + return RET_SYN; + break; + case 'u': + if ((num = onearg(player->argp[2], "Unit number? ")) < 0) + return RET_SYN; + if (!getland(num, &land)) + return RET_SYN; + break; + case 'n': + pr("Not implemented yet.\n"); + break; + default: + pr("huh?\n"); + return RET_SYN; + } + if (player->argp[3] == 0) { switch (ewhat) { case 'l': - if (!(ptr = getstarg(player->argp[2], "Sector : ", buf))) - return RET_FAIL; - if (!sarg_xy(ptr, &x, &y)) - return RET_FAIL; - if (!getsect(x, y, §)) - return RET_FAIL; - break; + prsect(§); + break; case 'c': - if ((num = natarg(player->argp[2], "Country number? ")) < 0) - return RET_SYN; - nat = (natid) num; - np = getnatp(nat); - break; + prnat(nat); + break; case 'p': - if ((num = onearg(player->argp[2], "Plane number? ")) < 0) - return RET_SYN; - if (!getplane(num, &plane)) - return RET_SYN; - break; + pr_plane(&plane); + break; case 's': - if ((num = onearg(player->argp[2], "Ship number? ")) < 0) - return RET_SYN; - if (!getship(num, &ship)) - return RET_SYN; - break; + pr_ship(&ship); + break; case 'u': - if ((num = onearg(player->argp[2], "Unit number? ")) < 0) - return RET_SYN; - if (!getland(num, &land)) - return RET_SYN; - break; - case 'n': - pr("Not implemented yet.\n"); - break; - default: - pr("huh?\n"); - return RET_SYN; + pr_land(&land); + break; } - if (player->argp[3] == 0) { - switch (ewhat) { - case 'l': - prsect(§); - break; - case 'c': - prnat(nat); - break; - case 'p': - pr_plane(&plane); - break; - case 's': - pr_ship(&ship); - break; - case 'u': - pr_land(&land); - break; - } - } else if (player->argp[4] != 0) - (void) strcat (player->argp[3], player->argp[4]); - ptr = &buf[0]; - *ptr = 0; - for (;;) { - if ((err = getin(&thing, &ptr, &arg, buf)) != RET_OK) { - if (err == END) { - switch (ewhat) { - case 'c': - prnat(nat); - break; - case 'l': - prsect(§); - break; - case 's': - pr_ship(&ship); - break; - case 'u': - pr_land(&land); - break; - case 'p': - pr_plane(&plane); - break; - } - break; - } else - return err; - } + } else if (player->argp[4] != 0) + (void)strcat(player->argp[3], player->argp[4]); + ptr = &buf[0]; + *ptr = 0; + for (;;) { + if ((err = getin(&thing, &ptr, &arg, buf)) != RET_OK) { + if (err == END) { switch (ewhat) { case 'c': - farg = atof(ptr); - if ((err = docountry(thing[0], arg, ptr, farg, nat, np)) - != RET_OK) - return err; - break; + prnat(nat); + break; case 'l': - if ((err = doland(thing[0], arg, §)) != RET_OK) - return err; - if (!putsect(§)) - return RET_FAIL; - break; + prsect(§); + break; case 's': - if ((err = doship(thing[0], arg, ptr, &ship)) != RET_OK) - return err; - if (!putship(ship.shp_uid, &ship)) - return RET_FAIL; - break; + pr_ship(&ship); + break; case 'u': - farg = atof(ptr); - if ((err = dounit(thing[0], arg, ptr, &land)) - != RET_OK) - return err; - if (!putland(land.lnd_uid, &land)) - return RET_FAIL; - break; + pr_land(&land); + break; case 'p': - if ((err = doplane(thing[0], arg, ptr, &plane)) - != RET_OK) - return err; - if (!putplane(plane.pln_uid, &plane)) - return RET_FAIL; - break; + pr_plane(&plane); + break; } - if (err != RET_OK) - break; - else - ptr = 0; + break; + } else + return err; + } + switch (ewhat) { + case 'c': + farg = atof(ptr); + if ((err = docountry(thing[0], arg, ptr, farg, nat, np)) + != RET_OK) + return err; + break; + case 'l': + if ((err = doland(thing[0], arg, §)) != RET_OK) + return err; + if (!putsect(§)) + return RET_FAIL; + break; + case 's': + if ((err = doship(thing[0], arg, ptr, &ship)) != RET_OK) + return err; + if (!putship(ship.shp_uid, &ship)) + return RET_FAIL; + break; + case 'u': + farg = atof(ptr); + if ((err = dounit(thing[0], arg, ptr, &land)) + != RET_OK) + return err; + if (!putland(land.lnd_uid, &land)) + return RET_FAIL; + break; + case 'p': + if ((err = doplane(thing[0], arg, ptr, &plane)) + != RET_OK) + return err; + if (!putplane(plane.pln_uid, &plane)) + return RET_FAIL; + break; } - return RET_OK; + if (err != RET_OK) + break; + else + ptr = 0; + } + return RET_OK; } static void benefit(natid who, int good) { - if (!opt_GODNEWS) - return; + if (!opt_GODNEWS) + return; - if (good) { - if (who) - nreport(player->cnum, N_AIDS, who, 1); - } else { - if (who) - nreport(player->cnum, N_HURTS, who, 1); - } + if (good) { + if (who) + nreport(player->cnum, N_AIDS, who, 1); + } else { + if (who) + nreport(player->cnum, N_HURTS, who, 1); + } } static void noise(struct sctstr *sptr, int public_amt, s_char *name, int old, int new) { - s_char p[100]; + s_char p[100]; - pr("%s of %s changed from %d to %d\n", - name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new); - if (public_amt) - (void) sprintf(p, "changed from %d to %d", old, new); - else - (void) sprintf(p, "%s", (oldsct_own) - wu(player->cnum, sptr->sct_own, - "%s in %s was %s by an act of %s\n", - name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own), - p, cname(player->cnum)); - benefit(sptr->sct_own, (old < new)); + pr("%s of %s changed from %d to %d\n", + name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new); + if (public_amt) + (void)sprintf(p, "changed from %d to %d", old, new); + else + (void)sprintf(p, "%s", (old < new ? "increased" : "decreased")); + if (sptr->sct_own) + wu(player->cnum, sptr->sct_own, + "%s in %s was %s by an act of %s\n", + name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own), + p, cname(player->cnum)); + benefit(sptr->sct_own, (old < new)); } static void prsect(struct sctstr *sect) { - pr("X coord : %d\t",sect->sct_x); - pr("Y coord : %d\n",sect->sct_y); - pr("X dist coord: %d\t",sect->sct_dist_x); - pr("Y dist coord: %d\n",sect->sct_dist_y); - pr(" sect own oo eff mob min gld frt oil urn wrk lty che plg ptime fall avail\n"); - pr("things: o O e m i g f c u w l x p t F a\n"); - prxy("%4d,%-4d", sect->sct_x, sect->sct_y, player->cnum); - pr(" %c%c %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %4d %3d %5d %4d %5d\n", - dchr[sect->sct_type].d_mnem, - (sect->sct_newtype == sect->sct_type) ? ' ' : - dchr[sect->sct_newtype].d_mnem, - sect->sct_own, sect->sct_oldown, - sect->sct_effic, sect->sct_mobil, - sect->sct_min, sect->sct_gmin, - sect->sct_fertil, sect->sct_oil, sect->sct_uran, - sect->sct_work, sect->sct_loyal, - getvar(V_CHE, (s_char *)sect, EF_SECTOR), - getvar(V_PSTAGE, (s_char *)sect, EF_SECTOR), - getvar(V_PTIME, (s_char *)sect, EF_SECTOR), - getvar(V_FALLOUT, (s_char *)sect, EF_SECTOR), - sect->sct_avail); + pr("X coord : %d\t", sect->sct_x); + pr("Y coord : %d\n", sect->sct_y); + pr("X dist coord: %d\t", sect->sct_dist_x); + pr("Y dist coord: %d\n", sect->sct_dist_y); + pr(" sect own oo eff mob min gld frt oil urn wrk lty che plg ptime fall avail\n"); + pr("things: o O e m i g f c u w l x p t F a\n"); + prxy("%4d,%-4d", sect->sct_x, sect->sct_y, player->cnum); + pr(" %c%c %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %3d %4d %3d %5d %4d %5d\n", dchr[sect->sct_type].d_mnem, (sect->sct_newtype == sect->sct_type) ? ' ' : dchr[sect->sct_newtype].d_mnem, sect->sct_own, sect->sct_oldown, sect->sct_effic, sect->sct_mobil, sect->sct_min, sect->sct_gmin, sect->sct_fertil, sect->sct_oil, sect->sct_uran, sect->sct_work, sect->sct_loyal, getvar(V_CHE, (s_char *)sect, EF_SECTOR), getvar(V_PSTAGE, (s_char *)sect, EF_SECTOR), getvar(V_PTIME, (s_char *)sect, EF_SECTOR), getvar(V_FALLOUT, (s_char *)sect, EF_SECTOR), sect->sct_avail); - pr(" Mines : %d\n", getvar(V_MINE, (s_char *)sect, EF_SECTOR)); - pr(" Road %% : %d\n", sect->sct_road); - pr(" Rail %% : %d\n", sect->sct_rail); - pr(" Defense %% : %d\n", sect->sct_defense); - pr(" Coastal : %d\n", sect->sct_coastal); + pr(" Mines : %d\n", getvar(V_MINE, (s_char *)sect, EF_SECTOR)); + pr(" Road %% : %d\n", sect->sct_road); + pr(" Rail %% : %d\n", sect->sct_rail); + pr(" Defense %% : %d\n", sect->sct_defense); + pr(" Coastal : %d\n", sect->sct_coastal); } static void prnat(natid n) { - struct natstr *np; - int i; + struct natstr *np; + int i; - if ((np = getnatp(n)) == 0) - return; - pr("Country #: %2d\n", n); - pr("Name : %-20s\t", np->nat_cnam); - pr("Connected: %d\n", np->nat_connected); - pr("Representative : %-20s\n", np->nat_pnam); - pr("BTUs : %3d\t\t\t", np->nat_btu); - pr("Reserves : %5d\n", np->nat_reserve); - pr("Capital : %s\t\t", xyas(np->nat_xcap, np->nat_ycap, player->cnum)); - pr("Origin : %3s\n", xyas(np->nat_xorg, np->nat_yorg, player->cnum)); - pr("Status : 0x%x\t\t\t", np->nat_stat); - pr("Min Used : %3d\n", np->nat_minused); - pr("Technology : %.2f\t\t", np->nat_level[NAT_TLEV]); - pr("Research : %.2f\n", np->nat_level[NAT_RLEV]); - pr("Education : %.2f\t\t", np->nat_level[NAT_ELEV]); - pr("Happiness : %.2f\n", np->nat_level[NAT_HLEV]); - pr("Money : $%6d\n", np->nat_money); - pr("Telegrams : %6d\n", np->nat_tgms); - if (opt_DEMANDUPDATE) - pr("Updates missed : %d\n", np->nat_missed); - if (opt_HIDDEN) { - pr("Countries contacted: "); - for (i=0; i: %-20s\t", np->nat_cnam); + pr("Connected: %d\n", np->nat_connected); + pr("Representative : %-20s\n", np->nat_pnam); + pr("BTUs : %3d\t\t\t", np->nat_btu); + pr("Reserves : %5d\n", np->nat_reserve); + pr("Capital : %s\t\t", + xyas(np->nat_xcap, np->nat_ycap, player->cnum)); + pr("Origin : %3s\n", + xyas(np->nat_xorg, np->nat_yorg, player->cnum)); + pr("Status : 0x%x\t\t\t", np->nat_stat); + pr("Min Used : %3d\n", np->nat_minused); + pr("Technology : %.2f\t\t", np->nat_level[NAT_TLEV]); + pr("Research : %.2f\n", np->nat_level[NAT_RLEV]); + pr("Education : %.2f\t\t", np->nat_level[NAT_ELEV]); + pr("Happiness : %.2f\n", np->nat_level[NAT_HLEV]); + pr("Money : $%6d\n", np->nat_money); + pr("Telegrams : %6d\n", np->nat_tgms); + if (opt_DEMANDUPDATE) + pr("Updates missed : %d\n", np->nat_missed); + if (opt_HIDDEN) { + pr("Countries contacted: "); + for (i = 0; i < MAXNOC; i++) { + if (getcontact(np, i)) + pr("%d(%d) ", i, getcontact(np, i)); } + pr("\n"); + } } static void pr_plane(struct plnstr *plane) { - pr("UID : %d\t\t", (int)plane->pln_uid); - pr("Owner : %d\t\t", (int)plane->pln_own); - pr("Location : %s\n", xyas(plane->pln_x, plane->pln_y, player->cnum)); - pr("Efficiency : %d\t", (int)plane->pln_effic); - pr("Mobility : %d\n", (int)plane->pln_mobil); - pr("Tech : %d\t\t", plane->pln_tech); - pr("Wing : %c\n", plane->pln_wing); - pr("Attack : %d\t\t", plane->pln_att); - pr("Defense : %d\n", plane->pln_def); - pr("Range : %d\t\t", plane->pln_range); - pr("Flags : %d\n", plane->pln_flags); - pr("Ship : %d\t\t", plane->pln_ship); - pr("Land Unit : %d\t", plane->pln_land); - pr("Nuke Type : %d\n", plane->pln_nuketype); + pr("UID : %d\t\t", (int)plane->pln_uid); + pr("Owner : %d\t\t", (int)plane->pln_own); + pr("Location : %s\n", + xyas(plane->pln_x, plane->pln_y, player->cnum)); + pr("Efficiency : %d\t", (int)plane->pln_effic); + pr("Mobility : %d\n", (int)plane->pln_mobil); + pr("Tech : %d\t\t", plane->pln_tech); + pr("Wing : %c\n", plane->pln_wing); + pr("Attack : %d\t\t", plane->pln_att); + pr("Defense : %d\n", plane->pln_def); + pr("Range : %d\t\t", plane->pln_range); + pr("Flags : %d\n", plane->pln_flags); + pr("Ship : %d\t\t", plane->pln_ship); + pr("Land Unit : %d\t", plane->pln_land); + pr("Nuke Type : %d\n", plane->pln_nuketype); } static void pr_land(struct lndstr *land) { - int vec[I_MAX+1]; - struct lchrstr *lcp; + int vec[I_MAX + 1]; + struct lchrstr *lcp; - lcp = &lchr[(int)land->lnd_type]; - pr("UID : %d\n", (int)land->lnd_uid); - pr("Owner : %d\n", (int)land->lnd_own); - pr("Location : %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum)); - pr("Efficiency : %d\t", (int)land->lnd_effic); - pr("Mobility : %d\n", (int)land->lnd_mobil); - pr("Tech : %d\t\t", land->lnd_tech); - pr("Army : %c\n", land->lnd_army); - pr("Attack: %f\t", lcp->l_att); - pr("Defense: %f\n", lcp->l_def); - pr("Fortification : %d\t", land->lnd_harden); - pr("Fuel : %d\n", land->lnd_fuel); - count_land_planes(land); - pr("Xlight planes : %d\n", land->lnd_nxlight); - pr("Land unit : %d\n", land->lnd_land); - pr("Ship : %d\t\t", land->lnd_ship); - pr("Radius

: %d\n", land->lnd_rad_max); - pr("Retreat percentage : %d\n", (int)land->lnd_retreat); - pr("Retreat path : '%s'\t\tRetreat Flags : %d\n",land->lnd_rpath,(int)land->lnd_rflags); - getvec(VT_ITEM, vec, (s_char *)land, EF_LAND); - pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n"); - pr(" c m u f s g p i d o l h r\n"); - pr("%3d", vec[I_CIVIL]); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_UW]); - pr("%5d", vec[I_FOOD]); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%5d", vec[I_PETROL]); - pr("%5d", vec[I_IRON]); - pr("%5d", vec[I_DUST]); - pr("%5d", vec[I_OIL]); - pr("%5d", vec[I_LCM]); - pr("%5d", vec[I_HCM]); - pr("%4d", vec[I_RAD]); - pr("\n"); + lcp = &lchr[(int)land->lnd_type]; + pr("UID : %d\n", (int)land->lnd_uid); + pr("Owner : %d\n", (int)land->lnd_own); + pr("Location : %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum)); + pr("Efficiency : %d\t", (int)land->lnd_effic); + pr("Mobility : %d\n", (int)land->lnd_mobil); + pr("Tech : %d\t\t", land->lnd_tech); + pr("Army : %c\n", land->lnd_army); + pr("Attack: %f\t", lcp->l_att); + pr("Defense: %f\n", lcp->l_def); + pr("Fortification : %d\t", land->lnd_harden); + pr("Fuel : %d\n", land->lnd_fuel); + count_land_planes(land); + pr("Xlight planes : %d\n", land->lnd_nxlight); + pr("Land unit : %d\n", land->lnd_land); + pr("Ship : %d\t\t", land->lnd_ship); + pr("Radius

: %d\n", land->lnd_rad_max); + pr("Retreat percentage : %d\n", (int)land->lnd_retreat); + pr("Retreat path : '%s'\t\tRetreat Flags : %d\n", + land->lnd_rpath, (int)land->lnd_rflags); + getvec(VT_ITEM, vec, (s_char *)land, EF_LAND); + pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n"); + pr(" c m u f s g p i d o l h r\n"); + pr("%3d", vec[I_CIVIL]); + pr("%4d", vec[I_MILIT]); + pr("%4d", vec[I_UW]); + pr("%5d", vec[I_FOOD]); + pr("%4d", vec[I_SHELL]); + pr("%4d", vec[I_GUN]); + pr("%5d", vec[I_PETROL]); + pr("%5d", vec[I_IRON]); + pr("%5d", vec[I_DUST]); + pr("%5d", vec[I_OIL]); + pr("%5d", vec[I_LCM]); + pr("%5d", vec[I_HCM]); + pr("%4d", vec[I_RAD]); + pr("\n"); } static void pr_ship(struct shpstr *ship) { - int vec[I_MAX+1]; - struct natstr *natp; + int vec[I_MAX + 1]; + struct natstr *natp; - if ((natp = getnatp(ship->shp_own)) == 0) - return; - pr("%s (#%d) %s\n", natp->nat_cnam, (int)ship->shp_own, - prship(ship)); - pr("UID : %d\n", (int)ship->shp_uid); - pr("Owner : %d\t\t\t", (int)ship->shp_own); - pr("Location : %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum)); - pr("Tech : %d\t\t\t", ship->shp_tech); - pr("Efficiency : %d\n", (int)ship->shp_effic); - pr("Mobility : %d\t\t\t", (int)ship->shp_mobil); - pr("Fleet : %c\n", ship->shp_fleet); - count_planes(ship); - pr("Helos : %d\n", (int)ship->shp_nchoppers); - pr("Xlight planes : %d\n", (int)ship->shp_nxlight); - pr("Planes

: %d\n", (int)ship->shp_nplane); - count_units(ship); - pr("Units : %d\n", (int)ship->shp_nland); - /* could depend on opt_FUEL - but a deity might want to set this - up before enabling the option */ - pr("Fuel : %d\n", (int)ship->shp_fuel); - pr("Retreat path : '%s'\t\tRetreat Flags : %d\n",ship->shp_rpath,(int)ship->shp_rflags); - getvec(VT_ITEM, vec, (s_char *)ship, EF_SHIP); - pr("Plague Stage : %d\n", getvar(V_PSTAGE, (s_char *)ship, EF_SHIP)); - pr("Plague Time : %d\n", getvar(V_PTIME, (s_char *)ship, EF_SHIP)); - pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n"); - pr(" c m u f s g p i d o l h r\n"); - pr("%3d", vec[I_CIVIL]); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_UW]); - pr("%5d", vec[I_FOOD]); - pr("%4d", vec[I_SHELL]); - pr("%4d", vec[I_GUN]); - pr("%5d", vec[I_PETROL]); - pr("%5d", vec[I_IRON]); - pr("%5d", vec[I_DUST]); - pr("%5d", vec[I_OIL]); - pr("%5d", vec[I_LCM]); - pr("%5d", vec[I_HCM]); - pr("%4d", vec[I_RAD]); - pr("\n"); + if ((natp = getnatp(ship->shp_own)) == 0) + return; + pr("%s (#%d) %s\n", natp->nat_cnam, (int)ship->shp_own, prship(ship)); + pr("UID : %d\n", (int)ship->shp_uid); + pr("Owner : %d\t\t\t", (int)ship->shp_own); + pr("Location : %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum)); + pr("Tech : %d\t\t\t", ship->shp_tech); + pr("Efficiency : %d\n", (int)ship->shp_effic); + pr("Mobility : %d\t\t\t", (int)ship->shp_mobil); + pr("Fleet : %c\n", ship->shp_fleet); + count_planes(ship); + pr("Helos : %d\n", (int)ship->shp_nchoppers); + pr("Xlight planes : %d\n", (int)ship->shp_nxlight); + pr("Planes

: %d\n", (int)ship->shp_nplane); + count_units(ship); + pr("Units : %d\n", (int)ship->shp_nland); + /* could depend on opt_FUEL - but a deity might want to set this + up before enabling the option */ + pr("Fuel : %d\n", (int)ship->shp_fuel); + pr("Retreat path : '%s'\t\tRetreat Flags : %d\n", + ship->shp_rpath, (int)ship->shp_rflags); + getvec(VT_ITEM, vec, (s_char *)ship, EF_SHIP); + pr("Plague Stage : %d\n", + getvar(V_PSTAGE, (s_char *)ship, EF_SHIP)); + pr("Plague Time : %d\n", getvar(V_PTIME, (s_char *)ship, EF_SHIP)); + pr("civ mil uw food shl gun pet irn dst oil lcm hcm rad\n"); + pr(" c m u f s g p i d o l h r\n"); + pr("%3d", vec[I_CIVIL]); + pr("%4d", vec[I_MILIT]); + pr("%4d", vec[I_UW]); + pr("%5d", vec[I_FOOD]); + pr("%4d", vec[I_SHELL]); + pr("%4d", vec[I_GUN]); + pr("%5d", vec[I_PETROL]); + pr("%5d", vec[I_IRON]); + pr("%5d", vec[I_DUST]); + pr("%5d", vec[I_OIL]); + pr("%5d", vec[I_LCM]); + pr("%5d", vec[I_HCM]); + pr("%4d", vec[I_RAD]); + pr("\n"); } int errcheck(int num, int min, int max) { - if (num < min) - return(min); - else if (num > max) - return(max); - return (num); + if (num < min) + return (min); + else if (num > max) + return (max); + return (num); } int getin(s_char **what, s_char **p, int *arg, s_char *buf) { - if (!(*what = getstarg(*p, "%c xxxxx -- thing value : ", buf))) { - return RET_SYN; - } - if (**what == '\0') - return END; - while (**what && isspace (**what)) - (*what) ++; - if (**what == '\0') - return RET_SYN; - for (*p = *what; **p && !isspace (**p); (*p) ++) /* skip non spaces */ - continue; - while (**p && isspace (**p)) - (*p) ++; - if (**p == '\0') - return RET_SYN; - *arg = atoi(*p); - return RET_OK; + if (!(*what = getstarg(*p, "%c xxxxx -- thing value : ", buf))) { + return RET_SYN; + } + if (**what == '\0') + return END; + while (**what && isspace(**what)) + (*what)++; + if (**what == '\0') + return RET_SYN; + for (*p = *what; **p && !isspace(**p); (*p)++) /* skip non spaces */ + continue; + while (**p && isspace(**p)) + (*p)++; + if (**p == '\0') + return RET_SYN; + *arg = atoi(*p); + return RET_OK; } int doland(s_char op, int arg, struct sctstr *sect) { - natid newown, oldown; - int new, old; - switch (op) { - case 'C': - if (arg < 0) - return RET_SYN; - sect->sct_coastal = (arg ? 1 : 0); - pr("Coastal flag of %s changed to %d\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), - sect->sct_coastal); - break; - case 'o': - if (arg < 0) - return RET_SYN; - newown = (natid) errcheck(arg, 0, MAXNOC-1); - pr("Owner of %s changed from %s (#%d) to %s (#%d).\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), - cname(sect->sct_own), - sect->sct_own, cname(newown), newown); - if (sect->sct_own) { - makelost(EF_SECTOR, sect->sct_own, 0, sect->sct_x, sect->sct_y); - wu(player->cnum, sect->sct_own, - "Sector %s lost to deity intervention\n", - xyas(sect->sct_x, sect->sct_y, sect->sct_own)); - } - benefit(sect->sct_own, 0); - sect->sct_own = newown; - if (newown) { - makenotlost(EF_SECTOR, newown, 0, sect->sct_x, sect->sct_y); - wu(player->cnum, newown, - "Sector %s gained from deity intervention\n", - xyas(sect->sct_x, sect->sct_y, sect->sct_own)); - } - benefit(newown, 1); - break; - case 'O': - if (arg < 0) - return RET_SYN; - oldown = (natid) errcheck(arg, 0, MAXNOC-1); - pr("Old player->owner of %s changed from %s (#%d) to %s (#%d).\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), - cname(sect->sct_oldown), - sect->sct_oldown, cname(oldown), oldown); - sect->sct_oldown = oldown; - break; - case 'e': - new = errcheck(arg, 0, 100); - noise(sect, 1, "Efficiency", (int) sect->sct_effic, new); - sect->sct_effic = (u_char) new; - break; - case 'm': - new = errcheck(arg, -127, 255); - noise(sect, 1, "Mobility", (int) sect->sct_mobil, new); - sect->sct_mobil = new; - break; - case 'i': - new = errcheck(arg, 0, 127); - noise(sect, 1, "Iron ore content", (int) sect->sct_min, new); - sect->sct_min = (u_char) new; - break; - case 'g': - new = errcheck(arg, 0, 127); - noise(sect, 1, "Gold content", (int) sect->sct_gmin, new); - sect->sct_gmin = (u_char) new; - break; - case 'f': - new = errcheck(arg, 0, 127); - noise(sect, 1, "Fertility", (int) sect->sct_fertil, new); - sect->sct_fertil = (u_char) new; - break; - case 'c': - new = errcheck(arg, 0, 127); - noise(sect, 1, "Oil content", (int) sect->sct_oil, new); - sect->sct_oil = (u_char) new; - break; - case 'u': - new = errcheck(arg, 0, 127); - noise(sect, 1, "Uranium content", (int) sect->sct_uran, new); - sect->sct_uran = (u_char) new; - break; - case 'w': - new = errcheck(arg, 0, 100); - noise(sect, 1, "Workforce percentage", - (int) sect->sct_work, new); - sect->sct_work = (u_char) new; - break; - case 'l': - new = errcheck(arg, 0, 127); - pr("Loyalty of %s changed from %d to %d%%\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), - sect->sct_loyal, new); - sect->sct_loyal = (u_char) new; - break; - case 'x': - old = getvar(V_CHE, (s_char *)sect, EF_SECTOR); - new = errcheck(arg, 0, 65536); - pr("Guerillas in %s changed from %d to %d%\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); - putvar(V_CHE, new, (s_char *)sect, EF_SECTOR); - break; - case 'p': - old = getvar(V_PSTAGE, (s_char *)sect, EF_SECTOR); - new = errcheck(arg, 0, PLG_EXPOSED); - pr("Plague stage of %s changed from %d to %d%\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); - putvar(V_PSTAGE, new, (s_char *)sect, EF_SECTOR); - break; - case 't': - old = getvar(V_PTIME, (s_char *)sect, EF_SECTOR); - new = errcheck(arg, 0, 255); - pr("Plague time of %s changed from %d to %d%\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); - putvar(V_PTIME, new, (s_char *)sect, EF_SECTOR); - break; - case 'F': - old = getvar(V_FALLOUT, (s_char *)sect, EF_SECTOR); - new = errcheck(arg, 0, 9999); - pr("Fallout for sector %s changed from %d to %d\n", - xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); - putvar(V_FALLOUT, new, (s_char *)sect, EF_SECTOR); - break; - case 'a': - new = errcheck(arg, 0, 9999); - noise(sect, 1, "Available workforce", (int) sect->sct_avail, - new); - sect->sct_avail = new; - break; - case 'M': - putvar(V_MINE, arg, (s_char *)sect, EF_SECTOR); - pr("Mines changed to %d\n",arg); - break; - case 'X': - sect->sct_x = arg; - break; - case 'Y': - sect->sct_y = arg; - break; - case 'R': - if (arg > 100) - arg = 100; - if (arg < 0) - arg = 0; - noise(sect, 1, "Road percentage", (int) sect->sct_road, - arg); - sect->sct_road = arg; - break; - case 'r': - if (arg > 100) - arg = 100; - if (arg < 0) - arg = 0; - noise(sect, 1, "Rail percentage", (int) sect->sct_rail, - arg); - sect->sct_rail = arg; - break; - case 'd': - if (arg > 100) - arg = 100; - if (arg < 0) - arg = 0; - noise(sect, 1, "Defense percentage", (int) sect->sct_defense, - arg); - sect->sct_defense = arg; - break; - default: - pr("huh? (%c)\n",op); - return RET_SYN; + natid newown, oldown; + int new, old; + switch (op) { + case 'C': + if (arg < 0) + return RET_SYN; + sect->sct_coastal = (arg ? 1 : 0); + pr("Coastal flag of %s changed to %d\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), + sect->sct_coastal); + break; + case 'o': + if (arg < 0) + return RET_SYN; + newown = (natid)errcheck(arg, 0, MAXNOC - 1); + pr("Owner of %s changed from %s (#%d) to %s (#%d).\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), + cname(sect->sct_own), sect->sct_own, cname(newown), newown); + if (sect->sct_own) { + makelost(EF_SECTOR, sect->sct_own, 0, sect->sct_x, + sect->sct_y); + wu(player->cnum, sect->sct_own, + "Sector %s lost to deity intervention\n", xyas(sect->sct_x, + sect->sct_y, + sect-> + sct_own)); } - return RET_OK; + benefit(sect->sct_own, 0); + sect->sct_own = newown; + if (newown) { + makenotlost(EF_SECTOR, newown, 0, sect->sct_x, sect->sct_y); + wu(player->cnum, newown, + "Sector %s gained from deity intervention\n", + xyas(sect->sct_x, sect->sct_y, sect->sct_own)); + } + benefit(newown, 1); + break; + case 'O': + if (arg < 0) + return RET_SYN; + oldown = (natid)errcheck(arg, 0, MAXNOC - 1); + pr("Old player->owner of %s changed from %s (#%d) to %s (#%d).\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), + cname(sect->sct_oldown), + sect->sct_oldown, cname(oldown), oldown); + sect->sct_oldown = oldown; + break; + case 'e': + new = errcheck(arg, 0, 100); + noise(sect, 1, "Efficiency", (int)sect->sct_effic, new); + sect->sct_effic = (u_char)new; + break; + case 'm': + new = errcheck(arg, -127, 255); + noise(sect, 1, "Mobility", (int)sect->sct_mobil, new); + sect->sct_mobil = new; + break; + case 'i': + new = errcheck(arg, 0, 127); + noise(sect, 1, "Iron ore content", (int)sect->sct_min, new); + sect->sct_min = (u_char)new; + break; + case 'g': + new = errcheck(arg, 0, 127); + noise(sect, 1, "Gold content", (int)sect->sct_gmin, new); + sect->sct_gmin = (u_char)new; + break; + case 'f': + new = errcheck(arg, 0, 127); + noise(sect, 1, "Fertility", (int)sect->sct_fertil, new); + sect->sct_fertil = (u_char)new; + break; + case 'c': + new = errcheck(arg, 0, 127); + noise(sect, 1, "Oil content", (int)sect->sct_oil, new); + sect->sct_oil = (u_char)new; + break; + case 'u': + new = errcheck(arg, 0, 127); + noise(sect, 1, "Uranium content", (int)sect->sct_uran, new); + sect->sct_uran = (u_char)new; + break; + case 'w': + new = errcheck(arg, 0, 100); + noise(sect, 1, "Workforce percentage", (int)sect->sct_work, new); + sect->sct_work = (u_char)new; + break; + case 'l': + new = errcheck(arg, 0, 127); + pr("Loyalty of %s changed from %d to %d%%\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), + sect->sct_loyal, new); + sect->sct_loyal = (u_char)new; + break; + case 'x': + old = getvar(V_CHE, (s_char *)sect, EF_SECTOR); + new = errcheck(arg, 0, 65536); + pr("Guerillas in %s changed from %d to %d%\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); + putvar(V_CHE, new, (s_char *)sect, EF_SECTOR); + break; + case 'p': + old = getvar(V_PSTAGE, (s_char *)sect, EF_SECTOR); + new = errcheck(arg, 0, PLG_EXPOSED); + pr("Plague stage of %s changed from %d to %d%\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); + putvar(V_PSTAGE, new, (s_char *)sect, EF_SECTOR); + break; + case 't': + old = getvar(V_PTIME, (s_char *)sect, EF_SECTOR); + new = errcheck(arg, 0, 255); + pr("Plague time of %s changed from %d to %d%\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); + putvar(V_PTIME, new, (s_char *)sect, EF_SECTOR); + break; + case 'F': + old = getvar(V_FALLOUT, (s_char *)sect, EF_SECTOR); + new = errcheck(arg, 0, 9999); + pr("Fallout for sector %s changed from %d to %d\n", + xyas(sect->sct_x, sect->sct_y, player->cnum), old, new); + putvar(V_FALLOUT, new, (s_char *)sect, EF_SECTOR); + break; + case 'a': + new = errcheck(arg, 0, 9999); + noise(sect, 1, "Available workforce", (int)sect->sct_avail, new); + sect->sct_avail = new; + break; + case 'M': + putvar(V_MINE, arg, (s_char *)sect, EF_SECTOR); + pr("Mines changed to %d\n", arg); + break; + case 'X': + sect->sct_x = arg; + break; + case 'Y': + sect->sct_y = arg; + break; + case 'R': + if (arg > 100) + arg = 100; + if (arg < 0) + arg = 0; + noise(sect, 1, "Road percentage", (int)sect->sct_road, arg); + sect->sct_road = arg; + break; + case 'r': + if (arg > 100) + arg = 100; + if (arg < 0) + arg = 0; + noise(sect, 1, "Rail percentage", (int)sect->sct_rail, arg); + sect->sct_rail = arg; + break; + case 'd': + if (arg > 100) + arg = 100; + if (arg < 0) + arg = 0; + noise(sect, 1, "Defense percentage", (int)sect->sct_defense, arg); + sect->sct_defense = arg; + break; + default: + pr("huh? (%c)\n", op); + return RET_SYN; + } + return RET_OK; } int -docountry(s_char op, int arg, s_char *p, float farg, natid nat, struct natstr *np) +docountry(s_char op, int arg, s_char *p, float farg, natid nat, + struct natstr *np) { - extern int m_m_p_d; - coord newx, newy; - switch (op) { - case 'n': - pr("Country name changed from %s to %s\n", np->nat_cnam, p); - strncpy(np->nat_cnam, p, sizeof(np->nat_cnam)-1); - break; - case 'r': - pr("Country representative changed from %s to %s\n", - np->nat_pnam, p); - strncpy(np->nat_pnam, p, sizeof(np->nat_pnam)-1); - break; - case 't': - np->nat_tgms = arg; - break; - case 'b': - arg = errcheck(arg, 0, 1024); - pr("BTU's changed from %d to %d\n", np->nat_btu, arg); - np->nat_btu = arg; - break; - case 'm': - benefit(nat, np->nat_reserve < arg); - pr("Military Reserves changed from %d to %d\n", - np->nat_reserve, arg); - if (np->nat_stat == STAT_NORM) - wu(player->cnum, nat, - "Military Reserves changed from %d to %d by divine intervention.\n", - np->nat_reserve, arg); - np->nat_reserve = arg; - break; - case 'c': - if (!sarg_xy(p, &newx, &newy)) - return RET_SYN; - pr("Capital coordinates changed from %s to %s\n", - xyas(np->nat_xcap, np->nat_ycap, player->cnum), - xyas(newx, newy, player->cnum)); - np->nat_xcap = newx; - np->nat_ycap = newy; - break; - case 'o': - if (!sarg_xy(p, &newx, &newy)) - return RET_SYN; - pr("Origin coordinates changed from %s to %s\n", - xyas(np->nat_xorg, np->nat_yorg, player->cnum), - xyas(newx, newy, player->cnum)); - np->nat_xorg = newx; - np->nat_yorg = newy; - break; - case 's': - np->nat_stat = (s_char)errcheck(arg, 0, STAT_NEW); - break; - case 'u': - arg = errcheck(arg, 0, m_m_p_d); - pr("Number of minutes used changed from %d to %d.\n", - np->nat_minused, arg); - np->nat_minused = arg; - break; - case 'M': - pr("Money changed from %d to %d\n",np->nat_money, arg); - wu(player->cnum, nat, - "Money changed from %d to %d by divine intervention.\n", - np->nat_money, arg); - np->nat_money = arg; - break; - case 'T': - pr("Tech changed from %.2f to %.2f.\n", - np->nat_level[NAT_TLEV], farg); - np->nat_level[NAT_TLEV] = farg; - break; - case 'R': - pr("Research changed from %.2f to %.2f.\n", - np->nat_level[NAT_RLEV], farg); - np->nat_level[NAT_RLEV] = farg; - break; - case 'E': - pr("Education changed from %.2f to %.2f.\n", - np->nat_level[NAT_ELEV], farg); - np->nat_level[NAT_ELEV] = farg; - break; - case 'H': - pr("Happiness changed from %.2f to %.2f.\n", - np->nat_level[NAT_HLEV], farg); - np->nat_level[NAT_HLEV] = farg; - break; - case 'U': - np->nat_missed = arg; - break; - default: - pr("huh? (%c)\n",op); - break; - } - putnat(np); - return RET_OK; + extern int m_m_p_d; + coord newx, newy; + switch (op) { + case 'n': + pr("Country name changed from %s to %s\n", np->nat_cnam, p); + strncpy(np->nat_cnam, p, sizeof(np->nat_cnam) - 1); + break; + case 'r': + pr("Country representative changed from %s to %s\n", + np->nat_pnam, p); + strncpy(np->nat_pnam, p, sizeof(np->nat_pnam) - 1); + break; + case 't': + np->nat_tgms = arg; + break; + case 'b': + arg = errcheck(arg, 0, 1024); + pr("BTU's changed from %d to %d\n", np->nat_btu, arg); + np->nat_btu = arg; + break; + case 'm': + benefit(nat, np->nat_reserve < arg); + pr("Military Reserves changed from %d to %d\n", + np->nat_reserve, arg); + if (np->nat_stat == STAT_NORM) + wu(player->cnum, nat, + "Military Reserves changed from %d to %d by divine intervention.\n", + np->nat_reserve, arg); + np->nat_reserve = arg; + break; + case 'c': + if (!sarg_xy(p, &newx, &newy)) + return RET_SYN; + pr("Capital coordinates changed from %s to %s\n", + xyas(np->nat_xcap, np->nat_ycap, player->cnum), + xyas(newx, newy, player->cnum)); + np->nat_xcap = newx; + np->nat_ycap = newy; + break; + case 'o': + if (!sarg_xy(p, &newx, &newy)) + return RET_SYN; + pr("Origin coordinates changed from %s to %s\n", + xyas(np->nat_xorg, np->nat_yorg, player->cnum), + xyas(newx, newy, player->cnum)); + np->nat_xorg = newx; + np->nat_yorg = newy; + break; + case 's': + np->nat_stat = (s_char)errcheck(arg, 0, STAT_NEW); + break; + case 'u': + arg = errcheck(arg, 0, m_m_p_d); + pr("Number of minutes used changed from %d to %d.\n", + np->nat_minused, arg); + np->nat_minused = arg; + break; + case 'M': + pr("Money changed from %d to %d\n", np->nat_money, arg); + wu(player->cnum, nat, + "Money changed from %d to %d by divine intervention.\n", + np->nat_money, arg); + np->nat_money = arg; + break; + case 'T': + pr("Tech changed from %.2f to %.2f.\n", + np->nat_level[NAT_TLEV], farg); + np->nat_level[NAT_TLEV] = farg; + break; + case 'R': + pr("Research changed from %.2f to %.2f.\n", + np->nat_level[NAT_RLEV], farg); + np->nat_level[NAT_RLEV] = farg; + break; + case 'E': + pr("Education changed from %.2f to %.2f.\n", + np->nat_level[NAT_ELEV], farg); + np->nat_level[NAT_ELEV] = farg; + break; + case 'H': + pr("Happiness changed from %.2f to %.2f.\n", + np->nat_level[NAT_HLEV], farg); + np->nat_level[NAT_HLEV] = farg; + break; + case 'U': + np->nat_missed = arg; + break; + default: + pr("huh? (%c)\n", op); + break; + } + putnat(np); + return RET_OK; } int doship(s_char op, int arg, s_char *p, struct shpstr *ship) { - coord newx, newy; + coord newx, newy; - newx = newy = 0; - switch (op) { - case 'a': - putvar(V_PSTAGE, arg, (s_char *)ship, EF_SHIP); - break; - case 'b': - putvar(V_PTIME, arg, (s_char *)ship, EF_SHIP); - break; - case 'R': - bcopy(p,ship->shp_rpath,10); - break; - case 'W': - ship->shp_rflags = arg; - break; - case 'H': - ship->shp_nchoppers = arg; - break; - case 'X': - ship->shp_nxlight = arg; - break; - case 'U': - ship->shp_uid = arg; - break; - case 'O': - if (ship->shp_own) - wu(player->cnum, ship->shp_own, - "%s taken from you by deity intervention!\n", - prship(ship)); - if (arg && arg < MAXNOC) { - wu(player->cnum, (natid)arg, - "%s given to you by deity intervention!\n", - prship(ship)); - makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, ship->shp_y); - ship->shp_own = (natid) arg; - makenotlost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, ship->shp_y); - } else if (!arg) { - ship->shp_effic = 0; - makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, ship->shp_y); - ship->shp_own = (natid) 0; - } - break; - case 'L': - if (!sarg_xy(p, &newx, &newy)) - return RET_SYN; - ship->shp_x = newx; - ship->shp_y = newy; - break; - case 'T': - ship->shp_tech = arg; - break; - case 'E': - ship->shp_effic = errcheck(arg, 0, 100); - if (arg < 10) { - ship->shp_effic = 0; - makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, ship->shp_y); - ship->shp_own = (natid) 0; - } - break; - case 'M': - ship->shp_mobil = arg; - break; - case 'B': - ship->shp_fuel = errcheck(arg, 0, 255); - break; - case 'F': - if (p[0] == '~') - ship->shp_fleet = ' '; - else if (isalpha(p[0])) - ship->shp_fleet = p[0]; - else { - pr("%c: invalid fleet\n",p[0]); - return RET_FAIL; - } - break; - case 'Y': - ship->shp_nland = errcheck(arg, 0, 100); - break; - case 'P': - ship->shp_nplane = errcheck(arg, 0, 100); - break; - case 'c': - if (!putvar(V_CIVIL, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'm': - if (!putvar(V_MILIT, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'u': - if (!putvar(V_UW, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'f': - if (!putvar(V_FOOD, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 's': - if (!putvar(V_SHELL, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'g': - if (!putvar(V_GUN, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'p': - if (!putvar(V_PETROL, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'i': - if (!putvar(V_IRON, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'd': - if (!putvar(V_DUST, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'o': - if (!putvar(V_OIL, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'l': - if (!putvar(V_LCM, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'h': - if (!putvar(V_HCM, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - case 'r': - if (!putvar(V_RAD, arg, (s_char *)ship, EF_SHIP)) { - pr("No room on ship!\n"); - return RET_FAIL; - } - break; - default: - pr("huh? (%c)\n",op); - return RET_FAIL; + newx = newy = 0; + switch (op) { + case 'a': + putvar(V_PSTAGE, arg, (s_char *)ship, EF_SHIP); + break; + case 'b': + putvar(V_PTIME, arg, (s_char *)ship, EF_SHIP); + break; + case 'R': + bcopy(p, ship->shp_rpath, 10); + break; + case 'W': + ship->shp_rflags = arg; + break; + case 'H': + ship->shp_nchoppers = arg; + break; + case 'X': + ship->shp_nxlight = arg; + break; + case 'U': + ship->shp_uid = arg; + break; + case 'O': + if (ship->shp_own) + wu(player->cnum, ship->shp_own, + "%s taken from you by deity intervention!\n", prship(ship)); + if (arg && arg < MAXNOC) { + wu(player->cnum, (natid)arg, + "%s given to you by deity intervention!\n", prship(ship)); + makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, + ship->shp_y); + ship->shp_own = (natid)arg; + makenotlost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, + ship->shp_y); + } else if (!arg) { + ship->shp_effic = 0; + makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, + ship->shp_y); + ship->shp_own = (natid)0; + } + break; + case 'L': + if (!sarg_xy(p, &newx, &newy)) + return RET_SYN; + ship->shp_x = newx; + ship->shp_y = newy; + break; + case 'T': + ship->shp_tech = arg; + break; + case 'E': + ship->shp_effic = errcheck(arg, 0, 100); + if (arg < 10) { + ship->shp_effic = 0; + makelost(EF_SHIP, ship->shp_own, ship->shp_uid, ship->shp_x, + ship->shp_y); + ship->shp_own = (natid)0; + } + break; + case 'M': + ship->shp_mobil = arg; + break; + case 'B': + ship->shp_fuel = errcheck(arg, 0, 255); + break; + case 'F': + if (p[0] == '~') + ship->shp_fleet = ' '; + else if (isalpha(p[0])) + ship->shp_fleet = p[0]; + else { + pr("%c: invalid fleet\n", p[0]); + return RET_FAIL; + } + break; + case 'Y': + ship->shp_nland = errcheck(arg, 0, 100); + break; + case 'P': + ship->shp_nplane = errcheck(arg, 0, 100); + break; + case 'c': + if (!putvar(V_CIVIL, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'm': + if (!putvar(V_MILIT, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'u': + if (!putvar(V_UW, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'f': + if (!putvar(V_FOOD, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 's': + if (!putvar(V_SHELL, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'g': + if (!putvar(V_GUN, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'p': + if (!putvar(V_PETROL, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'i': + if (!putvar(V_IRON, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'd': + if (!putvar(V_DUST, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'o': + if (!putvar(V_OIL, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; } - return RET_OK; + break; + case 'l': + if (!putvar(V_LCM, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'h': + if (!putvar(V_HCM, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + case 'r': + if (!putvar(V_RAD, arg, (s_char *)ship, EF_SHIP)) { + pr("No room on ship!\n"); + return RET_FAIL; + } + break; + default: + pr("huh? (%c)\n", op); + return RET_FAIL; + } + return RET_OK; } int dounit(s_char op, int arg, s_char *p, struct lndstr *land) { - coord newx, newy; + coord newx, newy; - newx = newy = 0; - switch (op) { - case 'Y': - land->lnd_land = arg; - break; - case 'U': - land->lnd_uid = arg; - break; - case 'O': - if (land->lnd_own) - wu(player->cnum, land->lnd_own, - "%s taken from you by deity intervention!\n", - prland(land)); + newx = newy = 0; + switch (op) { + case 'Y': + land->lnd_land = arg; + break; + case 'U': + land->lnd_uid = arg; + break; + case 'O': + if (land->lnd_own) + wu(player->cnum, land->lnd_own, + "%s taken from you by deity intervention!\n", prland(land)); - if (arg && arg < MAXNOC) { - wu(player->cnum, (natid)arg, - "%s given to you by deity intervention!\n", - prland(land)); - makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, land->lnd_y); - land->lnd_own = (natid) arg; - makenotlost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, land->lnd_y); - } else if (!arg) { - makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, land->lnd_y); - land->lnd_effic = 0; - land->lnd_own = (natid) 0; - } - break; - case 'L': - if (!sarg_xy(p, &newx, &newy)) - return RET_SYN; - land->lnd_x = newx; - land->lnd_y = newy; - break; - case 'e': - land->lnd_effic = errcheck(arg, 0, 100); - if (arg < 10) { - makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, land->lnd_y); - land->lnd_effic = 0; - land->lnd_own = (natid) 0; - } - break; - case 'M': - land->lnd_mobil = arg; - break; - case 't': - land->lnd_tech = arg; - break; - case 'a': - if (p[0] == '~') - land->lnd_army = ' '; - else if (isalpha(p[0])) - land->lnd_army = p[0]; - else { - pr("%c: invalid army\n",p[0]); - return RET_FAIL; - } - break; - case 'F': - land->lnd_harden = errcheck(arg, 0, 255); - break; - case 'B': - land->lnd_fuel = errcheck(arg, 0, 255); - break; - case 'X': - land->lnd_nxlight = arg; - break; - case 'S': - land->lnd_ship = arg; - break; - case 'P': - land->lnd_rad_max = arg; - break; - case 'Z': - land->lnd_retreat = arg; - break; - case 'R': - bcopy(p,land->lnd_rpath,10); - break; - case 'W': - land->lnd_rflags = arg; - break; - case 'c': - if (!putvar(V_CIVIL, arg, (s_char *)land, EF_LAND)) { - pr("No room on land unit!\n"); - return RET_FAIL; - } - break; - case 'm': - if (!putvar(V_MILIT, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'u': - if (!putvar(V_UW, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'f': - if (!putvar(V_FOOD, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 's': - if (!putvar(V_SHELL, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'g': - if (!putvar(V_GUN, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'p': - if (!putvar(V_PETROL, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'i': - if (!putvar(V_IRON, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'd': - if (!putvar(V_DUST, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'o': - if (!putvar(V_OIL, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'l': - if (!putvar(V_LCM, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'h': - if (!putvar(V_HCM, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - case 'r': - if (!putvar(V_RAD, arg, (s_char *)land, EF_LAND)) { - pr("No room on land!\n"); - return RET_FAIL; - } - break; - default: - pr("huh? (%c)\n",op); - return RET_FAIL; + if (arg && arg < MAXNOC) { + wu(player->cnum, (natid)arg, + "%s given to you by deity intervention!\n", prland(land)); + makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, + land->lnd_y); + land->lnd_own = (natid)arg; + makenotlost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, + land->lnd_y); + } else if (!arg) { + makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, + land->lnd_y); + land->lnd_effic = 0; + land->lnd_own = (natid)0; + } + break; + case 'L': + if (!sarg_xy(p, &newx, &newy)) + return RET_SYN; + land->lnd_x = newx; + land->lnd_y = newy; + break; + case 'e': + land->lnd_effic = errcheck(arg, 0, 100); + if (arg < 10) { + makelost(EF_LAND, land->lnd_own, land->lnd_uid, land->lnd_x, + land->lnd_y); + land->lnd_effic = 0; + land->lnd_own = (natid)0; + } + break; + case 'M': + land->lnd_mobil = arg; + break; + case 't': + land->lnd_tech = arg; + break; + case 'a': + if (p[0] == '~') + land->lnd_army = ' '; + else if (isalpha(p[0])) + land->lnd_army = p[0]; + else { + pr("%c: invalid army\n", p[0]); + return RET_FAIL; + } + break; + case 'F': + land->lnd_harden = errcheck(arg, 0, 255); + break; + case 'B': + land->lnd_fuel = errcheck(arg, 0, 255); + break; + case 'X': + land->lnd_nxlight = arg; + break; + case 'S': + land->lnd_ship = arg; + break; + case 'P': + land->lnd_rad_max = arg; + break; + case 'Z': + land->lnd_retreat = arg; + break; + case 'R': + bcopy(p, land->lnd_rpath, 10); + break; + case 'W': + land->lnd_rflags = arg; + break; + case 'c': + if (!putvar(V_CIVIL, arg, (s_char *)land, EF_LAND)) { + pr("No room on land unit!\n"); + return RET_FAIL; + } + break; + case 'm': + if (!putvar(V_MILIT, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'u': + if (!putvar(V_UW, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'f': + if (!putvar(V_FOOD, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 's': + if (!putvar(V_SHELL, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'g': + if (!putvar(V_GUN, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'p': + if (!putvar(V_PETROL, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; } - return RET_OK; + break; + case 'i': + if (!putvar(V_IRON, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'd': + if (!putvar(V_DUST, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'o': + if (!putvar(V_OIL, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'l': + if (!putvar(V_LCM, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'h': + if (!putvar(V_HCM, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + case 'r': + if (!putvar(V_RAD, arg, (s_char *)land, EF_LAND)) { + pr("No room on land!\n"); + return RET_FAIL; + } + break; + default: + pr("huh? (%c)\n", op); + return RET_FAIL; + } + return RET_OK; } int doplane(s_char op, int arg, s_char *p, struct plnstr *plane) { - coord newx, newy; + coord newx, newy; - switch (op) { - case 'n': - plane->pln_nuketype = arg; - break; - case 'U': - plane->pln_uid = arg; - break; - case 'l': - if (!sarg_xy(p, &newx, &newy)) - return RET_SYN; - plane->pln_x = newx; - plane->pln_y = newy; - break; - case 'O': - if (plane->pln_own) - wu(player->cnum, plane->pln_own, - "%s taken from you by deity intervention!\n", - prplane(plane)); - if (arg && arg < MAXNOC) { - makelost(EF_PLANE, plane->pln_own, plane->pln_uid, plane->pln_x, plane->pln_y); - plane->pln_own = (natid) arg; - makenotlost(EF_PLANE, plane->pln_own, plane->pln_uid, plane->pln_x, plane->pln_y); - wu(player->cnum, plane->pln_own, - "%s given to you by deity intervention!\n", - prplane(plane)); - } else if (!arg) { - plane->pln_effic = 0; - makelost(EF_PLANE, plane->pln_own, plane->pln_uid, plane->pln_x, plane->pln_y); - plane->pln_own = (natid) 0; - } - break; - case 'e': - plane->pln_effic = errcheck(arg, 0, 100); - if (arg < 10) { - plane->pln_effic = 0; - makelost(EF_PLANE, plane->pln_own, plane->pln_uid, plane->pln_x, plane->pln_y); - plane->pln_own = (natid) 0; - } - break; - case 'm': - plane->pln_mobil = errcheck(arg, -127, 255); - break; - case 't': - plane->pln_tech = arg; - break; - case 'w': - if (p[0] == '~') - plane->pln_wing = ' '; - else if (isalpha(p[0])) - plane->pln_wing = p[0]; - else { - pr("%c: invalid wing\n",p[0]); - return RET_FAIL; - } - break; - case 'a': - plane->pln_att = (s_char) errcheck(arg, 0, 127); - break; - case 'd': - plane->pln_def = (s_char) arg; - break; - case 'r': - plane->pln_range = (u_char) arg; - break; - case 's': - plane->pln_ship = arg; - break; - case 'y': - plane->pln_land = arg; - break; - case 'f': - plane->pln_flags = arg; - break; - default: - pr("huh? (%c)\n",op); - return RET_FAIL; + switch (op) { + case 'n': + plane->pln_nuketype = arg; + break; + case 'U': + plane->pln_uid = arg; + break; + case 'l': + if (!sarg_xy(p, &newx, &newy)) + return RET_SYN; + plane->pln_x = newx; + plane->pln_y = newy; + break; + case 'O': + if (plane->pln_own) + wu(player->cnum, plane->pln_own, + "%s taken from you by deity intervention!\n", + prplane(plane)); + if (arg && arg < MAXNOC) { + makelost(EF_PLANE, plane->pln_own, plane->pln_uid, + plane->pln_x, plane->pln_y); + plane->pln_own = (natid)arg; + makenotlost(EF_PLANE, plane->pln_own, plane->pln_uid, + plane->pln_x, plane->pln_y); + wu(player->cnum, plane->pln_own, + "%s given to you by deity intervention!\n", prplane(plane)); + } else if (!arg) { + plane->pln_effic = 0; + makelost(EF_PLANE, plane->pln_own, plane->pln_uid, + plane->pln_x, plane->pln_y); + plane->pln_own = (natid)0; + } + break; + case 'e': + plane->pln_effic = errcheck(arg, 0, 100); + if (arg < 10) { + plane->pln_effic = 0; + makelost(EF_PLANE, plane->pln_own, plane->pln_uid, + plane->pln_x, plane->pln_y); + plane->pln_own = (natid)0; + } + break; + case 'm': + plane->pln_mobil = errcheck(arg, -127, 255); + break; + case 't': + plane->pln_tech = arg; + break; + case 'w': + if (p[0] == '~') + plane->pln_wing = ' '; + else if (isalpha(p[0])) + plane->pln_wing = p[0]; + else { + pr("%c: invalid wing\n", p[0]); + return RET_FAIL; } - return RET_OK; + break; + case 'a': + plane->pln_att = (s_char)errcheck(arg, 0, 127); + break; + case 'd': + plane->pln_def = (s_char)arg; + break; + case 'r': + plane->pln_range = (u_char)arg; + break; + case 's': + plane->pln_ship = arg; + break; + case 'y': + plane->pln_land = arg; + break; + case 'f': + plane->pln_flags = arg; + break; + default: + pr("huh? (%c)\n", op); + return RET_FAIL; + } + return RET_OK; } diff --git a/src/lib/commands/enab.c b/src/lib/commands/enab.c index f0cdb4495..45ce67fba 100644 --- a/src/lib/commands/enab.c +++ b/src/lib/commands/enab.c @@ -39,9 +39,9 @@ int enab(void) { - extern s_char *disablefil; + extern s_char *disablefil; - (void) unlink(disablefil); - pr("Updates are enabled\n"); - return RET_OK; + (void)unlink(disablefil); + pr("Updates are enabled\n"); + return RET_OK; } diff --git a/src/lib/commands/enli.c b/src/lib/commands/enli.c index 519169e28..dd7b6c737 100644 --- a/src/lib/commands/enli.c +++ b/src/lib/commands/enli.c @@ -45,103 +45,102 @@ int enli(void) { - struct nstr_sect nstr; - struct sctstr sect; - struct natstr *natp; - int civ; - int mil; - int newmil; - int milwant; - int totalmil; - long reserve; - s_char *p; - int quota; - s_char prompt[128]; - s_char buf[1024]; + struct nstr_sect nstr; + struct sctstr sect; + struct natstr *natp; + int civ; + int mil; + int newmil; + int milwant; + int totalmil; + long reserve; + s_char *p; + int quota; + s_char prompt[128]; + s_char buf[1024]; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - if (!trechk(player->cnum, 0, TRTENL)) - return RET_FAIL; - natp = getnatp(player->cnum); - newmil = 500; - sprintf(prompt, "Number to enlist (max %d) : ", newmil); - if ((p = getstarg(player->argp[2], prompt, buf)) == 0) - return RET_SYN; - if ((milwant = atoi(p)) > newmil) - milwant = newmil; - if (0 != (quota = (milwant < 0))) - milwant = -milwant; - totalmil = 0; - reserve = natp->nat_reserve; - if (reserve <= 0) { - pr("No military reserves left\n"); - return RET_OK; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + if (!trechk(player->cnum, 0, TRTENL)) + return RET_FAIL; + natp = getnatp(player->cnum); + newmil = 500; + sprintf(prompt, "Number to enlist (max %d) : ", newmil); + if ((p = getstarg(player->argp[2], prompt, buf)) == 0) + return RET_SYN; + if ((milwant = atoi(p)) > newmil) + milwant = newmil; + if (0 != (quota = (milwant < 0))) + milwant = -milwant; + totalmil = 0; + reserve = natp->nat_reserve; + if (reserve <= 0) { + pr("No military reserves left\n"); + return RET_OK; + } + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (sect.sct_oldown != player->cnum) + continue; + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + if (civ == 0) + continue; + if (sect.sct_loyal > 70) { + pr("civilians refuse to report in %s!\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; } - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (sect.sct_oldown != player->cnum) - continue; - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - if (civ == 0) - continue; - if (sect.sct_loyal > 70) { - pr("civilians refuse to report in %s!\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - continue; - } - if (sect.sct_mobil <= 0) { - pr("%s is out of mobility!\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - } - mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); - newmil = civ * 0.5; - if (quota) { - if (newmil > milwant - mil) - newmil = milwant - mil; - if (newmil > 500) - newmil = 500; - } else if (newmil > milwant) - newmil = milwant; - if (newmil > 999 - mil) - newmil = 999 - mil; - if (newmil <= 0) - continue; - if (newmil > reserve) - newmil = reserve; - if (!putvar(V_MILIT, newmil + mil, (s_char *)§, EF_SECTOR)) { - pr("No room for military in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - continue; - } - reserve -= newmil; - totalmil += newmil; - putvar(V_CIVIL, civ - newmil, (s_char *)§, EF_SECTOR); - pr("%3d enlisted in %s (%d)\n", newmil, - xyas(sect.sct_x, sect.sct_y, player->cnum), mil + newmil); - if (sect.sct_mobil > 0) { - sect.sct_mobil = (u_char)((float)sect.sct_mobil * - (1.0 - (float)newmil / (float)civ)); - } - putsect(§); - if (totalmil >= 10000) { - pr("Rioting in induction center interrupts enlistment\n"); - break; - } - if (reserve == 0) { - pr("Military reserve exhausted\n"); - break; - } + if (sect.sct_mobil <= 0) { + pr("%s is out of mobility!\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); } - pr("Total new enlistment : %d\n", totalmil); - pr("Military reserves stand at %d\n", reserve); - if (totalmil) { - natp->nat_reserve -= totalmil; - putnat(natp); + mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); + newmil = civ * 0.5; + if (quota) { + if (newmil > milwant - mil) + newmil = milwant - mil; + if (newmil > 500) + newmil = 500; + } else if (newmil > milwant) + newmil = milwant; + if (newmil > 999 - mil) + newmil = 999 - mil; + if (newmil <= 0) + continue; + if (newmil > reserve) + newmil = reserve; + if (!putvar(V_MILIT, newmil + mil, (s_char *)§, EF_SECTOR)) { + pr("No room for military in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; } - if ((player->btused += roundavg((float)totalmil * 0.02)) > 0) - pr("Paperwork at recruiting stations ... %d\n", - player->btused); - return RET_OK; + reserve -= newmil; + totalmil += newmil; + putvar(V_CIVIL, civ - newmil, (s_char *)§, EF_SECTOR); + pr("%3d enlisted in %s (%d)\n", newmil, + xyas(sect.sct_x, sect.sct_y, player->cnum), mil + newmil); + if (sect.sct_mobil > 0) { + sect.sct_mobil = (u_char)((float)sect.sct_mobil * + (1.0 - (float)newmil / (float)civ)); + } + putsect(§); + if (totalmil >= 10000) { + pr("Rioting in induction center interrupts enlistment\n"); + break; + } + if (reserve == 0) { + pr("Military reserve exhausted\n"); + break; + } + } + pr("Total new enlistment : %d\n", totalmil); + pr("Military reserves stand at %d\n", reserve); + if (totalmil) { + natp->nat_reserve -= totalmil; + putnat(natp); + } + if ((player->btused += roundavg((float)totalmil * 0.02)) > 0) + pr("Paperwork at recruiting stations ... %d\n", player->btused); + return RET_OK; } diff --git a/src/lib/commands/expl.c b/src/lib/commands/expl.c index ce4cd1f6c..ce469aaaf 100644 --- a/src/lib/commands/expl.c +++ b/src/lib/commands/expl.c @@ -44,7 +44,7 @@ #include "optlist.h" #include "commands.h" -static int explore_map(s_char *what, coord curx, coord cury, s_char *arg); +static int explore_map(s_char *what, coord curx, coord cury, s_char *arg); extern int etu_per_update; extern int sect_mob_neg_factor; @@ -52,292 +52,289 @@ extern int sect_mob_neg_factor; int explore(void) { - register int amount; - struct sctstr orig, sect; - struct sctstr endsect; - struct sctstr start; - struct sctstr chksect; - double weight; - int mcost, dam; - int infected; - int vtype; - int amt_src; - int amt_dst; - struct ichrstr *ip; - int work; - int loyal; - int own, mob; - int justtook; - coord x, y; - s_char *p; - int n; - int left; - s_char buf[1024]; - s_char prompt[128]; + register int amount; + struct sctstr orig, sect; + struct sctstr endsect; + struct sctstr start; + struct sctstr chksect; + double weight; + int mcost, dam; + int infected; + int vtype; + int amt_src; + int amt_dst; + struct ichrstr *ip; + int work; + int loyal; + int own, mob; + int justtook; + coord x, y; + s_char *p; + int n; + int left; + s_char buf[1024]; + s_char prompt[128]; - if ((ip = whatitem(player->argp[1], "explore with what? (civ/mil) ")) == 0) - return RET_SYN; - vtype = ip->i_vtype; - if ((vtype != V_CIVIL) && (vtype != V_MILIT)) { - pr("You can only explore with civs and mil.\n"); - return RET_FAIL; - } - if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y)) - return RET_SYN; - if (!getsect(x, y, §) || !player->owner) { - pr("Not yours\n"); - return RET_FAIL; - } - bcopy((s_char *)§,(s_char *)&orig,sizeof(struct sctstr)); - infected = getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT; - if ((amt_src = getvar(vtype, (s_char *)§, EF_SECTOR)) <= 0) { - pr("No %s in %s\n", ip->i_name, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_SYN; - } - own = sect.sct_own; - mob = (int)sect.sct_mobil; - if (vtype == V_CIVIL && sect.sct_oldown != own) { - pr("You can't explore with conquered populace!\n"); - return RET_SYN; - } - if (mob <= 0) { - pr("No mobility in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_SYN; - } - if (vtype == V_CIVIL) { - work = sect.sct_work; - if (work != 100) - pr("Warning: civil unrest\n"); - loyal = sect.sct_loyal; - } else if (vtype == V_MILIT) { - work = 100; - loyal = 0; - } - sprintf(prompt, "Number of %s to explore with? (max %d) ", - ip->i_name, amt_src); - amount = onearg(player->argp[3], prompt); - if (!check_sect_ok(§)) - return RET_FAIL; - if (amount > amt_src) { - amount = amt_src; - pr("Only exploring with %d.\n", amount); - } - - if (!want_to_abandon(§, vtype, amount, 0)) { - pr("Explore cancelled.\n"); - return RET_FAIL; - } + if ((ip = + whatitem(player->argp[1], "explore with what? (civ/mil) ")) == 0) + return RET_SYN; + vtype = ip->i_vtype; + if ((vtype != V_CIVIL) && (vtype != V_MILIT)) { + pr("You can only explore with civs and mil.\n"); + return RET_FAIL; + } + if ((p = getstarg(player->argp[2], "from sector : ", buf)) == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y)) + return RET_SYN; + if (!getsect(x, y, §) || !player->owner) { + pr("Not yours\n"); + return RET_FAIL; + } + bcopy((s_char *)§, (s_char *)&orig, sizeof(struct sctstr)); + infected = getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT; + if ((amt_src = getvar(vtype, (s_char *)§, EF_SECTOR)) <= 0) { + pr("No %s in %s\n", ip->i_name, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_SYN; + } + own = sect.sct_own; + mob = (int)sect.sct_mobil; + if (vtype == V_CIVIL && sect.sct_oldown != own) { + pr("You can't explore with conquered populace!\n"); + return RET_SYN; + } + if (mob <= 0) { + pr("No mobility in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_SYN; + } + if (vtype == V_CIVIL) { + work = sect.sct_work; + if (work != 100) + pr("Warning: civil unrest\n"); + loyal = sect.sct_loyal; + } else if (vtype == V_MILIT) { + work = 100; + loyal = 0; + } + sprintf(prompt, "Number of %s to explore with? (max %d) ", + ip->i_name, amt_src); + amount = onearg(player->argp[3], prompt); + if (!check_sect_ok(§)) + return RET_FAIL; + if (amount > amt_src) { + amount = amt_src; + pr("Only exploring with %d.\n", amount); + } - if (!check_sect_ok(§)) - return RET_FAIL; + if (!want_to_abandon(§, vtype, amount, 0)) { + pr("Explore cancelled.\n"); + return RET_FAIL; + } - if (amount <= 0) - return RET_SYN; - weight = amount * ip->i_lbs; - /* remove commodities from source sector */ - getsect(x, y, &start); - amt_src = getvar(vtype, (s_char *)&start, EF_SECTOR); - amt_src -= amount; - if (amt_src < 0) { - pr("%s in %s are gone!\n", ip->i_name, - xyas(start.sct_x, start.sct_y, player->cnum)); - return RET_OK; - } - putvar(vtype, amt_src, (s_char *)&start, EF_SECTOR); - start.sct_flags |= MOVE_IN_PROGRESS; - putsect(&start); - /* - * Now parse the path and return ending sector. - */ - dam = 1; - mcost = move_ground((s_char *)ip, §, &endsect, - (double)sect.sct_mobil, weight, player->argp[4], - explore_map, 1, &dam); + if (!check_sect_ok(§)) + return RET_FAIL; - if (dam) { - left = effdamage(amount, dam); - if (left < amount) { - if (left) { - pr("%d of the %s you were exploring with were destroyed!\nOnly %d %s made it to %s\n", - amount - left, - ip->i_name, - left, - ip->i_name, - xyas(endsect.sct_x, endsect.sct_y, player->cnum)); - } else { - pr("All of the %s you were exploring with were destroyed!\n",ip->i_name); - } - amount = left; - } - } - if (mcost > 0) - pr("Total movement cost = %d",mcost); - else - pr("No mobility used"); + if (amount <= 0) + return RET_SYN; + weight = amount * ip->i_lbs; + /* remove commodities from source sector */ + getsect(x, y, &start); + amt_src = getvar(vtype, (s_char *)&start, EF_SECTOR); + amt_src -= amount; + if (amt_src < 0) { + pr("%s in %s are gone!\n", ip->i_name, + xyas(start.sct_x, start.sct_y, player->cnum)); + return RET_OK; + } + putvar(vtype, amt_src, (s_char *)&start, EF_SECTOR); + start.sct_flags |= MOVE_IN_PROGRESS; + putsect(&start); + /* + * Now parse the path and return ending sector. + */ + dam = 1; + mcost = move_ground((s_char *)ip, §, &endsect, + (double)sect.sct_mobil, weight, player->argp[4], + explore_map, 1, &dam); - if (mcost < 0) { - pr("\nExplore aborted"); - getsect(start.sct_x,start.sct_y,§); - sect.sct_mobil = (u_char)mob; - }else{ - /* Charge mobility */ - getsect(sect.sct_x, sect.sct_y, §); - n = sect.sct_mobil - mcost; - if (n < 0) - n = 0; - sect.sct_mobil = (u_char)n; - pr(", %d mob left in %s", sect.sct_mobil, - xyas(sect.sct_x,sect.sct_y,player->cnum)); - putsect(§); - getsect(endsect.sct_x, endsect.sct_y, §); + if (dam) { + left = effdamage(amount, dam); + if (left < amount) { + if (left) { + pr("%d of the %s you were exploring with were destroyed!\nOnly %d %s made it to %s\n", amount - left, ip->i_name, left, ip->i_name, xyas(endsect.sct_x, endsect.sct_y, player->cnum)); + } else { + pr("All of the %s you were exploring with were destroyed!\n", ip->i_name); + } + amount = left; } - pr("\n"); - justtook = 0; + } + if (mcost > 0) + pr("Total movement cost = %d", mcost); + else + pr("No mobility used"); - /* - * Check for a multitude of problems - */ - getsect(endsect.sct_x, endsect.sct_y, &chksect); - if(chksect.sct_type == '.') { - pr("Bridge disappeared!\n"); - getsect(start.sct_x,start.sct_y,&start); - start.sct_flags &= ~MOVE_IN_PROGRESS; - putsect(&start); - return RET_FAIL; - } - if(!player->god && chksect.sct_own && chksect.sct_own != player->cnum - && chksect.sct_type != SCT_SANCT) { - pr("Somebody beat you there!\n"); - /* Send them xback home */ - getsect(start.sct_x,start.sct_y,§); - if (sect.sct_own != own) { - pr("Someone captured the sector you started from!\n"); - pr("Your exploring people die of disappointment!\n"); - sect.sct_flags &= ~MOVE_IN_PROGRESS; - putsect(§); - return RET_FAIL; - } - } + if (mcost < 0) { + pr("\nExplore aborted"); + getsect(start.sct_x, start.sct_y, §); + sect.sct_mobil = (u_char)mob; + } else { + /* Charge mobility */ + getsect(sect.sct_x, sect.sct_y, §); + n = sect.sct_mobil - mcost; + if (n < 0) + n = 0; + sect.sct_mobil = (u_char)n; + pr(", %d mob left in %s", sect.sct_mobil, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + putsect(§); + getsect(endsect.sct_x, endsect.sct_y, §); + } + pr("\n"); + justtook = 0; - if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) { - (void) takeover(§, player->cnum); - justtook = 1; - sect.sct_oldown = own; - sect.sct_work = work; - sect.sct_loyal = loyal; - } - if (vtype == V_CIVIL && sect.sct_oldown != player->cnum) { - pr("Your civilians don't want to stay!\n"); - getsect(start.sct_x,start.sct_y,§); - if (sect.sct_own != own) { - pr("Someone captured the sector you started from!\n"); - pr("Your exploring people die of disappointment!\n"); - sect.sct_flags &= ~MOVE_IN_PROGRESS; - putsect(§); - return RET_FAIL; - } - } - getsect(start.sct_x,start.sct_y,&start); + /* + * Check for a multitude of problems + */ + getsect(endsect.sct_x, endsect.sct_y, &chksect); + if (chksect.sct_type == '.') { + pr("Bridge disappeared!\n"); + getsect(start.sct_x, start.sct_y, &start); start.sct_flags &= ~MOVE_IN_PROGRESS; putsect(&start); - amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR); - if (32767 - amt_dst < amount) { - amount = 32767 - amt_dst; - pr("Only %d can be left there.\n", amount); - if (amount <= 0) - getsect(start.sct_x,start.sct_y,§); - } - if (putvar(vtype, amount + amt_dst, (s_char *)§, EF_SECTOR) < 0) { - pr("No more room in %s.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_OK; - } - /* - * Now add commodities to destination sector, - * along with plague that came along for the ride. - * Takeover unowned sectors if not deity. - */ - if (!player->god && sect.sct_type != SCT_SANCT && justtook) { - pr("Sector %s is now yours.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - if (opt_MOB_ACCESS) { - time(§.sct_access); - sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor); - } else { - sect.sct_mobil = 0; - } + return RET_FAIL; + } + if (!player->god && chksect.sct_own && chksect.sct_own != player->cnum + && chksect.sct_type != SCT_SANCT) { + pr("Somebody beat you there!\n"); + /* Send them xback home */ + getsect(start.sct_x, start.sct_y, §); + if (sect.sct_own != own) { + pr("Someone captured the sector you started from!\n"); + pr("Your exploring people die of disappointment!\n"); + sect.sct_flags &= ~MOVE_IN_PROGRESS; + putsect(§); + return RET_FAIL; } - if (infected && getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == 0) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); - if (vtype == V_CIVIL) { - if (opt_NEW_WORK) { - sect.sct_loyal =( (amt_dst * sect.sct_loyal) + - (amount * loyal) ) / (amt_dst+amount); - sect.sct_work =( (amt_dst * sect.sct_work) + - (amount * work) ) / (amt_dst+amount); - } else { /* ! NEW_WORK */ + } - /* It only takes one bad apple... */ - if (sect.sct_loyal < loyal) - sect.sct_loyal = loyal; - if (sect.sct_work > work) - sect.sct_work = work; - } /* end NEW_WORK */ + if (!player->god && !player->owner && sect.sct_type != SCT_SANCT) { + (void)takeover(§, player->cnum); + justtook = 1; + sect.sct_oldown = own; + sect.sct_work = work; + sect.sct_loyal = loyal; + } + if (vtype == V_CIVIL && sect.sct_oldown != player->cnum) { + pr("Your civilians don't want to stay!\n"); + getsect(start.sct_x, start.sct_y, §); + if (sect.sct_own != own) { + pr("Someone captured the sector you started from!\n"); + pr("Your exploring people die of disappointment!\n"); + sect.sct_flags &= ~MOVE_IN_PROGRESS; + putsect(§); + return RET_FAIL; } - putsect(§); + } + getsect(start.sct_x, start.sct_y, &start); + start.sct_flags &= ~MOVE_IN_PROGRESS; + putsect(&start); + amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR); + if (32767 - amt_dst < amount) { + amount = 32767 - amt_dst; + pr("Only %d can be left there.\n", amount); + if (amount <= 0) + getsect(start.sct_x, start.sct_y, §); + } + if (putvar(vtype, amount + amt_dst, (s_char *)§, EF_SECTOR) < 0) { + pr("No more room in %s.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); return RET_OK; + } + /* + * Now add commodities to destination sector, + * along with plague that came along for the ride. + * Takeover unowned sectors if not deity. + */ + if (!player->god && sect.sct_type != SCT_SANCT && justtook) { + pr("Sector %s is now yours.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + if (opt_MOB_ACCESS) { + time(§.sct_access); + sect.sct_mobil = -(etu_per_update / sect_mob_neg_factor); + } else { + sect.sct_mobil = 0; + } + } + if (infected && getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == 0) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); + if (vtype == V_CIVIL) { + if (opt_NEW_WORK) { + sect.sct_loyal = ((amt_dst * sect.sct_loyal) + + (amount * loyal)) / (amt_dst + amount); + sect.sct_work = ((amt_dst * sect.sct_work) + + (amount * work)) / (amt_dst + amount); + } else { /* ! NEW_WORK */ + + /* It only takes one bad apple... */ + if (sect.sct_loyal < loyal) + sect.sct_loyal = loyal; + if (sect.sct_work > work) + sect.sct_work = work; + } /* end NEW_WORK */ + } + putsect(§); + return RET_OK; } /*ARGSUSED*/ static int explore_map(s_char *what, coord curx, coord cury, s_char *arg) { - struct nstr_sect ns; - struct natstr *np; - struct sctstr sect; - coord rel_x, rel_y; - s_char range[128]; - s_char view[7]; - int i; - int changed = 0; + struct nstr_sect ns; + struct natstr *np; + struct sctstr sect; + coord rel_x, rel_y; + s_char range[128]; + s_char view[7]; + int i; + int changed = 0; - np = getnatp(player->cnum); - rel_x = xrel(np, curx); - rel_y = yrel(np, cury); - sprintf(range, "%d:%d,%d:%d", rel_x-2, rel_x+2, rel_y-1, rel_y+1); - if (!snxtsct(&ns, range)) - return RET_FAIL; - i = 0; - while (i < 7 && nxtsct(&ns, §)) { - view[i] = dchr[sect.sct_type].d_mnem; - switch (sect.sct_type) { - case SCT_WATER: - case SCT_RURAL: - case SCT_MOUNT: - case SCT_WASTE: - case SCT_PLAINS: - break; - default: - if (sect.sct_own != player->cnum && !player->god) - view[i] = '?'; - break; - } - changed += map_set(player->cnum, ns.x, ns.y, view[i], 0); - i++; + np = getnatp(player->cnum); + rel_x = xrel(np, curx); + rel_y = yrel(np, cury); + sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1, + rel_y + 1); + if (!snxtsct(&ns, range)) + return RET_FAIL; + i = 0; + while (i < 7 && nxtsct(&ns, §)) { + view[i] = dchr[sect.sct_type].d_mnem; + switch (sect.sct_type) { + case SCT_WATER: + case SCT_RURAL: + case SCT_MOUNT: + case SCT_WASTE: + case SCT_PLAINS: + break; + default: + if (sect.sct_own != player->cnum && !player->god) + view[i] = '?'; + break; } - if (changed) - writemap(player->cnum); - if (!getsect(curx, cury, §)) - return RET_FAIL; - pr(" %c %c min gold fert oil uran\n", view[0], view[1]); - pr(" %c %c %c %3d %4d %4d %4d %4d\n", - view[2], view[3], view[4], - sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil, - sect.sct_uran); - pr(" %c %c\n", view[5], view[6]); - return RET_OK; + changed += map_set(player->cnum, ns.x, ns.y, view[i], 0); + i++; + } + if (changed) + writemap(player->cnum); + if (!getsect(curx, cury, §)) + return RET_FAIL; + pr(" %c %c min gold fert oil uran\n", view[0], view[1]); + pr(" %c %c %c %3d %4d %4d %4d %4d\n", + view[2], view[3], view[4], + sect.sct_min, sect.sct_gmin, sect.sct_fertil, sect.sct_oil, + sect.sct_uran); + pr(" %c %c\n", view[5], view[6]); + return RET_OK; } diff --git a/src/lib/commands/fina.c b/src/lib/commands/fina.c index bed9cf3f6..8b0c3b058 100644 --- a/src/lib/commands/fina.c +++ b/src/lib/commands/fina.c @@ -49,72 +49,72 @@ int fina(void) { - struct lonstr loan; - struct nstr_item ni; - time_t now; - int rdur; - int xdur; - double rate; - double amt; - time_t due; - time_t last; + struct lonstr loan; + struct nstr_item ni; + time_t now; + int rdur; + int xdur; + double rate; + double amt; + time_t due; + time_t last; - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; + } + (void)time(&now); + pr("\n"); + pr(" -= Empire Financial Status Report =- \n"); + pr(" "); + prdate(); + pr("Loan From To Rate Dur Paid Total\n"); + snxtitem(&ni, EF_LOAN, "*"); + while (nxtitem(&ni, (s_char *)&loan)) { + if (loan.l_status != LS_SIGNED) + continue; + due = loan.l_duedate; + last = loan.l_lastpay; + rdur = 0; + xdur = 0; + if (now < due) { + rdur = now - last; + xdur = 0; } - (void)time(&now); - pr("\n"); - pr(" -= Empire Financial Status Report =- \n"); - pr(" "); - prdate(); - pr("Loan From To Rate Dur Paid Total\n"); - snxtitem(&ni, EF_LOAN, "*"); - while (nxtitem(&ni, (s_char *)&loan)) { - if (loan.l_status != LS_SIGNED) - continue; - due = loan.l_duedate; - last = loan.l_lastpay; - rdur = 0; - xdur = 0; - if (now < due) { - rdur = now - last; - xdur = 0; - } - if (last < due && due < now) { - rdur = due - last; - xdur = now - due; - } - if (due < last) { - rdur = 0; - xdur = now - last; - } - if (loan.l_ldur == 0) { - logerror("loan #%d has zero duration", ni.cur); - continue; - } - rate = loan.l_irate / (loan.l_ldur * 8640000.0); + if (last < due && due < now) { + rdur = due - last; + xdur = now - due; + } + if (due < last) { + rdur = 0; + xdur = now - last; + } + if (loan.l_ldur == 0) { + logerror("loan #%d has zero duration", ni.cur); + continue; + } + rate = loan.l_irate / (loan.l_ldur * 8640000.0); /* changed following to avoid overflow 3/27/89 bailey@math-cs.kent.edu amt = (rdur * rate + xdur * rate * 2.0 + 1.0) * loan.l_amtdue; Begin overflow fix */ - amt = (rdur * rate + xdur * rate * 2.0 + 1.0); - if (((1 << 30) / amt) < loan.l_amtdue) - amt = (1 << 30); - else - amt *= loan.l_amtdue; + amt = (rdur * rate + xdur * rate * 2.0 + 1.0); + if (((1 << 30) / amt) < loan.l_amtdue) + amt = (1 << 30); + else + amt *= loan.l_amtdue; /* End overflow fix */ - pr(" %-2d (%3d) %-8.8s (%3d) %-8.8s ", ni.cur, - loan.l_loner, cname(loan.l_loner), - loan.l_lonee, cname(loan.l_lonee)); - pr("%3d%% %3d %5d %7d", - loan.l_irate, loan.l_ldur, loan.l_amtpaid, (int) amt); - if (now > loan.l_duedate) - pr(" (in arrears)\n"); - else - pr("\n"); - } - pr("\n"); - return RET_OK; + pr(" %-2d (%3d) %-8.8s (%3d) %-8.8s ", ni.cur, + loan.l_loner, cname(loan.l_loner), + loan.l_lonee, cname(loan.l_lonee)); + pr("%3d%% %3d %5d %7d", + loan.l_irate, loan.l_ldur, loan.l_amtpaid, (int)amt); + if (now > loan.l_duedate) + pr(" (in arrears)\n"); + else + pr("\n"); + } + pr("\n"); + return RET_OK; } diff --git a/src/lib/commands/flash.c b/src/lib/commands/flash.c index 094b62754..dcf3e39ee 100644 --- a/src/lib/commands/flash.c +++ b/src/lib/commands/flash.c @@ -46,152 +46,152 @@ int flash(void) { - struct natstr *us; - struct natstr *to; - s_char buf[600]; - int tocn; - s_char *sp; + struct natstr *us; + struct natstr *to; + s_char buf[600]; + int tocn; + s_char *sp; - us = getnatp(player->cnum); - if ((tocn = natarg(player->argp[1], "to which country? ")) < 0) - return RET_SYN; - if (!(to = getnatp((natid)tocn))) { - pr("Bad country number\n"); - return RET_SYN; - } + us = getnatp(player->cnum); + if ((tocn = natarg(player->argp[1], "to which country? ")) < 0) + return RET_SYN; + if (!(to = getnatp((natid)tocn))) { + pr("Bad country number\n"); + return RET_SYN; + } - if (us->nat_stat & STAT_GOD) { - /* We are gods, we can flash anyone */ - } else if (us->nat_stat == VIS) { - /* We are a visitor. We can only flash the gods. :) */ - if (!(to->nat_stat & STAT_GOD)) { - pr("Visitors can only flash the gods.\n"); - return RET_SYN; - } - } else { - /* Ok, we are a normal country, can we flash them? */ - if ((!(to->nat_stat & STAT_GOD)) && - (getrel(to, player->cnum) < FRIENDLY)) { - pr("%s is not a deity or friendly with us.\n", to->nat_cnam); - return RET_SYN; - } - } + if (us->nat_stat & STAT_GOD) { + /* We are gods, we can flash anyone */ + } else if (us->nat_stat == VIS) { + /* We are a visitor. We can only flash the gods. :) */ + if (!(to->nat_stat & STAT_GOD)) { + pr("Visitors can only flash the gods.\n"); + return RET_SYN; + } + } else { + /* Ok, we are a normal country, can we flash them? */ + if ((!(to->nat_stat & STAT_GOD)) && + (getrel(to, player->cnum) < FRIENDLY)) { + pr("%s is not a deity or friendly with us.\n", to->nat_cnam); + return RET_SYN; + } + } - if (player->argp[2]) { - for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp); - for (++sp; *sp && *sp != ' '; ++sp); - sprintf(buf, ":%s", sp); - sendmessage(us, to, buf, 1); - } else { - sendmessage(us, to, "...", 1); - while (getstring("> ", buf)) { - if (*buf == '.') - break; - sendmessage(us, to, buf, 0); - } - sendmessage(us, to, "", 0); + if (player->argp[2]) { + for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ; + for (++sp; *sp && *sp != ' '; ++sp) ; + sprintf(buf, ":%s", sp); + sendmessage(us, to, buf, 1); + } else { + sendmessage(us, to, "...", 1); + while (getstring("> ", buf)) { + if (*buf == '.') + break; + sendmessage(us, to, buf, 0); } - return RET_OK; + sendmessage(us, to, "", 0); + } + return RET_OK; } int wall(void) { - struct natstr *us; - s_char buf[600]; - s_char *sp; + struct natstr *us; + s_char buf[600]; + s_char *sp; - us = getnatp(player->cnum); - if (player->argp[1]) { - for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp); - for (++sp; *sp && *sp != ' '; ++sp); - sprintf(buf, ":%s", sp); - sendmessage(us, 0, buf, 1); - } else { - sendmessage(us, 0, "...", 1); - while (getstring("> ", buf)) { - if (*buf == '.') - break; - sendmessage(us, 0, buf, 0); - } - sendmessage(us, 0, "", 0); + us = getnatp(player->cnum); + if (player->argp[1]) { + for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ; + for (++sp; *sp && *sp != ' '; ++sp) ; + sprintf(buf, ":%s", sp); + sendmessage(us, 0, buf, 1); + } else { + sendmessage(us, 0, "...", 1); + while (getstring("> ", buf)) { + if (*buf == '.') + break; + sendmessage(us, 0, buf, 0); } - return RET_OK; + sendmessage(us, 0, "", 0); + } + return RET_OK; } int -sendmessage(struct natstr *us, struct natstr *to, char *message, int oneshot) +sendmessage(struct natstr *us, struct natstr *to, char *message, + int oneshot) { - struct player *other; - struct tm *tm; - char *p; - char c; - time_t now; - int sent = 0; - struct natstr *wto; + struct player *other; + struct tm *tm; + char *p; + char c; + time_t now; + int sent = 0; + struct natstr *wto; - for (p = message; 0 != (c = *p); p++) { - if (!isprint(c)) - *p = '*'; - } - if (strlen(message) > 60) { - s_char c = message[60]; - message[60] = '\0'; - sendmessage(us, to, message, oneshot); - message[60] = c; - sendmessage(us, to, &message[60], 0); - return 0; - } - time(&now); - tm = localtime(&now); - for (other = player_next(0); other != 0; other = player_next(other)) { - if (to && other->cnum != to->nat_cnum) - continue; - if (!(wto = getnatp(other->cnum))) - continue; - if (!to && !player->god && getrel(wto, player->cnum) != ALLIED) - continue; - if (!player->god && !(wto->nat_flags & NF_FLASH)) - continue; - if (player == other) - continue; - if (oneshot) - if (to) - pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n", - us->nat_cnam, us->nat_cnum, tm->tm_hour, - tm->tm_min, message); - else - pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n", - us->nat_cnam, us->nat_cnum, tm->tm_hour, - tm->tm_min, message); + for (p = message; 0 != (c = *p); p++) { + if (!isprint(c)) + *p = '*'; + } + if (strlen(message) > 60) { + s_char c = message[60]; + message[60] = '\0'; + sendmessage(us, to, message, oneshot); + message[60] = c; + sendmessage(us, to, &message[60], 0); + return 0; + } + time(&now); + tm = localtime(&now); + for (other = player_next(0); other != 0; other = player_next(other)) { + if (to && other->cnum != to->nat_cnum) + continue; + if (!(wto = getnatp(other->cnum))) + continue; + if (!to && !player->god && getrel(wto, player->cnum) != ALLIED) + continue; + if (!player->god && !(wto->nat_flags & NF_FLASH)) + continue; + if (player == other) + continue; + if (oneshot) + if (to) + pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n", + us->nat_cnam, us->nat_cnum, tm->tm_hour, + tm->tm_min, message); + else + pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n", + us->nat_cnam, us->nat_cnum, tm->tm_hour, + tm->tm_min, message); - else - pr_flash(other, "%s (#%d): %s\n", - us->nat_cnam, us->nat_cnum, message); - player_wakeup(other); - sent++; - } - if (player->god) { - if (to) - if (sent) - pr("Flash sent to %s\n", to->nat_cnam); - else - pr("%s is not logged on\n", to->nat_cnam); - else - if (sent) - pr("Broadcast sent to %d players\n", sent); - else - pr("No-one is logged in\n"); - } - if (to && !player->god) { - /* If they are allied with us, we would normally see that - * they are logged in anyway, so just tell us */ - if ((getrel(to, player->cnum) == ALLIED) && !sent) { + else + pr_flash(other, "%s (#%d): %s\n", + us->nat_cnam, us->nat_cnum, message); + player_wakeup(other); + sent++; + } + if (player->god) { + if (to) + if (sent) + pr("Flash sent to %s\n", to->nat_cnam); + else + pr("%s is not logged on\n", to->nat_cnam); + else if (sent) + pr("Broadcast sent to %d players\n", sent); + else + pr("No-one is logged in\n"); + } + if (to && !player->god) { + /* If they are allied with us, we would normally see that + * they are logged in anyway, so just tell us */ + if ((getrel(to, player->cnum) == ALLIED) && !sent) { if (to->nat_flags & NF_FLASH) - pr("%s is not logged on\n", to->nat_cnam); + pr("%s is not logged on\n", to->nat_cnam); else - pr("%s is not accepting flashes\n", to->nat_cnam); - } + pr("%s is not accepting flashes\n", to->nat_cnam); } - return 0; + } + return 0; } diff --git a/src/lib/commands/flee.c b/src/lib/commands/flee.c index 2a84e0f69..45d3baa3c 100644 --- a/src/lib/commands/flee.c +++ b/src/lib/commands/flee.c @@ -45,43 +45,43 @@ int flee(void) { - struct shpstr ship; - register int count; - s_char *cp; - s_char c; - struct nstr_item nstr; - struct nstr_item ni; - struct shpstr ship2; - int r; - s_char buf[1024]; + struct shpstr ship; + register int count; + s_char *cp; + s_char c; + struct nstr_item nstr; + struct nstr_item ni; + struct shpstr ship2; + int r; + s_char buf[1024]; - cp = getstarg(player->argp[1], "fleet? ", buf); - if (cp == 0) - return RET_SYN; - c = *cp; - if (!isalpha(c) && c != '~') { - pr("Specify fleet, (1 alpha char or '~')\n"); - return RET_SYN; + cp = getstarg(player->argp[1], "fleet? ", buf); + if (cp == 0) + return RET_SYN; + c = *cp; + if (!isalpha(c) && c != '~') { + pr("Specify fleet, (1 alpha char or '~')\n"); + return RET_SYN; + } + if (c == '~') + c = ' '; + if (!snxtitem(&nstr, EF_SHIP, player->argp[2])) + return RET_SYN; + count = 0; + while (nxtitem(&nstr, (s_char *)&ship)) { + if (!player->owner) + continue; + ship.shp_fleet = c; + snxtitem(&ni, EF_SHIP, cp); + while ((r = nxtitem(&ni, (s_char *)&ship2)) + && (ship2.shp_fleet != c)) ; + if (r) { + bcopy(ship2.shp_rpath, ship.shp_rpath, 10); + ship.shp_rflags = ship2.shp_rflags; } - if (c == '~') - c = ' '; - if (!snxtitem(&nstr, EF_SHIP, player->argp[2])) - return RET_SYN; - count = 0; - while (nxtitem(&nstr, (s_char *)&ship)) { - if (!player->owner) - continue; - ship.shp_fleet = c; - snxtitem(&ni, EF_SHIP, cp); - while((r=nxtitem(&ni, (s_char *)&ship2)) - && (ship2.shp_fleet != c)); - if (r){ - bcopy(ship2.shp_rpath, ship.shp_rpath,10); - ship.shp_rflags = ship2.shp_rflags; - } - putship(ship.shp_uid, &ship); - count++; - } - pr("%d ship%s added to fleet `%c'\n", count, splur(count), c); - return RET_OK; + putship(ship.shp_uid, &ship); + count++; + } + pr("%d ship%s added to fleet `%c'\n", count, splur(count), c); + return RET_OK; } diff --git a/src/lib/commands/fly.c b/src/lib/commands/fly.c index 52965e153..4daad8784 100644 --- a/src/lib/commands/fly.c +++ b/src/lib/commands/fly.c @@ -51,102 +51,109 @@ int fly(void) { - s_char *p; - int mission_flags; - int tech; - coord tx, ty; - coord ax, ay; - int ap_to_target; - struct ichrstr *ip; - s_char flightpath[MAX_PATH_LEN]; - struct shpstr ship; - int cno; - struct nstr_item ni_bomb; - struct nstr_item ni_esc; - coord x, y; - struct sctstr target; - struct emp_qelem bomb_list; - struct emp_qelem esc_list; - int wantflags; - struct sctstr ap_sect; - int dst_type; - s_char *dst_ptr; - s_char buf[1024]; + s_char *p; + int mission_flags; + int tech; + coord tx, ty; + coord ax, ay; + int ap_to_target; + struct ichrstr *ip; + s_char flightpath[MAX_PATH_LEN]; + struct shpstr ship; + int cno; + struct nstr_item ni_bomb; + struct nstr_item ni_esc; + coord x, y; + struct sctstr target; + struct emp_qelem bomb_list; + struct emp_qelem esc_list; + int wantflags; + struct sctstr ap_sect; + int dst_type; + s_char *dst_ptr; + s_char buf[1024]; - wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) - return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); - if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 || *p == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) - return RET_SYN; - if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && - getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { - pr("Assembly point not owned by you or an ally!\n"); - return RET_SYN; - } - ax = x; - ay = y; - if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, - 0, P_FLYING) == 0 || *flightpath == 0) - return RET_SYN; - tx = ax; - ty = ay; - (void) pathtoxy(flightpath, &tx, &ty, fcost); - pr("Ending sector is %s\n", xyas(tx, ty, player->cnum)); + wantflags = 0; + if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + return RET_SYN; + if (!snxtitem + (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) + pr("No escorts...\n"); + if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 + || *p == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) + return RET_SYN; + if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && + getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { + pr("Assembly point not owned by you or an ally!\n"); + return RET_SYN; + } + ax = x; + ay = y; + if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, + 0, P_FLYING) == 0 || *flightpath == 0) + return RET_SYN; + tx = ax; + ty = ay; + (void)pathtoxy(flightpath, &tx, &ty, fcost); + pr("Ending sector is %s\n", xyas(tx, ty, player->cnum)); + getsect(tx, ty, &target); + cno = -1; + ip = whatitem(player->argp[5], "transport what? "); + mission_flags = 0; + if (pln_onewaymission(&target, &cno, &wantflags) < 0) + return RET_SYN; + if (cno < 0) { + dst_ptr = (s_char *)⌖ + dst_type = EF_SECTOR; + } else { + getship(cno, &ship); + dst_ptr = (s_char *)&ship; + dst_type = EF_SHIP; + } + ap_to_target = strlen(flightpath); + if (*(flightpath + strlen(flightpath) - 1) == 'h') + ap_to_target--; + pr("range to target is %d\n", ap_to_target); + /* + * select planes within range + */ + pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, + 1, wantflags, P_M | P_O); + wantflags |= P_F; + wantflags |= P_ESC; + pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, + 1, wantflags, P_M | P_O); + /* + * now arm and equip the bombers, transports, whatever. + * tech is stored in high 16 bits of mission_flags. + * yuck. + */ + tech = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + mission_flags = + pln_arm(&bomb_list, ap_to_target, 't', ip, 0, mission_flags, + &tech); + if (QEMPTY(&bomb_list)) { + pr("No planes could be equipped for the mission.\n"); + return RET_FAIL; + } + mission_flags = + pln_arm(&esc_list, ap_to_target, 't', ip, P_ESC | P_F, + mission_flags, &tech); + ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, + 0, 0, 0); + if (QEMPTY(&bomb_list)) { + pr("No planes got through fighter defenses\n"); + } else { getsect(tx, ty, &target); - cno = -1; - ip = whatitem(player->argp[5], "transport what? "); - mission_flags = 0; - if (pln_onewaymission(&target, &cno, &wantflags) < 0) - return RET_SYN; - if (cno < 0) { - dst_ptr = (s_char *) ⌖ - dst_type = EF_SECTOR; - } else { - getship(cno, &ship); - dst_ptr = (s_char *) &ship; - dst_type = EF_SHIP; - } - ap_to_target = strlen(flightpath); - if (*(flightpath+strlen(flightpath)-1) == 'h') - ap_to_target--; - pr("range to target is %d\n", ap_to_target); - /* - * select planes within range - */ - pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, - 1, wantflags, P_M|P_O); - wantflags |= P_F; - wantflags |= P_ESC; - pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, - 1, wantflags, P_M|P_O); - /* - * now arm and equip the bombers, transports, whatever. - * tech is stored in high 16 bits of mission_flags. - * yuck. - */ - tech=0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - mission_flags = pln_arm(&bomb_list, ap_to_target, 't', ip, 0, mission_flags,&tech); - if (QEMPTY(&bomb_list)) { - pr("No planes could be equipped for the mission.\n"); - return RET_FAIL; - } - mission_flags = pln_arm(&esc_list, ap_to_target, 't', ip, P_ESC|P_F, mission_flags,&tech); - ac_encounter(&bomb_list,&esc_list,ax,ay,flightpath,mission_flags,0,0,0); - if (QEMPTY(&bomb_list)) { - pr("No planes got through fighter defenses\n"); - } else { - getsect(tx, ty, &target); - pln_dropoff(&bomb_list, ip, tx, ty, dst_ptr, dst_type); - pln_newlanding(&bomb_list, tx, ty, cno); - pln_newlanding(&esc_list, tx, ty, cno); - } - pln_put(&bomb_list); - pln_put(&esc_list); - return RET_OK; + pln_dropoff(&bomb_list, ip, tx, ty, dst_ptr, dst_type); + pln_newlanding(&bomb_list, tx, ty, cno); + pln_newlanding(&esc_list, tx, ty, cno); + } + pln_put(&bomb_list); + pln_put(&esc_list); + return RET_OK; } diff --git a/src/lib/commands/foll.c b/src/lib/commands/foll.c index a0d52a3a7..60fd41f96 100644 --- a/src/lib/commands/foll.c +++ b/src/lib/commands/foll.c @@ -46,67 +46,66 @@ int foll(void) { - struct shpstr ship; - s_char *cp; - int good,leader,count=0; - coord x,y; - struct nstr_item nstr; - s_char buf[1024]; + struct shpstr ship; + s_char *cp; + int good, leader, count = 0; + coord x, y; + struct nstr_item nstr; + s_char buf[1024]; - if (!opt_SAIL) { - pr("The SAIL option is not enabled, so this command is not valid.\n"); - return RET_FAIL; + if (!opt_SAIL) { + pr("The SAIL option is not enabled, so this command is not valid.\n"); + return RET_FAIL; + } + if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) + return RET_SYN; + cp = getstarg(player->argp[2], "leader?", buf); + if (cp == 0) + cp = ""; + good = sscanf(cp, "%d", &leader); + if (!good) + return RET_SYN; + getship(leader, &ship); + if (ship.shp_own != player->cnum && + getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY) { + pr("That ship won't let you follow.\n"); + return RET_FAIL; + } + x = ship.shp_x; + y = ship.shp_y; + while (nxtitem(&nstr, (s_char *)&ship)) { + if (!player->owner) + continue; + if (ship.shp_x != x || ship.shp_y != y) { + pr("Ship #%d not in same sector as #%d\n", ship.shp_uid, + leader); + continue; } - if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) - return RET_SYN; - cp = getstarg(player->argp[2],"leader?", buf); - if (cp==0) cp=""; - good = sscanf(cp,"%d",&leader); - if (!good) - return RET_SYN; - getship(leader,&ship); - if (ship.shp_own!=player->cnum && - getrel(getnatp(ship.shp_own),player->cnum) < FRIENDLY) - { - pr("That ship won't let you follow.\n"); - return RET_FAIL; - } - x = ship.shp_x; - y = ship.shp_y; - while (nxtitem(&nstr, (s_char *)&ship)) { - if (!player->owner) - continue; - if ( ship.shp_x!=x || ship.shp_y!=y ) - { - pr("Ship #%d not in same sector as #%d\n",ship.shp_uid,leader); - continue; - } - if (ship.shp_uid==leader) - { - pr("Ship #%d can't follow itself!\n",leader); - continue; - } - if ((ship.shp_autonav & AN_AUTONAV) && !(ship.shp_autonav & AN_STANDBY)) - { - pr("Ship #%d has other orders!\n",ship.shp_uid); - continue; - } - count++; - ship.shp_mission = 0; - *ship.shp_path = 'f'; - ship.shp_path[1] = 0; -/* sprintf(ship.shp_path,"f%d",leader);*/ - ship.shp_follow = leader; - pr("Ship #%d follows #%d.\n",ship.shp_uid,leader); - putship(ship.shp_uid, &ship); + if (ship.shp_uid == leader) { + pr("Ship #%d can't follow itself!\n", leader); + continue; + } + if ((ship.shp_autonav & AN_AUTONAV) + && !(ship.shp_autonav & AN_STANDBY)) { + pr("Ship #%d has other orders!\n", ship.shp_uid); + continue; } - if (count == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", count, splur(count)); - return RET_OK; + count++; + ship.shp_mission = 0; + *ship.shp_path = 'f'; + ship.shp_path[1] = 0; +/* sprintf(ship.shp_path,"f%d",leader);*/ + ship.shp_follow = leader; + pr("Ship #%d follows #%d.\n", ship.shp_uid, leader); + putship(ship.shp_uid, &ship); + } + if (count == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", count, splur(count)); + return RET_OK; } diff --git a/src/lib/commands/forc.c b/src/lib/commands/forc.c index 26d81eaef..d3a1dd15b 100644 --- a/src/lib/commands/forc.c +++ b/src/lib/commands/forc.c @@ -40,33 +40,33 @@ int force(void) { - extern empth_sem_t *update_sem; - extern int update_pending; - extern int shutdown_pending; - int seconds; - time_t now; + extern empth_sem_t *update_sem; + extern int update_pending; + extern int shutdown_pending; + int seconds; + time_t now; - if (update_pending) { - pr("Update is pending\n"); - return RET_FAIL; - } - if (shutdown_pending) { - pr("Shutdown is pending\n"); - return RET_FAIL; - } - if (updates_disabled()) { - pr("Updates are disabled\n"); - return RET_FAIL; - } - seconds = onearg(player->argp[1], "Time until update [in seconds]? "); - if (seconds < 0) - return RET_FAIL; - if (seconds) { - time(&now); - pr("Waiting %d seconds...\n", seconds); - empth_sleep(now + seconds); - } - pr("Scheduling update now\n"); - empth_sem_signal(update_sem); - return RET_OK; + if (update_pending) { + pr("Update is pending\n"); + return RET_FAIL; + } + if (shutdown_pending) { + pr("Shutdown is pending\n"); + return RET_FAIL; + } + if (updates_disabled()) { + pr("Updates are disabled\n"); + return RET_FAIL; + } + seconds = onearg(player->argp[1], "Time until update [in seconds]? "); + if (seconds < 0) + return RET_FAIL; + if (seconds) { + time(&now); + pr("Waiting %d seconds...\n", seconds); + empth_sleep(now + seconds); + } + pr("Scheduling update now\n"); + empth_sem_signal(update_sem); + return RET_OK; } diff --git a/src/lib/commands/fort.c b/src/lib/commands/fort.c index ca683f14c..7e8d0721f 100644 --- a/src/lib/commands/fort.c +++ b/src/lib/commands/fort.c @@ -47,114 +47,111 @@ int fort(void) { - int nunits; - struct nstr_item ni; - struct lndstr land; - int fort_amt, hard_amt, mob_used; - int eng; - s_char *p; - extern int land_mob_max; - s_char buf[1024]; - - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - p = getstarg(player->argp[2], "Amount: ", buf); - if (p == 0 || *p == 0) - return RET_SYN; - fort_amt = atoi(p); - if (fort_amt > land_mob_max) - fort_amt = land_mob_max; - nunits = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner || land.lnd_own == 0) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", - land.lnd_type, ni.cur); - continue; - } - - getland(land.lnd_uid,&land); - if (land.lnd_mobil < 0) - continue; - if (land.lnd_ship >= 0) { - pr("%s is on a ship and can't be fortified\n", - prland(&land)); - continue; - } - - hard_amt = fort_amt; - - /* This is use for things like "fort * -67" which will - use all mobility down to leaving 67 left. */ - if (hard_amt < 0) { - hard_amt = land.lnd_mobil + hard_amt; - if (hard_amt < 0) - continue; - } - - nunits++; - - hard_amt = min(land.lnd_mobil, hard_amt); - - if ((land.lnd_harden + hard_amt) > land_mob_max) - hard_amt = land_mob_max - land.lnd_harden; - - eng = is_engineer(land.lnd_x, land.lnd_y); - - if (eng) - hard_amt = ((float)hard_amt * 1.5); - - if ((land.lnd_harden + hard_amt) > land_mob_max) - hard_amt = land_mob_max - land.lnd_harden; - - /* Ok, set the mobility used */ - mob_used = hard_amt; - - /* Now, if an engineer helped, it's really only 2/3rds of - that */ - if (eng) - mob_used = (int)((float)mob_used / 1.5); - - /* If we increased it, but not much, we gotta take at least 1 - mob point. */ - if (mob_used <= 0 && hard_amt > 0) - mob_used = 1; - - land.lnd_mobil -= mob_used; - if (land.lnd_mobil < 0) - land.lnd_mobil = 0; - - land.lnd_harden += hard_amt; - land.lnd_harden = min(land.lnd_harden, land_mob_max); - - pr("%s hardened to %d\n", prland(&land), - land.lnd_harden); - - putland(land.lnd_uid,&land); + int nunits; + struct nstr_item ni; + struct lndstr land; + int fort_amt, hard_amt, mob_used; + int eng; + s_char *p; + extern int land_mob_max; + s_char buf[1024]; + + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + p = getstarg(player->argp[2], "Amount: ", buf); + if (p == 0 || *p == 0) + return RET_SYN; + fort_amt = atoi(p); + if (fort_amt > land_mob_max) + fort_amt = land_mob_max; + nunits = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + + getland(land.lnd_uid, &land); + if (land.lnd_mobil < 0) + continue; + if (land.lnd_ship >= 0) { + pr("%s is on a ship and can't be fortified\n", prland(&land)); + continue; + } + + hard_amt = fort_amt; + + /* This is use for things like "fort * -67" which will + use all mobility down to leaving 67 left. */ + if (hard_amt < 0) { + hard_amt = land.lnd_mobil + hard_amt; + if (hard_amt < 0) + continue; + } + + nunits++; + + hard_amt = min(land.lnd_mobil, hard_amt); + + if ((land.lnd_harden + hard_amt) > land_mob_max) + hard_amt = land_mob_max - land.lnd_harden; + + eng = is_engineer(land.lnd_x, land.lnd_y); + + if (eng) + hard_amt = ((float)hard_amt * 1.5); + + if ((land.lnd_harden + hard_amt) > land_mob_max) + hard_amt = land_mob_max - land.lnd_harden; + + /* Ok, set the mobility used */ + mob_used = hard_amt; + + /* Now, if an engineer helped, it's really only 2/3rds of + that */ + if (eng) + mob_used = (int)((float)mob_used / 1.5); + + /* If we increased it, but not much, we gotta take at least 1 + mob point. */ + if (mob_used <= 0 && hard_amt > 0) + mob_used = 1; + + land.lnd_mobil -= mob_used; + if (land.lnd_mobil < 0) + land.lnd_mobil = 0; + + land.lnd_harden += hard_amt; + land.lnd_harden = min(land.lnd_harden, land_mob_max); + + pr("%s hardened to %d\n", prland(&land), land.lnd_harden); + + putland(land.lnd_uid, &land); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } int is_engineer(int x, int y) { - struct nstr_item ni; - struct lndstr land; + struct nstr_item ni; + struct lndstr land; - snxtitem_xy(&ni, EF_LAND, x,y); - while(nxtitem(&ni, (s_char *)&land)){ - if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER) - return 1; - } + snxtitem_xy(&ni, EF_LAND, x, y); + while (nxtitem(&ni, (s_char *)&land)) { + if (lchr[(int)land.lnd_type].l_flags & L_ENGINEER) + return 1; + } - return 0; + return 0; } diff --git a/src/lib/commands/fuel.c b/src/lib/commands/fuel.c index 44c24cae8..104332a4b 100644 --- a/src/lib/commands/fuel.c +++ b/src/lib/commands/fuel.c @@ -48,451 +48,460 @@ union item_u { - struct shpstr ship; - struct lndstr land; + struct shpstr ship; + struct lndstr land; }; int fuel(void) { - struct nstr_item ni; - union item_u item, item2; - int type; - struct mchrstr *mp; - struct lchrstr *lcp; - s_char *p; - int fueled; - int land_fuel, ship_fuel; - int oil_amt, pet_amt, fuel_amt, tot_fuel, max_amt; - int move_amt; - float extra; - struct sctstr sect; - struct natstr *natp; - int harbor,sector; - int fuelled_ship = -1; - struct nstr_item tender, ltender; - s_char prompt[128]; - s_char buf[1024]; - - if (opt_FUEL == 0) { - pr ("Option 'FUEL' not enabled\n"); - return RET_SYN; - } - if ((p = getstarg(player->argp[1], "Ship or land unit (s,l)? ", buf)) == 0) - return RET_SYN; - type = ef_byname(p); - if (type == EF_SECTOR) - type = EF_SHIP; - if (type != EF_SHIP && type != EF_LAND){ - pr("Ships or land units only! (s, l)\n" ); - return RET_SYN; - } - sprintf(prompt, "%s(s)? ", ef_nameof(type)); - p = getstarg(player->argp[2], prompt, buf); - if (!snxtitem(&ni, type, p)) - return RET_SYN; - if (isdigit(*p)) - fuelled_ship = atoi(p); - p = getstarg(player->argp[3], "Amount: ", buf); - if (p == 0 || *p == 0) - return RET_SYN; - fuel_amt = atoi(p); - if (fuel_amt <= 0){ - pr("Fuel amount must be positive!\n"); - return RET_FAIL; - } + struct nstr_item ni; + union item_u item, item2; + int type; + struct mchrstr *mp; + struct lchrstr *lcp; + s_char *p; + int fueled; + int land_fuel, ship_fuel; + int oil_amt, pet_amt, fuel_amt, tot_fuel, max_amt; + int move_amt; + float extra; + struct sctstr sect; + struct natstr *natp; + int harbor, sector; + int fuelled_ship = -1; + struct nstr_item tender, ltender; + s_char prompt[128]; + s_char buf[1024]; + + if (opt_FUEL == 0) { + pr("Option 'FUEL' not enabled\n"); + return RET_SYN; + } + if ((p = + getstarg(player->argp[1], "Ship or land unit (s,l)? ", buf)) == 0) + return RET_SYN; + type = ef_byname(p); + if (type == EF_SECTOR) + type = EF_SHIP; + if (type != EF_SHIP && type != EF_LAND) { + pr("Ships or land units only! (s, l)\n"); + return RET_SYN; + } + sprintf(prompt, "%s(s)? ", ef_nameof(type)); + p = getstarg(player->argp[2], prompt, buf); + if (!snxtitem(&ni, type, p)) + return RET_SYN; + if (isdigit(*p)) + fuelled_ship = atoi(p); + p = getstarg(player->argp[3], "Amount: ", buf); + if (p == 0 || *p == 0) + return RET_SYN; + fuel_amt = atoi(p); + if (fuel_amt <= 0) { + pr("Fuel amount must be positive!\n"); + return RET_FAIL; + } + + ni.flags &= ~(EFF_OWNER); + + while (nxtitem(&ni, (s_char *)&item)) { + fueled = 0; + if (type == EF_SHIP) { + if (item.ship.shp_own != player->cnum) { + int rel; + + if (item.ship.shp_uid != fuelled_ship) + continue; + natp = getnatp(player->cnum); + rel = getrel(natp, item.ship.shp_own); + if (rel < FRIENDLY) + continue; + } + if (!getsect(item.ship.shp_x, item.ship.shp_y, §)) + continue; + if (!item.ship.shp_own) + continue; + + if ((sect.sct_type != SCT_HARBR) + && (sect.sct_type != SCT_WATER) + && (sect.sct_type != SCT_BSPAN) && (!opt_BIG_CITY + || sect.sct_type != + SCT_CAPIT)) { + pr("Sector %s is not a harbor, bridge span, or sea.\n", + xyas(item.ship.shp_x, item.ship.shp_y, + item.ship.shp_own)); + continue; + } + + mp = &mchr[(int)item.ship.shp_type]; + + harbor = 0; + if (sect.sct_type == SCT_HARBR + || (opt_BIG_CITY && sect.sct_type == SCT_CAPIT)) { + harbor = 1; + oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); + pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); + if ((oil_amt + pet_amt) == 0) + harbor = 0; + + if (sect.sct_effic < 2) { + pr("The harbor at %s is not 2%% efficient yet.\n", + xyas(item.ship.shp_x, + item.ship.shp_y, player->cnum)); + harbor = 0; + } + if ((sect.sct_own != player->cnum) && sect.sct_own) + harbor = 0; + } + + if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)) { + pr("%s does not use fuel!\n", prship(&item.ship)); + continue; + } + + if (harbor) { + ship_fuel = item.ship.shp_fuel; + oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); + pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); + max_amt = mp->m_fuelc - ship_fuel; + + if (max_amt == 0) { + pr("%s already has a full fuel load.\n", + prship(&item.ship)); + continue; + } + tot_fuel = (oil_amt * 50 + pet_amt * 5); + if (tot_fuel == 0) { + pr("No fuel in the harbor at %s!\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; + } + move_amt = min(tot_fuel, fuel_amt); + move_amt = min(move_amt, max_amt); + + if (move_amt == 0) + continue; + + item.ship.shp_fuel += move_amt; + + fueled = 1; + if ((pet_amt * 5) >= move_amt) { + extra = ((float)move_amt / 5.0) - (move_amt / 5); + if (extra > 0.0) + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)) - 1, 0), + (s_char *)§, EF_SECTOR); + else + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)), 0), + (s_char *)§, EF_SECTOR); + } else { + putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR); + move_amt -= pet_amt * 5; + extra = ((float)move_amt / 50.0) - (move_amt / 50); + putvar(V_OIL, max(oil_amt - (move_amt / 50), 0), + (s_char *)§, EF_SECTOR); + if (extra > 0.0) + putvar(V_OIL, + max((oil_amt - (move_amt / 50)) - 1, 0), + (s_char *)§, EF_SECTOR); + else + putvar(V_OIL, + max((oil_amt - (move_amt / 50)), 0), + (s_char *)§, EF_SECTOR); + } + + /* load plague */ + if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == + PLG_INFECT && getvar(V_PSTAGE, + (s_char *)&item.ship, + EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.ship, + EF_SHIP); + + putsect(§); + putship(item.ship.shp_uid, &item.ship); + } else { /* not in a harbor */ + if (!player->argp[4]) + pr("%s is not in a supplied, efficient harbor\n", + prship(&item.ship)); + if (!snxtitem + (&tender, EF_SHIP, + getstarg(player->argp[4], "Oiler? ", buf))) + continue; + + if (!check_ship_ok(&item.ship)) + continue; + + if (!nxtitem(&tender, (s_char *)&item2)) + continue; + + if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)) { + pr("%s is not an oiler!\n", prship(&item2.ship)); + continue; + } + if (item2.ship.shp_own != player->cnum) { + pr("You don't own that oiler!\n"); + continue; + } - ni.flags &= ~(EFF_OWNER); - - while (nxtitem(&ni, (s_char *)&item)) { - fueled = 0; - if (type == EF_SHIP) { - if (item.ship.shp_own != player->cnum){ - int rel; - - if (item.ship.shp_uid != fuelled_ship) - continue; - natp=getnatp(player->cnum); - rel=getrel(natp,item.ship.shp_own); - if (rel < FRIENDLY) - continue; - } - if (!getsect(item.ship.shp_x, item.ship.shp_y, §)) - continue; - if (!item.ship.shp_own) - continue; - - if ((sect.sct_type != SCT_HARBR) && (sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_BSPAN) && (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)){ - pr("Sector %s is not a harbor, bridge span, or sea.\n", - xyas(item.ship.shp_x, item.ship.shp_y, - item.ship.shp_own)); - continue; - } - - mp = &mchr[(int)item.ship.shp_type]; - - harbor=0; - if (sect.sct_type == SCT_HARBR || (opt_BIG_CITY && sect.sct_type == SCT_CAPIT)){ - harbor=1; - oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); - pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); - if ((oil_amt+pet_amt) == 0) - harbor=0; - - if (sect.sct_effic < 2) { - pr("The harbor at %s is not 2%% efficient yet.\n", - xyas(item.ship.shp_x, - item.ship.shp_y, - player->cnum)); - harbor=0; - } - if ((sect.sct_own != player->cnum) && sect.sct_own) - harbor=0; - } - - if ((mp->m_fuelu == 0) && (item.ship.shp_own == player->cnum)){ - pr("%s does not use fuel!\n", prship(&item.ship)); continue; - } - - if (harbor){ - ship_fuel = item.ship.shp_fuel; - oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); - pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); - max_amt = mp->m_fuelc-ship_fuel; - - if (max_amt == 0){ - pr("%s already has a full fuel load.\n",prship(&item.ship)); - continue; - } - tot_fuel = (oil_amt*50 + pet_amt*5); - if (tot_fuel == 0){ - pr("No fuel in the harbor at %s!\n", - xyas(sect.sct_x,sect.sct_y, - player->cnum)); - continue; - } - move_amt = min(tot_fuel, fuel_amt); - move_amt = min(move_amt, max_amt); - - if (move_amt == 0) - continue; - - item.ship.shp_fuel += move_amt; - - fueled=1; - if ((pet_amt*5) >= move_amt){ - extra = ((float)move_amt/5.0)-(move_amt/5); - if (extra > 0.0) - putvar(V_PETROL, - max((pet_amt-(move_amt/5))-1,0), - (s_char *)§, EF_SECTOR); - else - putvar(V_PETROL, - max((pet_amt-(move_amt/5)),0), - (s_char *)§, EF_SECTOR); - }else{ - putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR); - move_amt -= pet_amt*5; - extra = ((float)move_amt/50.0)-(move_amt/50); - putvar(V_OIL, max(oil_amt-(move_amt/50), 0), - (s_char *)§, EF_SECTOR); - if (extra > 0.0) - putvar(V_OIL, - max((oil_amt-(move_amt/50))-1,0), - (s_char *)§, EF_SECTOR); - else - putvar(V_OIL, - max((oil_amt-(move_amt/50)),0), - (s_char *)§, EF_SECTOR); - } - - /* load plague */ - if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == - PLG_INFECT && getvar(V_PSTAGE, - (s_char *)&item.ship, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, - (s_char *)&item.ship, EF_SHIP); - - putsect(§); - putship(item.ship.shp_uid, &item.ship); - } - else{ /* not in a harbor */ - if (!player->argp[4]) - pr("%s is not in a supplied, efficient harbor\n", prship(&item.ship)); - if (!snxtitem(&tender, EF_SHIP, getstarg(player->argp[4], "Oiler? ", buf))) - continue; - - if (!check_ship_ok(&item.ship)) - continue; - - if (!nxtitem(&tender, (s_char *)&item2)) - continue; - - if (!(mchr[(int)item2.ship.shp_type].m_flags & M_OILER)){ - pr("%s is not an oiler!\n", - prship(&item2.ship)); - continue; - } - if (item2.ship.shp_own != player->cnum){ - pr("You don't own that oiler!\n"); - continue; - } - - if ((item2.ship.shp_x != item.ship.shp_x) || - (item2.ship.shp_y != item.ship.shp_y)){ - pr("Not in the same sector!\n"); - continue; - } - ship_fuel = item.ship.shp_fuel; - oil_amt = getvar(V_OIL, (s_char *)&item2.ship, EF_SHIP); - pet_amt = getvar(V_PETROL, (s_char *)&item2.ship, EF_SHIP); - max_amt = mp->m_fuelc-ship_fuel; - - if (max_amt == 0){ - pr("%s already has a full fuel load.\n", prship(&item.ship)); - continue; - } - tot_fuel = oil_amt*50 + pet_amt*5; - move_amt = min(tot_fuel, fuel_amt); - move_amt = min(move_amt, max_amt); - - if (move_amt == 0) - continue; - - item.ship.shp_fuel += move_amt; - - fueled=1; - if ((pet_amt*5) >= move_amt){ - extra = ((float)move_amt/5.0)-(move_amt/5); - if (extra > 0.0) - putvar(V_PETROL, - max((pet_amt-(move_amt/5))-1,0), - (s_char *)&item2.ship, EF_SHIP); - else - putvar(V_PETROL, - max((pet_amt-(move_amt/5)),0), - (s_char *)&item2.ship, EF_SHIP); - }else{ - putvar(V_PETROL, 0, (s_char *)&item2.ship, EF_SHIP); - move_amt -= pet_amt*5; - extra = ((float)move_amt/50.0)-(move_amt/50); - putvar(V_OIL, max(oil_amt-(move_amt/50), 0), - (s_char *)&item2.ship, EF_SHIP); - if (extra > 0.0) - putvar(V_OIL, - max((oil_amt-(move_amt/50))-1,0), - (s_char *)&item2.ship, EF_SHIP); - else - putvar(V_OIL, - max((oil_amt-(move_amt/50)),0), - (s_char *)&item2.ship, EF_SHIP); - } - - /* load plague */ - if (getvar(V_PSTAGE, (s_char *)&item2.ship, EF_SHIP) == - PLG_INFECT && getvar(V_PSTAGE, - (s_char *)&item.ship, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, - (s_char *)&item.ship, EF_SHIP); - - putship(item.ship.shp_uid, &item.ship); - /* quick hack -KHS */ - if (item.ship.shp_uid == item2.ship.shp_uid) - item2.ship.shp_fuel = item.ship.shp_fuel; - putship(item2.ship.shp_uid, &item2.ship); - } - pr("%s",prship(&item.ship)); + if ((item2.ship.shp_x != item.ship.shp_x) || + (item2.ship.shp_y != item.ship.shp_y)) { + pr("Not in the same sector!\n"); + continue; + } + ship_fuel = item.ship.shp_fuel; + oil_amt = getvar(V_OIL, (s_char *)&item2.ship, EF_SHIP); + pet_amt = getvar(V_PETROL, (s_char *)&item2.ship, EF_SHIP); + max_amt = mp->m_fuelc - ship_fuel; + + if (max_amt == 0) { + pr("%s already has a full fuel load.\n", + prship(&item.ship)); + continue; } - else { - if (item.land.lnd_own != player->cnum) - continue; - - if (!getsect(item.land.lnd_x, item.land.lnd_y, §)) - continue; - - if (!player->owner) - continue; - - lcp = &lchr[(int)item.land.lnd_type]; - - sector=1; - oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); - pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); - - if ((oil_amt+pet_amt) == 0) - sector=0; - - if ((item.land.lnd_fuelu == 0) && (item.land.lnd_own == player->cnum)){ - pr("%s does not use fuel!\n", prland(&item.land)); - continue; - } - - if (sector){ - land_fuel = item.land.lnd_fuel; - oil_amt = getvar(V_OIL, (s_char *)§, - EF_SECTOR); - pet_amt = getvar(V_PETROL, (s_char *)§, - EF_SECTOR); - max_amt = item.land.lnd_fuelc-land_fuel; - - if (max_amt == 0){ - pr("%s already has a full fuel load.\n", prland(&item.land)); - continue; - } - tot_fuel = (oil_amt*50 + pet_amt*5); - if (tot_fuel == 0){ - pr("No fuel in the sector at %s!\n", - xyas(sect.sct_x,sect.sct_y, - player->cnum)); - continue; - } - move_amt = min(tot_fuel, fuel_amt); - move_amt = min(move_amt, max_amt); - - if (move_amt == 0) - continue; - - item.land.lnd_fuel += move_amt; - - fueled=1; - if ((pet_amt*5) >= move_amt){ - extra = ((float)move_amt/5.0)-(move_amt/5); - if (extra > 0.0) - putvar(V_PETROL, - max((pet_amt-(move_amt/5))-1,0), - (s_char *)§, EF_SECTOR); - else - putvar(V_PETROL, - max((pet_amt-(move_amt/5)),0), - (s_char *)§, EF_SECTOR); - }else{ - putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR); - move_amt -= pet_amt*5; - extra = ((float)move_amt/50.0)-(move_amt/50); - putvar(V_OIL, max(oil_amt-(move_amt/50), 0), - (s_char *)§, EF_SECTOR); - if (extra > 0.0) - putvar(V_OIL, - max((oil_amt-(move_amt/50))-1,0), - (s_char *)§, EF_SECTOR); - else - putvar(V_OIL, - max((oil_amt-(move_amt/50)),0), - (s_char *)§, EF_SECTOR); - } - - /* load plague */ - if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == - PLG_INFECT && getvar(V_PSTAGE, - (s_char *)&item.land, EF_LAND) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, - (s_char *)&item.land, EF_LAND); - - putsect(§); - putland(item.land.lnd_uid, &item.land); - } - else{ /* not in a sector */ - if (!player->argp[4]) - pr("%s is not in a supplied sector\n", - prland(&item.land)); - if (!snxtitem(<ender, EF_LAND, - getstarg(player->argp[4], "Supply unit? ", buf))) - continue; - - if (!check_land_ok(&item.land)) - continue; - - if (!nxtitem(<ender, (s_char *)&item2)) - continue; - - if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)){ - pr("%s is not a supply unit!\n", - prland(&item2.land)); - continue; - } - if (item2.land.lnd_own != player->cnum){ - pr("You don't own that unit!\n"); - continue; - } - - if ((item2.land.lnd_x != item.land.lnd_x) || - (item2.land.lnd_y != item.land.lnd_y)){ - pr("Not in the same sector!\n"); - continue; - } - land_fuel = item.land.lnd_fuel; - oil_amt = getvar(V_OIL, (s_char *)&item2.land, EF_LAND); - pet_amt = getvar(V_PETROL, (s_char *)&item2.land, EF_LAND); - max_amt = item.land.lnd_fuelc-land_fuel; - - if (max_amt == 0){ - pr("%s already has a full fuel load.\n", prland(&item.land)); - continue; - } - tot_fuel = oil_amt*50 + pet_amt*5; - move_amt = min(tot_fuel, fuel_amt); - move_amt = min(move_amt, max_amt); - - if (move_amt == 0) - continue; - - item.land.lnd_fuel += move_amt; - - fueled=1; - if ((pet_amt*5) >= move_amt){ - extra = ((float)move_amt/5.0)-(move_amt/5); - if (extra > 0.0) - putvar(V_PETROL, - max((pet_amt-(move_amt/5))-1,0), - (s_char *)&item2.land, EF_LAND); - else - putvar(V_PETROL, - max((pet_amt-(move_amt/5)),0), - (s_char *)&item2.land, EF_LAND); - }else{ - putvar(V_PETROL, 0, (s_char *)&item2.land, EF_LAND); - move_amt -= pet_amt*5; - extra = ((float)move_amt/50.0)-(move_amt/50); - putvar(V_OIL, max(oil_amt-(move_amt/50), 0), - (s_char *)&item2.land, EF_LAND); - if (extra > 0.0) - putvar(V_OIL, - max((oil_amt-(move_amt/50))-1,0), - (s_char *)&item2.land, EF_LAND); - else - putvar(V_OIL, - max((oil_amt-(move_amt/50)),0), - (s_char *)&item2.land, EF_LAND); - } - - /* load plague */ - if (getvar(V_PSTAGE, (s_char *)&item2.land, EF_LAND) == - PLG_INFECT && getvar(V_PSTAGE, - (s_char *)&item.land, EF_LAND) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, - (s_char *)&item.land, EF_LAND); - - putland(item.land.lnd_uid, &item.land); - /* quick hack -KHS */ - if (item2.land.lnd_uid == item.land.lnd_uid) - item2.land.lnd_fuel = item.land.lnd_fuel; - putland(item2.land.lnd_uid, &item2.land); - } - pr("%s",prland(&item.land)); + tot_fuel = oil_amt * 50 + pet_amt * 5; + move_amt = min(tot_fuel, fuel_amt); + move_amt = min(move_amt, max_amt); + + if (move_amt == 0) + continue; + + item.ship.shp_fuel += move_amt; + + fueled = 1; + if ((pet_amt * 5) >= move_amt) { + extra = ((float)move_amt / 5.0) - (move_amt / 5); + if (extra > 0.0) + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)) - 1, 0), + (s_char *)&item2.ship, EF_SHIP); + else + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)), 0), + (s_char *)&item2.ship, EF_SHIP); + } else { + putvar(V_PETROL, 0, (s_char *)&item2.ship, EF_SHIP); + move_amt -= pet_amt * 5; + extra = ((float)move_amt / 50.0) - (move_amt / 50); + putvar(V_OIL, max(oil_amt - (move_amt / 50), 0), + (s_char *)&item2.ship, EF_SHIP); + if (extra > 0.0) + putvar(V_OIL, + max((oil_amt - (move_amt / 50)) - 1, 0), + (s_char *)&item2.ship, EF_SHIP); + else + putvar(V_OIL, + max((oil_amt - (move_amt / 50)), 0), + (s_char *)&item2.ship, EF_SHIP); } - if (fueled){ - pr(" takes on %d fuel in %s\n", - move_amt, - xyas(item.ship.shp_x, item.ship.shp_y , player->cnum)); - if (player->cnum != item.ship.shp_own) - wu(0, item.ship.shp_own, - "%s takes on %d fuel in %s courtesy of %s\n", - prship(&item.ship), - move_amt, - xyas(item.ship.shp_x, item.ship.shp_y , - item.ship.shp_own), - cname(player->cnum)); + + /* load plague */ + if (getvar(V_PSTAGE, (s_char *)&item2.ship, EF_SHIP) == + PLG_INFECT && getvar(V_PSTAGE, + (s_char *)&item.ship, + EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.ship, + EF_SHIP); + + putship(item.ship.shp_uid, &item.ship); + /* quick hack -KHS */ + if (item.ship.shp_uid == item2.ship.shp_uid) + item2.ship.shp_fuel = item.ship.shp_fuel; + putship(item2.ship.shp_uid, &item2.ship); + } + pr("%s", prship(&item.ship)); + } else { + if (item.land.lnd_own != player->cnum) + continue; + + if (!getsect(item.land.lnd_x, item.land.lnd_y, §)) + continue; + + if (!player->owner) + continue; + + lcp = &lchr[(int)item.land.lnd_type]; + + sector = 1; + oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); + pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); + + if ((oil_amt + pet_amt) == 0) + sector = 0; + + if ((item.land.lnd_fuelu == 0) + && (item.land.lnd_own == player->cnum)) { + pr("%s does not use fuel!\n", prland(&item.land)); + continue; + } + + if (sector) { + land_fuel = item.land.lnd_fuel; + oil_amt = getvar(V_OIL, (s_char *)§, EF_SECTOR); + pet_amt = getvar(V_PETROL, (s_char *)§, EF_SECTOR); + max_amt = item.land.lnd_fuelc - land_fuel; + + if (max_amt == 0) { + pr("%s already has a full fuel load.\n", + prland(&item.land)); + continue; } + tot_fuel = (oil_amt * 50 + pet_amt * 5); + if (tot_fuel == 0) { + pr("No fuel in the sector at %s!\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + continue; + } + move_amt = min(tot_fuel, fuel_amt); + move_amt = min(move_amt, max_amt); + + if (move_amt == 0) + continue; + + item.land.lnd_fuel += move_amt; + + fueled = 1; + if ((pet_amt * 5) >= move_amt) { + extra = ((float)move_amt / 5.0) - (move_amt / 5); + if (extra > 0.0) + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)) - 1, 0), + (s_char *)§, EF_SECTOR); + else + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)), 0), + (s_char *)§, EF_SECTOR); + } else { + putvar(V_PETROL, 0, (s_char *)§, EF_SECTOR); + move_amt -= pet_amt * 5; + extra = ((float)move_amt / 50.0) - (move_amt / 50); + putvar(V_OIL, max(oil_amt - (move_amt / 50), 0), + (s_char *)§, EF_SECTOR); + if (extra > 0.0) + putvar(V_OIL, + max((oil_amt - (move_amt / 50)) - 1, 0), + (s_char *)§, EF_SECTOR); + else + putvar(V_OIL, + max((oil_amt - (move_amt / 50)), 0), + (s_char *)§, EF_SECTOR); + } + + /* load plague */ + if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == + PLG_INFECT && getvar(V_PSTAGE, + (s_char *)&item.land, + EF_LAND) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.land, + EF_LAND); + + putsect(§); + putland(item.land.lnd_uid, &item.land); + } else { /* not in a sector */ + if (!player->argp[4]) + pr("%s is not in a supplied sector\n", + prland(&item.land)); + if (!snxtitem(<ender, EF_LAND, + getstarg(player->argp[4], "Supply unit? ", + buf))) + continue; + + if (!check_land_ok(&item.land)) + continue; + + if (!nxtitem(<ender, (s_char *)&item2)) + continue; + + if (!(lchr[(int)item2.land.lnd_type].l_flags & L_SUPPLY)) { + pr("%s is not a supply unit!\n", prland(&item2.land)); + continue; + } + if (item2.land.lnd_own != player->cnum) { + pr("You don't own that unit!\n"); + continue; + } + + if ((item2.land.lnd_x != item.land.lnd_x) || + (item2.land.lnd_y != item.land.lnd_y)) { + pr("Not in the same sector!\n"); + continue; + } + land_fuel = item.land.lnd_fuel; + oil_amt = getvar(V_OIL, (s_char *)&item2.land, EF_LAND); + pet_amt = getvar(V_PETROL, (s_char *)&item2.land, EF_LAND); + max_amt = item.land.lnd_fuelc - land_fuel; + + if (max_amt == 0) { + pr("%s already has a full fuel load.\n", + prland(&item.land)); + continue; + } + tot_fuel = oil_amt * 50 + pet_amt * 5; + move_amt = min(tot_fuel, fuel_amt); + move_amt = min(move_amt, max_amt); + + if (move_amt == 0) + continue; + + item.land.lnd_fuel += move_amt; + + fueled = 1; + if ((pet_amt * 5) >= move_amt) { + extra = ((float)move_amt / 5.0) - (move_amt / 5); + if (extra > 0.0) + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)) - 1, 0), + (s_char *)&item2.land, EF_LAND); + else + putvar(V_PETROL, + max((pet_amt - (move_amt / 5)), 0), + (s_char *)&item2.land, EF_LAND); + } else { + putvar(V_PETROL, 0, (s_char *)&item2.land, EF_LAND); + move_amt -= pet_amt * 5; + extra = ((float)move_amt / 50.0) - (move_amt / 50); + putvar(V_OIL, max(oil_amt - (move_amt / 50), 0), + (s_char *)&item2.land, EF_LAND); + if (extra > 0.0) + putvar(V_OIL, + max((oil_amt - (move_amt / 50)) - 1, 0), + (s_char *)&item2.land, EF_LAND); + else + putvar(V_OIL, + max((oil_amt - (move_amt / 50)), 0), + (s_char *)&item2.land, EF_LAND); + } + + /* load plague */ + if (getvar(V_PSTAGE, (s_char *)&item2.land, EF_LAND) == + PLG_INFECT && getvar(V_PSTAGE, + (s_char *)&item.land, + EF_LAND) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&item.land, + EF_LAND); + + putland(item.land.lnd_uid, &item.land); + /* quick hack -KHS */ + if (item2.land.lnd_uid == item.land.lnd_uid) + item2.land.lnd_fuel = item.land.lnd_fuel; + putland(item2.land.lnd_uid, &item2.land); + } + pr("%s", prland(&item.land)); + } + if (fueled) { + pr(" takes on %d fuel in %s\n", + move_amt, + xyas(item.ship.shp_x, item.ship.shp_y, player->cnum)); + if (player->cnum != item.ship.shp_own) + wu(0, item.ship.shp_own, + "%s takes on %d fuel in %s courtesy of %s\n", + prship(&item.ship), + move_amt, + xyas(item.ship.shp_x, item.ship.shp_y, + item.ship.shp_own), cname(player->cnum)); } - return RET_OK; + } + return RET_OK; } diff --git a/src/lib/commands/give.c b/src/lib/commands/give.c index 0c65e4a5a..5b95262e8 100644 --- a/src/lib/commands/give.c +++ b/src/lib/commands/give.c @@ -52,54 +52,54 @@ int give(void) { - struct sctstr sect; - int amt; - struct ichrstr *ip; - int m, n; - s_char *p; - struct nstr_sect nstr; - s_char buf[1024]; + struct sctstr sect; + int amt; + struct ichrstr *ip; + int m, n; + s_char *p; + struct nstr_sect nstr; + s_char buf[1024]; - if (!(ip = whatitem(player->argp[1], "which commodity? "))) - return RET_SYN; - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr, §) > 0) { - p = getstarg(player->argp[3], "how much : ", buf); - if (p == 0 || *p == '\0') - return RET_SYN; - if ((amt = atoi(p)) == 0) - return RET_SYN; - n = getvar(ip->i_vtype, (s_char *)§, EF_SECTOR); - if (amt < 0 && -amt > n) { - m = 0; - } else if (amt > 0 && amt+n > 9990) { - m = 9990; - } else - m = n + amt; - if (putvar(ip->i_vtype, m, (s_char *)§, EF_SECTOR) < 0) { - pr("No room to store %s in %s\n", ip->i_name, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_FAIL; - } - putsect(§); - if (sect.sct_own != 0 && m != n) { - if (m > n) { - if (opt_GODNEWS) - nreport(player->cnum, N_GIFT, sect.sct_own, 1); - wu(player->cnum, sect.sct_own, "%s gave you %d %s in %s\n", - cname(player->cnum), m-n, ip->i_name, - xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - } else { - if (opt_GODNEWS) - nreport(sect.sct_own, N_TAKE, player->cnum, 1); - wu(player->cnum, sect.sct_own, "%s stole %d %s from %s\n", - cname(player->cnum), n-m, ip->i_name, - xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - } - } - pr("%d %s in %s\n", m, ip->i_name, - xyas(sect.sct_x, sect.sct_y, player->cnum)); + if (!(ip = whatitem(player->argp[1], "which commodity? "))) + return RET_SYN; + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + p = getstarg(player->argp[3], "how much : ", buf); + if (p == 0 || *p == '\0') + return RET_SYN; + if ((amt = atoi(p)) == 0) + return RET_SYN; + n = getvar(ip->i_vtype, (s_char *)§, EF_SECTOR); + if (amt < 0 && -amt > n) { + m = 0; + } else if (amt > 0 && amt + n > 9990) { + m = 9990; + } else + m = n + amt; + if (putvar(ip->i_vtype, m, (s_char *)§, EF_SECTOR) < 0) { + pr("No room to store %s in %s\n", ip->i_name, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_FAIL; } - return RET_OK; + putsect(§); + if (sect.sct_own != 0 && m != n) { + if (m > n) { + if (opt_GODNEWS) + nreport(player->cnum, N_GIFT, sect.sct_own, 1); + wu(player->cnum, sect.sct_own, "%s gave you %d %s in %s\n", + cname(player->cnum), m - n, ip->i_name, + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + } else { + if (opt_GODNEWS) + nreport(sect.sct_own, N_TAKE, player->cnum, 1); + wu(player->cnum, sect.sct_own, "%s stole %d %s from %s\n", + cname(player->cnum), n - m, ip->i_name, + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + } + } + pr("%d %s in %s\n", m, ip->i_name, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + } + return RET_OK; } diff --git a/src/lib/commands/grin.c b/src/lib/commands/grin.c index d437578d2..eb7b293c1 100644 --- a/src/lib/commands/grin.c +++ b/src/lib/commands/grin.c @@ -46,51 +46,52 @@ int grin(void) { - struct nstr_sect nstr; - int vec[I_MAX+1]; - struct sctstr sect; - s_char *p; - int i,n,qty; - int avail; - s_char buf[1024]; + struct nstr_sect nstr; + int vec[I_MAX + 1]; + struct sctstr sect; + s_char *p; + int i, n, qty; + int avail; + s_char buf[1024]; - if ((p = getstarg(player->argp[1], "Sectors? ", buf)) == 0) - return RET_SYN; - if (!snxtsct(&nstr, p)) - return RET_SYN; - if ((p = getstarg(player->argp[2], "amount : ", buf)) == 0 || *p == 0) - return RET_SYN; - qty = atoi(p); - if(qty < 0) - return RET_SYN; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; + if ((p = getstarg(player->argp[1], "Sectors? ", buf)) == 0) + return RET_SYN; + if (!snxtsct(&nstr, p)) + return RET_SYN; + if ((p = getstarg(player->argp[2], "amount : ", buf)) == 0 || *p == 0) + return RET_SYN; + qty = atoi(p); + if (qty < 0) + return RET_SYN; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; /* getsect(item.sct_x, item.sct_y, §); */ - if (sect.sct_effic < 60 || sect.sct_own != player->cnum) - continue; - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - n = (vec[I_BAR] >= qty) ? qty : vec[I_BAR]; - avail = n * 5.0; - if(avail > sect.sct_avail) { - n = sect.sct_avail / 5; - avail = sect.sct_avail; - if(n == 0) - continue; - } - if (n) { - vec[I_BAR] -= n; - pr("%d bars ground up in %s\n", n, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - for (i = 0; i < pchr[P_BAR].p_nv; i++) { - vec[unitem(pchr[P_BAR].p_vtype[i])] += (int)((n * - pchr[P_BAR].p_vamt[i]) * 0.8); - } - putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - sect.sct_avail -= avail; - putsect(§); - } + if (sect.sct_effic < 60 || sect.sct_own != player->cnum) + continue; + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + n = (vec[I_BAR] >= qty) ? qty : vec[I_BAR]; + avail = n * 5.0; + if (avail > sect.sct_avail) { + n = sect.sct_avail / 5; + avail = sect.sct_avail; + if (n == 0) + continue; } - return RET_OK; + if (n) { + vec[I_BAR] -= n; + pr("%d bars ground up in %s\n", n, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + for (i = 0; i < pchr[P_BAR].p_nv; i++) { + vec[unitem(pchr[P_BAR].p_vtype[i])] += (int)((n * + pchr[P_BAR]. + p_vamt[i]) * + 0.8); + } + putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + sect.sct_avail -= avail; + putsect(§); + } + } + return RET_OK; } - diff --git a/src/lib/commands/hard.c b/src/lib/commands/hard.c index 48a069f05..fd9a4c4f7 100644 --- a/src/lib/commands/hard.c +++ b/src/lib/commands/hard.c @@ -51,71 +51,70 @@ int hard(void) { - struct plchrstr *pcp; - struct plnstr pln; - int level; - s_char *p; - int hcm; - int n; - struct nstr_item ni; - struct sctstr sect; - s_char buf[1024]; - long cash; - struct natstr *natp; + struct plchrstr *pcp; + struct plnstr pln; + int level; + s_char *p; + int hcm; + int n; + struct nstr_item ni; + struct sctstr sect; + s_char buf[1024]; + long cash; + struct natstr *natp; - if (!snxtitem(&ni, EF_PLANE, player->argp[1])) - return RET_SYN; - if ((p = getstarg(player->argp[2], "Increase by? ", buf)) == 0 || *p == 0) - return RET_SYN; - level = atoi(p); - if (level < 0) - return RET_SYN; - natp = getnatp(player->cnum); - cash = natp->nat_money; - while (nxtitem(&ni, (s_char *)&pln)) { - if (!player->owner) - continue; - pcp = &plchr[(int)pln.pln_type]; - if ((pcp->pl_flags & P_M) == 0) { - pr("%s isn't a missile!\n", prplane(&pln)); - continue; - } - if (pln.pln_ship >= 0) /* can't harden ssbns ... */ - continue; - n = level; - if (level + pln.pln_harden > 127) - n = 127 - pln.pln_harden; - if (n <= 0) { - pr("%s is already completely hardened!\n", prplane(&pln)); - continue; - } - if (!getsect(pln.pln_x, pln.pln_y, §)) - continue; - if (sect.sct_own != player->cnum) { - pr("%s: you don't own %s!\n", - prplane(&pln), - xyas(pln.pln_x, pln.pln_y, player->cnum)); - continue; - } - hcm = getvar(V_HCM, (s_char *)§, EF_SECTOR); - if (hcm == 0) { - pr("No hcm in %s\n", - xyas(pln.pln_x, pln.pln_y, player->cnum)); - continue; - } - if (player->dolcost + 5.0 * n > cash) { - pr("You don't have enough money to harden %s!\n", - prplane(&pln)); - continue; - } - if (hcm <= n) - n = hcm; - pln.pln_harden += n; - player->dolcost += (5.0 * n); - putplane(pln.pln_uid, &pln); - putvar(V_HCM, hcm - n, (s_char *)§, EF_SECTOR); - putsect(§); - pr("%s hardened to %d\n", prplane(&pln), pln.pln_harden); + if (!snxtitem(&ni, EF_PLANE, player->argp[1])) + return RET_SYN; + if ((p = getstarg(player->argp[2], "Increase by? ", buf)) == 0 + || *p == 0) + return RET_SYN; + level = atoi(p); + if (level < 0) + return RET_SYN; + natp = getnatp(player->cnum); + cash = natp->nat_money; + while (nxtitem(&ni, (s_char *)&pln)) { + if (!player->owner) + continue; + pcp = &plchr[(int)pln.pln_type]; + if ((pcp->pl_flags & P_M) == 0) { + pr("%s isn't a missile!\n", prplane(&pln)); + continue; } - return RET_OK; + if (pln.pln_ship >= 0) /* can't harden ssbns ... */ + continue; + n = level; + if (level + pln.pln_harden > 127) + n = 127 - pln.pln_harden; + if (n <= 0) { + pr("%s is already completely hardened!\n", prplane(&pln)); + continue; + } + if (!getsect(pln.pln_x, pln.pln_y, §)) + continue; + if (sect.sct_own != player->cnum) { + pr("%s: you don't own %s!\n", + prplane(&pln), xyas(pln.pln_x, pln.pln_y, player->cnum)); + continue; + } + hcm = getvar(V_HCM, (s_char *)§, EF_SECTOR); + if (hcm == 0) { + pr("No hcm in %s\n", xyas(pln.pln_x, pln.pln_y, player->cnum)); + continue; + } + if (player->dolcost + 5.0 * n > cash) { + pr("You don't have enough money to harden %s!\n", + prplane(&pln)); + continue; + } + if (hcm <= n) + n = hcm; + pln.pln_harden += n; + player->dolcost += (5.0 * n); + putplane(pln.pln_uid, &pln); + putvar(V_HCM, hcm - n, (s_char *)§, EF_SECTOR); + putsect(§); + pr("%s hardened to %d\n", prplane(&pln), pln.pln_harden); + } + return RET_OK; } diff --git a/src/lib/commands/head.c b/src/lib/commands/head.c index b84a13fab..bea9fd0cb 100644 --- a/src/lib/commands/head.c +++ b/src/lib/commands/head.c @@ -40,180 +40,182 @@ #include "nsc.h" #include "commands.h" -struct histstr { - int h_past; - int h_recent; +struct histstr { + int h_past; + int h_recent; }; -static s_char *head_meanwhile(int val); -static s_char *head_describe(struct histstr *hp, int what); -static int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno); -static int head_findscoop(struct histstr (*hist)[MAXNOC], register natid maxcnum, natid *ano, natid *vno); +static s_char *head_meanwhile(int val); +static s_char *head_describe(struct histstr *hp, int what); +static int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, + natid vno); +static int head_findscoop(struct histstr (*hist)[MAXNOC], + register natid maxcnum, natid *ano, natid *vno); int head(void) { - register int i; - register struct histstr *hp; - register natid maxcnum; - time_t now; - int severity; - int scoop; - time_t news_per; - time_t news_age; - struct histstr hist[MAXNOC][MAXNOC]; - struct natstr *natp; - struct nwsstr news; - natid actor; - natid victim; - struct nstr_item nstr; - int n; + register int i; + register struct histstr *hp; + register natid maxcnum; + time_t now; + int severity; + int scoop; + time_t news_per; + time_t news_age; + struct histstr hist[MAXNOC][MAXNOC]; + struct natstr *natp; + struct nwsstr news; + natid actor; + natid victim; + struct nstr_item nstr; + int n; - (void) time(&now); - natp = getnatp(player->cnum); - if (player->argp[1] != 0 && *player->argp[1] != 0) { - news_per = days(atoi(player->argp[1])); - if (news_per > days(3)) - news_per = days(3); - } else - /* replaced the following line with the one under it to - * fix headlines which never change. - * 3/3/90 bailey@math-cs.kent.edu - */ + (void)time(&now); + natp = getnatp(player->cnum); + if (player->argp[1] != 0 && *player->argp[1] != 0) { + news_per = days(atoi(player->argp[1])); + if (news_per > days(3)) + news_per = days(3); + } else + /* replaced the following line with the one under it to + * fix headlines which never change. + * 3/3/90 bailey@math-cs.kent.edu + */ /* news_per = natp->nat_newstim; */ - news_per = now - natp->nat_newstim; - pr("\n -=[ EMPIRE NEWS ]=-\n"); - pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n"); - pr("! \"All the news that fits, we print.\" !\n"); - pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n"); - pr(" %s", ctime(&now)); - pr("\n"); - bzero((s_char *)hist, sizeof (hist)); - snxtitem_all(&nstr, EF_NEWS); - maxcnum = 0; - while (nxtitem(&nstr, (s_char *)&news)) { - news_age = now - news.nws_when; - if (news_age > news_per) - continue; - if (news.nws_ano == news.nws_vno) - continue; - if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0) - continue; - if (news_age > (news_per / 2)) - hist[news.nws_ano][news.nws_vno].h_past += i; - else - hist[news.nws_ano][news.nws_vno].h_recent += i; - if (maxcnum < news.nws_ano) - maxcnum = news.nws_ano; - if (maxcnum < news.nws_vno) - maxcnum = news.nws_vno; - } - for (n=0; n<5; n++) { - if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim))<10) - break; - severity = head_printscoop(hist, actor, victim); - hp = &hist[actor][victim]; - severity = hp->h_recent - hp->h_past; - if (severity <= -scoop/2 || severity >= scoop/2) { - pr("\t%s\n", head_meanwhile(severity)); - (void) head_printscoop(hist, victim, actor); - } + news_per = now - natp->nat_newstim; + pr("\n -=[ EMPIRE NEWS ]=-\n"); + pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n"); + pr("! \"All the news that fits, we print.\" !\n"); + pr("::::::::::::::::::::::::::::::::::::::::::::::::::\n"); + pr(" %s", ctime(&now)); + pr("\n"); + bzero((s_char *)hist, sizeof(hist)); + snxtitem_all(&nstr, EF_NEWS); + maxcnum = 0; + while (nxtitem(&nstr, (s_char *)&news)) { + news_age = now - news.nws_when; + if (news_age > news_per) + continue; + if (news.nws_ano == news.nws_vno) + continue; + if ((i = rpt[(int)news.nws_vrb].r_good_will) == 0) + continue; + if (news_age > (news_per / 2)) + hist[news.nws_ano][news.nws_vno].h_past += i; + else + hist[news.nws_ano][news.nws_vno].h_recent += i; + if (maxcnum < news.nws_ano) + maxcnum = news.nws_ano; + if (maxcnum < news.nws_vno) + maxcnum = news.nws_vno; + } + for (n = 0; n < 5; n++) { + if ((scoop = head_findscoop(hist, maxcnum, &actor, &victim)) < 10) + break; + severity = head_printscoop(hist, actor, victim); + hp = &hist[actor][victim]; + severity = hp->h_recent - hp->h_past; + if (severity <= -scoop / 2 || severity >= scoop / 2) { + pr("\t%s\n", head_meanwhile(severity)); + (void)head_printscoop(hist, victim, actor); } - if (n <= 1) - pr("\nRelative calm prevails.\n"); - return RET_OK; + } + if (n <= 1) + pr("\nRelative calm prevails.\n"); + return RET_OK; } static -int + int head_printscoop(struct histstr (*hist)[MAXNOC], natid ano, natid vno) { - register struct histstr *hp; - int severity; + register struct histstr *hp; + int severity; - hp = &hist[ano][vno]; - severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0; - severity += (hp->h_past >= 0) ? 2 : 0; - severity += (hp->h_recent >= 0) ? 4 : 0; - pr(head_describe(hp, severity), cname(ano), cname(vno)); - pr("\n"); - hp->h_past = 0; - hp->h_recent = 0; - return severity; + hp = &hist[ano][vno]; + severity = abs(hp->h_past) > abs(hp->h_recent) ? 1 : 0; + severity += (hp->h_past >= 0) ? 2 : 0; + severity += (hp->h_recent >= 0) ? 4 : 0; + pr(head_describe(hp, severity), cname(ano), cname(vno)); + pr("\n"); + hp->h_past = 0; + hp->h_recent = 0; + return severity; } static s_char * head_meanwhile(int val) { - switch (val & 03) { - case 0: - return "Meanwhile"; - case 1: - return "On the other hand"; - case 2: - return "At the same time"; - case 3: - return "Although"; - } - /*NOTREACHED*/ - return ""; + switch (val & 03) { + case 0: + return "Meanwhile"; + case 1: + return "On the other hand"; + case 2: + return "At the same time"; + case 3: + return "Although"; + } + /*NOTREACHED*/ + return ""; } static s_char * head_describe(struct histstr *hp, int what) { - s_char *cp; + s_char *cp; - cp = 0; - switch (what) { - case 0: - if (hp->h_recent > hp->h_past/2) - cp = "Bad relations between %s and %s worsen!"; - else - cp = "Carnage wrought by %s on %s continues unabated!"; - break; - case 1: - if (hp->h_recent < -16) - cp = "%s agression against %s has lessened slightly"; - else - cp = "Peace talks may occur between %s & %s"; - break; - case 2: - if (hp->h_recent < -16) { - if (hp->h_past > 0) - cp = " ! WAR ! Reversal of prior %s -- %s relations"; - else if (hp->h_recent >= -25) - cp = "VIOLENCE ERUPTS! -- %s wages war on %s"; - else - cp = "%s wreaks havoc on %s!"; - } else - cp = "Breakdown in communication between %s & %s"; - break; - case 3: - cp = "FLASH! %s turns on former ally, %s!"; - break; - case 4: - cp = "%s \"makes friends\" with %s"; - break; - case 5: - if (hp->h_past >= -25) - cp = "%s seems to have forgotten earlier disagreement with %s"; - else - cp = "Tensions ease as %s attacks on %s seem at an end"; - break; - case 6: - cp = "%s good deeds further growing alliance with %s"; - break; - case 7: - if (hp->h_recent - hp->h_past < 12) - cp = "Honeymoon appears to be over between %s & %s"; - else - cp = "Friendly relations between %s & %s have cooled"; - break; - } - return cp; + cp = 0; + switch (what) { + case 0: + if (hp->h_recent > hp->h_past / 2) + cp = "Bad relations between %s and %s worsen!"; + else + cp = "Carnage wrought by %s on %s continues unabated!"; + break; + case 1: + if (hp->h_recent < -16) + cp = "%s agression against %s has lessened slightly"; + else + cp = "Peace talks may occur between %s & %s"; + break; + case 2: + if (hp->h_recent < -16) { + if (hp->h_past > 0) + cp = " ! WAR ! Reversal of prior %s -- %s relations"; + else if (hp->h_recent >= -25) + cp = "VIOLENCE ERUPTS! -- %s wages war on %s"; + else + cp = "%s wreaks havoc on %s!"; + } else + cp = "Breakdown in communication between %s & %s"; + break; + case 3: + cp = "FLASH! %s turns on former ally, %s!"; + break; + case 4: + cp = "%s \"makes friends\" with %s"; + break; + case 5: + if (hp->h_past >= -25) + cp = "%s seems to have forgotten earlier disagreement with %s"; + else + cp = "Tensions ease as %s attacks on %s seem at an end"; + break; + case 6: + cp = "%s good deeds further growing alliance with %s"; + break; + case 7: + if (hp->h_recent - hp->h_past < 12) + cp = "Honeymoon appears to be over between %s & %s"; + else + cp = "Friendly relations between %s & %s have cooled"; + break; + } + return cp; } /* @@ -221,38 +223,39 @@ head_describe(struct histstr *hp, int what) * Pretty strange. */ static -int -head_findscoop(struct histstr (*hist)[MAXNOC], register natid maxcnum, natid *ano, natid *vno) + int +head_findscoop(struct histstr (*hist)[MAXNOC], register natid maxcnum, + natid *ano, natid *vno) { - register struct histstr *hp; - register int i; - register int j; - register int k; - int scoop; - natid actor; - natid victim; + register struct histstr *hp; + register int i; + register int j; + register int k; + int scoop; + natid actor; + natid victim; - scoop = 9; - actor = 0; - victim = 0; - for (i = 1; i < maxcnum; i++) { - for (j = 1; j < maxcnum; j++) { - hp = &hist[i][j]; - k = abs(hp->h_recent / 2); - if (k > scoop) { - scoop = k; - actor = (natid) i; - victim = (natid) j; - } - k = abs(hp->h_recent - hp->h_past); - if (k > scoop) { - scoop = k; - actor = (natid) i; - victim = (natid) j; - } - } + scoop = 9; + actor = 0; + victim = 0; + for (i = 1; i < maxcnum; i++) { + for (j = 1; j < maxcnum; j++) { + hp = &hist[i][j]; + k = abs(hp->h_recent / 2); + if (k > scoop) { + scoop = k; + actor = (natid)i; + victim = (natid)j; + } + k = abs(hp->h_recent - hp->h_past); + if (k > scoop) { + scoop = k; + actor = (natid)i; + victim = (natid)j; + } } - *ano = actor; - *vno = victim; - return scoop; + } + *ano = actor; + *vno = victim; + return scoop; } diff --git a/src/lib/commands/hidd.c b/src/lib/commands/hidd.c index 7064eb836..9b82e77b6 100644 --- a/src/lib/commands/hidd.c +++ b/src/lib/commands/hidd.c @@ -47,46 +47,45 @@ int hidd(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; - int cond[I_MAX+1]; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; + int cond[I_MAX + 1]; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) { - if (player->god) - pr(" "); - pr("HIDDEN VALUES old che------- plague----\n"); - if (player->god) - pr("own "); - pr(" sect eff own loyal cnum value stage time mines\n"); - } - if (player->god) - pr("%3d ", sect.sct_own); - getvec(VT_COND, cond, (s_char *)§, EF_SECTOR); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c %3d%% %3d %3d %3d %3d %3d %3d %3d", - dchr[sect.sct_type].d_mnem, sect.sct_effic, - sect.sct_oldown, sect.sct_loyal, - get_che_cnum(cond[C_CHE]), - get_che_value(cond[C_CHE]), - cond[C_PSTAGE], cond[C_PTIME], - cond[C_MINE]); - pr("\n"); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) { + if (player->god) + pr(" "); + pr("HIDDEN VALUES old che------- plague----\n"); + if (player->god) + pr("own "); + pr(" sect eff own loyal cnum value stage time mines\n"); } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + if (player->god) + pr("%3d ", sect.sct_own); + getvec(VT_COND, cond, (s_char *)§, EF_SECTOR); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c %3d%% %3d %3d %3d %3d %3d %3d %3d", + dchr[sect.sct_type].d_mnem, sect.sct_effic, + sect.sct_oldown, sect.sct_loyal, + get_che_cnum(cond[C_CHE]), + get_che_value(cond[C_CHE]), + cond[C_PSTAGE], cond[C_PTIME], cond[C_MINE]); + pr("\n"); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } diff --git a/src/lib/commands/improve.c b/src/lib/commands/improve.c index 643ea5f8f..012e42550 100644 --- a/src/lib/commands/improve.c +++ b/src/lib/commands/improve.c @@ -48,20 +48,21 @@ #include "commands.h" char *prompt[] = { - "Improve what ('road' or 'rail')? ", - "Improve what ('road', 'rail' or 'defense')? " }; + "Improve what ('road' or 'rail')? ", + "Improve what ('road', 'rail' or 'defense')? " +}; int improve(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; s_char *p; s_char buf[1024]; s_char inbuf[128]; int type; - int vec[I_MAX+1]; + int vec[I_MAX + 1]; int value; int ovalue; int maxup; @@ -71,10 +72,9 @@ improve(void) int mneeded; int dneeded; int wanted; - + if (!(p = getstarg(player->argp[1], - prompt[opt_DEFENSE_INFRA], buf)) || - !*p) + prompt[opt_DEFENSE_INFRA], buf)) || !*p) return RET_SYN; if (!strncmp(p, "ro", 2)) type = INT_ROAD; @@ -114,7 +114,8 @@ improve(void) if (!maxup) continue; lneeded = intrchr[type].in_lcms * maxup; - if (opt_NO_LCMS) lneeded = 0; + if (opt_NO_LCMS) + lneeded = 0; if (vec[I_LCM] < lneeded) { lneeded = vec[I_LCM]; maxup = lneeded / intrchr[type].in_lcms; @@ -125,7 +126,8 @@ improve(void) } } hneeded = intrchr[type].in_hcms * maxup; - if (opt_NO_HCMS) hneeded = 0; + if (opt_NO_HCMS) + hneeded = 0; if (vec[I_HCM] < hneeded) { hneeded = vec[I_HCM]; maxup = hneeded / intrchr[type].in_hcms; @@ -168,8 +170,10 @@ improve(void) mneeded = intrchr[type].in_mcost * maxup; dneeded = intrchr[type].in_dcost * maxup; player->dolcost += dneeded; - if (!opt_NO_LCMS) vec[I_LCM] -= lneeded; - if (!opt_NO_HCMS) vec[I_HCM] -= hneeded; + if (!opt_NO_LCMS) + vec[I_LCM] -= lneeded; + if (!opt_NO_HCMS) + vec[I_HCM] -= hneeded; sect.sct_mobil -= mneeded; putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); ovalue = value; @@ -194,9 +198,7 @@ improve(void) else pr("%s: No sector(s)\n", ""); return RET_FAIL; - }else + } else pr("%d sector%s\n", nsect, splur(nsect)); return 0; } - - diff --git a/src/lib/commands/info.c b/src/lib/commands/info.c index 4874e2824..37d4af09a 100644 --- a/src/lib/commands/info.c +++ b/src/lib/commands/info.c @@ -52,40 +52,44 @@ #include "commands.h" #if 0 -static int fileselect(struct dirent *dp); -static int printdir(void); +static int fileselect(struct dirent *dp); +static int printdir(void); #endif static s_char * -lowerit(s_char *buf, int n, s_char *orig) /* converts a string to lower case */ - /* lower case output buffer */ - /* size of output buffer */ - /* input strig */ -{ - int i; - s_char *tmp; - tmp = buf; - memset( buf, 0, n ); - for ( i=0; ic2) return 1; - else if (c1 c2) + return 1; + else if (c1 < c2) + return -1; + } + return 0; } #if !defined(_WIN32) @@ -93,144 +97,145 @@ strnccmp(s_char *s1, s_char *s2, int n) int info(void) { - extern int errno; - extern s_char *infodir; + extern int errno; + extern s_char *infodir; #if (!defined linux) && (!defined FBSD) && (!defined __linux__) && (!defined __ppc__) - extern s_char *sys_errlist[]; + extern s_char *sys_errlist[]; #endif - s_char buf[255]; - FILE *fp; - s_char *bp; - struct stat statb; - struct dirent *dp; - s_char filename[1024]; - DIR *info_dp; - - if (player->argp[1] == 0 || !*player->argp[1]) - bp = "TOP"; + s_char buf[255]; + FILE *fp; + s_char *bp; + struct stat statb; + struct dirent *dp; + s_char filename[1024]; + DIR *info_dp; + + if (player->argp[1] == 0 || !*player->argp[1]) + bp = "TOP"; #if 0 - /* Note that we generate an "all" file now, which contains - * this list, so we don't do printdir. */ - else if (!strcmp(player->argp[1], "all")) - return printdir(); + /* Note that we generate an "all" file now, which contains + * this list, so we don't do printdir. */ + else if (!strcmp(player->argp[1], "all")) + return printdir(); #endif - /* - * don't let sneaky people go outside the info directory - */ - else if (NULL != (bp = rindex(player->argp[1], '/'))) - bp++; - else - bp = player->argp[1]; - sprintf(filename, "%s/%s", infodir, bp); - fp = fopen(filename, "r"); - if (fp == NULL) { - int len = strlen(bp); - /* may be a "partial" request. */ - info_dp = opendir(infodir); - if (info_dp == 0) { - pr("Can't open info dir \"%s\"\n", infodir); - return RET_SYS; - } - rewinddir(info_dp); - while ((dp = readdir(info_dp)) != 0 && fp == 0) { - if (strnccmp(bp, dp->d_name, len) != 0) - continue; - sprintf(filename, "%s/%s", infodir, dp->d_name); - fp = fopen(filename, "r"); - } - closedir(info_dp); - if (fp == NULL) { - pr("Sorry, there is no info on %s\n", bp); - return RET_FAIL; - } + /* + * don't let sneaky people go outside the info directory + */ + else if (NULL != (bp = rindex(player->argp[1], '/'))) + bp++; + else + bp = player->argp[1]; + sprintf(filename, "%s/%s", infodir, bp); + fp = fopen(filename, "r"); + if (fp == NULL) { + int len = strlen(bp); + /* may be a "partial" request. */ + info_dp = opendir(infodir); + if (info_dp == 0) { + pr("Can't open info dir \"%s\"\n", infodir); + return RET_SYS; } - if (fstat(fileno(fp), &statb) < 0) { - pr("Cannot read info page for \"%s\" (%s)\n", - dp->d_name, sys_errlist[errno]); - fclose(fp); - return RET_SYS; + rewinddir(info_dp); + while ((dp = readdir(info_dp)) != 0 && fp == 0) { + if (strnccmp(bp, dp->d_name, len) != 0) + continue; + sprintf(filename, "%s/%s", infodir, dp->d_name); + fp = fopen(filename, "r"); } - if ((statb.st_mode & S_IFREG) == 0) { - pr("There is no available information on \"%s\"\n", - dp->d_name); - fclose(fp); - return RET_FAIL; + closedir(info_dp); + if (fp == NULL) { + pr("Sorry, there is no info on %s\n", bp); + return RET_FAIL; } - pr("Information on: %s Last modification date: %s", - bp, ctime(&statb.st_mtime)); - while (fgets(buf, sizeof(buf), fp) != 0) - pr("%s", buf); - (void) fclose(fp); - return RET_OK; + } + if (fstat(fileno(fp), &statb) < 0) { + pr("Cannot read info page for \"%s\" (%s)\n", + dp->d_name, sys_errlist[errno]); + fclose(fp); + return RET_SYS; + } + if ((statb.st_mode & S_IFREG) == 0) { + pr("There is no available information on \"%s\"\n", dp->d_name); + fclose(fp); + return RET_FAIL; + } + pr("Information on: %s Last modification date: %s", + bp, ctime(&statb.st_mtime)); + while (fgets(buf, sizeof(buf), fp) != 0) + pr("%s", buf); + (void)fclose(fp); + return RET_OK; } #if 0 static int biggest; static -int + int fileselect(struct dirent *dp) { - int l; - if (*dp->d_name == '.') - return 0; + int l; + if (*dp->d_name == '.') + return 0; - if ((l = strlen (dp->d_name)) > biggest) - biggest = l; - return 1; + if ((l = strlen(dp->d_name)) > biggest) + biggest = l; + return 1; } #ifdef solaris static -int + int alphasort(struct dirent *d1, struct dirent *d2) { - return strcmp(d1->d_name, d2->d_name); + return strcmp(d1->d_name, d2->d_name); } static int -scandir(char *dir, struct dirent ***dpp, int (*select)(), int (*sort)()) +scandir(char *dir, struct dirent ***dpp, int (*select) (), int (*sort) ()) /* directory to read */ /* directory entry pointer pointer */ { - DIR *dirp; - int nsize; - int nents; - struct dirent *d, *tmp; - - d = (struct dirent *)malloc(sizeof(struct dirent) + pathconf(".", _PC_NAME_MAX) +1); - if ( (dirp = opendir(dir)) == NULL) - return -1; - nsize = 100; - *dpp = (struct dirent **)malloc(nsize * sizeof(struct dirent *)); - if ( (*dpp) == NULL ) - { - closedir(dirp); - return -1; - } - nents = 0; - while ( (d = readdir_r(dirp, d)) != NULL) - { - if ( select != NULL && !(*select)(d) ) - continue; - tmp = (struct dirent *)malloc(sizeof(struct dirent) + strlen(d->d_name) + 1); - if ( tmp == NULL ) - return -1; - tmp->d_ino = d->d_ino; - tmp->d_reclen = d->d_reclen; - strcpy(tmp->d_name, d->d_name); - if ( nents > nsize ) - { - *dpp = (struct dirent **)realloc((char *)*dpp, nsize * sizeof(struct dirent *)); - if ( *dpp == NULL ) - return -1; - } - (*dpp)[nents++] = tmp; - } + DIR *dirp; + int nsize; + int nents; + struct dirent *d, *tmp; + + d = (struct dirent *)malloc(sizeof(struct dirent) + + pathconf(".", _PC_NAME_MAX) + 1); + if ((dirp = opendir(dir)) == NULL) + return -1; + nsize = 100; + *dpp = (struct dirent **)malloc(nsize * sizeof(struct dirent *)); + if ((*dpp) == NULL) { closedir(dirp); - if (nents > 0 && sort != NULL ) - qsort(*dpp, nents, sizeof(struct dirent *), sort); - return nents; + return -1; + } + nents = 0; + while ((d = readdir_r(dirp, d)) != NULL) { + if (select != NULL && !(*select) (d)) + continue; + tmp = + (struct dirent *)malloc(sizeof(struct dirent) + + strlen(d->d_name) + 1); + if (tmp == NULL) + return -1; + tmp->d_ino = d->d_ino; + tmp->d_reclen = d->d_reclen; + strcpy(tmp->d_name, d->d_name); + if (nents > nsize) { + *dpp = + (struct dirent **)realloc((char *)*dpp, + nsize * sizeof(struct dirent *)); + if (*dpp == NULL) + return -1; + } + (*dpp)[nents++] = tmp; + } + closedir(dirp); + if (nents > 0 && sort != NULL) + qsort(*dpp, nents, sizeof(struct dirent *), sort); + return nents; } #endif @@ -238,133 +243,137 @@ static int printdir(void) { #if !defined(solaris) && !defined(ALPHA) && !defined(__linux__) - extern int alphasort(const struct dirent *const *, const struct dirent *const *); + extern int alphasort(const struct dirent *const *, + const struct dirent *const *); #endif - extern s_char *infodir; - static time_t lastmodtime; - static int number; - static struct dirent **dp; - struct stat st; - int count; - int i; - int npl; - - if (stat(infodir, &st) == -1) - return RET_FAIL; - pr("Available topics are:\n"); - if (lastmodtime < st.st_mtime) { - if (dp) - free((s_char *)dp); - biggest = 0; - number = scandir(infodir, &dp, fileselect, alphasort); - lastmodtime = st.st_mtime; - } - count = 79 / (biggest + 1) - 1; - for(i = 0, npl = 0; i < number; i++) { - pr("%-*.*s%c", biggest, strlen (dp[i]->d_name), - dp[i]->d_name, npl == count ? '\n' : ' '); - if (npl == count) - npl = 0; - else - npl++; - } - if (npl != 0) - pr("\n"); - return 0; + extern s_char *infodir; + static time_t lastmodtime; + static int number; + static struct dirent **dp; + struct stat st; + int count; + int i; + int npl; + + if (stat(infodir, &st) == -1) + return RET_FAIL; + pr("Available topics are:\n"); + if (lastmodtime < st.st_mtime) { + if (dp) + free((s_char *)dp); + biggest = 0; + number = scandir(infodir, &dp, fileselect, alphasort); + lastmodtime = st.st_mtime; + } + count = 79 / (biggest + 1) - 1; + for (i = 0, npl = 0; i < number; i++) { + pr("%-*.*s%c", biggest, strlen(dp[i]->d_name), + dp[i]->d_name, npl == count ? '\n' : ' '); + if (npl == count) + npl = 0; + else + npl++; + } + if (npl != 0) + pr("\n"); + return 0; } #endif int apro(void) { - extern s_char *infodir; - FILE *fp; - s_char *bp,*lbp; - s_char *fbuf; - s_char *lbuf; - struct dirent *dp; - s_char filename[1024]; - DIR *info_dp; - long nf,nhf,nl,nlhl,nhl,nll; - int alreadyhit; - int lhitlim; - - if (player->argp[1] == 0 || !*player->argp[1]) { - pr("Apropos what?\n"); - return RET_FAIL; - } - - lhitlim = 100; - if (player->argp[2] ) { - lhitlim = atoi(player->argp[2]); - if (lhitlim<=0) lhitlim = 100; - } + extern s_char *infodir; + FILE *fp; + s_char *bp, *lbp; + s_char *fbuf; + s_char *lbuf; + struct dirent *dp; + s_char filename[1024]; + DIR *info_dp; + long nf, nhf, nl, nlhl, nhl, nll; + int alreadyhit; + int lhitlim; - info_dp = opendir(infodir); - if (info_dp == 0) { - pr("Can't open info dir \"%s\"\n", infodir); - return RET_SYS; - } + if (player->argp[1] == 0 || !*player->argp[1]) { + pr("Apropos what?\n"); + return RET_FAIL; + } - fbuf = (s_char *) malloc(256); - lbuf = (s_char *) malloc(256); - lbp = (s_char *) malloc(256); + lhitlim = 100; + if (player->argp[2]) { + lhitlim = atoi(player->argp[2]); + if (lhitlim <= 0) + lhitlim = 100; + } - /* - * lower case search string into lbp - */ - bp = player->argp[1]; - lowerit( lbp,256,bp ); + info_dp = opendir(infodir); + if (info_dp == 0) { + pr("Can't open info dir \"%s\"\n", infodir); + return RET_SYS; + } - /* - * search - */ - nf = nhf = nl = nhl = 0; - rewinddir(info_dp); - while ((dp = readdir(info_dp)) != 0) { - sprintf(filename, "%s/%s", infodir, dp->d_name); - fp = fopen(filename, "r"); - alreadyhit = 0; - nll = nlhl = 0; - if (fp != NULL) { - while (fgets(fbuf,256,fp)){ - lowerit(lbuf,256,fbuf); - if (strstr(lbuf,lbp)){ - if (!alreadyhit){ - pr("*** %s ***\n",dp->d_name); - alreadyhit = 1; - nhf++; - } - fbuf[74] = '\n'; - fbuf[75] = 0; - pr(" %s",fbuf); - nlhl++; - /* - * break if too many lines - */ - if ((nhl+nlhl)>lhitlim) break; - } - nll++; - } - fclose( fp ); - } - nhl += nlhl; - nl += nll; - nf++; - if (nhl>lhitlim) break; + fbuf = (s_char *)malloc(256); + lbuf = (s_char *)malloc(256); + lbp = (s_char *)malloc(256); + + /* + * lower case search string into lbp + */ + bp = player->argp[1]; + lowerit(lbp, 256, bp); + + /* + * search + */ + nf = nhf = nl = nhl = 0; + rewinddir(info_dp); + while ((dp = readdir(info_dp)) != 0) { + sprintf(filename, "%s/%s", infodir, dp->d_name); + fp = fopen(filename, "r"); + alreadyhit = 0; + nll = nlhl = 0; + if (fp != NULL) { + while (fgets(fbuf, 256, fp)) { + lowerit(lbuf, 256, fbuf); + if (strstr(lbuf, lbp)) { + if (!alreadyhit) { + pr("*** %s ***\n", dp->d_name); + alreadyhit = 1; + nhf++; + } + fbuf[74] = '\n'; + fbuf[75] = 0; + pr(" %s", fbuf); + nlhl++; + /* + * break if too many lines + */ + if ((nhl + nlhl) > lhitlim) + break; + } + nll++; + } + fclose(fp); } - closedir(info_dp); + nhl += nlhl; + nl += nll; + nf++; + if (nhl > lhitlim) + break; + } + closedir(info_dp); - free(fbuf); - free(lbuf); - free(lbp); + free(fbuf); + free(lbuf); + free(lbp); - if ((nhl)>lhitlim){ - pr("Limit of %ld lines exceeded\n",lhitlim); - } - pr("Found %s in %ld of %ld files and in %ld of %ld lines\n", - bp, nhf,nf, nhl,nl ); - return RET_OK; + if ((nhl) > lhitlim) { + pr("Limit of %ld lines exceeded\n", lhitlim); + } + pr("Found %s in %ld of %ld files and in %ld of %ld lines\n", + bp, nhf, nf, nhl, nl); + return RET_OK; } #else @@ -372,73 +381,72 @@ apro(void) int info(void) { - extern int errno; - extern s_char *infodir; - s_char buf[255]; - FILE *fp; - s_char *bp; - s_char *bp2; - s_char filename[1024]; + extern int errno; + extern s_char *infodir; + s_char buf[255]; + FILE *fp; + s_char *bp; + s_char *bp2; + s_char filename[1024]; if (player->argp[1] == 0 || !*player->argp[1]) - bp = "TOP"; + bp = "TOP"; #if 0 /* Note that we generate an "all" file now, which contains * this list, so we don't do printdir. */ else if (!strcmp(player->argp[1], "all")) - return printdir(); + return printdir(); #endif else { - /* - * don't let sneaky people go outside the info directory - */ - bp = player->argp[1]; - if (NULL != (bp2 = rindex(bp, '/'))) - bp = ++bp2; - if (NULL != (bp2 = rindex(bp, '\\'))) - bp = ++bp2; - if (NULL != (bp2 = rindex(bp, ':'))) - bp = ++bp2; - if (!*bp) - bp = "TOP"; + /* + * don't let sneaky people go outside the info directory + */ + bp = player->argp[1]; + if (NULL != (bp2 = rindex(bp, '/'))) + bp = ++bp2; + if (NULL != (bp2 = rindex(bp, '\\'))) + bp = ++bp2; + if (NULL != (bp2 = rindex(bp, ':'))) + bp = ++bp2; + if (!*bp) + bp = "TOP"; } - strncpy(filename, infodir, sizeof(filename)-2); + strncpy(filename, infodir, sizeof(filename) - 2); strcat(filename, "//"); - strncat(filename, bp, sizeof(filename)-1-strlen(filename)); + strncat(filename, bp, sizeof(filename) - 1 - strlen(filename)); fp = fopen(filename, "r"); if (fp == NULL) { - /* may be a "partial" request. */ - HANDLE hDir; - WIN32_FIND_DATA fData; - int len = strlen(bp); - strncat(filename, "*", sizeof(filename)-1-strlen(filename)); - hDir = FindFirstFile(filename, &fData); - if (hDir == INVALID_HANDLE_VALUE) { - pr("Can't open info dir \"%s\"\n", infodir); - return RET_SYS; - } - do { - if ((fData.dwFileAttributes == FILE_ATTRIBUTE_NORMAL) && - (strnccmp(bp, fData.cFileName, len) == 0)) - { - strncpy(filename, infodir, sizeof(filename)-2); - strcat(filename, "//"); - strncat(filename, fData.cFileName, - sizeof(filename)-1-strlen(filename)); - fp = fopen(filename, "r"); - } - } while (!fp && FindNextFile(hDir, &fData)); - FindClose(hDir); - if (fp == NULL) { - pr("Sorry, there is no info on %s\n", bp); - return RET_FAIL; - } + /* may be a "partial" request. */ + HANDLE hDir; + WIN32_FIND_DATA fData; + int len = strlen(bp); + strncat(filename, "*", sizeof(filename) - 1 - strlen(filename)); + hDir = FindFirstFile(filename, &fData); + if (hDir == INVALID_HANDLE_VALUE) { + pr("Can't open info dir \"%s\"\n", infodir); + return RET_SYS; + } + do { + if ((fData.dwFileAttributes == FILE_ATTRIBUTE_NORMAL) && + (strnccmp(bp, fData.cFileName, len) == 0)) { + strncpy(filename, infodir, sizeof(filename) - 2); + strcat(filename, "//"); + strncat(filename, fData.cFileName, + sizeof(filename) - 1 - strlen(filename)); + fp = fopen(filename, "r"); + } + } while (!fp && FindNextFile(hDir, &fData)); + FindClose(hDir); + if (fp == NULL) { + pr("Sorry, there is no info on %s\n", bp); + return RET_FAIL; + } } pr("Information on: %s", bp); while (fgets(buf, sizeof(buf), fp) != 0) - pr("%s", buf); - (void) fclose(fp); + pr("%s", buf); + (void)fclose(fp); return RET_OK; } @@ -446,117 +454,119 @@ info(void) static int printdir(void) { - extern s_char *infodir; + extern s_char *infodir; HANDLE hDir; WIN32_FIND_DATA fData; - int count; - int i; - int npl; - s_char filename[1024]; + int count; + int i; + int npl; + s_char filename[1024]; - strncpy(filename, infodir, sizeof(filename)-3); + strncpy(filename, infodir, sizeof(filename) - 3); strcat(filename, "//*"); hDir = FindFirstFile(filename, &fData); if (hDir == INVALID_HANDLE_VALUE) { - return RET_FAIL; + return RET_FAIL; } - pr("Available topics are:\n"); + pr("Available topics are:\n"); do { - if (fData.dwFileAttributes == FILE_ATTRIBUTE_NORMAL) - { - /* Yes, we could do multi-column work here. */ - pr("%s\n", fData.cFileName); - } + if (fData.dwFileAttributes == FILE_ATTRIBUTE_NORMAL) { + /* Yes, we could do multi-column work here. */ + pr("%s\n", fData.cFileName); + } } while (FindNextFile(hDir, &fData)); FindClose(hDir); - return 0; + return 0; } #endif int apro(void) { - extern s_char *infodir; + extern s_char *infodir; HANDLE hDir; WIN32_FIND_DATA fData; - FILE *fp; - s_char *bp,*lbp; - s_char *fbuf; - s_char *lbuf; - s_char filename[1024]; - long nf,nhf,nl,nlhl,nhl,nll; - int alreadyhit; - int lhitlim; + FILE *fp; + s_char *bp, *lbp; + s_char *fbuf; + s_char *lbuf; + s_char filename[1024]; + long nf, nhf, nl, nlhl, nhl, nll; + int alreadyhit; + int lhitlim; if (player->argp[1] == 0 || !*player->argp[1]) { - pr("Apropos what?\n"); - return RET_FAIL; + pr("Apropos what?\n"); + return RET_FAIL; } lhitlim = 100; - if (player->argp[2] ) { - lhitlim = atoi(player->argp[2]); - if (lhitlim<=0) lhitlim = 100; + if (player->argp[2]) { + lhitlim = atoi(player->argp[2]); + if (lhitlim <= 0) + lhitlim = 100; } - strncpy(filename, infodir, sizeof(filename)-3); + strncpy(filename, infodir, sizeof(filename) - 3); strcat(filename, "//*"); hDir = FindFirstFile(filename, &fData); if (hDir == INVALID_HANDLE_VALUE) { - return RET_FAIL; + return RET_FAIL; } - fbuf = (s_char *) malloc(256); - lbuf = (s_char *) malloc(256); - lbp = (s_char *) malloc(256); + fbuf = (s_char *)malloc(256); + lbuf = (s_char *)malloc(256); + lbp = (s_char *)malloc(256); /* * lower case search string into lbp */ bp = player->argp[1]; - lowerit( lbp,256,bp ); + lowerit(lbp, 256, bp); /* * search */ nf = nhf = nl = nhl = 0; do { - strncpy(filename, infodir, sizeof(filename)-3); - strcat(filename, "//"); - strncat(filename, fData.cFileName, - sizeof(filename)-1-strlen(filename)); - fp = fopen(filename, "r"); - alreadyhit = 0; - nll = nlhl = 0; - if (fp != NULL) { - while (fgets(fbuf,256,fp)){ - lowerit(lbuf,256,fbuf); - if (strstr(lbuf,lbp)){ - if (!alreadyhit){ - pr("*** %s ***\n",fData.cFileName); - alreadyhit = 1; - nhf++; - } - fbuf[74] = '\n'; - fbuf[75] = 0; - pr(" %s",fbuf); - nlhl++; - /* - * break if too many lines - */ - if ((nhl+nlhl)>lhitlim) break; - } - nll++; - } - fclose( fp ); - } - nhl += nlhl; - nl += nll; - nf++; - if (nhl>lhitlim) break; + strncpy(filename, infodir, sizeof(filename) - 3); + strcat(filename, "//"); + strncat(filename, fData.cFileName, + sizeof(filename) - 1 - strlen(filename)); + fp = fopen(filename, "r"); + alreadyhit = 0; + nll = nlhl = 0; + if (fp != NULL) { + while (fgets(fbuf, 256, fp)) { + lowerit(lbuf, 256, fbuf); + if (strstr(lbuf, lbp)) { + if (!alreadyhit) { + pr("*** %s ***\n", fData.cFileName); + alreadyhit = 1; + nhf++; + } + fbuf[74] = '\n'; + fbuf[75] = 0; + pr(" %s", fbuf); + nlhl++; + /* + * break if too many lines + */ + if ((nhl + nlhl) > lhitlim) + break; + } + nll++; + } + fclose(fp); + } + nhl += nlhl; + nl += nll; + nf++; + if (nhl > lhitlim) + break; } while (FindNextFile(hDir, &fData)); FindClose(hDir); @@ -564,11 +574,11 @@ apro(void) free(lbuf); free(lbp); - if ((nhl)>lhitlim) { - pr("Limit of %ld lines exceeded\n",lhitlim); + if ((nhl) > lhitlim) { + pr("Limit of %ld lines exceeded\n", lhitlim); } pr("Found %s in %ld of %ld files and in %ld of %ld lines\n", - bp, nhf,nf, nhl,nl ); + bp, nhf, nf, nhl, nl); return RET_OK; } diff --git a/src/lib/commands/land.c b/src/lib/commands/land.c index cb285f24f..e4eb20fcb 100644 --- a/src/lib/commands/land.c +++ b/src/lib/commands/land.c @@ -47,72 +47,71 @@ int land(void) { - int nunits; - struct nstr_item ni; - struct lndstr land; - int vec[I_MAX+1]; - s_char *mission_short_name(); + int nunits; + struct nstr_item ni; + struct lndstr land; + int vec[I_MAX + 1]; + s_char *mission_short_name(); - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; - nunits = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own == 0) - continue; - if (!player->owner && !player->god) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", - land.lnd_type, ni.cur); - continue; - } - count_land_planes(&land); - lnd_count_units(&land); + nunits = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (!player->owner && !player->god) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; + } + count_land_planes(&land); + lnd_count_units(&land); - if (nunits++ == 0) { - if (player->god) - pr("own "); -pr(" # unit type x,y a eff mil frt mu fd"); - if (opt_FUEL) - pr(" fl"); - pr(" tch retr rd"); - pr(" xl"); - pr(" ln"); - pr(" l/s\n"); - } - if (player->god) - pr("%3d ", land.lnd_own); - pr("%4d ", ni.cur); - pr("%-15.15s", lchr[(int)land.lnd_type].l_name); - prxy(" %4d,%-4d", land.lnd_x, land.lnd_y, player->cnum); - pr("%c", land.lnd_army); - pr("%4d%%", land.lnd_effic); - pr("%4d", lnd_getmil(&land)); - pr("%4d", land.lnd_harden); - pr("%4d", land.lnd_mobil); - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - pr("%4d", vec[I_FOOD]); - if (opt_FUEL) - pr("%3d",land.lnd_fuel); - pr("%4d ", land.lnd_tech); - pr("%3d%%", land.lnd_retreat); - pr("%3d", land.lnd_rad_max); - pr("%3d",land.lnd_nxlight); - pr("%3d",land.lnd_nland); - if (land.lnd_ship >= 0) - pr(" S%4d", land.lnd_ship); - else if (land.lnd_land >= 0) - pr(" L%4d", land.lnd_land); - pr("\n"); + if (nunits++ == 0) { + if (player->god) + pr("own "); + pr(" # unit type x,y a eff mil frt mu fd"); + if (opt_FUEL) + pr(" fl"); + pr(" tch retr rd"); + pr(" xl"); + pr(" ln"); + pr(" l/s\n"); } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + if (player->god) + pr("%3d ", land.lnd_own); + pr("%4d ", ni.cur); + pr("%-15.15s", lchr[(int)land.lnd_type].l_name); + prxy(" %4d,%-4d", land.lnd_x, land.lnd_y, player->cnum); + pr("%c", land.lnd_army); + pr("%4d%%", land.lnd_effic); + pr("%4d", lnd_getmil(&land)); + pr("%4d", land.lnd_harden); + pr("%4d", land.lnd_mobil); + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); + pr("%4d", vec[I_FOOD]); + if (opt_FUEL) + pr("%3d", land.lnd_fuel); + pr("%4d ", land.lnd_tech); + pr("%3d%%", land.lnd_retreat); + pr("%3d", land.lnd_rad_max); + pr("%3d", land.lnd_nxlight); + pr("%3d", land.lnd_nland); + if (land.lnd_ship >= 0) + pr(" S%4d", land.lnd_ship); + else if (land.lnd_land >= 0) + pr(" L%4d", land.lnd_land); + pr("\n"); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } diff --git a/src/lib/commands/laun.c b/src/lib/commands/laun.c index ed67b2c9f..a039bbfc4 100644 --- a/src/lib/commands/laun.c +++ b/src/lib/commands/laun.c @@ -53,9 +53,9 @@ #include "damage.h" #include "commands.h" -static int launch_as(struct plnstr *pp); -static int launch_missile(struct plnstr *pp, int sublaunch); -static int launch_sat(struct plnstr *pp, int sublaunch); +static int launch_as(struct plnstr *pp); +static int launch_missile(struct plnstr *pp, int sublaunch); +static int launch_sat(struct plnstr *pp, int sublaunch); /* * laun @@ -63,106 +63,107 @@ static int launch_sat(struct plnstr *pp, int sublaunch); int laun(void) { - struct nstr_item nstr; - struct plnstr plane; - struct shpstr ship; - struct sctstr sect; - int sublaunch; - struct plchrstr *pcp; - int rel; - struct natstr *natp; + struct nstr_item nstr; + struct plnstr plane; + struct shpstr ship; + struct sctstr sect; + int sublaunch; + struct plchrstr *pcp; + int rel; + struct natstr *natp; - if (!snxtitem(&nstr, EF_PLANE, player->argp[1])) - return RET_SYN; - while (nxtitem(&nstr, (s_char *)&plane)) { - if (plane.pln_own != player->cnum) - continue; - pcp = &plchr[(int)plane.pln_type]; - if ((pcp->pl_flags & (P_M|P_O)) == 0) { - pr("%s isn't a missile!\n", prplane(&plane)); - continue; - } - if (pcp->pl_flags & P_F) { - pr("%s is a surface-to-air missile!\n", - prplane(&plane)); - continue; - } - if (pcp->pl_flags & P_N) { - pr("%s is an anti-ballistic-missile missile!\n", - prplane(&plane)); - continue; - } - if ((plane.pln_flags & PLN_LAUNCHED) && (pcp->pl_flags & P_O)) { - pr("%s already in orbit!\n", prplane(&plane)); - continue; - } - if (opt_MARKET) { - if (ontradingblock(EF_PLANE,(int *) &plane)) { - pr("plane #%d inelligible - it's for sale.\n", plane.pln_uid); - continue; - } - } + if (!snxtitem(&nstr, EF_PLANE, player->argp[1])) + return RET_SYN; + while (nxtitem(&nstr, (s_char *)&plane)) { + if (plane.pln_own != player->cnum) + continue; + pcp = &plchr[(int)plane.pln_type]; + if ((pcp->pl_flags & (P_M | P_O)) == 0) { + pr("%s isn't a missile!\n", prplane(&plane)); + continue; + } + if (pcp->pl_flags & P_F) { + pr("%s is a surface-to-air missile!\n", prplane(&plane)); + continue; + } + if (pcp->pl_flags & P_N) { + pr("%s is an anti-ballistic-missile missile!\n", + prplane(&plane)); + continue; + } + if ((plane.pln_flags & PLN_LAUNCHED) && (pcp->pl_flags & P_O)) { + pr("%s already in orbit!\n", prplane(&plane)); + continue; + } + if (opt_MARKET) { + if (ontradingblock(EF_PLANE, (int *)&plane)) { + pr("plane #%d inelligible - it's for sale.\n", + plane.pln_uid); + continue; + } + } - sublaunch = 0; - if (plane.pln_ship >= 0) { - getship(plane.pln_ship, &ship); - if (!ship.shp_own) { - pr("%s: ship #%d was sunk!\n", - prplane(&plane), - ship.shp_uid); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = 0; - putplane(plane.pln_uid, &plane); - continue; - } - natp = getnatp(ship.shp_own); - rel = getrel(natp, player->cnum); - if (ship.shp_own != player->cnum && rel != ALLIED) { - pr("%s: you or an ally do not own ship #%d\n", - prplane(&plane), ship.shp_uid); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = 0; - putplane(plane.pln_uid, &plane); - continue; - } - if (mchr[(int)ship.shp_type].m_flags & M_SUB) - sublaunch = 1; - } else { - sublaunch = 0; - getsect(plane.pln_x, plane.pln_y, §); - natp = getnatp(sect.sct_own); - rel = getrel(natp, player->cnum); - if (sect.sct_own && sect.sct_own != player->cnum && rel != ALLIED) { - pr("%s: you or an ally do not own sector %s!\n", - prplane(&plane), - xyas(plane.pln_x, plane.pln_y, player->cnum)); - continue; - } - } - if (plane.pln_effic < 60) { - pr("%s is damaged (%d%%)\n", - prplane(&plane), plane.pln_effic); - continue; - } - pr("%s at %s; range %d, eff %d%%\n", prplane(&plane), - xyas(plane.pln_x, plane.pln_y, player->cnum), - plane.pln_range, - plane.pln_effic); - if (!(pcp->pl_flags & P_O)) { - if (launch_missile(&plane, sublaunch) < 0) - continue; - } else if ((pcp->pl_flags & (P_M|P_O)) == (P_M|P_O)) { - if (launch_as(&plane) < 0) /* anti-sat */ - continue; - } else { /* satellites */ - if (launch_sat(&plane, sublaunch) < 0) - continue; - } - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); + sublaunch = 0; + if (plane.pln_ship >= 0) { + getship(plane.pln_ship, &ship); + if (!ship.shp_own) { + pr("%s: ship #%d was sunk!\n", + prplane(&plane), ship.shp_uid); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); plane.pln_own = 0; putplane(plane.pln_uid, &plane); + continue; + } + natp = getnatp(ship.shp_own); + rel = getrel(natp, player->cnum); + if (ship.shp_own != player->cnum && rel != ALLIED) { + pr("%s: you or an ally do not own ship #%d\n", + prplane(&plane), ship.shp_uid); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_own = 0; + putplane(plane.pln_uid, &plane); + continue; + } + if (mchr[(int)ship.shp_type].m_flags & M_SUB) + sublaunch = 1; + } else { + sublaunch = 0; + getsect(plane.pln_x, plane.pln_y, §); + natp = getnatp(sect.sct_own); + rel = getrel(natp, player->cnum); + if (sect.sct_own && sect.sct_own != player->cnum + && rel != ALLIED) { + pr("%s: you or an ally do not own sector %s!\n", + prplane(&plane), xyas(plane.pln_x, plane.pln_y, + player->cnum)); + continue; + } + } + if (plane.pln_effic < 60) { + pr("%s is damaged (%d%%)\n", prplane(&plane), plane.pln_effic); + continue; + } + pr("%s at %s; range %d, eff %d%%\n", prplane(&plane), + xyas(plane.pln_x, plane.pln_y, player->cnum), + plane.pln_range, plane.pln_effic); + if (!(pcp->pl_flags & P_O)) { + if (launch_missile(&plane, sublaunch) < 0) + continue; + } else if ((pcp->pl_flags & (P_M | P_O)) == (P_M | P_O)) { + if (launch_as(&plane) < 0) /* anti-sat */ + continue; + } else { /* satellites */ + if (launch_sat(&plane, sublaunch) < 0) + continue; } - return RET_OK; + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, + plane.pln_y); + plane.pln_own = 0; + putplane(plane.pln_uid, &plane); + } + return RET_OK; } /* @@ -173,64 +174,65 @@ laun(void) static int launch_as(struct plnstr *pp) { - coord sx, sy; - s_char *cp, buf[1024]; - struct plnstr plane; - struct nstr_item ni; - int goodtarget; - int dam, nukedam; - natid oldown; + coord sx, sy; + s_char *cp, buf[1024]; + struct plnstr plane; + struct nstr_item ni; + int goodtarget; + int dam, nukedam; + natid oldown; - if (msl_equip(pp) < 0) { - pr("%s not enough petrol or shells!\n", prplane(pp)); - return -1; - } - for (;;) { - cp = getstarg(player->argp[2], "Target sector? ", buf); - if (!check_plane_ok(pp)) - return -1; - player->argp[2] = 0; - if (!cp || !*cp) - return -1; - if (!sarg_xy(cp, &sx, &sy)) { - pr("Bad sector designation; try again!\n"); - continue; - } - if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > - pp->pln_range) { - pr("Range too great; try again!\n"); - continue; - } - break; - } - goodtarget=0; - snxtitem_dist(&ni, EF_PLANE, sx, sy, 0); - while (!goodtarget && nxtitem(&ni, (caddr_t)&plane)) { - if (!plane.pln_own) - continue; - if (!(plane.pln_flags & PLN_LAUNCHED)) - continue; - goodtarget = 1; - - } - if (!goodtarget) { - pr("No satellites there!\n"); - return -1; + if (msl_equip(pp) < 0) { + pr("%s not enough petrol or shells!\n", prplane(pp)); + return -1; + } + for (;;) { + cp = getstarg(player->argp[2], "Target sector? ", buf); + if (!check_plane_ok(pp)) + return -1; + player->argp[2] = 0; + if (!cp || !*cp) + return -1; + if (!sarg_xy(cp, &sx, &sy)) { + pr("Bad sector designation; try again!\n"); + continue; } - if (msl_hit(pp, plane.pln_def, EF_PLANE, N_SAT_KILL, N_SAT_KILL, prplane(&plane), sx, sy, plane.pln_own)) { - dam = pln_damage(pp,sx,sy,'p',&nukedam,1); - oldown = plane.pln_own; - planedamage(&plane, dam); - pr("Hit satellite for %d%% damage!\n", dam); - mpr(oldown, - "%s anti-sat did %d%% damage to %s over %s\n", - cname(player->cnum), dam, prplane(&plane), - xyas(plane.pln_x, plane.pln_y, plane.pln_own)); - putplane(plane.pln_uid,&plane); - if (!plane.pln_own) - mpr(oldown, "Satellite shot down\n"); + if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > pp->pln_range) { + pr("Range too great; try again!\n"); + continue; } - return 0; + break; + } + goodtarget = 0; + snxtitem_dist(&ni, EF_PLANE, sx, sy, 0); + while (!goodtarget && nxtitem(&ni, (caddr_t)&plane)) { + if (!plane.pln_own) + continue; + if (!(plane.pln_flags & PLN_LAUNCHED)) + continue; + goodtarget = 1; + + } + if (!goodtarget) { + pr("No satellites there!\n"); + return -1; + } + if (msl_hit + (pp, plane.pln_def, EF_PLANE, N_SAT_KILL, N_SAT_KILL, + prplane(&plane), sx, sy, plane.pln_own)) { + dam = pln_damage(pp, sx, sy, 'p', &nukedam, 1); + oldown = plane.pln_own; + planedamage(&plane, dam); + pr("Hit satellite for %d%% damage!\n", dam); + mpr(oldown, + "%s anti-sat did %d%% damage to %s over %s\n", + cname(player->cnum), dam, prplane(&plane), + xyas(plane.pln_x, plane.pln_y, plane.pln_own)); + putplane(plane.pln_uid, &plane); + if (!plane.pln_own) + mpr(oldown, "Satellite shot down\n"); + } + return 0; } /* @@ -240,138 +242,135 @@ launch_as(struct plnstr *pp) static int launch_missile(struct plnstr *pp, int sublaunch) { - struct plchrstr *pcp = plchr + pp->pln_type; - coord sx, sy; - int n, dam; - s_char *cp; - struct mchrstr *mcp; - struct shpstr target_ship; - struct sctstr sect; - int nukedam; - int rel; - struct natstr *natp; - s_char buf[1024]; + struct plchrstr *pcp = plchr + pp->pln_type; + coord sx, sy; + int n, dam; + s_char *cp; + struct mchrstr *mcp; + struct shpstr target_ship; + struct sctstr sect; + int nukedam; + int rel; + struct natstr *natp; + s_char buf[1024]; - for (;;) { - if (pcp->pl_flags & P_MAR) - cp = getstarg(player->argp[2], "Target ship? ", buf); + for (;;) { + if (pcp->pl_flags & P_MAR) + cp = getstarg(player->argp[2], "Target ship? ", buf); + else + cp = getstarg(player->argp[2], "Target sector? ", buf); + player->argp[2] = 0; + if (!cp || !*cp) + return -1; + if (!check_plane_ok(pp)) + return -1; + if (opt_PINPOINTMISSILE && sarg_type(cp) == NS_LIST) { + if (!(pcp->pl_flags & P_MAR)) { + pr("Missile not designed to attack ships!\n"); + continue; + } + n = atoi(cp); + if ((n < 0) || !getship(n, &target_ship) || + !target_ship.shp_own) { + pr("Bad ship number; try again!\n"); + continue; + } + sx = target_ship.shp_x; + sy = target_ship.shp_y; + mcp = &mchr[(int)target_ship.shp_type]; + if (mcp->m_flags & M_SUB) { + pr("Bad ship number; try again!\n"); + continue; + } + } /* not PINPOINTMISSILE for ships */ + else if (!sarg_xy(cp, &sx, &sy)) { + pr("That's no good! try again!\n"); + continue; + } else if (opt_PINPOINTMISSILE) { + if (pcp->pl_flags & P_MAR) { + pr("Missile designed to attack ships!\n"); + continue; + } + } + /* end PINPOINTMISSILE */ + if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > pp->pln_range) { + pr("Range too great; try again!\n"); + continue; + } + break; + } + if (msl_equip(pp) < 0) { + pr("%s not enough shells!\n", prplane(pp)); + return -1; + } + if (opt_PINPOINTMISSILE == 0 || !(pcp->pl_flags & P_MAR)) { + getsect(sx, sy, §); + if (opt_SLOW_WAR) { + natp = getnatp(player->cnum); + rel = getrel(natp, sect.sct_own); + if ((rel != AT_WAR) && (sect.sct_own != player->cnum) && + (sect.sct_own) && (sect.sct_oldown != player->cnum)) { + pr("You are not at war with the player->owner of the target sector!\n"); + pr_beep(); + pr("Kaboom!!!\n"); + pr("Missile monitoring officer destroys RV before detonation.\n"); + return 0; + } + } + if (!msl_hit(pp, SECT_HARDTARGET, EF_SECTOR, N_SCT_MISS, + N_SCT_SMISS, "sector", sx, sy, sect.sct_own)) { + /* + dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 0); + collateral_damage(sect.sct_x, sect.sct_y, dam, 0); + */ + return 0; + } + dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 1); + if (!nukedam) { + pr("did %d damage in %s\n", PERCENT_DAMAGE(dam), + xyas(sx, sy, player->cnum)); + if (sect.sct_own != 0) { + if (sublaunch) + wu(0, sect.sct_own, + "Sub missile attack did %d damage in %s\n", + dam, xyas(sx, sy, sect.sct_own)); else - cp = getstarg(player->argp[2], "Target sector? ", buf); - player->argp[2] = 0; - if (!cp || !*cp) - return -1; - if (!check_plane_ok(pp)) - return -1; - if (opt_PINPOINTMISSILE && sarg_type(cp) == NS_LIST) { - if (!(pcp->pl_flags & P_MAR)) { - pr("Missile not designed to attack ships!\n"); - continue; - } - n = atoi(cp); - if ((n < 0) || !getship(n,&target_ship) || - !target_ship.shp_own) { - pr("Bad ship number; try again!\n"); - continue; - } - sx = target_ship.shp_x; - sy = target_ship.shp_y; - mcp = &mchr[(int)target_ship.shp_type]; - if (mcp->m_flags & M_SUB) { - pr("Bad ship number; try again!\n"); - continue; - } - } /* not PINPOINTMISSILE for ships */ - else if (!sarg_xy(cp, &sx, &sy)) { - pr("That's no good! try again!\n"); - continue; - } - else if (opt_PINPOINTMISSILE) - { - if (pcp->pl_flags & P_MAR) { - pr("Missile designed to attack ships!\n"); - continue; - } - } /* end PINPOINTMISSILE */ - - if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > - pp->pln_range) { - pr("Range too great; try again!\n"); - continue; - } - break; + wu(0, sect.sct_own, + "%s missile attack did %d damage in %s\n", + cname(player->cnum), dam, + xyas(sx, sy, sect.sct_own)); + } + sectdamage(§, dam, 0); + putsect(§); } - if (msl_equip(pp) < 0) { - pr("%s not enough shells!\n", prplane(pp)); - return -1; + } /* end PINPOINTMISSILE conditional */ + else if (opt_PINPOINTMISSILE) { /* else */ + if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP, + N_SHP_MISS, N_SHP_SMISS, prship(&target_ship), + target_ship.shp_x, target_ship.shp_y, + target_ship.shp_own)) { + pr("splash\n"); + /* + dam = pln_damage(pp,target_ship.shp_x,target_ship.shp_y,'p',&nukedam, 0); + collateral_damage(target_ship.shp_x, target_ship.shp_y, dam, 0); + */ + return 0; } - if (opt_PINPOINTMISSILE == 0 || !(pcp->pl_flags & P_MAR)) - { - getsect(sx,sy,§); - if (opt_SLOW_WAR) { - natp = getnatp(player->cnum); - rel = getrel(natp,sect.sct_own); - if ((rel != AT_WAR) && (sect.sct_own != player->cnum) && - (sect.sct_own) && (sect.sct_oldown != player->cnum)){ - pr("You are not at war with the player->owner of the target sector!\n"); - pr_beep(); - pr("Kaboom!!!\n"); - pr("Missile monitoring officer destroys RV before detonation.\n"); - return 0; - } - } - if (!msl_hit(pp, SECT_HARDTARGET, EF_SECTOR, N_SCT_MISS, - N_SCT_SMISS, "sector", sx, sy, sect.sct_own)) { - /* - dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 0); - collateral_damage(sect.sct_x, sect.sct_y, dam, 0); - */ - return 0; - } - dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 1); - if (!nukedam) { - pr("did %d damage in %s\n", PERCENT_DAMAGE(dam), - xyas(sx, sy, player->cnum)); - if (sect.sct_own != 0) { - if (sublaunch) - wu(0, sect.sct_own, - "Sub missile attack did %d damage in %s\n", - dam, xyas(sx, sy, sect.sct_own)); - else - wu(0, sect.sct_own, - "%s missile attack did %d damage in %s\n", - cname(player->cnum), dam, - xyas(sx, sy, sect.sct_own)); - } - sectdamage(§, dam, 0); - putsect(§); - } - } /* end PINPOINTMISSILE conditional */ - else if (opt_PINPOINTMISSILE) - { /* else */ - if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP, - N_SHP_MISS, N_SHP_SMISS, prship(&target_ship), - target_ship.shp_x, target_ship.shp_y, - target_ship.shp_own)) { - pr("splash\n"); - /* - dam = pln_damage(pp,target_ship.shp_x,target_ship.shp_y,'p',&nukedam, 0); - collateral_damage(target_ship.shp_x, target_ship.shp_y, dam, 0); - */ - return 0; - } - dam = pln_damage(pp,target_ship.shp_x,target_ship.shp_y,'p',&nukedam, 1); - if (!nukedam) { - check_retreat_and_do_shipdamage(&target_ship, dam); - if (target_ship.shp_effic < SHIP_MINEFF) - pr("\t%s sunk!\n", prship(&target_ship)); - putship(target_ship.shp_uid, &target_ship); - } - getship(n, &target_ship); - if (!target_ship.shp_own) - pr("%s sunk!\n", prship(&target_ship)); + dam = + pln_damage(pp, target_ship.shp_x, target_ship.shp_y, 'p', + &nukedam, 1); + if (!nukedam) { + check_retreat_and_do_shipdamage(&target_ship, dam); + if (target_ship.shp_effic < SHIP_MINEFF) + pr("\t%s sunk!\n", prship(&target_ship)); + putship(target_ship.shp_uid, &target_ship); } - /* end PINPOINTMISSILE */ - return 0; + getship(n, &target_ship); + if (!target_ship.shp_own) + pr("%s sunk!\n", prship(&target_ship)); + } + /* end PINPOINTMISSILE */ + return 0; } /* @@ -381,73 +380,69 @@ launch_missile(struct plnstr *pp, int sublaunch) static int launch_sat(struct plnstr *pp, int sublaunch) { - struct plchrstr *pcp = plchr + pp->pln_type; - coord sx, sy; - int i; - int dist; - int dir; - s_char *cp; - s_char *p; - s_char buf[1024]; + struct plchrstr *pcp = plchr + pp->pln_type; + coord sx, sy; + int i; + int dist; + int dir; + s_char *cp; + s_char *p; + s_char buf[1024]; - pr("\n"); - while (1) { - cp = getstarg(player->argp[2], "Target sector? ", buf); - if (!check_plane_ok(pp)) - return -1; - player->argp[2] = 0; - if (!cp || !*cp) - return -1; - if (!sarg_xy(cp, &sx, &sy)) { - pr("Bad sector designation; try again!\n"); - continue; - } - if ((dist = mapdist(pp->pln_x, pp->pln_y, sx, sy)) > - pp->pln_range) { - pr("Range too great; try again!\n"); - continue; - } - break; + pr("\n"); + while (1) { + cp = getstarg(player->argp[2], "Target sector? ", buf); + if (!check_plane_ok(pp)) + return -1; + player->argp[2] = 0; + if (!cp || !*cp) + return -1; + if (!sarg_xy(cp, &sx, &sy)) { + pr("Bad sector designation; try again!\n"); + continue; } - if (opt_ORBIT) { - p = getstring("Geostationary orbit? ", buf); - if (p == 0) - return -1; - if (!check_plane_ok(pp)) - return -1; - pp->pln_theta = 0; - pp->pln_flags |= PLN_SYNCHRONOUS; - if (*p == 0 || *p == 'n') - pp->pln_flags &= ~(PLN_SYNCHRONOUS); - } /* end opt_ORBIT */ - - pr("3... 2... 1... Blastoff!!!\n"); - if (chance(0.07 + (100 - pp->pln_effic)/100.0)) { - pr("KABOOOOM! Range safety officer detonates booster!\n"); - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - return 0; - } - i = pp->pln_tech + pp->pln_effic; - if (chance(1.0 - (i/(i+50.0)))) { - dir = (random() % 6) + 1; - sx += diroff[dir][0]; - sy += diroff[dir][1]; - pr("Your trajectory was a little off.\n"); - } - nreport(player->cnum, N_LAUNCH, 0, 1); - pr("%s positioned over %s", prplane(pp), - xyas(sx, sy, player->cnum)); - if (msl_intercept(sx, sy, pp->pln_own, pcp->pl_def, sublaunch, P_O, 0)) { - return 0; + if ((dist = mapdist(pp->pln_x, pp->pln_y, sx, sy)) > pp->pln_range) { + pr("Range too great; try again!\n"); + continue; } - pp->pln_x = sx; - pp->pln_y = sy; - pp->pln_flags |= PLN_LAUNCHED; - pp->pln_mobil = (pp->pln_mobil > dist) ? - (pp->pln_mobil - dist) : 0; - putplane(pp->pln_uid, pp); - pr(", will be ready for use in %d time units\n", - 127 - pp->pln_mobil); - return -1; + break; + } + if (opt_ORBIT) { + p = getstring("Geostationary orbit? ", buf); + if (p == 0) + return -1; + if (!check_plane_ok(pp)) + return -1; + pp->pln_theta = 0; + pp->pln_flags |= PLN_SYNCHRONOUS; + if (*p == 0 || *p == 'n') + pp->pln_flags &= ~(PLN_SYNCHRONOUS); + } + /* end opt_ORBIT */ + pr("3... 2... 1... Blastoff!!!\n"); + if (chance(0.07 + (100 - pp->pln_effic) / 100.0)) { + pr("KABOOOOM! Range safety officer detonates booster!\n"); + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + pp->pln_own = 0; + return 0; + } + i = pp->pln_tech + pp->pln_effic; + if (chance(1.0 - (i / (i + 50.0)))) { + dir = (random() % 6) + 1; + sx += diroff[dir][0]; + sy += diroff[dir][1]; + pr("Your trajectory was a little off.\n"); + } + nreport(player->cnum, N_LAUNCH, 0, 1); + pr("%s positioned over %s", prplane(pp), xyas(sx, sy, player->cnum)); + if (msl_intercept(sx, sy, pp->pln_own, pcp->pl_def, sublaunch, P_O, 0)) { + return 0; + } + pp->pln_x = sx; + pp->pln_y = sy; + pp->pln_flags |= PLN_LAUNCHED; + pp->pln_mobil = (pp->pln_mobil > dist) ? (pp->pln_mobil - dist) : 0; + putplane(pp->pln_uid, pp); + pr(", will be ready for use in %d time units\n", 127 - pp->pln_mobil); + return -1; } diff --git a/src/lib/commands/lboard.c b/src/lib/commands/lboard.c index faa71d281..6a0d06965 100644 --- a/src/lib/commands/lboard.c +++ b/src/lib/commands/lboard.c @@ -53,33 +53,33 @@ int lboa(void) { - struct combat off[1]; /* boarding sector */ - struct combat def[1]; /* defending land unit */ - struct emp_qelem olist; /* boarding units */ - struct emp_qelem dlist; /* defending units */ - int ototal; /* total boarding strength */ - int a_engineer = 0; /* boarder engineers are present */ - int a_spy = 0; /* the best boarder scout */ - struct sctstr sect; - struct lndstr land; - s_char *p; - s_char buf[1024]; - + struct combat off[1]; /* boarding sector */ + struct combat def[1]; /* defending land unit */ + struct emp_qelem olist; /* boarding units */ + struct emp_qelem dlist; /* defending units */ + int ototal; /* total boarding strength */ + int a_engineer = 0; /* boarder engineers are present */ + int a_spy = 0; /* the best boarder scout */ + struct sctstr sect; + struct lndstr land; + s_char *p; + s_char buf[1024]; + att_combat_init(def, EF_LAND); /* * Collect input from the boarder */ - + /* What are we boarding? */ - + if (!(p = getstarg(player->argp[1], "Victim land unit #? ", buf)) || (def->lnd_uid = atoi(p)) < 0) return RET_SYN; - + /* * Ask the boarder what sector they want to board with */ - + /* Note: if we allow land units to board other land units, we need * to make sure the code will allow that */ if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf))) @@ -90,8 +90,7 @@ lboa(void) return RET_SYN; getsect(off->x, off->y, §); if (sect.sct_own != player->cnum) { - pr("You don't own %s!\n", - xyas(off->x, off->y, player->cnum)); + pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum)); return RET_SYN; } if (sect.sct_mobil <= 0) { @@ -107,51 +106,50 @@ lboa(void) pr("Land unit boarding aborted\n"); return RET_OK; } - + /* Show what we're boarding */ - + if (att_show(def)) return RET_FAIL; - + /* Ask the player what he wants to board with */ - + att_ask_offense(A_LBOARD, off, def, &olist, &a_spy, &a_engineer); if (att_abort(A_LBOARD, off, def)) { pr("Land unit boarding aborted\n"); att_empty_attack(A_LBOARD, 0, def); return att_free_lists(&olist, 0); } - + /* * Estimate the defense strength and give the player a chance to abort */ - + ototal = att_estimate_defense(A_LBOARD, off, &olist, def, a_spy); if (att_abort(A_LBOARD, off, def)) { pr("Land unit boarding aborted\n"); att_empty_attack(A_LBOARD, 0, def); return att_free_lists(&olist, 0); } - + /* * We have now got all the answers from the boarder. From this point * forward, we can assume that this battle is the _only_ thing * happening in the game. */ - + /* Get the real defense */ - + att_get_defense(&olist, def, &dlist, a_spy, ototal); - + /* * Death, carnage, and destruction. */ - - if (!(att_fight(A_LBOARD,off,&olist,1.0,def,&dlist,1.0))) { + + if (!(att_fight(A_LBOARD, off, &olist, 1.0, def, &dlist, 1.0))) { getland(def->lnd_uid, &land); /* Now what? Don't bother retreating? No flag for it (yet) */ } - + return RET_OK; } - diff --git a/src/lib/commands/ldump.c b/src/lib/commands/ldump.c index 2d6f728bc..6072e1046 100644 --- a/src/lib/commands/ldump.c +++ b/src/lib/commands/ldump.c @@ -48,252 +48,405 @@ int ldump(void) { - int nunits; - int field[128]; - struct nstr_item ni; - struct lndstr land; - int vec[I_MAX+1]; - s_char *mission_short_name(); - int n,i; - struct natstr *np; - time_t now; + int nunits; + int field[128]; + struct nstr_item ni; + struct lndstr land; + int vec[I_MAX + 1]; + s_char *mission_short_name(); + int n, i; + struct natstr *np; + time_t now; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - prdate(); - nunits = 0; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + prdate(); + nunits = 0; - if (!player->argp[2]) { - for (n = 1; n <= 39; n++) field[n-1] = n; - field[n-1] = 0; - } else { - n = 2; - i = 0; - while (player->argp[n]) { - if (!strcmp("type",player->argp[n])) { - field[i++] = 1; - } else if (!strcmp("x",player->argp[n])) { - field[i++] = 2; - } else if (!strcmp("y",player->argp[n])) { - field[i++] = 3; - } else if (!strcmp("army",player->argp[n])) { - field[i++] = 4; - } else if (!strcmp("eff",player->argp[n])) { - field[i++] = 5; - } else if (!strcmp("mil",player->argp[n])) { - field[i++] = 6; - } else if (!strcmp("fort",player->argp[n])) { - field[i++] = 7; - } else if (!strcmp("mob",player->argp[n])) { - field[i++] = 8; - } else if (!strcmp("food",player->argp[n])) { - field[i++] = 9; - } else if (!strcmp("fuel",player->argp[n])) { - field[i++] = 10; - } else if (!strcmp("tech",player->argp[n])) { - field[i++] = 11; - } else if (!strcmp("retr",player->argp[n])) { - field[i++] = 12; - } else if (!strcmp("react",player->argp[n])) { - field[i++] = 13; - } else if (!strcmp("xl",player->argp[n])) { - field[i++] = 14; - } else if (!strcmp("nland",player->argp[n])) { - field[i++] = 15; - } else if (!strcmp("land",player->argp[n])) { - field[i++] = 16; - } else if (!strcmp("ship",player->argp[n])) { - field[i++] = 17; - } else if (!strcmp("shell",player->argp[n])) { - field[i++] = 18; - } else if (!strcmp("gun",player->argp[n])) { - field[i++] = 19; - } else if (!strcmp("petrol",player->argp[n])) { - field[i++] = 20; - } else if (!strcmp("iron",player->argp[n])) { - field[i++] = 21; - } else if (!strcmp("dust",player->argp[n])) { - field[i++] = 22; - } else if (!strcmp("bar",player->argp[n])) { - field[i++] = 23; - } else if (!strcmp("oil",player->argp[n])) { - field[i++] = 24; - } else if (!strcmp("lcm",player->argp[n])) { - field[i++] = 25; - } else if (!strcmp("hcm",player->argp[n])) { - field[i++] = 26; - } else if (!strcmp("rad",player->argp[n])) { - field[i++] = 27; - } else if (!strcmp("att",player->argp[n])) { - field[i++] = 28; - } else if (!strcmp("def",player->argp[n])) { - field[i++] = 29; - } else if (!strcmp("vul",player->argp[n])) { - field[i++] = 30; - } else if (!strcmp("spd",player->argp[n])) { - field[i++] = 31; - } else if (!strcmp("vis",player->argp[n])) { - field[i++] = 32; - } else if (!strcmp("spy",player->argp[n])) { - field[i++] = 33; - } else if (!strcmp("radius",player->argp[n])) { - field[i++] = 34; - } else if (!strcmp("frg",player->argp[n])) { - field[i++] = 35; - } else if (!strcmp("acc",player->argp[n])) { - field[i++] = 36; - } else if (!strcmp("dam",player->argp[n])) { - field[i++] = 37; - } else if (!strcmp("amm",player->argp[n])) { - field[i++] = 38; - } else if (!strcmp("aaf",player->argp[n])) { - field[i++] = 39; - } else { - pr("Unrecognized field %s\n",player->argp[n]); - } - if (n++ > 100) { - pr("Too many fields\n"); - return RET_FAIL; - } - } - field[i] = 0; + if (!player->argp[2]) { + for (n = 1; n <= 39; n++) + field[n - 1] = n; + field[n - 1] = 0; + } else { + n = 2; + i = 0; + while (player->argp[n]) { + if (!strcmp("type", player->argp[n])) { + field[i++] = 1; + } else if (!strcmp("x", player->argp[n])) { + field[i++] = 2; + } else if (!strcmp("y", player->argp[n])) { + field[i++] = 3; + } else if (!strcmp("army", player->argp[n])) { + field[i++] = 4; + } else if (!strcmp("eff", player->argp[n])) { + field[i++] = 5; + } else if (!strcmp("mil", player->argp[n])) { + field[i++] = 6; + } else if (!strcmp("fort", player->argp[n])) { + field[i++] = 7; + } else if (!strcmp("mob", player->argp[n])) { + field[i++] = 8; + } else if (!strcmp("food", player->argp[n])) { + field[i++] = 9; + } else if (!strcmp("fuel", player->argp[n])) { + field[i++] = 10; + } else if (!strcmp("tech", player->argp[n])) { + field[i++] = 11; + } else if (!strcmp("retr", player->argp[n])) { + field[i++] = 12; + } else if (!strcmp("react", player->argp[n])) { + field[i++] = 13; + } else if (!strcmp("xl", player->argp[n])) { + field[i++] = 14; + } else if (!strcmp("nland", player->argp[n])) { + field[i++] = 15; + } else if (!strcmp("land", player->argp[n])) { + field[i++] = 16; + } else if (!strcmp("ship", player->argp[n])) { + field[i++] = 17; + } else if (!strcmp("shell", player->argp[n])) { + field[i++] = 18; + } else if (!strcmp("gun", player->argp[n])) { + field[i++] = 19; + } else if (!strcmp("petrol", player->argp[n])) { + field[i++] = 20; + } else if (!strcmp("iron", player->argp[n])) { + field[i++] = 21; + } else if (!strcmp("dust", player->argp[n])) { + field[i++] = 22; + } else if (!strcmp("bar", player->argp[n])) { + field[i++] = 23; + } else if (!strcmp("oil", player->argp[n])) { + field[i++] = 24; + } else if (!strcmp("lcm", player->argp[n])) { + field[i++] = 25; + } else if (!strcmp("hcm", player->argp[n])) { + field[i++] = 26; + } else if (!strcmp("rad", player->argp[n])) { + field[i++] = 27; + } else if (!strcmp("att", player->argp[n])) { + field[i++] = 28; + } else if (!strcmp("def", player->argp[n])) { + field[i++] = 29; + } else if (!strcmp("vul", player->argp[n])) { + field[i++] = 30; + } else if (!strcmp("spd", player->argp[n])) { + field[i++] = 31; + } else if (!strcmp("vis", player->argp[n])) { + field[i++] = 32; + } else if (!strcmp("spy", player->argp[n])) { + field[i++] = 33; + } else if (!strcmp("radius", player->argp[n])) { + field[i++] = 34; + } else if (!strcmp("frg", player->argp[n])) { + field[i++] = 35; + } else if (!strcmp("acc", player->argp[n])) { + field[i++] = 36; + } else if (!strcmp("dam", player->argp[n])) { + field[i++] = 37; + } else if (!strcmp("amm", player->argp[n])) { + field[i++] = 38; + } else if (!strcmp("aaf", player->argp[n])) { + field[i++] = 39; + } else { + pr("Unrecognized field %s\n", player->argp[n]); + } + if (n++ > 100) { + pr("Too many fields\n"); + return RET_FAIL; + } } + field[i] = 0; + } + if (player->god) + pr(" "); + time(&now); + pr("DUMP LAND UNITS %d\n", now); + if (player->god) + pr("own "); + pr("id"); + n = 0; + while (field[n]) { + switch (field[n]) { + case 1: + pr(" type"); + break; + case 2: + pr(" x"); + break; + case 3: + pr(" y"); + break; + case 4: + pr(" army"); + break; + case 5: + pr(" eff"); + break; + case 6: + pr(" mil"); + break; + case 7: + pr(" fort"); + break; + case 8: + pr(" mob"); + break; + case 9: + pr(" food"); + break; + case 10: + pr(" fuel"); + break; + case 11: + pr(" tech"); + break; + case 12: + pr(" retr"); + break; + case 13: + pr(" react"); + break; + case 14: + pr(" xl"); + break; + case 15: + pr(" nland"); + break; + case 16: + pr(" land"); + break; + case 17: + pr(" ship"); + break; + case 18: + pr(" shell"); + break; + case 19: + pr(" gun"); + break; + case 20: + pr(" petrol"); + break; + case 21: + pr(" iron"); + break; + case 22: + pr(" dust"); + break; + case 23: + pr(" bar"); + break; + case 24: + pr(" oil"); + break; + case 25: + pr(" lcm"); + break; + case 26: + pr(" hcm"); + break; + case 27: + pr(" rad"); + break; + case 28: + pr(" att"); + break; + case 29: + pr(" def"); + break; + case 30: + pr(" vul"); + break; + case 31: + pr(" spd"); + break; + case 32: + pr(" vis"); + break; + case 33: + pr(" spy"); + break; + case 34: + pr(" radius"); + break; + case 35: + pr(" frg"); + break; + case 36: + pr(" acc"); + break; + case 37: + pr(" dam"); + break; + case 38: + pr(" amm"); + break; + case 39: + pr(" aaf"); + break; + } + n++; + } + pr("\n"); + + np = getnatp(player->cnum); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (!player->owner && !player->god) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; + } + count_land_planes(&land); + lnd_count_units(&land); + + nunits++; if (player->god) - pr(" "); - time(&now); - pr("DUMP LAND UNITS %d\n", now); - if (player->god) - pr("own "); - pr("id"); + pr("%3d ", land.lnd_own); + pr("%d", ni.cur); n = 0; + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); while (field[n]) { - switch (field[n]) { - case 1: pr(" type"); break; - case 2: pr(" x"); break; - case 3: pr(" y"); break; - case 4: pr(" army"); break; - case 5: pr(" eff"); break; - case 6: pr(" mil"); break; - case 7: pr(" fort"); break; - case 8: pr(" mob"); break; - case 9: pr(" food"); break; - case 10: pr(" fuel"); break; - case 11: pr(" tech"); break; - case 12: pr(" retr"); break; - case 13: pr(" react"); break; - case 14: pr(" xl"); break; - case 15: pr(" nland"); break; - case 16: pr(" land"); break; - case 17: pr(" ship"); break; - case 18: pr(" shell"); break; - case 19: pr(" gun"); break; - case 20: pr(" petrol"); break; - case 21: pr(" iron"); break; - case 22: pr(" dust"); break; - case 23: pr(" bar"); break; - case 24: pr(" oil"); break; - case 25: pr(" lcm"); break; - case 26: pr(" hcm"); break; - case 27: pr(" rad"); break; - case 28: pr(" att"); break; - case 29: pr(" def"); break; - case 30: pr(" vul"); break; - case 31: pr(" spd"); break; - case 32: pr(" vis"); break; - case 33: pr(" spy"); break; - case 34: pr(" radius"); break; - case 35: pr(" frg"); break; - case 36: pr(" acc"); break; - case 37: pr(" dam"); break; - case 38: pr(" amm"); break; - case 39: pr(" aaf"); break; - } - n++; + switch (field[n++]) { + case 1: + pr(" %0.4s", lchr[(int)land.lnd_type].l_name); + break; + case 2: + pr(" %d", xrel(np, land.lnd_x)); + break; + case 3: + pr(" %d", yrel(np, land.lnd_y)); + break; + case 4: + if (land.lnd_army == ' ') + pr(" ~"); + else + pr(" %c", land.lnd_army); + break; + case 5: + pr(" %d", land.lnd_effic); + break; + case 6: + pr(" %d", lnd_getmil(&land)); + break; + case 7: + pr(" %d", land.lnd_harden); + break; + case 8: + pr(" %d", land.lnd_mobil); + break; + case 9: + pr(" %d", vec[I_FOOD]); + break; + case 10: + if (opt_FUEL) + pr(" %d", land.lnd_fuel); + else + pr(" 0"); + break; + case 11: + pr(" %d", land.lnd_tech); + break; + case 12: + pr(" %d", land.lnd_retreat); + break; + case 13: + pr(" %d", land.lnd_rad_max); + break; + case 14: + pr(" %d", land.lnd_nxlight); + break; + case 15: + pr(" %d", land.lnd_nland); + break; + case 16: + pr(" %d", land.lnd_land); + break; + case 17: + pr(" %d", land.lnd_ship); + break; + case 18: + pr(" %d", vec[I_SHELL]); + break; + case 19: + pr(" %d", vec[I_GUN]); + break; + case 20: + pr(" %d", vec[I_PETROL]); + break; + case 21: + pr(" %d", vec[I_IRON]); + break; + case 22: + pr(" %d", vec[I_DUST]); + break; + case 23: + pr(" %d", vec[I_BAR]); + break; + case 24: + pr(" %d", vec[I_OIL]); + break; + case 25: + pr(" %d", vec[I_LCM]); + break; + case 26: + pr(" %d", vec[I_HCM]); + break; + case 27: + pr(" %d", vec[I_RAD]); + break; + case 28: + pr(" %1.2f", (float)land.lnd_att); + break; + case 29: + pr(" %1.2f", (float)land.lnd_def); + break; + case 30: + pr(" %d", land.lnd_vul); + break; + case 31: + pr(" %d", land.lnd_spd); + break; + case 32: + pr(" %d", land.lnd_vis); + break; + case 33: + pr(" %d", land.lnd_spy); + break; + case 34: + pr(" %d", land.lnd_rad); + break; + case 35: + pr(" %d", land.lnd_frg); + break; + case 36: + pr(" %d", land.lnd_acc); + break; + case 37: + pr(" %d", land.lnd_dam); + break; + case 38: + pr(" %d", land.lnd_ammo); + break; + case 39: + pr(" %d", land.lnd_aaf); + break; + } } pr("\n"); - - np = getnatp(player->cnum); - while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own == 0) - continue; - if (!player->owner && !player->god) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", - land.lnd_type, ni.cur); - continue; - } - count_land_planes(&land); - lnd_count_units(&land); - - nunits++; - if (player->god) - pr("%3d ", land.lnd_own); - pr("%d", ni.cur); - n = 0; - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - while (field[n]) { - switch (field[n++]) { - case 1: pr(" %0.4s",lchr[(int)land.lnd_type].l_name); break; - case 2: pr(" %d", xrel(np, land.lnd_x)); break; - case 3: pr(" %d", yrel(np, land.lnd_y)); break; - case 4: if (land.lnd_army == ' ') - pr(" ~"); - else - pr(" %c", land.lnd_army); - break; - case 5: pr(" %d", land.lnd_effic); break; - case 6: pr(" %d", lnd_getmil(&land)); break; - case 7: pr(" %d", land.lnd_harden); break; - case 8: pr(" %d", land.lnd_mobil); break; - case 9: pr(" %d", vec[I_FOOD]); break; - case 10: if (opt_FUEL) - pr(" %d",land.lnd_fuel); - else - pr(" 0"); - break; - case 11: pr(" %d", land.lnd_tech); break; - case 12: pr(" %d", land.lnd_retreat); break; - case 13: pr(" %d", land.lnd_rad_max); break; - case 14: pr(" %d", land.lnd_nxlight); break; - case 15: pr(" %d", land.lnd_nland); break; - case 16: pr(" %d", land.lnd_land); break; - case 17: pr(" %d", land.lnd_ship); break; - case 18: pr(" %d", vec[I_SHELL]); break; - case 19: pr(" %d", vec[I_GUN]); break; - case 20: pr(" %d", vec[I_PETROL]); break; - case 21: pr(" %d", vec[I_IRON]); break; - case 22: pr(" %d", vec[I_DUST]); break; - case 23: pr(" %d", vec[I_BAR]); break; - case 24: pr(" %d", vec[I_OIL]); break; - case 25: pr(" %d", vec[I_LCM]); break; - case 26: pr(" %d", vec[I_HCM]); break; - case 27: pr(" %d", vec[I_RAD]); break; - case 28: pr(" %1.2f", (float)land.lnd_att); break; - case 29: pr(" %1.2f", (float)land.lnd_def); break; - case 30: pr(" %d", land.lnd_vul); break; - case 31: pr(" %d", land.lnd_spd); break; - case 32: pr(" %d", land.lnd_vis); break; - case 33: pr(" %d", land.lnd_spy); break; - case 34: pr(" %d", land.lnd_rad); break; - case 35: pr(" %d", land.lnd_frg); break; - case 36: pr(" %d", land.lnd_acc); break; - case 37: pr(" %d", land.lnd_dam); break; - case 38: pr(" %d", land.lnd_ammo); break; - case 39: pr(" %d", land.lnd_aaf); break; - } - } - pr("\n"); - } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } - diff --git a/src/lib/commands/ledg.c b/src/lib/commands/ledg.c index e964c93cd..9cf525191 100644 --- a/src/lib/commands/ledg.c +++ b/src/lib/commands/ledg.c @@ -44,25 +44,25 @@ int ledg(void) { - struct nstr_item nstr; - struct lonstr loan; - int nloan; + struct nstr_item nstr; + struct lonstr loan; + int nloan; - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; - } - if (!snxtitem(&nstr, EF_LOAN, player->argp[1])) - return RET_SYN; - pr("\n... %s Ledger ...\n", cname(player->cnum)); - nloan = 0; - while (nxtitem(&nstr, (s_char *)&loan)) { - if (disloan(nstr.cur, &loan) > 0) - nloan++; - } - if (!nloan) - pr("No loans found\n"); - else - pr("%d loan%s outstanding.\n", nloan, splur(nloan)); - return RET_OK; + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; + } + if (!snxtitem(&nstr, EF_LOAN, player->argp[1])) + return RET_SYN; + pr("\n... %s Ledger ...\n", cname(player->cnum)); + nloan = 0; + while (nxtitem(&nstr, (s_char *)&loan)) { + if (disloan(nstr.cur, &loan) > 0) + nloan++; + } + if (!nloan) + pr("No loans found\n"); + else + pr("%d loan%s outstanding.\n", nloan, splur(nloan)); + return RET_OK; } diff --git a/src/lib/commands/leve.c b/src/lib/commands/leve.c index bb3d655f1..874eb292a 100644 --- a/src/lib/commands/leve.c +++ b/src/lib/commands/leve.c @@ -46,53 +46,53 @@ int leve(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; - int dist[I_MAX+1]; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; + int dist[I_MAX + 1]; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) { - pr("DISTRIBUTION LEVELS\n"); - if (player->god) - pr("own"); - pr(" sect dst civ mil uw food sh gun pet iron dust bar oil lcm hcm rad\n"); - } - if (player->god) - pr("%2d ", sect.sct_own); - getvec(VT_DIST, dist, (s_char *)§, EF_SECTOR); - prxy("%3d,%-3d", nstr.x, nstr.y, player->cnum); - pr(" %c ", dchr[sect.sct_type].d_mnem); - prxy("%3d,%-3d", sect.sct_dist_x,sect.sct_dist_y,player->cnum); - pr(" %4d", dist[I_CIVIL]); - pr("%4d", dist[I_MILIT]); - pr("%4d", dist[I_UW]); - pr("%5d", dist[I_FOOD]); - pr("%4d", dist[I_SHELL]); - pr("%4d", dist[I_GUN]); - pr("%4d", dist[I_PETROL]); - pr("%5d", dist[I_IRON]); - pr("%5d", dist[I_DUST]); - pr("%4d", dist[I_BAR]); - pr("%4d", dist[I_OIL]); - pr("%4d", dist[I_LCM]); - pr("%4d", dist[I_HCM]); - pr("%4d", dist[I_RAD]); - pr("\n"); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) { + pr("DISTRIBUTION LEVELS\n"); + if (player->god) + pr("own"); + pr(" sect dst civ mil uw food sh gun pet iron dust bar oil lcm hcm rad\n"); } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + if (player->god) + pr("%2d ", sect.sct_own); + getvec(VT_DIST, dist, (s_char *)§, EF_SECTOR); + prxy("%3d,%-3d", nstr.x, nstr.y, player->cnum); + pr(" %c ", dchr[sect.sct_type].d_mnem); + prxy("%3d,%-3d", sect.sct_dist_x, sect.sct_dist_y, player->cnum); + pr(" %4d", dist[I_CIVIL]); + pr("%4d", dist[I_MILIT]); + pr("%4d", dist[I_UW]); + pr("%5d", dist[I_FOOD]); + pr("%4d", dist[I_SHELL]); + pr("%4d", dist[I_GUN]); + pr("%4d", dist[I_PETROL]); + pr("%5d", dist[I_IRON]); + pr("%5d", dist[I_DUST]); + pr("%4d", dist[I_BAR]); + pr("%4d", dist[I_OIL]); + pr("%4d", dist[I_LCM]); + pr("%4d", dist[I_HCM]); + pr("%4d", dist[I_RAD]); + pr("\n"); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index 17b31bd53..9c7bdfd90 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -43,8 +43,8 @@ #include "var.h" #include "sect.h" #include "ship.h" -#include "plane.h" -#include "land.h" +#include "plane.h" +#include "land.h" #include "item.h" #include "nsc.h" #include "nat.h" @@ -58,265 +58,294 @@ #define UNLOAD -1 void gift(int givee, int giver, s_char *ptr, int type, s_char *mesg); -static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp); -static int load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp); -static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp, struct ichrstr *ich, int load_unload, int *nshipsp); -static int load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp); -static int load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp); -static int load_comm_land(struct sctstr *sectp, struct lndstr *lp, struct ichrstr *ich, int load_unload, int *nunitsp); +static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp, + int noisy, int load_unload, int *nshipsp); +static int load_land_ship(struct sctstr *sectp, struct shpstr *sp, + int noisy, int load_unload, int *nshipsp); +static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp, + struct ichrstr *ich, int load_unload, + int *nshipsp); +static int load_plane_land(struct sctstr *sectp, struct lndstr *lp, + int noisy, int load_unload, int *nunitsp); +static int load_land_land(struct sctstr *sectp, struct lndstr *lp, + int noisy, int load_unload, int *nunitsp); +static int load_comm_land(struct sctstr *sectp, struct lndstr *lp, + struct ichrstr *ich, int load_unload, + int *nunitsp); int load(void) { - int noisy; - int load_unload; - int type; - struct nstr_item nbst; - struct ichrstr *ich; - int nships; - struct sctstr sect; - struct shpstr ship; - int retval; - s_char *p; - s_char buf[1024]; - - if (!(p = getstarg(player->argp[1], - "What commodity (or 'plane' or 'land')? ", buf)) || !*p) - return RET_SYN; - - if (!strncmp(p, "plane", 5)) - type = EF_PLANE; - else if (!strncmp(p, "land", 4)) - type = EF_LAND; - else if (NULL != (ich = whatitem(p, (s_char *)0))) - type = EF_SECTOR; - else { - pr("Bad commodity.\n"); - return RET_SYN; - } + int noisy; + int load_unload; + int type; + struct nstr_item nbst; + struct ichrstr *ich; + int nships; + struct sctstr sect; + struct shpstr ship; + int retval; + s_char *p; + s_char buf[1024]; + + if (!(p = getstarg(player->argp[1], + "What commodity (or 'plane' or 'land')? ", buf)) + || !*p) + return RET_SYN; - if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p) - return RET_SYN; + if (!strncmp(p, "plane", 5)) + type = EF_PLANE; + else if (!strncmp(p, "land", 4)) + type = EF_LAND; + else if (NULL != (ich = whatitem(p, (s_char *)0))) + type = EF_SECTOR; + else { + pr("Bad commodity.\n"); + return RET_SYN; + } - noisy = isdigit(*p); + if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p) + return RET_SYN; - if (!snxtitem(&nbst, EF_SHIP, p)) - return RET_SYN; + noisy = isdigit(*p); - nbst.flags &= ~(EFF_OWNER); + if (!snxtitem(&nbst, EF_SHIP, p)) + return RET_SYN; - load_unload = **player->argp == 'l' ? LOAD : UNLOAD; + nbst.flags &= ~(EFF_OWNER); - nships = 0; - while (nxtitem(&nbst, (s_char *)&ship)) { - if (!ship.shp_own) - continue; - if (!player->owner && (load_unload == UNLOAD)) { - continue; - } - if (opt_MARKET) { - if (ontradingblock(EF_SHIP, (int *)&ship)) { - pr("You cannot load/unload an item on the trading block!\n"); - continue; - } - } + load_unload = **player->argp == 'l' ? LOAD : UNLOAD; - if (ship.shp_own != player->cnum) { - if (!noisy) - continue; - if (getrel(getnatp(player->cnum),ship.shp_own) < FRIENDLY) - continue; - } - if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */ - continue; - if ((sect.sct_own != player->cnum) && - (ship.shp_own != player->cnum)) - continue; - if (!player->owner && - sect.sct_type != SCT_HARBR && - (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) - continue; - if (!sect.sct_own) - continue; - if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) { - if (noisy) - pr("You don't own %s \n", - xyas(ship.shp_x, ship.shp_y, player->cnum)); - continue; - } - if (sect.sct_type != SCT_HARBR && - (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) { - if (noisy) - pr("Sector %s is not a harbor%s.\n", - xyas(ship.shp_x, ship.shp_y, player->cnum), - opt_BIG_CITY?" or a city":""); - continue; - } - if (sect.sct_own != player->cnum && load_unload == UNLOAD && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) { - if (noisy) - pr("You can't unload into an unfriendly %s\n", - dchr[sect.sct_type].d_name); - continue; - } - if (sect.sct_effic < 2) { - if (noisy) - pr("The %s at %s is not 2%% efficient yet.\n", - dchr[sect.sct_type].d_name, - xyas(ship.shp_x, ship.shp_y, player->cnum)); - continue; - } - switch (type) { - case EF_PLANE: - if (0 != (retval=load_plane_ship(§, &ship, noisy, load_unload, &nships))) - return retval; - break; - case EF_LAND: - if (0 != (retval=load_land_ship(§, &ship, noisy, load_unload, &nships))) - return retval; - break; - case EF_SECTOR: - if (0 != (retval=load_comm_ship(§, &ship, ich, load_unload, &nships))) - return retval; - } - /* load/unload plague */ - if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP); - if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); - putsect(§); - putship(ship.shp_uid, &ship); + nships = 0; + while (nxtitem(&nbst, (s_char *)&ship)) { + if (!ship.shp_own) + continue; + if (!player->owner && (load_unload == UNLOAD)) { + continue; + } + if (opt_MARKET) { + if (ontradingblock(EF_SHIP, (int *)&ship)) { + pr("You cannot load/unload an item on the trading block!\n"); + continue; + } + } + + if (ship.shp_own != player->cnum) { + if (!noisy) + continue; + if (getrel(getnatp(player->cnum), ship.shp_own) < FRIENDLY) + continue; + } + if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */ + continue; + if ((sect.sct_own != player->cnum) && + (ship.shp_own != player->cnum)) + continue; + if (!player->owner && + sect.sct_type != SCT_HARBR && + (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) + continue; + if (!sect.sct_own) + continue; + if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) { + if (noisy) + pr("You don't own %s \n", + xyas(ship.shp_x, ship.shp_y, player->cnum)); + continue; + } + if (sect.sct_type != SCT_HARBR && + (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) { + if (noisy) + pr("Sector %s is not a harbor%s.\n", + xyas(ship.shp_x, ship.shp_y, player->cnum), + opt_BIG_CITY ? " or a city" : ""); + continue; + } + if (sect.sct_own != player->cnum && load_unload == UNLOAD + && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) { + if (noisy) + pr("You can't unload into an unfriendly %s\n", + dchr[sect.sct_type].d_name); + continue; } - if (!nships) - pr("No ships affected\n"); - else - pr("%d ship%s %sloaded\n", nships, splur(nships), - load_unload == UNLOAD ? "un" : ""); - return RET_OK; + if (sect.sct_effic < 2) { + if (noisy) + pr("The %s at %s is not 2%% efficient yet.\n", + dchr[sect.sct_type].d_name, + xyas(ship.shp_x, ship.shp_y, player->cnum)); + continue; + } + switch (type) { + case EF_PLANE: + if (0 != + (retval = + load_plane_ship(§, &ship, noisy, load_unload, + &nships))) + return retval; + break; + case EF_LAND: + if (0 != + (retval = + load_land_ship(§, &ship, noisy, load_unload, + &nships))) + return retval; + break; + case EF_SECTOR: + if (0 != + (retval = + load_comm_ship(§, &ship, ich, load_unload, &nships))) + return retval; + } + /* load/unload plague */ + if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP); + if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); + putsect(§); + putship(ship.shp_uid, &ship); + } + if (!nships) + pr("No ships affected\n"); + else + pr("%d ship%s %sloaded\n", nships, splur(nships), + load_unload == UNLOAD ? "un" : ""); + return RET_OK; } int lload(void) { - int noisy; - int load_unload; - int type; - struct nstr_item nbst; - struct ichrstr *ich; - int nunits; - struct sctstr sect; - struct lndstr land; - int retval; - s_char *p; - s_char buf[1024]; - - if (!(p = getstarg(player->argp[1], - "What commodity (or 'plane' or 'land')? ", buf)) || !*p) - return RET_SYN; - if (!strncmp(p, "plane", 5)) - type = EF_PLANE; - else if (!strncmp(p, "land", 4)) - type = EF_LAND; - else if (NULL != (ich = whatitem(p, (s_char *)0))) - type = EF_SECTOR; - else { - pr("Bad commodity.\n"); - return RET_SYN; - } + int noisy; + int load_unload; + int type; + struct nstr_item nbst; + struct ichrstr *ich; + int nunits; + struct sctstr sect; + struct lndstr land; + int retval; + s_char *p; + s_char buf[1024]; + + if (!(p = getstarg(player->argp[1], + "What commodity (or 'plane' or 'land')? ", buf)) + || !*p) + return RET_SYN; + if (!strncmp(p, "plane", 5)) + type = EF_PLANE; + else if (!strncmp(p, "land", 4)) + type = EF_LAND; + else if (NULL != (ich = whatitem(p, (s_char *)0))) + type = EF_SECTOR; + else { + pr("Bad commodity.\n"); + return RET_SYN; + } - if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p) - return RET_SYN; + if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p) + return RET_SYN; - noisy = isdigit(*p); + noisy = isdigit(*p); - if (!snxtitem(&nbst, EF_LAND, p)) - return RET_SYN; + if (!snxtitem(&nbst, EF_LAND, p)) + return RET_SYN; - load_unload = *(*player->argp+1) == 'l' ? LOAD : UNLOAD; + load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD; - nbst.flags &= ~(EFF_OWNER); + nbst.flags &= ~(EFF_OWNER); - nunits = 0; - while (nxtitem(&nbst, (s_char *)&land)) { - if (land.lnd_own == 0) - continue; + nunits = 0; + while (nxtitem(&nbst, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; - if (player->cnum != land.lnd_own && - getrel(getnatp(player->cnum), land.lnd_own) != ALLIED) - continue; + if (player->cnum != land.lnd_own && + getrel(getnatp(player->cnum), land.lnd_own) != ALLIED) + continue; - if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */ - continue; + if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */ + continue; - if (sect.sct_own != player->cnum && - land.lnd_own != player->cnum) - continue; - if (opt_MARKET) { - if (ontradingblock(EF_LAND, (int *)&land)) { - pr("You cannot load/unload an item on the trading block!\n"); - continue; - } - } + if (sect.sct_own != player->cnum && land.lnd_own != player->cnum) + continue; + if (opt_MARKET) { + if (ontradingblock(EF_LAND, (int *)&land)) { + pr("You cannot load/unload an item on the trading block!\n"); + continue; + } + } - if (sect.sct_own != player->cnum && - getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) { - pr("Sector %s is not yours.\n", - xyas(land.lnd_x, land.lnd_y, player->cnum)); - continue; - } - switch (type) { - case EF_LAND: - if (0 != (retval=load_land_land(§, &land, noisy, load_unload, &nunits))) - return retval; - break; - case EF_PLANE: - if (0 != (retval=load_plane_land(§, &land, noisy, load_unload, &nunits))) - return retval; - break; - case EF_SECTOR: - if (0 != (retval=load_comm_land(§, &land, ich, load_unload, &nunits))) - return retval; - } - /* load/unload plague */ - if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND); - if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); - - putsect(§); - putland(land.lnd_uid, &land); + if (sect.sct_own != player->cnum && + getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) { + pr("Sector %s is not yours.\n", + xyas(land.lnd_x, land.lnd_y, player->cnum)); + continue; } - if (nunits == 0) - pr("No units affected\n"); - else - pr("%d unit%s %sloaded\n", nunits, splur(nunits), - load_unload == UNLOAD ? "un" : ""); - return RET_OK; + switch (type) { + case EF_LAND: + if (0 != + (retval = + load_land_land(§, &land, noisy, load_unload, + &nunits))) + return retval; + break; + case EF_PLANE: + if (0 != + (retval = + load_plane_land(§, &land, noisy, load_unload, + &nunits))) + return retval; + break; + case EF_SECTOR: + if (0 != + (retval = + load_comm_land(§, &land, ich, load_unload, &nunits))) + return retval; + } + /* load/unload plague */ + if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND); + if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); + + putsect(§); + putland(land.lnd_uid, &land); + } + if (nunits == 0) + pr("No units affected\n"); + else + pr("%d unit%s %sloaded\n", nunits, splur(nunits), + load_unload == UNLOAD ? "un" : ""); + return RET_OK; } void gift(int givee, int giver, s_char *ptr, int type, s_char *mesg) { - s_char *p, line[256]; - - if (giver == givee) - return; - - - switch(type) { - case EF_SHIP: p = prship((struct shpstr *)ptr); - break; - case EF_PLANE: p = prplane((struct plnstr *)ptr); - break; - case EF_LAND: p = prland((struct lndstr *)ptr); - break; - } + s_char *p, line[256]; + + if (giver == givee) + return; + + + switch (type) { + case EF_SHIP: + p = prship((struct shpstr *)ptr); + break; + case EF_PLANE: + p = prplane((struct plnstr *)ptr); + break; + case EF_LAND: + p = prland((struct lndstr *)ptr); + break; + } - sprintf(line,"%s %s %s\n",cname(giver),p,mesg); - wu(0,givee,line); + sprintf(line, "%s %s %s\n", cname(giver), p, mesg); + wu(0, givee, line); } static int @@ -340,152 +369,151 @@ still_ok_land(struct sctstr *sectp, struct lndstr *landp) } static int -load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp) +load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, + int load_unload, int *nshipsp) { - struct nstr_item ni; - struct plnstr pln; - int loaded = 0; - s_char buf[1024]; - s_char *p; - s_char prompt[512]; - struct mchrstr *mcp = mchr + sp->shp_type; - - if (!(mcp->m_flags & (M_CHOPPER|M_XLIGHT|M_FLY|M_MSL))) { - if (noisy) - pr("%s cannot carry planes\n", prship(sp)); - return 0; - } - count_planes(sp); - if (load_unload==LOAD && - sp->shp_nchoppers >= mcp->m_nchoppers && - sp->shp_nxlight >= mcp->m_nxlight && - sp->shp_nplane >= mcp->m_nplanes) { - if (noisy) - pr("%s doesn't have room for any more planes\n", - prship(sp)); - return 0; - } - sprintf(prompt, "Plane(s) to %s %s? ", - load_unload==LOAD?"load onto":"unload from", - prship(sp)); - if (!snxtitem(&ni, EF_PLANE, p=getstarg(player->argp[3], prompt, buf))) - return RET_SYN; + struct nstr_item ni; + struct plnstr pln; + int loaded = 0; + s_char buf[1024]; + s_char *p; + s_char prompt[512]; + struct mchrstr *mcp = mchr + sp->shp_type; + + if (!(mcp->m_flags & (M_CHOPPER | M_XLIGHT | M_FLY | M_MSL))) { + if (noisy) + pr("%s cannot carry planes\n", prship(sp)); + return 0; + } + count_planes(sp); + if (load_unload == LOAD && + sp->shp_nchoppers >= mcp->m_nchoppers && + sp->shp_nxlight >= mcp->m_nxlight && + sp->shp_nplane >= mcp->m_nplanes) { + if (noisy) + pr("%s doesn't have room for any more planes\n", prship(sp)); + return 0; + } + sprintf(prompt, "Plane(s) to %s %s? ", + load_unload == LOAD ? "load onto" : "unload from", prship(sp)); + if (!snxtitem + (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf))) + return RET_SYN; - if (!still_ok_ship(sectp, sp)) - return RET_SYN; + if (!still_ok_ship(sectp, sp)) + return RET_SYN; - if (p && *p) - noisy &= isdigit(*p); + if (p && *p) + noisy &= isdigit(*p); - while(nxtitem(&ni, (s_char *)&pln)) { - if (pln.pln_own != player->cnum) - continue; - if (!(plchr[(int)pln.pln_type].pl_flags & P_L) - && !(plchr[(int)pln.pln_type].pl_flags & P_E) - && !(plchr[(int)pln.pln_type].pl_flags & P_K) - && !(plchr[(int)pln.pln_type].pl_flags & P_M) - ) { - if (noisy) - pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n"); - continue; - } - if (load_unload == LOAD && pln.pln_ship > -1) { - if (noisy) - pr("%s is already on ship #%d!\n", - prplane(&pln), pln.pln_ship); - continue; - } - if (load_unload == LOAD && pln.pln_land > -1) { - if (noisy) - pr("%s is already on land unit #%d!\n", - prplane(&pln), pln.pln_land); - continue; - } + while (nxtitem(&ni, (s_char *)&pln)) { + if (pln.pln_own != player->cnum) + continue; + if (!(plchr[(int)pln.pln_type].pl_flags & P_L) + && !(plchr[(int)pln.pln_type].pl_flags & P_E) + && !(plchr[(int)pln.pln_type].pl_flags & P_K) + && !(plchr[(int)pln.pln_type].pl_flags & P_M) + ) { + if (noisy) + pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n"); + continue; + } + if (load_unload == LOAD && pln.pln_ship > -1) { + if (noisy) + pr("%s is already on ship #%d!\n", + prplane(&pln), pln.pln_ship); + continue; + } + if (load_unload == LOAD && pln.pln_land > -1) { + if (noisy) + pr("%s is already on land unit #%d!\n", + prplane(&pln), pln.pln_land); + continue; + } - /* Plane sanity done */ - /* Find the right ship */ - if (load_unload == UNLOAD) { - if (pln.pln_ship != sp->shp_uid) - continue; - } else if (sp->shp_x != pln.pln_x - || sp->shp_y != pln.pln_y) - continue; + /* Plane sanity done */ + /* Find the right ship */ + if (load_unload == UNLOAD) { + if (pln.pln_ship != sp->shp_uid) + continue; + } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y) + continue; - /* ship to (plane or missle) sanity */ - if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) { - if (plchr[(int)pln.pln_type].pl_flags & P_L) { - strcpy(buf, "planes"); - } else if (plchr[(int)pln.pln_type].pl_flags & P_K) { - strcpy(buf, "choppers"); - } else if (plchr[(int)pln.pln_type].pl_flags & P_M) { - strcpy(buf, "missiles"); - } else if (plchr[(int)pln.pln_type].pl_flags & P_E) { - strcpy(buf, "extra light planes"); - } /* else impossible */ - if (noisy) - pr("%s cannot carry %s.\n", - prship(sp), - buf); - continue; - } - /* Fit plane on ship */ - if (load_unload == LOAD){ - if (!put_plane_on_ship(&pln,sp)){ - if (noisy) - pr("Can't put plane %d on this ship!\n",pln.pln_uid); - continue; - } - sprintf(buf, "loaded on your %s at %s", - prship(sp),xyas(sp->shp_x, - sp->shp_y, sp->shp_own)); - gift(sp->shp_own, player->cnum, (s_char *)&pln, - EF_PLANE, buf); - makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - pln.pln_own = sp->shp_own; - makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - pln.pln_mission = 0; - putplane(pln.pln_uid,&pln); - } else { - if (!take_plane_off_ship(&pln,sp)) { - pr("Unable to take plane off ship!\n"); - logerror("load: plane %d could not be taken off ship %d\n",pln.pln_uid,sp->shp_uid); - continue; - } - sprintf(buf, "unloaded in your %s at %s", - dchr[sectp->sct_type].d_name, - xyas(sectp->sct_x,sectp->sct_y, - sectp->sct_own)); - gift(sectp->sct_own, player->cnum, (s_char *)&pln, - EF_PLANE, buf); - makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - pln.pln_own = sectp->sct_own; - makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - putplane(pln.pln_uid,&pln); - } - pr("%s %s %s at %s.\n", - prplane(&pln), - (load_unload==UNLOAD)? - "unloaded from":"loaded onto", - prship(sp), - xyas(sp->shp_x, sp->shp_y, player->cnum)); - loaded = 1; + /* ship to (plane or missle) sanity */ + if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) { + if (plchr[(int)pln.pln_type].pl_flags & P_L) { + strcpy(buf, "planes"); + } else if (plchr[(int)pln.pln_type].pl_flags & P_K) { + strcpy(buf, "choppers"); + } else if (plchr[(int)pln.pln_type].pl_flags & P_M) { + strcpy(buf, "missiles"); + } else if (plchr[(int)pln.pln_type].pl_flags & P_E) { + strcpy(buf, "extra light planes"); + } /* else impossible */ + if (noisy) + pr("%s cannot carry %s.\n", prship(sp), buf); + continue; } - *nshipsp += loaded; - return 0; + /* Fit plane on ship */ + if (load_unload == LOAD) { + if (!put_plane_on_ship(&pln, sp)) { + if (noisy) + pr("Can't put plane %d on this ship!\n", pln.pln_uid); + continue; + } + sprintf(buf, "loaded on your %s at %s", + prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + gift(sp->shp_own, player->cnum, (s_char *)&pln, EF_PLANE, buf); + makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + pln.pln_own = sp->shp_own; + makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + pln.pln_mission = 0; + putplane(pln.pln_uid, &pln); + } else { + if (!take_plane_off_ship(&pln, sp)) { + pr("Unable to take plane off ship!\n"); + logerror("load: plane %d could not be taken off ship %d\n", + pln.pln_uid, sp->shp_uid); + continue; + } + sprintf(buf, "unloaded in your %s at %s", + dchr[sectp->sct_type].d_name, + xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); + gift(sectp->sct_own, player->cnum, (s_char *)&pln, + EF_PLANE, buf); + makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + pln.pln_own = sectp->sct_own; + makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + putplane(pln.pln_uid, &pln); + } + pr("%s %s %s at %s.\n", + prplane(&pln), + (load_unload == UNLOAD) ? + "unloaded from" : "loaded onto", + prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); + loaded = 1; + } + *nshipsp += loaded; + return 0; } static int -load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp) +load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, + int load_unload, int *nshipsp) { - struct nstr_item pni, ni; - struct lndstr land; - struct plnstr plane; - int loaded = 0; - s_char *p; - s_char prompt[512]; - s_char buf[1024]; - int load_spy = 0; - + struct nstr_item pni, ni; + struct lndstr land; + struct plnstr plane; + int loaded = 0; + s_char *p; + s_char prompt[512]; + s_char buf[1024]; + int load_spy = 0; + count_units(sp); if (load_unload == LOAD) { if (opt_LANDSPIES) { @@ -499,33 +527,34 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo load_spy = 1; } } - if ((!load_spy) && + if ((!load_spy) && (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) { if (noisy) { if (mchr[(int)sp->shp_type].m_nland) - pr("%s doesn't have room for any more land units!\n",prship(sp)); + pr("%s doesn't have room for any more land units!\n", + prship(sp)); else - pr("%s cannot carry land units!\n",prship(sp)); + pr("%s cannot carry land units!\n", prship(sp)); } return 0; } } sprintf(prompt, "Land unit(s) to %s %s? ", - load_unload==LOAD?"load onto":"unload from", - prship(sp)); - if (!snxtitem(&ni, EF_LAND, p=getstarg(player->argp[3], prompt, buf))) + load_unload == LOAD ? "load onto" : "unload from", prship(sp)); + if (!snxtitem + (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf))) return RET_SYN; - + if (!still_ok_ship(sectp, sp)) return RET_SYN; - + if (p && *p) noisy &= isdigit(*p); - - while(nxtitem(&ni, (s_char *)&land)) { + + while (nxtitem(&ni, (s_char *)&land)) { if (land.lnd_own != player->cnum) continue; - + if (load_unload == LOAD) { if (land.lnd_ship > -1) { if (noisy) @@ -557,7 +586,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo continue; } } - + /* Unit sanity done */ /* Find the right ship */ if (load_unload == UNLOAD) { @@ -565,10 +594,9 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo continue; if (land.lnd_land > -1) continue; - } else if (sp->shp_x != land.lnd_x - || sp->shp_y != land.lnd_y) + } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y) continue; - + if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) && (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) && (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) { @@ -590,17 +618,17 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo pr("Non-land unit carrying subs can only carry up to two spy units.\n"); return 0; } - /* Eh, let 'em load a spy only */ + /* Eh, let 'em load a spy only */ load_spy = 1; } } - if ((!load_spy) && + if ((!load_spy) && (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) { - if (noisy) { + if (noisy) { if (mchr[(int)sp->shp_type].m_nland) - pr("%s doesn't have room for any more land units!\n",prship(sp)); + pr("%s doesn't have room for any more land units!\n", prship(sp)); else - pr("%s cannot carry land units!\n",prship(sp)); + pr("%s cannot carry land units!\n", prship(sp)); } return 0; } @@ -608,17 +636,15 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo if (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland) { if (noisy) if (mchr[(int)sp->shp_type].m_nland) - pr("%s doesn't have room for any more land units!\n",prship(sp)); + pr("%s doesn't have room for any more land units!\n", prship(sp)); else - pr("%s cannot carry land units!\n",prship(sp)); + pr("%s cannot carry land units!\n", prship(sp)); break; } #endif sprintf(buf, "loaded on your %s at %s", - prship(sp),xyas(sp->shp_x,sp->shp_y, - sp->shp_own)); - gift(sp->shp_own,player->cnum,(s_char *)&land, - EF_LAND, buf); + prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + gift(sp->shp_own, player->cnum, (s_char *)&land, EF_LAND, buf); makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); land.lnd_own = sp->shp_own; @@ -629,38 +655,35 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo land.lnd_mission = 0; resupply_all(&land); sp->shp_nland++; - putland(land.lnd_uid,&land); + putland(land.lnd_uid, &land); if (!has_supply(&land)) - pr("WARNING: %s is out of supply!\n", - prland(&land)); - putship(sp->shp_uid,sp); - snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y); - while (nxtitem(&pni, (s_char *)&plane)){ + pr("WARNING: %s is out of supply!\n", prland(&land)); + putship(sp->shp_uid, sp); + snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y); + while (nxtitem(&pni, (s_char *)&plane)) { if (plane.pln_flags & PLN_LAUNCHED) continue; if (plane.pln_land != land.lnd_uid) continue; - sprintf(buf, "loaded on %s", - prship(sp)); - gift(sp->shp_own,player->cnum,(s_char *)&plane, + sprintf(buf, "loaded on %s", prship(sp)); + gift(sp->shp_own, player->cnum, (s_char *)&plane, EF_PLANE, buf); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, - plane.pln_y); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); plane.pln_own = sp->shp_own; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); plane.pln_mission = 0; - putplane(plane.pln_uid,&plane); + putplane(plane.pln_uid, &plane); } } else { sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, - xyas(sectp->sct_x,sectp->sct_y, - sectp->sct_own)); - + xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); + /* Spies are unloaded quietly, others aren't */ if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) { - gift(sectp->sct_own,player->cnum,(s_char *)&land, + gift(sectp->sct_own, player->cnum, (s_char *)&land, EF_LAND, buf); makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); @@ -668,26 +691,26 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); } - + land.lnd_ship = (-1); sp->shp_nland--; - putland(land.lnd_uid,&land); - putship(sp->shp_uid,sp); - + putland(land.lnd_uid, &land); + putship(sp->shp_uid, sp); + /* Spies are unloaded quietly, others aren't, and in the off chance they can carry a plane (missile?) they are quietly unloaded too. */ if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) { - snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y); - while (nxtitem(&pni, (s_char *)&plane)){ + snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y); + while (nxtitem(&pni, (s_char *)&plane)) { if (plane.pln_flags & PLN_LAUNCHED) continue; if (plane.pln_land != land.lnd_uid) continue; sprintf(buf, "unloaded at %s", - xyas(plane.pln_x,plane.pln_y, + xyas(plane.pln_x, plane.pln_y, sectp->sct_own)); - gift(sectp->sct_own,player->cnum,(s_char *)&plane, + gift(sectp->sct_own, player->cnum, (s_char *)&plane, EF_PLANE, buf); makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); @@ -695,16 +718,15 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); plane.pln_mission = 0; - putplane(plane.pln_uid,&plane); + putplane(plane.pln_uid, &plane); } } } pr("%s %s %s at %s.\n", prland(&land), - (load_unload==UNLOAD)? - "unloaded from":"loaded onto", - prship(sp), - xyas(sp->shp_x, sp->shp_y, player->cnum)); + (load_unload == UNLOAD) ? + "unloaded from" : "loaded onto", + prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); loaded = 1; } *nshipsp += loaded; @@ -712,518 +734,504 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unlo } static int -load_comm_ship(struct sctstr *sectp, struct shpstr *sp, struct ichrstr *ich, int load_unload, int *nshipsp) +load_comm_ship(struct sctstr *sectp, struct shpstr *sp, + struct ichrstr *ich, int load_unload, int *nshipsp) { - register int item = ich->i_vtype; - register int max_amt; - register int move_amt; - register int ship_amt; - register int sect_amt; - int amount; - int upto=0, abs_max; - s_char prompt[512]; - s_char *p; - s_char buf[1024]; - - sprintf(prompt, "Number of %s to %s %s at %s? ", - ich->i_name, - (load_unload==UNLOAD)? - "unload from":"load onto", - prship(sp), - xyas(sp->shp_x, sp->shp_y, player->cnum)); - if (!(p = getstarg(player->argp[3], prompt, buf)) || - !*p) - return RET_SYN; - - if (!still_ok_ship(sectp, sp)) - return RET_SYN; - - amount = atoi(p); - if (amount < 0) { - /* We want to load up to this amount */ - upto = -(amount); - load_unload = LOAD; - } else if (!amount) - return 0; - ship_amt = getvar(item, (s_char *)sp, EF_SHIP); - sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR); - if (sectp->sct_oldown != player->cnum && - item == V_CIVIL) { - pr("%s civilians refuse to %s at %s!\n", - load_unload == UNLOAD ? "Your" : "Foreign", - load_unload == UNLOAD ? - "disembark" : "board", - xyas(sectp->sct_x, sectp->sct_y, player->cnum)); - return 0; - } - if (load_unload == UNLOAD) { - abs_max = max_amt = min(9999 - sect_amt, ship_amt); - } else { - struct mchrstr *vbase; - vbase = &mchr[(int)sp->shp_type]; - abs_max = max_amt = vl_find(item, vbase->m_vtype, - vbase->m_vamt, (int) vbase->m_nv); - max_amt = min(sect_amt, max_amt - ship_amt); - } - if (max_amt <= 0 && !upto) - return 0; - if (upto) { - move_amt = upto - ship_amt; - if (move_amt > sect_amt) - move_amt = sect_amt; - if (ship_amt+move_amt > abs_max) - move_amt = abs_max - ship_amt; - } else - move_amt = load_unload * min(amount, max_amt); - if (!move_amt) - return 0; + register int item = ich->i_vtype; + register int max_amt; + register int move_amt; + register int ship_amt; + register int sect_amt; + int amount; + int upto = 0, abs_max; + s_char prompt[512]; + s_char *p; + s_char buf[1024]; + + sprintf(prompt, "Number of %s to %s %s at %s? ", + ich->i_name, + (load_unload == UNLOAD) ? + "unload from" : "load onto", + prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); + if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) + return RET_SYN; - if (!want_to_abandon(sectp, item, move_amt, 0)) - return RET_FAIL; - if (!still_ok_ship(sectp, sp)) - return RET_SYN; - putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR); - putvar(item, ship_amt + move_amt, (s_char *)sp, EF_SHIP); - if (load_unload == LOAD) { - pr("%d %s loaded onto %s at %s\n", - move_amt, - ich->i_name, - prship(sp), - xyas(sp->shp_x, sp->shp_y, player->cnum)); - if (sp->shp_own != player->cnum) { - sprintf(buf,"%s loaded %d %s onto %s at %s\n", - cname(player->cnum), - move_amt, - ich->i_name, - prship(sp), - xyas(sp->shp_x, sp->shp_y, - sp->shp_own)); - wu(0, sp->shp_own, buf); - } - } else { - pr("%d %s unloaded from %s at %s\n", - -move_amt, - ich->i_name, - prship(sp), - xyas(sp->shp_x, sp->shp_y, player->cnum)); - if (sectp->sct_own != player->cnum) { - sprintf(buf,"%s unloaded %d %s from %s at %s\n", - cname(player->cnum), - -move_amt, - ich->i_name, - prship(sp), - xyas(sp->shp_x, sp->shp_y, - sectp->sct_own)); - wu(0, sectp->sct_own, buf); - } - } - ++(*nshipsp); + if (!still_ok_ship(sectp, sp)) + return RET_SYN; + + amount = atoi(p); + if (amount < 0) { + /* We want to load up to this amount */ + upto = -(amount); + load_unload = LOAD; + } else if (!amount) + return 0; + ship_amt = getvar(item, (s_char *)sp, EF_SHIP); + sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR); + if (sectp->sct_oldown != player->cnum && item == V_CIVIL) { + pr("%s civilians refuse to %s at %s!\n", + load_unload == UNLOAD ? "Your" : "Foreign", + load_unload == UNLOAD ? + "disembark" : "board", + xyas(sectp->sct_x, sectp->sct_y, player->cnum)); + return 0; + } + if (load_unload == UNLOAD) { + abs_max = max_amt = min(9999 - sect_amt, ship_amt); + } else { + struct mchrstr *vbase; + vbase = &mchr[(int)sp->shp_type]; + abs_max = max_amt = vl_find(item, vbase->m_vtype, + vbase->m_vamt, (int)vbase->m_nv); + max_amt = min(sect_amt, max_amt - ship_amt); + } + if (max_amt <= 0 && !upto) + return 0; + if (upto) { + move_amt = upto - ship_amt; + if (move_amt > sect_amt) + move_amt = sect_amt; + if (ship_amt + move_amt > abs_max) + move_amt = abs_max - ship_amt; + } else + move_amt = load_unload * min(amount, max_amt); + if (!move_amt) return 0; -} -static int -load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp) -{ - struct nstr_item ni; - struct plnstr pln; - int loaded = 0; - s_char *p; - s_char prompt[512]; - s_char buf[1024]; - - if (!(lchr[(int)lp->lnd_type].l_flags & L_XLIGHT)) { - if (noisy) - pr("%s cannot carry extra-light planes.\n", - prland(lp)); - return 0; + if (!want_to_abandon(sectp, item, move_amt, 0)) + return RET_FAIL; + if (!still_ok_ship(sectp, sp)) + return RET_SYN; + putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR); + putvar(item, ship_amt + move_amt, (s_char *)sp, EF_SHIP); + if (load_unload == LOAD) { + pr("%d %s loaded onto %s at %s\n", + move_amt, + ich->i_name, + prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); + if (sp->shp_own != player->cnum) { + sprintf(buf, "%s loaded %d %s onto %s at %s\n", + cname(player->cnum), + move_amt, + ich->i_name, + prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + wu(0, sp->shp_own, buf); } - count_land_planes(lp); - if (load_unload==LOAD && - lp->lnd_nxlight >= lp->lnd_maxlight) { - if (noisy) - pr("%s doesn't have room for any more extra-light planes\n", - prland(lp)); - return 0; + } else { + pr("%d %s unloaded from %s at %s\n", + -move_amt, + ich->i_name, + prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); + if (sectp->sct_own != player->cnum) { + sprintf(buf, "%s unloaded %d %s from %s at %s\n", + cname(player->cnum), + -move_amt, + ich->i_name, + prship(sp), + xyas(sp->shp_x, sp->shp_y, sectp->sct_own)); + wu(0, sectp->sct_own, buf); } - sprintf(prompt, "Plane(s) to %s %s? ", - load_unload==LOAD?"load onto":"unload from", - prland(lp)); - if (!snxtitem(&ni, EF_PLANE, p=getstarg(player->argp[3], prompt, buf))) - return RET_SYN; - - if (!still_ok_land(sectp, lp)) - return RET_SYN; - - if (p && *p) - noisy &= isdigit(*p); + } + ++(*nshipsp); + return 0; +} - if (sectp->sct_own != player->cnum && load_unload == LOAD) { - pr("Sector %s is not yours.\n", - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - return 0; - } +static int +load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, + int load_unload, int *nunitsp) +{ + struct nstr_item ni; + struct plnstr pln; + int loaded = 0; + s_char *p; + s_char prompt[512]; + s_char buf[1024]; + + if (!(lchr[(int)lp->lnd_type].l_flags & L_XLIGHT)) { + if (noisy) + pr("%s cannot carry extra-light planes.\n", prland(lp)); + return 0; + } + count_land_planes(lp); + if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) { + if (noisy) + pr("%s doesn't have room for any more extra-light planes\n", + prland(lp)); + return 0; + } + sprintf(prompt, "Plane(s) to %s %s? ", + load_unload == LOAD ? "load onto" : "unload from", prland(lp)); + if (!snxtitem + (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf))) + return RET_SYN; - while(nxtitem(&ni, (s_char *)&pln)) { - if (pln.pln_own != player->cnum) - continue; - - if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) { - if (noisy) - pr("You can only load xlight planes onto units.\n"); - continue; - } + if (!still_ok_land(sectp, lp)) + return RET_SYN; - if (load_unload == LOAD && pln.pln_ship > -1) { - if (noisy) - pr("%s is already on ship #%d!\n", - prplane(&pln), pln.pln_ship); - continue; - } - if (load_unload == LOAD && pln.pln_land > -1) { - if (noisy) - pr("%s is already on unit #%d!\n", - prplane(&pln), pln.pln_land); - continue; - } - /* Plane sanity done */ - /* Find the right unit */ - if (load_unload == UNLOAD) { - if (pln.pln_land != lp->lnd_uid) - continue; - } else if (lp->lnd_x != pln.pln_x - || lp->lnd_y != pln.pln_y) - continue; + if (p && *p) + noisy &= isdigit(*p); - /* Fit plane on unit */ - if (load_unload == LOAD){ - if (!put_plane_on_land(&pln,lp)){ - if (noisy) - pr("Can't put plane %d on this unit!\n",pln.pln_uid); - continue; - } - sprintf(buf, "loaded on %s at %s", - prland(lp), xyas(lp->lnd_x, - lp->lnd_y, lp->lnd_own)); - gift(lp->lnd_own,player->cnum,(s_char *)&pln, - EF_PLANE, buf); - makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - pln.pln_own = lp->lnd_own; - makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - putplane(pln.pln_uid,&pln); - }else{ - if (!take_plane_off_land(&pln,lp)){ - pr("Unable to take plane off unit!\n"); - logerror("load: plane %d could not be taken off unit %d\n",pln.pln_uid,lp->lnd_uid); - continue; - } - sprintf(buf, "unloaded at your sector at %s", - xyas(sectp->sct_x,sectp->sct_y, - sectp->sct_own)); - gift(sectp->sct_own,player->cnum,(s_char *)&pln, - EF_PLANE, buf); - makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - pln.pln_own = sectp->sct_own; - makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y); - putplane(pln.pln_uid,&pln); - } - pr("%s %s %s at %s.\n", - prplane(&pln), - (load_unload==UNLOAD)? - "unloaded from":"loaded onto", - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - loaded = 1; - } - *nunitsp += loaded; + if (sectp->sct_own != player->cnum && load_unload == LOAD) { + pr("Sector %s is not yours.\n", + xyas(lp->lnd_x, lp->lnd_y, player->cnum)); return 0; -} + } -static int -load_comm_land(struct sctstr *sectp, struct lndstr *lp, struct ichrstr *ich, int load_unload, int *nunitsp) -{ - register int item = ich->i_vtype; - register int max_amt; - register int move_amt; - register int land_amt; - register int sect_amt; - int amount; - int upto=0, abs_max; - s_char prompt[512]; - s_char *p; - s_char buf[1024]; - - sprintf(prompt, "Number of %s to %s %s at %s? ", - ich->i_name, - (load_unload==UNLOAD)? - "unload from":"load onto", - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - if (!(p = getstarg(player->argp[3], prompt, buf)) || - !*p) - return RET_SYN; - - if (!still_ok_land(sectp, lp)) - return RET_SYN; - - amount = atoi(p); - if (amount < 0) { - /* We want to load up to this amount */ - upto = -(amount); - load_unload = LOAD; - } else if (!amount) - return 0; + while (nxtitem(&ni, (s_char *)&pln)) { + if (pln.pln_own != player->cnum) + continue; - if (sectp->sct_own != player->cnum && load_unload == LOAD) { - pr("Sector %s is not yours.\n", - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - return 0; + if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) { + if (noisy) + pr("You can only load xlight planes onto units.\n"); + continue; } - land_amt = getvar(item, (s_char *)lp, EF_LAND); - sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR); - if (sectp->sct_oldown != player->cnum && item == V_CIVIL) { - pr("%s civilians refuse to %s at %s!\n", - load_unload == UNLOAD ? "Your" : "Foreign", - load_unload == UNLOAD ? - "disembark" : "board", - xyas(sectp->sct_x, sectp->sct_y, player->cnum)); - return 0; + if (load_unload == LOAD && pln.pln_ship > -1) { + if (noisy) + pr("%s is already on ship #%d!\n", + prplane(&pln), pln.pln_ship); + continue; } - if (load_unload == UNLOAD) { - abs_max = max_amt = min(9999 - sect_amt, land_amt); - } else { - struct lchrstr *vbase; - vbase = &lchr[(int)lp->lnd_type]; - abs_max = max_amt = vl_find(item, vbase->l_vtype, - vbase->l_vamt, (int) vbase->l_nv); - max_amt = min(sect_amt, max_amt - land_amt); + if (load_unload == LOAD && pln.pln_land > -1) { + if (noisy) + pr("%s is already on unit #%d!\n", + prplane(&pln), pln.pln_land); + continue; } - if ((max_amt <= 0) && (upto == 0)) - return 0; - if (upto){ - move_amt = upto - land_amt; - if (land_amt+move_amt > abs_max) - move_amt = abs_max - land_amt; - if (move_amt > sect_amt) - move_amt = sect_amt; - }else - move_amt = load_unload * min(amount, max_amt); - if (move_amt == 0) - return 0; - putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR); - putvar(item, land_amt + move_amt, (s_char *)lp, EF_LAND); + /* Plane sanity done */ + /* Find the right unit */ + if (load_unload == UNLOAD) { + if (pln.pln_land != lp->lnd_uid) + continue; + } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y) + continue; - /* Did we put mils onto this unit? If so, reset the fortification */ - if (item == V_MILIT && move_amt > 0) - lp->lnd_harden = 0; + /* Fit plane on unit */ if (load_unload == LOAD) { - pr("%d %s loaded onto %s at %s\n", - move_amt, - ich->i_name, - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - if (lp->lnd_own != player->cnum) { - sprintf(buf,"%s loaded %d %s onto %s at %s\n", - cname(player->cnum), - move_amt, - ich->i_name, - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, - lp->lnd_own)); - wu(0, lp->lnd_own, buf); - } + if (!put_plane_on_land(&pln, lp)) { + if (noisy) + pr("Can't put plane %d on this unit!\n", pln.pln_uid); + continue; + } + sprintf(buf, "loaded on %s at %s", + prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + gift(lp->lnd_own, player->cnum, (s_char *)&pln, EF_PLANE, buf); + makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + pln.pln_own = lp->lnd_own; + makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + putplane(pln.pln_uid, &pln); } else { - pr("%d %s unloaded from %s at %s\n", - -move_amt, - ich->i_name, - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - if (sectp->sct_own != player->cnum) { - sprintf(buf,"%s unloaded %d %s from %s at %s\n", - cname(player->cnum), - -move_amt, - ich->i_name, - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, - sectp->sct_own)); - wu(0, sectp->sct_own, buf); - } + if (!take_plane_off_land(&pln, lp)) { + pr("Unable to take plane off unit!\n"); + logerror("load: plane %d could not be taken off unit %d\n", + pln.pln_uid, lp->lnd_uid); + continue; + } + sprintf(buf, "unloaded at your sector at %s", + xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); + gift(sectp->sct_own, player->cnum, (s_char *)&pln, + EF_PLANE, buf); + makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + pln.pln_own = sectp->sct_own; + makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, + pln.pln_y); + putplane(pln.pln_uid, &pln); } + pr("%s %s %s at %s.\n", + prplane(&pln), + (load_unload == UNLOAD) ? + "unloaded from" : "loaded onto", + prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + loaded = 1; + } + *nunitsp += loaded; + return 0; +} + +static int +load_comm_land(struct sctstr *sectp, struct lndstr *lp, + struct ichrstr *ich, int load_unload, int *nunitsp) +{ + register int item = ich->i_vtype; + register int max_amt; + register int move_amt; + register int land_amt; + register int sect_amt; + int amount; + int upto = 0, abs_max; + s_char prompt[512]; + s_char *p; + s_char buf[1024]; + + sprintf(prompt, "Number of %s to %s %s at %s? ", + ich->i_name, + (load_unload == UNLOAD) ? + "unload from" : "load onto", + prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) + return RET_SYN; + + if (!still_ok_land(sectp, lp)) + return RET_SYN; + + amount = atoi(p); + if (amount < 0) { + /* We want to load up to this amount */ + upto = -(amount); + load_unload = LOAD; + } else if (!amount) + return 0; + + if (sectp->sct_own != player->cnum && load_unload == LOAD) { + pr("Sector %s is not yours.\n", + xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + return 0; + } - ++(*nunitsp); + land_amt = getvar(item, (s_char *)lp, EF_LAND); + sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR); + if (sectp->sct_oldown != player->cnum && item == V_CIVIL) { + pr("%s civilians refuse to %s at %s!\n", + load_unload == UNLOAD ? "Your" : "Foreign", + load_unload == UNLOAD ? + "disembark" : "board", + xyas(sectp->sct_x, sectp->sct_y, player->cnum)); return 0; + } + if (load_unload == UNLOAD) { + abs_max = max_amt = min(9999 - sect_amt, land_amt); + } else { + struct lchrstr *vbase; + vbase = &lchr[(int)lp->lnd_type]; + abs_max = max_amt = vl_find(item, vbase->l_vtype, + vbase->l_vamt, (int)vbase->l_nv); + max_amt = min(sect_amt, max_amt - land_amt); + } + if ((max_amt <= 0) && (upto == 0)) + return 0; + if (upto) { + move_amt = upto - land_amt; + if (land_amt + move_amt > abs_max) + move_amt = abs_max - land_amt; + if (move_amt > sect_amt) + move_amt = sect_amt; + } else + move_amt = load_unload * min(amount, max_amt); + if (move_amt == 0) + return 0; + putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR); + putvar(item, land_amt + move_amt, (s_char *)lp, EF_LAND); + + /* Did we put mils onto this unit? If so, reset the fortification */ + if (item == V_MILIT && move_amt > 0) + lp->lnd_harden = 0; + if (load_unload == LOAD) { + pr("%d %s loaded onto %s at %s\n", + move_amt, + ich->i_name, + prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + if (lp->lnd_own != player->cnum) { + sprintf(buf, "%s loaded %d %s onto %s at %s\n", + cname(player->cnum), + move_amt, + ich->i_name, + prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + wu(0, lp->lnd_own, buf); + } + } else { + pr("%d %s unloaded from %s at %s\n", + -move_amt, + ich->i_name, + prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + if (sectp->sct_own != player->cnum) { + sprintf(buf, "%s unloaded %d %s from %s at %s\n", + cname(player->cnum), + -move_amt, + ich->i_name, + prland(lp), + xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own)); + wu(0, sectp->sct_own, buf); + } + } + + ++(*nunitsp); + return 0; } static int -load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp) +load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, + int load_unload, int *nunitsp) { - struct nstr_item pni, ni; - struct lndstr land; - struct plnstr plane; - int loaded = 0; - s_char *p; - s_char prompt[512]; - s_char buf[1024]; - - lnd_count_units(lp); - - if (load_unload==LOAD && - lp->lnd_nland >= lp->lnd_maxland) { - if (noisy) { - if (lp->lnd_nland) - pr("%s doesn't have room for any more land units!\n",prland(lp)); - else - pr("%s cannot carry land units!\n",prland(lp)); - } - return 0; + struct nstr_item pni, ni; + struct lndstr land; + struct plnstr plane; + int loaded = 0; + s_char *p; + s_char prompt[512]; + s_char buf[1024]; + + lnd_count_units(lp); + + if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) { + if (noisy) { + if (lp->lnd_nland) + pr("%s doesn't have room for any more land units!\n", + prland(lp)); + else + pr("%s cannot carry land units!\n", prland(lp)); } - sprintf(prompt, "Land unit(s) to %s %s? ", - load_unload==LOAD?"load onto":"unload from", - prland(lp)); - if (!snxtitem(&ni, EF_LAND, p=getstarg(player->argp[3], prompt, buf))) - return RET_SYN; + return 0; + } + sprintf(prompt, "Land unit(s) to %s %s? ", + load_unload == LOAD ? "load onto" : "unload from", prland(lp)); + if (!snxtitem + (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf))) + return RET_SYN; - if (!still_ok_land(sectp, lp)) - return RET_SYN; + if (!still_ok_land(sectp, lp)) + return RET_SYN; - if (p && *p) - noisy &= isdigit(*p); + if (p && *p) + noisy &= isdigit(*p); - while(nxtitem(&ni, (s_char *)&land)) { - - if (land.lnd_own != player->cnum) - continue; - - if (load_unload == LOAD) { - if (land.lnd_ship > -1) { - if (noisy) - pr("%s is already on ship #%d!\n", - prland(&land), land.lnd_ship); - continue; - } - if (land.lnd_land > -1) { - if (noisy) - pr("%s is already on land #%d!\n", - prland(&land), land.lnd_land); + while (nxtitem(&ni, (s_char *)&land)) { + + if (land.lnd_own != player->cnum) + continue; + + if (load_unload == LOAD) { + if (land.lnd_ship > -1) { + if (noisy) + pr("%s is already on ship #%d!\n", + prland(&land), land.lnd_ship); + continue; + } + if (land.lnd_land > -1) { + if (noisy) + pr("%s is already on land #%d!\n", + prland(&land), land.lnd_land); + continue; + } + lnd_count_units(&land); + if (land.lnd_nland > 0) { + if (noisy) + pr("%s cannot be loaded since it is carrying units\n", + prland(&land)); + continue; + } + if (land.lnd_uid == lp->lnd_uid) { + if (noisy) + pr("%s can't be loaded onto itself!\n", prland(&land)); + continue; + } + if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) { + if (noisy) + pr("%s is too heavy to load.\n", prland(&land)); + continue; + } + } + + /* Unit sanity done */ + /* Find the right ship */ + if (load_unload == UNLOAD) { + if (land.lnd_land != lp->lnd_uid) + continue; + if (land.lnd_ship > -1) + continue; + } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y) + continue; + + /* Fit unit on ship */ + if (load_unload == LOAD) { + lnd_count_units(lp); + if (lp->lnd_nland >= lp->lnd_maxland) { + if (noisy) { + if (lp->lnd_nland) + pr("%s doesn't have room for any more land units!\n", prland(lp)); + else + pr("%s cannot carry land units!\n", prland(lp)); + } + break; + } + sprintf(buf, "loaded on your %s at %s", + prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + gift(lp->lnd_own, player->cnum, (s_char *)&land, EF_LAND, buf); + makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_own = lp->lnd_own; + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_land = lp->lnd_uid; + land.lnd_harden = 0; + land.lnd_mission = 0; + resupply_all(&land); + lp->lnd_nland++; + putland(land.lnd_uid, &land); + if (!has_supply(&land)) + pr("WARNING: %s is out of supply!\n", prland(&land)); + putland(lp->lnd_uid, lp); + snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y); + while (nxtitem(&pni, (s_char *)&plane)) { + if (plane.pln_flags & PLN_LAUNCHED) continue; - } - lnd_count_units(&land); - if (land.lnd_nland > 0) { - if (noisy) - pr("%s cannot be loaded since it is carrying units\n", - prland(&land)); + if (plane.pln_land != land.lnd_uid) continue; - } - if (land.lnd_uid == lp->lnd_uid) { - if (noisy) - pr("%s can't be loaded onto itself!\n", prland(&land)); + sprintf(buf, "loaded on %s", prland(lp)); + gift(lp->lnd_own, player->cnum, (s_char *)&plane, + EF_PLANE, buf); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_own = lp->lnd_own; + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_mission = 0; + putplane(plane.pln_uid, &plane); + } + } else { + sprintf(buf, "unloaded in your %s at %s", + dchr[sectp->sct_type].d_name, + xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); + gift(sectp->sct_own, player->cnum, (s_char *)&land, + EF_LAND, buf); + makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_own = sectp->sct_own; + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_land = (-1); + lp->lnd_nland--; + putland(land.lnd_uid, &land); + putland(lp->lnd_uid, lp); + snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y); + while (nxtitem(&pni, (s_char *)&plane)) { + if (plane.pln_flags & PLN_LAUNCHED) continue; - } - if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) { - if (noisy) - pr("%s is too heavy to load.\n", prland(&land)); + if (plane.pln_land != land.lnd_uid) continue; - } - } - - /* Unit sanity done */ - /* Find the right ship */ - if (load_unload == UNLOAD) { - if (land.lnd_land != lp->lnd_uid) - continue; - if (land.lnd_ship > -1) - continue; - } else if (lp->lnd_x != land.lnd_x - || lp->lnd_y != land.lnd_y) - continue; - - /* Fit unit on ship */ - if (load_unload == LOAD) { - lnd_count_units(lp); - if (lp->lnd_nland >= lp->lnd_maxland) { - if (noisy) { - if (lp->lnd_nland) - pr("%s doesn't have room for any more land units!\n",prland(lp)); - else - pr("%s cannot carry land units!\n",prland(lp)); - } - break; - } - sprintf(buf, "loaded on your %s at %s", - prland(lp),xyas(lp->lnd_x,lp->lnd_y, - lp->lnd_own)); - gift(lp->lnd_own,player->cnum,(s_char *)&land, - EF_LAND, buf); - makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_own = lp->lnd_own; - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_land = lp->lnd_uid; - land.lnd_harden = 0; - land.lnd_mission = 0; - resupply_all(&land); - lp->lnd_nland++; - putland(land.lnd_uid,&land); - if (!has_supply(&land)) - pr("WARNING: %s is out of supply!\n", - prland(&land)); - putland(lp->lnd_uid,lp); - snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y); - while (nxtitem(&pni, (s_char *)&plane)){ - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_land != land.lnd_uid) - continue; - sprintf(buf, "loaded on %s", - prland(lp)); - gift(lp->lnd_own,player->cnum,(s_char *)&plane, - EF_PLANE, buf); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = lp->lnd_own; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_mission = 0; - putplane(plane.pln_uid,&plane); - } - } else { - sprintf(buf, "unloaded in your %s at %s", - dchr[sectp->sct_type].d_name, - xyas(sectp->sct_x,sectp->sct_y, - sectp->sct_own)); - gift(sectp->sct_own,player->cnum,(s_char *)&land, - EF_LAND, buf); - makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_own = sectp->sct_own; - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_land = (-1); - lp->lnd_nland--; - putland(land.lnd_uid,&land); - putland(lp->lnd_uid,lp); - snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y); - while (nxtitem(&pni, (s_char *)&plane)){ - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_land != land.lnd_uid) - continue; - sprintf(buf, "unloaded at %s", - xyas(plane.pln_x,plane.pln_y, - sectp->sct_own)); - gift(sectp->sct_own,player->cnum,(s_char *)&plane, - EF_PLANE, buf); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = sectp->sct_own; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_mission = 0; - putplane(plane.pln_uid,&plane); - } - } - pr("%s %s %s at %s.\n", - prland(&land), - (load_unload==UNLOAD)? - "unloaded from":"loaded onto", - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); - loaded = 1; + sprintf(buf, "unloaded at %s", + xyas(plane.pln_x, plane.pln_y, sectp->sct_own)); + gift(sectp->sct_own, player->cnum, (s_char *)&plane, + EF_PLANE, buf); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_own = sectp->sct_own; + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_mission = 0; + putplane(plane.pln_uid, &plane); + } } - *nunitsp += loaded; - return 0; + pr("%s %s %s at %s.\n", + prland(&land), + (load_unload == UNLOAD) ? + "unloaded from" : "loaded onto", + prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + loaded = 1; + } + *nunitsp += loaded; + return 0; } - diff --git a/src/lib/commands/look.c b/src/lib/commands/look.c index 57447ee28..d8e31061b 100644 --- a/src/lib/commands/look.c +++ b/src/lib/commands/look.c @@ -47,275 +47,267 @@ #include "commands.h" #include "optlist.h" -static void look_ship(register struct shpstr *lookship); +static void look_ship(register struct shpstr *lookship); int look(void) { - register int i; - struct nstr_item ni; - struct shpstr myship; - struct sctstr sect; - int x, y; - int civ; - int mil; - u_char *bitmap; - int changed = 0; + register int i; + struct nstr_item ni; + struct shpstr myship; + struct sctstr sect; + int x, y; + int civ; + int mil; + u_char *bitmap; + int changed = 0; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; - if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) { - logerror("malloc failed in look\n"); - pr("Memory error. Tell the deity.\n"); - return RET_FAIL; + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; + if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) { + logerror("malloc failed in look\n"); + pr("Memory error. Tell the deity.\n"); + return RET_FAIL; + } + bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); + while (nxtitem(&ni, (s_char *)&myship)) { + if (!player->owner) + continue; + look_ship(&myship); + for (i = 0; i <= 6; i++) { + x = diroff[i][0] + myship.shp_x; + y = diroff[i][1] + myship.shp_y; + if (emp_getbit(x, y, bitmap)) + continue; + emp_setbit(x, y, bitmap); + getsect(x, y, §); + if (sect.sct_type == SCT_WATER) + continue; + if (player->owner) + pr("Your "); + else + pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own); + pr(dchr[sect.sct_type].d_name); + changed += map_set(player->cnum, x, y, + dchr[sect.sct_type].d_mnem, 0); + pr(" %d%% efficient ", player->owner ? sect.sct_effic : + roundintby((int)sect.sct_effic, 10)); + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); + if (civ) + pr("with %s%d civ ", player->owner ? "" : "approx ", + player->owner ? civ : roundintby(civ, 10)); + if (mil) + pr("with %s%d mil ", player->owner ? "" : "approx ", + player->owner ? mil : roundintby(mil, 10)); + pr("@ %s\n", xyas(x, y, player->cnum)); + if (opt_HIDDEN) { + setcont(player->cnum, sect.sct_own, FOUND_LOOK); + } } - bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); - while (nxtitem(&ni, (s_char *)&myship)) { - if (!player->owner) - continue; - look_ship(&myship); - for (i = 0; i <= 6; i++) { - x = diroff[i][0] + myship.shp_x; - y = diroff[i][1] + myship.shp_y; - if (emp_getbit(x, y, bitmap)) - continue; - emp_setbit(x, y, bitmap); - getsect(x, y, §); - if (sect.sct_type == SCT_WATER) - continue; - if (player->owner) - pr("Your "); - else - pr("%s (#%d) ", cname(sect.sct_own), - sect.sct_own); - pr(dchr[sect.sct_type].d_name); - changed += map_set(player->cnum, x, y, - dchr[sect.sct_type].d_mnem, 0); - pr(" %d%% efficient ", player->owner ? sect.sct_effic : - roundintby((int)sect.sct_effic, 10)); - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); - if (civ) - pr("with %s%d civ ", player->owner ? "" : "approx ", - player->owner ? civ : roundintby(civ, 10)); - if (mil) - pr("with %s%d mil ", player->owner ? "" : "approx ", - player->owner ? mil : roundintby(mil, 10)); - pr("@ %s\n", xyas(x, y, player->cnum)); - if (opt_HIDDEN) { - setcont(player->cnum, sect.sct_own, FOUND_LOOK); - } - } - } - if (changed) - writemap(player->cnum); - free((s_char *)bitmap); - return RET_OK; + } + if (changed) + writemap(player->cnum); + free((s_char *)bitmap); + return RET_OK; } static void look_ship(register struct shpstr *lookship) { - register struct shpstr *sp; - register struct mchrstr *smcp; - register struct mchrstr *tmcp; - extern int ship_max_interdiction_range; - struct sctstr sect; - int range; - int vrange; - int i; - int dist; + register struct shpstr *sp; + register struct mchrstr *smcp; + register struct mchrstr *tmcp; + extern int ship_max_interdiction_range; + struct sctstr sect; + int range; + int vrange; + int i; + int dist; - range = (int) techfact(lookship->shp_tech, - (double) mchr[(int)lookship->shp_type].m_vrnge); - range = range * (lookship->shp_effic / 100.0); - smcp = &mchr[(int)lookship->shp_type]; + range = (int)techfact(lookship->shp_tech, + (double)mchr[(int)lookship->shp_type].m_vrnge); + range = range * (lookship->shp_effic / 100.0); + smcp = &mchr[(int)lookship->shp_type]; + if (smcp->m_flags & M_SUB) + range = min(range, 1); + for (i = 0; NULL != (sp = getshipp(i)); i++) { + if (sp->shp_own == player->cnum || sp->shp_own == 0) + continue; + dist = mapdist(sp->shp_x, sp->shp_y, + lookship->shp_x, lookship->shp_y); + if (dist > ship_max_interdiction_range) + continue; + tmcp = &mchr[(int)sp->shp_type]; if (smcp->m_flags & M_SUB) - range = min(range, 1); - for (i=0; NULL != (sp = getshipp(i)); i++) { - if (sp->shp_own == player->cnum || sp->shp_own == 0) - continue; - dist = mapdist(sp->shp_x, sp->shp_y, - lookship->shp_x, lookship->shp_y); - if (dist > ship_max_interdiction_range) - continue; - tmcp = &mchr[(int)sp->shp_type]; - if (smcp->m_flags & M_SUB) - vrange = (int)(sp->shp_visib * range/30.0); - else - vrange = (int)(sp->shp_visib * range/20.0); - getsect(sp->shp_x, sp->shp_y, §); - if (sect.sct_type != SCT_WATER) - vrange = max(1, vrange); - if (dist > vrange) - continue; - if (smcp->m_flags & M_SUB) { - if (tmcp->m_flags & M_SONAR && dist < 2) { - if(sp->shp_own != 0) - wu(0, sp->shp_own, - "%s detected surfacing noises in %s.\n", - prship(sp), - xyas(lookship->shp_x, lookship->shp_y, - sp->shp_own)); - } - if (dist == 0 && (tmcp->m_flags & M_SUB) == 0) - if(sp->shp_own != 0) - wu(0, sp->shp_own, - "Periscope spotted in %s by %s\n", - xyas(lookship->shp_x, lookship->shp_y, - sp->shp_own), - prship(sp)); - } - /* subs at sea only seen by sonar */ - if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER) - continue; - pr("%s (#%d) %s @ %s\n", - cname(sp->shp_own), sp->shp_own, prship(sp), - xyas(sp->shp_x, sp->shp_y, player->cnum)); + vrange = (int)(sp->shp_visib * range / 30.0); + else + vrange = (int)(sp->shp_visib * range / 20.0); + getsect(sp->shp_x, sp->shp_y, §); + if (sect.sct_type != SCT_WATER) + vrange = max(1, vrange); + if (dist > vrange) + continue; + if (smcp->m_flags & M_SUB) { + if (tmcp->m_flags & M_SONAR && dist < 2) { + if (sp->shp_own != 0) + wu(0, sp->shp_own, + "%s detected surfacing noises in %s.\n", + prship(sp), + xyas(lookship->shp_x, lookship->shp_y, + sp->shp_own)); + } + if (dist == 0 && (tmcp->m_flags & M_SUB) == 0) + if (sp->shp_own != 0) + wu(0, sp->shp_own, + "Periscope spotted in %s by %s\n", + xyas(lookship->shp_x, lookship->shp_y, + sp->shp_own), prship(sp)); } + /* subs at sea only seen by sonar */ + if (tmcp->m_flags & M_SUB && sect.sct_type == SCT_WATER) + continue; + pr("%s (#%d) %s @ %s\n", + cname(sp->shp_own), sp->shp_own, prship(sp), + xyas(sp->shp_x, sp->shp_y, player->cnum)); + } } -static void look_land(register struct lndstr *lookland); +static void look_land(register struct lndstr *lookland); int llook(void) { - register int i; - struct nstr_item ni; - struct lndstr myland; - struct sctstr sect; - int x, y; - int civ; - int mil; - u_char *bitmap; - int changed = 0; + register int i; + struct nstr_item ni; + struct lndstr myland; + struct sctstr sect; + int x, y; + int civ; + int mil; + u_char *bitmap; + int changed = 0; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) { - logerror("malloc failed in llook\n"); - pr("Memory error. Tell the deity.\n"); - return RET_FAIL; - } - bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); - while (nxtitem(&ni, (s_char *)&myland)) { - if (!player->owner) - continue; - if (myland.lnd_ship >= 0) - continue; - if (myland.lnd_land >= 0) - continue; - /* Spies don't need military to do a "llook". Other - units do */ - if ((lnd_getmil(&myland) <= 0) && - !(lchr[(int)myland.lnd_type].l_flags & L_SPY)) - continue; - look_land(&myland); - for (i = 0; i <= 6; i++) { - x = diroff[i][0] + myland.lnd_x; - y = diroff[i][1] + myland.lnd_y; - if (emp_getbit(x, y, bitmap)) - continue; - emp_setbit(x, y, bitmap); - getsect(x, y, §); - if (sect.sct_type == SCT_WATER) - continue; - if (player->owner) - pr("Your "); - else - pr("%s (#%d) ", cname(sect.sct_own), - sect.sct_own); - pr(dchr[sect.sct_type].d_name); - changed += map_set(player->cnum, x, y, - dchr[sect.sct_type].d_mnem, 0); - pr(" %d%% efficient ", player->owner ? sect.sct_effic : - roundintby((int)sect.sct_effic, 10)); - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); - if (civ) - pr("with %s%d civ ", player->owner ? "" : - "approx ", - player->owner ? civ : roundintby(civ, 10)); - if (mil) - pr("with %s%d mil ", player->owner ? "" : - "approx ", - player->owner ? mil : roundintby(mil, 10)); - pr("@ %s\n", xyas(x, y, player->cnum)); - if (opt_HIDDEN) { - setcont(player->cnum, sect.sct_own, FOUND_LOOK); - } - } + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + if ((bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8)) == 0) { + logerror("malloc failed in llook\n"); + pr("Memory error. Tell the deity.\n"); + return RET_FAIL; + } + bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); + while (nxtitem(&ni, (s_char *)&myland)) { + if (!player->owner) + continue; + if (myland.lnd_ship >= 0) + continue; + if (myland.lnd_land >= 0) + continue; + /* Spies don't need military to do a "llook". Other + units do */ + if ((lnd_getmil(&myland) <= 0) && + !(lchr[(int)myland.lnd_type].l_flags & L_SPY)) + continue; + look_land(&myland); + for (i = 0; i <= 6; i++) { + x = diroff[i][0] + myland.lnd_x; + y = diroff[i][1] + myland.lnd_y; + if (emp_getbit(x, y, bitmap)) + continue; + emp_setbit(x, y, bitmap); + getsect(x, y, §); + if (sect.sct_type == SCT_WATER) + continue; + if (player->owner) + pr("Your "); + else + pr("%s (#%d) ", cname(sect.sct_own), sect.sct_own); + pr(dchr[sect.sct_type].d_name); + changed += map_set(player->cnum, x, y, + dchr[sect.sct_type].d_mnem, 0); + pr(" %d%% efficient ", player->owner ? sect.sct_effic : + roundintby((int)sect.sct_effic, 10)); + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); + if (civ) + pr("with %s%d civ ", player->owner ? "" : + "approx ", player->owner ? civ : roundintby(civ, 10)); + if (mil) + pr("with %s%d mil ", player->owner ? "" : + "approx ", player->owner ? mil : roundintby(mil, 10)); + pr("@ %s\n", xyas(x, y, player->cnum)); + if (opt_HIDDEN) { + setcont(player->cnum, sect.sct_own, FOUND_LOOK); + } } - if (changed) - writemap(player->cnum); - free((s_char *)bitmap); - return RET_OK; + } + if (changed) + writemap(player->cnum); + free((s_char *)bitmap); + return RET_OK; } static void look_land(register struct lndstr *lookland) { - register struct plnstr *pp; - register struct lndstr *lp; - double drange; - int range; - int vrange; - int i; - int dist; - double techfact(int, double); - double odds; - - drange = techfact(lookland->lnd_tech, - (double) lookland->lnd_spy); - drange = (drange * ((double)lookland->lnd_effic / 100.0)); - range = ldround(drange,1); + register struct plnstr *pp; + register struct lndstr *lp; + double drange; + int range; + int vrange; + int i; + int dist; + double techfact(int, double); + double odds; - if (range == 0) - return; + drange = techfact(lookland->lnd_tech, (double)lookland->lnd_spy); + drange = (drange * ((double)lookland->lnd_effic / 100.0)); + range = ldround(drange, 1); - for (i=0; NULL != (lp = getlandp(i)); i++) { - if (lp->lnd_own == player->cnum || lp->lnd_own == 0) - continue; - if (lp->lnd_ship >= 0) - continue; - /* Don't always see spies */ - if (lchr[(int)lp->lnd_type].l_flags & L_SPY) { - /* If it's on a ship or unit, assume it's hidden - enough not to be seen */ - if (lp->lnd_ship >= 0 || lp->lnd_land >= 0) - continue; - odds = (double)(100 - lp->lnd_effic) + 0.10; - if (!(chance(odds))) - continue; - } - vrange = ldround((double)((lp->lnd_vis - * range)/20.0),1); - dist = mapdist(lp->lnd_x, lp->lnd_y, - lookland->lnd_x, lookland->lnd_y); - if (dist > vrange) - continue; + if (range == 0) + return; - pr("%s (#%d) %s (approx %d mil) @ %s\n", - cname(lp->lnd_own), lp->lnd_own, - prland(lp), ldround((double)total_mil(lp), 20), - xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + for (i = 0; NULL != (lp = getlandp(i)); i++) { + if (lp->lnd_own == player->cnum || lp->lnd_own == 0) + continue; + if (lp->lnd_ship >= 0) + continue; + /* Don't always see spies */ + if (lchr[(int)lp->lnd_type].l_flags & L_SPY) { + /* If it's on a ship or unit, assume it's hidden + enough not to be seen */ + if (lp->lnd_ship >= 0 || lp->lnd_land >= 0) + continue; + odds = (double)(100 - lp->lnd_effic) + 0.10; + if (!(chance(odds))) + continue; } - for (i=0; NULL != (pp = getplanep(i)); i++) { - if (pp->pln_own == player->cnum || pp->pln_own == 0) - continue; - if (pp->pln_ship >= 0) - continue; - if (pp->pln_flags & PLN_LAUNCHED) - continue; - vrange = ldround((double)((10* range)/20.0),1); - dist = mapdist(pp->pln_x, pp->pln_y, - lookland->lnd_x, lookland->lnd_y); - if (dist > vrange) - continue; + vrange = ldround((double)((lp->lnd_vis * range) / 20.0), 1); + dist = mapdist(lp->lnd_x, lp->lnd_y, + lookland->lnd_x, lookland->lnd_y); + if (dist > vrange) + continue; - pr("%s (#%d) %s @ %s\n", - cname(pp->pln_own), pp->pln_own, - prplane(pp), - xyas(pp->pln_x, pp->pln_y, player->cnum)); - } + pr("%s (#%d) %s (approx %d mil) @ %s\n", + cname(lp->lnd_own), lp->lnd_own, + prland(lp), ldround((double)total_mil(lp), 20), + xyas(lp->lnd_x, lp->lnd_y, player->cnum)); + } + for (i = 0; NULL != (pp = getplanep(i)); i++) { + if (pp->pln_own == player->cnum || pp->pln_own == 0) + continue; + if (pp->pln_ship >= 0) + continue; + if (pp->pln_flags & PLN_LAUNCHED) + continue; + vrange = ldround((double)((10 * range) / 20.0), 1); + dist = mapdist(pp->pln_x, pp->pln_y, + lookland->lnd_x, lookland->lnd_y); + if (dist > vrange) + continue; + + pr("%s (#%d) %s @ %s\n", + cname(pp->pln_own), pp->pln_own, + prplane(pp), xyas(pp->pln_x, pp->pln_y, player->cnum)); + } } diff --git a/src/lib/commands/lost.c b/src/lib/commands/lost.c index f4cb4356c..8b0387287 100644 --- a/src/lib/commands/lost.c +++ b/src/lib/commands/lost.c @@ -53,7 +53,7 @@ lost(void) } else { if (!snxtitem(&ni, EF_LOST, player->argp[1])) return RET_SYN; - } + } prdate(); nlost = 0; diff --git a/src/lib/commands/lstat.c b/src/lib/commands/lstat.c index f6a7d5f62..9745920b3 100644 --- a/src/lib/commands/lstat.c +++ b/src/lib/commands/lstat.c @@ -47,63 +47,49 @@ int lstats(void) { - int nunits; - struct nstr_item ni; - struct lndstr land; - s_char *mission_short_name(); + int nunits; + struct nstr_item ni; + struct lndstr land; + s_char *mission_short_name(); - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; - nunits = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner || land.lnd_own == 0) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", - land.lnd_type, ni.cur); - continue; - } - count_land_planes(&land); + nunits = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; + } + count_land_planes(&land); - if (nunits++ == 0) { -pr(" %16.16s s v s r r a f a a\n", ""); -pr(" %16.16s p i p a n c i m a\n", ""); -pr("lnd# %16.16s x,y eff tech att def vul d s y d g c r m f\n", "unit-type"); - } - pr("%4d %-16.16s ", - land.lnd_uid, - lchr[(int)land.lnd_type].l_name); - prxy("%4d,%-4d", - land.lnd_x, - land.lnd_y, - player->cnum); - pr(" %3d%% %3d %1.1f %1.1f %3d ", - land.lnd_effic, - land.lnd_tech, - (float)land.lnd_att, - (float)land.lnd_def, - land.lnd_vul); - pr("%2d %2d %2d %2d ", - land.lnd_spd, - land.lnd_vis, - land.lnd_spy, - land.lnd_rad); - pr("%2d %2d %2d %2d %2d ", - land.lnd_frg, - land.lnd_acc, - land.lnd_dam, - land.lnd_ammo, - land.lnd_aaf); - pr("\n"); + if (nunits++ == 0) { + pr(" %16.16s s v s r r a f a a\n", ""); + pr(" %16.16s p i p a n c i m a\n", ""); + pr("lnd# %16.16s x,y eff tech att def vul d s y d g c r m f\n", "unit-type"); } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + pr("%4d %-16.16s ", land.lnd_uid, lchr[(int)land.lnd_type].l_name); + prxy("%4d,%-4d", land.lnd_x, land.lnd_y, player->cnum); + pr(" %3d%% %3d %1.1f %1.1f %3d ", + land.lnd_effic, + land.lnd_tech, + (float)land.lnd_att, (float)land.lnd_def, land.lnd_vul); + pr("%2d %2d %2d %2d ", + land.lnd_spd, land.lnd_vis, land.lnd_spy, land.lnd_rad); + pr("%2d %2d %2d %2d %2d ", + land.lnd_frg, + land.lnd_acc, land.lnd_dam, land.lnd_ammo, land.lnd_aaf); + pr("\n"); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } diff --git a/src/lib/commands/lten.c b/src/lib/commands/lten.c index 6bcee531d..88ef36ac3 100644 --- a/src/lib/commands/lten.c +++ b/src/lib/commands/lten.c @@ -55,121 +55,122 @@ static void expose_land(struct shpstr *s1, struct lndstr *l1); int ltend(void) { - struct nstr_item targets; - struct nstr_item tenders; - struct shpstr tender; - struct lndstr target; - struct ichrstr *ip; - struct mchrstr *vbase; - struct lchrstr *lbase; - int amt; - int ontender; - int ontarget; - int maxtender; - int maxtarget; - int transfer; - int total; - s_char *p; - s_char buf[1024]; + struct nstr_item targets; + struct nstr_item tenders; + struct shpstr tender; + struct lndstr target; + struct ichrstr *ip; + struct mchrstr *vbase; + struct lchrstr *lbase; + int amt; + int ontender; + int ontarget; + int maxtender; + int maxtarget; + int transfer; + int total; + s_char *p; + s_char buf[1024]; - if (!(ip = whatitem(player->argp[1], "Transfer what commodity? "))) - return RET_SYN; - - if (!snxtitem(&tenders, EF_SHIP, getstarg(player->argp[2], "Tender(s)? ", buf))) - return RET_SYN; - while (nxtitem(&tenders, (s_char *)&tender)) { - if (!player->owner) - continue; - if ((p = getstarg(player->argp[3], "Amount to transfer? ", buf)) == 0) - break; - if (!check_ship_ok(&tender)) - return RET_FAIL; - if ((amt = atoi(p)) == 0) - break; - ontender = getvar(ip->i_vtype, (s_char *)&tender, EF_SHIP); - if (ontender == 0 && amt > 0) { - pr("No %s on %s\n", ip->i_name, prship(&tender)); - return RET_FAIL; - } - vbase = &mchr[(int)tender.shp_type]; - maxtender = vl_find(ip->i_vtype, vbase->m_vtype, - vbase->m_vamt, (int)vbase->m_nv); - if (maxtender == 0) { - pr("A %s cannot hold any %s\n", - mchr[(int)tender.shp_type].m_name, - ip->i_name); - break; - } - if (!snxtitem(&targets, EF_LAND, - getstarg(player->argp[4], "Units to be tended? ", buf))) - break; - if (!check_ship_ok(&tender)) - return RET_FAIL; - total = 0; - while (tend_nxtitem(&targets, (s_char *)&target)) { - if (!player->owner) - continue; + if (!(ip = whatitem(player->argp[1], "Transfer what commodity? "))) + return RET_SYN; - if (target.lnd_ship != tender.shp_uid) - continue; - ontarget = getvar(ip->i_vtype,(s_char *)&target, EF_LAND); - if (ontarget == 0 && amt < 0) { - pr("No %s on %s\n", - ip->i_name, prship((struct shpstr *)&target)); - continue; - } - lbase = &lchr[(int)target.lnd_type]; - maxtarget = vl_find(ip->i_vtype, lbase->l_vtype, + if (!snxtitem + (&tenders, EF_SHIP, getstarg(player->argp[2], "Tender(s)? ", buf))) + return RET_SYN; + while (nxtitem(&tenders, (s_char *)&tender)) { + if (!player->owner) + continue; + if ((p = + getstarg(player->argp[3], "Amount to transfer? ", buf)) == 0) + break; + if (!check_ship_ok(&tender)) + return RET_FAIL; + if ((amt = atoi(p)) == 0) + break; + ontender = getvar(ip->i_vtype, (s_char *)&tender, EF_SHIP); + if (ontender == 0 && amt > 0) { + pr("No %s on %s\n", ip->i_name, prship(&tender)); + return RET_FAIL; + } + vbase = &mchr[(int)tender.shp_type]; + maxtender = vl_find(ip->i_vtype, vbase->m_vtype, + vbase->m_vamt, (int)vbase->m_nv); + if (maxtender == 0) { + pr("A %s cannot hold any %s\n", + mchr[(int)tender.shp_type].m_name, ip->i_name); + break; + } + if (!snxtitem(&targets, EF_LAND, + getstarg(player->argp[4], "Units to be tended? ", + buf))) + break; + if (!check_ship_ok(&tender)) + return RET_FAIL; + total = 0; + while (tend_nxtitem(&targets, (s_char *)&target)) { + if (!player->owner) + continue; + + if (target.lnd_ship != tender.shp_uid) + continue; + ontarget = getvar(ip->i_vtype, (s_char *)&target, EF_LAND); + if (ontarget == 0 && amt < 0) { + pr("No %s on %s\n", + ip->i_name, prship((struct shpstr *)&target)); + continue; + } + lbase = &lchr[(int)target.lnd_type]; + maxtarget = vl_find(ip->i_vtype, lbase->l_vtype, lbase->l_vamt, (int)lbase->l_nv); - if (amt < 0) { - if (!player->owner) - amt=0; + if (amt < 0) { + if (!player->owner) + amt = 0; - /* take from target and give to tender */ - transfer = min(ontarget, -amt); - transfer = min(maxtender - ontender, transfer); - if (transfer == 0) - continue; - putvar(ip->i_vtype, ontarget - transfer, - (s_char *)&target, EF_LAND); - ontender += transfer; - total += transfer; - } else { - /* give to target from tender */ - transfer = min(ontender, amt); - transfer = min(transfer, maxtarget - ontarget); - if (transfer == 0) - continue; - putvar(ip->i_vtype, ontarget + transfer, - (s_char *)&target, EF_LAND); - ontender -= transfer; - total += transfer; - } - expose_land(&tender, &target); - putland(target.lnd_uid, &target); - if (amt > 0 && ontender == 0) { - pr("%s out of %s\n", prship(&tender), - ip->i_name); - break; - } - } - pr("%d total %s transferred %s %s\n", - total, ip->i_name, (amt > 0) ? "off of" : "to", - prship(&tender)); - putvar(ip->i_vtype, ontender, (s_char *)&tender, EF_SHIP); - tender.shp_mission = 0; - putship(tender.shp_uid, &tender); + /* take from target and give to tender */ + transfer = min(ontarget, -amt); + transfer = min(maxtender - ontender, transfer); + if (transfer == 0) + continue; + putvar(ip->i_vtype, ontarget - transfer, + (s_char *)&target, EF_LAND); + ontender += transfer; + total += transfer; + } else { + /* give to target from tender */ + transfer = min(ontender, amt); + transfer = min(transfer, maxtarget - ontarget); + if (transfer == 0) + continue; + putvar(ip->i_vtype, ontarget + transfer, + (s_char *)&target, EF_LAND); + ontender -= transfer; + total += transfer; + } + expose_land(&tender, &target); + putland(target.lnd_uid, &target); + if (amt > 0 && ontender == 0) { + pr("%s out of %s\n", prship(&tender), ip->i_name); + break; + } } - return RET_OK; + pr("%d total %s transferred %s %s\n", + total, ip->i_name, (amt > 0) ? "off of" : "to", + prship(&tender)); + putvar(ip->i_vtype, ontender, (s_char *)&tender, EF_SHIP); + tender.shp_mission = 0; + putship(tender.shp_uid, &tender); + } + return RET_OK; } static void expose_land(struct shpstr *s1, struct lndstr *l1) { - if (getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)l1, EF_LAND) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)l1, EF_LAND); - if (getvar(V_PSTAGE, (s_char *)l1, EF_LAND) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s1, EF_SHIP); + if (getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)l1, EF_LAND) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)l1, EF_LAND); + if (getvar(V_PSTAGE, (s_char *)l1, EF_LAND) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s1, EF_SHIP); } diff --git a/src/lib/commands/map.c b/src/lib/commands/map.c index 02c38b2bf..1b540ac34 100644 --- a/src/lib/commands/map.c +++ b/src/lib/commands/map.c @@ -48,98 +48,115 @@ int map(void) { - register s_char *b; - int unit_type = 0; - int bmap = 0; - struct natstr *np; - s_char *str; - struct nstr_sect ns; - s_char origin = '\0'; - int as_country; - int map_flags = 0; - int i; - int where = 2; - s_char what[64]; - s_char buf[1024]; + register s_char *b; + int unit_type = 0; + int bmap = 0; + struct natstr *np; + s_char *str; + struct nstr_sect ns; + s_char origin = '\0'; + int as_country; + int map_flags = 0; + int i; + int where = 2; + s_char what[64]; + s_char buf[1024]; - if (**player->argp != 'm') { - if (**player->argp == 'b') - bmap = EF_BMAP; - else if (**player->argp == 'n') - bmap = EF_NMAP; - else { - if (**player->argp == 'l') - unit_type = EF_LAND; - else if (**player->argp == 'p') - unit_type = EF_PLANE; - else if (**player->argp == 's') - unit_type = EF_SHIP; - else { - logerror("map: bad player->argp[0]"); - return RET_SYN; - } - if (player->argp[0][1] == 'b') - bmap = EF_BMAP; - } + if (**player->argp != 'm') { + if (**player->argp == 'b') + bmap = EF_BMAP; + else if (**player->argp == 'n') + bmap = EF_NMAP; + else { + if (**player->argp == 'l') + unit_type = EF_LAND; + else if (**player->argp == 'p') + unit_type = EF_PLANE; + else if (**player->argp == 's') + unit_type = EF_SHIP; + else { + logerror("map: bad player->argp[0]"); + return RET_SYN; + } + if (player->argp[0][1] == 'b') + bmap = EF_BMAP; } + } - if (player->argp[1] == (s_char *) 0) { - if ((str = getstring("(sects)? ", buf)) == 0) - return RET_SYN; - } else { - str = player->argp[1]; - } + if (player->argp[1] == (s_char *)0) { + if ((str = getstring("(sects)? ", buf)) == 0) + return RET_SYN; + } else { + str = player->argp[1]; + } - np = getnatp(player->cnum); - if (*str == '*') { - sprintf(what, "%d:%d,%d:%d", - -WORLD_X/2, WORLD_X/2-1, - -WORLD_Y/2, WORLD_Y/2-1); - if (!snxtsct(&ns, what)) - return RET_FAIL; - } else if (!snxtsct(&ns, str)) { - i=atoi(str); - if (unit_map(unit_type, i, &ns, &origin)) - return RET_FAIL; - } - b = player->argp[2]; - while (b != (s_char *)0 && (*b)){ - where = 3; - switch(*b){ - case 's': - case 'S': map_flags |= MAP_SHIP; break; - case 'l': - case 'L': map_flags |= MAP_LAND; break; - case 'p': - case 'P': map_flags |= MAP_PLANE; break; - case '*': map_flags |= MAP_ALL; break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': where = 2; break; - case 't': bmap = EF_MAP; *(b+1)=0;break; - case 'r': bmap = EF_MAP + EF_BMAP;*(b+1)=0;break; - default: pr("Bad flag %c!\n",*b); - break; - } - b++; + np = getnatp(player->cnum); + if (*str == '*') { + sprintf(what, "%d:%d,%d:%d", + -WORLD_X / 2, WORLD_X / 2 - 1, + -WORLD_Y / 2, WORLD_Y / 2 - 1); + if (!snxtsct(&ns, what)) + return RET_FAIL; + } else if (!snxtsct(&ns, str)) { + i = atoi(str); + if (unit_map(unit_type, i, &ns, &origin)) + return RET_FAIL; + } + b = player->argp[2]; + while (b != (s_char *)0 && (*b)) { + where = 3; + switch (*b) { + case 's': + case 'S': + map_flags |= MAP_SHIP; + break; + case 'l': + case 'L': + map_flags |= MAP_LAND; + break; + case 'p': + case 'P': + map_flags |= MAP_PLANE; + break; + case '*': + map_flags |= MAP_ALL; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + where = 2; + break; + case 't': + bmap = EF_MAP; + *(b + 1) = 0; + break; + case 'r': + bmap = EF_MAP + EF_BMAP; + *(b + 1) = 0; + break; + default: + pr("Bad flag %c!\n", *b); + break; } + b++; + } - as_country = player->cnum; - if (player->god){ - if (player->argp[where] != (s_char *) 0) { - as_country=atoi(player->argp[where]); - if ((as_country < 0) || (as_country > MAXNOC)){ - as_country = player->cnum; - } - } + as_country = player->cnum; + if (player->god) { + if (player->argp[where] != (s_char *)0) { + as_country = atoi(player->argp[where]); + if ((as_country < 0) || (as_country > MAXNOC)) { + as_country = player->cnum; + } } + } - return draw_map(bmap, origin, map_flags, &ns, as_country); + return draw_map(bmap, origin, map_flags, &ns, as_country); } diff --git a/src/lib/commands/marc.c b/src/lib/commands/marc.c index 5a235dd30..b98064c1f 100644 --- a/src/lib/commands/marc.c +++ b/src/lib/commands/marc.c @@ -53,149 +53,147 @@ static int set_leader(struct emp_qelem *list, struct lndstr **leaderp); int march(void) { - struct nstr_item ni_land; - struct emp_qelem land_list; - double minmob, maxmob; - int together; - s_char *cp = 0; - struct lndstr *lnd = 0; /* leader */ - struct nstr_sect ns; - s_char origin; - int dir; - int stopping = 0; - int skip = 0; - s_char buf[1024]; - s_char prompt[128]; + struct nstr_item ni_land; + struct emp_qelem land_list; + double minmob, maxmob; + int together; + s_char *cp = 0; + struct lndstr *lnd = 0; /* leader */ + struct nstr_sect ns; + s_char origin; + int dir; + int stopping = 0; + int skip = 0; + s_char buf[1024]; + s_char prompt[128]; - if (!snxtitem(&ni_land, EF_LAND, player->argp[1])) - return RET_SYN; - lnd_sel(&ni_land, &land_list); - lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); - if (QEMPTY(&land_list)) { - pr("No lands\n"); - return RET_FAIL; - } - set_leader(&land_list, &lnd); - if (player->argp[2]) { - strcpy(buf, player->argp[2]); - if (!(cp = lnd_path(together, lnd, buf))) - cp = player->argp[2]; - } + if (!snxtitem(&ni_land, EF_LAND, player->argp[1])) + return RET_SYN; + lnd_sel(&ni_land, &land_list); + lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); + if (QEMPTY(&land_list)) { + pr("No lands\n"); + return RET_FAIL; + } + set_leader(&land_list, &lnd); + if (player->argp[2]) { + strcpy(buf, player->argp[2]); + if (!(cp = lnd_path(together, lnd, buf))) + cp = player->argp[2]; + } - while (!QEMPTY(&land_list)) { - s_char *bp,dp[80]; + while (!QEMPTY(&land_list)) { + s_char *bp, dp[80]; - if (cp == 0 || *cp == '\0' || stopping) { - stopping = 0; - lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); - if (QEMPTY(&land_list)) { - pr("No lands left\n"); - return RET_OK; - } - if (set_leader(&land_list, &lnd)) { - stopping = 1; - continue; - } - if (!skip) - nav_map(lnd->lnd_x, lnd->lnd_y, 1); - else - skip=0; - sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob, - minmob, xyas(lnd->lnd_x, lnd->lnd_y, player->cnum)); - cp = getstring(prompt, buf); + if (cp == 0 || *cp == '\0' || stopping) { + stopping = 0; + lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); + if (QEMPTY(&land_list)) { + pr("No lands left\n"); + return RET_OK; + } + if (set_leader(&land_list, &lnd)) { + stopping = 1; + continue; + } + if (!skip) + nav_map(lnd->lnd_x, lnd->lnd_y, 1); + else + skip = 0; + sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob, + minmob, xyas(lnd->lnd_x, lnd->lnd_y, player->cnum)); + cp = getstring(prompt, buf); /* Just in case any of our lands were shelled while we were at the * prompt, we call lnd_mar() again. */ - lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); - if (QEMPTY(&land_list)) { - pr("No lands left\n"); - return RET_OK; - } - if (set_leader(&land_list, &lnd)) { - stopping = 1; - continue; - } - } - if (cp == 0 || *cp == '\0') - cp = &dirch[DIR_STOP]; - if (*cp == 'M' || - *cp == 'B' || - *cp == 'f' || - *cp == 'i' || - *cp == 'm') { - ++cp; - if (cp[-1] == 'M') { - unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin); - draw_map(0, origin, 0, &ns, player->cnum); - skip = 1; - } else if (cp[-1] == 'B') { - unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin); - draw_map(EF_BMAP, origin, 0, &ns, player->cnum); - skip = 1; - } else if (cp[-1] == 'f') { - struct emp_qelem *qp; - qp = land_list.q_back; - emp_remque(land_list.q_back); - emp_insque(qp, &land_list); - set_leader(&land_list, &lnd); - } else if (cp[-1] == 'i') { - lnd_list(&land_list); - } else { - lnd_sweep(&land_list, 1, 1, player->cnum); - stopping |= lnd_check_mines(&land_list); - } - continue; - } else if (*cp == 'r' || - *cp == 'l') { - bp=++cp; - while((*bp != ' ') && (*bp)) bp++; - while((*bp == ' ') && (*bp)) bp++; - if ((bp != (s_char *)0) && (*bp)) - player->argp[1] = bp; - else { - sprintf(dp,"%d",lnd->lnd_uid); - player->argp[1] = dp; - } - if (cp[-1] == 'r') { - player->argp[0] = "lradar"; - rada(); - skip = 1; - } else - llook(); - *cp = 0; - player->btused++; - continue; - } else { - dir = chkdir(*cp++, DIR_STOP, DIR_LAST); - if (dir == -1) { - if (NULL != (cp = lnd_path(together, lnd, buf))) - continue; - direrr("`%c' to stop", 0 , 0); - pr(", `i' to list units, `f' to change leader,\n"); - pr("`r' to radar, `l' to look, `M' to map, `B' to bmap,\n"); - pr("and `m' to minesweep\n"); - stopping = 1; - continue; - } - } - stopping |= lnd_mar_one_sector(&land_list, dir, player->cnum, together); + lnd_mar(&land_list, &minmob, &maxmob, &together, player->cnum); + if (QEMPTY(&land_list)) { + pr("No lands left\n"); + return RET_OK; + } + if (set_leader(&land_list, &lnd)) { + stopping = 1; + continue; + } } - return RET_OK; + if (cp == 0 || *cp == '\0') + cp = &dirch[DIR_STOP]; + if (*cp == 'M' || + *cp == 'B' || *cp == 'f' || *cp == 'i' || *cp == 'm') { + ++cp; + if (cp[-1] == 'M') { + unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin); + draw_map(0, origin, 0, &ns, player->cnum); + skip = 1; + } else if (cp[-1] == 'B') { + unit_map(EF_LAND, lnd->lnd_uid, &ns, &origin); + draw_map(EF_BMAP, origin, 0, &ns, player->cnum); + skip = 1; + } else if (cp[-1] == 'f') { + struct emp_qelem *qp; + qp = land_list.q_back; + emp_remque(land_list.q_back); + emp_insque(qp, &land_list); + set_leader(&land_list, &lnd); + } else if (cp[-1] == 'i') { + lnd_list(&land_list); + } else { + lnd_sweep(&land_list, 1, 1, player->cnum); + stopping |= lnd_check_mines(&land_list); + } + continue; + } else if (*cp == 'r' || *cp == 'l') { + bp = ++cp; + while ((*bp != ' ') && (*bp)) + bp++; + while ((*bp == ' ') && (*bp)) + bp++; + if ((bp != (s_char *)0) && (*bp)) + player->argp[1] = bp; + else { + sprintf(dp, "%d", lnd->lnd_uid); + player->argp[1] = dp; + } + if (cp[-1] == 'r') { + player->argp[0] = "lradar"; + rada(); + skip = 1; + } else + llook(); + *cp = 0; + player->btused++; + continue; + } else { + dir = chkdir(*cp++, DIR_STOP, DIR_LAST); + if (dir == -1) { + if (NULL != (cp = lnd_path(together, lnd, buf))) + continue; + direrr("`%c' to stop", 0, 0); + pr(", `i' to list units, `f' to change leader,\n"); + pr("`r' to radar, `l' to look, `M' to map, `B' to bmap,\n"); + pr("and `m' to minesweep\n"); + stopping = 1; + continue; + } + } + stopping |= + lnd_mar_one_sector(&land_list, dir, player->cnum, together); + } + return RET_OK; } static int set_leader(struct emp_qelem *list, struct lndstr **leaderp) { - struct llist *llp = (struct llist *)(list->q_back); + struct llist *llp = (struct llist *)(list->q_back); - if (!*leaderp) - pr("Leader is "); - else if ((*leaderp)->lnd_uid != llp->land.lnd_uid) - pr("Changing leader to "); - else - return 0; - *leaderp = &llp->land; - pr("%s\n", prland(&llp->land)); - return 1; + if (!*leaderp) + pr("Leader is "); + else if ((*leaderp)->lnd_uid != llp->land.lnd_uid) + pr("Changing leader to "); + else + return 0; + *leaderp = &llp->land; + pr("%s\n", prland(&llp->land)); + return 1; } - diff --git a/src/lib/commands/mark.c b/src/lib/commands/mark.c index 7be9e5f8e..b9bab295a 100644 --- a/src/lib/commands/mark.c +++ b/src/lib/commands/mark.c @@ -52,30 +52,27 @@ mark(void) return RET_FAIL; } if (player->argp[1] && *(player->argp[1])) - return display_mark(player->argp[1]); + return display_mark(player->argp[1]); else - return display_mark(" "); + return display_mark(" "); } void pr_mark(struct comstr *comm) { time_t now; - double tleft; + double tleft; extern int MARK_DELAY; - - (void) time(&now); + + (void)time(&now); tleft = MARK_DELAY / 3600.0 - (now - comm->com_markettime) / 3600.0; - if (tleft < 0.0) + if (tleft < 0.0) tleft = 0.0; pr(" %3d $%12.2f %2d %5.2f hrs (%3d) %c %6d ", comm->com_uid, comm->com_maxprice, comm->com_maxbidder, - tleft, - comm->com_owner, - comm->com_type, - comm->com_amount); + tleft, comm->com_owner, comm->com_type, comm->com_amount); if (comm->com_owner == player->cnum || player->god) pr("%s", xyas(comm->sell_x, comm->sell_y, player->cnum)); pr("\n"); @@ -84,18 +81,18 @@ pr_mark(struct comstr *comm) int display_mark(s_char *arg) { - struct comstr comm; + struct comstr comm; struct comstr comm2; - int sellers = 0; - int cnt = 0; - char c; - s_char *p; - struct ichrstr *ip; - s_char buf[1024]; + int sellers = 0; + int cnt = 0; + char c; + s_char *p; + struct ichrstr *ip; + s_char buf[1024]; int cheapest_items[I_MAX + 2]; int i; int all = 0; - + /* First, we execute all trades, so that we can only buy what is available. */ check_market(); check_trade(); @@ -103,10 +100,10 @@ display_mark(s_char *arg) p = getstarg(arg, "What commodity (or 'all')? ", buf); c = (char)0; if (p && *p) - c = *p; + c = *p; for (ip = &ichr[0]; ip && ip->i_mnem; ip++) - if (ip->i_mnem == c) - break; + if (ip->i_mnem == c) + break; c = ip->i_mnem; pr("\n Empire Market Report\n "); @@ -155,7 +152,7 @@ display_mark(s_char *arg) continue; cnt = 1; pr_mark(&comm); - } + } } if (cnt <= 0) pr("\nHmmmm, the market seems to be empty today.\n"); diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index c18eb5452..f91e413cb 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -56,13 +56,13 @@ enum targ_type { targ_land, targ_ship, targ_sub, targ_unit, targ_bogus }; -struct flist{ - struct emp_qelem queue; /* list of fired things */ - int type; /* ship? otherwise sector */ - int uid; /* ship uid */ - coord x,y; /* sector coords */ - int defdam; /* damage defenders did */ - int victim; /* who I was shooting at */ +struct flist { + struct emp_qelem queue; /* list of fired things */ + int type; /* ship? otherwise sector */ + int uid; /* ship uid */ + coord x, y; /* sector coords */ + int defdam; /* damage defenders did */ + int victim; /* who I was shooting at */ }; union item_u { @@ -78,245 +78,241 @@ static int defend(struct emp_qelem *al, struct sctstr *vsect, struct sctstr *fsect, struct shpstr *vship, - struct shpstr *fship, - int fx, - int fy, - int *nd); + struct shpstr *fship, int fx, int fy, int *nd); int multifire(void) { - s_char vbuf[20]; - s_char *ptr; - double range2, range; - int trange; - coord fx; - coord fy; - coord x; - coord y; - int mil; - int gun; - int shell; - int shots; - double guneff; - int dam; - int totaldefdam=0; - int fshipno; - int vshipno; - double prb; - natid vict; - struct shpstr fship; - struct lndstr fland; - struct sctstr fsect; - struct shpstr vship; - struct sctstr vsect; - enum targ_type target, attacker, orig_attacker; - int rel; - struct natstr *natp; - struct nstr_item nbst; - int type; - s_char *p; - int nfiring=0; - int ndefending=0; - union item_u item; - struct emp_qelem fired, defended; - double odds; - s_char buf[1024]; + s_char vbuf[20]; + s_char *ptr; + double range2, range; + int trange; + coord fx; + coord fy; + coord x; + coord y; + int mil; + int gun; + int shell; + int shots; + double guneff; + int dam; + int totaldefdam = 0; + int fshipno; + int vshipno; + double prb; + natid vict; + struct shpstr fship; + struct lndstr fland; + struct sctstr fsect; + struct shpstr vship; + struct sctstr vsect; + enum targ_type target, attacker, orig_attacker; + int rel; + struct natstr *natp; + struct nstr_item nbst; + int type; + s_char *p; + int nfiring = 0; + int ndefending = 0; + union item_u item; + struct emp_qelem fired, defended; + double odds; + s_char buf[1024]; #if defined(_WIN32) - time_t now; + time_t now; #endif - + emp_initque(&fired); emp_initque(&defended); - type=(-1); - while ((type != EF_SECTOR) && (type != EF_SHIP) && (type != EF_LAND)){ - if (!(p = getstarg(player->argp[1], - "Firing from ship(s), sect(s), or land unit(s)? ", buf))) - return RET_SYN; - player->argp[1]=0; - type = ef_byname(p); - if (type == EF_SECTOR){ - if (opt_NO_FORT_FIRE) { - pr("Fort firing is disabled.\n"); - return RET_FAIL; - } - orig_attacker = attacker=targ_land; - shots = 1; - } - else if (type == EF_SHIP) { - orig_attacker = attacker=targ_ship; - } - else if (type == EF_LAND) { - orig_attacker = attacker=targ_unit; - } - else - pr("Please type 'sh', 'l', or 'se'!\n"); + type = (-1); + while ((type != EF_SECTOR) && (type != EF_SHIP) && (type != EF_LAND)) { + if (!(p = getstarg(player->argp[1], + "Firing from ship(s), sect(s), or land unit(s)? ", + buf))) + return RET_SYN; + player->argp[1] = 0; + type = ef_byname(p); + if (type == EF_SECTOR) { + if (opt_NO_FORT_FIRE) { + pr("Fort firing is disabled.\n"); + return RET_FAIL; + } + orig_attacker = attacker = targ_land; + shots = 1; + } else if (type == EF_SHIP) { + orig_attacker = attacker = targ_ship; + } else if (type == EF_LAND) { + orig_attacker = attacker = targ_unit; + } else + pr("Please type 'sh', 'l', or 'se'!\n"); } - if ((ptr = getstarg(player->argp[2], "Firing from? ", buf)) == 0 || *ptr == '\0') - return RET_SYN; - + if ((ptr = getstarg(player->argp[2], "Firing from? ", buf)) == 0 + || *ptr == '\0') + return RET_SYN; + if (!snxtitem(&nbst, type, ptr)) - return RET_SYN; - - if (player->aborted){ - pr("Fire aborted.\n"); - return RET_OK; + return RET_SYN; + + if (player->aborted) { + pr("Fire aborted.\n"); + return RET_OK; } - while(nxtitem(&nbst, (s_char *)&item)){ - attacker = orig_attacker; - if (attacker == targ_unit){ - if (!getland(item.land.lnd_uid, &fland)) - continue; - if (!getsect(item.land.lnd_x,item.land.lnd_y,&fsect)) - continue; - if (item.land.lnd_own != player->cnum) - continue; - - if (fland.lnd_frg == 0){ - pr("Unit %d cannot fire!\n",fland.lnd_uid); - continue; - } - if (lnd_getmil(&fland) < 1) { - pr("Unit %d cannot fire because it has no military!\n", - fland.lnd_uid); - continue; - } - if (fland.lnd_ship >= 0){ - pr("Unit %d cannot fire because it is on a ship!\n", - fland.lnd_uid); - continue; - } - if (fland.lnd_land >= 0){ - pr("Unit %d cannot fire because it is on a land unit!\n", - fland.lnd_uid); - continue; - } - if (fland.lnd_effic < LAND_MINFIREEFF){ - pr("Unit %d cannot fire because it is less than %d%% efficient\n",fland.lnd_uid, LAND_MINFIREEFF); - continue; - } - resupply_commod(&fland,I_SHELL); /* Get more shells */ - putland(fland.lnd_uid,&fland); - if (getvar(V_SHELL, (s_char *)&fland, EF_LAND) == 0){ - pr("%s -- not enough shells\n", - prland(&fland)); - continue; - } - } - else if (attacker == targ_ship){ - if (!getship(item.ship.shp_uid, &fship)) - continue; - if (item.ship.shp_own != player->cnum) - continue; - if (getvar(V_MILIT, (s_char *)&item.ship, EF_SHIP) < 1){ - pr("Not enough mil on ship #%d\n",item.ship.shp_uid); - continue; - } - gun = getvar(V_GUN, (s_char *)&item.ship, EF_SHIP); - gun = min(gun, item.ship.shp_glim); - if (item.ship.shp_frnge == 0){ - pr("Ships %d cannot fire guns!\n",item.ship.shp_uid); - continue; - } - if (gun == 0){ - pr("Not enough guns on ship #%d\n",item.ship.shp_uid); - continue; - } - if (getvar(V_SHELL, (s_char *)&item.ship, EF_SHIP) == 0){ - pr("Not enough shells on ship #%d\n",item.ship.shp_uid); - continue; - } - if (item.ship.shp_effic < 60){ - pr("Ship #%d is crippled!\n",item.ship.shp_uid); - continue; - } - fshipno=fship.shp_uid; - } - else if (attacker == targ_land){ - if (!getsect(item.sect.sct_x,item.sect.sct_y, &fsect)) - continue; - if (item.sect.sct_own != player->cnum) - continue; - if (item.sect.sct_type != SCT_FORTR) - continue; - if (item.sect.sct_effic < ((u_char)FORTEFF)){ - pr("Fort not efficient enough to fire!\n"); - continue; - } - if (getvar(V_GUN, (s_char *)&item.sect, EF_SECTOR) == 0){ - pr("Not enough guns in sector %s!\n",xyas(item.sect.sct_x,item.sect.sct_y,player->cnum)); - continue; - } - if (getvar(V_SHELL, (s_char *)&item.sect, EF_SECTOR) == 0){ - pr("Not enough shells in sector %s!\n",xyas(item.sect.sct_x,item.sect.sct_y,player->cnum)); - continue; - } - if (getvar(V_MILIT, (s_char *)&item.sect, EF_SECTOR) < 5){ - pr("Not enough military in sector %s!\n",xyas(item.sect.sct_x,item.sect.sct_y,player->cnum)); - continue; - } - pr("\nSector %s firing\n", - xyas(item.sect.sct_x,item.sect.sct_y,player->cnum)); - } - if ((ptr = getstarg(player->argp[3], "Firing at? ", buf)) == 0 || *ptr == '\0') - continue; - if (player->aborted){ - pr("Fire aborted.\n"); - continue; - } - ptr[19] = 0; - (void)strcpy(vbuf, ptr); - if (issector(vbuf)) - target = targ_land; - else - target = targ_ship; - if (target == targ_ship) { - vshipno = atoi(vbuf); - if (vshipno < 0 || !getship(vshipno, &vship) || - (!vship.shp_own)) { - pr("No such ship exists!\n"); - continue; - } - target = (mchr[(int)vship.shp_type].m_flags & M_SUB) ? - targ_sub : targ_ship; - vict = vship.shp_own; - x = vship.shp_x; - y = vship.shp_y; - if (!getsect(x, y, &vsect)) { - pr("No such sector exists!\n"); - continue; - } - } else { - if (!sarg_xy(vbuf, &x, &y) || !getsect(x, y, &vsect)) { - pr("No such sector exists!\n"); - continue; - } - /* We check the sector type, but we only use it for damage, not - reporting. That way, you don't get extra information you wouldn't - normally get. Besides, what if they want to slam water? :) */ - if (vsect.sct_type == SCT_SANCT || - vsect.sct_type == SCT_WATER) - target = targ_bogus; - else - target = targ_land; - vict = vsect.sct_own; - x = vsect.sct_x; - y = vsect.sct_y; + while (nxtitem(&nbst, (s_char *)&item)) { + attacker = orig_attacker; + if (attacker == targ_unit) { + if (!getland(item.land.lnd_uid, &fland)) + continue; + if (!getsect(item.land.lnd_x, item.land.lnd_y, &fsect)) + continue; + if (item.land.lnd_own != player->cnum) + continue; + + if (fland.lnd_frg == 0) { + pr("Unit %d cannot fire!\n", fland.lnd_uid); + continue; + } + if (lnd_getmil(&fland) < 1) { + pr("Unit %d cannot fire because it has no military!\n", + fland.lnd_uid); + continue; + } + if (fland.lnd_ship >= 0) { + pr("Unit %d cannot fire because it is on a ship!\n", + fland.lnd_uid); + continue; + } + if (fland.lnd_land >= 0) { + pr("Unit %d cannot fire because it is on a land unit!\n", + fland.lnd_uid); + continue; + } + if (fland.lnd_effic < LAND_MINFIREEFF) { + pr("Unit %d cannot fire because it is less than %d%% efficient\n", fland.lnd_uid, LAND_MINFIREEFF); + continue; + } + resupply_commod(&fland, I_SHELL); /* Get more shells */ + putland(fland.lnd_uid, &fland); + if (getvar(V_SHELL, (s_char *)&fland, EF_LAND) == 0) { + pr("%s -- not enough shells\n", prland(&fland)); + continue; + } + } else if (attacker == targ_ship) { + if (!getship(item.ship.shp_uid, &fship)) + continue; + if (item.ship.shp_own != player->cnum) + continue; + if (getvar(V_MILIT, (s_char *)&item.ship, EF_SHIP) < 1) { + pr("Not enough mil on ship #%d\n", item.ship.shp_uid); + continue; + } + gun = getvar(V_GUN, (s_char *)&item.ship, EF_SHIP); + gun = min(gun, item.ship.shp_glim); + if (item.ship.shp_frnge == 0) { + pr("Ships %d cannot fire guns!\n", item.ship.shp_uid); + continue; + } + if (gun == 0) { + pr("Not enough guns on ship #%d\n", item.ship.shp_uid); + continue; + } + if (getvar(V_SHELL, (s_char *)&item.ship, EF_SHIP) == 0) { + pr("Not enough shells on ship #%d\n", item.ship.shp_uid); + continue; + } + if (item.ship.shp_effic < 60) { + pr("Ship #%d is crippled!\n", item.ship.shp_uid); + continue; + } + fshipno = fship.shp_uid; + } else if (attacker == targ_land) { + if (!getsect(item.sect.sct_x, item.sect.sct_y, &fsect)) + continue; + if (item.sect.sct_own != player->cnum) + continue; + if (item.sect.sct_type != SCT_FORTR) + continue; + if (item.sect.sct_effic < ((u_char)FORTEFF)) { + pr("Fort not efficient enough to fire!\n"); + continue; + } + if (getvar(V_GUN, (s_char *)&item.sect, EF_SECTOR) == 0) { + pr("Not enough guns in sector %s!\n", + xyas(item.sect.sct_x, item.sect.sct_y, player->cnum)); + continue; + } + if (getvar(V_SHELL, (s_char *)&item.sect, EF_SECTOR) == 0) { + pr("Not enough shells in sector %s!\n", + xyas(item.sect.sct_x, item.sect.sct_y, player->cnum)); + continue; + } + if (getvar(V_MILIT, (s_char *)&item.sect, EF_SECTOR) < 5) { + pr("Not enough military in sector %s!\n", + xyas(item.sect.sct_x, item.sect.sct_y, player->cnum)); + continue; + } + pr("\nSector %s firing\n", + xyas(item.sect.sct_x, item.sect.sct_y, player->cnum)); + } + if ((ptr = getstarg(player->argp[3], "Firing at? ", buf)) == 0 + || *ptr == '\0') + continue; + if (player->aborted) { + pr("Fire aborted.\n"); + continue; + } + ptr[19] = 0; + (void)strcpy(vbuf, ptr); + if (issector(vbuf)) + target = targ_land; + else + target = targ_ship; + if (target == targ_ship) { + vshipno = atoi(vbuf); + if (vshipno < 0 || !getship(vshipno, &vship) || + (!vship.shp_own)) { + pr("No such ship exists!\n"); + continue; + } + target = (mchr[(int)vship.shp_type].m_flags & M_SUB) ? + targ_sub : targ_ship; + vict = vship.shp_own; + x = vship.shp_x; + y = vship.shp_y; + if (!getsect(x, y, &vsect)) { + pr("No such sector exists!\n"); + continue; + } + } else { + if (!sarg_xy(vbuf, &x, &y) || !getsect(x, y, &vsect)) { + pr("No such sector exists!\n"); + continue; + } + /* We check the sector type, but we only use it for damage, not + reporting. That way, you don't get extra information you wouldn't + normally get. Besides, what if they want to slam water? :) */ + if (vsect.sct_type == SCT_SANCT || vsect.sct_type == SCT_WATER) + target = targ_bogus; + else + target = targ_land; + vict = vsect.sct_own; + x = vsect.sct_x; + y = vsect.sct_y; + } + if (attacker == targ_ship) { + shots = -1; /* convert to max later */ + if (fship.shp_own != player->cnum) { + pr("Not your ship!\n"); + continue; + } + if (target == targ_sub || target == targ_ship) { + if (fship.shp_uid == vship.shp_uid) { + pr("You can't fire upon yourself!\n"); + continue; } - if (attacker == targ_ship) { - shots = -1; /* convert to max later */ - if (fship.shp_own != player->cnum) { - pr("Not your ship!\n"); - continue; - } - if (target == targ_sub || target == targ_ship) { - if (fship.shp_uid == vship.shp_uid) { - pr("You can't fire upon yourself!\n"); - continue; - } - } - fx = fship.shp_x; - fy = fship.shp_y; + } + fx = fship.shp_x; + fy = fship.shp_y; /* attacker = (mchr[fship.shp_type].m_flags & M_SUB) ? targ_sub : targ_ship; @@ -325,165 +321,167 @@ multifire(void) continue; } */ - attacker = targ_ship; - if ((mil = getvar(V_MILIT, (s_char *)&fship, EF_SHIP)) < 1) { - pr("Not enough military for firing crew.\n"); - continue; - } - gun = getvar(V_GUN, (s_char *)&fship, EF_SHIP); - gun = min(gun, fship.shp_glim); - if (fship.shp_frnge == 0 || gun == 0) { - pr("Insufficient arms.\n"); - continue; - } - shell = getvar(V_SHELL, (s_char *)&fship, EF_SHIP); - if (shell < 2) - shell+=supply_commod(fship.shp_own,fship.shp_x, - fship.shp_y,I_SHELL,2-shell); - if (shell <= 0){ - pr("Klick! ...\n"); - continue; - } - if (fship.shp_effic < 60) { - pr("Ship #%d is crippled (%d%%)\n", fshipno, - fship.shp_effic); - continue; - } - range = techfact(fship.shp_tech, - (double)fship.shp_frnge / 2.0); - range2 = (double)roundrange(range); - pr("range is %.2f (%.2f)\n", range2, range); - if (target == targ_sub) { - if ((mchr[(int)fship.shp_type].m_flags & M_DCH) == 0) { - pr("A %s can't drop depth charges!\n", - mchr[(int)fship.shp_type].m_name); - continue; - } - if (shell < 2) { - pr("Not enough shells for depth charge!\n"); - continue; - } - } - gun = min(gun, shell*2); - gun = min(gun, mil / 2); - gun = max(gun, 1); - if (shots > gun || shots < 0) - shots = gun; - else if (shots == 0) { - pr("No shots fired.\n"); - continue; - } - guneff = seagun(fship.shp_effic, shots); - dam = (int)guneff; - shell -= ldround(((double)shots)/2.0,1); - putvar(V_SHELL, shell, (s_char *)&fship, EF_SHIP); - putship(fship.shp_uid,&fship); - if (opt_NOMOBCOST == 0) - fship.shp_mobil = max(fship.shp_mobil - 15, -100); - } else if (attacker == targ_unit) { - if (fland.lnd_own != player->cnum) { - pr("Not your unit!\n"); - continue; - } - - if (target == targ_land) { - if (fland.lnd_x == vsect.sct_x && fland.lnd_y == vsect.sct_y) { - pr("You can't fire upon yourself!\n"); - continue; - } - } - - fx = fland.lnd_x; - fy = fland.lnd_y; - - if (fland.lnd_frg == 0){ - pr("Unit %d cannot fire!\n",fland.lnd_uid); - continue; - } - if (getvar(V_SHELL, (s_char *)&fland, EF_LAND) == 0){ - pr("%s -- not enough shells\n", prland(&fland)); - continue; - } - - shell = getvar(V_SHELL,(s_char *)&fland, EF_LAND); - - range = techfact((int)fland.lnd_tech, - (double)fland.lnd_frg / 2.0); - range2 = (double)roundrange(range); - pr("range is %.2f (%.2f)\n", range2, range); - if (target == targ_sub) { - pr("A %s can't drop depth charges!\n", - lchr[(int)fland.lnd_type].l_name); - continue; - } - - gun = getvar(V_GUN, (s_char *)&fland, EF_LAND); - if (gun <= 0) { - pr("%s -- not enough guns\n", prland(&fland)); - continue; - } + attacker = targ_ship; + if ((mil = getvar(V_MILIT, (s_char *)&fship, EF_SHIP)) < 1) { + pr("Not enough military for firing crew.\n"); + continue; + } + gun = getvar(V_GUN, (s_char *)&fship, EF_SHIP); + gun = min(gun, fship.shp_glim); + if (fship.shp_frnge == 0 || gun == 0) { + pr("Insufficient arms.\n"); + continue; + } + shell = getvar(V_SHELL, (s_char *)&fship, EF_SHIP); + if (shell < 2) + shell += supply_commod(fship.shp_own, fship.shp_x, + fship.shp_y, I_SHELL, 2 - shell); + if (shell <= 0) { + pr("Klick! ...\n"); + continue; + } + if (fship.shp_effic < 60) { + pr("Ship #%d is crippled (%d%%)\n", fshipno, + fship.shp_effic); + continue; + } + range = techfact(fship.shp_tech, + (double)fship.shp_frnge / 2.0); + range2 = (double)roundrange(range); + pr("range is %.2f (%.2f)\n", range2, range); + if (target == targ_sub) { + if ((mchr[(int)fship.shp_type].m_flags & M_DCH) == 0) { + pr("A %s can't drop depth charges!\n", + mchr[(int)fship.shp_type].m_name); + continue; + } + if (shell < 2) { + pr("Not enough shells for depth charge!\n"); + continue; + } + } + gun = min(gun, shell * 2); + gun = min(gun, mil / 2); + gun = max(gun, 1); + if (shots > gun || shots < 0) + shots = gun; + else if (shots == 0) { + pr("No shots fired.\n"); + continue; + } + guneff = seagun(fship.shp_effic, shots); + dam = (int)guneff; + shell -= ldround(((double)shots) / 2.0, 1); + putvar(V_SHELL, shell, (s_char *)&fship, EF_SHIP); + putship(fship.shp_uid, &fship); + if (opt_NOMOBCOST == 0) + fship.shp_mobil = max(fship.shp_mobil - 15, -100); + } else if (attacker == targ_unit) { + if (fland.lnd_own != player->cnum) { + pr("Not your unit!\n"); + continue; + } - dam = (int)landunitgun(fland.lnd_effic, fland.lnd_dam, gun, - fland.lnd_ammo, shell); - if (target == targ_ship){ - if (chance(((double)fland.lnd_acc)/100.0)) - dam = ldround(((double)dam/2.0),1); - } - use_supply(&fland); - resupply_commod(&fland,I_SHELL); /* Get more shells */ - putland(fland.lnd_uid,&fland); - } else { - fx=fsect.sct_x; - fy=fsect.sct_y; - if (fsect.sct_own != player->cnum || - fsect.sct_type != SCT_FORTR) { - pr("No fortress at %s\n", xyas(fsect.sct_x, - fsect.sct_y,player->cnum)); - continue; - } - if (target == targ_land) { - if (fsect.sct_x == vsect.sct_x && fsect.sct_y == vsect.sct_y) { - pr("You can't fire upon yourself!\n"); - continue; - } - } - attacker = targ_land; - if ((gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR)) == 0) { - pr("Insufficient arms.\n"); - continue; - } - shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR); - if (shell <= 0) - shell+=supply_commod(fsect.sct_own,fsect.sct_x, - fsect.sct_y,I_SHELL,1); - if (shell <= 0){ - pr("Klick! ...\n"); - continue; - } - if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5) { - pr("Not enough military for firing crew.\n"); - continue; - } - if (target == targ_sub) { - pr("Target ship not sighted!\n"); - continue; - } - if (gun>7) - gun = 7; - range = tfactfire(player->cnum, 7.0); - if (fsect.sct_effic > 59) - range++; - range2 = (double)roundrange(range); - pr("range is %.2f (%.2f)\n", range2, range); - guneff = landgun((int)fsect.sct_effic, gun); - dam = (int)guneff; - shell--; - putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR); - putsect(&fsect); + if (target == targ_land) { + if (fland.lnd_x == vsect.sct_x + && fland.lnd_y == vsect.sct_y) { + pr("You can't fire upon yourself!\n"); + continue; + } + } + + fx = fland.lnd_x; + fy = fland.lnd_y; + + if (fland.lnd_frg == 0) { + pr("Unit %d cannot fire!\n", fland.lnd_uid); + continue; + } + if (getvar(V_SHELL, (s_char *)&fland, EF_LAND) == 0) { + pr("%s -- not enough shells\n", prland(&fland)); + continue; + } + + shell = getvar(V_SHELL, (s_char *)&fland, EF_LAND); + + range = techfact((int)fland.lnd_tech, + (double)fland.lnd_frg / 2.0); + range2 = (double)roundrange(range); + pr("range is %.2f (%.2f)\n", range2, range); + if (target == targ_sub) { + pr("A %s can't drop depth charges!\n", + lchr[(int)fland.lnd_type].l_name); + continue; + } + + gun = getvar(V_GUN, (s_char *)&fland, EF_LAND); + if (gun <= 0) { + pr("%s -- not enough guns\n", prland(&fland)); + continue; + } + + dam = (int)landunitgun(fland.lnd_effic, fland.lnd_dam, gun, + fland.lnd_ammo, shell); + if (target == targ_ship) { + if (chance(((double)fland.lnd_acc) / 100.0)) + dam = ldround(((double)dam / 2.0), 1); + } + use_supply(&fland); + resupply_commod(&fland, I_SHELL); /* Get more shells */ + putland(fland.lnd_uid, &fland); + } else { + fx = fsect.sct_x; + fy = fsect.sct_y; + if (fsect.sct_own != player->cnum || + fsect.sct_type != SCT_FORTR) { + pr("No fortress at %s\n", xyas(fsect.sct_x, + fsect.sct_y, player->cnum)); + continue; + } + if (target == targ_land) { + if (fsect.sct_x == vsect.sct_x + && fsect.sct_y == vsect.sct_y) { + pr("You can't fire upon yourself!\n"); + continue; } - trange = mapdist(x, y, fx, fy); - if (trange > range2){ - pr("Target out of range.\n"); + } + attacker = targ_land; + if ((gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR)) == 0) { + pr("Insufficient arms.\n"); + continue; + } + shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR); + if (shell <= 0) + shell += supply_commod(fsect.sct_own, fsect.sct_x, + fsect.sct_y, I_SHELL, 1); + if (shell <= 0) { + pr("Klick! ...\n"); + continue; + } + if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5) { + pr("Not enough military for firing crew.\n"); + continue; + } + if (target == targ_sub) { + pr("Target ship not sighted!\n"); + continue; + } + if (gun > 7) + gun = 7; + range = tfactfire(player->cnum, 7.0); + if (fsect.sct_effic > 59) + range++; + range2 = (double)roundrange(range); + pr("range is %.2f (%.2f)\n", range2, range); + guneff = landgun((int)fsect.sct_effic, gun); + dam = (int)guneff; + shell--; + putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR); + putsect(&fsect); + } + trange = mapdist(x, y, fx, fy); + if (trange > range2) { + pr("Target out of range.\n"); /* switch (target) { case targ_land: @@ -495,20 +493,20 @@ multifire(void) break ; } */ - switch (attacker) { - case targ_land: - putsect(&fsect); - break ; - case targ_unit: - fland.lnd_mission = 0; - putland(fland.lnd_uid, &fland); - break; - default: - fship.shp_mission = 0; - putship(fship.shp_uid, &fship); - } - continue; - } + switch (attacker) { + case targ_land: + putsect(&fsect); + break; + case targ_unit: + fland.lnd_mission = 0; + putland(fland.lnd_uid, &fland); + break; + default: + fship.shp_mission = 0; + putship(fship.shp_uid, &fship); + } + continue; + } /* if (target == targ_bogus) { if (vsect.sct_type == SCT_SANCT) { @@ -522,551 +520,552 @@ multifire(void) } } */ - switch (target) { - case targ_ship: - if (!trechk(player->cnum, vict, SEAFIR)) - continue; - break; - case targ_sub: - if (!trechk(player->cnum, vict, SUBFIR)) - continue; - break; - case targ_unit: - case targ_land: - if (!trechk(player->cnum, vict, LANFIR)) - continue; - break; - default: - break; - } - - if (opt_SLOW_WAR) { - if (target == targ_land){ - natp = getnatp(player->cnum); - rel = getrel(natp,vict); - if ((rel != AT_WAR) && (player->cnum != vict) && - (vict) && (vsect.sct_oldown != player->cnum)){ - pr("You're not at war with them!\n"); - continue; - } - } + switch (target) { + case targ_ship: + if (!trechk(player->cnum, vict, SEAFIR)) + continue; + break; + case targ_sub: + if (!trechk(player->cnum, vict, SUBFIR)) + continue; + break; + case targ_unit: + case targ_land: + if (!trechk(player->cnum, vict, LANFIR)) + continue; + break; + default: + break; + } + + if (opt_SLOW_WAR) { + if (target == targ_land) { + natp = getnatp(player->cnum); + rel = getrel(natp, vict); + if ((rel != AT_WAR) && (player->cnum != vict) && + (vict) && (vsect.sct_oldown != player->cnum)) { + pr("You're not at war with them!\n"); + continue; } - nfiring++; - switch (target) { - case targ_sub: - pr_beep(); - pr("Kawhomp!!!\n"); - if (vship.shp_rflags & RET_DCHRGED) - retreat_ship(&vship,'d'); - break ; - default: - pr_beep(); - pr("Kaboom!!!\n"); - prb = (double)(range2?(trange / range2):1.0); - prb *= prb; + } + } + nfiring++; + switch (target) { + case targ_sub: + pr_beep(); + pr("Kawhomp!!!\n"); + if (vship.shp_rflags & RET_DCHRGED) + retreat_ship(&vship, 'd'); + break; + default: + pr_beep(); + pr("Kaboom!!!\n"); + prb = (double)(range2 ? (trange / range2) : 1.0); + prb *= prb; #if !defined(_WIN32) - srandom(random()); + srandom(random()); #else - (void) time(&now); - (void) srand(now); + (void)time(&now); + (void)srand(now); #endif - if (chance(prb)) { - pr("Wind deflects shell%s.\n", splur(shots)); + if (chance(prb)) { + pr("Wind deflects shell%s.\n", splur(shots)); /* dam = (int)((double)dam / 2.0);*/ - dam = (int)((double)dam * (double)((double)(90 - (random() % 11)) / 100.0)); - if (dam < 0) - dam = 0; - } - break ; - } - switch (target) { - case targ_bogus: - case targ_land: - nreport(player->cnum, N_SCT_SHELL, vict, 1); - if (vict && vict != player->cnum) - wu(0, vict, - "Country #%d shelled sector %s for %d damage.\n", - player->cnum, xyas(x, y, vict), dam); - pr("Shell%s hit sector %s for %d damage.\n", - splur(shots), xyas(x, y, player->cnum), dam); - /* Ok, it wasn't a bogus target, so do damage. */ - if (target != targ_bogus) - sectdamage(&vsect, dam, 0); - break ; - case targ_ship: - nreport(player->cnum, N_SHP_SHELL, vict, 1); - default: - if ((target != targ_sub) || - ((vship.shp_rflags & RET_DCHRGED) == 0)) - check_retreat_and_do_shipdamage(&vship, dam); - else - shipdamage(&vship, dam); - if (vict) { - wu(0, vict, - "Country #%d shelled %s in %s for %d damage.\n", - player->cnum, prship(&vship), - xyas(vship.shp_x, vship.shp_y, vict), - dam); - } - pr("Shell%s hit %s in %s for %d damage.\n", - splur(shots), prsub(&vship), - xyas(vship.shp_x, vship.shp_y, player->cnum), - dam); - - if (vship.shp_effic < SHIP_MINEFF) - pr("%s sunk!\n", prsub(&vship)); - - break ; - } - /* Ok, now, check if we had a bogus target. If so, - just continue on, since there is no defender. */ - if (target == targ_bogus) - continue; - if (attacker == targ_unit){ - attacker = targ_land; - getsect(fland.lnd_x,fland.lnd_y,&fsect); - } - totaldefdam=defend(&fired,&defended,target,attacker,&vsect,&fsect,&vship,&fship,fx,fy,&ndefending); - switch (target) { - case targ_land: - putsect(&vsect); - break ; - default: - putship(vship.shp_uid, &vship); - break ; - } - if ((totaldefdam == 0) && (target == targ_ship)) - if (vship.shp_rflags & RET_INJURED) - retreat_ship(&vship,'h'); - switch (attacker) { - case targ_land: - putsect(&fsect); - break ; - default: - if ((target == targ_ship) || (target == targ_sub)) { - if (fship.shp_effic > SHIP_MINEFF) { - shp_missdef(&fship, vict); - }; - }; - putship(fship.shp_uid, &fship); - break ; - } + dam = + (int)((double)dam * + (double)((double)(90 - (random() % 11)) / + 100.0)); + if (dam < 0) + dam = 0; + } + break; + } + switch (target) { + case targ_bogus: + case targ_land: + nreport(player->cnum, N_SCT_SHELL, vict, 1); + if (vict && vict != player->cnum) + wu(0, vict, + "Country #%d shelled sector %s for %d damage.\n", + player->cnum, xyas(x, y, vict), dam); + pr("Shell%s hit sector %s for %d damage.\n", + splur(shots), xyas(x, y, player->cnum), dam); + /* Ok, it wasn't a bogus target, so do damage. */ + if (target != targ_bogus) + sectdamage(&vsect, dam, 0); + break; + case targ_ship: + nreport(player->cnum, N_SHP_SHELL, vict, 1); + default: + if ((target != targ_sub) || + ((vship.shp_rflags & RET_DCHRGED) == 0)) + check_retreat_and_do_shipdamage(&vship, dam); + else + shipdamage(&vship, dam); + if (vict) { + wu(0, vict, + "Country #%d shelled %s in %s for %d damage.\n", + player->cnum, prship(&vship), + xyas(vship.shp_x, vship.shp_y, vict), dam); + } + pr("Shell%s hit %s in %s for %d damage.\n", + splur(shots), prsub(&vship), + xyas(vship.shp_x, vship.shp_y, player->cnum), dam); + + if (vship.shp_effic < SHIP_MINEFF) + pr("%s sunk!\n", prsub(&vship)); + + break; + } + /* Ok, now, check if we had a bogus target. If so, + just continue on, since there is no defender. */ + if (target == targ_bogus) + continue; + if (attacker == targ_unit) { + attacker = targ_land; + getsect(fland.lnd_x, fland.lnd_y, &fsect); + } + totaldefdam = + defend(&fired, &defended, target, attacker, &vsect, &fsect, + &vship, &fship, fx, fy, &ndefending); + switch (target) { + case targ_land: + putsect(&vsect); + break; + default: + putship(vship.shp_uid, &vship); + break; + } + if ((totaldefdam == 0) && (target == targ_ship)) + if (vship.shp_rflags & RET_INJURED) + retreat_ship(&vship, 'h'); + switch (attacker) { + case targ_land: + putsect(&fsect); + break; + default: + if ((target == targ_ship) || (target == targ_sub)) { + if (fship.shp_effic > SHIP_MINEFF) { + shp_missdef(&fship, vict); + }; + }; + putship(fship.shp_uid, &fship); + break; + } } - + use_ammo(&defended); if (nfiring) - odds = ((double)ndefending)/((double)nfiring); + odds = ((double)ndefending) / ((double)nfiring); else - odds = 1.0; + odds = 1.0; do_defdam(&fired, odds); return RET_OK; } static int -defend(struct emp_qelem *al, struct emp_qelem *dl, enum targ_type target, enum targ_type attacker, struct sctstr *vsect, struct sctstr *fsect, struct shpstr *vship, struct shpstr *fship, int fx, int fy, int *nd) +defend(struct emp_qelem *al, struct emp_qelem *dl, enum targ_type target, + enum targ_type attacker, struct sctstr *vsect, struct sctstr *fsect, + struct shpstr *vship, struct shpstr *fship, int fx, int fy, int *nd) { - - int dam; - int vict, nfiring=0; + + int dam; + int vict, nfiring = 0; struct flist *fp; - int aown; - + int aown; + if (attacker == targ_land) - aown = fsect->sct_own; + aown = fsect->sct_own; else - aown = fship->shp_own; - + aown = fship->shp_own; + if (target == targ_land) - vict = vsect->sct_own; + vict = vsect->sct_own; else - vict = vship->shp_own; - - if (0 != (dam = quiet_bigdef(attacker,dl,vict,aown,fx,fy,&nfiring))) { - if (nfiring > *nd) - *nd = nfiring; - fp = (struct flist *)malloc(sizeof(struct flist)); - bzero((s_char *)fp,sizeof(struct flist)); - fp->defdam = dam; - fp->victim = vict; - switch (attacker) { - case targ_land: - fp->x = fsect->sct_x; - fp->y = fsect->sct_y; - fp->type = targ_land; - break ; - default: - fp->type = targ_ship; - fp->uid = fship->shp_uid; - break ; - } - emp_insque(&fp->queue,al); + vict = vship->shp_own; + + if (0 != + (dam = quiet_bigdef(attacker, dl, vict, aown, fx, fy, &nfiring))) { + if (nfiring > *nd) + *nd = nfiring; + fp = (struct flist *)malloc(sizeof(struct flist)); + bzero((s_char *)fp, sizeof(struct flist)); + fp->defdam = dam; + fp->victim = vict; + switch (attacker) { + case targ_land: + fp->x = fsect->sct_x; + fp->y = fsect->sct_y; + fp->type = targ_land; + break; + default: + fp->type = targ_ship; + fp->uid = fship->shp_uid; + break; + } + emp_insque(&fp->queue, al); } - - return(dam); + + return (dam); } void do_defdam(struct emp_qelem *list, double odds) { - - int dam, vict,first=1; - struct flist *fp; - struct shpstr ship; - struct sctstr sect; - struct emp_qelem *qp, *next; - - for (qp = list->q_forw; qp != list; qp = next){ - next = qp->q_forw; - fp = (struct flist *)qp; - if (fp->type == targ_ship) { - if (!getship(fp->uid, &ship) || - !ship.shp_own) - continue; - } - if (first){ - pr_beep(); - pr("\nDefenders fire back!\n"); - first=0; - } - dam = (odds * (double)fp->defdam); - - if (fp->type == targ_ship){ - vict = fp->victim; - pr( - "Return fire hit %s in %s for %d damage.\n", - prship(&ship), - xyas(ship.shp_x, ship.shp_y, player->cnum), - dam); - if (vict) - wu(0, vict, - "Return fire hit %s in %s for %d damage.\n", - prsub(&ship), - xyas(ship.shp_x, ship.shp_y, vict), - dam); - shipdamage(&ship, dam); - putship(ship.shp_uid,&ship); - }else{ - getsect(fp->x, fp->y, §); - vict = fp->victim; - pr("Return fire hit sector %s for %d damage.\n", - xyas(fp->x, fp->y, player->cnum), dam); - sectdamage(§, dam, 0); - putsect(§); - if (vict) - wu(0, vict, "Return fire hit sector %s for %d damage.\n", - xyas(fp->x, fp->y, vict), dam); - } - emp_remque(&fp->queue); - free((s_char *)fp); + + int dam, vict, first = 1; + struct flist *fp; + struct shpstr ship; + struct sctstr sect; + struct emp_qelem *qp, *next; + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + fp = (struct flist *)qp; + if (fp->type == targ_ship) { + if (!getship(fp->uid, &ship) || !ship.shp_own) + continue; + } + if (first) { + pr_beep(); + pr("\nDefenders fire back!\n"); + first = 0; + } + dam = (odds * (double)fp->defdam); + + if (fp->type == targ_ship) { + vict = fp->victim; + pr("Return fire hit %s in %s for %d damage.\n", + prship(&ship), + xyas(ship.shp_x, ship.shp_y, player->cnum), dam); + if (vict) + wu(0, vict, + "Return fire hit %s in %s for %d damage.\n", + prsub(&ship), xyas(ship.shp_x, ship.shp_y, vict), dam); + shipdamage(&ship, dam); + putship(ship.shp_uid, &ship); + } else { + getsect(fp->x, fp->y, §); + vict = fp->victim; + pr("Return fire hit sector %s for %d damage.\n", + xyas(fp->x, fp->y, player->cnum), dam); + sectdamage(§, dam, 0); + putsect(§); + if (vict) + wu(0, vict, "Return fire hit sector %s for %d damage.\n", + xyas(fp->x, fp->y, vict), dam); + } + emp_remque(&fp->queue); + free((s_char *)fp); } } int -quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown, coord ax, coord ay, int *nfiring) +quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown, + coord ax, coord ay, int *nfiring) { - int nshot; - double range, erange, hitchance; - struct shpstr ship; - struct lndstr land; - struct nstr_item ni; - int vec[I_MAX+1]; - int dam, dam2, rel, rel2; - double tech; - struct sctstr firing; - struct nstr_sect ns; - struct flist *fp; - double techfact(int, double); - extern int torpedo_damage; - int gun; - + int nshot; + double range, erange, hitchance; + struct shpstr ship; + struct lndstr land; + struct nstr_item ni; + int vec[I_MAX + 1]; + int dam, dam2, rel, rel2; + double tech; + struct sctstr firing; + struct nstr_sect ns; + struct flist *fp; + double techfact(int, double); + extern int torpedo_damage; + int gun; + if (own == 0) - return 0; + return 0; dam = 0; snxtitem_dist(&ni, EF_SHIP, ax, ay, 8); - while (nxtitem(&ni, (caddr_t)&ship)){ - if (ship.shp_own == 0) - continue; - - if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && - (attacker == targ_land)) - continue; - - rel = getrel(getnatp(ship.shp_own),own); - rel2 = getrel(getnatp(ship.shp_own),aown); - if ((ship.shp_own != own) && - ((rel != ALLIED) || (rel2 != AT_WAR))) - continue; - /* Don't shoot yourself */ - if (ship.shp_own == aown) - continue; - if (ship.shp_effic < 60) - continue; - if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 0) - continue; - - if (vec[I_MILIT] < 1) - continue; - - if (mchr[(int)ship.shp_type].m_flags & M_SUB){ - if (vec[I_SHELL] < 3) - vec[I_SHELL] += supply_commod(ship.shp_own, - ship.shp_x,ship.shp_y,I_SHELL, - 3-vec[I_SHELL]); - if (vec[I_SHELL] < 3) - continue; - if (vec[I_GUN] < 1) - continue; + while (nxtitem(&ni, (caddr_t)&ship)) { + if (ship.shp_own == 0) + continue; + + if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && + (attacker == targ_land)) + continue; + + rel = getrel(getnatp(ship.shp_own), own); + rel2 = getrel(getnatp(ship.shp_own), aown); + if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR))) + continue; + /* Don't shoot yourself */ + if (ship.shp_own == aown) + continue; + if (ship.shp_effic < 60) + continue; + if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 0) + continue; + + if (vec[I_MILIT] < 1) + continue; + + if (mchr[(int)ship.shp_type].m_flags & M_SUB) { + if (vec[I_SHELL] < 3) + vec[I_SHELL] += supply_commod(ship.shp_own, + ship.shp_x, ship.shp_y, + I_SHELL, 3 - vec[I_SHELL]); + if (vec[I_SHELL] < 3) + continue; + if (vec[I_GUN] < 1) + continue; /* if (ship.shp_mobil <= 0) continue; */ - erange = ship.shp_effic* - techfact(ship.shp_tech, - ((double)ship.shp_frnge)) - / 100.0; - erange = (double)roundrange(erange); - range = mapdist(ship.shp_x, ship.shp_y, ax, ay); - if (range > erange) - continue; - if (!line_of_sight((s_char **)0, ship.shp_x, ship.shp_y, ax, ay)) - continue; - - (*nfiring)++; - fp = (struct flist *)malloc(sizeof(struct flist)); - bzero((s_char *)fp,sizeof(struct flist)); - fp->type = targ_ship; - fp->uid = ship.shp_uid; - add_to_fired_queue(&fp->queue, list); + erange = ship.shp_effic * + techfact(ship.shp_tech, ((double)ship.shp_frnge)) + / 100.0; + erange = (double)roundrange(erange); + range = mapdist(ship.shp_x, ship.shp_y, ax, ay); + if (range > erange) + continue; + if (!line_of_sight + ((s_char **)0, ship.shp_x, ship.shp_y, ax, ay)) + continue; + + (*nfiring)++; + fp = (struct flist *)malloc(sizeof(struct flist)); + bzero((s_char *)fp, sizeof(struct flist)); + fp->type = targ_ship; + fp->uid = ship.shp_uid; + add_to_fired_queue(&fp->queue, list); /* nreport(ship.shp_own, N_FIRE_BACK, player->cnum, 1); */ - hitchance = DTORP_HITCHANCE(range, ship.shp_visib); - if (!chance(hitchance)) - continue; - - dam += TORP_DAMAGE(); - }else{ - range = techfact(ship.shp_tech, - ship.shp_frnge * ship.shp_effic / 200.0); - range = (double)roundrange(range); - if (range < ni.curdist) - continue; - /* must have gun, shell, and milit to fire */ - if (vec[I_SHELL] < 1) - vec[I_SHELL] += supply_commod(ship.shp_own, - ship.shp_x,ship.shp_y,I_SHELL,1); - /* only need 1 shell, so don't check that */ - if (vec[I_SHELL] < 1) - continue; - nshot = min(vec[I_GUN],vec[I_MILIT]); - nshot = min(nshot, ship.shp_glim); - if (nshot == 0) - continue; - (*nfiring)++; - fp = (struct flist *)malloc(sizeof(struct flist)); - bzero((s_char *)fp,sizeof(struct flist)); - fp->type = targ_ship; - fp->uid = ship.shp_uid; - add_to_fired_queue(&fp->queue, list); - nreport(ship.shp_own, N_FIRE_BACK, player->cnum, 1); - dam += seagun(ship.shp_effic,nshot); - } + hitchance = DTORP_HITCHANCE(range, ship.shp_visib); + if (!chance(hitchance)) + continue; + + dam += TORP_DAMAGE(); + } else { + range = techfact(ship.shp_tech, + ship.shp_frnge * ship.shp_effic / 200.0); + range = (double)roundrange(range); + if (range < ni.curdist) + continue; + /* must have gun, shell, and milit to fire */ + if (vec[I_SHELL] < 1) + vec[I_SHELL] += supply_commod(ship.shp_own, + ship.shp_x, ship.shp_y, + I_SHELL, 1); + /* only need 1 shell, so don't check that */ + if (vec[I_SHELL] < 1) + continue; + nshot = min(vec[I_GUN], vec[I_MILIT]); + nshot = min(nshot, ship.shp_glim); + if (nshot == 0) + continue; + (*nfiring)++; + fp = (struct flist *)malloc(sizeof(struct flist)); + bzero((s_char *)fp, sizeof(struct flist)); + fp->type = targ_ship; + fp->uid = ship.shp_uid; + add_to_fired_queue(&fp->queue, list); + nreport(ship.shp_own, N_FIRE_BACK, player->cnum, 1); + dam += seagun(ship.shp_effic, nshot); + } } snxtitem_dist(&ni, EF_LAND, ax, ay, 8); - while (nxtitem(&ni, (caddr_t)&land)){ - if (land.lnd_own == 0) - continue; - if (land.lnd_effic < LAND_MINFIREEFF) - continue; - /* Can't fire if on a ship */ - if (land.lnd_ship >= 0) - continue; - if (land.lnd_land >= 0) - continue; - /* Gotta have military */ - if (lnd_getmil(&land) < 1) - continue; - /* Don't shoot yourself */ - if (land.lnd_own == aown) - continue; - - rel = getrel(getnatp(land.lnd_own),own); - rel2 = getrel(getnatp(land.lnd_own),aown); - - if ((land.lnd_own != own) && - ((rel != ALLIED) || (rel2 != AT_WAR))) - continue; - - - range = techfact((int)land.lnd_tech, - (double)land.lnd_frg / 2.0); - range = (double)roundrange(range); - if (range < ni.curdist) - continue; - - resupply_all(&land); - if (!has_supply(&land)) - continue; - - if (getvec(VT_ITEM, vec, (caddr_t)&land, EF_LAND) < 0) - continue; - - if (vec[I_MILIT] == 0 || vec[I_SHELL] == 0 || vec[I_GUN] == 0) - continue; + while (nxtitem(&ni, (caddr_t)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_effic < LAND_MINFIREEFF) + continue; + /* Can't fire if on a ship */ + if (land.lnd_ship >= 0) + continue; + if (land.lnd_land >= 0) + continue; + /* Gotta have military */ + if (lnd_getmil(&land) < 1) + continue; + /* Don't shoot yourself */ + if (land.lnd_own == aown) + continue; + + rel = getrel(getnatp(land.lnd_own), own); + rel2 = getrel(getnatp(land.lnd_own), aown); + + if ((land.lnd_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR))) + continue; + + + range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0); + range = (double)roundrange(range); + if (range < ni.curdist) + continue; + + resupply_all(&land); + if (!has_supply(&land)) + continue; + + if (getvec(VT_ITEM, vec, (caddr_t)&land, EF_LAND) < 0) + continue; + + if (vec[I_MILIT] == 0 || vec[I_SHELL] == 0 || vec[I_GUN] == 0) + continue; - dam2 = (int)landunitgun(land.lnd_effic, land.lnd_dam, vec[I_GUN], - land.lnd_ammo, vec[I_SHELL]); + dam2 = (int)landunitgun(land.lnd_effic, land.lnd_dam, vec[I_GUN], + land.lnd_ammo, vec[I_SHELL]); - (*nfiring)++; - fp = (struct flist *)malloc(sizeof(struct flist)); - bzero((s_char *)fp,sizeof(struct flist)); - fp->type = targ_unit; - fp->uid = land.lnd_uid; - add_to_fired_queue(&fp->queue, list); - use_supply(&land); - putland(land.lnd_uid, &land); - nreport(land.lnd_own, N_FIRE_BACK, player->cnum, 1); - dam += dam2; + (*nfiring)++; + fp = (struct flist *)malloc(sizeof(struct flist)); + bzero((s_char *)fp, sizeof(struct flist)); + fp->type = targ_unit; + fp->uid = land.lnd_uid; + add_to_fired_queue(&fp->queue, list); + use_supply(&land); + putland(land.lnd_uid, &land); + nreport(land.lnd_own, N_FIRE_BACK, player->cnum, 1); + dam += dam2; } - + /* * Determine if any nearby gun-equipped sectors are within * range and able to fire at an attacker. Firing sectors * need to have guns, shells, and military. Sector being * attacked is x,y -- attacker is at ax,ay. */ - - if (!opt_NO_FORT_FIRE) { - snxtsct_dist(&ns, ax, ay, 8); - while (nxtsct(&ns, &firing)){ - - if (firing.sct_type != SCT_FORTR) - continue; - if (firing.sct_own == 0) - continue; - rel = getrel(getnatp(firing.sct_own),own); - rel2 = getrel(getnatp(firing.sct_own),aown); - - if ((firing.sct_own != own) && - ((rel != ALLIED) || (rel2 != AT_WAR))) - continue; - /* Don't shoot yourself */ - if (firing.sct_own == aown) - continue; - tech = tfactfire(firing.sct_own, 1.0); - range = tech * 7.0; - if (firing.sct_effic > 59) /* fort bonus */ - range++; - range = (double)roundrange(range); - if (range < ns.curdist) - continue; - if (getvec(VT_ITEM, vec, (caddr_t)&firing, EF_SECTOR) < 0) - continue; - if (vec[I_SHELL] < 1) - vec[I_SHELL] += supply_commod(firing.sct_own, - firing.sct_x,firing.sct_y,I_SHELL,1); - if (vec[I_GUN] == 0 || vec[I_MILIT] < 5 || vec[I_SHELL] == 0) - continue; - (*nfiring)++; - fp = (struct flist *)malloc(sizeof(struct flist)); - bzero((s_char *)fp,sizeof(struct flist)); - fp->x = firing.sct_x; - fp->y = firing.sct_y; - fp->type = targ_land; - add_to_fired_queue(&fp->queue, list); - nreport(firing.sct_own, N_FIRE_BACK, player->cnum, 1); - gun = vec[I_GUN]; - if (gun > 7) - gun = 7; - dam += landgun((int)firing.sct_effic,gun); - } + + if (!opt_NO_FORT_FIRE) { + snxtsct_dist(&ns, ax, ay, 8); + while (nxtsct(&ns, &firing)) { + + if (firing.sct_type != SCT_FORTR) + continue; + if (firing.sct_own == 0) + continue; + rel = getrel(getnatp(firing.sct_own), own); + rel2 = getrel(getnatp(firing.sct_own), aown); + + if ((firing.sct_own != own) && + ((rel != ALLIED) || (rel2 != AT_WAR))) + continue; + /* Don't shoot yourself */ + if (firing.sct_own == aown) + continue; + tech = tfactfire(firing.sct_own, 1.0); + range = tech * 7.0; + if (firing.sct_effic > 59) /* fort bonus */ + range++; + range = (double)roundrange(range); + if (range < ns.curdist) + continue; + if (getvec(VT_ITEM, vec, (caddr_t)&firing, EF_SECTOR) < 0) + continue; + if (vec[I_SHELL] < 1) + vec[I_SHELL] += supply_commod(firing.sct_own, + firing.sct_x, firing.sct_y, + I_SHELL, 1); + if (vec[I_GUN] == 0 || vec[I_MILIT] < 5 || vec[I_SHELL] == 0) + continue; + (*nfiring)++; + fp = (struct flist *)malloc(sizeof(struct flist)); + bzero((s_char *)fp, sizeof(struct flist)); + fp->x = firing.sct_x; + fp->y = firing.sct_y; + fp->type = targ_land; + add_to_fired_queue(&fp->queue, list); + nreport(firing.sct_own, N_FIRE_BACK, player->cnum, 1); + gun = vec[I_GUN]; + if (gun > 7) + gun = 7; + dam += landgun((int)firing.sct_effic, gun); } + } - return ((*nfiring) == 0 ? 0 : (dam/(*nfiring))); + return ((*nfiring) == 0 ? 0 : (dam / (*nfiring))); } void use_ammo(struct emp_qelem *list) { - struct emp_qelem *qp, *next; - struct flist *fp; - struct shpstr ship; - struct lndstr land; - struct sctstr sect; - int shell, type; - s_char *ptr; - double mobcost; - struct mchrstr *mcp; - + struct emp_qelem *qp, *next; + struct flist *fp; + struct shpstr ship; + struct lndstr land; + struct sctstr sect; + int shell, type; + s_char *ptr; + double mobcost; + struct mchrstr *mcp; + /* use 1 shell from everyone */ - for (qp = list->q_forw; qp != list; qp = next){ - next = qp->q_forw; - fp = (struct flist *)qp; - if (fp->type == targ_ship){ - getship(fp->uid,&ship); - ptr = (s_char *)&ship; - type = EF_SHIP; - if (mchr[(int)ship.shp_type].m_flags & M_SUB){ - shell = getvar(V_SHELL, ptr, type); - shell--; - if (shell<0) - shell=0; - putvar(V_SHELL, shell, ptr, type); - putship(ship.shp_uid, &ship); - mcp = &mchr[(int)ship.shp_type]; - mobcost = ship.shp_effic * 0.01 * ship.shp_speed; - mobcost = (480.0 / (mobcost + - techfact(ship.shp_tech, mobcost))); - /* mob cost = 1/2 a sect's mob */ - mobcost /= 2.0; - ship.shp_mobil -= mobcost; - } - }else if (fp->type == targ_land){ - getsect(fp->x,fp->y,§); - ptr = (s_char *)§ - type = EF_SECTOR; - }else{ - getland(fp->uid,&land); - ptr = (s_char *)&land; - type = EF_LAND; - } + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + fp = (struct flist *)qp; + if (fp->type == targ_ship) { + getship(fp->uid, &ship); + ptr = (s_char *)&ship; + type = EF_SHIP; + if (mchr[(int)ship.shp_type].m_flags & M_SUB) { shell = getvar(V_SHELL, ptr, type); shell--; - if (shell<0) - shell=0; + if (shell < 0) + shell = 0; putvar(V_SHELL, shell, ptr, type); - if (fp->type == targ_ship) - putship(ship.shp_uid,&ship); - else if (fp->type == targ_land) - putsect(§); - else - putland(land.lnd_uid,&land); - - emp_remque(&fp->queue); - free((s_char *)fp); + putship(ship.shp_uid, &ship); + mcp = &mchr[(int)ship.shp_type]; + mobcost = ship.shp_effic * 0.01 * ship.shp_speed; + mobcost = (480.0 / (mobcost + + techfact(ship.shp_tech, mobcost))); + /* mob cost = 1/2 a sect's mob */ + mobcost /= 2.0; + ship.shp_mobil -= mobcost; + } + } else if (fp->type == targ_land) { + getsect(fp->x, fp->y, §); + ptr = (s_char *)§ + type = EF_SECTOR; + } else { + getland(fp->uid, &land); + ptr = (s_char *)&land; + type = EF_LAND; + } + shell = getvar(V_SHELL, ptr, type); + shell--; + if (shell < 0) + shell = 0; + putvar(V_SHELL, shell, ptr, type); + if (fp->type == targ_ship) + putship(ship.shp_uid, &ship); + else if (fp->type == targ_land) + putsect(§); + else + putland(land.lnd_uid, &land); + + emp_remque(&fp->queue); + free((s_char *)fp); } - + } void add_to_fired_queue(struct emp_qelem *elem, struct emp_qelem *list) { - struct emp_qelem *qp; - struct flist *fp, *ep; - int bad=0; - + struct emp_qelem *qp; + struct flist *fp, *ep; + int bad = 0; + ep = (struct flist *)elem; - + /* Don't put them on the list if they're already there */ - for (qp = list->q_forw; qp != list; qp = qp->q_forw){ - fp = (struct flist *)qp; - if ((fp->type == targ_ship) && (fp->uid == ep->uid)) - bad=1; - if ((fp->type != targ_ship) && (fp->x == ep->x) && - (fp->y == ep->y)) - bad=1; + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + fp = (struct flist *)qp; + if ((fp->type == targ_ship) && (fp->uid == ep->uid)) + bad = 1; + if ((fp->type != targ_ship) && (fp->x == ep->x) && + (fp->y == ep->y)) + bad = 1; } - + if (!bad) - emp_insque(elem, list); + emp_insque(elem, list); } diff --git a/src/lib/commands/mine.c b/src/lib/commands/mine.c index 8aae81cea..156206aca 100644 --- a/src/lib/commands/mine.c +++ b/src/lib/commands/mine.c @@ -49,48 +49,48 @@ int mine(void) { - struct shpstr ship; - struct sctstr sect; - struct mchrstr *mp; - struct nstr_item ni; - int mines; - int shells; - int mines_avail; - int mines_there; + struct shpstr ship; + struct sctstr sect; + struct mchrstr *mp; + struct nstr_item ni; + int mines; + int shells; + int mines_avail; + int mines_there; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; - mines = onearg(player->argp[2], "Drop how many mines from each ship? "); - if (mines <= 0) - return RET_SYN; - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner) - continue; - mp = &mchr[(int)ship.shp_type]; - if ((mp->m_flags & M_MINE) == 0) - continue; - if ((shells = getvar(V_SHELL, (s_char *)&ship, EF_SHIP)) == 0) - continue; - mines_avail = min(shells, mines); - if (getsect(ship.shp_x, ship.shp_y, §) == 0 || - (sect.sct_type != SCT_WATER && - sect.sct_type != SCT_BSPAN)) { - pr("You can't lay mines there!!\n"); - continue; - } - mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR); - putvar(V_SHELL, shells - mines_avail, (s_char *)&ship, EF_SHIP); - putvar(V_MINE, mines_avail + mines_there, (s_char *)§, - EF_SECTOR); - putsect(§); - ship.shp_mission = 0; - putship(ship.shp_uid, &ship); - pr("Laying %d mines from %s\n", mines_avail, prship(&ship)); - if (mines_avail && - map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0)) - writemap(player->cnum); + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; + mines = + onearg(player->argp[2], "Drop how many mines from each ship? "); + if (mines <= 0) + return RET_SYN; + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner) + continue; + mp = &mchr[(int)ship.shp_type]; + if ((mp->m_flags & M_MINE) == 0) + continue; + if ((shells = getvar(V_SHELL, (s_char *)&ship, EF_SHIP)) == 0) + continue; + mines_avail = min(shells, mines); + if (getsect(ship.shp_x, ship.shp_y, §) == 0 || + (sect.sct_type != SCT_WATER && sect.sct_type != SCT_BSPAN)) { + pr("You can't lay mines there!!\n"); + continue; } - return RET_OK; + mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR); + putvar(V_SHELL, shells - mines_avail, (s_char *)&ship, EF_SHIP); + putvar(V_MINE, mines_avail + mines_there, (s_char *)§, + EF_SECTOR); + putsect(§); + ship.shp_mission = 0; + putship(ship.shp_uid, &ship); + pr("Laying %d mines from %s\n", mines_avail, prship(&ship)); + if (mines_avail && + map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0)) + writemap(player->cnum); + } + return RET_OK; } /* @@ -99,77 +99,71 @@ mine(void) int landmine(void) { - struct lndstr land; - struct sctstr sect; - struct lchrstr *lp; - struct nstr_item ni; - int shells; - int mines_there; - int mines_wanted; - int mines_laid; - int total_mines_laid; - s_char prompt[128]; + struct lndstr land; + struct sctstr sect; + struct lchrstr *lp; + struct nstr_item ni; + int shells; + int mines_there; + int mines_wanted; + int mines_laid; + int total_mines_laid; + s_char prompt[128]; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner) - continue; - lp = &lchr[(int)land.lnd_type]; - if (!(lp->l_flags & L_ENGINEER)) - continue; - if (land.lnd_mobil < 1) { - pr("Unit %d is out of mobility\n", land.lnd_uid); - continue; - } - resupply_commod(&land,I_SHELL); - if (!(shells = getvar(V_SHELL, (s_char *)&land, EF_LAND))) - continue; - shells = min(shells, land.lnd_mobil); - if (!getsect(land.lnd_x, land.lnd_y, §) || - sect.sct_type == SCT_WATER || - sect.sct_type == SCT_BSPAN) { - pr("You can't lay mines there!!\n"); - continue; - } - mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR); - if (sect.sct_own == sect.sct_oldown) - pr("There are currently %d mines in %s\n", - mines_there,xyas(sect.sct_x,sect.sct_y,player->cnum)); - sprintf(prompt, "Drop how many mines from %s? ", - prland(&land)); - mines_wanted = onearg(player->argp[2], prompt); - if (!check_land_ok(&land)) - continue; - if (mines_wanted <= 0) - continue; - land.lnd_mission = 0; - total_mines_laid = 0; - while (shells > 0 && total_mines_laid < mines_wanted) { - mines_laid = min(shells, mines_wanted - total_mines_laid); - putvar(V_SHELL, shells - mines_laid, (s_char *)&land, EF_LAND); - land.lnd_mobil -= mines_laid; - putland(land.lnd_uid, &land); - resupply_commod(&land, I_SHELL); - putland(land.lnd_uid, &land); - total_mines_laid += mines_laid; - shells = getvar(V_SHELL, (s_char *)&land, EF_LAND); - shells = min(shells, land.lnd_mobil); - } - getsect(sect.sct_x, sect.sct_y, §); - putvar(V_MINE, total_mines_laid + mines_there, (s_char *)§, - EF_SECTOR); - putsect(§); - if (shells) - pr("%s laid a total of %d mines in %s\n", - prland(&land), total_mines_laid, - xyas(sect.sct_x,sect.sct_y,land.lnd_own)); - else - pr("%s ran out of %s before it could finish the job\nOnly %d mines were laid in %s\n", - prland(&land), - land.lnd_mobil > 0 ? "supply" : "mobility", - total_mines_laid, - xyas(sect.sct_x,sect.sct_y,land.lnd_own)); + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner) + continue; + lp = &lchr[(int)land.lnd_type]; + if (!(lp->l_flags & L_ENGINEER)) + continue; + if (land.lnd_mobil < 1) { + pr("Unit %d is out of mobility\n", land.lnd_uid); + continue; } - return RET_OK; + resupply_commod(&land, I_SHELL); + if (!(shells = getvar(V_SHELL, (s_char *)&land, EF_LAND))) + continue; + shells = min(shells, land.lnd_mobil); + if (!getsect(land.lnd_x, land.lnd_y, §) || + sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) { + pr("You can't lay mines there!!\n"); + continue; + } + mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR); + if (sect.sct_own == sect.sct_oldown) + pr("There are currently %d mines in %s\n", + mines_there, xyas(sect.sct_x, sect.sct_y, player->cnum)); + sprintf(prompt, "Drop how many mines from %s? ", prland(&land)); + mines_wanted = onearg(player->argp[2], prompt); + if (!check_land_ok(&land)) + continue; + if (mines_wanted <= 0) + continue; + land.lnd_mission = 0; + total_mines_laid = 0; + while (shells > 0 && total_mines_laid < mines_wanted) { + mines_laid = min(shells, mines_wanted - total_mines_laid); + putvar(V_SHELL, shells - mines_laid, (s_char *)&land, EF_LAND); + land.lnd_mobil -= mines_laid; + putland(land.lnd_uid, &land); + resupply_commod(&land, I_SHELL); + putland(land.lnd_uid, &land); + total_mines_laid += mines_laid; + shells = getvar(V_SHELL, (s_char *)&land, EF_LAND); + shells = min(shells, land.lnd_mobil); + } + getsect(sect.sct_x, sect.sct_y, §); + putvar(V_MINE, total_mines_laid + mines_there, (s_char *)§, + EF_SECTOR); + putsect(§); + if (shells) + pr("%s laid a total of %d mines in %s\n", + prland(&land), total_mines_laid, + xyas(sect.sct_x, sect.sct_y, land.lnd_own)); + else + pr("%s ran out of %s before it could finish the job\nOnly %d mines were laid in %s\n", prland(&land), land.lnd_mobil > 0 ? "supply" : "mobility", total_mines_laid, xyas(sect.sct_x, sect.sct_y, land.lnd_own)); + } + return RET_OK; } diff --git a/src/lib/commands/miss.c b/src/lib/commands/miss.c index 98c42a4ae..bbcc7ac40 100644 --- a/src/lib/commands/miss.c +++ b/src/lib/commands/miss.c @@ -57,40 +57,45 @@ int mission(void) { - s_char *p; - int type; - int mission; - coord x, y; - int size, desired_radius, radius; - struct sctstr opsect; - s_char *block; - struct genitem *gp; - int num=0, mobmax, mobused, dist; - struct nstr_item ni; - extern int ship_mob_max; - extern int land_mob_max; - extern int plane_mob_max; - extern double mission_mob_cost; - s_char *nameofitem(); - s_char prompt[128]; - s_char buf[1024]; - - if ((p = getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ", buf)) == 0) - return RET_SYN; - type = ef_byname(p); - if (type == EF_SECTOR) - type = EF_SHIP; - if (type != EF_SHIP && type != EF_LAND && type != EF_PLANE){ - pr("Ships, land units or planes only! (s, l, p)\n"); - return RET_SYN; - } - sprintf(prompt, "%s(s)? ", ef_nameof(type)); - p = getstarg(player->argp[2], prompt, buf); - if (!snxtitem(&ni, type, p)) - return RET_SYN; - - if ((p = getstarg(player->argp[3], "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ", buf)) == 0) - return RET_SYN; + s_char *p; + int type; + int mission; + coord x, y; + int size, desired_radius, radius; + struct sctstr opsect; + s_char *block; + struct genitem *gp; + int num = 0, mobmax, mobused, dist; + struct nstr_item ni; + extern int ship_mob_max; + extern int land_mob_max; + extern int plane_mob_max; + extern double mission_mob_cost; + s_char *nameofitem(); + s_char prompt[128]; + s_char buf[1024]; + + if ((p = + getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ", + buf)) == 0) + return RET_SYN; + type = ef_byname(p); + if (type == EF_SECTOR) + type = EF_SHIP; + if (type != EF_SHIP && type != EF_LAND && type != EF_PLANE) { + pr("Ships, land units or planes only! (s, l, p)\n"); + return RET_SYN; + } + sprintf(prompt, "%s(s)? ", ef_nameof(type)); + p = getstarg(player->argp[2], prompt, buf); + if (!snxtitem(&ni, type, p)) + return RET_SYN; + + if ((p = + getstarg(player->argp[3], + "Mission (int, sup, osup, dsup, esc, res, air, query, clear)? ", + buf)) == 0) + return RET_SYN; /* * 'i' interdiction @@ -101,123 +106,148 @@ mission(void) * 'r' defensive reserve * 'a' air defense (intercepts) */ - switch(*p){ - case 'I': - case 'i': mission = MI_INTERDICT; break; - case 'O': - case 'o': mission = MI_OSUPPORT; break; - case 'D': - case 'd': mission = MI_DSUPPORT; break; - case 'S': - case 's': mission = MI_SUPPORT; break; - case 'C': - case 'c': mission = 0; break; - case 'E': - case 'e': mission = MI_ESCORT; break; - case 'R': - case 'r': mission = MI_RESERVE; break; - case 'A': - case 'a': mission = MI_AIR_DEFENSE; break; - case 'q': show_mission(type,&ni); - return RET_OK; - default: pr("bad condition\n"); - pr("i\tinterdiction (any)\n"); - pr("s\tsupport (tactical planes only)\n"); - pr("o\toffensive support (tactical planes only)\n"); - pr("d\tdefensive support (tactical planes only)\n"); - pr("r\treserve (land units only)\n"); - pr("e\tescort (tactical or escort planes only)\n"); - pr("a\tair defense (intercept planes only)\n"); - pr("c\tclear mission\n"); - pr("q\tquery\n"); - return RET_SYN; - } + switch (*p) { + case 'I': + case 'i': + mission = MI_INTERDICT; + break; + case 'O': + case 'o': + mission = MI_OSUPPORT; + break; + case 'D': + case 'd': + mission = MI_DSUPPORT; + break; + case 'S': + case 's': + mission = MI_SUPPORT; + break; + case 'C': + case 'c': + mission = 0; + break; + case 'E': + case 'e': + mission = MI_ESCORT; + break; + case 'R': + case 'r': + mission = MI_RESERVE; + break; + case 'A': + case 'a': + mission = MI_AIR_DEFENSE; + break; + case 'q': + show_mission(type, &ni); + return RET_OK; + default: + pr("bad condition\n"); + pr("i\tinterdiction (any)\n"); + pr("s\tsupport (tactical planes only)\n"); + pr("o\toffensive support (tactical planes only)\n"); + pr("d\tdefensive support (tactical planes only)\n"); + pr("r\treserve (land units only)\n"); + pr("e\tescort (tactical or escort planes only)\n"); + pr("a\tair defense (intercept planes only)\n"); + pr("c\tclear mission\n"); + pr("q\tquery\n"); + return RET_SYN; + } + + if (mission && !cando(mission, type)) { + pr("A %s cannot do that mission!\n", ef_nameof(type)); + pr("i\tinterdiction (any)\n"); + pr("s\tsupport (planes only)\n"); + pr("o\toffensive support (planes only)\n"); + pr("d\tdefensive support (planes only)\n"); + pr("r\treserve (land units only)\n"); + pr("e\tescort (planes only)\n"); + pr("a\tair defense (planes only)\n"); + return RET_FAIL; + } + + if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))) { + if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0 + || *p == 0) + return RET_SYN; + + if (*p != '.') { + if (!sarg_xy(p, &x, &y)) + return RET_SYN; - if (mission && !cando(mission,type)){ - pr("A %s cannot do that mission!\n",ef_nameof(type)); - pr("i\tinterdiction (any)\n"); - pr("s\tsupport (planes only)\n"); - pr("o\toffensive support (planes only)\n"); - pr("d\tdefensive support (planes only)\n"); - pr("r\treserve (land units only)\n"); - pr("e\tescort (planes only)\n"); - pr("a\tair defense (planes only)\n"); + if (!getsect(x, y, &opsect)) return RET_FAIL; } - - if (mission && ((mission != MI_RESERVE) && (mission != MI_ESCORT))){ - if ((p=getstarg(player->argp[4],"operations point? ", buf)) == 0 || *p == 0) - return RET_SYN; - - if (*p != '.'){ - if (!sarg_xy(p, &x, &y)) - return RET_SYN; - - if (!getsect(x, y, &opsect)) - return RET_FAIL; - } - }else{ - x=0; - y=0; + } else { + x = 0; + y = 0; + } + + if (player->argp[5] != (s_char *)0) { + desired_radius = atoi(player->argp[5]); + if (desired_radius < 0) { + pr("Radius must be greater than zero!\n"); + return RET_FAIL; } - - if (player->argp[5] != (s_char *)0){ - desired_radius = atoi(player->argp[5]); - if (desired_radius < 0){ - pr("Radius must be greater than zero!\n"); - return RET_FAIL; - } - } else { - desired_radius=9999; + } else { + desired_radius = 9999; + } + + size = max(sizeof(struct lndstr), sizeof(struct plnstr)); + size = max(size, sizeof(struct shpstr)); + block = (s_char *)malloc(size); + switch (type) { + case EF_SHIP: + mobmax = ship_mob_max; + break; + case EF_LAND: + mobmax = land_mob_max; + break; + case EF_PLANE: + mobmax = plane_mob_max; + break; + } + + mobused = ldround((mission_mob_cost * (double)mobmax), 1); + + while (nxtitem(&ni, block)) { + gp = (struct genitem *)block; + + if (!player->owner || gp->own == 0) + continue; + + if ((mission && (gp->mobil < mobused)) && mission_mob_cost) { + pr("%s #%d: not enough mobility! (needs %d)\n", + ef_nameof(type), gp->uid, mobused); + continue; } - - size = max(sizeof(struct lndstr),sizeof(struct plnstr)); - size = max(size,sizeof(struct shpstr)); - block = (s_char *)malloc(size); - switch (type){ - case EF_SHIP: mobmax = ship_mob_max; break; - case EF_LAND: mobmax = land_mob_max; break; - case EF_PLANE: mobmax = plane_mob_max; break; + if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) { + pr("%s is not designed to fight ground troops\n", + prland((struct lndstr *)gp)); + continue; + } + if (*p == '.') { + x = gp->x; + y = gp->y; + if (!getsect(x, y, &opsect)) + return RET_FAIL; } - mobused = ldround((mission_mob_cost * (double)mobmax),1); - - while (nxtitem(&ni, block)) { - gp = (struct genitem *)block; - - if (!player->owner || gp->own == 0) - continue; - - if ((mission && (gp->mobil < mobused)) && mission_mob_cost) { - pr("%s #%d: not enough mobility! (needs %d)\n", - ef_nameof(type), gp->uid, mobused); - continue; - } - if (mission == MI_RESERVE && !lnd_can_attack((struct lndstr *)gp)) { - pr("%s is not designed to fight ground troops\n", prland((struct lndstr *)gp)); - continue; - } - if (*p == '.'){ - x = gp->x; - y = gp->y; - if (!getsect(x, y, &opsect)) - return RET_FAIL; - } - - dist = mapdist(gp->x, gp->y, x, y); - radius = 999; - if ((mission == MI_INTERDICT || mission == MI_SUPPORT || - mission == MI_OSUPPORT || mission == MI_DSUPPORT || - mission == MI_AIR_DEFENSE) && - (oprange(gp,type,&radius) < dist)){ - pr("%s #%d: out of range! (range %d)\n", - ef_nameof(type), gp->uid, - oprange(gp,type,&radius)); - continue; - } + dist = mapdist(gp->x, gp->y, x, y); + radius = 999; + if ((mission == MI_INTERDICT || mission == MI_SUPPORT || + mission == MI_OSUPPORT || mission == MI_DSUPPORT || + mission == MI_AIR_DEFENSE) && + (oprange(gp, type, &radius) < dist)) { + pr("%s #%d: out of range! (range %d)\n", + ef_nameof(type), gp->uid, oprange(gp, type, &radius)); + continue; + } - if (radius > desired_radius) - radius = desired_radius; + if (radius > desired_radius) + radius = desired_radius; /* if (mission && (gp->effic < 60)){ @@ -227,116 +257,117 @@ mission(void) } */ - if ((mission == MI_INTERDICT) && (type == EF_SHIP)) - if (mchr[(int)gp->type].m_frnge < 1){ - pr("%s #%d: cannot fire at range!\n", - ef_nameof(type), gp->uid); - continue; - } - - if ((mission == MI_INTERDICT) && (type == EF_LAND)) - if (lchr[(int)gp->type].l_frg < 1){ - pr("%s #%d: cannot fire at range!\n", - ef_nameof(type), gp->uid); - continue; - } - - if ((mission == MI_INTERDICT) && (type == EF_PLANE)){ - struct plchrstr *pcp; - - pcp = &plchr[(int)gp->type]; - if (!(pcp->pl_flags & P_T)){ - pr("Only planes with the tactical ability can interdict.\n%s #%d is ineligible\n", pcp->pl_name,gp->uid); - continue; - } - } - - if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)){ - struct plchrstr *pcp; + if ((mission == MI_INTERDICT) && (type == EF_SHIP)) + if (mchr[(int)gp->type].m_frnge < 1) { + pr("%s #%d: cannot fire at range!\n", + ef_nameof(type), gp->uid); + continue; + } + + if ((mission == MI_INTERDICT) && (type == EF_LAND)) + if (lchr[(int)gp->type].l_frg < 1) { + pr("%s #%d: cannot fire at range!\n", + ef_nameof(type), gp->uid); + continue; + } + + if ((mission == MI_INTERDICT) && (type == EF_PLANE)) { + struct plchrstr *pcp; + + pcp = &plchr[(int)gp->type]; + if (!(pcp->pl_flags & P_T)) { + pr("Only planes with the tactical ability can interdict.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid); + continue; + } + } - pcp = &plchr[(int)gp->type]; - if (!(pcp->pl_flags & P_F)){ - pr("Only planes with the intercept abilities can perform air defense.\n%s #%d is ineligible\n", pcp->pl_name,gp->uid); - continue; - } - } + if ((mission == MI_AIR_DEFENSE) && (type == EF_PLANE)) { + struct plchrstr *pcp; - if ((mission == MI_ESCORT) && (type == EF_PLANE)){ - struct plchrstr *pcp; + pcp = &plchr[(int)gp->type]; + if (!(pcp->pl_flags & P_F)) { + pr("Only planes with the intercept abilities can perform air defense.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid); + continue; + } + } - pcp = &plchr[(int)gp->type]; - if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)){ - pr("Only planes with the escort or intercept abilities can escort.\n%s #%d is ineligible\n", pcp->pl_name,gp->uid); - continue; - } - } + if ((mission == MI_ESCORT) && (type == EF_PLANE)) { + struct plchrstr *pcp; - if ((mission == MI_SUPPORT || mission == MI_OSUPPORT || - mission == MI_DSUPPORT) && (type == EF_PLANE)){ - struct plchrstr *pcp; + pcp = &plchr[(int)gp->type]; + if (!(pcp->pl_flags & P_ESC) && !(pcp->pl_flags & P_F)) { + pr("Only planes with the escort or intercept abilities can escort.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid); + continue; + } + } - pcp = &plchr[(int)gp->type]; - if (!(pcp->pl_flags & P_T)){ - pr("Only planes with the tactical ability can support.\n%s #%d is ineligible\n", pcp->pl_name,gp->uid); - continue; - } - } + if ((mission == MI_SUPPORT || mission == MI_OSUPPORT || + mission == MI_DSUPPORT) && (type == EF_PLANE)) { + struct plchrstr *pcp; - num++; /* good one.. go with it */ - - if (mission == MI_INTERDICT || mission == MI_SUPPORT || - mission == MI_OSUPPORT || mission == MI_DSUPPORT || - mission == MI_AIR_DEFENSE) - gp->radius = radius; - else - gp->radius = 0; - - if (mission == MI_SUPPORT || mission == MI_OSUPPORT || - mission == MI_DSUPPORT || mission == MI_INTERDICT || - mission == MI_AIR_DEFENSE) { - pr("%s on %s mission, centered on %s, radius %d\n", - nameofitem(buf, gp,type), mission_name(mission), - xyas(x,y,player->cnum), gp->radius); - } else if (mission == MI_RESERVE) { - int plus = 2; - - if (((struct lndstr *)gp)->lnd_rad_max == 0) { - plus = 0; - } else { - getsect(gp->x, gp->y, &opsect); - if ((opsect.sct_type == SCT_HEADQ) && (opsect.sct_effic >= 60)) - plus++; - plus += ((struct lndstr *)gp)->lnd_rad_max; - } - - pr("%s on %s mission with maximum reaction radius %d\n", nameofitem(buf, gp, type), - mission_name(mission), plus); - } else if (mission) { - pr("%s on %s mission\n", nameofitem(buf, gp, type), - mission_name(mission)); - } + pcp = &plchr[(int)gp->type]; + if (!(pcp->pl_flags & P_T)) { + pr("Only planes with the tactical ability can support.\n%s #%d is ineligible\n", pcp->pl_name, gp->uid); + continue; + } + } - if (mission) - gp->mobil -= mobused; - gp->mission = mission; - gp->opx = x; - gp->opy = y; - switch (type){ - case EF_SHIP: - putship(gp->uid,block); - break; - case EF_LAND: - putland(gp->uid,block); - break; - case EF_PLANE: - putplane(gp->uid,block); - break; - } + num++; /* good one.. go with it */ + + if (mission == MI_INTERDICT || mission == MI_SUPPORT || + mission == MI_OSUPPORT || mission == MI_DSUPPORT || + mission == MI_AIR_DEFENSE) + gp->radius = radius; + else + gp->radius = 0; + + if (mission == MI_SUPPORT || mission == MI_OSUPPORT || + mission == MI_DSUPPORT || mission == MI_INTERDICT || + mission == MI_AIR_DEFENSE) { + pr("%s on %s mission, centered on %s, radius %d\n", + nameofitem(buf, gp, type), mission_name(mission), + xyas(x, y, player->cnum), gp->radius); + } else if (mission == MI_RESERVE) { + int plus = 2; + + if (((struct lndstr *)gp)->lnd_rad_max == 0) { + plus = 0; + } else { + getsect(gp->x, gp->y, &opsect); + if ((opsect.sct_type == SCT_HEADQ) + && (opsect.sct_effic >= 60)) + plus++; + plus += ((struct lndstr *)gp)->lnd_rad_max; + } + + pr("%s on %s mission with maximum reaction radius %d\n", + nameofitem(buf, gp, type), mission_name(mission), plus); + } else if (mission) { + pr("%s on %s mission\n", nameofitem(buf, gp, type), + mission_name(mission)); } - if (num == 0) { - pr("No %s%s\n", ef_nameof(type), splur(num)); - return RET_FAIL; + + if (mission) + gp->mobil -= mobused; + gp->mission = mission; + gp->opx = x; + gp->opy = y; + switch (type) { + case EF_SHIP: + putship(gp->uid, block); + break; + case EF_LAND: + putland(gp->uid, block); + break; + case EF_PLANE: + putplane(gp->uid, block); + break; } - pr("%d %s%s\n", num, ef_nameof(type), splur(num)); - return RET_OK; + } + if (num == 0) { + pr("No %s%s\n", ef_nameof(type), splur(num)); + return RET_FAIL; + } + pr("%d %s%s\n", num, ef_nameof(type), splur(num)); + return RET_OK; } diff --git a/src/lib/commands/mobq.c b/src/lib/commands/mobq.c index b33ae6bd4..08e108b03 100644 --- a/src/lib/commands/mobq.c +++ b/src/lib/commands/mobq.c @@ -47,77 +47,74 @@ int mobq(void) { - extern int ship_mob_max; - extern float ship_mob_scale; - extern int etu_per_update; - struct shpstr ship; - s_char *cp,*oldmq; - int good,mobquota,count=0; - struct nstr_item nstr; - s_char buf[1024]; + extern int ship_mob_max; + extern float ship_mob_scale; + extern int etu_per_update; + struct shpstr ship; + s_char *cp, *oldmq; + int good, mobquota, count = 0; + struct nstr_item nstr; + s_char buf[1024]; - if (!opt_SAIL) { - pr("The SAIL option is not enabled, so this command is not valid.\n"); - return RET_FAIL; - } + if (!opt_SAIL) { + pr("The SAIL option is not enabled, so this command is not valid.\n"); + return RET_FAIL; + } /* getstarg(player->argp[1], "ships? ");*/ - if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) - return RET_SYN; - oldmq = player->argp[2]; - if (oldmq) - { - good = sscanf(oldmq,"%d",&mobquota); - if (!good) - return RET_SYN; - if (mobquota<0 || mobquota>ship_mob_max) - { - pr("Bad mobility quota value %d.\n",mobquota); - return RET_SYN; - } - if (mobquota+(ship_mob_scale*(float)etu_per_update) > ship_mob_max) - { - pr("warning: %d less than optimal\n",mobquota); - } - } - while (nxtitem(&nstr, (s_char *)&ship)) { - if (!player->owner) + if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) + return RET_SYN; + oldmq = player->argp[2]; + if (oldmq) { + good = sscanf(oldmq, "%d", &mobquota); + if (!good) + return RET_SYN; + if (mobquota < 0 || mobquota > ship_mob_max) { + pr("Bad mobility quota value %d.\n", mobquota); + return RET_SYN; + } + if (mobquota + (ship_mob_scale * (float)etu_per_update) > + ship_mob_max) { + pr("warning: %d less than optimal\n", mobquota); + } + } + while (nxtitem(&nstr, (s_char *)&ship)) { + if (!player->owner) + continue; + if (!oldmq) + pr("Ship #%d at %s. Old value %d.\n", ship.shp_uid, + xyas(ship.shp_x, ship.shp_y, player->cnum), + ship.shp_mobquota); + cp = getstarg(player->argp[2], "mobility quota?", buf); + if (!cp) + return RET_SYN; + if (!check_ship_ok(&ship)) continue; - if (!oldmq) - pr("Ship #%d at %s. Old value %d.\n",ship.shp_uid,xyas(ship.shp_x,ship.shp_y,player->cnum),ship.shp_mobquota); - cp = getstarg(player->argp[2],"mobility quota?", buf); - if (!cp) - return RET_SYN; - if (!check_ship_ok(&ship)) - continue; - good = sscanf(cp,"%d",&mobquota); - if (!good) - { - pr("Huh?\n"); + good = sscanf(cp, "%d", &mobquota); + if (!good) { + pr("Huh?\n"); + continue; + } + if (!oldmq) { + if (mobquota < 0 || mobquota > ship_mob_max) { + pr("Bad mobility quota value %d.\n", mobquota); continue; - } - if (!oldmq) - { - if (mobquota<0 || mobquota>ship_mob_max) - { - pr("Bad mobility quota value %d.\n",mobquota); - continue; - } - if (mobquota+(ship_mob_scale*(float)etu_per_update)> ship_mob_max) - { - pr("warning: %d less than optimal\n",mobquota); - } } - ship.shp_mobquota = mobquota; - count ++; - putship(ship.shp_uid, &ship); + if (mobquota + (ship_mob_scale * (float)etu_per_update) > + ship_mob_max) { + pr("warning: %d less than optimal\n", mobquota); + } } - if (count == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", count, splur(count)); - return RET_OK; + ship.shp_mobquota = mobquota; + count++; + putship(ship.shp_uid, &ship); + } + if (count == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", count, splur(count)); + return RET_OK; } diff --git a/src/lib/commands/mobu.c b/src/lib/commands/mobu.c index ad51e1189..3ba3df28d 100644 --- a/src/lib/commands/mobu.c +++ b/src/lib/commands/mobu.c @@ -50,67 +50,67 @@ int mobupdate(void) { - FILE *fp; - long minites; - extern int updating_mob; - struct mob_acc_globals timestamps; - long now; - extern s_char *timestampfil; - - if (!opt_MOB_ACCESS) { - pr("Command invalid - MOB_ACCESS is not enabled.\n"); - return RET_FAIL; - } - if (!player->argp[1]) - return RET_SYN; - if (*player->argp[1] == 'c') - minites = -1; - else - minites = atol(player->argp[1]) * 60; - time(&now); + FILE *fp; + long minites; + extern int updating_mob; + struct mob_acc_globals timestamps; + long now; + extern s_char *timestampfil; + + if (!opt_MOB_ACCESS) { + pr("Command invalid - MOB_ACCESS is not enabled.\n"); + return RET_FAIL; + } + if (!player->argp[1]) + return RET_SYN; + if (*player->argp[1] == 'c') + minites = -1; + else + minites = atol(player->argp[1]) * 60; + time(&now); #if !defined(_WIN32) - if ((fp = fopen(timestampfil, "r+")) == NULL) { + if ((fp = fopen(timestampfil, "r+")) == NULL) { #else - if ((fp = fopen(timestampfil, "r+b")) == NULL) { + if ((fp = fopen(timestampfil, "r+b")) == NULL) { #endif - logerror("Unable to edit timestamp file."); - } else { - rewind(fp); - fread(×tamps, sizeof(timestamps), 1, fp); - if (minites < 0) { - fclose(fp); - if (updating_mob) - pr("Mobility updating is enabled."); - else { - pr("Mobility updating will come back on around %s", - ctime(×tamps.starttime)); - pr("within 3 minutes, depending on when the server checks."); - } - return 0; - } - timestamps.timestamp = now; - timestamps.starttime = now + minites; - rewind(fp); - fwrite(×tamps, sizeof(timestamps), 1, fp); - fclose(fp); - if (now >= timestamps.starttime) { - pr("Turning on mobility updating."); - update_all_mob(); - updating_mob = 1; - } else if (updating_mob == 1) { - pr("Turning off mobility updating.\n\r"); - pr("Mobility updating will come back on around %s", - ctime(×tamps.starttime)); - pr("within 3 minutes, depending on when the server checks."); - update_all_mob(); - updating_mob = 0; - } else if (updating_mob == 0) { - pr("Mobility updating is already off.\n\r"); - pr("Mobility updating will come back on around %s", - ctime(×tamps.starttime)); - pr("within 3 minutes, depending on when the server checks."); - } + logerror("Unable to edit timestamp file."); + } else { + rewind(fp); + fread(×tamps, sizeof(timestamps), 1, fp); + if (minites < 0) { + fclose(fp); + if (updating_mob) + pr("Mobility updating is enabled."); + else { + pr("Mobility updating will come back on around %s", + ctime(×tamps.starttime)); + pr("within 3 minutes, depending on when the server checks."); + } + return 0; } - - return 0; + timestamps.timestamp = now; + timestamps.starttime = now + minites; + rewind(fp); + fwrite(×tamps, sizeof(timestamps), 1, fp); + fclose(fp); + if (now >= timestamps.starttime) { + pr("Turning on mobility updating."); + update_all_mob(); + updating_mob = 1; + } else if (updating_mob == 1) { + pr("Turning off mobility updating.\n\r"); + pr("Mobility updating will come back on around %s", + ctime(×tamps.starttime)); + pr("within 3 minutes, depending on when the server checks."); + update_all_mob(); + updating_mob = 0; + } else if (updating_mob == 0) { + pr("Mobility updating is already off.\n\r"); + pr("Mobility updating will come back on around %s", + ctime(×tamps.starttime)); + pr("within 3 minutes, depending on when the server checks."); + } + } + + return 0; } diff --git a/src/lib/commands/mora.c b/src/lib/commands/mora.c index 055ec1425..0c1f0eccc 100644 --- a/src/lib/commands/mora.c +++ b/src/lib/commands/mora.c @@ -47,38 +47,38 @@ extern int morale_base; int morale(void) { - struct nstr_item np; - struct lndstr land; - struct natstr *natp; - int i,min; - s_char *p; - s_char mess[128]; - double techfact(int, double); - s_char buf[1024]; + struct nstr_item np; + struct lndstr land; + struct natstr *natp; + int i, min; + s_char *p; + s_char mess[128]; + double techfact(int, double); + s_char buf[1024]; - if (!snxtitem(&np, EF_LAND, player->argp[1])) - return RET_SYN; - while (!player->aborted && nxtitem(&np, (s_char *)&land)) { - if (!player->owner || land.lnd_own == 0) - continue; - natp=getnatp(land.lnd_own); - min = morale_base-(int)natp->nat_level[NAT_HLEV]; - sprintf(mess, "New retreat percentage for %s (min %d%%)? ", - prland(&land), min); - p = getstarg(player->argp[2], mess, buf); - if (!check_land_ok(&land)) - continue; - if (player->aborted) - continue; - if (!p || (i = atoi(p)) < 0) - continue; - land.lnd_retreat = ((i < min) ? min : i); - if (land.lnd_retreat > 100) - land.lnd_retreat = 100; - pr("Unit %d retreat percentage changed to %d\n", - land.lnd_uid, land.lnd_retreat); - putland(land.lnd_uid,&land); - } + if (!snxtitem(&np, EF_LAND, player->argp[1])) + return RET_SYN; + while (!player->aborted && nxtitem(&np, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + natp = getnatp(land.lnd_own); + min = morale_base - (int)natp->nat_level[NAT_HLEV]; + sprintf(mess, "New retreat percentage for %s (min %d%%)? ", + prland(&land), min); + p = getstarg(player->argp[2], mess, buf); + if (!check_land_ok(&land)) + continue; + if (player->aborted) + continue; + if (!p || (i = atoi(p)) < 0) + continue; + land.lnd_retreat = ((i < min) ? min : i); + if (land.lnd_retreat > 100) + land.lnd_retreat = 100; + pr("Unit %d retreat percentage changed to %d\n", + land.lnd_uid, land.lnd_retreat); + putland(land.lnd_uid, &land); + } - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/move.c b/src/lib/commands/move.c index fe67a8ee7..dadf00e1c 100644 --- a/src/lib/commands/move.c +++ b/src/lib/commands/move.c @@ -47,318 +47,308 @@ #include "commands.h" -static int cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg); +static int cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg); int move(void) { - register int amount; - struct sctstr sect; - struct sctstr endsect; - struct sctstr start; - struct sctstr tsct; - int packing; - double weight; - int left; - int mcost, dam; - int infected; - int stype; - int vtype; - int amt_src; - int amt_dst; - struct dchrstr *dp; - struct ichrstr *ip; - int work; - int loyal; - int own, mob; - int istest=0; - int n; - coord x, y; - s_char *p; - s_char prompt[1024]; - s_char buf[1024]; - - - istest = *player->argp[0] == 't'; - if ((ip = whatitem(player->argp[1], "move what? ")) == 0) - return RET_SYN; - vtype = ip->i_vtype; - if (!(p = getstarg(player->argp[2], "from sector : ", buf))) - return RET_SYN; - if (!sarg_xy(p, &x, &y)) - return RET_SYN; - if (!getsect(x, y, §) || !player->owner) { - pr("Not yours\n"); - return RET_FAIL; + register int amount; + struct sctstr sect; + struct sctstr endsect; + struct sctstr start; + struct sctstr tsct; + int packing; + double weight; + int left; + int mcost, dam; + int infected; + int stype; + int vtype; + int amt_src; + int amt_dst; + struct dchrstr *dp; + struct ichrstr *ip; + int work; + int loyal; + int own, mob; + int istest = 0; + int n; + coord x, y; + s_char *p; + s_char prompt[1024]; + s_char buf[1024]; + + + istest = *player->argp[0] == 't'; + if ((ip = whatitem(player->argp[1], "move what? ")) == 0) + return RET_SYN; + vtype = ip->i_vtype; + if (!(p = getstarg(player->argp[2], "from sector : ", buf))) + return RET_SYN; + if (!sarg_xy(p, &x, &y)) + return RET_SYN; + if (!getsect(x, y, §) || !player->owner) { + pr("Not yours\n"); + return RET_FAIL; + } + /* + * military control necessary to move + * goodies in occupied territory. + */ + if (!istest && sect.sct_oldown != player->cnum && vtype != V_MILIT) { + int tot_mil = 0; + struct nstr_item ni; + struct lndstr land; + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == player->cnum) + tot_mil += total_mil(&land); } - /* - * military control necessary to move - * goodies in occupied territory. - */ - if (!istest && - sect.sct_oldown != player->cnum && - vtype != V_MILIT) { - int tot_mil=0; - struct nstr_item ni; - struct lndstr land; - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == player->cnum) - tot_mil += total_mil(&land); - } - if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR)+tot_mil) * 10 - < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) { - pr("Military control required to move goods.\n"); - return RET_FAIL; - } - } - stype = sect.sct_type; - dp = &dchr[stype]; - infected = getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT; - amt_src = getvar(vtype, (s_char *)§, EF_SECTOR); - if (!istest && amt_src <= 0) { - pr("No %s in %s\n", ip->i_name, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_FAIL; - } - own = sect.sct_own; - mob = (int)sect.sct_mobil; - if (!istest && vtype == V_CIVIL && sect.sct_oldown != own) { - pr("You can't move conquered populace!\n"); - return RET_FAIL; - } - if (mob <= 0) { - pr("No mobility in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_SYN; - } - if (vtype == V_CIVIL) { - work = sect.sct_work; - if (work != 100) - pr("Warning: civil unrest\n"); - loyal = sect.sct_loyal; - } else if (vtype == V_MILIT) { - work = 100; - loyal = 0; - } - if (istest) - sprintf(prompt, "Number of %s to test move? ", ip->i_name); - else - sprintf(prompt, "Number of %s to move? (max %d) ", - ip->i_name, - amt_src); - if ((amount = onearg(player->argp[3], prompt)) < 0) - return RET_FAIL; - if (!check_sect_ok(§)) + if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10 + < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) { + pr("Military control required to move goods.\n"); return RET_FAIL; - if (amount > amt_src) { - if (istest) { - pr("Note: there are actually only %d %s in %s,\nbut the test will be made for %d %s as you requested.\n", - amt_src, ip->i_name, - xyas(sect.sct_x, sect.sct_y, player->cnum), - amount, ip->i_name); - } else { - amount = amt_src; - pr("Only moving %d.\n", amount); - } } - - if (!want_to_abandon(§, vtype, amount, 0)) { - pr("Move cancelled.\n"); - return RET_FAIL; + } + stype = sect.sct_type; + dp = &dchr[stype]; + infected = getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT; + amt_src = getvar(vtype, (s_char *)§, EF_SECTOR); + if (!istest && amt_src <= 0) { + pr("No %s in %s\n", ip->i_name, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_FAIL; + } + own = sect.sct_own; + mob = (int)sect.sct_mobil; + if (!istest && vtype == V_CIVIL && sect.sct_oldown != own) { + pr("You can't move conquered populace!\n"); + return RET_FAIL; + } + if (mob <= 0) { + pr("No mobility in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_SYN; + } + if (vtype == V_CIVIL) { + work = sect.sct_work; + if (work != 100) + pr("Warning: civil unrest\n"); + loyal = sect.sct_loyal; + } else if (vtype == V_MILIT) { + work = 100; + loyal = 0; + } + if (istest) + sprintf(prompt, "Number of %s to test move? ", ip->i_name); + else + sprintf(prompt, "Number of %s to move? (max %d) ", + ip->i_name, amt_src); + if ((amount = onearg(player->argp[3], prompt)) < 0) + return RET_FAIL; + if (!check_sect_ok(§)) + return RET_FAIL; + if (amount > amt_src) { + if (istest) { + pr("Note: there are actually only %d %s in %s,\nbut the test will be made for %d %s as you requested.\n", amt_src, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum), amount, ip->i_name); + } else { + amount = amt_src; + pr("Only moving %d.\n", amount); } - - if (!check_sect_ok(§)) + } + + if (!want_to_abandon(§, vtype, amount, 0)) { + pr("Move cancelled.\n"); + return RET_FAIL; + } + + if (!check_sect_ok(§)) + return RET_FAIL; + + if (amount <= 0) + return RET_SYN; + packing = ip->i_pkg[dp->d_pkg]; + if (packing > 1 && sect.sct_effic < 60) + packing = 1; + weight = (double)amount *ip->i_lbs / packing; + /* + * First remove commodities from source sector + */ + if (!istest) { + getsect(x, y, &start); + if (start.sct_own != player->cnum) { + pr("Somebody has captured that sector!\n"); return RET_FAIL; - - if (amount <= 0) - return RET_SYN; - packing = ip->i_pkg[dp->d_pkg]; - if (packing > 1 && sect.sct_effic < 60) - packing = 1; - weight = (double)amount * ip->i_lbs / packing; - /* - * First remove commodities from source sector - */ - if (!istest){ - getsect(x, y, &start); - if (start.sct_own != player->cnum) { - pr("Somebody has captured that sector!\n"); - return RET_FAIL; - } - amt_src = getvar(vtype, (s_char *)&start, EF_SECTOR); - if (amt_src < amount) { - pr("Only %d %s left in %s!\n", amt_src, - ip->i_name,xyas(start.sct_x,start.sct_y,player->cnum)); - amount = amt_src; - amt_src = 0; - }else - amt_src -= amount; - - putvar(vtype, amt_src, (s_char *)&start, EF_SECTOR); - start.sct_flags |= MOVE_IN_PROGRESS; - putsect(&start); - } - - /* - * Now parse the path and return ending sector. - */ - dam = (istest ? 0 : 1); - if (dam && !chance(weight / 200.0)) - dam = 0; - mcost = move_ground((s_char *)ip, §, &endsect, - (double)sect.sct_mobil, weight, player->argp[4], cmd_move_map, 0, &dam); - - if (dam) { - left = commdamage(amount, dam, ip->i_vtype); - if (left < amount) { - if (left) { - pr("%d of the %s you were moving were destroyed!\nOnly %d %s made it to %s\n", - amount - left, - ip->i_name, - left, - ip->i_name, - xyas(endsect.sct_x, endsect.sct_y, player->cnum)); - } else { - pr("All of the %s you were moving were destroyed!\n",ip->i_name); - } - amount = left; - } } - - if (mcost > 0) - pr("Total movement cost = %d\n",mcost); - else - pr("No mobility used\n"); - - left=0; - if (mcost < 0) { - pr("Move aborted\n"); - getsect(x,y,§); - sect.sct_mobil = (u_char)mob; - left = mob; - } else if (!istest) { - /* - * decrement mobility appropriately. - */ - getsect(x, y, &start); - mob = start.sct_mobil; - if (mob < mcost) { - if (mob > 0) - mob = 0; - } else - mob -= mcost; - start.sct_mobil = (u_char)mob; - left = start.sct_mobil; - putsect(&start); - getsect(endsect.sct_x, endsect.sct_y, §); + amt_src = getvar(vtype, (s_char *)&start, EF_SECTOR); + if (amt_src < amount) { + pr("Only %d %s left in %s!\n", amt_src, + ip->i_name, xyas(start.sct_x, start.sct_y, player->cnum)); + amount = amt_src; + amt_src = 0; + } else + amt_src -= amount; + + putvar(vtype, amt_src, (s_char *)&start, EF_SECTOR); + start.sct_flags |= MOVE_IN_PROGRESS; + putsect(&start); + } + + /* + * Now parse the path and return ending sector. + */ + dam = (istest ? 0 : 1); + if (dam && !chance(weight / 200.0)) + dam = 0; + mcost = move_ground((s_char *)ip, §, &endsect, + (double)sect.sct_mobil, weight, player->argp[4], + cmd_move_map, 0, &dam); + + if (dam) { + left = commdamage(amount, dam, ip->i_vtype); + if (left < amount) { + if (left) { + pr("%d of the %s you were moving were destroyed!\nOnly %d %s made it to %s\n", amount - left, ip->i_name, left, ip->i_name, xyas(endsect.sct_x, endsect.sct_y, player->cnum)); + } else { + pr("All of the %s you were moving were destroyed!\n", + ip->i_name); + } + amount = left; } - + } + + if (mcost > 0) + pr("Total movement cost = %d\n", mcost); + else + pr("No mobility used\n"); + + left = 0; + if (mcost < 0) { + pr("Move aborted\n"); + getsect(x, y, §); + sect.sct_mobil = (u_char)mob; + left = mob; + } else if (!istest) { /* - * Check for lotsa stuff + * decrement mobility appropriately. */ - if (sect.sct_own != player->cnum) { - if (sect.sct_own != 0) - pr("Somebody has captured that sector!\n"); - getsect(x,y,§); - } - if (vtype == V_CIVIL && getvar(V_CIVIL, (s_char *)§, EF_SECTOR) && - sect.sct_oldown != player->cnum) { - pr("Your civilians don't want to stay!\n"); - getsect(x,y,§); - } - - amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR); - if (32767 - amt_dst < amount) { - pr("Only enough room for %d in %s. The goods will be returned.\n", - 32767 - amt_dst, xyas(sect.sct_x, sect.sct_y, player->cnum)); - getsect(x,y,§); - } - - if (!istest) - pr("%d mob left in %s\n", left, - xyas(start.sct_x,start.sct_y,player->cnum)); + getsect(x, y, &start); + mob = start.sct_mobil; + if (mob < mcost) { + if (mob > 0) + mob = 0; + } else + mob -= mcost; + start.sct_mobil = (u_char)mob; + left = start.sct_mobil; + putsect(&start); + getsect(endsect.sct_x, endsect.sct_y, §); + } + + /* + * Check for lotsa stuff + */ + if (sect.sct_own != player->cnum) { + if (sect.sct_own != 0) + pr("Somebody has captured that sector!\n"); + getsect(x, y, §); + } + if (vtype == V_CIVIL && getvar(V_CIVIL, (s_char *)§, EF_SECTOR) && + sect.sct_oldown != player->cnum) { + pr("Your civilians don't want to stay!\n"); + getsect(x, y, §); + } + + amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR); + if (32767 - amt_dst < amount) { + pr("Only enough room for %d in %s. The goods will be returned.\n", + 32767 - amt_dst, xyas(sect.sct_x, sect.sct_y, player->cnum)); + getsect(x, y, §); + } + + if (!istest) + pr("%d mob left in %s\n", left, + xyas(start.sct_x, start.sct_y, player->cnum)); /* If the sector that things are going to is no longer owned by the player, and was the starting sector, try to find somewhere to dump the stuff. If nowhere to dump it, it disappears. */ - if (sect.sct_own != player->cnum && - sect.sct_x == x && sect.sct_y == y) { - pr("Can't return the goods, since the starting point is no longer\n"); - pr("owned by you.\n"); - /* First lets see if there is one with room */ + if (sect.sct_own != player->cnum && sect.sct_x == x && sect.sct_y == y) { + pr("Can't return the goods, since the starting point is no longer\n"); + pr("owned by you.\n"); + /* First lets see if there is one with room */ + for (n = DIR_FIRST; n <= DIR_LAST; n++) { + getsect(x + diroff[n][0], y + diroff[n][1], &tsct); + if (tsct.sct_own != player->cnum) + continue; + amt_dst = getvar(vtype, (s_char *)&tsct, EF_SECTOR); + if (32767 - amt_dst < amount) + continue; + n = -1; + break; + } + if (n > -1) { + /* Find any sector if none with room */ for (n = DIR_FIRST; n <= DIR_LAST; n++) { getsect(x + diroff[n][0], y + diroff[n][1], &tsct); if (tsct.sct_own != player->cnum) continue; - amt_dst = getvar(vtype, (s_char *)&tsct, EF_SECTOR); - if (32767 - amt_dst < amount) - continue; n = -1; break; } if (n > -1) { - /* Find any sector if none with room */ - for (n = DIR_FIRST; n <= DIR_LAST; n++) { - getsect(x + diroff[n][0], y + diroff[n][1], &tsct); - if (tsct.sct_own != player->cnum) - continue; - n = -1; - break; - } - if (n > -1) { - pr("The goods had nowhere to go, and were destroyed.\n"); - sect.sct_flags &= ~MOVE_IN_PROGRESS; - putsect(§); - return RET_OK; - } - } - pr("The goods were dumped into %s.\n", - xyas(tsct.sct_x, tsct.sct_y, player->cnum)); - getsect(tsct.sct_x, tsct.sct_y, §); - } - - amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR); - if (32767 - amt_dst < amount) { - amount = 32767 - amt_dst; - pr("Only room for %d, the rest were lost.\n", amount); - } - if (istest) + pr("The goods had nowhere to go, and were destroyed.\n"); + sect.sct_flags &= ~MOVE_IN_PROGRESS; + putsect(§); return RET_OK; - if (putvar(vtype, amount + amt_dst, (s_char *)§, EF_SECTOR) < 0) { - pr("No more room in %s. The goods were lost.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - /* charge the player mobility anyway */ - amount = 0; - } - /* - * Now add commodities to destination sector, - * along with plague that came along for the ride. - * Takeover unowned sectors if not deity. - */ - if (infected && getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == 0) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); - if (vtype == V_CIVIL) { - if (opt_NEW_WORK) { - sect.sct_loyal =( (amt_dst * sect.sct_loyal) + - (amount * loyal) ) / (amt_dst+amount); - sect.sct_work =( (amt_dst * sect.sct_work) + - (amount * work) ) / (amt_dst+amount); - } else { /* ! NEW_WORK */ - - /* It only takes one bad apple... */ - if (sect.sct_loyal < loyal) - sect.sct_loyal = loyal; - if (sect.sct_work > work) - sect.sct_work = work; - } /* end NEW_WORK */ + } } - putsect(§); - getsect(x, y, &start); - start.sct_flags &= ~MOVE_IN_PROGRESS; - putsect(&start); + pr("The goods were dumped into %s.\n", + xyas(tsct.sct_x, tsct.sct_y, player->cnum)); + getsect(tsct.sct_x, tsct.sct_y, §); + } + + amt_dst = getvar(vtype, (s_char *)§, EF_SECTOR); + if (32767 - amt_dst < amount) { + amount = 32767 - amt_dst; + pr("Only room for %d, the rest were lost.\n", amount); + } + if (istest) return RET_OK; + if (putvar(vtype, amount + amt_dst, (s_char *)§, EF_SECTOR) < 0) { + pr("No more room in %s. The goods were lost.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + /* charge the player mobility anyway */ + amount = 0; + } + /* + * Now add commodities to destination sector, + * along with plague that came along for the ride. + * Takeover unowned sectors if not deity. + */ + if (infected && getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == 0) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); + if (vtype == V_CIVIL) { + if (opt_NEW_WORK) { + sect.sct_loyal = ((amt_dst * sect.sct_loyal) + + (amount * loyal)) / (amt_dst + amount); + sect.sct_work = ((amt_dst * sect.sct_work) + + (amount * work)) / (amt_dst + amount); + } else { /* ! NEW_WORK */ + + /* It only takes one bad apple... */ + if (sect.sct_loyal < loyal) + sect.sct_loyal = loyal; + if (sect.sct_work > work) + sect.sct_work = work; + } /* end NEW_WORK */ + } + putsect(§); + getsect(x, y, &start); + start.sct_flags &= ~MOVE_IN_PROGRESS; + putsect(&start); + return RET_OK; } /* @@ -371,66 +361,67 @@ move(void) static int cmd_move_map(s_char *what, coord curx, coord cury, s_char *arg) { - player->argp[1] = arg; - player->argp[2] = ""; - player->argp[3] = ""; - player->argp[4] = ""; - player->argp[5] = ""; - player->condarg = 0; - return map(); + player->argp[1] = arg; + player->argp[2] = ""; + player->argp[3] = ""; + player->argp[4] = ""; + player->argp[5] = ""; + player->condarg = 0; + return map(); } int want_to_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp) { - char prompt[80]; + char prompt[80]; - /* First, would we be abandoning it? If not, just return that it's - ok to move out */ - if (!would_abandon(sp, vtype, amnt, lp)) - return 1; + /* First, would we be abandoning it? If not, just return that it's + ok to move out */ + if (!would_abandon(sp, vtype, amnt, lp)) + return 1; - sprintf(prompt, "Do you really want to abandon %s [yn]? ", - xyas(sp->sct_x, sp->sct_y, player->cnum)); + sprintf(prompt, "Do you really want to abandon %s [yn]? ", + xyas(sp->sct_x, sp->sct_y, player->cnum)); - /* now, if they say yes that it's ok, just return 1 */ - if (askyn(prompt)) - return 1; + /* now, if they say yes that it's ok, just return 1 */ + if (askyn(prompt)) + return 1; - /* Nope, not ok */ - return 0; + /* Nope, not ok */ + return 0; } int would_abandon(struct sctstr *sp, int vtype, int amnt, struct lndstr *lp) { - struct sctstr sect; - int mil, civs, loyalcivs; + struct sctstr sect; + int mil, civs, loyalcivs; - if ((vtype != V_CIVIL) && (vtype != V_MILIT)) - return 0; + if ((vtype != V_CIVIL) && (vtype != V_MILIT)) + return 0; - bcopy((s_char *)sp,(s_char *)§,sizeof(struct sctstr)); + bcopy((s_char *)sp, (s_char *)§, sizeof(struct sctstr)); - mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR); - civs = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR); + mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR); + civs = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR); - if (vtype == V_MILIT) - mil -= amnt; + if (vtype == V_MILIT) + mil -= amnt; - if (vtype == V_CIVIL) - civs -= amnt; + if (vtype == V_CIVIL) + civs -= amnt; - if (sp->sct_own == sp->sct_oldown) - loyalcivs = civs; - else - loyalcivs = 0; + if (sp->sct_own == sp->sct_oldown) + loyalcivs = civs; + else + loyalcivs = 0; - /* If they have a military unit there, they still own it */ - if (sp->sct_own != 0 && ((loyalcivs == 0) && (mil == 0) && - (has_units(sp->sct_x, sp->sct_y, sp->sct_own, lp) == 0))) - return 1; + /* If they have a military unit there, they still own it */ + if (sp->sct_own != 0 && ((loyalcivs == 0) && (mil == 0) && + (has_units + (sp->sct_x, sp->sct_y, sp->sct_own, + lp) == 0))) + return 1; - return 0; + return 0; } - diff --git a/src/lib/commands/mult.c b/src/lib/commands/mult.c index 3c22642e0..f2d7f5770 100644 --- a/src/lib/commands/mult.c +++ b/src/lib/commands/mult.c @@ -42,35 +42,35 @@ #include "optlist.h" #include /* bailey@math-cs.kent.edu */ -static void multsingle(natid us, natid them, struct natstr *natp); +static void multsingle(natid us, natid them, struct natstr *natp); int mult(void) { - struct nstr_item ni; - struct natstr nat; - int nats; + struct nstr_item ni; + struct natstr nat; + int nats; - if (!opt_MARKET) { - pr("The market is disabled.\n"); - return RET_FAIL; - } - pr("The mult command is no longer used.\n"); - if (!snxtitem(&ni, EF_NATION, player->argp[1])) - return RET_SYN; - if (commread() < 0) { - pr("Unable to read commodity file; get help!\n"); - return RET_SYS; - } - nats = 0; - while (!player->aborted && nxtitem(&ni, (s_char *)&nat)) { - if ((nat.nat_stat & STAT_NORM) == 0) - continue; - multsingle(player->cnum, (natid)ni.cur, &nat); - nats++; - } - pr("%d nation multipliers changed\n", nats); - return RET_OK; + if (!opt_MARKET) { + pr("The market is disabled.\n"); + return RET_FAIL; + } + pr("The mult command is no longer used.\n"); + if (!snxtitem(&ni, EF_NATION, player->argp[1])) + return RET_SYN; + if (commread() < 0) { + pr("Unable to read commodity file; get help!\n"); + return RET_SYS; + } + nats = 0; + while (!player->aborted && nxtitem(&ni, (s_char *)&nat)) { + if ((nat.nat_stat & STAT_NORM) == 0) + continue; + multsingle(player->cnum, (natid)ni.cur, &nat); + nats++; + } + pr("%d nation multipliers changed\n", nats); + return RET_OK; } /* @@ -79,44 +79,44 @@ mult(void) static void multsingle(natid us, natid them, struct natstr *natp) { - extern double minmult; - extern double maxmult; - double price; - s_char *p; - s_char prompt[128]; - s_char buf[1024]; + extern double minmult; + extern double maxmult; + double price; + s_char *p; + s_char prompt[128]; + s_char buf[1024]; - sprintf(prompt, "%s (%7.3f) : ", natp->nat_cnam, multread(us, them)); - p = getstarg(player->argp[2], prompt, buf); - if (p == 0 || *p == 0) - return; - if ((price = atof(p)) == 0.0) - return; + sprintf(prompt, "%s (%7.3f) : ", natp->nat_cnam, multread(us, them)); + p = getstarg(player->argp[2], prompt, buf); + if (p == 0 || *p == 0) + return; + if ((price = atof(p)) == 0.0) + return; #if defined(HUGE) - if ((price == HUGE) || (price > 1000000.0)) /* Inf causes overflow. */ + if ((price == HUGE) || (price > 1000000.0)) /* Inf causes overflow. */ #else - if (price > 1000000.0) + if (price > 1000000.0) #endif - price = 1000000.0; /* bailey@math-cs.kent.edu */ - /* - * no free lunches! - */ - if (price <= minmult) - price = minmult; - if (price >= maxmult) - price = maxmult; - if (!commlock()) { - pr("Unable to lock commodity file; get help!\n"); - return; - } - if (commread() < 0) { - (void) communlock(); - pr("Unable to re-read commodity file; get help!\n"); - return; - } - multset(them, price); - if (commwrite() < 0) { - pr("Unable to write out commodity file; get help!\n"); - } - (void) communlock(); + price = 1000000.0; /* bailey@math-cs.kent.edu */ + /* + * no free lunches! + */ + if (price <= minmult) + price = minmult; + if (price >= maxmult) + price = maxmult; + if (!commlock()) { + pr("Unable to lock commodity file; get help!\n"); + return; + } + if (commread() < 0) { + (void)communlock(); + pr("Unable to re-read commodity file; get help!\n"); + return; + } + multset(them, price); + if (commwrite() < 0) { + pr("Unable to write out commodity file; get help!\n"); + } + (void)communlock(); } diff --git a/src/lib/commands/name.c b/src/lib/commands/name.c index ba12fa194..41fb770a1 100644 --- a/src/lib/commands/name.c +++ b/src/lib/commands/name.c @@ -51,36 +51,33 @@ int name(void) { - struct shpstr ship; - s_char *p; - struct nstr_item nb; - s_char buf[1024]; + struct shpstr ship; + s_char *p; + struct nstr_item nb; + s_char buf[1024]; - if (!opt_SHIPNAMES) { - pr("Ship naming is not enabled.\n"); + if (!opt_SHIPNAMES) { + pr("Ship naming is not enabled.\n"); + return RET_FAIL; + } + if (!snxtitem(&nb, EF_SHIP, player->argp[1])) + return RET_SYN; + while (nxtitem(&nb, (s_char *)&ship)) { + if (!player->owner) + continue; + p = getstarg(player->argp[2], "Name? ", buf); + if (!check_ship_ok(&ship)) return RET_FAIL; + if (p == 0 || *p == 0) + return RET_SYN; + if (!strcmp(p, "~")) { + ship.shp_name[0] = 0; + } else { + strncpy(ship.shp_name, p, MAXSHPNAMLEN - 1); + ship.shp_name[MAXSHPNAMLEN - 1] = 0; } - if (!snxtitem(&nb, EF_SHIP, player->argp[1])) - return RET_SYN; - while (nxtitem(&nb, (s_char *)&ship)) { - if (!player->owner) - continue; - p = getstarg(player->argp[2], "Name? ", buf); - if (!check_ship_ok(&ship)) - return RET_FAIL; - if (p == 0 || *p == 0) - return RET_SYN; - if (!strcmp(p,"~")) { - ship.shp_name[0] = 0; - } - else - { - strncpy(ship.shp_name,p,MAXSHPNAMLEN - 1); - ship.shp_name[MAXSHPNAMLEN - 1] = 0; - } - putship(ship.shp_uid,&ship); - } + putship(ship.shp_uid, &ship); + } - return RET_OK; + return RET_OK; } - diff --git a/src/lib/commands/nati.c b/src/lib/commands/nati.c index f79eb0598..842c5a266 100644 --- a/src/lib/commands/nati.c +++ b/src/lib/commands/nati.c @@ -44,82 +44,87 @@ int nati(void) { - extern int etu_per_update; - extern double obrate, uwbrate; - struct natstr *natp; - struct sctstr sect; - float hap; - int mil; - int civ; - int poplimit, safepop, uwpop; - double pfac; + extern int etu_per_update; + extern double obrate, uwbrate; + struct natstr *natp; + struct sctstr sect; + float hap; + int mil; + int civ; + int poplimit, safepop, uwpop; + double pfac; - if ((natp = getnatp(player->cnum)) == 0) { - pr("Bad country number %d\n", player->cnum); - return RET_SYN; + if ((natp = getnatp(player->cnum)) == 0) { + pr("Bad country number %d\n", player->cnum); + return RET_SYN; + } + pr("\n(#%i) %s Nation Report\t", player->cnum, cname(player->cnum)); + prdate(); + pr("Nation status is %s", natstate(natp)); + pr(" Bureaucratic Time Units: %d\n", natp->nat_btu); + if (natp->nat_stat & STAT_INUSE) { + getsect(natp->nat_xcap, natp->nat_ycap, §); + if (!player->owner || (sect.sct_type != SCT_CAPIT && + sect.sct_type != SCT_MOUNT && + sect.sct_type != SCT_SANCT)) + pr("No capital. (was at %s)\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + else { + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); + pr("%d%% eff %s at %s has %d civilian%s & %d military\n", + sect.sct_effic, + (sect.sct_type == + SCT_CAPIT ? "capital" : "mountain capital"), + xyas(sect.sct_x, sect.sct_y, player->cnum), civ, splur(civ), + mil); } - pr("\n(#%i) %s Nation Report\t", player->cnum, cname(player->cnum)); - prdate(); - pr("Nation status is %s", natstate(natp)); - pr(" Bureaucratic Time Units: %d\n", natp->nat_btu); - if (natp->nat_stat & STAT_INUSE) { - getsect(natp->nat_xcap, natp->nat_ycap, §); - if (!player->owner || (sect.sct_type != SCT_CAPIT && - sect.sct_type != SCT_MOUNT && - sect.sct_type != SCT_SANCT)) - pr("No capital. (was at %s)\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - else { - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); - pr("%d%% eff %s at %s has %d civilian%s & %d military\n", - sect.sct_effic, - (sect.sct_type == SCT_CAPIT ? "capital" : "mountain capital"), - xyas(sect.sct_x, sect.sct_y, player->cnum), civ, - splur(civ), mil); - } - } - pr(" The treasury has $%.2f", (double) natp->nat_money); - pr(" Military reserves: %d\n", natp->nat_reserve); - pr("Education..........%6.2f Happiness.......%6.2f\n", - (double) natp->nat_level[NAT_ELEV], - (double) natp->nat_level[NAT_HLEV]); - pr("Technology.........%6.2f Research........%6.2f\n", - (double) natp->nat_level[NAT_TLEV], - (double) natp->nat_level[NAT_RLEV]); - pr("Technology factor :%6.2f%%", tfact(player->cnum, 100.)); + } + pr(" The treasury has $%.2f", (double)natp->nat_money); + pr(" Military reserves: %d\n", natp->nat_reserve); + pr("Education..........%6.2f Happiness.......%6.2f\n", + (double)natp->nat_level[NAT_ELEV], + (double)natp->nat_level[NAT_HLEV]); + pr("Technology.........%6.2f Research........%6.2f\n", + (double)natp->nat_level[NAT_TLEV], + (double)natp->nat_level[NAT_RLEV]); + pr("Technology factor :%6.2f%%", tfact(player->cnum, 100.)); - if (opt_NO_PLAGUE) - pfac = 0.0; - else - pfac = ((double) natp->nat_level[NAT_TLEV] + 100.) / - ((double) natp->nat_level[NAT_RLEV] + 100.); - pr(" Plague factor : %6.2f%%\n", pfac); - pr("\n"); + if (opt_NO_PLAGUE) + pfac = 0.0; + else + pfac = ((double)natp->nat_level[NAT_TLEV] + 100.) / + ((double)natp->nat_level[NAT_RLEV] + 100.); + pr(" Plague factor : %6.2f%%\n", pfac); + pr("\n"); - poplimit = 999; - if (opt_RES_POP) - poplimit = max_pop(natp->nat_level[NAT_RLEV], 0); - pr("Max population : %d\n", poplimit); + poplimit = 999; + if (opt_RES_POP) + poplimit = max_pop(natp->nat_level[NAT_RLEV], 0); + pr("Max population : %d\n", poplimit); - safepop = (int)((double)poplimit/(1.0 + obrate*(double)etu_per_update)); - uwpop = (int)((double)poplimit/(1.0 + uwbrate*(double)etu_per_update)); - safepop++; - if (((double)safepop*(1.0 + obrate*(double)etu_per_update)) > ((double)poplimit+0.0000001)) - safepop--; - uwpop++; - if (((double)uwpop*(1.0 + uwbrate*(double)etu_per_update)) > ((double)poplimit+0.0000001)) - uwpop--; + safepop = + (int)((double)poplimit / (1.0 + obrate * (double)etu_per_update)); + uwpop = + (int)((double)poplimit / (1.0 + uwbrate * (double)etu_per_update)); + safepop++; + if (((double)safepop * (1.0 + obrate * (double)etu_per_update)) > + ((double)poplimit + 0.0000001)) + safepop--; + uwpop++; + if (((double)uwpop * (1.0 + uwbrate * (double)etu_per_update)) > + ((double)poplimit + 0.0000001)) + uwpop--; - pr("Max safe population for civs/uws: %d/%d\n",safepop,uwpop); + pr("Max safe population for civs/uws: %d/%d\n", safepop, uwpop); - hap = ((natp->nat_level[NAT_TLEV]-40)/40.0 + - natp->nat_level[NAT_ELEV]/3.0); + hap = ((natp->nat_level[NAT_TLEV] - 40) / 40.0 + + natp->nat_level[NAT_ELEV] / 3.0); - if (hap > 0.0) - pr("Happiness needed is %f\n",hap); - else - pr("No happiness needed\n"); + if (hap > 0.0) + pr("Happiness needed is %f\n", hap); + else + pr("No happiness needed\n"); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/navi.c b/src/lib/commands/navi.c index 1bb684ed9..5025572b2 100644 --- a/src/lib/commands/navi.c +++ b/src/lib/commands/navi.c @@ -53,27 +53,27 @@ static int set_flagship(struct emp_qelem *list, struct shpstr **flagshipp); int navi(void) { - struct nstr_item ni_ship; - struct emp_qelem ship_list; - double minmob, maxmob; - int together; - s_char *cp = 0; - struct shpstr *shp = 0; /* flagship */ + struct nstr_item ni_ship; + struct emp_qelem ship_list; + double minmob, maxmob; + int together; + s_char *cp = 0; + struct shpstr *shp = 0; /* flagship */ struct nstr_sect ns; - s_char origin; - int dir; - int stopping = 0; - int skip = 0; - s_char buf[1024]; - s_char prompt[128]; - s_char pathtaken[1024]; /* Doubtful we'll have a path longer than this */ - s_char *pt = pathtaken; - + s_char origin; + int dir; + int stopping = 0; + int skip = 0; + s_char buf[1024]; + s_char prompt[128]; + s_char pathtaken[1024]; /* Doubtful we'll have a path longer than this */ + s_char *pt = pathtaken; + if (!snxtitem(&ni_ship, EF_SHIP, player->argp[1])) return RET_SYN; shp_sel(&ni_ship, &ship_list); shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum); - player->condarg = 0; /* conditions don't apply to nav_map() */ + player->condarg = 0; /* conditions don't apply to nav_map() */ if (QEMPTY(&ship_list)) { pr("No ships\n"); return RET_FAIL; @@ -84,18 +84,18 @@ navi(void) if (!(cp = shp_path(together, shp, buf))) cp = player->argp[2]; } - + *pt = '\0'; while (!QEMPTY(&ship_list)) { - s_char *bp,dp[80]; - + s_char *bp, dp[80]; + if (cp == 0 || *cp == '\0' || stopping) { stopping = 0; shp_nav(&ship_list, &minmob, &maxmob, &together, player->cnum); if (QEMPTY(&ship_list)) { pr("No ships left\n"); if (strlen(pathtaken) > 0) { - pathtaken[strlen(pathtaken)-1] = '\0'; + pathtaken[strlen(pathtaken) - 1] = '\0'; if (strlen(pathtaken) > 0) pr("Path taken: %s\n", pathtaken); } @@ -106,10 +106,10 @@ navi(void) continue; } if (!skip) - nav_map(shp->shp_x, shp->shp_y, - !(mchr[(int)shp->shp_type].m_flags&M_SUB)); + nav_map(shp->shp_x, shp->shp_y, + !(mchr[(int)shp->shp_type].m_flags & M_SUB)); else - skip=0; + skip = 0; sprintf(prompt, "<%.1f:%.1f: %s> ", maxmob, minmob, xyas(shp->shp_x, shp->shp_y, player->cnum)); cp = getstring(prompt, buf); @@ -120,7 +120,7 @@ navi(void) if (QEMPTY(&ship_list)) { pr("No ships left\n"); if (strlen(pathtaken) > 0) { - pathtaken[strlen(pathtaken)-1] = '\0'; + pathtaken[strlen(pathtaken) - 1] = '\0'; if (strlen(pathtaken) > 0) pr("Path taken: %s\n", pathtaken); } @@ -131,19 +131,15 @@ navi(void) continue; } } - radmapnopr(shp->shp_x, shp->shp_y, (int)shp->shp_effic, + radmapnopr(shp->shp_x, shp->shp_y, (int)shp->shp_effic, (int)techfact(shp->shp_tech, (double)mchr[(int)shp->shp_type].m_vrnge), - (double)((mchr[(int)shp->shp_type].m_flags - & M_SONAR) + (double)((mchr[(int)shp->shp_type].m_flags & M_SONAR) ? techfact(shp->shp_tech, 1.0) : 0.0)); if (cp == 0 || *cp == '\0') cp = &dirch[DIR_STOP]; if (*cp == 'M' || - *cp == 'B' || - *cp == 'f' || - *cp == 'i' || - *cp == 'm') { + *cp == 'B' || *cp == 'f' || *cp == 'i' || *cp == 'm') { ++cp; if (cp[-1] == 'M') { unit_map(EF_SHIP, shp->shp_uid, &ns, &origin); @@ -165,16 +161,16 @@ navi(void) stopping |= shp_sweep(&ship_list, 1, player->cnum); } continue; - } else if (*cp == 'r' || - *cp == 'l' || - *cp == 's') { - bp=++cp; - while((*bp != ' ') && (*bp)) bp++; - while((*bp == ' ') && (*bp)) bp++; + } else if (*cp == 'r' || *cp == 'l' || *cp == 's') { + bp = ++cp; + while ((*bp != ' ') && (*bp)) + bp++; + while ((*bp == ' ') && (*bp)) + bp++; if ((bp != (s_char *)0) && (*bp)) player->argp[1] = bp; else { - sprintf(dp,"%d",shp->shp_uid); + sprintf(dp, "%d", shp->shp_uid); player->argp[1] = dp; } if (cp[-1] == 'r') { @@ -206,14 +202,15 @@ navi(void) continue; } } - stopping |= shp_nav_one_sector(&ship_list, dir, player->cnum, together); + stopping |= + shp_nav_one_sector(&ship_list, dir, player->cnum, together); if (stopping != 2) { - *pt++ = dirch[dir]; - *pt = '\0'; + *pt++ = dirch[dir]; + *pt = '\0'; } } if (strlen(pathtaken) > 0) { - pathtaken[strlen(pathtaken)-1] = '\0'; + pathtaken[strlen(pathtaken) - 1] = '\0'; if (strlen(pathtaken) > 0) pr("Path taken: %s\n", pathtaken); } @@ -224,26 +221,27 @@ int nav_map(int x, int y, int show_designations) { register s_char *ptr; - struct nstr_sect ns; - struct natstr *np; - struct sctstr sect; - struct range range; - int i; + struct nstr_sect ns; + struct natstr *np; + struct sctstr sect; + struct range range; + int i; /* Note this is not re-entrant anyway, so we keep the buffers around */ - static u_char *bitmap = (u_char *)0; - static s_char *wmapbuf = (s_char *)0; - static s_char **wmap = (s_char **)0; - s_char what[64]; - int changed = 0; - + static u_char *bitmap = (u_char *)0; + static s_char *wmapbuf = (s_char *)0; + static s_char **wmap = (s_char **)0; + s_char what[64]; + int changed = 0; + np = getnatp(player->cnum); - sprintf(what, "%d:%d,%d:%d",xrel(np,x-2),xrel(np,x+2),yrel(np,y-1), - yrel(np,y+1)); + sprintf(what, "%d:%d,%d:%d", xrel(np, x - 2), xrel(np, x + 2), + yrel(np, y - 1), yrel(np, y + 1)); if (!snxtsct(&ns, what)) return RET_FAIL; if (!wmapbuf) - wmapbuf = (s_char *)malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char)); + wmapbuf = + (s_char *)malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char)); if (!wmap) { wmap = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); if (wmap && wmapbuf) { @@ -266,14 +264,13 @@ nav_map(int x, int y, int show_designations) ns.ncond = 0; xyrelrange(np, &ns.range, &range); blankfill((s_char *)wmapbuf, &ns.range, 1); - while (nxtsct(&ns, §)){ + while (nxtsct(&ns, §)) { ptr = &wmap[ns.dy][ns.dx]; *ptr = dchr[sect.sct_type].d_mnem; if (!show_designations && sect.sct_own != player->cnum && sect.sct_type != SCT_WATER && - sect.sct_type != SCT_BSPAN && - sect.sct_type != SCT_HARBR) + sect.sct_type != SCT_BSPAN && sect.sct_type != SCT_HARBR) *ptr = '?'; changed += map_set(player->cnum, sect.sct_x, sect.sct_y, *ptr, 0); /* @@ -289,7 +286,7 @@ nav_map(int x, int y, int show_designations) } if (changed) writemap(player->cnum); - for (i=0; i < ns.range.height; i++) + for (i = 0; i < ns.range.height; i++) pr("%s\n", wmap[i]); return RET_OK; } @@ -298,7 +295,7 @@ static int set_flagship(struct emp_qelem *list, struct shpstr **flagshipp) { struct mlist *mlp = (struct mlist *)(list->q_back); - + if (!*flagshipp) pr("Flagship is "); else if ((*flagshipp)->shp_uid != mlp->ship.shp_uid) diff --git a/src/lib/commands/ndump.c b/src/lib/commands/ndump.c index b02663cf5..da2780e66 100644 --- a/src/lib/commands/ndump.c +++ b/src/lib/commands/ndump.c @@ -47,46 +47,49 @@ int ndump(void) { - register int i; - struct nstr_item nstr; - struct nukstr nuk; - time_t now; - int nnukes; + register int i; + struct nstr_item nstr; + struct nukstr nuk; + time_t now; + int nnukes; - if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) - return RET_SYN; - prdate(); - if (player->god) pr(" "); - time(&now); - pr("DUMP NUKES %d\n", now); - if (player->god) pr("own "); - pr("id x y num type\n"); - nnukes = 0; - while (nxtitem(&nstr, (s_char *)&nuk)) { - if (!player->god && !player->owner) - continue; - if (nuk.nuk_own == 0) - continue; - nnukes++; - for (i = 0; i < N_MAXNUKE; i++) { - if (nuk.nuk_types[i] > 0) { - if (player->god) pr("%3d ", nuk.nuk_own); - pr("%d ", nuk.nuk_uid); - prxy("%d %d", nuk.nuk_x, nuk.nuk_y, player->cnum); - pr(" %d", nuk.nuk_types[i]); - pr(" %0.5s", nchr[i].n_name); - pr("\n"); - } - } + if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) + return RET_SYN; + prdate(); + if (player->god) + pr(" "); + time(&now); + pr("DUMP NUKES %d\n", now); + if (player->god) + pr("own "); + pr("id x y num type\n"); + nnukes = 0; + while (nxtitem(&nstr, (s_char *)&nuk)) { + if (!player->god && !player->owner) + continue; + if (nuk.nuk_own == 0) + continue; + nnukes++; + for (i = 0; i < N_MAXNUKE; i++) { + if (nuk.nuk_types[i] > 0) { + if (player->god) + pr("%3d ", nuk.nuk_own); + pr("%d ", nuk.nuk_uid); + prxy("%d %d", nuk.nuk_x, nuk.nuk_y, player->cnum); + pr(" %d", nuk.nuk_types[i]); + pr(" %0.5s", nchr[i].n_name); + pr("\n"); + } } - if (nnukes == 0) { - if (player->argp[1]) - pr("%s: No nuke(s)\n", player->argp[1]); - else - pr("%s: No nuke(s)\n", ""); - return RET_FAIL; - } else - pr("%d nuke%s\n", nnukes, splur(nnukes)); + } + if (nnukes == 0) { + if (player->argp[1]) + pr("%s: No nuke(s)\n", player->argp[1]); + else + pr("%s: No nuke(s)\n", ""); + return RET_FAIL; + } else + pr("%d nuke%s\n", nnukes, splur(nnukes)); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/new.c b/src/lib/commands/new.c index 409b4bbab..721d37cb5 100644 --- a/src/lib/commands/new.c +++ b/src/lib/commands/new.c @@ -53,192 +53,191 @@ extern float start_education, start_happiness; extern float start_technology, start_research; extern int morale_base; -static void ok(s_char *map, int x, int y); -static int isok(int x, int y); +static void ok(s_char *map, int x, int y); +static int isok(int x, int y); -static struct range defrealm = {-8, -5, 10, 5, 0, 0}; +static struct range defrealm = { -8, -5, 10, 5, 0, 0 }; #define MAXAVAIL 300 int new(void) { - extern int max_btus; - extern int players_at_00; - extern int at_least_one_100; + extern int max_btus; + extern int players_at_00; + extern int at_least_one_100; #ifdef START_UNITS - extern int start_unit_type[START_UNITS]; + extern int start_unit_type[START_UNITS]; #endif /* START_UNITS */ - struct sctstr sect; - struct natstr *natp; - struct boundstr newrealms; - struct range absrealm; - natid num; - time_t now; - coord x, y; - int i; - s_char *p; - int n; - extern int startmob; - s_char buf[1024]; + struct sctstr sect; + struct natstr *natp; + struct boundstr newrealms; + struct range absrealm; + natid num; + time_t now; + coord x, y; + int i; + s_char *p; + int n; + extern int startmob; + s_char buf[1024]; - natp = getnatp(player->cnum); - if (natp->nat_xorg != 0 || natp->nat_yorg != 0) { - pr("Must be at 0,0 to add a new country\n"); - return 0; - } - if ((n = natarg(player->argp[1], "Country? ")) < 0) { - pr("Bad country number\n"); - return 0; + natp = getnatp(player->cnum); + if (natp->nat_xorg != 0 || natp->nat_yorg != 0) { + pr("Must be at 0,0 to add a new country\n"); + return 0; + } + if ((n = natarg(player->argp[1], "Country? ")) < 0) { + pr("Bad country number\n"); + return 0; + } + num = n; + natp = getnatp(num); + if ((natp->nat_stat & STAT_NEW) == 0) { + pr("Country #%d (%s) isn't a new country!\n", num, cname(num)); + return RET_SYN; + } + if (player->argp[2] != 0) { + if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, §)) + return RET_SYN; + if (sect.sct_type != SCT_RURAL) { + pr("%s is a %s; try again...\n", + xyas(x, y, player->cnum), dchr[sect.sct_type].d_name); + return RET_SYN; } - num = n; - natp = getnatp(num); - if ((natp->nat_stat & STAT_NEW) == 0) { - pr("Country #%d (%s) isn't a new country!\n", - num, cname(num)); - return RET_SYN; + getsect(x + 2, y, §); + if (sect.sct_type != SCT_RURAL) { + pr("%s is a %s; try again...\n", + xyas(x, y, player->cnum), dchr[sect.sct_type].d_name); + return RET_SYN; } - if (player->argp[2] != 0) { - if ((p = getstarg(player->argp[2], "sanctuary pair : ", buf)) == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, §)) - return RET_SYN; - if (sect.sct_type != SCT_RURAL) { - pr("%s is a %s; try again...\n", - xyas(x, y, player->cnum), dchr[sect.sct_type].d_name); - return RET_SYN; - } - getsect(x + 2, y, §); - if (sect.sct_type != SCT_RURAL) { - pr("%s is a %s; try again...\n", - xyas(x, y, player->cnum), dchr[sect.sct_type].d_name); - return RET_SYN; - } - } else { - (void) time(&now); + } else { + (void)time(&now); #if !defined(_WIN32) - (void) srandom(now); + (void)srandom(now); #else - (void) srand(now); + (void)srand(now); #endif - for (i = 0; i < 300 && !player->aborted; i++) { - /* Both x and y should be either odd or even */ - x = (random() % WORLD_X)-(WORLD_X/2); - y = (((random() % WORLD_Y)-(WORLD_Y/2)) & ~1) | (x & 1); - /* - * If either of the two potential - * sanctuary sectors are already - * owned by someone else, pick - * another place on the map. - */ - getsect(x, y, §); - if (sect.sct_type == SCT_WATER || sect.sct_own != 0) - continue; - getsect(x+2, y, §); - if (sect.sct_type == SCT_WATER || sect.sct_own != 0) - continue; - if (isok(x, y)) - break; - } - if (i == 300) { - pr("couldn't find an empty slot!\n"); - return RET_FAIL; - } - } - - if (player->aborted) - return RET_FAIL; - pr("added country %d at %s\n", num, xyas(x, y, player->cnum)); - getsect(x, y, §); - sect.sct_own = num; - sect.sct_type = SCT_SANCT; - sect.sct_newtype = SCT_SANCT; - sect.sct_effic = 100; - sect.sct_road = 0; - sect.sct_rail = 0; - sect.sct_defense = 0; - if (!opt_DEFENSE_INFRA) - sect.sct_defense = sect.sct_effic; - sect.sct_mobil = startmob; - sect.sct_work = 100; - sect.sct_oldown = num; - if (at_least_one_100) { - sect.sct_oil = 100; - sect.sct_fertil = 100; - sect.sct_uran = 100; - sect.sct_min = 100; - sect.sct_gmin = 100; + for (i = 0; i < 300 && !player->aborted; i++) { + /* Both x and y should be either odd or even */ + x = (random() % WORLD_X) - (WORLD_X / 2); + y = (((random() % WORLD_Y) - (WORLD_Y / 2)) & ~1) | (x & 1); + /* + * If either of the two potential + * sanctuary sectors are already + * owned by someone else, pick + * another place on the map. + */ + getsect(x, y, §); + if (sect.sct_type == SCT_WATER || sect.sct_own != 0) + continue; + getsect(x + 2, y, §); + if (sect.sct_type == SCT_WATER || sect.sct_own != 0) + continue; + if (isok(x, y)) + break; } - if (opt_RES_POP) - putvar(V_CIVIL, 550, (s_char *)§, EF_SECTOR); - else - putvar(V_CIVIL, 999, (s_char *)§, EF_SECTOR); - putvar(V_MILIT, 55, (s_char *)§, EF_SECTOR); - putvar(V_FOOD, 1000, (s_char *)§, EF_SECTOR); - putvar(V_UW, 75, (s_char *)§, EF_SECTOR); - putsect(§); - getsect(x + 2, y, §); - sect.sct_own = num; - sect.sct_type = SCT_SANCT; - sect.sct_newtype = SCT_SANCT; - sect.sct_effic = 100; - sect.sct_road = 0; - sect.sct_rail = 0; - sect.sct_defense = 0; - if (!opt_DEFENSE_INFRA) - sect.sct_defense = sect.sct_effic; - sect.sct_work = 100; - sect.sct_oldown = num; - sect.sct_mobil = startmob; - if (at_least_one_100) { - sect.sct_oil = 100; - sect.sct_fertil = 100; - sect.sct_uran = 100; - sect.sct_min = 100; - sect.sct_gmin = 100; - } - if (opt_RES_POP) - putvar(V_CIVIL, 550, (s_char *)§, EF_SECTOR); - else - putvar(V_CIVIL, 999, (s_char *)§, EF_SECTOR); - putvar(V_FOOD, 100, (s_char *)§, EF_SECTOR); - putvar(V_MILIT, 55, (s_char *)§, EF_SECTOR); - putvar(V_UW, 75, (s_char *)§, EF_SECTOR); - putsect(§); - natp->nat_btu = max_btus; - natp->nat_stat &= ~STAT_NEW; - natp->nat_stat |= STAT_SANCT; - natp->nat_xstart = x; - natp->nat_ystart = y; - natp->nat_xcap = x; - natp->nat_ycap = y; - if (players_at_00) { - natp->nat_xorg = 0; - natp->nat_yorg = 0; - } else { - natp->nat_xorg = x; - natp->nat_yorg = y; + if (i == 300) { + pr("couldn't find an empty slot!\n"); + return RET_FAIL; } - xyabsrange(natp, &defrealm, &absrealm); - newrealms.b_xl = absrealm.lx; - newrealms.b_xh = absrealm.hx; - newrealms.b_yl = absrealm.ly; - newrealms.b_yh = absrealm.hy; - natp->nat_money = START_CASH; - natp->nat_level[NAT_HLEV] = start_happiness; - natp->nat_level[NAT_RLEV] = start_research; - natp->nat_level[NAT_TLEV] = start_technology; - natp->nat_level[NAT_ELEV] = start_education; - for (i = 0; i < MAXNOR; i++) - natp->nat_b[i] = newrealms; - natp->nat_tgms = 0; - (void) close(open(mailbox(buf, num), O_RDWR|O_TRUNC|O_CREAT, 0660)); + } + + if (player->aborted) + return RET_FAIL; + pr("added country %d at %s\n", num, xyas(x, y, player->cnum)); + getsect(x, y, §); + sect.sct_own = num; + sect.sct_type = SCT_SANCT; + sect.sct_newtype = SCT_SANCT; + sect.sct_effic = 100; + sect.sct_road = 0; + sect.sct_rail = 0; + sect.sct_defense = 0; + if (!opt_DEFENSE_INFRA) + sect.sct_defense = sect.sct_effic; + sect.sct_mobil = startmob; + sect.sct_work = 100; + sect.sct_oldown = num; + if (at_least_one_100) { + sect.sct_oil = 100; + sect.sct_fertil = 100; + sect.sct_uran = 100; + sect.sct_min = 100; + sect.sct_gmin = 100; + } + if (opt_RES_POP) + putvar(V_CIVIL, 550, (s_char *)§, EF_SECTOR); + else + putvar(V_CIVIL, 999, (s_char *)§, EF_SECTOR); + putvar(V_MILIT, 55, (s_char *)§, EF_SECTOR); + putvar(V_FOOD, 1000, (s_char *)§, EF_SECTOR); + putvar(V_UW, 75, (s_char *)§, EF_SECTOR); + putsect(§); + getsect(x + 2, y, §); + sect.sct_own = num; + sect.sct_type = SCT_SANCT; + sect.sct_newtype = SCT_SANCT; + sect.sct_effic = 100; + sect.sct_road = 0; + sect.sct_rail = 0; + sect.sct_defense = 0; + if (!opt_DEFENSE_INFRA) + sect.sct_defense = sect.sct_effic; + sect.sct_work = 100; + sect.sct_oldown = num; + sect.sct_mobil = startmob; + if (at_least_one_100) { + sect.sct_oil = 100; + sect.sct_fertil = 100; + sect.sct_uran = 100; + sect.sct_min = 100; + sect.sct_gmin = 100; + } + if (opt_RES_POP) + putvar(V_CIVIL, 550, (s_char *)§, EF_SECTOR); + else + putvar(V_CIVIL, 999, (s_char *)§, EF_SECTOR); + putvar(V_FOOD, 100, (s_char *)§, EF_SECTOR); + putvar(V_MILIT, 55, (s_char *)§, EF_SECTOR); + putvar(V_UW, 75, (s_char *)§, EF_SECTOR); + putsect(§); + natp->nat_btu = max_btus; + natp->nat_stat &= ~STAT_NEW; + natp->nat_stat |= STAT_SANCT; + natp->nat_xstart = x; + natp->nat_ystart = y; + natp->nat_xcap = x; + natp->nat_ycap = y; + if (players_at_00) { + natp->nat_xorg = 0; + natp->nat_yorg = 0; + } else { + natp->nat_xorg = x; + natp->nat_yorg = y; + } + xyabsrange(natp, &defrealm, &absrealm); + newrealms.b_xl = absrealm.lx; + newrealms.b_xh = absrealm.hx; + newrealms.b_yl = absrealm.ly; + newrealms.b_yh = absrealm.hy; + natp->nat_money = START_CASH; + natp->nat_level[NAT_HLEV] = start_happiness; + natp->nat_level[NAT_RLEV] = start_research; + natp->nat_level[NAT_TLEV] = start_technology; + natp->nat_level[NAT_ELEV] = start_education; + for (i = 0; i < MAXNOR; i++) + natp->nat_b[i] = newrealms; + natp->nat_tgms = 0; + (void)close(open(mailbox(buf, num), O_RDWR | O_TRUNC | O_CREAT, 0660)); #ifdef START_UNITS - for(n=0;ncnum), nowned, nfree, navail); - pr("min: %d, oil: %d, gold: %d, uranium: %d\n", - nmin, noil, ngold, nur); - p = getstring("This setup ok? ", buf); - if (p == 0 || *p != 'y') - return 0; - return 1; + nmin = ngold = noil = nur = 0; + navail = nfree = nowned = 0; + if ((map = (s_char *)malloc((WORLD_X * WORLD_Y) / 2)) == 0) { + logerror("malloc failed in isok\n"); + pr("Memory error. Tell the deity.\n"); + return 0; + } + bzero((s_char *)map, (WORLD_X * WORLD_Y) / 2); + ok(map, x, y); + free((s_char *)map); + if (nfree < 5) + return 0; + pr("Cap at %s; owned sectors: %d, free sectors: %d, avail: %d\n", + xyas(x, y, player->cnum), nowned, nfree, navail); + pr("min: %d, oil: %d, gold: %d, uranium: %d\n", + nmin, noil, ngold, nur); + p = getstring("This setup ok? ", buf); + if (p == 0 || *p != 'y') + return 0; + return 1; } static void ok(s_char *map, int x, int y) { - struct sctstr sect; - int dir; - int id; + struct sctstr sect; + int dir; + int id; - if (navail > MAXAVAIL) - return; - id = sctoff(x, y); - if (map[id]) - return; - if (!ef_read(EF_SECTOR, id, (s_char *)§)) - return; - if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) - return; - navail++; - if (navail >= MAXAVAIL) { - pr("At least %d...\n", MAXAVAIL); - return; - } - if (sect.sct_type != SCT_MOUNT && - sect.sct_type != SCT_PLAINS) { - if (sect.sct_own == 0) - nfree++; - else - nowned++; - if (sect.sct_min > 9) - nmin++; - if (sect.sct_gmin > 9) - ngold++; - if (sect.sct_uran > 9) - nur++; - if (sect.sct_oil > 9) - noil++; - } - map[id] = 1; - for (dir = DIR_FIRST; dir <= DIR_LAST; dir++) - ok(map, diroff[dir][0] + x, diroff[dir][1] + y); + if (navail > MAXAVAIL) + return; + id = sctoff(x, y); + if (map[id]) + return; + if (!ef_read(EF_SECTOR, id, (s_char *)§)) + return; + if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_BSPAN) + return; + navail++; + if (navail >= MAXAVAIL) { + pr("At least %d...\n", MAXAVAIL); + return; + } + if (sect.sct_type != SCT_MOUNT && sect.sct_type != SCT_PLAINS) { + if (sect.sct_own == 0) + nfree++; + else + nowned++; + if (sect.sct_min > 9) + nmin++; + if (sect.sct_gmin > 9) + ngold++; + if (sect.sct_uran > 9) + nur++; + if (sect.sct_oil > 9) + noil++; + } + map[id] = 1; + for (dir = DIR_FIRST; dir <= DIR_LAST; dir++) + ok(map, diroff[dir][0] + x, diroff[dir][1] + y); } int deity_build_land(int type, coord x, coord y, natid own, int tlev) { - extern int land_mob_max; - struct lndstr land; - struct lchrstr *lp; - struct nstr_item nstr; - struct natstr *natp; - double techfact(int, double); - int lvec[I_MAX+1]; - int extend = 1; + extern int land_mob_max; + struct lndstr land; + struct lchrstr *lp; + struct nstr_item nstr; + struct natstr *natp; + double techfact(int, double); + int lvec[I_MAX + 1]; + int extend = 1; - natp = getnatp(own); + natp = getnatp(own); - snxtitem_all(&nstr, EF_LAND); - while (nxtitem(&nstr, (s_char *)&land)) { - if (land.lnd_own == 0) { - extend = 0; - break; - } + snxtitem_all(&nstr, EF_LAND); + while (nxtitem(&nstr, (s_char *)&land)) { + if (land.lnd_own == 0) { + extend = 0; + break; } - if (extend) - ef_extend(EF_LAND, 50); - land.lnd_x = x; - land.lnd_y = y; - land.lnd_own = own; - land.lnd_mission = 0; - land.lnd_type = type; - land.lnd_effic = 100; - land.lnd_mobil = land_mob_max; - land.lnd_sell = 0; - land.lnd_tech = tlev; - land.lnd_uid = nstr.cur; - land.lnd_army = ' '; - land.lnd_flags = 0; - land.lnd_ship = -1; - land.lnd_land = -1; - land.lnd_nland = 0; - land.lnd_harden = 0; - time(&land.lnd_access); + } + if (extend) + ef_extend(EF_LAND, 50); + land.lnd_x = x; + land.lnd_y = y; + land.lnd_own = own; + land.lnd_mission = 0; + land.lnd_type = type; + land.lnd_effic = 100; + land.lnd_mobil = land_mob_max; + land.lnd_sell = 0; + land.lnd_tech = tlev; + land.lnd_uid = nstr.cur; + land.lnd_army = ' '; + land.lnd_flags = 0; + land.lnd_ship = -1; + land.lnd_land = -1; + land.lnd_nland = 0; + land.lnd_harden = 0; + time(&land.lnd_access); - land.lnd_retreat = morale_base; + land.lnd_retreat = morale_base; - lp = &lchr[type]; - land.lnd_fuel = lp->l_fuelc; - land.lnd_nxlight = 0; - land.lnd_rflags = 0; - bzero((s_char *)land.lnd_rpath,10); - land.lnd_rad_max = lp->l_rad; - land.lnd_nv = 0; + lp = &lchr[type]; + land.lnd_fuel = lp->l_fuelc; + land.lnd_nxlight = 0; + land.lnd_rflags = 0; + bzero((s_char *)land.lnd_rpath, 10); + land.lnd_rad_max = lp->l_rad; + land.lnd_nv = 0; - land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech); - land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech); - land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech); - land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech); - land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech); - land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech); - land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech); - land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech); - land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech); - land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech); - land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech); - land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech); - land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech); - land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech); - land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech); - land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech); + land.lnd_att = (float)LND_ATTDEF(lp->l_att, tlev - lp->l_tech); + land.lnd_def = (float)LND_ATTDEF(lp->l_def, tlev - lp->l_tech); + land.lnd_vul = (int)LND_VUL(lp->l_vul, tlev - lp->l_tech); + land.lnd_spd = (int)LND_SPD(lp->l_spd, tlev - lp->l_tech); + land.lnd_vis = (int)LND_VIS(lp->l_vis, tlev - lp->l_tech); + land.lnd_spy = (int)LND_SPY(lp->l_spy, tlev - lp->l_tech); + land.lnd_rad = (int)LND_RAD(lp->l_rad, tlev - lp->l_tech); + land.lnd_frg = (int)LND_FRG(lp->l_frg, tlev - lp->l_tech); + land.lnd_acc = (int)LND_ACC(lp->l_acc, tlev - lp->l_tech); + land.lnd_dam = (int)LND_DAM(lp->l_dam, tlev - lp->l_tech); + land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, tlev - lp->l_tech); + land.lnd_aaf = (int)LND_AAF(lp->l_aaf, tlev - lp->l_tech); + land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, tlev - lp->l_tech); + land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, tlev - lp->l_tech); + land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, tlev - lp->l_tech); + land.lnd_maxland = (int)LND_MXL(lp->l_mxland, tlev - lp->l_tech); - bzero((s_char *)lvec, sizeof(lvec)); - getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); - lvec[I_FOOD] += vl_find(V_FOOD,lp->l_vtype,lp->l_vamt,(int)lp->l_nv); - lvec[I_MILIT] = lp->l_mil; - putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); + bzero((s_char *)lvec, sizeof(lvec)); + getvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); + lvec[I_FOOD] += + vl_find(V_FOOD, lp->l_vtype, lp->l_vamt, (int)lp->l_nv); + lvec[I_MILIT] = lp->l_mil; + putvec(VT_ITEM, lvec, (s_char *)&land, EF_LAND); - putland(land.lnd_uid, &land); - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - pr("%s", prland(&land)); - pr(" built in sector %s\n", xyas(x, y, player->cnum)); - return 1; + putland(land.lnd_uid, &land); + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + pr("%s", prland(&land)); + pr(" built in sector %s\n", xyas(x, y, player->cnum)); + return 1; } diff --git a/src/lib/commands/newe.c b/src/lib/commands/newe.c index dc72a667a..4608b1a9f 100644 --- a/src/lib/commands/newe.c +++ b/src/lib/commands/newe.c @@ -46,125 +46,123 @@ int newe(void) { - extern double obrate, uwbrate; - extern int etu_per_update; - struct natstr *natp; - struct sctstr sect; - struct nstr_sect nstr; - double work, wforce, lcms, hcms; - int items[I_MAX+1]; - int nsect; - int civs=0; - int uws=0; - int bwork; - int twork; - int type; - int eff; - int maxpop; + extern double obrate, uwbrate; + extern int etu_per_update; + struct natstr *natp; + struct sctstr sect; + struct nstr_sect nstr; + double work, wforce, lcms, hcms; + int items[I_MAX + 1]; + int nsect; + int civs = 0; + int uws = 0; + int bwork; + int twork; + int type; + int eff; + int maxpop; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - player->simulation = 1; - prdate(); - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (!sect.sct_off) { - getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR); - - civs = min(999, (int) ((obrate * (double) etu_per_update + 1.0) - * (double) items[I_CIVIL])); - uws = min(999, (int) ((uwbrate * (double) etu_per_update + 1.0) - * (double) items[I_UW])); - natp = getnatp(sect.sct_own); - maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); - civs = min(civs, maxpop); - uws = min(uws, maxpop); - /* This isn't quite right, since research might rise/fall */ - /* during the update, but it's the best we can really do */ - wforce = (int) - ((civs * sect.sct_work) / 100.0 - + uws + items[I_MILIT] * 2 / 5.0); - - work = etu_per_update * wforce / 100.0; - bwork = work/2; - - type = sect.sct_type; - eff = sect.sct_effic; - if(sect.sct_newtype != type) { - twork = (eff+3)/4; - if(twork > bwork) { - twork = bwork; - } - work -= twork; - bwork -= twork; - eff -= twork*4; - if(eff <= 0) { - type = sect.sct_newtype; - eff = 0; - } - - twork = 100 - eff; - if(twork > bwork) { - twork = bwork; - } - if (dchr[type].d_lcms>0){ - lcms = items[I_LCM]; - lcms = (int)(lcms/dchr[type].d_lcms); - if (twork > lcms) - twork = lcms; - } - if (dchr[type].d_hcms>0){ - hcms = items[I_HCM]; - hcms = (int)(hcms/dchr[type].d_hcms); - if (twork > hcms) - twork = hcms; - } - work -= twork; - eff += twork; - } - else if(eff < 100) { - twork = 100 - eff; - if(twork > bwork) { - twork = bwork; - } - if (dchr[type].d_lcms>0){ - lcms = items[I_LCM]; - lcms = (int)(lcms/dchr[type].d_lcms); - if (twork > lcms) - twork = lcms; - } - if (dchr[type].d_hcms>0){ - hcms = items[I_HCM]; - hcms = (int)(hcms/dchr[type].d_hcms); - if (twork > hcms) - twork = hcms; - } - work -= twork; - eff += twork; - } - } else { - eff = sect.sct_effic; - type = sect.sct_type; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + player->simulation = 1; + prdate(); + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (!sect.sct_off) { + getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR); + + civs = min(999, (int)((obrate * (double)etu_per_update + 1.0) + * (double)items[I_CIVIL])); + uws = min(999, (int)((uwbrate * (double)etu_per_update + 1.0) + * (double)items[I_UW])); + natp = getnatp(sect.sct_own); + maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); + civs = min(civs, maxpop); + uws = min(uws, maxpop); + /* This isn't quite right, since research might rise/fall */ + /* during the update, but it's the best we can really do */ + wforce = (int) + ((civs * sect.sct_work) / 100.0 + + uws + items[I_MILIT] * 2 / 5.0); + + work = etu_per_update * wforce / 100.0; + bwork = work / 2; + + type = sect.sct_type; + eff = sect.sct_effic; + if (sect.sct_newtype != type) { + twork = (eff + 3) / 4; + if (twork > bwork) { + twork = bwork; + } + work -= twork; + bwork -= twork; + eff -= twork * 4; + if (eff <= 0) { + type = sect.sct_newtype; + eff = 0; + } + + twork = 100 - eff; + if (twork > bwork) { + twork = bwork; } - if (nsect++ == 0) { - pr("EFFICIENCY SIMULATION\n"); - pr(" sect des projected eff\n"); + if (dchr[type].d_lcms > 0) { + lcms = items[I_LCM]; + lcms = (int)(lcms / dchr[type].d_lcms); + if (twork > lcms) + twork = lcms; } - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[type].d_mnem); - pr(" %3d%%\n", eff); + if (dchr[type].d_hcms > 0) { + hcms = items[I_HCM]; + hcms = (int)(hcms / dchr[type].d_hcms); + if (twork > hcms) + twork = hcms; + } + work -= twork; + eff += twork; + } else if (eff < 100) { + twork = 100 - eff; + if (twork > bwork) { + twork = bwork; + } + if (dchr[type].d_lcms > 0) { + lcms = items[I_LCM]; + lcms = (int)(lcms / dchr[type].d_lcms); + if (twork > lcms) + twork = lcms; + } + if (dchr[type].d_hcms > 0) { + hcms = items[I_HCM]; + hcms = (int)(hcms / dchr[type].d_hcms); + if (twork > hcms) + twork = hcms; + } + work -= twork; + eff += twork; + } + } else { + eff = sect.sct_effic; + type = sect.sct_type; + } + if (nsect++ == 0) { + pr("EFFICIENCY SIMULATION\n"); + pr(" sect des projected eff\n"); } - player->simulation = 0; - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return RET_OK; + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[type].d_mnem); + pr(" %3d%%\n", eff); + } + player->simulation = 0; + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return RET_OK; } - diff --git a/src/lib/commands/news.c b/src/lib/commands/news.c index 7ebadf047..ddbf6a6bb 100644 --- a/src/lib/commands/news.c +++ b/src/lib/commands/news.c @@ -42,174 +42,176 @@ #include "commands.h" #include "optlist.h" -static void preport(register struct nwsstr *np); +static void preport(register struct nwsstr *np); int news(void) { - extern s_char *page_headings[]; - struct natstr *natp; - time_t now; - int page; - time_t then; - time_t delta; - struct nwsstr nws; - struct nstr_item nstr; - int page_has_news[N_MAX_PAGE+1]; - int there_is_news = 0; - short sectors_taken[MAXNOC][MAXNOC]; - short sectors_delta; - short max_delta = -1; - short abs_delta; - short k; - int sectors_were_taken = 0; - natid i,j; - s_char num[128]; - s_char *verb; + extern s_char *page_headings[]; + struct natstr *natp; + time_t now; + int page; + time_t then; + time_t delta; + struct nwsstr nws; + struct nstr_item nstr; + int page_has_news[N_MAX_PAGE + 1]; + int there_is_news = 0; + short sectors_taken[MAXNOC][MAXNOC]; + short sectors_delta; + short max_delta = -1; + short abs_delta; + short k; + int sectors_were_taken = 0; + natid i, j; + s_char num[128]; + s_char *verb; - bzero((s_char *)page_has_news, sizeof(page_has_news)); - bzero((s_char *)sectors_taken, sizeof(sectors_taken)); - (void) head(); - (void) time(&now); - natp = getnatp(player->cnum); - then = natp->nat_newstim; - if (!opt_HIDDEN) { - if (player->argp[1] != 0 && isdigit(*player->argp[1])) { - delta = days(atoi(player->argp[1])); - then = now - delta; - } + bzero((s_char *)page_has_news, sizeof(page_has_news)); + bzero((s_char *)sectors_taken, sizeof(sectors_taken)); + (void)head(); + (void)time(&now); + natp = getnatp(player->cnum); + then = natp->nat_newstim; + if (!opt_HIDDEN) { + if (player->argp[1] != 0 && isdigit(*player->argp[1])) { + delta = days(atoi(player->argp[1])); + then = now - delta; } - natp->nat_newstim = now; + } + natp->nat_newstim = now; /* if (then < now - days(3)) then = now - days(3); */ - snxtitem(&nstr, EF_NEWS, "*"); - pr("\nThe details of Empire news since %s", ctime(&then)); + snxtitem(&nstr, EF_NEWS, "*"); + pr("\nThe details of Empire news since %s", ctime(&then)); + while (nxtitem(&nstr, (s_char *)&nws)) { + if (nws.nws_when < then) + continue; + if (opt_HIDDEN) { + if (!player->god && + !(getcontact(getnatp(player->cnum), nws.nws_ano) && + getcontact(getnatp(player->cnum), nws.nws_vno))) + continue; + } + ++page_has_news[rpt[(int)nws.nws_vrb].r_newspage]; + ++there_is_news; + } + for (page = 1; page <= N_MAX_PAGE; page++) { + if (!page_has_news[page]) + continue; + pr("\n\t === %s ===\n", page_headings[page]); + snxtitem_rewind(&nstr); while (nxtitem(&nstr, (s_char *)&nws)) { - if (nws.nws_when < then) - continue; - if (opt_HIDDEN) { - if (!player->god && - !(getcontact(getnatp(player->cnum), nws.nws_ano) && - getcontact(getnatp(player->cnum), nws.nws_vno))) - continue; - } - ++page_has_news[rpt[(int)nws.nws_vrb].r_newspage]; - ++there_is_news; + if (rpt[(int)nws.nws_vrb].r_newspage != page) + continue; + if (nws.nws_when < then) + continue; + if (nws.nws_ntm == 0) + nws.nws_ntm = 1; + if (opt_HIDDEN) { + if (!player->god && + !(getcontact(getnatp(player->cnum), nws.nws_ano) && + getcontact(getnatp(player->cnum), nws.nws_vno))) + continue; + } + if (page == N_FRONT && + (nws.nws_vrb == N_WON_SECT || + nws.nws_vrb == N_AWON_SECT || + nws.nws_vrb == N_PWON_SECT)) { + sectors_taken[nws.nws_ano][nws.nws_vno] += nws.nws_ntm; + sectors_were_taken += nws.nws_ntm; + } + preport(&nws); } - for (page = 1; page <= N_MAX_PAGE; page++) { - if (!page_has_news[page]) - continue; - pr("\n\t === %s ===\n", page_headings[page]); - snxtitem_rewind(&nstr); - while (nxtitem(&nstr, (s_char *)&nws)) { - if (rpt[(int)nws.nws_vrb].r_newspage != page) - continue; - if (nws.nws_when < then) - continue; - if (nws.nws_ntm == 0) - nws.nws_ntm = 1; - if (opt_HIDDEN) { - if (!player->god && - !(getcontact(getnatp(player->cnum), nws.nws_ano) && - getcontact(getnatp(player->cnum), nws.nws_vno))) - continue; - } - if (page == N_FRONT && - (nws.nws_vrb == N_WON_SECT || - nws.nws_vrb == N_AWON_SECT || - nws.nws_vrb == N_PWON_SECT)) { - sectors_taken[nws.nws_ano][nws.nws_vno] += nws.nws_ntm; - sectors_were_taken += nws.nws_ntm; - } - preport(&nws); - } + } + if (sectors_were_taken) { + for (i = 0; i < MAXNOC; ++i) { + for (j = 0; j < i; ++j) { + sectors_delta = sectors_taken[i][j] - sectors_taken[j][i]; + if (max_delta < abs(sectors_delta)) + max_delta = abs(sectors_delta); + } } - if (sectors_were_taken) { - for (i = 0; i < MAXNOC; ++i) { - for (j = 0; j < i; ++j) { - sectors_delta = sectors_taken[i][j] - - sectors_taken[j][i]; - if (max_delta < abs(sectors_delta)) - max_delta = abs(sectors_delta); - } - } - pr("\n\t === The Bottom Line ==\n"); - for (k = max_delta; k > 0; --k) { - for (i = 0; i < MAXNOC; ++i) { - for (j = 0; j < i; ++j) { - sectors_delta = sectors_taken[i][j] - - sectors_taken[j][i]; - abs_delta = abs(sectors_delta); - if (abs_delta != k) - continue; - if (abs_delta == 1) - verb = "stole"; - else if (abs_delta < 4) - verb = "took"; - else if (abs_delta < 8) - verb = "captured"; - else - verb = "seized"; - if (sectors_delta > 0) { - numstr(num, abs_delta); - pr("%s %s %s sector%s from %s\n", cname(i), verb, num, splur(sectors_delta), cname(j)); - } else if (sectors_delta < 0) { - numstr(num, abs_delta); - pr("%s %s %s sector%s from %s\n", cname(j), verb, num, splur(-sectors_delta), cname(i)); - } - } - } + pr("\n\t === The Bottom Line ==\n"); + for (k = max_delta; k > 0; --k) { + for (i = 0; i < MAXNOC; ++i) { + for (j = 0; j < i; ++j) { + sectors_delta = sectors_taken[i][j] - + sectors_taken[j][i]; + abs_delta = abs(sectors_delta); + if (abs_delta != k) + continue; + if (abs_delta == 1) + verb = "stole"; + else if (abs_delta < 4) + verb = "took"; + else if (abs_delta < 8) + verb = "captured"; + else + verb = "seized"; + if (sectors_delta > 0) { + numstr(num, abs_delta); + pr("%s %s %s sector%s from %s\n", cname(i), verb, + num, splur(sectors_delta), cname(j)); + } else if (sectors_delta < 0) { + numstr(num, abs_delta); + pr("%s %s %s sector%s from %s\n", cname(j), verb, + num, splur(-sectors_delta), cname(i)); + } } + } } - if (!there_is_news) - pr("\nNo news at the moment...\n"); - return 0; + } + if (!there_is_news) + pr("\nNo news at the moment...\n"); + return 0; } static void preport(register struct nwsstr *np) { - register s_char *cp; - register int i; - s_char buf[255]; - s_char num[128]; - s_char *ptr; + register s_char *cp; + register int i; + s_char buf[255]; + s_char num[128]; + s_char *ptr; - cp = buf; - sprintf(buf, "%-16.16s ", ctime(&np->nws_when)); + cp = buf; + sprintf(buf, "%-16.16s ", ctime(&np->nws_when)); + cp += strlen(cp); + ptr = numstr(num, np->nws_ntm); + /* + * vary the order of the printing of "%d times " + */ + if ((random() & 3) == 0 && np->nws_ntm > 1) { + sprintf(cp, "%s times ", ptr); cp += strlen(cp); - ptr = numstr(num, np->nws_ntm); - /* - * vary the order of the printing of "%d times " - */ - if ((random() & 3) == 0 && np->nws_ntm > 1) { - sprintf(cp, "%s times ", ptr); - cp += strlen(cp); - np->nws_ntm = 1; - } - strcpy(cp, cname(np->nws_ano)); - cp += strlen(cp); - *cp++ = ' '; - if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB) - np->nws_vrb = 0; - sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS], - cname(np->nws_vno)); + np->nws_ntm = 1; + } + strcpy(cp, cname(np->nws_ano)); + cp += strlen(cp); + *cp++ = ' '; + if (np->nws_vrb < 1 || np->nws_vrb > N_MAX_VERB) + np->nws_vrb = 0; + sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[random() % NUM_RPTS], + cname(np->nws_vno)); + cp += strlen(cp); + if (np->nws_ntm != 1) { + sprintf(cp, " %s times", ptr); cp += strlen(cp); - if (np->nws_ntm != 1) { - sprintf(cp, " %s times", ptr); - cp += strlen(cp); - } - if (*buf >= 'a' && *buf <= 'z') - *buf += 'A' - 'a'; - if (cp - buf > 80) { - for (i=80; --i > 60; ) - if (buf[i] == ' ') break; - buf[i] = '\0'; - pr("%s\n\t\t %s\n", buf, &buf[i+1]); - } else { - pr("%s\n", buf); - } - np->nws_ntm = 0; - return; + } + if (*buf >= 'a' && *buf <= 'z') + *buf += 'A' - 'a'; + if (cp - buf > 80) { + for (i = 80; --i > 60;) + if (buf[i] == ' ') + break; + buf[i] = '\0'; + pr("%s\n\t\t %s\n", buf, &buf[i + 1]); + } else { + pr("%s\n", buf); + } + np->nws_ntm = 0; + return; } diff --git a/src/lib/commands/nuke.c b/src/lib/commands/nuke.c index c10923098..531af0598 100644 --- a/src/lib/commands/nuke.c +++ b/src/lib/commands/nuke.c @@ -46,65 +46,65 @@ int nuke(void) { - register int first_line = 0; - register int first_nuke; - register int show_comm; - register int i; - struct nstr_item nstr; - struct nukstr nuk; - struct sctstr sect; - int item[I_MAX+1]; + register int first_line = 0; + register int first_nuke; + register int show_comm; + register int i; + struct nstr_item nstr; + struct nukstr nuk; + struct sctstr sect; + int item[I_MAX + 1]; - if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) - return RET_SYN; + if (!snxtitem(&nstr, EF_NUKE, player->argp[1])) + return RET_SYN; - while (nxtitem(&nstr, (s_char *)&nuk)) { - if (!player->god && !player->owner) - continue; - if (nuk.nuk_own == 0) - continue; - if (first_line++ == 0) { - if (player->god) - pr("own "); - pr(" sect eff num nuke-type lcm hcm oil rad avail\n"); + while (nxtitem(&nstr, (s_char *)&nuk)) { + if (!player->god && !player->owner) + continue; + if (nuk.nuk_own == 0) + continue; + if (first_line++ == 0) { + if (player->god) + pr("own "); + pr(" sect eff num nuke-type lcm hcm oil rad avail\n"); + } + getsect(nuk.nuk_x, nuk.nuk_y, §); + getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); + first_nuke = 1; + show_comm = 0; + if (sect.sct_type == SCT_NUKE && sect.sct_effic >= 60) + show_comm = 1; + for (i = 0; i < N_MAXNUKE; i++) { + if (nuk.nuk_types[i] > 0) { + if (first_nuke) { + if (player->god) + pr("%-3d ", nuk.nuk_own); + prxy("%4d,%-4d", sect.sct_x, sect.sct_y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sect.sct_effic); + first_nuke = 0; + } else { + pr(" "); } - getsect(nuk.nuk_x, nuk.nuk_y, §); - getvec(VT_ITEM, item, (s_char *)§, EF_SECTOR); - first_nuke = 1; - show_comm = 0; - if (sect.sct_type == SCT_NUKE && sect.sct_effic >= 60) - show_comm = 1; - for (i = 0; i < N_MAXNUKE; i++) { - if (nuk.nuk_types[i] > 0) { - if (first_nuke) { - if (player->god) - pr("%-3d ", nuk.nuk_own); - prxy("%4d,%-4d", sect.sct_x, sect.sct_y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sect.sct_effic); - first_nuke = 0; - } else { - pr(" "); - } - pr("%3d ", nuk.nuk_types[i]); - pr("%-16.16s ", nchr[i].n_name); - - if (show_comm) { - pr("%5d ", item[I_LCM]); - pr("%5d ", item[I_HCM]); - pr("%5d ", item[I_OIL]); - pr("%5d ", item[I_RAD]); - pr("%5d", sect.sct_avail); - show_comm = 0; - } - pr("\n"); - } + pr("%3d ", nuk.nuk_types[i]); + pr("%-16.16s ", nchr[i].n_name); + + if (show_comm) { + pr("%5d ", item[I_LCM]); + pr("%5d ", item[I_HCM]); + pr("%5d ", item[I_OIL]); + pr("%5d ", item[I_RAD]); + pr("%5d", sect.sct_avail); + show_comm = 0; } + pr("\n"); + } } - return RET_OK; + } + return RET_OK; } diff --git a/src/lib/commands/offe.c b/src/lib/commands/offe.c index 3af0c4c4a..72e0291c5 100644 --- a/src/lib/commands/offe.c +++ b/src/lib/commands/offe.c @@ -49,197 +49,197 @@ static int do_loan(void); int offe(void) { - register s_char *cp; - s_char buf[1024]; + register s_char *cp; + s_char buf[1024]; - if (!(cp = getstarg(player->argp[1], "loan or treaty? ", buf)) || !*cp) - return RET_SYN; + if (!(cp = getstarg(player->argp[1], "loan or treaty? ", buf)) || !*cp) + return RET_SYN; - switch (*cp) { - case 'l': - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; - } - return do_loan(); - case 't': - if (!opt_TREATIES) { - pr("Treaties are not enabled.\n"); - return RET_FAIL; - } - return do_treaty(); - default: - pr("You must specify \"loan\" as there are no treaties.\n"); - return RET_SYN; - } + switch (*cp) { + case 'l': + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; + } + return do_loan(); + case 't': + if (!opt_TREATIES) { + pr("Treaties are not enabled.\n"); + return RET_FAIL; + } + return do_treaty(); + default: + pr("You must specify \"loan\" as there are no treaties.\n"); + return RET_SYN; + } } -static int +static int do_treaty(void) { - register s_char *cp; - register int ourcond; - register int theircond; - register int j; - struct tchrstr *tcp; - struct trtstr trty; - struct nstr_item nstr; - natid recipient; - time_t now; - int n; - struct natstr *natp; - s_char prompt[128]; - s_char buf[1024]; + register s_char *cp; + register int ourcond; + register int theircond; + register int j; + struct tchrstr *tcp; + struct trtstr trty; + struct nstr_item nstr; + natid recipient; + time_t now; + int n; + struct natstr *natp; + s_char prompt[128]; + s_char buf[1024]; - if ((n = natarg(player->argp[2], "Treaty offered to? ")) < 0) - return RET_SYN; - recipient = n; - if (recipient == player->cnum) { - pr("You can't sign a treaty with yourself!\n"); - return RET_FAIL; - } - natp = getnatp(recipient); - if (player->cnum && (getrejects(player->cnum,natp) & REJ_TREA)) { - pr("%s is rejecting your treaties.\n", - cname(recipient)); - return RET_SYN; - } - pr("Terms for %s:\n", cname(recipient)); - theircond = 0; - for (tcp = tchr; tcp && tcp->t_cond; tcp++) { - sprintf(prompt, "%s? ", tcp->t_name); - if ((cp = getstring(prompt, buf)) == 0) - return RET_FAIL; - if (*cp == 'y') - theircond |= tcp->t_cond; - } - pr("Terms for you:\n"); - ourcond = 0; - for (tcp = tchr; tcp && tcp->t_cond; tcp++) { - sprintf(prompt, "%s? ", tcp->t_name); - if ((cp = getstring(prompt, buf)) == 0) - return RET_FAIL; - if (*cp == 'y') - ourcond |= tcp->t_cond; - } - if (ourcond == 0 && theircond == 0) { - pr("Treaties with no clauses aren't very useful, boss!\n"); - return RET_SYN; - } - cp = getstring("Proposed treaty duration? (days) ", buf); - if (cp == 0) - return RET_FAIL; - j = atopi(cp); - if (j == 0) { - pr("Bad treaty duration.\n"); - return RET_SYN; - } - (void) time(&now); - snxtitem_all(&nstr,EF_TREATY); - while (nxtitem(&nstr, (s_char *)&trty)) { - if (trty.trt_status == TS_FREE) { - break; - } - } - trty.trt_acond = ourcond; - trty.trt_bcond = theircond; - trty.trt_status = TS_PROPOSED; - trty.trt_cna = player->cnum; - trty.trt_cnb = recipient; - trty.trt_exp = j * SECS_PER_DAY + now; - if (!puttre(nstr.cur,&trty)) { - pr("Couldn't save treaty; get help.\n"); - return RET_SYS; - } - wu(0, recipient, "Treaty #%d proposed to you by %s\n", - nstr.cur, cname(player->cnum)); - pr("You have proposed treaty #%d\n", nstr.cur); - return RET_OK; + if ((n = natarg(player->argp[2], "Treaty offered to? ")) < 0) + return RET_SYN; + recipient = n; + if (recipient == player->cnum) { + pr("You can't sign a treaty with yourself!\n"); + return RET_FAIL; + } + natp = getnatp(recipient); + if (player->cnum && (getrejects(player->cnum, natp) & REJ_TREA)) { + pr("%s is rejecting your treaties.\n", cname(recipient)); + return RET_SYN; + } + pr("Terms for %s:\n", cname(recipient)); + theircond = 0; + for (tcp = tchr; tcp && tcp->t_cond; tcp++) { + sprintf(prompt, "%s? ", tcp->t_name); + if ((cp = getstring(prompt, buf)) == 0) + return RET_FAIL; + if (*cp == 'y') + theircond |= tcp->t_cond; + } + pr("Terms for you:\n"); + ourcond = 0; + for (tcp = tchr; tcp && tcp->t_cond; tcp++) { + sprintf(prompt, "%s? ", tcp->t_name); + if ((cp = getstring(prompt, buf)) == 0) + return RET_FAIL; + if (*cp == 'y') + ourcond |= tcp->t_cond; + } + if (ourcond == 0 && theircond == 0) { + pr("Treaties with no clauses aren't very useful, boss!\n"); + return RET_SYN; + } + cp = getstring("Proposed treaty duration? (days) ", buf); + if (cp == 0) + return RET_FAIL; + j = atopi(cp); + if (j == 0) { + pr("Bad treaty duration.\n"); + return RET_SYN; + } + (void)time(&now); + snxtitem_all(&nstr, EF_TREATY); + while (nxtitem(&nstr, (s_char *)&trty)) { + if (trty.trt_status == TS_FREE) { + break; + } + } + trty.trt_acond = ourcond; + trty.trt_bcond = theircond; + trty.trt_status = TS_PROPOSED; + trty.trt_cna = player->cnum; + trty.trt_cnb = recipient; + trty.trt_exp = j * SECS_PER_DAY + now; + if (!puttre(nstr.cur, &trty)) { + pr("Couldn't save treaty; get help.\n"); + return RET_SYS; + } + wu(0, recipient, "Treaty #%d proposed to you by %s\n", + nstr.cur, cname(player->cnum)); + pr("You have proposed treaty #%d\n", nstr.cur); + return RET_OK; } -static int +static int do_loan(void) { - register int amt, irate, dur, maxloan; - struct nstr_item nstr; - struct natstr *natp; - struct lonstr loan; - natid recipient; - int n; - s_char prompt[128]; + register int amt, irate, dur, maxloan; + struct nstr_item nstr; + struct natstr *natp; + struct lonstr loan; + natid recipient; + int n; + s_char prompt[128]; - if ((n = natarg(player->argp[2], "Lend to? ")) < 0) - return RET_SYN; - recipient = n; - if (recipient == player->cnum) { - pr("You can't loan yourself money!\n"); - return RET_FAIL; - } - natp = getnatp(recipient); - if (player->cnum && (getrejects(player->cnum,natp) & REJ_LOAN)) { - pr("%s is rejecting your loans.\n", - cname(recipient)); - return RET_SYN; - } - natp = getnatp(player->cnum); - if (natp->nat_money + 100 > MAXLOAN) - maxloan = MAXLOAN; - else - maxloan = natp->nat_money - 100; - if (maxloan < 0) { - pr("You don't have enough money to loan!\n"); - return RET_FAIL; - } - sprintf(prompt, "Size of loan for country #%d? (max %d) ", - recipient, maxloan); - amt = onearg(player->argp[3], prompt); - if (amt <= 0) - return RET_FAIL; - if (amt > MAXLOAN) { - pr("You can only loan $%d at a time.\n",MAXLOAN); - return RET_FAIL; - } - if (amt > maxloan) { - pr("You can't afford that much.\n"); - return RET_FAIL; - } - dur = onearg(player->argp[4], "Duration? (days, max 7) "); - if (dur <= 0) - return RET_FAIL; - if (dur >7) return RET_FAIL; - irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) "); - if (irate >25) return RET_FAIL; - if (irate < 5) - return RET_FAIL; - snxtitem_all(&nstr, EF_LOAN); - while (nxtitem(&nstr, (s_char *) &loan)) { - if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum) && - (loan.l_loner == recipient)) { - pr("You already owe HIM money - how about repaying your loan?\n"); - return RET_FAIL; - } - } - snxtitem_all(&nstr, EF_LOAN); - while (nxtitem(&nstr, (s_char *) &loan)) { - if (loan.l_status == LS_FREE) - break; - } - loan.l_loner = player->cnum; - loan.l_lonee = recipient; - loan.l_status = LS_PROPOSED; - loan.l_irate = min(irate, 127); - loan.l_ldur = min(dur, 127); - loan.l_amtpaid = 0; - loan.l_amtdue = amt; - (void) time(&loan.l_lastpay); - loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay; - loan.l_uid = nstr.cur; - if (!putloan(nstr.cur, &loan)) { - pr("Couldn't save loan; get help!\n"); - return RET_SYS; - } - pr("You have offered loan %d\n", nstr.cur); - wu(0, recipient, "Country #%d has offered you a loan (#%d)\n", - player->cnum, nstr.cur); - return RET_OK; + if ((n = natarg(player->argp[2], "Lend to? ")) < 0) + return RET_SYN; + recipient = n; + if (recipient == player->cnum) { + pr("You can't loan yourself money!\n"); + return RET_FAIL; + } + natp = getnatp(recipient); + if (player->cnum && (getrejects(player->cnum, natp) & REJ_LOAN)) { + pr("%s is rejecting your loans.\n", cname(recipient)); + return RET_SYN; + } + natp = getnatp(player->cnum); + if (natp->nat_money + 100 > MAXLOAN) + maxloan = MAXLOAN; + else + maxloan = natp->nat_money - 100; + if (maxloan < 0) { + pr("You don't have enough money to loan!\n"); + return RET_FAIL; + } + sprintf(prompt, "Size of loan for country #%d? (max %d) ", + recipient, maxloan); + amt = onearg(player->argp[3], prompt); + if (amt <= 0) + return RET_FAIL; + if (amt > MAXLOAN) { + pr("You can only loan $%d at a time.\n", MAXLOAN); + return RET_FAIL; + } + if (amt > maxloan) { + pr("You can't afford that much.\n"); + return RET_FAIL; + } + dur = onearg(player->argp[4], "Duration? (days, max 7) "); + if (dur <= 0) + return RET_FAIL; + if (dur > 7) + return RET_FAIL; + irate = onearg(player->argp[5], "Interest rate? (from 5 to 25%) "); + if (irate > 25) + return RET_FAIL; + if (irate < 5) + return RET_FAIL; + snxtitem_all(&nstr, EF_LOAN); + while (nxtitem(&nstr, (s_char *)&loan)) { + if ((loan.l_status == LS_SIGNED) && (loan.l_lonee == player->cnum) + && (loan.l_loner == recipient)) { + pr("You already owe HIM money - how about repaying your loan?\n"); + return RET_FAIL; + } + } + snxtitem_all(&nstr, EF_LOAN); + while (nxtitem(&nstr, (s_char *)&loan)) { + if (loan.l_status == LS_FREE) + break; + } + loan.l_loner = player->cnum; + loan.l_lonee = recipient; + loan.l_status = LS_PROPOSED; + loan.l_irate = min(irate, 127); + loan.l_ldur = min(dur, 127); + loan.l_amtpaid = 0; + loan.l_amtdue = amt; + (void)time(&loan.l_lastpay); + loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay; + loan.l_uid = nstr.cur; + if (!putloan(nstr.cur, &loan)) { + pr("Couldn't save loan; get help!\n"); + return RET_SYS; + } + pr("You have offered loan %d\n", nstr.cur); + wu(0, recipient, "Country #%d has offered you a loan (#%d)\n", + player->cnum, nstr.cur); + return RET_OK; } diff --git a/src/lib/commands/offs.c b/src/lib/commands/offs.c index c2698a1d8..f94e2cb33 100644 --- a/src/lib/commands/offs.c +++ b/src/lib/commands/offs.c @@ -41,40 +41,40 @@ int offs(void) { - register int i; - struct natstr *natp; - coord xorg, yorg; - coord dx, dy; - s_char *cp; - struct natstr *np; - s_char buf[1024]; + register int i; + struct natstr *natp; + coord xorg, yorg; + coord dx, dy; + s_char *cp; + struct natstr *np; + s_char buf[1024]; - natp = getnatp(player->cnum); - xorg = natp->nat_xorg; - yorg = natp->nat_yorg; - if (!(cp = getstarg(player->argp[1], "sector or nation? ", buf))) - return RET_SYN; - if (index(cp, ',')) { /* x, y pair for offset */ - if (!sarg_xy(cp, &dx, &dy)) { - pr("Bad sector designation.\n"); - return RET_SYN; - } - xorg = dx; - yorg = dy; - } else { - /* actually nation name */ - if ((i = natarg(cp, (s_char *)0)) < 0) - return RET_SYN; - np = getnatp(i); - xorg = np->nat_xorg; - yorg = np->nat_yorg; + natp = getnatp(player->cnum); + xorg = natp->nat_xorg; + yorg = natp->nat_yorg; + if (!(cp = getstarg(player->argp[1], "sector or nation? ", buf))) + return RET_SYN; + if (index(cp, ',')) { /* x, y pair for offset */ + if (!sarg_xy(cp, &dx, &dy)) { + pr("Bad sector designation.\n"); + return RET_SYN; } - np = getnatp(player->cnum); - /* NOTE: it's OK to use %d,%d here, because we want abs coords */ - pr("Old offset was %d,%d\n", np->nat_xorg, np->nat_yorg); - np->nat_xorg = xorg; - np->nat_yorg = yorg; - putnat(np); - pr("New offset was %d,%d\n", xorg, yorg); - return RET_OK; + xorg = dx; + yorg = dy; + } else { + /* actually nation name */ + if ((i = natarg(cp, (s_char *)0)) < 0) + return RET_SYN; + np = getnatp(i); + xorg = np->nat_xorg; + yorg = np->nat_yorg; + } + np = getnatp(player->cnum); + /* NOTE: it's OK to use %d,%d here, because we want abs coords */ + pr("Old offset was %d,%d\n", np->nat_xorg, np->nat_yorg); + np->nat_xorg = xorg; + np->nat_yorg = yorg; + putnat(np); + pr("New offset was %d,%d\n", xorg, yorg); + return RET_OK; } diff --git a/src/lib/commands/orde.c b/src/lib/commands/orde.c index d2378137c..17dc90f45 100644 --- a/src/lib/commands/orde.c +++ b/src/lib/commands/orde.c @@ -72,465 +72,470 @@ int orde(void) { - int nships=0; - int diffeachship = 0; - int orders,sub,level; - int scuttling = 0; - struct nstr_item nb; - struct shpstr ship; - struct shpstr start; /* Used for checking database */ - struct ichrstr *i1; - coord p0x, p0y, p1x, p1y; - int i; - s_char *p,*p1, *dest; - s_char buf1[128]; - s_char buf[1024]; - s_char prompt[128]; - - if (!snxtitem(&nb, EF_SHIP, player->argp[1])) return RET_SYN; - while (!player->aborted && nxtitem(&nb, (s_char *)(&ship))) { - if (!player->owner || ship.shp_own == 0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, nb.cur); - continue; - } - if (opt_SAIL) { - if (*ship.shp_path) { - if (!diffeachship) - pr("Ship #%d has a \"sail\" path!\n", - ship.shp_uid); - continue; + int nships = 0; + int diffeachship = 0; + int orders, sub, level; + int scuttling = 0; + struct nstr_item nb; + struct shpstr ship; + struct shpstr start; /* Used for checking database */ + struct ichrstr *i1; + coord p0x, p0y, p1x, p1y; + int i; + s_char *p, *p1, *dest; + s_char buf1[128]; + s_char buf[1024]; + s_char prompt[128]; + + if (!snxtitem(&nb, EF_SHIP, player->argp[1])) + return RET_SYN; + while (!player->aborted && nxtitem(&nb, (s_char *)(&ship))) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, nb.cur); + continue; + } + if (opt_SAIL) { + if (*ship.shp_path) { + if (!diffeachship) + pr("Ship #%d has a \"sail\" path!\n", ship.shp_uid); + continue; + } + } + memcpy(&start, &ship, sizeof(struct shpstr)); + sprintf(prompt, + "Ship #%d, declare, cancel, suspend, resume, level? ", + ship.shp_uid); + p = getstarg(player->argp[2], prompt, buf); + if (player->aborted || !p) + return RET_FAIL; + if (!*p) { + if (!diffeachship) + return RET_FAIL; + else + continue; + } + switch (*p) { + default: + pr("Bad order type!\n"); + return RET_SYN; + case 'c': /* clear ship fields */ + ship.shp_mission = 0; + ship.shp_autonav &= ~(AN_AUTONAV + AN_STANDBY + AN_LOADING); + for (i = 0; i < TMAX; i++) { + ship.shp_tstart[i] = ' '; + ship.shp_tend[i] = ' '; + ship.shp_lstart[i] = 0; + ship.shp_lend[i] = 0; + } + break; + case 's': /* suspend ship movement */ + ship.shp_mission = 0; + ship.shp_autonav |= AN_STANDBY; + break; + case 'r': /* resume ship movement */ + ship.shp_mission = 0; + ship.shp_autonav &= ~AN_STANDBY; + break; + case 'd': /* declare path */ + orders = 0; + scuttling = 0; + /* Need location */ + if ((p = getstarg(player->argp[3], "Destination? ", buf)) == 0 + || *p == 0) + return RET_SYN; + if (!sarg_xy(p, &p0x, &p0y)) + return RET_SYN; + p1x = p0x; + p1y = p0y; + + + + if (!orders) { + p = getstarg(player->argp[4], "Second dest? ", buf); + if (!p || !*p || !strcmp(p, "-")) { + orders = 1; + pr("A one-way order has been accepted.\n"); + } else if (!strncmp(p, "s", 1)) { + if (opt_TRADESHIPS) { + if (!(mchr[(int)ship.shp_type].m_flags & M_TRADE)) { + pr("You can't auto-scuttle that ship!\n"); + return RET_SYN; + } + } else { + pr("You can't auto-scuttle that ship!\n"); + return RET_SYN; } + pr("A scuttle order has been accepted.\n"); + scuttling = 1; + } else { + if (!sarg_xy(p, &p1x, &p1y)) + return RET_SYN; + pr("A circular order has been accepted.\n"); } - memcpy(&start, &ship, sizeof(struct shpstr)); - sprintf(prompt, "Ship #%d, declare, cancel, suspend, resume, level? ", - ship.shp_uid); - p = getstarg(player->argp[2], prompt, buf); - if (player->aborted || !p) - return RET_FAIL; - if (!*p) { - if (!diffeachship) - return RET_FAIL; - else - continue; - } - switch (*p) { - default: - pr("Bad order type!\n"); + } + + /* + * Set new destination and trade type fields. + */ + ship.shp_mission = 0; + ship.shp_destx[1] = p1x; + ship.shp_desty[1] = p1y; + ship.shp_destx[0] = p0x; + ship.shp_desty[0] = p0y; + + ship.shp_autonav &= ~(AN_STANDBY + AN_SAILDIR + AN_LOADING); + ship.shp_autonav |= AN_AUTONAV; + + if (scuttling) + ship.shp_autonav |= AN_SCUTTLE; + break; + + /* set cargo levels on the ship */ + + case 'l': + /* convert player->argp[3] to an integer */ + if (player->argp[3]) + sub = atoi(player->argp[3]); + else { + sprintf(buf1, "Field (1-%d) ", TMAX); + if (getstarg(player->argp[3], buf1, buf) == 0) + return RET_SYN; + sub = atoi(buf); + } + /* check to make sure value in within range. */ + if (sub > TMAX || sub < 1) { + pr("Value must range from 1 to %d\n", TMAX); + break; + } + + /* to keep sub in range of our arrays + subtract 1 so the new range is 0-(TMAX-1) + */ + sub = sub - 1;; + + if (ship.shp_autonav & AN_AUTONAV) { + orders = 1; + dest = getstarg(player->argp[4], "Start or End? ", buf); + if (orders) { /* before dest check */ + if (!dest) + break; + switch (*dest) { + default: + pr("You must enter 'start' or 'end'\n"); return RET_SYN; - case 'c': /* clear ship fields */ - ship.shp_mission = 0; - ship.shp_autonav &= ~(AN_AUTONAV+AN_STANDBY+AN_LOADING); - for (i=0;iargp[5], "Commodity? "); + if (!i1) + break; + else { + p1 = getstarg(player->argp[6], "Amount? ", + buf); + if (!p1) + return RET_SYN; + level = atoi(p1); } + if (level < 0) { + level = 0; /* prevent negatives. */ + pr("You must use positive number! Level set to 0.\n"); + } + ship.shp_tstart[sub] = (s_char)i1->i_mnem; + ship.shp_lstart[sub] = level; + pr("Order Set \n"); break; - case 's': /* suspend ship movement */ - ship.shp_mission = 0; - ship.shp_autonav |= AN_STANDBY; - break; - case 'r': /* resume ship movement */ - ship.shp_mission = 0; - ship.shp_autonav &= ~AN_STANDBY; - break; - case 'd': /* declare path */ - orders = 0; - scuttling = 0; - /* Need location */ - if ((p=getstarg(player->argp[3],"Destination? ", buf))==0 || *p==0) - return RET_SYN; - if (!sarg_xy(p, &p0x, &p0y)) + case 's': + case 'S': + i1 = whatitem(player->argp[5], "Commodity? "); + if (!i1) + break; + else { + p1 = getstarg(player->argp[6], "Amount? ", + buf); + if (!p1) return RET_SYN; - p1x = p0x; - p1y = p0y; - - - - if (!orders) { - p = getstarg(player->argp[4],"Second dest? ", buf); - if (!p || !*p || !strcmp (p, "-")) { - orders = 1; - pr("A one-way order has been accepted.\n"); - } else if (!strncmp(p, "s", 1)) { - if (opt_TRADESHIPS) { - if (!(mchr[(int)ship.shp_type].m_flags & M_TRADE)) { - pr("You can't auto-scuttle that ship!\n"); - return RET_SYN; - } - } else { - pr("You can't auto-scuttle that ship!\n"); - return RET_SYN; - } - pr("A scuttle order has been accepted.\n"); - scuttling = 1; - } else { - if (!sarg_xy(p, &p1x, &p1y)) - return RET_SYN; - pr("A circular order has been accepted.\n"); - } + level = atoi(p1); } - - /* - * Set new destination and trade type fields. - */ - ship.shp_mission = 0; - ship.shp_destx[1] = p1x; - ship.shp_desty[1] = p1y; - ship.shp_destx[0] = p0x; - ship.shp_desty[0] = p0y; - - ship.shp_autonav &= ~(AN_STANDBY+AN_SAILDIR+AN_LOADING); - ship.shp_autonav |= AN_AUTONAV; - - if (scuttling) - ship.shp_autonav |= AN_SCUTTLE; - break; - - /* set cargo levels on the ship */ - - case 'l' : - /* convert player->argp[3] to an integer */ - if (player->argp[3]) - sub = atoi(player->argp[3]); - else { - sprintf(buf1,"Field (1-%d) ",TMAX); - if (getstarg(player->argp[3],buf1, buf) == 0) - return RET_SYN; - sub = atoi(buf); - } - /* check to make sure value in within range. */ - if (sub>TMAX || sub<1 ) { - pr("Value must range from 1 to %d\n",TMAX); - break; } - - /* to keep sub in range of our arrays - subtract 1 so the new range is 0-(TMAX-1) - */ - sub = sub - 1; ; - - if (ship.shp_autonav & AN_AUTONAV ) { - orders=1; - dest = getstarg(player->argp[4],"Start or End? ", buf); - if (orders) { /* before dest check */ - if (!dest) - break; - switch (*dest) { - default: - pr("You must enter 'start' or 'end'\n"); - return RET_SYN; - case 'e' : - case 'E' : - i1 = whatitem(player->argp[5],"Commodity? "); - if (!i1) - break; - else { - p1 = getstarg(player->argp[6],"Amount? ", buf); - if (!p1) - return RET_SYN; - level = atoi(p1); - } - if (level < 0) { - level = 0; /* prevent negatives. */ - pr("You must use positive number! Level set to 0.\n"); - } - ship.shp_tstart[sub] = (s_char)i1->i_mnem; - ship.shp_lstart[sub] = level; - pr("Order Set \n"); - break; - case 's' : - case 'S' : - i1 = whatitem(player->argp[5],"Commodity? "); - if (!i1) - break; - else { - p1 = getstarg(player->argp[6],"Amount? ", buf); - if (!p1) - return RET_SYN; - level = atoi(p1); - } - if (level < 0 ) { - level = 0; - pr("You must use positive number! Level set to 0.\n"); - } - ship.shp_tend[sub] = (s_char)i1->i_mnem; - ship.shp_lend[sub] = level; - pr("Order Set \n"); - break; - } - } - } - else - pr("You need to 'declare' a ship path first, see 'info order'\n"); - - break; - } /* end of switch (*p) */ - - - - /* - * Set loading flag if ship is already in one - * of the specified harbors and a cargo has been - * specified. - */ - - if ( ((ship.shp_x == ship.shp_destx[0]) - && (ship.shp_y == ship.shp_desty[0]) - && (ship.shp_lstart[0] != ' ')) - || ((ship.shp_x == ship.shp_desty[1]) - && (ship.shp_y == ship.shp_desty[1]) - && (ship.shp_lstart[1] != ' ')) ) { - - coord tcord; - s_char tcomm[TMAX]; - short lev[TMAX]; - int i; - - ship.shp_autonav |= AN_LOADING; - - /* swap variables, this keeps - the load_it() procedure happy. CZ - */ - tcord = ship.shp_destx[0]; - ship.shp_destx[0] = ship.shp_destx[1]; - ship.shp_destx[1] = tcord; - tcord = ship.shp_desty[0]; - ship.shp_desty[0] = ship.shp_desty[1]; - ship.shp_desty[1] = tcord; - - for(i=0;ii_mnem; + ship.shp_lend[sub] = level; + pr("Order Set \n"); + break; + } + } + } else + pr("You need to 'declare' a ship path first, see 'info order'\n"); + + break; + } /* end of switch (*p) */ + + + + /* + * Set loading flag if ship is already in one + * of the specified harbors and a cargo has been + * specified. + */ + + if (((ship.shp_x == ship.shp_destx[0]) + && (ship.shp_y == ship.shp_desty[0]) + && (ship.shp_lstart[0] != ' ')) + || ((ship.shp_x == ship.shp_desty[1]) + && (ship.shp_y == ship.shp_desty[1]) + && (ship.shp_lstart[1] != ' '))) { + + coord tcord; + s_char tcomm[TMAX]; + short lev[TMAX]; + int i; + + ship.shp_autonav |= AN_LOADING; + + /* swap variables, this keeps + the load_it() procedure happy. CZ + */ + tcord = ship.shp_destx[0]; + ship.shp_destx[0] = ship.shp_destx[1]; + ship.shp_destx[1] = tcord; + tcord = ship.shp_desty[0]; + ship.shp_desty[0] = ship.shp_desty[1]; + ship.shp_desty[1] = tcord; + + for (i = 0; i < TMAX; i++) { + lev[i] = ship.shp_lstart[i]; + ship.shp_lstart[i] = ship.shp_lend[i]; + ship.shp_lend[i] = lev[i]; + tcomm[i] = ship.shp_tstart[i]; + ship.shp_tstart[i] = ship.shp_tend[i]; + ship.shp_tend[i] = tcomm[i]; + } + } + /* + ** Write ship back to database, then give it + ** a kick down the autonav route if necessary. + */ - /* Now do a sanity check. */ - if (!check_ship_ok(&start)) - return RET_SYN; - - putship(ship.shp_uid, &ship); - nships++; - } - return RET_OK; + /* Now do a sanity check. */ + if (!check_ship_ok(&start)) + return RET_SYN; + + putship(ship.shp_uid, &ship); + nships++; + } + return RET_OK; } static void eta_calc(struct shpstr *sp, s_char *path, int *len, int *nupdates) { - extern int etu_per_update; - extern float ship_mob_scale; - struct mchrstr *mcp; - double mobcost, mobil; - int i; - - i = strlen(path); - *len = i; - *nupdates = 1; - - mcp = &mchr[(int)sp->shp_type]; - mobcost = sp->shp_effic * 0.01 * sp->shp_speed; - mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost)); - mobil = sp->shp_mobil; - while (i) { - if (mobil > 0) { - mobil -= mobcost; - i--; - } else { - mobil += (ship_mob_scale * (float)etu_per_update); - (*nupdates)++; - } + extern int etu_per_update; + extern float ship_mob_scale; + struct mchrstr *mcp; + double mobcost, mobil; + int i; + + i = strlen(path); + *len = i; + *nupdates = 1; + + mcp = &mchr[(int)sp->shp_type]; + mobcost = sp->shp_effic * 0.01 * sp->shp_speed; + mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost)); + mobil = sp->shp_mobil; + while (i) { + if (mobil > 0) { + mobil -= mobcost; + i--; + } else { + mobil += (ship_mob_scale * (float)etu_per_update); + (*nupdates)++; } + } } int qorde(void) { - int nships=0; - int i; - struct nstr_item nb; - struct shpstr ship; - - if (!snxtitem(&nb, EF_SHIP, player->argp[1])) return RET_SYN; - while (nxtitem(&nb, (s_char *)(&ship))) { - if (!player->owner || ship.shp_own==0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, nb.cur); - continue; - } + int nships = 0; + int i; + struct nstr_item nb; + struct shpstr ship; + + if (!snxtitem(&nb, EF_SHIP, player->argp[1])) + return RET_SYN; + while (nxtitem(&nb, (s_char *)(&ship))) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, nb.cur); + continue; + } - if ((ship.shp_autonav & AN_AUTONAV) || - (ship.shp_path[0] && opt_SAIL)) { - if (!nships) { /* 1st ship, print banner */ - if (player->god) pr("own "); - pr("shp# ship type "); - pr("[Starting] (Ending) \n"); - } - nships++; - if (player->god) pr("%3d ", ship.shp_own); - pr("%4d", nb.cur); - pr(" %-16.16s", mchr[(int)ship.shp_type].m_name); + if ((ship.shp_autonav & AN_AUTONAV) || + (ship.shp_path[0] && opt_SAIL)) { + if (!nships) { /* 1st ship, print banner */ + if (player->god) + pr("own "); + pr("shp# ship type "); + pr("[Starting] (Ending) \n"); + } + nships++; + if (player->god) + pr("%3d ", ship.shp_own); + pr("%4d", nb.cur); + pr(" %-16.16s", mchr[(int)ship.shp_type].m_name); + } + if (ship.shp_autonav & AN_AUTONAV) { + + pr(" ["); + for (i = 0; i < TMAX; i++) { + if (ship.shp_tend[i] != ' ' && ship.shp_lend[i] != 0) { + pr("%d-", i + 1); + pr("%c", ship.shp_tend[i]); + pr(":"); + pr("%d ", ship.shp_lend[i]); } - if (ship.shp_autonav & AN_AUTONAV){ - - pr(" ["); - for (i=0;igod) - pr(" "); - pr(" %s\n",ship.shp_name); - } - } + if (opt_SHIPNAMES) { + if ((ship.shp_autonav & AN_AUTONAV) || + (ship.shp_path[0] && opt_SAIL)) { + if (ship.shp_name[0] != 0) { + if (player->god) + pr(" "); + pr(" %s\n", ship.shp_name); } + } } - if (!nships) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - } else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + } + if (!nships) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } + /* Chad Zabel 1-15-94 * New command added to display autonav stats. - */ + */ int sorde(void) { - int nships=0; - int len, updates; - s_char *c; - struct nstr_item nb; - struct shpstr ship; - s_char buf[1024]; - - if (!snxtitem(&nb, EF_SHIP, player->argp[1])) return RET_SYN; - while (nxtitem(&nb, (s_char *)(&ship))) { - if (!player->owner || ship.shp_own==0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, nb.cur); - continue; - } - if ((ship.shp_autonav & AN_AUTONAV) || - (ship.shp_path[0] && opt_SAIL)) { - if (!nships) { /* 1st ship, print banner */ - if (player->god) pr("own "); - pr("shp# ship type x,y "); - pr("start end "); - pr("len eta\n"); - } - nships++; - if (player->god) pr("%3d ", ship.shp_own); - pr("%4d", nb.cur); - pr(" %-16.16s", mchr[(int)ship.shp_type].m_name); - prxy(" %3d,%-3d", ship.shp_x, ship.shp_y, player->cnum); - } - if (ship.shp_autonav & AN_AUTONAV){ - /* Destination 1 */ - prxy(" %3d,%-3d", ship.shp_destx[1], - ship.shp_desty[1], player->cnum); - - /* Destination 2 */ - if ( (ship.shp_destx[1]!=ship.shp_destx[0]) - || (ship.shp_desty[1]!=ship.shp_desty[0]) ) { - prxy(" %2d,%-2d",ship.shp_destx[0], - ship.shp_desty[0], player->cnum); - } else pr(" "); - - if (ship.shp_autonav & AN_STANDBY) - pr(" suspended"); - else if (ship.shp_autonav & AN_LOADING) - pr(" loading"); - else { - /* ETA calculation */ - - c = BestShipPath(buf, ship.shp_x, - ship.shp_y, ship.shp_destx[0], - ship.shp_desty[0], ship.shp_own); - if (!c || !*c) - pr("no route possible"); - else if (*c == 'h') - pr("has arrived"); - else if (*c == '?') - pr("route too long"); - else { - /* distance to destination */ - eta_calc(&ship, c, &len, &updates); - pr(" %3d %4d", len, updates); - } - } - if (ship.shp_autonav & AN_SCUTTLE) - pr(" (scuttling)"); - pr("\n"); + int nships = 0; + int len, updates; + s_char *c; + struct nstr_item nb; + struct shpstr ship; + s_char buf[1024]; + + if (!snxtitem(&nb, EF_SHIP, player->argp[1])) + return RET_SYN; + while (nxtitem(&nb, (s_char *)(&ship))) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, nb.cur); + continue; + } + if ((ship.shp_autonav & AN_AUTONAV) || + (ship.shp_path[0] && opt_SAIL)) { + if (!nships) { /* 1st ship, print banner */ + if (player->god) + pr("own "); + pr("shp# ship type x,y "); + pr("start end "); + pr("len eta\n"); + } + nships++; + if (player->god) + pr("%3d ", ship.shp_own); + pr("%4d", nb.cur); + pr(" %-16.16s", mchr[(int)ship.shp_type].m_name); + prxy(" %3d,%-3d", ship.shp_x, ship.shp_y, player->cnum); + } + if (ship.shp_autonav & AN_AUTONAV) { + /* Destination 1 */ + prxy(" %3d,%-3d", ship.shp_destx[1], + ship.shp_desty[1], player->cnum); + + /* Destination 2 */ + if ((ship.shp_destx[1] != ship.shp_destx[0]) + || (ship.shp_desty[1] != ship.shp_desty[0])) { + prxy(" %2d,%-2d", ship.shp_destx[0], + ship.shp_desty[0], player->cnum); + } else + pr(" "); + + if (ship.shp_autonav & AN_STANDBY) + pr(" suspended"); + else if (ship.shp_autonav & AN_LOADING) + pr(" loading"); + else { + /* ETA calculation */ + + c = BestShipPath(buf, ship.shp_x, + ship.shp_y, ship.shp_destx[0], + ship.shp_desty[0], ship.shp_own); + if (!c || !*c) + pr("no route possible"); + else if (*c == 'h') + pr("has arrived"); + else if (*c == '?') + pr("route too long"); + else { + /* distance to destination */ + eta_calc(&ship, c, &len, &updates); + pr(" %3d %4d", len, updates); } - if (opt_SHIPNAMES) { - if ((ship.shp_autonav & AN_AUTONAV) || - (ship.shp_path[0] && opt_SAIL)) { - if (!(ship.shp_autonav & AN_AUTONAV)) - pr("\n"); - if (ship.shp_name[0] != 0) { - if (player->god) - pr(" "); - pr(" %s\n",ship.shp_name); - } - } + } + if (ship.shp_autonav & AN_SCUTTLE) + pr(" (scuttling)"); + pr("\n"); + } + if (opt_SHIPNAMES) { + if ((ship.shp_autonav & AN_AUTONAV) || + (ship.shp_path[0] && opt_SAIL)) { + if (!(ship.shp_autonav & AN_AUTONAV)) + pr("\n"); + if (ship.shp_name[0] != 0) { + if (player->god) + pr(" "); + pr(" %s\n", ship.shp_name); } + } } - if (!nships) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - } else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + } + if (!nships) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } - - diff --git a/src/lib/commands/orig.c b/src/lib/commands/orig.c index c50eb7d43..69793dccb 100644 --- a/src/lib/commands/orig.c +++ b/src/lib/commands/orig.c @@ -42,24 +42,25 @@ int orig(void) { - struct sctstr sect; - s_char *p; - coord x, y; - s_char buf[1024]; - struct natstr *np; + struct sctstr sect; + s_char *p; + coord x, y; + s_char buf[1024]; + struct natstr *np; - if ((p = getstarg(player->argp[1], "New origin location : ", buf)) == 0) { - return RET_SYN; - } - if (!sarg_xy(p, &x, &y)) - return RET_SYN; - if (!getsect(x, y, §)) - return RET_SYN; - pr("Origin at %s (old system) is now at 0,0 (new system).\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - np = getnatp(player->cnum); - np->nat_xorg = sect.sct_x; - np->nat_yorg = sect.sct_y; - putnat(np); - return RET_OK; + if ((p = + getstarg(player->argp[1], "New origin location : ", buf)) == 0) { + return RET_SYN; + } + if (!sarg_xy(p, &x, &y)) + return RET_SYN; + if (!getsect(x, y, §)) + return RET_SYN; + pr("Origin at %s (old system) is now at 0,0 (new system).\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + np = getnatp(player->cnum); + np->nat_xorg = sect.sct_x; + np->nat_yorg = sect.sct_y; + putnat(np); + return RET_OK; } diff --git a/src/lib/commands/para.c b/src/lib/commands/para.c index 58fe59982..4fcc4d767 100644 --- a/src/lib/commands/para.c +++ b/src/lib/commands/para.c @@ -57,157 +57,162 @@ static int paradrop(struct emp_qelem *list, coord x, coord y); int para(void) { - s_char *p; - int mission_flags; - int tech; - coord tx, ty; - coord ax, ay; - int ap_to_target; - s_char flightpath[MAX_PATH_LEN]; - struct nstr_item ni_bomb; - struct nstr_item ni_esc; - coord x, y; - struct sctstr target; - struct emp_qelem bomb_list; - struct emp_qelem esc_list; - int wantflags; - struct sctstr ap_sect; - s_char buf[1024]; - - wantflags = P_P; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) - return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); - if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 || *p == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) - return RET_SYN; - if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && - getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { - pr("Assembly point not owned by you or an ally!\n"); - return RET_SYN; - } - ax = x; - ay = y; - if (getpath(flightpath, player->argp[4], ax, ay, 0, - 0, 0, P_FLYING) == 0 || *flightpath == 0) - return RET_SYN; - tx = ax; - ty = ay; - (void) pathtoxy(flightpath, &tx, &ty, fcost); + s_char *p; + int mission_flags; + int tech; + coord tx, ty; + coord ax, ay; + int ap_to_target; + s_char flightpath[MAX_PATH_LEN]; + struct nstr_item ni_bomb; + struct nstr_item ni_esc; + coord x, y; + struct sctstr target; + struct emp_qelem bomb_list; + struct emp_qelem esc_list; + int wantflags; + struct sctstr ap_sect; + s_char buf[1024]; + + wantflags = P_P; + if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + return RET_SYN; + if (!snxtitem + (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) + pr("No escorts...\n"); + if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 + || *p == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) + return RET_SYN; + if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && + getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { + pr("Assembly point not owned by you or an ally!\n"); + return RET_SYN; + } + ax = x; + ay = y; + if (getpath(flightpath, player->argp[4], ax, ay, 0, + 0, 0, P_FLYING) == 0 || *flightpath == 0) + return RET_SYN; + tx = ax; + ty = ay; + (void)pathtoxy(flightpath, &tx, &ty, fcost); + getsect(tx, ty, &target); + pr("LZ is %s\n", xyas(tx, ty, player->cnum)); + ap_to_target = strlen(flightpath); + if (*(flightpath + strlen(flightpath) - 1) == 'h') + ap_to_target--; + pr("range to target is %d\n", ap_to_target); + /* + * select planes within range + */ + pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, + 2, P_C | wantflags, P_M | P_O); + pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, + 2, P_ESC | P_F, P_M | P_O); + /* + * now arm and equip the bombers, transports, whatever. + * tech is stored in high 16 bits of mission_flags. + * yuck. + */ + tech = 0; + mission_flags = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + mission_flags = + pln_arm(&bomb_list, 2 * ap_to_target, 'a', &ichr[I_MILIT], 0, + mission_flags, &tech); + if (QEMPTY(&bomb_list)) { + pr("No planes could be equipped for the mission.\n"); + return RET_FAIL; + } + mission_flags = + pln_arm(&esc_list, 2 * ap_to_target, 'a', &ichr[I_MILIT], + P_ESC | P_F, mission_flags, &tech); + ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, + 0, 0, 0); + if (QEMPTY(&bomb_list)) { + pr("No planes got through fighter defenses\n"); + } else { getsect(tx, ty, &target); - pr("LZ is %s\n", xyas(tx, ty, player->cnum)); - ap_to_target = strlen(flightpath); - if (*(flightpath+strlen(flightpath)-1) == 'h') - ap_to_target--; - pr("range to target is %d\n", ap_to_target); - /* - * select planes within range - */ - pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, - 2, P_C|wantflags, P_M|P_O); - pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, - 2, P_ESC|P_F, P_M|P_O); - /* - * now arm and equip the bombers, transports, whatever. - * tech is stored in high 16 bits of mission_flags. - * yuck. - */ - tech=0; - mission_flags = 0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - mission_flags = pln_arm(&bomb_list, 2*ap_to_target, 'a', &ichr[I_MILIT], - 0, mission_flags,&tech); - if (QEMPTY(&bomb_list)) { - pr("No planes could be equipped for the mission.\n"); - return RET_FAIL; - } - mission_flags = pln_arm(&esc_list, 2*ap_to_target, 'a', &ichr[I_MILIT], - P_ESC|P_F, mission_flags,&tech); - ac_encounter(&bomb_list,&esc_list,ax,ay,flightpath,mission_flags,0,0,0); - if (QEMPTY(&bomb_list)) { - pr("No planes got through fighter defenses\n"); - } else { - getsect(tx, ty, &target); - paradrop(&bomb_list, tx, ty); - } - pln_put(&bomb_list); - pln_put(&esc_list); - return RET_OK; + paradrop(&bomb_list, tx, ty); + } + pln_put(&bomb_list); + pln_put(&esc_list); + return RET_OK; } static int paradrop(struct emp_qelem *list, coord x, coord y) { - struct combat off[1]; /* assaulting ship or sector */ - struct combat def[1]; /* defending ship */ - struct emp_qelem olist; /* assaulting units */ - struct emp_qelem dlist; /* defending units */ - int ototal; /* total assaulting strength */ - int a_engineer = 0; /* assaulter engineers are present */ - int a_spy = 0; /* the best assaulter scout */ - double osupport = 1.0; /* assault support */ - double dsupport = 1.0; /* defense support */ - struct plist *plp; - struct emp_qelem *qp; - - /* Check for valid attack */ - - att_combat_init(def, EF_SECTOR); - def->x = x; - def->y = y; - if (att_abort(A_PARA, 0, def)) - return RET_FAIL; - - /* Show what we're air-assaulting, and check treaties */ - - if (att_show(def)) - return RET_FAIL; - - /* set what we're air-assaulting with */ - - emp_initque(&olist); - att_combat_init(off, EF_PLANE); - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *) qp; - if (plp->pcp->pl_flags & (P_V|P_C)) - off->troops += plp->misc; - } - off->mil = off->troops; - if (att_abort(A_PARA, off, def)) { - pr("Air-Assault aborted\n"); - return RET_OK; - } - - /* Get ototal */ - - ototal = att_estimate_defense(A_PARA, off, &olist, def, a_spy); - if (att_abort(A_PARA, off, def)) { - pr("Air-assault aborted\n"); - return RET_OK; - } - - /* Get the defense */ - - att_get_defense(&olist, def, &dlist, a_spy, ototal); - - /* Get defender support */ - - att_get_support(A_PARA, 0, 0, 0, 0, - &olist, off, &dlist, def, &osupport, &dsupport, - a_engineer); - - if (att_abort(A_PARA, off, def)) { - pr("Air-assault aborted\n"); - return RET_OK; - } - /* - * Death, carnage, and destruction. - */ - - att_fight(A_PARA,off,&olist,osupport,def,&dlist,dsupport); + struct combat off[1]; /* assaulting ship or sector */ + struct combat def[1]; /* defending ship */ + struct emp_qelem olist; /* assaulting units */ + struct emp_qelem dlist; /* defending units */ + int ototal; /* total assaulting strength */ + int a_engineer = 0; /* assaulter engineers are present */ + int a_spy = 0; /* the best assaulter scout */ + double osupport = 1.0; /* assault support */ + double dsupport = 1.0; /* defense support */ + struct plist *plp; + struct emp_qelem *qp; + + /* Check for valid attack */ + + att_combat_init(def, EF_SECTOR); + def->x = x; + def->y = y; + if (att_abort(A_PARA, 0, def)) + return RET_FAIL; + + /* Show what we're air-assaulting, and check treaties */ + + if (att_show(def)) + return RET_FAIL; + + /* set what we're air-assaulting with */ + + emp_initque(&olist); + att_combat_init(off, EF_PLANE); + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if (plp->pcp->pl_flags & (P_V | P_C)) + off->troops += plp->misc; + } + off->mil = off->troops; + if (att_abort(A_PARA, off, def)) { + pr("Air-Assault aborted\n"); + return RET_OK; + } + + /* Get ototal */ + ototal = att_estimate_defense(A_PARA, off, &olist, def, a_spy); + if (att_abort(A_PARA, off, def)) { + pr("Air-assault aborted\n"); return RET_OK; + } + + /* Get the defense */ + + att_get_defense(&olist, def, &dlist, a_spy, ototal); + + /* Get defender support */ + + att_get_support(A_PARA, 0, 0, 0, 0, + &olist, off, &dlist, def, &osupport, &dsupport, + a_engineer); + + if (att_abort(A_PARA, off, def)) { + pr("Air-assault aborted\n"); + return RET_OK; + } + /* + * Death, carnage, and destruction. + */ + + att_fight(A_PARA, off, &olist, osupport, def, &dlist, dsupport); + + return RET_OK; } diff --git a/src/lib/commands/path.c b/src/lib/commands/path.c index ccd2f80db..963a2fe57 100644 --- a/src/lib/commands/path.c +++ b/src/lib/commands/path.c @@ -50,79 +50,79 @@ int path(void) { - struct nstr_sect ns; - struct natstr *natp; - struct range absrange; - struct range relrange; - struct sctstr sect, dsect; - coord cx, cy; - int i; - int y; - s_char *pp, *p, *BestDistPath(); - /* Note this is not re-entrant anyway, so we keep the buffers - around */ - static s_char *mapbuf = (s_char *)0; - static s_char **map = (s_char **)0; - double move_cost; - s_char buf[1024]; + struct nstr_sect ns; + struct natstr *natp; + struct range absrange; + struct range relrange; + struct sctstr sect, dsect; + coord cx, cy; + int i; + int y; + s_char *pp, *p, *BestDistPath(); + /* Note this is not re-entrant anyway, so we keep the buffers + around */ + static s_char *mapbuf = (s_char *)0; + static s_char **map = (s_char **)0; + double move_cost; + s_char buf[1024]; - if (!(p = getstarg(player->argp[1], "from sector : ", buf)) || - !sarg_xy(p, &cx, &cy) || - !getsect(cx, cy, §)) - return RET_SYN; - if ((sect.sct_own != player->cnum) && !player->god){ - pr("Not yours\n"); - return RET_FAIL; + if (!(p = getstarg(player->argp[1], "from sector : ", buf)) || + !sarg_xy(p, &cx, &cy) || !getsect(cx, cy, §)) + return RET_SYN; + if ((sect.sct_own != player->cnum) && !player->god) { + pr("Not yours\n"); + return RET_FAIL; + } + getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect); + pp = BestDistPath(buf, §, &dsect, &move_cost, MOB_ROAD); + if (pp == (s_char *)0) { + pr("No path possible from %s to distribution sector %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), + xyas(dsect.sct_x, dsect.sct_y, player->cnum)); + return RET_FAIL; + } + if (!mapbuf) + mapbuf = + (s_char *)malloc((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char)); + if (!map) { + map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (map && mapbuf) { + for (i = 0; i < WORLD_Y; i++) + map[i] = &mapbuf[MAPWIDTH(3) * i]; + } else if (map) { + free((s_char *)map); + map = (s_char **)0; } - getsect(sect.sct_dist_x,sect.sct_dist_y,&dsect); - pp = BestDistPath(buf, §,&dsect,&move_cost,MOB_ROAD); - if (pp == (s_char *)0){ - pr("No path possible from %s to distribution sector %s\n", - xyas(sect.sct_x,sect.sct_y,player->cnum), - xyas(dsect.sct_x,dsect.sct_y,player->cnum)); - return RET_FAIL; - } - if (!mapbuf) - mapbuf = (s_char *)malloc((WORLD_Y*MAPWIDTH(3))*sizeof(s_char)); - if (!map) { - map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (map && mapbuf) { - for (i = 0; i < WORLD_Y; i++) - map[i] = &mapbuf[MAPWIDTH(3) * i]; - } else if (map) { - free((s_char *)map); - map = (s_char **)0; - } - } - if (!mapbuf || !map) { - pr("Memory error, tell the deity.\n"); - logerror("malloc failed in path\n"); - return RET_FAIL; - } - pathrange(cx, cy, pp, 1, &absrange); - snxtsct_area(&ns, &absrange); - natp = getnatp(player->cnum); - xyrelrange(natp, &absrange, &relrange); - blankfill((s_char *)mapbuf, &ns.range, 3); - while (*pp && (i = chkdir(*pp, DIR_STOP, DIR_LAST)) >= 0) { - bcopy(routech[i][0], &map[deltay(cy, ns.range.ly)] - [deltax(cx, ns.range.lx)*2], 3); - cx += diroff[i][0]; - cy += diroff[i][1]; - ++pp; - } - border(&relrange, " ", " "); - while (nxtsct(&ns, §)) { - if (!player->owner) - continue; - map[ns.dy][ns.dx*2+1] = dchr[sect.sct_type].d_mnem; - } - for (y=ns.range.ly, i=0; i < ns.range.height; y++, i++) { - cy = yrel(natp, y); - pr("%4d %s %-4d\n", cy, map[i], cy); - if (y >= WORLD_Y) - y -= WORLD_Y; - } - border(&relrange, " ", " "); - return RET_OK; + } + if (!mapbuf || !map) { + pr("Memory error, tell the deity.\n"); + logerror("malloc failed in path\n"); + return RET_FAIL; + } + pathrange(cx, cy, pp, 1, &absrange); + snxtsct_area(&ns, &absrange); + natp = getnatp(player->cnum); + xyrelrange(natp, &absrange, &relrange); + blankfill((s_char *)mapbuf, &ns.range, 3); + while (*pp && (i = chkdir(*pp, DIR_STOP, DIR_LAST)) >= 0) { + bcopy(routech[i][0], &map[deltay(cy, ns.range.ly)] + [deltax(cx, ns.range.lx) * 2], 3); + cx += diroff[i][0]; + cy += diroff[i][1]; + ++pp; + } + border(&relrange, " ", " "); + while (nxtsct(&ns, §)) { + if (!player->owner) + continue; + map[ns.dy][ns.dx * 2 + 1] = dchr[sect.sct_type].d_mnem; + } + for (y = ns.range.ly, i = 0; i < ns.range.height; y++, i++) { + cy = yrel(natp, y); + pr("%4d %s %-4d\n", cy, map[i], cy); + if (y >= WORLD_Y) + y -= WORLD_Y; + } + border(&relrange, " ", " "); + return RET_OK; } diff --git a/src/lib/commands/payo.c b/src/lib/commands/payo.c index 3c82204f2..9b1c8c532 100644 --- a/src/lib/commands/payo.c +++ b/src/lib/commands/payo.c @@ -47,85 +47,83 @@ int payo(void) { - struct sctstr sect; - int nships; - struct nstr_item ni; - struct shpstr ship; - struct mchrstr *mp; - int dist; - float cash=0.0; - extern int trade_1_dist; /* less than this gets no money */ - extern int trade_2_dist; /* less than this gets trade_1 money */ - extern int trade_3_dist; /* less than this gets trade_2 money */ - extern float trade_1; /* return on trade_1 distance */ - extern float trade_2; /* return on trade_2 distance */ - extern float trade_3; /* return on trade_3 distance */ - extern float trade_ally_bonus; /* 20% bonus for trading with allies */ + struct sctstr sect; + int nships; + struct nstr_item ni; + struct shpstr ship; + struct mchrstr *mp; + int dist; + float cash = 0.0; + extern int trade_1_dist; /* less than this gets no money */ + extern int trade_2_dist; /* less than this gets trade_1 money */ + extern int trade_3_dist; /* less than this gets trade_2 money */ + extern float trade_1; /* return on trade_1 distance */ + extern float trade_2; /* return on trade_2 distance */ + extern float trade_3; /* return on trade_3 distance */ + extern float trade_ally_bonus; /* 20% bonus for trading with allies */ - if (!opt_TRADESHIPS) { - pr("Tradeships are not enabled.\n"); - return RET_FAIL; - } - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; + if (!opt_TRADESHIPS) { + pr("Tradeships are not enabled.\n"); + return RET_FAIL; + } + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; - nships = 0; - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner || ship.shp_own == 0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, ni.cur); - continue; - } - mp = &mchr[(int)ship.shp_type]; + nships = 0; + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur); + continue; + } + mp = &mchr[(int)ship.shp_type]; - if (!(mp->m_flags & M_TRADE)) - continue; + if (!(mp->m_flags & M_TRADE)) + continue; - if (nships++ == 0) { - if (player->god) - pr("own "); - pr("shp# ship type orig x,y x,y dist $$\n"); - } - if (player->god) - pr("%3d ", ship.shp_own); - pr("%4d ", ni.cur); - pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); - prxy("%4d,%-4d ", ship.shp_orig_x, - ship.shp_orig_y, player->cnum); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + if (nships++ == 0) { + if (player->god) + pr("own "); + pr("shp# ship type orig x,y x,y dist $$\n"); + } + if (player->god) + pr("%3d ", ship.shp_own); + pr("%4d ", ni.cur); + pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); + prxy("%4d,%-4d ", ship.shp_orig_x, ship.shp_orig_y, player->cnum); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); - getsect(ship.shp_x,ship.shp_y,§); + getsect(ship.shp_x, ship.shp_y, §); - dist = mapdist(ship.shp_x, ship.shp_y, - ship.shp_orig_x, ship.shp_orig_y); - pr("%4d ", dist); + dist = mapdist(ship.shp_x, ship.shp_y, + ship.shp_orig_x, ship.shp_orig_y); + pr("%4d ", dist); - if (dist < trade_1_dist) - cash = 0; - else if (dist < trade_2_dist) - cash = (1.0 + trade_1*((float)dist)); - else if (dist < trade_3_dist) - cash = (1.0 + trade_2*((float)dist)); - else - cash = (1.0 + trade_3*((float)dist)); + if (dist < trade_1_dist) + cash = 0; + else if (dist < trade_2_dist) + cash = (1.0 + trade_1 * ((float)dist)); + else if (dist < trade_3_dist) + cash = (1.0 + trade_2 * ((float)dist)); + else + cash = (1.0 + trade_3 * ((float)dist)); - cash *= mp->m_cost; - cash *= (((float)ship.shp_effic) / 100.0); + cash *= mp->m_cost; + cash *= (((float)ship.shp_effic) / 100.0); - if (sect.sct_own && (sect.sct_own != ship.shp_own)) - cash *= (1.0 + trade_ally_bonus); - pr("$%6.2f\n",cash); - } - if (nships == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + if (sect.sct_own && (sect.sct_own != ship.shp_own)) + cash *= (1.0 + trade_ally_bonus); + pr("$%6.2f\n", cash); + } + if (nships == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } diff --git a/src/lib/commands/pboa.c b/src/lib/commands/pboa.c index 975c921a8..55879a2c3 100644 --- a/src/lib/commands/pboa.c +++ b/src/lib/commands/pboa.c @@ -39,18 +39,18 @@ int pboa(void) { - struct sctstr sect; + struct sctstr sect; struct nstr_item np; - struct plnstr plane; + struct plnstr plane; if (!snxtitem(&np, EF_PLANE, player->argp[1])) return RET_SYN; np.flags = 0; while (nxtitem(&np, (s_char *)&plane)) { getsect(plane.pln_x, plane.pln_y, §); - if (sect.sct_own != player->cnum) continue; + if (sect.sct_own != player->cnum) + continue; takeover_plane(&plane, player->cnum); } return RET_OK; } - diff --git a/src/lib/commands/pdump.c b/src/lib/commands/pdump.c index d87e6eea2..aaeaae091 100644 --- a/src/lib/commands/pdump.c +++ b/src/lib/commands/pdump.c @@ -48,171 +48,265 @@ int pdump(void) { - int nplanes; - struct nstr_item np; - struct plnstr plane; - int field[128]; - struct natstr *natp; - int n,i; - time_t now; + int nplanes; + struct nstr_item np; + struct plnstr plane; + int field[128]; + struct natstr *natp; + int n, i; + time_t now; - if (!snxtitem(&np, EF_PLANE, player->argp[1])) - return RET_SYN; - prdate(); + if (!snxtitem(&np, EF_PLANE, player->argp[1])) + return RET_SYN; + prdate(); - if (!player->argp[2]) { - for (n = 1; n <= 32; n++) field[n-1] = n; - field[n-1] = 0; - } else { - n = 2; - i = 0; - while (player->argp[n]) { + if (!player->argp[2]) { + for (n = 1; n <= 32; n++) + field[n - 1] = n; + field[n - 1] = 0; + } else { + n = 2; + i = 0; + while (player->argp[n]) { - if (!strcmp("type",player->argp[n])) { - field[i++] = 1; - } else if (!strcmp("x",player->argp[n])) { - field[i++] = 2; - } else if (!strcmp("y",player->argp[n])) { - field[i++] = 3; - } else if (!strcmp("wing",player->argp[n])) { - field[i++] = 4; - } else if (!strcmp("eff",player->argp[n])) { - field[i++] = 5; - } else if (!strcmp("mob",player->argp[n])) { - field[i++] = 6; - } else if (!strcmp("tech",player->argp[n])) { - field[i++] = 7; - } else if (!strcmp("att",player->argp[n])) { - field[i++] = 8; - } else if (!strcmp("def",player->argp[n])) { - field[i++] = 9; - } else if (!strcmp("acc",player->argp[n])) { - field[i++] = 10; - } else if (!strcmp("react",player->argp[n])) { - field[i++] = 11; - } else if (!strcmp("range",player->argp[n])) { - field[i++] = 12; - } else if (!strcmp("load",player->argp[n])) { - field[i++] = 13; - } else if (!strcmp("fuel",player->argp[n])) { - field[i++] = 14; - } else if (!strcmp("hard",player->argp[n])) { - field[i++] = 15; - } else if (!strcmp("ship",player->argp[n])) { - field[i++] = 16; - } else if (!strcmp("land",player->argp[n])) { - field[i++] = 17; - } else if (!strcmp("laun",player->argp[n])) { - field[i++] = 18; - } else if (!strcmp("orb",player->argp[n])) { - field[i++] = 19; - } else if (!strcmp("nuke",player->argp[n])) { - field[i++] = 20; - } else if (!strcmp("grd",player->argp[n])) { - field[i++] = 21; - } else { - pr("Unrecognized field %s\n",player->argp[n]); - } - if (n++ > 100) { - pr("Too many fields\n"); - return RET_FAIL; - } - } - field[i] = 0; + if (!strcmp("type", player->argp[n])) { + field[i++] = 1; + } else if (!strcmp("x", player->argp[n])) { + field[i++] = 2; + } else if (!strcmp("y", player->argp[n])) { + field[i++] = 3; + } else if (!strcmp("wing", player->argp[n])) { + field[i++] = 4; + } else if (!strcmp("eff", player->argp[n])) { + field[i++] = 5; + } else if (!strcmp("mob", player->argp[n])) { + field[i++] = 6; + } else if (!strcmp("tech", player->argp[n])) { + field[i++] = 7; + } else if (!strcmp("att", player->argp[n])) { + field[i++] = 8; + } else if (!strcmp("def", player->argp[n])) { + field[i++] = 9; + } else if (!strcmp("acc", player->argp[n])) { + field[i++] = 10; + } else if (!strcmp("react", player->argp[n])) { + field[i++] = 11; + } else if (!strcmp("range", player->argp[n])) { + field[i++] = 12; + } else if (!strcmp("load", player->argp[n])) { + field[i++] = 13; + } else if (!strcmp("fuel", player->argp[n])) { + field[i++] = 14; + } else if (!strcmp("hard", player->argp[n])) { + field[i++] = 15; + } else if (!strcmp("ship", player->argp[n])) { + field[i++] = 16; + } else if (!strcmp("land", player->argp[n])) { + field[i++] = 17; + } else if (!strcmp("laun", player->argp[n])) { + field[i++] = 18; + } else if (!strcmp("orb", player->argp[n])) { + field[i++] = 19; + } else if (!strcmp("nuke", player->argp[n])) { + field[i++] = 20; + } else if (!strcmp("grd", player->argp[n])) { + field[i++] = 21; + } else { + pr("Unrecognized field %s\n", player->argp[n]); + } + if (n++ > 100) { + pr("Too many fields\n"); + return RET_FAIL; + } } + field[i] = 0; + } + if (player->god) + pr(" "); + time(&now); + pr("DUMP PLANES %d\n", now); + if (player->god) + pr("own "); + pr("id"); + n = 0; + while (field[n]) { + switch (field[n]) { + case 1: + pr(" type"); + break; + case 2: + pr(" x"); + break; + case 3: + pr(" y"); + break; + case 4: + pr(" wing"); + break; + case 5: + pr(" eff"); + break; + case 6: + pr(" mob"); + break; + case 7: + pr(" tech"); + break; + case 8: + pr(" att"); + break; + case 9: + pr(" def"); + break; + case 10: + pr(" acc"); + break; + case 11: + pr(" react"); + break; + case 12: + pr(" range"); + break; + case 13: + pr(" load"); + break; + case 14: + pr(" fuel"); + break; + case 15: + pr(" hard"); + break; + case 16: + pr(" ship"); + break; + case 17: + pr(" land"); + break; + case 18: + pr(" laun"); + break; + case 19: + pr(" orb"); + break; + case 20: + pr(" nuke"); + break; + case 21: + pr(" grd"); + break; + } + n++; + } + pr("\n"); + + nplanes = 0; + natp = getnatp(player->cnum); + while (nxtitem(&np, (s_char *)&plane)) { + if (!player->owner || plane.pln_own == 0) + continue; + nplanes++; if (player->god) - pr(" "); - time(&now); - pr("DUMP PLANES %d\n", now); - if (player->god) - pr("own "); - pr("id"); + pr("%3d ", plane.pln_own); + pr("%d", np.cur); n = 0; while (field[n]) { - switch (field[n]) { - case 1: pr(" type"); break; - case 2: pr(" x"); break; - case 3: pr(" y"); break; - case 4: pr(" wing"); break; - case 5: pr(" eff"); break; - case 6: pr(" mob"); break; - case 7: pr(" tech"); break; - case 8: pr(" att"); break; - case 9: pr(" def"); break; - case 10: pr(" acc"); break; - case 11: pr(" react"); break; - case 12: pr(" range"); break; - case 13: pr(" load"); break; - case 14: pr(" fuel"); break; - case 15: pr(" hard"); break; - case 16: pr(" ship"); break; - case 17: pr(" land"); break; - case 18: pr(" laun"); break; - case 19: pr(" orb"); break; - case 20: pr(" nuke"); break; - case 21: pr(" grd"); break; - } - n++; - } - pr("\n"); - - nplanes = 0; - natp = getnatp(player->cnum); - while (nxtitem(&np, (s_char *)&plane)) { - if (!player->owner || plane.pln_own == 0) - continue; - nplanes++; - if (player->god) - pr("%3d ", plane.pln_own); - pr("%d", np.cur); - n = 0; - while (field[n]) { - switch (field[n++]) { - case 1: pr(" %0.4s", plchr[(int)plane.pln_type].pl_name); break; - case 2: pr(" %d", xrel(natp, plane.pln_x)); break; - case 3: pr(" %d", yrel(natp, plane.pln_y)); break; - case 4: if (plane.pln_wing == ' ') - pr(" ~"); - else - pr(" %c", plane.pln_wing); - break; - case 5: pr(" %d", plane.pln_effic); break; - case 6: pr(" %d", plane.pln_mobil); break; - case 7: pr(" %d", plane.pln_tech); break; - case 8: pr(" %d", plane.pln_att); break; - case 9: pr(" %d", plane.pln_def); break; - case 10: pr(" %d", plane.pln_acc); break; - case 11: pr(" %d", plane.pln_range); break; - case 12: pr(" %d", plane.pln_range_max); break; - case 13: pr(" %d", plane.pln_load); break; - case 14: pr(" %d", plane.pln_fuel); break; - case 15: pr(" %d", plane.pln_harden); break; - case 16: pr(" %d", plane.pln_ship); break; - case 17: pr(" %d", plane.pln_land); break; - case 18: if ((plchr[(int)plane.pln_type].pl_flags & (P_O|P_M)) == P_O) { - pr(" %c", (plane.pln_flags & PLN_LAUNCHED)?'Y':'N'); - } else pr (" N"); break; - case 19: if ((plchr[(int)plane.pln_type].pl_flags & (P_O|P_M)) == P_O) { - pr(" %c", opt_ORBIT?(plane.pln_flags & PLN_SYNCHRONOUS)?'Y':'N':'N'); - } else pr (" N"); break; - case 20: if (plane.pln_nuketype != -1) { - pr(" %0.5s", nchr[(int)plane.pln_nuketype].n_name); break; - } else pr(" N/A"); break; + switch (field[n++]) { + case 1: + pr(" %0.4s", plchr[(int)plane.pln_type].pl_name); + break; + case 2: + pr(" %d", xrel(natp, plane.pln_x)); + break; + case 3: + pr(" %d", yrel(natp, plane.pln_y)); + break; + case 4: + if (plane.pln_wing == ' ') + pr(" ~"); + else + pr(" %c", plane.pln_wing); + break; + case 5: + pr(" %d", plane.pln_effic); + break; + case 6: + pr(" %d", plane.pln_mobil); + break; + case 7: + pr(" %d", plane.pln_tech); + break; + case 8: + pr(" %d", plane.pln_att); + break; + case 9: + pr(" %d", plane.pln_def); + break; + case 10: + pr(" %d", plane.pln_acc); + break; + case 11: + pr(" %d", plane.pln_range); + break; + case 12: + pr(" %d", plane.pln_range_max); + break; + case 13: + pr(" %d", plane.pln_load); + break; + case 14: + pr(" %d", plane.pln_fuel); + break; + case 15: + pr(" %d", plane.pln_harden); + break; + case 16: + pr(" %d", plane.pln_ship); + break; + case 17: + pr(" %d", plane.pln_land); + break; + case 18: + if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) == + P_O) { + pr(" %c", + (plane.pln_flags & PLN_LAUNCHED) ? 'Y' : 'N'); + } else + pr(" N"); + break; + case 19: + if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) == + P_O) { + pr(" %c", + opt_ORBIT ? (plane. + pln_flags & PLN_SYNCHRONOUS) ? 'Y' : + 'N' : 'N'); + } else + pr(" N"); + break; + case 20: + if (plane.pln_nuketype != -1) { + pr(" %0.5s", nchr[(int)plane.pln_nuketype].n_name); + break; + } else + pr(" N/A"); + break; - case 21: pr(" %c", plane.pln_flags & PLN_AIRBURST?'A':'G'); break; - } - } - pr("\n"); + case 21: + pr(" %c", plane.pln_flags & PLN_AIRBURST ? 'A' : 'G'); + break; + } } - if (nplanes == 0) { - if (player->argp[1]) - pr("%s: No plane(s)\n", player->argp[1]); - else - pr("%s: No plane(s)\n", ""); - return RET_FAIL; - }else - pr("%d plane%s\n", nplanes, splur(nplanes)); + pr("\n"); + } + if (nplanes == 0) { + if (player->argp[1]) + pr("%s: No plane(s)\n", player->argp[1]); + else + pr("%s: No plane(s)\n", ""); + return RET_FAIL; + } else + pr("%d plane%s\n", nplanes, splur(nplanes)); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/plan.c b/src/lib/commands/plan.c index 729b6779b..494a76fd3 100644 --- a/src/lib/commands/plan.c +++ b/src/lib/commands/plan.c @@ -48,61 +48,62 @@ int plan(void) { - int nplanes; - struct nstr_item np; - struct plnstr plane; + int nplanes; + struct nstr_item np; + struct plnstr plane; - if (!snxtitem(&np, EF_PLANE, player->argp[1])) - return RET_SYN; - nplanes = 0; - while (nxtitem(&np, (s_char *)&plane)) { - if (!player->owner || plane.pln_own == 0) - continue; - if (nplanes++ == 0) { - if (player->god) - pr("own "); - pr(" # type x,y w eff mu def tech ran hard s/l L"); - if (opt_ORBIT) - pr("S"); - pr("B nuke\n"); - } - if (player->god) - pr("%3d ", plane.pln_own); - pr("%4d %-19.19s ", np.cur, plchr[(int)plane.pln_type].pl_name); - prxy("%4d,%-4d", plane.pln_x, plane.pln_y, player->cnum); - pr(" %c %3d%% %3d %3d %4d %3d %3d", - plane.pln_wing, plane.pln_effic, - plane.pln_mobil, - plane.pln_def, plane.pln_tech, - plane.pln_range, plane.pln_harden); - if (plane.pln_ship >= 0) - pr("%5dS", plane.pln_ship); - else - if (plane.pln_land >= 0) - pr("%5dL", plane.pln_land); - else - pr(" "); - if ((plchr[(int)plane.pln_type].pl_flags & (P_O|P_M)) == P_O) { - pr(" %c", (plane.pln_flags & PLN_LAUNCHED)?'Y':'N'); - pr("%c", - opt_ORBIT?(plane.pln_flags & PLN_SYNCHRONOUS)?'Y':'N':' '); - } else - pr(" "); - if (plane.pln_nuketype != -1) - pr("%c %-5.5s", - plane.pln_flags & PLN_AIRBURST?'A':'G', - nchr[(int)plane.pln_nuketype].n_name); - pr("\n"); + if (!snxtitem(&np, EF_PLANE, player->argp[1])) + return RET_SYN; + nplanes = 0; + while (nxtitem(&np, (s_char *)&plane)) { + if (!player->owner || plane.pln_own == 0) + continue; + if (nplanes++ == 0) { + if (player->god) + pr("own "); + pr(" # type x,y w eff mu def tech ran hard s/l L"); + if (opt_ORBIT) + pr("S"); + pr("B nuke\n"); } + if (player->god) + pr("%3d ", plane.pln_own); + pr("%4d %-19.19s ", np.cur, plchr[(int)plane.pln_type].pl_name); + prxy("%4d,%-4d", plane.pln_x, plane.pln_y, player->cnum); + pr(" %c %3d%% %3d %3d %4d %3d %3d", + plane.pln_wing, plane.pln_effic, + plane.pln_mobil, + plane.pln_def, plane.pln_tech, + plane.pln_range, plane.pln_harden); + if (plane.pln_ship >= 0) + pr("%5dS", plane.pln_ship); + else if (plane.pln_land >= 0) + pr("%5dL", plane.pln_land); + else + pr(" "); + if ((plchr[(int)plane.pln_type].pl_flags & (P_O | P_M)) == P_O) { + pr(" %c", (plane.pln_flags & PLN_LAUNCHED) ? 'Y' : 'N'); + pr("%c", + opt_ORBIT ? (plane. + pln_flags & PLN_SYNCHRONOUS) ? 'Y' : 'N' : + ' '); + } else + pr(" "); + if (plane.pln_nuketype != -1) + pr("%c %-5.5s", + plane.pln_flags & PLN_AIRBURST ? 'A' : 'G', + nchr[(int)plane.pln_nuketype].n_name); + pr("\n"); + } - if (nplanes == 0) { - if (player->argp[1]) - pr("%s: No plane(s)\n", player->argp[1]); - else - pr("%s: No plane(s)\n", ""); - return RET_FAIL; - }else - pr("%d plane%s\n", nplanes, splur(nplanes)); + if (nplanes == 0) { + if (player->argp[1]) + pr("%s: No plane(s)\n", player->argp[1]); + else + pr("%s: No plane(s)\n", ""); + return RET_FAIL; + } else + pr("%d plane%s\n", nplanes, splur(nplanes)); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/play.c b/src/lib/commands/play.c index b842ab978..067c63545 100644 --- a/src/lib/commands/play.c +++ b/src/lib/commands/play.c @@ -40,90 +40,81 @@ #include "commands.h" static void play_header(void); -static int play_list(struct player *joe); +static int play_list(struct player *joe); int play(void) { - struct player *joe; - int saw = 0; - int count = 0; + struct player *joe; + int saw = 0; + int count = 0; - for (joe = player_prev(0); joe; joe = player_prev(joe)) { - if (!count++) - play_header(); - saw += play_list(joe); - } - if (player->god || opt_BLITZ) - pr("%d player%s\n", count, splur(count)); + for (joe = player_prev(0); joe; joe = player_prev(joe)) { + if (!count++) + play_header(); + saw += play_list(joe); + } + if (player->god || opt_BLITZ) + pr("%d player%s\n", count, splur(count)); - return RET_OK; + return RET_OK; } static void play_header(void) { - prdate(); - pr("%9s %3s %-32s %5s %5s %-20s\n", - "", - "#", - "", - "time", - "idle", - "last command" - ); + prdate(); + pr("%9s %3s %-32s %5s %5s %-20s\n", + "", "#", "", "time", "idle", "last command"); } static int play_list(struct player *joe) { - time_t now; - s_char *com; - struct natstr *natp; - struct natstr *us; + time_t now; + s_char *com; + struct natstr *natp; + struct natstr *us; + + if (joe->cnum >= MAXNOC || !(natp = getnatp(joe->cnum))) + return 0; - if (joe->cnum >= MAXNOC || - !(natp = getnatp(joe->cnum))) - return 0; + us = getnatp(player->cnum); + if (player->god) { + /* We are a god, we see everything */ + } else if (opt_BLITZ) { + /* It's a blitz, we see everything */ + } else if (joe->god) { + /* This country is a god, so we see it */ + } else if (us->nat_stat == VIS) { + /* We are a visitor country, we can't see squat, except deities */ + return 0; + } else if (joe->cnum != player->cnum) { + /* This isn't us. Can we see it? */ + if (natp->nat_stat == VIS) { + /* Yes, we can see visitors are logged on */ + } else if (getrel(natp, player->cnum) < ALLIED) { + /* This is a non-allied country, don't show it. */ + return 0; + } + } - us = getnatp(player->cnum); - if (player->god) { - /* We are a god, we see everything */ - } else if (opt_BLITZ) { - /* It's a blitz, we see everything */ - } else if (joe->god) { - /* This country is a god, so we see it */ - } else if (us->nat_stat == VIS) { - /* We are a visitor country, we can't see squat, except deities */ - return 0; - } else if (joe->cnum != player->cnum) { - /* This isn't us. Can we see it? */ - if (natp->nat_stat == VIS) { - /* Yes, we can see visitors are logged on */ - } else if (getrel(natp, player->cnum) < ALLIED) { - /* This is a non-allied country, don't show it. */ - return 0; - } - } + time(&now); + if (player->god) { + if (!joe->combuf || !*joe->combuf) + com = "NULL"; + else + com = joe->combuf; + } else + com = ""; - time(&now); - if (player->god) { - if (!joe->combuf || !*joe->combuf) - com = "NULL"; - else - com = joe->combuf; - } else - com = ""; - - pr("%-9.9s %3d %32.32s %2d:%02d %4ds %-20.20s\n", - cname(joe->cnum), - joe->cnum, - (player->god || joe->cnum == player->cnum)?praddr(joe):(s_char *)"", - natp->nat_minused / 60, natp->nat_minused % 60, - now - joe->curup, - com - ); - return 1; + pr("%-9.9s %3d %32.32s %2d:%02d %4ds %-20.20s\n", + cname(joe->cnum), + joe->cnum, + (player->god + || joe->cnum == player->cnum) ? praddr(joe) : (s_char *)"", + natp->nat_minused / 60, natp->nat_minused % 60, now - joe->curup, + com); + return 1; } - diff --git a/src/lib/commands/powe.c b/src/lib/commands/powe.c index 3be73665a..578de0402 100644 --- a/src/lib/commands/powe.c +++ b/src/lib/commands/powe.c @@ -58,124 +58,126 @@ #include struct powsort { - float powval; - natid cnum; + float powval; + natid cnum; }; -static int powcmp(struct powsort *p1, struct powsort *p2); -static void out5(double value, int round_val, int round_flag); -static void gen_power(void); -static void addtopow(register int *vec, register struct powstr *pow); +static int powcmp(struct powsort *p1, struct powsort *p2); +static void out5(double value, int round_val, int round_flag); +static void gen_power(void); +static void addtopow(register int *vec, register struct powstr *pow); int powe(void) { - struct natstr *natp; - struct natstr *natp2; - int round_flag; - time_t pow_time; - struct nstr_item ni; - struct powstr pow; - int num; - int power_generated = 0; - int targets[MAXNOC]; - int use_targets = 0; - int got_targets = 0; - int no_numbers = 0; - s_char *p; + struct natstr *natp; + struct natstr *natp2; + int round_flag; + time_t pow_time; + struct nstr_item ni; + struct powstr pow; + int num; + int power_generated = 0; + int targets[MAXNOC]; + int use_targets = 0; + int got_targets = 0; + int no_numbers = 0; + s_char *p; - bzero((s_char *)targets, sizeof(targets)); - natp = getnatp(player->cnum); - num = MAXNOC; - if (player->argp[1] && player->argp[1][0] == 'n') { - if (natp->nat_btu < 1) - pr("\n Insufficient BTUs, using the last report.\n\n"); - else { - gen_power(); - power_generated = 1; - if (player->argp[2] && (num = atoi(player->argp[2])) < 0) { - num = MAXNOC; - if (player->god) - no_numbers = 1; - else - return RET_SYN; - } - } - } else if (player->argp[1] && player->argp[1][0] == 'c') { - if (!player->argp[2]) - return RET_SYN; - if (strchr(player->argp[2], '/')) { - p = strtok(player->argp[2], "/"); - do { - got_targets |= set_target(p, targets); - } while (NULL != (p = strtok(0, "/"))); - } else { - got_targets |= set_target(player->argp[2], targets); - } - use_targets = 1; - } else if (player->argp[1] && (num = atoi(player->argp[1])) < 0) { - num = -(num); - if (num > MAXNOC || num < 0) + bzero((s_char *)targets, sizeof(targets)); + natp = getnatp(player->cnum); + num = MAXNOC; + if (player->argp[1] && player->argp[1][0] == 'n') { + if (natp->nat_btu < 1) + pr("\n Insufficient BTUs, using the last report.\n\n"); + else { + gen_power(); + power_generated = 1; + if (player->argp[2] && (num = atoi(player->argp[2])) < 0) { + num = MAXNOC; + if (player->god) + no_numbers = 1; + else + return RET_SYN; + } + } + } else if (player->argp[1] && player->argp[1][0] == 'c') { + if (!player->argp[2]) + return RET_SYN; + if (strchr(player->argp[2], '/')) { + p = strtok(player->argp[2], "/"); + do { + got_targets |= set_target(p, targets); + } while (NULL != (p = strtok(0, "/"))); + } else { + got_targets |= set_target(player->argp[2], targets); + } + use_targets = 1; + } else if (player->argp[1] && (num = atoi(player->argp[1])) < 0) { + num = -(num); + if (num > MAXNOC || num < 0) num = MAXNOC; - if (player->god) + if (player->god) no_numbers = 1; - else + else return RET_SYN; - } + } - if (use_targets && !got_targets) - return RET_FAIL; + if (use_targets && !got_targets) + return RET_FAIL; - if (!power_generated) { - snxtitem_all(&ni, EF_POWER); - if (!nxtitem(&ni, (s_char *)&pow)) { - pr("Power for this game has not been built yet. Type 'power new' to build it.\n"); - return RET_FAIL; - } - } - pr(" - = [ Empire Power Report ] = -\n"); - pow_time = ef_mtime(EF_POWER); - pr(" as of %s\n sects eff civ", ctime(&pow_time)); - pr(" mil shell gun pet iron dust oil pln ship unit money\n"); + if (!power_generated) { snxtitem_all(&ni, EF_POWER); - while ((nxtitem(&ni, (s_char *)&pow)) && num > 0) { - if (pow.p_nation == 0 || pow.p_power <= 0.0) - continue; - if (opt_HIDDEN) { - if (!player->god && pow.p_nation != player->cnum) - continue; - } - natp2 = getnatp(pow.p_nation); - if (natp2->nat_stat & STAT_GOD) - continue; - if (use_targets && !targets[pow.p_nation]) - continue; - if (pow.p_nation != player->cnum && player->cnum != 0) - round_flag = 1; - else - round_flag = 0; - num--; - pr("%9.9s", cname(pow.p_nation)); - out5(pow.p_sects, 5, round_flag); - if (pow.p_sects) pr("%4.0f%%", pow.p_effic / pow.p_sects); - else pr(" 0%%"); - out5(pow.p_civil, 50, round_flag); - out5(pow.p_milit, 50, round_flag); - out5(pow.p_shell, 25, round_flag); - out5(pow.p_guns, 5, round_flag); - out5(pow.p_petrol, 50, round_flag); - out5(pow.p_iron, 50, round_flag); - out5(pow.p_dust, 50, round_flag); - out5(pow.p_oil, 50, round_flag); - out5(pow.p_planes, 10, round_flag); - out5(pow.p_ships, 10, round_flag); - out5(pow.p_units, 10, round_flag); - out5(pow.p_money, 5000, round_flag); - pr("\n"); - if (player->god != 0 && !no_numbers) - pr("%9.2f\n", pow.p_power); + if (!nxtitem(&ni, (s_char *)&pow)) { + pr("Power for this game has not been built yet. Type 'power new' to build it.\n"); + return RET_FAIL; + } + } + pr(" - = [ Empire Power Report ] = -\n"); + pow_time = ef_mtime(EF_POWER); + pr(" as of %s\n sects eff civ", ctime(&pow_time)); + pr(" mil shell gun pet iron dust oil pln ship unit money\n"); + snxtitem_all(&ni, EF_POWER); + while ((nxtitem(&ni, (s_char *)&pow)) && num > 0) { + if (pow.p_nation == 0 || pow.p_power <= 0.0) + continue; + if (opt_HIDDEN) { + if (!player->god && pow.p_nation != player->cnum) + continue; } - if (((player->god != 0) && opt_HIDDEN) || !opt_HIDDEN) { + natp2 = getnatp(pow.p_nation); + if (natp2->nat_stat & STAT_GOD) + continue; + if (use_targets && !targets[pow.p_nation]) + continue; + if (pow.p_nation != player->cnum && player->cnum != 0) + round_flag = 1; + else + round_flag = 0; + num--; + pr("%9.9s", cname(pow.p_nation)); + out5(pow.p_sects, 5, round_flag); + if (pow.p_sects) + pr("%4.0f%%", pow.p_effic / pow.p_sects); + else + pr(" 0%%"); + out5(pow.p_civil, 50, round_flag); + out5(pow.p_milit, 50, round_flag); + out5(pow.p_shell, 25, round_flag); + out5(pow.p_guns, 5, round_flag); + out5(pow.p_petrol, 50, round_flag); + out5(pow.p_iron, 50, round_flag); + out5(pow.p_dust, 50, round_flag); + out5(pow.p_oil, 50, round_flag); + out5(pow.p_planes, 10, round_flag); + out5(pow.p_ships, 10, round_flag); + out5(pow.p_units, 10, round_flag); + out5(pow.p_money, 5000, round_flag); + pr("\n"); + if (player->god != 0 && !no_numbers) + pr("%9.2f\n", pow.p_power); + } + if (((player->god != 0) && opt_HIDDEN) || !opt_HIDDEN) { pr(" ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----\n"); getpower(0, &pow); pr("worldwide"); @@ -194,248 +196,247 @@ powe(void) out5(pow.p_units, 10, 1); out5(pow.p_money, 5000, 1); pr("\n"); - } - return RET_OK; + } + return RET_OK; } static void out5(double value, int round_val, int round_flag) { - if (value > round_val && round_flag) - value = (int) (value / round_val + 0.5) * round_val; - if (value < -995000.) - pr("%4.0fM", value / 1e6); - else if (value < -9950.) - pr("%4.0fK", value / 1000.); - else if (value < -999.) - pr("%4.1fK", value / 1000.); - else if (value < 1000.) - pr("%4.0f ", value); - else if (value < 10000.) - pr("%4.1fK", value / 1000.); - else if (value < 1e6) - pr("%4.0fK", value / 1000.); - else if (value < 1e7) - pr("%4.1fM", value / 1e6); - else if (value >= 1e9) - pr("%4.0fG", value / 1e9); - else - pr("%4.0fM", value / 1e6); + if (value > round_val && round_flag) + value = (int)(value / round_val + 0.5) * round_val; + if (value < -995000.) + pr("%4.0fM", value / 1e6); + else if (value < -9950.) + pr("%4.0fK", value / 1000.); + else if (value < -999.) + pr("%4.1fK", value / 1000.); + else if (value < 1000.) + pr("%4.0f ", value); + else if (value < 10000.) + pr("%4.1fK", value / 1000.); + else if (value < 1e6) + pr("%4.0fK", value / 1000.); + else if (value < 1e7) + pr("%4.1fM", value / 1e6); + else if (value >= 1e9) + pr("%4.0fG", value / 1e9); + else + pr("%4.0fM", value / 1e6); } static void gen_power(void) { - extern double powe_cost; - float *f_ptr; - float *f_pt2; - register struct powstr *pow; - register int i; - struct sctstr sect; - struct plnstr plane; - struct shpstr ship; - struct lndstr land; - struct powstr powbuf[MAXNOC]; - struct nstr_item ni; - struct nstr_sect ns; - int vec[I_MAX+1]; - struct powsort order[MAXNOC]; - struct natstr *natp; - float f; + extern double powe_cost; + float *f_ptr; + float *f_pt2; + register struct powstr *pow; + register int i; + struct sctstr sect; + struct plnstr plane; + struct shpstr ship; + struct lndstr land; + struct powstr powbuf[MAXNOC]; + struct nstr_item ni; + struct nstr_sect ns; + int vec[I_MAX + 1]; + struct powsort order[MAXNOC]; + struct natstr *natp; + float f; - player->btused += powe_cost; - bzero((s_char *) powbuf, sizeof(powbuf)); - snxtsct_all(&ns); - while (nxtsct(&ns, §)) { - if (sect.sct_own == 0) - continue; - pow = &powbuf[sect.sct_own]; - pow->p_sects += 1.0; - pow->p_effic += sect.sct_effic; - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - addtopow(vec, pow); - } - snxtitem_all(&ni, EF_LAND); - while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own == 0) - continue; - pow = &powbuf[land.lnd_own]; - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - addtopow(vec, pow); - if (opt_NEWPOWER == 0) { - pow->p_power += lchr[(int)land.lnd_type].l_lcm / 10.0; - pow->p_power += lchr[(int)land.lnd_type].l_hcm / 5.0; - } else { /* old power */ - f = ((float)(lchr[(int)land.lnd_type].l_lcm / 10.0)) * - ((float)land.lnd_effic)/100.0; - f += ((float)(lchr[(int)land.lnd_type].l_hcm / 10.0)) * - ((float)land.lnd_effic/100.0); - pow->p_power += f*2; - } /* end NEWPOWER */ - pow->p_units += 1.0; + player->btused += powe_cost; + bzero((s_char *)powbuf, sizeof(powbuf)); + snxtsct_all(&ns); + while (nxtsct(&ns, §)) { + if (sect.sct_own == 0) + continue; + pow = &powbuf[sect.sct_own]; + pow->p_sects += 1.0; + pow->p_effic += sect.sct_effic; + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + addtopow(vec, pow); + } + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + pow = &powbuf[land.lnd_own]; + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); + addtopow(vec, pow); + if (opt_NEWPOWER == 0) { + pow->p_power += lchr[(int)land.lnd_type].l_lcm / 10.0; + pow->p_power += lchr[(int)land.lnd_type].l_hcm / 5.0; + } else { /* old power */ + f = ((float)(lchr[(int)land.lnd_type].l_lcm / 10.0)) * + ((float)land.lnd_effic) / 100.0; + f += ((float)(lchr[(int)land.lnd_type].l_hcm / 10.0)) * + ((float)land.lnd_effic / 100.0); + pow->p_power += f * 2; + } /* end NEWPOWER */ + pow->p_units += 1.0; + } + snxtitem_all(&ni, EF_SHIP); + while (nxtitem(&ni, (s_char *)&ship)) { + if (ship.shp_own == 0) + continue; + pow = &powbuf[ship.shp_own]; + getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); + addtopow(vec, pow); + if (opt_NEWPOWER == 0) { + pow->p_power += mchr[(int)ship.shp_type].m_lcm / 10.0; + pow->p_power += mchr[(int)ship.shp_type].m_hcm / 5.0; + } else { /* old power formula */ + f = ((float)(mchr[(int)ship.shp_type].m_lcm / 10.0)) * + ((float)ship.shp_effic) / 100.0; + f += ((float)(mchr[(int)ship.shp_type].m_hcm / 10.0)) * + ((float)ship.shp_effic / 100.0); + pow->p_power += f * 2; + } /* end NEWPOWER */ + pow->p_ships += 1.0; + } + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + pow = &powbuf[plane.pln_own]; + pow->p_planes += 1.0; + if (opt_NEWPOWER == 0) + pow->p_power += plane.pln_effic / 100.0; + else { /* old POWER */ + natp = getnatp(plane.pln_own); + pow->p_power += 20 * (plane.pln_effic / 100.0) * + (natp->nat_level[NAT_TLEV] / 500.0); + } /* end old POWER */ + } + for (i = 1; NULL != (natp = getnatp(i)); i++) { + pow = &powbuf[i]; + pow->p_nation = i; + if ((natp->nat_stat & STAT_INUSE) == 0 || + (natp->nat_stat & STAT_NORM) == 0) { + pow->p_power = 0.; + continue; } - snxtitem_all(&ni, EF_SHIP); - while (nxtitem(&ni, (s_char *)&ship)) { - if (ship.shp_own == 0) - continue; - pow = &powbuf[ship.shp_own]; - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - addtopow(vec, pow); - if (opt_NEWPOWER == 0) { - pow->p_power += mchr[(int)ship.shp_type].m_lcm / 10.0; - pow->p_power += mchr[(int)ship.shp_type].m_hcm / 5.0; - } else { /* old power formula */ - f = ((float)(mchr[(int)ship.shp_type].m_lcm / 10.0)) * - ((float)ship.shp_effic)/100.0; - f += ((float)(mchr[(int)ship.shp_type].m_hcm / 10.0)) * - ((float)ship.shp_effic/100.0); - pow->p_power += f*2; - } /* end NEWPOWER */ - pow->p_ships += 1.0; + if (opt_NEWPOWER && (natp->nat_stat & STAT_GOD)) { + pow->p_power = 0.; + continue; } - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) { - if (plane.pln_own == 0) - continue; - pow = &powbuf[plane.pln_own]; - pow->p_planes += 1.0; - if (opt_NEWPOWER == 0) - pow->p_power += plane.pln_effic / 100.0; - else { /* old POWER */ - natp=getnatp(plane.pln_own); - pow->p_power += 20 * (plane.pln_effic / 100.0) * - (natp->nat_level[NAT_TLEV]/500.0); - } /* end old POWER */ - } - for (i=1; NULL != (natp = getnatp(i)); i++) { - pow = &powbuf[i]; - pow->p_nation = i; - if ((natp->nat_stat & STAT_INUSE) == 0 || - (natp->nat_stat & STAT_NORM) == 0) { - pow->p_power = 0.; - continue; - } - if (opt_NEWPOWER && (natp->nat_stat & STAT_GOD)) { - pow->p_power = 0.; - continue; - } - pow->p_money = natp->nat_money; - pow->p_power += pow->p_money / 100.; + pow->p_money = natp->nat_money; + pow->p_power += pow->p_money / 100.; - pow->p_power += pow->p_petrol / (opt_NEWPOWER ? 500.0 : 50.0); + pow->p_power += pow->p_petrol / (opt_NEWPOWER ? 500.0 : 50.0); - if (opt_NEWPOWER == 0) { - pow->p_power += (pow->p_civil + pow->p_milit + - pow->p_shell) / 10.; - pow->p_power += (pow->p_iron + pow->p_dust + - pow->p_effic + pow->p_oil) / 10.; - pow->p_power += (pow->p_guns + pow->p_effic) / 3.; - pow->p_power += pow->p_ships; - pow->p_power += pow->p_sects * 3.0; - pow->p_power += pow->p_planes * 5.0; - } else { /* new POWER format */ - pow->p_power += (pow->p_civil + pow->p_milit)/10.0; - pow->p_power += (pow->p_shell)/12.5; - pow->p_power += (pow->p_iron)/100.0; - pow->p_power += (pow->p_dust/5 + - pow->p_oil/10 + - pow->p_bars); - pow->p_power += (pow->p_guns) / 2.5; - if (pow->p_sects > 0) - pow->p_power += (pow->p_sects * - ((pow->p_effic/pow->p_sects)/ - 100.0)) * 10.0; - if (natp->nat_level[NAT_TLEV] > 0.0) - pow->p_power = pow->p_power * - (((float)natp->nat_level[NAT_TLEV])/ - 500.0); - else - pow->p_power = pow->p_power * (1.0/500.0); - } /* end new POWER */ - /* ack. add this vec to the "world power" element */ - f_pt2 = &(powbuf[0].p_sects); - f_ptr = &(pow->p_sects); - while (f_ptr <= &(pow->p_power)) { - *f_pt2 += *f_ptr; - f_pt2++; - f_ptr++; - } + if (opt_NEWPOWER == 0) { + pow->p_power += (pow->p_civil + pow->p_milit + + pow->p_shell) / 10.; + pow->p_power += (pow->p_iron + pow->p_dust + + pow->p_effic + pow->p_oil) / 10.; + pow->p_power += (pow->p_guns + pow->p_effic) / 3.; + pow->p_power += pow->p_ships; + pow->p_power += pow->p_sects * 3.0; + pow->p_power += pow->p_planes * 5.0; + } else { /* new POWER format */ + pow->p_power += (pow->p_civil + pow->p_milit) / 10.0; + pow->p_power += (pow->p_shell) / 12.5; + pow->p_power += (pow->p_iron) / 100.0; + pow->p_power += (pow->p_dust / 5 + + pow->p_oil / 10 + pow->p_bars); + pow->p_power += (pow->p_guns) / 2.5; + if (pow->p_sects > 0) + pow->p_power += (pow->p_sects * + ((pow->p_effic / pow->p_sects) / + 100.0)) * 10.0; + if (natp->nat_level[NAT_TLEV] > 0.0) + pow->p_power = pow->p_power * + (((float)natp->nat_level[NAT_TLEV]) / 500.0); + else + pow->p_power = pow->p_power * (1.0 / 500.0); + } /* end new POWER */ + /* ack. add this vec to the "world power" element */ + f_pt2 = &(powbuf[0].p_sects); + f_ptr = &(pow->p_sects); + while (f_ptr <= &(pow->p_power)) { + *f_pt2 += *f_ptr; + f_pt2++; + f_ptr++; } - for (i=1; i < MAXNOC; i++) { - struct natstr *np; - int maxpop; - float f = 1.0; + } + for (i = 1; i < MAXNOC; i++) { + struct natstr *np; + int maxpop; + float f = 1.0; - if (opt_RES_POP) { - np = getnatp(i); - maxpop = max_pop(np->nat_level[NAT_RLEV], 0); - f = 1.0 + (((float)maxpop)/10000.0); - } - powbuf[i].p_power *= f; - order[i].powval = powbuf[i].p_power; - order[i].cnum = i; - } - qsort((s_char *)&order[1], MAXNOC-1, sizeof(*order), (qsort_func_t)powcmp); - putpower(0, &powbuf[0]); - for (i=1; inat_level[NAT_RLEV], 0); + f = 1.0 + (((float)maxpop) / 10000.0); } + powbuf[i].p_power *= f; + order[i].powval = powbuf[i].p_power; + order[i].cnum = i; + } + qsort((s_char *)&order[1], MAXNOC - 1, sizeof(*order), + (qsort_func_t)powcmp); + putpower(0, &powbuf[0]); + for (i = 1; i < MAXNOC; i++) { + putpower(i, &powbuf[order[i].cnum]); + } } static int powcmp(struct powsort *p1, struct powsort *p2) { - if (p1->powval > p2->powval) - return -1; - if (p1->powval < p2->powval) - return 1; - return 0; + if (p1->powval > p2->powval) + return -1; + if (p1->powval < p2->powval) + return 1; + return 0; } static void addtopow(register int *vec, register struct powstr *pow) { - pow->p_civil += vec[I_CIVIL]; - pow->p_milit += vec[I_MILIT]; - pow->p_shell += vec[I_SHELL]; - pow->p_guns += vec[I_GUN]; - pow->p_petrol += vec[I_PETROL]; - pow->p_iron += vec[I_IRON]; - pow->p_dust += vec[I_DUST]; - pow->p_food += vec[I_FOOD]; - pow->p_oil += vec[I_OIL]; - pow->p_bars += vec[I_BAR]; - pow->p_power += vec[I_LCM] / 10.0; - pow->p_power += vec[I_HCM] / 5.0; + pow->p_civil += vec[I_CIVIL]; + pow->p_milit += vec[I_MILIT]; + pow->p_shell += vec[I_SHELL]; + pow->p_guns += vec[I_GUN]; + pow->p_petrol += vec[I_PETROL]; + pow->p_iron += vec[I_IRON]; + pow->p_dust += vec[I_DUST]; + pow->p_food += vec[I_FOOD]; + pow->p_oil += vec[I_OIL]; + pow->p_bars += vec[I_BAR]; + pow->p_power += vec[I_LCM] / 10.0; + pow->p_power += vec[I_HCM] / 5.0; } int set_target(s_char *p, int *targets) { - int target; - struct natstr *natp; - - if (!p) - return 0; + int target; + struct natstr *natp; - if (isdigit(*p)) - target = atoi(p); - else - target = cnumb(p); + if (!p) + return 0; - if (target > 0 && target < MAXNOC && (natp = getnatp(target))) { - if (natp->nat_stat & STAT_GOD) { - pr("Country #%d is a deity country\n", target); - } else if (!(natp->nat_stat & STAT_INUSE)) { - pr("Country #%d is not in use\n", target); - } else if (!(natp->nat_stat & STAT_NORM)) { - pr("Country #%d is not a normal country\n", target); - } else { - targets[target] = 1; - return 1; - } - } else - pr("Bad country: \'%s\'\n", p); + if (isdigit(*p)) + target = atoi(p); + else + target = cnumb(p); - return 0; + if (target > 0 && target < MAXNOC && (natp = getnatp(target))) { + if (natp->nat_stat & STAT_GOD) { + pr("Country #%d is a deity country\n", target); + } else if (!(natp->nat_stat & STAT_INUSE)) { + pr("Country #%d is not in use\n", target); + } else if (!(natp->nat_stat & STAT_NORM)) { + pr("Country #%d is not a normal country\n", target); + } else { + targets[target] = 1; + return 1; + } + } else + pr("Bad country: \'%s\'\n", p); + + return 0; } diff --git a/src/lib/commands/prod.c b/src/lib/commands/prod.c index 6c66f187c..9daf60921 100644 --- a/src/lib/commands/prod.c +++ b/src/lib/commands/prod.c @@ -51,16 +51,16 @@ count_pop(register int n) register int i; register int pop = 0; struct sctstr *sp; - int vec[I_MAX+1]; + int vec[I_MAX + 1]; for (i = 0; NULL != (sp = getsectid(i)); i++) { - if (sp->sct_own != n) - continue; - if (sp->sct_oldown != n) - continue; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - continue; - pop += vec[I_CIVIL]; + if (sp->sct_own != n) + continue; + if (sp->sct_oldown != n) + continue; + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) + continue; + pop += vec[I_CIVIL]; } return pop; } @@ -68,94 +68,95 @@ count_pop(register int n) int prod(void) { - extern double obrate, uwbrate; - extern int etu_per_update; - struct natstr *natp; - struct sctstr sect; - struct nstr_sect nstr; - struct pchrstr *pp; - double effic; - double maxr; /* floating version of max */ - double prodeff; - double real; /* floating pt version of act */ - double work; - int totpop; - int act; /* actual production */ - int cost; - int i; - int max; /* production w/infinate materials */ - double maxtake; - int nsect; - double take; - double mtake; - int there; - int totcomp; /* sum of component amounts */ - int used; /* production w/infinite workforce */ - int wforce; - int it; - u_short *amount; /* amount for component pointer */ - u_char *comp; /* component pointer */ - u_char *endcomp; - u_char vtype; - s_char *resource; - int c; - s_char maxc[3][10]; - s_char use[3][10]; - int items[I_MAX+1]; - int vec[I_MAX+1], lcms, hcms; - int civs=0; - int uws=0; - int bwork; - int twork; - int type; - int eff; - int maxpop; - u_char otype; - + extern double obrate, uwbrate; + extern int etu_per_update; + struct natstr *natp; + struct sctstr sect; + struct nstr_sect nstr; + struct pchrstr *pp; + double effic; + double maxr; /* floating version of max */ + double prodeff; + double real; /* floating pt version of act */ + double work; + int totpop; + int act; /* actual production */ + int cost; + int i; + int max; /* production w/infinate materials */ + double maxtake; + int nsect; + double take; + double mtake; + int there; + int totcomp; /* sum of component amounts */ + int used; /* production w/infinite workforce */ + int wforce; + int it; + u_short *amount; /* amount for component pointer */ + u_char *comp; /* component pointer */ + u_char *endcomp; + u_char vtype; + s_char *resource; + int c; + s_char maxc[3][10]; + s_char use[3][10]; + int items[I_MAX + 1]; + int vec[I_MAX + 1], lcms, hcms; + int civs = 0; + int uws = 0; + int bwork; + int twork; + int type; + int eff; + int maxpop; + u_char otype; + if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; - player->simulation = 1; - prdate(); + player->simulation = 1; + prdate(); nsect = 0; while (nxtsct(&nstr, §)) { if (!player->owner) continue; getvec(VT_ITEM, items, (s_char *)§, EF_SECTOR); - - civs = min(9999, (int) ((obrate * (double) etu_per_update + 1.0) - * (double) items[I_CIVIL])); - uws = min(9999, (int) ((uwbrate * (double) etu_per_update + 1.0) - * (double) items[I_UW])); + + civs = min(9999, (int)((obrate * (double)etu_per_update + 1.0) + * (double)items[I_CIVIL])); + uws = min(9999, (int)((uwbrate * (double)etu_per_update + 1.0) + * (double)items[I_UW])); if (opt_RES_POP) { natp = getnatp(sect.sct_own); maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); civs = min(civs, maxpop); uws = min(uws, maxpop); - } else { /* now RES_POP */ - civs = min(999,civs); - uws = min(999,uws); - } /* end RES_POP */ - + } else { /* now RES_POP */ + civs = min(999, civs); + uws = min(999, uws); + } /* end RES_POP */ + /* This isn't quite right, since research might rise/fall */ /* during the update, but it's the best we can really do */ wforce = (int)(((double)civs * (double)sect.sct_work) - / 100.0 + (double)uws + (double)items[I_MILIT] * 2.0 / 5.0); - work = (double)etu_per_update * (double)wforce / 100.0; + / 100.0 + (double)uws + + (double)items[I_MILIT] * 2.0 / 5.0); + work = (double)etu_per_update *(double)wforce / 100.0; bwork = (int)((double)work / 2.0); - + if (sect.sct_off) continue; type = sect.sct_type; eff = sect.sct_effic; - if(sect.sct_newtype != type) { - twork = (eff+3)/4; - if(twork > bwork) { + if (sect.sct_newtype != type) { + twork = (eff + 3) / 4; + if (twork > bwork) { twork = bwork; } bwork -= twork; - eff -= twork*4; + eff -= twork * 4; otype = type; - if(eff <= 0) { + if (eff <= 0) { type = sect.sct_newtype; eff = 0; } @@ -164,29 +165,35 @@ prod(void) dchr[type].d_pkg != UPKG) { if (opt_RES_POP) { natp = getnatp(sect.sct_own); - civs = min(civs, max_pop(natp->nat_level[NAT_RLEV],0)); - uws = min(uws, max_pop(natp->nat_level[NAT_RLEV], 0)); + civs = + min(civs, + max_pop(natp->nat_level[NAT_RLEV], 0)); + uws = + min(uws, + max_pop(natp->nat_level[NAT_RLEV], 0)); } else { - civs = min(9999,civs); - uws = min(9999,uws); + civs = min(9999, civs); + uws = min(9999, uws); } - wforce = (int)((civs * sect.sct_work) / 100.0 + uws + items[I_MILIT] * 2 / 5.0); + wforce = + (int)((civs * sect.sct_work) / 100.0 + uws + + items[I_MILIT] * 2 / 5.0); work = etu_per_update * wforce / 100.0; - bwork = min((int)(work/2), bwork); + bwork = min((int)(work / 2), bwork); } } twork = 100 - eff; - if(twork > bwork) { + if (twork > bwork) { twork = bwork; } getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - if (dchr[type].d_lcms>0){ + if (dchr[type].d_lcms > 0) { lcms = vec[I_LCM]; lcms /= dchr[type].d_lcms; if (twork > lcms) twork = lcms; } - if (dchr[type].d_hcms>0){ + if (dchr[type].d_hcms > 0) { hcms = vec[I_HCM]; hcms /= dchr[type].d_hcms; if (twork > hcms) @@ -202,14 +209,14 @@ prod(void) bwork -= twork; eff += twork; } - work = work/2 + bwork; + work = work / 2 + bwork; if (eff < 60 || (type != SCT_ENLIST && eff < 61)) continue; - - effic = eff/100.0; + + effic = eff / 100.0; if (effic > 1.0) effic = 1.0; - + if (dchr[type].d_prd == 0 && type != SCT_ENLIST) continue; totcomp = 0; @@ -225,7 +232,7 @@ prod(void) goto is_enlist; if (pp->p_nrndx != 0) { totcomp++; - resource = ((s_char *) §) + pp->p_nrndx; + resource = ((s_char *)§) + pp->p_nrndx; effic = (*resource * effic) / 100.0; if (pp->p_nrdep > 0) { maxtake = (*resource * 100.0) / pp->p_nrdep; @@ -266,43 +273,44 @@ prod(void) * is production limited by resources or * workforce? */ - max = (int) (work * effic / (double) totcomp) + 0.5; + max = (int)(work * effic / (double)totcomp) + 0.5; act = min(used, max); /* * some things are easier to make.. food, * pet, etc. */ - act = (int) (((double)pp->p_effic * 0.01 * (double)act) + 0.5); - max = (int) (((double)pp->p_effic * 0.01 * (double)max) + 0.5); - - real = (double)act * (double)prodeff; - maxr = (double)max * (double)prodeff; - + act = (int)(((double)pp->p_effic * 0.01 * (double)act) + 0.5); + max = (int)(((double)pp->p_effic * 0.01 * (double)max) + 0.5); + + real = (double)act *(double)prodeff; + maxr = (double)max *(double)prodeff; + if (vtype != 0) { if (real < 0.0) real = 0.0; /* production backlog? */ - if ((there = getvar((int)vtype, (s_char *)§, EF_SECTOR)) >= 9999) { + if ((there = + getvar((int)vtype, (s_char *)§, EF_SECTOR)) >= 9999) { there = 9999; } act = min(act, (9999 - there)); max = min(max, (9999 - there)); } - + if (prodeff != 0) { take = real / prodeff; mtake = maxr / prodeff; } else mtake = take = 0.0; - + if (take > 999.0) take = 999.0; if (mtake > 999.0) mtake = 999.0; - + take = (double)take / ((double)pp->p_effic * 0.01); mtake = (double)mtake / ((double)pp->p_effic * 0.01); - + cost = (int)(take * (double)pp->p_cost); if (opt_TECH_POP) { if (pp->p_level == NAT_TLEV) { @@ -311,18 +319,20 @@ prod(void) cost = (int)((double)cost * (double)totpop / 50000.0); } } - + comp = pp->p_vtype; amount = pp->p_vamt; i = 0; while (comp < endcomp) { - it = unitem((int) *comp); + it = unitem((int)*comp); if (it > 0 && it <= I_MAX && ichr[it].i_name != 0) c = ichr[it].i_name[0]; else c = ' '; - (void) sprintf(use[i], " %3d%c", (int)((take * (double)(*amount)) + 0.5), c); - (void) sprintf(maxc[i], " %3d%c", (int)((mtake * (double)(*amount)) + 0.5), c); + (void)sprintf(use[i], " %3d%c", + (int)((take * (double)(*amount)) + 0.5), c); + (void)sprintf(maxc[i], " %3d%c", + (int)((mtake * (double)(*amount)) + 0.5), c); ++comp; ++amount; ++i; @@ -332,18 +342,18 @@ prod(void) strcpy(maxc[i], " "); ++i; } - - is_enlist: - + + is_enlist: + if (nsect++ == 0) { pr("PRODUCTION SIMULATION\n"); pr(" sect des eff wkfc will make- p.e. cost use1 use2 use3 max1 max2 max3 max\n"); } - + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); pr(" %c", dchr[type].d_mnem); pr(" %3.0f%%", effic * 100.0); - + pr(" %4d", wforce); if (vtype != 0) { pr(" %4d", (int)(real + 0.5)); @@ -362,12 +372,12 @@ prod(void) break; } } else { - int maxmil; - int enlisted; - int civs; - - civs = min(999, (int) ((obrate * (double) etu_per_update + 1.0) - * (double) items[I_CIVIL])); + int maxmil; + int enlisted; + int civs; + + civs = min(999, (int)((obrate * (double)etu_per_update + 1.0) + * (double)items[I_CIVIL])); natp = getnatp(sect.sct_own); maxpop = max_pop((float)natp->nat_level[NAT_RLEV], §); civs = min(civs, maxpop); @@ -383,7 +393,7 @@ prod(void) } if (enlisted < 0) enlisted = 0; - if (natp->nat_priorities[type] == 0){ + if (natp->nat_priorities[type] == 0) { maxmil = 0; } pr(" %4d mil 1.00 $%-5d%3dc", @@ -392,7 +402,7 @@ prod(void) enlisted, maxmil, maxmil); continue; } - + pr(" %-5.5s", pp->p_sname); prodeff = prodeff * (double)pp->p_effic * 0.01; pr(" %.2f", prodeff); @@ -404,13 +414,13 @@ prod(void) for (i = 0; i < 3; i++) { pr(maxc[i]); } - if (natp->nat_priorities[type] == 0){ + if (natp->nat_priorities[type] == 0) { max = 0; maxr = 0; } if (vtype != 0 || pp->p_level == NAT_ELEV || pp->p_level == NAT_HLEV) - pr(" %4d\n", min(999,(int)(max * prodeff + 0.05))); + pr(" %4d\n", min(999, (int)(max * prodeff + 0.05))); else pr(" %1.2f\n", maxr); } @@ -425,4 +435,3 @@ prod(void) pr("%d sector%s\n", nsect, splur(nsect)); return RET_OK; } - diff --git a/src/lib/commands/pstat.c b/src/lib/commands/pstat.c index 5e581c14f..25be05c57 100644 --- a/src/lib/commands/pstat.c +++ b/src/lib/commands/pstat.c @@ -47,51 +47,44 @@ int pstat(void) { - int nplanes; - struct nstr_item np; - struct plnstr plane; + int nplanes; + struct nstr_item np; + struct plnstr plane; - if (!snxtitem(&np, EF_PLANE, player->argp[1])) - return RET_SYN; - nplanes = 0; - while (nxtitem(&np, (s_char *)&plane)) { - if (!player->owner || plane.pln_own == 0) - continue; - if (plane.pln_type < 0 || plane.pln_type > pln_maxno) { - pr("bad plane type %d (#%d)\n", - plane.pln_type, np.cur); - continue; - } - if (nplanes++ == 0) { -pr("pln# %22.22s x,y eff tech att def acc ran load fuel\n", "plane-type"); - } - pr("%4d %-22.22s ", - plane.pln_uid, - plchr[(int)plane.pln_type].pl_name); - prxy("%4d,%-4d", - plane.pln_x, - plane.pln_y, - player->cnum); - pr(" %3d%% %4d %3d %3d %3d %3d %4d %4d", - plane.pln_effic, - plane.pln_tech, - plane.pln_att, - plane.pln_def, - plane.pln_acc, - plane.pln_range_max, - plane.pln_load, - plane.pln_fuel); - pr("\n"); + if (!snxtitem(&np, EF_PLANE, player->argp[1])) + return RET_SYN; + nplanes = 0; + while (nxtitem(&np, (s_char *)&plane)) { + if (!player->owner || plane.pln_own == 0) + continue; + if (plane.pln_type < 0 || plane.pln_type > pln_maxno) { + pr("bad plane type %d (#%d)\n", plane.pln_type, np.cur); + continue; } + if (nplanes++ == 0) { + pr("pln# %22.22s x,y eff tech att def acc ran load fuel\n", "plane-type"); + } + pr("%4d %-22.22s ", + plane.pln_uid, plchr[(int)plane.pln_type].pl_name); + prxy("%4d,%-4d", plane.pln_x, plane.pln_y, player->cnum); + pr(" %3d%% %4d %3d %3d %3d %3d %4d %4d", + plane.pln_effic, + plane.pln_tech, + plane.pln_att, + plane.pln_def, + plane.pln_acc, + plane.pln_range_max, plane.pln_load, plane.pln_fuel); + pr("\n"); + } - if (nplanes == 0) { - if (player->argp[1]) - pr("%s: No plane(s)\n", player->argp[1]); - else - pr("%s: No plane(s)\n", ""); - return RET_FAIL; - }else - pr("%d plane%s\n", nplanes, splur(nplanes)); + if (nplanes == 0) { + if (player->argp[1]) + pr("%s: No plane(s)\n", player->argp[1]); + else + pr("%s: No plane(s)\n", ""); + return RET_FAIL; + } else + pr("%d plane%s\n", nplanes, splur(nplanes)); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/rada.c b/src/lib/commands/rada.c index 4cadf25b7..49f016e4c 100644 --- a/src/lib/commands/rada.c +++ b/src/lib/commands/rada.c @@ -48,103 +48,103 @@ int rada(void) { - s_char *cp; - int type; - double tf; - double tech; - struct nstr_item ni; - struct nstr_sect ns; - struct shpstr ship; - struct lndstr land; - struct sctstr sect; - int from_unit; - s_char buf[1024]; + s_char *cp; + int type; + double tf; + double tech; + struct nstr_item ni; + struct nstr_sect ns; + struct shpstr ship; + struct lndstr land; + struct sctstr sect; + int from_unit; + s_char buf[1024]; - from_unit = (**player->argp == 'l'); + from_unit = (**player->argp == 'l'); - if (!from_unit) - cp = getstarg(player->argp[1], "Radar from (ship # or sector(s)) : ", buf); - else - cp = getstarg(player->argp[1], "Radar from (unit # or sector(s)) : ", buf); - if (cp == 0) + if (!from_unit) + cp = getstarg(player->argp[1], + "Radar from (ship # or sector(s)) : ", buf); + else + cp = getstarg(player->argp[1], + "Radar from (unit # or sector(s)) : ", buf); + if (cp == 0) + return RET_SYN; + type = sarg_type(cp); + if (type == NS_AREA) { + if (!snxtsct(&ns, cp)) + return RET_SYN; + tech = tfact(player->cnum, 8.0); + if (tech > ((double)WORLD_Y / 4.0)) + tech = ((double)WORLD_Y / 4.0); + if (tech > ((double)WORLD_X / 8.0)) + tech = ((double)WORLD_X / 8.0); + while (nxtsct(&ns, §)) { + if (sect.sct_type != SCT_RADAR) + continue; + if (!player->owner) + continue; + radmap(sect.sct_x, sect.sct_y, (int)sect.sct_effic, + (int)(tech * 2.0), 0.0); + } + } else if (type == NS_LIST || type == NS_GROUP) { + if (!from_unit) { + /* assumes a NS_LIST return is a shipno */ + if (!snxtitem(&ni, EF_SHIP, cp)) { + pr("Specify at least one ship\n"); return RET_SYN; - type = sarg_type(cp); - if (type == NS_AREA) { - if (!snxtsct(&ns, cp)) - return RET_SYN; - tech = tfact(player->cnum, 8.0); - if (tech > ((double)WORLD_Y/4.0)) - tech = ((double)WORLD_Y/4.0); - if (tech > ((double)WORLD_X/8.0)) - tech = ((double)WORLD_X/8.0); - while (nxtsct(&ns, §)) { - if (sect.sct_type != SCT_RADAR) - continue; - if (!player->owner) - continue; - radmap(sect.sct_x, sect.sct_y, (int)sect.sct_effic, - (int) (tech * 2.0), 0.0); - } - } else if (type == NS_LIST || type == NS_GROUP) { - if (!from_unit){ - /* assumes a NS_LIST return is a shipno */ - if (!snxtitem(&ni, EF_SHIP, cp)) { - pr("Specify at least one ship\n"); - return RET_SYN; - } - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner) - continue; - if (mchr[(int)ship.shp_type].m_flags & M_SONAR) - tf = techfact(ship.shp_tech, 1.0); - else - tf = 0.0; - pr("%s at ", prship(&ship)); - tech = techfact(ship.shp_tech, - (double) mchr[(int)ship.shp_type].m_vrnge); - if (tech > ((double)WORLD_Y/2.0)) - tech = ((double)WORLD_Y/2.0); - if (tech > ((double)WORLD_X/4.0)) - tech = ((double)WORLD_X/4.0); - radmap(ship.shp_x, ship.shp_y, ship.shp_effic, - (int) tech, tf); - } - }else{ - /* from a land unit */ - if (!snxtitem(&ni, EF_LAND, cp)) { - pr("Specify at least one unit\n"); - return RET_SYN; - } - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner) - continue; - if (!(lchr[(int)land.lnd_type].l_flags & L_RADAR)){ - pr("%s can't use radar!\n", - prland(&land)); - continue; - } - if (land.lnd_ship >= 0){ - pr("Units on ships can't use radar!\n"); - continue; - } - tf = 0.0; - pr("%s at ", prland(&land)); - tech = techfact(land.lnd_tech, - (double) land.lnd_spy); - if (tech > ((double)WORLD_Y/2.0)) - tech = ((double)WORLD_Y/2.0); - if (tech > ((double)WORLD_X/4.0)) - tech = ((double)WORLD_X/4.0); - radmap(land.lnd_x, land.lnd_y, land.lnd_effic, - (int) tech, tf); - } - } - } else { - if (!from_unit) - pr("Must use a ship or sector specifier\n"); + } + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner) + continue; + if (mchr[(int)ship.shp_type].m_flags & M_SONAR) + tf = techfact(ship.shp_tech, 1.0); else - pr("Must use a unit or sector specifier\n"); + tf = 0.0; + pr("%s at ", prship(&ship)); + tech = techfact(ship.shp_tech, + (double)mchr[(int)ship.shp_type].m_vrnge); + if (tech > ((double)WORLD_Y / 2.0)) + tech = ((double)WORLD_Y / 2.0); + if (tech > ((double)WORLD_X / 4.0)) + tech = ((double)WORLD_X / 4.0); + radmap(ship.shp_x, ship.shp_y, ship.shp_effic, + (int)tech, tf); + } + } else { + /* from a land unit */ + if (!snxtitem(&ni, EF_LAND, cp)) { + pr("Specify at least one unit\n"); return RET_SYN; + } + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner) + continue; + if (!(lchr[(int)land.lnd_type].l_flags & L_RADAR)) { + pr("%s can't use radar!\n", prland(&land)); + continue; + } + if (land.lnd_ship >= 0) { + pr("Units on ships can't use radar!\n"); + continue; + } + tf = 0.0; + pr("%s at ", prland(&land)); + tech = techfact(land.lnd_tech, (double)land.lnd_spy); + if (tech > ((double)WORLD_Y / 2.0)) + tech = ((double)WORLD_Y / 2.0); + if (tech > ((double)WORLD_X / 4.0)) + tech = ((double)WORLD_X / 4.0); + radmap(land.lnd_x, land.lnd_y, land.lnd_effic, + (int)tech, tf); + } } - return RET_OK; + } else { + if (!from_unit) + pr("Must use a ship or sector specifier\n"); + else + pr("Must use a unit or sector specifier\n"); + return RET_SYN; + } + return RET_OK; } diff --git a/src/lib/commands/rang.c b/src/lib/commands/rang.c index ef9d59d85..f04487a1d 100644 --- a/src/lib/commands/rang.c +++ b/src/lib/commands/rang.c @@ -46,63 +46,62 @@ int range(void) { - struct nstr_item np; - struct plnstr plane; - int i; - s_char *p; - s_char buf[1024]; + struct nstr_item np; + struct plnstr plane; + int i; + s_char *p; + s_char buf[1024]; - if (!snxtitem(&np, EF_PLANE, player->argp[1])) - return RET_SYN; - while (nxtitem(&np, (s_char *)&plane)) { - if (!player->owner || plane.pln_own == 0) - continue; - p = getstarg(player->argp[2],"New range? ", buf); - if (!check_plane_ok(&plane)) - return RET_SYN; - if (!p || (i = atoi(p)) < 0) - continue; - plane.pln_range = (plane.pln_range_max < i) ? - plane.pln_range_max : i; - pr("Plane %d range changed to %d\n",plane.pln_uid, - plane.pln_range); + if (!snxtitem(&np, EF_PLANE, player->argp[1])) + return RET_SYN; + while (nxtitem(&np, (s_char *)&plane)) { + if (!player->owner || plane.pln_own == 0) + continue; + p = getstarg(player->argp[2], "New range? ", buf); + if (!check_plane_ok(&plane)) + return RET_SYN; + if (!p || (i = atoi(p)) < 0) + continue; + plane.pln_range = (plane.pln_range_max < i) ? + plane.pln_range_max : i; + pr("Plane %d range changed to %d\n", plane.pln_uid, + plane.pln_range); - putplane(plane.pln_uid,&plane); - } + putplane(plane.pln_uid, &plane); + } - return RET_OK; + return RET_OK; } int lrange(void) { - struct nstr_item np; - struct lndstr land; - struct lchrstr *lcp; - int i; - s_char *p; - s_char prompt[128]; - s_char buf[128]; + struct nstr_item np; + struct lndstr land; + struct lchrstr *lcp; + int i; + s_char *p; + s_char prompt[128]; + s_char buf[128]; - if (!snxtitem(&np, EF_LAND, player->argp[1])) - return RET_SYN; - while (nxtitem(&np, (s_char *)&land)) { - if (!player->owner || land.lnd_own == 0) - continue; - lcp = &lchr[(int)land.lnd_type]; - sprintf(prompt, "New range for %s? ", prland(&land)); - if ((p = getstarg(player->argp[2], prompt, buf)) == 0) - return RET_SYN; - if (!check_land_ok(&land)) - return RET_SYN; - if ((i = atoi(p)) < 0) - continue; - land.lnd_rad_max = (i < land.lnd_rad) ? - i : land.lnd_rad; - pr("%s reaction radius changed to %d\n", prland(&land), - land.lnd_rad_max); - putland(land.lnd_uid,&land); - } + if (!snxtitem(&np, EF_LAND, player->argp[1])) + return RET_SYN; + while (nxtitem(&np, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + lcp = &lchr[(int)land.lnd_type]; + sprintf(prompt, "New range for %s? ", prland(&land)); + if ((p = getstarg(player->argp[2], prompt, buf)) == 0) + return RET_SYN; + if (!check_land_ok(&land)) + return RET_SYN; + if ((i = atoi(p)) < 0) + continue; + land.lnd_rad_max = (i < land.lnd_rad) ? i : land.lnd_rad; + pr("%s reaction radius changed to %d\n", prland(&land), + land.lnd_rad_max); + putland(land.lnd_uid, &land); + } - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/rea.c b/src/lib/commands/rea.c index d65b38e09..a6bb6de53 100644 --- a/src/lib/commands/rea.c +++ b/src/lib/commands/rea.c @@ -55,189 +55,184 @@ int rea(void) { - extern s_char *telnames[]; - register s_char *p; - register s_char *mbox; - s_char mbox_buf[256]; /* Maximum path length */ - struct telstr tgm; - FILE *telfp; - int teles; - int size; - unsigned int nbytes; - s_char buf[4096]; - int lasttype; - int lastcnum; - time_t lastdate; - int header; - int filelen; - s_char kind[80]; - int n; - int num = player->cnum; - struct natstr *np = getnatp(player->cnum); - time_t now; - time_t then; - time_t delta; - int first = 1; - int readit; + extern s_char *telnames[]; + register s_char *p; + register s_char *mbox; + s_char mbox_buf[256]; /* Maximum path length */ + struct telstr tgm; + FILE *telfp; + int teles; + int size; + unsigned int nbytes; + s_char buf[4096]; + int lasttype; + int lastcnum; + time_t lastdate; + int header; + int filelen; + s_char kind[80]; + int n; + int num = player->cnum; + struct natstr *np = getnatp(player->cnum); + time_t now; + time_t then; + time_t delta; + int first = 1; + int readit; - bzero(kind,80); - (void) time(&now); + bzero(kind, 80); + (void)time(&now); - if (*player->argp[0] == 'w') { - sprintf(kind,"announcement"); - if (player->argp[1] && isdigit(*player->argp[1])) { - delta = days(atoi(player->argp[1])); - then = now - delta; - } else - then = np->nat_annotim; - mbox = annfil; - } else { - sprintf(kind,"telegram"); - if (player->god && player->argp[1] != 0) { - if ((n = natarg(player->argp[1], "")) < 0) - return RET_SYN; - num = n; - } - mbox = mailbox(mbox_buf, num); - clear_telegram_is_new(player->cnum); + if (*player->argp[0] == 'w') { + sprintf(kind, "announcement"); + if (player->argp[1] && isdigit(*player->argp[1])) { + delta = days(atoi(player->argp[1])); + then = now - delta; + } else + then = np->nat_annotim; + mbox = annfil; + } else { + sprintf(kind, "telegram"); + if (player->god && player->argp[1] != 0) { + if ((n = natarg(player->argp[1], "")) < 0) + return RET_SYN; + num = n; } - + mbox = mailbox(mbox_buf, num); + clear_telegram_is_new(player->cnum); + } + #if !defined(_WIN32) - if ((telfp = fopen(mbox, "r+")) == 0) { + if ((telfp = fopen(mbox, "r+")) == 0) { #else - if ((telfp = fopen(mbox, "r+b")) == 0) { + if ((telfp = fopen(mbox, "r+b")) == 0) { #endif - logerror("telegram file %s", mbox); - return RET_FAIL; + logerror("telegram file %s", mbox); + return RET_FAIL; + } + teles = 0; + fseek(telfp, 0L, 0); + size = fsize(fileno(telfp)); + more: + lastdate = 0; + lastcnum = -1; + lasttype = -1; + while (fread((s_char *)&tgm, sizeof(tgm), 1, telfp) == 1) { + readit = 1; + if (tgm.tel_length < 0) { + logerror("bad telegram file header in %s", mbox); + break; + } + if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) { + pr("Bad telegram header. Skipping telegram...\n"); + readit = 0; + goto skip; + } + if (*kind == 'a') { + if (!player->god && (getrejects(tgm.tel_from, np) & REJ_ANNO)) { + readit = 0; + goto skip; + } + if (tgm.tel_date < then) { + readit = 0; + goto skip; + } } - teles = 0; - fseek(telfp, 0L, 0); - size = fsize(fileno(telfp)); -more: - lastdate = 0; - lastcnum = -1; - lasttype = -1; - while (fread((s_char *) &tgm, sizeof(tgm), 1, telfp) == 1) { - readit = 1; - if (tgm.tel_length < 0) { - logerror("bad telegram file header in %s", mbox); - break; - } - if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) { - pr("Bad telegram header. Skipping telegram...\n"); - readit = 0; - goto skip; - } - if (*kind == 'a') { - if (!player->god && - (getrejects(tgm.tel_from, np) & REJ_ANNO)) { - readit = 0; - goto skip; - } - if (tgm.tel_date < then) { - readit = 0; - goto skip; - } - } - if (first && *kind == 'a') { - pr("\nAnnouncements since %s", ctime(&then)); - first = 0; - } - header = 0; - if (tgm.tel_type != lasttype || tgm.tel_from != lastcnum) - header++; - if (abs((int)(tgm.tel_date - (long)lastdate)) > TEL_SECONDS) - header++; - if (header) { - pr("\n> "); - lastcnum = tgm.tel_from; - lasttype = tgm.tel_type; - pr("%s ", telnames[(int)tgm.tel_type]); - if ((tgm.tel_type == TEL_NORM) || - (tgm.tel_type == TEL_ANNOUNCE)) { - pr("from %s, (#%d)", - cname(tgm.tel_from), - tgm.tel_from); - } - if (tgm.tel_type == TEL_BULLETIN){ - pr("from %s, (#%d)", cname(tgm.tel_from), tgm.tel_from); - } - pr(" dated %s", ctime(&tgm.tel_date)); - lastdate = tgm.tel_date; - } - teles++; - skip: - while (tgm.tel_length > 0) { - nbytes = tgm.tel_length; - if (nbytes > sizeof(buf)-1) - nbytes = sizeof(buf)-1; - (void) fread(buf, sizeof(s_char), nbytes, telfp); - buf[nbytes] = 0; - if (readit) - prnf(buf); - tgm.tel_length -= nbytes; - } + if (first && *kind == 'a') { + pr("\nAnnouncements since %s", ctime(&then)); + first = 0; } - p=NULL; - if (teles > 0 && player->cnum == num) { /* } */ - pr("\n"); - if (teles == 1) { - if (chance(0.25)) - p = "Forget this one? "; - else - p = "Shall I burn it? "; - } else { - if (chance(0.25)) - p = "Into the shredder, boss? "; - else - p = "Can I throw away these old love letters? "; - } - if (player->god && *kind == 't') - p = getstarg(player->argp[2], p, buf); - else - p = getstarg(player->argp[1], p, buf); - if (p && *p == 'y') { - if ((filelen = fsize(fileno(telfp))) > size) { - pr("Wait a sec! A new %s has arrived...\n", kind); - /* force stdio to re-read tel file */ - (void) fflush(telfp); + header = 0; + if (tgm.tel_type != lasttype || tgm.tel_from != lastcnum) + header++; + if (abs((int)(tgm.tel_date - (long)lastdate)) > TEL_SECONDS) + header++; + if (header) { + pr("\n> "); + lastcnum = tgm.tel_from; + lasttype = tgm.tel_type; + pr("%s ", telnames[(int)tgm.tel_type]); + if ((tgm.tel_type == TEL_NORM) || + (tgm.tel_type == TEL_ANNOUNCE)) { + pr("from %s, (#%d)", cname(tgm.tel_from), tgm.tel_from); + } + if (tgm.tel_type == TEL_BULLETIN) { + pr("from %s, (#%d)", cname(tgm.tel_from), tgm.tel_from); + } + pr(" dated %s", ctime(&tgm.tel_date)); + lastdate = tgm.tel_date; + } + teles++; + skip: + while (tgm.tel_length > 0) { + nbytes = tgm.tel_length; + if (nbytes > sizeof(buf) - 1) + nbytes = sizeof(buf) - 1; + (void)fread(buf, sizeof(s_char), nbytes, telfp); + buf[nbytes] = 0; + if (readit) + prnf(buf); + tgm.tel_length -= nbytes; + } + } + p = NULL; + if (teles > 0 && player->cnum == num) { /* } */ + pr("\n"); + if (teles == 1) { + if (chance(0.25)) + p = "Forget this one? "; + else + p = "Shall I burn it? "; + } else { + if (chance(0.25)) + p = "Into the shredder, boss? "; + else + p = "Can I throw away these old love letters? "; + } + if (player->god && *kind == 't') + p = getstarg(player->argp[2], p, buf); + else + p = getstarg(player->argp[1], p, buf); + if (p && *p == 'y') { + if ((filelen = fsize(fileno(telfp))) > size) { + pr("Wait a sec! A new %s has arrived...\n", kind); + /* force stdio to re-read tel file */ + (void)fflush(telfp); #if !defined(_WIN32) - (void) fseek(telfp, (long)size, L_SET); + (void)fseek(telfp, (long)size, L_SET); #else - (void) fseek(telfp, (long)size, SEEK_SET); + (void)fseek(telfp, (long)size, SEEK_SET); #endif - size = filelen; - (void) time(&now); - goto more; - } - if (*kind == 'a') { - np->nat_annotim = now; - putnat(np); - } else { - /* Here, we just re-open the file for "w" only, - and that will wipe the file clean automatically */ - (void)fclose(telfp); + size = filelen; + (void)time(&now); + goto more; + } + if (*kind == 'a') { + np->nat_annotim = now; + putnat(np); + } else { + /* Here, we just re-open the file for "w" only, + and that will wipe the file clean automatically */ + (void)fclose(telfp); #if !defined(_WIN32) - telfp = fopen((char *)mbox, "w"); + telfp = fopen((char *)mbox, "w"); #else - telfp = fopen((char *)mbox, "wb"); + telfp = fopen((char *)mbox, "wb"); #endif - } - } - } - if (teles <= 0) { - if(player->cnum == num) - pr("No %ss for you at the moment...\n",kind); - else - pr("No %ss for %s at the moment...\n", kind, - cname(num)); + } } - (void) fclose(telfp); - if (np->nat_flags & NF_INFORM) { - pr_inform(player, "\n"); - np->nat_tgms = 0; - putnat(np); - } - return RET_OK; + } + if (teles <= 0) { + if (player->cnum == num) + pr("No %ss for you at the moment...\n", kind); + else + pr("No %ss for %s at the moment...\n", kind, cname(num)); + } + (void)fclose(telfp); + if (np->nat_flags & NF_INFORM) { + pr_inform(player, "\n"); + np->nat_tgms = 0; + putnat(np); + } + return RET_OK; } - diff --git a/src/lib/commands/real.c b/src/lib/commands/real.c index 8e084e396..691d31fd3 100644 --- a/src/lib/commands/real.c +++ b/src/lib/commands/real.c @@ -42,9 +42,9 @@ static void list_realm(int curr, struct natstr *natp) { - struct boundstr *b; - struct range abs; - struct range rel; + struct boundstr *b; + struct range abs; + struct range rel; abs.width = 0; abs.height = 0; @@ -54,60 +54,59 @@ list_realm(int curr, struct natstr *natp) abs.ly = b->b_yl; abs.hy = b->b_yh; xyrelrange(natp, &abs, &rel); - pr("Realm #%d is %d:%d,%d:%d\n", curr, - rel.lx, rel.hx, rel.ly, rel.hy); + pr("Realm #%d is %d:%d,%d:%d\n", curr, rel.lx, rel.hx, rel.ly, rel.hy); } int real(void) { - register struct boundstr *rp; - struct natstr *natp; - int curr; - int lastr; - struct range abs; - s_char *realmp = player->argp[1]; + register struct boundstr *rp; + struct natstr *natp; + int curr; + int lastr; + struct range abs; + s_char *realmp = player->argp[1]; - natp = getnatp(player->cnum); - if (!realmp) { - curr = 0; - lastr = MAXNOR - 1; - } else { - if (*realmp == '#') - ++realmp; - if (!isdigit(*realmp)) - return RET_SYN; - curr = lastr = atoi(realmp); - if (curr < 0 || curr >= MAXNOR) { - pr("Realm number must be in the range 0:%d\n", - MAXNOR-1); - return RET_SYN; - } + natp = getnatp(player->cnum); + if (!realmp) { + curr = 0; + lastr = MAXNOR - 1; + } else { + if (*realmp == '#') + ++realmp; + if (!isdigit(*realmp)) + return RET_SYN; + curr = lastr = atoi(realmp); + if (curr < 0 || curr >= MAXNOR) { + pr("Realm number must be in the range 0:%d\n", MAXNOR - 1); + return RET_SYN; } - abs.width = 0; - abs.height = 0; - if (player->argp[2] == 0) { - while (curr <= lastr) { - list_realm(curr, natp); - curr++; - } - } else { - if (sarg_type(player->argp[2]) != NS_AREA) - return RET_SYN; - if (!sarg_area(player->argp[2], &abs)) - return RET_SYN; - rp = &natp->nat_b[curr]; - rp->b_xl = abs.lx; - rp->b_xh = abs.hx - 1; - rp->b_yl = abs.ly; - rp->b_yh = abs.hy - 1; - natp->nat_b[curr] = *rp; - list_realm(curr, natp); - putnat(natp); + } + abs.width = 0; + abs.height = 0; + if (player->argp[2] == 0) { + while (curr <= lastr) { + list_realm(curr, natp); + curr++; } - return RET_OK; + } else { + if (sarg_type(player->argp[2]) != NS_AREA) + return RET_SYN; + if (!sarg_area(player->argp[2], &abs)) + return RET_SYN; + rp = &natp->nat_b[curr]; + rp->b_xl = abs.lx; + rp->b_xh = abs.hx - 1; + rp->b_yl = abs.ly; + rp->b_yh = abs.hy - 1; + natp->nat_b[curr] = *rp; + list_realm(curr, natp); + putnat(natp); + } + return RET_OK; } + /* dreal() { diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index df6902a40..b57830c28 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -50,96 +50,103 @@ int reco(void) { - s_char *p; - int mission_flags; - int tech; - coord tx, ty; - coord ax, ay; - int ap_to_target; - s_char flightpath[MAX_PATH_LEN]; - int cno; - struct nstr_item ni_bomb; - struct nstr_item ni_esc; - coord x, y; - struct sctstr target; - struct emp_qelem bomb_list; - struct emp_qelem esc_list; - int wantflags; - struct sctstr ap_sect; - s_char buf[1024]; + s_char *p; + int mission_flags; + int tech; + coord tx, ty; + coord ax, ay; + int ap_to_target; + s_char flightpath[MAX_PATH_LEN]; + int cno; + struct nstr_item ni_bomb; + struct nstr_item ni_esc; + coord x, y; + struct sctstr target; + struct emp_qelem bomb_list; + struct emp_qelem esc_list; + int wantflags; + struct sctstr ap_sect; + s_char buf[1024]; - wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) - return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); - if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 || *p == 0) - return RET_SYN; - if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) - return RET_SYN; - if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && - getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { - pr("Assembly point not owned by you or an ally!\n"); - return RET_SYN; - } - ax = x; - ay = y; - if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, - 0, P_FLYING) == 0 || *p == 0) - return RET_SYN; - tx = ax; - ty = ay; - (void) pathtoxy(flightpath, &tx, &ty, fcost); - pr("target is %s\n", xyas(tx, ty, player->cnum)); - getsect(tx, ty, &target); - cno = -1; - mission_flags = 0; - if (pln_onewaymission(&target, &cno, &wantflags) < 0) - return RET_SYN; - ap_to_target = strlen(flightpath); - if (*(flightpath+strlen(flightpath)-1) == 'h') - ap_to_target--; - pr("range to target is %d\n", ap_to_target); - /* - * select planes within range - */ - pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, - 1, wantflags, P_M|P_O); - if (QEMPTY(&bomb_list)) { - pr("No planes could be equipped for the mission.\n"); - return RET_FAIL; - } - wantflags |= P_F; - wantflags |= P_ESC; - pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, - 1, wantflags, P_M|P_O); - /* - * now arm and equip the bombers, transports, whatever. - */ - tech=0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - mission_flags |= P_A; - mission_flags = pln_arm(&bomb_list, ap_to_target, 'r', 0, P_S|P_I, mission_flags,&tech); - if (QEMPTY(&bomb_list)) { - pr("No planes could be equipped for the mission.\n"); - return RET_FAIL; - } - mission_flags = pln_arm(&esc_list, ap_to_target, 'r', 0, P_F, mission_flags,&tech); - mission_flags |= PM_R; + wantflags = 0; + if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + return RET_SYN; + if (!snxtitem + (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf))) + pr("No escorts...\n"); + if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0 + || *p == 0) + return RET_SYN; + if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect)) + return RET_SYN; + if (ap_sect.sct_own && ap_sect.sct_own != player->cnum && + getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) { + pr("Assembly point not owned by you or an ally!\n"); + return RET_SYN; + } + ax = x; + ay = y; + if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, + 0, P_FLYING) == 0 || *p == 0) + return RET_SYN; + tx = ax; + ty = ay; + (void)pathtoxy(flightpath, &tx, &ty, fcost); + pr("target is %s\n", xyas(tx, ty, player->cnum)); + getsect(tx, ty, &target); + cno = -1; + mission_flags = 0; + if (pln_onewaymission(&target, &cno, &wantflags) < 0) + return RET_SYN; + ap_to_target = strlen(flightpath); + if (*(flightpath + strlen(flightpath) - 1) == 'h') + ap_to_target--; + pr("range to target is %d\n", ap_to_target); + /* + * select planes within range + */ + pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, + 1, wantflags, P_M | P_O); + if (QEMPTY(&bomb_list)) { + pr("No planes could be equipped for the mission.\n"); + return RET_FAIL; + } + wantflags |= P_F; + wantflags |= P_ESC; + pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, + 1, wantflags, P_M | P_O); + /* + * now arm and equip the bombers, transports, whatever. + */ + tech = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + mission_flags |= P_A; + mission_flags = + pln_arm(&bomb_list, ap_to_target, 'r', 0, P_S | P_I, mission_flags, + &tech); + if (QEMPTY(&bomb_list)) { + pr("No planes could be equipped for the mission.\n"); + return RET_FAIL; + } + mission_flags = + pln_arm(&esc_list, ap_to_target, 'r', 0, P_F, mission_flags, + &tech); + mission_flags |= PM_R; - if (*player->argp[0] == 's') - mission_flags |= PM_S; + if (*player->argp[0] == 's') + mission_flags |= PM_S; - ac_encounter(&bomb_list,&esc_list,ax,ay,flightpath,mission_flags,0,0,0); - if (QEMPTY(&bomb_list)) { - pr("No planes got through fighter defenses\n"); - } else { - getsect(tx, ty, &target); - pln_newlanding(&bomb_list, tx, ty, cno); - pln_newlanding(&esc_list, tx, ty, cno); - } - pln_put(&bomb_list); - pln_put(&esc_list); - return RET_OK; + ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags, + 0, 0, 0); + if (QEMPTY(&bomb_list)) { + pr("No planes got through fighter defenses\n"); + } else { + getsect(tx, ty, &target); + pln_newlanding(&bomb_list, tx, ty, cno); + pln_newlanding(&esc_list, tx, ty, cno); + } + pln_put(&bomb_list); + pln_put(&esc_list); + return RET_OK; } diff --git a/src/lib/commands/reje.c b/src/lib/commands/reje.c index 999340452..dfa7f77e5 100644 --- a/src/lib/commands/reje.c +++ b/src/lib/commands/reje.c @@ -44,73 +44,83 @@ int reje(void) { - register s_char *p; - int rel; - int do_undo; - struct natstr nat; - struct nstr_item ni; - s_char buf[1024]; + register s_char *p; + int rel; + int do_undo; + struct natstr nat; + struct nstr_item ni; + s_char buf[1024]; - if ((p = getstarg(player->argp[1], "reject or accept? ", buf)) == 0) - return RET_SYN; - switch (*p) { - case 'r': - do_undo = 1; - break; - case 'a': - do_undo = 0; - break; - default: - pr("That's not one of the choices!\n"); - return RET_SYN; - } - if ((p = getstarg(player->argp[2], "mail, treaties, loans, or announcements? ", buf)) == 0) - return RET_SYN; - switch (*p) { - case 'a': - rel = REJ_ANNO; - break; - case 'l': - rel = REJ_LOAN; - break; - case 'm': - rel = REJ_TELE; - break; - case 't': - rel = REJ_TREA; - break; - default: - pr("That's not one of the choices!\n"); - return RET_SYN; - } - if (!snxtitem(&ni, EF_NATION, player->argp[3])) - return RET_SYN; - while (nxtitem(&ni, (s_char *) &nat)) { + if ((p = getstarg(player->argp[1], "reject or accept? ", buf)) == 0) + return RET_SYN; + switch (*p) { + case 'r': + do_undo = 1; + break; + case 'a': + do_undo = 0; + break; + default: + pr("That's not one of the choices!\n"); + return RET_SYN; + } + if ((p = + getstarg(player->argp[2], + "mail, treaties, loans, or announcements? ", buf)) == 0) + return RET_SYN; + switch (*p) { + case 'a': + rel = REJ_ANNO; + break; + case 'l': + rel = REJ_LOAN; + break; + case 'm': + rel = REJ_TELE; + break; + case 't': + rel = REJ_TREA; + break; + default: + pr("That's not one of the choices!\n"); + return RET_SYN; + } + if (!snxtitem(&ni, EF_NATION, player->argp[3])) + return RET_SYN; + while (nxtitem(&ni, (s_char *)&nat)) { #if 0 - if ((nat.nat_stat & STAT_NORM) == 0) { - pr("You may not reject/accept stuff from %s\nbecause they are not a normal country.\n", nat.nat_cnam); - continue; - } + if ((nat.nat_stat & STAT_NORM) == 0) { + pr("You may not reject/accept stuff from %s\nbecause they are not a normal country.\n", nat.nat_cnam); + continue; + } #endif - if (nat.nat_stat & STAT_GOD) { - pr("You may not reject/accept stuff from %s\nbecause they are a deity.\n", nat.nat_cnam); - continue; - } - if (opt_HIDDEN) { - if (!getcontact(getnatp(player->cnum), ni.cur)) - continue; - } - switch(rel){ - case REJ_ANNO: pr("%s annos from %s\n",(do_undo == 1 ? "Rejecting" : "Accepting"),nat.nat_cnam); - break; - case REJ_LOAN: pr("%s loans from %s\n",(do_undo == 1 ? "Rejecting" : "Accepting"),nat.nat_cnam); - break; - case REJ_TELE: pr("%s teles from %s\n",(do_undo == 1 ? "Rejecting" : "Accepting"),nat.nat_cnam); - break; - case REJ_TREA: pr("%s treaties from %s\n",(do_undo == 1 ? "Rejecting" : "Accepting"),nat.nat_cnam); - break; - } - setrej(player->cnum, (natid)ni.cur, do_undo, rel); + if (nat.nat_stat & STAT_GOD) { + pr("You may not reject/accept stuff from %s\nbecause they are a deity.\n", nat.nat_cnam); + continue; + } + if (opt_HIDDEN) { + if (!getcontact(getnatp(player->cnum), ni.cur)) + continue; + } + switch (rel) { + case REJ_ANNO: + pr("%s annos from %s\n", + (do_undo == 1 ? "Rejecting" : "Accepting"), nat.nat_cnam); + break; + case REJ_LOAN: + pr("%s loans from %s\n", + (do_undo == 1 ? "Rejecting" : "Accepting"), nat.nat_cnam); + break; + case REJ_TELE: + pr("%s teles from %s\n", + (do_undo == 1 ? "Rejecting" : "Accepting"), nat.nat_cnam); + break; + case REJ_TREA: + pr("%s treaties from %s\n", + (do_undo == 1 ? "Rejecting" : "Accepting"), nat.nat_cnam); + break; } - return RET_OK; + setrej(player->cnum, (natid)ni.cur, do_undo, rel); + } + return RET_OK; } diff --git a/src/lib/commands/rela.c b/src/lib/commands/rela.c index 94223c9e5..b75fb5524 100644 --- a/src/lib/commands/rela.c +++ b/src/lib/commands/rela.c @@ -49,54 +49,54 @@ int rela(void) { - struct natstr *natp; - struct natstr *np; - natid cn; - natid as; - int n; + struct natstr *natp; + struct natstr *np; + natid cn; + natid as; + int n; - if (player->argp[1] == 0) - as = player->cnum; - else { - if ((n = natarg(player->argp[1], "Which country? ")) < 0) { - pr("Bad country number\n"); - return RET_SYN; - } - as = (natid) n; + if (player->argp[1] == 0) + as = player->cnum; + else { + if ((n = natarg(player->argp[1], "Which country? ")) < 0) { + pr("Bad country number\n"); + return RET_SYN; } - if ((natp = getnatp(as)) == 0) { - pr("Bad country number %d\n", player->cnum); - return RET_SYN; + as = (natid)n; + } + if ((natp = getnatp(as)) == 0) { + pr("Bad country number %d\n", player->cnum); + return RET_SYN; + } + pr("\t%s Diplomatic Relations Report\t", cname(as)); + prdate(); + if (opt_SLOW_WAR) { + pr("\n Formal Relations %5s theirs\n", + player->cnum == as ? "yours" : "his"); + } else { + pr("\n Formal Relations %5s theirs\n", + player->cnum == as ? "yours" : "his"); + } + for (cn = 1; cn < MAXNOC; cn++) { + if ((np = getnatp(cn)) == 0) + break; + if (cn == as) + continue; + if ((np->nat_stat & STAT_NORM) == 0 && + (np->nat_stat & STAT_SANCT) == 0) + continue; + if (opt_HIDDEN) { + if (!player->god && !getcontact(natp, cn)) + continue; + if (!player->god && !getcontact(getnatp(player->cnum), cn)) + continue; } - pr("\t%s Diplomatic Relations Report\t", cname(as)); - prdate(); + pr("%3d) %-20.20s ", cn, cname(cn)); if (opt_SLOW_WAR) { - pr("\n Formal Relations %5s theirs\n", - player->cnum == as ? "yours" : "his"); + pr("%-10s %s\n", relatename(natp, cn), relatename(np, as)); } else { - pr("\n Formal Relations %5s theirs\n", - player->cnum == as ? "yours" : "his"); + pr("%-9s %s\n", relatename(natp, cn), relatename(np, as)); } - for (cn=1; cn < MAXNOC; cn++) { - if ((np = getnatp(cn)) == 0) - break; - if (cn == as) - continue; - if ((np->nat_stat & STAT_NORM) == 0 && - (np->nat_stat & STAT_SANCT) == 0) - continue; - if (opt_HIDDEN) { - if (!player->god && !getcontact(natp, cn)) - continue; - if (!player->god && !getcontact(getnatp(player->cnum), cn)) - continue; - } - pr("%3d) %-20.20s ", cn, cname(cn)); - if (opt_SLOW_WAR) { - pr("%-10s %s\n", relatename(natp, cn), relatename(np, as)); - } else { - pr("%-9s %s\n", relatename(natp, cn), relatename(np, as)); - } - } - return RET_OK; + } + return RET_OK; } diff --git a/src/lib/commands/repa.c b/src/lib/commands/repa.c index ddf2c1276..560d4c37e 100644 --- a/src/lib/commands/repa.c +++ b/src/lib/commands/repa.c @@ -44,103 +44,103 @@ int repa(void) { - struct lonstr loan; - struct natstr *natp; - struct natstr *loaner; - int loan_num; - long payment; - long owe; - long due; - long last_payment; - long normaltime; - long doubletime; - double rate_per_sec,amt; - s_char *cp; - time_t now; - s_char buf[1024]; + struct lonstr loan; + struct natstr *natp; + struct natstr *loaner; + int loan_num; + long payment; + long owe; + long due; + long last_payment; + long normaltime; + long doubletime; + double rate_per_sec, amt; + s_char *cp; + time_t now; + s_char buf[1024]; - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; - } - natp = getnatp(player->cnum); - cp = getstarg(player->argp[1], "Repay loan #? ", buf); - if (cp == 0) - return RET_SYN; - loan_num = atoi(cp); - if (loan_num < 0) - return RET_SYN; - if (!getloan(loan_num, &loan) || loan.l_lonee != player->cnum - || loan.l_status != LS_SIGNED) { - pr("You don't owe anything on that loan.\n"); - return RET_FAIL; - } - (void) time(&now); - due = loan.l_duedate; - last_payment = loan.l_lastpay; - if (now < due) { - normaltime = now - last_payment; - doubletime = 0; - } - if (last_payment < due && due < now) { - normaltime = due - last_payment; - doubletime = now - due; - } - if (due < last_payment) { - normaltime = 0; - doubletime = now - last_payment; - } - rate_per_sec = loan.l_irate / - ((double) loan.l_ldur * SECS_PER_DAY * 100.0); + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; + } + natp = getnatp(player->cnum); + cp = getstarg(player->argp[1], "Repay loan #? ", buf); + if (cp == 0) + return RET_SYN; + loan_num = atoi(cp); + if (loan_num < 0) + return RET_SYN; + if (!getloan(loan_num, &loan) || loan.l_lonee != player->cnum + || loan.l_status != LS_SIGNED) { + pr("You don't owe anything on that loan.\n"); + return RET_FAIL; + } + (void)time(&now); + due = loan.l_duedate; + last_payment = loan.l_lastpay; + if (now < due) { + normaltime = now - last_payment; + doubletime = 0; + } + if (last_payment < due && due < now) { + normaltime = due - last_payment; + doubletime = now - due; + } + if (due < last_payment) { + normaltime = 0; + doubletime = now - last_payment; + } + rate_per_sec = loan.l_irate / + ((double)loan.l_ldur * SECS_PER_DAY * 100.0); - owe = (long) (loan.l_amtdue * - ((double) normaltime * rate_per_sec + 1.0 + - (double) doubletime * rate_per_sec * 2.0) + 0.5); - amt = ((double) normaltime * rate_per_sec + 1.0 + - (double) doubletime * rate_per_sec * 2.0); - if (((1 << 30) / amt) < loan.l_amtdue) - owe = (1 << 30); - else - owe = (long) (loan.l_amtdue * - ((double) normaltime * rate_per_sec + 1.0 + - (double) doubletime * rate_per_sec * 2.0) + 0.5); - if ((cp = getstarg(player->argp[2], "amount? ", buf)) == 0) - return RET_SYN; - if (!check_loan_ok(&loan)) - return RET_FAIL; - payment = atoi(cp); - if (payment <= 0) - return RET_SYN; - if (payment > owe) { - pr("You don't owe that much.\n"); - return RET_FAIL; - } - if (natp->nat_money < payment) { - pr("You only have $%d.\n", natp->nat_money); - return RET_FAIL; - } - player->dolcost += payment; - loaner = getnatp(loan.l_loner); - loaner->nat_money += payment; - putnat(loaner); - (void) time(&loan.l_lastpay); - if (owe <= payment) { - wu(0, loan.l_loner, "Country #%d paid off loan #%d with $%d\n", - player->cnum, loan_num, payment); - nreport(player->cnum, N_REPAY_LOAN, loan.l_loner, 1); - loan.l_status = LS_FREE; - loan.l_ldur = 0; - pr("Congratulations, you've paid off the loan!\n"); - } else { - wu(0, loan.l_loner, - "Country #%d paid $%.2f on loan %d\n", player->cnum, - (double) payment, loan_num); - loan.l_amtdue = owe - payment; - loan.l_amtpaid += payment; - } - if (!putloan(loan_num, &loan)) { - pr("Can't save loan; get help!\n"); - return RET_SYS; - } - return RET_OK; + owe = (long)(loan.l_amtdue * + ((double)normaltime * rate_per_sec + 1.0 + + (double)doubletime * rate_per_sec * 2.0) + 0.5); + amt = ((double)normaltime * rate_per_sec + 1.0 + + (double)doubletime * rate_per_sec * 2.0); + if (((1 << 30) / amt) < loan.l_amtdue) + owe = (1 << 30); + else + owe = (long)(loan.l_amtdue * + ((double)normaltime * rate_per_sec + 1.0 + + (double)doubletime * rate_per_sec * 2.0) + 0.5); + if ((cp = getstarg(player->argp[2], "amount? ", buf)) == 0) + return RET_SYN; + if (!check_loan_ok(&loan)) + return RET_FAIL; + payment = atoi(cp); + if (payment <= 0) + return RET_SYN; + if (payment > owe) { + pr("You don't owe that much.\n"); + return RET_FAIL; + } + if (natp->nat_money < payment) { + pr("You only have $%d.\n", natp->nat_money); + return RET_FAIL; + } + player->dolcost += payment; + loaner = getnatp(loan.l_loner); + loaner->nat_money += payment; + putnat(loaner); + (void)time(&loan.l_lastpay); + if (owe <= payment) { + wu(0, loan.l_loner, "Country #%d paid off loan #%d with $%d\n", + player->cnum, loan_num, payment); + nreport(player->cnum, N_REPAY_LOAN, loan.l_loner, 1); + loan.l_status = LS_FREE; + loan.l_ldur = 0; + pr("Congratulations, you've paid off the loan!\n"); + } else { + wu(0, loan.l_loner, + "Country #%d paid $%.2f on loan %d\n", player->cnum, + (double)payment, loan_num); + loan.l_amtdue = owe - payment; + loan.l_amtpaid += payment; + } + if (!putloan(loan_num, &loan)) { + pr("Can't save loan; get help!\n"); + return RET_SYS; + } + return RET_OK; } diff --git a/src/lib/commands/repo.c b/src/lib/commands/repo.c index f577565b8..f03b68ceb 100644 --- a/src/lib/commands/repo.c +++ b/src/lib/commands/repo.c @@ -48,209 +48,226 @@ #include "optlist.h" struct stats { - double res; - double tech; - double edu; - double hap; - int stat; + double res; + double tech; + double edu; + double hap; + int stat; }; -static void printdiff(int mystat, double ours, struct natstr *natp, int what); -static void repo_header(void); -static void repo_list(struct stats *stat, natid cn, struct natstr *natp); +static void printdiff(int mystat, double ours, struct natstr *natp, + int what); +static void repo_header(void); +static void repo_list(struct stats *stat, natid cn, struct natstr *natp); -static int check(s_char *buf, double theirs, double min, double max, int shift, int what, int tolerance); +static int check(s_char *buf, double theirs, double min, double max, + int shift, int what, int tolerance); int repo(void) { - struct natstr *natp; - struct stats mystat; - struct natstr nat; - struct nstr_item ni; - int first; + struct natstr *natp; + struct stats mystat; + struct natstr nat; + struct nstr_item ni; + int first; - if (!snxtitem(&ni, EF_NATION, player->argp[1])) - return RET_SYN; - prdate(); - natp = getnatp(player->cnum); - bzero((s_char *)&mystat, sizeof(struct stats)); - mystat.stat = natp->nat_stat; - if (mystat.stat & STAT_NORM) { - mystat.res = natp->nat_level[NAT_RLEV]; - mystat.tech = natp->nat_level[NAT_TLEV]; - mystat.edu = natp->nat_level[NAT_ELEV]; - mystat.hap = natp->nat_level[NAT_HLEV]; - } + if (!snxtitem(&ni, EF_NATION, player->argp[1])) + return RET_SYN; + prdate(); + natp = getnatp(player->cnum); + bzero((s_char *)&mystat, sizeof(struct stats)); + mystat.stat = natp->nat_stat; + if (mystat.stat & STAT_NORM) { + mystat.res = natp->nat_level[NAT_RLEV]; + mystat.tech = natp->nat_level[NAT_TLEV]; + mystat.edu = natp->nat_level[NAT_ELEV]; + mystat.hap = natp->nat_level[NAT_HLEV]; + } + if (opt_HIDDEN) { + repo_header(); + first = 0; + } else { + first = 1; + } + while (nxtitem(&ni, (s_char *)&nat)) { + if (!(nat.nat_stat & STAT_INUSE)) + continue; if (opt_HIDDEN) { + if (!player->god && !getcontact(getnatp(player->cnum), ni.cur)) + continue; + } + if (first) { repo_header(); first = 0; - } else { - first = 1; } - while (nxtitem(&ni, (s_char *) &nat)) { - if (!(nat.nat_stat & STAT_INUSE)) - continue; - if (opt_HIDDEN) { - if (!player->god && - !getcontact(getnatp(player->cnum), ni.cur)) - continue; - } - if (first) { - repo_header(); - first = 0; - } - repo_list(&mystat, (natid)ni.cur, &nat); - } - return RET_OK; + repo_list(&mystat, (natid)ni.cur, &nat); + } + return RET_OK; } static void repo_header(void) { - pr(" # name tech research education happiness "); - if (player->god) - pr("capital\n"); - else { - if (opt_HIDDEN) - pr("\n"); - else - pr(" status\n"); - } + pr(" # name tech research education happiness "); + if (player->god) + pr("capital\n"); + else { + if (opt_HIDDEN) + pr("\n"); + else + pr(" status\n"); + } } static void repo_list(struct stats *stat, natid cn, struct natstr *natp) { - struct sctstr cap; + struct sctstr cap; - if (player->god) { - pr(" %-3d %-14.14s ", cn, natp->nat_cnam); - pr(" %7.2f %7.2f %7.2f %7.2f", - natp->nat_level[NAT_TLEV], - natp->nat_level[NAT_RLEV], - natp->nat_level[NAT_ELEV], - natp->nat_level[NAT_HLEV]); - prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, - player->cnum); - return; - } - switch (natp->nat_stat & (STAT_NORM|STAT_GOD|STAT_NEW|STAT_SANCT)) { - case STAT_NORM: - case (STAT_NORM|STAT_SANCT): - pr(" %-3d %-14.14s ", cn, natp->nat_cnam); - printdiff(stat->stat, stat->tech, natp, NAT_TLEV); - printdiff(stat->stat, stat->res, natp, NAT_RLEV); - printdiff(stat->stat, stat->edu, natp, NAT_ELEV); - printdiff(stat->stat, stat->hap, natp, NAT_HLEV); - getsect(natp->nat_xcap, natp->nat_ycap, &cap); - if (opt_HIDDEN) { - pr("\n"); - } else { - if ((cap.sct_own != cn) || - (cap.sct_type != SCT_CAPIT && - cap.sct_type != SCT_MOUNT) || - (natp->nat_flags & NF_SACKED)) - pr("In flux\n"); - else if (natp->nat_money <= 0) - pr("Broke\n"); - else - pr("Active\n"); - } - break; - case STAT_SANCT: - break; - case STAT_NEW: - case 0: - break; - case STAT_SANCT|STAT_NORM|STAT_GOD: - case STAT_NORM|STAT_GOD: - case STAT_GOD: - break; - default: - pr("???? ???? ???? ????\n"); - break; + if (player->god) { + pr(" %-3d %-14.14s ", cn, natp->nat_cnam); + pr(" %7.2f %7.2f %7.2f %7.2f", + natp->nat_level[NAT_TLEV], + natp->nat_level[NAT_RLEV], + natp->nat_level[NAT_ELEV], natp->nat_level[NAT_HLEV]); + prxy(" %4d,%-4d\n", natp->nat_xcap, natp->nat_ycap, player->cnum); + return; + } + switch (natp-> + nat_stat & (STAT_NORM | STAT_GOD | STAT_NEW | STAT_SANCT)) { + case STAT_NORM: + case (STAT_NORM | STAT_SANCT): + pr(" %-3d %-14.14s ", cn, natp->nat_cnam); + printdiff(stat->stat, stat->tech, natp, NAT_TLEV); + printdiff(stat->stat, stat->res, natp, NAT_RLEV); + printdiff(stat->stat, stat->edu, natp, NAT_ELEV); + printdiff(stat->stat, stat->hap, natp, NAT_HLEV); + getsect(natp->nat_xcap, natp->nat_ycap, &cap); + if (opt_HIDDEN) { + pr("\n"); + } else { + if ((cap.sct_own != cn) || + (cap.sct_type != SCT_CAPIT && + cap.sct_type != SCT_MOUNT) || + (natp->nat_flags & NF_SACKED)) + pr("In flux\n"); + else if (natp->nat_money <= 0) + pr("Broke\n"); + else + pr("Active\n"); } + break; + case STAT_SANCT: + break; + case STAT_NEW: + case 0: + break; + case STAT_SANCT | STAT_NORM | STAT_GOD: + case STAT_NORM | STAT_GOD: + case STAT_GOD: + break; + default: + pr("???? ???? ???? ????\n"); + break; + } } static void printdiff(int mystat, double ours, struct natstr *natp, int what) { - double theirs; - int shift; - int tolerance; - s_char buf[128]; - - if (natp->nat_cnum == player->cnum) { - pr(" %7.2f ", ours); - return; - } - if (ours && mystat & STAT_NORM && - natp->nat_stat &STAT_NORM) { - theirs = natp->nat_level[what]; - if ((shift = min((int)theirs, (int)ours) - 100) > 0) { - ours -= shift; - theirs -= shift; - } else - shift = 0; - switch (what) { - case NAT_TLEV: - tolerance = 20; break; - case NAT_RLEV: - tolerance = 10; break; - default: - tolerance = 5; - } - if (tolerance > 2 * ours) - tolerance = (int)(2 * ours); - if (check(buf, theirs, 2 * ours, -1.0, shift, what, tolerance)); - else if (check(buf, theirs, 1.5*ours, 2.0*ours, shift, what, tolerance)); - else if (check(buf, theirs, 1.2*ours, 1.5*ours, shift, what, tolerance)); - else if (check(buf, theirs, 1.1*ours, 1.2*ours, shift, what, tolerance)); - else if (check(buf, theirs, ours/1.1, 1.1*ours, shift, what, tolerance)); - else if (check(buf, theirs, ours/1.2, ours/1.1, shift, what, tolerance)); - else if (check(buf, theirs, ours/1.5, ours/1.2, shift, what, tolerance)); - else if (check(buf, theirs, ours/2.0, ours/1.5, shift, what, tolerance)); - else if (check(buf, theirs, -1.0, ours/2.0, shift, what, tolerance)); - else sprintf(buf, " n/a"); + double theirs; + int shift; + int tolerance; + s_char buf[128]; + + if (natp->nat_cnum == player->cnum) { + pr(" %7.2f ", ours); + return; + } + if (ours && mystat & STAT_NORM && natp->nat_stat & STAT_NORM) { + theirs = natp->nat_level[what]; + if ((shift = min((int)theirs, (int)ours) - 100) > 0) { + ours -= shift; + theirs -= shift; } else - sprintf(buf, " n/a"); + shift = 0; + switch (what) { + case NAT_TLEV: + tolerance = 20; + break; + case NAT_RLEV: + tolerance = 10; + break; + default: + tolerance = 5; + } + if (tolerance > 2 * ours) + tolerance = (int)(2 * ours); + if (check(buf, theirs, 2 * ours, -1.0, shift, what, tolerance)) ; + else if (check + (buf, theirs, 1.5 * ours, 2.0 * ours, shift, what, + tolerance)) ; + else if (check + (buf, theirs, 1.2 * ours, 1.5 * ours, shift, what, + tolerance)) ; + else if (check + (buf, theirs, 1.1 * ours, 1.2 * ours, shift, what, + tolerance)) ; + else if (check + (buf, theirs, ours / 1.1, 1.1 * ours, shift, what, + tolerance)) ; + else if (check + (buf, theirs, ours / 1.2, ours / 1.1, shift, what, + tolerance)) ; + else if (check + (buf, theirs, ours / 1.5, ours / 1.2, shift, what, + tolerance)) ; + else if (check + (buf, theirs, ours / 2.0, ours / 1.5, shift, what, + tolerance)) ; + else if (check + (buf, theirs, -1.0, ours / 2.0, shift, what, tolerance)) ; + else + sprintf(buf, " n/a"); + } else + sprintf(buf, " n/a"); - pr("%-11s ", buf); + pr("%-11s ", buf); } static int -check(s_char *buf, double theirs, double min, double max, int shift, int what, int tolerance) +check(s_char *buf, double theirs, double min, double max, int shift, + int what, int tolerance) { - double shove; + double shove; - if (min < 0) { - if (theirs <= max) { - if (max < tolerance) - max = tolerance; - sprintf(buf, " 0 - %d", (int)max + shift); - return 1; - } - } else if (max < 0) { - if (theirs >= min) { - sprintf(buf, " >= %d", (int)min + shift); - return 1; - } - } else if (theirs >= min && theirs <= max) { - if (max - min < tolerance) { - shove = (tolerance - (max - min)) / 2; - if (min + shift - shove >= 0) { - min -= shove; - max += shove; - } else { - min = 0; - max = tolerance; - } - } - sprintf(buf, "%4d - %d", (int)min + shift, (int)max + shift); - return 1; + if (min < 0) { + if (theirs <= max) { + if (max < tolerance) + max = tolerance; + sprintf(buf, " 0 - %d", (int)max + shift); + return 1; + } + } else if (max < 0) { + if (theirs >= min) { + sprintf(buf, " >= %d", (int)min + shift); + return 1; } + } else if (theirs >= min && theirs <= max) { + if (max - min < tolerance) { + shove = (tolerance - (max - min)) / 2; + if (min + shift - shove >= 0) { + min -= shove; + max += shove; + } else { + min = 0; + max = tolerance; + } + } + sprintf(buf, "%4d - %d", (int)min + shift, (int)max + shift); + return 1; + } - return 0; + return 0; } - diff --git a/src/lib/commands/rese.c b/src/lib/commands/rese.c index 69f3df375..88d6b01f9 100644 --- a/src/lib/commands/rese.c +++ b/src/lib/commands/rese.c @@ -58,20 +58,21 @@ rese(void) struct comstr comm; struct sctstr sect; struct ichrstr *ix; - int number_set; - int m; - char *p; - float price; - time_t now; + int number_set; + int m; + char *p; + float price; + time_t now; s_char buf[1024]; - + if (!opt_MARKET) { pr("The market is disabled.\n"); return RET_FAIL; } check_market(); check_trade(); - if ((p = getstarg(player->argp[1], "Which lot : ",buf)) == 0 || *p == 0) + if ((p = getstarg(player->argp[1], "Which lot : ", buf)) == 0 + || *p == 0) return RET_SYN; number_set = atoi(p); getcomm(number_set, &comm); @@ -83,7 +84,8 @@ rese(void) pr("Some one already has a bid out on that\n"); return RET_OK; } - if ((p = getstarg(player->argp[2], "New (lower) price: ",buf)) == 0 || *p == 0) + if ((p = getstarg(player->argp[2], "New (lower) price: ", buf)) == 0 + || *p == 0) return RET_SYN; if (!check_comm_ok(&comm)) return RET_FAIL; @@ -133,16 +135,16 @@ rese(void) pr("You can only lower the price.\n"); return RET_OK; } - if (price < 0){ + if (price < 0) { pr("New price must be greater than or equal to zero.\n"); return RET_OK; } comm.com_price = price; - (void) time(&now); + (void)time(&now); comm.com_markettime = now; - if((int)price < comm.com_maxprice) - comm.com_maxprice = (int) price; - if(!putcomm(number_set, &comm)){ + if ((int)price < comm.com_maxprice) + comm.com_maxprice = (int)price; + if (!putcomm(number_set, &comm)) { pr("Problems with the commodities file, Call the Deity\n"); return RET_OK; } diff --git a/src/lib/commands/reso.c b/src/lib/commands/reso.c index 48ec36854..96925197a 100644 --- a/src/lib/commands/reso.c +++ b/src/lib/commands/reso.c @@ -43,64 +43,64 @@ #include "file.h" #include "commands.h" -static void reso_hdr(void); +static void reso_hdr(void); int reso(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) - reso_hdr(); - if (player->god) - pr("%3d ", sect.sct_own); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sect.sct_effic); - pr(" %4d", sect.sct_min); - pr("%5d", sect.sct_gmin); - pr("%5d", sect.sct_fertil); - pr("%4d", sect.sct_oil); - pr("%5d", sect.sct_uran); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) + reso_hdr(); + if (player->god) + pr("%3d ", sect.sct_own); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sect.sct_effic); + pr(" %4d", sect.sct_min); + pr("%5d", sect.sct_gmin); + pr("%5d", sect.sct_fertil); + pr("%4d", sect.sct_oil); + pr("%5d", sect.sct_uran); /* pr("%5d", sect.sct_elev);*/ - if (!player->god && sect.sct_terr) - pr("%4d", sect.sct_terr); - pr("\n"); - } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + if (!player->god && sect.sct_terr) + pr("%4d", sect.sct_terr); + pr("\n"); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } static void reso_hdr(void) { - if (player->god) - pr(" "); - pr("RESOURCE\n"); - if (player->god) - pr("own "); - pr(" sect eff min gold fert oil uran "); - if (!player->god) - pr("ter"); - pr("\n"); + if (player->god) + pr(" "); + pr("RESOURCE\n"); + if (player->god) + pr("own "); + pr(" sect eff min gold fert oil uran "); + if (!player->god) + pr("ter"); + pr("\n"); } diff --git a/src/lib/commands/retr.c b/src/lib/commands/retr.c index 8754192b2..0812141b5 100644 --- a/src/lib/commands/retr.c +++ b/src/lib/commands/retr.c @@ -51,251 +51,279 @@ int retr(void) { - s_char *pq, *fl; - int nships; - struct nstr_item ni; - struct shpstr ship; - int isfleet=0, rflags=(-2),zero; - unsigned int x; - s_char buf1[1024]; - s_char buf2[1024]; + s_char *pq, *fl; + int nships; + struct nstr_item ni; + struct shpstr ship; + int isfleet = 0, rflags = (-2), zero; + unsigned int x; + s_char buf1[1024]; + s_char buf2[1024]; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; - nships = 0; - if (player->argp[1] != (s_char *)0) - if (isalpha(player->argp[1][0])) - isfleet=1; - if (player->argp[2] != (s_char *)0) - pq = getstarg(player->argp[2], "Retreat path? ", buf1); - else - pq = (s_char *)0; + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; + nships = 0; + if (player->argp[1] != (s_char *)0) + if (isalpha(player->argp[1][0])) + isfleet = 1; + if (player->argp[2] != (s_char *)0) + pq = getstarg(player->argp[2], "Retreat path? ", buf1); + else + pq = (s_char *)0; + + if (pq != (s_char *)0) { + fl = getstarg(player->argp[3], + "Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2); + if (!fl) + return RET_SYN; + rflags = 0 | isfleet; - if (pq != (s_char *)0){ - fl = getstarg(player->argp[3], "Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2); - if (!fl) - return RET_SYN; - rflags=0|isfleet; - - for(x=0;xowner || ship.shp_own == 0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, ni.cur); - continue; - } - if (zero) - bzero(ship.shp_rpath,RET_LEN); + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur); + continue; + } + if (zero) + bzero(ship.shp_rpath, RET_LEN); - if (pq != (s_char *)0){ - bzero(ship.shp_rpath,RET_LEN); - bcopy(pq,ship.shp_rpath,strlen(pq)); - putship(ship.shp_uid,&ship); - } - if (rflags >= 0){ - ship.shp_rflags = rflags; - putship(ship.shp_uid,&ship); - } - if (nships++ == 0) { - if (player->god) - pr("own "); - pr("shp# ship type x,y fl path as flt? flags\n"); - } - if (player->god) - pr("%3d ", ship.shp_own); - pr("%4d ", ni.cur); - pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); - pr("%1c", ship.shp_fleet); - pr(" %-11s", ship.shp_rpath); - if (ship.shp_rflags & RET_GROUP) - pr("Yes "); - else - pr(" "); - if (ship.shp_rflags & RET_INJURED) - pr("I"); - if (ship.shp_rflags & RET_TORPED) - pr("T"); - if (ship.shp_rflags & RET_SONARED) - pr("S"); - if (ship.shp_rflags & RET_HELPLESS) - pr("H"); - if (ship.shp_rflags & RET_BOMBED) - pr("B"); - if (ship.shp_rflags & RET_DCHRGED) - pr("D"); - if (ship.shp_rflags & RET_BOARDED) - pr("U"); - pr("\n"); + if (pq != (s_char *)0) { + bzero(ship.shp_rpath, RET_LEN); + bcopy(pq, ship.shp_rpath, strlen(pq)); + putship(ship.shp_uid, &ship); } - if (nships == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + if (rflags >= 0) { + ship.shp_rflags = rflags; + putship(ship.shp_uid, &ship); + } + if (nships++ == 0) { + if (player->god) + pr("own "); + pr("shp# ship type x,y fl path as flt? flags\n"); + } + if (player->god) + pr("%3d ", ship.shp_own); + pr("%4d ", ni.cur); + pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + pr("%1c", ship.shp_fleet); + pr(" %-11s", ship.shp_rpath); + if (ship.shp_rflags & RET_GROUP) + pr("Yes "); + else + pr(" "); + if (ship.shp_rflags & RET_INJURED) + pr("I"); + if (ship.shp_rflags & RET_TORPED) + pr("T"); + if (ship.shp_rflags & RET_SONARED) + pr("S"); + if (ship.shp_rflags & RET_HELPLESS) + pr("H"); + if (ship.shp_rflags & RET_BOMBED) + pr("B"); + if (ship.shp_rflags & RET_DCHRGED) + pr("D"); + if (ship.shp_rflags & RET_BOARDED) + pr("U"); + pr("\n"); + } + if (nships == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } int lretr(void) { - s_char *pq, *fl; - int nunits; - struct nstr_item ni; - struct lndstr land; - int isarmy=0, rflags=(-2),zero; - s_char buf1[1024]; - s_char buf2[1024]; - unsigned int x; + s_char *pq, *fl; + int nunits; + struct nstr_item ni; + struct lndstr land; + int isarmy = 0, rflags = (-2), zero; + s_char buf1[1024]; + s_char buf2[1024]; + unsigned int x; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - nunits = 0; - if (player->argp[1] != (s_char *)0) - if (isalpha(player->argp[1][0])) - isarmy=1; - if (player->argp[2] != (s_char *)0) - pq = getstarg(player->argp[2], "Retreat path? ", buf1); - else - pq = (s_char *)0; - if (pq != (s_char *)0){ - fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ", buf2); - if (!fl) - return RET_SYN; - rflags=0|isarmy; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + nunits = 0; + if (player->argp[1] != (s_char *)0) + if (isalpha(player->argp[1][0])) + isarmy = 1; + if (player->argp[2] != (s_char *)0) + pq = getstarg(player->argp[2], "Retreat path? ", buf1); + else + pq = (s_char *)0; + if (pq != (s_char *)0) { + fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ", + buf2); + if (!fl) + return RET_SYN; + rflags = 0 | isarmy; - for(x=0;xowner || land.lnd_own == 0) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", - land.lnd_type, ni.cur); - continue; - } - if (zero) - bzero(land.lnd_rpath,RET_LEN); + zero = (rflags == -1); + if (zero) + rflags = 0; - if (pq != (s_char *)0){ - bzero(land.lnd_rpath,RET_LEN); - bcopy(pq,land.lnd_rpath,strlen(pq)); - putland(land.lnd_uid,&land); - } - if (rflags >= 0){ - land.lnd_rflags = rflags; - putland(land.lnd_uid,&land); - } + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; + } + if (zero) + bzero(land.lnd_rpath, RET_LEN); - if (nunits++ == 0) { - if (player->god) - pr("own "); - pr("lnd# unit type x,y ar path as army? flags\n"); - } - if (player->god) - pr("%3d ", land.lnd_own); - pr("%4d ", ni.cur); - pr("%-16.16s ", lchr[(int)land.lnd_type].l_name); - prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum); - pr("%1c", land.lnd_army); - pr(" %-11s", land.lnd_rpath); - if (land.lnd_rflags & RET_GROUP) - pr("Yes "); - else - pr(" "); - if (land.lnd_rflags & RET_INJURED) - pr("I"); - if (land.lnd_rflags & RET_TORPED) - pr("T"); - if (land.lnd_rflags & RET_SONARED) - pr("S"); - if (land.lnd_rflags & RET_HELPLESS) - pr("H"); - if (land.lnd_rflags & RET_BOMBED) - pr("B"); - if (land.lnd_rflags & RET_DCHRGED) - pr("D"); - if (land.lnd_rflags & RET_BOARDED) - pr("U"); - pr("\n"); + if (pq != (s_char *)0) { + bzero(land.lnd_rpath, RET_LEN); + bcopy(pq, land.lnd_rpath, strlen(pq)); + putland(land.lnd_uid, &land); } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; + if (rflags >= 0) { + land.lnd_rflags = rflags; + putland(land.lnd_uid, &land); } - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + + if (nunits++ == 0) { + if (player->god) + pr("own "); + pr("lnd# unit type x,y ar path as army? flags\n"); + } + if (player->god) + pr("%3d ", land.lnd_own); + pr("%4d ", ni.cur); + pr("%-16.16s ", lchr[(int)land.lnd_type].l_name); + prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum); + pr("%1c", land.lnd_army); + pr(" %-11s", land.lnd_rpath); + if (land.lnd_rflags & RET_GROUP) + pr("Yes "); + else + pr(" "); + if (land.lnd_rflags & RET_INJURED) + pr("I"); + if (land.lnd_rflags & RET_TORPED) + pr("T"); + if (land.lnd_rflags & RET_SONARED) + pr("S"); + if (land.lnd_rflags & RET_HELPLESS) + pr("H"); + if (land.lnd_rflags & RET_BOMBED) + pr("B"); + if (land.lnd_rflags & RET_DCHRGED) + pr("D"); + if (land.lnd_rflags & RET_BOARDED) + pr("U"); + pr("\n"); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } diff --git a/src/lib/commands/rout.c b/src/lib/commands/rout.c index 43fd42e57..27e600971 100644 --- a/src/lib/commands/rout.c +++ b/src/lib/commands/rout.c @@ -48,94 +48,96 @@ int rout(void) { - struct ichrstr *ip; - struct nstr_sect ns; - struct natstr *natp; - struct sctstr sect; - struct nscstr cond[NS_NCOND]; - int ncond; - struct range relrange; - int row; - int y; - int ry; - int i_del; - int dir; - s_char *p; - s_char what[64]; - s_char *str; - s_char buf1[1024]; - /* Note this is not re-entrant anyway, so we keep the buffers - around */ - static s_char *mapbuf = (s_char *)0; - static s_char **map = (s_char **)0; - static s_char *buf = (s_char *)0; - int i; + struct ichrstr *ip; + struct nstr_sect ns; + struct natstr *natp; + struct sctstr sect; + struct nscstr cond[NS_NCOND]; + int ncond; + struct range relrange; + int row; + int y; + int ry; + int i_del; + int dir; + s_char *p; + s_char what[64]; + s_char *str; + s_char buf1[1024]; + /* Note this is not re-entrant anyway, so we keep the buffers + around */ + static s_char *mapbuf = (s_char *)0; + static s_char **map = (s_char **)0; + static s_char *buf = (s_char *)0; + int i; - if ((ip = whatitem(player->argp[1], "What item? ")) == 0) - return RET_SYN; - i_del = V_DEL(ip-ichr); - if(player->argp[2] == (s_char *) 0) { - if ((str = getstring("(sects)? ", buf1)) == 0) - return RET_SYN; - } else { - str = player->argp[2]; - } - if(*str == '*') { - sprintf(what, "%d:%d,%d:%d", - -WORLD_X/2, WORLD_X/2-1, - -WORLD_Y/2, WORLD_Y/2-1); - if (!snxtsct(&ns, what)) - return RET_FAIL; - } else if (!snxtsct(&ns, str)) - return RET_FAIL; - if (!mapbuf) - mapbuf = (s_char *)malloc((WORLD_Y*MAPWIDTH(3))*sizeof(s_char)); - if (!map) { - map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (map && mapbuf) { - for (i = 0; i < WORLD_Y; i++) - map[i] = &mapbuf[MAPWIDTH(3) * i]; - } else if (map) { - free((s_char *)map); - map = (s_char **)0; - } - } - if (!buf) - buf = (s_char *)malloc((MAPWIDTH(3) + 12) * sizeof(s_char)); - if (!mapbuf || !map || !buf) { - pr("Memory error, tell the deity.\n"); - logerror("malloc failed in rout\n"); + if ((ip = whatitem(player->argp[1], "What item? ")) == 0) + return RET_SYN; + i_del = V_DEL(ip - ichr); + if (player->argp[2] == (s_char *)0) { + if ((str = getstring("(sects)? ", buf1)) == 0) + return RET_SYN; + } else { + str = player->argp[2]; + } + if (*str == '*') { + sprintf(what, "%d:%d,%d:%d", + -WORLD_X / 2, WORLD_X / 2 - 1, + -WORLD_Y / 2, WORLD_Y / 2 - 1); + if (!snxtsct(&ns, what)) return RET_FAIL; + } else if (!snxtsct(&ns, str)) + return RET_FAIL; + if (!mapbuf) + mapbuf = + (s_char *)malloc((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char)); + if (!map) { + map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (map && mapbuf) { + for (i = 0; i < WORLD_Y; i++) + map[i] = &mapbuf[MAPWIDTH(3) * i]; + } else if (map) { + free((s_char *)map); + map = (s_char **)0; } - ncond = ns.ncond; - bcopy((s_char *)ns.cond, (s_char *)cond, sizeof(struct nscstr) * ncond); - ns.ncond = 0; + } + if (!buf) + buf = (s_char *)malloc((MAPWIDTH(3) + 12) * sizeof(s_char)); + if (!mapbuf || !map || !buf) { + pr("Memory error, tell the deity.\n"); + logerror("malloc failed in rout\n"); + return RET_FAIL; + } + ncond = ns.ncond; + bcopy((s_char *)ns.cond, (s_char *)cond, + sizeof(struct nscstr) * ncond); + ns.ncond = 0; - natp = getnatp(player->cnum); - xyrelrange(natp, &ns.range, &relrange); - bzero((s_char *)mapbuf,((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char))); - blankfill((s_char *)mapbuf, &ns.range, 3); - border(&relrange, " ", " "); + natp = getnatp(player->cnum); + xyrelrange(natp, &ns.range, &relrange); + bzero((s_char *)mapbuf, ((WORLD_Y * MAPWIDTH(3)) * sizeof(s_char))); + blankfill((s_char *)mapbuf, &ns.range, 3); + border(&relrange, " ", " "); - while (nxtsct(&ns, §)) { - if (!player->owner) - continue; - p = &map[ns.dy][ns.dx*2]; - if ((dir = getvar(i_del, (s_char *)§, EF_SECTOR) & 0x7) && - nstr_exec(cond, ncond, (s_char *)§, EF_SECTOR)) - bcopy(routech[dir][0], p, 3); - p[1] = dchr[sect.sct_type].d_mnem; - } - for (row = 0, y = ns.range.ly; row < ns.range.height; y++,row++) { - ry = yrel(natp, y); - bzero(buf,(MAPWIDTH(3) + 10) * sizeof(s_char)); - sprintf(buf,"%4d ",ry); - bcopy(map[row],buf+5,ns.range.width*2+1); - sprintf(buf+5+ns.range.width*2+1," %-4d\n",ry); - pr("%s", buf); - if (y >= WORLD_Y) - y -= WORLD_Y; - } - border(&relrange, " ", " "); - return RET_OK; + while (nxtsct(&ns, §)) { + if (!player->owner) + continue; + p = &map[ns.dy][ns.dx * 2]; + if ((dir = getvar(i_del, (s_char *)§, EF_SECTOR) & 0x7) && + nstr_exec(cond, ncond, (s_char *)§, EF_SECTOR)) + bcopy(routech[dir][0], p, 3); + p[1] = dchr[sect.sct_type].d_mnem; + } + for (row = 0, y = ns.range.ly; row < ns.range.height; y++, row++) { + ry = yrel(natp, y); + bzero(buf, (MAPWIDTH(3) + 10) * sizeof(s_char)); + sprintf(buf, "%4d ", ry); + bcopy(map[row], buf + 5, ns.range.width * 2 + 1); + sprintf(buf + 5 + ns.range.width * 2 + 1, " %-4d\n", ry); + pr("%s", buf); + if (y >= WORLD_Y) + y -= WORLD_Y; + } + border(&relrange, " ", " "); + return RET_OK; } diff --git a/src/lib/commands/sabo.c b/src/lib/commands/sabo.c index 950f0ba69..b66eb31c4 100644 --- a/src/lib/commands/sabo.c +++ b/src/lib/commands/sabo.c @@ -53,78 +53,78 @@ int sabo(void) { - struct nstr_item ni; - struct lndstr land; - struct sctstr sect; - double odds; - int vec[I_MAX+1]; - int dam; + struct nstr_item ni; + struct lndstr land; + struct sctstr sect; + double odds; + int vec[I_MAX + 1]; + int dam; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner) continue; - if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) { - pr("%s is not a spy.\n", prland(&land)); - continue; - } - if (land.lnd_ship >= 0) { - pr("%s is on ship %d.\n", prland(&land), - land.lnd_ship); - continue; - } - if (land.lnd_land >= 0) { - pr("%s is on unit %d.\n", prland(&land), - land.lnd_land); - continue; - } - if (!getsect(land.lnd_x, land.lnd_y, §)) continue; - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - if (vec[I_SHELL] == 0) { - pr("%s has no shells.\n", prland(&land)); - continue; - } - putvar(V_SHELL, vec[I_SHELL] - 1, (s_char *)&land, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner) + continue; + if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) { + pr("%s is not a spy.\n", prland(&land)); + continue; + } + if (land.lnd_ship >= 0) { + pr("%s is on ship %d.\n", prland(&land), land.lnd_ship); + continue; + } + if (land.lnd_land >= 0) { + pr("%s is on unit %d.\n", prland(&land), land.lnd_land); + continue; + } + if (!getsect(land.lnd_x, land.lnd_y, §)) + continue; + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); + if (vec[I_SHELL] == 0) { + pr("%s has no shells.\n", prland(&land)); + continue; + } + putvar(V_SHELL, vec[I_SHELL] - 1, (s_char *)&land, EF_LAND); - odds = (100 - land.lnd_effic) / 100.0 + .10; - if (chance(odds)) { - wu(0, sect.sct_own, - "%s spy shot in %s during sabotage attempt.\n", - cname(player->cnum), - xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - pr("%s was shot and killed.\n", prland(&land)); - land.lnd_effic = 0; - putland(land.lnd_uid, &land); - continue; - } + odds = (100 - land.lnd_effic) / 100.0 + .10; + if (chance(odds)) { + wu(0, sect.sct_own, + "%s spy shot in %s during sabotage attempt.\n", + cname(player->cnum), + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + pr("%s was shot and killed.\n", prland(&land)); + land.lnd_effic = 0; + putland(land.lnd_uid, &land); + continue; + } - land.lnd_own = 0; - putland(land.lnd_uid, &land); + land.lnd_own = 0; + putland(land.lnd_uid, &land); - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - dam = landgun(3*land.lnd_effic, 7); - if (vec[I_SHELL] > 20) - dam += seagun(land.lnd_effic, random() % (vec[I_SHELL] / 10)); - if (vec[I_PETROL] > 100) - dam += seagun(land.lnd_effic, random() % (vec[I_PETROL] / 50)); + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + dam = landgun(3 * land.lnd_effic, 7); + if (vec[I_SHELL] > 20) + dam += seagun(land.lnd_effic, random() % (vec[I_SHELL] / 10)); + if (vec[I_PETROL] > 100) + dam += seagun(land.lnd_effic, random() % (vec[I_PETROL] / 50)); - pr("Explosion in %s causes %d damage.\n", - xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam); - if (sect.sct_own) { - wu(0, sect.sct_own, - "Sabotage in sector %s caused %d damage.\n", - xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam); - } - sectdamage(§, dam, 0); - putsect(§); + pr("Explosion in %s causes %d damage.\n", + xyas(land.lnd_x, land.lnd_y, land.lnd_own), dam); + if (sect.sct_own) { + wu(0, sect.sct_own, + "Sabotage in sector %s caused %d damage.\n", + xyas(sect.sct_x, sect.sct_y, sect.sct_own), dam); + } + sectdamage(§, dam, 0); + putsect(§); - land.lnd_own = player->cnum; - if (chance(odds)) { - pr("%s dies in explosion.\n", prland(&land)); - land.lnd_effic = 0; - } - putland(land.lnd_uid, &land); + land.lnd_own = player->cnum; + if (chance(odds)) { + pr("%s dies in explosion.\n", prland(&land)); + land.lnd_effic = 0; } - return RET_OK; + putland(land.lnd_uid, &land); + } + return RET_OK; } diff --git a/src/lib/commands/sail.c b/src/lib/commands/sail.c index ad6ed7e9b..de602b509 100644 --- a/src/lib/commands/sail.c +++ b/src/lib/commands/sail.c @@ -48,136 +48,132 @@ static int show_sail(struct nstr_item *nstr) { - register int count=0; - struct shpstr ship; + register int count = 0; + struct shpstr ship; - while (nxtitem(nstr, (s_char *)&ship)) { - if (!player->owner || ship.shp_own==0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, nstr->cur); - continue; - } - if (count++==0) { - if (player->god) - pr("own "); - pr("shp# ship type x,y "); - pr("mobil mobquota follows path\n"); - } + while (nxtitem(nstr, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, nstr->cur); + continue; + } + if (count++ == 0) { + if (player->god) + pr("own "); + pr("shp# ship type x,y "); + pr("mobil mobquota follows path\n"); + } + if (player->god) + pr("%3d ", ship.shp_own); + pr("%4d ", ship.shp_uid); + pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + pr("%3d ", ship.shp_mobil); + pr(" %3d ", ship.shp_mobquota); + pr(" %3d ", ship.shp_follow); + if (ship.shp_path[0]) { + pr(ship.shp_path); + } else if ((ship.shp_autonav & AN_AUTONAV)) { + pr("Has orders"); + } + pr("\n"); + if (opt_SHIPNAMES) { + if (ship.shp_name[0] != 0) { if (player->god) - pr("%3d ",ship.shp_own); - pr("%4d ", ship.shp_uid); - pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); - pr("%3d ",ship.shp_mobil); - pr(" %3d ",ship.shp_mobquota); - pr(" %3d ",ship.shp_follow); - if (ship.shp_path[0]) { - pr(ship.shp_path); - } else if ((ship.shp_autonav & AN_AUTONAV)) { - pr("Has orders"); - } - pr("\n"); - if (opt_SHIPNAMES) { - if (ship.shp_name[0] != 0) { - if (player->god) - pr(" "); - pr(" %s\n",ship.shp_name); - } - } + pr(" "); + pr(" %s\n", ship.shp_name); + } } - if (count == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", count, splur(count)); - return RET_OK; + } + if (count == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", count, splur(count)); + return RET_OK; } static int cmd_unsail_ship(struct nstr_item *nstr) { - struct shpstr ship; - int count = 0; + struct shpstr ship; + int count = 0; - while (nxtitem(nstr, (s_char *)&ship)) { - if (!player->owner || ship.shp_own==0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, nstr->cur); - continue; - } - if (ship.shp_path[0]) { - pr("Ship #%d unsailed\n",ship.shp_uid); - count++; - ship.shp_path[0] = 0; - putship(ship.shp_uid, &ship); - } + while (nxtitem(nstr, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, nstr->cur); + continue; + } + if (ship.shp_path[0]) { + pr("Ship #%d unsailed\n", ship.shp_uid); + count++; + ship.shp_path[0] = 0; + putship(ship.shp_uid, &ship); } - return RET_OK; + } + return RET_OK; } static int cmd_sail_ship(struct nstr_item *nstr) { - s_char *cp; - struct shpstr ship; - char navpath[MAX_PATH_LEN]; + s_char *cp; + struct shpstr ship; + char navpath[MAX_PATH_LEN]; - while (!player->aborted && nxtitem(nstr, (s_char *)&ship)) { - if (!player->owner || ship.shp_own==0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, nstr->cur); - continue; - } - if ((ship.shp_autonav & AN_AUTONAV) && - !(ship.shp_autonav & AN_STANDBY)) { - pr("Ship #%d has other orders!\n", - ship.shp_uid); - continue; - } + while (!player->aborted && nxtitem(nstr, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, nstr->cur); + continue; + } + if ((ship.shp_autonav & AN_AUTONAV) && + !(ship.shp_autonav & AN_STANDBY)) { + pr("Ship #%d has other orders!\n", ship.shp_uid); + continue; + } - pr("Ship #%d at %s\n", ship.shp_uid, - xyas(ship.shp_x,ship.shp_y,ship.shp_own)); - cp = getpath(navpath, player->argp[2], - ship.shp_x, ship.shp_y, 0, 0, 0, P_SAILING); - if (!check_ship_ok(&ship)) - continue; - if (!player->aborted) { - bzero(ship.shp_path, sizeof(ship.shp_path)); - strncpy(ship.shp_path, cp, sizeof(ship.shp_path)-2); - ship.shp_mission = 0; - putship(ship.shp_uid, &ship); - } + pr("Ship #%d at %s\n", ship.shp_uid, + xyas(ship.shp_x, ship.shp_y, ship.shp_own)); + cp = getpath(navpath, player->argp[2], + ship.shp_x, ship.shp_y, 0, 0, 0, P_SAILING); + if (!check_ship_ok(&ship)) + continue; + if (!player->aborted) { + bzero(ship.shp_path, sizeof(ship.shp_path)); + strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2); + ship.shp_mission = 0; + putship(ship.shp_uid, &ship); } - return RET_OK; + } + return RET_OK; } int sail(void) { - s_char *cp; - struct nstr_item nstr; + s_char *cp; + struct nstr_item nstr; - if (!opt_SAIL) { - pr("The SAIL option is not enabled, so this command is not valid.\n"); - return RET_FAIL; - } - if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) - return RET_SYN; - cp = player->argp[2]; - if ( (*player->argp[0]=='q')/*qsail command*/ || (cp && *cp=='q') ) { - return(show_sail(&nstr)); - } else if ( *player->argp[0]=='u' /*unsail command*/ || (cp && *cp=='-')) { - return(cmd_unsail_ship(&nstr)); - } else - return(cmd_sail_ship(&nstr)); + if (!opt_SAIL) { + pr("The SAIL option is not enabled, so this command is not valid.\n"); + return RET_FAIL; + } + if (!snxtitem(&nstr, EF_SHIP, player->argp[1])) + return RET_SYN; + cp = player->argp[2]; + if ((*player->argp[0] == 'q') /*qsail command */ ||(cp && *cp == 'q')) { + return (show_sail(&nstr)); + } else if (*player->argp[0] == 'u' /*unsail command */ + || (cp && *cp == '-')) { + return (cmd_unsail_ship(&nstr)); + } else + return (cmd_sail_ship(&nstr)); } - diff --git a/src/lib/commands/sate.c b/src/lib/commands/sate.c index a28960738..66fa81f77 100644 --- a/src/lib/commands/sate.c +++ b/src/lib/commands/sate.c @@ -47,63 +47,61 @@ int sate(void) { - extern int plane_mob_max; - double tech; - int pln_uid; - struct plnstr plane; - int type = EF_BAD; + extern int plane_mob_max; + double tech; + int pln_uid; + struct plnstr plane; + int type = EF_BAD; - if (!player->argp[1] || - !*player->argp[1] || - !isdigit(*player->argp[1]) || - (pln_uid = atoi(player->argp[1])) < 0) - return RET_SYN; + if (!player->argp[1] || + !*player->argp[1] || + !isdigit(*player->argp[1]) || + (pln_uid = atoi(player->argp[1])) < 0) + return RET_SYN; - if (!getplane(pln_uid, &plane)) { - pr("No such plane\n"); - return RET_FAIL; - } + if (!getplane(pln_uid, &plane)) { + pr("No such plane\n"); + return RET_FAIL; + } - if (plane.pln_own != player->cnum && !player->god) { - pr("You don't own plane #%d\n", pln_uid); - return RET_FAIL; - } - - if (!(plane.pln_flags & PLN_LAUNCHED)) { - pr("%s isn't in orbit\n", - prplane(&plane)); - return RET_FAIL; - } - if (plane.pln_mobil < plane_mob_max) { - pr("%s doesn't have enough mobility (needs %d)\n", - prplane(&plane), - plane_mob_max); - return RET_FAIL; - } - if (player->argp[2]) { - switch (*player->argp[2]) { - case 'l': - type = EF_LAND; - break; - case 's': - if (*(player->argp[2] + 1) == 'e') - type = EF_SECTOR; - else - type = EF_SHIP; - break; - default: - return RET_SYN; - } + if (plane.pln_own != player->cnum && !player->god) { + pr("You don't own plane #%d\n", pln_uid); + return RET_FAIL; + } + + if (!(plane.pln_flags & PLN_LAUNCHED)) { + pr("%s isn't in orbit\n", prplane(&plane)); + return RET_FAIL; + } + if (plane.pln_mobil < plane_mob_max) { + pr("%s doesn't have enough mobility (needs %d)\n", + prplane(&plane), plane_mob_max); + return RET_FAIL; + } + if (player->argp[2]) { + switch (*player->argp[2]) { + case 'l': + type = EF_LAND; + break; + case 's': + if (*(player->argp[2] + 1) == 'e') + type = EF_SECTOR; + else + type = EF_SHIP; + break; + default: + return RET_SYN; } - - if (plchr[(int)plane.pln_type].pl_flags & P_S) - pr("Satellite Spy Report:\n"); - else - pr("Satellite Map Report:\n"); - pr("%s at ", prplane(&plane)); - tech = techfact(plane.pln_tech, 20.0); - satmap(plane.pln_x, plane.pln_y, plane.pln_effic, - (int)tech, plchr[(int)plane.pln_type].pl_flags, type); + } + + if (plchr[(int)plane.pln_type].pl_flags & P_S) + pr("Satellite Spy Report:\n"); + else + pr("Satellite Map Report:\n"); + pr("%s at ", prplane(&plane)); + tech = techfact(plane.pln_tech, 20.0); + satmap(plane.pln_x, plane.pln_y, plane.pln_effic, + (int)tech, plchr[(int)plane.pln_type].pl_flags, type); - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/scra.c b/src/lib/commands/scra.c index 034972662..3f7ebdddf 100644 --- a/src/lib/commands/scra.c +++ b/src/lib/commands/scra.c @@ -56,286 +56,292 @@ union item_u { int scra(void) { - struct nstr_item ni; - union item_u item; - int vec[I_MAX+1]; - int itemvec[I_MAX+1]; - int type; - struct sctstr sect; - struct mchrstr *mp; - struct plchrstr *pp; - struct lchrstr *lp; - s_char *p; - int i; - struct nstr_item ni2; - struct plnstr plane; - struct lndstr land; - struct sctstr sect2; - s_char prompt[128]; - s_char buf[1024]; + struct nstr_item ni; + union item_u item; + int vec[I_MAX + 1]; + int itemvec[I_MAX + 1]; + int type; + struct sctstr sect; + struct mchrstr *mp; + struct plchrstr *pp; + struct lchrstr *lp; + s_char *p; + int i; + struct nstr_item ni2; + struct plnstr plane; + struct lndstr land; + struct sctstr sect2; + s_char prompt[128]; + s_char buf[1024]; float eff; - + if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf))) - return RET_SYN; + return RET_SYN; switch (*p) { case 's': - type = EF_SHIP; break; + type = EF_SHIP; + break; case 'p': - type = EF_PLANE; break; + type = EF_PLANE; + break; case 'l': - type = EF_LAND; break; + type = EF_LAND; + break; default: - pr("Ships, land units, or planes only! (s, l, p)\n"); - return RET_SYN; + pr("Ships, land units, or planes only! (s, l, p)\n"); + return RET_SYN; } sprintf(prompt, "%s(s)? ", ef_nameof(type)); if ((p = getstarg(player->argp[2], prompt, buf)) == 0) - return RET_SYN; + return RET_SYN; if (!snxtitem(&ni, type, p)) - return RET_SYN; + return RET_SYN; if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p) - || islist(p))){ - s_char y_or_n[80], bbuf[80]; - - bzero(y_or_n, 80); - if (type == EF_SHIP) { - if (*p == '*') - sprintf(bbuf,"all ships"); - else if (*p == '~') - sprintf(bbuf,"all unassigned ships"); - else if (issector(p)) - sprintf(bbuf,"all ships in %s",p); - else if (isalpha(*p)) - sprintf(bbuf,"fleet %c",*p); - else - sprintf(bbuf,"ships %s",p); - } else if (type == EF_LAND) { - if (*p == '*') - sprintf(bbuf,"all land units"); - else if (*p == '~') - sprintf(bbuf,"all unassigned land units"); - else if (issector(p)) - sprintf(bbuf,"all units in %s",p); - else if (isalpha(*p)) - sprintf(bbuf,"army %c",*p); - else - sprintf(bbuf,"units %s",p); - } else { - if (*p == '*') - sprintf(bbuf,"all planes"); - else if (*p == '~') - sprintf(bbuf,"all unassigned planes"); - else if (issector(p)) - sprintf(bbuf,"all planes in %s",p); - else if (isalpha(*p)) - sprintf(bbuf,"wing %c",*p); - else - sprintf(bbuf,"planes %s",p); - } - - sprintf(y_or_n,"Really scrap %s [n]? ", bbuf); - if (!confirm(y_or_n)) - return RET_FAIL; + || islist(p))) { + s_char y_or_n[80], bbuf[80]; + + bzero(y_or_n, 80); + if (type == EF_SHIP) { + if (*p == '*') + sprintf(bbuf, "all ships"); + else if (*p == '~') + sprintf(bbuf, "all unassigned ships"); + else if (issector(p)) + sprintf(bbuf, "all ships in %s", p); + else if (isalpha(*p)) + sprintf(bbuf, "fleet %c", *p); + else + sprintf(bbuf, "ships %s", p); + } else if (type == EF_LAND) { + if (*p == '*') + sprintf(bbuf, "all land units"); + else if (*p == '~') + sprintf(bbuf, "all unassigned land units"); + else if (issector(p)) + sprintf(bbuf, "all units in %s", p); + else if (isalpha(*p)) + sprintf(bbuf, "army %c", *p); + else + sprintf(bbuf, "units %s", p); + } else { + if (*p == '*') + sprintf(bbuf, "all planes"); + else if (*p == '~') + sprintf(bbuf, "all unassigned planes"); + else if (issector(p)) + sprintf(bbuf, "all planes in %s", p); + else if (isalpha(*p)) + sprintf(bbuf, "wing %c", *p); + else + sprintf(bbuf, "planes %s", p); + } + + sprintf(y_or_n, "Really scrap %s [n]? ", bbuf); + if (!confirm(y_or_n)) + return RET_FAIL; } while (nxtitem(&ni, (s_char *)&item)) { - if (!player->owner) + if (!player->owner) + continue; + + if (opt_MARKET) { + if (ontradingblock(type, (int *)&item.ship)) { + pr("You cannot scrap an item on the trading block!\n"); + continue; + } + } + + if (type == EF_SHIP) { + getsect(item.ship.shp_x, item.ship.shp_y, §); + if (sect.sct_type != SCT_HARBR) + continue; + if (sect.sct_effic < 60 || sect.sct_own != player->cnum) + continue; + } else if (type == EF_LAND) { + if (item.land.lnd_ship >= 0) { + pr("%s is on a ship, and cannot be scrapped!\n", + prland(&item.land)); + continue; + } + getsect(item.land.lnd_x, item.land.lnd_y, §); + } else { + getsect(item.plane.pln_x, item.plane.pln_y, §); + if (sect.sct_type != SCT_AIRPT) + continue; + if (sect.sct_effic < 60 || + (sect.sct_own != player->cnum && + getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY)) + continue; + } + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + if (type == EF_SHIP) { + eff = ((float)item.ship.shp_effic / 100.0); + mp = &mchr[(int)item.ship.shp_type]; + if (opt_TRADESHIPS) { + if (mp->m_flags & M_TRADE) { + pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n"); + sprintf(prompt, + "Are you really sure that you want to scrap %s (n)? ", + prship(&item.ship)); + if (!confirm(prompt)) { + pr("%s not scrapped\n", prship(&item.ship)); continue; - - if (opt_MARKET) { - if (ontradingblock(type, (int *)&item.ship)) { - pr("You cannot scrap an item on the trading block!\n"); - continue; - } + } + } + } + pr("%s", prship(&item.ship)); + getvec(VT_ITEM, itemvec, (s_char *)&item.ship, EF_SHIP); + for (i = 1; i <= I_MAX; i++) { + vec[i] += itemvec[i]; + } + vec[I_LCM] += mp->m_lcm * 2 / 3 * eff; + vec[I_HCM] += mp->m_hcm * 2 / 3 * eff; + getsect(item.ship.shp_x, item.ship.shp_y, §2); + snxtitem_all(&ni2, EF_PLANE); + while (nxtitem(&ni2, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + if (plane.pln_ship == item.ship.shp_uid) { + wu(0, plane.pln_own, + "Plane %d transferred off ship %d to %s\n", + ni2.cur, item.ship.shp_uid, + xyas(plane.pln_x, plane.pln_y, player->cnum)); + plane.pln_ship = -1; + if (sect2.sct_own != plane.pln_own) { + wu(0, plane.pln_own, + "%s given to %s\n", prplane(&plane), + cname(sect2.sct_own)); + wu(0, sect2.sct_own, + "%s given to you by %s\n", prplane(&plane), + cname(player->cnum)); + } + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_own = sect2.sct_own; + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + putplane(plane.pln_uid, (s_char *)&plane); } - - if (type == EF_SHIP) { - getsect(item.ship.shp_x, item.ship.shp_y, §); - if (sect.sct_type != SCT_HARBR) - continue; - if (sect.sct_effic < 60 || sect.sct_own != player->cnum) - continue; - } else if (type == EF_LAND) { - if (item.land.lnd_ship >= 0) { - pr("%s is on a ship, and cannot be scrapped!\n", prland(&item.land)); - continue; - } - getsect(item.land.lnd_x, item.land.lnd_y, §); - } else { - getsect(item.plane.pln_x, item.plane.pln_y, §); - if (sect.sct_type != SCT_AIRPT) - continue; - if (sect.sct_effic < 60 || - (sect.sct_own != player->cnum && - getrel(getnatp(sect.sct_own),player->cnum) < FRIENDLY)) - continue; + } + snxtitem_all(&ni2, EF_LAND); + while (nxtitem(&ni2, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_ship == item.ship.shp_uid) { + wu(0, land.lnd_own, + "Land unit %d transferred off ship %d to %s\n", + ni2.cur, item.ship.shp_uid, + xyas(land.lnd_x, land.lnd_y, player->cnum)); + land.lnd_ship = -1; + if (sect2.sct_own != land.lnd_own) { + wu(0, land.lnd_own, + "%s given to %s\n", prland(&land), + cname(sect2.sct_own)); + wu(0, sect2.sct_own, + "%s given to you by %s\n", prland(&land), + cname(player->cnum)); + } + makelost(EF_LAND, land.lnd_own, land.lnd_uid, + land.lnd_x, land.lnd_y); + land.lnd_own = sect2.sct_own; + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, + land.lnd_x, land.lnd_y); + putland(land.lnd_uid, (s_char *)&land); } - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - if (type == EF_SHIP) { - eff = ((float)item.ship.shp_effic/100.0); - mp = &mchr[(int)item.ship.shp_type]; - if (opt_TRADESHIPS) { - if (mp->m_flags & M_TRADE) { - pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n"); - sprintf(prompt, "Are you really sure that you want to scrap %s (n)? ", prship(&item.ship)); - if (!confirm(prompt)) { - pr("%s not scrapped\n", prship(&item.ship)); - continue; - } - } - } - pr("%s", prship(&item.ship)); - getvec(VT_ITEM, itemvec, (s_char *)&item.ship, EF_SHIP); - for (i = 1; i <= I_MAX; i++) { - vec[i] += itemvec[i]; - } - vec[I_LCM] += mp->m_lcm * 2 / 3 * eff; - vec[I_HCM] += mp->m_hcm * 2 / 3 * eff; - getsect(item.ship.shp_x,item.ship.shp_y,§2); - snxtitem_all(&ni2, EF_PLANE); - while (nxtitem(&ni2, (s_char *)&plane)){ - if (plane.pln_own == 0) - continue; - if (plane.pln_ship == item.ship.shp_uid){ - wu(0 ,plane.pln_own, - "Plane %d transferred off ship %d to %s\n", - ni2.cur, item.ship.shp_uid, - xyas(plane.pln_x, plane.pln_y,player->cnum)); - plane.pln_ship = -1; - if(sect2.sct_own != plane.pln_own) { - wu(0, plane.pln_own, - "%s given to %s\n", prplane(&plane), - cname(sect2.sct_own)); - wu(0, sect2.sct_own, - "%s given to you by %s\n", prplane(&plane), - cname(player->cnum)); - } - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, - plane.pln_x, plane.pln_y); - plane.pln_own = sect2.sct_own; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, - plane.pln_x, plane.pln_y); - putplane(plane.pln_uid, (s_char *)&plane); - } - } - snxtitem_all(&ni2, EF_LAND); - while (nxtitem(&ni2, (s_char *)&land)){ - if (land.lnd_own == 0) - continue; - if (land.lnd_ship == item.ship.shp_uid){ - wu(0, land.lnd_own, - "Land unit %d transferred off ship %d to %s\n", - ni2.cur, item.ship.shp_uid, - xyas(land.lnd_x, land.lnd_y,player->cnum)); - land.lnd_ship = -1; - if(sect2.sct_own != land.lnd_own){ - wu(0, land.lnd_own, - "%s given to %s\n", prland(&land), - cname(sect2.sct_own)); - wu(0, sect2.sct_own, - "%s given to you by %s\n", prland(&land), - cname(player->cnum)); - } - makelost(EF_LAND, land.lnd_own, land.lnd_uid, - land.lnd_x, land.lnd_y); - land.lnd_own = sect2.sct_own; - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, - land.lnd_x, land.lnd_y); - putland(land.lnd_uid, (s_char *)&land); - } - } - makelost(EF_SHIP, item.ship.shp_own, item.ship.shp_uid, - item.ship.shp_x, item.ship.shp_y); - item.ship.shp_own = 0; - putship(item.ship.shp_uid, (s_char *)&item.ship); - } else if (type == EF_LAND) { - eff = ((float)item.land.lnd_effic/100.0); - lp = &lchr[(int)item.land.lnd_type]; - pr("%s", prland(&item.land)); - getvec(VT_ITEM, itemvec, (s_char *)&item.land, EF_LAND); - for (i = 1; i <= I_MAX; i++) { - vec[i] += itemvec[i]; - } + } + makelost(EF_SHIP, item.ship.shp_own, item.ship.shp_uid, + item.ship.shp_x, item.ship.shp_y); + item.ship.shp_own = 0; + putship(item.ship.shp_uid, (s_char *)&item.ship); + } else if (type == EF_LAND) { + eff = ((float)item.land.lnd_effic / 100.0); + lp = &lchr[(int)item.land.lnd_type]; + pr("%s", prland(&item.land)); + getvec(VT_ITEM, itemvec, (s_char *)&item.land, EF_LAND); + for (i = 1; i <= I_MAX; i++) { + vec[i] += itemvec[i]; + } /* Military, guns and shells are not required to build land units */ /* vec[I_MILIT] += total_mil(&item.land);*/ /* vec[I_GUN] += lp->l_gun * 2 / 3 * eff;*/ /* vec[I_SHELL] += lp->l_shell * 2 / 3 * eff;*/ - vec[I_LCM] += lp->l_lcm * 2 / 3 * eff; - vec[I_HCM] += lp->l_hcm * 2 / 3 * eff; - getsect(item.land.lnd_x,item.land.lnd_y,§2); - - snxtitem_all(&ni2, EF_LAND); - while (nxtitem(&ni2, (s_char *)&land)){ - if (land.lnd_own == 0) - continue; - if (land.lnd_land == item.land.lnd_uid){ - wu(0, land.lnd_own, - "Land unit %d transferred off land unit %d to %s\n", - land.lnd_uid, item.land.lnd_uid, - xyas(land.lnd_x, land.lnd_y,player->cnum)); - land.lnd_land = -1; - if (sect2.sct_own != land.lnd_own) { - wu(0, land.lnd_own, - "%s given to %s\n", prland(&land), - cname(sect2.sct_own)); - wu(0, sect2.sct_own, - "%s given to you by %s\n", prland(&land), - cname(player->cnum)); - } - makelost(EF_LAND, land.lnd_own, land.lnd_uid, - land.lnd_x, land.lnd_y); - land.lnd_own = sect2.sct_own; - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, - land.lnd_x, land.lnd_y); - putland(land.lnd_uid, (s_char *)&land); - } - } - - snxtitem_all(&ni2, EF_PLANE); - while (nxtitem(&ni2, (s_char *)&plane)) { - if (plane.pln_own == 0) - continue; - if (plane.pln_land == item.land.lnd_uid){ - wu(0, plane.pln_own, - "Plane %d transferred off land unit %d to %s\n", - ni2.cur, item.land.lnd_uid, - xyas(plane.pln_x, plane.pln_y,player->cnum)); - plane.pln_land = -1; - if(sect2.sct_own != plane.pln_own) { - wu(0, plane.pln_own, - "%s given to %s\n", prplane(&plane), - cname(sect2.sct_own)); - wu(0, sect2.sct_own, - "%s given to you by %s\n", prplane(&plane), - cname(player->cnum)); - } - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, - plane.pln_x, plane.pln_y); - plane.pln_own = sect2.sct_own; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, - plane.pln_x, plane.pln_y); - putplane(plane.pln_uid, (s_char *)&plane); - } - } - makelost(EF_LAND, item.land.lnd_own, item.land.lnd_uid, - item.land.lnd_x, item.land.lnd_y); + vec[I_LCM] += lp->l_lcm * 2 / 3 * eff; + vec[I_HCM] += lp->l_hcm * 2 / 3 * eff; + getsect(item.land.lnd_x, item.land.lnd_y, §2); + + snxtitem_all(&ni2, EF_LAND); + while (nxtitem(&ni2, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_land == item.land.lnd_uid) { + wu(0, land.lnd_own, + "Land unit %d transferred off land unit %d to %s\n", + land.lnd_uid, item.land.lnd_uid, + xyas(land.lnd_x, land.lnd_y, player->cnum)); + land.lnd_land = -1; + if (sect2.sct_own != land.lnd_own) { + wu(0, land.lnd_own, + "%s given to %s\n", prland(&land), + cname(sect2.sct_own)); + wu(0, sect2.sct_own, + "%s given to you by %s\n", prland(&land), + cname(player->cnum)); + } + makelost(EF_LAND, land.lnd_own, land.lnd_uid, + land.lnd_x, land.lnd_y); + land.lnd_own = sect2.sct_own; + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, + land.lnd_x, land.lnd_y); + putland(land.lnd_uid, (s_char *)&land); + } + } + + snxtitem_all(&ni2, EF_PLANE); + while (nxtitem(&ni2, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + if (plane.pln_land == item.land.lnd_uid) { + wu(0, plane.pln_own, + "Plane %d transferred off land unit %d to %s\n", + ni2.cur, item.land.lnd_uid, + xyas(plane.pln_x, plane.pln_y, player->cnum)); + plane.pln_land = -1; + if (sect2.sct_own != plane.pln_own) { + wu(0, plane.pln_own, + "%s given to %s\n", prplane(&plane), + cname(sect2.sct_own)); + wu(0, sect2.sct_own, + "%s given to you by %s\n", prplane(&plane), + cname(player->cnum)); + } + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_own = sect2.sct_own; + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + putplane(plane.pln_uid, (s_char *)&plane); + } + } + makelost(EF_LAND, item.land.lnd_own, item.land.lnd_uid, + item.land.lnd_x, item.land.lnd_y); item.land.lnd_own = 0; putland(item.land.lnd_uid, (s_char *)&item.land); - } else { - eff = ((float)item.land.lnd_effic/100.0); - pp = &plchr[(int)item.plane.pln_type]; - pr("%s", prplane(&item.plane)); - vec[I_LCM] += pp->pl_lcm * 2 / 3 * eff; - vec[I_HCM] += pp->pl_hcm * 2 / 3 * eff; - vec[I_MILIT] += pp->pl_crew; - makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid, - item.plane.pln_x, item.plane.pln_y); - item.plane.pln_own = 0; - putplane(item.plane.pln_uid, (s_char *)&item.plane); - } - pr(" scrapped in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - putsect(§); + } else { + eff = ((float)item.land.lnd_effic / 100.0); + pp = &plchr[(int)item.plane.pln_type]; + pr("%s", prplane(&item.plane)); + vec[I_LCM] += pp->pl_lcm * 2 / 3 * eff; + vec[I_HCM] += pp->pl_hcm * 2 / 3 * eff; + vec[I_MILIT] += pp->pl_crew; + makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid, + item.plane.pln_x, item.plane.pln_y); + item.plane.pln_own = 0; + putplane(item.plane.pln_uid, (s_char *)&item.plane); + } + pr(" scrapped in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + putsect(§); } return RET_OK; } diff --git a/src/lib/commands/scut.c b/src/lib/commands/scut.c index 70875c34e..97510df74 100644 --- a/src/lib/commands/scut.c +++ b/src/lib/commands/scut.c @@ -48,225 +48,224 @@ #include "optlist.h" union item_u { - struct shpstr ship; - struct plnstr plane; - struct lndstr land; + struct shpstr ship; + struct plnstr plane; + struct lndstr land; }; int -scuttle_tradeship(struct shpstr *sp, int interactive) +scuttle_tradeship(struct shpstr *sp, int interactive) { - extern int trade_1_dist; /* less than this gets no money */ - extern int trade_2_dist; /* less than this gets trade_1 money */ - extern int trade_3_dist; /* less than this gets trade_2 money */ - extern float trade_1; /* return on trade_1 distance */ - extern float trade_2; /* return on trade_2 distance */ - extern float trade_3; /* return on trade_3 distance */ - extern float trade_ally_bonus; /* 20% bonus for trading with allies */ - extern float trade_ally_cut; /* 10% bonus for ally you trade with */ - float cash = 0; - float ally_cash = 0; - int dist; - struct sctstr sect; - struct mchrstr *mp; - struct natstr *np; - s_char buf[512]; - struct natstr *natp; + extern int trade_1_dist; /* less than this gets no money */ + extern int trade_2_dist; /* less than this gets trade_1 money */ + extern int trade_3_dist; /* less than this gets trade_2 money */ + extern float trade_1; /* return on trade_1 distance */ + extern float trade_2; /* return on trade_2 distance */ + extern float trade_3; /* return on trade_3 distance */ + extern float trade_ally_bonus; /* 20% bonus for trading with allies */ + extern float trade_ally_cut; /* 10% bonus for ally you trade with */ + float cash = 0; + float ally_cash = 0; + int dist; + struct sctstr sect; + struct mchrstr *mp; + struct natstr *np; + s_char buf[512]; + struct natstr *natp; - mp = &mchr[(int)sp->shp_type]; - getsect(sp->shp_x,sp->shp_y,§); - if (sect.sct_own && sect.sct_type == SCT_HARBR) { - dist = mapdist(sp->shp_x, sp->shp_y, - sp->shp_orig_x, - sp->shp_orig_y); - if (interactive) - pr("%s has gone %d sects\n", prship(sp), dist); - else - wu(0, sp->shp_own, "%s has gone %d sects\n", prship(sp), - dist); - if (dist < trade_1_dist) - cash = 0; - else if (dist < trade_2_dist) - cash = (1.0 + trade_1*((float)dist)); - else if (dist < trade_3_dist) - cash = (1.0 + trade_2*((float)dist)); - else - cash = (1.0 + trade_3*((float)dist)); - cash *= mp->m_cost; - cash *= (((float)sp->shp_effic) / 100.0); + mp = &mchr[(int)sp->shp_type]; + getsect(sp->shp_x, sp->shp_y, §); + if (sect.sct_own && sect.sct_type == SCT_HARBR) { + dist = mapdist(sp->shp_x, sp->shp_y, + sp->shp_orig_x, sp->shp_orig_y); + if (interactive) + pr("%s has gone %d sects\n", prship(sp), dist); + else + wu(0, sp->shp_own, "%s has gone %d sects\n", prship(sp), dist); + if (dist < trade_1_dist) + cash = 0; + else if (dist < trade_2_dist) + cash = (1.0 + trade_1 * ((float)dist)); + else if (dist < trade_3_dist) + cash = (1.0 + trade_2 * ((float)dist)); + else + cash = (1.0 + trade_3 * ((float)dist)); + cash *= mp->m_cost; + cash *= (((float)sp->shp_effic) / 100.0); - if (sect.sct_own != sp->shp_own) { - cash *= (1.0 + trade_ally_bonus); - ally_cash = cash * trade_ally_cut; - } + if (sect.sct_own != sp->shp_own) { + cash *= (1.0 + trade_ally_bonus); + ally_cash = cash * trade_ally_cut; } + } - if (!interactive && cash) { - natp = getnatp(sp->shp_own); - natp->nat_money += cash; - putnat(natp); - wu(0, sp->shp_own, "You just made $%d.\n", (int)cash); - } else if (!cash && !interactive) { - wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n"); - } else if (cash && interactive) { - player->dolcost -= cash; - } else if (interactive) { - pr("You won't get any money if you scuttle in %s!", - xyas(sp->shp_x, sp->shp_y, player->cnum)); - sprintf(buf, "Are you sure you want to scuttle %s? ", - prship(sp)); - return confirm(buf); - } + if (!interactive && cash) { + natp = getnatp(sp->shp_own); + natp->nat_money += cash; + putnat(natp); + wu(0, sp->shp_own, "You just made $%d.\n", (int)cash); + } else if (!cash && !interactive) { + wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n"); + } else if (cash && interactive) { + player->dolcost -= cash; + } else if (interactive) { + pr("You won't get any money if you scuttle in %s!", + xyas(sp->shp_x, sp->shp_y, player->cnum)); + sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp)); + return confirm(buf); + } - if (ally_cash) { - np = getnatp(sect.sct_own); - np->nat_money += ally_cash; - putnat(np); - wu(0,sect.sct_own, - "Trade with %s nets you $%d at %s\n", - cname(sp->shp_own), - (int)ally_cash, - xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - if (sp->shp_own != sp->shp_orig_own) - nreport(sp->shp_own, - N_PIRATE_TRADE, sp->shp_orig_own, 1); - else - nreport(sp->shp_own, N_TRADE, sect.sct_own, 1); - } else if (sp->shp_own != sp->shp_orig_own) - nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1); + if (ally_cash) { + np = getnatp(sect.sct_own); + np->nat_money += ally_cash; + putnat(np); + wu(0, sect.sct_own, + "Trade with %s nets you $%d at %s\n", + cname(sp->shp_own), + (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + if (sp->shp_own != sp->shp_orig_own) + nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1); + else + nreport(sp->shp_own, N_TRADE, sect.sct_own, 1); + } else if (sp->shp_own != sp->shp_orig_own) + nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1); - return 1; + return 1; } int scut(void) { - struct nstr_item ni; - union item_u item; - int type; - struct mchrstr *mp; - struct plchrstr *pp; - struct lchrstr *lp; - s_char *p; - s_char prompt[128]; - s_char buf[1024]; + struct nstr_item ni; + union item_u item; + int type; + struct mchrstr *mp; + struct plchrstr *pp; + struct lchrstr *lp; + s_char *p; + s_char prompt[128]; + s_char buf[1024]; - if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf))) - return RET_SYN; - switch (*p) { - case 's': - type = EF_SHIP; break; - case 'p': - type = EF_PLANE; break; - case 'l': - type = EF_LAND; break; - default: - pr("Ships, land units, or planes only! (s, l, p)\n"); - return RET_SYN; - } - sprintf(prompt, "%s(s)? ", ef_nameof(type)); - if ((p = getstarg(player->argp[2], prompt, buf)) == 0) - return RET_SYN; - if (!snxtitem(&ni, type, p)) - return RET_SYN; - if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p) - || islist(p))){ - s_char y_or_n[80], bbuf[80]; + if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf))) + return RET_SYN; + switch (*p) { + case 's': + type = EF_SHIP; + break; + case 'p': + type = EF_PLANE; + break; + case 'l': + type = EF_LAND; + break; + default: + pr("Ships, land units, or planes only! (s, l, p)\n"); + return RET_SYN; + } + sprintf(prompt, "%s(s)? ", ef_nameof(type)); + if ((p = getstarg(player->argp[2], prompt, buf)) == 0) + return RET_SYN; + if (!snxtitem(&ni, type, p)) + return RET_SYN; + if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p) + || islist(p))) { + s_char y_or_n[80], bbuf[80]; - if (type == EF_SHIP) { - if (*p == '*') - sprintf(bbuf,"all ships"); - else if (*p == '~') - sprintf(bbuf,"all unassigned ships"); - else if (issector(p)) - sprintf(bbuf,"all ships in %s",p); - else if (isalpha(*p)) - sprintf(bbuf,"fleet %c",*p); - else - sprintf(bbuf,"ships %s",p); - } else if (type == EF_LAND) { - if (*p == '*') - sprintf(bbuf,"all land units"); - else if (*p == '~') - sprintf(bbuf,"all unassigned land units"); - else if (issector(p)) - sprintf(bbuf,"all units in %s",p); - else if (isalpha(*p)) - sprintf(bbuf,"army %c",*p); - else - sprintf(bbuf,"units %s",p); - } else { - if (*p == '*') - sprintf(bbuf,"all planes"); - else if (*p == '~') - sprintf(bbuf,"all unassigned planes"); - else if (issector(p)) - sprintf(bbuf,"all planes in %s",p); - else if (isalpha(*p)) - sprintf(bbuf,"wing %c",*p); - else - sprintf(bbuf,"planes %s",p); - } - sprintf(y_or_n,"Really scuttle %s? ", bbuf); - if (!confirm(y_or_n)) - return RET_FAIL; + if (type == EF_SHIP) { + if (*p == '*') + sprintf(bbuf, "all ships"); + else if (*p == '~') + sprintf(bbuf, "all unassigned ships"); + else if (issector(p)) + sprintf(bbuf, "all ships in %s", p); + else if (isalpha(*p)) + sprintf(bbuf, "fleet %c", *p); + else + sprintf(bbuf, "ships %s", p); + } else if (type == EF_LAND) { + if (*p == '*') + sprintf(bbuf, "all land units"); + else if (*p == '~') + sprintf(bbuf, "all unassigned land units"); + else if (issector(p)) + sprintf(bbuf, "all units in %s", p); + else if (isalpha(*p)) + sprintf(bbuf, "army %c", *p); + else + sprintf(bbuf, "units %s", p); + } else { + if (*p == '*') + sprintf(bbuf, "all planes"); + else if (*p == '~') + sprintf(bbuf, "all unassigned planes"); + else if (issector(p)) + sprintf(bbuf, "all planes in %s", p); + else if (isalpha(*p)) + sprintf(bbuf, "wing %c", *p); + else + sprintf(bbuf, "planes %s", p); + } + sprintf(y_or_n, "Really scuttle %s? ", bbuf); + if (!confirm(y_or_n)) + return RET_FAIL; + } + while (nxtitem(&ni, (s_char *)&item)) { + if (!player->owner) + continue; + if (opt_MARKET) { + if (ontradingblock(type, (int *)&item.ship)) { + pr("You cannot scuttle an item on the trading block!\n"); + continue; + } } - while (nxtitem(&ni, (s_char *)&item)) { - if (!player->owner) - continue; - if (opt_MARKET) { - if (ontradingblock(type, (int *)&item.ship)) { - pr("You cannot scuttle an item on the trading block!\n"); - continue; - } - } - if (type == EF_SHIP) { - mp = &mchr[(int)item.ship.shp_type]; - if (opt_TRADESHIPS) { - if (mp->m_flags & M_TRADE) - if (!scuttle_tradeship(&item.ship, 1)) - continue; - } - pr("%s", prship(&item.ship)); - scuttle_ship(&item.ship); - } else if (type == EF_LAND) { - if (item.land.lnd_ship >= 0) { - pr("%s is on a ship, and cannot be scuttled!\n", - prland(&item.land)); - continue; - } - lp = &lchr[(int)item.land.lnd_type]; - pr("%s", prland(&item.land)); - scuttle_land(&item.land); - } else { - pp = &plchr[(int)item.plane.pln_type]; - pr("%s", prplane(&item.plane)); - if (item.plane.pln_ship >= 0){ - struct shpstr ship; + if (type == EF_SHIP) { + mp = &mchr[(int)item.ship.shp_type]; + if (opt_TRADESHIPS) { + if (mp->m_flags & M_TRADE) + if (!scuttle_tradeship(&item.ship, 1)) + continue; + } + pr("%s", prship(&item.ship)); + scuttle_ship(&item.ship); + } else if (type == EF_LAND) { + if (item.land.lnd_ship >= 0) { + pr("%s is on a ship, and cannot be scuttled!\n", + prland(&item.land)); + continue; + } + lp = &lchr[(int)item.land.lnd_type]; + pr("%s", prland(&item.land)); + scuttle_land(&item.land); + } else { + pp = &plchr[(int)item.plane.pln_type]; + pr("%s", prplane(&item.plane)); + if (item.plane.pln_ship >= 0) { + struct shpstr ship; - getship(item.plane.pln_ship,&ship); - take_plane_off_ship(&item.plane,&ship); - } - makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid, item.plane.pln_x, item.plane.pln_y); - item.plane.pln_own = 0; - putplane(item.plane.pln_uid, (s_char *)&item.plane); - } - pr(" scuttled in %s\n", - xyas(item.ship.shp_x, item.ship.shp_y , player->cnum)); + getship(item.plane.pln_ship, &ship); + take_plane_off_ship(&item.plane, &ship); + } + makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid, + item.plane.pln_x, item.plane.pln_y); + item.plane.pln_own = 0; + putplane(item.plane.pln_uid, (s_char *)&item.plane); } + pr(" scuttled in %s\n", + xyas(item.ship.shp_x, item.ship.shp_y, player->cnum)); + } - return RET_OK; + return RET_OK; } void scuttle_ship(struct shpstr *sp) { - struct nstr_item ni; - struct sctstr sect; - struct plnstr plane; - struct lndstr land; - + struct nstr_item ni; + struct sctstr sect; + struct plnstr plane; + struct lndstr land; + getsect(sp->shp_x, sp->shp_y, §); snxtitem_all(&ni, EF_PLANE); while (nxtitem(&ni, (s_char *)&plane)) { @@ -278,13 +277,14 @@ scuttle_ship(struct shpstr *sp) wu(0, plane.pln_own, "Plane %d scuttled in %s\n", plane.pln_uid, xyas(plane.pln_x, plane.pln_y, plane.pln_own)); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); plane.pln_own = 0; } else { wu(0, plane.pln_own, "Plane %d transferred off ship %d to %s\n", plane.pln_uid, sp->shp_uid, - xyas(plane.pln_x, plane.pln_y,plane.pln_own)); + xyas(plane.pln_x, plane.pln_y, plane.pln_own)); } putplane(plane.pln_uid, (s_char *)&plane); } @@ -301,7 +301,7 @@ scuttle_ship(struct shpstr *sp) land.lnd_uid, sp->shp_uid, xyas(land.lnd_x, land.lnd_y, land.lnd_own)); putland(land.lnd_uid, (s_char *)&land); - } else + } else scuttle_land(&land); } } @@ -313,11 +313,11 @@ scuttle_ship(struct shpstr *sp) void scuttle_land(struct lndstr *lp) { - struct nstr_item ni; - struct sctstr sect; - struct plnstr plane; - struct lndstr land; - + struct nstr_item ni; + struct sctstr sect; + struct plnstr plane; + struct lndstr land; + getsect(lp->lnd_x, lp->lnd_y, §); snxtitem_all(&ni, EF_PLANE); while (nxtitem(&ni, (s_char *)&plane)) { @@ -329,13 +329,14 @@ scuttle_land(struct lndstr *lp) wu(0, plane.pln_own, "Plane %d scuttled in %s\n", plane.pln_uid, xyas(plane.pln_x, plane.pln_y, plane.pln_own)); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); plane.pln_own = 0; } else { wu(0, plane.pln_own, "Plane %d transferred off unit %d to %s\n", plane.pln_uid, lp->lnd_uid, - xyas(plane.pln_x, plane.pln_y,plane.pln_own)); + xyas(plane.pln_x, plane.pln_y, plane.pln_own)); } putplane(plane.pln_uid, (s_char *)&plane); } @@ -352,7 +353,7 @@ scuttle_land(struct lndstr *lp) land.lnd_uid, lp->lnd_uid, xyas(land.lnd_x, land.lnd_y, land.lnd_own)); putland(land.lnd_uid, (s_char *)&land); - } else + } else scuttle_land(&land); } } @@ -360,5 +361,3 @@ scuttle_land(struct lndstr *lp) lp->lnd_own = 0; putland(lp->lnd_uid, lp); } - - diff --git a/src/lib/commands/sdump.c b/src/lib/commands/sdump.c index 6b91c90d0..97ca3708d 100644 --- a/src/lib/commands/sdump.c +++ b/src/lib/commands/sdump.c @@ -48,227 +48,361 @@ int sdump(void) { - int nships; - struct nstr_item ni; - struct shpstr ship; - int vec[I_MAX+1]; - int field[128]; - struct natstr *np; - int n,i; - time_t now; + int nships; + struct nstr_item ni; + struct shpstr ship; + int vec[I_MAX + 1]; + int field[128]; + struct natstr *np; + int n, i; + time_t now; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; - prdate(); + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; + prdate(); - if (!player->argp[2]) { - for (n = 1; n <= 34; n++) field[n-1] = n; - field[n-1] = 0; - } else { - n = 2; - i = 0; - while (player->argp[n]) { - if (!strcmp("type",player->argp[n])) { - field[i++] = 1; - } else if (!strcmp("x",player->argp[n])) { - field[i++] = 2; - } else if (!strcmp("y",player->argp[n])) { - field[i++] = 3; - } else if (!strcmp("flt",player->argp[n])) { - field[i++] = 4; - } else if (!strcmp("eff",player->argp[n])) { - field[i++] = 5; - } else if (!strcmp("civ",player->argp[n])) { - field[i++] = 6; - } else if (!strcmp("mil",player->argp[n])) { - field[i++] = 7; - } else if (!strcmp("uw",player->argp[n])) { - field[i++] = 8; - } else if (!strcmp("food",player->argp[n])) { - field[i++] = 9; - } else if (!strcmp("pln",player->argp[n])) { - field[i++] = 10; - } else if (!strcmp("he",player->argp[n])) { - field[i++] = 11; - } else if (!strcmp("xl",player->argp[n])) { - field[i++] = 12; - } else if (!strcmp("land",player->argp[n])) { - field[i++] = 13; - } else if (!strcmp("mob",player->argp[n])) { - field[i++] = 14; - } else if (!strcmp("fuel",player->argp[n])) { - field[i++] = 15; - } else if (!strcmp("tech",player->argp[n])) { - field[i++] = 16; - } else if (!strcmp("shell",player->argp[n])) { - field[i++] = 17; - } else if (!strcmp("gun",player->argp[n])) { - field[i++] = 18; - } else if (!strcmp("petrol",player->argp[n])) { - field[i++] = 19; - } else if (!strcmp("iron",player->argp[n])) { - field[i++] = 20; - } else if (!strcmp("dust",player->argp[n])) { - field[i++] = 21; - } else if (!strcmp("bar",player->argp[n])) { - field[i++] = 22; - } else if (!strcmp("oil",player->argp[n])) { - field[i++] = 23; - } else if (!strcmp("lcm",player->argp[n])) { - field[i++] = 24; - } else if (!strcmp("hcm",player->argp[n])) { - field[i++] = 25; - } else if (!strcmp("rad",player->argp[n])) { - field[i++] = 26; - } else if (!strcmp("def",player->argp[n])) { - field[i++] = 27; - } else if (!strcmp("spd",player->argp[n])) { - field[i++] = 28; - } else if (!strcmp("vis",player->argp[n])) { - field[i++] = 29; - } else if (!strcmp("rng",player->argp[n])) { - field[i++] = 30; - } else if (!strcmp("fir",player->argp[n])) { - field[i++] = 31; - } else if (!strcmp("origx", player->argp[n])) { - field[i++] = 32; - } else if (!strcmp("origy", player->argp[n])) { - field[i++] = 33; - } else if (!strcmp("name",player->argp[n])) { - field[i++] = 34; - } else { - pr("Unrecognized field %s\n",player->argp[n]); - } - if (n++ > 100) { - pr("Too many fields\n"); - return RET_FAIL; - } - } - field[i] = 0; + if (!player->argp[2]) { + for (n = 1; n <= 34; n++) + field[n - 1] = n; + field[n - 1] = 0; + } else { + n = 2; + i = 0; + while (player->argp[n]) { + if (!strcmp("type", player->argp[n])) { + field[i++] = 1; + } else if (!strcmp("x", player->argp[n])) { + field[i++] = 2; + } else if (!strcmp("y", player->argp[n])) { + field[i++] = 3; + } else if (!strcmp("flt", player->argp[n])) { + field[i++] = 4; + } else if (!strcmp("eff", player->argp[n])) { + field[i++] = 5; + } else if (!strcmp("civ", player->argp[n])) { + field[i++] = 6; + } else if (!strcmp("mil", player->argp[n])) { + field[i++] = 7; + } else if (!strcmp("uw", player->argp[n])) { + field[i++] = 8; + } else if (!strcmp("food", player->argp[n])) { + field[i++] = 9; + } else if (!strcmp("pln", player->argp[n])) { + field[i++] = 10; + } else if (!strcmp("he", player->argp[n])) { + field[i++] = 11; + } else if (!strcmp("xl", player->argp[n])) { + field[i++] = 12; + } else if (!strcmp("land", player->argp[n])) { + field[i++] = 13; + } else if (!strcmp("mob", player->argp[n])) { + field[i++] = 14; + } else if (!strcmp("fuel", player->argp[n])) { + field[i++] = 15; + } else if (!strcmp("tech", player->argp[n])) { + field[i++] = 16; + } else if (!strcmp("shell", player->argp[n])) { + field[i++] = 17; + } else if (!strcmp("gun", player->argp[n])) { + field[i++] = 18; + } else if (!strcmp("petrol", player->argp[n])) { + field[i++] = 19; + } else if (!strcmp("iron", player->argp[n])) { + field[i++] = 20; + } else if (!strcmp("dust", player->argp[n])) { + field[i++] = 21; + } else if (!strcmp("bar", player->argp[n])) { + field[i++] = 22; + } else if (!strcmp("oil", player->argp[n])) { + field[i++] = 23; + } else if (!strcmp("lcm", player->argp[n])) { + field[i++] = 24; + } else if (!strcmp("hcm", player->argp[n])) { + field[i++] = 25; + } else if (!strcmp("rad", player->argp[n])) { + field[i++] = 26; + } else if (!strcmp("def", player->argp[n])) { + field[i++] = 27; + } else if (!strcmp("spd", player->argp[n])) { + field[i++] = 28; + } else if (!strcmp("vis", player->argp[n])) { + field[i++] = 29; + } else if (!strcmp("rng", player->argp[n])) { + field[i++] = 30; + } else if (!strcmp("fir", player->argp[n])) { + field[i++] = 31; + } else if (!strcmp("origx", player->argp[n])) { + field[i++] = 32; + } else if (!strcmp("origy", player->argp[n])) { + field[i++] = 33; + } else if (!strcmp("name", player->argp[n])) { + field[i++] = 34; + } else { + pr("Unrecognized field %s\n", player->argp[n]); + } + if (n++ > 100) { + pr("Too many fields\n"); + return RET_FAIL; + } } + field[i] = 0; + } + if (player->god) + pr(" "); + time(&now); + pr("DUMP SHIPS %d\n", now); + if (player->god) + pr("own "); + pr("id"); + n = 0; + while (field[n]) { + switch (field[n]) { + case 1: + pr(" type"); + break; + case 2: + pr(" x"); + break; + case 3: + pr(" y"); + break; + case 4: + pr(" flt"); + break; + case 5: + pr(" eff"); + break; + case 6: + pr(" civ"); + break; + case 7: + pr(" mil"); + break; + case 8: + pr(" uw"); + break; + case 9: + pr(" food"); + break; + case 10: + pr(" pln"); + break; + case 11: + pr(" he"); + break; + case 12: + pr(" xl"); + break; + case 13: + pr(" land"); + break; + case 14: + pr(" mob"); + break; + case 15: + pr(" fuel"); + break; + case 16: + pr(" tech"); + break; + case 17: + pr(" shell"); + break; + case 18: + pr(" gun"); + break; + case 19: + pr(" petrol"); + break; + case 20: + pr(" iron"); + break; + case 21: + pr(" dust"); + break; + case 22: + pr(" bar"); + break; + case 23: + pr(" oil"); + break; + case 24: + pr(" lcm"); + break; + case 25: + pr(" hcm"); + break; + case 26: + pr(" rad"); + break; + case 27: + pr(" def"); + break; + case 28: + pr(" spd"); + break; + case 29: + pr(" vis"); + break; + case 30: + pr(" rng"); + break; + case 31: + pr(" fir"); + break; + case 32: + pr(" origx"); + break; + case 33: + pr(" origy"); + break; + case 34: + pr(" name"); + break; + } + n++; + } + pr("\n"); + + nships = 0; + np = getnatp(player->cnum); + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur); + continue; + } + count_planes(&ship); + count_units(&ship); + nships++; if (player->god) - pr(" "); - time(&now); - pr("DUMP SHIPS %d\n", now); - if (player->god) - pr("own "); - pr("id"); + pr("%3d ", ship.shp_own); + pr("%d", ni.cur); n = 0; + getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); while (field[n]) { - switch (field[n]) { - case 1: pr(" type"); break; - case 2: pr(" x"); break; - case 3: pr(" y"); break; - case 4: pr(" flt"); break; - case 5: pr(" eff"); break; - case 6: pr(" civ"); break; - case 7: pr(" mil"); break; - case 8: pr(" uw"); break; - case 9: pr(" food"); break; - case 10: pr(" pln"); break; - case 11: pr(" he"); break; - case 12: pr(" xl"); break; - case 13: pr(" land"); break; - case 14: pr(" mob"); break; - case 15: pr(" fuel"); break; - case 16: pr(" tech"); break; - case 17: pr(" shell"); break; - case 18: pr(" gun"); break; - case 19: pr(" petrol"); break; - case 20: pr(" iron"); break; - case 21: pr(" dust"); break; - case 22: pr(" bar"); break; - case 23: pr(" oil"); break; - case 24: pr(" lcm"); break; - case 25: pr(" hcm"); break; - case 26: pr(" rad"); break; - case 27: pr(" def"); break; - case 28: pr(" spd"); break; - case 29: pr(" vis"); break; - case 30: pr(" rng"); break; - case 31: pr(" fir"); break; - case 32: pr(" origx"); break; - case 33: pr(" origy"); break; - case 34: pr(" name"); break; - } - n++; + switch (field[n++]) { + case 1: + pr(" %0.4s", mchr[(int)ship.shp_type].m_name); + break; + case 2: + pr(" %d", xrel(np, ship.shp_x)); + break; + case 3: + pr(" %d", yrel(np, ship.shp_y)); + break; + case 4: + if (ship.shp_fleet == ' ') + pr(" ~"); + else + pr(" %c", ship.shp_fleet); + break; + case 5: + pr(" %d", ship.shp_effic); + break; + case 6: + pr(" %d", vec[I_CIVIL]); + break; + case 7: + pr(" %d", vec[I_MILIT]); + break; + case 8: + pr(" %d", vec[I_UW]); + break; + case 9: + pr(" %d", vec[I_FOOD]); + break; + case 10: + pr(" %d", ship.shp_nplane); + break; + case 11: + pr(" %d", ship.shp_nchoppers); + break; + case 12: + pr(" %d", ship.shp_nxlight); + break; + case 13: + pr(" %d", ship.shp_nland); + break; + case 14: + pr(" %d", ship.shp_mobil); + break; + case 15: + if (opt_FUEL) + pr(" %d", ship.shp_fuel); + else + pr(" 0"); + break; + case 16: + pr(" %d", ship.shp_tech); + break; + case 17: + pr(" %d", vec[I_SHELL]); + break; + case 18: + pr(" %d", vec[I_GUN]); + break; + case 19: + pr(" %d", vec[I_PETROL]); + break; + case 20: + pr(" %d", vec[I_IRON]); + break; + case 21: + pr(" %d", vec[I_DUST]); + break; + case 22: + pr(" %d", vec[I_BAR]); + break; + case 23: + pr(" %d", vec[I_OIL]); + break; + case 24: + pr(" %d", vec[I_LCM]); + break; + case 25: + pr(" %d", vec[I_HCM]); + break; + case 26: + pr(" %d", vec[I_RAD]); + break; + case 27: + pr(" %d", ship.shp_armor); + break; + case 28: + pr(" %d", ship.shp_speed); + break; + case 29: + pr(" %d", ship.shp_visib); + break; + case 30: + pr(" %d", ship.shp_frnge); + break; + case 31: + pr(" %d", ship.shp_glim); + break; + case 32: + pr(" %d", xrel(np, ship.shp_orig_x)); + break; + case 33: + pr(" %d", yrel(np, ship.shp_orig_y)); + break; + case 34: + pr(" %c%s%c", '"', ship.shp_name, '"'); + break; + } } pr("\n"); - - nships = 0; - np = getnatp(player->cnum); - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner || ship.shp_own == 0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, ni.cur); - continue; - } - count_planes(&ship); - count_units(&ship); - nships++; - if (player->god) - pr("%3d ", ship.shp_own); - pr("%d", ni.cur); - n = 0; - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - while (field[n]) { - switch (field[n++]) { - case 1: pr(" %0.4s", mchr[(int)ship.shp_type].m_name); break; - case 2: pr(" %d", xrel(np, ship.shp_x)); break; - case 3: pr(" %d", yrel(np, ship.shp_y)); break; - case 4: if (ship.shp_fleet == ' ') - pr(" ~"); - else - pr(" %c", ship.shp_fleet); - break; - case 5: pr(" %d", ship.shp_effic); break; - case 6: pr(" %d", vec[I_CIVIL]); break; - case 7: pr(" %d", vec[I_MILIT]); break; - case 8: pr(" %d", vec[I_UW]); break; - case 9: pr(" %d", vec[I_FOOD]); break; - case 10: pr(" %d", ship.shp_nplane); break; - case 11: pr(" %d",ship.shp_nchoppers); break; - case 12: pr(" %d",ship.shp_nxlight); break; - case 13: pr(" %d", ship.shp_nland); break; - case 14: pr(" %d", ship.shp_mobil); break; - case 15: if (opt_FUEL) - pr(" %d",ship.shp_fuel); - else - pr(" 0"); - break; - case 16: pr(" %d", ship.shp_tech); break; - case 17: pr(" %d", vec[I_SHELL]); break; - case 18: pr(" %d", vec[I_GUN]); break; - case 19: pr(" %d", vec[I_PETROL]); break; - case 20: pr(" %d", vec[I_IRON]); break; - case 21: pr(" %d", vec[I_DUST]); break; - case 22: pr(" %d", vec[I_BAR]); break; - case 23: pr(" %d", vec[I_OIL]); break; - case 24: pr(" %d", vec[I_LCM]); break; - case 25: pr(" %d", vec[I_HCM]); break; - case 26: pr(" %d", vec[I_RAD]); break; - case 27: pr(" %d", ship.shp_armor); break; - case 28: pr(" %d", ship.shp_speed); break; - case 29: pr(" %d", ship.shp_visib); break; - case 30: pr(" %d", ship.shp_frnge); break; - case 31: pr(" %d", ship.shp_glim); break; - case 32: pr(" %d", xrel(np, ship.shp_orig_x)); break; - case 33: pr(" %d", yrel(np, ship.shp_orig_y)); break; - case 34: pr(" %c%s%c", '"', ship.shp_name, '"'); break; - } - } - pr("\n"); - } - if (nships == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + } + if (nships == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } diff --git a/src/lib/commands/sect.c b/src/lib/commands/sect.c index c946d1e59..503d0f431 100644 --- a/src/lib/commands/sect.c +++ b/src/lib/commands/sect.c @@ -48,91 +48,89 @@ int sct(void) { - struct nstr_sect ns; - struct sctstr sect; - struct nscstr cond[NS_NCOND]; - struct range range; - struct natstr *np; - int ncond; - int nsect; - s_char *ptr; - coord y, yval; - int i; - s_char what[64]; - s_char *str; - s_char buf[1024]; - /* Note this is not re-entrant anyway, so we keep the buffers - around */ - static s_char *mapbuf = (s_char *)0; - static s_char **map = (s_char **)0; + struct nstr_sect ns; + struct sctstr sect; + struct nscstr cond[NS_NCOND]; + struct range range; + struct natstr *np; + int ncond; + int nsect; + s_char *ptr; + coord y, yval; + int i; + s_char what[64]; + s_char *str; + s_char buf[1024]; + /* Note this is not re-entrant anyway, so we keep the buffers + around */ + static s_char *mapbuf = (s_char *)0; + static s_char **map = (s_char **)0; - nsect = 0; - if(player->argp[1] == (s_char *) 0) { - if ((str = getstring("(sects)? ", buf)) == 0) - return RET_SYN; - } - else { - str = player->argp[1]; - } + nsect = 0; + if (player->argp[1] == (s_char *)0) { + if ((str = getstring("(sects)? ", buf)) == 0) + return RET_SYN; + } else { + str = player->argp[1]; + } - if(*str == '*') { - sprintf(what, "%d:%d,%d:%d", - -WORLD_X/2, WORLD_X/2-1, - -WORLD_Y/2, WORLD_Y/2-1); - if (!snxtsct(&ns, what)) - return RET_FAIL; - } - else - if (!snxtsct(&ns, str)) - return RET_SYN; - if (!mapbuf) - mapbuf = (s_char *)malloc((WORLD_Y*MAPWIDTH(1))*sizeof(s_char)); - if (!map) { - map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (map && mapbuf) { - for (i = 0; i < WORLD_Y; i++) - map[i] = &mapbuf[MAPWIDTH(1) * i]; - } else if (map) { - free((s_char *)map); - map = (s_char **)0; - } - } - if (!mapbuf || !map) { - pr("Memory error, tell the deity.\n"); - logerror("malloc failed in sect\n"); + if (*str == '*') { + sprintf(what, "%d:%d,%d:%d", + -WORLD_X / 2, WORLD_X / 2 - 1, + -WORLD_Y / 2, WORLD_Y / 2 - 1); + if (!snxtsct(&ns, what)) return RET_FAIL; + } else if (!snxtsct(&ns, str)) + return RET_SYN; + if (!mapbuf) + mapbuf = + (s_char *)malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char)); + if (!map) { + map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (map && mapbuf) { + for (i = 0; i < WORLD_Y; i++) + map[i] = &mapbuf[MAPWIDTH(1) * i]; + } else if (map) { + free((s_char *)map); + map = (s_char **)0; } - np = getnatp(player->cnum); - ncond = ns.ncond; - bcopy((s_char *)ns.cond, (s_char *)cond, sizeof(*cond) * ncond); - ns.ncond = 0; - xyrelrange(getnatp(player->cnum), &ns.range, &range); - border(&range, " ", ""); - blankfill((s_char *)mapbuf, &ns.range, 1); - while (nxtsct(&ns, §)) { - if (!player->owner) - continue; - ptr = &map[ns.dy][ns.dx]; - *ptr = dchr[sect.sct_type].d_mnem; - if (nstr_exec(cond, ncond, (s_char *)§, EF_SECTOR)) { - ++nsect; - *ptr |= 0x80; - } - } - for (i=0,y=ns.range.ly; i < ns.range.height; y++,i++) { - yval = yrel(np, y); - pr("%3d %s %-3d\n", yval, map[i], yval); - if (y >= WORLD_Y) - y -= WORLD_Y; + } + if (!mapbuf || !map) { + pr("Memory error, tell the deity.\n"); + logerror("malloc failed in sect\n"); + return RET_FAIL; + } + np = getnatp(player->cnum); + ncond = ns.ncond; + bcopy((s_char *)ns.cond, (s_char *)cond, sizeof(*cond) * ncond); + ns.ncond = 0; + xyrelrange(getnatp(player->cnum), &ns.range, &range); + border(&range, " ", ""); + blankfill((s_char *)mapbuf, &ns.range, 1); + while (nxtsct(&ns, §)) { + if (!player->owner) + continue; + ptr = &map[ns.dy][ns.dx]; + *ptr = dchr[sect.sct_type].d_mnem; + if (nstr_exec(cond, ncond, (s_char *)§, EF_SECTOR)) { + ++nsect; + *ptr |= 0x80; } - border(&range, " ", ""); - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return RET_OK; + } + for (i = 0, y = ns.range.ly; i < ns.range.height; y++, i++) { + yval = yrel(np, y); + pr("%3d %s %-3d\n", yval, map[i], yval); + if (y >= WORLD_Y) + y -= WORLD_Y; + } + border(&range, " ", ""); + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return RET_OK; } diff --git a/src/lib/commands/sell.c b/src/lib/commands/sell.c index da1263455..61c50279d 100644 --- a/src/lib/commands/sell.c +++ b/src/lib/commands/sell.c @@ -63,141 +63,140 @@ int sell(void) { - struct sctstr sect; - struct ichrstr *ip; - struct comstr comm; - int number_set; - int number_sub; - int totalcom; - int amt; - int com; - char *p; - float price; - char cc; - time_t now; - int ii = 0; - coord x, y; - s_char buf[1024]; + struct sctstr sect; + struct ichrstr *ip; + struct comstr comm; + int number_set; + int number_sub; + int totalcom; + int amt; + int com; + char *p; + float price; + char cc; + time_t now; + int ii = 0; + coord x, y; + s_char buf[1024]; - if (!opt_MARKET) { - pr("The market is disabled.\n"); - return RET_FAIL; - } - check_market(); - check_trade(); - if ((ip = whatitem(player->argp[1], "Commodity you want to sell: ")) == 0) - return RET_SYN; - if (ip->i_sell == 0) { - pr("You can't sell %s\n", ip->i_name); - return RET_FAIL; - } - if (!(p = getstarg(player->argp[2], "Sector to sell from: ",buf))) - return RET_SYN; - if (!sarg_xy(p, &x, &y)) - return RET_SYN; - if (!getsect(x, y, §)) - pr("Could not access that sector.\n"); - if ((sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) || - !player->owner) { - pr("That sector cannot sell goods.\n"); - return RET_FAIL; - } - if(sect.sct_effic < 60){ - pr("Sectors need to be >= 60%% efficient to sell goods.\n"); - return RET_FAIL; - } - if (sect.sct_mobil <= 0) { - pr("Sectors need at least 1 mobility to sell goods.\n"); - return RET_FAIL; - } - number_set = 0; - number_sub = 0; - if ((p = getstarg(player->argp[3], "Amount: ",buf)) == 0 || *p == 0) - return RET_SYN; - if (!check_sect_ok(§)) - return RET_FAIL; - number_set = atoi(p); - if ((p = getstarg(player->argp[4], "Price per unit: ", buf)) == 0 || - *p == 0) - return RET_SYN; - if (!check_sect_ok(§)) - return RET_FAIL; - price = atof(p); - if (price <= 0.0) { - pr("No sale.\n"); - return RET_FAIL; - } - if (price > 1000.0) /* Inf can cause overflow */ - price = 1000.0; /* bailey@math-cs.kent.edu */ - totalcom = 0; - /* - * military control necessary to sell - * goodies in occupied territory. - */ - if (sect.sct_oldown != player->cnum) { - int tot_mil=0; - struct nstr_item ni; - struct lndstr land; + if (!opt_MARKET) { + pr("The market is disabled.\n"); + return RET_FAIL; + } + check_market(); + check_trade(); + if ((ip = + whatitem(player->argp[1], "Commodity you want to sell: ")) == 0) + return RET_SYN; + if (ip->i_sell == 0) { + pr("You can't sell %s\n", ip->i_name); + return RET_FAIL; + } + if (!(p = getstarg(player->argp[2], "Sector to sell from: ", buf))) + return RET_SYN; + if (!sarg_xy(p, &x, &y)) + return RET_SYN; + if (!getsect(x, y, §)) + pr("Could not access that sector.\n"); + if ((sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) || + !player->owner) { + pr("That sector cannot sell goods.\n"); + return RET_FAIL; + } + if (sect.sct_effic < 60) { + pr("Sectors need to be >= 60%% efficient to sell goods.\n"); + return RET_FAIL; + } + if (sect.sct_mobil <= 0) { + pr("Sectors need at least 1 mobility to sell goods.\n"); + return RET_FAIL; + } + number_set = 0; + number_sub = 0; + if ((p = getstarg(player->argp[3], "Amount: ", buf)) == 0 || *p == 0) + return RET_SYN; + if (!check_sect_ok(§)) + return RET_FAIL; + number_set = atoi(p); + if ((p = getstarg(player->argp[4], "Price per unit: ", buf)) == 0 || + *p == 0) + return RET_SYN; + if (!check_sect_ok(§)) + return RET_FAIL; + price = atof(p); + if (price <= 0.0) { + pr("No sale.\n"); + return RET_FAIL; + } + if (price > 1000.0) /* Inf can cause overflow */ + price = 1000.0; /* bailey@math-cs.kent.edu */ + totalcom = 0; + /* + * military control necessary to sell + * goodies in occupied territory. + */ + if (sect.sct_oldown != player->cnum) { + int tot_mil = 0; + struct nstr_item ni; + struct lndstr land; - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == player->cnum) - tot_mil += total_mil(&land); - } - if (((tot_mil+(getvar(V_MILIT, (char *)§, EF_SECTOR))) * 10) - < getvar(V_CIVIL, (char *)§, EF_SECTOR)) { - pr("Military control required to sell goods.\n"); - return RET_FAIL; - } + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == player->cnum) + tot_mil += total_mil(&land); } - if (((amt = getvar(ip->i_vtype, (char *)§,EF_SECTOR))) == 0) { - pr("You don't have any %s to sell there.\n", ip->i_name); + if (((tot_mil + (getvar(V_MILIT, (char *)§, EF_SECTOR))) * 10) + < getvar(V_CIVIL, (char *)§, EF_SECTOR)) { + pr("Military control required to sell goods.\n"); return RET_FAIL; } - if (number_set > 0) - com = min(number_set, amt); - else if (number_set < 0) - com = amt + number_set; - else - com = 0; - if (com <= 0) - return RET_SYN; - totalcom += com; - amt -= com; - pr("Sold %d %s at %s (%d left)\n", com, ip->i_name, - xyas(sect.sct_x, sect.sct_y, player->cnum), amt); - putvar(ip->i_vtype, amt, (char *)§, EF_SECTOR); - cc = ip->i_mnem; - putsect(§); - if (totalcom > 0) { - for (ii = 0; getcomm(ii, &comm); ii++) { - if (comm.com_owner == 0) - break; - } - if (getcomm(ii, &comm) == 0) - ef_extend(EF_COMM, 1); - (void) time(&now); - comm.com_type = ip->i_mnem; - comm.com_owner = player->cnum; - comm.com_price = price; - comm.com_maxbidder = player->cnum; - comm.com_maxprice = price; - comm.com_markettime = now; - comm.com_amount = totalcom; - comm.com_x = 0; - comm.com_y = 0; - comm.sell_x = sect.sct_x; - comm.sell_y = sect.sct_y; - comm.com_uid = ii; - if(!putcomm(ii, &comm)) { - pr("Problems with the commodities file, call the Deity\n"); - return RET_FAIL; - } - } else { - pr("No eligible %s for sale\n", ip->i_name); + } + if (((amt = getvar(ip->i_vtype, (char *)§, EF_SECTOR))) == 0) { + pr("You don't have any %s to sell there.\n", ip->i_name); + return RET_FAIL; + } + if (number_set > 0) + com = min(number_set, amt); + else if (number_set < 0) + com = amt + number_set; + else + com = 0; + if (com <= 0) + return RET_SYN; + totalcom += com; + amt -= com; + pr("Sold %d %s at %s (%d left)\n", com, ip->i_name, + xyas(sect.sct_x, sect.sct_y, player->cnum), amt); + putvar(ip->i_vtype, amt, (char *)§, EF_SECTOR); + cc = ip->i_mnem; + putsect(§); + if (totalcom > 0) { + for (ii = 0; getcomm(ii, &comm); ii++) { + if (comm.com_owner == 0) + break; + } + if (getcomm(ii, &comm) == 0) + ef_extend(EF_COMM, 1); + (void)time(&now); + comm.com_type = ip->i_mnem; + comm.com_owner = player->cnum; + comm.com_price = price; + comm.com_maxbidder = player->cnum; + comm.com_maxprice = price; + comm.com_markettime = now; + comm.com_amount = totalcom; + comm.com_x = 0; + comm.com_y = 0; + comm.sell_x = sect.sct_x; + comm.sell_y = sect.sct_y; + comm.com_uid = ii; + if (!putcomm(ii, &comm)) { + pr("Problems with the commodities file, call the Deity\n"); return RET_FAIL; } - return RET_OK; + } else { + pr("No eligible %s for sale\n", ip->i_name); + return RET_FAIL; + } + return RET_OK; } - - diff --git a/src/lib/commands/set.c b/src/lib/commands/set.c index 17af37946..dde4b4042 100644 --- a/src/lib/commands/set.c +++ b/src/lib/commands/set.c @@ -55,132 +55,130 @@ int set(void) { - char *p; - int type; - int price; - char prompt[80]; - struct trdstr trade; - struct nstr_item ni; - struct nstr_item ni_trade; - union trdgenstr item; - union trdgenstr check; - struct sctstr sect; - int freeslot; - int foundslot; - int id; - time_t now; - s_char buf[1024]; + char *p; + int type; + int price; + char prompt[80]; + struct trdstr trade; + struct nstr_item ni; + struct nstr_item ni_trade; + union trdgenstr item; + union trdgenstr check; + struct sctstr sect; + int freeslot; + int foundslot; + int id; + time_t now; + s_char buf[1024]; - if (!opt_MARKET) { - pr("The market is disabled.\n"); - return RET_FAIL; - } - check_market(); - check_trade(); + if (!opt_MARKET) { + pr("The market is disabled.\n"); + return RET_FAIL; + } + check_market(); + check_trade(); - if ((p = getstarg(player->argp[1], "Item type? ", buf)) == 0) - return RET_SYN; - if ((type = ef_byname(p)) < 0) { - pr("%s: not an item type\n", p); - return RET_SYN; + if ((p = getstarg(player->argp[1], "Item type? ", buf)) == 0) + return RET_SYN; + if ((type = ef_byname(p)) < 0) { + pr("%s: not an item type\n", p); + return RET_SYN; + } + if (type == EF_SECTOR) + type = EF_SHIP; + if (type == EF_NEWS) + type = EF_NUKE; + if (type == EF_LOAN) + type = EF_LAND; + if (!snxtitem(&ni, type, player->argp[2])) + return RET_SYN; + while (nxtitem(&ni, (char *)&item)) { + if (!player->owner && !player->god) + continue; + getsect(item.gen.trg_x, item.gen.trg_y, §); + /* + * military control necessary to sell + * goodies in occupied territory. + */ + if (sect.sct_oldown != player->cnum && !player->god) { + int tot_mil = 0; + struct nstr_item ni; + struct lndstr land; + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == player->cnum) + tot_mil += total_mil(&land); + } + if (tot_mil + (getvar(V_MILIT, (char *)§, EF_SECTOR)) * 10 + < getvar(V_CIVIL, (char *)§, EF_SECTOR)) { + pr("Military control required to sell goods.\n"); + return RET_FAIL; + } + } + trade.trd_type = type; + sprintf(prompt, "%s #%d; Price? ", + trade_nameof(&trade, &item), ni.cur); + memcpy(&check, &item, sizeof(union trdgenstr)); + if ((p = getstarg(player->argp[3], prompt, buf)) == 0) + break; + if (memcmp(&check, &item, sizeof(union trdgenstr))) { + pr("That item has changed!\n"); + return RET_FAIL; + } + if ((price = atoi(p)) < 0) + continue; + if (!ef_lock(EF_TRADE)) { + logerror("can't lock trade file"); + return RET_SYS; + } + foundslot = -1; + freeslot = -1; + snxtitem_all(&ni_trade, EF_TRADE); + while (nxtitem(&ni_trade, (char *)&trade)) { + if (trade.trd_unitid < 0) + freeslot = ni_trade.cur; + if (trade.trd_unitid == ni.cur && trade.trd_type == type) { + foundslot = ni_trade.cur; + break; + } } - if (type == EF_SECTOR) - type = EF_SHIP; - if (type == EF_NEWS) - type = EF_NUKE; - if (type == EF_LOAN) - type = EF_LAND; - if (!snxtitem(&ni, type, player->argp[2])) - return RET_SYN; - while (nxtitem(&ni, (char *)&item)) { - if (!player->owner && !player->god) - continue; - getsect(item.gen.trg_x, item.gen.trg_y, §); - /* - * military control necessary to sell - * goodies in occupied territory. - */ - if (sect.sct_oldown != player->cnum && !player->god) { - int tot_mil=0; - struct nstr_item ni; - struct lndstr land; - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == player->cnum) - tot_mil += total_mil(&land); - } - if (tot_mil+(getvar(V_MILIT, (char *)§, EF_SECTOR)) * 10 - < getvar(V_CIVIL, (char *)§, EF_SECTOR)) { - pr("Military control required to sell goods.\n"); - return RET_FAIL; - } - } - trade.trd_type = type; - sprintf(prompt, "%s #%d; Price? ", - trade_nameof(&trade, &item), ni.cur); - memcpy(&check, &item, sizeof(union trdgenstr)); - if ((p = getstarg(player->argp[3], prompt, buf))==0) - break; - if (memcmp(&check, &item, sizeof(union trdgenstr))) { - pr("That item has changed!\n"); - return RET_FAIL; - } - if ((price = atoi(p)) < 0) - continue; - if (!ef_lock(EF_TRADE)) { - logerror("can't lock trade file"); - return RET_SYS; - } - foundslot = -1; - freeslot = -1; - snxtitem_all(&ni_trade, EF_TRADE); - while (nxtitem(&ni_trade, (char *)&trade)) { - if (trade.trd_unitid < 0) - freeslot = ni_trade.cur; - if (trade.trd_unitid == ni.cur && - trade.trd_type == type) { - foundslot = ni_trade.cur; - break; - } - } - if (price == 0 && foundslot >= 0) { - pr("%s #%d (lot #%d) removed from trading\n", - trade_nameof(&trade, &item), - ni.cur, foundslot); - trade.trd_type = 0; - trade.trd_owner = 0; - trade.trd_unitid = -1; - trade.trd_price = 0; - (void) time(&now); - trade.trd_markettime = now; - trade.trd_maxbidder = player->cnum; - trade.trd_maxprice = 0; - puttrade(ni_trade.cur, &trade); - } else if (price > 0) { - trade.trd_x = item.gen.trg_x; - trade.trd_y = item.gen.trg_x; - trade.trd_type = type; - trade.trd_owner = player->cnum; - trade.trd_unitid = ni.cur; - trade.trd_price = price; - (void) time(&now); - trade.trd_markettime = now; - trade.trd_maxbidder = player->cnum; - trade.trd_maxprice = price; - if (foundslot >= 0) - id = foundslot; - else if (freeslot >= 0) - id = freeslot; - else { - ef_extend(EF_TRADE, 1); - id = ni_trade.cur; - } - puttrade(id, &trade); - pr("%s #%d (lot #%d) price %s to $%d\n", - trade_nameof(&trade, &item), ni.cur, - id, foundslot >= 0 ? "reset" : "set", price); - } - ef_unlock(EF_TRADE); + if (price == 0 && foundslot >= 0) { + pr("%s #%d (lot #%d) removed from trading\n", + trade_nameof(&trade, &item), ni.cur, foundslot); + trade.trd_type = 0; + trade.trd_owner = 0; + trade.trd_unitid = -1; + trade.trd_price = 0; + (void)time(&now); + trade.trd_markettime = now; + trade.trd_maxbidder = player->cnum; + trade.trd_maxprice = 0; + puttrade(ni_trade.cur, &trade); + } else if (price > 0) { + trade.trd_x = item.gen.trg_x; + trade.trd_y = item.gen.trg_x; + trade.trd_type = type; + trade.trd_owner = player->cnum; + trade.trd_unitid = ni.cur; + trade.trd_price = price; + (void)time(&now); + trade.trd_markettime = now; + trade.trd_maxbidder = player->cnum; + trade.trd_maxprice = price; + if (foundslot >= 0) + id = foundslot; + else if (freeslot >= 0) + id = freeslot; + else { + ef_extend(EF_TRADE, 1); + id = ni_trade.cur; + } + puttrade(id, &trade); + pr("%s #%d (lot #%d) price %s to $%d\n", + trade_nameof(&trade, &item), ni.cur, + id, foundslot >= 0 ? "reset" : "set", price); } - return RET_OK; + ef_unlock(EF_TRADE); + } + return RET_OK; } diff --git a/src/lib/commands/setres.c b/src/lib/commands/setres.c index 9ece4d007..94536a415 100644 --- a/src/lib/commands/setres.c +++ b/src/lib/commands/setres.c @@ -54,116 +54,115 @@ int setres(void) { - struct sctstr sect; - s_char *what; - int amt; - s_char *p; - struct nstr_sect nstr; - s_char buf[1024]; + struct sctstr sect; + s_char *what; + int amt; + s_char *p; + struct nstr_sect nstr; + s_char buf[1024]; - if ((what = getstarg(player->argp[1], - "Set What (iron, gold, oil, uranium, fertility)? ", buf)) == 0) + if ((what = getstarg(player->argp[1], + "Set What (iron, gold, oil, uranium, fertility)? ", + buf)) == 0) + return RET_SYN; + switch (what[0]) { + case 'i': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) return RET_SYN; - switch (what[0]) { - case 'i': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if (amt > 100) - amt = 100; - if (amt < 0) - amt = 0; - if (sect.sct_own != 0) - resnoise(§,1,"Iron ore content", - (int) sect.sct_min, amt); - sect.sct_min = (u_char) amt; - putsect(§); - } - break; - case 'g': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if (amt > 100) - amt = 100; - if (amt < 0) - amt = 0; - if (sect.sct_own != 0) - resnoise(§,1,"Gold content", - (int) sect.sct_gmin, amt); - sect.sct_gmin = (u_char) amt; - putsect(§); - } - break; - case 'o': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if (amt > 100) - amt = 100; - if (amt < 0) - amt = 0; - if (sect.sct_own != 0) - resnoise(§,1,"Oil content", - (int) sect.sct_oil, amt); - sect.sct_oil = (u_char) amt; - putsect(§); - } - break; - case 'f': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if (amt > 100) - amt = 100; - if (amt < 0) - amt = 0; - if (sect.sct_own != 0) - resnoise(§,1,"Fertility content", - (int) sect.sct_fertil, amt); - sect.sct_fertil = (u_char) amt; - putsect(§); - } - break; - case 'u': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if (amt > 100) - amt = 100; - if (amt < 0) - amt = 0; - if (sect.sct_own != 0) - resnoise(§,1,"Uranium content", - (int) sect.sct_uran, amt); - sect.sct_uran = (u_char) amt; - putsect(§); - } - break; - default: - pr("huh?\n"); + amt = atoi(p); + if (amt > 100) + amt = 100; + if (amt < 0) + amt = 0; + if (sect.sct_own != 0) + resnoise(§, 1, "Iron ore content", + (int)sect.sct_min, amt); + sect.sct_min = (u_char)amt; + putsect(§); + } + break; + case 'g': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + if (amt > 100) + amt = 100; + if (amt < 0) + amt = 0; + if (sect.sct_own != 0) + resnoise(§, 1, "Gold content", + (int)sect.sct_gmin, amt); + sect.sct_gmin = (u_char)amt; + putsect(§); + } + break; + case 'o': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + if (amt > 100) + amt = 100; + if (amt < 0) + amt = 0; + if (sect.sct_own != 0) + resnoise(§, 1, "Oil content", (int)sect.sct_oil, amt); + sect.sct_oil = (u_char)amt; + putsect(§); + } + break; + case 'f': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + if (amt > 100) + amt = 100; + if (amt < 0) + amt = 0; + if (sect.sct_own != 0) + resnoise(§, 1, "Fertility content", + (int)sect.sct_fertil, amt); + sect.sct_fertil = (u_char)amt; + putsect(§); + } + break; + case 'u': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) return RET_SYN; + amt = atoi(p); + if (amt > 100) + amt = 100; + if (amt < 0) + amt = 0; + if (sect.sct_own != 0) + resnoise(§, 1, "Uranium content", + (int)sect.sct_uran, amt); + sect.sct_uran = (u_char)amt; + putsect(§); } - return RET_OK; + break; + default: + pr("huh?\n"); + return RET_SYN; + } + return RET_OK; } - diff --git a/src/lib/commands/setsect.c b/src/lib/commands/setsect.c index 076ac34c1..d8aa8aaa2 100644 --- a/src/lib/commands/setsect.c +++ b/src/lib/commands/setsect.c @@ -54,335 +54,328 @@ int setsector(void) { - struct sctstr sect; - s_char *what; - int amt,current; - s_char *p; - struct nstr_sect nstr; - s_char buf[1024]; - s_char char0, char1; + struct sctstr sect; + s_char *what; + int amt, current; + s_char *p; + struct nstr_sect nstr; + s_char buf[1024]; + s_char char0, char1; - if ((what = getstarg(player->argp[1], - "Give What (iron, gold, oil, uranium, fertility, owner, eff., Mob., Work, Avail., oldown, mines)? ", buf)) == 0) - return RET_SYN; - char0 = what[0]; - char1 = what[1]; + if ((what = getstarg(player->argp[1], + "Give What (iron, gold, oil, uranium, fertility, owner, eff., Mob., Work, Avail., oldown, mines)? ", + buf)) == 0) + return RET_SYN; + char0 = what[0]; + char1 = what[1]; - switch (char0) { + switch (char0) { + case 'i': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_min; + current += amt; + if (current < 0) + current = 0; + if (current > 100) + current = 100; + if (sect.sct_own != 0) + resnoise(§, 1, "Iron ore content", + (int)sect.sct_min, current); + sect.sct_min = (u_char)current; + putsect(§); + } + break; + case 'g': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_gmin; + current += amt; + if (current < 0) + current = 0; + if (current > 100) + current = 100; + if (sect.sct_own != 0) + resnoise(§, 1, "Gold content", + (int)sect.sct_gmin, current); + sect.sct_gmin = (u_char)current; + putsect(§); + } + break; + case 'o': + switch (char1) { case 'i': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_min; - current += amt; - if (current < 0) - current = 0; - if (current > 100) - current = 100; - if (sect.sct_own != 0) - resnoise(§,1,"Iron ore content", - (int) sect.sct_min, current); - sect.sct_min = (u_char) current; - putsect(§); - } - break; - case 'g': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_gmin; - current += amt; - if (current < 0) - current = 0; - if (current > 100) - current = 100; - if (sect.sct_own != 0) - resnoise(§,1,"Gold content", - (int) sect.sct_gmin, current); - sect.sct_gmin = (u_char) current; - putsect(§); - } - break; - case 'o': - switch(char1) { - case 'i': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_oil; - current += amt; - if (current < 0) - current = 0; - if (current > 100) - current = 100; - if (sect.sct_own != 0) - resnoise(§,1,"Oil content", - (int) sect.sct_oil, current); - sect.sct_oil = (u_char) current; - putsect(§); - } - break; - case 'w': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if ((amt < 0) || (amt > MAXNOC-1)) - return RET_SYN; - pr("Owner of %s changed from %s (#%d) to %s (#%d).\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - cname(sect.sct_own), - sect.sct_own, cname(amt), amt); - if (sect.sct_own) { - wu(player->cnum, sect.sct_own, - "Sector %s lost to deity intervention\n", - xyas(sect.sct_x, sect.sct_y, - sect.sct_own)); - } - if (amt) - wu(player->cnum, amt, - "Sector %s gained from deity intervention\n", - xyas(sect.sct_x, sect.sct_y, - amt)); - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - makenotlost(EF_SECTOR, amt, 0, sect.sct_x, sect.sct_y); - - sect.sct_own = (natid) amt; - putsect(§); - } - break; - case 'l': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - if ((amt < 0) || (amt > MAXNOC-1)) - return RET_SYN; - pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - cname(sect.sct_oldown), - sect.sct_oldown, cname(amt), amt); - sect.sct_oldown = (natid) amt; - putsect(§); - } - break; - default: - pr("huh?\n"); + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) + || (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_oil; + current += amt; + if (current < 0) + current = 0; + if (current > 100) + current = 100; + if (sect.sct_own != 0) + resnoise(§, 1, "Oil content", + (int)sect.sct_oil, current); + sect.sct_oil = (u_char)current; + putsect(§); + } + break; + case 'w': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) + || (*p == '\0')) return RET_SYN; - } - break; - case 'e': - if (!snxtsct(&nstr, player->argp[2])) + amt = atoi(p); + if ((amt < 0) || (amt > MAXNOC - 1)) return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_effic; - current += amt; - if (current < 0) - current = 0; - if (current > 100) - current = 100; - pr("Efficiency in %s changed to %d.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - current); - sect.sct_effic = (u_char) current; - putsect(§); + pr("Owner of %s changed from %s (#%d) to %s (#%d).\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), + cname(sect.sct_own), sect.sct_own, cname(amt), amt); + if (sect.sct_own) { + wu(player->cnum, sect.sct_own, + "Sector %s lost to deity intervention\n", + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); } - break; - case 'm': - switch(char1) { - case 'i': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - int mines; - - if(!(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - mines=getvar(V_MINE, (s_char *)§,EF_SECTOR); - current = mines; - current += amt; - if (current < 0) - current = 0; - if (sect.sct_own != 0) - resnoise(§,1,"Mines", - (int) mines, current); - putvar(V_MINE,current,(s_char *)§, - EF_SECTOR); - putsect(§); - } - break; - case 'o': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if(!(p = getstarg(player->argp[3],"What value : ",buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_mobil; - current += amt; - if (current < -127) - current = -127; - if (current > 127) - current = 127; - pr("Mobility in %s changed to %d.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - current); - sect.sct_mobil = (short) current; - putsect(§); - } - break; - default: - pr("huh?\n"); - return RET_SYN; - } - break; - case 'a': - if (!snxtsct(&nstr, player->argp[2])) + if (amt) + wu(player->cnum, amt, + "Sector %s gained from deity intervention\n", + xyas(sect.sct_x, sect.sct_y, amt)); + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, + sect.sct_y); + makenotlost(EF_SECTOR, amt, 0, sect.sct_x, sect.sct_y); + + sect.sct_own = (natid)amt; + putsect(§); + } + break; + case 'l': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) + || (*p == '\0')) return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_avail; - current += amt; - if (current < 0) - current = 0; - if (current > 9999) - current = 9999; - pr("Available in %s changed to %d.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - current); - sect.sct_avail = (short) current; - putsect(§); - } - break; - case 'w': - if (!snxtsct(&nstr, player->argp[2])) + amt = atoi(p); + if ((amt < 0) || (amt > MAXNOC - 1)) return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_work; - current += amt; - if (current < 0) - current = 0; - if (current > 100) - current = 100; - pr("Work in %s changed to %d.\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - current); - sect.sct_work = (u_char) current; - putsect(§); - } - break; - case 'f': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_fertil; - current += amt; - if (current < 0) - current = 0; - if (current > 120) - current = 120; - if (sect.sct_own != 0) - resnoise(§,1,"Fertility content", - (int) sect.sct_fertil, current); - sect.sct_fertil = (u_char) current; - putsect(§); - } - break; - case 'u': - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - while (nxtsct(&nstr,§) > 0) { - if( !(p = getstarg(player->argp[3], "What value : ", buf)) || - (*p == '\0')) - return RET_SYN; - amt = atoi(p); - current = sect.sct_uran; - current += amt; - if (current < 0) - current = 0; - if (current > 100) - current = 100; - if (sect.sct_own != 0) - resnoise(§,1,"Uranium content", - (int) sect.sct_uran, current); - sect.sct_uran = (u_char) current; - putsect(§); - } - break; + pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), + cname(sect.sct_oldown), + sect.sct_oldown, cname(amt), amt); + sect.sct_oldown = (natid)amt; + putsect(§); + } + break; default: - pr("huh?\n"); + pr("huh?\n"); + return RET_SYN; + } + break; + case 'e': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) return RET_SYN; + amt = atoi(p); + current = sect.sct_effic; + current += amt; + if (current < 0) + current = 0; + if (current > 100) + current = 100; + pr("Efficiency in %s changed to %d.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), current); + sect.sct_effic = (u_char)current; + putsect(§); } - return RET_OK; + break; + case 'm': + switch (char1) { + case 'i': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + int mines; + + if (!(p = getstarg(player->argp[3], "What value : ", buf)) + || (*p == '\0')) + return RET_SYN; + amt = atoi(p); + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + current = mines; + current += amt; + if (current < 0) + current = 0; + if (sect.sct_own != 0) + resnoise(§, 1, "Mines", (int)mines, current); + putvar(V_MINE, current, (s_char *)§, EF_SECTOR); + putsect(§); + } + break; + case 'o': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) + || (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_mobil; + current += amt; + if (current < -127) + current = -127; + if (current > 127) + current = 127; + pr("Mobility in %s changed to %d.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), current); + sect.sct_mobil = (short)current; + putsect(§); + } + break; + default: + pr("huh?\n"); + return RET_SYN; + } + break; + case 'a': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_avail; + current += amt; + if (current < 0) + current = 0; + if (current > 9999) + current = 9999; + pr("Available in %s changed to %d.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), current); + sect.sct_avail = (short)current; + putsect(§); + } + break; + case 'w': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_work; + current += amt; + if (current < 0) + current = 0; + if (current > 100) + current = 100; + pr("Work in %s changed to %d.\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), current); + sect.sct_work = (u_char)current; + putsect(§); + } + break; + case 'f': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_fertil; + current += amt; + if (current < 0) + current = 0; + if (current > 120) + current = 120; + if (sect.sct_own != 0) + resnoise(§, 1, "Fertility content", + (int)sect.sct_fertil, current); + sect.sct_fertil = (u_char)current; + putsect(§); + } + break; + case 'u': + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + while (nxtsct(&nstr, §) > 0) { + if (!(p = getstarg(player->argp[3], "What value : ", buf)) || + (*p == '\0')) + return RET_SYN; + amt = atoi(p); + current = sect.sct_uran; + current += amt; + if (current < 0) + current = 0; + if (current > 100) + current = 100; + if (sect.sct_own != 0) + resnoise(§, 1, "Uranium content", + (int)sect.sct_uran, current); + sect.sct_uran = (u_char)current; + putsect(§); + } + break; + default: + pr("huh?\n"); + return RET_SYN; + } + return RET_OK; } static void resbenefit(natid who, int good) { - if (!opt_GODNEWS) - return; + if (!opt_GODNEWS) + return; - if (good) { - if (who) - nreport(player->cnum, N_AIDS, who, 1); - } else { - if (who) - nreport(player->cnum, N_HURTS, who, 1); - } + if (good) { + if (who) + nreport(player->cnum, N_AIDS, who, 1); + } else { + if (who) + nreport(player->cnum, N_HURTS, who, 1); + } } extern void -resnoise(struct sctstr *sptr, int public_amt, s_char *name, int old, int new) +resnoise(struct sctstr *sptr, int public_amt, s_char *name, int old, + int new) { - s_char p[100]; + s_char p[100]; - pr("%s of %s changed from %d to %d%%\n", - name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new); - if (public_amt) - (void) sprintf(p, "changed from %d to %d", old, new); - else - (void) sprintf(p, "%s", oldsct_own) - wu(0, sptr->sct_own, - "%s in %s was %s by an act of %s\n", - name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own), - p, cname(player->cnum)); - resbenefit(sptr->sct_own, (old < new)); + pr("%s of %s changed from %d to %d%%\n", + name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new); + if (public_amt) + (void)sprintf(p, "changed from %d to %d", old, new); + else + (void)sprintf(p, "%s", old < new ? "increased" : "decreased"); + if (sptr->sct_own) + wu(0, sptr->sct_own, + "%s in %s was %s by an act of %s\n", + name, xyas(sptr->sct_x, sptr->sct_y, sptr->sct_own), + p, cname(player->cnum)); + resbenefit(sptr->sct_own, (old < new)); } - diff --git a/src/lib/commands/shar.c b/src/lib/commands/shar.c index 49d41b13b..984bab37d 100644 --- a/src/lib/commands/shar.c +++ b/src/lib/commands/shar.c @@ -41,40 +41,39 @@ int shar(void) { - int to; - struct nstr_sect ns; - s_char des = 0; - int n; + int to; + struct nstr_sect ns; + s_char des = 0; + int n; - if (!player->argp[1] || - !*player->argp[1] || - (to = natarg(player->argp[1], "Share bmap with which country? ")) < 0) - return RET_SYN; + if (!player->argp[1] || + !*player->argp[1] || + (to = + natarg(player->argp[1], "Share bmap with which country? ")) < 0) + return RET_SYN; - if (getrel(getnatp(to), player->cnum) < FRIENDLY) { - pr("%s does not have friendly relations towards you\n", - cname(to)); - return RET_FAIL; - } + if (getrel(getnatp(to), player->cnum) < FRIENDLY) { + pr("%s does not have friendly relations towards you\n", cname(to)); + return RET_FAIL; + } - if (!snxtsct(&ns, player->argp[2])) - return RET_SYN; + if (!snxtsct(&ns, player->argp[2])) + return RET_SYN; - if (player->argp[3] && *player->argp[3]) { - if (typematch(player->argp[3], EF_SECTOR) < 0) - return RET_SYN; - else - des = *player->argp[3]; - } + if (player->argp[3] && *player->argp[3]) { + if (typematch(player->argp[3], EF_SECTOR) < 0) + return RET_SYN; + else + des = *player->argp[3]; + } - if (!bmaps_intersect(player->cnum, to)) { - pr("Your bmap does not intersect %s's bmap.\n", cname(to)); - return RET_FAIL; - } + if (!bmaps_intersect(player->cnum, to)) { + pr("Your bmap does not intersect %s's bmap.\n", cname(to)); + return RET_FAIL; + } - n = share_bmap(player->cnum, to, &ns, des, cname(player->cnum)); - pr("%d designations transmitted\n", n); + n = share_bmap(player->cnum, to, &ns, des, cname(player->cnum)); + pr("%d designations transmitted\n", n); - return RET_OK; + return RET_OK; } - diff --git a/src/lib/commands/shark.c b/src/lib/commands/shark.c index 80749b331..7c4af2ccb 100644 --- a/src/lib/commands/shark.c +++ b/src/lib/commands/shark.c @@ -49,83 +49,82 @@ int shark(void) { - register int arg; - time_t now; - char *p; - struct lonstr loan; - struct natstr *natp; - struct natstr *oldie; - long due; - long last; - long rdur; - long xdur; - double rate; - double owed; - long payment; - s_char buf[1024]; + register int arg; + time_t now; + char *p; + struct lonstr loan; + struct natstr *natp; + struct natstr *oldie; + long due; + long last; + long rdur; + long xdur; + double rate; + double owed; + long payment; + s_char buf[1024]; - if (!opt_LOANS) { - pr("Loans are not enabled.\n"); - return RET_FAIL; - } - p = getstarg(player->argp[1], "Transfer which loan #: ", buf); - if (p == 0) - return RET_SYN; - if (*p == 0) - return RET_SYN; - arg = atoi(p); - if (arg < 0) - return RET_SYN; - /* Check if it's a valid loan to shark. That means, is it a valid loan, - not owed to this player, with a valid duration and it's been signed. */ - if (!getloan(arg,&loan) || (loan.l_loner == player->cnum) || - (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) { - pr("Invalid loan\n"); - return RET_FAIL; - } - /* If we got here, we check to see if it's been defaulted on. */ - (void) time(&now); - due = loan.l_duedate; - if (now <= due) { - pr("There has been no default on loan %d\n", arg); - return RET_FAIL; - } - last = loan.l_lastpay; - if (last < due && due < now) { - rdur = due - last; - xdur = now - due; - } else if (due < last) { - rdur = 0; - xdur = now - last; - } - rate = loan.l_irate / (loan.l_ldur * 8.64e6); + if (!opt_LOANS) { + pr("Loans are not enabled.\n"); + return RET_FAIL; + } + p = getstarg(player->argp[1], "Transfer which loan #: ", buf); + if (p == 0) + return RET_SYN; + if (*p == 0) + return RET_SYN; + arg = atoi(p); + if (arg < 0) + return RET_SYN; + /* Check if it's a valid loan to shark. That means, is it a valid loan, + not owed to this player, with a valid duration and it's been signed. */ + if (!getloan(arg, &loan) || (loan.l_loner == player->cnum) || + (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) { + pr("Invalid loan\n"); + return RET_FAIL; + } + /* If we got here, we check to see if it's been defaulted on. */ + (void)time(&now); + due = loan.l_duedate; + if (now <= due) { + pr("There has been no default on loan %d\n", arg); + return RET_FAIL; + } + last = loan.l_lastpay; + if (last < due && due < now) { + rdur = due - last; + xdur = now - due; + } else if (due < last) { + rdur = 0; + xdur = now - last; + } + rate = loan.l_irate / (loan.l_ldur * 8.64e6); - owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0); - if (((1 << 30) / owed) < loan.l_amtdue) - owed = (1 << 30); - else - owed *= loan.l_amtdue; - pr("That loan is worth $%.2f.\n", owed); - natp = getnatp(player->cnum); - payment = owed * (1.0 + loan.l_irate / 100.0); - if (payment > natp->nat_money - 100.0){ - pr("You do not have enough to cover that loan\n"); - return RET_FAIL; - }else{ - wu(0, loan.l_lonee, - "%s bought loan #%d. You now owe him!\n", - cname(player->cnum), - arg); - wu(0, loan.l_loner, - "%s bought loan #%d out from under you for %d\n", - cname(player->cnum), arg, payment); - pr("You now own loan #%d. Go break some legs.\n", arg); - } + owed = ((rdur * rate) + (xdur * rate * 2.0) + 1.0); + if (((1 << 30) / owed) < loan.l_amtdue) + owed = (1 << 30); + else + owed *= loan.l_amtdue; + pr("That loan is worth $%.2f.\n", owed); + natp = getnatp(player->cnum); + payment = owed * (1.0 + loan.l_irate / 100.0); + if (payment > natp->nat_money - 100.0) { + pr("You do not have enough to cover that loan\n"); + return RET_FAIL; + } else { + wu(0, loan.l_lonee, + "%s bought loan #%d. You now owe him!\n", + cname(player->cnum), arg); + wu(0, loan.l_loner, + "%s bought loan #%d out from under you for %d\n", + cname(player->cnum), arg, payment); + pr("You now own loan #%d. Go break some legs.\n", arg); + } /* NAT_DELTA(natp->nat_money, loan.l_loner, payment);*/ - oldie = getnatp(loan.l_loner); - oldie->nat_money += payment; - player->dolcost += payment; - loan.l_loner = player->cnum; - putloan(arg, &loan); - return RET_OK; + oldie = getnatp(loan.l_loner); + oldie->nat_money += payment; + player->dolcost += payment; + loan.l_loner = player->cnum; + putloan(arg, &loan); + return RET_OK; } diff --git a/src/lib/commands/shi.c b/src/lib/commands/shi.c index 63f76c30b..cf48ac7d3 100644 --- a/src/lib/commands/shi.c +++ b/src/lib/commands/shi.c @@ -48,74 +48,73 @@ int shi(void) { - int nships; - struct nstr_item ni; - struct shpstr ship; - int vec[I_MAX+1]; + int nships; + struct nstr_item ni; + struct shpstr ship; + int vec[I_MAX + 1]; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; - nships = 0; - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner || ship.shp_own == 0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, ni.cur); - continue; - } - count_planes(&ship); - count_units(&ship); - if (nships++ == 0) { - if (player->god) - pr("own "); -pr("shp# ship type x,y fl eff civ mil uw fd pn"); - pr(" he"); - pr(" xl"); - pr(" ln"); - pr(" mob"); - if (opt_FUEL) - pr(" fuel"); - pr(" tech\n"); - } - if (player->god) - pr("%3d ", ship.shp_own); - pr("%4d ", ni.cur); - pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); - pr("%1c", ship.shp_fleet); - pr("%4d%%", ship.shp_effic); + nships = 0; + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur); + continue; + } + count_planes(&ship); + count_units(&ship); + if (nships++ == 0) { + if (player->god) + pr("own "); + pr("shp# ship type x,y fl eff civ mil uw fd pn"); + pr(" he"); + pr(" xl"); + pr(" ln"); + pr(" mob"); + if (opt_FUEL) + pr(" fuel"); + pr(" tech\n"); + } + if (player->god) + pr("%3d ", ship.shp_own); + pr("%4d ", ni.cur); + pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + pr("%1c", ship.shp_fleet); + pr("%4d%%", ship.shp_effic); - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - pr("%4d", vec[I_CIVIL]); - pr("%4d", vec[I_MILIT]); - pr("%4d", vec[I_UW]); - pr("%4d", vec[I_FOOD]); + getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); + pr("%4d", vec[I_CIVIL]); + pr("%4d", vec[I_MILIT]); + pr("%4d", vec[I_UW]); + pr("%4d", vec[I_FOOD]); - pr("%3d", ship.shp_nplane); - pr("%3d",ship.shp_nchoppers); - pr("%3d",ship.shp_nxlight); - pr("%3d", ship.shp_nland); - pr("%4d", ship.shp_mobil); - if (opt_FUEL) - pr("%5d",ship.shp_fuel); - pr("%5d\n", ship.shp_tech); - if (opt_SHIPNAMES) { - if (ship.shp_name[0] != 0) { - if (player->god) - pr(" "); - pr(" %s\n",ship.shp_name); - } - } + pr("%3d", ship.shp_nplane); + pr("%3d", ship.shp_nchoppers); + pr("%3d", ship.shp_nxlight); + pr("%3d", ship.shp_nland); + pr("%4d", ship.shp_mobil); + if (opt_FUEL) + pr("%5d", ship.shp_fuel); + pr("%5d\n", ship.shp_tech); + if (opt_SHIPNAMES) { + if (ship.shp_name[0] != 0) { + if (player->god) + pr(" "); + pr(" %s\n", ship.shp_name); + } } - if (nships == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + } + if (nships == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } diff --git a/src/lib/commands/shoo.c b/src/lib/commands/shoo.c index 10ef40794..4c97bb4f8 100644 --- a/src/lib/commands/shoo.c +++ b/src/lib/commands/shoo.c @@ -48,89 +48,88 @@ int shoo(void) { - struct sctstr sect; - struct nstr_sect nstr; - struct nstr_item ni; - int nshot; - int mob_cost; - double m; - int item; - struct ichrstr *ip; - struct lndstr land; - int targets; - s_char *p; - int vec[I_MAX+1], mil, nsec; - s_char prompt[128]; - s_char buf[128]; + struct sctstr sect; + struct nstr_sect nstr; + struct nstr_item ni; + int nshot; + int mob_cost; + double m; + int item; + struct ichrstr *ip; + struct lndstr land; + int targets; + s_char *p; + int vec[I_MAX + 1], mil, nsec; + s_char prompt[128]; + s_char buf[128]; - ip = whatitem(player->argp[1], "Shoot what "); - if (ip == 0 || (ip->i_vtype != V_CIVIL && ip->i_vtype != V_UW)) - return RET_SYN; - item = ip - ichr; - if (!snxtsct(&nstr, player->argp[2])) - return RET_SYN; - sprintf(prompt, "number of %s to shoot (max 999)? ", ip->i_name); - p = getstarg(player->argp[3], prompt, buf); - if (p == 0 || (targets = atoi(p)) <= 0) - return RET_SYN; - if (targets > 999) - targets = 999; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (getvec(VT_ITEM, vec, (s_char *) §, EF_SECTOR) <= 0) - continue; - mil = vec[I_MILIT]; - nsec = 0; - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - mil += total_mil(&land); + ip = whatitem(player->argp[1], "Shoot what "); + if (ip == 0 || (ip->i_vtype != V_CIVIL && ip->i_vtype != V_UW)) + return RET_SYN; + item = ip - ichr; + if (!snxtsct(&nstr, player->argp[2])) + return RET_SYN; + sprintf(prompt, "number of %s to shoot (max 999)? ", ip->i_name); + p = getstarg(player->argp[3], prompt, buf); + if (p == 0 || (targets = atoi(p)) <= 0) + return RET_SYN; + if (targets > 999) + targets = 999; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR) <= 0) + continue; + mil = vec[I_MILIT]; + nsec = 0; + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + mil += total_mil(&land); - if (lchr[(int)land.lnd_type].l_flags & L_SECURITY){ - mil += total_mil(&land); - nsec++; - } - } + if (lchr[(int)land.lnd_type].l_flags & L_SECURITY) { + mil += total_mil(&land); + nsec++; + } + } - if (vec[item] == 0 || vec[I_CIVIL] > mil * 10) - continue; - nshot = vec[item] > targets ? targets : vec[item]; - m = ((double)nshot + 4.0) / 5.0; + if (vec[item] == 0 || vec[I_CIVIL] > mil * 10) + continue; + nshot = vec[item] > targets ? targets : vec[item]; + m = ((double)nshot + 4.0) / 5.0; - if (m > sect.sct_mobil) { - nshot = sect.sct_mobil * 5; - m = sect.sct_mobil; - } - /* - * Each security unit lowers the cost of - * shooting a person by 10%. However, you - * can't go lower than 50% of normal cost - */ - if (nsec > 5) - nsec=5; - m = ((float)m * (1.0-((float)nsec * 0.1))); - if (nshot <= 0) - continue; - if (m < 0) - m = 0; - if (m > sect.sct_mobil) - m = sect.sct_mobil; - mob_cost = roundavg(m); - sect.sct_mobil -= (u_char)mob_cost; - vec[item] -= nshot; - pr("BANG!! (thump) %d %s shot in %s!\n", - nshot, ip->i_name, - xyas(sect.sct_x, sect.sct_y,player->cnum)); - if (chance(nshot / 100.0)) - nreport(player->cnum, N_SHOOT_CIV, sect.sct_oldown, 1); - if (vec[item] <= 0 && ip->i_vtype == V_CIVIL && - (sect.sct_own != sect.sct_oldown)) { - sect.sct_oldown = sect.sct_own; - pr(" %s is now completely yours\n", - xyas(sect.sct_x, sect.sct_y,player->cnum)); - } - putvar(ip->i_vtype, vec[item], (s_char *)§, EF_SECTOR); - putsect(§); + if (m > sect.sct_mobil) { + nshot = sect.sct_mobil * 5; + m = sect.sct_mobil; + } + /* + * Each security unit lowers the cost of + * shooting a person by 10%. However, you + * can't go lower than 50% of normal cost + */ + if (nsec > 5) + nsec = 5; + m = ((float)m * (1.0 - ((float)nsec * 0.1))); + if (nshot <= 0) + continue; + if (m < 0) + m = 0; + if (m > sect.sct_mobil) + m = sect.sct_mobil; + mob_cost = roundavg(m); + sect.sct_mobil -= (u_char)mob_cost; + vec[item] -= nshot; + pr("BANG!! (thump) %d %s shot in %s!\n", + nshot, ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum)); + if (chance(nshot / 100.0)) + nreport(player->cnum, N_SHOOT_CIV, sect.sct_oldown, 1); + if (vec[item] <= 0 && ip->i_vtype == V_CIVIL && + (sect.sct_own != sect.sct_oldown)) { + sect.sct_oldown = sect.sct_own; + pr(" %s is now completely yours\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); } - return RET_OK; + putvar(ip->i_vtype, vec[item], (s_char *)§, EF_SECTOR); + putsect(§); + } + return RET_OK; } diff --git a/src/lib/commands/show.c b/src/lib/commands/show.c index ed0ea562d..5e57878a2 100644 --- a/src/lib/commands/show.c +++ b/src/lib/commands/show.c @@ -44,80 +44,88 @@ int show(void) { - s_char *p; - void (*cfunc)(int); - void (*sfunc)(int); - void (*bfunc)(int); - struct natstr *natp; - int tlev; - s_char buf[1024]; - extern float drnuke_const; - int rlev; + s_char *p; + void (*cfunc) (int); + void (*sfunc) (int); + void (*bfunc) (int); + struct natstr *natp; + int tlev; + s_char buf[1024]; + extern float drnuke_const; + int rlev; - if (!(p = getstarg(player->argp[1], "Describe what (plane, nuke, bridge, ship, sect, land unit, tower)? ", buf)) || !*p) - return RET_SYN; + if (! + (p = + getstarg(player->argp[1], + "Describe what (plane, nuke, bridge, ship, sect, land unit, tower)? ", + buf)) || !*p) + return RET_SYN; - natp = getnatp (player->cnum); - rlev = (int) (1.25 * natp->nat_level[NAT_RLEV]); + natp = getnatp(player->cnum); + rlev = (int)(1.25 * natp->nat_level[NAT_RLEV]); - if (!player->argp[3]) { - tlev = (int) (1.25 * natp->nat_level[NAT_TLEV]); - if (player->god) - tlev = 1000; - } else { - tlev = (int)atoi(player->argp[3]); - if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god) - tlev = (int) (1.25 * natp->nat_level[NAT_TLEV]); - } + if (!player->argp[3]) { + tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); if (player->god) - rlev = 1000; - pr("Printing for tech level '%d'\n", tlev); - switch (*p) { - case 'b': - show_bridge(99999); - return RET_OK; - case 't': - show_tower(99999); - return RET_OK; - case 'n': - if (opt_DRNUKE) - tlev = ((rlev/drnuke_const) > tlev ? tlev : - (rlev/drnuke_const)); - bfunc = show_nuke_build; - cfunc = show_nuke_capab; - sfunc = show_nuke_stats; - break; - case 'l': - bfunc = show_land_build; - sfunc = show_land_stats; - cfunc = show_land_capab; - break; - case 'p': - bfunc = show_plane_build; - sfunc = show_plane_stats; - cfunc = show_plane_capab; - break; - case 's': - if (*(p+1) == 'e'){ - bfunc = show_sect_build; - sfunc = show_sect_stats; - cfunc = show_sect_capab; - }else{ - bfunc = show_ship_build; - sfunc = show_ship_stats; - cfunc = show_ship_capab; - } - break; - default: - return RET_SYN; - } - if (!(p = getstarg(player->argp[2], "Build, stats, or capability data (b,s,c)? ", buf)) || !*p) - return RET_SYN; - if (*p == 'B' || *p == 'b') - (*bfunc) (tlev); - else if (*p == 'C' || *p == 'c') - (*cfunc) (tlev); - else if (*p == 'S' || *p == 's') - (*sfunc) (tlev); + tlev = 1000; + } else { + tlev = (int)atoi(player->argp[3]); + if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god) + tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); + } + if (player->god) + rlev = 1000; + pr("Printing for tech level '%d'\n", tlev); + switch (*p) { + case 'b': + show_bridge(99999); return RET_OK; + case 't': + show_tower(99999); + return RET_OK; + case 'n': + if (opt_DRNUKE) + tlev = ((rlev / drnuke_const) > tlev ? tlev : + (rlev / drnuke_const)); + bfunc = show_nuke_build; + cfunc = show_nuke_capab; + sfunc = show_nuke_stats; + break; + case 'l': + bfunc = show_land_build; + sfunc = show_land_stats; + cfunc = show_land_capab; + break; + case 'p': + bfunc = show_plane_build; + sfunc = show_plane_stats; + cfunc = show_plane_capab; + break; + case 's': + if (*(p + 1) == 'e') { + bfunc = show_sect_build; + sfunc = show_sect_stats; + cfunc = show_sect_capab; + } else { + bfunc = show_ship_build; + sfunc = show_ship_stats; + cfunc = show_ship_capab; + } + break; + default: + return RET_SYN; + } + if (! + (p = + getstarg(player->argp[2], + "Build, stats, or capability data (b,s,c)? ", buf)) + || !*p) + return RET_SYN; + if (*p == 'B' || *p == 'b') + (*bfunc) (tlev); + else if (*p == 'C' || *p == 'c') + (*cfunc) (tlev); + else if (*p == 'S' || *p == 's') + (*sfunc) (tlev); + return RET_OK; } diff --git a/src/lib/commands/shut.c b/src/lib/commands/shut.c index 0e696e289..c78ead66e 100644 --- a/src/lib/commands/shut.c +++ b/src/lib/commands/shut.c @@ -44,57 +44,60 @@ extern void shutdown_sequence(); int shut(void) { - extern int update_pending; - extern int shutdown_pending; - int shutdown_minutes; - int shutdown_was_pending; - s_char buf[100]; - s_char newbuf[100]; - struct natstr *us; - s_char *p; - - if (update_pending) { - pr("Update is pending\n"); - return RET_FAIL; - } - shutdown_minutes = onearg(player->argp[1], "Time until shutdown in minutes (0 to abort shutdown sequence)? "); - if (shutdown_minutes < 0) - return RET_SYN; - if (!updates_disabled()) - if (!(p=getstarg(player->argp[3],"Disable update [y]? ",buf))|| - *p != 'n') - disa(); + extern int update_pending; + extern int shutdown_pending; + int shutdown_minutes; + int shutdown_was_pending; + s_char buf[100]; + s_char newbuf[100]; + struct natstr *us; + s_char *p; - shutdown_was_pending = shutdown_pending; - shutdown_pending = shutdown_minutes + !!shutdown_minutes; - buf[0] = '\0'; - if (shutdown_was_pending) { - if (shutdown_minutes) { - sprintf(buf, "The shutdown time has been changed to %d minutes", shutdown_minutes); - } else { - sprintf(buf, "The server shutdown has been cancelled"); - } - } else if (shutdown_minutes) { - pr("Shutdown sequence begun.\n"); - logerror("Shutdown sequence begun"); - empth_create(PP_SHUTDOWN, shutdown_sequence, (50*1024), - 0, "shutdownSeq", - "Counts down server shutdown", 0); - } - us = getnatp(player->cnum); - if (buf[0]) { - sprintf(newbuf, ": %s!", buf); - sendmessage(us, 0, newbuf, 1); - pr("%s.\n", buf); - logerror(buf); - } + if (update_pending) { + pr("Update is pending\n"); + return RET_FAIL; + } + shutdown_minutes = + onearg(player->argp[1], + "Time until shutdown in minutes (0 to abort shutdown sequence)? "); + if (shutdown_minutes < 0) + return RET_SYN; + if (!updates_disabled()) + if (!(p = getstarg(player->argp[3], "Disable update [y]? ", buf)) + || *p != 'n') + disa(); + + shutdown_was_pending = shutdown_pending; + shutdown_pending = shutdown_minutes + !!shutdown_minutes; + buf[0] = '\0'; + if (shutdown_was_pending) { if (shutdown_minutes) { - sprintf(buf, "The server will shut down in %d minutes", shutdown_minutes); - sprintf(newbuf, ": %s!", buf); - sendmessage(us, 0, newbuf, 1); - pr("%s.\n", buf); - logerror(buf); + sprintf(buf, + "The shutdown time has been changed to %d minutes", + shutdown_minutes); + } else { + sprintf(buf, "The server shutdown has been cancelled"); } - return RET_OK; + } else if (shutdown_minutes) { + pr("Shutdown sequence begun.\n"); + logerror("Shutdown sequence begun"); + empth_create(PP_SHUTDOWN, shutdown_sequence, (50 * 1024), + 0, "shutdownSeq", "Counts down server shutdown", 0); + } + us = getnatp(player->cnum); + if (buf[0]) { + sprintf(newbuf, ": %s!", buf); + sendmessage(us, 0, newbuf, 1); + pr("%s.\n", buf); + logerror(buf); + } + if (shutdown_minutes) { + sprintf(buf, "The server will shut down in %d minutes", + shutdown_minutes); + sprintf(newbuf, ": %s!", buf); + sendmessage(us, 0, newbuf, 1); + pr("%s.\n", buf); + logerror(buf); + } + return RET_OK; } - diff --git a/src/lib/commands/sinf.c b/src/lib/commands/sinf.c index f98a4a30e..6977a10ec 100644 --- a/src/lib/commands/sinf.c +++ b/src/lib/commands/sinf.c @@ -46,12 +46,12 @@ int sinfra(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; - double sector_mcost(); - double sector_strength(struct sctstr *); - + struct sctstr sect; + int nsect; + struct nstr_sect nstr; + double sector_mcost(); + double sector_strength(struct sctstr *); + if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; prdate(); @@ -81,7 +81,7 @@ sinfra(void) pr("%4d%% ", sect.sct_rail); pr("%4.3f ", sector_mcost(§, MOB_RAIL)); pr("%4d%% ", sect.sct_defense); - pr("%5.2f\n", sector_strength(§)); + pr("%5.2f\n", sector_strength(§)); } if (nsect == 0) { if (player->argp[1]) @@ -89,9 +89,7 @@ sinfra(void) else pr("%s: No sector(s)\n", ""); return RET_FAIL; - }else + } else pr("%d sector%s\n", nsect, splur(nsect)); return 0; } - - diff --git a/src/lib/commands/skyw.c b/src/lib/commands/skyw.c index 56868799e..37606788e 100644 --- a/src/lib/commands/skyw.c +++ b/src/lib/commands/skyw.c @@ -46,12 +46,12 @@ #define TSIZE 200 struct sky { - struct sky *s_next; - int s_spotted; - struct plnstr s_sat; + struct sky *s_next; + int s_spotted; + struct plnstr s_sat; }; -static int showsat(struct sky **skypp, int x, int y); +static int showsat(struct sky **skypp, int x, int y); /* * format: skywatch [] @@ -59,118 +59,118 @@ static int showsat(struct sky **skypp, int x, int y); int skyw(void) { - struct sctstr sect; - struct nstr_sect nstr; - struct sky *skyp; - struct sky *list[TSIZE]; - int i, k, j, n; - int vrange, see; - int x, y; - int mink, minj, maxk, maxj; - int nsat = 0; - float tech; - struct nstr_item ni; + struct sctstr sect; + struct nstr_sect nstr; + struct sky *skyp; + struct sky *list[TSIZE]; + int i, k, j, n; + int vrange, see; + int x, y; + int mink, minj, maxk, maxj; + int nsat = 0; + float tech; + struct nstr_item ni; - if (snxtsct(&nstr, player->argp[1]) == 0) - return RET_SYN; - for (i = 0; i < TSIZE; i++) - list[i] = 0; + if (snxtsct(&nstr, player->argp[1]) == 0) + return RET_SYN; + for (i = 0; i < TSIZE; i++) + list[i] = 0; + skyp = (struct sky *)malloc(sizeof(*skyp)); + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&skyp->s_sat)) { + if (!skyp->s_sat.pln_own) + continue; + if (!(skyp->s_sat.pln_flags & PLN_LAUNCHED)) + continue; + getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §); + n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE); + skyp->s_spotted = 0; + skyp->s_next = list[n]; + list[n] = skyp; skyp = (struct sky *)malloc(sizeof(*skyp)); - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *) &skyp->s_sat)) { - if (!skyp->s_sat.pln_own) - continue; - if (!(skyp->s_sat.pln_flags & PLN_LAUNCHED)) - continue; - getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §); - n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE); - skyp->s_spotted = 0; - skyp->s_next = list[n]; - list[n] = skyp; - skyp = (struct sky *)malloc(sizeof(*skyp)); - nsat++; + nsat++; + } + /* get that last one! */ + free((s_char *)skyp); + pr("- = [ Skywatch report for %s ] = -\n", cname(player->cnum)); + pr(" %18s%20s %s\n", "Country", "Satellite", "Location"); + tech = tfact(player->cnum, 1.0); + while (nxtsct(&nstr, §) && nsat) { + if (sect.sct_own != player->cnum) + continue; + see = sect.sct_type == SCT_RADAR ? 14 : 4; + vrange = (int)(sect.sct_effic / 100.0 * see * tech); + if (vrange < 1) + vrange = 1; + maxk = vrange; + maxj = vrange * 2; + vrange *= vrange; + mink = -maxk; + minj = -maxj; + for (j = minj; j <= maxj && nsat; j++) { + x = xnorm(sect.sct_x + j); + for (k = mink; k <= maxk && nsat; k++) { + if ((j + k) & 01) + continue; + /* quick range check to save time... */ + if (vrange < (j * j + 3 * k * k) / 4) + continue; + y = ynorm(sect.sct_y + k); + n = scthash(x, y, TSIZE); + if (list[n] == 0) + continue; + nsat -= showsat(&list[n], x, y); + } } - /* get that last one! */ - free((s_char *)skyp); - pr("- = [ Skywatch report for %s ] = -\n", cname(player->cnum)); - pr(" %18s%20s %s\n","Country", "Satellite", "Location"); - tech = tfact(player->cnum, 1.0); - while (nxtsct(&nstr, §) && nsat) { - if (sect.sct_own != player->cnum) - continue; - see = sect.sct_type == SCT_RADAR ? 14 : 4; - vrange = (int) (sect.sct_effic / 100.0 * see * tech); - if (vrange < 1) - vrange = 1; - maxk = vrange; - maxj = vrange * 2; - vrange *= vrange; - mink = -maxk; - minj = -maxj; - for (j = minj; j <= maxj && nsat; j++) { - x = xnorm(sect.sct_x + j); - for (k = mink; k <= maxk && nsat; k++) { - if ((j + k) & 01) - continue; - /* quick range check to save time... */ - if (vrange < (j * j + 3 * k * k) / 4) - continue; - y = ynorm(sect.sct_y + k); - n = scthash(x, y, TSIZE); - if (list[n] == 0) - continue; - nsat -= showsat(&list[n], x, y); - } - } + } + /* free up the sky structs calloc'ed above */ + for (i = 0; i < TSIZE; i++) { + while (NULL != (skyp = list[i])) { + list[i] = skyp->s_next; + free((s_char *)skyp); } - /* free up the sky structs calloc'ed above */ - for (i = 0; i < TSIZE; i++) { - while (NULL != (skyp = list[i])) { - list[i] = skyp->s_next; - free((s_char *)skyp); - } - } - return RET_OK; + } + return RET_OK; } static int showsat(struct sky **skypp, int x, int y) { - register struct sky *skyp; - register struct sky *todelete = 0; - register struct sky **prev; - register struct plchrstr *pcp; - s_char *name; - int nsat = 0; + register struct sky *skyp; + register struct sky *todelete = 0; + register struct sky **prev; + register struct plchrstr *pcp; + s_char *name; + int nsat = 0; - prev = 0; - skyp = *skypp; - prev = skypp; - do { - /* we delete it, we free it. */ - if (todelete) { - free((s_char *)todelete); - todelete = 0; - } - if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) { - prev = &(*prev)->s_next; - continue; - } - pcp = &plchr[(int)skyp->s_sat.pln_type]; - name = pcp->pl_name; - pr(" %12.12s (#%d) %20s %s\n", - cname(skyp->s_sat.pln_own), skyp->s_sat.pln_own, - name, xyas(x, y, player->cnum)); - if (opt_HIDDEN) { - /* FOUND_COAST should probably be changed to FOUND_SKY -KHS */ - setcont(player->cnum, skyp->s_sat.pln_own, FOUND_COAST); - } - *prev = skyp->s_next; - todelete = skyp; - nsat++; - } while (NULL != (skyp = skyp->s_next)); - /* check that last one! */ - if (todelete) - free((s_char *)todelete); - return (nsat); + prev = 0; + skyp = *skypp; + prev = skypp; + do { + /* we delete it, we free it. */ + if (todelete) { + free((s_char *)todelete); + todelete = 0; + } + if (skyp->s_sat.pln_x != x || skyp->s_sat.pln_y != y) { + prev = &(*prev)->s_next; + continue; + } + pcp = &plchr[(int)skyp->s_sat.pln_type]; + name = pcp->pl_name; + pr(" %12.12s (#%d) %20s %s\n", + cname(skyp->s_sat.pln_own), skyp->s_sat.pln_own, + name, xyas(x, y, player->cnum)); + if (opt_HIDDEN) { + /* FOUND_COAST should probably be changed to FOUND_SKY -KHS */ + setcont(player->cnum, skyp->s_sat.pln_own, FOUND_COAST); + } + *prev = skyp->s_next; + todelete = skyp; + nsat++; + } while (NULL != (skyp = skyp->s_next)); + /* check that last one! */ + if (todelete) + free((s_char *)todelete); + return (nsat); } diff --git a/src/lib/commands/sona.c b/src/lib/commands/sona.c index a4468cd7f..d924f1efb 100644 --- a/src/lib/commands/sona.c +++ b/src/lib/commands/sona.c @@ -53,275 +53,272 @@ int sona(void) { - struct nstr_item ni, nit; - struct sctstr sect; - struct shpstr ship; - struct shpstr targ; - struct natstr *natp; - struct mchrstr *mcp; - struct mchrstr *tmcp; - struct nstr_sect ns; - int range; - int pingrange; - int srange; - int vrange; - int dist; - int x,y; - int cx,cy; - int mines; - int changed = 0; - int row; - /* Where these are used are non-re-entrant, so we keep 'em around */ - static s_char **rad = (s_char **)0; - static s_char *radbuf = (s_char *)0; - static s_char **vis = (s_char **)0; - static s_char *visbuf = (s_char *)0; + struct nstr_item ni, nit; + struct sctstr sect; + struct shpstr ship; + struct shpstr targ; + struct natstr *natp; + struct mchrstr *mcp; + struct mchrstr *tmcp; + struct nstr_sect ns; + int range; + int pingrange; + int srange; + int vrange; + int dist; + int x, y; + int cx, cy; + int mines; + int changed = 0; + int row; + /* Where these are used are non-re-entrant, so we keep 'em around */ + static s_char **rad = (s_char **)0; + static s_char *radbuf = (s_char *)0; + static s_char **vis = (s_char **)0; + static s_char *visbuf = (s_char *)0; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; - if (!radbuf) - radbuf = (s_char *)malloc((WORLD_Y*(WORLD_X+1)) * sizeof(s_char)); - if (!visbuf) - visbuf = (s_char *)malloc((WORLD_Y*(WORLD_X+1)) * sizeof(s_char)); - if (!rad) { - rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (rad && radbuf) { - for (x = 0; x < WORLD_Y; x++) { - rad[x] = &radbuf[(WORLD_X + 1) * x]; - } - } else if (rad) { - free((s_char *)rad); - rad = (s_char **)0; + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; + if (!radbuf) + radbuf = + (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * sizeof(s_char)); + if (!visbuf) + visbuf = + (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * sizeof(s_char)); + if (!rad) { + rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (rad && radbuf) { + for (x = 0; x < WORLD_Y; x++) { + rad[x] = &radbuf[(WORLD_X + 1) * x]; } + } else if (rad) { + free((s_char *)rad); + rad = (s_char **)0; } - if (!vis) { - vis = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (vis && visbuf) { - for (x = 0; x < WORLD_Y; x++) { - vis[x] = &visbuf[(WORLD_X + 1) * x]; - } - } else if (vis) { - free((s_char *)vis); - vis = (s_char **)0; + } + if (!vis) { + vis = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (vis && visbuf) { + for (x = 0; x < WORLD_Y; x++) { + vis[x] = &visbuf[(WORLD_X + 1) * x]; } + } else if (vis) { + free((s_char *)vis); + vis = (s_char **)0; } - if (!radbuf || !visbuf || !rad || !vis) { - pr("Memory error, tell the deity.\n"); - logerror("malloc failed in sona\n"); - return RET_FAIL; + } + if (!radbuf || !visbuf || !rad || !vis) { + pr("Memory error, tell the deity.\n"); + logerror("malloc failed in sona\n"); + return RET_FAIL; + } + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner) + continue; + mcp = &mchr[(int)ship.shp_type]; + if (!(mcp->m_flags & M_SONAR)) + continue; + getsect(ship.shp_x, ship.shp_y, §); + if (sect.sct_type != SCT_WATER) + continue; + range = (int)techfact(ship.shp_tech, (double)mcp->m_vrnge); + srange = min(7, 7 * range * ship.shp_effic / 200); + pr("%s at %s efficiency %d%%, max range %d\n", + prship(&ship), + xyas(ship.shp_x, ship.shp_y, player->cnum), + ship.shp_effic, srange); + snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange); + blankfill((s_char *)radbuf, &ns.range, 1); + while (nxtsct(&ns, §)) { + if (player->owner || sect.sct_type == SCT_WATER) + rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; + else { + rad[ns.dy][ns.dx] = '?'; + } } - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner) - continue; - mcp = &mchr[(int)ship.shp_type]; - if (!(mcp->m_flags & M_SONAR)) - continue; - getsect(ship.shp_x, ship.shp_y, §); - if (sect.sct_type != SCT_WATER) - continue; - range = (int) techfact(ship.shp_tech, - (double) mcp->m_vrnge); - srange = min(7, 7 * range * ship.shp_effic / 200); - pr("%s at %s efficiency %d%%, max range %d\n", - prship(&ship), - xyas(ship.shp_x, ship.shp_y, player->cnum), - ship.shp_effic, - srange); - snxtsct_dist(&ns,ship.shp_x,ship.shp_y,srange); - blankfill((s_char *)radbuf, &ns.range, 1); - while(nxtsct(&ns,§)){ - if (player->owner || sect.sct_type == SCT_WATER) - rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; - else { - rad[ns.dy][ns.dx] = '?'; - } - } - snxtsct_dist(&ns,ship.shp_x,ship.shp_y,srange); - cx = deltax(ship.shp_x, ns.range.lx); - cy = deltay(ship.shp_y, ns.range.ly); - while(nxtsct(&ns,§)) { - if (!line_of_sight(rad, cx, cy, ns.dx, ns.dy)) { - rad[ns.dy][ns.dx] = ' '; - continue; - } - if (ship.shp_tech >= 310 && - sect.sct_type == SCT_WATER) { - mines=getvar(V_MINE,(s_char *)§,EF_SECTOR); - if (mines) { - pr("Sonar detects %d mines in %s!\n", - mines, - xyas(sect.sct_x,sect.sct_y,player->cnum)); - rad[ns.dy][ns.dx] = 'X'; - } - } - changed |= map_set(player->cnum, sect.sct_x, sect.sct_y, - rad[ns.dy][ns.dx], 0); - + snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange); + cx = deltax(ship.shp_x, ns.range.lx); + cy = deltay(ship.shp_y, ns.range.ly); + while (nxtsct(&ns, §)) { + if (!line_of_sight(rad, cx, cy, ns.dx, ns.dy)) { + rad[ns.dy][ns.dx] = ' '; + continue; + } + if (ship.shp_tech >= 310 && sect.sct_type == SCT_WATER) { + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + if (mines) { + pr("Sonar detects %d mines in %s!\n", + mines, xyas(sect.sct_x, sect.sct_y, player->cnum)); + rad[ns.dy][ns.dx] = 'X'; } - bzero((s_char *)visbuf, (WORLD_Y * (WORLD_X + 1))); - snxtitem_dist(&nit, EF_SHIP, ship.shp_x, ship.shp_y, range); - while (nxtitem(&nit, (caddr_t)&targ)) { + } + changed |= map_set(player->cnum, sect.sct_x, sect.sct_y, + rad[ns.dy][ns.dx], 0); - if (targ.shp_own == player->cnum || targ.shp_own == 0) - continue; - tmcp = &mchr[(int)targ.shp_type]; - pingrange = min(7, max(targ.shp_visib,10)*range/10); - vrange = pingrange * ship.shp_effic / 200; - dist = mapdist(targ.shp_x, targ.shp_y, - ship.shp_x, ship.shp_y); - pingrange = (max(pingrange, 2) * targ.shp_effic)/100; - if (dist > pingrange) - continue; - if (tmcp->m_flags & M_SONAR && targ.shp_own) { - natp = getnatp(targ.shp_own); - if (natp->nat_flags & NF_SONAR) - wu(0, targ.shp_own, - "Sonar ping from %s detected by %s!\n", - - xyas(ship.shp_x, ship.shp_y, - targ.shp_own), - prship(&targ)); - if (targ.shp_rflags & RET_SONARED){ - retreat_ship(&targ, 's'); - putship(targ.shp_uid,&targ); - } - } - if (dist > vrange) - continue; - x = deltx(&ns.range,(int)targ.shp_x); - y = delty(&ns.range,(int)targ.shp_y); - if (rad[y][x] != dchr[SCT_WATER].d_mnem && - rad[y][x] != 'X') - continue; - if (tmcp->m_flags & M_SUB && - getrel(getnatp(targ.shp_own), player->cnum) < FRIENDLY) { - if (mcp->m_vrnge + targ.shp_visib < 8) - pr("Sonar detects sub #%d @ %s\n", - targ.shp_uid, - xyas(targ.shp_x, targ.shp_y, player->cnum)); - else if (mcp->m_vrnge + targ.shp_visib < 10) - pr("Sonar detects %s @ %s\n", - prship(&targ), - xyas(targ.shp_x, targ.shp_y, player->cnum)); - else - pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own), - prship(&targ), - xyas(targ.shp_x, targ.shp_y, player->cnum)); - } else - pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own), - prship(&targ), - xyas(targ.shp_x, targ.shp_y, player->cnum)); + } + bzero((s_char *)visbuf, (WORLD_Y * (WORLD_X + 1))); + snxtitem_dist(&nit, EF_SHIP, ship.shp_x, ship.shp_y, range); + while (nxtitem(&nit, (caddr_t)&targ)) { - if (targ.shp_visib > vis[y][x]) { - vis[y][x] = targ.shp_visib; - /* &~0x20 makes it a cap letter */ - rad[y][x] = (*mchr[(int)targ.shp_type].m_name) & ~0x20; - } + if (targ.shp_own == player->cnum || targ.shp_own == 0) + continue; + tmcp = &mchr[(int)targ.shp_type]; + pingrange = min(7, max(targ.shp_visib, 10) * range / 10); + vrange = pingrange * ship.shp_effic / 200; + dist = mapdist(targ.shp_x, targ.shp_y, ship.shp_x, ship.shp_y); + pingrange = (max(pingrange, 2) * targ.shp_effic) / 100; + if (dist > pingrange) + continue; + if (tmcp->m_flags & M_SONAR && targ.shp_own) { + natp = getnatp(targ.shp_own); + if (natp->nat_flags & NF_SONAR) + wu(0, targ.shp_own, + "Sonar ping from %s detected by %s!\n", + xyas(ship.shp_x, ship.shp_y, + targ.shp_own), prship(&targ)); + if (targ.shp_rflags & RET_SONARED) { + retreat_ship(&targ, 's'); + putship(targ.shp_uid, &targ); } - if (!player->argp[2]) { - rad[cy][cx] = '0'; - for (row=0; row < ns.range.height; row++) - if (!blankrow(rad[row])) - pr("%s\n", rad[row]); - } - pr("\n"); - + } + if (dist > vrange) + continue; + x = deltx(&ns.range, (int)targ.shp_x); + y = delty(&ns.range, (int)targ.shp_y); + if (rad[y][x] != dchr[SCT_WATER].d_mnem && rad[y][x] != 'X') + continue; + if (tmcp->m_flags & M_SUB && + getrel(getnatp(targ.shp_own), player->cnum) < FRIENDLY) { + if (mcp->m_vrnge + targ.shp_visib < 8) + pr("Sonar detects sub #%d @ %s\n", + targ.shp_uid, + xyas(targ.shp_x, targ.shp_y, player->cnum)); + else if (mcp->m_vrnge + targ.shp_visib < 10) + pr("Sonar detects %s @ %s\n", + prship(&targ), + xyas(targ.shp_x, targ.shp_y, player->cnum)); + else + pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own), + prship(&targ), + xyas(targ.shp_x, targ.shp_y, player->cnum)); + } else + pr("Sonar detects %s %s @ %s\n", cname(targ.shp_own), + prship(&targ), + xyas(targ.shp_x, targ.shp_y, player->cnum)); + + if (targ.shp_visib > vis[y][x]) { + vis[y][x] = targ.shp_visib; + /* &~0x20 makes it a cap letter */ + rad[y][x] = (*mchr[(int)targ.shp_type].m_name) & ~0x20; + } } - if (changed) - writemap(player->cnum); - return RET_OK; + if (!player->argp[2]) { + rad[cy][cx] = '0'; + for (row = 0; row < ns.range.height; row++) + if (!blankrow(rad[row])) + pr("%s\n", rad[row]); + } + pr("\n"); + + } + if (changed) + writemap(player->cnum); + return RET_OK; } void -plane_sona(struct emp_qelem *plane_list, int x, int y, struct shiplook *head) +plane_sona(struct emp_qelem *plane_list, int x, int y, + struct shiplook *head) { - struct plnstr *pp; - struct plchrstr *pcp; - struct mchrstr *tmcp; - struct shpstr *targ,s; - struct natstr *natp; - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *ip; - struct sctstr sect; - int found=0; - int range,i; - int pingrange; - int vrange; - int dist; + struct plnstr *pp; + struct plchrstr *pcp; + struct mchrstr *tmcp; + struct shpstr *targ, s; + struct natstr *natp; + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *ip; + struct sctstr sect; + int found = 0; + int range, i; + int pingrange; + int vrange; + int dist; - getsect(x,y,§); - if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR)) - return; - for (qp = plane_list->q_forw; qp != plane_list; qp = next) { - next = qp->q_forw; - ip = (struct plist *) qp; - pp = &ip->plane; - pcp = ip->pcp; - if (!(pcp->pl_flags & P_A)) /* if it isn't an ASW plane */ - continue; - range = (int) techfact(pp->pln_tech, (double) ((100-pp->pln_acc)/10)); + getsect(x, y, §); + if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR)) + return; + for (qp = plane_list->q_forw; qp != plane_list; qp = next) { + next = qp->q_forw; + ip = (struct plist *)qp; + pp = &ip->plane; + pcp = ip->pcp; + if (!(pcp->pl_flags & P_A)) /* if it isn't an ASW plane */ + continue; + range = + (int)techfact(pp->pln_tech, + (double)((100 - pp->pln_acc) / 10)); /* for (i=0; targ = getshipp(i); i++) { */ - for (i=0; getship(i,&s) ; i++) { - targ = &s; - if (targ->shp_own == pp->pln_own || targ->shp_own == 0) - continue; + for (i = 0; getship(i, &s); i++) { + targ = &s; + if (targ->shp_own == pp->pln_own || targ->shp_own == 0) + continue; /* if (have_looked(targ->shp_uid,head)) continue; */ - if (have_found(targ->shp_uid,head)) - continue; - set_have_looked(targ->shp_uid,head); - tmcp = &mchr[(int)targ->shp_type]; - if (!(tmcp->m_flags & M_SUB)) - continue; - if (roll(100) > pln_identchance(pp, shp_hardtarget(targ), EF_SHIP)) - continue; - pingrange = max(targ->shp_visib, 10) * range / 10; - vrange = ((float)pingrange) * ((float)pp->pln_effic / 200.0); - dist = mapdist(targ->shp_x, targ->shp_y, x, y); - pingrange = (max(pingrange, 2) * targ->shp_effic); - pingrange = roundavg(pingrange/100.0); - if (dist > pingrange) - continue; - if (tmcp->m_flags & M_SONAR && targ->shp_own) { - natp = getnatp(targ->shp_own); - if (natp->nat_flags & NF_SONAR) - wu(0, targ->shp_own, - "Sonar ping from %s detected by %s!\n", - xyas(x, y, targ->shp_own), - prship(targ)); - } - if ((dist > vrange)) - continue; - set_have_found(targ->shp_uid,head); - if (!found){ - mpr(pp->pln_own, - "\nSonar contact in %s\n",xyas(x,y,pp->pln_own)); - found=1; - } - if (getrel(getnatp(targ->shp_own), pp->pln_own) < FRIENDLY && - roll(100) > pln_identchance(pp, shp_hardtarget(targ), EF_SHIP)) - if (roll(100) > pln_identchance(pp, shp_hardtarget(targ), EF_SHIP)) - mpr(pp->pln_own, - "sub #%d %s\n", - targ->shp_uid, - xyas(targ->shp_x, targ->shp_y, pp->pln_own)); - else - mpr(pp->pln_own, - "%s %s\n", - prship(targ), - xyas(targ->shp_x, targ->shp_y, pp->pln_own)); - else - mpr(pp->pln_own, - "%s %s @ %s\n", cname(targ->shp_own), - prship(targ), - xyas(targ->shp_x, targ->shp_y, pp->pln_own)); - } + if (have_found(targ->shp_uid, head)) + continue; + set_have_looked(targ->shp_uid, head); + tmcp = &mchr[(int)targ->shp_type]; + if (!(tmcp->m_flags & M_SUB)) + continue; + if (roll(100) > + pln_identchance(pp, shp_hardtarget(targ), EF_SHIP)) + continue; + pingrange = max(targ->shp_visib, 10) * range / 10; + vrange = ((float)pingrange) * ((float)pp->pln_effic / 200.0); + dist = mapdist(targ->shp_x, targ->shp_y, x, y); + pingrange = (max(pingrange, 2) * targ->shp_effic); + pingrange = roundavg(pingrange / 100.0); + if (dist > pingrange) + continue; + if (tmcp->m_flags & M_SONAR && targ->shp_own) { + natp = getnatp(targ->shp_own); + if (natp->nat_flags & NF_SONAR) + wu(0, targ->shp_own, + "Sonar ping from %s detected by %s!\n", + xyas(x, y, targ->shp_own), prship(targ)); + } + if ((dist > vrange)) + continue; + set_have_found(targ->shp_uid, head); + if (!found) { + mpr(pp->pln_own, + "\nSonar contact in %s\n", xyas(x, y, pp->pln_own)); + found = 1; + } + if (getrel(getnatp(targ->shp_own), pp->pln_own) < FRIENDLY && + roll(100) > pln_identchance(pp, shp_hardtarget(targ), + EF_SHIP)) + if (roll(100) > + pln_identchance(pp, shp_hardtarget(targ), EF_SHIP)) + mpr(pp->pln_own, "sub #%d %s\n", targ->shp_uid, + xyas(targ->shp_x, targ->shp_y, pp->pln_own)); + else + mpr(pp->pln_own, + "%s %s\n", + prship(targ), + xyas(targ->shp_x, targ->shp_y, pp->pln_own)); + else + mpr(pp->pln_own, + "%s %s @ %s\n", cname(targ->shp_own), + prship(targ), + xyas(targ->shp_x, targ->shp_y, pp->pln_own)); } + } } /* @@ -336,67 +333,67 @@ plane_sona(struct emp_qelem *plane_list, int x, int y, struct shiplook *head) int line_of_sight(s_char **rad, int ax, int ay, int bx, int by) { - int dx = bx - ax; - int dy = by - ay; - int dlen = LEN(dx, dy); - int n; - int cx = 0; - int cy = 0; - int tx, ty; /* test point */ - double cd_dist = dlen; /* closest distance from c to vector d */ - double md_dist; /* minimum distance from t to vector d */ - double td_dist; /* distance from t to vector d */ - double td_proj; /* the projection of t onto vector d */ - int closest; /* index of closest */ - int blocked = 0; - struct sctstr *sectp; + int dx = bx - ax; + int dy = by - ay; + int dlen = LEN(dx, dy); + int n; + int cx = 0; + int cy = 0; + int tx, ty; /* test point */ + double cd_dist = dlen; /* closest distance from c to vector d */ + double md_dist; /* minimum distance from t to vector d */ + double td_dist; /* distance from t to vector d */ + double td_proj; /* the projection of t onto vector d */ + int closest; /* index of closest */ + int blocked = 0; + struct sctstr *sectp; - while (cd_dist) { - if (blocked) - return 0; - md_dist = 100; /* will always be <= 2 */ - closest = -1; - for (n = 1; n <= 6; ++n) { /* Directions */ - tx = cx + diroff[n][0]; - ty = cy + diroff[n][1]; - if (DIST(tx,ty,dx,dy) >= cd_dist) - continue; - td_proj = (double)DOT(tx,ty,dx,dy) / dlen; - td_dist = DIST(tx,ty,td_proj*dx,td_proj*dy); - if (td_dist < md_dist) { - md_dist = td_dist; - closest = n; - } - } - if (closest < 0) /* not possible */ - return 0; - cx = cx + diroff[closest][0]; - cy = cy + diroff[closest][1]; - if (rad) { - blocked = (rad[ay+cy][ax+cx] != dchr[SCT_WATER].d_mnem); + while (cd_dist) { + if (blocked) + return 0; + md_dist = 100; /* will always be <= 2 */ + closest = -1; + for (n = 1; n <= 6; ++n) { /* Directions */ + tx = cx + diroff[n][0]; + ty = cy + diroff[n][1]; + if (DIST(tx, ty, dx, dy) >= cd_dist) + continue; + td_proj = (double)DOT(tx, ty, dx, dy) / dlen; + td_dist = DIST(tx, ty, td_proj * dx, td_proj * dy); + if (td_dist < md_dist) { + md_dist = td_dist; + closest = n; + } + } + if (closest < 0) /* not possible */ + return 0; + cx = cx + diroff[closest][0]; + cy = cy + diroff[closest][1]; + if (rad) { + blocked = (rad[ay + cy][ax + cx] != dchr[SCT_WATER].d_mnem); + } else { + sectp = getsectp((ax + cx), (ay + cy)); + if (sectp) { + if (sectp->sct_type == SCT_WATER || + sectp->sct_type == SCT_BSPAN) { + blocked = 0; } else { - sectp = getsectp((ax + cx), (ay + cy)); - if (sectp) { - if (sectp->sct_type == SCT_WATER || - sectp->sct_type == SCT_BSPAN) { - blocked = 0; - } else { - blocked = 1; - } - } + blocked = 1; } - cd_dist = DIST(cx,cy,dx,dy); + } } - return 1; + cd_dist = DIST(cx, cy, dx, dy); + } + return 1; } int blankrow(s_char *s) { - while (*s) { - if (*s != ' ') - return 0; - ++s; - } - return 1; + while (*s) { + if (*s != ' ') + return 0; + ++s; + } + return 1; } diff --git a/src/lib/commands/spy.c b/src/lib/commands/spy.c index 1a59cdb87..94d9e6df2 100644 --- a/src/lib/commands/spy.c +++ b/src/lib/commands/spy.c @@ -60,160 +60,159 @@ static int check(coord *table, int *len, coord x, coord y); int spy(void) { - int caught; - natid own; - int relat; - coord x, y; - coord nx, ny; - int military; - int savemil; - int btucost; - int i; - coord *table; /* sectors already seen */ - int t_len = 0; - int vec[I_MAX+1]; - int dvec[I_MAX+1]; - int nrecon; - int nunits; - struct nstr_sect nstr; - struct nstr_item ni; - struct natstr *natp; - struct sctstr from; - struct sctstr dsect; - struct lndstr land; - int changed = 0; - int nsects; + int caught; + natid own; + int relat; + coord x, y; + coord nx, ny; + int military; + int savemil; + int btucost; + int i; + coord *table; /* sectors already seen */ + int t_len = 0; + int vec[I_MAX + 1]; + int dvec[I_MAX + 1]; + int nrecon; + int nunits; + struct nstr_sect nstr; + struct nstr_item ni; + struct natstr *natp; + struct sctstr from; + struct sctstr dsect; + struct lndstr land; + int changed = 0; + int nsects; - /* - * first arg should be the range of sectors - */ - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - nsects = (nstr.range.width+1) * nstr.range.height / 2; - btucost = (nsects / 40) + 1; - natp = getnatp(player->cnum); - if (natp->nat_btu < btucost) { - pr("You don't have the BTU's for spying on that scale!\n"); - return RET_FAIL; + /* + * first arg should be the range of sectors + */ + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + nsects = (nstr.range.width + 1) * nstr.range.height / 2; + btucost = (nsects / 40) + 1; + natp = getnatp(player->cnum); + if (natp->nat_btu < btucost) { + pr("You don't have the BTU's for spying on that scale!\n"); + return RET_FAIL; + } + /* + * set up all the goodies we need later + * 6 = neighbors, 2 = x,y + */ + table = (coord *)malloc((nsects + 1) * 6 * 2 * sizeof(coord)); + bzero((s_char *)table, (nsects + 1) * 6 * 2 * sizeof(coord)); + pr("SPY report\n"); + prdate(); + pr(" old sct rd rl def\n"); + pr(" sect de own own eff eff eff eff civ mil shl gun pet food bars lnd pln\n"); + while (nxtsct(&nstr, &from)) { + if (!player->owner && !player->god) + continue; + getvec(VT_ITEM, vec, (s_char *)&from, EF_SECTOR); + nrecon = 0; + nunits = 0; + snxtitem_xy(&ni, EF_LAND, from.sct_x, from.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + nunits++; + if (lchr[(int)land.lnd_type].l_flags & L_RECON) + nrecon++; } + if ((military = vec[I_MILIT]) == 0 && (nunits == 0)) + continue; + x = from.sct_x; + y = from.sct_y; + /* Print out the units/planes in this sector */ + prunits(x, y); + prplanes(x, y); + savemil = military; /* - * set up all the goodies we need later - * 6 = neighbors, 2 = x,y + * check the neighboring sectors. */ - table = (coord *) malloc((nsects + 1) * 6 * 2 * sizeof(coord)); - bzero((s_char *)table, (nsects + 1) * 6 * 2 * sizeof(coord)); - pr("SPY report\n"); - prdate(); -pr(" old sct rd rl def\n"); -pr(" sect de own own eff eff eff eff civ mil shl gun pet food bars lnd pln\n"); - while (nxtsct(&nstr, &from)) { - if (!player->owner && !player->god) - continue; - getvec(VT_ITEM, vec, (s_char *) &from, EF_SECTOR); - nrecon=0; - nunits=0; - snxtitem_xy(&ni, EF_LAND, from.sct_x, from.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - nunits++; - if (lchr[(int)land.lnd_type].l_flags & L_RECON) - nrecon++; - } - if ((military = vec[I_MILIT]) == 0 && (nunits == 0)) - continue; - x = from.sct_x; - y = from.sct_y; - /* Print out the units/planes in this sector */ - prunits(x, y); - prplanes(x, y); - savemil = military; - /* - * check the neighboring sectors. - */ - for (i = 1; i <= 6; i++) { - if ((military == 0) && (nunits == 0)) - break; - nx = x + diroff[i][0]; - ny = y + diroff[i][1]; - /* - * if we've already seen the - * sector, don't bother checking it - * out. - */ - if (check(table, &t_len, nx, ny)) { - continue; - } - getsect(nx, ny, &dsect); - getvec(VT_ITEM, dvec, (s_char *) &dsect, EF_SECTOR); - if (player->owner || (dsect.sct_type == SCT_WATER) || - (!dvec[I_MILIT] && !dvec[I_CIVIL] && - (num_units(nx, ny) == 0))) { - /* mark sector as seen */ - insert(table, &t_len, nx, ny); - continue; - } - /* catch spy N/200 chance, N = # military */ - caught = chance((double) dvec[I_MILIT] / 200.0); - own = dsect.sct_own; - /* determine spyee relations with spyer */ - relat = getrel(getnatp(own), player->cnum); - if (relat == NEUTRAL && caught) { - /* neutral spy-ee */ - pr("Spy deported from %s\n", - xyas(nx, ny, player->cnum)); - if(own != 0) - wu(0, own, "%s (#%d) spy deported from %s\n", - cname(player->cnum), player->cnum, - xyas(nx, ny, own)); - } else if (relat < NEUTRAL && caught) { - /* at-war with spy-ee */ - pr("BANG!! A spy was shot in %s\n", - xyas(nx, ny, player->cnum)); - military--; - if(own != 0) - wu(0, own, "%s (#%d) spy caught in %s\n", - cname(player->cnum), player->cnum, - xyas(nx, ny, own)); - nreport(player->cnum, N_SPY_SHOT, own, 1); - } else { - insert(table, &t_len, nx, ny); - spyline(&dsect); - changed += map_set(player->cnum, dsect.sct_x, - dsect.sct_y, - dchr[dsect.sct_type].d_mnem, 0); - prunits(dsect.sct_x,dsect.sct_y); - prplanes(dsect.sct_x,dsect.sct_y); - if (opt_HIDDEN) { - setcont(player->cnum, own, FOUND_SPY); - } - } - /* - * If you have a recon unit, it'll - * see the sector anyway... - */ - if (nrecon && caught){ - insert(table, &t_len, nx, ny); - spyline(&dsect); - changed += map_set(player->cnum, dsect.sct_x, - dsect.sct_y, - dchr[dsect.sct_type].d_mnem, 0); - prunits(dsect.sct_x, dsect.sct_y); - prplanes(dsect.sct_x,dsect.sct_y); - } - } - /* subtract any military if necessary */ - if ((savemil != military) && (savemil > 0)){ - if ((military < 0) || (military > savemil)) - military = 0; - vec[I_MILIT] = military; - putvec (VT_ITEM, vec, (s_char *) &from, EF_SECTOR); - putsect(&from); + for (i = 1; i <= 6; i++) { + if ((military == 0) && (nunits == 0)) + break; + nx = x + diroff[i][0]; + ny = y + diroff[i][1]; + /* + * if we've already seen the + * sector, don't bother checking it + * out. + */ + if (check(table, &t_len, nx, ny)) { + continue; + } + getsect(nx, ny, &dsect); + getvec(VT_ITEM, dvec, (s_char *)&dsect, EF_SECTOR); + if (player->owner || (dsect.sct_type == SCT_WATER) || + (!dvec[I_MILIT] && !dvec[I_CIVIL] && + (num_units(nx, ny) == 0))) { + /* mark sector as seen */ + insert(table, &t_len, nx, ny); + continue; + } + /* catch spy N/200 chance, N = # military */ + caught = chance((double)dvec[I_MILIT] / 200.0); + own = dsect.sct_own; + /* determine spyee relations with spyer */ + relat = getrel(getnatp(own), player->cnum); + if (relat == NEUTRAL && caught) { + /* neutral spy-ee */ + pr("Spy deported from %s\n", xyas(nx, ny, player->cnum)); + if (own != 0) + wu(0, own, "%s (#%d) spy deported from %s\n", + cname(player->cnum), player->cnum, + xyas(nx, ny, own)); + } else if (relat < NEUTRAL && caught) { + /* at-war with spy-ee */ + pr("BANG!! A spy was shot in %s\n", + xyas(nx, ny, player->cnum)); + military--; + if (own != 0) + wu(0, own, "%s (#%d) spy caught in %s\n", + cname(player->cnum), player->cnum, + xyas(nx, ny, own)); + nreport(player->cnum, N_SPY_SHOT, own, 1); + } else { + insert(table, &t_len, nx, ny); + spyline(&dsect); + changed += map_set(player->cnum, dsect.sct_x, + dsect.sct_y, + dchr[dsect.sct_type].d_mnem, 0); + prunits(dsect.sct_x, dsect.sct_y); + prplanes(dsect.sct_x, dsect.sct_y); + if (opt_HIDDEN) { + setcont(player->cnum, own, FOUND_SPY); } + } + /* + * If you have a recon unit, it'll + * see the sector anyway... + */ + if (nrecon && caught) { + insert(table, &t_len, nx, ny); + spyline(&dsect); + changed += map_set(player->cnum, dsect.sct_x, + dsect.sct_y, + dchr[dsect.sct_type].d_mnem, 0); + prunits(dsect.sct_x, dsect.sct_y); + prplanes(dsect.sct_x, dsect.sct_y); + } } - if (changed) - writemap(player->cnum); - player->btused += btucost; - free((s_char *)table); - return RET_OK; + /* subtract any military if necessary */ + if ((savemil != military) && (savemil > 0)) { + if ((military < 0) || (military > savemil)) + military = 0; + vec[I_MILIT] = military; + putvec(VT_ITEM, vec, (s_char *)&from, EF_SECTOR); + putsect(&from); + } + } + if (changed) + writemap(player->cnum); + player->btused += btucost; + free((s_char *)table); + return RET_OK; } @@ -223,23 +222,11 @@ pr(" sect de own own eff eff eff eff civ mil shl gun pet food bars lnd p static void spyline(struct sctstr *sp) { - int vec[I_MAX+1]; + int vec[I_MAX + 1]; - getvec(VT_ITEM, vec, (s_char *) sp, EF_SECTOR); - prxy("%4d,%-4d",sp->sct_x, sp->sct_y, player->cnum); - pr(" %c%c %3d %3d %3d %3d %3d %3d %4d %4d %4d %3d %4d %4d %4d %3d %3d\n", - dchr[sp->sct_type].d_mnem, - (sp->sct_newtype == sp->sct_type)?' ':dchr[sp->sct_newtype].d_mnem, - sp->sct_own, - sp->sct_oldown, - roundintby((int)sp->sct_effic, 10), - roundintby((int)sp->sct_road, 10), - roundintby((int)sp->sct_rail, 10), - roundintby((int)sp->sct_defense, 10), - roundintby(vec[I_CIVIL], 10), roundintby(vec[I_MILIT], 10), - roundintby(vec[I_SHELL], 10), roundintby(vec[I_GUN], 10), - roundintby(vec[I_PETROL], 10), roundintby(vec[I_FOOD], 10), - roundintby(vec[I_BAR], 10), count_sect_units(sp), count_sect_planes(sp)); + getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum); + pr(" %c%c %3d %3d %3d %3d %3d %3d %4d %4d %4d %3d %4d %4d %4d %3d %3d\n", dchr[sp->sct_type].d_mnem, (sp->sct_newtype == sp->sct_type) ? ' ' : dchr[sp->sct_newtype].d_mnem, sp->sct_own, sp->sct_oldown, roundintby((int)sp->sct_effic, 10), roundintby((int)sp->sct_road, 10), roundintby((int)sp->sct_rail, 10), roundintby((int)sp->sct_defense, 10), roundintby(vec[I_CIVIL], 10), roundintby(vec[I_MILIT], 10), roundintby(vec[I_SHELL], 10), roundintby(vec[I_GUN], 10), roundintby(vec[I_PETROL], 10), roundintby(vec[I_FOOD], 10), roundintby(vec[I_BAR], 10), count_sect_units(sp), count_sect_planes(sp)); } @@ -249,32 +236,33 @@ spyline(struct sctstr *sp) static void insert(coord *table, int *len, coord x, coord y) { - if (!check(table, len, x, y)) { - table[(*len)++] = x; - table[(*len)++] = y; - } + if (!check(table, len, x, y)) { + table[(*len)++] = x; + table[(*len)++] = y; + } } + /* * see if a key is in the bitmask table */ static int check(coord *table, int *len, coord x, coord y) { - int i; + int i; - for (i = 0; i < *len; i += 2) - if (table[i] == x && table[i + 1] == y) - return 1; - return 0; + for (i = 0; i < *len; i += 2) + if (table[i] == x && table[i + 1] == y) + return 1; + return 0; } int num_units(int x, int y) { - struct lndstr land; - struct nstr_item ni; - int n=0; - + struct lndstr land; + struct nstr_item ni; + int n = 0; + snxtitem_xy(&ni, EF_LAND, x, y); while (nxtitem(&ni, (s_char *)&land)) { if ((land.lnd_own == player->cnum) || (land.lnd_own == 0)) @@ -283,7 +271,7 @@ num_units(int x, int y) continue; n++; } - + return n; } @@ -292,36 +280,36 @@ prunits(int x, int y) { struct lndstr land; struct nstr_item ni; - s_char report[128]; + s_char report[128]; double odds; snxtitem_xy(&ni, EF_LAND, x, y); while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own == player->cnum || land.lnd_own == 0) - continue; - if (land.lnd_ship >= 0 || land.lnd_land >= 0) - continue; - /* Don't always see spies */ - if (lchr[(int)land.lnd_type].l_flags & L_SPY) { - odds = (double)(100 - land.lnd_effic) + 0.10; - if (!(chance(odds))) - continue; - } - if ((land.lnd_own != player->cnum) && land.lnd_own) { - int rel; - s_char *format; + if (land.lnd_own == player->cnum || land.lnd_own == 0) + continue; + if (land.lnd_ship >= 0 || land.lnd_land >= 0) + continue; + /* Don't always see spies */ + if (lchr[(int)land.lnd_type].l_flags & L_SPY) { + odds = (double)(100 - land.lnd_effic) + 0.10; + if (!(chance(odds))) + continue; + } + if ((land.lnd_own != player->cnum) && land.lnd_own) { + int rel; + s_char *format; - rel = getrel(getnatp(player->cnum),land.lnd_own); - if (rel == ALLIED) - format = "Allied (%s) unit in %s: "; - else if (rel == FRIENDLY || rel == NEUTRAL) - format = "Neutral (%s) unit in %s: "; - else - format = "Enemy (%s) unit in %s: "; - sprintf(report, format, cname(land.lnd_own), - xyas(land.lnd_x, land.lnd_y,player->cnum)); - intelligence_report(player->cnum, &land, 3, report); - } + rel = getrel(getnatp(player->cnum), land.lnd_own); + if (rel == ALLIED) + format = "Allied (%s) unit in %s: "; + else if (rel == FRIENDLY || rel == NEUTRAL) + format = "Neutral (%s) unit in %s: "; + else + format = "Enemy (%s) unit in %s: "; + sprintf(report, format, cname(land.lnd_own), + xyas(land.lnd_x, land.lnd_y, player->cnum)); + intelligence_report(player->cnum, &land, 3, report); + } } } @@ -330,32 +318,31 @@ prplanes(int x, int y) { struct plnstr plane; struct nstr_item ni; - s_char report[128]; + s_char report[128]; snxtitem_xy(&ni, EF_PLANE, x, y); while (nxtitem(&ni, (s_char *)&plane)) { - if (plane.pln_own == player->cnum || plane.pln_own == 0) - continue; - if (plane.pln_ship >= 0 || plane.pln_land >= 0) - continue; + if (plane.pln_own == player->cnum || plane.pln_own == 0) + continue; + if (plane.pln_ship >= 0 || plane.pln_land >= 0) + continue; if (plane.pln_flags & PLN_LAUNCHED) continue; - if ((plane.pln_own != player->cnum) && plane.pln_own) { - int rel; - s_char *format; + if ((plane.pln_own != player->cnum) && plane.pln_own) { + int rel; + s_char *format; - rel = getrel(getnatp(player->cnum),plane.pln_own); - if (rel == ALLIED) - format = "Allied (%s) plane in %s: %s\n"; - else if (rel == FRIENDLY || rel == NEUTRAL) - format = "Neutral (%s) plane in %s: %s\n"; - else - format = "Enemy (%s) plane in %s: %s\n"; - sprintf(report, format, cname(plane.pln_own), - xyas(plane.pln_x, plane.pln_y,player->cnum), + rel = getrel(getnatp(player->cnum), plane.pln_own); + if (rel == ALLIED) + format = "Allied (%s) plane in %s: %s\n"; + else if (rel == FRIENDLY || rel == NEUTRAL) + format = "Neutral (%s) plane in %s: %s\n"; + else + format = "Enemy (%s) plane in %s: %s\n"; + sprintf(report, format, cname(plane.pln_own), + xyas(plane.pln_x, plane.pln_y, player->cnum), prplane(&plane)); pr(report); - } + } } } - diff --git a/src/lib/commands/sstat.c b/src/lib/commands/sstat.c index e3949ca1f..85458ea9a 100644 --- a/src/lib/commands/sstat.c +++ b/src/lib/commands/sstat.c @@ -47,52 +47,44 @@ int sstat(void) { - int nships; - struct nstr_item ni; - struct shpstr ship; + int nships; + struct nstr_item ni; + struct shpstr ship; - if (!snxtitem(&ni, EF_SHIP, player->argp[1])) - return RET_SYN; + if (!snxtitem(&ni, EF_SHIP, player->argp[1])) + return RET_SYN; - nships = 0; - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner || ship.shp_own == 0) - continue; - if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { - pr("bad ship type %d (#%d)\n", - ship.shp_type, ni.cur); - continue; - } - count_planes(&ship); - count_units(&ship); + nships = 0; + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner || ship.shp_own == 0) + continue; + if (ship.shp_type < 0 || ship.shp_type > shp_maxno) { + pr("bad ship type %d (#%d)\n", ship.shp_type, ni.cur); + continue; + } + count_planes(&ship); + count_units(&ship); - if (nships++ == 0) { -pr("shp# %22.22s x,y eff tech def spd vis rng fir\n", "ship-type"); - } - pr("%4d %-22.22s ", - ship.shp_uid, - mchr[(int)ship.shp_type].m_name); - prxy("%4d,%-4d", - ship.shp_x, - ship.shp_y, - player->cnum); - pr(" %3d%% %4d %3d %3d %3d %3d %3d", - ship.shp_effic, - ship.shp_tech, - ship.shp_armor, - ship.shp_speed, - ship.shp_visib, - ship.shp_frnge, - ship.shp_glim); - pr("\n"); + if (nships++ == 0) { + pr("shp# %22.22s x,y eff tech def spd vis rng fir\n", + "ship-type"); } - if (nships == 0) { - if (player->argp[1]) - pr("%s: No ship(s)\n", player->argp[1]); - else - pr("%s: No ship(s)\n", ""); - return RET_FAIL; - }else - pr("%d ship%s\n", nships, splur(nships)); - return RET_OK; + pr("%4d %-22.22s ", ship.shp_uid, mchr[(int)ship.shp_type].m_name); + prxy("%4d,%-4d", ship.shp_x, ship.shp_y, player->cnum); + pr(" %3d%% %4d %3d %3d %3d %3d %3d", + ship.shp_effic, + ship.shp_tech, + ship.shp_armor, + ship.shp_speed, ship.shp_visib, ship.shp_frnge, ship.shp_glim); + pr("\n"); + } + if (nships == 0) { + if (player->argp[1]) + pr("%s: No ship(s)\n", player->argp[1]); + else + pr("%s: No ship(s)\n", ""); + return RET_FAIL; + } else + pr("%d ship%s\n", nships, splur(nships)); + return RET_OK; } diff --git a/src/lib/commands/star.c b/src/lib/commands/star.c index 21f464892..d9601f249 100644 --- a/src/lib/commands/star.c +++ b/src/lib/commands/star.c @@ -50,53 +50,53 @@ static void start_hdr(void); int start(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) - start_hdr(); - if (player->god) - pr("%3d ", sect.sct_own); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sect.sct_effic); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) + start_hdr(); + if (player->god) + pr("%3d ", sect.sct_own); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sect.sct_effic); - pr(" will be updated normally.\n"); - if (sect.sct_off != 0) { - sect.sct_off = 0; - putsect(§); - } + pr(" will be updated normally.\n"); + if (sect.sct_off != 0) { + sect.sct_off = 0; + putsect(§); } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } static void start_hdr(void) { - if (player->god) - pr(" "); - pr("PRODUCTION STARTING\n"); - if (player->god) - pr("own "); - pr(" sect eff\n"); + if (player->god) + pr(" "); + pr("PRODUCTION STARTING\n"); + if (player->god) + pr("own "); + pr(" sect eff\n"); } diff --git a/src/lib/commands/stop.c b/src/lib/commands/stop.c index 4e47322f3..a16382ed0 100644 --- a/src/lib/commands/stop.c +++ b/src/lib/commands/stop.c @@ -50,53 +50,53 @@ static void stop_hdr(void); int stop(void) { - struct sctstr sect; - int nsect; - struct nstr_sect nstr; + struct sctstr sect; + int nsect; + struct nstr_sect nstr; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - nsect = 0; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) - stop_hdr(); - if (player->god) - pr("%3d ", sect.sct_own); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sect.sct_effic); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + nsect = 0; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) + stop_hdr(); + if (player->god) + pr("%3d ", sect.sct_own); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sect.sct_effic); - pr(" will not produce or gain efficiency.\n"); - if (sect.sct_off != 1) { - sect.sct_off = 1; - putsect(§); - } + pr(" will not produce or gain efficiency.\n"); + if (sect.sct_off != 1) { + sect.sct_off = 1; + putsect(§); } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - }else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } static void stop_hdr(void) { - if (player->god) - pr(" "); - pr("PRODUCTION STOPPAGE\n"); - if (player->god) - pr("own "); - pr(" sect eff\n"); + if (player->god) + pr(" "); + pr("PRODUCTION STOPPAGE\n"); + if (player->god) + pr("own "); + pr(" sect eff\n"); } diff --git a/src/lib/commands/stre.c b/src/lib/commands/stre.c index cf890157b..974cdf502 100644 --- a/src/lib/commands/stre.c +++ b/src/lib/commands/stre.c @@ -55,107 +55,106 @@ static void stre_hdr(void); int stre(void) { - struct sctstr sect; - int nsect = 0; - struct nstr_sect nstr; - double dtotal, r_total, eff; - struct combat def[1]; - int dummy; - int mines; + struct sctstr sect; + int nsect = 0; + struct nstr_sect nstr; + double dtotal, r_total, eff; + struct combat def[1]; + int dummy; + int mines; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - prdate(); - nsect = 0; - att_combat_init(def, EF_SECTOR); - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (nsect++ == 0) - stre_hdr(); - if (player->god) - pr("%3d ", sect.sct_own); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - pr("%4d%%", sect.sct_effic); - def->x = nstr.x; - def->y = nstr.y; - def->set = 0; - att_get_combat(def, 1); - if (def->mil) - pr("%5d", def->mil); - else - pr("%5s", ""); - dtotal = units_in_sector(def); - if (dtotal > 0) - pr("%7d", (int)dtotal); - else - pr("%7s", ""); + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + prdate(); + nsect = 0; + att_combat_init(def, EF_SECTOR); + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (nsect++ == 0) + stre_hdr(); + if (player->god) + pr("%3d ", sect.sct_own); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + pr("%4d%%", sect.sct_effic); + def->x = nstr.x; + def->y = nstr.y; + def->set = 0; + att_get_combat(def, 1); + if (def->mil) + pr("%5d", def->mil); + else + pr("%5s", ""); + dtotal = units_in_sector(def); + if (dtotal > 0) + pr("%7d", (int)dtotal); + else + pr("%7s", ""); - r_total = att_reacting_units(def, 0, 0, &dummy, 9999999); - def->own = 0; - eff = att_combat_eff(def); - if (sect.sct_own == sect.sct_oldown) { - mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); - if (mines > 0) - pr("%7d", mines); - else - pr("%7s", ""); - eff *= (1.0 + min(mines,20) * 0.02); - } else { - pr("%7s", "?"); - } - pr("%6.2f", eff); - pr("%9d", (int)((dtotal + def->mil) * eff)); - if (r_total > 0) - pr(" %9d", (int)(r_total * eff)); - else - pr(" %9s", ""); - pr("%9d\n", (int)((dtotal + def->mil + r_total) * eff)); + r_total = att_reacting_units(def, 0, 0, &dummy, 9999999); + def->own = 0; + eff = att_combat_eff(def); + if (sect.sct_own == sect.sct_oldown) { + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + if (mines > 0) + pr("%7d", mines); + else + pr("%7s", ""); + eff *= (1.0 + min(mines, 20) * 0.02); + } else { + pr("%7s", "?"); } - if (!nsect) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return RET_FAIL; - } else - pr("%d sector%s\n", nsect, splur(nsect)); - return 0; + pr("%6.2f", eff); + pr("%9d", (int)((dtotal + def->mil) * eff)); + if (r_total > 0) + pr(" %9d", (int)(r_total * eff)); + else + pr(" %9s", ""); + pr("%9d\n", (int)((dtotal + def->mil + r_total) * eff)); + } + if (!nsect) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); + return RET_FAIL; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return 0; } static double units_in_sector(struct combat *def) { - double d_unit; - double dtotal = 0.0; - struct nstr_item ni; - struct lndstr land; + double d_unit; + double dtotal = 0.0; + struct nstr_item ni; + struct lndstr land; - snxtitem_xy(&ni,EF_LAND,def->x, def->y); - while(nxtitem(&ni,(s_char *)&land)){ - if (land.lnd_own == 0) - continue; - if (land.lnd_own != def->own) - continue; - if (land.lnd_ship >= 0) - continue; - d_unit = defense_val(&land); - if (!has_supply(&land)) - d_unit /= 2.0; - dtotal += d_unit; - } - return dtotal; + snxtitem_xy(&ni, EF_LAND, def->x, def->y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_own != def->own) + continue; + if (land.lnd_ship >= 0) + continue; + d_unit = defense_val(&land); + if (!has_supply(&land)) + d_unit /= 2.0; + dtotal += d_unit; + } + return dtotal; } static void stre_hdr(void) { - if (player->god) - pr(" "); - pr("DEFENSE STRENGTH land sect sector reacting total\n"); - if (player->god) - pr("own "); - pr(" sect eff mil units mines mult defense units defense\n"); + if (player->god) + pr(" "); + pr("DEFENSE STRENGTH land sect sector reacting total\n"); + if (player->god) + pr("own "); + pr(" sect eff mil units mines mult defense units defense\n"); } - diff --git a/src/lib/commands/strv.c b/src/lib/commands/strv.c index 75e3b2df5..d473fdc8f 100644 --- a/src/lib/commands/strv.c +++ b/src/lib/commands/strv.c @@ -48,224 +48,214 @@ #include "land.h" #include "commands.h" -extern int etu_per_update; -static void starv_sects(s_char *range); -static void starv_ships(s_char *range); -static void starv_units(s_char *range); -static void sect_hdr(void); -static void ship_hdr(void); -static void unit_hdr(void); +extern int etu_per_update; +static void starv_sects(s_char *range); +static void starv_ships(s_char *range); +static void starv_units(s_char *range); +static void sect_hdr(void); +static void ship_hdr(void); +static void unit_hdr(void); int starve(void) { - struct nstr_sect nstr; - int do_sects = 0; - int do_ships = 0; - int do_units = 0; - s_char range[1024]; + struct nstr_sect nstr; + int do_sects = 0; + int do_ships = 0; + int do_units = 0; + s_char range[1024]; - if (opt_NOFOOD) { /* no food - no work! */ - pr("No food is required in this game\n"); - return RET_OK; - } - - strcpy(range, "*"); - if (!player->argp[1]) { - do_sects = do_ships = do_units = 1; - } else if (*(player->argp[1]) == 's') { - do_ships = 1; - if (player->argp[2]) - strcpy(range, player->argp[2]); - } else if (*(player->argp[1]) == 'l') { - do_units = 1; - if (player->argp[2]) - strcpy(range, player->argp[2]); - } else { - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - do_sects = 1; - strcpy(range, player->argp[1]); - } - player->simulation = 1; - prdate(); - if (do_sects) - starv_sects(range); - if (do_ships) - starv_ships(range); - if (do_units) - starv_units(range); - player->simulation = 0; + if (opt_NOFOOD) { /* no food - no work! */ + pr("No food is required in this game\n"); return RET_OK; + } + + strcpy(range, "*"); + if (!player->argp[1]) { + do_sects = do_ships = do_units = 1; + } else if (*(player->argp[1]) == 's') { + do_ships = 1; + if (player->argp[2]) + strcpy(range, player->argp[2]); + } else if (*(player->argp[1]) == 'l') { + do_units = 1; + if (player->argp[2]) + strcpy(range, player->argp[2]); + } else { + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + do_sects = 1; + strcpy(range, player->argp[1]); + } + player->simulation = 1; + prdate(); + if (do_sects) + starv_sects(range); + if (do_ships) + starv_ships(range); + if (do_units) + starv_units(range); + player->simulation = 0; + return RET_OK; } static void starv_sects(s_char *range) { - struct nstr_sect nstr; - struct sctstr sect; - int nsect = 0; - int vec[I_MAX+1], s, needed; + struct nstr_sect nstr; + struct sctstr sect; + int nsect = 0; + int vec[I_MAX + 1], s, needed; - if (!snxtsct(&nstr, range)) - return; - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - if (sect.sct_type == SCT_SANCT) - continue; + if (!snxtsct(&nstr, range)) + return; + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + if (sect.sct_type == SCT_SANCT) + continue; - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); /* This next 2 lines were added to overcompensate for the needy */ - if (vec[I_FOOD]) - vec[I_FOOD]--; - s = feed_people(vec, etu_per_update, &needed); + if (vec[I_FOOD]) + vec[I_FOOD]--; + s = feed_people(vec, etu_per_update, &needed); - if (s==0) - continue; - if (nsect++ == 0) - sect_hdr(); - if (player->god) - pr("%3d ", sect.sct_own); - prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); - pr(" %c", dchr[sect.sct_type].d_mnem); - pr(" %c", (sect.sct_own != sect.sct_oldown ? '*' : ' ')); - if (sect.sct_newtype != sect.sct_type) - pr("%c", dchr[sect.sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sect.sct_effic); - pr(" will starve %d people. %d more food needed\n",s, - needed); - } - if (nsect == 0) { - if (player->argp[1]) - pr("%s: No sector(s)\n", player->argp[1]); - else - pr("%s: No sector(s)\n", ""); - return; - }else - pr("%d sector%s\n", nsect, splur(nsect)); + if (s == 0) + continue; + if (nsect++ == 0) + sect_hdr(); + if (player->god) + pr("%3d ", sect.sct_own); + prxy("%4d,%-4d", nstr.x, nstr.y, player->cnum); + pr(" %c", dchr[sect.sct_type].d_mnem); + pr(" %c", (sect.sct_own != sect.sct_oldown ? '*' : ' ')); + if (sect.sct_newtype != sect.sct_type) + pr("%c", dchr[sect.sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sect.sct_effic); + pr(" will starve %d people. %d more food needed\n", s, needed); + } + if (nsect == 0) { + if (player->argp[1]) + pr("%s: No sector(s)\n", player->argp[1]); + else + pr("%s: No sector(s)\n", ""); return; + } else + pr("%d sector%s\n", nsect, splur(nsect)); + return; } static void sect_hdr(void) { - if (player->god) - pr(" "); - pr("Starvation \n"); - if (player->god) - pr("own "); - pr(" sect eff "); - pr("\n"); + if (player->god) + pr(" "); + pr("Starvation \n"); + if (player->god) + pr("own "); + pr(" sect eff "); + pr("\n"); } static void starv_ships(s_char *range) { - struct nstr_item ni; - struct shpstr ship; - int nship = 0; - int vec[I_MAX+1], s, needed; + struct nstr_item ni; + struct shpstr ship; + int nship = 0; + int vec[I_MAX + 1], s, needed; - if (!snxtitem(&ni, EF_SHIP, range)) - return; + if (!snxtitem(&ni, EF_SHIP, range)) + return; - while (nxtitem(&ni, (s_char *)&ship)) { - if (!player->owner || !ship.shp_own) - continue; + while (nxtitem(&ni, (s_char *)&ship)) { + if (!player->owner || !ship.shp_own) + continue; - getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - s = feed_ship(&ship, vec, etu_per_update, &needed, 0); + getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); + s = feed_ship(&ship, vec, etu_per_update, &needed, 0); - if (s==0) - continue; - if (nship++ == 0) - ship_hdr(); - if (player->god) - pr("%3d ", ship.shp_own); - pr("%5d ", ship.shp_uid); - pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); - pr(" will starve %d people. %d more food needed\n",s, - needed); - } - if (nship == 0) { - if (range) - pr("%s: No ship(s)\n", range); - else - pr("%s: No ship(s)\n", ""); - return; - }else - pr("%d ship%s\n", nship, splur(nship)); + if (s == 0) + continue; + if (nship++ == 0) + ship_hdr(); + if (player->god) + pr("%3d ", ship.shp_own); + pr("%5d ", ship.shp_uid); + pr("%-16.16s ", mchr[(int)ship.shp_type].m_name); + pr(" will starve %d people. %d more food needed\n", s, needed); + } + if (nship == 0) { + if (range) + pr("%s: No ship(s)\n", range); + else + pr("%s: No ship(s)\n", ""); return; + } else + pr("%d ship%s\n", nship, splur(nship)); + return; } static void ship_hdr(void) { - if (player->god) - pr(" "); - pr("Starvation \n"); - if (player->god) - pr("own "); - pr(" shp# ship type \n"); + if (player->god) + pr(" "); + pr("Starvation \n"); + if (player->god) + pr("own "); + pr(" shp# ship type \n"); } static void starv_units(s_char *range) { - struct nstr_item ni; - struct lndstr land; - int nunit = 0; - int vec[I_MAX+1], s, needed; + struct nstr_item ni; + struct lndstr land; + int nunit = 0; + int vec[I_MAX + 1], s, needed; - if (!snxtitem(&ni, EF_LAND, range)) - return; + if (!snxtitem(&ni, EF_LAND, range)) + return; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner || !land.lnd_own) - continue; + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner || !land.lnd_own) + continue; - getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - s = feed_land(&land, vec, etu_per_update, &needed, 0); + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); + s = feed_land(&land, vec, etu_per_update, &needed, 0); - if (s==0) - continue; - if (nunit++ == 0) - unit_hdr(); - if (player->god) - pr("%3d ", land.lnd_own); - pr("%5d ", land.lnd_uid); - pr("%-16.16s ", lchr[(int)land.lnd_type].l_name); - pr(" will starve %d mil. %d more food needed\n",s, - needed); - } - if (nunit == 0) { - if (range) - pr("%s: No unit(s)\n", range); - else - pr("%s: No unit(s)\n", ""); - return; - }else - pr("%d unit%s\n", nunit, splur(nunit)); + if (s == 0) + continue; + if (nunit++ == 0) + unit_hdr(); + if (player->god) + pr("%3d ", land.lnd_own); + pr("%5d ", land.lnd_uid); + pr("%-16.16s ", lchr[(int)land.lnd_type].l_name); + pr(" will starve %d mil. %d more food needed\n", s, needed); + } + if (nunit == 0) { + if (range) + pr("%s: No unit(s)\n", range); + else + pr("%s: No unit(s)\n", ""); return; + } else + pr("%d unit%s\n", nunit, splur(nunit)); + return; } static void unit_hdr(void) { - if (player->god) - pr(" "); - pr("Starvation \n"); - if (player->god) - pr("own "); - pr(" lnd# unit type \n"); + if (player->god) + pr(" "); + pr("Starvation \n"); + if (player->god) + pr("own "); + pr(" lnd# unit type \n"); } - - - - - - - diff --git a/src/lib/commands/supp.c b/src/lib/commands/supp.c index a432f1baa..5974d123d 100644 --- a/src/lib/commands/supp.c +++ b/src/lib/commands/supp.c @@ -46,32 +46,32 @@ int supp(void) { - int nunits; - struct nstr_item ni; - struct lndstr land; + int nunits; + struct nstr_item ni; + struct lndstr land; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; - nunits = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner || land.lnd_own == 0) - continue; - nunits++; - resupply_all(&land); - putland(land.lnd_uid,&land); - if (has_supply(&land)) - pr("%s has supplies\n", prland(&land)); - else - pr("%s is out of supply\n", prland(&land)); - } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + nunits = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + nunits++; + resupply_all(&land); + putland(land.lnd_uid, &land); + if (has_supply(&land)) + pr("%s has supplies\n", prland(&land)); + else + pr("%s is out of supply\n", prland(&land)); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } diff --git a/src/lib/commands/surv.c b/src/lib/commands/surv.c index 04472c818..a6302deec 100644 --- a/src/lib/commands/surv.c +++ b/src/lib/commands/surv.c @@ -44,7 +44,7 @@ #include "commands.h" #include "optlist.h" -static s_char code_char(long int coding, struct sctstr *sp); +static s_char code_char(long int coding, struct sctstr *sp); /* * survey type ?cond @@ -53,114 +53,115 @@ static s_char code_char(long int coding, struct sctstr *sp); int surv(void) { - int nsect; - struct nstr_sect nstr; - int y; - long coding; - struct natstr *np; - struct sctstr sect; - struct range range; - s_char *ptr; - struct nscstr cond[NS_NCOND]; - int ncond; - int i; - s_char what[64]; - s_char buf[1024]; - s_char *str; - /* Note this is not re-entrant anyway, so we keep the buffers - around */ - static s_char *mapbuf = (s_char *)0; - static s_char **map = (s_char **)0; + int nsect; + struct nstr_sect nstr; + int y; + long coding; + struct natstr *np; + struct sctstr sect; + struct range range; + s_char *ptr; + struct nscstr cond[NS_NCOND]; + int ncond; + int i; + s_char what[64]; + s_char buf[1024]; + s_char *str; + /* Note this is not re-entrant anyway, so we keep the buffers + around */ + static s_char *mapbuf = (s_char *)0; + static s_char **map = (s_char **)0; - nsect = 0; - if ((ptr = getstarg(player->argp[1], "commodity or variable? ", buf)) == 0) - return RET_SYN; - if (encode(ptr, &coding, EF_SECTOR) < 0) - return RET_SYN; - if(player->argp[2] == (s_char *) 0) { - if ((str = getstring("(sects)? ", buf)) == 0) - return RET_SYN; - } else { - str = player->argp[2]; - } - if(*str == '*') { - sprintf(what, "%d:%d,%d:%d", - -WORLD_X/2, WORLD_X/2-1, - -WORLD_Y/2, WORLD_Y/2-1); - if (!snxtsct(&nstr, what)) - return RET_FAIL; - } - else - if (!snxtsct(&nstr, str)) - return RET_SYN; - if (!mapbuf) - mapbuf = (s_char *)malloc((WORLD_Y*MAPWIDTH(1))*sizeof(s_char)); - if (!map) { - map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (map && mapbuf) { - for (i = 0; i < WORLD_Y; i++) - map[i] = &mapbuf[MAPWIDTH(1) * i]; - } else if (map) { - free((s_char *)map); - map = (s_char **)0; - } - } - if (!mapbuf || !map) { - pr("Memory error, tell the deity.\n"); - logerror("malloc failed in sect\n"); + nsect = 0; + if ((ptr = + getstarg(player->argp[1], "commodity or variable? ", buf)) == 0) + return RET_SYN; + if (encode(ptr, &coding, EF_SECTOR) < 0) + return RET_SYN; + if (player->argp[2] == (s_char *)0) { + if ((str = getstring("(sects)? ", buf)) == 0) + return RET_SYN; + } else { + str = player->argp[2]; + } + if (*str == '*') { + sprintf(what, "%d:%d,%d:%d", + -WORLD_X / 2, WORLD_X / 2 - 1, + -WORLD_Y / 2, WORLD_Y / 2 - 1); + if (!snxtsct(&nstr, what)) return RET_FAIL; + } else if (!snxtsct(&nstr, str)) + return RET_SYN; + if (!mapbuf) + mapbuf = + (s_char *)malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char)); + if (!map) { + map = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (map && mapbuf) { + for (i = 0; i < WORLD_Y; i++) + map[i] = &mapbuf[MAPWIDTH(1) * i]; + } else if (map) { + free((s_char *)map); + map = (s_char **)0; } - ncond = nstr.ncond; - bcopy((s_char *)nstr.cond, (s_char *)cond, sizeof(struct nscstr) * ncond); - nstr.ncond = 0; - np = getnatp(player->cnum); - xyrelrange(np, &nstr.range, &range); - border(&range, " ", ""); - blankfill((s_char *)mapbuf, &nstr.range, 1); - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - ptr = &map[nstr.dy][nstr.dx]; - if (nstr_exec(cond, ncond, (s_char *)§, EF_SECTOR)) { - ++nsect; - *ptr = 0x80 | code_char(coding, §); - } else { - *ptr = dchr[sect.sct_type].d_mnem; - } + } + if (!mapbuf || !map) { + pr("Memory error, tell the deity.\n"); + logerror("malloc failed in sect\n"); + return RET_FAIL; + } + ncond = nstr.ncond; + bcopy((s_char *)nstr.cond, (s_char *)cond, + sizeof(struct nscstr) * ncond); + nstr.ncond = 0; + np = getnatp(player->cnum); + xyrelrange(np, &nstr.range, &range); + border(&range, " ", ""); + blankfill((s_char *)mapbuf, &nstr.range, 1); + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + ptr = &map[nstr.dy][nstr.dx]; + if (nstr_exec(cond, ncond, (s_char *)§, EF_SECTOR)) { + ++nsect; + *ptr = 0x80 | code_char(coding, §); + } else { + *ptr = dchr[sect.sct_type].d_mnem; } - for (y=nstr.range.ly, i=0; i < nstr.range.height; y++, i++) { - int yval; + } + for (y = nstr.range.ly, i = 0; i < nstr.range.height; y++, i++) { + int yval; - yval = yrel(np, y); - pr("%4d %s %4d\n", yval, map[i], yval); - if (y >= WORLD_Y) - y -= WORLD_Y; - } - border(&range, " ", ""); - if (nsect > 0) - pr("\n%d sector%s.\n", nsect, splur(nsect)); - return RET_OK; + yval = yrel(np, y); + pr("%4d %s %4d\n", yval, map[i], yval); + if (y >= WORLD_Y) + y -= WORLD_Y; + } + border(&range, " ", ""); + if (nsect > 0) + pr("\n%d sector%s.\n", nsect, splur(nsect)); + return RET_OK; } static -s_char + s_char code_char(long int coding, struct sctstr *sp) { - int amt; - int n; + int amt; + int n; - if (!(coding & NSC_VAR)) - coding |= NSC_OFF; - amt = decode(player->cnum, coding, (s_char *) sp, EF_SECTOR); + if (!(coding & NSC_VAR)) + coding |= NSC_OFF; + amt = decode(player->cnum, coding, (s_char *)sp, EF_SECTOR); + n = 0; + if ((coding & NSC_CMASK) == NSC_VAR) { + if (amt != 0) + n = (amt / 100) + 1; + } else if (amt != 0) + n = (amt / 10) + 1; + if (n > 11) + n = 11; + if (n < 0) n = 0; - if ((coding & NSC_CMASK) == NSC_VAR) { - if (amt != 0) - n = (amt / 100) + 1; - } else if (amt != 0) - n = (amt / 10) + 1; - if (n > 11) - n = 11; - if (n < 0) - n = 0; - return " 0123456789$"[n]; + return " 0123456789$"[n]; } diff --git a/src/lib/commands/swap.c b/src/lib/commands/swap.c index 7aab1ee9b..85953e553 100644 --- a/src/lib/commands/swap.c +++ b/src/lib/commands/swap.c @@ -52,60 +52,61 @@ int swaps(void) { - struct sctstr secta, sectb; - coord x,y; - s_char buf[1024]; - s_char *p; + struct sctstr secta, sectb; + coord x, y; + s_char buf[1024]; + s_char *p; - if (!(p = getstarg(player->argp[1], "First sector : ", buf)) || - !sarg_xy(p, §a.sct_x, §a.sct_y) || - !getsect(secta.sct_x, secta.sct_y, §a)) - return RET_SYN; - print_res(§a); - if (!(p = getstarg(player->argp[2], "Second sector : ", buf)) || - !sarg_xy(p, §b.sct_x, §b.sct_y) || - !getsect(sectb.sct_x, sectb.sct_y, §b)) - return RET_SYN; - print_res(§b); - if (!confirm("Are you sure these are the two sectors you wish to swap? ")) - return RET_FAIL; - /* save x and y from secta */ - x = secta.sct_x; - y = secta.sct_y; - /* change the location of secta to that of sectb */ - secta.sct_x = sectb.sct_x; - secta.sct_y = sectb.sct_y; - secta.sct_dist_x = sectb.sct_x; - secta.sct_dist_y = sectb.sct_y; - /* change the location of sectb to where secta was */ - sectb.sct_x = x; - sectb.sct_y = y; - sectb.sct_dist_x = x; - sectb.sct_dist_y = y; - putsect(§a); - putsect(§b); - pr("done\n"); - return RET_OK; + if (!(p = getstarg(player->argp[1], "First sector : ", buf)) || + !sarg_xy(p, §a.sct_x, §a.sct_y) || + !getsect(secta.sct_x, secta.sct_y, §a)) + return RET_SYN; + print_res(§a); + if (!(p = getstarg(player->argp[2], "Second sector : ", buf)) || + !sarg_xy(p, §b.sct_x, §b.sct_y) || + !getsect(sectb.sct_x, sectb.sct_y, §b)) + return RET_SYN; + print_res(§b); + if (!confirm + ("Are you sure these are the two sectors you wish to swap? ")) + return RET_FAIL; + /* save x and y from secta */ + x = secta.sct_x; + y = secta.sct_y; + /* change the location of secta to that of sectb */ + secta.sct_x = sectb.sct_x; + secta.sct_y = sectb.sct_y; + secta.sct_dist_x = sectb.sct_x; + secta.sct_dist_y = sectb.sct_y; + /* change the location of sectb to where secta was */ + sectb.sct_x = x; + sectb.sct_y = y; + sectb.sct_dist_x = x; + sectb.sct_dist_y = y; + putsect(§a); + putsect(§b); + pr("done\n"); + return RET_OK; } void print_res(struct sctstr *sp) { - pr("own sect eff min gold fert oil uran\n"); + pr("own sect eff min gold fert oil uran\n"); - pr("%3d ", sp->sct_own); + pr("%3d ", sp->sct_own); - prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum); - pr(" %c", dchr[sp->sct_type].d_mnem); - if (sp->sct_newtype != sp->sct_type) - pr("%c", dchr[sp->sct_newtype].d_mnem); - else - pr(" "); - pr("%4d%%", sp->sct_effic); - pr(" %4d", sp->sct_min); - pr("%5d", sp->sct_gmin); - pr("%5d", sp->sct_fertil); - pr("%4d", sp->sct_oil); - pr("%5d", sp->sct_uran); - pr("\n"); + prxy("%4d,%-4d", sp->sct_x, sp->sct_y, player->cnum); + pr(" %c", dchr[sp->sct_type].d_mnem); + if (sp->sct_newtype != sp->sct_type) + pr("%c", dchr[sp->sct_newtype].d_mnem); + else + pr(" "); + pr("%4d%%", sp->sct_effic); + pr(" %4d", sp->sct_min); + pr("%5d", sp->sct_gmin); + pr("%5d", sp->sct_fertil); + pr("%4d", sp->sct_oil); + pr("%5d", sp->sct_uran); + pr("\n"); } diff --git a/src/lib/commands/tele.c b/src/lib/commands/tele.c index 669e2b4a0..d61d03c60 100644 --- a/src/lib/commands/tele.c +++ b/src/lib/commands/tele.c @@ -45,91 +45,89 @@ int tele(void) { - natid to; - struct natstr *natp; - int teltype; - s_char buf[MAXTELSIZE+1]; - int n; + natid to; + struct natstr *natp; + int teltype; + s_char buf[MAXTELSIZE + 1]; + int n; - natp = getnatp(player->cnum); - if (*player->argp[0] == 'a') { - if (getele("everybody", buf) <= 0) { - pr("Announcement aborted\n"); + natp = getnatp(player->cnum); + if (*player->argp[0] == 'a') { + if (getele("everybody", buf) <= 0) { + pr("Announcement aborted\n"); + return RET_OK; + } + pr("\n"); + to = 0; + if (typed_wu(player->cnum, to, buf, TEL_ANNOUNCE) < 0) + logerror("tele: typed_wu failed to #%d", to); + } else if (*player->argp[0] == 'p') { + if (getele("your Gracious Deity", buf) <= 0) { + pr("Prayor aborted\n"); + return RET_OK; + } + pr("\n"); + if (typed_wu(player->cnum, 0, buf, TEL_NORM) < 0) + logerror("tele: typed_wu failed to #0"); + } else { + int kk; + + kk = 1; + while (player->argp[kk] != (s_char *)0) { + if ((n = natarg(player->argp[kk], "for which country? ")) < 0) { + if (opt_HIDDEN) { + if (n < -1) { return RET_OK; + } else { + return RET_SYN; + } + } else { + return RET_SYN; } - pr("\n"); - to = 0; - if (typed_wu(player->cnum, to, buf, TEL_ANNOUNCE) < 0) - logerror("tele: typed_wu failed to #%d", to); - } else if (*player->argp[0] == 'p') { - if (getele("your Gracious Deity", buf) <= 0) { - pr("Prayor aborted\n"); + } + to = n; + + if (kk == 1) { + if (player->argp[2]) { + if (getele("multiple recipients", buf) < 0) { + pr("Telegram aborted\n"); return RET_OK; + } + } else { + if (getele(cname(to), buf) < 0) { + pr("Telegram aborted\n"); + return RET_OK; + } } pr("\n"); - if (typed_wu(player->cnum, 0, buf, TEL_NORM) < 0) - logerror("tele: typed_wu failed to #0"); - } else { - int kk; - - kk = 1; - while (player->argp[kk] != (s_char *)0){ - if ((n = natarg(player->argp[kk], "for which country? ")) < 0) { - if (opt_HIDDEN) { - if (n < -1) { - return RET_OK; - } else { - return RET_SYN; - } - } else { - return RET_SYN; - } - } - to = n; + } - if (kk == 1){ - if (player->argp[2]){ - if(getele("multiple recipients",buf)<0){ - pr("Telegram aborted\n"); - return RET_OK; - } - }else{ - if (getele(cname(to), buf) < 0) { - pr("Telegram aborted\n"); - return RET_OK; - } - } - pr("\n"); - } + natp = getnatp(to); + if (((natp->nat_stat & STAT_NORM) == 0) && + ((natp->nat_stat & STAT_SANCT) == 0)) { + pr("%s has no \"telegram priveleges\".\n", cname(to)); + kk++; + continue; + } + if (!player->god + && (getrejects(player->cnum, natp) & REJ_TELE)) { + pr("%s is rejecting your telegrams.\n", cname(to)); + return RET_SYN; + } + teltype = /* player->god ? TEL_BULLETIN : */ TEL_NORM; + if (typed_wu(player->cnum, to, buf, teltype) < 0) { + logerror("tele: typed_wu failed to #%d", n); + return RET_FAIL; + } - natp = getnatp(to); - if (((natp->nat_stat & STAT_NORM) == 0) && - ((natp->nat_stat & STAT_SANCT) == 0)){ - pr("%s has no \"telegram priveleges\".\n", - cname(to)); - kk++; - continue; - } - if (!player->god && (getrejects(player->cnum,natp) & REJ_TELE)) { - pr("%s is rejecting your telegrams.\n", - cname(to)); - return RET_SYN; - } - teltype = /* player->god ? TEL_BULLETIN : */ TEL_NORM; - if (typed_wu(player->cnum, to, buf, teltype) < 0) { - logerror("tele: typed_wu failed to #%d", n); - return RET_FAIL; - } - - if (!player->god && - (natp->nat_stat & GOD) != GOD && - player->cnum != to) - nreport(player->cnum, N_SENT_TEL, to, 1); - if (opt_HIDDEN) { - setcont(to, player->cnum, FOUND_TELE); - } - kk++; - } + if (!player->god && + (natp->nat_stat & GOD) != GOD && player->cnum != to) + nreport(player->cnum, N_SENT_TEL, to, 1); + if (opt_HIDDEN) { + setcont(to, player->cnum, FOUND_TELE); + } + kk++; } - return RET_OK; + } + return RET_OK; } diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index db5cad06d..88bd5cdd3 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -51,163 +51,159 @@ #include "genitem.h" #include "commands.h" -static void expose_ship(struct shpstr *s1, struct shpstr *s2); -static int tend_land(struct shpstr *tenderp, s_char *units); +static void expose_ship(struct shpstr *s1, struct shpstr *s2); +static int tend_land(struct shpstr *tenderp, s_char *units); int tend(void) { - struct nstr_item targets; - struct nstr_item tenders; - struct shpstr tender; - struct shpstr target; - struct ichrstr *ip; - struct mchrstr *vbase; - int amt; - int retval; - int ontender; - int ontarget; - int maxtender; - int maxtarget; - int transfer; - int total; - int type; - s_char *p; - s_char prompt[512]; - s_char buf[1024]; + struct nstr_item targets; + struct nstr_item tenders; + struct shpstr tender; + struct shpstr target; + struct ichrstr *ip; + struct mchrstr *vbase; + int amt; + int retval; + int ontender; + int ontarget; + int maxtender; + int maxtarget; + int transfer; + int total; + int type; + s_char *p; + s_char prompt[512]; + s_char buf[1024]; - if (!(p = getstarg(player->argp[1], - "Tend what commodity (or 'land')? ", buf)) || !*p) - return RET_SYN; - - if (!strncmp(p, "land", 4)) - type = EF_LAND; - else if (NULL != (ip = whatitem(p, (s_char *)0))) - type = EF_SECTOR; - else { - pr("Bad commodity.\n"); - return RET_SYN; - } + if (!(p = getstarg(player->argp[1], + "Tend what commodity (or 'land')? ", buf)) || !*p) + return RET_SYN; - if (!snxtitem(&tenders, EF_SHIP, getstarg(player->argp[2], "Tender(s)? ", buf))) - return RET_SYN; + if (!strncmp(p, "land", 4)) + type = EF_LAND; + else if (NULL != (ip = whatitem(p, (s_char *)0))) + type = EF_SECTOR; + else { + pr("Bad commodity.\n"); + return RET_SYN; + } - while (nxtitem(&tenders, (s_char *)&tender)) { - if (!player->owner) - continue; - if (type == EF_LAND) { - sprintf(prompt, "Land unit(s) to tend from %s? ", - prship(&tender)); - if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) - continue; - if (!check_ship_ok(&tender)) - return RET_SYN; - if (0 != (retval=tend_land(&tender, p))) - return retval; - continue; - } - sprintf(prompt, "Number of %s to tend from %s? ", - ip->i_name, prship(&tender)); - if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) - continue; - if (!check_ship_ok(&tender)) - return RET_SYN; - if (!(amt = atoi(p))) { - pr("Amount must be non-zero!\n"); - return RET_SYN; - } - ontender = getvar(ip->i_vtype, (s_char *)&tender, EF_SHIP); - if (ontender == 0 && amt > 0) { - pr("No %s on %s\n", ip->i_name, prship(&tender)); - return RET_FAIL; - } - vbase = &mchr[(int)tender.shp_type]; - maxtender = vl_find(ip->i_vtype, vbase->m_vtype, - vbase->m_vamt, (int)vbase->m_nv); - if (maxtender == 0) { - pr("A %s cannot hold any %s\n", - mchr[(int)tender.shp_type].m_name, - ip->i_name); - break; - } - if (!snxtitem(&targets, EF_SHIP, - getstarg(player->argp[4], "Ships to be tended? ", buf))) - break; - if (!check_ship_ok(&tender)) - return RET_SYN; - total = 0; - while (tend_nxtitem(&targets, (s_char *)&target)) { - if (!player->owner && - (getrel(getnatp(target.shp_own), - player->cnum) < FRIENDLY)) - continue; - if (target.shp_uid == tender.shp_uid) - continue; - if (tender.shp_x != target.shp_x || - tender.shp_y != target.shp_y) - continue; - ontarget = getvar(ip->i_vtype, - (s_char *)&target, EF_SHIP); - if (ontarget == 0 && amt < 0) { - pr("No %s on %s\n", - ip->i_name, prship(&target)); - continue; - } - vbase = &mchr[(int)target.shp_type]; - maxtarget = vl_find(ip->i_vtype, vbase->m_vtype, + if (!snxtitem + (&tenders, EF_SHIP, getstarg(player->argp[2], "Tender(s)? ", buf))) + return RET_SYN; + + while (nxtitem(&tenders, (s_char *)&tender)) { + if (!player->owner) + continue; + if (type == EF_LAND) { + sprintf(prompt, "Land unit(s) to tend from %s? ", + prship(&tender)); + if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) + continue; + if (!check_ship_ok(&tender)) + return RET_SYN; + if (0 != (retval = tend_land(&tender, p))) + return retval; + continue; + } + sprintf(prompt, "Number of %s to tend from %s? ", + ip->i_name, prship(&tender)); + if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) + continue; + if (!check_ship_ok(&tender)) + return RET_SYN; + if (!(amt = atoi(p))) { + pr("Amount must be non-zero!\n"); + return RET_SYN; + } + ontender = getvar(ip->i_vtype, (s_char *)&tender, EF_SHIP); + if (ontender == 0 && amt > 0) { + pr("No %s on %s\n", ip->i_name, prship(&tender)); + return RET_FAIL; + } + vbase = &mchr[(int)tender.shp_type]; + maxtender = vl_find(ip->i_vtype, vbase->m_vtype, + vbase->m_vamt, (int)vbase->m_nv); + if (maxtender == 0) { + pr("A %s cannot hold any %s\n", + mchr[(int)tender.shp_type].m_name, ip->i_name); + break; + } + if (!snxtitem(&targets, EF_SHIP, + getstarg(player->argp[4], "Ships to be tended? ", + buf))) + break; + if (!check_ship_ok(&tender)) + return RET_SYN; + total = 0; + while (tend_nxtitem(&targets, (s_char *)&target)) { + if (!player->owner && + (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY)) + continue; + if (target.shp_uid == tender.shp_uid) + continue; + if (tender.shp_x != target.shp_x || + tender.shp_y != target.shp_y) + continue; + ontarget = getvar(ip->i_vtype, (s_char *)&target, EF_SHIP); + if (ontarget == 0 && amt < 0) { + pr("No %s on %s\n", ip->i_name, prship(&target)); + continue; + } + vbase = &mchr[(int)target.shp_type]; + maxtarget = vl_find(ip->i_vtype, vbase->m_vtype, vbase->m_vamt, (int)vbase->m_nv); - if (amt < 0) { - if (!player->owner) - amt=0; + if (amt < 0) { + if (!player->owner) + amt = 0; - /* take from target and give to tender */ - transfer = min(ontarget, -amt); - transfer = min(maxtender - ontender, transfer); - if (transfer == 0) - continue; - putvar(ip->i_vtype, ontarget - transfer, - (s_char *)&target, EF_SHIP); - ontender += transfer; - total += transfer; - } else { - /* give to target from tender */ - transfer = min(ontender, amt); - transfer = min(transfer, maxtarget - ontarget); - if (transfer == 0) - continue; - putvar(ip->i_vtype, ontarget + transfer, - (s_char *)&target, EF_SHIP); - ontender -= transfer; - total += transfer; - } - expose_ship(&tender, &target); - putship(target.shp_uid, &target); - if (amt > 0 && ontender == 0) { - pr("%s out of %s\n", - prship(&tender), - ip->i_name); - break; - } - } - pr("%d total %s transferred %s %s\n", - total, ip->i_name, (amt > 0) ? "off of" : "to", - prship(&tender)); - putvar(ip->i_vtype, ontender, (s_char *)&tender, EF_SHIP); - tender.shp_mission = 0; - putship(tender.shp_uid, &tender); + /* take from target and give to tender */ + transfer = min(ontarget, -amt); + transfer = min(maxtender - ontender, transfer); + if (transfer == 0) + continue; + putvar(ip->i_vtype, ontarget - transfer, + (s_char *)&target, EF_SHIP); + ontender += transfer; + total += transfer; + } else { + /* give to target from tender */ + transfer = min(ontender, amt); + transfer = min(transfer, maxtarget - ontarget); + if (transfer == 0) + continue; + putvar(ip->i_vtype, ontarget + transfer, + (s_char *)&target, EF_SHIP); + ontender -= transfer; + total += transfer; + } + expose_ship(&tender, &target); + putship(target.shp_uid, &target); + if (amt > 0 && ontender == 0) { + pr("%s out of %s\n", prship(&tender), ip->i_name); + break; + } } - return RET_OK; + pr("%d total %s transferred %s %s\n", + total, ip->i_name, (amt > 0) ? "off of" : "to", + prship(&tender)); + putvar(ip->i_vtype, ontender, (s_char *)&tender, EF_SHIP); + tender.shp_mission = 0; + putship(tender.shp_uid, &tender); + } + return RET_OK; } static void expose_ship(struct shpstr *s1, struct shpstr *s2) { - if (getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)s2, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s2, EF_SHIP); - if (getvar(V_PSTAGE, (s_char *)s2, EF_SHIP) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s1, EF_SHIP); + if (getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)s2, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s2, EF_SHIP); + if (getvar(V_PSTAGE, (s_char *)s2, EF_SHIP) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)s1, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)s1, EF_SHIP); } /* @@ -221,158 +217,162 @@ expose_ship(struct shpstr *s1, struct shpstr *s2) int tend_nxtitem(struct nstr_item *np, caddr_t ptr) { - struct genitem *gp; - int selected; + struct genitem *gp; + int selected; - if (np->sel == NS_UNDEF) + if (np->sel == NS_UNDEF) + return 0; + gp = (struct genitem *)ptr; + do { + if (np->sel == NS_LIST) { + np->index++; + if (np->index >= np->size) return 0; - gp = (struct genitem *) ptr; - do { - if (np->sel == NS_LIST) { - np->index++; - if (np->index >= np->size) - return 0; - np->cur = np->list[np->index]; - } else { - np->cur++; - } - if (!np->read(np->type, np->cur, ptr)) { - /* if read fails, fatal */ - return 0; - } - selected = 1; - switch (np->sel) { - case NS_LIST: - /* The change is to take the player->owner check out here */ - break; - case NS_ALL: - /* XXX maybe combine NS_LIST and NS_ALL later */ - break; - case NS_DIST: - if (!xyinrange(gp->x, gp->y, &np->range)) { - selected = 0; - break; - } - np->curdist = mapdist((int)gp->x, (int)gp->y, - (int)np->cx, (int)np->cy); - if (np->curdist > np->dist) - selected = 0; - break; - case NS_AREA: - if (!xyinrange(gp->x, gp->y, &np->range)) - selected = 0; - if (gp->x == np->range.hx || gp->y == np->range.hy) - selected = 0; - break; - case NS_XY: - if (gp->x != np->cx || gp->y != np->cy) - selected = 0; - break; - case NS_GROUP: - if (np->group != gp->group) - selected = 0; - break; - default: - logerror("nxtitem: bad selector %d\n", np->sel); - return 0; - } - if (selected && np->ncond) { - /* nstr_exec is expensive, so we do it last */ - if (!nstr_exec(np->cond, np->ncond, ptr, np->type)) - selected = 0; - } - } while (!selected); - return 1; + np->cur = np->list[np->index]; + } else { + np->cur++; + } + if (!np->read(np->type, np->cur, ptr)) { + /* if read fails, fatal */ + return 0; + } + selected = 1; + switch (np->sel) { + case NS_LIST: + /* The change is to take the player->owner check out here */ + break; + case NS_ALL: + /* XXX maybe combine NS_LIST and NS_ALL later */ + break; + case NS_DIST: + if (!xyinrange(gp->x, gp->y, &np->range)) { + selected = 0; + break; + } + np->curdist = mapdist((int)gp->x, (int)gp->y, + (int)np->cx, (int)np->cy); + if (np->curdist > np->dist) + selected = 0; + break; + case NS_AREA: + if (!xyinrange(gp->x, gp->y, &np->range)) + selected = 0; + if (gp->x == np->range.hx || gp->y == np->range.hy) + selected = 0; + break; + case NS_XY: + if (gp->x != np->cx || gp->y != np->cy) + selected = 0; + break; + case NS_GROUP: + if (np->group != gp->group) + selected = 0; + break; + default: + logerror("nxtitem: bad selector %d\n", np->sel); + return 0; + } + if (selected && np->ncond) { + /* nstr_exec is expensive, so we do it last */ + if (!nstr_exec(np->cond, np->ncond, ptr, np->type)) + selected = 0; + } + } while (!selected); + return 1; } static int tend_land(struct shpstr *tenderp, s_char *units) { - struct nstr_item lni; - struct nstr_item targets; - struct shpstr target; - struct lndstr land; - struct plnstr plane; - struct nstr_item pni; - s_char buf[1024]; + struct nstr_item lni; + struct nstr_item targets; + struct shpstr target; + struct lndstr land; + struct plnstr plane; + struct nstr_item pni; + s_char buf[1024]; - if (!snxtitem(&lni, EF_LAND, units)) - return RET_SYN; + if (!snxtitem(&lni, EF_LAND, units)) + return RET_SYN; - while(nxtitem(&lni, (s_char *)&land)) { - if (!player->owner) - continue; - if (land.lnd_ship != tenderp->shp_uid) { - pr("%s is not on %s!\n", - prland(&land), prship(tenderp)); - continue; - } - if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) { - pr("%s does not have \"assault\" capability and can't be tended\n", prland(&land)); - continue; - } - if (!snxtitem(&targets, EF_SHIP, - getstarg(player->argp[4], "Ship to be tended? ", buf))) - break; - if (!check_land_ok(&land)) - return RET_SYN; - while (tend_nxtitem(&targets, (s_char *)&target)) { - if (!player->owner && - (getrel(getnatp(target.shp_own), - player->cnum) < FRIENDLY)) - continue; - if (target.shp_uid == tenderp->shp_uid) - continue; - if (tenderp->shp_x != target.shp_x || - tenderp->shp_y != target.shp_y) - continue; - - /* Fit unit on ship */ - count_units(&target); - getship(target.shp_uid,&target); + while (nxtitem(&lni, (s_char *)&land)) { + if (!player->owner) + continue; + if (land.lnd_ship != tenderp->shp_uid) { + pr("%s is not on %s!\n", prland(&land), prship(tenderp)); + continue; + } + if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) { + pr("%s does not have \"assault\" capability and can't be tended\n", prland(&land)); + continue; + } + if (!snxtitem(&targets, EF_SHIP, + getstarg(player->argp[4], "Ship to be tended? ", + buf))) + break; + if (!check_land_ok(&land)) + return RET_SYN; + while (tend_nxtitem(&targets, (s_char *)&target)) { + if (!player->owner && + (getrel(getnatp(target.shp_own), player->cnum) < FRIENDLY)) + continue; + if (target.shp_uid == tenderp->shp_uid) + continue; + if (tenderp->shp_x != target.shp_x || + tenderp->shp_y != target.shp_y) + continue; - if (target.shp_nland >= mchr[(int)target.shp_type].m_nland) { - if (mchr[(int)target.shp_type].m_nland) - pr("%s doesn't have room for any more land units!\n",prship(&target)); - else - pr("%s doesn't carry land units!\n",prship(&target)); - continue; - } - pr("%s transferred from %s to %s\n", - prland(&land), prship(tenderp), prship(&target)); - sprintf(buf, "loaded on your %s at %s", - prship(&target),xyas(target.shp_x,target.shp_y, - target.shp_own)); - gift(target.shp_own,player->cnum,(s_char *)&land, - EF_LAND, buf); - makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_own = target.shp_own; - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_ship = target.shp_uid; - land.lnd_harden = 0; - land.lnd_mission = 0; - target.shp_nland++; - putland(land.lnd_uid,&land); - expose_ship(tenderp, &target); - putship(target.shp_uid, &target); - count_units(tenderp); - putship(tenderp->shp_uid, tenderp); - snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y); - while (nxtitem(&pni, (s_char *)&plane)) { - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_land != land.lnd_uid) - continue; - sprintf(buf, "loaded on %s", prship(&target)); - gift(target.shp_own,player->cnum,(s_char *)&plane, - EF_PLANE, buf); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = target.shp_own; - makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_mission = 0; - putplane(plane.pln_uid,&plane); - } - } + /* Fit unit on ship */ + count_units(&target); + getship(target.shp_uid, &target); + + if (target.shp_nland >= mchr[(int)target.shp_type].m_nland) { + if (mchr[(int)target.shp_type].m_nland) + pr("%s doesn't have room for any more land units!\n", + prship(&target)); + else + pr("%s doesn't carry land units!\n", prship(&target)); + continue; + } + pr("%s transferred from %s to %s\n", + prland(&land), prship(tenderp), prship(&target)); + sprintf(buf, "loaded on your %s at %s", + prship(&target), xyas(target.shp_x, target.shp_y, + target.shp_own)); + gift(target.shp_own, player->cnum, (s_char *)&land, + EF_LAND, buf); + makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_own = target.shp_own; + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_ship = target.shp_uid; + land.lnd_harden = 0; + land.lnd_mission = 0; + target.shp_nland++; + putland(land.lnd_uid, &land); + expose_ship(tenderp, &target); + putship(target.shp_uid, &target); + count_units(tenderp); + putship(tenderp->shp_uid, tenderp); + snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y); + while (nxtitem(&pni, (s_char *)&plane)) { + if (plane.pln_flags & PLN_LAUNCHED) + continue; + if (plane.pln_land != land.lnd_uid) + continue; + sprintf(buf, "loaded on %s", prship(&target)); + gift(target.shp_own, player->cnum, (s_char *)&plane, + EF_PLANE, buf); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_own = target.shp_own; + makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, + plane.pln_x, plane.pln_y); + plane.pln_mission = 0; + putplane(plane.pln_uid, &plane); + } } - return 0; + } + return 0; } diff --git a/src/lib/commands/terr.c b/src/lib/commands/terr.c index 0510bd4c2..2ccf9ee25 100644 --- a/src/lib/commands/terr.c +++ b/src/lib/commands/terr.c @@ -44,14 +44,14 @@ int terr(void) { - struct sctstr sect; - s_char *p; - int terr_n; - int field; - struct nstr_sect nstr; - s_char prompt[128]; - s_char buf[1024]; - + struct sctstr sect; + s_char *p; + int terr_n; + int field; + struct nstr_sect nstr; + s_char prompt[128]; + s_char buf[1024]; + if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; if (player->argp[3] && isdigit(*(player->argp[3]))) { @@ -62,7 +62,7 @@ terr(void) while (nxtsct(&nstr, §)) { if (!player->owner) continue; - sprintf(prompt, "%s %d%% %s territory? ", + sprintf(prompt, "%s %d%% %s territory? ", xyas(nstr.x, nstr.y, player->cnum), sect.sct_effic, dchr[sect.sct_type].d_name); if ((p = getstarg(player->argp[2], prompt, buf)) == 0) @@ -74,7 +74,7 @@ terr(void) terr_n = atoi(p); while (terr_n < 0 || terr_n > 99 || *p < '0' || *p > '9') { pr("Enter a number between 0 and 99!\n"); - sprintf(prompt, "%s %d%% %s territory? ", + sprintf(prompt, "%s %d%% %s territory? ", xyas(nstr.x, nstr.y, player->cnum), sect.sct_effic, dchr[sect.sct_type].d_name); if ((p = getstarg((s_char *)0, prompt, buf)) == 0) @@ -88,13 +88,19 @@ terr(void) if (*p == 0) continue; switch (field) { - case 1: sect.sct_terr1 = terr_n; break; - case 2: sect.sct_terr2 = terr_n; break; - case 3: sect.sct_terr3 = terr_n; break; - default: sect.sct_terr = terr_n; + case 1: + sect.sct_terr1 = terr_n; + break; + case 2: + sect.sct_terr2 = terr_n; + break; + case 3: + sect.sct_terr3 = terr_n; + break; + default: + sect.sct_terr = terr_n; } putsect(§); } return RET_OK; } - diff --git a/src/lib/commands/thre.c b/src/lib/commands/thre.c index d821291cb..164389de3 100644 --- a/src/lib/commands/thre.c +++ b/src/lib/commands/thre.c @@ -49,17 +49,17 @@ int thre(void) { - extern struct ichrstr *whatitem(); - struct sctstr sect; - struct nstr_sect nstr; - int val; - struct ichrstr *ip; - s_char *p; - int thresh; - int type; - s_char prompt[128]; - s_char buf[128]; - + extern struct ichrstr *whatitem(); + struct sctstr sect; + struct nstr_sect nstr; + int val; + struct ichrstr *ip; + s_char *p; + int thresh; + int type; + s_char prompt[128]; + s_char buf[128]; + if ((ip = whatitem(player->argp[1], "What commodity? ")) == 0) return RET_SYN; if (!snxtsct(&nstr, player->argp[2])) @@ -67,7 +67,7 @@ thre(void) type = V_DIST(ip->i_vtype & (~VT_TYPE)); if (player->argp[3] && *player->argp[3] && (*player->argp[3] < '0' || *player->argp[3] > '9')) { - pr ("Threshold must be a number\n"); + pr("Threshold must be a number\n"); return RET_SYN; } while (!player->aborted && nxtsct(&nstr, §)) { @@ -98,8 +98,7 @@ thre(void) } if (val > 0 && (player->argp[3] != 0 && *player->argp[3] != 0)) pr("%s old threshold %d\n", - xyas(nstr.x, nstr.y, player->cnum), - val); + xyas(nstr.x, nstr.y, player->cnum), val); if (putvar(type, thresh, (s_char *)§, EF_SECTOR) < 0) pr("No room for threshold in %s\n", xyas(nstr.x, nstr.y, player->cnum)); diff --git a/src/lib/commands/togg.c b/src/lib/commands/togg.c index ff4b65378..14211d7f3 100644 --- a/src/lib/commands/togg.c +++ b/src/lib/commands/togg.c @@ -41,70 +41,82 @@ int togg(void) { - int flag = 0; - int pos; - s_char *name; - struct natstr *np; + int flag = 0; + int pos; + s_char *name; + struct natstr *np; - np = getnatp(player->cnum); - if (player->argp[1]) { - switch (*player->argp[1]) { - case 'i': - name = "inform"; flag = NF_INFORM; break; - case 'f': - name = "flash"; flag = NF_FLASH; break; - case 'b': - name = "beep"; flag = NF_BEEP; break; - case 'c': - name = "coastwatch"; flag = NF_COASTWATCH; break; - case 's': - name = "sonar"; flag = NF_SONAR; break; - case 't': - name = "techlists"; flag = NF_TECHLISTS; break; - default: - return RET_SYN; - } - if (player->argp[2]) - if (!strcmp(player->argp[2], "on")) - pos = 1; - else if (!strcmp(player->argp[2], "off")) - pos = 0; - else - return RET_SYN; - else - pos = !(np->nat_flags & flag); - if (pos) - np->nat_flags |= flag; - else - np->nat_flags &= ~flag; - putnat(np); - pr("%s flag %s\n", name, pos?"on":"off"); - } else { - if (np->nat_flags & NF_INFORM) - pr("inform flag on\n"); - else - pr("inform flag off\n"); - if (np->nat_flags & NF_FLASH) - pr("flash flag on\n"); - else - pr("flash flag off\n"); - if (np->nat_flags & NF_BEEP) - pr("beep flag on\n"); - else - pr("beep flag off\n"); - if (np->nat_flags & NF_COASTWATCH) - pr("coastwatch flag on\n"); - else - pr("coastwatch flag off\n"); - if (np->nat_flags & NF_SONAR) - pr("sonar flag on\n"); - else - pr("sonar flag off\n"); - if (np->nat_flags & NF_TECHLISTS) - pr("techlists flag on\n"); - else - pr("techlists flag off\n"); + np = getnatp(player->cnum); + if (player->argp[1]) { + switch (*player->argp[1]) { + case 'i': + name = "inform"; + flag = NF_INFORM; + break; + case 'f': + name = "flash"; + flag = NF_FLASH; + break; + case 'b': + name = "beep"; + flag = NF_BEEP; + break; + case 'c': + name = "coastwatch"; + flag = NF_COASTWATCH; + break; + case 's': + name = "sonar"; + flag = NF_SONAR; + break; + case 't': + name = "techlists"; + flag = NF_TECHLISTS; + break; + default: + return RET_SYN; } + if (player->argp[2]) + if (!strcmp(player->argp[2], "on")) + pos = 1; + else if (!strcmp(player->argp[2], "off")) + pos = 0; + else + return RET_SYN; + else + pos = !(np->nat_flags & flag); + if (pos) + np->nat_flags |= flag; + else + np->nat_flags &= ~flag; + putnat(np); + pr("%s flag %s\n", name, pos ? "on" : "off"); + } else { + if (np->nat_flags & NF_INFORM) + pr("inform flag on\n"); + else + pr("inform flag off\n"); + if (np->nat_flags & NF_FLASH) + pr("flash flag on\n"); + else + pr("flash flag off\n"); + if (np->nat_flags & NF_BEEP) + pr("beep flag on\n"); + else + pr("beep flag off\n"); + if (np->nat_flags & NF_COASTWATCH) + pr("coastwatch flag on\n"); + else + pr("coastwatch flag off\n"); + if (np->nat_flags & NF_SONAR) + pr("sonar flag on\n"); + else + pr("sonar flag off\n"); + if (np->nat_flags & NF_TECHLISTS) + pr("techlists flag on\n"); + else + pr("techlists flag off\n"); + } - return RET_OK; + return RET_OK; } diff --git a/src/lib/commands/torp.c b/src/lib/commands/torp.c index 8ad43b539..cb51043e9 100644 --- a/src/lib/commands/torp.c +++ b/src/lib/commands/torp.c @@ -49,439 +49,435 @@ #include "commands.h" void anti_torp(int f, int ntorping, int vshipown); -void fire_dchrg(struct shpstr *sp, struct shpstr *targ, int range, int ntargets); +void fire_dchrg(struct shpstr *sp, struct shpstr *targ, int range, + int ntargets); s_char *prsub(struct shpstr *sp); int torp(void) { - extern int torpedo_damage; - natid vshipown; - int range; - int dam; - int shells; - int subno; - int victno; - double erange; - double hitchance; - struct shpstr vship; - struct shpstr sub; - s_char *ptr; - double mobcost; - struct mchrstr *mcp; - struct nstr_item nbst; - s_char buf[1024]; - s_char *sav; - int ntorping=0; - s_char prompt[128]; - - if (!(sav = getstarg(player->argp[1], "From ship(s)? ", buf))) - return RET_SYN; - if (!snxtitem(&nbst, EF_SHIP, sav)) - return RET_SYN; - while (nxtitem(&nbst, (s_char *)&sub)){ - if (sub.shp_own != player->cnum) - continue; - if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0) - continue; - shells = getvar(V_SHELL, (s_char *)&sub, EF_SHIP); - if (shells < 3) - shells += supply_commod(sub.shp_own,sub.shp_x,sub.shp_y,I_SHELL, - 3-shells); - if (getvar(V_GUN, (s_char *)&sub, EF_SHIP) == 0 || shells < 3) - continue; - if (getvar(V_MILIT, (s_char *)&sub, EF_SHIP) < 1) - continue; - if (sub.shp_effic < 60) - continue; - if (sub.shp_mobil <= 0) - continue; - ntorping++; + extern int torpedo_damage; + natid vshipown; + int range; + int dam; + int shells; + int subno; + int victno; + double erange; + double hitchance; + struct shpstr vship; + struct shpstr sub; + s_char *ptr; + double mobcost; + struct mchrstr *mcp; + struct nstr_item nbst; + s_char buf[1024]; + s_char *sav; + int ntorping = 0; + s_char prompt[128]; + + if (!(sav = getstarg(player->argp[1], "From ship(s)? ", buf))) + return RET_SYN; + if (!snxtitem(&nbst, EF_SHIP, sav)) + return RET_SYN; + while (nxtitem(&nbst, (s_char *)&sub)) { + if (sub.shp_own != player->cnum) + continue; + if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0) + continue; + shells = getvar(V_SHELL, (s_char *)&sub, EF_SHIP); + if (shells < 3) + shells += + supply_commod(sub.shp_own, sub.shp_x, sub.shp_y, I_SHELL, + 3 - shells); + if (getvar(V_GUN, (s_char *)&sub, EF_SHIP) == 0 || shells < 3) + continue; + if (getvar(V_MILIT, (s_char *)&sub, EF_SHIP) < 1) + continue; + if (sub.shp_effic < 60) + continue; + if (sub.shp_mobil <= 0) + continue; + ntorping++; + } + pr("%d ships are eligible to torp\n", ntorping); + snxtitem(&nbst, EF_SHIP, sav); + while (nxtitem(&nbst, (s_char *)&sub)) { + if (!sub.shp_own) + continue; + if (sub.shp_own != player->cnum) { + continue; + } + if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0) { + pr("Ship # %d: A %s can't fire torpedoes!\n", sub.shp_uid, + mchr[(int)sub.shp_type].m_name); + continue; + } + shells = getvar(V_SHELL, (s_char *)&sub, EF_SHIP); + if (shells < 3) + shells += + supply_commod(sub.shp_own, sub.shp_x, sub.shp_y, I_SHELL, + 3 - shells); + if (getvar(V_GUN, (s_char *)&sub, EF_SHIP) == 0 || shells < 3) { + pr("Ship #%d has insufficient armament\n", sub.shp_uid); + continue; + } + if (getvar(V_MILIT, (s_char *)&sub, EF_SHIP) < 1) { + pr("Ship #%d has insufficient crew\n", sub.shp_uid); + continue; + } + if (sub.shp_effic < 60) { + pr("Ship #%d torpedo tubes inoperative.\n", sub.shp_uid); + continue; + } + if (sub.shp_mobil <= 0) { + pr("Ship #%d has insufficient mobility\n", sub.shp_uid); + continue; + } + bzero(buf, 80); + subno = sub.shp_uid; + sprintf(prompt, "Ship %d, target? ", sub.shp_uid); + if ((ptr = getstarg(player->argp[2], prompt, buf)) == 0) + return RET_SYN; + if (!check_ship_ok(&sub)) + return RET_FAIL; + if ((victno = atoi(ptr)) < 0) + return RET_SYN; + if (!getship(victno, &vship)) + return RET_FAIL; + if (!vship.shp_own) + return RET_FAIL; + vshipown = vship.shp_own; + if (victno == subno) { + pr("Shooting yourself, eh? How strange...\n"); + continue; + } + if (mchr[(int)vship.shp_type].m_flags & M_SUB) { + if (!(mchr[(int)sub.shp_type].m_flags & M_SUBT)) { + pr("You can't torpedo a submarine!\n"); + continue; + } + } + if ((mchr[(int)sub.shp_type].m_flags & M_SUB) == 0) + anti_torp(sub.shp_uid, ntorping, vshipown); + getship(sub.shp_uid, &sub); + if (sub.shp_own == 0) { + continue; + } + erange = ((double)sub.shp_effic / 100.0) * + techfact(sub.shp_tech, ((double)sub.shp_frnge)); + erange = (double)roundrange(erange); + pr("Effective torpedo range is %.1f\n", erange); + shells -= 3; + putvar(V_SHELL, shells, (s_char *)&sub, EF_SHIP); + putship(sub.shp_uid, &sub); + mcp = &mchr[(int)sub.shp_type]; + mobcost = sub.shp_effic * 0.01 * sub.shp_speed; + mobcost = (480.0 / (mobcost + techfact(sub.shp_tech, mobcost))); + + /* Mob cost for a torp is equal to the cost of 1/2 sector of movement */ + mobcost /= 2.0; + sub.shp_mobil -= mobcost; + pr("Whooosh... "); + getship(victno, &vship); + vshipown = vship.shp_own; + range = mapdist(sub.shp_x, sub.shp_y, vship.shp_x, vship.shp_y); + hitchance = DTORP_HITCHANCE(range, sub.shp_visib); + if (range <= erange) { + pr("Hitchance = %d%%\n", (int)(hitchance * 100)); } - pr("%d ships are eligible to torp\n",ntorping); - snxtitem(&nbst, EF_SHIP, sav); - while (nxtitem(&nbst, (s_char *)&sub)) { - if (!sub.shp_own) - continue; - if (sub.shp_own != player->cnum) { - continue; - } - if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0) { - pr("Ship # %d: A %s can't fire torpedoes!\n", sub.shp_uid, - mchr[(int)sub.shp_type].m_name); - continue; - } - shells = getvar(V_SHELL, (s_char *)&sub, EF_SHIP); - if (shells < 3) - shells += supply_commod(sub.shp_own,sub.shp_x,sub.shp_y -,I_SHELL, - 3-shells); - if (getvar(V_GUN, (s_char *)&sub, EF_SHIP) == 0 || shells < 3) { - pr("Ship #%d has insufficient armament\n",sub.shp_uid); - continue; - } - if (getvar(V_MILIT, (s_char *)&sub, EF_SHIP) < 1){ - pr("Ship #%d has insufficient crew\n",sub.shp_uid); - continue; - } - if (sub.shp_effic < 60) { - pr("Ship #%d torpedo tubes inoperative.\n",sub.shp_uid); - continue; - } - if (sub.shp_mobil <= 0) { - pr("Ship #%d has insufficient mobility\n",sub.shp_uid); - continue; - } - bzero(buf,80); - subno=sub.shp_uid; - sprintf(prompt, "Ship %d, target? ",sub.shp_uid); - if ((ptr = getstarg(player->argp[2],prompt, buf)) == 0) - return RET_SYN; - if (!check_ship_ok(&sub)) - return RET_FAIL; - if ((victno = atoi(ptr)) < 0) - return RET_SYN; - if (!getship(victno, &vship)) - return RET_FAIL; - if (!vship.shp_own) - return RET_FAIL; - vshipown=vship.shp_own; - if (victno == subno) { - pr("Shooting yourself, eh? How strange...\n"); - continue; - } - if (mchr[(int)vship.shp_type].m_flags & M_SUB) { - if (!(mchr[(int)sub.shp_type].m_flags & M_SUBT)){ - pr("You can't torpedo a submarine!\n"); - continue; - } - } - if ((mchr[(int)sub.shp_type].m_flags & M_SUB) == 0) - anti_torp(sub.shp_uid,ntorping,vshipown); - getship(sub.shp_uid,&sub); - if (sub.shp_own == 0){ - continue; - } - erange = ((double)sub.shp_effic/100.0) * - techfact(sub.shp_tech, ((double)sub.shp_frnge)); - erange = (double)roundrange(erange); - pr("Effective torpedo range is %.1f\n", erange); - shells -= 3; - putvar(V_SHELL, shells, (s_char *)&sub, EF_SHIP); - putship(sub.shp_uid,&sub); - mcp = &mchr[(int)sub.shp_type]; - mobcost = sub.shp_effic * 0.01 * sub.shp_speed; - mobcost = (480.0 / (mobcost + techfact(sub.shp_tech, mobcost))); - - /* Mob cost for a torp is equal to the cost of 1/2 sector of movement */ - mobcost /= 2.0; - sub.shp_mobil -= mobcost; - pr("Whooosh... "); - getship(victno, &vship); - vshipown = vship.shp_own; - range = mapdist(sub.shp_x, sub.shp_y, vship.shp_x, vship.shp_y); - hitchance = DTORP_HITCHANCE(range, sub.shp_visib); - if (range <= erange) { - pr("Hitchance = %d%%\n",(int)(hitchance*100)); - } - /* Now, can the torpedo even get there? */ - if (!line_of_sight((s_char **)0, sub.shp_x, sub.shp_y, - vship.shp_x, vship.shp_y)) { - pr("BOOM!... Torpedo slams into land before reaching target.\n"); - /* We only tell the victim if we were within range. */ - if (range <= erange) { - if (vshipown != 0) - wu(0, vshipown, "Torpedo sighted @ %s by %s\n", - xyas(sub.shp_x, sub.shp_y, vshipown), - prship(&vship)); - } - } else if (range > erange) { - pr("Out of range\n"); - } else if (hitchance >= 1.0 || chance(hitchance)) { - pr("BOOM!...\n"); - dam = TORP_DAMAGE(); - if(vshipown != 0) - wu(0, vshipown, "%s in %s torpedoed %s for %d damage.\n", prsub(&sub), - xyas(sub.shp_x, sub.shp_y, vshipown), - prship(&vship), dam); - if (vship.shp_rflags & RET_TORPED){ - retreat_ship(&vship, 't'); - shipdamage(&vship, dam); - }else - shipdamage(&vship, dam); - pr("Torpedo hit %s for %d damage.\n", - prship(&vship), - dam); - - if (vship.shp_effic < SHIP_MINEFF) - pr("%s sunk!\n", - prship(&vship)); - putship(vship.shp_uid, &vship); - if (mchr[(int)sub.shp_type].m_flags & M_SUB) - nreport(vshipown, N_TORP_SHIP, 0, 1); - else - nreport(vshipown, N_SHIP_TORP, player->cnum, 1); - } else { - pr("Missed\n"); - if (vshipown != 0) - wu(0, vshipown, "Torpedo sighted @ %s by %s\n", - xyas(sub.shp_x, sub.shp_y, vshipown), - prship(&vship)); - } - sub.shp_mission=0; - putship(sub.shp_uid, &sub); - if (mchr[(int)sub.shp_type].m_flags & M_SUB) - anti_torp(sub.shp_uid,ntorping,vshipown); + /* Now, can the torpedo even get there? */ + if (!line_of_sight((s_char **)0, sub.shp_x, sub.shp_y, + vship.shp_x, vship.shp_y)) { + pr("BOOM!... Torpedo slams into land before reaching target.\n"); + /* We only tell the victim if we were within range. */ + if (range <= erange) { + if (vshipown != 0) + wu(0, vshipown, "Torpedo sighted @ %s by %s\n", + xyas(sub.shp_x, sub.shp_y, vshipown), + prship(&vship)); + } + } else if (range > erange) { + pr("Out of range\n"); + } else if (hitchance >= 1.0 || chance(hitchance)) { + pr("BOOM!...\n"); + dam = TORP_DAMAGE(); + if (vshipown != 0) + wu(0, vshipown, "%s in %s torpedoed %s for %d damage.\n", + prsub(&sub), xyas(sub.shp_x, sub.shp_y, vshipown), + prship(&vship), dam); + if (vship.shp_rflags & RET_TORPED) { + retreat_ship(&vship, 't'); + shipdamage(&vship, dam); + } else + shipdamage(&vship, dam); + pr("Torpedo hit %s for %d damage.\n", prship(&vship), dam); + + if (vship.shp_effic < SHIP_MINEFF) + pr("%s sunk!\n", prship(&vship)); + putship(vship.shp_uid, &vship); + if (mchr[(int)sub.shp_type].m_flags & M_SUB) + nreport(vshipown, N_TORP_SHIP, 0, 1); + else + nreport(vshipown, N_SHIP_TORP, player->cnum, 1); + } else { + pr("Missed\n"); + if (vshipown != 0) + wu(0, vshipown, "Torpedo sighted @ %s by %s\n", + xyas(sub.shp_x, sub.shp_y, vshipown), prship(&vship)); } - return RET_OK; + sub.shp_mission = 0; + putship(sub.shp_uid, &sub); + if (mchr[(int)sub.shp_type].m_flags & M_SUB) + anti_torp(sub.shp_uid, ntorping, vshipown); + } + return RET_OK; } void anti_torp(int f, int ntorping, int vshipown) { - int range; - double erange; - struct shpstr sub; - struct shpstr dd; - int x; + int range; + double erange; + struct shpstr sub; + struct shpstr dd; + int x; - getship(f,&sub); + getship(f, &sub); - if (sub.shp_own == vshipown) - return; + if (sub.shp_own == vshipown) + return; - if ((mchr[(int)sub.shp_type].m_flags & M_SUB) == 0) - pr("Starting our attack run...\n"); + if ((mchr[(int)sub.shp_type].m_flags & M_SUB) == 0) + pr("Starting our attack run...\n"); - x=0; - while (getship(x++,&dd) && sub.shp_effic >= SHIP_MINEFF){ - if (dd.shp_own == 0) - continue; - if (dd.shp_own != vshipown) - continue; - if (dd.shp_effic < 60) - continue; + x = 0; + while (getship(x++, &dd) && sub.shp_effic >= SHIP_MINEFF) { + if (dd.shp_own == 0) + continue; + if (dd.shp_own != vshipown) + continue; + if (dd.shp_effic < 60) + continue; - if (!canshoot(&dd,&sub)) - continue; + if (!canshoot(&dd, &sub)) + continue; - erange = techfact(dd.shp_tech, - ((double)dd.shp_frnge))/ 2.0; + erange = techfact(dd.shp_tech, ((double)dd.shp_frnge)) / 2.0; - erange = (double)roundrange(erange); + erange = (double)roundrange(erange); - range = mapdist(sub.shp_x, sub.shp_y, dd.shp_x, dd.shp_y); + range = mapdist(sub.shp_x, sub.shp_y, dd.shp_x, dd.shp_y); - if (range > erange) - continue; + if (range > erange) + continue; - if (!line_of_sight((s_char **)0, sub.shp_x, sub.shp_y, - dd.shp_x, dd.shp_y)) - continue; + if (!line_of_sight((s_char **)0, sub.shp_x, sub.shp_y, + dd.shp_x, dd.shp_y)) + continue; - if (cantorp(&dd,&sub)){ - /* Try torping.. if we can, maybe we can fire */ - if (!fire_torp(&dd,&sub,range,ntorping)) - if (candchrg(&dd,&sub)) - fire_dchrg(&dd,&sub,range,ntorping); - }else - fire_dchrg(&dd,&sub,range,ntorping); - } + if (cantorp(&dd, &sub)) { + /* Try torping.. if we can, maybe we can fire */ + if (!fire_torp(&dd, &sub, range, ntorping)) + if (candchrg(&dd, &sub)) + fire_dchrg(&dd, &sub, range, ntorping); + } else + fire_dchrg(&dd, &sub, range, ntorping); + } } /* Can ship A shoot at ship B? */ int canshoot(struct shpstr *a, struct shpstr *b) { - /* Anyone can shoot a normal ship */ - if ((mchr[(int)b->shp_type].m_flags & M_SUB) == 0) - return 1; + /* Anyone can shoot a normal ship */ + if ((mchr[(int)b->shp_type].m_flags & M_SUB) == 0) + return 1; - /* You can depth-charge a sub */ - if (mchr[(int)a->shp_type].m_flags & M_DCH) - return 1; + /* You can depth-charge a sub */ + if (mchr[(int)a->shp_type].m_flags & M_DCH) + return 1; - /* If you have SUBT flag, you can torp a sub */ - if (mchr[(int)a->shp_type].m_flags & M_SUBT) - return 1; + /* If you have SUBT flag, you can torp a sub */ + if (mchr[(int)a->shp_type].m_flags & M_SUBT) + return 1; - return 0; + return 0; } /* Can ship A torp ship B? */ int cantorp(struct shpstr *a, struct shpstr *b) { - if ((mchr[(int)a->shp_type].m_flags & M_TORP) == 0) - return 0; + if ((mchr[(int)a->shp_type].m_flags & M_TORP) == 0) + return 0; - /* Anyone with TORP flag can torp a normal ship */ - if ((mchr[(int)b->shp_type].m_flags & M_SUB) == 0) - return 1; + /* Anyone with TORP flag can torp a normal ship */ + if ((mchr[(int)b->shp_type].m_flags & M_SUB) == 0) + return 1; - /* Ship b is a sub, so we need to have the SUBT flag */ - if (mchr[(int)a->shp_type].m_flags & M_SUBT) - return 1; + /* Ship b is a sub, so we need to have the SUBT flag */ + if (mchr[(int)a->shp_type].m_flags & M_SUBT) + return 1; - return 0; + return 0; } /* Can ship A depth-charge (or fire guns at) ship B? */ int candchrg(struct shpstr *a, struct shpstr *b) { - if ((mchr[(int)b->shp_type].m_flags & M_SUB) == 0){ - if ((mchr[(int)a->shp_type].m_flags & M_SUB) == 0) - return 1; + if ((mchr[(int)b->shp_type].m_flags & M_SUB) == 0) { + if ((mchr[(int)a->shp_type].m_flags & M_SUB) == 0) + return 1; - return 0; - } + return 0; + } - if ((mchr[(int)a->shp_type].m_flags & M_DCH) == 0) - return 0; + if ((mchr[(int)a->shp_type].m_flags & M_DCH) == 0) + return 0; - return 1; + return 1; } void fire_dchrg(struct shpstr *sp, struct shpstr *targ, int range, int ntargets) { - int dam; - int shells; - int gun; - double guneff; - - shells = getvar(V_SHELL, (s_char *)sp, EF_SHIP); - gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); - gun = min(gun, sp->shp_glim); - gun = min(gun, getvar(V_MILIT, (s_char *)sp, EF_SHIP)/2); - - shells+=supply_commod(sp->shp_own,sp->shp_x,sp->shp_y,I_SHELL,(gun+1)/2-shells); - - gun = min(gun, shells*2); - if (gun == 0) return; - - /* ok, all set.. now, we shoot */ - shells -= ldround(((double)gun)/2.0,1); - putvar(V_SHELL, shells, (s_char *)sp, EF_SHIP); - putship(sp->shp_uid,sp); - - guneff = seagun(sp->shp_effic, gun); - dam = (int)guneff; - - if ((mchr[(int)targ->shp_type].m_flags & M_SUB) == 0){ - pr_beep(); - pr("Kaboom!!! Incoming shells!\n"); - if(sp->shp_own != 0) - wu(0, sp->shp_own, - "%s fired at %s\n", - prship(sp), - prship(targ)); - - if (ntargets > 2) - dam /= ((float)ntargets/2.0); - pr_beep(); - pr("BLAM! %d damage!\n", dam); - shipdamage(targ, dam); - putship(targ->shp_uid,targ); - }else{ - pr("\nCAPTAIN! !!Depth charges!!...\n"); - if(sp->shp_own != 0) - wu(0, sp->shp_own, - "%s depth charged %s\n", - prship(sp), prsub(targ)); - - if (ntargets>2) - dam /= ((float)ntargets/2.0); - - pr("click...WHAM! %d damage!\n", dam); - shipdamage(targ, dam); - putship(targ->shp_uid,targ); - } + int dam; + int shells; + int gun; + double guneff; + + shells = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); + gun = min(gun, sp->shp_glim); + gun = min(gun, getvar(V_MILIT, (s_char *)sp, EF_SHIP) / 2); + + shells += + supply_commod(sp->shp_own, sp->shp_x, sp->shp_y, I_SHELL, + (gun + 1) / 2 - shells); + + gun = min(gun, shells * 2); + if (gun == 0) + return; + + /* ok, all set.. now, we shoot */ + shells -= ldround(((double)gun) / 2.0, 1); + putvar(V_SHELL, shells, (s_char *)sp, EF_SHIP); + putship(sp->shp_uid, sp); + + guneff = seagun(sp->shp_effic, gun); + dam = (int)guneff; + + if ((mchr[(int)targ->shp_type].m_flags & M_SUB) == 0) { + pr_beep(); + pr("Kaboom!!! Incoming shells!\n"); + if (sp->shp_own != 0) + wu(0, sp->shp_own, + "%s fired at %s\n", prship(sp), prship(targ)); + + if (ntargets > 2) + dam /= ((float)ntargets / 2.0); + pr_beep(); + pr("BLAM! %d damage!\n", dam); + shipdamage(targ, dam); + putship(targ->shp_uid, targ); + } else { + pr("\nCAPTAIN! !!Depth charges!!...\n"); + if (sp->shp_own != 0) + wu(0, sp->shp_own, + "%s depth charged %s\n", prship(sp), prsub(targ)); + + if (ntargets > 2) + dam /= ((float)ntargets / 2.0); + + pr("click...WHAM! %d damage!\n", dam); + shipdamage(targ, dam); + putship(targ->shp_uid, targ); + } } int fire_torp(struct shpstr *sp, struct shpstr *targ, int range, int ntargets) { - extern int torpedo_damage; - int dam; - int shells; - double hitchance; - double mobcost; - struct mchrstr *mcp; - - shells = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + extern int torpedo_damage; + int dam; + int shells; + double hitchance; + double mobcost; + struct mchrstr *mcp; - if (shells < 3) - shells += supply_commod(sp->shp_own,sp->shp_x,sp->shp_y,I_SHELL, - 3-shells); + shells = getvar(V_SHELL, (s_char *)sp, EF_SHIP); - if (getvar(V_GUN, (s_char *)sp, EF_SHIP) == 0 || shells < 3) - return 0; + if (shells < 3) + shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y, I_SHELL, + 3 - shells); - if (getvar(V_MILIT, (s_char *)sp, EF_SHIP) < 1) - return 0; + if (getvar(V_GUN, (s_char *)sp, EF_SHIP) == 0 || shells < 3) + return 0; - if (sp->shp_effic < 60) - return 0; + if (getvar(V_MILIT, (s_char *)sp, EF_SHIP) < 1) + return 0; - if (sp->shp_mobil <= 0) - return 0; + if (sp->shp_effic < 60) + return 0; - /* All set.. fire! */ - shells -= 3; - putvar(V_SHELL, shells, (s_char *)sp, EF_SHIP); - putship(sp->shp_uid,sp); + if (sp->shp_mobil <= 0) + return 0; - mcp = &mchr[(int)sp->shp_type]; - mobcost = sp->shp_effic * 0.01 * sp->shp_speed; - mobcost = (480.0 / (mobcost + techfact(sp->shp_tech, mobcost))); + /* All set.. fire! */ + shells -= 3; + putvar(V_SHELL, shells, (s_char *)sp, EF_SHIP); + putship(sp->shp_uid, sp); - /* Mob cost for a torp is equal to the cost of 1/2 sector of movement */ - mobcost /= 2.0; - sp->shp_mobil -= mobcost; + mcp = &mchr[(int)sp->shp_type]; + mobcost = sp->shp_effic * 0.01 * sp->shp_speed; + mobcost = (480.0 / (mobcost + techfact(sp->shp_tech, mobcost))); - hitchance = DTORP_HITCHANCE(range, sp->shp_visib); + /* Mob cost for a torp is equal to the cost of 1/2 sector of movement */ + mobcost /= 2.0; + sp->shp_mobil -= mobcost; - pr("Captain! Torpedoes sighted!\n"); + hitchance = DTORP_HITCHANCE(range, sp->shp_visib); - if (chance(hitchance)) { - pr("BOOM!...\n"); - if(sp->shp_own != 0) - wu(0, sp->shp_own, "%s @ %s torpedoed %s\n", - prship(sp), - xyas(sp->shp_x, sp->shp_y, sp->shp_own), - prsub(targ)); - dam = TORP_DAMAGE(); + pr("Captain! Torpedoes sighted!\n"); - if (ntargets>2) - dam /= ((float)ntargets/2.0); + if (chance(hitchance)) { + pr("BOOM!...\n"); + if (sp->shp_own != 0) + wu(0, sp->shp_own, "%s @ %s torpedoed %s\n", + prship(sp), + xyas(sp->shp_x, sp->shp_y, sp->shp_own), prsub(targ)); + dam = TORP_DAMAGE(); - shipdamage(targ, dam); - putship(targ->shp_uid, targ); + if (ntargets > 2) + dam /= ((float)ntargets / 2.0); - if (mchr[(int)sp->shp_type].m_flags & M_SUB) - nreport(targ->shp_own, N_TORP_SHIP, 0, 1); - else - nreport(targ->shp_own, N_SHIP_TORP, player->cnum, 1); - } else { - pr("Missed!\n"); - if(sp->shp_own != 0) - wu(0, sp->shp_own, - "%s missed %s with a torp at %s\n", - prship(sp), prsub(targ), - xyas(sp->shp_x, sp->shp_y, sp->shp_own)); - } + shipdamage(targ, dam); + putship(targ->shp_uid, targ); - return 1; + if (mchr[(int)sp->shp_type].m_flags & M_SUB) + nreport(targ->shp_own, N_TORP_SHIP, 0, 1); + else + nreport(targ->shp_own, N_SHIP_TORP, player->cnum, 1); + } else { + pr("Missed!\n"); + if (sp->shp_own != 0) + wu(0, sp->shp_own, + "%s missed %s with a torp at %s\n", + prship(sp), prsub(targ), + xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + } + + return 1; } s_char * prsub(struct shpstr *sp) { - if (mchr[(int)sp->shp_type].m_flags & M_SUB) - return "sub"; - else - return prship(sp); + if (mchr[(int)sp->shp_type].m_flags & M_SUB) + return "sub"; + else + return prship(sp); } diff --git a/src/lib/commands/trad.c b/src/lib/commands/trad.c index 920493307..0a0603379 100644 --- a/src/lib/commands/trad.c +++ b/src/lib/commands/trad.c @@ -65,44 +65,44 @@ extern int TRADE_DELAY; int trad(void) { - struct sctstr sect; - struct natstr *natp; - struct comstr comt; - int lotno; - float price; - coord sx, sy; - int n; - char *p; - struct nstr_item ni; - struct trdstr trade; - struct trdstr tmpt; - union trdgenstr tg; - int plflags; - extern double tradetax; - extern double buytax; - double canspend; - time_t now; - int bid; - double tleft; + struct sctstr sect; + struct natstr *natp; + struct comstr comt; + int lotno; + float price; + coord sx, sy; + int n; + char *p; + struct nstr_item ni; + struct trdstr trade; + struct trdstr tmpt; + union trdgenstr tg; + int plflags; + extern double tradetax; + extern double buytax; + double canspend; + time_t now; + int bid; + double tleft; double tally; int q; s_char buf[1024]; - - + + if (!opt_MARKET) { pr("The market is disabled.\n"); return RET_FAIL; - } + } /* First, we execute all trades, so that we can only buy what is available. */ check_market(); check_trade(); - + pr("\n Empire Trade Report\n "); prdate(); n = 0; pr(" lot high bid by time left owner description\n"); - pr(" --- -------- -- --------- ----- -------------------------\n"); - + pr(" --- -------- -- --------- ----- -------------------------\n"); + snxtitem_all(&ni, EF_TRADE); while (nxtitem(&ni, (char *)&trade)) { if (trade.trd_unitid < 0) @@ -112,17 +112,19 @@ trad(void) }; /* fix up database if things get weird */ /*if (trade.trd_owner != tg.gen.trg_own) { - trade.trd_unitid = -1; - (void) puttrade(ni.cur, &trade); - continue; - }*/ + trade.trd_unitid = -1; + (void) puttrade(ni.cur, &trade); + continue; + } */ pr(" %3d ", ni.cur); - (void) time(&now); - tleft = TRADE_DELAY/3600.0 - (now - trade.trd_markettime) / 3600.0; - if (tleft < 0.0) tleft = 0.0; - pr("$%7d %2d %5.2f hrs ",trade.trd_maxprice, + (void)time(&now); + tleft = + TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0; + if (tleft < 0.0) + tleft = 0.0; + pr("$%7d %2d %5.2f hrs ", trade.trd_maxprice, trade.trd_maxbidder, tleft); - (void) trade_desc(&trade, &tg); /* XXX */ + (void)trade_desc(&trade, &tg); /* XXX */ pr("\n"); if (trade.trd_owner == player->cnum && !player->god) pr(" (your own lot)\n"); @@ -160,13 +162,13 @@ trad(void) } switch (trade.trd_type) { case EF_NUKE: - /* - if (!getsect(tg.gen.trg_x, tg.gen.trg_y, §)) { - return RET_FAIL; - } - trade.trd_owner = sect.sct_own; - break; - */ + /* + if (!getsect(tg.gen.trg_x, tg.gen.trg_y, §)) { + return RET_FAIL; + } + trade.trd_owner = sect.sct_own; + break; + */ case EF_PLANE: case EF_SHIP: case EF_LAND: @@ -188,15 +190,13 @@ trad(void) tally = 0.0; for (q = 0; gettrade(q, &tmpt); q++) { if (tmpt.trd_maxbidder == player->cnum && - tmpt.trd_unitid >= 0 && - tmpt.trd_owner != player->cnum) { + tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) { tally += tmpt.trd_maxprice * tradetax; } } for (q = 0; getcomm(q, &comt); q++) { if (comt.com_maxbidder == player->cnum && - comt.com_owner != 0 && - comt.com_owner != player->cnum) { + comt.com_owner != 0 && comt.com_owner != player->cnum) { tally += (comt.com_maxprice * comt.com_amount) * buytax; } } @@ -217,8 +217,7 @@ trad(void) if (p == 0) { return RET_FAIL; } - if (!sarg_xy(p, &sx, &sy) || - !getsect(sx, sy, §)) { + if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, §)) { pr("Bad sector designation; try again!\n"); continue; } @@ -228,20 +227,18 @@ trad(void) } if (!(plflags & (P_V | P_O))) { if (!player->god && (sect.sct_type != SCT_AIRPT)) { - pr( - "Destination sector is not an airfield!\n"); + pr("Destination sector is not an airfield!\n"); continue; } - if (!player->god && (sect.sct_effic < 60)) { - pr( - "That airport still under construction!\n"); + if (!player->god && (sect.sct_effic < 60)) { + pr("That airport still under construction!\n"); continue; } } break; } } - if (trade.trd_type == EF_LAND){ + if (trade.trd_type == EF_LAND) { while (1) { p = getstring("Destination sector: ", buf); if (!trade_check_ok(lotno, &trade, &tg)) @@ -249,8 +246,7 @@ trad(void) if (p == 0) { return RET_FAIL; } - if (!sarg_xy(p, &sx, &sy) || - !getsect(sx, sy, §)) { + if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, §)) { pr("Bad sector designation; try again!\n"); continue; } @@ -262,20 +258,20 @@ trad(void) pr("Destination sector is not a headquarters!\n"); continue; } - if (!player->god && (sect.sct_effic < 60)) { - pr("That headquarters still under construction!\n"); + if (!player->god && (sect.sct_effic < 60)) { + pr("That headquarters still under construction!\n"); continue; } break; } } - + pr("WARNING! This market issues credit. If you make more\n"); pr(" bids than your treasury can cover at the time of sale,\n"); pr(" you can potentially go into financial ruin, and see no\n"); pr(" gains. You have been warned.\n\n"); - - if((p = getstring("How much do you bid: ", buf)) == 0 || *p == 0) + + if ((p = getstring("How much do you bid: ", buf)) == 0 || *p == 0) return RET_OK; if (!trade_check_ok(lotno, &trade, &tg)) return RET_FAIL; @@ -296,14 +292,14 @@ trad(void) trade.trd_maxbidder = player->cnum; trade.trd_x = sx; trade.trd_y = sy; - pr("Your bid on lot #%d is being considered.\n",lotno); + pr("Your bid on lot #%d is being considered.\n", lotno); if (!puttrade(lotno, &trade)) pr("Problems with the trade file. Get help\n"); } else pr("Your bid wasn't high enough (you need to bid more than someone else.)\n"); - + check_trade(); - + return RET_OK; } @@ -318,7 +314,7 @@ check_trade(void) struct lndstr land; struct natstr *natp; struct trdstr trade; - union trdgenstr tg; + union trdgenstr tg; time_t now; double subleft; double monleft; @@ -326,10 +322,10 @@ check_trade(void) float price; int saveid; struct lonstr loan; - long outstanding; /* Outstanding debt */ - long couval; /* Value of country's goods */ + long outstanding; /* Outstanding debt */ + long couval; /* Value of country's goods */ int foundloan; - + /* logerror("Checking the trades.\n");*/ for (n = 0; gettrade(n, &trade); n++) { if (trade.trd_unitid < 0) @@ -342,27 +338,29 @@ check_trade(void) continue; } if (tg.gen.trg_own != trade.trd_owner) { - logerror("SOmething weird, tg.gen.trg_own != trade.trd_owner!\n"); + logerror + ("SOmething weird, tg.gen.trg_own != trade.trd_owner!\n"); trade.trd_unitid = -1; puttrade(n, &trade); continue; } - + if (trade.trd_owner == trade.trd_maxbidder) continue; - - (void) time(&now); - tleft = TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0; + + (void)time(&now); + tleft = + TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0; if (tleft < 0.0) tleft = 0.0; if (tleft > 0.0) continue; - + saveid = trade.trd_unitid; trade.trd_unitid = -1; if (!puttrade(n, &trade)) { - logerror("Couldn't save trade after purchase; get help!\n"); - continue; + logerror("Couldn't save trade after purchase; get help!\n"); + continue; } monleft = 0; @@ -385,7 +383,8 @@ check_trade(void) /* Try to make a loan for the rest from the owner. */ if (monleft > 0 && natp->nat_money > 0) { if ((float)((float)price / (float)(price + monleft)) < 0.1) { - wu(0, trade.trd_maxbidder, "You need at least 10 percent down to purchase something on credit.\n"); + wu(0, trade.trd_maxbidder, + "You need at least 10 percent down to purchase something on credit.\n"); } else { couval = get_couval(trade.trd_maxbidder); outstanding = get_outstand(trade.trd_maxbidder); @@ -409,34 +408,46 @@ check_trade(void) loan.l_amtpaid = 0; loan.l_amtdue = monleft; time(&loan.l_lastpay); - loan.l_duedate = (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay; + loan.l_duedate = + (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay; loan.l_uid = j; if (!putloan(j, &loan)) logerror("Error writing to the loan file.\n"); else monleft = 0; - nreport(trade.trd_maxbidder,N_FIN_TROUBLE, trade.trd_owner, 1); - wu(0, trade.trd_maxbidder, "You just took loan #%d for $%.2f to cover the cost of your purchase.\n", j, (float)loan.l_amtdue); - wu(0, trade.trd_owner, "You just extended loan #%d to %s to help with the purchase cost.\n", j, cname(trade.trd_maxbidder)); + nreport(trade.trd_maxbidder, N_FIN_TROUBLE, + trade.trd_owner, 1); + wu(0, trade.trd_maxbidder, + "You just took loan #%d for $%.2f to cover the cost of your purchase.\n", + j, (float)loan.l_amtdue); + wu(0, trade.trd_owner, + "You just extended loan #%d to %s to help with the purchase cost.\n", + j, cname(trade.trd_maxbidder)); } else { - nreport(trade.trd_maxbidder,N_CREDIT_JUNK, trade.trd_owner, 1); - wu(0, trade.trd_maxbidder, "You don't have enough credit to get a loan.\n"); - wu(0, trade.trd_owner, "You just turned down a loan to %s.\n", cname(trade.trd_maxbidder)); + nreport(trade.trd_maxbidder, N_CREDIT_JUNK, + trade.trd_owner, 1); + wu(0, trade.trd_maxbidder, + "You don't have enough credit to get a loan.\n"); + wu(0, trade.trd_owner, + "You just turned down a loan to %s.\n", + cname(trade.trd_maxbidder)); } } } } if (monleft > 0) { nreport(trade.trd_maxbidder, N_WELCH_DEAL, trade.trd_owner, 1); - wu(0, trade.trd_owner, "%s tried to buy a %s #%d from you for $%.2f\n", - cname(trade.trd_maxbidder), trade_nameof(&trade, &tg), + wu(0, trade.trd_owner, + "%s tried to buy a %s #%d from you for $%.2f\n", + cname(trade.trd_maxbidder), trade_nameof(&trade, &tg), saveid, (float)(price * tradetax)); wu(0, trade.trd_owner, " but couldn't afford it.\n"); - wu(0, trade.trd_owner, " Your item was taken off the market.\n"); - wu(0, trade.trd_maxbidder, + wu(0, trade.trd_owner, + " Your item was taken off the market.\n"); + wu(0, trade.trd_maxbidder, "You tried to buy %s #%d from %s for $%.2f\n", - trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner), - (float)(price * tradetax)); + trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner), + (float)(price * tradetax)); wu(0, trade.trd_maxbidder, "but couldn't afford it.\n"); continue; } @@ -446,107 +457,113 @@ check_trade(void) we don't tax the part you have to give a loan on. */ putnat(natp); - natp = getnatp(trade.trd_owner); + natp = getnatp(trade.trd_owner); /* Make sure we subtract the extra amount */ - natp->nat_money += (roundavg(price * tradetax) - subleft); + natp->nat_money += (roundavg(price * tradetax) - subleft); putnat(natp); switch (trade.trd_type) { case EF_NUKE: - tg.nuk.nuk_x = trade.trd_x; - tg.nuk.nuk_y = trade.trd_y; - makelost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid, tg.nuk.nuk_x, tg.nuk.nuk_y); - tg.nuk.nuk_own = trade.trd_maxbidder; - makenotlost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid, tg.nuk.nuk_x, tg.nuk.nuk_y); - break; + tg.nuk.nuk_x = trade.trd_x; + tg.nuk.nuk_y = trade.trd_y; + makelost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid, tg.nuk.nuk_x, + tg.nuk.nuk_y); + tg.nuk.nuk_own = trade.trd_maxbidder; + makenotlost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid, + tg.nuk.nuk_x, tg.nuk.nuk_y); + break; case EF_PLANE: - if ((tg.pln.pln_flags & PLN_LAUNCHED) == 0) { - tg.pln.pln_x = trade.trd_x; - tg.pln.pln_y = trade.trd_y; - } - makelost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid, tg.pln.pln_x, tg.pln.pln_y); - tg.pln.pln_own = trade.trd_maxbidder; - makenotlost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid, tg.pln.pln_x, tg.pln.pln_y); - tg.pln.pln_wing = ' '; - /* no cheap version of fly */ - if (opt_MOB_ACCESS) { - tg.pln.pln_mobil = -(etu_per_update / sect_mob_neg_factor); - } else { - tg.pln.pln_mobil = 0; - } - tg.pln.pln_mission = 0; - tg.pln.pln_harden = 0; - time(&tg.pln.pln_access); - tg.pln.pln_ship = -1; - tg.pln.pln_land = -1; - break; + if ((tg.pln.pln_flags & PLN_LAUNCHED) == 0) { + tg.pln.pln_x = trade.trd_x; + tg.pln.pln_y = trade.trd_y; + } + makelost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid, + tg.pln.pln_x, tg.pln.pln_y); + tg.pln.pln_own = trade.trd_maxbidder; + makenotlost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid, + tg.pln.pln_x, tg.pln.pln_y); + tg.pln.pln_wing = ' '; + /* no cheap version of fly */ + if (opt_MOB_ACCESS) { + tg.pln.pln_mobil = -(etu_per_update / sect_mob_neg_factor); + } else { + tg.pln.pln_mobil = 0; + } + tg.pln.pln_mission = 0; + tg.pln.pln_harden = 0; + time(&tg.pln.pln_access); + tg.pln.pln_ship = -1; + tg.pln.pln_land = -1; + break; case EF_SHIP: - takeover_ship(&tg.shp, trade.trd_maxbidder, 0); - break; - case EF_LAND: - tg.lnd.lnd_x = trade.trd_x; - tg.lnd.lnd_y = trade.trd_y; - if (tg.lnd.lnd_ship >= 0){ - struct shpstr ship; - getship(tg.lnd.lnd_ship, &ship); - ship.shp_nland--; - putship(ship.shp_uid,&ship); - } - makelost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid, tg.lnd.lnd_x, tg.lnd.lnd_y); - tg.lnd.lnd_own = trade.trd_maxbidder; - makenotlost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid, tg.lnd.lnd_x, tg.lnd.lnd_y); - tg.lnd.lnd_army = ' '; - /* no cheap version of fly */ - if (opt_MOB_ACCESS) { - tg.lnd.lnd_mobil = -(etu_per_update / sect_mob_neg_factor); - } else { - tg.lnd.lnd_mobil = 0; - } - tg.lnd.lnd_harden = 0; - time(&tg.lnd.lnd_access); - tg.lnd.lnd_mission = 0; - /* Drop any land units this unit was carrying */ - snxtitem_xy(&ni, EF_LAND, tg.lnd.lnd_x, tg.lnd.lnd_y); - while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_land != tg.lnd.lnd_uid) - continue; - land.lnd_land = -1; - wu(0, land.lnd_own, "unit #%d dropped in %s\n", - land.lnd_uid, - xyas(land.lnd_x, land.lnd_y, land.lnd_own)); - putland(land.lnd_uid, &land); - } - /* Drop any planes this unit was carrying */ - snxtitem_xy(&ni, EF_PLANE, tg.lnd.lnd_x, tg.lnd.lnd_y); - while (nxtitem(&ni, (s_char *)&plane)) { - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_land != land.lnd_uid) - continue; - plane.pln_land = -1; - wu(0, plane.pln_own, "plane #%d dropped in %s\n", - plane.pln_uid, - xyas(plane.pln_x, plane.pln_y, plane.pln_own)); - putplane(plane.pln_uid, &plane); - } - tg.lnd.lnd_ship = -1; - tg.lnd.lnd_land = -1; - break; + takeover_ship(&tg.shp, trade.trd_maxbidder, 0); + break; + case EF_LAND: + tg.lnd.lnd_x = trade.trd_x; + tg.lnd.lnd_y = trade.trd_y; + if (tg.lnd.lnd_ship >= 0) { + struct shpstr ship; + getship(tg.lnd.lnd_ship, &ship); + ship.shp_nland--; + putship(ship.shp_uid, &ship); + } + makelost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid, tg.lnd.lnd_x, + tg.lnd.lnd_y); + tg.lnd.lnd_own = trade.trd_maxbidder; + makenotlost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid, + tg.lnd.lnd_x, tg.lnd.lnd_y); + tg.lnd.lnd_army = ' '; + /* no cheap version of fly */ + if (opt_MOB_ACCESS) { + tg.lnd.lnd_mobil = -(etu_per_update / sect_mob_neg_factor); + } else { + tg.lnd.lnd_mobil = 0; + } + tg.lnd.lnd_harden = 0; + time(&tg.lnd.lnd_access); + tg.lnd.lnd_mission = 0; + /* Drop any land units this unit was carrying */ + snxtitem_xy(&ni, EF_LAND, tg.lnd.lnd_x, tg.lnd.lnd_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_land != tg.lnd.lnd_uid) + continue; + land.lnd_land = -1; + wu(0, land.lnd_own, "unit #%d dropped in %s\n", + land.lnd_uid, + xyas(land.lnd_x, land.lnd_y, land.lnd_own)); + putland(land.lnd_uid, &land); + } + /* Drop any planes this unit was carrying */ + snxtitem_xy(&ni, EF_PLANE, tg.lnd.lnd_x, tg.lnd.lnd_y); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_flags & PLN_LAUNCHED) + continue; + if (plane.pln_land != land.lnd_uid) + continue; + plane.pln_land = -1; + wu(0, plane.pln_own, "plane #%d dropped in %s\n", + plane.pln_uid, + xyas(plane.pln_x, plane.pln_y, plane.pln_own)); + putplane(plane.pln_uid, &plane); + } + tg.lnd.lnd_ship = -1; + tg.lnd.lnd_land = -1; + break; default: - logerror("Bad trade type %d in trade\n", trade.trd_type); - break; + logerror("Bad trade type %d in trade\n", trade.trd_type); + break; } if (!ef_write(trade.trd_type, saveid, (char *)&tg)) { - logerror("Couldn't write unit to disk; seek help.\n"); - continue; + logerror("Couldn't write unit to disk; seek help.\n"); + continue; } nreport(trade.trd_owner, N_MAKE_SALE, trade.trd_maxbidder, 1); wu(0, trade.trd_owner, "%s bought a %s #%d from you for $%.2f\n", - cname(trade.trd_maxbidder), trade_nameof(&trade, &tg), - saveid, (float)(price * tradetax)); - wu(0, trade.trd_maxbidder, - "The bidding is over & you bought %s #%d from %s for $%.2f\n", - trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner), - (float)price); + cname(trade.trd_maxbidder), trade_nameof(&trade, &tg), + saveid, (float)(price * tradetax)); + wu(0, trade.trd_maxbidder, + "The bidding is over & you bought %s #%d from %s for $%.2f\n", + trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner), + (float)price); } /* logerror("Done checking the trades.\n");*/ return RET_OK; @@ -554,7 +571,7 @@ check_trade(void) int ontradingblock(int type, int *ptr) - /* Generic pointer */ + /* Generic pointer */ { struct trdstr trade; union trdgenstr tg; @@ -567,7 +584,7 @@ ontradingblock(int type, int *ptr) continue; if (trade.trd_type != type) continue; - if (tg.gen.trg_uid == ((struct genstr *)ptr)->trg_uid) + if (tg.gen.trg_uid == ((struct genstr *)ptr)->trg_uid) return 1; } return 0; @@ -575,7 +592,7 @@ ontradingblock(int type, int *ptr) void trdswitchown(int type, int *ptr, int newown) - /* Generic pointer */ + /* Generic pointer */ { struct trdstr trade; union trdgenstr tg; @@ -588,7 +605,7 @@ trdswitchown(int type, int *ptr, int newown) continue; if (trade.trd_type != type) continue; - if (tg.gen.trg_uid != ((struct genstr *)ptr)->trg_uid) + if (tg.gen.trg_uid != ((struct genstr *)ptr)->trg_uid) continue; if (trade.trd_owner == trade.trd_maxbidder) trade.trd_maxbidder = newown; diff --git a/src/lib/commands/tran.c b/src/lib/commands/tran.c index 8baaa09dd..80ca0ed6c 100644 --- a/src/lib/commands/tran.c +++ b/src/lib/commands/tran.c @@ -51,24 +51,25 @@ #include -static int tran_map(s_char *what, coord curx, coord cury, s_char *arg); -static int tran_nuke(void); -static int tran_plane(void); +static int tran_map(s_char *what, coord curx, coord cury, s_char *arg); +static int tran_nuke(void); +static int tran_plane(void); int tran(void) { - s_char *what; - s_char buf[1024]; + s_char *what; + s_char buf[1024]; - what = getstarg(player->argp[1], "transport what (nuke or plane): ", buf); - if (what == 0) - return RET_SYN; - if (*what == 'n') - return tran_nuke(); - else if (*what == 'p') - return tran_plane(); + what = + getstarg(player->argp[1], "transport what (nuke or plane): ", buf); + if (what == 0) return RET_SYN; + if (*what == 'n') + return tran_nuke(); + else if (*what == 'p') + return tran_plane(); + return RET_SYN; } /* @@ -78,254 +79,250 @@ tran(void) static int tran_nuke(void) { - struct nchrstr *ncp; - int len; - coord x, y; - coord dstx, dsty; - int found; - s_char *p; - int i; - int nuketype; - int moving; - struct nukstr nuke; - struct sctstr sect; - struct sctstr endsect; - int mcost, dam; - struct nstr_item nstr; - s_char buf[1024]; + struct nchrstr *ncp; + int len; + coord x, y; + coord dstx, dsty; + int found; + s_char *p; + int i; + int nuketype; + int moving; + struct nukstr nuke; + struct sctstr sect; + struct sctstr endsect; + int mcost, dam; + struct nstr_item nstr; + s_char buf[1024]; - if (!(p = getstarg(player->argp[2], "from sector : ", buf))) - return RET_SYN; - if (!sarg_xy(p, &x, &y)) - return RET_SYN; - if (!getsect(x, y, §) || !player->owner) { - pr("Not yours\n"); - return RET_FAIL; - } + if (!(p = getstarg(player->argp[2], "from sector : ", buf))) + return RET_SYN; + if (!sarg_xy(p, &x, &y)) + return RET_SYN; + if (!getsect(x, y, §) || !player->owner) { + pr("Not yours\n"); + return RET_FAIL; + } #if 0 - if (!snxtitem_xy(&nstr,EF_NUKE,sect.sct_x,sect.sct_y)) { - pr("There are no nukes in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_FAIL; - } + if (!snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y)) { + pr("There are no nukes in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_FAIL; + } #else - snxtitem_xy(&nstr,EF_NUKE,sect.sct_x,sect.sct_y); + snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y); #endif - found = 0; - while (nxtitem(&nstr, (caddr_t)&nuke)) { - if (player->owner) { - found = 1; - break; - } + found = 0; + while (nxtitem(&nstr, (caddr_t)&nuke)) { + if (player->owner) { + found = 1; + break; } - if (!found) { - pr("There are no nukes in %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_FAIL; - } - if (!(p = getstarg(player->argp[3], "warhead type : ", buf))) - return RET_SYN; - if (!check_sect_ok(§)) + } + if (!found) { + pr("There are no nukes in %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_FAIL; + } + if (!(p = getstarg(player->argp[3], "warhead type : ", buf))) + return RET_SYN; + if (!check_sect_ok(§)) + return RET_FAIL; + len = strlen(p); + for (i = 0, ncp = nchr; i < N_MAXNUKE; i++, ncp++) { + if (strncmp(ncp->n_name, p, len) == 0) + break; + } + if (i >= N_MAXNUKE) { + pr("No such nuke type!\n"); + return RET_SYN; + } + nuketype = i; + if (!nuke.nuk_types[nuketype]) { + pr("No %s nukes in %s\n", + ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum)); + return RET_FAIL; + } + p = getstarg(player->argp[4], "number of warheads : ", buf); + if (!check_sect_ok(§)) + return RET_FAIL; + if (p == 0 || *p == 0 || (moving = atoi(p)) < 0) + return RET_FAIL; + if (moving > nuke.nuk_types[nuketype]) { + moving = nuke.nuk_types[nuketype]; + if (moving) + pr("only moving %d\n", moving); + else return RET_FAIL; - len = strlen(p); - for (i=0, ncp = nchr; in_name, p, len) == 0) - break; - } - if (i >= N_MAXNUKE) { - pr("No such nuke type!\n"); - return RET_SYN; + } + /* + * military control necessary to move + * goodies in occupied territory. + */ + if (sect.sct_oldown != player->cnum) { + int tot_mil = 0; + struct nstr_item ni; + struct lndstr land; + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == player->cnum) + tot_mil += total_mil(&land); } - nuketype = i; - if (!nuke.nuk_types[nuketype]) { - pr("No %s nukes in %s\n", - ncp->n_name, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - return RET_FAIL; - } - p = getstarg(player->argp[4], "number of warheads : ", buf); - if (!check_sect_ok(§)) + if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10 + < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) { + pr("Military control required to move goods.\n"); return RET_FAIL; - if (p == 0 || *p == 0 || (moving = atoi(p)) < 0) - return RET_FAIL; - if (moving > nuke.nuk_types[nuketype]) { - moving = nuke.nuk_types[nuketype]; - if (moving) - pr("only moving %d\n", moving); - else - return RET_FAIL; - } - /* - * military control necessary to move - * goodies in occupied territory. - */ - if (sect.sct_oldown != player->cnum){ - int tot_mil=0; - struct nstr_item ni; - struct lndstr land; - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == player->cnum) - tot_mil += total_mil(&land); - } - if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR)+tot_mil) * 10 - < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) { - pr("Military control required to move goods.\n"); - return RET_FAIL; - } } - dam = 0; - mcost = move_ground((s_char *)&nuke, §, &endsect, - (double)sect.sct_mobil, - (double) ncp->n_weight * moving, - player->argp[5], tran_map, 0, &dam); + } + dam = 0; + mcost = move_ground((s_char *)&nuke, §, &endsect, + (double)sect.sct_mobil, + (double)ncp->n_weight * moving, + player->argp[5], tran_map, 0, &dam); - if (mcost < 0) - return 0; + if (mcost < 0) + return 0; - if (mcost > 0) - pr("Total movement cost = %d\n",mcost); - else - pr("No mobility used\n"); + if (mcost > 0) + pr("Total movement cost = %d\n", mcost); + else + pr("No mobility used\n"); - dstx = endsect.sct_x; - dsty = endsect.sct_y; - /* - * decrement mobility from src sector - */ - getsect(nuke.nuk_x, nuke.nuk_y, §); - sect.sct_mobil -= mcost; - if (sect.sct_mobil < 0) - sect.sct_mobil = 0; - putsect(§); - /* - * update old nuke - */ - if (!getnuke(nuke.nuk_uid, &nuke)) { - pr("Could not find that stockpile again.\n"); - return RET_FAIL; - } - if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) { - pr("Stockpile changed!\n"); - return RET_FAIL; - } - nuk_delete(&nuke, nuketype, moving); - nuk_add(dstx, dsty, nuketype, moving); - return RET_OK; + dstx = endsect.sct_x; + dsty = endsect.sct_y; + /* + * decrement mobility from src sector + */ + getsect(nuke.nuk_x, nuke.nuk_y, §); + sect.sct_mobil -= mcost; + if (sect.sct_mobil < 0) + sect.sct_mobil = 0; + putsect(§); + /* + * update old nuke + */ + if (!getnuke(nuke.nuk_uid, &nuke)) { + pr("Could not find that stockpile again.\n"); + return RET_FAIL; + } + if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) { + pr("Stockpile changed!\n"); + return RET_FAIL; + } + nuk_delete(&nuke, nuketype, moving); + nuk_add(dstx, dsty, nuketype, moving); + return RET_OK; } static int tran_plane(void) { - int srcx, srcy; - int dstx, dsty; - int mcost; - int weight, count; - int first; - int type, dam; - struct nstr_item nstr; - struct plnstr plane; - struct sctstr sect; - struct sctstr endsect; + int srcx, srcy; + int dstx, dsty; + int mcost; + int weight, count; + int first; + int type, dam; + struct nstr_item nstr; + struct plnstr plane; + struct sctstr sect; + struct sctstr endsect; - first = 1; - weight = 0; - count = 0; - if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) - return RET_SYN; - /* - * First do some sanity checks: make sure that they are all in the, - * same sector, not on ships, owned, etc. - * No one could seriously want to move planes in parallel from - * several sectors! - */ - while (nxtitem(&nstr, (s_char *)&plane)) { - if (!player->owner) - continue; - type = plane.pln_type; - if (plane.pln_ship >= 0) { - pr("%s is at sea and can't be transported\n", - prplane(&plane)); - return RET_FAIL; - } else if (plane.pln_harden != 0) { - pr("%s has been hardened and can't be transported\n", - prplane(&plane)); - return RET_FAIL; - } else if ((plane.pln_flags & PLN_LAUNCHED) && - (plchr[type].pl_flags & P_O)) { - pr("%s is in space and can't be transported\n", - prplane(&plane)); - return RET_FAIL; - } - if (first == 1) { - srcx = plane.pln_x; - srcy = plane.pln_y; - first = 0; - } else { - if (plane.pln_x != srcx || plane.pln_y != srcy) { - pr("All planes must be in the same sector.\n"); - return RET_FAIL; - } - } - weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2); - ++count; + first = 1; + weight = 0; + count = 0; + if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) + return RET_SYN; + /* + * First do some sanity checks: make sure that they are all in the, + * same sector, not on ships, owned, etc. + * No one could seriously want to move planes in parallel from + * several sectors! + */ + while (nxtitem(&nstr, (s_char *)&plane)) { + if (!player->owner) + continue; + type = plane.pln_type; + if (plane.pln_ship >= 0) { + pr("%s is at sea and can't be transported\n", prplane(&plane)); + return RET_FAIL; + } else if (plane.pln_harden != 0) { + pr("%s has been hardened and can't be transported\n", + prplane(&plane)); + return RET_FAIL; + } else if ((plane.pln_flags & PLN_LAUNCHED) && + (plchr[type].pl_flags & P_O)) { + pr("%s is in space and can't be transported\n", + prplane(&plane)); + return RET_FAIL; } if (first == 1) { - /* no planes */ + srcx = plane.pln_x; + srcy = plane.pln_y; + first = 0; + } else { + if (plane.pln_x != srcx || plane.pln_y != srcy) { + pr("All planes must be in the same sector.\n"); return RET_FAIL; + } } - getsect(srcx, srcy, §); - /* - * military control necessary to move - * goodies in occupied territory. - */ - if (sect.sct_oldown != player->cnum){ - int tot_mil=0; - struct nstr_item ni; - struct lndstr land; - snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); - while (nxtitem(&ni, (s_char *)&land)) - tot_mil += total_mil(&land); - if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR)+tot_mil) * 10 - < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) { - pr("Military control required to move goods.\n"); - return RET_FAIL; - } + weight += plchr[type].pl_lcm + (plchr[type].pl_hcm * 2); + ++count; + } + if (first == 1) { + /* no planes */ + return RET_FAIL; + } + getsect(srcx, srcy, §); + /* + * military control necessary to move + * goodies in occupied territory. + */ + if (sect.sct_oldown != player->cnum) { + int tot_mil = 0; + struct nstr_item ni; + struct lndstr land; + snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y); + while (nxtitem(&ni, (s_char *)&land)) + tot_mil += total_mil(&land); + if ((getvar(V_MILIT, (s_char *)§, EF_SECTOR) + tot_mil) * 10 + < getvar(V_CIVIL, (s_char *)§, EF_SECTOR)) { + pr("Military control required to move goods.\n"); + return RET_FAIL; } - dam = 1; - mcost = move_ground((s_char *)&plane, §, &endsect, - (double)sect.sct_mobil, (double)weight, - player->argp[3], tran_map, 0, &dam); - dam /= count; - if (mcost < 0) - return 0; + } + dam = 1; + mcost = move_ground((s_char *)&plane, §, &endsect, + (double)sect.sct_mobil, (double)weight, + player->argp[3], tran_map, 0, &dam); + dam /= count; + if (mcost < 0) + return 0; - dstx = endsect.sct_x; - dsty = endsect.sct_y; - snxtitem_rewind(&nstr); - while (nxtitem(&nstr, (s_char *)&plane)) { - if (!player->owner) - continue; - if (dam) { - planedamage(&plane,dam); - pr("\t%s takes %d\n", - prplane(&plane), - dam); - } - plane.pln_x = dstx; - plane.pln_y = dsty; - plane.pln_mission = 0; - putplane(plane.pln_uid, &plane); + dstx = endsect.sct_x; + dsty = endsect.sct_y; + snxtitem_rewind(&nstr); + while (nxtitem(&nstr, (s_char *)&plane)) { + if (!player->owner) + continue; + if (dam) { + planedamage(&plane, dam); + pr("\t%s takes %d\n", prplane(&plane), dam); } - if (mcost > 0) - pr("Total movement cost = %d\n",mcost); - else - pr("No mobility used\n"); - sect.sct_mobil -= mcost; - if (sect.sct_mobil < 0) - sect.sct_mobil = 0; - putsect(§); - return RET_OK; + plane.pln_x = dstx; + plane.pln_y = dsty; + plane.pln_mission = 0; + putplane(plane.pln_uid, &plane); + } + if (mcost > 0) + pr("Total movement cost = %d\n", mcost); + else + pr("No mobility used\n"); + sect.sct_mobil -= mcost; + if (sect.sct_mobil < 0) + sect.sct_mobil = 0; + putsect(§); + return RET_OK; } /* @@ -338,7 +335,7 @@ tran_plane(void) static int tran_map(s_char *what, coord curx, coord cury, s_char *arg) { - player->argp[1] = arg; - player->condarg = 0; - return map(); + player->argp[1] = arg; + player->condarg = 0; + return map(); } diff --git a/src/lib/commands/trea.c b/src/lib/commands/trea.c index 3d45b8767..1b1e1a97c 100644 --- a/src/lib/commands/trea.c +++ b/src/lib/commands/trea.c @@ -43,21 +43,21 @@ int trea(void) { - struct trtstr treaty; - struct nstr_item nstr; - int ntreaty; + struct trtstr treaty; + struct nstr_item nstr; + int ntreaty; - if (!snxtitem(&nstr, EF_TREATY, player->argp[1])) - return RET_SYN; - pr("\t... %s Treaty Report ...\n", cname(player->cnum)); - ntreaty = 0; - while (nxtitem(&nstr, (s_char *)&treaty)) { - if (distrea(nstr.cur, &treaty) > 0) - ntreaty++; - } - if (!ntreaty) - pr("No treaties found.\n"); - else - pr("%d treat%s\n", ntreaty, iesplur(ntreaty)); - return RET_OK; + if (!snxtitem(&nstr, EF_TREATY, player->argp[1])) + return RET_SYN; + pr("\t... %s Treaty Report ...\n", cname(player->cnum)); + ntreaty = 0; + while (nxtitem(&nstr, (s_char *)&treaty)) { + if (distrea(nstr.cur, &treaty) > 0) + ntreaty++; + } + if (!ntreaty) + pr("No treaties found.\n"); + else + pr("%d treat%s\n", ntreaty, iesplur(ntreaty)); + return RET_OK; } diff --git a/src/lib/commands/turn.c b/src/lib/commands/turn.c index 90fc698ed..158f5c178 100644 --- a/src/lib/commands/turn.c +++ b/src/lib/commands/turn.c @@ -41,49 +41,49 @@ int turn(void) { - extern s_char *upfil; - extern s_char *downfil; - int fd; - struct telstr tgm; - register s_char *p; - s_char buf[MAXTELSIZE]; + extern s_char *upfil; + extern s_char *downfil; + int fd; + struct telstr tgm; + register s_char *p; + s_char buf[MAXTELSIZE]; - p = getstarg(player->argp[1], "on, off or message? ", buf); - if (!p) - return RET_SYN; - if (strcmp(p, "off") == 0) { - (void) unlink(upfil); + p = getstarg(player->argp[1], "on, off or message? ", buf); + if (!p) + return RET_SYN; + if (strcmp(p, "off") == 0) { + (void)unlink(upfil); #if !defined(_WIN32) - fd = open(downfil, O_RDWR|O_CREAT|O_TRUNC, 0660); + fd = open(downfil, O_RDWR | O_CREAT | O_TRUNC, 0660); #else - fd = open(downfil, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0660); + fd = open(downfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660); #endif - pr("off "); - } else if (strcmp(p, "on") == 0) { - (void) unlink(downfil); + pr("off "); + } else if (strcmp(p, "on") == 0) { + (void)unlink(downfil); #if !defined(_WIN32) - fd = open(upfil, O_RDWR|O_CREAT|O_TRUNC, 0660); + fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC, 0660); #else - fd = open(upfil, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0660); + fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660); #endif - pr("on "); - } else { + pr("on "); + } else { #if !defined(_WIN32) - fd = open(upfil, O_RDWR|O_CREAT|O_TRUNC, 0660); + fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC, 0660); #else - fd = open(upfil, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0660); + fd = open(upfil, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660); #endif - pr("motd "); - } - (void) time(&tgm.tel_date); - if ((tgm.tel_length = getele("The World", buf)) <= 0) { - pr("Ignored\n"); - close(fd); - return RET_SYN; - } - (void) write(fd, (s_char *)&tgm, sizeof (tgm)); - (void) write(fd, buf, tgm.tel_length); - (void) close(fd); - pr("\n"); - return RET_OK; + pr("motd "); + } + (void)time(&tgm.tel_date); + if ((tgm.tel_length = getele("The World", buf)) <= 0) { + pr("Ignored\n"); + close(fd); + return RET_SYN; + } + (void)write(fd, (s_char *)&tgm, sizeof(tgm)); + (void)write(fd, buf, tgm.tel_length); + (void)close(fd); + pr("\n"); + return RET_OK; } diff --git a/src/lib/commands/upda.c b/src/lib/commands/upda.c index a381af8b3..beca583c1 100644 --- a/src/lib/commands/upda.c +++ b/src/lib/commands/upda.c @@ -48,140 +48,141 @@ int upda(void) { - FILE *fp; - struct mob_acc_globals timestamps; - extern int updating_mob; - extern int update_window; - extern s_char *timestampfil; + FILE *fp; + struct mob_acc_globals timestamps; + extern int updating_mob; + extern int update_window; + extern s_char *timestampfil; if (opt_MOB_ACCESS) { #if !defined(_WIN32) - if ((fp = fopen(timestampfil, "r")) == NULL) { + if ((fp = fopen(timestampfil, "r")) == NULL) { #else - if ((fp = fopen(timestampfil, "rb")) == NULL) { + if ((fp = fopen(timestampfil, "rb")) == NULL) { #endif - logerror("Unable to open timestamp file."); - } else { - rewind(fp); - fread(×tamps, sizeof(timestamps), 1, fp); - fclose(fp); - if (updating_mob) - pr("Mobility updating is enabled.\n\n"); - else { - pr("Mobility updating will come back on around %s", - ctime(×tamps.starttime)); - pr("game time, within 3 minutes, depending on when the server checks.\n\n"); - } - } + logerror("Unable to open timestamp file."); + } else { + rewind(fp); + fread(×tamps, sizeof(timestamps), 1, fp); + fclose(fp); + if (updating_mob) + pr("Mobility updating is enabled.\n\n"); + else { + pr("Mobility updating will come back on around %s", + ctime(×tamps.starttime)); + pr("game time, within 3 minutes, depending on when the server checks.\n\n"); + } + } + } + if (opt_UPDATESCHED) { + time_t now, next, delta; + extern int update_time; + extern int update_policy; + extern int update_demandpolicy; + extern int update_wantmin; + extern int blitz_time; + extern s_char *update_times; + extern s_char *update_demandtimes; + extern s_char *game_days; + extern s_char *game_hours; + + if (updates_disabled()) + pr("UPDATES ARE DISABLED!\n"); + + (void)time(&now); + switch (update_policy) { + case UDP_NORMAL: + next_update_time(&now, &next, &delta); + pr("\nUpdates occur at times specified by the ETU rates.\n\n"); + pr("The next update is at %19.19s.\n", ctime(&next)); + break; + case UDP_TIMES: + next_update_time(&now, &next, &delta); + pr("\nUpdates occur at scheduled times.\n\n"); + pr("The next update is at %19.19s.\n", ctime(&next)); + break; + case UDP_BLITZ: + next_update_time(&now, &next, &delta); + pr("\nBlitz Updates occur every %d minutes. \n\n", blitz_time); + pr("The next update is at %19.19s.\n", ctime(&next)); + break; + case UDP_NOREG: + pr("There are no regularly scheduled updates.\n"); + break; + default: + pr("Update policy is inconsistent.\n"); + } + pr("The current time is %19.19s.\n\n", ctime(&now)); + + if (update_window) { + now = update_time - update_window; + next_update_time(&now, &next, &delta); + pr("The next update window starts at %19.19s.\n", + ctime(&next)); + next += update_window; + pr("The next update window stops at %19.19s.\n", ctime(&next)); } - if (opt_UPDATESCHED) { - time_t now, next, delta; - extern int update_time; - extern int update_policy; - extern int update_demandpolicy; - extern int update_wantmin; - extern int blitz_time; - extern s_char *update_times; - extern s_char *update_demandtimes; - extern s_char *game_days; - extern s_char *game_hours; - - if (updates_disabled()) - pr("UPDATES ARE DISABLED!\n"); - - (void) time(&now); - switch (update_policy) { - case UDP_NORMAL: - next_update_time(&now, &next, &delta); - pr("\nUpdates occur at times specified by the ETU rates.\n\n"); - pr("The next update is at %19.19s.\n", ctime(&next)); - break; - case UDP_TIMES: - next_update_time(&now, &next, &delta); - pr("\nUpdates occur at scheduled times.\n\n"); - pr("The next update is at %19.19s.\n", ctime(&next)); - break; - case UDP_BLITZ: - next_update_time(&now, &next, &delta); - pr("\nBlitz Updates occur every %d minutes. \n\n", - blitz_time); - pr("The next update is at %19.19s.\n",ctime(&next)); - break; - case UDP_NOREG: - pr("There are no regularly scheduled updates.\n"); - break; + if (opt_DEMANDUPDATE) { + if (update_demandpolicy != UDDEM_DISABLE) { + switch (update_demandpolicy) { + case UDDEM_TMCHECK: + next_update_check_time(&now, &next, &delta); + pr("Demand updates occur at update CHECK times.\n"); + pr("The next update check is at %19.19s.\n", + ctime(&next)); + break; + case UDDEM_COMSET: + pr("Demand updates occur right after the demand is set.\n"); + break; default: - pr("Update policy is inconsistent.\n"); - } - pr("The current time is %19.19s.\n\n", ctime(&now)); - - if (update_window) { - now = update_time - update_window; - next_update_time(&now, &next, &delta); - pr("The next update window starts at %19.19s.\n",ctime(&next)); - next += update_window; - pr("The next update window stops at %19.19s.\n",ctime(&next)); - } - if (opt_DEMANDUPDATE) { - if (update_demandpolicy != UDDEM_DISABLE) { - switch (update_demandpolicy) { - case UDDEM_TMCHECK: - next_update_check_time(&now, &next, &delta); - pr("Demand updates occur at update CHECK times.\n"); - pr("The next update check is at %19.19s.\n", - ctime(&next)); - break; - case UDDEM_COMSET: - pr("Demand updates occur right after the demand is set.\n"); - break; - default: - pr("Update demand policy is inconsistent.\n"); - } - } + pr("Update demand policy is inconsistent.\n"); } - - if ((update_policy == UDP_TIMES) || - ((update_demandpolicy == UDDEM_TMCHECK) && - opt_DEMANDUPDATE)) { - if (*update_times != 0) - pr("The update schedule is: %s\n", update_times); - } - if (opt_DEMANDUPDATE) { - if (update_demandpolicy != UDDEM_DISABLE) { - if (*update_demandtimes != 0) - pr("Demand updates are allowed during: %s\n", update_demandtimes); - if (update_wantmin == 0) { - pr("Demand updates are disabled by a mininum of 0\n"); - } else { - pr("Demand updates require %d country(s) to want one.\n",update_wantmin); - } - } + } + } + + if ((update_policy == UDP_TIMES) || + ((update_demandpolicy == UDDEM_TMCHECK) && opt_DEMANDUPDATE)) { + if (*update_times != 0) + pr("The update schedule is: %s\n", update_times); + } + if (opt_DEMANDUPDATE) { + if (update_demandpolicy != UDDEM_DISABLE) { + if (*update_demandtimes != 0) + pr("Demand updates are allowed during: %s\n", + update_demandtimes); + if (update_wantmin == 0) { + pr("Demand updates are disabled by a mininum of 0\n"); + } else { + pr("Demand updates require %d country(s) to want one.\n", update_wantmin); } - if (*game_days != 0) pr("Game days are: %s\n", game_days); - if (*game_hours != 0) pr("Game hours are: %s\n", game_hours); - - return(0); + } + } + if (*game_days != 0) + pr("Game days are: %s\n", game_days); + if (*game_hours != 0) + pr("Game hours are: %s\n", game_hours); + + return (0); } else { - extern int s_p_etu; - extern int etu_per_update; - extern int adj_update; - time_t now; - time_t upd_time; - time_t next_update; - int secs_per_update; - int delta; - - (void) time(&now); - upd_time = now + adj_update; - secs_per_update = etu_per_update * s_p_etu; - delta = secs_per_update - (upd_time % secs_per_update); - next_update = now + delta; - pr("The next update is at %19.19s.\n",ctime(&next_update)); - pr("The current time is %19.19s.\n",ctime(&now)); - if (update_window) { - pr("Update times are variable, update window is +/- %d minutes %d seconds.\n", - update_window / 60, update_window % 60); - } - return 0; + extern int s_p_etu; + extern int etu_per_update; + extern int adj_update; + time_t now; + time_t upd_time; + time_t next_update; + int secs_per_update; + int delta; + + (void)time(&now); + upd_time = now + adj_update; + secs_per_update = etu_per_update * s_p_etu; + delta = secs_per_update - (upd_time % secs_per_update); + next_update = now + delta; + pr("The next update is at %19.19s.\n", ctime(&next_update)); + pr("The current time is %19.19s.\n", ctime(&now)); + if (update_window) { + pr("Update times are variable, update window is +/- %d minutes %d seconds.\n", update_window / 60, update_window % 60); + } + return 0; } } diff --git a/src/lib/commands/upgr.c b/src/lib/commands/upgr.c index 98bc4c47b..125c7daa6 100644 --- a/src/lib/commands/upgr.c +++ b/src/lib/commands/upgr.c @@ -73,314 +73,307 @@ upgr(void) int lupgr(void) { - struct sctstr sect; - struct natstr *natp; - struct nstr_item ni; - struct lndstr land; - struct lchrstr *lp; - int n; - int tlev; - int w_p_eff; - int points; - int rel; - int techdiff; - long cash; + struct sctstr sect; + struct natstr *natp; + struct nstr_item ni; + struct lndstr land; + struct lchrstr *lp; + int n; + int tlev; + int w_p_eff; + int points; + int rel; + int techdiff; + long cash; - if (!snxtitem(&ni, EF_LAND, player->argp[2])) - return RET_SYN; - ni.flags &= ~(EFF_OWNER); - natp = getnatp(player->cnum); - cash = natp->nat_money; - tlev = (int) natp->nat_level[NAT_TLEV]; - n = 0; - while (nxtitem(&ni, (s_char *) &land)) { - if (land.lnd_own == 0) - continue; - getsect(land.lnd_x, land.lnd_y, §); - if (sect.sct_own != player->cnum) - continue; - if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60) - continue; - rel=getrel(getnatp(land.lnd_own),sect.sct_own); - if ((rel < FRIENDLY) && (sect.sct_own != land.lnd_own)){ - pr("You are not on friendly terms with the owner of unit %d!\n", - land.lnd_uid); - continue; - } - n++; - lp = &lchr[(int)land.lnd_type]; - w_p_eff = ((lp->l_lcm / 2) + lp->l_hcm); - points = sect.sct_avail * 100 / w_p_eff; - if (points < 20) { - pr("Not enough available work in %s to upgrade a %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - lp->l_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20)/100); - continue; - } - if (land.lnd_effic < 60) { - pr("%s is too damaged to upgrade!\n", prland(&land)); - continue; - } - if (land.lnd_tech >= tlev) { - pr("%s tech: %d, yours is only %d\n", prland(&land), - land.lnd_tech, tlev); - continue; - } - if (lp->l_cost * .15 + player->dolcost > cash) { - pr("You don't have enough money to upgrade %s!\n", - prland(&land)); - continue; - } + if (!snxtitem(&ni, EF_LAND, player->argp[2])) + return RET_SYN; + ni.flags &= ~(EFF_OWNER); + natp = getnatp(player->cnum); + cash = natp->nat_money; + tlev = (int)natp->nat_level[NAT_TLEV]; + n = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + getsect(land.lnd_x, land.lnd_y, §); + if (sect.sct_own != player->cnum) + continue; + if (sect.sct_type != SCT_HEADQ || sect.sct_effic < 60) + continue; + rel = getrel(getnatp(land.lnd_own), sect.sct_own); + if ((rel < FRIENDLY) && (sect.sct_own != land.lnd_own)) { + pr("You are not on friendly terms with the owner of unit %d!\n", land.lnd_uid); + continue; + } + n++; + lp = &lchr[(int)land.lnd_type]; + w_p_eff = ((lp->l_lcm / 2) + lp->l_hcm); + points = sect.sct_avail * 100 / w_p_eff; + if (points < 20) { + pr("Not enough available work in %s to upgrade a %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), lp->l_name); + pr(" (%d available work required)\n", + 1 + (w_p_eff * 20) / 100); + continue; + } + if (land.lnd_effic < 60) { + pr("%s is too damaged to upgrade!\n", prland(&land)); + continue; + } + if (land.lnd_tech >= tlev) { + pr("%s tech: %d, yours is only %d\n", prland(&land), + land.lnd_tech, tlev); + continue; + } + if (lp->l_cost * .15 + player->dolcost > cash) { + pr("You don't have enough money to upgrade %s!\n", + prland(&land)); + continue; + } - sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; - land.lnd_effic -= 35; + sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; + land.lnd_effic -= 35; - land.lnd_tech = tlev; - techdiff = (int)(tlev - lp->l_tech); + land.lnd_tech = tlev; + techdiff = (int)(tlev - lp->l_tech); - land.lnd_harden = 0; - land.lnd_mission = 0; + land.lnd_harden = 0; + land.lnd_mission = 0; - land.lnd_att = (float)LND_ATTDEF(lp->l_att, techdiff); - land.lnd_def = (float)LND_ATTDEF(lp->l_def, techdiff); - land.lnd_vul = (int)LND_VUL(lp->l_vul, techdiff); - land.lnd_spd = (int)LND_SPD(lp->l_spd, techdiff); - land.lnd_vis = (int)LND_VIS(lp->l_vis, techdiff); - land.lnd_spy = (int)LND_SPY(lp->l_spy, techdiff); - land.lnd_rad = (int)LND_RAD(lp->l_rad, techdiff); - land.lnd_frg = (int)LND_FRG(lp->l_frg, techdiff); - land.lnd_acc = (int)LND_ACC(lp->l_acc, techdiff); - land.lnd_dam = (int)LND_DAM(lp->l_dam, techdiff); - land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, techdiff); - land.lnd_aaf = (int)LND_AAF(lp->l_aaf, techdiff); - land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, techdiff); - land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, techdiff); - land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, techdiff); - land.lnd_maxland = (int)LND_MXL(lp->l_mxland, techdiff); - - time(&land.lnd_access); + land.lnd_att = (float)LND_ATTDEF(lp->l_att, techdiff); + land.lnd_def = (float)LND_ATTDEF(lp->l_def, techdiff); + land.lnd_vul = (int)LND_VUL(lp->l_vul, techdiff); + land.lnd_spd = (int)LND_SPD(lp->l_spd, techdiff); + land.lnd_vis = (int)LND_VIS(lp->l_vis, techdiff); + land.lnd_spy = (int)LND_SPY(lp->l_spy, techdiff); + land.lnd_rad = (int)LND_RAD(lp->l_rad, techdiff); + land.lnd_frg = (int)LND_FRG(lp->l_frg, techdiff); + land.lnd_acc = (int)LND_ACC(lp->l_acc, techdiff); + land.lnd_dam = (int)LND_DAM(lp->l_dam, techdiff); + land.lnd_ammo = (int)LND_AMM(lp->l_ammo, lp->l_dam, techdiff); + land.lnd_aaf = (int)LND_AAF(lp->l_aaf, techdiff); + land.lnd_fuelc = (int)LND_FC(lp->l_fuelc, techdiff); + land.lnd_fuelu = (int)LND_FU(lp->l_fuelu, techdiff); + land.lnd_maxlight = (int)LND_XPL(lp->l_nxlight, techdiff); + land.lnd_maxland = (int)LND_MXL(lp->l_mxland, techdiff); - putland(land.lnd_uid, &land); - putsect(§); - player->dolcost += (double) lp->l_cost * .15; - pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land), - land.lnd_tech, - (int)(lp->l_cost * .15)); - if (land.lnd_own != player->cnum) - wu(0,land.lnd_own,"%s upgraded by %s to tech %d, at a cost of %d\n", prland(&land), - cname(player->cnum), - land.lnd_tech, (int)(lp->l_cost * .15)); - } - if (n == 0) { - pr("No land units\n"); - return RET_SYN; - } - return RET_OK; + time(&land.lnd_access); + + putland(land.lnd_uid, &land); + putsect(§); + player->dolcost += (double)lp->l_cost * .15; + pr("%s upgraded to tech %d, at a cost of %d\n", prland(&land), + land.lnd_tech, (int)(lp->l_cost * .15)); + if (land.lnd_own != player->cnum) + wu(0, land.lnd_own, + "%s upgraded by %s to tech %d, at a cost of %d\n", + prland(&land), cname(player->cnum), land.lnd_tech, + (int)(lp->l_cost * .15)); + } + if (n == 0) { + pr("No land units\n"); + return RET_SYN; + } + return RET_OK; } int supgr(void) { - struct sctstr sect; - struct natstr *natp; - struct nstr_item ni; - struct shpstr ship; - struct mchrstr *mp; - int n; - int tlev; - int w_p_eff; - int points; - int rel; - int techdiff; - long cash; + struct sctstr sect; + struct natstr *natp; + struct nstr_item ni; + struct shpstr ship; + struct mchrstr *mp; + int n; + int tlev; + int w_p_eff; + int points; + int rel; + int techdiff; + long cash; - if (!snxtitem(&ni, EF_SHIP, player->argp[2])) - return RET_SYN; - ni.flags &= ~(EFF_OWNER); - natp = getnatp(player->cnum); - cash = natp->nat_money; - tlev = (int) natp->nat_level[NAT_TLEV]; - n = 0; - while (nxtitem(&ni, (s_char *) &ship)) { - if (ship.shp_own == 0) - continue; - getsect(ship.shp_x, ship.shp_y, §); - if (sect.sct_own != player->cnum) - continue; - if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60) - continue; - rel=getrel(getnatp(ship.shp_own),sect.sct_own); - if ((rel < FRIENDLY) && (sect.sct_own != ship.shp_own)){ - pr("You are not on friendly terms with the owner of ship %d!\n", - ship.shp_uid); - continue; - } - n++; - mp = &mchr[(int)ship.shp_type]; - w_p_eff = ((mp->m_lcm / 2) + mp->m_hcm); - points = sect.sct_avail * 100 / w_p_eff; - if (points < 20) { - pr("Not enough available work in %s to upgrade a %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - mp->m_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20)/100); - continue; - } - if (ship.shp_effic < 60) { - pr("%s is too damaged to upgrade!\n", prship(&ship)); - continue; - } - if (ship.shp_tech >= tlev) { - pr("%s tech: %d, yours is only %d\n", prship(&ship), - ship.shp_tech, tlev); - continue; - } - if (mp->m_cost * .15 + player->dolcost > cash) { - pr("You don't have enough money to upgrade %s!\n", - prship(&ship)); - continue; - } + if (!snxtitem(&ni, EF_SHIP, player->argp[2])) + return RET_SYN; + ni.flags &= ~(EFF_OWNER); + natp = getnatp(player->cnum); + cash = natp->nat_money; + tlev = (int)natp->nat_level[NAT_TLEV]; + n = 0; + while (nxtitem(&ni, (s_char *)&ship)) { + if (ship.shp_own == 0) + continue; + getsect(ship.shp_x, ship.shp_y, §); + if (sect.sct_own != player->cnum) + continue; + if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60) + continue; + rel = getrel(getnatp(ship.shp_own), sect.sct_own); + if ((rel < FRIENDLY) && (sect.sct_own != ship.shp_own)) { + pr("You are not on friendly terms with the owner of ship %d!\n", ship.shp_uid); + continue; + } + n++; + mp = &mchr[(int)ship.shp_type]; + w_p_eff = ((mp->m_lcm / 2) + mp->m_hcm); + points = sect.sct_avail * 100 / w_p_eff; + if (points < 20) { + pr("Not enough available work in %s to upgrade a %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name); + pr(" (%d available work required)\n", + 1 + (w_p_eff * 20) / 100); + continue; + } + if (ship.shp_effic < 60) { + pr("%s is too damaged to upgrade!\n", prship(&ship)); + continue; + } + if (ship.shp_tech >= tlev) { + pr("%s tech: %d, yours is only %d\n", prship(&ship), + ship.shp_tech, tlev); + continue; + } + if (mp->m_cost * .15 + player->dolcost > cash) { + pr("You don't have enough money to upgrade %s!\n", + prship(&ship)); + continue; + } - sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; - ship.shp_effic -= 35; - ship.shp_tech = tlev; + sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; + ship.shp_effic -= 35; + ship.shp_tech = tlev; - techdiff = (int)(tlev - mp->m_tech); - ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff); - ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff); - ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff); - ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff); - ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff); + techdiff = (int)(tlev - mp->m_tech); + ship.shp_armor = (short)SHP_DEF(mp->m_armor, techdiff); + ship.shp_speed = (short)SHP_SPD(mp->m_speed, techdiff); + ship.shp_visib = (short)SHP_VIS(mp->m_visib, techdiff); + ship.shp_frnge = (short)SHP_RNG(mp->m_frnge, techdiff); + ship.shp_glim = (short)SHP_FIR(mp->m_glim, techdiff); - ship.shp_mission = 0; - time(&ship.shp_access); + ship.shp_mission = 0; + time(&ship.shp_access); - putship(ship.shp_uid, &ship); - putsect(§); - player->dolcost += (double) mp->m_cost * .15; - pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship), - ship.shp_tech, - (int)(mp->m_cost * .15)); - if (ship.shp_own != player->cnum) - wu(0,ship.shp_own,"%s upgraded by %s to tech %d, at a cost of %d\n", prship(&ship), - cname(player->cnum), - ship.shp_tech, (int)(mp->m_cost * .15)); - } - if (n == 0) { - pr("No ships\n"); - return RET_SYN; - } - return RET_OK; + putship(ship.shp_uid, &ship); + putsect(§); + player->dolcost += (double)mp->m_cost * .15; + pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship), + ship.shp_tech, (int)(mp->m_cost * .15)); + if (ship.shp_own != player->cnum) + wu(0, ship.shp_own, + "%s upgraded by %s to tech %d, at a cost of %d\n", + prship(&ship), cname(player->cnum), ship.shp_tech, + (int)(mp->m_cost * .15)); + } + if (n == 0) { + pr("No ships\n"); + return RET_SYN; + } + return RET_OK; } int pupgr(void) { - struct sctstr sect; - struct natstr *natp; - struct nstr_item ni; - struct plnstr plane; - struct plchrstr *pp; - int n; - int tlev; - int w_p_eff; - int points; - int rel; - int techdiff; - long cash; + struct sctstr sect; + struct natstr *natp; + struct nstr_item ni; + struct plnstr plane; + struct plchrstr *pp; + int n; + int tlev; + int w_p_eff; + int points; + int rel; + int techdiff; + long cash; + + if (!snxtitem(&ni, EF_PLANE, player->argp[2])) + return RET_SYN; + ni.flags &= ~(EFF_OWNER); + natp = getnatp(player->cnum); + cash = natp->nat_money; + tlev = (int)natp->nat_level[NAT_TLEV]; + n = 0; + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + getsect(plane.pln_x, plane.pln_y, §); + if (sect.sct_own != player->cnum) + continue; + if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60) + continue; + rel = getrel(getnatp(plane.pln_own), sect.sct_own); + if ((rel < FRIENDLY) && (sect.sct_own != plane.pln_own)) { + pr("You are not on friendly terms with the owner of plane %d!\n", plane.pln_uid); + continue; + } + n++; + pp = &plchr[(int)plane.pln_type]; + w_p_eff = ((pp->pl_lcm / 2) + pp->pl_hcm); + points = sect.sct_avail * 100 / w_p_eff; + if (points < 20) { + pr("Not enough available work in %s to upgrade a %s\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), pp->pl_name); + pr(" (%d available work required)\n", + 1 + (w_p_eff * 20) / 100); + continue; + } + if (plane.pln_effic < 60) { + pr("%s is too damaged to upgrade!\n", prplane(&plane)); + continue; + } + if (plane.pln_tech >= tlev) { + pr("%s tech: %d, yours is only %d\n", prplane(&plane), + plane.pln_tech, tlev); + continue; + } + if (pp->pl_cost * .15 + player->dolcost > cash) { + pr("You don't have enough money to upgrade %s!\n", + prplane(&plane)); + continue; + } + if (plane.pln_flags & PLN_LAUNCHED) { + pr("Plane %s is in orbit!\n", prplane(&plane)); + continue; + } - if (!snxtitem(&ni, EF_PLANE, player->argp[2])) - return RET_SYN; - ni.flags &= ~(EFF_OWNER); - natp = getnatp(player->cnum); - cash = natp->nat_money; - tlev = (int) natp->nat_level[NAT_TLEV]; - n = 0; - while (nxtitem(&ni, (s_char *) &plane)) { - if (plane.pln_own == 0) - continue; - getsect(plane.pln_x, plane.pln_y, §); - if (sect.sct_own != player->cnum) - continue; - if (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60) - continue; - rel=getrel(getnatp(plane.pln_own),sect.sct_own); - if ((rel < FRIENDLY) && (sect.sct_own != plane.pln_own)){ - pr("You are not on friendly terms with the owner of plane %d!\n", - plane.pln_uid); - continue; - } - n++; - pp = &plchr[(int)plane.pln_type]; - w_p_eff = ((pp->pl_lcm / 2) + pp->pl_hcm); - points = sect.sct_avail * 100 / w_p_eff; - if (points < 20) { - pr("Not enough available work in %s to upgrade a %s\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - pp->pl_name); - pr(" (%d available work required)\n", - 1 + (w_p_eff * 20)/100); - continue; - } - if (plane.pln_effic < 60) { - pr("%s is too damaged to upgrade!\n", prplane(&plane)); - continue; - } - if (plane.pln_tech >= tlev) { - pr("%s tech: %d, yours is only %d\n", prplane(&plane), - plane.pln_tech, tlev); - continue; - } - if (pp->pl_cost * .15 + player->dolcost > cash) { - pr("You don't have enough money to upgrade %s!\n", - prplane(&plane)); - continue; - } - if (plane.pln_flags & PLN_LAUNCHED) { - pr("Plane %s is in orbit!\n", prplane(&plane)); - continue; - } + sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; + plane.pln_effic -= 35; - sect.sct_avail = (sect.sct_avail * 100 - w_p_eff * 20) / 100; - plane.pln_effic -= 35; + plane.pln_tech = tlev; + techdiff = (int)(tlev - pp->pl_tech); - plane.pln_tech = tlev; - techdiff = (int)(tlev - pp->pl_tech); + plane.pln_mission = 0; + plane.pln_opx = 0; + plane.pln_opy = 0; + plane.pln_radius = 0; + plane.pln_harden = 0; + plane.pln_mission = 0; - plane.pln_mission = 0; - plane.pln_opx = 0; - plane.pln_opy = 0; - plane.pln_radius = 0; - plane.pln_harden = 0; - plane.pln_mission = 0; + plane.pln_att = PLN_ATTDEF(pp->pl_att, techdiff); + plane.pln_def = PLN_ATTDEF(pp->pl_def, techdiff); + plane.pln_acc = PLN_ACC(pp->pl_acc, techdiff); + plane.pln_range = PLN_RAN(pp->pl_range, techdiff); + plane.pln_range_max = plane.pln_range; + plane.pln_load = PLN_LOAD(pp->pl_load, techdiff); - plane.pln_att = PLN_ATTDEF(pp->pl_att, techdiff); - plane.pln_def = PLN_ATTDEF(pp->pl_def, techdiff); - plane.pln_acc = PLN_ACC(pp->pl_acc, techdiff); - plane.pln_range = PLN_RAN(pp->pl_range, techdiff); - plane.pln_range_max = plane.pln_range; - plane.pln_load = PLN_LOAD(pp->pl_load, techdiff); - - time(&plane.pln_access); + time(&plane.pln_access); - putplane(plane.pln_uid, &plane); - putsect(§); - player->dolcost += (double) pp->pl_cost * .15; - pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane), - plane.pln_tech, - (int)(pp->pl_cost * .15)); - if (plane.pln_own != player->cnum) - wu(0,plane.pln_own,"%s upgraded by %s to tech %d, at a cost of %d\n", prplane(&plane), - cname(player->cnum), - plane.pln_tech, (int)(pp->pl_cost * .15)); - } - if (n == 0) { - pr("No planes.\n"); - return RET_SYN; - } - return RET_OK; + putplane(plane.pln_uid, &plane); + putsect(§); + player->dolcost += (double)pp->pl_cost * .15; + pr("%s upgraded to tech %d, at a cost of %d\n", prplane(&plane), + plane.pln_tech, (int)(pp->pl_cost * .15)); + if (plane.pln_own != player->cnum) + wu(0, plane.pln_own, + "%s upgraded by %s to tech %d, at a cost of %d\n", + prplane(&plane), cname(player->cnum), plane.pln_tech, + (int)(pp->pl_cost * .15)); + } + if (n == 0) { + pr("No planes.\n"); + return RET_SYN; + } + return RET_OK; } - diff --git a/src/lib/commands/vers.c b/src/lib/commands/vers.c index 04645b9a7..ed22a5887 100644 --- a/src/lib/commands/vers.c +++ b/src/lib/commands/vers.c @@ -43,7 +43,7 @@ #include "deity.h" #include "nat.h" #include "version.h" -#include "ship.h" +#include "ship.h" #include "optlist.h" #include "commands.h" @@ -52,207 +52,190 @@ extern float drnuke_const; int vers(void) { - extern int s_p_etu; - extern int etu_per_update; - extern int m_m_p_d; - extern int players_at_00; - extern float btu_build_rate; - extern double fgrate, fcrate; - extern double eatrate, babyeat; - extern double obrate, uwbrate; - extern double bankint; - extern double hap_cons, edu_cons; - extern double money_civ, money_uw, money_mil, money_res; - extern float hap_avg, edu_avg, ally_factor; - extern float level_age_rate; + extern int s_p_etu; + extern int etu_per_update; + extern int m_m_p_d; + extern int players_at_00; + extern float btu_build_rate; + extern double fgrate, fcrate; + extern double eatrate, babyeat; + extern double obrate, uwbrate; + extern double bankint; + extern double hap_cons, edu_cons; + extern double money_civ, money_uw, money_mil, money_res; + extern float hap_avg, edu_avg, ally_factor; + extern float level_age_rate; /* extern float easy_tech, hard_tech, tech_log_base; */ - extern float easy_tech, tech_log_base; - extern int land_mob_max; - extern int land_grow_scale; - extern float land_mob_scale; - extern int sect_mob_max; - extern float sect_mob_scale; - extern int ship_mob_max; - extern float ship_mob_scale; - extern int ship_grow_scale; - extern int plane_mob_max; - extern float plane_mob_scale; - extern int plane_grow_scale; - extern int War_Cost; - extern float fire_range_factor; - extern int trade_1_dist; /* less than this gets no money */ - extern int trade_2_dist; /* less than this gets trade_1 money */ - extern int trade_3_dist; /* less than this gets trade_2 money */ - extern float trade_1; /* return on trade_1 distance */ - extern float trade_2; /* return on trade_2 distance */ - extern float trade_3; /* return on trade_3 distance */ - extern float trade_ally_bonus; /* 20% bonus for trading with allies */ - extern float trade_ally_cut; /* 10% bonus for ally you trade with */ - extern double tradetax; - extern double buytax; - struct option_list *op; - - time_t now; - int j; - - (void) time(&now); - pr("Empire %d.%d.%d\n(KSU distribution %2.2f, Chainsaw version %2.2f, Wolfpack version %2.2f)\n\n", - EMP_VERS_MAJOR, EMP_VERS_MINOR, EMP_VERS_PATCH, - (float)KSU_DIST, (float)CHAINSAW_DIST, (float)WOLFPACK_DIST); - pr("The following parameters have been set for this game:\n"); - pr("World size is %d by %d.\n", WORLD_X, WORLD_Y); - pr("There can be up to %d countries.\n", MAXNOC); - pr("By default, countries use %s coordinate system.\n", - (players_at_00) ? "the deity's" : "their own"); - pr("\n"); - pr("An Empire time unit is %d second%s long.\n", - s_p_etu, s_p_etu != 1 ? "s" : ""); - pr("Use the 'update' command to find out the time of the next update.\n"); - pr("The current time is %19.19s.\n",ctime(&now)); - pr("An update consists of %d empire time units.\n", - etu_per_update); - pr("Each country is allowed to be logged in %d minutes a day.\n", - m_m_p_d); - pr("It takes %.2f civilians to produce a BTU in one time unit.\n", - (1.0/(btu_build_rate*100.0))); - pr("\n"); - - pr("A non-aggi, 100 fertility sector can grow %.2f food per etu.\n", - 100.0 * fgrate); - pr("1000 civilians will harvest %.1f food per etu.\n", - 1000.0*fcrate); - pr("1000 civilians will give birth to %.1f babies per etu.\n", - 1000.0*obrate); - pr("1000 uncompensated workers will give birth to %.1f babies.\n", - 1000.0*uwbrate); - pr("In one time unit, 1000 people eat %.1f units of food.\n", - 1000.0*eatrate); - pr("1000 babies eat %.1f units of food becoming adults.\n", - 1000.0*babyeat); - if (opt_NOFOOD) - pr("No food is needed!!\n"); - - pr("\n"); - - pr("Banks pay $%.2f in interest per 1000 gold bars per etu.\n", - bankint*1000.0); - pr("1000 civilians generate $%.2f, uncompensated workers $%.2f each time unit.\n", 1000.0*money_civ, 1000.0*money_uw); - pr("1000 active military cost $%.2f, reserves cost $%.2f.\n", - -money_mil*1000.0, -money_res*1000.0); - if (opt_SLOW_WAR) - pr("Declaring war will cost you $%i\n\n", War_Cost); - pr("Happiness p.e. requires 1 happy stroller per %d civ.\n", - (int) hap_cons / etu_per_update); - pr("Education p.e. requires 1 class of graduates per %d civ.\n", - (int) edu_cons / etu_per_update); - pr("Happiness is averaged over %d time units.\n", (int)hap_avg); - pr("Education is averaged over %d time units.\n", (int)edu_avg); - if (opt_ALL_BLEED == 0) - pr( - "The technology/research boost you get from your allies is %.2f%%.\n", - 100.0/ally_factor); - else /* ! ALL_BLEED */ - pr( - "The technology/research boost you get from the world is %.2f%%.\n", - 100.0/ally_factor); - - pr("Nation levels (tech etc.) decline 1%% every %d time units.\n", - (int)(level_age_rate)); - - pr("Tech Buildup is "); + extern float easy_tech, tech_log_base; + extern int land_mob_max; + extern int land_grow_scale; + extern float land_mob_scale; + extern int sect_mob_max; + extern float sect_mob_scale; + extern int ship_mob_max; + extern float ship_mob_scale; + extern int ship_grow_scale; + extern int plane_mob_max; + extern float plane_mob_scale; + extern int plane_grow_scale; + extern int War_Cost; + extern float fire_range_factor; + extern int trade_1_dist; /* less than this gets no money */ + extern int trade_2_dist; /* less than this gets trade_1 money */ + extern int trade_3_dist; /* less than this gets trade_2 money */ + extern float trade_1; /* return on trade_1 distance */ + extern float trade_2; /* return on trade_2 distance */ + extern float trade_3; /* return on trade_3 distance */ + extern float trade_ally_bonus; /* 20% bonus for trading with allies */ + extern float trade_ally_cut; /* 10% bonus for ally you trade with */ + extern double tradetax; + extern double buytax; + struct option_list *op; + + time_t now; + int j; + + (void)time(&now); + pr("Empire %d.%d.%d\n(KSU distribution %2.2f, Chainsaw version %2.2f, Wolfpack version %2.2f)\n\n", EMP_VERS_MAJOR, EMP_VERS_MINOR, EMP_VERS_PATCH, (float)KSU_DIST, (float)CHAINSAW_DIST, (float)WOLFPACK_DIST); + pr("The following parameters have been set for this game:\n"); + pr("World size is %d by %d.\n", WORLD_X, WORLD_Y); + pr("There can be up to %d countries.\n", MAXNOC); + pr("By default, countries use %s coordinate system.\n", + (players_at_00) ? "the deity's" : "their own"); + pr("\n"); + pr("An Empire time unit is %d second%s long.\n", + s_p_etu, s_p_etu != 1 ? "s" : ""); + pr("Use the 'update' command to find out the time of the next update.\n"); + pr("The current time is %19.19s.\n", ctime(&now)); + pr("An update consists of %d empire time units.\n", etu_per_update); + pr("Each country is allowed to be logged in %d minutes a day.\n", + m_m_p_d); + pr("It takes %.2f civilians to produce a BTU in one time unit.\n", + (1.0 / (btu_build_rate * 100.0))); + pr("\n"); + + pr("A non-aggi, 100 fertility sector can grow %.2f food per etu.\n", + 100.0 * fgrate); + pr("1000 civilians will harvest %.1f food per etu.\n", + 1000.0 * fcrate); + pr("1000 civilians will give birth to %.1f babies per etu.\n", + 1000.0 * obrate); + pr("1000 uncompensated workers will give birth to %.1f babies.\n", + 1000.0 * uwbrate); + pr("In one time unit, 1000 people eat %.1f units of food.\n", + 1000.0 * eatrate); + pr("1000 babies eat %.1f units of food becoming adults.\n", + 1000.0 * babyeat); + if (opt_NOFOOD) + pr("No food is needed!!\n"); + + pr("\n"); + + pr("Banks pay $%.2f in interest per 1000 gold bars per etu.\n", + bankint * 1000.0); + pr("1000 civilians generate $%.2f, uncompensated workers $%.2f each time unit.\n", 1000.0 * money_civ, 1000.0 * money_uw); + pr("1000 active military cost $%.2f, reserves cost $%.2f.\n", + -money_mil * 1000.0, -money_res * 1000.0); + if (opt_SLOW_WAR) + pr("Declaring war will cost you $%i\n\n", War_Cost); + pr("Happiness p.e. requires 1 happy stroller per %d civ.\n", + (int)hap_cons / etu_per_update); + pr("Education p.e. requires 1 class of graduates per %d civ.\n", + (int)edu_cons / etu_per_update); + pr("Happiness is averaged over %d time units.\n", (int)hap_avg); + pr("Education is averaged over %d time units.\n", (int)edu_avg); + if (opt_ALL_BLEED == 0) + pr("The technology/research boost you get from your allies is %.2f%%.\n", 100.0 / ally_factor); + else /* ! ALL_BLEED */ + pr("The technology/research boost you get from the world is %.2f%%.\n", 100.0 / ally_factor); + + pr("Nation levels (tech etc.) decline 1%% every %d time units.\n", + (int)(level_age_rate)); + + pr("Tech Buildup is "); /* if (tech_log_base <= 1.0 && hard_tech == 0.0) { */ - if (tech_log_base <= 1.0 ) { - pr("not limited\n"); - } - if (tech_log_base > 1.0) { - pr("limited to logarithmic growth (base %.2f)", - tech_log_base); - if (easy_tech == 0.0) - pr(".\n"); - else - pr(" after %0.2f.\n", easy_tech); - } /*else { - pr("limited to asymptotic growth towards %.2f", - hard_tech + easy_tech); - if (easy_tech == 0.00) - pr(".\n"); - else - pr("after %.2f\n",easy_tech); - } */ - - pr("\n"); - pr("\t\t\t\tSectors\tShips\tPlanes\tUnits\n"); - pr("Maximum mobility\t\t%d\t%d\t%d\t%d\n", sect_mob_max, - ship_mob_max, plane_mob_max, land_mob_max); - pr("Max mob gain per update\t\t%d\t%d\t%d\t%d\n", - (int)(sect_mob_scale*(float)etu_per_update), - (int)(ship_mob_scale*(float)etu_per_update), - (int)(plane_mob_scale*(float)etu_per_update), - (int)(land_mob_scale*(float)etu_per_update)); - pr("Max eff gain per update\t\t--\t%d\t%d\t%d\n", - min(ship_grow_scale*etu_per_update,100), - min(plane_grow_scale*etu_per_update,100), - min(land_grow_scale*etu_per_update,100)); - pr("\n"); - pr("Ships on autonavigation may use %i cargo holds per ship.\n",TMAX); - if (opt_TRADESHIPS) { - pr("Trade-ships that go at least %d sectors get a return of %.1f%% per sector.\n", - trade_1_dist, (float)(trade_1 * 100.0)); - pr("Trade-ships that go at least %d sectors get a return of %.1f%% per sector.\n", - trade_2_dist, (float)(trade_2 * 100.0)); - pr("Trade-ships that go at least %d sectors get a return of %.1f%% per sector.\n", - trade_3_dist, (float)(trade_3 * 100.0)); - pr("Cashing in trade-ships with an ally nets you a %.1f%% bonus.\n", - trade_ally_bonus * 100.0); - pr("Cashing in trade-ships with an ally nets your ally a %.1f%% bonus.\n\n", - trade_ally_cut * 100.0); + if (tech_log_base <= 1.0) { + pr("not limited\n"); + } + if (tech_log_base > 1.0) { + pr("limited to logarithmic growth (base %.2f)", tech_log_base); + if (easy_tech == 0.0) + pr(".\n"); + else + pr(" after %0.2f.\n", easy_tech); + } + /*else { + pr("limited to asymptotic growth towards %.2f", + hard_tech + easy_tech); + if (easy_tech == 0.00) + pr(".\n"); + else + pr("after %.2f\n",easy_tech); + } */ + pr("\n"); + pr("\t\t\t\tSectors\tShips\tPlanes\tUnits\n"); + pr("Maximum mobility\t\t%d\t%d\t%d\t%d\n", sect_mob_max, + ship_mob_max, plane_mob_max, land_mob_max); + pr("Max mob gain per update\t\t%d\t%d\t%d\t%d\n", + (int)(sect_mob_scale * (float)etu_per_update), + (int)(ship_mob_scale * (float)etu_per_update), + (int)(plane_mob_scale * (float)etu_per_update), + (int)(land_mob_scale * (float)etu_per_update)); + pr("Max eff gain per update\t\t--\t%d\t%d\t%d\n", + min(ship_grow_scale * etu_per_update, 100), + min(plane_grow_scale * etu_per_update, 100), + min(land_grow_scale * etu_per_update, 100)); + pr("\n"); + pr("Ships on autonavigation may use %i cargo holds per ship.\n", TMAX); + if (opt_TRADESHIPS) { + pr("Trade-ships that go at least %d sectors get a return of %.1f%% per sector.\n", trade_1_dist, (float)(trade_1 * 100.0)); + pr("Trade-ships that go at least %d sectors get a return of %.1f%% per sector.\n", trade_2_dist, (float)(trade_2 * 100.0)); + pr("Trade-ships that go at least %d sectors get a return of %.1f%% per sector.\n", trade_3_dist, (float)(trade_3 * 100.0)); + pr("Cashing in trade-ships with an ally nets you a %.1f%% bonus.\n", trade_ally_bonus * 100.0); + pr("Cashing in trade-ships with an ally nets your ally a %.1f%% bonus.\n\n", trade_ally_cut * 100.0); + } + if (opt_MARKET) { + pr("The tax you pay on selling things on the trading block is %.1f%%\n", (1.00 - tradetax) * 100.0); + pr("The tax you pay on buying commodities on the market is %.1f%%\n\n", (buytax - 1.00) * 100.0); + } + + if (opt_NONUKES) + pr("Nukes are disabled.\n"); + else if (opt_DRNUKE) { /* NUKES && DRNUKE enabled */ + pr("In order to build a nuke, you need %1.2f times the tech level in research\n", drnuke_const); + pr("\tExample: In order to build a 300 tech nuke, you need %d research\n\n", (int)(300.0 * drnuke_const)); + } + + pr("Fire ranges are scaled by %.2f\n", fire_range_factor); + + pr("\nOptions enabled in this game:\n "); + for (j = 0, op = Options; op->opt_key; op++) { + if (*op->opt_valuep == 0) + continue; + + j += strlen(op->opt_key) + 2; + if (j > 70) { + pr("\n "); + j = strlen(op->opt_key) + 2; } - if (opt_MARKET) { - pr("The tax you pay on selling things on the trading block is %.1f%%\n", - (1.00-tradetax) * 100.0); - pr("The tax you pay on buying commodities on the market is %.1f%%\n\n", - (buytax - 1.00) * 100.0); - } - - if (opt_NONUKES) - pr("Nukes are disabled.\n"); - else if(opt_DRNUKE) { /* NUKES && DRNUKE enabled */ - pr("In order to build a nuke, you need %1.2f times the tech level in research\n", - drnuke_const); - pr("\tExample: In order to build a 300 tech nuke, you need %d research\n\n", - (int)(300.0*drnuke_const)); - } - - pr("Fire ranges are scaled by %.2f\n", fire_range_factor); - - pr("\nOptions enabled in this game:\n "); - for (j = 0, op = Options; op -> opt_key; op++) { - if (*op -> opt_valuep == 0) - continue; - - j += strlen (op -> opt_key) + 2; - if (j > 70) { - pr ("\n "); - j = strlen (op -> opt_key) + 2; - } - pr ("%s%s", op -> opt_key, op[1].opt_key == NULL ? "": ", "); - } - pr("\n\nOptions disabled in this game:\n "); - for (j = 0, op = Options; op -> opt_key; op++) { - if (!(*op -> opt_valuep == 0)) - continue; - - j += strlen (op -> opt_key) + 2; - if (j > 70) { - pr ("\n "); - j = strlen (op -> opt_key) + 2; - } - pr ("%s%s", op -> opt_key, op[1].opt_key == NULL ? "": ", "); + pr("%s%s", op->opt_key, op[1].opt_key == NULL ? "" : ", "); + } + pr("\n\nOptions disabled in this game:\n "); + for (j = 0, op = Options; op->opt_key; op++) { + if (!(*op->opt_valuep == 0)) + continue; + + j += strlen(op->opt_key) + 2; + if (j > 70) { + pr("\n "); + j = strlen(op->opt_key) + 2; } - pr("\n\n\"info Options\" for a detailed list of options and descriptions"); - pr("\n\n"); - pr("The person to annoy if something goes wrong is:\n\t%s\n\t(%s).\n", - privname, privlog); - pr("You can get your own copy of the source %s\n", GET_SOURCE); - return RET_OK; + pr("%s%s", op->opt_key, op[1].opt_key == NULL ? "" : ", "); + } + pr("\n\n\"info Options\" for a detailed list of options and descriptions"); + pr("\n\n"); + pr("The person to annoy if something goes wrong is:\n\t%s\n\t(%s).\n", + privname, privlog); + pr("You can get your own copy of the source %s\n", GET_SOURCE); + return RET_OK; } diff --git a/src/lib/commands/wai.c b/src/lib/commands/wai.c index 913b8a556..31d6a79ba 100644 --- a/src/lib/commands/wai.c +++ b/src/lib/commands/wai.c @@ -41,20 +41,20 @@ int wai(void) { - struct natstr *np; + struct natstr *np; - np = getnatp(player->cnum); - io_output(player->iop, IO_WAIT); - if (np->nat_ann == 0 && np->nat_tgms == 0) { - player->waiting++; - io_input(player->iop, IO_WAIT); - player->waiting--; - } - if (player->aborted || io_eof(player->iop)) - return RET_OK; - if (np->nat_ann != 0) - player->argp[0] = "wire"; - if (np->nat_tgms != 0) - player->argp[0] = "read"; - return rea(); -} + np = getnatp(player->cnum); + io_output(player->iop, IO_WAIT); + if (np->nat_ann == 0 && np->nat_tgms == 0) { + player->waiting++; + io_input(player->iop, IO_WAIT); + player->waiting--; + } + if (player->aborted || io_eof(player->iop)) + return RET_OK; + if (np->nat_ann != 0) + player->argp[0] = "wire"; + if (np->nat_tgms != 0) + player->argp[0] = "read"; + return rea(); +} diff --git a/src/lib/commands/wing.c b/src/lib/commands/wing.c index f30165b06..93dc90a14 100644 --- a/src/lib/commands/wing.c +++ b/src/lib/commands/wing.c @@ -46,32 +46,32 @@ int wing(void) { - struct plnstr plane; - register int count; - s_char *cp; - s_char c; - struct nstr_item nstr; - s_char buf[1024]; + struct plnstr plane; + register int count; + s_char *cp; + s_char c; + struct nstr_item nstr; + s_char buf[1024]; - if (!(cp = getstarg(player->argp[1], "wing? ", buf))) - return RET_SYN; - c = *cp; - if (!isalpha(c) && c != '~') { - pr("Specify wing, (1 alpha char or '~')\n"); - return RET_SYN; + if (!(cp = getstarg(player->argp[1], "wing? ", buf))) + return RET_SYN; + c = *cp; + if (!isalpha(c) && c != '~') { + pr("Specify wing, (1 alpha char or '~')\n"); + return RET_SYN; + } + if (c == '~') + c = ' '; + if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) + return RET_SYN; + for (count = 0; nxtitem(&nstr, (s_char *)&plane); count++) { + if (plane.pln_own != player->cnum) { + count--; + continue; } - if (c == '~') - c = ' '; - if (!snxtitem(&nstr, EF_PLANE, player->argp[2])) - return RET_SYN; - for (count = 0; nxtitem(&nstr, (s_char *)&plane); count++) { - if (plane.pln_own != player->cnum) { - count--; - continue; - } - plane.pln_wing = c; - putplane(plane.pln_uid, &plane); - } - pr("%d plane%s added to wing `%c'\n", count, splur(count), c); - return RET_OK; + plane.pln_wing = c; + putplane(plane.pln_uid, &plane); + } + pr("%d plane%s added to wing `%c'\n", count, splur(count), c); + return RET_OK; } diff --git a/src/lib/commands/wipe.c b/src/lib/commands/wipe.c index d58283610..a5ebc2d50 100644 --- a/src/lib/commands/wipe.c +++ b/src/lib/commands/wipe.c @@ -45,20 +45,20 @@ int wipe(void) { - struct sctstr sect; - struct nstr_sect nstr; - int vec[I_MAX+1]; + struct sctstr sect; + struct nstr_sect nstr; + int vec[I_MAX + 1]; - if (!snxtsct(&nstr, player->argp[1])) - return RET_SYN; - bzero((s_char *)vec, sizeof(vec)); - while (nxtsct(&nstr, §)) { - if (!player->owner) - continue; - putvec(VT_DIST, vec, (s_char *)§, EF_SECTOR); - pr("Distribution thresholds wiped from %s\n", - xyas(nstr.x, nstr.y, player->cnum)); - putsect(§); - } - return RET_OK; + if (!snxtsct(&nstr, player->argp[1])) + return RET_SYN; + bzero((s_char *)vec, sizeof(vec)); + while (nxtsct(&nstr, §)) { + if (!player->owner) + continue; + putvec(VT_DIST, vec, (s_char *)§, EF_SECTOR); + pr("Distribution thresholds wiped from %s\n", + xyas(nstr.x, nstr.y, player->cnum)); + putsect(§); + } + return RET_OK; } diff --git a/src/lib/commands/work.c b/src/lib/commands/work.c index 89212fc16..629c9079e 100644 --- a/src/lib/commands/work.c +++ b/src/lib/commands/work.c @@ -47,144 +47,140 @@ int work(void) { - int nunits; - struct nstr_item ni; - struct sctstr sect; - struct lndstr land; - int work_amt, eff_amt, w; - s_char *p; - extern int land_mob_max; - coord donex = 0, doney = 1; - s_char buf[1024]; + int nunits; + struct nstr_item ni; + struct sctstr sect; + struct lndstr land; + int work_amt, eff_amt, w; + s_char *p; + extern int land_mob_max; + coord donex = 0, doney = 1; + s_char buf[1024]; - if (!snxtitem(&ni, EF_LAND, player->argp[1])) - return RET_SYN; - p = getstarg(player->argp[2], "Amount: ", buf); - if (p == 0 || *p == 0) - return RET_SYN; - work_amt = atoi(p); - if ((work_amt<0) || (work_amt > land_mob_max)){ - pr("Mobility used must be from 0 to %d\n",land_mob_max); - return RET_FAIL; + if (!snxtitem(&ni, EF_LAND, player->argp[1])) + return RET_SYN; + p = getstarg(player->argp[2], "Amount: ", buf); + if (p == 0 || *p == 0) + return RET_SYN; + work_amt = atoi(p); + if ((work_amt < 0) || (work_amt > land_mob_max)) { + pr("Mobility used must be from 0 to %d\n", land_mob_max); + return RET_FAIL; + } + nunits = 0; + while (nxtitem(&ni, (s_char *)&land)) { + if (!player->owner || land.lnd_own == 0) + continue; + if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { + pr("bad unit type %d (#%d)\n", land.lnd_type, ni.cur); + continue; } - nunits = 0; - while (nxtitem(&ni, (s_char *)&land)) { - if (!player->owner || land.lnd_own == 0) - continue; - if (land.lnd_type < 0 || land.lnd_type > lnd_maxno) { - pr("bad unit type %d (#%d)\n", - land.lnd_type, ni.cur); - continue; - } - if (!(lchr[(int)land.lnd_type].l_flags & L_ENGINEER)) - continue; - if (land.lnd_mobil <= 0){ - pr("%s has no mobility!\n", - prland(&land)); - continue; - } - getsect(land.lnd_x,land.lnd_y,§); - if (sect.sct_effic >= 100 - && sect.sct_type == sect.sct_newtype) { - if (sect.sct_x != donex || sect.sct_y != doney) - pr("%s is %d%% efficient\n", - xyas(sect.sct_x, sect.sct_y, player->cnum), - sect.sct_effic); - /* not perfect, but it'll do -KHS */ - donex = sect.sct_x; - doney = sect.sct_y; - continue; - } - eff_amt= min(land.lnd_mobil,work_amt); - w = ldround(((double)eff_amt * land.lnd_effic/600.0),1); - if (w < 1) { - pr("%s doesn't work enough to change efficiency (try increasing amount)\n", - prland(&land)); - continue; - } - nunits++; - eff_amt = ((6 * buildeff(§, w, &player->dolcost)) / - (land.lnd_effic / 100.0)); - land.lnd_mission = 0; - land.lnd_mobil -= eff_amt; - pr("%s %s efficiency at %s to %d\n", - prland(&land), - sect.sct_type == sect.sct_newtype ? "raised" : "lowered", - xyas(land.lnd_x,land.lnd_y,player->cnum), - (int)sect.sct_effic); - putland(land.lnd_uid,&land); - putsect(§); + if (!(lchr[(int)land.lnd_type].l_flags & L_ENGINEER)) + continue; + if (land.lnd_mobil <= 0) { + pr("%s has no mobility!\n", prland(&land)); + continue; } - if (nunits == 0) { - if (player->argp[1]) - pr("%s: No unit(s)\n", player->argp[1]); - else - pr("%s: No unit(s)\n", ""); - return RET_FAIL; - }else - pr("%d unit%s\n", nunits, splur(nunits)); - return RET_OK; + getsect(land.lnd_x, land.lnd_y, §); + if (sect.sct_effic >= 100 && sect.sct_type == sect.sct_newtype) { + if (sect.sct_x != donex || sect.sct_y != doney) + pr("%s is %d%% efficient\n", + xyas(sect.sct_x, sect.sct_y, player->cnum), + sect.sct_effic); + /* not perfect, but it'll do -KHS */ + donex = sect.sct_x; + doney = sect.sct_y; + continue; + } + eff_amt = min(land.lnd_mobil, work_amt); + w = ldround(((double)eff_amt * land.lnd_effic / 600.0), 1); + if (w < 1) { + pr("%s doesn't work enough to change efficiency (try increasing amount)\n", prland(&land)); + continue; + } + nunits++; + eff_amt = ((6 * buildeff(§, w, &player->dolcost)) / + (land.lnd_effic / 100.0)); + land.lnd_mission = 0; + land.lnd_mobil -= eff_amt; + pr("%s %s efficiency at %s to %d\n", + prland(&land), + sect.sct_type == sect.sct_newtype ? "raised" : "lowered", + xyas(land.lnd_x, land.lnd_y, player->cnum), + (int)sect.sct_effic); + putland(land.lnd_uid, &land); + putsect(§); + } + if (nunits == 0) { + if (player->argp[1]) + pr("%s: No unit(s)\n", player->argp[1]); + else + pr("%s: No unit(s)\n", ""); + return RET_FAIL; + } else + pr("%d unit%s\n", nunits, splur(nunits)); + return RET_OK; } int buildeff(struct sctstr *sp, int work, double *money) { - int vec[I_MAX+1]; - register int work_cost; - int n, hcms, lcms; - int effdone = 0; + int vec[I_MAX + 1]; + register int work_cost; + int n, hcms, lcms; + int effdone = 0; - getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - work_cost = 0; - if (sp->sct_type != sp->sct_newtype) { - /* - * Tear down existing sector. - * Easier to destroy than to build. - */ - work_cost = (sp->sct_effic + 3) / 4; - if (work_cost > work) - work_cost = work; - n = sp->sct_effic - work_cost * 4; - if (n <= 0) { - n = 0; - sp->sct_type = sp->sct_newtype; - } - sp->sct_effic = n; - if (!opt_DEFENSE_INFRA) - sp->sct_defense = sp->sct_effic; - work -= work_cost; - *money += work_cost; - effdone += work_cost; + work_cost = 0; + if (sp->sct_type != sp->sct_newtype) { + /* + * Tear down existing sector. + * Easier to destroy than to build. + */ + work_cost = (sp->sct_effic + 3) / 4; + if (work_cost > work) + work_cost = work; + n = sp->sct_effic - work_cost * 4; + if (n <= 0) { + n = 0; + sp->sct_type = sp->sct_newtype; } - if (sp->sct_type == sp->sct_newtype) { - work_cost = 100 - sp->sct_effic; - if (work_cost > work) - work_cost = work; + sp->sct_effic = n; + if (!opt_DEFENSE_INFRA) + sp->sct_defense = sp->sct_effic; + work -= work_cost; + *money += work_cost; + effdone += work_cost; + } + if (sp->sct_type == sp->sct_newtype) { + work_cost = 100 - sp->sct_effic; + if (work_cost > work) + work_cost = work; - if (dchr[sp->sct_type].d_lcms>0){ - lcms = vec[I_LCM]; - lcms /= dchr[sp->sct_type].d_lcms; - if (work_cost > lcms) - work_cost = lcms; - } - if (dchr[sp->sct_type].d_hcms>0){ - hcms = vec[I_HCM]; - hcms /= dchr[sp->sct_type].d_hcms; - if (work_cost > hcms) - work_cost = hcms; - } + if (dchr[sp->sct_type].d_lcms > 0) { + lcms = vec[I_LCM]; + lcms /= dchr[sp->sct_type].d_lcms; + if (work_cost > lcms) + work_cost = lcms; + } + if (dchr[sp->sct_type].d_hcms > 0) { + hcms = vec[I_HCM]; + hcms /= dchr[sp->sct_type].d_hcms; + if (work_cost > hcms) + work_cost = hcms; + } - sp->sct_effic += work_cost; - *money += work_cost*dchr[sp->sct_type].d_build; + sp->sct_effic += work_cost; + *money += work_cost * dchr[sp->sct_type].d_build; - if ((dchr[sp->sct_type].d_lcms>0) || - (dchr[sp->sct_type].d_hcms>0)){ - vec[I_LCM] -= work_cost * dchr[sp->sct_type].d_lcms; - vec[I_HCM] -= work_cost * dchr[sp->sct_type].d_hcms; - } - effdone += work_cost; + if ((dchr[sp->sct_type].d_lcms > 0) || + (dchr[sp->sct_type].d_hcms > 0)) { + vec[I_LCM] -= work_cost * dchr[sp->sct_type].d_lcms; + vec[I_HCM] -= work_cost * dchr[sp->sct_type].d_hcms; } - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - return effdone; + effdone += work_cost; + } + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + return effdone; } diff --git a/src/lib/commands/zdon.c b/src/lib/commands/zdon.c index 27af2a9de..2d44fa55c 100644 --- a/src/lib/commands/zdon.c +++ b/src/lib/commands/zdon.c @@ -62,84 +62,83 @@ int zdon(void) { - extern empth_sem_t *update_sem; - natid whichcnum; - struct natstr *natp; - register s_char *p; + extern empth_sem_t *update_sem; + natid whichcnum; + struct natstr *natp; + register s_char *p; - int update; - int checking; - int wantupd; - int totpop; - int totwant; - int dowant; - s_char buf[1024]; + int update; + int checking; + int wantupd; + int totpop; + int totwant; + int dowant; + s_char buf[1024]; - if (!opt_DEMANDUPDATE) { - pr("Demand updates are not enabled.\n"); - return RET_FAIL; - } - whichcnum = player->cnum; - p = NULL; - if (player->god) { - /* Deity syntax "country what" */ - whichcnum = onearg(player->argp[1], "Which country no.? "); - if ((whichcnum > 0) && (getnatp(whichcnum))) - p = getstarg(player->argp[2], "Want update? [Yes|No|Check] ", buf); - } else { - p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf); - } - if (player->aborted) - return RET_FAIL; + if (!opt_DEMANDUPDATE) { + pr("Demand updates are not enabled.\n"); + return RET_FAIL; + } + whichcnum = player->cnum; + p = NULL; + if (player->god) { + /* Deity syntax "country what" */ + whichcnum = onearg(player->argp[1], "Which country no.? "); + if ((whichcnum > 0) && (getnatp(whichcnum))) + p = getstarg(player->argp[2], "Want update? [Yes|No|Check] ", + buf); + } else { + p = getstarg(player->argp[1], "Want update? [Yes|No|Check] ", buf); + } + if (player->aborted) + return RET_FAIL; - if (!p) { - /* Default response is checking only */ - checking = 1; + if (!p) { + /* Default response is checking only */ + checking = 1; + } else { + checking = 0; + if (*p == 'n' || *p == 'N') { + wantupd = 0; + } else if (*p == 'y' || *p == 'Y') { + wantupd = 1; } else { - checking = 0; - if (*p == 'n' || *p == 'N') { - wantupd = 0; - } else if (*p == 'y' || *p == 'Y') { - wantupd = 1; - } else { - /* Default response is checking only */ - checking = 1; - } + /* Default response is checking only */ + checking = 1; } + } - if (!checking) { - if (!(natp = getnatp(whichcnum))) { - pr("Unable to find country. %d\n", whichcnum); - pr("Notify the Deity.\n"); - return RET_FAIL; - } - if (wantupd) { - update = natp->nat_update | WUPD_WANT; - natp->nat_missed = 0; - pr("You (%d) now want an update.\n", - whichcnum); - } else { - update = natp->nat_update & ~WUPD_WANT; - pr("You (%d) now DON'T want an update.\n", - whichcnum); - } - natp->nat_update = update; - putnat(natp); + if (!checking) { + if (!(natp = getnatp(whichcnum))) { + pr("Unable to find country. %d\n", whichcnum); + pr("Notify the Deity.\n"); + return RET_FAIL; } - - dowant = demand_update_want(&totwant, &totpop, whichcnum); - if (checking) { - if (dowant) { - pr("You want an update.\n"); - } else - pr("You DON'T want an update, yet.\n"); + if (wantupd) { + update = natp->nat_update | WUPD_WANT; + natp->nat_missed = 0; + pr("You (%d) now want an update.\n", whichcnum); + } else { + update = natp->nat_update & ~WUPD_WANT; + pr("You (%d) now DON'T want an update.\n", whichcnum); } + natp->nat_update = update; + putnat(natp); + } - pr("%d of a total of %d lunatics want an update.\n", totwant, totpop); + dowant = demand_update_want(&totwant, &totpop, whichcnum); + if (checking) { + if (dowant) { + pr("You want an update.\n"); + } else + pr("You DON'T want an update, yet.\n"); + } - if (!checking && wantupd && demandupdatecheck()) { - pr("Here goes...\n"); - empth_sem_signal(update_sem); - } - return RET_OK; + pr("%d of a total of %d lunatics want an update.\n", totwant, totpop); + + if (!checking && wantupd && demandupdatecheck()) { + pr("Here goes...\n"); + empth_sem_signal(update_sem); + } + return RET_OK; } diff --git a/src/lib/common/bestpath.c b/src/lib/common/bestpath.c index 9d4b039a9..74d8332b9 100644 --- a/src/lib/common/bestpath.c +++ b/src/lib/common/bestpath.c @@ -53,9 +53,9 @@ #include "common.h" #include "optlist.h" -static int owned_and_navigable(s_char * , int , int , s_char * , int ); +static int owned_and_navigable(s_char *, int, int, s_char *, int); -#define MAXROUTE 100 /* return '?' if path longer than this */ +#define MAXROUTE 100 /* return '?' if path longer than this */ #define valid(x,y) (((x^y)&1)==0) /* ________________________________________________________________ @@ -106,9 +106,9 @@ static int owned_and_navigable(s_char * , int , int , s_char * , int ); ** ________________________________________________________________ */ -s_char *dirchar = "juygbn"; -int dx[6] = { 2, 1,-1,-2,-1, 1 }; -int dy[6] = { 0,-1,-1, 0, 1, 1 }; +s_char *dirchar = "juygbn"; +int dx[6] = { 2, 1, -1, -2, -1, 1 }; +int dy[6] = { 0, -1, -1, 0, 1, 1 }; int tmp; /* @@ -125,198 +125,196 @@ int tmp; static unsigned int *mapbuf = (unsigned int *)0; static unsigned int **mapindex = (unsigned int **)0; -s_char *bestownedpath(s_char *bpath, - s_char *bigmap, - int x, - int y, - int ex, - int ey, - s_char *terrain, - int own) +s_char * +bestownedpath(s_char *bpath, + s_char *bigmap, + int x, int y, int ex, int ey, s_char *terrain, int own) { - int i, j, tx, ty, markedsectors, restr2; - int minx, maxx, miny, maxy, scanx, scany; - unsigned int routelen; + int i, j, tx, ty, markedsectors, restr2; + int minx, maxx, miny, maxy, scanx, scany; + unsigned int routelen; - if (!mapbuf) - mapbuf = (unsigned int *)malloc((WORLD_X * WORLD_Y) * - sizeof(unsigned int)); - if (!mapbuf) - return ((s_char *)0); - if (!mapindex) { - mapindex = (unsigned int **)malloc(WORLD_X * sizeof(unsigned int *)); - if (mapindex) { - /* Setup the map pointers */ - for (i = 0; i < WORLD_X; i++) - mapindex[i] = &mapbuf[WORLD_Y * i]; - } - } - if (!mapindex) - return ((s_char *)0); + if (!mapbuf) + mapbuf = (unsigned int *)malloc((WORLD_X * WORLD_Y) * + sizeof(unsigned int)); + if (!mapbuf) + return ((s_char *)0); + if (!mapindex) { + mapindex = + (unsigned int **)malloc(WORLD_X * sizeof(unsigned int *)); + if (mapindex) { + /* Setup the map pointers */ + for (i = 0; i < WORLD_X; i++) + mapindex[i] = &mapbuf[WORLD_Y * i]; + } + } + if (!mapindex) + return ((s_char *)0); - bpath[0] = 0; - if (0 != (restr2 = (*terrain == 'R'))) - terrain++; + bpath[0] = 0; + if (0 != (restr2 = (*terrain == 'R'))) + terrain++; - x = XNORM(x); - y = YNORM(y); - ex = XNORM(ex); - ey = YNORM(ey); + x = XNORM(x); + y = YNORM(y); + ex = XNORM(ex); + ey = YNORM(ey); - if (x == ex && y == ey) { - bpath[0] = 'h'; - bpath[1] = 0; - return ((s_char *)bpath); - } + if (x == ex && y == ey) { + bpath[0] = 'h'; + bpath[1] = 0; + return ((s_char *)bpath); + } - if (!valid(x,y) || !valid(ex,ey)) - return((s_char *)0); + if (!valid(x, y) || !valid(ex, ey)) + return ((s_char *)0); - if (restr2 && (!owned_and_navigable(bigmap, x, y, terrain, own) || - !owned_and_navigable(bigmap, x, y, terrain, own))) - return ((s_char *)0); + if (restr2 && (!owned_and_navigable(bigmap, x, y, terrain, own) || + !owned_and_navigable(bigmap, x, y, terrain, own))) + return ((s_char *)0); - for (i = 0; i < WORLD_X; i++) - for (j = 0; j < WORLD_Y; j++) - mapindex[i][j] = 0xFFFF; /* clear the workspace */ + for (i = 0; i < WORLD_X; i++) + for (j = 0; j < WORLD_Y; j++) + mapindex[i][j] = 0xFFFF; /* clear the workspace */ - routelen = 0; /* path length is now 0 */ - mapindex[x][y] = 0; /* mark starting spot */ - markedsectors = 1; /* source sector marked */ - minx = x - 2; /* set X scan bounds */ - maxx = x + 2; - miny = y - 1; /* set Y scan bounds */ - maxy = y + 1; + routelen = 0; /* path length is now 0 */ + mapindex[x][y] = 0; /* mark starting spot */ + markedsectors = 1; /* source sector marked */ + minx = x - 2; /* set X scan bounds */ + maxx = x + 2; + miny = y - 1; /* set Y scan bounds */ + maxy = y + 1; - do { - if (++routelen == MAXROUTE) { - bpath[0] = '?'; - bpath[1] = 0; - return ((s_char *)bpath); - } - markedsectors = 0; - for (scanx = minx; scanx <= maxx; scanx++) { - x = XNORM(scanx); - for (scany = miny; scany <= maxy; scany++) { - y = YNORM(scany); - if (valid(x,y)) { - if ((((mapindex[x][y]) & 0x1FFF) == (routelen - 1))) { - for (i = 0; i < 6; i++) { - tx = x + dx[i]; - ty = y + dy[i]; - tx = XNORM(tx); - ty = YNORM(ty); - if (mapindex[tx][ty] == 0xFFFF) { - if (owned_and_navigable(bigmap, tx, ty, terrain, own) || - (tx == ex && ty == ey && !restr2) ) { - mapindex[tx][ty] = ((i + 1) << 13) + routelen; - markedsectors++; - } - } - if (tx == ex && ty == ey) { - bpath[routelen] = 0; - while (routelen--) { - i = ((mapindex[tx][ty]) >> 13) - 1; - bpath[routelen] = dirchar[i]; - tx = tx - dx[i]; - ty = ty - dy[i]; - tx = XNORM(tx); - ty = YNORM(ty); + do { + if (++routelen == MAXROUTE) { + bpath[0] = '?'; + bpath[1] = 0; + return ((s_char *)bpath); + } + markedsectors = 0; + for (scanx = minx; scanx <= maxx; scanx++) { + x = XNORM(scanx); + for (scany = miny; scany <= maxy; scany++) { + y = YNORM(scany); + if (valid(x, y)) { + if ((((mapindex[x][y]) & 0x1FFF) == (routelen - 1))) { + for (i = 0; i < 6; i++) { + tx = x + dx[i]; + ty = y + dy[i]; + tx = XNORM(tx); + ty = YNORM(ty); + if (mapindex[tx][ty] == 0xFFFF) { + if (owned_and_navigable + (bigmap, tx, ty, terrain, own) + || (tx == ex && ty == ey && !restr2)) { + mapindex[tx][ty] = + ((i + 1) << 13) + routelen; + markedsectors++; + } + } + if (tx == ex && ty == ey) { + bpath[routelen] = 0; + while (routelen--) { + i = ((mapindex[tx][ty]) >> 13) - 1; + bpath[routelen] = dirchar[i]; + tx = tx - dx[i]; + ty = ty - dy[i]; + tx = XNORM(tx); + ty = YNORM(ty); + } + return ((s_char *)bpath); + } + } + } } - return((s_char *)bpath); - } } - } } - } - } - miny--; - maxy++; - minx -= 2; - maxx += 2; - } while (markedsectors); + miny--; + maxy++; + minx -= 2; + maxx += 2; + } while (markedsectors); - bpath[0] = 0; - return((s_char *)0); /* no route possible */ + bpath[0] = 0; + return ((s_char *)0); /* no route possible */ } /* return TRUE if sector is passable */ static int owned_and_navigable(s_char *map, int x, int y, s_char *terrain, int own) { - s_char c; - s_char *t; - s_char mapspot; /* What this spot on the bmap is */ - int negate; - struct sctstr *sect; - int rel; + s_char c; + s_char *t; + s_char mapspot; /* What this spot on the bmap is */ + int negate; + struct sctstr *sect; + int rel; - /* No terrain to check? Everything is navigable! (this - probably means we are flying) */ - if (!(*terrain)) - return (1); + /* No terrain to check? Everything is navigable! (this + probably means we are flying) */ + if (!(*terrain)) + return (1); - /* Are we checking this map? */ - if (map) { - /* Do we know what this sector is? If not, we assume it's ok, - since otherwise we'll never venture anywhere */ - mapspot = map[sctoff(x, y)]; - if (mapspot == ' ' || mapspot == 0) + /* Are we checking this map? */ + if (map) { + /* Do we know what this sector is? If not, we assume it's ok, + since otherwise we'll never venture anywhere */ + mapspot = map[sctoff(x, y)]; + if (mapspot == ' ' || mapspot == 0) return (1); - - /* Now, is it marked with a 'x' or 'X'? If so, avoid it! */ - if (mapspot == 'x' || mapspot == 'X') + + /* Now, is it marked with a 'x' or 'X'? If so, avoid it! */ + if (mapspot == 'x' || mapspot == 'X') return (0); - } else { - /* We don't know what it is since we have no map, so return ok! */ - return (1); - } - - /* Now, check this bmap entry to see if it is one of the - terrain types. */ - t = terrain; - if (*t == '~') { - negate = 1; - t++; - } else - negate = 0; + } else { + /* We don't know what it is since we have no map, so return ok! */ + return (1); + } + + /* Now, check this bmap entry to see if it is one of the + terrain types. */ + t = terrain; + if (*t == '~') { + negate = 1; + t++; + } else + negate = 0; - while (*t) { - if (*t == mapspot) + while (*t) { + if (*t == mapspot) break; - t++; - } - if (negate && *t) { - /* We found it, so we say it's bad since we are negating */ - return (0); - } else if (!negate && !*t) { - /* We didn't find it, so we say it's bad since we aren't negating */ - return (0); - } + t++; + } + if (negate && *t) { + /* We found it, so we say it's bad since we are negating */ + return (0); + } else if (!negate && !*t) { + /* We didn't find it, so we say it's bad since we aren't negating */ + return (0); + } - /* According to our bmap, this sector is ok so far. */ + /* According to our bmap, this sector is ok so far. */ - /* Ok, we made it this far. Now get the sector */ - sect = getsectp(x, y); - c = dchr[sect->sct_type].d_mnem; - /* Ok, now, check the owner if needed */ - if (own >= 0) { - if (sect->sct_own != own) { + /* Ok, we made it this far. Now get the sector */ + sect = getsectp(x, y); + c = dchr[sect->sct_type].d_mnem; + /* Ok, now, check the owner if needed */ + if (own >= 0) { + if (sect->sct_own != own) { rel = getrel(getnatp(sect->sct_own), own); /* We can't sail through deity sectors, but we can sail through any ocean */ if (rel < FRIENDLY && sect->sct_type != SCT_WATER) - return (0); - } + return (0); } - /* Ok, now, check these two sector types */ - /* check for bad harbors. */ - if (c == 'h' && sect->sct_effic < 2) - return (0); - /* check for bad bridges */ - if (c == '=' && sect->sct_effic < 60) - return (0); - /* Woo-hoo, it's ok! */ - return (1); + } + /* Ok, now, check these two sector types */ + /* check for bad harbors. */ + if (c == 'h' && sect->sct_effic < 2) + return (0); + /* check for bad bridges */ + if (c == '=' && sect->sct_effic < 60) + return (0); + /* Woo-hoo, it's ok! */ + return (1); } - diff --git a/src/lib/common/bridgefall.c b/src/lib/common/bridgefall.c index f9c165115..93534fa7e 100644 --- a/src/lib/common/bridgefall.c +++ b/src/lib/common/bridgefall.c @@ -48,45 +48,45 @@ void bridgefall(struct sctstr *sp, struct emp_qelem *list) { - register int i; - register int j; - struct sctstr sect; - struct sctstr bh_sect; - int nx; - int ny; - int nnx; - int nny; + register int i; + register int j; + struct sctstr sect; + struct sctstr bh_sect; + int nx; + int ny; + int nnx; + int nny; - for (i = 1; i <= 6; i++) { - nx = sp->sct_x + diroff[i][0]; - ny = sp->sct_y + diroff[i][1]; - getsect(nx, ny, §); - if (sect.sct_type != SCT_BSPAN) - continue; - for (j = 1; j <= 6; j++) { - nnx = nx + diroff[j][0]; - nny = ny + diroff[j][1]; - if (nnx == sp->sct_x && nny == sp->sct_y) - continue; - getsect(nnx, nny, &bh_sect); - if (bh_sect.sct_type == SCT_BHEAD && - bh_sect.sct_newtype == SCT_BHEAD) - break; - if (bh_sect.sct_type == SCT_BTOWER) - break; - /* With EASY_BRIDGES, it just has to be next to any - land */ - if (opt_EASY_BRIDGES) { - if (bh_sect.sct_type != SCT_WATER && - bh_sect.sct_type != SCT_BSPAN) - break; - } - } - if (j > 6) { - knockdown(§, list); - putsect(§); - } + for (i = 1; i <= 6; i++) { + nx = sp->sct_x + diroff[i][0]; + ny = sp->sct_y + diroff[i][1]; + getsect(nx, ny, §); + if (sect.sct_type != SCT_BSPAN) + continue; + for (j = 1; j <= 6; j++) { + nnx = nx + diroff[j][0]; + nny = ny + diroff[j][1]; + if (nnx == sp->sct_x && nny == sp->sct_y) + continue; + getsect(nnx, nny, &bh_sect); + if (bh_sect.sct_type == SCT_BHEAD && + bh_sect.sct_newtype == SCT_BHEAD) + break; + if (bh_sect.sct_type == SCT_BTOWER) + break; + /* With EASY_BRIDGES, it just has to be next to any + land */ + if (opt_EASY_BRIDGES) { + if (bh_sect.sct_type != SCT_WATER && + bh_sect.sct_type != SCT_BSPAN) + break; + } } + if (j > 6) { + knockdown(§, list); + putsect(§); + } + } } /* Knock down a bridge span. Note that this does NOT write the @@ -94,74 +94,79 @@ bridgefall(struct sctstr *sp, struct emp_qelem *list) void knockdown(struct sctstr *sp, struct emp_qelem *list) { - struct lndstr land; - struct plnstr plane; - struct nstr_item ni; - int mines; - struct natstr *np; + struct lndstr land; + struct plnstr plane; + struct nstr_item ni; + int mines; + struct natstr *np; - if (sp->sct_type == SCT_BTOWER) - mpr(sp->sct_own, "Crumble... SCREEEECH! Splash! Bridge tower falls at %s!\n", - xyas(sp->sct_x, sp->sct_y, sp->sct_own)); - else - mpr(sp->sct_own, "Crumble... SCREEEECH! Splash! Bridge falls at %s!\n", - xyas(sp->sct_x, sp->sct_y, sp->sct_own)); - sp->sct_type = SCT_WATER; - sp->sct_newtype = SCT_WATER; - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - sp->sct_mobil = 0; - sp->sct_effic = 0; + if (sp->sct_type == SCT_BTOWER) + mpr(sp->sct_own, + "Crumble... SCREEEECH! Splash! Bridge tower falls at %s!\n", + xyas(sp->sct_x, sp->sct_y, sp->sct_own)); + else + mpr(sp->sct_own, + "Crumble... SCREEEECH! Splash! Bridge falls at %s!\n", + xyas(sp->sct_x, sp->sct_y, sp->sct_own)); + sp->sct_type = SCT_WATER; + sp->sct_newtype = SCT_WATER; + makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); + sp->sct_own = 0; + sp->sct_oldown = 0; + sp->sct_mobil = 0; + sp->sct_effic = 0; - /* Sink all the units */ - snxtitem_xy(&ni,EF_LAND,sp->sct_x,sp->sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == 0) - continue; - if(land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y) - continue; - if (land.lnd_ship >= 0) - continue; - np = getnatp(land.lnd_own); - if (np->nat_flags & NF_BEEP) - mpr(land.lnd_own, "\07"); - mpr(land.lnd_own, " AARGH! %s tumbles to its doom!\n", prland(&land)); - makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_own = 0; - land.lnd_effic = 0; - putland(land.lnd_uid, &land); - } - /* Sink all the planes */ - snxtitem_xy(&ni,EF_PLANE,sp->sct_x,sp->sct_y); - while (nxtitem(&ni, (s_char *)&plane)){ - if (plane.pln_own == 0) - continue; - if(plane.pln_x != sp->sct_x || plane.pln_y != sp->sct_y) - continue; - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_ship >= 0) - continue; - /* Is this plane flying in this list? */ - if (ac_isflying(&plane, list)) - continue; - np = getnatp(plane.pln_own); - if (np->nat_flags & NF_BEEP) - mpr(plane.pln_own, "\07"); - mpr(plane.pln_own, " AARGH! %s tumbles to its doom!\n", prplane(&plane)); - makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y); - plane.pln_own = 0; - plane.pln_effic = 0; - putplane(plane.pln_uid, &plane); - } - /* - * save only the mines; zero the rest of the - * commodities. - */ - mines = getvar(V_MINE, (caddr_t)sp, EF_SECTOR); - sp->sct_nv = 0; - if (mines > 0) - (void) putvar(V_MINE, mines, (caddr_t)sp, EF_SECTOR); + /* Sink all the units */ + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y) + continue; + if (land.lnd_ship >= 0) + continue; + np = getnatp(land.lnd_own); + if (np->nat_flags & NF_BEEP) + mpr(land.lnd_own, "\07"); + mpr(land.lnd_own, " AARGH! %s tumbles to its doom!\n", + prland(&land)); + makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_own = 0; + land.lnd_effic = 0; + putland(land.lnd_uid, &land); + } + /* Sink all the planes */ + snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + if (plane.pln_x != sp->sct_x || plane.pln_y != sp->sct_y) + continue; + if (plane.pln_flags & PLN_LAUNCHED) + continue; + if (plane.pln_ship >= 0) + continue; + /* Is this plane flying in this list? */ + if (ac_isflying(&plane, list)) + continue; + np = getnatp(plane.pln_own); + if (np->nat_flags & NF_BEEP) + mpr(plane.pln_own, "\07"); + mpr(plane.pln_own, " AARGH! %s tumbles to its doom!\n", + prplane(&plane)); + makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, + plane.pln_y); + plane.pln_own = 0; + plane.pln_effic = 0; + putplane(plane.pln_uid, &plane); + } + /* + * save only the mines; zero the rest of the + * commodities. + */ + mines = getvar(V_MINE, (caddr_t)sp, EF_SECTOR); + sp->sct_nv = 0; + if (mines > 0) + (void)putvar(V_MINE, mines, (caddr_t)sp, EF_SECTOR); } - diff --git a/src/lib/common/check.c b/src/lib/common/check.c index 9e7a64022..4894091d5 100644 --- a/src/lib/common/check.c +++ b/src/lib/common/check.c @@ -38,9 +38,9 @@ #include "var.h" #include "sect.h" #include "ship.h" -#include "plane.h" +#include "plane.h" #include "nuke.h" -#include "land.h" +#include "land.h" #include "item.h" #include "nsc.h" #include "nat.h" @@ -161,5 +161,3 @@ check_comm_ok(struct comstr *commp) } return 1; } - - diff --git a/src/lib/common/damage.c b/src/lib/common/damage.c index 0705f9e29..b12c3c056 100644 --- a/src/lib/common/damage.c +++ b/src/lib/common/damage.c @@ -53,82 +53,82 @@ void ship_damage(struct shpstr *sp, int dam) { - if (dam <= 0) - return; - if (dam > 100) - dam = 100; - - mpr(sp->shp_own, "\t%s takes %d\n", prship(sp), dam); - - sp->shp_effic = damage((int)sp->shp_effic, dam); - if (sp->shp_mobil > 0) - sp->shp_mobil = damage((int)sp->shp_mobil, dam); - if (opt_FUEL && sp->shp_fuel) - sp->shp_fuel = damage((int)sp->shp_fuel, dam); - sp->shp_nv = vl_damage(dam, sp->shp_vtype, sp->shp_vamt, - (int) sp->shp_nv); + if (dam <= 0) + return; + if (dam > 100) + dam = 100; + + mpr(sp->shp_own, "\t%s takes %d\n", prship(sp), dam); + + sp->shp_effic = damage((int)sp->shp_effic, dam); + if (sp->shp_mobil > 0) + sp->shp_mobil = damage((int)sp->shp_mobil, dam); + if (opt_FUEL && sp->shp_fuel) + sp->shp_fuel = damage((int)sp->shp_fuel, dam); + sp->shp_nv = vl_damage(dam, sp->shp_vtype, sp->shp_vamt, + (int)sp->shp_nv); } void shipdamage(struct shpstr *sp, int dam) { - ship_damage(sp, (int)( dam/(1.0 + sp->shp_armor / 100.0))); + ship_damage(sp, (int)(dam / (1.0 + sp->shp_armor / 100.0))); } void land_damage(struct lndstr *lp, int dam) { - if (dam <= 0) - return; - if (dam > 100) - dam = 100; - - mpr(lp->lnd_own, "\t%s takes %d\n", prland(lp), dam); - if (lchr[(int)lp->lnd_type].l_flags & L_SPY) { - /* Spies die! */ - lp->lnd_effic = 0; - } else { - lp->lnd_effic = damage((int)lp->lnd_effic, dam); - if (lp->lnd_mobil > 0) - lp->lnd_mobil = damage((int)lp->lnd_mobil, dam); - if (opt_FUEL && lp->lnd_fuel) - lp->lnd_fuel = damage((int)lp->lnd_fuel, dam); - lp->lnd_nv = vl_damage(dam, lp->lnd_vtype, lp->lnd_vamt, - (int) lp->lnd_nv); - } + if (dam <= 0) + return; + if (dam > 100) + dam = 100; + + mpr(lp->lnd_own, "\t%s takes %d\n", prland(lp), dam); + if (lchr[(int)lp->lnd_type].l_flags & L_SPY) { + /* Spies die! */ + lp->lnd_effic = 0; + } else { + lp->lnd_effic = damage((int)lp->lnd_effic, dam); + if (lp->lnd_mobil > 0) + lp->lnd_mobil = damage((int)lp->lnd_mobil, dam); + if (opt_FUEL && lp->lnd_fuel) + lp->lnd_fuel = damage((int)lp->lnd_fuel, dam); + lp->lnd_nv = vl_damage(dam, lp->lnd_vtype, lp->lnd_vamt, + (int)lp->lnd_nv); + } } void landdamage(struct lndstr *lp, int dam) { - double damage_factor, m; - extern int land_mob_max; + double damage_factor, m; + extern int land_mob_max; - m = (double)land_mob_max; + m = (double)land_mob_max; - /* fortification reduces damage */ - damage_factor = m / (m+((double)lp->lnd_harden)); - if (damage_factor == 0.0) - damage_factor = 1.0; + /* fortification reduces damage */ + damage_factor = m / (m + ((double)lp->lnd_harden)); + if (damage_factor == 0.0) + damage_factor = 1.0; - /* vulnerable units take more damage */ - damage_factor *= lp->lnd_vul / 100.0; + /* vulnerable units take more damage */ + damage_factor *= lp->lnd_vul / 100.0; - land_damage(lp, ldround(damage_factor * dam,1)); + land_damage(lp, ldround(damage_factor * dam, 1)); } void planedamage(struct plnstr *pp, int dam) { - if (dam <= 0) - return; - if (dam > 100) - dam = 100; - - mpr(pp->pln_own, "\t%s takes %d\n", prplane(pp), dam); - pp->pln_effic = damage((int)pp->pln_effic, dam); - if (pp->pln_mobil > 0) - pp->pln_mobil = damage((int)pp->pln_mobil, dam); + if (dam <= 0) + return; + if (dam > 100) + dam = 100; + + mpr(pp->pln_own, "\t%s takes %d\n", prplane(pp), dam); + pp->pln_effic = damage((int)pp->pln_effic, dam); + if (pp->pln_mobil > 0) + pp->pln_mobil = damage((int)pp->pln_mobil, dam); } /* @@ -138,62 +138,60 @@ planedamage(struct plnstr *pp, int dam) int nukedamage(struct nchrstr *ncp, int range, int airburst) { - int dam; - int rad; - - rad = ncp->n_blast; - if (airburst) - rad = (int) (rad * 1.5); - if (rad < range) - return 0; - if (airburst) { - /* larger area, less center damage */ - dam = (int) ((ncp->n_dam * 0.75) - (range * 20)); - } else { - /* smaller area, more center damage */ - dam = (int) (ncp->n_dam / (range + 1.0)); - } - if (dam < 5) - dam = 0; - return dam; + int dam; + int rad; + + rad = ncp->n_blast; + if (airburst) + rad = (int)(rad * 1.5); + if (rad < range) + return 0; + if (airburst) { + /* larger area, less center damage */ + dam = (int)((ncp->n_dam * 0.75) - (range * 20)); + } else { + /* smaller area, more center damage */ + dam = (int)(ncp->n_dam / (range + 1.0)); + } + if (dam < 5) + dam = 0; + return dam; } int damage(register int amt, int pct) { - register int tmp; - register int lost; - - if (amt <= 0) - return 0; - tmp = amt * pct; - lost = tmp / 100; - if ((random() % 100) < (tmp % 100)) - lost++; - return amt - lost; + register int tmp; + register int lost; + + if (amt <= 0) + return 0; + tmp = amt * pct; + lost = tmp / 100; + if ((random() % 100) < (tmp % 100)) + lost++; + return amt - lost; } /* asymptotic damage to commodities, efficiency, and sectors */ int effdamage(register int amt, int dam) { - return damage(amt, PERCENT_DAMAGE(dam)); + return damage(amt, PERCENT_DAMAGE(dam)); } int commdamage(register int amt, int dam, int vtype) { - extern double people_damage; - int lost; + extern double people_damage; + int lost; - if (vtype == V_BAR && opt_SUPER_BARS) - return amt; + if (vtype == V_BAR && opt_SUPER_BARS) + return amt; - lost = amt - effdamage(amt, dam); + lost = amt - effdamage(amt, dam); - if (vtype == V_MILIT || - vtype == V_CIVIL || - vtype == V_UW) - lost = ldround(people_damage * lost, 1); - return amt - lost; + if (vtype == V_MILIT || vtype == V_CIVIL || vtype == V_UW) + lost = ldround(people_damage * lost, 1); + return amt - lost; } diff --git a/src/lib/common/file.c b/src/lib/common/file.c index 1b24ac419..f8e3ad9ba 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -54,123 +54,121 @@ #include #endif -static void fillcache(struct empfile *ep, int start); +static void fillcache(struct empfile *ep, int start); int ef_open(int type, int mode, int how) { - register struct empfile *ep; - static int block; - int size; + register struct empfile *ep; + static int block; + int size; #if defined(_WIN32) mode |= _O_BINARY; #endif - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if ((ep->fd = open(ep->file, mode, 0660)) < 0) { - logerror("%s: open failed", ep->file); - return 0; - } - if (block == 0) - block = blksize(ep->fd); - ep->baseid = 0; - ep->cids = 0; - ep->mode = mode; - ep->flags |= how; - ep->fids = fsize(ep->fd) / ep->size; - if (ep->flags & EFF_MEM) - ep->csize = ep->fids; - else - ep->csize = block / ep->size; - size = ep->csize * ep->size; - ep->cache = (s_char *)malloc(size); - if ((ep->cache == 0) && (size !=0)) { - logerror("ef_open: %s malloc(%d) failed\n", ep->file, size); - return 0; - } - if (ep->flags & EFF_MEM) { - if (read(ep->fd, ep->cache, size) != size) { - logerror("ef_open: read(%s) failed\n", ep->file); - return 0; - } - ep->cids = size / ep->size; + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if ((ep->fd = open(ep->file, mode, 0660)) < 0) { + logerror("%s: open failed", ep->file); + return 0; + } + if (block == 0) + block = blksize(ep->fd); + ep->baseid = 0; + ep->cids = 0; + ep->mode = mode; + ep->flags |= how; + ep->fids = fsize(ep->fd) / ep->size; + if (ep->flags & EFF_MEM) + ep->csize = ep->fids; + else + ep->csize = block / ep->size; + size = ep->csize * ep->size; + ep->cache = (s_char *)malloc(size); + if ((ep->cache == 0) && (size != 0)) { + logerror("ef_open: %s malloc(%d) failed\n", ep->file, size); + return 0; + } + if (ep->flags & EFF_MEM) { + if (read(ep->fd, ep->cache, size) != size) { + logerror("ef_open: read(%s) failed\n", ep->file); + return 0; } - return 1; + ep->cids = size / ep->size; + } + return 1; } int ef_close(int type) { - register struct empfile *ep; - int r; + register struct empfile *ep; + int r; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (ep->cache == 0) { - /* no cache implies never opened */ - return 0; - } - ef_flush(type); - ep->flags &= ~EFF_MEM; - free(ep->cache); - ep->cache = 0; - if ((r = close(ep->fd)) < 0) { - logerror("ef_close: %s close(%d) -> %d", - ep->name, ep->fd, r); - } - return 1; + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (ep->cache == 0) { + /* no cache implies never opened */ + return 0; + } + ef_flush(type); + ep->flags &= ~EFF_MEM; + free(ep->cache); + ep->cache = 0; + if ((r = close(ep->fd)) < 0) { + logerror("ef_close: %s close(%d) -> %d", ep->name, ep->fd, r); + } + return 1; } int ef_flush(int type) { - register struct empfile *ep; - int size; - int r; + register struct empfile *ep; + int size; + int r; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (ep->cache == 0) { - /* no cache implies never opened */ - return 0; + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (ep->cache == 0) { + /* no cache implies never opened */ + return 0; + } + size = ep->csize * ep->size; + if (ep->mode > 0 && (ep->flags & EFF_MEM)) { + if ((r = lseek(ep->fd, 0L, 0)) < 0) { + logerror("ef_flush: %s cache lseek(%d, 0L, 0) -> %d", + ep->name, ep->fd, r); + return 0; } - size = ep->csize * ep->size; - if (ep->mode > 0 && (ep->flags & EFF_MEM)) { - if ((r = lseek(ep->fd, 0L, 0)) < 0) { - logerror("ef_flush: %s cache lseek(%d, 0L, 0) -> %d", - ep->name, ep->fd, r); - return 0; - } - if (write(ep->fd, ep->cache, size) != size) { - logerror("ef_flush: %s cache write(%d, %x, %d) -> %d", - ep->name, ep->fd, ep->cache, ep->size, r); - return 0; - } + if (write(ep->fd, ep->cache, size) != size) { + logerror("ef_flush: %s cache write(%d, %x, %d) -> %d", + ep->name, ep->fd, ep->cache, ep->size, r); + return 0; } - /*ef_zapcache(type);*/ - return 1; + } + /*ef_zapcache(type); */ + return 1; } s_char * ef_ptr(int type, int id) { - register struct empfile *ep; + register struct empfile *ep; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (id < 0 || id >= ep->fids) - return 0; - if ((ep->flags & EFF_MEM) == 0) { - logerror("ef_ptr: (%s) only valid for EFF_MEM entries", - ep->file); - return 0; - } - return (s_char *) (ep->cache + ep->size * id); + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (id < 0 || id >= ep->fids) + return 0; + if ((ep->flags & EFF_MEM) == 0) { + logerror("ef_ptr: (%s) only valid for EFF_MEM entries", ep->file); + return 0; + } + return (s_char *)(ep->cache + ep->size * id); } /* @@ -180,44 +178,44 @@ ef_ptr(int type, int id) int ef_read(int type, int id, caddr_t ptr) { - register struct empfile *ep; - caddr_t from; + register struct empfile *ep; + caddr_t from; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (id < 0) + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (id < 0) + return 0; + if (ep->flags & EFF_MEM) { + if (id >= ep->fids) + return 0; + from = ep->cache + (id * ep->size); + } else { + if (id >= ep->fids) { + ep->fids = fsize(ep->fd) / ep->size; + if (id >= ep->fids) return 0; - if (ep->flags & EFF_MEM) { - if (id >= ep->fids) - return 0; - from = ep->cache + (id * ep->size); - } else { - if (id >= ep->fids) { - ep->fids = fsize(ep->fd) / ep->size; - if (id >= ep->fids) - return 0; - } - if (ep->baseid + ep->cids <= id || ep->baseid > id) - fillcache(ep, id); - from = ep->cache + (id - ep->baseid) * ep->size; } - bcopy(from, ptr, ep->size); - - if (ep->postread) - ep->postread(id, ptr); - return 1; + if (ep->baseid + ep->cids <= id || ep->baseid > id) + fillcache(ep, id); + from = ep->cache + (id - ep->baseid) * ep->size; + } + bcopy(from, ptr, ep->size); + + if (ep->postread) + ep->postread(id, ptr); + return 1; } static void fillcache(struct empfile *ep, int start) { - int n; + int n; - ep->baseid = start; - lseek(ep->fd, start * ep->size, 0); - n = read(ep->fd, ep->cache, ep->csize * ep->size); - ep->cids = n / ep->size; + ep->baseid = start; + lseek(ep->fd, start * ep->size, 0); + n = read(ep->fd, ep->cache, ep->csize * ep->size); + ep->cids = n / ep->size; } #ifdef notdef @@ -228,33 +226,33 @@ fillcache(struct empfile *ep, int start) int ef_nbread(int type, int id, caddr_t ptr) { - register struct empfile *ep; - int r; + register struct empfile *ep; + int r; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (id < 0) - return 0; - if (id >= ep->fids) { - ep->fids = fsize(ep->fd) / ep->size; - if (id >= ep->fids) - return 0; - } - if ((r = lseek(ep->fd, id * ep->size, 0)) < 0) { - logerror("ef_nbread: %s #%d lseek(%d, %d, 0) -> %d", - ep->name, id, ep->fd, id * ep->size, r); - return 0; - } - if ((r = read(ep->fd, ptr, ep->size)) != ep->size) { - logerror("ef_nbread: %s #%d read(%d, %x, %d) -> %d", - ep->name, id, ep->fd, ptr, ep->size, r); - return 0; - } - ef_zapcache(type); - if (ep->postread) - ep->postread(id, ptr); - return 1; + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (id < 0) + return 0; + if (id >= ep->fids) { + ep->fids = fsize(ep->fd) / ep->size; + if (id >= ep->fids) + return 0; + } + if ((r = lseek(ep->fd, id * ep->size, 0)) < 0) { + logerror("ef_nbread: %s #%d lseek(%d, %d, 0) -> %d", + ep->name, id, ep->fd, id * ep->size, r); + return 0; + } + if ((r = read(ep->fd, ptr, ep->size)) != ep->size) { + logerror("ef_nbread: %s #%d read(%d, %x, %d) -> %d", + ep->name, id, ep->fd, ptr, ep->size, r); + return 0; + } + ef_zapcache(type); + if (ep->postread) + ep->postread(id, ptr); + return 1; } #endif @@ -265,49 +263,51 @@ ef_nbread(int type, int id, caddr_t ptr) int ef_write(int type, int id, caddr_t ptr) { - register int r; - register struct empfile *ep; - s_char *to; + register int r; + register struct empfile *ep; + s_char *to; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (id > 65536) { - /* largest unit id; this may bite us in large games */ - logerror("ef_write: type %d id %d is too large!\n", type, id); - return 0; - } - if ((r = lseek(ep->fd, id * ep->size, 0)) < 0) { - logerror("ef_write: %s #%d lseek(%d, %d, 0) -> %d", - ep->name, id, ep->fd, id * ep->size, r); - return 0; - } - if (ep->prewrite) - ep->prewrite(id, ptr); - if ((r = write(ep->fd, ptr, ep->size)) != ep->size) { - logerror("ef_write: %s #%d write(%d, %x, %d) -> %d", - ep->name, id, ep->fd, ptr, ep->size, r); - return 0; - } - if (id >= ep->baseid && id < ep->baseid + ep->cids) { - /* update the cache if necessary */ - to = ep->cache + (id - ep->baseid) * ep->size; - bcopy(ptr, to, ep->size); - } - if (id > ep->fids) { - logerror("WARNING ef_write: expanded %s by more than one id", - ep->name); - log_last_commands(); - } - if (id >= ep->fids) { - if (ep->flags & EFF_MEM) { - logerror("file %s went beyond %d items; won't be able toread item w/o restart", ep->name, ep->fids); - } else { - /* write expanded file; ep->fids = last id + 1 */ - ep->fids = id + 1; - } + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (id > 65536) { + /* largest unit id; this may bite us in large games */ + logerror("ef_write: type %d id %d is too large!\n", type, id); + return 0; + } + if ((r = lseek(ep->fd, id * ep->size, 0)) < 0) { + logerror("ef_write: %s #%d lseek(%d, %d, 0) -> %d", + ep->name, id, ep->fd, id * ep->size, r); + return 0; + } + if (ep->prewrite) + ep->prewrite(id, ptr); + if ((r = write(ep->fd, ptr, ep->size)) != ep->size) { + logerror("ef_write: %s #%d write(%d, %x, %d) -> %d", + ep->name, id, ep->fd, ptr, ep->size, r); + return 0; + } + if (id >= ep->baseid && id < ep->baseid + ep->cids) { + /* update the cache if necessary */ + to = ep->cache + (id - ep->baseid) * ep->size; + bcopy(ptr, to, ep->size); + } + if (id > ep->fids) { + logerror("WARNING ef_write: expanded %s by more than one id", + ep->name); + log_last_commands(); + } + if (id >= ep->fids) { + if (ep->flags & EFF_MEM) { + logerror + ("file %s went beyond %d items; won't be able toread item w/o restart", + ep->name, ep->fids); + } else { + /* write expanded file; ep->fids = last id + 1 */ + ep->fids = id + 1; } - return 1; + } + return 1; } #ifdef notdef @@ -318,177 +318,178 @@ ef_write(int type, int id, caddr_t ptr) int ef_nbwrite(int type, int id, caddr_t ptr) { - register struct empfile *ep; - register int r; + register struct empfile *ep; + register int r; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - if (id > 65536) { - /* largest unit id; this may bite us in large games */ - logerror("ef_nbwrite: %s id %d is too large!\n", ep->name, id); - return 0; - } - if ((r = lseek(ep->fd, id * ep->size, 0)) < 0) { - logerror("ef_nbwrite: %s #%d lseek(%d, %d, 0) -> %d", - ep->name, id, ep->fd, id * ep->size, r); - return 0; - } - if (ep->prewrite) - ep->prewrite(id, ptr); - if ((r = write(ep->fd, ptr, ep->size)) != ep->size) { - logerror("ef_nbwrite: %s #%d write(%d, %x, %d) -> %d", - ep->name, id, ep->fd, ptr, ep->size, r); - return 0; - } - ef_zapcache(type); - if (id >= ep->fids) { - /* write expanded file; ep->fids = last id + 1 */ - ep->fids = id + 1; - } - return 1; + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + if (id > 65536) { + /* largest unit id; this may bite us in large games */ + logerror("ef_nbwrite: %s id %d is too large!\n", ep->name, id); + return 0; + } + if ((r = lseek(ep->fd, id * ep->size, 0)) < 0) { + logerror("ef_nbwrite: %s #%d lseek(%d, %d, 0) -> %d", + ep->name, id, ep->fd, id * ep->size, r); + return 0; + } + if (ep->prewrite) + ep->prewrite(id, ptr); + if ((r = write(ep->fd, ptr, ep->size)) != ep->size) { + logerror("ef_nbwrite: %s #%d write(%d, %x, %d) -> %d", + ep->name, id, ep->fd, ptr, ep->size, r); + return 0; + } + ef_zapcache(type); + if (id >= ep->fids) { + /* write expanded file; ep->fids = last id + 1 */ + ep->fids = id + 1; + } + return 1; } #endif int ef_extend(int type, int count) { - register struct empfile *ep; - char *ptr; - int cur, max; - int mode, how; - int r; + register struct empfile *ep; + char *ptr; + int cur, max; + int mode, how; + int r; - if (ef_check(type) < 0) - return 0; - ep = &empfile[type]; - max = ep->fids + count; - cur = ep->fids; - ptr = (s_char *)calloc(1, ep->size); - if ((r = lseek(ep->fd, ep->fids * ep->size, 0)) < 0) { - logerror("ef_extend: %s +#%d lseek(%d, %d, 0) -> %d", - ep->name, count, ep->fd, ep->fids * ep->size, r); - return 0; - } - for (cur = ep->fids; cur < max; cur++) { - if (ep->init) - ep->init(cur, ptr); - if ((r = write(ep->fd, ptr, ep->size)) != ep->size) { - logerror("ef_extend: %s +#%d write(%d, %x, %d) -> %d", - ep->name, count, ep->fd, ptr, ep->size, r); - return 0; - } - } - free(ptr); - if (ep->flags & EFF_MEM) { - /* XXX this will cause problems if there are ef_ptrs (to the - * old allocated structure) active when we do the re-open */ - mode = ep->mode; - how = ep->flags; - ef_close(type); - ef_open(type, mode, how); - } else { - ep->fids += count; + if (ef_check(type) < 0) + return 0; + ep = &empfile[type]; + max = ep->fids + count; + cur = ep->fids; + ptr = (s_char *)calloc(1, ep->size); + if ((r = lseek(ep->fd, ep->fids * ep->size, 0)) < 0) { + logerror("ef_extend: %s +#%d lseek(%d, %d, 0) -> %d", + ep->name, count, ep->fd, ep->fids * ep->size, r); + return 0; + } + for (cur = ep->fids; cur < max; cur++) { + if (ep->init) + ep->init(cur, ptr); + if ((r = write(ep->fd, ptr, ep->size)) != ep->size) { + logerror("ef_extend: %s +#%d write(%d, %x, %d) -> %d", + ep->name, count, ep->fd, ptr, ep->size, r); + return 0; } - return 1; + } + free(ptr); + if (ep->flags & EFF_MEM) { + /* XXX this will cause problems if there are ef_ptrs (to the + * old allocated structure) active when we do the re-open */ + mode = ep->mode; + how = ep->flags; + ef_close(type); + ef_open(type, mode, how); + } else { + ep->fids += count; + } + return 1; } void ef_zapcache(int type) { - register struct empfile *ep = &empfile[type]; - if ((ep->flags & EFF_MEM) == 0) { - ep->cids = 0; - ep->baseid = -1; - } + register struct empfile *ep = &empfile[type]; + if ((ep->flags & EFF_MEM) == 0) { + ep->cids = 0; + ep->baseid = -1; + } } struct castr * ef_cadef(int type) { - return empfile[type].cadef; + return empfile[type].cadef; } int ef_nelem(int type) { - return empfile[type].fids; + return empfile[type].fids; } int ef_flags(int type) { - return empfile[type].flags; + return empfile[type].flags; } int ef_lock(int type) { - return file_lock(empfile[type].fd); + return file_lock(empfile[type].fd); } int ef_unlock(int type) { - return file_unlock(empfile[type].fd); + return file_unlock(empfile[type].fd); } time_t ef_mtime(int type) { - extern time_t fdate(int fd); + extern time_t fdate(int fd); - if (empfile[type].fd <= 0) - return 0; - return fdate(empfile[type].fd); + if (empfile[type].fd <= 0) + return 0; + return fdate(empfile[type].fd); } int -ef_vars(int type, register s_char *sp, u_char **nvp, u_char **vp, u_short **ap) +ef_vars(int type, register s_char *sp, u_char **nvp, u_char **vp, + u_short **ap) { - register struct empfile *ef; + register struct empfile *ef; - if (ef_check(type) < 0) - return 0; - ef = &empfile[type]; - if ((ef->flags & EFF_COM) == 0) - return -1; - *nvp = (u_char *) (sp + ef->varoffs[0]); - *vp = (u_char *) (sp + ef->varoffs[1]); - *ap = (u_short *) (sp + ef->varoffs[2]); - return ef->maxvars; + if (ef_check(type) < 0) + return 0; + ef = &empfile[type]; + if ((ef->flags & EFF_COM) == 0) + return -1; + *nvp = (u_char *)(sp + ef->varoffs[0]); + *vp = (u_char *)(sp + ef->varoffs[1]); + *ap = (u_short *)(sp + ef->varoffs[2]); + return ef->maxvars; } int ef_byname(s_char *name) { - register struct empfile *ef; - register int i; - int len; - - len = strlen(name); - for (i=0; iname, name, min(len, strlen(ef->name))) == 0) - return i; - } - return -1; + register struct empfile *ef; + register int i; + int len; + + len = strlen(name); + for (i = 0; i < EF_MAX; i++) { + ef = &empfile[i]; + if (strncmp(ef->name, name, min(len, strlen(ef->name))) == 0) + return i; + } + return -1; } s_char * ef_nameof(int type) { - if (type < 0 || type >= EF_MAX) - return "bad item type"; - return empfile[type].name; + if (type < 0 || type >= EF_MAX) + return "bad item type"; + return empfile[type].name; } int ef_check(int type) { - if (type < 0 || type >= EF_MAX) { - logerror("ef_ptr: bad EF_type %d\n", type); - return -1; - } - return 0; + if (type < 0 || type >= EF_MAX) { + logerror("ef_ptr: bad EF_type %d\n", type); + return -1; + } + return 0; } diff --git a/src/lib/common/fsize.c b/src/lib/common/fsize.c index 2b6990d82..3a8c8da33 100644 --- a/src/lib/common/fsize.c +++ b/src/lib/common/fsize.c @@ -48,11 +48,11 @@ int fsize(int fd) { - struct stat statb; + struct stat statb; - if (fstat(fd, &statb) < 0) - return -1; - return statb.st_size; + if (fstat(fd, &statb) < 0) + return -1; + return statb.st_size; } /* @@ -63,30 +63,30 @@ int blksize(int fd) { #if defined(_WIN32) - return 2048; + return 2048; #elif (!defined (aix) && !defined (sgi)) - struct stat statb; + struct stat statb; - if (fstat(fd, &statb) < 0) - return 1024; - return statb.st_blksize; -#else + if (fstat(fd, &statb) < 0) return 1024; + return statb.st_blksize; +#else + return 1024; #endif } time_t fdate(int fd) { - struct stat statb; + struct stat statb; - if (fstat(fd, &statb) < 0) - return 0; - return statb.st_mtime; + if (fstat(fd, &statb) < 0) + return 0; + return statb.st_mtime; } void filetruncate(s_char *name) { - close(open(name, O_RDWR|O_TRUNC, 0660)); + close(open(name, O_RDWR | O_TRUNC, 0660)); } diff --git a/src/lib/common/getvar.c b/src/lib/common/getvar.c index 3a5499f86..7c2d84775 100644 --- a/src/lib/common/getvar.c +++ b/src/lib/common/getvar.c @@ -39,80 +39,78 @@ int getvar(int vtype, s_char *sp, int ptype) { - u_char *vtypep; - u_short *vamtp; - u_char *nvp; - int amt; + u_char *vtypep; + u_short *vamtp; + u_char *nvp; + int amt; - if (ef_vars(ptype, sp, &nvp, &vtypep, &vamtp) < 0) { - logerror("getvar: ptype %d has no vars", ptype); - return 0; - } - amt = vl_find(vtype, vtypep, vamtp, (int) *nvp); - if (amt < 0) { - logerror("getvar: vl_find returns %d, vtype %d", - amt, vtype); - return 0; - } - return amt; + if (ef_vars(ptype, sp, &nvp, &vtypep, &vamtp) < 0) { + logerror("getvar: ptype %d has no vars", ptype); + return 0; + } + amt = vl_find(vtype, vtypep, vamtp, (int)*nvp); + if (amt < 0) { + logerror("getvar: vl_find returns %d, vtype %d", amt, vtype); + return 0; + } + return amt; } int getvec(int class, int *vec, s_char *sp, int ptype) { - u_char *vtypep; - u_short *vamtp; - u_char *nvp; - int nv; + u_char *vtypep; + u_short *vamtp; + u_char *nvp; + int nv; - if (ef_vars(ptype, sp, &nvp, &vtypep, &vamtp) < 0) { - logerror("getvec: ptype %d has no vars", ptype); - return 0; - } - nv = vl_getvec(vtypep, vamtp, (int)*nvp, class, vec); - if (nv < 0) { - logerror("vl_getvec: returns %d, ptype %d\n", - nv, ptype); - return 0; - } - return nv; + if (ef_vars(ptype, sp, &nvp, &vtypep, &vamtp) < 0) { + logerror("getvec: ptype %d has no vars", ptype); + return 0; + } + nv = vl_getvec(vtypep, vamtp, (int)*nvp, class, vec); + if (nv < 0) { + logerror("vl_getvec: returns %d, ptype %d\n", nv, ptype); + return 0; + } + return nv; } int putvar(int vtype, int amt, s_char *sp, int ptype) { - u_char *vtypep; - u_short *vamtp; - u_char *nvp; - int maxv; + u_char *vtypep; + u_short *vamtp; + u_char *nvp; + int maxv; - if (vtype < 0 || vtype > V_MAX) { - logerror("putvar: bad vtype %d\n", vtype); - return 0; - } - if ((maxv = ef_vars(ptype, sp, &nvp, &vtypep, &vamtp)) < 0) { - logerror("putvar: ptype %d has no vars", ptype); - return 0; - } - if (amt < 0) - amt = 0; - return vl_set(vtype, (u_int)amt, vtypep, vamtp, nvp, maxv); + if (vtype < 0 || vtype > V_MAX) { + logerror("putvar: bad vtype %d\n", vtype); + return 0; + } + if ((maxv = ef_vars(ptype, sp, &nvp, &vtypep, &vamtp)) < 0) { + logerror("putvar: ptype %d has no vars", ptype); + return 0; + } + if (amt < 0) + amt = 0; + return vl_set(vtype, (u_int)amt, vtypep, vamtp, nvp, maxv); } int putvec(int class, int *vec, s_char *sp, int ptype) { - u_char *vtypep; - u_short *vamtp; - u_char *nvp; - int maxv,x; + u_char *vtypep; + u_short *vamtp; + u_char *nvp; + int maxv, x; - if ((maxv = ef_vars(ptype, sp, &nvp, &vtypep, &vamtp)) < 0) { - logerror("putvec: ptype %d has no vars", ptype); - return 0; - } - for(x=0;xnat_level[NAT_HLEV]; if (hap_fact && tnat->nat_level[NAT_HLEV]) - hap_fact = tnat->nat_level[NAT_HLEV] / hap_fact; + hap_fact = tnat->nat_level[NAT_HLEV] / hap_fact; else if (!hap_fact && !tnat->nat_level[NAT_HLEV]) - hap_fact = 1.0; - else if (tnat->nat_level[NAT_HLEV]) /* Target has happy, better fighting */ - hap_fact = 2.0; - else /* Target has no happy, worse fighting */ - hap_fact = 0.8; + hap_fact = 1.0; + else if (tnat->nat_level[NAT_HLEV]) /* Target has happy, better fighting */ + hap_fact = 2.0; + else /* Target has no happy, worse fighting */ + hap_fact = 0.8; if (hap_fact > 2.0) - hap_fact = 2.0; + hap_fact = 2.0; if (hap_fact < 0.8) - hap_fact = 0.8; + hap_fact = 0.8; return hap_fact; } diff --git a/src/lib/common/hours.c b/src/lib/common/hours.c index 5e0819b79..93737ca6c 100644 --- a/src/lib/common/hours.c +++ b/src/lib/common/hours.c @@ -58,43 +58,43 @@ int gamehours(time_t now, int *hour) { - extern s_char *game_days,*game_hours; - extern int errno; - extern struct tm *localtime(const time_t *); - register s_char *bp; - register struct tm *tm; - int day; - int curtime; - int okday[7]; - int tomorrow; + extern s_char *game_days, *game_hours; + extern int errno; + extern struct tm *localtime(const time_t *); + register s_char *bp; + register struct tm *tm; + int day; + int curtime; + int okday[7]; + int tomorrow; - tm = localtime(&now); - curtime = tm->tm_min + tm->tm_hour * 60; - bp = game_days; - if (*bp != 0) { - for (day=0; day<7; day++) - okday[day] = 0; - while (NULL != (bp = kw_parse(CF_WEEKDAY, bp, &day))) - okday[day] = 1; - } else { - for (day=0; day<7; day++) - okday[day] = 1; - } - if (!okday[tm->tm_wday]) - return 0; - bp = game_hours; - if (*bp != 0) { - while (NULL != (bp = kw_parse(CF_TIMERANGE, bp, hour))) - if (curtime >= hour[0] && curtime < hour[1]) - break; - if (bp == 0) - return 0; - } else { - hour[0] = 0; - hour[1] = 24*60; - } - tomorrow = tm->tm_wday + 1; - if (tomorrow >= 7) - tomorrow = 0; - return 1; + tm = localtime(&now); + curtime = tm->tm_min + tm->tm_hour * 60; + bp = game_days; + if (*bp != 0) { + for (day = 0; day < 7; day++) + okday[day] = 0; + while (NULL != (bp = kw_parse(CF_WEEKDAY, bp, &day))) + okday[day] = 1; + } else { + for (day = 0; day < 7; day++) + okday[day] = 1; + } + if (!okday[tm->tm_wday]) + return 0; + bp = game_hours; + if (*bp != 0) { + while (NULL != (bp = kw_parse(CF_TIMERANGE, bp, hour))) + if (curtime >= hour[0] && curtime < hour[1]) + break; + if (bp == 0) + return 0; + } else { + hour[0] = 0; + hour[1] = 24 * 60; + } + tomorrow = tm->tm_wday + 1; + if (tomorrow >= 7) + tomorrow = 0; + return 1; } diff --git a/src/lib/common/keyword.c b/src/lib/common/keyword.c index 98565382d..6a502d8b5 100644 --- a/src/lib/common/keyword.c +++ b/src/lib/common/keyword.c @@ -40,62 +40,62 @@ #include "common.h" struct kwtab { - struct kwtab *next; - s_char *name; - s_char *text; + struct kwtab *next; + s_char *name; + s_char *text; }; struct kwtab *kw_list; int -kw_read(FILE *fp) +kw_read(FILE * fp) { - register struct kwtab *kw; - register struct kwtab *next; - s_char buf[255]; - s_char *p; - int n; - - for (kw = kw_list; kw != 0; kw = next) { - next = kw->next; - free(kw->name); - free(kw->text); - free(kw); + register struct kwtab *kw; + register struct kwtab *next; + s_char buf[255]; + s_char *p; + int n; + + for (kw = kw_list; kw != 0; kw = next) { + next = kw->next; + free(kw->name); + free(kw->text); + free(kw); + } + kw_list = 0; + for (n = 0; fgets(buf, sizeof(buf), fp) != 0; n++) { + /* Allow for comments.. any line starting with # */ + if (buf[0] == '#') + continue; + p = rindex(buf, '\n'); + if (p != 0) + *p = 0; + if ((p = index(buf, ':')) == 0) { + logerror("kw_read: Bad keyword line #%d\n", n); + return 0; } - kw_list = 0; - for (n=0; fgets(buf, sizeof(buf), fp) != 0; n++) { - /* Allow for comments.. any line starting with # */ - if (buf[0] == '#') - continue; - p = rindex(buf, '\n'); - if (p != 0) - *p = 0; - if ((p = index(buf, ':')) == 0) { - logerror("kw_read: Bad keyword line #%d\n", n); - return 0; - } - *p++ = 0; - while (*p && isspace(*p)) - p++; - kw = (struct kwtab *) malloc(sizeof(*kw)); - kw->name = strcpy(malloc(strlen(buf)+1), buf); - kw->text = strcpy(malloc(strlen(p)+1), p); - kw->next = kw_list; - kw_list = kw; - } - return n; + *p++ = 0; + while (*p && isspace(*p)) + p++; + kw = (struct kwtab *)malloc(sizeof(*kw)); + kw->name = strcpy(malloc(strlen(buf) + 1), buf); + kw->text = strcpy(malloc(strlen(p) + 1), p); + kw->next = kw_list; + kw_list = kw; + } + return n; } s_char * kw_find(s_char *name) { - register struct kwtab *kw; + register struct kwtab *kw; - for (kw = kw_list; kw != 0; kw = kw->next) { - if (strcmp(kw->name, name) == 0) - return kw->text; - } - return 0; + for (kw = kw_list; kw != 0; kw = kw->next) { + if (strcmp(kw->name, name) == 0) + return kw->text; + } + return 0; } #define CF_VALUE 1 @@ -109,91 +109,94 @@ kw_find(s_char *name) s_char * kw_parse(int type, s_char *text, int *data) { - s_char *get_time(s_char *ptr, int *data); - s_char *weekday(s_char *ptr, int *data); - s_char *next; - - while (isspace(*text)) - text++; - switch (type) { - case CF_VALUE: - *data = atoip(&text); - break; - case CF_TIME: - text = get_time(text, &data[0]); - break; - case CF_TIMERANGE: - if ((next = index(text, '-')) == 0) - return 0; - next++; - if ((text = get_time(text, &data[0])) == 0) - return 0; - text = get_time(next, &data[1]); - break; - case CF_WEEKDAY: - text = weekday(text, &data[0]); - break; - default: - text = 0; - break; - } - return text; + s_char *get_time(s_char *ptr, int *data); + s_char *weekday(s_char *ptr, int *data); + s_char *next; + + while (isspace(*text)) + text++; + switch (type) { + case CF_VALUE: + *data = atoip(&text); + break; + case CF_TIME: + text = get_time(text, &data[0]); + break; + case CF_TIMERANGE: + if ((next = index(text, '-')) == 0) + return 0; + next++; + if ((text = get_time(text, &data[0])) == 0) + return 0; + text = get_time(next, &data[1]); + break; + case CF_WEEKDAY: + text = weekday(text, &data[0]); + break; + default: + text = 0; + break; + } + return text; } struct day { - s_char *string; - int day[7]; + s_char *string; + int day[7]; } day[] = { - { "smtwtfs", { -1, 0, -1, 2, -1, 4, -1 } }, - { "uouehra", { 0, 1, 2, 3, 4, 5, 6 } } + { + "smtwtfs", { + -1, 0, -1, 2, -1, 4, -1}}, { + "uouehra", { + 0, 1, 2, 3, 4, 5, 6}} }; s_char * weekday(s_char *ptr, int *data) { - register s_char *string; - register int c; - register int n; - - c = *ptr++; - if (isupper(c)) - c = tolower(c); - string = day[0].string; - for (n=0; n<7; n++) { - if (string[n] != c) - continue; - if (day[0].day[n] >= 0) - break; - if (day[1].string[n] == *ptr) - break; - } - if (n == 7) - return 0; - *data = day[1].day[n]; - while (*ptr && !isspace(*ptr)) - ptr++; - return ptr; + register s_char *string; + register int c; + register int n; + + c = *ptr++; + if (isupper(c)) + c = tolower(c); + string = day[0].string; + for (n = 0; n < 7; n++) { + if (string[n] != c) + continue; + if (day[0].day[n] >= 0) + break; + if (day[1].string[n] == *ptr) + break; + } + if (n == 7) + return 0; + *data = day[1].day[n]; + while (*ptr && !isspace(*ptr)) + ptr++; + return ptr; } s_char * get_time(s_char *ptr, int *data) { - int hour; - int minute; + int hour; + int minute; + if (!isdigit(*ptr)) + return 0; + hour = atoip(&ptr); + minute = 0; + if (*ptr) { + if (*ptr != ':') + return 0; + ptr++; if (!isdigit(*ptr)) - return 0; - hour = atoip(&ptr); - minute = 0; - if (*ptr) { - if (*ptr != ':') - return 0; - ptr++; - if (!isdigit(*ptr)) - return 0; - minute = atoip(&ptr); - } - *data = (hour * 60) + minute; - return ptr; + return 0; + minute = atoip(&ptr); + } + *data = (hour * 60) + minute; + return ptr; } diff --git a/src/lib/common/land.c b/src/lib/common/land.c index af263b881..a7e415b82 100644 --- a/src/lib/common/land.c +++ b/src/lib/common/land.c @@ -47,52 +47,52 @@ int adj_units(coord x, coord y, natid own) { - register int i; - struct sctstr sect; + register int i; + struct sctstr sect; - for (i = DIR_FIRST; i <= DIR_LAST; i++) { - getsect(x + diroff[i][0], y + diroff[i][1], §); - if (has_units(sect.sct_x, sect.sct_y, own, 0)) - return 1; - } - return 0; + for (i = DIR_FIRST; i <= DIR_LAST; i++) { + getsect(x + diroff[i][0], y + diroff[i][1], §); + if (has_units(sect.sct_x, sect.sct_y, own, 0)) + return 1; + } + return 0; } int has_units(coord x, coord y, natid cn, struct lndstr *lp) { - register int n; - struct lndstr land; - - for (n=0; ef_read(EF_LAND, n, (s_char *)&land); n++) { - if(land.lnd_x != x || land.lnd_y != y) - continue; - if (lp) { - /* Check this unit. If it is this one, we don't want - it included in the count. */ - if (lp->lnd_uid == land.lnd_uid) - continue; - } - if (land.lnd_own == cn) - return 1; + register int n; + struct lndstr land; + + for (n = 0; ef_read(EF_LAND, n, (s_char *)&land); n++) { + if (land.lnd_x != x || land.lnd_y != y) + continue; + if (lp) { + /* Check this unit. If it is this one, we don't want + it included in the count. */ + if (lp->lnd_uid == land.lnd_uid) + continue; } + if (land.lnd_own == cn) + return 1; + } - return 0; + return 0; } int has_units_with_mob(coord x, coord y, natid cn) { - struct nstr_item ni; - struct lndstr land; - - snxtitem_xy(&ni,EF_LAND,x,y); - while(nxtitem(&ni,(s_char *)&land)) { - if (land.lnd_own != cn) - continue; - if (land.lnd_mobil > 0) - return 1; - } + struct nstr_item ni; + struct lndstr land; + + snxtitem_xy(&ni, EF_LAND, x, y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own != cn) + continue; + if (land.lnd_mobil > 0) + return 1; + } - return 0; + return 0; } diff --git a/src/lib/common/log.c b/src/lib/common/log.c index 5947a34f7..5d6b31408 100644 --- a/src/lib/common/log.c +++ b/src/lib/common/log.c @@ -48,12 +48,12 @@ #include "player.h" #include "common.h" -static s_char *logfile = 0; +static s_char *logfile = 0; s_char * getlogfile() { - return (s_char *)logfile; + return (s_char *)logfile; } /* @@ -62,103 +62,105 @@ getlogfile() void loginit(void) { - extern s_char program[]; - extern s_char *datadir; - s_char buf[1024]; + extern s_char program[]; + extern s_char *datadir; + s_char buf[1024]; #if !defined(_WIN32) - sprintf(buf, "%s/%s.log", datadir, program); + sprintf(buf, "%s/%s.log", datadir, program); #else - sprintf(buf, "%s\\%s.log", datadir, program); + sprintf(buf, "%s\\%s.log", datadir, program); #endif - logfile = malloc(strlen(buf) + 1); - strcpy(logfile, buf); + logfile = malloc(strlen(buf) + 1); + strcpy(logfile, buf); } /*VARARGS*/ -void logerror(s_char *format, ...) +void +logerror(s_char *format, ...) { #if !defined(Rel4) && !defined(__linux__) && !defined(__ppc__) - extern s_char *sys_errlist[]; -#endif + extern s_char *sys_errlist[]; +#endif #ifndef sgi - extern int errno; + extern int errno; #endif /* sgi */ - va_list list; - time_t now; - s_char buf[512]; - s_char cbuf[512]; - s_char buf1[512]; - int logf; + va_list list; + time_t now; + s_char buf[512]; + s_char cbuf[512]; + s_char buf1[512]; + int logf; /* s_char *error; */ - s_char *p; + s_char *p; - if (logfile == 0) - loginit(); - va_start(list, format); - vsprintf(buf, format, list); - if ((p = index(buf, '\n')) != 0) - *p = 0; - (void) time(&now); + if (logfile == 0) + loginit(); + va_start(list, format); + vsprintf(buf, format, list); + if ((p = index(buf, '\n')) != 0) + *p = 0; + (void)time(&now); /* error = "log"; if (errno != 0) error = sys_errlist[errno]; (void) sprintf(buf1, "%s; (%s) %s", buf, error, ctime(&now)); */ - strcpy(cbuf, ctime(&now)); - if ((p = index(cbuf, '\n')) != 0) - *p = 0; - (void) sprintf(buf1, "%s %s\n", cbuf, buf); - if ((logf = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0) - return; - (void) write(logf, buf1, strlen(buf1)); - (void) close(logf); - errno = 0; + strcpy(cbuf, ctime(&now)); + if ((p = index(cbuf, '\n')) != 0) + *p = 0; + (void)sprintf(buf1, "%s %s\n", cbuf, buf); + if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) + return; + (void)write(logf, buf1, strlen(buf1)); + (void)close(logf); + errno = 0; #ifdef notdef - if (player) { - pr("A system error has occured; please notify the deity.\n"); - pr(buf1); - } + if (player) { + pr("A system error has occured; please notify the deity.\n"); + pr(buf1); + } #endif - va_end(list); + va_end(list); } /*VARARGS*/ -void filelogerror(s_char *format, ...) +void +filelogerror(s_char *format, ...) { #if !defined(Rel4) && !defined(__linux__) && !defined(__ppc__) - extern s_char *sys_errlist[]; + extern s_char *sys_errlist[]; #endif /* Rel4 */ #ifndef sgi - extern int errno; + extern int errno; #endif /* sgi */ - va_list list; - time_t now; - s_char buf[512]; - s_char buf1[512]; - int logf; - s_char *error; - s_char *p; + va_list list; + time_t now; + s_char buf[512]; + s_char buf1[512]; + int logf; + s_char *error; + s_char *p; - if (logfile == 0) - loginit(); - va_start(list, format); - vsprintf(buf, format, list); - if ((p = index(buf, '\n')) != 0) - *p = 0; - (void) time(&now); - error = "log"; - if (errno != 0) + if (logfile == 0) + loginit(); + va_start(list, format); + vsprintf(buf, format, list); + if ((p = index(buf, '\n')) != 0) + *p = 0; + (void)time(&now); + error = "log"; + if (errno != 0) #ifdef Rel4 - error = strerror (errno); + error = strerror(errno); #else - error = (s_char *)sys_errlist[errno]; + error = (s_char *)sys_errlist[errno]; #endif /* Rel4 */ - (void) sprintf(buf1, "%s; (%s) %s", buf, error, ctime(&now)); - if ((logf = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0) - return; - (void) write(logf, buf1, strlen(buf1)); - (void) close(logf); - errno = 0; - va_end(list); + (void)sprintf(buf1, "%s; (%s) %s", buf, error, ctime(&now)); + if ((logf = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666)) < 0) + return; + (void)write(logf, buf1, strlen(buf1)); + (void)close(logf); + errno = 0; + va_end(list); } diff --git a/src/lib/common/mailbox.c b/src/lib/common/mailbox.c index e34ed2bc8..50c64dfc9 100644 --- a/src/lib/common/mailbox.c +++ b/src/lib/common/mailbox.c @@ -38,8 +38,6 @@ s_char * mailbox(s_char *buf, natid cn) { - (void) sprintf(buf, "%s%d", telfil, cn); - return buf; + (void)sprintf(buf, "%s%d", telfil, cn); + return buf; } - - diff --git a/src/lib/common/maps.c b/src/lib/common/maps.c index c7b363aa1..8613c771f 100644 --- a/src/lib/common/maps.c +++ b/src/lib/common/maps.c @@ -51,48 +51,51 @@ #include "optlist.h" int -draw_map(int bmap, s_char origin, int map_flags, struct nstr_sect *nsp, int country) +draw_map(int bmap, s_char origin, int map_flags, struct nstr_sect *nsp, + int country) { - struct natstr *np; - struct range range; - struct nstr_item ni; - struct shpstr ship; - struct lndstr land; - struct plnstr plane; - coord x,y; - int i; + struct natstr *np; + struct range range; + struct nstr_item ni; + struct shpstr ship; + struct lndstr land; + struct plnstr plane; + coord x, y; + int i; /* Note this is not re-entrant anyway, so we keep the buffers around */ - static u_char *bitmap = (u_char *)0; - static s_char *wmapbuf = (s_char *)0; - static s_char **wmap = (s_char **)0; - + static u_char *bitmap = (u_char *)0; + static s_char *wmapbuf = (s_char *)0; + static s_char **wmap = (s_char **)0; + if (!wmapbuf) - wmapbuf = (s_char *)malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char)); + wmapbuf = + (s_char *)malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char)); if (!wmap) { - wmap = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (wmap && wmapbuf) { - for (i = 0; i < WORLD_Y; i++) - wmap[i] = &wmapbuf[MAPWIDTH(1) * i]; - } else if (wmap) { - free((s_char *)wmap); - wmap = (s_char **)0; - } + wmap = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (wmap && wmapbuf) { + for (i = 0; i < WORLD_Y; i++) + wmap[i] = &wmapbuf[MAPWIDTH(1) * i]; + } else if (wmap) { + free((s_char *)wmap); + wmap = (s_char **)0; + } } if (!bitmap) - bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8); + bitmap = (u_char *)malloc((WORLD_X * WORLD_Y) / 8); if (!wmapbuf || !wmap || !bitmap) { - pr("Memory error, tell the deity.\n"); - logerror("malloc failed in draw_map\n"); - return RET_FAIL; + pr("Memory error, tell the deity.\n"); + logerror("malloc failed in draw_map\n"); + return RET_FAIL; } - + if (bmap == EF_MAP + EF_BMAP) { if (!confirm("Are you sure you want to revert your bmap? ")) - return RET_OK; + return RET_OK; } if (!player->command->c_flags & C_MOD) { - logerror("%s command needs C_MOD flag set",player->command->c_form); + logerror("%s command needs C_MOD flag set", + player->command->c_form); player->command->c_flags |= C_MOD; } np = getnatp(country); @@ -102,166 +105,167 @@ draw_map(int bmap, s_char origin, int map_flags, struct nstr_sect *nsp, int coun border(&range, " ", ""); blankfill((s_char *)wmapbuf, &nsp->range, 1); if (bmap) { - register int c; - switch (bmap) { - case EF_BMAP: - while (bmnxtsct(nsp) && !player->aborted) { - if (0 != (c = player->bmap[sctoff(nsp->x, nsp->y)])) - wmap[nsp->dy][nsp->dx] = c; - } - break; - case EF_MAP: - while (bmnxtsct(nsp) && !player->aborted) { - if (0 != (c = player->map[sctoff(nsp->x, nsp->y)])) - wmap[nsp->dy][nsp->dx] = c; - } - break; - case (EF_MAP + EF_BMAP): - while (bmnxtsct(nsp) && !player->aborted) { - player->bmap[sctoff(nsp->x, nsp->y)] = - player->map[sctoff(nsp->x, nsp->y)]; - if (0 != (c = player->bmap[sctoff(nsp->x, nsp->y)])) - wmap[nsp->dy][nsp->dx] = c; - } - ef_write(EF_BMAP, player->cnum, player->bmap); - break; - case EF_NMAP: - do { - register s_char *ptr; - struct sctstr sect; - - if ((!player->god || country)) { - bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); - bitinit2(nsp, bitmap, country); - } - while (nxtsct(nsp, §) && !player->aborted) { - if ((!player->god || country) && - !emp_getbit(nsp->x, nsp->y, bitmap)) { - if (!player->god) - continue; - } - ptr = &wmap[nsp->dy][nsp->dx]; - if (sect.sct_newtype > SCT_MAXDEF) { - *ptr = '?'; - } else { - *ptr = dchr[sect.sct_newtype].d_mnem; - switch (sect.sct_newtype) { - case SCT_WATER: - case SCT_RURAL: - case SCT_MOUNT: - case SCT_WASTE: - case SCT_PLAINS: - break; - default: - if (sect.sct_own != country && - (!player->god || country)) { - if (!player->god) - *ptr = '?'; - } - break; - } - } - } - } while (0); - break; - } - } else { + register int c; + switch (bmap) { + case EF_BMAP: + while (bmnxtsct(nsp) && !player->aborted) { + if (0 != (c = player->bmap[sctoff(nsp->x, nsp->y)])) + wmap[nsp->dy][nsp->dx] = c; + } + break; + case EF_MAP: + while (bmnxtsct(nsp) && !player->aborted) { + if (0 != (c = player->map[sctoff(nsp->x, nsp->y)])) + wmap[nsp->dy][nsp->dx] = c; + } + break; + case (EF_MAP + EF_BMAP): + while (bmnxtsct(nsp) && !player->aborted) { + player->bmap[sctoff(nsp->x, nsp->y)] = + player->map[sctoff(nsp->x, nsp->y)]; + if (0 != (c = player->bmap[sctoff(nsp->x, nsp->y)])) + wmap[nsp->dy][nsp->dx] = c; + } + ef_write(EF_BMAP, player->cnum, player->bmap); + break; + case EF_NMAP: + do { register s_char *ptr; - struct sctstr sect; - int changed = 0; - + struct sctstr sect; + if ((!player->god || country)) { - bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); - bitinit2(nsp, bitmap, country); + bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); + bitinit2(nsp, bitmap, country); } while (nxtsct(nsp, §) && !player->aborted) { - if ((!player->god || country) && !emp_getbit(nsp->x, nsp->y, bitmap)) { + if ((!player->god || country) && + !emp_getbit(nsp->x, nsp->y, bitmap)) { + if (!player->god) + continue; + } + ptr = &wmap[nsp->dy][nsp->dx]; + if (sect.sct_newtype > SCT_MAXDEF) { + *ptr = '?'; + } else { + *ptr = dchr[sect.sct_newtype].d_mnem; + switch (sect.sct_newtype) { + case SCT_WATER: + case SCT_RURAL: + case SCT_MOUNT: + case SCT_WASTE: + case SCT_PLAINS: + break; + default: + if (sect.sct_own != country && + (!player->god || country)) { if (!player->god) - continue; - } - ptr = &wmap[nsp->dy][nsp->dx]; - if (sect.sct_type > SCT_MAXDEF) { - *ptr = '?'; - } else { - *ptr = dchr[sect.sct_type].d_mnem; - switch (sect.sct_type) { - case SCT_WATER: - case SCT_RURAL: - case SCT_MOUNT: - case SCT_WASTE: - case SCT_PLAINS: - break; - default: - if (sect.sct_own != country && - (!player->god || country)) { - if(!player->god) - *ptr = '?'; - } - break; - } - changed += map_set(player->cnum, nsp->x, nsp->y, *ptr, 0); + *ptr = '?'; + } + break; } + } } - if (changed) - writemap(player->cnum); + } while (0); + break; + } + } else { + register s_char *ptr; + struct sctstr sect; + int changed = 0; + + if ((!player->god || country)) { + bzero((s_char *)bitmap, (WORLD_X * WORLD_Y) / 8); + bitinit2(nsp, bitmap, country); + } + while (nxtsct(nsp, §) && !player->aborted) { + if ((!player->god || country) + && !emp_getbit(nsp->x, nsp->y, bitmap)) { + if (!player->god) + continue; + } + ptr = &wmap[nsp->dy][nsp->dx]; + if (sect.sct_type > SCT_MAXDEF) { + *ptr = '?'; + } else { + *ptr = dchr[sect.sct_type].d_mnem; + switch (sect.sct_type) { + case SCT_WATER: + case SCT_RURAL: + case SCT_MOUNT: + case SCT_WASTE: + case SCT_PLAINS: + break; + default: + if (sect.sct_own != country && + (!player->god || country)) { + if (!player->god) + *ptr = '?'; + } + break; + } + changed += map_set(player->cnum, nsp->x, nsp->y, *ptr, 0); + } + } + if (changed) + writemap(player->cnum); } if (player->aborted) - return RET_OK; - if (map_flags & MAP_PLANE){ - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (caddr_t)&plane)) { - if (plane.pln_own == 0) - continue; - if (plane.pln_own != player->cnum && !player->god) - continue; - if (!xyinrange(plane.pln_x, plane.pln_y, &nsp->range)) - continue; - - x = xnorm(plane.pln_x-nsp->range.lx); - y = ynorm(plane.pln_y-nsp->range.ly); - wmap[y][x] = (*plchr[(int)plane.pln_type].pl_name) & ~0x20; - } + return RET_OK; + if (map_flags & MAP_PLANE) { + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (caddr_t)&plane)) { + if (plane.pln_own == 0) + continue; + if (plane.pln_own != player->cnum && !player->god) + continue; + if (!xyinrange(plane.pln_x, plane.pln_y, &nsp->range)) + continue; + + x = xnorm(plane.pln_x - nsp->range.lx); + y = ynorm(plane.pln_y - nsp->range.ly); + wmap[y][x] = (*plchr[(int)plane.pln_type].pl_name) & ~0x20; + } } - if (map_flags & MAP_SHIP){ - snxtitem_all(&ni, EF_SHIP); - while (nxtitem(&ni, (caddr_t)&ship)) { - if (ship.shp_own == 0) - continue; - if (ship.shp_own != player->cnum && !player->god) - continue; - if (!xyinrange(ship.shp_x, ship.shp_y, &nsp->range)) - continue; - - x = xnorm(ship.shp_x-nsp->range.lx); - y = ynorm(ship.shp_y-nsp->range.ly); - wmap[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; - } + if (map_flags & MAP_SHIP) { + snxtitem_all(&ni, EF_SHIP); + while (nxtitem(&ni, (caddr_t)&ship)) { + if (ship.shp_own == 0) + continue; + if (ship.shp_own != player->cnum && !player->god) + continue; + if (!xyinrange(ship.shp_x, ship.shp_y, &nsp->range)) + continue; + + x = xnorm(ship.shp_x - nsp->range.lx); + y = ynorm(ship.shp_y - nsp->range.ly); + wmap[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; + } } - if (map_flags & MAP_LAND){ - snxtitem_all(&ni, EF_LAND); - while (nxtitem(&ni, (caddr_t)&land)) { - if (land.lnd_own == 0) - continue; - if (land.lnd_own != player->cnum && !player->god) - continue; - if (!xyinrange(land.lnd_x, land.lnd_y, &nsp->range)) - continue; - - x = xnorm(land.lnd_x-nsp->range.lx); - y = ynorm(land.lnd_y-nsp->range.ly); - wmap[y][x] = (*lchr[(int)land.lnd_type].l_name) & ~0x20; - } + if (map_flags & MAP_LAND) { + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (caddr_t)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_own != player->cnum && !player->god) + continue; + if (!xyinrange(land.lnd_x, land.lnd_y, &nsp->range)) + continue; + + x = xnorm(land.lnd_x - nsp->range.lx); + y = ynorm(land.lnd_y - nsp->range.ly); + wmap[y][x] = (*lchr[(int)land.lnd_type].l_name) & ~0x20; + } } if (origin) - wmap[5][10] = origin & ~0x20; - for (y=nsp->range.ly, i=0; i < nsp->range.height; y++, i++) { - int yval; - - yval = yrel(np, y); - wmap[i][nsp->range.width] = '\0'; - pr("%4d %s %-4d\n", yval, wmap[i], yval); - if (y >= WORLD_Y) - y -= WORLD_Y; + wmap[5][10] = origin & ~0x20; + for (y = nsp->range.ly, i = 0; i < nsp->range.height; y++, i++) { + int yval; + + yval = yrel(np, y); + wmap[i][nsp->range.width] = '\0'; + pr("%4d %s %-4d\n", yval, wmap[i], yval); + if (y >= WORLD_Y) + y -= WORLD_Y; } border(&range, " ", ""); return RET_OK; @@ -274,29 +278,29 @@ int bmnxtsct(register struct nstr_sect *np) { while (1) { - np->dx++; - np->x++; - if (np->x >= WORLD_X) - np->x = 0; - if (np->dx >= np->range.width) { - np->dx = 0; - np->x = np->range.lx; - np->dy++; - if (np->dy >= np->range.height) - return 0; - np->y++; - if (np->y >= WORLD_Y) - np->y = 0; - } - if ((np->y + np->x) & 01) - continue; - if (np->type == NS_DIST) { - np->curdist = mapdist(np->x, np->y, np->cx, np->cy); - if (np->curdist > np->dist) - continue; - } - np->id = sctoff(np->x, np->y); - return 1; + np->dx++; + np->x++; + if (np->x >= WORLD_X) + np->x = 0; + if (np->dx >= np->range.width) { + np->dx = 0; + np->x = np->range.lx; + np->dy++; + if (np->dy >= np->range.height) + return 0; + np->y++; + if (np->y >= WORLD_Y) + np->y = 0; + } + if ((np->y + np->x) & 01) + continue; + if (np->type == NS_DIST) { + np->curdist = mapdist(np->x, np->y, np->cx, np->cy); + if (np->curdist > np->dist) + continue; + } + np->id = sctoff(np->x, np->y); + return 1; } /*NOTREACHED*/ } @@ -304,17 +308,17 @@ bmnxtsct(register struct nstr_sect *np) void bitinit2(struct nstr_sect *np, u_char *bitmap, int country) { - extern int *bitmaps[]; - struct sctstr sect; - int eff; - + extern int *bitmaps[]; + struct sctstr sect; + int eff; + while (nxtsct(np, §)) { - if (sect.sct_own != country) - continue; - eff = sect.sct_effic / 20; - if (eff > 4) - eff = 4; - emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]); + if (sect.sct_own != country) + continue; + eff = sect.sct_effic / 20; + if (eff > 4) + eff = 4; + emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]); } snxtsct_rewind(np); } @@ -322,99 +326,95 @@ bitinit2(struct nstr_sect *np, u_char *bitmap, int country) int unit_map(int unit_type, int i, struct nstr_sect *nsp, s_char *originp) { - struct shpstr origs; - struct lndstr origl; - struct plnstr origp; - s_char what[64]; - struct natstr *np; - + struct shpstr origs; + struct lndstr origl; + struct plnstr origp; + s_char what[64]; + struct natstr *np; + np = getnatp(player->cnum); - if (unit_type == EF_LAND){ - if (!getland(i, &origl) || - (origl.lnd_own != player->cnum && !player->god) || - (origl.lnd_own == 0)) - return RET_FAIL; - sprintf(what, "%d:%d,%d:%d",xrel(np,origl.lnd_x-10), - xrel(np,origl.lnd_x+10), - yrel(np,origl.lnd_y-5), yrel(np,origl.lnd_y+5)); - *originp = *lchr[(int)origl.lnd_type].l_name; - } else if (unit_type == EF_PLANE){ - if (!getplane(i, &origp) || - (origp.pln_own != player->cnum && !player->god) || - (origp.pln_own == 0)) - return RET_FAIL; - sprintf(what, "%d:%d,%d:%d",xrel(np,origp.pln_x-10), - xrel(np,origp.pln_x+10), - yrel(np,origp.pln_y-5), yrel(np,origp.pln_y+5)); - *originp = *plchr[(int)origp.pln_type].pl_name; + if (unit_type == EF_LAND) { + if (!getland(i, &origl) || + (origl.lnd_own != player->cnum && !player->god) || + (origl.lnd_own == 0)) + return RET_FAIL; + sprintf(what, "%d:%d,%d:%d", xrel(np, origl.lnd_x - 10), + xrel(np, origl.lnd_x + 10), + yrel(np, origl.lnd_y - 5), yrel(np, origl.lnd_y + 5)); + *originp = *lchr[(int)origl.lnd_type].l_name; + } else if (unit_type == EF_PLANE) { + if (!getplane(i, &origp) || + (origp.pln_own != player->cnum && !player->god) || + (origp.pln_own == 0)) + return RET_FAIL; + sprintf(what, "%d:%d,%d:%d", xrel(np, origp.pln_x - 10), + xrel(np, origp.pln_x + 10), + yrel(np, origp.pln_y - 5), yrel(np, origp.pln_y + 5)); + *originp = *plchr[(int)origp.pln_type].pl_name; } else { - if (!getship(i, &origs) || - (origs.shp_own != player->cnum && !player->god) || - (origs.shp_own == 0)) - return RET_FAIL; - sprintf(what, "%d:%d,%d:%d",xrel(np,origs.shp_x-10), - xrel(np,origs.shp_x+10), - yrel(np,origs.shp_y-5), yrel(np,origs.shp_y+5)); - unit_type = EF_SHIP; - *originp = *mchr[(int)origs.shp_type].m_name; + if (!getship(i, &origs) || + (origs.shp_own != player->cnum && !player->god) || + (origs.shp_own == 0)) + return RET_FAIL; + sprintf(what, "%d:%d,%d:%d", xrel(np, origs.shp_x - 10), + xrel(np, origs.shp_x + 10), + yrel(np, origs.shp_y - 5), yrel(np, origs.shp_y + 5)); + unit_type = EF_SHIP; + *originp = *mchr[(int)origs.shp_type].m_name; } if (!snxtsct(nsp, what)) - return RET_FAIL; + return RET_FAIL; return RET_OK; } int bmaps_intersect(natid a, natid b) { - s_char *mapa = ef_ptr(EF_MAP, a); - s_char *mapb = ef_ptr(EF_MAP, b); - int i; - - for (i = 0; i < WORLD_X*WORLD_Y/2; ++i, ++mapa, ++mapb) - if (*mapa && *mapa != ' ' && *mapb && *mapb != ' ') - return 1; + s_char *mapa = ef_ptr(EF_MAP, a); + s_char *mapb = ef_ptr(EF_MAP, b); + int i; + + for (i = 0; i < WORLD_X * WORLD_Y / 2; ++i, ++mapa, ++mapb) + if (*mapa && *mapa != ' ' && *mapb && *mapb != ' ') + return 1; return 0; } /* Note that this requires that the BMAP is mapped into memory */ int -share_bmap(natid from, natid to, struct nstr_sect *ns, s_char des, s_char *from_name) +share_bmap(natid from, natid to, struct nstr_sect *ns, s_char des, + s_char *from_name) { - s_char *from_bmap = ef_ptr(EF_BMAP, from); - s_char *to_bmap = ef_ptr(EF_BMAP, to); - int n = 0; - struct sctstr sect; - s_char fromdes; - s_char todes; - s_char from_des = *from_name; - + s_char *from_bmap = ef_ptr(EF_BMAP, from); + s_char *to_bmap = ef_ptr(EF_BMAP, to); + int n = 0; + struct sctstr sect; + s_char fromdes; + s_char todes; + s_char from_des = *from_name; + if (isalpha(from_des)) - from_des &= ~0x20; - + from_des &= ~0x20; + while (nxtsct(ns, §)) { - if (!(fromdes = from_bmap[sctoff(ns->x, ns->y)])) - continue; - todes = to_bmap[sctoff(ns->x, ns->y)]; - if (todes && - todes != '?' && - todes != '.' && - todes != ' ' && - todes != from_des) - continue; - if (sect.sct_own == from) { - if (fromdes != '=' && - fromdes != 'h' && - fromdes != des) - fromdes = from_des; - } - if (todes == fromdes) - continue; - n += map_set(to, ns->x, ns->y, fromdes, 1); + if (!(fromdes = from_bmap[sctoff(ns->x, ns->y)])) + continue; + todes = to_bmap[sctoff(ns->x, ns->y)]; + if (todes && + todes != '?' && + todes != '.' && todes != ' ' && todes != from_des) + continue; + if (sect.sct_own == from) { + if (fromdes != '=' && fromdes != 'h' && fromdes != des) + fromdes = from_des; + } + if (todes == fromdes) + continue; + n += map_set(to, ns->x, ns->y, fromdes, 1); } - + if (n) - writebmap(to); + writebmap(to); return n; } - diff --git a/src/lib/common/move.c b/src/lib/common/move.c index 6be004359..f6b611318 100644 --- a/src/lib/common/move.c +++ b/src/lib/common/move.c @@ -45,13 +45,13 @@ double sector_mcost(struct sctstr *sp, int do_bonus) { - double d; + double d; if (!(d = dchr[sp->sct_type].d_mcst)) return -1.0; /* Note, the best you can get is a 1.0 here. */ - + if (do_bonus == MOB_ROAD) { d = d / (1.0 + ((double)sp->sct_road / 122.0)); } else if (do_bonus == MOB_RAIL) { @@ -61,15 +61,14 @@ sector_mcost(struct sctstr *sp, int do_bonus) d = 2.0; } if (d < 1.0) - d = 1.0; + d = 1.0; if (dchr[sp->sct_type].d_mcst < 25) - d = (d * 100.0 - (double)sp->sct_effic) / 500.0; + d = (d * 100.0 - (double)sp->sct_effic) / 500.0; /* d = (200.0 + (d - 3.0) * (double)sp->sct_effic) / 500.0;*/ else d = (d * 10.0 - (double)sp->sct_effic) / 115; - + if (d <= 0.0 || d < MIN_MOBCOST) return MIN_MOBCOST; return d; } - diff --git a/src/lib/common/nat.c b/src/lib/common/nat.c index 76df8e8ec..7c44210ef 100644 --- a/src/lib/common/nat.c +++ b/src/lib/common/nat.c @@ -39,115 +39,115 @@ s_char * cname(natid n) { - struct natstr *np; + struct natstr *np; - if ((np = getnatp(n)) == 0) - return 0; - return np->nat_cnam; + if ((np = getnatp(n)) == 0) + return 0; + return np->nat_cnam; } s_char * relatename(struct natstr *np, natid other) { - extern s_char *relates[]; + extern s_char *relates[]; - return relates[getrel(np, other)]; + return relates[getrel(np, other)]; } s_char * rejectname(struct natstr *np, natid other) { - extern s_char *rejects[]; + extern s_char *rejects[]; - return rejects[getrejects(other, np)]; + return rejects[getrejects(other, np)]; } s_char * natstate(struct natstr *np) { - if ((np->nat_stat & STAT_INUSE) == 0) - return "FREE"; - if (np->nat_stat & STAT_GOD) - return "DEITY"; - if ((np->nat_stat & STAT_NORM) == 0) - return "VISITOR"; - return "ACTIVE"; + if ((np->nat_stat & STAT_INUSE) == 0) + return "FREE"; + if (np->nat_stat & STAT_GOD) + return "DEITY"; + if ((np->nat_stat & STAT_NORM) == 0) + return "VISITOR"; + return "ACTIVE"; } /* This returns the relations that np has with them */ int getrel(struct natstr *np, natid them) { - return np->nat_relate[them]; + return np->nat_relate[them]; } int getrejects(natid them, struct natstr *np) { - int ind; - int shift; - int reject; - - ind = them / 4; - shift = 12 - ((them - ((them / 4) << 2)) * 4); - /* the 07 should *really* be 017 */ - reject = (np->nat_rejects[ind] >> shift) & 0x0f; - return reject; + int ind; + int shift; + int reject; + + ind = them / 4; + shift = 12 - ((them - ((them / 4) << 2)) * 4); + /* the 07 should *really* be 017 */ + reject = (np->nat_rejects[ind] >> shift) & 0x0f; + return reject; } void agecontact(struct natstr *np) { - int them; - - if (opt_LOSE_CONTACT) { - for (them = 1; them < MAXNOC; ++them) { - if (them != np->nat_cnum && np->nat_contact[them]) { - --np->nat_contact[them]; - } - } - } + int them; + + if (opt_LOSE_CONTACT) { + for (them = 1; them < MAXNOC; ++them) { + if (them != np->nat_cnum && np->nat_contact[them]) { + --np->nat_contact[them]; + } + } + } } int getcontact(struct natstr *np, natid them) { - int contact; + int contact; - if (opt_LOSE_CONTACT) { - contact = np->nat_contact[them]; - } else { - int ind = them/16; - int shift = (them % 16); + if (opt_LOSE_CONTACT) { + contact = np->nat_contact[them]; + } else { + int ind = them / 16; + int shift = (them % 16); - contact = (np->nat_contact[ind] >> shift) & 1; - } - return contact; -} + contact = (np->nat_contact[ind] >> shift) & 1; + } + return contact; +} void putrel(struct natstr *np, natid them, int relate) { - np->nat_relate[them] = relate; + np->nat_relate[them] = relate; } void putreject(struct natstr *np, natid them, int how, int what) { - int shift; - int newrej; - int ind; - - /* This 07 should be changed to 017 after the current game is over */ - what &= 0x0f; - ind = them / 4; - shift = 12 - ((them - ((them / 4) << 2)) * 4); - newrej = np->nat_rejects[ind]; - if (how) - newrej |= (what << shift); - else - newrej &= ~(what << shift); - np->nat_rejects[ind] = newrej; + int shift; + int newrej; + int ind; + + /* This 07 should be changed to 017 after the current game is over */ + what &= 0x0f; + ind = them / 4; + shift = 12 - ((them - ((them / 4) << 2)) * 4); + newrej = np->nat_rejects[ind]; + if (how) + newrej |= (what << shift); + else + newrej &= ~(what << shift); + np->nat_rejects[ind] = newrej; } void @@ -155,14 +155,14 @@ putcontact(struct natstr *np, natid them, int contact) { if (opt_LOSE_CONTACT) { if (np->nat_contact[them] > contact) - return; + return; np->nat_contact[them] = contact; } else { - int ind = them/16; - int shift = them%16; + int ind = them / 16; + int shift = them % 16; int new = np->nat_contact[ind]; if (contact) - contact = 1; + contact = 1; new &= ~(1 << shift); new |= (contact << shift); np->nat_contact[ind] = new; diff --git a/src/lib/common/nstr_subs.c b/src/lib/common/nstr_subs.c index efff7479e..2ca2400d9 100644 --- a/src/lib/common/nstr_subs.c +++ b/src/lib/common/nstr_subs.c @@ -52,108 +52,107 @@ int nstr_exec(struct nscstr *conds, register int ncond, void *ptr, int type) { - register struct nscstr *nsc; - register int op; - register int lhs; - register int rhs; - register int oper; + register struct nscstr *nsc; + register int op; + register int lhs; + register int rhs; + register int oper; - for (nsc=conds; --ncond >= 0; nsc++) { - oper = nsc->oper; - if (oper > 65535) { - oper = oper - 65535; - rhs = nsc->fld2; - } else - rhs = decode(player->cnum, nsc->fld2, ptr, type); + for (nsc = conds; --ncond >= 0; nsc++) { + oper = nsc->oper; + if (oper > 65535) { + oper = oper - 65535; + rhs = nsc->fld2; + } else + rhs = decode(player->cnum, nsc->fld2, ptr, type); - if (oper > 255) { - oper = oper - 255; - lhs = nsc->fld1; - } else - lhs = decode(player->cnum, nsc->fld1, ptr, type); + if (oper > 255) { + oper = oper - 255; + lhs = nsc->fld1; + } else + lhs = decode(player->cnum, nsc->fld1, ptr, type); - op = oper; - if ((op == '<' && lhs >= rhs) || - (op == '=' && lhs != rhs) || - (op == '>' && lhs <= rhs) || - (op == '#' && lhs == rhs)) - return 0; - } - return 1; + op = oper; + if ((op == '<' && lhs >= rhs) || + (op == '=' && lhs != rhs) || + (op == '>' && lhs <= rhs) || (op == '#' && lhs == rhs)) + return 0; + } + return 1; } int decode(natid cnum, long int code, void *addr, int type) { - register int val; - register int nsc_code; - struct natstr *np; - long code_type = (code & NSC_TMASK); + register int val; + register int nsc_code; + struct natstr *np; + long code_type = (code & NSC_TMASK); + + val = (code & ~NSC_MASK) & 0xffff; - val = (code & ~NSC_MASK) & 0xffff; + /* handle negative numbers properly */ + /* this assumes a binary two's complement number representation */ + if (val >= 0x8000) + val -= 0x10000; - /* handle negative numbers properly */ - /* this assumes a binary two's complement number representation */ - if (val>=0x8000) val -= 0x10000; - - nsc_code = code & NSC_CMASK; - if (nsc_code == NSC_VAR) { - val = getvar(val, addr, type); - } else if (nsc_code == NSC_OFF) { - /* - * add offset to value - */ - addr = (s_char *)addr + val; - switch (code_type) { - case NSC_TIME: - val = *((time_t *)addr); - break; - case NSC_CHAR: - val = *((s_char *) addr); - break; - case NSC_UCHAR: - val = (int) *((unsigned char *) addr); - break; - case NSC_SHORT: - val = *((short *) addr); - break; - case NSC_USHORT: - val = *((u_short *) addr); - break; - case NSC_INT: - val = *((int *) addr); - break; - case NSC_LONG: - val = *((long *) addr); - break; - case NSC_XCOORD: - val = *((short *) addr); - np = getnatp(cnum); - val = xrel(np, val); - break; - case NSC_YCOORD: - val = *((short *) addr); - np = getnatp(cnum); - val = yrel(np, val); - break; - default: - logerror("bad type in decode: %x!\n", - code & NSC_TMASK); - val = 0; - break; - } + nsc_code = code & NSC_CMASK; + if (nsc_code == NSC_VAR) { + val = getvar(val, addr, type); + } else if (nsc_code == NSC_OFF) { + /* + * add offset to value + */ + addr = (s_char *)addr + val; + switch (code_type) { + case NSC_TIME: + val = *((time_t *) addr); + break; + case NSC_CHAR: + val = *((s_char *)addr); + break; + case NSC_UCHAR: + val = (int)*((unsigned char *)addr); + break; + case NSC_SHORT: + val = *((short *)addr); + break; + case NSC_USHORT: + val = *((u_short *)addr); + break; + case NSC_INT: + val = *((int *)addr); + break; + case NSC_LONG: + val = *((long *)addr); + break; + case NSC_XCOORD: + val = *((short *)addr); + np = getnatp(cnum); + val = xrel(np, val); + break; + case NSC_YCOORD: + val = *((short *)addr); + np = getnatp(cnum); + val = yrel(np, val); + break; + default: + logerror("bad type in decode: %x!\n", code & NSC_TMASK); + val = 0; + break; } - if (code & NSC_ROUND) - val = roundintby(val, 10); - return val; + } + if (code & NSC_ROUND) + val = roundintby(val, 10); + return val; } s_char * decodep(long int code, void *addr) { - addr = (char *)addr + ((code & ~NSC_MASK) & 0xffff); + addr = (char *)addr + ((code & ~NSC_MASK) & 0xffff); - if ((code & NSC_TMASK) == NSC_CHARP) - return *(s_char **)addr?*((s_char **)addr):(s_char *)""; - return addr; + if ((code & NSC_TMASK) == NSC_CHARP) + return *(s_char **)addr ? *((s_char **)addr) : (s_char *)""; + return addr; } diff --git a/src/lib/common/path.c b/src/lib/common/path.c index 5cb2bc218..8e6be460e 100644 --- a/src/lib/common/path.c +++ b/src/lib/common/path.c @@ -62,39 +62,44 @@ /* XXX won't need sector hash when sect file is memory mapped */ -#define BP_SCTHASHSIZE 128 /* sector cache hash table size */ -#define BP_ASHASHSIZE 128 /* A* queue hash table size */ -#define BP_NEIGHBORS 6 /* max number of neighbors */ - -struct sctcache { - coord x, y; - struct sctstr *sp; - struct sctcache *next; +#define BP_SCTHASHSIZE 128 /* sector cache hash table size */ +#define BP_ASHASHSIZE 128 /* A* queue hash table size */ +#define BP_NEIGHBORS 6 /* max number of neighbors */ + +struct sctcache { + coord x, y; + struct sctstr *sp; + struct sctcache *next; }; struct bestp { - struct sctcache *sctcachetab[BP_SCTHASHSIZE]; - int sctcache_hits; - int sctcache_misses; - int bp_mobtype; - struct as_data *adp; + struct sctcache *sctcachetab[BP_SCTHASHSIZE]; + int sctcache_hits; + int sctcache_misses; + int bp_mobtype; + struct as_data *adp; }; #ifdef DO_EFF_MEM_CHECKING -static struct sctstr *bp_getsect(struct bestp *bp, coord x, coord y); -static struct sctstr *bp_sctcache_get(struct bestp *bp, coord x, coord y); -static void bp_sctcache_set(struct bestp *bp, coord x, coord y, struct sctstr *sp); -static void bp_sctcache_zap(struct bestp *bp); +static struct sctstr *bp_getsect(struct bestp *bp, coord x, coord y); +static struct sctstr *bp_sctcache_get(struct bestp *bp, coord x, coord y); +static void bp_sctcache_set(struct bestp *bp, coord x, coord y, + struct sctstr *sp); +static void bp_sctcache_zap(struct bestp *bp); #endif /* DO_EFF_MEM_CHECKING */ -static int bp_path(struct as_path *pp, s_char *buf); -static int bp_neighbors(struct as_coord c, struct as_coord *cp, s_char *pp); -static double bp_lbcost(struct as_coord from, struct as_coord to, s_char *pp); -static double bp_realcost(struct as_coord from, struct as_coord to, s_char *pp); -static double bp_seccost(struct as_coord from, struct as_coord to, s_char *pp); -static int bp_coord_hash(struct as_coord c); +static int bp_path(struct as_path *pp, s_char *buf); +static int bp_neighbors(struct as_coord c, struct as_coord *cp, + s_char *pp); +static double bp_lbcost(struct as_coord from, struct as_coord to, + s_char *pp); +static double bp_realcost(struct as_coord from, struct as_coord to, + s_char *pp); +static double bp_seccost(struct as_coord from, struct as_coord to, + s_char *pp); +static int bp_coord_hash(struct as_coord c); struct empfile *ep; @@ -105,24 +110,25 @@ struct sctstr **neighsects = (struct sctstr **)0; s_char * bp_init(void) { - struct bestp *bp; + struct bestp *bp; - ep = &empfile[EF_SECTOR]; + ep = &empfile[EF_SECTOR]; - bp = (struct bestp *) malloc(sizeof(*bp)); - bzero((s_char *)bp, sizeof(*bp)); - bp->adp = as_init(BP_NEIGHBORS, BP_ASHASHSIZE, bp_coord_hash, - bp_neighbors, bp_lbcost, bp_realcost, - bp_seccost, (s_char *)bp); + bp = (struct bestp *)malloc(sizeof(*bp)); + bzero((s_char *)bp, sizeof(*bp)); + bp->adp = as_init(BP_NEIGHBORS, BP_ASHASHSIZE, bp_coord_hash, + bp_neighbors, bp_lbcost, bp_realcost, + bp_seccost, (s_char *)bp); - if (bp->adp == NULL) - return NULL; + if (bp->adp == NULL) + return NULL; - if (neighsects == (struct sctstr **)0) - neighsects = (struct sctstr **)calloc(1, (sizeof(struct sctstr *) * - ((WORLD_X * WORLD_Y)/2)*6)); + if (neighsects == (struct sctstr **)0) + neighsects = (struct sctstr **)calloc(1, (sizeof(struct sctstr *) * + ((WORLD_X * WORLD_Y) / + 2) * 6)); - return (s_char *) bp; + return (s_char *)bp; } /* @@ -130,43 +136,44 @@ bp_init(void) * string in path. Return 0 on success, -1 on error. */ int -best_path(struct sctstr *from, struct sctstr *to, s_char *path, int mob_type) +best_path(struct sctstr *from, struct sctstr *to, s_char *path, + int mob_type) { - static struct bestp *mybestpath; - struct as_data *adp; - struct as_path *ap; + static struct bestp *mybestpath; + struct as_data *adp; + struct as_path *ap; - if (mybestpath == 0) - mybestpath = (struct bestp *)bp_init(); - adp = mybestpath->adp; + if (mybestpath == 0) + mybestpath = (struct bestp *)bp_init(); + adp = mybestpath->adp; #ifdef DO_EFF_MEM_CHECKING - bp_sctcache_zap(mybestpath); + bp_sctcache_zap(mybestpath); #endif - ap = as_find_cachepath(from->sct_x, from->sct_y, to->sct_x, to->sct_y); - if (ap == NULL) { - adp->from.x = from->sct_x; - adp->from.y = from->sct_y; - adp->to.x = to->sct_x; - adp->to.y = to->sct_y; - mybestpath->bp_mobtype = mob_type; - - if (as_search(adp) < 0) - return -1; - ap = adp->path; - } - - if (bp_path(ap, path) < 0) - return -1; + ap = as_find_cachepath(from->sct_x, from->sct_y, to->sct_x, to->sct_y); + if (ap == NULL) { + adp->from.x = from->sct_x; + adp->from.y = from->sct_y; + adp->to.x = to->sct_x; + adp->to.y = to->sct_y; + mybestpath->bp_mobtype = mob_type; + + if (as_search(adp) < 0) + return -1; + ap = adp->path; + } + + if (bp_path(ap, path) < 0) + return -1; #ifdef AS_STATS - as_stats(adp, stderr); + as_stats(adp, stderr); #endif /* AS_STATS */ #ifdef BP_STATS - fprintf(stderr, "best path %s\n", path); - fprintf(stderr, "cache hits/misses: %d/%d\n", - bp->sctcache_hits, bp->sctcache_misses); + fprintf(stderr, "best path %s\n", path); + fprintf(stderr, "cache hits/misses: %d/%d\n", + bp->sctcache_hits, bp->sctcache_misses); #endif /* BP_STATS */ - return 0; + return 0; } /* @@ -176,36 +183,36 @@ best_path(struct sctstr *from, struct sctstr *to, s_char *path, int mob_type) static int bp_path(struct as_path *pp, s_char *buf) { - struct as_path *np; - s_char *cp = buf; - int dx, dy; - int n; - - np = pp->next; - while (np) { - dx = np->c.x - pp->c.x; - /* deal with wraparound from non-neg coords */ - if (dx < -2) - dx += WORLD_X; - else if (dx > 2) - dx -= WORLD_X; - dy = np->c.y - pp->c.y; - if (dy < -1) - dy += WORLD_Y; - else if (dy > 1) - dy -= WORLD_Y; - for (n=1;n<=6;n++) - if (dx == diroff[n][0] && dy == diroff[n][1]) - break; - if (n > 6) - return -1; - - *cp++ = dirch[n]; - pp = np; - np = np->next; - } - *cp = '\0'; - return 0; + struct as_path *np; + s_char *cp = buf; + int dx, dy; + int n; + + np = pp->next; + while (np) { + dx = np->c.x - pp->c.x; + /* deal with wraparound from non-neg coords */ + if (dx < -2) + dx += WORLD_X; + else if (dx > 2) + dx -= WORLD_X; + dy = np->c.y - pp->c.y; + if (dy < -1) + dy += WORLD_Y; + else if (dy > 1) + dy -= WORLD_Y; + for (n = 1; n <= 6; n++) + if (dx == diroff[n][0] && dy == diroff[n][1]) + break; + if (n > 6) + return -1; + + *cp++ = dirch[n]; + pp = np; + np = np->next; + } + *cp = '\0'; + return 0; } /* @@ -218,71 +225,71 @@ static int bp_neighbors(struct as_coord c, struct as_coord *cp, s_char *pp) { #ifdef DO_EFF_MEM_CHECKING - struct bestp *bp = (struct bestp *) pp; + struct bestp *bp = (struct bestp *)pp; #endif /* DO_EFF_MEM_CHECKING */ - coord x, y; - coord nx, ny; - int n = 0, q; - struct sctstr *sp, *from, **ssp; - /* Six pointers, just in case our cache isn't there */ - struct sctstr *tsp[] = { 0, 0, 0, 0, 0, 0 }; - int sx, sy, offset; - - x = c.x; - y = c.y; + coord x, y; + coord nx, ny; + int n = 0, q; + struct sctstr *sp, *from, **ssp; + /* Six pointers, just in case our cache isn't there */ + struct sctstr *tsp[] = { 0, 0, 0, 0, 0, 0 }; + int sx, sy, offset; + + x = c.x; + y = c.y; #ifdef DO_EFF_MEM_CHECKING - if ((ep->flags & EFF_MEM) == 0) { - from = bp_getsect(bp, x, y); - } else { + if ((ep->flags & EFF_MEM) == 0) { + from = bp_getsect(bp, x, y); + } else { #endif /* DO_EFF_MEM_CHECKING */ - sx = XNORM(x); - sy = YNORM(y); - offset = (sy * WORLD_X + sx) / 2; - from = (struct sctstr *) (ep->cache + ep->size * offset); + sx = XNORM(x); + sy = YNORM(y); + offset = (sy * WORLD_X + sx) / 2; + from = (struct sctstr *)(ep->cache + ep->size * offset); #ifdef DO_EFF_MEM_CHECKING - } + } #endif /* DO_EFF_MEM_CHECKING */ - if (neighsects == (struct sctstr **)0) - ssp = (struct sctstr **)&tsp[0]; - else - ssp = (struct sctstr **)&neighsects[offset * 6]; - for (q = 1; q <= 6; q++, ssp++) { - if (*ssp == (struct sctstr *)0) { - /* We haven't cached this neighbor yet */ - nx = x + diroff[q][0]; - ny = y + diroff[q][1]; - sx = XNORM(nx); - sy = YNORM(ny); + if (neighsects == (struct sctstr **)0) + ssp = (struct sctstr **)&tsp[0]; + else + ssp = (struct sctstr **)&neighsects[offset * 6]; + for (q = 1; q <= 6; q++, ssp++) { + if (*ssp == (struct sctstr *)0) { + /* We haven't cached this neighbor yet */ + nx = x + diroff[q][0]; + ny = y + diroff[q][1]; + sx = XNORM(nx); + sy = YNORM(ny); #ifdef DO_EFF_MEM_CHECKING - if ((ep->flags & EFF_MEM) == 0) { - sp = bp_getsect(bp, nx, ny); - } else { + if ((ep->flags & EFF_MEM) == 0) { + sp = bp_getsect(bp, nx, ny); + } else { #endif /* DO_EFF_MEM_CHECKING */ - offset = (sy * WORLD_X + sx) / 2; - sp = (struct sctstr *) (ep->cache + ep->size * offset); - /* We can only save in our neighbor cache if the - sector file is in memory */ - *ssp = sp; + offset = (sy * WORLD_X + sx) / 2; + sp = (struct sctstr *)(ep->cache + ep->size * offset); + /* We can only save in our neighbor cache if the + sector file is in memory */ + *ssp = sp; #ifdef DO_EFF_MEM_CHECKING - } -#endif /* DO_EFF_MEM_CHECKING */ - } else { - sp = *ssp; - sx = XNORM(sp->sct_x); - sy = YNORM(sp->sct_y); } - /* No need to calculate cost each time, just make sure we can - move through it. We calculate it later. */ - if (dchr[sp->sct_type].d_mcst == 0) - continue; - if (sp->sct_own != from->sct_own) - continue; - cp[n].x = sx; - cp[n].y = sy; - n++; +#endif /* DO_EFF_MEM_CHECKING */ + } else { + sp = *ssp; + sx = XNORM(sp->sct_x); + sy = YNORM(sp->sct_y); } - return (n); + /* No need to calculate cost each time, just make sure we can + move through it. We calculate it later. */ + if (dchr[sp->sct_type].d_mcst == 0) + continue; + if (sp->sct_own != from->sct_own) + continue; + cp[n].x = sx; + cp[n].y = sy; + n++; + } + return (n); } /* @@ -292,27 +299,27 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, s_char *pp) static double bp_lbcost(struct as_coord from, struct as_coord to, s_char *pp) { - struct bestp *bp = (struct bestp *) pp; - struct sctstr *ts; - float cost; - int x, y, sx, sy, offset; + struct bestp *bp = (struct bestp *)pp; + struct sctstr *ts; + float cost; + int x, y, sx, sy, offset; #ifdef DO_EFF_MEM_CHECKING - if ((ep->flags & EFF_MEM) == 0) { - ts = bp_getsect(bp, (coord)to.x, (coord)to.y); - } else { + if ((ep->flags & EFF_MEM) == 0) { + ts = bp_getsect(bp, (coord)to.x, (coord)to.y); + } else { #endif /* DO_EFF_MEM_CHECKING */ - x = to.x; - y = to.y; - sx = XNORM(x); - sy = YNORM(y); - offset = (sy * WORLD_X + sx) / 2; - ts = (struct sctstr *)(ep->cache + ep->size * offset); + x = to.x; + y = to.y; + sx = XNORM(x); + sy = YNORM(y); + offset = (sy * WORLD_X + sx) / 2; + ts = (struct sctstr *)(ep->cache + ep->size * offset); #ifdef DO_EFF_MEM_CHECKING - } + } #endif /* DO_EFF_MEM_CHECKING */ - cost = sector_mcost(ts, bp->bp_mobtype); - return (cost); + cost = sector_mcost(ts, bp->bp_mobtype); + return (cost); } /* @@ -321,7 +328,7 @@ bp_lbcost(struct as_coord from, struct as_coord to, s_char *pp) static double bp_realcost(struct as_coord from, struct as_coord to, s_char *pp) { - return (bp_lbcost(from, to, pp)); + return (bp_lbcost(from, to, pp)); } /* @@ -332,8 +339,8 @@ bp_realcost(struct as_coord from, struct as_coord to, s_char *pp) static double bp_seccost(struct as_coord from, struct as_coord to, s_char *pp) { - return ((double) mapdist((coord)from.x, (coord)from.y, - (coord)to.x, (coord)to.y)); + return ((double)mapdist((coord)from.x, (coord)from.y, + (coord)to.x, (coord)to.y)); } #ifdef DO_EFF_MEM_CHECKING @@ -345,18 +352,18 @@ bp_seccost(struct as_coord from, struct as_coord to, s_char *pp) static struct sctstr * bp_getsect(struct bestp *bp, coord x, coord y) { - struct sctstr *sp; - - sp = bp_sctcache_get(bp, x, y); - if (sp == NULL) { - sp = (struct sctstr *) malloc(sizeof(*sp)); - getsect(x, y, sp); - bp_sctcache_set(bp, x, y, sp); - bp->sctcache_misses++; - } else { - bp->sctcache_hits++; - } - return (sp); + struct sctstr *sp; + + sp = bp_sctcache_get(bp, x, y); + if (sp == NULL) { + sp = (struct sctstr *)malloc(sizeof(*sp)); + getsect(x, y, sp); + bp_sctcache_set(bp, x, y, sp); + bp->sctcache_misses++; + } else { + bp->sctcache_hits++; + } + return (sp); } /* @@ -365,18 +372,18 @@ bp_getsect(struct bestp *bp, coord x, coord y) static struct sctstr * bp_sctcache_get(struct bestp *bp, coord x, coord y) { - int hashval; - struct as_coord c; - struct sctcache *hp; - - c.x = x; - c.y = y; - hashval = bp_coord_hash(c) % BP_SCTHASHSIZE; - for (hp = bp->sctcachetab[hashval]; hp; hp = hp->next) { - if (hp->x == x && hp->y == y) - return (hp->sp); - } - return (NULL); + int hashval; + struct as_coord c; + struct sctcache *hp; + + c.x = x; + c.y = y; + hashval = bp_coord_hash(c) % BP_SCTHASHSIZE; + for (hp = bp->sctcachetab[hashval]; hp; hp = hp->next) { + if (hp->x == x && hp->y == y) + return (hp->sp); + } + return (NULL); } /* @@ -385,19 +392,19 @@ bp_sctcache_get(struct bestp *bp, coord x, coord y) static void bp_sctcache_set(struct bestp *bp, coord x, coord y, struct sctstr *sp) { - int hashval; - struct as_coord c; - struct sctcache *hp; - - hp = (struct sctcache *) calloc(1, sizeof(*hp)); - hp->x = x; - hp->y = y; - hp->sp = sp; - c.x = x; - c.y = y; - hashval = bp_coord_hash(c) % BP_SCTHASHSIZE; - hp->next = bp->sctcachetab[hashval]; - bp->sctcachetab[hashval] = hp; + int hashval; + struct as_coord c; + struct sctcache *hp; + + hp = (struct sctcache *)calloc(1, sizeof(*hp)); + hp->x = x; + hp->y = y; + hp->sp = sp; + c.x = x; + c.y = y; + hashval = bp_coord_hash(c) % BP_SCTHASHSIZE; + hp->next = bp->sctcachetab[hashval]; + bp->sctcachetab[hashval] = hp; } /* @@ -406,20 +413,20 @@ bp_sctcache_set(struct bestp *bp, coord x, coord y, struct sctstr *sp) static void bp_sctcache_zap(struct bestp *bp) { - register struct sctcache *hp; - register struct sctcache *np; - register int i; - - for (i = 0; i < BP_SCTHASHSIZE; i++) { - for (hp = bp->sctcachetab[i]; hp; hp = np) { - np = hp->next; - free(hp->sp); - free(hp); - } - bp->sctcachetab[i] = NULL; + register struct sctcache *hp; + register struct sctcache *np; + register int i; + + for (i = 0; i < BP_SCTHASHSIZE; i++) { + for (hp = bp->sctcachetab[i]; hp; hp = np) { + np = hp->next; + free(hp->sp); + free(hp); } - bp->sctcache_hits = 0; - bp->sctcache_misses = 0; + bp->sctcachetab[i] = NULL; + } + bp->sctcache_hits = 0; + bp->sctcache_misses = 0; } #endif /* DO_EFF_MEM_CHECKING */ @@ -430,7 +437,7 @@ bp_sctcache_zap(struct bestp *bp) static int bp_coord_hash(struct as_coord c) { - return ((abs(c.x) + 1) << 3) ^ abs(c.y); + return ((abs(c.x) + 1) << 3) ^ abs(c.y); } void @@ -454,40 +461,38 @@ bp_clear_cachepath() double pathcost(struct sctstr *start, s_char *path, int mob_type) { - register int o; - register int cx, cy; - double cost = 0.0; - struct sctstr *sp; - int sx, sy, offset; - - cx = start->sct_x; - cy = start->sct_y; - - while (*path) { - if (*path == 'h') { - path++; - continue; - } - o = dirindex[(int)((*path) - 'a')]; - cx += diroff[o][0]; - cy += diroff[o][1]; - sx = XNORM(cx); - sy = YNORM(cy); - offset = (sy * WORLD_X + sx) / 2; - sp = (struct sctstr *)(ep->cache + ep->size * offset); - cost += sector_mcost(sp, mob_type); + register int o; + register int cx, cy; + double cost = 0.0; + struct sctstr *sp; + int sx, sy, offset; + + cx = start->sct_x; + cy = start->sct_y; + + while (*path) { + if (*path == 'h') { path++; + continue; } - - return cost; + o = dirindex[(int)((*path) - 'a')]; + cx += diroff[o][0]; + cy += diroff[o][1]; + sx = XNORM(cx); + sy = YNORM(cy); + offset = (sy * WORLD_X + sx) / 2; + sp = (struct sctstr *)(ep->cache + ep->size * offset); + cost += sector_mcost(sp, mob_type); + path++; + } + + return cost; } -s_char * +s_char * BestDistPath(s_char *path, struct sctstr *from, - struct sctstr *to, - double *cost, - int mob_type) + struct sctstr *to, double *cost, int mob_type) { return BestLandPath(path, from, to, cost, mob_type); } @@ -495,9 +500,7 @@ BestDistPath(s_char *path, s_char * BestLandPath(s_char *path, struct sctstr *from, - struct sctstr *to, - double *cost, - int mob_type) + struct sctstr *to, double *cost, int mob_type) { int length; @@ -513,12 +516,7 @@ BestLandPath(s_char *path, } s_char * -BestShipPath(s_char *path, - int fx, - int fy, - int tx, - int ty, - int owner) +BestShipPath(s_char *path, int fx, int fy, int tx, int ty, int owner) { s_char *map; @@ -529,13 +527,8 @@ BestShipPath(s_char *path, } s_char * -BestAirPath(s_char *path, - int fx, - int fy, - int tx, - int ty) +BestAirPath(s_char *path, int fx, int fy, int tx, int ty) { return (bestownedpath(path, 0, fx, fy, tx, ty, "", -1)); - /* return (bestpath(path, fx, fy, tx, ty, ""));*/ + /* return (bestpath(path, fx, fy, tx, ty, "")); */ } - diff --git a/src/lib/common/res_pop.c b/src/lib/common/res_pop.c index 990ffc2e2..9a429d625 100644 --- a/src/lib/common/res_pop.c +++ b/src/lib/common/res_pop.c @@ -47,25 +47,27 @@ int max_pop(float research, struct sctstr *sp) { - int maxpop = 999; + int maxpop = 999; - if (opt_RES_POP) { - maxpop = (((50.0+4.0*research)/(200.0+3.0*research))*600.0) + 400; - if (maxpop > 999) - maxpop = 999; - } + if (opt_RES_POP) { + maxpop = + (((50.0 + 4.0 * research) / (200.0 + + 3.0 * research)) * 600.0) + 400; + if (maxpop > 999) + maxpop = 999; + } - if (opt_BIG_CITY) { - if (sp && dchr[sp->sct_type].d_pkg == UPKG) - maxpop = (int)(maxpop * ((9.0 * sp->sct_effic) / 100 + 1)); - } + if (opt_BIG_CITY) { + if (sp && dchr[sp->sct_type].d_pkg == UPKG) + maxpop = (int)(maxpop * ((9.0 * sp->sct_effic) / 100 + 1)); + } - if (sp) { - if (sp->sct_type == SCT_MOUNT) - maxpop /= 10; - else if (sp->sct_type == SCT_PLAINS) - maxpop /= 20; - } + if (sp) { + if (sp->sct_type == SCT_MOUNT) + maxpop /= 10; + else if (sp->sct_type == SCT_PLAINS) + maxpop /= 20; + } - return maxpop; + return maxpop; } diff --git a/src/lib/common/sectdamage.c b/src/lib/common/sectdamage.c index 828fbf41e..cf1c2d59d 100644 --- a/src/lib/common/sectdamage.c +++ b/src/lib/common/sectdamage.c @@ -53,89 +53,88 @@ int sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list) { - int eff; + int eff; - if (dam <= 0) - return 0; - if (dam > 100) - dam = 100; + if (dam <= 0) + return 0; + if (dam > 100) + dam = 100; - sp->sct_effic = damage((int)sp->sct_effic, dam); - sp->sct_road = damage((int)sp->sct_road, dam); - sp->sct_rail = damage((int)sp->sct_rail, dam); - sp->sct_defense = damage((int)sp->sct_defense, dam); - if (!opt_DEFENSE_INFRA) - sp->sct_defense = sp->sct_effic; + sp->sct_effic = damage((int)sp->sct_effic, dam); + sp->sct_road = damage((int)sp->sct_road, dam); + sp->sct_rail = damage((int)sp->sct_rail, dam); + sp->sct_defense = damage((int)sp->sct_defense, dam); + if (!opt_DEFENSE_INFRA) + sp->sct_defense = sp->sct_effic; - eff = dam; + eff = dam; - if (sp->sct_mobil > 0) - sp->sct_mobil = damage((int)sp->sct_mobil, dam); - sp->sct_nv = vl_damage(dam, - sp->sct_vtype, sp->sct_vamt, - (int)sp->sct_nv); - if (opt_EASY_BRIDGES == 0) { - if (sp->sct_effic < 20 && sp->sct_type == SCT_BHEAD) + if (sp->sct_mobil > 0) + sp->sct_mobil = damage((int)sp->sct_mobil, dam); + sp->sct_nv = vl_damage(dam, + sp->sct_vtype, sp->sct_vamt, (int)sp->sct_nv); + if (opt_EASY_BRIDGES == 0) { + if (sp->sct_effic < 20 && sp->sct_type == SCT_BHEAD) bridgefall(sp, list); - } else { - if (sp->sct_effic < 20 && sp->sct_type == SCT_BSPAN) + } else { + if (sp->sct_effic < 20 && sp->sct_type == SCT_BSPAN) knockdown(sp, list); - } - putsect(sp); - return eff; + } + putsect(sp); + return eff; } int sectdamage(struct sctstr *sp, int dam, struct emp_qelem *list) { - extern double unit_damage; - struct nstr_item ni; - struct lndstr land; - struct plnstr plane; - double real_dam; - int eff; - double sector_strength(); + extern double unit_damage; + struct nstr_item ni; + struct lndstr land; + struct plnstr plane; + double real_dam; + int eff; + double sector_strength(); + + /* Some sectors are harder/easier to kill.. */ + /* Average sector has a dstr of 1, so adjust */ + /* the damage accordingly. Makes forts a pain */ - /* Some sectors are harder/easier to kill.. */ - /* Average sector has a dstr of 1, so adjust */ - /* the damage accordingly. Makes forts a pain */ - /* real_dam = (double)dam * (1.0/((((double)(dchr[sp->sct_type].d_dstr - 1))*(sp->sct_effic/100.0)) + 1.0));*/ - real_dam = (double)dam * (1.0/sector_strength(sp)); - dam = ldround(real_dam,1); + real_dam = (double)dam *(1.0 / sector_strength(sp)); + dam = ldround(real_dam, 1); - eff = sect_damage(sp, PERCENT_DAMAGE(dam), list); + eff = sect_damage(sp, PERCENT_DAMAGE(dam), list); - /* Damage all the land units in the sector */ - /* Units don't take full damage */ - dam = ldround(DPERCENT_DAMAGE(dam * unit_damage), 1); - if (dam <= 0) - return eff; + /* Damage all the land units in the sector */ + /* Units don't take full damage */ + dam = ldround(DPERCENT_DAMAGE(dam * unit_damage), 1); + if (dam <= 0) + return eff; - snxtitem_xy(&ni,EF_LAND,sp->sct_x,sp->sct_y); - while(nxtitem(&ni,(s_char *)&land)){ - if (!land.lnd_own) - continue; - landdamage(&land,dam); - putland(land.lnd_uid,&land); - } + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (!land.lnd_own) + continue; + landdamage(&land, dam); + putland(land.lnd_uid, &land); + } - dam = dam / 7; - if (dam <= 0) - return eff; - snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y); - while (nxtitem(&ni, (s_char *)&plane)) { - if (!plane.pln_own) - continue; - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_ship >= 0) - continue; - /* Is this plane flying in this list? */ - if (ac_isflying(&plane, list)) - continue; - planedamage(&plane, dam); - putplane(plane.pln_uid, &plane); - } + dam = dam / 7; + if (dam <= 0) return eff; + snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (s_char *)&plane)) { + if (!plane.pln_own) + continue; + if (plane.pln_flags & PLN_LAUNCHED) + continue; + if (plane.pln_ship >= 0) + continue; + /* Is this plane flying in this list? */ + if (ac_isflying(&plane, list)) + continue; + planedamage(&plane, dam); + putplane(plane.pln_uid, &plane); + } + return eff; } diff --git a/src/lib/common/snxtit_subs.c b/src/lib/common/snxtit_subs.c index 01ff7031f..fbadfec2b 100644 --- a/src/lib/common/snxtit_subs.c +++ b/src/lib/common/snxtit_subs.c @@ -42,115 +42,116 @@ void snxtitem_area(register struct nstr_item *np, int type, struct range *range) { - bzero((s_char *)np, sizeof(*np)); - np->cur = -1; - np->type = type; - np->sel = NS_AREA; - np->index = -1; - np->range = *range; - np->read = ef_read; - np->flags = ef_flags(type); - xysize_range(&np->range); - ef_zapcache(type); + bzero((s_char *)np, sizeof(*np)); + np->cur = -1; + np->type = type; + np->sel = NS_AREA; + np->index = -1; + np->range = *range; + np->read = ef_read; + np->flags = ef_flags(type); + xysize_range(&np->range); + ef_zapcache(type); } void -snxtitem_dist(register struct nstr_item *np, int type, int cx, int cy, int dist) +snxtitem_dist(register struct nstr_item *np, int type, int cx, int cy, + int dist) { - struct range range; + struct range range; - bzero((s_char *)np, sizeof(*np)); - xydist_range(cx, cy, dist, &range); - np->cur = -1; - np->type = type; - np->sel = NS_DIST; - np->cx = cx; - np->cy = cy; - np->index = -1; - np->range = range; - np->dist = dist; - np->read = ef_read; - np->flags = ef_flags(type); + bzero((s_char *)np, sizeof(*np)); + xydist_range(cx, cy, dist, &range); + np->cur = -1; + np->type = type; + np->sel = NS_DIST; + np->cx = cx; + np->cy = cy; + np->index = -1; + np->range = range; + np->dist = dist; + np->read = ef_read; + np->flags = ef_flags(type); #if 0 - /* This is no longer proper. */ - /* It did the wrong thing for small, hitech worlds. */ - xysize_range(&np->range); + /* This is no longer proper. */ + /* It did the wrong thing for small, hitech worlds. */ + xysize_range(&np->range); #endif - ef_zapcache(type); + ef_zapcache(type); } void snxtitem_xy(register struct nstr_item *np, int type, coord x, coord y) { - bzero((s_char *)np, sizeof(*np)); - np->cur = -1; - np->type = type; - np->sel = NS_XY; - np->cx = xnorm(x); - np->cy = ynorm(y); - np->index = -1; - np->dist = 0; - np->read = ef_read; - np->flags = ef_flags(type); - ef_zapcache(type); + bzero((s_char *)np, sizeof(*np)); + np->cur = -1; + np->type = type; + np->sel = NS_XY; + np->cx = xnorm(x); + np->cy = ynorm(y); + np->index = -1; + np->dist = 0; + np->read = ef_read; + np->flags = ef_flags(type); + ef_zapcache(type); } void snxtitem_all(register struct nstr_item *np, int type) { - bzero((s_char *)np, sizeof(*np)); - np->cur = -1; - np->sel = NS_ALL; - np->type = type; - np->index = -1; - np->read = ef_read; - np->flags = ef_flags(type); - xysize_range(&np->range); - ef_zapcache(type); + bzero((s_char *)np, sizeof(*np)); + np->cur = -1; + np->sel = NS_ALL; + np->type = type; + np->index = -1; + np->read = ef_read; + np->flags = ef_flags(type); + xysize_range(&np->range); + ef_zapcache(type); } void snxtitem_group(register struct nstr_item *np, int type, s_char group) { - if (group == '~') - group = ' '; - bzero((s_char *)np, sizeof(*np)); - np->cur = -1; - np->sel = NS_GROUP; - np->group = group; - np->type = type; - np->index = -1; - np->read = ef_read; - np->flags = ef_flags(type); - xysize_range(&np->range); - ef_zapcache(type); + if (group == '~') + group = ' '; + bzero((s_char *)np, sizeof(*np)); + np->cur = -1; + np->sel = NS_GROUP; + np->group = group; + np->type = type; + np->index = -1; + np->read = ef_read; + np->flags = ef_flags(type); + xysize_range(&np->range); + ef_zapcache(type); } void snxtitem_rewind(struct nstr_item *np) { - np->cur = -1; - np->index = -1; - ef_zapcache(np->type); + np->cur = -1; + np->index = -1; + ef_zapcache(np->type); } int snxtitem_list(register struct nstr_item *np, int type, int *list, int len) { - int i; + int i; - bzero((s_char *)np, sizeof(*np)); - np->cur = -1; - np->type = type; - np->sel = NS_LIST; - np->index = -1; - np->read = ef_read; - np->flags = ef_flags(type); - if (len <= 0 || len > NS_LSIZE) - return 0; - for (i=0; ilist[i] = list[i]; - np->size = len; - ef_zapcache(type); - return 1; + bzero((s_char *)np, sizeof(*np)); + np->cur = -1; + np->type = type; + np->sel = NS_LIST; + np->index = -1; + np->read = ef_read; + np->flags = ef_flags(type); + if (len <= 0 || len > NS_LSIZE) + return 0; + for (i = 0; i < len; i++) + np->list[i] = list[i]; + np->size = len; + ef_zapcache(type); + return 1; } diff --git a/src/lib/common/snxtsct_subs.c b/src/lib/common/snxtsct_subs.c index 7c3cf52cb..91025cadc 100644 --- a/src/lib/common/snxtsct_subs.c +++ b/src/lib/common/snxtsct_subs.c @@ -47,86 +47,86 @@ void snxtsct_all(struct nstr_sect *np) { - struct range worldrange; + struct range worldrange; - worldrange.lx = -WORLD_X/2; - worldrange.ly = -WORLD_Y/2; - worldrange.hx = WORLD_X/2; - worldrange.hy = WORLD_Y/2; - worldrange.width = worldrange.height = 0; - snxtsct_area(np, &worldrange); + worldrange.lx = -WORLD_X / 2; + worldrange.ly = -WORLD_Y / 2; + worldrange.hx = WORLD_X / 2; + worldrange.hy = WORLD_Y / 2; + worldrange.width = worldrange.height = 0; + snxtsct_area(np, &worldrange); } void snxtsct_area(register struct nstr_sect *np, struct range *range) { - bzero((s_char *)np, sizeof(*np)); - np->range = *range; - np->ncond = 0; - np->type = NS_AREA; - np->read = ef_read; - np->x = np->range.lx - 1; - np->y = np->range.ly; - np->dx = -1; - np->dy = 0; - xysize_range(&np->range); - ef_zapcache(EF_SECTOR); + bzero((s_char *)np, sizeof(*np)); + np->range = *range; + np->ncond = 0; + np->type = NS_AREA; + np->read = ef_read; + np->x = np->range.lx - 1; + np->y = np->range.ly; + np->dx = -1; + np->dy = 0; + xysize_range(&np->range); + ef_zapcache(EF_SECTOR); } void snxtsct_rewind(struct nstr_sect *np) { - np->x = np->range.lx - 1; - np->y = np->range.ly; - np->dx = -1; - np->dy = 0; - np->id = -1; - ef_zapcache(EF_SECTOR); + np->x = np->range.lx - 1; + np->y = np->range.ly; + np->dx = -1; + np->dy = 0; + np->id = -1; + ef_zapcache(EF_SECTOR); } void snxtsct_dist(register struct nstr_sect *np, coord cx, coord cy, int dist) { - bzero((s_char *)np, sizeof(*np)); - xydist_range(cx, cy, dist, &np->range); - np->cx = cx; - np->cy = cy; - np->ncond = 0; - np->dist = dist; - np->type = NS_DIST; - np->read = ef_read; - np->x = np->range.lx - 1; - np->y = np->range.ly; - np->dx = -1; - np->dy = 0; + bzero((s_char *)np, sizeof(*np)); + xydist_range(cx, cy, dist, &np->range); + np->cx = cx; + np->cy = cy; + np->ncond = 0; + np->dist = dist; + np->type = NS_DIST; + np->read = ef_read; + np->x = np->range.lx - 1; + np->y = np->range.ly; + np->dx = -1; + np->dy = 0; #if 0 - /* This function is now done elsewhere. */ - /* It was not doing the right thing when the world was small */ - xysize_range(&np->range); + /* This function is now done elsewhere. */ + /* It was not doing the right thing when the world was small */ + xysize_range(&np->range); #endif - ef_zapcache(EF_SECTOR); + ef_zapcache(EF_SECTOR); } void xysize_range(register struct range *rp) { - if (rp->lx >= rp->hx) - rp->width = WORLD_X + rp->hx - rp->lx; - else - rp->width = rp->hx - rp->lx; + if (rp->lx >= rp->hx) + rp->width = WORLD_X + rp->hx - rp->lx; + else + rp->width = rp->hx - rp->lx; #ifndef HAY - /* This is a necessary check for small, hitech worlds. */ - if (rp->width > WORLD_X) - rp->width = WORLD_X; + /* This is a necessary check for small, hitech worlds. */ + if (rp->width > WORLD_X) + rp->width = WORLD_X; #endif - if (rp->ly >= rp->hy) - rp->height = WORLD_Y + rp->hy - rp->ly; - else - rp->height = rp->hy - rp->ly; + if (rp->ly >= rp->hy) + rp->height = WORLD_Y + rp->hy - rp->ly; + else + rp->height = rp->hy - rp->ly; #ifndef HAY - /* This is a necessary check for small, hitech worlds. */ - if (rp->height > WORLD_Y) - rp->height = WORLD_Y; + /* This is a necessary check for small, hitech worlds. */ + if (rp->height > WORLD_Y) + rp->height = WORLD_Y; #endif } @@ -134,26 +134,26 @@ xysize_range(register struct range *rp) void xydist_range(coord x, coord y, register int dist, struct range *rp) { - if (dist < WORLD_X/4) { - rp->lx = xnorm((coord)(x - 2 * dist)); - rp->hx = xnorm((coord)(x + 2 * dist) + 1); - rp->width = 4 * dist + 1; - } else { - /* Range is larger than the world */ - /* Make sure we get lx in the right place. */ - rp->lx = xnorm((coord)(x - WORLD_X/2)); - rp->hx = xnorm((coord)(rp->lx + WORLD_X - 1)); - rp->width = WORLD_X; - } + if (dist < WORLD_X / 4) { + rp->lx = xnorm((coord)(x - 2 * dist)); + rp->hx = xnorm((coord)(x + 2 * dist) + 1); + rp->width = 4 * dist + 1; + } else { + /* Range is larger than the world */ + /* Make sure we get lx in the right place. */ + rp->lx = xnorm((coord)(x - WORLD_X / 2)); + rp->hx = xnorm((coord)(rp->lx + WORLD_X - 1)); + rp->width = WORLD_X; + } - if (dist < WORLD_Y/2) { - rp->ly = ynorm((coord)(y - dist)); - rp->hy = ynorm((coord)(y + dist) + 1); - rp->height = 2 * dist + 1; - } else { - /* Range is larger than the world */ - rp->ly = ynorm((coord)(y - WORLD_Y/2)); - rp->hy = ynorm((coord)(rp->ly + WORLD_Y - 1)); - rp->height = WORLD_Y; - } + if (dist < WORLD_Y / 2) { + rp->ly = ynorm((coord)(y - dist)); + rp->hy = ynorm((coord)(y + dist) + 1); + rp->height = 2 * dist + 1; + } else { + /* Range is larger than the world */ + rp->ly = ynorm((coord)(y - WORLD_Y / 2)); + rp->hy = ynorm((coord)(rp->ly + WORLD_Y - 1)); + rp->height = WORLD_Y; + } } diff --git a/src/lib/common/stmtch.c b/src/lib/common/stmtch.c index 958a13abb..2233a98ab 100644 --- a/src/lib/common/stmtch.c +++ b/src/lib/common/stmtch.c @@ -47,23 +47,23 @@ int stmtch(register s_char *obj, s_char *base, int off, int size) { - register s_char *str; - register int stat2; - register int i; - register int n; + register s_char *str; + register int stat2; + register int i; + register int n; - stat2 = M_NOTFOUND; - str = base + off; - for (i=0; *(s_char **)str; i++, str += size) { - if ((n = mineq(obj, *(s_char **)str)) == ME_MISMATCH) - continue; - if (n == ME_EXACT) - return i; - if (stat2 != M_NOTFOUND) - return M_NOTUNIQUE; - stat2 = i; - } - return stat2; + stat2 = M_NOTFOUND; + str = base + off; + for (i = 0; *(s_char **)str; i++, str += size) { + if ((n = mineq(obj, *(s_char **)str)) == ME_MISMATCH) + continue; + if (n == ME_EXACT) + return i; + if (stat2 != M_NOTFOUND) + return M_NOTUNIQUE; + stat2 = i; + } + return stat2; } /* @@ -72,11 +72,11 @@ stmtch(register s_char *obj, s_char *base, int off, int size) int mineq(register s_char *a, register s_char *b) { - do { - if (*a++ != *b++) - return ME_MISMATCH; - } while (*b != ' ' && *a != 0); - if (*a == 0 && (*b == ' ' || *b == 0)) - return ME_EXACT; - return ME_PARTIAL; + do { + if (*a++ != *b++) + return ME_MISMATCH; + } while (*b != ' ' && *a != 0); + if (*a == 0 && (*b == ' ' || *b == 0)) + return ME_EXACT; + return ME_PARTIAL; } diff --git a/src/lib/common/tfact.c b/src/lib/common/tfact.c index dfdd847ca..934a7a5c6 100644 --- a/src/lib/common/tfact.c +++ b/src/lib/common/tfact.c @@ -40,40 +40,40 @@ extern float fire_range_factor; double tfact(natid cn, double mult) { - double tlev; - struct natstr *np; + double tlev; + struct natstr *np; - np = getnatp(cn); - tlev = np->nat_level[NAT_TLEV]; - tlev = (50.0 + tlev) / (200.0 + tlev); - return mult * tlev; + np = getnatp(cn); + tlev = np->nat_level[NAT_TLEV]; + tlev = (50.0 + tlev) / (200.0 + tlev); + return mult * tlev; } double tfactfire(natid cn, double mult) { - double tlev; - struct natstr *np; + double tlev; + struct natstr *np; - np = getnatp(cn); - tlev = np->nat_level[NAT_TLEV]; - tlev = (50.0 + tlev) / (200.0 + tlev); - return mult * tlev * fire_range_factor; + np = getnatp(cn); + tlev = np->nat_level[NAT_TLEV]; + tlev = (50.0 + tlev) / (200.0 + tlev); + return mult * tlev * fire_range_factor; } double techfact(int level, double mult) { - return mult * ((50.0 + level) / (200.0 + level)); + return mult * ((50.0 + level) / (200.0 + level)); } /* * added so that firing range can be different to other ranges - */ + */ double techfactfire(int level, double mult) { - return mult * ((50.0 + level) / (200.0 + level)) * fire_range_factor; + return mult * ((50.0 + level) / (200.0 + level)) * fire_range_factor; } /* @@ -82,8 +82,8 @@ techfactfire(int level, double mult) double reltech(int level1, int level2, double mult) { - int diff; + int diff; - diff = level1 - level2; - return (1.0 + ((diff + 50.0) / (level1 + 50.0))) * mult; + diff = level1 - level2; + return (1.0 + ((diff + 50.0) / (level1 + 50.0))) * mult; } diff --git a/src/lib/common/type.c b/src/lib/common/type.c index e01a5aaf0..8a192b166 100644 --- a/src/lib/common/type.c +++ b/src/lib/common/type.c @@ -47,55 +47,55 @@ int typematch(s_char *buf, int type) { - register int n; - int len; + register int n; + int len; - len = strlen(buf); - switch (type) { - case EF_SECTOR: { - register struct dchrstr *dcp; - - if (!buf[0] || buf[1]) - return -1; - for (dcp=dchr,n=0; dcp->d_name; n++,dcp++) - if (dcp->d_mnem == *buf) - return n; - } - break; - case EF_SHIP: { - register struct mchrstr *mcp; - - for (mcp=mchr,n=0; *mcp->m_name; n++,mcp++) - if (strncmp(mcp->m_name, buf, len) == 0) - return n; - } - break; - case EF_LAND: { - register struct lchrstr *lcp; + len = strlen(buf); + switch (type) { + case EF_SECTOR:{ + register struct dchrstr *dcp; - for (lcp=lchr,n=0; *lcp->l_name; n++,lcp++) - if (strncmp(lcp->l_name, buf, len) == 0) - return n; - } - break; - case EF_PLANE: { - register struct plchrstr *pcp; - - for (pcp=plchr,n=0; *pcp->pl_name; n++,pcp++) - if (strncmp(pcp->pl_name, buf, len) == 0) - return n; - } - break; - case EF_NUKE: { - register struct nchrstr *ncp; - - for (ncp=nchr,n=0; *ncp->n_name; n++,ncp++) - if (strncmp(ncp->n_name, buf, len) == 0) - return n; - } - break; - default: - break; + if (!buf[0] || buf[1]) + return -1; + for (dcp = dchr, n = 0; dcp->d_name; n++, dcp++) + if (dcp->d_mnem == *buf) + return n; } - return -1; + break; + case EF_SHIP:{ + register struct mchrstr *mcp; + + for (mcp = mchr, n = 0; *mcp->m_name; n++, mcp++) + if (strncmp(mcp->m_name, buf, len) == 0) + return n; + } + break; + case EF_LAND:{ + register struct lchrstr *lcp; + + for (lcp = lchr, n = 0; *lcp->l_name; n++, lcp++) + if (strncmp(lcp->l_name, buf, len) == 0) + return n; + } + break; + case EF_PLANE:{ + register struct plchrstr *pcp; + + for (pcp = plchr, n = 0; *pcp->pl_name; n++, pcp++) + if (strncmp(pcp->pl_name, buf, len) == 0) + return n; + } + break; + case EF_NUKE:{ + register struct nchrstr *ncp; + + for (ncp = nchr, n = 0; *ncp->n_name; n++, ncp++) + if (strncmp(ncp->n_name, buf, len) == 0) + return n; + } + break; + default: + break; + } + return -1; } diff --git a/src/lib/common/vlist.c b/src/lib/common/vlist.c index 3bfd9d0b3..38f2ee0d3 100644 --- a/src/lib/common/vlist.c +++ b/src/lib/common/vlist.c @@ -41,115 +41,116 @@ #include "common.h" #include "gen.h" -static int freeslot(u_char *vec, register u_char *end); +static int freeslot(u_char *vec, register u_char *end); int vl_find(register int vtype, u_char *typevec, u_short *amtvec, int nelem) { - register u_char *vp; - register u_short *ap; - register u_char *endp; + register u_char *vp; + register u_short *ap; + register u_char *endp; - if (vtype < 0 || vtype > V_MAX) - return -1; - vp = typevec; - ap = amtvec; - endp = vp + nelem; - for ( ; vp < endp; vp++, ap++) { - if (*vp == vtype) - return (int) *ap; - } - return 0; + if (vtype < 0 || vtype > V_MAX) + return -1; + vp = typevec; + ap = amtvec; + endp = vp + nelem; + for (; vp < endp; vp++, ap++) { + if (*vp == vtype) + return (int)*ap; + } + return 0; } int -vl_set(register int vtype, u_int amt, u_char *typevec, u_short *amtvec, u_char *nvp, int max) +vl_set(register int vtype, u_int amt, u_char *typevec, u_short *amtvec, + u_char *nvp, int max) { - register u_char *vp; - register u_char *endp; - register u_short *ap; - int n; + register u_char *vp; + register u_char *endp; + register u_short *ap; + int n; - if (vtype < 0 || vtype > V_MAX) - return 0; - if (amt > 65536) { - logerror("vl_set: bad amt %d (%x), vtype %d\n", (int)amt, amt, - vtype); - return 0; - } - vp = typevec; - ap = amtvec; - endp = vp + *nvp; - for ( ; vp < endp; vp++, ap++) { - if (*vp == vtype) - break; + if (vtype < 0 || vtype > V_MAX) + return 0; + if (amt > 65536) { + logerror("vl_set: bad amt %d (%x), vtype %d\n", (int)amt, amt, + vtype); + return 0; + } + vp = typevec; + ap = amtvec; + endp = vp + *nvp; + for (; vp < endp; vp++, ap++) { + if (*vp == vtype) + break; + } + if (vp == endp) { + if (amt == 0) { + /* deleting, but not present */ + return 0; } - if (vp == endp) { - if (amt == 0) { - /* deleting, but not present */ - return 0; - } - if (*nvp == max) { - if (isdel(vtype) || isdist(vtype)) - return -1; - /* replace any del or dst entries */ - if ((n = freeslot(typevec, endp)) < 0) - return -1; - vp = &typevec[n]; - ap = &amtvec[n]; - } else { - /* add at end */ - (*nvp)++; - } - *vp = vtype; - *ap = amt; + if (*nvp == max) { + if (isdel(vtype) || isdist(vtype)) + return -1; + /* replace any del or dst entries */ + if ((n = freeslot(typevec, endp)) < 0) + return -1; + vp = &typevec[n]; + ap = &amtvec[n]; } else { - if (amt != 0) { - /* altering; just change value */ - *ap = amt; - return 1; - } - (*nvp)--; - if (vp < endp-1) { - /* if not last element, copy last to current */ - *ap = amtvec[*nvp]; - *vp = typevec[*nvp]; - } + /* add at end */ + (*nvp)++; } - return 1; + *vp = vtype; + *ap = amt; + } else { + if (amt != 0) { + /* altering; just change value */ + *ap = amt; + return 1; + } + (*nvp)--; + if (vp < endp - 1) { + /* if not last element, copy last to current */ + *ap = amtvec[*nvp]; + *vp = typevec[*nvp]; + } + } + return 1; } int -vl_damage(register int pct, register u_char *typevec, register u_short *amtvec, register int nelem) +vl_damage(register int pct, register u_char *typevec, + register u_short *amtvec, register int nelem) { - register int i; - register int lose; - extern double people_damage; + register int i; + register int lose; + extern double people_damage; - if (pct >= 100) - return 0; - if (pct <= 0) - return nelem; - for (i=0; i= 100) + return 0; + if (pct <= 0) return nelem; + for (i = 0; i < nelem; i++) { + if (!isitem(typevec[i])) + continue; + if (opt_SUPER_BARS && typevec[i] == V_BAR) + continue; + lose = roundavg((double)amtvec[i] * pct * 0.01); + if (typevec[i] == V_CIVIL || + typevec[i] == V_MILIT || typevec[i] == V_UW) + lose = ldround(people_damage * lose, 1); + if ((amtvec[i] -= lose) + 1 == 0) { + nelem--; + if (i == nelem) + break; + typevec[i] = typevec[nelem]; + amtvec[i] = amtvec[nelem]; + i--; + } + } + return nelem; } /* @@ -158,27 +159,28 @@ vl_damage(register int pct, register u_char *typevec, register u_short *amtvec, * or else bad things will happen. */ int -vl_getvec(register u_char *src_type, register u_short *src_amt, register int src_nv, register int class, register int *dst_amt) +vl_getvec(register u_char *src_type, register u_short *src_amt, + register int src_nv, register int class, register int *dst_amt) { - register int n; - int count; - int item; + register int n; + int count; + int item; - for (n=0; n I_MAX) { - logerror("vl_getvec: bad I-type %d (vtype %d)\n", - item, src_type[n]); - continue; - } - dst_amt[item] = src_amt[n]; - count++; + for (n = 0; n < I_MAX + 1; n++) + dst_amt[n] = 0; + for (count = 0, n = 0; n < src_nv; n++) { + if ((src_type[n] & VT_TYPE) != class) + continue; + item = src_type[n] & ~VT_TYPE; + if (item > I_MAX) { + logerror("vl_getvec: bad I-type %d (vtype %d)\n", + item, src_type[n]); + continue; } - return count; + dst_amt[item] = src_amt[n]; + count++; + } + return count; } /* @@ -187,83 +189,84 @@ vl_getvec(register u_char *src_type, register u_short *src_amt, register int src * present in the vec will be added to the vlist. */ int -vl_setvec(register u_char *type, register u_short *amt, u_char *nvp, int max, register int class, register int *vec) +vl_setvec(register u_char *type, register u_short *amt, u_char *nvp, + int max, register int class, register int *vec) { - register int nv; - register int n; - register int vec_n; + register int nv; + register int n; + register int vec_n; - nv = *nvp; - vec_n = 1; - n = 0; - while (n < nv) { - if ((type[n] & VT_TYPE) != class) { - n++; - continue; - } - /* find non-zero vec entry to overwrite current slot */ - for ( ; vec_n <= I_MAX; vec_n++) - if (vec[vec_n] != 0) - break; - if (vec_n > I_MAX) { - /* no more elements left; delete */ - nv--; - if (n < nv) { - /* copy last entry over current entry */ - type[n] = type[nv]; - amt[n] = amt[nv]; - } - } else { - /* use new (unused) entry */ - type[n] = vec_n | class; - amt[n] = vec[vec_n]; - vec_n++; - n++; - } + nv = *nvp; + vec_n = 1; + n = 0; + while (n < nv) { + if ((type[n] & VT_TYPE) != class) { + n++; + continue; } - *nvp = nv; - if (n >= nv && vec_n > I_MAX) - return 1; - /* free slots at end; copy rest of vec into the vlist */ - for ( ; vec_n <= I_MAX && nv < max; vec_n++) { - if (vec[vec_n] == 0) - continue; - type[nv] = vec_n | class; - amt[nv] = vec[vec_n]; - nv++; + /* find non-zero vec entry to overwrite current slot */ + for (; vec_n <= I_MAX; vec_n++) + if (vec[vec_n] != 0) + break; + if (vec_n > I_MAX) { + /* no more elements left; delete */ + nv--; + if (n < nv) { + /* copy last entry over current entry */ + type[n] = type[nv]; + amt[n] = amt[nv]; + } + } else { + /* use new (unused) entry */ + type[n] = vec_n | class; + amt[n] = vec[vec_n]; + vec_n++; + n++; } - *nvp = nv; - if (vec_n <= I_MAX && (class == VT_ITEM || class == VT_COND)) { - /* - * still stuff left; make free slots out of deliveries - * and distributes and stuff 'em in (only for item or cond) - */ - for ( ; vec_n <= I_MAX; vec_n++) { - if (vec[vec_n] == 0) - continue; - if ((n = freeslot(type, &type[max])) < 0) { - logerror("vl_setvec: no free slots left\n"); - return 0; - } - logerror("vl_setvec: replacing type %d amt %d\n", - type[n], amt[n]); - type[n] = vec_n | class; - amt[n] = vec[vec_n]; - } + } + *nvp = nv; + if (n >= nv && vec_n > I_MAX) + return 1; + /* free slots at end; copy rest of vec into the vlist */ + for (; vec_n <= I_MAX && nv < max; vec_n++) { + if (vec[vec_n] == 0) + continue; + type[nv] = vec_n | class; + amt[nv] = vec[vec_n]; + nv++; + } + *nvp = nv; + if (vec_n <= I_MAX && (class == VT_ITEM || class == VT_COND)) { + /* + * still stuff left; make free slots out of deliveries + * and distributes and stuff 'em in (only for item or cond) + */ + for (; vec_n <= I_MAX; vec_n++) { + if (vec[vec_n] == 0) + continue; + if ((n = freeslot(type, &type[max])) < 0) { + logerror("vl_setvec: no free slots left\n"); + return 0; + } + logerror("vl_setvec: replacing type %d amt %d\n", + type[n], amt[n]); + type[n] = vec_n | class; + amt[n] = vec[vec_n]; } - if (nv == max) { - /* checking for overflow */ - while (vec_n <= I_MAX) { - if (vec[vec_n]) - break; - } - if (vec_n <= I_MAX) { - logerror("vl_setvec: no space for i-type #%d (%d)\n", - vec_n, vec[vec_n]); - return 0; - } + } + if (nv == max) { + /* checking for overflow */ + while (vec_n <= I_MAX) { + if (vec[vec_n]) + break; } - return 1; + if (vec_n <= I_MAX) { + logerror("vl_setvec: no space for i-type #%d (%d)\n", + vec_n, vec[vec_n]); + return 0; + } + } + return 1; } /* @@ -271,14 +274,14 @@ vl_setvec(register u_char *type, register u_short *amt, u_char *nvp, int max, re * are fair game for us. */ static -int + int freeslot(u_char *vec, register u_char *end) { - register u_char *vp; + register u_char *vp; - for (vp=vec; vp < end; vp++) { - if (isdel(*vp) || isdist(*vp)) - return vp - vec; - } - return -1; + for (vp = vec; vp < end; vp++) { + if (isdel(*vp) || isdist(*vp)) + return vp - vec; + } + return -1; } diff --git a/src/lib/common/wantupd.c b/src/lib/common/wantupd.c index 038cda62b..ae67955b4 100644 --- a/src/lib/common/wantupd.c +++ b/src/lib/common/wantupd.c @@ -47,156 +47,164 @@ #include #if defined(Rel4) || defined(_WIN32) #include -#else /* Rel4 */ +#else /* Rel4 */ #include #endif /* Rel4 */ void update_policy_check(void) { - extern int update_policy,update_demandpolicy; - extern int update_wantmin,blitz_time; - - if (update_policy < 0) update_policy = UDP_DEFAULT; - if (update_policy > UDP_MAX) update_policy = UDP_DEFAULT; - if (update_demandpolicy < 0) update_demandpolicy = UDDEM_DEFAULT; - if (update_demandpolicy > UDDEM_MAX) - update_demandpolicy = UDDEM_DEFAULT; - if (update_wantmin < 0) update_wantmin = 0; - if (update_wantmin > MAXNOC) update_wantmin = MAXNOC; - if (blitz_time < 0) blitz_time = 0; + extern int update_policy, update_demandpolicy; + extern int update_wantmin, blitz_time; + + if (update_policy < 0) + update_policy = UDP_DEFAULT; + if (update_policy > UDP_MAX) + update_policy = UDP_DEFAULT; + if (update_demandpolicy < 0) + update_demandpolicy = UDDEM_DEFAULT; + if (update_demandpolicy > UDDEM_MAX) + update_demandpolicy = UDDEM_DEFAULT; + if (update_wantmin < 0) + update_wantmin = 0; + if (update_wantmin > MAXNOC) + update_wantmin = MAXNOC; + if (blitz_time < 0) + blitz_time = 0; } static int -demand_update_time(time_t *now) +demand_update_time(time_t * now) { - struct tm *tm; - s_char *p; - int curtime; - int hour[2]; - extern s_char *update_demandtimes; - - tm = localtime(now); - curtime = tm->tm_min + tm->tm_hour * 60; - p=update_demandtimes; - if (*p == 0) return(1); - while (NULL != (p = kw_parse(CF_TIMERANGE, p, &hour[0]))) { - if (curtime >= hour[0] && curtime < hour[1]) - return(1); - } - return(0); + struct tm *tm; + s_char *p; + int curtime; + int hour[2]; + extern s_char *update_demandtimes; + + tm = localtime(now); + curtime = tm->tm_min + tm->tm_hour * 60; + p = update_demandtimes; + if (*p == 0) + return (1); + while (NULL != (p = kw_parse(CF_TIMERANGE, p, &hour[0]))) { + if (curtime >= hour[0] && curtime < hour[1]) + return (1); + } + return (0); } /* When is the next regularly scheduled update from now. */ static void -regular_update_time(time_t *now, time_t *tim, time_t *delta) +regular_update_time(time_t * now, time_t * tim, time_t * delta) { - extern int s_p_etu; - extern int etu_per_update; - extern int adj_update; - s_char *p; - time_t tw; - int secs_per_update; - - tw = *now + adj_update; - secs_per_update = etu_per_update * s_p_etu; - *delta = secs_per_update - (tw % secs_per_update); - *tim = *now + *delta; + extern int s_p_etu; + extern int etu_per_update; + extern int adj_update; + s_char *p; + time_t tw; + int secs_per_update; + + tw = *now + adj_update; + secs_per_update = etu_per_update * s_p_etu; + *delta = secs_per_update - (tw % secs_per_update); + *tim = *now + *delta; } /* Is this a valid time for a scheduled update. */ static int -scheduled_update_time(time_t *now, int *which) +scheduled_update_time(time_t * now, int *which) { - struct tm *tm; - s_char *p, *p1; - int curtime; - int hour; - extern int hourslop; - extern s_char *update_times; - - *which = -1; - p=update_times; - if (*p == 0) return(0); - - tm = localtime(now); - curtime = tm->tm_min + tm->tm_hour * 60; - while (NULL != (p = kw_parse(CF_TIME, p, &hour))) { - (*which) ++; - if (curtime >= hour && - curtime < hour+hourslop) - return(1); - } - - return 0; + struct tm *tm; + s_char *p, *p1; + int curtime; + int hour; + extern int hourslop; + extern s_char *update_times; + + *which = -1; + p = update_times; + if (*p == 0) + return (0); + + tm = localtime(now); + curtime = tm->tm_min + tm->tm_hour * 60; + while (NULL != (p = kw_parse(CF_TIME, p, &hour))) { + (*which)++; + if (curtime >= hour && curtime < hour + hourslop) + return (1); + } + + return 0; } static int -next_scheduled_time(time_t *now, time_t *tim, time_t *delta) +next_scheduled_time(time_t * now, time_t * tim, time_t * delta) { - struct tm *tm; - s_char *p; - int curtime; - int hour; - int mintime; - extern s_char *update_times; - - p=update_times; - if (*p == 0) return(0); - - tm = localtime(now); - curtime = tm->tm_min + tm->tm_hour * 60; /* now - in minutes */ - mintime = curtime + 24*60+1; /* start with now + 1 day */ - while (NULL != (p = kw_parse(CF_TIME, p, &hour))) { - if (hour <= curtime) - hour += 24 * 60; /* this must be tomorrow */ - if (hour < mintime) - mintime = hour; /* this is best bet so far */ - } - *delta = 60*(mintime - curtime); - *tim = *now + *delta - tm->tm_sec; - return(1); + struct tm *tm; + s_char *p; + int curtime; + int hour; + int mintime; + extern s_char *update_times; + + p = update_times; + if (*p == 0) + return (0); + + tm = localtime(now); + curtime = tm->tm_min + tm->tm_hour * 60; /* now - in minutes */ + mintime = curtime + 24 * 60 + 1; /* start with now + 1 day */ + while (NULL != (p = kw_parse(CF_TIME, p, &hour))) { + if (hour <= curtime) + hour += 24 * 60; /* this must be tomorrow */ + if (hour < mintime) + mintime = hour; /* this is best bet so far */ + } + *delta = 60 * (mintime - curtime); + *tim = *now + *delta - tm->tm_sec; + return (1); } int demand_update_want(int *want, int *pop, int which) { - natid cn; - struct natstr *natp; - int totpop; - int totwant; - int whichwants; - - whichwants = totpop = totwant = 0; - for (cn = 1; 0 != (natp = getnatp(cn)); cn++) { - /* Only countries which are normal. */ - /* Should probably include sanctuaries ..... */ - if (((natp->nat_stat & NORM) == NORM) && - ((natp->nat_stat & GOD) != GOD)) { - totpop++; - if ((natp->nat_update & WUPD_WANT) == WUPD_WANT) { - totwant++; - if (which == cn) - whichwants++; - } - } + natid cn; + struct natstr *natp; + int totpop; + int totwant; + int whichwants; + + whichwants = totpop = totwant = 0; + for (cn = 1; 0 != (natp = getnatp(cn)); cn++) { + /* Only countries which are normal. */ + /* Should probably include sanctuaries ..... */ + if (((natp->nat_stat & NORM) == NORM) && + ((natp->nat_stat & GOD) != GOD)) { + totpop++; + if ((natp->nat_update & WUPD_WANT) == WUPD_WANT) { + totwant++; + if (which == cn) + whichwants++; + } } - *want = totwant; - *pop = totpop; - return(whichwants); + } + *want = totwant; + *pop = totpop; + return (whichwants); } static int demand_check(void) { - extern int update_wantmin,update_missed; - struct natstr *natp; - int want, pop, cn, veto; - time_t now; - time_t cur; - extern long last_demand_update; + extern int update_wantmin, update_missed; + struct natstr *natp; + int want, pop, cn, veto; + time_t now; + time_t cur; + extern long last_demand_update; - time(&cur); + time(&cur); /* if (last_demand_update == 0){ @@ -223,45 +231,45 @@ demand_check(void) logerror("No forced update!\n"); */ - if (0 == update_wantmin) { - logerror("no demand update allowed, wantmin = 0"); - return(0); - } - - demand_update_want(&want, &pop, 0); - if (want < update_wantmin) { - logerror("no demand update, want = %d, min = %d", - want, update_wantmin); - return(0); - } - - time(&now); - if (!demand_update_time(&now)) { - logerror("no demand update, not within hours allowed."); - return(0); - } - - - veto=0; - for (cn = 1; 0 != (natp = getnatp(cn)); cn++){ - if (((natp->nat_stat & NORM) == NORM) && - ((natp->nat_stat & GOD) != GOD)){ - if (natp->nat_missed >= update_missed) - veto=cn+1; - } - } - - if (veto){ - logerror("no demand update, %d has missed more than %d updates", - veto-1, update_missed); - return(0); + if (0 == update_wantmin) { + logerror("no demand update allowed, wantmin = 0"); + return (0); + } + + demand_update_want(&want, &pop, 0); + if (want < update_wantmin) { + logerror("no demand update, want = %d, min = %d", + want, update_wantmin); + return (0); + } + + time(&now); + if (!demand_update_time(&now)) { + logerror("no demand update, not within hours allowed."); + return (0); + } + + + veto = 0; + for (cn = 1; 0 != (natp = getnatp(cn)); cn++) { + if (((natp->nat_stat & NORM) == NORM) && + ((natp->nat_stat & GOD) != GOD)) { + if (natp->nat_missed >= update_missed) + veto = cn + 1; } - - last_demand_update = cur; - natp=getnatp(0); - /* A dumb way to do it, but simple */ - last_demand_update = natp->nat_reserve; - return(1); + } + + if (veto) { + logerror("no demand update, %d has missed more than %d updates", + veto - 1, update_missed); + return (0); + } + + last_demand_update = cur; + natp = getnatp(0); + /* A dumb way to do it, but simple */ + last_demand_update = natp->nat_reserve; + return (1); } /* Check if enough countries want an update, @@ -270,14 +278,14 @@ demand_check(void) int demandupdatecheck(void) { - extern int update_demandpolicy; + extern int update_demandpolicy; - if (UDDEM_COMSET != update_demandpolicy) { - logerror("no demand update, not policy."); - return(0); - } + if (UDDEM_COMSET != update_demandpolicy) { + logerror("no demand update, not policy."); + return (0); + } - return(demand_check()); + return (demand_check()); } /* Is it time for a regular or scheduled update? @@ -285,34 +293,34 @@ demandupdatecheck(void) * a demand update can occur. */ int -updatetime(time_t *now) +updatetime(time_t * now) { - extern int update_policy; - int which; - - if (opt_BLITZ && update_policy == UDP_BLITZ) { - logerror("BLITZ Update."); - return(1); - } - - if (UDP_NORMAL == update_policy) { - logerror("Regular update, etu type."); - return(1); + extern int update_policy; + int which; + + if (opt_BLITZ && update_policy == UDP_BLITZ) { + logerror("BLITZ Update."); + return (1); + } + + if (UDP_NORMAL == update_policy) { + logerror("Regular update, etu type."); + return (1); + } + + if (UDP_TIMES == update_policy) { + if (scheduled_update_time(now, &which)) { + logerror("Scheduled update, %d.", which); + return (1); } - - if (UDP_TIMES == update_policy) { - if (scheduled_update_time(now, &which)) { - logerror("Scheduled update, %d.", which); - return(1); - } - } - if (opt_DEMANDUPDATE) { - if (demand_check()) { - logerror("Demand update, at check time."); - return(1); - } + } + if (opt_DEMANDUPDATE) { + if (demand_check()) { + logerror("Demand update, at check time."); + return (1); } - return(0); + } + return (0); } /* Return the time, and delta seconds, of the next update. @@ -320,80 +328,80 @@ updatetime(time_t *now) * the next possible check. */ void -next_update_time(time_t *now, time_t *tim, time_t *delta) - /* From when */ - /* Time of next update */ - /* Seconds till next update */ +next_update_time(time_t * now, time_t * tim, time_t * delta) + /* From when */ + /* Time of next update */ + /* Seconds till next update */ { - extern int update_policy; - time_t stim, sdelta; - extern int blitz_time; - - switch (update_policy) { - case UDP_NORMAL: - regular_update_time(now, tim, delta); - break; - case UDP_TIMES: - if (!next_scheduled_time(now, tim, delta)) - regular_update_time(now, tim, delta); - break; - case UDP_BLITZ: - *delta = (blitz_time * 60) - (*now % (blitz_time * 60)); - *tim = *now + *delta; - break; - - case UDP_NOREG: - default: - regular_update_time(now, tim, delta); - if (next_scheduled_time(now, &stim, &sdelta)) { - if (*delta > sdelta) { - *delta = sdelta; - *tim = stim; - } - } - break; + extern int update_policy; + time_t stim, sdelta; + extern int blitz_time; + + switch (update_policy) { + case UDP_NORMAL: + regular_update_time(now, tim, delta); + break; + case UDP_TIMES: + if (!next_scheduled_time(now, tim, delta)) + regular_update_time(now, tim, delta); + break; + case UDP_BLITZ: + *delta = (blitz_time * 60) - (*now % (blitz_time * 60)); + *tim = *now + *delta; + break; + + case UDP_NOREG: + default: + regular_update_time(now, tim, delta); + if (next_scheduled_time(now, &stim, &sdelta)) { + if (*delta > sdelta) { + *delta = sdelta; + *tim = stim; + } } + break; + } } void -next_update_check_time(time_t *now, time_t *tim, time_t *delta) - /* From when */ - /* Time of next update */ - /* Seconds till next update check */ +next_update_check_time(time_t * now, time_t * tim, time_t * delta) + /* From when */ + /* Time of next update */ + /* Seconds till next update check */ { - extern int update_policy; - time_t stim, sdelta; - extern int blitz_time; - - switch (update_policy) { - case UDP_NORMAL: - regular_update_time(now, tim, delta); - break; - case UDP_BLITZ: - *delta = (blitz_time * 60) - (*now % (blitz_time * 60)); - *tim = *now + *delta; - break; - case UDP_TIMES: - case UDP_NOREG: - default: - regular_update_time(now, tim, delta); - if (next_scheduled_time(now, &stim, &sdelta)) { - if (*delta > sdelta) { - *delta = sdelta; - *tim = stim; - } - } + extern int update_policy; + time_t stim, sdelta; + extern int blitz_time; + + switch (update_policy) { + case UDP_NORMAL: + regular_update_time(now, tim, delta); + break; + case UDP_BLITZ: + *delta = (blitz_time * 60) - (*now % (blitz_time * 60)); + *tim = *now + *delta; + break; + case UDP_TIMES: + case UDP_NOREG: + default: + regular_update_time(now, tim, delta); + if (next_scheduled_time(now, &stim, &sdelta)) { + if (*delta > sdelta) { + *delta = sdelta; + *tim = stim; + } } + } } int updates_disabled(void) { - extern s_char *disablefil; - int fd; + extern s_char *disablefil; + int fd; - if ((fd = open(disablefil, O_RDONLY, 0)) < 0) - return 0; - close(fd); - return 1; + if ((fd = open(disablefil, O_RDONLY, 0)) < 0) + return 0; + close(fd); + return 1; } diff --git a/src/lib/common/xy.c b/src/lib/common/xy.c index 2ba3c2cdc..9135cd83b 100644 --- a/src/lib/common/xy.c +++ b/src/lib/common/xy.c @@ -50,163 +50,162 @@ s_char * xyas(coord x, coord y, natid country) { - struct natstr *np; + struct natstr *np; - np = getnatp(country); - return prbuf("%d,%d", xrel(np, x), yrel(np, y)); + np = getnatp(country); + return prbuf("%d,%d", xrel(np, x), yrel(np, y)); } s_char * ownxy(struct sctstr *sp) { - return xyas(sp->sct_x, sp->sct_y, sp->sct_own); + return xyas(sp->sct_x, sp->sct_y, sp->sct_own); } coord xrel(struct natstr *np, coord absx) { - coord x; - - if ((np->nat_stat & STAT_ABS) == 0) { - x = XNORM(absx - np->nat_xorg); - } else { - x = XNORM(absx); - } - if (x >= WORLD_X/2) - x -= WORLD_X; - else if (x < -WORLD_X/2) - x += WORLD_X; - return x; + coord x; + + if ((np->nat_stat & STAT_ABS) == 0) { + x = XNORM(absx - np->nat_xorg); + } else { + x = XNORM(absx); + } + if (x >= WORLD_X / 2) + x -= WORLD_X; + else if (x < -WORLD_X / 2) + x += WORLD_X; + return x; } coord yrel(struct natstr *np, coord absy) { - coord y; - - if ((np->nat_stat & STAT_ABS) == 0) { - y = YNORM(absy - np->nat_yorg); - } else { - y = YNORM(absy); - } - if (y >= WORLD_Y/2) - y -= WORLD_Y; - else if (y < -WORLD_Y/2) - y += WORLD_Y; - return y; + coord y; + + if ((np->nat_stat & STAT_ABS) == 0) { + y = YNORM(absy - np->nat_yorg); + } else { + y = YNORM(absy); + } + if (y >= WORLD_Y / 2) + y -= WORLD_Y; + else if (y < -WORLD_Y / 2) + y += WORLD_Y; + return y; } void xyrelrange(struct natstr *np, struct range *src, struct range *dst) { - dst->lx = xrel(np, src->lx); - dst->hx = xrel(np, src->hx); - dst->ly = yrel(np, src->ly); - dst->hy = yrel(np, src->hy); - dst->width = src->width; - dst->height = src->height; + dst->lx = xrel(np, src->lx); + dst->hx = xrel(np, src->hx); + dst->ly = yrel(np, src->ly); + dst->hy = yrel(np, src->hy); + dst->width = src->width; + dst->height = src->height; } void xyabsrange(struct natstr *np, struct range *src, struct range *dst) { - dst->lx = xabs(np, src->lx); - dst->hx = xabs(np, src->hx); - dst->ly = yabs(np, src->ly); - dst->hy = yabs(np, src->hy); - dst->width = src->width; - dst->height = src->height; + dst->lx = xabs(np, src->lx); + dst->hx = xabs(np, src->hx); + dst->ly = yabs(np, src->ly); + dst->hy = yabs(np, src->hy); + dst->width = src->width; + dst->height = src->height; } void inputxy(coord *xp, coord *yp, natid cn) { - struct natstr *np; + struct natstr *np; - np = getnatp(cn); - *xp = xabs(np, *xp); - *yp = yabs(np, *yp); + np = getnatp(cn); + *xp = xabs(np, *xp); + *yp = yabs(np, *yp); } coord xabs(struct natstr *np, coord relx) { - if ((np->nat_stat & STAT_ABS) == 0) - relx += np->nat_xorg; - return XNORM(relx); + if ((np->nat_stat & STAT_ABS) == 0) + relx += np->nat_xorg; + return XNORM(relx); } coord yabs(struct natstr *np, coord rely) { - if ((np->nat_stat & STAT_ABS) == 0) - rely += np->nat_yorg; - return YNORM(rely); + if ((np->nat_stat & STAT_ABS) == 0) + rely += np->nat_yorg; + return YNORM(rely); } int sctoff(coord x, coord y) { - if ((x + y) & 01) { - logerror("%d,%d is an invalid sector specification!\n", x, y); - return -1; - } - return (YNORM(y) * WORLD_X + XNORM(x))/2; + if ((x + y) & 01) { + logerror("%d,%d is an invalid sector specification!\n", x, y); + return -1; + } + return (YNORM(y) * WORLD_X + XNORM(x)) / 2; } coord xnorm(register coord x) { - if (x < 0) - x = WORLD_X - (-x % WORLD_X); - return x % WORLD_X; + if (x < 0) + x = WORLD_X - (-x % WORLD_X); + return x % WORLD_X; } coord ynorm(register coord y) { - if (y < 0) - y = WORLD_Y - (-y % WORLD_Y); - return y % WORLD_Y; + if (y < 0) + y = WORLD_Y - (-y % WORLD_Y); + return y % WORLD_Y; } int xyinrange(coord x, coord y, struct range *rp) { - if (rp->lx < rp->hx) { - /* xrange doesn't wrap */ - if (x < rp->lx || x > rp->hx) - return 0; - } else { - if (x < rp->lx && x > rp->hx) - return 0; - } - if (rp->ly < rp->hy) { - /* yrange doesn't wrap */ - if (y < rp->ly || y > rp->hy) - return 0; - } else { - if (y < rp->ly && y > rp->hy) - return 0; - } - return 1; + if (rp->lx < rp->hx) { + /* xrange doesn't wrap */ + if (x < rp->lx || x > rp->hx) + return 0; + } else { + if (x < rp->lx && x > rp->hx) + return 0; + } + if (rp->ly < rp->hy) { + /* yrange doesn't wrap */ + if (y < rp->ly || y > rp->hy) + return 0; + } else { + if (y < rp->ly && y > rp->hy) + return 0; + } + return 1; } s_char * prbuf(s_char *format, ...) { - static int nbuf = -1; - static s_char buf[20][1024]; - va_list ap; + static int nbuf = -1; + static s_char buf[20][1024]; + va_list ap; - if (++nbuf > 19) - nbuf = 0; + if (++nbuf > 19) + nbuf = 0; - va_start(ap, format); - (void) vsprintf(buf[nbuf], format, ap); - va_end(ap); + va_start(ap, format); + (void)vsprintf(buf[nbuf], format, ap); + va_end(ap); - return buf[nbuf]; + return buf[nbuf]; } - diff --git a/src/lib/empthread/lwp.c b/src/lib/empthread/lwp.c index 7e876409c..ce5832fac 100644 --- a/src/lib/empthread/lwp.c +++ b/src/lib/empthread/lwp.c @@ -38,7 +38,7 @@ #ifdef _EMPTH_LWP int -empth_init (char **ctx, int flags) +empth_init(char **ctx, int flags) { lwpInitSystem(7, ctx, flags); return 0; @@ -46,11 +46,11 @@ empth_init (char **ctx, int flags) empth_t * -empth_create (int prio, void (*entry)(), int size, int flags, char *name, - char *desc, void *ud) +empth_create(int prio, void (*entry) (), int size, int flags, char *name, + char *desc, void *ud) { /* inherit flags */ - if(!flags) + if (!flags) flags = LwpCurrent->flags; return lwpCreate(prio, entry, size, flags, name, desc, 0, 0, ud); } @@ -72,23 +72,23 @@ empth_self(void) } void -empth_exit (void) +empth_exit(void) { - time_t now; + time_t now; - /* We want to leave the main thread around forever, until it's time - for it to die for real (in a shutdown) */ + /* We want to leave the main thread around forever, until it's time + for it to die for real (in a shutdown) */ if (!strcmp(LwpCurrent->name, "Main")) { - while(1) { - time(&now); - lwpSleepUntil(now + 60); - } + while (1) { + time(&now); + lwpSleepUntil(now + 60); + } } lwpExit(); } - + void -empth_yield (void) +empth_yield(void) { /* a hack! */ lwpReschedule(); @@ -132,7 +132,7 @@ empth_sem_signal(empth_sem_t *sm) } void -empth_sem_wait (empth_sem_t *sm) +empth_sem_wait(empth_sem_t *sm) { lwpWait(sm); } @@ -144,4 +144,3 @@ empth_alarm(int sig) panic(sig); } #endif - diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index a373a25c7..d2cd02976 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -85,13 +85,13 @@ typedef struct { BOOL bKilled; /* The entry function for the thread. */ - void (*pfnEntry)(void *); + void (*pfnEntry) (void *); /* The system thread ID. */ - unsigned long ulThreadID; + unsigned long ulThreadID; /* An Event sem that the thread will wait/sleep on. */ - HANDLE hThreadEvent; + HANDLE hThreadEvent; } loc_Thread_t; @@ -104,31 +104,30 @@ typedef struct { */ typedef struct { - char szName[17]; + char szName[17]; /* An exclusion semaphore for this sem. */ - HANDLE hMutex; + HANDLE hMutex; /* An Event sem that the thread(s) will sleep on. */ - HANDLE hEvent; + HANDLE hEvent; /* The count variable */ int count; } loc_Sem_t; -static struct -{ +static struct { /* This is the thread exclusion/non-premption mutex. */ /* The running thread has this MUTEX, and all others are */ /* either blocked on it, or waiting for some OS response. */ - HANDLE hThreadMutex; + HANDLE hThreadMutex; /* This is the thread startup event sem. */ /* We use this to lockstep when we are starting up threads. */ - HANDLE hThreadStartEvent; + HANDLE hThreadStartEvent; /* The Thread Local Storage index. We store the pThread pointer */ /* for each thread at this index. */ - DWORD dwTLSIndex; + DWORD dwTLSIndex; /* The current running thread. */ loc_Thread_t *pCurThread; @@ -158,35 +157,31 @@ loc_debug(const char *pszFmt, ...) unsigned long ulRunTick; unsigned long ulMs, ulSec, ulMin, ulHr; loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); - char buf[1024]; - + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); + char buf[1024]; + if ((loc_GVAR.flags & EMPTH_PRINT) != 0) { - /* Ticks are in milliseconds */ - ulCurTick = GetTickCount(); - - ulRunTick = ulCurTick - loc_GVAR.ulTickAtStart; - ulMs = ulRunTick % 1000L; - ulSec = (ulRunTick / 1000L) % 60L; - ulMin = (ulRunTick / (60L * 1000L)) % 60L; - ulHr = (ulRunTick / (60L * 60L * 1000L)); - - va_start(vaList, pszFmt); - vsprintf(buf, pszFmt, vaList); - va_end(vaList); - - if (pThread) { - printf("%ld:%02ld:%02ld.%03ld %17s: %s\n", - ulHr, ulMin, ulSec, ulMs, - pThread->szName, - buf); - } else { - printf("%ld:%02ld:%02ld.%03ld %17s: %s\n", - ulHr, ulMin, ulSec, ulMs, - "UNKNOWN", - buf); - } + /* Ticks are in milliseconds */ + ulCurTick = GetTickCount(); + + ulRunTick = ulCurTick - loc_GVAR.ulTickAtStart; + ulMs = ulRunTick % 1000L; + ulSec = (ulRunTick / 1000L) % 60L; + ulMin = (ulRunTick / (60L * 1000L)) % 60L; + ulHr = (ulRunTick / (60L * 60L * 1000L)); + + va_start(vaList, pszFmt); + vsprintf(buf, pszFmt, vaList); + va_end(vaList); + + if (pThread) { + printf("%ld:%02ld:%02ld.%03ld %17s: %s\n", + ulHr, ulMin, ulSec, ulMs, pThread->szName, buf); + } else { + printf("%ld:%02ld:%02ld.%03ld %17s: %s\n", + ulHr, ulMin, ulSec, ulMs, "UNKNOWN", buf); + } } } @@ -199,10 +194,10 @@ static void loc_FreeThreadInfo(loc_Thread_t *pThread) { if (pThread) { - if (pThread->hThreadEvent) - CloseHandle(pThread->hThreadEvent); - memset(pThread, 0, sizeof(*pThread)); - free(pThread); + if (pThread->hThreadEvent) + CloseHandle(pThread->hThreadEvent); + memset(pThread, 0, sizeof(*pThread)); + free(pThread); } } @@ -218,27 +213,27 @@ static void loc_RunThisThread() { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); if (pThread->bKilled) { - if (!pThread->bMainThread) { - TlsSetValue(loc_GVAR.dwTLSIndex, NULL); - loc_FreeThreadInfo(pThread); - _endthread(); - } + if (!pThread->bMainThread) { + TlsSetValue(loc_GVAR.dwTLSIndex, NULL); + loc_FreeThreadInfo(pThread); + _endthread(); + } } /* Get the MUTEX semaphore, wait forever. */ WaitForSingleObject(loc_GVAR.hThreadMutex, INFINITE); if (!loc_GVAR.pCurThread) { - /* Set the globals to this thread. */ - *loc_GVAR.ppvUserData = pThread->pvUserData; + /* Set the globals to this thread. */ + *loc_GVAR.ppvUserData = pThread->pvUserData; - loc_GVAR.pCurThread = pThread; + loc_GVAR.pCurThread = pThread; } else { - /* Hmm, a problem, eh? */ - logerror("RunThisThread, someone already running."); + /* Hmm, a problem, eh? */ + logerror("RunThisThread, someone already running."); } } @@ -251,19 +246,19 @@ static void loc_BlockThisThread() { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); if (loc_GVAR.pCurThread == pThread) { - /* Reset the globals back to original */ + /* Reset the globals back to original */ - loc_GVAR.pCurThread = NULL; - *loc_GVAR.ppvUserData = NULL; + loc_GVAR.pCurThread = NULL; + *loc_GVAR.ppvUserData = NULL; - /* Release the MUTEX */ - ReleaseMutex(loc_GVAR.hThreadMutex); + /* Release the MUTEX */ + ReleaseMutex(loc_GVAR.hThreadMutex); } else { - /* Hmm, this thread was not the running one. */ - logerror("BlockThisThread, not running."); + /* Hmm, this thread was not the running one. */ + logerror("BlockThisThread, not running."); } } @@ -275,7 +270,7 @@ static void loc_SleepThisThread(unsigned long ulMillisecs) { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); /* Make sure the event thread is clean. */ ResetEvent(pThread->hThreadEvent); @@ -297,7 +292,8 @@ empth_threadMain(void *pvData) loc_Thread_t *pThread = (loc_Thread_t *)pvData; /* Out of here... */ - if (!pvData) return; + if (!pvData) + return; /* Store pThread on this thread. */ TlsSetValue(loc_GVAR.dwTLSIndex, pvData); @@ -313,7 +309,7 @@ empth_threadMain(void *pvData) /* Run the thread. */ if (pThread->pfnEntry) - pThread->pfnEntry(pThread->pvUserData); + pThread->pfnEntry(pThread->pvUserData); /* Kill the thread. */ empth_exit(); @@ -328,7 +324,7 @@ empth_threadMain(void *pvData) * main line. */ int -empth_init (char **ctx_ptr, int flags) +empth_init(char **ctx_ptr, int flags) { loc_Thread_t *pThread = NULL; @@ -341,28 +337,29 @@ empth_init (char **ctx_ptr, int flags) /* Initally unowned. */ loc_GVAR.hThreadMutex = CreateMutex(NULL, FALSE, NULL); if (!loc_GVAR.hThreadMutex) { - logerror("Failed to create mutex"); - return 0; + logerror("Failed to create mutex"); + return 0; } /* Create the thread start event sem. */ /* Automatic state reset. */ loc_GVAR.hThreadStartEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (!loc_GVAR.hThreadStartEvent) { - logerror("Failed to create mutex"); - return 0; + logerror("Failed to create mutex"); + return 0; } /* Create the global Thread context. */ - pThread = (loc_Thread_t *) malloc(sizeof(*pThread)); + pThread = (loc_Thread_t *)malloc(sizeof(*pThread)); if (!pThread) { - logerror("not enough memory to create main thread."); - return 0; + logerror("not enough memory to create main thread."); + return 0; } memset(pThread, 0, sizeof(*pThread)); - strncpy(pThread->szName, "Main", sizeof(pThread->szName)-1); - strncpy(pThread->szDesc, "The main process", sizeof(pThread->szDesc)-1); + strncpy(pThread->szName, "Main", sizeof(pThread->szName) - 1); + strncpy(pThread->szDesc, "The main process", + sizeof(pThread->szDesc) - 1); pThread->ulThreadID = GetCurrentThreadId(); pThread->bMainThread = TRUE; @@ -393,22 +390,23 @@ empth_init (char **ctx_ptr, int flags) * It is also passed to the entry function... */ empth_t * -empth_create (int prio, void (*entry)(), int size, int flags, - char *name, char *desc, void *ud) +empth_create(int prio, void (*entry) (), int size, int flags, + char *name, char *desc, void *ud) { loc_Thread_t *pThread = NULL; loc_debug("creating new thread %s:%s", name, desc); - pThread = (loc_Thread_t *) malloc(sizeof(*pThread)); + pThread = (loc_Thread_t *)malloc(sizeof(*pThread)); if (!pThread) { - logerror("not enough memory to create thread: %s (%s)", name, desc); - return NULL; + logerror("not enough memory to create thread: %s (%s)", name, + desc); + return NULL; } memset(pThread, 0, sizeof(*pThread)); - strncpy(pThread->szName, name, sizeof(pThread->szName)-1); - strncpy(pThread->szDesc, desc, sizeof(pThread->szDesc)-1); + strncpy(pThread->szName, name, sizeof(pThread->szName) - 1); + strncpy(pThread->szDesc, desc, sizeof(pThread->szDesc) - 1); pThread->pvUserData = ud; pThread->pfnEntry = entry; pThread->bMainThread = FALSE; @@ -417,22 +415,22 @@ empth_create (int prio, void (*entry)(), int size, int flags, pThread->hThreadEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (size < loc_MIN_THREAD_STACK) - size = loc_MIN_THREAD_STACK; + size = loc_MIN_THREAD_STACK; pThread->ulThreadID = _beginthread(empth_threadMain, size, - (void *)pThread); + (void *)pThread); if (pThread->ulThreadID == -1) { - logerror("can not create thread: %s (%s): %s", name, desc, - strerror(errno)); - goto bad; + logerror("can not create thread: %s (%s): %s", name, desc, + strerror(errno)); + goto bad; } loc_debug("new thread id is %ld", pThread->ulThreadID); return pThread; -bad: + bad: if (pThread) { - loc_FreeThreadInfo(pThread); + loc_FreeThreadInfo(pThread); } return NULL; } @@ -445,7 +443,7 @@ empth_t * empth_self(void) { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); return pThread; } @@ -454,45 +452,45 @@ empth_self(void) * empth_exit */ void -empth_exit (void) +empth_exit(void) { - s_char *getlogfile(); + s_char *getlogfile(); loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); - + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); + loc_BlockThisThread(); loc_debug("empth_exit"); if (pThread->bMainThread) { - char buf[20]; - /* The main line. Wait forever. */ - if (getlogfile() == (s_char *)0) - loginit(); - printf("log file: %s\n", getlogfile()); - while (1) { - printf("\nEmpire Server>"); - fgets(buf, sizeof(buf), stdin); - if (!strnicmp(buf, "quit", 4)) - break; - } - TlsSetValue(loc_GVAR.dwTLSIndex, NULL); - loc_FreeThreadInfo(pThread); + char buf[20]; + /* The main line. Wait forever. */ + if (getlogfile() == (s_char *)0) + loginit(); + printf("log file: %s\n", getlogfile()); + while (1) { + printf("\nEmpire Server>"); + fgets(buf, sizeof(buf), stdin); + if (!strnicmp(buf, "quit", 4)) + break; + } + TlsSetValue(loc_GVAR.dwTLSIndex, NULL); + loc_FreeThreadInfo(pThread); } else { - TlsSetValue(loc_GVAR.dwTLSIndex, NULL); - loc_FreeThreadInfo(pThread); - _endthread(); + TlsSetValue(loc_GVAR.dwTLSIndex, NULL); + loc_FreeThreadInfo(pThread); + _endthread(); } } - + /************************ * empth_yield * * Yield processing to another thread. */ void -empth_yield (void) +empth_yield(void) { loc_BlockThisThread(); loc_RunThisThread(); @@ -506,7 +504,7 @@ empth_yield (void) void empth_terminate(empth_t *a) { - loc_Thread_t *pThread = (loc_Thread_t *) a; + loc_Thread_t *pThread = (loc_Thread_t *)a; loc_debug("killing thread %s", pThread->szName); pThread->bKilled = TRUE; @@ -527,7 +525,7 @@ void empth_select(int fd, int flags) { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); fd_set readmask; fd_set writemask; struct lwpProc *proc; @@ -535,54 +533,54 @@ empth_select(int fd, int flags) int n; loc_debug("%s select on %d", - flags == EMPTH_FD_READ ? "read" : "write", fd ); + flags == EMPTH_FD_READ ? "read" : "write", fd); loc_BlockThisThread(); while (1) { - tv.tv_sec = 1000000; - tv.tv_usec = 0; - - FD_ZERO(&readmask); - FD_ZERO(&writemask); - - switch(flags) { - case EMPTH_FD_READ: - FD_SET(fd, &readmask); - break; - case EMPTH_FD_WRITE: - FD_SET(fd, &writemask); - break; - default: - logerror("bad flag %d passed to empth_select", flags); - empth_exit(); - } - - n = select(fd + 1, &readmask, &writemask, (fd_set *)0, &tv); - - if (n < 0) { - if (errno == EINTR) { - /* go handle the signal */ - loc_debug("select broken by signal"); - goto done; - return; - } - /* strange but we dont get EINTR on select broken by signal */ - loc_debug("select failed (%s)", strerror(errno)); - goto done; - return; - } - - if (flags == EMPTH_FD_READ && FD_ISSET(fd, &readmask)) { - loc_debug("input ready"); - break; - } - if (flags == EMPTH_FD_WRITE && FD_ISSET(fd, &writemask)) { - loc_debug("output ready"); - break; - } + tv.tv_sec = 1000000; + tv.tv_usec = 0; + + FD_ZERO(&readmask); + FD_ZERO(&writemask); + + switch (flags) { + case EMPTH_FD_READ: + FD_SET(fd, &readmask); + break; + case EMPTH_FD_WRITE: + FD_SET(fd, &writemask); + break; + default: + logerror("bad flag %d passed to empth_select", flags); + empth_exit(); + } + + n = select(fd + 1, &readmask, &writemask, (fd_set *) 0, &tv); + + if (n < 0) { + if (errno == EINTR) { + /* go handle the signal */ + loc_debug("select broken by signal"); + goto done; + return; + } + /* strange but we dont get EINTR on select broken by signal */ + loc_debug("select failed (%s)", strerror(errno)); + goto done; + return; + } + + if (flags == EMPTH_FD_READ && FD_ISSET(fd, &readmask)) { + loc_debug("input ready"); + break; + } + if (flags == EMPTH_FD_WRITE && FD_ISSET(fd, &writemask)) { + loc_debug("output ready"); + break; + } } -done: + done: loc_RunThisThread(); } @@ -593,7 +591,7 @@ emp_sig_t empth_alarm(int sig) { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); loc_debug("got alarm signal %d", sig); @@ -626,7 +624,7 @@ void empth_sleep(long until) { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); unsigned long ulSec; ulSec = until - time(0); @@ -653,14 +651,14 @@ empth_sem_create(char *name, int cnt) { loc_Sem_t *pSem; - pSem = (loc_Sem_t *) malloc(sizeof(*pSem)); + pSem = (loc_Sem_t *)malloc(sizeof(*pSem)); if (!pSem) { - logerror("out of memory at %s:%d", __FILE__, __LINE__); - return NULL; + logerror("out of memory at %s:%d", __FILE__, __LINE__); + return NULL; } memset(pSem, 0, sizeof(pSem)); - strncpy(pSem->szName, name, sizeof(pSem->szName)-1); + strncpy(pSem->szName, name, sizeof(pSem->szName) - 1); pSem->hMutex = CreateMutex(NULL, FALSE, NULL); pSem->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -677,7 +675,7 @@ empth_sem_create(char *name, int cnt) void empth_sem_signal(empth_sem_t *sm) { - loc_Sem_t *pSem = (loc_Sem_t *) sm; + loc_Sem_t *pSem = (loc_Sem_t *)sm; loc_debug("signal on semaphore %s:%d", pSem->szName, pSem->count); @@ -685,7 +683,7 @@ empth_sem_signal(empth_sem_t *sm) WaitForSingleObject(pSem->hMutex, INFINITE); if (pSem->count++ < 0) { - SetEvent(pSem->hEvent); + SetEvent(pSem->hEvent); } ReleaseMutex(pSem->hMutex); @@ -698,11 +696,11 @@ empth_sem_signal(empth_sem_t *sm) * to be signaled. */ void -empth_sem_wait (empth_sem_t *sm) +empth_sem_wait(empth_sem_t *sm) { loc_Thread_t *pThread = - (loc_Thread_t *) TlsGetValue(loc_GVAR.dwTLSIndex); - loc_Sem_t *pSem = (loc_Sem_t *) sm; + (loc_Thread_t *)TlsGetValue(loc_GVAR.dwTLSIndex); + loc_Sem_t *pSem = (loc_Sem_t *)sm; loc_debug("wait on semaphore %s:%d", pSem->szName, pSem->count); @@ -712,17 +710,16 @@ empth_sem_wait (empth_sem_t *sm) /* Wait for the Semaphore */ WaitForSingleObject(pSem->hMutex, INFINITE); if (--pSem->count < 0) { - loc_debug("blocking"); - ReleaseMutex(pSem->hMutex); + loc_debug("blocking"); + ReleaseMutex(pSem->hMutex); - WaitForSingleObject(pSem->hEvent, INFINITE); + WaitForSingleObject(pSem->hEvent, INFINITE); - loc_debug("waking up"); - } - else - ReleaseMutex(pSem->hMutex); + loc_debug("waking up"); + } else + ReleaseMutex(pSem->hMutex); loc_RunThisThread(); } -#endif /* _WIN32 */ +#endif /* _WIN32 */ diff --git a/src/lib/empthread/pthread.c b/src/lib/empthread/pthread.c index cc6d41bc5..057102b79 100644 --- a/src/lib/empthread/pthread.c +++ b/src/lib/empthread/pthread.c @@ -47,13 +47,13 @@ #include "prototypes.h" #include - + #ifdef _EMPTH_POSIX static pthread_key_t ctx_key; static int empth_flags; -static char **udata; /* pointer to out global context */ +static char **udata; /* pointer to out global context */ -static pthread_mutex_t mtx_ctxsw; /* thread in critical section */ +static pthread_mutex_t mtx_ctxsw; /* thread in critical section */ #if 0 @@ -68,25 +68,25 @@ empth_start(void *ctx) extern emp_sig_t panic(); extern emp_sig_t shutdwn(); - - /* actually it should inherit all this from main but... */ + + /* actually it should inherit all this from main but... */ #ifdef SA_SIGINFO act.sa_flags = SA_SIGINFO; #endif - sigemptyset (&act.sa_mask); + sigemptyset(&act.sa_mask); act.sa_handler = shutdwn; - /* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on - a Linux box running POSIX threads -- STM */ + /* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on + a Linux box running POSIX threads -- STM */ #if !(defined(__linux__) && defined(_EMPTH_POSIX)) - sigaction (SIGUSR1, &act, NULL); + sigaction(SIGUSR1, &act, NULL); #endif - sigaction (SIGTERM, &act, NULL); - sigaction (SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); act.sa_handler = panic; - sigaction (SIGBUS, &act, NULL); - sigaction (SIGSEGV, &act, NULL); - sigaction (SIGILL, &act, NULL); - sigaction (SIGFPE, &act, NULL); + sigaction(SIGBUS, &act, NULL); + sigaction(SIGSEGV, &act, NULL); + sigaction(SIGILL, &act, NULL); + sigaction(SIGFPE, &act, NULL); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); @@ -100,62 +100,61 @@ empth_start(void *ctx) ((empth_t *)ctx)->ep(((empth_t *)ctx)->ud); empth_exit(); return NULL; -} - +} + static void empth_status(char *format, ...) { - va_list ap; - static struct timeval startTime; - struct timeval tv; - char buf[1024]; - int sec, msec; - empth_t *a; - - va_start(ap, format); - if (empth_flags & EMPTH_PRINT) { - if (startTime.tv_sec == 0) - gettimeofday(&startTime, 0); - gettimeofday(&tv, 0); - sec = tv.tv_sec - startTime.tv_sec; - msec = (tv.tv_usec - startTime.tv_usec) / 1000; - if (msec < 0) { - sec++; - msec += 1000; - } - vsprintf(buf, format, ap); - a = empth_self(); - printf("%d:%02d.%03d %17s: %s\n", sec/60, sec%60, msec/10, - a->name, - buf); - + va_list ap; + static struct timeval startTime; + struct timeval tv; + char buf[1024]; + int sec, msec; + empth_t *a; + + va_start(ap, format); + if (empth_flags & EMPTH_PRINT) { + if (startTime.tv_sec == 0) + gettimeofday(&startTime, 0); + gettimeofday(&tv, 0); + sec = tv.tv_sec - startTime.tv_sec; + msec = (tv.tv_usec - startTime.tv_usec) / 1000; + if (msec < 0) { + sec++; + msec += 1000; } - va_end(ap); + vsprintf(buf, format, ap); + a = empth_self(); + printf("%d:%02d.%03d %17s: %s\n", sec / 60, sec % 60, msec / 10, + a->name, buf); + + } + va_end(ap); } int -empth_init (char **ctx_ptr, int flags) +empth_init(char **ctx_ptr, int flags) { empth_t *ctx; struct sigaction act; - - pthread_key_create(&ctx_key, 0); + + pthread_key_create(&ctx_key, 0); #ifdef _DECTHREADS_ pthread_mutex_init(&mtx_ctxsw, pthread_mutexattr_default); #else pthread_mutex_init(&mtx_ctxsw, 0); #endif - + act.sa_flags = 0; - sigemptyset (&act.sa_mask); + sigemptyset(&act.sa_mask); act.sa_handler = empth_alarm; sigaction(SIGALRM, &act, NULL); - + udata = ctx_ptr; ctx = (empth_t *)malloc(sizeof(empth_t)); - if(!ctx) { + if (!ctx) { logerror("pthread init failed: not enough memory"); exit(1); } @@ -164,15 +163,15 @@ empth_init (char **ctx_ptr, int flags) ctx->ep = 0; ctx->ud = 0; ctx->id = pthread_self(); - ctx->state = 0; + ctx->state = 0; pthread_setspecific(ctx_key, ctx); - pthread_mutex_lock(&mtx_ctxsw); + pthread_mutex_lock(&mtx_ctxsw); empth_flags = flags; logerror("pthreads initialized"); return 0; } - + /* * prio can be used for setting scheeduling policy but... * it seems to be optional in POSIX threads and Solaris @@ -180,25 +179,26 @@ empth_init (char **ctx_ptr, int flags) * More then that priority is not needed even in lwp threads. */ empth_t * -empth_create (int prio, void (*entry)(), int size, int flags, - char *name, char *desc, void *ud) +empth_create(int prio, void (*entry) (), int size, int flags, + char *name, char *desc, void *ud) { pthread_t t; pthread_attr_t attr; empth_t *ctx; int eno; - + empth_status("creating new thread %s:%s", name, desc); - + ctx = (empth_t *)malloc(sizeof(empth_t)); - if(!ctx) { - logerror("not enough memoty to create thread: %s (%s)", name, desc); + if (!ctx) { + logerror("not enough memoty to create thread: %s (%s)", name, + desc); return NULL; } ctx->name = strdup(name); ctx->desc = strdup(desc); ctx->ud = ud; - ctx->state = 0; + ctx->state = 0; ctx->ep = entry; #ifdef _DECTHREADS_ @@ -206,27 +206,26 @@ empth_create (int prio, void (*entry)(), int size, int flags, #else eno = pthread_attr_init(&attr); #endif - if(eno) { + if (eno) { logerror("can not create thread attribute %s (%s): %s", name, desc, strerror(eno)); goto bad; } - #if defined(__linux__) - /* Linux doesn't let you adjust the stack */ + /* Linux doesn't let you adjust the stack */ #elif defined(_DECTHREADS_) /* DEC does not have PTHREAD_STACK_MIN constant */ /* Do not go below default size */ - if(size > pthread_attr_getstacksize(attr)) - pthread_attr_setstacksize(&attr, size); + if (size > pthread_attr_getstacksize(attr)) + pthread_attr_setstacksize(&attr, size); #else - if(size < PTHREAD_STACK_MIN) - size = PTHREAD_STACK_MIN + 1; + if (size < PTHREAD_STACK_MIN) + size = PTHREAD_STACK_MIN + 1; pthread_attr_setstacksize(&attr, size); #endif - - pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); + + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); #ifdef _DECTHREADS_ eno = pthread_create(&t, attr, empth_start, (void *)ctx) ? errno : 0; @@ -234,14 +233,14 @@ empth_create (int prio, void (*entry)(), int size, int flags, eno = pthread_create(&t, &attr, empth_start, (void *)ctx); #endif if (eno) { - logerror("can not create thread: %s (%s): %s", name, desc, - strerror(eno)); - goto bad; + logerror("can not create thread: %s (%s): %s", name, desc, + strerror(eno)); + goto bad; } empth_status("new thread id is %d", t); return ctx; pthread_attr_destroy(&attr); -bad: + bad: pthread_attr_destroy(&attr); free(ctx); return NULL; @@ -255,7 +254,7 @@ empth_setctx(void *ct) empth_t *ctx_ptr; #ifdef _DECTHREADS_ - pthread_getspecific(ctx_key, (pthread_addr_t *)&ctx_ptr); + pthread_getspecific(ctx_key, (pthread_addr_t *) & ctx_ptr); #else ctx_ptr = (empth_t *)pthread_getspecific(ctx_key); #endif @@ -266,13 +265,13 @@ empth_setctx(void *ct) } #endif -static void +static void empth_restorectx(void) { empth_t *ctx_ptr; - + #ifdef _DECTHREADS_ - pthread_getspecific(ctx_key, (pthread_addr_t *)&ctx_ptr); + pthread_getspecific(ctx_key, (pthread_addr_t *) & ctx_ptr); #else ctx_ptr = (empth_t *)pthread_getspecific(ctx_key); #endif @@ -288,47 +287,47 @@ empth_t * empth_self(void) { #ifdef _DECTHREADS_ - empth_t *ctx_ptr; - - pthread_getspecific(ctx_key, (pthread_addr_t *)&ctx_ptr); - return ctx_ptr; + empth_t *ctx_ptr; + + pthread_getspecific(ctx_key, (pthread_addr_t *) & ctx_ptr); + return ctx_ptr; #else - return (empth_t *)pthread_getspecific(ctx_key); + return (empth_t *)pthread_getspecific(ctx_key); #endif } void -empth_exit (void) +empth_exit(void) { empth_t *ctx_ptr; pthread_mutex_unlock(&mtx_ctxsw); empth_status("empth_exit"); #ifdef _DECTHREADS_ - pthread_getspecific(ctx_key, (pthread_addr_t *)&ctx_ptr); + pthread_getspecific(ctx_key, (pthread_addr_t *) & ctx_ptr); #else ctx_ptr = (empth_t *)pthread_getspecific(ctx_key); #endif - /* We want to leave the main thread around forever, until it's time - for it to die for real (in a shutdown) */ + /* We want to leave the main thread around forever, until it's time + for it to die for real (in a shutdown) */ if (!strcmp(ctx_ptr->name, "Main")) { - while(1) { + while (1) { #ifdef _DECTHREADS_ - pthread_yield(); + pthread_yield(); #endif - sleep(60); - } + sleep(60); + } } free(ctx_ptr); pthread_exit(0); } - + void -empth_yield (void) +empth_yield(void) { pthread_mutex_unlock(&mtx_ctxsw); - sleep(10); /* take a nap pthread_yield(); */ + sleep(10); /* take a nap pthread_yield(); */ pthread_mutex_lock(&mtx_ctxsw); empth_restorectx(); } @@ -337,16 +336,16 @@ void empth_terminate(empth_t *a) { /* logerror("calling non supported function empth_terminate: %s:%d", - __FILE__, __LINE__); */ + __FILE__, __LINE__); */ empth_status("killing thread %s", a->name); a->state = EMPTH_KILLED; #ifndef _DECTHREADS_ /* DEC and OSX do not have pthread_kill. Not sure that cancel is correct. */ - #if (!defined __ppc__) - pthread_kill(a->id, SIGALRM); - #endif +#if (!defined __ppc__) + pthread_kill(a->id, SIGALRM); +#endif #endif - return; + return; } void @@ -357,18 +356,18 @@ empth_select(int fd, int flags) fd_set writemask; struct timeval tv; int n; - + pthread_mutex_unlock(&mtx_ctxsw); empth_status("%s select on %d", - flags == EMPTH_FD_READ ? "read" : "write", fd ); + flags == EMPTH_FD_READ ? "read" : "write", fd); while (1) { tv.tv_sec = 1000000; tv.tv_usec = 0; FD_ZERO(&readmask); FD_ZERO(&writemask); - - switch(flags) { + + switch (flags) { case EMPTH_FD_READ: FD_SET(fd, &readmask); break; @@ -380,8 +379,8 @@ empth_select(int fd, int flags) empth_exit(); } - n = select(fd + 1, &readmask, &writemask, (fd_set *)0, &tv); - + n = select(fd + 1, &readmask, &writemask, (fd_set *) 0, &tv); + if (n < 0) { if (errno == EINTR) { /* go handle the signal */ @@ -391,10 +390,10 @@ empth_select(int fd, int flags) } /* strange but we dont get EINTR on select broken by signal */ empth_status("select failed (%s)", strerror(errno)); - goto done; + goto done; return; } - + if (flags == EMPTH_FD_READ && FD_ISSET(fd, &readmask)) { empth_status("input ready"); break; @@ -404,11 +403,11 @@ empth_select(int fd, int flags) break; } } - -done: + + done: pthread_mutex_lock(&mtx_ctxsw); empth_restorectx(); - + } @@ -420,7 +419,7 @@ empth_alarm(int sig) #ifdef SA_RESTART act.sa_flags &= ~SA_RESTART; #endif - sigemptyset (&act.sa_mask); + sigemptyset(&act.sa_mask); act.sa_handler = empth_alarm; sigaction(SIGALRM, &act, NULL); } @@ -430,9 +429,9 @@ empth_wakeup(empth_t *a) { empth_status("waking up thread %s", a->name); #ifndef _DECTHREADS_ - #if (!defined __ppc__) - pthread_kill(a->id, SIGALRM); - #endif +#if (!defined __ppc__) + pthread_kill(a->id, SIGALRM); +#endif #endif empth_status("waiting for it to run"); /* empth_yield(); */ @@ -448,7 +447,7 @@ empth_sleep(long until) tv.tv_sec = until - time(NULL); tv.tv_usec = 0; do { - select (0, NULL, NULL, NULL, &tv); + select(0, NULL, NULL, NULL, &tv); } while ((tv.tv_sec = until - time(NULL)) > 0); empth_status("sleep done. Waiting for lock"); pthread_mutex_lock(&mtx_ctxsw); @@ -462,11 +461,11 @@ empth_sem_create(char *name, int cnt) empth_sem_t *sm; sm = (empth_sem_t *)malloc(sizeof(empth_sem_t)); - if(!sm) { + if (!sm) { logerror("out of memory at %s:%d", __FILE__, __LINE__); return NULL; } - strncpy(sm->name, name, sizeof(sm->name)-1); + strncpy(sm->name, name, sizeof(sm->name) - 1); sm->count = cnt; #ifdef _DECTHREADS_ pthread_mutex_init(&sm->mtx_update, pthread_mutexattr_default); @@ -485,22 +484,21 @@ empth_sem_signal(empth_sem_t *sm) { empth_status("signal on semaphore %s:%d", sm->name, sm->count); pthread_mutex_lock(&sm->mtx_update); - if(sm->count++ < 0) { + if (sm->count++ < 0) { pthread_mutex_unlock(&sm->mtx_update); pthread_mutex_lock(&sm->mtx_sem); pthread_cond_signal(&sm->cnd_sem); pthread_mutex_unlock(&sm->mtx_sem); - } - else + } else pthread_mutex_unlock(&sm->mtx_update); } void -empth_sem_wait (empth_sem_t *sm) +empth_sem_wait(empth_sem_t *sm) { empth_status("wait on semaphore %s:%d", sm->name, sm->count); pthread_mutex_lock(&sm->mtx_update); - if(--sm->count < 0) { + if (--sm->count < 0) { pthread_mutex_unlock(&sm->mtx_update); empth_status("blocking"); pthread_mutex_unlock(&mtx_ctxsw); @@ -510,8 +508,7 @@ empth_sem_wait (empth_sem_t *sm) pthread_mutex_unlock(&sm->mtx_sem); pthread_mutex_lock(&mtx_ctxsw); empth_restorectx(); - } - else + } else pthread_mutex_unlock(&sm->mtx_update); } diff --git a/src/lib/gen/atoip.c b/src/lib/gen/atoip.c index 5e13dd826..d575378a7 100644 --- a/src/lib/gen/atoip.c +++ b/src/lib/gen/atoip.c @@ -36,24 +36,25 @@ int atoip(s_char **ptrptr) { - register int num; - register s_char *cp; - register int neg; + register int num; + register s_char *cp; + register int neg; - if (ptrptr == 0 || *ptrptr == 0) return 0; - cp = *ptrptr; - num = 0; - neg = 0; -loop: - while (*cp == ' ' || *cp == '\t') - cp++; - if (*cp == '-') { - neg++; - cp++; - goto loop; - } - while (*cp >= '0' && *cp <= '9') - num = num * 10 + *cp++ - '0'; - *ptrptr = cp; - return(neg ? -num : num); + if (ptrptr == 0 || *ptrptr == 0) + return 0; + cp = *ptrptr; + num = 0; + neg = 0; + loop: + while (*cp == ' ' || *cp == '\t') + cp++; + if (*cp == '-') { + neg++; + cp++; + goto loop; + } + while (*cp >= '0' && *cp <= '9') + num = num * 10 + *cp++ - '0'; + *ptrptr = cp; + return (neg ? -num : num); } diff --git a/src/lib/gen/atopi.c b/src/lib/gen/atopi.c index 5807b6097..d3d8be465 100644 --- a/src/lib/gen/atopi.c +++ b/src/lib/gen/atopi.c @@ -42,14 +42,14 @@ int atopi(s_char *p) { - register int r11; + register int r11; - if (p) { - r11 = atoi(p); - if (r11 < 0) - r11 = -r11; - return r11; - } else { - return (0); - } + if (p) { + r11 = atoi(p); + if (r11 < 0) + r11 = -r11; + return r11; + } else { + return (0); + } } diff --git a/src/lib/gen/bit.c b/src/lib/gen/bit.c index 47ea9e370..314069477 100644 --- a/src/lib/gen/bit.c +++ b/src/lib/gen/bit.c @@ -33,23 +33,23 @@ #include "misc.h" #include "bit.h" -#include "gen.h" /* getfdtablesize etc. */ +#include "gen.h" /* getfdtablesize etc. */ -static int bit_nbytes; +static int bit_nbytes; bit_fdmask bit_newfdmask(void) { - bit_fdmask mask; - int nfile; - - if (bit_nbytes == 0) { - nfile = getfdtablesize(); - bit_nbytes = (nfile + (BIT_BITSPERMASK-1)) / BIT_NBBY; - } - mask = (bit_fdmask) malloc(bit_nbytes); - (void) bit_zero(mask); - return mask; + bit_fdmask mask; + int nfile; + + if (bit_nbytes == 0) { + nfile = getfdtablesize(); + bit_nbytes = (nfile + (BIT_BITSPERMASK - 1)) / BIT_NBBY; + } + mask = (bit_fdmask)malloc(bit_nbytes); + (void)bit_zero(mask); + return mask; } /* @@ -58,14 +58,14 @@ bit_newfdmask(void) void bit_zero(bit_fdmask bitp) { - bit_mask *mask; - register int i; - register int nwords; - - mask = bitp; - nwords = bit_nbytes / sizeof(*mask); - for (i=0; i roll/32768.0) - return 1; - return 0; + if (d > roll / 32768.0) + return 1; + return 0; } int roll(int n) { - return (random() % n) + 1; + return (random() % n) + 1; } /* @@ -76,12 +76,12 @@ roll(int n) int roundavg(double val) { - int flr; + int flr; - flr = (int) val; - if (val < 0) - flr -= chance(flr - val); - else - flr += chance(val - flr); - return flr; + flr = (int)val; + if (val < 0) + flr -= chance(flr - val); + else + flr += chance(val - flr); + return flr; } diff --git a/src/lib/gen/copy.c b/src/lib/gen/copy.c index ebed92966..e49450ecb 100644 --- a/src/lib/gen/copy.c +++ b/src/lib/gen/copy.c @@ -40,9 +40,8 @@ s_char * copy(register s_char *s1, register s_char *s2) { - while ((*s2++ = *s1++) != 0) - ; - return s2 - 1; + while ((*s2++ = *s1++) != 0) ; + return s2 - 1; } #ifdef hpux @@ -51,13 +50,13 @@ copy(register s_char *s1, register s_char *s2) void bzero(s_char *ptr, int len) { - memset(ptr, 0, len); + memset(ptr, 0, len); } void bcopy(s_char *src, s_char *dst, int len) { - memcpy(dst, src, len); + memcpy(dst, src, len); } #endif @@ -68,16 +67,16 @@ bcopy(s_char *src, s_char *dst, int len) void blankfill(s_char *ptr, register struct range *range, int size) { - register s_char *p; - register int row; - register int col; + register s_char *p; + register int row; + register int col; - for (row=0; rowheight; row++) { - col = (range->width + 1) * (size + 1) / 2 - 1; - p = ptr; - while (--col >= 0) - *p++ = ' '; - *p++ = 0; - ptr += MAPWIDTH(size); - } + for (row = 0; row < range->height; row++) { + col = (range->width + 1) * (size + 1) / 2 - 1; + p = ptr; + while (--col >= 0) + *p++ = ' '; + *p++ = 0; + ptr += MAPWIDTH(size); + } } diff --git a/src/lib/gen/disassoc.c b/src/lib/gen/disassoc.c index b4559f566..bed2a9f4d 100644 --- a/src/lib/gen/disassoc.c +++ b/src/lib/gen/disassoc.c @@ -41,7 +41,7 @@ #include #if !defined(_WIN32) #include -#include /* fork close dup2 */ +#include /* fork close dup2 */ #endif #include #include "gen.h" @@ -50,23 +50,23 @@ void disassoc(void) { #if !defined(_WIN32) - int i; + int i; - if (fork() != 0) - exit(0); - for (i = 0; i < 10; i++) - (void) close(i); - (void) open("/", O_RDONLY, 0); - (void) dup2(0, 1); - (void) dup2(0, 2); + if (fork() != 0) + exit(0); + for (i = 0; i < 10; i++) + (void)close(i); + (void)open("/", O_RDONLY, 0); + (void)dup2(0, 1); + (void)dup2(0, 2); #if defined hpux || defined Rel4 - setsid(); + setsid(); #else - i = open("/dev/tty", O_RDWR, 0); - if (i > 0) { - (void) ioctl(i, TIOCNOTTY, 0); - (void) close(i); - } + i = open("/dev/tty", O_RDWR, 0); + if (i > 0) { + (void)ioctl(i, TIOCNOTTY, 0); + (void)close(i); + } #endif #endif } diff --git a/src/lib/gen/dtable.c b/src/lib/gen/dtable.c index 0f07a6657..d01a4748b 100644 --- a/src/lib/gen/dtable.c +++ b/src/lib/gen/dtable.c @@ -32,7 +32,7 @@ */ #if !defined(_WIN32) -#include /* getdtablesize */ +#include /* getdtablesize */ #endif #include "gen.h" @@ -41,14 +41,14 @@ void setfdtablesize(int min, int start) { #ifdef sequent - extern int errno; + extern int errno; - while (start >= min) { - if (setdtablesize(start) > 0) - break; - start -= 16; - } - errno = 0; + while (start >= min) { + if (setdtablesize(start) > 0) + break; + start -= 16; + } + errno = 0; #endif } @@ -56,10 +56,10 @@ int getfdtablesize(void) { #if defined(_WIN32) - return (_NFILE); + return (_NFILE); #elif defined(hpux) - return (int)sysconf(_SC_OPEN_MAX); + return (int)sysconf(_SC_OPEN_MAX); #else - return getdtablesize(); + return getdtablesize(); #endif } diff --git a/src/lib/gen/emp_config.c b/src/lib/gen/emp_config.c index 7aa228df8..20773e1cb 100644 --- a/src/lib/gen/emp_config.c +++ b/src/lib/gen/emp_config.c @@ -44,7 +44,7 @@ */ #include -#include /* atoi free atol */ +#include /* atoi free atol */ #ifdef Rel4 #include #endif /* Rel4 */ @@ -54,7 +54,7 @@ #include "match.h" #include "file.h" #include "optlist.h" -#include "gen.h" /* parse */ +#include "gen.h" /* parse */ /* for systems without strdup */ #ifdef NOSTRDUP @@ -62,10 +62,11 @@ extern char *strdup(); #endif /* NOSTRDUP */ /* All the configurable variables ... */ -extern s_char *infodir, *datadir, *gamedir, *loginport, *privname, *privlog; +extern s_char *infodir, *datadir, *gamedir, *loginport, *privname, + *privlog; extern double buil_tower_bt, buil_tower_bc; -extern double buytax, flakscale, maxmult, minmult, tradetax, uwbrate; +extern double buytax, flakscale, maxmult, minmult, tradetax, uwbrate; extern double buil_bc, buil_bt, combat_mob, edu_cons, hap_cons, money_civ; extern double money_land, money_mil, money_plane, money_res, money_ship; extern double money_uw, people_damage, powe_cost, unit_damage, babyeat; @@ -94,8 +95,8 @@ extern int TRADE_DELAY; extern int morale_base; extern float fire_range_factor; -extern long adj_update; -extern long s_p_etu; +extern long adj_update; +extern long s_p_etu; extern int update_policy; extern s_char *update_times; extern int hourslop; @@ -109,18 +110,18 @@ extern s_char *game_days; extern s_char *game_hours; /* conditional ones */ -extern double decay_per_etu, fallout_spread; +extern double decay_per_etu, fallout_spread; extern int fuel_mult; -extern int War_Cost; -extern long last_demand_update; +extern int War_Cost; +extern long last_demand_update; -extern float drnuke_const; +extern float drnuke_const; extern float start_education, start_happiness; extern float start_technology, start_research; -extern int trade_1_dist, trade_2_dist, trade_3_dist; +extern int trade_1_dist, trade_2_dist, trade_3_dist; extern float trade_1, trade_2, trade_3, trade_ally_bonus, trade_ally_cut; /* Dummy one */ @@ -128,305 +129,312 @@ static int emp_config_dummy; /* things that can be changed */ struct keymatch configkeys[] = { -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n### Server configuration and information" }, -{ "data", optstrset, (caddr_t) &datadir, 0, - "Directory the data is stored in" }, -{ "info", optstrset, (caddr_t) &infodir, 0, - "Directory the info pages are stored in" }, -{ "port", optstrset, (caddr_t) &loginport, 0, - "TCP/IP port the server will start up on" }, -{ "privname", optstrset, (caddr_t) &privname, 0, - "Name of the deity" }, -{ "privlog", optstrset, (caddr_t) &privlog, 0, - "E-mail of the deity" }, -{ "WORLD_X", worldxset, (caddr_t) &WORLD_X, 0, - "World size X dimension (enforced to be even by subtracting 1 if necessary)" }, -{ "WORLD_Y", intset, (caddr_t) &WORLD_Y, 0, - "World size Y dimension" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Update policy" }, -{ "update_policy", intset, (caddr_t) &update_policy, 0, - "0 - normal, 1 - update_times, 2 - blitz, 3 - demand only" }, -{ "etu_per_update", intset, (caddr_t) &etu_per_update, 0, - "Number of ETUs per update" }, -{ "s_p_etu", longset, (caddr_t) &s_p_etu, 0, - "Seconds per etu, updates will occur every s_p_etu * etu_per_update seconds" }, -{ "adj_update", longset, (caddr_t) &adj_update, 0, - "Move the update forward or backward (in seconds)" }, -{ "update_window", intset, (caddr_t) &update_window, 0, - "Window the update will occur in (in seconds) before and after the update time" }, -{ "update_times", optstrset, (caddr_t) &update_times, 0, - "Times when updates occur under policy #1. Must coincide with schedule." }, -{ "hourslop", intset, (caddr_t) &hourslop, 0, - "Number of minutes update check can slip to match update_times" }, -{ "blitz_time", intset, (caddr_t) &blitz_time, 0, - "Number of minutes between updates under policy #2." }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Demand update policy" }, -{ "update_demandpolicy",intset, (caddr_t) &update_demandpolicy, 0, - "0 - emp_tm checks, 1 - after setting, 2 - demand updates disabled" }, -{ "update_wantmin", intset, (caddr_t) &update_wantmin, 0, - "number of requests needed for demand update" }, -{ "update_missed", intset, (caddr_t) &update_missed, 0, - "number of demand updates country can miss before veto update" }, -{ "update_demandtimes", optstrset, (caddr_t) &update_demandtimes, 0, - "Times when demand updates can occur. Ranges CANNOT cross midnight." }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Game hours restrictions" }, -{ "game_days", optstrset, (caddr_t) &game_days, 0, - "Days game is up and running (Su Mo Tu We Th Fr Sa)" }, -{ "game_hours", optstrset, (caddr_t) &game_hours, 0, - "Hours game is up and running (6:00-18:00)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Options\n" }, -{ "option", optionset, (caddr_t) NULL, 0, NULL }, -{ "nooption", optiondel, (caddr_t) NULL, 0, NULL }, - - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Countries" }, -{ "btu_build_rate", floatset, (caddr_t) &btu_build_rate, 0, - "Rate at which BTUs accumulate (etu * civ * eff * btu_build_rate)" }, -{ "m_m_p_d", intset, (caddr_t) &m_m_p_d, 0, - "Maximum minutes per day a country is allowed to be logged in" }, -{ "max_btus", intset, (caddr_t) &max_btus, 0, - "Maximum number of BTUs a country can have" }, -{ "max_idle", intset, (caddr_t) &max_idle, 0, - "Maximum number of minutes a player can sit idle while logged in" }, -{ "players_at_00", intset, (caddr_t) &players_at_00, 0, - "Players have their coordinate system at deity 0,0 (0 - no, 1 - yes)" }, -{ "at_least_one_100", intset, (caddr_t) &at_least_one_100, 0, - "Initialize new countries with at least one sector with 100 of all resource" }, -{ "powe_cost", doubleset, (caddr_t) &powe_cost, 0, - "Number of BTUs needed to generate a new power report" }, -{ "war_cost", intset, (caddr_t) &War_Cost, 0, - "Cost to declare war (if SLOW_WAR is on)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Technology/Research/Education/Happiness" }, -{ "easy_tech", floatset, (caddr_t) &easy_tech, 0, - "Amount of tech built with no penalty" }, -{ "hard_tech", floatset, (caddr_t) &hard_tech, 0, - "Amount of in-efficiently built tech" }, -{ "start_tech", floatset, (caddr_t) &start_technology, 0, - "Starting technology for new countries" }, -{ "start_happy", floatset, (caddr_t) &start_happiness, 0, - "Starting happiness for new countries" }, -{ "start_research", floatset, (caddr_t) &start_research, 0, - "Starting research for new countries" }, -{ "start_edu", floatset, (caddr_t) &start_education, 0, - "Starting education for new countries" }, -{ "level_age_rate", floatset, (caddr_t) &level_age_rate, 0, - "ETU rate at which tech decays (0 -> no decline)" }, -{ "tech_log_base", floatset, (caddr_t) &tech_log_base, 0, - "Log base to apply to tech breakthroughs above the easy tech level" }, -{ "ally_factor", floatset, (caddr_t) &ally_factor, 0, - "Shared tech with allies (1 / ally_factor)" }, -{ "edu_avg", floatset, (caddr_t) &edu_avg, 0, - "Number of ETUs education is averaged over" }, -{ "hap_avg", floatset, (caddr_t) &hap_avg, 0, - "Number of ETUs happiness is averaged over" }, -{ "edu_cons", doubleset, (caddr_t) &edu_cons, 0, - "Education consumption (1 breakthrough per edu_cons)" }, -{ "hap_cons", doubleset, (caddr_t) &hap_cons, 0, - "Happiness consumption (1 breakthrough per hap_cons)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Sectors" }, -{ "startmob", intset, (caddr_t) &startmob, 0, - "Starting mobility for sanctuaries" }, -{ "sect_mob_scale", floatset, (caddr_t) §_mob_scale, 0, - "Sector mobility accumulation (sect_mob_scale * ETUs per update)" }, -{ "sect_mob_max", intset, (caddr_t) §_mob_max, 0, - "Maximum mobility for sectors" }, -{ "buil_bh", intset, (caddr_t) &buil_bh, 0, - "Number of hcms required to build a bridge span" }, -{ "buil_bc", doubleset, (caddr_t) &buil_bc, 0, - "Cash required to build a bridge span" }, -{ "buil_bt", doubleset, (caddr_t) &buil_bt, 0, - "Technology required to build a bridge span" }, -{ "buil_tower_bh", intset, (caddr_t) &buil_tower_bh, 0, - "Number of hcms required to build a bridge tower" }, -{ "buil_tower_bc", doubleset, (caddr_t) &buil_tower_bc, 0, - "Cash required to build a bridge tower" }, -{ "buil_tower_bt", doubleset, (caddr_t) &buil_tower_bt, 0, - "Technology required to build a bridge tower" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Land Units" }, -{ "land_mob_scale", floatset, (caddr_t) &land_mob_scale, 0, - "Land unit mobility accumulation (land_mob_scale * ETUs per update)" }, -{ "land_grow_scale", intset, (caddr_t) &land_grow_scale, 0, - "How fast efficiency grows for land units each update (* ETUs)" }, -{ "land_mob_max", intset, (caddr_t) &land_mob_max, 0, - "Maximum mobility for land units" }, -{ "money_land", doubleset, (caddr_t) &money_land, 0, - "Cost per ETU to maintain land units (percentage of unit price)" }, -{ "morale_base", intset, (caddr_t) &morale_base, 0, - "Base level for setting morale of land units" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Planes" }, -{ "plane_mob_scale", floatset, (caddr_t) &plane_mob_scale, 0, - "Plane mobility accumulation (plane_mob_scale * ETUs per update)" }, -{ "plane_grow_scale", intset, (caddr_t) &plane_grow_scale, 0, - "How fast efficiency grows for planes each update (* ETUs)" }, -{ "plane_mob_max", intset, (caddr_t) &plane_mob_max, 0, - "Maximum mobility for planes" }, -{ "money_plane", doubleset, (caddr_t) &money_plane, 0, - "Cost per ETU to maintain planes (percentage of plane price)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Ships" }, -{ "ship_mob_scale", floatset, (caddr_t) &ship_mob_scale, 0, - "Ship mobility accumulation (ship_mob_scale * ETUs per update)" }, -{ "ship_grow_scale", intset, (caddr_t) &ship_grow_scale, 0, - "How fast efficiency grows for ships each update (* ETUs)" }, -{ "ship_mob_max", intset, (caddr_t) &ship_mob_max, 0, - "Maximum mobility for ships" }, -{ "money_ship", doubleset, (caddr_t) &money_ship, 0, - "Cost per ETU to maintain ships (percentage of ship price)" }, -{ "torpedo_damage", intset, (caddr_t) &torpedo_damage, 0, - "Torpedo damage (damage is X + 1dX + 1dX)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Combat/Damage" }, -{ "fort_max_interdiction_range", intset, (caddr_t)&fort_max_interdiction_range, 0, - "Maximum range (in sectors) a fort will try to interdict another country" }, -{ "land_max_interdiction_range", intset, (caddr_t)&land_max_interdiction_range, 0, - "Maximum range (in sectors) a land unit will try to interdict another country" }, -{ "ship_max_interdiction_range", intset, (caddr_t)&ship_max_interdiction_range, 0, - "Maximum range (in sectors) a ship will try to interdict another country" }, -{ "flakscale", doubleset, (caddr_t) &flakscale, 0, - "Scale factor for flak damage" }, -{ "combat_mob", doubleset, (caddr_t) &combat_mob, 0, - "How much mobility do units spend for combat (* casualties/bodies)" }, -{ "people_damage", doubleset, (caddr_t) &people_damage, 0, - "People take this amount of normal damage" }, -{ "unit_damage", doubleset, (caddr_t) &unit_damage, 0, - "Land units take this amount of normal damage" }, -{ "collateral_dam", doubleset, (caddr_t) &collateral_dam, 0, - "Side effect damage amount done to sector" }, -{ "assault_penalty", doubleset, (caddr_t) &assault_penalty, 0, - "Amount of normal attacking efficiency for paratroopers and assaulting" }, -{ "fire_range_factor", floatset, (caddr_t) &fire_range_factor, 0, - "Scale normal firing ranges by this amount" }, -{ "sect_mob_neg_factor", intset, (caddr_t) §_mob_neg_factor, 0, - "Amount of negative mobility a sector has after takeover (ETU / x) (MOB_ACCESS)" }, -{ "mission_mob_cost", doubleset, (caddr_t) &mission_mob_cost, 0, - "Cost to put something on a mission (percentage of max mob)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Populace" }, -{ "uwbrate", doubleset, (caddr_t) &uwbrate, 0, - "Birth rate for uw's" }, -{ "money_civ", doubleset, (caddr_t) &money_civ, 0, - "Money gained from taxes on a civilian in one ETU" }, -{ "money_mil", doubleset, (caddr_t) &money_mil, 0, - "Money gained from taxes on an active soldier in one ETU" }, -{ "money_res", doubleset, (caddr_t) &money_res, 0, - "Money gained from taxes on a soldier on active reserve in one ETU" }, -{ "money_uw", doubleset, (caddr_t) &money_uw, 0, - "Money gained from taxes on an uncompensated worker in one ETU" }, -{ "babyeat", doubleset, (caddr_t) &babyeat, 0, - "Amount of food to mature 1 baby into a civilian" }, -{ "bankint", doubleset, (caddr_t) &bankint, 0, - "Bank dollar gain (per bar per etu)" }, -{ "eatrate", doubleset, (caddr_t) &eatrate, 0, - "Food eating rate for mature people" }, -{ "fcrate", doubleset, (caddr_t) &fcrate, 0, - "Food cultivation rate (* workforce in sector)" }, -{ "fgrate", doubleset, (caddr_t) &fgrate, 0, - "Food growth rate (* fertility of sector)" }, -{ "obrate", doubleset, (caddr_t) &obrate, 0, - "Civilian birth rate" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Nukes" }, -{ "decay_per_etu", doubleset, (caddr_t) &decay_per_etu, 0, - "Decay of fallout per ETU" }, -{ "fallout_spread", doubleset, (caddr_t) &fallout_spread, 0, - "Amount of fallout that leaks into surrounding sectors" }, -{ "drnuke_const", floatset, (caddr_t) &drnuke_const, 0, - "Amount of research to tech needed to build a nuke (if DR_NUKE is on)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Market/Trade" }, -{ "MARK_DELAY", intset, (caddr_t) &MARK_DELAY, 0, - "Number of seconds commodities stay on the market for bidding" }, -{ "TRADE_DELAY", intset, (caddr_t) &TRADE_DELAY, 0, - "Number of seconds ships, planes, and units stay on the market for bidding" }, -{ "maxmult", doubleset, (caddr_t) &maxmult, 0, - "Maximum trade multiple (used for mult command)" }, -{ "minmult", doubleset, (caddr_t) &minmult, 0, - "Minimum trade multiple (used for mult command)" }, -{ "buytax", doubleset, (caddr_t) &buytax, 0, - "Tax (in percentage points) charged to the buyer on market purchases" }, -{ "tradetax", doubleset, (caddr_t) &tradetax, 0, - "Amount of a trade transaction the seller makes (the rest is tax)" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Trade ships" }, -{ "trade_1_dist", intset, (caddr_t) &trade_1_dist, 0, - "Less than this distance no money for cashing in" }, -{ "trade_2_dist", intset, (caddr_t) &trade_2_dist, 0, - "Less than this distance gets trade_1 money for cashing in" }, -{ "trade_3_dist", intset, (caddr_t) &trade_3_dist, 0, - "Less than this distance gets trade_2 money for cashing in (>= gets trade_3" }, -{ "trade_1", floatset, (caddr_t) &trade_1, 0, - "Return per sector on trade_1 distance amount" }, -{ "trade_2", floatset, (caddr_t) &trade_2, 0, - "Return per sector on trade_2 distance amount" }, -{ "trade_3", floatset, (caddr_t) &trade_3, 0, - "Return per sector on trade_3 distance amount" }, -{ "trade_ally_bonus", floatset, (caddr_t) &trade_ally_bonus, 0, - "Bonus you get for cashing in with an ally" }, -{ "trade_ally_cut", floatset, (caddr_t) &trade_ally_cut, 0, - "Bonus your ally gets for you cashing in with them" }, - -{ "", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Misc." }, -{ "fuel_mult", intset, (caddr_t) &fuel_mult, 0, - "Multiplier for fuel to mobility calculation" }, -{ "lost_items_timeout", intset, (caddr_t) &lost_items_timeout, 0, - "Seconds before a lost item is timed out of the database" }, -{ "last_demand_update", longset, (caddr_t) &last_demand_update, 0, - "When was the last demand update occured" }, - -{ NULL, NULL, (caddr_t)0, 0, NULL } + {"", intset, (caddr_t)&emp_config_dummy, 0, + "\n### Server configuration and information"}, + {"data", optstrset, (caddr_t)&datadir, 0, + "Directory the data is stored in"}, + {"info", optstrset, (caddr_t)&infodir, 0, + "Directory the info pages are stored in"}, + {"port", optstrset, (caddr_t)&loginport, 0, + "TCP/IP port the server will start up on"}, + {"privname", optstrset, (caddr_t)&privname, 0, + "Name of the deity"}, + {"privlog", optstrset, (caddr_t)&privlog, 0, + "E-mail of the deity"}, + {"WORLD_X", worldxset, (caddr_t)&WORLD_X, 0, + "World size X dimension (enforced to be even by subtracting 1 if necessary)"}, + {"WORLD_Y", intset, (caddr_t)&WORLD_Y, 0, + "World size Y dimension"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Update policy"}, + {"update_policy", intset, (caddr_t)&update_policy, 0, + "0 - normal, 1 - update_times, 2 - blitz, 3 - demand only"}, + {"etu_per_update", intset, (caddr_t)&etu_per_update, 0, + "Number of ETUs per update"}, + {"s_p_etu", longset, (caddr_t)&s_p_etu, 0, + "Seconds per etu, updates will occur every s_p_etu * etu_per_update seconds"}, + {"adj_update", longset, (caddr_t)&adj_update, 0, + "Move the update forward or backward (in seconds)"}, + {"update_window", intset, (caddr_t)&update_window, 0, + "Window the update will occur in (in seconds) before and after the update time"}, + {"update_times", optstrset, (caddr_t)&update_times, 0, + "Times when updates occur under policy #1. Must coincide with schedule."}, + {"hourslop", intset, (caddr_t)&hourslop, 0, + "Number of minutes update check can slip to match update_times"}, + {"blitz_time", intset, (caddr_t)&blitz_time, 0, + "Number of minutes between updates under policy #2."}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, + "\n\n### Demand update policy"}, + {"update_demandpolicy", intset, (caddr_t)&update_demandpolicy, 0, + "0 - emp_tm checks, 1 - after setting, 2 - demand updates disabled"}, + {"update_wantmin", intset, (caddr_t)&update_wantmin, 0, + "number of requests needed for demand update"}, + {"update_missed", intset, (caddr_t)&update_missed, 0, + "number of demand updates country can miss before veto update"}, + {"update_demandtimes", optstrset, (caddr_t)&update_demandtimes, 0, + "Times when demand updates can occur. Ranges CANNOT cross midnight."}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, + "\n\n### Game hours restrictions"}, + {"game_days", optstrset, (caddr_t)&game_days, 0, + "Days game is up and running (Su Mo Tu We Th Fr Sa)"}, + {"game_hours", optstrset, (caddr_t)&game_hours, 0, + "Hours game is up and running (6:00-18:00)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Options\n"}, + {"option", optionset, (caddr_t)NULL, 0, NULL}, + {"nooption", optiondel, (caddr_t)NULL, 0, NULL}, + + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Countries"}, + {"btu_build_rate", floatset, (caddr_t)&btu_build_rate, 0, + "Rate at which BTUs accumulate (etu * civ * eff * btu_build_rate)"}, + {"m_m_p_d", intset, (caddr_t)&m_m_p_d, 0, + "Maximum minutes per day a country is allowed to be logged in"}, + {"max_btus", intset, (caddr_t)&max_btus, 0, + "Maximum number of BTUs a country can have"}, + {"max_idle", intset, (caddr_t)&max_idle, 0, + "Maximum number of minutes a player can sit idle while logged in"}, + {"players_at_00", intset, (caddr_t)&players_at_00, 0, + "Players have their coordinate system at deity 0,0 (0 - no, 1 - yes)"}, + {"at_least_one_100", intset, (caddr_t)&at_least_one_100, 0, + "Initialize new countries with at least one sector with 100 of all resource"}, + {"powe_cost", doubleset, (caddr_t)&powe_cost, 0, + "Number of BTUs needed to generate a new power report"}, + {"war_cost", intset, (caddr_t)&War_Cost, 0, + "Cost to declare war (if SLOW_WAR is on)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, + "\n\n### Technology/Research/Education/Happiness"}, + {"easy_tech", floatset, (caddr_t)&easy_tech, 0, + "Amount of tech built with no penalty"}, + {"hard_tech", floatset, (caddr_t)&hard_tech, 0, + "Amount of in-efficiently built tech"}, + {"start_tech", floatset, (caddr_t)&start_technology, 0, + "Starting technology for new countries"}, + {"start_happy", floatset, (caddr_t)&start_happiness, 0, + "Starting happiness for new countries"}, + {"start_research", floatset, (caddr_t)&start_research, 0, + "Starting research for new countries"}, + {"start_edu", floatset, (caddr_t)&start_education, 0, + "Starting education for new countries"}, + {"level_age_rate", floatset, (caddr_t)&level_age_rate, 0, + "ETU rate at which tech decays (0 -> no decline)"}, + {"tech_log_base", floatset, (caddr_t)&tech_log_base, 0, + "Log base to apply to tech breakthroughs above the easy tech level"}, + {"ally_factor", floatset, (caddr_t)&ally_factor, 0, + "Shared tech with allies (1 / ally_factor)"}, + {"edu_avg", floatset, (caddr_t)&edu_avg, 0, + "Number of ETUs education is averaged over"}, + {"hap_avg", floatset, (caddr_t)&hap_avg, 0, + "Number of ETUs happiness is averaged over"}, + {"edu_cons", doubleset, (caddr_t)&edu_cons, 0, + "Education consumption (1 breakthrough per edu_cons)"}, + {"hap_cons", doubleset, (caddr_t)&hap_cons, 0, + "Happiness consumption (1 breakthrough per hap_cons)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Sectors"}, + {"startmob", intset, (caddr_t)&startmob, 0, + "Starting mobility for sanctuaries"}, + {"sect_mob_scale", floatset, (caddr_t)§_mob_scale, 0, + "Sector mobility accumulation (sect_mob_scale * ETUs per update)"}, + {"sect_mob_max", intset, (caddr_t)§_mob_max, 0, + "Maximum mobility for sectors"}, + {"buil_bh", intset, (caddr_t)&buil_bh, 0, + "Number of hcms required to build a bridge span"}, + {"buil_bc", doubleset, (caddr_t)&buil_bc, 0, + "Cash required to build a bridge span"}, + {"buil_bt", doubleset, (caddr_t)&buil_bt, 0, + "Technology required to build a bridge span"}, + {"buil_tower_bh", intset, (caddr_t)&buil_tower_bh, 0, + "Number of hcms required to build a bridge tower"}, + {"buil_tower_bc", doubleset, (caddr_t)&buil_tower_bc, 0, + "Cash required to build a bridge tower"}, + {"buil_tower_bt", doubleset, (caddr_t)&buil_tower_bt, 0, + "Technology required to build a bridge tower"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Land Units"}, + {"land_mob_scale", floatset, (caddr_t)&land_mob_scale, 0, + "Land unit mobility accumulation (land_mob_scale * ETUs per update)"}, + {"land_grow_scale", intset, (caddr_t)&land_grow_scale, 0, + "How fast efficiency grows for land units each update (* ETUs)"}, + {"land_mob_max", intset, (caddr_t)&land_mob_max, 0, + "Maximum mobility for land units"}, + {"money_land", doubleset, (caddr_t)&money_land, 0, + "Cost per ETU to maintain land units (percentage of unit price)"}, + {"morale_base", intset, (caddr_t)&morale_base, 0, + "Base level for setting morale of land units"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Planes"}, + {"plane_mob_scale", floatset, (caddr_t)&plane_mob_scale, 0, + "Plane mobility accumulation (plane_mob_scale * ETUs per update)"}, + {"plane_grow_scale", intset, (caddr_t)&plane_grow_scale, 0, + "How fast efficiency grows for planes each update (* ETUs)"}, + {"plane_mob_max", intset, (caddr_t)&plane_mob_max, 0, + "Maximum mobility for planes"}, + {"money_plane", doubleset, (caddr_t)&money_plane, 0, + "Cost per ETU to maintain planes (percentage of plane price)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Ships"}, + {"ship_mob_scale", floatset, (caddr_t)&ship_mob_scale, 0, + "Ship mobility accumulation (ship_mob_scale * ETUs per update)"}, + {"ship_grow_scale", intset, (caddr_t)&ship_grow_scale, 0, + "How fast efficiency grows for ships each update (* ETUs)"}, + {"ship_mob_max", intset, (caddr_t)&ship_mob_max, 0, + "Maximum mobility for ships"}, + {"money_ship", doubleset, (caddr_t)&money_ship, 0, + "Cost per ETU to maintain ships (percentage of ship price)"}, + {"torpedo_damage", intset, (caddr_t)&torpedo_damage, 0, + "Torpedo damage (damage is X + 1dX + 1dX)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Combat/Damage"}, + {"fort_max_interdiction_range", intset, + (caddr_t)&fort_max_interdiction_range, 0, + "Maximum range (in sectors) a fort will try to interdict another country"}, + {"land_max_interdiction_range", intset, + (caddr_t)&land_max_interdiction_range, 0, + "Maximum range (in sectors) a land unit will try to interdict another country"}, + {"ship_max_interdiction_range", intset, + (caddr_t)&ship_max_interdiction_range, 0, + "Maximum range (in sectors) a ship will try to interdict another country"}, + {"flakscale", doubleset, (caddr_t)&flakscale, 0, + "Scale factor for flak damage"}, + {"combat_mob", doubleset, (caddr_t)&combat_mob, 0, + "How much mobility do units spend for combat (* casualties/bodies)"}, + {"people_damage", doubleset, (caddr_t)&people_damage, 0, + "People take this amount of normal damage"}, + {"unit_damage", doubleset, (caddr_t)&unit_damage, 0, + "Land units take this amount of normal damage"}, + {"collateral_dam", doubleset, (caddr_t)&collateral_dam, 0, + "Side effect damage amount done to sector"}, + {"assault_penalty", doubleset, (caddr_t)&assault_penalty, 0, + "Amount of normal attacking efficiency for paratroopers and assaulting"}, + {"fire_range_factor", floatset, (caddr_t)&fire_range_factor, 0, + "Scale normal firing ranges by this amount"}, + {"sect_mob_neg_factor", intset, (caddr_t)§_mob_neg_factor, 0, + "Amount of negative mobility a sector has after takeover (ETU / x) (MOB_ACCESS)"}, + {"mission_mob_cost", doubleset, (caddr_t)&mission_mob_cost, 0, + "Cost to put something on a mission (percentage of max mob)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Populace"}, + {"uwbrate", doubleset, (caddr_t)&uwbrate, 0, + "Birth rate for uw's"}, + {"money_civ", doubleset, (caddr_t)&money_civ, 0, + "Money gained from taxes on a civilian in one ETU"}, + {"money_mil", doubleset, (caddr_t)&money_mil, 0, + "Money gained from taxes on an active soldier in one ETU"}, + {"money_res", doubleset, (caddr_t)&money_res, 0, + "Money gained from taxes on a soldier on active reserve in one ETU"}, + {"money_uw", doubleset, (caddr_t)&money_uw, 0, + "Money gained from taxes on an uncompensated worker in one ETU"}, + {"babyeat", doubleset, (caddr_t)&babyeat, 0, + "Amount of food to mature 1 baby into a civilian"}, + {"bankint", doubleset, (caddr_t)&bankint, 0, + "Bank dollar gain (per bar per etu)"}, + {"eatrate", doubleset, (caddr_t)&eatrate, 0, + "Food eating rate for mature people"}, + {"fcrate", doubleset, (caddr_t)&fcrate, 0, + "Food cultivation rate (* workforce in sector)"}, + {"fgrate", doubleset, (caddr_t)&fgrate, 0, + "Food growth rate (* fertility of sector)"}, + {"obrate", doubleset, (caddr_t)&obrate, 0, + "Civilian birth rate"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Nukes"}, + {"decay_per_etu", doubleset, (caddr_t)&decay_per_etu, 0, + "Decay of fallout per ETU"}, + {"fallout_spread", doubleset, (caddr_t)&fallout_spread, 0, + "Amount of fallout that leaks into surrounding sectors"}, + {"drnuke_const", floatset, (caddr_t)&drnuke_const, 0, + "Amount of research to tech needed to build a nuke (if DR_NUKE is on)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Market/Trade"}, + {"MARK_DELAY", intset, (caddr_t)&MARK_DELAY, 0, + "Number of seconds commodities stay on the market for bidding"}, + {"TRADE_DELAY", intset, (caddr_t)&TRADE_DELAY, 0, + "Number of seconds ships, planes, and units stay on the market for bidding"}, + {"maxmult", doubleset, (caddr_t)&maxmult, 0, + "Maximum trade multiple (used for mult command)"}, + {"minmult", doubleset, (caddr_t)&minmult, 0, + "Minimum trade multiple (used for mult command)"}, + {"buytax", doubleset, (caddr_t)&buytax, 0, + "Tax (in percentage points) charged to the buyer on market purchases"}, + {"tradetax", doubleset, (caddr_t)&tradetax, 0, + "Amount of a trade transaction the seller makes (the rest is tax)"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Trade ships"}, + {"trade_1_dist", intset, (caddr_t)&trade_1_dist, 0, + "Less than this distance no money for cashing in"}, + {"trade_2_dist", intset, (caddr_t)&trade_2_dist, 0, + "Less than this distance gets trade_1 money for cashing in"}, + {"trade_3_dist", intset, (caddr_t)&trade_3_dist, 0, + "Less than this distance gets trade_2 money for cashing in (>= gets trade_3"}, + {"trade_1", floatset, (caddr_t)&trade_1, 0, + "Return per sector on trade_1 distance amount"}, + {"trade_2", floatset, (caddr_t)&trade_2, 0, + "Return per sector on trade_2 distance amount"}, + {"trade_3", floatset, (caddr_t)&trade_3, 0, + "Return per sector on trade_3 distance amount"}, + {"trade_ally_bonus", floatset, (caddr_t)&trade_ally_bonus, 0, + "Bonus you get for cashing in with an ally"}, + {"trade_ally_cut", floatset, (caddr_t)&trade_ally_cut, 0, + "Bonus your ally gets for you cashing in with them"}, + + {"", intset, (caddr_t)&emp_config_dummy, 0, "\n\n### Misc."}, + {"fuel_mult", intset, (caddr_t)&fuel_mult, 0, + "Multiplier for fuel to mobility calculation"}, + {"lost_items_timeout", intset, (caddr_t)&lost_items_timeout, 0, + "Seconds before a lost item is timed out of the database"}, + {"last_demand_update", longset, (caddr_t)&last_demand_update, 0, + "When was the last demand update occured"}, + + {NULL, NULL, (caddr_t)0, 0, NULL} }; static void fixup_files _PROTO((void)); -static struct keymatch *keylookup _PROTO((s_char *key, struct keymatch tbl[])); +static struct keymatch *keylookup +_PROTO((s_char *key, struct keymatch tbl[])); /* * read in empire configuration */ int -emp_config (char *file) +emp_config(char *file) { - FILE *fp; - s_char scanspace[1024]; - s_char *av[65]; - char buf[BUFSIZ]; - struct keymatch *kp; - - if (file == NULL || (fp = fopen (file, "r")) == NULL) { - fixup_files (); - return RET_OK; + FILE *fp; + s_char scanspace[1024]; + s_char *av[65]; + char buf[BUFSIZ]; + struct keymatch *kp; + + if (file == NULL || (fp = fopen(file, "r")) == NULL) { + fixup_files(); + return RET_OK; + } + while (fgets(buf, sizeof buf, fp) != NULL) { + if (buf[0] == '#' || buf[0] == '\n') + continue; + if (parse(buf, av, 0, scanspace, 0) < 0) { + fprintf(stderr, "Can't parse line %s", buf); + continue; } - while (fgets (buf, sizeof buf, fp) != NULL) { - if (buf[0] == '#' || buf[0] == '\n') - continue; - if (parse (buf, av, 0, scanspace, 0) < 0) { - fprintf (stderr, "Can't parse line %s", buf); - continue; - } - if ((kp = keylookup (av[0], configkeys)) != NULL) { - (*kp -> km_func) (kp, av + 1); - } - else { - fprintf (stderr, "Unknown config key %s\n", av[0]); - } + if ((kp = keylookup(av[0], configkeys)) != NULL) { + (*kp->km_func) (kp, av + 1); + } else { + fprintf(stderr, "Unknown config key %s\n", av[0]); } - fclose (fp); - fixup_files (); + } + fclose(fp); + fixup_files(); - return RET_OK; + return RET_OK; } struct otherfiles { - s_char **files; - char *name; + s_char **files; + char *name; }; extern s_char *upfil, *downfil, *disablefil, *banfil, *authfil; @@ -435,245 +443,241 @@ extern s_char *commfil, *annfil, *telfil, *teldir, *timestampfil; /* list of other well known files... -maybe tailor these oneday * anyway - meantime they are all relative to datadir */ static struct otherfiles ofiles[] = { -{ &upfil, "up" }, -{ &downfil, "down"}, -{ &disablefil, "disable"}, -{ &banfil, "ban" }, -{ &authfil, "auth" }, -{ &commfil, "comm" }, -{ &annfil, "ann" }, -{ ×tampfil, "timestamp" }, -{ &teldir, "tel" }, + {&upfil, "up"}, + {&downfil, "down"}, + {&disablefil, "disable"}, + {&banfil, "ban"}, + {&authfil, "auth"}, + {&commfil, "comm"}, + {&annfil, "ann"}, + {×tampfil, "timestamp"}, + {&teldir, "tel"}, #if !defined(_WIN32) -{ &telfil, "tel/tel" }, + {&telfil, "tel/tel"}, #else -{ &telfil, "tel\\tel" }, + {&telfil, "tel\\tel"}, #endif -{ NULL, NULL } + {NULL, NULL} }; /* fix up the empfile struct to reference full path names */ -static void fixup_files (void) +static void +fixup_files(void) { - struct empfile *ep; - struct otherfiles *op; - s_char buf[1024]; + struct empfile *ep; + struct otherfiles *op; + s_char buf[1024]; - for (ep = empfile; ep < &empfile[EF_MAX]; ep ++) { + for (ep = empfile; ep < &empfile[EF_MAX]; ep++) { #if !defined(_WIN32) - sprintf (buf, "%s/%s", datadir, ep->name); + sprintf(buf, "%s/%s", datadir, ep->name); #else - sprintf (buf, "%s\\%s", datadir, ep->name); + sprintf(buf, "%s\\%s", datadir, ep->name); #endif - ep->file = strdup (buf); - } + ep->file = strdup(buf); + } - for (op = ofiles; op -> files; op ++) { + for (op = ofiles; op->files; op++) { #if !defined(_WIN32) - sprintf (buf, "%s/%s", datadir, op -> name); + sprintf(buf, "%s/%s", datadir, op->name); #else - sprintf (buf, "%s\\%s", datadir, op -> name); + sprintf(buf, "%s\\%s", datadir, op->name); #endif - *op -> files = strdup (buf); - } + *op->files = strdup(buf); + } } /* find the key in the table */ -static struct keymatch *keylookup (register s_char *command, struct keymatch *tbl) +static struct keymatch * +keylookup(register s_char *command, struct keymatch *tbl) { - register struct keymatch *kp; - - if (command == 0 || *command == 0) - return 0; - for (kp = tbl; kp->km_key != 0; kp++) { - if (strcmp (kp -> km_key, command) == 0) - return kp; - } - return NULL; + register struct keymatch *kp; + + if (command == 0 || *command == 0) + return 0; + for (kp = tbl; kp->km_key != 0; kp++) { + if (strcmp(kp->km_key, command) == 0) + return kp; + } + return NULL; } /* worldx int setting function */ -void worldxset (struct keymatch *kp, s_char **av) +void +worldxset(struct keymatch *kp, s_char **av) { - int *intptr = (int *)kp -> km_data; - - if (*av == NULL || intptr == NULL) - return; - *intptr = atoi (*av); - if (!((*intptr % 2) == 0)) { - /* Must be div / 2, so subtract one */ - *intptr = *intptr - 1; - } + int *intptr = (int *)kp->km_data; + + if (*av == NULL || intptr == NULL) + return; + *intptr = atoi(*av); + if (!((*intptr % 2) == 0)) { + /* Must be div / 2, so subtract one */ + *intptr = *intptr - 1; + } } /* generic int setting function */ -void intset (struct keymatch *kp, s_char **av) +void +intset(struct keymatch *kp, s_char **av) { - int *intptr = (int *)kp -> km_data; + int *intptr = (int *)kp->km_data; - if (*av == NULL || intptr == NULL) - return; - *intptr = atoi (*av); + if (*av == NULL || intptr == NULL) + return; + *intptr = atoi(*av); } /* generic float set function */ -void floatset (struct keymatch *kp, s_char **av) +void +floatset(struct keymatch *kp, s_char **av) { - float *floatptr = (float *)kp -> km_data; + float *floatptr = (float *)kp->km_data; - if (*av == NULL || floatptr == NULL) - return; - *floatptr = atof (*av); + if (*av == NULL || floatptr == NULL) + return; + *floatptr = atof(*av); } /* generic string set function */ -void optstrset (struct keymatch *kp, s_char **av) +void +optstrset(struct keymatch *kp, s_char **av) { - s_char **confstrp = (s_char **)kp -> km_data; - - if (*av == NULL || confstrp == NULL) - return; - if (kp -> km_flags & KM_ALLOC) - free (*confstrp); - *confstrp = strdup (*av); - kp -> km_flags |= KM_ALLOC; + s_char **confstrp = (s_char **)kp->km_data; + + if (*av == NULL || confstrp == NULL) + return; + if (kp->km_flags & KM_ALLOC) + free(*confstrp); + *confstrp = strdup(*av); + kp->km_flags |= KM_ALLOC; } /* generic double set function */ -void doubleset (struct keymatch *kp, s_char **av) +void +doubleset(struct keymatch *kp, s_char **av) { - double *doublep = (double *)kp -> km_data; + double *doublep = (double *)kp->km_data; - if (*av == NULL || doublep == NULL) - return; - *doublep = atof (*av); + if (*av == NULL || doublep == NULL) + return; + *doublep = atof(*av); } /* generic long set function */ -void longset (struct keymatch *kp, s_char **av) +void +longset(struct keymatch *kp, s_char **av) { - long int *longp = (long int *)kp -> km_data; + long int *longp = (long int *)kp->km_data; - if (*av == NULL || longp == NULL) - return; - *longp = atol (*av); + if (*av == NULL || longp == NULL) + return; + *longp = atol(*av); } void -print_config (FILE *fp) +print_config(FILE * fp) { - struct empfile *ep; - struct otherfiles *op; - struct keymatch *kp; - - fprintf(fp, "# Empire Configuration File:\n"); - for (kp = configkeys; kp -> km_key; kp ++) { - /* We print a few special things here */ - if (kp->km_comment) { - if (kp->km_comment[0]) { - if (kp->km_comment[0] != '\n') - fprintf(fp, "\n# "); - fprintf(fp, "%s\n", kp->km_comment); - } - } - if (!kp->km_key[0]) - continue; - if (kp -> km_func == optstrset) { - fprintf (fp, "%s \"%s\"\n", kp -> km_key, - *(s_char **)kp -> km_data); - } - else if (kp -> km_func == intset) { - fprintf (fp, "%s %d\n", kp -> km_key, - *(int *)kp -> km_data); - } - else if (kp -> km_func == worldxset) { - fprintf (fp, "%s %d\n", kp -> km_key, - *(int *)kp -> km_data); - } - else if (kp -> km_func == floatset) { - fprintf (fp, "%s %g\n", kp -> km_key, - *(float *)kp -> km_data); - } - else if (kp -> km_func == doubleset) { - fprintf (fp, "%s %g\n", kp -> km_key, - *(double *)kp -> km_data); - } - else if (kp -> km_func == longset) { - fprintf (fp, "%s %ld\n", kp -> km_key, - *(long *)kp -> km_data); - } - else if (kp -> km_func == optionset) { - struct option_list *op; - - for (op = Options; op -> opt_key; op++) { - if (*op -> opt_valuep) - fprintf (fp, "%s %s\n", kp -> km_key, - op -> opt_key); - } - } - else if (kp -> km_func == optiondel) { - struct option_list *op; - - for (op = Options; op -> opt_key; op++) { - if (*op -> opt_valuep == 0) - fprintf (fp, "%s %s\n", kp -> km_key, - op -> opt_key); - } - } - else fprintf (fp, "# Unknown format %s\n", kp -> km_key); + struct empfile *ep; + struct otherfiles *op; + struct keymatch *kp; + + fprintf(fp, "# Empire Configuration File:\n"); + for (kp = configkeys; kp->km_key; kp++) { + /* We print a few special things here */ + if (kp->km_comment) { + if (kp->km_comment[0]) { + if (kp->km_comment[0] != '\n') + fprintf(fp, "\n# "); + fprintf(fp, "%s\n", kp->km_comment); + } } - - fprintf(fp, "\n"); - for (ep = empfile; ep < &empfile[EF_MAX]; ep ++) - fprintf (fp, "# File %s -> %s\n", ep -> name, ep -> file); - for (op = ofiles; op -> files; op ++) - fprintf (fp, "# File %s -> %s\n", op -> name, *(op -> files)); + if (!kp->km_key[0]) + continue; + if (kp->km_func == optstrset) { + fprintf(fp, "%s \"%s\"\n", kp->km_key, + *(s_char **)kp->km_data); + } else if (kp->km_func == intset) { + fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data); + } else if (kp->km_func == worldxset) { + fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data); + } else if (kp->km_func == floatset) { + fprintf(fp, "%s %g\n", kp->km_key, *(float *)kp->km_data); + } else if (kp->km_func == doubleset) { + fprintf(fp, "%s %g\n", kp->km_key, *(double *)kp->km_data); + } else if (kp->km_func == longset) { + fprintf(fp, "%s %ld\n", kp->km_key, *(long *)kp->km_data); + } else if (kp->km_func == optionset) { + struct option_list *op; + + for (op = Options; op->opt_key; op++) { + if (*op->opt_valuep) + fprintf(fp, "%s %s\n", kp->km_key, op->opt_key); + } + } else if (kp->km_func == optiondel) { + struct option_list *op; + + for (op = Options; op->opt_key; op++) { + if (*op->opt_valuep == 0) + fprintf(fp, "%s %s\n", kp->km_key, op->opt_key); + } + } else + fprintf(fp, "# Unknown format %s\n", kp->km_key); + } + + fprintf(fp, "\n"); + for (ep = empfile; ep < &empfile[EF_MAX]; ep++) + fprintf(fp, "# File %s -> %s\n", ep->name, ep->file); + for (op = ofiles; op->files; op++) + fprintf(fp, "# File %s -> %s\n", op->name, *(op->files)); } - + /* add an option to the list */ -void set_option (const char *s) +void +set_option(const char *s) { - struct option_list *op; + struct option_list *op; - for (op = Options; op -> opt_key; op++) { - if (strcmp (op -> opt_key, s) == 0) - *op -> opt_valuep = 1; - } + for (op = Options; op->opt_key; op++) { + if (strcmp(op->opt_key, s) == 0) + *op->opt_valuep = 1; + } } /* delete an option from the list */ -void delete_option (const char *s) +void +delete_option(const char *s) { - struct option_list *op; + struct option_list *op; - for (op = Options; op -> opt_key; op++) { - if (strcmp (op -> opt_key, s) == 0) - *op -> opt_valuep = 0; - } + for (op = Options; op->opt_key; op++) { + if (strcmp(op->opt_key, s) == 0) + *op->opt_valuep = 0; + } } /* config interface */ -void optionset (struct keymatch *kp, s_char **av) - /* unused - we have a well known global */ - +void +optionset(struct keymatch *kp, s_char **av) + /* unused - we have a well known global */ { char **cpp; for (cpp = (char **)av; *cpp; cpp++) - set_option (*cpp); + set_option(*cpp); } /* config interface */ -void optiondel (struct keymatch *kp, s_char **av) - /* unused - we have a well known global */ - +void +optiondel(struct keymatch *kp, s_char **av) + /* unused - we have a well known global */ { char **cpp; for (cpp = (char **)av; *cpp; cpp++) - delete_option (*cpp); + delete_option(*cpp); } diff --git a/src/lib/gen/getstarg.c b/src/lib/gen/getstarg.c index a6c12a0a5..fb42f5d18 100644 --- a/src/lib/gen/getstarg.c +++ b/src/lib/gen/getstarg.c @@ -37,14 +37,14 @@ s_char * getstarg(s_char *input, s_char *prompt, s_char *buf) { - extern s_char *getstring(s_char *prompt, s_char *buf); + extern s_char *getstring(s_char *prompt, s_char *buf); - *buf = '\0'; - if (input == 0 || *input == 0) { - if (getstring(prompt, buf) == 0) - return 0; - } else { - strcpy(buf, input); - } - return buf; + *buf = '\0'; + if (input == 0 || *input == 0) { + if (getstring(prompt, buf) == 0) + return 0; + } else { + strcpy(buf, input); + } + return buf; } diff --git a/src/lib/gen/getstring.c b/src/lib/gen/getstring.c index 56a7706df..f1b7e65d5 100644 --- a/src/lib/gen/getstring.c +++ b/src/lib/gen/getstring.c @@ -38,8 +38,8 @@ s_char * getstring(s_char *prompt, s_char *buf) { - *buf = '\0'; - if (prmptrd(prompt, buf, 1024) < 0) - return 0; - return buf; + *buf = '\0'; + if (prmptrd(prompt, buf, 1024) < 0) + return 0; + return buf; } diff --git a/src/lib/gen/hpux.c b/src/lib/gen/hpux.c index b5cf0812a..93af1ead3 100644 --- a/src/lib/gen/hpux.c +++ b/src/lib/gen/hpux.c @@ -37,54 +37,54 @@ #include setbuffer(fp, buf, size) - FILE *fp; - s_char *buf; - int size; +FILE *fp; +s_char *buf; +int size; { - if (size > BUFSIZ) - setbuf(fp, buf); - /* XXX else report error */ + if (size > BUFSIZ) + setbuf(fp, buf); + /* XXX else report error */ } s_char * rindex(sp, c) - register s_char *sp; - register int c; +register s_char *sp; +register int c; { - register s_char *r; + register s_char *r; - r = NULL; - do { - if (*sp == c) - r = sp; - } while (*sp++); - return r; + r = NULL; + do { + if (*sp == c) + r = sp; + } while (*sp++); + return r; } s_char * index(sp, c) - register s_char *sp; - register int c; +register s_char *sp; +register int c; { - do { - if (*sp == c) - return (sp); - } while (*sp++); - return NULL; + do { + if (*sp == c) + return (sp); + } while (*sp++); + return NULL; } int ffs(marg) - register unsigned marg; +register unsigned marg; { - register unsigned bval; - register int i; + register unsigned bval; + register int i; - if (marg == 0) - return 0; - for (bval=1, i=1; i <= 32; i++, bval <<= 1) - if (marg & bval) - return i; + if (marg == 0) return 0; + for (bval = 1, i = 1; i <= 32; i++, bval <<= 1) + if (marg & bval) + return i; + return 0; } #endif diff --git a/src/lib/gen/iceil.c b/src/lib/gen/iceil.c index 6b3c45d2c..bc11c1837 100644 --- a/src/lib/gen/iceil.c +++ b/src/lib/gen/iceil.c @@ -36,17 +36,17 @@ int iceil(double arg) { - register int i; + register int i; - i = arg; - return(i >= arg ? i : i + 1); + i = arg; + return (i >= arg ? i : i + 1); } int ifloor(double arg) { - register int i; + register int i; - i = arg; - return(i <= arg ? i : i - 1); + i = arg; + return (i <= arg ? i : i - 1); } diff --git a/src/lib/gen/inet.c b/src/lib/gen/inet.c index a888a54da..20b58ec6a 100644 --- a/src/lib/gen/inet.c +++ b/src/lib/gen/inet.c @@ -35,7 +35,7 @@ #if !defined(_WIN32) #include #endif -#include /* sprintf */ +#include /* sprintf */ #include "misc.h" #include "gen.h" @@ -43,11 +43,11 @@ s_char * inet_ntoa(struct in_addr addr) { - static s_char str[18]; - register u_char *p; + static s_char str[18]; + register u_char *p; - p = (u_char *)&addr; - sprintf(str, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); - return str; + p = (u_char *)&addr; + sprintf(str, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]); + return str; } #endif /* NeXT */ diff --git a/src/lib/gen/io.c b/src/lib/gen/io.c index fae8b84ad..286d4aa1c 100644 --- a/src/lib/gen/io.c +++ b/src/lib/gen/io.c @@ -44,12 +44,12 @@ #if !defined(_WIN32) #include #include -#include /* close read shutdown select */ +#include /* close read shutdown select */ #include #endif #include #include -#include /* malloc calloc free */ +#include /* malloc calloc free */ #if defined(_WIN32) #include @@ -61,475 +61,463 @@ #include "ioqueue.h" #include "io_mask.h" #include "empio.h" -#include "gen.h" /* getfdtablesize */ +#include "gen.h" /* getfdtablesize */ #include "empthread.h" extern struct player *player; /* XXX */ -static struct iop **io_list; -static struct io_mask *iom; -static bit_fdmask newoutput; +static struct iop **io_list; +static struct io_mask *iom; +static bit_fdmask newoutput; struct iop { - int fd; - struct ioqueue *input; - struct ioqueue *output; - int flags; - s_char *assoc; - int bufsize; - int (*notify)(); + int fd; + struct ioqueue *input; + struct ioqueue *output; + int flags; + s_char *assoc; + int bufsize; + int (*notify) (); }; -extern int errno; +extern int errno; void io_init(void) { - iom = iom_create(IO_READ|IO_WRITE); - io_list = (struct iop **) calloc(getfdtablesize(), sizeof(*io_list)); - newoutput = bit_newfdmask(); + iom = iom_create(IO_READ | IO_WRITE); + io_list = (struct iop **)calloc(getfdtablesize(), sizeof(*io_list)); + newoutput = bit_newfdmask(); } struct iop * -io_open(int fd, int flags, int bufsize, int (*notify) (void), s_char *assoc) +io_open(int fd, int flags, int bufsize, int (*notify) (void), + s_char *assoc) { - struct iop *iop; + struct iop *iop; - if (io_list[fd] != 0) { - /* already exists */ - return 0; - } - flags = flags & (IO_READ|IO_WRITE|IO_NBLOCK|IO_NEWSOCK); - if ((flags & (IO_READ|IO_WRITE)) == 0) - return 0; - iop = (struct iop *) malloc(sizeof(struct iop)); - iop->fd = fd; - iop->input = 0; - iop->output = 0; - iop->flags = 0; - iop->bufsize = bufsize; - if ((flags & IO_READ) && (flags & IO_NEWSOCK) == 0) - iop->input = ioq_create(bufsize); - if ((flags & IO_WRITE) && (flags & IO_NEWSOCK) == 0) - iop->output = ioq_create(bufsize); - if (flags & IO_NBLOCK) - io_noblocking(iop, 1); - iop->flags = flags; - iop->assoc = assoc; - iop->notify = notify; - io_list[fd] = iop; - iom_set(iom, flags, fd); - return iop; + if (io_list[fd] != 0) { + /* already exists */ + return 0; + } + flags = flags & (IO_READ | IO_WRITE | IO_NBLOCK | IO_NEWSOCK); + if ((flags & (IO_READ | IO_WRITE)) == 0) + return 0; + iop = (struct iop *)malloc(sizeof(struct iop)); + iop->fd = fd; + iop->input = 0; + iop->output = 0; + iop->flags = 0; + iop->bufsize = bufsize; + if ((flags & IO_READ) && (flags & IO_NEWSOCK) == 0) + iop->input = ioq_create(bufsize); + if ((flags & IO_WRITE) && (flags & IO_NEWSOCK) == 0) + iop->output = ioq_create(bufsize); + if (flags & IO_NBLOCK) + io_noblocking(iop, 1); + iop->flags = flags; + iop->assoc = assoc; + iop->notify = notify; + io_list[fd] = iop; + iom_set(iom, flags, fd); + return iop; } void io_close(struct iop *iop) { - - if (iop->input != 0) - ioq_destroy(iop->input); - if (iop->output != 0) - ioq_destroy(iop->output); - iom_clear(iom, iop->flags, iop->fd); - BIT_CLRB(iop->fd, newoutput); - io_list[iop->fd] = 0; + + if (iop->input != 0) + ioq_destroy(iop->input); + if (iop->output != 0) + ioq_destroy(iop->output); + iom_clear(iom, iop->flags, iop->fd); + BIT_CLRB(iop->fd, newoutput); + io_list[iop->fd] = 0; #if !defined(_WIN32) - (void) close(iop->fd); + (void)close(iop->fd); #else closesocket(iop->fd); #endif - free((s_char *)iop); + free((s_char *)iop); } int io_input(struct iop *iop, int waitforinput) { - s_char buf[IO_BUFSIZE]; - int cc; + s_char buf[IO_BUFSIZE]; + int cc; /* Not a read IOP */ - if ((iop->flags & IO_READ) == 0) - return -1; + if ((iop->flags & IO_READ) == 0) + return -1; /* IOP is markes as in error. */ - if (iop->flags & IO_ERROR) - return -1; + if (iop->flags & IO_ERROR) + return -1; /* Wait for the file to have input. */ - if (waitforinput) { - empth_select(iop->fd, EMPTH_FD_READ); - } + if (waitforinput) { + empth_select(iop->fd, EMPTH_FD_READ); + } #if !defined(_WIN32) /* Do the actual read. */ - cc = read(iop->fd, buf, sizeof(buf)); - if (cc < 0) { - /* would block, so nothing to read. */ - if (errno == EWOULDBLOCK) - return 0; - - /* Some form of file error occurred... */ - iop->flags |= IO_ERROR; - iom_clear(iom, IO_READ, iop->fd); - return -1; - } + cc = read(iop->fd, buf, sizeof(buf)); + if (cc < 0) { + /* would block, so nothing to read. */ + if (errno == EWOULDBLOCK) + return 0; + + /* Some form of file error occurred... */ + iop->flags |= IO_ERROR; + iom_clear(iom, IO_READ, iop->fd); + return -1; + } #else cc = recv(iop->fd, buf, sizeof(buf), 0); if (cc == SOCKET_ERROR) { - int err = WSAGetLastError(); - /* Hmm, it would block. file is opened noblock, soooooo.. */ - if (err == WSAEWOULDBLOCK) - return 0; - - /* Some form of file error occurred... */ - iop->flags |= IO_ERROR; - iom_clear(iom, IO_READ, iop->fd); - return -1; + int err = WSAGetLastError(); + /* Hmm, it would block. file is opened noblock, soooooo.. */ + if (err == WSAEWOULDBLOCK) + return 0; + + /* Some form of file error occurred... */ + iop->flags |= IO_ERROR; + iom_clear(iom, IO_READ, iop->fd); + return -1; } #endif /* We eof'd */ - if (cc == 0) { - iop->flags |= IO_EOF; - return 0; - } + if (cc == 0) { + iop->flags |= IO_EOF; + return 0; + } /* Append the input to the IOQ. */ - ioq_append(iop->input, buf, cc); - return cc; + ioq_append(iop->input, buf, cc); + return cc; } int io_inputwaiting(struct iop *iop) { - return ioq_qsize(iop->input); + return ioq_qsize(iop->input); } int io_outputwaiting(struct iop *iop) { - return ioq_qsize(iop->output); + return ioq_qsize(iop->output); } int io_output(struct iop *iop, int waitforoutput) { #if !defined(_WIN32) - struct iovec iov[16]; + struct iovec iov[16]; #else - s_char buf[IO_BUFSIZE]; + s_char buf[IO_BUFSIZE]; #endif - int cc; - int n; - int remain; + int cc; + int n; + int remain; /* If there is no output waiting. */ - if (!io_outputwaiting(iop)) - return 0; + if (!io_outputwaiting(iop)) + return 0; /* bit clear */ - BIT_CLRB(iop->fd, newoutput); + BIT_CLRB(iop->fd, newoutput); /* If the iop is not write enabled. */ - if ((iop->flags & IO_WRITE) == 0) - return -1; + if ((iop->flags & IO_WRITE) == 0) + return -1; /* If the io is marked as in error... */ - if (iop->flags & IO_ERROR) - return -1; + if (iop->flags & IO_ERROR) + return -1; /* This is the same test as io_outputwaiting.... */ - if (ioq_qsize(iop->output) == 0) - return 0; + if (ioq_qsize(iop->output) == 0) + return 0; #if !defined(_WIN32) /* make the iov point to the data in the queue. */ /* I.E., each of the elements in the queue. */ /* returns the number of elements in the iov. */ - n = ioq_makeiov(iop->output, iov, IO_BUFSIZE); + n = ioq_makeiov(iop->output, iov, IO_BUFSIZE); #else /* Make a buffer containing the output to write. */ - n = ioq_makebuf(iop->output, buf, sizeof(buf)); + n = ioq_makebuf(iop->output, buf, sizeof(buf)); #endif - if (n <= 0) { - /* If we got no elements, we have no output.... */ - iom_clear(iom, IO_WRITE, iop->fd); - return 0; - } + if (n <= 0) { + /* If we got no elements, we have no output.... */ + iom_clear(iom, IO_WRITE, iop->fd); + return 0; + } /* wait for the file to be output ready. */ - if (waitforoutput != IO_NOWAIT) { - /* This waits for the file to be ready for writing, */ - /* and lets other threads run. */ - empth_select(iop->fd, EMPTH_FD_WRITE); - } + if (waitforoutput != IO_NOWAIT) { + /* This waits for the file to be ready for writing, */ + /* and lets other threads run. */ + empth_select(iop->fd, EMPTH_FD_WRITE); + } /* Do the actual write. */ #if !defined(_WIN32) - cc = writev(iop->fd, iov, n); + cc = writev(iop->fd, iov, n); /* if it failed.... */ - if (cc < 0) { - /* Hmm, it would block. file is opened noblock, soooooo.. */ - if (errno == EWOULDBLOCK) { - /* If there are remaining bytes, set the IO as remaining.. */ - remain = ioq_qsize(iop->output); - if (remain > 0) - iom_set(iom, IO_WRITE, iop->fd); - return remain; - } - iop->flags |= IO_ERROR; - iom_clear(iom, IO_WRITE, iop->fd); - return -1; + if (cc < 0) { + /* Hmm, it would block. file is opened noblock, soooooo.. */ + if (errno == EWOULDBLOCK) { + /* If there are remaining bytes, set the IO as remaining.. */ + remain = ioq_qsize(iop->output); + if (remain > 0) + iom_set(iom, IO_WRITE, iop->fd); + return remain; } + iop->flags |= IO_ERROR; + iom_clear(iom, IO_WRITE, iop->fd); + return -1; + } #else - cc = send(iop->fd, buf, n, 0); + cc = send(iop->fd, buf, n, 0); /* if it failed.... */ - if (cc == SOCKET_ERROR) { - int err = WSAGetLastError(); - /* Hmm, it would block. file is opened noblock, soooooo.. */ - if (err == WSAEWOULDBLOCK) { - /* If there are remaining bytes, set the IO as remaining.. */ - remain = ioq_qsize(iop->output); - if (remain > 0) - iom_set(iom, IO_WRITE, iop->fd); - return remain; - } - iop->flags |= IO_ERROR; - iom_clear(iom, IO_WRITE, iop->fd); - return -1; + if (cc == SOCKET_ERROR) { + int err = WSAGetLastError(); + /* Hmm, it would block. file is opened noblock, soooooo.. */ + if (err == WSAEWOULDBLOCK) { + /* If there are remaining bytes, set the IO as remaining.. */ + remain = ioq_qsize(iop->output); + if (remain > 0) + iom_set(iom, IO_WRITE, iop->fd); + return remain; } + iop->flags |= IO_ERROR; + iom_clear(iom, IO_WRITE, iop->fd); + return -1; + } #endif /* If no bytes were written, something happened.. Like an EOF. */ #ifndef hpux - if (cc == 0) { - iop->flags |= IO_EOF; - return 0; - } + if (cc == 0) { + iop->flags |= IO_EOF; + return 0; + } #else - if (cc == 0) { - remain = ioq_qsize(iop->output); - if (remain > 0) - iom_set(iom, IO_WRITE, iop->fd); - return remain; - } -#endif /* hpux */ + if (cc == 0) { + remain = ioq_qsize(iop->output); + if (remain > 0) + iom_set(iom, IO_WRITE, iop->fd); + return remain; + } +#endif /* hpux */ /* Remove the number of written bytes from the queue. */ - ioq_dequeue(iop->output, cc); + ioq_dequeue(iop->output, cc); /* If the queue has stuff remaining, set it still needing output. */ - remain = ioq_qsize(iop->output); - if (remain == 0) { - iom_clear(iom, IO_WRITE, iop->fd); - } else { - iom_set(iom, IO_WRITE, iop->fd); - } - return cc; + remain = ioq_qsize(iop->output); + if (remain == 0) { + iom_clear(iom, IO_WRITE, iop->fd); + } else { + iom_set(iom, IO_WRITE, iop->fd); + } + return cc; } int io_select(struct timeval *tv) { - bit_fdmask readmask; - bit_fdmask writemask; - int n; - int nfds; - int fd; - struct iop *iop; - - iom_getmask(iom, &nfds, &readmask, &writemask); - n = select(nfds + 1, (fd_set *)readmask, (fd_set *)writemask, 0, tv); - if (n <= 0) { - if (errno == EINTR) - return 0; - return -1; - } - while ((fd = bit_fd(readmask)) >= 0) { - iop = io_list[fd]; - if ((iop->flags & IO_NEWSOCK) == 0) - (void) io_input(iop, IO_NOWAIT); - if (iop->notify != 0) - iop->notify(iop, IO_READ, iop->assoc); - BIT_CLRB(fd, readmask); - } - while ((fd = bit_fd(writemask)) >= 0) { - iop = io_list[fd]; - if (io_output(iop, IO_NOWAIT) < 0 && iop->notify != 0) - iop->notify(iop, IO_WRITE, iop->assoc); - BIT_CLRB(fd, writemask); - } - return n; + bit_fdmask readmask; + bit_fdmask writemask; + int n; + int nfds; + int fd; + struct iop *iop; + + iom_getmask(iom, &nfds, &readmask, &writemask); + n = select(nfds + 1, (fd_set *) readmask, (fd_set *) writemask, 0, tv); + if (n <= 0) { + if (errno == EINTR) + return 0; + return -1; + } + while ((fd = bit_fd(readmask)) >= 0) { + iop = io_list[fd]; + if ((iop->flags & IO_NEWSOCK) == 0) + (void)io_input(iop, IO_NOWAIT); + if (iop->notify != 0) + iop->notify(iop, IO_READ, iop->assoc); + BIT_CLRB(fd, readmask); + } + while ((fd = bit_fd(writemask)) >= 0) { + iop = io_list[fd]; + if (io_output(iop, IO_NOWAIT) < 0 && iop->notify != 0) + iop->notify(iop, IO_WRITE, iop->assoc); + BIT_CLRB(fd, writemask); + } + return n; } void io_flush(int doWait) { - int fd; - struct iop *iop; + int fd; + struct iop *iop; - while ((fd = bit_fd(newoutput)) >= 0) { - iop = io_list[fd]; - if (io_output(iop, doWait) < 0 && iop->notify != 0) - iop->notify(iop, IO_WRITE, iop->assoc); - } + while ((fd = bit_fd(newoutput)) >= 0) { + iop = io_list[fd]; + if (io_output(iop, doWait) < 0 && iop->notify != 0) + iop->notify(iop, IO_WRITE, iop->assoc); + } } int io_peek(struct iop *iop, s_char *buf, int nbytes) { - if ((iop->flags & IO_READ) == 0) - return -1; - return ioq_peek(iop->input, buf, nbytes); + if ((iop->flags & IO_READ) == 0) + return -1; + return ioq_peek(iop->input, buf, nbytes); } int io_read(struct iop *iop, s_char *buf, int nbytes) { - int cc; - - if ((iop->flags & IO_READ) == 0) - return -1; - cc = ioq_peek(iop->input, buf, nbytes); - if (cc > 0) - ioq_dequeue(iop->input, cc); - return cc; + int cc; + + if ((iop->flags & IO_READ) == 0) + return -1; + cc = ioq_peek(iop->input, buf, nbytes); + if (cc > 0) + ioq_dequeue(iop->input, cc); + return cc; } int io_write(struct iop *iop, s_char *buf, int nbytes, int doWait) { - int len; - - if ((iop->flags & IO_WRITE) == 0) - return -1; - ioq_append(iop->output, buf, nbytes); - BIT_SETB(iop->fd, newoutput); - len = ioq_qsize(iop->output); - if (len > iop->bufsize) { - if (doWait) { - io_output_all(iop); - } else { - /* only try a write every BUFSIZE characters */ - if (((len-nbytes) % iop->bufsize) < - (len % iop->bufsize)) - io_output(iop, 0); - } + int len; + + if ((iop->flags & IO_WRITE) == 0) + return -1; + ioq_append(iop->output, buf, nbytes); + BIT_SETB(iop->fd, newoutput); + len = ioq_qsize(iop->output); + if (len > iop->bufsize) { + if (doWait) { + io_output_all(iop); + } else { + /* only try a write every BUFSIZE characters */ + if (((len - nbytes) % iop->bufsize) < (len % iop->bufsize)) + io_output(iop, 0); } - return nbytes; + } + return nbytes; } int io_output_all(struct iop *iop) { - int n; + int n; - while ((n = io_output(iop, IO_NOWAIT)) > 0) { - empth_select(iop->fd, EMPTH_FD_WRITE); - } - return n; + while ((n = io_output(iop, IO_NOWAIT)) > 0) { + empth_select(iop->fd, EMPTH_FD_WRITE); + } + return n; } int io_gets(struct iop *iop, s_char *buf, int nbytes) { - if ((iop->flags & IO_READ) == 0) - return -1; - return ioq_gets(iop->input, buf, nbytes); + if ((iop->flags & IO_READ) == 0) + return -1; + return ioq_gets(iop->input, buf, nbytes); } int io_puts(struct iop *iop, s_char *buf) { - if ((iop->flags & IO_WRITE) == 0) - return -1; - BIT_SETB(iop->fd, newoutput); - return ioq_puts(iop->output, buf); + if ((iop->flags & IO_WRITE) == 0) + return -1; + BIT_SETB(iop->fd, newoutput); + return ioq_puts(iop->output, buf); } int io_shutdown(struct iop *iop, int flags) { - flags &= (IO_READ|IO_WRITE); - if ((iop->flags & flags) != flags) - return -1; - if (flags & IO_READ) { - shutdown(iop->fd, 0); - ioq_drain(iop->input); - } - if (flags & IO_WRITE) { - shutdown(iop->fd, 1); - ioq_drain(iop->output); - } - return 0; + flags &= (IO_READ | IO_WRITE); + if ((iop->flags & flags) != flags) + return -1; + if (flags & IO_READ) { + shutdown(iop->fd, 0); + ioq_drain(iop->input); + } + if (flags & IO_WRITE) { + shutdown(iop->fd, 1); + ioq_drain(iop->output); + } + return 0; } int io_noblocking(struct iop *iop, int value) { #if !defined(_WIN32) - int flags; - - flags = fcntl(iop->fd, F_GETFL, 0); - if (flags < 0) - return -1; - if (value == 0) - flags &= ~FNDELAY; - else - flags |= FNDELAY; - if (fcntl(iop->fd, F_SETFL, flags) < 0) - return -1; + int flags; + + flags = fcntl(iop->fd, F_GETFL, 0); + if (flags < 0) + return -1; + if (value == 0) + flags &= ~FNDELAY; + else + flags |= FNDELAY; + if (fcntl(iop->fd, F_SETFL, flags) < 0) + return -1; #else u_long arg = value; ioctlsocket(iop->fd, FIONBIO, &arg); #endif - if (value == 0) - iop->flags &= ~IO_NBLOCK; - else - iop->flags |= IO_NBLOCK; - return 0; + if (value == 0) + iop->flags &= ~IO_NBLOCK; + else + iop->flags |= IO_NBLOCK; + return 0; } int io_conn(struct iop *iop) { - return (iop->flags & IO_CONN); + return (iop->flags & IO_CONN); } int io_error(struct iop *iop) { - return (iop->flags & IO_ERROR); + return (iop->flags & IO_ERROR); } int io_eof(struct iop *iop) { - return (iop->flags & IO_EOF); + return (iop->flags & IO_EOF); } int io_fileno(struct iop *iop) { - return iop->fd; + return iop->fd; } struct iop * io_iopfromfd(int fd) { - return io_list[fd]; + return io_list[fd]; } - - - - - - - - - - - - diff --git a/src/lib/gen/io_mask.c b/src/lib/gen/io_mask.c index d96e3a248..f64d57e85 100644 --- a/src/lib/gen/io_mask.c +++ b/src/lib/gen/io_mask.c @@ -31,83 +31,84 @@ * */ -#include /* malloc */ +#include /* malloc */ #include #include "misc.h" #include "bit.h" #include "empio.h" #include "io_mask.h" -extern int errno; +extern int errno; struct io_mask * iom_create(int what) { - struct io_mask *imp; + struct io_mask *imp; - imp = (struct io_mask *) malloc(sizeof(*imp)); - if (what & IO_READ) { - imp->readmask = bit_newfdmask(); - imp->user_readmask = bit_newfdmask(); - } else { - imp->readmask = 0; - imp->user_readmask = 0; - } - if (what & IO_WRITE) { - imp->writemask = bit_newfdmask(); - imp->user_writemask = bit_newfdmask(); - } else { - imp->writemask = 0; - imp->user_writemask = 0; - } - imp->what = what; - imp->maxfd = 0; - return imp; + imp = (struct io_mask *)malloc(sizeof(*imp)); + if (what & IO_READ) { + imp->readmask = bit_newfdmask(); + imp->user_readmask = bit_newfdmask(); + } else { + imp->readmask = 0; + imp->user_readmask = 0; + } + if (what & IO_WRITE) { + imp->writemask = bit_newfdmask(); + imp->user_writemask = bit_newfdmask(); + } else { + imp->writemask = 0; + imp->user_writemask = 0; + } + imp->what = what; + imp->maxfd = 0; + return imp; } void -iom_getmask(struct io_mask *mask, int *nfdp, bit_fdmask *readp, bit_fdmask *writep) +iom_getmask(struct io_mask *mask, int *nfdp, bit_fdmask *readp, + bit_fdmask *writep) { - if (mask->what & IO_READ) - bit_copy(mask->readmask, mask->user_readmask); - if (mask->what & IO_WRITE) - bit_copy(mask->writemask, mask->user_writemask); - *readp = mask->user_readmask; - *writep = mask->user_writemask; - *nfdp = mask->maxfd; + if (mask->what & IO_READ) + bit_copy(mask->readmask, mask->user_readmask); + if (mask->what & IO_WRITE) + bit_copy(mask->writemask, mask->user_writemask); + *readp = mask->user_readmask; + *writep = mask->user_writemask; + *nfdp = mask->maxfd; } void iom_set(struct io_mask *mask, int what, int fd) { - if ((mask->what & what) == 0) - return; - if (what & IO_READ) - BIT_SETB(fd, mask->readmask); - if (what & IO_WRITE) - BIT_SETB(fd, mask->writemask); - if (fd > mask->maxfd) - mask->maxfd = fd; + if ((mask->what & what) == 0) + return; + if (what & IO_READ) + BIT_SETB(fd, mask->readmask); + if (what & IO_WRITE) + BIT_SETB(fd, mask->writemask); + if (fd > mask->maxfd) + mask->maxfd = fd; } void iom_clear(struct io_mask *mask, int what, int fd) { - if ((mask->what & what) == 0) - return; - if (what & IO_READ) - BIT_CLRB(fd, mask->readmask); - if (what & IO_WRITE) - BIT_CLRB(fd, mask->writemask); + if ((mask->what & what) == 0) + return; + if (what & IO_READ) + BIT_CLRB(fd, mask->readmask); + if (what & IO_WRITE) + BIT_CLRB(fd, mask->writemask); } void iom_zero(struct io_mask *mask, int what) { - if ((mask->what & what) == 0) - return; - if (what & IO_READ) - bit_zero(mask->readmask); - if (what & IO_WRITE) - bit_zero(mask->writemask); + if ((mask->what & what) == 0) + return; + if (what & IO_READ) + bit_zero(mask->readmask); + if (what & IO_WRITE) + bit_zero(mask->writemask); } diff --git a/src/lib/gen/ioqueue.c b/src/lib/gen/ioqueue.c index 123607a53..c9c20114a 100644 --- a/src/lib/gen/ioqueue.c +++ b/src/lib/gen/ioqueue.c @@ -38,7 +38,7 @@ */ #include -#include /* malloc free */ +#include /* malloc free */ #include #if !defined(_WIN32) #include @@ -47,9 +47,11 @@ #include "queue.h" #include "ioqueue.h" -static int ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, register int stopc); +static int ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, + register int stopc); #if !defined(_WIN32) -static int ioqtoiov(struct ioqueue *ioq, struct iovec *iov, register int max); +static int ioqtoiov(struct ioqueue *ioq, struct iovec *iov, + register int max); #endif static int ioqtobuf(struct ioqueue *ioq, s_char *buf, int cc); static int appendcc(struct ioqueue *ioq, s_char *buf, int cc); @@ -62,43 +64,43 @@ static void loc_StripDels(char *pBuf); struct ioqueue * ioq_create(int size) { - struct ioqueue *ioq; - - ioq = (struct ioqueue *) malloc(sizeof(struct ioqueue)); - emp_initque(&ioq->list.queue); - ioq->list.nbytes = 0; - ioq->list.offset = 0; - ioq->list.size = 0; - ioq->list.data = 0; - ioq->bufsize = size; - ioq->cc = 0; - return ioq; + struct ioqueue *ioq; + + ioq = (struct ioqueue *)malloc(sizeof(struct ioqueue)); + emp_initque(&ioq->list.queue); + ioq->list.nbytes = 0; + ioq->list.offset = 0; + ioq->list.size = 0; + ioq->list.data = 0; + ioq->bufsize = size; + ioq->cc = 0; + return ioq; } void ioq_destroy(struct ioqueue *ioq) { -#if !defined(aix) && !defined(NeXT) +#if !defined(aix) && !defined(NeXT) /* ioq_drain doesn't work under aix or NeXT... dunno why --ts */ - ioq_drain(ioq); + ioq_drain(ioq); #endif /* aix */ - free((s_char *)ioq); + free((s_char *)ioq); } void ioq_drain(struct ioqueue *ioq) { - struct emp_qelem *qp; - struct io *io; - - while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue){ - io = (struct io *) qp; - (void) emp_remque(&io->queue); - (void) free((s_char *)io->data); - (void) free((s_char *)io); - } - - ioq->cc = 0; + struct emp_qelem *qp; + struct io *io; + + while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) { + io = (struct io *)qp; + (void)emp_remque(&io->queue); + (void)free((s_char *)io->data); + (void)free((s_char *)io); + } + + ioq->cc = 0; } /* @@ -110,9 +112,9 @@ ioq_drain(struct ioqueue *ioq) int ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc) { - if (ioq->cc <= 0) - return 0; - return ioqtoiov(ioq, iov, cc); + if (ioq->cc <= 0) + return 0; + return ioqtoiov(ioq, iov, cc); } #endif @@ -124,25 +126,25 @@ ioq_makeiov(struct ioqueue *ioq, struct iovec *iov, int cc) int ioq_peek(struct ioqueue *ioq, s_char *buf, int cc) { - return ioqtobuf(ioq, buf, cc); + return ioqtobuf(ioq, buf, cc); } int ioq_dequeue(struct ioqueue *ioq, int cc) { - return removecc(ioq, cc); + return removecc(ioq, cc); } void ioq_append(struct ioqueue *ioq, s_char *buf, int cc) { - appendcc(ioq, buf, cc); + appendcc(ioq, buf, cc); } int ioq_qsize(struct ioqueue *ioq) { - return ioq->cc; + return ioq->cc; } /* @@ -153,28 +155,28 @@ ioq_qsize(struct ioqueue *ioq) int ioq_gets(struct ioqueue *ioq, s_char *buf, int cc) { - int nbytes; - int actual; - - nbytes = ioqtocbuf(ioq, buf, cc - 1, '\n'); - if (nbytes >= 0) { - actual = nbytes; - if (actual > cc - 1) - actual = cc - 1; - buf[actual] = '\0'; - /* remove the newline too */ - removecc(ioq, nbytes + 1); + int nbytes; + int actual; + + nbytes = ioqtocbuf(ioq, buf, cc - 1, '\n'); + if (nbytes >= 0) { + actual = nbytes; + if (actual > cc - 1) + actual = cc - 1; + buf[actual] = '\0'; + /* remove the newline too */ + removecc(ioq, nbytes + 1); #if defined(_WIN32) - loc_StripDels(buf); + loc_StripDels(buf); #endif - } - return nbytes; + } + return nbytes; } int ioq_puts(struct ioqueue *ioq, s_char *buf) { - return appendcc(ioq, buf, strlen(buf)); + return appendcc(ioq, buf, strlen(buf)); } /* @@ -188,34 +190,34 @@ ioq_puts(struct ioqueue *ioq, s_char *buf) * left for a higher level. */ static -int + int ioqtobuf(struct ioqueue *ioq, s_char *buf, int cc) { - struct io *io; - struct emp_qelem *qp; - struct emp_qelem *head; - register int nbytes; - register int nleft; - register s_char *offset; - - nleft = cc; - offset = buf; - head = &ioq->list.queue; - for (qp = head->q_forw; qp != head && nleft > 0; qp = qp->q_forw) { - io = (struct io *) qp; - if ((nbytes = io->nbytes - io->offset) < 0) { - /* XXX log something here */ - continue; - } - if (nbytes > 0) { - if (nleft < nbytes) - nbytes = nleft; - bcopy(io->data + io->offset, offset, nbytes); - offset += nbytes; - nleft -= nbytes; - } + struct io *io; + struct emp_qelem *qp; + struct emp_qelem *head; + register int nbytes; + register int nleft; + register s_char *offset; + + nleft = cc; + offset = buf; + head = &ioq->list.queue; + for (qp = head->q_forw; qp != head && nleft > 0; qp = qp->q_forw) { + io = (struct io *)qp; + if ((nbytes = io->nbytes - io->offset) < 0) { + /* XXX log something here */ + continue; + } + if (nbytes > 0) { + if (nleft < nbytes) + nbytes = nleft; + bcopy(io->data + io->offset, offset, nbytes); + offset += nbytes; + nleft -= nbytes; } - return offset - buf; + } + return offset - buf; } /* @@ -223,38 +225,37 @@ ioqtobuf(struct ioqueue *ioq, s_char *buf, int cc) * terminating on the stop character. */ static -int + int ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, register int stopc) { - register int nbytes; - register s_char *p; - register int n; - struct io *io; - struct emp_qelem *qp; - struct emp_qelem *head; - int total; - int found; - - head = &ioq->list.queue; - found = 0; - total = 0; - for (qp = head->q_forw; qp != head; qp = qp->q_forw) { - io = (struct io *) qp; - if ((nbytes = io->nbytes - io->offset) <= 0) - continue; - p = io->data + io->offset; - for (n=0; n < nbytes && p[n] != stopc; n++) - ; - total += n; - if (n < nbytes) { - found++; - break; - } + register int nbytes; + register s_char *p; + register int n; + struct io *io; + struct emp_qelem *qp; + struct emp_qelem *head; + int total; + int found; + + head = &ioq->list.queue; + found = 0; + total = 0; + for (qp = head->q_forw; qp != head; qp = qp->q_forw) { + io = (struct io *)qp; + if ((nbytes = io->nbytes - io->offset) <= 0) + continue; + p = io->data + io->offset; + for (n = 0; n < nbytes && p[n] != stopc; n++) ; + total += n; + if (n < nbytes) { + found++; + break; } - if (found == 0) - return -1; - ioqtobuf(ioq, buf, cc < total ? cc : total); - return total; + } + if (found == 0) + return -1; + ioqtobuf(ioq, buf, cc < total ? cc : total); + return total; } /* @@ -263,33 +264,33 @@ ioqtocbuf(struct ioqueue *ioq, s_char *buf, int cc, register int stopc) */ #if !defined(_WIN32) static -int + int ioqtoiov(struct ioqueue *ioq, struct iovec *iov, register int max) { - struct io *io; - register int cc; - register int niov; - register int len; - struct emp_qelem *qp; - - cc = max; - niov = 0; - qp = ioq->list.queue.q_forw; - while (qp != &ioq->list.queue && cc > 0) { - io = (struct io *) qp; - len = io->nbytes - io->offset; - if (len > cc) - len = cc; - iov->iov_base = io->data + io->offset; - iov->iov_len = len; - cc -= len; - niov++; - iov++; - qp = qp->q_forw; - if (niov >= 16) - break; - } - return niov; + struct io *io; + register int cc; + register int niov; + register int len; + struct emp_qelem *qp; + + cc = max; + niov = 0; + qp = ioq->list.queue.q_forw; + while (qp != &ioq->list.queue && cc > 0) { + io = (struct io *)qp; + len = io->nbytes - io->offset; + if (len > cc) + len = cc; + iov->iov_base = io->data + io->offset; + iov->iov_len = len; + cc -= len; + niov++; + iov++; + qp = qp->q_forw; + if (niov >= 16) + break; + } + return niov; } #endif @@ -297,39 +298,39 @@ ioqtoiov(struct ioqueue *ioq, struct iovec *iov, register int max) * append a buffer to the end of the ioq. */ static -int + int appendcc(struct ioqueue *ioq, s_char *buf, int cc) { - struct io *io; - int len; - s_char *ptr; - int avail; - - /* determine if any space is left */ - io = (struct io *)ioq->list.queue.q_back; - avail = io->size - io->nbytes; - if (avail > 0) { - /* append to existing buffer */ - len = cc > avail ? avail : cc; - bcopy(buf, io->data + io->nbytes, len); - io->nbytes += len; - ioq->cc += len; - if (avail < cc) - appendcc(ioq, buf + len, cc - len); - } else { - /* create a new buffer, minimum bufsize bytes */ - len = cc > ioq->bufsize ? cc : ioq->bufsize; - ptr = malloc(len); - bcopy(buf, ptr, cc); - io = (struct io *) malloc(sizeof(struct io)); - io->nbytes = cc; - io->size = len; - io->offset = 0; - io->data = ptr; - emp_insque(&io->queue, ioq->list.queue.q_back); - ioq->cc += cc; - } - return cc; + struct io *io; + int len; + s_char *ptr; + int avail; + + /* determine if any space is left */ + io = (struct io *)ioq->list.queue.q_back; + avail = io->size - io->nbytes; + if (avail > 0) { + /* append to existing buffer */ + len = cc > avail ? avail : cc; + bcopy(buf, io->data + io->nbytes, len); + io->nbytes += len; + ioq->cc += len; + if (avail < cc) + appendcc(ioq, buf + len, cc - len); + } else { + /* create a new buffer, minimum bufsize bytes */ + len = cc > ioq->bufsize ? cc : ioq->bufsize; + ptr = malloc(len); + bcopy(buf, ptr, cc); + io = (struct io *)malloc(sizeof(struct io)); + io->nbytes = cc; + io->size = len; + io->offset = 0; + io->data = ptr; + emp_insque(&io->queue, ioq->list.queue.q_back); + ioq->cc += cc; + } + return cc; } /* @@ -338,45 +339,46 @@ appendcc(struct ioqueue *ioq, s_char *buf, int cc) * which are no longer used. */ static -int + int removecc(struct ioqueue *ioq, register int cc) { - struct io *io; - struct emp_qelem *qp; - register int nbytes; - register int there; - register int remain; - - nbytes = 0; - remain = cc; - while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) { - io = (struct io *) qp; - there = io->nbytes - io->offset; - if (there < 0) { - /* error */ - (void) emp_remque(&io->queue); - (void) free((s_char *)io); - continue; - } - if (remain >= there) { - /* not enough or exact; free entry */ - nbytes += there; - remain -= there; - (void) emp_remque(&io->queue); - (void) free(io->data); - (void) free((s_char *)io); - } else { - /* too much; increment offset */ - io->offset += remain; - nbytes += remain; - remain = 0; - } - if (remain <= 0) - break; + struct io *io; + struct emp_qelem *qp; + register int nbytes; + register int there; + register int remain; + + nbytes = 0; + remain = cc; + while ((qp = ioq->list.queue.q_forw) != &ioq->list.queue) { + io = (struct io *)qp; + there = io->nbytes - io->offset; + if (there < 0) { + /* error */ + (void)emp_remque(&io->queue); + (void)free((s_char *)io); + continue; + } + if (remain >= there) { + /* not enough or exact; free entry */ + nbytes += there; + remain -= there; + (void)emp_remque(&io->queue); + (void)free(io->data); + (void)free((s_char *)io); + } else { + /* too much; increment offset */ + io->offset += remain; + nbytes += remain; + remain = 0; } - ioq->cc -= nbytes; - return nbytes; + if (remain <= 0) + break; + } + ioq->cc -= nbytes; + return nbytes; } + #if defined(_WIN32) /* * Make an (output) buffer up to the @@ -387,39 +389,37 @@ removecc(struct ioqueue *ioq, register int cc) int ioq_makebuf(struct ioqueue *ioq, char *pBuf, int nBufLen) { - struct io *io; - struct emp_qelem *qp; - struct emp_qelem *head; - int nbytes; - int nleft; + struct io *io; + struct emp_qelem *qp; + struct emp_qelem *head; + int nbytes; + int nleft; int ncopied; - s_char *offset; + s_char *offset; ncopied = 0; - nleft = nBufLen; - offset = pBuf; - head = &ioq->list.queue; - - for (qp = head->q_forw; - (qp != head) && (nleft > 0); - qp = qp->q_forw) { - io = (struct io *) qp; - nbytes = io->nbytes - io->offset; - if (nbytes < 0) { - /* Paranoid check for bad buffer. */ - continue; - } - - /* too many bytes, wait till next time. */ - if (nbytes > nleft) - break; - - bcopy(io->data + io->offset, offset, nbytes); - offset += nbytes; - nleft -= nbytes; - ncopied += nbytes; + nleft = nBufLen; + offset = pBuf; + head = &ioq->list.queue; + + for (qp = head->q_forw; (qp != head) && (nleft > 0); qp = qp->q_forw) { + io = (struct io *)qp; + nbytes = io->nbytes - io->offset; + if (nbytes < 0) { + /* Paranoid check for bad buffer. */ + continue; } - return ncopied; + + /* too many bytes, wait till next time. */ + if (nbytes > nleft) + break; + + bcopy(io->data + io->offset, offset, nbytes); + offset += nbytes; + nleft -= nbytes; + ncopied += nbytes; + } + return ncopied; } #endif /* _WIN32 */ @@ -438,19 +438,18 @@ loc_StripDels(char *pBuf) char *sp; for (cp = pBuf; *cp;) { - /* Remove Backspace and DEL */ - if (*cp == '\b' || *cp == '\x8F') { - if (cp == pBuf) - dp = cp; - else - dp = cp - 1; - sp = cp + 1; - while (*sp) - *dp++ = *sp++; - *dp = 0; - } else - cp++; + /* Remove Backspace and DEL */ + if (*cp == '\b' || *cp == '\x8F') { + if (cp == pBuf) + dp = cp; + else + dp = cp - 1; + sp = cp + 1; + while (*sp) + *dp++ = *sp++; + *dp = 0; + } else + cp++; } } #endif - diff --git a/src/lib/gen/lock.c b/src/lib/gen/lock.c index cc08b25ea..c3015f830 100644 --- a/src/lib/gen/lock.c +++ b/src/lib/gen/lock.c @@ -58,20 +58,20 @@ int file_lock(int fd) { if (_locking(fd, _LK_LOCK, 0) < 0) { - logerror("file lock (fd %d) failed", fd); - return 0; + logerror("file lock (fd %d) failed", fd); + return 0; } - return 1; + return 1; } int file_unlock(int fd) { if (_locking(fd, _LK_UNLCK, 0) < 0) { - logerror("file lock (fd %d) failed", fd); - return 0; + logerror("file lock (fd %d) failed", fd); + return 0; } - return 1; + return 1; } #else @@ -83,21 +83,21 @@ int flock(); int file_lock(int fd) { - if (flock(fd, LOCK_EX) < 0) { - logerror("file lock (fd %d) failed", fd); - return 0; - } - return 1; + if (flock(fd, LOCK_EX) < 0) { + logerror("file lock (fd %d) failed", fd); + return 0; + } + return 1; } int file_unlock(int fd) { - if (flock(fd, LOCK_UN) < 0) { - logerror("file unlock (fd %d) failed", fd); - return 0; - } - return 1; + if (flock(fd, LOCK_UN) < 0) { + logerror("file unlock (fd %d) failed", fd); + return 0; + } + return 1; } #else @@ -105,35 +105,35 @@ file_unlock(int fd) int file_lock(int fd) { - struct flock lock; - - lock.l_type = F_WRLCK; - lock.l_whence = L_SET; - lock.l_start = 0; - lock.l_len = 0; - lock.l_pid = 0; - if (fcntl(fd, F_SETLKW, &lock) < 0) { - logerror("file lock (fd %d) failed", fd); - return 0; - } - return 1; + struct flock lock; + + lock.l_type = F_WRLCK; + lock.l_whence = L_SET; + lock.l_start = 0; + lock.l_len = 0; + lock.l_pid = 0; + if (fcntl(fd, F_SETLKW, &lock) < 0) { + logerror("file lock (fd %d) failed", fd); + return 0; + } + return 1; } int file_unlock(int fd) { - struct flock lock; - - lock.l_type = F_UNLCK; - lock.l_whence = L_SET; - lock.l_start = 0; - lock.l_len = 0; - lock.l_pid = 0; - if (fcntl(fd, F_SETLKW, &lock) < 0) { - logerror("file unlock (fd %d) failed", fd); - return 0; - } - return 1; + struct flock lock; + + lock.l_type = F_UNLCK; + lock.l_whence = L_SET; + lock.l_start = 0; + lock.l_len = 0; + lock.l_pid = 0; + if (fcntl(fd, F_SETLKW, &lock) < 0) { + logerror("file unlock (fd %d) failed", fd); + return 0; + } + return 1; } #endif diff --git a/src/lib/gen/mapdist.c b/src/lib/gen/mapdist.c index f728bc6d7..ab9b5e9ce 100644 --- a/src/lib/gen/mapdist.c +++ b/src/lib/gen/mapdist.c @@ -43,76 +43,76 @@ int diffx(int x1, int x2) { - int dx; + int dx; - dx = x1 - x2; - dx = dx % WORLD_X; - if (dx > WORLD_X/2) - dx = dx - WORLD_X; - if (dx < -WORLD_X/2) - dx = dx + WORLD_X; - return dx; + dx = x1 - x2; + dx = dx % WORLD_X; + if (dx > WORLD_X / 2) + dx = dx - WORLD_X; + if (dx < -WORLD_X / 2) + dx = dx + WORLD_X; + return dx; } int diffy(int y1, int y2) { - int dy; + int dy; - dy = y1 - y2; - dy = dy % WORLD_Y; - if (dy > WORLD_Y/2) - dy = dy - WORLD_Y; - if (dy < -WORLD_Y/2) - dy = dy + WORLD_Y; - return dy; + dy = y1 - y2; + dy = dy % WORLD_Y; + if (dy > WORLD_Y / 2) + dy = dy - WORLD_Y; + if (dy < -WORLD_Y / 2) + dy = dy + WORLD_Y; + return dy; } int deltax(int x1, int x2) { - int dx; + int dx; - dx = abs(x1 - x2); - dx = dx % WORLD_X; - if (dx > WORLD_X/2) - dx = WORLD_X - dx; - return dx; + dx = abs(x1 - x2); + dx = dx % WORLD_X; + if (dx > WORLD_X / 2) + dx = WORLD_X - dx; + return dx; } int deltay(int y1, int y2) { - int dy; + int dy; - dy = abs(y1 - y2); - dy = dy % WORLD_Y; - if (dy > WORLD_Y/2) - dy = WORLD_Y - dy; - return dy; + dy = abs(y1 - y2); + dy = dy % WORLD_Y; + if (dy > WORLD_Y / 2) + dy = WORLD_Y - dy; + return dy; } int mapdist(int x1, int y1, int x2, int y2) { - int dx, dy; + int dx, dy; - x1 = x1 % WORLD_X; - y1 = y1 % WORLD_Y; - x2 = x2 % WORLD_X; - y2 = y2 % WORLD_Y; - dx = deltax(x1, x2); - dy = deltay(y1, y2); - if (dx > dy) - return (dx - dy) / 2 + dy; - return dy; + x1 = x1 % WORLD_X; + y1 = y1 % WORLD_Y; + x2 = x2 % WORLD_X; + y2 = y2 % WORLD_Y; + dx = deltax(x1, x2); + dy = deltay(y1, y2); + if (dx > dy) + return (dx - dy) / 2 + dy; + return dy; } int mapdsq(int x1, int y1, int x2, int y2) { - int sq; + int sq; - sq = mapdist(x1, y1, x2, y2); - return sq * sq; + sq = mapdist(x1, y1, x2, y2); + return sq * sq; } diff --git a/src/lib/gen/minmax.c b/src/lib/gen/minmax.c index ae98726a8..69dab1197 100644 --- a/src/lib/gen/minmax.c +++ b/src/lib/gen/minmax.c @@ -37,35 +37,35 @@ double dmax(double n1, double n2) { - if (n1 > n2) - return n1; - return n2; + if (n1 > n2) + return n1; + return n2; } double dmin(double n1, double n2) { - if (n1 < n2) - return n1; - return n2; + if (n1 < n2) + return n1; + return n2; } #if !defined(_WIN32) int max(int n1, int n2) { - if (n1 > n2) - return n1; - return n2; + if (n1 > n2) + return n1; + return n2; } int min(int n1, int n2) { - if (n1 < n2) - return n1; - return n2; + if (n1 < n2) + return n1; + return n2; } #endif diff --git a/src/lib/gen/numstr.c b/src/lib/gen/numstr.c index b50d4b477..5002f5072 100644 --- a/src/lib/gen/numstr.c +++ b/src/lib/gen/numstr.c @@ -40,35 +40,35 @@ s_char * numstr(s_char *buf, int n) { - extern s_char *numnames[]; - extern s_char *tennames[]; + extern s_char *numnames[]; + extern s_char *tennames[]; - if (n > 100) { - (void) strcpy(buf, "several"); - } else if (n < 0) { - (void) strcpy(buf, "a negative number of"); + if (n > 100) { + (void)strcpy(buf, "several"); + } else if (n < 0) { + (void)strcpy(buf, "a negative number of"); + } else { + if (n >= 20) { + (void)strcpy(buf, tennames[n / 10]); + if (n % 10) { + (void)strcat(buf, "-"); + (void)strcat(buf, numnames[n % 10]); + } } else { - if (n >= 20) { - (void) strcpy(buf, tennames[n / 10]); - if (n % 10) { - (void) strcat(buf, "-"); - (void) strcat(buf, numnames[n % 10]); - } - } else { - (void) strcpy(buf, numnames[n % 20]); - } + (void)strcpy(buf, numnames[n % 20]); } - return buf; + } + return buf; } s_char * effadv(int n) { - extern s_char *effadv_list[]; + extern s_char *effadv_list[]; - if (n < 0) - n = 0; - if (n >= 100) - n = 99; - return effadv_list[n/25]; + if (n < 0) + n = 0; + if (n >= 100) + n = 99; + return effadv_list[n / 25]; } diff --git a/src/lib/gen/onearg.c b/src/lib/gen/onearg.c index 7146b2fbc..b679d2b8a 100644 --- a/src/lib/gen/onearg.c +++ b/src/lib/gen/onearg.c @@ -37,16 +37,16 @@ int onearg(s_char *arg, s_char *prompt) { - extern s_char *getstring(s_char *prompt, s_char *buf); - int n; - s_char buf[1024]; + extern s_char *getstring(s_char *prompt, s_char *buf); + int n; + s_char buf[1024]; - if (arg == 0 || *arg == 0) { - if ((arg = getstring(prompt, buf)) == 0) - return -1; - } - n = atoi(arg); - if (n < 0) - return -1; - return n; + if (arg == 0 || *arg == 0) { + if ((arg = getstring(prompt, buf)) == 0) + return -1; + } + n = atoi(arg); + if (n < 0) + return -1; + return n; } diff --git a/src/lib/gen/parse.c b/src/lib/gen/parse.c index b688564fd..e978b155d 100644 --- a/src/lib/gen/parse.c +++ b/src/lib/gen/parse.c @@ -44,53 +44,54 @@ #include "gen.h" int -parse(register s_char *buf, s_char **argpp, s_char **condp, s_char *space, s_char **redir) +parse(register s_char *buf, s_char **argpp, s_char **condp, s_char *space, + s_char **redir) { - register s_char *bp2; - register s_char *bp1 = space; - register s_char **arg = argpp; - int fs; - int quoted; - int argnum; + register s_char *bp2; + register s_char *bp1 = space; + register s_char **arg = argpp; + int fs; + int quoted; + int argnum; - if (space == 0) - return -1; - if (redir) - *redir = 0; - if (condp != 0) - *condp = 0; - for (argnum=0; *buf && argnum < 100; ) { - arg[argnum] = bp1; - argnum++; - while (isspace(*buf)) - buf++; - if (redir && (*buf == '>' || *buf == '|')) { - *redir = buf; - argnum--; - arg[argnum] = 0; - break; - } - quoted = 0; - for (bp2 = bp1; *buf; ) { - if (!quoted && isspace(*buf)) { - buf++; - break; - } - if (*buf == '"'){ - quoted = !quoted; - buf++; - } else { - *bp1++ = *buf++; - } - } - *bp1++ = 0; - if (*bp2 == '?' && condp != 0) { - *condp = bp2 + 1; - argnum--; - } + if (space == 0) + return -1; + if (redir) + *redir = 0; + if (condp != 0) + *condp = 0; + for (argnum = 0; *buf && argnum < 100;) { + arg[argnum] = bp1; + argnum++; + while (isspace(*buf)) + buf++; + if (redir && (*buf == '>' || *buf == '|')) { + *redir = buf; + argnum--; + arg[argnum] = 0; + break; } - arg[argnum] = 0; - for (fs = argnum + 1; fs < 16; fs++) - arg[fs] = 0; - return argnum; + quoted = 0; + for (bp2 = bp1; *buf;) { + if (!quoted && isspace(*buf)) { + buf++; + break; + } + if (*buf == '"') { + quoted = !quoted; + buf++; + } else { + *bp1++ = *buf++; + } + } + *bp1++ = 0; + if (*bp2 == '?' && condp != 0) { + *condp = bp2 + 1; + argnum--; + } + } + arg[argnum] = 0; + for (fs = argnum + 1; fs < 16; fs++) + arg[fs] = 0; + return argnum; } diff --git a/src/lib/gen/plur.c b/src/lib/gen/plur.c index 97b199422..805b64843 100644 --- a/src/lib/gen/plur.c +++ b/src/lib/gen/plur.c @@ -37,23 +37,23 @@ s_char * plur(int n, s_char *no, s_char *yes) { - return (n == 1 ? no : yes); + return (n == 1 ? no : yes); } s_char * splur(int n) { - return (n == 1 ? "" : "s"); + return (n == 1 ? "" : "s"); } s_char * esplur(int n) { - return (n == 1 ? "" : "es"); + return (n == 1 ? "" : "es"); } s_char * iesplur(int n) { - return (n == 1 ? "y" : "ies"); + return (n == 1 ? "y" : "ies"); } diff --git a/src/lib/gen/queue.c b/src/lib/gen/queue.c index c454ebd0b..ad3988517 100644 --- a/src/lib/gen/queue.c +++ b/src/lib/gen/queue.c @@ -36,30 +36,29 @@ void emp_insque(struct emp_qelem *elem, struct emp_qelem *queue) { - struct emp_qelem *next; + struct emp_qelem *next; - next = queue->q_forw; - queue->q_forw = elem; - elem->q_forw = next; - elem->q_back = queue; - next->q_back = elem; + next = queue->q_forw; + queue->q_forw = elem; + elem->q_forw = next; + elem->q_back = queue; + next->q_back = elem; } void emp_remque(struct emp_qelem *elem) { - if (elem == (struct emp_qelem *)0) - return; - if (elem->q_forw != (struct emp_qelem *)0) - elem->q_forw->q_back = elem->q_back; - if (elem->q_back != (struct emp_qelem *)0) - elem->q_back->q_forw = elem->q_forw; + if (elem == (struct emp_qelem *)0) + return; + if (elem->q_forw != (struct emp_qelem *)0) + elem->q_forw->q_back = elem->q_back; + if (elem->q_back != (struct emp_qelem *)0) + elem->q_back->q_forw = elem->q_forw; } void emp_initque(struct emp_qelem *elem) { - elem->q_forw = elem; - elem->q_back = elem; + elem->q_forw = elem; + elem->q_back = elem; } - diff --git a/src/lib/gen/round.c b/src/lib/gen/round.c index db7116540..1b89e4aa0 100644 --- a/src/lib/gen/round.c +++ b/src/lib/gen/round.c @@ -36,17 +36,17 @@ int roundintby(int n, int m) { - register int r11; + register int r11; - r11 = (m >> 1) + n; - return (r11 / m * m); + r11 = (m >> 1) + n; + return (r11 / m * m); } int ldround(double a4, int ac) { - int f4; + int f4; - f4 = ac / 2.0 + a4; - return (f4 / ac * ac); + f4 = ac / 2.0 + a4; + return (f4 / ac * ac); } diff --git a/src/lib/gen/same.c b/src/lib/gen/same.c index dc4604760..3db1b4bc8 100644 --- a/src/lib/gen/same.c +++ b/src/lib/gen/same.c @@ -37,9 +37,9 @@ int same(register s_char *s1, register s_char *s2) { - while (*s1 == *s2++) { - if (*s1++ == 0) - return 1; - } - return 0; + while (*s1 == *s2++) { + if (*s1++ == 0) + return 1; + } + return 0; } diff --git a/src/lib/gen/scthash.c b/src/lib/gen/scthash.c index 391cf6137..74024a085 100644 --- a/src/lib/gen/scthash.c +++ b/src/lib/gen/scthash.c @@ -36,9 +36,9 @@ int scthash(register int x, register int y, int tsize) { - if (x < 0) - x = -x; - if (y < 0) - y = -y; - return ((x*10 + y) % tsize); + if (x < 0) + x = -x; + if (y < 0) + y = -y; + return ((x * 10 + y) % tsize); } diff --git a/src/lib/gen/signal.c b/src/lib/gen/signal.c index 3dc64ff3a..f5c8a7c1d 100644 --- a/src/lib/gen/signal.c +++ b/src/lib/gen/signal.c @@ -36,13 +36,13 @@ #include "gen.h" #include -u_int mask; +u_int mask; void blocksig(void) { #if !defined(_WIN32) - mask = sigsetmask(0xffffffff); + mask = sigsetmask(0xffffffff); #endif } @@ -50,43 +50,43 @@ void unblocksig(void) { #if !defined(_WIN32) - sigsetmask(mask); + sigsetmask(mask); #endif } #ifdef sys5 const s_char *sys_siglist[] = { - "no signal", - "interrupt", - "quit", - "illegal instruction", - "trace trap", - "IOT instruction", - "system crash imminent", - "floating point exception", - "kill", - "bus error", - "segmentation violation", - "bad argument to system call", - "write on a pipe with no one to read it", - "alarm clock", - "software termination", - "user defined signal 1", - "user defined signal 2", - "death of a child", - "power-fail restart", - "asychronous i/o", - "PTY read/write", - "I/O intervention required", - "monitor mode granted", - "monitor mode retracted", - "sound ack", - "data pending", + "no signal", + "interrupt", + "quit", + "illegal instruction", + "trace trap", + "IOT instruction", + "system crash imminent", + "floating point exception", + "kill", + "bus error", + "segmentation violation", + "bad argument to system call", + "write on a pipe with no one to read it", + "alarm clock", + "software termination", + "user defined signal 1", + "user defined signal 2", + "death of a child", + "power-fail restart", + "asychronous i/o", + "PTY read/write", + "I/O intervention required", + "monitor mode granted", + "monitor mode retracted", + "sound ack", + "data pending", }; #else #if (!defined __ppc__) && (!defined linux) && (!defined FBSD) && (!defined __linux__) /* linux and osx declare sys_siglist in signal.h */ -extern s_char *sys_siglist[]; +extern s_char *sys_siglist[]; #endif /* linux */ #endif /* sys5 */ @@ -94,12 +94,12 @@ const s_char * signame(int sig) { #ifdef POSIX_SIGNALS - if (sig <= 0 || sig > _sys_nsig) - return "bad signal"; - return _sys_siglist[sig]; -#else /* POSIX_SIGNALS */ - if (sig <= 0 || sig > NSIG) - return "bad signal"; - return sys_siglist[sig]; + if (sig <= 0 || sig > _sys_nsig) + return "bad signal"; + return _sys_siglist[sig]; +#else /* POSIX_SIGNALS */ + if (sig <= 0 || sig > NSIG) + return "bad signal"; + return sys_siglist[sig]; #endif /* POSIX_SIGNALS */ } diff --git a/src/lib/gen/strdup.c b/src/lib/gen/strdup.c index 59165b26d..9f5ae17de 100644 --- a/src/lib/gen/strdup.c +++ b/src/lib/gen/strdup.c @@ -36,13 +36,13 @@ #include "gen.h" #ifdef NOSTRDUP -char *strdup(char *x) +char * +strdup(char *x) { - char *y; + char *y; - y=(char *)malloc((sizeof(char)*strlen(x))+1); - strcpy(y,x); - return y; + y = (char *)malloc((sizeof(char) * strlen(x)) + 1); + strcpy(y, x); + return y; } #endif /* NOSTRDUP */ - diff --git a/src/lib/gen/strscan.c b/src/lib/gen/strscan.c index 838571cb8..2e153c2e3 100644 --- a/src/lib/gen/strscan.c +++ b/src/lib/gen/strscan.c @@ -40,18 +40,18 @@ int strscan(s_char *target, s_char *string) { - int i,n,delta; + int i, n, delta; - if ((string == NULL) || (target == NULL)) - return(1); - n = strlen(target); - delta = strlen(string); - if (delta < n) - return(1); - delta -= n; - for (i = 0; i <= delta; i++) { - if (!strncmp(target,&(string[i]),n)) - return(0); - } - return(1); + if ((string == NULL) || (target == NULL)) + return (1); + n = strlen(target); + delta = strlen(string); + if (delta < n) + return (1); + delta -= n; + for (i = 0; i <= delta; i++) { + if (!strncmp(target, &(string[i]), n)) + return (0); + } + return (1); } diff --git a/src/lib/gen/vsprintf.c b/src/lib/gen/vsprintf.c index 858579fea..b7f7a0fd4 100644 --- a/src/lib/gen/vsprintf.c +++ b/src/lib/gen/vsprintf.c @@ -45,7 +45,7 @@ #include "misc.h" #include "gen.h" -#ifdef OSK /* os9/68k can take advantage of both */ +#ifdef OSK /* os9/68k can take advantage of both */ #define LONGINT #define INTSPRINTF #endif @@ -72,7 +72,8 @@ typedef void *pointer; typedef int *intp; -int vsprintf(dest, format, args) +int +vsprintf(dest, format, args) s_char *dest; register s_char *format; va_list args; @@ -86,96 +87,98 @@ va_list args; #endif tempfmt[0] = '%'; - while(c = *format++) { - if(c=='%') { + while (c = *format++) { + if (c == '%') { tp = &tempfmt[1]; #ifndef LONGINT longflag = 0; #endif -continue_format: - switch(c = *format++) { - case 's': - *tp++ = c; - *tp = '\0'; - dp += Sprintf(dp, tempfmt, va_arg(args, s_char *)); - break; - case 'u': - case 'x': - case 'o': - case 'X': + continue_format: + switch (c = *format++) { + case 's': + *tp++ = c; + *tp = '\0'; + dp += Sprintf(dp, tempfmt, va_arg(args, s_char *)); + break; + case 'u': + case 'x': + case 'o': + case 'X': #ifdef UNSIGNEDSPECIAL - *tp++ = c; - *tp = '\0'; + *tp++ = c; + *tp = '\0'; #ifndef LONGINT - if(longflag) - dp += Sprintf(dp, tempfmt, va_arg(args, unsigned long)); - else + if (longflag) + dp += + Sprintf(dp, tempfmt, va_arg(args, unsigned long)); + else #endif - dp += Sprintf(dp, tempfmt, va_arg(args, unsigned)); - break; + dp += Sprintf(dp, tempfmt, va_arg(args, unsigned)); + break; #endif - case 'd': - case 'c': - case 'i': - *tp++ = c; - *tp = '\0'; + case 'd': + case 'c': + case 'i': + *tp++ = c; + *tp = '\0'; #ifndef LONGINT - if(longflag) - dp += Sprintf(dp, tempfmt, va_arg(args, long)); - else + if (longflag) + dp += Sprintf(dp, tempfmt, va_arg(args, long)); + else #endif - dp += Sprintf(dp, tempfmt, va_arg(args, int)); - break; - case 'f': - case 'e': - case 'E': - case 'g': - case 'G': - *tp++ = c; - *tp = '\0'; - dp += Sprintf(dp, tempfmt, va_arg(args, double)); - break; - case 'p': - *tp++ = c; - *tp = '\0'; - dp += Sprintf(dp, tempfmt, va_arg(args, pointer)); - break; - case '-': - case '+': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '.': - case ' ': - case '#': - case 'h': - *tp++ = c; - goto continue_format; - case 'l': + dp += Sprintf(dp, tempfmt, va_arg(args, int)); + break; + case 'f': + case 'e': + case 'E': + case 'g': + case 'G': + *tp++ = c; + *tp = '\0'; + dp += Sprintf(dp, tempfmt, va_arg(args, double)); + break; + case 'p': + *tp++ = c; + *tp = '\0'; + dp += Sprintf(dp, tempfmt, va_arg(args, pointer)); + break; + case '-': + case '+': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '.': + case ' ': + case '#': + case 'h': + *tp++ = c; + goto continue_format; + case 'l': #ifndef LONGINT - longflag = 1; - *tp++ = c; + longflag = 1; + *tp++ = c; #endif - goto continue_format; - case '*': - tp += Sprintf(tp, "%d", va_arg(args, int)); - goto continue_format; - case 'n': - *va_arg(args, intp) = dp - dest; - break; - case '%': - default: - *dp++ = c; - break; + goto continue_format; + case '*': + tp += Sprintf(tp, "%d", va_arg(args, int)); + goto continue_format; + case 'n': + *va_arg(args, intp) = dp - dest; + break; + case '%': + default: + *dp++ = c; + break; } - } else *dp++ = c; + } else + *dp++ = c; } *dp = '\0'; return dp - dest; diff --git a/src/lib/global/constants.c b/src/lib/global/constants.c index a69c920e8..6895d50a9 100644 --- a/src/lib/global/constants.c +++ b/src/lib/global/constants.c @@ -38,54 +38,54 @@ #include "misc.h" #include "xy.h" -s_char *privname = PRVNAM; /* name of priv user */ -s_char *privlog = PRVLOG; /* logname of priv user */ - -int WORLD_X = DEF_WORLD_X; /* World size - x */ -int WORLD_Y = DEF_WORLD_Y; /* World size - y */ - -int MARK_DELAY = 7200; /* Seconds to bid on commodities */ -int TRADE_DELAY = 7200; /* Seconds to bid on units */ - -int m_m_p_d = 1440; /* max mins of play per day (per country) */ -long s_p_etu = DEF_S_P_ETU; /* seconds per Empire time unit */ -int etu_per_update = ETUS; /* # of etu's per update, from misc.h */ -long adj_update = 0; /* update time adjustment */ -int update_window = 0; /* update window adjustment */ -int hourslop = 5; /* amount of slop to match update times */ -s_char *update_times = ""; /* times regular update is allowed */ -int update_policy = 0; /* update policy for regular updates */ -int update_demandpolicy = 2;/* update policy for demand updates */ -int update_missed = 999; /* demand updates missed before veto */ -int update_wantmin = 0; /* number of votes required for demand update */ -int blitz_time = 10; /* number of minutes between blitz updates */ -s_char *update_demandtimes = "";/* times demand update is allowed */ -s_char *game_days = ""; /* days game is running */ -s_char *game_hours = ""; /* hours game is running */ -int max_idle = 15; /* session dies after max_idle minutes idle */ - -int sect_mob_max = 127; /* sector mobility limits */ -float sect_mob_scale = 1.0; /* accumulation multiplier */ -int land_mob_max = 127; /* land mobility limits */ -float land_mob_scale = 1.0; /* accumulation multiplier */ -int ship_mob_max = 127; /* ship mobility limits */ -float ship_mob_scale = 1.5; /* accumulation multiplier */ -int plane_mob_max = 127; /* plane mobility limits */ -float plane_mob_scale = 1.0; /* accumulation multiplier */ - -float fire_range_factor = 1.0;/* Increase/reduce firing ranges */ - -int morale_base = 42; /* base for morale */ +s_char *privname = PRVNAM; /* name of priv user */ +s_char *privlog = PRVLOG; /* logname of priv user */ + +int WORLD_X = DEF_WORLD_X; /* World size - x */ +int WORLD_Y = DEF_WORLD_Y; /* World size - y */ + +int MARK_DELAY = 7200; /* Seconds to bid on commodities */ +int TRADE_DELAY = 7200; /* Seconds to bid on units */ + +int m_m_p_d = 1440; /* max mins of play per day (per country) */ +long s_p_etu = DEF_S_P_ETU; /* seconds per Empire time unit */ +int etu_per_update = ETUS; /* # of etu's per update, from misc.h */ +long adj_update = 0; /* update time adjustment */ +int update_window = 0; /* update window adjustment */ +int hourslop = 5; /* amount of slop to match update times */ +s_char *update_times = ""; /* times regular update is allowed */ +int update_policy = 0; /* update policy for regular updates */ +int update_demandpolicy = 2; /* update policy for demand updates */ +int update_missed = 999; /* demand updates missed before veto */ +int update_wantmin = 0; /* number of votes required for demand update */ +int blitz_time = 10; /* number of minutes between blitz updates */ +s_char *update_demandtimes = ""; /* times demand update is allowed */ +s_char *game_days = ""; /* days game is running */ +s_char *game_hours = ""; /* hours game is running */ +int max_idle = 15; /* session dies after max_idle minutes idle */ + +int sect_mob_max = 127; /* sector mobility limits */ +float sect_mob_scale = 1.0; /* accumulation multiplier */ +int land_mob_max = 127; /* land mobility limits */ +float land_mob_scale = 1.0; /* accumulation multiplier */ +int ship_mob_max = 127; /* ship mobility limits */ +float ship_mob_scale = 1.5; /* accumulation multiplier */ +int plane_mob_max = 127; /* plane mobility limits */ +float plane_mob_scale = 1.0; /* accumulation multiplier */ + +float fire_range_factor = 1.0; /* Increase/reduce firing ranges */ + +int morale_base = 42; /* base for morale */ /* opt_MOB_ACCESS */ -int sect_mob_neg_factor = 2;/* ETU/neg_factor = negative amount of mobility - a sector has after being taken */ -int updating_mob = 1; /* If we are currently updating mob */ -int timestamp_fixing = 0; /* If we are currently fixing timestamps */ +int sect_mob_neg_factor = 2; /* ETU/neg_factor = negative amount of mobility + a sector has after being taken */ +int updating_mob = 1; /* If we are currently updating mob */ +int timestamp_fixing = 0; /* If we are currently fixing timestamps */ -int lost_items_timeout = 172800; /* How long before removing from database */ +int lost_items_timeout = 172800; /* How long before removing from database */ -double combat_mob=5.0; /* how much mob do units spend for combat? */ +double combat_mob = 5.0; /* how much mob do units spend for combat? */ /* if you find that naving is taking too long, try reducing these */ int fort_max_interdiction_range = 8; @@ -94,32 +94,32 @@ int land_max_interdiction_range = 8; double mission_mob_cost = 0.0; /* Cost is percentage of max mob */ -double unit_damage = 0.30; /* Units take this % of normal damage */ -double people_damage = 1.00; /* Civs/Mil/Uw take this % of normal damage */ -double collateral_dam = 0.10; /* Side effect damage to sector */ -double assault_penalty = 0.50; /* attack factor for para & assault troops */ +double unit_damage = 0.30; /* Units take this % of normal damage */ +double people_damage = 1.00; /* Civs/Mil/Uw take this % of normal damage */ +double collateral_dam = 0.10; /* Side effect damage to sector */ +double assault_penalty = 0.50; /* attack factor for para & assault troops */ /* START_UNITS */ #ifdef START_UNITS -int start_unit_type[START_UNITS] = {0, 1}; /* type of unit */ +int start_unit_type[START_UNITS] = { 0, 1 }; /* type of unit */ #endif /* START_UNITS */ /* opt_FUEL */ -int fuel_mult = 10; /* 1 fuel = 10 mob */ +int fuel_mult = 10; /* 1 fuel = 10 mob */ -int land_grow_scale = 2; /* how fast eff grows for land units (xETUS) */ -int ship_grow_scale = 3; /* how fast eff grows for ships (xETUS) */ -int plane_grow_scale = 2; /* how fast eff grows for planes (xETUS) */ +int land_grow_scale = 2; /* how fast eff grows for land units (xETUS) */ +int ship_grow_scale = 3; /* how fast eff grows for ships (xETUS) */ +int plane_grow_scale = 2; /* how fast eff grows for planes (xETUS) */ -double fgrate = 0.0012; /* food growth rate (dt * fert) */ -double fcrate = 0.0013; /* food cultivate rate (dt * workforce) */ -double eatrate = 0.0005; /* food eating rate (dt * people) */ -/*double eatrate = 0.0001;*/ /* food eating rate (dt * people) */ -double babyeat = 0.0060; /* food to mature 1 baby into a civilian */ -/*double babyeat = 0.0000;*/ /* food to mature 1 baby into a civilian */ +double fgrate = 0.0012; /* food growth rate (dt * fert) */ +double fcrate = 0.0013; /* food cultivate rate (dt * workforce) */ +double eatrate = 0.0005; /* food eating rate (dt * people) */ +/*double eatrate = 0.0001;*//* food eating rate (dt * people) */ +double babyeat = 0.0060; /* food to mature 1 baby into a civilian */ +/*double babyeat = 0.0000;*//* food to mature 1 baby into a civilian */ -double obrate = 0.005; /* other sectors birth rate */ -double uwbrate = 0.0025; /* uncompensated worker birth rate */ +double obrate = 0.005; /* other sectors birth rate */ +double uwbrate = 0.0025; /* uncompensated worker birth rate */ /* values > 0.25 for either will overflow */ /* opt_FALLOUT */ @@ -127,12 +127,13 @@ double uwbrate = 0.0025; /* uncompensated worker birth rate */ /* fraction of commodity destroyed is etus*fallout/(1000*melt_item_denom[item]) higher denominators for tougher commodities */ -int melt_item_denom[] = - /* civ mil shell gun pet iron dust bar*/ - { 0, 4, 20, 80, 100,50, 100, 100, 200, - 2, 50, 100,100,2, 1000 }; +int melt_item_denom[] = + /* civ mil shell gun pet iron dust bar */ +{ 0, 4, 20, 80, 100, 50, 100, 100, 200, + 2, 50, 100, 100, 2, 1000 +}; /*food oil lcm hcm UW rads */ -double decay_per_etu = 0.006; /* This gives a half life of ? etus, +double decay_per_etu = 0.006; /* This gives a half life of ? etus, about ? days. half life in Jt log(.5) / log(1-decay_per_etu) @@ -144,11 +145,11 @@ double decay_per_etu = 0.006; /* This gives a half life of ? etus, you can not get a precise number without intensive simulation (more than 3 digits). */ -double fallout_spread = 0.005; /* fraction of fallout that leaks into - each surrounding sector */ +double fallout_spread = 0.005; /* fraction of fallout that leaks into + each surrounding sector */ /* end opt_FALLOUT */ -double bankint = 0.25; /* bank interest rate (dt * bars) */ +double bankint = 0.25; /* bank interest rate (dt * bars) */ /* Note in the taxes below: tradetax - this is charged to the seller, so it is < 1 (because the seller @@ -157,32 +158,32 @@ double bankint = 0.25; /* bank interest rate (dt * bars) */ charged (price paid * buytax). Not perfect, but it works. :) */ -double minmult = 0.5; /* minimum trade mulitple */ -double maxmult = 10.0; /* maximum trade multiple */ -double tradetax = 0.99; /* Tax charged on trade */ -double buytax = 1.0; /* Tax charged on market purchases */ -int startmob = 127; /* Sanctuary starting mobility */ -double flakscale = 1.75; /* Scale factor for flak damage */ +double minmult = 0.5; /* minimum trade mulitple */ +double maxmult = 10.0; /* maximum trade multiple */ +double tradetax = 0.99; /* Tax charged on trade */ +double buytax = 1.0; /* Tax charged on market purchases */ +int startmob = 127; /* Sanctuary starting mobility */ +double flakscale = 1.75; /* Scale factor for flak damage */ /* money gained from taxes, paid to military, and reservists */ -double money_civ = 0.0083333; -double money_uw = 0.0017777; -double money_mil = -0.0833333; -double money_res = -0.0083333; +double money_civ = 0.0083333; +double money_uw = 0.0017777; +double money_mil = -0.0833333; +double money_res = -0.0083333; /* pct cost per ETU for maintaining a ship or plane or land unit */ -double money_plane = -0.001; -double money_ship = -0.001; -double money_land = -0.001; +double money_plane = -0.001; +double money_ship = -0.001; +double money_land = -0.001; /* edu and hap consumption factors -- hap_cons civs need 1 hap --> hlev++ */ -double hap_cons = 600000.0; -double edu_cons = 600000.0; +double hap_cons = 600000.0; +double edu_cons = 600000.0; /* hap and edu avg mean that the weight on current happiness is * (cur_hap * hap_avg + hap_prod * etu) / (hap_avg + etu); */ -float hap_avg = 16.0 * 3.0; -float edu_avg = 16.0 * 12.0; +float hap_avg = 16.0 * 3.0; +float edu_avg = 16.0 * 12.0; /* tech build limitations. Tech limits only apply after easy_tech. @@ -192,49 +193,49 @@ float edu_avg = 16.0 * 12.0; * set hard_tech > 0 to have it take effect * for log based, only tech values where the slop is < 1 are used */ -float easy_tech = 1.00; /* amount of tech built with no penality */ -float hard_tech = 10.0; /* amount of in-efficiently built tech */ -float tech_log_base = 2.0; /* base of log to take of in-efficient tech */ +float easy_tech = 1.00; /* amount of tech built with no penality */ +float hard_tech = 10.0; /* amount of in-efficiently built tech */ +float tech_log_base = 2.0; /* base of log to take of in-efficient tech */ -float ally_factor = 2.0; /* shared tech with allies = 1/factor */ -float level_age_rate = 96.0; /* 1% per 96 etu's; 0 -> no decline */ +float ally_factor = 2.0; /* shared tech with allies = 1/factor */ +float level_age_rate = 96.0; /* 1% per 96 etu's; 0 -> no decline */ -int players_at_00 = 0; /* players coord system on deity 0,0? */ -int at_least_one_100 = 1; /* init player with 100/100/100/100 sector? */ +int players_at_00 = 0; /* players coord system on deity 0,0? */ +int at_least_one_100 = 1; /* init player with 100/100/100/100 sector? */ -float btu_build_rate = 0.0012;/* etu * civ * eff * btu_build_rate */ +float btu_build_rate = 0.0012; /* etu * civ * eff * btu_build_rate */ /* 8 * 999 * 100 * 0.0004 = 319 */ -int max_btus = 640; /* maximum # of btu's */ -double powe_cost = 10.0; /* btu cost to gen a power report */ +int max_btus = 640; /* maximum # of btu's */ +double powe_cost = 10.0; /* btu cost to gen a power report */ -double buil_bt = 10.0; /* tech level required to build a bridge */ -int buil_bh = 100; /* hcm required to build a bridge */ -double buil_bc = 2000.0; /* cash required to build a bridge */ +double buil_bt = 10.0; /* tech level required to build a bridge */ +int buil_bh = 100; /* hcm required to build a bridge */ +double buil_bc = 2000.0; /* cash required to build a bridge */ -double buil_tower_bt = 100.0; /* tech level required to build a tower */ -int buil_tower_bh = 400; /* hcm required to build a bridge tower */ -double buil_tower_bc = 7500.0; /* cash required to build a bridge tower */ +double buil_tower_bt = 100.0; /* tech level required to build a tower */ +int buil_tower_bh = 400; /* hcm required to build a bridge tower */ +double buil_tower_bc = 7500.0; /* cash required to build a bridge tower */ /* opt_SLOW_WAR */ -int War_Cost = 1000; /* Cost to declare war */ +int War_Cost = 1000; /* Cost to declare war */ /* opt_DEMANDUPDATE */ -long last_demand_update=0; /* When was last demand update? */ +long last_demand_update = 0; /* When was last demand update? */ /* opt_DRNUKE */ -float drnuke_const = .33; /* research must be at least drnuke_const*tech*/ +float drnuke_const = .33; /* research must be at least drnuke_const*tech */ /* in order to build a nuke. For example, if * drnuke_const is .25, you need a 75 res to * build a nuke that takes 300 tech */ /* opt_TRADESHIPS */ -int trade_1_dist = 8; /* less than this gets no money */ -int trade_2_dist = 14; /* less than this gets trade_1 money */ -int trade_3_dist = 25; /* less than this gets trade_2 money */ +int trade_1_dist = 8; /* less than this gets no money */ +int trade_2_dist = 14; /* less than this gets trade_1 money */ +int trade_3_dist = 25; /* less than this gets trade_2 money */ float trade_1 = 0.025; /* return on trade_1 distance */ float trade_2 = 0.035; /* return on trade_2 distance */ float trade_3 = 0.050; /* return on trade_3 distance */ @@ -242,7 +243,7 @@ float trade_ally_bonus = 0.20; /* 20% bonus for trading with allies */ float trade_ally_cut = 0.10; /* 10% bonus for ally you trade with */ /* end opt_TRADESHIPS */ -int torpedo_damage = 40; /* damage is X + 1dX + 1dX, so 40+1d40+1d40 */ +int torpedo_damage = 40; /* damage is X + 1dX + 1dX, so 40+1d40+1d40 */ /* initial levels */ float start_education = 0.0; diff --git a/src/lib/global/dir.c b/src/lib/global/dir.c index eef55bce6..44737db84 100644 --- a/src/lib/global/dir.c +++ b/src/lib/global/dir.c @@ -36,36 +36,38 @@ #include "xy.h" /* must agree with DIR_ defines */ -s_char dirch[] = { - 'h', /* stop */ - 'u', /* up-right */ - 'j', /* right */ - 'n', /* down-right */ - 'b', /* down-left */ - 'g', /* left */ - 'y', /* up-left */ - 'v', /* view */ - 'm', /* map */ - '\0', +s_char dirch[] = { + 'h', /* stop */ + 'u', /* up-right */ + 'j', /* right */ + 'n', /* down-right */ + 'b', /* down-left */ + 'g', /* left */ + 'y', /* up-left */ + 'v', /* view */ + 'm', /* map */ + '\0', }; /* must agree with dirch[] and DIR_ defines */ -int diroff[][2] = { - {0,0}, {1,-1}, {2,0}, {1,1}, {-1,1}, {-2,0}, {-1,-1}, {0,0}, {0,0} +int diroff[][2] = { + {0, 0}, {1, -1}, {2, 0}, {1, 1}, {-1, 1}, {-2, 0}, {-1, -1}, {0, 0}, + {0, 0} }; /* this maps a character from a to z into the diroff mappings. It keeps us from having to loop if we don't want to */ int dirindex[] = { 0, 4, 0, 0, 0, 0, 5, 0, 0, 2, 0, 0, 8, - 3, 0, 0, 0, 0, 0, 0, 1, 7, 0, 0, 6, 0 }; + 3, 0, 0, 0, 0, 0, 0, 1, 7, 0, 0, 6, 0 +}; /* must agree with dirch[] and DIR_ defines */ -s_char *routech[7][2] = { - { " ", "$ $" }, - { " /", "$ /" }, - { " >", "$ >" }, - { " \\", "$ \\" }, - { "/ ", "/ $" }, - { "< ", "< $" }, - { "\\ ", "\\ $" } +s_char *routech[7][2] = { + {" ", "$ $"}, + {" /", "$ /"}, + {" >", "$ >"}, + {" \\", "$ \\"}, + {"/ ", "/ $"}, + {"< ", "< $"}, + {"\\ ", "\\ $"} }; diff --git a/src/lib/global/file.c b/src/lib/global/file.c index a00cb9acd..da76d041b 100644 --- a/src/lib/global/file.c +++ b/src/lib/global/file.c @@ -61,46 +61,46 @@ #endif struct empfile empfile[] = { - { "sect", FILEPATH(sector), EFF_COM|EFF_XY|EFF_OWNER, - 0, sizeof(struct sctstr), - 0, 0, 0, { fldoff(sctstr, sct_nv), fldoff(sctstr, sct_vtype[0]), - fldoff(sctstr, sct_vamt[0]) }, MAXSCTV, - -1, -1, 0, 0, 0, 0, 0 }, - { "ship", FILEPATH(ship), EFF_COM|EFF_XY|EFF_OWNER|EFF_GROUP, - 0, sizeof(struct shpstr), - 0, 0, 0, { fldoff(shpstr, shp_nv), fldoff(shpstr, shp_vtype[0]), - fldoff(shpstr, shp_vamt[0]) }, MAXSHPV, - -1, -1, 0, 0, 0, 0, 0 }, - { "plane", FILEPATH(plane), EFF_XY|EFF_OWNER|EFF_GROUP, - 0, sizeof(struct plnstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "land", FILEPATH(land), EFF_COM|EFF_XY|EFF_OWNER|EFF_GROUP, - 0, sizeof(struct lndstr), - 0, 0, 0, { fldoff(lndstr, lnd_nv), fldoff(lndstr, lnd_vtype[0]), - fldoff(lndstr, lnd_vamt[0]) }, MAXLNDV, - -1, -1, 0, 0, 0, 0, 0 }, - { "nuke", FILEPATH(nuke), EFF_XY|EFF_OWNER, 0, sizeof(struct nukstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "news", FILEPATH(news), 0, - 0, sizeof(struct nwsstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "treaty", FILEPATH(treaty), 0, 0, sizeof(struct trtstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "trade", FILEPATH(trade), 0, 0, sizeof(struct trdstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "pow", FILEPATH(power), 0, 0, sizeof(struct powstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "nat", FILEPATH(nation), 0, 0, sizeof(struct natstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "loan", FILEPATH(loan), 0, - 0, sizeof(struct lonstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "map", FILEPATH(map), 0, 0, DEF_WORLD_X*DEF_WORLD_Y/2, - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "bmap", FILEPATH(bmap), 0, 0, DEF_WORLD_X*DEF_WORLD_Y/2, - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "commodity", FILEPATH(commodity),0,0,sizeof(struct comstr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 }, - { "lost", FILEPATH(lostitems), 0, 0, sizeof(struct loststr), - 0, 0, 0, { 0, 0, 0 }, 0, -1, -1, 0, 0, 0, 0, 0 } + {"sect", FILEPATH(sector), EFF_COM | EFF_XY | EFF_OWNER, + 0, sizeof(struct sctstr), + 0, 0, 0, {fldoff(sctstr, sct_nv), fldoff(sctstr, sct_vtype[0]), + fldoff(sctstr, sct_vamt[0])}, MAXSCTV, + -1, -1, 0, 0, 0, 0, 0}, + {"ship", FILEPATH(ship), EFF_COM | EFF_XY | EFF_OWNER | EFF_GROUP, + 0, sizeof(struct shpstr), + 0, 0, 0, {fldoff(shpstr, shp_nv), fldoff(shpstr, shp_vtype[0]), + fldoff(shpstr, shp_vamt[0])}, MAXSHPV, + -1, -1, 0, 0, 0, 0, 0}, + {"plane", FILEPATH(plane), EFF_XY | EFF_OWNER | EFF_GROUP, + 0, sizeof(struct plnstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"land", FILEPATH(land), EFF_COM | EFF_XY | EFF_OWNER | EFF_GROUP, + 0, sizeof(struct lndstr), + 0, 0, 0, {fldoff(lndstr, lnd_nv), fldoff(lndstr, lnd_vtype[0]), + fldoff(lndstr, lnd_vamt[0])}, MAXLNDV, + -1, -1, 0, 0, 0, 0, 0}, + {"nuke", FILEPATH(nuke), EFF_XY | EFF_OWNER, 0, sizeof(struct nukstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"news", FILEPATH(news), 0, + 0, sizeof(struct nwsstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"treaty", FILEPATH(treaty), 0, 0, sizeof(struct trtstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"trade", FILEPATH(trade), 0, 0, sizeof(struct trdstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"pow", FILEPATH(power), 0, 0, sizeof(struct powstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"nat", FILEPATH(nation), 0, 0, sizeof(struct natstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"loan", FILEPATH(loan), 0, + 0, sizeof(struct lonstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"map", FILEPATH(map), 0, 0, DEF_WORLD_X * DEF_WORLD_Y / 2, + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"bmap", FILEPATH(bmap), 0, 0, DEF_WORLD_X * DEF_WORLD_Y / 2, + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"commodity", FILEPATH(commodity), 0, 0, sizeof(struct comstr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0}, + {"lost", FILEPATH(lostitems), 0, 0, sizeof(struct loststr), + 0, 0, 0, {0, 0, 0}, 0, -1, -1, 0, 0, 0, 0, 0} }; diff --git a/src/lib/global/init.c b/src/lib/global/init.c index 240ceb7a7..bc661c906 100644 --- a/src/lib/global/init.c +++ b/src/lib/global/init.c @@ -53,31 +53,31 @@ global_init(void) void init_mchr(void) { - register struct mchrstr *mp; - register int n; + register struct mchrstr *mp; + register int n; - for (mp = mchr, n = 0; n < shp_maxno; n++, mp++) { - if (mp->m_nxlight) - mp->m_flags |= M_XLIGHT; - if (mp->m_nchoppers) - mp->m_flags |= M_CHOPPER; - if (mp->m_nplanes && !(mp->m_flags & M_MSL || mp->m_flags & M_FLY)) - mp->m_flags |= M_MSL; - if (mp->m_nland) - mp->m_flags |= M_UNIT; - } + for (mp = mchr, n = 0; n < shp_maxno; n++, mp++) { + if (mp->m_nxlight) + mp->m_flags |= M_XLIGHT; + if (mp->m_nchoppers) + mp->m_flags |= M_CHOPPER; + if (mp->m_nplanes && !(mp->m_flags & M_MSL || mp->m_flags & M_FLY)) + mp->m_flags |= M_MSL; + if (mp->m_nland) + mp->m_flags |= M_UNIT; + } } void init_plchr(void) { - register struct plchrstr *pp; - int pcount; + register struct plchrstr *pp; + int pcount; - for (pp = plchr, pcount = 0; pcount < pln_maxno; pcount++, pp++) { - if (pp->pl_flags & P_M) - pp->pl_flags |= P_V; - } + for (pp = plchr, pcount = 0; pcount < pln_maxno; pcount++, pp++) { + if (pp->pl_flags & P_M) + pp->pl_flags |= P_V; + } } void diff --git a/src/lib/global/item.c b/src/lib/global/item.c index 13b256612..60924b606 100644 --- a/src/lib/global/item.c +++ b/src/lib/global/item.c @@ -39,25 +39,25 @@ #include "var.h" #include "item.h" -struct ichrstr ichr[I_MAX+2] = { +struct ichrstr ichr[I_MAX + 2] = { /* mnem vtype val sell lbs rg,wh,ur,bnk name */ - { '?', 0, 0, 0, 0, { 0, 0, 0, 0}, "unused" }, + {'?', 0, 0, 0, 0, {0, 0, 0, 0}, "unused"}, /* STM CHANGED HERE */ - { 'c', V_CIVIL, 1, 0, 1, {10,10,10,10}, "civilians" }, - { 'm', V_MILIT, 0, 0, 1, { 1, 1, 1, 1}, "military" }, - { 's', V_SHELL, 5, 1, 1, { 1,10, 1, 1}, "shells" }, - { 'g', V_GUN, 60, 1, 10,{ 1,10, 1, 1}, "guns" }, - { 'p', V_PETROL, 4, 1, 1, { 1,10, 1, 1}, "petrol" }, - { 'i', V_IRON, 2, 1, 1, { 1,10, 1, 1}, "iron ore" }, - { 'd', V_DUST, 20, 1, 5, { 1,10, 1, 1}, "dust (gold)" }, - { 'b', V_BAR, 280, 1, 50,{ 1, 5, 1, 4}, "bars of gold" }, - { 'f', V_FOOD, 0, 1, 1, { 1,10, 1, 1}, "food" }, - { 'o', V_OIL, 8, 1, 1, { 1,10, 1, 1}, "oil" }, - { 'l', V_LCM, 2, 1, 1, { 1,10, 1, 1}, "light products" }, - { 'h', V_HCM, 4, 1, 1, { 1,10, 1, 1}, "heavy products" }, - { 'u', V_UW, 1, 1, 2, { 1, 2, 1, 1}, "uncompensated workers"}, - { 'r', V_RAD, 150, 1, 8, { 1,10, 1, 1}, "radioactive materials"}, - { 0, 0, 0, 0, 0, { 0, 0, 0, 0}, 0 } + {'c', V_CIVIL, 1, 0, 1, {10, 10, 10, 10}, "civilians"}, + {'m', V_MILIT, 0, 0, 1, {1, 1, 1, 1}, "military"}, + {'s', V_SHELL, 5, 1, 1, {1, 10, 1, 1}, "shells"}, + {'g', V_GUN, 60, 1, 10, {1, 10, 1, 1}, "guns"}, + {'p', V_PETROL, 4, 1, 1, {1, 10, 1, 1}, "petrol"}, + {'i', V_IRON, 2, 1, 1, {1, 10, 1, 1}, "iron ore"}, + {'d', V_DUST, 20, 1, 5, {1, 10, 1, 1}, "dust (gold)"}, + {'b', V_BAR, 280, 1, 50, {1, 5, 1, 4}, "bars of gold"}, + {'f', V_FOOD, 0, 1, 1, {1, 10, 1, 1}, "food"}, + {'o', V_OIL, 8, 1, 1, {1, 10, 1, 1}, "oil"}, + {'l', V_LCM, 2, 1, 1, {1, 10, 1, 1}, "light products"}, + {'h', V_HCM, 4, 1, 1, {1, 10, 1, 1}, "heavy products"}, + {'u', V_UW, 1, 1, 2, {1, 2, 1, 1}, "uncompensated workers"}, + {'r', V_RAD, 150, 1, 8, {1, 10, 1, 1}, "radioactive materials"}, + {0, 0, 0, 0, 0, {0, 0, 0, 0}, 0} }; -int itm_maxno = (sizeof(ichr) / sizeof(struct ichrstr)) - 1; +int itm_maxno = (sizeof(ichr) / sizeof(struct ichrstr)) - 1; diff --git a/src/lib/global/land.c b/src/lib/global/land.c index ec6482011..e4d2051db 100644 --- a/src/lib/global/land.c +++ b/src/lib/global/land.c @@ -37,7 +37,7 @@ #include "var.h" #include "land.h" -struct lchrstr lchr[] = { +struct lchrstr lchr[] = { /* name lcm, hcm, mil, gun, shell, tech, $, @@ -47,203 +47,205 @@ struct lchrstr lchr[] = { */ /* ((int)((ETUS*4)/(mil/1000)) is enough food for 3 updates */ -{ 2, - { V_FOOD, V_MILIT }, - { ((int)((ETUS*4)/20)), 20 }, -"cav cavalry", - 10, 5, 0, 0, 0, 30, 500, - 1.2, 0.5, 80, 32, 18, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, - L_RECON|L_LIGHT, - }, + {2, + {V_FOOD, V_MILIT}, + {((int)((ETUS * 4) / 20)), 20}, + "cav cavalry", + 10, 5, 0, 0, 0, 30, 500, + 1.2, 0.5, 80, 32, 18, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, + L_RECON | L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS)/4)), 1, 25 }, -"linf light infantry", - 8, 4, 0, 0, 0, 40, 300, - 1.0, 1.5, 60, 28, 15, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, - L_ASSAULT|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS) / 4)), 1, 25}, + "linf light infantry", + 8, 4, 0, 0, 0, 40, 300, + 1.0, 1.5, 60, 28, 15, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, + L_ASSAULT | L_LIGHT, + }, -{ 2, - { V_FOOD, V_MILIT }, - { ((int)((ETUS*4)/10)), 100 }, -"inf infantry", - 10, 5, 0, 0, 0, 50, 500, - 1.0, 1.5, 60, 25, 15, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - L_ASSAULT|L_LIGHT, -}, + {2, + {V_FOOD, V_MILIT}, + {((int)((ETUS * 4) / 10)), 100}, + "inf infantry", + 10, 5, 0, 0, 0, 50, 500, + 1.0, 1.5, 60, 25, 15, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + L_ASSAULT | L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*5)/5)), 8, 100 }, -"mtif motor inf", - 15, 10, 0, 0, 0, 190, 400, - 1.2, 2.2, 60, 33, 17, 1, 3, 0, 0, 0, 2, 3, 13, 1, 0, 0, - L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 5)), 8, 100}, + "mtif motor inf", + 15, 10, 0, 0, 0, 190, 400, + 1.2, 2.2, 60, 33, 17, 1, 3, 0, 0, 0, 2, 3, 13, 1, 0, 0, + L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*5)/5)), 8, 100 }, -"mif mech inf", - 15, 10, 0, 0, 0, 190, 800, - 1.5, 2.5, 50, 33, 17, 1, 3, 0, 0, 0, 2, 3, 13, 1, 0, 0, - L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 5)), 8, 100}, + "mif mech inf", + 15, 10, 0, 0, 0, 190, 800, + 1.5, 2.5, 50, 33, 17, 1, 3, 0, 0, 0, 2, 3, 13, 1, 0, 0, + L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*5)/5)), 4, 100 }, -"mar marines", - 10, 5, 0, 0, 0, 140,1000, - 1.4, 2.4, 60, 25, 14, 2, 1, 0, 0, 0, 1, 2, 0, 0, 0, 0, - L_MARINE|L_ASSAULT|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 5)), 4, 100}, + "mar marines", + 10, 5, 0, 0, 0, 140, 1000, + 1.4, 2.4, 60, 25, 14, 2, 1, 0, 0, 0, 1, 2, 0, 0, 0, 0, + L_MARINE | L_ASSAULT | L_LIGHT, + }, -{ 10, - { V_SHELL,V_GUN,V_FOOD,V_LCM,V_HCM,V_DUST,V_BAR,V_IRON,V_PETROL,V_MILIT}, - { 200, 10, 300, 200, 100, 100, 10, 100, 300, 25}, -"sup supply", - 10, 5, 0, 0, 0, 50, 500, - 0.1, 0.2, 80, 25, 20, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - L_LIGHT|L_SUPPLY, -}, + {10, + {V_SHELL, V_GUN, V_FOOD, V_LCM, V_HCM, V_DUST, V_BAR, V_IRON, + V_PETROL, V_MILIT}, + {200, 10, 300, 200, 100, 100, 10, 100, 300, 25}, + "sup supply", + 10, 5, 0, 0, 0, 50, 500, + 0.1, 0.2, 80, 25, 20, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + L_LIGHT | L_SUPPLY, + }, -{ 12, - { V_SHELL,V_GUN,V_FOOD,V_LCM,V_HCM,V_DUST,V_BAR,V_IRON,V_PETROL,V_MILIT,V_OIL,V_RAD}, - { 990, 200, 990, 990, 990, 500, 100, 500, 990, 990, 990, 150}, -"tra train", - 100, 50, 0, 0, 0, 40, 3500, - 0.0, 0.0, 120, 10, 25, 3, 0, 0, 0, 0, 0, 0, 0, 0, 5, 12, - L_XLIGHT|L_TRAIN|L_HEAVY|L_SUPPLY, -}, + {12, + {V_SHELL, V_GUN, V_FOOD, V_LCM, V_HCM, V_DUST, V_BAR, V_IRON, + V_PETROL, V_MILIT, V_OIL, V_RAD}, + {990, 200, 990, 990, 990, 500, 100, 500, 990, 990, 990, 150}, + "tra train", + 100, 50, 0, 0, 0, 40, 3500, + 0.0, 0.0, 120, 10, 25, 3, 0, 0, 0, 0, 0, 0, 0, 0, 5, 12, + L_XLIGHT | L_TRAIN | L_HEAVY | L_SUPPLY, + }, -{ 0, - { V_FOOD }, - { 0, }, -"spy infiltrator", - 10, 5, 0, 0, 0, 40, 750, - 0.0, 0.0, 80, 32, 18, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, - L_ASSAULT|L_RECON|L_LIGHT|L_SPY, - }, + {0, + {V_FOOD}, + {0,}, + "spy infiltrator", + 10, 5, 0, 0, 0, 40, 750, + 0.0, 0.0, 80, 32, 18, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, + L_ASSAULT | L_RECON | L_LIGHT | L_SPY, + }, -{ 1, - { V_SHELL }, - { 3, }, -"com commando", - 10, 5, 0, 0, 0, 55, 1500, - 0.0, 0.0, 80, 32, 18, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, - L_ASSAULT|L_RECON|L_LIGHT|L_SPY, - }, + {1, + {V_SHELL}, + {3,}, + "com commando", + 10, 5, 0, 0, 0, 55, 1500, + 0.0, 0.0, 80, 32, 18, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, + L_ASSAULT | L_RECON | L_LIGHT | L_SPY, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS)/5)), 5, 20 }, -"aau aa unit", - 20, 10, 0, 0, 0, 70, 500, - 0.5, 1.0, 60, 18, 20, 1, 1, 0, 0, 0, 1, 2, 0, 0, 0, 0, - L_FLAK|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS) / 5)), 5, 20}, + "aau aa unit", + 20, 10, 0, 0, 0, 70, 500, + 0.5, 1.0, 60, 18, 20, 1, 1, 0, 0, 0, 1, 2, 0, 0, 0, 0, + L_FLAK | L_LIGHT, + }, -{ 4, - { V_FOOD, V_SHELL, V_MILIT, V_GUN}, - { ((int)((ETUS*4)/10)), 40, 25, 10 }, -"art artillery", - 20, 10, 0, 0, 0, 35, 800, - 0.1, 0.4, 70, 18, 20, 1, 0, 8, 50, 5, 2, 1, 0, 0, 0, 0, - L_LIGHT, -}, + {4, + {V_FOOD, V_SHELL, V_MILIT, V_GUN}, + {((int)((ETUS * 4) / 10)), 40, 25, 10}, + "art artillery", + 20, 10, 0, 0, 0, 35, 800, + 0.1, 0.4, 70, 18, 20, 1, 0, 8, 50, 5, 2, 1, 0, 0, 0, 0, + L_LIGHT, + }, -{ 4, - { V_FOOD, V_SHELL, V_MILIT, V_GUN }, - { ((int)((ETUS*4)/20)), 20, 25, 6 }, -"lat lt artillery", - 20, 10, 0, 0, 0, 70, 500, - 0.2, 0.6, 60, 30, 18, 1, 1, 5, 10, 3, 1, 1, 0, 0, 0, 0, - L_LIGHT, -}, + {4, + {V_FOOD, V_SHELL, V_MILIT, V_GUN}, + {((int)((ETUS * 4) / 20)), 20, 25, 6}, + "lat lt artillery", + 20, 10, 0, 0, 0, 70, 500, + 0.2, 0.6, 60, 30, 18, 1, 1, 5, 10, 3, 1, 1, 0, 0, 0, 0, + L_LIGHT, + }, -{ 4, - { V_FOOD, V_SHELL, V_MILIT, V_GUN }, - { ((int)((ETUS*4)/10)), 80, 25, 12 }, -"hat hvy artillery", - 40, 20, 0, 0, 0, 100, 800, - 0.0, 0.2, 60, 12, 20, 1, 0, 11, 99, 8, 4, 1, 0, 0, 0, 0, - 0, -}, + {4, + {V_FOOD, V_SHELL, V_MILIT, V_GUN}, + {((int)((ETUS * 4) / 10)), 80, 25, 12}, + "hat hvy artillery", + 40, 20, 0, 0, 0, 100, 800, + 0.0, 0.2, 60, 12, 20, 1, 0, 11, 99, 8, 4, 1, 0, 0, 0, 0, + 0, + }, -{ 4, - { V_FOOD, V_SHELL, V_MILIT, V_GUN }, - { ((int)((ETUS*5)/20)), 40, 25, 10 }, -"mat mech artillery", - 20, 10, 0, 0, 0, 200, 1000, - 0.2, 0.6, 50, 35, 17, 1, 1, 8, 35, 6, 3, 3, 13, 1, 0, 0, - L_LIGHT, -}, + {4, + {V_FOOD, V_SHELL, V_MILIT, V_GUN}, + {((int)((ETUS * 5) / 20)), 40, 25, 10}, + "mat mech artillery", + 20, 10, 0, 0, 0, 200, 1000, + 0.2, 0.6, 50, 35, 17, 1, 1, 8, 35, 6, 3, 3, 13, 1, 0, 0, + L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*4)/20)), 3, 20}, -"eng engineer", - 10, 5, 0, 0, 0, 130,3000, - 1.2, 2.4, 50, 25, 14, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, - L_ENGINEER|L_ASSAULT|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 4) / 20)), 3, 20}, + "eng engineer", + 10, 5, 0, 0, 0, 130, 3000, + 1.2, 2.4, 50, 25, 14, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, + L_ENGINEER | L_ASSAULT | L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*5)/20)), 4, 20 }, -"meng mech engineer", - 10, 5, 0, 0, 0, 260,4500, - 1.8, 3.5, 45, 33, 15, 3, 3, 0, 0, 0, 1, 5, 25, 2, 0, 0, - L_ENGINEER|L_ASSAULT|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 20)), 4, 20}, + "meng mech engineer", + 10, 5, 0, 0, 0, 260, 4500, + 1.8, 3.5, 45, 33, 15, 3, 3, 0, 0, 0, 1, 5, 25, 2, 0, 0, + L_ENGINEER | L_ASSAULT | L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL,V_MILIT }, - { ((int)((ETUS*5)/10)), 4, 50}, -"lar lt armor", - 10, 5, 0, 0, 0, 150, 600, - 2.0, 1.0, 50, 42, 15, 4, 4, 0, 0, 0, 1, 2, 25, 1, 0, 0, - L_RECON|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 10)), 4, 50}, + "lar lt armor", + 10, 5, 0, 0, 0, 150, 600, + 2.0, 1.0, 50, 42, 15, 4, 4, 0, 0, 0, 1, 2, 25, 1, 0, 0, + L_RECON | L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*4)/5)), 3, 100 }, -"har hvy armor", - 20, 10, 0, 0, 0, 120, 500, - 2.0, 0.8, 50, 18, 17, 1, 1, 0, 0, 0, 2, 1, 10, 2, 0, 0, - 0, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 4) / 5)), 3, 100}, + "har hvy armor", + 20, 10, 0, 0, 0, 120, 500, + 2.0, 0.8, 50, 18, 17, 1, 1, 0, 0, 0, 2, 1, 10, 2, 0, 0, + 0, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT}, - { ((int)((ETUS*5)/10)), 4, 50 }, -"arm armor", - 20, 10, 0, 0, 0, 170,1000, - 3.0, 1.5, 40, 33, 16, 2, 2, 0, 0, 0, 1, 2, 13, 1, 0, 0, - L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 10)), 4, 50}, + "arm armor", + 20, 10, 0, 0, 0, 170, 1000, + 3.0, 1.5, 40, 33, 16, 2, 2, 0, 0, 0, 1, 2, 13, 1, 0, 0, + L_LIGHT, + }, -{ 3, - { V_FOOD, V_SHELL, V_MILIT }, - { ((int)((ETUS*5)/10)), 4, 50 }, -"sec security", - 10, 5, 0, 0, 0, 170, 600, - 1.0, 2.0, 60, 25, 15, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, - L_SECURITY|L_LIGHT, -}, + {3, + {V_FOOD, V_SHELL, V_MILIT}, + {((int)((ETUS * 5) / 10)), 4, 50}, + "sec security", + 10, 5, 0, 0, 0, 170, 600, + 1.0, 2.0, 60, 25, 15, 2, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, + L_SECURITY | L_LIGHT, + }, -{ 2, - { V_FOOD, V_MILIT }, - { ((int)((ETUS*5)/40)), 10 }, -"rad radar unit", - 10, 5, 0, 0, 0, 270,1000, - 0.0, 0.0, 50, 33, 15, 3, 0, 0, 0, 0, 0, 2, 25, 2, 1, 0, - L_XLIGHT|L_RADAR|L_LIGHT, -}, + {2, + {V_FOOD, V_MILIT}, + {((int)((ETUS * 5) / 40)), 10}, + "rad radar unit", + 10, 5, 0, 0, 0, 270, 1000, + 0.0, 0.0, 50, 33, 15, 3, 0, 0, 0, 0, 0, 2, 25, 2, 1, 0, + L_XLIGHT | L_RADAR | L_LIGHT, + }, /* name lcm, hcm, mil, gun, shell, tech, $, @@ -252,15 +254,14 @@ struct lchrstr lchr[] = { cargo */ -{ 0, - { 0 }, - { 0 }, -"", - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, -} + {0, + {0}, + {0}, + "", + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, + } }; -int lnd_maxno = (sizeof(lchr) / sizeof(struct lchrstr)) - 1; - +int lnd_maxno = (sizeof(lchr) / sizeof(struct lchrstr)) - 1; diff --git a/src/lib/global/misc.c b/src/lib/global/misc.c index 616b5a3d7..eee38ced7 100644 --- a/src/lib/global/misc.c +++ b/src/lib/global/misc.c @@ -33,40 +33,41 @@ #include "misc.h" -s_char *effadv_list[] = { - "minimally", "partially", "moderately", "completely", 0, +s_char *effadv_list[] = { + "minimally", "partially", "moderately", "completely", 0, }; /* must follow nation relation defines in nat.h */ -s_char *relates[] = { - "At War", "Sitzkrieg", "Mobilizing", "Hostile", "Neutral", "Friendly", "Allied" +s_char *relates[] = { + "At War", "Sitzkrieg", "Mobilizing", "Hostile", "Neutral", "Friendly", + "Allied" }; /* must follow reject flags defined in nat.h */ -s_char *rejects[] = { - " YES YES YES YES", - " NO YES YES YES", - " YES NO YES YES", - " NO NO YES YES", - " YES YES NO YES", - " NO YES NO YES", - " YES NO NO YES", - " NO NO NO YES", - " YES YES YES NO ", - " NO YES YES NO ", - " YES NO YES NO ", - " NO NO YES NO ", - " YES YES NO NO ", - " NO YES NO NO ", - " YES NO NO NO ", - " NO NO NO NO " +s_char *rejects[] = { + " YES YES YES YES", + " NO YES YES YES", + " YES NO YES YES", + " NO NO YES YES", + " YES YES NO YES", + " NO YES NO YES", + " YES NO NO YES", + " NO NO NO YES", + " YES YES YES NO ", + " NO YES YES NO ", + " YES NO YES NO ", + " NO NO YES NO ", + " YES YES NO NO ", + " NO YES NO NO ", + " YES NO NO NO ", + " NO NO NO NO " }; /* must follow TEL_ defines in tel.h */ -s_char *telnames[] = { - "Telegram", "Announcement", "BULLETIN", "Production Report" +s_char *telnames[] = { + "Telegram", "Announcement", "BULLETIN", "Production Report" }; -s_char *att_mode[] = { - "defend", "attack", "assault", "paradrop", "board", "lboard" +s_char *att_mode[] = { + "defend", "attack", "assault", "paradrop", "board", "lboard" }; diff --git a/src/lib/global/news.c b/src/lib/global/news.c index c65849417..faf153202 100644 --- a/src/lib/global/news.c +++ b/src/lib/global/news.c @@ -41,189 +41,205 @@ #include "misc.h" #include "news.h" -s_char *page_headings[N_MAX_PAGE+1] = { -/* not used */ "Comics", -/* N_FOR */ "Foreign Affairs", -/* N_FRONT */ "The Front Line", -/* N_SEA */ "The High Seas", -/* N_SKY */ "Sky Watch", -/* N_MISS */ "Guidance Systems", -/* N_ARTY */ "Firestorms", -/* N_ECON */ "Business & Economics", -/* N_COLONY */ "The Frontier", -/* N_HOME */ "The Home Front", -/* N_SPY */ "Espionage", -/* N_TELE */ "Telecommunications" +s_char *page_headings[N_MAX_PAGE + 1] = { +/* not used */ "Comics", +/* N_FOR */ "Foreign Affairs", +/* N_FRONT */ "The Front Line", +/* N_SEA */ "The High Seas", +/* N_SKY */ "Sky Watch", +/* N_MISS */ "Guidance Systems", +/* N_ARTY */ "Firestorms", +/* N_ECON */ "Business & Economics", +/* N_COLONY */ "The Frontier", +/* N_HOME */ "The Home Front", +/* N_SPY */ "Espionage", +/* N_TELE */ "Telecommunications" }; -struct rptstr rpt[N_MAX_VERB+1] = { +struct rptstr rpt[N_MAX_VERB + 1] = { /* nice page text -*/{ 0, 0, { "does nothing in particular to %s", -/* 0*/ "does nothing to %s" } }, - { -4, N_FRONT, { "infantry capture %s territory", -/* 1*/ "shock troops overrun one of %s's sectors" } }, - { -4, N_FRONT, { "infantry beaten back by %s troops", -/* 2*/ "shock troops annihilated in failed attack on %s" } }, - { -1, N_SPY, { "spy shot by %s firing squad", -/* 3*/ "spy captured and shot by %s" } }, - { 1, N_TELE, { "sends a telegram to %s", -/* 4*/ "telexes %s" } }, - { 3, N_FOR, { "diplomats sign a treaty with %s", -/* 5*/ "ambassador agrees to a treaty with %s" } }, - { 2, N_ECON, { "bankers make a loan to %s", -/* 6*/ "Ministry of Finance lends money to %s" } }, - { 1, N_ECON, { "repays a loan from %s", -/* 7*/ "makes last payment on loan from %s" } }, - { 0, N_ECON, { "makes a sale to %s", -/* 8*/ "sells goods to %s" } }, - { -1, N_SKY, { "violates %s airspace", -/* 9*/ "overflies %s territory" } }, - { -2, N_ARTY, { "gunners bombard %s territory", -/* 10*/ "artillery fires on %s sectors" } }, - { -2, N_SEA, { "shells a ship owned by %s", -/* 11*/ "fires on %s ships" } }, - { 0, N_FRONT, { "takes over unoccupied land", -/* 12*/ "attacks unowned land for some reason" } }, - { 0, N_SEA, { "ships torpedoed by enemy wolf-packs", -/* 13*/ "ships torpedoed by marauding U-boats" } }, - { 0, N_ARTY, { "gunners fire on %s in self-defense", -/* 14*/ "gunners decimate %s aggressors" } }, - { 0, N_FOR, { "breaks sanctuary", -/* 15*/ "no longer has a sanctuary" } }, - { -2, N_SKY, { "planes divebomb one of %s's sectors", -/* 16*/ "bombers wreak havoc on %s" } }, - { -2, N_SEA, { "divebombs a ship flying the flag of %s", -/* 17*/ "airforce bombs %s ships" } }, - { -2, N_SEA, { "seadogs board one of %s's ships", -/* 18*/ "pirates board %s ship" } }, - { -3, N_SEA, { "is repelled by %s while attempting to board a ship", -/* 19*/ "pirates prove inept at boarding %s's ships" } }, - { -1, N_SKY, { "anti-aircraft gunners fire on %s airforce", -/* 20*/ "attempts to shoot down %s aircraft" } }, - { -2, N_ECON, { "seizes a sector from %s to collect on a loan", -/* 21*/ "collects one of %s's sectors in repayment of a loan" } }, - { -1, N_FOR, { "considers an action which would violate a treaty with %s", -/* 22*/ "decides not to violate treaty with %s (yet)" } }, - { -4, N_FOR, { "violates a treaty with %s", -/* 23*/ "actions violate treaty with %s" } }, - { 0, N_FOR, { "dissolves its government", -/* 24*/ "throws in the towel" } }, - { 0, N_SEA, { "ship hits a mine", -/* 25*/ "ship severely damaged in mine field" } }, - { 5, N_FOR, { "announces an alliance with %s", -/* 26*/ "/ %s alliance declared" } }, - { 0, N_FOR, { "declares their neutrality toward %s", /* no longer used */ -/* 27*/ "announces neutral relations with %s" } }, - { -5, N_FOR, { "declares TOTAL WAR on %s", -/* 28*/ "gets serious with %s and declares WAR" } }, - { 0, N_FOR, { "diplomats disavow former alliance with %s", -/* 29*/ "is no longer allied with %s" } }, - { 5, N_FOR, { "is no longer at war with %s", -/* 30*/ "Foreign Ministry declares \"No more war with %s\"" } }, - { 0, N_HOME, { "reports outbreak of the black plague", -/* 31*/ "sector infected with bubonic plague" } }, - { 0, N_HOME, { "citizens die from bubonic plague", -/* 32*/ "sector reports plague deaths" } }, - { 0, N_FOR, { "goes through a name change", -/* 33*/ "adopts a new country name" } }, - { 0, N_HOME, { "citizens starve in disastrous famine", -/* 34*/ "loses citizens to mass starvation" } }, - { 0, N_HOME, { "endures lawless rioting", -/* 35*/ "suffers from outbreaks of rioting" } }, - { -3, N_SKY, { "pilots down %s planes", -/* 36*/ "victorious in air-to-air combat against %s" } }, - { -10, N_MISS, { "nuclear device devastates %s sector", -/* 37*/ "explodes a nuclear device damaging %s territory" } }, - { 0, N_HOME, { "terrorists shoot it out with %s special forces", -/* 38*/ "underground rises up against %s occupation" } }, - { -2, N_HOME, { "execution squads gun down helpless %s civilians", -/* 39*/ "firing squads massacre defenseless %s workers" } }, - { 0, N_MISS, { "launches a satellite into orbit", -/* 40*/ "continues its conquest of space with a successful launch" } }, - { -8, N_MISS, { "strikes a %s big bird", -/* 41*/ "rockets damage a %s satellite" } }, - { 4, N_ECON, { "makes a contribution to %s", -/* 42*/ "helps out %s" } }, - { 2, N_HOME, { "aids %s with divine intervention", -/* 43*/ "smiles upon %s" } }, - { -3, N_HOME, { "hurts %s with divine intervention", -/* 44*/ "frowns upon %s" } }, - { -4, N_ECON, { "sacrifices to %s", -/* 45*/ "makes divine payment to %s" } }, - { -10, N_MISS, { "abms intercept a %s missile", -/* 46*/ "strategic defense systems destroy a %s missile" } }, - { -2, N_MISS, { "missile fired at one of %s's sectors", -/* 47*/ "missile wreaks havoc on %s" } }, - { -2, N_MISS, { "missile fired at a ship flying the flag of %s", -/* 48*/ "missiles hit %s ships" } }, - { 2, N_ECON, { "engages in friendly trade with %s", -/* 49*/ "profits from a merchant venture with %s" } }, - { 0, N_ECON, { "pirates dispose of %s booty in trade", -/* 50*/ "buccaneers sell their %s goods" } }, - { 0, N_ECON, { "pirates keep their %s booty", -/* 51*/ "buccaneers laugh and bury their %s goods" } }, - { 0, N_SEA, { "ships torpedoed by %s torpedo-boats", -/* 52*/ "ships sunk by marauding %s torpedo-boats" } }, - { 0, N_SEA, { "planes bomb a skulking %s submarine", -/* 53*/ "planes drop depth-charges on a %s sub" } }, - { -2, N_SEA, { "ship is blown up in a failed assault on %s", -/* 54*/ "has a ship destroyed while assaulting %s" } }, - { -2, N_SKY, { "divebombs a brave %s unit", -/* 55*/ "airforce bombs %s units" } }, - { 0, N_FRONT, { "troops run afoul of a landmine", -/* 56*/ "troops severely damaged in mine field" } }, - { -2, N_ARTY, { "fortress gunners support troops attacking %s", -/* 57*/ "fortress artillery massacres %s defenders" } }, - { -2, N_ARTY, { "gunners support troops attacking %s", -/* 58*/ "artillery battery massacres %s defenders" } }, - { -2, N_ARTY, { "naval gunners support troops attacking %s", -/* 59*/ "naval gunfire massacres %s defenders" } }, - {-10, N_FOR, { "sacks %s capital", -/* 60*/ "captures and pillages %s's capital" } }, - { 3, N_FOR, { "announces friendly trade relations with %s", -/* 61*/ "upgrades %s's trade status to triple-A" } }, - { 0, N_FOR, { "downgrades relations with %s to friendly", -/* 62*/ "cools relations with %s to friendly" } }, - { 2, N_FOR, { "upgrades relations with %s to neutral", -/* 63*/ "Foreign Ministry declares \"%s is A-OK.\"" } }, - { 0, N_FOR, { "downgrades relations with %s to neutral", -/* 64*/ "gives the cold shoulder to %s and declares neutral relations" } }, - { 3, N_FOR, { "upgrades relations with %s to hostile", -/* 65*/ "forgives %s of past war crimes but remains hostile" } }, - {-3, N_FOR, { "downgrades relations with %s to hostile", -/* 66*/ "is suspicious that %s has hostile intentions" } }, - { 0, N_MISS, { "sector is struck by a sub-launched missile", -/* 67*/ "sector devastated by missile" } }, - { 0, N_MISS, { "ship is hit by a sub-launched missile", -/* 68*/ "ship damaged by marine missile" } }, - { 0, N_COLONY,{ "pilgrims settle on a new island", -/* 69*/ "discovers new land and starts a colony" } }, - { 0, N_MISS, { "abms intercept an incoming nuclear device", -/* 70*/ "strategic defense systems destroy an incoming nuclear warhead" } }, - {-2, N_MISS, { "missile fired at %s ground troops", -/* 71*/ "missile hits %s troops" } }, - { 0, N_MISS, { "regiment struck by sub-launched missile", -/* 72*/ "ground troops hit by missile" } }, - { -4, N_FRONT, { "navy secures a beachhead on %s territory", -/* 73*/ "sailors take a coastal sector from %s" } }, - { -4, N_FRONT, { "paratroopers comandeer a sector from %s", -/* 74*/ "air force parachutists overwhelm a %s sector" } }, - { 0, N_COLONY,{ "parachutists grab unoccupied land", -/* 75*/ "paratroopers break new ground" } }, - {-4, N_FRONT, { "sailors repelled by %s coast-guard", -/* 76*/ "naval forces massacred in failed assault of %s" } }, - {-4, N_FRONT, { "paratroopers destroyed in failed air-assault on %s", -/* 77*/ "loses parachutists in failed air-assault of %s" } }, - { 0, N_ECON, { "is forced into debt to %s by bad management", -/* 78*/ "shows bad financial planning" } }, - { 0, N_ECON, { "has its credit rating downgraded to unworthy status", -/* 79*/ "is denied credit by %s due to lack of collatoral" } }, - { 0, N_ECON, { "is unable to fulfill its financial obligations to %s", -/* 80*/ "welches on a deal with %s" } }, - { -3, N_FRONT, { "is repelled by %s while attempting to board a land unit", -/* 81*/ "forces prove inept at boarding %s's land unit" } }, - { -2, N_FRONT, { "mercenaries board one of %s's land units", -/* 82*/ "elite forces board %s land unit" } } +*/ {0, 0, {"does nothing in particular to %s", +/* 0*/ "does nothing to %s"}}, + {-4, N_FRONT, {"infantry capture %s territory", +/* 1*/ "shock troops overrun one of %s's sectors"}}, + {-4, N_FRONT, {"infantry beaten back by %s troops", +/* 2*/ + "shock troops annihilated in failed attack on %s"}}, + {-1, N_SPY, {"spy shot by %s firing squad", +/* 3*/ "spy captured and shot by %s"}}, + {1, N_TELE, {"sends a telegram to %s", +/* 4*/ "telexes %s"}}, + {3, N_FOR, {"diplomats sign a treaty with %s", +/* 5*/ "ambassador agrees to a treaty with %s"}}, + {2, N_ECON, {"bankers make a loan to %s", +/* 6*/ "Ministry of Finance lends money to %s"}}, + {1, N_ECON, {"repays a loan from %s", +/* 7*/ "makes last payment on loan from %s"}}, + {0, N_ECON, {"makes a sale to %s", +/* 8*/ "sells goods to %s"}}, + {-1, N_SKY, {"violates %s airspace", +/* 9*/ "overflies %s territory"}}, + {-2, N_ARTY, {"gunners bombard %s territory", +/* 10*/ "artillery fires on %s sectors"}}, + {-2, N_SEA, {"shells a ship owned by %s", +/* 11*/ "fires on %s ships"}}, + {0, N_FRONT, {"takes over unoccupied land", +/* 12*/ "attacks unowned land for some reason"}}, + {0, N_SEA, {"ships torpedoed by enemy wolf-packs", +/* 13*/ "ships torpedoed by marauding U-boats"}}, + {0, N_ARTY, {"gunners fire on %s in self-defense", +/* 14*/ "gunners decimate %s aggressors"}}, + {0, N_FOR, {"breaks sanctuary", +/* 15*/ "no longer has a sanctuary"}}, + {-2, N_SKY, {"planes divebomb one of %s's sectors", +/* 16*/ "bombers wreak havoc on %s"}}, + {-2, N_SEA, {"divebombs a ship flying the flag of %s", +/* 17*/ "airforce bombs %s ships"}}, + {-2, N_SEA, {"seadogs board one of %s's ships", +/* 18*/ "pirates board %s ship"}}, + {-3, N_SEA, {"is repelled by %s while attempting to board a ship", +/* 19*/ "pirates prove inept at boarding %s's ships"}}, + {-1, N_SKY, {"anti-aircraft gunners fire on %s airforce", +/* 20*/ "attempts to shoot down %s aircraft"}}, + {-2, N_ECON, {"seizes a sector from %s to collect on a loan", +/* 21*/ + "collects one of %s's sectors in repayment of a loan"}}, + {-1, N_FOR, + {"considers an action which would violate a treaty with %s", +/* 22*/ "decides not to violate treaty with %s (yet)"}}, + {-4, N_FOR, {"violates a treaty with %s", +/* 23*/ "actions violate treaty with %s"}}, + {0, N_FOR, {"dissolves its government", +/* 24*/ "throws in the towel"}}, + {0, N_SEA, {"ship hits a mine", +/* 25*/ "ship severely damaged in mine field"}}, + {5, N_FOR, {"announces an alliance with %s", +/* 26*/ "/ %s alliance declared"}}, + {0, N_FOR, {"declares their neutrality toward %s", /* no longer used */ +/* 27*/ "announces neutral relations with %s"}}, + {-5, N_FOR, {"declares TOTAL WAR on %s", +/* 28*/ "gets serious with %s and declares WAR"}}, + {0, N_FOR, {"diplomats disavow former alliance with %s", +/* 29*/ "is no longer allied with %s"}}, + {5, N_FOR, {"is no longer at war with %s", +/* 30*/ + "Foreign Ministry declares \"No more war with %s\""}}, + {0, N_HOME, {"reports outbreak of the black plague", +/* 31*/ "sector infected with bubonic plague"}}, + {0, N_HOME, {"citizens die from bubonic plague", +/* 32*/ "sector reports plague deaths"}}, + {0, N_FOR, {"goes through a name change", +/* 33*/ "adopts a new country name"}}, + {0, N_HOME, {"citizens starve in disastrous famine", +/* 34*/ "loses citizens to mass starvation"}}, + {0, N_HOME, {"endures lawless rioting", +/* 35*/ "suffers from outbreaks of rioting"}}, + {-3, N_SKY, {"pilots down %s planes", +/* 36*/ "victorious in air-to-air combat against %s"}}, + {-10, N_MISS, {"nuclear device devastates %s sector", +/* 37*/ + "explodes a nuclear device damaging %s territory"}}, + {0, N_HOME, {"terrorists shoot it out with %s special forces", +/* 38*/ "underground rises up against %s occupation"}}, + {-2, N_HOME, {"execution squads gun down helpless %s civilians", +/* 39*/ + "firing squads massacre defenseless %s workers"}}, + {0, N_MISS, {"launches a satellite into orbit", +/* 40*/ + "continues its conquest of space with a successful launch"}}, + {-8, N_MISS, {"strikes a %s big bird", +/* 41*/ "rockets damage a %s satellite"}}, + {4, N_ECON, {"makes a contribution to %s", +/* 42*/ "helps out %s"}}, + {2, N_HOME, {"aids %s with divine intervention", +/* 43*/ "smiles upon %s"}}, + {-3, N_HOME, {"hurts %s with divine intervention", +/* 44*/ "frowns upon %s"}}, + {-4, N_ECON, {"sacrifices to %s", +/* 45*/ "makes divine payment to %s"}}, + {-10, N_MISS, {"abms intercept a %s missile", +/* 46*/ + "strategic defense systems destroy a %s missile"}}, + {-2, N_MISS, {"missile fired at one of %s's sectors", +/* 47*/ "missile wreaks havoc on %s"}}, + {-2, N_MISS, {"missile fired at a ship flying the flag of %s", +/* 48*/ "missiles hit %s ships"}}, + {2, N_ECON, {"engages in friendly trade with %s", +/* 49*/ "profits from a merchant venture with %s"}}, + {0, N_ECON, {"pirates dispose of %s booty in trade", +/* 50*/ "buccaneers sell their %s goods"}}, + {0, N_ECON, {"pirates keep their %s booty", +/* 51*/ "buccaneers laugh and bury their %s goods"}}, + {0, N_SEA, {"ships torpedoed by %s torpedo-boats", +/* 52*/ "ships sunk by marauding %s torpedo-boats"}}, + {0, N_SEA, {"planes bomb a skulking %s submarine", +/* 53*/ "planes drop depth-charges on a %s sub"}}, + {-2, N_SEA, {"ship is blown up in a failed assault on %s", +/* 54*/ "has a ship destroyed while assaulting %s"}}, + {-2, N_SKY, {"divebombs a brave %s unit", +/* 55*/ "airforce bombs %s units"}}, + {0, N_FRONT, {"troops run afoul of a landmine", +/* 56*/ "troops severely damaged in mine field"}}, + {-2, N_ARTY, {"fortress gunners support troops attacking %s", +/* 57*/ "fortress artillery massacres %s defenders"}}, + {-2, N_ARTY, {"gunners support troops attacking %s", +/* 58*/ "artillery battery massacres %s defenders"}}, + {-2, N_ARTY, {"naval gunners support troops attacking %s", +/* 59*/ "naval gunfire massacres %s defenders"}}, + {-10, N_FOR, {"sacks %s capital", +/* 60*/ "captures and pillages %s's capital"}}, + {3, N_FOR, {"announces friendly trade relations with %s", +/* 61*/ "upgrades %s's trade status to triple-A"}}, + {0, N_FOR, {"downgrades relations with %s to friendly", +/* 62*/ "cools relations with %s to friendly"}}, + {2, N_FOR, {"upgrades relations with %s to neutral", +/* 63*/ "Foreign Ministry declares \"%s is A-OK.\""}}, + {0, N_FOR, {"downgrades relations with %s to neutral", +/* 64*/ + "gives the cold shoulder to %s and declares neutral relations"}}, + {3, N_FOR, {"upgrades relations with %s to hostile", +/* 65*/ + "forgives %s of past war crimes but remains hostile"}}, + {-3, N_FOR, {"downgrades relations with %s to hostile", +/* 66*/ "is suspicious that %s has hostile intentions"}}, + {0, N_MISS, {"sector is struck by a sub-launched missile", +/* 67*/ "sector devastated by missile"}}, + {0, N_MISS, {"ship is hit by a sub-launched missile", +/* 68*/ "ship damaged by marine missile"}}, + {0, N_COLONY, {"pilgrims settle on a new island", +/* 69*/ "discovers new land and starts a colony"}}, + {0, N_MISS, {"abms intercept an incoming nuclear device", +/* 70*/ + "strategic defense systems destroy an incoming nuclear warhead"}}, + {-2, N_MISS, {"missile fired at %s ground troops", +/* 71*/ "missile hits %s troops"}}, + {0, N_MISS, {"regiment struck by sub-launched missile", +/* 72*/ "ground troops hit by missile"}}, + {-4, N_FRONT, {"navy secures a beachhead on %s territory", +/* 73*/ "sailors take a coastal sector from %s"}}, + {-4, N_FRONT, {"paratroopers comandeer a sector from %s", +/* 74*/ + "air force parachutists overwhelm a %s sector"}}, + {0, N_COLONY, {"parachutists grab unoccupied land", +/* 75*/ "paratroopers break new ground"}}, + {-4, N_FRONT, {"sailors repelled by %s coast-guard", +/* 76*/ + "naval forces massacred in failed assault of %s"}}, + {-4, N_FRONT, {"paratroopers destroyed in failed air-assault on %s", +/* 77*/ + "loses parachutists in failed air-assault of %s"}}, + {0, N_ECON, {"is forced into debt to %s by bad management", +/* 78*/ "shows bad financial planning"}}, + {0, N_ECON, {"has its credit rating downgraded to unworthy status", +/* 79*/ + "is denied credit by %s due to lack of collatoral"}}, + {0, N_ECON, {"is unable to fulfill its financial obligations to %s", +/* 80*/ "welches on a deal with %s"}}, + {-3, N_FRONT, + {"is repelled by %s while attempting to board a land unit", +/* 81*/ "forces prove inept at boarding %s's land unit"}}, + {-2, N_FRONT, {"mercenaries board one of %s's land units", +/* 82*/ "elite forces board %s land unit"}} }; -int nws_maxno = (sizeof(rpt) / sizeof(struct rptstr)) - 1; +int nws_maxno = (sizeof(rpt) / sizeof(struct rptstr)) - 1; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index 8dbd3f531..7642ae80c 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -51,89 +51,89 @@ #include "commodity.h" #include "lost.h" -struct castr var_ca[] = { -{ NSC_DEITY | NSC_VAR | V_PSTAGE, "pstage",0,0 }, -{ NSC_DEITY | NSC_VAR | V_PTIME, "ptime",0,0 }, -{ NSC_DEITY | NSC_VAR | V_CHE, "che",0,0 }, -{ NSC_DEITY | NSC_VAR | V_MINE, "lmine",0,0 }, -{ NSC_VAR | V_FALLOUT, "fallout",0,0 }, -{ NSC_ROUND | NSC_VAR | V_CIVIL, "civil",0,0 }, -{ NSC_ROUND | NSC_VAR | V_MILIT, "milit",0,0 }, -{ NSC_ROUND | NSC_VAR | V_SHELL, "shell",0,0 }, -{ NSC_ROUND | NSC_VAR | V_GUN, "gun",0,0 }, -{ NSC_ROUND | NSC_VAR | V_PETROL, "petrol",0,0 }, -{ NSC_ROUND | NSC_VAR | V_IRON, "iron",0,0 }, -{ NSC_ROUND | NSC_VAR | V_DUST, "dust",0,0 }, -{ NSC_ROUND | NSC_VAR | V_BAR, "bar",0,0 }, -{ NSC_ROUND | NSC_VAR | V_FOOD, "food",0,0 }, -{ NSC_ROUND | NSC_VAR | V_OIL, "oil",0,0 }, -{ NSC_ROUND | NSC_VAR | V_LCM, "lcm",0,0 }, -{ NSC_ROUND | NSC_VAR | V_HCM, "hcm",0,0 }, -{ NSC_ROUND | NSC_VAR | V_UW, "uw",0,0 }, -{ NSC_ROUND | NSC_VAR | V_RAD, "rad",0,0 }, -{ NSC_VAR | V_CDIST, "c_dist",0,0 }, -{ NSC_VAR | V_MDIST, "m_dist",0,0 }, -{ NSC_VAR | V_UDIST, "u_dist",0,0 }, -{ NSC_VAR | V_SDIST, "s_dist",0,0 }, -{ NSC_VAR | V_GDIST, "g_dist",0,0 }, -{ NSC_VAR | V_PDIST, "p_dist",0,0 }, -{ NSC_VAR | V_IDIST, "i_dist",0,0 }, -{ NSC_VAR | V_DDIST, "d_dist",0,0 }, -{ NSC_VAR | V_BDIST, "b_dist",0,0 }, -{ NSC_VAR | V_FDIST, "f_dist",0,0 }, -{ NSC_VAR | V_ODIST, "o_dist",0,0 }, -{ NSC_VAR | V_LDIST, "l_dist",0,0 }, -{ NSC_VAR | V_HDIST, "h_dist",0,0 }, -{ NSC_VAR | V_RDIST, "r_dist",0,0 }, -{ NSC_VAR | V_CDEL, "c_del",0,0 }, -{ NSC_VAR | V_MDEL, "m_del",0,0 }, -{ NSC_VAR | V_UDEL, "u_del",0,0 }, -{ NSC_VAR | V_SDEL, "s_del",0,0 }, -{ NSC_VAR | V_GDEL, "g_del",0,0 }, -{ NSC_VAR | V_PDEL, "p_del",0,0 }, -{ NSC_VAR | V_IDEL, "i_del",0,0 }, -{ NSC_VAR | V_DDEL, "d_del",0,0 }, -{ NSC_VAR | V_BDEL, "b_del",0,0 }, -{ NSC_VAR | V_FDEL, "f_del",0,0 }, -{ NSC_VAR | V_ODEL, "o_del",0,0 }, -{ NSC_VAR | V_LDEL, "l_del",0,0 }, -{ NSC_VAR | V_HDEL, "h_del",0,0 }, -{ NSC_VAR | V_RDEL, "r_del",0,0 }, -{ 0, 0, 0,0 } +struct castr var_ca[] = { + {NSC_DEITY | NSC_VAR | V_PSTAGE, "pstage", 0, 0}, + {NSC_DEITY | NSC_VAR | V_PTIME, "ptime", 0, 0}, + {NSC_DEITY | NSC_VAR | V_CHE, "che", 0, 0}, + {NSC_DEITY | NSC_VAR | V_MINE, "lmine", 0, 0}, + {NSC_VAR | V_FALLOUT, "fallout", 0, 0}, + {NSC_ROUND | NSC_VAR | V_CIVIL, "civil", 0, 0}, + {NSC_ROUND | NSC_VAR | V_MILIT, "milit", 0, 0}, + {NSC_ROUND | NSC_VAR | V_SHELL, "shell", 0, 0}, + {NSC_ROUND | NSC_VAR | V_GUN, "gun", 0, 0}, + {NSC_ROUND | NSC_VAR | V_PETROL, "petrol", 0, 0}, + {NSC_ROUND | NSC_VAR | V_IRON, "iron", 0, 0}, + {NSC_ROUND | NSC_VAR | V_DUST, "dust", 0, 0}, + {NSC_ROUND | NSC_VAR | V_BAR, "bar", 0, 0}, + {NSC_ROUND | NSC_VAR | V_FOOD, "food", 0, 0}, + {NSC_ROUND | NSC_VAR | V_OIL, "oil", 0, 0}, + {NSC_ROUND | NSC_VAR | V_LCM, "lcm", 0, 0}, + {NSC_ROUND | NSC_VAR | V_HCM, "hcm", 0, 0}, + {NSC_ROUND | NSC_VAR | V_UW, "uw", 0, 0}, + {NSC_ROUND | NSC_VAR | V_RAD, "rad", 0, 0}, + {NSC_VAR | V_CDIST, "c_dist", 0, 0}, + {NSC_VAR | V_MDIST, "m_dist", 0, 0}, + {NSC_VAR | V_UDIST, "u_dist", 0, 0}, + {NSC_VAR | V_SDIST, "s_dist", 0, 0}, + {NSC_VAR | V_GDIST, "g_dist", 0, 0}, + {NSC_VAR | V_PDIST, "p_dist", 0, 0}, + {NSC_VAR | V_IDIST, "i_dist", 0, 0}, + {NSC_VAR | V_DDIST, "d_dist", 0, 0}, + {NSC_VAR | V_BDIST, "b_dist", 0, 0}, + {NSC_VAR | V_FDIST, "f_dist", 0, 0}, + {NSC_VAR | V_ODIST, "o_dist", 0, 0}, + {NSC_VAR | V_LDIST, "l_dist", 0, 0}, + {NSC_VAR | V_HDIST, "h_dist", 0, 0}, + {NSC_VAR | V_RDIST, "r_dist", 0, 0}, + {NSC_VAR | V_CDEL, "c_del", 0, 0}, + {NSC_VAR | V_MDEL, "m_del", 0, 0}, + {NSC_VAR | V_UDEL, "u_del", 0, 0}, + {NSC_VAR | V_SDEL, "s_del", 0, 0}, + {NSC_VAR | V_GDEL, "g_del", 0, 0}, + {NSC_VAR | V_PDEL, "p_del", 0, 0}, + {NSC_VAR | V_IDEL, "i_del", 0, 0}, + {NSC_VAR | V_DDEL, "d_del", 0, 0}, + {NSC_VAR | V_BDEL, "b_del", 0, 0}, + {NSC_VAR | V_FDEL, "f_del", 0, 0}, + {NSC_VAR | V_ODEL, "o_del", 0, 0}, + {NSC_VAR | V_LDEL, "l_del", 0, 0}, + {NSC_VAR | V_HDEL, "h_del", 0, 0}, + {NSC_VAR | V_RDEL, "r_del", 0, 0}, + {0, 0, 0, 0} }; -struct castr sect_ca[] = { +struct castr sect_ca[] = { #ifndef apollo -{ NSC_UCHAR|fldoff(sctstr, sct_own),"owner",0,0 }, -{ NSC_XCOORD|fldoff(sctstr, sct_x), "xloc",0,0 }, -{ NSC_YCOORD|fldoff(sctstr, sct_y), "yloc",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_type), "des",0,0 }, -{ NSC_ROUND|NSC_UCHAR|fldoff(sctstr, sct_effic), "effic",0,0 }, -{ NSC_SHORT|fldoff(sctstr, sct_mobil), "mobil",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_terr), "terr",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_terr), "terr0",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_terr1), "terr1",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_terr2), "terr2",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_terr3), "terr3",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_work), "work",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_coastal), "coastal",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_newtype), "newdes",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_min), "min",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_gmin), "gold",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_fertil), "fert",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_oil), "ocontent",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_uran), "uran",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_oldown), "oldown",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_off), "off",0,0 }, -{ NSC_XCOORD|fldoff(sctstr, sct_dist_x), "xdist",0,0 }, -{ NSC_YCOORD|fldoff(sctstr, sct_dist_y), "ydist",0,0 }, -{ NSC_SHORT|fldoff(sctstr, sct_avail), "avail",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_road), "road",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_rail), "rail",0,0 }, -{ NSC_UCHAR|fldoff(sctstr, sct_defense), "dfense",0,0 }, -{ NSC_TIME|fldoff(sctstr, sct_timestamp), "timestamp",0,0 }, + {NSC_UCHAR | fldoff(sctstr, sct_own), "owner", 0, 0}, + {NSC_XCOORD | fldoff(sctstr, sct_x), "xloc", 0, 0}, + {NSC_YCOORD | fldoff(sctstr, sct_y), "yloc", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_type), "des", 0, 0}, + {NSC_ROUND | NSC_UCHAR | fldoff(sctstr, sct_effic), "effic", 0, 0}, + {NSC_SHORT | fldoff(sctstr, sct_mobil), "mobil", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_terr), "terr", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_terr), "terr0", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_terr1), "terr1", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_terr2), "terr2", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_terr3), "terr3", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_work), "work", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_coastal), "coastal", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_newtype), "newdes", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_min), "min", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_gmin), "gold", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_fertil), "fert", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_oil), "ocontent", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_uran), "uran", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_oldown), "oldown", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_off), "off", 0, 0}, + {NSC_XCOORD | fldoff(sctstr, sct_dist_x), "xdist", 0, 0}, + {NSC_YCOORD | fldoff(sctstr, sct_dist_y), "ydist", 0, 0}, + {NSC_SHORT | fldoff(sctstr, sct_avail), "avail", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_road), "road", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_rail), "rail", 0, 0}, + {NSC_UCHAR | fldoff(sctstr, sct_defense), "dfense", 0, 0}, + {NSC_TIME | fldoff(sctstr, sct_timestamp), "timestamp", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; #define NSC_GENITEM \ @@ -151,220 +151,219 @@ struct castr sect_ca[] = { { NSC_YCOORD | fldoff(genitem, opy), "opy",0,0 },\ { NSC_SHORT | fldoff(genitem, mission), "mission",0,0 } -struct castr genitem_ca[] = { +struct castr genitem_ca[] = { #ifndef apollo -NSC_GENITEM, + NSC_GENITEM, #endif -{0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr ship_ca[] = { +struct castr ship_ca[] = { #ifndef apollo -NSC_GENITEM, -{ NSC_CHAR | fldoff(shpstr, shp_fleet), "fleet",0,0 }, -{ NSC_CHAR | fldoff(shpstr, shp_nplane), "nplane",0,0 }, -{ NSC_TIME | fldoff(shpstr, shp_timestamp), "timestamp",0,0 }, -{ NSC_UCHAR | fldoff(shpstr, shp_fuel), "fuel",0,0 }, -{ NSC_UCHAR | fldoff(shpstr, shp_nxlight), "nxlight",0,0 }, -{ NSC_UCHAR | fldoff(shpstr, shp_nchoppers), "nchoppers",0,0 }, -{ NSC_UCHAR | fldoff(shpstr, shp_autonav), "autonav",0,0 }, + NSC_GENITEM, + {NSC_CHAR | fldoff(shpstr, shp_fleet), "fleet", 0, 0}, + {NSC_CHAR | fldoff(shpstr, shp_nplane), "nplane", 0, 0}, + {NSC_TIME | fldoff(shpstr, shp_timestamp), "timestamp", 0, 0}, + {NSC_UCHAR | fldoff(shpstr, shp_fuel), "fuel", 0, 0}, + {NSC_UCHAR | fldoff(shpstr, shp_nxlight), "nxlight", 0, 0}, + {NSC_UCHAR | fldoff(shpstr, shp_nchoppers), "nchoppers", 0, 0}, + {NSC_UCHAR | fldoff(shpstr, shp_autonav), "autonav", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr plane_ca[] = { +struct castr plane_ca[] = { #ifndef apollo -NSC_GENITEM, -{ NSC_UCHAR | fldoff(plnstr, pln_wing), "wing",0,0 }, -{ NSC_UCHAR | fldoff(plnstr, pln_range), "range",0,0 }, -{ NSC_SHORT | fldoff(plnstr, pln_ship), "ship",0,0 }, -{ NSC_UCHAR | fldoff(plnstr, pln_att), "att",0,0 }, -{ NSC_UCHAR | fldoff(plnstr, pln_def), "def",0,0 }, -{ NSC_UCHAR | fldoff(plnstr, pln_harden), "harden",0,0 }, -{ NSC_UCHAR | fldoff(plnstr, pln_nuketype), "nuketype",0,0 }, -{ NSC_UCHAR | fldoff(plnstr, pln_flags), "flags",0,0 }, -{ NSC_SHORT | fldoff(plnstr, pln_land), "land",0,0 }, -{ NSC_TIME | fldoff(plnstr, pln_timestamp), "timestamp",0,0 }, + NSC_GENITEM, + {NSC_UCHAR | fldoff(plnstr, pln_wing), "wing", 0, 0}, + {NSC_UCHAR | fldoff(plnstr, pln_range), "range", 0, 0}, + {NSC_SHORT | fldoff(plnstr, pln_ship), "ship", 0, 0}, + {NSC_UCHAR | fldoff(plnstr, pln_att), "att", 0, 0}, + {NSC_UCHAR | fldoff(plnstr, pln_def), "def", 0, 0}, + {NSC_UCHAR | fldoff(plnstr, pln_harden), "harden", 0, 0}, + {NSC_UCHAR | fldoff(plnstr, pln_nuketype), "nuketype", 0, 0}, + {NSC_UCHAR | fldoff(plnstr, pln_flags), "flags", 0, 0}, + {NSC_SHORT | fldoff(plnstr, pln_land), "land", 0, 0}, + {NSC_TIME | fldoff(plnstr, pln_timestamp), "timestamp", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr land_ca[] = { +struct castr land_ca[] = { #ifndef apollo -NSC_GENITEM, -{ NSC_CHAR | fldoff(lndstr, lnd_army), "army",0,0 }, -{ NSC_SHORT | fldoff(lndstr, lnd_ship), "ship",0,0 }, -{ NSC_SHORT | fldoff(lndstr, lnd_land), "land",0,0 }, -{ NSC_CHAR | fldoff(lndstr, lnd_harden), "harden",0,0 }, -{ NSC_SHORT | fldoff(lndstr, lnd_retreat), "retreat",0,0 }, -{ NSC_UCHAR | fldoff(lndstr, lnd_fuel), "fuel",0,0 }, -{ NSC_UCHAR | fldoff(lndstr, lnd_nxlight), "nxlight",0,0 }, -{ NSC_FLOAT | fldoff(lndstr, lnd_att), "att",0,0 }, -{ NSC_FLOAT | fldoff(lndstr, lnd_def), "def",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_vul), "vul",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_spd), "spd",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_vis), "vis",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_spy), "spy",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_rad), "rad",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_frg), "frg",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_acc), "acc",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_dam), "dam",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_ammo), "ammo",0,0 }, -{ NSC_INT | fldoff(lndstr, lnd_aaf), "aaf",0,0 }, -{ NSC_UCHAR | fldoff(lndstr, lnd_fuelc), "fuelc",0,0 }, -{ NSC_UCHAR | fldoff(lndstr, lnd_fuelu), "fuelu",0,0 }, -{ NSC_UCHAR | fldoff(lndstr, lnd_maxlight), "maxlight",0,0 }, -{ NSC_TIME | fldoff(lndstr, lnd_timestamp), "timestamp",0,0 }, + NSC_GENITEM, + {NSC_CHAR | fldoff(lndstr, lnd_army), "army", 0, 0}, + {NSC_SHORT | fldoff(lndstr, lnd_ship), "ship", 0, 0}, + {NSC_SHORT | fldoff(lndstr, lnd_land), "land", 0, 0}, + {NSC_CHAR | fldoff(lndstr, lnd_harden), "harden", 0, 0}, + {NSC_SHORT | fldoff(lndstr, lnd_retreat), "retreat", 0, 0}, + {NSC_UCHAR | fldoff(lndstr, lnd_fuel), "fuel", 0, 0}, + {NSC_UCHAR | fldoff(lndstr, lnd_nxlight), "nxlight", 0, 0}, + {NSC_FLOAT | fldoff(lndstr, lnd_att), "att", 0, 0}, + {NSC_FLOAT | fldoff(lndstr, lnd_def), "def", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_vul), "vul", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_spd), "spd", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_vis), "vis", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_spy), "spy", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_rad), "rad", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_frg), "frg", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_acc), "acc", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_dam), "dam", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_ammo), "ammo", 0, 0}, + {NSC_INT | fldoff(lndstr, lnd_aaf), "aaf", 0, 0}, + {NSC_UCHAR | fldoff(lndstr, lnd_fuelc), "fuelc", 0, 0}, + {NSC_UCHAR | fldoff(lndstr, lnd_fuelu), "fuelu", 0, 0}, + {NSC_UCHAR | fldoff(lndstr, lnd_maxlight), "maxlight", 0, 0}, + {NSC_TIME | fldoff(lndstr, lnd_timestamp), "timestamp", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr nuke_ca[] = { +struct castr nuke_ca[] = { #ifndef apollo -{ NSC_UCHAR | fldoff(nukstr, nuk_own), "owner",0,0 }, -{ NSC_SHORT | fldoff(nukstr, nuk_uid), "uid",0,0 }, -{ NSC_XCOORD | fldoff(nukstr, nuk_x), "xloc",0,0 }, -{ NSC_YCOORD | fldoff(nukstr, nuk_y), "yloc",0,0 }, -{ NSC_CHAR | fldoff(nukstr, nuk_n), "number",0,0 }, + {NSC_UCHAR | fldoff(nukstr, nuk_own), "owner", 0, 0}, + {NSC_SHORT | fldoff(nukstr, nuk_uid), "uid", 0, 0}, + {NSC_XCOORD | fldoff(nukstr, nuk_x), "xloc", 0, 0}, + {NSC_YCOORD | fldoff(nukstr, nuk_y), "yloc", 0, 0}, + {NSC_CHAR | fldoff(nukstr, nuk_n), "number", 0, 0}, #if !defined(_WIN32) -{ NSC_CHAR | fldoff(nukstr, nuk_types[0]),"types",N_MAXNUKE,0 }, + {NSC_CHAR | fldoff(nukstr, nuk_types[0]), "types", N_MAXNUKE, 0}, #else -{ NSC_CHAR | fldoff(nukstr, nuk_types),"types",N_MAXNUKE,0 }, + {NSC_CHAR | fldoff(nukstr, nuk_types), "types", N_MAXNUKE, 0}, #endif -{ NSC_TIME | fldoff(nukstr, nuk_timestamp), "timestamp",0,0 }, + {NSC_TIME | fldoff(nukstr, nuk_timestamp), "timestamp", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr treaty_ca[] = { +struct castr treaty_ca[] = { #ifndef apollo -{ NSC_UCHAR | fldoff(trtstr, trt_cna), "cna",0,0 }, -{ NSC_UCHAR | fldoff(trtstr, trt_cnb), "cnb",0,0 }, -{ NSC_UCHAR | fldoff(trtstr, trt_status), "status",0,0 }, -{ NSC_SHORT | fldoff(trtstr, trt_acond), "acond",0,0 }, -{ NSC_SHORT | fldoff(trtstr, trt_bcond), "bcond",0,0 }, -{ NSC_LONG | fldoff(trtstr, trt_exp), "exp",0,0 }, + {NSC_UCHAR | fldoff(trtstr, trt_cna), "cna", 0, 0}, + {NSC_UCHAR | fldoff(trtstr, trt_cnb), "cnb", 0, 0}, + {NSC_UCHAR | fldoff(trtstr, trt_status), "status", 0, 0}, + {NSC_SHORT | fldoff(trtstr, trt_acond), "acond", 0, 0}, + {NSC_SHORT | fldoff(trtstr, trt_bcond), "bcond", 0, 0}, + {NSC_LONG | fldoff(trtstr, trt_exp), "exp", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr loan_ca[] = { +struct castr loan_ca[] = { #ifndef apollo -{ NSC_UCHAR | fldoff(lonstr, l_loner), "loaner",0,0 }, -{ NSC_SHORT | fldoff(lonstr, l_uid), "uid", 0, 0 }, -{ NSC_UCHAR | fldoff(lonstr, l_lonee), "loanee",0,0 }, -{ NSC_CHAR | fldoff(lonstr, l_status), "status",0,0 }, -{ NSC_SHORT | fldoff(lonstr, l_sell), "sell",0,0 }, -{ NSC_INT | fldoff(lonstr, l_irate), "irate",0,0 }, -{ NSC_INT | fldoff(lonstr, l_ldur), "ldur",0,0 }, -{ NSC_LONG | fldoff(lonstr, l_amtpaid), "amtpaid",0,0 }, -{ NSC_LONG | fldoff(lonstr, l_amtdue), "amtdue",0,0 }, -{ NSC_TIME | fldoff(lonstr, l_lastpay), "lastpay",0,0 }, -{ NSC_TIME | fldoff(lonstr, l_duedate), "duedate",0,0 }, + {NSC_UCHAR | fldoff(lonstr, l_loner), "loaner", 0, 0}, + {NSC_SHORT | fldoff(lonstr, l_uid), "uid", 0, 0}, + {NSC_UCHAR | fldoff(lonstr, l_lonee), "loanee", 0, 0}, + {NSC_CHAR | fldoff(lonstr, l_status), "status", 0, 0}, + {NSC_SHORT | fldoff(lonstr, l_sell), "sell", 0, 0}, + {NSC_INT | fldoff(lonstr, l_irate), "irate", 0, 0}, + {NSC_INT | fldoff(lonstr, l_ldur), "ldur", 0, 0}, + {NSC_LONG | fldoff(lonstr, l_amtpaid), "amtpaid", 0, 0}, + {NSC_LONG | fldoff(lonstr, l_amtdue), "amtdue", 0, 0}, + {NSC_TIME | fldoff(lonstr, l_lastpay), "lastpay", 0, 0}, + {NSC_TIME | fldoff(lonstr, l_duedate), "duedate", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr news_ca[] = { +struct castr news_ca[] = { #ifndef apollo -{ NSC_CHAR | fldoff(nwsstr, nws_ano), "actor",0,0 }, -{ NSC_CHAR | fldoff(nwsstr, nws_vrb), "action",0,0 }, -{ NSC_CHAR | fldoff(nwsstr, nws_vno), "victim",0,0 }, -{ NSC_CHAR | fldoff(nwsstr, nws_ntm), "times",0,0 }, -{ NSC_LONG | fldoff(nwsstr, nws_when), "time",0,0 }, + {NSC_CHAR | fldoff(nwsstr, nws_ano), "actor", 0, 0}, + {NSC_CHAR | fldoff(nwsstr, nws_vrb), "action", 0, 0}, + {NSC_CHAR | fldoff(nwsstr, nws_vno), "victim", 0, 0}, + {NSC_CHAR | fldoff(nwsstr, nws_ntm), "times", 0, 0}, + {NSC_LONG | fldoff(nwsstr, nws_when), "time", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; struct castr lost_ca[] = { -{ NSC_UCHAR | fldoff(loststr, lost_owner), "owner", 0, 0 }, -{ NSC_INT | fldoff(loststr, lost_uid), "uid", 0, 0 }, -{ NSC_UCHAR | fldoff(loststr, lost_type), "type", 0, 0 }, -{ NSC_XCOORD | fldoff(loststr, lost_x), "x", 0, 0 }, -{ NSC_YCOORD | fldoff(loststr, lost_y), "y", 0, 0 }, -{ NSC_TIME | fldoff(loststr, lost_timestamp), "timestamp", 0, 0 }, -{ 0, 0, 0, 0 } + {NSC_UCHAR | fldoff(loststr, lost_owner), "owner", 0, 0}, + {NSC_INT | fldoff(loststr, lost_uid), "uid", 0, 0}, + {NSC_UCHAR | fldoff(loststr, lost_type), "type", 0, 0}, + {NSC_XCOORD | fldoff(loststr, lost_x), "x", 0, 0}, + {NSC_YCOORD | fldoff(loststr, lost_y), "y", 0, 0}, + {NSC_TIME | fldoff(loststr, lost_timestamp), "timestamp", 0, 0}, + {0, 0, 0, 0} }; -struct castr commodity_ca[] = { -{ NSC_UCHAR | fldoff(comstr, com_owner), "owner",0,0 }, -{ NSC_SHORT | fldoff(comstr, com_uid), "uid",0,0 }, -{ NSC_UCHAR | fldoff(comstr, com_type), "type",0,0 }, -{ NSC_INT | fldoff(comstr, com_amount), "amount",0,0 }, -{ NSC_FLOAT | fldoff(comstr, com_price), "price",0,0 }, -{ NSC_INT | fldoff(comstr, com_maxbidder), "maxbidder",0,0 }, -{ NSC_FLOAT | fldoff(comstr, com_maxprice), "maxprice",0,0 }, -{ NSC_TIME | fldoff(comstr, com_markettime), "markettime",0,0 }, -{ NSC_INT | fldoff(comstr, com_x), "xloc",0,0 }, -{ NSC_INT | fldoff(comstr, com_y), "yloc",0,0 }, -{ NSC_XCOORD | fldoff(comstr, sell_x), "xsell",0,0 }, -{ NSC_YCOORD | fldoff(comstr, sell_y), "ysell",0,0 }, -{ 0, 0, 0,0 } +struct castr commodity_ca[] = { + {NSC_UCHAR | fldoff(comstr, com_owner), "owner", 0, 0}, + {NSC_SHORT | fldoff(comstr, com_uid), "uid", 0, 0}, + {NSC_UCHAR | fldoff(comstr, com_type), "type", 0, 0}, + {NSC_INT | fldoff(comstr, com_amount), "amount", 0, 0}, + {NSC_FLOAT | fldoff(comstr, com_price), "price", 0, 0}, + {NSC_INT | fldoff(comstr, com_maxbidder), "maxbidder", 0, 0}, + {NSC_FLOAT | fldoff(comstr, com_maxprice), "maxprice", 0, 0}, + {NSC_TIME | fldoff(comstr, com_markettime), "markettime", 0, 0}, + {NSC_INT | fldoff(comstr, com_x), "xloc", 0, 0}, + {NSC_INT | fldoff(comstr, com_y), "yloc", 0, 0}, + {NSC_XCOORD | fldoff(comstr, sell_x), "xsell", 0, 0}, + {NSC_YCOORD | fldoff(comstr, sell_y), "ysell", 0, 0}, + {0, 0, 0, 0} }; -struct castr trade_ca[] = { +struct castr trade_ca[] = { #ifndef apollo -{ NSC_UCHAR | fldoff(trdstr, trd_owner), "owner",0,0 }, -{ NSC_SHORT | fldoff(trdstr, trd_uid), "uid", 0, 0 }, -{ NSC_UCHAR | fldoff(trdstr, trd_type), "type",0,0 }, -{ NSC_SHORT | fldoff(trdstr, trd_unitid), "unitid",0,0 }, -{ NSC_LONG | fldoff(trdstr, trd_price), "price",0,0 }, -{ NSC_INT | fldoff(trdstr, trd_maxbidder), "maxbidder",0,0 }, -{ NSC_INT | fldoff(trdstr, trd_maxprice), "maxprice",0,0 }, -{ NSC_TIME | fldoff(trdstr, trd_markettime), "markettime",0,0 }, -{ NSC_XCOORD | fldoff(trdstr, trd_x), "xloc",0,0 }, -{ NSC_YCOORD | fldoff(trdstr, trd_y), "yloc",0,0 }, + {NSC_UCHAR | fldoff(trdstr, trd_owner), "owner", 0, 0}, + {NSC_SHORT | fldoff(trdstr, trd_uid), "uid", 0, 0}, + {NSC_UCHAR | fldoff(trdstr, trd_type), "type", 0, 0}, + {NSC_SHORT | fldoff(trdstr, trd_unitid), "unitid", 0, 0}, + {NSC_LONG | fldoff(trdstr, trd_price), "price", 0, 0}, + {NSC_INT | fldoff(trdstr, trd_maxbidder), "maxbidder", 0, 0}, + {NSC_INT | fldoff(trdstr, trd_maxprice), "maxprice", 0, 0}, + {NSC_TIME | fldoff(trdstr, trd_markettime), "markettime", 0, 0}, + {NSC_XCOORD | fldoff(trdstr, trd_x), "xloc", 0, 0}, + {NSC_YCOORD | fldoff(trdstr, trd_y), "yloc", 0, 0}, #endif -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr nat_ca[] = { -{ NSC_UCHAR | fldoff(natstr, nat_cnum),"cnum",0,0 }, +struct castr nat_ca[] = { + {NSC_UCHAR | fldoff(natstr, nat_cnum), "cnum", 0, 0}, #if !defined(_WIN32) -{ NSC_CHAR | fldoff(natstr, nat_cnam[0]),"cnam",20,0 }, -{ NSC_DEITY | NSC_CHAR | fldoff(natstr, nat_pnam[0]),"pnam",20,0 }, + {NSC_CHAR | fldoff(natstr, nat_cnam[0]), "cnam", 20, 0}, + {NSC_DEITY | NSC_CHAR | fldoff(natstr, nat_pnam[0]), "pnam", 20, 0}, #else -{ NSC_CHAR | fldoff(natstr, nat_cnam),"cnam",20,0 }, -{ NSC_DEITY | NSC_CHAR | fldoff(natstr, nat_pnam),"pnam",20,0 }, + {NSC_CHAR | fldoff(natstr, nat_cnam), "cnam", 20, 0}, + {NSC_DEITY | NSC_CHAR | fldoff(natstr, nat_pnam), "pnam", 20, 0}, #endif -{ NSC_XCOORD | fldoff(natstr, nat_xstart),"xstart",0,0 }, -{ NSC_YCOORD | fldoff(natstr, nat_ystart),"ystart",0,0 }, -{ NSC_XCOORD | fldoff(natstr, nat_xcap),"xcap",0,0 }, -{ NSC_YCOORD | fldoff(natstr, nat_ycap),"ycap",0,0 }, -{ NSC_DEITY | NSC_XCOORD | fldoff(natstr, nat_xorg),"xorg",0,0 }, -{ NSC_DEITY | NSC_YCOORD | fldoff(natstr, nat_yorg),"yorg",0,0 }, + {NSC_XCOORD | fldoff(natstr, nat_xstart), "xstart", 0, 0}, + {NSC_YCOORD | fldoff(natstr, nat_ystart), "ystart", 0, 0}, + {NSC_XCOORD | fldoff(natstr, nat_xcap), "xcap", 0, 0}, + {NSC_YCOORD | fldoff(natstr, nat_ycap), "ycap", 0, 0}, + {NSC_DEITY | NSC_XCOORD | fldoff(natstr, nat_xorg), "xorg", 0, 0}, + {NSC_DEITY | NSC_YCOORD | fldoff(natstr, nat_yorg), "yorg", 0, 0}, #ifdef MAYBE_LATER -{ NSC_CHAR | fldoff(natstr, nat_stat),"stat",0,0 }, -{ NSC_CHAR | fldoff(natstr, nat_dayno),"dayno",0,0 }, -{ NSC_CHAR | fldoff(natstr, nat_update),"update",0,0 }, -{ NSC_UCHAR | fldoff(natstr, nat_missed),"missed",0,0 }, + {NSC_CHAR | fldoff(natstr, nat_stat), "stat", 0, 0}, + {NSC_CHAR | fldoff(natstr, nat_dayno), "dayno", 0, 0}, + {NSC_CHAR | fldoff(natstr, nat_update), "update", 0, 0}, + {NSC_UCHAR | fldoff(natstr, nat_missed), "missed", 0, 0}, #endif /* MAYBE_LATER */ -{ NSC_USHORT | fldoff(natstr, nat_tgms),"tgms",0,0 }, -{ NSC_USHORT | fldoff(natstr, nat_ann),"ann",0,0 }, -{ NSC_USHORT | fldoff(natstr, nat_minused),"minused",0,0 }, -{ NSC_SHORT | fldoff(natstr, nat_btu),"btu",0,0 }, -{ NSC_LONG | fldoff(natstr, nat_reserve),"reserve",0,0 }, -{ NSC_LONG | fldoff(natstr, nat_money),"money",0,0 }, + {NSC_USHORT | fldoff(natstr, nat_tgms), "tgms", 0, 0}, + {NSC_USHORT | fldoff(natstr, nat_ann), "ann", 0, 0}, + {NSC_USHORT | fldoff(natstr, nat_minused), "minused", 0, 0}, + {NSC_SHORT | fldoff(natstr, nat_btu), "btu", 0, 0}, + {NSC_LONG | fldoff(natstr, nat_reserve), "reserve", 0, 0}, + {NSC_LONG | fldoff(natstr, nat_money), "money", 0, 0}, #ifdef MAYBE_LATER -{ NSC_LONG | fldoff(natstr, nat_last_login),"last_login",0,0 }, -{ NSC_LONG | fldoff(natstr, nat_last_logout),"last_logout",0,0 }, -{ NSC_LONG | fldoff(natstr, nat_newstim),"newstim",0,0 }, + {NSC_LONG | fldoff(natstr, nat_last_login), "last_login", 0, 0}, + {NSC_LONG | fldoff(natstr, nat_last_logout), "last_logout", 0, 0}, + {NSC_LONG | fldoff(natstr, nat_newstim), "newstim", 0, 0}, #endif /* MAYBE_LATER */ #if !defined(_WIN32) -{ NSC_FLOAT | fldoff(natstr, nat_level[0]),"level",4,0 }, + {NSC_FLOAT | fldoff(natstr, nat_level[0]), "level", 4, 0}, #else -{ NSC_FLOAT | fldoff(natstr, nat_level),"level",4,0 }, + {NSC_FLOAT | fldoff(natstr, nat_level), "level", 4, 0}, #endif /* NSC_SHORT | fldoff(natstr, nat_relate[0]),"relate",MAXNOC,0, */ /* NSC_CHAR | fldoff(natstr, nat_priorities[0]),"priorities",39,0, */ /* NSC_LONG | fldoff(natstr, nat_flags),"flags",0,0, */ -{ 0, 0, 0,0 } + {0, 0, 0, 0} }; -struct castr map_ca[] = { -{ NSC_XCOORD | fldoff(mapstr, map_x),"x",0,0 }, -{ NSC_YCOORD | fldoff(mapstr, map_y),"y",0,0 }, -{ NSC_CHAR | fldoff(mapstr, map_des),"des",0,0 }, -{ 0, 0, 0,0 } +struct castr map_ca[] = { + {NSC_XCOORD | fldoff(mapstr, map_x), "x", 0, 0}, + {NSC_YCOORD | fldoff(mapstr, map_y), "y", 0, 0}, + {NSC_CHAR | fldoff(mapstr, map_des), "des", 0, 0}, + {0, 0, 0, 0} }; - diff --git a/src/lib/global/nuke.c b/src/lib/global/nuke.c index 7bea0852f..8c6cfc328 100644 --- a/src/lib/global/nuke.c +++ b/src/lib/global/nuke.c @@ -36,22 +36,22 @@ struct nchrstr nchr[N_MAXNUKE] = { - /* name lcm hcm oil rads blst dam cost tech lbs flags */ - { "10kt fission", 50, 50, 25, 70, 3, 70, 10000, 280, 4, 0 }, - { "15kt fission", 50, 50, 25, 80, 3, 90, 15000, 290, 5, 0 }, - { "50kt fission", 60, 60, 30, 90, 3, 100, 25000, 300, 6, 0 }, - { "100kt fission", 75, 75, 40, 120, 4, 125, 30000, 310, 8, 0 }, - { "5kt fusion", 15, 15, 15, 30, 2, 80, 12500, 315, 1, 0 }, - { "75kt fusion", 40, 40, 35, 50, 3, 90, 20000, 320, 3, 0 }, - { "250kt fusion", 50, 50, 45, 60, 4, 110, 25000, 330, 4, 0 }, - { "500kt fusion", 60, 60, 50, 80, 5, 120, 35000, 340, 5, 0 }, - { "1mt fusion", 75, 75, 50, 110, 6, 150, 40000, 350, 5, 0 }, - { "60kt neutron", 60, 60, 30, 100, 3, 30, 30000, 355, 2, N_NEUT }, - { "3mt fusion", 100, 100, 75, 130, 7, 170, 45000, 360, 6, 0 }, - { "5mt fusion", 120, 120, 100, 150, 8, 190, 50000, 370, 8, 0 }, - { "120kt neutron", 75, 75, 40, 120, 5, 50, 36000, 375, 3, N_NEUT }, - { "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - { "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + /* name lcm hcm oil rads blst dam cost tech lbs flags */ + {"10kt fission", 50, 50, 25, 70, 3, 70, 10000, 280, 4, 0}, + {"15kt fission", 50, 50, 25, 80, 3, 90, 15000, 290, 5, 0}, + {"50kt fission", 60, 60, 30, 90, 3, 100, 25000, 300, 6, 0}, + {"100kt fission", 75, 75, 40, 120, 4, 125, 30000, 310, 8, 0}, + {"5kt fusion", 15, 15, 15, 30, 2, 80, 12500, 315, 1, 0}, + {"75kt fusion", 40, 40, 35, 50, 3, 90, 20000, 320, 3, 0}, + {"250kt fusion", 50, 50, 45, 60, 4, 110, 25000, 330, 4, 0}, + {"500kt fusion", 60, 60, 50, 80, 5, 120, 35000, 340, 5, 0}, + {"1mt fusion", 75, 75, 50, 110, 6, 150, 40000, 350, 5, 0}, + {"60kt neutron", 60, 60, 30, 100, 3, 30, 30000, 355, 2, N_NEUT}, + {"3mt fusion", 100, 100, 75, 130, 7, 170, 45000, 360, 6, 0}, + {"5mt fusion", 120, 120, 100, 150, 8, 190, 50000, 370, 8, 0}, + {"120kt neutron", 75, 75, 40, 120, 5, 50, 36000, 375, 3, N_NEUT}, + {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; -int nuk_maxno = (sizeof(nchr) / sizeof(struct nchrstr)) - 1; +int nuk_maxno = (sizeof(nchr) / sizeof(struct nchrstr)) - 1; diff --git a/src/lib/global/numnames.c b/src/lib/global/numnames.c index b9f180061..c78d04e5f 100644 --- a/src/lib/global/numnames.c +++ b/src/lib/global/numnames.c @@ -33,16 +33,16 @@ #include "misc.h" -s_char *numnames[] = { - "zero", "one", "two", "three", "four", "five", "six", - "seven", "eight", "nine", "ten", "eleven", "twelve", - "thirteen", "fourteen", "fifteen", "sixteen", - "seventeen", "eighteen", "nineteen", +s_char *numnames[] = { + "zero", "one", "two", "three", "four", "five", "six", + "seven", "eight", "nine", "ten", "eleven", "twelve", + "thirteen", "fourteen", "fifteen", "sixteen", + "seventeen", "eighteen", "nineteen", }; -s_char *tennames[] = { - "", "", "twenty", "thirty", "forty", "fifty", - "sixty", "seventy", "eighty", "ninety", - "hundred", "hundred ten", "hundred twenty", - "hundred thirty", 0, +s_char *tennames[] = { + "", "", "twenty", "thirty", "forty", "fifty", + "sixty", "seventy", "eighty", "ninety", + "hundred", "hundred ten", "hundred twenty", + "hundred thirty", 0, }; diff --git a/src/lib/global/options.c b/src/lib/global/options.c index 89bb0faf0..fb07ba37e 100644 --- a/src/lib/global/options.c +++ b/src/lib/global/options.c @@ -286,9 +286,9 @@ int opt_NUKEFAILDETONATE = 0; #endif #ifdef SHIPNAMES -int opt_SHIPNAMES = 1; /* not used currently */ +int opt_SHIPNAMES = 1; /* not used currently */ #else -int opt_SHIPNAMES = 0; /* not used currently */ +int opt_SHIPNAMES = 0; /* not used currently */ #endif #ifdef NEUTRON @@ -328,53 +328,53 @@ int opt_TECH_POP = 0; #endif struct option_list Options[] = { -{ "ALL_BLEED", &opt_ALL_BLEED }, -{ "BIG_CITY", &opt_BIG_CITY }, -{ "BLITZ", &opt_BLITZ }, -{ "BRIDGETOWERS", &opt_BRIDGETOWERS }, -{ "DEFENSE_INFRA", &opt_DEFENSE_INFRA }, -{ "DEMANDUPDATE", &opt_DEMANDUPDATE }, -{ "DRNUKE", &opt_DRNUKE }, -{ "EASY_BRIDGES", &opt_EASY_BRIDGES }, -{ "FALLOUT", &opt_FALLOUT }, -{ "FUEL", &opt_FUEL }, -{ "GODNEWS", &opt_GODNEWS }, -{ "GO_RENEW", &opt_GO_RENEW }, -{ "GRAB_THINGS", &opt_GRAB_THINGS }, -{ "HIDDEN", &opt_HIDDEN }, -{ "INTERDICT_ATT", &opt_INTERDICT_ATT }, -{ "LANDSPIES", &opt_LANDSPIES }, -{ "LOANS", &opt_LOANS }, -{ "LOSE_CONTACT", &opt_LOSE_CONTACT }, -{ "MARKET", &opt_MARKET }, -{ "MOB_ACCESS", &opt_MOB_ACCESS }, -{ "NEUTRON", &opt_NEUTRON }, -{ "NEW_STARVE", &opt_NEW_STARVE }, -{ "NEW_WORK", &opt_NEW_WORK }, -{ "NEWPOWER", &opt_NEWPOWER }, -{ "NO_FORT_FIRE", &opt_NO_FORT_FIRE }, -{ "NO_HCMS", &opt_NO_HCMS }, -{ "NO_LCMS", &opt_NO_LCMS }, -{ "NO_OIL", &opt_NO_OIL }, -{ "NO_PLAGUE", &opt_NO_PLAGUE }, -{ "NOFOOD", &opt_NOFOOD }, -{ "NOMOBCOST", &opt_NOMOBCOST }, -{ "NONUKES", &opt_NONUKES }, -{ "NUKEFAILDETONATE", &opt_NUKEFAILDETONATE }, -{ "ORBIT", &opt_ORBIT }, -{ "PINPOINTMISSILE", &opt_PINPOINTMISSILE }, -{ "PLANENAMES", &opt_PLANENAMES }, -{ "RES_POP", &opt_RES_POP }, -{ "SAIL", &opt_SAIL }, -{ "SHIP_DECAY", &opt_SHIP_DECAY }, -{ "SHIPNAMES", &opt_SHIPNAMES }, -{ "SHOWPLANE", &opt_SHOWPLANE }, -{ "SLOW_WAR", &opt_SLOW_WAR }, -{ "SNEAK_ATTACK", &opt_SNEAK_ATTACK }, -{ "SUPER_BARS", &opt_SUPER_BARS }, -{ "TECH_POP", &opt_TECH_POP }, -{ "TRADESHIPS", &opt_TRADESHIPS }, -{ "TREATIES", &opt_TREATIES }, -{ "UPDATESCHED", &opt_UPDATESCHED }, -{ NULL, NULL }, + {"ALL_BLEED", &opt_ALL_BLEED}, + {"BIG_CITY", &opt_BIG_CITY}, + {"BLITZ", &opt_BLITZ}, + {"BRIDGETOWERS", &opt_BRIDGETOWERS}, + {"DEFENSE_INFRA", &opt_DEFENSE_INFRA}, + {"DEMANDUPDATE", &opt_DEMANDUPDATE}, + {"DRNUKE", &opt_DRNUKE}, + {"EASY_BRIDGES", &opt_EASY_BRIDGES}, + {"FALLOUT", &opt_FALLOUT}, + {"FUEL", &opt_FUEL}, + {"GODNEWS", &opt_GODNEWS}, + {"GO_RENEW", &opt_GO_RENEW}, + {"GRAB_THINGS", &opt_GRAB_THINGS}, + {"HIDDEN", &opt_HIDDEN}, + {"INTERDICT_ATT", &opt_INTERDICT_ATT}, + {"LANDSPIES", &opt_LANDSPIES}, + {"LOANS", &opt_LOANS}, + {"LOSE_CONTACT", &opt_LOSE_CONTACT}, + {"MARKET", &opt_MARKET}, + {"MOB_ACCESS", &opt_MOB_ACCESS}, + {"NEUTRON", &opt_NEUTRON}, + {"NEW_STARVE", &opt_NEW_STARVE}, + {"NEW_WORK", &opt_NEW_WORK}, + {"NEWPOWER", &opt_NEWPOWER}, + {"NO_FORT_FIRE", &opt_NO_FORT_FIRE}, + {"NO_HCMS", &opt_NO_HCMS}, + {"NO_LCMS", &opt_NO_LCMS}, + {"NO_OIL", &opt_NO_OIL}, + {"NO_PLAGUE", &opt_NO_PLAGUE}, + {"NOFOOD", &opt_NOFOOD}, + {"NOMOBCOST", &opt_NOMOBCOST}, + {"NONUKES", &opt_NONUKES}, + {"NUKEFAILDETONATE", &opt_NUKEFAILDETONATE}, + {"ORBIT", &opt_ORBIT}, + {"PINPOINTMISSILE", &opt_PINPOINTMISSILE}, + {"PLANENAMES", &opt_PLANENAMES}, + {"RES_POP", &opt_RES_POP}, + {"SAIL", &opt_SAIL}, + {"SHIP_DECAY", &opt_SHIP_DECAY}, + {"SHIPNAMES", &opt_SHIPNAMES}, + {"SHOWPLANE", &opt_SHOWPLANE}, + {"SLOW_WAR", &opt_SLOW_WAR}, + {"SNEAK_ATTACK", &opt_SNEAK_ATTACK}, + {"SUPER_BARS", &opt_SUPER_BARS}, + {"TECH_POP", &opt_TECH_POP}, + {"TRADESHIPS", &opt_TRADESHIPS}, + {"TREATIES", &opt_TREATIES}, + {"UPDATESCHED", &opt_UPDATESCHED}, + {NULL, NULL}, }; diff --git a/src/lib/global/path.c b/src/lib/global/path.c index 2ec2df250..a9394b0fb 100644 --- a/src/lib/global/path.c +++ b/src/lib/global/path.c @@ -41,31 +41,31 @@ #define FILEPATH(p) EMPPATH(data\\p) #endif -s_char *gamedir = EMPPATH(.); -s_char *infodir = EMPPATH(info.nr); -s_char *datadir = EMPPATH(data); -s_char *teldir = FILEPATH(tel); +s_char *gamedir = EMPPATH(.); +s_char *infodir = EMPPATH(info.nr); +s_char *datadir = EMPPATH(data); +s_char *teldir = FILEPATH(tel); -s_char *upfil = FILEPATH(up); -s_char *downfil = FILEPATH(down); -s_char *disablefil = FILEPATH(disable); +s_char *upfil = FILEPATH(up); +s_char *downfil = FILEPATH(down); +s_char *disablefil = FILEPATH(disable); #if !defined(_WIN32) -s_char *telfil = FILEPATH(tel/tel); +s_char *telfil = FILEPATH(tel / tel); #else -s_char *telfil = FILEPATH(tel\\tel); +s_char *telfil = FILEPATH(tel \\ tel); #endif -s_char *annfil = FILEPATH(ann); -s_char *commfil = FILEPATH(comm); -s_char *banfil = FILEPATH(ban); -s_char *authfil = FILEPATH(auth); -s_char *timestampfil = FILEPATH(timestamp); -s_char *lostfil = FILEPATH(lostitems); +s_char *annfil = FILEPATH(ann); +s_char *commfil = FILEPATH(comm); +s_char *banfil = FILEPATH(ban); +s_char *authfil = FILEPATH(auth); +s_char *timestampfil = FILEPATH(timestamp); +s_char *lostfil = FILEPATH(lostitems); #if !defined(_WIN32) -s_char *playerbin = EMPPATH(bin/emp_player); -s_char *updatebin = EMPPATH(bin/emp_update); +s_char *playerbin = EMPPATH(bin / emp_player); +s_char *updatebin = EMPPATH(bin / emp_update); #else -s_char *playerbin = EMPPATH(bin\\emp_player); -s_char *updatebin = EMPPATH(bin\\emp_update); +s_char *playerbin = EMPPATH(bin \\ emp_player); +s_char *updatebin = EMPPATH(bin \\ emp_update); #endif -s_char *loginport = EMP_PORT; +s_char *loginport = EMP_PORT; diff --git a/src/lib/global/plane.c b/src/lib/global/plane.c index 7636416c6..7d2307a0e 100644 --- a/src/lib/global/plane.c +++ b/src/lib/global/plane.c @@ -60,285 +60,285 @@ struct plchrstr plchr[] = { /* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"f1 fighter 1", -"f1 Sopwith Camel", - 8, 2, 400, 50, 90, 1, 1,1, 4, 1, 1, - 0, - P_V|P_T|P_F }, + { + "f1 fighter 1", + "f1 Sopwith Camel", + 8, 2, 400, 50, 90, 1, 1, 1, 4, 1, 1, + 0, + P_V | P_T | P_F}, /* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"f2 fighter 2", -"f2 P-51 Mustang", - 8, 2, 400, 80, 80, 1, 4,4, 8, 1, 1, - 0, - P_L|P_T|P_F }, + { + "f2 fighter 2", + "f2 P-51 Mustang", + 8, 2, 400, 80, 80, 1, 4, 4, 8, 1, 1, + 0, + P_L | P_T | P_F}, -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jf1 jet fighter 1", -"jf1 F-4 Phantom", - 12, 4, 1000, 125, 45, 1, 14,14, 11, 2, 3, - 0, - P_T|P_F|P_L }, +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jf1 jet fighter 1", + "jf1 F-4 Phantom", + 12, 4, 1000, 125, 45, 1, 14, 14, 11, 2, 3, + 0, + P_T | P_F | P_L}, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jf2 jet fighter 2", -"jf2 AV-8B Harrier", - 12, 4, 1400, 195, 30, 1, 17,17, 14, 2, 3, - 0, - P_T|P_F|P_L|P_V }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"sf stealth fighter", -"sf F-117A Nighthawk", - 15, 5, 3000, 325, 45, 3, 19,19, 20, 2, 4, - 80, - P_T|P_F|P_L }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"es escort", -"es P-38 Lightning", - 9, 3, 700, 90, 60, 1, 5,5, 15, 1, 2, - 0, - P_ESC|P_T }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jes jet escort", -"jes F-14E jet escort", - 14, 8,1400,160, 60, 1, 10,10, 25, 2, 3, - 0, - P_ESC|P_T }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"lb lt bomber", -"lb TBD-1 Devastator", - 10, 3, 550, 60, 50, 2, 0,3, 7, 1, 1, - 0, - P_L|P_V|P_T|P_B }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jl jet lt bomber", -"jl A-6 Intruder", - 14, 4, 1000, 130, 25, 3, 0,9, 11, 2, 3, - 0, - P_T|P_B|P_L }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"mb medium bomber", -"mb medium bomber", - 14, 5, 1000, 80, 45, 4, 0,5, 14, 3, 3, - 0, - P_T|P_B }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jmb jet med bomber", -"jfb FB-111 Aardvark f/b", - 20, 10, 1800, 140, 30, 7, 8, 8, 20, 5, 5, - 0, - P_T|P_B }, -{ -"hb hvy bomber", -"hb B-26B Marauder", - 20, 6, 1100, 90, 90, 5, 0,4, 15, 2, 2, - 0, - P_B }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jhb jet hvy bomber", -"jhb B-52 Strato-Fortress", - 26, 13, 3200, 150, 80,12, 0,11, 35, 5, 6, - 0, - P_B }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"sb stealth bomber", -"sb B-2 stealth bomber", - 15, 5, 4000, 325, 25, 8, 0,15, 28, 2, 5, - 80, - P_T|P_B }, - - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"as anti-sub plane", -"as anti-sub plane", - 10, 3, 550, 100, 85, 2, 0,3, 15, 2, 2, - 0, - P_SWEEP|P_MINE|P_T|P_A }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"np naval plane", -"np naval plane", - 20, 10, 1800, 135, 70, 3, 0,4, 28, 4, 2, - 0, - P_SWEEP|P_MINE|P_C|P_T|P_A|P_L }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"nc naval chopper", -"nc AH-1 Cobra", - 8, 2, 800, 160, 55, 2, 0,3, 11, 2, 2, - 0, - P_V|P_SWEEP|P_T|P_A|P_K }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"ac attack chopper", -"ac AH-64 Apache", - 8, 2, 800, 200, 15, 1, 0,9, 11, 2, 2, - 40, - P_V|P_T|P_K }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"tc transport chopper", -"tc transport chopper", - 8, 2, 800, 135, 0, 5, 0,3, 7, 2, 2, - 40, - P_V|P_C|P_P|P_L|P_K }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"tr transport", -"tr C-56 Lodestar", - 14, 5, 1000, 85, 0, 7, 0,2, 15, 3, 3, - 0, - P_C|P_P }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"jt jet transport", -"jt C-141 Starlifter", - 18, 5, 1500, 160, 0,16, 0,9, 35, 3, 4, - 0, - P_C|P_P }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"zep Zeppelin", -"zep Zeppelin", - 6, 2, 1000, 70, 60, 2, 0,-3, 15, 3, 2, - 0, - P_S|P_V|P_T|P_C }, -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"re recon", -"re recon", - 12, 4, 800, 130, 0, 0, 0,4, 15, 2, 2, - 20, - P_S }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"sp spyplane", -"sp E2-C Hawkeye", - 15, 5, 2000, 190, 0, 0, 0,11, 32, 2, 5, - 50, - P_S }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"lst landsat", -"lst landsat", - 20, 20, 2000, 245, 0, 0, 0,3, 41, 0, 9, - 0, - P_O }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"ss spysat", -"ss KH-7 spysat", - 20, 20, 4000, 305, 0, 0, 0,3, 61, 0, 9, - 0, - P_I|P_O|P_S }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"mi naval missile", -"mi Harpoon", - 8, 2, 300, 160, 50, 6, 0,5, 6, 0, 0, - 0, - P_L|P_T|P_M|P_MAR }, -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"sam sam", -"sam Sea Sparrow", - 3, 1, 200, 180, 0, 0, 0,18, 2, 0, 0, - 0, - P_L|P_F|P_E|P_M }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"ssm", -"ssm V2", - 15, 15, 800, 145, 60, 3, 0,3, 4, 0, 0, - 0, - P_T|P_M }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"srbm", -"srbm Atlas", - 20, 20, 1000, 200, 60, 6, 0,5, 9, 0, 0, - 0, - P_T|P_M }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"irbm", -"irbm Titan", - 20, 20, 1500, 260, 60, 8, 0,10, 15, 0, 0, - 0, - P_T| P_M }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"icbm", -"icbm Minuteman", - 20, 20, 3000, 310, 60,10, 0,15, 41, 0, 0, - 0, - P_T|P_M }, -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"slbm", -"slbm Trident", - 20, 20, 2000, 280, 60, 8, 0,6, 23, 0, 0, - 0, - P_T|P_L|P_M }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"asat anti-sat", -"asat anti-sat", - 20, 20, 2000, 305, 50, 6, 0,7, 13, 0, 4, - 0, - P_O|P_M }, - -/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ -{ -"abm anti-ballistic missile", -"abm Patriot", - 16, 8, 1500, 270, 50, 0, 0,31, 12, 0, 0, - 0, - P_N|P_M }, -{ -"", "", 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, - 0, - 0 } + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jf2 jet fighter 2", + "jf2 AV-8B Harrier", + 12, 4, 1400, 195, 30, 1, 17, 17, 14, 2, 3, + 0, + P_T | P_F | P_L | P_V}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "sf stealth fighter", + "sf F-117A Nighthawk", + 15, 5, 3000, 325, 45, 3, 19, 19, 20, 2, 4, + 80, + P_T | P_F | P_L}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "es escort", + "es P-38 Lightning", + 9, 3, 700, 90, 60, 1, 5, 5, 15, 1, 2, + 0, + P_ESC | P_T}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jes jet escort", + "jes F-14E jet escort", + 14, 8, 1400, 160, 60, 1, 10, 10, 25, 2, 3, + 0, + P_ESC | P_T}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "lb lt bomber", + "lb TBD-1 Devastator", + 10, 3, 550, 60, 50, 2, 0, 3, 7, 1, 1, + 0, + P_L | P_V | P_T | P_B}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jl jet lt bomber", + "jl A-6 Intruder", + 14, 4, 1000, 130, 25, 3, 0, 9, 11, 2, 3, + 0, + P_T | P_B | P_L}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "mb medium bomber", + "mb medium bomber", + 14, 5, 1000, 80, 45, 4, 0, 5, 14, 3, 3, + 0, + P_T | P_B}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jmb jet med bomber", + "jfb FB-111 Aardvark f/b", + 20, 10, 1800, 140, 30, 7, 8, 8, 20, 5, 5, + 0, + P_T | P_B}, + { + "hb hvy bomber", + "hb B-26B Marauder", + 20, 6, 1100, 90, 90, 5, 0, 4, 15, 2, 2, + 0, + P_B}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jhb jet hvy bomber", + "jhb B-52 Strato-Fortress", + 26, 13, 3200, 150, 80, 12, 0, 11, 35, 5, 6, + 0, + P_B}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "sb stealth bomber", + "sb B-2 stealth bomber", + 15, 5, 4000, 325, 25, 8, 0, 15, 28, 2, 5, + 80, + P_T | P_B}, + + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "as anti-sub plane", + "as anti-sub plane", + 10, 3, 550, 100, 85, 2, 0, 3, 15, 2, 2, + 0, + P_SWEEP | P_MINE | P_T | P_A}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "np naval plane", + "np naval plane", + 20, 10, 1800, 135, 70, 3, 0, 4, 28, 4, 2, + 0, + P_SWEEP | P_MINE | P_C | P_T | P_A | P_L}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "nc naval chopper", + "nc AH-1 Cobra", + 8, 2, 800, 160, 55, 2, 0, 3, 11, 2, 2, + 0, + P_V | P_SWEEP | P_T | P_A | P_K}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "ac attack chopper", + "ac AH-64 Apache", + 8, 2, 800, 200, 15, 1, 0, 9, 11, 2, 2, + 40, + P_V | P_T | P_K}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "tc transport chopper", + "tc transport chopper", + 8, 2, 800, 135, 0, 5, 0, 3, 7, 2, 2, + 40, + P_V | P_C | P_P | P_L | P_K}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "tr transport", + "tr C-56 Lodestar", + 14, 5, 1000, 85, 0, 7, 0, 2, 15, 3, 3, + 0, + P_C | P_P}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "jt jet transport", + "jt C-141 Starlifter", + 18, 5, 1500, 160, 0, 16, 0, 9, 35, 3, 4, + 0, + P_C | P_P}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "zep Zeppelin", + "zep Zeppelin", + 6, 2, 1000, 70, 60, 2, 0, -3, 15, 3, 2, + 0, + P_S | P_V | P_T | P_C}, +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "re recon", + "re recon", + 12, 4, 800, 130, 0, 0, 0, 4, 15, 2, 2, + 20, + P_S}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "sp spyplane", + "sp E2-C Hawkeye", + 15, 5, 2000, 190, 0, 0, 0, 11, 32, 2, 5, + 50, + P_S}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "lst landsat", + "lst landsat", + 20, 20, 2000, 245, 0, 0, 0, 3, 41, 0, 9, + 0, + P_O}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "ss spysat", + "ss KH-7 spysat", + 20, 20, 4000, 305, 0, 0, 0, 3, 61, 0, 9, + 0, + P_I | P_O | P_S}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "mi naval missile", + "mi Harpoon", + 8, 2, 300, 160, 50, 6, 0, 5, 6, 0, 0, + 0, + P_L | P_T | P_M | P_MAR}, +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "sam sam", + "sam Sea Sparrow", + 3, 1, 200, 180, 0, 0, 0, 18, 2, 0, 0, + 0, + P_L | P_F | P_E | P_M}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "ssm", + "ssm V2", + 15, 15, 800, 145, 60, 3, 0, 3, 4, 0, 0, + 0, + P_T | P_M}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "srbm", + "srbm Atlas", + 20, 20, 1000, 200, 60, 6, 0, 5, 9, 0, 0, + 0, + P_T | P_M}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "irbm", + "irbm Titan", + 20, 20, 1500, 260, 60, 8, 0, 10, 15, 0, 0, + 0, + P_T | P_M}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "icbm", + "icbm Minuteman", + 20, 20, 3000, 310, 60, 10, 0, 15, 41, 0, 0, + 0, + P_T | P_M}, +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "slbm", + "slbm Trident", + 20, 20, 2000, 280, 60, 8, 0, 6, 23, 0, 0, + 0, + P_T | P_L | P_M}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "asat anti-sat", + "asat anti-sat", + 20, 20, 2000, 305, 50, 6, 0, 7, 13, 0, 4, + 0, + P_O | P_M}, + +/* name lcm hcm $$$ tch acc ld at/df ran mil gas stlth flags */ + { + "abm anti-ballistic missile", + "abm Patriot", + 16, 8, 1500, 270, 50, 0, 0, 31, 12, 0, 0, + 0, + P_N | P_M}, + { + "", "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, + 0} }; -int pln_maxno = (sizeof(plchr) / sizeof(struct plchrstr)) - 1; +int pln_maxno = (sizeof(plchr) / sizeof(struct plchrstr)) - 1; diff --git a/src/lib/global/product.c b/src/lib/global/product.c index 6b551d410..5f2c30fb0 100644 --- a/src/lib/global/product.c +++ b/src/lib/global/product.c @@ -38,61 +38,61 @@ #include "var.h" -struct pchrstr pchr[] = { +struct pchrstr pchr[] = { /* level cost nrndx nrdep nlndx nlmin nllag effic sname name */ -{ 0, { 0 }, { 0 }, -0, 0, 0, 0, 0, 0, 0, 0, 0, - "unused", "", }, -{ 2, { V_LCM, V_HCM}, { 2, 1 }, -V_SHELL, -1, 3, 0, 0, NAT_TLEV, 20, 10, 100, - "shells", "shells", }, -{ 3, { V_OIL, V_LCM, V_HCM }, { 1, 5, 10 }, -V_GUN, -1, 30, 0, 0, NAT_TLEV, 20, 10, 100, - "guns", "guns",}, -{ 1, { V_OIL }, { 1 }, -V_PETROL,-1, 1, 0, 0, NAT_TLEV, 20, 10, 1000, - "petrol", "petrol",}, -{ 0, { 0 }, { 0 }, -V_IRON, -1, 0,OFFSET(sctstr, sct_min),0, -1, 0, 0, 100, - "iron ore", "iron", }, -{ 0, { 0 }, { 0 }, -V_DUST, -1, 0,OFFSET(sctstr, sct_gmin),20, -1, 0, 0, 100, - "gold dust", "dust",}, -{ 1, { V_DUST }, { 5 }, -V_BAR, -1, 10, 0, 0, -1, 0, 0, 100, - "gold bars", "bars",}, -{ 0, { 0 }, { 0 }, -V_FOOD, -1, 0,OFFSET(sctstr, sct_fertil),0, NAT_TLEV, -10, 10, 900, - "food", "food",}, -{ 0, { 0 }, { 0 }, -V_OIL, -1, 0,OFFSET(sctstr, sct_oil),10, NAT_TLEV, -10, 10, 100, - "oil", "oil",}, -{ 1, { V_IRON }, { 1 }, -V_LCM, -1, 0, 0, 0, NAT_TLEV, -10, 10, 100, - "light construction materials", "lcm",}, -{ 1, { V_IRON }, { 2 }, -V_HCM, -1, 0, 0, 0, NAT_TLEV, -10, 10, 100, - "heavy construction materials", "hcm", }, -{3,{V_DUST,V_OIL,V_LCM}, {1,5,10}, -0, NAT_TLEV, 5*ETUS, 0, 0, NAT_ELEV, 5, 10, 100, - "technological breakthroughs", "tech",}, -{3,{V_DUST,V_OIL,V_LCM }, { 1, 5, 10 }, -0, NAT_RLEV, 90, 0, 0, NAT_ELEV, 5, 10, 100, - "medical discoveries", "medical",}, -{ 1, { V_LCM }, { 1 }, -0, NAT_ELEV, 9, 0, 0, -1, 0, 0, 100, - "a class of graduates", "edu",}, -{ 1, { V_LCM }, { 1 }, -0, NAT_HLEV, 9, 0, 0, -1, 0, 0, 100, - "happy strollers", "happy",}, -{ 0, { 0 }, { 0 }, -V_RAD, -1, 2,OFFSET(sctstr, sct_uran),35, NAT_TLEV, 40, 10, 100, - "radioactive materials", "rad",}, -{ 0, { 0 }, { 0 }, -V_DUST, -1, 0,OFFSET(sctstr, sct_gmin),20, -1, 0, 0, 75, - "gold dust", "dust",}, -{ 0, {0}, {0}, -0, 0, 0, 0, 0, 0, 0, 0, 0, "", "",} + {0, {0}, {0}, + 0, 0, 0, 0, 0, 0, 0, 0, 0, + "unused", "",}, + {2, {V_LCM, V_HCM}, {2, 1}, + V_SHELL, -1, 3, 0, 0, NAT_TLEV, 20, 10, 100, + "shells", "shells",}, + {3, {V_OIL, V_LCM, V_HCM}, {1, 5, 10}, + V_GUN, -1, 30, 0, 0, NAT_TLEV, 20, 10, 100, + "guns", "guns",}, + {1, {V_OIL}, {1}, + V_PETROL, -1, 1, 0, 0, NAT_TLEV, 20, 10, 1000, + "petrol", "petrol",}, + {0, {0}, {0}, + V_IRON, -1, 0, OFFSET(sctstr, sct_min), 0, -1, 0, 0, 100, + "iron ore", "iron",}, + {0, {0}, {0}, + V_DUST, -1, 0, OFFSET(sctstr, sct_gmin), 20, -1, 0, 0, 100, + "gold dust", "dust",}, + {1, {V_DUST}, {5}, + V_BAR, -1, 10, 0, 0, -1, 0, 0, 100, + "gold bars", "bars",}, + {0, {0}, {0}, + V_FOOD, -1, 0, OFFSET(sctstr, sct_fertil), 0, NAT_TLEV, -10, 10, 900, + "food", "food",}, + {0, {0}, {0}, + V_OIL, -1, 0, OFFSET(sctstr, sct_oil), 10, NAT_TLEV, -10, 10, 100, + "oil", "oil",}, + {1, {V_IRON}, {1}, + V_LCM, -1, 0, 0, 0, NAT_TLEV, -10, 10, 100, + "light construction materials", "lcm",}, + {1, {V_IRON}, {2}, + V_HCM, -1, 0, 0, 0, NAT_TLEV, -10, 10, 100, + "heavy construction materials", "hcm",}, + {3, {V_DUST, V_OIL, V_LCM}, {1, 5, 10}, + 0, NAT_TLEV, 5 * ETUS, 0, 0, NAT_ELEV, 5, 10, 100, + "technological breakthroughs", "tech",}, + {3, {V_DUST, V_OIL, V_LCM}, {1, 5, 10}, + 0, NAT_RLEV, 90, 0, 0, NAT_ELEV, 5, 10, 100, + "medical discoveries", "medical",}, + {1, {V_LCM}, {1}, + 0, NAT_ELEV, 9, 0, 0, -1, 0, 0, 100, + "a class of graduates", "edu",}, + {1, {V_LCM}, {1}, + 0, NAT_HLEV, 9, 0, 0, -1, 0, 0, 100, + "happy strollers", "happy",}, + {0, {0}, {0}, + V_RAD, -1, 2, OFFSET(sctstr, sct_uran), 35, NAT_TLEV, 40, 10, 100, + "radioactive materials", "rad",}, + {0, {0}, {0}, + V_DUST, -1, 0, OFFSET(sctstr, sct_gmin), 20, -1, 0, 0, 75, + "gold dust", "dust",}, + {0, {0}, {0}, + 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "",} }; -int prd_maxno = (sizeof(pchr) / sizeof(struct pchrstr)) - 1; +int prd_maxno = (sizeof(pchr) / sizeof(struct pchrstr)) - 1; diff --git a/src/lib/global/sect.c b/src/lib/global/sect.c index b2a166cc0..e3715ba9a 100644 --- a/src/lib/global/sect.c +++ b/src/lib/global/sect.c @@ -42,56 +42,59 @@ #include "product.h" struct dchrstr bigcity_dchr = { - 'c', 0, 2, NAV_02, UPKG,1.0, 2.0, 30, 0, 10, 1, 2, "city" + 'c', 0, 2, NAV_02, UPKG, 1.0, 2.0, 30, 0, 10, 1, 2, "city" }; -struct dchrstr dchr[SCT_MAXDEF+2] = { +struct dchrstr dchr[SCT_MAXDEF + 2] = { /* mnem prd mcst flg pkg ostr dstr value $ bld lcm hcm name */ -{ '.', 0, 0, NAVOK, NPKG,0.0, 0.0, 0, 0, 0, 0, 0, "sea" }, -{ '^', P_MDUST, 25, 0, NPKG,1.0, 4.0, 5, 0, 1, 0, 0, "mountain" }, -{ 's', 0, 0, 0, NPKG,0.0,99.0, 127, 0, 0, 0, 0, "sanctuary" }, -{ '\\',0, 0, 0, NPKG,0.0,99.0, 0, 0, 0, 0, 0, "wasteland" }, -{ '-', 0, 3, 0, NPKG,1.0, 2.0, 1, 0, 0, 0, 0, "wilderness" }, -{ 'c', 0, 2, 0, NPKG,1.0, 2.0, 30, 0, 1, 0, 0, "capital" }, -{ 'u', P_URAN, 2, 0, NPKG,1.0, 2.0, 15, 0, 1, 0, 0, "uranium mine" }, -{ 'p', P_HLEV, 2, 0, NPKG,1.0, 1.5, 5, 0, 1, 0, 0, "park" }, -{ 'd', P_GUN, 2, 0, NPKG,1.0, 1.5, 7, 0, 1, 0, 0, "defense plant" }, -{ 'i', P_SHELL, 2, 0, NPKG,1.0, 1.5, 6, 0, 1, 0, 0, "shell industry" }, -{ 'm', P_IRON, 2, 0, NPKG,1.0, 2.0, 5, 0, 1, 0, 0, "mine" }, -{ 'g', P_DUST, 2, 0, NPKG,1.0, 2.0, 8, 0, 1, 0, 0, "gold mine" }, -{ 'h', 0, 2, NAV_02, WPKG,1.0, 1.5, 12, 0, 1, 0, 0, "harbor" }, -{ 'w', 0, 2, 0, WPKG,1.0, 1.5, 7, 0, 1, 0, 0, "warehouse" }, -{ '*', 0, 2, 0, NPKG,1.0,1.25, 12, 0, 1, 0, 0, "airfield" }, -{ 'a', P_FOOD, 2, 0, NPKG,1.0, 1.5, 2, 0, 1, 0, 0, "agribusiness" }, -{ 'o', P_OIL, 2, 0, NPKG,1.0, 1.5, 5, 0, 1, 0, 0, "oil field" }, -{ 'j', P_LCM, 2, 0, NPKG,1.0, 1.5, 3, 0, 1, 0, 0, "light manufacturing" }, -{ 'k', P_HCM, 2, 0, NPKG,1.0, 1.5, 4, 0, 1, 0, 0, "heavy manufacturing" }, -{ 'f', 0, 2, 0, NPKG,2.0, 4.0, 10, 0, 5, 0, 1, "fortress" }, -{ 't', P_TLEV, 2, 0, NPKG,1.0, 1.5, 10, 0, 1, 0, 0, "technical center" }, -{ 'r', P_RLEV, 2, 0, NPKG,1.0, 1.5, 9, 0, 1, 0, 0, "research lab" }, -{ 'n', 0, 2, 0, NPKG,1.0, 2.0, 10, 0, 1, 0, 0, "nuclear plant" }, -{ 'l', P_ELEV, 2, 0, NPKG,1.0, 1.5, 4, 0, 1, 0, 0, "library/school" }, -{ '+', 0, 1, 0, NPKG,1.0, 1.0, 3, 0, 1, 0, 0, "highway" }, -{ ')', 0, 2, 0, NPKG,1.0, 1.5, 4, 0, 1, 0, 0, "radar installation" }, -{ '!', 0, 2, 0, NPKG,1.0, 1.5, 12, 0, 1, 0, 0, "headquarters" }, -{ '#', 0, 1, 0, NPKG,1.0, 1.5, 4, 0, 1, 0, 0, "bridge head" }, -{ '=', 0, 1, NAV_60, NPKG,1.0, 1.0, 5, 0, 1, 0, 0, "bridge span" }, -{ 'b', P_BAR, 2, 0, BPKG,1.0,2.25, 10, 0, 1, 0, 0, "bank" }, -{ '%', P_PETROL, 2, 0, NPKG,1.0, 1.5, 2, 0, 1, 0, 0, "refinery" }, -{ 'e', 0, 2, 0, NPKG,1.0, 2.0, 7, 0, 1, 0, 0, "enlistment center" }, -{ '~', 0, 2, 0, NPKG,1.0, 1.5, 1, 0, 1, 0, 0, "plains" }, -{ '@', 0, 1, 0, NPKG,1.0, 1.5, 4, 0, 1, 0, 0, "bridge tower" }, -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, -{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } + {'.', 0, 0, NAVOK, NPKG, 0.0, 0.0, 0, 0, 0, 0, 0, "sea"}, + {'^', P_MDUST, 25, 0, NPKG, 1.0, 4.0, 5, 0, 1, 0, 0, "mountain"}, + {'s', 0, 0, 0, NPKG, 0.0, 99.0, 127, 0, 0, 0, 0, "sanctuary"}, + {'\\', 0, 0, 0, NPKG, 0.0, 99.0, 0, 0, 0, 0, 0, "wasteland"}, + {'-', 0, 3, 0, NPKG, 1.0, 2.0, 1, 0, 0, 0, 0, "wilderness"}, + {'c', 0, 2, 0, NPKG, 1.0, 2.0, 30, 0, 1, 0, 0, "capital"}, + {'u', P_URAN, 2, 0, NPKG, 1.0, 2.0, 15, 0, 1, 0, 0, "uranium mine"}, + {'p', P_HLEV, 2, 0, NPKG, 1.0, 1.5, 5, 0, 1, 0, 0, "park"}, + {'d', P_GUN, 2, 0, NPKG, 1.0, 1.5, 7, 0, 1, 0, 0, "defense plant"}, + {'i', P_SHELL, 2, 0, NPKG, 1.0, 1.5, 6, 0, 1, 0, 0, "shell industry"}, + {'m', P_IRON, 2, 0, NPKG, 1.0, 2.0, 5, 0, 1, 0, 0, "mine"}, + {'g', P_DUST, 2, 0, NPKG, 1.0, 2.0, 8, 0, 1, 0, 0, "gold mine"}, + {'h', 0, 2, NAV_02, WPKG, 1.0, 1.5, 12, 0, 1, 0, 0, "harbor"}, + {'w', 0, 2, 0, WPKG, 1.0, 1.5, 7, 0, 1, 0, 0, "warehouse"}, + {'*', 0, 2, 0, NPKG, 1.0, 1.25, 12, 0, 1, 0, 0, "airfield"}, + {'a', P_FOOD, 2, 0, NPKG, 1.0, 1.5, 2, 0, 1, 0, 0, "agribusiness"}, + {'o', P_OIL, 2, 0, NPKG, 1.0, 1.5, 5, 0, 1, 0, 0, "oil field"}, + {'j', P_LCM, 2, 0, NPKG, 1.0, 1.5, 3, 0, 1, 0, 0, + "light manufacturing"}, + {'k', P_HCM, 2, 0, NPKG, 1.0, 1.5, 4, 0, 1, 0, 0, + "heavy manufacturing"}, + {'f', 0, 2, 0, NPKG, 2.0, 4.0, 10, 0, 5, 0, 1, "fortress"}, + {'t', P_TLEV, 2, 0, NPKG, 1.0, 1.5, 10, 0, 1, 0, 0, + "technical center"}, + {'r', P_RLEV, 2, 0, NPKG, 1.0, 1.5, 9, 0, 1, 0, 0, "research lab"}, + {'n', 0, 2, 0, NPKG, 1.0, 2.0, 10, 0, 1, 0, 0, "nuclear plant"}, + {'l', P_ELEV, 2, 0, NPKG, 1.0, 1.5, 4, 0, 1, 0, 0, "library/school"}, + {'+', 0, 1, 0, NPKG, 1.0, 1.0, 3, 0, 1, 0, 0, "highway"}, + {')', 0, 2, 0, NPKG, 1.0, 1.5, 4, 0, 1, 0, 0, "radar installation"}, + {'!', 0, 2, 0, NPKG, 1.0, 1.5, 12, 0, 1, 0, 0, "headquarters"}, + {'#', 0, 1, 0, NPKG, 1.0, 1.5, 4, 0, 1, 0, 0, "bridge head"}, + {'=', 0, 1, NAV_60, NPKG, 1.0, 1.0, 5, 0, 1, 0, 0, "bridge span"}, + {'b', P_BAR, 2, 0, BPKG, 1.0, 2.25, 10, 0, 1, 0, 0, "bank"}, + {'%', P_PETROL, 2, 0, NPKG, 1.0, 1.5, 2, 0, 1, 0, 0, "refinery"}, + {'e', 0, 2, 0, NPKG, 1.0, 2.0, 7, 0, 1, 0, 0, "enlistment center"}, + {'~', 0, 2, 0, NPKG, 1.0, 1.5, 1, 0, 1, 0, 0, "plains"}, + {'@', 0, 1, 0, NPKG, 1.0, 1.5, 4, 0, 1, 0, 0, "bridge tower"}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; -int sct_maxno = (sizeof(dchr) / sizeof(struct dchrstr)) - 1; +int sct_maxno = (sizeof(dchr) / sizeof(struct dchrstr)) - 1; struct sctintrins intrchr[] = { /* name lcm hcm dollars mobility */ -{ "road network", 2, 2, 2, 1 }, -{ "rail network", 1, 1, 1, 1 }, -{ "defense factor", 1, 1, 1, 1 }, -{ 0, 0, 0, 0, 0 } + {"road network", 2, 2, 2, 1}, + {"rail network", 1, 1, 1, 1}, + {"defense factor", 1, 1, 1, 1}, + {0, 0, 0, 0, 0} }; diff --git a/src/lib/global/ship.c b/src/lib/global/ship.c index 8a14dfab9..b4be4826c 100644 --- a/src/lib/global/ship.c +++ b/src/lib/global/ship.c @@ -49,278 +49,304 @@ #include "var.h" #include "ship.h" -struct mchrstr mchr[] = { +struct mchrstr mchr[] = { /* a s v v f E K f f */ /* r p i r r g | | u u */ /* l h m e s n n l x V e e */ /* c c o e i g g i p p l l */ /* m m r d b e e m l l c u name tech Cost*/ -{ 4, - { V_CIVIL, V_MILIT, V_FOOD, V_UW }, - { 300, 10, 900, 15 }, -25, 15, 10, 10, 15, 2, 0, 0, 0, 0, 0, 0, "fb fishing boat", 0, 180, - M_FOOD, 0, 0, -}, - -{ 4, - { V_CIVIL, V_MILIT, V_FOOD, V_UW }, - { 300, 10, 900, 15 }, -25, 15, 10, 25, 15, 2, 0, 0, 0, 0, 20, 1, "ft fishing trawler", 35, 300, - M_FOOD, 0, 0, -}, - -{ 8, - { V_CIVIL, V_MILIT, V_SHELL, V_GUN, V_FOOD, V_LCM, V_HCM, V_UW }, - { 600, 50, 300, 50, 900, 1400, 900, 250 }, -60, 40, 20, 25, 35, 3, 0, 0, 1, 0, 0, 0, "cs cargo ship", 20, 500, - M_SUPPLY, 0, 2, -}, - -{ 7, - { V_CIVIL, V_MILIT, V_IRON, V_DUST, V_FOOD, V_UW, V_RAD }, - { 30, 5, 990, 990, 200, 45, 990 }, -60, 40, 20, 25, 35, 3, 0, 0, 1, 0, 30, 1, "os ore ship", 20, 500, - 0, 0, 0, -}, - -{ 4, - { V_CIVIL, V_MILIT, V_FOOD, V_UW }, - { 20, 80, 200, 1200 }, -60, 40, 20, 10, 35, 3, 0, 0, 1, 0, 0, 0, "ss slave ship", 0, 300, - 0, 0, 0, -}, - -{ 3, - { V_CIVIL, V_MILIT, V_FOOD }, - { 50, 50, 100 }, -200, 100, 20, 25, 35, 3, 0, 0, 1, 0, 30, 1, "ts trade ship", 30, 1750, - M_TRADE, 0, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 60, 10, 2, 60 }, -30, 30, 50, 25, 25, 3, 1, 1, 1, 0, 0, 0, "frg frigate", 0, 600, - M_SEMILAND, 0, 2, -}, - -{ 4, - { V_CIVIL, V_MILIT, V_FOOD, V_OIL }, - { 10, 5, 100, 1 }, -25, 15, 10, 25, 15, 2, 0, 0, 0, 0, 20, 1, "oe oil exploration boat", 40, 800, - M_OIL, 0, 0, -}, - -{ 5, - { V_CIVIL, V_MILIT, V_FOOD, V_OIL, V_UW }, - { 990, 80, 990, 990, 990 }, -60, 60, 30, 15, 65, 3, 0, 0, 2, 0, 0, 0, "od oil derrick", 50, 1500, - M_OIL, 0, 0, -}, - -{ 4, - { V_MILIT, V_GUN, V_SHELL, V_FOOD }, - { 2, 2, 12, 5 }, -20, 10, 10, 38, 10, 2, 1, 1, 0, 0, 4, 1, "pt patrol boat", 40, 300, - M_TORP, 0, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 100, 40, 5, 100 }, -30, 40, 50, 30, 30, 5, 6, 3, 1, 0, 40, 1, "lc light cruiser", 45, 800, - M_MINE, 0, 2, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 120, 100, 8, 200 }, -40, 50, 70, 30, 30, 5, 8, 4, 1, 0, 30, 1, "hc heavy cruiser", 50, 1200, - 0, 0, 4, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 120, 20, 4, 120 }, -50, 50, 60, 20, 35, 3, 1, 2, 1, 0, 0, 0, "tt troop transport", 10, 800, - M_SEMILAND, 0, 2, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 200, 200, 10, 900 }, -50, 70, 95, 25, 35, 6, 10, 7, 1, 0, 50, 2, "bb battleship", 45, 1800, - 0, 0, 2, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 180, 100, 10, 400 }, -50, 60, 55, 30, 35, 6, 10, 6, 1, 0, 60, 2, "bbc battlecruiser", 75, 1500, - 0, 0, 2, -}, - -{ 6, - { V_CIVIL, V_MILIT, V_PETROL, V_FOOD, V_OIL, V_UW }, - { 30, 5, 990, 200, 990, 25 }, -60, 40, 75, 25, 45, 3, 0, 0, 1, 0, 30, 1, "tk tanker", 35, 600, - M_OILER|M_SUPPLY, 0, 0, -}, - -{ 4, - { V_MILIT, V_FOOD, V_SHELL, V_GUN }, - { 10, 90, 100, 1 }, -25, 15, 10, 25, 15, 2, 0, 0, 0, 0, 20, 1, "ms minesweeper", 40, 400, - M_MINE|M_SWEEP, 0, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 60, 40, 4, 80 }, -30, 30, 45, 35, 20, 4, 6, 3, 1, 0, 30, 1, "dd destroyer", 70, 600, - M_MINE|M_DCH|M_SONAR, 0, 1, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 25, 36, 5, 80 }, -30, 30, 25, 20, 5, 4, 3, 3, 0, 0, 30, 1, "sb submarine", 60, 650, - M_TORP|M_SUB|M_MINE|M_SONAR, 0, 0, -}, - -{ 8, - { V_CIVIL, V_MILIT, V_SHELL, V_GUN, V_FOOD, V_LCM, V_HCM, V_PETROL }, - { 5, 10, 104, 20, 900, 500, 300, 100 }, -40, 40, 50, 30, 2, 3, 0, 0, 0, 0, 50, 2, "sbc cargo submarine", 150, 1200, - M_SUPPLY|M_OILER|M_SUB|M_SONAR, 0, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 175, 250, 4, 300, 180 }, -50, 60, 60, 30, 40, 5, 2, 2, 4, 20, 50, 2, "cal light carrier", 80, 2700, - M_FLY, 20, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 350, 500, 4, 500, 900 }, -60, 70, 80, 35, 40, 7, 2, 2, 10, 40, 120, 3, "car aircraft carrier", 160, 4500, - M_FLY, 40, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 350, 999, 4, 999, 900 }, -70, 80, 100, 45, 40, 9, 2, 2, 20, 4, 0, 0, "can nuc carrier", 305, 8000, - M_OILER|M_FLY|M_SUPPLY, 60, 0, -}, - -{ 4, - { V_MILIT, V_FOOD , V_GUN , V_SHELL }, - { 400, 300 , 1 , 10 }, -60, 40, 40, 30, 30, 2, 0, 0, 2, 0, 30, 1, "ls landing ship", 145, 1000, - M_LAND, 0, 6, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 60, 60, 4, 120 }, -40, 30, 50, 35, 30, 5, 2, 2, 4, 0, 40, 1, "af asw frigate", 220, 800, - M_TORP|M_SUBT|M_DCH|M_SONAR, 0, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 25, 60, 6, 500 }, -30, 40, 45, 40, 3, 6, 5, 3, 0, 0, 0, 0, "na nuc attack sub", 260, 1200, - M_TORP|M_SUB|M_MINE|M_SONAR|M_SUBT, 0, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 100, 80, 6, 40, 500 }, -40, 40, 60, 40, 35, 6, 8, 3, 10, 2, 80, 2, "ad asw destroyer", 240, 1500, - M_TORP|M_SUBT|M_DCH|M_SONAR, 0, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_FOOD, V_GUN }, - { 25, 200, 500, 1 }, -30, 40, 55, 35, 2, 6, 0, 0, 0, 0, 0, 0, "nm nuc miss sub", 270, 1500, - M_SUB|M_SONAR, 20, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_FOOD, V_GUN }, - { 25, 100, 500, 1 }, -30, 30, 35, 30, 3, 3, 0, 0, 0, 0, 30, 1, "msb missile sub", 230, 1200, - M_SUB|M_SONAR, 10, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 5, 100, 3, 500 }, -20, 20, 15, 40, 15, 3, 2, 2, 0, 0, 7, 1, "mb missile boat", 180, 500, - 0, 10, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 60, 220, 4, 120 }, -40, 30, 50, 35, 30, 5, 2, 2, 2, 0, 30, 1, "mf missile frigate", 280, 1000, - 0, 20, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 120, 500, 6, 160, 200 }, -50, 50, 70, 35, 35, 8, 8, 6, 8, 8, 35, 1, "mc missile cruiser", 290, 1500, - M_ANTIMISSILE, 40, 0, -}, - -{ 4, - { V_MILIT, V_SHELL, V_GUN, V_FOOD }, - { 100, 100, 15, 200 }, -50, 60, 80, 35, 30, 6, 1, 8, 1, 0, 60, 2, "aac aa cruiser", 130, 1500, - M_ANTIMISSILE, 0, 4, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 200, 400, 25, 40, 900 }, -50, 60, 80, 35, 30, 6, 1, 16, 30, 2, 0, 0, "agc aegis cruiser", 265, 4000, - M_ANTIMISSILE, 32, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 200, 400, 8, 40, 900 }, -50, 50, 100, 45, 35, 6, 14, 7, 10, 2, 0, 0, "ncr nuc cruiser", 325, 1800, - M_ANTIMISSILE, 20, 0, -}, - -{ 5, - { V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD }, - { 200, 120, 6, 160, 500 }, -50, 50, 80, 45, 35, 9, 10, 4, 25, 8, 0, 0, "nas nuc asw cruiser", 330, 1800, - M_TORP|M_SUBT|M_DCH|M_SONAR, 0, 0, -}, - -{ 8, - { V_CIVIL, V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD, V_LCM, V_HCM }, - { 50, 50, 600, 50, 999, 999, 1500, 900 }, -60, 40, 40, 45, 35, 6, 0, 0, 10, 2, 0, 0, "nsp nuc supply ship", 360, 1500, - M_SUPPLY,0,2, -}, - -{ 0, - { 0 }, - { 0 }, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, 0, - 0, 0, 0, -} + {4, + {V_CIVIL, V_MILIT, V_FOOD, V_UW}, + {300, 10, 900, 15}, + 25, 15, 10, 10, 15, 2, 0, 0, 0, 0, 0, 0, "fb fishing boat", 0, 180, + M_FOOD, 0, 0, + }, + + {4, + {V_CIVIL, V_MILIT, V_FOOD, V_UW}, + {300, 10, 900, 15}, + 25, 15, 10, 25, 15, 2, 0, 0, 0, 0, 20, 1, "ft fishing trawler", 35, + 300, + M_FOOD, 0, 0, + }, + + {8, + {V_CIVIL, V_MILIT, V_SHELL, V_GUN, V_FOOD, V_LCM, V_HCM, V_UW}, + {600, 50, 300, 50, 900, 1400, 900, 250}, + 60, 40, 20, 25, 35, 3, 0, 0, 1, 0, 0, 0, "cs cargo ship", 20, 500, + M_SUPPLY, 0, 2, + }, + + {7, + {V_CIVIL, V_MILIT, V_IRON, V_DUST, V_FOOD, V_UW, V_RAD}, + {30, 5, 990, 990, 200, 45, 990}, + 60, 40, 20, 25, 35, 3, 0, 0, 1, 0, 30, 1, "os ore ship", 20, 500, + 0, 0, 0, + }, + + {4, + {V_CIVIL, V_MILIT, V_FOOD, V_UW}, + {20, 80, 200, 1200}, + 60, 40, 20, 10, 35, 3, 0, 0, 1, 0, 0, 0, "ss slave ship", 0, 300, + 0, 0, 0, + }, + + {3, + {V_CIVIL, V_MILIT, V_FOOD}, + {50, 50, 100}, + 200, 100, 20, 25, 35, 3, 0, 0, 1, 0, 30, 1, "ts trade ship", 30, + 1750, + M_TRADE, 0, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {60, 10, 2, 60}, + 30, 30, 50, 25, 25, 3, 1, 1, 1, 0, 0, 0, "frg frigate", 0, 600, + M_SEMILAND, 0, 2, + }, + + {4, + {V_CIVIL, V_MILIT, V_FOOD, V_OIL}, + {10, 5, 100, 1}, + 25, 15, 10, 25, 15, 2, 0, 0, 0, 0, 20, 1, "oe oil exploration boat", + 40, 800, + M_OIL, 0, 0, + }, + + {5, + {V_CIVIL, V_MILIT, V_FOOD, V_OIL, V_UW}, + {990, 80, 990, 990, 990}, + 60, 60, 30, 15, 65, 3, 0, 0, 2, 0, 0, 0, "od oil derrick", 50, 1500, + M_OIL, 0, 0, + }, + + {4, + {V_MILIT, V_GUN, V_SHELL, V_FOOD}, + {2, 2, 12, 5}, + 20, 10, 10, 38, 10, 2, 1, 1, 0, 0, 4, 1, "pt patrol boat", 40, 300, + M_TORP, 0, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {100, 40, 5, 100}, + 30, 40, 50, 30, 30, 5, 6, 3, 1, 0, 40, 1, "lc light cruiser", 45, + 800, + M_MINE, 0, 2, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {120, 100, 8, 200}, + 40, 50, 70, 30, 30, 5, 8, 4, 1, 0, 30, 1, "hc heavy cruiser", 50, + 1200, + 0, 0, 4, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {120, 20, 4, 120}, + 50, 50, 60, 20, 35, 3, 1, 2, 1, 0, 0, 0, "tt troop transport", 10, + 800, + M_SEMILAND, 0, 2, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {200, 200, 10, 900}, + 50, 70, 95, 25, 35, 6, 10, 7, 1, 0, 50, 2, "bb battleship", 45, + 1800, + 0, 0, 2, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {180, 100, 10, 400}, + 50, 60, 55, 30, 35, 6, 10, 6, 1, 0, 60, 2, "bbc battlecruiser", 75, + 1500, + 0, 0, 2, + }, + + {6, + {V_CIVIL, V_MILIT, V_PETROL, V_FOOD, V_OIL, V_UW}, + {30, 5, 990, 200, 990, 25}, + 60, 40, 75, 25, 45, 3, 0, 0, 1, 0, 30, 1, "tk tanker", 35, 600, + M_OILER | M_SUPPLY, 0, 0, + }, + + {4, + {V_MILIT, V_FOOD, V_SHELL, V_GUN}, + {10, 90, 100, 1}, + 25, 15, 10, 25, 15, 2, 0, 0, 0, 0, 20, 1, "ms minesweeper", 40, 400, + M_MINE | M_SWEEP, 0, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {60, 40, 4, 80}, + 30, 30, 45, 35, 20, 4, 6, 3, 1, 0, 30, 1, "dd destroyer", 70, 600, + M_MINE | M_DCH | M_SONAR, 0, 1, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {25, 36, 5, 80}, + 30, 30, 25, 20, 5, 4, 3, 3, 0, 0, 30, 1, "sb submarine", 60, 650, + M_TORP | M_SUB | M_MINE | M_SONAR, 0, 0, + }, + + {8, + {V_CIVIL, V_MILIT, V_SHELL, V_GUN, V_FOOD, V_LCM, V_HCM, V_PETROL}, + {5, 10, 104, 20, 900, 500, 300, 100}, + 40, 40, 50, 30, 2, 3, 0, 0, 0, 0, 50, 2, "sbc cargo submarine", 150, + 1200, + M_SUPPLY | M_OILER | M_SUB | M_SONAR, 0, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {175, 250, 4, 300, 180}, + 50, 60, 60, 30, 40, 5, 2, 2, 4, 20, 50, 2, "cal light carrier", 80, + 2700, + M_FLY, 20, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {350, 500, 4, 500, 900}, + 60, 70, 80, 35, 40, 7, 2, 2, 10, 40, 120, 3, "car aircraft carrier", + 160, 4500, + M_FLY, 40, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {350, 999, 4, 999, 900}, + 70, 80, 100, 45, 40, 9, 2, 2, 20, 4, 0, 0, "can nuc carrier", 305, + 8000, + M_OILER | M_FLY | M_SUPPLY, 60, 0, + }, + + {4, + {V_MILIT, V_FOOD, V_GUN, V_SHELL}, + {400, 300, 1, 10}, + 60, 40, 40, 30, 30, 2, 0, 0, 2, 0, 30, 1, "ls landing ship", 145, + 1000, + M_LAND, 0, 6, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {60, 60, 4, 120}, + 40, 30, 50, 35, 30, 5, 2, 2, 4, 0, 40, 1, "af asw frigate", 220, + 800, + M_TORP | M_SUBT | M_DCH | M_SONAR, 0, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {25, 60, 6, 500}, + 30, 40, 45, 40, 3, 6, 5, 3, 0, 0, 0, 0, "na nuc attack sub", 260, + 1200, + M_TORP | M_SUB | M_MINE | M_SONAR | M_SUBT, 0, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {100, 80, 6, 40, 500}, + 40, 40, 60, 40, 35, 6, 8, 3, 10, 2, 80, 2, "ad asw destroyer", 240, + 1500, + M_TORP | M_SUBT | M_DCH | M_SONAR, 0, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_FOOD, V_GUN}, + {25, 200, 500, 1}, + 30, 40, 55, 35, 2, 6, 0, 0, 0, 0, 0, 0, "nm nuc miss sub", 270, + 1500, + M_SUB | M_SONAR, 20, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_FOOD, V_GUN}, + {25, 100, 500, 1}, + 30, 30, 35, 30, 3, 3, 0, 0, 0, 0, 30, 1, "msb missile sub", 230, + 1200, + M_SUB | M_SONAR, 10, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {5, 100, 3, 500}, + 20, 20, 15, 40, 15, 3, 2, 2, 0, 0, 7, 1, "mb missile boat", 180, + 500, + 0, 10, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {60, 220, 4, 120}, + 40, 30, 50, 35, 30, 5, 2, 2, 2, 0, 30, 1, "mf missile frigate", 280, + 1000, + 0, 20, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {120, 500, 6, 160, 200}, + 50, 50, 70, 35, 35, 8, 8, 6, 8, 8, 35, 1, "mc missile cruiser", 290, + 1500, + M_ANTIMISSILE, 40, 0, + }, + + {4, + {V_MILIT, V_SHELL, V_GUN, V_FOOD}, + {100, 100, 15, 200}, + 50, 60, 80, 35, 30, 6, 1, 8, 1, 0, 60, 2, "aac aa cruiser", 130, + 1500, + M_ANTIMISSILE, 0, 4, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {200, 400, 25, 40, 900}, + 50, 60, 80, 35, 30, 6, 1, 16, 30, 2, 0, 0, "agc aegis cruiser", 265, + 4000, + M_ANTIMISSILE, 32, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {200, 400, 8, 40, 900}, + 50, 50, 100, 45, 35, 6, 14, 7, 10, 2, 0, 0, "ncr nuc cruiser", 325, + 1800, + M_ANTIMISSILE, 20, 0, + }, + + {5, + {V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD}, + {200, 120, 6, 160, 500}, + 50, 50, 80, 45, 35, 9, 10, 4, 25, 8, 0, 0, "nas nuc asw cruiser", + 330, 1800, + M_TORP | M_SUBT | M_DCH | M_SONAR, 0, 0, + }, + + {8, + {V_CIVIL, V_MILIT, V_SHELL, V_GUN, V_PETROL, V_FOOD, V_LCM, V_HCM}, + {50, 50, 600, 50, 999, 999, 1500, 900}, + 60, 40, 40, 45, 35, 6, 0, 0, 10, 2, 0, 0, "nsp nuc supply ship", 360, + 1500, + M_SUPPLY, 0, 2, + }, + + {0, + {0}, + {0}, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", 0, 0, + 0, 0, 0, + } }; -int shp_maxno = (sizeof(mchr) / sizeof(struct mchrstr)) - 1; +int shp_maxno = (sizeof(mchr) / sizeof(struct mchrstr)) - 1; diff --git a/src/lib/global/treaty.c b/src/lib/global/treaty.c index 176fb9176..b4569a58a 100644 --- a/src/lib/global/treaty.c +++ b/src/lib/global/treaty.c @@ -35,19 +35,19 @@ #include "misc.h" #include "treaty.h" -struct tchrstr tchr[] = { - { LNDATT, "no attacks on any land units" }, - { SEAATT, "no attacks on any ships" }, - { SEAFIR, "no shelling any ships" }, - { SUBFIR, "no depth-charging any subs" }, - { LANATT, "no sector attacks" }, - { LANFIR, "no shelling any land" }, - { NEWSHP, "no building ships" }, - { NEWNUK, "no new nuclear weapons" }, - { NEWPLN, "no building planes" }, - { NEWLND, "no building land units" }, - { TRTENL, "no enlistment" }, - { 0, 0 } +struct tchrstr tchr[] = { + {LNDATT, "no attacks on any land units"}, + {SEAATT, "no attacks on any ships"}, + {SEAFIR, "no shelling any ships"}, + {SUBFIR, "no depth-charging any subs"}, + {LANATT, "no sector attacks"}, + {LANFIR, "no shelling any land"}, + {NEWSHP, "no building ships"}, + {NEWNUK, "no new nuclear weapons"}, + {NEWPLN, "no building planes"}, + {NEWLND, "no building land units"}, + {TRTENL, "no enlistment"}, + {0, 0} }; -int trt_maxno = (sizeof(tchr) / sizeof(struct tchrstr)) - 1; +int trt_maxno = (sizeof(tchr) / sizeof(struct tchrstr)) - 1; diff --git a/src/lib/lwp/arch.c b/src/lib/lwp/arch.c index a1966ae8a..b03774dd5 100644 --- a/src/lib/lwp/arch.c +++ b/src/lib/lwp/arch.c @@ -45,198 +45,211 @@ #if defined(hpc) static struct lwpProc *tempcontext; -struct lwpProc *initcontext=NULL; +struct lwpProc *initcontext = NULL; int startpoint; startcontext() { - int space[10000]; - int x; + int space[10000]; + int x; - startpoint = (void *) &x; - if (!setjmp(initcontext->context)) longjmp(tempcontext->context,1); + startpoint = (void *)&x; + if (!setjmp(initcontext->context)) + longjmp(tempcontext->context, 1); - if (!setjmp(tempcontext->context)) longjmp(LwpCurrent->context,1); + if (!setjmp(tempcontext->context)) + longjmp(LwpCurrent->context, 1); - lwpEntryPoint(); + lwpEntryPoint(); } -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - struct lwpProc holder; - int endpoint; - - if (initcontext == NULL) { - initcontext = (struct lwpProc *) malloc (sizeof(struct lwpProc)); - tempcontext = &holder; - if (!setjmp(tempcontext->context)) startcontext(); - } - - tempcontext = newp; - endpoint = &endpoint; - if (endpoint < startpoint) { - if (!setjmp(LwpCurrent->context)) longjmp(initcontext->context,1); - } else { - LwpCurrent->size = endpoint - startpoint; - LwpCurrent->sbtm = realloc(LwpCurrent->sbtm, LwpCurrent->size); - memcpy(LwpCurrent->sbtm, startpoint, LwpCurrent->size); - if (!setjmp(LwpCurrent->context)) longjmp(initcontext->context,1); - memcpy(startpoint, LwpCurrent->sbtm, LwpCurrent->size); - } + struct lwpProc holder; + int endpoint; + + if (initcontext == NULL) { + initcontext = (struct lwpProc *)malloc(sizeof(struct lwpProc)); + tempcontext = &holder; + if (!setjmp(tempcontext->context)) + startcontext(); + } + + tempcontext = newp; + endpoint = &endpoint; + if (endpoint < startpoint) { + if (!setjmp(LwpCurrent->context)) + longjmp(initcontext->context, 1); + } else { + LwpCurrent->size = endpoint - startpoint; + LwpCurrent->sbtm = realloc(LwpCurrent->sbtm, LwpCurrent->size); + memcpy(LwpCurrent->sbtm, startpoint, LwpCurrent->size); + if (!setjmp(LwpCurrent->context)) + longjmp(initcontext->context, 1); + memcpy(startpoint, LwpCurrent->sbtm, LwpCurrent->size); + } } #elif defined(hpux) -void lwpInitContext(newp, sp) - volatile struct lwpProc *volatile newp; - void *sp; +void +lwpInitContext(newp, sp) +volatile struct lwpProc *volatile newp; +void *sp; { static jmp_buf *cpp; extern struct lwpProc *LwpCurrent; if (!lwpSave(LwpCurrent->context)) { - cpp = (jmp_buf *)&newp->context; - asm volatile ("ldw %0, %%sp": : "o" (sp)); + cpp = (jmp_buf *) & newp->context; + asm volatile ("ldw %0, %%sp"::"o" (sp)); if (!lwpSave(*cpp)) lwpRestore(LwpCurrent->context); lwpEntryPoint(); } } -int lwpSave(jb) - jmp_buf jb; +int +lwpSave(jb) +jmp_buf jb; { - /* save stack pointer and return program counter */ - asm ("stw %sp, 4(%arg0)"); - asm ("stw %rp, 8(%arg0)"); - - /* save "callee save" registers */ - asm ("stw %r3, 12(%arg0)"); - asm ("stw %r4, 16(%arg0)"); - asm ("stw %r5, 20(%arg0)"); - asm ("stw %r6, 24(%arg0)"); - asm ("stw %r7, 28(%arg0)"); - asm ("stw %r8, 32(%arg0)"); - asm ("stw %r9, 36(%arg0)"); - asm ("stw %r10, 40(%arg0)"); - asm ("stw %r11, 44(%arg0)"); - asm ("stw %r12, 48(%arg0)"); - asm ("stw %r13, 52(%arg0)"); - asm ("stw %r14, 56(%arg0)"); - asm ("stw %r15, 60(%arg0)"); - asm ("stw %r16, 64(%arg0)"); - asm ("stw %r17, 68(%arg0)"); - asm ("stw %r18, 72(%arg0)"); - - /* save "callee save" space register */ - asm volatile ("mfsp %sr3, %r1"); - asm ("stw %r1, 0(%arg0)"); - - /* indicate "true return" from saved() */ - asm ("ldi 0, %ret0"); - - asm (".LABEL _comefrom_"); + /* save stack pointer and return program counter */ + asm("stw %sp, 4(%arg0)"); + asm("stw %rp, 8(%arg0)"); + + /* save "callee save" registers */ + asm("stw %r3, 12(%arg0)"); + asm("stw %r4, 16(%arg0)"); + asm("stw %r5, 20(%arg0)"); + asm("stw %r6, 24(%arg0)"); + asm("stw %r7, 28(%arg0)"); + asm("stw %r8, 32(%arg0)"); + asm("stw %r9, 36(%arg0)"); + asm("stw %r10, 40(%arg0)"); + asm("stw %r11, 44(%arg0)"); + asm("stw %r12, 48(%arg0)"); + asm("stw %r13, 52(%arg0)"); + asm("stw %r14, 56(%arg0)"); + asm("stw %r15, 60(%arg0)"); + asm("stw %r16, 64(%arg0)"); + asm("stw %r17, 68(%arg0)"); + asm("stw %r18, 72(%arg0)"); + + /* save "callee save" space register */ + asm volatile ("mfsp %sr3, %r1"); + asm("stw %r1, 0(%arg0)"); + + /* indicate "true return" from saved() */ + asm("ldi 0, %ret0"); + + asm(".LABEL _comefrom_"); } void lwpRestore(jb) - jmp_buf jb; +jmp_buf jb; { - /* restore stack pointer and program counter */ - asm volatile ("ldw 4(%arg0), %sp"); - asm volatile ("ldw 8(%arg0), %rp"); - - /* restore "callee save" space register */ - asm volatile ("ldw 0(%arg0), %r1"); - asm volatile ("mtsp %r1, %sr3"); - - /* restore "callee save" registers */ - asm volatile ("ldw 12(%arg0), %r3"); - asm volatile ("ldw 16(%arg0), %r4"); - asm volatile ("ldw 20(%arg0), %r5"); - asm volatile ("ldw 24(%arg0), %r6"); - asm volatile ("ldw 28(%arg0), %r7"); - asm volatile ("ldw 32(%arg0), %r8"); - asm volatile ("ldw 36(%arg0), %r9"); - asm volatile ("ldw 40(%arg0), %r10"); - asm volatile ("ldw 44(%arg0), %r11"); - asm volatile ("ldw 48(%arg0), %r12"); - asm volatile ("ldw 52(%arg0), %r13"); - asm volatile ("ldw 56(%arg0), %r14"); - asm volatile ("ldw 60(%arg0), %r15"); - asm volatile ("ldw 64(%arg0), %r16"); - asm volatile ("ldw 68(%arg0), %r17"); - asm volatile ("ldw 72(%arg0), %r18"); - - /* warp to saved() to unwind the frame correctly */ - asm volatile ("bl _comefrom_, %r0"); - asm volatile ("ldi 1, %ret0"); + /* restore stack pointer and program counter */ + asm volatile ("ldw 4(%arg0), %sp"); + asm volatile ("ldw 8(%arg0), %rp"); + + /* restore "callee save" space register */ + asm volatile ("ldw 0(%arg0), %r1"); + asm volatile ("mtsp %r1, %sr3"); + + /* restore "callee save" registers */ + asm volatile ("ldw 12(%arg0), %r3"); + asm volatile ("ldw 16(%arg0), %r4"); + asm volatile ("ldw 20(%arg0), %r5"); + asm volatile ("ldw 24(%arg0), %r6"); + asm volatile ("ldw 28(%arg0), %r7"); + asm volatile ("ldw 32(%arg0), %r8"); + asm volatile ("ldw 36(%arg0), %r9"); + asm volatile ("ldw 40(%arg0), %r10"); + asm volatile ("ldw 44(%arg0), %r11"); + asm volatile ("ldw 48(%arg0), %r12"); + asm volatile ("ldw 52(%arg0), %r13"); + asm volatile ("ldw 56(%arg0), %r14"); + asm volatile ("ldw 60(%arg0), %r15"); + asm volatile ("ldw 64(%arg0), %r16"); + asm volatile ("ldw 68(%arg0), %r17"); + asm volatile ("ldw 72(%arg0), %r18"); + + /* warp to saved() to unwind the frame correctly */ + asm volatile ("bl _comefrom_, %r0"); + asm volatile ("ldi 1, %ret0"); } #elif defined(BSD386) -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - newp->context[2] = (int)sp; - newp->context[0] = (int)lwpEntryPoint; + newp->context[2] = (int)sp; + newp->context[0] = (int)lwpEntryPoint; } #elif defined(FBSD) -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - setjmp (newp->context); - newp->context->_jb[2] = (int)sp; - newp->context->_jb[3] = (int)sp; - newp->context->_jb[0] = (int)lwpEntryPoint; + setjmp(newp->context); + newp->context->_jb[2] = (int)sp; + newp->context->_jb[3] = (int)sp; + newp->context->_jb[0] = (int)lwpEntryPoint; } #elif defined(__linux__) -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { #if defined(__GLIBC__) && (__GLIBC__ >= 2) #if defined(__PPC__) - newp->context->__jmpbuf[JB_GPR1] = (int) sp; - newp->context->__jmpbuf[JB_LR] = (int) lwpEntryPoint; + newp->context->__jmpbuf[JB_GPR1] = (int)sp; + newp->context->__jmpbuf[JB_LR] = (int)lwpEntryPoint; #else - newp->context->__jmpbuf[JB_SP] = (int) sp; - newp->context->__jmpbuf[JB_BP] = (int) sp; - newp->context->__jmpbuf[JB_PC] = (int) lwpEntryPoint; + newp->context->__jmpbuf[JB_SP] = (int)sp; + newp->context->__jmpbuf[JB_BP] = (int)sp; + newp->context->__jmpbuf[JB_PC] = (int)lwpEntryPoint; #endif #else - newp->context->__sp = sp; - newp->context->__bp = sp; - newp->context->__pc = (void *)lwpEntryPoint; + newp->context->__sp = sp; + newp->context->__bp = sp; + newp->context->__pc = (void *)lwpEntryPoint; #endif } #elif defined(SUN3) -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - newp->context[2] = (int)sp; - newp->context[3] = (int)lwpEntryPoint; + newp->context[2] = (int)sp; + newp->context[3] = (int)lwpEntryPoint; } #elif defined(__vax) #include -void lwpInitContext(newp, stack) - struct lwpProc *newp; - void *stack; +void +lwpInitContext(newp, stack) +struct lwpProc *newp; +void *stack; { - int *sp = (int*)stack; + int *sp = (int *)stack; int *fp = 0; /* Build root frame on new stack for lwpEntryPoint */ @@ -248,7 +261,7 @@ void lwpInitContext(newp, stack) fp = sp; /* Build stack frame to return from. */ - *--sp = (int)lwpEntryPoint+2;/* pc */ + *--sp = (int)lwpEntryPoint + 2; /* pc */ *--sp = (int)fp; /* fp */ *--sp = 0; /* ap */ *--sp = 0; /* psw */ @@ -268,8 +281,9 @@ void lwpInitContext(newp, stack) return; } -int lwpSave(jb) - jmp_buf jb; +int +lwpSave(jb) +jmp_buf jb; { asm("movl 4(ap), r0"); /* r0 = &jb */ asm("movl r6, (r0)"); /* jb[0] = r6 */ @@ -283,8 +297,9 @@ int lwpSave(jb) return 0; } -void lwpRestore(jb) - jmp_buf jb; +void +lwpRestore(jb) +jmp_buf jb; { asm("movl 4(ap), r0"); /* r0 = &jb */ asm("movl (r0), r6"); /* r6 = jb[0] */ @@ -303,31 +318,32 @@ void lwpRestore(jb) #elif defined(SUN4) -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - static jmp_buf *cpp; - extern struct lwpProc *LwpCurrent; - - bzero(newp->context, sizeof(newp->context)); - newp->context[0] = (int)sp; - /* preserve cpp for new context */ - cpp = (jmp_buf *)&newp->context; - if (!_setjmp(LwpCurrent->context)) { - /* create new context */ - /* flush registers */ - asm ("ta 0x03"); - /* %o0 <- newp */ - asm ("ld [%fp+0x44], %o0"); - /* %o1 <- newp->context[0] */ - asm ("ld [%o0], %o1"); - /* create min frame on new stack */ - asm ("save %o1,-96, %sp"); - if (!_setjmp(*cpp)) - _longjmp(LwpCurrent->context, 1); - lwpEntryPoint(); - } + static jmp_buf *cpp; + extern struct lwpProc *LwpCurrent; + + bzero(newp->context, sizeof(newp->context)); + newp->context[0] = (int)sp; + /* preserve cpp for new context */ + cpp = (jmp_buf *) & newp->context; + if (!_setjmp(LwpCurrent->context)) { + /* create new context */ + /* flush registers */ + asm("ta 0x03"); + /* %o0 <- newp */ + asm("ld [%fp+0x44], %o0"); + /* %o1 <- newp->context[0] */ + asm("ld [%o0], %o1"); + /* create min frame on new stack */ + asm("save %o1,-96, %sp"); + if (!_setjmp(*cpp)) + _longjmp(LwpCurrent->context, 1); + lwpEntryPoint(); + } } #elif defined(__USLC__) && defined(i386) @@ -360,12 +376,13 @@ void lwpInitContext(newp, sp) * context + 0x14 [5] -> jump location for return */ -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - newp->context[4] = (int)sp; - newp->context[5] = (int)lwpEntryPoint; + newp->context[4] = (int)sp; + newp->context[5] = (int)lwpEntryPoint; } #elif defined UCONTEXT @@ -375,50 +392,54 @@ void lwpInitContext(newp, sp) * longjump. This should work on any SVr4 machine independant of * architecture. Unfortunaltely some changes are still nessesary in lwp.c. * Tested on IRIX 5.3 - */ + */ -void lwpInitContext(newp, spp) - struct lwpProc *newp; - stack_t *spp; +void +lwpInitContext(newp, spp) +struct lwpProc *newp; +stack_t *spp; { - getcontext (&(newp->context)); - newp->context.uc_stack.ss_sp = spp->ss_sp; - newp->context.uc_stack.ss_size = spp->ss_size; - makecontext (&(newp->context), lwpEntryPoint, 0); + getcontext(&(newp->context)); + newp->context.uc_stack.ss_sp = spp->ss_sp; + newp->context.uc_stack.ss_size = spp->ss_size; + makecontext(&(newp->context), lwpEntryPoint, 0); } #elif defined(ALPHA) #include -void lwpInitContext(newp, sp) - struct lwpProc *newp; - void *sp; +void +lwpInitContext(newp, sp) +struct lwpProc *newp; +void *sp; { - extern long *_gp; - - /* register values obtained from setjmp.h */ - _setjmp(newp->context); - newp->context[2] = (long)lwpEntryPoint; /* program counter */ - newp->context[30] = (long)lwpEntryPoint; /* return address */ - newp->context[31] = (long)lwpEntryPoint; /* fake program value (!) */ - newp->context[34] = (long)sp; /* stack pointer */ + extern long *_gp; + + /* register values obtained from setjmp.h */ + _setjmp(newp->context); + newp->context[2] = (long)lwpEntryPoint; /* program counter */ + newp->context[30] = (long)lwpEntryPoint; /* return address */ + newp->context[31] = (long)lwpEntryPoint; /* fake program value (!) */ + newp->context[34] = (long)sp; /* stack pointer */ } -int lwpSave(jb) - jmp_buf jb; +int +lwpSave(jb) +jmp_buf jb; { - return _setjmp(jb); + return _setjmp(jb); } -void lwpRestore(jb) - jmp_buf jb; +void +lwpRestore(jb) +jmp_buf jb; { - /* resume, but get the pv from the jmp_buf */ - asm("ldq %pv, 248(%a0)"); - asm("stq %a0, 16(%sp)"); - /* generates a warning, but functions just fine */ - asm("bsr %ra, __longjump_resume"); + /* resume, but get the pv from the jmp_buf */ + asm("ldq %pv, 248(%a0)"); + asm("stq %a0, 16(%sp)"); + /* generates a warning, but functions just fine */ + asm("bsr %ra, __longjump_resume"); } #endif diff --git a/src/lib/lwp/lwp.c b/src/lib/lwp/lwp.c index f6b3b12fd..3bef1e0c8 100644 --- a/src/lib/lwp/lwp.c +++ b/src/lib/lwp/lwp.c @@ -41,16 +41,16 @@ extern struct lwpProc *initcontext; extern int startpoint; #endif -struct lwpQueue LwpSchedQ[LWP_MAX_PRIO], LwpDeadQ; +struct lwpQueue LwpSchedQ[LWP_MAX_PRIO], LwpDeadQ; -struct lwpProc *LwpCurrent = NULL; -char **LwpContextPtr; -int LwpMaxpri=0; /* maximum priority so far */ +struct lwpProc *LwpCurrent = NULL; +char **LwpContextPtr; +int LwpMaxpri = 0; /* maximum priority so far */ #ifdef POSIXSIGNALS -static sigset_t oldmask; -#else /* POSIXSIGNALS */ -static int oldmask; +static sigset_t oldmask; +#else /* POSIXSIGNALS */ +static int oldmask; #endif /* POSIXSIGNALS */ /* for systems without strdup */ @@ -58,169 +58,168 @@ static int oldmask; extern char *strdup(); #endif /* NOSTRDUP */ -static void lwpStackCheckInit(); -static int lwpStackCheck(); -static void lwpStackCheckUsed(); +static void lwpStackCheckInit(); +static int lwpStackCheck(); +static void lwpStackCheckUsed(); /* check stack direction */ -static int growsdown (x) - void *x; +static int +growsdown(x) +void *x; { - int y; - + int y; + #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_OFF; + BOUNDS_CHECKING_OFF; #endif - y = (x > (void *)&y); + y = (x > (void *)&y); #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_ON; + BOUNDS_CHECKING_ON; #endif - - return y; + + return y; } /* * lwpReschedule -- schedule another process. we also check for dead * processes here and free them. */ -void lwpReschedule() +void +lwpReschedule() { - extern struct lwpQueue LwpSchedQ[]; - static int lcount = LCOUNT; - static struct lwpProc *nextp; - static int i; + extern struct lwpQueue LwpSchedQ[]; + static int lcount = LCOUNT; + static struct lwpProc *nextp; + static int i; #ifdef POSIXSIGNALS - static sigset_t tmask; + static sigset_t tmask; #endif /* POSIXSIGNALS */ - if (LwpCurrent && (LwpCurrent->flags & LWP_STACKCHECK)) { - lwpStackCheck(LwpCurrent); - } - if (!--lcount) { - int p = lwpSetPriority(LWP_MAX_PRIO-1); - lcount = LCOUNT; + if (LwpCurrent && (LwpCurrent->flags & LWP_STACKCHECK)) { + lwpStackCheck(LwpCurrent); + } + if (!--lcount) { + int p = lwpSetPriority(LWP_MAX_PRIO - 1); + lcount = LCOUNT; #ifdef POSIXSIGNALS - sigprocmask (SIG_SETMASK, &oldmask, &tmask); - sigprocmask (SIG_SETMASK, &tmask, &oldmask); -#else /* POSIXSIGNALS */ - sigsetmask(sigsetmask(oldmask)); + sigprocmask(SIG_SETMASK, &oldmask, &tmask); + sigprocmask(SIG_SETMASK, &tmask, &oldmask); +#else /* POSIXSIGNALS */ + sigsetmask(sigsetmask(oldmask)); #endif /* POSIXSIGNALS */ - LwpCurrent->pri = p; + LwpCurrent->pri = p; + } + + /* destroy dead threads */ + lwpStatus(LwpCurrent, "Cleaning dead queue"); + while (NULL != (nextp = lwpGetFirst(&LwpDeadQ))) { + if (nextp == LwpCurrent) { + lwpStatus(nextp, "OOOPS, we are running already dead thread"); + exit(1); } - - /* destroy dead threads */ - lwpStatus(LwpCurrent, "Cleaning dead queue"); - while (NULL != (nextp = lwpGetFirst(&LwpDeadQ))) { - if (nextp == LwpCurrent) { - lwpStatus(nextp, - "OOOPS, we are running already dead thread"); - exit(1); - } + lwpDestroy(nextp); + lwpStatus(LwpCurrent, "Destroying done"); + } + + for (i = LwpMaxpri + 1; i--;) { + while (NULL != (nextp = lwpGetFirst(&LwpSchedQ[i]))) { + if (!nextp->dead) + break; + /* clean up after dead bodies */ + lwpStatus(nextp, "got a dead body"); + if (nextp == LwpCurrent) { + lwpStatus(nextp, "we are in it -- will bury later"); + lwpAddTail(&LwpDeadQ, nextp); + } else { lwpDestroy(nextp); - lwpStatus(LwpCurrent, "Destroying done"); - } - - for (i=LwpMaxpri+1; i--; ) { - while (NULL != (nextp = lwpGetFirst(&LwpSchedQ[i]))) { - if (!nextp->dead) - break; - /* clean up after dead bodies */ - lwpStatus(nextp, "got a dead body"); - if (nextp == LwpCurrent) { - lwpStatus(nextp, - "we are in it -- will bury later"); - lwpAddTail(&LwpDeadQ, nextp); - } - else{ - lwpDestroy(nextp); /* fprintf(stderr, "Destroying done\n"); */ - } - nextp = 0; - } - if (nextp) - break; - } - if (LwpCurrent == 0 && nextp == 0) { - fprintf(stderr, "No processes to run!\n"); - exit(1); + } + nextp = 0; } - if (LwpCurrent) - lwpStatus(LwpCurrent, "switch out"); - /* do context switch */ + if (nextp) + break; + } + if (LwpCurrent == 0 && nextp == 0) { + fprintf(stderr, "No processes to run!\n"); + exit(1); + } + if (LwpCurrent) + lwpStatus(LwpCurrent, "switch out"); + /* do context switch */ #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_OFF; + BOUNDS_CHECKING_OFF; #endif #if defined(hpc) - { - int endpoint; - - endpoint = &endpoint; - if (initcontext == NULL || endpoint < startpoint) { - i = lwpSave(LwpCurrent->context); - } else { - LwpCurrent->size = endpoint - startpoint; - LwpCurrent->sbtm = realloc(LwpCurrent->sbtm, LwpCurrent->size); - memcpy(LwpCurrent->sbtm, startpoint, LwpCurrent->size); - if (i = lwpSave(LwpCurrent->context)) { - memcpy(startpoint, LwpCurrent->sbtm, LwpCurrent->size); - i = 1; - } - } + { + int endpoint; + + endpoint = &endpoint; + if (initcontext == NULL || endpoint < startpoint) { + i = lwpSave(LwpCurrent->context); + } else { + LwpCurrent->size = endpoint - startpoint; + LwpCurrent->sbtm = realloc(LwpCurrent->sbtm, LwpCurrent->size); + memcpy(LwpCurrent->sbtm, startpoint, LwpCurrent->size); + if (i = lwpSave(LwpCurrent->context)) { + memcpy(startpoint, LwpCurrent->sbtm, LwpCurrent->size); + i = 1; + } } + } #else - i = lwpSave(LwpCurrent->context); + i = lwpSave(LwpCurrent->context); #endif #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_ON; + BOUNDS_CHECKING_ON; #endif - - if (LwpCurrent != nextp && - !(LwpCurrent && i)) { - /* restore previous context */ - lwpStatus(nextp, "switch in", nextp->pri); - LwpCurrent = nextp; - *LwpContextPtr = LwpCurrent->ud; + + if (LwpCurrent != nextp && !(LwpCurrent && i)) { + /* restore previous context */ + lwpStatus(nextp, "switch in", nextp->pri); + LwpCurrent = nextp; + *LwpContextPtr = LwpCurrent->ud; #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_OFF; + BOUNDS_CHECKING_OFF; #endif - lwpRestore(LwpCurrent->context); + lwpRestore(LwpCurrent->context); #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_ON; + BOUNDS_CHECKING_ON; #endif - } + } } /* * lwpEntryPoint -- process entry point. */ -void lwpEntryPoint() +void +lwpEntryPoint() { - extern struct lwpProc *LwpCurrent; + extern struct lwpProc *LwpCurrent; #ifdef POSIXSIGNALS - sigset_t set; + sigset_t set; #endif /* POSIXSIGNALS */ #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_OFF; + BOUNDS_CHECKING_OFF; #endif #ifdef POSIXSIGNALS - sigemptyset (&set); - sigaddset (&set, SIGALRM); - sigprocmask (SIG_SETMASK, &set, &oldmask); -#else /* POSIXSIGNALS */ - sigsetmask(SIGNALS); + sigemptyset(&set); + sigaddset(&set, SIGALRM); + sigprocmask(SIG_SETMASK, &set, &oldmask); +#else /* POSIXSIGNALS */ + sigsetmask(SIGNALS); #endif /* POSIXSIGNALS */ - *LwpContextPtr = LwpCurrent->ud; + *LwpContextPtr = LwpCurrent->ud; - lwpStatus(LwpCurrent, "starting at entry point"); - (*LwpCurrent->entry)(LwpCurrent->argc, LwpCurrent->argv, - LwpCurrent->ud); - lwpExit(); + lwpStatus(LwpCurrent, "starting at entry point"); + (*LwpCurrent->entry) (LwpCurrent->argc, LwpCurrent->argv, + LwpCurrent->ud); + lwpExit(); #ifdef BOUNDS_CHECK - BOUNDS_CHECKING_ON; + BOUNDS_CHECKING_ON; #endif @@ -231,274 +230,284 @@ void lwpEntryPoint() */ struct lwpProc * lwpCreate(priority, entry, size, flags, name, desc, argc, argv, ud) - int priority; - void (*entry)(); - int size; - int flags; - char *name; - char *desc; - int argc; - char *argv[]; - void *ud; +int priority; +void (*entry) (); +int size; +int flags; +char *name; +char *desc; +int argc; +char *argv[]; +void *ud; { - extern struct lwpProc *LwpCurrent; - struct lwpProc *newp; - int *s, x; + extern struct lwpProc *LwpCurrent; + struct lwpProc *newp; + int *s, x; #ifdef UCONTEXT - stack_t sp; -#else /* UCONTEXT */ - void *sp; + stack_t sp; +#else /* UCONTEXT */ + void *sp; #endif /* UCONTEXT */ - unsigned long stackp; - - if (!(newp = (struct lwpProc *)malloc(sizeof(struct lwpProc)))) - return (0); - if (flags & LWP_STACKCHECK) { - /* Add a 1K buffer on each side of the stack */ - size += 2 * LWP_REDZONE; - } - size += LWP_EXTRASTACK; - size += sizeof(stkalign_t); - if (!(s = (int *)malloc(size))) - return (0); - newp->flags = flags; - newp->name = strdup(name); - newp->desc = strdup(desc); - newp->entry = entry; - newp->argc = argc; - newp->argv = argv; - newp->ud = ud; - if ((newp->flags & LWP_STACKCHECK) == 0) { - stackp = growsdown((void *)&x) ? - (((long)s) + size - sizeof(stkalign_t) - LWP_EXTRASTACK) : - (long) s + LWP_EXTRASTACK; + unsigned long stackp; + + if (!(newp = (struct lwpProc *)malloc(sizeof(struct lwpProc)))) + return (0); + if (flags & LWP_STACKCHECK) { + /* Add a 1K buffer on each side of the stack */ + size += 2 * LWP_REDZONE; + } + size += LWP_EXTRASTACK; + size += sizeof(stkalign_t); + if (!(s = (int *)malloc(size))) + return (0); + newp->flags = flags; + newp->name = strdup(name); + newp->desc = strdup(desc); + newp->entry = entry; + newp->argc = argc; + newp->argv = argv; + newp->ud = ud; + if ((newp->flags & LWP_STACKCHECK) == 0) { + stackp = growsdown((void *)&x) ? + (((long)s) + size - sizeof(stkalign_t) - LWP_EXTRASTACK) : + (long)s + LWP_EXTRASTACK; #ifdef UCONTEXT - sp.ss_sp = (void *)(stackp & -sizeof(stkalign_t)); - sp.ss_size = size; - sp.ss_flags = 0; -#else /* UCONTEXT */ - sp = (void *)(stackp & -sizeof(stkalign_t)); + sp.ss_sp = (void *)(stackp & -sizeof(stkalign_t)); + sp.ss_size = size; + sp.ss_flags = 0; +#else /* UCONTEXT */ + sp = (void *)(stackp & -sizeof(stkalign_t)); #endif /* UCONTEXT */ - } else { - if (growsdown(&x)) { - /* round address off to stkalign_t */ - stackp = ((long)s) + size - LWP_REDZONE - - LWP_EXTRASTACK - sizeof(stkalign_t); -#ifdef UCONTEXT - sp.ss_sp = (void *)(stackp & -sizeof(stkalign_t)); - sp.ss_size = size; - sp.ss_flags = 0; - newp->lowmark = (void *)(((long) sp.ss_sp) + LWP_EXTRASTACK); -#else /* UCONTEXT */ - sp = (void *)(stackp & -sizeof(stkalign_t)); - newp->lowmark = (void *)(((long) sp) + LWP_EXTRASTACK); + } else { + if (growsdown(&x)) { + /* round address off to stkalign_t */ + stackp = ((long)s) + size - LWP_REDZONE - + LWP_EXTRASTACK - sizeof(stkalign_t); +#ifdef UCONTEXT + sp.ss_sp = (void *)(stackp & -sizeof(stkalign_t)); + sp.ss_size = size; + sp.ss_flags = 0; + newp->lowmark = (void *)(((long)sp.ss_sp) + LWP_EXTRASTACK); +#else /* UCONTEXT */ + sp = (void *)(stackp & -sizeof(stkalign_t)); + newp->lowmark = (void *)(((long)sp) + LWP_EXTRASTACK); #endif /* UCONTEXT */ - newp->himark = s; - } else { - stackp = ((long)s) + LWP_REDZONE + LWP_EXTRASTACK; -#ifdef UCONTEXT - sp.ss_sp = (void *)(((long)stackp) & - -sizeof(stkalign_t)); - sp.ss_size = size; - sp.ss_flags = 0; -#else /* UCONTEXT */ - sp = (void *)(((long)stackp) & -sizeof(stkalign_t)); + newp->himark = s; + } else { + stackp = ((long)s) + LWP_REDZONE + LWP_EXTRASTACK; +#ifdef UCONTEXT + sp.ss_sp = (void *)(((long)stackp) & -sizeof(stkalign_t)); + sp.ss_size = size; + sp.ss_flags = 0; +#else /* UCONTEXT */ + sp = (void *)(((long)stackp) & -sizeof(stkalign_t)); #endif /* UCONTEXT */ - newp->lowmark = (void *)s; - newp->himark = (void *)(((long)s) + size - LWP_REDZONE); - } + newp->lowmark = (void *)s; + newp->himark = (void *)(((long)s) + size - LWP_REDZONE); } - if (LWP_MAX_PRIO <= priority) - priority = LWP_MAX_PRIO-1; - if (LwpMaxpri < (newp->pri = priority)) - LwpMaxpri = priority; - newp->sbtm = (void *)s; - newp->size = size; - newp->dead = 0; - if (flags & LWP_STACKCHECK) - lwpStackCheckInit(newp); - lwpStatus(newp, "creating process structure sbtm: %d", - (int)newp->sbtm); - lwpReady(newp); - lwpReady(LwpCurrent); + } + if (LWP_MAX_PRIO <= priority) + priority = LWP_MAX_PRIO - 1; + if (LwpMaxpri < (newp->pri = priority)) + LwpMaxpri = priority; + newp->sbtm = (void *)s; + newp->size = size; + newp->dead = 0; + if (flags & LWP_STACKCHECK) + lwpStackCheckInit(newp); + lwpStatus(newp, "creating process structure sbtm: %d", + (int)newp->sbtm); + lwpReady(newp); + lwpReady(LwpCurrent); #ifdef UCONTEXT - lwpInitContext(newp, &sp); /* architecture-dependent: from arch.c */ -#else /* UCONTEXT */ - lwpInitContext(newp, sp); /* architecture-dependent: from arch.c */ + lwpInitContext(newp, &sp); /* architecture-dependent: from arch.c */ +#else /* UCONTEXT */ + lwpInitContext(newp, sp); /* architecture-dependent: from arch.c */ #endif /* UCONTEXT */ - lwpReschedule(); - return (newp); + lwpReschedule(); + return (newp); } -void lwpDestroy(proc) - struct lwpProc *proc; +void +lwpDestroy(proc) +struct lwpProc *proc; { - if (proc->flags & LWP_STACKCHECK){ - lwpStackCheckUsed(proc); - lwpStackCheck(proc); - } - lwpStatus(proc, "destroying sbtm: %d", (int)proc->sbtm); - proc->entry = 0; - proc->ud = 0; - proc->argv = 0; - free((char *)proc->sbtm); - free(proc->name); - free(proc->desc); - proc->name = 0; - proc->desc = 0; - proc->sbtm = 0; - proc->lowmark = 0; - proc->himark = 0; - free((char *)proc); + if (proc->flags & LWP_STACKCHECK) { + lwpStackCheckUsed(proc); + lwpStackCheck(proc); + } + lwpStatus(proc, "destroying sbtm: %d", (int)proc->sbtm); + proc->entry = 0; + proc->ud = 0; + proc->argv = 0; + free((char *)proc->sbtm); + free(proc->name); + free(proc->desc); + proc->name = 0; + proc->desc = 0; + proc->sbtm = 0; + proc->lowmark = 0; + proc->himark = 0; + free((char *)proc); } /* * lwpReady -- put process on ready queue. if null, assume current. */ -void lwpReady(p) - struct lwpProc *p; +void +lwpReady(p) +struct lwpProc *p; { - extern struct lwpProc *LwpCurrent; - extern struct lwpQueue LwpSchedQ[]; + extern struct lwpProc *LwpCurrent; + extern struct lwpQueue LwpSchedQ[]; - if (!p) - p = LwpCurrent; - lwpStatus(p, "added to run queue"); - lwpAddTail(&LwpSchedQ[p->pri], p); + if (!p) + p = LwpCurrent; + lwpStatus(p, "added to run queue"); + lwpAddTail(&LwpSchedQ[p->pri], p); } /* * return user's data */ -void *lwpGetUD(p) - struct lwpProc *p; +void * +lwpGetUD(p) +struct lwpProc *p; { - if (!p) - p = LwpCurrent; - return (p->ud); + if (!p) + p = LwpCurrent; + return (p->ud); } /* * set user's data */ -void lwpSetUD(p, ud) - struct lwpProc *p; - char *ud; +void +lwpSetUD(p, ud) +struct lwpProc *p; +char *ud; { - if (!p) - p = LwpCurrent; - p->ud = ud; + if (!p) + p = LwpCurrent; + p->ud = ud; } /* * set name & desc */ -void lwpSetDesc(p, name, desc) - struct lwpProc *p; - char *name; - char *desc; +void +lwpSetDesc(p, name, desc) +struct lwpProc *p; +char *name; +char *desc; { - if (!p) - p = LwpCurrent; - free(p->name); - free(p->desc); - p->name = strdup(name); - p->desc = strdup(desc); + if (!p) + p = LwpCurrent; + free(p->name); + free(p->desc); + p->name = strdup(name); + p->desc = strdup(desc); } /* * lwpYield -- yield the processor to another thread. */ -void lwpYield() +void +lwpYield() { - lwpStatus(LwpCurrent, "yielding control"); - lwpReady(LwpCurrent); - lwpReschedule(); + lwpStatus(LwpCurrent, "yielding control"); + lwpReady(LwpCurrent); + lwpReschedule(); } /* * cause the current process to be scheduled for deletion. */ -void lwpExit() +void +lwpExit() { - lwpStatus(LwpCurrent, "marking self as dead"); - LwpCurrent->dead = 1; - lwpYield(); + lwpStatus(LwpCurrent, "marking self as dead"); + LwpCurrent->dead = 1; + lwpYield(); } /* * mark another process as dead, so it will never be rescheduled. * remove any lingering FD action */ -void lwpTerminate(p) - struct lwpProc *p; +void +lwpTerminate(p) +struct lwpProc *p; { - lwpStatus(p, "terminating process"); - p->dead = 1; - if (p->fd >= 0) - lwpWakeupFd(p); + lwpStatus(p, "terminating process"); + p->dead = 1; + if (p->fd >= 0) + lwpWakeupFd(p); } /* * set the thread's priority, returning the old. * if the new priority is lower than the old, we reschedule. */ -int lwpSetPriority(new) - int new; +int +lwpSetPriority(new) +int new; { - int old = LwpCurrent->pri; - - if (LWP_MAX_PRIO <= new) - new = LWP_MAX_PRIO-1; - if (LwpMaxpri < new) - LwpMaxpri = new; - LwpCurrent->pri = new; - lwpStatus(LwpCurrent, "resetting priority (%d -> %d)", old, new); - if (new < old) - lwpYield(); - return (old); + int old = LwpCurrent->pri; + + if (LWP_MAX_PRIO <= new) + new = LWP_MAX_PRIO - 1; + if (LwpMaxpri < new) + LwpMaxpri = new; + LwpCurrent->pri = new; + lwpStatus(LwpCurrent, "resetting priority (%d -> %d)", old, new); + if (new < old) + lwpYield(); + return (old); } /* * initialise the coroutine structures */ -struct lwpProc *lwpInitSystem(pri, ctxptr, flags) - int pri; - char **ctxptr; - int flags; +struct lwpProc * +lwpInitSystem(pri, ctxptr, flags) +int pri; +char **ctxptr; +int flags; { - extern struct lwpQueue LwpSchedQ[]; - extern struct lwpProc *LwpCurrent; - struct lwpQueue *q; - int i, *stack; - struct lwpProc *sel; - - LwpContextPtr = ctxptr; - if (pri < 1) - pri = 1; - /* *LwpContextPtr = 0; */ - if (!(LwpCurrent = (struct lwpProc *)calloc (1, sizeof(struct lwpProc)))) - return (0); - if (!(stack = (int *)malloc(64))) - return (0); - if (LWP_MAX_PRIO <= pri) - pri = LWP_MAX_PRIO-1; - if (LwpMaxpri < pri) - LwpMaxpri = pri; - LwpCurrent->next = 0; - LwpCurrent->sbtm = stack; /* dummy stack for "main" */ - LwpCurrent->pri = pri; - LwpCurrent->dead = 0; - LwpCurrent->flags = flags; - LwpCurrent->name = "Main"; - for (i=LWP_MAX_PRIO, q=LwpSchedQ; i--; q++) - q->head = q->tail = 0; - LwpDeadQ.head = LwpDeadQ.tail = 0; - /* must be lower in priority than us for this to work right */ - sel = lwpCreate(0, lwpSelect, 16384, flags, "EventHandler", - "Select (main loop) Event Handler", 0, 0, 0); - lwpInitSelect(sel); - return (LwpCurrent); + extern struct lwpQueue LwpSchedQ[]; + extern struct lwpProc *LwpCurrent; + struct lwpQueue *q; + int i, *stack; + struct lwpProc *sel; + + LwpContextPtr = ctxptr; + if (pri < 1) + pri = 1; + /* *LwpContextPtr = 0; */ + if (! + (LwpCurrent = (struct lwpProc *)calloc(1, sizeof(struct lwpProc)))) + return (0); + if (!(stack = (int *)malloc(64))) + return (0); + if (LWP_MAX_PRIO <= pri) + pri = LWP_MAX_PRIO - 1; + if (LwpMaxpri < pri) + LwpMaxpri = pri; + LwpCurrent->next = 0; + LwpCurrent->sbtm = stack; /* dummy stack for "main" */ + LwpCurrent->pri = pri; + LwpCurrent->dead = 0; + LwpCurrent->flags = flags; + LwpCurrent->name = "Main"; + for (i = LWP_MAX_PRIO, q = LwpSchedQ; i--; q++) + q->head = q->tail = 0; + LwpDeadQ.head = LwpDeadQ.tail = 0; + /* must be lower in priority than us for this to work right */ + sel = lwpCreate(0, lwpSelect, 16384, flags, "EventHandler", + "Select (main loop) Event Handler", 0, 0, 0); + lwpInitSelect(sel); + return (LwpCurrent); } /* lwpStackCheckInit @@ -507,18 +516,19 @@ struct lwpProc *lwpInitSystem(pri, ctxptr, flags) * check mark. Thus, we can get some indication of how much stack was * used. */ -static void lwpStackCheckInit(newp) - struct lwpProc *newp; +static void +lwpStackCheckInit(newp) +struct lwpProc *newp; { - register int i; - register long *lp; - - int lim = newp->size/sizeof(long); - if (!newp || !newp->sbtm) - return; - for (lp=newp->sbtm,i=0; i < lim; i++,lp++) { - *lp = LWP_CHECKMARK; - } + register int i; + register long *lp; + + int lim = newp->size / sizeof(long); + if (!newp || !newp->sbtm) + return; + for (lp = newp->sbtm, i = 0; i < lim; i++, lp++) { + *lp = LWP_CHECKMARK; + } } /* lwpStackCheck @@ -531,95 +541,99 @@ static void lwpStackCheckInit(newp) * the thread, well, could be done. Should more like take * down the entire process. */ -static int lwpStackCheck(newp) - struct lwpProc *newp; +static int +lwpStackCheck(newp) +struct lwpProc *newp; { - register int end, amt; - register unsigned int i; - register long *lp; - register int growsDown; - int marker; - - if (!newp || !newp->himark || !newp->lowmark) - return(1); - growsDown = growsdown(&marker); - for (lp=newp->himark,i=0; i < LWP_REDZONE/sizeof(long); i++,lp++) { - if (*lp == LWP_CHECKMARK) - continue; - /* Stack overflow. */ - if (growsDown) { - end = i; - while (i < LWP_REDZONE/sizeof(long)) { - if (*lp++ != LWP_CHECKMARK) - end = i; - i++; - } - amt = (end+1) * sizeof(long); - } else { - amt = (i+1) * sizeof(long); - } - lwpStatus(newp, "Thread stack overflowed %d bytes (of %u)", - amt, newp->size - 2*LWP_REDZONE - sizeof(stkalign_t)); - return(0); + register int end, amt; + register unsigned int i; + register long *lp; + register int growsDown; + int marker; + + if (!newp || !newp->himark || !newp->lowmark) + return (1); + growsDown = growsdown(&marker); + for (lp = newp->himark, i = 0; i < LWP_REDZONE / sizeof(long); + i++, lp++) { + if (*lp == LWP_CHECKMARK) + continue; + /* Stack overflow. */ + if (growsDown) { + end = i; + while (i < LWP_REDZONE / sizeof(long)) { + if (*lp++ != LWP_CHECKMARK) + end = i; + i++; + } + amt = (end + 1) * sizeof(long); + } else { + amt = (i + 1) * sizeof(long); } - for (lp=newp->lowmark,i=0; i < LWP_REDZONE/sizeof(long); i++,lp++) { - if (*lp == LWP_CHECKMARK) - continue; - /* Stack underflow. */ - if (growsDown) { - end = i; - while (i < LWP_REDZONE/sizeof(long)) { - if (*lp++ != LWP_CHECKMARK) - end = i; - i++; - } - amt = (end+1) * sizeof(long); - } else { - amt = (LWP_REDZONE - i+1) * sizeof(long); - } - lwpStatus(newp, "Thread stack underflow %d bytes (of %u)", - amt, newp->size - 2*LWP_REDZONE - sizeof(stkalign_t)); - return(0); + lwpStatus(newp, "Thread stack overflowed %d bytes (of %u)", + amt, newp->size - 2 * LWP_REDZONE - sizeof(stkalign_t)); + return (0); + } + for (lp = newp->lowmark, i = 0; i < LWP_REDZONE / sizeof(long); + i++, lp++) { + if (*lp == LWP_CHECKMARK) + continue; + /* Stack underflow. */ + if (growsDown) { + end = i; + while (i < LWP_REDZONE / sizeof(long)) { + if (*lp++ != LWP_CHECKMARK) + end = i; + i++; + } + amt = (end + 1) * sizeof(long); + } else { + amt = (LWP_REDZONE - i + 1) * sizeof(long); } - return(1); + lwpStatus(newp, "Thread stack underflow %d bytes (of %u)", + amt, newp->size - 2 * LWP_REDZONE - sizeof(stkalign_t)); + return (0); + } + return (1); } /* lwpStackCheckUsed * * Figure out how much stack was used by this thread. */ -static void lwpStackCheckUsed(newp) - struct lwpProc *newp; +static void +lwpStackCheckUsed(newp) +struct lwpProc *newp; { - register int i; - register long *lp; - register int lim; - int marker; - - if (!newp || !newp->sbtm) - return; - lim = newp->size/sizeof(long); - if (growsdown(&marker)) { - /* Start at the bottom and find first non checkmark. */ - for (lp=newp->sbtm,i=0; i < lim; i++,lp++) { - if (*lp != LWP_CHECKMARK) { - break; - } - } - } else { - /* Start at the top and find first non checkmark. */ - lp = newp->sbtm; - lp += newp->size/sizeof(long); - lp--; - for (i=0; i < lim; i++, lp--) { - if (*lp != LWP_CHECKMARK) { - break; - } - } + register int i; + register long *lp; + register int lim; + int marker; + + if (!newp || !newp->sbtm) + return; + lim = newp->size / sizeof(long); + if (growsdown(&marker)) { + /* Start at the bottom and find first non checkmark. */ + for (lp = newp->sbtm, i = 0; i < lim; i++, lp++) { + if (*lp != LWP_CHECKMARK) { + break; + } + } + } else { + /* Start at the top and find first non checkmark. */ + lp = newp->sbtm; + lp += newp->size / sizeof(long); + lp--; + for (i = 0; i < lim; i++, lp--) { + if (*lp != LWP_CHECKMARK) { + break; + } } - lwpStatus(newp, "stack use: %u bytes (of %u total)", - (i * sizeof(long)) - LWP_REDZONE, - newp->size - 2*LWP_REDZONE - sizeof(stkalign_t)); + } + lwpStatus(newp, "stack use: %u bytes (of %u total)", + (i * sizeof(long)) - LWP_REDZONE, + newp->size - 2 * LWP_REDZONE - sizeof(stkalign_t)); } #endif diff --git a/src/lib/lwp/lwpint.h b/src/lib/lwp/lwpint.h index 0d8226606..53fc15359 100644 --- a/src/lib/lwp/lwpint.h +++ b/src/lib/lwp/lwpint.h @@ -30,13 +30,13 @@ #define LCOUNT -1 #ifdef hpux -int lwpSave _PROTO((jmp_buf)); -void lwpRestore _PROTO((jmp_buf)); +int lwpSave _PROTO((jmp_buf)); +void lwpRestore _PROTO((jmp_buf)); #endif #if defined(MIPS) || defined(AIX32) || defined(ALPHA) || defined(__vax) -int lwpSave _PROTO((jmp_buf)); -void lwpRestore _PROTO((jmp_buf)); +int lwpSave _PROTO((jmp_buf)); +void lwpRestore _PROTO((jmp_buf)); #elif defined(SUN4) #define lwpSave(x) _setjmp(x) #define lwpRestore(x) _longjmp(x, 1) @@ -78,28 +78,27 @@ typedef struct { #endif /* internal routines */ -void lwpAddTail _PROTO((struct lwpQueue *, struct lwpProc *)); -struct lwpProc *lwpGetFirst _PROTO((struct lwpQueue *)); -void lwpReschedule _PROTO((void)); -void lwpReady _PROTO((struct lwpProc *)); -void lwpOnalarm _PROTO((void)); +void lwpAddTail _PROTO((struct lwpQueue *, struct lwpProc *)); +struct lwpProc *lwpGetFirst _PROTO((struct lwpQueue *)); +void lwpReschedule _PROTO((void)); +void lwpReady _PROTO((struct lwpProc *)); +void lwpOnalarm _PROTO((void)); #ifdef UCONTEXT -void lwpInitContext _PROTO((struct lwpProc *, stack_t *)); -#else /* GETCONTEXT */ +void lwpInitContext _PROTO((struct lwpProc *, stack_t *)); +#else /* GETCONTEXT */ #ifdef hpc -void lwpInitContext _PROTO((struct lwpProc *, void *)); +void lwpInitContext _PROTO((struct lwpProc *, void *)); #else #ifdef hpux -void lwpInitContext _PROTO((volatile struct lwpProc *volatile, void *)); +void lwpInitContext _PROTO((volatile struct lwpProc * volatile, void *)); #else -void lwpInitContext _PROTO((struct lwpProc *, void *)); +void lwpInitContext _PROTO((struct lwpProc *, void *)); #endif /* hpux */ #endif /* hpc */ #endif /* GETCONTEXT */ -void lwpEntryPoint _PROTO((void)); -void lwpInitSelect _PROTO((struct lwpProc *self)); -void lwpDestroy _PROTO((struct lwpProc *proc)); - -#endif /* _LWP_H */ +void lwpEntryPoint _PROTO((void)); +void lwpInitSelect _PROTO((struct lwpProc * self)); +void lwpDestroy _PROTO((struct lwpProc * proc)); +#endif /* _LWP_H */ diff --git a/src/lib/lwp/misc/echo.c b/src/lib/lwp/misc/echo.c index 6c2a949f5..c0220f280 100644 --- a/src/lib/lwp/misc/echo.c +++ b/src/lib/lwp/misc/echo.c @@ -18,98 +18,101 @@ #include "lwp.h" struct context { - struct lwpProc *us; - struct sockaddr_in addr; - int fd; + struct lwpProc *us; + struct sockaddr_in addr; + int fd; }; /*ARGSUSED*/ -int readConn(argc, argv, ud) - int argc; - char **argv; - void *ud; +int +readConn(argc, argv, ud) +int argc; +char **argv; +void *ud; { - struct context *ctx = (struct context *) ud; - char buf[1024]; - int n; + struct context *ctx = (struct context *)ud; + char buf[1024]; + int n; - while (1) { - printf("sleeping\n"); - lwpSleepFd(ctx->fd, LWP_FD_READ); - printf("waiting to read\n"); - if ((n = read(ctx->fd, buf, sizeof(buf))) <= 0) - break; - printf("got %d char\n", n); - lwpSleepFd(ctx->fd, LWP_FD_WRITE); - printf("waiting to write\n"); - if (write(ctx->fd, buf, n) < 0) - break; - printf("wrote %d char\n", n); - } - printf("process/fd %d exiting\n", ctx->fd); - close(ctx->fd); - lwpExit(); - /*NOTREACHED*/ + while (1) { + printf("sleeping\n"); + lwpSleepFd(ctx->fd, LWP_FD_READ); + printf("waiting to read\n"); + if ((n = read(ctx->fd, buf, sizeof(buf))) <= 0) + break; + printf("got %d char\n", n); + lwpSleepFd(ctx->fd, LWP_FD_WRITE); + printf("waiting to write\n"); + if (write(ctx->fd, buf, n) < 0) + break; + printf("wrote %d char\n", n); + } + printf("process/fd %d exiting\n", ctx->fd); + close(ctx->fd); + lwpExit(); + /*NOTREACHED*/ } -int acceptConn(argc, argv) - int argc; - char **argv; +int +acceptConn(argc, argv) +int argc; +char **argv; { - struct sockaddr_in sin; - int s; - int ns; - int len; - int maxfd; - struct context *ctx; + struct sockaddr_in sin; + int s; + int ns; + int len; + int maxfd; + struct context *ctx; - if (argc != 2) { - fprintf(stderr, "Usage: %s port\n", *argv); - exit(-1); - } - if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - perror("inet socket"); - exit(-1); - } - sin.sin_family = AF_INET; - sin.sin_port = htons(atoi(argv[1])); - sin.sin_addr.s_addr = 0; - if (bind(s, &sin, sizeof(sin)) < 0) { - perror("inet socket bind"); - exit(-1); - } - if (listen(s, LISTENMAXCONN) < 0) { - perror("inet socket listen"); - exit(-1); + if (argc != 2) { + fprintf(stderr, "Usage: %s port\n", *argv); + exit(-1); + } + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + perror("inet socket"); + exit(-1); + } + sin.sin_family = AF_INET; + sin.sin_port = htons(atoi(argv[1])); + sin.sin_addr.s_addr = 0; + if (bind(s, &sin, sizeof(sin)) < 0) { + perror("inet socket bind"); + exit(-1); + } + if (listen(s, LISTENMAXCONN) < 0) { + perror("inet socket listen"); + exit(-1); + } + maxfd = getdtablesize() - 1; + while (1) { + lwpSleepFd(s, LWP_FD_READ); + len = sizeof(sin); + ns = accept(s, &sin, &len); + if (ns < 0) { + perror("accept"); + exit(-1); } - maxfd = getdtablesize() - 1; - while (1) { - lwpSleepFd(s, LWP_FD_READ); - len = sizeof(sin); - ns = accept(s, &sin, &len); - if (ns < 0) { - perror("accept"); - exit(-1); - } - if (ns == maxfd) { - fprintf(stderr, "no more connections"); - close(ns); - } - printf("got connection from %s\n", inet_ntoa(sin.sin_addr)); - ctx = (struct context *) malloc(sizeof(*ctx)); - ctx->addr = sin; - ctx->fd = ns; - ctx->us = lwpCreate(SP_READER, readConn, 8192, 0, 0, ctx); + if (ns == maxfd) { + fprintf(stderr, "no more connections"); + close(ns); } - /*NOTREACHED*/ + printf("got connection from %s\n", inet_ntoa(sin.sin_addr)); + ctx = (struct context *)malloc(sizeof(*ctx)); + ctx->addr = sin; + ctx->fd = ns; + ctx->us = lwpCreate(SP_READER, readConn, 8192, 0, 0, ctx); + } + /*NOTREACHED*/ } -int main(argc, argv) - int argc; - char **argv; +int +main(argc, argv) +int argc; +char **argv; { - lwpInitSystem(1); - lwpCreate(SP_ACCEPT, acceptConn, 8192, argc, argv, 0); - lwpReschedule(); - /*NOTREACHED*/ + lwpInitSystem(1); + lwpCreate(SP_ACCEPT, acceptConn, 8192, argc, argv, 0); + lwpReschedule(); + /*NOTREACHED*/ } diff --git a/src/lib/lwp/misc/lwp.h b/src/lib/lwp/misc/lwp.h index 06d49dd0b..69fa110a5 100644 --- a/src/lib/lwp/misc/lwp.h +++ b/src/lib/lwp/misc/lwp.h @@ -36,30 +36,30 @@ /* process control block. do *not* change the position of context */ struct lwpProc { - jmp_buf context; /* processor context area */ - void *sbtm; /* bottom of stack attached to it */ - int size; /* size of stack */ - void (*entry)(); /* entry point */ - int dead; /* whether the process can be rescheduled */ - int pri; /* which scheduling queue we're on */ - long runtime; /* time at which process is restarted */ - int fd; /* fd we're blocking on */ - int argc; /* initial arguments */ - char **argv; - void *ud; /* user data */ - struct lwpProc *next; + jmp_buf context; /* processor context area */ + void *sbtm; /* bottom of stack attached to it */ + int size; /* size of stack */ + void (*entry) (); /* entry point */ + int dead; /* whether the process can be rescheduled */ + int pri; /* which scheduling queue we're on */ + long runtime; /* time at which process is restarted */ + int fd; /* fd we're blocking on */ + int argc; /* initial arguments */ + char **argv; + void *ud; /* user data */ + struct lwpProc *next; }; /* queue */ struct lwpQueue { - struct lwpProc *head; - struct lwpProc *tail; + struct lwpProc *head; + struct lwpProc *tail; }; /* semaphore */ struct lwpSem { - int count; - struct lwpQueue q; + int count; + struct lwpQueue q; }; #define LWP_FD_READ 0x1 @@ -67,24 +67,25 @@ struct lwpSem { #define LWP_MAX_PRIO 8 -struct lwpProc *lwpInitSystem _PROTO((int)); -struct lwpProc *lwpCreate _PROTO((int, void (*)(), int, int, char **, void *)); -void lwpExit _PROTO((void)); -void lwpTerminate _PROTO((struct lwpProc *)); -void lwpYield _PROTO((void)); -void lwpSleepFd _PROTO((int fd, int flags)); -void lwpSleepUntil _PROTO((long until)); -void lwpWakeupFd _PROTO((struct lwpProc *)); -void *lwpGetUD _PROTO((struct lwpProc *)); -void lwpSetUD _PROTO((struct lwpProc *, char *)); -int lwpSetPriority _PROTO((int)); -void lwpReschedule _PROTO(()); +struct lwpProc *lwpInitSystem _PROTO((int)); +struct lwpProc *lwpCreate +_PROTO((int, void (*)(), int, int, char **, void *)); +void lwpExit _PROTO((void)); +void lwpTerminate _PROTO((struct lwpProc *)); +void lwpYield _PROTO((void)); +void lwpSleepFd _PROTO((int fd, int flags)); +void lwpSleepUntil _PROTO((long until)); +void lwpWakeupFd _PROTO((struct lwpProc *)); +void *lwpGetUD _PROTO((struct lwpProc *)); +void lwpSetUD _PROTO((struct lwpProc *, char *)); +int lwpSetPriority _PROTO((int)); +void lwpReschedule _PROTO(()); -struct lwpSem *lwpCreateSem _PROTO((int)); -void lwpSignal _PROTO((struct lwpSem *)); -void lwpWait _PROTO((struct lwpSem *)); -void lwpSelect _PROTO((int argc, char **argv)); +struct lwpSem *lwpCreateSem _PROTO((int)); +void lwpSignal _PROTO((struct lwpSem *)); +void lwpWait _PROTO((struct lwpSem *)); +void lwpSelect _PROTO((int argc, char **argv)); -extern struct lwpProc *LwpCurrent; +extern struct lwpProc *LwpCurrent; -#endif /* _LWP_H */ +#endif /* _LWP_H */ diff --git a/src/lib/lwp/queue.c b/src/lib/lwp/queue.c index 1aa5ad481..b44e85f93 100644 --- a/src/lib/lwp/queue.c +++ b/src/lib/lwp/queue.c @@ -26,26 +26,28 @@ #if defined(_EMPTH_LWP) -struct lwpProc *lwpGetFirst(q) - struct lwpQueue *q; +struct lwpProc * +lwpGetFirst(q) +struct lwpQueue *q; { - struct lwpProc *head; + struct lwpProc *head; - if ((head = q->head) && !(q->head = head->next)) - q->tail = 0; - return (head); + if ((head = q->head) && !(q->head = head->next)) + q->tail = 0; + return (head); } -void lwpAddTail(q, p) - register struct lwpQueue *q; - register struct lwpProc *p; +void +lwpAddTail(q, p) +register struct lwpQueue *q; +register struct lwpProc *p; { - if (!q->tail) - q->head = p; - else - q->tail->next = p; - q->tail = p; - p->next = 0; + if (!q->tail) + q->head = p; + else + q->tail->next = p; + q->tail = p; + p->next = 0; } #endif diff --git a/src/lib/lwp/sel.c b/src/lib/lwp/sel.c index af9526945..fcbd80ec4 100644 --- a/src/lib/lwp/sel.c +++ b/src/lib/lwp/sel.c @@ -50,201 +50,204 @@ #if defined(_EMPTH_LWP) struct lwpSelect { - int maxfd; - int nfds; - int nfile; - fd_set readmask; - fd_set writemask; - struct lwpProc **wait; - struct lwpQueue delayq; - struct lwpProc *proc; + int maxfd; + int nfds; + int nfile; + fd_set readmask; + fd_set writemask; + struct lwpProc **wait; + struct lwpQueue delayq; + struct lwpProc *proc; }; struct lwpSelect LwpSelect; -void lwpInitSelect(proc) - struct lwpProc *proc; +void +lwpInitSelect(proc) +struct lwpProc *proc; { - LwpSelect.maxfd = 0; - LwpSelect.nfds = 0; + LwpSelect.maxfd = 0; + LwpSelect.nfds = 0; #ifdef hpux - LwpSelect.nfile = _NFILE; + LwpSelect.nfile = _NFILE; #else - LwpSelect.nfile = getdtablesize(); + LwpSelect.nfile = getdtablesize(); #endif - FD_ZERO(&LwpSelect.readmask); - FD_ZERO(&LwpSelect.writemask); - LwpSelect.wait = (struct lwpProc **) - calloc(LwpSelect.nfile, sizeof(char *)); - LwpSelect.delayq.head = 0; - LwpSelect.delayq.tail = 0; - LwpSelect.proc = proc; + FD_ZERO(&LwpSelect.readmask); + FD_ZERO(&LwpSelect.writemask); + LwpSelect.wait = (struct lwpProc **) + calloc(LwpSelect.nfile, sizeof(char *)); + LwpSelect.delayq.head = 0; + LwpSelect.delayq.tail = 0; + LwpSelect.proc = proc; } -void lwpSleepFd(fd, mask) - int fd; - int mask; +void +lwpSleepFd(fd, mask) +int fd; +int mask; { - extern struct lwpProc *LwpCurrent; - - lwpStatus(LwpCurrent, "sleeping on fd %d", fd); - - if (LwpSelect.wait[fd] != 0) { - lwpStatus(LwpCurrent, - "multiple sleeps attempted on file descriptor %d", fd); - return; - } - if (mask & LWP_FD_READ) - FD_SET(fd, &LwpSelect.readmask); - if (mask & LWP_FD_WRITE) - FD_SET(fd, &LwpSelect.writemask); - - LwpSelect.nfds++; - - if (LwpSelect.maxfd == 0 && LwpSelect.delayq.head == 0) { - /* select process is sleeping until first waiter arrives */ - lwpStatus(LwpCurrent, "going to resched fd %d", fd); - lwpReady(LwpSelect.proc); - } - lwpStatus(LwpCurrent, "going to wait on fd %d", fd); - if (fd > LwpSelect.maxfd) - LwpSelect.maxfd = fd; - LwpSelect.wait[fd] = LwpCurrent; - LwpCurrent->fd = fd; - lwpReschedule(); + extern struct lwpProc *LwpCurrent; + + lwpStatus(LwpCurrent, "sleeping on fd %d", fd); + + if (LwpSelect.wait[fd] != 0) { + lwpStatus(LwpCurrent, + "multiple sleeps attempted on file descriptor %d", fd); + return; + } + if (mask & LWP_FD_READ) + FD_SET(fd, &LwpSelect.readmask); + if (mask & LWP_FD_WRITE) + FD_SET(fd, &LwpSelect.writemask); + + LwpSelect.nfds++; + + if (LwpSelect.maxfd == 0 && LwpSelect.delayq.head == 0) { + /* select process is sleeping until first waiter arrives */ + lwpStatus(LwpCurrent, "going to resched fd %d", fd); + lwpReady(LwpSelect.proc); + } + lwpStatus(LwpCurrent, "going to wait on fd %d", fd); + if (fd > LwpSelect.maxfd) + LwpSelect.maxfd = fd; + LwpSelect.wait[fd] = LwpCurrent; + LwpCurrent->fd = fd; + lwpReschedule(); } -void lwpWakeupFd(proc) - struct lwpProc *proc; +void +lwpWakeupFd(proc) +struct lwpProc *proc; { - if (proc->fd < 0) - return; - - lwpStatus(proc, "awakening; was sleeping on fd %d", proc->fd); - FD_CLR(proc->fd, &LwpSelect.readmask); - FD_CLR(proc->fd, &LwpSelect.writemask); - LwpSelect.nfds--; - LwpSelect.wait[proc->fd] = 0; - proc->fd = -1; - lwpReady(proc); + if (proc->fd < 0) + return; + + lwpStatus(proc, "awakening; was sleeping on fd %d", proc->fd); + FD_CLR(proc->fd, &LwpSelect.readmask); + FD_CLR(proc->fd, &LwpSelect.writemask); + LwpSelect.nfds--; + LwpSelect.wait[proc->fd] = 0; + proc->fd = -1; + lwpReady(proc); } -void lwpSleepUntil(until) - long until; +void +lwpSleepUntil(until) +long until; { - extern struct lwpProc *LwpCurrent; - - lwpStatus(LwpCurrent, "sleeping for %d sec", until - time(0)); - LwpCurrent->runtime = until; - if (LwpSelect.maxfd == 0 && LwpSelect.delayq.head == 0) { - /* select process is sleeping until first waiter arrives */ - lwpReady(LwpSelect.proc); - } - lwpAddTail(&LwpSelect.delayq, LwpCurrent); - lwpReschedule(); + extern struct lwpProc *LwpCurrent; + + lwpStatus(LwpCurrent, "sleeping for %d sec", until - time(0)); + LwpCurrent->runtime = until; + if (LwpSelect.maxfd == 0 && LwpSelect.delayq.head == 0) { + /* select process is sleeping until first waiter arrives */ + lwpReady(LwpSelect.proc); + } + lwpAddTail(&LwpSelect.delayq, LwpCurrent); + lwpReschedule(); } /*ARGSUSED*/ void lwpSelect(argc, argv) - int argc; - char **argv; +int argc; +char **argv; { - extern struct lwpProc *LwpCurrent; - struct lwpProc *us = LwpCurrent; - fd_set readmask; - fd_set writemask; - int n; - int fd; - time_t now; - time_t delta; - struct lwpProc *proc; - struct timeval tv; - struct lwpQueue save; - - lwpStatus(us, "starting select loop"); - FD_ZERO(&readmask); - FD_ZERO(&writemask); + extern struct lwpProc *LwpCurrent; + struct lwpProc *us = LwpCurrent; + fd_set readmask; + fd_set writemask; + int n; + int fd; + time_t now; + time_t delta; + struct lwpProc *proc; + struct timeval tv; + struct lwpQueue save; + + lwpStatus(us, "starting select loop"); + FD_ZERO(&readmask); + FD_ZERO(&writemask); + while (1) { while (1) { - while (1) { - if (LwpSelect.nfds) - break; - if (LwpSelect.delayq.head) - break; - /* wait for someone to lwpSleepFd or lwpSleepUntil */ - LwpSelect.maxfd = 0; - lwpStatus(us, "no fds or sleepers, waiting"); - lwpReschedule(); - } - tv.tv_sec = 1000000; - tv.tv_usec = 0; - if (LwpSelect.delayq.head) { - time(&now); - proc = LwpSelect.delayq.head; - for ( ; proc != 0; proc = proc->next) { - delta = proc->runtime - now; - if (delta < tv.tv_sec) - tv.tv_sec = delta; - } - if (tv.tv_sec < 0) - tv.tv_sec = 0; - } - lwpStatus(us, "selecting; sleep %ld secs", (long)delta); - - bcopy((s_char *)&LwpSelect.readmask, (s_char *)&readmask, sizeof(fd_set)); - bcopy((s_char *)&LwpSelect.writemask, (s_char *)&writemask, sizeof(fd_set)); - n = select(LwpSelect.maxfd + 1, &readmask, &writemask, - (fd_set *)0, &tv); - - if (n < 0) { - if (errno == EINTR) { - /* go handle the signal */ - lwpReady(us); - lwpReschedule(); - continue; - } - lwpStatus(us, - "select failed (bad file descriptor?)"); - exit(-1); + if (LwpSelect.nfds) + break; + if (LwpSelect.delayq.head) + break; + /* wait for someone to lwpSleepFd or lwpSleepUntil */ + LwpSelect.maxfd = 0; + lwpStatus(us, "no fds or sleepers, waiting"); + lwpReschedule(); + } + tv.tv_sec = 1000000; + tv.tv_usec = 0; + if (LwpSelect.delayq.head) { + time(&now); + proc = LwpSelect.delayq.head; + for (; proc != 0; proc = proc->next) { + delta = proc->runtime - now; + if (delta < tv.tv_sec) + tv.tv_sec = delta; + } + if (tv.tv_sec < 0) + tv.tv_sec = 0; + } + lwpStatus(us, "selecting; sleep %ld secs", (long)delta); + + bcopy((s_char *)&LwpSelect.readmask, (s_char *)&readmask, + sizeof(fd_set)); + bcopy((s_char *)&LwpSelect.writemask, (s_char *)&writemask, + sizeof(fd_set)); + n = select(LwpSelect.maxfd + 1, &readmask, &writemask, + (fd_set *) 0, &tv); + + if (n < 0) { + if (errno == EINTR) { + /* go handle the signal */ + lwpReady(us); + lwpReschedule(); + continue; + } + lwpStatus(us, "select failed (bad file descriptor?)"); + exit(-1); + } + + if (LwpSelect.delayq.head) { + /* sleeping proecss activity */ + time(&now); + save.tail = save.head = 0; + while (NULL != (proc = lwpGetFirst(&LwpSelect.delayq))) { + if (now >= proc->runtime) { + lwpStatus(proc, "sleep done"); + lwpReady(proc); + } else { + lwpAddTail(&save, proc); } - - if (LwpSelect.delayq.head) { - /* sleeping proecss activity */ - time(&now); - save.tail = save.head = 0; - while (NULL != (proc = lwpGetFirst(&LwpSelect.delayq))) { - if (now >= proc->runtime) { - lwpStatus(proc, "sleep done"); - lwpReady(proc); - } else { - lwpAddTail(&save, proc); - } - } - LwpSelect.delayq = save; + } + LwpSelect.delayq = save; + } + if (n > 0) { + /* file descriptor activity */ + for (fd = 0; fd <= LwpSelect.maxfd; fd++) { + if (LwpSelect.wait[fd] == 0) + continue; + if (FD_ISSET(fd, &readmask)) { + lwpStatus(LwpSelect.wait[fd], "input ready"); + lwpWakeupFd(LwpSelect.wait[fd]); + continue; } - if (n > 0) { - /* file descriptor activity */ - for(fd = 0; fd <= LwpSelect.maxfd; fd++) { - if (LwpSelect.wait[fd] == 0) - continue; - if (FD_ISSET(fd, &readmask)) { - lwpStatus(LwpSelect.wait[fd], - "input ready"); - lwpWakeupFd(LwpSelect.wait[fd]); - continue; - } - if (FD_ISSET(fd, &writemask)) { - lwpStatus(LwpSelect.wait[fd], - "output ready"); - lwpWakeupFd(LwpSelect.wait[fd]); - continue; - } - } + if (FD_ISSET(fd, &writemask)) { + lwpStatus(LwpSelect.wait[fd], "output ready"); + lwpWakeupFd(LwpSelect.wait[fd]); + continue; } - lwpStatus(us, "fd dispatch completed"); - lwpReady(LwpCurrent); - lwpReschedule(); + } } - /*NOTREACHED*/ + lwpStatus(us, "fd dispatch completed"); + lwpReady(LwpCurrent); + lwpReschedule(); + } + /*NOTREACHED*/ } #endif diff --git a/src/lib/lwp/sem.c b/src/lib/lwp/sem.c index ee8199acf..58867cf26 100644 --- a/src/lib/lwp/sem.c +++ b/src/lib/lwp/sem.c @@ -37,54 +37,57 @@ extern char *strdup(); /* * create a lwpSemaphore. */ -struct lwpSem *lwpCreateSem(name, count) - char *name; - int count; +struct lwpSem * +lwpCreateSem(name, count) +char *name; +int count; { - struct lwpSem *new; + struct lwpSem *new; - if (!(new = (struct lwpSem *)malloc(sizeof(struct lwpSem)))) - return (0); - new->name = strdup(name); - new->count = count; - new->q.head = new->q.tail = 0; - return (new); + if (!(new = (struct lwpSem *)malloc(sizeof(struct lwpSem)))) + return (0); + new->name = strdup(name); + new->count = count; + new->q.head = new->q.tail = 0; + return (new); } /* * signal a lwpSemaphore. We only yield here if * the blocked process has a higher priority than ours'. */ -void lwpSignal(s) - struct lwpSem *s; +void +lwpSignal(s) +struct lwpSem *s; { - extern struct lwpProc *LwpCurrent; + extern struct lwpProc *LwpCurrent; - lwpStatus(LwpCurrent, "done with semaphore %s", s->name); - if (s->count++ < 0) { - struct lwpProc *p = lwpGetFirst(&s->q); - lwpStatus(LwpCurrent, "activating first waiter"); - lwpReady(p); - if (LwpCurrent->pri < p->pri) { - lwpStatus(p, "priority is higher"); - lwpYield(); - } + lwpStatus(LwpCurrent, "done with semaphore %s", s->name); + if (s->count++ < 0) { + struct lwpProc *p = lwpGetFirst(&s->q); + lwpStatus(LwpCurrent, "activating first waiter"); + lwpReady(p); + if (LwpCurrent->pri < p->pri) { + lwpStatus(p, "priority is higher"); + lwpYield(); } + } } /* * wait on a lwpSemaphore */ -void lwpWait(s) - struct lwpSem *s; +void +lwpWait(s) +struct lwpSem *s; { - extern struct lwpProc *LwpCurrent; + extern struct lwpProc *LwpCurrent; - lwpStatus(LwpCurrent, "checking semaphore %s", s->name); - if (--s->count < 0) { - lwpStatus(LwpCurrent, "blocking"); - lwpAddTail(&s->q, LwpCurrent); - lwpReschedule(); - } + lwpStatus(LwpCurrent, "checking semaphore %s", s->name); + if (--s->count < 0) { + lwpStatus(LwpCurrent, "blocking"); + lwpAddTail(&s->q, LwpCurrent); + lwpReschedule(); + } } #endif diff --git a/src/lib/lwp/status.c b/src/lib/lwp/status.c index 045c30146..0cff83383 100644 --- a/src/lib/lwp/status.c +++ b/src/lib/lwp/status.c @@ -40,30 +40,31 @@ #if defined(_EMPTH_LWP) -void lwpStatus(struct lwpProc *proc, char *format, ...) +void +lwpStatus(struct lwpProc *proc, char *format, ...) { - va_list ap; - static struct timeval startTime; - struct timeval tv; - char buf[1024]; - int sec, msec; + va_list ap; + static struct timeval startTime; + struct timeval tv; + char buf[1024]; + int sec, msec; - va_start(ap,format); - if (proc->flags & LWP_PRINT) { - if (startTime.tv_sec == 0) - gettimeofday(&startTime, 0); - gettimeofday(&tv, 0); - sec = tv.tv_sec - startTime.tv_sec; - msec = (tv.tv_usec - startTime.tv_usec) / 1000; - if (msec < 0) { - sec++; - msec += 1000; - } - vsprintf(buf, format, ap); - printf("%d:%02d.%03d %17s[%d]: %s\n", sec/60, sec%60, msec/10, - proc->name, proc->pri, buf); + va_start(ap, format); + if (proc->flags & LWP_PRINT) { + if (startTime.tv_sec == 0) + gettimeofday(&startTime, 0); + gettimeofday(&tv, 0); + sec = tv.tv_sec - startTime.tv_sec; + msec = (tv.tv_usec - startTime.tv_usec) / 1000; + if (msec < 0) { + sec++; + msec += 1000; } - va_end(ap); + vsprintf(buf, format, ap); + printf("%d:%02d.%03d %17s[%d]: %s\n", sec / 60, sec % 60, + msec / 10, proc->name, proc->pri, buf); + } + va_end(ap); } #endif diff --git a/src/lib/player/accept.c b/src/lib/player/accept.c index 4c50a62d7..2ef5e61a9 100644 --- a/src/lib/player/accept.c +++ b/src/lib/player/accept.c @@ -62,207 +62,212 @@ #include #include -struct emp_qelem Players; +struct emp_qelem Players; void player_init(void) { - emp_initque(&Players); - init_player_commands(); + emp_initque(&Players); + init_player_commands(); } struct player * player_new(int s, struct sockaddr_in *sin) { - struct player *lp; - struct hostent *hostp; + struct player *lp; + struct hostent *hostp; - lp = (struct player *) calloc(1, sizeof(struct player)); - bzero((s_char *)lp, sizeof(struct player)); - if (sin) { - /* update uses dummy player */ - /* so does the market updater */ - emp_insque(&lp->queue, &Players); - strcpy(lp->hostaddr, inet_ntoa(sin->sin_addr)); + lp = (struct player *)calloc(1, sizeof(struct player)); + bzero((s_char *)lp, sizeof(struct player)); + if (sin) { + /* update uses dummy player */ + /* so does the market updater */ + emp_insque(&lp->queue, &Players); + strcpy(lp->hostaddr, inet_ntoa(sin->sin_addr)); #ifdef RESOLVE_IPADDRESS - if (NULL != (hostp = gethostbyaddr((char *) &sin->sin_addr, sizeof(sin->sin_addr), AF_INET))) - strcpy(lp->hostname, hostp->h_name); + if (NULL != + (hostp = + gethostbyaddr((char *)&sin->sin_addr, sizeof(sin->sin_addr), + AF_INET))) + strcpy(lp->hostname, hostp->h_name); #endif /* RESOLVE_IPADDRESS */ - lp->cnum = 255; - lp->curid = -1; - time(&lp->curup); - lp->iop = io_open(s, IO_READ|IO_WRITE|IO_NBLOCK, - IO_BUFSIZE, 0, 0); - } - return lp; + lp->cnum = 255; + lp->curid = -1; + time(&lp->curup); + lp->iop = io_open(s, IO_READ | IO_WRITE | IO_NBLOCK, + IO_BUFSIZE, 0, 0); + } + return lp; } struct player * player_delete(struct player *lp) { - struct player *back; + struct player *back; - back = (struct player *) lp->queue.q_back; - if (back) - emp_remque(&lp->queue); - if (lp->iop) { - /* it's a real player */ - io_close(lp->iop); - lp->iop = 0; - } - free((s_char *)lp); - /* XXX may need to free bigmap here */ - return back; + back = (struct player *)lp->queue.q_back; + if (back) + emp_remque(&lp->queue); + if (lp->iop) { + /* it's a real player */ + io_close(lp->iop); + lp->iop = 0; + } + free((s_char *)lp); + /* XXX may need to free bigmap here */ + return back; } struct player * player_next(struct player *lp) { - if (lp == 0) - lp = (struct player *)Players.q_forw; - else - lp = (struct player *)lp->queue.q_forw; - if (&lp->queue == &Players) - return 0; - return lp; + if (lp == 0) + lp = (struct player *)Players.q_forw; + else + lp = (struct player *)lp->queue.q_forw; + if (&lp->queue == &Players) + return 0; + return lp; } struct player * player_prev(struct player *lp) { - if (lp == 0) - lp = (struct player *)Players.q_back; - else - lp = (struct player *)lp->queue.q_back; - if (&lp->queue == &Players) - return 0; - return lp; + if (lp == 0) + lp = (struct player *)Players.q_back; + else + lp = (struct player *)lp->queue.q_back; + if (&lp->queue == &Players) + return 0; + return lp; } struct player * getplayer(natid cnum) { - register struct emp_qelem *qp; + register struct emp_qelem *qp; - for (qp = Players.q_forw; qp != &Players; qp = qp->q_forw) - if (((struct player *)qp)->cnum == cnum) - return (struct player *)qp; + for (qp = Players.q_forw; qp != &Players; qp = qp->q_forw) + if (((struct player *)qp)->cnum == cnum) + return (struct player *)qp; - return 0; + return 0; } struct player * player_find_other(struct player *us, register natid cnum) { - register struct emp_qelem *qp; + register struct emp_qelem *qp; - for (qp = Players.q_forw; qp != &Players; qp = qp->q_forw) - if (((struct player *)qp)->cnum == cnum && - ((struct player *)qp != us) && - (((struct player *)qp)->state == PS_PLAYING)) - return (struct player *)qp; + for (qp = Players.q_forw; qp != &Players; qp = qp->q_forw) + if (((struct player *)qp)->cnum == cnum && + ((struct player *)qp != us) && + (((struct player *)qp)->state == PS_PLAYING)) + return (struct player *)qp; - - return 0; + + return 0; } void player_wakeup_all(natid cnum) { - register struct player *lp; + register struct player *lp; - if (NULL != (lp = getplayer(cnum))) - player_wakeup(lp); + if (NULL != (lp = getplayer(cnum))) + player_wakeup(lp); } void player_wakeup(struct player *pl) { - if (pl->waiting) - empth_wakeup(pl->proc); + if (pl->waiting) + empth_wakeup(pl->proc); } /*ARGSUSED*/ void player_accept(void *argv) { - extern s_char *loginport; - extern int errno; - struct sockaddr_in sin; - struct servent *sp; - int s; - short port; - int val; - int maxfd; - struct player *np; - int len; - int ns; - int set = 1; - int stacksize; - char buf[128]; + extern s_char *loginport; + extern int errno; + struct sockaddr_in sin; + struct servent *sp; + int s; + short port; + int val; + int maxfd; + struct player *np; + int len; + int ns; + int set = 1; + int stacksize; + char buf[128]; - player_init(); - sp = getservbyname("empire", "tcp"); - if (sp == 0) - port = htons(atoi(loginport)); - else - port = sp->s_port; - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = port; - sin.sin_family = AF_INET; - if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - logerror("inet socket create"); - exit(1); - } - val = 1; + player_init(); + sp = getservbyname("empire", "tcp"); + if (sp == 0) + port = htons(atoi(loginport)); + else + port = sp->s_port; + sin.sin_addr.s_addr = INADDR_ANY; + sin.sin_port = port; + sin.sin_family = AF_INET; + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + logerror("inet socket create"); + exit(1); + } + val = 1; #if !(defined(__linux__) && defined(__alpha__)) - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) < 0) { - logerror("inet socket setsockopt SO_REUSEADDR (%d)", errno); - exit(1); - } + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val)) + < 0) { + logerror("inet socket setsockopt SO_REUSEADDR (%d)", errno); + exit(1); + } #else - logerror("Alpha/Linux? You don't support SO_REUSEADDR yet, do you?\n"); + logerror + ("Alpha/Linux? You don't support SO_REUSEADDR yet, do you?\n"); #endif - if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) { - logerror("inet socket bind"); - exit(1); - } -#ifdef LISTENMAXCONN /* because someone in linux world didn't want to use - * SOMAXCONN as defined in the header files... */ - if (listen(s, LISTENMAXCONN) < 0) { - logerror("inet socket listen"); - exit(1); - } + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { + logerror("inet socket bind"); + exit(1); + } +#ifdef LISTENMAXCONN /* because someone in linux world didn't want to use + * SOMAXCONN as defined in the header files... */ + if (listen(s, LISTENMAXCONN) < 0) { + logerror("inet socket listen"); + exit(1); + } #else - if (listen(s, SOMAXCONN) < 0) { - logerror("inet socket listen"); - exit(1); - } + if (listen(s, SOMAXCONN) < 0) { + logerror("inet socket listen"); + exit(1); + } #endif - maxfd = getfdtablesize() - 1; - while (1) { - empth_select(s, EMPTH_FD_READ); - len = sizeof(sin); - ns = accept(s, (struct sockaddr *) &sin, &len); - if (ns < 0) { - logerror("new socket accept"); - continue; - } - (void) setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE, - (char *) &set, sizeof(set)); - if (ns >= maxfd) { - logerror("new fd %d, max %d, no fd's left for new user", - ns, maxfd); - close(ns); - continue; - } - np = player_new(ns, &sin); - /* XXX may not be big enough */ - stacksize = 100000 -/* budget */ + max(WORLD_X*WORLD_Y/2 * sizeof(int) * 7, -/* power */ MAXNOC * sizeof(struct powstr)); - sprintf(buf, "Player (fd #%d)", ns); - empth_create(PP_PLAYER, player_login, stacksize, - 0, buf, "Empire player", np); + maxfd = getfdtablesize() - 1; + while (1) { + empth_select(s, EMPTH_FD_READ); + len = sizeof(sin); + ns = accept(s, (struct sockaddr *)&sin, &len); + if (ns < 0) { + logerror("new socket accept"); + continue; + } + (void)setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE, + (char *)&set, sizeof(set)); + if (ns >= maxfd) { + logerror("new fd %d, max %d, no fd's left for new user", + ns, maxfd); + close(ns); + continue; } + np = player_new(ns, &sin); + /* XXX may not be big enough */ + stacksize = 100000 +/* budget */ + max(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7, +/* power */ MAXNOC * sizeof(struct powstr)); + sprintf(buf, "Player (fd #%d)", ns); + empth_create(PP_PLAYER, player_login, stacksize, + 0, buf, "Empire player", np); + } } diff --git a/src/lib/player/dispatch.c b/src/lib/player/dispatch.c index 3e2ceecf6..791c7212b 100644 --- a/src/lib/player/dispatch.c +++ b/src/lib/player/dispatch.c @@ -49,66 +49,66 @@ int dispatch(s_char *buf, s_char *redir) { - extern struct cmndstr player_coms[]; - extern int update_pending; - extern int max_btus; - struct natstr *np; - struct cmndstr *command; - int cmd; + extern struct cmndstr player_coms[]; + extern int update_pending; + extern int max_btus; + struct natstr *np; + struct cmndstr *command; + int cmd; - cmd = comtch(player->argp[0], player_coms, - player->ncomstat, player->god); - if (cmd < 0) { - if (cmd == M_NOTUNIQUE) - pr("\"%s\" is ambiguous -- ", buf); - else if (cmd == M_IGNORE) - return 0; - else { - pr("\"%s\" is not a legal command ", buf); - if (player->nstat != player->ncomstat) - pr("now "); - pr("\n"); - } - return -1; + cmd = comtch(player->argp[0], player_coms, + player->ncomstat, player->god); + if (cmd < 0) { + if (cmd == M_NOTUNIQUE) + pr("\"%s\" is ambiguous -- ", buf); + else if (cmd == M_IGNORE) + return 0; + else { + pr("\"%s\" is not a legal command ", buf); + if (player->nstat != player->ncomstat) + pr("now "); + pr("\n"); } - command = &player_coms[cmd]; - np = getnatp(player->cnum); - if (np->nat_btu < command->c_cost && command->c_cost > 0) { - if (player->god || opt_BLITZ) - np->nat_btu = max_btus; - else { - pr("You don't have the BTU's, bozo\n"); - return 0; - } + return -1; + } + command = &player_coms[cmd]; + np = getnatp(player->cnum); + if (np->nat_btu < command->c_cost && command->c_cost > 0) { + if (player->god || opt_BLITZ) + np->nat_btu = max_btus; + else { + pr("You don't have the BTU's, bozo\n"); + return 0; } - if (command->c_addr == 0) { - pr("Command not implemented\n"); - return 0; - } - if (update_pending) { - pr("Update in progress...command failed\n"); - return 0; - } - if (redir) { - prredir(redir); - pr("%s\n", buf); - } - player->command = command; - switch (command->c_addr()) { - case RET_OK: - player->btused += command->c_cost; - break; - case RET_FAIL: - pr("command failed\n"); - player->btused += command->c_cost; - break; - case RET_SYN: - pr("Usage: %s\n", command->c_form); - break; - default: - logerror("%s: returned bad value", command->c_form); - break; - } - player->command = 0; + } + if (command->c_addr == 0) { + pr("Command not implemented\n"); + return 0; + } + if (update_pending) { + pr("Update in progress...command failed\n"); return 0; + } + if (redir) { + prredir(redir); + pr("%s\n", buf); + } + player->command = command; + switch (command->c_addr()) { + case RET_OK: + player->btused += command->c_cost; + break; + case RET_FAIL: + pr("command failed\n"); + player->btused += command->c_cost; + break; + case RET_SYN: + pr("Usage: %s\n", command->c_form); + break; + default: + logerror("%s: returned bad value", command->c_form); + break; + } + player->command = 0; + return 0; } diff --git a/src/lib/player/empdis.c b/src/lib/player/empdis.c index 3c54dcdd8..5c9da90b8 100644 --- a/src/lib/player/empdis.c +++ b/src/lib/player/empdis.c @@ -58,32 +58,32 @@ #include #define KEEP_COMMANDS 50 -s_char player_commands[KEEP_COMMANDS][1024 + 8]; -int player_commands_index = 0; +s_char player_commands[KEEP_COMMANDS][1024 + 8]; +int player_commands_index = 0; int getcommand(s_char *combufp) { - struct natstr *natp; + struct natstr *natp; s_char buf[1024]; - + /* Note this now assumes a 1024 byte buffer is being passed in */ natp = getnatp(player->cnum); if (++player_commands_index >= KEEP_COMMANDS) - player_commands_index = 0; + player_commands_index = 0; sprintf(player_commands[player_commands_index], "%3d %3d [prompt]", - player_commands_index, player->cnum); + player_commands_index, player->cnum); do { - prprompt(natp->nat_minused, natp->nat_btu); - buf[0] = 0; - if (recvclient(buf, 1024) < 0) { - return -1; - } + prprompt(natp->nat_minused, natp->nat_btu); + buf[0] = 0; + if (recvclient(buf, 1024) < 0) { + return -1; + } } while (buf[0] == 0); if (++player_commands_index >= KEEP_COMMANDS) - player_commands_index = 0; + player_commands_index = 0; sprintf(player_commands[player_commands_index], "%3d %3d %s", - player_commands_index, player->cnum, buf); + player_commands_index, player->cnum, buf); copy(buf, combufp); return (strlen(combufp)); } @@ -91,63 +91,64 @@ getcommand(s_char *combufp) void init_player_commands(void) { - int i; + int i; - for (i = 0; i < KEEP_COMMANDS; ++i) - *player_commands[i] = 0; + for (i = 0; i < KEEP_COMMANDS; ++i) + *player_commands[i] = 0; } void log_last_commands(void) { - int i; - - logerror("Most recent player commands:"); - for (i = player_commands_index; i >=0; --i) - if (*player_commands[i]) - logerror("%s", player_commands[i]+4); - for (i = KEEP_COMMANDS - 1; i > player_commands_index; --i) - if (*player_commands[i]) - logerror("%s", player_commands[i]+4); + int i; + + logerror("Most recent player commands:"); + for (i = player_commands_index; i >= 0; --i) + if (*player_commands[i]) + logerror("%s", player_commands[i] + 4); + for (i = KEEP_COMMANDS - 1; i > player_commands_index; --i) + if (*player_commands[i]) + logerror("%s", player_commands[i] + 4); } int explain(void) { - extern struct cmndstr player_coms[]; - register s_char *format; - register int i; - - pr("\t\tCurrent EMPIRE Command List\n"); - pr("\t\t------- ------ ------- ----\n"); - pr("Initial number is cost in B.T.U. units.\n"); - pr("Next 2 chars (if present) are:\n"); - pr("$ - must be non-broke\tc -- must have capital\n"); - pr("Args in [brackets] are optional.\n"); - if (player->nstat > 4) { - pr("All-caps args in "); - pr(" have the following meanings:\n"); - pr(" :: a number in unspecified units\n"); - pr(" :: a commodity such as `food', `guns', etc\n"); - pr(" :: a commodity such as `food', `guns', etc\n"); - pr(" :: an item type such as `ship', `plane', etc\n"); - } - for (i = 0; (format = player_coms[i].c_form) != 0; i++) { - if ((player_coms[i].c_permit & player->ncomstat) == player_coms[i].c_permit){ - pr("%2d ", player_coms[i].c_cost); - if ((player_coms[i].c_permit & MONEY) == MONEY) - pr("$"); - else - pr(" "); - if ((player_coms[i].c_permit & CAP) == CAP) - pr("c"); - else - pr(" "); - pr(" %s\n", format); - } + extern struct cmndstr player_coms[]; + register s_char *format; + register int i; + + pr("\t\tCurrent EMPIRE Command List\n"); + pr("\t\t------- ------ ------- ----\n"); + pr("Initial number is cost in B.T.U. units.\n"); + pr("Next 2 chars (if present) are:\n"); + pr("$ - must be non-broke\tc -- must have capital\n"); + pr("Args in [brackets] are optional.\n"); + if (player->nstat > 4) { + pr("All-caps args in "); + pr(" have the following meanings:\n"); + pr(" :: a number in unspecified units\n"); + pr(" :: a commodity such as `food', `guns', etc\n"); + pr(" :: a commodity such as `food', `guns', etc\n"); + pr(" :: an item type such as `ship', `plane', etc\n"); + } + for (i = 0; (format = player_coms[i].c_form) != 0; i++) { + if ((player_coms[i].c_permit & player->ncomstat) == + player_coms[i].c_permit) { + pr("%2d ", player_coms[i].c_cost); + if ((player_coms[i].c_permit & MONEY) == MONEY) + pr("$"); + else + pr(" "); + if ((player_coms[i].c_permit & CAP) == CAP) + pr("c"); + else + pr(" "); + pr(" %s\n", format); } - pr("For further info on command syntax see \"info Syntax\".\n"); - return RET_OK; + } + pr("For further info on command syntax see \"info Syntax\".\n"); + return RET_OK; } /* @@ -156,79 +157,79 @@ explain(void) int gamedown(void) { - extern s_char *downfil; - int downf; - struct telstr tgm; - s_char buf[1024]; + extern s_char *downfil; + int downf; + struct telstr tgm; + s_char buf[1024]; - if (player->god) - return 0; + if (player->god) + return 0; #if !defined(_WIN32) - if ((downf = open(downfil, O_RDONLY, 0)) < 0) + if ((downf = open(downfil, O_RDONLY, 0)) < 0) #else - if ((downf = open(downfil, O_RDONLY|O_BINARY, 0)) < 0) + if ((downf = open(downfil, O_RDONLY | O_BINARY, 0)) < 0) #endif - return 0; - if (read(downf, (s_char *) &tgm, sizeof(tgm)) != sizeof(tgm)) { - logerror("bad header on login message (downfil)"); - close(downf); - return 1; - } - if (read(downf, buf, tgm.tel_length) != tgm.tel_length) { - logerror("bad length %d on login message", tgm.tel_length); - close(downf); - return 1; - } - if (tgm.tel_length >= (long)sizeof(buf)) - tgm.tel_length = sizeof(buf)-1; - buf[tgm.tel_length] = 0; - pr(buf); - pr("\nThe game is down\n"); - (void) close(downf); + return 0; + if (read(downf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) { + logerror("bad header on login message (downfil)"); + close(downf); return 1; + } + if (read(downf, buf, tgm.tel_length) != tgm.tel_length) { + logerror("bad length %d on login message", tgm.tel_length); + close(downf); + return 1; + } + if (tgm.tel_length >= (long)sizeof(buf)) + tgm.tel_length = sizeof(buf) - 1; + buf[tgm.tel_length] = 0; + pr(buf); + pr("\nThe game is down\n"); + (void)close(downf); + return 1; } void daychange(time_t now) { - struct natstr *natp; - struct tm *tm; - - natp = getnatp(player->cnum); - tm = localtime(&now); - if ((tm->tm_yday % 128) != natp->nat_dayno) { - natp->nat_dayno = tm->tm_yday % 128; - natp->nat_minused = 0; - } + struct natstr *natp; + struct tm *tm; + + natp = getnatp(player->cnum); + tm = localtime(&now); + if ((tm->tm_yday % 128) != natp->nat_dayno) { + natp->nat_dayno = tm->tm_yday % 128; + natp->nat_minused = 0; + } } int getminleft(time_t now, int *hour, int *mpd) { - s_char *bp; - struct tm *tm; - int nminleft; - int curtime; - struct natstr *natp; - int n; - - tm = localtime(&now); - curtime = tm->tm_min + tm->tm_hour * 60; - if (NULL != (bp = kw_find("minutes"))) - kw_parse(CF_VALUE, bp, mpd); - natp = getnatp(player->cnum); - nminleft = *mpd - natp->nat_minused; - if (NULL != (bp = kw_find("hours"))) { - /* - * assume hours has already been set; just verify - * that it is present - */ - n = hour[1] - curtime; - if (n < nminleft) - nminleft = n; - } - n = 60*24 - (tm->tm_min + tm->tm_hour*60); + s_char *bp; + struct tm *tm; + int nminleft; + int curtime; + struct natstr *natp; + int n; + + tm = localtime(&now); + curtime = tm->tm_min + tm->tm_hour * 60; + if (NULL != (bp = kw_find("minutes"))) + kw_parse(CF_VALUE, bp, mpd); + natp = getnatp(player->cnum); + nminleft = *mpd - natp->nat_minused; + if (NULL != (bp = kw_find("hours"))) { + /* + * assume hours has already been set; just verify + * that it is present + */ + n = hour[1] - curtime; if (n < nminleft) - nminleft = n; - return nminleft; + nminleft = n; + } + n = 60 * 24 - (tm->tm_min + tm->tm_hour * 60); + if (n < nminleft) + nminleft = n; + return nminleft; } diff --git a/src/lib/player/empmod.c b/src/lib/player/empmod.c index 24b28700d..21874f3be 100644 --- a/src/lib/player/empmod.c +++ b/src/lib/player/empmod.c @@ -40,394 +40,428 @@ #include "nat.h" #include "file.h" -extern int add(); -extern int anti(); -extern int assa(); -extern int atta(); -extern int boar(); -extern int bdes(); -extern int bomb(); -extern int buil(); -extern int chan(); -extern int coas(); -extern int comm(); -extern int coun(); -extern int decl(); -extern int deli(); -extern int show(); -extern int show_motd(void); -extern int desi(); -extern int diss(); -extern int drop(); -extern int echo(void); -extern int enli(); -extern int fire(); -extern int flee(); -extern int fly(); -extern int force(); -extern int info(); -extern int apro(); -extern int load(); -extern int look(); -extern int map(); -extern int mine(); -extern int move(); -extern int nati(); -extern int navi(); -extern int head(), news(); -extern int nuke(); -extern int offs(); -extern int para(); -extern int path(); -extern int payo(); -extern int powe(); -extern int rada(); -extern int rea(); -extern int real(); -extern int reco(); -extern int rout(); -extern int sona(); -extern int spy(); -extern int tele(); -extern int tend(); -extern int torp(); -extern int tran(); -extern int trea(); -extern int turn(); -extern int vers(); +extern int add(); +extern int anti(); +extern int assa(); +extern int atta(); +extern int boar(); +extern int bdes(); +extern int bomb(); +extern int buil(); +extern int chan(); +extern int coas(); +extern int comm(); +extern int coun(); +extern int decl(); +extern int deli(); +extern int show(); +extern int show_motd(void); +extern int desi(); +extern int diss(); +extern int drop(); +extern int echo(void); +extern int enli(); +extern int fire(); +extern int flee(); +extern int fly(); +extern int force(); +extern int info(); +extern int apro(); +extern int load(); +extern int look(); +extern int map(); +extern int mine(); +extern int move(); +extern int nati(); +extern int navi(); +extern int head(), news(); +extern int nuke(); +extern int offs(); +extern int para(); +extern int path(); +extern int payo(); +extern int powe(); +extern int rada(); +extern int rea(); +extern int real(); +extern int reco(); +extern int rout(); +extern int sona(); +extern int spy(); +extern int tele(); +extern int tend(); +extern int torp(); +extern int tran(); +extern int trea(); +extern int turn(); +extern int vers(); /* * new commands */ -extern int repo(); -extern int laun(); -extern int new(); -extern int shoo(); -extern int thre(); -extern int dist(); -extern int sct(); -extern int plan(); -extern int arm(); -extern int hard(); -extern int upgr(); -extern int surv(); -extern int capi(); -extern int orig(); -extern int conv(); -extern int leve(); -extern int cuto(); -extern int prod(); -extern int wai(); -extern int carg(); -extern int terr(); -extern int sate(); -extern int give(); -extern int edit(); -extern int wipe(); -extern int dump(); -extern int ldump(); -extern int ndump(); -extern int pdump(); -extern int pboa(); -extern int sdump(); -extern int lost(); -extern int explore(); -extern int reso(); -extern int scra(); -extern int rela(); -extern int brea(); -extern int upda(); -extern int hidd(); -extern int orde(); -extern int qorde(); -extern int sorde(); -extern int reje(); -extern int acce(); -extern int sabo(); -extern int scut(); -extern int grin(); -extern int shar(); -extern int sail(); /* Forsman's hacks */ -extern int foll(); /**/ -extern int mobq(); /**/ -extern int name(); -extern int range(); -extern int zdon(); -extern int fuel(); -extern int multifire(); -extern int retr(); -extern int budg(); -extern int wire(); -extern int stop(); -extern int start(); +extern int repo(); +extern int laun(); +extern int new(); +extern int shoo(); +extern int thre(); +extern int dist(); +extern int sct(); +extern int plan(); +extern int arm(); +extern int hard(); +extern int upgr(); +extern int surv(); +extern int capi(); +extern int orig(); +extern int conv(); +extern int leve(); +extern int cuto(); +extern int prod(); +extern int wai(); +extern int carg(); +extern int terr(); +extern int sate(); +extern int give(); +extern int edit(); +extern int wipe(); +extern int dump(); +extern int ldump(); +extern int ndump(); +extern int pdump(); +extern int pboa(); +extern int sdump(); +extern int lost(); +extern int explore(); +extern int reso(); +extern int scra(); +extern int rela(); +extern int brea(); +extern int upda(); +extern int hidd(); +extern int orde(); +extern int qorde(); +extern int sorde(); +extern int reje(); +extern int acce(); +extern int sabo(); +extern int scut(); +extern int grin(); +extern int shar(); +extern int sail(); /* Forsman's hacks */ +extern int foll(); +/**/ extern int mobq(); +/**/ extern int name(); +extern int range(); +extern int zdon(); +extern int fuel(); +extern int multifire(); +extern int retr(); +extern int budg(); +extern int wire(); +extern int stop(); +extern int start(); -extern int land(); -extern int supp(); -extern int lboa(); -extern int lcarg(); -extern int lload(); -extern int army(); -extern int lrange(); -extern int morale(); -extern int lretr(); -extern int landmine(); -extern int fort(); -extern int march(); -extern int llook(); -extern int mission(); -extern int work(); -extern int ltend(); -extern int cede(); -extern int best(); -extern int newe(); -extern int starve(); +extern int land(); +extern int supp(); +extern int lboa(); +extern int lcarg(); +extern int lload(); +extern int army(); +extern int lrange(); +extern int morale(); +extern int lretr(); +extern int landmine(); +extern int fort(); +extern int march(); +extern int llook(); +extern int mission(); +extern int work(); +extern int ltend(); +extern int cede(); +extern int best(); +extern int newe(); +extern int starve(); -extern int setres(); -extern int setsector(); +extern int setres(); +extern int setsector(); -extern int disa(); -extern int enab(); +extern int disa(); +extern int enab(); /* * Undeclared functions */ -extern int quit(void); -extern int cens(); -extern int demo(); -extern int shi(); -extern int wing(); -extern int execute(void); -extern int explain(void); -extern int set(); -extern int flash(void); -extern int wall(); -extern int shut(); -extern int togg(); -extern int stre(); -extern int skyw(); -extern int play(); -extern int swaps(); +extern int quit(void); +extern int cens(); +extern int demo(); +extern int shi(); +extern int wing(); +extern int execute(void); +extern int explain(void); +extern int set(); +extern int flash(void); +extern int wall(); +extern int shut(); +extern int togg(); +extern int stre(); +extern int skyw(); +extern int play(); +extern int swaps(); -extern int trad(); -extern int mark(); -extern int buy(); -extern int mult(); -extern int sell(); -extern int rese(); +extern int trad(); +extern int mark(); +extern int buy(); +extern int mult(); +extern int sell(); +extern int rese(); -extern int repa(); -extern int fina(); -extern int coll(); -extern int cons(); -extern int ledg(); -extern int shark(); -extern int offe(); +extern int repa(); +extern int fina(); +extern int coll(); +extern int cons(); +extern int ledg(); +extern int shark(); +extern int offe(); -extern int mobupdate(); +extern int mobupdate(); -extern int sinfra(); -extern int improve(); -extern int lstats(); -extern int pstat(); -extern int sstat(); +extern int sinfra(); +extern int improve(); +extern int lstats(); +extern int pstat(); +extern int sstat(); -struct cmndstr player_coms[] = { +struct cmndstr player_coms[] = { /* command form cost addr permit */ -{ "accept [as-COUNTRY]", 0, acce, C_MOD, NORM }, -{ "add ",0, add, C_MOD, GOD }, -{ "announce {message}", 0, tele, C_MOD, VIS }, -{ "anti ", 3, anti, C_MOD, NORM+MONEY+CAP }, -{ "apropos ", 0, apro, 0, VIS }, -{ "arm ", 3, arm, C_MOD, NORM+MONEY+CAP }, -{ "army ", 0, army, C_MOD, NORM }, -{ "assault [ ]",3,assa,C_MOD, NORM+MONEY+CAP }, -{ "attack [ ]",3,atta,C_MOD, NORM+MONEY+CAP }, -{ "bdes ", 0, bdes, C_MOD, NORM }, -{ "bestpath ", 0, best, 0, NORM }, -{ "bestdistpath ", 0, best, 0, NORM }, -{ "bmap [s|l|p|r|t*]", 0, map, C_MOD, NORM }, -{ "board [|]", 3, boar, C_MOD, NORM+MONEY+CAP }, -{ "bomb ",2,bomb,C_MOD, NORM+MONEY+CAP }, -{ "break {sanctuary}", 1, brea, C_MOD, SANCT }, -{ "budget [ ]",1,budg,0, NORM }, -{ "build [ ]",1, buil, C_MOD, NORM+MONEY+CAP }, -{ "buy ", 1, buy, C_MOD, CAP+NORM+MONEY }, -{ "bye {log-off}", 0, quit, 0, VIS }, -{ "capital ", 0, capi, C_MOD, NORM }, -{ "cargo ", 0, carg, 0, NORM }, + {"accept [as-COUNTRY]", 0, acce, C_MOD, NORM}, + {"add ", 0, add, C_MOD, GOD}, + {"announce {message}", 0, tele, C_MOD, VIS}, + {"anti ", 3, anti, C_MOD, NORM + MONEY + CAP}, + {"apropos ", 0, apro, 0, VIS}, + {"arm ", 3, arm, C_MOD, + NORM + MONEY + CAP}, + {"army ", 0, army, C_MOD, NORM}, + {"assault [ ]", + 3, assa, C_MOD, NORM + MONEY + CAP}, + {"attack [ ]", 3, atta, C_MOD, + NORM + MONEY + CAP}, + {"bdes ", 0, bdes, C_MOD, NORM}, + {"bestpath ", 0, best, 0, NORM}, + {"bestdistpath ", 0, best, 0, NORM}, + {"bmap [s|l|p|r|t*]", 0, map, C_MOD, NORM}, + {"board [|]", 3, boar, C_MOD, + NORM + MONEY + CAP}, + {"bomb ", 2, bomb, C_MOD, NORM + MONEY + CAP}, + {"break {sanctuary}", 1, brea, C_MOD, SANCT}, + {"budget [ ]", 1, budg, 0, + NORM}, + {"build [ ]", 1, + buil, C_MOD, NORM + MONEY + CAP}, + {"buy ", 1, buy, C_MOD, + CAP + NORM + MONEY}, + {"bye {log-off}", 0, quit, 0, VIS}, + {"capital ", 0, capi, C_MOD, NORM}, + {"cargo ", 0, carg, 0, NORM}, #ifdef CEDE_IS_ALLOWED -{ "cede [se|sh]", 639, cede, C_MOD, NORM }, + {"cede [se|sh]", 639, cede, C_MOD, NORM}, #endif /* CEDE_IS_ALLOWED */ -{ "census ", 0, cens, 0, VIS }, -{ "change ",0, chan, C_MOD, VIS }, -{ "coastwatch ", 1, coas, C_MOD, NORM+CAP }, -{ "collect ", 2, coll, C_MOD, NORM+MONEY+CAP }, -{ "commodity ", 0, comm, 0, VIS }, -{ "consider ",1,cons,C_MOD, NORM+CAP }, -{ "convert [sure?]", 2, conv, C_MOD, NORM+MONEY+CAP }, -{ "country ", 0, coun, 0, NORM }, -{ "cutoff ", 0, cuto, C_MOD, NORM }, -{ "declare ", 2, decl, C_MOD, NORM+CAP }, -{ "deliver [q|] [

]",1, deli, C_MOD, NORM }, -{ "demobilize [sure?]",1, demo, C_MOD, NORM+CAP }, -{ "designate [sure?]", 1, desi, C_MOD, NORM }, -{ "disable", 0, disa, C_MOD, GOD }, -{ "disarm ", 2, arm, C_MOD, NORM+MONEY+CAP }, -{ "dissolve ", 0, diss, C_MOD, GOD }, -{ "distribute ", 1, dist, C_MOD, NORM }, -{ "drop ",1,drop,C_MOD, NORM+MONEY+CAP }, -{ "dump []", 0, dump, 0, NORM }, -{ "echo []", 0, echo, 0, NORM }, -{ "edit ", 0, edit, C_MOD, GOD }, -{ "enable", 0, enab, C_MOD, GOD }, -{ "enlist ", 2, enli, C_MOD, NORM+MONEY+CAP }, -{ "execute ", 0, execute,0, VIS }, -{ "explore ",1,explore, C_MOD, NORM+MONEY+CAP }, -{ "financial", 0, fina, 0, NORM }, -{ "fire [TO-SECT | SHIP]",1,multifire,C_MOD, NORM+MONEY+CAP }, -{ "flash []", 0, flash, 0, VIS }, -{ "fleetadd ", 0, flee, C_MOD, NORM }, -{ "fly ",2,fly,C_MOD, NORM+MONEY+CAP }, -{ "follow ", 1, foll, C_MOD, NORM+CAP }, -{ "force ", 0, force, C_MOD, GOD }, -{ "fortify ", 1, fort, C_MOD, NORM }, -{ "fuel []", 1, fuel, C_MOD, NORM }, -{ "give ", 0, give, C_MOD, GOD }, -{ "grind ", 1, grin, C_MOD, NORM+MONEY+CAP }, -{ "harden ", 2, hard, C_MOD, NORM+MONEY+CAP }, -{ "help ", 0, info, 0, VIS }, -{ "headlines [days]", 0, head, C_MOD, VIS }, -{ "hidden ", 0, hidd, 0, GOD }, -{ "improve ",1, improve,C_MOD, NORM+MONEY+CAP }, -{ "info ", 0, info, 0, VIS }, -{ "land ", 0, land, C_MOD, NORM }, -{ "launch ", 3, laun, C_MOD, NORM+MONEY+CAP }, -{ "lboard []", 3, lboa, C_MOD, NORM+MONEY+CAP }, -{ "lcargo ", 0, lcarg, 0, NORM }, -{ "ledger ", 0, ledg, 0, NORM }, -{ "level ", 0, leve, 0, NORM }, -{ "list of commands", 0, explain,0, VIS }, -{ "lbmap [s|l|p|*]", 0, map, C_MOD, NORM }, -{ "ldump []", 0, ldump, 0, NORM }, -{ "lload ",1, lload, C_MOD, NORM+CAP }, -{ "llookout ", 1, llook, 0, NORM+CAP }, -{ "lmap [s|l|p|*]", 0, map, C_MOD, NORM }, -{ "lmine ", 2, landmine,C_MOD, NORM+MONEY+CAP }, -{ "load ",1,load,C_MOD, NORM+CAP }, -{ "lookout ", 1, look, 0, NORM+CAP }, -{ "lost", 0, lost, 0, NORM }, -{ "lradar ", 1, rada, 0, NORM+CAP }, -{ "lrange ", 1, lrange, C_MOD, NORM+CAP }, -{ "lretreat [i|h|b|c]", 1, lretr, C_MOD, NORM+CAP }, -{ "lstats ", 0, lstats, C_MOD, NORM }, -{ "ltend ",1, ltend, C_MOD, NORM+CAP }, -{ "lunload ",1,lload, C_MOD, NORM+CAP }, -{ "market [COMM]", 0, mark, 0, VIS }, -{ "map ", 0, map, C_MOD, VIS }, -{ "march ", 1, march, C_MOD, NORM+CAP }, -{ "mine ", 2, mine, C_MOD, NORM+MONEY+CAP }, -{ "mission []", 2,mission,C_MOD, NORM+CAP }, -{ "mobupdate ", 0, mobupdate, C_MOD, GOD }, -{ "morale ", 1, morale, C_MOD, NORM+CAP }, -{ "motd", 0, show_motd, C_MOD, VIS }, -{ "move ",1,move,C_MOD, NORM+CAP }, -{ "mquota ", 2, mobq, C_MOD, NORM+CAP }, -{ "mult [COUNTRY]", 1, mult, C_MOD, GOD }, -{ "name ", 0, name, C_MOD, NORM }, -{ "nation", 0, nati, 0, VIS }, -{ "navigate ", 1, navi, C_MOD, NORM+CAP }, -{ "ndump ", 0, ndump, 0, NORM }, -{ "newcap []", 0, new, C_MOD, GOD }, -{ "neweff ", 0, newe, C_MOD, NORM }, -{ "newspaper [days]", 0, news, 0, VIS }, -{ "nmap ", 0, map, C_MOD, VIS }, -{ "nuke ", 0, nuke, 0, NORM }, -{ "offer [ ]",1,offe,C_MOD, NORM+MONEY+CAP }, -{ "offset ", 0, offs, C_MOD, GOD }, -{ "order ", 1, orde, C_MOD, NORM+CAP }, -{ "origin ", 1, orig, C_MOD, NORM }, -{ "paradrop ",3,para,C_MOD, NORM+MONEY+CAP }, -{ "path ", 0, path, 0, NORM }, -{ "payoff ", 0, payo, C_MOD, NORM }, -{ "pbmap [s|l|p|*]", 0, map, C_MOD, NORM }, -{ "pboard ", 3, pboa, C_MOD, NORM+MONEY+CAP }, -{ "pdump []", 0, pdump, 0, NORM }, -{ "plane ", 0, plan, 0, NORM }, -{ "players", 0, play, 0, VIS }, -{ "pmap [s|l|p|*]", 0, map, C_MOD, NORM }, -{ "power [[\"new\" []] | [\"country\" ]]", 0, powe, C_MOD, VIS }, -{ "pray", 0, tele, C_MOD, NORM }, -{ "production ", 0, prod, 0, NORM }, -{ "pstat ", 0, pstat, 0, NORM }, -{ "qorder ", 0, qorde, C_MOD, NORM+CAP }, -{ "quit", 0, quit, 0, VIS }, -{ "radar ", 1, rada, 0, NORM+CAP }, -{ "range ", 1, range, C_MOD, NORM+CAP }, -{ "read", 0, rea, C_MOD, VIS }, -{ "realm []", 0, real, C_MOD, NORM }, -{ "recon ",3,reco,C_MOD, NORM+MONEY+CAP }, -{ "retreat [i|t|s|h|b|d|u|c]", 1,retr, C_MOD, NORM+CAP }, -{ "relations [as-COUNTRY]", 0, rela, 0, VIS }, -{ "reject ",2,reje,C_MOD, NORM }, -{ "repay ", 1, repa, C_MOD, NORM+MONEY+CAP }, -{ "report ", 0, repo, 0, VIS }, -{ "reset <0|price>", 1, rese, C_MOD, NORM+CAP }, -{ "resource ", 0, reso, 0, NORM }, -{ "route ", 1, rout, 0, NORM }, -{ "sabotage ", 1, sabo, C_MOD, NORM+MONEY+CAP }, -{ "sail ", 1, sail, C_MOD, NORM+CAP }, -{ "satellite [ [?cond&cond&...]]",1, sate, 0, NORM+MONEY+CAP }, -{ "sbmap [s|l|p|*]", 0, map, C_MOD, NORM }, -{ "scrap ", 2, scra, C_MOD, NORM+MONEY+CAP }, -{ "scuttle ", 5, scut, C_MOD, NORM+CAP }, -{ "sdump []", 0, sdump, 0, NORM }, -{ "sect ", 0, sct, 0, NORM }, -{ "sell ", 1, sell, C_MOD, NORM+CAP }, -{ "set ", 1, set, C_MOD, NORM+CAP }, -{ "setsector ", 0, setsector,C_MOD, GOD }, -{ "setresource ", 0, setres, C_MOD, GOD }, -{ "shark ", 25, shark, C_MOD, NORM+MONEY+CAP }, -{ "sharebmap []", 0, shar, C_MOD, NORM }, -{ "ship ", 0, shi, 0, NORM }, -{ "shoot ", 3, shoo, C_MOD, NORM+MONEY+CAP }, -{ "show <\"build\"|\"stats\"|\"cap\"> []", 0,show, 0, VIS }, -{ "shutdown [] ", 0, shut, 0, GOD }, -{ "sinfrastructure ", 0, sinfra, 0, VIS }, -{ "skywatch ", 1, skyw, C_MOD, NORM+CAP }, -{ "smap [s|l|p|*]", 0, map, C_MOD, NORM }, -{ "sonar ", 1, sona, C_MOD, NORM+CAP }, -{ "sorder ", 0, sorde, C_MOD, NORM+CAP }, -{ "spy ", 1, spy, C_MOD, NORM+CAP }, -{ "sstat ", 0, sstat, 0, NORM }, -{ "start ", 1, start, C_MOD, NORM+CAP }, -{ "starvation [|l |s ]", 0, starve, 0, NORM }, -{ "stop ", 1, stop, C_MOD, NORM+CAP }, -{ "strength ", 1, stre, C_MOD, NORM }, -{ "supply ", 1, supp, C_MOD, NORM+CAP }, -{ "survey ", 0, surv, 0, NORM+CAP }, -{ "swapsector ", 0, swaps, C_MOD, GOD }, -{ "sweep ",3,reco,C_MOD, NORM+MONEY+CAP }, -{ "telegram ", 0, tele, C_MOD, NORM }, -{ "tend ",1,tend, C_MOD, NORM+CAP }, -{ "territory []", 0, terr, C_MOD, NORM }, -{ "test ",1,move,0, NORM+CAP }, -{ "threshold ", 1, thre, C_MOD, NORM }, -{ "toggle [inform|flash|beep|coastwatch|sonar|techlists] [on|off]", 0, togg, C_MOD, VIS }, -{ "torpedo ",3, torp, C_MOD, NORM+MONEY+CAP }, -{ "trade", 1, trad, C_MOD, NORM+CAP+MONEY }, -{ "transport <\"nuke\"|\"plane\"> [ ] ",1,tran,C_MOD, NORM+CAP }, -{ "treaty ", 0, trea, 0, NORM+MONEY+CAP }, -{ "turn <\"on\"|\"off\"|\"mess\">", 0, turn, C_MOD, GOD }, -{ "unload ",1,load,C_MOD, NORM+CAP }, -{ "unsail ", 1, sail, C_MOD, NORM+CAP }, -{ "update", 0, upda, 0, VIS }, -{ "upgrade ", 1, upgr, C_MOD, NORM+MONEY+CAP }, -{ "version", 0, vers, 0, VIS }, -{ "wait", 0, wai, C_MOD, GOD }, -{ "wall []", 0, wall, C_MOD, NORM }, -{ "wingadd ", 1, wing, C_MOD, NORM }, -{ "wipe ", 1, wipe, C_MOD, NORM }, -{ "wire [yes|no|]", 0, rea, C_MOD, VIS }, -{ "work ", 1, work, C_MOD, NORM+MONEY+CAP }, -{ "zdone ", 0, zdon, C_MOD, NORM }, -{ 0, 0, 0, 0, 0 } + {"census ", 0, cens, 0, VIS}, + {"change ", 0, chan, C_MOD, VIS}, + {"coastwatch ", 1, coas, C_MOD, NORM + CAP}, + {"collect ", 2, coll, C_MOD, NORM + MONEY + CAP}, + {"commodity ", 0, comm, 0, VIS}, + {"consider ", 1, cons, + C_MOD, NORM + CAP}, + {"convert [sure?]", 2, conv, C_MOD, NORM + MONEY + CAP}, + {"country ", 0, coun, 0, NORM}, + {"cutoff ", 0, cuto, C_MOD, NORM}, + {"declare ", 2, decl, C_MOD, + NORM + CAP}, + {"deliver [q|] []", 1, deli, C_MOD, NORM}, + {"demobilize [sure?]", 1, demo, C_MOD, + NORM + CAP}, + {"designate [sure?]", 1, desi, C_MOD, NORM}, + {"disable", 0, disa, C_MOD, GOD}, + {"disarm ", 2, arm, C_MOD, NORM + MONEY + CAP}, + {"dissolve ", 0, diss, C_MOD, GOD}, + {"distribute ", 1, dist, C_MOD, NORM}, + {"drop ", 1, drop, C_MOD, NORM + MONEY + CAP}, + {"dump []", 0, dump, 0, NORM}, + {"echo []", 0, echo, 0, NORM}, + {"edit ", 0, edit, C_MOD, GOD}, + {"enable", 0, enab, C_MOD, GOD}, + {"enlist ", 2, enli, C_MOD, NORM + MONEY + CAP}, + {"execute ", 0, execute, 0, VIS}, + {"explore ", 1, explore, C_MOD, + NORM + MONEY + CAP}, + {"financial", 0, fina, 0, NORM}, + {"fire [TO-SECT | SHIP]", 1, multifire, C_MOD, NORM + MONEY + CAP}, + {"flash []", 0, flash, 0, VIS}, + {"fleetadd ", 0, flee, C_MOD, NORM}, + {"fly ", 2, fly, C_MOD, NORM + MONEY + CAP}, + {"follow ", 1, foll, C_MOD, NORM + CAP}, + {"force ", 0, force, C_MOD, GOD}, + {"fortify ", 1, fort, C_MOD, NORM}, + {"fuel []", 1, fuel, + C_MOD, NORM}, + {"give ", 0, give, C_MOD, GOD}, + {"grind ", 1, grin, C_MOD, NORM + MONEY + CAP}, + {"harden ", 2, hard, C_MOD, NORM + MONEY + CAP}, + {"help ", 0, info, 0, VIS}, + {"headlines [days]", 0, head, C_MOD, VIS}, + {"hidden ", 0, hidd, 0, GOD}, + {"improve ", 1, improve, C_MOD, + NORM + MONEY + CAP}, + {"info ", 0, info, 0, VIS}, + {"land ", 0, land, C_MOD, NORM}, + {"launch ", 3, laun, C_MOD, NORM + MONEY + CAP}, + {"lboard []", 3, lboa, C_MOD, + NORM + MONEY + CAP}, + {"lcargo ", 0, lcarg, 0, NORM}, + {"ledger ", 0, ledg, 0, NORM}, + {"level ", 0, leve, 0, NORM}, + {"list of commands", 0, explain, 0, VIS}, + {"lbmap [s|l|p|*]", 0, map, C_MOD, NORM}, + {"ldump []", 0, ldump, 0, NORM}, + {"lload ", 1, + lload, C_MOD, NORM + CAP}, + {"llookout ", 1, llook, 0, NORM + CAP}, + {"lmap [s|l|p|*]", 0, map, C_MOD, NORM}, + {"lmine ", 2, landmine, C_MOD, NORM + MONEY + CAP}, + {"load ", 1, load, + C_MOD, NORM + CAP}, + {"lookout ", 1, look, 0, NORM + CAP}, + {"lost", 0, lost, 0, NORM}, + {"lradar ", 1, rada, 0, NORM + CAP}, + {"lrange ", 1, lrange, C_MOD, NORM + CAP}, + {"lretreat [i|h|b|c]", 1, lretr, C_MOD, + NORM + CAP}, + {"lstats ", 0, lstats, C_MOD, NORM}, + {"ltend ", 1, ltend, C_MOD, + NORM + CAP}, + {"lunload ", 1, + lload, C_MOD, NORM + CAP}, + {"market [COMM]", 0, mark, 0, VIS}, + {"map ", 0, map, C_MOD, VIS}, + {"march ", 1, march, C_MOD, NORM + CAP}, + {"mine ", 2, mine, C_MOD, NORM + MONEY + CAP}, + {"mission []", 2, mission, C_MOD, NORM + CAP}, + {"mobupdate ", 0, mobupdate, C_MOD, GOD}, + {"morale ", 1, morale, C_MOD, NORM + CAP}, + {"motd", 0, show_motd, C_MOD, VIS}, + {"move ", 1, + move, C_MOD, NORM + CAP}, + {"mquota ", 2, mobq, C_MOD, NORM + CAP}, + {"mult [COUNTRY]", 1, mult, C_MOD, GOD}, + {"name ", 0, name, C_MOD, NORM}, + {"nation", 0, nati, 0, VIS}, + {"navigate ", 1, navi, C_MOD, NORM + CAP}, + {"ndump ", 0, ndump, 0, NORM}, + {"newcap []", 0, new, C_MOD, GOD}, + {"neweff ", 0, newe, C_MOD, NORM}, + {"newspaper [days]", 0, news, 0, VIS}, + {"nmap ", 0, map, C_MOD, VIS}, + {"nuke ", 0, nuke, 0, NORM}, + {"offer [ ]", 1, offe, C_MOD, + NORM + MONEY + CAP}, + {"offset ", 0, offs, C_MOD, GOD}, + {"order ", 1, orde, C_MOD, NORM + CAP}, + {"origin ", 1, orig, C_MOD, NORM}, + {"paradrop ", 3, para, C_MOD, NORM + MONEY + CAP}, + {"path ", 0, path, 0, NORM}, + {"payoff ", 0, payo, C_MOD, NORM}, + {"pbmap [s|l|p|*]", 0, map, C_MOD, NORM}, + {"pboard ", 3, pboa, C_MOD, NORM + MONEY + CAP}, + {"pdump []", 0, pdump, 0, NORM}, + {"plane ", 0, plan, 0, NORM}, + {"players", 0, play, 0, VIS}, + {"pmap [s|l|p|*]", 0, map, C_MOD, NORM}, + {"power [[\"new\" []] | [\"country\" ]]", 0, powe, C_MOD, VIS}, + {"pray", 0, tele, C_MOD, NORM}, + {"production ", 0, prod, 0, NORM}, + {"pstat ", 0, pstat, 0, NORM}, + {"qorder ", 0, qorde, C_MOD, NORM + CAP}, + {"quit", 0, quit, 0, VIS}, + {"radar ", 1, rada, 0, NORM + CAP}, + {"range ", 1, range, C_MOD, NORM + CAP}, + {"read", 0, rea, C_MOD, VIS}, + {"realm []", 0, real, C_MOD, NORM}, + {"recon ", 3, + reco, C_MOD, NORM + MONEY + CAP}, + {"retreat [i|t|s|h|b|d|u|c]", 1, retr, C_MOD, + NORM + CAP}, + {"relations [as-COUNTRY]", 0, rela, 0, VIS}, + {"reject ", 2, + reje, C_MOD, NORM}, + {"repay ", 1, repa, C_MOD, NORM + MONEY + CAP}, + {"report ", 0, repo, 0, VIS}, + {"reset <0|price>", 1, rese, C_MOD, NORM + CAP}, + {"resource ", 0, reso, 0, NORM}, + {"route ", 1, rout, 0, NORM}, + {"sabotage ", 1, sabo, C_MOD, NORM + MONEY + CAP}, + {"sail ", 1, sail, C_MOD, NORM + CAP}, + {"satellite [ [?cond&cond&...]]", 1, sate, 0, + NORM + MONEY + CAP}, + {"sbmap [s|l|p|*]", 0, map, C_MOD, NORM}, + {"scrap ", 2, scra, C_MOD, + NORM + MONEY + CAP}, + {"scuttle ", 5, scut, C_MOD, NORM + CAP}, + {"sdump []", 0, sdump, 0, NORM}, + {"sect ", 0, sct, 0, NORM}, + {"sell ", 1, sell, C_MOD, NORM + CAP}, + {"set ", 1, set, C_MOD, NORM + CAP}, + {"setsector ", 0, setsector, C_MOD, GOD}, + {"setresource ", 0, setres, C_MOD, GOD}, + {"shark ", 25, shark, C_MOD, NORM + MONEY + CAP}, + {"sharebmap []", 0, shar, C_MOD, NORM}, + {"ship ", 0, shi, 0, NORM}, + {"shoot ", 3, shoo, C_MOD, NORM + MONEY + CAP}, + {"show <\"build\"|\"stats\"|\"cap\"> []", 0, show, 0, + VIS}, + {"shutdown [] ", 0, shut, 0, GOD}, + {"sinfrastructure ", 0, sinfra, 0, VIS}, + {"skywatch ", 1, skyw, C_MOD, NORM + CAP}, + {"smap [s|l|p|*]", 0, map, C_MOD, NORM}, + {"sonar ", 1, sona, C_MOD, NORM + CAP}, + {"sorder ", 0, sorde, C_MOD, NORM + CAP}, + {"spy ", 1, spy, C_MOD, NORM + CAP}, + {"sstat ", 0, sstat, 0, NORM}, + {"start ", 1, start, C_MOD, NORM + CAP}, + {"starvation [|l |s ]", 0, starve, 0, NORM}, + {"stop ", 1, stop, C_MOD, NORM + CAP}, + {"strength ", 1, stre, C_MOD, NORM}, + {"supply ", 1, supp, C_MOD, NORM + CAP}, + {"survey ", 0, surv, 0, NORM + CAP}, + {"swapsector ", 0, swaps, C_MOD, GOD}, + {"sweep ", + 3, reco, C_MOD, NORM + MONEY + CAP}, + {"telegram ", 0, tele, C_MOD, NORM}, + {"tend ", 1, + tend, C_MOD, NORM + CAP}, + {"territory []", 0, terr, C_MOD, NORM}, + {"test ", 1, + move, 0, NORM + CAP}, + {"threshold ", 1, thre, C_MOD, NORM}, + {"toggle [inform|flash|beep|coastwatch|sonar|techlists] [on|off]", 0, + togg, C_MOD, VIS}, + {"torpedo ", 3, torp, C_MOD, + NORM + MONEY + CAP}, + {"trade", 1, trad, C_MOD, NORM + CAP + MONEY}, + {"transport <\"nuke\"|\"plane\"> [ ] ", 1, tran, C_MOD, NORM + CAP}, + {"treaty ", 0, trea, 0, NORM + MONEY + CAP}, + {"turn <\"on\"|\"off\"|\"mess\">", 0, turn, C_MOD, GOD}, + {"unload ", 1, load, + C_MOD, NORM + CAP}, + {"unsail ", 1, sail, C_MOD, NORM + CAP}, + {"update", 0, upda, 0, VIS}, + {"upgrade ", 1, upgr, C_MOD, + NORM + MONEY + CAP}, + {"version", 0, vers, 0, VIS}, + {"wait", 0, wai, C_MOD, GOD}, + {"wall []", 0, wall, C_MOD, NORM}, + {"wingadd ", 1, wing, C_MOD, NORM}, + {"wipe ", 1, wipe, C_MOD, NORM}, + {"wire [yes|no|]", 0, rea, C_MOD, VIS}, + {"work ", 1, work, C_MOD, NORM + MONEY + CAP}, + {"zdone ", 0, zdon, C_MOD, NORM}, + {0, 0, 0, 0, 0} }; diff --git a/src/lib/player/init_nats.c b/src/lib/player/init_nats.c index 5f92b4608..dd1a213b5 100644 --- a/src/lib/player/init_nats.c +++ b/src/lib/player/init_nats.c @@ -47,87 +47,87 @@ int init_nats(void) { - struct natstr *np; + struct natstr *np; - if ((np = getnatp(player->cnum)) == 0) - return -1; - player->nstat = np->nat_stat; - player->god = np->nat_stat & STAT_GOD; - player->map = ef_ptr(EF_MAP, player->cnum); - player->bmap = ef_ptr(EF_BMAP, player->cnum); - if (opt_HIDDEN) { - putcontact(np, player->cnum, FOUND_SPY); - } - if (np->nat_money <= 0) - player->broke = 1; - else { - player->nstat |= MONEY; - player->broke = 0; - } - if (nat_cap(np->nat_btu) < 0) - return -1; - return 0; + if ((np = getnatp(player->cnum)) == 0) + return -1; + player->nstat = np->nat_stat; + player->god = np->nat_stat & STAT_GOD; + player->map = ef_ptr(EF_MAP, player->cnum); + player->bmap = ef_ptr(EF_BMAP, player->cnum); + if (opt_HIDDEN) { + putcontact(np, player->cnum, FOUND_SPY); + } + if (np->nat_money <= 0) + player->broke = 1; + else { + player->nstat |= MONEY; + player->broke = 0; + } + if (nat_cap(np->nat_btu) < 0) + return -1; + return 0; } int nat_cap(int btu) { - extern int s_p_etu; - extern int max_btus; - extern float btu_build_rate; - struct sctstr sect; - struct natstr *np; - double d; - double civ; - int delta; + extern int s_p_etu; + extern int max_btus; + extern float btu_build_rate; + struct sctstr sect; + struct natstr *np; + double d; + double civ; + int delta; - np = getnatp(player->cnum); - if (!getsect(np->nat_xcap, np->nat_ycap, §)) { - logerror("can't read %s's cap @ %d,%d", - np->nat_cnam, np->nat_xcap, np->nat_ycap); - return -1; - } - if ((player->nstat & NORM) == NORM) { - if (player->owner && (sect.sct_type == SCT_CAPIT || - sect.sct_type == SCT_MOUNT || - sect.sct_type == SCT_SANCT)) - player->nstat |= CAP; - else - player->nstat &= ~CAP; - /* Ok, has the country owner reset his capital yet after it was sacked? */ - if (np->nat_flags & NF_SACKED) - player->nstat &= ~CAP; /* No capital yet */ - } - delta = 0; - if ((player->nstat & CAP) || player->god) { - d = (double) (player->curup - np->nat_last_login) / s_p_etu; - if (d > 336.0) - d = 336.0; - civ = getvar(V_CIVIL, (caddr_t)§, EF_SECTOR); - if (civ > 999) - civ = 999; - if ((sect.sct_effic) && (sect.sct_type != SCT_MOUNT)) - delta=roundavg(d*civ*sect.sct_effic*btu_build_rate); - else /* Assume 1/2% efficiency minimum */ - delta=roundavg(d*civ*btu_build_rate/2.0); - if (player->god) - delta = max_btus - btu; - if (delta + btu > max_btus) - delta = max_btus - btu; - if (btu > max_btus) - delta = max_btus - btu; - if (opt_BLITZ) - delta = max_btus - btu; + np = getnatp(player->cnum); + if (!getsect(np->nat_xcap, np->nat_ycap, §)) { + logerror("can't read %s's cap @ %d,%d", + np->nat_cnam, np->nat_xcap, np->nat_ycap); + return -1; + } + if ((player->nstat & NORM) == NORM) { + if (player->owner && (sect.sct_type == SCT_CAPIT || + sect.sct_type == SCT_MOUNT || + sect.sct_type == SCT_SANCT)) + player->nstat |= CAP; + else + player->nstat &= ~CAP; + /* Ok, has the country owner reset his capital yet after it was sacked? */ + if (np->nat_flags & NF_SACKED) + player->nstat &= ~CAP; /* No capital yet */ + } + delta = 0; + if ((player->nstat & CAP) || player->god) { + d = (double)(player->curup - np->nat_last_login) / s_p_etu; + if (d > 336.0) + d = 336.0; + civ = getvar(V_CIVIL, (caddr_t)§, EF_SECTOR); + if (civ > 999) + civ = 999; + if ((sect.sct_effic) && (sect.sct_type != SCT_MOUNT)) + delta = roundavg(d * civ * sect.sct_effic * btu_build_rate); + else /* Assume 1/2% efficiency minimum */ + delta = roundavg(d * civ * btu_build_rate / 2.0); + if (player->god) + delta = max_btus - btu; + if (delta + btu > max_btus) + delta = max_btus - btu; + if (btu > max_btus) + delta = max_btus - btu; + if (opt_BLITZ) + delta = max_btus - btu; - if (delta > 0) { - /* set date if BTUs made */ - np->nat_btu += delta; - } - if (btu > max_btus) - np->nat_btu = max_btus; + if (delta > 0) { + /* set date if BTUs made */ + np->nat_btu += delta; } - if (np->nat_stat == VIS) + if (btu > max_btus) np->nat_btu = max_btus; - putnat(np); - return 0; + } + if (np->nat_stat == VIS) + np->nat_btu = max_btus; + putnat(np); + return 0; } diff --git a/src/lib/player/login.c b/src/lib/player/login.c index 2bc15df19..5b3dfcdb2 100644 --- a/src/lib/player/login.c +++ b/src/lib/player/login.c @@ -65,263 +65,261 @@ struct cmndstr login_coms[]; void player_login(void *ud) { - s_char buf[128]; - s_char space[512]; - s_char *av[64]; - int ac; - int cmd; + s_char buf[128]; + s_char space[512]; + s_char *av[64]; + int ac; + int cmd; - player->proc = empth_self(); + player->proc = empth_self(); - pr_id(player, C_INIT, "Empire server ready\n"); + pr_id(player, C_INIT, "Empire server ready\n"); - while (!io_eof(player->iop) && !io_error(player->iop)) { - io_output(player->iop, IO_WAIT); - if (io_gets(player->iop, buf, sizeof(buf)) < 0) { - io_input(player->iop, IO_WAIT); - continue; - } - ac = parse(buf, av, 0, space, 0); - cmd = comtch(av[0], login_coms, 0, 0); - if (cmd < 0) { - pr_id(player, C_BADCMD, "Command %s not found\n", av[0]); - continue; - } - switch (login_coms[cmd].c_addr(player, ac, av)) { - case RET_OK: - break; - case RET_FAIL: - break; - case RET_SYN: - pr_id(player, C_BADCMD, "Usage %s\n", login_coms[cmd].c_form); - break; - default: - break; - } - if (player->state >= PS_SHUTDOWN) - break; + while (!io_eof(player->iop) && !io_error(player->iop)) { + io_output(player->iop, IO_WAIT); + if (io_gets(player->iop, buf, sizeof(buf)) < 0) { + io_input(player->iop, IO_WAIT); + continue; } - player->state = PS_SHUTDOWN; - if (!io_eof(player->iop)) { - (void) pr_player(player, C_EXIT, "so long...\n"); - io_noblocking(player->iop, 0); - while (io_output(player->iop, IO_WAIT) > 0) - ; + ac = parse(buf, av, 0, space, 0); + cmd = comtch(av[0], login_coms, 0, 0); + if (cmd < 0) { + pr_id(player, C_BADCMD, "Command %s not found\n", av[0]); + continue; } - player_delete(player); - empth_exit(); - /*NOTREACHED*/ + switch (login_coms[cmd].c_addr(player, ac, av)) { + case RET_OK: + break; + case RET_FAIL: + break; + case RET_SYN: + pr_id(player, C_BADCMD, "Usage %s\n", login_coms[cmd].c_form); + break; + default: + break; + } + if (player->state >= PS_SHUTDOWN) + break; + } + player->state = PS_SHUTDOWN; + if (!io_eof(player->iop)) { + (void)pr_player(player, C_EXIT, "so long...\n"); + io_noblocking(player->iop, 0); + while (io_output(player->iop, IO_WAIT) > 0) ; + } + player_delete(player); + empth_exit(); + /*NOTREACHED*/ } int client_cmd(struct player *player, int ac, char **av) { - int i; + int i; - if (ac < 1 || av[1] == '\0') - return RET_SYN; + if (ac < 1 || av[1] == '\0') + return RET_SYN; - for (i = 1; i < ac; ++i) { - if (i > 1) - (void) strncat(player->client, " ", sizeof(player->client)-1); - (void) strncat(player->client, av[i], sizeof(player->client)-1); - } - player->client[sizeof(player->client)-1] = '\0'; - pr_id(player, C_CMDOK, "talking to %s\n", player->client); - return RET_OK; + for (i = 1; i < ac; ++i) { + if (i > 1) + (void)strncat(player->client, " ", sizeof(player->client) - 1); + (void)strncat(player->client, av[i], sizeof(player->client) - 1); + } + player->client[sizeof(player->client) - 1] = '\0'; + pr_id(player, C_CMDOK, "talking to %s\n", player->client); + return RET_OK; } int user_cmd(struct player *player, int ac, char **av) { - if (ac < 1 || av[1] == '\0') - return RET_SYN; - (void) strncpy(player->userid, av[1], sizeof(player->userid)-1); - player->userid[sizeof(player->userid)-1] = '\0'; - pr_id(player, C_CMDOK, "hello %s\n", player->userid); - return RET_OK; + if (ac < 1 || av[1] == '\0') + return RET_SYN; + (void)strncpy(player->userid, av[1], sizeof(player->userid) - 1); + player->userid[sizeof(player->userid) - 1] = '\0'; + pr_id(player, C_CMDOK, "hello %s\n", player->userid); + return RET_OK; } int sanc_cmd(struct player *player, int ac, char **av) { - struct nstr_item ni; - struct natstr nat; - int first = 1; + struct nstr_item ni; + struct natstr nat; + int first = 1; - if (!opt_BLITZ) { - pr_id(player, C_BADCMD, "Command %s not found\n", av[0]); - return RET_FAIL; - } + if (!opt_BLITZ) { + pr_id(player, C_BADCMD, "Command %s not found\n", av[0]); + return RET_FAIL; + } - snxtitem_all(&ni, EF_NATION); - while (nxtitem(&ni, (s_char *)&nat)) { - if (nat.nat_stat != (STAT_INUSE|STAT_SANCT)) - continue; - if (first) { - pr_id(player, C_DATA, "The following countries are still in sanctuary:\n"); - first = 0; - } - pr_id(player, C_DATA, "%s\n", nat.nat_cnam); + snxtitem_all(&ni, EF_NATION); + while (nxtitem(&ni, (s_char *)&nat)) { + if (nat.nat_stat != (STAT_INUSE | STAT_SANCT)) + continue; + if (first) { + pr_id(player, C_DATA, + "The following countries are still in sanctuary:\n"); + first = 0; } - if (first) - pr_id(player, C_CMDOK, "There are no countries in sanctuary\n"); - else - pr_id(player, C_CMDOK, "\n"); - return RET_OK; + pr_id(player, C_DATA, "%s\n", nat.nat_cnam); + } + if (first) + pr_id(player, C_CMDOK, "There are no countries in sanctuary\n"); + else + pr_id(player, C_CMDOK, "\n"); + return RET_OK; } int coun_cmd(struct player *player, int ac, char **av) { - natid cnum; + natid cnum; - if (ac < 1 || av[1] == '\0') - return RET_SYN; - if (natbyname(av[1], &cnum) < 0) { - pr_id(player, C_CMDERR, "country %s does not exist\n",av[1]); - return 0; - } - player->cnum = cnum; - player->validated = 0; - pr_id(player, C_CMDOK, "country name %s\n", av[1]); + if (ac < 1 || av[1] == '\0') + return RET_SYN; + if (natbyname(av[1], &cnum) < 0) { + pr_id(player, C_CMDERR, "country %s does not exist\n", av[1]); return 0; + } + player->cnum = cnum; + player->validated = 0; + pr_id(player, C_CMDOK, "country name %s\n", av[1]); + return 0; } int pass_cmd(struct player *player, int ac, char **av) { - if (ac < 1 || av[1] == '\0') - return RET_SYN; - if (player->cnum == 255) { - pr_id(player, C_CMDERR, "need country first\n"); - return RET_FAIL; - } - if (!natpass(player->cnum, av[1])) { - pr_id(player, C_CMDERR, "password bad, logging entry\n"); - logerror("%s tried country #%d with %s", - praddr(player), player->cnum, av[1]); - return RET_FAIL; - } - player->validated++; - pr_id(player, C_CMDOK, "password ok\n"); - logerror("%s using country #%d", praddr(player), player->cnum); - return RET_OK; + if (ac < 1 || av[1] == '\0') + return RET_SYN; + if (player->cnum == 255) { + pr_id(player, C_CMDERR, "need country first\n"); + return RET_FAIL; + } + if (!natpass(player->cnum, av[1])) { + pr_id(player, C_CMDERR, "password bad, logging entry\n"); + logerror("%s tried country #%d with %s", + praddr(player), player->cnum, av[1]); + return RET_FAIL; + } + player->validated++; + pr_id(player, C_CMDOK, "password ok\n"); + logerror("%s using country #%d", praddr(player), player->cnum); + return RET_OK; } /*ARGSUSED*/ int play_cmd(struct player *player, int ac, char **av) { - extern char *banfil; - struct player *other; - natid cnum; - struct natstr *natp; + extern char *banfil; + struct player *other; + natid cnum; + struct natstr *natp; - if (ac == 4) { - (void) strncpy(player->userid, av[1], sizeof(player->userid)-1); - player->userid[sizeof(player->userid)-1] = '\0'; - player->validated = 0; - if (natbyname(av[2], &cnum) < 0) { - pr_id(player, C_CMDERR, "country %s does not exist\n", av[2]); - return 0; - } - if (!natpass(cnum, av[3])) { - pr_id(player, C_CMDERR, "password bad, logging entry\n"); - logerror("%s tried country #%d with %s", - praddr(player), cnum, av[3]); - return RET_FAIL; - } - player->cnum = cnum; - player->validated++; - } - if (player->cnum == 255 || !player->validated) { - pr_id(player, C_CMDERR, "need country and password\n"); - return RET_FAIL; + if (ac == 4) { + (void)strncpy(player->userid, av[1], sizeof(player->userid) - 1); + player->userid[sizeof(player->userid) - 1] = '\0'; + player->validated = 0; + if (natbyname(av[2], &cnum) < 0) { + pr_id(player, C_CMDERR, "country %s does not exist\n", av[2]); + return 0; } - if ((other = player_find_other(player, (natid)player->cnum)) != 0) { - natp = getnatp(player->cnum); - if (natp->nat_stat != VIS) { - pr_id(player, C_EXIT, "country in use by %s\n", - praddr(other)); - } else { - pr_id(player, C_EXIT, "country in use\n"); - } - return RET_FAIL; + if (!natpass(cnum, av[3])) { + pr_id(player, C_CMDERR, "password bad, logging entry\n"); + logerror("%s tried country #%d with %s", + praddr(player), cnum, av[3]); + return RET_FAIL; } - if (match_user(banfil, player)) { - logerror("Attempted login by BANNED host %s", - praddr(player)); - pr("Your login has been banned from this game\n"); - io_shutdown(player->iop, IO_READ); - return RET_FAIL; + player->cnum = cnum; + player->validated++; + } + if (player->cnum == 255 || !player->validated) { + pr_id(player, C_CMDERR, "need country and password\n"); + return RET_FAIL; + } + if ((other = player_find_other(player, (natid)player->cnum)) != 0) { + natp = getnatp(player->cnum); + if (natp->nat_stat != VIS) { + pr_id(player, C_EXIT, "country in use by %s\n", praddr(other)); + } else { + pr_id(player, C_EXIT, "country in use\n"); } - player_main(player); - player->state = PS_SHUTDOWN; - return RET_OK; + return RET_FAIL; + } + if (match_user(banfil, player)) { + logerror("Attempted login by BANNED host %s", praddr(player)); + pr("Your login has been banned from this game\n"); + io_shutdown(player->iop, IO_READ); + return RET_FAIL; + } + player_main(player); + player->state = PS_SHUTDOWN; + return RET_OK; } /*ARGSUSED*/ int kill_cmd(struct player *player, int ac, char **av) { - struct player *other; + struct player *other; - if (player->cnum == 255 || !player->validated) { - pr_id(player, C_CMDERR, "need country and password\n"); - return RET_FAIL; - } - /* XXX find cnum other than us */ - if ((other = player_find_other(player, player->cnum)) == 0) { - pr_id(player, C_EXIT, "country not in use\n"); - return RET_FAIL; - } - io_shutdown(other->iop, IO_READ|IO_WRITE); - pr_id(player, C_EXIT, "closed socket of offending job\n"); - return RET_OK; + if (player->cnum == 255 || !player->validated) { + pr_id(player, C_CMDERR, "need country and password\n"); + return RET_FAIL; + } + /* XXX find cnum other than us */ + if ((other = player_find_other(player, player->cnum)) == 0) { + pr_id(player, C_EXIT, "country not in use\n"); + return RET_FAIL; + } + io_shutdown(other->iop, IO_READ | IO_WRITE); + pr_id(player, C_EXIT, "closed socket of offending job\n"); + return RET_OK; } /*ARGSUSED*/ int list_cmd(struct player *player, int ac, char **av) { - struct player *lp; - int first = 1; + struct player *lp; + int first = 1; - if (player->cnum != 0 || !player->validated) { - pr_id(player, C_CMDERR, "Permission denied\n"); - return 0; - } - for (lp = player_next(0); lp != 0; lp = player_next(lp)) { - if (first) { - pr_id(player, C_DATA, "user@host\tcountry\tpid\n"); - first = 0; - } - pr_id(player, C_DATA, "%s\t%d\n", praddr(lp), lp->cnum); - } - if (first == 0) - pr_id(player, C_DATA, "\n"); + if (player->cnum != 0 || !player->validated) { + pr_id(player, C_CMDERR, "Permission denied\n"); return 0; + } + for (lp = player_next(0); lp != 0; lp = player_next(lp)) { + if (first) { + pr_id(player, C_DATA, "user@host\tcountry\tpid\n"); + first = 0; + } + pr_id(player, C_DATA, "%s\t%d\n", praddr(lp), lp->cnum); + } + if (first == 0) + pr_id(player, C_DATA, "\n"); + return 0; } /*ARGSUSED*/ int quit_cmd(struct player *player, int ac, char **av) { - pr_id(player, C_EXIT, "so long\n"); - io_shutdown(player->iop, IO_READ); - return RET_OK; + pr_id(player, C_EXIT, "so long\n"); + io_shutdown(player->iop, IO_READ); + return RET_OK; } struct cmndstr login_coms[] = { - { "list", 0, list_cmd, 0, 0 }, - { "client clientname [version info]", 0, client_cmd, 0, 0 }, - { "user username", 0, user_cmd, 0, 0 }, - { "sanc", 0, sanc_cmd, 0, 0 }, - { "coun countryname", 0, coun_cmd, 0, 0 }, - { "pass password", 0, pass_cmd, 0, 0 }, - { "play [user country pass]", 0, play_cmd, 0, 0 }, - { "quit ", 0, quit_cmd, 0, 0 }, - { "kill {self}", 0, kill_cmd, 0, 0 }, - { 0, 0, 0, 0, 0 } + {"list", 0, list_cmd, 0, 0}, + {"client clientname [version info]", 0, client_cmd, 0, 0}, + {"user username", 0, user_cmd, 0, 0}, + {"sanc", 0, sanc_cmd, 0, 0}, + {"coun countryname", 0, coun_cmd, 0, 0}, + {"pass password", 0, pass_cmd, 0, 0}, + {"play [user country pass]", 0, play_cmd, 0, 0}, + {"quit ", 0, quit_cmd, 0, 0}, + {"kill {self}", 0, kill_cmd, 0, 0}, + {0, 0, 0, 0, 0} }; diff --git a/src/lib/player/nat.c b/src/lib/player/nat.c index 73005d6fb..2405bc9fb 100644 --- a/src/lib/player/nat.c +++ b/src/lib/player/nat.c @@ -41,28 +41,28 @@ int natbyname(s_char *name, natid *result) { - struct natstr *np; - int i; + struct natstr *np; + int i; - for (i=0; NULL != (np = getnatp(i)); i++) { - if (strcmp(np->nat_cnam, name) == 0) { - *result = i; - return 0; - } + for (i = 0; NULL != (np = getnatp(i)); i++) { + if (strcmp(np->nat_cnam, name) == 0) { + *result = i; + return 0; } - *result = 255; - return -1; + } + *result = 255; + return -1; } int natpass(int cn, s_char *pass) { - struct natstr *np; + struct natstr *np; - np = getnatp((natid)cn); - if (np->nat_stat == VIS) - return 1; - if (strcmp(np->nat_pnam, pass) == 0) - return 1; - return 0; + np = getnatp((natid)cn); + if (np->nat_stat == VIS) + return 1; + if (strcmp(np->nat_pnam, pass) == 0) + return 1; + return 0; } diff --git a/src/lib/player/player.c b/src/lib/player/player.c index b175279b8..c90d639a2 100644 --- a/src/lib/player/player.c +++ b/src/lib/player/player.c @@ -59,248 +59,245 @@ #include #include -struct player *player; -extern int m_m_p_d; +struct player *player; +extern int m_m_p_d; void player_main(struct player *p) { - extern s_char *authfil; - struct natstr *natp; - int hour[2]; - int secs; - s_char buf[128]; + extern s_char *authfil; + struct natstr *natp; + int hour[2]; + int secs; + s_char buf[128]; - p->state = PS_PLAYING; - player = p; - time(&player->lasttime); - (void) time(&player->curup); - showvers(CLIENTPROTO); - show_motd(); - if (init_nats() < 0) - return; - natp = getnatp(player->cnum); - if (player->god && - !match_user(authfil, player)) { - logerror("NON-AUTHed Login attempted by %s", - praddr(player)); - pr("You're not a deity!\n"); - return; - } - if (!gamehours(player->curup, hour)) { - pr("Empire hours restriction in force\n"); - if ((natp->nat_stat & STAT_GOD) == 0) - return; - } - daychange(player->curup); - if ((player->minleft = getminleft(player->curup, hour, &m_m_p_d)) <= 0){ - pr("Time exceeded today\n"); - return; + p->state = PS_PLAYING; + player = p; + time(&player->lasttime); + (void)time(&player->curup); + showvers(CLIENTPROTO); + show_motd(); + if (init_nats() < 0) + return; + natp = getnatp(player->cnum); + if (player->god && !match_user(authfil, player)) { + logerror("NON-AUTHed Login attempted by %s", praddr(player)); + pr("You're not a deity!\n"); + return; + } + if (!gamehours(player->curup, hour)) { + pr("Empire hours restriction in force\n"); + if ((natp->nat_stat & STAT_GOD) == 0) + return; + } + daychange(player->curup); + if ((player->minleft = getminleft(player->curup, hour, &m_m_p_d)) <= 0) { + pr("Time exceeded today\n"); + return; + } + if ((*natp->nat_hostaddr && + *player->hostaddr && + strcmp(natp->nat_hostaddr, player->hostaddr)) || + (*natp->nat_userid && + *player->userid && strcmp(natp->nat_userid, player->userid))) { + if (natp->nat_stat != VIS) { + pr("Last connection from: %s", ctime(&natp->nat_last_login)); + pr(" to: %s", natp->nat_last_login < + natp->nat_last_logout ? ctime(&natp-> + nat_last_logout) : "?"); + pr(" by: %s@%s\n", + *natp->nat_userid ? natp->nat_userid : (s_char *)"nobody", + *natp->nat_hostname ? natp->nat_hostname : *natp-> + nat_hostaddr ? natp->nat_hostaddr : (s_char *)"nowhere"); } - if ((*natp->nat_hostaddr && - *player->hostaddr && - strcmp(natp->nat_hostaddr, player->hostaddr)) || - (*natp->nat_userid && - *player->userid && - strcmp(natp->nat_userid, player->userid))) { - if (natp->nat_stat != VIS) { - pr("Last connection from: %s", ctime(&natp->nat_last_login)); - pr(" to: %s", natp->nat_last_login < - natp->nat_last_logout ? ctime(&natp->nat_last_logout):"?"); - pr(" by: %s@%s\n", - *natp->nat_userid?natp->nat_userid : (s_char *)"nobody", - *natp->nat_hostname?natp->nat_hostname: - *natp->nat_hostaddr?natp->nat_hostaddr:(s_char *)"nowhere"); - } - } - if (*player->userid) - strcpy(natp->nat_userid, player->userid); - else - strcpy(natp->nat_userid, "nobody"); + } + if (*player->userid) + strcpy(natp->nat_userid, player->userid); + else + strcpy(natp->nat_userid, "nobody"); - if (*player->hostname) - strcpy(natp->nat_hostname, player->hostname); - else - strcpy(natp->nat_hostname, "nowhere"); + if (*player->hostname) + strcpy(natp->nat_hostname, player->hostname); + else + strcpy(natp->nat_hostname, "nowhere"); - if (*player->hostaddr) - strcpy(natp->nat_hostaddr, player->hostaddr); - - time(&natp->nat_last_login); - natp->nat_connected = 1; - putnat(natp); - if (natp->nat_flags & NF_INFORM && - natp->nat_tgms > 0) { - if (natp->nat_tgms == 1) - pr("You have a new telegram waiting ...\n"); - else - pr("You have %s new telegrams waiting ...\n", - numstr(buf, natp->nat_tgms)); - natp->nat_tgms = 0; - } + if (*player->hostaddr) + strcpy(natp->nat_hostaddr, player->hostaddr); - while (status()) { - if (command() == 0 && !player->aborted) - break; - player->aborted = 0; - } - /* #*# I put the following line in to prevent server crash -KHS */ - natp = getnatp(player->cnum); - /* - * randomly round up to the nearest minute, - * charging at least 15 seconds. - */ - time(&natp->nat_last_logout); - secs = max(natp->nat_last_logout - player->lasttime, 15); - natp->nat_minused += secs / 60; - secs = secs % 60; - if (chance(secs / 60.0)) - natp->nat_minused += 1; - natp->nat_connected = 0; - putnat(natp); - pr("Bye-bye\n"); + time(&natp->nat_last_login); + natp->nat_connected = 1; + putnat(natp); + if (natp->nat_flags & NF_INFORM && natp->nat_tgms > 0) { + if (natp->nat_tgms == 1) + pr("You have a new telegram waiting ...\n"); + else + pr("You have %s new telegrams waiting ...\n", + numstr(buf, natp->nat_tgms)); + natp->nat_tgms = 0; + } + + while (status()) { + if (command() == 0 && !player->aborted) + break; + player->aborted = 0; + } + /* #*# I put the following line in to prevent server crash -KHS */ + natp = getnatp(player->cnum); + /* + * randomly round up to the nearest minute, + * charging at least 15 seconds. + */ + time(&natp->nat_last_logout); + secs = max(natp->nat_last_logout - player->lasttime, 15); + natp->nat_minused += secs / 60; + secs = secs % 60; + if (chance(secs / 60.0)) + natp->nat_minused += 1; + natp->nat_connected = 0; + putnat(natp); + pr("Bye-bye\n"); } int command(void) { - register unsigned int x; - s_char *redir; - int kill_player(); - s_char scanspace[1024]; + register unsigned int x; + s_char *redir; + int kill_player(); + s_char scanspace[1024]; - if (getcommand(player->combuf) < 0) - return 0; - if (parse(player->combuf, player->argp, &player->condarg, - scanspace, &redir) < 0) { - pr("See \"info Syntax\"?\n"); - } else { - /* XXX don't use alarm; use a scavenger thread */ - /* DONT USE IT!!!! alarm and sleep may and dont work - together -- Sasha */ - /* alarm((unsigned int)60*60); 1 hour */ - if (player->condarg != (s_char *)0) - for(x=0;xcondarg);x++) - if (isupper(*(player->condarg+x))) - *(player->condarg+x) = tolower(*(player->condarg+x)); - if (dispatch(player->combuf, redir) < 0) - pr("Try \"list of commands\" or \"info\"\n"); - } - return 1; + if (getcommand(player->combuf) < 0) + return 0; + if (parse(player->combuf, player->argp, &player->condarg, + scanspace, &redir) < 0) { + pr("See \"info Syntax\"?\n"); + } else { + /* XXX don't use alarm; use a scavenger thread */ + /* DONT USE IT!!!! alarm and sleep may and dont work + together -- Sasha */ + /* alarm((unsigned int)60*60); 1 hour */ + if (player->condarg != (s_char *)0) + for (x = 0; x < strlen(player->condarg); x++) + if (isupper(*(player->condarg + x))) + *(player->condarg + x) = + tolower(*(player->condarg + x)); + if (dispatch(player->combuf, redir) < 0) + pr("Try \"list of commands\" or \"info\"\n"); + } + return 1; } int status(void) { - struct natstr *natp; - int minute; - struct sctstr sect; - int hour[2]; - s_char buf[128]; + struct natstr *natp; + int minute; + struct sctstr sect; + int hour[2]; + s_char buf[128]; - if (player->state == PS_SHUTDOWN) - return 0; - natp = getnatp(player->cnum); - if (io_error(player->iop) || io_eof(player->iop)) { - putnat(natp); - return 0; - } - player->visitor = (natp->nat_stat & (STAT_NORM|STAT_GOD)) == 0; - if (player->dolcost != 0.0) { - if (player->dolcost > 100.0) - pr("That just cost you $%.2f\n", player->dolcost); - else if (player->dolcost < -100.0) - pr("You just made $%.2f\n", -player->dolcost); - if (natp->nat_money < player->dolcost && !player->broke) { - player->broke = 1; - player->nstat &= ~MONEY; - pr("You are now broke; industries are on strike.\n"); - } else if (player->broke && natp->nat_money - player->dolcost > 0) { - player->broke = 0; - player->nstat |= MONEY; - pr("You are no longer broke!\n"); - } - natp->nat_money -= roundavg(player->dolcost); - player->dolcost = 0.0; - } else { - if (natp->nat_money < 0.0 && !player->broke) { - player->broke = 1; - player->nstat &= ~MONEY; - pr("You are now broke; industries are on strike.\n"); - } - if (player->broke && natp->nat_money > 0) { - player->broke = 0; - player->nstat |= MONEY; - pr("You are no longer broke!\n"); - } - } - getsect(natp->nat_xcap, natp->nat_ycap, §); - if ((sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT || - sect.sct_type == SCT_SANCT) && - sect.sct_own == player->cnum) - player->nstat |= CAP; - else - player->nstat &= ~CAP; - /* Ok, has the country owner reset his capital yet after it was sacked? */ - if (natp->nat_flags & NF_SACKED) - player->nstat &= ~CAP; /* No capital yet */ - player->ncomstat = player->nstat; - (void) time(&player->curup); - minute = (player->curup - player->lasttime) / 60; - if (minute > 0) { - player->minleft -= minute; - if (player->minleft <= 0) { - /* - * countdown timer "player->minleft" has expired. - * either day change, or hours restriction - */ - daychange(player->curup); - if (!gamehours(player->curup, hour)) { - pr("Empire hours restriction in force\n"); - if ((natp->nat_stat & STAT_GOD) == 0) { - putnat(natp); - return 0; - } - } - player->minleft = getminleft(player->curup, hour, &m_m_p_d); - } - player->lasttime += minute * 60; - natp->nat_minused += minute; + if (player->state == PS_SHUTDOWN) + return 0; + natp = getnatp(player->cnum); + if (io_error(player->iop) || io_eof(player->iop)) { + putnat(natp); + return 0; + } + player->visitor = (natp->nat_stat & (STAT_NORM | STAT_GOD)) == 0; + if (player->dolcost != 0.0) { + if (player->dolcost > 100.0) + pr("That just cost you $%.2f\n", player->dolcost); + else if (player->dolcost < -100.0) + pr("You just made $%.2f\n", -player->dolcost); + if (natp->nat_money < player->dolcost && !player->broke) { + player->broke = 1; + player->nstat &= ~MONEY; + pr("You are now broke; industries are on strike.\n"); + } else if (player->broke && natp->nat_money - player->dolcost > 0) { + player->broke = 0; + player->nstat |= MONEY; + pr("You are no longer broke!\n"); } - if ((player->nstat & NORM) && natp->nat_minused > m_m_p_d) { - pr("Max minutes per day limit exceeded.\n"); - player->ncomstat = VIS; + natp->nat_money -= roundavg(player->dolcost); + player->dolcost = 0.0; + } else { + if (natp->nat_money < 0.0 && !player->broke) { + player->broke = 1; + player->nstat &= ~MONEY; + pr("You are now broke; industries are on strike.\n"); } - if (player->btused) { - natp->nat_btu -= player->btused; - player->btused = 0; + if (player->broke && natp->nat_money > 0) { + player->broke = 0; + player->nstat |= MONEY; + pr("You are no longer broke!\n"); } - if (natp->nat_tgms > 0) { - if (!(natp->nat_flags & NF_INFORM)) { - if (natp->nat_tgms == 1) - pr("You have a new telegram waiting ...\n"); - else - pr("You have %s new telegrams waiting ...\n", - numstr(buf, natp->nat_tgms)); - natp->nat_tgms = 0; + } + getsect(natp->nat_xcap, natp->nat_ycap, §); + if ((sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT || + sect.sct_type == SCT_SANCT) && sect.sct_own == player->cnum) + player->nstat |= CAP; + else + player->nstat &= ~CAP; + /* Ok, has the country owner reset his capital yet after it was sacked? */ + if (natp->nat_flags & NF_SACKED) + player->nstat &= ~CAP; /* No capital yet */ + player->ncomstat = player->nstat; + (void)time(&player->curup); + minute = (player->curup - player->lasttime) / 60; + if (minute > 0) { + player->minleft -= minute; + if (player->minleft <= 0) { + /* + * countdown timer "player->minleft" has expired. + * either day change, or hours restriction + */ + daychange(player->curup); + if (!gamehours(player->curup, hour)) { + pr("Empire hours restriction in force\n"); + if ((natp->nat_stat & STAT_GOD) == 0) { + putnat(natp); + return 0; } + } + player->minleft = getminleft(player->curup, hour, &m_m_p_d); } - if (natp->nat_ann > 0) { - if (natp->nat_ann == 1) - pr("You have a new announcement waiting ...\n"); - else - pr("You have %s new announcements waiting ...\n", - numstr(buf, natp->nat_ann)); - natp->nat_ann = 0; - } - if (!player->visitor && !player->god && (player->nstat & CAP) == 0) - pr("You lost your capital... better designate one\n"); - putnat(natp); - if (gamedown() && !player->god) { - pr("gamedown\n"); - return 0; + player->lasttime += minute * 60; + natp->nat_minused += minute; + } + if ((player->nstat & NORM) && natp->nat_minused > m_m_p_d) { + pr("Max minutes per day limit exceeded.\n"); + player->ncomstat = VIS; + } + if (player->btused) { + natp->nat_btu -= player->btused; + player->btused = 0; + } + if (natp->nat_tgms > 0) { + if (!(natp->nat_flags & NF_INFORM)) { + if (natp->nat_tgms == 1) + pr("You have a new telegram waiting ...\n"); + else + pr("You have %s new telegrams waiting ...\n", + numstr(buf, natp->nat_tgms)); + natp->nat_tgms = 0; } - return 1; + } + if (natp->nat_ann > 0) { + if (natp->nat_ann == 1) + pr("You have a new announcement waiting ...\n"); + else + pr("You have %s new announcements waiting ...\n", + numstr(buf, natp->nat_ann)); + natp->nat_ann = 0; + } + if (!player->visitor && !player->god && (player->nstat & CAP) == 0) + pr("You lost your capital... better designate one\n"); + putnat(natp); + if (gamedown() && !player->god) { + pr("gamedown\n"); + return 0; + } + return 1; } /* @@ -312,115 +309,115 @@ status(void) int execute(void) { - s_char buf[512]; - int abort; - s_char *p; - s_char *redir; - s_char scanspace[1024]; + s_char buf[512]; + int abort; + s_char *p; + s_char *redir; + s_char scanspace[1024]; - abort = 0; - redir = 0; - - p = getstarg (player->argp[1], "File? ", buf); + abort = 0; + redir = 0; - if (p == (s_char *) 0 || p == '\0') - return RET_SYN; + p = getstarg(player->argp[1], "File? ", buf); - prexec(player->argp[1]); - while (!abort && status()) { - if (recvclient(buf, sizeof(buf)) < 0) - break; - if (parse(buf, player->argp, &player->condarg, - scanspace, &redir) < 0) { - abort = 1; - continue; - } - if (redir == 0) - pr("\nExecute : %s\n", buf); - if (dispatch(buf, redir) < 0) - abort = 1; - } - if (abort) { - while (recvclient(buf, sizeof(buf)) >= 0) - ; + if (p == (s_char *)0 || p == '\0') + return RET_SYN; + + prexec(player->argp[1]); + while (!abort && status()) { + if (recvclient(buf, sizeof(buf)) < 0) + break; + if (parse(buf, player->argp, &player->condarg, + scanspace, &redir) < 0) { + abort = 1; + continue; } if (redir == 0) - pr("Execute : %s\n", abort ? "aborted" : "terminated"); - return RET_OK; + pr("\nExecute : %s\n", buf); + if (dispatch(buf, redir) < 0) + abort = 1; + } + if (abort) { + while (recvclient(buf, sizeof(buf)) >= 0) ; + } + if (redir == 0) + pr("Execute : %s\n", abort ? "aborted" : "terminated"); + return RET_OK; } int show_motd(void) { - extern s_char *upfil; - int upf; - struct telstr tgm; - s_char buf[MAXTELSIZE]; + extern s_char *upfil; + int upf; + struct telstr tgm; + s_char buf[MAXTELSIZE]; #if !defined(_WIN32) - if ((upf = open(upfil, O_RDONLY, 0)) < 0) + if ((upf = open(upfil, O_RDONLY, 0)) < 0) #else - if ((upf = open(upfil, O_RDONLY|O_BINARY, 0)) < 0) + if ((upf = open(upfil, O_RDONLY | O_BINARY, 0)) < 0) #endif - return RET_FAIL; - if (read(upf, (s_char *) &tgm, sizeof(tgm)) != sizeof(tgm)) { - logerror("bad header on login message (upfil)"); - close(upf); - return RET_FAIL; - } - if (read(upf, buf, tgm.tel_length) != tgm.tel_length) { - logerror("bad length %d on login message", tgm.tel_length); - close(upf); - return RET_FAIL; - } - if (tgm.tel_length >= (long)sizeof(buf)) - tgm.tel_length = sizeof(buf)-1; - buf[tgm.tel_length] = 0; - pr(buf); - (void) close(upf); - return RET_OK; + return RET_FAIL; + if (read(upf, (s_char *)&tgm, sizeof(tgm)) != sizeof(tgm)) { + logerror("bad header on login message (upfil)"); + close(upf); + return RET_FAIL; + } + if (read(upf, buf, tgm.tel_length) != tgm.tel_length) { + logerror("bad length %d on login message", tgm.tel_length); + close(upf); + return RET_FAIL; + } + if (tgm.tel_length >= (long)sizeof(buf)) + tgm.tel_length = sizeof(buf) - 1; + buf[tgm.tel_length] = 0; + pr(buf); + (void)close(upf); + return RET_OK; } -int match_user(char *file, struct player *player) +int +match_user(char *file, struct player *player) { - FILE *fp; - int match = 0; - s_char host[256]; - s_char user[256]; + FILE *fp; + int match = 0; + s_char host[256]; + s_char user[256]; - if ((fp = fopen(file, "r")) == NULL) { - /*logerror("Cannot find file %s", file);*/ - return 0; - } - match = 0; - while (!feof(fp) && !match) { - if (fgets(host, sizeof(host)-1, fp) == NULL) - break; - if (host[0] == '#') continue; - if (fgets(user, sizeof(user)-1, fp) == NULL) - break; - host[strlen(host)-1] = '\0'; - user[strlen(user)-1] = '\0'; - if (strstr(player->userid, user) && - (strstr(player->hostaddr, host) || - strstr(player->hostname, host))) - ++match; - } - fclose(fp); - return match; + if ((fp = fopen(file, "r")) == NULL) { + /*logerror("Cannot find file %s", file); */ + return 0; + } + match = 0; + while (!feof(fp) && !match) { + if (fgets(host, sizeof(host) - 1, fp) == NULL) + break; + if (host[0] == '#') + continue; + if (fgets(user, sizeof(user) - 1, fp) == NULL) + break; + host[strlen(host) - 1] = '\0'; + user[strlen(user) - 1] = '\0'; + if (strstr(player->userid, user) && + (strstr(player->hostaddr, host) || + strstr(player->hostname, host))) + ++match; + } + fclose(fp); + return match; } int quit(void) { - player->state = PS_SHUTDOWN; - return RET_OK; + player->state = PS_SHUTDOWN; + return RET_OK; } s_char * praddr(struct player *player) { - return prbuf("%s@%s", player->userid, - *player->hostname?player->hostname:player->hostaddr); + return prbuf("%s@%s", player->userid, + *player->hostname ? player->hostname : player->hostaddr); } - diff --git a/src/lib/player/recvclient.c b/src/lib/player/recvclient.c index fa8baa533..e5a6dbc8c 100644 --- a/src/lib/player/recvclient.c +++ b/src/lib/player/recvclient.c @@ -44,29 +44,29 @@ int recvclient(s_char *cmd, int size) { - extern int errno; - int count; + extern int errno; + int count; - if (player->aborted) - return -2; - count = io_gets(player->iop, cmd, size); - while (!player->aborted && count < 0) { - io_output_all(player->iop); - io_input(player->iop, IO_WAIT); - if (io_error(player->iop)) - player->aborted++; - else if (io_eof(player->iop)) - return -1; - else - count = io_gets(player->iop, cmd, size); - } - if (count > 0) { - if (strcmp(cmd, "ctld") == 0) - return -1; - if (strcmp(cmd, "aborted") == 0) - player->aborted = 1; - } - if (player->aborted) - return -2; - return count; + if (player->aborted) + return -2; + count = io_gets(player->iop, cmd, size); + while (!player->aborted && count < 0) { + io_output_all(player->iop); + io_input(player->iop, IO_WAIT); + if (io_error(player->iop)) + player->aborted++; + else if (io_eof(player->iop)) + return -1; + else + count = io_gets(player->iop, cmd, size); + } + if (count > 0) { + if (strcmp(cmd, "ctld") == 0) + return -1; + if (strcmp(cmd, "aborted") == 0) + player->aborted = 1; + } + if (player->aborted) + return -2; + return count; } diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index cff1e3882..aab0ca213 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -69,633 +69,637 @@ static void ac_dog(register struct plist *ap, register struct plist *dp); #define DOG_MAX 15 #define FLAK_MAX 15 - /* -7 -6 -5 -4 -3 -2 -1 0 */ + /* -7 -6 -5 -4 -3 -2 -1 0 */ float flaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, - 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, }; + 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, +}; void -ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, coord x, coord y, s_char *path, int mission_flags, int no_air_defense, struct emp_qelem *obomb, struct emp_qelem *oesc) +ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, + coord x, coord y, s_char *path, int mission_flags, + int no_air_defense, struct emp_qelem *obomb, + struct emp_qelem *oesc) { - int val, non_missiles; - int rel; - int dir; - int nats[MAXNOC]; - int lnats[MAXNOC]; - int gotilist[MAXNOC]; - int unfriendly[MAXNOC]; - int overfly[MAXNOC]; - struct emp_qelem ilist[MAXNOC], *qp; - s_char mypath[1024]; - int myp; - int civ, mil; - natid plane_owner; - struct sctstr sect; - struct shpstr ship; - struct lndstr land; - struct nstr_item ni; - natid cn; - struct natstr *over, *mynatp; - struct plist *plp; - int evaded; - struct shiplook head; - struct shiplook *s,*s2; - int changed = 0; - int intx, inty; /* Last sector planes intercepted over */ - int intown = 0; /* Last owner to intercept */ + int val, non_missiles; + int rel; + int dir; + int nats[MAXNOC]; + int lnats[MAXNOC]; + int gotilist[MAXNOC]; + int unfriendly[MAXNOC]; + int overfly[MAXNOC]; + struct emp_qelem ilist[MAXNOC], *qp; + s_char mypath[1024]; + int myp; + int civ, mil; + natid plane_owner; + struct sctstr sect; + struct shpstr ship; + struct lndstr land; + struct nstr_item ni; + natid cn; + struct natstr *over, *mynatp; + struct plist *plp; + int evaded; + struct shiplook head; + struct shiplook *s, *s2; + int changed = 0; + int intx, inty; /* Last sector planes intercepted over */ + int intown = 0; /* Last owner to intercept */ /* We want to only intercept once per sector per owner. So, if we overfly a sector, and then overfly some land units or ships, we don't want to potentially intercept 3 times. */ - bzero((s_char *)&head,sizeof(struct shiplook)); - head.uid = -1; - - plp = (struct plist *) bomb_list->q_forw; - plane_owner = plp->plane.pln_own; - - bzero((s_char *)mypath, 1024); - bcopy(path,mypath,strlen(path)); - myp = 0; - - bzero((s_char *)overfly, sizeof(overfly)); - bzero((s_char *)gotilist, sizeof(gotilist)); - bzero((s_char *)unfriendly, sizeof(unfriendly)); - for (cn=1; cn HOSTILE) - continue; - if (plane_owner == cn) - continue; - unfriendly[cn]++; - } - if (mission_flags & PM_R) { - if (mission_flags & P_S) { - PR(plane_owner,"\nSPY Plane report\n"); - PRdate(plane_owner); - sathead(); - } else if (mission_flags & P_A){ - PR(plane_owner,"\nAnti-Sub Patrol report\n"); - } else { - PR(plane_owner,"\nReconnaissance report\n"); - PRdate(plane_owner); - } - } - - pln_removedupes(bomb_list, esc_list); - while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) { - if ((val = chkdir(dir, DIR_STOP, DIR_LAST)) == 0) - break; - /* XXX using xnorm is probably bad */ - x = xnorm(x + diroff[val][0]); - y = ynorm(y + diroff[val][1]); - getsect(x, y, §); - over = getnatp(sect.sct_own); - if (opt_HIDDEN) { - setcont(plane_owner,sect.sct_own, FOUND_FLY); - } + bzero((s_char *)&head, sizeof(struct shiplook)); + head.uid = -1; + + plp = (struct plist *)bomb_list->q_forw; + plane_owner = plp->plane.pln_own; + + bzero((s_char *)mypath, 1024); + bcopy(path, mypath, strlen(path)); + myp = 0; + + bzero((s_char *)overfly, sizeof(overfly)); + bzero((s_char *)gotilist, sizeof(gotilist)); + bzero((s_char *)unfriendly, sizeof(unfriendly)); + for (cn = 1; cn < MAXNOC; cn++) { + if ((mynatp = getnatp(cn)) == 0) + continue; + rel = getrel(mynatp, plane_owner); + if (rel > HOSTILE) + continue; + if (plane_owner == cn) + continue; + unfriendly[cn]++; + } + if (mission_flags & PM_R) { + if (mission_flags & P_S) { + PR(plane_owner, "\nSPY Plane report\n"); + PRdate(plane_owner); + sathead(); + } else if (mission_flags & P_A) { + PR(plane_owner, "\nAnti-Sub Patrol report\n"); + } else { + PR(plane_owner, "\nReconnaissance report\n"); + PRdate(plane_owner); + } + } + + pln_removedupes(bomb_list, esc_list); + while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) { + if ((val = chkdir(dir, DIR_STOP, DIR_LAST)) == 0) + break; + /* XXX using xnorm is probably bad */ + x = xnorm(x + diroff[val][0]); + y = ynorm(y + diroff[val][1]); + getsect(x, y, §); + over = getnatp(sect.sct_own); + if (opt_HIDDEN) { + setcont(plane_owner, sect.sct_own, FOUND_FLY); + } - if (mission_flags & PM_R) { - if (sect.sct_type == SCT_WATER){ - PR(plane_owner,"flying over %s at %s\n", - dchr[sect.sct_type].d_name, - xyas(x, y, plane_owner)); - if (mission_flags & PM_S) - plane_sweep(bomb_list,x,y); - if (mission_flags & P_A){ - plane_sona(bomb_list,x,y,&head); - } - changed += map_set(plane_owner, - sect.sct_x, sect.sct_y, - dchr[sect.sct_type].d_mnem, - 0); - } else if (mission_flags & P_S) { - satdisp(§, (mission_flags&P_I)?10:50, 1); - } else { - /* This is borrowed from lookout */ - if (sect.sct_own == plane_owner) - PR(plane_owner,"Your "); - else - PR(plane_owner, - "%s (#%d) ", - cname(sect.sct_own), - sect.sct_own); - PR(plane_owner,dchr[sect.sct_type].d_name); - changed += map_set(plane_owner, - sect.sct_x, sect.sct_y, - dchr[sect.sct_type].d_mnem, - 0); - PR(plane_owner," %d%% efficient ", - (sect.sct_own == plane_owner) ? - sect.sct_effic : - roundintby((int)sect.sct_effic,25)); - civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); - if (civ) - PR(plane_owner,"with %s%d civ ", - (sect.sct_own == plane_owner) ? - "" : "approx ", - (sect.sct_own == plane_owner) ? - civ : roundintby(civ, 25)); - if (mil) - PR(plane_owner,"with %s%d mil ", - (sect.sct_own == plane_owner) ? - "" : "approx ", - (sect.sct_own == plane_owner) ? - mil : roundintby(mil, 25)); - PR(plane_owner,"@ %s\n", xyas(x, y, plane_owner)); - } - } else { - PR(plane_owner,"flying over %s at %s\n", - dchr[sect.sct_type].d_name, - xyas(x, y, plane_owner)); - changed += map_set(plane_owner, sect.sct_x, - sect.sct_y, - dchr[sect.sct_type].d_mnem, 0); - } - if ((rel = getrel(over, plane_owner)) == ALLIED) - continue; - - evaded = do_evade(bomb_list,esc_list); - - if (sect.sct_own != 0 && sect.sct_own != plane_owner && - (!evaded)) { - /* We only show planes overhead if they didn't - * evade radar */ - overfly[sect.sct_own]++; - PR(sect.sct_own, "%s planes spotted over %s\n", - cname(plane_owner), xyas(x, y, sect.sct_own)); + if (mission_flags & PM_R) { + if (sect.sct_type == SCT_WATER) { + PR(plane_owner, "flying over %s at %s\n", + dchr[sect.sct_type].d_name, xyas(x, y, plane_owner)); + if (mission_flags & PM_S) + plane_sweep(bomb_list, x, y); + if (mission_flags & P_A) { + plane_sona(bomb_list, x, y, &head); } + changed += map_set(plane_owner, + sect.sct_x, sect.sct_y, + dchr[sect.sct_type].d_mnem, 0); + } else if (mission_flags & P_S) { + satdisp(§, (mission_flags & P_I) ? 10 : 50, 1); + } else { + /* This is borrowed from lookout */ + if (sect.sct_own == plane_owner) + PR(plane_owner, "Your "); + else + PR(plane_owner, + "%s (#%d) ", cname(sect.sct_own), sect.sct_own); + PR(plane_owner, dchr[sect.sct_type].d_name); + changed += map_set(plane_owner, + sect.sct_x, sect.sct_y, + dchr[sect.sct_type].d_mnem, 0); + PR(plane_owner, " %d%% efficient ", + (sect.sct_own == plane_owner) ? + sect.sct_effic : roundintby((int)sect.sct_effic, 25)); + civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR); + if (civ) + PR(plane_owner, "with %s%d civ ", + (sect.sct_own == plane_owner) ? + "" : "approx ", + (sect.sct_own == plane_owner) ? + civ : roundintby(civ, 25)); + if (mil) + PR(plane_owner, "with %s%d mil ", + (sect.sct_own == plane_owner) ? + "" : "approx ", + (sect.sct_own == plane_owner) ? + mil : roundintby(mil, 25)); + PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner)); + } + } else { + PR(plane_owner, "flying over %s at %s\n", + dchr[sect.sct_type].d_name, xyas(x, y, plane_owner)); + changed += map_set(plane_owner, sect.sct_x, + sect.sct_y, dchr[sect.sct_type].d_mnem, 0); + } + if ((rel = getrel(over, plane_owner)) == ALLIED) + continue; - if (!evaded) { - /* Fire flak */ - if (unfriendly[sect.sct_own]) - ac_doflak(bomb_list, §); - /* If bombers left, fire flak from units and ships */ - if (!QEMPTY(bomb_list)) - ac_landflak(bomb_list, x, y); - if (!QEMPTY(bomb_list)) - ac_shipflak(bomb_list, x, y); - } - /* mission planes aborted due to flak -- don't send escorts */ - if (QEMPTY(bomb_list)) - break; - if ((!no_air_defense) && (!evaded)) - air_defense(x,y,plane_owner,bomb_list, esc_list); - - if (sect.sct_own == 0 || sect.sct_own == plane_owner) - continue; - - if (evaded) - continue; - - non_missiles = 0; - for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw){ - struct plist *ip = (struct plist *) qp; - if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M)) - non_missiles = 1; - } - - if (!non_missiles) - continue; - - if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) { - getilist(&ilist[sect.sct_own], sect.sct_own, - bomb_list, esc_list, obomb, oesc); - gotilist[sect.sct_own]++; - } - if (rel > HOSTILE) - continue; - ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own], - sect.sct_own, x, y); - intx = x; - inty = y; - intown = sect.sct_own; + evaded = do_evade(bomb_list, esc_list); + + if (sect.sct_own != 0 && sect.sct_own != plane_owner && (!evaded)) { + /* We only show planes overhead if they didn't + * evade radar */ + overfly[sect.sct_own]++; + PR(sect.sct_own, "%s planes spotted over %s\n", + cname(plane_owner), xyas(x, y, sect.sct_own)); } - /* Let's report all of the overflights even if aborted */ - for (cn = 1; cn < MAXNOC; cn++) { - if (plane_owner == cn) - continue; - if (overfly[cn] > 0) - nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]); + if (!evaded) { + /* Fire flak */ + if (unfriendly[sect.sct_own]) + ac_doflak(bomb_list, §); + /* If bombers left, fire flak from units and ships */ + if (!QEMPTY(bomb_list)) + ac_landflak(bomb_list, x, y); + if (!QEMPTY(bomb_list)) + ac_shipflak(bomb_list, x, y); } - /* If the map changed, update it */ - if (changed) - if (!update_pending && plane_owner == player->cnum) - writemap(player->cnum); - /* Now, if the bomber and escort lists are empty, we are done */ - if (QEMPTY(bomb_list) && QEMPTY(esc_list)) { - if (mission_flags & P_A){ - s=head.next; - while (s != (struct shiplook *)0){ - s2=s; - s=s->next; - free(s2); - } + /* mission planes aborted due to flak -- don't send escorts */ + if (QEMPTY(bomb_list)) + break; + if ((!no_air_defense) && (!evaded)) + air_defense(x, y, plane_owner, bomb_list, esc_list); + + if (sect.sct_own == 0 || sect.sct_own == plane_owner) + continue; + + if (evaded) + continue; + + non_missiles = 0; + for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) { + struct plist *ip = (struct plist *)qp; + if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M)) + non_missiles = 1; + } + + if (!non_missiles) + continue; + + if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) { + getilist(&ilist[sect.sct_own], sect.sct_own, + bomb_list, esc_list, obomb, oesc); + gotilist[sect.sct_own]++; + } + if (rel > HOSTILE) + continue; + ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own], + sect.sct_own, x, y); + intx = x; + inty = y; + intown = sect.sct_own; + } + + /* Let's report all of the overflights even if aborted */ + for (cn = 1; cn < MAXNOC; cn++) { + if (plane_owner == cn) + continue; + if (overfly[cn] > 0) + nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]); + } + /* If the map changed, update it */ + if (changed) + if (!update_pending && plane_owner == player->cnum) + writemap(player->cnum); + /* Now, if the bomber and escort lists are empty, we are done */ + if (QEMPTY(bomb_list) && QEMPTY(esc_list)) { + if (mission_flags & P_A) { + s = head.next; + while (s != (struct shiplook *)0) { + s2 = s; + s = s->next; + free(s2); } - return; - } - - /* Something made it through */ - /* Go figure out if there are ships in this sector, and who's they are */ - bzero((s_char *)nats, sizeof(nats)); - snxtitem_xy(&ni, EF_SHIP, x, y); - while (nxtitem(&ni, (s_char *)&ship)) { - if (mchr[(int)ship.shp_type].m_flags & M_SUB) - continue; - nats[ship.shp_own]++; - } - /* Go figure out if there are units in this sector, and who's they are */ - bzero((s_char *)lnats, sizeof(lnats)); - snxtitem_xy(&ni, EF_LAND, x, y); - while (nxtitem(&ni, (s_char *)&land)) { - lnats[land.lnd_own]++; - } - - /* Now, let's make life a little rougher. */ - for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) { - if (plane_owner == cn) - continue; - intown = -1; - /* Are there ships owned by this country? */ - if (nats[cn] != 0) { - /* Yes. */ - if (cn != 0) - PR(cn, "%s planes spotted over ships in %s\n", - cname(plane_owner), xyas(x, y, cn)); - if (unfriendly[cn]) { - /* They are unfriendly too */ - if (!gotilist[cn]) { - getilist(&ilist[cn], cn, bomb_list, esc_list, obomb, oesc); - gotilist[cn]++; - } - PR(plane_owner, "Flying over %s ships in %s\n", cname(cn), xyas(x, y, plane_owner)); - /* This makes going for ships in harbors tough */ - if (!evaded) { - /* We already fired flak up above. Now we intercept again if we haven't already */ - /* Flag that we intercepted */ - intown = 1; - /* And now intercept again */ - ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, y); - } + } + return; + } + + /* Something made it through */ + /* Go figure out if there are ships in this sector, and who's they are */ + bzero((s_char *)nats, sizeof(nats)); + snxtitem_xy(&ni, EF_SHIP, x, y); + while (nxtitem(&ni, (s_char *)&ship)) { + if (mchr[(int)ship.shp_type].m_flags & M_SUB) + continue; + nats[ship.shp_own]++; + } + /* Go figure out if there are units in this sector, and who's they are */ + bzero((s_char *)lnats, sizeof(lnats)); + snxtitem_xy(&ni, EF_LAND, x, y); + while (nxtitem(&ni, (s_char *)&land)) { + lnats[land.lnd_own]++; + } + + /* Now, let's make life a little rougher. */ + for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) { + if (plane_owner == cn) + continue; + intown = -1; + /* Are there ships owned by this country? */ + if (nats[cn] != 0) { + /* Yes. */ + if (cn != 0) + PR(cn, "%s planes spotted over ships in %s\n", + cname(plane_owner), xyas(x, y, cn)); + if (unfriendly[cn]) { + /* They are unfriendly too */ + if (!gotilist[cn]) { + getilist(&ilist[cn], cn, bomb_list, esc_list, obomb, + oesc); + gotilist[cn]++; + } + PR(plane_owner, "Flying over %s ships in %s\n", cname(cn), + xyas(x, y, plane_owner)); + /* This makes going for ships in harbors tough */ + if (!evaded) { + /* We already fired flak up above. Now we intercept again if we haven't already */ + /* Flag that we intercepted */ + intown = 1; + /* And now intercept again */ + ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, + y); } } - /* Are there units owned by this country? */ - if (lnats[cn] != 0) { - /* Yes. */ - if (cn != 0) - PR(cn, "%s planes spotted over land units in %s\n", - cname(plane_owner), xyas(x, y, cn)); - if (unfriendly[cn]) { - /* They are unfriendly too */ - if (!gotilist[cn]) { - getilist(&ilist[cn], cn, bomb_list, esc_list, obomb, oesc); - gotilist[cn]++; - } - PR(plane_owner,"Flying over %s land units in %s\n", cname(cn), xyas(x, y, plane_owner)); - if (!evaded) { - if (intown == -1) { - /* We haven't intercepted yet, so intercept */ - ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, y); - } + } + /* Are there units owned by this country? */ + if (lnats[cn] != 0) { + /* Yes. */ + if (cn != 0) + PR(cn, "%s planes spotted over land units in %s\n", + cname(plane_owner), xyas(x, y, cn)); + if (unfriendly[cn]) { + /* They are unfriendly too */ + if (!gotilist[cn]) { + getilist(&ilist[cn], cn, bomb_list, esc_list, obomb, + oesc); + gotilist[cn]++; + } + PR(plane_owner, "Flying over %s land units in %s\n", + cname(cn), xyas(x, y, plane_owner)); + if (!evaded) { + if (intown == -1) { + /* We haven't intercepted yet, so intercept */ + ac_intercept(bomb_list, esc_list, &ilist[cn], cn, + x, y); } } } - } - - if ((mission_flags & P_A) && (head.uid != -1)) { - s=head.next; - while (s != (struct shiplook *)0){ - s2=s; - s=s->next; - free(s2); - } - } + } + } + + if ((mission_flags & P_A) && (head.uid != -1)) { + s = head.next; + while (s != (struct shiplook *)0) { + s2 = s; + s = s->next; + free(s2); + } + } } static int count_non_missiles(struct emp_qelem *list) { - struct emp_qelem *qp; - struct plist *plp; - int att_count = 0; - - /* don't intercept missiles */ - for (qp = list->q_forw; qp != list; qp = qp->q_forw){ - plp = (struct plist *)qp; - if (!(plp->pcp->pl_flags & P_M)) - att_count++; - } - return att_count; + struct emp_qelem *qp; + struct plist *plp; + int att_count = 0; + + /* don't intercept missiles */ + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if (!(plp->pcp->pl_flags & P_M)) + att_count++; + } + return att_count; } void -sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list, natid def_own, natid plane_owner, coord x, coord y, int delete_missiles) +sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list, + natid def_own, natid plane_owner, coord x, coord y, + int delete_missiles) { - struct emp_qelem *aqp; - struct emp_qelem *anext; - struct emp_qelem *dqp; - struct emp_qelem *dnext; - struct plist *aplp; - struct plist *dplp; - int first = 1; - - for (aqp = att_list->q_forw, - dqp = def_list->q_forw; - aqp != att_list && - dqp != def_list; - aqp = anext) { - anext = aqp->q_forw; - aplp = (struct plist *)aqp; - if (aplp->pcp->pl_flags & P_M) - continue; - if (aplp->pcp->pl_cost < 1000) - continue; - for (;dqp != def_list; dqp = dnext) { - dnext = dqp->q_forw; - dplp = (struct plist *)dqp; - if (!(dplp->pcp->pl_flags & P_M)) - continue; - - if (dplp->plane.pln_range < mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) { - emp_remque(dqp); - free((s_char *)dqp); - continue; - } - if (mission_pln_equip(dplp, 0, P_F, 0) < 0) { - emp_remque(dqp); - free((s_char *)dqp); - continue; - } - if (first) { - first = 0; - PR(plane_owner,"%s launches SAMs!\n", cname(def_own)); - PR(def_own, "Launching SAMs at %s planes!\n", cname(plane_owner)); - ac_combat_headers(plane_owner, def_own); - } - ac_dog(aplp, dplp); - dqp = dnext; - break; - } - } - if (!first) { - PR(plane_owner, "\n"); - PR(def_own, "\n"); + struct emp_qelem *aqp; + struct emp_qelem *anext; + struct emp_qelem *dqp; + struct emp_qelem *dnext; + struct plist *aplp; + struct plist *dplp; + int first = 1; + + for (aqp = att_list->q_forw, + dqp = def_list->q_forw; + aqp != att_list && dqp != def_list; aqp = anext) { + anext = aqp->q_forw; + aplp = (struct plist *)aqp; + if (aplp->pcp->pl_flags & P_M) + continue; + if (aplp->pcp->pl_cost < 1000) + continue; + for (; dqp != def_list; dqp = dnext) { + dnext = dqp->q_forw; + dplp = (struct plist *)dqp; + if (!(dplp->pcp->pl_flags & P_M)) + continue; + + if (dplp->plane.pln_range < + mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) { + emp_remque(dqp); + free((s_char *)dqp); + continue; + } + if (mission_pln_equip(dplp, 0, P_F, 0) < 0) { + emp_remque(dqp); + free((s_char *)dqp); + continue; + } + if (first) { + first = 0; + PR(plane_owner, "%s launches SAMs!\n", cname(def_own)); + PR(def_own, "Launching SAMs at %s planes!\n", + cname(plane_owner)); + ac_combat_headers(plane_owner, def_own); + } + ac_dog(aplp, dplp); + dqp = dnext; + break; } - if (delete_missiles) { - for (;dqp != def_list; dqp = dnext) { - dnext = dqp->q_forw; - dplp = (struct plist *)dqp; - if (!(dplp->pcp->pl_flags & P_M)) - continue; - emp_remque(dqp); - free((s_char *)dqp); - continue; - } + } + if (!first) { + PR(plane_owner, "\n"); + PR(def_own, "\n"); + } + if (delete_missiles) { + for (; dqp != def_list; dqp = dnext) { + dnext = dqp->q_forw; + dplp = (struct plist *)dqp; + if (!(dplp->pcp->pl_flags & P_M)) + continue; + emp_remque(dqp); + free((s_char *)dqp); + continue; } + } } void -ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, struct emp_qelem *def_list, natid def_own, coord x, coord y) +ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, + struct emp_qelem *def_list, natid def_own, coord x, coord y) { - register struct plnstr *pp; - struct plist *plp; - int icount; - struct emp_qelem *next; - struct emp_qelem *qp; - struct emp_qelem int_list; - int att_count; - natid plane_owner; - int dist; - - plp = (struct plist *)bomb_list->q_forw; - plane_owner = plp->plane.pln_own; - - icount = 0; - - sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0); - sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1); - if (!(att_count = count_non_missiles(bomb_list) + - count_non_missiles(esc_list))) - return; - - emp_initque(&int_list); - for (qp = def_list->q_forw; qp != def_list; qp = next) { - next = qp->q_forw; - plp = (struct plist *) qp; - pp = &plp->plane; - /* SAMs interdict separately */ - if (plp->pcp->pl_flags & P_M) - continue; - dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2; - if (pp->pln_range < dist) - continue; - if (mission_pln_equip(plp, 0, P_F, 0) < 0) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* got one; delete from def_list, add to int_list */ - emp_remque(qp); - emp_insque(qp, &int_list); - pp->pln_mobil -= pln_mobcost(dist,pp,P_F); - putplane(pp->pln_uid, pp); - icount++; - if (icount > att_count) - break; - } - if (icount == 0) - return; - PR(plane_owner,"%d %s fighter%s rising to intercept!\n", icount, - cname(def_own), icount == 1 ? " is" : "s are"); - PR(def_own,"%d fighter%s intercepting %s planes!\n", icount, - icount == 1 ? " is" : "s are", cname(plane_owner)); - ac_combat_headers(plane_owner, def_own); - ac_airtoair(esc_list, &int_list, def_own); - ac_airtoair(bomb_list, &int_list, def_own); - PR(plane_owner, "\n"); - PR(def_own, "\n"); + register struct plnstr *pp; + struct plist *plp; + int icount; + struct emp_qelem *next; + struct emp_qelem *qp; + struct emp_qelem int_list; + int att_count; + natid plane_owner; + int dist; + + plp = (struct plist *)bomb_list->q_forw; + plane_owner = plp->plane.pln_own; + + icount = 0; + + sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0); + sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1); + if (!(att_count = count_non_missiles(bomb_list) + + count_non_missiles(esc_list))) + return; + + emp_initque(&int_list); + for (qp = def_list->q_forw; qp != def_list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + pp = &plp->plane; + /* SAMs interdict separately */ + if (plp->pcp->pl_flags & P_M) + continue; + dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2; + if (pp->pln_range < dist) + continue; + if (mission_pln_equip(plp, 0, P_F, 0) < 0) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + /* got one; delete from def_list, add to int_list */ + emp_remque(qp); + emp_insque(qp, &int_list); + pp->pln_mobil -= pln_mobcost(dist, pp, P_F); + putplane(pp->pln_uid, pp); + icount++; + if (icount > att_count) + break; + } + if (icount == 0) + return; + PR(plane_owner, "%d %s fighter%s rising to intercept!\n", icount, + cname(def_own), icount == 1 ? " is" : "s are"); + PR(def_own, "%d fighter%s intercepting %s planes!\n", icount, + icount == 1 ? " is" : "s are", cname(plane_owner)); + ac_combat_headers(plane_owner, def_own); + ac_airtoair(esc_list, &int_list, def_own); + ac_airtoair(bomb_list, &int_list, def_own); + PR(plane_owner, "\n"); + PR(def_own, "\n"); } void ac_combat_headers(natid plane_owner, natid def_own) { - PR(plane_owner," %-10.10s %-10.10s strength int odds damage results\n", cname(plane_owner), cname(def_own)); - PR(def_own," %-10.10s %-10.10s strength int odds damage results\n", cname(def_own), cname(plane_owner)); + PR(plane_owner, + " %-10.10s %-10.10s strength int odds damage results\n", + cname(plane_owner), cname(def_own)); + PR(def_own, + " %-10.10s %-10.10s strength int odds damage results\n", + cname(def_own), cname(plane_owner)); } /* * air-to-air combat. */ void -ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list, natid def_own) +ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list, + natid def_own) { - register struct plist *attacker; - register struct plist *interceptor; - struct emp_qelem *att; - struct emp_qelem *in; - int nplanes; - int more_att; - int more_int; - struct emp_qelem *att_next; - struct emp_qelem *in_next; - natid att_own; - - att = att_list->q_forw; - in = int_list->q_forw; - more_att = 1; - more_int = 1; - if (QEMPTY(att_list) || QEMPTY(int_list)) { - more_att = 0; - more_int = 0; - } - while (more_att || more_int) { - in_next = in->q_forw; - att_next = att->q_forw; - attacker = (struct plist *) att; - - /* skip missiles. If only missiles left, we're done */ - if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M){ - att = att_next; - if (att == att_list) { - more_att = 0; - if (QEMPTY(att_list)) - more_int = 0; - else - att = att->q_forw; - } - if (all_missiles(att_list)) - more_att = 0; - continue; - } - interceptor = (struct plist *) in; - att_own = attacker->plane.pln_own; - def_own = interceptor->plane.pln_own; - nplanes = attacker->plane.pln_effic; - if (nplanes > interceptor->plane.pln_effic) - nplanes = interceptor->plane.pln_effic; - ac_dog(attacker, interceptor); - in = in_next; - att = att_next; - if (att == att_list) { - more_att = 0; - if (QEMPTY(att_list)) - more_int = 0; - else - att = att->q_forw; - } - if (in == int_list) { - more_int = 0; - if (QEMPTY(int_list)) - more_att = 0; - else - in = in->q_forw; - } - } + register struct plist *attacker; + register struct plist *interceptor; + struct emp_qelem *att; + struct emp_qelem *in; + int nplanes; + int more_att; + int more_int; + struct emp_qelem *att_next; + struct emp_qelem *in_next; + natid att_own; + + att = att_list->q_forw; + in = int_list->q_forw; + more_att = 1; + more_int = 1; + if (QEMPTY(att_list) || QEMPTY(int_list)) { + more_att = 0; + more_int = 0; + } + while (more_att || more_int) { + in_next = in->q_forw; + att_next = att->q_forw; + attacker = (struct plist *)att; + + /* skip missiles. If only missiles left, we're done */ + if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M) { + att = att_next; + if (att == att_list) { + more_att = 0; + if (QEMPTY(att_list)) + more_int = 0; + else + att = att->q_forw; + } + if (all_missiles(att_list)) + more_att = 0; + continue; + } + interceptor = (struct plist *)in; + att_own = attacker->plane.pln_own; + def_own = interceptor->plane.pln_own; + nplanes = attacker->plane.pln_effic; + if (nplanes > interceptor->plane.pln_effic) + nplanes = interceptor->plane.pln_effic; + ac_dog(attacker, interceptor); + in = in_next; + att = att_next; + if (att == att_list) { + more_att = 0; + if (QEMPTY(att_list)) + more_int = 0; + else + att = att->q_forw; + } + if (in == int_list) { + more_int = 0; + if (QEMPTY(int_list)) + more_att = 0; + else + in = in->q_forw; + } + } } int all_missiles(struct emp_qelem *att_list) { - struct emp_qelem *qp; - struct plist *p; - - qp = att_list->q_forw; - while (qp != att_list){ - p = (struct plist *)qp; - if (!(plchr[(int)p->plane.pln_type].pl_flags & P_M)) - return 0; - - qp = qp->q_forw; - } - return 1; + struct emp_qelem *qp; + struct plist *p; + + qp = att_list->q_forw; + while (qp != att_list) { + p = (struct plist *)qp; + if (!(plchr[(int)p->plane.pln_type].pl_flags & P_M)) + return 0; + + qp = qp->q_forw; + } + return 1; } static void ac_dog(register struct plist *ap, register struct plist *dp) { - int att, def; - double odds; - int intensity; - natid att_own, def_own; - int adam, ddam; - s_char mesg[1024]; - s_char temp[14]; - - att_own = ap->plane.pln_own; - def_own = dp->plane.pln_own; - - PR(att_own," %3.3s #%-4d %3.3s #%-4d", - ap->pcp->pl_name, - ap->plane.pln_uid, + int att, def; + double odds; + int intensity; + natid att_own, def_own; + int adam, ddam; + s_char mesg[1024]; + s_char temp[14]; + + att_own = ap->plane.pln_own; + def_own = dp->plane.pln_own; + + PR(att_own, " %3.3s #%-4d %3.3s #%-4d", + ap->pcp->pl_name, + ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid); + if (def_own) + PR(def_own, " %3.3s #%-4d %3.3s #%-4d", dp->pcp->pl_name, - dp->plane.pln_uid); - if (def_own) - PR(def_own," %3.3s #%-4d %3.3s #%-4d", - dp->pcp->pl_name, - dp->plane.pln_uid, - ap->pcp->pl_name, - ap->plane.pln_uid); - if (ap->plane.pln_att == 0){ - att = ap->plane.pln_def * ap->plane.pln_effic / 100; - att = MAX(att,ap->pcp->pl_def/2); - }else{ - att = ap->plane.pln_att * ap->plane.pln_effic / 100; - att = MAX(att,ap->pcp->pl_att/2); - } - - def = dp->plane.pln_def * dp->plane.pln_effic / 100; - def = MAX(def,dp->pcp->pl_def/2); - - if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0) - att -= 2; - if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0) - def -= 2; - att += ((float)ap->pcp->pl_stealth/25.0); - def += ((float)dp->pcp->pl_stealth/25.0); - if (att < 1) { - def += 1 - att; - att = 1; - } - if (def < 1) { - att += 1 - def; - def = 1; + dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid); + if (ap->plane.pln_att == 0) { + att = ap->plane.pln_def * ap->plane.pln_effic / 100; + att = MAX(att, ap->pcp->pl_def / 2); + } else { + att = ap->plane.pln_att * ap->plane.pln_effic / 100; + att = MAX(att, ap->pcp->pl_att / 2); + } + + def = dp->plane.pln_def * dp->plane.pln_effic / 100; + def = MAX(def, dp->pcp->pl_def / 2); + + if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0) + att -= 2; + if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0) + def -= 2; + att += ((float)ap->pcp->pl_stealth / 25.0); + def += ((float)dp->pcp->pl_stealth / 25.0); + if (att < 1) { + def += 1 - att; + att = 1; + } + if (def < 1) { + att += 1 - def; + def = 1; + } + odds = ((double)att / ((double)def + (double)att)); + if (odds <= 0.05) + odds = 0.05; + intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1; + + PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds); + PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds); + + adam = 0; + ddam = 0; + while ((intensity--) > 0) { + + if (chance(odds)) { + ddam += 1; + if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF) + intensity = 0; + } else { + adam += 1; + if ((ap->plane.pln_effic - adam) < PLANE_MINEFF) + intensity = 0; } - odds = ((double)att/((double)def+(double)att)); - if (odds <= 0.05) - odds = 0.05; - intensity = roll(20)+roll(20)+roll(20)+roll(20)+1; - - PR(att_own," %3d/%-3d %3d %3.2f ",att,def,intensity,odds); - PR(def_own," %3d/%-3d %3d %3.2f ",def,att,intensity,odds); - - adam = 0; ddam = 0; - while ((intensity--)>0){ - - if (chance(odds)) { - ddam += 1; - if ((dp->plane.pln_effic-ddam) < PLANE_MINEFF) - intensity=0; - } else { - adam += 1; - if ((ap->plane.pln_effic-adam) < PLANE_MINEFF) - intensity=0; - } - } - - if (dp->pcp->pl_flags & P_M) - ddam = 100; - - PR(att_own,"%3d/%-3d", adam, ddam); - PR(def_own,"%3d/%-3d", ddam, adam); - ac_planedamage(ap, dp->plane.pln_own, - adam, def_own, 1, 0, mesg); - strncpy(temp,mesg,14); - ac_planedamage(dp, ap->plane.pln_own, - ddam, att_own, 1, 0, mesg); - PR(att_own, "%-13.13s %-13.13s\n", temp, mesg); - PR(def_own, "%-13.13s %-13.13s\n", mesg, temp); + } + + if (dp->pcp->pl_flags & P_M) + ddam = 100; + + PR(att_own, "%3d/%-3d", adam, ddam); + PR(def_own, "%3d/%-3d", ddam, adam); + ac_planedamage(ap, dp->plane.pln_own, adam, def_own, 1, 0, mesg); + strncpy(temp, mesg, 14); + ac_planedamage(dp, ap->plane.pln_own, ddam, att_own, 1, 0, mesg); + PR(att_own, "%-13.13s %-13.13s\n", temp, mesg); + PR(def_own, "%-13.13s %-13.13s\n", mesg, temp); } /* @@ -711,250 +715,252 @@ ac_dog(register struct plist *ap, register struct plist *dp) * call. (this has caused bugs in the past) */ void -ac_planedamage(struct plist *plp, natid from, int dam, natid other, int checkabort, int show, s_char *mesg) +ac_planedamage(struct plist *plp, natid from, int dam, natid other, + int checkabort, int show, s_char *mesg) { - register struct plnstr *pp; - int disp; - s_char dmess[255]; - int eff; - struct shpstr ship; - struct lndstr land; - /* s_char *sprintf(); already in misc.h [JFW] */ - natid plane_owner; - - disp = 0; - pp = &plp->plane; - plane_owner = pp->pln_own; - eff = pp->pln_effic; - sprintf(dmess," no damage"); - if (dam <= 0) { - strcpy(mesg, dmess); - return; - } - bzero(dmess,255); - eff -= dam; - if (eff < 0) - eff = 0; - if (eff < PLANE_MINEFF) { - sprintf(dmess," shot down"); - disp = 1; - } else if (eff < 80 && chance((100-eff)/100.0) && checkabort){ - sprintf(dmess," aborted @%2d%%", eff); - disp = 2; - } else if (show == 0) { - sprintf(dmess," cleared"); - } - - if ((plp->pcp->pl_flags & P_M) == 0) { - if (show) { - PR(plane_owner, " %s %s takes %d%s.\n", - cname(pp->pln_own), - prplane(pp), dam, dmess); - if (other) - PR(other, " %s %s takes %d%s.\n", - cname(pp->pln_own), - prplane(pp), dam, dmess); - } - } - if (show && checkabort == 1) { - PR(plane_owner,"\n"); + register struct plnstr *pp; + int disp; + s_char dmess[255]; + int eff; + struct shpstr ship; + struct lndstr land; + /* s_char *sprintf(); already in misc.h [JFW] */ + natid plane_owner; + + disp = 0; + pp = &plp->plane; + plane_owner = pp->pln_own; + eff = pp->pln_effic; + sprintf(dmess, " no damage"); + if (dam <= 0) { + strcpy(mesg, dmess); + return; + } + bzero(dmess, 255); + eff -= dam; + if (eff < 0) + eff = 0; + if (eff < PLANE_MINEFF) { + sprintf(dmess, " shot down"); + disp = 1; + } else if (eff < 80 && chance((100 - eff) / 100.0) && checkabort) { + sprintf(dmess, " aborted @%2d%%", eff); + disp = 2; + } else if (show == 0) { + sprintf(dmess, " cleared"); + } + + if ((plp->pcp->pl_flags & P_M) == 0) { + if (show) { + PR(plane_owner, " %s %s takes %d%s.\n", + cname(pp->pln_own), prplane(pp), dam, dmess); if (other) - PR(other,"\n"); - } - - pp->pln_effic = eff; - pp->pln_mobil -= min(32 + pp->pln_mobil, dam/2); - if (disp == 1) { - if (from != 0 && (plp->pcp->pl_flags & P_M) == 0) - nreport(from, N_DOWN_PLANE, pp->pln_own, 1); - if (pp->pln_ship >= 0) { - getship(pp->pln_ship,&ship); - take_plane_off_ship(pp,&ship); - } - if (pp->pln_land >= 0) { - getland(pp->pln_land,&land); - take_plane_off_land(pp,&land); - } - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - putplane(pp->pln_uid, pp); - emp_remque(&plp->queue); - free((s_char *)plp); - } else if (disp == 2) { - putplane(pp->pln_uid, pp); - emp_remque(&plp->queue); - free((s_char *)plp); - } else - putplane(pp->pln_uid, pp); - strcpy(mesg, dmess); + PR(other, " %s %s takes %d%s.\n", + cname(pp->pln_own), prplane(pp), dam, dmess); + } + } + if (show && checkabort == 1) { + PR(plane_owner, "\n"); + if (other) + PR(other, "\n"); + } + + pp->pln_effic = eff; + pp->pln_mobil -= min(32 + pp->pln_mobil, dam / 2); + if (disp == 1) { + if (from != 0 && (plp->pcp->pl_flags & P_M) == 0) + nreport(from, N_DOWN_PLANE, pp->pln_own, 1); + if (pp->pln_ship >= 0) { + getship(pp->pln_ship, &ship); + take_plane_off_ship(pp, &ship); + } + if (pp->pln_land >= 0) { + getland(pp->pln_land, &land); + take_plane_off_land(pp, &land); + } + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + pp->pln_own = 0; + putplane(pp->pln_uid, pp); + emp_remque(&plp->queue); + free((s_char *)plp); + } else if (disp == 2) { + putplane(pp->pln_uid, pp); + emp_remque(&plp->queue); + free((s_char *)plp); + } else + putplane(pp->pln_uid, pp); + strcpy(mesg, dmess); } void ac_doflak(struct emp_qelem *list, struct sctstr *from) { - int shell, add; - int gun; - natid plane_owner; - struct plist *plp; - - plp = (struct plist *)list->q_forw; - plane_owner = plp->plane.pln_own; - - gun = getvar(V_GUN, (s_char *)from, EF_SECTOR); - shell = getvar(V_SHELL, (s_char *)from, EF_SECTOR); - add = 0; - if (shell < (gun/2)) - add = supply_commod(from->sct_own,from->sct_x,from->sct_y, - I_SHELL,ldround(((double)gun/2.0),1)-shell); - shell += add; - if (gun == 0 || shell == 0) - return; - if (gun > shell*2) - gun = shell*2; - if (gun > 14) - gun = 14; - - putvar(V_SHELL, shell, (s_char *)from, EF_SECTOR); - putsect(from); - gun = 2.0 * tfact(from->sct_own, (double) gun); - if (gun > 0) { - PR(plane_owner,"firing %d flak guns in %s...\n", - gun, xyas(from->sct_x, from->sct_y, plane_owner)); - if(from->sct_own != 0) - PR(from->sct_own, "firing %d flak guns in %s...\n", - gun, xyas(from->sct_x, from->sct_y, from->sct_own)); - ac_fireflak(list, from->sct_own, 0, gun); - } + int shell, add; + int gun; + natid plane_owner; + struct plist *plp; + + plp = (struct plist *)list->q_forw; + plane_owner = plp->plane.pln_own; + + gun = getvar(V_GUN, (s_char *)from, EF_SECTOR); + shell = getvar(V_SHELL, (s_char *)from, EF_SECTOR); + add = 0; + if (shell < (gun / 2)) + add = supply_commod(from->sct_own, from->sct_x, from->sct_y, + I_SHELL, ldround(((double)gun / 2.0), + 1) - shell); + shell += add; + if (gun == 0 || shell == 0) + return; + if (gun > shell * 2) + gun = shell * 2; + if (gun > 14) + gun = 14; + + putvar(V_SHELL, shell, (s_char *)from, EF_SECTOR); + putsect(from); + gun = 2.0 * tfact(from->sct_own, (double)gun); + if (gun > 0) { + PR(plane_owner, "firing %d flak guns in %s...\n", + gun, xyas(from->sct_x, from->sct_y, plane_owner)); + if (from->sct_own != 0) + PR(from->sct_own, "firing %d flak guns in %s...\n", + gun, xyas(from->sct_x, from->sct_y, from->sct_own)); + ac_fireflak(list, from->sct_own, 0, gun); + } } void ac_shipflak(struct emp_qelem *list, coord x, coord y) { - struct nstr_item ni; - struct shpstr ship; - struct mchrstr *mcp; - int firing; - int guns; - int gun; - int shell; - int rel; - struct plist *plp; - natid plane_owner; - natid from; - int nats[MAXNOC]; - - plp = (struct plist *)list->q_forw; - plane_owner = plp->plane.pln_own; - - bzero((s_char *)nats, sizeof(nats)); - guns = 0; - snxtitem_xy(&ni, EF_SHIP, x, y); - while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&ship)) { - if (ship.shp_own == 0 || ship.shp_own == plane_owner) - continue; - if (guns >= 14) - break; - mcp = &mchr[(int)ship.shp_type]; - if (mcp->m_flags & M_SUB) - continue; - rel = getrel(getnatp(ship.shp_own), plane_owner); - if (rel > HOSTILE) - continue; - shell = gun = 0; - gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim); - if (gun) { - shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP); - if (shell <= 0) - shell = supply_commod(ship.shp_own, ship.shp_x, - ship.shp_y, I_SHELL, 1); - } - if (gun == 0 || shell == 0) - continue; - firing = (int) (techfact(ship.shp_tech, (double)gun) * 2.0); - guns += firing; - - if (!nats[ship.shp_own]) { - /* First time here, print the message */ - PR(ship.shp_own, "%s planes spotted over ships in %s\n", - cname(plane_owner), xyas(x, y, ship.shp_own)); - PR(plane_owner, "Flying over %s ships in %s\n", cname(ship.shp_own), - xyas(x, y, plane_owner)); - nats[ship.shp_own] = 1; - } - PR(ship.shp_own, "firing %d flak guns from %s...\n", - firing, prship(&ship)); - putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP); - putship(ship.shp_uid, &ship); - from = ship.shp_own; - } - if (guns > 0) { - if (guns > 14) - guns = 14; - guns = 2.0 * tfact(from, (double)guns); - PR(plane_owner, "Flak! Ships firing %d flak guns...\n", guns); - ac_fireflak(list, from, 0, guns); + struct nstr_item ni; + struct shpstr ship; + struct mchrstr *mcp; + int firing; + int guns; + int gun; + int shell; + int rel; + struct plist *plp; + natid plane_owner; + natid from; + int nats[MAXNOC]; + + plp = (struct plist *)list->q_forw; + plane_owner = plp->plane.pln_own; + + bzero((s_char *)nats, sizeof(nats)); + guns = 0; + snxtitem_xy(&ni, EF_SHIP, x, y); + while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&ship)) { + if (ship.shp_own == 0 || ship.shp_own == plane_owner) + continue; + if (guns >= 14) + break; + mcp = &mchr[(int)ship.shp_type]; + if (mcp->m_flags & M_SUB) + continue; + rel = getrel(getnatp(ship.shp_own), plane_owner); + if (rel > HOSTILE) + continue; + shell = gun = 0; + gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim); + if (gun) { + shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP); + if (shell <= 0) + shell = supply_commod(ship.shp_own, ship.shp_x, + ship.shp_y, I_SHELL, 1); + } + if (gun == 0 || shell == 0) + continue; + firing = (int)(techfact(ship.shp_tech, (double)gun) * 2.0); + guns += firing; + + if (!nats[ship.shp_own]) { + /* First time here, print the message */ + PR(ship.shp_own, "%s planes spotted over ships in %s\n", + cname(plane_owner), xyas(x, y, ship.shp_own)); + PR(plane_owner, "Flying over %s ships in %s\n", + cname(ship.shp_own), xyas(x, y, plane_owner)); + nats[ship.shp_own] = 1; } + PR(ship.shp_own, "firing %d flak guns from %s...\n", + firing, prship(&ship)); + putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP); + putship(ship.shp_uid, &ship); + from = ship.shp_own; + } + if (guns > 0) { + if (guns > 14) + guns = 14; + guns = 2.0 * tfact(from, (double)guns); + PR(plane_owner, "Flak! Ships firing %d flak guns...\n", guns); + ac_fireflak(list, from, 0, guns); + } } void ac_landflak(struct emp_qelem *list, coord x, coord y) { - struct nstr_item ni; - struct lndstr land; - struct lchrstr *lcp; - int firing; - int guns; - int rel; - natid from; - struct plist *plp; - natid plane_owner; - int nats[MAXNOC]; - - plp = (struct plist *)list->q_forw; - plane_owner = plp->plane.pln_own; - - bzero((s_char *)nats, sizeof(nats)); - guns = 0; - snxtitem_xy(&ni, EF_LAND, x, y); - while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_own == 0 || land.lnd_own == plane_owner) - continue; - if (guns >= 14) - break; - lcp = &lchr[(int)land.lnd_type]; - - if ((lcp->l_flags & L_FLAK) == 0) - continue; - - if (land.lnd_aaf == 0) - continue; - - rel = getrel(getnatp(land.lnd_own), plane_owner); - if (rel > HOSTILE) - continue; - firing = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0); - guns += firing; - - if (!nats[land.lnd_own]) { - /* First time here, print the message */ - PR(land.lnd_own, "%s planes spotted over land units in %s\n", - cname(plane_owner), xyas(x, y, land.lnd_own)); - PR(plane_owner, "Flying over %s land units in %s\n", cname(land.lnd_own), - xyas(x, y, plane_owner)); - nats[land.lnd_own] = 1; - } - PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n", - prland(&land), land.lnd_aaf); - - from = land.lnd_own; /* We always use the last owner as the from */ - } - if (guns > 0) { - if (guns > 14) - guns = 14; - guns = 2.0 * tfact(from, (double)guns); - PR(plane_owner, "Flak! Land units firing %d flak guns...\n", guns); - ac_fireflak(list, from, 0, guns); - } + struct nstr_item ni; + struct lndstr land; + struct lchrstr *lcp; + int firing; + int guns; + int rel; + natid from; + struct plist *plp; + natid plane_owner; + int nats[MAXNOC]; + + plp = (struct plist *)list->q_forw; + plane_owner = plp->plane.pln_own; + + bzero((s_char *)nats, sizeof(nats)); + guns = 0; + snxtitem_xy(&ni, EF_LAND, x, y); + while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0 || land.lnd_own == plane_owner) + continue; + if (guns >= 14) + break; + lcp = &lchr[(int)land.lnd_type]; + + if ((lcp->l_flags & L_FLAK) == 0) + continue; + + if (land.lnd_aaf == 0) + continue; + + rel = getrel(getnatp(land.lnd_own), plane_owner); + if (rel > HOSTILE) + continue; + firing = + (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0); + guns += firing; + + if (!nats[land.lnd_own]) { + /* First time here, print the message */ + PR(land.lnd_own, "%s planes spotted over land units in %s\n", + cname(plane_owner), xyas(x, y, land.lnd_own)); + PR(plane_owner, "Flying over %s land units in %s\n", + cname(land.lnd_own), xyas(x, y, plane_owner)); + nats[land.lnd_own] = 1; + } + PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n", + prland(&land), land.lnd_aaf); + + from = land.lnd_own; /* We always use the last owner as the from */ + } + if (guns > 0) { + if (guns > 14) + guns = 14; + guns = 2.0 * tfact(from, (double)guns); + PR(plane_owner, "Flak! Land units firing %d flak guns...\n", + guns); + ac_fireflak(list, from, 0, guns); + } } /* @@ -963,48 +969,48 @@ ac_landflak(struct emp_qelem *list, coord x, coord y) void ac_fireflak(struct emp_qelem *list, natid from, natid other, int guns) { - extern double flakscale; - register struct plnstr *pp; - struct plist *plp; - int n; - float mult; - int diff; - struct emp_qelem *qp; - struct emp_qelem *next; - s_char msg[255]; - - plp = (struct plist *)list->q_forw; - - for (qp = list->q_forw; qp != list; qp = next) { - /* - * fighters don't get shot at by flak - * non-tactical bombers are harder to hit with flak. - * ('Cause they're not dive-bombing?) - */ - next = qp->q_forw; - plp = (struct plist *) qp; - pp = &plp->plane; - diff = guns - pp->pln_def; - if ((plp->pcp->pl_flags & P_T) == 0) - diff--; - if (plp->pcp->pl_flags & P_X) - diff -= 2; - if (plp->pcp->pl_flags & P_H) - diff -= 1; - if (diff > 8) - mult = flaktable[FLAK_MAX] * 1.33; - else if (diff < -7) - mult = flaktable[0] * 0.66; - else { - diff += 7; - mult = flaktable[diff]; - } - mult *= flakscale; - n = (int) ((roll(8) + 2) * mult); - if (n > 100) - n = 100; - ac_planedamage(plp, from, n, other, 2, 1, msg); - } + extern double flakscale; + register struct plnstr *pp; + struct plist *plp; + int n; + float mult; + int diff; + struct emp_qelem *qp; + struct emp_qelem *next; + s_char msg[255]; + + plp = (struct plist *)list->q_forw; + + for (qp = list->q_forw; qp != list; qp = next) { + /* + * fighters don't get shot at by flak + * non-tactical bombers are harder to hit with flak. + * ('Cause they're not dive-bombing?) + */ + next = qp->q_forw; + plp = (struct plist *)qp; + pp = &plp->plane; + diff = guns - pp->pln_def; + if ((plp->pcp->pl_flags & P_T) == 0) + diff--; + if (plp->pcp->pl_flags & P_X) + diff -= 2; + if (plp->pcp->pl_flags & P_H) + diff -= 1; + if (diff > 8) + mult = flaktable[FLAK_MAX] * 1.33; + else if (diff < -7) + mult = flaktable[0] * 0.66; + else { + diff += 7; + mult = flaktable[diff]; + } + mult *= flakscale; + n = (int)((roll(8) + 2) * mult); + if (n > 100) + n = 100; + ac_planedamage(plp, from, n, other, 2, 1, msg); + } } /* @@ -1013,21 +1019,21 @@ ac_fireflak(struct emp_qelem *list, natid from, natid other, int guns) int ac_isflying(struct plnstr *plane, struct emp_qelem *list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct plnstr *pp; - struct plist *plp; - - if (!list) + struct emp_qelem *qp; + struct emp_qelem *next; + struct plnstr *pp; + struct plist *plp; + + if (!list) + return 0; + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + pp = &plp->plane; + if (plane->pln_uid == pp->pln_uid) + return 1; + } return 0; - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *) qp; - pp = &plp->plane; - if (plane->pln_uid == pp->pln_uid) - return 1; - } - return 0; } @@ -1035,162 +1041,160 @@ ac_isflying(struct plnstr *plane, struct emp_qelem *list) * Get a list of planes available for interception duties. */ static void -getilist(struct emp_qelem *list, natid own, struct emp_qelem *a, struct emp_qelem *b, struct emp_qelem *c, struct emp_qelem *d) +getilist(struct emp_qelem *list, natid own, struct emp_qelem *a, + struct emp_qelem *b, struct emp_qelem *c, struct emp_qelem *d) { - register struct plchrstr *pcp; - struct plnstr plane; - struct shpstr ship; - struct lndstr land; - struct sctstr sect; - struct nstr_item ni; - int type; - s_char *ptr; - struct plist *ip; - - emp_initque(list); - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) { - if (plane.pln_own != own) - continue; - pcp = &plchr[(int)plane.pln_type]; - if ((pcp->pl_flags & P_F) == 0) - continue; - if (plane.pln_mission != 0) - continue; - if (plane.pln_mobil <= 0) - continue; - if (plane.pln_effic < 40) - continue; - if (plane.pln_ship >= 0) { - if (!can_fly(plane.pln_uid)) - continue; - getship(plane.pln_ship,&ship); - ptr = (s_char *)&ship; - type = EF_SHIP; - } else - if (plane.pln_land >= 0) { - if (!can_fly(plane.pln_uid)) - continue; - getland(plane.pln_land,&land); - ptr = (s_char *)&land; - type = EF_LAND; - } else { - getsect(plane.pln_x, plane.pln_y, §); - ptr = (s_char *)§ - type = EF_SECTOR; + register struct plchrstr *pcp; + struct plnstr plane; + struct shpstr ship; + struct lndstr land; + struct sctstr sect; + struct nstr_item ni; + int type; + s_char *ptr; + struct plist *ip; + + emp_initque(list); + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own != own) + continue; + pcp = &plchr[(int)plane.pln_type]; + if ((pcp->pl_flags & P_F) == 0) + continue; + if (plane.pln_mission != 0) + continue; + if (plane.pln_mobil <= 0) + continue; + if (plane.pln_effic < 40) + continue; + if (plane.pln_ship >= 0) { + if (!can_fly(plane.pln_uid)) + continue; + getship(plane.pln_ship, &ship); + ptr = (s_char *)&ship; + type = EF_SHIP; + } else if (plane.pln_land >= 0) { + if (!can_fly(plane.pln_uid)) + continue; + getland(plane.pln_land, &land); + ptr = (s_char *)&land; + type = EF_LAND; + } else { + getsect(plane.pln_x, plane.pln_y, §); + ptr = (s_char *)§ + type = EF_SECTOR; #if 0 - if (sect.sct_effic < 60 && (pcp->pl_flags & P_V) == 0) - continue; + if (sect.sct_effic < 60 && (pcp->pl_flags & P_V) == 0) + continue; #else - if ((sect.sct_effic < 60 || sect.sct_type != SCT_AIRPT) - && (pcp->pl_flags & P_V) == 0) - continue; + if ((sect.sct_effic < 60 || sect.sct_type != SCT_AIRPT) + && (pcp->pl_flags & P_V) == 0) + continue; #endif - } - if (((float)getvar(V_PETROL, ptr, type)) < - (((float)pcp->pl_fuel)/2.0)) - continue; - /* Finally, is it in the list of planes already in - flight? */ - if (ac_isflying(&plane, a)) - continue; - if (ac_isflying(&plane, b)) - continue; - if (ac_isflying(&plane, c)) - continue; - if (ac_isflying(&plane, d)) - continue; - /* got one! */ - ip = (struct plist *) malloc(sizeof(*ip)); - ip->state = P_OK; - ip->bombs = 0; - ip->misc = 0; - ip->pcp = &plchr[(int)plane.pln_type]; - bcopy((s_char *)&plane, (s_char *)&ip->plane, sizeof(plane)); - emp_insque(&ip->queue, list); - } + } + if (((float)getvar(V_PETROL, ptr, type)) < + (((float)pcp->pl_fuel) / 2.0)) + continue; + /* Finally, is it in the list of planes already in + flight? */ + if (ac_isflying(&plane, a)) + continue; + if (ac_isflying(&plane, b)) + continue; + if (ac_isflying(&plane, c)) + continue; + if (ac_isflying(&plane, d)) + continue; + /* got one! */ + ip = (struct plist *)malloc(sizeof(*ip)); + ip->state = P_OK; + ip->bombs = 0; + ip->misc = 0; + ip->pcp = &plchr[(int)plane.pln_type]; + bcopy((s_char *)&plane, (s_char *)&ip->plane, sizeof(plane)); + emp_insque(&ip->queue, list); + } } int -can_fly(int p) /* Can this plane fly from the ship or land unit it is on? */ - -{ - struct plnstr plane; - struct shpstr ship; - struct lndstr land; - struct plchrstr *pcp; - struct mchrstr *scp; - struct lchrstr *lcp; - - getplane(p,&plane); - pcp = &plchr[(int)plane.pln_type]; - - if (plane.pln_ship >= 0){ - if ( - !(pcp->pl_flags & P_L) && !(pcp->pl_flags & P_M) - && !(pcp->pl_flags & P_K) - && !(pcp->pl_flags & P_E) - ) - return 0; - - getship(plane.pln_ship,&ship); - scp = & mchr[(int)ship.shp_type]; - - if ((pcp->pl_flags & P_L) && (scp->m_flags & M_FLY)){ - return 1; - } - - if ((pcp->pl_flags & P_M) && (scp->m_flags & M_MSL)){ - return 1; - } - - if ((pcp->pl_flags & P_K) && (scp->m_flags & M_CHOPPER)){ - return 1; - } - - if ((pcp->pl_flags & P_E) && (scp->m_flags & M_XLIGHT)){ - return 1; - } - } - - if (plane.pln_land >= 0){ - if (!(pcp->pl_flags & P_E)) - return 0; - - getland(plane.pln_land,&land); - lcp = & lchr[(int)land.lnd_type]; - - if ((pcp->pl_flags & P_E) && (lcp->l_flags & L_XLIGHT)){ - return 1; - } - } - - return 0; +can_fly(int p) +{ /* Can this plane fly from the ship or land unit it is on? */ + struct plnstr plane; + struct shpstr ship; + struct lndstr land; + struct plchrstr *pcp; + struct mchrstr *scp; + struct lchrstr *lcp; + + getplane(p, &plane); + pcp = &plchr[(int)plane.pln_type]; + + if (plane.pln_ship >= 0) { + if (!(pcp->pl_flags & P_L) && !(pcp->pl_flags & P_M) + && !(pcp->pl_flags & P_K) + && !(pcp->pl_flags & P_E) + ) + return 0; + + getship(plane.pln_ship, &ship); + scp = &mchr[(int)ship.shp_type]; + + if ((pcp->pl_flags & P_L) && (scp->m_flags & M_FLY)) { + return 1; + } + + if ((pcp->pl_flags & P_M) && (scp->m_flags & M_MSL)) { + return 1; + } + + if ((pcp->pl_flags & P_K) && (scp->m_flags & M_CHOPPER)) { + return 1; + } + + if ((pcp->pl_flags & P_E) && (scp->m_flags & M_XLIGHT)) { + return 1; + } + } + + if (plane.pln_land >= 0) { + if (!(pcp->pl_flags & P_E)) + return 0; + + getland(plane.pln_land, &land); + lcp = &lchr[(int)land.lnd_type]; + + if ((pcp->pl_flags & P_E) && (lcp->l_flags & L_XLIGHT)) { + return 1; + } + } + + return 0; } int do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list) { - struct emp_qelem *qp; - double evade; - struct plist *plp; - - evade=100.0; - for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw){ - plp = (struct plist *) qp; - if (evade > ((float)plp->pcp->pl_stealth/100.0)) - evade = (plp->pcp->pl_stealth/100.0); - } - for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw){ - plp = (struct plist *) qp; - if (evade > plp->pcp->pl_stealth/100.0) - evade = (plp->pcp->pl_stealth/100.0); - } - - if (chance(evade)) - return 1; - - return 0; + struct emp_qelem *qp; + double evade; + struct plist *plp; + + evade = 100.0; + for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if (evade > ((float)plp->pcp->pl_stealth / 100.0)) + evade = (plp->pcp->pl_stealth / 100.0); + } + for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) { + plp = (struct plist *)qp; + if (evade > plp->pcp->pl_stealth / 100.0) + evade = (plp->pcp->pl_stealth / 100.0); + } + + if (chance(evade)) + return 1; + + return 0; } diff --git a/src/lib/subs/askyn.c b/src/lib/subs/askyn.c index f4ed15cbf..d152d0a01 100644 --- a/src/lib/subs/askyn.c +++ b/src/lib/subs/askyn.c @@ -49,15 +49,15 @@ int confirm(s_char *promptstring) { - s_char y_or_n[1024]; - char c; + s_char y_or_n[1024]; + char c; - if (getstring(promptstring, y_or_n) == 0) - return 0; - c = *y_or_n; - if (c == 'y' || c == 'Y') - return 1; + if (getstring(promptstring, y_or_n) == 0) return 0; + c = *y_or_n; + if (c == 'y' || c == 'Y') + return 1; + return 0; } /* @@ -67,17 +67,17 @@ confirm(s_char *promptstring) int askyn(s_char *promptstring) { - s_char y_or_n[1024]; - char c; + s_char y_or_n[1024]; + char c; - while (getstring(promptstring, y_or_n)) { - c = *y_or_n; - if (c == 'y' || c == 'Y') - return 1; - if (c == 'n' || c == 'N') - return 0; - pr("You must answer either yes or no!\n"); - } - /* assume no if aborted */ - return 0; + while (getstring(promptstring, y_or_n)) { + c = *y_or_n; + if (c == 'y' || c == 'Y') + return 1; + if (c == 'n' || c == 'N') + return 0; + pr("You must answer either yes or no!\n"); + } + /* assume no if aborted */ + return 0; } diff --git a/src/lib/subs/aswplnsubs.c b/src/lib/subs/aswplnsubs.c index 1b6d9d9fb..797f0eb26 100644 --- a/src/lib/subs/aswplnsubs.c +++ b/src/lib/subs/aswplnsubs.c @@ -50,127 +50,125 @@ int have_looked(u_char uid, struct shiplook *head) { - struct shiplook *s; + struct shiplook *s; - s=head; - if (s->uid == -1) - return 0; + s = head; + if (s->uid == -1) + return 0; - while (s != ((struct shiplook *)0)){ - if (s->uid == uid) - return s->looked; - s=s->next; - } + while (s != ((struct shiplook *)0)) { + if (s->uid == uid) + return s->looked; + s = s->next; + } - return 0; + return 0; } int have_found(u_char uid, struct shiplook *head) { - struct shiplook *s; + struct shiplook *s; - s=head; - if (s->uid == -1) - return 0; + s = head; + if (s->uid == -1) + return 0; - while (s != ((struct shiplook *)0)){ - if (s->uid == uid) - return s->found; - s=s->next; - } + while (s != ((struct shiplook *)0)) { + if (s->uid == uid) + return s->found; + s = s->next; + } - return 0; + return 0; } void set_have_looked(u_char uid, struct shiplook *head) { - struct shiplook *s,*s2; - - s=head; - if (s->uid == -1){ - s->uid=uid; - s->looked=1; - s->found=0; - s->next=(struct shiplook *)0; - } + struct shiplook *s, *s2; - while (s != ((struct shiplook *)0)){ - if (s->uid == uid){ - s->looked=1; - return; - } - s2=s; - s=s->next; - } - - s=(struct shiplook *)malloc(sizeof(struct shiplook)); - bzero((s_char *)s,sizeof(struct shiplook)); - s2->next = s; + s = head; + if (s->uid == -1) { s->uid = uid; s->looked = 1; + s->found = 0; s->next = (struct shiplook *)0; + } + + while (s != ((struct shiplook *)0)) { + if (s->uid == uid) { + s->looked = 1; + return; + } + s2 = s; + s = s->next; + } + + s = (struct shiplook *)malloc(sizeof(struct shiplook)); + bzero((s_char *)s, sizeof(struct shiplook)); + s2->next = s; + s->uid = uid; + s->looked = 1; + s->next = (struct shiplook *)0; } void set_have_found(u_char uid, struct shiplook *head) { - struct shiplook *s,*s2; - - s=head; - if (s->uid == -1){ - s->uid=uid; - s->looked=0; - s->found=1; - s->next=(struct shiplook *)0; - } - - - while (s != ((struct shiplook *)0)){ - if (s->uid == uid){ - s->found=1; - return; - } - s2=s; - s=s->next; - } + struct shiplook *s, *s2; - s=(struct shiplook *)malloc(sizeof(struct shiplook)); - bzero((s_char *)s,sizeof(struct shiplook)); - s2->next = s; + s = head; + if (s->uid == -1) { s->uid = uid; + s->looked = 0; s->found = 1; s->next = (struct shiplook *)0; + } + + + while (s != ((struct shiplook *)0)) { + if (s->uid == uid) { + s->found = 1; + return; + } + s2 = s; + s = s->next; + } + + s = (struct shiplook *)malloc(sizeof(struct shiplook)); + bzero((s_char *)s, sizeof(struct shiplook)); + s2->next = s; + s->uid = uid; + s->found = 1; + s->next = (struct shiplook *)0; } int print_found(struct shiplook *head) { - struct shiplook *s; - extern s_char *effadv(int); - int first; - struct mchrstr *mp; - struct shpstr ship; - - s=head; - first = 1; - if (s->uid == -1) - return 0; - - while (s != ((struct shiplook *)0)){ - getship(s->uid,&ship); - mp = &mchr[(int)ship.shp_type]; - if (first) { - pr(" # player->owner eff type\n"); - first = 0; - } - pr("(#%3d) %10.10s %12.12s %s\n", ship.shp_uid, - cname(ship.shp_own), - effadv(ship.shp_effic), - prship(&ship)); - s=s->next; + struct shiplook *s; + extern s_char *effadv(int); + int first; + struct mchrstr *mp; + struct shpstr ship; + + s = head; + first = 1; + if (s->uid == -1) + return 0; + + while (s != ((struct shiplook *)0)) { + getship(s->uid, &ship); + mp = &mchr[(int)ship.shp_type]; + if (first) { + pr(" # player->owner eff type\n"); + first = 0; } + pr("(#%3d) %10.10s %12.12s %s\n", ship.shp_uid, + cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship)); + s = s->next; + } - return 1; + return 1; } diff --git a/src/lib/subs/attsub.c b/src/lib/subs/attsub.c index 39bef2c34..041b72ea0 100644 --- a/src/lib/subs/attsub.c +++ b/src/lib/subs/attsub.c @@ -54,25 +54,39 @@ #define CASUALTY_LUMP 1 /* How big casualty chunks should be */ -static void ask_olist(int combat_mode, struct combat *off, struct combat *def, struct emp_qelem *olist, s_char *land_answer, int *a_spyp, int *a_engineerp); -static void take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off, struct combat *def); -static void move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist, struct combat *def); -static void ask_move_in(struct combat *off, struct emp_qelem *olist, struct combat *def); +static void ask_olist(int combat_mode, struct combat *off, + struct combat *def, struct emp_qelem *olist, + s_char *land_answer, int *a_spyp, int *a_engineerp); +static void take_move_in_mob(int combat_mode, struct llist *llp, + struct combat *off, struct combat *def); +static void move_in_land(int combat_mode, struct combat *off, + struct emp_qelem *olist, struct combat *def); +static void ask_move_in(struct combat *off, struct emp_qelem *olist, + struct combat *def); static void ask_move_in_off(struct combat *off, struct combat *def); static int board_abort(struct combat *off, struct combat *def); static int land_board_abort(struct combat *off, struct combat *def); -static int ask_off(int combat_mode, struct combat *off, struct combat *def); -static int get_dlist(struct combat *def, struct emp_qelem *list, int a_spy, int *d_spyp); -static int get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist, double osupport, int check); -static int get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport, int check); -static int take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist); - -static void send_reacting_units_home(struct combat *def, struct emp_qelem *list); -static int take_def(int combat_mode, struct emp_qelem *list, struct combat *off, struct combat *def); - -void att_move_in_off(int combat_mode, struct combat *off, struct emp_qelem *olist, struct combat *def); -static int get_land(int combat_mode, struct combat *def, int uid, struct llist *llp, int victim_land); +static int ask_off(int combat_mode, struct combat *off, + struct combat *def); +static int get_dlist(struct combat *def, struct emp_qelem *list, int a_spy, + int *d_spyp); +static int get_ototal(int combat_mode, struct combat *off, + struct emp_qelem *olist, double osupport, int check); +static int get_dtotal(struct combat *def, struct emp_qelem *list, + double dsupport, int check); +static int take_casualty(int combat_mode, struct combat *off, + struct emp_qelem *olist); + +static void send_reacting_units_home(struct combat *def, + struct emp_qelem *list); +static int take_def(int combat_mode, struct emp_qelem *list, + struct combat *off, struct combat *def); + +void att_move_in_off(int combat_mode, struct combat *off, + struct emp_qelem *olist, struct combat *def); +static int get_land(int combat_mode, struct combat *def, int uid, + struct llist *llp, int victim_land); /* * The principal object in this code is the "combat" object. A combat object @@ -101,9 +115,9 @@ static int get_land(int combat_mode, struct combat *def, int uid, struct lli int att_combat_init(struct combat *com, int type) { - bzero((s_char *)com, sizeof(*com)); - com->type = type; - return type; + bzero((s_char *)com, sizeof(*com)); + com->type = type; + return type; } /* print a combat object with optional preposition */ @@ -111,70 +125,69 @@ att_combat_init(struct combat *com, int type) static s_char * pr_com(int inon, struct combat *com, natid who) { - if (com->type == EF_SECTOR) { - return prbuf("%s%s", - inon?inon==1?"in ":"into ":"", - xyas(com->x, com->y, who)); - } else if (com->type == EF_SHIP) { - if (opt_SHIPNAMES) { - return prbuf("%s%s %s(#%d)", - inon?inon==1?"on ":"onto ":"", - com->shp_mcp->m_name, com->shp_name, com->shp_uid); - } else { - return prbuf("%s%s #%d", - inon?inon==1?"on ":"onto ":"", - com->shp_mcp->m_name, com->shp_uid); - } - } else if (com->type == EF_LAND) { - return prbuf("%s%s #%d", - inon?inon==1?"on ":"onto ":"", - com->lnd_lcp->l_name, com->lnd_uid); + if (com->type == EF_SECTOR) { + return prbuf("%s%s", + inon ? inon == 1 ? "in " : "into " : "", + xyas(com->x, com->y, who)); + } else if (com->type == EF_SHIP) { + if (opt_SHIPNAMES) { + return prbuf("%s%s %s(#%d)", + inon ? inon == 1 ? "on " : "onto " : "", + com->shp_mcp->m_name, com->shp_name, + com->shp_uid); } else { - return "your forces"; - } -} + return prbuf("%s%s #%d", + inon ? inon == 1 ? "on " : "onto " : "", + com->shp_mcp->m_name, com->shp_uid); + } + } else if (com->type == EF_LAND) { + return prbuf("%s%s #%d", + inon ? inon == 1 ? "on " : "onto " : "", + com->lnd_lcp->l_name, com->lnd_uid); + } else { + return "your forces"; + } +} static s_char * prcom(int inon, struct combat *com) { - return pr_com(inon, com, player->cnum); + return pr_com(inon, com, player->cnum); } /* Doing a sneak attack */ static void do_sneak(def, success) - struct combat *def; - int success; +struct combat *def; +int success; { - struct sctstr sect; - struct natstr *natp = getnatp(player->cnum); - int issneak = getrel(natp, def->own); + struct sctstr sect; + struct natstr *natp = getnatp(player->cnum); + int issneak = getrel(natp, def->own); - if (def->type != EF_SECTOR) - return; + if (def->type != EF_SECTOR) + return; - getsect(def->x, def->y, §); + getsect(def->x, def->y, §); - if (issneak == AT_WAR || - !def->own || - sect.sct_oldown == player->cnum) - return; + if (issneak == AT_WAR || !def->own || sect.sct_oldown == player->cnum) + return; - if (success) - pr("Your sneak attack was successful\nBut "); - else - pr("Your sneak attack was unsuccessful\nAnd "); - - pr("it will cost you $5000\n"); - pr("War has been declared!!!!\n"); - wu(0,def->own, "Country %s (#%d) has Sneak Attacked!!\n", - cname(player->cnum), player->cnum); - wu(0,def->own,"Country %s (#%d) has Declared WAR on you!!\n", - cname(player->cnum), player->cnum); - player->dolcost += 5000; - issneak = min(issneak, MOBILIZATION); - nreport(player->cnum, N_DECL_WAR, def->own, 1); - setrel(player->cnum,def->own,issneak); + if (success) + pr("Your sneak attack was successful\nBut "); + else + pr("Your sneak attack was unsuccessful\nAnd "); + + pr("it will cost you $5000\n"); + pr("War has been declared!!!!\n"); + wu(0, def->own, "Country %s (#%d) has Sneak Attacked!!\n", + cname(player->cnum), player->cnum); + wu(0, def->own, "Country %s (#%d) has Declared WAR on you!!\n", + cname(player->cnum), player->cnum); + player->dolcost += 5000; + issneak = min(issneak, MOBILIZATION); + nreport(player->cnum, N_DECL_WAR, def->own, 1); + setrel(player->cnum, def->own, issneak); } /* @@ -186,152 +199,152 @@ do_sneak(def, success) int att_get_combat(struct combat *com, int isdef) { - struct sctstr sect; - struct shpstr ship; - struct lndstr land; - s_char *thing; - natid owner; - int mil; - int eff; - int mob; - coord x, y; - - switch (com->type) { - case EF_SECTOR: - if (!getsect(com->x, com->y, §)) { - pr("Bad sector: %s\n", - xyas(com->x, com->y, player->cnum)); - return att_combat_init(com, EF_BAD); - } - com->sct_type = sect.sct_type; - com->sct_dcp = &dchr[sect.sct_type]; - thing = (s_char *)§ - owner = sect.sct_own; - eff = sect.sct_effic; - mob = sect.sct_mobil; - x = com->x; - y = com->y; - break; - case EF_LAND: - if (!getland(com->lnd_uid, &land)) { - if (isdef) - pr("Land unit #%d is not in the same sector!\n", com->lnd_uid); - return att_combat_init(com, EF_BAD); - } - if (isdef && player->owner) { - pr("Boarding yourself? Try using the 'load' command.\n"); - return att_combat_init(com, EF_BAD); - } - com->lnd_lcp = &lchr[(int)land.lnd_type]; - thing = (s_char *)&land; - owner = land.lnd_own; - eff = land.lnd_effic; - mob = land.lnd_mobil; - x = land.lnd_x; - y = land.lnd_y; - break; - case EF_SHIP: - if (!getship(com->shp_uid, &ship) || !ship.shp_own) { - if (isdef) - pr("Ship #%d is not in the same sector!\n", com->shp_uid); - else - pr("Ship #%d is not your ship!\n", com->shp_uid); - return att_combat_init(com, EF_BAD); - } - if (opt_MARKET) { - if (isdef && player->owner && - ontradingblock(EF_SHIP, (int *)&ship)) { - pr("%s is on the trading block.\n", prcom(0, com)); - return att_combat_init(com, EF_BAD); - } - } - if (isdef && player->owner) { - pr("Boarding yourself? Try using the 'tend' command.\n"); - return att_combat_init(com, EF_BAD); - } - com->shp_mcp = &mchr[(int)ship.shp_type]; - if (opt_SHIPNAMES) - strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN); - if (!isdef && !player->owner) { - if (com->set) - pr("%s was just sunk!\n", prcom(0, com)); - else - pr("Ship #%d is not your ship!\n", com->shp_uid); - return att_combat_init(com, EF_BAD); - } - thing = (s_char *)&ship; - owner = ship.shp_own; - eff = ship.shp_effic; - mob = ship.shp_mobil; - x = ship.shp_x; - y = ship.shp_y; - break; - case EF_PLANE: - return com->mil; - case EF_BAD: - return EF_BAD; - default: + struct sctstr sect; + struct shpstr ship; + struct lndstr land; + s_char *thing; + natid owner; + int mil; + int eff; + int mob; + coord x, y; + + switch (com->type) { + case EF_SECTOR: + if (!getsect(com->x, com->y, §)) { + pr("Bad sector: %s\n", xyas(com->x, com->y, player->cnum)); + return att_combat_init(com, EF_BAD); + } + com->sct_type = sect.sct_type; + com->sct_dcp = &dchr[sect.sct_type]; + thing = (s_char *)§ + owner = sect.sct_own; + eff = sect.sct_effic; + mob = sect.sct_mobil; + x = com->x; + y = com->y; + break; + case EF_LAND: + if (!getland(com->lnd_uid, &land)) { + if (isdef) + pr("Land unit #%d is not in the same sector!\n", + com->lnd_uid); + return att_combat_init(com, EF_BAD); + } + if (isdef && player->owner) { + pr("Boarding yourself? Try using the 'load' command.\n"); + return att_combat_init(com, EF_BAD); + } + com->lnd_lcp = &lchr[(int)land.lnd_type]; + thing = (s_char *)&land; + owner = land.lnd_own; + eff = land.lnd_effic; + mob = land.lnd_mobil; + x = land.lnd_x; + y = land.lnd_y; + break; + case EF_SHIP: + if (!getship(com->shp_uid, &ship) || !ship.shp_own) { + if (isdef) + pr("Ship #%d is not in the same sector!\n", com->shp_uid); + else + pr("Ship #%d is not your ship!\n", com->shp_uid); + return att_combat_init(com, EF_BAD); + } + if (opt_MARKET) { + if (isdef && player->owner && + ontradingblock(EF_SHIP, (int *)&ship)) { + pr("%s is on the trading block.\n", prcom(0, com)); return att_combat_init(com, EF_BAD); + } } + if (isdef && player->owner) { + pr("Boarding yourself? Try using the 'tend' command.\n"); + return att_combat_init(com, EF_BAD); + } + com->shp_mcp = &mchr[(int)ship.shp_type]; + if (opt_SHIPNAMES) + strncpy(com->shp_name, ship.shp_name, MAXSHPNAMLEN); + if (!isdef && !player->owner) { + if (com->set) + pr("%s was just sunk!\n", prcom(0, com)); + else + pr("Ship #%d is not your ship!\n", com->shp_uid); + return att_combat_init(com, EF_BAD); + } + thing = (s_char *)&ship; + owner = ship.shp_own; + eff = ship.shp_effic; + mob = ship.shp_mobil; + x = ship.shp_x; + y = ship.shp_y; + break; + case EF_PLANE: + return com->mil; + case EF_BAD: + return EF_BAD; + default: + return att_combat_init(com, EF_BAD); + } - mil = getvar(V_MILIT, thing, com->type); - if (!com->set) { /* first time */ - if (isdef) { /* defender */ - com->troops = mil; - } else { /* attacker */ - if (!mil) - pr("No mil %s\n", prcom(1, com)); - else if (mil == 1) - pr("Only 1 mil %s\n", prcom(1, com)); - /* don't abandon attacking sectors or ships */ - com->troops = max(0, mil-1); - } - com->plague = (getvar(V_PSTAGE, thing, com->type)) == - PLG_INFECT; - } else { /* not first time */ - if (isdef) { /* defender */ - if (com->x != x || com->y != y) { - pr("%s has moved!\n", prcom(0, com)); - return att_combat_init(com, EF_BAD); - } - if (owner != com->own) { - if (owner) { - pr("WARNING: The ownership of %s just changed from %s to %s!\n", prcom(0, com), cname(com->own), cname(owner)); - } else if (com->type == EF_SECTOR) { - pr("WARNING: %s just abandoned sector %s!\n", cname(com->own), xyas(com->x,com->y,player->cnum)); - } - } - if (com->mil != mil) - pr("WARNING: The enemy mil %s just %s from %d to %d!\n", prcom(1, com), - com->mil < mil?"increased":"decreased", - com->mil, mil); - com->troops = mil; - } else { /* attacker */ - if (owner != player->cnum && - getrel(getnatp(owner), player->cnum) != ALLIED) { /* must be EF_SECTOR */ - if (com->mil) - pr("WARNING: Your %d mil in %s were destroyed because %s just took the sector!\n", com->mil, xyas(com->x,com->y,player->cnum), cname(owner)); - else - pr("You no longer own %s\n", - xyas(com->x,com->y,player->cnum)); - return att_combat_init(com, EF_BAD); - } - if (com->troops && com->troops + 1 > mil) { - if (com->own == owner && - player->cnum == owner) /* not a takeover */ - pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, max(0,mil-1)); - com->troops = max(0,mil-1); - } + mil = getvar(V_MILIT, thing, com->type); + if (!com->set) { /* first time */ + if (isdef) { /* defender */ + com->troops = mil; + } else { /* attacker */ + if (!mil) + pr("No mil %s\n", prcom(1, com)); + else if (mil == 1) + pr("Only 1 mil %s\n", prcom(1, com)); + /* don't abandon attacking sectors or ships */ + com->troops = max(0, mil - 1); + } + com->plague = (getvar(V_PSTAGE, thing, com->type)) == PLG_INFECT; + } else { /* not first time */ + if (isdef) { /* defender */ + if (com->x != x || com->y != y) { + pr("%s has moved!\n", prcom(0, com)); + return att_combat_init(com, EF_BAD); + } + if (owner != com->own) { + if (owner) { + pr("WARNING: The ownership of %s just changed from %s to %s!\n", prcom(0, com), cname(com->own), cname(owner)); + } else if (com->type == EF_SECTOR) { + pr("WARNING: %s just abandoned sector %s!\n", + cname(com->own), xyas(com->x, com->y, + player->cnum)); } + } + if (com->mil != mil) + pr("WARNING: The enemy mil %s just %s from %d to %d!\n", + prcom(1, com), + com->mil < mil ? "increased" : "decreased", com->mil, + mil); + com->troops = mil; + } else { /* attacker */ + if (owner != player->cnum && getrel(getnatp(owner), player->cnum) != ALLIED) { /* must be EF_SECTOR */ + if (com->mil) + pr("WARNING: Your %d mil in %s were destroyed because %s just took the sector!\n", com->mil, xyas(com->x, com->y, player->cnum), cname(owner)); + else + pr("You no longer own %s\n", + xyas(com->x, com->y, player->cnum)); + return att_combat_init(com, EF_BAD); + } + if (com->troops && com->troops + 1 > mil) { + if (com->own == owner && player->cnum == owner) /* not a takeover */ + pr("WARNING: Your mil %s has been reduced from %d to %d!\n", prcom(1, com), com->troops, max(0, mil - 1)); + com->troops = max(0, mil - 1); + } } - com->set = 1; - com->mil = mil; - com->own = owner; - com->x = x; - com->y = y; - com->eff = eff; - com->mob = mob; - return com->troops; + } + com->set = 1; + com->mil = mil; + com->own = owner; + com->x = x; + com->y = y; + com->eff = eff; + com->mob = mob; + return com->troops; } /* @@ -343,108 +356,112 @@ att_get_combat(struct combat *com, int isdef) static void put_combat(struct combat *com) { - struct sctstr sect; - struct shpstr ship; - struct lndstr land; - int deff; - - switch (com->type) { - case EF_SECTOR: - getsect(com->x, com->y, §); - sect.sct_type = com->sct_type; - deff = sect.sct_effic - com->eff; - if (deff > 0) { - sect.sct_road -= (sect.sct_road * deff / 100.0); - sect.sct_rail -= (sect.sct_rail * deff / 100.0); - sect.sct_defense -= (sect.sct_defense * deff / 100.0); - if (sect.sct_road <= 0) - sect.sct_road = 0; - if (sect.sct_rail <= 0) - sect.sct_rail = 0; - if (sect.sct_defense <= 0) - sect.sct_defense = 0; - } - sect.sct_effic = com->eff; - if (!opt_DEFENSE_INFRA) - sect.sct_defense = sect.sct_effic; - if (com->mobcost) { - if (opt_MOB_ACCESS) { - if ((com->mob - com->mobcost) < -127) - sect.sct_mobil = -127; - else - sect.sct_mobil = (short)(com->mob - com->mobcost); - } else { - if ((com->mob - com->mobcost) < 0) - sect.sct_mobil = 0; - else - sect.sct_mobil = (short)(com->mob - com->mobcost); - } - } - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - makenotlost(EF_SECTOR, com->own, 0, sect.sct_x, sect.sct_y); - sect.sct_own = com->own; - if (com->plague) { - if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); - } - putvar(V_MILIT, com->mil, (s_char *)§, EF_SECTOR); - putsect(§); - com->own = sect.sct_own; /* avoid WARNING if sector reverts */ - break; - case EF_LAND: - getland(com->lnd_uid, &land); - land.lnd_effic = com->eff; - if (com->mobcost) { - if (com->mob - com->mobcost < -127) - land.lnd_mobil = -127; - else - land.lnd_mobil = (s_char)(com->mob - com->mobcost); - } - makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - land.lnd_own = com->own; - makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y); - if (com->plague) { - if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND); - } - if (!(com->lnd_lcp->l_flags & L_SPY)) - putvar(V_MILIT, com->mil, (s_char *)&land, EF_LAND); - lnd_count_units(&land); - if (com->own == player->cnum) { - land.lnd_mission = 0; - land.lnd_rflags = 0; - bzero(land.lnd_rpath, RET_LEN); - } - putland(com->lnd_uid, &land); - break; - case EF_SHIP: - getship(com->shp_uid, &ship); - ship.shp_effic = com->eff; - if (com->mobcost) { - if (com->mob - com->mobcost < -127) - ship.shp_mobil = -127; - else - ship.shp_mobil = - (s_char)(com->mob - com->mobcost); - } - makelost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x, ship.shp_y); - ship.shp_own = com->own; - makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x, ship.shp_y); - if (com->plague) { - if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP); - } - putvar(V_MILIT, com->mil, (s_char *)&ship, EF_SHIP); - count_units(&ship); - if (com->own == player->cnum) { - ship.shp_mission = 0; - ship.shp_rflags = 0; - bzero(ship.shp_rpath,RET_LEN); - } - putship(com->shp_uid, &ship); + struct sctstr sect; + struct shpstr ship; + struct lndstr land; + int deff; + + switch (com->type) { + case EF_SECTOR: + getsect(com->x, com->y, §); + sect.sct_type = com->sct_type; + deff = sect.sct_effic - com->eff; + if (deff > 0) { + sect.sct_road -= (sect.sct_road * deff / 100.0); + sect.sct_rail -= (sect.sct_rail * deff / 100.0); + sect.sct_defense -= (sect.sct_defense * deff / 100.0); + if (sect.sct_road <= 0) + sect.sct_road = 0; + if (sect.sct_rail <= 0) + sect.sct_rail = 0; + if (sect.sct_defense <= 0) + sect.sct_defense = 0; + } + sect.sct_effic = com->eff; + if (!opt_DEFENSE_INFRA) + sect.sct_defense = sect.sct_effic; + if (com->mobcost) { + if (opt_MOB_ACCESS) { + if ((com->mob - com->mobcost) < -127) + sect.sct_mobil = -127; + else + sect.sct_mobil = (short)(com->mob - com->mobcost); + } else { + if ((com->mob - com->mobcost) < 0) + sect.sct_mobil = 0; + else + sect.sct_mobil = (short)(com->mob - com->mobcost); + } } - com->mobcost = 0; - att_get_combat(com, com->own != player->cnum); + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); + makenotlost(EF_SECTOR, com->own, 0, sect.sct_x, sect.sct_y); + sect.sct_own = com->own; + if (com->plague) { + if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == + PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR); + } + putvar(V_MILIT, com->mil, (s_char *)§, EF_SECTOR); + putsect(§); + com->own = sect.sct_own; /* avoid WARNING if sector reverts */ + break; + case EF_LAND: + getland(com->lnd_uid, &land); + land.lnd_effic = com->eff; + if (com->mobcost) { + if (com->mob - com->mobcost < -127) + land.lnd_mobil = -127; + else + land.lnd_mobil = (s_char)(com->mob - com->mobcost); + } + makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + land.lnd_own = com->own; + makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, + land.lnd_y); + if (com->plague) { + if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND); + } + if (!(com->lnd_lcp->l_flags & L_SPY)) + putvar(V_MILIT, com->mil, (s_char *)&land, EF_LAND); + lnd_count_units(&land); + if (com->own == player->cnum) { + land.lnd_mission = 0; + land.lnd_rflags = 0; + bzero(land.lnd_rpath, RET_LEN); + } + putland(com->lnd_uid, &land); + break; + case EF_SHIP: + getship(com->shp_uid, &ship); + ship.shp_effic = com->eff; + if (com->mobcost) { + if (com->mob - com->mobcost < -127) + ship.shp_mobil = -127; + else + ship.shp_mobil = (s_char)(com->mob - com->mobcost); + } + makelost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x, + ship.shp_y); + ship.shp_own = com->own; + makenotlost(EF_SHIP, ship.shp_own, ship.shp_uid, ship.shp_x, + ship.shp_y); + if (com->plague) { + if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP); + } + putvar(V_MILIT, com->mil, (s_char *)&ship, EF_SHIP); + count_units(&ship); + if (com->own == player->cnum) { + ship.shp_mission = 0; + ship.shp_rflags = 0; + bzero(ship.shp_rpath, RET_LEN); + } + putship(com->shp_uid, &ship); + } + com->mobcost = 0; + att_get_combat(com, com->own != player->cnum); } /* If pre-attack, abort fight. If post-attack, don't move anything in */ @@ -452,7 +469,7 @@ put_combat(struct combat *com) static int abort_attack(void) { - return player->aborted = 1; + return player->aborted = 1; } /* @@ -463,120 +480,125 @@ abort_attack(void) int att_abort(int combat_mode, struct combat *off, struct combat *def) { - struct sctstr sect; - int issneak; - s_char y_or_n[512]; - struct natstr *natp; - - if (player->aborted) - return 1; - if (att_get_combat(def, 1) < 0) - return abort_attack(); - - if (off && combat_mode != A_ATTACK) { - if (att_get_combat(off, 0) < 0) - return abort_attack(); - if (off->type == EF_SHIP && - (!getsect(off->x, off->y, §) || - sect.sct_type != SCT_WATER)) { - pr("%s can not %s from that far inland!\n", - prcom(0, off), - att_mode[combat_mode]); - return abort_attack(); - } + struct sctstr sect; + int issneak; + s_char y_or_n[512]; + struct natstr *natp; + + if (player->aborted) + return 1; + if (att_get_combat(def, 1) < 0) + return abort_attack(); + + if (off && combat_mode != A_ATTACK) { + if (att_get_combat(off, 0) < 0) + return abort_attack(); + if (off->type == EF_SHIP && + (!getsect(off->x, off->y, §) || + sect.sct_type != SCT_WATER)) { + pr("%s can not %s from that far inland!\n", + prcom(0, off), att_mode[combat_mode]); + return abort_attack(); } - switch (combat_mode) { - case A_ATTACK: - if (!neigh(def->x, def->y, player->cnum) && - !adj_units(def->x, def->y, player->cnum)) { - pr("You are not adjacent to %s\n", xyas(def->x, def->y, player->cnum)); - return abort_attack(); - } - if (def->own == player->cnum) { - pr("You can't attack your own sector.\n"); - return abort_attack(); - } - break; - case A_ASSAULT: - if (off && mapdist(off->x, off->y, def->x, def->y) > 1) { - pr("You'll have to get there first...\n"); - return abort_attack(); - } - if (off && def->sct_type == SCT_MOUNT) { - pr("You can't assault a %s sector!\n", def->sct_dcp->d_name); - return abort_attack(); - } - break; - case A_PARA: - if (def->own == player->cnum) { - pr("You can't air-assault your own sector.\n"); - return abort_attack(); - } - if (off && (def->sct_type == SCT_MOUNT || + } + switch (combat_mode) { + case A_ATTACK: + if (!neigh(def->x, def->y, player->cnum) && + !adj_units(def->x, def->y, player->cnum)) { + pr("You are not adjacent to %s\n", + xyas(def->x, def->y, player->cnum)); + return abort_attack(); + } + if (def->own == player->cnum) { + pr("You can't attack your own sector.\n"); + return abort_attack(); + } + break; + case A_ASSAULT: + if (off && mapdist(off->x, off->y, def->x, def->y) > 1) { + pr("You'll have to get there first...\n"); + return abort_attack(); + } + if (off && def->sct_type == SCT_MOUNT) { + pr("You can't assault a %s sector!\n", def->sct_dcp->d_name); + return abort_attack(); + } + break; + case A_PARA: + if (def->own == player->cnum) { + pr("You can't air-assault your own sector.\n"); + return abort_attack(); + } + if (off && (def->sct_type == SCT_MOUNT || def->sct_type == SCT_WATER || def->sct_type == SCT_CAPIT || def->sct_type == SCT_FORTR || def->sct_type == SCT_WASTE)) { - pr("You can't air-assault a %s sector!\n", - def->sct_dcp->d_name); - return abort_attack(); - } - break; - case A_BOARD: - return board_abort(off, def); - case A_LBOARD: - return land_board_abort(off, def); + pr("You can't air-assault a %s sector!\n", + def->sct_dcp->d_name); + return abort_attack(); } - - if (off && def->sct_dcp->d_mcst <= 0) { - pr("You can't %s a %s sector!\n", att_mode[combat_mode], - def->sct_dcp->d_name); + break; + case A_BOARD: + return board_abort(off, def); + case A_LBOARD: + return land_board_abort(off, def); + } + + if (off && def->sct_dcp->d_mcst <= 0) { + pr("You can't %s a %s sector!\n", att_mode[combat_mode], + def->sct_dcp->d_name); + return abort_attack(); + } + if (!off || off->relations_checked) + return 0; + off->relations_checked = 1; + + if (opt_HIDDEN) { + setcont(player->cnum, def->own, FOUND_SPY); + setcont(def->own, player->cnum, FOUND_SPY); + } + if (opt_SLOW_WAR && def->own != player->cnum) { + natp = getnatp(player->cnum); + issneak = getrel(natp, def->own); + + if (issneak == ALLIED) { + sprintf(y_or_n, "Sector is owned by %s, your ally, %s [yn]? ", + cname(def->own), att_mode[combat_mode]); + if (!confirm(y_or_n)) return abort_attack(); + } - if (!off || off->relations_checked) - return 0; - off->relations_checked = 1; - - if (opt_HIDDEN) { - setcont(player->cnum, def->own, FOUND_SPY); - setcont(def->own, player->cnum, FOUND_SPY); - } - if (opt_SLOW_WAR && def->own != player->cnum) { - natp = getnatp(player->cnum); - issneak = getrel(natp, def->own); - - if (issneak == ALLIED){ - sprintf(y_or_n,"Sector is owned by %s, your ally, %s [yn]? ",cname(def->own), att_mode[combat_mode]); - if (!confirm(y_or_n)) - return abort_attack(); - - } - if (opt_SNEAK_ATTACK) { + if (opt_SNEAK_ATTACK) { getsect(def->x, def->y, §); - if ((issneak != AT_WAR) && (def->own) && (def->own != player->cnum) && - (sect.sct_oldown != player->cnum) && (issneak != SITZKRIEG) && - (issneak != MOBILIZATION)) { - pr("You're not at war with them!\n"); - if (!confirm("Do you really want to sneak attack (it will cost you $5000) [yn]? ")){ - pr("Sneak attack cancelled!\n"); + if ((issneak != AT_WAR) && (def->own) + && (def->own != player->cnum) + && (sect.sct_oldown != player->cnum) + && (issneak != SITZKRIEG) && (issneak != MOBILIZATION)) { + pr("You're not at war with them!\n"); + if (!confirm + ("Do you really want to sneak attack (it will cost you $5000) [yn]? ")) + { + pr("Sneak attack cancelled!\n"); + return abort_attack(); + } + } + if ((issneak != AT_WAR) && (def->own) + && (def->own != player->cnum) + && (sect.sct_oldown != player->cnum) + && ((issneak == MOBILIZATION) || (issneak == SITZKRIEG))) { + pr("You're not at war with them!\n"); return abort_attack(); - } } - if ((issneak != AT_WAR) && (def->own) && (def->own != player->cnum) && - (sect.sct_oldown != player->cnum) && ((issneak == MOBILIZATION) || - (issneak == SITZKRIEG))) { - pr("You're not at war with them!\n"); - return abort_attack(); - } - } else { + } else { if ((issneak != AT_WAR) && (def->own) && (sect.sct_oldown != player->cnum)) { - pr("You're not at war with them!\n"); - return abort_attack(); - } - } + pr("You're not at war with them!\n"); + return abort_attack(); + } } - return 0; + } + return 0; } /* @@ -587,54 +609,52 @@ att_abort(int combat_mode, struct combat *off, struct combat *def) static int board_abort(struct combat *off, struct combat *def) { - struct shpstr aship, dship; /* for tech levels */ - struct sctstr sect; - - if (att_get_combat(def, 1) < 0) - return abort_attack(); + struct shpstr aship, dship; /* for tech levels */ + struct sctstr sect; - if (!off) - return 0; + if (att_get_combat(def, 1) < 0) + return abort_attack(); - if (att_get_combat(off, 0) < 0) - return abort_attack(); + if (!off) + return 0; - if (off->x != def->x || off->y != def->y) { - pr("Ship #%d is not in the same sector!\n", def->shp_uid); + if (att_get_combat(off, 0) < 0) + return abort_attack(); + + if (off->x != def->x || off->y != def->y) { + pr("Ship #%d is not in the same sector!\n", def->shp_uid); + return abort_attack(); + } + if (off->type == EF_SHIP) { + if (off->mob <= 0) { + pr("%s has no mobility!\n", prcom(0, off)); return abort_attack(); } - if (off->type == EF_SHIP) { - if (off->mob <= 0) { - pr("%s has no mobility!\n", prcom(0, off)); - return abort_attack(); - } - getship(off->shp_uid, &aship); - getship(def->shp_uid, &dship); - if (techfact(aship.shp_tech, 1.0) * - aship.shp_speed * off->eff <= - techfact(dship.shp_tech, 1.0) * - dship.shp_speed * def->eff) { - pr("Victim ship moves faster than you do!\n"); - if (def->own) - wu(0, def->own, - "%s (#%d) %s failed to catch %s\n", - cname(aship.shp_own), aship.shp_own, - pr_com(0, off, def->own), - pr_com(0, def, def->own)); - return abort_attack(); - } - } else if (off->type != EF_SECTOR) { - pr("Please tell the deity that you got the 'banana boat' error\n"); - return abort_attack(); + getship(off->shp_uid, &aship); + getship(def->shp_uid, &dship); + if (techfact(aship.shp_tech, 1.0) * + aship.shp_speed * off->eff <= + techfact(dship.shp_tech, 1.0) * dship.shp_speed * def->eff) { + pr("Victim ship moves faster than you do!\n"); + if (def->own) + wu(0, def->own, + "%s (#%d) %s failed to catch %s\n", + cname(aship.shp_own), aship.shp_own, + pr_com(0, off, def->own), pr_com(0, def, def->own)); + return abort_attack(); } - if (def->shp_mcp->m_flags & M_SUB) { - getsect(def->x, def->y, §); - if (sect.sct_type == SCT_WATER) { - pr("You can't board a submarine!\n"); - return abort_attack(); - } + } else if (off->type != EF_SECTOR) { + pr("Please tell the deity that you got the 'banana boat' error\n"); + return abort_attack(); + } + if (def->shp_mcp->m_flags & M_SUB) { + getsect(def->x, def->y, §); + if (sect.sct_type == SCT_WATER) { + pr("You can't board a submarine!\n"); + return abort_attack(); } - return 0; + } + return 0; } /* @@ -646,68 +666,63 @@ board_abort(struct combat *off, struct combat *def) static int land_board_abort(struct combat *off, struct combat *def) { - if (att_get_combat(def, 1) < 0) - return abort_attack(); + if (att_get_combat(def, 1) < 0) + return abort_attack(); - if (!off) - return 0; + if (!off) + return 0; - if (att_get_combat(off, 0) < 0) - return abort_attack(); + if (att_get_combat(off, 0) < 0) + return abort_attack(); - if (off->x != def->x || off->y != def->y) { - pr("Land unit #%d is not in the same sector!\n", def->lnd_uid); - return abort_attack(); - } + if (off->x != def->x || off->y != def->y) { + pr("Land unit #%d is not in the same sector!\n", def->lnd_uid); + return abort_attack(); + } - return 0; + return 0; } /* If we are boarding, then the defending ship gets a chance to fire back */ int att_approach(struct combat *off, struct combat *def) { - int dam; - struct sctstr sect; - struct shpstr ship; - - pr("Approaching %s...\n", prcom(0, def)); - if (def->own) - wu(0, def->own, - "%s is being approached by %s...\n", - pr_com(0, def, def->own), - pr_com(0, off, def->own)); - if (!(dam = shipdef(player->cnum, def->own, def->x, def->y))) - return 0; - - pr("They're firing at us sir!\n"); - if (def->own) { - wu(0, def->own, - "Your fleet at %s does %d damage to %s\n", - xyas(def->x, def->y, def->own), - dam, - pr_com(0, off, def->own)); - } - if (off->type == EF_SECTOR) { - getsect(off->x, off->y, §); - sectdamage(§, dam, 0); - putsect(§); - pr("Enemy fleet at %s does %d damage to %s\n", - xyas(def->x, def->y, player->cnum), - dam, prcom(0, off)); - } else if (off->type == EF_SHIP) { - getship(off->shp_uid, &ship); - shipdamage(&ship, dam); - putship(off->shp_uid, &ship); - if (def->own && ship.shp_effic < SHIP_MINEFF) { - wu(0, def->own, - "%s sunk!\n", pr_com(0, off, def->own)); - nreport(player->cnum, N_SHP_LOSE, def->own, 1); - } - } - if (att_get_combat(off, 0) < 0) - return abort_attack(); + int dam; + struct sctstr sect; + struct shpstr ship; + + pr("Approaching %s...\n", prcom(0, def)); + if (def->own) + wu(0, def->own, + "%s is being approached by %s...\n", + pr_com(0, def, def->own), pr_com(0, off, def->own)); + if (!(dam = shipdef(player->cnum, def->own, def->x, def->y))) return 0; + + pr("They're firing at us sir!\n"); + if (def->own) { + wu(0, def->own, + "Your fleet at %s does %d damage to %s\n", + xyas(def->x, def->y, def->own), dam, pr_com(0, off, def->own)); + } + if (off->type == EF_SECTOR) { + getsect(off->x, off->y, §); + sectdamage(§, dam, 0); + putsect(§); + pr("Enemy fleet at %s does %d damage to %s\n", + xyas(def->x, def->y, player->cnum), dam, prcom(0, off)); + } else if (off->type == EF_SHIP) { + getship(off->shp_uid, &ship); + shipdamage(&ship, dam); + putship(off->shp_uid, &ship); + if (def->own && ship.shp_effic < SHIP_MINEFF) { + wu(0, def->own, "%s sunk!\n", pr_com(0, off, def->own)); + nreport(player->cnum, N_SHP_LOSE, def->own, 1); + } + } + if (att_get_combat(off, 0) < 0) + return abort_attack(); + return 0; } /* The attack is valid. Tell the attacker about what they're going to hit */ @@ -728,17 +743,14 @@ att_show(struct combat *def) if (map_set(player->cnum, def->x, def->y, def->sct_dcp->d_mnem, 0)) writemap(player->cnum); } else if (def->type == EF_SHIP || def->type == EF_LAND) { - if (def->type == EF_SHIP) { + if (def->type == EF_SHIP) { if (!trechk(player->cnum, def->own, SEAATT)) return abort_attack(); } else { if (!trechk(player->cnum, def->own, LNDATT)) return abort_attack(); } - pr("%s is about %d%% efficient and has approximately %d mil on board.\n", - prcom(0, def), - roundintby((int)def->eff, 10), - roundintby(def->troops, 10)); + pr("%s is about %d%% efficient and has approximately %d mil on board.\n", prcom(0, def), roundintby((int)def->eff, 10), roundintby(def->troops, 10)); } /* Ok, everything is fine */ return 0; @@ -747,48 +759,60 @@ att_show(struct combat *def) /* Attack and assault ask the user which kind of support they want */ int -att_ask_support(int offset, int *fortp, int *shipp, int *landp, int *planep) +att_ask_support(int offset, int *fortp, int *shipp, int *landp, + int *planep) { - s_char buf[1024]; - s_char *p; - *fortp = *shipp = *landp = *planep = 1; - - if (player->argp[offset] != (s_char *)0){ - if ((player->argp[offset+1] == (s_char *)0) || - (player->argp[offset+2] == (s_char *)0) || - (player->argp[offset+3] == (s_char *)0)){ - pr("If any support arguments are used, all must be!\n"); - return RET_SYN; - } - - *fortp=*shipp=0; - *landp=*planep=0; - - if (!(p = getstarg(player->argp[offset], "Use fort support? ", buf))) - return RET_SYN; - - if ((*p == 'y') || (*p == 'Y')) - *fortp = 1; - - if (!(p = getstarg(player->argp[offset+1], "Use ship support? ", buf))) - return RET_SYN; - - if ((*p == 'y') || (*p == 'Y')) - *shipp = 1; - - if (!(p = getstarg(player->argp[offset+2], "Use land support? ", buf))) - return RET_SYN; - - if ((*p == 'y') || (*p == 'Y')) - *landp = 1; - - if (!(p = getstarg(player->argp[offset+3], "Use plane support? ", buf))) - return RET_SYN; - - if ((*p == 'y') || (*p == 'Y')) - *planep = 1; - } - return RET_OK; + s_char buf[1024]; + s_char *p; + *fortp = *shipp = *landp = *planep = 1; + + if (player->argp[offset] != (s_char *)0) { + if ((player->argp[offset + 1] == (s_char *)0) || + (player->argp[offset + 2] == (s_char *)0) || + (player->argp[offset + 3] == (s_char *)0)) { + pr("If any support arguments are used, all must be!\n"); + return RET_SYN; + } + + *fortp = *shipp = 0; + *landp = *planep = 0; + + if (! + (p = + getstarg(player->argp[offset], "Use fort support? ", buf))) + return RET_SYN; + + if ((*p == 'y') || (*p == 'Y')) + *fortp = 1; + + if (! + (p = + getstarg(player->argp[offset + 1], "Use ship support? ", + buf))) + return RET_SYN; + + if ((*p == 'y') || (*p == 'Y')) + *shipp = 1; + + if (! + (p = + getstarg(player->argp[offset + 2], "Use land support? ", + buf))) + return RET_SYN; + + if ((*p == 'y') || (*p == 'Y')) + *landp = 1; + + if (! + (p = + getstarg(player->argp[offset + 3], "Use plane support? ", + buf))) + return RET_SYN; + + if ((*p == 'y') || (*p == 'Y')) + *planep = 1; + } + return RET_OK; } /* @@ -799,25 +823,26 @@ att_ask_support(int offset, int *fortp, int *shipp, int *landp, int *planep) */ int -att_ask_offense(int combat_mode, struct combat *off, struct combat *def, struct emp_qelem *olist, int *a_spyp, int *a_engineerp) +att_ask_offense(int combat_mode, struct combat *off, struct combat *def, + struct emp_qelem *olist, int *a_spyp, int *a_engineerp) { - int n; - s_char land_answer[1024]; - - emp_initque(olist); - if (att_abort(combat_mode, off, def)) - return 0; - bzero(land_answer, sizeof(land_answer)); - for (n = 0; n <= off->last; ++n) { - off[n].troops = ask_off(combat_mode, off + n, def); - if (att_abort(combat_mode, off, def)) - return 0; - ask_olist(combat_mode, off + n, def, olist, land_answer, - a_spyp, a_engineerp); - if (att_abort(combat_mode, off, def)) - return 0; - } + int n; + s_char land_answer[1024]; + + emp_initque(olist); + if (att_abort(combat_mode, off, def)) return 0; + bzero(land_answer, sizeof(land_answer)); + for (n = 0; n <= off->last; ++n) { + off[n].troops = ask_off(combat_mode, off + n, def); + if (att_abort(combat_mode, off, def)) + return 0; + ask_olist(combat_mode, off + n, def, olist, land_answer, + a_spyp, a_engineerp); + if (att_abort(combat_mode, off, def)) + return 0; + } + return 0; } /* How many mil is off allowed to attack with when it attacks def? */ @@ -825,55 +850,52 @@ att_ask_offense(int combat_mode, struct combat *off, struct combat *def, struct static int get_mob_support(int combat_mode, struct combat *off, struct combat *def) { - int mob_support; - - switch (combat_mode) { - case A_ATTACK: - mob_support = off->mob / sector_mcost(getsectp(def->x, def->y), - MOB_ROAD); - if (mob_support < 0) - mob_support = 0; + int mob_support; + + switch (combat_mode) { + case A_ATTACK: + mob_support = off->mob / sector_mcost(getsectp(def->x, def->y), + MOB_ROAD); + if (mob_support < 0) + mob_support = 0; /* mob_support = off->mob / sector_mcost(def->sct_type, def->eff);*/ - if (mob_support < off->troops) - pr("Sector %s has %d mobility which can only support %d mil,\n", - xyas(off->x, off->y, player->cnum), - off->mob, - mob_support); - else - mob_support = off->troops; - return mob_support; - case A_ASSAULT: - if (def->own != player->cnum && def->mil) { - if (off->shp_mcp->m_flags & M_SEMILAND) - return off->troops/4; - else if (!(off->shp_mcp->m_flags & M_LAND)) - return off->troops/10; - } - break; - case A_BOARD: - if (off->type == EF_SECTOR && off->mob <= 0) - return 0; - mob_support = vl_find(V_MILIT, def->shp_mcp->m_vtype, - def->shp_mcp->m_vamt,def->shp_mcp->m_nv); - if (mob_support < off->troops) - pr("The size of the ship you are trying to board limits your party to %d mil,\n", mob_support); - else - mob_support = off->troops; - return mob_support; - case A_LBOARD: - if (off->mob <= 0) - return 0; - if (def->lnd_lcp->l_flags & L_SPY) - return 1; - mob_support = vl_find(V_MILIT, def->lnd_lcp->l_vtype, - def->lnd_lcp->l_vamt,def->lnd_lcp->l_nv); - if (mob_support < off->troops) - pr("The size of the unit you are trying to board limits your party to %d mil,\n", mob_support); - else - mob_support = off->troops; - return mob_support; - } - return off->troops; + if (mob_support < off->troops) + pr("Sector %s has %d mobility which can only support %d mil,\n", xyas(off->x, off->y, player->cnum), off->mob, mob_support); + else + mob_support = off->troops; + return mob_support; + case A_ASSAULT: + if (def->own != player->cnum && def->mil) { + if (off->shp_mcp->m_flags & M_SEMILAND) + return off->troops / 4; + else if (!(off->shp_mcp->m_flags & M_LAND)) + return off->troops / 10; + } + break; + case A_BOARD: + if (off->type == EF_SECTOR && off->mob <= 0) + return 0; + mob_support = vl_find(V_MILIT, def->shp_mcp->m_vtype, + def->shp_mcp->m_vamt, def->shp_mcp->m_nv); + if (mob_support < off->troops) + pr("The size of the ship you are trying to board limits your party to %d mil,\n", mob_support); + else + mob_support = off->troops; + return mob_support; + case A_LBOARD: + if (off->mob <= 0) + return 0; + if (def->lnd_lcp->l_flags & L_SPY) + return 1; + mob_support = vl_find(V_MILIT, def->lnd_lcp->l_vtype, + def->lnd_lcp->l_vamt, def->lnd_lcp->l_nv); + if (mob_support < off->troops) + pr("The size of the unit you are trying to board limits your party to %d mil,\n", mob_support); + else + mob_support = off->troops; + return mob_support; + } + return off->troops; } /* @@ -884,32 +906,34 @@ get_mob_support(int combat_mode, struct combat *off, struct combat *def) */ static void -calc_mobcost(int combat_mode, struct combat *off, struct combat *def, int attacking_mil) +calc_mobcost(int combat_mode, struct combat *off, struct combat *def, + int attacking_mil) { - struct shpstr ship; + struct shpstr ship; - if (!attacking_mil) - return; - switch (combat_mode) { - case A_ATTACK: - off->mobcost += - max(1, (int)(attacking_mil * sector_mcost(getsectp(def->x, def->y), MOB_ROAD))); - break; - case A_LBOARD: + if (!attacking_mil) + return; + switch (combat_mode) { + case A_ATTACK: + off->mobcost += + max(1, + (int)(attacking_mil * + sector_mcost(getsectp(def->x, def->y), MOB_ROAD))); + break; + case A_LBOARD: + off->mobcost += max(1, attacking_mil / 5); + break; + case A_BOARD: + switch (off->type) { + case EF_SECTOR: off->mobcost += max(1, attacking_mil / 5); break; - case A_BOARD: - switch (off->type) { - case EF_SECTOR: - off->mobcost += max(1, attacking_mil / 5); - break; - case EF_SHIP: - /* the 2 in the formula below is a fudge factor */ - getship(def->shp_uid, &ship); - off->mobcost += (def->eff / 100) * - (ship.shp_speed / 2); - } + case EF_SHIP: + /* the 2 in the formula below is a fudge factor */ + getship(def->shp_uid, &ship); + off->mobcost += (def->eff / 100) * (ship.shp_speed / 2); } + } } /* How many mil to we want to attack from off against def? */ @@ -917,37 +941,38 @@ calc_mobcost(int combat_mode, struct combat *off, struct combat *def, int attack static int ask_off(int combat_mode, struct combat *off, struct combat *def) { - int attacking_mil; - int mob_support; - s_char prompt[512]; + int attacking_mil; + int mob_support; + s_char prompt[512]; - if (att_get_combat(off, 0) <= 0) - return 0; - if ((off->type == EF_SECTOR) && (off->own != player->cnum)) - return 0; - if ((mob_support = get_mob_support(combat_mode, off, def)) <= 0) - return 0; - if (off->type == EF_SECTOR) { - if (off->own != player->cnum) - return 0; - sprintf(prompt, "Number of mil from %s at %s (max %d) : ", - off->sct_dcp->d_name, - xyas(off->x, off->y, player->cnum), mob_support); - } else { - sprintf(prompt, "Number of mil from %s (max %d) : ", - prcom(0, off), mob_support); - } - if ((attacking_mil = onearg(0, prompt)) < 0) - abort_attack(); - if (att_abort(combat_mode, off, def)) - return 0; - if (att_get_combat(off, 0) <= 0) - return 0; - if ((attacking_mil = min(attacking_mil, min(mob_support, off->troops))) <= 0) - return 0; - - calc_mobcost(combat_mode, off, def, attacking_mil); - return attacking_mil; + if (att_get_combat(off, 0) <= 0) + return 0; + if ((off->type == EF_SECTOR) && (off->own != player->cnum)) + return 0; + if ((mob_support = get_mob_support(combat_mode, off, def)) <= 0) + return 0; + if (off->type == EF_SECTOR) { + if (off->own != player->cnum) + return 0; + sprintf(prompt, "Number of mil from %s at %s (max %d) : ", + off->sct_dcp->d_name, + xyas(off->x, off->y, player->cnum), mob_support); + } else { + sprintf(prompt, "Number of mil from %s (max %d) : ", + prcom(0, off), mob_support); + } + if ((attacking_mil = onearg(0, prompt)) < 0) + abort_attack(); + if (att_abort(combat_mode, off, def)) + return 0; + if (att_get_combat(off, 0) <= 0) + return 0; + if ((attacking_mil = + min(attacking_mil, min(mob_support, off->troops))) <= 0) + return 0; + + calc_mobcost(combat_mode, off, def, attacking_mil); + return attacking_mil; } /* @@ -957,195 +982,188 @@ ask_off(int combat_mode, struct combat *off, struct combat *def) static s_char att_prompt(s_char *prompt, s_char army) { - s_char buf[1024]; - s_char *p = buf; - - if (army == ' ') - army = '~'; - *buf = -2; - while (!p || - (*p != 'y' && - *p != 'n' && - *p != 'Y' && - *p != 'N')) { - if (p && *p == 'q') { - abort_attack(); - return 'N'; - } - if (!p || !*p) - return 'n'; - if (p && *p != -2) - pr("y - yes this unit\nn - no this unit\nY - yes to all units in army '%c'\nN - no to all units in army '%c'\nq - quit\n? - this help message\n\n", army, army); - p = getstring(prompt, buf); - if (player->aborted) { - buf[0] = 'N'; - p = buf; - } + s_char buf[1024]; + s_char *p = buf; + + if (army == ' ') + army = '~'; + *buf = -2; + while (!p || (*p != 'y' && *p != 'n' && *p != 'Y' && *p != 'N')) { + if (p && *p == 'q') { + abort_attack(); + return 'N'; + } + if (!p || !*p) + return 'n'; + if (p && *p != -2) + pr("y - yes this unit\nn - no this unit\nY - yes to all units in army '%c'\nN - no to all units in army '%c'\nq - quit\n? - this help message\n\n", army, army); + p = getstring(prompt, buf); + if (player->aborted) { + buf[0] = 'N'; + p = buf; } - return *p; + } + return *p; } /* Ask the attacker which units they want to attack/assault/board with */ static void -ask_olist(int combat_mode, struct combat *off, struct combat *def, struct emp_qelem *olist, s_char *land_answer, int *a_spyp, int *a_engineerp) +ask_olist(int combat_mode, struct combat *off, struct combat *def, + struct emp_qelem *olist, s_char *land_answer, int *a_spyp, + int *a_engineerp) { - struct nstr_item ni; - struct lndstr land; - double mobcost; - struct llist *llp; - struct lchrstr *lcp; - int att_val; - int count = 0; - int maxland = 0; - int first_time = 1; - s_char prompt[512]; - - if (def->type == EF_LAND) - return; - if (def->type == EF_SHIP) - maxland = def->shp_mcp->m_nland; + struct nstr_item ni; + struct lndstr land; + double mobcost; + struct llist *llp; + struct lchrstr *lcp; + int att_val; + int count = 0; + int maxland = 0; + int first_time = 1; + s_char prompt[512]; + + if (def->type == EF_LAND) + return; + if (def->type == EF_SHIP) + maxland = def->shp_mcp->m_nland; + + snxtitem_xy(&ni, EF_LAND, off->x, off->y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own != player->cnum) + continue; + if (land.lnd_effic < LAND_MINEFF) + continue; + if (land_answer[(int)land.lnd_army] == 'N') + continue; + if (!lnd_can_attack(&land)) + continue; + lcp = &lchr[(int)land.lnd_type]; + + if (def->type == EF_SHIP && !maxland) { + pr("Land units are not able to board this kind of ship\n"); + return; + } + if (land.lnd_mobil <= 0) { + pr("%s is out of mobility, and cannot %s\n", + prland(&land), att_mode[combat_mode]); + continue; + } + + if (opt_MARKET) { + if (ontradingblock(EF_LAND, (int *)&land)) { + pr("%s is on the trading block, and cannot %s\n", + prland(&land), att_mode[combat_mode]); + continue; + } + } - snxtitem_xy(&ni,EF_LAND,off->x,off->y); - while(nxtitem(&ni,(s_char *)&land)){ - if (land.lnd_own != player->cnum) - continue; - if (land.lnd_effic < LAND_MINEFF) - continue; - if (land_answer[(int)land.lnd_army] == 'N') - continue; - if (!lnd_can_attack(&land)) - continue; - lcp = &lchr[(int)land.lnd_type]; + if (off->type == EF_SECTOR && land.lnd_ship >= 0) { + pr("%s is on ship #%d, and cannot %s\n", + prland(&land), land.lnd_ship, att_mode[combat_mode]); + continue; + } else if (off->type == EF_SHIP) { + if (land.lnd_ship != off->shp_uid) + continue; + } else if (land.lnd_land >= 0) { + pr("%s is on unit #%d, and cannot %s\n", + prland(&land), land.lnd_land, att_mode[combat_mode]); + continue; + } + switch (combat_mode) { + case A_ATTACK: + mobcost = + lnd_mobcost(&land, getsectp(def->x, def->y), MOB_NONE); + if (land.lnd_mobil < mobcost) { + pr("%s does not have enough mobility (%d needed)\n", + prland(&land), (int)mobcost + 1); + continue; + } + break; + case A_ASSAULT: + case A_BOARD: + mobcost = 0; + if (!(lcp->l_flags & L_ASSAULT)) + continue; + } + att_val = attack_val(combat_mode, &land); + if (!att_val) { + pr("%s has no offensive strength\n", prland(&land)); + continue; + } + resupply_all(&land); + putland(land.lnd_uid, &land); + if (!has_supply(&land)) { + pr("%s is out of supply, and cannot %s\n", + prland(&land), att_mode[combat_mode]); + continue; + } + if (def->type == EF_SHIP && first_time) { + first_time = 0; + pr("You may board with a maximum of %d land units\n", maxland); + } + pr("%s has a base %s value of %d\n", + prland(&land), att_mode[combat_mode], att_val); + if (land_answer[(int)land.lnd_army] != 'Y') { + sprintf(prompt, + "%s with %s %s (%c %d%%) [ynYNq?] ", + att_mode[combat_mode], + prland(&land), + prcom(1, off), + land.lnd_army == ' ' ? '~' : land.lnd_army, + land.lnd_effic); + land_answer[(int)land.lnd_army] = + att_prompt(prompt, land.lnd_army); + if (att_abort(combat_mode, off, def)) + return; + if (land_answer[(int)land.lnd_army] != 'y' && + land_answer[(int)land.lnd_army] != 'Y') + continue; + } + if (!(llp = (struct llist *)malloc(sizeof(struct llist)))) { + logerror("Malloc failed in attack!\n"); + abort_attack(); + return; + } + bzero((s_char *)llp, sizeof(struct llist)); + emp_insque(&llp->queue, olist); + llp->mobil = mobcost; + if (!get_land(combat_mode, def, land.lnd_uid, llp, 0)) + continue; + if (lnd_spyval(&land) > *a_spyp) + *a_spyp = lnd_spyval(&land); + if (llp->lcp->l_flags & L_ENGINEER) + ++(*a_engineerp); + if (def->type == EF_SHIP && ++count >= maxland) + break; + } +} - if (def->type == EF_SHIP && !maxland) { - pr("Land units are not able to board this kind of ship\n"); - return; - } - if (land.lnd_mobil <= 0) { - pr("%s is out of mobility, and cannot %s\n", - prland(&land), - att_mode[combat_mode]); - continue; - } +/* What's the offense or defense multiplier? */ - if (opt_MARKET) { - if (ontradingblock(EF_LAND, (int *)&land)) { - pr("%s is on the trading block, and cannot %s\n", - prland(&land), att_mode[combat_mode]); - continue; - } - } - - if (off->type == EF_SECTOR && land.lnd_ship >= 0) { - pr("%s is on ship #%d, and cannot %s\n", - prland(&land), land.lnd_ship, - att_mode[combat_mode]); - continue; - } else if (off->type == EF_SHIP) { - if (land.lnd_ship != off->shp_uid) - continue; - } else if (land.lnd_land >= 0) { - pr("%s is on unit #%d, and cannot %s\n", - prland(&land), land.lnd_land, att_mode[combat_mode]); - continue; - } - switch (combat_mode) { - case A_ATTACK: - mobcost = lnd_mobcost(&land, getsectp(def->x, def->y), MOB_NONE); - if (land.lnd_mobil < mobcost) { - pr("%s does not have enough mobility (%d needed)\n", - prland(&land), - (int)mobcost + 1); - continue; - } - break; - case A_ASSAULT: - case A_BOARD: - mobcost = 0; - if (!(lcp->l_flags & L_ASSAULT)) - continue; - } - att_val = attack_val(combat_mode, &land); - if (!att_val) { - pr("%s has no offensive strength\n", - prland(&land)); - continue; - } - resupply_all(&land); - putland(land.lnd_uid,&land); - if (!has_supply(&land)){ - pr("%s is out of supply, and cannot %s\n", - prland(&land), att_mode[combat_mode]); - continue; - } - if (def->type == EF_SHIP && first_time) { - first_time = 0; - pr("You may board with a maximum of %d land units\n", maxland); - } - pr("%s has a base %s value of %d\n", - prland(&land), - att_mode[combat_mode], - att_val); - if (land_answer[(int)land.lnd_army] != 'Y') { - sprintf(prompt, - "%s with %s %s (%c %d%%) [ynYNq?] ", - att_mode[combat_mode], - prland(&land), - prcom(1, off), - land.lnd_army==' '?'~':land.lnd_army, - land.lnd_effic); - land_answer[(int)land.lnd_army] = - att_prompt(prompt, land.lnd_army); - if (att_abort(combat_mode, off, def)) - return; - if (land_answer[(int)land.lnd_army] != 'y' && - land_answer[(int)land.lnd_army] != 'Y') - continue; - } - if (!(llp = (struct llist *)malloc(sizeof(struct llist)))) { - logerror("Malloc failed in attack!\n"); - abort_attack(); - return; - } - bzero((s_char *)llp,sizeof(struct llist)); - emp_insque(&llp->queue,olist); - llp->mobil = mobcost; - if (!get_land(combat_mode, def, land.lnd_uid, llp, 0)) - continue; - if (lnd_spyval(&land) > *a_spyp) - *a_spyp = lnd_spyval(&land); - if (llp->lcp->l_flags & L_ENGINEER) - ++(*a_engineerp); - if (def->type == EF_SHIP && ++count >= maxland) - break; - } -} - -/* What's the offense or defense multiplier? */ - -double -att_combat_eff(struct combat *com) -{ - double eff = 1.0; - double str; - double sector_strength(struct sctstr *sp); - struct shpstr ship; - - if (com->type == EF_SECTOR) { - eff = com->eff / 100.0; - if (com->own == player->cnum) { - str = com->sct_dcp->d_ostr; - eff = 1.0 + ((str - 1.0) * eff); - } else - eff = sector_strength(getsectp(com->x, com->y)); -/* str = com->sct_dcp->d_dstr;*/ - } else if (com->type == EF_SHIP && com->own != player->cnum) { - getship(com->shp_uid, &ship); - eff = (1.0 + ship.shp_armor / 100.0); - } - return eff; -} +double +att_combat_eff(struct combat *com) +{ + double eff = 1.0; + double str; + double sector_strength(struct sctstr *sp); + struct shpstr ship; + + if (com->type == EF_SECTOR) { + eff = com->eff / 100.0; + if (com->own == player->cnum) { + str = com->sct_dcp->d_ostr; + eff = 1.0 + ((str - 1.0) * eff); + } else + eff = sector_strength(getsectp(com->x, com->y)); +/* str = com->sct_dcp->d_dstr;*/ + } else if (com->type == EF_SHIP && com->own != player->cnum) { + getship(com->shp_uid, &ship); + eff = (1.0 + ship.shp_armor / 100.0); + } + return eff; +} /* * Estimate the defense strength and give the attacker a chance to abort @@ -1153,33 +1171,35 @@ att_combat_eff(struct combat *com) */ int -att_estimate_defense(int combat_mode, struct combat *off, struct emp_qelem *olist, struct combat *def, int a_spy) +att_estimate_defense(int combat_mode, struct combat *off, + struct emp_qelem *olist, struct combat *def, + int a_spy) { - int ototal; - int estimate; - int odds; - - /* - * Get the attacker units & mil again in case they changed while the - * attacker was answering sub-prompts. - */ - - ototal = get_ototal(combat_mode, off, olist, 1.0, 1); - if (att_empty_attack(combat_mode, ototal, def)) - return abort_attack(); - if (combat_mode == A_PARA) - return ototal; - pr("\n Initial attack strength: %8d\n", ototal); + int ototal; + int estimate; + int odds; + + /* + * Get the attacker units & mil again in case they changed while the + * attacker was answering sub-prompts. + */ + + ototal = get_ototal(combat_mode, off, olist, 1.0, 1); + if (att_empty_attack(combat_mode, ototal, def)) + return abort_attack(); + if (combat_mode == A_PARA) + return ototal; + pr("\n Initial attack strength: %8d\n", ototal); - estimate = att_combat_eff(def) * roundintby(def->troops, 10); - estimate += att_combat_eff(def) * get_dlist(def, 0, a_spy, 0); + estimate = att_combat_eff(def) * roundintby(def->troops, 10); + estimate += att_combat_eff(def) * get_dlist(def, 0, a_spy, 0); - /* - * Calculate the initial (pre-support) attack odds. If they're less - * than 50%, ask for a confirmation. - */ + /* + * Calculate the initial (pre-support) attack odds. If they're less + * than 50%, ask for a confirmation. + */ - odds = (int)(att_calcodds(ototal,estimate) * 100); + odds = (int)(att_calcodds(ototal, estimate) * 100); /* if (odds < 50) { @@ -1194,182 +1214,186 @@ att_estimate_defense(int combat_mode, struct combat *off, struct emp_qelem *olis return abort_attack(); } */ - return ototal; + return ototal; } /* Get the defensive units and reacting units */ int -att_get_defense(struct emp_qelem *olist, struct combat *def, struct emp_qelem *dlist, int a_spy, int ototal) +att_get_defense(struct emp_qelem *olist, struct combat *def, + struct emp_qelem *dlist, int a_spy, int ototal) { - int d_spy = 0; - struct emp_qelem *qp; - struct llist *llp; - int dtotal; - int old_dtotal; + int d_spy = 0; + struct emp_qelem *qp; + struct llist *llp; + int dtotal; + int old_dtotal; - emp_initque(dlist); - get_dlist(def, dlist, 0, &d_spy); - dtotal = get_dtotal(def,dlist,1.0,0); + emp_initque(dlist); + get_dlist(def, dlist, 0, &d_spy); + dtotal = get_dtotal(def, dlist, 1.0, 0); - /* - * Call in reacting units - */ + /* + * Call in reacting units + */ - if (def->type == EF_SECTOR && def->sct_type != SCT_MOUNT) - att_reacting_units(def, dlist, a_spy, &d_spy, ototal); + if (def->type == EF_SECTOR && def->sct_type != SCT_MOUNT) + att_reacting_units(def, dlist, a_spy, &d_spy, ototal); - for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) { - llp = (struct llist *)qp; - intelligence_report(def->own, &llp->land, d_spy, - "Scouts report attacking unit:"); - } + for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) { + llp = (struct llist *)qp; + intelligence_report(def->own, &llp->land, d_spy, + "Scouts report attacking unit:"); + } - old_dtotal = dtotal; - dtotal = get_dtotal(def,dlist,1.0,0); - if (dtotal != old_dtotal) - pr("Defense strength with reacting units: %8d\n", dtotal); + old_dtotal = dtotal; + dtotal = get_dtotal(def, dlist, 1.0, 0); + if (dtotal != old_dtotal) + pr("Defense strength with reacting units: %8d\n", dtotal); - return dtotal; + return dtotal; } /* Get the defensive land units in the sector or on the ship */ static int -get_dlist(struct combat *def, struct emp_qelem *list, int a_spy, int *d_spyp) +get_dlist(struct combat *def, struct emp_qelem *list, int a_spy, + int *d_spyp) { - struct nstr_item ni; - struct llist *llp; - struct lndstr land; - int estimate = 0; + struct nstr_item ni; + struct llist *llp; + struct lndstr land; + int estimate = 0; /* In here is where you need to take out spies and trains from the defending lists. Spies try to hide, trains get trapped and can be boarded. */ - snxtitem_xy(&ni,EF_LAND,def->x,def->y); - while(nxtitem(&ni,(s_char *)&land)){ - if (!land.lnd_own) - continue; - if (land.lnd_own != def->own) - continue; - if (def->type == EF_SECTOR && land.lnd_ship >= 0) - continue; - if (def->type == EF_SECTOR && land.lnd_land >= 0) - continue; - if (def->type == EF_SHIP && land.lnd_ship != def->shp_uid) - continue; - if (def->type == EF_LAND && land.lnd_land != def->lnd_uid) - continue; - if (!list) { /* Just estimating the enemy strength */ - estimate += intelligence_report(player->cnum, - &land,a_spy, - "Scouts report defending unit:"); - continue; - } - if (!(llp = (struct llist *)malloc(sizeof(struct llist)))) { - logerror("Malloc failed in attack!\n"); - abort_attack(); - return 0; - } - bzero((s_char *)llp,sizeof(struct llist)); - emp_insque(&llp->queue,list); - llp->supplied = has_supply(&land); - if (!get_land(A_DEFEND,def,land.lnd_uid, llp, 1)) - continue; - if (lnd_spyval(&land) > *d_spyp) - *d_spyp = lnd_spyval(&land); - } - return estimate; + snxtitem_xy(&ni, EF_LAND, def->x, def->y); + while (nxtitem(&ni, (s_char *)&land)) { + if (!land.lnd_own) + continue; + if (land.lnd_own != def->own) + continue; + if (def->type == EF_SECTOR && land.lnd_ship >= 0) + continue; + if (def->type == EF_SECTOR && land.lnd_land >= 0) + continue; + if (def->type == EF_SHIP && land.lnd_ship != def->shp_uid) + continue; + if (def->type == EF_LAND && land.lnd_land != def->lnd_uid) + continue; + if (!list) { /* Just estimating the enemy strength */ + estimate += intelligence_report(player->cnum, + &land, a_spy, + "Scouts report defending unit:"); + continue; + } + if (!(llp = (struct llist *)malloc(sizeof(struct llist)))) { + logerror("Malloc failed in attack!\n"); + abort_attack(); + return 0; + } + bzero((s_char *)llp, sizeof(struct llist)); + emp_insque(&llp->queue, list); + llp->supplied = has_supply(&land); + if (!get_land(A_DEFEND, def, land.lnd_uid, llp, 1)) + continue; + if (lnd_spyval(&land) > *d_spyp) + *d_spyp = lnd_spyval(&land); + } + return estimate; } /* Calculate the total offensive strength */ static int -get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist, double osupport, int check) +get_ototal(int combat_mode, struct combat *off, struct emp_qelem *olist, + double osupport, int check) { - double ototal=0.0; - struct emp_qelem *qp, *next; - struct llist *llp; - int n,w; - - /* - * first, total the attacking mil - */ + double ototal = 0.0; + struct emp_qelem *qp, *next; + struct llist *llp; + int n, w; + + /* + * first, total the attacking mil + */ + + for (n = 0; n <= off->last; ++n) { + if (off[n].type == EF_BAD || (check && + att_get_combat(&off[n], 0) <= 0)) + continue; + ototal += off[n].troops * att_combat_eff(off + n); + } - for (n = 0; n <= off->last; ++n) { - if (off[n].type == EF_BAD || (check && - att_get_combat(&off[n], 0) <= 0)) - continue; - ototal += off[n].troops * att_combat_eff(off + n); - } + /* + * next, add in the attack_values of all + * the attacking units + */ - /* - * next, add in the attack_values of all - * the attacking units - */ - - for (qp = olist->q_forw; qp != olist; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - if (check && !get_land(combat_mode,0,llp->land.lnd_uid, llp, 0)) - continue; - if (combat_mode == A_ATTACK) { - w=-1; - for(n = 0;n <= off->last; ++n) { - if (off[n].type == EF_BAD) - continue; - if ((off[n].x == llp->land.lnd_x) && - (off[n].y == llp->land.lnd_y)) - w = n; - } - if (w < 0) { - lnd_delete(llp, "is in a sector not owned by you"); - continue; - } - ototal += attack_val(combat_mode, &llp->land) * - att_combat_eff(off + w); - } else { - ototal += attack_val(combat_mode, &llp->land); - } + for (qp = olist->q_forw; qp != olist; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + if (check && !get_land(combat_mode, 0, llp->land.lnd_uid, llp, 0)) + continue; + if (combat_mode == A_ATTACK) { + w = -1; + for (n = 0; n <= off->last; ++n) { + if (off[n].type == EF_BAD) + continue; + if ((off[n].x == llp->land.lnd_x) && + (off[n].y == llp->land.lnd_y)) + w = n; + } + if (w < 0) { + lnd_delete(llp, "is in a sector not owned by you"); + continue; + } + ototal += attack_val(combat_mode, &llp->land) * + att_combat_eff(off + w); + } else { + ototal += attack_val(combat_mode, &llp->land); } - ototal *= osupport; + } + ototal *= osupport; - return ldround(ototal, 1); + return ldround(ototal, 1); } /* Calculate the total defensive strength */ static int -get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport, int check) +get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport, + int check) { - double dtotal=0.0, eff = 1.0, d_unit; - struct emp_qelem *qp, *next; - struct llist *llp; + double dtotal = 0.0, eff = 1.0, d_unit; + struct emp_qelem *qp, *next; + struct llist *llp; - if (check && att_get_combat(def, 1) < 0) - return 0; - eff = att_combat_eff(def); - dtotal = def->troops * eff; + if (check && att_get_combat(def, 1) < 0) + return 0; + eff = att_combat_eff(def); + dtotal = def->troops * eff; - /* - * next, add in the defense_values of all - * the defending non-retreating units - */ + /* + * next, add in the defense_values of all + * the defending non-retreating units + */ - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - d_unit = 0.0; - if (check && !get_land(A_DEFEND,def,llp->land.lnd_uid, llp, 1)) - continue; - d_unit = defense_val(&llp->land); - if (!llp->supplied) - d_unit = ((double)defense_val(&llp->land)/2.0); - dtotal += d_unit * eff; - } + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + d_unit = 0.0; + if (check && !get_land(A_DEFEND, def, llp->land.lnd_uid, llp, 1)) + continue; + d_unit = defense_val(&llp->land); + if (!llp->supplied) + d_unit = ((double)defense_val(&llp->land) / 2.0); + dtotal += d_unit * eff; + } - dtotal *= dsupport; + dtotal *= dsupport; - return ldround(dtotal,1); + return ldround(dtotal, 1); } /* @@ -1378,49 +1402,56 @@ get_dtotal(struct combat *def, struct emp_qelem *list, double dsupport, int chec */ static int -get_land(int combat_mode, struct combat *def, int uid, struct llist *llp, int victim_land) +get_land(int combat_mode, struct combat *def, int uid, struct llist *llp, + int victim_land) { - struct lndstr *lp = &llp->land; - s_char buf[512]; - - getland(uid, lp); - - if (!llp->lcp) { /* first time */ - llp->x = llp->land.lnd_x; - llp->y = llp->land.lnd_y; - llp->lcp = &lchr[(int)llp->land.lnd_type]; - } else { /* not first time */ - if (lp->lnd_effic < LAND_MINEFF) { - sprintf(buf, "was destroyed and is no longer a part of the %s", att_mode[combat_mode]); - lnd_delete(llp, buf); - return 0; - } - if (victim_land) { - if (lp->lnd_x != def->x || lp->lnd_y != def->y) { - lnd_delete(llp, "left to go fight another battle and is no longer a part of the defense"); - return 0; - } - } else { - if (lp->lnd_own != player->cnum) { - sprintf(buf, "was destroyed and is no longer a part of the %s", att_mode[combat_mode]); - lnd_delete(llp, buf); - return 0; - } - if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) { - sprintf(buf, "left to fight another battle and is no longer a part of the %s", att_mode[combat_mode]); - lnd_delete(llp, buf); - return 0; - } - if (lp->lnd_effic < llp->eff) { - sprintf(buf, "damaged from %d%% to %d%%", - llp->eff, lp->lnd_effic); - lnd_print(llp, buf); - } - } + struct lndstr *lp = &llp->land; + s_char buf[512]; + + getland(uid, lp); + + if (!llp->lcp) { /* first time */ + llp->x = llp->land.lnd_x; + llp->y = llp->land.lnd_y; + llp->lcp = &lchr[(int)llp->land.lnd_type]; + } else { /* not first time */ + if (lp->lnd_effic < LAND_MINEFF) { + sprintf(buf, "was destroyed and is no longer a part of the %s", + att_mode[combat_mode]); + lnd_delete(llp, buf); + return 0; + } + if (victim_land) { + if (lp->lnd_x != def->x || lp->lnd_y != def->y) { + lnd_delete(llp, + "left to go fight another battle and is no longer a part of the defense"); + return 0; + } + } else { + if (lp->lnd_own != player->cnum) { + sprintf(buf, + "was destroyed and is no longer a part of the %s", + att_mode[combat_mode]); + lnd_delete(llp, buf); + return 0; + } + if (lp->lnd_x != llp->x || lp->lnd_y != llp->y) { + sprintf(buf, + "left to fight another battle and is no longer a part of the %s", + att_mode[combat_mode]); + lnd_delete(llp, buf); + return 0; + } + if (lp->lnd_effic < llp->eff) { + sprintf(buf, "damaged from %d%% to %d%%", + llp->eff, lp->lnd_effic); + lnd_print(llp, buf); + } } - llp->eff = llp->land.lnd_effic; + } + llp->eff = llp->land.lnd_effic; - return 1; + return 1; } /* @@ -1433,31 +1464,32 @@ get_land(int combat_mode, struct combat *def, int uid, struct llist *llp, int vi static void kill_land(struct emp_qelem *list) { - struct emp_qelem *qp, *next; - struct llist *llp; - - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - if (llp->land.lnd_ship >= 0) { - llp->land.lnd_effic=0; - lnd_delete(llp, "cannot return to the ship, and dies!"); - } + struct emp_qelem *qp, *next; + struct llist *llp; + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + if (llp->land.lnd_ship >= 0) { + llp->land.lnd_effic = 0; + lnd_delete(llp, "cannot return to the ship, and dies!"); } + } } static void att_infect_units(struct emp_qelem *list, int plague) { - struct emp_qelem *qp, *next; - struct llist *llp; + struct emp_qelem *qp, *next; + struct llist *llp; if (!plague) return; for (qp = list->q_forw; qp != list; qp = next) { next = qp->q_forw; llp = (struct llist *)qp; - if (getvar(V_PSTAGE, (s_char *)&(llp->land), EF_LAND) == PLG_HEALTHY) + if (getvar(V_PSTAGE, (s_char *)&(llp->land), EF_LAND) == + PLG_HEALTHY) putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&(llp->land), EF_LAND); } } @@ -1465,23 +1497,23 @@ att_infect_units(struct emp_qelem *list, int plague) static void put_land(struct emp_qelem *list) { - struct emp_qelem *qp, *next; - struct llist *llp; - - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - llp->land.lnd_mission=0; - llp->land.lnd_harden=0; - llp->land.lnd_mobil -= (int)llp->mobil; - llp->mobil = 0.0; - putland(llp->land.lnd_uid, &llp->land); - if (llp->land.lnd_own != player->cnum) { - emp_remque((struct emp_qelem *)llp); - free((s_char *)llp); - } else - get_land(A_ATTACK,0, llp->land.lnd_uid, llp, 0); - } + struct emp_qelem *qp, *next; + struct llist *llp; + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + llp->land.lnd_mission = 0; + llp->land.lnd_harden = 0; + llp->land.lnd_mobil -= (int)llp->mobil; + llp->mobil = 0.0; + putland(llp->land.lnd_uid, &llp->land); + if (llp->land.lnd_own != player->cnum) { + emp_remque((struct emp_qelem *)llp); + free((s_char *)llp); + } else + get_land(A_ATTACK, 0, llp->land.lnd_uid, llp, 0); + } } /* @@ -1490,213 +1522,223 @@ put_land(struct emp_qelem *list) */ int -att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy, int *d_spyp, int ototal) +att_reacting_units(struct combat *def, struct emp_qelem *list, int a_spy, + int *d_spyp, int ototal) { - struct nstr_item ni; - struct lndstr land; - struct sctstr sect, dsect; - struct llist *llp; - int dtotal; - int new_land = 0; - double mobcost; - double move_cost; - int supply_state; - int dist; - int radius; - int origx, origy; - double eff = att_combat_eff(def); - s_char *p; - s_char buf[1024]; - - /* - * - * All units that are within their reaction radius and not damaged - * below their morale value now get to react to the threatened sect. - * Once we've sent enough to counter the threat, stop sending them. - * - * Not anymore. All units get to react. :) - */ - - if (list) - dtotal = get_dtotal(def, list, 1.0, 1); - else - dtotal = 0; - snxtitem_all(&ni,EF_LAND); - while(nxtitem(&ni,(s_char *)&land) && - (dtotal + new_land * eff < (int)(1.2*(float)ototal))){ - if (!land.lnd_own) - continue; - if (!land.lnd_rad_max) - continue; - if ((land.lnd_x == def->x) && (land.lnd_y == def->y)) - continue; - if (land.lnd_own != def->own) - continue; - if (land.lnd_ship >= 0) - continue; - if (!defense_val(&land)) - continue; + struct nstr_item ni; + struct lndstr land; + struct sctstr sect, dsect; + struct llist *llp; + int dtotal; + int new_land = 0; + double mobcost; + double move_cost; + int supply_state; + int dist; + int radius; + int origx, origy; + double eff = att_combat_eff(def); + s_char *p; + s_char buf[1024]; + + /* + * + * All units that are within their reaction radius and not damaged + * below their morale value now get to react to the threatened sect. + * Once we've sent enough to counter the threat, stop sending them. + * + * Not anymore. All units get to react. :) + */ + + if (list) + dtotal = get_dtotal(def, list, 1.0, 1); + else + dtotal = 0; + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land) && + (dtotal + new_land * eff < (int)(1.2 * (float)ototal))) { + if (!land.lnd_own) + continue; + if (!land.lnd_rad_max) + continue; + if ((land.lnd_x == def->x) && (land.lnd_y == def->y)) + continue; + if (land.lnd_own != def->own) + continue; + if (land.lnd_ship >= 0) + continue; + if (!defense_val(&land)) + continue; /* if (land.lnd_effic <= land.lnd_retreat) continue; */ - if (!lnd_can_attack(&land)) - continue; - - /* Only supplied units can react */ - if (!(supply_state=has_supply(&land))) - continue; - - dist = mapdist(land.lnd_x,land.lnd_y,def->x,def->y); - - getsect(land.lnd_x, land.lnd_y, §); - /* Units on efficient headquarters can react 1 farther */ - if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60)) - radius=land.lnd_rad_max+1; - else - radius=land.lnd_rad_max; - - if (land.lnd_mission == MI_RESERVE) - radius += 2; + if (!lnd_can_attack(&land)) + continue; - if (dist > radius) - continue; + /* Only supplied units can react */ + if (!(supply_state = has_supply(&land))) + continue; - getsect(def->x, def->y, &dsect); - if (!(p = (s_char *)BestLandPath(buf, §, &dsect, &move_cost, MOB_ROAD))) - continue; - - mobcost = land.lnd_effic * 0.01*lchr[(int)land.lnd_type].l_spd; - if (mobcost < 0.01) - mobcost = 0.01; - mobcost = 480.0 / (mobcost + techfact(land.lnd_tech, mobcost)); - mobcost *= (move_cost * 5.0); - - if (land.lnd_mobil < mobcost) - continue; + dist = mapdist(land.lnd_x, land.lnd_y, def->x, def->y); - new_land += defense_val(&land); - - if (!list) /* we are in the "strength" command */ - continue; - - /* move to defending sector */ - land.lnd_mobil -= ldround(mobcost,1); - origx = land.lnd_x; - origy = land.lnd_y; - land.lnd_x = def->x; - land.lnd_y = def->y; - putland(land.lnd_uid,&land); - wu(0,land.lnd_own,"%s reacts to %s.\n", - prland(&land), - xyas(land.lnd_x,land.lnd_y,land.lnd_own)); - - llp = (struct llist *) - malloc(sizeof(struct llist)); - - bzero((s_char *)llp,sizeof(struct llist)); - llp->supplied = supply_state; - llp->x = origx; - llp->y = origy; - llp->lcp = &lchr[(int)land.lnd_type]; - bcopy((s_char *)&land,(s_char *)&llp->land,sizeof(struct lndstr)); - emp_insque(&llp->queue, list); - if (lnd_spyval(&land) > *d_spyp) - *d_spyp = lnd_spyval(&land); - - intelligence_report(player->cnum,&land,a_spy, - "Scouts sight reacting enemy unit:"); - } - return new_land; + getsect(land.lnd_x, land.lnd_y, §); + /* Units on efficient headquarters can react 1 farther */ + if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60)) + radius = land.lnd_rad_max + 1; + else + radius = land.lnd_rad_max; + + if (land.lnd_mission == MI_RESERVE) + radius += 2; + + if (dist > radius) + continue; + + getsect(def->x, def->y, &dsect); + if (! + (p = + (s_char *)BestLandPath(buf, §, &dsect, &move_cost, + MOB_ROAD))) + continue; + + mobcost = land.lnd_effic * 0.01 * lchr[(int)land.lnd_type].l_spd; + if (mobcost < 0.01) + mobcost = 0.01; + mobcost = 480.0 / (mobcost + techfact(land.lnd_tech, mobcost)); + mobcost *= (move_cost * 5.0); + + if (land.lnd_mobil < mobcost) + continue; + + new_land += defense_val(&land); + + if (!list) /* we are in the "strength" command */ + continue; + + /* move to defending sector */ + land.lnd_mobil -= ldround(mobcost, 1); + origx = land.lnd_x; + origy = land.lnd_y; + land.lnd_x = def->x; + land.lnd_y = def->y; + putland(land.lnd_uid, &land); + wu(0, land.lnd_own, "%s reacts to %s.\n", + prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own)); + + llp = (struct llist *) + malloc(sizeof(struct llist)); + + bzero((s_char *)llp, sizeof(struct llist)); + llp->supplied = supply_state; + llp->x = origx; + llp->y = origy; + llp->lcp = &lchr[(int)land.lnd_type]; + bcopy((s_char *)&land, (s_char *)&llp->land, + sizeof(struct lndstr)); + emp_insque(&llp->queue, list); + if (lnd_spyval(&land) > *d_spyp) + *d_spyp = lnd_spyval(&land); + + intelligence_report(player->cnum, &land, a_spy, + "Scouts sight reacting enemy unit:"); + } + return new_land; } /* Pop off shells and fly bombing missions to get your attack multiplier up */ static double -get_osupport(s_char *outs, struct combat *def, int fort_sup, int ship_sup, int land_sup, int plane_sup) +get_osupport(s_char *outs, struct combat *def, int fort_sup, int ship_sup, + int land_sup, int plane_sup) { - double osupport = 1.0; - int dam; - double af, as, au, ap; - - af = as = au = ap = 0.0; - if (fort_sup) { - dam = dd(def->own, player->cnum, def->x, def->y, 0, 0); - af = ((double)dam/100.0); - osupport += af; - } - if (ship_sup){ - dam = sd(def->own, player->cnum, def->x, def->y, 0, 0, 0); + double osupport = 1.0; + int dam; + double af, as, au, ap; + + af = as = au = ap = 0.0; + if (fort_sup) { + dam = dd(def->own, player->cnum, def->x, def->y, 0, 0); + af = ((double)dam / 100.0); + osupport += af; + } + if (ship_sup) { + dam = sd(def->own, player->cnum, def->x, def->y, 0, 0, 0); - as = ((double)dam/100.0); - osupport += as; - } + as = ((double)dam / 100.0); + osupport += as; + } - if (land_sup){ - dam = lnd_support(def->own, player->cnum, def->x, def->y); - au = ((double)dam/100.0); - osupport += au; - } + if (land_sup) { + dam = lnd_support(def->own, player->cnum, def->x, def->y); + au = ((double)dam / 100.0); + osupport += au; + } - if (plane_sup){ - dam = off_support(def->x,def->y,def->own,player->cnum); - ap = (((double)dam)/100.0); - osupport += ap; - } - sprintf(outs,"attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n",af,as,au,ap); - return osupport; + if (plane_sup) { + dam = off_support(def->x, def->y, def->own, player->cnum); + ap = (((double)dam) / 100.0); + osupport += ap; + } + sprintf(outs, "attacker\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n", af, as, au, + ap); + return osupport; } /* Pop off shells and fly bombing missions to get your defense multiplier up */ static double -get_dsupport(s_char *outs, struct emp_qelem *list, struct combat *def, int ototal, int dtotal) +get_dsupport(s_char *outs, struct emp_qelem *list, struct combat *def, + int ototal, int dtotal) { - double dsupport = 1.0; - int dam; - double df, ds, du, dp; - int good = 0; - - df = ds = du = dp = 0.0; - if (dtotal < 0.1 * ototal) { - good = -1; - } else if (dtotal >= 1.2 * ototal) { - good = 1; - } else { - dam = dd(player->cnum, def->own, def->x, def->y, 0, 1); - df = ((double)dam/100.0); - dsupport += df; - - dtotal = get_dtotal(def,list,dsupport,0); - if ( dtotal < 1.2 * ototal) { - dam = sd(player->cnum, def->own, def->x, def->y, 0, 1, 0); - ds = ((double)dam/100.0); - dsupport += ds; - dtotal = get_dtotal(def,list,dsupport,0); - } - if ( dtotal < 1.2 * ototal) { - dam = lnd_support(player->cnum, def->own, def->x, def->y); - du = ((double)dam/100.0); - dsupport += du; - dtotal = get_dtotal(def,list,dsupport,1); - } - if ( dtotal < 1.2 * ototal) { - dam = def_support(def->x,def->y,player->cnum,def->own); - dp = (((double)dam)/100.0); - dsupport += dp; - } + double dsupport = 1.0; + int dam; + double df, ds, du, dp; + int good = 0; + + df = ds = du = dp = 0.0; + if (dtotal < 0.1 * ototal) { + good = -1; + } else if (dtotal >= 1.2 * ototal) { + good = 1; + } else { + dam = dd(player->cnum, def->own, def->x, def->y, 0, 1); + df = ((double)dam / 100.0); + dsupport += df; + + dtotal = get_dtotal(def, list, dsupport, 0); + if (dtotal < 1.2 * ototal) { + dam = sd(player->cnum, def->own, def->x, def->y, 0, 1, 0); + ds = ((double)dam / 100.0); + dsupport += ds; + dtotal = get_dtotal(def, list, dsupport, 0); + } + if (dtotal < 1.2 * ototal) { + dam = lnd_support(player->cnum, def->own, def->x, def->y); + du = ((double)dam / 100.0); + dsupport += du; + dtotal = get_dtotal(def, list, dsupport, 1); + } + if (dtotal < 1.2 * ototal) { + dam = def_support(def->x, def->y, player->cnum, def->own); + dp = (((double)dam) / 100.0); + dsupport += dp; } - if (good) - *outs = '\0'; - else - sprintf(outs,"defender\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n\n",df,ds,du,dp); - if (def->own) { - if (good < 0) - wu(0,def->own,"\nOdds are bad for us...support cancelled.\n\n"); - else if (good > 0) - wu(0,def->own,"\nOdds are good for us...support cancelled.\n\n"); - } - return dsupport; + } + if (good) + *outs = '\0'; + else + sprintf(outs, "defender\t%1.2f\t%1.2f\t%1.2f\t%1.2f\n\n", df, ds, + du, dp); + if (def->own) { + if (good < 0) + wu(0, def->own, + "\nOdds are bad for us...support cancelled.\n\n"); + else if (good > 0) + wu(0, def->own, + "\nOdds are good for us...support cancelled.\n\n"); + } + return dsupport; } /* @@ -1707,83 +1749,87 @@ get_dsupport(s_char *outs, struct emp_qelem *list, struct combat *def, int otota static double get_mine_dsupport(struct combat *def, int a_engineer) { - int mines; - struct sctstr sect; - - getsect(def->x, def->y, §); - - if (sect.sct_oldown != player->cnum){ - mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); - mines = min(mines,20); - if (a_engineer) - mines = ldround(((double)mines/2.0),1); - if (mines > 0){ - if (def->own) - wu(0,def->own,"Defending mines add %1.2f\n", mines * 0.02); - pr("Defending mines add %1.2f\n", mines * 0.02); - return mines * 0.02; - } + int mines; + struct sctstr sect; + + getsect(def->x, def->y, §); + + if (sect.sct_oldown != player->cnum) { + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + mines = min(mines, 20); + if (a_engineer) + mines = ldround(((double)mines / 2.0), 1); + if (mines > 0) { + if (def->own) + wu(0, def->own, "Defending mines add %1.2f\n", + mines * 0.02); + pr("Defending mines add %1.2f\n", mines * 0.02); + return mines * 0.02; } - return 0.0; + } + return 0.0; } /* Get the offensive and defensive support */ int -att_get_support(int combat_mode, int ofort, int oship, int oland, int oplane, struct emp_qelem *olist, struct combat *off, struct emp_qelem *dlist, struct combat *def, double *osupportp, double *dsupportp, int a_engineer) +att_get_support(int combat_mode, int ofort, int oship, int oland, + int oplane, struct emp_qelem *olist, struct combat *off, + struct emp_qelem *dlist, struct combat *def, + double *osupportp, double *dsupportp, int a_engineer) { - int ototal, dtotal; - s_char osupports[512]; - s_char dsupports[512]; - - if (combat_mode == A_PARA) - *osupports = '\0'; - else - *osupportp = get_osupport(osupports, def, - ofort, oship, oland, oplane); - - /* - * I need to put a 1 at the end of the next four total_stren calls - * becauase units & mil may have been damaged by collateral damage or - * neclear warheads from the offensive & defensive support. - */ - - ototal = get_ototal(combat_mode,off,olist,*osupportp,1); - if (att_empty_attack(combat_mode, ototal, def)) - return abort_attack(); - dtotal = get_dtotal(def,dlist,*dsupportp,1); - - /* - * Calculate defensive support. If odds are too good or too bad - * then don't call in support. - */ - - *dsupportp = get_dsupport(dsupports, dlist, def, ototal, dtotal); - ototal = get_ototal(combat_mode,off,olist,*osupportp,1); - if (att_empty_attack(combat_mode, ototal, def)) - return abort_attack(); - - if ((*osupports || *dsupports) && - (*osupportp != 1.0 || *dsupportp != 1.0)) { - pr("\n\t\tsupport values\n"); - pr("\t\tforts\tships\tunits\tplanes\n"); - if (*osupportp != 1.0) - pr("%s", osupports); - if (*dsupportp != 1.0) - pr("%s", dsupports); - if (def->own) { - wu(0,def->own,"\n\t\tsupport values\n"); - wu(0,def->own,"\t\tforts\tships\tunits\tplanes\n"); - if (*osupportp != 1.0) - wu(0, def->own, "%s", osupports); - if (*dsupportp != 1.0) - wu(0, def->own, "%s", dsupports); - } + int ototal, dtotal; + s_char osupports[512]; + s_char dsupports[512]; + + if (combat_mode == A_PARA) + *osupports = '\0'; + else + *osupportp = get_osupport(osupports, def, + ofort, oship, oland, oplane); + + /* + * I need to put a 1 at the end of the next four total_stren calls + * becauase units & mil may have been damaged by collateral damage or + * neclear warheads from the offensive & defensive support. + */ + + ototal = get_ototal(combat_mode, off, olist, *osupportp, 1); + if (att_empty_attack(combat_mode, ototal, def)) + return abort_attack(); + dtotal = get_dtotal(def, dlist, *dsupportp, 1); + + /* + * Calculate defensive support. If odds are too good or too bad + * then don't call in support. + */ + + *dsupportp = get_dsupport(dsupports, dlist, def, ototal, dtotal); + ototal = get_ototal(combat_mode, off, olist, *osupportp, 1); + if (att_empty_attack(combat_mode, ototal, def)) + return abort_attack(); + + if ((*osupports || *dsupports) && + (*osupportp != 1.0 || *dsupportp != 1.0)) { + pr("\n\t\tsupport values\n"); + pr("\t\tforts\tships\tunits\tplanes\n"); + if (*osupportp != 1.0) + pr("%s", osupports); + if (*dsupportp != 1.0) + pr("%s", dsupports); + if (def->own) { + wu(0, def->own, "\n\t\tsupport values\n"); + wu(0, def->own, "\t\tforts\tships\tunits\tplanes\n"); + if (*osupportp != 1.0) + wu(0, def->own, "%s", osupports); + if (*dsupportp != 1.0) + wu(0, def->own, "%s", dsupports); } + } - dtotal = get_dtotal(def,dlist,*dsupportp,1); - if (dtotal && def->type == EF_SECTOR) - *dsupportp += get_mine_dsupport(def, a_engineer); - return 0; + dtotal = get_dtotal(def, dlist, *dsupportp, 1); + if (dtotal && def->type == EF_SECTOR) + *dsupportp += get_mine_dsupport(def, a_engineer); + return 0; } /* How many two-legged bipeds are in this combat force? */ @@ -1791,298 +1837,309 @@ att_get_support(int combat_mode, int ofort, int oship, int oland, int oplane, st static int count_bodies(struct combat *off, struct emp_qelem *list) { - int n; - int bodies = 0; - struct emp_qelem *qp; - struct llist *llp; - - for (n = 0; n <= off->last; ++n) - bodies += off[n].troops; - for (qp=list->q_forw;qp!=list;qp=qp->q_forw) { - llp = (struct llist *)qp; - bodies += total_mil(&llp->land); - } - return bodies; + int n; + int bodies = 0; + struct emp_qelem *qp; + struct llist *llp; + + for (n = 0; n <= off->last; ++n) + bodies += off[n].troops; + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + llp = (struct llist *)qp; + bodies += total_mil(&llp->land); + } + return bodies; } /* This is where the fighting actually occurs. */ int -att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist, double osupport, struct combat *def, struct emp_qelem *dlist, double dsupport) +att_fight(int combat_mode, struct combat *off, struct emp_qelem *olist, + double osupport, struct combat *def, struct emp_qelem *dlist, + double dsupport) { - int success = 0; - int a_cas = 0; /* Casualty counts */ - int d_cas = 0; - int ototal; /* total attacking strength */ - int dtotal; /* total defending strength */ - int a_bodies; /* total attacking mil (incl. mil in units) */ - int d_bodies; /* total defending mil (incl. mil in units) */ - int d_mil; - int a_troops[6]; - int n; - int news_item; - int recalctime; - double odds; - s_char *action; - - ototal = get_ototal(combat_mode,off,olist,osupport, - combat_mode != A_PARA); - dtotal = get_dtotal(def,dlist,dsupport,0); - if (!dtotal) - success = 1; - - a_bodies = count_bodies(off, olist); - d_bodies = count_bodies(def, dlist); - d_mil = def->troops; - for (n=0; n <= off->last; ++n) - if (off[n].type == EF_BAD) - a_troops[n] = 0; - else - a_troops[n] = off[n].troops; + int success = 0; + int a_cas = 0; /* Casualty counts */ + int d_cas = 0; + int ototal; /* total attacking strength */ + int dtotal; /* total defending strength */ + int a_bodies; /* total attacking mil (incl. mil in units) */ + int d_bodies; /* total defending mil (incl. mil in units) */ + int d_mil; + int a_troops[6]; + int n; + int news_item; + int recalctime; + double odds; + s_char *action; + + ototal = get_ototal(combat_mode, off, olist, osupport, + combat_mode != A_PARA); + dtotal = get_dtotal(def, dlist, dsupport, 0); + if (!dtotal) + success = 1; + + a_bodies = count_bodies(off, olist); + d_bodies = count_bodies(def, dlist); + d_mil = def->troops; + for (n = 0; n <= off->last; ++n) + if (off[n].type == EF_BAD) + a_troops[n] = 0; + else + a_troops[n] = off[n].troops; + + /* This switch is required to get the spacing right */ + switch (combat_mode) { + case A_ATTACK: + pr(" Final attack strength: %8d\n", ototal); + break; + case A_ASSAULT: + pr(" Final assault strength: %8d\n", ototal); + break; + case A_PARA: + if (def->sct_type == SCT_MOUNT || + def->sct_type == SCT_WATER || + def->sct_type == SCT_CAPIT || + def->sct_type == SCT_FORTR || def->sct_type == SCT_WASTE) { + pr("You can't air-assault a %s sector!\n", + def->sct_dcp->d_name); + a_cas = a_bodies; + off[0].troops = 0; + ototal = get_ototal(A_PARA, off, olist, osupport, 0); + } + pr(" Final air-assault strength: %8d\n", ototal); + break; + case A_BOARD: + case A_LBOARD: + pr(" Final board strength: %8d\n", ototal); + } + - /* This switch is required to get the spacing right */ + pr(" Final defense strength: %8d\n", dtotal); + odds = att_calcodds(ototal, dtotal); + pr(" Final odds: %8d%%\n", (int)(odds * 100)); + + /* spread the plague */ + if (combat_mode != A_PARA) { + if (!def->plague) + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD) + def->plague |= off[n].plague; + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD) + off[n].plague |= def->plague; + } + att_infect_units(olist, off->plague); + att_infect_units(dlist, def->plague); + + /* Fighting is slightly random. There is always that last little + * effort you see people put in. Or the stray bullet that takes out + * an officer and the rest go into chaos. Things like that. + * Thus, we have added a very slight random factor that will sometimes + * allow the little guy to win. We modify the odds a little + * (either +- 5%) to account for this randomness. We also only + * recalculate the odds every 8-50 casualties, not every cacsualty, + * since a single dead guy normally wouldn't cause a commander to + * rethink his strategies, but 50 dead guys might. */ + odds = odds + (double)((double)((random() % 11) - 5) / 100.0); + if (odds < 0.0) + odds = 0.1; + if (odds > 1.0) + odds = 1.0; + recalctime = 8 + (random() % 43); + while (!success && ototal) { + if (chance(odds)) { + pr("!"); + d_cas += take_casualty(A_DEFEND, def, dlist); + dtotal = get_dtotal(def, dlist, dsupport, 0); + if (!dtotal) + ++success; + } else { + pr("@"); + a_cas += take_casualty(combat_mode, off, olist); + ototal = get_ototal(combat_mode, off, olist, osupport, 0); + } + if (((a_cas + d_cas) % 70) == 69) + pr("\n"); + if (recalctime-- <= 0) { + recalctime = 8 + (random() % 43); + odds = att_calcodds(ototal, dtotal); + odds = odds + (double)((double)((random() % 11) - 5) / 100.0); + if (odds < 0.0) + odds = 0.1; + if (odds > 1.0) + odds = 1.0; + } + } + pr("\n"); + /* update defense mobility & mil */ + if (success) + def->mil = 0; + else { + if (def->type == EF_SECTOR && d_mil && d_cas) { + int tmob; + + /* Make sure we use a positive mobility here */ + tmob = ((def->mob < 0) ? -(def->mob) : (def->mob)); + def->mobcost = + min(20, min(1, tmob - damage(tmob, 100 * d_cas / d_mil))); + } + def->mil = def->troops; + } + + /* update attack mobility & mil */ + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD && off[n].troops < a_troops[n]) { + if (off[n].type == EF_SECTOR && off[n].mil) + off[n].mobcost += + min(20, + min(1, + off[n].mob - damage(off[n].mob, + 100 * (a_troops[n] - + off[n].troops) / + off[n].mil))); + off[n].mil -= a_troops[n] - off[n].troops; + } + + /* update land unit mobility */ + if (d_bodies && d_cas) + lnd_takemob(dlist, (double)d_cas / d_bodies); + if (a_bodies && a_cas) + lnd_takemob(olist, (double)a_cas / a_bodies); + + /* damage attacked sector */ + def->eff = effdamage(def->eff, (d_cas + a_cas) / 10); + + pr("- Casualties -\n Yours: %d\n", a_cas); + pr(" Theirs: %d\n", d_cas); + pr("Papershuffling ... %.1f B.T.U\n", (d_cas + a_cas) * 0.15); + player->btused += (int)((d_cas + a_cas) * 0.015 + 0.5); + + if (success) { switch (combat_mode) { case A_ATTACK: - pr(" Final attack strength: %8d\n", ototal); - break; + news_item = def->own ? N_WON_SECT : N_TOOK_UNOCC; + pr("We have captured %s, sir!\n", prcom(0, def)); + action = "taking"; + break; case A_ASSAULT: - pr(" Final assault strength: %8d\n", ototal); - break; + news_item = def->own ? N_AWON_SECT : N_START_COL; + pr("We have secured a beachhead at %s, sir!\n", prcom(0, def)); + action = "assaulting and taking"; + break; case A_PARA: - if (def->sct_type == SCT_MOUNT || - def->sct_type == SCT_WATER || - def->sct_type == SCT_CAPIT || - def->sct_type == SCT_FORTR || - def->sct_type == SCT_WASTE) { - pr("You can't air-assault a %s sector!\n", - def->sct_dcp->d_name); - a_cas = a_bodies; - off[0].troops = 0; - ototal = get_ototal(A_PARA,off,olist,osupport, 0); - } - pr(" Final air-assault strength: %8d\n", ototal); - break; + news_item = def->own ? N_PWON_SECT : N_PARA_UNOCC; + pr("We have captured %s, sir!\n", prcom(0, def)); + action = "air-assaulting and taking"; + break; case A_BOARD: + news_item = N_BOARD_SHIP; + pr("We have boarded %s, sir!\n", prcom(0, def)); + action = "boarding"; + break; case A_LBOARD: - pr(" Final board strength: %8d\n", ototal); - } - - - pr(" Final defense strength: %8d\n",dtotal); - odds = att_calcodds(ototal,dtotal); - pr(" Final odds: %8d%%\n",(int)(odds*100)); - - /* spread the plague */ - if (combat_mode != A_PARA) { - if (!def->plague) - for (n = 0; n <= off->last; ++n) - if (off[n].type != EF_BAD) - def->plague |= off[n].plague; - for (n = 0; n <= off->last; ++n) - if (off[n].type != EF_BAD) - off[n].plague |= def->plague; - } - att_infect_units(olist, off->plague); - att_infect_units(dlist, def->plague); - - /* Fighting is slightly random. There is always that last little - * effort you see people put in. Or the stray bullet that takes out - * an officer and the rest go into chaos. Things like that. - * Thus, we have added a very slight random factor that will sometimes - * allow the little guy to win. We modify the odds a little - * (either +- 5%) to account for this randomness. We also only - * recalculate the odds every 8-50 casualties, not every cacsualty, - * since a single dead guy normally wouldn't cause a commander to - * rethink his strategies, but 50 dead guys might. */ - odds = odds + (double)((double)((random() % 11) - 5) / 100.0); - if (odds < 0.0) - odds = 0.1; - if (odds > 1.0) - odds = 1.0; - recalctime = 8 + (random() % 43); - while (!success && ototal){ - if (chance(odds)) { - pr("!"); - d_cas += take_casualty(A_DEFEND,def,dlist); - dtotal = get_dtotal(def,dlist,dsupport,0); - if (!dtotal) - ++success; - } else { - pr("@"); - a_cas += take_casualty(combat_mode,off,olist); - ototal = get_ototal(combat_mode,off,olist,osupport,0); - } - if (((a_cas + d_cas) % 70) == 69) - pr("\n"); - if (recalctime-- <= 0) { - recalctime = 8 + (random() % 43); - odds = att_calcodds(ototal,dtotal); - odds = odds + (double)((double)((random() % 11) - 5) / 100.0); - if (odds < 0.0) - odds = 0.1; - if (odds > 1.0) - odds = 1.0; - } - } - pr("\n"); - /* update defense mobility & mil */ - if (success) - def->mil = 0; - else { - if (def->type == EF_SECTOR && d_mil && d_cas) { - int tmob; - - /* Make sure we use a positive mobility here */ - tmob = ((def->mob < 0) ? -(def->mob) : (def->mob)); - def->mobcost = min(20, min(1, tmob - damage(tmob, 100 * d_cas / d_mil))); - } - def->mil = def->troops; - } - - /* update attack mobility & mil */ - for (n=0; n <= off->last; ++n) - if (off[n].type != EF_BAD && off[n].troops < a_troops[n]) { - if (off[n].type == EF_SECTOR && off[n].mil) - off[n].mobcost += min(20,min(1, off[n].mob - damage(off[n].mob, 100 * (a_troops[n] - off[n].troops) / off[n].mil))); - off[n].mil -= a_troops[n] - off[n].troops; - } - - /* update land unit mobility */ - if (d_bodies && d_cas) - lnd_takemob(dlist, (double)d_cas / d_bodies); - if (a_bodies && a_cas) - lnd_takemob(olist, (double)a_cas / a_bodies); - - /* damage attacked sector */ - def->eff = effdamage(def->eff, (d_cas + a_cas)/10); - - pr("- Casualties -\n Yours: %d\n", a_cas); - pr(" Theirs: %d\n", d_cas); - pr("Papershuffling ... %.1f B.T.U\n", (d_cas + a_cas) * 0.15); - player->btused += (int) ((d_cas + a_cas) * 0.015 + 0.5); - - if (success) { - switch (combat_mode) { - case A_ATTACK: - news_item = def->own?N_WON_SECT:N_TOOK_UNOCC; - pr("We have captured %s, sir!\n", prcom(0, def)); - action = "taking"; break; - case A_ASSAULT: - news_item = def->own?N_AWON_SECT:N_START_COL; - pr("We have secured a beachhead at %s, sir!\n", prcom(0, def)); - action = "assaulting and taking"; break; - case A_PARA: - news_item = def->own?N_PWON_SECT:N_PARA_UNOCC; - pr("We have captured %s, sir!\n", prcom(0, def)); - action = "air-assaulting and taking"; break; - case A_BOARD: - news_item = N_BOARD_SHIP; - pr("We have boarded %s, sir!\n", prcom(0, def)); - action = "boarding"; break; - case A_LBOARD: - news_item = N_BOARD_LAND; - pr("We have boarded %s, sir!\n", prcom(0, def)); - action = "boarding"; break; - } - } else { - switch (combat_mode) { - case A_ATTACK: - news_item = N_SCT_LOSE; - pr("You have been defeated!\n"); - action = "attacking"; - break; - case A_ASSAULT: - news_item = N_ALOSE_SCT; - pr("You have been defeated!\n"); - kill_land(olist); - action = "trying to assault"; - break; - case A_PARA: - news_item = N_PLOSE_SCT; - pr("All of your troops were destroyed\n"); - action = "trying to air-assault"; - break; - case A_BOARD: - news_item = N_SHP_LOSE; - pr("You have been repelled\n"); - kill_land(olist); - action = "trying to board"; - break; - case A_LBOARD: - news_item = N_LND_LOSE; - pr("You have been repelled\n"); - kill_land(olist); - action = "trying to board"; - break; - } + news_item = N_BOARD_LAND; + pr("We have boarded %s, sir!\n", prcom(0, def)); + action = "boarding"; + break; } - nreport(player->cnum, news_item, def->own, 1); - if (def->own) { - wu(0, def->own, - "%s (#%d) lost %d troops %s %s\nWe lost %d troops defending\n", - cname(player->cnum), player->cnum, a_cas, - action, - pr_com(0, def, def->own), - d_cas); + } else { + switch (combat_mode) { + case A_ATTACK: + news_item = N_SCT_LOSE; + pr("You have been defeated!\n"); + action = "attacking"; + break; + case A_ASSAULT: + news_item = N_ALOSE_SCT; + pr("You have been defeated!\n"); + kill_land(olist); + action = "trying to assault"; + break; + case A_PARA: + news_item = N_PLOSE_SCT; + pr("All of your troops were destroyed\n"); + action = "trying to air-assault"; + break; + case A_BOARD: + news_item = N_SHP_LOSE; + pr("You have been repelled\n"); + kill_land(olist); + action = "trying to board"; + break; + case A_LBOARD: + news_item = N_LND_LOSE; + pr("You have been repelled\n"); + kill_land(olist); + action = "trying to board"; + break; } + } + nreport(player->cnum, news_item, def->own, 1); + if (def->own) { + wu(0, def->own, + "%s (#%d) lost %d troops %s %s\nWe lost %d troops defending\n", + cname(player->cnum), player->cnum, a_cas, + action, pr_com(0, def, def->own), d_cas); + } - if (opt_SNEAK_ATTACK) { - do_sneak(def, success); - } + if (opt_SNEAK_ATTACK) { + do_sneak(def, success); + } - send_reacting_units_home(def, dlist); + send_reacting_units_home(def, dlist); - /* putland the defending land */ - lnd_put(dlist, 0); - - /* putland the attacking land */ - put_land(olist); + /* putland the defending land */ + lnd_put(dlist, 0); - /* put the victim sector/ship/land */ - if (!success || !take_def(combat_mode, olist, off, def)) - put_combat(def); + /* putland the attacking land */ + put_land(olist); - /* put the attacking sectors/ship */ - for (n = 0; n <= off->last; ++n) - if (off[n].type != EF_BAD) - put_combat(&off[n]); + /* put the victim sector/ship/land */ + if (!success || !take_def(combat_mode, olist, off, def)) + put_combat(def); - if (!success) - return 0; + /* put the attacking sectors/ship */ + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD) + put_combat(&off[n]); - switch (combat_mode) { - case A_ATTACK: - ask_move_in(off, olist, def); - - /* put sectors again to get abandon warnings */ - for (n = 0; n <= off->last; ++n) - if (off[n].type != EF_BAD) - put_combat(&off[n]); - break; - default: - att_move_in_off(combat_mode, off, olist, def); - } - if (def->mil > 0) - pr("%d of your troops now occupy %s\n", def->mil, prcom(0, def)); - return 1; -} + if (!success) + return 0; + + switch (combat_mode) { + case A_ATTACK: + ask_move_in(off, olist, def); + + /* put sectors again to get abandon warnings */ + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD) + put_combat(&off[n]); + break; + default: + att_move_in_off(combat_mode, off, olist, def); + } + if (def->mil > 0) + pr("%d of your troops now occupy %s\n", def->mil, prcom(0, def)); + return 1; +} /* What percentage of the combat forces going head-to-head are we? */ double att_calcodds(int ototal, int dtotal) { - double odds; + double odds; - /* calculate odds */ - if (ototal <= 0) - odds = 0.0; - else if (dtotal <=0) - odds = 1.0; - else - odds = ((double)ototal) / (dtotal + ototal); + /* calculate odds */ + if (ototal <= 0) + odds = 0.0; + else if (dtotal <= 0) + odds = 1.0; + else + odds = ((double)ototal) / (dtotal + ototal); - return odds; + return odds; } /* Here's where the dead soldiers get dragged off the battlefield */ @@ -2090,82 +2147,80 @@ att_calcodds(int ototal, int dtotal) static int take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist) { - int to_take = CASUALTY_LUMP; - int biggest_troops = 0, index = -1; - int n, tot_troops = 0, biggest_mil, cas; - struct emp_qelem *qp, *biggest; - struct llist *llp; - - for (n = 0; n <= off->last; ++n) { - if (off[n].type != EF_BAD) { - tot_troops += off[n].troops; - if (off[n].troops > biggest_troops) { - biggest_troops = off[n].troops; - index = n; - } - } + int to_take = CASUALTY_LUMP; + int biggest_troops = 0, index = -1; + int n, tot_troops = 0, biggest_mil, cas; + struct emp_qelem *qp, *biggest; + struct llist *llp; + + for (n = 0; n <= off->last; ++n) { + if (off[n].type != EF_BAD) { + tot_troops += off[n].troops; + if (off[n].troops > biggest_troops) { + biggest_troops = off[n].troops; + index = n; + } } + } - if (tot_troops) - to_take -= tot_troops; + if (tot_troops) + to_take -= tot_troops; - if (to_take >= 0) { - for(n = 0; n <= off->last; ++n) - if (off[n].type != EF_BAD) - off[n].troops=0; - } else { - /* - * They can all come off mil. We rotate the casualties, - * starting with the sector containing the most mil. - */ - to_take = CASUALTY_LUMP; - if (index < 0) { - pr("ERROR: Tell the deity that you got the 'green librarian' error\n"); - index = 0; + if (to_take >= 0) { + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD) + off[n].troops = 0; + } else { + /* + * They can all come off mil. We rotate the casualties, + * starting with the sector containing the most mil. + */ + to_take = CASUALTY_LUMP; + if (index < 0) { + pr("ERROR: Tell the deity that you got the 'green librarian' error\n"); + index = 0; + } + while (to_take > 0) { + for (n = index; n <= off->last && to_take; ++n) { + if (off[n].type != EF_BAD && off[n].troops > 0) { + --to_take; + --off[n].troops; } - while (to_take > 0) { - for (n = index; n <= off->last && to_take; ++n) { - if (off[n].type != EF_BAD && - off[n].troops > 0) { - --to_take; - --off[n].troops; - } - } - for (n = 0; n < index && to_take; ++n) { - if (off[n].type != EF_BAD && - off[n].troops > 0) { - --to_take; - --off[n].troops; - } - } + } + for (n = 0; n < index && to_take; ++n) { + if (off[n].type != EF_BAD && off[n].troops > 0) { + --to_take; + --off[n].troops; } - return CASUALTY_LUMP; + } } + return CASUALTY_LUMP; + } - if (QEMPTY(olist)) - return (CASUALTY_LUMP - to_take); + if (QEMPTY(olist)) + return (CASUALTY_LUMP - to_take); + + /* + * Need to take some casualties from attacking units + * Procedure: find the biggest unit remaining (in + * terms of mil) and give it the casualties. + */ + biggest = (struct emp_qelem *)0; + biggest_mil = -1; + for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) { + llp = (struct llist *)qp; - /* - * Need to take some casualties from attacking units - * Procedure: find the biggest unit remaining (in - * terms of mil) and give it the casualties. - */ - biggest = (struct emp_qelem *)0; - biggest_mil = -1; - for (qp = olist->q_forw; qp != olist; qp = qp->q_forw){ - llp = (struct llist *)qp; - - if (total_mil(&llp->land) > biggest_mil){ - biggest_mil = total_mil(&llp->land); - biggest = qp; - } + if (total_mil(&llp->land) > biggest_mil) { + biggest_mil = total_mil(&llp->land); + biggest = qp; } - if (biggest == (struct emp_qelem *)0) - return (CASUALTY_LUMP-to_take); + } + if (biggest == (struct emp_qelem *)0) + return (CASUALTY_LUMP - to_take); - llp = (struct llist *)biggest; - cas = lnd_take_casualty(combat_mode,llp,to_take); - return (CASUALTY_LUMP-(to_take-cas)); + llp = (struct llist *)biggest; + cas = lnd_take_casualty(combat_mode, llp, to_take); + return (CASUALTY_LUMP - (to_take - cas)); } /* Send reacting defense units back to where they came from (at no mob cost) */ @@ -2173,22 +2228,21 @@ take_casualty(int combat_mode, struct combat *off, struct emp_qelem *olist) static void send_reacting_units_home(struct combat *def, struct emp_qelem *list) { - struct emp_qelem *qp, *next; - struct llist *llp; - s_char buf[1024]; - - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - if ((llp->land.lnd_x != llp->x) || - (llp->land.lnd_y != llp->y)) { - sprintf(buf, "returns to %s", - xyas(llp->x, llp->y, llp->land.lnd_own)); - llp->land.lnd_x = llp->x; - llp->land.lnd_y = llp->y; - lnd_delete(llp, buf); - } + struct emp_qelem *qp, *next; + struct llist *llp; + s_char buf[1024]; + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + if ((llp->land.lnd_x != llp->x) || (llp->land.lnd_y != llp->y)) { + sprintf(buf, "returns to %s", + xyas(llp->x, llp->y, llp->land.lnd_own)); + llp->land.lnd_x = llp->x; + llp->land.lnd_y = llp->y; + lnd_delete(llp, buf); } + } } /* Check for 0 offense strength. This call will always preceed an abort */ @@ -2196,18 +2250,17 @@ send_reacting_units_home(struct combat *def, struct emp_qelem *list) int att_empty_attack(int combat_mode, int ototal, struct combat *def) { - if (ototal <= 0) { - if (def->own && player->cnum != def->own) { - wu(0, def->own, - "%s (#%d) considered %sing you @%s\n", - cname(player->cnum), player->cnum, - att_mode[combat_mode], - xyas(def->x, def->y, def->own)); - } - pr("No troops for %s...\n", att_mode[combat_mode]); - return 1; - } - return 0; + if (ototal <= 0) { + if (def->own && player->cnum != def->own) { + wu(0, def->own, + "%s (#%d) considered %sing you @%s\n", + cname(player->cnum), player->cnum, + att_mode[combat_mode], xyas(def->x, def->y, def->own)); + } + pr("No troops for %s...\n", att_mode[combat_mode]); + return 1; + } + return 0; } /* @@ -2216,78 +2269,80 @@ att_empty_attack(int combat_mode, int ototal, struct combat *def) */ static int -take_def(int combat_mode, struct emp_qelem *list, struct combat *off, struct combat *def) +take_def(int combat_mode, struct emp_qelem *list, struct combat *off, + struct combat *def) { - int n; - int occuppied = 0; - struct llist *llp, *delete_me = 0; - s_char buf[1024]; - struct sctstr sect; - struct shpstr ship; - struct lndstr land; - - for (n = 0; n <= off->last && !occuppied; ++n) { - if (off[n].type != EF_BAD && - off[n].troops > 0 && - (off[n].type != EF_SECTOR || off[n].mob)) { - ++occuppied; - if (def->type == EF_LAND) { - if (def->lnd_lcp->l_flags & L_SPY) { - continue; - } - } - --(off[n].troops); - --(off[n].mil); - ++def->mil; - pr("1 mil from %s moves %s\n", - prcom(0, off + n), prcom(2, def)); + int n; + int occuppied = 0; + struct llist *llp, *delete_me = 0; + s_char buf[1024]; + struct sctstr sect; + struct shpstr ship; + struct lndstr land; + + for (n = 0; n <= off->last && !occuppied; ++n) { + if (off[n].type != EF_BAD && + off[n].troops > 0 && + (off[n].type != EF_SECTOR || off[n].mob)) { + ++occuppied; + if (def->type == EF_LAND) { + if (def->lnd_lcp->l_flags & L_SPY) { + continue; } + } + --(off[n].troops); + --(off[n].mil); + ++def->mil; + pr("1 mil from %s moves %s\n", + prcom(0, off + n), prcom(2, def)); } - if (!occuppied) { - if (QEMPTY(list)) { - pr("%s left unoccupied\n", prcom(0, def)); - if (def->own) - wu(0, def->own, - "No enemy troops moved %s so you still own it!\n", pr_com(2, def, def->own)); - return 0; - } else { - llp = (struct llist *)list->q_forw; - llp->land.lnd_x = def->x; - llp->land.lnd_y = def->y; - take_move_in_mob(combat_mode, llp, off, def); - if (def->type == EF_SHIP) { - llp->land.lnd_ship = def->shp_uid; - sprintf(buf, "boards %s", prcom(0, def)); - delete_me = llp; - } else { - llp->land.lnd_ship = -1; - sprintf(buf, "moves in to occupy %s", - xyas(def->x, def->y, player->cnum)); - lnd_delete(llp, buf); - } - } + } + if (!occuppied) { + if (QEMPTY(list)) { + pr("%s left unoccupied\n", prcom(0, def)); + if (def->own) + wu(0, def->own, + "No enemy troops moved %s so you still own it!\n", + pr_com(2, def, def->own)); + return 0; + } else { + llp = (struct llist *)list->q_forw; + llp->land.lnd_x = def->x; + llp->land.lnd_y = def->y; + take_move_in_mob(combat_mode, llp, off, def); + if (def->type == EF_SHIP) { + llp->land.lnd_ship = def->shp_uid; + sprintf(buf, "boards %s", prcom(0, def)); + delete_me = llp; + } else { + llp->land.lnd_ship = -1; + sprintf(buf, "moves in to occupy %s", + xyas(def->x, def->y, player->cnum)); + lnd_delete(llp, buf); + } } - put_combat(def); - if (def->type == EF_SECTOR) { - getsect(def->x, def->y, §); - takeover(§, player->cnum); - if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT) - caploss(§, def->own, - "* We have captured %s's capital, sir! *\n"); - putsect(§); - } else if (def->type == EF_SHIP) { - getship(def->shp_uid, &ship); - takeover_ship(&ship, player->cnum, 1); - putship(ship.shp_uid, &ship); - } else if (def->type == EF_LAND) { - getland(def->lnd_uid, &land); - takeover_land(&land, player->cnum, 1); - putland(land.lnd_uid, &land); - } - if (delete_me) - lnd_delete(delete_me, buf); - att_get_combat(def, 0); - return 1; + } + put_combat(def); + if (def->type == EF_SECTOR) { + getsect(def->x, def->y, §); + takeover(§, player->cnum); + if (sect.sct_type == SCT_CAPIT || sect.sct_type == SCT_MOUNT) + caploss(§, def->own, + "* We have captured %s's capital, sir! *\n"); + putsect(§); + } else if (def->type == EF_SHIP) { + getship(def->shp_uid, &ship); + takeover_ship(&ship, player->cnum, 1); + putship(ship.shp_uid, &ship); + } else if (def->type == EF_LAND) { + getland(def->lnd_uid, &land); + takeover_land(&land, player->cnum, 1); + putland(land.lnd_uid, &land); + } + if (delete_me) + lnd_delete(delete_me, buf); + att_get_combat(def, 0); + return 1; } /* @@ -2296,120 +2351,120 @@ take_def(int combat_mode, struct emp_qelem *list, struct combat *off, struct com */ static void -ask_move_in(struct combat *off, struct emp_qelem *olist, struct combat *def) +ask_move_in(struct combat *off, struct emp_qelem *olist, + struct combat *def) { - int n; - struct emp_qelem *qp, *next; - struct llist *llp; - s_char buf[512]; - s_char prompt[512]; - s_char land_answer[1024]; - s_char *answerp; - - for (n = 0; n <= off->last; ++n) - if (off[n].type != EF_BAD && off[n].troops > 0) - if (off[n].mob) { - ask_move_in_off(&off[n], def); - if (player->aborted) - break; - } - - if (QEMPTY(olist)) - return; - bzero(land_answer, sizeof(land_answer)); + int n; + struct emp_qelem *qp, *next; + struct llist *llp; + s_char buf[512]; + s_char prompt[512]; + s_char land_answer[1024]; + s_char *answerp; + + for (n = 0; n <= off->last; ++n) + if (off[n].type != EF_BAD && off[n].troops > 0) + if (off[n].mob) { + ask_move_in_off(&off[n], def); + if (player->aborted) + break; + } + + if (QEMPTY(olist)) + return; + bzero(land_answer, sizeof(land_answer)); + for (qp = olist->q_forw; qp != olist; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + answerp = &land_answer[(int)llp->land.lnd_army]; + if (player->aborted || att_get_combat(def, 0) < 0) + *answerp = 'N'; + if (*answerp == 'Y') + continue; + if (*answerp != 'N') { + if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0)) + continue; + sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ", + prland(&llp->land), + llp->land.lnd_army == ' ' ? '~' : llp->land.lnd_army, + llp->land.lnd_effic); + *answerp = att_prompt(prompt, llp->land.lnd_army); + if (player->aborted || att_get_combat(def, 0) < 0) + *answerp = 'N'; + if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0)) + continue; + } + if (*answerp == 'y' || *answerp == 'Y') + continue; + sprintf(buf, "stays in %s", + xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum)); + lnd_delete(llp, buf); + } + if (QEMPTY(olist)) + return; + if (att_get_combat(def, 0) < 0) { for (qp = olist->q_forw; qp != olist; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - answerp = &land_answer[(int)llp->land.lnd_army]; - if (player->aborted || - att_get_combat(def, 0) < 0) - *answerp = 'N'; - if (*answerp == 'Y') - continue; - if (*answerp != 'N') { - if (!get_land(A_ATTACK, def,llp->land.lnd_uid, llp, 0)) - continue; - sprintf(prompt, "Move in with %s (%c %d%%) [ynYNq?] ", - prland(&llp->land), - llp->land.lnd_army==' '?'~':llp->land.lnd_army, - llp->land.lnd_effic); - *answerp = att_prompt(prompt, llp->land.lnd_army); - if (player->aborted || - att_get_combat(def, 0) < 0) - *answerp = 'N'; - if (!get_land(A_ATTACK,def, llp->land.lnd_uid, llp, 0)) - continue; - } - if (*answerp == 'y' || *answerp == 'Y') - continue; - sprintf(buf, "stays in %s", - xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum)); - lnd_delete(llp, buf); + next = qp->q_forw; + llp = (struct llist *)qp; + if (!get_land(A_ATTACK, def, llp->land.lnd_uid, llp, 0)) + continue; + sprintf(buf, "stays in %s", + xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum)); + lnd_delete(llp, buf); } - if (QEMPTY(olist)) - return; - if (att_get_combat(def, 0) < 0) { - for (qp = olist->q_forw; qp != olist; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - if (!get_land(A_ATTACK,def,llp->land.lnd_uid, llp, 0)) - continue; - sprintf(buf, "stays in %s", - xyas(llp->land.lnd_x, llp->land.lnd_y, player->cnum)); - lnd_delete(llp, buf); - } - return; - } - if (opt_INTERDICT_ATT) - lnd_interdict(olist, def->x, def->y, player->cnum); - move_in_land(A_ATTACK, off, olist, def); + return; + } + if (opt_INTERDICT_ATT) + lnd_interdict(olist, def->x, def->y, player->cnum); + move_in_land(A_ATTACK, off, olist, def); } /* Move offensive land units to the conquered sector or ship */ static void -move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist, struct combat *def) +move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist, + struct combat *def) { - struct emp_qelem *qp, *next; - struct llist *llp; - s_char buf[512]; + struct emp_qelem *qp, *next; + struct llist *llp; + s_char buf[512]; - if (QEMPTY(olist)) - return; - for (qp = olist->q_forw; qp != olist; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - if (!get_land(combat_mode, def,llp->land.lnd_uid, llp, 0)) - continue; - take_move_in_mob(combat_mode, llp, off, def); - llp->land.lnd_x = def->x; - llp->land.lnd_y = def->y; - if (def->type == EF_SHIP) - llp->land.lnd_ship = def->shp_uid; - else - llp->land.lnd_ship = -1; - } - if (QEMPTY(olist)) - return; - if (def->type == EF_SECTOR) { - if (opt_INTERDICT_ATT) { - lnd_sweep(olist, 0, 0, def->own); - lnd_check_mines(olist); - } - sprintf(buf, "now occupies %s", prcom(0, def)); - } else { - sprintf(buf, "boards %s", prcom(0, def)); - } - if (QEMPTY(olist)) - return; - for (qp = olist->q_forw; qp != olist; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; - lnd_print(llp, buf); + if (QEMPTY(olist)) + return; + for (qp = olist->q_forw; qp != olist; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + if (!get_land(combat_mode, def, llp->land.lnd_uid, llp, 0)) + continue; + take_move_in_mob(combat_mode, llp, off, def); + llp->land.lnd_x = def->x; + llp->land.lnd_y = def->y; + if (def->type == EF_SHIP) + llp->land.lnd_ship = def->shp_uid; + else + llp->land.lnd_ship = -1; + } + if (QEMPTY(olist)) + return; + if (def->type == EF_SECTOR) { + if (opt_INTERDICT_ATT) { + lnd_sweep(olist, 0, 0, def->own); + lnd_check_mines(olist); } - if (QEMPTY(olist)) - return; - lnd_put(olist, 0); + sprintf(buf, "now occupies %s", prcom(0, def)); + } else { + sprintf(buf, "boards %s", prcom(0, def)); + } + if (QEMPTY(olist)) + return; + for (qp = olist->q_forw; qp != olist; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; + lnd_print(llp, buf); + } + if (QEMPTY(olist)) + return; + lnd_put(olist, 0); } /* @@ -2418,63 +2473,65 @@ move_in_land(int combat_mode, struct combat *off, struct emp_qelem *olist, struc */ void -att_move_in_off(int combat_mode, struct combat *off, struct emp_qelem *olist, struct combat *def) +att_move_in_off(int combat_mode, struct combat *off, + struct emp_qelem *olist, struct combat *def) { - struct sctstr sect; - struct shpstr ship; - struct lndstr land; - int defvec[I_MAX+1]; - int shipvec[I_MAX+1]; - int troops; - int n, lunchbox = 0; - s_char *thing; - - move_in_land(combat_mode, off, olist, def); - - for (n = 0; n <= off->last; ++n) { - if (off[n].type == EF_BAD || !off[n].troops) - continue; - troops = off[n].troops; - off[n].troops = 0; - off[n].mil -= troops; - def->mil += troops; - put_combat(off + n); - if (combat_mode == A_ASSAULT) { - getship(off[n].shp_uid, &ship); - getvec(VT_ITEM, shipvec, (s_char *)&ship, EF_SHIP); - lunchbox += (int)((troops + 1) * shipvec[I_FOOD] / - (shipvec[I_MILIT] + troops + shipvec[I_CIVIL] + 0.5)); - shipvec[I_FOOD] -= lunchbox; - putvec(VT_ITEM, shipvec, (s_char *)&ship, EF_SHIP); - putship(ship.shp_uid, &ship); - } + struct sctstr sect; + struct shpstr ship; + struct lndstr land; + int defvec[I_MAX + 1]; + int shipvec[I_MAX + 1]; + int troops; + int n, lunchbox = 0; + s_char *thing; + + move_in_land(combat_mode, off, olist, def); + + for (n = 0; n <= off->last; ++n) { + if (off[n].type == EF_BAD || !off[n].troops) + continue; + troops = off[n].troops; + off[n].troops = 0; + off[n].mil -= troops; + def->mil += troops; + put_combat(off + n); + if (combat_mode == A_ASSAULT) { + getship(off[n].shp_uid, &ship); + getvec(VT_ITEM, shipvec, (s_char *)&ship, EF_SHIP); + lunchbox += (int)((troops + 1) * shipvec[I_FOOD] / + (shipvec[I_MILIT] + troops + + shipvec[I_CIVIL] + 0.5)); + shipvec[I_FOOD] -= lunchbox; + putvec(VT_ITEM, shipvec, (s_char *)&ship, EF_SHIP); + putship(ship.shp_uid, &ship); } - put_combat(def); - if (!lunchbox) - return; + } + put_combat(def); + if (!lunchbox) + return; - if (def->type == EF_SECTOR) { - getsect(def->x, def->y, §); - thing = (s_char *)§ - } else if (def->type == EF_SHIP) { - getship(def->shp_uid, &ship); - thing = (s_char *)&ship; - } else if (def->type == EF_LAND) { - getship(def->lnd_uid, &land); - thing = (s_char *)&land; - } else { - pr("Please tell the deity that you got the 'hungry mole' error\n"); - return; - } - getvec(VT_ITEM, defvec, thing, def->type); - defvec[I_FOOD] += lunchbox; - putvec(VT_ITEM, defvec, thing, def->type); - if (def->type == EF_SECTOR) - putsect(§); - else if (def->type == EF_SHIP) - putship(ship.shp_uid, &ship); - else - putland(land.lnd_uid, &land); + if (def->type == EF_SECTOR) { + getsect(def->x, def->y, §); + thing = (s_char *)§ + } else if (def->type == EF_SHIP) { + getship(def->shp_uid, &ship); + thing = (s_char *)&ship; + } else if (def->type == EF_LAND) { + getship(def->lnd_uid, &land); + thing = (s_char *)&land; + } else { + pr("Please tell the deity that you got the 'hungry mole' error\n"); + return; + } + getvec(VT_ITEM, defvec, thing, def->type); + defvec[I_FOOD] += lunchbox; + putvec(VT_ITEM, defvec, thing, def->type); + if (def->type == EF_SECTOR) + putsect(§); + else if (def->type == EF_SHIP) + putship(ship.shp_uid, &ship); + else + putland(land.lnd_uid, &land); } @@ -2483,141 +2540,141 @@ att_move_in_off(int combat_mode, struct combat *off, struct emp_qelem *olist, st static void ask_move_in_off(struct combat *off, struct combat *def) { - int mob_support; - int num_mil, dam = 0, left; - double d, weight; - s_char prompt[512]; - s_char buf[1024]; - s_char *p; - - if (att_get_combat(off, 0) <= 0) - return; - if (att_get_combat(def, 0) < 0) - return; - if (off->own != player->cnum) - return; - d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD); - if ((mob_support = min(off->troops, (int)(off->mob / d))) <= 0) - return; - sprintf(prompt,"How many mil to move in from %s (%d max)? ", xyas(off->x, off->y, player->cnum), mob_support); - if (!(p = getstring(prompt, buf)) || - !*p || - (num_mil = atoi(p)) <= 0) { - num_mil = 0; - return; - } + int mob_support; + int num_mil, dam = 0, left; + double d, weight; + s_char prompt[512]; + s_char buf[1024]; + s_char *p; + + if (att_get_combat(off, 0) <= 0) + return; + if (att_get_combat(def, 0) < 0) + return; + if (off->own != player->cnum) + return; + d = sector_mcost(getsectp(def->x, def->y), MOB_ROAD); + if ((mob_support = min(off->troops, (int)(off->mob / d))) <= 0) + return; + sprintf(prompt, "How many mil to move in from %s (%d max)? ", + xyas(off->x, off->y, player->cnum), mob_support); + if (!(p = getstring(prompt, buf)) || !*p || (num_mil = atoi(p)) <= 0) { + num_mil = 0; + return; + } /* Make sure we don't move in more than we can support mobility-wise */ - if (num_mil > mob_support) - num_mil = mob_support; - if (att_get_combat(off, 0) <= 0) - return; - if (att_get_combat(def, 0) < 0) - return; - if ((num_mil = min(off->troops, num_mil)) <= 0) { - pr("No mil moved in from %s\n", - xyas(off->x, off->y, player->cnum)); - return; + if (num_mil > mob_support) + num_mil = mob_support; + if (att_get_combat(off, 0) <= 0) + return; + if (att_get_combat(def, 0) < 0) + return; + if ((num_mil = min(off->troops, num_mil)) <= 0) { + pr("No mil moved in from %s\n", + xyas(off->x, off->y, player->cnum)); + return; + } + mob_support = max(1, (int)(num_mil * d)); + off->mob -= min(off->mob, mob_support); + off->mil -= num_mil; + off->troops -= num_mil; + put_combat(off); + left = num_mil; + weight = num_mil * ichr[I_MILIT].i_lbs; + if (opt_INTERDICT_ATT && chance(weight / 200.0)) { + if (chance(weight / 100.0)) + dam += + ground_interdict(def->x, def->y, player->cnum, "military"); + dam += check_lmines(def->x, def->y, weight); + } + + if (dam) { + left = commdamage(num_mil, dam, V_MILIT); + if (left < num_mil) { + if (left) { + pr("%d of the mil you were moving were destroyed!\nOnly %d mil made it to %s\n", num_mil - left, left, xyas(def->x, def->y, player->cnum)); + } else { + pr("All of the mil you were moving were destroyed!\n"); + } } - mob_support = max(1,(int)(num_mil * d)); - off->mob -= min(off->mob, mob_support); - off->mil -= num_mil; - off->troops -= num_mil; - put_combat(off); - left = num_mil; - weight = num_mil * ichr[I_MILIT].i_lbs; - if (opt_INTERDICT_ATT && chance(weight / 200.0)) { - if (chance(weight/100.0)) - dam += ground_interdict(def->x, def->y, player->cnum, "military"); - dam += check_lmines(def->x, def->y, weight); - } - - if (dam) { - left = commdamage(num_mil, dam, V_MILIT); - if (left < num_mil) { - if (left) { - pr("%d of the mil you were moving were destroyed!\nOnly %d mil made it to %s\n", - num_mil - left, - left, - xyas(def->x, def->y, player->cnum)); - } else { - pr("All of the mil you were moving were destroyed!\n"); - } - } - /* maybe got nuked */ - if (att_get_combat(def, 0) < 0) - return; - } - def->mil += left; - put_combat(def); + /* maybe got nuked */ + if (att_get_combat(def, 0) < 0) + return; + } + def->mil += left; + put_combat(def); } /* Charge land units for moving into a sector or onto a ship */ static void -take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off, struct combat *def) +take_move_in_mob(int combat_mode, struct llist *llp, struct combat *off, + struct combat *def) { - extern int etu_per_update; - extern float land_mob_scale; - int mobcost; - int new; - - switch (combat_mode) { - case A_ATTACK: - mobcost = lnd_mobcost(&llp->land, getsectp(def->x, def->y), MOB_NONE); - new = llp->land.lnd_mobil - mobcost; - if (new < -127) - new = -127; - llp->land.lnd_mobil = new; - break; - case A_ASSAULT: - if (off->shp_mcp->m_flags & M_LAND) { - if (llp->lcp->l_flags & L_MARINE) - llp->land.lnd_mobil -= ((float)etu_per_update *land_mob_scale*0.5); - else - llp->land.lnd_mobil -= ((float)etu_per_update - *land_mob_scale); - } else { - if (llp->lcp->l_flags & L_MARINE) - llp->land.lnd_mobil = 0; - else - llp->land.lnd_mobil = (((float)etu_per_update - *land_mob_scale)*(-1)); - } - break; - case A_BOARD: - /* I arbitrarily chose the numbers 10 and 40 below -KHS */ - if (llp->lcp->l_flags & L_MARINE) - llp->land.lnd_mobil -= 10; - else - llp->land.lnd_mobil -= 40; - break; - } + extern int etu_per_update; + extern float land_mob_scale; + int mobcost; + int new; + + switch (combat_mode) { + case A_ATTACK: + mobcost = + lnd_mobcost(&llp->land, getsectp(def->x, def->y), MOB_NONE); + new = llp->land.lnd_mobil - mobcost; + if (new < -127) + new = -127; + llp->land.lnd_mobil = new; + break; + case A_ASSAULT: + if (off->shp_mcp->m_flags & M_LAND) { + if (llp->lcp->l_flags & L_MARINE) + llp->land.lnd_mobil -= + ((float)etu_per_update * land_mob_scale * 0.5); + else + llp->land.lnd_mobil -= ((float)etu_per_update + * land_mob_scale); + } else { + if (llp->lcp->l_flags & L_MARINE) + llp->land.lnd_mobil = 0; + else + llp->land.lnd_mobil = (((float)etu_per_update + * land_mob_scale) * (-1)); + } + break; + case A_BOARD: + /* I arbitrarily chose the numbers 10 and 40 below -KHS */ + if (llp->lcp->l_flags & L_MARINE) + llp->land.lnd_mobil -= 10; + else + llp->land.lnd_mobil -= 40; + break; + } } static void free_list(struct emp_qelem *list) { - register struct emp_qelem *qp, *next; + register struct emp_qelem *qp, *next; - if (!list || QEMPTY(list)) - return; + if (!list || QEMPTY(list)) + return; - qp = list->q_forw; - while(qp != list) { - next = qp->q_forw; - emp_remque(qp); - free(qp); - qp = next; - } + qp = list->q_forw; + while (qp != list) { + next = qp->q_forw; + emp_remque(qp); + free(qp); + qp = next; + } } int att_free_lists(struct emp_qelem *olist, struct emp_qelem *dlist) { - free_list(olist); - free_list(dlist); - return RET_OK; + free_list(olist); + free_list(dlist); + return RET_OK; } /* @@ -2634,7 +2691,7 @@ sector_strength(struct sctstr *sp) d = 1.0; if (sp->sct_type == SCT_MOUNT) - d = 2.0; + d = 2.0; d = d + ((double)(dchr[sp->sct_type].d_dstr - d) * ((double)sp->sct_defense / 100.0)); diff --git a/src/lib/subs/bigmap.c b/src/lib/subs/bigmap.c index ea3b55539..1e297e152 100644 --- a/src/lib/subs/bigmap.c +++ b/src/lib/subs/bigmap.c @@ -44,62 +44,64 @@ */ static int -do_map_set(natid cnum, s_char *map, coord x, coord y, s_char t, int force, int sync); + do_map_set(natid cnum, s_char *map, coord x, coord y, s_char t, int force, int sync); int map_set(natid cnum, coord x, coord y, s_char t, int only_bmap) { - int set = 0; + int set = 0; - if (!t) - return 0; - if (!only_bmap) - set |= do_map_set(cnum, ef_ptr(EF_MAP,cnum), x,y, t, 0, 0); - set |= do_map_set(cnum, ef_ptr(EF_BMAP,cnum),x,y, t, only_bmap > 1, 1); + if (!t) + return 0; + if (!only_bmap) + set |= do_map_set(cnum, ef_ptr(EF_MAP, cnum), x, y, t, 0, 0); + set |= + do_map_set(cnum, ef_ptr(EF_BMAP, cnum), x, y, t, only_bmap > 1, 1); - return set; + return set; } static int -do_map_set(natid cnum, s_char *map, coord x, coord y, s_char t, int force, int sync) +do_map_set(natid cnum, s_char *map, coord x, coord y, s_char t, int force, + int sync) { - int id; - s_char ot; + int id; + s_char ot; - if ((id = sctoff(x, y)) < 0) - return 0; + if ((id = sctoff(x, y)) < 0) + return 0; - if (((map[id] == 'x') || (map[id] == 'X')) && !force) - return 0; + if (((map[id] == 'x') || (map[id] == 'X')) && !force) + return 0; - ot = map[id]; - if (t == '?') { - switch (map[id]) { - case '.': - case '-': - case ' ': - case 0: - map[id] = t; - break; - default: - break; - } - } else { - map[id] = t; + ot = map[id]; + if (t == '?') { + switch (map[id]) { + case '.': + case '-': + case ' ': + case 0: + map[id] = t; + break; + default: + break; } - return 1; + } else { + map[id] = t; + } + return 1; } void writebmap(natid cnum) { - ef_write(EF_BMAP, cnum, ef_ptr(EF_BMAP,cnum)); + ef_write(EF_BMAP, cnum, ef_ptr(EF_BMAP, cnum)); } void writemap(natid cnum) { - ef_write(EF_MAP, cnum, ef_ptr(EF_MAP,cnum)); - ef_write(EF_BMAP, cnum, ef_ptr(EF_BMAP,cnum)); + ef_write(EF_MAP, cnum, ef_ptr(EF_MAP, cnum)); + ef_write(EF_BMAP, cnum, ef_ptr(EF_BMAP, cnum)); } diff --git a/src/lib/subs/border.c b/src/lib/subs/border.c index 4dbb2b478..2046959e3 100644 --- a/src/lib/subs/border.c +++ b/src/lib/subs/border.c @@ -40,59 +40,59 @@ void border(struct range *rp, s_char *prefstr, s_char *sep) - - /* prefixes each line */ - /* separates the numbers */ + + /* prefixes each line */ + /* separates the numbers */ { - register int posi; - register int n; - register int x; - - if ((WORLD_X / 2) >= 100) { - if (rp->lx + rp->width > 99 || rp->hx - rp->width < -99) { - /* - * hundreds - */ - pr(prefstr); - for (x=rp->lx, n=0; n < rp->width; n++, x++) { - if (x >= WORLD_X/2) - x -= WORLD_X; - pr(sep); - if (x < 0 && x > -100) { - pr("-"); - } else { - posi = (x < 0 ? -x : x) / 100; - pr("%d", posi % 10); - } - } - pr("\n"); - } - } - /* - * tens - */ - pr(prefstr); - for (x=rp->lx, n=0; n < rp->width; n++, x++) { - if (x >= WORLD_X/2) - x -= WORLD_X; + register int posi; + register int n; + register int x; + + if ((WORLD_X / 2) >= 100) { + if (rp->lx + rp->width > 99 || rp->hx - rp->width < -99) { + /* + * hundreds + */ + pr(prefstr); + for (x = rp->lx, n = 0; n < rp->width; n++, x++) { + if (x >= WORLD_X / 2) + x -= WORLD_X; pr(sep); - if (x < 0 && x > -10) { - pr("-"); + if (x < 0 && x > -100) { + pr("-"); } else { - posi = (x < 0 ? -x : x) / 10; - pr("%d", posi % 10); + posi = (x < 0 ? -x : x) / 100; + pr("%d", posi % 10); } + } + pr("\n"); } - pr("\n"); - /* - * units... - */ - pr(prefstr); - for (x=rp->lx, n=0; n < rp->width; n++, x++) { - if (x >= WORLD_X/2) - x -= WORLD_X; - posi = (x < 0 ? -x : x); - pr("%s%d", sep, posi % 10); + } + /* + * tens + */ + pr(prefstr); + for (x = rp->lx, n = 0; n < rp->width; n++, x++) { + if (x >= WORLD_X / 2) + x -= WORLD_X; + pr(sep); + if (x < 0 && x > -10) { + pr("-"); + } else { + posi = (x < 0 ? -x : x) / 10; + pr("%d", posi % 10); } - pr("\n"); + } + pr("\n"); + /* + * units... + */ + pr(prefstr); + for (x = rp->lx, n = 0; n < rp->width; n++, x++) { + if (x >= WORLD_X / 2) + x -= WORLD_X; + posi = (x < 0 ? -x : x); + pr("%s%d", sep, posi % 10); + } + pr("\n"); } diff --git a/src/lib/subs/bsanct.c b/src/lib/subs/bsanct.c index f784091bd..d9d06960b 100644 --- a/src/lib/subs/bsanct.c +++ b/src/lib/subs/bsanct.c @@ -47,32 +47,32 @@ void bsanct(void) { - register int count; - struct sctstr s; - struct nstr_sect nstr; + register int count; + struct sctstr s; + struct nstr_sect nstr; - if (player->god) - return; - count = 0; - snxtsct(&nstr, "*"); - while (nxtsct(&nstr, &s)) { - if (!player->owner) - continue; - if (s.sct_type != SCT_SANCT) - continue; - pr("%s is no longer a sanctuary.\n", - xyas(s.sct_x, s.sct_y, player->cnum)); - if (s.sct_effic == 100) { - s.sct_type = SCT_CAPIT; - s.sct_newtype = SCT_CAPIT; - } else { - s.sct_type = SCT_HIWAY; - s.sct_newtype = SCT_HIWAY; - } - time(&s.sct_access); - (void) putsect(&s); - count++; + if (player->god) + return; + count = 0; + snxtsct(&nstr, "*"); + while (nxtsct(&nstr, &s)) { + if (!player->owner) + continue; + if (s.sct_type != SCT_SANCT) + continue; + pr("%s is no longer a sanctuary.\n", + xyas(s.sct_x, s.sct_y, player->cnum)); + if (s.sct_effic == 100) { + s.sct_type = SCT_CAPIT; + s.sct_newtype = SCT_CAPIT; + } else { + s.sct_type = SCT_HIWAY; + s.sct_newtype = SCT_HIWAY; } - if (count > 0) - nreport(player->cnum, N_BROKE_SANCT, 0, 1); + time(&s.sct_access); + (void)putsect(&s); + count++; + } + if (count > 0) + nreport(player->cnum, N_BROKE_SANCT, 0, 1); } diff --git a/src/lib/subs/caploss.c b/src/lib/subs/caploss.c index 9f8d2e808..fb18e76f3 100644 --- a/src/lib/subs/caploss.c +++ b/src/lib/subs/caploss.c @@ -49,81 +49,73 @@ void caploss(struct sctstr *sp, natid coun, s_char *msg) { - struct natstr *natp; - struct lonstr loan; - struct comstr comm; - long lose; - long gain; - struct sctstr sect; - int n; - int loan_num = 0; - int comm_num = 0; + struct natstr *natp; + struct lonstr loan; + struct comstr comm; + long lose; + long gain; + struct sctstr sect; + int n; + int loan_num = 0; + int comm_num = 0; - if (coun == 0) return; - natp = getnatp(coun); - if ((xrel(natp,natp->nat_xcap) != xrel(natp,sp->sct_x)) || - (yrel(natp,natp->nat_ycap) != yrel(natp,sp->sct_y))) - return; - if (coun == player->cnum) { - player->nstat &= ~CAP; - return; - } - /* Ok, has the country owner reset their capital yet after it was last sacked? */ - if (natp->nat_flags & NF_SACKED) - return; /* No, so not really the capital yet, so return */ - pr(msg, natp->nat_cnam); - gain = lose = natp->nat_money / 2; - if (lose < 3000) - lose = 3000; - n = roll(6); - getsect(sp->sct_x + diroff[n][0], - sp->sct_y + diroff[n][1], - §); - natp->nat_xcap = sect.sct_x; - natp->nat_ycap = sect.sct_y; - natp->nat_money -= lose; - /* Your capital has now been sacked, no more sacking until you reset it */ - natp->nat_flags |= NF_SACKED; - putnat(natp); - wu(0, coun, - "* %s just sacked your capital! *\n", - cname(player->cnum)); - - if (gain >= 0) { - gain = (0.2 + 0.8 * (sp->sct_effic/100.0)) * gain; - player->dolcost -= gain; - } else - gain = 0; - wu(0, coun, - "You lost $%d and they gained $%d\n", - lose, gain); - wu(0, coun, - "Your capital has been moved to %s. You must use 'capital' to reset it.\n", - xyas(natp->nat_xcap, natp->nat_ycap, coun)); - wu(0, 0, "%s just took %s's capital and gained $%d\n", - cname(player->cnum), cname(coun), - -(int)(player->dolcost)); - if (opt_LOANS) { - for (loan_num = 0; getloan(loan_num, &loan); loan_num++) { - if (loan.l_ldur != 0 && loan.l_loner == coun) { - loan.l_loner = player->cnum; - putloan(loan_num, &loan); - pr("Loan %d has been transfered over to you\n", - loan_num); - } + if (coun == 0) + return; + natp = getnatp(coun); + if ((xrel(natp, natp->nat_xcap) != xrel(natp, sp->sct_x)) || + (yrel(natp, natp->nat_ycap) != yrel(natp, sp->sct_y))) + return; + if (coun == player->cnum) { + player->nstat &= ~CAP; + return; + } + /* Ok, has the country owner reset their capital yet after it was last sacked? */ + if (natp->nat_flags & NF_SACKED) + return; /* No, so not really the capital yet, so return */ + pr(msg, natp->nat_cnam); + gain = lose = natp->nat_money / 2; + if (lose < 3000) + lose = 3000; + n = roll(6); + getsect(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1], §); + natp->nat_xcap = sect.sct_x; + natp->nat_ycap = sect.sct_y; + natp->nat_money -= lose; + /* Your capital has now been sacked, no more sacking until you reset it */ + natp->nat_flags |= NF_SACKED; + putnat(natp); + wu(0, coun, "* %s just sacked your capital! *\n", cname(player->cnum)); + + if (gain >= 0) { + gain = (0.2 + 0.8 * (sp->sct_effic / 100.0)) * gain; + player->dolcost -= gain; + } else + gain = 0; + wu(0, coun, "You lost $%d and they gained $%d\n", lose, gain); + wu(0, coun, + "Your capital has been moved to %s. You must use 'capital' to reset it.\n", + xyas(natp->nat_xcap, natp->nat_ycap, coun)); + wu(0, 0, "%s just took %s's capital and gained $%d\n", + cname(player->cnum), cname(coun), -(int)(player->dolcost)); + if (opt_LOANS) { + for (loan_num = 0; getloan(loan_num, &loan); loan_num++) { + if (loan.l_ldur != 0 && loan.l_loner == coun) { + loan.l_loner = player->cnum; + putloan(loan_num, &loan); + pr("Loan %d has been transfered over to you\n", loan_num); } } - if (opt_MARKET) { - for (comm_num = 0; getcomm(comm_num, &comm); comm_num++) { - if (comm.com_owner == coun) { - if (comm.com_owner == comm.com_maxbidder) - comm.com_maxbidder = player->cnum; - comm.com_owner = player->cnum; - putcomm(comm_num, &comm); - pr("You now own commodity #%d.\n", - comm_num); - } + } + if (opt_MARKET) { + for (comm_num = 0; getcomm(comm_num, &comm); comm_num++) { + if (comm.com_owner == coun) { + if (comm.com_owner == comm.com_maxbidder) + comm.com_maxbidder = player->cnum; + comm.com_owner = player->cnum; + putcomm(comm_num, &comm); + pr("You now own commodity #%d.\n", comm_num); } } - nreport(player->cnum, N_SACK_CAP, coun, 1); + } + nreport(player->cnum, N_SACK_CAP, coun, 1); } diff --git a/src/lib/subs/chkmoney.c b/src/lib/subs/chkmoney.c index fa8bb8209..8ff622e97 100644 --- a/src/lib/subs/chkmoney.c +++ b/src/lib/subs/chkmoney.c @@ -38,39 +38,43 @@ int chkmoney(long int cost, long int cash, s_char *argp) { - s_char buf[1024]; - s_char *p; + s_char buf[1024]; + s_char *p; - if (cash > 0 && cost > cash/2) { - pr("This operation will cost you $%d, and you only have $%d.\n", cost, cash); - if (cost > cash) { - pr("You will be broke with $%d if you proceed with this command.\n", cash - cost); - } - p = getstarg(argp, "Are you sure that you want to do this? ", buf); - if (p == 0 || *p != 'y') - return RET_SYN; + if (cash > 0 && cost > cash / 2) { + pr("This operation will cost you $%d, and you only have $%d.\n", + cost, cash); + if (cost > cash) { + pr("You will be broke with $%d if you proceed with this command.\n", cash - cost); } - return 0; + p = getstarg(argp, "Are you sure that you want to do this? ", buf); + if (p == 0 || *p != 'y') + return RET_SYN; + } + return 0; } int -check_cost(int looping, int cost, long int cash, int *warnedp, s_char *argp) +check_cost(int looping, int cost, long int cash, int *warnedp, + s_char *argp) { - s_char buf[1024]; - s_char *p; + s_char buf[1024]; + s_char *p; - if (looping && cash > 0 && player->dolcost + cost > cash && *warnedp < 2) { - *warnedp = 2; - pr("You will go broke! (it will cost $%d and you only have $%d)\n", cost, cash - (long)player->dolcost); - p = getstarg(argp, "Are you sure you wish to continue? ", buf); - if (p == 0 || *p != 'y') - return 1; - } - player->dolcost += cost; - if (looping && cash > 0 && player->dolcost > cash/2 && *warnedp < 1) { - *warnedp = 1; - pr("WARNING. You have just spent over half of your money.\n"); - pr("You started with $%d and now you only have $%d left\n", cash, cash - (long)player->dolcost); - } - return 0; + if (looping && cash > 0 && player->dolcost + cost > cash + && *warnedp < 2) { + *warnedp = 2; + pr("You will go broke! (it will cost $%d and you only have $%d)\n", cost, cash - (long)player->dolcost); + p = getstarg(argp, "Are you sure you wish to continue? ", buf); + if (p == 0 || *p != 'y') + return 1; + } + player->dolcost += cost; + if (looping && cash > 0 && player->dolcost > cash / 2 && *warnedp < 1) { + *warnedp = 1; + pr("WARNING. You have just spent over half of your money.\n"); + pr("You started with $%d and now you only have $%d left\n", cash, + cash - (long)player->dolcost); + } + return 0; } diff --git a/src/lib/subs/cnumb.c b/src/lib/subs/cnumb.c index 044e4adbe..1dc96ddbd 100644 --- a/src/lib/subs/cnumb.c +++ b/src/lib/subs/cnumb.c @@ -40,27 +40,27 @@ int cnumb(s_char *cntry) { - register s_char *ncp; - register s_char *cp; - register struct natstr *natp; - int bcount; - natid best; - natid cn; + register s_char *ncp; + register s_char *cp; + register struct natstr *natp; + int bcount; + natid best; + natid cn; - bcount = 0; - for (cn = 0; cn < MAXNOC; cn++) { - if ((natp = getnatp(cn)) == 0) - break; - ncp = natp->nat_cnam; - for (cp=cntry; *cp == *ncp; cp++, ncp++) { - if (*cp == 0) - return cn; - } - if (cp > cntry && *cp == 0) { - best = cn; - bcount++; - } + bcount = 0; + for (cn = 0; cn < MAXNOC; cn++) { + if ((natp = getnatp(cn)) == 0) + break; + ncp = natp->nat_cnam; + for (cp = cntry; *cp == *ncp; cp++, ncp++) { + if (*cp == 0) + return cn; } - /* can only have 1 match or not successful */ - return bcount == 1 ? (int) best : -1; + if (cp > cntry && *cp == 0) { + best = cn; + bcount++; + } + } + /* can only have 1 match or not successful */ + return bcount == 1 ? (int)best : -1; } diff --git a/src/lib/subs/comsub.c b/src/lib/subs/comsub.c index ba35fe11d..9cbc790ee 100644 --- a/src/lib/subs/comsub.c +++ b/src/lib/subs/comsub.c @@ -42,19 +42,21 @@ #include #endif -int commf; +int commf; -int c_comm[MAXNOC][I_MAX+1]; -float c_price[MAXNOC][I_MAX+1]; -float c_mult[MAXNOC][MAXNOC]; +int c_comm[MAXNOC][I_MAX + 1]; +float c_price[MAXNOC][I_MAX + 1]; +float c_mult[MAXNOC][MAXNOC]; #if !defined(_WIN32) -static struct iovec commvec[3] = { - { (caddr_t)c_comm, sizeof(c_comm) }, - { (caddr_t)c_price, sizeof(c_price) }, - { (caddr_t)c_mult, sizeof(c_mult) } +static struct iovec commvec[3] = { + {(caddr_t)c_comm, sizeof(c_comm)} + , + {(caddr_t)c_price, sizeof(c_price)} + , + {(caddr_t)c_mult, sizeof(c_mult)} }; -static int nvec = sizeof(commvec)/sizeof(struct iovec); +static int nvec = sizeof(commvec) / sizeof(struct iovec); #endif /* @@ -70,72 +72,73 @@ static int nvec = sizeof(commvec)/sizeof(struct iovec); int commread(void) { - int n; + int n; - (void) lseek(commf, (off_t) 0, 0); + (void)lseek(commf, (off_t) 0, 0); #if !defined(_WIN32) - if ((n = readv(commf, commvec, nvec)) != - sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) { - logerror("commread: readv returns %d", n); - return -1; - } + if ((n = readv(commf, commvec, nvec)) != + sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) { + logerror("commread: readv returns %d", n); + return -1; + } #else - if ((n = read(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) { - logerror("commread: read returns %d, not %d", n, sizeof(c_comm)); - return -1; + if ((n = read(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) { + logerror("commread: read returns %d, not %d", n, sizeof(c_comm)); + return -1; } - if ((n = read(commf, c_price, sizeof(c_price))) != sizeof(c_price)) { - logerror("commread: read returns %d, not %d", n, sizeof(c_price)); - return -1; + if ((n = read(commf, c_price, sizeof(c_price))) != sizeof(c_price)) { + logerror("commread: read returns %d, not %d", n, sizeof(c_price)); + return -1; } - if ((n = read(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) { - logerror("commread: read returns %d, not %d", n, sizeof(c_mult)); - return -1; + if ((n = read(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) { + logerror("commread: read returns %d, not %d", n, sizeof(c_mult)); + return -1; } #endif - return 0; + return 0; } int commwrite(void) { #if defined(_WIN32) - int n; + int n; #endif - (void) lseek(commf, (off_t) 0, 0); + (void)lseek(commf, (off_t) 0, 0); #if !defined(_WIN32) - if (writev(commf, commvec, nvec) != - sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) { - logerror("commwrite: writev failed"); - return -1; - } + if (writev(commf, commvec, nvec) != + sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) { + logerror("commwrite: writev failed"); + return -1; + } #else - if ((n = write(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) { - logerror("commwrite: write returns %d, not %d", n, sizeof(c_comm)); - return -1; + if ((n = write(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) { + logerror("commwrite: write returns %d, not %d", n, sizeof(c_comm)); + return -1; } - if ((n = write(commf, c_price, sizeof(c_price))) != sizeof(c_price)) { - logerror("commwrite: write returns %d, not %d", n, sizeof(c_price)); - return -1; + if ((n = write(commf, c_price, sizeof(c_price))) != sizeof(c_price)) { + logerror("commwrite: write returns %d, not %d", n, + sizeof(c_price)); + return -1; } - if ((n = write(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) { - logerror("commwrite: write returns %d, not %d", n, sizeof(c_mult)); - return -1; + if ((n = write(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) { + logerror("commwrite: write returns %d, not %d", n, sizeof(c_mult)); + return -1; } #endif - return 0; + return 0; } int commlock(void) { - return file_lock(commf); + return file_lock(commf); } int communlock(void) { - return file_unlock(commf); + return file_unlock(commf); } /* @@ -144,30 +147,30 @@ communlock(void) int commamt(natid trader, int product, float *priceval) { - *priceval = c_price[trader][product] * c_mult[trader][player->cnum]; - return c_comm[trader][product]; + *priceval = c_price[trader][product] * c_mult[trader][player->cnum]; + return c_comm[trader][product]; } void commset(natid trader, int product, int amt) { - c_comm[trader][product] += amt; + c_comm[trader][product] += amt; } double multread(natid trader, natid tradee) { - return c_mult[trader][tradee]; + return c_mult[trader][tradee]; } void multset(natid tradee, float newmult) { - c_mult[player->cnum][tradee] = newmult; + c_mult[player->cnum][tradee] = newmult; } void commprice(int product, float *newprice) { - c_price[player->cnum][product] = *newprice; + c_price[player->cnum][product] = *newprice; } diff --git a/src/lib/subs/control.c b/src/lib/subs/control.c index 5edb9ba29..9835fbbd6 100644 --- a/src/lib/subs/control.c +++ b/src/lib/subs/control.c @@ -53,20 +53,20 @@ int military_control(struct sctstr *sp) { - int tot_mil=0; - struct nstr_item ni; - struct lndstr land; + int tot_mil = 0; + struct nstr_item ni; + struct lndstr land; - if (sp->sct_oldown != sp->sct_own){ - snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == sp->sct_own) - tot_mil += total_mil(&land); - } - if ((getvar(V_MILIT, (s_char *)sp, EF_SECTOR)+tot_mil) * 10 - < getvar(V_CIVIL, (s_char *)sp, EF_SECTOR)) - return 0; + if (sp->sct_oldown != sp->sct_own) { + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == sp->sct_own) + tot_mil += total_mil(&land); } + if ((getvar(V_MILIT, (s_char *)sp, EF_SECTOR) + tot_mil) * 10 + < getvar(V_CIVIL, (s_char *)sp, EF_SECTOR)) + return 0; + } - return 1; + return 1; } diff --git a/src/lib/subs/detonate.c b/src/lib/subs/detonate.c index 4c58387ef..c244071ea 100644 --- a/src/lib/subs/detonate.c +++ b/src/lib/subs/detonate.c @@ -52,270 +52,265 @@ void kaboom(int x, int y, int rad, natid cn); int detonate(struct plnstr *pp, int x, int y) { - int nuketype = pp->pln_nuketype; - natid bombown = pp->pln_own; - int airburst = (pp->pln_flags & PLN_AIRBURST); - struct nchrstr *ncp; - struct plnstr plane; - struct sctstr sect; - struct shpstr ship; - struct lndstr land; - struct nukstr nuke; - s_char *bp; - s_char buf[128]; - s_char buf2[128]; - natid own; - int type; - int damage; - int fallout; - int rad; - struct nstr_sect ns; - struct nstr_item ni; - int issea = 0; - int retval; + int nuketype = pp->pln_nuketype; + natid bombown = pp->pln_own; + int airburst = (pp->pln_flags & PLN_AIRBURST); + struct nchrstr *ncp; + struct plnstr plane; + struct sctstr sect; + struct shpstr ship; + struct lndstr land; + struct nukstr nuke; + s_char *bp; + s_char buf[128]; + s_char buf2[128]; + natid own; + int type; + int damage; + int fallout; + int rad; + struct nstr_sect ns; + struct nstr_item ni; + int issea = 0; + int retval; - pp->pln_nuketype = -1; - getsect(x,y,§); - if (sect.sct_type == SCT_WATER) - issea = 1; - ncp = &nchr[nuketype]; - kaboom(x, y, ncp->n_blast, bombown); - rad = ncp->n_blast; - if (!airburst) - rad = rad * 2 / 3; - snxtsct_dist(&ns, x, y, rad); - while (nxtsct(&ns, §)) { - /* Nukes falling on water affect only 1 sector */ - if ((sect.sct_x != x) && issea) - continue; - if ((sect.sct_y != y) && issea) - continue; - own = sect.sct_own; - type = sect.sct_type; - if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0) - continue; - if (type == SCT_SANCT) { - mpr(bombown,"bounced off %s\n", xyas(ns.x, ns.y, bombown)); - if(own != 0) - mpr(own, "%s nuclear device bounced off %s\n", - cname(bombown), xyas(ns.x, ns.y, bombown)); - nreport(bombown, N_NUKE, own, 1); - continue; - } - if (opt_FALLOUT) - fallout = getvar(V_FALLOUT,(s_char *)§,EF_SECTOR); - sect_damage(§, damage, 0); - if (sect.sct_x == x && sect.sct_y == y) - retval = damage; - if (opt_FALLOUT) { - if (opt_NEUTRON && (ncp->n_flags & N_NEUT)) - fallout += damage*30; - else - fallout += damage*3; - putvar(V_FALLOUT,fallout,(s_char *)§,EF_SECTOR); - } - if (damage > 100) { - makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); - sect.sct_oldown = 0; - sect.sct_own = 0; - if (type == SCT_WATER || type == SCT_BSPAN || - type == SCT_BTOWER) { - bp = "left nothing but water in %s\n"; - if (type != SCT_WATER) { - sect.sct_newtype = SCT_WATER; - sect.sct_type = SCT_WATER; - } - } else { - sect.sct_newtype = SCT_WASTE; - sect.sct_type = SCT_WASTE; - bp = "turned %s into a radioactive wasteland\n"; + pp->pln_nuketype = -1; + getsect(x, y, §); + if (sect.sct_type == SCT_WATER) + issea = 1; + ncp = &nchr[nuketype]; + kaboom(x, y, ncp->n_blast, bombown); + rad = ncp->n_blast; + if (!airburst) + rad = rad * 2 / 3; + snxtsct_dist(&ns, x, y, rad); + while (nxtsct(&ns, §)) { + /* Nukes falling on water affect only 1 sector */ + if ((sect.sct_x != x) && issea) + continue; + if ((sect.sct_y != y) && issea) + continue; + own = sect.sct_own; + type = sect.sct_type; + if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0) + continue; + if (type == SCT_SANCT) { + mpr(bombown, "bounced off %s\n", xyas(ns.x, ns.y, bombown)); + if (own != 0) + mpr(own, "%s nuclear device bounced off %s\n", + cname(bombown), xyas(ns.x, ns.y, bombown)); + nreport(bombown, N_NUKE, own, 1); + continue; + } + if (opt_FALLOUT) + fallout = getvar(V_FALLOUT, (s_char *)§, EF_SECTOR); + sect_damage(§, damage, 0); + if (sect.sct_x == x && sect.sct_y == y) + retval = damage; + if (opt_FALLOUT) { + if (opt_NEUTRON && (ncp->n_flags & N_NEUT)) + fallout += damage * 30; + else + fallout += damage * 3; + putvar(V_FALLOUT, fallout, (s_char *)§, EF_SECTOR); + } + if (damage > 100) { + makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y); + sect.sct_oldown = 0; + sect.sct_own = 0; + if (type == SCT_WATER || type == SCT_BSPAN || + type == SCT_BTOWER) { + bp = "left nothing but water in %s\n"; + if (type != SCT_WATER) { + sect.sct_newtype = SCT_WATER; + sect.sct_type = SCT_WATER; } } else { - sprintf(buf, "did %d%%%% damage in %%s\n", damage); - bp = buf; - } - if ((type == SCT_CAPIT || type == SCT_MOUNT) && damage >= 100) - caploss(§, own, "\n%s lost its capital!\n\n"); - (void) putsect(§); - if (type != SCT_WATER) - nreport(bombown, N_NUKE, own, 1); - mpr(bombown,bp, xyas(ns.x, ns.y, bombown)); - if (own != bombown && own != 0) { - (void) sprintf(buf2, bp, xyas(ns.x, ns.y, own)); - mpr(own, "%s nuclear device %s\n", - cname(bombown), buf2); + sect.sct_newtype = SCT_WASTE; + sect.sct_type = SCT_WASTE; + bp = "turned %s into a radioactive wasteland\n"; } + } else { + sprintf(buf, "did %d%%%% damage in %%s\n", damage); + bp = buf; } - snxtitem_dist(&ni, EF_PLANE, x, y, rad); - while (nxtitem(&ni, (caddr_t)&plane)) { - /* Nukes falling on water affect only 1 sector */ - if ((plane.pln_x != x) && issea) - continue; - if ((plane.pln_y != y) && issea) - continue; - if ((own = plane.pln_own) == 0) - continue; - if ((plane.pln_flags & PLN_LAUNCHED) && (airburst != 2)) - continue; - damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden; - if (damage <= 0) - continue; - if (plane.pln_ship >= 0) { - /* Are we on a sub? */ - getship(plane.pln_ship, &ship); - - if (mchr[(int)ship.shp_type].m_flags & M_SUB) { - struct sctstr sect1; - - /* Should we damage this sub? */ - getsect(ship.shp_x,ship.shp_y,§1); - - if (sect1.sct_type == SCT_BSPAN || - sect1.sct_type == SCT_BTOWER || - sect1.sct_type == SCT_WATER) { - /* Ok, we're not in a harbor or trapped - inland. Now, did we get pasted - directly? */ - if (ship.shp_x != x || ship.shp_y != y) { - /* Nope, so don't mess with it */ - continue; - } - } - } - } - planedamage(&plane, damage); - if (own == bombown) { - mpr(bombown,"%s at %s reports %d%% damage\n", - prplane(&plane), - xyas(plane.pln_x, plane.pln_y, own), - damage); - } else { - if(own != 0) - mpr(own, - "%s nuclear device did %d%% damage to %s at %s\n", - cname(bombown), damage, - prplane(&plane), - xyas(plane.pln_x, plane.pln_y, own)); - } - putplane(ni.cur, &plane); + if ((type == SCT_CAPIT || type == SCT_MOUNT) && damage >= 100) + caploss(§, own, "\n%s lost its capital!\n\n"); + (void)putsect(§); + if (type != SCT_WATER) + nreport(bombown, N_NUKE, own, 1); + mpr(bombown, bp, xyas(ns.x, ns.y, bombown)); + if (own != bombown && own != 0) { + (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own)); + mpr(own, "%s nuclear device %s\n", cname(bombown), buf2); } - snxtitem_dist(&ni, EF_LAND, x, y, rad); - while (nxtitem(&ni, (caddr_t)&land)) { - /* Nukes falling on water affect only 1 sector */ - if ((land.lnd_x != x) && issea) - continue; - if ((land.lnd_y != y) && issea) - continue; - if ((own = land.lnd_own) == 0) - continue; - if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) - continue; + } + snxtitem_dist(&ni, EF_PLANE, x, y, rad); + while (nxtitem(&ni, (caddr_t)&plane)) { + /* Nukes falling on water affect only 1 sector */ + if ((plane.pln_x != x) && issea) + continue; + if ((plane.pln_y != y) && issea) + continue; + if ((own = plane.pln_own) == 0) + continue; + if ((plane.pln_flags & PLN_LAUNCHED) && (airburst != 2)) + continue; + damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden; + if (damage <= 0) + continue; + if (plane.pln_ship >= 0) { + /* Are we on a sub? */ + getship(plane.pln_ship, &ship); + + if (mchr[(int)ship.shp_type].m_flags & M_SUB) { + struct sctstr sect1; - if (land.lnd_ship >= 0) { - /* Are we on a sub? */ - getship(land.lnd_ship, &ship); + /* Should we damage this sub? */ + getsect(ship.shp_x, ship.shp_y, §1); - if (mchr[(int)ship.shp_type].m_flags & M_SUB) { - struct sctstr sect1; - - /* Should we damage this sub? */ - getsect(ship.shp_x,ship.shp_y,§1); - - if (sect1.sct_type == SCT_BSPAN || - sect1.sct_type == SCT_BTOWER || - sect1.sct_type == SCT_WATER) { - /* Ok, we're not in a harbor or trapped - inland. Now, did we get pasted - directly? */ - if (ship.shp_x != x || ship.shp_y != y) { + if (sect1.sct_type == SCT_BSPAN || + sect1.sct_type == SCT_BTOWER || + sect1.sct_type == SCT_WATER) { + /* Ok, we're not in a harbor or trapped + inland. Now, did we get pasted + directly? */ + if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; - } } - } } - land_damage(&land, damage); - if (own == bombown) { - mpr(bombown,"%s at %s reports %d%% damage\n", - prland(&land), - xyas(land.lnd_x, land.lnd_y, own), damage); - } else { - if(own != 0) - mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", - cname(bombown), damage, - prland(&land), - xyas(land.lnd_x, land.lnd_y, own)); - } - putland(land.lnd_uid, &land); + } } - snxtitem_dist(&ni, EF_SHIP, x, y, rad); - while (nxtitem(&ni, (caddr_t)&ship)) { - /* Nukes falling on water affect only 1 sector */ - if ((ship.shp_x != x) && issea) - continue; - if ((ship.shp_y != y) && issea) - continue; - if ((own = ship.shp_own) == 0) - continue; - if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) - continue; - if (mchr[(int)ship.shp_type].m_flags & M_SUB) { - struct sctstr sect1; + planedamage(&plane, damage); + if (own == bombown) { + mpr(bombown, "%s at %s reports %d%% damage\n", + prplane(&plane), + xyas(plane.pln_x, plane.pln_y, own), damage); + } else { + if (own != 0) + mpr(own, + "%s nuclear device did %d%% damage to %s at %s\n", + cname(bombown), damage, + prplane(&plane), xyas(plane.pln_x, plane.pln_y, own)); + } + putplane(ni.cur, &plane); + } + snxtitem_dist(&ni, EF_LAND, x, y, rad); + while (nxtitem(&ni, (caddr_t)&land)) { + /* Nukes falling on water affect only 1 sector */ + if ((land.lnd_x != x) && issea) + continue; + if ((land.lnd_y != y) && issea) + continue; + if ((own = land.lnd_own) == 0) + continue; + if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) + continue; - /* Should we damage this sub? */ - getsect(ship.shp_x,ship.shp_y,§1); - - if (sect1.sct_type == SCT_BSPAN || - sect1.sct_type == SCT_BTOWER || - sect1.sct_type == SCT_WATER) { + if (land.lnd_ship >= 0) { + /* Are we on a sub? */ + getship(land.lnd_ship, &ship); + + if (mchr[(int)ship.shp_type].m_flags & M_SUB) { + struct sctstr sect1; + + /* Should we damage this sub? */ + getsect(ship.shp_x, ship.shp_y, §1); + + if (sect1.sct_type == SCT_BSPAN || + sect1.sct_type == SCT_BTOWER || + sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { - /* Nope, so don't mess with it */ - continue; + /* Nope, so don't mess with it */ + continue; } - } - } - ship_damage(&ship, damage); - if (own == bombown) { - mpr(bombown,"%s at %s reports %d%% damage\n", - prship(&ship), - xyas(ship.shp_x, ship.shp_y, own), damage); - } else { - if(own != 0) - mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", - cname(bombown), damage, prship(&ship), - xyas(ship.shp_x, ship.shp_y, own)); } - putship(ship.shp_uid, &ship); + } } - snxtitem_dist(&ni, EF_NUKE, x, y, rad); - while (nxtitem(&ni, (caddr_t)&nuke)) { - /* Nukes falling on water affect only 1 sector */ - if ((nuke.nuk_x != x) && issea) - continue; - if ((nuke.nuk_y != y) && issea) - continue; - if ((own = nuke.nuk_own) == 0) - continue; - if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) - continue; - if (roll(100) >= damage) - continue; - makelost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x, nuke.nuk_y); - nuke.nuk_own = 0; - if (own == bombown) { - mpr(bombown,"nuclear stockpile #%d at %s destroyed\n", - ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own)); - } else { - if(own != 0) - mpr(own, "nuclear stockpile #%d at %s destroyed\n", - ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own)); + land_damage(&land, damage); + if (own == bombown) { + mpr(bombown, "%s at %s reports %d%% damage\n", + prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage); + } else { + if (own != 0) + mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", + cname(bombown), damage, + prland(&land), xyas(land.lnd_x, land.lnd_y, own)); + } + putland(land.lnd_uid, &land); + } + snxtitem_dist(&ni, EF_SHIP, x, y, rad); + while (nxtitem(&ni, (caddr_t)&ship)) { + /* Nukes falling on water affect only 1 sector */ + if ((ship.shp_x != x) && issea) + continue; + if ((ship.shp_y != y) && issea) + continue; + if ((own = ship.shp_own) == 0) + continue; + if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) + continue; + if (mchr[(int)ship.shp_type].m_flags & M_SUB) { + struct sctstr sect1; + + /* Should we damage this sub? */ + getsect(ship.shp_x, ship.shp_y, §1); + + if (sect1.sct_type == SCT_BSPAN || + sect1.sct_type == SCT_BTOWER || + sect1.sct_type == SCT_WATER) { + /* Ok, we're not in a harbor or trapped + inland. Now, did we get pasted + directly? */ + if (ship.shp_x != x || ship.shp_y != y) { + /* Nope, so don't mess with it */ + continue; } - putnuke(ni.cur, &nuke); + } + } + ship_damage(&ship, damage); + if (own == bombown) { + mpr(bombown, "%s at %s reports %d%% damage\n", + prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage); + } else { + if (own != 0) + mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", + cname(bombown), damage, prship(&ship), + xyas(ship.shp_x, ship.shp_y, own)); + } + putship(ship.shp_uid, &ship); + } + snxtitem_dist(&ni, EF_NUKE, x, y, rad); + while (nxtitem(&ni, (caddr_t)&nuke)) { + /* Nukes falling on water affect only 1 sector */ + if ((nuke.nuk_x != x) && issea) + continue; + if ((nuke.nuk_y != y) && issea) + continue; + if ((own = nuke.nuk_own) == 0) + continue; + if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) + continue; + if (roll(100) >= damage) + continue; + makelost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x, + nuke.nuk_y); + nuke.nuk_own = 0; + if (own == bombown) { + mpr(bombown, "nuclear stockpile #%d at %s destroyed\n", + ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own)); + } else { + if (own != 0) + mpr(own, "nuclear stockpile #%d at %s destroyed\n", + ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own)); } - return retval; + putnuke(ni.cur, &nuke); + } + return retval; } @@ -325,8 +320,8 @@ detonate(struct plnstr *pp, int x, int y) void kaboom(int x, int y, int rad, natid cn) { - mpr(cn,"\n\nK A B "); - while (rad-- > 0) - mpr(cn,"O O "); - mpr(cn,"M ! in %s\n\n", xyas(x, y, cn)); + mpr(cn, "\n\nK A B "); + while (rad-- > 0) + mpr(cn, "O O "); + mpr(cn, "M ! in %s\n\n", xyas(x, y, cn)); } diff --git a/src/lib/subs/disloan.c b/src/lib/subs/disloan.c index 62d90c54d..c567bf72c 100644 --- a/src/lib/subs/disloan.c +++ b/src/lib/subs/disloan.c @@ -53,63 +53,63 @@ int disloan(int n, register struct lonstr *loan) { - time_t now; - time_t due; - time_t lastpaydate; - time_t normaltime; - time_t doubletime; - time_t accept; - double rate; - double owe; + time_t now; + time_t due; + time_t lastpaydate; + time_t normaltime; + time_t doubletime; + time_t accept; + double rate; + double owe; - if (loan->l_status == LS_FREE) - return 0; - if (loan->l_ldur == 0) - return 0; - if (loan->l_loner != player->cnum && loan->l_lonee != player->cnum) - return 0; - (void) time(&now); - pr("\nLoan #%d from %s to", n, cname(loan->l_loner)); - pr(" %s\n", cname(loan->l_lonee)); - if (loan->l_status == LS_PROPOSED) { - pr("(proposed) principal=$%d interest rate=%d%%", - loan->l_amtdue, loan->l_irate); - pr(" duration(days)=%d\n", loan->l_ldur); - if (loan->l_duedate < now) { - loan->l_status = LS_FREE; - putloan(n, loan); - pr("This offer has expired\n"); - return 0; - } - accept = loan->l_lastpay + loan->l_ldur * SECS_PER_DAY; - pr("Loan must be accepted by %s", ctime(&accept)); - return 1; + if (loan->l_status == LS_FREE) + return 0; + if (loan->l_ldur == 0) + return 0; + if (loan->l_loner != player->cnum && loan->l_lonee != player->cnum) + return 0; + (void)time(&now); + pr("\nLoan #%d from %s to", n, cname(loan->l_loner)); + pr(" %s\n", cname(loan->l_lonee)); + if (loan->l_status == LS_PROPOSED) { + pr("(proposed) principal=$%d interest rate=%d%%", + loan->l_amtdue, loan->l_irate); + pr(" duration(days)=%d\n", loan->l_ldur); + if (loan->l_duedate < now) { + loan->l_status = LS_FREE; + putloan(n, loan); + pr("This offer has expired\n"); + return 0; } - due = loan->l_duedate; - lastpaydate = loan->l_lastpay; - if (now < due) { - normaltime = now - lastpaydate; - doubletime = 0; - } - if (lastpaydate < due && due < now) { - normaltime = due - lastpaydate; - doubletime = now - due; - } - if (due < lastpaydate) { - normaltime = 0; - doubletime = now - lastpaydate; - } - rate = ((double)loan->l_irate / 100.0) / (loan->l_ldur * SECS_PER_DAY); - owe = ((double) loan->l_amtdue * - (((double) normaltime * rate + 1.0) + - ((double) doubletime * rate * 2.0))) + 0.5; - pr("Amount paid to date $%d\n", loan->l_amtpaid); - pr("Amount due (if paid now) $%.2f", owe); - if (doubletime == 0) { - pr(" (if paid on due date) $%.2f\n", - loan->l_amtdue * ((due - lastpaydate) * rate + 1.0)); - pr("Due date is %s", ctime(&loan->l_duedate)); - } else - pr(" ** In Arrears **\n"); + accept = loan->l_lastpay + loan->l_ldur * SECS_PER_DAY; + pr("Loan must be accepted by %s", ctime(&accept)); return 1; + } + due = loan->l_duedate; + lastpaydate = loan->l_lastpay; + if (now < due) { + normaltime = now - lastpaydate; + doubletime = 0; + } + if (lastpaydate < due && due < now) { + normaltime = due - lastpaydate; + doubletime = now - due; + } + if (due < lastpaydate) { + normaltime = 0; + doubletime = now - lastpaydate; + } + rate = ((double)loan->l_irate / 100.0) / (loan->l_ldur * SECS_PER_DAY); + owe = ((double)loan->l_amtdue * + (((double)normaltime * rate + 1.0) + + ((double)doubletime * rate * 2.0))) + 0.5; + pr("Amount paid to date $%d\n", loan->l_amtpaid); + pr("Amount due (if paid now) $%.2f", owe); + if (doubletime == 0) { + pr(" (if paid on due date) $%.2f\n", + loan->l_amtdue * ((due - lastpaydate) * rate + 1.0)); + pr("Due date is %s", ctime(&loan->l_duedate)); + } else + pr(" ** In Arrears **\n"); + return 1; } diff --git a/src/lib/subs/distrea.c b/src/lib/subs/distrea.c index 87489a454..2ee977021 100644 --- a/src/lib/subs/distrea.c +++ b/src/lib/subs/distrea.c @@ -42,53 +42,53 @@ int distrea(int n, register struct trtstr *tp) { - register int i; - int acond; - int bcond; - int cond; - time_t now; + register int i; + int acond; + int bcond; + int cond; + time_t now; - if (tp->trt_status == TS_FREE) - return 0; - if (tp->trt_cna != player->cnum && - tp->trt_cnb != player->cnum && !player->god) - return 0; - (void) time(&now); - if (now > tp->trt_exp) { - if (!ef_lock(EF_TREATY)) { - pr("Can't lock treaty file; get help!\n"); - return 0; - } - tp->trt_status = TS_FREE; - if (!puttre(n, tp)) { - pr("Couldn't save treaty; get help!\n"); - (void) ef_unlock(EF_TREATY); - return 0; - } - (void) ef_unlock(EF_TREATY); - pr("Treaty #%d expired %s", n, ctime(&tp->trt_exp)); - return 0; + if (tp->trt_status == TS_FREE) + return 0; + if (tp->trt_cna != player->cnum && + tp->trt_cnb != player->cnum && !player->god) + return 0; + (void)time(&now); + if (now > tp->trt_exp) { + if (!ef_lock(EF_TREATY)) { + pr("Can't lock treaty file; get help!\n"); + return 0; } - pr("\n * * * Empire Treaty #%d * * *\n", n); - if (tp->trt_status == TS_PROPOSED) - pr("(proposed)\n"); - pr("between %s and ", cname(tp->trt_cna)); - pr("%s expires %s", cname(tp->trt_cnb), ctime(&tp->trt_exp)); - pr("%24.24s terms", cname(tp->trt_cna)); - pr(" - %s terms\n", cname(tp->trt_cnb)); - for (i = 0; 0 != (cond = tchr[i].t_cond); i++) { - acond = tp->trt_acond & cond; - bcond = tp->trt_bcond & cond; - if (acond | bcond) { - if (acond) - pr("%30s", tchr[i].t_name); - else - pr("%30s", ""); - if (bcond) - pr(" - %s\n", tchr[i].t_name); - else - pr(" -\n"); - } + tp->trt_status = TS_FREE; + if (!puttre(n, tp)) { + pr("Couldn't save treaty; get help!\n"); + (void)ef_unlock(EF_TREATY); + return 0; } - return 1; + (void)ef_unlock(EF_TREATY); + pr("Treaty #%d expired %s", n, ctime(&tp->trt_exp)); + return 0; + } + pr("\n * * * Empire Treaty #%d * * *\n", n); + if (tp->trt_status == TS_PROPOSED) + pr("(proposed)\n"); + pr("between %s and ", cname(tp->trt_cna)); + pr("%s expires %s", cname(tp->trt_cnb), ctime(&tp->trt_exp)); + pr("%24.24s terms", cname(tp->trt_cna)); + pr(" - %s terms\n", cname(tp->trt_cnb)); + for (i = 0; 0 != (cond = tchr[i].t_cond); i++) { + acond = tp->trt_acond & cond; + bcond = tp->trt_bcond & cond; + if (acond | bcond) { + if (acond) + pr("%30s", tchr[i].t_name); + else + pr("%30s", ""); + if (bcond) + pr(" - %s\n", tchr[i].t_name); + else + pr(" -\n"); + } + } + return 1; } diff --git a/src/lib/subs/fileinit.c b/src/lib/subs/fileinit.c index 1477b04d4..9177d2ce4 100644 --- a/src/lib/subs/fileinit.c +++ b/src/lib/subs/fileinit.c @@ -43,52 +43,52 @@ #include "prototypes.h" #include "optlist.h" -extern struct castr sect_ca[]; -extern struct castr news_ca[]; -extern struct castr loan_ca[]; -extern struct castr ship_ca[]; -extern struct castr plane_ca[]; -extern struct castr treaty_ca[]; -extern struct castr nuke_ca[]; -extern struct castr trade_ca[]; -extern struct castr commodity_ca[]; -extern struct castr lost_ca[]; +extern struct castr sect_ca[]; +extern struct castr news_ca[]; +extern struct castr loan_ca[]; +extern struct castr ship_ca[]; +extern struct castr plane_ca[]; +extern struct castr treaty_ca[]; +extern struct castr nuke_ca[]; +extern struct castr trade_ca[]; +extern struct castr commodity_ca[]; +extern struct castr lost_ca[]; struct fileinit fileinit[EF_MAX] = { - { (ef_fileinit) sct_init, sct_postread, sct_prewrite, sect_ca }, - { shp_init, shp_postread, shp_prewrite, ship_ca }, - { pln_init, pln_postread, pln_prewrite, plane_ca }, - { lnd_init, lnd_postread, lnd_prewrite, land_ca }, - { nuk_init, nuk_postread, nuk_prewrite, nuke_ca }, - { 0, 0, 0, news_ca }, - { 0, 0, 0, treaty_ca }, - { 0, 0, 0, trade_ca }, - { 0, 0, 0, 0 }, /* power */ - { 0, 0, 0, 0 }, /* nation */ - { 0, 0, 0, loan_ca }, - { 0, 0, 0, 0 }, /* map */ - { 0, 0, 0, 0 }, /* map */ - { 0, 0, 0, commodity_ca }, - { 0, 0, 0, lost_ca } + {(ef_fileinit)sct_init, sct_postread, sct_prewrite, sect_ca}, + {shp_init, shp_postread, shp_prewrite, ship_ca}, + {pln_init, pln_postread, pln_prewrite, plane_ca}, + {lnd_init, lnd_postread, lnd_prewrite, land_ca}, + {nuk_init, nuk_postread, nuk_prewrite, nuke_ca}, + {0, 0, 0, news_ca}, + {0, 0, 0, treaty_ca}, + {0, 0, 0, trade_ca}, + {0, 0, 0, 0}, /* power */ + {0, 0, 0, 0}, /* nation */ + {0, 0, 0, loan_ca}, + {0, 0, 0, 0}, /* map */ + {0, 0, 0, 0}, /* map */ + {0, 0, 0, commodity_ca}, + {0, 0, 0, lost_ca} }; void ef_init(void) { - int i; - struct empfile *ef; - struct fileinit *fi; + int i; + struct empfile *ef; + struct fileinit *fi; - ef = empfile; - fi = fileinit; - for (i=0; iinit = fi->init; - ef->postread = fi->postread; - ef->prewrite = fi->prewrite; - ef->cadef = fi->cadef; - /* We have to set the size for the map and bmap files at - runtime. */ - if (i == EF_MAP || i == EF_BMAP) - ef->size = (WORLD_X * WORLD_Y) / 2; - } + ef = empfile; + fi = fileinit; + for (i = 0; i < EF_MAX; i++, ef++, fi++) { + ef->init = fi->init; + ef->postread = fi->postread; + ef->prewrite = fi->prewrite; + ef->cadef = fi->cadef; + /* We have to set the size for the map and bmap files at + runtime. */ + if (i == EF_MAP || i == EF_BMAP) + ef->size = (WORLD_X * WORLD_Y) / 2; + } } diff --git a/src/lib/subs/fortdef.c b/src/lib/subs/fortdef.c index e4bab65fa..141265c7c 100644 --- a/src/lib/subs/fortdef.c +++ b/src/lib/subs/fortdef.c @@ -64,89 +64,92 @@ extern double tfactfire(natid, double); int shipdef(natid att, natid own, coord x, coord y) { - return sd(att, own, x, y, NOISY, 1, 1); + return sd(att, own, x, y, NOISY, 1, 1); } int -sd(natid att, natid own, coord x, coord y, int noisy, int defending, int usesubs) +sd(natid att, natid own, coord x, coord y, int noisy, int defending, + int usesubs) { - int nshot; - double range; - double eff; - struct shpstr ship; - struct nstr_item ni; - int vec[I_MAX+1]; - int dam, rel, rel2; + int nshot; + double range; + double eff; + struct shpstr ship; + struct nstr_item ni; + int vec[I_MAX + 1]; + int dam, rel, rel2; - if (own == 0) - return 0; - if (att == own) - return 0; - eff = 1.0; - snxtitem_dist(&ni, EF_SHIP, x, y, 8); - while (nxtitem(&ni, (caddr_t)&ship) && eff > 0.30) { - if (ship.shp_own == att) - continue; - if (ship.shp_own == 0) - continue; + if (own == 0) + return 0; + if (att == own) + return 0; + eff = 1.0; + snxtitem_dist(&ni, EF_SHIP, x, y, 8); + while (nxtitem(&ni, (caddr_t)&ship) && eff > 0.30) { + if (ship.shp_own == att) + continue; + if (ship.shp_own == 0) + continue; - rel = getrel(getnatp(ship.shp_own),own); - rel2 = getrel(getnatp(ship.shp_own),att); - if ((ship.shp_own != own) && - ((rel != ALLIED) || (rel2 != AT_WAR))) - continue; - if (ship.shp_effic < 60) - continue; - if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && (!usesubs)) - continue; - range = techfact(ship.shp_tech, - ship.shp_frnge * ship.shp_effic / 200.0); - range = (double)roundrange(range); - if (range < ni.curdist) - continue; - /* must have gun, shell, and milit to fire */ - if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 3) - continue; - if (vec[I_SHELL] < ship.shp_glim) - vec[I_SHELL] += supply_commod(ship.shp_own,ship.shp_x, - ship.shp_y,I_SHELL, - vec[I_SHELL]-ship.shp_glim); - nshot = min(min(vec[I_GUN], vec[I_SHELL]), vec[I_MILIT]); - nshot = min(nshot, ship.shp_glim); - if (nshot <= 0) - continue; - (void)putvar(V_SHELL,vec[I_SHELL]-nshot,(caddr_t)&ship,EF_SHIP); - putship(ship.shp_uid, &ship); + rel = getrel(getnatp(ship.shp_own), own); + rel2 = getrel(getnatp(ship.shp_own), att); + if ((ship.shp_own != own) && ((rel != ALLIED) || (rel2 != AT_WAR))) + continue; + if (ship.shp_effic < 60) + continue; + if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && (!usesubs)) + continue; + range = techfact(ship.shp_tech, + ship.shp_frnge * ship.shp_effic / 200.0); + range = (double)roundrange(range); + if (range < ni.curdist) + continue; + /* must have gun, shell, and milit to fire */ + if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 3) + continue; + if (vec[I_SHELL] < ship.shp_glim) + vec[I_SHELL] += supply_commod(ship.shp_own, ship.shp_x, + ship.shp_y, I_SHELL, + vec[I_SHELL] - ship.shp_glim); + nshot = min(min(vec[I_GUN], vec[I_SHELL]), vec[I_MILIT]); + nshot = min(nshot, ship.shp_glim); + if (nshot <= 0) + continue; + (void)putvar(V_SHELL, vec[I_SHELL] - nshot, (caddr_t)&ship, + EF_SHIP); + putship(ship.shp_uid, &ship); + if (defending) + nreport(ship.shp_own, N_FIRE_BACK, att, 1); + else + nreport(ship.shp_own, N_FIRE_S_ATTACK, att, 1); + dam = seagun(ship.shp_effic, nshot); + eff *= (1.0 - (0.01 * dam)); + if (noisy) { + pr_beep(); + pr("Incoming shell%s %d damage!\n", + nshot == 1 ? " does" : "s do", dam); + } + if (noisy || (ship.shp_own != own)) { + if (ship.shp_own == own) + wu(0, own, "%s fired on %s at %s doing %d damage.\n", + prship(&ship), cname(att), xyas(x, y, own), dam); + else { if (defending) - nreport(ship.shp_own, N_FIRE_BACK, att, 1); + wu(0, ship.shp_own, + "%s fired on %s at %s in defense of %s, doing %d damage.\n", + prship(&ship), cname(att), xyas(x, y, ship.shp_own), + cname(own), dam); else - nreport(ship.shp_own, N_FIRE_S_ATTACK, att, 1); - dam = seagun(ship.shp_effic, nshot); - eff *= (1.0 - (0.01 * dam)); - if (noisy) { - pr_beep(); - pr("Incoming shell%s %d damage!\n", - nshot == 1 ? " does" : "s do", dam); - } - if (noisy || (ship.shp_own != own)){ - if (ship.shp_own == own) - wu(0, own, "%s fired on %s at %s doing %d damage.\n", prship(&ship), - cname(att), xyas(x, y,own),dam); - else{ - if (defending) - wu(0, ship.shp_own, "%s fired on %s at %s in defense of %s, doing %d damage.\n", prship(&ship), - cname(att), - xyas(x, y, ship.shp_own), - cname(own),dam); - else - wu(0, ship.shp_own,"%s supported %s attacks against %s at %s, doing %d damage.\n", prship(&ship), - cname(own), - cname(att), - xyas(x, y, ship.shp_own), dam); - } - } + wu(0, ship.shp_own, + "%s supported %s attacks against %s at %s, doing %d damage.\n", + prship(&ship), cname(own), cname(att), xyas(x, y, + ship. + shp_own), + dam); + } } - return (int) 100 - (eff * 100); + } + return (int)100 - (eff * 100); } /* @@ -160,65 +163,64 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending, int usesubs * number of arguments for dd */ int defdef(att, def_own, defval, ax, ay) - natid att; - natid def_own; - int defval; - coord ax; - coord ay; +natid att; +natid def_own; +int defval; +coord ax; +coord ay; { - return dd(att, def_own, defval, ax, ay, NOISY, 1); + return dd(att, def_own, defval, ax, ay, NOISY, 1); } #endif int dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending) { - int dam, rel, rel2; - double tech; - double range; - struct sctstr firing; - struct nstr_sect ns; - int vec[I_MAX+1]; + int dam, rel, rel2; + double tech; + double range; + struct sctstr firing; + struct nstr_sect ns; + int vec[I_MAX + 1]; - if (opt_NO_FORT_FIRE) /* Forts can't fire! */ - return 0; - if (def_own == 0) - return 0; - if (att == def_own) - return 0; - tech = tfactfire(def_own, 1.0); - dam = 0; - snxtsct_dist(&ns, ax, ay, 8); - while (nxtsct(&ns, &firing) && dam < 80) { - if (firing.sct_own == att) - continue; - if (firing.sct_own == 0) - continue; - if (firing.sct_effic < (u_char)FORTEFF ) - continue; - rel = getrel(getnatp(firing.sct_own),def_own); - rel2 = getrel(getnatp(firing.sct_own),att); - if ((firing.sct_own != def_own) && - ((rel != ALLIED) || (rel2 != AT_WAR))) - continue; - if (getvec(VT_ITEM, vec, (caddr_t)&firing, EF_SECTOR) < 0) - continue; + if (opt_NO_FORT_FIRE) /* Forts can't fire! */ + return 0; + if (def_own == 0) + return 0; + if (att == def_own) + return 0; + tech = tfactfire(def_own, 1.0); + dam = 0; + snxtsct_dist(&ns, ax, ay, 8); + while (nxtsct(&ns, &firing) && dam < 80) { + if (firing.sct_own == att) + continue; + if (firing.sct_own == 0) + continue; + if (firing.sct_effic < (u_char)FORTEFF) + continue; + rel = getrel(getnatp(firing.sct_own), def_own); + rel2 = getrel(getnatp(firing.sct_own), att); + if ((firing.sct_own != def_own) && + ((rel != ALLIED) || (rel2 != AT_WAR))) + continue; + if (getvec(VT_ITEM, vec, (caddr_t)&firing, EF_SECTOR) < 0) + continue; - range = tfactfire(def_own, 7.0); - if (firing.sct_effic > 59) - range++; - /* Here we round down the range, and then add 1 to it - to determine if we could possibly hit the sector. If - we do, we call sb where the range is re-calculated and - the percentages are checked. */ - range = (double)((int)(range) + 1); - if (range < ns.curdist) - continue; + range = tfactfire(def_own, 7.0); + if (firing.sct_effic > 59) + range++; + /* Here we round down the range, and then add 1 to it + to determine if we could possibly hit the sector. If + we do, we call sb where the range is re-calculated and + the percentages are checked. */ + range = (double)((int)(range) + 1); + if (range < ns.curdist) + continue; /* XXX defdef damage is additive, but ship or land unit damage isn't */ - dam += sb(att, def_own, &firing, - ax, ay, noisy, defending); - } - return dam; + dam += sb(att, def_own, &firing, ax, ay, noisy, defending); + } + return dam; } /* Shoot back @@ -226,56 +228,60 @@ dd(natid att, natid def_own, coord ax, coord ay, int noisy, int defending) * See if the sector being fired at will defend itself. */ int -sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy, int defending) +sb(natid att, natid def, struct sctstr *sp, coord tx, coord ty, int noisy, + int defending) { - register int damage; - natid own; - int shell; - double range; - int range2, gun; + register int damage; + natid own; + int shell; + double range; + int range2, gun; - if (sp->sct_type != SCT_FORTR) { - /* XXX I don't like this restriction */ - return 0; - } + if (sp->sct_type != SCT_FORTR) { + /* XXX I don't like this restriction */ + return 0; + } - if (sp->sct_effic < (u_char)FORTEFF) - return 0; + if (sp->sct_effic < (u_char)FORTEFF) + return 0; - own = sp->sct_own; - if (own == 0) - return 0; - if (att == own) - return 0; - range = tfactfire(own, 7.0); - if (sp->sct_effic > 59) - range++; - range = (double)roundrange(range); - range2 = mapdist((int)sp->sct_x, (int)sp->sct_y, tx, ty); - if (range < range2) - return 0; - gun = getvar(V_GUN, (caddr_t)sp, EF_SECTOR); - if (gun == 0) - return 0; - shell = getvar(V_SHELL, (caddr_t)sp, EF_SECTOR); - if (shell <= 0) - shell += supply_commod(sp->sct_own,sp->sct_x,sp->sct_y,I_SHELL, - 1); - if (shell <= 0) - return 0; - putvar(V_SHELL, shell - 1, (caddr_t)sp, EF_SECTOR); - putsect(sp); - damage = landgun((int)sp->sct_effic,gun); - if (sp->sct_own != def) - wu(0,sp->sct_own, "%s fired on %s in %s in defense of %s, doing %d damage!\n", - xyas(sp->sct_x,sp->sct_y,sp->sct_own), - cname(att), xyas(tx,ty,sp->sct_own), - cname(def), damage); - if (defending) - nreport(sp->sct_own, N_FIRE_BACK, att, 1); - else - nreport(sp->sct_own, N_FIRE_F_ATTACK, att, 1); - if (noisy) - pr("Incoming shell! %d damage done.\007\n", damage); - return damage; + own = sp->sct_own; + if (own == 0) + return 0; + if (att == own) + return 0; + range = tfactfire(own, 7.0); + if (sp->sct_effic > 59) + range++; + range = (double)roundrange(range); + range2 = mapdist((int)sp->sct_x, (int)sp->sct_y, tx, ty); + if (range < range2) + return 0; + gun = getvar(V_GUN, (caddr_t)sp, EF_SECTOR); + if (gun == 0) + return 0; + shell = getvar(V_SHELL, (caddr_t)sp, EF_SECTOR); + if (shell <= 0) + shell += supply_commod(sp->sct_own, sp->sct_x, sp->sct_y, I_SHELL, + 1); + if (shell <= 0) + return 0; + putvar(V_SHELL, shell - 1, (caddr_t)sp, EF_SECTOR); + putsect(sp); + damage = landgun((int)sp->sct_effic, gun); + if (sp->sct_own != def) + wu(0, sp->sct_own, + "%s fired on %s in %s in defense of %s, doing %d damage!\n", + xyas(sp->sct_x, sp->sct_y, sp->sct_own), cname(att), xyas(tx, + ty, + sp-> + sct_own), + cname(def), damage); + if (defending) + nreport(sp->sct_own, N_FIRE_BACK, att, 1); + else + nreport(sp->sct_own, N_FIRE_F_ATTACK, att, 1); + if (noisy) + pr("Incoming shell! %d damage done.\007\n", damage); + return damage; } diff --git a/src/lib/subs/getbit.c b/src/lib/subs/getbit.c index 263a0c4f3..ce4994a42 100644 --- a/src/lib/subs/getbit.c +++ b/src/lib/subs/getbit.c @@ -46,34 +46,35 @@ int emp_getbit(int x, int y, u_char *bitmap) { - int id; + int id; - id = (GCFy(y)) * WORLD_X/2 + GCFx(x)/2; - return bitmap[id / 8] & bit(id & 07); + id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2; + return bitmap[id / 8] & bit(id & 07); } void emp_setbit(int x, int y, u_char *bitmap) { - register int id; + register int id; - id = (GCFy(y)) * WORLD_X/2 + GCFx(x)/2; - bitmap[id / 8] |= bit(id & 07); + id = (GCFy(y)) * WORLD_X / 2 + GCFx(x) / 2; + bitmap[id / 8] |= bit(id & 07); } void -emp_setbitmap(register int x, register int y, register u_char *bitmap, int *bitmaps) +emp_setbitmap(register int x, register int y, register u_char *bitmap, + int *bitmaps) { - register int *mp; - register int id; - register int dx, dy; - - for (mp = bitmaps; *mp != 9999; ) { - dx = x + *mp++; - dy = y + *mp++; - id = (GCFy(dy)) * WORLD_X/2 + GCFx(dx)/2; - bitmap[id / 8] |= bit(id & 07); - } + register int *mp; + register int id; + register int dx, dy; + + for (mp = bitmaps; *mp != 9999;) { + dx = x + *mp++; + dy = y + *mp++; + id = (GCFy(dy)) * WORLD_X / 2 + GCFx(dx) / 2; + bitmap[id / 8] |= bit(id & 07); + } } @@ -85,19 +86,19 @@ emp_setbitmap(register int x, register int y, register u_char *bitmap, int *bitm void emp_bitinit(struct nstr_sect *np, u_char *bitmap) { - extern int *bitmaps[]; - struct sctstr sect; - int eff; - - while (nxtsct(np, §)) { - if (!player->owner) - continue; - eff = sect.sct_effic / 20; - if (eff > 4) - eff = 4; - emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]); - } - snxtsct_rewind(np); + extern int *bitmaps[]; + struct sctstr sect; + int eff; + + while (nxtsct(np, §)) { + if (!player->owner) + continue; + eff = sect.sct_effic / 20; + if (eff > 4) + eff = 4; + emp_setbitmap(np->x, np->y, bitmap, bitmaps[eff]); + } + snxtsct_rewind(np); } /* @@ -112,64 +113,67 @@ emp_bitinit(struct nstr_sect *np, u_char *bitmap) * bitmap4: 81-100% */ -#define bitoff(x, y) x, y +#define bitoff(x, y) x, y int bitmap0[] = { - bitoff(-1,-1), bitoff(1,-1), - bitoff(-2,0), bitoff(0,0), bitoff(2,0), - bitoff(-1,1), bitoff(1,1), - bitoff(9999,9999), + bitoff(-1, -1), bitoff(1, -1), + bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), + bitoff(-1, 1), bitoff(1, 1), + bitoff(9999, 9999), }; int bitmap1[] = { - bitoff(0,-2), - bitoff(-3,-1), bitoff(-1,-1), bitoff(1,-1), bitoff(3,-1), - bitoff(-2,0), bitoff(0,0), bitoff(2,0), - bitoff(-3,1), bitoff(-1,1), bitoff(1,1), bitoff(3,1), - bitoff(0,2), - bitoff(9999,9999), + bitoff(0, -2), + bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1), + bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), + bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1), + bitoff(0, 2), + bitoff(9999, 9999), }; int bitmap2[] = { - bitoff(-2,-2), bitoff(0,-2), bitoff(2,-2), - bitoff(-3,-1), bitoff(-1,-1), bitoff(1,-1), bitoff(3,-1), - bitoff(-4,0), bitoff(-2,0), bitoff(0,0), bitoff(2,0), bitoff(4,0), - bitoff(-3,1), bitoff(-1,1), bitoff(1,1), bitoff(3,1), - bitoff(-2,2), bitoff(0,2), bitoff(2,2), - bitoff(9999,9999), + bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), + bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), bitoff(3, -1), + bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0), + bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), bitoff(3, 1), + bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), + bitoff(9999, 9999), }; int bitmap3[] = { - bitoff(-1,-3), bitoff(1,-3), - bitoff(-4,-2), bitoff(-2,-2), bitoff(0,-2), bitoff(2,-2), bitoff(4,-2), - bitoff(-5,-1), bitoff(-3,-1), bitoff(-1,-1), bitoff(1,-1), - bitoff(3,-1), bitoff(5,-1), - bitoff(-4,0), bitoff(-2,0), bitoff(0,0), bitoff(2,0), bitoff(4,0), - bitoff(-5,1), bitoff(-3,1), bitoff(-1,1), bitoff(1,1), - bitoff(3,1), bitoff(5,1), - bitoff(-4,2), bitoff(-2,2), bitoff(0,2), bitoff(2,2), bitoff(4,2), - bitoff(-1,3), bitoff(1,3), - bitoff(9999,9999), + bitoff(-1, -3), bitoff(1, -3), + bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4, + -2), + bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), + bitoff(3, -1), bitoff(5, -1), + bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, 0), bitoff(4, 0), + bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), + bitoff(3, 1), bitoff(5, 1), + bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2), + bitoff(-1, 3), bitoff(1, 3), + bitoff(9999, 9999), }; int bitmap4[] = { - bitoff(-3,-3), bitoff(-1,-3), bitoff(1,-3), bitoff(3,-3), - bitoff(-4,-2), bitoff(-2,-2), bitoff(0,-2), bitoff(2,-2), bitoff(4,-2), - bitoff(-5,-1), bitoff(-3,-1), bitoff(-1,-1), bitoff(1,-1), - bitoff(3,-1), bitoff(5,-1), - bitoff(-6,0), bitoff(-4,0), bitoff(-2,0), bitoff(0,0), bitoff(2,0), - bitoff(4,0), bitoff(6,0), - bitoff(-5,1), bitoff(-3,1), bitoff(-1,1), bitoff(1,1), - bitoff(3,1), bitoff(5,1), - bitoff(-4,2), bitoff(-2,2), bitoff(0,2), bitoff(2,2), bitoff(4,2), - bitoff(-3,3), bitoff(-1,3), bitoff(1,3), bitoff(3, 3), - bitoff(9999,9999), + bitoff(-3, -3), bitoff(-1, -3), bitoff(1, -3), bitoff(3, -3), + bitoff(-4, -2), bitoff(-2, -2), bitoff(0, -2), bitoff(2, -2), bitoff(4, + -2), + bitoff(-5, -1), bitoff(-3, -1), bitoff(-1, -1), bitoff(1, -1), + bitoff(3, -1), bitoff(5, -1), + bitoff(-6, 0), bitoff(-4, 0), bitoff(-2, 0), bitoff(0, 0), bitoff(2, + 0), + bitoff(4, 0), bitoff(6, 0), + bitoff(-5, 1), bitoff(-3, 1), bitoff(-1, 1), bitoff(1, 1), + bitoff(3, 1), bitoff(5, 1), + bitoff(-4, 2), bitoff(-2, 2), bitoff(0, 2), bitoff(2, 2), bitoff(4, 2), + bitoff(-3, 3), bitoff(-1, 3), bitoff(1, 3), bitoff(3, 3), + bitoff(9999, 9999), }; int *bitmaps[5] = { - bitmap0, - bitmap1, - bitmap2, - bitmap3, - bitmap4, + bitmap0, + bitmap1, + bitmap2, + bitmap3, + bitmap4, }; diff --git a/src/lib/subs/getele.c b/src/lib/subs/getele.c index 4041980a6..e50a4844a 100644 --- a/src/lib/subs/getele.c +++ b/src/lib/subs/getele.c @@ -42,74 +42,74 @@ static int tilde_escape(s_char *s, s_char c); int getele(s_char *nation, s_char *buf) { - register s_char *bp; - register int len; - register int c; - s_char buffer[MAXTELSIZE + 2]; - s_char left[MAXTELSIZE + 2]; + register s_char *bp; + register int len; + register int c; + s_char buffer[MAXTELSIZE + 2]; + s_char left[MAXTELSIZE + 2]; - pr("Enter telegram for %s\n", nation); - pr("undo last line with ~u, print with ~p, abort with ~q, end with ^D or .\n"); - bp = buf; - while (!player->aborted) { - sprintf(left, "%4d left: ", (int)(buf + MAXTELSIZE - bp)); - buffer[0] = 0; - if (prmptrd(left, buffer, MAXTELSIZE-2) <= 0) - break; - if (tilde_escape(buffer, 'q')) - return -1; - if (tilde_escape(buffer, 'u')) { - if (bp == buf) { - pr("No more lines to undo\n"); - continue; - } - pr("Last line deleted.\n"); - for (bp -= 2; bp > buf && *bp != '\n'; --bp); - if (bp > buf) - *(++bp) = 0; - else - bp = buf; - continue; - } - if (tilde_escape(buffer, 'p')) { - pr("This is what you have written so far:\n"); - pr("%s", buf); - continue; - } - if (buffer[0] == '.' && ((buffer[1] == 0) || - (buffer[1] == '\n') || (buffer[1] == '\r'))) - break; - len = strlen(buffer); - buffer[len++] = '\n'; - buffer[len] = 0; - if (len + (bp - buf) > MAXTELSIZE) - pr("Too long. Try that last line again...\n"); - else { - if (buffer[0] == '>') /* forgery attempt? */ - buffer[0] = '?'; /* foil it */ - (void) strcpy(bp, buffer); - bp += len; - } + pr("Enter telegram for %s\n", nation); + pr("undo last line with ~u, print with ~p, abort with ~q, end with ^D or .\n"); + bp = buf; + while (!player->aborted) { + sprintf(left, "%4d left: ", (int)(buf + MAXTELSIZE - bp)); + buffer[0] = 0; + if (prmptrd(left, buffer, MAXTELSIZE - 2) <= 0) + break; + if (tilde_escape(buffer, 'q')) + return -1; + if (tilde_escape(buffer, 'u')) { + if (bp == buf) { + pr("No more lines to undo\n"); + continue; + } + pr("Last line deleted.\n"); + for (bp -= 2; bp > buf && *bp != '\n'; --bp) ; + if (bp > buf) + *(++bp) = 0; + else + bp = buf; + continue; } - if (player->aborted) - return -1; - len = bp - buf; - buf[len] = 0; - /* Get rid of non-ASCII and control characters. */ - for (bp = buf; 0 != (c = *bp); bp++) { - if (isascii(c) && (isprint(c) || isspace(c))) - continue; - *bp = '?'; + if (tilde_escape(buffer, 'p')) { + pr("This is what you have written so far:\n"); + pr("%s", buf); + continue; } - return len; + if (buffer[0] == '.' && ((buffer[1] == 0) || + (buffer[1] == '\n') + || (buffer[1] == '\r'))) + break; + len = strlen(buffer); + buffer[len++] = '\n'; + buffer[len] = 0; + if (len + (bp - buf) > MAXTELSIZE) + pr("Too long. Try that last line again...\n"); + else { + if (buffer[0] == '>') /* forgery attempt? */ + buffer[0] = '?'; /* foil it */ + (void)strcpy(bp, buffer); + bp += len; + } + } + if (player->aborted) + return -1; + len = bp - buf; + buf[len] = 0; + /* Get rid of non-ASCII and control characters. */ + for (bp = buf; 0 != (c = *bp); bp++) { + if (isascii(c) && (isprint(c) || isspace(c))) + continue; + *bp = '?'; + } + return len; } static int tilde_escape(s_char *s, s_char c) { - if (s[0] == '~' && s[1] == c && - ((s[2] == 0) || (s[2] == '\n') || (s[2] == '\r'))) - return 1; - return 0; + if (s[0] == '~' && s[1] == c && + ((s[2] == 0) || (s[2] == '\n') || (s[2] == '\r'))) + return 1; + return 0; } - diff --git a/src/lib/subs/land.c b/src/lib/subs/land.c index 2d5a06aff..7c0dfc1b7 100644 --- a/src/lib/subs/land.c +++ b/src/lib/subs/land.c @@ -48,61 +48,64 @@ int lnd_postread(int n, s_char *ptr) { - struct lndstr *llp = (struct lndstr *) ptr; - struct shpstr theship; - struct lndstr theland; - - if (llp->lnd_uid != n) { - logerror("lnd_postread: Error - %d != %d, zeroing.\n", llp->lnd_uid, n); - bzero(ptr, sizeof(struct lndstr)); - } - if (llp->lnd_ship >= 0 && llp->lnd_own && llp->lnd_effic >= LAND_MINEFF) { - if (getship(llp->lnd_ship, &theship) && - (theship.shp_effic >= SHIP_MINEFF)) { - /* wooof! Carriers are a pain */ - if (llp->lnd_mission){ - /* - * If the unit is on a mission centered - * on it's loc, the op-area travels with - * the unit. - */ - if ((llp->lnd_opx == llp->lnd_x) && - (llp->lnd_opy == llp->lnd_y)) { - llp->lnd_opx = theship.shp_x; - llp->lnd_opy = theship.shp_y; - } - } - if (llp->lnd_x != theship.shp_x || llp->lnd_y != theship.shp_y) - time(&llp->lnd_timestamp); - llp->lnd_x = theship.shp_x; - llp->lnd_y = theship.shp_y; + struct lndstr *llp = (struct lndstr *)ptr; + struct shpstr theship; + struct lndstr theland; + + if (llp->lnd_uid != n) { + logerror("lnd_postread: Error - %d != %d, zeroing.\n", + llp->lnd_uid, n); + bzero(ptr, sizeof(struct lndstr)); + } + if (llp->lnd_ship >= 0 && llp->lnd_own + && llp->lnd_effic >= LAND_MINEFF) { + if (getship(llp->lnd_ship, &theship) + && (theship.shp_effic >= SHIP_MINEFF)) { + /* wooof! Carriers are a pain */ + if (llp->lnd_mission) { + /* + * If the unit is on a mission centered + * on it's loc, the op-area travels with + * the unit. + */ + if ((llp->lnd_opx == llp->lnd_x) && + (llp->lnd_opy == llp->lnd_y)) { + llp->lnd_opx = theship.shp_x; + llp->lnd_opy = theship.shp_y; } + } + if (llp->lnd_x != theship.shp_x || llp->lnd_y != theship.shp_y) + time(&llp->lnd_timestamp); + llp->lnd_x = theship.shp_x; + llp->lnd_y = theship.shp_y; + } } - if (llp->lnd_land >= 0 && llp->lnd_own && llp->lnd_effic >= LAND_MINEFF) { - if (getland(llp->lnd_land, &theland) && - (theland.lnd_effic >= LAND_MINEFF)) { - /* wooof! Carriers are a pain */ - if (llp->lnd_mission){ - /* - * If the unit is on a mission centered - * on it's loc, the op-area travels with - * the unit. - */ - if ((llp->lnd_opx == llp->lnd_x) && - (llp->lnd_opy == llp->lnd_y)){ - llp->lnd_opx = theland.lnd_x; - llp->lnd_opy = theland.lnd_y; - } - } - if (llp->lnd_x != theland.lnd_x || llp->lnd_y != theland.lnd_y) - time(&llp->lnd_timestamp); - llp->lnd_x = theland.lnd_x; - llp->lnd_y = theland.lnd_y; + if (llp->lnd_land >= 0 && llp->lnd_own + && llp->lnd_effic >= LAND_MINEFF) { + if (getland(llp->lnd_land, &theland) + && (theland.lnd_effic >= LAND_MINEFF)) { + /* wooof! Carriers are a pain */ + if (llp->lnd_mission) { + /* + * If the unit is on a mission centered + * on it's loc, the op-area travels with + * the unit. + */ + if ((llp->lnd_opx == llp->lnd_x) && + (llp->lnd_opy == llp->lnd_y)) { + llp->lnd_opx = theland.lnd_x; + llp->lnd_opy = theland.lnd_y; } + } + if (llp->lnd_x != theland.lnd_x || llp->lnd_y != theland.lnd_y) + time(&llp->lnd_timestamp); + llp->lnd_x = theland.lnd_x; + llp->lnd_y = theland.lnd_y; + } } if (opt_MOB_ACCESS) - lnd_do_upd_mob(llp); - + lnd_do_upd_mob(llp); + player->owner = (player->god || llp->lnd_own == player->cnum); return 1; } @@ -111,63 +114,66 @@ lnd_postread(int n, s_char *ptr) int lnd_prewrite(int n, s_char *ptr) { - struct lndstr *llp = (struct lndstr *) ptr; - struct lndstr land; + struct lndstr *llp = (struct lndstr *)ptr; + struct lndstr land; struct lndstr *lp; struct plnstr *pp; int i; - + llp->ef_type = EF_LAND; llp->lnd_uid = n; - + time(&llp->lnd_timestamp); if (llp->lnd_own && llp->lnd_effic < LAND_MINEFF) { - makelost(EF_LAND, llp->lnd_own, llp->lnd_uid, llp->lnd_x, llp->lnd_y); - llp->lnd_own = 0; - - getland(n, &land); - - for (i = 0; NULL != (lp = getlandp(i)); i++) { - if (lp->lnd_own && lp->lnd_land == n) { - mpr(lp->lnd_own, "%s MIA!\n", prland(lp)); - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own = 0; - lp->lnd_effic = 0; - lp->lnd_ship = -1; - lp->lnd_land = -1; - putland(lp->lnd_uid, lp); - } - } - for (i = 0; NULL != (pp = getplanep(i)); i++) { - if (pp->pln_own && pp->pln_land == n) { - mpr(pp->pln_own, "%s MIA!\n", prplane(pp)); - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - pp->pln_effic = 0; - pp->pln_ship = -1; - pp->pln_land = -1; - putplane(pp->pln_uid, pp); - } - } + makelost(EF_LAND, llp->lnd_own, llp->lnd_uid, llp->lnd_x, + llp->lnd_y); + llp->lnd_own = 0; + + getland(n, &land); + + for (i = 0; NULL != (lp = getlandp(i)); i++) { + if (lp->lnd_own && lp->lnd_land == n) { + mpr(lp->lnd_own, "%s MIA!\n", prland(lp)); + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, + lp->lnd_y); + lp->lnd_own = 0; + lp->lnd_effic = 0; + lp->lnd_ship = -1; + lp->lnd_land = -1; + putland(lp->lnd_uid, lp); + } + } + for (i = 0; NULL != (pp = getplanep(i)); i++) { + if (pp->pln_own && pp->pln_land == n) { + mpr(pp->pln_own, "%s MIA!\n", prplane(pp)); + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_own = 0; + pp->pln_effic = 0; + pp->pln_ship = -1; + pp->pln_land = -1; + putplane(pp->pln_uid, pp); + } + } } else - getland(n, &land); - + getland(n, &land); + return 1; } void lnd_init(int n, s_char *ptr) { - struct lndstr *lp = (struct lndstr *) ptr; + struct lndstr *lp = (struct lndstr *)ptr; - lp->ef_type = EF_LAND; - lp->lnd_uid = n; - lp->lnd_own = 0; + lp->ef_type = EF_LAND; + lp->lnd_uid = n; + lp->lnd_own = 0; } s_char * prland(struct lndstr *lp) { - return prbuf("%s #%d", lchr[(int)lp->lnd_type].l_name, lp->lnd_uid); + return prbuf("%s #%d", lchr[(int)lp->lnd_type].l_name, lp->lnd_uid); } diff --git a/src/lib/subs/landgun.c b/src/lib/subs/landgun.c index afad0b565..2b1eae61d 100644 --- a/src/lib/subs/landgun.c +++ b/src/lib/subs/landgun.c @@ -40,49 +40,49 @@ double landgun(int effic, int guns) { - double d; - double g = (double)min(guns,7); + double d; + double g = (double)min(guns, 7); - d = ((double)(random() % 30) + 20.0) * ((double)g / 7.0); - d *= ((double)effic); - d /= 100.0; - return d; + d = ((double)(random() % 30) + 20.0) * ((double)g / 7.0); + d *= ((double)effic); + d /= 100.0; + return d; } double seagun(int effic, int guns) { - double d; + double d; - d = 0.0; - while (guns--) - d += 10.0 + (double)(random() % 6); - d *= ((double)effic) * 0.01; - return d; + d = 0.0; + while (guns--) + d += 10.0 + (double)(random() % 6); + d *= ((double)effic) * 0.01; + return d; } double landunitgun(int effic, int shots, int guns, int ammo, int shells) { - double d = 0.0; + double d = 0.0; - shots = min(shots, guns); - while (shots-- > 0) - d += 5.0 + (double)(random() % 6); - d *= ((double)effic) * 0.01; - if (shells < ammo && ammo != 0) - d *= (double)((double)shells / (double)ammo); - return d; + shots = min(shots, guns); + while (shots-- > 0) + d += 5.0 + (double)(random() % 6); + d *= ((double)effic) * 0.01; + if (shells < ammo && ammo != 0) + d *= (double)((double)shells / (double)ammo); + return d; } int roundrange(double r) { - double f; + double f; - f = r - ((int)r); - if (chance(f)) - return (((int)r) + 1); - else - return ((int)r); + f = r - ((int)r); + if (chance(f)) + return (((int)r) + 1); + else + return ((int)r); } diff --git a/src/lib/subs/list.c b/src/lib/subs/list.c index defb1f6ef..f562084aa 100644 --- a/src/lib/subs/list.c +++ b/src/lib/subs/list.c @@ -47,44 +47,43 @@ #include "file.h" #include "prototypes.h" -extern s_char *effadv(int); +extern s_char *effadv(int); int shipsatxy(coord x, coord y, int wantflags, int nowantflags) { - int first; - int ships; - struct nstr_item ni; - struct mchrstr *mp; - struct shpstr ship; + int first; + int ships; + struct nstr_item ni; + struct mchrstr *mp; + struct shpstr ship; - first = 1; - ships = 0; - snxtitem_xy(&ni, EF_SHIP, x, y); - while (nxtitem(&ni, (s_char *)&ship)) { - if (player->owner) - continue; - if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) - continue; - mp = &mchr[(int)ship.shp_type]; - if (wantflags) { - if ((mp->m_flags & wantflags) == 0) - continue; - } - if (nowantflags) { - if (mp->m_flags & nowantflags) - continue; - } - if (first) { - pr(" # owner eff type\n"); - first = 0; - } - pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, - cname(ship.shp_own), - effadv(ship.shp_effic), prship(&ship)); - ships++; + first = 1; + ships = 0; + snxtitem_xy(&ni, EF_SHIP, x, y); + while (nxtitem(&ni, (s_char *)&ship)) { + if (player->owner) + continue; + if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) + continue; + mp = &mchr[(int)ship.shp_type]; + if (wantflags) { + if ((mp->m_flags & wantflags) == 0) + continue; } - return ships; + if (nowantflags) { + if (mp->m_flags & nowantflags) + continue; + } + if (first) { + pr(" # owner eff type\n"); + first = 0; + } + pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, + cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship)); + ships++; + } + return ships; } /* This one only shows owned or allied ships */ @@ -92,203 +91,199 @@ shipsatxy(coord x, coord y, int wantflags, int nowantflags) int carriersatxy(coord x, coord y, int wantflags, int nowantflags, natid own) { - int first; - int ships; - struct nstr_item ni; - struct mchrstr *mp; - struct shpstr ship; - int allied; + int first; + int ships; + struct nstr_item ni; + struct mchrstr *mp; + struct shpstr ship; + int allied; - first = 1; - ships = 0; - snxtitem_xy(&ni, EF_SHIP, x, y); - while (nxtitem(&ni, (s_char *)&ship)) { - if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) - continue; - allied = (getrel(getnatp(ship.shp_own), own) == ALLIED); - if ((ship.shp_own != own) & !allied) - continue; - mp = &mchr[(int)ship.shp_type]; - if (wantflags) { - if ((mp->m_flags & wantflags) == 0) - continue; - } - if (nowantflags) { - if (mp->m_flags & nowantflags) - continue; - } - if (first) { - pr(" # owner eff type\n"); - first = 0; - } - pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, - cname(ship.shp_own), - effadv(ship.shp_effic), - prship(&ship)); - ships++; + first = 1; + ships = 0; + snxtitem_xy(&ni, EF_SHIP, x, y); + while (nxtitem(&ni, (s_char *)&ship)) { + if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) + continue; + allied = (getrel(getnatp(ship.shp_own), own) == ALLIED); + if ((ship.shp_own != own) & !allied) + continue; + mp = &mchr[(int)ship.shp_type]; + if (wantflags) { + if ((mp->m_flags & wantflags) == 0) + continue; + } + if (nowantflags) { + if (mp->m_flags & nowantflags) + continue; + } + if (first) { + pr(" # owner eff type\n"); + first = 0; } - return ships; + pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, + cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship)); + ships++; + } + return ships; } int unitsatxy(coord x, coord y, int wantflags, int nowantflags) { - int first; - int units; - struct nstr_item ni; - struct lchrstr *lp; - struct lndstr land; - double odds; + int first; + int units; + struct nstr_item ni; + struct lchrstr *lp; + struct lndstr land; + double odds; - first = 1; - units = 0; - snxtitem_xy(&ni, EF_LAND, x, y); - while (nxtitem(&ni, (s_char *)&land)) { - if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0) - continue; - /* Can't bomb units on ships or other units */ - if (land.lnd_ship >= 0 || land.lnd_land >= 0) - continue; - lp = &lchr[(int)land.lnd_type]; + first = 1; + units = 0; + snxtitem_xy(&ni, EF_LAND, x, y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_effic < LAND_MINEFF || land.lnd_own == 0) + continue; + /* Can't bomb units on ships or other units */ + if (land.lnd_ship >= 0 || land.lnd_land >= 0) + continue; + lp = &lchr[(int)land.lnd_type]; - if (wantflags) { - if ((lp->l_flags & wantflags) == 0) - continue; - } - if (nowantflags) { - if (lp->l_flags & nowantflags) - continue; - } + if (wantflags) { + if ((lp->l_flags & wantflags) == 0) + continue; + } + if (nowantflags) { + if (lp->l_flags & nowantflags) + continue; + } - if (lp->l_flags & L_SPY) { - odds = (double)(100 - land.lnd_effic) + 0.10; - if (!(chance(odds))) - continue; - } + if (lp->l_flags & L_SPY) { + odds = (double)(100 - land.lnd_effic) + 0.10; + if (!(chance(odds))) + continue; + } - if (first) { - pr(" # owner eff type\n"); - first = 0; - } - pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, - cname(land.lnd_own), - effadv(land.lnd_effic), prland(&land)); - units++; + if (first) { + pr(" # owner eff type\n"); + first = 0; } - return units; + pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, + cname(land.lnd_own), effadv(land.lnd_effic), prland(&land)); + units++; + } + return units; } int -planesatxy(coord x, coord y, int wantflags, int nowantflags, struct emp_qelem *list) +planesatxy(coord x, coord y, int wantflags, int nowantflags, + struct emp_qelem *list) { - int first; - int planes; - struct plnstr plane; - struct nstr_item ni; - struct plchrstr *plp; + int first; + int planes; + struct plnstr plane; + struct nstr_item ni; + struct plchrstr *plp; - planes = 0; - first = 1; - snxtitem_xy(&ni, EF_PLANE, x, y); - while (nxtitem(&ni, (s_char *)&plane)) { - if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0) - continue; - if (plane.pln_flags & PLN_LAUNCHED) - continue; - /* Is this plane one of the ones flying somewhere? */ - if (ac_isflying(&plane, list)) - continue; - plp = &plchr[(int)plane.pln_type]; - if (first) { - pr(" # owner eff type\n"); - first = 0; - } - if (wantflags) { - if ((plp->pl_flags & wantflags) == 0) - continue; - } - if (nowantflags) { - if (plp->pl_flags & nowantflags) - continue; - } - pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, - cname(plane.pln_own), - effadv(plane.pln_effic), prplane(&plane)); - planes++; + planes = 0; + first = 1; + snxtitem_xy(&ni, EF_PLANE, x, y); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_effic < PLANE_MINEFF || plane.pln_own == 0) + continue; + if (plane.pln_flags & PLN_LAUNCHED) + continue; + /* Is this plane one of the ones flying somewhere? */ + if (ac_isflying(&plane, list)) + continue; + plp = &plchr[(int)plane.pln_type]; + if (first) { + pr(" # owner eff type\n"); + first = 0; } - return planes; + if (wantflags) { + if ((plp->pl_flags & wantflags) == 0) + continue; + } + if (nowantflags) { + if (plp->pl_flags & nowantflags) + continue; + } + pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, + cname(plane.pln_own), effadv(plane.pln_effic), prplane(&plane)); + planes++; + } + return planes; } int -asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags, struct plnstr *pp, struct shiplook *head) +asw_shipsatxy(coord x, coord y, int wantflags, int nowantflags, + struct plnstr *pp, struct shiplook *head) { - int first; - int ships; - struct nstr_item ni; - struct mchrstr *mp; - struct shpstr ship; + int first; + int ships; + struct nstr_item ni; + struct mchrstr *mp; + struct shpstr ship; - first = 1; - ships = 0; - snxtitem_xy(&ni, EF_SHIP, x, y); - while (nxtitem(&ni, (s_char *)&ship)) { - if (player->owner) - continue; - if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) - continue; - mp = &mchr[(int)ship.shp_type]; - if (wantflags) { - if ((mp->m_flags & wantflags) == 0) - continue; - } - if (nowantflags) { - if (mp->m_flags & nowantflags) - continue; - } - if (mp->m_flags & M_SUB){ - if (roll(100) > pln_hitchance(pp, - shp_hardtarget(&ship), - EF_SHIP)) - continue; - } - set_have_found(ship.shp_uid,head); - if (first) { - pr(" # owner eff type\n"); - first = 0; - } - pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, - cname(ship.shp_own), - effadv(ship.shp_effic), prship(&ship)); - ships++; + first = 1; + ships = 0; + snxtitem_xy(&ni, EF_SHIP, x, y); + while (nxtitem(&ni, (s_char *)&ship)) { + if (player->owner) + continue; + if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) + continue; + mp = &mchr[(int)ship.shp_type]; + if (wantflags) { + if ((mp->m_flags & wantflags) == 0) + continue; + } + if (nowantflags) { + if (mp->m_flags & nowantflags) + continue; + } + if (mp->m_flags & M_SUB) { + if (roll(100) > pln_hitchance(pp, + shp_hardtarget(&ship), EF_SHIP)) + continue; } - return ships; + set_have_found(ship.shp_uid, head); + if (first) { + pr(" # owner eff type\n"); + first = 0; + } + pr("(#%3d) %10.10s %12.12s %s\n", ni.cur, + cname(ship.shp_own), effadv(ship.shp_effic), prship(&ship)); + ships++; + } + return ships; } int num_shipsatxy(coord x, coord y, int wantflags, int nowantflags) { - int ships; - struct nstr_item ni; - struct mchrstr *mp; - struct shpstr ship; + int ships; + struct nstr_item ni; + struct mchrstr *mp; + struct shpstr ship; - ships = 0; - snxtitem_xy(&ni, EF_SHIP, x, y); - while (nxtitem(&ni, (s_char *)&ship)) { - if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) - continue; - mp = &mchr[(int)ship.shp_type]; - if (wantflags) { - if ((mp->m_flags & wantflags) == 0) - continue; - } - if (nowantflags) { - if (mp->m_flags & nowantflags) - continue; - } - ships++; + ships = 0; + snxtitem_xy(&ni, EF_SHIP, x, y); + while (nxtitem(&ni, (s_char *)&ship)) { + if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) + continue; + mp = &mchr[(int)ship.shp_type]; + if (wantflags) { + if ((mp->m_flags & wantflags) == 0) + continue; + } + if (nowantflags) { + if (mp->m_flags & nowantflags) + continue; } - return ships; + ships++; + } + return ships; } /* @@ -299,16 +294,16 @@ num_shipsatxy(coord x, coord y, int wantflags, int nowantflags) int islist(s_char *p) { - register int x; + register int x; - x=0; + x = 0; - while(*(p+x)){ - if (!isdigit(*(p+x)) && (*(p+x) != '/')) - return 0; + while (*(p + x)) { + if (!isdigit(*(p + x)) && (*(p + x) != '/')) + return 0; - x++; - } + x++; + } - return 1; + return 1; } diff --git a/src/lib/subs/lndsub.c b/src/lib/subs/lndsub.c index 5311c7de2..0dfa8af8d 100644 --- a/src/lib/subs/lndsub.c +++ b/src/lib/subs/lndsub.c @@ -58,267 +58,272 @@ 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; - - if (((int)lp->lnd_effic) < LAND_MINEFF){ - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own=0; - putland(lp->lnd_uid,lp); - return 0; - } + extern double assault_penalty; + int men; + int value; + struct lchrstr *lcp; + + if (((int)lp->lnd_effic) < LAND_MINEFF) { + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); + lp->lnd_own = 0; + putland(lp->lnd_uid, lp); + return 0; + } - lcp = &lchr[(int)lp->lnd_type]; + lcp = &lchr[(int)lp->lnd_type]; /* Spies always count as 1 during assaults. If they are the only ones in the assault, they get to sneak on anyway. */ - if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT) - return 1; - - men = total_mil(lp); + if (lcp->l_flags & L_SPY && combat_mode == A_ASSAULT) + return 1; - value = ldround(((double)men*(double)lp->lnd_att),1); + men = total_mil(lp); - value = (int)((double)value * ((double)lp->lnd_effic / 100.0)); + value = ldround(((double)men * (double)lp->lnd_att), 1); - switch (combat_mode) { - case A_ATTACK: - return value; - case A_ASSAULT: - if (!(lcp->l_flags & L_MARINE)) - return (int)(assault_penalty * value); - break; - case A_BOARD: - if (!(lcp->l_flags & L_MARINE)) - return (int)(assault_penalty * men); - } + value = (int)((double)value * ((double)lp->lnd_effic / 100.0)); + switch (combat_mode) { + case A_ATTACK: return value; + case A_ASSAULT: + if (!(lcp->l_flags & L_MARINE)) + return (int)(assault_penalty * value); + break; + case A_BOARD: + if (!(lcp->l_flags & L_MARINE)) + return (int)(assault_penalty * men); + } + + return value; } + int defense_val(struct lndstr *lp) { - extern int land_mob_max; - int men; - double value; - struct lchrstr *lcp; - - if (((int)lp->lnd_effic) < LAND_MINEFF){ - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own=0; - putland(lp->lnd_uid,lp); - return 0; - } + extern int land_mob_max; + int men; + double value; + struct lchrstr *lcp; + + if (((int)lp->lnd_effic) < LAND_MINEFF) { + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); + lp->lnd_own = 0; + putland(lp->lnd_uid, lp); + return 0; + } - lcp = &lchr[(int)lp->lnd_type]; + lcp = &lchr[(int)lp->lnd_type]; - men = total_mil(lp); + men = total_mil(lp); - if (men < 0) - men = 0; - if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) && - !(lcp->l_flags & L_MARINE)) - return men; + if (men < 0) + men = 0; + if ((lp->lnd_ship >= 0 || lp->lnd_land >= 0) && + !(lcp->l_flags & L_MARINE)) + return men; - value = men * lp->lnd_def; + value = men * lp->lnd_def; - value *= ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max; - value = (int)((double)value * ((double)lp->lnd_effic / 100.0)); - value = (int)ldround(value, 1); + value *= + ((double)land_mob_max + lp->lnd_harden) / (double)land_mob_max; + value = (int)((double)value * ((double)lp->lnd_effic / 100.0)); + value = (int)ldround(value, 1); - /* If there are military on the unit, you get at least a 1 - man defensive unit, except for spies */ - if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY)) - return 1; + /* If there are military on the unit, you get at least a 1 + man defensive unit, except for spies */ + if (value < 1.0 && men > 0 && !(lcp->l_flags & L_SPY)) + return 1; - return (int)(value); + return (int)(value); } + int total_mil(struct lndstr *lp) { - struct lchrstr *lcp; - double men; + struct lchrstr *lcp; + double men; - lcp = &lchr[(int)lp->lnd_type]; + lcp = &lchr[(int)lp->lnd_type]; - men = lnd_getmil(lp); + men = lnd_getmil(lp); /* men *= ((double)lp->lnd_effic)/100.0;*/ - return ldround(men,1); + return ldround(men, 1); } void lnd_print(struct llist *llp, s_char *s) { - if (llp->land.lnd_own == player->cnum) - pr("%s %s\n",prland(&llp->land), s); - else - wu(0, llp->land.lnd_own, - "%s %s\n",prland(&llp->land),s); + if (llp->land.lnd_own == player->cnum) + pr("%s %s\n", prland(&llp->land), s); + else + wu(0, llp->land.lnd_own, "%s %s\n", prland(&llp->land), s); } void lnd_delete(struct llist *llp, s_char *s) { - if (s) - lnd_print(llp, s); - putland(llp->land.lnd_uid, &llp->land); - emp_remque((struct emp_qelem *)llp); - free((s_char *)llp); + if (s) + lnd_print(llp, s); + putland(llp->land.lnd_uid, &llp->land); + emp_remque((struct emp_qelem *)llp); + free((s_char *)llp); } + int lnd_take_casualty(int combat_mode, struct llist *llp, int cas) - /* attacking or assaulting or paratrooping? */ - - /* number of casualties to take */ + /* attacking or assaulting or paratrooping? */ + /* number of casualties to take */ { - int eff_eq; - int n; - int biggest; - int civs; - int nowned; - coord ret_x, ret_y; - coord bx, by; - struct sctstr sect; - int ret_chance; - s_char buf[1024]; - int taken; - int nowhere_to_go = 0; - struct sctstr rsect; - double mobcost; - s_char orig; - int mob; - - - - taken = lnd_getmil(&(llp->land)); - /* Spies always die */ - if (llp->lcp->l_flags & L_SPY) { - eff_eq = 100; - llp->land.lnd_effic = 0; - } else { - eff_eq = ldround((((double)cas*100.0) / (double)llp->lcp->l_mil),1); - llp->land.lnd_effic -= eff_eq; - lnd_submil(&(llp->land), cas); - } - - if (llp->land.lnd_effic < LAND_MINEFF) { - sprintf(buf, "dies %s %s!", - combat_mode?att_mode[combat_mode]:(s_char*) "defending", - xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own)); - lnd_delete(llp, buf); - /* Since we killed the unit, we killed all the mil on it */ - return taken; - } else { - /* Ok, now, how many did we take off? (sould be the diff) */ - taken = taken - lnd_getmil(&(llp->land)); - } - - if (llp->land.lnd_effic >= llp->land.lnd_retreat) - return taken; + int eff_eq; + int n; + int biggest; + int civs; + int nowned; + coord ret_x, ret_y; + coord bx, by; + struct sctstr sect; + int ret_chance; + s_char buf[1024]; + int taken; + int nowhere_to_go = 0; + struct sctstr rsect; + double mobcost; + s_char orig; + int mob; + + + + taken = lnd_getmil(&(llp->land)); + /* Spies always die */ + if (llp->lcp->l_flags & L_SPY) { + eff_eq = 100; + llp->land.lnd_effic = 0; + } else { + eff_eq = + ldround((((double)cas * 100.0) / (double)llp->lcp->l_mil), 1); + llp->land.lnd_effic -= eff_eq; + lnd_submil(&(llp->land), cas); + } + + if (llp->land.lnd_effic < LAND_MINEFF) { + sprintf(buf, "dies %s %s!", + combat_mode ? att_mode[combat_mode] : (s_char *) + "defending", xyas(llp->land.lnd_x, llp->land.lnd_y, + llp->land.lnd_own)); + lnd_delete(llp, buf); + /* Since we killed the unit, we killed all the mil on it */ + return taken; + } else { + /* Ok, now, how many did we take off? (sould be the diff) */ + taken = taken - lnd_getmil(&(llp->land)); + } - /* we're being boarded */ - if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND) - return taken; + if (llp->land.lnd_effic >= llp->land.lnd_retreat) + return taken; - /* we're being boarded */ - if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND) - return taken; + /* we're being boarded */ + if (llp->land.lnd_ship >= 0 && combat_mode == A_DEFEND) + return taken; - /* Have to make a retreat check */ + /* we're being boarded */ + if (llp->land.lnd_land >= 0 && combat_mode == A_DEFEND) + return taken; - ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic; - if (roll(100) < ret_chance) { - pr("\n"); - lnd_print(llp, "fails morale check!"); - llp->land.lnd_mission = 0; - llp->land.lnd_harden = 0; - if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0) - nowhere_to_go = 1; - else if (combat_mode == A_DEFEND) { - /* - * defending unit.. find a place to send it - * strategy: look for the most-populated - * adjacent sector that is owned by the unit - * player->owner. Charge mob.. - */ - biggest = -1; - nowned = 0; - for(n = 1; n <= 6; ++n) { - ret_x = llp->land.lnd_x + diroff[n][0]; - ret_y = llp->land.lnd_y + diroff[n][1]; - getsect(ret_x, ret_y, §); - if (sect.sct_own != llp->land.lnd_own) - continue; - if (sect.sct_type == SCT_MOUNT) - continue; - ++nowned; - civs = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); - if (civs > biggest){ - biggest = civs; - bx = sect.sct_x; - by = sect.sct_y; - } - } - if (!nowned) - nowhere_to_go = 1; - else { - /* retreat to bx,by */ - llp->land.lnd_x = bx; - llp->land.lnd_y = by; - getsect(bx,by,&rsect); - mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD); - mob = llp->land.lnd_mobil-(int)mobcost; - if (mob < -127) - mob = -127; - orig = llp->land.lnd_mobil; - llp->land.lnd_mobil = (s_char)mob; - if (llp->land.lnd_mobil > orig) - llp->land.lnd_mobil = (-127); - sprintf(buf, "retreats at %d%% efficiency to %s!", - llp->land.lnd_effic, - xyas(bx,by,llp->land.lnd_own)); - lnd_delete(llp, buf); - } - } else { /* attacking from a sector */ - sprintf(buf, "leaves the battlefield at %d%% efficiency", - llp->land.lnd_effic); - if ((llp->land.lnd_mobil - (int)llp->mobil) < -127) - llp->land.lnd_mobil = -127; - else - llp->land.lnd_mobil -= (int)llp->mobil; - llp->mobil = 0.0; - lnd_delete(llp, buf); + /* Have to make a retreat check */ + + ret_chance = llp->land.lnd_retreat - llp->land.lnd_effic; + if (roll(100) < ret_chance) { + pr("\n"); + lnd_print(llp, "fails morale check!"); + llp->land.lnd_mission = 0; + llp->land.lnd_harden = 0; + if (llp->land.lnd_ship >= 0 || llp->land.lnd_land >= 0) + nowhere_to_go = 1; + else if (combat_mode == A_DEFEND) { + /* + * defending unit.. find a place to send it + * strategy: look for the most-populated + * adjacent sector that is owned by the unit + * player->owner. Charge mob.. + */ + biggest = -1; + nowned = 0; + for (n = 1; n <= 6; ++n) { + ret_x = llp->land.lnd_x + diroff[n][0]; + ret_y = llp->land.lnd_y + diroff[n][1]; + getsect(ret_x, ret_y, §); + if (sect.sct_own != llp->land.lnd_own) + continue; + if (sect.sct_type == SCT_MOUNT) + continue; + ++nowned; + civs = getvar(V_CIVIL, (s_char *)§, EF_SECTOR); + if (civs > biggest) { + biggest = civs; + bx = sect.sct_x; + by = sect.sct_y; } + } + if (!nowned) + nowhere_to_go = 1; + else { + /* retreat to bx,by */ + llp->land.lnd_x = bx; + llp->land.lnd_y = by; + getsect(bx, by, &rsect); + mobcost = lnd_mobcost(&llp->land, &rsect, MOB_ROAD); + mob = llp->land.lnd_mobil - (int)mobcost; + if (mob < -127) + mob = -127; + orig = llp->land.lnd_mobil; + llp->land.lnd_mobil = (s_char)mob; + if (llp->land.lnd_mobil > orig) + llp->land.lnd_mobil = (-127); + sprintf(buf, "retreats at %d%% efficiency to %s!", + llp->land.lnd_effic, + xyas(bx, by, llp->land.lnd_own)); + lnd_delete(llp, buf); + } + } else { /* attacking from a sector */ + sprintf(buf, "leaves the battlefield at %d%% efficiency", + llp->land.lnd_effic); + if ((llp->land.lnd_mobil - (int)llp->mobil) < -127) + llp->land.lnd_mobil = -127; + else + llp->land.lnd_mobil -= (int)llp->mobil; + llp->mobil = 0.0; + lnd_delete(llp, buf); } - if (nowhere_to_go) { - /* nowhere to go.. take more casualties */ - llp->land.lnd_effic -= 10; - lnd_submil(&llp->land, llp->lcp->l_mil / 10); - if (llp->land.lnd_effic < LAND_MINEFF) - lnd_delete(llp, "has nowhere to retreat, and dies!"); - else - lnd_print(llp, "has nowhere to retreat and takes extra losses!"); - } + } + if (nowhere_to_go) { + /* nowhere to go.. take more casualties */ + llp->land.lnd_effic -= 10; + lnd_submil(&llp->land, llp->lcp->l_mil / 10); + if (llp->land.lnd_effic < LAND_MINEFF) + lnd_delete(llp, "has nowhere to retreat, and dies!"); + else + lnd_print(llp, + "has nowhere to retreat and takes extra losses!"); + } - return taken; + return taken; } void lnd_takemob(struct emp_qelem *list, double loss) { - extern double combat_mob; - struct emp_qelem *qp, *next; - struct llist *llp; - int new; - int mcost = ldround(combat_mob * loss, 1); - - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - llp = (struct llist *)qp; + extern double combat_mob; + struct emp_qelem *qp, *next; + struct llist *llp; + int new; + int mcost = ldround(combat_mob * loss, 1); + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + llp = (struct llist *)qp; /* if (chance(loss)) use_supply(&llp->land); @@ -326,16 +331,16 @@ lnd_takemob(struct emp_qelem *list, double loss) new = llp->land.lnd_mobil - mcost/2; else */ - new = llp->land.lnd_mobil - mcost; - if (new < -127) - new = -127; - llp->land.lnd_mobil = (s_char)new; - } + new = llp->land.lnd_mobil - mcost; + if (new < -127) + new = -127; + llp->land.lnd_mobil = (s_char)new; + } } int lnd_getmil(struct lndstr *lp) { - int vec[I_MAX+1]; + int vec[I_MAX + 1]; getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); return vec[I_MILIT]; @@ -344,7 +349,7 @@ lnd_getmil(struct lndstr *lp) void lnd_submil(struct lndstr *lp, int num) { - int vec[I_MAX+1]; + int vec[I_MAX + 1]; getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); vec[I_MILIT] -= num; @@ -352,79 +357,84 @@ lnd_submil(struct lndstr *lp, int num) vec[I_MILIT] = 0; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); } + int lnd_spyval(struct lndstr *lp) { - if (lchr[(int)lp->lnd_type].l_flags & L_RECON) - return (lp->lnd_spy * (lp->lnd_effic/100.0))+2; - else - return (lp->lnd_spy * (lp->lnd_effic/100.0)); + if (lchr[(int)lp->lnd_type].l_flags & L_RECON) + return (lp->lnd_spy * (lp->lnd_effic / 100.0)) + 2; + else + return (lp->lnd_spy * (lp->lnd_effic / 100.0)); } int -intelligence_report(int destination, struct lndstr *lp, int spy, s_char *mess) +intelligence_report(int destination, struct lndstr *lp, int spy, + s_char *mess) { - struct lchrstr *lcp; - s_char buf1[80],buf2[80],buf3[80]; - double estimate = 0.0; /* estimated defense value */ + struct lchrstr *lcp; + s_char buf1[80], buf2[80], buf3[80]; + double estimate = 0.0; /* estimated defense value */ + + if (destination == 0) + return 0; - if (destination == 0) - return 0; + if (lp->lnd_own == 0) + return 0; + + lcp = &lchr[(int)lp->lnd_type]; + + bzero(buf1, 80); + bzero(buf2, 80); + bzero(buf3, 80); + if (chance((double)(spy + lp->lnd_vis) / 10.0)) { + if (destination == player->cnum) + pr("%s %s", mess, prland(lp)); + else + sprintf(buf1, "%s %s", mess, prland(lp)); + + estimate = lnd_getmil(lp); - if (lp->lnd_own == 0) - return 0; + if (chance((double)(spy + lp->lnd_vis) / 20.0)) { - lcp = &lchr[(int)lp->lnd_type]; + if (destination == player->cnum) + pr(" (eff %d, mil %d", roundintby(lp->lnd_effic, 5), + roundintby(lnd_getmil(lp), 10)); + else + sprintf(buf2, " (eff %d, mil %d", + roundintby(lp->lnd_effic, 5), + roundintby(lnd_getmil(lp), 10)); + estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0; - bzero(buf1,80); - bzero(buf2,80); - bzero(buf3,80); - if (chance((double)(spy+lp->lnd_vis)/10.0)){ + if (chance((double)(spy + lp->lnd_vis) / 20.0)) { + int t; + t = lp->lnd_tech - 20 + roll(40); + t = max(t, 0); + if (destination == player->cnum) + pr(", tech %d)\n", t); + else + sprintf(buf3, ", tech %d)\n", t); + } else { if (destination == player->cnum) - pr("%s %s", mess, prland(lp)); + pr(")\n"); else - sprintf(buf1,"%s %s", mess, prland(lp)); - - estimate = lnd_getmil(lp); - - if (chance((double)(spy+lp->lnd_vis)/20.0)){ - - if (destination == player->cnum) - pr(" (eff %d, mil %d", roundintby(lp->lnd_effic,5), roundintby(lnd_getmil(lp),10)); - else - sprintf(buf2," (eff %d, mil %d", roundintby(lp->lnd_effic,5), roundintby(lnd_getmil(lp),10)); - estimate = lnd_getmil(lp) * lp->lnd_effic / 100.0; - - if (chance((double)(spy+lp->lnd_vis)/20.0)){ - int t; - t = lp->lnd_tech - 20 + roll(40); - t = max(t,0); - if (destination == player->cnum) - pr(", tech %d)\n",t); - else - sprintf(buf3,", tech %d)\n",t); - }else{ - if (destination == player->cnum) - pr(")\n"); - else - sprintf(buf3,")\n"); - } - }else{ - if (destination == player->cnum) - pr("\n"); - else - sprintf(buf2,"\n"); - } + sprintf(buf3, ")\n"); + } + } else { + if (destination == player->cnum) + pr("\n"); + else + sprintf(buf2, "\n"); } + } - if (destination != player->cnum){ - wu(0, destination, "%s%s%s",buf1,buf2,buf3); - } + if (destination != player->cnum) { + wu(0, destination, "%s%s%s", buf1, buf2, buf3); + } - if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE) - estimate *= lp->lnd_def; + if (lp->lnd_ship < 0 || lcp->l_flags & L_MARINE) + estimate *= lp->lnd_def; - return (int)estimate; + return (int)estimate; } /* Used by the spy command to count land units in a sector. If used @@ -433,108 +443,109 @@ intelligence_report(int destination, struct lndstr *lp, int spy, s_char *mess) int count_sect_units(struct sctstr *sp) { - int count = 0; - double odds; - struct nstr_item ni; - struct lndstr land; - - snxtitem_all(&ni, EF_LAND); - while (nxtitem(&ni, (s_char *)&land)) { - if (!land.lnd_own) - continue; - if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y) - continue; - /* Don't always see spies */ - if (lchr[(int)land.lnd_type].l_flags & L_SPY) { - odds = (double)(100 - land.lnd_effic) + 0.10; - if (!(chance(odds))) - continue; - } - /* Got here, report it */ - ++count; + int count = 0; + double odds; + struct nstr_item ni; + struct lndstr land; + + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (!land.lnd_own) + continue; + if (land.lnd_x != sp->sct_x || land.lnd_y != sp->sct_y) + continue; + /* Don't always see spies */ + if (lchr[(int)land.lnd_type].l_flags & L_SPY) { + odds = (double)(100 - land.lnd_effic) + 0.10; + if (!(chance(odds))) + continue; } + /* Got here, report it */ + ++count; + } - return count; + return count; } void count_units(struct shpstr *sp) { - struct nstr_item ni; - struct lndstr land; - int nland = 0; - - if (sp->shp_effic < SHIP_MINEFF) - return; - - snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == 0) - continue; - if (land.lnd_ship == sp->shp_uid) - nland++; - } - - if (sp->shp_nland != nland) { - sp->shp_nland = nland; - putship(sp->shp_uid,sp); - } + struct nstr_item ni; + struct lndstr land; + int nland = 0; + + if (sp->shp_effic < SHIP_MINEFF) + return; + + snxtitem_xy(&ni, EF_LAND, sp->shp_x, sp->shp_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_ship == sp->shp_uid) + nland++; + } + + if (sp->shp_nland != nland) { + sp->shp_nland = nland; + putship(sp->shp_uid, sp); + } } void lnd_count_units(struct lndstr *lp) { - struct nstr_item ni; - struct lndstr land; - int nland = 0; - - if (lp->lnd_effic < LAND_MINEFF) - return; - - snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y); - while (nxtitem(&ni, (s_char *)&land)){ - if (land.lnd_own == 0) - continue; - if (land.lnd_land == lp->lnd_uid) - nland++; - } - - if (lp->lnd_nland != nland) { - lp->lnd_nland = nland; - putland(lp->lnd_uid,lp); - } + struct nstr_item ni; + struct lndstr land; + int nland = 0; + + if (lp->lnd_effic < LAND_MINEFF) + return; + + snxtitem_xy(&ni, EF_LAND, lp->lnd_x, lp->lnd_y); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_own == 0) + continue; + if (land.lnd_land == lp->lnd_uid) + nland++; + } + + if (lp->lnd_nland != nland) { + lp->lnd_nland = nland; + putland(lp->lnd_uid, lp); + } } void lnd_sel(struct nstr_item *ni, struct emp_qelem *list) - - + + /* int wantflags; int nowantflags; */ { - struct lndstr land; - struct lchrstr *lcp; - struct llist *llp; - - emp_initque(list); - while (nxtitem(ni, (s_char *)&land)) { - if (!player->owner) - continue; - if (opt_MARKET) { - if (ontradingblock(EF_LAND, (int *)&land)) { - pr("unit #%d inelligible - it's for sale.\n", land.lnd_uid); - continue; - } - } - lcp = &lchr[(int)land.lnd_type]; + struct lndstr land; + struct lchrstr *lcp; + struct llist *llp; + + emp_initque(list); + while (nxtitem(ni, (s_char *)&land)) { + if (!player->owner) + continue; + if (opt_MARKET) { + if (ontradingblock(EF_LAND, (int *)&land)) { + pr("unit #%d inelligible - it's for sale.\n", + land.lnd_uid); + continue; + } + } + lcp = &lchr[(int)land.lnd_type]; /* if (wantflags && (lcp->m_flags & wantflags) != wantflags) continue; if (nowantflags && lcp->m_flags & nowantflags) continue; */ /* This abuse is better fixed by building a unit with the normal negative - mobility that everything else is built with */ + mobility that everything else is built with */ /* Just so that the player can't build a bunch of land units, and them march them a few minutes later... */ /* @@ -547,376 +558,379 @@ lnd_sel(struct nstr_item *ni, struct emp_qelem *list) } } */ - land.lnd_mission = 0; - land.lnd_rflags = 0; - land.lnd_harden = 0; - bzero(land.lnd_rpath,RET_LEN); - putland(land.lnd_uid, &land); - llp = (struct llist *) malloc(sizeof(struct llist)); - llp->lcp = lcp; - bcopy((s_char *)&land, (s_char *)&llp->land, - sizeof(struct lndstr)); - llp->mobil = (double)land.lnd_mobil; - emp_insque(&llp->queue, list); - } + land.lnd_mission = 0; + land.lnd_rflags = 0; + land.lnd_harden = 0; + bzero(land.lnd_rpath, RET_LEN); + putland(land.lnd_uid, &land); + llp = (struct llist *)malloc(sizeof(struct llist)); + llp->lcp = lcp; + bcopy((s_char *)&land, (s_char *)&llp->land, + sizeof(struct lndstr)); + llp->mobil = (double)land.lnd_mobil; + emp_insque(&llp->queue, list); + } } /* This function assumes that the list was created by lnd_sel */ void -lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp, int *togetherp, natid actor) +lnd_mar(struct emp_qelem *list, double *minmobp, double *maxmobp, + int *togetherp, natid actor) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - struct sctstr sect; - struct lndstr land; - coord allx; - coord ally; - int first=1; - s_char mess[128]; - int rel; - - *minmobp = 9876.0; - *maxmobp = -9876.0; - *togetherp = 1; - for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - llp = (struct llist *) qp; - getland(llp->land.lnd_uid, &land); - if (land.lnd_own != actor) { - mpr(actor, "%s was disbanded at %s\n", - prland(&land), - xyas(land.lnd_x, land.lnd_y, land.lnd_own)); - emp_remque((struct emp_qelem *)llp); - free((s_char *)llp); - continue; - } - if (land.lnd_ship >= 0) { - lnd_mess("is on a ship", llp); - continue; - } - if (land.lnd_land >= 0) { - lnd_mess("is on a unit", llp); - continue; - } - if (!getsect(land.lnd_x, land.lnd_y, §)) { - lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */ - continue; - } - if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && - !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) && - lnd_getmil(&llp->land) == 0) { - lnd_mess("has no mil on it to guide it", llp); - continue; - } - rel = getrel(getnatp(sect.sct_own), player->cnum); - if (sect.sct_own != land.lnd_own && rel != ALLIED && - !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && - sect.sct_own) { - sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own)); - lnd_mess(mess, llp); - continue; - } - if (first){ - allx = land.lnd_x; - ally = land.lnd_y; - first = 0; - } - if (land.lnd_x != allx || - land.lnd_y != ally) - *togetherp = 0; - if (land.lnd_mobil + 1 < (int)llp->mobil) { - llp->mobil = (double)land.lnd_mobil; - } - if (llp->mobil < *minmobp) - *minmobp = llp->mobil; - if (llp->mobil > *maxmobp) - *maxmobp = llp->mobil; - bcopy((s_char *)&land, (s_char *)&llp->land, - sizeof(struct lndstr)); + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + struct sctstr sect; + struct lndstr land; + coord allx; + coord ally; + int first = 1; + s_char mess[128]; + int rel; + + *minmobp = 9876.0; + *maxmobp = -9876.0; + *togetherp = 1; + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + getland(llp->land.lnd_uid, &land); + if (land.lnd_own != actor) { + mpr(actor, "%s was disbanded at %s\n", + prland(&land), xyas(land.lnd_x, land.lnd_y, land.lnd_own)); + emp_remque((struct emp_qelem *)llp); + free((s_char *)llp); + continue; + } + if (land.lnd_ship >= 0) { + lnd_mess("is on a ship", llp); + continue; + } + if (land.lnd_land >= 0) { + lnd_mess("is on a unit", llp); + continue; + } + if (!getsect(land.lnd_x, land.lnd_y, §)) { + lnd_mess("was sucked into the sky by a strange looking spaceland", llp); /* heh -KHS */ + continue; + } + if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && + !(lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) && + lnd_getmil(&llp->land) == 0) { + lnd_mess("has no mil on it to guide it", llp); + continue; } + rel = getrel(getnatp(sect.sct_own), player->cnum); + if (sect.sct_own != land.lnd_own && rel != ALLIED && + !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && + sect.sct_own) { + sprintf(mess, "has been kidnapped by %s", cname(sect.sct_own)); + lnd_mess(mess, llp); + continue; + } + if (first) { + allx = land.lnd_x; + ally = land.lnd_y; + first = 0; + } + if (land.lnd_x != allx || land.lnd_y != ally) + *togetherp = 0; + if (land.lnd_mobil + 1 < (int)llp->mobil) { + llp->mobil = (double)land.lnd_mobil; + } + if (llp->mobil < *minmobp) + *minmobp = llp->mobil; + if (llp->mobil > *maxmobp) + *maxmobp = llp->mobil; + bcopy((s_char *)&land, (s_char *)&llp->land, + sizeof(struct lndstr)); + } } void lnd_put(struct emp_qelem *list, natid actor) { - register struct emp_qelem *qp; - register struct emp_qelem *newqp; - struct llist *llp; - - qp = list->q_back; - while (qp != list) { - llp = (struct llist *) qp; - if (actor) { - mpr(actor, "%s stopped at %s\n", prland(&llp->land), - xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own)); - if (llp->mobil < -127) - llp->mobil = -127; - llp->land.lnd_mobil = llp->mobil; - } - putland(llp->land.lnd_uid, &llp->land); - newqp = qp->q_back; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + register struct emp_qelem *qp; + register struct emp_qelem *newqp; + struct llist *llp; + + qp = list->q_back; + while (qp != list) { + llp = (struct llist *)qp; + if (actor) { + mpr(actor, "%s stopped at %s\n", prland(&llp->land), + xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own)); + if (llp->mobil < -127) + llp->mobil = -127; + llp->land.lnd_mobil = llp->mobil; } + putland(llp->land.lnd_uid, &llp->land); + newqp = qp->q_back; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } } void -lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob, natid actor) +lnd_sweep(struct emp_qelem *land_list, int verbose, int takemob, + natid actor) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - struct sctstr sect; - int mines, m, max, sshells, lshells; - double mobcost; - - for (qp=land_list->q_back;qp!=land_list;qp=next) { - next = qp->q_back; - llp = (struct llist *) qp; - if (!(llp->lcp->l_flags & L_ENGINEER)) { - if (verbose) - mpr(actor, "%s is not an engineer!\n", - prland(&llp->land)); - continue; - } - if (takemob && llp->mobil < 0.0) { - if (verbose) - lnd_mess("is out of mobility", llp); - continue; - } - getsect(llp->land.lnd_x,llp->land.lnd_y,§); - if (sect.sct_oldown == llp->land.lnd_own) { - if (verbose) - mpr(actor, "%s is in a sector completely owned by you. Don't bother digging up mines there!\n", - prland(&llp->land)); - continue; - } - if (sect.sct_type == SCT_BSPAN) { - if (verbose) - mpr(actor, "%s is on a bridge. No mines there!\n", prland(&llp->land)); - continue; - } - if (takemob) { + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + struct sctstr sect; + int mines, m, max, sshells, lshells; + double mobcost; + + for (qp = land_list->q_back; qp != land_list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + if (!(llp->lcp->l_flags & L_ENGINEER)) { + if (verbose) + mpr(actor, "%s is not an engineer!\n", prland(&llp->land)); + continue; + } + if (takemob && llp->mobil < 0.0) { + if (verbose) + lnd_mess("is out of mobility", llp); + continue; + } + getsect(llp->land.lnd_x, llp->land.lnd_y, §); + if (sect.sct_oldown == llp->land.lnd_own) { + if (verbose) + mpr(actor, + "%s is in a sector completely owned by you. Don't bother digging up mines there!\n", + prland(&llp->land)); + continue; + } + if (sect.sct_type == SCT_BSPAN) { + if (verbose) + mpr(actor, "%s is on a bridge. No mines there!\n", + prland(&llp->land)); + continue; + } + if (takemob) { /* mobcost = llp->land.lnd_effic * 0.01 * llp->lcp->l_spd;*/ - mobcost = llp->land.lnd_spd; - mobcost = 480.0 / (mobcost + - techfact(llp->land.lnd_tech,mobcost)); - llp->mobil -= mobcost; - llp->land.lnd_mobil = (int)llp->mobil; - } - putland(llp->land.lnd_uid, &llp->land); - if (!(mines=getvar(V_MINE,(s_char *)§,EF_SECTOR))) - 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 *)§, EF_SECTOR); - 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 - ++sshells; - } - } - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND); - putvar(V_SHELL, sshells, (s_char *)§, EF_SECTOR); - putland(llp->land.lnd_uid, &llp->land); - putsect(§); + mobcost = llp->land.lnd_spd; + mobcost = 480.0 / (mobcost + + techfact(llp->land.lnd_tech, mobcost)); + llp->mobil -= mobcost; + llp->land.lnd_mobil = (int)llp->mobil; } + putland(llp->land.lnd_uid, &llp->land); + if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR))) + 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 *)§, EF_SECTOR); + 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 + ++sshells; + } + } + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putvar(V_SHELL, lshells, (s_char *)&llp->land, EF_LAND); + putvar(V_SHELL, sshells, (s_char *)§, EF_SECTOR); + putland(llp->land.lnd_uid, &llp->land); + putsect(§); + } } static int contains_engineer(struct emp_qelem *list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - - for (qp=list->q_back;qp!=list;qp=next) { - next = qp->q_back; - llp = (struct llist *) qp; - if (llp->lcp->l_flags & L_ENGINEER) - return 1; - } - return 0; + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + if (llp->lcp->l_flags & L_ENGINEER) + return 1; + } + return 0; } int lnd_check_mines(struct emp_qelem *land_list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - struct sctstr sect; - int mines; - int stopping = 0; - int has_engineers = contains_engineer(land_list); - - for (qp=land_list->q_back;qp!=land_list;qp=next) { - next = qp->q_back; - llp = (struct llist *) qp; - getsect(llp->land.lnd_x,llp->land.lnd_y,§); - if (sect.sct_oldown == llp->land.lnd_own) - continue; - if (sect.sct_type == SCT_BSPAN) - continue; - if (!(mines=getvar(V_MINE,(s_char *)§,EF_SECTOR))) - continue; - if (chance(DMINE_LHITCHANCE(mines)/(1 + 2*has_engineers))) { - lnd_hit_mine(&llp->land, llp->lcp); - mines--; - putvar(V_MINE,mines,(s_char *)§,EF_SECTOR); - putsect(§); - putland(llp->land.lnd_uid, (s_char *)&llp->land); - if (!llp->land.lnd_own) { - stopping = 1; - emp_remque(qp); - free((s_char *)qp); - } - } + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + struct sctstr sect; + int mines; + int stopping = 0; + int has_engineers = contains_engineer(land_list); + + for (qp = land_list->q_back; qp != land_list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + getsect(llp->land.lnd_x, llp->land.lnd_y, §); + if (sect.sct_oldown == llp->land.lnd_own) + continue; + if (sect.sct_type == SCT_BSPAN) + continue; + if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR))) + continue; + if (chance(DMINE_LHITCHANCE(mines) / (1 + 2 * has_engineers))) { + lnd_hit_mine(&llp->land, llp->lcp); + mines--; + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putsect(§); + putland(llp->land.lnd_uid, (s_char *)&llp->land); + if (!llp->land.lnd_own) { + stopping = 1; + emp_remque(qp); + free((s_char *)qp); + } } - return stopping; + } + return stopping; } void lnd_list(struct emp_qelem *land_list) { - struct emp_qelem *qp; - 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"); - - for (qp=land_list->q_back;qp!=land_list;qp=next) { - next = qp->q_back; - llp = (struct llist *) qp; - lnd = &llp->land; - pr("%4d ", lnd->lnd_uid); - pr("%-16.16s ", llp->lcp->l_name); - 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]); - count_land_planes(lnd); - pr("%3d",lnd->lnd_nxlight); - pr("%4d", lnd->lnd_mobil); - pr("%4d", lnd->lnd_tech); - pr("%4d%%", lnd->lnd_retreat); - pr("%5d\n", lnd->lnd_fuel); - } + struct emp_qelem *qp; + 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"); + + for (qp = land_list->q_back; qp != land_list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + lnd = &llp->land; + pr("%4d ", lnd->lnd_uid); + pr("%-16.16s ", llp->lcp->l_name); + 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]); + count_land_planes(lnd); + pr("%3d", lnd->lnd_nxlight); + pr("%4d", lnd->lnd_mobil); + pr("%4d", lnd->lnd_tech); + pr("%4d%%", lnd->lnd_retreat); + pr("%5d\n", lnd->lnd_fuel); + } } -void +void lnd_mess(s_char *str, struct llist *llp) { - mpr(llp->land.lnd_own, "%s %s & stays in %s\n", - prland(&llp->land), - str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own)); - if (llp->mobil < -127) - llp->mobil = -127; - llp->land.lnd_mobil = llp->mobil; - putland(llp->land.lnd_uid, &llp->land); - emp_remque((struct emp_qelem *)llp); - free((s_char *)llp); + mpr(llp->land.lnd_own, "%s %s & stays in %s\n", + prland(&llp->land), + str, xyas(llp->land.lnd_x, llp->land.lnd_y, llp->land.lnd_own)); + if (llp->mobil < -127) + llp->mobil = -127; + llp->land.lnd_mobil = llp->mobil; + putland(llp->land.lnd_uid, &llp->land); + emp_remque((struct emp_qelem *)llp); + free((s_char *)llp); } static int lnd_count(struct emp_qelem *list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - int count = 0; - - for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - llp = (struct llist *) qp; - ++count; - } - return count; + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + int count = 0; + + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + ++count; + } + return count; } static int lnd_damage(struct emp_qelem *list, int totdam) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - int dam; - int count; - - if (!totdam || !(count = lnd_count(list))) - return 0; - dam = ldround(((double)totdam/(double)count),1); - for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - llp = (struct llist *) qp; - /* have to get it again because of collateral damage */ - getland(llp->land.lnd_uid, &llp->land); - landdamage(&llp->land, dam); - putland(llp->land.lnd_uid, &llp->land); - if (!llp->land.lnd_own) { - emp_remque(qp); - free((s_char *)qp); - } + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + int dam; + int count; + + if (!totdam || !(count = lnd_count(list))) + return 0; + dam = ldround(((double)totdam / (double)count), 1); + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + /* have to get it again because of collateral damage */ + getland(llp->land.lnd_uid, &llp->land); + landdamage(&llp->land, dam); + putland(llp->land.lnd_uid, &llp->land); + if (!llp->land.lnd_own) { + emp_remque(qp); + free((s_char *)qp); } - return dam; + } + return dam; } -static int lnd_easiest_target(struct emp_qelem *list) +static int +lnd_easiest_target(struct emp_qelem *list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct llist *llp; - int hard; - int easiest = 9876; /* things start great for victim */ - int count = 0; - - for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - llp = (struct llist *) qp; - hard = lnd_hardtarget(&llp->land); - if (hard < easiest) - easiest = hard; /* things get worse for victim */ - ++count; - } - return easiest - count; + struct emp_qelem *qp; + struct emp_qelem *next; + struct llist *llp; + int hard; + int easiest = 9876; /* things start great for victim */ + int count = 0; + + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + hard = lnd_hardtarget(&llp->land); + if (hard < easiest) + easiest = hard; /* things get worse for victim */ + ++count; + } + return easiest - count; } static int -lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, natid victim) +lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, + natid victim) { - int dam; - struct emp_qelem msl_list, *qp, *newqp; - - msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT); - - dam = msl_launch_mindam(&msl_list, newx, newy, - lnd_easiest_target(list), EF_LAND, - lnd_count(list) * 20, "troops", victim, - MI_INTERDICT); - if (dam) { - mpr(victim, "missile interdiction mission does %d damage!\n", dam); - collateral_damage(newx, newy, dam, 0); - } - qp = msl_list.q_forw; - while(qp != msl_list.q_forw) { - newqp=qp->q_forw; - emp_remque(qp); - free(qp); - qp = newqp; - } - return dam; + int dam; + struct emp_qelem msl_list, *qp, *newqp; + + msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT); + + dam = msl_launch_mindam(&msl_list, newx, newy, + lnd_easiest_target(list), EF_LAND, + lnd_count(list) * 20, "troops", victim, + MI_INTERDICT); + if (dam) { + mpr(victim, "missile interdiction mission does %d damage!\n", dam); + collateral_damage(newx, newy, dam, 0); + } + qp = msl_list.q_forw; + while (qp != msl_list.q_forw) { + newqp = qp->q_forw; + emp_remque(qp); + free(qp); + qp = newqp; + } + return dam; } #if 0 @@ -924,291 +938,295 @@ lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, natid v /* risner: allow forts to interdict land units. */ static int lnd_fort_interdiction(struct emp_qelem *list, - coord newx, coord newy, natid victim) + coord newx, coord newy, natid victim) { - extern int fort_max_interdiction_range; - struct nstr_sect ns; - struct sctstr fsect; - int trange; - double range, range2, guneff; - int shell, gun; - int dam; - int totdam = 0; - int i; - - snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range); - while (nxtsct(&ns,&fsect)) { - if (fsect.sct_own == 0) - continue; - if (fsect.sct_own == victim) - continue; - if (fsect.sct_type != SCT_FORTR) - continue; - if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL) - continue; - gun = getvar(V_GUN,(s_char *)&fsect,EF_SECTOR); - if (gun < 1) - continue; - range = tfactfire(fsect.sct_own,(double)min(gun,7)); - if (fsect.sct_effic > 59) - range++; - range2 = roundrange(range); - trange = mapdist(newx, newy, - fsect.sct_x, fsect.sct_y); - if (trange > range2) - continue; - if (getvar(V_MILIT,(s_char *)&fsect,EF_SECTOR)<5) - continue; - shell = getvar(V_SHELL,(s_char *)&fsect,EF_SECTOR); - 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); - putsect(&fsect); - if (gun > 7) - gun = 7; - guneff = landgun((int)fsect.sct_effic, gun); - dam = (int)guneff; - totdam += dam; - mpr(victim, "Incoming fire does %d damage!\n", dam); - wu(0,fsect.sct_own, - "%s fires at %s land units in %s for %d!\n", - xyas(fsect.sct_x,fsect.sct_y, - fsect.sct_own), - cname(victim), - xyas(newx,newy,fsect.sct_own), dam); - nreport(fsect.sct_own, N_SCT_SHELL, victim, 1); - } - if (totdam > 0) - return lnd_damage(list, totdam); - return 0; + extern int fort_max_interdiction_range; + struct nstr_sect ns; + struct sctstr fsect; + int trange; + double range, range2, guneff; + int shell, gun; + int dam; + int totdam = 0; + int i; + + snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range); + while (nxtsct(&ns, &fsect)) { + if (fsect.sct_own == 0) + continue; + if (fsect.sct_own == victim) + continue; + if (fsect.sct_type != SCT_FORTR) + continue; + if (getrel(getnatp(fsect.sct_own), victim) >= NEUTRAL) + continue; + gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR); + if (gun < 1) + continue; + range = tfactfire(fsect.sct_own, (double)min(gun, 7)); + if (fsect.sct_effic > 59) + range++; + range2 = roundrange(range); + trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y); + if (trange > range2) + continue; + if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5) + continue; + shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR); + 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); + putsect(&fsect); + if (gun > 7) + gun = 7; + guneff = landgun((int)fsect.sct_effic, gun); + dam = (int)guneff; + totdam += dam; + mpr(victim, "Incoming fire does %d damage!\n", dam); + wu(0, fsect.sct_own, + "%s fires at %s land units in %s for %d!\n", + xyas(fsect.sct_x, fsect.sct_y, + fsect.sct_own), + cname(victim), xyas(newx, newy, fsect.sct_own), dam); + nreport(fsect.sct_own, N_SCT_SHELL, victim, 1); + } + if (totdam > 0) + return lnd_damage(list, totdam); + return 0; } #endif int lnd_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim) { - int stopping = 0; + int stopping = 0; #if 0 - if (!opt_NO_FORT_FIRE) + if (!opt_NO_FORT_FIRE) /* Steve M. - commented out for now until abuse is decided upon */ - stopping |= lnd_fort_interdiction(list, newx, newy, victim); + stopping |= lnd_fort_interdiction(list, newx, newy, victim); #endif - stopping |= lnd_damage(list, unit_interdict(newx,newy,victim,"land units", lnd_easiest_target(list), MI_INTERDICT)); + stopping |= + lnd_damage(list, + unit_interdict(newx, newy, victim, "land units", + lnd_easiest_target(list), MI_INTERDICT)); - stopping |= lnd_damage(list, lnd_missile_interdiction(list,newx,newy,victim)); - return stopping; + stopping |= + lnd_damage(list, + lnd_missile_interdiction(list, newx, newy, victim)); + return stopping; } /* high value of hardtarget is harder to hit */ int lnd_hardtarget(struct lndstr *lp) { - struct sctstr sect; + struct sctstr sect; - getsect(lp->lnd_x, lp->lnd_y, §); - return (int)(((double)lp->lnd_effic/100.0) * - (10 + dchr[sect.sct_type].d_dstr * 2 + - (double)lp->lnd_spd/2.0 - lp->lnd_vis)); + getsect(lp->lnd_x, lp->lnd_y, §); + return (int)(((double)lp->lnd_effic / 100.0) * + (10 + dchr[sect.sct_type].d_dstr * 2 + + (double)lp->lnd_spd / 2.0 - lp->lnd_vis)); } int lnd_hit_mine(struct lndstr *lp, struct lchrstr *lcp) { - double m; + double m; - mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ", - xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + mpr(lp->lnd_own, "Blammo! Landmines detected in %s! ", + xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); - nreport(lp->lnd_own, N_LHIT_MINE, 0, 1); + nreport(lp->lnd_own, N_LHIT_MINE, 0, 1); - m = roll(20) + 10; - if (lcp->l_flags & L_ENGINEER) - m /= 2.0; + m = roll(20) + 10; + if (lcp->l_flags & L_ENGINEER) + m /= 2.0; - landdamage(lp, ldround(m,1)); + landdamage(lp, ldround(m, 1)); - return (int)m; + return (int)m; } double lnd_mobcost(struct lndstr *lp, struct sctstr *sp, int mobtype) { - double mobcost; - double smobcost; - - /* supply unit's speed depends on their eff, since - that is their purpose */ - if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY) - mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd; - else - mobcost = lp->lnd_spd; - if (mobcost < 0.01) - mobcost = 0.01; + double mobcost; + double smobcost; + + /* supply unit's speed depends on their eff, since + that is their purpose */ + if (lchr[(int)lp->lnd_type].l_flags & L_SUPPLY) + mobcost = lp->lnd_effic * 0.01 * lp->lnd_spd; + else + mobcost = lp->lnd_spd; + if (mobcost < 0.01) + mobcost = 0.01; /* sector_mcost now takes 2 different arguments, a sector pointer, and whether or not to figure in the highway bonus, rail bonus or none. bridge heads, bridges and highways have built-in highways bonus because they are a 1, and this will discount that. */ - smobcost = (double)sector_mcost(sp, mobtype); - if (smobcost < 0.01) - smobcost = 0.01; + smobcost = (double)sector_mcost(sp, mobtype); + if (smobcost < 0.01) + smobcost = 0.01; /* marching through 0 mobility conquered sectors takes lots of mobility, unless you are a train. Capturing railways is a good thing. */ - if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 && - smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL) - smobcost = LND_MINMOBCOST; + if (sp->sct_own != sp->sct_oldown && sp->sct_mobil <= 0 && + smobcost < LND_MINMOBCOST && mobtype != MOB_RAIL) + smobcost = LND_MINMOBCOST; - mobcost = smobcost * 5.0 * 480.0 / - (mobcost + techfact(lp->lnd_tech, mobcost)); + mobcost = smobcost * 5.0 * 480.0 / + (mobcost + techfact(lp->lnd_tech, mobcost)); - return mobcost; + return mobcost; } int -lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor, int together) +lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor, + int together) { - struct sctstr sect, osect; - struct emp_qelem *qp; - struct emp_qelem *qp2; - struct emp_qelem *next; - struct llist *llp; - coord dx; - coord dy; - coord newx; - coord newy; - int stopping = 0; - int visible = 0; - int stop; - s_char dp[80]; - int rel; - double odds; - int oldown; - - if (dir <= DIR_STOP || dir >= DIR_VIEW) { - lnd_put(list, actor); + struct sctstr sect, osect; + struct emp_qelem *qp; + struct emp_qelem *qp2; + struct emp_qelem *next; + struct llist *llp; + coord dx; + coord dy; + coord newx; + coord newy; + int stopping = 0; + int visible = 0; + int stop; + s_char dp[80]; + int rel; + double odds; + int oldown; + + if (dir <= DIR_STOP || dir >= DIR_VIEW) { + lnd_put(list, actor); + return 1; + } + dx = diroff[dir][0]; + dy = diroff[dir][1]; + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + llp = (struct llist *)qp; + getsect(llp->land.lnd_x, llp->land.lnd_y, &osect); + oldown = osect.sct_own; + newx = xnorm(llp->land.lnd_x + dx); + newy = ynorm(llp->land.lnd_y + dy); + getsect(newx, newy, §); + rel = getrel(getnatp(sect.sct_own), player->cnum); + if ((sect.sct_own != actor && rel != ALLIED && + !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && + sect.sct_own) || (sect.sct_type == SCT_WATER || + sect.sct_type == SCT_SANCT || + sect.sct_type == SCT_WASTE)) { + if (together) { + pr("can't go to %s\n", xyas(newx, newy, actor)); return 1; + } else { + sprintf(dp, "can't go to %s", xyas(newx, newy, actor)); + lnd_mess(dp, llp); + continue; + } } - dx = diroff[dir][0]; - dy = diroff[dir][1]; - for (qp=list->q_back;qp!=list;qp=next) { - next = qp->q_back; - llp = (struct llist *)qp; - getsect(llp->land.lnd_x, llp->land.lnd_y, &osect); - oldown = osect.sct_own; - newx = xnorm(llp->land.lnd_x + dx); - newy = ynorm(llp->land.lnd_y + dy); - getsect(newx, newy, §); - rel = getrel(getnatp(sect.sct_own), player->cnum); - if ((sect.sct_own != actor && rel != ALLIED && - !(lchr[(int)llp->land.lnd_type].l_flags & L_SPY) && - sect.sct_own) || (sect.sct_type == SCT_WATER || - sect.sct_type == SCT_SANCT || - sect.sct_type == SCT_WASTE)) { - if (together) { - pr("can't go to %s\n",xyas(newx, newy, actor)); - return 1; - } else { - sprintf(dp, "can't go to %s", - xyas(newx, newy, actor)); - lnd_mess(dp, llp); - continue; - } - } - if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY)) visible = 1; - if (sect.sct_rail == 0 && - lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) { - if (together) { - pr("no rail system in %s\n",xyas(newx, newy, actor)); - return 1; - } else { - sprintf(dp, "has no rail system in %s", - xyas(newx, newy, actor)); - lnd_mess(dp, llp); - continue; - } - } - /* 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))) { - stop = 0; - if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) { - stop = 1; - } - /* now check stuff */ - if (!check_sect_ok(§)) - return 1; - if (!check_sect_ok(&osect)) - return 1; - for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) { - if (!check_land_ok(&(((struct llist *)qp2)->land))) - return 1; - } - if (stop) { - lnd_mess("stops", llp); - continue; - } - } - if (llp->mobil <= 0.0) { - lnd_mess("is out of mobility", llp); - continue; - } - llp->land.lnd_x = newx; - llp->land.lnd_y = newy; - if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) { - llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL); - } else { - llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD); - } - llp->land.lnd_mobil = (int)llp->mobil; - putland(llp->land.lnd_uid, &llp->land); - putsect(&osect); - getsect(osect.sct_x, osect.sct_y, &osect); - if (osect.sct_own != oldown && oldown == player->cnum) { - /* It was your sector, now it's not. Simple :) */ - pr("You no longer own %s\n", - xyas(osect.sct_x, osect.sct_y, player->cnum)); - } - if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */ - /* Always a 10% chance of getting caught. */ - odds = (100 - llp->land.lnd_effic) + .10; - if (chance(odds)) { - if (rel == NEUTRAL || rel == FRIENDLY) { - wu(0, sect.sct_own, - "%s unit spotted in %s\n", cname(player->cnum), - xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - setrel(sect.sct_own, llp->land.lnd_own, HOSTILE); - } else if (rel == HOSTILE || rel == AT_WAR || - rel == SITZKRIEG || rel == MOBILIZATION) { - wu(0, sect.sct_own, - "%s spy shot in %s\n", cname(player->cnum), - xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - pr("%s was shot and killed.\n", prland(&llp->land)); - llp->land.lnd_effic = 0; - putland(llp->land.lnd_uid, &llp->land); - lnd_delete(llp, 0); - } - } + if (!(lchr[(int)llp->land.lnd_type].l_flags & L_SPY)) + visible = 1; + if (sect.sct_rail == 0 && + lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) { + if (together) { + pr("no rail system in %s\n", xyas(newx, newy, actor)); + return 1; + } else { + sprintf(dp, "has no rail system in %s", + xyas(newx, newy, actor)); + lnd_mess(dp, llp); + continue; + } + } + /* 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))) { + stop = 0; + if (!want_to_abandon(&osect, V_CIVIL, 0, &(llp->land))) { + stop = 1; + } + /* now check stuff */ + if (!check_sect_ok(§)) + return 1; + if (!check_sect_ok(&osect)) + return 1; + for (qp2 = list->q_back; qp2 != list; qp2 = qp2->q_back) { + if (!check_land_ok(&(((struct llist *)qp2)->land))) + return 1; + } + if (stop) { + lnd_mess("stops", llp); + continue; + } + } + if (llp->mobil <= 0.0) { + lnd_mess("is out of mobility", llp); + continue; + } + llp->land.lnd_x = newx; + llp->land.lnd_y = newy; + if (lchr[(int)llp->land.lnd_type].l_flags & L_TRAIN) { + llp->mobil -= lnd_mobcost(&llp->land, §, MOB_RAIL); + } else { + llp->mobil -= lnd_mobcost(&llp->land, §, MOB_ROAD); + } + llp->land.lnd_mobil = (int)llp->mobil; + putland(llp->land.lnd_uid, &llp->land); + putsect(&osect); + getsect(osect.sct_x, osect.sct_y, &osect); + if (osect.sct_own != oldown && oldown == player->cnum) { + /* It was your sector, now it's not. Simple :) */ + pr("You no longer own %s\n", + xyas(osect.sct_x, osect.sct_y, player->cnum)); + } + if (rel != ALLIED && sect.sct_own != actor && sect.sct_own) { /* must be a spy */ + /* Always a 10% chance of getting caught. */ + odds = (100 - llp->land.lnd_effic) + .10; + if (chance(odds)) { + if (rel == NEUTRAL || rel == FRIENDLY) { + wu(0, sect.sct_own, + "%s unit spotted in %s\n", cname(player->cnum), + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + setrel(sect.sct_own, llp->land.lnd_own, HOSTILE); + } else if (rel == HOSTILE || rel == AT_WAR || + rel == SITZKRIEG || rel == MOBILIZATION) { + wu(0, sect.sct_own, + "%s spy shot in %s\n", cname(player->cnum), + xyas(sect.sct_x, sect.sct_y, sect.sct_own)); + pr("%s was shot and killed.\n", prland(&llp->land)); + llp->land.lnd_effic = 0; + putland(llp->land.lnd_uid, &llp->land); + lnd_delete(llp, 0); } + } } - if (QEMPTY(list)) - return stopping; - lnd_sweep(list, 0, 1, actor); - stopping |= lnd_check_mines(list); - if (QEMPTY(list)) - return stopping; - if (visible) stopping |= lnd_interdict(list, newx, newy, actor); + } + if (QEMPTY(list)) + return stopping; + lnd_sweep(list, 0, 1, actor); + stopping |= lnd_check_mines(list); + if (QEMPTY(list)) return stopping; + if (visible) + stopping |= lnd_interdict(list, newx, newy, actor); + return stopping; } /* @@ -1220,122 +1238,120 @@ lnd_mar_one_sector(struct emp_qelem *list, int dir, natid actor, int together) int lnd_support(natid victim, natid attacker, coord x, coord y) { - struct nstr_item ni; - struct lndstr land; - int rel, rel2; - double dam = 0.0; - int dist; - int shell; - int gun; - double range, range2; - - snxtitem_all(&ni,EF_LAND); - while(nxtitem(&ni,(s_char *)&land)){ - if (land.lnd_frg == 0) - continue; - if ((land.lnd_x == x) && (land.lnd_y == y)) - continue; - if (land.lnd_ship >= 0) - continue; - if (land.lnd_land >= 0) - continue; - if (land.lnd_mission > 0) - continue; - if (land.lnd_effic < LAND_MINFIREEFF) - continue; - /* Do we have mil? */ - if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0) - continue; - rel = getrel(getnatp(land.lnd_own),attacker); - rel2 = getrel(getnatp(land.lnd_own),victim); - if ((land.lnd_own != attacker) && - ((rel != ALLIED) || (rel2 != AT_WAR))) - continue; - - /* do we have supplies? */ - if (!has_supply(&land)) - continue; - - /* are we in range? */ - dist=mapdist(land.lnd_x,land.lnd_y,x,y); - - range=techfact((int)land.lnd_tech, - (double)land.lnd_frg / 2.0); - - range2=roundrange(range); - if (dist>range2) - continue; - - shell = getvar(V_SHELL, (s_char *)&land, EF_LAND); - gun = getvar(V_GUN, (s_char *)&land, EF_LAND); - - if (shell == 0 || gun == 0) - continue; - - use_supply(&land); - nreport(land.lnd_own,N_FIRE_L_ATTACK,victim,1); - if (roll(100) < land.lnd_acc){ - dam += landunitgun(land.lnd_effic, land.lnd_dam, gun, - land.lnd_ammo, shell) / 2; - } else { - dam += landunitgun(land.lnd_effic, land.lnd_dam, gun, - land.lnd_ammo, shell); - } - if (land.lnd_own != attacker) - wu(0,land.lnd_own, - "%s supported %s at %s\n", - prland(&land), - cname(attacker),xyas(x,y,land.lnd_own)); + struct nstr_item ni; + struct lndstr land; + int rel, rel2; + double dam = 0.0; + int dist; + int shell; + int gun; + double range, range2; + + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_frg == 0) + continue; + if ((land.lnd_x == x) && (land.lnd_y == y)) + continue; + if (land.lnd_ship >= 0) + continue; + if (land.lnd_land >= 0) + continue; + if (land.lnd_mission > 0) + continue; + if (land.lnd_effic < LAND_MINFIREEFF) + continue; + /* Do we have mil? */ + if (getvar(V_MILIT, (s_char *)&land, EF_LAND) <= 0) + continue; + rel = getrel(getnatp(land.lnd_own), attacker); + rel2 = getrel(getnatp(land.lnd_own), victim); + if ((land.lnd_own != attacker) && + ((rel != ALLIED) || (rel2 != AT_WAR))) + continue; + + /* do we have supplies? */ + if (!has_supply(&land)) + continue; + + /* are we in range? */ + dist = mapdist(land.lnd_x, land.lnd_y, x, y); + + range = techfact((int)land.lnd_tech, (double)land.lnd_frg / 2.0); + + range2 = roundrange(range); + if (dist > range2) + continue; + + shell = getvar(V_SHELL, (s_char *)&land, EF_LAND); + gun = getvar(V_GUN, (s_char *)&land, EF_LAND); + + if (shell == 0 || gun == 0) + continue; + + use_supply(&land); + nreport(land.lnd_own, N_FIRE_L_ATTACK, victim, 1); + if (roll(100) < land.lnd_acc) { + dam += landunitgun(land.lnd_effic, land.lnd_dam, gun, + land.lnd_ammo, shell) / 2; + } else { + dam += landunitgun(land.lnd_effic, land.lnd_dam, gun, + land.lnd_ammo, shell); } - return (int)dam; + if (land.lnd_own != attacker) + wu(0, land.lnd_own, + "%s supported %s at %s\n", + prland(&land), cname(attacker), xyas(x, y, land.lnd_own)); + } + return (int)dam; } s_char * lnd_path(int together, struct lndstr *lp, s_char *buf) { - coord destx; - coord desty; - struct sctstr d_sect, sect; - s_char *cp; - double dummy; - - if (!sarg_xy(buf, &destx, &desty)) - return 0; - if (!together){ - pr("Cannot go to a destination sector if not all starting in the same sector\n"); - return 0; - } - if (!getsect(destx, desty, &d_sect)) { - pr("%d,%d is not a sector\n", destx, desty); - return 0; - } - getsect(lp->lnd_x, lp->lnd_y, §); - if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN) - cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL); - else - cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD); - if (!cp) { - pr("No owned path from %s to %s!\n", - xyas(lp->lnd_x,lp->lnd_y,player->cnum), - xyas(d_sect.sct_x,d_sect.sct_y,player->cnum)); - return 0; - } - pr("Using path '%s'\n",cp); - return cp; + coord destx; + coord desty; + struct sctstr d_sect, sect; + s_char *cp; + double dummy; + + if (!sarg_xy(buf, &destx, &desty)) + return 0; + if (!together) { + pr("Cannot go to a destination sector if not all starting in the same sector\n"); + return 0; + } + if (!getsect(destx, desty, &d_sect)) { + pr("%d,%d is not a sector\n", destx, desty); + return 0; + } + getsect(lp->lnd_x, lp->lnd_y, §); + if (lchr[(int)lp->lnd_type].l_flags & L_TRAIN) + cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_RAIL); + else + cp = (s_char *)BestLandPath(buf, §, &d_sect, &dummy, MOB_ROAD); + if (!cp) { + pr("No owned path from %s to %s!\n", + xyas(lp->lnd_x, lp->lnd_y, player->cnum), + xyas(d_sect.sct_x, d_sect.sct_y, player->cnum)); + return 0; + } + pr("Using path '%s'\n", cp); + return cp; } int lnd_can_attack(struct lndstr *lp) { - struct lchrstr *lcp = &lchr[(int)lp->lnd_type]; - + struct lchrstr *lcp = &lchr[(int)lp->lnd_type]; + /* if (lcp->l_flags & L_SUPPLY || lcp->l_flags & L_SECURITY || lcp->l_flags & L_FLAK || lcp->l_frg) return 0; */ - if (lcp->l_flags & L_SUPPLY) - return 0; + if (lcp->l_flags & L_SUPPLY) + return 0; - return 1; + return 1; } diff --git a/src/lib/subs/lostsub.c b/src/lib/subs/lostsub.c index ce875f85d..c6ab56c52 100644 --- a/src/lib/subs/lostsub.c +++ b/src/lib/subs/lostsub.c @@ -87,12 +87,12 @@ makenotlost(char type, natid owner, short int id, coord x, coord y) int findlost(char type, natid owner, short int id, coord x, coord y, int free) - - - - - - /* Give me the item of a free slot */ + + + + + + /* Give me the item of a free slot */ { struct loststr lost; int n; diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index c92f9cdbc..cc802e53f 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -57,14 +57,14 @@ #include "prototypes.h" #include "optlist.h" -struct airport{ - struct emp_qelem queue; - coord x,y; - natid own; +struct airport { + struct emp_qelem queue; + coord x, y; + natid own; }; -s_char *mission_name(short int mission); -s_char *nameofitem(s_char *buf, struct genitem *gp, int type); +s_char *mission_name(short int mission); +s_char *nameofitem(s_char *buf, struct genitem *gp, int type); /* * Interdict commodities & transported planes @@ -72,60 +72,60 @@ s_char *nameofitem(s_char *buf, struct genitem *gp, int type); int ground_interdict(coord x, coord y, natid victim, s_char *s) { - register int cn; - int dam=0, newdam, rel; - struct genlist mi[MAXNOC]; - int z; - - bzero((s_char *)mi,sizeof(mi)); - for(z=1;z HOSTILE) - continue; - - if (QEMPTY(&mi[cn].queue)) - continue; - - newdam = perform_mission(x,y,victim,&mi[cn].queue, - MI_INTERDICT,s,SECT_HARDTARGET); - dam += newdam; - if (newdam) - mpr(victim, "%s interdiction mission does %d damage!\n", - cname(cn), newdam); - } - if (dam) { - collateral_damage(x,y,dam, 0); - } - return dam; + register int cn; + int dam = 0, newdam, rel; + struct genlist mi[MAXNOC]; + int z; + + bzero((s_char *)mi, sizeof(mi)); + for (z = 1; z < MAXNOC; z++) + emp_initque((struct emp_qelem *)&mi[z]); + + build_mission_list(mi, x, y, MI_INTERDICT, victim); + + for (cn = 1; cn < MAXNOC; cn++) { + rel = getrel(getnatp(cn), victim); + if (rel > HOSTILE) + continue; + + if (QEMPTY(&mi[cn].queue)) + continue; + + newdam = perform_mission(x, y, victim, &mi[cn].queue, + MI_INTERDICT, s, SECT_HARDTARGET); + dam += newdam; + if (newdam) + mpr(victim, "%s interdiction mission does %d damage!\n", + cname(cn), newdam); + } + if (dam) { + collateral_damage(x, y, dam, 0); + } + return dam; } int collateral_damage(coord x, coord y, int dam, struct emp_qelem *list) { - extern double collateral_dam; - int coll; - struct sctstr sect; - - if (!dam) - return 0; - - getsect(x,y,§); - if (sect.sct_own) { - coll = ldround((double)dam * collateral_dam, 1); - if (coll == 0) - return 0; - mpr(sect.sct_own, "%s takes %d%% collateral damage\n", - xyas(x,y,sect.sct_own), coll); - sectdamage(§, coll, list); - putsect(§); - return coll; - } + extern double collateral_dam; + int coll; + struct sctstr sect; + + if (!dam) return 0; + + getsect(x, y, §); + if (sect.sct_own) { + coll = ldround((double)dam * collateral_dam, 1); + if (coll == 0) + return 0; + mpr(sect.sct_own, "%s takes %d%% collateral damage\n", + xyas(x, y, sect.sct_own), coll); + sectdamage(§, coll, list); + putsect(§); + return coll; + } + return 0; } int @@ -136,7 +136,7 @@ only_subs(struct emp_qelem *list) struct genitem *gp; struct mchrstr *mcp; - for(qp = list->q_forw; qp != list; qp = qp->q_forw) { + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { glp = (struct genlist *)qp; gp = (struct genitem *)glp->thing; @@ -157,54 +157,55 @@ only_subs(struct emp_qelem *list) * */ int -unit_interdict(coord x, coord y, natid victim, s_char *s, int hardtarget, int mission) +unit_interdict(coord x, coord y, natid victim, s_char *s, int hardtarget, + int mission) { - register int cn; - int dam=0, newdam; - struct genlist mi[MAXNOC]; - int z; - int osubs; + register int cn; + int dam = 0, newdam; + struct genlist mi[MAXNOC]; + int z; + int osubs; - bzero((s_char *)mi,sizeof(mi)); - for(z=1;z= FRIENDLY) - continue; - } else if (getrel(getnatp(cn),victim) > HOSTILE) - continue; - - if (QEMPTY(&mi[cn].queue)) - continue; - - osubs = only_subs(&mi[cn].queue); - newdam = perform_mission(x,y,victim,&mi[cn].queue, - mission,s,hardtarget); - dam += newdam; - if (newdam) { - /* If only subs responded, then we don't know who's - subs they are */ - if (osubs) { - mpr(victim, - "Enemy interdiction mission does %d damage!\n", - newdam); - } else { - mpr(victim, - "%s interdiction mission does %d damage!\n", - cname(cn), newdam); - } - } - } - if (dam) { - collateral_damage(x,y,dam, 0); - } - return dam; + for (cn = 1; cn < MAXNOC; cn++) { + if (cn == victim) + continue; + if (mission == MI_SINTERDICT) { + if (getrel(getnatp(cn), victim) >= FRIENDLY) + continue; + } else if (getrel(getnatp(cn), victim) > HOSTILE) + continue; + + if (QEMPTY(&mi[cn].queue)) + continue; + + osubs = only_subs(&mi[cn].queue); + newdam = perform_mission(x, y, victim, &mi[cn].queue, + mission, s, hardtarget); + dam += newdam; + if (newdam) { + /* If only subs responded, then we don't know who's + subs they are */ + if (osubs) { + mpr(victim, + "Enemy interdiction mission does %d damage!\n", + newdam); + } else { + mpr(victim, + "%s interdiction mission does %d damage!\n", + cname(cn), newdam); + } + } + } + if (dam) { + collateral_damage(x, y, dam, 0); + } + return dam; } /* @@ -213,19 +214,19 @@ unit_interdict(coord x, coord y, natid victim, s_char *s, int hardtarget, int mi int off_support(coord x, coord y, natid victim, natid actee) { - int dam=0; - struct genlist mi[MAXNOC]; - int z; + int dam = 0; + struct genlist mi[MAXNOC]; + int z; - bzero((s_char *)mi,sizeof(mi)); - for(z=1;zown == 0) - continue; + if (gp->own == 0) + continue; - if (gp->mobil < 1) - continue; + if (gp->mobil < 1) + continue; - if ((gp->mission != mission) && (mission != MI_SINTERDICT)) - continue; - - if ((gp->mission != mission) && (mission == MI_SINTERDICT) && - (gp->mission != MI_INTERDICT)) - continue; - - relat = getrel(getnatp(gp->own), victim); - if (mission == MI_SINTERDICT) { - if (relat >= FRIENDLY) - continue; - else if (type != EF_PLANE && relat > HOSTILE) - continue; - } else if (relat > HOSTILE) - continue; - - dist = mapdist(x, y, gp->opx, gp->opy); - - radius = gp->radius; - if (mission != MI_RESERVE) /* XXX */ - oprange(gp,type,&radius); - - if (dist > radius) - continue; - - /* Ok, it is within the operations range. */ - /* Now check from where the object actually is */ - dist = mapdist(x, y, gp->x, gp->y); - radius = 999; - oprange(gp, type, &radius); - if (dist > radius) - continue; - /* Ok, the object can get to where the x,y is */ - - if (opt_SLOW_WAR) { - if (mission != MI_AIR_DEFENSE) { - getsect(x,y,(s_char *)§); - if (getrel(getnatp(gp->own), sect.sct_own) > AT_WAR) { - - /* - * If the player->owner of the unit isn't at war - * with the victim, and doesn't own the - * sect being acted upon, and isn't the - * old player->owner of that sect, bounce them. - */ - if (sect.sct_type != SCT_WATER && - sect.sct_own != gp->own && - sect.sct_oldown != gp->own) - continue; - } - } + if ((gp->mission != mission) && (mission != MI_SINTERDICT)) + continue; + + if ((gp->mission != mission) && (mission == MI_SINTERDICT) && + (gp->mission != MI_INTERDICT)) + continue; + + relat = getrel(getnatp(gp->own), victim); + if (mission == MI_SINTERDICT) { + if (relat >= FRIENDLY) + continue; + else if (type != EF_PLANE && relat > HOSTILE) + continue; + } else if (relat > HOSTILE) + continue; + + dist = mapdist(x, y, gp->opx, gp->opy); + + radius = gp->radius; + if (mission != MI_RESERVE) /* XXX */ + oprange(gp, type, &radius); + + if (dist > radius) + continue; + + /* Ok, it is within the operations range. */ + /* Now check from where the object actually is */ + dist = mapdist(x, y, gp->x, gp->y); + radius = 999; + oprange(gp, type, &radius); + if (dist > radius) + continue; + /* Ok, the object can get to where the x,y is */ + + if (opt_SLOW_WAR) { + if (mission != MI_AIR_DEFENSE) { + getsect(x, y, (s_char *)§); + if (getrel(getnatp(gp->own), sect.sct_own) > AT_WAR) { + + /* + * If the player->owner of the unit isn't at war + * with the victim, and doesn't own the + * sect being acted upon, and isn't the + * old player->owner of that sect, bounce them. + */ + if (sect.sct_type != SCT_WATER && + sect.sct_own != gp->own && + sect.sct_oldown != gp->own) + continue; } + } + } - glp = (struct genlist *) malloc(sizeof(struct genlist)); - bzero((s_char *)glp,sizeof(struct genlist)); - glp->x = gp->x; - glp->y = gp->y; - glp->type = type; - switch(type){ - case EF_LAND: glp->cp = (s_char *)&lchr[(int)gp->type]; - break; - case EF_SHIP: glp->cp = (s_char *)&mchr[(int)gp->type]; - break; - case EF_PLANE: glp->cp = (s_char *)&plchr[(int)gp->type]; - break; - } - glp->thing = (s_char *)malloc(size); - bcopy(block,glp->thing,size); - emp_insque(&glp->queue, &mi[gp->own].queue); - } + glp = (struct genlist *)malloc(sizeof(struct genlist)); + bzero((s_char *)glp, sizeof(struct genlist)); + glp->x = gp->x; + glp->y = gp->y; + glp->type = type; + switch (type) { + case EF_LAND: + glp->cp = (s_char *)&lchr[(int)gp->type]; + break; + case EF_SHIP: + glp->cp = (s_char *)&mchr[(int)gp->type]; + break; + case EF_PLANE: + glp->cp = (s_char *)&plchr[(int)gp->type]; + break; + } + glp->thing = (s_char *)malloc(size); + bcopy(block, glp->thing, size); + emp_insque(&glp->queue, &mi[gp->own].queue); + } } void find_escorts(coord x, coord y, natid cn, struct emp_qelem *escorts) { - struct nstr_item ni; - struct plist *plp; - struct plnstr plane; - int dist; - - snxtitem_all(&ni,EF_PLANE); - while(nxtitem(&ni, (s_char *)&plane)){ - if (plane.pln_own != cn) - continue; - - if (plane.pln_mission != MI_ESCORT) - continue; - - dist = mapdist(x,y,plane.pln_x,plane.pln_y); - - if (dist > ((int)((float)plane.pln_range/2.0)) ) - continue; - - plp = (struct plist *) malloc(sizeof(struct plist)); - bzero((s_char *)plp,sizeof(struct plist)); - plp->pcp = &plchr[(int)plane.pln_type]; - bcopy((s_char *)&plane,(s_char *)&plp->plane,sizeof(struct plnstr)); - emp_insque(&plp->queue, escorts); - } + struct nstr_item ni; + struct plist *plp; + struct plnstr plane; + int dist; + + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own != cn) + continue; + + if (plane.pln_mission != MI_ESCORT) + continue; + + dist = mapdist(x, y, plane.pln_x, plane.pln_y); + + if (dist > ((int)((float)plane.pln_range / 2.0))) + continue; + + plp = (struct plist *)malloc(sizeof(struct plist)); + bzero((s_char *)plp, sizeof(struct plist)); + plp->pcp = &plchr[(int)plane.pln_type]; + bcopy((s_char *)&plane, (s_char *)&plp->plane, + sizeof(struct plnstr)); + emp_insque(&plp->queue, escorts); + } } int -perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, int mission, s_char *s, int hardtarget) +perform_mission(coord x, coord y, natid victim, struct emp_qelem *list, + int mission, s_char *s, int hardtarget) { - extern int land_max_interdiction_range; - extern int ship_max_interdiction_range; - s_char *mission_name(short int mission), *nameofitem(s_char *buf, struct genitem *gp, int type); - struct emp_qelem *qp, missiles, bombers, escorts, airp, b, e; - struct emp_qelem *newqp; - struct genlist *glp; - struct plist *plp; - struct genitem *gp; - struct lndstr *lp; - struct shpstr *sp; - struct sctstr sect; - struct lchrstr *lcp; - struct mchrstr *mcp; - struct plchrstr *pcp; - int dam=0,dam2, mission_flags, tech; - natid plane_owner = 0; - int gun,shell,md, air_dam=0; - double range2, prb, range, mobcost, hitchance; - extern int torpedo_damage; - - getsect(x,y,§); - - emp_initque(&missiles); - emp_initque(&bombers); - emp_initque(&escorts); - emp_initque(&airp); - - for(qp = list->q_forw; qp != list; qp = qp->q_forw){ - glp = (struct genlist *)qp; - gp = (struct genitem *)glp->thing; - - md = mapdist(x,y,gp->x,gp->y); - - if (glp->type == EF_LAND){ - lp = (struct lndstr *)glp->thing; - lcp = (struct lchrstr *)glp->cp; - - if (lp->lnd_effic < LAND_MINFIREEFF) - continue; - - if (mission == MI_SINTERDICT) - continue; - - if ((mission == MI_INTERDICT) && - (md > land_max_interdiction_range)) - continue; - - if (md > (lp->lnd_frg / 2)) - continue; - - if (lnd_getmil(lp) < 1) - continue; - - range = techfact((int)lp->lnd_tech, - (double)lp->lnd_frg / 2.0); - range2 = (double)roundrange(range); - - if (md > range2) - continue; - - shell = getvar(V_SHELL, (s_char *)lp, EF_LAND); - gun = getvar(V_GUN, (s_char *)lp, EF_LAND); - if (shell == 0 || gun == 0) - continue; - - if (has_supply(lp)){ - use_supply(lp); - putland(lp->lnd_uid, lp); - dam2 = ldround(landunitgun(lp->lnd_effic, lp->lnd_dam, gun, - lp->lnd_ammo, shell),1); - if (sect.sct_type == SCT_WATER){ - double dam3 = (double)dam2; - if (chance(((double)lp->lnd_acc)/100.0)) - dam2=ldround((dam3/2.0),1); - } - dam += dam2; - if (sect.sct_type == SCT_WATER) - nreport(lp->lnd_own,N_SHP_SHELL,victim,1); - else - nreport(lp->lnd_own,N_SCT_SHELL,victim,1); - wu(0,lp->lnd_own, - "%s fires at %s %s at %s\n", - prland(lp), cname(victim), - s, xyas(x,y,lp->lnd_own)); - - mpr(victim, "%s %s fires at you at %s\n", - cname(lp->lnd_own), prland(lp), - xyas(x,y,victim)); - } - }else if (glp->type == EF_SHIP){ - sp = (struct shpstr *)glp->thing; - mcp = (struct mchrstr *)glp->cp; - - if (sp->shp_effic < 60) - continue; - if (sp->shp_frnge == 0) - continue; - if (((mission == MI_INTERDICT) || - (mission == MI_SINTERDICT)) && - (md > ship_max_interdiction_range)) - continue; - if (getvar(V_MILIT, (s_char *)sp, EF_SHIP) < 1) - continue; + extern int land_max_interdiction_range; + extern int ship_max_interdiction_range; + s_char *mission_name(short int mission), *nameofitem(s_char *buf, + struct genitem + *gp, int type); + struct emp_qelem *qp, missiles, bombers, escorts, airp, b, e; + struct emp_qelem *newqp; + struct genlist *glp; + struct plist *plp; + struct genitem *gp; + struct lndstr *lp; + struct shpstr *sp; + struct sctstr sect; + struct lchrstr *lcp; + struct mchrstr *mcp; + struct plchrstr *pcp; + int dam = 0, dam2, mission_flags, tech; + natid plane_owner = 0; + int gun, shell, md, air_dam = 0; + double range2, prb, range, mobcost, hitchance; + extern int torpedo_damage; + + getsect(x, y, §); + + emp_initque(&missiles); + emp_initque(&bombers); + emp_initque(&escorts); + emp_initque(&airp); + + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + glp = (struct genlist *)qp; + gp = (struct genitem *)glp->thing; + + md = mapdist(x, y, gp->x, gp->y); + + if (glp->type == EF_LAND) { + lp = (struct lndstr *)glp->thing; + lcp = (struct lchrstr *)glp->cp; + + if (lp->lnd_effic < LAND_MINFIREEFF) + continue; + + if (mission == MI_SINTERDICT) + continue; + + if ((mission == MI_INTERDICT) && + (md > land_max_interdiction_range)) + continue; + + if (md > (lp->lnd_frg / 2)) + continue; + + if (lnd_getmil(lp) < 1) + continue; + + range = techfact((int)lp->lnd_tech, (double)lp->lnd_frg / 2.0); + range2 = (double)roundrange(range); + + if (md > range2) + continue; + + shell = getvar(V_SHELL, (s_char *)lp, EF_LAND); + gun = getvar(V_GUN, (s_char *)lp, EF_LAND); + if (shell == 0 || gun == 0) + continue; + + if (has_supply(lp)) { + use_supply(lp); + putland(lp->lnd_uid, lp); + dam2 = ldround(landunitgun(lp->lnd_effic, lp->lnd_dam, gun, + lp->lnd_ammo, shell), 1); + if (sect.sct_type == SCT_WATER) { + double dam3 = (double)dam2; + if (chance(((double)lp->lnd_acc) / 100.0)) + dam2 = ldround((dam3 / 2.0), 1); + } + dam += dam2; + if (sect.sct_type == SCT_WATER) + nreport(lp->lnd_own, N_SHP_SHELL, victim, 1); + else + nreport(lp->lnd_own, N_SCT_SHELL, victim, 1); + wu(0, lp->lnd_own, + "%s fires at %s %s at %s\n", + prland(lp), cname(victim), s, xyas(x, y, lp->lnd_own)); + + mpr(victim, "%s %s fires at you at %s\n", + cname(lp->lnd_own), prland(lp), xyas(x, y, victim)); + } + } else if (glp->type == EF_SHIP) { + sp = (struct shpstr *)glp->thing; + mcp = (struct mchrstr *)glp->cp; + + if (sp->shp_effic < 60) + continue; + if (sp->shp_frnge == 0) + continue; + if (((mission == MI_INTERDICT) || + (mission == MI_SINTERDICT)) && + (md > ship_max_interdiction_range)) + continue; + if (getvar(V_MILIT, (s_char *)sp, EF_SHIP) < 1) + continue; /* if ((mcp->m_flags & M_SUB) && (sect.sct_type != SCT_WATER)) continue; */ - if (mission == MI_SINTERDICT){ - if (!(mcp->m_flags & M_SONAR)) - continue; - if (!(mcp->m_flags & M_DCH) && - !(mcp->m_flags & M_SUBT)) - continue; - range2 = techfact(sp->shp_tech, - (double)mcp->m_vrnge); - range2 *= (double)sp->shp_effic / 200.0; - if (md > range2) - continue; - /* can't look all the time */ - if (chance(0.5)) - continue; - } - if (mcp->m_flags & M_SUB){ + if (mission == MI_SINTERDICT) { + if (!(mcp->m_flags & M_SONAR)) + continue; + if (!(mcp->m_flags & M_DCH) && !(mcp->m_flags & M_SUBT)) + continue; + range2 = techfact(sp->shp_tech, (double)mcp->m_vrnge); + range2 *= (double)sp->shp_effic / 200.0; + if (md > range2) + continue; + /* can't look all the time */ + if (chance(0.5)) + continue; + } + if (mcp->m_flags & M_SUB) { /* If we aren't shooting at "subs" or "ships" don't fire at all from a sub. */ - if (*s != 's') - continue; - if (sp->shp_mobil < (s_char)0) - continue; - gun = getvar(V_GUN,(s_char *)sp,EF_SHIP); - if (gun < 1) - continue; - shell = getvar(V_SHELL,(s_char *)sp,EF_SHIP); - if (shell < 3) - shell += supply_commod(sp->shp_own, - sp->shp_x,sp->shp_y,I_SHELL, - 3-shell); - if (shell < 3) - continue; - - range = sp->shp_effic* techfact(sp->shp_tech, - ((double)sp->shp_frnge)) / 100.0; - - range2 = (double)roundrange(range); - if (md > range) - continue; - - if (!line_of_sight((s_char **)0, x, y, - gp->x, gp->y)) - continue; - putvar(V_SHELL,shell-3,(s_char *)sp,EF_SHIP); - mobcost = sp->shp_effic * 0.01 * sp->shp_speed; - mobcost = (480.0/(mobcost + - techfact(sp->shp_tech, mobcost))); - sp->shp_mobil -= mobcost; - putship(sp->shp_uid,sp); - hitchance = DTORP_HITCHANCE(md, sp->shp_visib); - - wu(0,sp->shp_own, - "%s locking on %s %s in %s\n", - prship(sp),cname(victim),s, - xyas(x,y,sp->shp_own)); - wu(0,sp->shp_own, - "\tEffective torpedo range is %.1f\n", range); - wu(0,sp->shp_own, - "\tWhooosh... Hitchance = %d%%\n", - (int)(hitchance*100)); - - if (hitchance < 1.0 && !chance(hitchance)) { - wu(0,sp->shp_own, - "\tMissed\n"); - mpr(victim, "Incoming torpedo sighted @ %s missed (whew)!\n", - xyas(x,y,victim)); - continue; - } - wu(0,sp->shp_own, - "\tBOOM!...\n"); - dam2 = TORP_DAMAGE(); - - dam += dam2; - nreport(victim,N_TORP_SHIP,sp->shp_own,1); - wu(0,sp->shp_own, - "\tTorpedo hit %s %s for %d damage\n", - cname(victim),s,dam2); - - mpr(victim, - "Incoming torpedo sighted @ %s hits and does %d damage!\n", - xyas(x,y,victim), dam2); - }else{ - range = techfact(sp->shp_tech, - (double)mcp->m_frnge/2.0); - range2 = (double)roundrange(range); - if (md > range2) - continue; - gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); - gun = min(gun, sp->shp_glim); - shell = getvar(V_SHELL, (s_char *)sp, EF_SHIP); - if (shell < gun) - shell += supply_commod(sp->shp_own, - sp->shp_x,sp->shp_y,I_SHELL, - gun-shell); - gun = min(gun, shell); - gun = min(gun,(int)((float)getvar(V_MILIT, - (s_char *)sp,EF_SHIP)/2.0)); - if (gun ==0) - continue; - gun = max(gun,1); - dam2 = seagun(sp->shp_effic,gun); - if ( range2 == 0.0 ) - prb = 1.0; - else - prb = ((double)md) / range2; - prb *= prb; - if (chance(prb)) - dam2 = (int)((float)dam2/2.0); - dam += dam2; - if (sect.sct_type == SCT_WATER) - nreport(sp->shp_own,N_SHP_SHELL,victim,1); - else - nreport(sp->shp_own,N_SCT_SHELL,victim,1); - wu(0,sp->shp_own, - "%s fires at %s %s at %s\n", - prship(sp), - cname(victim), s, - xyas(x,y,sp->shp_own)); - - mpr(victim, "%s fires at you at %s\n", - cname(sp->shp_own), prship(sp), - xyas(x,y,victim)); - - putvar(V_SHELL,shell-gun,(s_char *)sp, EF_SHIP); - putship(sp->shp_uid,sp); - } - }else if (glp->type == EF_PLANE) { - pcp = (struct plchrstr *)glp->cp; - if (pcp->pl_flags & P_M) - /* units have their own missile interdiction */ - if (hardtarget != SECT_HARDTARGET || - pcp->pl_flags & P_MAR) - continue; - - /* save planes for later */ - plp = (struct plist *)malloc(sizeof(struct plist)); - - bzero((s_char *)plp,sizeof(struct plist)); - plp->pcp = pcp; - bcopy(glp->thing, (s_char *)&plp->plane, - sizeof(struct plnstr)); - if (plp->pcp->pl_flags & P_M) - emp_insque(&plp->queue, &missiles); - else - emp_insque(&plp->queue, &bombers); - plane_owner = plp->plane.pln_own; - } - } - if (!QEMPTY(&missiles)) { - /* I arbitrarily chose 100 mindam -KHS */ - dam += msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100, "sector", victim, mission); - qp=missiles.q_forw; - while(qp != (&missiles)){ - qp=qp->q_forw; - free(qp); - } - } - - if (QEMPTY(&bombers)) { - qp=list->q_forw; - while(qp != list){ - glp = (struct genlist *)qp; - qp=qp->q_forw; - - free(glp->thing); - free((s_char *)glp); - } - return dam; - } - /* - * If there are planes performing an - * interdict or support mission, find - * some escorts for them, if possible. - * Up to 2 per bomber, if possible. - */ - find_escorts(x,y,plane_owner,&escorts); - - if (mission == MI_SINTERDICT) - mission_pln_sel(&bombers,P_T|P_A,0,hardtarget); - else - mission_pln_sel(&bombers,P_T,P_A,SECT_HARDTARGET); - - mission_pln_sel(&escorts,P_ESC|P_F,0,SECT_HARDTARGET); - - for(qp = bombers.q_forw; qp != (&bombers); qp = qp->q_forw){ - plp = (struct plist *)qp; - if (!find_airport(&airp,plp->plane.pln_x,plp->plane.pln_y)) - add_airport(&airp,plp->plane.pln_x, - plp->plane.pln_y); - } - - for(qp = airp.q_forw; qp != (&airp); qp = qp->q_forw){ - struct airport *air; - s_char pp[512]; - - air = (struct airport *)qp; - md = mapdist(x,y,air->x,air->y); - - emp_initque(&b); - emp_initque(&e); - - /* Split off the bombers at this base into b */ - divide(&bombers,&b,air->x,air->y); - - /* Split off the escorts at this base into e */ - divide(&escorts,&e,air->x,air->y); - - tech = 0; - mission_flags = 0; - mission_flags |= P_X; /* stealth (shhh) */ - mission_flags |= P_H; /* gets turned off if not all choppers */ - - mission_flags = mission_pln_arm(&b,air->x,air->y,2*md,'p',0, - 0,mission_flags,&tech); - - if (QEMPTY(&b)){ - continue; - } - - mission_flags = mission_pln_arm(&e,air->x,air->y,2*md,'p',0, - P_F|P_ESC,mission_flags,&tech); - - BestAirPath(pp, air->x, air->y, x, y); - wu(0, plane_owner, "Flying %s mission from %s\n", - mission_name(mission), xyas(air->x, air->y, plane_owner)); - if (air->own && (air->own != plane_owner)) { - wu(0, air->own, "%s is flying %s mission from %s\n", - cname(plane_owner), mission_name(mission), - xyas(air->x, air->y, air->own)); + if (*s != 's') + continue; + if (sp->shp_mobil < (s_char)0) + continue; + gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); + if (gun < 1) + continue; + shell = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + if (shell < 3) + shell += supply_commod(sp->shp_own, + sp->shp_x, sp->shp_y, I_SHELL, + 3 - shell); + if (shell < 3) + continue; + + range = sp->shp_effic * techfact(sp->shp_tech, + ((double)sp->shp_frnge)) / + 100.0; + + range2 = (double)roundrange(range); + if (md > range) + continue; + + if (!line_of_sight((s_char **)0, x, y, gp->x, gp->y)) + continue; + putvar(V_SHELL, shell - 3, (s_char *)sp, EF_SHIP); + mobcost = sp->shp_effic * 0.01 * sp->shp_speed; + mobcost = (480.0 / (mobcost + + techfact(sp->shp_tech, mobcost))); + sp->shp_mobil -= mobcost; + putship(sp->shp_uid, sp); + hitchance = DTORP_HITCHANCE(md, sp->shp_visib); + + wu(0, sp->shp_own, + "%s locking on %s %s in %s\n", + prship(sp), cname(victim), s, xyas(x, y, sp->shp_own)); + wu(0, sp->shp_own, + "\tEffective torpedo range is %.1f\n", range); + wu(0, sp->shp_own, + "\tWhooosh... Hitchance = %d%%\n", + (int)(hitchance * 100)); + + if (hitchance < 1.0 && !chance(hitchance)) { + wu(0, sp->shp_own, "\tMissed\n"); + mpr(victim, + "Incoming torpedo sighted @ %s missed (whew)!\n", + xyas(x, y, victim)); + continue; } - - ac_encounter(&b,&e,air->x,air->y,pp,mission_flags,0, 0, 0); - - if (!QEMPTY(&b)) - air_dam += air_damage(&b,x,y,mission,victim,s,hardtarget); - - pln_put(&b); - pln_put(&e); - } - - if (air_dam > 0){ - dam += air_dam; + wu(0, sp->shp_own, "\tBOOM!...\n"); + dam2 = TORP_DAMAGE(); + + dam += dam2; + nreport(victim, N_TORP_SHIP, sp->shp_own, 1); + wu(0, sp->shp_own, + "\tTorpedo hit %s %s for %d damage\n", + cname(victim), s, dam2); + + mpr(victim, + "Incoming torpedo sighted @ %s hits and does %d damage!\n", + xyas(x, y, victim), dam2); + } else { + range = techfact(sp->shp_tech, (double)mcp->m_frnge / 2.0); + range2 = (double)roundrange(range); + if (md > range2) + continue; + gun = getvar(V_GUN, (s_char *)sp, EF_SHIP); + gun = min(gun, sp->shp_glim); + shell = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + if (shell < gun) + shell += supply_commod(sp->shp_own, + sp->shp_x, sp->shp_y, I_SHELL, + gun - shell); + gun = min(gun, shell); + gun = min(gun, (int)((float)getvar(V_MILIT, + (s_char *)sp, + EF_SHIP) / 2.0)); + if (gun == 0) + continue; + gun = max(gun, 1); + dam2 = seagun(sp->shp_effic, gun); + if (range2 == 0.0) + prb = 1.0; + else + prb = ((double)md) / range2; + prb *= prb; + if (chance(prb)) + dam2 = (int)((float)dam2 / 2.0); + dam += dam2; if (sect.sct_type == SCT_WATER) - nreport(plane_owner,N_SHP_BOMB,victim,1); + nreport(sp->shp_own, N_SHP_SHELL, victim, 1); else - nreport(plane_owner,N_SCT_BOMB,victim,1); - } - - /* free up all this memory */ - qp=list->q_forw; - while(qp != list){ - glp = (struct genlist *)qp; - qp=qp->q_forw; - - free(glp->thing); - free((s_char *)glp); + nreport(sp->shp_own, N_SCT_SHELL, victim, 1); + wu(0, sp->shp_own, + "%s fires at %s %s at %s\n", + prship(sp), cname(victim), s, xyas(x, y, sp->shp_own)); + + mpr(victim, "%s fires at you at %s\n", + cname(sp->shp_own), prship(sp), xyas(x, y, victim)); + + putvar(V_SHELL, shell - gun, (s_char *)sp, EF_SHIP); + putship(sp->shp_uid, sp); + } + } else if (glp->type == EF_PLANE) { + pcp = (struct plchrstr *)glp->cp; + if (pcp->pl_flags & P_M) + /* units have their own missile interdiction */ + if (hardtarget != SECT_HARDTARGET || pcp->pl_flags & P_MAR) + continue; + + /* save planes for later */ + plp = (struct plist *)malloc(sizeof(struct plist)); + + bzero((s_char *)plp, sizeof(struct plist)); + plp->pcp = pcp; + bcopy(glp->thing, (s_char *)&plp->plane, + sizeof(struct plnstr)); + if (plp->pcp->pl_flags & P_M) + emp_insque(&plp->queue, &missiles); + else + emp_insque(&plp->queue, &bombers); + plane_owner = plp->plane.pln_own; } - - qp = escorts.q_forw; - while(qp != (&escorts)){ - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + } + if (!QEMPTY(&missiles)) { + /* I arbitrarily chose 100 mindam -KHS */ + dam += + msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100, + "sector", victim, mission); + qp = missiles.q_forw; + while (qp != (&missiles)) { + qp = qp->q_forw; + free(qp); } - - qp=bombers.q_forw; - while(qp != (&bombers)){ - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + } + + if (QEMPTY(&bombers)) { + qp = list->q_forw; + while (qp != list) { + glp = (struct genlist *)qp; + qp = qp->q_forw; + + free(glp->thing); + free((s_char *)glp); } - return dam; + } + /* + * If there are planes performing an + * interdict or support mission, find + * some escorts for them, if possible. + * Up to 2 per bomber, if possible. + */ + find_escorts(x, y, plane_owner, &escorts); + + if (mission == MI_SINTERDICT) + mission_pln_sel(&bombers, P_T | P_A, 0, hardtarget); + else + mission_pln_sel(&bombers, P_T, P_A, SECT_HARDTARGET); + + mission_pln_sel(&escorts, P_ESC | P_F, 0, SECT_HARDTARGET); + + for (qp = bombers.q_forw; qp != (&bombers); qp = qp->q_forw) { + plp = (struct plist *)qp; + if (!find_airport(&airp, plp->plane.pln_x, plp->plane.pln_y)) + add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y); + } + + for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) { + struct airport *air; + s_char pp[512]; + + air = (struct airport *)qp; + md = mapdist(x, y, air->x, air->y); + + emp_initque(&b); + emp_initque(&e); + + /* Split off the bombers at this base into b */ + divide(&bombers, &b, air->x, air->y); + + /* Split off the escorts at this base into e */ + divide(&escorts, &e, air->x, air->y); + + tech = 0; + mission_flags = 0; + mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_H; /* gets turned off if not all choppers */ + + mission_flags = mission_pln_arm(&b, air->x, air->y, 2 * md, 'p', 0, + 0, mission_flags, &tech); + + if (QEMPTY(&b)) { + continue; + } + + mission_flags = mission_pln_arm(&e, air->x, air->y, 2 * md, 'p', 0, + P_F | P_ESC, mission_flags, &tech); + + BestAirPath(pp, air->x, air->y, x, y); + wu(0, plane_owner, "Flying %s mission from %s\n", + mission_name(mission), xyas(air->x, air->y, plane_owner)); + if (air->own && (air->own != plane_owner)) { + wu(0, air->own, "%s is flying %s mission from %s\n", + cname(plane_owner), mission_name(mission), + xyas(air->x, air->y, air->own)); + } + + ac_encounter(&b, &e, air->x, air->y, pp, mission_flags, 0, 0, 0); + + if (!QEMPTY(&b)) + air_dam += + air_damage(&b, x, y, mission, victim, s, hardtarget); + + pln_put(&b); + pln_put(&e); + } + + if (air_dam > 0) { + dam += air_dam; + if (sect.sct_type == SCT_WATER) + nreport(plane_owner, N_SHP_BOMB, victim, 1); + else + nreport(plane_owner, N_SCT_BOMB, victim, 1); + } + + /* free up all this memory */ + qp = list->q_forw; + while (qp != list) { + glp = (struct genlist *)qp; + qp = qp->q_forw; + + free(glp->thing); + free((s_char *)glp); + } + + qp = escorts.q_forw; + while (qp != (&escorts)) { + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } + + qp = bombers.q_forw; + while (qp != (&bombers)) { + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } + + return dam; } int cando(int mission, int type) { - switch (mission){ - case MI_ESCORT: - if (type == EF_PLANE) - return 1; - return 0; - case MI_AIR_DEFENSE: - if (type == EF_PLANE) - return 1; - return 0; - case MI_SINTERDICT: - if ((type == EF_PLANE) || (type == EF_SHIP)) - return 1; - return 0; - case MI_INTERDICT: - return 1; - case MI_SUPPORT: - case MI_OSUPPORT: - case MI_DSUPPORT: - if (type == EF_PLANE) - return 1; - return 0; - case MI_RESERVE: - if (type == EF_LAND) - return 1; - return 0; - } - + switch (mission) { + case MI_ESCORT: + if (type == EF_PLANE) + return 1; + return 0; + case MI_AIR_DEFENSE: + if (type == EF_PLANE) + return 1; + return 0; + case MI_SINTERDICT: + if ((type == EF_PLANE) || (type == EF_SHIP)) + return 1; return 0; + case MI_INTERDICT: + return 1; + case MI_SUPPORT: + case MI_OSUPPORT: + case MI_DSUPPORT: + if (type == EF_PLANE) + return 1; + return 0; + case MI_RESERVE: + if (type == EF_LAND) + return 1; + return 0; + } + + return 0; } -s_char *nameofitem(s_char *buf, struct genitem *gp, int type) +s_char * +nameofitem(s_char *buf, struct genitem *gp, int type) { - switch(type){ - case EF_SHIP: - return prship((struct shpstr *)gp); - break; - case EF_PLANE: - return prplane((struct plnstr *)gp); - break; - case EF_LAND: - return prland((struct lndstr *)gp); - } - return NULL; + switch (type) { + case EF_SHIP: + return prship((struct shpstr *)gp); + break; + case EF_PLANE: + return prplane((struct plnstr *)gp); + break; + case EF_LAND: + return prland((struct lndstr *)gp); + } + return NULL; } -s_char *mission_short_name(int mission) +s_char * +mission_short_name(int mission) { - switch (mission){ - case MI_INTERDICT: return "interdict"; - case MI_SUPPORT: return "support "; - case MI_OSUPPORT: return "offensive"; - case MI_DSUPPORT: return "defensive"; - case MI_RESERVE: return "reserve "; - case MI_ESCORT: return "escort "; - case MI_SINTERDICT: return "interdict"; - case MI_AIR_DEFENSE: return "air def "; - default: return " "; - } + switch (mission) { + case MI_INTERDICT: + return "interdict"; + case MI_SUPPORT: + return "support "; + case MI_OSUPPORT: + return "offensive"; + case MI_DSUPPORT: + return "defensive"; + case MI_RESERVE: + return "reserve "; + case MI_ESCORT: + return "escort "; + case MI_SINTERDICT: + return "interdict"; + case MI_AIR_DEFENSE: + return "air def "; + default: + return " "; + } } -s_char *mission_name(short int mission) +s_char * +mission_name(short int mission) { - switch (mission){ - case MI_INTERDICT: return "an interdiction"; - case MI_SUPPORT: return "a support"; - case MI_OSUPPORT: return "a offensive support"; - case MI_DSUPPORT: return "a defensive support"; - case MI_RESERVE: return "a reserve"; - case MI_ESCORT: return "an escort"; - case MI_SINTERDICT: return "a sub interdiction"; - case MI_AIR_DEFENSE: return "an air defense"; - } - return "a mysterious"; + switch (mission) { + case MI_INTERDICT: + return "an interdiction"; + case MI_SUPPORT: + return "a support"; + case MI_OSUPPORT: + return "a offensive support"; + case MI_DSUPPORT: + return "a defensive support"; + case MI_RESERVE: + return "a reserve"; + case MI_ESCORT: + return "an escort"; + case MI_SINTERDICT: + return "a sub interdiction"; + case MI_AIR_DEFENSE: + return "an air defense"; + } + return "a mysterious"; } void show_mission(int type, struct nstr_item *np) { - int size, first=1, radius; - s_char *block; - struct genitem *gp; - s_char buf[128]; + int size, first = 1, radius; + s_char *block; + struct genitem *gp; + s_char buf[128]; - size = max(sizeof(struct lndstr),sizeof(struct plnstr)); - size = max(size,sizeof(struct shpstr)); - block = (s_char *)malloc(size); + size = max(sizeof(struct lndstr), sizeof(struct plnstr)); + size = max(size, sizeof(struct shpstr)); + block = (s_char *)malloc(size); + + while (nxtitem(np, block)) { + gp = (struct genitem *)block; + if (!player->owner || gp->own == 0) + continue; - while (nxtitem(np, block)) { - gp = (struct genitem *)block; - if (!player->owner || gp->own == 0) - continue; - - if (first){ - pr("Thing x,y op-sect rad mission\n"); - first=0; - } - pr("%-25s", nameofitem(buf, gp,type)); - pr(" %7s", xyas(gp->x,gp->y,player->cnum)); - if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT || - gp->mission == MI_OSUPPORT || - gp->mission == MI_DSUPPORT || - gp->mission == MI_AIR_DEFENSE){ - radius = 999; - oprange(gp,type,&radius); - pr(" %7s", xyas(gp->opx,gp->opy,player->cnum)); - if (radius < gp->radius) - pr(" %4d", radius); - else - pr(" %4d", gp->radius); - }else if (gp->mission == MI_RESERVE){ - struct sctstr sect; - int plus=2; - - getsect(gp->x,gp->y,§); - if ((sect.sct_type == SCT_HEADQ) && - (sect.sct_effic >= 60)) - plus++; - - if (((struct lndstr *)block)->lnd_rad_max == 0) - plus = 0; - else - plus += ((struct lndstr *)block)->lnd_rad_max; - pr(" %7s", xyas(gp->x,gp->y,player->cnum)); - pr(" %4d", plus); - }else if (gp->mission == MI_ESCORT){ - pr(" "); - pr(" %4d", (int) - ((float)((struct plnstr *)block)->pln_range/2.0) - ); - }else - pr(" "); - if (gp->mission) - pr(" is on %s mission\n", - mission_name(gp->mission)); - else - pr(" has no mission.\n"); - } + if (first) { + pr("Thing x,y op-sect rad mission\n"); + first = 0; + } + pr("%-25s", nameofitem(buf, gp, type)); + pr(" %7s", xyas(gp->x, gp->y, player->cnum)); + if (gp->mission == MI_INTERDICT || gp->mission == MI_SUPPORT || + gp->mission == MI_OSUPPORT || + gp->mission == MI_DSUPPORT || gp->mission == MI_AIR_DEFENSE) { + radius = 999; + oprange(gp, type, &radius); + pr(" %7s", xyas(gp->opx, gp->opy, player->cnum)); + if (radius < gp->radius) + pr(" %4d", radius); + else + pr(" %4d", gp->radius); + } else if (gp->mission == MI_RESERVE) { + struct sctstr sect; + int plus = 2; + + getsect(gp->x, gp->y, §); + if ((sect.sct_type == SCT_HEADQ) && (sect.sct_effic >= 60)) + plus++; + + if (((struct lndstr *)block)->lnd_rad_max == 0) + plus = 0; + else + plus += ((struct lndstr *)block)->lnd_rad_max; + pr(" %7s", xyas(gp->x, gp->y, player->cnum)); + pr(" %4d", plus); + } else if (gp->mission == MI_ESCORT) { + pr(" "); + pr(" %4d", (int) + ((float)((struct plnstr *)block)->pln_range / 2.0) + ); + } else + pr(" "); + if (gp->mission) + pr(" is on %s mission\n", mission_name(gp->mission)); + else + pr(" has no mission.\n"); + } } int oprange(struct genitem *gp, int type, int *radius) { - double techfact(int, double); - int range; - struct shpstr ship; - struct lndstr land; - struct plnstr plane; - - switch (type){ - case EF_SHIP: - getship(gp->uid,&ship); - range = ldround(techfact(gp->tech, - (double)ship.shp_frnge / 2.0),1); - break; - case EF_LAND: - getland(gp->uid,&land); - range = ldround(techfact((int)land.lnd_tech, - (double)land.lnd_frg / 2.0),1); - break; - case EF_PLANE: - getplane(gp->uid,&plane); - /* missiles go one way, so we can use all the range */ - if (plchr[(int)plane.pln_type].pl_flags & P_M) - range = plane.pln_range; - else - range = ldround((double)plane.pln_range/2.0,1);; - break; - } - - if ((*radius) > range) - *radius = range; - - return range; + double techfact(int, double); + int range; + struct shpstr ship; + struct lndstr land; + struct plnstr plane; + + switch (type) { + case EF_SHIP: + getship(gp->uid, &ship); + range = ldround(techfact(gp->tech, + (double)ship.shp_frnge / 2.0), 1); + break; + case EF_LAND: + getland(gp->uid, &land); + range = ldround(techfact((int)land.lnd_tech, + (double)land.lnd_frg / 2.0), 1); + break; + case EF_PLANE: + getplane(gp->uid, &plane); + /* missiles go one way, so we can use all the range */ + if (plchr[(int)plane.pln_type].pl_flags & P_M) + range = plane.pln_range; + else + range = ldround((double)plane.pln_range / 2.0, 1);; + break; + } + + if ((*radius) > range) + *radius = range; + + return range; } /* @@ -988,189 +1006,191 @@ oprange(struct genitem *gp, int type, int *radius) * the mission from the plane list. */ void -mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, int hardtarget) +mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, + int hardtarget) { - struct emp_qelem *qp, *next; - struct plnstr *pp; - struct shpstr ship; - struct lndstr land; - struct sctstr sect; - struct plchrstr *pcp; - struct plist *plp; - register int y, bad, bad1; - unsigned int x; - - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *)qp; - pp = &plp->plane; - pcp = plp->pcp; - - if (pp->pln_effic < 40){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - - if (pp->pln_mobil < 1) { - emp_remque(qp); - free((s_char *)qp); - continue; - } + struct emp_qelem *qp, *next; + struct plnstr *pp; + struct shpstr ship; + struct lndstr land; + struct sctstr sect; + struct plchrstr *pcp; + struct plist *plp; + register int y, bad, bad1; + unsigned int x; + + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + pp = &plp->plane; + pcp = plp->pcp; + + if (pp->pln_effic < 40) { + emp_remque(qp); + free((s_char *)qp); + continue; + } - if (opt_MARKET) { - if (ontradingblock(EF_PLANE, (int *)pp)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } + if (pp->pln_mobil < 1) { + emp_remque(qp); + free((s_char *)qp); + continue; + } - bad=0; - bad1=0; - if (wantflags) { - for(x=0;xpl_flags & y) != y){ - switch(y){ - case P_F: - case P_ESC: bad1=2; - break; - case P_E: - case P_L: - case P_K: bad1=1; - break; - default: bad=1; - } - } - } - if (bad){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (bad1 == 2){ - if ((pcp->pl_flags & P_ESC) || - (pcp->pl_flags & P_F)) - bad1=0; - } - if (bad1 == 1){ - if ((pcp->pl_flags & P_E) || - (pcp->pl_flags & P_K) || - (pcp->pl_flags & P_L)) - bad1=0; - } - if (bad1){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - bad=0; - bad1=0; - if (nowantflags) { - for(x=0;xpl_flags & y) == y) - bad=1; - } - if (bad){ - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - if (pp->pln_ship >= 0) { - if (!getship(pp->pln_ship, &ship)){ - shipsunk: - pp->pln_effic = 0; - putplane(pp->pln_uid, pp); - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (!can_be_on_ship(pp->pln_uid,ship.shp_uid)) { - goto shipsunk; - } - if (ship.shp_effic < SHIP_MINEFF){ - goto shipsunk; - } - /* Can't fly off of ships < 50%, or non-owned or non-allied ships */ - if ((ship.shp_effic < 50) || - ((ship.shp_own != pp->pln_own) && - (getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED))) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - if (pp->pln_land >= 0) { - if (!getland(pp->pln_land, &land)){ - landdead: - pp->pln_effic = 0; - putplane(pp->pln_uid, pp); - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (!(pcp->pl_flags & P_E)) - goto landdead; - if (land.lnd_effic < LAND_MINEFF) - goto landdead; - - /* Can't fly off of units < 50%, or non-owned or non-allied units */ - if ((land.lnd_effic < 50) || - ((land.lnd_own != pp->pln_own) && - (getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED))) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - - /* Can't fly off units in ships or other units */ - if ((land.lnd_ship >= 0) || (land.lnd_land >= 0)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } - /* Now, check the sector status if not on a plane or unit */ - if ((pp->pln_ship < 0) && (pp->pln_land < 0)) { - /* If we can't get the sector, we can't check it, and can't fly */ - if (!getsect(pp->pln_x, pp->pln_y, §)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* First, check allied status */ - /* Can't fly from non-owned sectors or non-allied sectors */ - if ((sect.sct_own != pp->pln_own) && - (getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* non-vtol plane */ - if ((pcp->pl_flags & P_V) == 0) { - if ((sect.sct_type != SCT_AIRPT) || (sect.sct_effic < 40)) { - emp_remque(qp); - free((s_char *)qp); - continue; + if (opt_MARKET) { + if (ontradingblock(EF_PLANE, (int *)pp)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + + bad = 0; + bad1 = 0; + if (wantflags) { + for (x = 0; x < sizeof(wantflags) * 8; x++) { + y = (1 << x); + if ((wantflags & y) == y) + if ((pcp->pl_flags & y) != y) { + switch (y) { + case P_F: + case P_ESC: + bad1 = 2; + break; + case P_E: + case P_L: + case P_K: + bad1 = 1; + break; + default: + bad = 1; } } + } + if (bad) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (bad1 == 2) { + if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F)) + bad1 = 0; + } + if (bad1 == 1) { + if ((pcp->pl_flags & P_E) || + (pcp->pl_flags & P_K) || (pcp->pl_flags & P_L)) + bad1 = 0; + } + if (bad1) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + bad = 0; + bad1 = 0; + if (nowantflags) { + for (x = 0; x < sizeof(nowantflags) * 8; x++) { + y = (1 << x); + if ((nowantflags & y) == y) + if ((pcp->pl_flags & y) == y) + bad = 1; + } + if (bad) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + if (pp->pln_ship >= 0) { + if (!getship(pp->pln_ship, &ship)) { + shipsunk: + pp->pln_effic = 0; + putplane(pp->pln_uid, pp); + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (!can_be_on_ship(pp->pln_uid, ship.shp_uid)) { + goto shipsunk; + } + if (ship.shp_effic < SHIP_MINEFF) { + goto shipsunk; + } + /* Can't fly off of ships < 50%, or non-owned or non-allied ships */ + if ((ship.shp_effic < 50) || + ((ship.shp_own != pp->pln_own) && + (getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED))) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + if (pp->pln_land >= 0) { + if (!getland(pp->pln_land, &land)) { + landdead: + pp->pln_effic = 0; + putplane(pp->pln_uid, pp); + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (!(pcp->pl_flags & P_E)) + goto landdead; + if (land.lnd_effic < LAND_MINEFF) + goto landdead; + + /* Can't fly off of units < 50%, or non-owned or non-allied units */ + if ((land.lnd_effic < 50) || + ((land.lnd_own != pp->pln_own) && + (getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED))) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + + /* Can't fly off units in ships or other units */ + if ((land.lnd_ship >= 0) || (land.lnd_land >= 0)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } + /* Now, check the sector status if not on a plane or unit */ + if ((pp->pln_ship < 0) && (pp->pln_land < 0)) { + /* If we can't get the sector, we can't check it, and can't fly */ + if (!getsect(pp->pln_x, pp->pln_y, §)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + /* First, check allied status */ + /* Can't fly from non-owned sectors or non-allied sectors */ + if ((sect.sct_own != pp->pln_own) && + (getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + /* non-vtol plane */ + if ((pcp->pl_flags & P_V) == 0) { + if ((sect.sct_type != SCT_AIRPT) || (sect.sct_effic < 40)) { + emp_remque(qp); + free((s_char *)qp); + continue; } - if (pcp->pl_flags & P_A) { - if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - } + } + } + if (pcp->pl_flags & P_A) { + if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + } - putplane(pp->pln_uid, pp); - } + putplane(pp->pln_uid, pp); + } } /* @@ -1178,166 +1198,168 @@ mission_pln_sel(struct emp_qelem *list, int wantflags, int nowantflags, int hard * */ int -mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, int mission, struct ichrstr *ip, int flags, int mission_flags, int *tech) +mission_pln_arm(struct emp_qelem *list, coord x, coord y, int dist, + int mission, struct ichrstr *ip, int flags, + int mission_flags, int *tech) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *plp; - - if (*tech == 0) - *tech = 9999; - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *) qp; - - if (plp->plane.pln_x != x) - continue; - if (plp->plane.pln_y != y) - continue; - - if (mission_pln_equip(plp, ip, flags, mission) < 0) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (flags & (P_S|P_I)) { - if(plp->pcp->pl_flags & P_S) - mission_flags |= P_S; - if(plp->pcp->pl_flags & P_I) - mission_flags |= P_I; - } - if (*tech > plp->plane.pln_tech) - *tech = plp->plane.pln_tech; - if (!(plp->pcp->pl_flags & P_H)) - /* no stealth on this mission */ - mission_flags &= ~P_H; - if (!(plp->pcp->pl_flags & P_X)) - /* no stealth on this mission */ - mission_flags &= ~P_X; - if (!(plp->pcp->pl_flags & P_A)) { - /* no asw on this mission */ - mission_flags &= ~P_A; - } - if (!(plp->pcp->pl_flags & P_MINE)) { - /* no asw on this mission */ - mission_flags &= ~P_MINE; - } - - /* - * Mob costs for missions are 1/2 normal - * Not anymore. :) - */ + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *plp; + + if (*tech == 0) + *tech = 9999; + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + + if (plp->plane.pln_x != x) + continue; + if (plp->plane.pln_y != y) + continue; + + if (mission_pln_equip(plp, ip, flags, mission) < 0) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + if (flags & (P_S | P_I)) { + if (plp->pcp->pl_flags & P_S) + mission_flags |= P_S; + if (plp->pcp->pl_flags & P_I) + mission_flags |= P_I; + } + if (*tech > plp->plane.pln_tech) + *tech = plp->plane.pln_tech; + if (!(plp->pcp->pl_flags & P_H)) + /* no stealth on this mission */ + mission_flags &= ~P_H; + if (!(plp->pcp->pl_flags & P_X)) + /* no stealth on this mission */ + mission_flags &= ~P_X; + if (!(plp->pcp->pl_flags & P_A)) { + /* no asw on this mission */ + mission_flags &= ~P_A; + } + if (!(plp->pcp->pl_flags & P_MINE)) { + /* no asw on this mission */ + mission_flags &= ~P_MINE; + } + + /* + * Mob costs for missions are 1/2 normal + * Not anymore. :) + */ /* plp->plane.pln_mobil -= pln_mobcost(dist,&plp->plane,flags)/2;*/ - plp->plane.pln_mobil -= pln_mobcost(dist,&plp->plane,flags); + plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags); - } - return mission_flags; + } + return mission_flags; } int -mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission) +mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, + s_char mission) { - register struct plchrstr *pcp; - struct plnstr *pp; - int needed; - struct lndstr land; - struct shpstr ship; - struct sctstr sect; - int type; - s_char *ptr; - int item; - int rval; - int vec[I_MAX+1]; - - pp = &plp->plane; - pcp = plp->pcp; - if (pp->pln_ship >= 0) { - getship(pp->pln_ship, &ship); - type = EF_SHIP; - ptr = (s_char *) &ship; - } else - if (pp->pln_land >= 0) { - getland(pp->pln_land, &land); - type = EF_LAND; - ptr = (s_char *) &land; - } else { - getsect(pp->pln_x, pp->pln_y, §); - type = EF_SECTOR; - ptr = (s_char *) § - } - getvec(VT_ITEM, vec, ptr, type); - if (pcp->pl_fuel > vec[I_PETROL]) { - return -1; - } - vec[I_PETROL] -= pcp->pl_fuel; - rval = 0; - if (!(flags & P_F)) { - item = 0; - needed = 0; - switch (mission) { - case 's': - case 'p': - if (pp->pln_nuketype == -1) { - item = I_SHELL; - needed = pp->pln_load; - } - break; - case 't': - if ((pcp->pl_flags & P_C) == 0 || ip == 0) - break; - item = ip - ichr; - needed = (pp->pln_load * 2) / ip->i_lbs; - break; - case 'd': - if ((pcp->pl_flags & P_C) == 0 || ip == 0) - break; - item = ip - ichr; - needed = (pp->pln_load * 2) / ip->i_lbs; - break; - case 'a': - if ((pcp->pl_flags & (P_V|P_C)) == 0) - break; - item = I_MILIT; - needed = pp->pln_load / ip->i_lbs; - break; - case 'n': - if (pp->pln_nuketype == -1) - rval = -1; - break; - case 'i': /* missile interception */ - if (pp->pln_load) { - item = I_SHELL; - needed = pp->pln_load; - } - break; - default: - break; - } - if (rval < 0 || (item && needed <= 0)) { - return -1; - } - if ((vec[item] < needed) && (item == I_SHELL)) - vec[item] += supply_commod(plp->plane.pln_own, - plp->plane.pln_x,plp->plane.pln_y, - I_SHELL,needed); - if (vec[item] < needed) { - return -1; - } else { - vec[item] -= needed; - } - if (item == I_SHELL && (mission == 's' || mission == 'p')) - plp->bombs = needed; - else - plp->misc = needed; - } - putvec(VT_ITEM, vec, ptr, type); - if (type == EF_SHIP) - putship(ship.shp_uid,&ship); - else if (type == EF_LAND) - putland(land.lnd_uid,&land); - else - putsect(§); - return rval; + register struct plchrstr *pcp; + struct plnstr *pp; + int needed; + struct lndstr land; + struct shpstr ship; + struct sctstr sect; + int type; + s_char *ptr; + int item; + int rval; + int vec[I_MAX + 1]; + + pp = &plp->plane; + pcp = plp->pcp; + if (pp->pln_ship >= 0) { + getship(pp->pln_ship, &ship); + type = EF_SHIP; + ptr = (s_char *)&ship; + } else if (pp->pln_land >= 0) { + getland(pp->pln_land, &land); + type = EF_LAND; + ptr = (s_char *)&land; + } else { + getsect(pp->pln_x, pp->pln_y, §); + type = EF_SECTOR; + ptr = (s_char *)§ + } + getvec(VT_ITEM, vec, ptr, type); + if (pcp->pl_fuel > vec[I_PETROL]) { + return -1; + } + vec[I_PETROL] -= pcp->pl_fuel; + rval = 0; + if (!(flags & P_F)) { + item = 0; + needed = 0; + switch (mission) { + case 's': + case 'p': + if (pp->pln_nuketype == -1) { + item = I_SHELL; + needed = pp->pln_load; + } + break; + case 't': + if ((pcp->pl_flags & P_C) == 0 || ip == 0) + break; + item = ip - ichr; + needed = (pp->pln_load * 2) / ip->i_lbs; + break; + case 'd': + if ((pcp->pl_flags & P_C) == 0 || ip == 0) + break; + item = ip - ichr; + needed = (pp->pln_load * 2) / ip->i_lbs; + break; + case 'a': + if ((pcp->pl_flags & (P_V | P_C)) == 0) + break; + item = I_MILIT; + needed = pp->pln_load / ip->i_lbs; + break; + case 'n': + if (pp->pln_nuketype == -1) + rval = -1; + break; + case 'i': /* missile interception */ + if (pp->pln_load) { + item = I_SHELL; + needed = pp->pln_load; + } + break; + default: + break; + } + if (rval < 0 || (item && needed <= 0)) { + return -1; + } + if ((vec[item] < needed) && (item == I_SHELL)) + vec[item] += supply_commod(plp->plane.pln_own, + plp->plane.pln_x, plp->plane.pln_y, + I_SHELL, needed); + if (vec[item] < needed) { + return -1; + } else { + vec[item] -= needed; + } + if (item == I_SHELL && (mission == 's' || mission == 'p')) + plp->bombs = needed; + else + plp->misc = needed; + } + putvec(VT_ITEM, vec, ptr, type); + if (type == EF_SHIP) + putship(ship.shp_uid, &ship); + else if (type == EF_LAND) + putland(land.lnd_uid, &land); + else + putsect(§); + return rval; } /* @@ -1346,33 +1368,33 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char missi int find_airport(struct emp_qelem *airp, coord x, coord y) { - struct emp_qelem *qp; - struct airport *a; + struct emp_qelem *qp; + struct airport *a; - for (qp = airp->q_forw; qp != airp; qp = qp->q_forw){ - a = (struct airport *)qp; - if ((a->x == x) && (a->y == y)) - return 1; - } + for (qp = airp->q_forw; qp != airp; qp = qp->q_forw) { + a = (struct airport *)qp; + if ((a->x == x) && (a->y == y)) + return 1; + } - return 0; + return 0; } /* #*# This needs to be changed to include acc's -KHS */ void add_airport(struct emp_qelem *airp, coord x, coord y) { - struct airport *a; - struct sctstr sect; + struct airport *a; + struct sctstr sect; - a = (struct airport *)malloc(sizeof(struct airport)); + a = (struct airport *)malloc(sizeof(struct airport)); - a->x = x; - a->y = y; - getsect(x,y,§); - a->own = sect.sct_own; + a->x = x; + a->y = y; + getsect(x, y, §); + a->own = sect.sct_own; - emp_insque((struct emp_qelem *)a,airp); + emp_insque((struct emp_qelem *)a, airp); } /* @@ -1382,122 +1404,116 @@ add_airport(struct emp_qelem *airp, coord x, coord y) void divide(struct emp_qelem *l1, struct emp_qelem *l2, coord x, coord y) { - struct emp_qelem *qp, *next; - struct plist *plp; + struct emp_qelem *qp, *next; + struct plist *plp; - for (qp = l1->q_forw; qp != l1; qp = next){ - next = qp->q_forw; - plp = (struct plist *)qp; + for (qp = l1->q_forw; qp != l1; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; - if (plp->plane.pln_x != x) - continue; - if (plp->plane.pln_y != y) - continue; + if (plp->plane.pln_x != x) + continue; + if (plp->plane.pln_y != y) + continue; - emp_remque(qp); - emp_insque(qp,l2); - } + emp_remque(qp); + emp_insque(qp, l2); + } } int -air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, natid victim, s_char *s, int hardtarget) +air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, + natid victim, s_char *s, int hardtarget) { - struct emp_qelem *qp; - struct plist *plp; - struct plnstr *pp; - int newdam,dam=0; - int hitchance; - int nukedam; - - for(qp = bombers->q_forw; qp != bombers; qp = qp->q_forw){ - plp = (struct plist *)qp; - pp = &plp->plane; - - if ((mission == MI_SINTERDICT) && !(plp->pcp->pl_flags & P_A)) - continue; - - if (!plp->bombs) - continue; + struct emp_qelem *qp; + struct plist *plp; + struct plnstr *pp; + int newdam, dam = 0; + int hitchance; + int nukedam; - newdam = 0; - if (plp->pcp->pl_flags & P_A) { - if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { - wu(0,pp->pln_own, - "\t%s detects sub movement in %s\n", - prplane(pp), xyas(x,y,pp->pln_own)); - continue; - } - if (getrel(getnatp(pp->pln_own),victim) > HOSTILE) { - wu(0,pp->pln_own, - "\t%s tracks %s %s at %s\n", - prplane(pp), - cname(victim), s, xyas(x,y,pp->pln_own)); - continue; - } - wu(0,pp->pln_own, - "\t%s depth-charging %s %s in %s\n", - prplane(pp), - cname(victim), - s, - xyas(x,y,pp->pln_own)); - } else { - wu(0,pp->pln_own, - "\t%s pinbombing %s %s in %s\n", - prplane(pp), - cname(victim), - s, - xyas(x,y,pp->pln_own)); - } - hitchance = pln_hitchance(pp, hardtarget, EF_SHIP); - if (plp->plane.pln_nuketype != -1) - hitchance = 100; - else if (hardtarget != SECT_HARDTARGET) - wu(0,pp->pln_own,"\t\t%d%% hitchance...", hitchance); - /* Always calculate damage */ - if (roll(100) <= hitchance) { - newdam = pln_damage(&plp->plane,x,y,'p',&nukedam, 1); - if (nukedam) { - if (mission == MI_INTERDICT) { - wu(0,pp->pln_own, - "\t\tnuclear warhead does %d damage to %s %s\n", - prplane(pp), - nukedam, cname(victim), s); - dam += nukedam; - } - } else { - wu(0,pp->pln_own, - "\t\thit %s %s for %d damage\n", - cname(victim), s, newdam); - dam += newdam; - } - } else { - newdam = pln_damage(&plp->plane,x,y,'p',&nukedam, 0); - wu(0,pp->pln_own,"missed\n"); - if (mission == MI_SINTERDICT) { - mpr(victim, - "RUMBLE... your sub in %s hears a depth-charge explode nearby\n", - xyas(x,y,victim)); - } else if (*s == 's') { - mpr(victim, - "SPLASH! Bombs miss your %s in %s\n", - s, xyas(x,y,victim)); - } else { - mpr(victim, "SPLAT! Bombs miss your %s in %s\n", - s, xyas(x, y, victim)); - } - /* Now, even though we missed, the bombs - land somewhere. */ - collateral_damage(x, y, newdam, bombers); - } - - /* use up missiles */ - if (plp->pcp->pl_flags & P_M) { - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; + for (qp = bombers->q_forw; qp != bombers; qp = qp->q_forw) { + plp = (struct plist *)qp; + pp = &plp->plane; + + if ((mission == MI_SINTERDICT) && !(plp->pcp->pl_flags & P_A)) + continue; + + if (!plp->bombs) + continue; + + newdam = 0; + if (plp->pcp->pl_flags & P_A) { + if (roll(100) > pln_identchance(pp, hardtarget, EF_SHIP)) { + wu(0, pp->pln_own, + "\t%s detects sub movement in %s\n", + prplane(pp), xyas(x, y, pp->pln_own)); + continue; + } + if (getrel(getnatp(pp->pln_own), victim) > HOSTILE) { + wu(0, pp->pln_own, + "\t%s tracks %s %s at %s\n", + prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own)); + continue; + } + wu(0, pp->pln_own, + "\t%s depth-charging %s %s in %s\n", + prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own)); + } else { + wu(0, pp->pln_own, + "\t%s pinbombing %s %s in %s\n", + prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own)); + } + hitchance = pln_hitchance(pp, hardtarget, EF_SHIP); + if (plp->plane.pln_nuketype != -1) + hitchance = 100; + else if (hardtarget != SECT_HARDTARGET) + wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance); + /* Always calculate damage */ + if (roll(100) <= hitchance) { + newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1); + if (nukedam) { + if (mission == MI_INTERDICT) { + wu(0, pp->pln_own, + "\t\tnuclear warhead does %d damage to %s %s\n", + prplane(pp), nukedam, cname(victim), s); + dam += nukedam; } - } + } else { + wu(0, pp->pln_own, + "\t\thit %s %s for %d damage\n", + cname(victim), s, newdam); + dam += newdam; + } + } else { + newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0); + wu(0, pp->pln_own, "missed\n"); + if (mission == MI_SINTERDICT) { + mpr(victim, + "RUMBLE... your sub in %s hears a depth-charge explode nearby\n", + xyas(x, y, victim)); + } else if (*s == 's') { + mpr(victim, + "SPLASH! Bombs miss your %s in %s\n", + s, xyas(x, y, victim)); + } else { + mpr(victim, "SPLAT! Bombs miss your %s in %s\n", + s, xyas(x, y, victim)); + } + /* Now, even though we missed, the bombs + land somewhere. */ + collateral_damage(x, y, newdam, bombers); + } - return dam; + /* use up missiles */ + if (plp->pcp->pl_flags & P_M) { + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_own = 0; + } + } + + return dam; } /* @@ -1506,41 +1522,42 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission, natid victi * sector. If so, do air combat */ int -air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct emp_qelem *esc_list) +air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, + struct emp_qelem *esc_list) { - int dam=0,cn; - int mission_flags, tech, combat=0, rel, dist, z; - struct emp_qelem *qp, interceptors, airp, i, empty, *next; - struct plist *plp; - struct genlist *glp; - struct genitem *gp; - struct genlist mi[MAXNOC]; - s_char path[512]; - int count; - int tcount; - + int dam = 0, cn; + int mission_flags, tech, combat = 0, rel, dist, z; + struct emp_qelem *qp, interceptors, airp, i, empty, *next; + struct plist *plp; + struct genlist *glp; + struct genitem *gp; + struct genlist mi[MAXNOC]; + s_char path[512]; + int count; + int tcount; + count = 0; for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) count++; for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) count++; - - bzero((s_char *)mi,sizeof(mi)); + + bzero((s_char *)mi, sizeof(mi)); for (z = 1; z < MAXNOC; z++) emp_initque((struct emp_qelem *)&mi[z]); - - build_mission_list_type(mi,x,y,MI_AIR_DEFENSE,EF_PLANE,victim); - + + build_mission_list_type(mi, x, y, MI_AIR_DEFENSE, EF_PLANE, victim); + for (cn = 1; cn < MAXNOC; cn++) { /* Check our relations */ - rel = getrel(getnatp(cn),victim); - + rel = getrel(getnatp(cn), victim); + if (rel > HOSTILE) continue; - + if (QEMPTY(&mi[cn].queue)) continue; - + /* Ok, make a list of all the interceptors. Note that this *copies* the * list from the mission creation. This list must be deleted later. */ emp_initque(&interceptors); @@ -1550,15 +1567,15 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct glp = (struct genlist *)qp; gp = (struct genitem *)glp->thing; plp = (struct plist *)qp; - - dist = mapdist(x,y,gp->x,gp->y); - + + dist = mapdist(x, y, gp->x, gp->y); + plp = (struct plist *)malloc(sizeof(struct plist)); - bzero((s_char *)plp,sizeof(struct plist)); + bzero((s_char *)plp, sizeof(struct plist)); plp->pcp = (struct plchrstr *)glp->cp; bcopy(glp->thing, (s_char *)&plp->plane, sizeof(struct plnstr)); - + /* missiles go one way, so we can use all the range */ if (!(plp->pcp->pl_flags & P_M)) dist *= 2; @@ -1569,18 +1586,19 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct } emp_insque(&plp->queue, &interceptors); } - + /* Remove those who cannot go */ - mission_pln_sel(&interceptors,P_F,0,SECT_HARDTARGET); - + mission_pln_sel(&interceptors, P_F, 0, SECT_HARDTARGET); + if (QEMPTY(&interceptors)) continue; - + /* Now, delete all the extras, but delete the first ones, not the last ones, so - * that the higher numbered planes go into battle (they should be the better ones + * that the higher numbered planes go into battle (they should be the better ones * at fighting, if all went well.) */ tcount = 0; - for (qp = interceptors.q_forw; qp != (&interceptors); qp = qp->q_forw) + for (qp = interceptors.q_forw; qp != (&interceptors); + qp = qp->q_forw) tcount++; tcount -= (count * 2); /* Just in case there are more incoming than we have */ @@ -1599,27 +1617,28 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct /* Now, make a list of all the airports these planes are coming from */ emp_initque(&airp); - for (qp = interceptors.q_forw ; qp != (&interceptors); qp = qp->q_forw) { + for (qp = interceptors.q_forw; qp != (&interceptors); + qp = qp->q_forw) { plp = (struct plist *)qp; - if (!find_airport(&airp,plp->plane.pln_x, plp->plane.pln_y)) - add_airport(&airp,plp->plane.pln_x, plp->plane.pln_y); + if (!find_airport(&airp, plp->plane.pln_x, plp->plane.pln_y)) + add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y); } - + /* Now, fly them out one airport at a time */ for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) { - struct airport *air; - + struct airport *air; + air = (struct airport *)qp; - dist = mapdist(x,y,air->x,air->y); - + dist = mapdist(x, y, air->x, air->y); + emp_initque(&i); - + /* Split off the interceptors at this base into i */ divide(&interceptors, &i, air->x, air->y); - + tech = 0; mission_flags = 0; - mission_flags |= P_X; /* stealth (shhh) */ + mission_flags |= P_X; /* stealth (shhh) */ /* gets turned off if not all choppers */ mission_flags |= P_H; sam_intercept(bomb_list, &i, cn, victim, x, y, 0); @@ -1635,8 +1654,9 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct pln_put(&i); continue; } - mission_flags = mission_pln_arm(&i,air->x,air->y,2*dist,'r',0, - P_F,mission_flags,&tech); + mission_flags = + mission_pln_arm(&i, air->x, air->y, 2 * dist, 'r', 0, P_F, + mission_flags, &tech); /* Did we run out of interceptors? */ if (QEMPTY(&i)) @@ -1648,47 +1668,47 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct pln_put(&i); continue; } - + BestAirPath(path, air->x, air->y, x, y); wu(0, cn, "Flying %s mission from %s\n", - mission_name(MI_AIR_DEFENSE), - xyas(air->x, air->y, cn)); + mission_name(MI_AIR_DEFENSE), xyas(air->x, air->y, cn)); if (air->own && (air->own != cn)) { wu(0, air->own, "%s is flying %s mission from %s\n", cname(cn), mission_name(MI_AIR_DEFENSE), xyas(air->x, air->y, air->own)); } - + /* Now, fly the planes to the sector */ emp_initque(&empty); ac_encounter(&i, &empty, air->x, air->y, - path, mission_flags,1, bomb_list, esc_list); - + path, mission_flags, 1, bomb_list, esc_list); + /* If none made it, continue */ if (QEMPTY(&i)) continue; - + /* Some made it, so now they get to try to fight. */ /* Intercept the escorts first */ combat = 0; - if (!QEMPTY(esc_list)){ + if (!QEMPTY(esc_list)) { mpr(victim, "%s air defense planes intercept!\n", cname(cn)); ac_combat_headers(victim, cn); - ac_airtoair(esc_list,&i,air->own); + ac_airtoair(esc_list, &i, air->own); combat = 1; } /* Now intercept the bombers */ if (!QEMPTY(bomb_list)) { if (!combat) { - mpr(victim, "%s air defense planes intercept!\n", cname(cn)); + mpr(victim, "%s air defense planes intercept!\n", + cname(cn)); ac_combat_headers(victim, cn); } ac_airtoair(bomb_list, &i, air->own); PR(cn, "\n"); PR(victim, "\n"); } - + pln_put(&i); } } @@ -1707,6 +1727,3 @@ air_defense(coord x, coord y, natid victim, struct emp_qelem *bomb_list, struct return dam; } - - - diff --git a/src/lib/subs/move.c b/src/lib/subs/move.c index ea35d85cd..770aab6e0 100644 --- a/src/lib/subs/move.c +++ b/src/lib/subs/move.c @@ -49,209 +49,213 @@ extern int move_map(s_char *what, coord curx, coord cury, s_char *arg); int -move_ground(s_char *what, struct sctstr *start, struct sctstr *end, double mobility, double weight, s_char *path, int (*map) (s_char *, coord, coord, s_char *), int exploring, int *dam) - - - /* RESULT */ - - - - - +move_ground(s_char *what, struct sctstr *start, struct sctstr *end, + double mobility, double weight, s_char *path, + int (*map) (s_char *, coord, coord, s_char *), int exploring, + int *dam) + + + /* RESULT */ { - struct sctstr sect, ending_sect; - struct sctstr next, dsect; - int vec[I_MAX+1]; - coord curx, cury, oldx, oldy; - coord tmpx, tmpy; - coord dx, dy; - s_char *movstr, *BestLandPath(s_char *, struct sctstr *, struct sctstr *, double *, int); - double sect_mcost; - double total_mcost; - double mv_cost; - int dir; - int intcost; - int takedam = (*dam), out=0; - s_char bpath[512]; - s_char buf2[512]; - s_char prompt[128]; - s_char buf[1024]; + struct sctstr sect, ending_sect; + struct sctstr next, dsect; + int vec[I_MAX + 1]; + coord curx, cury, oldx, oldy; + coord tmpx, tmpy; + coord dx, dy; + s_char *movstr, *BestLandPath(s_char *, struct sctstr *, + struct sctstr *, double *, int); + double sect_mcost; + double total_mcost; + double mv_cost; + int dir; + int intcost; + int takedam = (*dam), out = 0; + s_char bpath[512]; + s_char buf2[512]; + s_char prompt[128]; + s_char buf[1024]; - if (mobility <= 0.0) - return -1; - *dam = 0; - if (path && sarg_xy(path, &dx, &dy) && getsect(dx,dy,&ending_sect)){ - if ((ending_sect.sct_x == start->sct_x) && - (ending_sect.sct_y == start->sct_y)){ - pr("Start sector is ending sector!\n"); - return -1; - } - pr("Looking for best path to %s\n", path); - path = BestLandPath(buf2, start, &ending_sect, &total_mcost, MOB_ROAD); - if (exploring && (path != (s_char *)0)) /* take off the 'h' */ - *(path+strlen(path)-1) = '\0'; - if (path == (s_char *)0) - pr("No owned path exists!\n"); - else{ - pr("Using best path '%s', movement cost %1.3f\n", - path,total_mcost); - bzero(bpath,512); - bcopy(path,bpath,strlen(path)); - path = bpath; - } - if ((total_mcost*weight) > mobility){ - pr("Not enough mobility to go all the way. Nothing moved.\n"); - *end = *start; - return -1; - } + if (mobility <= 0.0) + return -1; + *dam = 0; + if (path && sarg_xy(path, &dx, &dy) && getsect(dx, dy, &ending_sect)) { + if ((ending_sect.sct_x == start->sct_x) && + (ending_sect.sct_y == start->sct_y)) { + pr("Start sector is ending sector!\n"); + return -1; } - movstr = path; - tmpx = start->sct_x; - curx = tmpx; - tmpy = start->sct_y; - cury = tmpy; - total_mcost = 0.0; - if (getsect(curx, cury, §) < 0) { - logerror("move_path: getsect %d,%d", curx, cury); - return -1; + pr("Looking for best path to %s\n", path); + path = + BestLandPath(buf2, start, &ending_sect, &total_mcost, + MOB_ROAD); + if (exploring && (path != (s_char *)0)) /* take off the 'h' */ + *(path + strlen(path) - 1) = '\0'; + if (path == (s_char *)0) + pr("No owned path exists!\n"); + else { + pr("Using best path '%s', movement cost %1.3f\n", + path, total_mcost); + bzero(bpath, 512); + bcopy(path, bpath, strlen(path)); + path = bpath; } - for (;;) { - tmpx = curx; - tmpy = cury; - oldx = curx; - oldy = cury; - if (movstr == 0 || *movstr == 0) { - if (exploring) { - map(what, curx, cury, (s_char *)0); } - else { - move_map(what, curx, cury, (s_char *)0); } - sprintf(prompt, "<%.1f: %c %s> ", mobility, - dchr[sect.sct_type].d_mnem, - xyas(sect.sct_x, sect.sct_y, player->cnum)); - movstr = getstring(prompt, buf); - } - if (movstr && sarg_xy(movstr, &dx, &dy)){ - if (getsect(dx,dy,&dsect)){ - movstr=BestLandPath(buf2,§,&dsect,&mv_cost,MOB_ROAD); - }else{ - pr("Invalid destination sector!\n"); - movstr=(s_char *)0; - } + if ((total_mcost * weight) > mobility) { + pr("Not enough mobility to go all the way. Nothing moved.\n"); + *end = *start; + return -1; + } + } + movstr = path; + tmpx = start->sct_x; + curx = tmpx; + tmpy = start->sct_y; + cury = tmpy; + total_mcost = 0.0; + if (getsect(curx, cury, §) < 0) { + logerror("move_path: getsect %d,%d", curx, cury); + return -1; + } + for (;;) { + tmpx = curx; + tmpy = cury; + oldx = curx; + oldy = cury; + if (movstr == 0 || *movstr == 0) { + if (exploring) { + map(what, curx, cury, (s_char *)0); + } else { + move_map(what, curx, cury, (s_char *)0); + } + sprintf(prompt, "<%.1f: %c %s> ", mobility, + dchr[sect.sct_type].d_mnem, + xyas(sect.sct_x, sect.sct_y, player->cnum)); + movstr = getstring(prompt, buf); + } + if (movstr && sarg_xy(movstr, &dx, &dy)) { + if (getsect(dx, dy, &dsect)) { + movstr = + BestLandPath(buf2, §, &dsect, &mv_cost, MOB_ROAD); + } else { + pr("Invalid destination sector!\n"); + movstr = (s_char *)0; + } - if (movstr == (s_char *)0){ - pr("Can't get to %s from here!\n", - xyas(dx,dy,player->cnum)); - movstr=(s_char *)0; - }else{ - if ((mv_cost*weight) > mobility){ - pr("Not enough mobility to go all the way. Nothing moved.\n"); - movstr = (s_char *)0; - }else{ - pr("Using best path '%s', movement cost %1.3f\n", - movstr,mv_cost); - bzero(bpath,512); - bcopy(movstr,bpath,strlen(movstr)); - movstr = bpath; - } - } - } - if (movstr == 0 || *movstr == 0) - movstr = dirch; - if ((dir = chkdir(*movstr, DIR_STOP, DIR_MAP)) < 0) { - pr("\"%c\" is not legal...", *movstr); - direrr("'%c' to stop ", "'%c' to view ", - "& '%c' to map\n"); - *movstr = 0; - continue; - } - movstr++; - if (dir == DIR_MAP) { - if (!exploring) - map(what, curx, cury, movstr+1); - *movstr = 0; - continue; - } else if (dir == DIR_STOP) - break; - else if (dir == DIR_VIEW) { - pr("%d%% %s with %d civilians.\n", sect.sct_effic, - dchr[sect.sct_type].d_name, - getvar(V_CIVIL, (s_char *)§, EF_SECTOR)); - continue; - } - /* - * now see if we can move into the - * next sector. Mobility, terrain, - * or ownership may prevent us. - */ - tmpx += diroff[dir][0]; - tmpy += diroff[dir][1]; - if (getsect(tmpx, tmpy, &next) < 0) { - pr("You can't go there...\n"); - *movstr = 0; - continue; + if (movstr == (s_char *)0) { + pr("Can't get to %s from here!\n", + xyas(dx, dy, player->cnum)); + movstr = (s_char *)0; + } else { + if ((mv_cost * weight) > mobility) { + pr("Not enough mobility to go all the way. Nothing moved.\n"); + movstr = (s_char *)0; + } else { + pr("Using best path '%s', movement cost %1.3f\n", + movstr, mv_cost); + bzero(bpath, 512); + bcopy(movstr, bpath, strlen(movstr)); + movstr = bpath; } - if (!player->god) { - if ((next.sct_type == SCT_SANCT) && - (next.sct_own != player->cnum)) { - pr("Converts, huh?\n"); - *end = next; - intcost = (int) total_mcost; - if (chance(total_mcost - intcost)) - intcost++; - return intcost; - } - getvec(VT_ITEM, vec, (s_char *)&next, EF_SECTOR); - sect_mcost = sector_mcost(&next, MOB_ROAD); - if ((!player->owner && (!exploring || - (vec[I_MILIT] || vec[I_CIVIL]))) || - sect_mcost == -1.0) { - /* already-owned, or prohibited terrain */ - pr("You can't go there...\n"); - *movstr = 0; - continue; - } - sect_mcost *= weight; - if (sect_mcost > mobility) { - pr("Not enough mobility. "); - pr("You can't go there...\n"); - *movstr = 0; - continue; - } - mobility -= sect_mcost; - total_mcost += sect_mcost; - } - curx = tmpx; - cury = tmpy; - if (cury != start->sct_y) - out=1; - if (curx != start->sct_x) - out=1; + } + } + if (movstr == 0 || *movstr == 0) + movstr = dirch; + if ((dir = chkdir(*movstr, DIR_STOP, DIR_MAP)) < 0) { + pr("\"%c\" is not legal...", *movstr); + direrr("'%c' to stop ", "'%c' to view ", "& '%c' to map\n"); + *movstr = 0; + continue; + } + movstr++; + if (dir == DIR_MAP) { + if (!exploring) + map(what, curx, cury, movstr + 1); + *movstr = 0; + continue; + } else if (dir == DIR_STOP) + break; + else if (dir == DIR_VIEW) { + pr("%d%% %s with %d civilians.\n", sect.sct_effic, + dchr[sect.sct_type].d_name, + getvar(V_CIVIL, (s_char *)§, EF_SECTOR)); + continue; + } + /* + * now see if we can move into the + * next sector. Mobility, terrain, + * or ownership may prevent us. + */ + tmpx += diroff[dir][0]; + tmpy += diroff[dir][1]; + if (getsect(tmpx, tmpy, &next) < 0) { + pr("You can't go there...\n"); + *movstr = 0; + continue; + } + if (!player->god) { + if ((next.sct_type == SCT_SANCT) && + (next.sct_own != player->cnum)) { + pr("Converts, huh?\n"); + *end = next; + intcost = (int)total_mcost; + if (chance(total_mcost - intcost)) + intcost++; + return intcost; + } + getvec(VT_ITEM, vec, (s_char *)&next, EF_SECTOR); + sect_mcost = sector_mcost(&next, MOB_ROAD); + if ((!player->owner && (!exploring || + (vec[I_MILIT] || vec[I_CIVIL]))) || + sect_mcost == -1.0) { + /* already-owned, or prohibited terrain */ + pr("You can't go there...\n"); + *movstr = 0; + continue; + } + sect_mcost *= weight; + if (sect_mcost > mobility) { + pr("Not enough mobility. "); + pr("You can't go there...\n"); + *movstr = 0; + continue; + } + mobility -= sect_mcost; + total_mcost += sect_mcost; + } + curx = tmpx; + cury = tmpy; + if (cury != start->sct_y) + out = 1; + if (curx != start->sct_x) + out = 1; - sect = next; + sect = next; - if (takedam) - *dam += check_lmines(sect.sct_x, sect.sct_y, weight); - if (*dam >= 100) - break; - /* - * Check and see if anyone will interdict us - */ - if (takedam && chance(weight/100.0) && - ((curx != oldx) || (cury != oldy))) - (*dam) += ground_interdict(curx,cury,player->cnum,"commodities"); - if (*dam >= 100) - break; - } - *end = sect; - intcost = (int) total_mcost; - if (intcost < 0) - return -1; - if ((start->sct_x == end->sct_x) && (start->sct_y == end->sct_y) && !out) - return -1; + if (takedam) + *dam += check_lmines(sect.sct_x, sect.sct_y, weight); + if (*dam >= 100) + break; + /* + * Check and see if anyone will interdict us + */ + if (takedam && chance(weight / 100.0) && + ((curx != oldx) || (cury != oldy))) + (*dam) += + ground_interdict(curx, cury, player->cnum, "commodities"); + if (*dam >= 100) + break; + } + *end = sect; + intcost = (int)total_mcost; + if (intcost < 0) + return -1; + if ((start->sct_x == end->sct_x) && (start->sct_y == end->sct_y) + && !out) + return -1; - if (chance(total_mcost - intcost)) - intcost++; - return intcost; + if (chance(total_mcost - intcost)) + intcost++; + return intcost; } @@ -259,117 +263,118 @@ move_ground(s_char *what, struct sctstr *start, struct sctstr *end, double mobil int move_map(s_char *what, coord curx, coord cury, s_char *arg) { - struct nstr_sect ns; - struct natstr *np; - struct sctstr sect; - coord rel_x, rel_y; - s_char range[128]; - s_char view[7]; - int i; - int vec[I_MAX+1]; - int changed = 0; - - np = getnatp(player->cnum); - rel_x = xrel(np, curx); - rel_y = yrel(np, cury); - sprintf(range, "%d:%d,%d:%d", rel_x-2, rel_x+2, rel_y-1, rel_y+1); - player->condarg = 0; - /* This is necessary, otherwise move_map would attempt to pay */ - /* attention to the conditional arguments left behind by such */ - /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */ - /* 100% efficienct sects, and get all screwed up --ts */ - if (!snxtsct(&ns, range)) - return RET_FAIL; - i = 0; - while (i < 7 && nxtsct(&ns, §)) { - view[i] = dchr[sect.sct_type].d_mnem; - switch (sect.sct_type) { - case SCT_WATER: - case SCT_RURAL: - case SCT_MOUNT: - case SCT_WASTE: - case SCT_PLAINS: - break; - default: - if (sect.sct_own != player->cnum && !player->god) - view[i] = '?'; - break; - } - changed += map_set(player->cnum, ns.x, ns.y, view[i], 0); - i++; - } - if (changed) - writemap(player->cnum); - if (!getsect(curx, cury, §)) - return RET_FAIL; - getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - pr(" %c %c eff mob civ mil uw food work avail\n", - view[0], view[1]); - pr(" %c %c %c %3d %3d %4d %4d %4d %4d %3d %3d\n", - view[2], view[3], view[4], - sect.sct_effic, sect.sct_mobil, vec[I_CIVIL],vec[I_MILIT], - vec[I_UW],vec[I_FOOD], sect.sct_work, sect.sct_avail); - pr(" %c %c\n", view[5], view[6]); - return RET_OK; + struct nstr_sect ns; + struct natstr *np; + struct sctstr sect; + coord rel_x, rel_y; + s_char range[128]; + s_char view[7]; + int i; + int vec[I_MAX + 1]; + int changed = 0; + + np = getnatp(player->cnum); + rel_x = xrel(np, curx); + rel_y = yrel(np, cury); + sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1, + rel_y + 1); + player->condarg = 0; + /* This is necessary, otherwise move_map would attempt to pay */ + /* attention to the conditional arguments left behind by such */ + /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */ + /* 100% efficienct sects, and get all screwed up --ts */ + if (!snxtsct(&ns, range)) + return RET_FAIL; + i = 0; + while (i < 7 && nxtsct(&ns, §)) { + view[i] = dchr[sect.sct_type].d_mnem; + switch (sect.sct_type) { + case SCT_WATER: + case SCT_RURAL: + case SCT_MOUNT: + case SCT_WASTE: + case SCT_PLAINS: + break; + default: + if (sect.sct_own != player->cnum && !player->god) + view[i] = '?'; + break; + } + changed += map_set(player->cnum, ns.x, ns.y, view[i], 0); + i++; + } + if (changed) + writemap(player->cnum); + if (!getsect(curx, cury, §)) + return RET_FAIL; + getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); + pr(" %c %c eff mob civ mil uw food work avail\n", + view[0], view[1]); + pr(" %c %c %c %3d %3d %4d %4d %4d %4d %3d %3d\n", + view[2], view[3], view[4], + sect.sct_effic, sect.sct_mobil, vec[I_CIVIL], vec[I_MILIT], + vec[I_UW], vec[I_FOOD], sect.sct_work, sect.sct_avail); + pr(" %c %c\n", view[5], view[6]); + return RET_OK; } int fly_map(coord curx, coord cury) { - struct nstr_sect ns; - struct natstr *np; - struct sctstr sect; - coord rel_x, rel_y; - s_char view[7]; - int i; - s_char range[128]; - - np = getnatp(player->cnum); - rel_x = xrel(np, curx); - rel_y = yrel(np, cury); - sprintf(range, "%d:%d,%d:%d", rel_x-2, rel_x+2, rel_y-1, rel_y+1); - player->condarg = 0; - /* This is necessary, otherwise move_map would attempt to pay */ - /* attention to the conditional arguments left behind by such */ - /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */ - /* 100% efficienct sects, and get all screwed up --ts */ + struct nstr_sect ns; + struct natstr *np; + struct sctstr sect; + coord rel_x, rel_y; + s_char view[7]; + int i; + s_char range[128]; + + np = getnatp(player->cnum); + rel_x = xrel(np, curx); + rel_y = yrel(np, cury); + sprintf(range, "%d:%d,%d:%d", rel_x - 2, rel_x + 2, rel_y - 1, + rel_y + 1); + player->condarg = 0; + /* This is necessary, otherwise move_map would attempt to pay */ + /* attention to the conditional arguments left behind by such */ + /* a command as "tran p -1,-1 ?eff=100".. It'd then only see */ + /* 100% efficienct sects, and get all screwed up --ts */ - if (!snxtsct(&ns, range)) - return RET_FAIL; - i = 0; - while (i < 7 && nxtsct(&ns, §)){ - if (!(view[i] = player->bmap[sctoff(ns.x, ns.y)])) - view[i] = ' '; - i++; - } + if (!snxtsct(&ns, range)) + return RET_FAIL; + i = 0; + while (i < 7 && nxtsct(&ns, §)) { + if (!(view[i] = player->bmap[sctoff(ns.x, ns.y)])) + view[i] = ' '; + i++; + } - pr(" %c %c\n",view[0], view[1]); - pr(" %c %c %c\n", view[2], view[3], view[4]); - pr(" %c %c\n", view[5], view[6]); - return RET_OK; + pr(" %c %c\n", view[0], view[1]); + pr(" %c %c %c\n", view[2], view[3], view[4]); + pr(" %c %c\n", view[5], view[6]); + return RET_OK; } int check_lmines(coord x, coord y, double weight) { - struct sctstr sect; - int mines; - int dam = 0; + struct sctstr sect; + int mines; + int dam = 0; - getsect(x, y, §); - mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); - if (mines > 0 && - sect.sct_oldown != player->cnum && - chance(DMINE_LHITCHANCE(mines)) && - chance(weight/100.0)) { - pr_beep(); - pr("Blammo! Landmines detected! in %s ", - xyas(sect.sct_x,sect.sct_y,player->cnum)); - dam = roll(20); - --mines; - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putsect(§); - pr("%d damage sustained.\n", dam); - } - return dam; + getsect(x, y, §); + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + if (mines > 0 && + sect.sct_oldown != player->cnum && + chance(DMINE_LHITCHANCE(mines)) && chance(weight / 100.0)) { + pr_beep(); + pr("Blammo! Landmines detected! in %s ", + xyas(sect.sct_x, sect.sct_y, player->cnum)); + dam = roll(20); + --mines; + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putsect(§); + pr("%d damage sustained.\n", dam); + } + return dam; } diff --git a/src/lib/subs/mslsub.c b/src/lib/subs/mslsub.c index 8f76405da..7b4589de9 100644 --- a/src/lib/subs/mslsub.c +++ b/src/lib/subs/mslsub.c @@ -55,370 +55,382 @@ int msl_equip(struct plnstr *pp) { - struct plist pl; + struct plist pl; - bzero((s_char *)&pl, sizeof(struct plist)); - pl.pcp = plchr + pp->pln_type; - bcopy((s_char *)pp, (s_char *)&pl.plane, sizeof(struct plnstr)); - return mission_pln_equip(&pl, 0, 0, 'p'); + bzero((s_char *)&pl, sizeof(struct plist)); + pl.pcp = plchr + pp->pln_type; + bcopy((s_char *)pp, (s_char *)&pl.plane, sizeof(struct plnstr)); + return mission_pln_equip(&pl, 0, 0, 'p'); } int -msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item, int snews_item, s_char *what, coord x, coord y, int victim) +msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item, + int snews_item, s_char *what, coord x, coord y, int victim) { - int hit; - struct shpstr ship; - struct sctstr sect; - int sublaunch = 0; - struct plchrstr *pcp = plchr + pp->pln_type; - int hitchance = pln_hitchance(pp, hardtarget, type); - s_char *from; - int dam, dummyi; - - mpr(pp->pln_own,"Preparing to launch %s at %s %s %s%s\n", - prplane(pp), - cname(victim), - what, - (type==EF_SHIP||type==EF_PLANE)?"in ":"", - xyas(x, y, pp->pln_own)); - mpr(pp->pln_own, "\tLaunching from "); - if (pp->pln_ship >= 0) { - getship(pp->pln_ship, &ship); - mpr(pp->pln_own, "%s in ", prship(&ship)); - if (mchr[(int)ship.shp_type].m_flags & M_SUB) { - sublaunch = 1; - from = "in hatch"; - } else - from = "on deck"; - mpr(pp->pln_own, "%s\n", - xyas(ship.shp_x, ship.shp_y, pp->pln_own)); - } else { - if (pp->pln_harden > 0) { - mpr(pp->pln_own, "missile silo at "); - from = "in cilo"; - } else - from = "on launch pad"; - mpr(pp->pln_own, "%s\n", - xyas(pp->pln_x, pp->pln_y, pp->pln_own)); - } + int hit; + struct shpstr ship; + struct sctstr sect; + int sublaunch = 0; + struct plchrstr *pcp = plchr + pp->pln_type; + int hitchance = pln_hitchance(pp, hardtarget, type); + s_char *from; + int dam, dummyi; + + mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n", + prplane(pp), + cname(victim), + what, + (type == EF_SHIP || type == EF_PLANE) ? "in " : "", + xyas(x, y, pp->pln_own)); + mpr(pp->pln_own, "\tLaunching from "); + if (pp->pln_ship >= 0) { + getship(pp->pln_ship, &ship); + mpr(pp->pln_own, "%s in ", prship(&ship)); + if (mchr[(int)ship.shp_type].m_flags & M_SUB) { + sublaunch = 1; + from = "in hatch"; + } else + from = "on deck"; + mpr(pp->pln_own, "%s\n", + xyas(ship.shp_x, ship.shp_y, pp->pln_own)); + } else { + if (pp->pln_harden > 0) { + mpr(pp->pln_own, "missile silo at "); + from = "in cilo"; + } else + from = "on launch pad"; + mpr(pp->pln_own, "%s\n", xyas(pp->pln_x, pp->pln_y, pp->pln_own)); + } - if (chance((0.05 + (100 - pp->pln_effic)/100.0) - * (1 - techfact(pp->pln_tech, 1.0)))) { - mpr(pp->pln_own, "KABOOOOM! Missile explodes %s!\n", from); - if (chance(0.33)) { - if (pp->pln_nuketype != (s_char)-1 && - opt_NUKEFAILDETONATE) { - pp->pln_flags &= ~PLN_AIRBURST; - detonate(pp, pp->pln_x, pp->pln_y); - } else { - dam = pln_damage(pp, pp->pln_x, pp->pln_y, - 'p', &dummyi, 1) / 2; - if (dam) { - if (pp->pln_ship >= 0) { - shipdamage(&ship, dam); - putship(ship.shp_uid, &ship); - } else { - pr("Explosion damages %s %d%%", - xyas(pp->pln_x, pp->pln_y, pp->pln_own), - dam); - getsect(pp->pln_x, pp->pln_y, §); - sectdamage(§, dam, 0); - putsect(§); - } - } - } + if (chance((0.05 + (100 - pp->pln_effic) / 100.0) + * (1 - techfact(pp->pln_tech, 1.0)))) { + mpr(pp->pln_own, "KABOOOOM! Missile explodes %s!\n", from); + if (chance(0.33)) { + if (pp->pln_nuketype != (s_char)-1 && opt_NUKEFAILDETONATE) { + pp->pln_flags &= ~PLN_AIRBURST; + detonate(pp, pp->pln_x, pp->pln_y); + } else { + dam = pln_damage(pp, pp->pln_x, pp->pln_y, + 'p', &dummyi, 1) / 2; + if (dam) { + if (pp->pln_ship >= 0) { + shipdamage(&ship, dam); + putship(ship.shp_uid, &ship); + } else { + pr("Explosion damages %s %d%%", + xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam); + getsect(pp->pln_x, pp->pln_y, §); + sectdamage(§, dam, 0); + putsect(§); + } } - return 0; + } } - - mpr(pp->pln_own, "\tSHWOOOOOSH! Missile launched!\n"); + return 0; + } - if (pp->pln_nuketype != (s_char)-1) - mpr(pp->pln_own, "\tArming nuclear warheads...\n"); + mpr(pp->pln_own, "\tSHWOOOOOSH! Missile launched!\n"); - if (pcp->pl_flags & P_T) - mpr(victim, "Incoming %s missile...\n",sublaunch?(s_char *)"":cname(pp->pln_own)); + if (pp->pln_nuketype != (s_char)-1) + mpr(pp->pln_own, "\tArming nuclear warheads...\n"); - if (opt_PINPOINTMISSILE == 0 || - (pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) { - if (msl_intercept(x, y, pp->pln_own, pcp->pl_def, - sublaunch, P_N, P_O)) { - return 0; - } + if (pcp->pl_flags & P_T) + mpr(victim, "Incoming %s missile...\n", + sublaunch ? (s_char *)"" : cname(pp->pln_own)); + + if (opt_PINPOINTMISSILE == 0 || + (pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) { + if (msl_intercept(x, y, pp->pln_own, pcp->pl_def, + sublaunch, P_N, P_O)) { + return 0; } - if (pcp->pl_flags & P_MAR) { - if (shp_missile_defense(x, y, pp->pln_own, pcp->pl_def)) { - return 0; - } + } + if (pcp->pl_flags & P_MAR) { + if (shp_missile_defense(x, y, pp->pln_own, pcp->pl_def)) { + return 0; } + } - if (pp->pln_nuketype != (s_char)-1) - hitchance = 100; + if (pp->pln_nuketype != (s_char)-1) + hitchance = 100; - mpr(pp->pln_own,"\t%d%% hitchance...", hitchance); - hit = (roll(100) <= hitchance); + mpr(pp->pln_own, "\t%d%% hitchance...", hitchance); + hit = (roll(100) <= hitchance); - mpr(pp->pln_own,hit?"HIT!\n":"miss\n"); - if (pcp->pl_flags & P_T) - mpr(victim, "...Incoming %s missile %s\n",sublaunch?(s_char *)"":cname(pp->pln_own), hit?"HIT!\n":"missed\n"); - if (hit && news_item) { - if (sublaunch) - nreport(victim, snews_item, 0, 1); - else - nreport(pp->pln_own, news_item, victim, 1); - } - return hit; + mpr(pp->pln_own, hit ? "HIT!\n" : "miss\n"); + if (pcp->pl_flags & P_T) + mpr(victim, "...Incoming %s missile %s\n", + sublaunch ? (s_char *)"" : cname(pp->pln_own), + hit ? "HIT!\n" : "missed\n"); + if (hit && news_item) { + if (sublaunch) + nreport(victim, snews_item, 0, 1); + else + nreport(pp->pln_own, news_item, victim, 1); + } + return hit; } void -msl_sel(struct emp_qelem *list, coord x, coord y, natid victim, int wantflags, int nowantflags, int mission) +msl_sel(struct emp_qelem *list, coord x, coord y, natid victim, + int wantflags, int nowantflags, int mission) { - register struct plchrstr *pcp; - struct plnstr plane; - struct plist *irv; - struct nstr_item ni; + register struct plchrstr *pcp; + struct plnstr plane; + struct plist *irv; + struct nstr_item ni; - emp_initque (list); - snxtitem_all (&ni, EF_PLANE); - while (nxtitem (&ni, (s_char *)&plane)) { - if (!plane.pln_own) - continue; + emp_initque(list); + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (!plane.pln_own) + continue; - pcp = &plchr[(int)plane.pln_type]; - if (!(pcp->pl_flags & P_M)) - continue; - if (wantflags && (pcp->pl_flags & wantflags) != wantflags) - continue; - if (nowantflags && pcp->pl_flags & nowantflags) - continue; - if (mission && plane.pln_mission != mission) - continue; - if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL) - continue; - /* missiles go one way, so we can use all the range */ - if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y)) - continue; - if (plane.pln_mobil <= (s_char)0) - continue; - if (plane.pln_effic < 100) - continue; - /* got a valid interceptor */ - irv = (struct plist *) malloc(sizeof(*irv)); - irv->state = P_OK; - irv->bombs = 0; - irv->misc = 0; - irv->pcp = &plchr[(int)plane.pln_type]; - bcopy((s_char *)&plane, (s_char *)&irv->plane, sizeof(plane)); - emp_insque(&irv->queue, list); - } + pcp = &plchr[(int)plane.pln_type]; + if (!(pcp->pl_flags & P_M)) + continue; + if (wantflags && (pcp->pl_flags & wantflags) != wantflags) + continue; + if (nowantflags && pcp->pl_flags & nowantflags) + continue; + if (mission && plane.pln_mission != mission) + continue; + if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL) + continue; + /* missiles go one way, so we can use all the range */ + if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y)) + continue; + if (plane.pln_mobil <= (s_char)0) + continue; + if (plane.pln_effic < 100) + continue; + /* got a valid interceptor */ + irv = (struct plist *)malloc(sizeof(*irv)); + irv->state = P_OK; + irv->bombs = 0; + irv->misc = 0; + irv->pcp = &plchr[(int)plane.pln_type]; + bcopy((s_char *)&plane, (s_char *)&irv->plane, sizeof(plane)); + emp_insque(&irv->queue, list); + } } int -msl_intercept(coord x, coord y, natid bombown, int hardtarget, int sublaunch, int wantflags, int nowantflags) +msl_intercept(coord x, coord y, natid bombown, int hardtarget, + int sublaunch, int wantflags, int nowantflags) { - register struct plnstr *pp; - register struct plchrstr *pcp; - struct sctstr sect; - struct emp_qelem *irvlist; - struct emp_qelem foo; - struct emp_qelem *intlist; - struct emp_qelem intfoo; - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *ip; - int icount = 0; - short destroyed = 0; - s_char *att_name; - s_char *def_name; - int news_item; - s_char what[512]; - s_char *who = sublaunch?(s_char *)"":cname(bombown); + register struct plnstr *pp; + register struct plchrstr *pcp; + struct sctstr sect; + struct emp_qelem *irvlist; + struct emp_qelem foo; + struct emp_qelem *intlist; + struct emp_qelem intfoo; + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *ip; + int icount = 0; + short destroyed = 0; + s_char *att_name; + s_char *def_name; + int news_item; + s_char what[512]; + s_char *who = sublaunch ? (s_char *)"" : cname(bombown); - getsect(x, y, §); - if (wantflags == P_O && !nowantflags) { - att_name = "satellite"; - def_name = "a-sat missile"; - news_item = N_SAT_KILL; - if (sect.sct_own) { - mpr(sect.sct_own, "%s has positioned a satellite over %s\n", sublaunch?(s_char *)"someone":cname(bombown), xyas(x,y,sect.sct_own)); - } - } else if (wantflags == P_N && nowantflags == P_O) { - att_name = "warhead"; - def_name = "abm"; - news_item = sublaunch?N_NUKE_SSTOP:N_NUKE_STOP; - } else { - att_name = "elephant"; - def_name = "tomato"; /* heh -KHS */ - news_item = N_NUKE_STOP; + getsect(x, y, §); + if (wantflags == P_O && !nowantflags) { + att_name = "satellite"; + def_name = "a-sat missile"; + news_item = N_SAT_KILL; + if (sect.sct_own) { + mpr(sect.sct_own, "%s has positioned a satellite over %s\n", + sublaunch ? (s_char *)"someone" : cname(bombown), xyas(x, + y, + sect. + sct_own)); } - sprintf(what,"%s %s",who, att_name); - irvlist = &foo; + } else if (wantflags == P_N && nowantflags == P_O) { + att_name = "warhead"; + def_name = "abm"; + news_item = sublaunch ? N_NUKE_SSTOP : N_NUKE_STOP; + } else { + att_name = "elephant"; + def_name = "tomato"; /* heh -KHS */ + news_item = N_NUKE_STOP; + } + sprintf(what, "%s %s", who, att_name); + irvlist = &foo; - /* get all hostile abms in range */ - msl_sel(irvlist, x, y, bombown, wantflags, nowantflags, 0); - intlist = &intfoo; - emp_initque(intlist); - /* First choose interceptors belonging to the target sector */ - /* only allow two defense missiles per missile attack */ - for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) { - next = qp->q_forw; - ip = (struct plist *)qp; - pp = &ip->plane; - if (pp->pln_own != sect.sct_own) - continue; - pcp = ip->pcp; - if (mission_pln_equip(ip, 0, 0, 'i') < 0) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* got one interceptor, delete from irv_list and - * add to int_list. - */ - emp_remque(qp); - emp_insque(qp, intlist); - putplane(pp->pln_uid, pp); - icount++; - } - /* only allow two defense missiles per missile attack */ - for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) { - next = qp->q_forw; - ip = (struct plist *)qp; - pp = &ip->plane; - pcp = ip->pcp; - if (mission_pln_equip(ip, 0, 0, 'i') < 0) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - /* got one interceptor, delete from irv_list and - * add to int_list. - */ - emp_remque(qp); - emp_insque(qp, intlist); - putplane(pp->pln_uid, pp); - icount++; - } - /* Now, clean out the queue */ - while (!QEMPTY(irvlist)) { - qp = irvlist->q_forw; - emp_remque(qp); - free((s_char *)qp); + /* get all hostile abms in range */ + msl_sel(irvlist, x, y, bombown, wantflags, nowantflags, 0); + intlist = &intfoo; + emp_initque(intlist); + /* First choose interceptors belonging to the target sector */ + /* only allow two defense missiles per missile attack */ + for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) { + next = qp->q_forw; + ip = (struct plist *)qp; + pp = &ip->plane; + if (pp->pln_own != sect.sct_own) + continue; + pcp = ip->pcp; + if (mission_pln_equip(ip, 0, 0, 'i') < 0) { + emp_remque(qp); + free((s_char *)qp); + continue; + } + /* got one interceptor, delete from irv_list and + * add to int_list. + */ + emp_remque(qp); + emp_insque(qp, intlist); + putplane(pp->pln_uid, pp); + icount++; + } + /* only allow two defense missiles per missile attack */ + for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) { + next = qp->q_forw; + ip = (struct plist *)qp; + pp = &ip->plane; + pcp = ip->pcp; + if (mission_pln_equip(ip, 0, 0, 'i') < 0) { + emp_remque(qp); + free((s_char *)qp); + continue; } - if (icount == 0) { - if(sect.sct_own != 0) - mpr(sect.sct_own, "No %ss launched to intercept.\n", def_name); - return (destroyed); - } + /* got one interceptor, delete from irv_list and + * add to int_list. + */ + emp_remque(qp); + emp_insque(qp, intlist); + putplane(pp->pln_uid, pp); + icount++; + } + /* Now, clean out the queue */ + while (!QEMPTY(irvlist)) { + qp = irvlist->q_forw; + emp_remque(qp); + free((s_char *)qp); + } + if (icount == 0) { + if (sect.sct_own != 0) + mpr(sect.sct_own, "No %ss launched to intercept.\n", def_name); + return (destroyed); + } - /* attempt to destroy incoming missile */ + /* attempt to destroy incoming missile */ - while (!QEMPTY(intlist)) { - qp = intlist->q_forw; - ip = (struct plist *)qp; - pp = &ip->plane; - pcp = ip->pcp; + while (!QEMPTY(intlist)) { + qp = intlist->q_forw; + ip = (struct plist *)qp; + pp = &ip->plane; + pcp = ip->pcp; - mpr(bombown,"%s %s launched in defense!\n", - cname(pp->pln_own), def_name); - if (sect.sct_own == pp->pln_own) { - mpr(sect.sct_own, "%s launched to intercept %s %s!\n", + mpr(bombown, "%s %s launched in defense!\n", + cname(pp->pln_own), def_name); + if (sect.sct_own == pp->pln_own) { + mpr(sect.sct_own, "%s launched to intercept %s %s!\n", def_name, who, att_name); - } else { + } else { if (sect.sct_own) - mpr(sect.sct_own, "%s launched an %s to intercept the %s %s!\n", - cname(pp->pln_own), def_name, who, att_name); - mpr(pp->pln_own, - "%s launched to intercept %s %s arcing towards %s territory!\n", + mpr(sect.sct_own, + "%s launched an %s to intercept the %s %s!\n", + cname(pp->pln_own), def_name, who, att_name); + mpr(pp->pln_own, + "%s launched to intercept %s %s arcing towards %s territory!\n", def_name, who, att_name, cname(sect.sct_own)); - } - - if (!destroyed && - msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item, what, x, y, bombown)) { + } + + if (!destroyed && + msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item, what, + x, y, bombown)) { mpr(bombown, "%s destroyed by %s %s!\n", att_name, cname(pp->pln_own), def_name); if (sect.sct_own) - mpr(sect.sct_own, "%s %s intercepted!\n", who, att_name); + mpr(sect.sct_own, "%s %s intercepted!\n", who, att_name); if (sect.sct_own != pp->pln_own) - mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name); + mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name); destroyed = 1; - } - /* zap the missile */ - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - putplane(pp->pln_uid, pp); - emp_remque(qp); - free((s_char *)qp); - if (destroyed) - break; - } - /* Clean out what is left in the list */ - while (!QEMPTY(intlist)) { - qp = intlist->q_forw; - emp_remque(qp); - free((s_char *)qp); - } - if (destroyed) - return (destroyed); - if (icount) { - mpr(bombown,"%s made it through %s defenses!\n", att_name, def_name); - if (sect.sct_own) - mpr(sect.sct_own, "%s made it through %s defenses!\n", att_name, - def_name); } - return (destroyed); + /* zap the missile */ + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + pp->pln_own = 0; + putplane(pp->pln_uid, pp); + emp_remque(qp); + free((s_char *)qp); + if (destroyed) + break; + } + /* Clean out what is left in the list */ + while (!QEMPTY(intlist)) { + qp = intlist->q_forw; + emp_remque(qp); + free((s_char *)qp); + } + if (destroyed) + return (destroyed); + if (icount) { + mpr(bombown, "%s made it through %s defenses!\n", att_name, + def_name); + if (sect.sct_own) + mpr(sect.sct_own, "%s made it through %s defenses!\n", + att_name, def_name); + } + return (destroyed); } /* Keep launching missiles on list until mindam damage has been done */ int -msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget, int type, int mindam, s_char *whatp, int victim, int mission) +msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget, + int type, int mindam, s_char *whatp, int victim, + int mission) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *plp; - int newdam, dam = 0; - int nukedam = 0; - int news_item; - int snews_item; + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *plp; + int newdam, dam = 0; + int nukedam = 0; + int news_item; + int snews_item; - if (type == EF_SHIP) { - news_item = N_SHP_MISS; - snews_item = N_SHP_SMISS; - } else if (type == EF_LAND) { - news_item = N_LND_MISS; - snews_item = N_LND_SMISS; - } else { - news_item = N_SCT_MISS; - snews_item = N_SCT_SMISS; - } - - for (qp = list->q_back;qp != list && dam < mindam && !nukedam;qp = next) { - next = qp->q_back; - plp = (struct plist *)qp; + if (type == EF_SHIP) { + news_item = N_SHP_MISS; + snews_item = N_SHP_SMISS; + } else if (type == EF_LAND) { + news_item = N_LND_MISS; + snews_item = N_LND_SMISS; + } else { + news_item = N_SCT_MISS; + snews_item = N_SCT_SMISS; + } - if (mission_pln_equip(plp, 0, 0, 'p') >= 0) { - if (msl_hit(&plp->plane, - hardtarget, type, news_item, snews_item, - whatp, x, y, victim)) { - newdam = pln_damage(&plp->plane,x,y,'p',&nukedam, 1); - if (nukedam) { - if (mission == MI_INTERDICT && - type == EF_SECTOR) - dam += nukedam; - } else - dam += newdam; - } else { - /* Missiles that miss have to hit somewhere! */ - newdam = pln_damage(&plp->plane,x,y,'p',&nukedam, 0); - collateral_damage(x, y, newdam, 0); - } - makelost(EF_PLANE, plp->plane.pln_own, plp->plane.pln_uid, plp->plane.pln_x, plp->plane.pln_y); - plp->plane.pln_own = 0; - putplane(plp->plane.pln_uid, &plp->plane); - emp_remque(qp); - free(qp); - } + for (qp = list->q_back; qp != list && dam < mindam && !nukedam; + qp = next) { + next = qp->q_back; + plp = (struct plist *)qp; + + if (mission_pln_equip(plp, 0, 0, 'p') >= 0) { + if (msl_hit(&plp->plane, + hardtarget, type, news_item, snews_item, + whatp, x, y, victim)) { + newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1); + if (nukedam) { + if (mission == MI_INTERDICT && type == EF_SECTOR) + dam += nukedam; + } else + dam += newdam; + } else { + /* Missiles that miss have to hit somewhere! */ + newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0); + collateral_damage(x, y, newdam, 0); + } + makelost(EF_PLANE, plp->plane.pln_own, plp->plane.pln_uid, + plp->plane.pln_x, plp->plane.pln_y); + plp->plane.pln_own = 0; + putplane(plp->plane.pln_uid, &plp->plane); + emp_remque(qp); + free(qp); } - return dam; + } + return dam; } - diff --git a/src/lib/subs/mtch.c b/src/lib/subs/mtch.c index d45e229a0..dfbd6848d 100644 --- a/src/lib/subs/mtch.c +++ b/src/lib/subs/mtch.c @@ -49,13 +49,13 @@ int intmatch(register int value, register int *ptr, int size) { - register int i; + register int i; - size /= sizeof(*ptr); - for (i=0; *ptr; i++, ptr += size) - if (value == *ptr) - return i; - return -1; + size /= sizeof(*ptr); + for (i = 0; *ptr; i++, ptr += size) + if (value == *ptr) + return i; + return -1; } /* @@ -63,28 +63,28 @@ intmatch(register int value, register int *ptr, int size) * >= 0: match found, value is array entry in coms[] */ int -comtch(register s_char *command, struct cmndstr *coms, int comstat, int god) +comtch(register s_char *command, struct cmndstr *coms, int comstat, + int god) { - register struct cmndstr *com; - register int status; - register int i; + register struct cmndstr *com; + register int status; + register int i; - if (command == 0 || *command == 0) - return M_IGNORE; - status = M_NOTFOUND; - for (com=coms; com->c_form != 0; com++) { - if ((com->c_permit & comstat) != com->c_permit && !god) - continue; - if ((i = mineq(command, com->c_form)) == ME_MISMATCH) - continue; - if (i == ME_EXACT) - return com - coms; - /* partial */ - if (status != M_NOTFOUND) - return M_NOTUNIQUE; - status = com - coms; - } + if (command == 0 || *command == 0) + return M_IGNORE; + status = M_NOTFOUND; + for (com = coms; com->c_form != 0; com++) { + if ((com->c_permit & comstat) != com->c_permit && !god) + continue; + if ((i = mineq(command, com->c_form)) == ME_MISMATCH) + continue; + if (i == ME_EXACT) + return com - coms; + /* partial */ + if (status != M_NOTFOUND) + return M_NOTUNIQUE; + status = com - coms; + } - return status; + return status; } - diff --git a/src/lib/subs/natarg.c b/src/lib/subs/natarg.c index 13e27034e..c2c7fbbd9 100644 --- a/src/lib/subs/natarg.c +++ b/src/lib/subs/natarg.c @@ -42,40 +42,40 @@ int natarg(s_char *arg, s_char *prompt) { - s_char buf[1024]; - int n; - struct natstr *np; - int byname = 0; + s_char buf[1024]; + int n; + struct natstr *np; + int byname = 0; - arg = getstarg(arg, prompt, buf); - if (arg == 0 || *arg == 0) + arg = getstarg(arg, prompt, buf); + if (arg == 0 || *arg == 0) + return -1; + if (isdigit(*arg)) + n = atoi(arg); + else { + n = cnumb(arg); + if (opt_HIDDEN) { + byname = 1; + } + } + if (n < 0 || n >= MAXNOC) { + pr("No such country exists.\n"); + n = -1; + } + if (opt_HIDDEN) { + if (!player->god && !getcontact(getnatp(player->cnum), n)) { + if ((np = getnatp(n)) == 0) return -1; - if (isdigit(*arg)) - n = atoi(arg); - else { - n = cnumb(arg); - if (opt_HIDDEN) { - byname = 1; + if ((np->nat_stat & STAT_GOD) == 0) { + if (byname) { + pr("No such country exists.\n"); + n = -1; + } else { + pr("Country has not been contacted.\n"); + n = -2; } - } - if (n < 0 || n >= MAXNOC) { - pr("No such country exists.\n"); - n = -1; - } - if (opt_HIDDEN) { - if (!player->god && !getcontact(getnatp(player->cnum), n)) { - if ((np = getnatp(n)) == 0) - return -1; - if ((np->nat_stat & STAT_GOD) == 0) { - if (byname) { - pr("No such country exists.\n"); - n = -1; - } else { - pr("Country has not been contacted.\n"); - n = -2; - } - } } } - return n; + } + return n; } diff --git a/src/lib/subs/neigh.c b/src/lib/subs/neigh.c index 426b7878d..0a5af3534 100644 --- a/src/lib/subs/neigh.c +++ b/src/lib/subs/neigh.c @@ -41,13 +41,13 @@ int neigh(coord x, coord y, natid own) { - register int i; - struct sctstr sect; + register int i; + struct sctstr sect; - for (i = DIR_FIRST; i <= DIR_LAST; i++) { - getsect(x + diroff[i][0], y + diroff[i][1], §); - if (sect.sct_own == own) - return 1; - } - return 0; + for (i = DIR_FIRST; i <= DIR_LAST; i++) { + getsect(x + diroff[i][0], y + diroff[i][1], §); + if (sect.sct_own == own) + return 1; + } + return 0; } diff --git a/src/lib/subs/nreport.c b/src/lib/subs/nreport.c index 356be274a..061024855 100644 --- a/src/lib/subs/nreport.c +++ b/src/lib/subs/nreport.c @@ -44,56 +44,56 @@ void nreport(natid actor, int event, natid victim, int times) { - int nice; - int rel; - struct natstr *np; - - filereport(actor, event, victim, times); - /* - * this is probably pretty expensive, but hopefully we - * don't fire zillions of these things off every second. - */ - if (victim == 0 || (nice = rpt[event].r_good_will) >= 0) - return; - /* - * Pretty schlocky to put it here, but - * I guess it can't go anywhere else. - */ - if (actor == victim) - return; - if (!chance((double)-nice * times/20.0)) - return; - if ((np = getnatp(victim)) == 0) - return; - if ((rel = getrel(np, actor)) < HOSTILE) - return; - - rel = HOSTILE; + int nice; + int rel; + struct natstr *np; + + filereport(actor, event, victim, times); + /* + * this is probably pretty expensive, but hopefully we + * don't fire zillions of these things off every second. + */ + if (victim == 0 || (nice = rpt[event].r_good_will) >= 0) + return; + /* + * Pretty schlocky to put it here, but + * I guess it can't go anywhere else. + */ + if (actor == victim) + return; + if (!chance((double)-nice * times / 20.0)) + return; + if ((np = getnatp(victim)) == 0) + return; + if ((rel = getrel(np, actor)) < HOSTILE) + return; + + rel = HOSTILE; /* if (rel > HOSTILE) rel = HOSTILE; else rel = AT_WAR; */ - setrel(victim, actor, rel); + setrel(victim, actor, rel); } struct free { - struct free *next; - int id; + struct free *next; + int id; }; -struct free *freelist; +struct free *freelist; static void addfree(int n) { - struct free *fp; + struct free *fp; - fp = (struct free *) malloc(sizeof(*fp)); - fp->next = freelist; - fp->id = n; - freelist = fp; + fp = (struct free *)malloc(sizeof(*fp)); + fp->next = freelist; + fp->id = n; + freelist = fp; } /* @@ -104,97 +104,97 @@ addfree(int n) static void findfree(void) { - register time_t oldnewstime; - register int n; - struct nwsstr news; - time_t newstime; - - (void) time(&newstime); - oldnewstime = newstime - NEWS_PERIOD; - for (n=0; getnews(n, &news); n++) { - if (news.nws_when < oldnewstime) - addfree(n); - } - if (freelist == 0) { - if (!ef_extend(EF_NEWS, 100)) - return; - findfree(); - } + register time_t oldnewstime; + register int n; + struct nwsstr news; + time_t newstime; + + (void)time(&newstime); + oldnewstime = newstime - NEWS_PERIOD; + for (n = 0; getnews(n, &news); n++) { + if (news.nws_when < oldnewstime) + addfree(n); + } + if (freelist == 0) { + if (!ef_extend(EF_NEWS, 100)) + return; + findfree(); + } } static -int + int nextfree(void) { - struct free *fp; - int id; - - if (freelist == 0) - findfree(); - if ((fp = freelist) == 0) - return 0; - freelist = fp->next; - id = fp->id; - free(fp); - return id; + struct free *fp; + int id; + + if (freelist == 0) + findfree(); + if ((fp = freelist) == 0) + return 0; + freelist = fp->next; + id = fp->id; + free(fp); + return id; } #define SLOTS 5 struct newscache { - struct nwsstr news; - int id; + struct nwsstr news; + int id; }; static struct newscache * ncache(time_t now, int actor, int event, int victim, int times) { - static struct newscache cache[MAXNOC][SLOTS]; - register struct newscache *np; - int i; - int oldslot; - time_t oldtime; - - oldslot = -1; - oldtime = 0x7fffffff; - for (i=0; inews.nws_when < oldtime) { - oldslot = i; - oldtime = np->news.nws_when; - } - if (np->id == 0) - continue; - if ((now - np->news.nws_when) > minutes(5)) - continue; - if (np->news.nws_vrb == event && np->news.nws_vno == victim && - np->news.nws_ntm + times <= 127) { - np->news.nws_ntm += times; - return np; - } + static struct newscache cache[MAXNOC][SLOTS]; + register struct newscache *np; + int i; + int oldslot; + time_t oldtime; + + oldslot = -1; + oldtime = 0x7fffffff; + for (i = 0; i < SLOTS; i++) { + np = &cache[actor][i]; + if (np->news.nws_when < oldtime) { + oldslot = i; + oldtime = np->news.nws_when; } - if (oldslot < 0) { - logerror("internal error; ncache oldslot < 0"); - return &cache[actor][0]; + if (np->id == 0) + continue; + if ((now - np->news.nws_when) > minutes(5)) + continue; + if (np->news.nws_vrb == event && np->news.nws_vno == victim && + np->news.nws_ntm + times <= 127) { + np->news.nws_ntm += times; + return np; } - np = &cache[actor][oldslot]; - np->news.nws_ano = actor; - np->news.nws_vno = victim; - np->news.nws_when = now; - np->news.nws_vrb = event; - np->news.nws_ntm = times; - np->id = nextfree(); - return np; + } + if (oldslot < 0) { + logerror("internal error; ncache oldslot < 0"); + return &cache[actor][0]; + } + np = &cache[actor][oldslot]; + np->news.nws_ano = actor; + np->news.nws_vno = victim; + np->news.nws_when = now; + np->news.nws_vrb = event; + np->news.nws_ntm = times; + np->id = nextfree(); + return np; } void filereport(int actor, int event, int victim, int times) { - struct newscache *np; - time_t now; + struct newscache *np; + time_t now; - time(&now); - np = ncache(now, actor, event, victim, times); - ef_write(EF_NEWS, np->id, (s_char *)&np->news); + time(&now); + np = ncache(now, actor, event, victim, times); + ef_write(EF_NEWS, np->id, (s_char *)&np->news); } diff --git a/src/lib/subs/nstr.c b/src/lib/subs/nstr.c index 57a8b2a92..75eeb1a07 100644 --- a/src/lib/subs/nstr.c +++ b/src/lib/subs/nstr.c @@ -57,116 +57,116 @@ static int legal_val(s_char *str, int val); s_char * nstr_comp(struct nscstr *np, int *size, int type, s_char *str) { - register s_char *bp; - register s_char *cp; - register int c; - s_char ident[80]; - s_char arg[255]; - int op; - int val; + register s_char *bp; + register s_char *cp; + register int c; + s_char ident[80]; + s_char arg[255]; + int op; + int val; - strncpy(arg, str, sizeof(arg)-1); - arg[sizeof(arg)-1] = 0; - cp = arg; - bp = ident; - while ((c = *cp++) && bp < &ident[sizeof(ident)-1]) { - if (c == '<' || c == '=' || c == '>' || c == '#') - break; - *bp++ = c; - } - *bp = 0; - if (c == 0) { - pr("'%s'? -- meaningless condition?\n", arg); - return 0; - } - op = c; - np[*size].oper = op; - if ((val = encode(ident, &np[*size].fld1, type)) < 0) - return 0; - if (val == 2) - np[*size].oper += 255; - bp = ident; - while ((c = *cp++) && bp < &ident[sizeof(ident)-1]) { - if (c == '&') - break; - *bp++ = c; - } - *bp = 0; - if ((val = encode(ident, &np[*size].fld2, type)) < 0) - return 0; - if (val == 2) - np[*size].oper += 65535; - if (c == 0) - cp--; - (*size)++; - return str + (cp - arg); + strncpy(arg, str, sizeof(arg) - 1); + arg[sizeof(arg) - 1] = 0; + cp = arg; + bp = ident; + while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) { + if (c == '<' || c == '=' || c == '>' || c == '#') + break; + *bp++ = c; + } + *bp = 0; + if (c == 0) { + pr("'%s'? -- meaningless condition?\n", arg); + return 0; + } + op = c; + np[*size].oper = op; + if ((val = encode(ident, &np[*size].fld1, type)) < 0) + return 0; + if (val == 2) + np[*size].oper += 255; + bp = ident; + while ((c = *cp++) && bp < &ident[sizeof(ident) - 1]) { + if (c == '&') + break; + *bp++ = c; + } + *bp = 0; + if ((val = encode(ident, &np[*size].fld2, type)) < 0) + return 0; + if (val == 2) + np[*size].oper += 65535; + if (c == 0) + cp--; + (*size)++; + return str + (cp - arg); } int encode(register s_char *str, long int *val, int type) { - register int i; - struct castr *cap; + register int i; + struct castr *cap; - if (str == 0) { - *val = 0; - return 0; - } - if (isdigit(*str) || ((*str == '-') && isdigit(str[1]))) { + if (str == 0) { + *val = 0; + return 0; + } + if (isdigit(*str) || ((*str == '-') && isdigit(str[1]))) { #ifdef BIT16ONLY - /* XXX silently truncate to 16 bit int */ - *val = atoi(str) & 0xffff; + /* XXX silently truncate to 16 bit int */ + *val = atoi(str) & 0xffff; #else - *val = atoi(str); + *val = atoi(str); #endif /* BIT16ONLY */ - return 2; + return 2; + } + if ((i = typematch(str, type)) >= 0) { + *val = i; + return 1; + } + if ((cap = ef_cadef(type)) != 0) { + i = stmtch(str, (caddr_t)cap, fldoff(castr, ca_name), + sizeof(struct castr)); + if (i >= 0) { + *val = cap[i].ca_code | NSC_OFF; + *val &= ~NSC_ROUND; + return legal_val(str, *val); } - if ((i = typematch(str, type)) >= 0) { - *val = i; - return 1; + if (i == M_NOTUNIQUE) { + pr("%s -- ambiguous type selector\n", str); + return 0; } - if ((cap = ef_cadef(type)) != 0) { - i = stmtch(str, (caddr_t)cap, fldoff(castr, ca_name), - sizeof(struct castr)); - if (i >= 0) { - *val = cap[i].ca_code|NSC_OFF; - *val &= ~NSC_ROUND; - return legal_val(str, *val); - } - if (i == M_NOTUNIQUE) { - pr("%s -- ambiguous type selector\n", str); - return 0; - } + } + /* + * Only check for commodity selectors on objects which + * are allowed to have commodities. + */ + if (ef_flags(type) & EFF_COM) { + i = stmtch(str, (caddr_t)var_ca, fldoff(castr, ca_name), + sizeof(struct castr)); + if (i >= 0) { + *val = var_ca[i].ca_code & ~NSC_ROUND; + return legal_val(str, *val); + return 1; } - /* - * Only check for commodity selectors on objects which - * are allowed to have commodities. - */ - if (ef_flags(type) & EFF_COM) { - i = stmtch(str, (caddr_t)var_ca, fldoff(castr, ca_name), - sizeof(struct castr)); - if (i >= 0) { - *val = var_ca[i].ca_code & ~NSC_ROUND; - return legal_val(str, *val); - return 1; - } - if (i == M_NOTUNIQUE) { - pr("%s -- ambiguous commodity selector\n", str); - return 0; - } + if (i == M_NOTUNIQUE) { + pr("%s -- ambiguous commodity selector\n", str); + return 0; } - pr("%s -- not a valid selector\n", str); - return 0; + } + pr("%s -- not a valid selector\n", str); + return 0; } static int legal_val(s_char *str, int val) { - if (val & NSC_DEITY && !player->god) { - pr("%s -- permission denied\n", str); - return -1; - } - return 1; + if (val & NSC_DEITY && !player->god) { + pr("%s -- permission denied\n", str); + return -1; + } + return 1; } diff --git a/src/lib/subs/nuke.c b/src/lib/subs/nuke.c index 31ff09a92..827af3e78 100644 --- a/src/lib/subs/nuke.c +++ b/src/lib/subs/nuke.c @@ -48,103 +48,105 @@ int nuk_postread(int n, s_char *ptr) { - struct nukstr *np = (struct nukstr *) ptr; - - if (np->nuk_uid != n) { - logerror("nuk_postread: Error - %d != %d, zeroing.\n", np->nuk_uid, n); - bzero(ptr, sizeof(struct nukstr)); - } - player->owner = (player->god || np->nuk_own == player->cnum); - return 1; + struct nukstr *np = (struct nukstr *)ptr; + + if (np->nuk_uid != n) { + logerror("nuk_postread: Error - %d != %d, zeroing.\n", np->nuk_uid, + n); + bzero(ptr, sizeof(struct nukstr)); + } + player->owner = (player->god || np->nuk_own == player->cnum); + return 1; } /*ARGSUSED*/ int nuk_prewrite(int n, s_char *ptr) { - struct nukstr *np = (struct nukstr *) ptr; - struct nukstr nuke; + struct nukstr *np = (struct nukstr *)ptr; + struct nukstr nuke; - np->ef_type = EF_NUKE; - np->nuk_uid = n; + np->ef_type = EF_NUKE; + np->nuk_uid = n; - time(&np->nuk_timestamp); + time(&np->nuk_timestamp); - getnuke(n, &nuke); + getnuke(n, &nuke); - return 1; + return 1; } void nuk_init(int n, s_char *ptr) { - struct nukstr *np = (struct nukstr *) ptr; + struct nukstr *np = (struct nukstr *)ptr; - np->ef_type = EF_NUKE; - np->nuk_uid = n; - np->nuk_own = 0; + np->ef_type = EF_NUKE; + np->nuk_uid = n; + np->nuk_own = 0; } void nuk_add(coord x, coord y, int type, int num) { - struct nukstr nuke; - struct sctstr sect; - int nuk_uid; - natid own; - int n; - - /* getsect in case of world wraparound */ - getsect(x, y, §); - if (!(own = sect.sct_own)) - return; - x = sect.sct_x; - y = sect.sct_y; - - /* - * either find a stockpile in x,y or add a new one - */ - nuk_uid = -1; - for (n = 0; getnuke(n, &nuke); n++) { - if (nuke.nuk_own == own) { - if (nuke.nuk_x == x && nuke.nuk_y == y) { - nuk_uid = n; - break; - } - } else if (nuke.nuk_own == 0 && nuk_uid == -1) + struct nukstr nuke; + struct sctstr sect; + int nuk_uid; + natid own; + int n; + + /* getsect in case of world wraparound */ + getsect(x, y, §); + if (!(own = sect.sct_own)) + return; + x = sect.sct_x; + y = sect.sct_y; + + /* + * either find a stockpile in x,y or add a new one + */ + nuk_uid = -1; + for (n = 0; getnuke(n, &nuke); n++) { + if (nuke.nuk_own == own) { + if (nuke.nuk_x == x && nuke.nuk_y == y) { nuk_uid = n; - } - if (nuk_uid == -1) + break; + } + } else if (nuke.nuk_own == 0 && nuk_uid == -1) nuk_uid = n; - if (getnuke(nuk_uid, &nuke) == 0) { - ef_extend(EF_NUKE, 10); - bzero((s_char *)&nuke, sizeof(struct nukstr)); - nuke.nuk_uid = nuk_uid; - nuke.nuk_ship = -1; - nuke.nuk_n = 0; - makenotlost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x, nuke.nuk_y); - } - nuke.nuk_x = x; - nuke.nuk_y = y; - nuke.nuk_own = own; - nuke.nuk_types[type] += num; - nuke.nuk_n += num; - - if (!putnuke(nuke.nuk_uid, &nuke)) - pr("Problem with the nuclear stockpiles, tell the deity.\n"); + } + if (nuk_uid == -1) + nuk_uid = n; + if (getnuke(nuk_uid, &nuke) == 0) { + ef_extend(EF_NUKE, 10); + bzero((s_char *)&nuke, sizeof(struct nukstr)); + nuke.nuk_uid = nuk_uid; + nuke.nuk_ship = -1; + nuke.nuk_n = 0; + makenotlost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x, + nuke.nuk_y); + } + nuke.nuk_x = x; + nuke.nuk_y = y; + nuke.nuk_own = own; + nuke.nuk_types[type] += num; + nuke.nuk_n += num; + + if (!putnuke(nuke.nuk_uid, &nuke)) + pr("Problem with the nuclear stockpiles, tell the deity.\n"); } void nuk_delete(struct nukstr *np, int type, int num) { - if (np->nuk_types[type] < num) - num = np->nuk_types[type]; - np->nuk_types[type] -= num; - np->nuk_n -= num; - if (np->nuk_n <= 0) { - makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y); - np->nuk_own = 0; - } - putnuke(np->nuk_uid, np); + if (np->nuk_types[type] < num) + num = np->nuk_types[type]; + np->nuk_types[type] -= num; + np->nuk_n -= num; + if (np->nuk_n <= 0) { + makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y); + np->nuk_own = 0; + } + putnuke(np->nuk_uid, np); } diff --git a/src/lib/subs/nxtitem.c b/src/lib/subs/nxtitem.c index d3cb14264..a498000fe 100644 --- a/src/lib/subs/nxtitem.c +++ b/src/lib/subs/nxtitem.c @@ -48,71 +48,71 @@ int nxtitem(struct nstr_item *np, caddr_t ptr) { - struct genitem *gp; - int selected; + struct genitem *gp; + int selected; - if (np->sel == NS_UNDEF) + if (np->sel == NS_UNDEF) + return 0; + gp = (struct genitem *)ptr; + do { + if (np->sel == NS_LIST) { + np->index++; + if (np->index >= np->size) return 0; - gp = (struct genitem *) ptr; - do { - if (np->sel == NS_LIST) { - np->index++; - if (np->index >= np->size) - return 0; - np->cur = np->list[np->index]; - } else { - np->cur++; - } - if (!np->read(np->type, np->cur, ptr)) { - /* if read fails, fatal */ - return 0; - } - selected = 1; - switch (np->sel) { - /* - * This one won't work unless you're running in emp_player - * - */ - case NS_LIST: - if ((np->flags & EFF_OWNER) && !player->owner) - selected = 0; - break; - case NS_ALL: - /* XXX maybe combine NS_LIST and NS_ALL later */ - break; - case NS_DIST: - if (!xyinrange(gp->x, gp->y, &np->range)) { - selected = 0; - break; - } - np->curdist = mapdist((int)gp->x, (int)gp->y, - (int)np->cx, (int)np->cy); - if (np->curdist > np->dist) - selected = 0; - break; - case NS_AREA: - if (!xyinrange(gp->x, gp->y, &np->range)) - selected = 0; - if (gp->x == np->range.hx || gp->y == np->range.hy) - selected = 0; - break; - case NS_XY: - if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy) - selected = 0; - break; - case NS_GROUP: - if (np->group != gp->group) - selected = 0; - break; - default: - logerror("nxtitem: bad selector %d\n", np->sel); - return 0; - } - if (selected && np->ncond) { - /* nstr_exec is expensive, so we do it last */ - if (!nstr_exec(np->cond, np->ncond, ptr, np->type)) - selected = 0; - } - } while (!selected); - return 1; + np->cur = np->list[np->index]; + } else { + np->cur++; + } + if (!np->read(np->type, np->cur, ptr)) { + /* if read fails, fatal */ + return 0; + } + selected = 1; + switch (np->sel) { + /* + * This one won't work unless you're running in emp_player + * + */ + case NS_LIST: + if ((np->flags & EFF_OWNER) && !player->owner) + selected = 0; + break; + case NS_ALL: + /* XXX maybe combine NS_LIST and NS_ALL later */ + break; + case NS_DIST: + if (!xyinrange(gp->x, gp->y, &np->range)) { + selected = 0; + break; + } + np->curdist = mapdist((int)gp->x, (int)gp->y, + (int)np->cx, (int)np->cy); + if (np->curdist > np->dist) + selected = 0; + break; + case NS_AREA: + if (!xyinrange(gp->x, gp->y, &np->range)) + selected = 0; + if (gp->x == np->range.hx || gp->y == np->range.hy) + selected = 0; + break; + case NS_XY: + if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy) + selected = 0; + break; + case NS_GROUP: + if (np->group != gp->group) + selected = 0; + break; + default: + logerror("nxtitem: bad selector %d\n", np->sel); + return 0; + } + if (selected && np->ncond) { + /* nstr_exec is expensive, so we do it last */ + if (!nstr_exec(np->cond, np->ncond, ptr, np->type)) + selected = 0; + } + } while (!selected); + return 1; } diff --git a/src/lib/subs/nxtsct.c b/src/lib/subs/nxtsct.c index 12265ff08..0de037169 100644 --- a/src/lib/subs/nxtsct.c +++ b/src/lib/subs/nxtsct.c @@ -47,35 +47,35 @@ int nxtsct(register struct nstr_sect *np, struct sctstr *sp) { - while (1) { - np->dx++; - np->x++; - if (np->x >= WORLD_X) - np->x = 0; - if (np->dx >= np->range.width) { - np->dx = 0; - np->x = np->range.lx; - np->dy++; - if (np->dy >= np->range.height) - return 0; - np->y++; - if (np->y >= WORLD_Y) - np->y = 0; - } - if ((np->y + np->x) & 01) - continue; - if (np->type == NS_DIST) { - np->curdist = mapdist(np->x, np->y, np->cx, np->cy); - if (np->curdist > np->dist) - continue; - } - np->id = sctoff(np->x, np->y); - if (!np->read(EF_SECTOR, np->id, (caddr_t) sp)) - continue; - if (np->ncond == 0) - return 1; - if (nstr_exec(np->cond, np->ncond, (caddr_t)sp, EF_SECTOR)) - return 1; + while (1) { + np->dx++; + np->x++; + if (np->x >= WORLD_X) + np->x = 0; + if (np->dx >= np->range.width) { + np->dx = 0; + np->x = np->range.lx; + np->dy++; + if (np->dy >= np->range.height) + return 0; + np->y++; + if (np->y >= WORLD_Y) + np->y = 0; } - /*NOTREACHED*/ + if ((np->y + np->x) & 01) + continue; + if (np->type == NS_DIST) { + np->curdist = mapdist(np->x, np->y, np->cx, np->cy); + if (np->curdist > np->dist) + continue; + } + np->id = sctoff(np->x, np->y); + if (!np->read(EF_SECTOR, np->id, (caddr_t)sp)) + continue; + if (np->ncond == 0) + return 1; + if (nstr_exec(np->cond, np->ncond, (caddr_t)sp, EF_SECTOR)) + return 1; + } + /*NOTREACHED*/ } diff --git a/src/lib/subs/paths.c b/src/lib/subs/paths.c index 59bd0f96a..095feeb7b 100644 --- a/src/lib/subs/paths.c +++ b/src/lib/subs/paths.c @@ -41,56 +41,57 @@ #include "prototypes.h" int -getdir(s_char *prompt, s_char *stop_msg, s_char *view_msg, s_char *bomb_msg) +getdir(s_char *prompt, s_char *stop_msg, s_char *view_msg, + s_char *bomb_msg) { - register int max_dir; - register int min_dir; - register int dir_num; - s_char buf[1024]; + register int max_dir; + register int min_dir; + register int dir_num; + s_char buf[1024]; - if (stop_msg != 0) - min_dir = DIR_STOP; - else - min_dir = DIR_FIRST; - if (view_msg == 0) - max_dir = DIR_LAST; - else - max_dir = DIR_VIEW; - while (1) { - if (getstring(prompt, buf) == 0 || *buf == 0) - return -1; - dir_num = chkdir(buf[0], min_dir, max_dir); - if (dir_num >= min_dir) - break; - direrr(stop_msg, view_msg, bomb_msg); - } - return dir_num; + if (stop_msg != 0) + min_dir = DIR_STOP; + else + min_dir = DIR_FIRST; + if (view_msg == 0) + max_dir = DIR_LAST; + else + max_dir = DIR_VIEW; + while (1) { + if (getstring(prompt, buf) == 0 || *buf == 0) + return -1; + dir_num = chkdir(buf[0], min_dir, max_dir); + if (dir_num >= min_dir) + break; + direrr(stop_msg, view_msg, bomb_msg); + } + return dir_num; } int chkdir(s_char dir_char, int min_dir, int max_dir) { - register int i; + register int i; - for (i = min_dir; i <= max_dir; i++) - if (dir_char == dirch[i]) - return i; - return -1; + for (i = min_dir; i <= max_dir; i++) + if (dir_char == dirch[i]) + return i; + return -1; } void direrr(s_char *stop_msg, s_char *view_msg, s_char *map_msg) { - pr("Legal directions are:\n"); - pr(" %c %c\n", dirch[DIR_UL], dirch[DIR_UR]); - pr("%c %c\n", dirch[DIR_L], dirch[DIR_R]); - pr(" %c %c\n", dirch[DIR_DL], dirch[DIR_DR]); - if (stop_msg != 0) - pr(stop_msg, dirch[DIR_STOP]); - if (view_msg != 0) - pr(view_msg, dirch[DIR_VIEW]); - if (map_msg != 0) - pr(map_msg, dirch[DIR_MAP]); + pr("Legal directions are:\n"); + pr(" %c %c\n", dirch[DIR_UL], dirch[DIR_UR]); + pr("%c %c\n", dirch[DIR_L], dirch[DIR_R]); + pr(" %c %c\n", dirch[DIR_DL], dirch[DIR_DR]); + if (stop_msg != 0) + pr(stop_msg, dirch[DIR_STOP]); + if (view_msg != 0) + pr(view_msg, dirch[DIR_VIEW]); + if (map_msg != 0) + pr(map_msg, dirch[DIR_MAP]); } /* @@ -101,108 +102,109 @@ direrr(s_char *stop_msg, s_char *view_msg, s_char *map_msg) * which do not accept partial moves. */ s_char * -getpath(s_char *buf, s_char *arg, coord x, coord y, int onlyown, int showdes, int showxy, int destinations) +getpath(s_char *buf, s_char *arg, coord x, coord y, int onlyown, + int showdes, int showxy, int destinations) { - s_char *p = buf; - s_char *bp; - s_char prompt[128]; - coord dx, dy; - struct sctstr sect, dsect; - coord nx, ny; - int dir; - s_char *execute; - double mv_cost; + s_char *p = buf; + s_char *bp; + s_char prompt[128]; + coord dx, dy; + struct sctstr sect, dsect; + coord nx, ny; + int dir; + s_char *execute; + double mv_cost; - if (arg) { - strncpy(buf, arg, MAX_PATH_LEN - 1); - buf[MAX_PATH_LEN - 1] = 0; - } else { - *p = 0; - } + if (arg) { + strncpy(buf, arg, MAX_PATH_LEN - 1); + buf[MAX_PATH_LEN - 1] = 0; + } else { + *p = 0; + } - if (showxy) - execute = " & '%c' to execute\n"; - else - execute = "\n"; + if (showxy) + execute = " & '%c' to execute\n"; + else + execute = "\n"; - getsect(x,y,§); - nx = x; - ny = y; + getsect(x, y, §); + nx = x; + ny = y; -more: - while (*p) { - if (sarg_xy(p, &dx, &dy)) { - bp = 0; - if (destinations == P_NONE) { - pr("Destination sectors not allowed here!\n"); - *p = 0; - } - if (getsect(dx,dy,&dsect)) { - if (destinations == P_WALKING){ - bp=BestLandPath(p, §,&dsect, - &mv_cost, MOB_ROAD); - } else if (destinations == P_FLYING) { - bp=BestAirPath(p, nx, ny, dx, dy); - } - } else { - pr("Invalid destination sector!\n"); - *p = 0; - } - if (bp) { - pr("Using best path '%s'\n", p); - pr("Using total path '%s'\n", buf); - return buf; - } else { - pr("Can't get to %s from here!\n", - xyas(nx,ny,player->cnum)); - *p = 0; - } - break; - } - dir = chkdir(*p, DIR_STOP, DIR_LAST); - if (dir < 0) { - pr("\"%c\" is not legal...", *p); - direrr("'%c' to stop", (s_char *)0, execute); - *p = 0; - break; - } - nx = x + diroff[dir][0]; - ny = y + diroff[dir][1]; - getsect(nx, ny, §); - if (onlyown && sect.sct_own != player->cnum) { - *p = 0; - pr("You don't own %s; you can't go there!\n", - xyas(nx, ny, player->cnum)); - break; - } - if (dir == DIR_STOP || dir == DIR_MAP) { - p[1] = 0; - return buf; - } - if (++p - buf == MAX_PATH_LEN) { - pr("Path length may not exceed %d.\n", MAX_PATH_LEN); - pr("Aborting...\n"); - *buf = 0; - return buf; + more: + while (*p) { + if (sarg_xy(p, &dx, &dy)) { + bp = 0; + if (destinations == P_NONE) { + pr("Destination sectors not allowed here!\n"); + *p = 0; + } + if (getsect(dx, dy, &dsect)) { + if (destinations == P_WALKING) { + bp = BestLandPath(p, §, &dsect, + &mv_cost, MOB_ROAD); + } else if (destinations == P_FLYING) { + bp = BestAirPath(p, nx, ny, dx, dy); } - x = nx; - y = ny; + } else { + pr("Invalid destination sector!\n"); + *p = 0; + } + if (bp) { + pr("Using best path '%s'\n", p); + pr("Using total path '%s'\n", buf); + return buf; + } else { + pr("Can't get to %s from here!\n", + xyas(nx, ny, player->cnum)); + *p = 0; + } + break; } - fly_map(x,y); - if (showdes) { - getsect(x, y, §); - sprintf(prompt, "<%c: %s> ", dchr[sect.sct_type].d_mnem, - xyas(x, y, player->cnum)); - } else { - sprintf(prompt, "<%d: %s> ", (int)(p - buf), - xyas(x, y, player->cnum)); + dir = chkdir(*p, DIR_STOP, DIR_LAST); + if (dir < 0) { + pr("\"%c\" is not legal...", *p); + direrr("'%c' to stop", (s_char *)0, execute); + *p = 0; + break; } - if (!(bp = getstring(prompt, p)) || !*bp) { - if (player->aborted) - *buf = 0; - return buf; + nx = x + diroff[dir][0]; + ny = y + diroff[dir][1]; + getsect(nx, ny, §); + if (onlyown && sect.sct_own != player->cnum) { + *p = 0; + pr("You don't own %s; you can't go there!\n", + xyas(nx, ny, player->cnum)); + break; + } + if (dir == DIR_STOP || dir == DIR_MAP) { + p[1] = 0; + return buf; } - goto more; + if (++p - buf == MAX_PATH_LEN) { + pr("Path length may not exceed %d.\n", MAX_PATH_LEN); + pr("Aborting...\n"); + *buf = 0; + return buf; + } + x = nx; + y = ny; + } + fly_map(x, y); + if (showdes) { + getsect(x, y, §); + sprintf(prompt, "<%c: %s> ", dchr[sect.sct_type].d_mnem, + xyas(x, y, player->cnum)); + } else { + sprintf(prompt, "<%d: %s> ", (int)(p - buf), + xyas(x, y, player->cnum)); + } + if (!(bp = getstring(prompt, p)) || !*bp) { + if (player->aborted) + *buf = 0; + return buf; + } + goto more; } /* ARGSUSED */ @@ -230,7 +232,7 @@ mcost(struct sctstr *sp, int own) double fcost(struct sctstr *sp, natid own) { - return 1.0; + return 1.0; } /* @@ -240,7 +242,7 @@ fcost(struct sctstr *sp, natid own) double ncost(struct sctstr *sp, natid own) { - return 1.0; + return 1.0; } /* @@ -248,34 +250,35 @@ ncost(struct sctstr *sp, natid own) * movement cost it takes to get there. */ double -pathtoxy(s_char *path, coord *xp, coord *yp, double (*cost) (struct sctstr *, natid)) +pathtoxy(s_char *path, coord *xp, coord *yp, + double (*cost) (struct sctstr *, natid)) { - struct sctstr s; - s_char *pp; - coord x; - coord y; - int val; - double m; - int c; + struct sctstr s; + s_char *pp; + coord x; + coord y; + int val; + double m; + int c; - x = *xp; - y = *yp; - m = 0.0; - for (pp = path; *pp; pp++) { - if ((val = chkdir(*pp, DIR_STOP, DIR_LAST)) == 0) - break; - x += diroff[val][0]; - y += diroff[val][1]; - c = dirch[val]; - if (c == DIR_STOP) - break; - if (!getsect(x, y, &s)) - return -1.0; - m += cost(&s, s.sct_own); - } - *xp = xnorm(x); - *yp = ynorm(y); - return m; + x = *xp; + y = *yp; + m = 0.0; + for (pp = path; *pp; pp++) { + if ((val = chkdir(*pp, DIR_STOP, DIR_LAST)) == 0) + break; + x += diroff[val][0]; + y += diroff[val][1]; + c = dirch[val]; + if (c == DIR_STOP) + break; + if (!getsect(x, y, &s)) + return -1.0; + m += cost(&s, s.sct_own); + } + *xp = xnorm(x); + *yp = ynorm(y); + return m; } /* @@ -284,49 +287,49 @@ pathtoxy(s_char *path, coord *xp, coord *yp, double (*cost) (struct sctstr *, na int chkpath(natid who, s_char *path, coord x, coord y) { - s_char *pp; - int val; - struct sctstr sect; + s_char *pp; + int val; + struct sctstr sect; - for (pp = path; *pp; pp++) { - if ((val = chkdir(*pp, DIR_STOP, DIR_LAST)) == 0) - break; - x += diroff[val][0]; - y += diroff[val][1]; - if (!getsect(x, y, §) || sect.sct_own != who) - return 0; - } - return 1; + for (pp = path; *pp; pp++) { + if ((val = chkdir(*pp, DIR_STOP, DIR_LAST)) == 0) + break; + x += diroff[val][0]; + y += diroff[val][1]; + if (!getsect(x, y, §) || sect.sct_own != who) + return 0; + } + return 1; } void -pathrange(register coord cx, register coord cy, register s_char *pp, int border, struct range *range) +pathrange(register coord cx, register coord cy, register s_char *pp, + int border, struct range *range) { - int dir; + int dir; - range->lx = cx; - range->hx = cx; - range->ly = cy; - range->hy = cy; - range->width = 0; - range->height = 0; - while ((dir = chkdir(*pp, DIR_FIRST, DIR_LAST)) >= 0) { - pp++; - cx += diroff[dir][0]; - cy += diroff[dir][1]; - if (cx < range->lx) - range->lx = cx; - if (cx > range->hx) - range->hx = cx; - if (cy < range->ly) - range->ly = cy; - if (cy > range->hy) - range->hy = cy; - } - range->lx = xnorm(range->lx - border*2); - range->ly = ynorm(range->ly - border); - range->hx = xnorm(range->hx + border*2 + 1); - range->hy = ynorm(range->hy + border + 1); - xysize_range(range); + range->lx = cx; + range->hx = cx; + range->ly = cy; + range->hy = cy; + range->width = 0; + range->height = 0; + while ((dir = chkdir(*pp, DIR_FIRST, DIR_LAST)) >= 0) { + pp++; + cx += diroff[dir][0]; + cy += diroff[dir][1]; + if (cx < range->lx) + range->lx = cx; + if (cx > range->hx) + range->hx = cx; + if (cy < range->ly) + range->ly = cy; + if (cy > range->hy) + range->hy = cy; + } + range->lx = xnorm(range->lx - border * 2); + range->ly = ynorm(range->ly - border); + range->hx = xnorm(range->hx + border * 2 + 1); + range->hy = ynorm(range->hy + border + 1); + xysize_range(range); } - diff --git a/src/lib/subs/plane.c b/src/lib/subs/plane.c index f5338d98d..8f0eb1ff7 100644 --- a/src/lib/subs/plane.c +++ b/src/lib/subs/plane.c @@ -48,100 +48,102 @@ int pln_postread(int n, s_char *ptr) { - struct plnstr *pp = (struct plnstr *) ptr; - struct shpstr theship; - struct lndstr theland; + struct plnstr *pp = (struct plnstr *)ptr; + struct shpstr theship; + struct lndstr theland; - if (pp->pln_uid != n) { - logerror("pln_postread: Error - %d != %d, zeroing.\n", pp->pln_uid, n); - bzero(ptr, sizeof(struct plnstr)); - } + if (pp->pln_uid != n) { + logerror("pln_postread: Error - %d != %d, zeroing.\n", pp->pln_uid, + n); + bzero(ptr, sizeof(struct plnstr)); + } - if (pp->pln_ship >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) { - if (getship(pp->pln_ship, &theship) && - (theship.shp_effic >= SHIP_MINEFF)) { - /* wooof! Carriers are a pain */ - if (pp->pln_mission){ - /* - * If the plane is on a mission centered - * on it's loc, the op-area travels with - * the plane. - */ - if ((pp->pln_opx == pp->pln_x) && - (pp->pln_opy == pp->pln_y)){ - pp->pln_opx = theship.shp_x; - pp->pln_opy = theship.shp_y; - } - } - if (pp->pln_x != theship.shp_x || pp->pln_y != theship.shp_y) - time(&pp->pln_timestamp); - pp->pln_x = theship.shp_x; - pp->pln_y = theship.shp_y; + if (pp->pln_ship >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) { + if (getship(pp->pln_ship, &theship) && + (theship.shp_effic >= SHIP_MINEFF)) { + /* wooof! Carriers are a pain */ + if (pp->pln_mission) { + /* + * If the plane is on a mission centered + * on it's loc, the op-area travels with + * the plane. + */ + if ((pp->pln_opx == pp->pln_x) && + (pp->pln_opy == pp->pln_y)) { + pp->pln_opx = theship.shp_x; + pp->pln_opy = theship.shp_y; } + } + if (pp->pln_x != theship.shp_x || pp->pln_y != theship.shp_y) + time(&pp->pln_timestamp); + pp->pln_x = theship.shp_x; + pp->pln_y = theship.shp_y; } - if (pp->pln_land >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) { - if (getland(pp->pln_land, &theland) && - (theland.lnd_effic >= LAND_MINEFF)) { - /* wooof! Units are a pain, too */ - if (pp->pln_mission){ - /* - * If the plane is on a mission centered - * on it's loc, the op-area travels with - * the plane. - */ - if ((pp->pln_opx == pp->pln_x) && - (pp->pln_opy == pp->pln_y)){ - pp->pln_opx = theland.lnd_x; - pp->pln_opy = theland.lnd_y; - } - } - if (pp->pln_x != theland.lnd_x || pp->pln_y != theland.lnd_y) - time(&pp->pln_timestamp); - pp->pln_x = theland.lnd_x; - pp->pln_y = theland.lnd_y; + } + if (pp->pln_land >= 0 && pp->pln_own && pp->pln_effic >= PLANE_MINEFF) { + if (getland(pp->pln_land, &theland) && + (theland.lnd_effic >= LAND_MINEFF)) { + /* wooof! Units are a pain, too */ + if (pp->pln_mission) { + /* + * If the plane is on a mission centered + * on it's loc, the op-area travels with + * the plane. + */ + if ((pp->pln_opx == pp->pln_x) && + (pp->pln_opy == pp->pln_y)) { + pp->pln_opx = theland.lnd_x; + pp->pln_opy = theland.lnd_y; } + } + if (pp->pln_x != theland.lnd_x || pp->pln_y != theland.lnd_y) + time(&pp->pln_timestamp); + pp->pln_x = theland.lnd_x; + pp->pln_y = theland.lnd_y; } - player->owner = (player->god || pp->pln_own == player->cnum); - if (opt_MOB_ACCESS) - pln_do_upd_mob(pp); - return 1; + } + player->owner = (player->god || pp->pln_own == player->cnum); + if (opt_MOB_ACCESS) + pln_do_upd_mob(pp); + return 1; } /*ARGSUSED*/ int pln_prewrite(int n, s_char *ptr) { - struct plnstr *pp = (struct plnstr *) ptr; - struct plnstr plane; + struct plnstr *pp = (struct plnstr *)ptr; + struct plnstr plane; - if (pp->pln_effic < PLANE_MINEFF) { - if (pp->pln_own) - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - pp->pln_effic = 0; - } - pp->ef_type = EF_PLANE; - pp->pln_uid = n; + if (pp->pln_effic < PLANE_MINEFF) { + if (pp->pln_own) + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_own = 0; + pp->pln_effic = 0; + } + pp->ef_type = EF_PLANE; + pp->pln_uid = n; - time(&pp->pln_timestamp); + time(&pp->pln_timestamp); - getplane(n, &plane); + getplane(n, &plane); - return 1; + return 1; } void pln_init(int n, s_char *ptr) { - struct plnstr *pp = (struct plnstr *) ptr; + struct plnstr *pp = (struct plnstr *)ptr; - pp->ef_type = EF_PLANE; - pp->pln_uid = n; - pp->pln_own = 0; + pp->ef_type = EF_PLANE; + pp->pln_uid = n; + pp->pln_own = 0; } s_char * prplane(struct plnstr *pp) { - return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid); + return prbuf("%s #%d", plchr[(int)pp->pln_type].pl_name, pp->pln_uid); } diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index 8a7d48730..f32ec182f 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -54,1119 +54,1120 @@ int pln_onewaymission(struct sctstr *target, int *shipno, int *flagp) { - int nships; - int cno; - int flags; - int n; - struct shpstr ship; - s_char buf[1024]; - s_char *p; - - flags = *flagp; - if ((target->sct_own && target->sct_own != player->cnum && - (getrel(getnatp(target->sct_own),player->cnum) != ALLIED)) && - (target->sct_type != SCT_HARBR) && - (target->sct_type != SCT_BSPAN)) { + int nships; + int cno; + int flags; + int n; + struct shpstr ship; + s_char buf[1024]; + s_char *p; + + flags = *flagp; + if ((target->sct_own && target->sct_own != player->cnum && + (getrel(getnatp(target->sct_own), player->cnum) != ALLIED)) && + (target->sct_type != SCT_HARBR) && + (target->sct_type != SCT_BSPAN)) { + pr("Nowhere to land at sector %s!\n", + xyas(target->sct_x, target->sct_y, player->cnum)); + return -1; + } + if (target->sct_type == SCT_MOUNT) { + pr("Nowhere to land at sector %s!\n", + xyas(target->sct_x, target->sct_y, player->cnum)); + return -1; + } + cno = -1; + if (target->sct_type != SCT_AIRPT || target->sct_effic < 60) + flags |= P_V; + if (target->sct_type == SCT_WATER || target->sct_type == SCT_HARBR + || target->sct_type == SCT_BSPAN) { + nships = carriersatxy(target->sct_x, target->sct_y, + M_FLY | M_CHOPPER, 0, player->cnum); + if (nships <= 0) { + if (target->sct_type == SCT_WATER) { pr("Nowhere to land at sector %s!\n", - xyas(target->sct_x, target->sct_y, player->cnum)); + xyas(target->sct_x, target->sct_y, player->cnum)); return -1; + } else { + if ((target->sct_own && target->sct_own != player->cnum) + && (getrel(getnatp(target->sct_own), player->cnum) != + ALLIED)) { + pr("Nowhere to land at sector %s!\n", + xyas(target->sct_x, target->sct_y, player->cnum)); + return -1; + } + *shipno = cno; + *flagp = flags; + return 0; + } } - if (target->sct_type == SCT_MOUNT) { - pr("Nowhere to land at sector %s!\n", - xyas(target->sct_x, target->sct_y, player->cnum)); - return -1; + cno = (-1); + n = (-1); + while (cno < 0) { + if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p) + break; + n = atoi(p); + if (n < 0 || !getship(n, &ship) || (!player->owner && + (getrel + (getnatp(ship.shp_own), + player->cnum) != + ALLIED))) { + pr("Not yours\n"); + continue; + } + if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) { + pr("Ship #%d not in %s\n", n, + xyas(target->sct_x, target->sct_y, player->cnum)); + continue; + } + if (!(mchr[(int)ship.shp_type].m_flags & M_FLY) + && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT) + && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER) + ) { + pr("Can't land on %s.\n", prship(&ship)); + continue; + } + pr("landing on carrier %d\n", n); + cno = n; + flags &= ~P_V; + if (mchr[(int)ship.shp_type].m_flags & M_FLY) + flags |= P_L; + if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER) + flags |= P_K; + if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT) + flags |= P_E; } - cno = -1; - if (target->sct_type != SCT_AIRPT || target->sct_effic < 60) - flags |= P_V; - if (target->sct_type == SCT_WATER || target->sct_type == SCT_HARBR - || target->sct_type == SCT_BSPAN) { - nships = carriersatxy(target->sct_x, target->sct_y, - M_FLY|M_CHOPPER, 0, player->cnum); - if (nships <= 0) { - if (target->sct_type == SCT_WATER){ - pr("Nowhere to land at sector %s!\n", - xyas(target->sct_x, target->sct_y, player->cnum)); - return -1; - }else{ - if ((target->sct_own && target->sct_own != player->cnum) - && (getrel(getnatp(target->sct_own),player->cnum) != ALLIED)){ - pr("Nowhere to land at sector %s!\n", - xyas(target->sct_x, - target->sct_y, player->cnum)); - return -1; - } - *shipno=cno; - *flagp=flags; - return 0; - } - } - cno = (-1); - n = (-1); - while (cno < 0) { - if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p) - break; - n = atoi(p); - if (n < 0 || !getship(n, &ship) || (!player->owner && - (getrel(getnatp(ship.shp_own),player->cnum) != ALLIED))) { - pr("Not yours\n"); - continue; - } - if (ship.shp_x != target->sct_x || - ship.shp_y != target->sct_y) { - pr("Ship #%d not in %s\n", n, - xyas(target->sct_x, target->sct_y, player->cnum)); - continue; - } - if (!(mchr[(int)ship.shp_type].m_flags & M_FLY) - && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT) - && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER) - ){ - pr("Can't land on %s.\n", prship(&ship)); - continue; - } - pr("landing on carrier %d\n",n); - cno = n; - flags &= ~P_V; - if (mchr[(int)ship.shp_type].m_flags & M_FLY) - flags |= P_L; - if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER) - flags |= P_K; - if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT) - flags |= P_E; - } - if ((target->sct_own && target->sct_own != player->cnum) && - (getrel(getnatp(target->sct_own),player->cnum)!= ALLIED) && - (cno== -1)) { - pr("Nowhere to land at sector %s!\n", - xyas(target->sct_x, target->sct_y, player->cnum)); - return -1; - } + if ((target->sct_own && target->sct_own != player->cnum) && + (getrel(getnatp(target->sct_own), player->cnum) != ALLIED) && + (cno == -1)) { + pr("Nowhere to land at sector %s!\n", + xyas(target->sct_x, target->sct_y, player->cnum)); + return -1; } + } - if ((target->sct_own == 0) && (cno < 0)) { - pr("Nowhere to land at sector %s!\n", - xyas(target->sct_x, target->sct_y, player->cnum)); - return -1; - } + if ((target->sct_own == 0) && (cno < 0)) { + pr("Nowhere to land at sector %s!\n", + xyas(target->sct_x, target->sct_y, player->cnum)); + return -1; + } - *shipno = cno; - *flagp = flags; - return 0; + *shipno = cno; + *flagp = flags; + return 0; } void pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno) { - struct emp_qelem *qp; - struct plist *plp; - struct shpstr ship; - struct sctstr sect; - - if (cno >= 0) - getship(cno, &ship); - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *)qp; - /* XXX - need to restrict # of planes per ship */ - if (cno >= 0){ - count_planes(&ship); - if (!can_be_on_ship(plp->plane.pln_uid,ship.shp_uid)) - pr("\t%s cannot land on ship #%d! %s aborts!\n",prplane(&plp->plane),cno,prplane(&plp->plane)); - else if (!put_plane_on_ship(&plp->plane,&ship)) - pr("\tNo room on ship #%d! %s aborts!\n",cno,prplane(&plp->plane)); - else{ - if (plp->plane.pln_own != ship.shp_own){ + struct emp_qelem *qp; + struct plist *plp; + struct shpstr ship; + struct sctstr sect; + + if (cno >= 0) + getship(cno, &ship); + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + /* XXX - need to restrict # of planes per ship */ + if (cno >= 0) { + count_planes(&ship); + if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid)) + pr("\t%s cannot land on ship #%d! %s aborts!\n", + prplane(&plp->plane), cno, prplane(&plp->plane)); + else if (!put_plane_on_ship(&plp->plane, &ship)) + pr("\tNo room on ship #%d! %s aborts!\n", cno, + prplane(&plp->plane)); + else { + if (plp->plane.pln_own != ship.shp_own) { /* plp->plane.pln_own = ship.shp_own;*/ - wu(0,ship.shp_own, - "%s %s lands on your %s\n", - cname(player->cnum), - prplane(&plp->plane), - prship(&ship)); - } - } + wu(0, ship.shp_own, + "%s %s lands on your %s\n", + cname(player->cnum), + prplane(&plp->plane), prship(&ship)); } - else{ - plp->plane.pln_x = tx; - plp->plane.pln_y = ty; - getsect(tx,ty,§); - if (plp->plane.pln_own != sect.sct_own){ + } + } else { + plp->plane.pln_x = tx; + plp->plane.pln_y = ty; + getsect(tx, ty, §); + if (plp->plane.pln_own != sect.sct_own) { /* plp->plane.pln_own = sect.sct_own;*/ - wu(0,sect.sct_own, - "%s %s lands at your sector %s\n", - cname(player->cnum), - prplane(&plp->plane), - xyas(tx,ty,sect.sct_own)); - } - plp->plane.pln_ship = cno; - } + wu(0, sect.sct_own, + "%s %s lands at your sector %s\n", + cname(player->cnum), + prplane(&plp->plane), xyas(tx, ty, sect.sct_own)); + } + plp->plane.pln_ship = cno; } - if (cno >= 0) - putship(ship.shp_uid, &ship); + } + if (cno >= 0) + putship(ship.shp_uid, &ship); } void -pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty, s_char *ptr, int type) +pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty, + s_char *ptr, int type) { - struct emp_qelem *qp; - struct plist *plp; - int amt; - struct shpstr *ship; - int there; - int max; - struct mchrstr *mp; - int mines_there; - - if (ip == 0) - return; - amt = 0; - for (qp = list->q_forw; qp != list; qp = qp->q_forw) { - plp = (struct plist *)qp; - amt += plp->misc; + struct emp_qelem *qp; + struct plist *plp; + int amt; + struct shpstr *ship; + int there; + int max; + struct mchrstr *mp; + int mines_there; + + if (ip == 0) + return; + amt = 0; + for (qp = list->q_forw; qp != list; qp = qp->q_forw) { + plp = (struct plist *)qp; + amt += plp->misc; + } + if (type == EF_SECTOR && + (((struct sctstr *)ptr)->sct_type == SCT_WATER) && + ip->i_vtype == V_SHELL) { + mines_there = getvar(V_MINE, ptr, EF_SECTOR); + putvar(V_MINE, amt + mines_there, ptr, EF_SECTOR); + pr("%d mines laid in %s.\n", amt, + xyas(((struct sctstr *)ptr)->sct_x, + ((struct sctstr *)ptr)->sct_y, player->cnum)); + if (amt > 0 && + map_set(player->cnum, ((struct sctstr *)ptr)->sct_x, + ((struct sctstr *)ptr)->sct_y, 'X', 0)) + writemap(player->cnum); + putsect((struct sctstr *)ptr); + } else { + there = getvar(ip->i_vtype, ptr, type) + amt; + max = 32767; + if (type == EF_SHIP) { + ship = (struct shpstr *)ptr; + mp = &mchr[(int)ship->shp_type]; + max = vl_find(ip->i_vtype, mp->m_vtype, + mp->m_vamt, (int)mp->m_nv); } - if (type == EF_SECTOR && - (((struct sctstr *)ptr)->sct_type == SCT_WATER) && - ip->i_vtype == V_SHELL){ - mines_there = getvar(V_MINE, ptr, EF_SECTOR); - putvar(V_MINE, amt + mines_there, ptr, EF_SECTOR); - pr("%d mines laid in %s.\n", amt, - xyas(((struct sctstr *)ptr)->sct_x, - ((struct sctstr *)ptr)->sct_y, player->cnum)); - if (amt > 0 && - map_set(player->cnum, ((struct sctstr *)ptr)->sct_x, - ((struct sctstr *)ptr)->sct_y, 'X', 0)) - writemap(player->cnum); - putsect((struct sctstr *) ptr); - }else{ - there = getvar(ip->i_vtype, ptr, type) + amt; - max = 32767; - if (type == EF_SHIP) { - ship = (struct shpstr *) ptr; - mp = &mchr[(int)ship->shp_type]; - max = vl_find(ip->i_vtype, mp->m_vtype, - mp->m_vamt, (int)mp->m_nv); - } - if (there > max) { - pr("%d excess %s discarded\n", max-there, ip->i_name); - amt = max - there; - there = max; - } - putvar(ip->i_vtype, there, ptr, type); - pr("%d %s landed safely", amt, ip->i_name); - if (type == EF_SECTOR) { - struct sctstr *sectp = (struct sctstr *)ptr; - if (sectp->sct_own != player->cnum) - wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n", - cname(player->cnum),amt,ip->i_name, - xyas(sectp->sct_x,sectp->sct_y, - sectp->sct_own)); - pr(" at %s\n", xyas(tx, ty, player->cnum)); - putsect((struct sctstr *) ptr); - } else { - struct shpstr *sp = (struct shpstr *)ptr; - if (sp->shp_own != player->cnum) - wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n", - cname(player->cnum),amt,ip->i_name,sp->shp_uid); - pr(" on carrier #%d\n", ship->shp_uid); - putship(ship->shp_uid, ship); - } + if (there > max) { + pr("%d excess %s discarded\n", max - there, ip->i_name); + amt = max - there; + there = max; + } + putvar(ip->i_vtype, there, ptr, type); + pr("%d %s landed safely", amt, ip->i_name); + if (type == EF_SECTOR) { + struct sctstr *sectp = (struct sctstr *)ptr; + if (sectp->sct_own != player->cnum) + wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n", + cname(player->cnum), amt, ip->i_name, + xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); + pr(" at %s\n", xyas(tx, ty, player->cnum)); + putsect((struct sctstr *)ptr); + } else { + struct shpstr *sp = (struct shpstr *)ptr; + if (sp->shp_own != player->cnum) + wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n", + cname(player->cnum), amt, ip->i_name, sp->shp_uid); + pr(" on carrier #%d\n", ship->shp_uid); + putship(ship->shp_uid, ship); } + } } void -pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap, int ap_to_target, int rangemult, int wantflags, int nowantflags) +pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap, + int ap_to_target, int rangemult, int wantflags, int nowantflags) { - struct plnstr plane; - struct shpstr ship; - struct lndstr land; - struct sctstr sect; - int range; - struct plchrstr *pcp; - struct plist *plp; - register int y; - register int bad,bad1; - unsigned int x; - - emp_initque(list); - while (nxtitem(ni, (s_char *)&plane)) { - if (!player->owner) - continue; - if (plane.pln_mobil <= (s_char)0) - continue; - if (opt_MARKET) { - if (ontradingblock(EF_PLANE, (int *)&plane)) { - pr("plane #%d inelligible - it's for sale.\n", plane.pln_uid); - continue; - } - } + struct plnstr plane; + struct shpstr ship; + struct lndstr land; + struct sctstr sect; + int range; + struct plchrstr *pcp; + struct plist *plp; + register int y; + register int bad, bad1; + unsigned int x; + + emp_initque(list); + while (nxtitem(ni, (s_char *)&plane)) { + if (!player->owner) + continue; + if (plane.pln_mobil <= (s_char)0) + continue; + if (opt_MARKET) { + if (ontradingblock(EF_PLANE, (int *)&plane)) { + pr("plane #%d inelligible - it's for sale.\n", + plane.pln_uid); + continue; + } + } - range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y); - if (range > 4) { - pr("%s too far from assembly point\n", - prplane(&plane)); - continue; - } - if (plane.pln_effic < 40) { - pr("%s not efficient enough (must be 40%%)\n", prplane(&plane)); - continue; - } - range += ap_to_target; - pcp = &plchr[(int)plane.pln_type]; - bad=0; - bad1=0; - if (wantflags) { - for(x=0;xpl_flags & y) != y){ - switch(y){ - case P_F: - case P_ESC: bad1=2; - break; - case P_E: - case P_L: - case P_K: bad1=1; - break; - default: bad=1; - } - } - } - if (bad) - continue; - if (bad1 == 2){ - if ((pcp->pl_flags & P_ESC) || - (pcp->pl_flags & P_F)) - bad1=0; - } - if (bad1 == 1){ - if ((wantflags & P_L) && (pcp->pl_flags & P_L)) - bad1=0; - if ((wantflags & P_K) && (pcp->pl_flags & P_K)) - bad1=0; - if ((wantflags & P_E) && (pcp->pl_flags & P_E)) - bad1=0; - } - if (bad1) - continue; - } - bad=0; - bad1=0; - if (nowantflags) { - for(x=0;xpl_flags & y) == y) - bad=1; - } - if (bad) - continue; - } - range *= rangemult; - if (plane.pln_range < range) { - pr("%s out of range (%d:%d)\n", prplane(&plane), - plane.pln_range, range); - continue; - } - if (plane.pln_ship >= 0) { - if (!getship(plane.pln_ship, &ship) || - plane.pln_own != player->cnum) { - shipsunk: - plane.pln_effic = 0; - pr("(note) ship not valid for %s\n", - prplane(&plane)); - putplane(plane.pln_uid, &plane); - continue; - } - if (!can_be_on_ship(plane.pln_uid,ship.shp_uid)) - goto shipsunk; - if (ship.shp_effic < SHIP_MINEFF) - goto shipsunk; - if (ship.shp_effic < 50) - continue; - /* Can't fly off non-owned ships or non-allied ship */ - if ((ship.shp_own != player->cnum) && - (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) { - pr("(note) An ally does not own the ship %s is on\n", - prplane(&plane)); - continue; + range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y); + if (range > 4) { + pr("%s too far from assembly point\n", prplane(&plane)); + continue; + } + if (plane.pln_effic < 40) { + pr("%s not efficient enough (must be 40%%)\n", + prplane(&plane)); + continue; + } + range += ap_to_target; + pcp = &plchr[(int)plane.pln_type]; + bad = 0; + bad1 = 0; + if (wantflags) { + for (x = 0; x < sizeof(wantflags) * 8; x++) { + y = (1 << x); + if ((wantflags & y) == y) + if ((pcp->pl_flags & y) != y) { + switch (y) { + case P_F: + case P_ESC: + bad1 = 2; + break; + case P_E: + case P_L: + case P_K: + bad1 = 1; + break; + default: + bad = 1; } + } + } + if (bad) + continue; + if (bad1 == 2) { + if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F)) + bad1 = 0; + } + if (bad1 == 1) { + if ((wantflags & P_L) && (pcp->pl_flags & P_L)) + bad1 = 0; + if ((wantflags & P_K) && (pcp->pl_flags & P_K)) + bad1 = 0; + if ((wantflags & P_E) && (pcp->pl_flags & P_E)) + bad1 = 0; + } + if (bad1) + continue; + } + bad = 0; + bad1 = 0; + if (nowantflags) { + for (x = 0; x < sizeof(nowantflags) * 8; x++) { + y = (1 << x); + if ((nowantflags & y) == y) + if ((pcp->pl_flags & y) == y) + bad = 1; + } + if (bad) + continue; + } + range *= rangemult; + if (plane.pln_range < range) { + pr("%s out of range (%d:%d)\n", prplane(&plane), + plane.pln_range, range); + continue; + } + if (plane.pln_ship >= 0) { + if (!getship(plane.pln_ship, &ship) || + plane.pln_own != player->cnum) { + shipsunk: + plane.pln_effic = 0; + pr("(note) ship not valid for %s\n", prplane(&plane)); + putplane(plane.pln_uid, &plane); + continue; + } + if (!can_be_on_ship(plane.pln_uid, ship.shp_uid)) + goto shipsunk; + if (ship.shp_effic < SHIP_MINEFF) + goto shipsunk; + if (ship.shp_effic < 50) + continue; + /* Can't fly off non-owned ships or non-allied ship */ + if ((ship.shp_own != player->cnum) && + (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) { + pr("(note) An ally does not own the ship %s is on\n", + prplane(&plane)); + continue; + } + } + if (plane.pln_land >= 0) { + if (!getland(plane.pln_land, &land) || + (plane.pln_own != player->cnum)) { + landdead: + plane.pln_effic = 0; + pr("(note) land unit not valid for %s\n", prplane(&plane)); + putplane(plane.pln_uid, &plane); + continue; + } + if (!(plchr[(int)plane.pln_type].pl_flags & P_E)) + goto landdead; + if (land.lnd_effic < LAND_MINEFF) + goto landdead; + if (land.lnd_effic < 50) + continue; + /* Can't fly off units in ships or other units */ + if ((land.lnd_ship >= 0) || (land.lnd_land >= 0)) + continue; + /* Can't fly off non-owned units or non-allied unit */ + if ((land.lnd_own != player->cnum) && + (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) { + pr("(note) An ally does not own the unit %s is on\n", + prplane(&plane)); + continue; + } + } + /* Now, check the sector status if not on a plane or unit */ + if ((plane.pln_ship < 0) && (plane.pln_land < 0)) { + if (!getsect(plane.pln_x, plane.pln_y, §)) + continue; + /* First, check allied status */ + /* Can't fly from non-owned sectors or non-allied sectors */ + if ((sect.sct_own != player->cnum) && + (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) { + pr("(note) An ally does not own the sector %s is in\n", + prplane(&plane)); + continue; + } + /* non-vtol plane */ + if ((pcp->pl_flags & P_V) == 0) { + if (sect.sct_type != SCT_AIRPT) { + pr("%s not at airport\n", prplane(&plane)); + continue; } - if (plane.pln_land >= 0) { - if (!getland(plane.pln_land, &land) || - (plane.pln_own != player->cnum)) { - landdead: - plane.pln_effic = 0; - pr("(note) land unit not valid for %s\n", - prplane(&plane)); - putplane(plane.pln_uid, &plane); - continue; - } - if (!(plchr[(int)plane.pln_type].pl_flags & P_E)) - goto landdead; - if (land.lnd_effic < LAND_MINEFF) - goto landdead; - if (land.lnd_effic < 50) - continue; - /* Can't fly off units in ships or other units */ - if ((land.lnd_ship >= 0) || (land.lnd_land >= 0)) - continue; - /* Can't fly off non-owned units or non-allied unit */ - if ((land.lnd_own != player->cnum) && - (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) { - pr("(note) An ally does not own the unit %s is on\n", - prplane(&plane)); - continue; - } + if (sect.sct_effic < 40) { + pr("%s is not 40%% efficient, %s can't take off from there.\n", xyas(sect.sct_x, sect.sct_y, plane.pln_own), prplane(&plane)); + continue; } - /* Now, check the sector status if not on a plane or unit */ - if ((plane.pln_ship < 0) && (plane.pln_land < 0)) { - if (!getsect(plane.pln_x, plane.pln_y, §)) - continue; - /* First, check allied status */ - /* Can't fly from non-owned sectors or non-allied sectors */ - if ((sect.sct_own != player->cnum) && - (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) { - pr("(note) An ally does not own the sector %s is in\n", - prplane(&plane)); - continue; - } - /* non-vtol plane */ - if ((pcp->pl_flags & P_V) == 0) { - if (sect.sct_type != SCT_AIRPT) { - pr("%s not at airport\n", prplane(&plane)); - continue; - } - if (sect.sct_effic < 40) { - pr("%s is not 40%% efficient, %s can't take off from there.\n", - xyas(sect.sct_x,sect.sct_y,plane.pln_own), - prplane(&plane)); - continue; - } - if (rangemult == 2 && sect.sct_effic < 60) { - pr("%s is not 60%% efficient, %s can't land there.\n", - xyas(sect.sct_x,sect.sct_y,plane.pln_own), - prplane(&plane)); - continue; - } - } + if (rangemult == 2 && sect.sct_effic < 60) { + pr("%s is not 60%% efficient, %s can't land there.\n", + xyas(sect.sct_x, sect.sct_y, plane.pln_own), + prplane(&plane)); + continue; } - pr("%s standing by\n", prplane(&plane)); - plane.pln_mission = 0; - putplane(plane.pln_uid, &plane); - plp = (struct plist *) malloc(sizeof(struct plist)); - plp->state = P_OK; - plp->misc = 0; - plp->bombs = 0; - plp->pcp = pcp; - bcopy((s_char *)&plane, (s_char *)&plp->plane, - sizeof(struct plnstr)); - emp_insque(&plp->queue, list); + } } + pr("%s standing by\n", prplane(&plane)); + plane.pln_mission = 0; + putplane(plane.pln_uid, &plane); + plp = (struct plist *)malloc(sizeof(struct plist)); + plp->state = P_OK; + plp->misc = 0; + plp->bombs = 0; + plp->pcp = pcp; + bcopy((s_char *)&plane, (s_char *)&plp->plane, + sizeof(struct plnstr)); + emp_insque(&plp->queue, list); + } } int -pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip, int flags, int mission_flags, int *tech) +pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip, + int flags, int mission_flags, int *tech) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *plp; - - if (*tech == 0) - *tech = 9999; - for (qp = list->q_forw; qp != list; qp = next) { - next = qp->q_forw; - plp = (struct plist *) qp; - if (pln_equip(plp, ip, flags, mission) < 0) { - emp_remque(qp); - free((s_char *)qp); - continue; - } - if (flags & (P_S|P_I)) { - if(plp->pcp->pl_flags & P_S) - mission_flags |= P_S; - if(plp->pcp->pl_flags & P_I) - mission_flags |= P_I; - } - if (*tech > plp->plane.pln_tech) - *tech = plp->plane.pln_tech; - if (!(plp->pcp->pl_flags & P_H)) - /* no stealth on this mission */ - mission_flags &= ~P_H; - if (!(plp->pcp->pl_flags & P_X)) - /* no stealth on this mission */ - mission_flags &= ~P_X; - if (!(plp->pcp->pl_flags & P_A)) { - /* no asw on this mission */ - mission_flags &= ~P_A; - } - if (!(plp->pcp->pl_flags & P_MINE)) { - /* no asw on this mission */ - mission_flags &= ~P_MINE; - } - plp->plane.pln_mobil -= pln_mobcost(dist,&plp->plane,flags); - pr("%s equipped\n", prplane(&plp->plane)); + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *plp; + + if (*tech == 0) + *tech = 9999; + for (qp = list->q_forw; qp != list; qp = next) { + next = qp->q_forw; + plp = (struct plist *)qp; + if (pln_equip(plp, ip, flags, mission) < 0) { + emp_remque(qp); + free((s_char *)qp); + continue; } - return mission_flags; + if (flags & (P_S | P_I)) { + if (plp->pcp->pl_flags & P_S) + mission_flags |= P_S; + if (plp->pcp->pl_flags & P_I) + mission_flags |= P_I; + } + if (*tech > plp->plane.pln_tech) + *tech = plp->plane.pln_tech; + if (!(plp->pcp->pl_flags & P_H)) + /* no stealth on this mission */ + mission_flags &= ~P_H; + if (!(plp->pcp->pl_flags & P_X)) + /* no stealth on this mission */ + mission_flags &= ~P_X; + if (!(plp->pcp->pl_flags & P_A)) { + /* no asw on this mission */ + mission_flags &= ~P_A; + } + if (!(plp->pcp->pl_flags & P_MINE)) { + /* no asw on this mission */ + mission_flags &= ~P_MINE; + } + plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags); + pr("%s equipped\n", prplane(&plp->plane)); + } + return mission_flags; } int pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission) { - register struct plchrstr *pcp; - struct plnstr *pp; - int needed; - struct lndstr land; - struct shpstr ship; - struct sctstr sect; - int type; - s_char *ptr; - int item; - int rval; - int vec[I_MAX+1]; - int own; - - pp = &plp->plane; - pcp = plp->pcp; - if (pp->pln_ship >= 0) { - getship(pp->pln_ship, &ship); - type = EF_SHIP; - ptr = (s_char *) &ship; - own = ship.shp_own; - } else if (pp->pln_land >= 0) { - getland(pp->pln_land, &land); - type = EF_LAND; - ptr = (s_char *) &land; - own = land.lnd_own; - } else { - getsect(pp->pln_x, pp->pln_y, §); - type = EF_SECTOR; - ptr = (s_char *) § - own = sect.sct_oldown; - } - if (ip) { - if (ip->i_vtype == V_CIVIL) { - if (pp->pln_own != own) { - pr("You don't control those civilians!\n"); - return -1; - } - } - } - getvec(VT_ITEM, vec, ptr, type); - if (pcp->pl_fuel > vec[I_PETROL]) { - pr("%s not enough petrol there!\n", prplane(pp)); + register struct plchrstr *pcp; + struct plnstr *pp; + int needed; + struct lndstr land; + struct shpstr ship; + struct sctstr sect; + int type; + s_char *ptr; + int item; + int rval; + int vec[I_MAX + 1]; + int own; + + pp = &plp->plane; + pcp = plp->pcp; + if (pp->pln_ship >= 0) { + getship(pp->pln_ship, &ship); + type = EF_SHIP; + ptr = (s_char *)&ship; + own = ship.shp_own; + } else if (pp->pln_land >= 0) { + getland(pp->pln_land, &land); + type = EF_LAND; + ptr = (s_char *)&land; + own = land.lnd_own; + } else { + getsect(pp->pln_x, pp->pln_y, §); + type = EF_SECTOR; + ptr = (s_char *)§ + own = sect.sct_oldown; + } + if (ip) { + if (ip->i_vtype == V_CIVIL) { + if (pp->pln_own != own) { + pr("You don't control those civilians!\n"); return -1; + } } - vec[I_PETROL] -= pcp->pl_fuel; - rval = 0; - if ((flags & P_F) == 0) { + } + getvec(VT_ITEM, vec, ptr, type); + if (pcp->pl_fuel > vec[I_PETROL]) { + pr("%s not enough petrol there!\n", prplane(pp)); + return -1; + } + vec[I_PETROL] -= pcp->pl_fuel; + rval = 0; + if ((flags & P_F) == 0) { + item = 0; + needed = 0; + switch (mission) { + case 's': + case 'p': + if (pp->pln_nuketype == -1) { + item = I_SHELL; + needed = pp->pln_load; + } + break; + case 't': + if ((pcp->pl_flags & P_C) == 0 || ip == 0) + break; + item = ip - ichr; + needed = (pp->pln_load * 2) / ip->i_lbs; + break; + case 'd': + item = ip - ichr; + needed = (pp->pln_load * 2) / ip->i_lbs; + /* Is this mine dropping excursion? */ + if ((item == I_SHELL) && (pcp->pl_flags & P_MINE)) + break; + /* Is this a cargo drop? */ + if ((pcp->pl_flags & P_C) == 0 || ip == 0) { item = 0; needed = 0; - switch (mission) { - case 's': - case 'p': - if (pp->pln_nuketype == -1) { - item = I_SHELL; - needed = pp->pln_load; - } - break; - case 't': - if ((pcp->pl_flags & P_C) == 0 || ip == 0) - break; - item = ip - ichr; - needed = (pp->pln_load * 2) / ip->i_lbs; - break; - case 'd': - item = ip - ichr; - needed = (pp->pln_load * 2) / ip->i_lbs; - /* Is this mine dropping excursion? */ - if ((item == I_SHELL) && (pcp->pl_flags & P_MINE)) - break; - /* Is this a cargo drop? */ - if ((pcp->pl_flags & P_C) == 0 || ip == 0) { - item = 0; - needed = 0; - break; - } - break; - case 'a': - if ((pcp->pl_flags & (P_V|P_C)) == 0) - break; - item = I_MILIT; - needed = pp->pln_load / ip->i_lbs; - break; - case 'n': - if (pp->pln_nuketype == (s_char)-1) - rval = -1; - break; - default: - break; - } - if (rval < 0 || (item && needed <= 0)) { - pr("%s can't contribute to mission\n", prplane(pp)); - return -1; - } + break; + } + break; + case 'a': + if ((pcp->pl_flags & (P_V | P_C)) == 0) + break; + item = I_MILIT; + needed = pp->pln_load / ip->i_lbs; + break; + case 'n': + if (pp->pln_nuketype == (s_char)-1) + rval = -1; + break; + default: + break; + } + if (rval < 0 || (item && needed <= 0)) { + pr("%s can't contribute to mission\n", prplane(pp)); + return -1; + } #if 0 - /* Supply is broken somewhere, so don't use it for now */ - if ((vec[item] < needed) && (item == I_SHELL)) - vec[item] += supply_commod(plp->plane.pln_own, - plp->plane.pln_x,plp->plane.pln_y,I_SHELL, - needed); + /* Supply is broken somewhere, so don't use it for now */ + if ((vec[item] < needed) && (item == I_SHELL)) + vec[item] += supply_commod(plp->plane.pln_own, + plp->plane.pln_x, plp->plane.pln_y, + I_SHELL, needed); #endif - if (vec[item] < needed) { - pr("Not enough %s for %s\n", - ichr[item].i_name, prplane(pp)); - return -1; - } else { - vec[item] -= needed; - } - if (item == I_SHELL && (mission == 's' || mission == 'p')) - plp->bombs = needed; - else - plp->misc = needed; - } - putvec(VT_ITEM, vec, ptr, type); - if (type == EF_SHIP) { - if (pp->pln_own != ship.shp_own) { - wu(0, ship.shp_own, "%s %s prepares for takeoff from ship %s\n", - cname(pp->pln_own), prplane(pp), prship(&ship)); - } - putship(ship.shp_uid,&ship); - } else if (type == EF_LAND) { - if (pp->pln_own != land.lnd_own) { - wu(0, land.lnd_own, "%s %s prepares for takeoff from unit %s\n", - cname(pp->pln_own), prplane(pp), prland(&land)); - } - putland(land.lnd_uid,&land); + if (vec[item] < needed) { + pr("Not enough %s for %s\n", ichr[item].i_name, prplane(pp)); + return -1; } else { - if (pp->pln_own != sect.sct_own) { - wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n", - cname(pp->pln_own), prplane(pp), xyas(sect.sct_x, sect.sct_y, sect.sct_own)); - } - putsect(§); + vec[item] -= needed; + } + if (item == I_SHELL && (mission == 's' || mission == 'p')) + plp->bombs = needed; + else + plp->misc = needed; + } + putvec(VT_ITEM, vec, ptr, type); + if (type == EF_SHIP) { + if (pp->pln_own != ship.shp_own) { + wu(0, ship.shp_own, + "%s %s prepares for takeoff from ship %s\n", + cname(pp->pln_own), prplane(pp), prship(&ship)); + } + putship(ship.shp_uid, &ship); + } else if (type == EF_LAND) { + if (pp->pln_own != land.lnd_own) { + wu(0, land.lnd_own, + "%s %s prepares for takeoff from unit %s\n", + cname(pp->pln_own), prplane(pp), prland(&land)); + } + putland(land.lnd_uid, &land); + } else { + if (pp->pln_own != sect.sct_own) { + wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n", + cname(pp->pln_own), prplane(pp), xyas(sect.sct_x, + sect.sct_y, + sect.sct_own)); } - return rval; + putsect(§); + } + return rval; } void pln_put(struct emp_qelem *list) { - register struct emp_qelem *qp; - register struct emp_qelem *newqp; - struct plist *plp; - struct plnstr *pp; - struct shpstr ship; - struct sctstr sect; - - /* Here is where planes return home from bombing runs. - We need to make sure they still have somewhere to return - home to! */ - qp = list->q_forw; - while (qp != list) { - plp = (struct plist *) qp; - pp = &plp->plane; - /* Ok, check out where it wants to land */ - if (pp->pln_ship >= 0) { - /* It is landing on a carrier */ - getship(pp->pln_ship, &ship); - /* We should do more, like make sure it's really - a carrier, etc. but for now just make sure it's - not sunk. */ - if (ship.shp_effic < SHIP_MINEFF) { - mpr(pp->pln_own, "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n", pp->pln_ship, pp->pln_uid); - pp->pln_effic = 0; - } - } else { - /* Presume we are landing back in a sector. */ - getsect(pp->pln_x, pp->pln_y, §); - if (sect.sct_type == SCT_WATER || - sect.sct_type == SCT_WASTE) { - mpr(pp->pln_own, "Nowwhere to land at %s, plane #%d crashes and burns...\n", xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid); - pp->pln_effic = 0; - } - } - putplane(pp->pln_uid, pp); - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + register struct emp_qelem *qp; + register struct emp_qelem *newqp; + struct plist *plp; + struct plnstr *pp; + struct shpstr ship; + struct sctstr sect; + + /* Here is where planes return home from bombing runs. + We need to make sure they still have somewhere to return + home to! */ + qp = list->q_forw; + while (qp != list) { + plp = (struct plist *)qp; + pp = &plp->plane; + /* Ok, check out where it wants to land */ + if (pp->pln_ship >= 0) { + /* It is landing on a carrier */ + getship(pp->pln_ship, &ship); + /* We should do more, like make sure it's really + a carrier, etc. but for now just make sure it's + not sunk. */ + if (ship.shp_effic < SHIP_MINEFF) { + mpr(pp->pln_own, + "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n", + pp->pln_ship, pp->pln_uid); + pp->pln_effic = 0; + } + } else { + /* Presume we are landing back in a sector. */ + getsect(pp->pln_x, pp->pln_y, §); + if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) { + mpr(pp->pln_own, + "Nowwhere to land at %s, plane #%d crashes and burns...\n", + xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid); + pp->pln_effic = 0; + } } + putplane(pp->pln_uid, pp); + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } } void pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list) { - struct emp_qelem *bomb; - struct emp_qelem *esc; - struct plist *bombp; - struct plist *escp; - - if (QEMPTY(bomb_list) || QEMPTY(esc_list)) - return; - bomb = bomb_list->q_forw; - while (bomb != bomb_list) { - if (QEMPTY(esc_list)) { - bomb = bomb_list; - continue; - } - esc = esc_list->q_forw; - bombp = (struct plist *) bomb; - while (esc != esc_list) { - escp = (struct plist *) esc; - if (escp->plane.pln_uid == bombp->plane.pln_uid) { - emp_remque(esc); - free((s_char *)esc); - esc = esc_list; - } else - esc = esc->q_forw; - } - bomb = bomb->q_forw; + struct emp_qelem *bomb; + struct emp_qelem *esc; + struct plist *bombp; + struct plist *escp; + + if (QEMPTY(bomb_list) || QEMPTY(esc_list)) + return; + bomb = bomb_list->q_forw; + while (bomb != bomb_list) { + if (QEMPTY(esc_list)) { + bomb = bomb_list; + continue; } + esc = esc_list->q_forw; + bombp = (struct plist *)bomb; + while (esc != esc_list) { + escp = (struct plist *)esc; + if (escp->plane.pln_uid == bombp->plane.pln_uid) { + emp_remque(esc); + free((s_char *)esc); + esc = esc_list; + } else + esc = esc->q_forw; + } + bomb = bomb->q_forw; + } } int put_plane_on_ship(struct plnstr *plane, struct shpstr *ship) { - struct plchrstr *pcp; - struct mchrstr *mcp; - - pcp = &plchr[(int)plane->pln_type]; - mcp = &mchr[(int)ship->shp_type]; - - if (((int)plane->pln_ship) == ((int)ship->shp_uid)) - return 1; /* Already on ship */ - - /* Try to put on ship as a chopper plane */ - if ((pcp->pl_flags & P_K) && - (mcp->m_flags & M_CHOPPER) && - (ship->shp_nchoppers < mcp->m_nchoppers)){ - - ship->shp_nchoppers++; - plane->pln_x = ship->shp_x; - plane->pln_y = ship->shp_y; - plane->pln_ship = ship->shp_uid; - putship(ship->shp_uid,ship); - putplane(plane->pln_uid,plane); - return 1; - } - - /* Try to put on ship as an xlight plane */ - if ((pcp->pl_flags & P_E) && - (mcp->m_flags & M_XLIGHT) && - (ship->shp_nxlight < mcp->m_nxlight)){ - - ship->shp_nxlight++; - plane->pln_x = ship->shp_x; - plane->pln_y = ship->shp_y; - plane->pln_ship = ship->shp_uid; - putship(ship->shp_uid,ship); - putplane(plane->pln_uid,plane); - return 1; - } - - /* Try to put on ship as a normal plane */ - if ( ( ((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) || - ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) && - (mcp->m_flags & M_MSL)) ) && - (ship->shp_nplane < mcp->m_nplanes)){ - - ship->shp_nplane++; - plane->pln_x = ship->shp_x; - plane->pln_y = ship->shp_y; - plane->pln_ship = ship->shp_uid; - putship(ship->shp_uid,ship); - putplane(plane->pln_uid,plane); - return 1; - } - - /* We have failed */ - return 0; + struct plchrstr *pcp; + struct mchrstr *mcp; + + pcp = &plchr[(int)plane->pln_type]; + mcp = &mchr[(int)ship->shp_type]; + + if (((int)plane->pln_ship) == ((int)ship->shp_uid)) + return 1; /* Already on ship */ + + /* Try to put on ship as a chopper plane */ + if ((pcp->pl_flags & P_K) && + (mcp->m_flags & M_CHOPPER) && + (ship->shp_nchoppers < mcp->m_nchoppers)) { + + ship->shp_nchoppers++; + plane->pln_x = ship->shp_x; + plane->pln_y = ship->shp_y; + plane->pln_ship = ship->shp_uid; + putship(ship->shp_uid, ship); + putplane(plane->pln_uid, plane); + return 1; + } + + /* Try to put on ship as an xlight plane */ + if ((pcp->pl_flags & P_E) && + (mcp->m_flags & M_XLIGHT) && + (ship->shp_nxlight < mcp->m_nxlight)) { + + ship->shp_nxlight++; + plane->pln_x = ship->shp_x; + plane->pln_y = ship->shp_y; + plane->pln_ship = ship->shp_uid; + putship(ship->shp_uid, ship); + putplane(plane->pln_uid, plane); + return 1; + } + + /* Try to put on ship as a normal plane */ + if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) || + ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) && + (mcp->m_flags & M_MSL))) && + (ship->shp_nplane < mcp->m_nplanes)) { + + ship->shp_nplane++; + plane->pln_x = ship->shp_x; + plane->pln_y = ship->shp_y; + plane->pln_ship = ship->shp_uid; + putship(ship->shp_uid, ship); + putplane(plane->pln_uid, plane); + return 1; + } + + /* We have failed */ + return 0; } int take_plane_off_ship(struct plnstr *plane, struct shpstr *ship) { - struct plchrstr *pcp; - struct mchrstr *mcp; - - pcp = &plchr[(int)plane->pln_type]; - mcp = &mchr[(int)ship->shp_type]; - - /* Try to take off ship as a chopper plane */ - if ((pcp->pl_flags & P_K) && - (mcp->m_flags & M_CHOPPER) && - (ship->shp_nchoppers)){ - - ship->shp_nchoppers--; - plane->pln_ship = -1; - putship(ship->shp_uid,ship); - putplane(plane->pln_uid,plane); - return 1; - } - - /* Try to take off ship as an xlight plane */ - if ((pcp->pl_flags & P_E) && - (mcp->m_flags & M_XLIGHT) && - (ship->shp_nxlight)){ - - ship->shp_nxlight--; - plane->pln_ship = -1; - putship(ship->shp_uid,ship); - putplane(plane->pln_uid,plane); - return 1; - } - - /* Try to take off ship as a normal plane */ - if ( ( ((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) || - ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) && - (mcp->m_flags & M_MSL)) ) && - (ship->shp_nplane)){ - - ship->shp_nplane--; - plane->pln_ship = -1; - putship(ship->shp_uid,ship); - putplane(plane->pln_uid,plane); - return 1; - } - - /* We have failed */ - return 0; + struct plchrstr *pcp; + struct mchrstr *mcp; + + pcp = &plchr[(int)plane->pln_type]; + mcp = &mchr[(int)ship->shp_type]; + + /* Try to take off ship as a chopper plane */ + if ((pcp->pl_flags & P_K) && + (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) { + + ship->shp_nchoppers--; + plane->pln_ship = -1; + putship(ship->shp_uid, ship); + putplane(plane->pln_uid, plane); + return 1; + } + + /* Try to take off ship as an xlight plane */ + if ((pcp->pl_flags & P_E) && + (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) { + + ship->shp_nxlight--; + plane->pln_ship = -1; + putship(ship->shp_uid, ship); + putplane(plane->pln_uid, plane); + return 1; + } + + /* Try to take off ship as a normal plane */ + if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) || + ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) && + (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) { + + ship->shp_nplane--; + plane->pln_ship = -1; + putship(ship->shp_uid, ship); + putplane(plane->pln_uid, plane); + return 1; + } + + /* We have failed */ + return 0; } int take_plane_off_land(struct plnstr *plane, struct lndstr *land) { - struct plchrstr *pcp; - struct lchrstr *lcp; - - pcp = &plchr[(int)plane->pln_type]; - lcp = &lchr[(int)land->lnd_type]; - - /* Try to take off ship as an xlight plane */ - if ((pcp->pl_flags & P_E) && - (lcp->l_flags & L_XLIGHT) && - (land->lnd_nxlight)){ - - land->lnd_nxlight--; - plane->pln_land = -1; - putland(land->lnd_uid,land); - putplane(plane->pln_uid,plane); - return 1; - } + struct plchrstr *pcp; + struct lchrstr *lcp; - /* We have failed */ - return 0; + pcp = &plchr[(int)plane->pln_type]; + lcp = &lchr[(int)land->lnd_type]; + + /* Try to take off ship as an xlight plane */ + if ((pcp->pl_flags & P_E) && + (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) { + + land->lnd_nxlight--; + plane->pln_land = -1; + putland(land->lnd_uid, land); + putplane(plane->pln_uid, plane); + return 1; + } + + /* We have failed */ + return 0; } int can_be_on_ship(int p, int s) { - struct plnstr plane; - struct shpstr ship; - struct plchrstr *pcp; - struct mchrstr *mcp; + struct plnstr plane; + struct shpstr ship; + struct plchrstr *pcp; + struct mchrstr *mcp; - getplane(p,&plane); - getship(s,&ship); + getplane(p, &plane); + getship(s, &ship); - pcp = &plchr[(int)plane.pln_type]; - mcp = &mchr[(int)ship.shp_type]; + pcp = &plchr[(int)plane.pln_type]; + mcp = &mchr[(int)ship.shp_type]; - if (pcp->pl_flags & P_L) - if (mcp->m_flags & M_FLY) - return 1; + if (pcp->pl_flags & P_L) + if (mcp->m_flags & M_FLY) + return 1; - if (pcp->pl_flags & P_K) - if (mcp->m_flags & M_CHOPPER) - return 1; + if (pcp->pl_flags & P_K) + if (mcp->m_flags & M_CHOPPER) + return 1; - if (pcp->pl_flags & P_M) - if (mcp->m_flags & M_MSL) - return 1; + if (pcp->pl_flags & P_M) + if (mcp->m_flags & M_MSL) + return 1; - if (pcp->pl_flags & P_E) - if (mcp->m_flags & M_XLIGHT) - return 1; + if (pcp->pl_flags & P_E) + if (mcp->m_flags & M_XLIGHT) + return 1; - return 0; + return 0; } void plane_sweep(struct emp_qelem *plane_list, coord x, coord y) { - struct plnstr *pp; - struct plchrstr *pcp; - struct emp_qelem *qp; - struct emp_qelem *next; - struct plist *ip; - struct sctstr sect; - int mines_there; - int found = 0; - - getsect(x,y,§); - mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR); - - if (mines_there == 0) - return; - - if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR)) - return; - - for (qp=plane_list->q_forw;((qp!=plane_list)&&(mines_there));qp=next) { - next = qp->q_forw; - ip = (struct plist *) qp; - pp = &ip->plane; - pcp = ip->pcp; - if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */ - continue; - - if (chance( ((double) (100-pp->pln_acc))/100.0 )){ - pr("Sweep! in %s\n", - xyas(sect.sct_x,sect.sct_y,pp->pln_own)); - mines_there--; - found = 1; - } + struct plnstr *pp; + struct plchrstr *pcp; + struct emp_qelem *qp; + struct emp_qelem *next; + struct plist *ip; + struct sctstr sect; + int mines_there; + int found = 0; + + getsect(x, y, §); + mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR); + + if (mines_there == 0) + return; + + if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR)) + return; + + for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there)); + qp = next) { + next = qp->q_forw; + ip = (struct plist *)qp; + pp = &ip->plane; + pcp = ip->pcp; + if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */ + continue; + + if (chance(((double)(100 - pp->pln_acc)) / 100.0)) { + pr("Sweep! in %s\n", + xyas(sect.sct_x, sect.sct_y, pp->pln_own)); + mines_there--; + found = 1; } + } - if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0)) - writemap(player->cnum); - putvar(V_MINE, mines_there, (s_char *)§, EF_SECTOR); - putsect(§); + if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0)) + writemap(player->cnum); + putvar(V_MINE, mines_there, (s_char *)§, EF_SECTOR); + putsect(§); } void count_planes(struct shpstr *sp) { - struct nstr_item ni; - struct plnstr plane; - struct plchrstr *pcp; - struct mchrstr *mcp; - int nplane = 0; - int nchoppers = 0; - int nxlight = 0; - - if (sp->shp_effic < SHIP_MINEFF) - return; - - mcp = &mchr[(int)sp->shp_type]; - snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y); - while (nxtitem(&ni, (s_char *)&plane)){ - if (plane.pln_own == 0) - continue; - if (plane.pln_ship == sp->shp_uid){ - pcp = &plchr[(int)plane.pln_type]; - if ((pcp->pl_flags & P_K) && - (nchoppers < mcp->m_nchoppers)) - nchoppers++; - else - if ((pcp->pl_flags & P_E) && - (nxlight < mcp->m_nxlight)) - nxlight++; - else - if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M)) - nplane++; - } - } - - if (nplane != sp->shp_nplane || - nxlight != sp->shp_nxlight || - nchoppers != sp->shp_nchoppers) { - sp->shp_nplane = nplane; - sp->shp_nxlight = nxlight; - sp->shp_nchoppers = nchoppers; - putship(sp->shp_uid, sp); + struct nstr_item ni; + struct plnstr plane; + struct plchrstr *pcp; + struct mchrstr *mcp; + int nplane = 0; + int nchoppers = 0; + int nxlight = 0; + + if (sp->shp_effic < SHIP_MINEFF) + return; + + mcp = &mchr[(int)sp->shp_type]; + snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + if (plane.pln_ship == sp->shp_uid) { + pcp = &plchr[(int)plane.pln_type]; + if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers)) + nchoppers++; + else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight)) + nxlight++; + else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M)) + nplane++; } + } + + if (nplane != sp->shp_nplane || + nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) { + sp->shp_nplane = nplane; + sp->shp_nxlight = nxlight; + sp->shp_nchoppers = nchoppers; + putship(sp->shp_uid, sp); + } } void count_land_planes(struct lndstr *lp) { - struct nstr_item ni; - struct plnstr plane; - int nplane = 0; - - if (lp->lnd_effic < LAND_MINEFF) - return; - - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) { - if (plane.pln_own == 0) - continue; - if (plane.pln_land == lp->lnd_uid) - nplane++; - } - - if (lp->lnd_nxlight != nplane) { - lp->lnd_nxlight = nplane; - putland(lp->lnd_uid,lp); - } + struct nstr_item ni; + struct plnstr plane; + int nplane = 0; + + if (lp->lnd_effic < LAND_MINEFF) + return; + + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_own == 0) + continue; + if (plane.pln_land == lp->lnd_uid) + nplane++; + } + + if (lp->lnd_nxlight != nplane) { + lp->lnd_nxlight = nplane; + putland(lp->lnd_uid, lp); + } } int count_sect_planes(struct sctstr *sp) { - int count = 0; - struct nstr_item ni; - struct plnstr plane; - - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) { - if (!plane.pln_own) - continue; - if (plane.pln_flags & PLN_LAUNCHED) - continue; - if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y) - ++count; - } - - return count; + int count = 0; + struct nstr_item ni; + struct plnstr plane; + + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (!plane.pln_own) + continue; + if (plane.pln_flags & PLN_LAUNCHED) + continue; + if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y) + ++count; + } + + return count; } int put_plane_on_land(struct plnstr *plane, struct lndstr *land) { - struct plchrstr *pcp; - struct lchrstr *lcp; - - pcp = &plchr[(int)plane->pln_type]; - lcp = &lchr[(int)land->lnd_type]; - - if (((int)plane->pln_land) == ((int)land->lnd_uid)) - return 1; /* Already on unit */ - - /* Try to put on unit as an xlight plane */ - if ((pcp->pl_flags & P_E) && - (lcp->l_flags & L_XLIGHT) && - (land->lnd_nxlight < lcp->l_nxlight)){ - - land->lnd_nxlight++; - plane->pln_x = land->lnd_x; - plane->pln_y = land->lnd_y; - plane->pln_land = land->lnd_uid; - putland(land->lnd_uid,land); - putplane(plane->pln_uid,plane); - return 1; - } - - /* We have failed */ - return 0; + struct plchrstr *pcp; + struct lchrstr *lcp; + + pcp = &plchr[(int)plane->pln_type]; + lcp = &lchr[(int)land->lnd_type]; + + if (((int)plane->pln_land) == ((int)land->lnd_uid)) + return 1; /* Already on unit */ + + /* Try to put on unit as an xlight plane */ + if ((pcp->pl_flags & P_E) && + (lcp->l_flags & L_XLIGHT) && + (land->lnd_nxlight < lcp->l_nxlight)) { + + land->lnd_nxlight++; + plane->pln_x = land->lnd_x; + plane->pln_y = land->lnd_y; + plane->pln_land = land->lnd_uid; + putland(land->lnd_uid, land); + putplane(plane->pln_uid, plane); + return 1; + } + + /* We have failed */ + return 0; } int pln_hitchance(struct plnstr *pp, int hardtarget, int type) { - struct plchrstr *pcp = plchr + pp->pln_type; - float tfact = (float)(pp->pln_tech - pcp->pl_tech) / - (pp->pln_tech - pcp->pl_tech / 2); - int acc = pp->pln_acc; - int hitchance; - - if (type == EF_SHIP) { - if (pcp->pl_flags & P_A) - acc -= 20; - if (!(pcp->pl_flags & P_T)) - acc += 35; - } - hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) * - (1.0 - (float)acc / 100.0)) - hardtarget; - - /* smooth out the bottom of the graph with asymtote at 5 -KHS */ - if (hitchance < 20) - hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1); - if (hitchance > 100) - hitchance = 100; - return hitchance; + struct plchrstr *pcp = plchr + pp->pln_type; + float tfact = (float)(pp->pln_tech - pcp->pl_tech) / + (pp->pln_tech - pcp->pl_tech / 2); + int acc = pp->pln_acc; + int hitchance; + + if (type == EF_SHIP) { + if (pcp->pl_flags & P_A) + acc -= 20; + if (!(pcp->pl_flags & P_T)) + acc += 35; + } + hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) * + (1.0 - (float)acc / 100.0)) - hardtarget; + + /* smooth out the bottom of the graph with asymtote at 5 -KHS */ + if (hitchance < 20) + hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1); + if (hitchance > 100) + hitchance = 100; + return hitchance; } /* return 0 if there was a nuclear detonation */ int -pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp, int noisy) +pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp, + int noisy) { - struct plchrstr *pcp = plchr + pp->pln_type; - int i; - int hitroll; - int dam = 0; - int aim; - int effective = 1; - int pinbomber = 0; - - if (pp->pln_nuketype != (s_char)-1) { - mpr(pp->pln_own, "Releasing RV's for %s detonation...\n", - pp->pln_flags & PLN_AIRBURST?"airburst":"groundburst"); - *nukedamp = detonate(pp, x, y); - return 0; - } else - *nukedamp = 0; + struct plchrstr *pcp = plchr + pp->pln_type; + int i; + int hitroll; + int dam = 0; + int aim; + int effective = 1; + int pinbomber = 0; + + if (pp->pln_nuketype != (s_char)-1) { + mpr(pp->pln_own, "Releasing RV's for %s detonation...\n", + pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst"); + *nukedamp = detonate(pp, x, y); + return 0; + } else + *nukedamp = 0; - if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */ - return 0; + if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */ + return 0; - i = roll(pp->pln_load) + 1; - if (i > pp->pln_load) - i = pp->pln_load; - - if (pcp->pl_flags & P_M) { - if (pcp->pl_flags & P_MAR) - pinbomber = 1; - } else if (pcp->pl_flags & P_T) - pinbomber = 1; - - aim = 100 - pp->pln_acc; - if (type == 's') { - if (pinbomber) { - aim = pp->pln_acc; - effective = 0; - } - aim += 30; - } else { - if (!pinbomber) { - effective = 0; - } + i = roll(pp->pln_load) + 1; + if (i > pp->pln_load) + i = pp->pln_load; + + if (pcp->pl_flags & P_M) { + if (pcp->pl_flags & P_MAR) + pinbomber = 1; + } else if (pcp->pl_flags & P_T) + pinbomber = 1; + + aim = 100 - pp->pln_acc; + if (type == 's') { + if (pinbomber) { + aim = pp->pln_acc; + effective = 0; } - while (i--) { - dam += roll(6); - hitroll = roll(100); - if (hitroll >= 90) { - dam += 8; - if (noisy) - mpr(pp->pln_own, "BLAM"); - } else if (hitroll < aim) { - dam += 5; - if (noisy) - mpr(pp->pln_own, "Blam"); - } else { - dam += 1; - if (noisy) - mpr(pp->pln_own, "blam"); - } - if (i && noisy) - mpr(pp->pln_own, "-"); + aim += 30; + } else { + if (!pinbomber) { + effective = 0; + } + } + while (i--) { + dam += roll(6); + hitroll = roll(100); + if (hitroll >= 90) { + dam += 8; + if (noisy) + mpr(pp->pln_own, "BLAM"); + } else if (hitroll < aim) { + dam += 5; + if (noisy) + mpr(pp->pln_own, "Blam"); + } else { + dam += 1; + if (noisy) + mpr(pp->pln_own, "blam"); } - if (noisy) - mpr(pp->pln_own, "\n"); - if (effective) - dam *= 2; - return dam; + if (i && noisy) + mpr(pp->pln_own, "-"); + } + if (noisy) + mpr(pp->pln_own, "\n"); + if (effective) + dam *= 2; + return dam; } int pln_identchance(struct plnstr *pp, int hardtarget, int type) { - double misschance = (100.0-pln_hitchance(pp, hardtarget, type))/100.0; - return (int)(100 - 100 * misschance * misschance); + double misschance = + (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0; + return (int)(100 - 100 * misschance * misschance); } int pln_mobcost(int dist, struct plnstr *pp, int flags) { - int cost; + int cost; - if ((flags & P_F) || (flags & P_ESC)) - cost = 10 * 100 / pp->pln_effic; - else - cost = 20 * 100 / pp->pln_effic; + if ((flags & P_F) || (flags & P_ESC)) + cost = 10 * 100 / pp->pln_effic; + else + cost = 20 * 100 / pp->pln_effic; - cost = ldround((double)cost * dist/pp->pln_range_max, 1); + cost = ldround((double)cost * dist / pp->pln_range_max, 1); - return min(32 + pp->pln_mobil, cost + 5); + return min(32 + pp->pln_mobil, cost + 5); } - diff --git a/src/lib/subs/pr.c b/src/lib/subs/pr.c index dc0c69a28..a244f4de4 100644 --- a/src/lib/subs/pr.c +++ b/src/lib/subs/pr.c @@ -55,7 +55,7 @@ #include "com.h" #include "news.h" #include "tel.h" -extern int update_pending; +extern int update_pending; #include "prototypes.h" void outid(struct player *pl, int n); @@ -64,116 +64,116 @@ void outid(struct player *pl, int n); void pr(s_char *format, ...) { - s_char buf[4096]; - va_list ap; + s_char buf[4096]; + va_list ap; - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - pr_player(player, C_DATA, buf); + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + pr_player(player, C_DATA, buf); } void prnf(s_char *buf) { - pr_player(player, C_DATA, buf); + pr_player(player, C_DATA, buf); } /*VARARGS*/ void -pr_id(struct player *p, int id, s_char *format, ...) +pr_id(struct player *p, int id, s_char *format, ...) { - s_char buf[4096]; - va_list ap; - - if (p->curid >= 0) { - io_puts(p->iop, "\n"); - p->curid = -1; - } - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - pr_player(p, id, buf); + s_char buf[4096]; + va_list ap; + + if (p->curid >= 0) { + io_puts(p->iop, "\n"); + p->curid = -1; + } + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + pr_player(p, id, buf); } void -pr_flash(struct player *pl, s_char *format, ...) +pr_flash(struct player *pl, s_char *format, ...) { - s_char buf[4096]; - va_list ap; - - if (pl->state != PS_PLAYING) - return; - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - pr_player(pl, C_FLASH, buf); - io_output(pl->iop, IO_NOWAIT); + s_char buf[4096]; + va_list ap; + + if (pl->state != PS_PLAYING) + return; + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + pr_player(pl, C_FLASH, buf); + io_output(pl->iop, IO_NOWAIT); } void -pr_inform(struct player *pl, s_char *format, ...) +pr_inform(struct player *pl, s_char *format, ...) { - s_char buf[4096]; - va_list ap; - - if (pl->state != PS_PLAYING) - return; - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - pr_player(pl, C_INFORM, buf); - io_output(pl->iop, IO_NOWAIT); + s_char buf[4096]; + va_list ap; + + if (pl->state != PS_PLAYING) + return; + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + pr_player(pl, C_INFORM, buf); + io_output(pl->iop, IO_NOWAIT); } void -pr_wall(s_char *format, ...) +pr_wall(s_char *format, ...) { - s_char buf[4096]; - struct player *p; - va_list ap; - - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - for (p = player_next(0); p; p = player_next(p)) { - if (p->state != PS_PLAYING) - continue; - pr_player(p, C_FLASH, buf); - io_output(p->iop, IO_NOWAIT); - } + s_char buf[4096]; + struct player *p; + va_list ap; + + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + for (p = player_next(0); p; p = player_next(p)) { + if (p->state != PS_PLAYING) + continue; + pr_player(p, C_FLASH, buf); + io_output(p->iop, IO_NOWAIT); + } } void pr_player(struct player *pl, int id, s_char *buf) { - register s_char *p; - register s_char *bp; - register int len; - - bp = buf; - while (*bp != '\0') { - if (pl->curid != -1 && pl->curid != id) { - io_puts (pl->iop, "\n"); - pl->curid = -1; - } - if (pl->curid == -1) { - outid(pl, id); - } - p = index(bp, '\n'); - if (p != 0) { - len = (p - bp) + 1; - if (pl->command && (pl->command->c_flags & C_MOD)) - io_write(pl->iop, bp, len, IO_NOWAIT); - else - io_write(pl->iop, bp, len, IO_WAIT); - bp += len; - pl->curid = -1; - } else { - len = io_puts(pl->iop, bp); - bp += len; - } + register s_char *p; + register s_char *bp; + register int len; + + bp = buf; + while (*bp != '\0') { + if (pl->curid != -1 && pl->curid != id) { + io_puts(pl->iop, "\n"); + pl->curid = -1; } + if (pl->curid == -1) { + outid(pl, id); + } + p = index(bp, '\n'); + if (p != 0) { + len = (p - bp) + 1; + if (pl->command && (pl->command->c_flags & C_MOD)) + io_write(pl->iop, bp, len, IO_NOWAIT); + else + io_write(pl->iop, bp, len, IO_WAIT); + bp += len; + pl->curid = -1; + } else { + len = io_puts(pl->iop, bp); + bp += len; + } + } } /* @@ -183,17 +183,17 @@ pr_player(struct player *pl, int id, s_char *buf) void pr_hilite(s_char *buf) { - register s_char *bp; - register s_char c; - s_char *p; - - p = (s_char *)malloc(strlen(buf) + 1); - strcpy(p, buf); - for (bp=p; 0 != (c = *bp); bp++) - if (isprint(c)) - *bp |= 0x80; - pr(p); - free(p); + register s_char *bp; + register s_char c; + s_char *p; + + p = (s_char *)malloc(strlen(buf) + 1); + strcpy(p, buf); + for (bp = p; 0 != (c = *bp); bp++) + if (isprint(c)) + *bp |= 0x80; + pr(p); + free(p); } /* @@ -202,69 +202,69 @@ pr_hilite(s_char *buf) void outid(struct player *pl, int n) { - s_char c; - s_char buf[3]; - - if (n > C_LAST) { - logerror("outid: %d not valid code\n", n); - return; - } - if (n >= 10) - c = 'a' - 10 + n; - else - c = '0' + n; - buf[0] = c; - buf[1] = ' '; - buf[2] = '\0'; - io_puts(pl->iop, buf); - pl->curid = n; + s_char c; + s_char buf[3]; + + if (n > C_LAST) { + logerror("outid: %d not valid code\n", n); + return; + } + if (n >= 10) + c = 'a' - 10 + n; + else + c = '0' + n; + buf[0] = c; + buf[1] = ' '; + buf[2] = '\0'; + io_puts(pl->iop, buf); + pl->curid = n; } void prredir(s_char *redir) { - pr_id(player, *redir == '>' ? C_REDIR : C_PIPE, "%s\n", redir); + pr_id(player, *redir == '>' ? C_REDIR : C_PIPE, "%s\n", redir); } void prexec(s_char *file) { - pr_id(player, C_EXECUTE, "%s\n", file); + pr_id(player, C_EXECUTE, "%s\n", file); } void prprompt(int min, int btu) { - pr_id(player, C_PROMPT, "%d %d\n", min, btu); + pr_id(player, C_PROMPT, "%d %d\n", min, btu); } void showvers(int vers) { - pr_id(player, C_INIT, "%d\n", vers); + pr_id(player, C_INIT, "%d\n", vers); } int prmptrd(s_char *prompt, s_char *str, int size) { - int r; - - pr_id(player, C_FLUSH, "%s\n", prompt); - if ((r = recvclient(str, size)) < 0) - return r; - time(&player->curup); - if (*str == 0) - return 1; - return strlen(str); + int r; + + pr_id(player, C_FLUSH, "%s\n", prompt); + if ((r = recvclient(str, size)) < 0) + return r; + time(&player->curup); + if (*str == 0) + return 1; + return strlen(str); } void prdate(void) { - time_t now; + time_t now; - (void) time(&now); - pr(ctime(&now)); + (void)time(&now); + pr(ctime(&now)); } /* @@ -273,69 +273,69 @@ prdate(void) void prxy(s_char *format, coord x, coord y, natid country) { - s_char buf[255]; - struct natstr *np; + s_char buf[255]; + struct natstr *np; - np = getnatp(country); - sprintf(buf, format, xrel(np, x), yrel(np, y)); - pr(buf); + np = getnatp(country); + sprintf(buf, format, xrel(np, x), yrel(np, y)); + pr(buf); } /*VARARGS*/ void -PR(int cn, s_char *format, ...) +PR(int cn, s_char *format, ...) { - /* XXX should really do this on a per-nation basis */ - static s_char longline[MAXNOC][512]; - int newline; - va_list ap; - s_char buf[1024]; - - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - newline = strrchr(buf, '\n') ? 1 : 0; - strcat(longline[cn], buf); - if (newline){ - if (update_pending || (cn && cn != player->cnum)) - typed_wu(0, cn, longline[cn], TEL_BULLETIN); - else - pr_player(player, C_DATA, longline[cn]); - longline[cn][0] = '\0'; - } + /* XXX should really do this on a per-nation basis */ + static s_char longline[MAXNOC][512]; + int newline; + va_list ap; + s_char buf[1024]; + + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + newline = strrchr(buf, '\n') ? 1 : 0; + strcat(longline[cn], buf); + if (newline) { + if (update_pending || (cn && cn != player->cnum)) + typed_wu(0, cn, longline[cn], TEL_BULLETIN); + else + pr_player(player, C_DATA, longline[cn]); + longline[cn][0] = '\0'; + } } void PRdate(natid cn) { - time_t now; + time_t now; - (void) time(&now); - PR(cn, ctime(&now)); + (void)time(&now); + PR(cn, ctime(&now)); } void pr_beep(void) { - struct natstr *np = getnatp(player->cnum); + struct natstr *np = getnatp(player->cnum); - if (np->nat_flags & NF_BEEP) - pr("\07"); + if (np->nat_flags & NF_BEEP) + pr("\07"); } void -mpr(int cn, s_char *format, ...) +mpr(int cn, s_char *format, ...) { - s_char buf[4096]; - va_list ap; - - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - if (cn) { - if (update_pending || cn != player->cnum) - typed_wu(0, cn, buf, TEL_BULLETIN); - else - pr_player(player, C_DATA, buf); - } + s_char buf[4096]; + va_list ap; + + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + if (cn) { + if (update_pending || cn != player->cnum) + typed_wu(0, cn, buf, TEL_BULLETIN); + else + pr_player(player, C_DATA, buf); + } } diff --git a/src/lib/subs/radmap.c b/src/lib/subs/radmap.c index d2eec4724..9c45fb7d3 100644 --- a/src/lib/subs/radmap.c +++ b/src/lib/subs/radmap.c @@ -47,168 +47,162 @@ void radmap(int cx, int cy, int eff, int range, double seesub) { - radmap2(player->cnum, cx, cy, eff, range, seesub, 1); + radmap2(player->cnum, cx, cy, eff, range, seesub, 1); } void radmapnopr(int cx, int cy, int eff, int range, double seesub) { - radmap2(player->cnum, cx, cy, eff, range, seesub, 0); + radmap2(player->cnum, cx, cy, eff, range, seesub, 0); } void radmapupd(int own, int cx, int cy, int eff, int range, double seesub) { - radmap2(own, cx, cy, eff, range, seesub, 0); + radmap2(own, cx, cy, eff, range, seesub, 0); } /* More dynamic world sized buffers. We create 'em once, and then * never again. No need to keep creating/tearint apart. We may * want to do this in other places too where it doesn't matter. */ -static s_char **rad; -static s_char *radbuf; -static s_char **vis; -static s_char *visbuf; +static s_char **rad; +static s_char *radbuf; +static s_char **vis; +static s_char *visbuf; void radmap2(int owner, - int cx, - int cy, - int eff, - int range, - double seesub, - int pr_flag) + int cx, int cy, int eff, int range, double seesub, int pr_flag) { - int rng; - struct sctstr sect; - struct shpstr ship; - struct plnstr plane; - struct nstr_sect ns; - struct nstr_item ni; - int x, y; - int row; - int n; - int changed = 0; - - if (!radbuf) - radbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * - sizeof(s_char)); - if (!visbuf) - visbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * - sizeof(s_char)); - if (!rad) { - rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (rad && radbuf) { - for (x = 0; x < WORLD_Y; x++) - rad[x] = &radbuf[(WORLD_X + 1) * x]; - } + int rng; + struct sctstr sect; + struct shpstr ship; + struct plnstr plane; + struct nstr_sect ns; + struct nstr_item ni; + int x, y; + int row; + int n; + int changed = 0; + + if (!radbuf) + radbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * + sizeof(s_char)); + if (!visbuf) + visbuf = (s_char *)malloc((WORLD_Y * (WORLD_X + 1)) * + sizeof(s_char)); + if (!rad) { + rad = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (rad && radbuf) { + for (x = 0; x < WORLD_Y; x++) + rad[x] = &radbuf[(WORLD_X + 1) * x]; } - if (!vis) { - vis = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); - if (vis && visbuf) { - for (x = 0; x < WORLD_Y; x++) - vis[x] = &visbuf[(WORLD_X + 1) * x]; - } + } + if (!vis) { + vis = (s_char **)malloc(WORLD_Y * sizeof(s_char *)); + if (vis && visbuf) { + for (x = 0; x < WORLD_Y; x++) + vis[x] = &visbuf[(WORLD_X + 1) * x]; } - if (!radbuf || !visbuf || !rad || !vis) { - pr("Memory error in radmap2, tell the deity.\n"); - return; + } + if (!radbuf || !visbuf || !rad || !vis) { + pr("Memory error in radmap2, tell the deity.\n"); + return; + } + + bzero((s_char *)visbuf, (WORLD_Y * (WORLD_X + 1))); + range = (int)(range * (eff / 100.0)); + if (range < 1) + range = 1; + if (pr_flag) + pr("%s efficiency %d%%, max range %d\n", + xyas(cx, cy, owner), eff, range); + snxtsct_dist(&ns, cx, cy, range); + blankfill((s_char *)radbuf, &ns.range, 1); + while (nxtsct(&ns, §)) { + if (sect.sct_own == owner || + (sect.sct_type <= SCT_RURAL && sect.sct_type != SCT_SANCT) + || ns.curdist <= range / 3) + rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; + else + rad[ns.dy][ns.dx] = '?'; + changed += map_set(owner, ns.x, ns.y, rad[ns.dy][ns.dx], 0); + } + if (changed) + writemap(owner); + if (!pr_flag) + return; + snxtitem_dist(&ni, EF_PLANE, cx, cy, range); + while (nxtitem(&ni, (caddr_t)&plane)) { + if (plane.pln_own == 0) + continue; + /* Used to have 'ghosts' when scanning whole world --ts */ + x = deltx(&ns.range, (int)plane.pln_x); + y = delty(&ns.range, (int)plane.pln_y); + + if ((plane.pln_flags & PLN_LAUNCHED) && plane.pln_own != owner) { + vis[y][x] = (s_char)100; + rad[y][x] = '$'; } - - bzero((s_char *)visbuf, (WORLD_Y * (WORLD_X + 1))); - range = (int) (range * (eff / 100.0)); - if (range < 1) - range = 1; - if (pr_flag) - pr("%s efficiency %d%%, max range %d\n", - xyas(cx, cy, owner), eff, range); - snxtsct_dist(&ns, cx, cy, range); - blankfill((s_char *)radbuf, &ns.range, 1); - while (nxtsct(&ns, §)) { - if (sect.sct_own == owner || - (sect.sct_type <= SCT_RURAL && sect.sct_type != SCT_SANCT) - || ns.curdist <= range/3) - rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; - else - rad[ns.dy][ns.dx] = '?'; - changed += map_set(owner, ns.x, ns.y, rad[ns.dy][ns.dx],0); - } - if (changed) - writemap(owner); - if (!pr_flag) - return; - snxtitem_dist(&ni, EF_PLANE, cx, cy, range); - while (nxtitem(&ni, (caddr_t)&plane)) { - if (plane.pln_own == 0) - continue; - /* Used to have 'ghosts' when scanning whole world --ts */ - x = deltx(&ns.range,(int)plane.pln_x); - y = delty(&ns.range,(int)plane.pln_y); - - if ((plane.pln_flags & PLN_LAUNCHED) && - plane.pln_own != owner) { - vis[y][x] = (s_char) 100; - rad[y][x] = '$'; - } - } - snxtitem_dist(&ni, EF_SHIP, cx, cy, range); - while (nxtitem(&ni, (caddr_t)&ship)) { - if (ship.shp_own == 0) - continue; - /* Used to have 'ghosts' when scanning whole world --ts */ - x = deltx(&ns.range,(int)ship.shp_x); - y = delty(&ns.range,(int)ship.shp_y); - - rng = (int) (range * ship.shp_visib / 20.0); - if (ni.curdist > rng) - continue; - if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && - ni.curdist > rng * seesub) - continue; - if (ship.shp_visib > vis[y][x]) { - vis[y][x] = ship.shp_visib; - /* &~0x20 makes it a cap letter */ - rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; - } + } + snxtitem_dist(&ni, EF_SHIP, cx, cy, range); + while (nxtitem(&ni, (caddr_t)&ship)) { + if (ship.shp_own == 0) + continue; + /* Used to have 'ghosts' when scanning whole world --ts */ + x = deltx(&ns.range, (int)ship.shp_x); + y = delty(&ns.range, (int)ship.shp_y); + + rng = (int)(range * ship.shp_visib / 20.0); + if (ni.curdist > rng) + continue; + if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && + ni.curdist > rng * seesub) + continue; + if (ship.shp_visib > vis[y][x]) { + vis[y][x] = ship.shp_visib; + /* &~0x20 makes it a cap letter */ + rad[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; } - /* - * make the center of the display 0 - * so ve et al can find it. - */ - rad[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx)] = '0'; - /* won't work for radar maps > WORLD_Y/2 */ + } + /* + * make the center of the display 0 + * so ve et al can find it. + */ + rad[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx)] = '0'; + /* won't work for radar maps > WORLD_Y/2 */ #ifdef HAY - /* This is not correct for small, hitech worlds. */ - n = deltay(ns.range.hy, ns.range.ly); + /* This is not correct for small, hitech worlds. */ + n = deltay(ns.range.hy, ns.range.ly); #else - /* This is already available, so why not use it. */ - n = ns.range.height; + /* This is already available, so why not use it. */ + n = ns.range.height; #endif - for (row=0; row < n; row++) - pr("%s\n", rad[row]); - pr("\n"); + for (row = 0; row < n; row++) + pr("%s\n", rad[row]); + pr("\n"); } int deltx(struct range *r, coord x) { - if (r->lx < r->hx) - return x-r->lx; + if (r->lx < r->hx) + return x - r->lx; - if (x >= r->lx) - return x-r->lx; + if (x >= r->lx) + return x - r->lx; - return x+WORLD_X-r->lx; + return x + WORLD_X - r->lx; } int delty(struct range *r, coord y) { - if (r->ly < r->hy) - return y-r->ly; + if (r->ly < r->hy) + return y - r->ly; - if (y >= r->ly) - return y-r->ly; + if (y >= r->ly) + return y - r->ly; - return y+WORLD_Y-r->ly; + return y + WORLD_Y - r->ly; } diff --git a/src/lib/subs/rej.c b/src/lib/subs/rej.c index 31ba58ef9..94472b68b 100644 --- a/src/lib/subs/rej.c +++ b/src/lib/subs/rej.c @@ -45,123 +45,125 @@ extern int update_pending; int setrel(natid us, natid them, int rel) { - struct natstr *mynp; - struct natstr *themnp; - s_char *myname = cname(us); - s_char *themname; - int oldrel; - s_char *whichway; - int n_up = 0; - int n_down = 0; - s_char *addendum = 0; - int theirrel; - extern int War_Cost; + struct natstr *mynp; + struct natstr *themnp; + s_char *myname = cname(us); + s_char *themname; + int oldrel; + s_char *whichway; + int n_up = 0; + int n_down = 0; + s_char *addendum = 0; + int theirrel; + extern int War_Cost; - if (rel < AT_WAR) - rel = AT_WAR; - if (rel > ALLIED) - rel = ALLIED; - if (!(mynp = getnatp(us))) - return RET_FAIL; - if (!(themnp = getnatp(them))) - return RET_FAIL; - if ((oldrel = getrel(mynp, them)) == rel) - return RET_FAIL; - themname = cname(them); - if (rel > oldrel) - whichway = "upgraded"; - else - whichway = "downgraded"; - if (rel == ALLIED) { - addendum = "Congratulations!"; - n_up = N_DECL_ALLY; - } else if (rel == FRIENDLY) { - n_up = N_UP_FRIENDLY; - n_down = N_DOWN_FRIENDLY; - } else if (rel == NEUTRAL) { - n_up = N_UP_NEUTRAL; - n_down = N_DOWN_NEUTRAL; - } else if (rel == HOSTILE) { - addendum = "Another cold war..."; - n_up = N_UP_HOSTILE; - n_down = N_DOWN_HOSTILE; - } else if (rel < HOSTILE) { - if (opt_SLOW_WAR) { - struct natstr *natp2; - double cost; + if (rel < AT_WAR) + rel = AT_WAR; + if (rel > ALLIED) + rel = ALLIED; + if (!(mynp = getnatp(us))) + return RET_FAIL; + if (!(themnp = getnatp(them))) + return RET_FAIL; + if ((oldrel = getrel(mynp, them)) == rel) + return RET_FAIL; + themname = cname(them); + if (rel > oldrel) + whichway = "upgraded"; + else + whichway = "downgraded"; + if (rel == ALLIED) { + addendum = "Congratulations!"; + n_up = N_DECL_ALLY; + } else if (rel == FRIENDLY) { + n_up = N_UP_FRIENDLY; + n_down = N_DOWN_FRIENDLY; + } else if (rel == NEUTRAL) { + n_up = N_UP_NEUTRAL; + n_down = N_DOWN_NEUTRAL; + } else if (rel == HOSTILE) { + addendum = "Another cold war..."; + n_up = N_UP_HOSTILE; + n_down = N_DOWN_HOSTILE; + } else if (rel < HOSTILE) { + if (opt_SLOW_WAR) { + struct natstr *natp2; + double cost; - if (!player->god) { - natp2 = themnp; - theirrel = getrel(natp2,us); - if (theirrel <= MOBILIZATION) { - rel = theirrel; - cost = 0; - } else if (us == player->cnum && !update_pending) { - if (mynp->nat_money < War_Cost){ - mpr(us, "You don't have the money!\n"); - return RET_FAIL; - } - rel = MOBILIZATION; - cost = War_Cost; - } else { /* nreport is forcing us to decl war */ - return RET_FAIL; - } - if (rel >= oldrel) { - if (us == player->cnum && !update_pending) - mpr(us, "No change required for that!\n"); - return RET_FAIL; - } - player->dolcost += cost; + if (!player->god) { + natp2 = themnp; + theirrel = getrel(natp2, us); + if (theirrel <= MOBILIZATION) { + rel = theirrel; + cost = 0; + } else if (us == player->cnum && !update_pending) { + if (mynp->nat_money < War_Cost) { + mpr(us, "You don't have the money!\n"); + return RET_FAIL; + } + rel = MOBILIZATION; + cost = War_Cost; + } else { /* nreport is forcing us to decl war */ + return RET_FAIL; + } + if (rel >= oldrel) { + if (us == player->cnum && !update_pending) + mpr(us, "No change required for that!\n"); + return RET_FAIL; } - } - addendum = "Declaration made (give 'em hell)."; - n_down = N_DECL_WAR; + player->dolcost += cost; + } } + addendum = "Declaration made (give 'em hell)."; + n_down = N_DECL_WAR; + } - if (addendum && us == player->cnum && !update_pending) - pr("%s\n", addendum); - mpr(us, "Diplomatic relations with %s %s to \"%s\".\n", themname, whichway, relates[rel]); - if(!(getrejects(us, themnp) & REJ_TELE)) - mpr(them, - "Country %s (#%d) has %s their relations with you to \"%s\"!\n", myname, us, whichway, relates[rel]); + if (addendum && us == player->cnum && !update_pending) + pr("%s\n", addendum); + mpr(us, "Diplomatic relations with %s %s to \"%s\".\n", themname, + whichway, relates[rel]); + if (!(getrejects(us, themnp) & REJ_TELE)) + mpr(them, + "Country %s (#%d) has %s their relations with you to \"%s\"!\n", + myname, us, whichway, relates[rel]); - putrel(mynp, them, rel); - putnat(mynp); + putrel(mynp, them, rel); + putnat(mynp); - if (!player->god) { - if (oldrel == ALLIED) - nreport(us, N_DIS_ALLY, them, 1); - else if (oldrel < HOSTILE && rel >= HOSTILE) - nreport(us, N_DIS_WAR, them, 1); - if (rel > oldrel) - nreport(us, n_up, them, 1); - else - nreport(us, n_down, them, 1); - } + if (!player->god) { + if (oldrel == ALLIED) + nreport(us, N_DIS_ALLY, them, 1); + else if (oldrel < HOSTILE && rel >= HOSTILE) + nreport(us, N_DIS_WAR, them, 1); + if (rel > oldrel) + nreport(us, n_up, them, 1); + else + nreport(us, n_down, them, 1); + } - return RET_OK; + return RET_OK; } int setcont(natid us, natid them, int contact) { - struct natstr *np; + struct natstr *np; - if ((np = getnatp(us)) == 0) - return 0; - putcontact(np, them, contact); - putnat(np); - return 1; + if ((np = getnatp(us)) == 0) + return 0; + putcontact(np, them, contact); + putnat(np); + return 1; } int setrej(natid us, natid them, int how, int what) { - struct natstr *np; + struct natstr *np; - if ((np = getnatp(us)) == 0) - return 0; - putreject(np, them, how, what); - putnat(np); - return 1; + if ((np = getnatp(us)) == 0) + return 0; + putreject(np, them, how, what); + putnat(np); + return 1; } diff --git a/src/lib/subs/retreat.c b/src/lib/subs/retreat.c index 9d4a6d4cd..ec47c80f3 100644 --- a/src/lib/subs/retreat.c +++ b/src/lib/subs/retreat.c @@ -51,517 +51,532 @@ #include "prototypes.h" #include "optlist.h" -struct ccode{ - s_char code; - s_char *desc[2]; +struct ccode { + s_char code; + s_char *desc[2]; } conditions[] = { - { 'i', { - "retreated with a damaged friend", - "was damaged", - }, }, - { 't', { - "retreated with a torpedoed ship", - "was hit by a torpedo", - }, }, - { 's', { - "retreated with a ship scared by sonar", - "detected a sonar ping", - }, }, - { 'h', { - "retreated with a helpless ship", - "was fired upon with no one able to defend it", - }, }, - { 'b', { - "retreated with a bombed friend", - "was bombed", - }, }, - { 'd', { - "retreated with a depth-charged ship", - "was depth-charged", - }, }, - { 'u', { - "retreated with a boared ship", - "was boarded", - }, }, - { 0, {"",""} }, -}; + { + 'i', { + "retreated with a damaged friend", "was damaged",},}, { + 't', { + "retreated with a torpedoed ship", "was hit by a torpedo",},}, { + 's', { + "retreated with a ship scared by sonar", + "detected a sonar ping",},}, { + 'h', { + "retreated with a helpless ship", + "was fired upon with no one able to defend it",},}, { + 'b', { + "retreated with a bombed friend", "was bombed",},}, { + 'd', { + "retreated with a depth-charged ship", "was depth-charged",},}, { + 'u', { + "retreated with a boared ship", "was boarded",},}, { + 0, { +"", ""}},}; int check_retreat_and_do_shipdamage(struct shpstr *sp, int dam) { - if (dam <=0) - return 0; + if (dam <= 0) + return 0; - shipdamage(sp,dam); - if (sp->shp_rflags & RET_INJURED) - retreat_ship(sp, 'i'); + shipdamage(sp, dam); + if (sp->shp_rflags & RET_INJURED) + retreat_ship(sp, 'i'); - return 1; + return 1; } void retreat_ship(struct shpstr *sp, s_char code) { - struct nstr_item ni; - struct shpstr ship; - s_char buf[2]; - - if (sp->shp_rflags & RET_GROUP){ - bzero(buf,2); - buf[0] = sp->shp_fleet; - snxtitem(&ni, EF_SHIP, buf); - while(nxtitem(&ni,(s_char *)&ship)) - if ((ship.shp_fleet == buf[0]) && - (ship.shp_own == sp->shp_own)) { - if (ship.shp_uid == sp->shp_uid){ - retreat_ship1(sp,code,1); - if (sp->shp_rpath[0] == 0) - sp->shp_rflags = 0; - } else { - retreat_ship1(&ship,code,0); - getship(ship.shp_uid,&ship); - if (ship.shp_rpath[0] == 0){ - ship.shp_rflags = 0; - putship(ship.shp_uid,&ship); - } - } - } - } else { - retreat_ship1(sp,code,1); - if (sp->shp_rpath[0] == 0) + struct nstr_item ni; + struct shpstr ship; + s_char buf[2]; + + if (sp->shp_rflags & RET_GROUP) { + bzero(buf, 2); + buf[0] = sp->shp_fleet; + snxtitem(&ni, EF_SHIP, buf); + while (nxtitem(&ni, (s_char *)&ship)) + if ((ship.shp_fleet == buf[0]) && + (ship.shp_own == sp->shp_own)) { + if (ship.shp_uid == sp->shp_uid) { + retreat_ship1(sp, code, 1); + if (sp->shp_rpath[0] == 0) sp->shp_rflags = 0; - } + } else { + retreat_ship1(&ship, code, 0); + getship(ship.shp_uid, &ship); + if (ship.shp_rpath[0] == 0) { + ship.shp_rflags = 0; + putship(ship.shp_uid, &ship); + } + } + } + } else { + retreat_ship1(sp, code, 1); + if (sp->shp_rpath[0] == 0) + sp->shp_rflags = 0; + } } int retreat_ship1(struct shpstr *sp, s_char code, int orig) - - - /* Is this the originally scared ship, or a follower */ + + + /* Is this the originally scared ship, or a follower */ { - extern double techfact(int, double); - struct sctstr sect; - register int n; - register int m; - int max; - int dir; - coord newx; - coord newy; - coord dx; - coord dy; - int stopping; - int mines; - int shells; - double mobcost; - struct mchrstr *mcp; - int vec[I_MAX+1]; - int time_to_stop; - s_char buf[RET_LEN-1]; - - sp->shp_mission = 0; - if (sp->shp_own == 0) - return 0; - - if (isupper(code)) - code = tolower(code); - - n = 0; - if (sp->shp_effic < SHIP_MINEFF){ - wu(0, sp->shp_own, "%s %s,\nbut it died in the attack, and so couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; + extern double techfact(int, double); + struct sctstr sect; + register int n; + register int m; + int max; + int dir; + coord newx; + coord newy; + coord dx; + coord dy; + int stopping; + int mines; + int shells; + double mobcost; + struct mchrstr *mcp; + int vec[I_MAX + 1]; + int time_to_stop; + s_char buf[RET_LEN - 1]; + + sp->shp_mission = 0; + if (sp->shp_own == 0) + return 0; + + if (isupper(code)) + code = tolower(code); + + n = 0; + if (sp->shp_effic < SHIP_MINEFF) { + wu(0, sp->shp_own, + "%s %s,\nbut it died in the attack, and so couldn't retreat!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; + } + + if (opt_SAIL) { + /* can't retreat a ship that's sailin, bad things happend */ + if (*sp->shp_path) { + wu(0, sp->shp_own, + "%s %s,\nbut had sailing orders, and couldn't retreat!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; } - - if (opt_SAIL) { - /* can't retreat a ship that's sailin, bad things happend */ - if (*sp->shp_path){ - wu(0, sp->shp_own, "%s %s,\nbut had sailing orders, and couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; - } + } + /* check crew - uws don't count */ + getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); + if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0) { + wu(0, sp->shp_own, + "%s %s,\nbut had no crew, and couldn't retreat!\n", prship(sp), + conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; + } + + getsect(sp->shp_x, sp->shp_y, §); + switch (check_nav(§)) { + case CN_CONSTRUCTION: + wu(0, sp->shp_own, + "%s %s,\nbut was caught in a construction zone, and couldn't retreat!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; + case CN_LANDLOCKED: + wu(0, sp->shp_own, + "%s %s,\nbut was landlocked, and couldn't retreat!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; + /*NOTREACHED*/ + case CN_NAVIGABLE: + break; + case CN_ERROR: + default: + wu(0, sp->shp_own, + "%s %s,\nbut was subject to an empire error, and couldn't retreat!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; + /*NOTREACHED*/ + } + + if (sp->shp_mobil <= 0.0) { + wu(0, sp->shp_own, + "%s %s,\nbut had no mobility, and couldn't retreat!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; + } + + n = (-1 * MAX_RETREAT); + stopping = 0; + time_to_stop = 0; + while ((!stopping) && n) { + dx = dy = 0; + if (sp->shp_rpath[0] == 0 || sp->shp_rpath[0] == 0) { + stopping = 1; + continue; } - /* check crew - uws don't count */ - getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); - if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0){ - wu(0, sp->shp_own, "%s %s,\nbut had no crew, and couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; + if (sp->shp_mobil <= 0.0) { + wu(0, sp->shp_own, + "%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n", + prship(sp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putship(sp->shp_uid, sp); + return 0; } - - getsect(sp->shp_x,sp->shp_y,§); - switch (check_nav(§)) { - case CN_CONSTRUCTION: - wu(0, sp->shp_own, "%s %s,\nbut was caught in a construction zone, and couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; - case CN_LANDLOCKED: - wu(0, sp->shp_own, "%s %s,\nbut was landlocked, and couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; - /*NOTREACHED*/ - case CN_NAVIGABLE: - break; - case CN_ERROR: - default: - wu(0, sp->shp_own, "%s %s,\nbut was subject to an empire error, and couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; - /*NOTREACHED*/ + dir = chkdir(sp->shp_rpath[0], DIR_STOP, DIR_VIEW); + bzero(buf, RET_LEN - 1); + bcopy(&sp->shp_rpath[1], buf, RET_LEN - 1); + bzero(sp->shp_rpath, RET_LEN); + bcopy(buf, sp->shp_rpath, RET_LEN - 1); + if (dir == -1) + continue; + if (dir == DIR_STOP) + stopping++; + else { + dx = diroff[dir][0]; + dy = diroff[dir][1]; } - - if (sp->shp_mobil <= 0.0) { - wu(0, sp->shp_own, "%s %s,\nbut had no mobility, and couldn't retreat!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; + n++; + + mcp = &mchr[(int)sp->shp_type]; + newx = xnorm(sp->shp_x + dx); + newy = ynorm(sp->shp_y + dy); + mobcost = sp->shp_effic * 0.01 * sp->shp_speed; + mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost)); + + getsect(newx, newy, §); + if (check_nav(§) != CN_NAVIGABLE || + (sect.sct_own && !player->owner && + getrel(getnatp(sect.sct_own), sp->shp_own) < FRIENDLY)) { + wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n", + prship(sp), conditions[findcondition(code)].desc[orig], + xyas(newx, newy, sp->shp_own)); + if (!orig) + putship(sp->shp_uid, sp); + return 0; } - - n=(-1*MAX_RETREAT); - stopping = 0; - time_to_stop = 0; - while ((!stopping) && n){ - dx = dy = 0; - if (sp->shp_rpath[0] == 0 || sp->shp_rpath[0] == 0){ - stopping=1; - continue; - } - if (sp->shp_mobil <= 0.0) { - wu(0, sp->shp_own, "%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n", prship(sp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putship(sp->shp_uid,sp); - return 0; - } - dir = chkdir(sp->shp_rpath[0], DIR_STOP, DIR_VIEW); - bzero(buf,RET_LEN-1); - bcopy(&sp->shp_rpath[1],buf,RET_LEN-1); - bzero(sp->shp_rpath,RET_LEN); - bcopy(buf,sp->shp_rpath,RET_LEN-1); - if (dir == -1) - continue; - if (dir == DIR_STOP) - stopping++; - else { - dx = diroff[dir][0]; - dy = diroff[dir][1]; - } - n++; - - mcp = &mchr[(int)sp->shp_type]; - newx = xnorm(sp->shp_x + dx); - newy = ynorm(sp->shp_y + dy); - mobcost = sp->shp_effic * 0.01 * sp->shp_speed; - mobcost = 480.0 / (mobcost + techfact(sp->shp_tech, mobcost)); - - getsect(newx, newy, §); - if (check_nav(§) != CN_NAVIGABLE || - (sect.sct_own && !player->owner && - getrel(getnatp(sect.sct_own), sp->shp_own) < FRIENDLY)) { - wu(0, sp->shp_own, "%s %s,\nbut could not retreat to %s!\n", prship(sp), - conditions[findcondition(code)].desc[orig], - xyas(newx, newy, sp->shp_own)); - if (!orig) putship(sp->shp_uid,sp); - return 0; + sp->shp_x = newx; + sp->shp_y = newy; + sp->shp_mobil -= mobcost; + if (stopping) + continue; + + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + if ((mcp->m_flags & M_SWEEP) && mines > 0 && !player->owner) { + max = vl_find(V_SHELL, mcp->m_vtype, + mcp->m_vamt, (int)mcp->m_nv); + shells = getvar(V_SHELL, (s_char *)sp, EF_SHIP); + for (m = 0; mines > 0 && m < 5; m++) { + if (chance(0.66)) { + mines--; + shells = min(max, shells + 1); } - sp->shp_x = newx; - sp->shp_y = newy; - sp->shp_mobil -= mobcost; - if (stopping) - continue; - - mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); - if ((mcp->m_flags & M_SWEEP) && mines > 0 && !player->owner) { - max = vl_find(V_SHELL, mcp->m_vtype, - mcp->m_vamt, (int) mcp->m_nv); - shells = getvar(V_SHELL, (s_char *)sp, EF_SHIP); - for (m=0; mines > 0 && m < 5; m++) { - if (chance(0.66)) { - mines--; - shells = min(max, shells + 1); - } - } - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putvar(V_SHELL, shells, (s_char *)sp, EF_SHIP); - putsect(§); - } - if (mines > 0 && !player->owner && - chance(DMINE_HITCHANCE(mines))) { - wu(0, sp->shp_own, "%s %s,\nand hit a mine in %s while retreating!\n", prship(sp), - conditions[findcondition(code)].desc[orig], - xyas(newx, newy, sp->shp_own)); - nreport(sp->shp_own, N_HIT_MINE, 0, 1); - m = MINE_DAMAGE(); - shipdamage(sp, m); - mines--; - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putsect(§); - if (sp->shp_effic < SHIP_MINEFF) - time_to_stop = 1; - if (!orig) putship(sp->shp_uid,sp); - return 0; - } - if (time_to_stop) - stopping = 1; + } + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putvar(V_SHELL, shells, (s_char *)sp, EF_SHIP); + putsect(§); } - - if (orig) { - wu(0, sp->shp_own, "%s %s, and retreated to %s\n", prship(sp), - conditions[findcondition(code)].desc[orig], - xyas(sp->shp_x, sp->shp_y, sp->shp_own)); - }else{ - wu(0, sp->shp_own, "%s %s, and ended up at %s\n", - prship(sp), - conditions[findcondition(code)].desc[orig], - xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + if (mines > 0 && !player->owner && chance(DMINE_HITCHANCE(mines))) { + wu(0, sp->shp_own, + "%s %s,\nand hit a mine in %s while retreating!\n", + prship(sp), conditions[findcondition(code)].desc[orig], + xyas(newx, newy, sp->shp_own)); + nreport(sp->shp_own, N_HIT_MINE, 0, 1); + m = MINE_DAMAGE(); + shipdamage(sp, m); + mines--; + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putsect(§); + if (sp->shp_effic < SHIP_MINEFF) + time_to_stop = 1; + if (!orig) + putship(sp->shp_uid, sp); + return 0; } - if (!orig) putship(sp->shp_uid,sp); - return 1; + if (time_to_stop) + stopping = 1; + } + + if (orig) { + wu(0, sp->shp_own, "%s %s, and retreated to %s\n", prship(sp), + conditions[findcondition(code)].desc[orig], + xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + } else { + wu(0, sp->shp_own, "%s %s, and ended up at %s\n", + prship(sp), + conditions[findcondition(code)].desc[orig], + xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + } + if (!orig) + putship(sp->shp_uid, sp); + return 1; } #if 0 -static int +static int check_nav(sect) - struct sctstr *sect; +struct sctstr *sect; { - extern struct dchrstr dchr[]; - - switch (dchr[sect->sct_type].d_flg & 03) { - case NAVOK: - break; - - case NAV_02: - if (sect->sct_effic < 2) - return CN_CONSTRUCTION; - break; - case NAV_60: - if (sect->sct_effic < 60) - return CN_CONSTRUCTION; - break; - default: - return CN_LANDLOCKED; - } - return CN_NAVIGABLE; + extern struct dchrstr dchr[]; + + switch (dchr[sect->sct_type].d_flg & 03) { + case NAVOK: + break; + + case NAV_02: + if (sect->sct_effic < 2) + return CN_CONSTRUCTION; + break; + case NAV_60: + if (sect->sct_effic < 60) + return CN_CONSTRUCTION; + break; + default: + return CN_LANDLOCKED; + } + return CN_NAVIGABLE; } #endif int findcondition(s_char code) { - int x; + int x; - x=0; - while (conditions[x].code){ - if (conditions[x].code == code) - return(x); - x++; - } + x = 0; + while (conditions[x].code) { + if (conditions[x].code == code) + return (x); + x++; + } - return(x); + return (x); } int check_retreat_and_do_landdamage(struct lndstr *lp, int dam) { - if (dam <=0) - return 0; + if (dam <= 0) + return 0; - landdamage(lp,dam); - if (lp->lnd_rflags & RET_INJURED) - retreat_land(lp, 'i'); + landdamage(lp, dam); + if (lp->lnd_rflags & RET_INJURED) + retreat_land(lp, 'i'); - return 1; + return 1; } void retreat_land(struct lndstr *lp, s_char code) { - struct nstr_item ni; - struct lndstr land; - s_char buf[2]; - - if (lp->lnd_rflags & RET_GROUP){ - bzero(buf,2); - buf[0] = lp->lnd_army; - snxtitem(&ni, EF_SHIP, buf); - while(nxtitem(&ni,(s_char *)&land)) - if ((land.lnd_army == buf[0]) && - (land.lnd_own == lp->lnd_own)) { - if (land.lnd_uid == lp->lnd_uid){ - retreat_land1(lp,code,1); - if (lp->lnd_rpath[0] == 0) - lp->lnd_rflags = 0; - }else{ - retreat_land1(&land,code,0); - getland(land.lnd_uid,&land); - if (land.lnd_rpath[0] == 0){ - land.lnd_rflags = 0; - putland(land.lnd_uid,&land); - } - } - } - }else{ - retreat_land1(lp,code,1); - if (lp->lnd_rpath[0] == 0) + struct nstr_item ni; + struct lndstr land; + s_char buf[2]; + + if (lp->lnd_rflags & RET_GROUP) { + bzero(buf, 2); + buf[0] = lp->lnd_army; + snxtitem(&ni, EF_SHIP, buf); + while (nxtitem(&ni, (s_char *)&land)) + if ((land.lnd_army == buf[0]) && (land.lnd_own == lp->lnd_own)) { + if (land.lnd_uid == lp->lnd_uid) { + retreat_land1(lp, code, 1); + if (lp->lnd_rpath[0] == 0) lp->lnd_rflags = 0; - } + } else { + retreat_land1(&land, code, 0); + getland(land.lnd_uid, &land); + if (land.lnd_rpath[0] == 0) { + land.lnd_rflags = 0; + putland(land.lnd_uid, &land); + } + } + } + } else { + retreat_land1(lp, code, 1); + if (lp->lnd_rpath[0] == 0) + lp->lnd_rflags = 0; + } } int retreat_land1(struct lndstr *lp, s_char code, int orig) - - - /* Is this the originally scared unit, or a follower */ -{ - extern double techfact(int, double); - struct sctstr sect; - register int n; - register int m; - int max; - int dir; - coord newx; - coord newy; - coord dx; - coord dy; - int stopping; - int mines; - int shells; - double mobcost; - struct lchrstr *lcp; - int time_to_stop; - s_char buf[RET_LEN-1]; - - lp->lnd_mission = 0; - if (lp->lnd_own == 0) - return 0; - - if (isupper(code)) - code = tolower(code); - - n = 0; - if (lp->lnd_effic < LAND_MINEFF){ - wu(0, lp->lnd_own, "%s %s,\nbut it died in the attack, and so couldn't retreat!\n", prland(lp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putland(lp->lnd_uid,lp); - return 0; - } - getsect(lp->lnd_x,lp->lnd_y,§); + /* Is this the originally scared unit, or a follower */ +{ + extern double techfact(int, double); + struct sctstr sect; + register int n; + register int m; + int max; + int dir; + coord newx; + coord newy; + coord dx; + coord dy; + int stopping; + int mines; + int shells; + double mobcost; + struct lchrstr *lcp; + int time_to_stop; + s_char buf[RET_LEN - 1]; + + lp->lnd_mission = 0; + if (lp->lnd_own == 0) + return 0; + + if (isupper(code)) + code = tolower(code); + + n = 0; + if (lp->lnd_effic < LAND_MINEFF) { + wu(0, lp->lnd_own, + "%s %s,\nbut it died in the attack, and so couldn't retreat!\n", + prland(lp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putland(lp->lnd_uid, lp); + return 0; + } + + getsect(lp->lnd_x, lp->lnd_y, §); + + if (lp->lnd_mobil <= 0.0) { + wu(0, lp->lnd_own, + "%s %s,\nbut had no mobility, and couldn't retreat!\n", + prland(lp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putland(lp->lnd_uid, lp); + return 0; + } + + n = (-1 * MAX_RETREAT); + stopping = 0; + time_to_stop = 0; + while ((!stopping) && n) { + dx = dy = 0; + if (lp->lnd_rpath[0] == 0 || lp->lnd_rpath[0] == 0) { + stopping = 1; + continue; + } if (lp->lnd_mobil <= 0.0) { - wu(0, lp->lnd_own, "%s %s,\nbut had no mobility, and couldn't retreat!\n", - prland(lp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putland(lp->lnd_uid,lp); - return 0; + wu(0, lp->lnd_own, + "%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n", + prland(lp), conditions[findcondition(code)].desc[orig]); + if (!orig) + putland(lp->lnd_uid, lp); + return 0; } - - n=(-1*MAX_RETREAT); - stopping = 0; - time_to_stop = 0; - while ((!stopping) && n){ - dx = dy = 0; - if (lp->lnd_rpath[0] == 0 || lp->lnd_rpath[0] == 0){ - stopping=1; - continue; - } - if (lp->lnd_mobil <= 0.0) { - wu(0, lp->lnd_own, "%s %s,\nbut ran out of mobility, and couldn't retreat fully!\n", - prland(lp), - conditions[findcondition(code)].desc[orig]); - if (!orig) putland(lp->lnd_uid,lp); - return 0; - } - dir = chkdir(lp->lnd_rpath[0], DIR_STOP, DIR_VIEW); - bzero(buf,RET_LEN-1); - bcopy(&lp->lnd_rpath[1],buf,RET_LEN-1); - bzero(lp->lnd_rpath,RET_LEN); - bcopy(buf,lp->lnd_rpath,RET_LEN-1); - if (dir == -1) - continue; - if (dir == DIR_STOP) - stopping++; - else { - dx = diroff[dir][0]; - dy = diroff[dir][1]; - } - n++; - - lcp = &lchr[(int)lp->lnd_type]; - newx = xnorm(lp->lnd_x + dx); - newy = ynorm(lp->lnd_y + dy); - - getsect(newx, newy, §); - if ((sect.sct_type == SCT_WATER) || - (sect.sct_type == SCT_MOUNT) || - (sect.sct_type == SCT_SANCT) || - (sect.sct_type == SCT_WASTE) || - (sect.sct_own != lp->lnd_own)){ - wu(0, lp->lnd_own, "%s %s,\nbut could not retreat to %s!\n", - prland(lp), - conditions[findcondition(code)].desc[orig], - xyas(newx, newy, lp->lnd_own)); - if (!orig) putland(lp->lnd_uid,lp); - return 0; - } - mobcost = lnd_mobcost(lp, §, MOB_ROAD); - lp->lnd_x = newx; - lp->lnd_y = newy; - lp->lnd_mobil -= mobcost; - if (stopping) - continue; - - mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); - if ((lcp->l_flags & L_ENGINEER) && mines > 0 && - (sect.sct_oldown != lp->lnd_own)){ - max = vl_find(V_SHELL, lcp->l_vtype, - lcp->l_vamt, (int) lcp->l_nv); - shells = getvar(V_SHELL, (s_char *)lp, EF_LAND); - for (m=0; mines > 0 && m < 5; m++) { - if (chance(0.66)) { - mines--; - shells = min(max, shells + 1); - } - } - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putvar(V_SHELL, shells, (s_char *)lp, EF_LAND); - putsect(§); - } - if (mines > 0 && (sect.sct_oldown != lp->lnd_own) && - chance(DMINE_HITCHANCE(mines))) { - wu(0, lp->lnd_own, "%s %s,\nand hit a mine while retreating!\n", - prland(lp), - conditions[findcondition(code)].desc[orig], - xyas(newx, newy, lp->lnd_own)); - nreport(lp->lnd_own, N_LHIT_MINE, 0, 1); - m = MINE_LDAMAGE(); - landdamage(lp, m); - mines--; - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putsect(§); - if (lp->lnd_effic < LAND_MINEFF) - time_to_stop = 1; - if (!orig) putland(lp->lnd_uid,lp); - return 0; + dir = chkdir(lp->lnd_rpath[0], DIR_STOP, DIR_VIEW); + bzero(buf, RET_LEN - 1); + bcopy(&lp->lnd_rpath[1], buf, RET_LEN - 1); + bzero(lp->lnd_rpath, RET_LEN); + bcopy(buf, lp->lnd_rpath, RET_LEN - 1); + if (dir == -1) + continue; + if (dir == DIR_STOP) + stopping++; + else { + dx = diroff[dir][0]; + dy = diroff[dir][1]; + } + n++; + + lcp = &lchr[(int)lp->lnd_type]; + newx = xnorm(lp->lnd_x + dx); + newy = ynorm(lp->lnd_y + dy); + + getsect(newx, newy, §); + if ((sect.sct_type == SCT_WATER) || + (sect.sct_type == SCT_MOUNT) || + (sect.sct_type == SCT_SANCT) || + (sect.sct_type == SCT_WASTE) || + (sect.sct_own != lp->lnd_own)) { + wu(0, lp->lnd_own, "%s %s,\nbut could not retreat to %s!\n", + prland(lp), + conditions[findcondition(code)].desc[orig], + xyas(newx, newy, lp->lnd_own)); + if (!orig) + putland(lp->lnd_uid, lp); + return 0; + } + mobcost = lnd_mobcost(lp, §, MOB_ROAD); + lp->lnd_x = newx; + lp->lnd_y = newy; + lp->lnd_mobil -= mobcost; + if (stopping) + continue; + + mines = getvar(V_MINE, (s_char *)§, EF_SECTOR); + if ((lcp->l_flags & L_ENGINEER) && mines > 0 && + (sect.sct_oldown != lp->lnd_own)) { + max = vl_find(V_SHELL, lcp->l_vtype, + lcp->l_vamt, (int)lcp->l_nv); + shells = getvar(V_SHELL, (s_char *)lp, EF_LAND); + for (m = 0; mines > 0 && m < 5; m++) { + if (chance(0.66)) { + mines--; + shells = min(max, shells + 1); } - if (time_to_stop) - stopping = 1; + } + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putvar(V_SHELL, shells, (s_char *)lp, EF_LAND); + putsect(§); } - - if (orig){ - wu(0, lp->lnd_own, "%s %s, and retreated to %s\n", - prland(lp), - conditions[findcondition(code)].desc[orig], - xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); - }else{ - wu(0, lp->lnd_own, "%s %s, and ended up at %s\n", - prland(lp), - conditions[findcondition(code)].desc[orig], - xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + if (mines > 0 && (sect.sct_oldown != lp->lnd_own) && + chance(DMINE_HITCHANCE(mines))) { + wu(0, lp->lnd_own, + "%s %s,\nand hit a mine while retreating!\n", prland(lp), + conditions[findcondition(code)].desc[orig], xyas(newx, newy, + lp-> + lnd_own)); + nreport(lp->lnd_own, N_LHIT_MINE, 0, 1); + m = MINE_LDAMAGE(); + landdamage(lp, m); + mines--; + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putsect(§); + if (lp->lnd_effic < LAND_MINEFF) + time_to_stop = 1; + if (!orig) + putland(lp->lnd_uid, lp); + return 0; } - if (!orig) putland(lp->lnd_uid,lp); - return 1; + if (time_to_stop) + stopping = 1; + } + + if (orig) { + wu(0, lp->lnd_own, "%s %s, and retreated to %s\n", + prland(lp), + conditions[findcondition(code)].desc[orig], + xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + } else { + wu(0, lp->lnd_own, "%s %s, and ended up at %s\n", + prland(lp), + conditions[findcondition(code)].desc[orig], + xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + } + if (!orig) + putland(lp->lnd_uid, lp); + return 1; } diff --git a/src/lib/subs/sarg.c b/src/lib/subs/sarg.c index 128a03f8b..f80956874 100644 --- a/src/lib/subs/sarg.c +++ b/src/lib/subs/sarg.c @@ -56,91 +56,91 @@ int sarg_type(s_char *ptr) { - int c; + int c; - c = *ptr; - if (c == '@') - return NS_DIST; - if (c == '*') - return NS_ALL; - if (c == '#' || index(ptr, ',') != 0) - return NS_AREA; - if (isdigit(c)) - return NS_LIST; - if (c == '~' || isupper(c) || islower(c)) - return NS_GROUP; - return 0; + c = *ptr; + if (c == '@') + return NS_DIST; + if (c == '*') + return NS_ALL; + if (c == '#' || index(ptr, ',') != 0) + return NS_AREA; + if (isdigit(c)) + return NS_LIST; + if (c == '~' || isupper(c) || islower(c)) + return NS_GROUP; + return 0; } int sarg_xy(s_char *ptr, coord *xp, coord *yp) { - if (sarg_type(ptr) != NS_AREA) - return 0; - *xp = atoip(&ptr); - if (*ptr++ != ',') - return 0; - if (!isdigit(*ptr) && *ptr != '-') - return 0; - *yp = atoi(ptr); - inputxy(xp, yp, player->cnum); - if ((*xp ^ *yp) & 01) - return 0; - return 1; + if (sarg_type(ptr) != NS_AREA) + return 0; + *xp = atoip(&ptr); + if (*ptr++ != ',') + return 0; + if (!isdigit(*ptr) && *ptr != '-') + return 0; + *yp = atoi(ptr); + inputxy(xp, yp, player->cnum); + if ((*xp ^ *yp) & 01) + return 0; + return 1; } /* returns absolute coords */ int sarg_getrange(s_char *buf, register struct range *rp) { - register int rlm; - register int c; - struct natstr *np; - s_char *bp; + register int rlm; + register int c; + struct natstr *np; + s_char *bp; - bp = buf; - c = *bp; - if (c == '#') { - /* - * realm #X where (X > 0 && X < MAXNOR) - * Assumes realms are in abs coordinates - */ - bp++; - rlm = atoi(bp); - if (rlm < 0 || rlm >= MAXNOR) - return 0; - np = getnatp(player->cnum); - rp->lx = np->nat_b[rlm].b_xl; - rp->hx = np->nat_b[rlm].b_xh; - rp->ly = np->nat_b[rlm].b_yl; - rp->hy = np->nat_b[rlm].b_yh; - } else { - /* - * full map specification - * LX:LY,HX:HY where - * ly, hy are optional. - */ - if (!isdigit(c) && c != '-') - return 0; - rp->lx = rp->hx = atoip(&bp); - if (*bp == ':') { - bp++; - rp->hx = atoip(&bp); - } - if (*bp++ != ',') - return 0; - if (!isdigit(c) && c != '-') - return 0; - rp->ly = rp->hy = atoip(&bp); - if (*bp == ':') { - bp++; - rp->hy = atoip(&bp); - } - inputxy(&rp->lx, &rp->ly, player->cnum); - inputxy(&rp->hx, &rp->hy, player->cnum); + bp = buf; + c = *bp; + if (c == '#') { + /* + * realm #X where (X > 0 && X < MAXNOR) + * Assumes realms are in abs coordinates + */ + bp++; + rlm = atoi(bp); + if (rlm < 0 || rlm >= MAXNOR) + return 0; + np = getnatp(player->cnum); + rp->lx = np->nat_b[rlm].b_xl; + rp->hx = np->nat_b[rlm].b_xh; + rp->ly = np->nat_b[rlm].b_yl; + rp->hy = np->nat_b[rlm].b_yh; + } else { + /* + * full map specification + * LX:LY,HX:HY where + * ly, hy are optional. + */ + if (!isdigit(c) && c != '-') + return 0; + rp->lx = rp->hx = atoip(&bp); + if (*bp == ':') { + bp++; + rp->hx = atoip(&bp); + } + if (*bp++ != ',') + return 0; + if (!isdigit(c) && c != '-') + return 0; + rp->ly = rp->hy = atoip(&bp); + if (*bp == ':') { + bp++; + rp->hy = atoip(&bp); } - xysize_range(rp); - return 1; + inputxy(&rp->lx, &rp->ly, player->cnum); + inputxy(&rp->hx, &rp->hy, player->cnum); + } + xysize_range(rp); + return 1; } /* @@ -150,16 +150,16 @@ sarg_getrange(s_char *buf, register struct range *rp) int sarg_area(s_char *buf, register struct range *rp) { - if (!sarg_getrange(buf, rp)) - return 0; - rp->hx += 1; - if (rp->hx >= WORLD_X) - rp->hx = 0; - rp->hy += 1; - if (rp->hy >= WORLD_Y) - rp->hy = 0; - xysize_range(rp); - return 1; + if (!sarg_getrange(buf, rp)) + return 0; + rp->hx += 1; + if (rp->hx >= WORLD_X) + rp->hx = 0; + rp->hy += 1; + if (rp->hy >= WORLD_Y) + rp->hy = 0; + xysize_range(rp); + return 1; } /* @@ -169,22 +169,22 @@ sarg_area(s_char *buf, register struct range *rp) int sarg_range(s_char *buf, coord *xp, coord *yp, int *dist) { - s_char *bp; + s_char *bp; - bp = buf; - if (bp == 0 || *bp == 0) - return 0; - if (*bp++ != '@') - return 0; - *xp = atoip(&bp); - if (*bp++ != ',') - return 0; - *yp = atoip(&bp); - if (*bp++ != ':') - return 0; - inputxy(xp, yp, player->cnum); - *dist = atoi(bp); - return 1; + bp = buf; + if (bp == 0 || *bp == 0) + return 0; + if (*bp++ != '@') + return 0; + *xp = atoip(&bp); + if (*bp++ != ',') + return 0; + *yp = atoip(&bp); + if (*bp++ != ':') + return 0; + inputxy(xp, yp, player->cnum); + *dist = atoi(bp); + return 1; } /* @@ -193,36 +193,36 @@ sarg_range(s_char *buf, coord *xp, coord *yp, int *dist) int sarg_list(s_char *str, register int *list, int max) { - register int i; - register int j; - register int n; - s_char *arg; + register int i; + register int j; + register int n; + s_char *arg; - arg = str; - for (i=0; icnum), - eff, range); - bzero(noise, sizeof(noise)); - if (eff < 100) { - pr("Some noise on the transmission...\n"); - for (n = 0; n < (100 - eff); ++n) - noise[100 * n / (100 - eff)] = 1; - } + range = range * (eff / 100.0); + pr("%s efficiency %d%%, max range %d\n", xyas(x, y, player->cnum), + eff, range); + bzero(noise, sizeof(noise)); + if (eff < 100) { + pr("Some noise on the transmission...\n"); + for (n = 0; n < (100 - eff); ++n) + noise[100 * n / (100 - eff)] = 1; + } - /* Have to convert to player coords, since it gets converted - back from there */ - sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range); + /* Have to convert to player coords, since it gets converted + back from there */ + sprintf(selection, "@%s:%d", xyas(x, y, player->cnum), range); - if (type == EF_BAD || type == EF_SECTOR) { - if (type == EF_SECTOR) /* Use ?conditionals */ - snxtsct(&ns, selection); - else - snxtsct_dist(&ns, x, y, range); - - blankfill((s_char *)radbuf, &ns.range, 1); - if (flags & P_S) { - pr("Satellite sector report\n"); - prdate(); - sathead(); - acc = (flags & P_I) ? 5 : 50; + if (type == EF_BAD || type == EF_SECTOR) { + if (type == EF_SECTOR) /* Use ?conditionals */ + snxtsct(&ns, selection); + else + snxtsct_dist(&ns, x, y, range); + + blankfill((s_char *)radbuf, &ns.range, 1); + if (flags & P_S) { + pr("Satellite sector report\n"); + prdate(); + sathead(); + acc = (flags & P_I) ? 5 : 50; + } + crackle = count = 0; + while (nxtsct(&ns, §)) { + if (++crackle == 100) + crackle = 0; + if (noise[crackle]) + continue; + if (flags & P_S) { + if (sect.sct_type > SCT_RURAL) { + satdisp(§, acc, 0); + ++count; } - crackle = count = 0; - while (nxtsct(&ns, §)) { - if (++crackle == 100) - crackle = 0; - if (noise[crackle]) - continue; - if (flags & P_S) { - if (sect.sct_type > SCT_RURAL) { - satdisp(§, acc,0); - ++count; - } - if (opt_HIDDEN) { - setcont(player->cnum, sect.sct_own, FOUND_FLY); - } - } - if ((flags & P_I) || - sect.sct_type == SCT_WATER || - sect.sct_type == SCT_MOUNT) { - rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; - } else - rad[ns.dy][ns.dx] = '?'; - changed += map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx],0); + if (opt_HIDDEN) { + setcont(player->cnum, sect.sct_own, FOUND_FLY); } - if (changed) - writemap(player->cnum); - if (flags & P_S) - pr(" %d sectors\n\n", count); + } + if ((flags & P_I) || + sect.sct_type == SCT_WATER || sect.sct_type == SCT_MOUNT) { + rad[ns.dy][ns.dx] = dchr[sect.sct_type].d_mnem; + } else + rad[ns.dy][ns.dx] = '?'; + changed += + map_set(player->cnum, ns.x, ns.y, rad[ns.dy][ns.dx], 0); } + if (changed) + writemap(player->cnum); + if (flags & P_S) + pr(" %d sectors\n\n", count); + } - if ((type == EF_BAD || type == EF_SHIP) && - (flags & P_S || flags & P_I)) { - if (type == EF_SHIP) - snxtitem(&ni, EF_SHIP, selection); - else - snxtitem_dist(&ni, EF_SHIP, x, y, range); + if ((type == EF_BAD || type == EF_SHIP) && + (flags & P_S || flags & P_I)) { + if (type == EF_SHIP) + snxtitem(&ni, EF_SHIP, selection); + else + snxtitem_dist(&ni, EF_SHIP, x, y, range); - crackle = count = 0; - if (flags & P_S) { - pr("Satellite ship report\n"); - prdate(); - if (opt_SHIPNAMES) { - pr(" own shp# ship type sector eff\n"); - } else { - pr(" own shp# ship type sector eff\n"); - } - } - while (nxtitem(&ni, (caddr_t)&ship)) { - if (ship.shp_own == 0) - continue; - if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && - ((flags & (P_S|P_I)) != (P_S|P_I))) - continue; - if (++crackle == 100) - crackle = 0; - if (noise[crackle]) - continue; - if (flags & P_S) { - pr("%4d %4d %-16.16s ", - ship.shp_own, ship.shp_uid, - mchr[(int)ship.shp_type].m_name); - if (opt_SHIPNAMES) - pr("%-25.25s ", ship.shp_name); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, - player->cnum); - pr("%3d%%\n", ship.shp_effic); - ++count; - if (opt_HIDDEN) { - setcont(player->cnum, ship.shp_own, FOUND_FLY); - } - } - /* If we are imaging *and* drawing the map */ - if ((flags & P_I) && (type == EF_BAD)) { - /* Figure out where to put the ship */ - /* First, figure out the distance from the two */ - rx = diffx((int)ship.shp_x, x); - ry = diffy((int)ship.shp_y, y); - /* Next, determine which direction to add it to the center */ - /* We can only do this if imaging and we have gotten the center - up above by imaging the sectors. */ - rx = deltax(x, ns.range.lx) + rx; - ry = deltay(y, ns.range.ly) + ry; - /* &~0x20 makes it a cap letter */ - rad[ry][rx] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; - } + crackle = count = 0; + if (flags & P_S) { + pr("Satellite ship report\n"); + prdate(); + if (opt_SHIPNAMES) { + pr(" own shp# ship type sector eff\n"); + } else { + pr(" own shp# ship type sector eff\n"); + } + } + while (nxtitem(&ni, (caddr_t)&ship)) { + if (ship.shp_own == 0) + continue; + if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && + ((flags & (P_S | P_I)) != (P_S | P_I))) + continue; + if (++crackle == 100) + crackle = 0; + if (noise[crackle]) + continue; + if (flags & P_S) { + pr("%4d %4d %-16.16s ", + ship.shp_own, ship.shp_uid, + mchr[(int)ship.shp_type].m_name); + if (opt_SHIPNAMES) + pr("%-25.25s ", ship.shp_name); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + pr("%3d%%\n", ship.shp_effic); + ++count; + if (opt_HIDDEN) { + setcont(player->cnum, ship.shp_own, FOUND_FLY); } - if (flags & P_S) - pr(" %d ships\n\n", count); + } + /* If we are imaging *and* drawing the map */ + if ((flags & P_I) && (type == EF_BAD)) { + /* Figure out where to put the ship */ + /* First, figure out the distance from the two */ + rx = diffx((int)ship.shp_x, x); + ry = diffy((int)ship.shp_y, y); + /* Next, determine which direction to add it to the center */ + /* We can only do this if imaging and we have gotten the center + up above by imaging the sectors. */ + rx = deltax(x, ns.range.lx) + rx; + ry = deltay(y, ns.range.ly) + ry; + /* &~0x20 makes it a cap letter */ + rad[ry][rx] = (*mchr[(int)ship.shp_type].m_name) & ~0x20; + } } + if (flags & P_S) + pr(" %d ships\n\n", count); + } - if ((type == EF_BAD || type == EF_LAND) && - (flags & P_S || flags & P_I)) { - if (type == EF_LAND) - snxtitem(&ni, EF_LAND, selection); - else - snxtitem_dist(&ni, EF_LAND, x, y, range); + if ((type == EF_BAD || type == EF_LAND) && + (flags & P_S || flags & P_I)) { + if (type == EF_LAND) + snxtitem(&ni, EF_LAND, selection); + else + snxtitem_dist(&ni, EF_LAND, x, y, range); - crackle = count = 0; - if (flags & P_S) { - pr("Satellite unit report\n"); - prdate(); - pr(" own lnd# unit type sector eff\n"); - } - while (nxtitem(&ni, (caddr_t)&land)) { - if (land.lnd_own == 0) - continue; - if (!chance((double)land.lnd_effic/20.0)) - continue; - if (++crackle == 100) - crackle = 0; - if (noise[crackle]) - continue; - if (flags & P_S) { - pr("%4d %4d %-16.16s ", - land.lnd_own, land.lnd_uid, - lchr[(int)land.lnd_type].l_name); - prxy("%4d,%-4d", land.lnd_x, land.lnd_y, - player->cnum); - pr("%3d%%\n", land.lnd_effic); - ++count; - } - /* If we are imaging *and* drawing the map */ - if ((flags & P_I) && (type == EF_BAD)) { - /* Figure out where to put the unit */ - /* First, figure out the distance from the two */ - rx = diffx((int)land.lnd_x, x); - ry = diffy((int)land.lnd_y, y); - /* Next, determine which direction to add it to the center */ - /* We can only do this if imaging and we have gotten the center - up above by imaging the sectors. */ - rx = deltax(x, ns.range.lx) + rx; - ry = deltay(y, ns.range.ly) + ry; - /* &~0x20 makes it a cap letter */ - rad[ry][rx] = (*lchr[(int)land.lnd_type].l_name) & ~0x20; - } - } - if (flags & P_S) - pr(" %d units\n\n", count); + crackle = count = 0; + if (flags & P_S) { + pr("Satellite unit report\n"); + prdate(); + pr(" own lnd# unit type sector eff\n"); } + while (nxtitem(&ni, (caddr_t)&land)) { + if (land.lnd_own == 0) + continue; + if (!chance((double)land.lnd_effic / 20.0)) + continue; + if (++crackle == 100) + crackle = 0; + if (noise[crackle]) + continue; + if (flags & P_S) { + pr("%4d %4d %-16.16s ", + land.lnd_own, land.lnd_uid, + lchr[(int)land.lnd_type].l_name); + prxy("%4d,%-4d", land.lnd_x, land.lnd_y, player->cnum); + pr("%3d%%\n", land.lnd_effic); + ++count; + } + /* If we are imaging *and* drawing the map */ + if ((flags & P_I) && (type == EF_BAD)) { + /* Figure out where to put the unit */ + /* First, figure out the distance from the two */ + rx = diffx((int)land.lnd_x, x); + ry = diffy((int)land.lnd_y, y); + /* Next, determine which direction to add it to the center */ + /* We can only do this if imaging and we have gotten the center + up above by imaging the sectors. */ + rx = deltax(x, ns.range.lx) + rx; + ry = deltay(y, ns.range.ly) + ry; + /* &~0x20 makes it a cap letter */ + rad[ry][rx] = (*lchr[(int)land.lnd_type].l_name) & ~0x20; + } + } + if (flags & P_S) + pr(" %d units\n\n", count); + } - /* Ok, have we made the map? If so, display it */ - if (type == EF_BAD) { - /* - * print out the map - * We have to make the center a '0' for ve - * ve needs a garbage line to terminate the map - */ - rad[deltay(y, ns.range.ly)][deltax(x, ns.range.lx)] = '0'; + /* Ok, have we made the map? If so, display it */ + if (type == EF_BAD) { + /* + * print out the map + * We have to make the center a '0' for ve + * ve needs a garbage line to terminate the map + */ + rad[deltay(y, ns.range.ly)][deltax(x, ns.range.lx)] = '0'; - pr("Satellite radar report\n"); + pr("Satellite radar report\n"); #ifdef HAY - /* This is wrong for small, hitech worlds. */ - n = deltay(ns.range.hy, ns.range.ly); + /* This is wrong for small, hitech worlds. */ + n = deltay(ns.range.hy, ns.range.ly); #else - /* This is already available, so why not use it. */ - n = ns.range.height; + /* This is already available, so why not use it. */ + n = ns.range.height; #endif - for (row=0; row < n; row++) - pr("%s\n", rad[row]); - pr("\n(c) 1989 Imaginative Images Inc.\n"); - } + for (row = 0; row < n; row++) + pr("%s\n", rad[row]); + pr("\n(c) 1989 Imaginative Images Inc.\n"); + } } void sathead(void) { -pr(" sct rd rl def\n"); -pr(" sect type own eff eff eff eff civ mil shl gun iron pet food\n"); + pr(" sct rd rl def\n"); + pr(" sect type own eff eff eff eff civ mil shl gun iron pet food\n"); } void satdisp(struct sctstr *sp, int acc, int showstuff) { - int vec[I_MAX+1], first; - struct nstr_item ni; - struct shpstr ship; - struct lndstr land; + int vec[I_MAX + 1], first; + struct nstr_item ni; + struct shpstr ship; + struct lndstr land; - if (getvec(VT_ITEM, vec, (caddr_t)sp, EF_SECTOR) < 0) - return; - prxy("%4d,%-4d ", sp->sct_x, sp->sct_y, player->cnum), + if (getvec(VT_ITEM, vec, (caddr_t)sp, EF_SECTOR) < 0) + return; + prxy("%4d,%-4d ", sp->sct_x, sp->sct_y, player->cnum), pr("%c %3d %3d %3d %3d %3d %4d %4d %4d %4d %4d %4d %5d\n", - dchr[sp->sct_type].d_mnem, - sp->sct_own, roundintby((int)sp->sct_effic, acc / 2), - roundintby((int)sp->sct_road, acc / 2), - roundintby((int)sp->sct_rail, acc / 2), - roundintby((int)sp->sct_defense, acc / 2), - roundintby(vec[I_CIVIL], acc), roundintby(vec[I_MILIT], acc), - roundintby(vec[I_SHELL], acc), roundintby(vec[I_GUN], acc), - roundintby(vec[I_IRON], acc), roundintby(vec[I_PETROL], acc), - roundintby(vec[I_FOOD], acc)); - map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem, 0); - if (!showstuff) - return; - snxtitem_xy(&ni, EF_SHIP, sp->sct_x, sp->sct_y); - first=1; - while (nxtitem(&ni, (caddr_t)&ship)) { - if (ship.shp_own == 0) - continue; - if (mchr[(int)ship.shp_type].m_flags & M_SUB) - continue; - if (first){ - if (opt_SHIPNAMES) { -pr("\t own shp# ship type sector eff\n"); - } else { -pr("\t own shp# ship type sector eff\n"); - } - first=0; - } - pr("\t%4d %4d %-16.16s ", ship.shp_own, ship.shp_uid, - mchr[(int)ship.shp_type].m_name); - if (opt_SHIPNAMES) - pr("%-25.25s ", ship.shp_name); - prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); - pr("%3d%%\n", ship.shp_effic); + dchr[sp->sct_type].d_mnem, + sp->sct_own, roundintby((int)sp->sct_effic, acc / 2), + roundintby((int)sp->sct_road, acc / 2), + roundintby((int)sp->sct_rail, acc / 2), + roundintby((int)sp->sct_defense, acc / 2), + roundintby(vec[I_CIVIL], acc), roundintby(vec[I_MILIT], acc), + roundintby(vec[I_SHELL], acc), roundintby(vec[I_GUN], acc), + roundintby(vec[I_IRON], acc), roundintby(vec[I_PETROL], acc), + roundintby(vec[I_FOOD], acc)); + map_set(player->cnum, sp->sct_x, sp->sct_y, dchr[sp->sct_type].d_mnem, + 0); + if (!showstuff) + return; + snxtitem_xy(&ni, EF_SHIP, sp->sct_x, sp->sct_y); + first = 1; + while (nxtitem(&ni, (caddr_t)&ship)) { + if (ship.shp_own == 0) + continue; + if (mchr[(int)ship.shp_type].m_flags & M_SUB) + continue; + if (first) { + if (opt_SHIPNAMES) { + pr("\t own shp# ship type sector eff\n"); + } else { + pr("\t own shp# ship type sector eff\n"); + } + first = 0; } + pr("\t%4d %4d %-16.16s ", ship.shp_own, ship.shp_uid, + mchr[(int)ship.shp_type].m_name); + if (opt_SHIPNAMES) + pr("%-25.25s ", ship.shp_name); + prxy("%4d,%-4d ", ship.shp_x, ship.shp_y, player->cnum); + pr("%3d%%\n", ship.shp_effic); + } - if (!first) - pr("\n"); + if (!first) + pr("\n"); - snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); - first=1; + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + first = 1; - while (nxtitem(&ni, (caddr_t)&land)) { - if (land.lnd_own == 0) - continue; - if (!chance((double)land.lnd_effic/20.0)) - continue; + while (nxtitem(&ni, (caddr_t)&land)) { + if (land.lnd_own == 0) + continue; + if (!chance((double)land.lnd_effic / 20.0)) + continue; - if (first){ - pr("\t own lnd# unit type sector eff\n"); - first=0; - } - - pr("\t%4d %4d %-16.16s ",land.lnd_own, land.lnd_uid, - lchr[(int)land.lnd_type].l_name); - prxy("%4d,%-4d ",land.lnd_x, land.lnd_y, player->cnum); - pr("%3d%%\n", land.lnd_effic); + if (first) { + pr("\t own lnd# unit type sector eff\n"); + first = 0; } - if (!first) - pr("\n"); -} + pr("\t%4d %4d %-16.16s ", land.lnd_own, land.lnd_uid, + lchr[(int)land.lnd_type].l_name); + prxy("%4d,%-4d ", land.lnd_x, land.lnd_y, player->cnum); + pr("%3d%%\n", land.lnd_effic); + } + if (!first) + pr("\n"); +} diff --git a/src/lib/subs/sect.c b/src/lib/subs/sect.c index 2d723e111..23eaf7369 100644 --- a/src/lib/subs/sect.c +++ b/src/lib/subs/sect.c @@ -52,117 +52,116 @@ static void give_back_cap(struct sctstr *sp); int sct_postread(int id, s_char *ptr) { - struct sctstr *sp = (struct sctstr *) ptr; + struct sctstr *sp = (struct sctstr *)ptr; - checksect(sp); - player->owner = (player->god || sp->sct_own == player->cnum); - if (opt_MOB_ACCESS) - sct_do_upd_mob(sp); - return 1; + checksect(sp); + player->owner = (player->god || sp->sct_own == player->cnum); + if (opt_MOB_ACCESS) + sct_do_upd_mob(sp); + return 1; } /*ARGSUSED*/ int sct_prewrite(int id, s_char *ptr) { - struct sctstr *sp = (struct sctstr *) ptr; - struct sctstr sect; + struct sctstr *sp = (struct sctstr *)ptr; + struct sctstr sect; - time(&sp->sct_timestamp); + time(&sp->sct_timestamp); - checksect(sp); - getsect(sp->sct_x, sp->sct_y, §); - return 1; + checksect(sp); + getsect(sp->sct_x, sp->sct_y, §); + return 1; } int checksect(struct sctstr *sp) { - int mil, civs, loyalcivs; - - /* shouldn't happen, but... */ - if (sp->sct_mobil > 127) - sp->sct_mobil = 0; - - mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR); - civs = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR); - if (sp->sct_own == sp->sct_oldown) - loyalcivs = civs; - else - loyalcivs = 0; - - if (sp->sct_effic < 20) { - if (sp->sct_type == SCT_BSPAN) - knockdown(sp, 0); - else if (sp->sct_type == SCT_BTOWER) { - knockdown(sp, 0); - bridgefall(sp, 0); - } - } - if (sp->sct_own != 0 && !civs) { - sp->sct_work = 100; - sp->sct_oldown = sp->sct_own; + int mil, civs, loyalcivs; + + /* shouldn't happen, but... */ + if (sp->sct_mobil > 127) + sp->sct_mobil = 0; + + mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR); + civs = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR); + if (sp->sct_own == sp->sct_oldown) + loyalcivs = civs; + else + loyalcivs = 0; + + if (sp->sct_effic < 20) { + if (sp->sct_type == SCT_BSPAN) + knockdown(sp, 0); + else if (sp->sct_type == SCT_BTOWER) { + knockdown(sp, 0); + bridgefall(sp, 0); } - /* If they have a military unit there, they still own it */ - if (sp->sct_own && !loyalcivs && !(sp->sct_flags & MOVE_IN_PROGRESS)) { - if (!mil && !has_units(sp->sct_x,sp->sct_y,sp->sct_own,0)) { - /* more cruft! */ - if (sp->sct_type == SCT_CAPIT || - sp->sct_type == SCT_MOUNT) - caploss(sp, sp->sct_own, ""); - - if (sp->sct_oldown == sp->sct_own) { - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - } else { - /* if oldown gets his cap back make agri */ - if (sp->sct_oldown && - player->cnum == sp->sct_own && - sp->sct_type == SCT_CAPIT && - sp->sct_newtype == SCT_CAPIT) - give_back_cap(sp); - takeover(sp, sp->sct_oldown); - } - sp->sct_mobil = 0; - } + } + if (sp->sct_own != 0 && !civs) { + sp->sct_work = 100; + sp->sct_oldown = sp->sct_own; + } + /* If they have a military unit there, they still own it */ + if (sp->sct_own && !loyalcivs && !(sp->sct_flags & MOVE_IN_PROGRESS)) { + if (!mil && !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + /* more cruft! */ + if (sp->sct_type == SCT_CAPIT || sp->sct_type == SCT_MOUNT) + caploss(sp, sp->sct_own, ""); + + if (sp->sct_oldown == sp->sct_own) { + makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); + sp->sct_own = 0; + sp->sct_oldown = 0; + } else { + /* if oldown gets his cap back make agri */ + if (sp->sct_oldown && + player->cnum == sp->sct_own && + sp->sct_type == SCT_CAPIT && + sp->sct_newtype == SCT_CAPIT) + give_back_cap(sp); + takeover(sp, sp->sct_oldown); + } + sp->sct_mobil = 0; } - if (!opt_DEFENSE_INFRA) - sp->sct_defense = sp->sct_effic; - return 1; + } + if (!opt_DEFENSE_INFRA) + sp->sct_defense = sp->sct_effic; + return 1; } int issector(s_char *arg) { - s_char c; + s_char c; - while (0 != (c = *arg++)) - if (!isdigit(c) && !isspace(c) && (c != '/')) - return 1; + while (0 != (c = *arg++)) + if (!isdigit(c) && !isspace(c) && (c != '/')) + return 1; - return 0; + return 0; } static void give_back_cap(struct sctstr *sp) { - struct natstr *natp = getnatp(sp->sct_oldown); + struct natstr *natp = getnatp(sp->sct_oldown); - if (xrel(natp,natp->nat_xcap) == xrel(natp,sp->sct_x) && - yrel(natp,natp->nat_ycap) == yrel(natp,sp->sct_y)) { - sp->sct_newtype = SCT_AGRI; - } + if (xrel(natp, natp->nat_xcap) == xrel(natp, sp->sct_x) && + yrel(natp, natp->nat_ycap) == yrel(natp, sp->sct_y)) { + sp->sct_newtype = SCT_AGRI; + } } void sct_init(coord x, coord y, s_char *ptr) { - struct sctstr *sp = (struct sctstr *) ptr; + struct sctstr *sp = (struct sctstr *)ptr; - sp->ef_type = EF_SECTOR; - sp->sct_x = x; - sp->sct_y = y; - sp->sct_dist_x = x; - sp->sct_dist_y = y; + sp->ef_type = EF_SECTOR; + sp->sct_x = x; + sp->sct_y = y; + sp->sct_dist_x = x; + sp->sct_dist_y = y; } diff --git a/src/lib/subs/ship.c b/src/lib/subs/ship.c index 71fb2a78f..c087a75d3 100644 --- a/src/lib/subs/ship.c +++ b/src/lib/subs/ship.c @@ -50,76 +50,79 @@ int shp_postread(int n, s_char *ptr) { - struct shpstr *sp = (struct shpstr *)ptr; + struct shpstr *sp = (struct shpstr *)ptr; - if (sp->shp_uid != n) { - logerror("shp_postread: Error - %d != %d, zeroing.\n", sp->shp_uid, n); - bzero(ptr, sizeof(struct shpstr)); - } + if (sp->shp_uid != n) { + logerror("shp_postread: Error - %d != %d, zeroing.\n", sp->shp_uid, + n); + bzero(ptr, sizeof(struct shpstr)); + } - if (opt_MOB_ACCESS) - shp_do_upd_mob(sp); - player->owner = (player->god || sp->shp_own == player->cnum); - return 1; + if (opt_MOB_ACCESS) + shp_do_upd_mob(sp); + player->owner = (player->god || sp->shp_own == player->cnum); + return 1; } int shp_prewrite(int n, s_char *ptr) { - struct shpstr *sp = (struct shpstr *) ptr; - struct shpstr ship; + struct shpstr *sp = (struct shpstr *)ptr; + struct shpstr ship; struct lndstr *lp; struct plnstr *pp; int i; - + sp->ef_type = EF_SHIP; sp->shp_uid = n; - + time(&sp->shp_timestamp); - + if (sp->shp_own != 0 && sp->shp_effic < SHIP_MINEFF) { - mpr(sp->shp_own, "\t%s sunk!\n", prship(sp)); - makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); - sp->shp_own = 0; - - getship(n, &ship); - - for (i = 0; NULL != (lp = getlandp(i)); i++) { - if (lp->lnd_own && lp->lnd_ship == n) { - mpr(lp->lnd_own, "%s sunk!\n", prland(lp)); - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own = 0; - lp->lnd_effic = 0; - lp->lnd_ship = -1; - lp->lnd_land = -1; - putland(lp->lnd_uid, lp); - } - } - for (i = 0; NULL != (pp = getplanep(i)); i++) { - if (pp->pln_own && pp->pln_ship == n) { - mpr(pp->pln_own, "%s sunk!\n", prplane(pp)); - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - pp->pln_effic = 0; - pp->pln_ship = -1; - pp->pln_land = -1; - putplane(pp->pln_uid, pp); - } - } + mpr(sp->shp_own, "\t%s sunk!\n", prship(sp)); + makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); + sp->shp_own = 0; + + getship(n, &ship); + + for (i = 0; NULL != (lp = getlandp(i)); i++) { + if (lp->lnd_own && lp->lnd_ship == n) { + mpr(lp->lnd_own, "%s sunk!\n", prland(lp)); + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, + lp->lnd_y); + lp->lnd_own = 0; + lp->lnd_effic = 0; + lp->lnd_ship = -1; + lp->lnd_land = -1; + putland(lp->lnd_uid, lp); + } + } + for (i = 0; NULL != (pp = getplanep(i)); i++) { + if (pp->pln_own && pp->pln_ship == n) { + mpr(pp->pln_own, "%s sunk!\n", prplane(pp)); + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_own = 0; + pp->pln_effic = 0; + pp->pln_ship = -1; + pp->pln_land = -1; + putplane(pp->pln_uid, pp); + } + } } else - getship(n, &ship); - + getship(n, &ship); + return 1; } void shp_init(int n, s_char *ptr) { - struct shpstr *sp = (struct shpstr *) ptr; + struct shpstr *sp = (struct shpstr *)ptr; - sp->ef_type = EF_SHIP; - sp->shp_uid = n; - sp->shp_own = 0; + sp->ef_type = EF_SHIP; + sp->shp_uid = n; + sp->shp_own = 0; } s_char * @@ -127,8 +130,10 @@ prship(struct shpstr *sp) { if (opt_SHIPNAMES) { return prbuf("%s %s(#%d)", - mchr[(int)sp->shp_type].m_name, sp->shp_name, sp->shp_uid); + mchr[(int)sp->shp_type].m_name, sp->shp_name, + sp->shp_uid); } else { - return prbuf("%s #%d", mchr[(int)sp->shp_type].m_name, sp->shp_uid); + return prbuf("%s #%d", mchr[(int)sp->shp_type].m_name, + sp->shp_uid); } } diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index dba03716a..f024d9052 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -64,78 +64,78 @@ double logx(double, double); */ struct lookup { - int key; - s_char *value; + int key; + s_char *value; }; -struct lookup ship_flags[] = { - { M_FOOD, "fish" }, - { M_TORP, "torp" }, - { M_DCH, "dchrg" }, - { M_FLY, "plane" }, - { M_MSL, "miss" }, - { M_OIL, "oil" }, - { M_SONAR, "sonar" }, - { M_MINE, "mine" }, - { M_SWEEP, "sweep" }, - { M_SUB, "sub" }, - { M_SPY, "spy" }, - { M_LAND, "land" }, - { M_SUBT, "sub-torp" }, - { M_TRADE, "trade" }, - { M_SEMILAND, "semi-land" }, - { M_OILER, "oiler" }, - { M_SUPPLY, "supply" }, - { M_ANTIMISSILE, "anti-missile" }, - { 0, 0 } +struct lookup ship_flags[] = { + {M_FOOD, "fish"}, + {M_TORP, "torp"}, + {M_DCH, "dchrg"}, + {M_FLY, "plane"}, + {M_MSL, "miss"}, + {M_OIL, "oil"}, + {M_SONAR, "sonar"}, + {M_MINE, "mine"}, + {M_SWEEP, "sweep"}, + {M_SUB, "sub"}, + {M_SPY, "spy"}, + {M_LAND, "land"}, + {M_SUBT, "sub-torp"}, + {M_TRADE, "trade"}, + {M_SEMILAND, "semi-land"}, + {M_OILER, "oiler"}, + {M_SUPPLY, "supply"}, + {M_ANTIMISSILE, "anti-missile"}, + {0, 0} }; -struct lookup land_flags[] = { - { L_XLIGHT, "xlight" }, - { L_ENGINEER, "engineer" }, - { L_SUPPLY, "supply" }, - { L_SECURITY, "security" }, - { L_LIGHT, "light" }, - { L_MARINE, "marine" }, - { L_RECON, "recon" }, - { L_RADAR, "radar" }, - { L_ASSAULT, "assault" }, - { L_FLAK, "flak" }, - { L_SPY, "spy" }, - { L_TRAIN, "train" }, - { L_HEAVY, "heavy" }, - { 0, 0 } +struct lookup land_flags[] = { + {L_XLIGHT, "xlight"}, + {L_ENGINEER, "engineer"}, + {L_SUPPLY, "supply"}, + {L_SECURITY, "security"}, + {L_LIGHT, "light"}, + {L_MARINE, "marine"}, + {L_RECON, "recon"}, + {L_RADAR, "radar"}, + {L_ASSAULT, "assault"}, + {L_FLAK, "flak"}, + {L_SPY, "spy"}, + {L_TRAIN, "train"}, + {L_HEAVY, "heavy"}, + {0, 0} }; -struct lookup plane_flags[] = { - { P_T, "tactical" }, - { P_B, "bomber" }, - { P_F, "intercept" }, - { P_C, "cargo" }, - { P_V, "VTOL" }, - { P_M, "missile" }, - { P_L, "light" }, - { P_S, "spy" }, - { P_I, "image" }, - { P_O, "satellite" }, - { P_X, "stealth" }, - { P_N, "SDI" }, - { P_H, "half-stealth" }, - { P_E, "x-light" }, - { P_K, "helo" }, - { P_A, "ASW" }, - { P_P, "para" }, - { P_ESC, "escort" }, - { P_MINE, "mine" }, - { P_SWEEP, "sweep" }, - { P_MAR, "marine" }, - { 0, 0 } +struct lookup plane_flags[] = { + {P_T, "tactical"}, + {P_B, "bomber"}, + {P_F, "intercept"}, + {P_C, "cargo"}, + {P_V, "VTOL"}, + {P_M, "missile"}, + {P_L, "light"}, + {P_S, "spy"}, + {P_I, "image"}, + {P_O, "satellite"}, + {P_X, "stealth"}, + {P_N, "SDI"}, + {P_H, "half-stealth"}, + {P_E, "x-light"}, + {P_K, "helo"}, + {P_A, "ASW"}, + {P_P, "para"}, + {P_ESC, "escort"}, + {P_MINE, "mine"}, + {P_SWEEP, "sweep"}, + {P_MAR, "marine"}, + {0, 0} }; struct lookup nuke_flags[] = { - { N_NEUT, "neutron" }, - { 0, 0 } + {N_NEUT, "neutron"}, + {0, 0} }; struct look_list { @@ -146,8 +146,8 @@ struct look_list { int value; } l_u; int tech; -} lookup_list[200]; /* Change this if there are ever more than 200 planes, ships - or land units. */ +} lookup_list[200]; /* Change this if there are ever more than 200 planes, ships + or land units. */ static int lookup_list_cnt = 0; void @@ -157,7 +157,7 @@ sort_lookup_list(void) struct look_list tmp; int i; int j; - + if (!(np->nat_flags & NF_TECHLISTS)) return; for (i = 0; i < lookup_list_cnt; i++) { @@ -172,7 +172,7 @@ sort_lookup_list(void) } static -void + void make_new_list(int tlev, int type) { struct plchrstr *pp; @@ -211,7 +211,7 @@ make_new_list(int tlev, int type) lookup_list[lookup_list_cnt].tech = lp->l_tech; lookup_list_cnt++; } - } else + } else return; sort_lookup_list(); @@ -221,566 +221,559 @@ static s_char * lookup(int key, struct lookup *table) { - int match; + int match; - if ((match = intmatch(key, &table->key, sizeof(*table))) < 0) - return 0; - return table[match].value; + if ((match = intmatch(key, &table->key, sizeof(*table))) < 0) + return 0; + return table[match].value; } void show_bridge(int tlev) { - extern double buil_bt, buil_bc; - extern int buil_bh; - - if (tlev < buil_bt) - return; - pr("Bridges require %g tech,", buil_bt); - if (!opt_NO_HCMS) - pr(" %d hcm,", buil_bh); - else if (!opt_NO_LCMS) - pr(" %d lcm,", buil_bh); - pr(" %d workers,\n", buil_bh * 2); - pr("%d available workforce, and cost $%g\n", - 1 + (buil_bh * 40 / 100), buil_bc); + extern double buil_bt, buil_bc; + extern int buil_bh; + + if (tlev < buil_bt) + return; + pr("Bridges require %g tech,", buil_bt); + if (!opt_NO_HCMS) + pr(" %d hcm,", buil_bh); + else if (!opt_NO_LCMS) + pr(" %d lcm,", buil_bh); + pr(" %d workers,\n", buil_bh * 2); + pr("%d available workforce, and cost $%g\n", + 1 + (buil_bh * 40 / 100), buil_bc); } void show_tower(int tlev) { - extern double buil_tower_bt, buil_tower_bc; - extern int buil_tower_bh; - - if (tlev < buil_tower_bt) - return; - pr("Bridge Towers require %g tech,", buil_tower_bt); - if (!opt_NO_HCMS) - pr(" %d hcm,", buil_tower_bh); - else if (!opt_NO_LCMS) - pr(" %d lcm,", buil_tower_bh); - pr(" %d workers,\n", buil_tower_bh * 2); - pr("%d available workforce, and cost $%g\n", - 1 + (buil_tower_bh * 40 / 100), buil_tower_bc); + extern double buil_tower_bt, buil_tower_bc; + extern int buil_tower_bh; + + if (tlev < buil_tower_bt) + return; + pr("Bridge Towers require %g tech,", buil_tower_bt); + if (!opt_NO_HCMS) + pr(" %d hcm,", buil_tower_bh); + else if (!opt_NO_LCMS) + pr(" %d lcm,", buil_tower_bh); + pr(" %d workers,\n", buil_tower_bh * 2); + pr("%d available workforce, and cost $%g\n", + 1 + (buil_tower_bh * 40 / 100), buil_tower_bc); } void show_nuke_stats(int tlev) { - show_nuke_capab(tlev); + show_nuke_capab(tlev); } void show_nuke_build(int tlev) { - register struct nchrstr *np; - register int n; - register int avail; - extern float drnuke_const; + register struct nchrstr *np; + register int n; + register int avail; + extern float drnuke_const; + + if (opt_DRNUKE) + pr("%13s lcm hcm oil rad avail tech res $\n", ""); + else + pr("%13s lcm hcm oil rad avail tech $\n", ""); + if (opt_NONUKES) + return; + for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) { + avail = + (4 + np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2) / 5; + if (np->n_tech > tlev) + continue; + if (np->n_name == 0 || np->n_name[0] == '\0') + continue; + if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT)) + continue; if (opt_DRNUKE) - pr("%13s lcm hcm oil rad avail tech res $\n", ""); - else - pr("%13s lcm hcm oil rad avail tech $\n", ""); - - if (opt_NONUKES) - return; - for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) { - avail = (4 + np->n_rad + np->n_oil + np->n_lcm + np->n_hcm * 2)/5; - if (np->n_tech > tlev) - continue; - if (np->n_name == 0 || np->n_name[0] == '\0') - continue; - if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT)) - continue; - if (opt_DRNUKE) - pr("%-13.13s %3d %3d %4d %4d %5d %4d %3d $%6d\n", - np->n_name, np->n_lcm, np->n_hcm, np->n_oil, - np->n_rad, avail, np->n_tech, - (int)(np->n_tech*drnuke_const)+1, - np->n_cost); - else /* not DRNUKE */ - pr("%-13.13s %3d %3d %4d %4d %5d %4d $%6d\n", - np->n_name, np->n_lcm, np->n_hcm, np->n_oil, - np->n_rad, avail, np->n_tech, np->n_cost); - } + pr("%-13.13s %3d %3d %4d %4d %5d %4d %3d $%6d\n", + np->n_name, np->n_lcm, np->n_hcm, np->n_oil, + np->n_rad, avail, np->n_tech, + (int)(np->n_tech * drnuke_const) + 1, np->n_cost); + else /* not DRNUKE */ + pr("%-13.13s %3d %3d %4d %4d %5d %4d $%6d\n", + np->n_name, np->n_lcm, np->n_hcm, np->n_oil, + np->n_rad, avail, np->n_tech, np->n_cost); + } } void show_nuke_capab(int tlev) { - register struct nchrstr *np; - register int i,j,n; - s_char *p; - extern float drnuke_const; + register struct nchrstr *np; + register int i, j, n; + s_char *p; + extern float drnuke_const; + + if (opt_DRNUKE) + pr("%13s blst dam lbs tech res $%7s abilities\n", "", ""); + else + pr("%13s blst dam lbs tech $%7s abilities\n", "", ""); + if (opt_NONUKES) + return; + for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) { + if (np->n_tech > tlev) + continue; + if (opt_NEUTRON == 0 && (np->n_flags & N_NEUT)) + continue; + if (np->n_name == 0 || np->n_name[0] == '\0') + continue; if (opt_DRNUKE) - pr("%13s blst dam lbs tech res $%7s abilities\n", "",""); - else - pr("%13s blst dam lbs tech $%7s abilities\n", "",""); - - if (opt_NONUKES) - return; - for (np = nchr, n = 0; n < N_MAXNUKE; np++, n++) { - if (np->n_tech > tlev) - continue; - if (opt_NEUTRON == 0 && (np -> n_flags & N_NEUT)) - continue; - if (np->n_name == 0 || np->n_name[0] == '\0') - continue; - if (opt_DRNUKE) - pr("%-13.13s %4d %3d %3d %4d %3d $%7d ", - np->n_name, np->n_blast, np->n_dam, - np->n_weight, np->n_tech, - (int)(np->n_tech * drnuke_const)+1, - np->n_cost); - else /* not DRNUKE */ - pr("%-13.13s %4d %3d %3d %4d $%7d ", - np->n_name, np->n_blast, np->n_dam, - np->n_weight, np->n_tech, np->n_cost); - - for (i = j = 0; i < 32; i++) { - if (!(np->n_flags & bit(i))) - continue; - if (NULL != (p = lookup(bit(i), nuke_flags))) { - if (j++ > 0) - pr(" "); - pr(p); - } - } - pr("\n"); + pr("%-13.13s %4d %3d %3d %4d %3d $%7d ", + np->n_name, np->n_blast, np->n_dam, + np->n_weight, np->n_tech, + (int)(np->n_tech * drnuke_const) + 1, np->n_cost); + else /* not DRNUKE */ + pr("%-13.13s %4d %3d %3d %4d $%7d ", + np->n_name, np->n_blast, np->n_dam, + np->n_weight, np->n_tech, np->n_cost); + + for (i = j = 0; i < 32; i++) { + if (!(np->n_flags & bit(i))) + continue; + if (NULL != (p = lookup(bit(i), nuke_flags))) { + if (j++ > 0) + pr(" "); + pr(p); + } } + pr("\n"); + } } void show_ship_build(int tlev) { - register struct mchrstr *mp; - register int n; - - pr("%25s lcm hcm avail tech $\n", ""); - make_new_list(tlev, EF_SHIP); - for (n = 0; n < lookup_list_cnt; n++) { - mp = (struct mchrstr *)lookup_list[n].l_u.mp; - /* Can't show trade ships unless it's turned on */ - if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) - continue; - - pr("%-25.25s %3d %3d %5d %4d $%d\n", - mp->m_name, mp->m_lcm, mp->m_hcm, - 20 + mp->m_lcm + mp->m_hcm * 2, - mp->m_tech, mp->m_cost); - } + register struct mchrstr *mp; + register int n; + + pr("%25s lcm hcm avail tech $\n", ""); + make_new_list(tlev, EF_SHIP); + for (n = 0; n < lookup_list_cnt; n++) { + mp = (struct mchrstr *)lookup_list[n].l_u.mp; + /* Can't show trade ships unless it's turned on */ + if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) + continue; + + pr("%-25.25s %3d %3d %5d %4d $%d\n", + mp->m_name, mp->m_lcm, mp->m_hcm, + 20 + mp->m_lcm + mp->m_hcm * 2, mp->m_tech, mp->m_cost); + } } void show_ship_stats(int tlev) { - register struct mchrstr *mp; - int scount; - int techdiff; - - pr("%25s s v s r f l p",""); - pr(" h"); - pr(" x"); - if (opt_FUEL) - pr(" fuel"); - pr("\n"); - - pr("%25s p i p n i n l",""); - pr(" e"); - pr(" p"); - if (opt_FUEL) - pr(" c/u"); - pr("\n"); - - pr("%25s def d s y g r d n",""); - pr(" l"); - pr(" l"); + register struct mchrstr *mp; + int scount; + int techdiff; + + pr("%25s s v s r f l p", ""); + pr(" h"); + pr(" x"); + if (opt_FUEL) + pr(" fuel"); + pr("\n"); + + pr("%25s p i p n i n l", ""); + pr(" e"); + pr(" p"); + if (opt_FUEL) + pr(" c/u"); + pr("\n"); + + pr("%25s def d s y g r d n", ""); + pr(" l"); + pr(" l"); + if (opt_FUEL) + pr(" "); + pr("\n"); + + + make_new_list(tlev, EF_SHIP); + for (scount = 0; scount < lookup_list_cnt; scount++) { + mp = (struct mchrstr *)lookup_list[scount].l_u.mp; + /* Can't show trade ships unless it's turned on */ + if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) + continue; + + techdiff = (int)(tlev - mp->m_tech); + pr("%-25.25s %3d %2d %2d %2d %2d %2d ", + mp->m_name, + (short)SHP_DEF(mp->m_armor, techdiff), + (short)SHP_SPD(mp->m_speed, techdiff), + (short)SHP_VIS(mp->m_visib, techdiff), + mp->m_vrnge, + (short)SHP_RNG(mp->m_frnge, techdiff), + (short)SHP_FIR(mp->m_glim, techdiff)); + + pr("%2d ", mp->m_nland); + pr("%2d ", mp->m_nplanes); + pr("%2d ", mp->m_nchoppers); + pr("%2d ", mp->m_nxlight); if (opt_FUEL) - pr(" "); + pr("%3d/%1d ", mp->m_fuelc, mp->m_fuelu); pr("\n"); - - - make_new_list(tlev, EF_SHIP); - for (scount = 0; scount < lookup_list_cnt; scount++) { - mp = (struct mchrstr *)lookup_list[scount].l_u.mp; - /* Can't show trade ships unless it's turned on */ - if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) - continue; - - techdiff = (int)(tlev - mp->m_tech); - pr("%-25.25s %3d %2d %2d %2d %2d %2d ", - mp->m_name, - (short)SHP_DEF(mp->m_armor, techdiff), - (short)SHP_SPD(mp->m_speed, techdiff), - (short)SHP_VIS(mp->m_visib, techdiff), - mp->m_vrnge, - (short)SHP_RNG(mp->m_frnge, techdiff), - (short)SHP_FIR(mp->m_glim, techdiff)); - - pr("%2d ", mp->m_nland); - pr("%2d ", mp->m_nplanes); - pr("%2d ", mp->m_nchoppers); - pr("%2d ", mp->m_nxlight); - if (opt_FUEL) - pr("%3d/%1d ", mp->m_fuelc,mp->m_fuelu); - pr("\n"); - } + } } void show_ship_capab(int tlev) { - register struct mchrstr *mp; - register u_short *ap; - register u_char *type; - register int i; - register int it; - int scount; - int n; - s_char c; - s_char *p; - - pr("%25s cargos & capabilities\n",""); - - make_new_list(tlev, EF_SHIP); - for (scount = 0; scount < lookup_list_cnt; scount++) { - mp = (struct mchrstr *)lookup_list[scount].l_u.mp; - /* Can't show trade ships unless it's turned on */ - if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) - continue; - - pr("%-25.25s ", mp->m_name); - - /* - * should use vector stuff - */ - for (ap = mp->m_vamt, type = mp->m_vtype, i = 0; - i < mp->m_nv; i++, ap++, type++) { - it = unitem((int) *type); - if (it > 0 && it <= I_MAX && ichr[it].i_name != 0) - c = ichr[it].i_name[0]; - else - c = '?'; - pr(" %d%c", *ap, c); - } - pr(" "); - for (i = n = 0; i < 32; i++) { - if (!(mp->m_flags & bit(i))) - continue; - if (NULL != (p = lookup(bit(i), ship_flags))) { - if (n++ > 0) - pr(" "); - pr(p); - } - } - pr("\n"); + register struct mchrstr *mp; + register u_short *ap; + register u_char *type; + register int i; + register int it; + int scount; + int n; + s_char c; + s_char *p; + + pr("%25s cargos & capabilities\n", ""); + + make_new_list(tlev, EF_SHIP); + for (scount = 0; scount < lookup_list_cnt; scount++) { + mp = (struct mchrstr *)lookup_list[scount].l_u.mp; + /* Can't show trade ships unless it's turned on */ + if ((mp->m_flags & M_TRADE) && !opt_TRADESHIPS) + continue; + + pr("%-25.25s ", mp->m_name); + + /* + * should use vector stuff + */ + for (ap = mp->m_vamt, type = mp->m_vtype, i = 0; + i < mp->m_nv; i++, ap++, type++) { + it = unitem((int)*type); + if (it > 0 && it <= I_MAX && ichr[it].i_name != 0) + c = ichr[it].i_name[0]; + else + c = '?'; + pr(" %d%c", *ap, c); } + pr(" "); + for (i = n = 0; i < 32; i++) { + if (!(mp->m_flags & bit(i))) + continue; + if (NULL != (p = lookup(bit(i), ship_flags))) { + if (n++ > 0) + pr(" "); + pr(p); + } + } + pr("\n"); + } } void show_plane_stats(int tlev) { - register struct plchrstr *pp; - int pcount; - - pr("%25s acc load att def ran fuel stlth\n", ""); - make_new_list(tlev, EF_PLANE); - for (pcount = 0; pcount < lookup_list_cnt; pcount++) { - pp = (struct plchrstr *)lookup_list[pcount].l_u.pp; - pr("%-25.25s %3d %4d %3d %3d %3d %4d ", - pp->pl_name, - (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)), - (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)), - (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)), - (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)), - (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)), - pp->pl_fuel); - pr("%4d%% ",pp->pl_stealth); - pr("\n"); - } + register struct plchrstr *pp; + int pcount; + + pr("%25s acc load att def ran fuel stlth\n", ""); + make_new_list(tlev, EF_PLANE); + for (pcount = 0; pcount < lookup_list_cnt; pcount++) { + pp = (struct plchrstr *)lookup_list[pcount].l_u.pp; + pr("%-25.25s %3d %4d %3d %3d %3d %4d ", + pp->pl_name, + (int)PLN_ACC(pp->pl_acc, (int)(tlev - pp->pl_tech)), + (int)PLN_LOAD(pp->pl_load, (int)(tlev - pp->pl_tech)), + (int)PLN_ATTDEF(pp->pl_att, (int)(tlev - pp->pl_tech)), + (int)PLN_ATTDEF(pp->pl_def, (int)(tlev - pp->pl_tech)), + (int)PLN_RAN(pp->pl_range, (int)(tlev - pp->pl_tech)), + pp->pl_fuel); + pr("%4d%% ", pp->pl_stealth); + pr("\n"); + } } void show_plane_capab(int tlev) { - register struct plchrstr *pp; - register int i; - int pcount; - int n; - s_char *p; - - pr("%25s capabilities\n",""); - make_new_list(tlev, EF_PLANE); - for (pcount = 0; pcount < lookup_list_cnt; pcount++) { - pp = (struct plchrstr *)lookup_list[pcount].l_u.pp; - pr("%-25.25s ", pp->pl_name); - - for (i = n = 0; i < 32; i++) { - if (!(pp->pl_flags & bit(i))) - continue; - if (NULL != (p = lookup(bit(i), plane_flags))) { - if (n++ > 0) - pr(" "); - pr(p); - } - } - pr("\n"); + register struct plchrstr *pp; + register int i; + int pcount; + int n; + s_char *p; + + pr("%25s capabilities\n", ""); + make_new_list(tlev, EF_PLANE); + for (pcount = 0; pcount < lookup_list_cnt; pcount++) { + pp = (struct plchrstr *)lookup_list[pcount].l_u.pp; + pr("%-25.25s ", pp->pl_name); + + for (i = n = 0; i < 32; i++) { + if (!(pp->pl_flags & bit(i))) + continue; + if (NULL != (p = lookup(bit(i), plane_flags))) { + if (n++ > 0) + pr(" "); + pr(p); + } } + pr("\n"); + } } void show_plane_build(int tlev) { - register struct plchrstr *pp; - register int pcount; - - pr("%25s lcm hcm crew avail tech $\n", ""); - make_new_list(tlev, EF_PLANE); - for (pcount = 0; pcount < lookup_list_cnt; pcount++) { - pp = (struct plchrstr *)lookup_list[pcount].l_u.pp; - pr("%-25.25s %3d %3d %3d %5d %4d $%d\n", - pp->pl_name, pp->pl_lcm, - pp->pl_hcm, pp->pl_crew, - 20 + 2 * pp->pl_hcm + pp->pl_lcm, - pp->pl_tech, pp->pl_cost); - } + register struct plchrstr *pp; + register int pcount; + + pr("%25s lcm hcm crew avail tech $\n", ""); + make_new_list(tlev, EF_PLANE); + for (pcount = 0; pcount < lookup_list_cnt; pcount++) { + pp = (struct plchrstr *)lookup_list[pcount].l_u.pp; + pr("%-25.25s %3d %3d %3d %5d %4d $%d\n", + pp->pl_name, pp->pl_lcm, + pp->pl_hcm, pp->pl_crew, + 20 + 2 * pp->pl_hcm + pp->pl_lcm, pp->pl_tech, pp->pl_cost); + } } void show_land_build(int tlev) { - register struct lchrstr *lp; - register int n; - - pr("%25s lcm hcm guns avail tech $\n", ""); - make_new_list(tlev, EF_LAND); - for (n = 0; n < lookup_list_cnt; n++) { - lp = (struct lchrstr *)lookup_list[n].l_u.lp; - if ((lp->l_flags & L_SPY) && !opt_LANDSPIES) - continue; - pr("%-25.25s %3d %3d %4d %5d %4d $%d\n", - lp->l_name, lp->l_lcm, - lp->l_hcm, - lp->l_gun, - 20 + lp->l_lcm + (lp->l_hcm * 2), - lp->l_tech, lp->l_cost); - } + register struct lchrstr *lp; + register int n; + + pr("%25s lcm hcm guns avail tech $\n", ""); + make_new_list(tlev, EF_LAND); + for (n = 0; n < lookup_list_cnt; n++) { + lp = (struct lchrstr *)lookup_list[n].l_u.lp; + if ((lp->l_flags & L_SPY) && !opt_LANDSPIES) + continue; + pr("%-25.25s %3d %3d %4d %5d %4d $%d\n", + lp->l_name, lp->l_lcm, + lp->l_hcm, + lp->l_gun, + 20 + lp->l_lcm + (lp->l_hcm * 2), lp->l_tech, lp->l_cost); + } } void show_land_capab(int tlev) { - struct lchrstr *lcp; - int lcount; - register u_short *ap; - register u_char *type; - register int i,n; - register int it; - register s_char *p,c; - - pr("%25s capabilities\n",""); - - make_new_list(tlev, EF_LAND); - for (lcount = 0; lcount < lookup_list_cnt; lcount++) { - lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp; - if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES) - continue; - - pr("%-25s ", lcp->l_name); - - /* - * should use vector stuff - */ - for (ap = lcp->l_vamt, type = lcp->l_vtype, i = 0; - i < lcp->l_nv; i++, ap++, type++) { - it = unitem((int) *type); - if (it > 0 && it <= I_MAX && ichr[it].i_name != 0) - c = ichr[it].i_name[0]; - else - c = '?'; - pr(" %d%c", *ap, c); - } - pr(" "); - for (i = n = 0; i < 32; i++) { - if (!(lcp->l_flags & bit(i))) - continue; - if (NULL != (p = lookup(bit(i), land_flags))) { - if (n++ > 0) - pr(" "); - pr(p); - } - } - pr("\n"); + struct lchrstr *lcp; + int lcount; + register u_short *ap; + register u_char *type; + register int i, n; + register int it; + register s_char *p, c; + + pr("%25s capabilities\n", ""); + + make_new_list(tlev, EF_LAND); + for (lcount = 0; lcount < lookup_list_cnt; lcount++) { + lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp; + if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES) + continue; + + pr("%-25s ", lcp->l_name); + + /* + * should use vector stuff + */ + for (ap = lcp->l_vamt, type = lcp->l_vtype, i = 0; + i < lcp->l_nv; i++, ap++, type++) { + it = unitem((int)*type); + if (it > 0 && it <= I_MAX && ichr[it].i_name != 0) + c = ichr[it].i_name[0]; + else + c = '?'; + pr(" %d%c", *ap, c); + } + pr(" "); + for (i = n = 0; i < 32; i++) { + if (!(lcp->l_flags & bit(i))) + continue; + if (NULL != (p = lookup(bit(i), land_flags))) { + if (n++ > 0) + pr(" "); + pr(p); + } } + pr("\n"); + } } void show_land_stats(int tlev) { - struct lchrstr *lcp; - int lcount; - int ourtlev; - -pr("%25s s v s r r a f a a x l\n",""); -pr("%25s p i p a n c i m a f f p n\n",""); -pr("%25s att def vul d s y d g c r m f c u l d\n",""); - - make_new_list(tlev, EF_LAND); - for (lcount = 0; lcount < lookup_list_cnt; lcount++) { - lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp; - if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES) - continue; - - ourtlev = (int)(tlev - lcp->l_tech); - pr("%-25s %1.1f %1.1f %3d ", - lcp->l_name, (float)LND_ATTDEF(lcp->l_att, ourtlev), - (float)LND_ATTDEF(lcp->l_def, ourtlev), - (int)LND_VUL(lcp->l_vul, ourtlev)); - pr("%2d %2d %2d %2d ", - (int)LND_SPD(lcp->l_spd, ourtlev), - (int)LND_VIS(lcp->l_vis, ourtlev), - (int)LND_SPY(lcp->l_spy, ourtlev), - (int)LND_RAD(lcp->l_rad, ourtlev)); - pr("%2d %2d %2d %2d %2d ", - (int)LND_FRG(lcp->l_frg, ourtlev), - (int)LND_ACC(lcp->l_acc, ourtlev), - (int)LND_DAM(lcp->l_dam, ourtlev), - (int)LND_AMM(lcp->l_ammo, lcp->l_dam, ourtlev), - (int)LND_AAF(lcp->l_aaf, ourtlev)); - pr("%2d %2d %2d %2d ", - (int)LND_FC(lcp->l_fuelc, ourtlev), - (int)LND_FU(lcp->l_fuelu, ourtlev), - (int)LND_XPL(lcp->l_nxlight, ourtlev), - (int)LND_MXL(lcp->l_mxland, ourtlev)); - - pr("\n"); - } + struct lchrstr *lcp; + int lcount; + int ourtlev; + + pr("%25s s v s r r a f a a x l\n", ""); + pr("%25s p i p a n c i m a f f p n\n", ""); + pr("%25s att def vul d s y d g c r m f c u l d\n", ""); + + make_new_list(tlev, EF_LAND); + for (lcount = 0; lcount < lookup_list_cnt; lcount++) { + lcp = (struct lchrstr *)lookup_list[lcount].l_u.lp; + if ((lcp->l_flags & L_SPY) && !opt_LANDSPIES) + continue; + + ourtlev = (int)(tlev - lcp->l_tech); + pr("%-25s %1.1f %1.1f %3d ", + lcp->l_name, (float)LND_ATTDEF(lcp->l_att, ourtlev), + (float)LND_ATTDEF(lcp->l_def, ourtlev), + (int)LND_VUL(lcp->l_vul, ourtlev)); + pr("%2d %2d %2d %2d ", + (int)LND_SPD(lcp->l_spd, ourtlev), + (int)LND_VIS(lcp->l_vis, ourtlev), + (int)LND_SPY(lcp->l_spy, ourtlev), + (int)LND_RAD(lcp->l_rad, ourtlev)); + pr("%2d %2d %2d %2d %2d ", + (int)LND_FRG(lcp->l_frg, ourtlev), + (int)LND_ACC(lcp->l_acc, ourtlev), + (int)LND_DAM(lcp->l_dam, ourtlev), + (int)LND_AMM(lcp->l_ammo, lcp->l_dam, ourtlev), + (int)LND_AAF(lcp->l_aaf, ourtlev)); + pr("%2d %2d %2d %2d ", + (int)LND_FC(lcp->l_fuelc, ourtlev), + (int)LND_FU(lcp->l_fuelu, ourtlev), + (int)LND_XPL(lcp->l_nxlight, ourtlev), + (int)LND_MXL(lcp->l_mxland, ourtlev)); + + pr("\n"); + } } void show_sect_build(int foo) { - register int x, first=1; - - for(x=5;x0) || (dchr[x].d_build!=1) || - (dchr[x].d_lcms>0) || (dchr[x].d_hcms>0)){ - if (first){ - pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n"); - first=0; - } - pr("%-14c %-14d %-17d %-14d %d\n", - dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build, - dchr[x].d_lcms, dchr[x].d_hcms); - } - } - pr("\n"); - pr("Infrastructure building - adding 1 point of efficiency costs:\n"); - pr(" type lcms hcms mobility $$$$\n"); - for (x = 0; intrchr[x].in_name; x++) { - pr("%-20s %4d %4d %8d %4d\n", intrchr[x].in_name, - intrchr[x].in_lcms, intrchr[x].in_hcms, - intrchr[x].in_mcost, intrchr[x].in_dcost); + register int x, first = 1; + + for (x = 5; x < SCT_MAXDEF + 2; x++) { + if (dchr[x].d_mnem == 0) + continue; + if ((dchr[x].d_cost > 0) || (dchr[x].d_build != 1) || + (dchr[x].d_lcms > 0) || (dchr[x].d_hcms > 0)) { + if (first) { + pr("sector type cost to des cost for 1%% eff lcms for 1%% hcms for 1%%\n"); + first = 0; + } + pr("%-14c %-14d %-17d %-14d %d\n", + dchr[x].d_mnem, dchr[x].d_cost, dchr[x].d_build, + dchr[x].d_lcms, dchr[x].d_hcms); } + } + pr("\n"); + pr("Infrastructure building - adding 1 point of efficiency costs:\n"); + pr(" type lcms hcms mobility $$$$\n"); + for (x = 0; intrchr[x].in_name; x++) { + pr("%-20s %4d %4d %8d %4d\n", intrchr[x].in_name, + intrchr[x].in_lcms, intrchr[x].in_hcms, + intrchr[x].in_mcost, intrchr[x].in_dcost); + } } void show_sect_stats(int foo) { - register int x, first=1; - struct sctstr sect; - struct natstr *natp; - - natp = getnatp(player->cnum); - /* We fake this */ - sect.sct_effic = 100; - for(x=0;xnat_level[NAT_RLEV], §)); + register int x, first = 1; + struct sctstr sect; + struct natstr *natp; + + natp = getnatp(player->cnum); + /* We fake this */ + sect.sct_effic = 100; + for (x = 0; x < SCT_MAXDEF + 2; x++) { + if (dchr[x].d_mnem == 0) + continue; + if (first) { + pr(" base max max -- packing bonus -- max\n"); + pr(" sector type mcost off def mil uw civ bar other pop\n"); + first = 0; } + sect.sct_type = x; + pr("%c %-23s %3d %5.2f %5.2f %3d %3d %3d %3d %5d %5d\n", + dchr[x].d_mnem, dchr[x].d_name, + dchr[x].d_mcst, dchr[x].d_ostr, + dchr[x].d_dstr, + ichr[I_MILIT].i_pkg[dchr[x].d_pkg], + ichr[I_UW].i_pkg[dchr[x].d_pkg], + ichr[I_CIVIL].i_pkg[dchr[x].d_pkg], + ichr[I_BAR].i_pkg[dchr[x].d_pkg], + ichr[I_LCM].i_pkg[dchr[x].d_pkg], + max_pop(natp->nat_level[NAT_RLEV], §)); + } } void show_sect_capab(int foo) { - register int x, first=1, i, j; - char *tmpstr; - char c; - char *outputs = " cmsgpidbfolhur"; - - for(x = 0; x < SCT_MAXDEF + 2; x++) { - if ((dchr[x].d_mnem == 0) || (dchr[x].d_prd == 0)) - continue; - if (first) { - pr(" --- level --- reso \n"); - pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n"); - first = 0; - } - - j = dchr[x].d_prd; - - pr("%c %-23s %-7s ", dchr[x].d_mnem, dchr[x].d_name, pchr[j].p_sname); - /*for(i=0;i 0)) { - pr("%2d %c ", pchr[j].p_vamt[i], - ichr[pchr[j].p_vtype[i] & (~VT_ITEM)].i_name[0]); - } else { - pr(" "); - } - } - switch(pchr[j].p_nlndx) { - case NAT_TLEV: - tmpstr = "tech"; - break; - case NAT_ELEV: - tmpstr = "edu"; - break; - case NAT_RLEV: - tmpstr = "res"; - break; - case NAT_HLEV: - tmpstr = "hap"; - break; - default: - tmpstr = " "; - break; - } - if (pchr[j].p_type) - c = outputs[pchr[j].p_type - VT_ITEM]; - else - c = ' '; - pr("%-5s %3d %3d %4d %3d %3d %c", - tmpstr, - pchr[j].p_nlmin, - pchr[j].p_nllag, - pchr[j].p_effic, - pchr[j].p_cost, - pchr[j].p_nrdep, - c); - - pr("\n"); + register int x, first = 1, i, j; + char *tmpstr; + char c; + char *outputs = " cmsgpidbfolhur"; + + for (x = 0; x < SCT_MAXDEF + 2; x++) { + if ((dchr[x].d_mnem == 0) || (dchr[x].d_prd == 0)) + continue; + if (first) { + pr(" --- level --- reso \n"); + pr(" sector type product use1 use2 use3 level min lag eff%% $$$ dep c\n"); + first = 0; } -} + j = dchr[x].d_prd; + + pr("%c %-23s %-7s ", dchr[x].d_mnem, dchr[x].d_name, + pchr[j].p_sname); + /*for(i=0;i 0)) { + pr("%2d %c ", pchr[j].p_vamt[i], + ichr[pchr[j].p_vtype[i] & (~VT_ITEM)].i_name[0]); + } else { + pr(" "); + } + } + switch (pchr[j].p_nlndx) { + case NAT_TLEV: + tmpstr = "tech"; + break; + case NAT_ELEV: + tmpstr = "edu"; + break; + case NAT_RLEV: + tmpstr = "res"; + break; + case NAT_HLEV: + tmpstr = "hap"; + break; + default: + tmpstr = " "; + break; + } + if (pchr[j].p_type) + c = outputs[pchr[j].p_type - VT_ITEM]; + else + c = ' '; + pr("%-5s %3d %3d %4d %3d %3d %c", + tmpstr, + pchr[j].p_nlmin, + pchr[j].p_nllag, + pchr[j].p_effic, pchr[j].p_cost, pchr[j].p_nrdep, c); + + pr("\n"); + } +} diff --git a/src/lib/subs/shpsub.c b/src/lib/subs/shpsub.c index d55a342a3..94bba0df3 100644 --- a/src/lib/subs/shpsub.c +++ b/src/lib/subs/shpsub.c @@ -58,16 +58,16 @@ extern int etu_per_update; void shp_sel(struct nstr_item *ni, struct emp_qelem *list) - - - /* int wantflags; - int nowantflags; - */ + + + /* int wantflags; + int nowantflags; + */ { - struct shpstr ship; - struct mchrstr *mcp; - struct mlist *mlp; - + struct shpstr ship; + struct mchrstr *mcp; + struct mlist *mlp; + emp_initque(list); while (nxtitem(ni, (s_char *)&ship)) { if (!player->owner) @@ -77,15 +77,16 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list) continue; if (nowantflags && mcp->m_flags & nowantflags) continue; - */ + */ if (opt_MARKET) { if (ontradingblock(EF_SHIP, (int *)&ship)) { - pr("ship #%d inelligible - it's for sale.\n", ship.shp_uid); + pr("ship #%d inelligible - it's for sale.\n", + ship.shp_uid); continue; } } /* This abuse is better fixed by building a ship with the normal negative - mobility that everything else is built with */ + mobility that everything else is built with */ /* if (opt_MOB_ACCESS) { if (ship.shp_effic < 21 && @@ -98,9 +99,9 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list) */ ship.shp_mission = 0; ship.shp_rflags = 0; - bzero(ship.shp_rpath,RET_LEN); + bzero(ship.shp_rpath, RET_LEN); putship(ship.shp_uid, &ship); - mlp = (struct mlist *) malloc(sizeof(struct mlist)); + mlp = (struct mlist *)malloc(sizeof(struct mlist)); mlp->mcp = mcp; bcopy((s_char *)&ship, (s_char *)&mlp->ship, sizeof(struct shpstr)); @@ -111,30 +112,30 @@ shp_sel(struct nstr_item *ni, struct emp_qelem *list) /* This function assumes that the list was created by shp_sel */ void -shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, int *togetherp, natid actor) +shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, + int *togetherp, natid actor) { extern int update_pending; - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - struct sctstr sect; - struct shpstr ship; - int vec[I_MAX+1]; - coord allx; - coord ally; - int first=1; - + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + struct sctstr sect; + struct shpstr ship; + int vec[I_MAX + 1]; + coord allx; + coord ally; + int first = 1; + *minmobp = 9876.0; *maxmobp = -9876.0; *togetherp = 1; for (qp = list->q_back; qp != list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; getship(mlp->ship.shp_uid, &ship); if (ship.shp_own != actor) { mpr(actor, "%s was sunk at %s\n", - prship(&ship), - xyas(ship.shp_x, ship.shp_y, actor)); + prship(&ship), xyas(ship.shp_x, ship.shp_y, actor)); emp_remque((struct emp_qelem *)mlp); free((s_char *)mlp); continue; @@ -153,7 +154,7 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, int *togetherp continue; } if (!getsect(ship.shp_x, ship.shp_y, §)) { - shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */ + shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */ continue; } switch (shp_check_nav(§)) { @@ -170,13 +171,12 @@ shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp, int *togetherp shp_mess("was just swallowed by a big green worm", mlp); continue; } - if (first){ + if (first) { allx = ship.shp_x; ally = ship.shp_y; first = 0; } - if (ship.shp_x != allx || - ship.shp_y != ally) + if (ship.shp_x != allx || ship.shp_y != ally) *togetherp = 0; if (ship.shp_mobil + 1 < (int)mlp->mobil) { mlp->mobil = (double)ship.shp_mobil; @@ -195,11 +195,11 @@ shp_put(struct emp_qelem *list, natid actor) { register struct emp_qelem *qp; register struct emp_qelem *newqp; - struct mlist *mlp; - + struct mlist *mlp; + qp = list->q_back; - while (qp != list) { - mlp = (struct mlist *) qp; + while (qp != list) { + mlp = (struct mlist *)qp; mpr(actor, "%s stopped at %s\n", prship(&mlp->ship), xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own)); mlp->ship.shp_mobil = (int)mlp->mobil; @@ -214,21 +214,22 @@ shp_put(struct emp_qelem *list, natid actor) int shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - struct sctstr sect; - int mines, m, max, shells; - int changed = 0; + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + struct sctstr sect; + int mines, m, max, shells; + int changed = 0; int stopping = 0; - double mobcost; - - for (qp=ship_list->q_back;qp!=ship_list;qp=next) { + double mobcost; + + for (qp = ship_list->q_back; qp != ship_list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; if (!(mlp->mcp->m_flags & M_SWEEP)) { if (verbose) - mpr(actor, "%s doesn't have minesweeping capability!\n", prship(&mlp->ship)); + mpr(actor, "%s doesn't have minesweeping capability!\n", + prship(&mlp->ship)); continue; } if (mlp->mobil <= 0.0) { @@ -236,40 +237,38 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor) mpr(actor, "%s is out of mobility!\n", prship(&mlp->ship)); continue; } - getsect(mlp->ship.shp_x,mlp->ship.shp_y,§); + getsect(mlp->ship.shp_x, mlp->ship.shp_y, §); if (sect.sct_type != SCT_WATER) { if (verbose) - mpr(actor, "%s is not at sea. No mines there!\n", prship(&mlp->ship)); + mpr(actor, "%s is not at sea. No mines there!\n", + prship(&mlp->ship)); continue; - } + } mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed; mobcost = 480.0 / (mobcost + - techfact(mlp->ship.shp_tech,mobcost)); + techfact(mlp->ship.shp_tech, mobcost)); mlp->mobil -= mobcost; mlp->ship.shp_mobil = (int)mlp->mobil; putship(mlp->ship.shp_uid, &mlp->ship); - if (!(mines=getvar(V_MINE,(s_char *)§,EF_SECTOR))) + if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR))) continue; max = vl_find(V_SHELL, mlp->mcp->m_vtype, mlp->mcp->m_vamt, (int)mlp->mcp->m_nv); shells = getvar(V_SHELL, (s_char *)&mlp->ship, EF_SHIP); - for (m=0; mines > 0 && m < 5; m++) { + for (m = 0; mines > 0 && m < 5; m++) { if (chance(0.66)) { mpr(actor, "Sweep...\n"); mines--; shells = min(max, shells + 1); - changed |= map_set(actor, - sect.sct_x, - sect.sct_y, - 'X', 0); + changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0); } } putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); putvar(V_SHELL, shells, (s_char *)&mlp->ship, EF_SHIP); if (shp_check_one_mines(mlp)) { - stopping = 1; - emp_remque(qp); - free((s_char *)qp); + stopping = 1; + emp_remque(qp); + free((s_char *)qp); } putship(mlp->ship.shp_uid, &mlp->ship); putsect(§); @@ -282,47 +281,47 @@ shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor) int shp_check_one_mines(struct mlist *mlp) { - struct sctstr sect; - int mines; - int changed = 0; - int actor; + struct sctstr sect; + int mines; + int changed = 0; + int actor; - getsect(mlp->ship.shp_x, mlp->ship.shp_y, §); - if (sect.sct_type != SCT_WATER) - return 0; - if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR))) + getsect(mlp->ship.shp_x, mlp->ship.shp_y, §); + if (sect.sct_type != SCT_WATER) + return 0; + if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR))) + return 0; + if (chance(DMINE_HITCHANCE(mines))) { + actor = mlp->ship.shp_own; + shp_hit_mine(&mlp->ship, mlp->mcp); + mines--; + changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0); + if (changed) + writemap(actor); + putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); + putsect(§); + putship(mlp->ship.shp_uid, (s_char *)&mlp->ship); + if (!mlp->ship.shp_own) + return 1; + } return 0; - if (chance(DMINE_HITCHANCE(mines))) { - actor = mlp->ship.shp_own; - shp_hit_mine(&mlp->ship, mlp->mcp); - mines--; - changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0); - if (changed) - writemap(actor); - putvar(V_MINE, mines, (s_char *)§, EF_SECTOR); - putsect(§); - putship(mlp->ship.shp_uid, (s_char *)&mlp->ship); - if (!mlp->ship.shp_own) - return 1; - } - return 0; } int shp_check_mines(struct emp_qelem *ship_list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - int stopping = 0; - - for (qp=ship_list->q_back;qp!=ship_list;qp=next) { + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + int stopping = 0; + + for (qp = ship_list->q_back; qp != ship_list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; if (shp_check_one_mines(mlp)) { - stopping = 1; - emp_remque(qp); - free((s_char *)qp); + stopping = 1; + emp_remque(qp); + free((s_char *)qp); } } return stopping; @@ -331,17 +330,17 @@ shp_check_mines(struct emp_qelem *ship_list) void shp_list(struct emp_qelem *ship_list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - struct shpstr *shp; - int vec[I_MAX+1]; - + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + struct shpstr *shp; + int vec[I_MAX + 1]; + pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n"); - - for (qp=ship_list->q_back;qp!=ship_list;qp=next) { + + for (qp = ship_list->q_back; qp != ship_list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; shp = &mlp->ship; pr("%4d ", shp->shp_uid); pr("%-16.16s ", mlp->mcp->m_name); @@ -354,8 +353,8 @@ shp_list(struct emp_qelem *ship_list) pr("%4d", vec[I_GUN]); count_planes(shp); pr("%3d", shp->shp_nplane); - pr("%3d",shp->shp_nchoppers); - pr("%3d",shp->shp_nxlight); + pr("%3d", shp->shp_nchoppers); + pr("%3d", shp->shp_nxlight); count_units(shp); pr("%3d", shp->shp_nland); pr("%4d", shp->shp_mobil); @@ -363,7 +362,7 @@ shp_list(struct emp_qelem *ship_list) } } -void +void shp_mess(s_char *str, struct mlist *mlp) { mpr(mlp->ship.shp_own, "%s %s & stays in %s\n", @@ -379,11 +378,11 @@ int shp_check_nav(struct sctstr *sect) { extern struct dchrstr dchr[]; - + switch (dchr[sect->sct_type].d_flg & 03) { case NAVOK: break; - + case NAV_02: if (sect->sct_effic < 2) return CN_CONSTRUCTION; @@ -399,23 +398,24 @@ shp_check_nav(struct sctstr *sect) } static int -shp_count(struct emp_qelem *list, int wantflags, int nowantflags, int x, int y) +shp_count(struct emp_qelem *list, int wantflags, int nowantflags, int x, + int y) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - int count = 0; - + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + int count = 0; + for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - mlp = (struct mlist *) qp; - if (mlp->ship.shp_x != x || mlp->ship.shp_y != y) - continue; - if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) - continue; - if (nowantflags && mlp->mcp->m_flags & nowantflags) - continue; - ++count; + next = qp->q_back; + mlp = (struct mlist *)qp; + if (mlp->ship.shp_x != x || mlp->ship.shp_y != y) + continue; + if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) + continue; + if (nowantflags && mlp->mcp->m_flags & nowantflags) + continue; + ++count; } return count; } @@ -432,41 +432,44 @@ shp_damage_one(struct mlist *mlp, int dam) } static int -shp_damage(struct emp_qelem *list, int totdam, int wantflags, int nowantflags, int x, int y) +shp_damage(struct emp_qelem *list, int totdam, int wantflags, + int nowantflags, int x, int y) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - int dam; - int count; - - if (!totdam || !(count = shp_count(list, wantflags, nowantflags, x, y))) - return 0; - dam = ldround(((double)totdam/(double)count),1); + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + int dam; + int count; + + if (!totdam + || !(count = shp_count(list, wantflags, nowantflags, x, y))) + return 0; + dam = ldround(((double)totdam / (double)count), 1); for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - mlp = (struct mlist *) qp; - if (mlp->ship.shp_x != x || mlp->ship.shp_y != y) - continue; - if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) - continue; - if (nowantflags && mlp->mcp->m_flags & nowantflags) - continue; - shp_damage_one(mlp, dam); + next = qp->q_back; + mlp = (struct mlist *)qp; + if (mlp->ship.shp_x != x || mlp->ship.shp_y != y) + continue; + if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) + continue; + if (nowantflags && mlp->mcp->m_flags & nowantflags) + continue; + shp_damage_one(mlp, dam); } return dam; } static int -shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags, int nowantflags) +shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags, + int nowantflags) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + for (qp = list->q_back; qp != list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; /* If the ship isn't in the requested sector, then continue */ if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y) continue; @@ -482,21 +485,20 @@ shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags, int nowa static struct mlist * most_valuable_ship(struct emp_qelem *list) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - struct mlist *mvs = 0; - + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + struct mlist *mvs = 0; + for (qp = list->q_back; qp != list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; if (mlp->mcp->m_flags & M_SUB) continue; if (!mlp->mcp->m_nxlight && !mlp->mcp->m_nchoppers && mlp->mcp->m_cost < 1000 && - !mlp->mcp->m_nplanes && - !mlp->mcp->m_nland) + !mlp->mcp->m_nplanes && !mlp->mcp->m_nland) continue; if (!mvs) { mvs = mlp; @@ -509,52 +511,54 @@ most_valuable_ship(struct emp_qelem *list) return mvs; } -static int shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags) +static int +shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - int hard; - int easiest = 9876; /* things start great for victim */ - int count = 0; - + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + int hard; + int easiest = 9876; /* things start great for victim */ + int count = 0; + for (qp = list->q_back; qp != list; qp = next) { next = qp->q_back; - mlp = (struct mlist *) qp; + mlp = (struct mlist *)qp; if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags) continue; if (nowantflags && mlp->mcp->m_flags & nowantflags) continue; hard = shp_hardtarget(&mlp->ship); if (hard < easiest) - easiest = hard; /* things get worse for victim */ + easiest = hard; /* things get worse for victim */ ++count; } return easiest - count; } static int -shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, natid victim) +shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, + natid victim) { - int dam; - int twotries; - int stopping = 0; - struct emp_qelem msl_list, *qp, *newqp; - struct mlist *mvs; - s_char what[512]; - - msl_sel(&msl_list, newx, newy, victim, P_T|P_MAR, 0, MI_INTERDICT); - + int dam; + int twotries; + int stopping = 0; + struct emp_qelem msl_list, *qp, *newqp; + struct mlist *mvs; + s_char what[512]; + + msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT); + twotries = 0; while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) { sprintf(what, "%s", prship(&mvs->ship)); dam = msl_launch_mindam(&msl_list, newx, newy, shp_hardtarget(&mvs->ship), - EF_SHIP, - 1, - what, victim, MI_INTERDICT); + EF_SHIP, 1, what, victim, MI_INTERDICT); if (dam) { - mpr(victim, "missile interdiction mission does %d damage to %s!\n", dam, what); + mpr(victim, + "missile interdiction mission does %d damage to %s!\n", + dam, what); shp_damage_one(mvs, dam); twotries = 0; stopping |= 1; @@ -563,13 +567,13 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, natid v } } qp = msl_list.q_forw; - while(qp != msl_list.q_forw) { - newqp=qp->q_forw; + while (qp != msl_list.q_forw) { + newqp = qp->q_forw; emp_remque(qp); free(qp); qp = newqp; } - + return stopping; } @@ -580,138 +584,136 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy, natid v static int notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp) { - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - struct natstr *natp; - int vrange; - - natp = getnatp(sectp->sct_own); - - vrange = sectp->sct_type==SCT_RADAR?14:4; + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + struct natstr *natp; + int vrange; + + natp = getnatp(sectp->sct_own); + + vrange = sectp->sct_type == SCT_RADAR ? 14 : 4; vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0; - + if (vrange < 1) - vrange = 1; - + vrange = 1; + if (vrange < trange) - return 0; - - /* We got here, so we could theoretically see the ship. Now, - * do we want to see it in our telebox? If not, return positive - * since we could see the ship and want forts to fire. */ - if (!(natp->nat_flags & NF_COASTWATCH)) - return 1; + return 0; + + /* We got here, so we could theoretically see the ship. Now, + * do we want to see it in our telebox? If not, return positive + * since we could see the ship and want forts to fire. */ + if (!(natp->nat_flags & NF_COASTWATCH)) + return 1; for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - mlp = (struct mlist *) qp; - if (mlp->mcp->m_flags & M_SUB) - continue; - wu(0, sectp->sct_own, - "%s %s sighted at %s\n", - cname(mlp->ship.shp_own), - prship(&mlp->ship), - xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own)); - if (opt_HIDDEN) { - setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_LOOK); - } + next = qp->q_back; + mlp = (struct mlist *)qp; + if (mlp->mcp->m_flags & M_SUB) + continue; + wu(0, sectp->sct_own, + "%s %s sighted at %s\n", + cname(mlp->ship.shp_own), + prship(&mlp->ship), + xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own)); + if (opt_HIDDEN) { + setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_LOOK); + } } - + return 1; } static int -shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy, natid victim) +shp_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; - double range, range2, guneff; - int shell, gun; - int dam; - int totdam = 0; - s_char notified[MAXNOC]; - int i; - + extern int fort_max_interdiction_range; + struct nstr_sect ns; + struct sctstr fsect; + int trange; + double range, range2, guneff; + int shell, gun; + int dam; + int totdam = 0; + s_char notified[MAXNOC]; + int i; + /* Inform neutral and worse */ for (i = 0; i < MAXNOC; ++i) { - if (getrel(getnatp(i),victim) <= NEUTRAL) - notified[i] = 0; - else - notified[i] = 1; + if (getrel(getnatp(i), victim) <= NEUTRAL) + notified[i] = 0; + else + notified[i] = 1; } - - snxtsct_dist(&ns,newx,newy,fort_max_interdiction_range); - while (nxtsct(&ns,&fsect)){ - if (!fsect.sct_own) - continue; - if (fsect.sct_own == victim) - continue; - if (notified[fsect.sct_own]) - continue; - trange = mapdist(newx, newy, - fsect.sct_x, fsect.sct_y); - if (notify_coastguard(list, trange, &fsect)) - notified[fsect.sct_own] = 1; + + snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range); + while (nxtsct(&ns, &fsect)) { + if (!fsect.sct_own) + continue; + if (fsect.sct_own == victim) + continue; + if (notified[fsect.sct_own]) + continue; + trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y); + if (notify_coastguard(list, trange, &fsect)) + notified[fsect.sct_own] = 1; } - if (opt_NO_FORT_FIRE) return 0; /* Only coastwatch notify in nofortfire */ + if (opt_NO_FORT_FIRE) + return 0; /* Only coastwatch notify in nofortfire */ /* Only fire at Hostile ships */ for (i = 0; i < MAXNOC; ++i) { - if (getrel(getnatp(i),victim) >= NEUTRAL) - notified[i] = 0; - } - snxtsct_dist(&ns,newx,newy,fort_max_interdiction_range); - while (nxtsct(&ns,&fsect)){ - if (!notified[fsect.sct_own]) - continue; - if (fsect.sct_type != SCT_FORTR) - continue; - gun=getvar(V_GUN,(s_char *)&fsect,EF_SECTOR); - if (gun < 1) - continue; - range = tfactfire(fsect.sct_own,(double)min(gun,7)); - if (fsect.sct_effic > 59) - range++; - range2 = roundrange(range); - trange = mapdist(newx, newy, - fsect.sct_x, fsect.sct_y); - if (trange > range2) - continue; - if (getvar(V_MILIT,(s_char *)&fsect,EF_SECTOR)<5) - continue; - shell = getvar(V_SHELL,(s_char *)&fsect,EF_SECTOR); - 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); - putsect(&fsect); - if (gun > 7) - gun = 7; - guneff = landgun((int)fsect.sct_effic, gun); - dam = (int)guneff; - totdam += dam; - mpr(victim, "Incoming fire does %d damage!\n", dam); + if (getrel(getnatp(i), victim) >= NEUTRAL) + notified[i] = 0; + } + snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range); + while (nxtsct(&ns, &fsect)) { + if (!notified[fsect.sct_own]) + continue; + if (fsect.sct_type != SCT_FORTR) + continue; + gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR); + if (gun < 1) + continue; + range = tfactfire(fsect.sct_own, (double)min(gun, 7)); + if (fsect.sct_effic > 59) + range++; + range2 = roundrange(range); + trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y); + if (trange > range2) + continue; + if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5) + continue; + shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR); + 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); + putsect(&fsect); + if (gun > 7) + gun = 7; + guneff = landgun((int)fsect.sct_effic, gun); + dam = (int)guneff; + totdam += dam; + mpr(victim, "Incoming fire does %d damage!\n", dam); /* mpr(victim, "%s fires at you for %d!\n", xyas(fsect.sct_x,fsect.sct_y,victim), dam); */ - wu(0,fsect.sct_own, - "%s fires at %s ships in %s for %d!\n", - xyas(fsect.sct_x,fsect.sct_y, - fsect.sct_own), - cname(victim), - xyas(newx,newy,fsect.sct_own), dam); - nreport(fsect.sct_own, N_SHP_SHELL, victim, 1); + wu(0, fsect.sct_own, + "%s fires at %s ships in %s for %d!\n", + xyas(fsect.sct_x, fsect.sct_y, + fsect.sct_own), + cname(victim), xyas(newx, newy, fsect.sct_own), dam); + nreport(fsect.sct_own, N_SHP_SHELL, victim, 1); } if (totdam > 0) - return shp_damage(list, totdam, 0, M_SUB, newx, newy); + return shp_damage(list, totdam, 0, M_SUB, newx, newy); return 0; } @@ -719,70 +721,83 @@ int shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim) { int stopping = 0; - + if (shp_contains(list, newx, newy, 0, M_SUB)) { - stopping |= shp_fort_interdiction(list, newx, newy, victim); - - if (shp_contains(list, newx, newy, 0, M_SUB)) { - stopping |= shp_damage(list, unit_interdict(newx,newy,victim,"ships", shp_easiest_target(list, 0, M_SUB), MI_INTERDICT), 0, M_SUB, newx, newy); - if (most_valuable_ship(list)) { - stopping |= shp_missile_interdiction(list,newx,newy,victim); - } - } - } - if (shp_contains(list, newx, newy, M_SUB, 0)) { - stopping |= shp_damage(list, unit_interdict(newx, newy, victim, "subs", shp_easiest_target(list, M_SUB, 0), MI_SINTERDICT), M_SUB, 0, newx, newy); + stopping |= shp_fort_interdiction(list, newx, newy, victim); + + if (shp_contains(list, newx, newy, 0, M_SUB)) { + stopping |= + shp_damage(list, + unit_interdict(newx, newy, victim, "ships", + shp_easiest_target(list, 0, + M_SUB), + MI_INTERDICT), 0, M_SUB, newx, + newy); + if (most_valuable_ship(list)) { + stopping |= + shp_missile_interdiction(list, newx, newy, victim); + } } - return stopping; + } + if (shp_contains(list, newx, newy, M_SUB, 0)) { + stopping |= + shp_damage(list, + unit_interdict(newx, newy, victim, "subs", + shp_easiest_target(list, M_SUB, 0), + MI_SINTERDICT), M_SUB, 0, newx, + newy); + } + return stopping; } /* high value of hardtarget is harder to hit */ -int shp_hardtarget(struct shpstr *sp) +int +shp_hardtarget(struct shpstr *sp) { - struct sctstr sect; - int vis, onsea; - struct mchrstr *mcp = mchr + sp->shp_type; - + struct sctstr sect; + int vis, onsea; + struct mchrstr *mcp = mchr + sp->shp_type; + vis = sp->shp_visib; - getsect(sp->shp_x,sp->shp_y, §); + getsect(sp->shp_x, sp->shp_y, §); onsea = (sect.sct_type == SCT_WATER); if (mcp->m_flags & M_SUB) vis *= 4; - return (int)(((double)sp->shp_effic/100.0) * - (20 + (double)sp->shp_speed * onsea/2.0 - vis)); + return (int)(((double)sp->shp_effic / 100.0) * + (20 + (double)sp->shp_speed * onsea / 2.0 - vis)); } int shp_hit_mine(struct shpstr *sp, struct mchrstr *mcp) { - double m; - + double m; + mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n", xyas(sp->shp_x, sp->shp_y, sp->shp_own)); - + nreport(sp->shp_own, N_HIT_MINE, 0, 1); - + m = 22.0 + (double)(random() % 21); if (mcp->m_flags & M_SWEEP) m /= 2.0; - - shipdamage(sp, ldround(m,1)); - + + shipdamage(sp, ldround(m, 1)); + return (int)m; } void shp_view(struct emp_qelem *list) { - struct sctstr sect; - struct emp_qelem *qp; - struct emp_qelem *next; - struct mlist *mlp; - - for (qp=list->q_back;qp!=list;qp=next) { + struct sctstr sect; + struct emp_qelem *qp; + struct emp_qelem *next; + struct mlist *mlp; + + for (qp = list->q_back; qp != list; qp = next) { next = qp->q_back; mlp = (struct mlist *)qp; - getsect(mlp->ship.shp_x,mlp->ship.shp_y,§); + getsect(mlp->ship.shp_x, mlp->ship.shp_y, §); if (mlp->mcp->m_flags & M_FOOD) mpr(mlp->ship.shp_own, "[fert:%d] ", sect.sct_fertil); if (mlp->mcp->m_flags & M_OIL) @@ -790,119 +805,120 @@ shp_view(struct emp_qelem *list) mpr(mlp->ship.shp_own, "%s @ %s %d%% %s\n", prship(&mlp->ship), xyas(mlp->ship.shp_x, mlp->ship.shp_y, player->cnum), - sect.sct_effic, - dchr[sect.sct_type].d_name); + sect.sct_effic, dchr[sect.sct_type].d_name); } } int -shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor, int together) +shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor, + int together) { - struct sctstr sect; - struct emp_qelem *qp; - struct emp_qelem *next; - struct emp_qelem *nqp; - struct emp_qelem *nnext; - struct mlist *mlp; - coord dx; - coord dy; - coord newx; - coord newy; - int stopping = 0; - double mobcost; - double tech; /* for mapping */ - double tf; /* for mapping */ - s_char dp[80]; - + struct sctstr sect; + struct emp_qelem *qp; + struct emp_qelem *next; + struct emp_qelem *nqp; + struct emp_qelem *nnext; + struct mlist *mlp; + coord dx; + coord dy; + coord newx; + coord newy; + int stopping = 0; + double mobcost; + double tech; /* for mapping */ + double tf; /* for mapping */ + s_char dp[80]; + if (dir <= DIR_STOP || dir >= DIR_VIEW) { - shp_put(list, actor); - return 1; + shp_put(list, actor); + return 1; } dx = diroff[dir][0]; dy = diroff[dir][1]; - for (qp=list->q_back;qp!=list;qp=next) { - next = qp->q_back; - mlp = (struct mlist *)qp; - newx = xnorm(mlp->ship.shp_x + dx); - newy = ynorm(mlp->ship.shp_y + dy); - getsect(newx, newy, §); - if (shp_check_nav(§) != CN_NAVIGABLE || - (sect.sct_own && actor != sect.sct_own && - getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) { - if (together) { - mpr(actor,"can't go to %s\n",xyas(newx, newy, actor)); - return 2; - } else { - sprintf(dp, "can't go to %s", - xyas(newx, newy, actor)); - shp_mess(dp, mlp); - continue; - } - } - if (opt_BIG_CITY && sect.sct_type == SCT_CAPIT) { - if (mlp->mcp->m_lcm + 2 * mlp->mcp->m_hcm >= 60) { - sprintf(dp, "is too large to fit into the canal system at %s", xyas(newx, newy, actor)); - shp_mess(dp, mlp); - continue; - } - } - if (mlp->mobil <= 0.0) { - shp_mess("is out of mobility", mlp); - continue; - } - mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed; - mobcost = 480.0 / - (mobcost + techfact(mlp->ship.shp_tech, mobcost)); - mlp->ship.shp_x = newx; - mlp->ship.shp_y = newy; - if (mlp->mobil - mobcost < -127) { - mlp->mobil = -127; - } else { - mlp->mobil -= mobcost; - } - mlp->ship.shp_mobil = (int)mlp->mobil; - putship(mlp->ship.shp_uid, &mlp->ship); - mlp->done = 0; /* We haven't interdicted this ship yet */ - - /* Now update the map for this ship */ - tech = techfact(mlp->ship.shp_tech, (double)mlp->mcp->m_vrnge); - if (mlp->mcp->m_flags & M_SONAR) - tf = techfact(mlp->ship.shp_tech, 1.0); - else - tf = 0.0; - radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y, - (int)mlp->ship.shp_effic, (int)tech, tf); + for (qp = list->q_back; qp != list; qp = next) { + next = qp->q_back; + mlp = (struct mlist *)qp; + newx = xnorm(mlp->ship.shp_x + dx); + newy = ynorm(mlp->ship.shp_y + dy); + getsect(newx, newy, §); + if (shp_check_nav(§) != CN_NAVIGABLE || + (sect.sct_own && actor != sect.sct_own && + getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) { + if (together) { + mpr(actor, "can't go to %s\n", xyas(newx, newy, actor)); + return 2; + } else { + sprintf(dp, "can't go to %s", xyas(newx, newy, actor)); + shp_mess(dp, mlp); + continue; + } + } + if (opt_BIG_CITY && sect.sct_type == SCT_CAPIT) { + if (mlp->mcp->m_lcm + 2 * mlp->mcp->m_hcm >= 60) { + sprintf(dp, + "is too large to fit into the canal system at %s", + xyas(newx, newy, actor)); + shp_mess(dp, mlp); + continue; + } + } + if (mlp->mobil <= 0.0) { + shp_mess("is out of mobility", mlp); + continue; + } + mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed; + mobcost = 480.0 / + (mobcost + techfact(mlp->ship.shp_tech, mobcost)); + mlp->ship.shp_x = newx; + mlp->ship.shp_y = newy; + if (mlp->mobil - mobcost < -127) { + mlp->mobil = -127; + } else { + mlp->mobil -= mobcost; + } + mlp->ship.shp_mobil = (int)mlp->mobil; + putship(mlp->ship.shp_uid, &mlp->ship); + mlp->done = 0; /* We haven't interdicted this ship yet */ + + /* Now update the map for this ship */ + tech = techfact(mlp->ship.shp_tech, (double)mlp->mcp->m_vrnge); + if (mlp->mcp->m_flags & M_SONAR) + tf = techfact(mlp->ship.shp_tech, 1.0); + else + tf = 0.0; + radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y, + (int)mlp->ship.shp_effic, (int)tech, tf); } if (QEMPTY(list)) - return stopping; + return stopping; stopping |= shp_sweep(list, 0, actor); if (QEMPTY(list)) - return stopping; + return stopping; stopping |= shp_check_mines(list); if (QEMPTY(list)) - return stopping; - + return stopping; + /* Ok, run through each ship and interdict each coordinate */ for (qp = list->q_back; qp != list; qp = next) { - next = qp->q_back; - mlp = (struct mlist *) qp; + next = qp->q_back; + mlp = (struct mlist *)qp; /* Has this ship been interdicted yet? */ - if (mlp->done) - continue; - newx = mlp->ship.shp_x; - newy = mlp->ship.shp_y; - stopping |= shp_interdict(list, newx, newy, actor); - if (QEMPTY(list)) - return stopping; + if (mlp->done) + continue; + newx = mlp->ship.shp_x; + newy = mlp->ship.shp_y; + stopping |= shp_interdict(list, newx, newy, actor); + if (QEMPTY(list)) + return stopping; /* Now, set all ships in this coordinate to done */ - for (nqp = list->q_back; nqp != list; nqp = nnext) { - nnext = nqp->q_back; - mlp = (struct mlist *)nqp; - if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy) - mlp->done = 1; - } + for (nqp = list->q_back; nqp != list; nqp = nnext) { + nnext = nqp->q_back; + mlp = (struct mlist *)nqp; + if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy) + mlp->done = 1; + } } - + return stopping; } @@ -919,93 +935,94 @@ int shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget) { struct nstr_item ni; - struct shpstr ship; - int hitchance; - int vec[I_MAX+1]; - double gun,eff,teff; - - snxtitem_dist(&ni,EF_SHIP,dx,dy,1); - - while (nxtitem(&ni,(caddr_t)&ship)) { + struct shpstr ship; + int hitchance; + int vec[I_MAX + 1]; + double gun, eff, teff; + + snxtitem_dist(&ni, EF_SHIP, dx, dy, 1); + + while (nxtitem(&ni, (caddr_t)&ship)) { if (!ship.shp_own) continue; - + if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE)) continue; - + if (getrel(getnatp(ship.shp_own), bombown) >= NEUTRAL) continue; - + if (ship.shp_effic < 60) continue; - - if (getvec(VT_ITEM,vec,(caddr_t)&ship,EF_SHIP) < 0) + + if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 0) continue; - if (vec[I_MILIT] < 1) /* do we have mil? */ + if (vec[I_MILIT] < 1) /* do we have mil? */ continue; - if (vec[I_SHELL] < 2) { /* do we need shells */ + if (vec[I_SHELL] < 2) { /* do we need shells */ if (vec[I_SHELL] += supply_commod(ship.shp_own, ship.shp_x, - ship.shp_y, - I_SHELL,2) < 2) + ship.shp_y, I_SHELL, 2) < 2) continue; } - if (vec[I_GUN] < 1) /* we need at least 1 gun */ + if (vec[I_GUN] < 1) /* we need at least 1 gun */ continue; - + /* now calculate the odds */ - gun = ((double)min(vec[I_GUN],ship.shp_glim)); - eff = (double)ship.shp_effic / 100.0; - teff = (((double)ship.shp_tech)/(((double)ship.shp_tech)+200.0)); + gun = ((double)min(vec[I_GUN], ship.shp_glim)); + eff = (double)ship.shp_effic / 100.0; + teff = + (((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0)); /* raise 4.5 for better interception -KHS */ - hitchance = (int)(gun*eff*teff*4.5) - hardtarget; + hitchance = (int)(gun * eff * teff * 4.5) - hardtarget; if (hitchance < 0) hitchance = 0; if (hitchance > 100) hitchance = 100; - - mpr(bombown,"%s anti-missile system activated...",cname(ship.shp_own)); - mpr(ship.shp_own, - "Ship #%i anti-missile system activated!\n",ship.shp_uid); - mpr(ship.shp_own, - "%d%% hitchance...", hitchance); + + mpr(bombown, "%s anti-missile system activated...", + cname(ship.shp_own)); + mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n", + ship.shp_uid); + mpr(ship.shp_own, "%d%% hitchance...", hitchance); /* use ammo */ - putvar (V_SHELL, vec[I_SHELL]-2,(caddr_t)&ship, EF_SHIP); - putship(ship.shp_uid,&ship); - + putvar(V_SHELL, vec[I_SHELL] - 2, (caddr_t)&ship, EF_SHIP); + putship(ship.shp_uid, &ship); + if (roll(100) <= hitchance) { - mpr(bombown,"KABOOOM!! Missile destroyed\n\n"); + mpr(bombown, "KABOOOM!! Missile destroyed\n\n"); mpr(ship.shp_own, "KABOOOM!! Incoming missile destroyed!\n\n"); return 1; } else { mpr(bombown, "SWOOSH!! anti-missile system failed!!\n"); mpr(ship.shp_own, - "SWOOSH!! Missile evades anti-missile systems\n\n"); + "SWOOSH!! Missile evades anti-missile systems\n\n"); } } - return 0; /* all attempts failed */ + return 0; /* all attempts failed */ } s_char * shp_path(int together, struct shpstr *shp, s_char *buf) { - coord destx; - coord desty; - struct sctstr d_sect; - s_char *cp; - + coord destx; + coord desty; + struct sctstr d_sect; + s_char *cp; + if (!sarg_xy(buf, &destx, &desty)) return 0; - if (!together){ - mpr(shp->shp_own, "Cannot go to a destination sector if not all starting in the same sector\n"); + if (!together) { + mpr(shp->shp_own, + "Cannot go to a destination sector if not all starting in the same sector\n"); return 0; } if (!getsect(destx, desty, &d_sect)) { mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty); return 0; } - + cp = (s_char *)BestShipPath(buf, shp->shp_x, shp->shp_y, d_sect.sct_x, d_sect.sct_y, player->cnum); if (!cp || shp->shp_mobil <= 0) { @@ -1020,33 +1037,36 @@ shp_path(int together, struct shpstr *shp, s_char *buf) void shp_missdef(struct shpstr *sp, natid victim) { - struct emp_qelem list; - struct mlist *mlp; - int eff; - s_char buf[512]; - + struct emp_qelem list; + struct mlist *mlp; + int eff; + s_char buf[512]; + emp_initque(&list); - - mlp = (struct mlist *) malloc(sizeof(struct mlist)); + + mlp = (struct mlist *)malloc(sizeof(struct mlist)); mlp->mcp = &mchr[(int)sp->shp_type]; bcopy((s_char *)sp, (s_char *)&mlp->ship, sizeof(struct shpstr)); mlp->mobil = (double)sp->shp_mobil; emp_insque(&mlp->queue, &list); sprintf(buf, "%s", prship(&mlp->ship)); - + eff = sp->shp_effic; if (most_valuable_ship(&list)) { shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own); getship(sp->shp_uid, sp); - + if (!sp->shp_own) { - wu(0, victim, "missiles launched in defense did 100%% damage to %s\n", buf); + wu(0, victim, + "missiles launched in defense did 100%% damage to %s\n", + buf); wu(0, victim, "%s sunk!\n", buf); } else if (eff > 0 && sp->shp_effic < eff) { - wu(0, victim, "missiles launched in defense did %d%% damage to %s\n", 100*(eff - sp->shp_effic)/eff, buf); + wu(0, victim, + "missiles launched in defense did %d%% damage to %s\n", + 100 * (eff - sp->shp_effic) / eff, buf); } } if (!QEMPTY(&list)) free(mlp); } - diff --git a/src/lib/subs/snxtitem.c b/src/lib/subs/snxtitem.c index d11138892..cf45cacc6 100644 --- a/src/lib/subs/snxtitem.c +++ b/src/lib/subs/snxtitem.c @@ -50,82 +50,81 @@ int snxtitem(register struct nstr_item *np, int type, s_char *str) { - register s_char *cp; - struct range range; - int list[NS_LSIZE]; - int n; - coord cx, cy; - int dist; - int flags; - s_char natnumber[16]; - s_char prompt[128]; - s_char buf[1024]; + register s_char *cp; + struct range range; + int list[NS_LSIZE]; + int n; + coord cx, cy; + int dist; + int flags; + s_char natnumber[16]; + s_char prompt[128]; + s_char buf[1024]; - np->type = NS_UNDEF; - np->sel = NS_UNDEF; - if (str == 0) { - sprintf(prompt, "%s(s)? ", ef_nameof(type)); - str = getstring(prompt, buf); - if (str == 0) - return 0; - } - if (*str == 0) { - /* str present, but only : nil string passed by player */ - return 0; - } - if (type == EF_NATION && isalpha(*str)) { - sprintf(natnumber, "%d", natarg(str, "")); - str = natnumber; - } - flags = ef_flags(type); - switch (sarg_type(str)) { - case NS_AREA: - if (!(flags & EFF_XY)) - return 0; - if (!sarg_area(str, &range)) - return 0; - snxtitem_area(np, type, &range); - break; - case NS_DIST: - if (!(flags & EFF_XY)) - return 0; - if (!sarg_range(str, &cx, &cy, &dist)) - return 0; - snxtitem_dist(np, type, cx, cy, dist); - break; - case NS_ALL: - snxtitem_all(np, type); - break; - case NS_LIST: - if ((n = sarg_list(str, list, NS_LSIZE)) == 0) - return 0; - if (!snxtitem_list(np, type, list, n)) - return 0; - break; - case NS_XY: - if (!(flags & EFF_XY)) - return 0; - if (!sarg_xy(str, &cx, &cy)) - return 0; - snxtitem_xy(np, type, cx, cy); - break; - case NS_GROUP: - if (!(flags & EFF_GROUP)) - return 0; - snxtitem_group(np, type, *str); - break; - default: - return 0; - } - np->flags = flags; - if (player->condarg == 0) - return 1; - cp = player->condarg; - while ((cp = nstr_comp(np->cond, &np->ncond, type, cp)) && *cp) - ; - if (cp == 0) - return 0; + np->type = NS_UNDEF; + np->sel = NS_UNDEF; + if (str == 0) { + sprintf(prompt, "%s(s)? ", ef_nameof(type)); + str = getstring(prompt, buf); + if (str == 0) + return 0; + } + if (*str == 0) { + /* str present, but only : nil string passed by player */ + return 0; + } + if (type == EF_NATION && isalpha(*str)) { + sprintf(natnumber, "%d", natarg(str, "")); + str = natnumber; + } + flags = ef_flags(type); + switch (sarg_type(str)) { + case NS_AREA: + if (!(flags & EFF_XY)) + return 0; + if (!sarg_area(str, &range)) + return 0; + snxtitem_area(np, type, &range); + break; + case NS_DIST: + if (!(flags & EFF_XY)) + return 0; + if (!sarg_range(str, &cx, &cy, &dist)) + return 0; + snxtitem_dist(np, type, cx, cy, dist); + break; + case NS_ALL: + snxtitem_all(np, type); + break; + case NS_LIST: + if ((n = sarg_list(str, list, NS_LSIZE)) == 0) + return 0; + if (!snxtitem_list(np, type, list, n)) + return 0; + break; + case NS_XY: + if (!(flags & EFF_XY)) + return 0; + if (!sarg_xy(str, &cx, &cy)) + return 0; + snxtitem_xy(np, type, cx, cy); + break; + case NS_GROUP: + if (!(flags & EFF_GROUP)) + return 0; + snxtitem_group(np, type, *str); + break; + default: + return 0; + } + np->flags = flags; + if (player->condarg == 0) return 1; + cp = player->condarg; + while ((cp = nstr_comp(np->cond, &np->ncond, type, cp)) && *cp) ; + if (cp == 0) + return 0; + return 1; } /* diff --git a/src/lib/subs/snxtsct.c b/src/lib/subs/snxtsct.c index 510e6a434..5312b7fa9 100644 --- a/src/lib/subs/snxtsct.c +++ b/src/lib/subs/snxtsct.c @@ -51,49 +51,49 @@ int snxtsct(register struct nstr_sect *np, s_char *str) { - register s_char *cp; - struct range range; - coord cx, cy; - int dist; - s_char buf[1024]; - struct range wr; + register s_char *cp; + struct range range; + coord cx, cy; + int dist; + s_char buf[1024]; + struct range wr; - if (str == 0 || *str == 0) { - if ((str = getstring("(sects)? ", buf)) == 0) - return 0; - } - wr.lx = -WORLD_X/2; - wr.ly = -WORLD_Y/2; - wr.hx = WORLD_X/2; - wr.hy = WORLD_Y/2; - wr.width = wr.height = 0; - switch (sarg_type(str)) { - case NS_AREA: - if (!sarg_area(str, &range)) - return 0; - snxtsct_area(np, &range); - break; - case NS_DIST: - if (!sarg_range(str, &cx, &cy, &dist)) - return 0; - snxtsct_dist(np, cx, cy, dist); - break; - case NS_ALL: - /* fake "all" by doing a world-sized area query */ - snxtsct_area(np, &wr); - break; - default: - return 0; - } - if (player->condarg == 0) - return 1; - cp = player->condarg; - while ((cp = nstr_comp(np->cond, &np->ncond, EF_SECTOR, cp)) && *cp) - ; - if (cp == 0) - return 0; + if (str == 0 || *str == 0) { + if ((str = getstring("(sects)? ", buf)) == 0) + return 0; + } + wr.lx = -WORLD_X / 2; + wr.ly = -WORLD_Y / 2; + wr.hx = WORLD_X / 2; + wr.hy = WORLD_Y / 2; + wr.width = wr.height = 0; + switch (sarg_type(str)) { + case NS_AREA: + if (!sarg_area(str, &range)) + return 0; + snxtsct_area(np, &range); + break; + case NS_DIST: + if (!sarg_range(str, &cx, &cy, &dist)) + return 0; + snxtsct_dist(np, cx, cy, dist); + break; + case NS_ALL: + /* fake "all" by doing a world-sized area query */ + snxtsct_area(np, &wr); + break; + default: + return 0; + } + if (player->condarg == 0) return 1; + cp = player->condarg; + while ((cp = nstr_comp(np->cond, &np->ncond, EF_SECTOR, cp)) && *cp) ; + if (cp == 0) + return 0; + return 1; } + /* * The rest of these (snxtsct_all, snxtsct_area, etc, have been moved * into the common lib, since they don't use condargs, and are useful diff --git a/src/lib/subs/supply.c b/src/lib/subs/supply.c index 99a57ee15..ed7b9bba7 100644 --- a/src/lib/subs/supply.c +++ b/src/lib/subs/supply.c @@ -70,10 +70,10 @@ void resupply_all(struct lndstr *lp) { if (!opt_NOFOOD) - resupply_commod(lp,I_FOOD); - resupply_commod(lp,I_SHELL); + resupply_commod(lp, I_FOOD); + resupply_commod(lp, I_SHELL); if (opt_FUEL) - resupply_commod(lp,I_PETROL); + resupply_commod(lp, I_PETROL); } /* @@ -84,23 +84,23 @@ resupply_all(struct lndstr *lp) void resupply_commod(struct lndstr *lp, int type) { - int vec[I_MAX+1]; - int svec[I_MAX+1]; + int vec[I_MAX + 1]; + int svec[I_MAX + 1]; int amt; - struct lchrstr *lcp; + struct lchrstr *lcp; struct shpstr ship; - + lcp = &lchr[(int)lp->lnd_type]; - + getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); /* Ok, do we now have enough? */ - if (vec[type] < get_minimum(lp,type)) { - vec[type] += supply_commod(lp->lnd_own,lp->lnd_x,lp->lnd_y,type, - get_minimum(lp,type)-vec[type]); + if (vec[type] < get_minimum(lp, type)) { + vec[type] += supply_commod(lp->lnd_own, lp->lnd_x, lp->lnd_y, type, + get_minimum(lp, type) - vec[type]); putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); } /* Now, check again to see if we have enough. */ - if (vec[type] < get_minimum(lp,type)) { + if (vec[type] < get_minimum(lp, type)) { /* Nope. How much do we need? */ amt = (get_minimum(lp, type) - vec[type]); /* Are we on a ship? if so, try to get it from the ship first. */ @@ -119,12 +119,12 @@ resupply_commod(struct lndstr *lp, int type) } if (opt_FUEL && type == I_PETROL) { - extern float land_mob_scale; - extern int etu_per_update; - int fuel_needed = (lp->lnd_fuelu * (((float)etu_per_update - * land_mob_scale))/10.0); - - while((lp->lnd_fuel < fuel_needed) && vec[I_PETROL]){ + extern float land_mob_scale; + extern int etu_per_update; + int fuel_needed = (lp->lnd_fuelu * (((float)etu_per_update + * land_mob_scale)) / 10.0); + + while ((lp->lnd_fuel < fuel_needed) && vec[I_PETROL]) { lp->lnd_fuel += 10; if (lp->lnd_fuel > lp->lnd_fuelc) lp->lnd_fuel = lp->lnd_fuelc; @@ -137,12 +137,12 @@ resupply_commod(struct lndstr *lp, int type) /* * Actually get the commod */ -int +int supply_commod(int own, int x, int y, int type, int total_wanted) { if (total_wanted < 0) return 0; - return s_commod(own, x, y, type,total_wanted,!player->simulation); + return s_commod(own, x, y, type, total_wanted, !player->simulation); } /* @@ -153,65 +153,65 @@ try_supply_commod(int own, int x, int y, int type, int total_wanted) { if (total_wanted < 0) return 0; - - return s_commod(own, x, y, type,total_wanted,0); + + return s_commod(own, x, y, type, total_wanted, 0); } /* Get supplies of a certain type */ -int -s_commod(int own, int x, int y, int type, int total_wanted, int actually_doit) +int +s_commod(int own, int x, int y, int type, int total_wanted, + int actually_doit) { - int wanted=total_wanted; - int gotten=0, lookrange; - struct sctstr sect, dest; - int vec[I_MAX+1]; - struct nstr_sect ns; - struct nstr_item ni; - struct lchrstr *lcp; - struct shpstr ship; - struct lndstr land; + int wanted = total_wanted; + int gotten = 0, lookrange; + struct sctstr sect, dest; + int vec[I_MAX + 1]; + struct nstr_sect ns; + struct nstr_item ni; + struct lchrstr *lcp; + struct shpstr ship; + struct lndstr land; /* leave at least 1 military in sectors/ships */ - int minimum=(type == I_MILIT ? 1 : 0); - int can_move; - double move_cost, weight, mobcost; - int packing; - extern double eatrate; - extern int etu_per_update; - struct dchrstr *dp; - struct ichrstr *ip; - s_char buf[1024]; - + int minimum = (type == I_MILIT ? 1 : 0); + int can_move; + double move_cost, weight, mobcost; + int packing; + extern double eatrate; + extern int etu_per_update; + struct dchrstr *dp; + struct ichrstr *ip; + s_char buf[1024]; + /* try to get it from sector we're in */ - getsect(x,y,&dest); - getsect(x,y,§); - if (sect.sct_own == own){ + getsect(x, y, &dest); + getsect(x, y, §); + if (sect.sct_own == own) { getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); - if ((vec[type]-minimum) >= wanted){ + if ((vec[type] - minimum) >= wanted) { vec[type] -= wanted; - if (actually_doit){ - putvec(VT_ITEM,vec,(s_char *)§,EF_SECTOR); + if (actually_doit) { + putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); putsect(§); } return total_wanted; - }else if ((vec[type]-minimum) > 0){ - gotten += (vec[type]-minimum); - wanted -= (vec[type]-minimum); + } else if ((vec[type] - minimum) > 0) { + gotten += (vec[type] - minimum); + wanted -= (vec[type] - minimum); vec[type] = minimum; - if (actually_doit){ - putvec(VT_ITEM,vec,(s_char *)§,EF_SECTOR); + if (actually_doit) { + putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); putsect(§); } } } /* look for a headquarters or warehouse */ - lookrange = tfact(own,(double)10.0); + lookrange = tfact(own, (double)10.0); snxtsct_dist(&ns, x, y, lookrange); - while (nxtsct(&ns, §) && wanted){ + while (nxtsct(&ns, §) && wanted) { if (sect.sct_own != own) continue; if ((sect.sct_type != SCT_WAREH) && - (sect.sct_type != SCT_HEADQ) && - (sect.sct_type != SCT_HARBR)) + (sect.sct_type != SCT_HEADQ) && (sect.sct_type != SCT_HARBR)) continue; if ((sect.sct_type == SCT_HEADQ) && (sect.sct_dist_x == sect.sct_x) && @@ -219,13 +219,14 @@ s_commod(int own, int x, int y, int type, int total_wanted, int actually_doit) continue; if (sect.sct_effic < 60) continue; - if (BestLandPath(buf, &dest,§,&move_cost,MOB_ROAD) == (s_char *)0) + if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) == + (s_char *)0) continue; getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); if (!opt_NOFOOD && type == I_FOOD) { - minimum=(((double)etu_per_update * eatrate) * - (double)(vec[I_CIVIL]+vec[I_MILIT]+vec[I_UW])) - +2; + minimum = (((double)etu_per_update * eatrate) * + (double)(vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])) + + 2; } if (vec[type] <= minimum) { /* Don't bother... */ @@ -241,71 +242,72 @@ s_commod(int own, int x, int y, int type, int total_wanted, int actually_doit) if (mobcost > 0) can_move = ((double)sect.sct_mobil / mobcost); else - can_move = vec[type]-minimum; - if (can_move > (vec[type]-minimum)) - can_move = (vec[type]-minimum); - - if (can_move >= wanted){ - int n; - + can_move = vec[type] - minimum; + if (can_move > (vec[type] - minimum)) + can_move = (vec[type] - minimum); + + if (can_move >= wanted) { + int n; + vec[type] -= wanted; - + /* take off mobility for delivering sect */ - n = roundavg(total_wanted*weight*move_cost); + n = roundavg(total_wanted * weight * move_cost); if (n < 0) n = 0; if (n > sect.sct_mobil) n = sect.sct_mobil; sect.sct_mobil -= (u_char)n; - - if (actually_doit){ + + if (actually_doit) { putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); putsect(§); } - + return total_wanted; - }else if (can_move > 0){ - int n; + } else if (can_move > 0) { + int n; gotten += can_move; wanted -= can_move; vec[type] -= can_move; - + /* take off mobility for delivering sect */ - n = roundavg(can_move*weight*move_cost); + n = roundavg(can_move * weight * move_cost); if (n < 0) n = 0; if (n > sect.sct_mobil) n = sect.sct_mobil; sect.sct_mobil -= (u_char)n; - - if (actually_doit){ + + if (actually_doit) { putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR); putsect(§); } } } - + /* look for an owned ship in a harbor */ snxtitem_dist(&ni, EF_SHIP, x, y, lookrange); - - while (nxtitem(&ni, (s_char *)&ship) && wanted){ + + while (nxtitem(&ni, (s_char *)&ship) && wanted) { if (ship.shp_own != own) continue; - + if (!(mchr[(int)ship.shp_type].m_flags & M_SUPPLY)) continue; - getsect(ship.shp_x,ship.shp_y,§); + getsect(ship.shp_x, ship.shp_y, §); if (sect.sct_type != SCT_HARBR) continue; if (sect.sct_effic < 2) continue; - if (BestLandPath(buf, &dest,§,&move_cost,MOB_ROAD) == (s_char *)0) + if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) == + (s_char *)0) continue; getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); if (!opt_NOFOOD && type == I_FOOD) - minimum=(((double)etu_per_update * eatrate) * - (double)(vec[I_CIVIL]+vec[I_MILIT]+vec[I_UW])) - +2; + minimum = (((double)etu_per_update * eatrate) * + (double)(vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])) + + 2; if (vec[type] <= minimum) { /* Don't bother... */ continue; @@ -320,91 +322,94 @@ s_commod(int own, int x, int y, int type, int total_wanted, int actually_doit) if (mobcost > 0) can_move = ((double)sect.sct_mobil / mobcost); else - can_move = vec[type]-minimum; - if (can_move > (vec[type]-minimum)) - can_move = (vec[type]-minimum); - if (can_move >= wanted){ - int n; + can_move = vec[type] - minimum; + if (can_move > (vec[type] - minimum)) + can_move = (vec[type] - minimum); + if (can_move >= wanted) { + int n; vec[type] -= wanted; - - n = roundavg(wanted*weight*move_cost); + + n = roundavg(wanted * weight * move_cost); if (n < 0) n = 0; if (n > sect.sct_mobil) n = sect.sct_mobil; sect.sct_mobil -= (u_char)n; - if (actually_doit){ + if (actually_doit) { putvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - putship(ship.shp_uid,&ship); + putship(ship.shp_uid, &ship); putsect(§); } return total_wanted; - }else if (can_move > 0){ - int n; + } else if (can_move > 0) { + int n; gotten += can_move; wanted -= can_move; vec[type] -= can_move; - - n = roundavg(can_move*weight*move_cost); + + n = roundavg(can_move * weight * move_cost); if (n < 0) n = 0; if (n > sect.sct_mobil) n = sect.sct_mobil; sect.sct_mobil -= (u_char)n; - - if (actually_doit){ + + if (actually_doit) { putvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP); - putship(ship.shp_uid,&ship); + putship(ship.shp_uid, &ship); putsect(§); } } } - + /* look for an owned supply unit */ snxtitem_dist(&ni, EF_LAND, x, y, lookrange); - - while (nxtitem(&ni, (s_char *)&land) && wanted){ - int min; - + + while (nxtitem(&ni, (s_char *)&land) && wanted) { + int min; + if (land.lnd_own != own) continue; - + lcp = &lchr[(int)land.lnd_type]; if (!(lcp->l_flags & L_SUPPLY)) continue; - + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - if (vec[type] <= get_minimum(&land,type)) + if (vec[type] <= get_minimum(&land, type)) continue; - - getsect(land.lnd_x,land.lnd_y,§); - if (BestLandPath(buf, &dest,§,&move_cost,MOB_ROAD) == (s_char *)0) + + getsect(land.lnd_x, land.lnd_y, §); + if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) == + (s_char *)0) continue; - + if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR)) continue; - + if ((land.lnd_ship >= 0) && (sect.sct_effic < 2)) continue; - - if ((vec[type]-wanted) < get_minimum(&land,type)){ - int hold; - struct lndstr l2; - - bcopy((s_char *)&land,(s_char *)&l2,sizeof(struct lndstr)); + + if ((vec[type] - wanted) < get_minimum(&land, type)) { + int hold; + struct lndstr l2; + + bcopy((s_char *)&land, (s_char *)&l2, sizeof(struct lndstr)); hold = vec[type]; vec[type] = 0; putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); land.lnd_fuel = 0; - putland(land.lnd_uid,&land); - hold += s_commod(own,land.lnd_x,land.lnd_y,type,wanted, actually_doit); + putland(land.lnd_uid, &land); + hold += + s_commod(own, land.lnd_x, land.lnd_y, type, wanted, + actually_doit); vec[type] = hold; putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - putland(land.lnd_uid,&land); + putland(land.lnd_uid, &land); if (!actually_doit) - putland(l2.lnd_uid,&l2); + putland(l2.lnd_uid, &l2); } - + getvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); ip = &ichr[type]; weight = ((double)ip->i_lbs); @@ -412,38 +417,38 @@ s_commod(int own, int x, int y, int type, int total_wanted, int actually_doit) if (mobcost > 0) can_move = ((double)land.lnd_mobil / mobcost); else - can_move = vec[type]-min; - min = get_minimum(&land,type); - if (can_move > (vec[type]-min)) - can_move = (vec[type]-min); - - if (can_move >= wanted){ + can_move = vec[type] - min; + min = get_minimum(&land, type); + if (can_move > (vec[type] - min)) + can_move = (vec[type] - min); + + if (can_move >= wanted) { vec[type] -= wanted; - + /* resupply the supply unit */ resupply_commod(&land, type); - - land.lnd_mobil -= roundavg(wanted*weight*move_cost); - - if (actually_doit){ + + land.lnd_mobil -= roundavg(wanted * weight * move_cost); + + if (actually_doit) { putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - putland(land.lnd_uid,&land); + putland(land.lnd_uid, &land); } return total_wanted; - }else if (can_move > 0){ + } else if (can_move > 0) { gotten += can_move; wanted -= can_move; vec[type] -= can_move; - - land.lnd_mobil -= roundavg(can_move*weight*move_cost); - - if (actually_doit){ + + land.lnd_mobil -= roundavg(can_move * weight * move_cost); + + if (actually_doit) { putvec(VT_ITEM, vec, (s_char *)&land, EF_LAND); - putland(land.lnd_uid,&land); + putland(land.lnd_uid, &land); } } } - + /* We've done the best we could */ /* return the number gotten */ return gotten; @@ -455,8 +460,8 @@ itemname(int type) { register int t; register struct ichrstr *ip; - - t=V_ITEM(type); + + t = V_ITEM(type); for (ip = &ichr[1]; ip->i_mnem != 0; ip++) { if (t == ip->i_vtype) return ip->i_name; @@ -467,12 +472,12 @@ itemname(int type) int at_minimum(struct lndstr *lp, int type) { - int vec[I_MAX+1]; - + int vec[I_MAX + 1]; + getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - if (vec[type] <= get_minimum(lp,type)) + if (vec[type] <= get_minimum(lp, type)) return 1; - + return 0; } @@ -485,204 +490,204 @@ at_minimum(struct lndstr *lp, int type) int get_minimum(struct lndstr *lp, int type) { - struct lchrstr *lcp; - int max, want=0; - extern double eatrate; - extern int etu_per_update; - extern float land_mob_scale; - + struct lchrstr *lcp; + int max, want = 0; + extern double eatrate; + extern int etu_per_update; + extern float land_mob_scale; + lcp = &lchr[(int)lp->lnd_type]; - max = vl_find(V_ITEM(type), lcp->l_vtype, lcp->l_vamt, (int) lcp->l_nv); - + max = vl_find(V_ITEM(type), lcp->l_vtype, lcp->l_vamt, (int)lcp->l_nv); + switch (type) { case I_FOOD: if (opt_NOFOOD) - return 0; /* no food reqd, get out */ + return 0; /* no food reqd, get out */ want = (((double)etu_per_update * eatrate) * - (double)total_mil(lp))+1; + (double)total_mil(lp)) + 1; break; case I_SHELL: want = lp->lnd_ammo; break; - + /* * return the amount of pet we'd need to get to * enough fuel for 1 update * */ case I_PETROL: - if (opt_FUEL == 0) return 0; + if (opt_FUEL == 0) + return 0; want = (lp->lnd_fuelu * (((float)etu_per_update * - land_mob_scale))/10.0); + land_mob_scale)) / 10.0); want -= lp->lnd_fuel; - if (want > 0){ - double d; - d = (double)want/10.0; + if (want > 0) { + double d; + d = (double)want / 10.0; want = (int)d; if (want == 0) want++; } - + max = want; break; - default: return 0; + default: + return 0; } - + if (want > max) want = max; - + return want; } int has_supply(struct lndstr *lp) { - struct lchrstr *lcp; - int vec[I_MAX+1], shells_needed, shells, keepshells; - int food, food_needed, keepfood; - int fuel_needed, fuel, petrol_needed, petrol, keeppetrol; - + struct lchrstr *lcp; + int vec[I_MAX + 1], shells_needed, shells, keepshells; + int food, food_needed, keepfood; + int fuel_needed, fuel, petrol_needed, petrol, keeppetrol; + lcp = &lchr[(int)lp->lnd_type]; getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - + if (!opt_NOFOOD) { - food_needed = get_minimum(lp,I_FOOD); + food_needed = get_minimum(lp, I_FOOD); food = keepfood = vec[I_FOOD]; - if (food < food_needed){ - vec[I_FOOD]=0; + if (food < food_needed) { + vec[I_FOOD] = 0; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - food += try_supply_commod(lp->lnd_own,lp->lnd_x,lp->lnd_y, - I_FOOD,(food_needed-food)); - vec[I_FOOD]=keepfood; + food += try_supply_commod(lp->lnd_own, lp->lnd_x, lp->lnd_y, + I_FOOD, (food_needed - food)); + vec[I_FOOD] = keepfood; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); } if (food < food_needed) return 0; - + } - + shells_needed = lp->lnd_ammo; shells = keepshells = vec[I_SHELL]; - if (shells < shells_needed){ - vec[I_SHELL]=0; + if (shells < shells_needed) { + vec[I_SHELL] = 0; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - shells += try_supply_commod(lp->lnd_own,lp->lnd_x,lp->lnd_y, - I_SHELL,(shells_needed-shells)); - vec[I_SHELL]=keepshells; + shells += try_supply_commod(lp->lnd_own, lp->lnd_x, lp->lnd_y, + I_SHELL, (shells_needed - shells)); + vec[I_SHELL] = keepshells; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); } - + if (shells < shells_needed) return 0; - + if (opt_FUEL) { fuel_needed = lp->lnd_fuelu; - + fuel = lp->lnd_fuel; - - petrol=petrol_needed = 0; - - if (fuel < fuel_needed){ + + petrol = petrol_needed = 0; + + if (fuel < fuel_needed) { petrol_needed = - ldround(((double)(fuel_needed-fuel)/10.0),1); + ldround(((double)(fuel_needed - fuel) / 10.0), 1); petrol = keeppetrol = vec[I_PETROL]; } - - if (petrol < petrol_needed){ - vec[I_PETROL]=0; + + if (petrol < petrol_needed) { + vec[I_PETROL] = 0; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); petrol += try_supply_commod(lp->lnd_own, - lp->lnd_x,lp->lnd_y, - I_PETROL,(petrol_needed-petrol)); - vec[I_PETROL]=keeppetrol; + lp->lnd_x, lp->lnd_y, + I_PETROL, + (petrol_needed - petrol)); + vec[I_PETROL] = keeppetrol; putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - fuel += petrol*10; + fuel += petrol * 10; } - + if (fuel < fuel_needed) return 0; - } /* end opt_FUEL */ - + } + /* end opt_FUEL */ return 1; } int use_supply(struct lndstr *lp) { - struct lchrstr *lcp; - int vec[I_MAX+1], shells_needed, shells, food, food_needed; - int fuel_needed, fuel, petrol_needed, petrol; - + struct lchrstr *lcp; + int vec[I_MAX + 1], shells_needed, shells, food, food_needed; + int fuel_needed, fuel, petrol_needed, petrol; + lcp = &lchr[(int)lp->lnd_type]; getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - + shells_needed = lp->lnd_ammo; shells = vec[I_SHELL]; - if (shells < shells_needed){ - vec[I_SHELL] = 0; - putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - shells += supply_commod(lp->lnd_own,lp->lnd_x,lp->lnd_y,I_SHELL, - (shells_needed-shells)); - vec[I_SHELL] = shells; + if (shells < shells_needed) { + vec[I_SHELL] = 0; + putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); + shells += supply_commod(lp->lnd_own, lp->lnd_x, lp->lnd_y, I_SHELL, + (shells_needed - shells)); + vec[I_SHELL] = shells; } - + vec[I_SHELL] = max(vec[I_SHELL] - shells_needed, 0); - - if (lp->lnd_frg) /* artillery */ - goto artillery; - - food_needed = get_minimum(lp,I_FOOD); + + if (lp->lnd_frg) /* artillery */ + goto artillery; + + food_needed = get_minimum(lp, I_FOOD); food = vec[I_SHELL]; - - if (food < food_needed){ - vec[I_FOOD]=0; - putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - food += supply_commod(lp->lnd_own,lp->lnd_x,lp->lnd_y,I_FOOD, - (food_needed-food)); - vec[I_FOOD]=food; + + if (food < food_needed) { + vec[I_FOOD] = 0; + putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); + food += supply_commod(lp->lnd_own, lp->lnd_x, lp->lnd_y, I_FOOD, + (food_needed - food)); + vec[I_FOOD] = food; } - - vec[I_FOOD] = max(vec[I_FOOD]-food_needed,0); - + + vec[I_FOOD] = max(vec[I_FOOD] - food_needed, 0); + if (opt_FUEL) { - fuel_needed = lp->lnd_fuelu; - fuel = lp->lnd_fuel; - - petrol=petrol_needed = 0; - - if (fuel < fuel_needed){ - petrol_needed = - ldround(((double)(fuel_needed-fuel)/10.0),1); - petrol = vec[I_PETROL]; - } - - if (petrol < petrol_needed){ - vec[I_PETROL]=0; - putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - petrol += supply_commod(lp->lnd_own, - lp->lnd_x,lp->lnd_y, - I_PETROL,(petrol_needed-petrol)); - vec[I_PETROL]=petrol; - } - - if (petrol_needed){ - if (petrol>=petrol_needed){ - vec[I_PETROL]= - max(vec[I_PETROL]-petrol_needed,0); - lp->lnd_fuel += petrol_needed * 10; - } - else{ - lp->lnd_fuel += vec[I_PETROL]*10; - vec[I_PETROL]=0; - } - } - - lp->lnd_fuel = max(lp->lnd_fuel - fuel_needed, 0); - } /* end opt_FUEL */ - - artillery: + fuel_needed = lp->lnd_fuelu; + fuel = lp->lnd_fuel; + + petrol = petrol_needed = 0; + + if (fuel < fuel_needed) { + petrol_needed = + ldround(((double)(fuel_needed - fuel) / 10.0), 1); + petrol = vec[I_PETROL]; + } + + if (petrol < petrol_needed) { + vec[I_PETROL] = 0; + putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); + petrol += supply_commod(lp->lnd_own, + lp->lnd_x, lp->lnd_y, + I_PETROL, (petrol_needed - petrol)); + vec[I_PETROL] = petrol; + } + + if (petrol_needed) { + if (petrol >= petrol_needed) { + vec[I_PETROL] = max(vec[I_PETROL] - petrol_needed, 0); + lp->lnd_fuel += petrol_needed * 10; + } else { + lp->lnd_fuel += vec[I_PETROL] * 10; + vec[I_PETROL] = 0; + } + } + + lp->lnd_fuel = max(lp->lnd_fuel - fuel_needed, 0); + } + /* end opt_FUEL */ + artillery: putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - putland(lp->lnd_uid,lp); + putland(lp->lnd_uid, lp); return 1; } - diff --git a/src/lib/subs/takeover.c b/src/lib/subs/takeover.c index c1bac9465..000d6b061 100644 --- a/src/lib/subs/takeover.c +++ b/src/lib/subs/takeover.c @@ -47,7 +47,8 @@ #define CHE_MAX 255 -void takeover_land(register struct lndstr *landp, natid newown, int hostile); +void takeover_land(register struct lndstr *landp, natid newown, + int hostile); void takeover_plane(register struct plnstr *pp, natid newown); void @@ -55,16 +56,16 @@ takeover(register struct sctstr *sp, natid newown) { struct plnstr *pp; struct lndstr *lp; - int civ; - int che; - int che_count; - int oldche; - int n, vec[I_MAX+1]; + int civ; + int che; + int che_count; + int oldche; + int n, vec[I_MAX + 1]; double odds; - struct nstr_item ni; - struct plnstr p; - struct lndstr land; - extern double hap_fact(struct natstr *, struct natstr *); + struct nstr_item ni; + struct plnstr p; + struct lndstr land; + extern double hap_fact(struct natstr *, struct natstr *); extern int etu_per_update; extern int sect_mob_neg_factor; @@ -73,21 +74,21 @@ takeover(register struct sctstr *sp, natid newown) putvec(VT_DIST, vec, (s_char *)sp, EF_SECTOR); putvec(VT_DEL, vec, (s_char *)sp, EF_SECTOR); if (sp->sct_own == 0) - sp->sct_off = 0; - else - sp->sct_off = 1; + sp->sct_off = 0; + else + sp->sct_off = 1; sp->sct_dist_x = sp->sct_x; sp->sct_dist_y = sp->sct_y; - + pp = &p; /* Take over planes */ snxtitem_dist(&ni, EF_PLANE, sp->sct_x, sp->sct_y, 0); while (nxtitem(&ni, (caddr_t)pp)) { if (pp->pln_own != sp->sct_own) - continue; + continue; takeover_plane(pp, newown); } - + /* Take over land units */ lp = &land; snxtitem_dist(&ni, EF_LAND, sp->sct_x, sp->sct_y, 0); @@ -100,9 +101,9 @@ takeover(register struct sctstr *sp, natid newown) continue; /* Spies get a chance to hide */ if (lchr[(int)lp->lnd_type].l_flags & L_SPY) { - odds = (double)(100 - lp->lnd_effic) + 0.10; - if (!(chance(odds))) - continue; + odds = (double)(100 - lp->lnd_effic) + 0.10; + if (!(chance(odds))) + continue; } n = lp->lnd_effic - (30 + (random() % 100)); if (n < 0) @@ -110,7 +111,7 @@ takeover(register struct sctstr *sp, natid newown) lp->lnd_effic = n; if (lp->lnd_effic < LAND_MINEFF) { lp->lnd_effic = 0; - mpr(newown,"%s blown up by the crew!\n", prland(lp)); + mpr(newown, "%s blown up by the crew!\n", prland(lp)); wu(0, lp->lnd_own, "%s blown up by the crew when %s took %s!\n", prland(lp), @@ -124,7 +125,7 @@ takeover(register struct sctstr *sp, natid newown) } takeover_land(lp, newown, 1); } - + sp->sct_avail = 0; civ = getvar(V_CIVIL, (s_char *)sp, EF_SECTOR); oldche = get_che_value(getvar(V_CHE, (s_char *)sp, EF_SECTOR)); @@ -137,10 +138,10 @@ takeover(register struct sctstr *sp, natid newown) che_count = 0; che = 0; if (n > 0 && sp->sct_own == sp->sct_oldown) { - che_count = (civ * n/3000) + 5; + che_count = (civ * n / 3000) + 5; if (che_count * 2 > civ) che_count = civ / 2; - che_count /= hap_fact(getnatp(newown),getnatp(sp->sct_own)); + che_count /= hap_fact(getnatp(newown), getnatp(sp->sct_own)); if (che_count + oldche > CHE_MAX) che_count = CHE_MAX - oldche; if (che_count > 0) { @@ -153,8 +154,8 @@ takeover(register struct sctstr *sp, natid newown) set_che_value(che, che_count); if (newown != sp->sct_oldown) set_che_cnum(che, newown); - (void) putvar(V_CHE, che, (s_char *)sp, EF_SECTOR); - (void) putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); + (void)putvar(V_CHE, che, (s_char *)sp, EF_SECTOR); + (void)putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); if (sp->sct_oldown == newown || civ == 0) { /* * taking over one of your old sectors @@ -184,36 +185,37 @@ takeover_plane(register struct plnstr *pp, natid newown) int n; if ((pp->pln_own == newown) || (pp->pln_own == 0)) - return; + return; if (pp->pln_flags & PLN_LAUNCHED) - return; + return; if (pp->pln_ship >= 0 || pp->pln_land >= 0) - return; + return; /* * XXX If this was done right, planes could escape, * flying to a nearby friendly airport. */ n = pp->pln_effic - (30 + (random() % 100)); - if (n < 0) n = 0; + if (n < 0) + n = 0; pp->pln_effic = n; if (pp->pln_effic < PLANE_MINEFF || pp->pln_harden > (s_char)0) { - pp->pln_effic = 0; - mpr(newown,"%s blown up by the crew!\n", prplane(pp)); - wu(0, pp->pln_own, - "%s blown up by the crew to avoid capture by %s at %s!\n", - prplane(pp), - cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own)); + pp->pln_effic = 0; + mpr(newown, "%s blown up by the crew!\n", prplane(pp)); + wu(0, pp->pln_own, + "%s blown up by the crew to avoid capture by %s at %s!\n", + prplane(pp), + cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own)); } else { - mpr(newown, "We have captured %s!\n", prplane(pp)); - wu(0, pp->pln_own, - "%s captured by %s at %s!\n", - prplane(pp), - cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own)); + mpr(newown, "We have captured %s!\n", prplane(pp)); + wu(0, pp->pln_own, + "%s captured by %s at %s!\n", + prplane(pp), + cname(newown), xyas(pp->pln_x, pp->pln_y, pp->pln_own)); } if (opt_MARKET) - trdswitchown(EF_PLANE, (int *)pp, newown); + trdswitchown(EF_PLANE, (int *)pp, newown); if (pp->pln_mobil > (s_char)0) - pp->pln_mobil = 0; + pp->pln_mobil = 0; makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); pp->pln_own = newown; makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); @@ -226,12 +228,12 @@ takeover_ship(register struct shpstr *sp, natid newown, int hostile) { register struct plnstr *pp; register struct lndstr *lp; - struct nstr_item ni; - struct plnstr p; - struct lndstr llp; - + struct nstr_item ni; + struct plnstr p; + struct lndstr llp; + if (opt_MARKET) - trdswitchown(EF_SHIP, (int *)sp, newown); + trdswitchown(EF_SHIP, (int *)sp, newown); makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); sp->shp_own = newown; makenotlost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); @@ -240,7 +242,7 @@ takeover_ship(register struct shpstr *sp, natid newown, int hostile) sp->shp_rflags = 0; /* Keep track of when this was taken over */ time(&sp->shp_access); - bzero(sp->shp_rpath,RET_LEN); + bzero(sp->shp_rpath, RET_LEN); pp = &p; lp = &llp; /* Take over planes */ @@ -262,7 +264,8 @@ takeover_ship(register struct shpstr *sp, natid newown, int hostile) pp->pln_mission = 0; makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); pp->pln_own = newown; - makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); putplane(pp->pln_uid, pp); } /* Take over land units */ @@ -282,10 +285,10 @@ takeover_land(register struct lndstr *landp, natid newown, int hostile) { register struct plnstr *pp; register struct lndstr *lp; - struct nstr_item ni; - struct plnstr p; - struct lndstr llp; - + struct nstr_item ni; + struct plnstr p; + struct lndstr llp; + if (landp->lnd_effic < LAND_MINEFF) { putland(landp->lnd_uid, landp); return; @@ -298,9 +301,11 @@ takeover_land(register struct lndstr *landp, natid newown, int hostile) if (opt_MARKET) trdswitchown(EF_LAND, (int *)landp, newown); landp->lnd_mission = 0; - makelost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x, landp->lnd_y); + makelost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x, + landp->lnd_y); landp->lnd_own = newown; - makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x, landp->lnd_y); + makenotlost(EF_LAND, landp->lnd_own, landp->lnd_uid, landp->lnd_x, + landp->lnd_y); pp = &p; lp = &llp; /* Take over planes */ @@ -322,7 +327,8 @@ takeover_land(register struct lndstr *landp, natid newown, int hostile) pp->pln_mission = 0; makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); pp->pln_own = newown; - makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); + makenotlost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); putplane(pp->pln_uid, pp); } /* Take over land units */ @@ -336,7 +342,3 @@ takeover_land(register struct lndstr *landp, natid newown, int hostile) } putland(landp->lnd_uid, landp); } - - - - diff --git a/src/lib/subs/trdsub.c b/src/lib/subs/trdsub.c index cf4d947c4..52f0c979b 100644 --- a/src/lib/subs/trdsub.c +++ b/src/lib/subs/trdsub.c @@ -54,19 +54,19 @@ int trade_check_ok(int lot, struct trdstr *tp, union trdgenstr *tgp) { - union trdgenstr check; - struct trdstr trade; + union trdgenstr check; + struct trdstr trade; int result = 0; - + trade_getitem(tp, &check); if (tp->trd_type == EF_LAND) - result = memcmp(&(check.lnd), &(tgp->lnd), sizeof(struct lndstr)); + result = memcmp(&(check.lnd), &(tgp->lnd), sizeof(struct lndstr)); else if (tp->trd_type == EF_PLANE) - result = memcmp(&(check.pln), &(tgp->pln), sizeof(struct plnstr)); + result = memcmp(&(check.pln), &(tgp->pln), sizeof(struct plnstr)); else if (tp->trd_type == EF_SHIP) - result = memcmp(&(check.shp), &(tgp->shp), sizeof(struct shpstr)); + result = memcmp(&(check.shp), &(tgp->shp), sizeof(struct shpstr)); else - result = memcmp(&(check.nuk), &(tgp->nuk), sizeof(struct nukstr)); + result = memcmp(&(check.nuk), &(tgp->nuk), sizeof(struct nukstr)); if (result) { pr("That item has changed!\n"); return 0; @@ -82,17 +82,17 @@ trade_check_ok(int lot, struct trdstr *tp, union trdgenstr *tgp) s_char * trade_nameof(struct trdstr *tp, union trdgenstr *tgp) { - switch (tp->trd_type) { - case EF_NUKE: - return "nuclear stockpile"; - case EF_PLANE: - return plchr[(int)tgp->pln.pln_type].pl_name; - case EF_SHIP: - return mchr[(int)tgp->shp.shp_type].m_name; - case EF_LAND: - return lchr[(int)tgp->lnd.lnd_type].l_name; - } - return "Bad trade type, get help"; + switch (tp->trd_type) { + case EF_NUKE: + return "nuclear stockpile"; + case EF_PLANE: + return plchr[(int)tgp->pln.pln_type].pl_name; + case EF_SHIP: + return mchr[(int)tgp->shp.shp_type].m_name; + case EF_LAND: + return lchr[(int)tgp->lnd.lnd_type].l_name; + } + return "Bad trade type, get help"; } /* @@ -103,174 +103,148 @@ trade_nameof(struct trdstr *tp, union trdgenstr *tgp) int trade_desc(struct trdstr *tp, union trdgenstr *tgp) { - int i; - float price; - struct sctstr sect; - struct nukstr *np; - struct shpstr *sp; - struct plnstr *pp; - struct lndstr *lp; - struct natstr *natp; - int needcomma; - struct nstr_item ni; - struct plnstr plane; - struct lndstr land; + int i; + float price; + struct sctstr sect; + struct nukstr *np; + struct shpstr *sp; + struct plnstr *pp; + struct lndstr *lp; + struct natstr *natp; + int needcomma; + struct nstr_item ni; + struct plnstr plane; + struct lndstr land; - price = multread(tp->trd_owner, player->cnum) * tp->trd_price; - switch (tp->trd_type) { - case EF_NUKE: - np = &tgp->nuk; - if (!getsect(np->nuk_x, np->nuk_y, §)) - return 0; - tp->trd_owner = sect.sct_own; - natp = getnatp(tp->trd_owner); - pr("(%3d) ", sect.sct_own); - needcomma = 0; - for (i = 0; i < N_MAXNUKE; i++) { - if (np->nuk_types[i]) { - if (needcomma) - pr(","); - pr("%dx%s", np->nuk_types[i], nchr[i].n_name); - needcomma = 1; - } - } - break; - case EF_SHIP: - sp = &tgp->shp; - tp->trd_owner = sp->shp_own; - pr("(%3d) tech %d %d%% %s [", - tp->trd_owner, - sp->shp_tech, - sp->shp_effic, - prship(sp)); + price = multread(tp->trd_owner, player->cnum) * tp->trd_price; + switch (tp->trd_type) { + case EF_NUKE: + np = &tgp->nuk; + if (!getsect(np->nuk_x, np->nuk_y, §)) + return 0; + tp->trd_owner = sect.sct_own; + natp = getnatp(tp->trd_owner); + pr("(%3d) ", sect.sct_own); + needcomma = 0; + for (i = 0; i < N_MAXNUKE; i++) { + if (np->nuk_types[i]) { + if (needcomma) + pr(","); + pr("%dx%s", np->nuk_types[i], nchr[i].n_name); + needcomma = 1; + } + } + break; + case EF_SHIP: + sp = &tgp->shp; + tp->trd_owner = sp->shp_own; + pr("(%3d) tech %d %d%% %s [", + tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp)); - for (i = 0; i < sp->shp_nv; i++) { - pr("%c:%d ", - ichr[sp->shp_vtype[i] & ~VT_TYPE].i_mnem, - sp->shp_vamt[i]); - } - pr("] #%d", tp->trd_unitid); - if (opt_SHOWPLANE) { - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) - { - if (plane.pln_ship == sp->shp_uid && - plane.pln_own != 0) - { - pr("\n\t\t\t\t tech %3d %3d%% %s #%d", - plane.pln_tech, - plane.pln_effic, - plchr[(int)plane.pln_type].pl_name, - plane.pln_uid); - if (plane.pln_nuketype != (s_char)-1) - { - pr("(%s)",nchr[(int)plane.pln_nuketype].n_name); - } - } + for (i = 0; i < sp->shp_nv; i++) { + pr("%c:%d ", + ichr[sp->shp_vtype[i] & ~VT_TYPE].i_mnem, sp->shp_vamt[i]); + } + pr("] #%d", tp->trd_unitid); + if (opt_SHOWPLANE) { + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_ship == sp->shp_uid && plane.pln_own != 0) { + pr("\n\t\t\t\t tech %3d %3d%% %s #%d", + plane.pln_tech, + plane.pln_effic, + plchr[(int)plane.pln_type].pl_name, plane.pln_uid); + if (plane.pln_nuketype != (s_char)-1) { + pr("(%s)", nchr[(int)plane.pln_nuketype].n_name); } - snxtitem_all(&ni, EF_LAND); - while (nxtitem(&ni, (s_char *)&land)) - { - if (land.lnd_ship == sp->shp_uid && - land.lnd_own != 0) - { - pr("\n\t\t\t\t tech %3d %3d%% %s #%d", - land.lnd_tech, - land.lnd_effic, - lchr[(int)land.lnd_type].l_name, - land.lnd_uid); - if (land.lnd_nxlight) - { - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) - { - if (plane.pln_land == land.lnd_uid) - { - pr("\n\t\t\t\t tech %3d %3d%% %s #%d", - plane.pln_tech, - plane.pln_effic, - plchr[(int)plane.pln_type].pl_name, - plane.pln_uid); - if (plane.pln_nuketype != (s_char)-1) - { - pr("(%s)", - nchr[(int)plane.pln_nuketype].n_name); - } - } + } + } + snxtitem_all(&ni, EF_LAND); + while (nxtitem(&ni, (s_char *)&land)) { + if (land.lnd_ship == sp->shp_uid && land.lnd_own != 0) { + pr("\n\t\t\t\t tech %3d %3d%% %s #%d", + land.lnd_tech, + land.lnd_effic, + lchr[(int)land.lnd_type].l_name, land.lnd_uid); + if (land.lnd_nxlight) { + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_land == land.lnd_uid) { + pr("\n\t\t\t\t tech %3d %3d%% %s #%d", + plane.pln_tech, + plane.pln_effic, + plchr[(int)plane.pln_type].pl_name, + plane.pln_uid); + if (plane.pln_nuketype != (s_char)-1) { + pr("(%s)", + nchr[(int)plane.pln_nuketype]. + n_name); } } } } } - getsect(sp->shp_x, sp->shp_y, §); - if (sect.sct_type != SCT_WATER) - pr(" in a %s %s", cname(sect.sct_own), - dchr[sect.sct_type].d_name); - else - pr(" at sea"); - break; - case EF_LAND: - lp = &tgp->lnd; - tp->trd_owner = lp->lnd_own; - pr("(%3d) tech %d %d%% %s [", - tp->trd_owner, - lp->lnd_tech, - lp->lnd_effic, - lchr[(int)lp->lnd_type].l_name); - for (i = 0; i < lp->lnd_nv; i++) { - pr("%c:%d ", - ichr[lp->lnd_vtype[i] & ~VT_TYPE].i_mnem, - lp->lnd_vamt[i]); - } - pr("] #%d", tp->trd_unitid); - if (opt_SHOWPLANE) { - snxtitem_all(&ni, EF_PLANE); - while (nxtitem(&ni, (s_char *)&plane)) - { - if (plane.pln_land == lp->lnd_uid && - plane.pln_own != 0) - { - pr("\n\t\t\t\t tech %3d %3d%% %s #%d", - plane.pln_tech, - plane.pln_effic, - plchr[(int)plane.pln_type].pl_name, - plane.pln_uid); - if (plane.pln_nuketype != (s_char)-1) - { - pr("(%s)", - nchr[(int)plane.pln_nuketype].n_name); - } - } + } + } + getsect(sp->shp_x, sp->shp_y, §); + if (sect.sct_type != SCT_WATER) + pr(" in a %s %s", cname(sect.sct_own), + dchr[sect.sct_type].d_name); + else + pr(" at sea"); + break; + case EF_LAND: + lp = &tgp->lnd; + tp->trd_owner = lp->lnd_own; + pr("(%3d) tech %d %d%% %s [", + tp->trd_owner, + lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name); + for (i = 0; i < lp->lnd_nv; i++) { + pr("%c:%d ", + ichr[lp->lnd_vtype[i] & ~VT_TYPE].i_mnem, lp->lnd_vamt[i]); + } + pr("] #%d", tp->trd_unitid); + if (opt_SHOWPLANE) { + snxtitem_all(&ni, EF_PLANE); + while (nxtitem(&ni, (s_char *)&plane)) { + if (plane.pln_land == lp->lnd_uid && plane.pln_own != 0) { + pr("\n\t\t\t\t tech %3d %3d%% %s #%d", + plane.pln_tech, + plane.pln_effic, + plchr[(int)plane.pln_type].pl_name, plane.pln_uid); + if (plane.pln_nuketype != (s_char)-1) { + pr("(%s)", nchr[(int)plane.pln_nuketype].n_name); } } - getsect(lp->lnd_x, lp->lnd_y, §); - break; - case EF_PLANE: - pp = &tgp->pln; - tp->trd_owner = pp->pln_own; - pr("(%3d) tech %d %d%% %s #%d", - tp->trd_owner, - pp->pln_tech, - pp->pln_effic, - plchr[(int)pp->pln_type].pl_name, - tp->trd_unitid); - if (pp->pln_nuketype != (s_char)-1) { - pr("(%s)", nchr[(int)pp->pln_nuketype].n_name); - } - break; - default: - pr("flaky unit type %d", tp->trd_type); - break; + } + } + getsect(lp->lnd_x, lp->lnd_y, §); + break; + case EF_PLANE: + pp = &tgp->pln; + tp->trd_owner = pp->pln_own; + pr("(%3d) tech %d %d%% %s #%d", + tp->trd_owner, + pp->pln_tech, + pp->pln_effic, + plchr[(int)pp->pln_type].pl_name, tp->trd_unitid); + if (pp->pln_nuketype != (s_char)-1) { + pr("(%s)", nchr[(int)pp->pln_nuketype].n_name); } - return 1; + break; + default: + pr("flaky unit type %d", tp->trd_type); + break; + } + return 1; } int trade_getitem(struct trdstr *tp, union trdgenstr *tgp) { - if (!ef_read(tp->trd_type, tp->trd_unitid, (s_char *)tgp)) - return 0; - return 1; + if (!ef_read(tp->trd_type, tp->trd_unitid, (s_char *)tgp)) + return 0; + return 1; } long @@ -284,7 +258,7 @@ get_couval(int cnum) if (sp->sct_own != cnum) continue; secttot += (long)(dchr[sp->sct_type].d_value * - ((float)sp->sct_effic+100.0)); + ((float)sp->sct_effic + 100.0)); for (k = 0; ichr[k].i_name; k++) { if (ichr[k].i_value == 0 || ichr[k].i_vtype == 0) continue; @@ -315,7 +289,7 @@ struct ichrstr * whichitem(char p) { register int i; - + if (p == 0) return 0; for (i = 1; ichr[i].i_mnem != 0; i++) @@ -324,4 +298,3 @@ whichitem(char p) pr("Unrecognized item \"%c\"\n", p); return 0; } - diff --git a/src/lib/subs/trechk.c b/src/lib/subs/trechk.c index e301f45ce..7b2dcd149 100644 --- a/src/lib/subs/trechk.c +++ b/src/lib/subs/trechk.c @@ -52,83 +52,83 @@ int trechk(register natid actor, register natid victim, int provision) { - register natid cn; - s_char buf[1024]; - int news_verb; - int involved[MAXNOC]; - struct trtstr treaty; - time_t now; - int conditions; - natid other; - int broken; - int applied; - struct nstr_item nstr; + register natid cn; + s_char buf[1024]; + int news_verb; + int involved[MAXNOC]; + struct trtstr treaty; + time_t now; + int conditions; + natid other; + int broken; + int applied; + struct nstr_item nstr; - if (!opt_TREATIES) - return 1; - (void) time(&now); - broken = 0; - applied = 0; - for (cn = 0; cn < MAXNOC; cn++) - involved[cn] = 0; - snxtitem_all(&nstr, EF_TREATY); - while (nxtitem(&nstr, (s_char *)&treaty)) { - if (treaty.trt_status == TS_FREE) - continue; - if (treaty.trt_exp < now) - continue; - if (actor == treaty.trt_cna) { - conditions = treaty.trt_acond; - other = treaty.trt_cnb; - } else if (actor == treaty.trt_cnb) { - conditions = treaty.trt_bcond; - other = treaty.trt_cna; - } else - continue; - if ((conditions & provision) == 0) - continue; - if (victim != other) { - switch (provision) { - /* These are violations no matter who the victim is */ - case NEWSHP: - case NEWLND: - case NEWNUK: - case NEWPLN: - case TRTENL: - break; - default: - /* The rest are only violations against the victim */ - continue; - } - } - /* treaty applies to actor */ - applied++; - pr("This action is in contravention of "); - if (treaty.trt_status == TS_PROPOSED) - pr("pending "); - pr(" treaty #%d (with %s)\n", nstr.cur, cname(other)); - getstring("Do you wish to go ahead anyway? [yn] ", buf); - if (*buf == 'n' || *buf == 'N') - broken = 0; - else - broken = 1; - if (treaty.trt_status == TS_SIGNED) - involved[other]++; - } - if (applied > 0) { - news_verb = N_HONOR_TRE; - if (broken > 0) - news_verb = N_VIOL_TRE; - for (cn=0; cn < MAXNOC; cn++) - if (involved[cn] > 0) - nreport(actor, news_verb, cn, 1); - } - if (applied && !broken) { - /* - * if any treaty applied, and none were broken - * the intended action is NOT performed. - */ - return 0; - } + if (!opt_TREATIES) return 1; + (void)time(&now); + broken = 0; + applied = 0; + for (cn = 0; cn < MAXNOC; cn++) + involved[cn] = 0; + snxtitem_all(&nstr, EF_TREATY); + while (nxtitem(&nstr, (s_char *)&treaty)) { + if (treaty.trt_status == TS_FREE) + continue; + if (treaty.trt_exp < now) + continue; + if (actor == treaty.trt_cna) { + conditions = treaty.trt_acond; + other = treaty.trt_cnb; + } else if (actor == treaty.trt_cnb) { + conditions = treaty.trt_bcond; + other = treaty.trt_cna; + } else + continue; + if ((conditions & provision) == 0) + continue; + if (victim != other) { + switch (provision) { + /* These are violations no matter who the victim is */ + case NEWSHP: + case NEWLND: + case NEWNUK: + case NEWPLN: + case TRTENL: + break; + default: + /* The rest are only violations against the victim */ + continue; + } + } + /* treaty applies to actor */ + applied++; + pr("This action is in contravention of "); + if (treaty.trt_status == TS_PROPOSED) + pr("pending "); + pr(" treaty #%d (with %s)\n", nstr.cur, cname(other)); + getstring("Do you wish to go ahead anyway? [yn] ", buf); + if (*buf == 'n' || *buf == 'N') + broken = 0; + else + broken = 1; + if (treaty.trt_status == TS_SIGNED) + involved[other]++; + } + if (applied > 0) { + news_verb = N_HONOR_TRE; + if (broken > 0) + news_verb = N_VIOL_TRE; + for (cn = 0; cn < MAXNOC; cn++) + if (involved[cn] > 0) + nreport(actor, news_verb, cn, 1); + } + if (applied && !broken) { + /* + * if any treaty applied, and none were broken + * the intended action is NOT performed. + */ + return 0; + } + return 1; } diff --git a/src/lib/subs/whatitem.c b/src/lib/subs/whatitem.c index e531739c4..23e8a8de8 100644 --- a/src/lib/subs/whatitem.c +++ b/src/lib/subs/whatitem.c @@ -38,17 +38,17 @@ struct ichrstr * whatitem(s_char *ptr, s_char *prompt) { - register s_char *p; - register struct ichrstr *ip; - s_char buf[1024]; + register s_char *p; + register struct ichrstr *ip; + s_char buf[1024]; - p = getstarg(ptr, prompt, buf); - if (p == 0 || *p == 0) - return 0; - for (ip = &ichr[1]; ip->i_mnem != 0; ip++) { - if (*p == ip->i_mnem) - return ip; - } - pr("Unrecognized item \"%c\"\n", *p); + p = getstarg(ptr, prompt, buf); + if (p == 0 || *p == 0) return 0; + for (ip = &ichr[1]; ip->i_mnem != 0; ip++) { + if (*p == ip->i_mnem) + return ip; + } + pr("Unrecognized item \"%c\"\n", *p); + return 0; } diff --git a/src/lib/subs/wire.c b/src/lib/subs/wire.c index 12e5482ef..b411c5886 100644 --- a/src/lib/subs/wire.c +++ b/src/lib/subs/wire.c @@ -45,45 +45,44 @@ int typed_wire(natid from, natid to, s_char *message, int type) { - register s_char *bp; - int len; - struct telstr tel; - struct natstr *np; - struct iovec iov[2]; - int fd; - s_char buf[1024]; + register s_char *bp; + int len; + struct telstr tel; + struct natstr *np; + struct iovec iov[2]; + int fd; + s_char buf[1024]; - if ((np = getnatp(to)) == 0 || - ((np->nat_stat & STAT_NORM) == 0 && - (np->nat_stat & STAT_SANCT) == 0)) - return 0; - if ((fd = open(wirebox(buf, to), O_WRONLY|O_APPEND, 0)) < 0) { - logerror("telegram 'open' of %s (#%d) failed", - wirebox(buf, to), to); - return 0; - } - tel.tel_from = from; - (void) time(&tel.tel_date); - bp = message; - while (*bp++) - ; - len = bp - message; - if (len >= MAXTELSIZE) - len = MAXTELSIZE; - message[len] = 0; - tel.tel_length = len; - tel.tel_type = type; - iov[0].iov_base = (caddr_t) &tel; - iov[0].iov_len = sizeof(tel); - iov[1].iov_base = message; - iov[1].iov_len = len; - if (writev(fd, iov, 2) < iov[0].iov_len + iov[1].iov_len) { - logerror("telegram 'write' to #%d failed", to); - } else { - np->nat_ann++; - /* don't do putnat because of expense */ - } - (void) close(fd); + if ((np = getnatp(to)) == 0 || + ((np->nat_stat & STAT_NORM) == 0 && + (np->nat_stat & STAT_SANCT) == 0)) return 0; + if ((fd = open(wirebox(buf, to), O_WRONLY | O_APPEND, 0)) < 0) { + logerror("telegram 'open' of %s (#%d) failed", + wirebox(buf, to), to); + return 0; + } + tel.tel_from = from; + (void)time(&tel.tel_date); + bp = message; + while (*bp++) ; + len = bp - message; + if (len >= MAXTELSIZE) + len = MAXTELSIZE; + message[len] = 0; + tel.tel_length = len; + tel.tel_type = type; + iov[0].iov_base = (caddr_t)&tel; + iov[0].iov_len = sizeof(tel); + iov[1].iov_base = message; + iov[1].iov_len = len; + if (writev(fd, iov, 2) < iov[0].iov_len + iov[1].iov_len) { + logerror("telegram 'write' to #%d failed", to); + } else { + np->nat_ann++; + /* don't do putnat because of expense */ + } + (void)close(fd); + return 0; } #endif diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c index 6f516db2e..18b5d3255 100644 --- a/src/lib/subs/wu.c +++ b/src/lib/subs/wu.c @@ -44,14 +44,14 @@ #include "player.h" #include "prototypes.h" -static struct telstr last_tel[MAXNOC]; +static struct telstr last_tel[MAXNOC]; void clear_telegram_is_new(natid to) { - last_tel[to].tel_type = 0; - last_tel[to].tel_from = 0; - last_tel[to].tel_date = 0; + last_tel[to].tel_type = 0; + last_tel[to].tel_from = 0; + last_tel[to].tel_date = 0; } /* @@ -60,135 +60,131 @@ clear_telegram_is_new(natid to) */ static int -telegram_is_new (natid to, struct telstr *tel) +telegram_is_new(natid to, struct telstr *tel) { - extern int update_pending; - int is_new = 0; + extern int update_pending; + int is_new = 0; - is_new |= tel->tel_type != last_tel[to].tel_type; - is_new |= tel->tel_from != last_tel[to].tel_from; - is_new |= !update_pending && /* sometimes updates take a long time */ - abs (tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS; - - last_tel[to].tel_type = tel->tel_type; - last_tel[to].tel_from = tel->tel_from; - last_tel[to].tel_date = tel->tel_date; + is_new |= tel->tel_type != last_tel[to].tel_type; + is_new |= tel->tel_from != last_tel[to].tel_from; + is_new |= !update_pending && /* sometimes updates take a long time */ + abs(tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS; - return is_new; + last_tel[to].tel_type = tel->tel_type; + last_tel[to].tel_from = tel->tel_from; + last_tel[to].tel_date = tel->tel_date; + + return is_new; } /*VARARGS*/ int wu(natid from, natid to, s_char *format, ...) { - struct natstr *np; - va_list ap; - s_char buf[4096]; - extern int update_pending; - - va_start(ap, format); - (void) vsprintf(buf, format, ap); - va_end(ap); - np = getnatp(from); - if (update_pending) - return typed_wu(from, to, buf, TEL_UPDATE); - else if (np->nat_stat & STAT_GOD) - return typed_wu(from, to, buf, TEL_BULLETIN); - else - return typed_wu(from, to, buf, TEL_NORM); + struct natstr *np; + va_list ap; + s_char buf[4096]; + extern int update_pending; + + va_start(ap, format); + (void)vsprintf(buf, format, ap); + va_end(ap); + np = getnatp(from); + if (update_pending) + return typed_wu(from, to, buf, TEL_UPDATE); + else if (np->nat_stat & STAT_GOD) + return typed_wu(from, to, buf, TEL_BULLETIN); + else + return typed_wu(from, to, buf, TEL_NORM); } int typed_wu(natid from, natid to, s_char *message, int type) { - register s_char *bp; - int len; - struct telstr tel; - struct natstr *np; + register s_char *bp; + int len; + struct telstr tel; + struct natstr *np; #if !defined(_WIN32) - struct iovec iov[2]; + struct iovec iov[2]; #endif - int fd; - s_char box[1024]; - int notify = 0; - int new_tele = 0; - struct player *other; - - if (type == TEL_ANNOUNCE) - strcpy(box, annfil); - else - mailbox(box, to); - - if (type != TEL_ANNOUNCE) - if ((np = getnatp(to)) == 0 || - ((np->nat_stat & STAT_NORM) == 0 && - (np->nat_stat & STAT_SANCT) == 0)) { - return -1; - } - + int fd; + s_char box[1024]; + int notify = 0; + int new_tele = 0; + struct player *other; + + if (type == TEL_ANNOUNCE) + strcpy(box, annfil); + else + mailbox(box, to); + + if (type != TEL_ANNOUNCE) + if ((np = getnatp(to)) == 0 || + ((np->nat_stat & STAT_NORM) == 0 && + (np->nat_stat & STAT_SANCT) == 0)) { + return -1; + } #if !defined(_WIN32) - if ((fd = open(box, O_WRONLY|O_APPEND, 0)) < 0) { + if ((fd = open(box, O_WRONLY | O_APPEND, 0)) < 0) { #else - if ((fd = open(box, O_WRONLY|O_APPEND|O_BINARY, 0)) < 0) { + if ((fd = open(box, O_WRONLY | O_APPEND | O_BINARY, 0)) < 0) { #endif - logerror("telegram 'open' of %s (#%d) failed", box, to); - return -1; - } - tel.tel_from = from; - (void) time(&tel.tel_date); - bp = message; - while (*bp++) - ; - len = bp - message; - if (len >= MAXTELSIZE) - len = (MAXTELSIZE - 1); - message[len] = 0; - tel.tel_length = len; - tel.tel_type = type; + logerror("telegram 'open' of %s (#%d) failed", box, to); + return -1; + } + tel.tel_from = from; + (void)time(&tel.tel_date); + bp = message; + while (*bp++) ; + len = bp - message; + if (len >= MAXTELSIZE) + len = (MAXTELSIZE - 1); + message[len] = 0; + tel.tel_length = len; + tel.tel_type = type; #if !defined(_WIN32) - iov[0].iov_base = (caddr_t) &tel; - iov[0].iov_len = sizeof(tel); - iov[1].iov_base = message; - iov[1].iov_len = len; - if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) { + iov[0].iov_base = (caddr_t)&tel; + iov[0].iov_len = sizeof(tel); + iov[1].iov_base = message; + iov[1].iov_len = len; + if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) { #else if ((write(fd, &tel, sizeof(tel)) != sizeof(tel)) || - (write(fd, message, len) != len)) { + (write(fd, message, len) != len)) { #endif - logerror("telegram 'write' to #%d failed", to); - } else if (type == TEL_ANNOUNCE) { - for (to=0; NULL != (np = getnatp(to)); to++) { - if (!(np->nat_stat & STAT_NORM) && - !(np->nat_stat & STAT_SANCT)) - continue; - if (!player->god && (getrejects(from,np) & REJ_ANNO)) - continue; - notify = (np->nat_ann == 0); - np->nat_ann++; - putnat(np); - if (notify) - player_wakeup_all(to); - } - } else { - notify = (np->nat_tgms == 0); - new_tele = telegram_is_new(to, &tel); - np->nat_tgms += new_tele || notify; - putnat(np); - - if (new_tele && np->nat_flags & NF_INFORM) { - if (NULL != (other = getplayer(to))) { - if (np->nat_tgms == 1) - pr_inform(other, "[new tele]\n"); - else - pr_inform(other, "[%d new teles]\n", - np->nat_tgms); - player_wakeup_all(to); - } - } else if (notify) - player_wakeup_all(to); + logerror("telegram 'write' to #%d failed", to); + } else if (type == TEL_ANNOUNCE) { + for (to = 0; NULL != (np = getnatp(to)); to++) { + if (!(np->nat_stat & STAT_NORM) && + !(np->nat_stat & STAT_SANCT)) + continue; + if (!player->god && (getrejects(from, np) & REJ_ANNO)) + continue; + notify = (np->nat_ann == 0); + np->nat_ann++; + putnat(np); + if (notify) + player_wakeup_all(to); } - - close(fd); - return 0; + } else { + notify = (np->nat_tgms == 0); + new_tele = telegram_is_new(to, &tel); + np->nat_tgms += new_tele || notify; + putnat(np); + + if (new_tele && np->nat_flags & NF_INFORM) { + if (NULL != (other = getplayer(to))) { + if (np->nat_tgms == 1) + pr_inform(other, "[new tele]\n"); + else + pr_inform(other, "[%d new teles]\n", np->nat_tgms); + player_wakeup_all(to); + } + } else if (notify) + player_wakeup_all(to); + } + + close(fd); + return 0; } - diff --git a/src/lib/update/age.c b/src/lib/update/age.c index 2e1c78962..34b252412 100644 --- a/src/lib/update/age.c +++ b/src/lib/update/age.c @@ -40,63 +40,60 @@ void age_levels(int etu) { - extern float level_age_rate; - register float best_tech; - register float best_res; - register struct natstr *np; - int i; - double level; - double delta; - int deltares; + extern float level_age_rate; + register float best_tech; + register float best_res; + register struct natstr *np; + int i; + double level; + double delta; + int deltares; - best_tech = 0.0; - best_res = 0.0; - for (i=0; NULL != (np = getnatp(i)); i++) { - if ((np->nat_stat & STAT_NORM) == 0) - continue; + best_tech = 0.0; + best_res = 0.0; + for (i = 0; NULL != (np = getnatp(i)); i++) { + if ((np->nat_stat & STAT_NORM) == 0) + continue; - if (np->nat_stat & STAT_GOD) - continue; + if (np->nat_stat & STAT_GOD) + continue; - if (np->nat_stat == VIS) - continue; + if (np->nat_stat == VIS) + continue; - if (best_tech < np->nat_level[NAT_TLEV]) - best_tech = np->nat_level[NAT_TLEV]; - if (best_res < np->nat_level[NAT_RLEV]) - best_res = np->nat_level[NAT_RLEV]; - if (level_age_rate != 0.0) { - delta = np->nat_level[NAT_RLEV] * etu / - (100 * level_age_rate); - np->nat_level[NAT_RLEV] -= delta; - delta = np->nat_level[NAT_TLEV] * etu / - (100 * level_age_rate); - np->nat_level[NAT_TLEV] -= delta; - } - /* - * age reserves by 1% per every 24 etus - */ - deltares = -roundavg(np->nat_reserve * etu / 2400.0); - if (deltares != 0) - np->nat_reserve += deltares; - /* Chad Zabel - above number is negative ( was a -= there - which was wrong. */ - } - best_tech /= 5; - best_res /= 5; - for (i=0; NULL != (np = getnatp(i)); i++) { - if ((np->nat_stat & STAT_INUSE) == 0) - continue; - if (np->nat_stat & STAT_GOD) - continue; - if (np->nat_stat == VIS) - continue; - level = np->nat_level[NAT_TLEV]; - if (level < best_tech && chance(0.2)) - np->nat_level[NAT_TLEV] += (best_tech - level) / 3; - level = np->nat_level[NAT_RLEV]; - if (level < best_res && chance(0.2)) - np->nat_level[NAT_RLEV] += (best_res - level) / 3; + if (best_tech < np->nat_level[NAT_TLEV]) + best_tech = np->nat_level[NAT_TLEV]; + if (best_res < np->nat_level[NAT_RLEV]) + best_res = np->nat_level[NAT_RLEV]; + if (level_age_rate != 0.0) { + delta = np->nat_level[NAT_RLEV] * etu / (100 * level_age_rate); + np->nat_level[NAT_RLEV] -= delta; + delta = np->nat_level[NAT_TLEV] * etu / (100 * level_age_rate); + np->nat_level[NAT_TLEV] -= delta; } + /* + * age reserves by 1% per every 24 etus + */ + deltares = -roundavg(np->nat_reserve * etu / 2400.0); + if (deltares != 0) + np->nat_reserve += deltares; + /* Chad Zabel - above number is negative ( was a -= there + which was wrong. */ + } + best_tech /= 5; + best_res /= 5; + for (i = 0; NULL != (np = getnatp(i)); i++) { + if ((np->nat_stat & STAT_INUSE) == 0) + continue; + if (np->nat_stat & STAT_GOD) + continue; + if (np->nat_stat == VIS) + continue; + level = np->nat_level[NAT_TLEV]; + if (level < best_tech && chance(0.2)) + np->nat_level[NAT_TLEV] += (best_tech - level) / 3; + level = np->nat_level[NAT_RLEV]; + if (level < best_res && chance(0.2)) + np->nat_level[NAT_RLEV] += (best_res - level) / 3; + } } - diff --git a/src/lib/update/anno.c b/src/lib/update/anno.c index 763951724..06d235b71 100644 --- a/src/lib/update/anno.c +++ b/src/lib/update/anno.c @@ -47,91 +47,94 @@ void delete_old_announcements(void) { - time_t now; - time_t old; - struct telstr tgm; - FILE *oldfp; - int tmpfd; - s_char tmp_filename[1024]; - int writeit; - s_char message[MAXTELSIZE]; - int deleted = 0; - int saved = 0; - int length; - int nbytes; - int first = 1; + time_t now; + time_t old; + struct telstr tgm; + FILE *oldfp; + int tmpfd; + s_char tmp_filename[1024]; + int writeit; + s_char message[MAXTELSIZE]; + int deleted = 0; + int saved = 0; + int length; + int nbytes; + int first = 1; - time(&now); - old = now - days(ANNO_KEEP_DAYS); - logerror("Deleting annos older than %s", ctime(&old)); + time(&now); + old = now - days(ANNO_KEEP_DAYS); + logerror("Deleting annos older than %s", ctime(&old)); #if !defined(_WIN32) - if ((oldfp = fopen(annfil, "r+")) == 0) { + if ((oldfp = fopen(annfil, "r+")) == 0) { #else - if ((oldfp = fopen(annfil, "r+b")) == 0) { + if ((oldfp = fopen(annfil, "r+b")) == 0) { #endif - logerror("can't read telegram file %s", annfil); - return; - } - sprintf(tmp_filename, "%s.tmp", annfil); + logerror("can't read telegram file %s", annfil); + return; + } + sprintf(tmp_filename, "%s.tmp", annfil); #if !defined(_WIN32) - if ((tmpfd = open(tmp_filename, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) { + if ((tmpfd = + open(tmp_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { #else - if ((tmpfd = open(tmp_filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666)) < 0) { + if ((tmpfd = + open(tmp_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, + 0666)) < 0) { #endif - logerror("can't write telegram file %s", tmp_filename); + logerror("can't write telegram file %s", tmp_filename); + return; + } + while (fread((s_char *)&tgm, sizeof(tgm), 1, oldfp) == 1) { + writeit = 1; + if (tgm.tel_length < 0) { + logerror("bad telegram file header (length)"); + return; + } + if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) { + logerror("bad telegram file header (type)"); + writeit = 0; + } + if (first) { + first = 0; + if (tgm.tel_date >= old) { + fclose(oldfp); return; + } } - while (fread((s_char *) &tgm, sizeof(tgm), 1, oldfp) == 1) { - writeit = 1; - if (tgm.tel_length < 0) { - logerror("bad telegram file header (length)"); - return; - } - if (tgm.tel_type < 0 || tgm.tel_type > TEL_LAST) { - logerror("bad telegram file header (type)"); - writeit = 0; - } - if (first) { - first = 0; - if (tgm.tel_date >= old) { - fclose(oldfp); - return; - } - } - - if (tgm.tel_date < old) { - writeit = 0; - } - if (writeit) { - if (write(tmpfd, &tgm, sizeof(tgm)) < (int)sizeof(tgm)) { - logerror("error writing to ann.tmp"); - return; - } - ++saved; - } else { - ++deleted; - } - length = tgm.tel_length; - while (length > 0) { - nbytes = length; - if (nbytes > (int)sizeof(message)) - nbytes = sizeof(message); - (void) fread(message, sizeof(s_char), nbytes, oldfp); - if (writeit) { - if (write(tmpfd, message, nbytes) < nbytes) { - logerror("Error writing to ann.tmp"); - return; - } - } - length -= nbytes; + if (tgm.tel_date < old) { + writeit = 0; + } + + if (writeit) { + if (write(tmpfd, &tgm, sizeof(tgm)) < (int)sizeof(tgm)) { + logerror("error writing to ann.tmp"); + return; + } + ++saved; + } else { + ++deleted; + } + length = tgm.tel_length; + while (length > 0) { + nbytes = length; + if (nbytes > (int)sizeof(message)) + nbytes = sizeof(message); + (void)fread(message, sizeof(s_char), nbytes, oldfp); + if (writeit) { + if (write(tmpfd, message, nbytes) < nbytes) { + logerror("Error writing to ann.tmp"); + return; } + } + length -= nbytes; } - logerror("%d announcements deleted; %d announcements saved", - deleted, saved); - fclose(oldfp); - close(tmpfd); - unlink(annfil); - rename(tmp_filename, annfil); + } + logerror("%d announcements deleted; %d announcements saved", + deleted, saved); + fclose(oldfp); + close(tmpfd); + unlink(annfil); + rename(tmp_filename, annfil); } diff --git a/src/lib/update/bp.c b/src/lib/update/bp.c index e608f7204..ab3038d25 100644 --- a/src/lib/update/bp.c +++ b/src/lib/update/bp.c @@ -41,57 +41,59 @@ #include "common.h" #include "optlist.h" -static int bud_key[I_MAX+2] = {0,1,2,3,4,0,0,0,0,0,0,5,6,0,0,7}; +static int bud_key[I_MAX + 2] = + { 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 5, 6, 0, 0, 7 }; int -*get_wp(int *bp, struct sctstr *sp, int cm) +* +get_wp(int *bp, struct sctstr *sp, int cm) { - return (bp + (sp->sct_x + (sp->sct_y * WORLD_X)) + WORLD_X * WORLD_Y * (cm - 1)); + return (bp + (sp->sct_x + (sp->sct_y * WORLD_X)) + + WORLD_X * WORLD_Y * (cm - 1)); } int gt_bg_nmbr(int *bp, struct sctstr *sp, int comm) { - int *wp; - int cm; - int svec[I_MAX+1]; + int *wp; + int cm; + int svec[I_MAX + 1]; - if ((cm = bud_key[comm]) == 0) { - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - return svec[comm]; - } else { - wp = get_wp(bp, sp, cm); - return *wp; - } + if ((cm = bud_key[comm]) == 0) { + getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); + return svec[comm]; + } else { + wp = get_wp(bp, sp, cm); + return *wp; + } } -void pt_bg_nmbr(int *bp, struct sctstr *sp, int comm, int amount) +void +pt_bg_nmbr(int *bp, struct sctstr *sp, int comm, int amount) { - int *wp; - int cm; + int *wp; + int cm; - if ((cm = bud_key[comm]) != 0) { - wp = get_wp(bp, sp, cm); - *wp = amount; - } + if ((cm = bud_key[comm]) != 0) { + wp = get_wp(bp, sp, cm); + *wp = amount; + } } void fill_update_array(int *bp, struct sctstr *sp) { - int vec[I_MAX+1]; - int i, k; - int *wp; + int vec[I_MAX + 1]; + int i, k; + int *wp; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return; - for (i=1;i<=I_MAX;i++) - if ((k = bud_key[i]) != 0) { - wp = get_wp(bp, sp, k); + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) + return; + for (i = 1; i <= I_MAX; i++) + if ((k = bud_key[i]) != 0) { + wp = get_wp(bp, sp, k); *wp = vec[i]; - } - wp = get_wp(bp, sp, bud_key[I_MAX+1]); - *wp = sp->sct_avail; + } + wp = get_wp(bp, sp, bud_key[I_MAX + 1]); + *wp = sp->sct_avail; } - - diff --git a/src/lib/update/deliver.c b/src/lib/update/deliver.c index 025b4a01b..dd1281b41 100644 --- a/src/lib/update/deliver.c +++ b/src/lib/update/deliver.c @@ -43,77 +43,82 @@ #include "common.h" int -deliver(register struct sctstr *from, struct ichrstr *ip, int dir, int thresh, int amt_src, int plague) +deliver(register struct sctstr *from, struct ichrstr *ip, int dir, + int thresh, int amt_src, int plague) { - register struct sctstr *to; - int vtype; /* item vartype */ - int pack_src; - int amt_moved; - int amt_dst; - int mobility; - float mcost; - struct dchrstr *dp; - int n; + register struct sctstr *to; + int vtype; /* item vartype */ + int pack_src; + int amt_moved; + int amt_dst; + int mobility; + float mcost; + struct dchrstr *dp; + int n; - if (dir <= 0 || dir > DIR_UL) - return 0; - if (amt_src <= 0) - return 0; - if ((amt_moved = amt_src - thresh) <= 0) - return 0; - /* - * make sure delivery looks ok. Check where its going, - * where its coming from, and see if there is more than - * the threshold amount - */ - if (!military_control(from)) - return 0; - to = getsectp(from->sct_x+diroff[dir][0], from->sct_y+diroff[dir][1]); - if (to->sct_own != from->sct_own) { - wu(0, from->sct_own, "%s delivery walkout at %s\n", - ip->i_name, ownxy(from)); - return 0; - } - dp = &dchr[from->sct_type]; - vtype = ip->i_vtype; - pack_src = ip->i_pkg[dp->d_pkg]; - mobility = from->sct_mobil / 2; - if (vtype == V_CIVIL && from->sct_own != from->sct_oldown) { - wu(0, from->sct_own, "The conquered populace in %s refuses to relocate!\n", ownxy(from)); - return 0; - } - /* - * disallow delivery into prohibited sectors. - * calculate unit movement cost; decrease amount if - * there isn't enough mobility. - */ - mcost = sector_mcost(to, MOB_ROAD)*ip->i_lbs/pack_src; - mcost /= 4.0; + if (dir <= 0 || dir > DIR_UL) + return 0; + if (amt_src <= 0) + return 0; + if ((amt_moved = amt_src - thresh) <= 0) + return 0; + /* + * make sure delivery looks ok. Check where its going, + * where its coming from, and see if there is more than + * the threshold amount + */ + if (!military_control(from)) + return 0; + to = getsectp(from->sct_x + diroff[dir][0], + from->sct_y + diroff[dir][1]); + if (to->sct_own != from->sct_own) { + wu(0, from->sct_own, "%s delivery walkout at %s\n", + ip->i_name, ownxy(from)); + return 0; + } + dp = &dchr[from->sct_type]; + vtype = ip->i_vtype; + pack_src = ip->i_pkg[dp->d_pkg]; + mobility = from->sct_mobil / 2; + if (vtype == V_CIVIL && from->sct_own != from->sct_oldown) { + wu(0, from->sct_own, + "The conquered populace in %s refuses to relocate!\n", + ownxy(from)); + return 0; + } + /* + * disallow delivery into prohibited sectors. + * calculate unit movement cost; decrease amount if + * there isn't enough mobility. + */ + mcost = sector_mcost(to, MOB_ROAD) * ip->i_lbs / pack_src; + mcost /= 4.0; - if (mobility < mcost * amt_moved) { - /* XXX can mcost be == 0? */ - amt_moved = (int) (mobility / mcost); - if (amt_moved <= 0) - return 0; - } - amt_dst = getvar(vtype, (caddr_t)to, EF_SECTOR); - if (amt_moved + amt_dst > 9990) { - /* delivery backlog */ - if ((amt_moved = 9990 - amt_dst) <= 0) - return 0; - } - if (putvar(vtype, amt_moved + amt_dst, (s_char *)to, EF_SECTOR) < 0) { - /* "No room to deliver commodities */ - wu(0, from->sct_own, "no room for %s in %s\n", - ip->i_name, ownxy(to)); - return 0; - } - /* deliver the plague too! */ - if (plague == PLG_INFECT && getvar(V_PSTAGE, (s_char *)to,EF_SECTOR) == 0) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)to, EF_SECTOR); - n = from->sct_mobil - (int) (mcost * amt_moved); - if (n < 0) - n = 0; - from->sct_mobil = n; - return amt_moved; + if (mobility < mcost * amt_moved) { + /* XXX can mcost be == 0? */ + amt_moved = (int)(mobility / mcost); + if (amt_moved <= 0) + return 0; + } + amt_dst = getvar(vtype, (caddr_t)to, EF_SECTOR); + if (amt_moved + amt_dst > 9990) { + /* delivery backlog */ + if ((amt_moved = 9990 - amt_dst) <= 0) + return 0; + } + if (putvar(vtype, amt_moved + amt_dst, (s_char *)to, EF_SECTOR) < 0) { + /* "No room to deliver commodities */ + wu(0, from->sct_own, "no room for %s in %s\n", + ip->i_name, ownxy(to)); + return 0; + } + /* deliver the plague too! */ + if (plague == PLG_INFECT + && getvar(V_PSTAGE, (s_char *)to, EF_SECTOR) == 0) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)to, EF_SECTOR); + n = from->sct_mobil - (int)(mcost * amt_moved); + if (n < 0) + n = 0; + from->sct_mobil = n; + return amt_moved; } diff --git a/src/lib/update/distribute.c b/src/lib/update/distribute.c index 95b2d3d82..5d1987770 100644 --- a/src/lib/update/distribute.c +++ b/src/lib/update/distribute.c @@ -47,177 +47,178 @@ #include "common.h" int -dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost, double dist_e_cost) - /* import or export? */ +dodistribute(struct sctstr *sp, int imex, s_char *path, double dist_i_cost, + double dist_e_cost) + /* import or export? */ { - struct sctstr *getdistsp(); - float distpathcost(); - struct ichrstr *ip; - struct sctstr *dist; - int amt; - int thresh; - int amt_dist; - int amt_sect; - int packing; - float imcost; - float excost; - int dist_packing; - int diff; - int item; - int dists[I_MAX+1]; - int remote[I_MAX+1]; - int local[I_MAX+1]; - int changed; - int rplague; - int lplague; - - getvec(VT_ITEM, local, (s_char *)sp, EF_SECTOR); - if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y)) - return 0; - - if (getvec(VT_DIST, dists, (s_char *)sp, EF_SECTOR) <= 0) - return 0; - - if (path == (s_char *)0){ - if (sp->sct_own != 0) { - if (imex == EXPORT) /* only want this once */ - wu(0,sp->sct_own,"No path to dist sector for %s\n", - ownxy(sp)); - } - return 0; + struct sctstr *getdistsp(); + float distpathcost(); + struct ichrstr *ip; + struct sctstr *dist; + int amt; + int thresh; + int amt_dist; + int amt_sect; + int packing; + float imcost; + float excost; + int dist_packing; + int diff; + int item; + int dists[I_MAX + 1]; + int remote[I_MAX + 1]; + int local[I_MAX + 1]; + int changed; + int rplague; + int lplague; + + getvec(VT_ITEM, local, (s_char *)sp, EF_SECTOR); + if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y)) + return 0; + + if (getvec(VT_DIST, dists, (s_char *)sp, EF_SECTOR) <= 0) + return 0; + + if (path == (s_char *)0) { + if (sp->sct_own != 0) { + if (imex == EXPORT) /* only want this once */ + wu(0, sp->sct_own, "No path to dist sector for %s\n", + ownxy(sp)); } - - dist = getsectp(sp->sct_dist_x,sp->sct_dist_y); - if (dist->sct_effic >= 60) - dist_packing = dchr[dist->sct_type].d_pkg; - else - dist_packing = NPKG; /* No packing */ - - if (sp->sct_effic >= 60) - packing = dchr[sp->sct_type].d_pkg; - else - packing = NPKG; /* No packing */ - - if ((dist->sct_effic >= 60) && dchr[dist->sct_type].d_pkg == WPKG) - packing = dchr[dist->sct_type].d_pkg; - - getvec(VT_ITEM, remote, (s_char *)dist, EF_SECTOR); - lplague = rplague = changed = 0; - for (item = 1; item < I_MAX+1; item++) { - if (dists[item] == 0) - continue; - ip = &ichr[item]; - thresh = dists[item]; - /* - * calculate costs for importing and exporting. - * the div 10.0 is because delivering straight through - * to the dist sect is cheaper than stopping at each - * sector along the way (processor-timewise) - */ - excost = (dist_e_cost/ip->i_pkg[packing] * ip->i_lbs) / 10.0; - imcost = (dist_i_cost/ip->i_pkg[dist_packing] *ip->i_lbs)/10.0; - amt_sect = local[item]; - amt_dist = remote[item]; - diff = amt_sect - thresh; - if (item == I_CIVIL) - if (sp->sct_own != sp->sct_oldown) - continue; - if (item == I_CIVIL) - if (dist->sct_own != dist->sct_oldown) - continue; - if (diff < 0){ - if (imex != IMPORT) - continue; - - if (!military_control(dist)) - continue; - - diff = -diff; - /* - * import. - * don't import if no mobility. - * check to make sure have enough mobility in the - * dist sector to import what we need. - */ - if (dist->sct_mobil <= 0) { - /*logerror(" dist mobil < 0");*/ - continue; - } - amt = diff; - if (item == I_CIVIL) - amt_dist--; /* Don't send your last civ */ - - if (amt_dist < amt) { - amt = amt_dist; - if (amt_dist == 0) - continue; - } - if (dist->sct_mobil < imcost * amt) - amt = dist->sct_mobil / imcost; - - lplague++; - /* XXX replace with vector assign and putvec() */ - remote[item] -= amt; - changed++; - dist->sct_mobil -= (int) (imcost * amt); - local[item] += amt; - } else { - if (imex != EXPORT) - continue; - if (!military_control(sp)) - continue; - if ((item == I_CIVIL)&&(sp->sct_work < 100)) - continue; - if ((item == I_CIVIL)&&(sp->sct_own != sp->sct_oldown)) - continue; - /* - * export. - * don't export if no mobility. check to make sure we - * have mobility enough to do the right thing. - * also make sure that there's enough space in the - * target sector to hold the required amt. - */ - if (sp->sct_mobil <= 0) { - /*logerror(" sp mob is zero");*/ - continue; - } - amt = diff; - if (amt > amt_sect) - amt = amt_sect; - if (sp->sct_mobil < excost * amt) - amt = sp->sct_mobil / excost; - if (amt + amt_dist > 9999) - amt = 9999 - amt_dist; - if (amt == 0) - continue; - /* XXX replace with vector assign and putvec() */ - - rplague++; - local[item] -= amt; - changed++; - sp->sct_mobil -= (int) (excost * amt); - remote[item] += amt; - } + return 0; + } + + dist = getsectp(sp->sct_dist_x, sp->sct_dist_y); + if (dist->sct_effic >= 60) + dist_packing = dchr[dist->sct_type].d_pkg; + else + dist_packing = NPKG; /* No packing */ + + if (sp->sct_effic >= 60) + packing = dchr[sp->sct_type].d_pkg; + else + packing = NPKG; /* No packing */ + + if ((dist->sct_effic >= 60) && dchr[dist->sct_type].d_pkg == WPKG) + packing = dchr[dist->sct_type].d_pkg; + + getvec(VT_ITEM, remote, (s_char *)dist, EF_SECTOR); + lplague = rplague = changed = 0; + for (item = 1; item < I_MAX + 1; item++) { + if (dists[item] == 0) + continue; + ip = &ichr[item]; + thresh = dists[item]; + /* + * calculate costs for importing and exporting. + * the div 10.0 is because delivering straight through + * to the dist sect is cheaper than stopping at each + * sector along the way (processor-timewise) + */ + excost = (dist_e_cost / ip->i_pkg[packing] * ip->i_lbs) / 10.0; + imcost = + (dist_i_cost / ip->i_pkg[dist_packing] * ip->i_lbs) / 10.0; + amt_sect = local[item]; + amt_dist = remote[item]; + diff = amt_sect - thresh; + if (item == I_CIVIL) + if (sp->sct_own != sp->sct_oldown) + continue; + if (item == I_CIVIL) + if (dist->sct_own != dist->sct_oldown) + continue; + if (diff < 0) { + if (imex != IMPORT) + continue; + + if (!military_control(dist)) + continue; + + diff = -diff; + /* + * import. + * don't import if no mobility. + * check to make sure have enough mobility in the + * dist sector to import what we need. + */ + if (dist->sct_mobil <= 0) { + /*logerror(" dist mobil < 0"); */ + continue; + } + amt = diff; + if (item == I_CIVIL) + amt_dist--; /* Don't send your last civ */ + + if (amt_dist < amt) { + amt = amt_dist; + if (amt_dist == 0) + continue; + } + if (dist->sct_mobil < imcost * amt) + amt = dist->sct_mobil / imcost; + + lplague++; + /* XXX replace with vector assign and putvec() */ + remote[item] -= amt; + changed++; + dist->sct_mobil -= (int)(imcost * amt); + local[item] += amt; + } else { + if (imex != EXPORT) + continue; + if (!military_control(sp)) + continue; + if ((item == I_CIVIL) && (sp->sct_work < 100)) + continue; + if ((item == I_CIVIL) && (sp->sct_own != sp->sct_oldown)) + continue; + /* + * export. + * don't export if no mobility. check to make sure we + * have mobility enough to do the right thing. + * also make sure that there's enough space in the + * target sector to hold the required amt. + */ + if (sp->sct_mobil <= 0) { + /*logerror(" sp mob is zero"); */ + continue; + } + amt = diff; + if (amt > amt_sect) + amt = amt_sect; + if (sp->sct_mobil < excost * amt) + amt = sp->sct_mobil / excost; + if (amt + amt_dist > 9999) + amt = 9999 - amt_dist; + if (amt == 0) + continue; + /* XXX replace with vector assign and putvec() */ + + rplague++; + local[item] -= amt; + changed++; + sp->sct_mobil -= (int)(excost * amt); + remote[item] += amt; } - putvec(VT_ITEM, remote, (s_char *)dist, EF_SECTOR); - putvec(VT_ITEM, local, (s_char *)sp, EF_SECTOR); - - if (lplague) { - lplague = getvar(V_PSTAGE, (s_char *)dist, EF_SECTOR); - if (lplague == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_HEALTHY) { + } + putvec(VT_ITEM, remote, (s_char *)dist, EF_SECTOR); + putvec(VT_ITEM, local, (s_char *)sp, EF_SECTOR); + + if (lplague) { + lplague = getvar(V_PSTAGE, (s_char *)dist, EF_SECTOR); + if (lplague == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR) == PLG_HEALTHY) { putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SECTOR); - } } + } - if (rplague) { - rplague = getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR); - if (rplague == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)dist, EF_SECTOR) == PLG_HEALTHY) { + if (rplague) { + rplague = getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR); + if (rplague == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)dist, EF_SECTOR) == PLG_HEALTHY) { putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)dist, EF_SECTOR); - } } + } - return changed; + return changed; } - diff --git a/src/lib/update/finish.c b/src/lib/update/finish.c index 6811602d7..370272f94 100644 --- a/src/lib/update/finish.c +++ b/src/lib/update/finish.c @@ -50,9 +50,9 @@ /* Used for building up distribution info */ struct distinfo { - s_char *path; /* path to take */ - double imcost; /* import cost */ - double excost; /* export cost */ + s_char *path; /* path to take */ + double imcost; /* import cost */ + double excost; /* export cost */ }; /* This is our global buffer of distribution pointers. Note that @@ -68,7 +68,7 @@ struct distinfo *g_distptrs = (struct distinfo *)0; /* #define SAVE_FINISH_PATHS */ #ifndef SAVE_FINISH_PATHS -static s_char *finish_path = "h"; /* Placeholder indicating path exists */ +static s_char *finish_path = "h"; /* Placeholder indicating path exists */ #endif /* SAVE_FINISH_PATHS */ static void assemble_dist_paths(struct distinfo *distptrs); @@ -79,109 +79,109 @@ double pathcost(); void finish_sects(int etu) { - register struct sctstr *sp; - struct natstr *np; - int n; - int vec[I_MAX+1]; - int changed; - struct distinfo *infptr; + register struct sctstr *sp; + struct natstr *np; + int n; + int vec[I_MAX + 1]; + int changed; + struct distinfo *infptr; + if (g_distptrs == (struct distinfo *)0) { + logerror("First update since reboot, allocating buffer\n"); + /* Allocate the information buffer */ + g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) * + sizeof(struct distinfo))); if (g_distptrs == (struct distinfo *)0) { - logerror("First update since reboot, allocating buffer\n"); - /* Allocate the information buffer */ - g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) * - sizeof(struct distinfo))); - if (g_distptrs == (struct distinfo *)0) { - logerror("malloc failed in finish_sects.\n"); - return; - } - - logerror("Allocated '%d' bytes '%d' indices\n", - ((WORLD_X * WORLD_Y) * sizeof(struct distinfo)), - (WORLD_X * WORLD_Y)); - + logerror("malloc failed in finish_sects.\n"); + return; } - /* Wipe it clean */ - bzero((s_char *)g_distptrs, ((WORLD_X * WORLD_Y) * - sizeof(struct distinfo))); + logerror("Allocated '%d' bytes '%d' indices\n", + ((WORLD_X * WORLD_Y) * sizeof(struct distinfo)), + (WORLD_X * WORLD_Y)); - logerror("delivering...\n"); - /* Do deliveries */ - for (n=0; NULL != (sp = getsectid(n)); n++) { - if (sp->sct_type == SCT_WATER) - continue; - if (sp->sct_own == 0) - continue; - np = getnatp(sp->sct_own); - if (np->nat_money < 0) - continue; - changed = 0; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) > 0) - changed += dodeliver(sp, vec); - if (changed) - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - } - logerror("done delivering\n"); + } - logerror("assembling paths...\n"); + /* Wipe it clean */ + bzero((s_char *)g_distptrs, ((WORLD_X * WORLD_Y) * + sizeof(struct distinfo))); - /* First, enable the best_path cacheing */ - bp_enable_cachepath(); + logerror("delivering...\n"); + /* Do deliveries */ + for (n = 0; NULL != (sp = getsectid(n)); n++) { + if (sp->sct_type == SCT_WATER) + continue; + if (sp->sct_own == 0) + continue; + np = getnatp(sp->sct_own); + if (np->nat_money < 0) + continue; + changed = 0; + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) > 0) + changed += dodeliver(sp, vec); + if (changed) + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + } + logerror("done delivering\n"); - /* Now assemble the paths */ - assemble_dist_paths(g_distptrs); + logerror("assembling paths...\n"); - /* Now disable the best_path cacheing */ - bp_disable_cachepath(); + /* First, enable the best_path cacheing */ + bp_enable_cachepath(); - /* Now, clear the best_path cache that may have been created */ - bp_clear_cachepath(); + /* Now assemble the paths */ + assemble_dist_paths(g_distptrs); - logerror("done assembling paths\n"); + /* Now disable the best_path cacheing */ + bp_disable_cachepath(); - logerror("exporting..."); - for (n=0; NULL != (sp = getsectid(n)); n++) { - if (sp->sct_type == SCT_WATER || sp->sct_own == 0) - continue; - np = getnatp(sp->sct_own); - if (np->nat_money < 0) - continue; - /* Get the pointer */ - infptr = &g_distptrs[XYOFFSET(sp->sct_x, sp->sct_y)]; - dodistribute(sp, EXPORT, - infptr->path, infptr->imcost, infptr->excost); - } - logerror("done exporting\n"); + /* Now, clear the best_path cache that may have been created */ + bp_clear_cachepath(); - /* Note that we free the paths (if allocated) as we loop here */ - logerror("importing..."); - for (n=0; NULL != (sp = getsectid(n)); n++) { - /* Get the pointer (we do it first so we can free if needed) */ - infptr = &g_distptrs[XYOFFSET(sp->sct_x, sp->sct_y)]; - if (sp->sct_type == SCT_WATER || sp->sct_own == 0) { -#ifdef SAVE_FINISH_PATHS - if (infptr->path) - free((s_char *)infptr->path); -#endif /* SAVE_FINISH_PATHS */ - continue; - } - np = getnatp(sp->sct_own); - if (np->nat_money < 0) { + logerror("done assembling paths\n"); + + logerror("exporting..."); + for (n = 0; NULL != (sp = getsectid(n)); n++) { + if (sp->sct_type == SCT_WATER || sp->sct_own == 0) + continue; + np = getnatp(sp->sct_own); + if (np->nat_money < 0) + continue; + /* Get the pointer */ + infptr = &g_distptrs[XYOFFSET(sp->sct_x, sp->sct_y)]; + dodistribute(sp, EXPORT, + infptr->path, infptr->imcost, infptr->excost); + } + logerror("done exporting\n"); + + /* Note that we free the paths (if allocated) as we loop here */ + logerror("importing..."); + for (n = 0; NULL != (sp = getsectid(n)); n++) { + /* Get the pointer (we do it first so we can free if needed) */ + infptr = &g_distptrs[XYOFFSET(sp->sct_x, sp->sct_y)]; + if (sp->sct_type == SCT_WATER || sp->sct_own == 0) { #ifdef SAVE_FINISH_PATHS - if (infptr->path) - free((s_char *)infptr->path); + if (infptr->path) + free((s_char *)infptr->path); #endif /* SAVE_FINISH_PATHS */ - continue; - } - dodistribute(sp, IMPORT, - infptr->path, infptr->imcost, infptr->excost); + continue; + } + np = getnatp(sp->sct_own); + if (np->nat_money < 0) { #ifdef SAVE_FINISH_PATHS if (infptr->path) free((s_char *)infptr->path); #endif /* SAVE_FINISH_PATHS */ + continue; } - logerror("done importing\n"); + dodistribute(sp, IMPORT, + infptr->path, infptr->imcost, infptr->excost); +#ifdef SAVE_FINISH_PATHS + if (infptr->path) + free((s_char *)infptr->path); +#endif /* SAVE_FINISH_PATHS */ + } + logerror("done importing\n"); } @@ -196,16 +196,16 @@ assemble_dist_paths(struct distinfo *distptrs) int n; s_char buf[512]; - for (n=0; NULL != (sp = getsectid(n)); n++) { + for (n = 0; NULL != (sp = getsectid(n)); n++) { if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y)) continue; /* Set the pointer */ infptr = &distptrs[XYOFFSET(sp->sct_x, sp->sct_y)]; /* now, get the dist sector */ dist = getsectp(sp->sct_dist_x, sp->sct_dist_y); - if (dist == (struct sctstr *)0){ - logerror("Bad dist sect %d,%d for %d,%d !\n",sp->sct_dist_x, - sp->sct_dist_y,sp->sct_x,sp->sct_y); + if (dist == (struct sctstr *)0) { + logerror("Bad dist sect %d,%d for %d,%d !\n", sp->sct_dist_x, + sp->sct_dist_y, sp->sct_x, sp->sct_y); continue; } /* Now, get the best distribution path over roads */ @@ -242,7 +242,8 @@ assemble_dist_paths(struct distinfo *distptrs) } s_char -*ReversePath(s_char *path) +* +ReversePath(s_char *path) { s_char *patharray = "aucdefjhigklmyopqrstbvwxnz"; static s_char new_path[512]; @@ -267,4 +268,3 @@ s_char return new_path; } - diff --git a/src/lib/update/human.c b/src/lib/update/human.c index 45812a832..009c0e172 100644 --- a/src/lib/update/human.c +++ b/src/lib/update/human.c @@ -54,17 +54,18 @@ * */ int -do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, int *workp, int *bp, int etu) +do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, + int *workp, int *bp, int etu) { - extern double eatrate; - int people; - int work_avail; - int starved, sctwork; - int needed, dummy; + extern double eatrate; + int people; + int work_avail; + int starved, sctwork; + int needed, dummy; int civvies, uws; int mil; int maxpop; - + /* grow people & stuff */ sctwork = sp->sct_work; @@ -73,32 +74,33 @@ do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, int *w uws = (vec[I_UW] > maxpop) ? maxpop : vec[I_UW]; mil = (vec[I_MILIT] > maxpop) ? maxpop : vec[I_MILIT]; work_avail = total_work(sctwork, etu, civvies, mil, uws); - + people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; if (sp->sct_type != SCT_SANCT) { if (opt_NOFOOD == 0) { if (vec[I_FOOD] < 1 + etu * people * eatrate) { - /* need to grow "emergency rations" */ - work_avail -= (2 * - growfood(sp, vec, (int)(work_avail/2), etu)); - /* It's twice as hard to grow those than norm*/ - pt_bg_nmbr(bp, sp, I_MAX+1, work_avail); + /* need to grow "emergency rations" */ + work_avail -= (2 * + growfood(sp, vec, (int)(work_avail / 2), + etu)); + /* It's twice as hard to grow those than norm */ + pt_bg_nmbr(bp, sp, I_MAX + 1, work_avail); if (!player->simulation) sp->sct_avail = work_avail; } if ((vec[I_FOOD] < 1 + etu * people * eatrate) && - (sp->sct_own == sp->sct_oldown)){ - + (sp->sct_own == sp->sct_oldown)) { + /* steal food from warehouses, headquarters, supply ships in port, or supply units */ - int needed; - - needed = ldround((double)(1+etu*people*eatrate),1); - + int needed; + + needed = ldround((double)(1 + etu * people * eatrate), 1); + /* Now, find some food */ - vec[I_FOOD] = supply_commod(sp->sct_own,sp->sct_x, - sp->sct_y,I_FOOD,needed); - + vec[I_FOOD] = supply_commod(sp->sct_own, sp->sct_x, + sp->sct_y, I_FOOD, needed); + } } starved = feed_people(vec, etu, &needed); @@ -112,7 +114,7 @@ do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, int *w if (starved > 0) { if (!player->simulation) starvation(sp); - sctwork = 0; + sctwork = 0; } else { if (sp->sct_work < 100) sctwork = sp->sct_work + 8 + (random() % 15); @@ -126,7 +128,7 @@ do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, int *w sctwork = sp->sct_work = 100; /* Here is where we truncate extra people, always */ trunc_people(sp, np, vec); - + pt_bg_nmbr(bp, sp, I_CIVIL, vec[I_CIVIL]); pt_bg_nmbr(bp, sp, I_UW, vec[I_UW]); pt_bg_nmbr(bp, sp, I_MILIT, vec[I_MILIT]); @@ -137,13 +139,13 @@ do_feed(register struct sctstr *sp, register struct natstr *np, int *vec, int *w int growfood(struct sctstr *sp, register int *vec, int work, int etu) { - extern double fgrate; - extern double fcrate; - double food_fertil; - double food_workers; - double food; - int work_used; - + extern double fgrate; + extern double fcrate; + double food_fertil; + double food_workers; + double food; + int work_used; + /* I'm being very nice and commenting out this so players * won't whine about starvation if (sp->sct_fertil == 0 || work == 0) @@ -158,12 +160,12 @@ growfood(struct sctstr *sp, register int *vec, int work, int etu) * be nice; grow minimum one food unit. * This makes life simpler for the player. */ - vec[I_FOOD] += (int) food; + vec[I_FOOD] += (int)food; if (vec[I_FOOD] == 0) vec[I_FOOD] = 1; if (vec[I_FOOD] > 9999) vec[I_FOOD] = 9999; - work_used = (int) food / fcrate; + work_used = (int)food / fcrate; return work_used; } @@ -173,18 +175,19 @@ growfood(struct sctstr *sp, register int *vec, int work, int etu) int feed_people(register int *vec, int etu, int *needed) { - extern double eatrate; - double food_eaten; - double people_left; - int can_eat; - int total_people; - int to_starve; - int starved; - + extern double eatrate; + double food_eaten; + double people_left; + int can_eat; + int total_people; + int to_starve; + int starved; + if (opt_NOFOOD) return 0; food_eaten = (double)(((double)etu * (double)eatrate) * - (double)(vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW])); + (double)(vec[I_CIVIL] + vec[I_MILIT] + + vec[I_UW])); if (food_eaten <= 1) return 0; starved = 0; @@ -196,43 +199,42 @@ feed_people(register int *vec, int etu, int *needed) if (opt_NEW_STARVE) { can_eat = (vec[I_FOOD] / (etu * eatrate)); total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; - + /* only want to starve off at most 1/2 the populace. */ - if (can_eat < (total_people/2)) - can_eat = total_people/2; - - to_starve = total_people - can_eat; - while(to_starve && vec[I_UW]){ + if (can_eat < (total_people / 2)) + can_eat = total_people / 2; + + to_starve = total_people - can_eat; + while (to_starve && vec[I_UW]) { to_starve--; starved++; vec[I_UW]--; } - while(to_starve && vec[I_CIVIL]){ + while (to_starve && vec[I_CIVIL]) { to_starve--; starved++; vec[I_CIVIL]--; } - while(to_starve && vec[I_MILIT]){ + while (to_starve && vec[I_MILIT]) { to_starve--; starved++; vec[I_MILIT]--; } - + vec[I_FOOD] = 0; - } - else { /* ! opt_NEW_STARVE */ - + } else { /* ! opt_NEW_STARVE */ + people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01); starved = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; /* only want to starve off at most 1/2 the populace. */ if (people_left < 0.5) people_left = 0.5; - vec[I_CIVIL] = (int) (vec[I_CIVIL] * people_left); - vec[I_MILIT] = (int) (vec[I_MILIT] * people_left); - vec[I_UW] = (int) (vec[I_UW] * people_left); + vec[I_CIVIL] = (int)(vec[I_CIVIL] * people_left); + vec[I_MILIT] = (int)(vec[I_MILIT] * people_left); + vec[I_UW] = (int)(vec[I_UW] * people_left); starved -= vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; vec[I_FOOD] = 0; - } /* end opt_NEW_STARVE */ + } /* end opt_NEW_STARVE */ } else { vec[I_FOOD] -= roundavg(food_eaten); } @@ -243,10 +245,11 @@ feed_people(register int *vec, int etu, int *needed) * Truncate any extra people that may be around */ void -trunc_people(struct sctstr *sp, register struct natstr *np, register int *vec) +trunc_people(struct sctstr *sp, register struct natstr *np, + register int *vec) { int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); - + if (vec[I_CIVIL] > maxpop) vec[I_CIVIL] = maxpop; if (vec[I_UW] > maxpop) @@ -259,26 +262,29 @@ trunc_people(struct sctstr *sp, register struct natstr *np, register int *vec) * rate limitation on countries with high tech * production? Maybe with just high education? */ -int grow_people(struct sctstr *sp, register int etu, register struct natstr *np, int *workp, int sctwork, register int *vec) +int +grow_people(struct sctstr *sp, register int etu, + register struct natstr *np, int *workp, int sctwork, + register int *vec) { - extern double obrate; - extern double uwbrate; - extern double babyeat; - int newciv; - int newuw; - int new_birth; - int new_food; - int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); - + extern double obrate; + extern double uwbrate; + extern double babyeat; + int newciv; + int newuw; + int new_birth; + int new_food; + int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); + newciv = 0; newuw = 0; if (vec[I_CIVIL] < maxpop) { - new_birth = (int) roundavg(obrate * (double)(etu * vec[I_CIVIL])); - if (opt_NOFOOD) - new_food = (int) (0.5 + maxpop / (2.0 * babyeat)); - else /* we are using food */ - new_food = (int) (0.5 + vec[I_FOOD] / (2.0 * babyeat)); - + new_birth = (int)roundavg(obrate * (double)(etu * vec[I_CIVIL])); + if (opt_NOFOOD) + new_food = (int)(0.5 + maxpop / (2.0 * babyeat)); + else /* we are using food */ + new_food = (int)(0.5 + vec[I_FOOD] / (2.0 * babyeat)); + newciv = new_birth; if (newciv > new_food) newciv = new_food; @@ -291,12 +297,12 @@ int grow_people(struct sctstr *sp, register int etu, register struct natstr *np, /* * now grow uw's */ - new_birth = (int) roundavg(uwbrate * (double)(etu * vec[I_UW])); + new_birth = (int)roundavg(uwbrate * (double)(etu * vec[I_UW])); if (opt_NOFOOD) - new_food = (int) (0.5 + maxpop / (2.0 * babyeat)); - else /* food is important */ - new_food = (int) (0.5 + vec[I_FOOD] / (2.0 * babyeat)); - + new_food = (int)(0.5 + maxpop / (2.0 * babyeat)); + else /* food is important */ + new_food = (int)(0.5 + vec[I_FOOD] / (2.0 * babyeat)); + newuw = new_birth; if (newuw > new_food) newuw = new_food; diff --git a/src/lib/update/land.c b/src/lib/update/land.c index 2ba16105f..d31bf0108 100644 --- a/src/lib/update/land.c +++ b/src/lib/update/land.c @@ -59,381 +59,379 @@ int mil_dbl_pay; #define MIN(x,y) ((x) > (y) ? (y) : (x)) #endif -void upd_land(register struct lndstr *lp, int landno, register int etus, struct natstr *np, int *bp, int build); +void upd_land(register struct lndstr *lp, int landno, register int etus, + struct natstr *np, int *bp, int build); int prod_land(int etus, int natnum, int *bp, int build) - /* build = 1, maintain = 0 */ + /* build = 1, maintain = 0 */ { - register struct lndstr *lp; - struct sctstr *sp; - struct natstr *np; - int n, k=0; - extern long lnd_money[MAXNOC]; - int start_money; - int lastx = 9999, lasty = 9999; - - bp_enable_cachepath(); - for (n=0; NULL != (lp = getlandp(n)); n++) { - if (lp->lnd_own == 0) - continue; - if (lp->lnd_own != natnum) - continue; - - sp = getsectp(lp->lnd_x,lp->lnd_y); - if (sp->sct_type == SCT_SANCT) - continue; - if (lastx == 9999 || lasty == 9999) { - lastx = lp->lnd_x; - lasty = lp->lnd_y; - } - if (lastx != lp->lnd_x || lasty != lp->lnd_y) { - /* Reset the cache */ - bp_disable_cachepath(); - bp_clear_cachepath(); - bp_enable_cachepath(); - } - np = getnatp(lp->lnd_own); - start_money = np->nat_money; - upd_land(lp, n, etus, np, bp, build); - lnd_money[lp->lnd_own] += np->nat_money - start_money; - if ((build && (np->nat_money != start_money)) || (!build)) - k++; - if (player->simulation) - np->nat_money = start_money; - } - bp_disable_cachepath(); - bp_clear_cachepath(); - - return k; + register struct lndstr *lp; + struct sctstr *sp; + struct natstr *np; + int n, k = 0; + extern long lnd_money[MAXNOC]; + int start_money; + int lastx = 9999, lasty = 9999; + + bp_enable_cachepath(); + for (n = 0; NULL != (lp = getlandp(n)); n++) { + if (lp->lnd_own == 0) + continue; + if (lp->lnd_own != natnum) + continue; + + sp = getsectp(lp->lnd_x, lp->lnd_y); + if (sp->sct_type == SCT_SANCT) + continue; + if (lastx == 9999 || lasty == 9999) { + lastx = lp->lnd_x; + lasty = lp->lnd_y; + } + if (lastx != lp->lnd_x || lasty != lp->lnd_y) { + /* Reset the cache */ + bp_disable_cachepath(); + bp_clear_cachepath(); + bp_enable_cachepath(); + } + np = getnatp(lp->lnd_own); + start_money = np->nat_money; + upd_land(lp, n, etus, np, bp, build); + lnd_money[lp->lnd_own] += np->nat_money - start_money; + if ((build && (np->nat_money != start_money)) || (!build)) + k++; + if (player->simulation) + np->nat_money = start_money; + } + bp_disable_cachepath(); + bp_clear_cachepath(); + + return k; } void -upd_land(register struct lndstr *lp, int landno, register int etus, struct natstr *np, int *bp, int build) - /* build = 1, maintain = 0 */ +upd_land(register struct lndstr *lp, int landno, register int etus, + struct natstr *np, int *bp, int build) + /* build = 1, maintain = 0 */ { - extern int morale_base; - struct lchrstr *lcp; - int vec[I_MAX+1]; - int cvec[I_MAX+1]; - int n; - double techfact(int, double); - int min = morale_base-(int)np->nat_level[NAT_HLEV]; - int mult; - extern double money_land; - int needed; - int cost; - int eff; - - if (!player->simulation) - if (lp->lnd_retreat < min) + extern int morale_base; + struct lchrstr *lcp; + int vec[I_MAX + 1]; + int cvec[I_MAX + 1]; + int n; + double techfact(int, double); + int min = morale_base - (int)np->nat_level[NAT_HLEV]; + int mult; + extern double money_land; + int needed; + int cost; + int eff; + + if (!player->simulation) + if (lp->lnd_retreat < min) lp->lnd_retreat = min; - lcp = &lchr[(int)lp->lnd_type]; - getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - if (build == 1){ - if (np->nat_priorities[PRI_LBUILD] == 0 || - np->nat_money < 0) - return; - if (lp->lnd_effic < LAND_MINEFF || - !(landrepair(lp,vec,np,bp,etus))){ - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own = 0; - return; - } - }else{ - mult = 1; - if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85) - mult = 2; - if (lcp->l_flags & L_ENGINEER) - mult *= 3; + lcp = &lchr[(int)lp->lnd_type]; + getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); + if (build == 1) { + if (np->nat_priorities[PRI_LBUILD] == 0 || np->nat_money < 0) + return; + if (lp->lnd_effic < LAND_MINEFF || + !(landrepair(lp, vec, np, bp, etus))) { + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, + lp->lnd_y); + lp->lnd_own = 0; + return; + } + } else { + mult = 1; + if (np->nat_level[NAT_TLEV] < lp->lnd_tech * 0.85) + mult = 2; + if (lcp->l_flags & L_ENGINEER) + mult *= 3; /* cost = -(mult * etus * dmin(0.0, money_land * LND_COST(lcp->l_cost, lp->lnd_tech - lcp->l_tech)));*/ - cost = -(mult * etus * dmin(0.0, money_land * lcp->l_cost)); - if ((np->nat_priorities[PRI_LMAINT] == 0 || - np->nat_money < cost) && !player->simulation) { - if ((eff = lp->lnd_effic - etus/5) < LAND_MINEFF) { - wu(0, lp->lnd_own, - "%s lost to lack of maintenance\n", - prland(lp)); - makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); - lp->lnd_own = 0; - return; - } - wu(0, lp->lnd_own, - "%s lost %d%% to lack of maintenance\n", - prland(lp), lp->lnd_effic - eff); - lp->lnd_effic = eff; - } else { - np->nat_money -= cost; - } + cost = -(mult * etus * dmin(0.0, money_land * lcp->l_cost)); + if ((np->nat_priorities[PRI_LMAINT] == 0 || + np->nat_money < cost) && !player->simulation) { + if ((eff = lp->lnd_effic - etus / 5) < LAND_MINEFF) { + wu(0, lp->lnd_own, + "%s lost to lack of maintenance\n", prland(lp)); + makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, + lp->lnd_y); + lp->lnd_own = 0; + return; + } + wu(0, lp->lnd_own, + "%s lost %d%% to lack of maintenance\n", + prland(lp), lp->lnd_effic - eff); + lp->lnd_effic = eff; + } else { + np->nat_money -= cost; + } /* Mil costs are now part of regular mil costs, not maint costs */ /* np->nat_money += (int) (money_mil * etus * lnd_getmil(lp));*/ - /* Grab more stuff */ - if ((opt_NOFOOD == 0) && !player->simulation) - resupply_commod(lp,I_FOOD); - - getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - if (!player->simulation) { - if ((n = feed_land(lp, vec, etus, &needed, 1)) > 0) { - wu(0, lp->lnd_own, "%d starved in %s%s\n", - n, prland(lp), - (lp->lnd_effic < LAND_MINEFF ? - ", killing it" : "")); - if (n > 10) - nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1); - } - /* - * do plague stuff. plague can't break out on land units, - * but it can still kill people on them. - */ - getvec(VT_COND, cvec, (s_char *)lp, EF_LAND); - if (cvec[C_PSTAGE] > 0) { - n = plague_people(np, vec, cvec, etus); - switch (n) { - case PLG_DYING: + /* Grab more stuff */ + if ((opt_NOFOOD == 0) && !player->simulation) + resupply_commod(lp, I_FOOD); + + getvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); + if (!player->simulation) { + if ((n = feed_land(lp, vec, etus, &needed, 1)) > 0) { + wu(0, lp->lnd_own, "%d starved in %s%s\n", + n, prland(lp), + (lp->lnd_effic < LAND_MINEFF ? ", killing it" : "")); + if (n > 10) + nreport(lp->lnd_own, N_DIE_FAMINE, 0, 1); + } + /* + * do plague stuff. plague can't break out on land units, + * but it can still kill people on them. + */ + getvec(VT_COND, cvec, (s_char *)lp, EF_LAND); + if (cvec[C_PSTAGE] > 0) { + n = plague_people(np, vec, cvec, etus); + switch (n) { + case PLG_DYING: + wu(0, lp->lnd_own, + "PLAGUE deaths reported on %s\n", prland(lp)); + nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1); + break; + case PLG_INFECT: + wu(0, lp->lnd_own, "%s battling PLAGUE\n", prland(lp)); + break; + case PLG_INCUBATE: + /* Are we still incubating? */ + if (n == cvec[C_PSTAGE]) { + /* Yes. Will it turn "infectious" next time? */ + if (cvec[C_PTIME] <= etus) { + /* Yes. Report an outbreak. */ wu(0, lp->lnd_own, - "PLAGUE deaths reported on %s\n", - prland(lp)); - nreport(lp->lnd_own, N_DIE_PLAGUE, 0, 1); - break; - case PLG_INFECT: - wu(0, lp->lnd_own, "%s battling PLAGUE\n", - prland(lp)); - break; - case PLG_INCUBATE: - /* Are we still incubating? */ - if (n == cvec[C_PSTAGE]) { - /* Yes. Will it turn "infectious" next time? */ - if (cvec[C_PTIME] <= etus) { - /* Yes. Report an outbreak. */ - wu(0, lp->lnd_own, - "Outbreak of PLAGUE on %s!\n", - prland(lp)); - nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1); - } - } else { - /* It has already moved on to "infectious" */ - wu(0, lp->lnd_own, - "%s battling PLAGUE\n", prland(lp)); - } - break; - case PLG_EXPOSED: - /* Has the plague moved to "incubation" yet? */ - if (n != cvec[C_PSTAGE]) { - /* Yes. Will it turn "infectious" next time? */ - if (cvec[C_PTIME] <= etus) { - /* Yes. Report an outbreak. */ - wu(0, lp->lnd_own, - "Outbreak of PLAGUE on %s!\n", - prland(lp)); - nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1); - } - } - break; - default: - break; + "Outbreak of PLAGUE on %s!\n", prland(lp)); + nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1); } - putvec(VT_COND, cvec, (s_char *)lp, EF_LAND); - } - putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); - } /* end !player->simulation */ - } + } else { + /* It has already moved on to "infectious" */ + wu(0, lp->lnd_own, + "%s battling PLAGUE\n", prland(lp)); + } + break; + case PLG_EXPOSED: + /* Has the plague moved to "incubation" yet? */ + if (n != cvec[C_PSTAGE]) { + /* Yes. Will it turn "infectious" next time? */ + if (cvec[C_PTIME] <= etus) { + /* Yes. Report an outbreak. */ + wu(0, lp->lnd_own, + "Outbreak of PLAGUE on %s!\n", prland(lp)); + nreport(lp->lnd_own, N_OUT_PLAGUE, 0, 1); + } + } + break; + default: + break; + } + putvec(VT_COND, cvec, (s_char *)lp, EF_LAND); + } + putvec(VT_ITEM, vec, (s_char *)lp, EF_LAND); + } /* end !player->simulation */ + } } /*ARGSUSED*/ int -landrepair(register struct lndstr *land, int *vec, struct natstr *np, int *bp, int etus) +landrepair(register struct lndstr *land, int *vec, struct natstr *np, + int *bp, int etus) { - extern int mil_dbl_pay; - extern int land_grow_scale; - register int delta; - struct sctstr *sp; - struct lchrstr *lp; - float leftp, buildp; - int left, build; - int mil_needed, lcm_needed, hcm_needed, gun_needed, shell_needed; - int avail; - int w_p_eff; - int mult; - int svec[I_MAX+1]; - int mvec[I_MAX+1]; - - lp = &lchr[(int)land->lnd_type]; - sp = getsectp(land->lnd_x, land->lnd_y); - if (sp->sct_off) - return 1; - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - mult = 1; - if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85) - mult = 2; + extern int mil_dbl_pay; + extern int land_grow_scale; + register int delta; + struct sctstr *sp; + struct lchrstr *lp; + float leftp, buildp; + int left, build; + int mil_needed, lcm_needed, hcm_needed, gun_needed, shell_needed; + int avail; + int w_p_eff; + int mult; + int svec[I_MAX + 1]; + int mvec[I_MAX + 1]; + + lp = &lchr[(int)land->lnd_type]; + sp = getsectp(land->lnd_x, land->lnd_y); + if (sp->sct_off) + return 1; + getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); + mult = 1; + if (np->nat_level[NAT_TLEV] < land->lnd_tech * 0.85) + mult = 2; - if (land->lnd_effic == 100) { - /* land is ok; no repairs needed */ - return 1; - } - if (sp->sct_own != land->lnd_own) - return 1; - - if (!player->simulation) - avail = sp->sct_avail * 100; - else - avail = gt_bg_nmbr(bp, sp, I_MAX+1) * 100; - - w_p_eff = 20 + (lp->l_lcm + 2 * lp->l_hcm); - delta = roundavg((double)avail/w_p_eff); - if (delta <= 0) - return 1; - if (delta > etus*land_grow_scale) - delta = etus*land_grow_scale; - - /* delta is the max amount we can grow */ - - left = 100 - land->lnd_effic; - if (left > delta) - left = delta; - - leftp = ((float)left/100.0); - - bzero((s_char *)mvec, sizeof(mvec)); - mvec[I_LCM] = lcm_needed = ldround((double)(lp->l_lcm * leftp),1); - mvec[I_HCM] = hcm_needed = ldround((double)(lp->l_hcm * leftp),1); + if (land->lnd_effic == 100) { + /* land is ok; no repairs needed */ + return 1; + } + if (sp->sct_own != land->lnd_own) + return 1; + + if (!player->simulation) + avail = sp->sct_avail * 100; + else + avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; + + w_p_eff = 20 + (lp->l_lcm + 2 * lp->l_hcm); + delta = roundavg((double)avail / w_p_eff); + if (delta <= 0) + return 1; + if (delta > etus * land_grow_scale) + delta = etus * land_grow_scale; + + /* delta is the max amount we can grow */ + + left = 100 - land->lnd_effic; + if (left > delta) + left = delta; + + leftp = ((float)left / 100.0); + + bzero((s_char *)mvec, sizeof(mvec)); + mvec[I_LCM] = lcm_needed = ldround((double)(lp->l_lcm * leftp), 1); + mvec[I_HCM] = hcm_needed = ldround((double)(lp->l_hcm * leftp), 1); /* mvec[I_GUN] = gun_needed = ldround((double)(lp->l_gun * leftp),1); mvec[I_MILIT] = mil_needed = ldround((double)(lp->l_mil * leftp),1); mvec[I_SHELL] = shell_needed = ldround((double)(lp->l_shell *leftp),1); */ - mvec[I_GUN] = gun_needed = 0; - mvec[I_MILIT] = mil_needed = 0; - mvec[I_SHELL] = shell_needed = 0; - - get_materials(sp, bp, mvec, 0); - - if (mvec[I_MILIT]>=mil_needed) - buildp=leftp; - else - buildp=((float)mvec[I_MILIT]/(float)lp->l_mil); - if (mvec[I_LCM] < lcm_needed) - buildp = MIN(buildp,((float)mvec[I_LCM]/(float)lp->l_lcm)); - if (mvec[I_HCM] < hcm_needed) - buildp = MIN(buildp,((float)mvec[I_HCM]/(float)lp->l_hcm)); - if (mvec[I_GUN] < gun_needed) - buildp = MIN(buildp,((float)mvec[I_GUN]/(float)lp->l_gun)); - if (mvec[I_SHELL] < shell_needed) - buildp = MIN(buildp,((float)mvec[I_SHELL]/(float)lp->l_shell)); - - build=ldround((double)(buildp*100.0),1); - - bzero((s_char *)mvec, sizeof(mvec)); - mvec[I_LCM] = lcm_needed = roundavg((double)(lp->l_lcm * buildp)); - mvec[I_HCM] = hcm_needed = roundavg((double)(lp->l_hcm * buildp)); + mvec[I_GUN] = gun_needed = 0; + mvec[I_MILIT] = mil_needed = 0; + mvec[I_SHELL] = shell_needed = 0; + + get_materials(sp, bp, mvec, 0); + + if (mvec[I_MILIT] >= mil_needed) + buildp = leftp; + else + buildp = ((float)mvec[I_MILIT] / (float)lp->l_mil); + if (mvec[I_LCM] < lcm_needed) + buildp = MIN(buildp, ((float)mvec[I_LCM] / (float)lp->l_lcm)); + if (mvec[I_HCM] < hcm_needed) + buildp = MIN(buildp, ((float)mvec[I_HCM] / (float)lp->l_hcm)); + if (mvec[I_GUN] < gun_needed) + buildp = MIN(buildp, ((float)mvec[I_GUN] / (float)lp->l_gun)); + if (mvec[I_SHELL] < shell_needed) + buildp = MIN(buildp, ((float)mvec[I_SHELL] / (float)lp->l_shell)); + + build = ldround((double)(buildp * 100.0), 1); + + bzero((s_char *)mvec, sizeof(mvec)); + mvec[I_LCM] = lcm_needed = roundavg((double)(lp->l_lcm * buildp)); + mvec[I_HCM] = hcm_needed = roundavg((double)(lp->l_hcm * buildp)); /* mvec[I_GUN] = gun_needed = roundavg((double)(lp->l_gun * buildp)); mvec[I_MILIT] = mil_needed = roundavg((double)(lp->l_mil * buildp)); mvec[I_SHELL] = shell_needed = roundavg((double)(lp->l_shell *buildp)); */ - mvec[I_GUN] = gun_needed = 0; - mvec[I_MILIT] = mil_needed = 0; - mvec[I_SHELL] = shell_needed = 0; - mil_dbl_pay += mil_needed; - - get_materials(sp, bp, mvec, 1); - - if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR)) - build /= 3; - - avail -= build * w_p_eff; - if (!player->simulation) { - sp->sct_avail = avail/100; - if (sp->sct_avail < 0) - sp->sct_avail = 0; - } else { - pt_bg_nmbr(bp, sp, I_MAX+1, avail/100); - if (gt_bg_nmbr(bp, sp, I_MAX+1) < 0) - pt_bg_nmbr(bp, sp, I_MAX+1, 0); - } - -if (build<0) - logerror("land unit %d building %d ! \n",land->lnd_uid,build); - np->nat_money -= mult * lp->l_cost * build / 100.0; - if (!player->simulation) { - land->lnd_effic += (s_char)build; - - putsect(sp); - } - return 1; + mvec[I_GUN] = gun_needed = 0; + mvec[I_MILIT] = mil_needed = 0; + mvec[I_SHELL] = shell_needed = 0; + mil_dbl_pay += mil_needed; + + get_materials(sp, bp, mvec, 1); + + if ((sp->sct_type != SCT_HEADQ) && (sp->sct_type != SCT_FORTR)) + build /= 3; + + avail -= build * w_p_eff; + if (!player->simulation) { + sp->sct_avail = avail / 100; + if (sp->sct_avail < 0) + sp->sct_avail = 0; + } else { + pt_bg_nmbr(bp, sp, I_MAX + 1, avail / 100); + if (gt_bg_nmbr(bp, sp, I_MAX + 1) < 0) + pt_bg_nmbr(bp, sp, I_MAX + 1, 0); + } + + if (build < 0) + logerror("land unit %d building %d ! \n", land->lnd_uid, build); + np->nat_money -= mult * lp->l_cost * build / 100.0; + if (!player->simulation) { + land->lnd_effic += (s_char)build; + + putsect(sp); + } + return 1; } /* * returns the number who starved, if any. */ int -feed_land(struct lndstr *lp, register int *vec, int etus, int *needed, int doit) +feed_land(struct lndstr *lp, register int *vec, int etus, int *needed, + int doit) { - extern double eatrate; - double food_eaten, ship_eaten; - double people_left; - int can_eat, need, svec[I_MAX+1]; - int total_people; - int starved; - struct lchrstr *lcp; - struct shpstr *sp; - - if (opt_NOFOOD) return 0; /* no food no work to be done */ - - lcp = &lchr[(int)lp->lnd_type]; - - food_eaten = (etus * eatrate) * total_mil(lp); - starved = 0; - *needed = 0; - /* - * If we're on a ship, and we don't have enough food, - * get some food off the carrying ship. (Don't starve - * the ship, tho... - */ + extern double eatrate; + double food_eaten, ship_eaten; + double people_left; + int can_eat, need, svec[I_MAX + 1]; + int total_people; + int starved; + struct lchrstr *lcp; + struct shpstr *sp; + + if (opt_NOFOOD) + return 0; /* no food no work to be done */ + + lcp = &lchr[(int)lp->lnd_type]; + + food_eaten = (etus * eatrate) * total_mil(lp); + starved = 0; + *needed = 0; + /* + * If we're on a ship, and we don't have enough food, + * get some food off the carrying ship. (Don't starve + * the ship, tho... + */ /* doit - Only try to take food off the ship during the update */ - if ((food_eaten > vec[I_FOOD]) && (lp->lnd_ship >= 0) && doit){ - need = (int)food_eaten - vec[I_FOOD]; - sp = getshipp(lp->lnd_ship); - getvec(VT_ITEM, svec, (s_char *)sp, EF_SHIP); - ship_eaten = (etus * eatrate) * - (svec[I_CIVIL]+svec[I_MILIT]+svec[I_UW]); - if ((svec[I_FOOD]-need) > ship_eaten){ - vec[I_FOOD] += need; - svec[I_FOOD] -= need; - } - else if ((svec[I_FOOD]-ship_eaten) > 0){ - vec[I_FOOD] += (svec[I_FOOD] - ship_eaten); - svec[I_FOOD] -= (svec[I_FOOD] - ship_eaten); - } - putvec(VT_ITEM, svec, (s_char *)sp, EF_SHIP); + if ((food_eaten > vec[I_FOOD]) && (lp->lnd_ship >= 0) && doit) { + need = (int)food_eaten - vec[I_FOOD]; + sp = getshipp(lp->lnd_ship); + getvec(VT_ITEM, svec, (s_char *)sp, EF_SHIP); + ship_eaten = (etus * eatrate) * + (svec[I_CIVIL] + svec[I_MILIT] + svec[I_UW]); + if ((svec[I_FOOD] - need) > ship_eaten) { + vec[I_FOOD] += need; + svec[I_FOOD] -= need; + } else if ((svec[I_FOOD] - ship_eaten) > 0) { + vec[I_FOOD] += (svec[I_FOOD] - ship_eaten); + svec[I_FOOD] -= (svec[I_FOOD] - ship_eaten); } - - if (food_eaten > vec[I_FOOD]) { - *needed = food_eaten - vec[I_FOOD]; - if (*needed < (food_eaten - vec[I_FOOD])) - (*needed)++; - can_eat = (vec[I_FOOD] / (etus * eatrate)); - total_people = total_mil(lp); - /* only want to starve off at most 1/2 the populace. */ - if (can_eat < (total_people/2)) - can_eat = total_people/2; - - people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01); - /* only want to starve off at most 1/2 the populace. */ - if (people_left < 0.5) - people_left = 0.5; + putvec(VT_ITEM, svec, (s_char *)sp, EF_SHIP); + } + + if (food_eaten > vec[I_FOOD]) { + *needed = food_eaten - vec[I_FOOD]; + if (*needed < (food_eaten - vec[I_FOOD])) + (*needed)++; + can_eat = (vec[I_FOOD] / (etus * eatrate)); + total_people = total_mil(lp); + /* only want to starve off at most 1/2 the populace. */ + if (can_eat < (total_people / 2)) + can_eat = total_people / 2; + + people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01); + /* only want to starve off at most 1/2 the populace. */ + if (people_left < 0.5) + people_left = 0.5; /* lp->lnd_effic *= people_left;*/ - starved = vec[I_MILIT] - (vec[I_MILIT] * people_left); + starved = vec[I_MILIT] - (vec[I_MILIT] * people_left); /* if (!player->simulation) wu(0, lp->lnd_own, "%d mil starved on unit %s.\n", starved, prland(lp));*/ - vec[I_MILIT] -= starved; - vec[I_FOOD] = 0; - } else { - vec[I_FOOD] -= (int)food_eaten; - } - return starved; + vec[I_MILIT] -= starved; + vec[I_FOOD] = 0; + } else { + vec[I_FOOD] -= (int)food_eaten; + } + return starved; } - diff --git a/src/lib/update/main.c b/src/lib/update/main.c index 7f90e93d2..1082aaa6c 100644 --- a/src/lib/update/main.c +++ b/src/lib/update/main.c @@ -51,202 +51,198 @@ #include #endif -long money[MAXNOC]; -long pops[MAXNOC]; -long sea_money[MAXNOC]; -long lnd_money[MAXNOC]; -long air_money[MAXNOC]; -long tpops[MAXNOC]; +long money[MAXNOC]; +long pops[MAXNOC]; +long sea_money[MAXNOC]; +long lnd_money[MAXNOC]; +long air_money[MAXNOC]; +long tpops[MAXNOC]; -extern int mil_dbl_pay; -int update_pending = 0; +extern int mil_dbl_pay; +int update_pending = 0; /*ARGSUSED*/ void update_main(void *argv) { - extern int etu_per_update; - extern double money_res; - int etu = etu_per_update; - int n; - int x; - int *bp; - int cn,cn2,rel; - struct natstr *cnp; - struct natstr *np; + extern int etu_per_update; + extern double money_res; + int etu = etu_per_update; + int n; + int x; + int *bp; + int cn, cn2, rel; + struct natstr *cnp; + struct natstr *np; - /* First, make sure all mobility is updated correctly. */ - if (opt_MOB_ACCESS) { - mob_ship(etu); - mob_sect(etu); - mob_plane(etu); - mob_land(etu); - } - update_pending = 1; - player->proc = empth_self(); - player->cnum = 0; - player->god = 1; - /* - * set up all the variables which get used in the - * sector production routine (for producing education, - * happiness, and printing out the state of the nation) - */ - logerror("production update (%d etus)", etu); - bzero((s_char *)pops, sizeof(pops)); - bzero((s_char *)air_money, sizeof(air_money)); - bzero((s_char *)sea_money, sizeof(sea_money)); - bzero((s_char *)lnd_money, sizeof(lnd_money)); - bp = (int *) calloc(WORLD_X * WORLD_Y * 7, sizeof(int)); - for (n=0; nnat_money; - tpops[n] = count_pop(n); - } + /* First, make sure all mobility is updated correctly. */ + if (opt_MOB_ACCESS) { + mob_ship(etu); + mob_sect(etu); + mob_plane(etu); + mob_land(etu); + } + update_pending = 1; + player->proc = empth_self(); + player->cnum = 0; + player->god = 1; + /* + * set up all the variables which get used in the + * sector production routine (for producing education, + * happiness, and printing out the state of the nation) + */ + logerror("production update (%d etus)", etu); + bzero((s_char *)pops, sizeof(pops)); + bzero((s_char *)air_money, sizeof(air_money)); + bzero((s_char *)sea_money, sizeof(sea_money)); + bzero((s_char *)lnd_money, sizeof(lnd_money)); + bp = (int *)calloc(WORLD_X * WORLD_Y * 7, sizeof(int)); + for (n = 0; n < MAXNOC; n++) { + money[n] = 0; + if ((np = getnatp(n)) == (struct natstr *)0) + continue; + money[n] = np->nat_money; + tpops[n] = count_pop(n); + } - logerror("preparing sectors..."); - prepare_sects(etu, bp); - logerror("done preparing sectors."); - logerror("producing for countries..."); - for (x=0; xnat_stat & STAT_SANCT ) { + bzero((s_char *)p_sect, sizeof(p_sect)); + mil_dbl_pay = 0; + if ((np = getnatp(x)) == (struct natstr *)0) + continue; + if (np->nat_stat & STAT_SANCT) { #ifdef DEBUG - logerror("Country %i is in sanctuary and did not update",x); + logerror("Country %i is in sanctuary and did not update", x); #endif - continue; - } - np->nat_money += (int) (np->nat_reserve * money_res * etu); + continue; + } + np->nat_money += (int)(np->nat_reserve * money_res * etu); - for(y=1; ynat_priorities[z] == y) { - do_prod(z, etu, x, bp, p_sect, - &sb, &sm, &pb, &pm, &lb, &lm); - } - } + for (y = 1; y < SCT_MAXDEF + 8; y++) { + for (z = 0; z < SCT_MAXDEF + 8; z++) { + if (np->nat_priorities[z] == y) { + do_prod(z, etu, x, bp, p_sect, + &sb, &sm, &pb, &pm, &lb, &lm); } - /* 0 is maintain, 1 is build */ - if (!sm) prod_ship(etu, x, bp, 0); - if (!sb) prod_ship(etu, x, bp, 1); - if (!pm) prod_plane(etu, x, bp, 0); - if (!pb) prod_plane(etu, x, bp, 1); - if (!lm) prod_land(etu, x, bp, 0); - if (!lb) prod_land(etu, x, bp, 1); - - /* produce all sects that haven't produced yet */ - produce_sect(x, etu, bp, p_sect, -1); - np->nat_money -= p_sect[SCT_CAPIT][1]; + } } - logerror("done producing for countries."); + /* 0 is maintain, 1 is build */ + if (!sm) + prod_ship(etu, x, bp, 0); + if (!sb) + prod_ship(etu, x, bp, 1); + if (!pm) + prod_plane(etu, x, bp, 0); + if (!pb) + prod_plane(etu, x, bp, 1); + if (!lm) + prod_land(etu, x, bp, 0); + if (!lb) + prod_land(etu, x, bp, 1); - finish_sects(etu); - prod_nat(etu); - age_levels(etu); - free(bp); - /*flushwu();*/ - if (opt_SLOW_WAR) { - /* Update war declarations */ - /* MOBILIZATION->SITZKRIEG->AT_WAR */ - for (cn=1; cn < MAXNOC; cn++) { - if ((cnp = getnatp(cn)) == 0) - break; - for (cn2=1; cn2 < MAXNOC; cn2++) { - if (cn2 == cn) - continue; - rel=getrel(cnp,cn2); - if (rel == MOBILIZATION){ - rel = SITZKRIEG; - setrel(cn,cn2,rel); - } - else if (rel == SITZKRIEG){ - rel = AT_WAR; - setrel(cn,cn2,rel); - } + /* produce all sects that haven't produced yet */ + produce_sect(x, etu, bp, p_sect, -1); + np->nat_money -= p_sect[SCT_CAPIT][1]; + } + logerror("done producing for countries."); + + finish_sects(etu); + prod_nat(etu); + age_levels(etu); + free(bp); + /*flushwu(); */ + if (opt_SLOW_WAR) { + /* Update war declarations */ + /* MOBILIZATION->SITZKRIEG->AT_WAR */ + for (cn = 1; cn < MAXNOC; cn++) { + if ((cnp = getnatp(cn)) == 0) + break; + for (cn2 = 1; cn2 < MAXNOC; cn2++) { + if (cn2 == cn) + continue; + rel = getrel(cnp, cn2); + if (rel == MOBILIZATION) { + rel = SITZKRIEG; + setrel(cn, cn2, rel); + } else if (rel == SITZKRIEG) { + rel = AT_WAR; + setrel(cn, cn2, rel); } - } + } } - /* Age contact */ - if (opt_LOSE_CONTACT) { - for (cn=1; cnnat_money -= (int) (money_mil * etu * mil_dbl_pay); - prod_land(etu,n,bp,0); - *land_maint=1; - } - else - if (sector_type == PRI_LBUILD){ - prod_land(etu,n,bp,1); - *land_build=1; - } - else { - produce_sect(n,etu,bp,p_sect,sector_type); - } + if (sector_type == PRI_SMAINT) { + prod_ship(etu, n, bp, 0); + *ship_maint = 1; + } else if (sector_type == PRI_SBUILD) { + prod_ship(etu, n, bp, 1); + *ship_build = 1; + } else if (sector_type == PRI_PMAINT) { + prod_plane(etu, n, bp, 0); + *plane_maint = 1; + } else if (sector_type == PRI_PBUILD) { + prod_plane(etu, n, bp, 1); + *plane_build = 1; + } else if (sector_type == PRI_LMAINT) { + if (*land_build) + np->nat_money -= (int)(money_mil * etu * mil_dbl_pay); + prod_land(etu, n, bp, 0); + *land_maint = 1; + } else if (sector_type == PRI_LBUILD) { + prod_land(etu, n, bp, 1); + *land_build = 1; + } else { + produce_sect(n, etu, bp, p_sect, sector_type); + } } - diff --git a/src/lib/update/material.c b/src/lib/update/material.c index 15067e924..593e60aa4 100644 --- a/src/lib/update/material.c +++ b/src/lib/update/material.c @@ -45,49 +45,51 @@ #ifndef MIN #define MIN(x,y) ((x) > (y) ? (y) : (x)) #endif - + void get_materials(struct sctstr *sp, int *bp, int *mvec, int check) - /* only check if found=0, remove them=1 */ + /* only check if found=0, remove them=1 */ { - struct sctstr *usp; - int i; - int used_already; - int still_left; - int svec[I_MAX+1]; + struct sctstr *usp; + int i; + int used_already; + int still_left; + int svec[I_MAX + 1]; - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - for(i=1;i<=I_MAX;i++) { - if (mvec[i]==0) - continue; + getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); + for (i = 1; i <= I_MAX; i++) { + if (mvec[i] == 0) + continue; - usp = sp; - if (check) { - still_left = gt_bg_nmbr(bp, sp, i); - if ((still_left - mvec[i])<0) - still_left = 0; - else - still_left -= mvec[i]; + usp = sp; + if (check) { + still_left = gt_bg_nmbr(bp, sp, i); + if ((still_left - mvec[i]) < 0) + still_left = 0; + else + still_left -= mvec[i]; - if (opt_GRAB_THINGS) - mvec[i] = supply_commod(usp->sct_own, usp->sct_x, usp->sct_y, - i, mvec[i]); - pt_bg_nmbr(bp, sp, i, still_left); - svec[i] = still_left; - if (!player->simulation) - putvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); + if (opt_GRAB_THINGS) + mvec[i] = + supply_commod(usp->sct_own, usp->sct_x, usp->sct_y, i, + mvec[i]); + pt_bg_nmbr(bp, sp, i, still_left); + svec[i] = still_left; + if (!player->simulation) + putvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - } else { + } else { - if (opt_GRAB_THINGS) { - used_already = svec[i] - gt_bg_nmbr(bp, sp, i); - mvec[i] = try_supply_commod(usp->sct_own, usp->sct_x, usp->sct_y, - i, (mvec[i] + used_already)); - mvec[i] -= used_already; - } else { /* ! GRAB_THINGS */ - still_left = gt_bg_nmbr(bp, sp, i); - mvec[i] = MIN(mvec[i], still_left); - } + if (opt_GRAB_THINGS) { + used_already = svec[i] - gt_bg_nmbr(bp, sp, i); + mvec[i] = + try_supply_commod(usp->sct_own, usp->sct_x, usp->sct_y, + i, (mvec[i] + used_already)); + mvec[i] -= used_already; + } else { /* ! GRAB_THINGS */ + still_left = gt_bg_nmbr(bp, sp, i); + mvec[i] = MIN(mvec[i], still_left); + } + } } - } } diff --git a/src/lib/update/mobility.c b/src/lib/update/mobility.c index 369832523..0785d257a 100644 --- a/src/lib/update/mobility.c +++ b/src/lib/update/mobility.c @@ -53,7 +53,7 @@ int do_upd_checking = 0; int -increase_mob(time_t *counter, float mult) +increase_mob(time_t * counter, float mult) { time_t secs; time_t now; @@ -62,91 +62,91 @@ increase_mob(time_t *counter, float mult) extern int updating_mob; int newetus; float newmob; - int inewmob; + int inewmob; time(&now); secs = now - *counter; if (secs < 1 || secs < s_p_etu) - return 0; - newetus = (int)(secs / s_p_etu); + return 0; + newetus = (int)(secs / s_p_etu); if (newetus < 1) return 0; left = (secs % s_p_etu); do { - newmob = (float)(newetus * mult); - inewmob = (int)(newetus * mult); - if (newmob == inewmob || newetus > 7) - break; - newetus--; - left += s_p_etu; + newmob = (float)(newetus * mult); + inewmob = (int)(newetus * mult); + if (newmob == inewmob || newetus > 7) + break; + newetus--; + left += s_p_etu; } while (newetus > 0); if (newetus <= 0) - return 0; + return 0; time(counter); *counter = *counter - left; if (updating_mob) - return (newetus); + return (newetus); return 0; } void update_timestamps(time_t lastsavedtime) { - struct shpstr *shipp; - struct sctstr *sectp; - struct lndstr *landp; - struct plnstr *planep; - int n; - time_t now; - time_t delta; - - timestamp_fixing = 1; - time(&now); - delta = now - lastsavedtime; - for (n = 0; (shipp = getshipp(n)); n++) - shipp->shp_access += delta; - for (n = 0; (sectp = getsectid(n)); n++) - sectp->sct_access += delta; - for (n = 0; (landp = getlandp(n)); n++) - landp->lnd_access += delta; - for (n = 0; (planep = getplanep(n)); n++) - planep->pln_access += delta; - timestamp_fixing = 0; + struct shpstr *shipp; + struct sctstr *sectp; + struct lndstr *landp; + struct plnstr *planep; + int n; + time_t now; + time_t delta; + + timestamp_fixing = 1; + time(&now); + delta = now - lastsavedtime; + for (n = 0; (shipp = getshipp(n)); n++) + shipp->shp_access += delta; + for (n = 0; (sectp = getsectid(n)); n++) + sectp->sct_access += delta; + for (n = 0; (landp = getlandp(n)); n++) + landp->lnd_access += delta; + for (n = 0; (planep = getplanep(n)); n++) + planep->pln_access += delta; + timestamp_fixing = 0; } void update_all_mob(void) { - struct shpstr *shipp; - struct sctstr *sectp; - struct lndstr *landp; - struct plnstr *planep; - int n; - - n = 0; - while (1) { - do_upd_checking = 1; - shipp = getshipp(n); - sectp = getsectid(n); - landp = getlandp(n); - planep = getplanep(n); + struct shpstr *shipp; + struct sctstr *sectp; + struct lndstr *landp; + struct plnstr *planep; + int n; + + n = 0; + while (1) { + do_upd_checking = 1; + shipp = getshipp(n); + sectp = getsectid(n); + landp = getlandp(n); + planep = getplanep(n); + do_upd_checking = 0; + if (shipp) + shp_do_upd_mob(shipp); + if (sectp) + sct_do_upd_mob(sectp); + if (landp) + lnd_do_upd_mob(landp); + if (planep) + pln_do_upd_mob(planep); + if (!shipp && !sectp && !landp && !planep) + break; + n++; + } do_upd_checking = 0; - if (shipp) - shp_do_upd_mob(shipp); - if (sectp) - sct_do_upd_mob(sectp); - if (landp) - lnd_do_upd_mob(landp); - if (planep) - pln_do_upd_mob(planep); - if (!shipp && !sectp && !landp && !planep) - break; - n++; - } - do_upd_checking = 0; } void @@ -156,11 +156,11 @@ sct_do_upd_mob(register struct sctstr *sp) int etus; if (do_upd_checking || timestamp_fixing || update_pending) - return; + return; if (sp->sct_own == 0) - return; + return; if (sp->sct_type == SCT_SANCT) - return; + return; if ((etus = increase_mob(&sp->sct_access, sect_mob_scale)) == 0) return; do_upd_checking = 1; @@ -176,11 +176,11 @@ shp_do_upd_mob(register struct shpstr *sp) int etus; if (do_upd_checking || timestamp_fixing || update_pending) - return; + return; if (sp->shp_own == 0) - return; + return; if ((etus = increase_mob(&sp->shp_access, ship_mob_scale)) == 0) - return; + return; do_upd_checking = 1; do_mob_ship(sp, etus); do_upd_checking = 0; @@ -193,11 +193,11 @@ lnd_do_upd_mob(register struct lndstr *lp) int etus; if (do_upd_checking || timestamp_fixing || update_pending) - return; + return; if (lp->lnd_own == 0) - return; + return; if ((etus = increase_mob(&lp->lnd_access, land_mob_scale)) == 0) - return; + return; do_upd_checking = 1; do_mob_land(lp, etus); @@ -211,11 +211,11 @@ pln_do_upd_mob(register struct plnstr *pp) int etus; if (do_upd_checking || timestamp_fixing || update_pending) - return; + return; if (pp->pln_own == 0) - return; + return; if ((etus = increase_mob(&pp->pln_access, plane_mob_scale)) == 0) - return; + return; do_upd_checking = 1; do_mob_plane(pp, etus); @@ -225,191 +225,191 @@ pln_do_upd_mob(register struct plnstr *pp) void mob_sect(register int etus) { - register struct sctstr *sp; - register int n; - time_t now; - - time(&now); - for (n=0; NULL != (sp = getsectid(n)); n++) { - sp->sct_timestamp = now; - if (opt_MOB_ACCESS) - sct_do_upd_mob(sp); - else - do_mob_sect(sp, etus); - } + register struct sctstr *sp; + register int n; + time_t now; + + time(&now); + for (n = 0; NULL != (sp = getsectid(n)); n++) { + sp->sct_timestamp = now; + if (opt_MOB_ACCESS) + sct_do_upd_mob(sp); + else + do_mob_sect(sp, etus); + } } void do_mob_sect(register struct sctstr *sp, register int etus) { - extern float sect_mob_scale; - extern int sect_mob_max; - register int value; + extern float sect_mob_scale; + extern int sect_mob_max; + register int value; if (sp->sct_own == 0) - return; + return; if (sp->sct_type == SCT_SANCT) - return; - /* Do we have to even bother? */ - if (sp->sct_mobil >= sect_mob_max) { - /* No, so set just in case and then return */ - sp->sct_mobil = sect_mob_max; - return; - } - value = sp->sct_mobil + ((float)etus * sect_mob_scale); - if (value > sect_mob_max) - value = sect_mob_max; - sp->sct_mobil = value; + return; + /* Do we have to even bother? */ + if (sp->sct_mobil >= sect_mob_max) { + /* No, so set just in case and then return */ + sp->sct_mobil = sect_mob_max; + return; + } + value = sp->sct_mobil + ((float)etus * sect_mob_scale); + if (value > sect_mob_max) + value = sect_mob_max; + sp->sct_mobil = value; } void mob_ship(register int etus) { - register struct shpstr *sp; - register int n; - time_t now; - - time(&now); - for (n=0; NULL != (sp = getshipp(n)); n++) { - sp->shp_timestamp = now; - if (opt_MOB_ACCESS) - shp_do_upd_mob(sp); - else - do_mob_ship(sp, etus); - } + register struct shpstr *sp; + register int n; + time_t now; + + time(&now); + for (n = 0; NULL != (sp = getshipp(n)); n++) { + sp->shp_timestamp = now; + if (opt_MOB_ACCESS) + shp_do_upd_mob(sp); + else + do_mob_ship(sp, etus); + } } void do_mob_ship(register struct shpstr *sp, register int etus) { - extern int ship_mob_max; - extern float ship_mob_scale; - int newfuel=0; + extern int ship_mob_max; + extern float ship_mob_scale; + int newfuel = 0; register int value; - int can_add,have_fuel_for,total_add; - double d; - extern int fuel_mult; + int can_add, have_fuel_for, total_add; + double d; + extern int fuel_mult; if (sp->shp_own == 0) - return; - - /* Do we even have to bother updating this mobility? */ - if (sp->shp_mobil >= ship_mob_max) { - /* No, so don't. Just set it to max (just in case) and - return. */ - sp->shp_mobil = ship_mob_max; - return; - } + return; + + /* Do we even have to bother updating this mobility? */ + if (sp->shp_mobil >= ship_mob_max) { + /* No, so don't. Just set it to max (just in case) and + return. */ + sp->shp_mobil = ship_mob_max; + return; + } - if (opt_FUEL == 0) { /* only a bit to do ... */ - value = sp->shp_mobil + ((float)etus * ship_mob_scale); - if (value > ship_mob_max) - value = ship_mob_max; - sp->shp_mobil = value; - return; /* so we ship the FUEL stuff */ + if (opt_FUEL == 0) { /* only a bit to do ... */ + value = sp->shp_mobil + ((float)etus * ship_mob_scale); + if (value > ship_mob_max) + value = ship_mob_max; + sp->shp_mobil = value; + return; /* so we ship the FUEL stuff */ } /* opt_FUEL in force */ if (mchr[(int)sp->shp_type].m_fuelu == 0) { - value = sp->shp_mobil + ((float)etus * ship_mob_scale); - if (value > ship_mob_max) - value = ship_mob_max; - sp->shp_mobil = (s_char)value; + value = sp->shp_mobil + ((float)etus * ship_mob_scale); + if (value > ship_mob_max) + value = ship_mob_max; + sp->shp_mobil = (s_char)value; } else { - can_add = ship_mob_max - sp->shp_mobil; - if (can_add > ((float)etus*ship_mob_scale)) - can_add = ((float)etus*ship_mob_scale); - have_fuel_for = ldround((((double)sp->shp_fuel / - (double)mchr[(int)sp->shp_type].m_fuelu)* - (double)fuel_mult),1); - - if (can_add > have_fuel_for){ - int need; - need = can_add - have_fuel_for; - d = (double)need; - d *= (double)mchr[(int)sp->shp_type].m_fuelu; - d /= (double)fuel_mult; - d /= 5.0; - if ((d-(int)d) > 0.0) - d++; - need = (int)d; - newfuel = supply_commod(sp->shp_own,sp->shp_x, - sp->shp_y,I_PETROL,need); - sp->shp_fuel += (u_char)(newfuel * 5); - } - - have_fuel_for = ldround((((double)sp->shp_fuel / - (double)mchr[(int)sp->shp_type].m_fuelu)* - (double)fuel_mult),1); - - if (can_add > have_fuel_for){ - int need; - need = can_add - have_fuel_for; - d = (double)need; - d *= (double)mchr[(int)sp->shp_type].m_fuelu; - d /= (double)fuel_mult; - d /= 50.0; - if ((d-(int)d) > 0.0) - d++; - need = (int)d; - newfuel = supply_commod(sp->shp_own,sp->shp_x, - sp->shp_y,I_OIL,need); - sp->shp_fuel += (u_char)(newfuel * 50); - } - - have_fuel_for = ldround((((double)sp->shp_fuel / - (double)mchr[(int)sp->shp_type].m_fuelu)* - (double)fuel_mult),1); - - if (can_add > have_fuel_for) - total_add = have_fuel_for; - else - total_add = can_add; - d = (double)total_add; - d *= (double)mchr[(int)sp->shp_type].m_fuelu; - d /= (double)fuel_mult; - sp->shp_fuel -= (u_char)ldround(d,1); - sp->shp_fuel = (u_char)min(sp->shp_fuel, - mchr[(int)sp->shp_type].m_fuelc); - sp->shp_mobil += (s_char)total_add; + can_add = ship_mob_max - sp->shp_mobil; + if (can_add > ((float)etus * ship_mob_scale)) + can_add = ((float)etus * ship_mob_scale); + have_fuel_for = ldround((((double)sp->shp_fuel / + (double)mchr[(int)sp->shp_type]. + m_fuelu) * (double)fuel_mult), 1); + + if (can_add > have_fuel_for) { + int need; + need = can_add - have_fuel_for; + d = (double)need; + d *= (double)mchr[(int)sp->shp_type].m_fuelu; + d /= (double)fuel_mult; + d /= 5.0; + if ((d - (int)d) > 0.0) + d++; + need = (int)d; + newfuel = supply_commod(sp->shp_own, sp->shp_x, + sp->shp_y, I_PETROL, need); + sp->shp_fuel += (u_char)(newfuel * 5); + } + + have_fuel_for = ldround((((double)sp->shp_fuel / + (double)mchr[(int)sp->shp_type]. + m_fuelu) * (double)fuel_mult), 1); + + if (can_add > have_fuel_for) { + int need; + need = can_add - have_fuel_for; + d = (double)need; + d *= (double)mchr[(int)sp->shp_type].m_fuelu; + d /= (double)fuel_mult; + d /= 50.0; + if ((d - (int)d) > 0.0) + d++; + need = (int)d; + newfuel = supply_commod(sp->shp_own, sp->shp_x, + sp->shp_y, I_OIL, need); + sp->shp_fuel += (u_char)(newfuel * 50); + } + + have_fuel_for = ldround((((double)sp->shp_fuel / + (double)mchr[(int)sp->shp_type]. + m_fuelu) * (double)fuel_mult), 1); + + if (can_add > have_fuel_for) + total_add = have_fuel_for; + else + total_add = can_add; + d = (double)total_add; + d *= (double)mchr[(int)sp->shp_type].m_fuelu; + d /= (double)fuel_mult; + sp->shp_fuel -= (u_char)ldround(d, 1); + sp->shp_fuel = (u_char)min(sp->shp_fuel, + mchr[(int)sp->shp_type].m_fuelc); + sp->shp_mobil += (s_char)total_add; } } void mob_land(register int etus) { - register struct lndstr *lp; - register int n; - time_t now; - - time(&now); - for (n=0; NULL != (lp = getlandp(n)); n++) { - lp->lnd_timestamp = now; - if (opt_MOB_ACCESS) - lnd_do_upd_mob(lp); - else - do_mob_land(lp, etus); - } + register struct lndstr *lp; + register int n; + time_t now; + + time(&now); + for (n = 0; NULL != (lp = getlandp(n)); n++) { + lp->lnd_timestamp = now; + if (opt_MOB_ACCESS) + lnd_do_upd_mob(lp); + else + do_mob_land(lp, etus); + } } void do_mob_land(register struct lndstr *lp, register int etus) { - extern int land_mob_max; - extern float land_mob_scale; - int newfuel=0; + extern int land_mob_max; + extern float land_mob_scale; + int newfuel = 0; register int value; - int can_add,have_fuel_for,total_add; - double d; - extern int fuel_mult; - + int can_add, have_fuel_for, total_add; + double d; + extern int fuel_mult; + if (lp->lnd_own == 0) - return; - - if (lp->lnd_mobil >= land_mob_max) { - lp->lnd_mobil = land_mob_max; - return; - } + return; + + if (lp->lnd_mobil >= land_mob_max) { + lp->lnd_mobil = land_mob_max; + return; + } /* * Give damaged units a break. When at low @@ -420,144 +420,141 @@ do_mob_land(register struct lndstr *lp, register int etus) * be too much of an advantage. So, we just add double * the small amount of mob if we are < 0 instead. */ - + if (!opt_MOB_ACCESS) { - if (lp->lnd_mobil < 0) - lp->lnd_mobil /= 2; - } - - if (opt_FUEL == 0) { /* just some bits and pieces */ - if (opt_MOB_ACCESS) { if (lp->lnd_mobil < 0) - value = lp->lnd_mobil + (2 * ((float)etus * land_mob_scale)); - else + lp->lnd_mobil /= 2; + } + + if (opt_FUEL == 0) { /* just some bits and pieces */ + if (opt_MOB_ACCESS) { + if (lp->lnd_mobil < 0) + value = + lp->lnd_mobil + (2 * ((float)etus * land_mob_scale)); + else + value = lp->lnd_mobil + ((float)etus * land_mob_scale); + } else { value = lp->lnd_mobil + ((float)etus * land_mob_scale); - } else { - value = lp->lnd_mobil + ((float)etus * land_mob_scale); - } - if (value > land_mob_max) - value = land_mob_max; - lp->lnd_mobil = value; - - return; /* Done! */ + } + if (value > land_mob_max) + value = land_mob_max; + lp->lnd_mobil = value; + + return; /* Done! */ } - + /* opt_FUEL in force ... */ - if (lp->lnd_fuelu == 0){ - if (opt_MOB_ACCESS) { - if (lp->lnd_mobil < 0) - value = lp->lnd_mobil + (2 * ((float)etus * land_mob_scale)); - else + if (lp->lnd_fuelu == 0) { + if (opt_MOB_ACCESS) { + if (lp->lnd_mobil < 0) + value = + lp->lnd_mobil + (2 * ((float)etus * land_mob_scale)); + else + value = lp->lnd_mobil + ((float)etus * land_mob_scale); + } else { value = lp->lnd_mobil + ((float)etus * land_mob_scale); - } else { - value = lp->lnd_mobil + ((float)etus * land_mob_scale); - } - if (value > land_mob_max) - value = land_mob_max; - lp->lnd_mobil = value; + } + if (value > land_mob_max) + value = land_mob_max; + lp->lnd_mobil = value; } else { - - can_add = land_mob_max - lp->lnd_mobil; - - if (can_add > ((float)etus*land_mob_scale)) - can_add = ((float)etus*land_mob_scale); - - have_fuel_for = (lp->lnd_fuel / - lp->lnd_fuelu)*fuel_mult; - - if (can_add > have_fuel_for){ - int need; - need = can_add - have_fuel_for; - d = (double)need; - d *= (double)lp->lnd_fuelu; - d /= (double)fuel_mult; - d /= 5.0; - if ((d-(int)d) > 0.0) - d++; - need = (int)d; - newfuel = supply_commod(lp->lnd_own,lp->lnd_x, - lp->lnd_y,I_PETROL,need); - lp->lnd_fuel += (u_char)(newfuel * 5); - } - - have_fuel_for = (lp->lnd_fuel / - lp->lnd_fuelu)*fuel_mult; - - if (can_add > have_fuel_for){ - int need; - need = can_add - have_fuel_for; - d = (double)need; - d *= (double)lp->lnd_fuelu; - d /= (double)fuel_mult; - d /= 50.0; - if ((d-(int)d) > 0.0) - d++; - need = (int)d; - newfuel = supply_commod(lp->lnd_own,lp->lnd_x, - lp->lnd_y,I_OIL,need); - lp->lnd_fuel += (u_char)(newfuel * 50); - } - - have_fuel_for = (lp->lnd_fuel / - lp->lnd_fuelu)*fuel_mult; - - if (can_add > have_fuel_for){ - total_add = have_fuel_for; - } - else - total_add = can_add; - d = (double)total_add; - d *= (double)lp->lnd_fuelu; - d /= (double)fuel_mult; - lp->lnd_fuel -= (u_char)ldround(d,1); - lp->lnd_fuel = (u_char)min(lp->lnd_fuel, - lp->lnd_fuelc); - if(total_add + lp->lnd_mobil > land_mob_max) { + + can_add = land_mob_max - lp->lnd_mobil; + + if (can_add > ((float)etus * land_mob_scale)) + can_add = ((float)etus * land_mob_scale); + + have_fuel_for = (lp->lnd_fuel / lp->lnd_fuelu) * fuel_mult; + + if (can_add > have_fuel_for) { + int need; + need = can_add - have_fuel_for; + d = (double)need; + d *= (double)lp->lnd_fuelu; + d /= (double)fuel_mult; + d /= 5.0; + if ((d - (int)d) > 0.0) + d++; + need = (int)d; + newfuel = supply_commod(lp->lnd_own, lp->lnd_x, + lp->lnd_y, I_PETROL, need); + lp->lnd_fuel += (u_char)(newfuel * 5); + } + + have_fuel_for = (lp->lnd_fuel / lp->lnd_fuelu) * fuel_mult; + + if (can_add > have_fuel_for) { + int need; + need = can_add - have_fuel_for; + d = (double)need; + d *= (double)lp->lnd_fuelu; + d /= (double)fuel_mult; + d /= 50.0; + if ((d - (int)d) > 0.0) + d++; + need = (int)d; + newfuel = supply_commod(lp->lnd_own, lp->lnd_x, + lp->lnd_y, I_OIL, need); + lp->lnd_fuel += (u_char)(newfuel * 50); + } + + have_fuel_for = (lp->lnd_fuel / lp->lnd_fuelu) * fuel_mult; + + if (can_add > have_fuel_for) { + total_add = have_fuel_for; + } else + total_add = can_add; + d = (double)total_add; + d *= (double)lp->lnd_fuelu; + d /= (double)fuel_mult; + lp->lnd_fuel -= (u_char)ldround(d, 1); + lp->lnd_fuel = (u_char)min(lp->lnd_fuel, lp->lnd_fuelc); + if (total_add + lp->lnd_mobil > land_mob_max) { total_add = land_mob_max - lp->lnd_mobil; } - + if (opt_MOB_ACCESS) { - if (lp->lnd_mobil < 0) - lp->lnd_mobil += (s_char)total_add; + if (lp->lnd_mobil < 0) + lp->lnd_mobil += (s_char)total_add; } - lp->lnd_mobil += (s_char)total_add; + lp->lnd_mobil += (s_char)total_add; } } void mob_plane(register int etus) { - register struct plnstr *pp; - register int n; - time_t now; - - time(&now); - for (n=0; NULL != (pp = getplanep(n)); n++) { - pp->pln_timestamp = now; - if (opt_MOB_ACCESS) - pln_do_upd_mob(pp); - else - do_mob_plane(pp, etus); - } + register struct plnstr *pp; + register int n; + time_t now; + + time(&now); + for (n = 0; NULL != (pp = getplanep(n)); n++) { + pp->pln_timestamp = now; + if (opt_MOB_ACCESS) + pln_do_upd_mob(pp); + else + do_mob_plane(pp, etus); + } } void do_mob_plane(register struct plnstr *pp, register int etus) { - extern int plane_mob_max; - extern float plane_mob_scale; + extern int plane_mob_max; + extern float plane_mob_scale; register int value; if (pp->pln_own == 0) - return; - if (pp->pln_mobil >= plane_mob_max) { - pp->pln_mobil = plane_mob_max; - return; - } + return; + if (pp->pln_mobil >= plane_mob_max) { + pp->pln_mobil = plane_mob_max; + return; + } value = pp->pln_mobil + ((float)etus * plane_mob_scale); if (value > plane_mob_max) - value = plane_mob_max; + value = plane_mob_max; pp->pln_mobil = value; } diff --git a/src/lib/update/move_sat.c b/src/lib/update/move_sat.c index b4345dc86..da7c0324e 100644 --- a/src/lib/update/move_sat.c +++ b/src/lib/update/move_sat.c @@ -53,15 +53,14 @@ void move_sat(register struct plnstr *pp) { - coord x1,y1,x2,y2; - coord dx,dy; - float newtheta; - struct sctstr sect; + coord x1, y1, x2, y2; + coord dx, dy; + float newtheta; + struct sctstr sect; newtheta = pp->pln_theta + .05; - if (newtheta >= 1.0) - { + if (newtheta >= 1.0) { newtheta -= 1.0; } @@ -76,8 +75,7 @@ move_sat(register struct plnstr *pp) x2 -= dx; y2 -= dy; - if ((x2 + y2) & 1) - { + if ((x2 + y2) & 1) { x2++; } @@ -86,8 +84,9 @@ move_sat(register struct plnstr *pp) pp->pln_theta = newtheta; getsect(pp->pln_x, pp->pln_y, §); if (sect.sct_own) - if (pp->pln_own != sect.sct_own) - wu(0, sect.sct_own, "%s satellite spotted over %s\n", - cname(pp->pln_own), xyas(pp->pln_x, pp->pln_y, sect.sct_own)); + if (pp->pln_own != sect.sct_own) + wu(0, sect.sct_own, "%s satellite spotted over %s\n", + cname(pp->pln_own), xyas(pp->pln_x, pp->pln_y, + sect.sct_own)); return; } diff --git a/src/lib/update/nat.c b/src/lib/update/nat.c index fc09f052d..8bd4c8aa6 100644 --- a/src/lib/update/nat.c +++ b/src/lib/update/nat.c @@ -45,7 +45,7 @@ #include "update.h" #include "subs.h" -float levels[MAXNOC][4]; +float levels[MAXNOC][4]; /* * hap and edu avg mean that the weight on current happiness is @@ -58,9 +58,9 @@ float levels[MAXNOC][4]; * level of 0 yields (1) 0.4, (6) 2.2, (12) 3.9, (18) 5.2. */ -extern float hap_avg; -extern float edu_avg; -extern float ally_factor; +extern float hap_avg; +extern float edu_avg; +extern float ally_factor; /* * for values below the "easy level" values, production is @@ -75,8 +75,8 @@ extern float ally_factor; * They are changed later in the limit_level routine. */ /*tech res edu hap */ -float level_easy[4] = { 0.75, 0.75, 5.00, 5.00 }; -float level_log[4] = { 1.75, 2.00, 4.00, 6.00 }; +float level_easy[4] = { 0.75, 0.75, 5.00, 5.00 }; +float level_log[4] = { 1.75, 2.00, 4.00, 6.00 }; /* * technique to limit the sharpers who turn entire countries @@ -86,158 +86,156 @@ float level_log[4] = { 1.75, 2.00, 4.00, 6.00 }; double logx(double d, double base) { - if (base == 1.0) - return d; - return log10(d) / log10(base); + if (base == 1.0) + return d; + return log10(d) / log10(base); } double limit_level(double level, int type, int flag) { - double above_easy; - double above; - double logbase; - double easy; + double above_easy; + double above; + double logbase; + double easy; /* * Begin ugly hack. */ - extern float easy_tech, tech_log_base; + extern float easy_tech, tech_log_base; - level_easy[0] = easy_tech; - level_log[0] = tech_log_base; + level_easy[0] = easy_tech; + level_log[0] = tech_log_base; /* * End ugly hack. */ - if (level > level_easy[type]) { - logbase = level_log[type]; - easy = level_easy[type]; - above_easy = level - easy; - if (flag) - above = above_easy / logx(logbase + above_easy,logbase); - else - above = logx(above_easy + 1.0, logbase); - if (above > 250) above = 250; - return ((above) < 0) ? easy : (easy + above); - } else - return level; + if (level > level_easy[type]) { + logbase = level_log[type]; + easy = level_easy[type]; + above_easy = level - easy; + if (flag) + above = above_easy / logx(logbase + above_easy, logbase); + else + above = logx(above_easy + 1.0, logbase); + if (above > 250) + above = 250; + return ((above) < 0) ? easy : (easy + above); + } else + return level; } void prod_nat(int etu) { - extern long money[MAXNOC]; - extern long pops[MAXNOC]; - extern double hap_cons, edu_cons; - extern long sea_money[MAXNOC]; - extern long lnd_money[MAXNOC]; - extern long air_money[MAXNOC]; - struct natstr *np; - float hap; - float edu; - float hap_edu; - long pop; - double rlev; - double tlev; - double tech[MAXNOC]; - double res[MAXNOC]; - double newvalue; - natid n; - int cn,cont; + extern long money[MAXNOC]; + extern long pops[MAXNOC]; + extern double hap_cons, edu_cons; + extern long sea_money[MAXNOC]; + extern long lnd_money[MAXNOC]; + extern long air_money[MAXNOC]; + struct natstr *np; + float hap; + float edu; + float hap_edu; + long pop; + double rlev; + double tlev; + double tech[MAXNOC]; + double res[MAXNOC]; + double newvalue; + natid n; + int cn, cont; - for (n=0; NULL != (np = getnatp(n)); n++) { - if ((np->nat_stat & STAT_NORM) == 0) - continue; - /* - * hap_edu: the more education people have, the - * more happiness they want. - */ - hap_edu = np->nat_level[NAT_ELEV]; - hap_edu = 1.5 - ((hap_edu + 10.0) / (hap_edu + 20.0)); - pop = pops[n] + 1; - /* - * get per-population happiness and education - * see what the total per-civilian production is - * for this time period. - */ - hap = levels[n][NAT_HLEV] * hap_edu * hap_cons / - ((float)pop * etu); - edu = levels[n][NAT_ELEV] * edu_cons / - ((float)pop * etu); - wu((natid)0, n, "%3.0f happiness, %3.0f education produced\n", - levels[n][NAT_HLEV], levels[n][NAT_ELEV]); - hap = limit_level(hap, NAT_HLEV, 1); - edu = limit_level(edu, NAT_ELEV, 1); - /* - * change the "moving average"...old happiness and - * education levels are weighted heavier than current - * production. - */ - newvalue = (np->nat_level[NAT_HLEV] * hap_avg + hap * etu) / - (hap_avg + etu); - np->nat_level[NAT_HLEV] = newvalue; - newvalue = (np->nat_level[NAT_ELEV] * edu_avg + edu * etu) / - (edu_avg + etu); - np->nat_level[NAT_ELEV] = newvalue; - /* - * limit tech/research production - */ - levels[n][NAT_TLEV] = - limit_level(levels[n][NAT_TLEV] / 1, - NAT_TLEV, 0) * 1; - levels[n][NAT_RLEV] = - limit_level(levels[n][NAT_RLEV] / 1, - NAT_RLEV, 0) * 1; - wu((natid)0, n, - "total pop is %d, yielding %4.2f hap, %4.2f edu\n", - pop - 1, hap, edu); - } - if (ally_factor > 0.0) - share_incr(res, tech); - else { - bzero((s_char *)res, sizeof(res)); - bzero((s_char *)tech, sizeof(tech)); - } - for (n=0; NULL != (np = getnatp(n)); n++) { - if ((np->nat_stat & STAT_NORM) == 0) - continue; - tlev = levels[n][NAT_TLEV]; - rlev = levels[n][NAT_RLEV]; - if (tech[n] != 0.0 || res[n] != 0.0) { - wu((natid)0, n, - "%5.4f technology (%5.4f + %5.4f), ", - tlev + tech[n], tlev, tech[n]); - wu((natid)0, n, - "%5.4f research (%5.4f + %5.4f) produced\n", - rlev + res[n], rlev, res[n]); - } else - wu((natid)0, n, - "%5.4f tech, %5.4f research produced\n", - tlev, rlev); - rlev += res[n]; - tlev += tech[n]; - if (rlev != 0.0) - np->nat_level[NAT_RLEV] += rlev; - if (tlev != 0.0) - np->nat_level[NAT_TLEV] += tlev; - if ((sea_money[n] != 0) || (air_money[n] != 0) || - (lnd_money[n] != 0)) - wu((natid)0, n, - "Army delta $%d, Navy delta $%d, Air force delta $%d\n", - lnd_money[n], sea_money[n], air_money[n]); - wu((natid)0, n, "money delta was $%d for this update\n", - np->nat_money - money[n]); - if (opt_LOSE_CONTACT) { - for (cn=0; cn <= MAXNOC; cn++) { - cont = getcontact(np, cn); - if (cont > 0) { - logerror ("country %d at level %d with country %d.\n", n, cont, cn); - setcont(n, cn, cont-1); - } - } + for (n = 0; NULL != (np = getnatp(n)); n++) { + if ((np->nat_stat & STAT_NORM) == 0) + continue; + /* + * hap_edu: the more education people have, the + * more happiness they want. + */ + hap_edu = np->nat_level[NAT_ELEV]; + hap_edu = 1.5 - ((hap_edu + 10.0) / (hap_edu + 20.0)); + pop = pops[n] + 1; + /* + * get per-population happiness and education + * see what the total per-civilian production is + * for this time period. + */ + hap = levels[n][NAT_HLEV] * hap_edu * hap_cons / + ((float)pop * etu); + edu = levels[n][NAT_ELEV] * edu_cons / ((float)pop * etu); + wu((natid)0, n, "%3.0f happiness, %3.0f education produced\n", + levels[n][NAT_HLEV], levels[n][NAT_ELEV]); + hap = limit_level(hap, NAT_HLEV, 1); + edu = limit_level(edu, NAT_ELEV, 1); + /* + * change the "moving average"...old happiness and + * education levels are weighted heavier than current + * production. + */ + newvalue = (np->nat_level[NAT_HLEV] * hap_avg + hap * etu) / + (hap_avg + etu); + np->nat_level[NAT_HLEV] = newvalue; + newvalue = (np->nat_level[NAT_ELEV] * edu_avg + edu * etu) / + (edu_avg + etu); + np->nat_level[NAT_ELEV] = newvalue; + /* + * limit tech/research production + */ + levels[n][NAT_TLEV] = + limit_level(levels[n][NAT_TLEV] / 1, NAT_TLEV, 0) * 1; + levels[n][NAT_RLEV] = + limit_level(levels[n][NAT_RLEV] / 1, NAT_RLEV, 0) * 1; + wu((natid)0, n, + "total pop is %d, yielding %4.2f hap, %4.2f edu\n", + pop - 1, hap, edu); + } + if (ally_factor > 0.0) + share_incr(res, tech); + else { + bzero((s_char *)res, sizeof(res)); + bzero((s_char *)tech, sizeof(tech)); + } + for (n = 0; NULL != (np = getnatp(n)); n++) { + if ((np->nat_stat & STAT_NORM) == 0) + continue; + tlev = levels[n][NAT_TLEV]; + rlev = levels[n][NAT_RLEV]; + if (tech[n] != 0.0 || res[n] != 0.0) { + wu((natid)0, n, + "%5.4f technology (%5.4f + %5.4f), ", + tlev + tech[n], tlev, tech[n]); + wu((natid)0, n, + "%5.4f research (%5.4f + %5.4f) produced\n", + rlev + res[n], rlev, res[n]); + } else + wu((natid)0, n, + "%5.4f tech, %5.4f research produced\n", tlev, rlev); + rlev += res[n]; + tlev += tech[n]; + if (rlev != 0.0) + np->nat_level[NAT_RLEV] += rlev; + if (tlev != 0.0) + np->nat_level[NAT_TLEV] += tlev; + if ((sea_money[n] != 0) || (air_money[n] != 0) || + (lnd_money[n] != 0)) + wu((natid)0, n, + "Army delta $%d, Navy delta $%d, Air force delta $%d\n", + lnd_money[n], sea_money[n], air_money[n]); + wu((natid)0, n, "money delta was $%d for this update\n", + np->nat_money - money[n]); + if (opt_LOSE_CONTACT) { + for (cn = 0; cn <= MAXNOC; cn++) { + cont = getcontact(np, cn); + if (cont > 0) { + logerror("country %d at level %d with country %d.\n", + n, cont, cn); + setcont(n, cn, cont - 1); } + } } + } } /* @@ -246,64 +244,63 @@ prod_nat(int etu) void share_incr(register double *res, register double *tech) { - register struct natstr *np; - register struct natstr *other; - register natid i; - register natid j; - int rnc; - int tnc; + register struct natstr *np; + register struct natstr *other; + register natid i; + register natid j; + int rnc; + int tnc; - for (i=0; NULL != (np = getnatp(i)); i++) { - res[i] = tech[i] = 0.0; - if ((np->nat_stat & STAT_INUSE) == 0) - continue; - if (np->nat_stat & STAT_GOD) - continue; - if (np->nat_stat == VIS) - continue; - rnc = tnc = 0; - for (j=0; NULL != (other = getnatp(j)); j++) { - if (j == i) - continue; - if (other->nat_stat & STAT_GOD) - continue; - if (other->nat_stat == VIS) - continue; - if ((other->nat_stat & STAT_INUSE) == 0) - continue; - if (opt_HIDDEN) { - if (!getcontact(np, j)) - continue; - } - if (!opt_ALL_BLEED) { - if (getrel(np, j) != ALLIED) - continue; - if (getrel(other, i) != ALLIED) - continue; - res[i] += levels[j][NAT_RLEV]; - tech[i] += levels[j][NAT_TLEV]; - rnc++; - tnc++; - } else { - if (levels[j][NAT_TLEV] > 0.001) { - tech[i] += levels[j][NAT_TLEV]; - tnc++; - } - if (levels[j][NAT_RLEV] > 0.001) { - res[i] += levels[j][NAT_RLEV]; - rnc++; - } - } - } - if (rnc == 0 && tnc == 0) - continue; - if (rnc > 0) { - res[i] /= rnc * ally_factor; + for (i = 0; NULL != (np = getnatp(i)); i++) { + res[i] = tech[i] = 0.0; + if ((np->nat_stat & STAT_INUSE) == 0) + continue; + if (np->nat_stat & STAT_GOD) + continue; + if (np->nat_stat == VIS) + continue; + rnc = tnc = 0; + for (j = 0; NULL != (other = getnatp(j)); j++) { + if (j == i) + continue; + if (other->nat_stat & STAT_GOD) + continue; + if (other->nat_stat == VIS) + continue; + if ((other->nat_stat & STAT_INUSE) == 0) + continue; + if (opt_HIDDEN) { + if (!getcontact(np, j)) + continue; + } + if (!opt_ALL_BLEED) { + if (getrel(np, j) != ALLIED) + continue; + if (getrel(other, i) != ALLIED) + continue; + res[i] += levels[j][NAT_RLEV]; + tech[i] += levels[j][NAT_TLEV]; + rnc++; + tnc++; + } else { + if (levels[j][NAT_TLEV] > 0.001) { + tech[i] += levels[j][NAT_TLEV]; + tnc++; } - if (tnc > 0) { - tech[i] /= tnc * ally_factor; + if (levels[j][NAT_RLEV] > 0.001) { + res[i] += levels[j][NAT_RLEV]; + rnc++; } -/* logerror("Country #%d gets %g res from %d allies, %g tech from %d allies", i, res[i], rnc, tech[i], tnc);*/ + } + } + if (rnc == 0 && tnc == 0) + continue; + if (rnc > 0) { + res[i] /= rnc * ally_factor; + } + if (tnc > 0) { + tech[i] /= tnc * ally_factor; } +/* logerror("Country #%d gets %g res from %d allies, %g tech from %d allies", i, res[i], rnc, tech[i], tnc);*/ + } } - diff --git a/src/lib/update/nav_ship.c b/src/lib/update/nav_ship.c index d2e5c5b20..5021d5049 100644 --- a/src/lib/update/nav_ship.c +++ b/src/lib/update/nav_ship.c @@ -61,7 +61,7 @@ scuttle_it(register struct shpstr *sp) struct sctstr *sectp; sp->shp_autonav &= ~AN_SCUTTLE; - if (!(sectp = getsectp(sp->shp_x,sp->shp_y))) { + if (!(sectp = getsectp(sp->shp_x, sp->shp_y))) { wu(0, 0, "bad sector (%d,%d) ship %d\n", sp->shp_x, sp->shp_y, sp->shp_uid); return; @@ -74,14 +74,12 @@ scuttle_it(register struct shpstr *sp) } if (opt_TRADESHIPS) { if (!(mchr[(int)sp->shp_type].m_flags & M_TRADE)) { - wu(0, sp->shp_own, - "You can only autoscuttle trade ships!\n"); + wu(0, sp->shp_own, "You can only autoscuttle trade ships!\n"); return; } } wu(0, sp->shp_own, "Scuttling %s in sector %s\n", - prship(sp), - xyas(sp->shp_x, sp->shp_y, sp->shp_own)); + prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); if (opt_TRADESHIPS) { scuttle_tradeship(sp, 0); } @@ -91,17 +89,15 @@ scuttle_it(register struct shpstr *sp) static void nav_check_atdest(register struct shpstr *sp, struct mchrstr *mcp) { - if ((sp->shp_x == sp->shp_destx[0]) && - (sp->shp_y == sp->shp_desty[0])) { + if ((sp->shp_x == sp->shp_destx[0]) && (sp->shp_y == sp->shp_desty[0])) { if ((sp->shp_destx[0] == sp->shp_destx[1]) && (sp->shp_desty[0] == sp->shp_desty[1])) { - + /* End of road */ - + sp->shp_autonav &= ~AN_AUTONAV; wu(0, sp->shp_own, "%s arrived at %s, finished\n", - prship(sp), - xyas(sp->shp_x,sp->shp_y,sp->shp_own)); + prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); if (sp->shp_autonav & AN_SCUTTLE) { scuttle_it(sp); } @@ -109,10 +105,9 @@ nav_check_atdest(register struct shpstr *sp, struct mchrstr *mcp) /* unload all cargo */ unload_it(sp); wu(0, sp->shp_own, "%s arrived at %s\n", - prship(sp), - xyas(sp->shp_x,sp->shp_y,sp->shp_own)); + prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); /* Swap */ - swap(sp); + swap(sp); } } else sp->shp_autonav &= ~AN_LOADING; @@ -124,32 +119,35 @@ nav_check_atdest(register struct shpstr *sp, struct mchrstr *mcp) void swap(register struct shpstr *sp) { - coord tcord; - s_char tcomm[TMAX]; - short lev[TMAX]; - int i; - - tcord = sp->shp_destx[0]; - sp->shp_destx[0] = sp->shp_destx[1]; - sp->shp_destx[1] = tcord; - tcord = sp->shp_desty[0]; - sp->shp_desty[0] = sp->shp_desty[1]; - sp->shp_desty[1] = tcord; - - for (i=0;ishp_lstart[i]; - tcomm[i] = sp->shp_tstart[i]; } - - for (i=0;ishp_destx[0]; + sp->shp_destx[0] = sp->shp_destx[1]; + sp->shp_destx[1] = tcord; + tcord = sp->shp_desty[0]; + sp->shp_desty[0] = sp->shp_desty[1]; + sp->shp_desty[1] = tcord; + + for (i = 0; i < TMAX; ++i) { + lev[i] = sp->shp_lstart[i]; + tcomm[i] = sp->shp_tstart[i]; + } + + for (i = 0; i < TMAX; ++i) { sp->shp_lstart[i] = sp->shp_lend[i]; - sp->shp_tstart[i] = sp->shp_tend[i]; } + sp->shp_tstart[i] = sp->shp_tend[i]; + } - for (i=0;ishp_lend[i] = lev[i]; - sp->shp_tend[i] = tcomm[i]; } + for (i = 0; i < TMAX; ++i) { + sp->shp_lend[i] = lev[i]; + sp->shp_tend[i] = tcomm[i]; + } - /* set load bit */ - sp->shp_autonav |= AN_LOADING; + /* set load bit */ + sp->shp_autonav |= AN_LOADING; } /* New Autonav code. @@ -157,75 +155,70 @@ swap(register struct shpstr *sp) * 6-1-94 */ -static int +static int nav_loadship(register struct shpstr *sp, natid cnum) { - struct sctstr *sectp; - s_char item; - int i, - landown, - shipown, - level, - didsomething[TMAX], - rel; + struct sctstr *sectp; + s_char item; + int i, landown, shipown, level, didsomething[TMAX], rel; - for (i=0;ishp_autonav &= ~AN_LOADING; + sp->shp_autonav &= ~AN_LOADING; - if (!(sectp = getsectp(sp->shp_x,sp->shp_y))) - return RET_SYS; /* safety */ - /* I suspect RET_SYS isn't really what you want here --dfp */ + if (!(sectp = getsectp(sp->shp_x, sp->shp_y))) + return RET_SYS; /* safety */ + /* I suspect RET_SYS isn't really what you want here --dfp */ - landown = sectp->sct_own; - shipown = sp->shp_own; - rel = getrel(getnatp(sectp->sct_own),cnum); + landown = sectp->sct_own; + shipown = sp->shp_own; + rel = getrel(getnatp(sectp->sct_own), cnum); - /* loop through each field for that ship */ - for (i=0;ishp_tend[i]; /* commodity */ - level = sp->shp_lend[i]; /* amount */ + /* loop through each field for that ship */ + for (i = 0; i < TMAX; ++i) { + item = sp->shp_tend[i]; /* commodity */ + level = sp->shp_lend[i]; /* amount */ - /* check and see if the data fields have been set. */ + /* check and see if the data fields have been set. */ - if (item == ' ' || level == 0) { - /* nothing to do move on. */ - didsomething[i] = 1; - continue; - } - if (landown == 0) { - /* either sea or deity harbor */ - didsomething[i] = 1; - continue; - } - if (sectp->sct_type != SCT_HARBR && - (!opt_BIG_CITY || sectp->sct_type != SCT_CAPIT)) { - /* we can only load in harbors */ - didsomething[i] = 1; - continue; - } - if (landown == shipown || rel >= FRIENDLY) - didsomething[i] = load_it(sp,sectp,i); + if (item == ' ' || level == 0) { + /* nothing to do move on. */ + didsomething[i] = 1; + continue; + } + if (landown == 0) { + /* either sea or deity harbor */ + didsomething[i] = 1; + continue; } + if (sectp->sct_type != SCT_HARBR && + (!opt_BIG_CITY || sectp->sct_type != SCT_CAPIT)) { + /* we can only load in harbors */ + didsomething[i] = 1; + continue; + } + if (landown == shipown || rel >= FRIENDLY) + didsomething[i] = load_it(sp, sectp, i); + } - /* check for any unsucessful loads */ - /* if we have any return 0 to stop */ - /* the nav_ship loop. */ + /* check for any unsucessful loads */ + /* if we have any return 0 to stop */ + /* the nav_ship loop. */ - for (i=0;ishp_autonav & AN_AUTONAV) || (sp->shp_autonav & AN_STANDBY)) - return RET_OK; - - cnum = sp->shp_own; - vship = mcp = &mchr[(int)sp->shp_type]; - - /* Make a list of one ships so we can use the navi.c code */ - emp_initque(&ship_list); - mlp = (struct mlist *) malloc(sizeof(struct mlist)); - mlp->mcp = mchr + sp->shp_type; - bcopy((s_char *)sp, (s_char *)&mlp->ship, sizeof(struct shpstr)); - mlp->mobil = (double)sp->shp_mobil; - emp_insque(&mlp->queue, &ship_list); - - quit = 1; /* setup loop, we want to check it 1 time. */ - - do { - if ((sp->shp_mobil > 0) && (!(sp->shp_autonav & AN_LOADING)) && - (!(sp->shp_autonav & AN_STANDBY))) { - shp_nav(&ship_list, &dummydouble, &dummydouble, &dummyint, - sp->shp_own); - if (QEMPTY(&ship_list)) - return RET_OK; - /* before we move check to see if ship needs fuel. */ - sectp = getsectp(sp->shp_x,sp->shp_y); - if (opt_FUEL && - sectp->sct_own != 0 && - sp->shp_fuel <= 0 && - mlp->mcp->m_fuelu != 0) - auto_fuel_ship(sp); - mlp->ship.shp_fuel = sp->shp_fuel; - - cp = BestShipPath(buf, sp->shp_x, sp->shp_y, - sp->shp_destx[0], sp->shp_desty[0], - sp->shp_own); - if (cp == 0 || (*cp == '\0') || (*cp == '?')) { - wu(0, cnum, - "%s bad path, ship put on standby\n", - prship(sp)); - sp->shp_autonav |= AN_STANDBY; - putship(sp->shp_uid, (s_char *)sp); - - /* We need to free the ship list */ - qp = ship_list.q_forw; - while (qp != &(ship_list)) { - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; - } - return RET_SYN; - } - stopping = 0; - - while (*cp && !stopping && sp->shp_own && - mlp->mobil > 0.0) { - dir = chkdir(*cp++, DIR_STOP, DIR_LAST); - - stopping |= shp_nav_one_sector(&ship_list, dir, - sp->shp_own, 0); + extern double techfact(int, double); + struct sctstr *sectp; + s_char *cp, item; + int stopping; + int quit; + int didsomething = 0; + int max_amt, food_amt, comm; + s_char buf[1024]; + struct emp_qelem ship_list; + struct emp_qelem *qp, *newqp; + struct mlist *mlp; + int dummyint; + double dummydouble; + int dir; + natid cnum; + struct mchrstr *mcp, *vship; + + /* just return if no autonaving to do for this ship */ + if (!(sp->shp_autonav & AN_AUTONAV) || (sp->shp_autonav & AN_STANDBY)) + return RET_OK; + + cnum = sp->shp_own; + vship = mcp = &mchr[(int)sp->shp_type]; + + /* Make a list of one ships so we can use the navi.c code */ + emp_initque(&ship_list); + mlp = (struct mlist *)malloc(sizeof(struct mlist)); + mlp->mcp = mchr + sp->shp_type; + bcopy((s_char *)sp, (s_char *)&mlp->ship, sizeof(struct shpstr)); + mlp->mobil = (double)sp->shp_mobil; + emp_insque(&mlp->queue, &ship_list); + + quit = 1; /* setup loop, we want to check it 1 time. */ + + do { + if ((sp->shp_mobil > 0) && (!(sp->shp_autonav & AN_LOADING)) && + (!(sp->shp_autonav & AN_STANDBY))) { + shp_nav(&ship_list, &dummydouble, &dummydouble, &dummyint, + sp->shp_own); + if (QEMPTY(&ship_list)) + return RET_OK; + /* before we move check to see if ship needs fuel. */ + sectp = getsectp(sp->shp_x, sp->shp_y); + if (opt_FUEL && + sectp->sct_own != 0 && + sp->shp_fuel <= 0 && mlp->mcp->m_fuelu != 0) + auto_fuel_ship(sp); + mlp->ship.shp_fuel = sp->shp_fuel; + + cp = BestShipPath(buf, sp->shp_x, sp->shp_y, + sp->shp_destx[0], sp->shp_desty[0], + sp->shp_own); + if (cp == 0 || (*cp == '\0') || (*cp == '?')) { + wu(0, cnum, + "%s bad path, ship put on standby\n", prship(sp)); + sp->shp_autonav |= AN_STANDBY; + putship(sp->shp_uid, (s_char *)sp); + + /* We need to free the ship list */ + qp = ship_list.q_forw; + while (qp != &(ship_list)) { + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; } - -/* sp->shp_mobil = (int) mobil; - */ - /* Ship not sunk */ - if (sp->shp_own) - nav_check_atdest(sp, mcp); + return RET_SYN; } - - quit = 0; /* stop loop */ - - /* Try to load the ship */ - if (sp->shp_autonav & AN_LOADING) { - didsomething = nav_loadship(sp, cnum); - if (didsomething) - quit = 1; - } - /* special case for fishing boats */ - if ((mchr[(int)sp->shp_type].m_flags & M_FOOD) == 1) { - item = (s_char)'f'; - comm = com_num(&item); - food_amt=getvar(comm,(s_char *) sp, EF_SHIP); - max_amt=(vl_find(comm,vship->m_vtype, - vship->m_vamt, - (int) vship->m_nv)); - sectp=getsectp(sp->shp_x,sp->shp_y); - - if (food_amtsct_own==0)) - quit=0; + stopping = 0; + + while (*cp && !stopping && sp->shp_own && mlp->mobil > 0.0) { + dir = chkdir(*cp++, DIR_STOP, DIR_LAST); + + stopping |= shp_nav_one_sector(&ship_list, dir, + sp->shp_own, 0); } - /* reset flag and check if we can move. */ - - } while (quit); /* end loop */ - - putship(sp->shp_uid, sp); - - /* We need to free the ship list (just in case) */ - qp = ship_list.q_forw; - while (qp != &(ship_list)) { - newqp = qp->q_forw; - emp_remque(qp); - free((s_char *)qp); - qp = newqp; + +/* sp->shp_mobil = (int) mobil; + */ + /* Ship not sunk */ + if (sp->shp_own) + nav_check_atdest(sp, mcp); } - return RET_OK; -} + + quit = 0; /* stop loop */ + + /* Try to load the ship */ + if (sp->shp_autonav & AN_LOADING) { + didsomething = nav_loadship(sp, cnum); + if (didsomething) + quit = 1; + } + /* special case for fishing boats */ + if ((mchr[(int)sp->shp_type].m_flags & M_FOOD) == 1) { + item = (s_char)'f'; + comm = com_num(&item); + food_amt = getvar(comm, (s_char *)sp, EF_SHIP); + max_amt = (vl_find(comm, vship->m_vtype, + vship->m_vamt, (int)vship->m_nv)); + sectp = getsectp(sp->shp_x, sp->shp_y); + + if (food_amt < max_amt && (sectp->sct_own == 0)) + quit = 0; + } + /* reset flag and check if we can move. */ + + } while (quit); /* end loop */ + + putship(sp->shp_uid, sp); + + /* We need to free the ship list (just in case) */ + qp = ship_list.q_forw; + while (qp != &(ship_list)) { + newqp = qp->q_forw; + emp_remque(qp); + free((s_char *)qp); + qp = newqp; + } + return RET_OK; +} diff --git a/src/lib/update/nav_util.c b/src/lib/update/nav_util.c index 30293b969..fa3c70972 100644 --- a/src/lib/update/nav_util.c +++ b/src/lib/update/nav_util.c @@ -56,27 +56,27 @@ #include "gen.h" /* Format a ship name */ -int +int check_nav(struct sctstr *sect) { - extern struct dchrstr dchr[]; - - switch (dchr[sect->sct_type].d_flg & 03) { - case NAVOK: - break; - - case NAV_02: - if (sect->sct_effic < 2) - return CN_CONSTRUCTION; - break; - case NAV_60: - if (sect->sct_effic < 60) - return CN_CONSTRUCTION; - break; - default: - return CN_LANDLOCKED; - } - return CN_NAVIGABLE; + extern struct dchrstr dchr[]; + + switch (dchr[sect->sct_type].d_flg & 03) { + case NAVOK: + break; + + case NAV_02: + if (sect->sct_effic < 2) + return CN_CONSTRUCTION; + break; + case NAV_60: + if (sect->sct_effic < 60) + return CN_CONSTRUCTION; + break; + default: + return CN_LANDLOCKED; + } + return CN_NAVIGABLE; } /* load a specific ship given its @@ -84,74 +84,75 @@ check_nav(struct sctstr *sect) * new autonav code * Chad Zabel 6/1/94 */ -int +int load_it(register struct shpstr *sp, register struct sctstr *psect, int i) -{ - int comm, shipown, amount, ship_amt, sect_amt, - abs_max, max_amt, transfer; - s_char item; - struct mchrstr *vship; - - amount = sp->shp_lend[i]; - shipown = sp->shp_own; - item = sp->shp_tend[i]; /* commodity */ - comm = com_num(&item); - - ship_amt = getvar(comm,(s_char *) sp , EF_SHIP); - sect_amt = getvar(comm,(s_char *) psect, EF_SECTOR); - - /* check for disloyal civilians */ - if (psect->sct_oldown != shipown && comm == V_CIVIL) - { wu(0,shipown,"Ship #%d - unable to load disloyal civilians at %s.", - sp->shp_uid, xyas(psect->sct_x,psect->sct_y,psect->sct_own)); - return 0; - } - if (comm == V_CIVIL || comm == V_MILIT) - sect_amt--; /* leave 1 civ or mil to hold the sector. */ - vship = &mchr[(int)sp->shp_type]; - abs_max = max_amt = (vl_find(comm,vship->m_vtype, - vship->m_vamt,(int) vship->m_nv)); - - if (!abs_max) - return 0; /* can't load the ship, skip to the end. */ - - max_amt = min (sect_amt, max_amt - ship_amt); - if (max_amt <= 0 && (ship_amt != abs_max)) { - sp->shp_autonav |= AN_LOADING; - return 0; - } - - - transfer = amount - ship_amt; - if (transfer > sect_amt) { /* not enough in the */ - transfer = sect_amt; /* sector to fill the */ - sp->shp_autonav |= AN_LOADING; /* ship, set load flag */ - } - if (ship_amt + transfer > abs_max) /* Do not load more */ - transfer = abs_max-ship_amt; /* then the max alowed */ - /* on the ship. */ - - if (transfer == 0) - return 0; /* nothing to move */ - - - putvar(comm, ship_amt + transfer, (s_char *)sp, EF_SHIP); - if (comm == V_CIVIL || comm == V_MILIT) - sect_amt++; /*adjustment*/ - putvar(comm, sect_amt - transfer, (s_char *)psect, EF_SECTOR); - - /* deal with the plague */ - if (getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)sp , EF_SHIP) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP); - if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)psect, EF_SECTOR); - - return 1; /* we did someloading return 1 to keep */ - /* our loop happy in nav_ship() */ - -} +{ + int comm, shipown, amount, ship_amt, sect_amt, + abs_max, max_amt, transfer; + s_char item; + struct mchrstr *vship; + + amount = sp->shp_lend[i]; + shipown = sp->shp_own; + item = sp->shp_tend[i]; /* commodity */ + comm = com_num(&item); + + ship_amt = getvar(comm, (s_char *)sp, EF_SHIP); + sect_amt = getvar(comm, (s_char *)psect, EF_SECTOR); + + /* check for disloyal civilians */ + if (psect->sct_oldown != shipown && comm == V_CIVIL) { + wu(0, shipown, + "Ship #%d - unable to load disloyal civilians at %s.", + sp->shp_uid, xyas(psect->sct_x, psect->sct_y, psect->sct_own)); + return 0; + } + if (comm == V_CIVIL || comm == V_MILIT) + sect_amt--; /* leave 1 civ or mil to hold the sector. */ + vship = &mchr[(int)sp->shp_type]; + abs_max = max_amt = (vl_find(comm, vship->m_vtype, + vship->m_vamt, (int)vship->m_nv)); + + if (!abs_max) + return 0; /* can't load the ship, skip to the end. */ + + max_amt = min(sect_amt, max_amt - ship_amt); + if (max_amt <= 0 && (ship_amt != abs_max)) { + sp->shp_autonav |= AN_LOADING; + return 0; + } + + + transfer = amount - ship_amt; + if (transfer > sect_amt) { /* not enough in the */ + transfer = sect_amt; /* sector to fill the */ + sp->shp_autonav |= AN_LOADING; /* ship, set load flag */ + } + if (ship_amt + transfer > abs_max) /* Do not load more */ + transfer = abs_max - ship_amt; /* then the max alowed */ + /* on the ship. */ + + if (transfer == 0) + return 0; /* nothing to move */ + + + putvar(comm, ship_amt + transfer, (s_char *)sp, EF_SHIP); + if (comm == V_CIVIL || comm == V_MILIT) + sect_amt++; /*adjustment */ + putvar(comm, sect_amt - transfer, (s_char *)psect, EF_SECTOR); + + /* deal with the plague */ + if (getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP); + if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)psect, EF_SECTOR) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)psect, EF_SECTOR); + + return 1; /* we did someloading return 1 to keep */ + /* our loop happy in nav_ship() */ + +} /* unload_it * A guess alot of this looks like load_it but because of its location @@ -160,75 +161,77 @@ load_it(register struct shpstr *sp, register struct sctstr *psect, int i) * ONLY goods in the trade fields will be unloaded. * new autonav code * Chad Zabel 6/1/94 - */ + */ void unload_it(register struct shpstr *sp) { - struct sctstr *sectp; - s_char item; - int i; - int landowner; - int shipown; - int comm; - int sect_amt; - int ship_amt; - int abs_max = 99999; /* max amount a sector can hold. */ - int max_amt; - int level; - - - sectp = getsectp(sp->shp_x,sp->shp_y); - - landowner = sectp->sct_own; - shipown = sp->shp_own; - - for(i=0;ishp_tend[i]; - level = sp->shp_lend[i]; - - if (item == ' ' || level == 0) - continue; - if (landowner == 0 ) - continue; - if (sectp->sct_type != SCT_HARBR) - continue; - - comm = com_num(&item); - ship_amt = getvar(comm,(s_char *) sp ,EF_SHIP); - sect_amt = getvar(comm,(s_char *) sectp ,EF_SECTOR); - - /* check for disloyal civilians */ - if (sectp->sct_oldown != shipown && comm == V_CIVIL) - { - wu(0,sp->shp_own,"Ship #%d - unable to unload civilians into a disloyal sector at %s.", - sp->shp_uid, xyas(sectp->sct_x,sectp->sct_y,sectp->sct_own)); - continue; - } - if (comm == V_CIVIL) - ship_amt--; /* This leaves 1 civs on board the ship */ - - if (sect_amt >= abs_max) - continue; /* The sector is full. */ - - max_amt = min (ship_amt,abs_max - sect_amt); - - if (max_amt <= 0) - continue; - - putvar(comm, ship_amt - max_amt, (s_char *) sp ,EF_SHIP); - putvar(comm, sect_amt + max_amt, (s_char *) sectp,EF_SECTOR); - - if (getvar(V_PSTAGE, (s_char *)sectp,EF_SECTOR) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)sp ,EF_SHIP ) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED,(s_char *)sp, EF_SHIP); - - if (getvar(V_PSTAGE, (s_char *)sp ,EF_SHIP ) == PLG_INFECT && - getvar(V_PSTAGE, (s_char *)sectp,EF_SECTOR) == PLG_HEALTHY) - putvar(V_PSTAGE, PLG_EXPOSED,(s_char *)sectp, EF_SECTOR); - - } - - } + struct sctstr *sectp; + s_char item; + int i; + int landowner; + int shipown; + int comm; + int sect_amt; + int ship_amt; + int abs_max = 99999; /* max amount a sector can hold. */ + int max_amt; + int level; + + + sectp = getsectp(sp->shp_x, sp->shp_y); + + landowner = sectp->sct_own; + shipown = sp->shp_own; + + for (i = 0; i < TMAX; ++i) { + item = sp->shp_tend[i]; + level = sp->shp_lend[i]; + + if (item == ' ' || level == 0) + continue; + if (landowner == 0) + continue; + if (sectp->sct_type != SCT_HARBR) + continue; + + comm = com_num(&item); + ship_amt = getvar(comm, (s_char *)sp, EF_SHIP); + sect_amt = getvar(comm, (s_char *)sectp, EF_SECTOR); + + /* check for disloyal civilians */ + if (sectp->sct_oldown != shipown && comm == V_CIVIL) { + wu(0, sp->shp_own, + "Ship #%d - unable to unload civilians into a disloyal sector at %s.", + sp->shp_uid, xyas(sectp->sct_x, sectp->sct_y, + sectp->sct_own)); + continue; + } + if (comm == V_CIVIL) + ship_amt--; /* This leaves 1 civs on board the ship */ + + if (sect_amt >= abs_max) + continue; /* The sector is full. */ + + max_amt = min(ship_amt, abs_max - sect_amt); + + if (max_amt <= 0) + continue; + + putvar(comm, ship_amt - max_amt, (s_char *)sp, EF_SHIP); + putvar(comm, sect_amt + max_amt, (s_char *)sectp, EF_SECTOR); + + if (getvar(V_PSTAGE, (s_char *)sectp, EF_SECTOR) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sp, EF_SHIP); + + if (getvar(V_PSTAGE, (s_char *)sp, EF_SHIP) == PLG_INFECT && + getvar(V_PSTAGE, (s_char *)sectp, EF_SECTOR) == PLG_HEALTHY) + putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)sectp, EF_SECTOR); + + } + +} + /* com_num * This small but useful bit of code runs through the list * of commodities and return the integer value of the @@ -242,13 +245,13 @@ unload_it(register struct shpstr *sp) int com_num(s_char *ptr) { - struct ichrstr *ip; + struct ichrstr *ip; - for(ip = &ichr[1];ip->i_mnem != 0; ip++) { - if (*ptr == ip->i_mnem) - return ip->i_vtype; - } - return 0; /*NOTREACHED*/ + for (ip = &ichr[1]; ip->i_mnem != 0; ip++) { + if (*ptr == ip->i_mnem) + return ip->i_vtype; + } + return 0; /*NOTREACHED*/ } @@ -259,52 +262,52 @@ com_num(s_char *ptr) * new autonav code. * This should be merged with the fuel command someday. * Chad Zabel 6/1/94 - */ + */ void auto_fuel_ship(register struct shpstr *sp) { - double d; - int totalfuel = 0; - int need; - int maxfuel; - int newfuel = 0; - int add_fuel = 0; - - if (opt_FUEL == 0) return; - getship(sp->shp_uid,sp); /* refresh */ - /* fill with petro */ - maxfuel = mchr[(int)sp->shp_type].m_fuelc; - d = (double) maxfuel / 5.0; - if (( d-(int)d > 0.0 )) - d++; - need = (int)d; - - newfuel = supply_commod(sp->shp_own,sp->shp_x, - sp->shp_y,I_PETROL,need); - add_fuel += newfuel * 5; - if (add_fuel > maxfuel) - add_fuel = maxfuel; - sp->shp_fuel += add_fuel; - totalfuel += add_fuel; - - if (totalfuel == maxfuel) { - putship(sp->shp_uid,sp); - return; /* the ship is full */ - } - add_fuel = 0; - /* fill with oil */ - d = (double) (maxfuel - totalfuel) / 50.0; - if ((d-(int)d > 0.0)) - d++; - need = (int)d; - - newfuel = supply_commod(sp->shp_own,sp->shp_x, - sp->shp_y,I_OIL,need); - add_fuel = newfuel * 50; - if (add_fuel > maxfuel) - add_fuel = maxfuel; - sp->shp_fuel += add_fuel; - putship(sp->shp_uid,sp); -} - + double d; + int totalfuel = 0; + int need; + int maxfuel; + int newfuel = 0; + int add_fuel = 0; + + if (opt_FUEL == 0) + return; + getship(sp->shp_uid, sp); /* refresh */ + /* fill with petro */ + maxfuel = mchr[(int)sp->shp_type].m_fuelc; + d = (double)maxfuel / 5.0; + if ((d - (int)d > 0.0)) + d++; + need = (int)d; + + newfuel = supply_commod(sp->shp_own, sp->shp_x, + sp->shp_y, I_PETROL, need); + add_fuel += newfuel * 5; + if (add_fuel > maxfuel) + add_fuel = maxfuel; + sp->shp_fuel += add_fuel; + totalfuel += add_fuel; + + if (totalfuel == maxfuel) { + putship(sp->shp_uid, sp); + return; /* the ship is full */ + } + add_fuel = 0; + /* fill with oil */ + d = (double)(maxfuel - totalfuel) / 50.0; + if ((d - (int)d > 0.0)) + d++; + need = (int)d; + + newfuel = supply_commod(sp->shp_own, sp->shp_x, + sp->shp_y, I_OIL, need); + add_fuel = newfuel * 50; + if (add_fuel > maxfuel) + add_fuel = maxfuel; + sp->shp_fuel += add_fuel; + putship(sp->shp_uid, sp); +} diff --git a/src/lib/update/nxtitemp.c b/src/lib/update/nxtitemp.c index f6268badf..f2106122e 100644 --- a/src/lib/update/nxtitemp.c +++ b/src/lib/update/nxtitemp.c @@ -50,70 +50,70 @@ s_char * nxtitemp(struct nstr_item *np, int owner) { - struct genitem *gp; - int selected; + struct genitem *gp; + int selected; - if (np->sel == NS_UNDEF) + if (np->sel == NS_UNDEF) + return 0; + do { + if (np->sel == NS_LIST) { + np->index++; + if (np->index >= np->size) return 0; - do { - if (np->sel == NS_LIST) { - np->index++; - if (np->index >= np->size) - return 0; - np->cur = np->list[np->index]; - } else { - np->cur++; - } - gp = (struct genitem *)ef_ptr(np->type,np->cur); - if (gp == (struct genitem *)0) - return 0; + np->cur = np->list[np->index]; + } else { + np->cur++; + } + gp = (struct genitem *)ef_ptr(np->type, np->cur); + if (gp == (struct genitem *)0) + return 0; - selected = 1; - switch (np->sel) { - /* - * This one won't work unless you're running in emp_player - * - */ - case NS_LIST: - if ((np->flags & EFF_OWNER) && !owner) - selected = 0; - break; - case NS_ALL: - /* XXX maybe combine NS_LIST and NS_ALL later */ - break; - case NS_DIST: - if (!xyinrange(gp->x, gp->y, &np->range)) { - selected = 0; - break; - } - np->curdist = mapdist((int)gp->x, (int)gp->y, - (int)np->cx, (int)np->cy); - if (np->curdist > np->dist) - selected = 0; - break; - case NS_AREA: - if (!xyinrange(gp->x, gp->y, &np->range)) - selected = 0; - if (gp->x == np->range.hx || gp->y == np->range.hy) - selected = 0; - break; - case NS_XY: - if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy) - selected = 0; - break; - case NS_GROUP: - if (np->group != gp->group) - selected = 0; - break; - default: - logerror("nxtitemp: bad selector %d\n", np->sel); - return 0; - } - if (selected && np->ncond) { - /* nstr_exec is expensive, so we do it last */ - if (!nstr_exec(np->cond, np->ncond, (s_char *)gp, np->type)) - selected = 0; - } - } while (!selected); - return (s_char *)gp; + selected = 1; + switch (np->sel) { + /* + * This one won't work unless you're running in emp_player + * + */ + case NS_LIST: + if ((np->flags & EFF_OWNER) && !owner) + selected = 0; + break; + case NS_ALL: + /* XXX maybe combine NS_LIST and NS_ALL later */ + break; + case NS_DIST: + if (!xyinrange(gp->x, gp->y, &np->range)) { + selected = 0; + break; + } + np->curdist = mapdist((int)gp->x, (int)gp->y, + (int)np->cx, (int)np->cy); + if (np->curdist > np->dist) + selected = 0; + break; + case NS_AREA: + if (!xyinrange(gp->x, gp->y, &np->range)) + selected = 0; + if (gp->x == np->range.hx || gp->y == np->range.hy) + selected = 0; + break; + case NS_XY: + if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy) + selected = 0; + break; + case NS_GROUP: + if (np->group != gp->group) + selected = 0; + break; + default: + logerror("nxtitemp: bad selector %d\n", np->sel); + return 0; + } + if (selected && np->ncond) { + /* nstr_exec is expensive, so we do it last */ + if (!nstr_exec(np->cond, np->ncond, (s_char *)gp, np->type)) + selected = 0; + } + } while (!selected); + return (s_char *)gp; } diff --git a/src/lib/update/nxtsctp.c b/src/lib/update/nxtsctp.c index fb9e7e923..22e3e2d37 100644 --- a/src/lib/update/nxtsctp.c +++ b/src/lib/update/nxtsctp.c @@ -48,29 +48,29 @@ struct sctstr * nxtsctp(register struct nstr_sect *np) { - while (1) { - np->dx++; - np->x++; - if (np->x >= WORLD_X) - np->x = 0; - if (np->dx >= np->range.width) { - np->dx = 0; - np->x = np->range.lx; - np->dy++; - if (np->dy >= np->range.height) - return (struct sctstr *)0; - np->y++; - if (np->y >= WORLD_Y) - np->y = 0; - } - if ((np->y + np->x) & 01) - continue; - if (np->type == NS_DIST) { - np->curdist = mapdist(np->x, np->y, np->cx, np->cy); - if (np->curdist > np->dist) - continue; - } - return(getsectp(np->x, np->y)); - } - /*NOTREACHED*/ + while (1) { + np->dx++; + np->x++; + if (np->x >= WORLD_X) + np->x = 0; + if (np->dx >= np->range.width) { + np->dx = 0; + np->x = np->range.lx; + np->dy++; + if (np->dy >= np->range.height) + return (struct sctstr *)0; + np->y++; + if (np->y >= WORLD_Y) + np->y = 0; + } + if ((np->y + np->x) & 01) + continue; + if (np->type == NS_DIST) { + np->curdist = mapdist(np->x, np->y, np->cx, np->cy); + if (np->curdist > np->dist) + continue; + } + return (getsectp(np->x, np->y)); + } + /*NOTREACHED*/ } diff --git a/src/lib/update/plague.c b/src/lib/update/plague.c index 6f0f24548..909f63fed 100644 --- a/src/lib/update/plague.c +++ b/src/lib/update/plague.c @@ -50,105 +50,104 @@ void do_plague(struct sctstr *sp, struct natstr *np, int etu) { - int vec[I_MAX+1]; - int cvec[I_MAX+1]; - int n; + int vec[I_MAX + 1]; + int cvec[I_MAX + 1]; + int n; - if (opt_NO_PLAGUE) /* no plague nothing to do */ - return; + if (opt_NO_PLAGUE) /* no plague nothing to do */ + return; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return; - if (getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR) <= 0) - bzero((s_char *)cvec, sizeof(cvec)); + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) + return; + if (getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR) <= 0) + bzero((s_char *)cvec, sizeof(cvec)); - if (cvec[C_PSTAGE] == 0) { - cvec[C_PSTAGE] = infect_people(np, vec, sp->sct_effic, - (int)sp->sct_mobil, sp); - cvec[C_PTIME] = 0; - } else { - n = plague_people(np, vec, cvec, etu); - switch (n) { - case PLG_DYING: - wu(0, sp->sct_own, "PLAGUE deaths reported in %s.\n", - ownxy(sp)); - nreport(sp->sct_own, N_DIE_PLAGUE, 0, 1); - break; - case PLG_INFECT: - wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp)); - break; - case PLG_INCUBATE: - /* Are we still incubating? */ - if (n == cvec[C_PSTAGE]) { - /* Yes. Will it turn "infectious" next time? */ - if (cvec[C_PTIME] <= etu) { - /* Yes. Report an outbreak. */ - wu(0, sp->sct_own, - "Outbreak of PLAGUE in %s!\n", - ownxy(sp)); - nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1); - } - } else { - /* It has already moved on to "infectious" */ - wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp)); - } - break; - case PLG_EXPOSED: - /* Has the plague moved to "incubation" yet? */ - if (n != cvec[C_PSTAGE]) { - /* Yes. Will it turn "infectious" next time? */ - if (cvec[C_PTIME] <= etu) { - /* Yes. Report an outbreak. */ - wu(0, sp->sct_own, - "Outbreak of PLAGUE in %s!\n", - ownxy(sp)); - nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1); - } - } - break; - default: - break; + if (cvec[C_PSTAGE] == 0) { + cvec[C_PSTAGE] = infect_people(np, vec, sp->sct_effic, + (int)sp->sct_mobil, sp); + cvec[C_PTIME] = 0; + } else { + n = plague_people(np, vec, cvec, etu); + switch (n) { + case PLG_DYING: + wu(0, sp->sct_own, "PLAGUE deaths reported in %s.\n", + ownxy(sp)); + nreport(sp->sct_own, N_DIE_PLAGUE, 0, 1); + break; + case PLG_INFECT: + wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp)); + break; + case PLG_INCUBATE: + /* Are we still incubating? */ + if (n == cvec[C_PSTAGE]) { + /* Yes. Will it turn "infectious" next time? */ + if (cvec[C_PTIME] <= etu) { + /* Yes. Report an outbreak. */ + wu(0, sp->sct_own, + "Outbreak of PLAGUE in %s!\n", ownxy(sp)); + nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1); } + } else { + /* It has already moved on to "infectious" */ + wu(0, sp->sct_own, "%s battling PLAGUE\n", ownxy(sp)); + } + break; + case PLG_EXPOSED: + /* Has the plague moved to "incubation" yet? */ + if (n != cvec[C_PSTAGE]) { + /* Yes. Will it turn "infectious" next time? */ + if (cvec[C_PTIME] <= etu) { + /* Yes. Report an outbreak. */ + wu(0, sp->sct_own, + "Outbreak of PLAGUE in %s!\n", ownxy(sp)); + nreport(sp->sct_own, N_OUT_PLAGUE, 0, 1); + } + } + break; + default: + break; } - if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && - !has_units(sp->sct_x,sp->sct_y,sp->sct_own,0)) { - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - } - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - putvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); + } + if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && + !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); + sp->sct_own = 0; + sp->sct_oldown = 0; + } + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + putvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); } /*ARGSUSED*/ int -infect_people(struct natstr *np, register int *vec, u_int eff, int mobil, struct sctstr *sp) +infect_people(struct natstr *np, register int *vec, u_int eff, int mobil, + struct sctstr *sp) { - double plg_num; - double plg_denom; - double plg_chance; - double civvies = 999.0; + double plg_num; + double plg_denom; + double plg_chance; + double civvies = 999.0; - if (opt_NO_PLAGUE) /* no plague nothing to do */ - return PLG_HEALTHY; + if (opt_NO_PLAGUE) /* no plague nothing to do */ + return PLG_HEALTHY; - if (np->nat_level[NAT_TLEV] <= 10.0) - return PLG_HEALTHY; + if (np->nat_level[NAT_TLEV] <= 10.0) + return PLG_HEALTHY; - if (opt_BIG_CITY && (sp->sct_type == SCT_CAPIT)) - civvies = 9999.0; + if (opt_BIG_CITY && (sp->sct_type == SCT_CAPIT)) + civvies = 9999.0; - /* - * make plague where there was none before... - */ - plg_num = ((vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]) / civvies) * - ((vec[I_IRON] + vec[I_OIL] + (vec[I_RAD] * 2)) / 10.0 + - np->nat_level[NAT_TLEV] + 100.0); - plg_denom = eff + mobil + 100 + np->nat_level[NAT_RLEV]; - plg_chance = ((plg_num / plg_denom) - 1.0) * 0.01; - if (chance(plg_chance)) - return PLG_EXPOSED; - return PLG_HEALTHY; + /* + * make plague where there was none before... + */ + plg_num = ((vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]) / civvies) * + ((vec[I_IRON] + vec[I_OIL] + (vec[I_RAD] * 2)) / 10.0 + + np->nat_level[NAT_TLEV] + 100.0); + plg_denom = eff + mobil + 100 + np->nat_level[NAT_RLEV]; + plg_chance = ((plg_num / plg_denom) - 1.0) * 0.01; + if (chance(plg_chance)) + return PLG_EXPOSED; + return PLG_HEALTHY; } /* @@ -158,43 +157,44 @@ infect_people(struct natstr *np, register int *vec, u_int eff, int mobil, struct * stage. No reports generated here anymore. */ int -plague_people(struct natstr *np, register int *vec, register int *cvec, int etus) +plague_people(struct natstr *np, register int *vec, register int *cvec, + int etus) { - int stage; - double plg_num; - double plg_denom; - double pct_left; + int stage; + double plg_num; + double plg_denom; + double pct_left; - if (opt_NO_PLAGUE) /* no plague nothing to do */ - return PLG_HEALTHY; - cvec[C_PTIME] -= etus; - stage = cvec[C_PSTAGE]; - switch (stage) { - case PLG_DYING: - plg_num = 100.0 * etus; - plg_denom = (np->nat_level[NAT_RLEV] + 100.0) * - (vec[C_PTIME] + etus + 1.0); - pct_left = 1.0 - (double)(plg_num / plg_denom); - if (pct_left < 0.2) - pct_left = 0.2; - vec[I_CIVIL] = vec[I_CIVIL] * pct_left; - vec[I_MILIT] = vec[I_MILIT] * pct_left; - vec[I_UW] = vec[I_UW] * pct_left; - break; - case PLG_INFECT: - case PLG_INCUBATE: - break; - case PLG_EXPOSED: - cvec[C_PTIME] = 0; - break; - default: - /* bad */ - cvec[C_PTIME] = 0; - break; - } - if (cvec[C_PTIME] <= 0) { - cvec[C_PSTAGE]--; - cvec[C_PTIME] = (etus / 2) + (random() % etus); - } - return stage; + if (opt_NO_PLAGUE) /* no plague nothing to do */ + return PLG_HEALTHY; + cvec[C_PTIME] -= etus; + stage = cvec[C_PSTAGE]; + switch (stage) { + case PLG_DYING: + plg_num = 100.0 * etus; + plg_denom = (np->nat_level[NAT_RLEV] + 100.0) * + (vec[C_PTIME] + etus + 1.0); + pct_left = 1.0 - (double)(plg_num / plg_denom); + if (pct_left < 0.2) + pct_left = 0.2; + vec[I_CIVIL] = vec[I_CIVIL] * pct_left; + vec[I_MILIT] = vec[I_MILIT] * pct_left; + vec[I_UW] = vec[I_UW] * pct_left; + break; + case PLG_INFECT: + case PLG_INCUBATE: + break; + case PLG_EXPOSED: + cvec[C_PTIME] = 0; + break; + default: + /* bad */ + cvec[C_PTIME] = 0; + break; + } + if (cvec[C_PTIME] <= 0) { + cvec[C_PSTAGE]--; + cvec[C_PTIME] = (etus / 2) + (random() % etus); + } + return stage; } diff --git a/src/lib/update/plane.c b/src/lib/update/plane.c index f05f63c6c..dd0fcac48 100644 --- a/src/lib/update/plane.c +++ b/src/lib/update/plane.c @@ -54,229 +54,225 @@ int prod_plane(int etus, int natnum, int *bp, int buildem) - - - - /* Build = 1, maintain =0 */ + + + + /* Build = 1, maintain =0 */ { - extern double money_mil; - extern double money_plane; - extern int plane_grow_scale; - extern long air_money[MAXNOC]; - register struct plnstr *pp; - register struct plchrstr *plp; - struct natstr *np; - float leftp, buildp; - int left, build; - int lcm_needed,hcm_needed; - int mil_needed; - int svec[I_MAX+1]; - int mvec[I_MAX+1]; - int n, k=0; - struct shpstr *shp; - struct plchrstr *desc; - struct sctstr *sp; - int delta; - int mult; - int cost; - int eff; - int avail; - int w_p_eff; - int used; - int start_money, onship=0; + extern double money_mil; + extern double money_plane; + extern int plane_grow_scale; + extern long air_money[MAXNOC]; + register struct plnstr *pp; + register struct plchrstr *plp; + struct natstr *np; + float leftp, buildp; + int left, build; + int lcm_needed, hcm_needed; + int mil_needed; + int svec[I_MAX + 1]; + int mvec[I_MAX + 1]; + int n, k = 0; + struct shpstr *shp; + struct plchrstr *desc; + struct sctstr *sp; + int delta; + int mult; + int cost; + int eff; + int avail; + int w_p_eff; + int used; + int start_money, onship = 0; + + for (n = 0; NULL != (pp = getplanep(n)); n++) { + if (pp->pln_own == 0) + continue; + if (pp->pln_own != natnum) + continue; + if (pp->pln_effic < PLANE_MINEFF) { + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, + pp->pln_x, pp->pln_y); + pp->pln_own = 0; + continue; + } + + plp = &plchr[(int)pp->pln_type]; + if (pp->pln_flags & PLN_LAUNCHED) { + if (opt_ORBIT && (buildem == 0)) { + if ((!player->simulation) && + (plp->pl_flags & P_O) && + (pp->pln_flags & PLN_LAUNCHED) && + !(plp->pl_flags & P_M) && + !(pp->pln_flags & PLN_SYNCHRONOUS)) + move_sat(pp); + } + continue; + } + + onship = 0; + shp = (struct shpstr *)0; + if (pp->pln_ship >= 0 && (buildem == 1)) { + if (pp->pln_effic >= 80) + continue; + onship = 1; + shp = getshipp(pp->pln_ship); + if (shp == 0 || shp->shp_own != pp->pln_own) { + /* nplane is unsigned... */ + if (shp->shp_nplane > 0) + shp->shp_nplane--; + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); + pp->pln_own = 0; + continue; + } + } + np = getnatp(pp->pln_own); + desc = &plchr[(int)pp->pln_type]; + sp = getsectp(pp->pln_x, pp->pln_y); + getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); + mult = 1; + if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85) + mult = 2; - for (n=0; NULL != (pp = getplanep(n)); n++) { - if (pp->pln_own == 0) - continue; - if (pp->pln_own != natnum) - continue; - if (pp->pln_effic < PLANE_MINEFF) { - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, - pp->pln_x, pp->pln_y); + if (buildem == 0) { + /* flight pay is 5x the pay received by other military */ + start_money = np->nat_money; + cost = -(mult * etus * dmin(0.0, desc->pl_cost * money_plane)); + if ((np->nat_priorities[PRI_PMAINT] == 0 || + np->nat_money < cost) && !player->simulation) { + if ((eff = pp->pln_effic - etus / 5) < PLANE_MINEFF) { + wu(0, pp->pln_own, + "%s lost to lack of maintenance\n", prplane(pp)); + makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, + pp->pln_y); pp->pln_own = 0; continue; } + wu(0, pp->pln_own, + "%s lost %d%% to lack of maintenance\n", + prplane(pp), pp->pln_effic - eff); + pp->pln_effic = eff; + } else { + np->nat_money -= cost; + } - plp = &plchr[(int)pp->pln_type]; - if (pp->pln_flags & PLN_LAUNCHED) { - if (opt_ORBIT && (buildem == 0)) { - if ((!player->simulation) && - (plp->pl_flags & P_O) && - (pp->pln_flags & PLN_LAUNCHED) && - !(plp->pl_flags & P_M) && - !(pp->pln_flags & PLN_SYNCHRONOUS)) - move_sat(pp); - } - continue; - } + np->nat_money += (etus * plp->pl_crew * money_mil * 5); - onship = 0; - shp = (struct shpstr *)0; - if (pp->pln_ship >= 0 && (buildem == 1)) { - if (pp->pln_effic >= 80) - continue; - onship = 1; - shp = getshipp(pp->pln_ship); - if (shp == 0 || shp->shp_own != pp->pln_own) { - /* nplane is unsigned... */ - if (shp->shp_nplane > 0) - shp->shp_nplane --; - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - continue; - } - } - np = getnatp(pp->pln_own); - desc = &plchr[(int)pp->pln_type]; - sp = getsectp(pp->pln_x, pp->pln_y); - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - mult=1; - if (np->nat_level[NAT_TLEV] < pp->pln_tech * 0.85) - mult = 2; + air_money[pp->pln_own] += np->nat_money - start_money; + k++; + if (player->simulation) + np->nat_money = start_money; + if ((pp->pln_flags & PLN_LAUNCHED) == PLN_LAUNCHED) + continue; + } else { + if (sp->sct_off) + continue; + if (np->nat_priorities[PRI_PBUILD] == 0 || np->nat_money < 0) + continue; - if (buildem == 0) { - /* flight pay is 5x the pay received by other military */ - start_money = np->nat_money; - cost = -(mult * etus * - dmin(0.0, desc->pl_cost * money_plane)); - if ((np->nat_priorities[PRI_PMAINT] == 0 || - np->nat_money < cost) && !player->simulation) { - if ((eff = pp->pln_effic - etus/5) < PLANE_MINEFF) { - wu(0, pp->pln_own, - "%s lost to lack of maintenance\n", - prplane(pp)); - makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y); - pp->pln_own = 0; - continue; - } - wu(0, pp->pln_own, - "%s lost %d%% to lack of maintenance\n", - prplane(pp), pp->pln_effic - eff); - pp->pln_effic = eff; - } else { - np->nat_money -= cost; - } - - np->nat_money += (etus * plp->pl_crew * money_mil * 5); + start_money = np->nat_money; + left = 100 - pp->pln_effic; + if (left <= 0) + continue; - air_money[pp->pln_own] += np->nat_money - start_money; - k++; - if (player->simulation) - np->nat_money = start_money; - if ((pp->pln_flags & PLN_LAUNCHED) == PLN_LAUNCHED) - continue; - }else{ - if (sp->sct_off) - continue; - if (np->nat_priorities[PRI_PBUILD] == 0 || - np->nat_money < 0) - continue; + if (!player->simulation) + avail = sp->sct_avail * 100; + else + avail = gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; - start_money = np->nat_money; - left = 100 - pp->pln_effic; - if (left <= 0) - continue; + if (pp->pln_ship >= 0) { + int vec[I_MAX + 1]; + shp = getshipp(pp->pln_ship); + getvec(VT_ITEM, vec, (s_char *)shp, EF_SHIP); + avail += (etus * vec[I_MILIT] / 2); + } + w_p_eff = 20 + (desc->pl_lcm + 2 * desc->pl_hcm); + delta = roundavg((double)avail / w_p_eff); + if (delta <= 0) + continue; + if (delta > etus * plane_grow_scale) + delta = etus * plane_grow_scale; + if (delta > left) + delta = left; - if (!player->simulation) - avail = sp->sct_avail * 100; - else - avail = gt_bg_nmbr(bp, sp, I_MAX+1) * 100; + /* delta is the max amount we can grow */ - if (pp->pln_ship >= 0) { - int vec[I_MAX+1]; - shp = getshipp(pp->pln_ship); - getvec(VT_ITEM, vec, (s_char *)shp, EF_SHIP); - avail += (etus * vec[I_MILIT]/2); - } - w_p_eff = 20 + (desc->pl_lcm + 2 * desc->pl_hcm); - delta = roundavg((double)avail/w_p_eff); - if (delta <= 0) - continue; - if (delta > etus*plane_grow_scale) - delta = etus*plane_grow_scale; - if (delta > left) - delta = left; + left = 100 - pp->pln_effic; + if (left > delta) + left = delta; - /* delta is the max amount we can grow */ + leftp = ((float)left / 100.0); + bzero((s_char *)mvec, sizeof(mvec)); + mvec[I_MILIT] = mil_needed = + ldround((double)(plp->pl_crew * leftp), 1); + mvec[I_LCM] = lcm_needed = + ldround((double)(plp->pl_lcm * leftp), 1); + mvec[I_HCM] = hcm_needed = + ldround((double)(plp->pl_hcm * leftp), 1); - left = 100 - pp->pln_effic; - if (left > delta) - left = delta; + get_materials(sp, bp, mvec, 0); - leftp = ((float)left/100.0); - bzero((s_char *)mvec, sizeof(mvec)); - mvec[I_MILIT] = mil_needed = - ldround((double)(plp->pl_crew * leftp),1); - mvec[I_LCM] = lcm_needed = - ldround((double)(plp->pl_lcm * leftp),1); - mvec[I_HCM] = hcm_needed = - ldround((double)(plp->pl_hcm * leftp),1); + if (mvec[I_MILIT] >= mil_needed) + buildp = leftp; + else + buildp = ((float)mvec[I_MILIT] / (float)plp->pl_crew); - get_materials(sp, bp, mvec, 0); - - if (mvec[I_MILIT]>=mil_needed) - buildp=leftp; - else - buildp=((float)mvec[I_MILIT]/(float)plp->pl_crew); - - if (mvec[I_LCM] < lcm_needed) - buildp = MIN(buildp,((float)mvec[I_LCM]/ - (float)plp->pl_lcm)); + if (mvec[I_LCM] < lcm_needed) + buildp = MIN(buildp, ((float)mvec[I_LCM] / + (float)plp->pl_lcm)); - if (mvec[I_HCM] < hcm_needed) - buildp = MIN(buildp,((float)mvec[I_HCM]/ - (float)plp->pl_hcm)); + if (mvec[I_HCM] < hcm_needed) + buildp = MIN(buildp, ((float)mvec[I_HCM] / + (float)plp->pl_hcm)); - build=ldround((double)(buildp*100.0),1); - bzero((s_char *)mvec, sizeof(mvec)); - mvec[I_MILIT] = mil_needed = - roundavg((double)(plp->pl_crew * buildp)); - mvec[I_LCM] = lcm_needed = - roundavg((double)(plp->pl_lcm * buildp)); - mvec[I_HCM] = hcm_needed = - roundavg((double)(plp->pl_hcm * buildp)); + build = ldround((double)(buildp * 100.0), 1); + bzero((s_char *)mvec, sizeof(mvec)); + mvec[I_MILIT] = mil_needed = + roundavg((double)(plp->pl_crew * buildp)); + mvec[I_LCM] = lcm_needed = + roundavg((double)(plp->pl_lcm * buildp)); + mvec[I_HCM] = hcm_needed = + roundavg((double)(plp->pl_hcm * buildp)); - get_materials(sp, bp, mvec, 1); + get_materials(sp, bp, mvec, 1); - if (onship) build = delta; - used = build * w_p_eff; + if (onship) + build = delta; + used = build * w_p_eff; - /* - * I didn't use roundavg here, because I want to - * penalize the player with a large number of planes. - */ - if (!player->simulation) - avail = (sp->sct_avail * 100 - used) / 100; - else - avail = (gt_bg_nmbr(bp,sp,I_MAX+1) *100 -used) / 100; + /* + * I didn't use roundavg here, because I want to + * penalize the player with a large number of planes. + */ + if (!player->simulation) + avail = (sp->sct_avail * 100 - used) / 100; + else + avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 100 - used) / 100; - if (avail < 0) - avail = 0; - if (!player->simulation) - sp->sct_avail = avail; - else - pt_bg_nmbr(bp,sp,I_MAX+1,avail); + if (avail < 0) + avail = 0; + if (!player->simulation) + sp->sct_avail = avail; + else + pt_bg_nmbr(bp, sp, I_MAX + 1, avail); - if (sp->sct_type != SCT_AIRPT) - build /= 3; - if (onship){ - if ((pp->pln_effic + build) > 80) - build = 80- pp ->pln_effic; - } - np->nat_money -= roundavg(mult * build * - desc->pl_cost / 100.0); - air_money[pp->pln_own] += np->nat_money - start_money; - - if (!player->simulation) - pp->pln_effic += (s_char)build; - else - np->nat_money = start_money; - k++; - } + if (sp->sct_type != SCT_AIRPT) + build /= 3; + if (onship) { + if ((pp->pln_effic + build) > 80) + build = 80 - pp->pln_effic; + } + np->nat_money -= roundavg(mult * build * + desc->pl_cost / 100.0); + air_money[pp->pln_own] += np->nat_money - start_money; + + if (!player->simulation) + pp->pln_effic += (s_char)build; + else + np->nat_money = start_money; + k++; } - return k; + } + return k; } - - - - diff --git a/src/lib/update/populace.c b/src/lib/update/populace.c index a2cbee46c..e4623dbff 100644 --- a/src/lib/update/populace.c +++ b/src/lib/update/populace.c @@ -49,93 +49,95 @@ #include "lost.h" void -populace(struct natstr *np, register struct sctstr *sp, register int *vec, int etu) +populace(struct natstr *np, register struct sctstr *sp, register int *vec, + int etu) { - float hap; - float tech; - float edu; - float pct; - int n; + float hap; + float tech; + float edu; + float pct; + int n; - if (vec[I_CIVIL] == 0 && vec[I_MILIT] > 0) { - sp->sct_work = 100; - sp->sct_loyal = 0; - sp->sct_oldown = sp->sct_own; - } - if (!vec[I_CIVIL] && !vec[I_MILIT] && !vec[I_UW] && - !has_units(sp->sct_x,sp->sct_y,sp->sct_own,0)) { - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - return; - } - if (sp->sct_own != sp->sct_oldown && sp->sct_loyal == 0) { - sp->sct_oldown = sp->sct_own; - } + if (vec[I_CIVIL] == 0 && vec[I_MILIT] > 0) { + sp->sct_work = 100; + sp->sct_loyal = 0; + sp->sct_oldown = sp->sct_own; + } + if (!vec[I_CIVIL] && !vec[I_MILIT] && !vec[I_UW] && + !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); + sp->sct_own = 0; + sp->sct_oldown = 0; + return; + } + if (sp->sct_own != sp->sct_oldown && sp->sct_loyal == 0) { + sp->sct_oldown = sp->sct_own; + } - hap = np->nat_level[NAT_HLEV]; - edu = np->nat_level[NAT_ELEV]; - tech = np->nat_level[NAT_TLEV]; - pct = (double)((tech - 40) / 40.0 + edu / 3.0); - if (sp->sct_own == sp->sct_oldown && hap < pct && - chance((double)(((double)pct-(double)hap)/(double)5.0))) { - /* - * zap the loyalty of unhappy civilians. - * there is a 20% chance per hap point below the - * "recommended" amount of this happening. - */ - n = roundavg(etu * 0.125); - if (n == 0) n = 1; - n = sp->sct_loyal + (random() % n) + 1; - if (n > 127) - n = 127; - sp->sct_loyal = n; - } - if (sp->sct_loyal > 65 && vec[I_MILIT] < vec[I_CIVIL]/20) { - int work_red; + hap = np->nat_level[NAT_HLEV]; + edu = np->nat_level[NAT_ELEV]; + tech = np->nat_level[NAT_TLEV]; + pct = (double)((tech - 40) / 40.0 + edu / 3.0); + if (sp->sct_own == sp->sct_oldown && hap < pct && + chance((double)(((double)pct - (double)hap) / (double)5.0))) { + /* + * zap the loyalty of unhappy civilians. + * there is a 20% chance per hap point below the + * "recommended" amount of this happening. + */ + n = roundavg(etu * 0.125); + if (n == 0) + n = 1; + n = sp->sct_loyal + (random() % n) + 1; + if (n > 127) + n = 127; + sp->sct_loyal = n; + } + if (sp->sct_loyal > 65 && vec[I_MILIT] < vec[I_CIVIL] / 20) { + int work_red; - work_red = sp->sct_loyal - (50 + (random() % 15)); - n = sp->sct_work - work_red; - if (n < 0) - n = 0; - sp->sct_work = n; - if (chance((double)work_red/1000.0)) { - /* - * small chance of rebellion... - * if work_red is (max) 67, - * then revolt chance is 6.7% - */ - revolt(sp); - } else if (chance(.30) && sp->sct_own) - wu(0, sp->sct_own, "Civil unrest in %s!\n", ownxy(sp)); - } - if (sp->sct_loyal) { - n = sp->sct_loyal; - if (chance(0.75)) - n -= roundavg(etu * 0.25); - else - n += roundavg(etu * 0.125); - if (n < 0) - n = 0; - else if (n > 127) - n = 127; - sp->sct_loyal = n; - if (sp->sct_loyal == 0) { - if (sp->sct_oldown != sp->sct_own) { - wu(0, sp->sct_own, - "Sector %s is now fully yours\n", - ownxy(sp)); - sp->sct_oldown = sp->sct_own; - } - sp->sct_loyal = 0; - } + work_red = sp->sct_loyal - (50 + (random() % 15)); + n = sp->sct_work - work_red; + if (n < 0) + n = 0; + sp->sct_work = n; + if (chance((double)work_red / 1000.0)) { + /* + * small chance of rebellion... + * if work_red is (max) 67, + * then revolt chance is 6.7% + */ + revolt(sp); + } else if (chance(.30) && sp->sct_own) + wu(0, sp->sct_own, "Civil unrest in %s!\n", ownxy(sp)); + } + if (sp->sct_loyal) { + n = sp->sct_loyal; + if (chance(0.75)) + n -= roundavg(etu * 0.25); + else + n += roundavg(etu * 0.125); + if (n < 0) + n = 0; + else if (n > 127) + n = 127; + sp->sct_loyal = n; + if (sp->sct_loyal == 0) { + if (sp->sct_oldown != sp->sct_own) { + wu(0, sp->sct_own, + "Sector %s is now fully yours\n", ownxy(sp)); + sp->sct_oldown = sp->sct_own; + } + sp->sct_loyal = 0; } - return; + } + return; } int -total_work(register int sctwork, register int etu, register int civil, register int milit, register int uw) +total_work(register int sctwork, register int etu, register int civil, + register int milit, register int uw) { - return ((int)((((civil * sctwork) / 100.0 + - (milit * 2 / 5.0) + uw)) * etu) / 100); + return ((int)((((civil * sctwork) / 100.0 + + (milit * 2 / 5.0) + uw)) * etu) / 100); } diff --git a/src/lib/update/prepare.c b/src/lib/update/prepare.c index 742b86cb4..677b83c0a 100644 --- a/src/lib/update/prepare.c +++ b/src/lib/update/prepare.c @@ -52,99 +52,101 @@ #include "gen.h" #include "common.h" -extern float levels[MAXNOC][4]; +extern float levels[MAXNOC][4]; void prepare_sects(int etu, int *bp) { - extern long pops[]; - register struct sctstr *sp; - struct natstr *np; - int n, civ_tax, uw_tax, mil_pay; + extern long pops[]; + register struct sctstr *sp; + struct natstr *np; + int n, civ_tax, uw_tax, mil_pay; - bzero((s_char *)levels, sizeof(levels)); + bzero((s_char *)levels, sizeof(levels)); /* Process all the fallout. */ - if (opt_FALLOUT) { - if (!player->simulation) { + if (opt_FALLOUT) { + if (!player->simulation) { /* First, we determine which sectors to process fallout in */ for (n = 0; NULL != (sp = getsectid(n)); n++) { - if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR)) - sp->sct_updated = 1; - else - sp->sct_updated = 0; + if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR)) + sp->sct_updated = 1; + else + sp->sct_updated = 0; } /* Next, we process the fallout there */ for (n = 0; NULL != (sp = getsectid(n)); n++) - if (sp->sct_updated) - do_fallout(sp, etu); + if (sp->sct_updated) + do_fallout(sp, etu); /* Next, we spread the fallout */ for (n = 0; NULL != (sp = getsectid(n)); n++) - if (sp->sct_updated) - spread_fallout(sp, etu); + if (sp->sct_updated) + spread_fallout(sp, etu); /* Next, we decay the fallout */ for (n = 0; NULL != (sp = getsectid(n)); n++) - if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR)) - decay_fallout(sp, etu); - } + if (getvar(V_FALLOUT, (s_char *)sp, EF_SECTOR)) + decay_fallout(sp, etu); } - for (n=0; NULL != (sp = getsectid(n)); n++) { - sp->sct_updated = 0; + } + for (n = 0; NULL != (sp = getsectid(n)); n++) { + sp->sct_updated = 0; - if (sp->sct_type == SCT_WATER) - continue; - fill_update_array(bp, sp); - np = getnatp(sp->sct_own); + if (sp->sct_type == SCT_WATER) + continue; + fill_update_array(bp, sp); + np = getnatp(sp->sct_own); #ifdef DEBUG - if (np->nat_stat & STAT_SANCT) - logerror("Prepare.c: country in sanctuary skipped production"); -#endif /* DEBUG */ - - if (!(np->nat_stat & STAT_SANCT)){ - guerrilla(sp); - do_plague(sp, np, etu); - tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax, &mil_pay); - np->nat_money += civ_tax + uw_tax + mil_pay; - if (sp->sct_type == SCT_BANK) - np->nat_money += bank_income(sp, etu); - } - } - for (n=0; NULL != (np = getnatp(n)); n++) { - np->nat_money += upd_slmilcosts(np->nat_cnum, etu); + if (np->nat_stat & STAT_SANCT) + logerror("Prepare.c: country in sanctuary skipped production"); +#endif /* DEBUG */ + + if (!(np->nat_stat & STAT_SANCT)) { + guerrilla(sp); + do_plague(sp, np, etu); + tax(sp, np, etu, &pops[sp->sct_own], &civ_tax, &uw_tax, + &mil_pay); + np->nat_money += civ_tax + uw_tax + mil_pay; + if (sp->sct_type == SCT_BANK) + np->nat_money += bank_income(sp, etu); } + } + for (n = 0; NULL != (np = getnatp(n)); n++) { + np->nat_money += upd_slmilcosts(np->nat_cnum, etu); + } } void -tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax, int *uw_tax, int *mil_pay) +tax(struct sctstr *sp, struct natstr *np, int etu, long *pop, int *civ_tax, + int *uw_tax, int *mil_pay) { - int vec[I_MAX+1]; - extern double money_civ, money_mil, money_uw; - - *civ_tax = 0; - *uw_tax = 0; - *mil_pay = 0; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return; - - if (!player->simulation) - populace(np, sp, vec, etu); - *civ_tax = (int)(0.5 + vec[I_CIVIL] * sp->sct_effic * - etu * money_civ / 100); - /* - * captured civs only pay 1/4 taxes - */ - if (sp->sct_own != sp->sct_oldown) - *civ_tax = *civ_tax / 4; - *uw_tax = (int)(0.5 + vec[I_UW] * sp->sct_effic * - etu * money_uw / 100); - *mil_pay = vec[I_MILIT] * etu * money_mil; - - /* - * only non-captured civs add to census for nation - */ - if (sp->sct_oldown == sp->sct_own) - *pop += vec[I_CIVIL]; + int vec[I_MAX + 1]; + extern double money_civ, money_mil, money_uw; + + *civ_tax = 0; + *uw_tax = 0; + *mil_pay = 0; + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) + return; + + if (!player->simulation) + populace(np, sp, vec, etu); + *civ_tax = (int)(0.5 + vec[I_CIVIL] * sp->sct_effic * + etu * money_civ / 100); + /* + * captured civs only pay 1/4 taxes + */ + if (sp->sct_own != sp->sct_oldown) + *civ_tax = *civ_tax / 4; + *uw_tax = (int)(0.5 + vec[I_UW] * sp->sct_effic * + etu * money_uw / 100); + *mil_pay = vec[I_MILIT] * etu * money_mil; + + /* + * only non-captured civs add to census for nation + */ + if (sp->sct_oldown == sp->sct_own) + *pop += vec[I_CIVIL]; } int @@ -177,11 +179,11 @@ upd_slmilcosts(natid n, int etu) int bank_income(struct sctstr *sp, int etu) { - extern double bankint; - int vec[I_MAX+1]; + extern double bankint; + int vec[I_MAX + 1]; - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return 0; - else - return (int)(vec[I_BAR] * etu * bankint * sp->sct_effic / 100); + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) + return 0; + else + return (int)(vec[I_BAR] * etu * bankint * sp->sct_effic / 100); } diff --git a/src/lib/update/produce.c b/src/lib/update/produce.c index e618a232b..f3eb61bac 100644 --- a/src/lib/update/produce.c +++ b/src/lib/update/produce.c @@ -45,193 +45,196 @@ #include "common.h" #include "optlist.h" -s_char *levelnames[] = { "Technology", "Research", "Education", "Happiness" }; +s_char *levelnames[] = + { "Technology", "Research", "Education", "Happiness" }; int -produce(struct natstr *np, struct sctstr *sp, int *vec, int work, int sctwork, int desig, int neweff, int *cost, int *amount) +produce(struct natstr *np, struct sctstr *sp, int *vec, int work, + int sctwork, int desig, int neweff, int *cost, int *amount) { - extern float levels[MAXNOC][4]; - extern long tpops[]; - register struct pchrstr *product; - int vtype; - double p_e; - double level_p_e; - s_char *resource; - int output; - int actual; - int unit_work; - double depend; - int item; - int worker_limit; - int material_limit; - int material_consume; - int val; + extern float levels[MAXNOC][4]; + extern long tpops[]; + register struct pchrstr *product; + int vtype; + double p_e; + double level_p_e; + s_char *resource; + int output; + int actual; + int unit_work; + double depend; + int item; + int worker_limit; + int material_limit; + int material_consume; + int val; - product = &pchr[dchr[desig].d_prd]; - if (product == &pchr[0]) - return 0; - vtype = product->p_type; - item = vtype &~ VT_ITEM; - *amount = 0; - *cost = 0; + product = &pchr[dchr[desig].d_prd]; + if (product == &pchr[0]) + return 0; + vtype = product->p_type; + item = vtype & ~VT_ITEM; + *amount = 0; + *cost = 0; - if ((material_limit = materials_cost(product, vec, &unit_work)) <= 0) - return 0; - /* - * calculate production efficiency. - */ - p_e = neweff / 100.0; - if (product->p_nrndx != 0) { - unit_work++; - resource = ((s_char *) sp) + product->p_nrndx; - p_e = (*resource * p_e) / 100.0; - if (product->p_nrdep > 0) { - /* XXX this looks way wrong */ - depend = (*resource * 100.0) / product->p_nrdep; - if (p_e > depend) - p_e = depend; - } + if ((material_limit = materials_cost(product, vec, &unit_work)) <= 0) + return 0; + /* + * calculate production efficiency. + */ + p_e = neweff / 100.0; + if (product->p_nrndx != 0) { + unit_work++; + resource = ((s_char *)sp) + product->p_nrndx; + p_e = (*resource * p_e) / 100.0; + if (product->p_nrdep > 0) { + /* XXX this looks way wrong */ + depend = (*resource * 100.0) / product->p_nrdep; + if (p_e > depend) + p_e = depend; } - /* - * determine number that can be made with - * the available workforce - */ - if (unit_work == 0) - unit_work = 1; - material_consume = material_limit; - worker_limit = roundavg(work * p_e / unit_work); - if (material_consume > worker_limit) - material_consume = worker_limit; - if (material_consume == 0) - return 0; - level_p_e = 1.0; - if (product->p_nlndx >= 0) { - level_p_e = np->nat_level[product->p_nlndx] - product->p_nlmin; - if ((level_p_e < 0.0) && (!player->simulation)) { - wu(0, sp->sct_own, - "%s level too low to produce in %s (need %d)\n", - levelnames[product->p_nlndx], ownxy(sp), - product->p_nlmin); - return 0; - } - level_p_e = level_p_e / (level_p_e + product->p_nllag); + } + /* + * determine number that can be made with + * the available workforce + */ + if (unit_work == 0) + unit_work = 1; + material_consume = material_limit; + worker_limit = roundavg(work * p_e / unit_work); + if (material_consume > worker_limit) + material_consume = worker_limit; + if (material_consume == 0) + return 0; + level_p_e = 1.0; + if (product->p_nlndx >= 0) { + level_p_e = np->nat_level[product->p_nlndx] - product->p_nlmin; + if ((level_p_e < 0.0) && (!player->simulation)) { + wu(0, sp->sct_own, + "%s level too low to produce in %s (need %d)\n", + levelnames[product->p_nlndx], ownxy(sp), product->p_nlmin); + return 0; } - /* - * Adjust produced amount by commodity production ratio - */ - output = roundavg(product->p_effic * 0.01 * material_consume); - if ((vtype == 0) && (!player->simulation)) { - levels[sp->sct_own][product->p_level] += output * level_p_e; - wu((natid)0, sp->sct_own, "%s (%.2f) produced in %s\n", - product->p_name, output * level_p_e, ownxy(sp)); - } else { - if ((actual = roundavg(level_p_e * output)) <= 0) - return 0; - if (product->p_nrdep != 0) { - if(*resource*100 < product->p_nrdep*actual) - actual = *resource*100/product->p_nrdep; - } - if (actual > 999) { - actual = 999; - material_consume = (int)(actual / (product->p_effic * 0.01)); - } - vec[item] += actual; - if (vec[item] > 9999) { - material_consume = - roundavg((9999.0 - vec[item] + actual) * - material_consume / actual); - if (material_consume < 0) - material_consume = 0; - vec[item] = 9999; - if ((/* vtype != V_FOOD && */ sp->sct_own) && - (!player->simulation)) - wu(0, sp->sct_own, - "%s production backlog in %s\n", - product->p_name, ownxy(sp)); - } + level_p_e = level_p_e / (level_p_e + product->p_nllag); + } + /* + * Adjust produced amount by commodity production ratio + */ + output = roundavg(product->p_effic * 0.01 * material_consume); + if ((vtype == 0) && (!player->simulation)) { + levels[sp->sct_own][product->p_level] += output * level_p_e; + wu((natid)0, sp->sct_own, "%s (%.2f) produced in %s\n", + product->p_name, output * level_p_e, ownxy(sp)); + } else { + if ((actual = roundavg(level_p_e * output)) <= 0) + return 0; + if (product->p_nrdep != 0) { + if (*resource * 100 < product->p_nrdep * actual) + actual = *resource * 100 / product->p_nrdep; } - /* - * Reset produced amount by commodity production ratio - */ - if (!player->simulation) { - materials_charge(product, vec, material_consume); - if (product->p_nrdep != 0) { - /* - * lower natural resource in sector depending on - * amount produced - */ - val = *resource - roundavg(product->p_nrdep * - material_consume / 100.0); - if (val < 0) - val = 0; - *resource = val; - } + if (actual > 999) { + actual = 999; + material_consume = (int)(actual / (product->p_effic * 0.01)); } - *amount = actual; - *cost = product->p_cost * material_consume; - - if (opt_TECH_POP) { - if (product->p_level == NAT_TLEV) { - if (tpops[sp->sct_own] > 50000) - *cost = (double)*cost * (double)tpops[sp->sct_own] / 50000.0; - } + vec[item] += actual; + if (vec[item] > 9999) { + material_consume = + roundavg((9999.0 - vec[item] + actual) * + material_consume / actual); + if (material_consume < 0) + material_consume = 0; + vec[item] = 9999; + if (( /* vtype != V_FOOD && */ sp->sct_own) && + (!player->simulation)) + wu(0, sp->sct_own, + "%s production backlog in %s\n", + product->p_name, ownxy(sp)); + } + } + /* + * Reset produced amount by commodity production ratio + */ + if (!player->simulation) { + materials_charge(product, vec, material_consume); + if (product->p_nrdep != 0) { + /* + * lower natural resource in sector depending on + * amount produced + */ + val = *resource - roundavg(product->p_nrdep * + material_consume / 100.0); + if (val < 0) + val = 0; + *resource = val; } + } + *amount = actual; + *cost = product->p_cost * material_consume; - /* The min() here is to take care of integer rounding errors */ - if (p_e > 0.0) { - return min(work, (int)(unit_work * material_consume / p_e)); + if (opt_TECH_POP) { + if (product->p_level == NAT_TLEV) { + if (tpops[sp->sct_own] > 50000) + *cost = + (double)*cost * (double)tpops[sp->sct_own] / 50000.0; } - return 0; + } + + /* The min() here is to take care of integer rounding errors */ + if (p_e > 0.0) { + return min(work, (int)(unit_work * material_consume / p_e)); + } + return 0; } int materials_cost(struct pchrstr *product, register int *vec, int *costp) { - register u_char *vp; - register u_short *ap; - register int count; - register int cost; - register int n; - register u_char *endp; + register u_char *vp; + register u_short *ap; + register int count; + register int cost; + register int n; + register u_char *endp; - count = 9999; - cost = 0; - ap = product->p_vamt; - endp = product->p_vtype + product->p_nv; - for (vp = product->p_vtype; vp < endp; vp++, ap++) { - if (!*ap) - continue; - n = vec[*vp & ~VT_ITEM] / *ap; - if (n < count) - count = n; - cost += *ap; - } - *costp = cost; - return count; + count = 9999; + cost = 0; + ap = product->p_vamt; + endp = product->p_vtype + product->p_nv; + for (vp = product->p_vtype; vp < endp; vp++, ap++) { + if (!*ap) + continue; + n = vec[*vp & ~VT_ITEM] / *ap; + if (n < count) + count = n; + cost += *ap; + } + *costp = cost; + return count; } void -materials_charge(struct pchrstr *product, register int *vec, register int count) +materials_charge(struct pchrstr *product, register int *vec, + register int count) { - register u_char *vp; - register u_short *ap; - register u_char *endp; - register int item; - register int n; + register u_char *vp; + register u_short *ap; + register u_char *endp; + register int item; + register int n; - ap = product->p_vamt; - endp = product->p_vtype + product->p_nv; - for (vp = product->p_vtype; vp < endp; vp++, ap++) { - item = *vp & ~VT_ITEM; - if (item < 0 || item > I_MAX) { - logerror("materials_charge: bad item %d", item); - continue; - } - if ((n = vec[item] - *ap * count) < 0) { - logerror("materials_charge: %d > %d item #%d", - n, vec[item], item); - n = 0; - } - vec[item] = n; + ap = product->p_vamt; + endp = product->p_vtype + product->p_nv; + for (vp = product->p_vtype; vp < endp; vp++, ap++) { + item = *vp & ~VT_ITEM; + if (item < 0 || item > I_MAX) { + logerror("materials_charge: bad item %d", item); + continue; + } + if ((n = vec[item] - *ap * count) < 0) { + logerror("materials_charge: %d > %d item #%d", + n, vec[item], item); + n = 0; } + vec[item] = n; + } } diff --git a/src/lib/update/removewants.c b/src/lib/update/removewants.c index 0f7f5f91f..f8d4d42af 100644 --- a/src/lib/update/removewants.c +++ b/src/lib/update/removewants.c @@ -44,15 +44,15 @@ int update_removewants(void) { - natid cn; - struct natstr *natp; + natid cn; + struct natstr *natp; - for (cn = 0; NULL != (natp=getnatp(cn)); cn++) { - if ((natp->nat_stat & STAT_INUSE) && - (natp->nat_update & WUPD_WANT) == 0){ - natp->nat_missed++; - } - natp->nat_update = natp->nat_stat & ~WUPD_WANT; + for (cn = 0; NULL != (natp = getnatp(cn)); cn++) { + if ((natp->nat_stat & STAT_INUSE) && + (natp->nat_update & WUPD_WANT) == 0) { + natp->nat_missed++; } - return 0; + natp->nat_update = natp->nat_stat & ~WUPD_WANT; + } + return 0; } diff --git a/src/lib/update/revolt.c b/src/lib/update/revolt.c index d734b9e17..9d3b767fa 100644 --- a/src/lib/update/revolt.c +++ b/src/lib/update/revolt.c @@ -60,15 +60,15 @@ void revolt(struct sctstr *sp) { - int che_civ; - int che_uw; - int civ; - int uw; - u_short che_combo; - int che; - int n; - int target; - + int che_civ; + int che_uw; + int civ; + int uw; + u_short che_combo; + int che; + int n; + int target; + che_combo = getvar(V_CHE, (s_char *)sp, EF_SECTOR); che = get_che_value(che_combo); target = get_che_cnum(che_combo); @@ -82,7 +82,7 @@ revolt(struct sctstr *sp) che_civ = 0; /* che due to civilian unrest */ n = 10 - (random() % 20); - che_civ = 3 + (civ * n/500); + che_civ = 3 + (civ * n / 500); if (che_civ < 0) che_civ = 0; else if (che_civ * 3 > civ) @@ -93,7 +93,7 @@ revolt(struct sctstr *sp) if (che < CHE_MAX) { /* che due to uw unrest */ n = 10 + (random() % 30); - che_uw = 5 + (uw * n/500); + che_uw = 5 + (uw * n / 500); if (che_uw > uw) che_uw = uw; if (che + che_uw > CHE_MAX) @@ -142,454 +142,449 @@ revolt(struct sctstr *sp) void guerrilla(struct sctstr *sp) { - extern s_char *effadv(); - struct sctstr *nsp; - int recruit; - int move; - int ratio; - int che; - int mil; - int cc, mc; - double odds; - int civ; - int n; - int uw; - natid target; - struct natstr *tnat; - int convert; - natid actor; - natid victim; - u_short che_combo; - int vec[I_MAX+1]; - int tmp; - int min_mil; - int val; + extern s_char *effadv(); + struct sctstr *nsp; + int recruit; + int move; + int ratio; + int che; + int mil; + int cc, mc; + double odds; + int civ; + int n; + int uw; + natid target; + struct natstr *tnat; + int convert; + natid actor; + natid victim; + u_short che_combo; + int vec[I_MAX + 1]; + int tmp; + int min_mil; + int val; int oldmob; - struct lndstr *lp; - s_char *nxtitemp(struct nstr_item *np, int owner); - struct nstr_item ni; - extern double hap_fact(); - + struct lndstr *lp; + s_char *nxtitemp(struct nstr_item *np, int owner); + struct nstr_item ni; + extern double hap_fact(); + mc = cc = 0; recruit = 0; convert = 0; move = 0; if ((n = getvar(V_CHE, (s_char *)sp, EF_SECTOR)) <= 0) - return; + return; che_combo = n; if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - return; + return; civ = vec[I_CIVIL]; - + uw = vec[I_UW]; victim = sp->sct_own; actor = sp->sct_oldown; che = get_che_value(che_combo); - + mil = vec[I_MILIT]; - snxtitem_xy(&ni, EF_LAND, sp->sct_x,sp->sct_y); - - while (NULL != (lp=(struct lndstr *)nxtitemp(&ni, 0))){ - if (lp->lnd_own != sp->sct_own) - continue; - - mil += lnd_getmil(lp); - - /* Security troops can now kill up to 1/2 their complement each - update, before doing anything else. */ - if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY){ - int che_kill, r; - struct lchrstr *lcp; - - lcp = &lchr[(int)lp->lnd_type]; - mil += lnd_getmil(lp); - r = (((float)(lp->lnd_effic / 100) * (float)(lnd_getmil(lp))) / 2); - if (r < 2) - r = 2; - che_kill = (roll(r) - 1); - if (che_kill > che) - che_kill = che; - if (che_kill) { - wu(0, sp->sct_own, - "%s kills %d guerrilla%s in raid at %s!\n", - prland(lp), - che_kill, splur(che_kill), - ownxy(sp)); - che -= che_kill; - } - } + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + + while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { + if (lp->lnd_own != sp->sct_own) + continue; + + mil += lnd_getmil(lp); + + /* Security troops can now kill up to 1/2 their complement each + update, before doing anything else. */ + if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) { + int che_kill, r; + struct lchrstr *lcp; + + lcp = &lchr[(int)lp->lnd_type]; + mil += lnd_getmil(lp); + r = (((float)(lp->lnd_effic / 100) * (float)(lnd_getmil(lp))) / + 2); + if (r < 2) + r = 2; + che_kill = (roll(r) - 1); + if (che_kill > che) + che_kill = che; + if (che_kill) { + wu(0, sp->sct_own, + "%s kills %d guerrilla%s in raid at %s!\n", + prland(lp), che_kill, splur(che_kill), ownxy(sp)); + che -= che_kill; + } + } } - + /* Security forces killed all the che */ if (che <= 0) { - putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR); - return; + putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR); + return; } - + target = get_che_cnum(che_combo); if (target == 0) { - /* the deity can't be a target! */ - return; + /* the deity can't be a target! */ + return; } tnat = getnatp(target); if ((tnat->nat_stat & STAT_INUSE) == 0) { - /* target nation has dissolved: che's retire. */ - logerror("%d Che targeted at country %d retiring", che, target); - civ += che; - putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR); - putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); - return; + /* target nation has dissolved: che's retire. */ + logerror("%d Che targeted at country %d retiring", che, target); + civ += che; + putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR); + putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); + return; } - + if (sp->sct_own != target) { - /*logerror("own %d != target %d", sp->sct_own, target);*/ - move++; - goto domove; + /*logerror("own %d != target %d", sp->sct_own, target); */ + move++; + goto domove; } - + ratio = mil / che; - odds = (double) che / (mil+che); - odds /= hap_fact(tnat,getnatp(sp->sct_oldown)); + odds = (double)che / (mil + che); + odds /= hap_fact(tnat, getnatp(sp->sct_oldown)); if (mil == 0) { - wu(0, sp->sct_own, "Revolutionary subversion reported in %s!\n", - ownxy(sp)); - recruit++; - convert++; + wu(0, sp->sct_own, "Revolutionary subversion reported in %s!\n", + ownxy(sp)); + recruit++; + convert++; } else if (che > mil && mil > 0) { - /*logerror("guerrilla shootout with military");*/ - /* - * shoot it out with the military, and kill them off. - * If loyalty bad enough, then take the sector over, - * and enlist 5% of civ as military force. - */ - while (che > 0 && mil > 0) { - if (chance(odds)) { - mc++; - mil--; - } else { - cc++; - che--; - } - } - if (mil > 0) { - /* military won. */ - n = sp->sct_loyal - (random() % 15); - if (n < 0) - n = 0; - sp->sct_loyal = n; - /*logerror("(#%d) mil beat che in %s", sp->sct_own,*/ - /*ownxy(sp));*/ - } else { - convert++; - recruit++; - /*logerror("(#%d) che beat mil in %s", sp->sct_own,*/ - /*ownxy(sp));*/ - } - take_casualties(sp,mc); - } else if (ratio < 5) { - /* - * guerrillas have to resort to blowing things up. - * Note this disrupts work in the sector. - */ + /*logerror("guerrilla shootout with military"); */ + /* + * shoot it out with the military, and kill them off. + * If loyalty bad enough, then take the sector over, + * and enlist 5% of civ as military force. + */ + while (che > 0 && mil > 0) { + if (chance(odds)) { + mc++; + mil--; + } else { + cc++; + che--; + } + } + if (mil > 0) { + /* military won. */ + n = sp->sct_loyal - (random() % 15); + if (n < 0) n = 0; - n = (random() % 10) + (random() % che); - if (n > 100) - n = 100; - tmp = sp->sct_work - n; - if (tmp < 0) - tmp = 0; - sp->sct_work = tmp; - wu(0, sp->sct_own, - "Production %s disrupted by terrorists in %s\n", - effadv(n), ownxy(sp)); - sect_damage(sp, n/10, 0); - /*logerror("(#%d) che blew up %s for %d", sp->sct_own,*/ - /*ownxy(sp), n);*/ - recruit++; + sp->sct_loyal = n; + /*logerror("(#%d) mil beat che in %s", sp->sct_own, */ + /*ownxy(sp)); */ + } else { + convert++; + recruit++; + /*logerror("(#%d) che beat mil in %s", sp->sct_own, */ + /*ownxy(sp)); */ + } + take_casualties(sp, mc); + } else if (ratio < 5) { + /* + * guerrillas have to resort to blowing things up. + * Note this disrupts work in the sector. + */ + n = 0; + n = (random() % 10) + (random() % che); + if (n > 100) + n = 100; + tmp = sp->sct_work - n; + if (tmp < 0) + tmp = 0; + sp->sct_work = tmp; + wu(0, sp->sct_own, + "Production %s disrupted by terrorists in %s\n", + effadv(n), ownxy(sp)); + sect_damage(sp, n / 10, 0); + /*logerror("(#%d) che blew up %s for %d", sp->sct_own, */ + /*ownxy(sp), n); */ + recruit++; } else { - /* ratio >= 5 */ - /*logerror("(#%d) %d che fleeing %d mil in %s", sp->sct_own,*/ - /*che, mil, ownxy(sp));*/ - move++; + /* ratio >= 5 */ + /*logerror("(#%d) %d che fleeing %d mil in %s", sp->sct_own, */ + /*che, mil, ownxy(sp)); */ + move++; } if (mil > 0 && che > 0) { - /* - * we only get here if we haven't had combat previously. - * Chance to catch them. - * 20% of mil involved in attacking the che's. - */ - if (chance(ratio*0.10)) { - n = (mil/5) + 1; - if ((n+che) == 0){ - logerror("n=%d che=%d\n",n,che); - if (che == 0) - return; - } - odds = (double) che / (n + che); - odds /= hap_fact(tnat,getnatp(sp->sct_oldown)); - while (che > 0 && n > 0) { - if (chance(odds)) { - mc++; - n--; - } else { - cc++; - che--; - } - } - take_casualties(sp,mc); - recruit = 0; - /*logerror("Caught che; mc: %d, cc: %d", cc, mc);*/ + /* + * we only get here if we haven't had combat previously. + * Chance to catch them. + * 20% of mil involved in attacking the che's. + */ + if (chance(ratio * 0.10)) { + n = (mil / 5) + 1; + if ((n + che) == 0) { + logerror("n=%d che=%d\n", n, che); + if (che == 0) + return; + } + odds = (double)che / (n + che); + odds /= hap_fact(tnat, getnatp(sp->sct_oldown)); + while (che > 0 && n > 0) { + if (chance(odds)) { + mc++; + n--; + } else { + cc++; + che--; } + } + take_casualties(sp, mc); + recruit = 0; + /*logerror("Caught che; mc: %d, cc: %d", cc, mc); */ + } } if (convert && sp->sct_loyal >= 50) { - register int n; - /* new owner gets to keep the mobility there */ - oldmob = sp->sct_mobil; - /* che won, and sector converts. */ - if (sp->sct_own == sp->sct_oldown) - sp->sct_oldown = 0; - else - takeover(sp, sp->sct_oldown); - sp->sct_mobil = oldmob; - civ += uw; - uw = 0; - /* - * so we can't keep losing money by having - * our cap retaken - */ - if (sp->sct_type == SCT_CAPIT && - sp->sct_newtype == SCT_CAPIT) - sp->sct_newtype = SCT_AGRI; - n = civ / 20; - civ -= n; - putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); - putvar(V_UW, uw, (s_char *)sp, EF_SECTOR); - putvar(V_MILIT, n, (s_char *)sp, EF_SECTOR); - move++; - recruit = 0; - if (sp->sct_own) - wu(0, sp->sct_own, "Sector %s has been retaken!\n", - xyas(sp->sct_x, sp->sct_y, sp->sct_own)); + register int n; + /* new owner gets to keep the mobility there */ + oldmob = sp->sct_mobil; + /* che won, and sector converts. */ + if (sp->sct_own == sp->sct_oldown) + sp->sct_oldown = 0; + else + takeover(sp, sp->sct_oldown); + sp->sct_mobil = oldmob; + civ += uw; + uw = 0; + /* + * so we can't keep losing money by having + * our cap retaken + */ + if (sp->sct_type == SCT_CAPIT && sp->sct_newtype == SCT_CAPIT) + sp->sct_newtype = SCT_AGRI; + n = civ / 20; + civ -= n; + putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); + putvar(V_UW, uw, (s_char *)sp, EF_SECTOR); + putvar(V_MILIT, n, (s_char *)sp, EF_SECTOR); + move++; + recruit = 0; + if (sp->sct_own) + wu(0, sp->sct_own, "Sector %s has been retaken!\n", + xyas(sp->sct_x, sp->sct_y, sp->sct_own)); } if (recruit && che > 0) { - /* loyalty drops during recruitment efforts */ - n = sp->sct_loyal; - if (n < 30) - n += (random() % 5) + 1; - else if (n < 70) - n += (random() % 10) + 4; - if (n > 127) - n = 127; - sp->sct_loyal = n; - if (sp->sct_oldown != sp->sct_own || n > 100) { - n = civ * (random() % 3) / 200; - n /= hap_fact(tnat,getnatp(sp->sct_oldown)); - if (n + che > CHE_MAX) - n = CHE_MAX - che; - che += n; - civ -= n; - putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); - } - n = uw * (random() % 3) / 200; - if (n + che > CHE_MAX) - n = CHE_MAX - che; - che += n; - uw -= n; - putvar(V_UW, uw, (s_char *)sp, EF_SECTOR); + /* loyalty drops during recruitment efforts */ + n = sp->sct_loyal; + if (n < 30) + n += (random() % 5) + 1; + else if (n < 70) + n += (random() % 10) + 4; + if (n > 127) + n = 127; + sp->sct_loyal = n; + if (sp->sct_oldown != sp->sct_own || n > 100) { + n = civ * (random() % 3) / 200; + n /= hap_fact(tnat, getnatp(sp->sct_oldown)); + if (n + che > CHE_MAX) + n = CHE_MAX - che; + che += n; + civ -= n; + putvar(V_CIVIL, civ, (s_char *)sp, EF_SECTOR); + } + n = uw * (random() % 3) / 200; + if (n + che > CHE_MAX) + n = CHE_MAX - che; + che += n; + uw -= n; + putvar(V_UW, uw, (s_char *)sp, EF_SECTOR); } - domove: + domove: if (move && che > 0) { - struct sctstr *maybe_sp = 0; - if (convert) - min_mil = 999; - else - min_mil = mil; - for (n=1; n<=6; n++) { - nsp = getsectp(sp->sct_x+diroff[n][0], - sp->sct_y+diroff[n][1]); - if (dchr[nsp->sct_type].d_mcst == 0) - continue; - if (nsp->sct_own != target) - continue; - if ((val = getvar(V_CHE, (s_char *)nsp, EF_SECTOR)) > 0) { - che_combo = val; - if (get_che_cnum(che_combo) != target) - continue; - if (get_che_value(che_combo) + che > CHE_MAX) - continue; - } - val = getvar(V_MILIT, (s_char *)nsp, EF_SECTOR); - if (val >= min_mil) - continue; - maybe_sp = nsp; - min_mil = val; - } - /* - * if n <= 6, we found a sector owned by TARGET which - * is a nice sector. Otherwise, we move to the first - * one we find ("maybe_sp"). - */ - if (maybe_sp != 0) { - che_combo = getvar(V_CHE, (s_char *)maybe_sp, EF_SECTOR); - che += get_che_value(che_combo); - set_che_value(che_combo, che); - set_che_cnum(che_combo, target); - putvar(V_CHE, (int) che_combo, (s_char *)maybe_sp, EF_SECTOR); - che = 0; - } + struct sctstr *maybe_sp = 0; + if (convert) + min_mil = 999; + else + min_mil = mil; + for (n = 1; n <= 6; n++) { + nsp = getsectp(sp->sct_x + diroff[n][0], + sp->sct_y + diroff[n][1]); + if (dchr[nsp->sct_type].d_mcst == 0) + continue; + if (nsp->sct_own != target) + continue; + if ((val = getvar(V_CHE, (s_char *)nsp, EF_SECTOR)) > 0) { + che_combo = val; + if (get_che_cnum(che_combo) != target) + continue; + if (get_che_value(che_combo) + che > CHE_MAX) + continue; + } + val = getvar(V_MILIT, (s_char *)nsp, EF_SECTOR); + if (val >= min_mil) + continue; + maybe_sp = nsp; + min_mil = val; + } + /* + * if n <= 6, we found a sector owned by TARGET which + * is a nice sector. Otherwise, we move to the first + * one we find ("maybe_sp"). + */ + if (maybe_sp != 0) { + che_combo = getvar(V_CHE, (s_char *)maybe_sp, EF_SECTOR); + che += get_che_value(che_combo); + set_che_value(che_combo, che); + set_che_cnum(che_combo, target); + putvar(V_CHE, (int)che_combo, (s_char *)maybe_sp, EF_SECTOR); + che = 0; + } } if (che > 0) { - set_che_value(che_combo, che); - set_che_cnum(che_combo, target); - putvar(V_CHE, (int) che_combo, (s_char *)sp, EF_SECTOR); + set_che_value(che_combo, che); + set_che_cnum(che_combo, target); + putvar(V_CHE, (int)che_combo, (s_char *)sp, EF_SECTOR); } else - putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR); + putvar(V_CHE, 0, (s_char *)sp, EF_SECTOR); if (mc > 0 || cc > 0) { - /* don't tell who won just to be mean */ - wu(0, target, - "Guerrilla warfare in %s\n", - xyas(sp->sct_x, sp->sct_y, target)); - wu(0, target, " body count: troops: %d, rebels: %d\n", mc, cc); - nreport(actor, N_FREEDOM_FIGHT, victim, 1); + /* don't tell who won just to be mean */ + wu(0, target, + "Guerrilla warfare in %s\n", + xyas(sp->sct_x, sp->sct_y, target)); + wu(0, target, " body count: troops: %d, rebels: %d\n", mc, cc); + nreport(actor, N_FREEDOM_FIGHT, victim, 1); } } void take_casualties(struct sctstr *sp, int mc) { - int orig_mil; - int cantake; - int nunits=0, each, deq; - struct lndstr *lp; - s_char *nxtitemp(struct nstr_item *np, int owner); - struct nstr_item ni; - + int orig_mil; + int cantake; + int nunits = 0, each, deq; + struct lndstr *lp; + s_char *nxtitemp(struct nstr_item *np, int owner); + struct nstr_item ni; + /* casualties come out of mil first */ orig_mil = getvar(V_MILIT, (s_char *)sp, EF_SECTOR); - - if (mc <= orig_mil){ - putvar(V_MILIT, (orig_mil-mc), (s_char *)sp, EF_SECTOR); + + if (mc <= orig_mil) { + putvar(V_MILIT, (orig_mil - mc), (s_char *)sp, EF_SECTOR); return; } putvar(V_MILIT, 0, (s_char *)sp, EF_SECTOR); - + /* remaining casualites */ mc -= orig_mil; - + /* * Need to take total_casualties and divide * them amongst the land units in the sector * Do security troops first, then others. * Try not to kill any unit. */ - snxtitem_xy(&ni, EF_LAND, sp->sct_x,sp->sct_y); - while(NULL != (lp=(struct lndstr *)nxtitemp(&ni, 0))){ + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { nunits++; if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) nunits++; } - - if (nunits==0) + + if (nunits == 0) return; - - each = (mc/nunits)+2; - + + each = (mc / nunits) + 2; + /* kill some security troops */ - snxtitem_xy(&ni, EF_LAND, sp->sct_x,sp->sct_y); - while(NULL != (lp=(struct lndstr *)nxtitemp(&ni, 0))){ + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY)) continue; - - cantake = (((float)(lp->lnd_effic-40)/100.0)* - (float)lnd_getmil(lp))*2; - /* (float)lchr[lp->lnd_type].l_mil)*2;*/ - - if (cantake >= each){ - /* deq = (((float)each/(float)(lchr[lp->lnd_type].l_mil*2))*/ - deq = (((float)each/(float)(lnd_getmil(lp)*2)) - *100.0); + + cantake = (((float)(lp->lnd_effic - 40) / 100.0) * + (float)lnd_getmil(lp)) * 2; + /* (float)lchr[lp->lnd_type].l_mil)*2; */ + + if (cantake >= each) { + /* deq = (((float)each/(float)(lchr[lp->lnd_type].l_mil*2)) */ + deq = (((float)each / (float)(lnd_getmil(lp) * 2)) + * 100.0); mc -= each; - }else if (cantake > 0){ - deq = (((float)cantake/ - (float)(lnd_getmil(lp)*2)) * 100.0); - /* (float)(lchr[lp->lnd_type].l_mil*2)) * 100.0);*/ - mc -= (((float)deq/100.0)* - (float)lnd_getmil(lp))*2; - /* (float)lchr[lp->lnd_type].l_mil)*2;*/ - }else + } else if (cantake > 0) { + deq = (((float)cantake / (float)(lnd_getmil(lp) * 2)) * 100.0); + /* (float)(lchr[lp->lnd_type].l_mil*2)) * 100.0); */ + mc -= (((float)deq / 100.0) * (float)lnd_getmil(lp)) * 2; + /* (float)lchr[lp->lnd_type].l_mil)*2; */ + } else deq = 0; - + lp->lnd_effic -= deq; - lp->lnd_mobil -= deq/2; + lp->lnd_mobil -= deq / 2; deq = (double)lchr[(int)lp->lnd_type].l_mil * (deq / 100.0); lnd_submil(lp, deq); - if (mc<=0) return; + if (mc <= 0) + return; } - + /* kill some normal troops */ - snxtitem_xy(&ni, EF_LAND, sp->sct_x,sp->sct_y); - while(NULL != (lp=(struct lndstr *)nxtitemp(&ni, 0))){ + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) continue; - - cantake = (((float)(lp->lnd_effic-40)/100.0)* + + cantake = (((float)(lp->lnd_effic - 40) / 100.0) * (float)lnd_getmil(lp)); - - if (cantake >= each){ - deq = (((float)each/(float)(lnd_getmil(lp)*2)) - *100.0); + + if (cantake >= each) { + deq = (((float)each / (float)(lnd_getmil(lp) * 2)) + * 100.0); mc -= each; - }else if (cantake > 0){ - deq = (((float)cantake/(float)lnd_getmil(lp)) + } else if (cantake > 0) { + deq = (((float)cantake / (float)lnd_getmil(lp)) * 100.0); - mc -= (((float)deq/100.0)* - (float)lnd_getmil(lp)); - }else + mc -= (((float)deq / 100.0) * (float)lnd_getmil(lp)); + } else deq = 0; lp->lnd_effic -= deq; - lp->lnd_mobil -= deq/2; + lp->lnd_mobil -= deq / 2; deq = (double)lchr[(int)lp->lnd_type].l_mil * (deq / 100.0); lnd_submil(lp, deq); - if (mc<=0) return; + if (mc <= 0) + return; } - + /* Hmm.. still some left.. kill off units now */ /* kill some normal troops */ - snxtitem_xy(&ni, EF_LAND, sp->sct_x,sp->sct_y); - while(NULL != (lp=(struct lndstr *)nxtitemp(&ni, 0))){ + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { if (lchr[(int)lp->lnd_type].l_flags & L_SECURITY) continue; - - mc -= (((float)lp->lnd_effic/100.0) * - (float)lnd_getmil(lp)); + + mc -= (((float)lp->lnd_effic / 100.0) * (float)lnd_getmil(lp)); lp->lnd_effic = 0; - lnd_submil(lp, 1000); /* Remove 'em all */ - wu(0,lp->lnd_own,"%s dies fighting guerrillas in %s\n", - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + lnd_submil(lp, 1000); /* Remove 'em all */ + wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n", + prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); lp->lnd_own = 0; - if (mc<=0) return; + if (mc <= 0) + return; } - + /* Hmm.. still some left.. kill off units now */ /* kill some security troops */ - snxtitem_xy(&ni, EF_LAND, sp->sct_x,sp->sct_y); - while(NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))){ + snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y); + while (NULL != (lp = (struct lndstr *)nxtitemp(&ni, 0))) { if (!(lchr[(int)lp->lnd_type].l_flags & L_SECURITY)) continue; - + mc -= (((float)lp->lnd_effic / 100.0) * (float)lnd_getmil(lp)) * 2; lp->lnd_effic = 0; - lnd_submil(lp, 1000); /* Kill 'em all */ + lnd_submil(lp, 1000); /* Kill 'em all */ wu(0, lp->lnd_own, "%s dies fighting guerrillas in %s\n", - prland(lp), - xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); + prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y); lp->lnd_own = 0; - if (mc <= 0) + if (mc <= 0) return; } - + /* Hmm.. everyone dead.. too bad */ } diff --git a/src/lib/update/sail.c b/src/lib/update/sail.c index 5ecba2129..3103b222b 100644 --- a/src/lib/update/sail.c +++ b/src/lib/update/sail.c @@ -53,281 +53,280 @@ static void cost_ship(struct shpstr *sp, struct fltelemstr *ep, struct fltheadstr *fp) { - double mobcost,ceil(double); - int howfar; + double mobcost, ceil(double); + int howfar; - mobcost = 0.0; - if (sp->shp_effic > 0) { - mobcost = sp->shp_effic * sp->shp_speed * 0.01; - mobcost = 480.0 / ( mobcost*(1 + (50+sp->shp_tech)/ - (double)(200+sp->shp_tech))); - } + mobcost = 0.0; + if (sp->shp_effic > 0) { + mobcost = sp->shp_effic * sp->shp_speed * 0.01; + mobcost = 480.0 / (mobcost * (1 + (50 + sp->shp_tech) / + (double)(200 + sp->shp_tech))); + } /* the next two lines are not necessary since shp_mobquota is unsigned and therefore cannot be less than 0. if (sp->shp_mobquota<0) sp->shp_mobquota=0; */ + howfar = 0; + if (mobcost > 0) { + howfar = (int)sp->shp_mobil - (int)sp->shp_mobquota; + howfar = ceil((howfar / mobcost)); + } + if (howfar < 0) howfar = 0; - if (mobcost > 0) { - howfar = (int)sp->shp_mobil - (int)sp->shp_mobquota; - howfar = ceil((howfar / mobcost)); - } - if (howfar<0) - howfar=0; #ifdef SAILDEBUG - wu(0,fp->own, - "Ship #%d can move %d spaces on mobility %d (cost/sect %f)\n", - sp->shp_uid, howfar, sp->shp_mobil, mobcost); + wu(0, fp->own, + "Ship #%d can move %d spaces on mobility %d (cost/sect %f)\n", + sp->shp_uid, howfar, sp->shp_mobil, mobcost); #endif - if ((unsigned int)howfar < fp->maxmoves) - fp->maxmoves = howfar; + if ((unsigned int)howfar < fp->maxmoves) + fp->maxmoves = howfar; - ep->mobil = sp->shp_mobil; - ep->mobcost = mobcost; + ep->mobil = sp->shp_mobil; + ep->mobcost = mobcost; } static int sail_find_fleet(struct fltheadstr **head, struct shpstr *sp) { - struct fltheadstr *fltp; - struct shpstr *ap; - struct fltelemstr *this; - int len=0; - int follow = -1; - int stop; - s_char *cp; + struct fltheadstr *fltp; + struct shpstr *ap; + struct fltelemstr *this; + int len = 0; + int follow = -1; + int stop; + s_char *cp; - if (sp->shp_own==0) - return(0); + if (sp->shp_own == 0) + return (0); - /* If this ship is following, find the head of the follow list. */ - for (ap=sp; ap; len++, ap=getshipp(follow)) { - follow = ap->shp_follow; - /* Not same owner */ - if (ap->shp_own != sp->shp_own) { - wu(0, sp->shp_own, - "Ship #%d, following #%d, which you don't own.\n", - sp->shp_uid, ap->shp_uid); - return(0); - } - /* Not a follower. */ - if (ap->shp_path[0] != 'f') - break; - /* Following itself */ - if (follow==ap->shp_uid || - follow==sp->shp_uid) - break; - } - if (!ap) { - wu(0, sp->shp_own, - "Ship #%d, following #%d, which you don't own.\n", - sp->shp_uid, follow); - return(0); + /* If this ship is following, find the head of the follow list. */ + for (ap = sp; ap; len++, ap = getshipp(follow)) { + follow = ap->shp_follow; + /* Not same owner */ + if (ap->shp_own != sp->shp_own) { + wu(0, sp->shp_own, + "Ship #%d, following #%d, which you don't own.\n", + sp->shp_uid, ap->shp_uid); + return (0); } + /* Not a follower. */ + if (ap->shp_path[0] != 'f') + break; + /* Following itself */ + if (follow == ap->shp_uid || follow == sp->shp_uid) + break; + } + if (!ap) { + wu(0, sp->shp_own, + "Ship #%d, following #%d, which you don't own.\n", + sp->shp_uid, follow); + return (0); + } - /* This should prevent infinite loops. */ - if (len>=10) { - wu(0,sp->shp_own, - "Ship #%d, too many follows (circular follow?).\n", - sp->shp_uid); - return(0); - } + /* This should prevent infinite loops. */ + if (len >= 10) { + wu(0, sp->shp_own, + "Ship #%d, too many follows (circular follow?).\n", + sp->shp_uid); + return (0); + } - for (stop=0,cp=ap->shp_path; (!stop) && (*cp); cp++) { - switch (*cp) { - case 'y': - case 'u': - case 'g': - case 'j': - case 'b': - case 'n': - case 'h': - case 't': - break; - default: - stop=1; - } + for (stop = 0, cp = ap->shp_path; (!stop) && (*cp); cp++) { + switch (*cp) { + case 'y': + case 'u': + case 'g': + case 'j': + case 'b': + case 'n': + case 'h': + case 't': + break; + default: + stop = 1; } + } - /* we found a non-valid char in the path. */ - if (*cp) { - wu(0,ap->shp_own, "invalid char '\\%03o' in path of ship %d\n", - (unsigned char)*cp, ap->shp_uid); - *cp=0; - } + /* we found a non-valid char in the path. */ + if (*cp) { + wu(0, ap->shp_own, "invalid char '\\%03o' in path of ship %d\n", + (unsigned char)*cp, ap->shp_uid); + *cp = 0; + } - /* if this ship is not sailing anywhere then ignore it. */ - if (!*ap->shp_path) - return(0); + /* if this ship is not sailing anywhere then ignore it. */ + if (!*ap->shp_path) + return (0); - /* Find the fleet structure we belong to. */ - for (fltp=(*head); (fltp && fltp->leader != follow); fltp = fltp->next) - ; + /* Find the fleet structure we belong to. */ + for (fltp = (*head); (fltp && fltp->leader != follow); + fltp = fltp->next) ; - if (!fltp) { - fltp = (struct fltheadstr *) malloc(sizeof(*fltp)); - bzero((s_char *)fltp, sizeof(*fltp)); + if (!fltp) { + fltp = (struct fltheadstr *)malloc(sizeof(*fltp)); + bzero((s_char *)fltp, sizeof(*fltp)); - /* Fix the links. */ - fltp->next = (*head); - *head = fltp; + /* Fix the links. */ + fltp->next = (*head); + *head = fltp; - /* Set the leader. */ - fltp->leader = ap->shp_uid; - fltp->real_q = LEADER_REAL; - fltp->x = ap->shp_x; - fltp->y = ap->shp_y; - fltp->own = ap->shp_own; - fltp->maxmoves = 500; - } + /* Set the leader. */ + fltp->leader = ap->shp_uid; + fltp->real_q = LEADER_REAL; + fltp->x = ap->shp_x; + fltp->y = ap->shp_y; + fltp->own = ap->shp_own; + fltp->maxmoves = 500; + } - /* If the fleet is not in the same sector as us, no go. */ - if ( ( fltp->x!=sp->shp_x ) || ( fltp->y!=sp->shp_y ) ) { - wu(0,sp->shp_own, - "Ship %d not in same sector as its sailing fleet\n", - sp->shp_uid); - fltp->real_q = LEADER_WRONGSECT; - return(0); - } + /* If the fleet is not in the same sector as us, no go. */ + if ((fltp->x != sp->shp_x) || (fltp->y != sp->shp_y)) { + wu(0, sp->shp_own, + "Ship %d not in same sector as its sailing fleet\n", + sp->shp_uid); + fltp->real_q = LEADER_WRONGSECT; + return (0); + } - this = (struct fltelemstr *) malloc(sizeof(*this)); - bzero((s_char *)this, sizeof(*this)); - this->num = sp->shp_uid; - this->own = sp->shp_own; - this->next = fltp->head; - fltp->head = this; - cost_ship(sp, this, fltp); + this = (struct fltelemstr *)malloc(sizeof(*this)); + bzero((s_char *)this, sizeof(*this)); + this->num = sp->shp_uid; + this->own = sp->shp_own; + this->next = fltp->head; + fltp->head = this; + cost_ship(sp, this, fltp); - return 1; + return 1; } static int sail_nav_fleet(struct fltheadstr *fltp) { - struct fltelemstr *fe; - struct shpstr *sp, ship; - int vec[I_MAX+1]; - struct sctstr *sectp; - int error=0; - s_char *s, *p; - natid own; - struct emp_qelem ship_list; - int dir; + struct fltelemstr *fe; + struct shpstr *sp, ship; + int vec[I_MAX + 1]; + struct sctstr *sectp; + int error = 0; + s_char *s, *p; + natid own; + struct emp_qelem ship_list; + int dir; #ifdef SAILDEBUG - switch (fltp->real_q) { - case LEADER_VIRTUAL: - s = "leaderless"; - break; - case LEADER_REAL: - s = "real"; - break; - case LEADER_WRONGSECT: - s = "scattered"; - break; - default: - s = "inconsistent"; - } - wu(0,fltp->own, - "Fleet lead by %d is %s, can go %d spaces\n contains ships:", - fltp->leader, s, fltp->maxmoves); - for (fe=fltp->head; fe; fe = fe->next) - wu(0, fltp->own, " %d", fe->num); - wu(0, fltp->own, "\n"); + switch (fltp->real_q) { + case LEADER_VIRTUAL: + s = "leaderless"; + break; + case LEADER_REAL: + s = "real"; + break; + case LEADER_WRONGSECT: + s = "scattered"; + break; + default: + s = "inconsistent"; + } + wu(0, fltp->own, + "Fleet lead by %d is %s, can go %d spaces\n contains ships:", + fltp->leader, s, fltp->maxmoves); + for (fe = fltp->head; fe; fe = fe->next) + wu(0, fltp->own, " %d", fe->num); + wu(0, fltp->own, "\n"); #endif - sectp = getsectp(fltp->x, fltp->y); - switch (check_nav(sectp)) { - case CN_NAVIGABLE: - break; - case CN_CONSTRUCTION: - case CN_LANDLOCKED: - default: - wu(0,fltp->own, "Your fleet lead by %d is trapped by land.\n", - fltp->leader); - return(0); - } - for (fe=fltp->head; fe; fe = fe->next) { - sp = getshipp(fe->num); - getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); - if (vec[I_MILIT]==0 && vec[I_CIVIL]==0) { - wu(0,fltp->own, - " ship #%d (%s) is crewless and can't go on\n", - fe->num, cname(fe->own)); - error = 1; - } + sectp = getsectp(fltp->x, fltp->y); + switch (check_nav(sectp)) { + case CN_NAVIGABLE: + break; + case CN_CONSTRUCTION: + case CN_LANDLOCKED: + default: + wu(0, fltp->own, "Your fleet lead by %d is trapped by land.\n", + fltp->leader); + return (0); + } + for (fe = fltp->head; fe; fe = fe->next) { + sp = getshipp(fe->num); + getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); + if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0) { + wu(0, fltp->own, + " ship #%d (%s) is crewless and can't go on\n", + fe->num, cname(fe->own)); + error = 1; } - if (error) - return(0); - sp = getshipp(fltp->leader); - own = sp->shp_own; - fltp_to_list(fltp, &ship_list); /* hack -KHS 1995 */ - for (s=sp->shp_path; (*s) && (fltp->maxmoves>0); s++) { - dir = chkdir(*s, DIR_STOP, DIR_LAST); - if (0 != (error = shp_nav_one_sector(&ship_list, dir, own, 0))) - fltp->maxmoves = 1; - --(fltp->maxmoves); - } - shp_put(&ship_list, own); - getship(sp->shp_uid, &ship); - fltp->x = ship.shp_x; - fltp->y = ship.shp_y; - for (p=&ship.shp_path[0]; *s; p++,s++) - *p = *s; - *p = 0; - putship(ship.shp_uid, &ship); + } + if (error) + return (0); + sp = getshipp(fltp->leader); + own = sp->shp_own; + fltp_to_list(fltp, &ship_list); /* hack -KHS 1995 */ + for (s = sp->shp_path; (*s) && (fltp->maxmoves > 0); s++) { + dir = chkdir(*s, DIR_STOP, DIR_LAST); + if (0 != (error = shp_nav_one_sector(&ship_list, dir, own, 0))) + fltp->maxmoves = 1; + --(fltp->maxmoves); + } + shp_put(&ship_list, own); + getship(sp->shp_uid, &ship); + fltp->x = ship.shp_x; + fltp->y = ship.shp_y; + for (p = &ship.shp_path[0]; *s; p++, s++) + *p = *s; + *p = 0; + putship(ship.shp_uid, &ship); #ifdef SAILDEBUG - if (sp->shp_path[0]) { - wu(0,fltp->own, - "Fleet lead by #%d nav'd to %s, path left = %s\n", - fltp->leader, xyas(fltp->x,fltp->y,fltp->own), - &sp->shp_path); - } else - wu(0,fltp->own, - "Fleet lead by #%d nav'd to %s, finished.\n", - fltp->leader, xyas(fltp->x,fltp->y,fltp->own)); - wu(0,sp->shp_own, "Ship #%d has %d mobility now.\n", - fe->num, (int)fe->mobil); + if (sp->shp_path[0]) { + wu(0, fltp->own, + "Fleet lead by #%d nav'd to %s, path left = %s\n", + fltp->leader, xyas(fltp->x, fltp->y, fltp->own), &sp->shp_path); + } else + wu(0, fltp->own, + "Fleet lead by #%d nav'd to %s, finished.\n", + fltp->leader, xyas(fltp->x, fltp->y, fltp->own)); + wu(0, sp->shp_own, "Ship #%d has %d mobility now.\n", + fe->num, (int)fe->mobil); #endif - return 1; + return 1; } void sail_ship(natid cn) -{ - struct shpstr *sp; - struct fltheadstr *head=0; - struct fltheadstr *fltp; - int n; +{ + struct shpstr *sp; + struct fltheadstr *head = 0; + struct fltheadstr *fltp; + int n; - for (n=0; NULL != (sp = getshipp(n)); n++) if (sp->shp_own==cn) { - sail_find_fleet(&head, sp); + for (n = 0; NULL != (sp = getshipp(n)); n++) + if (sp->shp_own == cn) { + sail_find_fleet(&head, sp); } - /* see what the fleets fall out into */ - for (fltp=head; fltp; fltp = fltp->next) { - sail_nav_fleet(fltp); - wu(0,fltp->own, "Your fleet lead by ship #%d has reached %s.\n", - fltp->leader,xyas(fltp->x,fltp->y,fltp->own)); - } + /* see what the fleets fall out into */ + for (fltp = head; fltp; fltp = fltp->next) { + sail_nav_fleet(fltp); + wu(0, fltp->own, "Your fleet lead by ship #%d has reached %s.\n", + fltp->leader, xyas(fltp->x, fltp->y, fltp->own)); + } - /* Free up the memory, 'cause I want to. */ - for (fltp=head; fltp!=0; ) { - struct fltelemstr *fe; - struct fltheadstr *saveh; - saveh = fltp->next; - for (fe=fltp->head; fe!=0; ) { - struct fltelemstr *saveel; - saveel = fe->next; - free(fe); - fe = saveel; - } - free(fltp); - fltp = saveh; + /* Free up the memory, 'cause I want to. */ + for (fltp = head; fltp != 0;) { + struct fltelemstr *fe; + struct fltheadstr *saveh; + saveh = fltp->next; + for (fe = fltp->head; fe != 0;) { + struct fltelemstr *saveel; + saveel = fe->next; + free(fe); + fe = saveel; } + free(fltp); + fltp = saveh; + } } /* The following is a total hack by Ken Stevens to cut down dramatically on repeated code 1995 */ @@ -335,18 +334,17 @@ sail_ship(natid cn) void fltp_to_list(struct fltheadstr *fltp, struct emp_qelem *list) { - struct fltelemstr *fe; - struct mlist *mlp; - struct shpstr *sp; + struct fltelemstr *fe; + struct mlist *mlp; + struct shpstr *sp; - emp_initque(list); - for (fe=fltp->head; fe; fe = fe->next) { - mlp = (struct mlist *) malloc(sizeof(struct mlist)); - sp = getshipp(fe->num); - mlp->mcp = mchr + sp->shp_type; - bcopy((s_char *)sp, (s_char *)&mlp->ship, - sizeof(struct shpstr)); - mlp->mobil = fe->mobil; - emp_insque(&mlp->queue, list); - } + emp_initque(list); + for (fe = fltp->head; fe; fe = fe->next) { + mlp = (struct mlist *)malloc(sizeof(struct mlist)); + sp = getshipp(fe->num); + mlp->mcp = mchr + sp->shp_type; + bcopy((s_char *)sp, (s_char *)&mlp->ship, sizeof(struct shpstr)); + mlp->mobil = fe->mobil; + emp_insque(&mlp->queue, list); + } } diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index 9d6ab2d47..8ba9304c7 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -55,39 +55,39 @@ #include "lost.h" #include "gen.h" -extern float levels[MAXNOC][4]; +extern float levels[MAXNOC][4]; int dodeliver(struct sctstr *sp, int *vec) { - register int i; - int del[I_MAX+1]; - int thresh; - int dir; - int plague; - int n; - int changed; - - if (sp->sct_mobil <= 0) - return 0; - if (getvec(VT_DEL, del, (s_char *)sp, EF_SECTOR) <= 0) - return 0; - changed = 0; - plague = getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR); - for (i=1; i<=I_MAX; i++) { - if (del[i] == 0) - continue; - thresh = del[i] & ~0x7; - dir = del[i] & 0x7; - n = deliver(sp, &ichr[i], dir, thresh, vec[i], plague); - if (n > 0) { - vec[i] -= n; - changed++; - if (sp->sct_mobil <= 0) - break; - } + register int i; + int del[I_MAX + 1]; + int thresh; + int dir; + int plague; + int n; + int changed; + + if (sp->sct_mobil <= 0) + return 0; + if (getvec(VT_DEL, del, (s_char *)sp, EF_SECTOR) <= 0) + return 0; + changed = 0; + plague = getvar(V_PSTAGE, (s_char *)sp, EF_SECTOR); + for (i = 1; i <= I_MAX; i++) { + if (del[i] == 0) + continue; + thresh = del[i] & ~0x7; + dir = del[i] & 0x7; + n = deliver(sp, &ichr[i], dir, thresh, vec[i], plague); + if (n > 0) { + vec[i] -= n; + changed++; + if (sp->sct_mobil <= 0) + break; } - return changed; + } + return changed; } /* @@ -96,83 +96,81 @@ dodeliver(struct sctstr *sp, int *vec) * Return amount of work used. */ int -upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp, int *vec, int etu, int *desig, int sctwork, int *cost) +upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp, + int *vec, int etu, int *desig, int sctwork, int *cost) { - register int work_cost = 0; - int buildeff_work = (int)(*workp / 2); - int n, hcms, lcms, neweff; - u_char old_type = *desig; - - *cost = 0; - neweff = sp->sct_effic; + register int work_cost = 0; + int buildeff_work = (int)(*workp / 2); + int n, hcms, lcms, neweff; + u_char old_type = *desig; + + *cost = 0; + neweff = sp->sct_effic; + + if (*desig != sp->sct_newtype) { + /* + * Tear down existing sector. + * Easier to destroy than to build. + */ + work_cost = (sp->sct_effic + 3) / 4; + if (work_cost > buildeff_work) + work_cost = buildeff_work; + buildeff_work -= work_cost; + n = sp->sct_effic - work_cost * 4; + if (n <= 0) { + n = 0; + *desig = sp->sct_newtype; + } + neweff = n; + *cost += work_cost; + if (opt_BIG_CITY) { + if (!n && dchr[old_type].d_pkg == UPKG && + dchr[*desig].d_pkg != UPKG) { + int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); + if (vec[I_CIVIL] > maxpop) + vec[I_CIVIL] = maxpop; + if (vec[I_UW] > maxpop) + vec[I_UW] = maxpop; + *workp = (vec[I_CIVIL] * sctwork) / 100.0 + + (vec[I_MILIT] * 2 / 5.0) + vec[I_UW]; + *workp = roundavg((etu * (*workp)) / 100.0); - if (*desig != sp->sct_newtype) { - /* - * Tear down existing sector. - * Easier to destroy than to build. - */ - work_cost = (sp->sct_effic + 3) / 4; - if (work_cost > buildeff_work) - work_cost = buildeff_work; - buildeff_work -= work_cost; - n = sp->sct_effic - work_cost * 4; - if (n <= 0) { - n = 0; - *desig = sp->sct_newtype; - } - neweff = n; - *cost += work_cost; - if (opt_BIG_CITY) { - if (!n && dchr[old_type].d_pkg == UPKG && - dchr[*desig].d_pkg != UPKG) { - int maxpop = max_pop(np->nat_level[NAT_RLEV], sp); - if (vec[I_CIVIL] > maxpop) - vec[I_CIVIL] = maxpop; - if (vec[I_UW] > maxpop) - vec[I_UW] = maxpop; - *workp = (vec[I_CIVIL] * sctwork) / 100.0 - +(vec[I_MILIT] * 2 / 5.0) + vec[I_UW]; - *workp = roundavg((etu * (*workp)) / 100.0); - - buildeff_work = min((int)(*workp / 2), buildeff_work); - } - } + buildeff_work = min((int)(*workp / 2), buildeff_work); + } } - if (np->nat_priorities[*desig]) { - if (*desig == sp->sct_newtype) { - work_cost = 100 - neweff; - if (work_cost > buildeff_work) - work_cost = buildeff_work; - - if (dchr[*desig].d_lcms>0){ - lcms = vec[I_LCM]; - lcms /= dchr[*desig].d_lcms; - if (work_cost > lcms) - work_cost = lcms; - } - if (dchr[*desig].d_hcms>0){ - hcms = vec[I_HCM]; - hcms /= dchr[*desig].d_hcms; - if (work_cost > hcms) - work_cost = hcms; - } - - neweff += work_cost; - *cost += work_cost*dchr[*desig].d_build; - buildeff_work -= work_cost; - - if ((dchr[*desig].d_lcms>0) || - (dchr[*desig].d_hcms>0)){ - vec[I_LCM] -= work_cost * - dchr[*desig].d_lcms; - vec[I_HCM] -= work_cost * - dchr[*desig].d_hcms; - } - } + } + if (np->nat_priorities[*desig]) { + if (*desig == sp->sct_newtype) { + work_cost = 100 - neweff; + if (work_cost > buildeff_work) + work_cost = buildeff_work; + + if (dchr[*desig].d_lcms > 0) { + lcms = vec[I_LCM]; + lcms /= dchr[*desig].d_lcms; + if (work_cost > lcms) + work_cost = lcms; + } + if (dchr[*desig].d_hcms > 0) { + hcms = vec[I_HCM]; + hcms /= dchr[*desig].d_hcms; + if (work_cost > hcms) + work_cost = hcms; + } + + neweff += work_cost; + *cost += work_cost * dchr[*desig].d_build; + buildeff_work -= work_cost; + + if ((dchr[*desig].d_lcms > 0) || (dchr[*desig].d_hcms > 0)) { + vec[I_LCM] -= work_cost * dchr[*desig].d_lcms; + vec[I_HCM] -= work_cost * dchr[*desig].d_hcms; + } } - *workp = *workp/2 + buildeff_work; + } + *workp = *workp / 2 + buildeff_work; - return neweff; + return neweff; } /* @@ -184,21 +182,21 @@ upd_buildeff(struct natstr *np, register struct sctstr *sp, int *workp, int *vec int enlist(register int *vec, int etu, int *cost) { - int maxmil; - int enlisted; - - /* Need to check treaties here */ - enlisted = 0; - maxmil = (vec[I_CIVIL] / 2) - vec[I_MILIT]; - if (maxmil > 0) { - enlisted = (etu * (10 + vec[I_MILIT]) * 0.05); - if (enlisted > maxmil) - enlisted = maxmil; - vec[I_CIVIL] -= enlisted; - vec[I_MILIT] += enlisted; - } - *cost = enlisted * 3; - return enlisted; + int maxmil; + int enlisted; + + /* Need to check treaties here */ + enlisted = 0; + maxmil = (vec[I_CIVIL] / 2) - vec[I_MILIT]; + if (maxmil > 0) { + enlisted = (etu * (10 + vec[I_MILIT]) * 0.05); + if (enlisted > maxmil) + enlisted = maxmil; + vec[I_CIVIL] -= enlisted; + vec[I_MILIT] += enlisted; + } + *cost = enlisted * 3; + return enlisted; } /* Fallout is calculated here. */ @@ -206,33 +204,34 @@ enlist(register int *vec, int etu, int *cost) extern int melt_item_denom[]; void -meltitems(int etus, int fallout, int own, int *vec, int type, int x, int y, int uid) +meltitems(int etus, int fallout, int own, int *vec, int type, int x, int y, + int uid) { - int n; - int melt; - - for (n = 1; n <= I_MAX; n++) { - melt = roundavg(vec[n] * etus * (long)fallout / - (1000.0 * melt_item_denom[n])); - if (melt > 5 && own) { - if (type == EF_SECTOR) - wu(0, own, "Lost %d %s to radiation in %s.\n", - (melt < vec[n] ? melt : vec[n]), ichr[n].i_name, - xyas(x, y, own)); - else if (type == EF_LAND) - wu(0, own, "Unit #%d lost %d %s to radiation in %s.\n", - uid, (melt < vec[n] ? melt : vec[n]), ichr[n].i_name, - xyas(x, y, own)); - else if (type == EF_SHIP) - wu(0, own, "Ship #%d lost %d %s to radiation in %s.\n", - uid, (melt < vec[n] ? melt : vec[n]), ichr[n].i_name, - xyas(x, y, own)); + int n; + int melt; + + for (n = 1; n <= I_MAX; n++) { + melt = roundavg(vec[n] * etus * (long)fallout / + (1000.0 * melt_item_denom[n])); + if (melt > 5 && own) { + if (type == EF_SECTOR) + wu(0, own, "Lost %d %s to radiation in %s.\n", + (melt < vec[n] ? melt : vec[n]), ichr[n].i_name, + xyas(x, y, own)); + else if (type == EF_LAND) + wu(0, own, "Unit #%d lost %d %s to radiation in %s.\n", + uid, (melt < vec[n] ? melt : vec[n]), ichr[n].i_name, + xyas(x, y, own)); + else if (type == EF_SHIP) + wu(0, own, "Ship #%d lost %d %s to radiation in %s.\n", + uid, (melt < vec[n] ? melt : vec[n]), ichr[n].i_name, + xyas(x, y, own)); + } + if (melt < vec[n]) + vec[n] -= melt; + else + vec[n] = 0; } - if (melt < vec[n]) - vec[n] -= melt; - else - vec[n] = 0; - } } /* @@ -245,111 +244,113 @@ meltitems(int etus, int fallout, int own, int *vec, int type, int x, int y, int void do_fallout(register struct sctstr *sp, register int etus) { - int vec[I_MAX+1]; - int cvec[I_MAX+1]; - int tvec[I_MAX+1]; - struct shpstr *spp; - struct lndstr *lp; - int i; - - getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); + int vec[I_MAX + 1]; + int cvec[I_MAX + 1]; + int tvec[I_MAX + 1]; + struct shpstr *spp; + struct lndstr *lp; + int i; + + getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); /* This check shouldn't be needed, but just in case. :) */ - if (!cvec[C_FALLOUT] || !sp->sct_updated) - return; - if (etus > 24) - etus = 24; + if (!cvec[C_FALLOUT] || !sp->sct_updated) + return; + if (etus > 24) + etus = 24; #if 0 - wu(0,0,"Running fallout in %d,%d\n", sp->sct_x, sp->sct_y); + wu(0, 0, "Running fallout in %d,%d\n", sp->sct_x, sp->sct_y); #endif - meltitems(etus, cvec[C_FALLOUT], sp->sct_own, vec, EF_SECTOR, - sp->sct_x, sp->sct_y, 0); - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - for (i = 0; NULL != (lp = getlandp(i)); i++) { - if (!lp->lnd_own) - continue; - if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y) - continue; - getvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND); - meltitems(etus, cvec[C_FALLOUT], lp->lnd_own, tvec, EF_LAND, - lp->lnd_x, lp->lnd_y, lp->lnd_uid); - putvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND); - } - for (i = 0; NULL != (spp = getshipp(i)); i++) { - if (!spp->shp_own) - continue; - if (spp->shp_x != sp->sct_x || spp->shp_y != sp->sct_y) - continue; - if (mchr[(int)spp->shp_type].m_flags & M_SUB) - continue; - getvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP); - meltitems(etus, cvec[C_FALLOUT], spp->shp_own, tvec, EF_SHIP, - spp->shp_x, spp->shp_y, spp->shp_uid); - putvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP); - } + meltitems(etus, cvec[C_FALLOUT], sp->sct_own, vec, EF_SECTOR, + sp->sct_x, sp->sct_y, 0); + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + for (i = 0; NULL != (lp = getlandp(i)); i++) { + if (!lp->lnd_own) + continue; + if (lp->lnd_x != sp->sct_x || lp->lnd_y != sp->sct_y) + continue; + getvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND); + meltitems(etus, cvec[C_FALLOUT], lp->lnd_own, tvec, EF_LAND, + lp->lnd_x, lp->lnd_y, lp->lnd_uid); + putvec(VT_ITEM, tvec, (s_char *)lp, EF_LAND); + } + for (i = 0; NULL != (spp = getshipp(i)); i++) { + if (!spp->shp_own) + continue; + if (spp->shp_x != sp->sct_x || spp->shp_y != sp->sct_y) + continue; + if (mchr[(int)spp->shp_type].m_flags & M_SUB) + continue; + getvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP); + meltitems(etus, cvec[C_FALLOUT], spp->shp_own, tvec, EF_SHIP, + spp->shp_x, spp->shp_y, spp->shp_uid); + putvec(VT_ITEM, tvec, (s_char *)spp, EF_SHIP); + } #ifdef GODZILLA - if ((cvec[C_FALLOUT] > 20) && chance(100)) + if ((cvec[C_FALLOUT] > 20) && chance(100)) do_godzilla(sp); -#endif /* GODZILLA */ +#endif /* GODZILLA */ } void spread_fallout(struct sctstr *sp, int etus) { - extern double fallout_spread; - struct sctstr *ap; - int tvec[I_MAX+1]; - int cvec[I_MAX+1]; - int n; - register int inc; - - if (etus > 24) - etus = 24; - getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); - for (n = DIR_FIRST; n <= DIR_LAST; n++) { - ap = getsectp(sp->sct_x+diroff[n][0], sp->sct_y+diroff[n][1]); - getvec(VT_COND, tvec, (char *)ap, EF_SECTOR); - if (ap->sct_type == SCT_SANCT) - continue; - inc = roundavg(etus * fallout_spread * (cvec[C_FALLOUT])) - 1; + extern double fallout_spread; + struct sctstr *ap; + int tvec[I_MAX + 1]; + int cvec[I_MAX + 1]; + int n; + register int inc; + + if (etus > 24) + etus = 24; + getvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); + for (n = DIR_FIRST; n <= DIR_LAST; n++) { + ap = getsectp(sp->sct_x + diroff[n][0], sp->sct_y + diroff[n][1]); + getvec(VT_COND, tvec, (char *)ap, EF_SECTOR); + if (ap->sct_type == SCT_SANCT) + continue; + inc = roundavg(etus * fallout_spread * (cvec[C_FALLOUT])) - 1; #if 0 - if (cvec[C_FALLOUT]) { - wu(0,0,"Fallout from sector %d,%d to %d,%d is %d=%d*%e*%d\n", - sp->sct_x,sp->sct_y,sp->sct_x+diroff[n][0], - sp->sct_y+diroff[n][1], inc, etus, - fallout_spread, cvec[C_FALLOUT]); - } + if (cvec[C_FALLOUT]) { + wu(0, 0, "Fallout from sector %d,%d to %d,%d is %d=%d*%e*%d\n", + sp->sct_x, sp->sct_y, sp->sct_x + diroff[n][0], + sp->sct_y + diroff[n][1], inc, etus, + fallout_spread, cvec[C_FALLOUT]); + } #endif - if (inc < 0) - inc = 0; - tvec[C_FALLOUT] += inc; - putvec(VT_COND, tvec, (char *)ap, EF_SECTOR); - } + if (inc < 0) + inc = 0; + tvec[C_FALLOUT] += inc; + putvec(VT_COND, tvec, (char *)ap, EF_SECTOR); + } } void decay_fallout(struct sctstr *sp, int etus) { - extern double decay_per_etu; - extern double fallout_spread; - int cvec[I_MAX+1]; - int decay; + extern double decay_per_etu; + extern double fallout_spread; + int cvec[I_MAX + 1]; + int decay; - if (etus > 24) - etus = 24; - getvec(VT_COND, cvec, (char *)sp, EF_SECTOR); - decay = roundavg(((decay_per_etu + 6.0) * fallout_spread) * - (double)etus * (double)cvec[C_FALLOUT]); + if (etus > 24) + etus = 24; + getvec(VT_COND, cvec, (char *)sp, EF_SECTOR); + decay = roundavg(((decay_per_etu + 6.0) * fallout_spread) * + (double)etus * (double)cvec[C_FALLOUT]); #if 0 - if (decay || cvec[C_FALLOUT]) - wu(0,0,"Fallout decay in %d,%d is %d from %d\n", sp->sct_x, sp->sct_y, decay, cvec[C_FALLOUT]); + if (decay || cvec[C_FALLOUT]) + wu(0, 0, "Fallout decay in %d,%d is %d from %d\n", sp->sct_x, + sp->sct_y, decay, cvec[C_FALLOUT]); #endif - cvec[C_FALLOUT] = (decay < cvec[C_FALLOUT]) ? (cvec[C_FALLOUT] - decay) : 0; - if (cvec[C_FALLOUT] < 0) - cvec[C_FALLOUT] = 0; - putvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); + cvec[C_FALLOUT] = + (decay < cvec[C_FALLOUT]) ? (cvec[C_FALLOUT] - decay) : 0; + if (cvec[C_FALLOUT] < 0) + cvec[C_FALLOUT] = 0; + putvec(VT_COND, cvec, (s_char *)sp, EF_SECTOR); } #define SHOULD_PRODUCE(sp,t) (((sp->sct_type == t) || (t == -1)) ? 1 : 0) @@ -360,151 +361,156 @@ decay_fallout(struct sctstr *sp, int etus) * */ void -produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2], int sector_type) +produce_sect(int natnum, int etu, int *bp, long int (*p_sect)[2], + int sector_type) { - register struct sctstr *sp; - register struct natstr *np; - int vec[I_MAX+1]; - int work, cost, ecost, pcost, sctwork; - int n, desig, maxpop, neweff, amount; - - for (n=0; NULL != (sp = getsectid(n)); n++) { - if (sp->sct_type == SCT_WATER) - continue; - if (sp->sct_own != natnum) - continue; - if (sp->sct_updated != 0) - continue; - if (!SHOULD_PRODUCE(sp,sector_type)) - continue; - - if ((sp->sct_type == SCT_CAPIT) && (sp->sct_effic > 60)) { - p_sect[SCT_CAPIT][0]++; - p_sect[SCT_CAPIT][1] += etu; - } - - if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) - continue; - /* If everybody is dead, the sector reverts to unowned. - * This is also checked at the end of the production in - * they all starved or were plagued off. - */ - if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && - !has_units(sp->sct_x,sp->sct_y,sp->sct_own,0)) { - makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); - sp->sct_own = 0; - sp->sct_oldown = 0; - continue; - } - - sp->sct_updated = 1; - work = 0; - - np = getnatp(natnum); - - /* do_feed trys to supply. So, we need to enable cacheing - here */ - bp_enable_cachepath(); - - sctwork = do_feed(sp, np, vec, &work, bp, etu); - - bp_disable_cachepath(); - bp_clear_cachepath(); - - if (sp->sct_off || np->nat_money < 0) { - if (!player->simulation) { - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - sp->sct_off = 0; - } - continue; - } - if ((np->nat_priorities[sp->sct_type] == 0) && - (sp->sct_type == sp->sct_newtype) && - ((pchr[dchr[sp->sct_type].d_prd].p_cost != 0) || - (sp->sct_type == SCT_ENLIST))){ - if (!player->simulation) { - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - logerror("Skipping %s production for country %s\n", - dchr[sp->sct_type].d_name,np->nat_cnam); - } - continue; - } - - neweff = sp->sct_effic; - amount = 0; - pcost = cost = ecost = 0; - - desig = sp->sct_type; - - if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) && - np->nat_money > 0) { - neweff = upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork, &cost); - pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]); - pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]); - p_sect[SCT_EFFIC][0]++; - p_sect[SCT_EFFIC][1] += cost; - if (!player->simulation) { - np->nat_money -= cost; - /* No longer tear down infrastructure - if (sp->sct_type != desig) { - sp->sct_road = 0; - sp->sct_defense = 0; - } else if (neweff < sp->sct_effic) { - sp->sct_road -= (sp->sct_road * (sp->sct_effic - neweff) / 100.0); - sp->sct_defense -= (sp->sct_defense * (sp->sct_effic - neweff) / 100.0); - if (sp->sct_road < 0) - sp->sct_road = 0; - if (sp->sct_defense < 0) - sp->sct_defense = 0; - } - */ - sp->sct_type = desig; - sp->sct_effic = neweff; - if (!opt_DEFENSE_INFRA) - sp->sct_defense = sp->sct_effic; - } - } - - if ((np->nat_priorities[desig] == 0) && - ((pchr[dchr[desig].d_prd].p_cost != 0) || - (desig == SCT_ENLIST))) { - if (!player->simulation) { - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - logerror("Skipping %s production for country %s\n", - dchr[sp->sct_type].d_name,np->nat_cnam); - } - continue; - } - - if (desig == SCT_ENLIST && neweff >= 60 && - sp->sct_own == sp->sct_oldown) { - p_sect[desig][0] += enlist(vec, etu, &ecost); - p_sect[desig][1] += ecost; - if (!player->simulation) - np->nat_money -= ecost; - } - - /* - * now do the production (if sector effic >= 60%) - */ - - if (neweff >= 60) { - if (np->nat_money > 0 && dchr[desig].d_prd) - work -= produce(np, sp, vec, work, sctwork, desig, neweff, &pcost, &amount); - } - - pt_bg_nmbr(bp, sp, I_MAX+1, work); - p_sect[desig][0] += amount; - p_sect[desig][1] += pcost; - if (!player->simulation) { - maxpop = max_pop(np->nat_level[NAT_RLEV], sp); - if (vec[I_CIVIL] > maxpop) - vec[I_CIVIL] = maxpop; - if (vec[I_UW] > maxpop) - vec[I_UW] = maxpop; - putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); - sp->sct_avail = work; - np->nat_money -= pcost; - } + register struct sctstr *sp; + register struct natstr *np; + int vec[I_MAX + 1]; + int work, cost, ecost, pcost, sctwork; + int n, desig, maxpop, neweff, amount; + + for (n = 0; NULL != (sp = getsectid(n)); n++) { + if (sp->sct_type == SCT_WATER) + continue; + if (sp->sct_own != natnum) + continue; + if (sp->sct_updated != 0) + continue; + if (!SHOULD_PRODUCE(sp, sector_type)) + continue; + + if ((sp->sct_type == SCT_CAPIT) && (sp->sct_effic > 60)) { + p_sect[SCT_CAPIT][0]++; + p_sect[SCT_CAPIT][1] += etu; } + + if (getvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR) <= 0) + continue; + /* If everybody is dead, the sector reverts to unowned. + * This is also checked at the end of the production in + * they all starved or were plagued off. + */ + if (vec[I_CIVIL] == 0 && vec[I_MILIT] == 0 && + !has_units(sp->sct_x, sp->sct_y, sp->sct_own, 0)) { + makelost(EF_SECTOR, sp->sct_own, 0, sp->sct_x, sp->sct_y); + sp->sct_own = 0; + sp->sct_oldown = 0; + continue; + } + + sp->sct_updated = 1; + work = 0; + + np = getnatp(natnum); + + /* do_feed trys to supply. So, we need to enable cacheing + here */ + bp_enable_cachepath(); + + sctwork = do_feed(sp, np, vec, &work, bp, etu); + + bp_disable_cachepath(); + bp_clear_cachepath(); + + if (sp->sct_off || np->nat_money < 0) { + if (!player->simulation) { + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + sp->sct_off = 0; + } + continue; + } + if ((np->nat_priorities[sp->sct_type] == 0) && + (sp->sct_type == sp->sct_newtype) && + ((pchr[dchr[sp->sct_type].d_prd].p_cost != 0) || + (sp->sct_type == SCT_ENLIST))) { + if (!player->simulation) { + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + logerror("Skipping %s production for country %s\n", + dchr[sp->sct_type].d_name, np->nat_cnam); + } + continue; + } + + neweff = sp->sct_effic; + amount = 0; + pcost = cost = ecost = 0; + + desig = sp->sct_type; + + if ((sp->sct_effic < 100 || sp->sct_type != sp->sct_newtype) && + np->nat_money > 0) { + neweff = + upd_buildeff(np, sp, &work, vec, etu, &desig, sctwork, + &cost); + pt_bg_nmbr(bp, sp, I_LCM, vec[I_LCM]); + pt_bg_nmbr(bp, sp, I_HCM, vec[I_HCM]); + p_sect[SCT_EFFIC][0]++; + p_sect[SCT_EFFIC][1] += cost; + if (!player->simulation) { + np->nat_money -= cost; + /* No longer tear down infrastructure + if (sp->sct_type != desig) { + sp->sct_road = 0; + sp->sct_defense = 0; + } else if (neweff < sp->sct_effic) { + sp->sct_road -= (sp->sct_road * (sp->sct_effic - neweff) / 100.0); + sp->sct_defense -= (sp->sct_defense * (sp->sct_effic - neweff) / 100.0); + if (sp->sct_road < 0) + sp->sct_road = 0; + if (sp->sct_defense < 0) + sp->sct_defense = 0; + } + */ + sp->sct_type = desig; + sp->sct_effic = neweff; + if (!opt_DEFENSE_INFRA) + sp->sct_defense = sp->sct_effic; + } + } + + if ((np->nat_priorities[desig] == 0) && + ((pchr[dchr[desig].d_prd].p_cost != 0) || + (desig == SCT_ENLIST))) { + if (!player->simulation) { + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + logerror("Skipping %s production for country %s\n", + dchr[sp->sct_type].d_name, np->nat_cnam); + } + continue; + } + + if (desig == SCT_ENLIST && neweff >= 60 && + sp->sct_own == sp->sct_oldown) { + p_sect[desig][0] += enlist(vec, etu, &ecost); + p_sect[desig][1] += ecost; + if (!player->simulation) + np->nat_money -= ecost; + } + + /* + * now do the production (if sector effic >= 60%) + */ + + if (neweff >= 60) { + if (np->nat_money > 0 && dchr[desig].d_prd) + work -= + produce(np, sp, vec, work, sctwork, desig, neweff, + &pcost, &amount); + } + + pt_bg_nmbr(bp, sp, I_MAX + 1, work); + p_sect[desig][0] += amount; + p_sect[desig][1] += pcost; + if (!player->simulation) { + maxpop = max_pop(np->nat_level[NAT_RLEV], sp); + if (vec[I_CIVIL] > maxpop) + vec[I_CIVIL] = maxpop; + if (vec[I_UW] > maxpop) + vec[I_UW] = maxpop; + putvec(VT_ITEM, vec, (s_char *)sp, EF_SECTOR); + sp->sct_avail = work; + np->nat_money -= pcost; + } + } } diff --git a/src/lib/update/ship.c b/src/lib/update/ship.c index 02ff1ef46..fa83cb94e 100644 --- a/src/lib/update/ship.c +++ b/src/lib/update/ship.c @@ -58,201 +58,199 @@ int prod_ship(int etus, int natnum, int *bp, int build) - /* build = 1, maintain = 0 */ + /* build = 1, maintain = 0 */ { - register struct shpstr *sp; - struct natstr *np; - int n, k=0; - extern long sea_money[MAXNOC]; - int start_money; - int lastx = 9999, lasty = 9999; - - bp_enable_cachepath(); - for (n=0; NULL != (sp = getshipp(n)); n++) { - if (sp->shp_own == 0) - continue; - if (sp->shp_own != natnum) - continue; - np = getnatp(sp->shp_own); - start_money = np->nat_money; - if (lastx == 9999 || lasty == 9999) { - lastx = sp->shp_x; - lasty = sp->shp_y; - } - if (lastx != sp->shp_x || lasty != sp->shp_y) { - /* Reset the cache */ - bp_disable_cachepath(); - bp_clear_cachepath(); - bp_enable_cachepath(); - } - upd_ship(sp, n, etus, np, bp, build); - if (build && !player->simulation) /* make sure to only autonav once */ - nav_ship(sp); /* autonav the ship */ - sea_money[sp->shp_own] += np->nat_money - start_money; - if ((build && (np->nat_money != start_money)) || (!build)) - k++; - if (player->simulation) - np->nat_money = start_money; + register struct shpstr *sp; + struct natstr *np; + int n, k = 0; + extern long sea_money[MAXNOC]; + int start_money; + int lastx = 9999, lasty = 9999; + + bp_enable_cachepath(); + for (n = 0; NULL != (sp = getshipp(n)); n++) { + if (sp->shp_own == 0) + continue; + if (sp->shp_own != natnum) + continue; + np = getnatp(sp->shp_own); + start_money = np->nat_money; + if (lastx == 9999 || lasty == 9999) { + lastx = sp->shp_x; + lasty = sp->shp_y; } - bp_disable_cachepath(); - bp_clear_cachepath(); - - if (opt_SAIL) { - if (build && !player->simulation) /* make sure to only sail once */ - sail_ship(natnum); + if (lastx != sp->shp_x || lasty != sp->shp_y) { + /* Reset the cache */ + bp_disable_cachepath(); + bp_clear_cachepath(); + bp_enable_cachepath(); } - return k; + upd_ship(sp, n, etus, np, bp, build); + if (build && !player->simulation) /* make sure to only autonav once */ + nav_ship(sp); /* autonav the ship */ + sea_money[sp->shp_own] += np->nat_money - start_money; + if ((build && (np->nat_money != start_money)) || (!build)) + k++; + if (player->simulation) + np->nat_money = start_money; + } + bp_disable_cachepath(); + bp_clear_cachepath(); + + if (opt_SAIL) { + if (build && !player->simulation) /* make sure to only sail once */ + sail_ship(natnum); + } + return k; } void -upd_ship(register struct shpstr *sp, int shipno, register int etus, struct natstr *np, int *bp, int build) - /* build = 1, maintain = 0 */ +upd_ship(register struct shpstr *sp, int shipno, register int etus, + struct natstr *np, int *bp, int build) + /* build = 1, maintain = 0 */ { - extern long pops[]; - struct sctstr *sectp; - struct mchrstr *mp; - int vec[I_MAX+1]; - int cvec[I_MAX+1]; - int oil_gained; - int max_oil; - int max_food; - struct pchrstr *product; - s_char *resource; - int n; - int mult; - extern double money_ship; - int needed; - int cost; - int eff; - - mp = &mchr[(int)sp->shp_type]; - getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); - if (build == 1){ - if (np->nat_priorities[PRI_SBUILD] == 0 || - np->nat_money < 0) - return; - if (sp->shp_effic < SHIP_MINEFF || - !shiprepair(sp, vec, np, bp, etus)) { - makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); - sp->shp_own = 0; - return; - } - }else{ - mult = 1; - if (np->nat_level[NAT_TLEV] < sp->shp_tech * 0.85) - mult = 2; - cost = -(mult * etus * dmin(0.0, money_ship * mp->m_cost)); - if ((np->nat_priorities[PRI_SMAINT] == 0 || - np->nat_money < cost) && !player->simulation){ - if ((eff = sp->shp_effic - etus/5) < SHIP_MINEFF) { - wu(0, sp->shp_own, - "%s lost to lack of maintenance\n", - prship(sp)); - makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y); - sp->shp_own = 0; - return; - } - wu(0, sp->shp_own, - "%s lost %d%% to lack of maintenance\n", - prship(sp), sp->shp_effic - eff); - sp->shp_effic = eff; - } else { - np->nat_money -= cost; - } + extern long pops[]; + struct sctstr *sectp; + struct mchrstr *mp; + int vec[I_MAX + 1]; + int cvec[I_MAX + 1]; + int oil_gained; + int max_oil; + int max_food; + struct pchrstr *product; + s_char *resource; + int n; + int mult; + extern double money_ship; + int needed; + int cost; + int eff; + + mp = &mchr[(int)sp->shp_type]; + getvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); + if (build == 1) { + if (np->nat_priorities[PRI_SBUILD] == 0 || np->nat_money < 0) + return; + if (sp->shp_effic < SHIP_MINEFF || + !shiprepair(sp, vec, np, bp, etus)) { + makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, + sp->shp_y); + sp->shp_own = 0; + return; + } + } else { + mult = 1; + if (np->nat_level[NAT_TLEV] < sp->shp_tech * 0.85) + mult = 2; + cost = -(mult * etus * dmin(0.0, money_ship * mp->m_cost)); + if ((np->nat_priorities[PRI_SMAINT] == 0 || + np->nat_money < cost) && !player->simulation) { + if ((eff = sp->shp_effic - etus / 5) < SHIP_MINEFF) { + wu(0, sp->shp_own, + "%s lost to lack of maintenance\n", prship(sp)); + makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, + sp->shp_y); + sp->shp_own = 0; + return; + } + wu(0, sp->shp_own, + "%s lost %d%% to lack of maintenance\n", + prship(sp), sp->shp_effic - eff); + sp->shp_effic = eff; + } else { + np->nat_money -= cost; + } - sectp = getsectp(sp->shp_x, sp->shp_y); - if (((mp->m_flags & M_OIL) && (sectp->sct_type == SCT_WATER)) - && !player->simulation){ - /* - * take care of oil production - */ - oil_gained = roundavg((vec[I_CIVIL] * etus / 10000.0) - * sectp->sct_oil); - vec[I_OIL] += oil_gained; - max_oil = vl_find(V_OIL,mp->m_vtype,mp->m_vamt,mp->m_nv); - if (vec[I_OIL] > max_oil) - vec[I_OIL] = max_oil; - product = &pchr[P_OIL]; - if (product->p_nrdep != 0 && oil_gained > 0) { - resource = ((s_char *)sectp) + product->p_nrndx; - *resource -= roundavg(oil_gained * - product->p_nrdep / 100.0); - } - } else if (((mp->m_flags&M_FOOD)&&(sectp->sct_type==SCT_WATER)) && !player->simulation){ - sectp = getsectp(sp->shp_x, sp->shp_y); - vec[I_FOOD] += ((vec[I_CIVIL] * etus) / 1000.0) - * sectp->sct_fertil; - } + sectp = getsectp(sp->shp_x, sp->shp_y); + if (((mp->m_flags & M_OIL) && (sectp->sct_type == SCT_WATER)) + && !player->simulation) { + /* + * take care of oil production + */ + oil_gained = roundavg((vec[I_CIVIL] * etus / 10000.0) + * sectp->sct_oil); + vec[I_OIL] += oil_gained; + max_oil = vl_find(V_OIL, mp->m_vtype, mp->m_vamt, mp->m_nv); + if (vec[I_OIL] > max_oil) + vec[I_OIL] = max_oil; + product = &pchr[P_OIL]; + if (product->p_nrdep != 0 && oil_gained > 0) { + resource = ((s_char *)sectp) + product->p_nrndx; + *resource -= roundavg(oil_gained * + product->p_nrdep / 100.0); + } + } else + if (((mp->m_flags & M_FOOD) && (sectp->sct_type == SCT_WATER)) + && !player->simulation) { + sectp = getsectp(sp->shp_x, sp->shp_y); + vec[I_FOOD] += ((vec[I_CIVIL] * etus) / 1000.0) + * sectp->sct_fertil; + } /* Military costs are now part of regular military costs, not ship costs */ /* np->nat_money += (int) (etus * vec[I_MILIT] * money_mil);*/ - if (!player->simulation){ - if ((n = feed_ship(sp,vec,etus, &needed, 1)) > 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); + if (!player->simulation) { + if ((n = feed_ship(sp, vec, etus, &needed, 1)) > 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 = vl_find(V_FOOD, mp->m_vtype, mp->m_vamt, mp->m_nv); + if (vec[I_FOOD] > max_food) + vec[I_FOOD] = max_food; + /* + * do plague stuff. plague can't break out on ships, + * but it can still kill people. + */ + getvec(VT_COND, cvec, (s_char *)sp, EF_SHIP); + if (cvec[C_PSTAGE] > 0) { + n = plague_people(np, vec, cvec, 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 == cvec[C_PSTAGE]) { + /* Yes. Will it turn "infectious" next time? */ + if (cvec[C_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); } - max_food = vl_find(V_FOOD, mp->m_vtype, mp->m_vamt, mp->m_nv); - if (vec[I_FOOD] > max_food) - vec[I_FOOD] = max_food; - /* - * do plague stuff. plague can't break out on ships, - * but it can still kill people. - */ - getvec(VT_COND, cvec, (s_char *)sp, EF_SHIP); - if (cvec[C_PSTAGE] > 0) { - n = plague_people(np, vec, cvec, 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 == cvec[C_PSTAGE]) { - /* Yes. Will it turn "infectious" next time? */ - if (cvec[C_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 != cvec[C_PSTAGE]) { - /* Yes. Will it turn "infectious" next time? */ - if (cvec[C_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; - } - - putvec(VT_COND, cvec, (s_char *)sp, EF_SHIP); + } 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 != cvec[C_PSTAGE]) { + /* Yes. Will it turn "infectious" next time? */ + if (cvec[C_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); } - putvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); - pops[sp->shp_own] += vec[I_CIVIL]; + } + break; + default: + break; } + + putvec(VT_COND, cvec, (s_char *)sp, EF_SHIP); + } + putvec(VT_ITEM, vec, (s_char *)sp, EF_SHIP); + pops[sp->shp_own] += vec[I_CIVIL]; } + } } /* @@ -261,269 +259,270 @@ upd_ship(register struct shpstr *sp, int shipno, register int etus, struct natst * 8 * 8 * $40 = $2560! */ int -shiprepair(register struct shpstr *ship, int *vec, struct natstr *np, int *bp, int etus) +shiprepair(register struct shpstr *ship, int *vec, struct natstr *np, + int *bp, int etus) { - extern int ship_grow_scale; - register int delta; - struct sctstr *sp; - struct mchrstr *mp; - float leftp, buildp; - int left, build; - int lcm_needed, hcm_needed; - int wf; - int avail; - int w_p_eff; - int mult; - int svec[I_MAX+1]; - int mvec[I_MAX+1]; - int rel; - - mp = &mchr[(int)ship->shp_type]; - sp = getsectp(ship->shp_x, ship->shp_y); - - if ((sp->sct_own != ship->shp_own) && (sp->sct_own != 0)) { - rel=getrel(getnatp(sp->sct_own),ship->shp_own); - - if (rel < FRIENDLY) - return 1; - } - - wf = 0; - /* only military can work on a military boat */ - if (ship->shp_glim > 0) - wf = etus * vec[I_MILIT]/2; + extern int ship_grow_scale; + register int delta; + struct sctstr *sp; + struct mchrstr *mp; + float leftp, buildp; + int left, build; + int lcm_needed, hcm_needed; + int wf; + int avail; + int w_p_eff; + int mult; + int svec[I_MAX + 1]; + int mvec[I_MAX + 1]; + int rel; + + mp = &mchr[(int)ship->shp_type]; + sp = getsectp(ship->shp_x, ship->shp_y); + + if ((sp->sct_own != ship->shp_own) && (sp->sct_own != 0)) { + rel = getrel(getnatp(sp->sct_own), ship->shp_own); + + if (rel < FRIENDLY) + return 1; + } + + wf = 0; + /* only military can work on a military boat */ + if (ship->shp_glim > 0) + wf = etus * vec[I_MILIT] / 2; + else + wf = etus * (vec[I_CIVIL] / 2 + vec[I_MILIT] / 5); + + if (sp->sct_type != SCT_HARBR) { + wf /= 3; + avail = wf; + } else { + if (!player->simulation) + avail = wf + sp->sct_avail * 100; else - wf = etus * (vec[I_CIVIL]/2 + vec[I_MILIT]/5); - - if (sp->sct_type != SCT_HARBR){ - wf /= 3; - avail = wf; - }else{ - if (!player->simulation) - avail = wf + sp->sct_avail * 100; - else - avail = wf + gt_bg_nmbr(bp, sp, I_MAX+1) * 100; - } - - w_p_eff = 20 + (mp->m_lcm + 2 * mp->m_hcm); - - if (sp->sct_type != SCT_HARBR){ - int abs_max, amt; - - if (ship->shp_glim > 0){ - abs_max = vl_find(V_MILIT, mp->m_vtype, - mp->m_vamt, (int) mp->m_nv); - amt = vec[I_MILIT]; - }else{ - abs_max = vl_find(V_CIVIL, mp->m_vtype, - mp->m_vamt, (int) mp->m_nv); - amt = vec[I_CIVIL]; - if (abs_max==0) { - abs_max = vl_find(V_MILIT, mp->m_vtype, mp->m_vamt, - (int) mp->m_nv); - amt = vec[I_MILIT]; - } - } - - if (abs_max == 0){ - logerror("Abs max of 0 for ship %d\n",ship->shp_uid); - abs_max = 1; - } - avail -= (etus * (100-((amt*100)/abs_max)))/7; - /* think of it as entropy in action */ + avail = wf + gt_bg_nmbr(bp, sp, I_MAX + 1) * 100; + } + + w_p_eff = 20 + (mp->m_lcm + 2 * mp->m_hcm); + + if (sp->sct_type != SCT_HARBR) { + int abs_max, amt; + + if (ship->shp_glim > 0) { + abs_max = vl_find(V_MILIT, mp->m_vtype, + mp->m_vamt, (int)mp->m_nv); + amt = vec[I_MILIT]; + } else { + abs_max = vl_find(V_CIVIL, mp->m_vtype, + mp->m_vamt, (int)mp->m_nv); + amt = vec[I_CIVIL]; + if (abs_max == 0) { + abs_max = vl_find(V_MILIT, mp->m_vtype, mp->m_vamt, + (int)mp->m_nv); + amt = vec[I_MILIT]; + } } - if (avail <= 0){ - if (!player->simulation) { - if (opt_SHIP_DECAY) { - ship->shp_effic += avail/w_p_eff; + if (abs_max == 0) { + logerror("Abs max of 0 for ship %d\n", ship->shp_uid); + abs_max = 1; + } + avail -= (etus * (100 - ((amt * 100) / abs_max))) / 7; + /* think of it as entropy in action */ + } + + if (avail <= 0) { + if (!player->simulation) { + if (opt_SHIP_DECAY) { + ship->shp_effic += avail / w_p_eff; } return 1; - } } + } - if ((sp->sct_off) && (sp->sct_own == ship->shp_own)) - return 1; + if ((sp->sct_off) && (sp->sct_own == ship->shp_own)) + return 1; - getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); + getvec(VT_ITEM, svec, (s_char *)sp, EF_SECTOR); - mult = 1; - if (np->nat_level[NAT_TLEV] < ship->shp_tech * 0.85) - mult = 2; + mult = 1; + if (np->nat_level[NAT_TLEV] < ship->shp_tech * 0.85) + mult = 2; - if (ship->shp_effic == 100) { - /* ship is ok; no repairs needed */ - return 1; - } + if (ship->shp_effic == 100) { + /* ship is ok; no repairs needed */ + return 1; + } - left = 100 - ship->shp_effic; - delta = roundavg((double)avail/w_p_eff); - if (delta <= 0) - return 1; - if (delta > etus*ship_grow_scale) - delta = etus*ship_grow_scale; - if (delta > left) - delta = left; - - /* delta is the max amount we can grow */ - - left = 100 - ship->shp_effic; - if (left > delta) - left = delta; - - leftp = ((float)left/100.0); - bzero((s_char *)mvec, sizeof(mvec)); - mvec[I_LCM] = lcm_needed = ldround((double)(mp->m_lcm * leftp),1); - mvec[I_HCM] = hcm_needed = ldround((double)(mp->m_hcm * leftp),1); - - get_materials(sp, bp, mvec, 0); - - if (mvec[I_LCM]>=lcm_needed) - buildp=leftp; - else - 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((double)(buildp*100.0),1); - bzero((s_char *)mvec, sizeof(mvec)); - mvec[I_LCM] = lcm_needed = roundavg((double)(mp->m_lcm * buildp)); - mvec[I_HCM] = hcm_needed = roundavg((double)(mp->m_hcm * buildp)); - - get_materials(sp, bp, mvec, 1); - - if (sp->sct_type != SCT_HARBR) - build = delta; - wf -= build * w_p_eff; - if (wf < 0) { - /* - * I didn't use roundavg here, because I want to penalize - * the player with a large number of ships. - */ - if (!player->simulation) - avail = (sp->sct_avail * 100 + wf) / 100; - else - avail = (gt_bg_nmbr(bp,sp,I_MAX+1) * 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); - } - if (sp->sct_type != SCT_HARBR) - if ((build+ship->shp_effic)>80){ - build = 80 - ship->shp_effic; - if (build < 0) - build = 0; - } - - np->nat_money -= mult * mp->m_cost * build / 100.0; - if (!player->simulation) - ship->shp_effic += (s_char)build; + left = 100 - ship->shp_effic; + delta = roundavg((double)avail / w_p_eff); + if (delta <= 0) return 1; + if (delta > etus * ship_grow_scale) + delta = etus * ship_grow_scale; + if (delta > left) + delta = left; + + /* delta is the max amount we can grow */ + + left = 100 - ship->shp_effic; + if (left > delta) + left = delta; + + leftp = ((float)left / 100.0); + bzero((s_char *)mvec, sizeof(mvec)); + mvec[I_LCM] = lcm_needed = ldround((double)(mp->m_lcm * leftp), 1); + mvec[I_HCM] = hcm_needed = ldround((double)(mp->m_hcm * leftp), 1); + + get_materials(sp, bp, mvec, 0); + + if (mvec[I_LCM] >= lcm_needed) + buildp = leftp; + else + 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((double)(buildp * 100.0), 1); + bzero((s_char *)mvec, sizeof(mvec)); + mvec[I_LCM] = lcm_needed = roundavg((double)(mp->m_lcm * buildp)); + mvec[I_HCM] = hcm_needed = roundavg((double)(mp->m_hcm * buildp)); + + get_materials(sp, bp, mvec, 1); + + if (sp->sct_type != SCT_HARBR) + build = delta; + wf -= build * w_p_eff; + if (wf < 0) { + /* + * I didn't use roundavg here, because I want to penalize + * the player with a large number of ships. + */ + if (!player->simulation) + avail = (sp->sct_avail * 100 + wf) / 100; + else + avail = (gt_bg_nmbr(bp, sp, I_MAX + 1) * 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); + } + if (sp->sct_type != SCT_HARBR) + if ((build + ship->shp_effic) > 80) { + build = 80 - ship->shp_effic; + if (build < 0) + build = 0; + } + + np->nat_money -= mult * mp->m_cost * build / 100.0; + if (!player->simulation) + ship->shp_effic += (s_char)build; + return 1; } /* * returns the number who starved, if any. */ int -feed_ship(struct shpstr *sp, register int *vec, int etus, int *needed, int doit) +feed_ship(struct shpstr *sp, register int *vec, int etus, int *needed, + int doit) { - extern double eatrate; - double food_eaten, land_eaten; - double people_left; - int ifood_eaten; - int can_eat, need; - int total_people; - int to_starve; - int starved, lvec[I_MAX+1]; - struct nstr_item ni; - struct lndstr *lp; - s_char *nxtitemp(struct nstr_item *np, int owner); - - if (opt_NOFOOD) return 0; /* no food no work to do */ - - food_eaten = (etus * eatrate) * (vec[I_CIVIL]+vec[I_MILIT]+vec[I_UW]); - ifood_eaten = (int)food_eaten; - if ((food_eaten-ifood_eaten) > 0) - ifood_eaten++; - starved = 0; - *needed = 0; - if (!player->simulation && - food_eaten > vec[I_FOOD]) - vec[I_FOOD] += supply_commod(sp->shp_own,sp->shp_x,sp->shp_y, - I_FOOD,(ifood_eaten-vec[I_FOOD])); - - if (food_eaten > vec[I_FOOD]) { + extern double eatrate; + double food_eaten, land_eaten; + double people_left; + int ifood_eaten; + int can_eat, need; + int total_people; + int to_starve; + int starved, lvec[I_MAX + 1]; + struct nstr_item ni; + struct lndstr *lp; + s_char *nxtitemp(struct nstr_item *np, int owner); + + if (opt_NOFOOD) + return 0; /* no food no work to do */ + + food_eaten = + (etus * eatrate) * (vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]); + ifood_eaten = (int)food_eaten; + if ((food_eaten - ifood_eaten) > 0) + ifood_eaten++; + starved = 0; + *needed = 0; + if (!player->simulation && food_eaten > vec[I_FOOD]) + vec[I_FOOD] += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y, + I_FOOD, (ifood_eaten - vec[I_FOOD])); + + if (food_eaten > vec[I_FOOD]) { /* doit - only steal food from land units during the update */ - if (sp->shp_nland > 0 && doit) { - snxtitem_all(&ni,EF_LAND); - while((lp=(struct lndstr *)nxtitemp(&ni, 0)) && - (food_eaten > vec[I_FOOD])){ - if (lp->lnd_ship != sp->shp_uid) - continue; - need = ifood_eaten - vec[I_FOOD]; - getvec(VT_ITEM, lvec, (s_char *)lp, EF_LAND); - land_eaten = (etus * eatrate) * - (double)lnd_getmil(lp); - if (lvec[I_FOOD]-need > land_eaten){ - vec[I_FOOD] += need; - lvec[I_FOOD] -= need; - }else if ((lvec[I_FOOD]-land_eaten) > 0){ - vec[I_FOOD]+= (lvec[I_FOOD]-land_eaten); - lvec[I_FOOD]-=(lvec[I_FOOD]-land_eaten); - } - putvec(VT_ITEM, lvec, (s_char *)lp, EF_LAND); - } + if (sp->shp_nland > 0 && doit) { + snxtitem_all(&ni, EF_LAND); + while ((lp = (struct lndstr *)nxtitemp(&ni, 0)) && + (food_eaten > vec[I_FOOD])) { + if (lp->lnd_ship != sp->shp_uid) + continue; + need = ifood_eaten - vec[I_FOOD]; + getvec(VT_ITEM, lvec, (s_char *)lp, EF_LAND); + land_eaten = (etus * eatrate) * (double)lnd_getmil(lp); + if (lvec[I_FOOD] - need > land_eaten) { + vec[I_FOOD] += need; + lvec[I_FOOD] -= need; + } else if ((lvec[I_FOOD] - land_eaten) > 0) { + vec[I_FOOD] += (lvec[I_FOOD] - land_eaten); + lvec[I_FOOD] -= (lvec[I_FOOD] - land_eaten); } + putvec(VT_ITEM, lvec, (s_char *)lp, EF_LAND); + } } + } + + if (food_eaten > vec[I_FOOD]) { + *needed = food_eaten - vec[I_FOOD]; + if (*needed < (food_eaten - vec[I_FOOD])) + (*needed)++; + if (opt_NEW_STARVE) { + can_eat = (vec[I_FOOD] / (etus * eatrate)); + total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; + + /* only want to starve off at most 1/2 the populace. */ + if (can_eat < (total_people / 2)) + can_eat = total_people / 2; + + to_starve = total_people - can_eat; + while (to_starve && vec[I_UW]) { + to_starve--; + starved++; + vec[I_UW]--; + } + while (to_starve && vec[I_CIVIL]) { + to_starve--; + starved++; + vec[I_CIVIL]--; + } + while (to_starve && vec[I_MILIT]) { + to_starve--; + starved++; + vec[I_MILIT]--; + } - if (food_eaten > vec[I_FOOD]){ - *needed = food_eaten - vec[I_FOOD]; - if (*needed < (food_eaten - vec[I_FOOD])) - (*needed)++; - if (opt_NEW_STARVE) { - can_eat = (vec[I_FOOD] / (etus * eatrate)); - total_people = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; - - /* only want to starve off at most 1/2 the populace. */ - if (can_eat < (total_people/2)) - can_eat = total_people/2; - - to_starve = total_people - can_eat; - while(to_starve && vec[I_UW]){ - to_starve--; - starved++; - vec[I_UW]--; - } - while(to_starve && vec[I_CIVIL]){ - to_starve--; - starved++; - vec[I_CIVIL]--; - } - while(to_starve && vec[I_MILIT]){ - to_starve--; - starved++; - vec[I_MILIT]--; - } - - vec[I_FOOD] = 0; - } - else { /* ! opt_NEW_STARVE */ - people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01); - starved = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; - /* only want to starve off at most 1/2 the populace. */ - if (people_left < 0.5) - people_left = 0.5; - vec[I_CIVIL] = (int) (vec[I_CIVIL] * people_left); - vec[I_MILIT] = (int) (vec[I_MILIT] * people_left); - vec[I_UW] = (int) (vec[I_UW] * people_left); - starved -= vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; - vec[I_FOOD] = 0; - } - } else { - vec[I_FOOD] -= (int)food_eaten; + vec[I_FOOD] = 0; + } else { /* ! opt_NEW_STARVE */ + people_left = (vec[I_FOOD] + 0.01) / (food_eaten + 0.01); + starved = vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; + /* only want to starve off at most 1/2 the populace. */ + if (people_left < 0.5) + people_left = 0.5; + vec[I_CIVIL] = (int)(vec[I_CIVIL] * people_left); + vec[I_MILIT] = (int)(vec[I_MILIT] * people_left); + vec[I_UW] = (int)(vec[I_UW] * people_left); + starved -= vec[I_CIVIL] + vec[I_MILIT] + vec[I_UW]; + vec[I_FOOD] = 0; } - return starved; + } else { + vec[I_FOOD] -= (int)food_eaten; + } + return starved; } diff --git a/src/server/idle.c b/src/server/idle.c index b0dd6de48..60b197826 100644 --- a/src/server/idle.c +++ b/src/server/idle.c @@ -41,43 +41,41 @@ /*ARGSUSED*/ void player_kill_idle(argv) - void *argv; +void *argv; { - extern int max_idle; - struct player *p; - time_t now; + extern int max_idle; + struct player *p; + time_t now; + time(&now); + while (1) { + empth_sleep(now + 60); time(&now); - while (1) { - empth_sleep(now + 60); - time(&now); - /*if (update_pending)*/ - /*continue;*/ - for (p = player_next(0); p != 0; p = player_next(p)) { - if (p->state == PS_SHUTDOWN) { - /* no more mr. nice guy */ - p->state = PS_KILL; - p->aborted++; - empth_terminate(p->proc); - p = player_delete(p); - continue; - } - if (p->curup + max_idle * 60 < now) { - p->state = PS_SHUTDOWN; - /* giving control to another thread while - * in the middle of walking player list is - * not a good idea at all. Sasha */ - p->aborted++; - pr_flash(p, - "idle connection terminated\n"); - empth_wakeup(p->proc); - /* go to sleep because player thread - could vandalize a player list */ - - break; - } - } + /*if (update_pending) */ + /*continue; */ + for (p = player_next(0); p != 0; p = player_next(p)) { + if (p->state == PS_SHUTDOWN) { + /* no more mr. nice guy */ + p->state = PS_KILL; + p->aborted++; + empth_terminate(p->proc); + p = player_delete(p); + continue; + } + if (p->curup + max_idle * 60 < now) { + p->state = PS_SHUTDOWN; + /* giving control to another thread while + * in the middle of walking player list is + * not a good idea at all. Sasha */ + p->aborted++; + pr_flash(p, "idle connection terminated\n"); + empth_wakeup(p->proc); + /* go to sleep because player thread + could vandalize a player list */ + + break; + } } - /*NOTREACHED*/ + } + /*NOTREACHED*/ } - diff --git a/src/server/lostitem.c b/src/server/lostitem.c index 2cbf92ef0..8dcb19393 100644 --- a/src/server/lostitem.c +++ b/src/server/lostitem.c @@ -44,14 +44,14 @@ /*ARGSUSED*/ void delete_lostitems(argv) -void *argv; +void *argv; { extern int lost_items_timeout; - time_t now; - struct loststr lost; - int n; - int ncnt; - + time_t now; + struct loststr lost; + int n; + int ncnt; + while (1) { time(&now); /* logerror("Deleting lost items at %s", ctime(&now));*/ @@ -67,9 +67,8 @@ void *argv; ncnt++; } /* logerror("Deleted %d lost items", ncnt, ctime(&now));*/ - now = now + 900; /* Every 15 minutes */ + now = now + 900; /* Every 15 minutes */ empth_sleep(now); } /*NOTREACHED*/ } - diff --git a/src/server/main.c b/src/server/main.c index 37f6da55d..d3c38f9c7 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -65,12 +65,12 @@ #include "global.h" #include "prototypes.h" -s_char program[] = "server"; +s_char program[] = "server"; -extern void player_accept(); -extern void player_kill_idle(); -extern void update_sched(); -extern void delete_lostitems(); +extern void player_accept(); +extern void player_kill_idle(); +extern void update_sched(); +extern void delete_lostitems(); void nullify_objects(void); void init_files(void); void close_files(void); @@ -90,14 +90,14 @@ static int mainpid = 0; int main(argc, argv) -int argc; -char *argv[]; +int argc; +char *argv[]; { - time_t now; - int hour[2]; - int flags = 0; - int debug = 0; - int op; + time_t now; + int hour[2]; + int flags = 0; + int debug = 0; + int op; char *config_file = NULL; extern s_char *datadir; extern char *optarg; @@ -105,54 +105,54 @@ char *argv[]; #ifdef POSIXSIGNALS struct sigaction act; #endif /* POSIXSIGNALS */ - + #if !defined(_WIN32) - mainpid = getpid(); - + mainpid = getpid(); + while ((op = getopt(argc, argv, "D:de:psh")) != EOF) { - switch (op) { - case 'D': - datadir = optarg; - break; - case 'd': - debug++; - break; - case 'e': - config_file = optarg; - break; - case 'p': - flags |= EMPTH_PRINT; - break; - case 's': - flags |= EMPTH_PRINT|EMPTH_STACKCHECK; - break; - case 'h': - default: - printf("Usage: %s -d -p -s\n",argv[0]); - return 0; - } + switch (op) { + case 'D': + datadir = optarg; + break; + case 'd': + debug++; + break; + case 'e': + config_file = optarg; + break; + case 'p': + flags |= EMPTH_PRINT; + break; + case 's': + flags |= EMPTH_PRINT | EMPTH_STACKCHECK; + break; + case 'h': + default: + printf("Usage: %s -d -p -s\n", argv[0]); + return 0; + } } #endif if (config_file == NULL) { - sprintf (tbuf, "%s/econfig", datadir); - config_file = tbuf; + sprintf(tbuf, "%s/econfig", datadir); + config_file = tbuf; } - + logerror("------------------------------------------------------"); #if !defined(_WIN32) logerror("Empire server (pid %d) started", getpid()); #else logerror("Empire server started"); #endif /* _WIN32 */ - + #if defined(_WIN32) loc_NTInit(); #endif - emp_config (config_file); + emp_config(config_file); update_policy_check(); - + nullify_objects(); - + #if !defined(_WIN32) /* signal() should not be used with mit pthreads. Anyway if u have a posix threads u definitly have posix signals -- Sasha */ @@ -160,39 +160,39 @@ char *argv[]; #ifdef SA_SIGINFO act.sa_flags = SA_SIGINFO; #endif - sigemptyset (&act.sa_mask); + sigemptyset(&act.sa_mask); if (debug == 0 && flags == 0) { - disassoc(); + disassoc(); } act.sa_handler = shutdwn; - /* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on - a Linux box running POSIX threads -- STM */ + /* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on + a Linux box running POSIX threads -- STM */ #if !(defined(__linux__) && defined(_EMPTH_POSIX)) - sigaction (SIGUSR1, &act, NULL); + sigaction(SIGUSR1, &act, NULL); #endif - sigaction (SIGTERM, &act, NULL); - sigaction (SIGINT, &act, NULL); + sigaction(SIGTERM, &act, NULL); + sigaction(SIGINT, &act, NULL); act.sa_handler = panic; - sigaction (SIGBUS, &act, NULL); - sigaction (SIGSEGV, &act, NULL); - sigaction (SIGILL, &act, NULL); - sigaction (SIGFPE, &act, NULL); + sigaction(SIGBUS, &act, NULL); + sigaction(SIGSEGV, &act, NULL); + sigaction(SIGILL, &act, NULL); + sigaction(SIGFPE, &act, NULL); act.sa_handler = SIG_IGN; sigaction(SIGPIPE, &act, NULL); #else if (debug == 0 && flags == 0) { - disassoc(); + disassoc(); /* pthreads on Linux use SIGUSR1 (*shrug*) so only catch it if not on a Linux box running POSIX threads -- STM */ #if !(defined(__linux__) && defined(_EMPTH_POSIX)) - signal(SIGUSR1, shutdwn); + signal(SIGUSR1, shutdwn); #endif - signal(SIGTERM, shutdwn); - signal(SIGBUS, panic); - signal(SIGSEGV, panic); - signal(SIGILL, panic); - signal(SIGFPE, panic); - signal(SIGINT, shutdwn); + signal(SIGTERM, shutdwn); + signal(SIGBUS, panic); + signal(SIGSEGV, panic); + signal(SIGILL, panic); + signal(SIGFPE, panic); + signal(SIGINT, shutdwn); } signal(SIGPIPE, SIG_IGN); #endif /* POSIXSIGNALS */ @@ -212,47 +212,47 @@ char *argv[]; init_files(); io_init(); gamehours(now, hour); - - if (opt_MOB_ACCESS) { - /* This fixes up mobility upon restart */ - mobility_init(); - } - empth_create(PP_ACCEPT, player_accept, (50*1024), flags, "AcceptPlayers", - "Accept network connections", 0); - empth_create(PP_KILLIDLE, player_kill_idle, (50*1024), flags, "KillIdle", - "Kills idle player connections", 0); - empth_create(PP_SCHED, update_sched, (50*1024), flags, "UpdateSched", - "Schedules updates to occur", 0); - empth_create(PP_TIMESTAMP, delete_lostitems, (50*1024), flags, "DeleteItems", - "Deletes old lost items", 0); if (opt_MOB_ACCESS) { - /* Start the mobility access check thread */ - empth_create(PP_TIMESTAMP, mobility_check, (50*1024), flags, "MobilityCheck", - "Writes the timestamp file", 0); + /* This fixes up mobility upon restart */ + mobility_init(); + } + + empth_create(PP_ACCEPT, player_accept, (50 * 1024), flags, + "AcceptPlayers", "Accept network connections", 0); + empth_create(PP_KILLIDLE, player_kill_idle, (50 * 1024), flags, + "KillIdle", "Kills idle player connections", 0); + empth_create(PP_SCHED, update_sched, (50 * 1024), flags, "UpdateSched", + "Schedules updates to occur", 0); + empth_create(PP_TIMESTAMP, delete_lostitems, (50 * 1024), flags, + "DeleteItems", "Deletes old lost items", 0); + if (opt_MOB_ACCESS) { + /* Start the mobility access check thread */ + empth_create(PP_TIMESTAMP, mobility_check, (50 * 1024), flags, + "MobilityCheck", "Writes the timestamp file", 0); } - + if (opt_MARKET) { - empth_create(PP_TIMESTAMP, market_update, (50*1024), flags, "MarketUpdate", - "Updates the market", 0); + empth_create(PP_TIMESTAMP, market_update, (50 * 1024), flags, + "MarketUpdate", "Updates the market", 0); } #if defined(__linux__) && defined(_EMPTH_POSIX) - strcpy(tbuf, argv[0]); - for (op = 1; op < argc; op++) { - strcat(tbuf, " "); - strcat(tbuf, argv[op]); - } - sprintf(argv[0], "%s (main pid: %d)", tbuf, getpid()); + strcpy(tbuf, argv[0]); + for (op = 1; op < argc; op++) { + strcat(tbuf, " "); + strcat(tbuf, argv[op]); + } + sprintf(argv[0], "%s (main pid: %d)", tbuf, getpid()); #endif - empth_exit(); + empth_exit(); /* We should never get here. But, just in case... */ close_files(); #if defined(_WIN32) loc_NTTerm(); -#endif +#endif return 0; } @@ -303,14 +303,14 @@ panic(int sig) #if !defined(_WIN32) #ifdef POSIXSIGNALS struct sigaction act; - + act.sa_flags = 0; - sigemptyset (&act.sa_mask); + sigemptyset(&act.sa_mask); act.sa_handler = SIG_DFL; - sigaction (SIGBUS, &act, NULL); - sigaction (SIGSEGV, &act, NULL); - sigaction (SIGILL, &act, NULL); - sigaction (SIGFPE, &act, NULL); + sigaction(SIGBUS, &act, NULL); + sigaction(SIGSEGV, &act, NULL); + sigaction(SIGILL, &act, NULL); + sigaction(SIGFPE, &act, NULL); #else signal(SIGBUS, SIG_DFL); signal(SIGSEGV, SIG_DFL); @@ -328,43 +328,43 @@ emp_sig_t shutdwn(int sig) { struct player *p; - time_t now; + time_t now; #if defined(__linux__) && defined(_EMPTH_POSIX) /* This is a hack to get around the way pthreads work on Linux. This may be useful on other platforms too where threads are turned into processes. */ - if (getpid() != mainpid) { - empth_t *me; - - me = empth_self(); - if (me && me->name) { - if (strlen(me->name) > 5) { - /* Player threads are cleaned up below, so just have - them return. This should work. */ - if (!strncmp("Player", me->name, 6)) { - return; - } - } + if (getpid() != mainpid) { + empth_t *me; + + me = empth_self(); + if (me && me->name) { + if (strlen(me->name) > 5) { + /* Player threads are cleaned up below, so just have + them return. This should work. */ + if (!strncmp("Player", me->name, 6)) { + return; } - /* Not a player thread - must be server thread, so exit */ - empth_exit(); - return; + } } + /* Not a player thread - must be server thread, so exit */ + empth_exit(); + return; + } #endif - logerror("Shutdown commencing (cleaning up threads.)"); + logerror("Shutdown commencing (cleaning up threads.)"); for (p = player_next(0); p != 0; p = player_next(p)) { - if (p->state != PS_PLAYING) - continue; - pr_flash(p, "Server shutting down...\n"); - p->state = PS_SHUTDOWN; - p->aborted++; - if (p->command) { - pr_flash(p, "Shutdown aborting command\n"); - } - empth_wakeup(p->proc); + if (p->state != PS_PLAYING) + continue; + pr_flash(p, "Server shutting down...\n"); + p->state = PS_SHUTDOWN; + p->aborted++; + if (p->command) { + pr_flash(p, "Shutdown aborting command\n"); + } + empth_wakeup(p->proc); } if (!sig) { @@ -377,15 +377,15 @@ shutdwn(int sig) } for (p = player_next(0); p != 0; p = player_next(p)) { - p->state = PS_KILL; - p->aborted++; - empth_terminate(p->proc); - p = player_delete(p); + p->state = PS_KILL; + p->aborted++; + empth_terminate(p->proc); + p = player_delete(p); } if (sig) - logerror("Server shutting down on signal %d", sig); + logerror("Server shutting down on signal %d", sig); else - logerror("Server shutting down at Deity's request"); + logerror("Server shutting down at Deity's request"); close_files(); _exit(0); } @@ -395,67 +395,67 @@ void nullify_objects(void) { int i, j; - + if (opt_BIG_CITY) { - dchr[SCT_CAPIT].d_flg = bigcity_dchr.d_flg; - dchr[SCT_CAPIT].d_pkg = bigcity_dchr.d_pkg; - dchr[SCT_CAPIT].d_build = bigcity_dchr.d_build; - dchr[SCT_CAPIT].d_lcms = bigcity_dchr.d_lcms; - dchr[SCT_CAPIT].d_hcms = bigcity_dchr.d_hcms; - dchr[SCT_CAPIT].d_name = bigcity_dchr.d_name; + dchr[SCT_CAPIT].d_flg = bigcity_dchr.d_flg; + dchr[SCT_CAPIT].d_pkg = bigcity_dchr.d_pkg; + dchr[SCT_CAPIT].d_build = bigcity_dchr.d_build; + dchr[SCT_CAPIT].d_lcms = bigcity_dchr.d_lcms; + dchr[SCT_CAPIT].d_hcms = bigcity_dchr.d_hcms; + dchr[SCT_CAPIT].d_name = bigcity_dchr.d_name; } for (i = 0; i < pln_maxno; i++) { - if (opt_NO_HCMS) - plchr[i].pl_hcm = 0; - if (opt_NO_LCMS) - plchr[i].pl_lcm = 0; - if (opt_NO_OIL) - plchr[i].pl_fuel = 0; - if (opt_PLANENAMES) - plchr[i].pl_name = plchr[i].pl_planename; + if (opt_NO_HCMS) + plchr[i].pl_hcm = 0; + if (opt_NO_LCMS) + plchr[i].pl_lcm = 0; + if (opt_NO_OIL) + plchr[i].pl_fuel = 0; + if (opt_PLANENAMES) + plchr[i].pl_name = plchr[i].pl_planename; } for (i = 0; i < lnd_maxno; i++) { - if (opt_NO_HCMS) - lchr[i].l_hcm = 0; - if (opt_NO_LCMS) - lchr[i].l_lcm = 0; - /* Fix up the military values */ - for (j = 0; j < lchr[i].l_nv; j++) { - if (lchr[i].l_vtype[j] == V_MILIT) - lchr[i].l_mil = lchr[i].l_vamt[j]; - } + if (opt_NO_HCMS) + lchr[i].l_hcm = 0; + if (opt_NO_LCMS) + lchr[i].l_lcm = 0; + /* Fix up the military values */ + for (j = 0; j < lchr[i].l_nv; j++) { + if (lchr[i].l_vtype[j] == V_MILIT) + lchr[i].l_mil = lchr[i].l_vamt[j]; + } } for (i = 0; i < shp_maxno; i++) { - if (opt_NO_HCMS) - mchr[i].m_hcm = 0; - if (opt_NO_LCMS) - mchr[i].m_lcm = 0; - if (opt_NO_OIL) { - if (mchr[i].m_flags & M_OIL) - mchr[i].m_name = 0; - } + if (opt_NO_HCMS) + mchr[i].m_hcm = 0; + if (opt_NO_LCMS) + mchr[i].m_lcm = 0; + if (opt_NO_OIL) { + if (mchr[i].m_flags & M_OIL) + mchr[i].m_name = 0; + } } for (i = 0; i < nuk_maxno; i++) { - if (opt_NO_HCMS) - nchr[i].n_hcm = 0; - if (opt_NO_LCMS) - nchr[i].n_lcm = 0; + if (opt_NO_HCMS) + nchr[i].n_hcm = 0; + if (opt_NO_LCMS) + nchr[i].n_lcm = 0; } for (i = 0; i < sct_maxno; i++) { - if (opt_NO_HCMS) - dchr[i].d_hcms = 0; - if (opt_NO_LCMS) - dchr[i].d_lcms = 0; + if (opt_NO_HCMS) + dchr[i].d_hcms = 0; + if (opt_NO_LCMS) + dchr[i].d_lcms = 0; } for (i = 0; i < prd_maxno; i++) { - for (j = 0; j < pchr[i].p_nv; j++) { - if (opt_NO_HCMS && pchr[i].p_vtype[j] == V_HCM) - pchr[i].p_vamt[j] = 0; - if (opt_NO_LCMS && pchr[i].p_vtype[j] == V_LCM) - pchr[i].p_vamt[j] = 0; - if (opt_NO_OIL && pchr[i].p_vtype[j] == V_OIL) - pchr[i].p_vamt[j] = 0; - } + for (j = 0; j < pchr[i].p_nv; j++) { + if (opt_NO_HCMS && pchr[i].p_vtype[j] == V_HCM) + pchr[i].p_vamt[j] = 0; + if (opt_NO_LCMS && pchr[i].p_vtype[j] == V_LCM) + pchr[i].p_vamt[j] = 0; + if (opt_NO_OIL && pchr[i].p_vtype[j] == V_OIL) + pchr[i].p_vamt[j] = 0; + } } } @@ -466,12 +466,12 @@ loc_NTInit() int rc; WORD wVersionRequested; WSADATA wsaData; - + wVersionRequested = MAKEWORD(2, 0); rc = WSAStartup(wVersionRequested, &wsaData); if (rc != 0) { - logerror("WSAStartup failed. %d", rc); - _exit(1); + logerror("WSAStartup failed. %d", rc); + _exit(1); } } #endif @@ -483,4 +483,3 @@ loc_NTTerm() WSACleanup(); } #endif - diff --git a/src/server/marketup.c b/src/server/marketup.c index 73d6791f0..dacf515a7 100644 --- a/src/server/marketup.c +++ b/src/server/marketup.c @@ -68,20 +68,19 @@ void *argv; /*ARGSUSED*/ void market_update(argv) -void *argv; +void *argv; { - time_t now; + time_t now; struct player *dp; - + while (1) { time(&now); /* logerror("Checking the world markets at %s", ctime(&now));*/ dp = player_new(0, 0); - empth_create(PP_UPDATE, check_all_markets, (50*1024), 0, - "MarketCheck", "Checks the world markets", dp); - now = now + 300; /* Every 5 minutes */ + empth_create(PP_UPDATE, check_all_markets, (50 * 1024), 0, + "MarketCheck", "Checks the world markets", dp); + now = now + 300; /* Every 5 minutes */ empth_sleep(now); } /*NOTREACHED*/ } - diff --git a/src/server/shutdown.c b/src/server/shutdown.c index 78f2179cc..dcdfd998c 100644 --- a/src/server/shutdown.c +++ b/src/server/shutdown.c @@ -46,51 +46,53 @@ int shutdown_pending; void shutdown_init(void) { - shutdown_pending = 0; + shutdown_pending = 0; } void shutdown_sequence(argc, argv) - int argc; - s_char **argv; +int argc; +s_char **argv; { - struct natstr *god; - struct tm *tm; - time_t now; - s_char header[100]; + struct natstr *god; + struct tm *tm; + time_t now; + s_char header[100]; - if (shutdown_pending <= 0) { - shutdown_pending = 0; - logerror("shutdown called with 0 shutdown_pending"); - empth_exit(); - return; - } - god = getnatp(0); - while (shutdown_pending > 0) { - --shutdown_pending; - time(&now); - if (shutdown_pending <= 1440) { /* one day */ - tm = localtime(&now); - sprintf(header, "BROADCAST from %s @ %02d:%02d: ", - god->nat_cnam, tm->tm_hour, tm->tm_min); - if (!shutdown_pending) { - pr_wall("%sServer shutting down NOW!\n", header); - shutdwn(0); - } else if (shutdown_pending == 1) { - pr_wall("%sServer shutting down in 1 minute!\n", header); - } else if (shutdown_pending <= 5) { - pr_wall("%sServer shutting down in %d minutes!\n", header, shutdown_pending); - } else if (shutdown_pending <= 60 && - shutdown_pending%10 == 0) { - pr_wall("%sThe server will be shutting down in %d minutes!\n", header, shutdown_pending); - } else if (shutdown_pending%60 == 0) { - pr_wall("%sThe server will be shutting down %d hours from now.\n", header, (int)(shutdown_pending/60)); - } - } - empth_sleep(now + 60); - } + if (shutdown_pending <= 0) { + shutdown_pending = 0; + logerror("shutdown called with 0 shutdown_pending"); empth_exit(); + return; + } + god = getnatp(0); + while (shutdown_pending > 0) { + --shutdown_pending; + time(&now); + if (shutdown_pending <= 1440) { /* one day */ + tm = localtime(&now); + sprintf(header, "BROADCAST from %s @ %02d:%02d: ", + god->nat_cnam, tm->tm_hour, tm->tm_min); + if (!shutdown_pending) { + pr_wall("%sServer shutting down NOW!\n", header); + shutdwn(0); + } else if (shutdown_pending == 1) { + pr_wall("%sServer shutting down in 1 minute!\n", header); + } else if (shutdown_pending <= 5) { + pr_wall("%sServer shutting down in %d minutes!\n", header, + shutdown_pending); + } else if (shutdown_pending <= 60 + && shutdown_pending % 10 == 0) { + pr_wall + ("%sThe server will be shutting down in %d minutes!\n", + header, shutdown_pending); + } else if (shutdown_pending % 60 == 0) { + pr_wall + ("%sThe server will be shutting down %d hours from now.\n", + header, (int)(shutdown_pending / 60)); + } + } + empth_sleep(now + 60); + } + empth_exit(); } - - - diff --git a/src/server/timestamp.c b/src/server/timestamp.c index f64560339..2af831abb 100644 --- a/src/server/timestamp.c +++ b/src/server/timestamp.c @@ -43,99 +43,99 @@ /*ARGSUSED*/ void mobility_check(argv) -void *argv; +void *argv; { - extern s_char *timestampfil; - extern int updating_mob; - struct mob_acc_globals timestamps; - time_t now; - FILE *fp; - int hour[2]; + extern s_char *timestampfil; + extern int updating_mob; + struct mob_acc_globals timestamps; + time_t now; + FILE *fp; + int hour[2]; - while (1) { - time(&now); + while (1) { + time(&now); /* logerror("Updating timestamp file at %s", ctime(&now));*/ #if !defined(_WIN32) - if ((fp = fopen(timestampfil, "r+")) == NULL) { + if ((fp = fopen(timestampfil, "r+")) == NULL) { #else - if ((fp = fopen(timestampfil, "r+b")) == NULL) { + if ((fp = fopen(timestampfil, "r+b")) == NULL) { #endif - logerror("Unable to edit timestamp file."); - continue; - } - rewind(fp); - fread(×tamps, sizeof(timestamps), 1, fp); - timestamps.timestamp = now; - rewind(fp); - fwrite(×tamps, sizeof(timestamps), 1, fp); - fclose(fp); - if (!gamehours(now, hour)) { - if (updating_mob == 1) { - update_all_mob(); - logerror("Turning off mobility updating (gamehours)."); - updating_mob = 0; - } - } else if (updating_mob == 1 && now < timestamps.starttime) { - logerror("Turning off mobility updating at %s", ctime(&now)); - update_all_mob(); - updating_mob = 0; - } else if (updating_mob == 0 && now >= timestamps.starttime) { - logerror("Turning on mobility updating at %s", ctime(&now)); - update_all_mob(); - updating_mob = 1; - } - now = now + 180; /* Every 3 minutes */ - empth_sleep(now); - + logerror("Unable to edit timestamp file."); + continue; } - /*NOTREACHED*/ + rewind(fp); + fread(×tamps, sizeof(timestamps), 1, fp); + timestamps.timestamp = now; + rewind(fp); + fwrite(×tamps, sizeof(timestamps), 1, fp); + fclose(fp); + if (!gamehours(now, hour)) { + if (updating_mob == 1) { + update_all_mob(); + logerror("Turning off mobility updating (gamehours)."); + updating_mob = 0; + } + } else if (updating_mob == 1 && now < timestamps.starttime) { + logerror("Turning off mobility updating at %s", ctime(&now)); + update_all_mob(); + updating_mob = 0; + } else if (updating_mob == 0 && now >= timestamps.starttime) { + logerror("Turning on mobility updating at %s", ctime(&now)); + update_all_mob(); + updating_mob = 1; + } + now = now + 180; /* Every 3 minutes */ + empth_sleep(now); + + } + /*NOTREACHED*/ } void mobility_init() { - extern s_char *timestampfil; - extern int updating_mob; - struct mob_acc_globals timestamps; - time_t now; - time_t lastsavedtime; - FILE *fp; - int hour[2]; + extern s_char *timestampfil; + extern int updating_mob; + struct mob_acc_globals timestamps; + time_t now; + time_t lastsavedtime; + FILE *fp; + int hour[2]; - /* During downtime, we don't want mobility to accrue. So, we look - at the timestamp file, and determine how far forward to push - mobility */ + /* During downtime, we don't want mobility to accrue. So, we look + at the timestamp file, and determine how far forward to push + mobility */ - time(&now); + time(&now); #if !defined(_WIN32) - if ((fp = fopen(timestampfil, "r+")) == NULL) { + if ((fp = fopen(timestampfil, "r+")) == NULL) { #else - if ((fp = fopen(timestampfil, "r+b")) == NULL) { + if ((fp = fopen(timestampfil, "r+b")) == NULL) { #endif - logerror("Unable to edit timestamp file."); - } else { - rewind(fp); - fread(×tamps, sizeof(timestamps), 1, fp); - lastsavedtime = timestamps.timestamp; - timestamps.timestamp = now; - rewind(fp); - fwrite(×tamps, sizeof(timestamps), 1, fp); - fclose(fp); - } - time(&now); - logerror("Adjusting timestamps at %s",ctime(&now)); - logerror("(was %s)",ctime(&lastsavedtime)); - /* Update the timestamps to this point in time */ - update_timestamps(lastsavedtime); - time(&now); - logerror("Done at %s", ctime(&now)); + logerror("Unable to edit timestamp file."); + } else { + rewind(fp); + fread(×tamps, sizeof(timestamps), 1, fp); + lastsavedtime = timestamps.timestamp; + timestamps.timestamp = now; + rewind(fp); + fwrite(×tamps, sizeof(timestamps), 1, fp); + fclose(fp); + } + time(&now); + logerror("Adjusting timestamps at %s", ctime(&now)); + logerror("(was %s)", ctime(&lastsavedtime)); + /* Update the timestamps to this point in time */ + update_timestamps(lastsavedtime); + time(&now); + logerror("Done at %s", ctime(&now)); - if (now >= timestamps.starttime && gamehours(now, hour)) { - logerror("Turning on mobility updating."); - updating_mob = 1; - } else { - logerror("Turning off mobility updating."); - updating_mob = 0; - } + if (now >= timestamps.starttime && gamehours(now, hour)) { + logerror("Turning on mobility updating."); + updating_mob = 1; + } else { + logerror("Turning off mobility updating."); + updating_mob = 0; + } } diff --git a/src/server/update.c b/src/server/update.c index 22818fde6..f89817e30 100644 --- a/src/server/update.c +++ b/src/server/update.c @@ -39,114 +39,115 @@ #include "prototypes.h" #include "optlist.h" -empth_sem_t *update_sem; +empth_sem_t *update_sem; -extern void update_main(); -extern void update_wait(); -time_t update_time; +extern void update_main(); +extern void update_wait(); +time_t update_time; /*ARGSUSED*/ void update_sched(argv) -void *argv; +void *argv; { - extern int s_p_etu; - extern int etu_per_update; - extern int adj_update; - extern int update_window; - s_char *kw; - int hour[2]; - int wind; - time_t now, delta; + extern int s_p_etu; + extern int etu_per_update; + extern int adj_update; + extern int update_window; + s_char *kw; + int hour[2]; + int wind; + time_t now, delta; - update_sem = empth_sem_create("Update", 0); - empth_create(PP_SCHED, update_wait, (50*1024), 0, "UpdateWait", - "Waits until players idle", 0); + update_sem = empth_sem_create("Update", 0); + empth_create(PP_SCHED, update_wait, (50 * 1024), 0, "UpdateWait", + "Waits until players idle", 0); + time(&now); + (void)gamehours(now, hour); + if (NULL != (kw = kw_find("s_p_etu"))) + kw_parse(CF_VALUE, kw, &s_p_etu); + if (NULL != (kw = kw_find("etu_per_update"))) + kw_parse(CF_VALUE, kw, &etu_per_update); + if (NULL != (kw = kw_find("adj_update"))) + kw_parse(CF_VALUE, kw, &adj_update); + if (NULL != (kw = kw_find("update_window"))) + kw_parse(CF_VALUE, kw, &update_window); + if (s_p_etu <= 0) { + logerror("bad value for s_p_etu (%d)", s_p_etu); + s_p_etu = 2 * 60; + logerror("setting s_p_etu to %d", s_p_etu); + } + while (1) { time(&now); - (void) gamehours(now, hour); - if (NULL != (kw = kw_find("s_p_etu"))) - kw_parse(CF_VALUE, kw, &s_p_etu); - if (NULL != (kw = kw_find("etu_per_update"))) - kw_parse(CF_VALUE, kw, &etu_per_update); - if (NULL != (kw = kw_find("adj_update"))) - kw_parse(CF_VALUE, kw, &adj_update); - if (NULL != (kw = kw_find("update_window"))) - kw_parse(CF_VALUE, kw, &update_window); - if (s_p_etu <= 0) { - logerror("bad value for s_p_etu (%d)", s_p_etu); - s_p_etu = 2 * 60; - logerror("setting s_p_etu to %d", s_p_etu); + next_update_time(&now, &update_time, &delta); + if (update_window > 0) { + wind = (random() % update_window); + update_time += wind; + delta += wind; } - while (1) { - time(&now); - next_update_time(&now, &update_time, &delta); - if (update_window > 0) { - wind = (random() % update_window); - update_time += wind; - delta += wind; - } - logerror("Next update at %s", ctime(&update_time)); - logerror("Next update in %d seconds", delta); - /* sleep until update is scheduled to go off */ - empth_sleep(update_time); - time(&now); - now += adj_update; - if (!gamehours(now, hour)) { - logerror("No update permitted (hours restriction)"); - continue; - } - if (!updatetime(&now)) { - logerror("No update wanted"); - continue; - } - if (updates_disabled()) { - logerror("Updates disabled...skipping update"); - continue; - } - empth_sem_signal(update_sem); + logerror("Next update at %s", ctime(&update_time)); + logerror("Next update in %d seconds", delta); + /* sleep until update is scheduled to go off */ + empth_sleep(update_time); + time(&now); + now += adj_update; + if (!gamehours(now, hour)) { + logerror("No update permitted (hours restriction)"); + continue; + } + if (!updatetime(&now)) { + logerror("No update wanted"); + continue; + } + if (updates_disabled()) { + logerror("Updates disabled...skipping update"); + continue; } - /*NOTREACHED*/ + empth_sem_signal(update_sem); + } + /*NOTREACHED*/ } /*ARGSUSED*/ void update_wait(argv) - void *argv; +void *argv; { - struct player *p; - int running; - time_t now; - int stacksize; - struct player *dp; + struct player *p; + int running; + time_t now; + int stacksize; + struct player *dp; - while (1) { - empth_sem_wait(update_sem); - running = 0; - for (p = player_next(0); p != 0; p = player_next(p)) { - if (p->state != PS_PLAYING) - continue; - if (p->command) { - pr_flash(p, "Update aborting command\n"); - p->aborted = 1; - empth_wakeup(p->proc); - running++; - } - } - time(&now); - if (running) { - /* sleep a few, wait for aborts to take effect */ - empth_sleep(now + 2); - } - /* - * we rely on the fact that update's priority is the highest - * in the land so it can finish before it yields. - */ - dp = player_new(0, 0); - stacksize= 100000 + -/* finish_sects */ WORLD_X*WORLD_Y*(2*sizeof(double)+sizeof(s_char *)); - - empth_create(PP_UPDATE, update_main, stacksize, 0, - "UpdateRun", "Updates the world", dp); + while (1) { + empth_sem_wait(update_sem); + running = 0; + for (p = player_next(0); p != 0; p = player_next(p)) { + if (p->state != PS_PLAYING) + continue; + if (p->command) { + pr_flash(p, "Update aborting command\n"); + p->aborted = 1; + empth_wakeup(p->proc); + running++; + } } - /*NOTREACHED*/ + time(&now); + if (running) { + /* sleep a few, wait for aborts to take effect */ + empth_sleep(now + 2); + } + /* + * we rely on the fact that update's priority is the highest + * in the land so it can finish before it yields. + */ + dp = player_new(0, 0); + stacksize = 100000 + +/* finish_sects */ WORLD_X * WORLD_Y * (2 * sizeof(double) + + sizeof(s_char *)); + + empth_create(PP_UPDATE, update_main, stacksize, 0, + "UpdateRun", "Updates the world", dp); + } + /*NOTREACHED*/ } diff --git a/src/util/fairland.c b/src/util/fairland.c index d9630d2b9..88814f174 100644 --- a/src/util/fairland.c +++ b/src/util/fairland.c @@ -34,7 +34,7 @@ /* define ORE 1 to add resources, define ORE 0 if you want to use another program to add the resources */ -static int ORE = 1; +static int ORE = 1; static int quiet = 0; /* If you don't specify these command line arguments, then these are the @@ -82,10 +82,10 @@ static int quiet = 0; #include "prototypes.h" /* do not change these 4 defines */ -#define LANDMIN 1 /* plate altitude for normal land */ -#define HILLMIN 34 /* plate altitude for hills */ -#define PLATMIN 36 /* plate altitude for plateau */ -#define HIGHMIN 98 /* plate altitude for mountains */ +#define LANDMIN 1 /* plate altitude for normal land */ +#define HILLMIN 34 /* plate altitude for hills */ +#define PLATMIN 36 /* plate altitude for plateau */ +#define HIGHMIN 98 /* plate altitude for mountains */ static void qprint _PROTO((const char *str)); @@ -98,19 +98,19 @@ static int AIRPORT_MARKER = 0; 1 = don't merge, 0 = merge. */ static int DISTINCT_ISLANDS = 1; -#define XSIZE ((WORLD_X) / 2) /* basically world x-y size */ +#define XSIZE ((WORLD_X) / 2) /* basically world x-y size */ #define YSIZE (WORLD_Y) -#define STABLE_CYCLE 4 /* stability required for perterbed capitals */ -#define INFINITY 999 /* a number which means "BIG" */ +#define STABLE_CYCLE 4 /* stability required for perterbed capitals */ +#define INFINITY 999 /* a number which means "BIG" */ /* these defines prevent infinite loops: */ -#define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector - when growing continents and islands */ +#define COAST_SEARCH_MAX 200 /* how many times do we look for a coast sector + when growing continents and islands */ #define DRIFT_BEFORE_CHECK ((WORLD_X + WORLD_Y)/2) #define DRIFT_MAX ((WORLD_X + WORLD_Y)*2) -#define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */ +#define MOUNTAIN_SEARCH_MAX 1000 /* how long do we try to place mountains */ /* handy macros: */ @@ -122,35 +122,36 @@ static int DISTINCT_ISLANDS = 1; #endif #define rnd(x) (random() % (x)) -int secs; /* number of sectors grown */ -int ctot; /* total number of continents and islands grown */ -int *isecs; /* array of how large each island is */ - -int nc, sc, di, sp, pm, ni, is, id; /* the 8 arguments to this program */ -int *capx, *capy; /* location of the nc capitals */ -int *mc, mcc; /* array and counter used for stability - check when perturbing */ -int spike; /* are we spiking? */ -int mind; /* the final distance between capitals that - we achieved */ -int dirx[] = {-2, -1, 1, 2, 1, -1}; /* gyujnb */ -int diry[] = {0, -1, -1, 0, 1, 1}; - -int **own; /* owner of the sector. -1 means water */ -int **elev; /* elevation of the sectors */ -int **sectx, **secty; /* the sectors for each continent */ -int **sectc; /* which sectors are on the coast? */ -int *vector; /* used for measuring distances */ -int *weight; /* used for placing mountains */ -int *dsea, *dmoun; /* the dist to the ocean and mountain */ -int the_file; /* the file we write everything to */ +int secs; /* number of sectors grown */ +int ctot; /* total number of continents and islands grown */ +int *isecs; /* array of how large each island is */ + +int nc, sc, di, sp, pm, ni, is, id; /* the 8 arguments to this program */ +int *capx, *capy; /* location of the nc capitals */ +int *mc, mcc; /* array and counter used for stability + check when perturbing */ +int spike; /* are we spiking? */ +int mind; /* the final distance between capitals that + we achieved */ +int dirx[] = { -2, -1, 1, 2, 1, -1 }; /* gyujnb */ +int diry[] = { 0, -1, -1, 0, 1, 1 }; + +int **own; /* owner of the sector. -1 means water */ +int **elev; /* elevation of the sectors */ +int **sectx, **secty; /* the sectors for each continent */ +int **sectc; /* which sectors are on the coast? */ +int *vector; /* used for measuring distances */ +int *weight; /* used for placing mountains */ +int *dsea, *dmoun; /* the dist to the ocean and mountain */ +int the_file; /* the file we write everything to */ struct sctstr **sects; struct sctstr *sectsbuf; -int fl_status; /* is anything wrong? */ -#define STATUS_NO_ROOM (1) /* there was no room to grow */ -#define NUMTRIES 10 /* keep trying to grow this many times */ +int fl_status; /* is anything wrong? */ +#define STATUS_NO_ROOM (1) /* there was no room to grow */ +#define NUMTRIES 10 /* keep trying to grow this many times */ -const char *numletter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; +const char *numletter = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; void parse_args(int argc, char *argv[]); int allocate_memory(void); @@ -169,10 +170,10 @@ void translate_continents(void); int map_symbol(int x, int y); static void fl_sct_init(coord x, coord y, s_char *ptr); -void print_vars(); -void fl_move(int); -void next_coast(); -void grow_islands(); +void print_vars(); +void fl_move(int); +void next_coast(); +void grow_islands(); /**************************************************************************** MAIN @@ -181,110 +182,114 @@ void grow_islands(); int main(int argc, char *argv[]) { - int opt; - extern int optind; - extern char *optarg; - extern s_char *datadir; - char *config_file = NULL; - char tbuf[512]; - int i = 0; + int opt; + extern int optind; + extern char *optarg; + extern s_char *datadir; + char *config_file = NULL; + char tbuf[512]; + int i = 0; #if !defined(_WIN32) - while ((opt = getopt(argc, argv, "ae:ioqs:")) != EOF) { - switch (opt) { - case 'a': - AIRPORT_MARKER = 1; - break; - case 'i': - DISTINCT_ISLANDS = 0; - break; - case 'e': - config_file = optarg; - break; - case 'o': - ORE = 0; - break; - case 'q': - quiet = 1; - break; - case 's': - outfile = optarg; - break; + while ((opt = getopt(argc, argv, "ae:ioqs:")) != EOF) { + switch (opt) { + case 'a': + AIRPORT_MARKER = 1; + break; + case 'i': + DISTINCT_ISLANDS = 0; + break; + case 'e': + config_file = optarg; + break; + case 'o': + ORE = 0; + break; + case 'q': + quiet = 1; + break; + case 's': + outfile = optarg; + break; + } } - } #endif - if (config_file == NULL) { - sprintf (tbuf, "%s/econfig", datadir); - config_file = tbuf; - } - emp_config (config_file); + if (config_file == NULL) { + sprintf(tbuf, "%s/econfig", datadir); + config_file = tbuf; + } + emp_config(config_file); #if !defined(_WIN32) - parse_args(argc - optind, argv + optind); + parse_args(argc - optind, argv + optind); #else - parse_args(argc - 1, argv + 1); + parse_args(argc - 1, argv + 1); #endif - if (allocate_memory() == -1) - exit(-1); - print_vars(); - - do { - init(); - if (!quiet && i) - printf("\ntry #%d (out of %d)...", i + 1, NUMTRIES); - qprint ("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n"); - qprint ("placing capitals...\n"); - if (!drift()) - qprint ("fairland: unstable drift -- try increasisg DRIFT_MAX\n"); - qprint ("growing continents...\n"); - grow_continents(); - } while (fl_status && ++i < NUMTRIES); - if (fl_status) { - fputs("ERROR: World not large enough to hold continents\n", stderr); - exit(1); - } - qprint ("growing islands:"); - grow_islands(); - qprint ("\nelevating land...\n"); - create_elevations(); - qprint ("designating sectors...\n"); - if (ORE) - qprint ("adding resources...\n"); - write_sects(); - qprint ("writing to sectors file...\n"); - if (write_file() == -1) - exit (-1); - output(); - write_newcap_script(); - exit(0); + if (allocate_memory() == -1) + exit(-1); + print_vars(); + + do { + init(); + if (!quiet && i) + printf("\ntry #%d (out of %d)...", i + 1, NUMTRIES); + qprint + ("\n\n #*# ...fairland rips open a rift in the datumplane... #*#\n\n"); + qprint("placing capitals...\n"); + if (!drift()) + qprint + ("fairland: unstable drift -- try increasisg DRIFT_MAX\n"); + qprint("growing continents...\n"); + grow_continents(); + } while (fl_status && ++i < NUMTRIES); + if (fl_status) { + fputs("ERROR: World not large enough to hold continents\n", + stderr); + exit(1); + } + qprint("growing islands:"); + grow_islands(); + qprint("\nelevating land...\n"); + create_elevations(); + qprint("designating sectors...\n"); + if (ORE) + qprint("adding resources...\n"); + write_sects(); + qprint("writing to sectors file...\n"); + if (write_file() == -1) + exit(-1); + output(); + write_newcap_script(); + exit(0); } void print_vars() { - if (quiet) - return; - puts("Creating a planet with:\n"); - printf("%d continents\n", nc); - printf("continent size: %d\n", sc); - printf("number of islands: %d\n", ni); - printf("average size of islands: %d\n", is); - printf("spike: %d%%\n", sp); - printf("%d%% of land is mountain (each continent will have %d mountains)\n", - pm, (pm*sc)/100); - printf("minimum distance between continents: %d\n", di); - printf("minimum distance from islands to continents: %d\n", id); - printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y); + if (quiet) + return; + puts("Creating a planet with:\n"); + printf("%d continents\n", nc); + printf("continent size: %d\n", sc); + printf("number of islands: %d\n", ni); + printf("average size of islands: %d\n", is); + printf("spike: %d%%\n", sp); + printf + ("%d%% of land is mountain (each continent will have %d mountains)\n", + pm, (pm * sc) / 100); + printf("minimum distance between continents: %d\n", di); + printf("minimum distance from islands to continents: %d\n", id); + printf("World dimensions: %dx%d\n", WORLD_X, WORLD_Y); } int my_sqrt(n) -int n; +int n; { - int i; + int i; - for (i = 1; i*i < n*10000; ++i); - return (i+50)/100; + for (i = 1; i * i < n * 10000; ++i) ; + return (i + 50) / 100; } /**************************************************************************** @@ -294,95 +299,103 @@ int n; void parse_args(int argc, char *argv[]) { - if (argc < 2 || argc > 8) { - puts("fairland syntax:\n"); - puts("fairland [-e config] [-aiqo] [-s script] [] [] [] [] [] []"); - puts ("-q = quiet, -o = no ore produced"); - puts ("-a = Airport marker for continents, -i = islands not distinct"); - printf ("-e = read config file, -s = name of script (default %s)\n", - outfile); - puts("nc = number of continents [MANDATORY]"); - puts("sc = continent size [MANDATORY]"); - puts("ni = number of islands (default = nc)"); - puts("is = average size of islands (default = sc/2)"); - printf("sp = spike percentage: 0 = round, 100 = snake (default = %d)\n", DEFAULT_SPIKE); - printf("pm = the percentage of land that is mountain (default = %d)\n", DEFAULT_MOUNTAIN); - printf("di = the minimum distance between continents (default = %d)\n", DEFAULT_CONTDIST); - printf("id = minimum distance from islands to continents (default = %d)\n", DEFAULT_ISLDIST); - exit (1); - } - nc = atoi(argv[0]); - if (nc < 1) { - puts("fairland: error -- number of continents must be > 0"); - exit (1); - } - - sc = atoi(argv[1]); - if (sc < 1) { - puts("fairland: error -- size of continents must be > 0"); - exit (1); - } - - if (argc > 2) - ni = atoi(argv[2]); - else - ni = nc; - - if (argc > 3) - is = atoi(argv[3]); - else - is = sc/2; - if (is < 0) - is = 0; - - if (argc > 4) - sp = atoi(argv[4]); - else - sp = DEFAULT_SPIKE; - if (sp < 0) - sp = 0; - if (sp > 100) - sp = 100; - - if (argc > 5) - pm = atoi(argv[5]); - else - pm = DEFAULT_MOUNTAIN; - if (pm < 0) - pm = 0; - - if (argc > 6) - di = atoi(argv[6]); - else - di = DEFAULT_CONTDIST; - - if (di < 0) { - puts("fairland: error -- distance between continents must be >= 0"); - exit (1); - } - if (di > WORLD_X/2 || di > WORLD_Y/2) { - puts("fairland: error -- distance between continents too large"); - exit (1); - } - - if (argc > 7) - id = atoi(argv[7]); - else - id = DEFAULT_ISLDIST; - if (id < 0) { - puts("fairland: error -- distance from islands to continents must be >= 0"); - exit (1); - } - if (id > WORLD_X || id > WORLD_Y) { - puts("fairland: error -- distance from islands to continents too large"); - exit (1); - } - if (nc*sc + nc*my_sqrt(sc)*2*(di+1) > WORLD_X * WORLD_Y) { - puts("fairland: error -- world not big enough to fit continents."); - puts("arguments must satisfy:"); - puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y"); - exit (1); - } + if (argc < 2 || argc > 8) { + puts("fairland syntax:\n"); + puts("fairland [-e config] [-aiqo] [-s script] [] [] [] [] [] []"); + puts("-q = quiet, -o = no ore produced"); + puts("-a = Airport marker for continents, -i = islands not distinct"); + printf("-e = read config file, -s = name of script (default %s)\n", + outfile); + puts("nc = number of continents [MANDATORY]"); + puts("sc = continent size [MANDATORY]"); + puts("ni = number of islands (default = nc)"); + puts("is = average size of islands (default = sc/2)"); + printf + ("sp = spike percentage: 0 = round, 100 = snake (default = %d)\n", + DEFAULT_SPIKE); + printf + ("pm = the percentage of land that is mountain (default = %d)\n", + DEFAULT_MOUNTAIN); + printf + ("di = the minimum distance between continents (default = %d)\n", + DEFAULT_CONTDIST); + printf + ("id = minimum distance from islands to continents (default = %d)\n", + DEFAULT_ISLDIST); + exit(1); + } + nc = atoi(argv[0]); + if (nc < 1) { + puts("fairland: error -- number of continents must be > 0"); + exit(1); + } + + sc = atoi(argv[1]); + if (sc < 1) { + puts("fairland: error -- size of continents must be > 0"); + exit(1); + } + + if (argc > 2) + ni = atoi(argv[2]); + else + ni = nc; + + if (argc > 3) + is = atoi(argv[3]); + else + is = sc / 2; + if (is < 0) + is = 0; + + if (argc > 4) + sp = atoi(argv[4]); + else + sp = DEFAULT_SPIKE; + if (sp < 0) + sp = 0; + if (sp > 100) + sp = 100; + + if (argc > 5) + pm = atoi(argv[5]); + else + pm = DEFAULT_MOUNTAIN; + if (pm < 0) + pm = 0; + + if (argc > 6) + di = atoi(argv[6]); + else + di = DEFAULT_CONTDIST; + + if (di < 0) { + puts("fairland: error -- distance between continents must be >= 0"); + exit(1); + } + if (di > WORLD_X / 2 || di > WORLD_Y / 2) { + puts("fairland: error -- distance between continents too large"); + exit(1); + } + + if (argc > 7) + id = atoi(argv[7]); + else + id = DEFAULT_ISLDIST; + if (id < 0) { + puts("fairland: error -- distance from islands to continents must be >= 0"); + exit(1); + } + if (id > WORLD_X || id > WORLD_Y) { + puts("fairland: error -- distance from islands to continents too large"); + exit(1); + } + if (nc * sc + nc * my_sqrt(sc) * 2 * (di + 1) > WORLD_X * WORLD_Y) { + puts("fairland: error -- world not big enough to fit continents."); + puts("arguments must satisfy:"); + puts("nc*sc*sc + nc*sqrt(sc)*2*(di+1) < WORLD_X * WORLD_Y"); + exit(1); + } } /**************************************************************************** @@ -392,90 +405,94 @@ parse_args(int argc, char *argv[]) int allocate_memory(void) { - int i; - time_t now; + int i; + time_t now; #if !defined(_WIN32) - the_file = open(empfile[EF_SECTOR].file, O_RDWR|O_CREAT|O_TRUNC, 0660); + the_file = + open(empfile[EF_SECTOR].file, O_RDWR | O_CREAT | O_TRUNC, 0660); #else - the_file = open(empfile[EF_SECTOR].file, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, 0660); + the_file = + open(empfile[EF_SECTOR].file, + O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0660); #endif - if (the_file < 0) { - perror(empfile[EF_SECTOR].file); - return -1; - } - sectsbuf = (struct sctstr *)calloc((YSIZE * XSIZE), sizeof(struct sctstr)); - sects = (struct sctstr **)calloc(YSIZE, sizeof(struct sctstr *)); - for (i = 0; i < YSIZE; i++) - sects[i] = §sbuf[XSIZE * i]; - time(&now); + if (the_file < 0) { + perror(empfile[EF_SECTOR].file); + return -1; + } + sectsbuf = + (struct sctstr *)calloc((YSIZE * XSIZE), sizeof(struct sctstr)); + sects = (struct sctstr **)calloc(YSIZE, sizeof(struct sctstr *)); + for (i = 0; i < YSIZE; i++) + sects[i] = §sbuf[XSIZE * i]; + time(&now); #if !defined(_WIN32) - srandom(now+getpid()); + srandom(now + getpid()); #else - srandom(now); + srandom(now); #endif - capx = (int *)calloc(nc, sizeof(int)); - capy = (int *)calloc(nc, sizeof(int)); - vector = (int *)calloc(WORLD_X+WORLD_Y, sizeof(int)); - mc = (int *)calloc(STABLE_CYCLE, sizeof(int)); - own = (int **)calloc(WORLD_X, sizeof(int*)); - elev = (int **)calloc(WORLD_X, sizeof(int*)); - for (i = 0; i < WORLD_X; ++i) { - own[i] = (int *)calloc(WORLD_Y, sizeof(int)); - elev[i] = (int *)calloc(WORLD_Y, sizeof(int)); - } - sectx = (int **)calloc(nc+ni, sizeof(int*)); - secty = (int **)calloc(nc+ni, sizeof(int*)); - sectc = (int **)calloc(nc+ni, sizeof(int*)); - isecs = (int *)calloc(nc+ni, sizeof(int)); - weight = (int *)calloc(max(sc,is*2), sizeof(int)); - dsea = (int *)calloc(max(sc,is*2), sizeof(int)); - dmoun = (int *)calloc(max(sc,is*2), sizeof(int)); - for (i = 0; i < nc; ++i) { - sectx[i] = (int *)calloc(sc, sizeof(int)); - secty[i] = (int *)calloc(sc, sizeof(int)); - sectc[i] = (int *)calloc(sc, sizeof(int)); - } - for (i = nc; i < nc+ni; ++i) { - sectx[i] = (int *)calloc(is*2, sizeof(int)); - secty[i] = (int *)calloc(is*2, sizeof(int)); - sectc[i] = (int *)calloc(is*2, sizeof(int)); - } - - return 0; + capx = (int *)calloc(nc, sizeof(int)); + capy = (int *)calloc(nc, sizeof(int)); + vector = (int *)calloc(WORLD_X + WORLD_Y, sizeof(int)); + mc = (int *)calloc(STABLE_CYCLE, sizeof(int)); + own = (int **)calloc(WORLD_X, sizeof(int *)); + elev = (int **)calloc(WORLD_X, sizeof(int *)); + for (i = 0; i < WORLD_X; ++i) { + own[i] = (int *)calloc(WORLD_Y, sizeof(int)); + elev[i] = (int *)calloc(WORLD_Y, sizeof(int)); + } + sectx = (int **)calloc(nc + ni, sizeof(int *)); + secty = (int **)calloc(nc + ni, sizeof(int *)); + sectc = (int **)calloc(nc + ni, sizeof(int *)); + isecs = (int *)calloc(nc + ni, sizeof(int)); + weight = (int *)calloc(max(sc, is * 2), sizeof(int)); + dsea = (int *)calloc(max(sc, is * 2), sizeof(int)); + dmoun = (int *)calloc(max(sc, is * 2), sizeof(int)); + for (i = 0; i < nc; ++i) { + sectx[i] = (int *)calloc(sc, sizeof(int)); + secty[i] = (int *)calloc(sc, sizeof(int)); + sectc[i] = (int *)calloc(sc, sizeof(int)); + } + for (i = nc; i < nc + ni; ++i) { + sectx[i] = (int *)calloc(is * 2, sizeof(int)); + secty[i] = (int *)calloc(is * 2, sizeof(int)); + sectc[i] = (int *)calloc(is * 2, sizeof(int)); + } + + return 0; } void init(void) { - int i, j, xx = 0, yy = 0; + int i, j, xx = 0, yy = 0; - mcc = 0; - fl_status = 0; + mcc = 0; + fl_status = 0; - for (i = 0; i < WORLD_X; ++i) { - for (j = 0; j < WORLD_Y; ++j) { - own[i][j] = -1; - elev[i][j] = -INFINITY; + for (i = 0; i < WORLD_X; ++i) { + for (j = 0; j < WORLD_Y; ++j) { + own[i][j] = -1; + elev[i][j] = -INFINITY; + } } - } - - for (i = 0; i < nc; ++i, xx += 2) { - if (xx >= WORLD_X) { - ++yy; - xx = yy%2; - if (yy == WORLD_Y) { - puts("fairland error: world not big enough for all the continents.\n"); - exit(1); - } + + for (i = 0; i < nc; ++i, xx += 2) { + if (xx >= WORLD_X) { + ++yy; + xx = yy % 2; + if (yy == WORLD_Y) { + puts("fairland error: world not big enough for all the continents.\n"); + exit(1); + } + } + capx[i] = xx; + capy[i] = yy; } - capx[i] = xx; - capy[i] = yy; - } - for (i = 0; i < STABLE_CYCLE; ++i) - mc[i] = i; + for (i = 0; i < STABLE_CYCLE; ++i) + mc[i] = i; } - + /**************************************************************************** DRIFT THE CAPITALS UNTIL THEY ARE AS FAR AWAY FROM EACH OTHER AS POSSIBLE ****************************************************************************/ @@ -486,17 +503,17 @@ int iso(j, newx, newy) int j, newx, newy; { - int i, md, d = WORLD_X + WORLD_Y; - - for (i = 0; i < nc; ++i) { - if (i == j) - continue; - md = mapdist(capx[i], capy[i], newx, newy); - if (md < d) - d = md; - } - - return d; + int i, md, d = WORLD_X + WORLD_Y; + + for (i = 0; i < nc; ++i) { + if (i == j) + continue; + md = mapdist(capx[i], capy[i], newx, newy); + if (md < d) + d = md; + } + + return d; } /* Drift all the capitals @@ -504,15 +521,15 @@ int j, newx, newy; int drift(void) { - int i, turns; - - for (turns = 0; turns < DRIFT_MAX; ++turns) { - if (turns > DRIFT_BEFORE_CHECK && (mind = stable())) - return 1; - for (i = 0; i < nc; ++i) - fl_move(i); - } - return 0; + int i, turns; + + for (turns = 0; turns < DRIFT_MAX; ++turns) { + if (turns > DRIFT_BEFORE_CHECK && (mind = stable())) + return 1; + for (i = 0; i < nc; ++i) + fl_move(i); + } + return 0; } /* Check to see if we have stabilized--can we stop drifting the capitals? @@ -521,19 +538,19 @@ drift(void) int stable(void) { - int i, isod, d = 0, stab = 1; - - for (i = 0; i < nc; ++i) { - isod = iso(i, capx[i], capy[i]); - if (isod > d) - d = isod; - } - for (i = 0; i < STABLE_CYCLE; ++i) - if (d != mc[i]) - stab = 0; - mc[mcc] = d; - mcc = (mcc + 1) % STABLE_CYCLE; - return stab?d:0; + int i, isod, d = 0, stab = 1; + + for (i = 0; i < nc; ++i) { + isod = iso(i, capx[i], capy[i]); + if (isod > d) + d = isod; + } + for (i = 0; i < STABLE_CYCLE; ++i) + if (d != mc[i]) + stab = 0; + mc[mcc] = d; + mcc = (mcc + 1) % STABLE_CYCLE; + return stab ? d : 0; } /* This routine does the actual drifting @@ -543,17 +560,17 @@ void fl_move(j) int j; { - int i, n, newx, newy; - - for (i = rnd(6), n = 0; n < 6; i = (i + 1)%6, ++n) { - newx = new_x(capx[j] + dirx[i]); - newy = new_y(capy[j] + diry[i]); - if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) { - capx[j] = newx; - capy[j] = newy; - return; + int i, n, newx, newy; + + for (i = rnd(6), n = 0; n < 6; i = (i + 1) % 6, ++n) { + newx = new_x(capx[j] + dirx[i]); + newy = new_y(capy[j] + diry[i]); + if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) { + capx[j] = newx; + capy[j] = newy; + return; + } } - } } /**************************************************************************** @@ -567,14 +584,15 @@ void find_coast(c) int c; { - int i, j; - - for (i = 0; i < secs; ++i) { - sectc[c][i] = 0; - for (j = 0; j < 6; ++j) - if (own[new_x(sectx[c][i] + dirx[j])][new_y(secty[c][i] + diry[j])] == -1) - sectc[c][i] = 1; - } + int i, j; + + for (i = 0; i < secs; ++i) { + sectc[c][i] = 0; + for (j = 0; j < 6; ++j) + if (own[new_x(sectx[c][i] + dirx[j])] + [new_y(secty[c][i] + diry[j])] == -1) + sectc[c][i] = 1; + } } /* Used for measuring distances @@ -583,17 +601,17 @@ int next_vector(n) int n; { - int i; - - if (n == 1) { - vector[0] += 1; - vector[0] %= 6; - return vector[0]; - } - for (i = 1; i < n && vector[i] == vector[i-1]; ++i); - vector[i-1] += 1; - vector[i-1] %= 6; - return i > 1 || vector[0] > 0; + int i; + + if (n == 1) { + vector[0] += 1; + vector[0] %= 6; + return vector[0]; + } + for (i = 1; i < n && vector[i] == vector[i - 1]; ++i) ; + vector[i - 1] += 1; + vector[i - 1] %= 6; + return i > 1 || vector[0] > 0; } /* Test to see if we're allowed to grow there: the arguments di and id @@ -602,28 +620,27 @@ int try_to_grow(c, newx, newy, d) int c, newx, newy, d; { - int i, j, px, py; - - for (i = 1; i <= d; ++i) { - for (j = 0; j < i; ++j) - vector[j] = 0; - do { - px = newx; - py = newy; - for (j = 0; j < i; ++j) { - px = new_x(px + dirx[vector[j]]); - py = new_y(py + diry[vector[j]]); - } - if (own[px][py] != -1 && - own[px][py] != c && - (DISTINCT_ISLANDS || own[px][py] < nc)) - return 0; - } while (next_vector(i)); - } - sectx[c][secs] = newx; - secty[c][secs] = newy; - own[newx][newy] = c; - return 1; + int i, j, px, py; + + for (i = 1; i <= d; ++i) { + for (j = 0; j < i; ++j) + vector[j] = 0; + do { + px = newx; + py = newy; + for (j = 0; j < i; ++j) { + px = new_x(px + dirx[vector[j]]); + py = new_y(py + diry[vector[j]]); + } + if (own[px][py] != -1 && + own[px][py] != c && (DISTINCT_ISLANDS || own[px][py] < nc)) + return 0; + } while (next_vector(i)); + } + sectx[c][secs] = newx; + secty[c][secs] = newy; + own[newx][newy] = c; + return 1; } /* Move along the coast in a clockwise direction. @@ -633,25 +650,25 @@ void next_coast(c, x, y, xp, yp) int c, x, y, *xp, *yp; { - int i, nx, ny, wat = 0; - - if (secs == 1) { - *xp = x; - *yp = y; - return; - } - - for (i = 0; i < 12; ++i) { - nx = new_x(x+dirx[i%6]); - ny = new_y(y+diry[i%6]); - if (own[nx][ny] == -1) - wat = 1; - if (wat && own[nx][ny] == c) { - *xp = nx; - *yp = ny; - return; + int i, nx, ny, wat = 0; + + if (secs == 1) { + *xp = x; + *yp = y; + return; + } + + for (i = 0; i < 12; ++i) { + nx = new_x(x + dirx[i % 6]); + ny = new_y(y + diry[i % 6]); + if (own[nx][ny] == -1) + wat = 1; + if (wat && own[nx][ny] == c) { + *xp = nx; + *yp = ny; + return; + } } - } } /* Choose a sector to grow from @@ -660,27 +677,27 @@ int c, x, y, *xp, *yp; int new_try(int c) { - int i, starti; - - if (secs == 1) { - if (sectc[c][0]) - return 0; - } - else { - i = starti = (spike && sectc[c][secs-1])?secs-1:rnd(secs); - do { - if (sectc[c][i]) - return i; - i = (i + 1)%secs; - } while (i != starti); - if (c < nc) { - printf("fairland: BUG -- couldn't find coast for continent %c, sector %d.\nPlease mail stevens@math.utoronto.ca.\n", c + 'a', secs); - exit (1); + int i, starti; + + if (secs == 1) { + if (sectc[c][0]) + return 0; + } else { + i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : rnd(secs); + do { + if (sectc[c][i]) + return i; + i = (i + 1) % secs; + } while (i != starti); + if (c < nc) { + printf + ("fairland: BUG -- couldn't find coast for continent %c, sector %d.\nPlease mail stevens@math.utoronto.ca.\n", + c + 'a', secs); + exit(1); + } else + return -1; } - else - return -1; - } - return -1; + return -1; } /* Grow continent c by 1 sector @@ -690,47 +707,53 @@ int grow_one_sector(c) int c; { - int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy; + int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy; - spike = rnd(100) < sp; - if ((try1 = new_try(c)) == -1) - return 0; - x = sx = sectx[c][try1]; - y = sy = secty[c][try1]; - coast_search = 0; - done = 0; - do { - if (spike) { - for (i = rnd(6), n = 0; n < 12 && !done; i = (i + 1)%6, ++n) { - newx = new_x(x+dirx[i]); - newy = new_y(y+diry[i]); - if (own[newx][newy] == -1 && - (n > 5 || - (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 && - own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1))) - if (try_to_grow(c, newx, newy, c 5 || + (own[new_x(x + dirx[(i + 5) % 6])] + [new_y(y + diry[(i + 5) % 6])] == -1 + && + own[new_x(x + dirx[(i + 1) % 6])][new_y + (y + + diry[(i + + 1) % 6])] == + -1))) + if (try_to_grow(c, newx, newy, c < nc ? di : id)) + done = 1; + } + } else + for (i = rnd(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) { + newx = new_x(x + dirx[i]); + newy = new_y(y + diry[i]); + if (own[newx][newy] == -1) + if (try_to_grow(c, newx, newy, c < nc ? di : id)) + done = 1; + } + next_coast(c, x, y, &x, &y); + ++coast_search; + } while (!done && coast_search < COAST_SEARCH_MAX && + (secs == 1 || x != sx || y != sy)); + if (!done && c < nc) { + if (!quiet) + printf + ("fairland: error -- continent %c had no room to grow!\n", + numletter[c % 62]); + fl_status |= STATUS_NO_ROOM; } - else - for (i = rnd(6), n = 0; n < 6 && !done; i = (i + 1)%6, ++n) { - newx = new_x(x+dirx[i]); - newy = new_y(y+diry[i]); - if (own[newx][newy] == -1) - if (try_to_grow(c, newx, newy, c WORLD_X - 2) - ssx = new_x(ssx + 2); - for (d = di + id; d >= id; --d) { - sx = ssx; - sy = ssy; - *xp = new_x(sx + 2); - for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) { - if (*xp >= WORLD_X) { - *yp = new_y(*yp + 1); - *xp = (*yp)%2; - if (*xp == sx && *yp == sy) - break; - } - if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d)) - return 1; + int d, sx, sy; + int ssy = rnd(WORLD_Y); + int ssx = new_x(rnd(WORLD_X / 2) * 2 + ssy % 2); + + if (ssx > WORLD_X - 2) + ssx = new_x(ssx + 2); + for (d = di + id; d >= id; --d) { + sx = ssx; + sy = ssy; + *xp = new_x(sx + 2); + for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) { + if (*xp >= WORLD_X) { + *yp = new_y(*yp + 1); + *xp = (*yp) % 2; + if (*xp == sx && *yp == sy) + break; + } + if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d)) + return 1; + } } - } - return 0; + return 0; } /* Grow all the islands @@ -800,21 +823,22 @@ int c, *xp, *yp; void grow_islands() { - int c, x, y, isiz; - - for (c = nc; c < nc+ni; ++c) { - secs = 0; - if (!place_island(c, &x, &y)) - return; - isiz = 1 + rnd(2*is - 1); - do { - ++secs; - find_coast(c); - } while (secs < isiz && grow_one_sector(c)); - if (quiet == 0) printf(" %d(%d)", c - nc + 1, secs); - isecs[c] = secs; - ctot = c; - } + int c, x, y, isiz; + + for (c = nc; c < nc + ni; ++c) { + secs = 0; + if (!place_island(c, &x, &y)) + return; + isiz = 1 + rnd(2 * is - 1); + do { + ++secs; + find_coast(c); + } while (secs < isiz && grow_one_sector(c)); + if (quiet == 0) + printf(" %d(%d)", c - nc + 1, secs); + isecs[c] = secs; + ctot = c; + } } /**************************************************************************** @@ -823,46 +847,46 @@ grow_islands() void create_elevations(void) { - elevate_land(); - elevate_sea(); + elevate_land(); + elevate_sea(); } /* Generic function for finding the distance to the closest sea, land, or mountain */ int -distance_to_what(x,y,flag) +distance_to_what(x, y, flag) int x, y, flag; { - int j, d, px, py; - - for (d = 1; d < 5; ++d) { - for (j = 0; j < d; ++j) - vector[j] = 0; - do { - px = x; - py = y; - for (j = 0; j < d; ++j) { - px = new_x(px + dirx[vector[j]]); - py = new_y(py + diry[vector[j]]); - } - switch(flag) { - case 0: /* distance to sea */ - if (own[px][py] == -1) - return d; - break; - case 1: /* distance to land */ - if (own[px][py] != -1) - return d; - break; - case 2: /* distance to mountain */ - if (elev[px][py] == INFINITY) - return d; - break; - } - } while (next_vector(d)); - } - return d; + int j, d, px, py; + + for (d = 1; d < 5; ++d) { + for (j = 0; j < d; ++j) + vector[j] = 0; + do { + px = x; + py = y; + for (j = 0; j < d; ++j) { + px = new_x(px + dirx[vector[j]]); + py = new_y(py + diry[vector[j]]); + } + switch (flag) { + case 0: /* distance to sea */ + if (own[px][py] == -1) + return d; + break; + case 1: /* distance to land */ + if (own[px][py] != -1) + return d; + break; + case 2: /* distance to mountain */ + if (elev[px][py] == INFINITY) + return d; + break; + } + } while (next_vector(d)); + } + return d; } #define ELEV elev[sectx[c][i]][secty[c][i]] @@ -874,81 +898,108 @@ int x, y, flag; void elevate_land(void) { - int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk, r, dk; + int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk, + r, dk; - for (c = 0; c < ctot; ++c) { - total = 0; - ns = (c < nc)?sc:isecs[c]; - nm = (pm*ns)/100; + for (c = 0; c < ctot; ++c) { + total = 0; + ns = (c < nc) ? sc : isecs[c]; + nm = (pm * ns) / 100; /* Place the mountains */ - for (i = 0; i < ns; ++i) { - dsea[i] = distance_to_sea(); - weight[i] = (total += (dsea[i]*dsea[i])); - } - - for (k = nm, mountain_search = 0; - k && mountain_search < MOUNTAIN_SEARCH_MAX; - ++mountain_search) { - r = rnd(total); - for (i = 0; i < ns; ++i) - if (r < weight[i] && ELEV == -INFINITY && (c >= nc || - ((!(capx[c] == sectx[c][i] && capy[c] == secty[c][i])) && - (!(new_x(capx[c] + 2) == sectx[c][i] && capy[c] == secty[c][i]))))) { - ELEV = INFINITY; - break; + for (i = 0; i < ns; ++i) { + dsea[i] = distance_to_sea(); + weight[i] = (total += (dsea[i] * dsea[i])); + } + + for (k = nm, mountain_search = 0; + k && mountain_search < MOUNTAIN_SEARCH_MAX; + ++mountain_search) { + r = rnd(total); + for (i = 0; i < ns; ++i) + if (r < weight[i] && ELEV == -INFINITY && (c >= nc || + ((!(capx[c] == + sectx[c][i] + && capy[c] + == + secty[c] + [i])) + && + (!(new_x + (capx[c] + + 2) == + sectx[c][i] + && capy[c] + == + secty[c] + [i]))))) { + ELEV = INFINITY; + break; + } + --k; } - --k; - } /* Elevate land that is not mountain and not capital */ - for (i = 0; i < ns; ++i) - dmoun[i] = distance_to_mountain(); - dk=(ns-nm-((c0)?(100*(HIGHMIN-LANDMIN))/(ns-nm-((c= nc || - ((!(capx[c] == sectx[c][i] && capy[c] == secty[c][i])) && - (!(new_x(capx[c] + 2) == sectx[c][i] && capy[c] == secty[c][i]))))) - { - h = 3*(5 - dmoun[i]) + dsea[i]; - if (h > highest) { - highest = h; - where = i; + for (i = 0; i < ns; ++i) + dmoun[i] = distance_to_mountain(); + dk = (ns - nm - ((c < nc) ? 3 : 1) > + 0) ? (100 * (HIGHMIN - LANDMIN)) / (ns - nm - + ((c < + nc) ? 3 : 1)) : 100 * + INFINITY; + for (k = 100 * (HIGHMIN - 1);; k -= dk) { + highest = -INFINITY; + where = -1; + for (i = 0; i < ns; ++i) { + if (ELEV != INFINITY && (c >= nc || + ((!(capx[c] == sectx[c][i] + && capy[c] == secty[c][i])) + && + (!(new_x(capx[c] + 2) == + sectx[c][i] + && capy[c] == + secty[c][i]))))) { + h = 3 * (5 - dmoun[i]) + dsea[i]; + if (h > highest) { + highest = h; + where = i; + } + } } - } - } - if (where == -1) - break; - newk = k/100; - if (newk >= HILLMIN && newk < PLATMIN) - newk = PLATMIN; - if (newk < LANDMIN) - newk = LANDMIN; - elev[sectx[c][where]][secty[c][where]] = newk; - dsea[where] = -INFINITY; - dmoun[where] = INFINITY; - } + if (where == -1) + break; + newk = k / 100; + if (newk >= HILLMIN && newk < PLATMIN) + newk = PLATMIN; + if (newk < LANDMIN) + newk = LANDMIN; + elev[sectx[c][where]][secty[c][where]] = newk; + dsea[where] = -INFINITY; + dmoun[where] = INFINITY; + } /* Elevate the mountains and capitals */ - for (i = 0; i < ns; ++i) { - if (ELEV == INFINITY) { - if (dsea[i] == 1) - ELEV = HILLMIN + rnd(PLATMIN - HILLMIN); - else - ELEV = HIGHMIN + rnd((256-HIGHMIN)/2) + rnd((256-HIGHMIN)/2); - } - else if ((c < nc && - ((capx[c] == sectx[c][i] && capy[c] == secty[c][i]))) || - ((new_x(capx[c] + 2) == sectx[c][i] && capy[c] == secty[c][i]))) - ELEV = PLATMIN; + for (i = 0; i < ns; ++i) { + if (ELEV == INFINITY) { + if (dsea[i] == 1) + ELEV = HILLMIN + rnd(PLATMIN - HILLMIN); + else + ELEV = + HIGHMIN + rnd((256 - HIGHMIN) / 2) + + rnd((256 - HIGHMIN) / 2); + } else + if ((c < nc + && + ((capx[c] == sectx[c][i] && capy[c] == secty[c][i]))) + || + ((new_x(capx[c] + 2) == sectx[c][i] + && capy[c] == secty[c][i]))) + ELEV = PLATMIN; + } } - } } #define distance_to_land() distance_to_what(x, y, 1) @@ -956,14 +1007,14 @@ elevate_land(void) void elevate_sea(void) { - int x, y; + int x, y; - for (y = 0; y < WORLD_Y; ++y) { - for (x = y%2; x < WORLD_X; x +=2) { - if (elev[x][y] == -INFINITY) - elev[x][y] = - rnd((distance_to_land()*20 + 27)) - 1; + for (y = 0; y < WORLD_Y; ++y) { + for (x = y % 2; x < WORLD_X; x += 2) { + if (elev[x][y] == -INFINITY) + elev[x][y] = -rnd((distance_to_land() * 20 + 27)) - 1; } - } + } } /**************************************************************************** @@ -974,79 +1025,79 @@ int set_fert(e) int e; { - int fert = 0; - if (e < LANDMIN) - fert = LANDMIN - e + 40; - else if (e < FERT_MAX) - fert = (140*(FERT_MAX - e))/(FERT_MAX - LANDMIN); - if (fert > 120) - fert = 120; - return fert; + int fert = 0; + if (e < LANDMIN) + fert = LANDMIN - e + 40; + else if (e < FERT_MAX) + fert = (140 * (FERT_MAX - e)) / (FERT_MAX - LANDMIN); + if (fert > 120) + fert = 120; + return fert; } int set_oil(e) int e; { - int oil = 0; - if (e < LANDMIN) - oil = (LANDMIN - e)*2 + rnd(2); - else if (e <= OIL_MAX) - oil = (120*(OIL_MAX - e + 1))/(OIL_MAX - LANDMIN + 1); - if (oil > 100) - oil = 100; - return oil; + int oil = 0; + if (e < LANDMIN) + oil = (LANDMIN - e) * 2 + rnd(2); + else if (e <= OIL_MAX) + oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1); + if (oil > 100) + oil = 100; + return oil; } int set_iron(e) int e; { - int iron = 0; - if (e >= IRON_MIN && e < HIGHMIN) - iron = (120*(e - IRON_MIN + 1))/(HIGHMIN - IRON_MIN); - if (iron > 100) - iron = 100; - return iron; + int iron = 0; + if (e >= IRON_MIN && e < HIGHMIN) + iron = (120 * (e - IRON_MIN + 1)) / (HIGHMIN - IRON_MIN); + if (iron > 100) + iron = 100; + return iron; } int set_gold(e) int e; { - int gold = 0; - if (e >= GOLD_MIN) { - if (e < HIGHMIN) - gold = (80*(e - GOLD_MIN + 1))/(HIGHMIN - GOLD_MIN); - else - gold = 100 - 20 * HIGHMIN / e; - } - if (gold > 100) - gold = 100; - return gold; + int gold = 0; + if (e >= GOLD_MIN) { + if (e < HIGHMIN) + gold = (80 * (e - GOLD_MIN + 1)) / (HIGHMIN - GOLD_MIN); + else + gold = 100 - 20 * HIGHMIN / e; + } + if (gold > 100) + gold = 100; + return gold; } int set_uran(e) int e; { - int uran = 0; - if (e >= URAN_MIN && e < HIGHMIN) - uran = (120*(e - URAN_MIN + 1))/(HIGHMIN - URAN_MIN); - if (uran > 100) - uran = 100; - return uran; + int uran = 0; + if (e >= URAN_MIN && e < HIGHMIN) + uran = (120 * (e - URAN_MIN + 1)) / (HIGHMIN - URAN_MIN); + if (uran > 100) + uran = 100; + return uran; } void add_resources(sct) struct sctstr *sct; { - sct->sct_fertil = set_fert(sct->sct_elev); - sct->sct_oil = set_oil(sct->sct_elev); - sct->sct_min = set_iron(sct->sct_elev); - sct->sct_gmin = set_gold(sct->sct_elev); - sct->sct_uran = set_uran(sct->sct_elev); + sct->sct_fertil = set_fert(sct->sct_elev); + sct->sct_oil = set_oil(sct->sct_elev); + sct->sct_min = set_iron(sct->sct_elev); + sct->sct_gmin = set_gold(sct->sct_elev); + sct->sct_uran = set_uran(sct->sct_elev); } /**************************************************************************** @@ -1056,36 +1107,37 @@ struct sctstr *sct; void write_sects(void) { - register struct sctstr *sct; - int c, x, y, total; - - /* sct = §s[0][0];*/ - sct = sectsbuf; - for (y = 0; y < YSIZE; y++) { - for (x = 0; x < XSIZE; x++, sct++) { - fl_sct_init(x*2 + (y & 01), y, (s_char *) sct); - total = elev[sct->sct_x][y]; - if (total < LANDMIN) { - sct->sct_type = SCT_WATER; - } else if (total < HILLMIN) - sct->sct_type = SCT_RURAL; - else if (total < PLATMIN) - sct->sct_type = SCT_MOUNT; - else if (total < HIGHMIN) - sct->sct_type = SCT_RURAL; - else - sct->sct_type = SCT_MOUNT; - sct->sct_elev = total; - sct->sct_newtype = sct->sct_type; - if (ORE) - add_resources(sct); - } - } - if (AIRPORT_MARKER) - for (c = 0; c < nc; ++c) { - sects[capy[c]][capx[c]/2 + capy[c]%2].sct_type = SCT_AIRPT; - sects[capy[c]][capx[c]/2 + capy[c]%2].sct_newtype = SCT_AIRPT; + register struct sctstr *sct; + int c, x, y, total; + + /* sct = §s[0][0]; */ + sct = sectsbuf; + for (y = 0; y < YSIZE; y++) { + for (x = 0; x < XSIZE; x++, sct++) { + fl_sct_init(x * 2 + (y & 01), y, (s_char *)sct); + total = elev[sct->sct_x][y]; + if (total < LANDMIN) { + sct->sct_type = SCT_WATER; + } else if (total < HILLMIN) + sct->sct_type = SCT_RURAL; + else if (total < PLATMIN) + sct->sct_type = SCT_MOUNT; + else if (total < HIGHMIN) + sct->sct_type = SCT_RURAL; + else + sct->sct_type = SCT_MOUNT; + sct->sct_elev = total; + sct->sct_newtype = sct->sct_type; + if (ORE) + add_resources(sct); + } } + if (AIRPORT_MARKER) + for (c = 0; c < nc; ++c) { + sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_type = SCT_AIRPT; + sects[capy[c]][capx[c] / 2 + capy[c] % 2].sct_newtype = + SCT_AIRPT; + } } /**************************************************************************** @@ -1094,19 +1146,21 @@ write_sects(void) int write_file(void) { - int n; - - /* if ((n = write(the_file, sects, sizeof(sects))) < 0) {*/ - if ((n = write(the_file, sectsbuf, YSIZE * XSIZE * sizeof(struct sctstr))) < 0) { - perror(empfile[EF_SECTOR].file); - return -1; - } - if (n != (int)(YSIZE * XSIZE * sizeof(struct sctstr))) { - printf("%s:partial write\n", empfile[EF_SECTOR].file); - return -1; - } - close(the_file); - return 0; + int n; + + /* if ((n = write(the_file, sects, sizeof(sects))) < 0) { */ + if ((n = + write(the_file, sectsbuf, + YSIZE * XSIZE * sizeof(struct sctstr))) < 0) { + perror(empfile[EF_SECTOR].file); + return -1; + } + if (n != (int)(YSIZE * XSIZE * sizeof(struct sctstr))) { + printf("%s:partial write\n", empfile[EF_SECTOR].file); + return -1; + } + close(the_file); + return 0; } /**************************************************************************** @@ -1115,87 +1169,91 @@ write_file(void) void output(void) { - int i, j; - if (opt_BLITZ) - translate_continents(); - if (quiet == 0) { - for (i = 0; i < WORLD_Y; ++i) { - puts(""); - if (i%2) - printf(" "); - for (j = i%2; j < WORLD_X; j += 2) { - if (own[j][i] == -1) - printf(". "); - else { - printf("%c ", map_symbol(j,i)); + int i, j; + if (opt_BLITZ) + translate_continents(); + if (quiet == 0) { + for (i = 0; i < WORLD_Y; ++i) { + puts(""); + if (i % 2) + printf(" "); + for (j = i % 2; j < WORLD_X; j += 2) { + if (own[j][i] == -1) + printf(". "); + else { + printf("%c ", map_symbol(j, i)); + } + } } - } } - } - if (AIRPORT_MARKER) - printf("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\nthe islands). You can redesignate these airfields to wilderness sectors\none at a time, each time you add a new country to the game.\n"); + if (AIRPORT_MARKER) + printf + ("\n\nEach continent is marked by a \"*\" on the map (to distinguish them from\nthe islands). You can redesignate these airfields to wilderness sectors\none at a time, each time you add a new country to the game.\n"); } /* Reorder the continents from top left to bottom right */ void translate_continents(void) { - int i, j, n = 0, k, gotit, c; - int *trans, *trans_cont, *oldcapx, *oldcapy; - - trans = (int *)calloc(nc, sizeof(int)); - trans_cont = (int *)calloc(nc, sizeof(int)); - oldcapx = (int *)calloc(nc, sizeof(int)); - oldcapy = (int *)calloc(nc, sizeof(int)); - - for (i = 0; i < WORLD_Y; ++i) { - for (j = i%2; j < WORLD_X; j += 2) { - if (own[j][i] >-1 && own[j][i] < nc) { - gotit = 0; - for (k = 0; k < n; ++k) { - if (trans[k] == own[j][i]) - gotit = 1; + int i, j, n = 0, k, gotit, c; + int *trans, *trans_cont, *oldcapx, *oldcapy; + + trans = (int *)calloc(nc, sizeof(int)); + trans_cont = (int *)calloc(nc, sizeof(int)); + oldcapx = (int *)calloc(nc, sizeof(int)); + oldcapy = (int *)calloc(nc, sizeof(int)); + + for (i = 0; i < WORLD_Y; ++i) { + for (j = i % 2; j < WORLD_X; j += 2) { + if (own[j][i] > -1 && own[j][i] < nc) { + gotit = 0; + for (k = 0; k < n; ++k) { + if (trans[k] == own[j][i]) + gotit = 1; + } + if (!gotit) { + if (n > nc) { + printf + ("fairland: BUG in translate continents! mail stevens@math.utoronto.ca\n"); + exit(2); + } + trans[n] = own[j][i]; + trans_cont[own[j][i]] = n; + ++n; + } + } } - if (!gotit) { - if (n > nc) { - printf("fairland: BUG in translate continents! mail stevens@math.utoronto.ca\n"); - exit (2); - } - trans[n] = own[j][i]; - trans_cont[own[j][i]] = n; - ++n; + } + for (i = 0; i < WORLD_Y; ++i) { + for (j = i % 2; j < WORLD_X; j += 2) { + if (own[j][i] > -1 && own[j][i] < nc) { + own[j][i] = trans_cont[own[j][i]]; + } } - } } - } - for (i = 0; i < WORLD_Y; ++i) { - for (j = i%2; j < WORLD_X; j += 2) { - if (own[j][i] >-1 && own[j][i] < nc) { - own[j][i] = trans_cont[own[j][i]]; - } + for (c = 0; c < nc; ++c) { + oldcapx[c] = capx[c]; + oldcapy[c] = capy[c]; + } + for (c = 0; c < nc; ++c) { + capx[c] = oldcapx[trans[c]]; + capy[c] = oldcapy[trans[c]]; } - } - for (c = 0; c < nc; ++c) { - oldcapx[c] = capx[c]; - oldcapy[c] = capy[c]; - } - for (c = 0; c < nc; ++c) { - capx[c] = oldcapx[trans[c]]; - capy[c] = oldcapy[trans[c]]; - } } int map_symbol(int x, int y) { - int c, iscap = 0; - - for (c = 0; c < nc; ++c) - if ((x == capx[c] && y == capy[c]) || (x == new_x(capx[c]+2) && y == capy[c])) - iscap = 1; - if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN) || elev[x][y] >= HIGHMIN) - return '^'; - return own[x][y]>=nc?'%':iscap?'#':numletter[own[x][y] % 62]; + int c, iscap = 0; + + for (c = 0; c < nc; ++c) + if ((x == capx[c] && y == capy[c]) + || (x == new_x(capx[c] + 2) && y == capy[c])) + iscap = 1; + if ((elev[x][y] >= HILLMIN && elev[x][y] < PLATMIN) + || elev[x][y] >= HIGHMIN) + return '^'; + return own[x][y] >= nc ? '%' : iscap ? '#' : numletter[own[x][y] % 62]; } /*************************************************************************** @@ -1204,49 +1262,52 @@ map_symbol(int x, int y) int write_newcap_script(void) { - int c; - FILE *script = fopen(outfile, "w"); + int c; + FILE *script = fopen(outfile, "w"); - if (!script) { - printf("fairland: error, unable to write to %s.\n", outfile); - return -1; - } + if (!script) { + printf("fairland: error, unable to write to %s.\n", outfile); + return -1; + } - for (c = 0; c < nc; ++c) { - fprintf(script, "add %d %d %d n i\n", c+1, c+1, c+1); - if (AIRPORT_MARKER) - fprintf(script, "des %d,%d -\n", capx[c], capy[c]); - fprintf(script, "newcap %d %d,%d\n", c+1, capx[c], capy[c]); - } - fprintf(script, "add %d visitor visitor v i\n", c+1); - ++c; - fclose (script); - if (quiet == 0) - printf("\n\nA script for adding all the countries can be found in \"%s\".\n", + for (c = 0; c < nc; ++c) { + fprintf(script, "add %d %d %d n i\n", c + 1, c + 1, c + 1); + if (AIRPORT_MARKER) + fprintf(script, "des %d,%d -\n", capx[c], capy[c]); + fprintf(script, "newcap %d %d,%d\n", c + 1, capx[c], capy[c]); + } + fprintf(script, "add %d visitor visitor v i\n", c + 1); + ++c; + fclose(script); + if (quiet == 0) + printf + ("\n\nA script for adding all the countries can be found in \"%s\".\n", outfile); - if (ORE && quiet == 0) - printf("\t***IMPORTANT: Resources have already been added***\n\tYou do NOT need to run the ore program.\n"); - return 0; + if (ORE && quiet == 0) + printf + ("\t***IMPORTANT: Resources have already been added***\n\tYou do NOT need to run the ore program.\n"); + return 0; } -static void qprint (str) +static void +qprint(str) const char *str; { - if (quiet == 0) - fputs (str, stdout); + if (quiet == 0) + fputs(str, stdout); } void fl_sct_init(coord x, coord y, s_char *ptr) { - struct sctstr *sp = (struct sctstr *) ptr; - - sp->ef_type = EF_SECTOR; - sp->sct_x = x; - sp->sct_y = y; - sp->sct_dist_x = x; - sp->sct_dist_y = y; - sp->sct_road = 0; - sp->sct_rail = 0; - sp->sct_defense = 0; + struct sctstr *sp = (struct sctstr *)ptr; + + sp->ef_type = EF_SECTOR; + sp->sct_x = x; + sp->sct_y = y; + sp->sct_dist_x = x; + sp->sct_dist_y = y; + sp->sct_road = 0; + sp->sct_rail = 0; + sp->sct_defense = 0; } diff --git a/src/util/files.c b/src/util/files.c index a0a67cae6..fc0fdf2ba 100644 --- a/src/util/files.c +++ b/src/util/files.c @@ -63,7 +63,7 @@ #include "prototypes.h" #include "optlist.h" -s_char program[] = "file"; +s_char program[] = "file"; static void comminit(int fd); static int make(char *filename); @@ -72,191 +72,196 @@ static void file_sct_init(coord x, coord y, s_char *ptr); int main(int argc, char *argv[]) { - extern s_char *annfil; - extern s_char *timestampfil; - extern s_char *infodir; - extern s_char *commfil; - extern s_char *datadir; - s_char buf[255]; - s_char tbuf[512]; - s_char *filename; - int x,y; - struct natstr nat; - struct sctstr sct; - int i; - s_char *map; - extern char *optarg; - int opt; - char *config_file = NULL; + extern s_char *annfil; + extern s_char *timestampfil; + extern s_char *infodir; + extern s_char *commfil; + extern s_char *datadir; + s_char buf[255]; + s_char tbuf[512]; + s_char *filename; + int x, y; + struct natstr nat; + struct sctstr sct; + int i; + s_char *map; + extern char *optarg; + int opt; + char *config_file = NULL; #if !defined(_WIN32) - while ((opt = getopt (argc, argv, "e:")) != EOF) { - switch (opt) { - case 'e': - config_file = optarg; - break; - } + while ((opt = getopt(argc, argv, "e:")) != EOF) { + switch (opt) { + case 'e': + config_file = optarg; + break; } + } #endif - /* Try to use the existing data directory */ - if (config_file == NULL) { - sprintf (tbuf, "%s/econfig", datadir); - config_file = tbuf; - } - emp_config (config_file); - empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2; - empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2; + /* Try to use the existing data directory */ + if (config_file == NULL) { + sprintf(tbuf, "%s/econfig", datadir); + config_file = tbuf; + } + emp_config(config_file); + empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2; + empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2; #if !defined(_WIN32) - if (access(datadir, F_OK) < 0 && mkdir(datadir, 0750) < 0) { + if (access(datadir, F_OK) < 0 && mkdir(datadir, 0750) < 0) { #else - if (_access(datadir, 06) < 0 && _mkdir(datadir) < 0) { + if (_access(datadir, 06) < 0 && _mkdir(datadir) < 0) { #endif - perror(datadir); - printf("Can't make game directory\n"); - exit(1); - } - printf("WARNING: this blasts the existing game in %s (if any)\n", datadir); - printf("continue? "); - fgets(buf, sizeof(buf) - 1, stdin); - if (*buf != 'y' && *buf != 'Y') - exit(1); - for (i=0; i < EF_MAX; i++) { - if (ef_open(i, O_RDWR|O_CREAT|O_TRUNC, 0) < 0) { - perror("ef_open"); - exit(1); - } + perror(datadir); + printf("Can't make game directory\n"); + exit(1); + } + printf("WARNING: this blasts the existing game in %s (if any)\n", + datadir); + printf("continue? "); + fgets(buf, sizeof(buf) - 1, stdin); + if (*buf != 'y' && *buf != 'Y') + exit(1); + for (i = 0; i < EF_MAX; i++) { + if (ef_open(i, O_RDWR | O_CREAT | O_TRUNC, 0) < 0) { + perror("ef_open"); + exit(1); } - bzero((s_char *)&nat, sizeof(nat)); + } + bzero((s_char *)&nat, sizeof(nat)); + nat.ef_type = EF_NATION; + if (nat.nat_cnam[0] == 0) + strcpy(nat.nat_cnam, "POGO"); + if (nat.nat_pnam[0] == 0) + strcpy(nat.nat_pnam, "peter"); + nat.nat_stat = STAT_INUSE | STAT_NORM | STAT_GOD | STAT_ABS; + nat.nat_btu = 255; + nat.nat_money = 123456789; + nat.nat_cnum = 0; + nat.nat_flags |= NF_FLASH; + for (x = 0; x < SCT_MAXDEF + 8; x++) + nat.nat_priorities[x] = -1; + putnat((&nat)); + printf("All praise to %s!\n", nat.nat_cnam); + bzero((s_char *)&nat, sizeof(nat)); + for (x = 0; x < SCT_MAXDEF + 8; x++) + nat.nat_priorities[x] = -1; + for (i = 1; i < MAXNOC; i++) { nat.ef_type = EF_NATION; - if (nat.nat_cnam[0] == 0) - strcpy(nat.nat_cnam,"POGO"); - if (nat.nat_pnam[0] == 0) - strcpy(nat.nat_pnam,"peter"); - nat.nat_stat = STAT_INUSE|STAT_NORM|STAT_GOD|STAT_ABS; - nat.nat_btu = 255; - nat.nat_money = 123456789; - nat.nat_cnum = 0; - nat.nat_flags |= NF_FLASH; - for(x=0;x= 0; x--) { - filename = mailbox(buf, x); - close(creat(filename, 0600)); - chmod(filename, 0600); - } - close(creat(timestampfil, 0600)); - close(creat(annfil, 0600)); - chmod(infodir, 0750); - chmod(datadir, 0770); - chmod(teldir, 0770); + perror(teldir); + printf("Can't make telegram directory\n"); + exit(1); + } + for (x = MAXNOC - 1; x >= 0; x--) { + filename = mailbox(buf, x); + close(creat(filename, 0600)); + chmod(filename, 0600); + } + close(creat(timestampfil, 0600)); + close(creat(annfil, 0600)); + chmod(infodir, 0750); + chmod(datadir, 0770); + chmod(teldir, 0770); - /* create a zero-filled sector file */ - bzero((s_char *)&sct,sizeof(sct)); - for (y=0;yef_type = EF_SECTOR; - sp->sct_x = x; - sp->sct_y = y; - sp->sct_dist_x = x; - sp->sct_dist_y = y; + sp->ef_type = EF_SECTOR; + sp->sct_x = x; + sp->sct_y = y; + sp->sct_dist_x = x; + sp->sct_dist_y = y; } void -log_last_commands(void) {} +log_last_commands(void) +{ +} diff --git a/src/util/land.c b/src/util/land.c index 457455474..bfca31d4d 100644 --- a/src/util/land.c +++ b/src/util/land.c @@ -51,40 +51,40 @@ #define XSIZE (XPLATES) #define YSIZE (YPLATES) -#define BIGV 256 /* used in making altitude */ -#define SMALLV 128 /* ex-ocean: rnd(SMALLV) - rnd(BIGV) */ +#define BIGV 256 /* used in making altitude */ +#define SMALLV 128 /* ex-ocean: rnd(SMALLV) - rnd(BIGV) */ typedef enum plates { - OCEAN, ISLAND, CONTINENT + OCEAN, ISLAND, CONTINENT } plate_e; -#define LANDMIN 1 /* plate altitude for normal land */ -#define HILLMIN 34 /* plate altitude for hills */ -#define PLATMIN 36 /* plate altitude for plateau */ -#define HIGHMIN 98 /* plate altitude for mountains */ +#define LANDMIN 1 /* plate altitude for normal land */ +#define HILLMIN 34 /* plate altitude for hills */ +#define PLATMIN 36 /* plate altitude for plateau */ +#define HIGHMIN 98 /* plate altitude for mountains */ -#define LANDCH 60 /* land plate percentage */ +#define LANDCH 60 /* land plate percentage */ #define NUMLAND (YPLATES * XPLATES * LANDCH)/100 -#define NUMISLE NUMLAND/5 /* 1 isle for 5 land */ +#define NUMISLE NUMLAND/5 /* 1 isle for 5 land */ #define NUMWATER (XPLATES * YPLATES) - (NUMLAND + NUMISLE) -#define SECTRANGE 3 /* smoothing area */ -#define MINCONTDIST 2 /* minimum continent distance */ -#define CHUNKSIZE 2 /* basic land block size */ +#define SECTRANGE 3 /* smoothing area */ +#define MINCONTDIST 2 /* minimum continent distance */ +#define CHUNKSIZE 2 /* basic land block size */ #define NEWCONTDIST (rnd(mincontdist) + mincontdist) /* dist away from others for newcont */ -#define NUMCHUNKS 70 /* number of CHUNKS per cont */ +#define NUMCHUNKS 70 /* number of CHUNKS per cont */ -struct sctstr sects[YSIZE][XSIZE]; +struct sctstr sects[YSIZE][XSIZE]; -plate_e plates[YPLATES][XPLATES]; -int world[YSIZE][XSIZE]; +plate_e plates[YPLATES][XPLATES]; +int world[YSIZE][XSIZE]; -int sectrange = SECTRANGE; -int mincontdist = MINCONTDIST; -int chunksize = CHUNKSIZE; -int numchunks = NUMCHUNKS; -int numisle = NUMISLE; +int sectrange = SECTRANGE; +int mincontdist = MINCONTDIST; +int chunksize = CHUNKSIZE; +int numchunks = NUMCHUNKS; +int numisle = NUMISLE; static void initworld(); static void growcont(); @@ -99,134 +99,133 @@ static void land_sct_init(coord x, coord y, s_char *ptr); int main(argc, argv) - int argc; - s_char **argv; +int argc; +s_char **argv; { - extern struct empfile empfile[]; - register int n; - int x, y; - int i, j; - time_t now; - int fd; - int left; - int big; - - if (argc > 1 && argc != 6) { - printf("usage: %s sectrange mincontdist chunksize numchunks numisle\n", - *argv); - return -1; + extern struct empfile empfile[]; + register int n; + int x, y; + int i, j; + time_t now; + int fd; + int left; + int big; + + if (argc > 1 && argc != 6) { + printf + ("usage: %s sectrange mincontdist chunksize numchunks numisle\n", + *argv); + return -1; + } + if (argc == 6) { + sectrange = atoi(argv[1]); + mincontdist = atoi(argv[2]); + chunksize = atoi(argv[3]); + numchunks = atoi(argv[4]); + numisle = atoi(argv[5]); + } + printf("sectrange: %d\n", sectrange); + printf("mincontdist: %d\n", mincontdist); + printf("chunksize: %d\n", chunksize); + printf("numchunks: %d\n", numchunks); + printf("numisle: %d\n", numisle); + fd = open(empfile[EF_SECTOR].file, O_RDWR | O_CREAT | O_TRUNC, 0660); + if (fd < 0) { + perror(empfile[EF_SECTOR].file); + return -1; + } + time(&now); + srandom(now + getpid()); + initworld((plate_e *)plates); + left = NUMLAND; + printf("Creating continents"); + while (left > 0) { + big = (left / (numchunks * 3 * chunksize * chunksize)) + 1; + for (n = 0; n < big; n++) { + newcont(plates, &x, &y, NEWCONTDIST); + left -= makeland(plates, x, y, chunksize, CONTINENT); } - if (argc == 6) { - sectrange = atoi(argv[1]); - mincontdist = atoi(argv[2]); - chunksize = atoi(argv[3]); - numchunks = atoi(argv[4]); - numisle = atoi(argv[5]); + for (n = 0; n < big * numchunks; n++) { + growcont(plates, &x, &y); + left -= makeland(plates, x, y, chunksize, CONTINENT); + if ((n % numchunks) == 0) { + printf("."); + fflush(stdout); + } } - printf("sectrange: %d\n", sectrange); - printf("mincontdist: %d\n", mincontdist); - printf("chunksize: %d\n", chunksize); - printf("numchunks: %d\n", numchunks); - printf("numisle: %d\n", numisle); - fd = open(empfile[EF_SECTOR].file, O_RDWR|O_CREAT|O_TRUNC, 0660); - if (fd < 0) { - perror(empfile[EF_SECTOR].file); - return -1; - } - time(&now); - srandom(now+getpid()); - initworld((plate_e *)plates); - left = NUMLAND; - printf("Creating continents"); - while (left > 0) { - big = (left / (numchunks * 3 * chunksize*chunksize)) + 1; - for (n=0; nsct_type = SCT_WATER; - } else if (total < HILLMIN) - sct->sct_type = SCT_RURAL; - else if (total < PLATMIN) - sct->sct_type = SCT_MOUNT; - else if (total < HIGHMIN) - sct->sct_type = SCT_RURAL; - else - sct->sct_type = SCT_MOUNT; - sct->sct_elev = total; - sct->sct_newtype = sct->sct_type; - sum += total; - if (total < -129) - elev[0]++; - else - if (total > 129) - elev[26]++; - else - elev[13+total/10]++; - } + register struct sctstr *sct; + register int i; + register int x, y; + int elev[12 + 12 + 3]; /* # sects from -12 to 12 in steps of 10 elev */ + int range; + int rangesq; + int total; + int sum; + + for (i = 0; i < 12 + 12 + 3; i++) + elev[i] = 0; + sum = 0; + sct = sects; + for (y = 0; y < YSIZE; y++) { + for (x = 0; x < XSIZE; x++, sct++) { + land_sct_init(x * 2 + (y & 01), y, (s_char *)sct); + range = 3 + rnd(sectrange); + rangesq = range * range; + total = total_land(world, x, y, range) / rangesq; + if (total < LANDMIN) { + sct->sct_type = SCT_WATER; + } else if (total < HILLMIN) + sct->sct_type = SCT_RURAL; + else if (total < PLATMIN) + sct->sct_type = SCT_MOUNT; + else if (total < HIGHMIN) + sct->sct_type = SCT_RURAL; + else + sct->sct_type = SCT_MOUNT; + sct->sct_elev = total; + sct->sct_newtype = sct->sct_type; + sum += total; + if (total < -129) + elev[0]++; + else if (total > 129) + elev[26]++; + else + elev[13 + total / 10]++; } - for (i = 0; i < 12+12+3; i++) - if (elev[i] != 0) - printf("%4d sectors elevation %4d to %4d\n", - elev[i], 10*i - 140, 10*i - 130); + } + for (i = 0; i < 12 + 12 + 3; i++) + if (elev[i] != 0) + printf("%4d sectors elevation %4d to %4d\n", + elev[i], 10 * i - 140, 10 * i - 130); } static void land_sct_init(coord x, coord y, s_char *ptr) { - struct sctstr *sp = (struct sctstr *) ptr; + struct sctstr *sp = (struct sctstr *)ptr; - sp->ef_type = EF_SECTOR; - sp->sct_x = x; - sp->sct_y = y; - sp->sct_dist_x = x; - sp->sct_dist_y = y; + sp->ef_type = EF_SECTOR; + sp->sct_x = x; + sp->sct_y = y; + sp->sct_dist_x = x; + sp->sct_dist_y = y; } diff --git a/src/util/ore.c b/src/util/ore.c index a254cb9fc..0342286f5 100644 --- a/src/util/ore.c +++ b/src/util/ore.c @@ -49,12 +49,10 @@ * sectors, and should be run AFTER you have placed capitals. */ - */ - +* / #if defined(aix) || defined(linux) || defined(solaris) #include #endif /* aix or linux */ - #include #include #include "misc.h" @@ -65,187 +63,187 @@ #include "path.h" #include "xy.h" #include "prototypes.h" - #define XPLATES WORLD_X/2 #define YPLATES WORLD_Y #define YbyX (YPLATES*XPLATES/8) #define ISLANDSIZE 25 #define ISLANDMAX 1000 - -int MIN[] = { 90,85,85,85,70,70,70,70,70 }; -int OIL[] = { 90,80,70,60,50 }; -int GOLD[] = { 90,80,70,60,50 }; -int URAN[] = { 90,80,70,60,50 }; +int MIN[] = { 90, 85, 85, 85, 70, 70, 70, 70, 70 }; +int OIL[] = { 90, 80, 70, 60, 50 }; +int GOLD[] = { 90, 80, 70, 60, 50 }; +int URAN[] = { 90, 80, 70, 60, 50 }; #define MIN_TYPE 0 #define OIL_TYPE 1 #define GOLD_TYPE 2 #define URAN_TYPE 3 -struct sctstr sects[YPLATES*XPLATES]; -u_char s[WORLD_Y][WORLD_X]; -short c[WORLD_Y][WORLD_X]; -short e[WORLD_Y][WORLD_X]; -int size[YbyX]; -int goldchance[YbyX]; -int ironchance[YbyX]; -int oilchance[YbyX]; -int fertchance[YbyX]; -int urchance[YbyX]; -int ix[ISLANDMAX],iy[ISLANDMAX],ic[ISLANDMAX],in=0; -int cont = 0; - -void makec(); -void makeore(); -int place(); -int nearelev(); +struct sctstr sects[YPLATES * XPLATES]; +u_char s[WORLD_Y][WORLD_X]; +short c[WORLD_Y][WORLD_X]; +short e[WORLD_Y][WORLD_X]; +int size[YbyX]; +int goldchance[YbyX]; +int ironchance[YbyX]; +int oilchance[YbyX]; +int fertchance[YbyX]; +int urchance[YbyX]; +int ix[ISLANDMAX], iy[ISLANDMAX], ic[ISLANDMAX], in = 0; +int cont = 0; + +void makec(); +void makeore(); +int place(); +int nearelev(); int main(argc, argp) - int argc; - s_char **argp; +int argc; +s_char **argp; { - register struct sctstr *sp; - register int y; - register int x; - int sectf; - time_t now; - s_char *sectfil = NULL; - int xx,x1,y1; - extern char *optarg; - int opt; - char *config_file = NULL; - - - while ((opt = getopt (argc, argp, "e:s:")) != EOF) { - switch (opt) { - case 'e': - config_file = optarg; - break; - case 's': - sectfil = optarg; - break; - } + register struct sctstr *sp; + register int y; + register int x; + int sectf; + time_t now; + s_char *sectfil = NULL; + int xx, x1, y1; + extern char *optarg; + int opt; + char *config_file = NULL; + + + while ((opt = getopt(argc, argp, "e:s:")) != EOF) { + switch (opt) { + case 'e': + config_file = optarg; + break; + case 's': + sectfil = optarg; + break; } - - emp_config (config_file); - - if (sectfil == NULL) - sectfil = empfile[EF_SECTOR].file; - time(&now); - srandom((unsigned int)now); - sectf = open(sectfil, O_RDWR, 0); - if (sectf < 0) { - perror(sectfil); - exit(1); - } - read(sectf, sects, sizeof(sects)); - sp = sects; - for (y = 0; y < WORLD_Y; y++) { - for (x = 0; x < WORLD_X; x++) { - if (((x ^ y) & 1)) - continue; - c[sp->sct_y][sp->sct_x] = 0; - s[sp->sct_y][sp->sct_x] = sp->sct_type; - e[sp->sct_y][sp->sct_x] = sp->sct_elev; - sp++; - } + } + + emp_config(config_file); + + if (sectfil == NULL) + sectfil = empfile[EF_SECTOR].file; + time(&now); + srandom((unsigned int)now); + sectf = open(sectfil, O_RDWR, 0); + if (sectf < 0) { + perror(sectfil); + exit(1); + } + read(sectf, sects, sizeof(sects)); + sp = sects; + for (y = 0; y < WORLD_Y; y++) { + for (x = 0; x < WORLD_X; x++) { + if (((x ^ y) & 1)) + continue; + c[sp->sct_y][sp->sct_x] = 0; + s[sp->sct_y][sp->sct_x] = sp->sct_type; + e[sp->sct_y][sp->sct_x] = sp->sct_elev; + sp++; } - for (y = 0; y < WORLD_Y; y++) { - for (x = 0; x < WORLD_X; x++) { - if (((x ^ y) & 1)) - continue; - if (c[y][x] != 0) - continue; - if (s[y][x] == SCT_WATER) - continue; - - makec(x, y, 0); - - for(y1=0;y1= ISLANDSIZE){ - xx = ISLANDSIZE/2; - for(y1=0;y1= ISLANDSIZE) { + xx = ISLANDSIZE / 2; + for (y1 = 0; y1 < WORLD_Y; y1++) + for (x1 = 0; x1 < WORLD_X; x1++) + if (c[y1][x1] == cont) { + if (--xx == 0) { + ix[in] = x1; + iy[in] = y1; + ic[in] = cont; + in++; + } } - else{ - printf("Found islet %d of size %d\n", - cont, size[cont]); - for(y1=0;y1 y ? y : x) @@ -253,85 +251,84 @@ makec(x, y, n) void makeore(sp) - register struct sctstr *sp; +register struct sctstr *sp; { - int elev; - int oil, gmin, iron, fertil, ur; - int lev; - int i; - int x,y; - - if (sp->sct_type == SCT_SANCT) - return; - - y = sp->sct_y; - x = sp->sct_x; - - elev = e[y][x]; - lev = (elev*12 + nearelev(x, y))/18; - i = c[y][x]; - oil = 0; - iron = 0; - gmin = 0; - fertil = 0; - ur = 0; - - if (sp->sct_type == SCT_WATER){ - oil = MAXIMUM(((roll(6)+roll(6)-4)*10+roll(10)),0); - sp->sct_oil = MINIMUM(oil,127); - fertil = MAXIMUM(((roll(6)+roll(6)-2)*12+roll(10)),0); - sp->sct_fertil = MINIMUM(fertil,127); - return; - } - iron = roll(100) + 100-roll(100); - oil = roll(100) + 100-roll(100); - ur = roll(100) + 100-roll(100); - gmin = roll(100) + 100-roll(100); - fertil = 85 + 100-roll(100); - - iron = MAXIMUM(iron,0); - oil = MAXIMUM(oil,0); - ur = MAXIMUM(ur,0); - gmin = MAXIMUM(gmin,0); - fertil = MAXIMUM(fertil,0); - iron = MINIMUM(iron,127); - oil = MINIMUM(oil,127); - ur = MINIMUM(ur,127); - gmin = MINIMUM(gmin,127); - fertil = MINIMUM(fertil,127); - + int elev; + int oil, gmin, iron, fertil, ur; + int lev; + int i; + int x, y; + + if (sp->sct_type == SCT_SANCT) + return; + + y = sp->sct_y; + x = sp->sct_x; + + elev = e[y][x]; + lev = (elev * 12 + nearelev(x, y)) / 18; + i = c[y][x]; + oil = 0; + iron = 0; + gmin = 0; + fertil = 0; + ur = 0; + + if (sp->sct_type == SCT_WATER) { + oil = MAXIMUM(((roll(6) + roll(6) - 4) * 10 + roll(10)), 0); + sp->sct_oil = MINIMUM(oil, 127); + fertil = MAXIMUM(((roll(6) + roll(6) - 2) * 12 + roll(10)), 0); + sp->sct_fertil = MINIMUM(fertil, 127); + return; + } + iron = roll(100) + 100 - roll(100); + oil = roll(100) + 100 - roll(100); + ur = roll(100) + 100 - roll(100); + gmin = roll(100) + 100 - roll(100); + fertil = 85 + 100 - roll(100); + + iron = MAXIMUM(iron, 0); + oil = MAXIMUM(oil, 0); + ur = MAXIMUM(ur, 0); + gmin = MAXIMUM(gmin, 0); + fertil = MAXIMUM(fertil, 0); + iron = MINIMUM(iron, 127); + oil = MINIMUM(oil, 127); + ur = MINIMUM(ur, 127); + gmin = MINIMUM(gmin, 127); + fertil = MINIMUM(fertil, 127); + + sp->sct_fertil = fertil; + if (i > ISLANDMAX) { + sp->sct_oil = oil; + sp->sct_min = iron; + sp->sct_gmin = gmin; + sp->sct_uran = ur; + } else { + fertil -= 20; + fertil = MAXIMUM(fertil, 0); + fertil = MINIMUM(fertil, 127); sp->sct_fertil = fertil; - if (i > ISLANDMAX){ - sp->sct_oil = oil; - sp->sct_min = iron; - sp->sct_gmin = gmin; - sp->sct_uran = ur; - } - else{ - fertil -= 20; - fertil = MAXIMUM(fertil,0); - fertil = MINIMUM(fertil,127); - sp->sct_fertil = fertil; - } + } } int nearelev(x, y) - int x; - int y; +int x; +int y; { - int dir; - int dx; - int dy; - int level; - - level = 0; - for (dir = 1; dir <= 6; dir++) { - dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X; - dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y; - level += e[dy][dx]; - } - return level; + int dir; + int dx; + int dy; + int level; + + level = 0; + for (dir = 1; dir <= 6; dir++) { + dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X; + dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y; + level += e[dy][dx]; + } + return level; } /* Already in libgen.a @@ -344,66 +341,73 @@ roll(n) int min(a, b) - int a; - int b; +int a; +int b; { - if (a < b) - return a; - return b; + if (a < b) + return a; + return b; } int -place(island,res,num,offset,restype) -int island, res[], num, offset; -s_char *restype; +place(island, res, num, offset, restype) +int island, res[], num, offset; +s_char *restype; { - int x1,y1,x2,y2,x3,y3,j,k; - int tried[WORLD_Y][WORLD_X]; - int numtried, there; - struct sctstr *foo; - - x1=ix[island]; - y1=iy[island]; - - for(k=0;k 0) || - (sects[y2*XPLATES+x2/2].sct_type==SCT_MOUNT)){ - - there = *((u_char *)(((s_char *)& - sects[y2*XPLATES+x2/2])+offset)); - - foo = §s[y2*XPLATES+x2/2]; - - if (sects[y2*XPLATES+x2/2].sct_type==SCT_RURAL){ - if (!tried[y2][x2]){ - tried[y2][x2]=1; - numtried++; - if (numtried == ISLANDSIZE){ - int a,b; -printf("*** %d) couldn't place %s %d (%d)\n",island,restype,k,res[k]); -for(a=0;a 0) + || (sects[y2 * XPLATES + x2 / 2].sct_type == SCT_MOUNT)) { + + there = + *((u_char *)(((s_char *)§s[y2 * XPLATES + x2 / 2]) + + offset)); + + foo = §s[y2 * XPLATES + x2 / 2]; + + if (sects[y2 * XPLATES + x2 / 2].sct_type == SCT_RURAL) { + if (!tried[y2][x2]) { + tried[y2][x2] = 1; + numtried++; + if (numtried == ISLANDSIZE) { + int a, b; + printf("*** %d) couldn't place %s %d (%d)\n", + island, restype, k, res[k]); + for (a = 0; a < WORLD_Y; a++) + for (b = 0; b < WORLD_X; b++) + if (tried[a][b]) + printf("\tTried %d,%d\n", b, a); + return (0); + } } + } + do { + j = roll(6); + x3 = (diroff[j][0] + x2 + WORLD_X) % WORLD_X; + y3 = (diroff[j][1] + y2 + WORLD_Y) % WORLD_Y; + } while (sects[y3 * XPLATES + x3 / 2].sct_type == SCT_WATER); + x2 = x3; + y2 = y3; + } /* sects[y2*XPLATES+x2/2].sct_min = MIN[k]; */ -*((u_char *)(((s_char *)§s[y2*XPLATES+x2/2])+offset)) = res[k]; - } - return(1); + *((u_char *)(((s_char *)§s[y2 * XPLATES + x2 / 2]) + offset)) = + res[k]; + } + return (1); } diff --git a/src/util/pconfig.c b/src/util/pconfig.c index f5fff21a3..479782500 100644 --- a/src/util/pconfig.c +++ b/src/util/pconfig.c @@ -36,14 +36,15 @@ #include "prototypes.h" int -main (argc, argv) +main(argc, argv) int argc; char *argv[]; { - if (argc > 1) - emp_config (argv[1]); - else emp_config (NULL); + if (argc > 1) + emp_config(argv[1]); + else + emp_config(NULL); - print_config (stdout); - exit (0); + print_config(stdout); + exit(0); } diff --git a/src/util/perfect.c b/src/util/perfect.c index 9097c00e8..ea2880c1e 100644 --- a/src/util/perfect.c +++ b/src/util/perfect.c @@ -51,222 +51,222 @@ #define YPLATES WORLD_Y #define YbyX (YPLATES*XPLATES/8) -struct sctstr sects[YPLATES*XPLATES]; -u_char s[YPLATES][XPLATES]; -short c[YPLATES][XPLATES]; -short e[YPLATES][XPLATES]; -int size[YbyX]; -int goldchance[YbyX]; -int ironchance[YbyX]; -int oilchance[YbyX]; -int fertchance[YbyX]; -int urchance[YbyX]; +struct sctstr sects[YPLATES * XPLATES]; +u_char s[YPLATES][XPLATES]; +short c[YPLATES][XPLATES]; +short e[YPLATES][XPLATES]; +int size[YbyX]; +int goldchance[YbyX]; +int ironchance[YbyX]; +int oilchance[YbyX]; +int fertchance[YbyX]; +int urchance[YbyX]; -void makec(); -void makeore(); -int nearelev(); +void makec(); +void makeore(); +int nearelev(); int main(argc, argp) - int argc; - s_char **argp; +int argc; +s_char **argp; { - register struct sctstr *sp; - register int y; - register int x; - int sectf; - int i; - time_t now; - s_char *sectfil = NULL; - extern char *optarg; - int opt; - char *config_file = NULL; - + register struct sctstr *sp; + register int y; + register int x; + int sectf; + int i; + time_t now; + s_char *sectfil = NULL; + extern char *optarg; + int opt; + char *config_file = NULL; - while ((opt = getopt (argc, argp, "e:s:")) != EOF) { - switch (opt) { - case 'e': - config_file = optarg; - break; - case 's': - sectfil = optarg; - break; - } + + while ((opt = getopt(argc, argp, "e:s:")) != EOF) { + switch (opt) { + case 'e': + config_file = optarg; + break; + case 's': + sectfil = optarg; + break; } + } - emp_config (config_file); + emp_config(config_file); - if (sectfil == NULL) - sectfil = empfile[EF_SECTOR].file; + if (sectfil == NULL) + sectfil = empfile[EF_SECTOR].file; - time(&now); - srandom((unsigned int)now); - sectf = open(sectfil, O_RDWR, 0); - if (sectf < 0) { - perror(sectfil); - exit(1); - } - read(sectf, sects, sizeof(sects)); - sp = sects; - for (y = 0; y < WORLD_Y; y++) { - for (x = 0; x < WORLD_X; x++) { - if (((x ^ y) & 1)) - continue; - c[y][x/2] = 0; - s[y][x/2] = sp->sct_type; - e[y][x/2] = sp->sct_elev; - sp++; - } + time(&now); + srandom((unsigned int)now); + sectf = open(sectfil, O_RDWR, 0); + if (sectf < 0) { + perror(sectfil); + exit(1); + } + read(sectf, sects, sizeof(sects)); + sp = sects; + for (y = 0; y < WORLD_Y; y++) { + for (x = 0; x < WORLD_X; x++) { + if (((x ^ y) & 1)) + continue; + c[y][x / 2] = 0; + s[y][x / 2] = sp->sct_type; + e[y][x / 2] = sp->sct_elev; + sp++; } - for (y = 0; y < WORLD_Y; y++) { - for (x = 0; x < WORLD_X; x++) { - if (((x ^ y) & 1)) - continue; - if (c[y][x/2] != 0) - continue; - makec(x, y, 0); - } + } + for (y = 0; y < WORLD_Y; y++) { + for (x = 0; x < WORLD_X; x++) { + if (((x ^ y) & 1)) + continue; + if (c[y][x / 2] != 0) + continue; + makec(x, y, 0); } - printf("size oil gold fert iron\n"); - for (i=1; i 10) { - printf("%3d %3d %3d %3d %3d\n", - size[i], oilchance[i], goldchance[i], - fertchance[i], ironchance[i]); - } + urchance[i] = roll(30) - goldchance[i]; + fertchance[i] = roll(40) - (goldchance[i] + oilchance[i]); + ironchance[i] = roll(45) - (goldchance[i] + oilchance[i] / 2); + if (size[i] > 10) { + printf("%3d %3d %3d %3d %3d\n", + size[i], oilchance[i], goldchance[i], + fertchance[i], ironchance[i]); } - if (i == YbyX) - printf("Oops. YbyX not big enough\n"); - sp = sects; - for (y = 0; y < WORLD_Y; y++) { - for (x = 0; x < WORLD_X; x++) { - if (((x ^ y) & 1)) - continue; - makeore(sp++); - } + } + if (i == YbyX) + printf("Oops. YbyX not big enough\n"); + sp = sects; + for (y = 0; y < WORLD_Y; y++) { + for (x = 0; x < WORLD_X; x++) { + if (((x ^ y) & 1)) + continue; + makeore(sp++); } - lseek(sectf, 0L, 0); - write(sectf, sects, sizeof(sects)); - close(sectf); - exit(0); + } + lseek(sectf, 0L, 0); + write(sectf, sects, sizeof(sects)); + close(sectf); + exit(0); } -int cont = 0; +int cont = 0; #define max(a,b) (a < b ? b : a) void makec(x, y, n) - int x; - int y; - int n; +int x; +int y; +int n; { - register int dy; - register int dx; - register int dir; - register short *cp; + register int dy; + register int dx; + register int dir; + register short *cp; - if (s[y][x/2] == SCT_WATER) - return; - cp = &c[y][x/2]; - if (*cp != 0) - return; - if (n == 0) - n = ++cont; - *cp = n; - size[n]++; - for (dir = 1; dir <= 6; dir++) { - dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X; - dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y; - makec(dx, dy, n); - } + if (s[y][x / 2] == SCT_WATER) + return; + cp = &c[y][x / 2]; + if (*cp != 0) + return; + if (n == 0) + n = ++cont; + *cp = n; + size[n]++; + for (dir = 1; dir <= 6; dir++) { + dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X; + dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y; + makec(dx, dy, n); + } } void makeore(sp) - register struct sctstr *sp; +register struct sctstr *sp; { - int elev; - int oil, gmin, iron, fertil, ur; - int lev; - int i; - int x,y; + int elev; + int oil, gmin, iron, fertil, ur; + int lev; + int i; + int x, y; - y = sp->sct_y; - x = sp->sct_x; - elev = e[y][x/2]; - lev = (elev*12 + nearelev(x, y))/18; - i = c[y][x/2]; - oil = 0; - iron = 0; - gmin = 0; + y = sp->sct_y; + x = sp->sct_x; + elev = e[y][x / 2]; + lev = (elev * 12 + nearelev(x, y)) / 18; + i = c[y][x / 2]; + oil = 0; + iron = 0; + gmin = 0; + fertil = 0; + ur = 0; + if (lev < 20 && lev > -15 && roll(100) < 30 + oilchance[i] + lev) { + oil = (45 - lev) + roll(50); + if (oil > 100) + oil = 100; + if (oil < 10) + oil = 0; + } + if (lev > 15 && roll(20 + lev) < lev + ironchance[i]) { + iron = lev + roll(55); + if (iron > 100) + iron = 100; + if (iron < 10) + iron = 0; + } + if (lev > 16 && roll(35 + lev) < lev + goldchance[i]) { + gmin = (lev - 5) + roll(45); + if (gmin > 100) + gmin = 100; + if (gmin < 10) + gmin = 0; + } + if (lev > 14 && roll(35 + lev) < lev + urchance[i]) { + ur = (lev - 5) + roll(45); + if (ur > 100) + ur = 100; + if (ur < 10) + ur = 0; + } + fertil = (85 + fertchance[i] - lev) - (((iron + gmin) / 2) - oil / 3); + if (fertil > 120) + fertil = 120; + if (fertil < 0) fertil = 0; - ur = 0; - if (lev < 20 && lev > -15 && roll(100) < 30+oilchance[i]+lev) { - oil = (45 - lev) + roll(50); - if (oil > 100) - oil = 100; - if (oil < 10) - oil = 0; - } - if (lev > 15 && roll(20+lev) < lev+ironchance[i]) { - iron = lev + roll(55); - if (iron > 100) - iron = 100; - if (iron < 10) - iron = 0; - } - if (lev > 16 && roll(35+lev) < lev+goldchance[i]) { - gmin = (lev - 5) + roll(45); - if (gmin > 100) - gmin = 100; - if (gmin < 10) - gmin = 0; - } - if (lev > 14 && roll(35+lev) < lev+urchance[i]) { - ur = (lev - 5) + roll(45); - if (ur > 100) - ur = 100; - if (ur < 10) - ur = 0; - } - fertil = (85 + fertchance[i] - lev) - (((iron + gmin)/2) - oil/3); - if (fertil > 120) - fertil = 120; - if (fertil < 0) - fertil = 0; - sp->sct_oil = 100; - sp->sct_min = 100; - sp->sct_gmin = 100; - sp->sct_fertil = 100; - sp->sct_uran = 100; + sp->sct_oil = 100; + sp->sct_min = 100; + sp->sct_gmin = 100; + sp->sct_fertil = 100; + sp->sct_uran = 100; } int nearelev(x, y) - int x; - int y; +int x; +int y; { - int dir; - int dx; - int dy; - int level; + int dir; + int dx; + int dy; + int level; - level = 0; - for (dir = 1; dir <= 6; dir++) { - dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X; - dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y; - level += e[dy][dx/2]; - } - return level; + level = 0; + for (dir = 1; dir <= 6; dir++) { + dx = (diroff[dir][0] + x + WORLD_X) % WORLD_X; + dy = (diroff[dir][1] + y + WORLD_Y) % WORLD_Y; + level += e[dy][dx / 2]; + } + return level; } /* Already in libgen.a @@ -279,10 +279,10 @@ roll(n) int min(a, b) - int a; - int b; +int a; +int b; { - if (a < b) - return a; - return b; + if (a < b) + return a; + return b; } -- 2.43.0