Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!cbatt!ucbvax!okamoto
From: okamoto@ucbvax.UUCP
Newsgroups: net.sources.games
Subject: Trek73 (Part 1 of 6)
Message-ID: <16574@ucbvax.BERKELEY.EDU>
Date: Wed, 10-Dec-86 12:10:11 EST
Article-I.D.: ucbvax.16574
Posted: Wed Dec 10 12:10:11 1986
Date-Received: Sun, 14-Dec-86 03:25:27 EST
Organization: University of California at Berkeley
Lines: 1979
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# Makefile
# defines.h
# externs.h
# options.h
# structs.h
# cmds1.c
# cmds2.c
# This archive created: Wed Dec 10 09:01:05 1986
# By: Jeff Okamoto ()
export PATH; PATH=/bin:$PATH
if test -f 'Makefile'
then
echo shar: will not over-write existing file "'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
#
# Makefile for TREK73
#
#
# Select which operating system you are using.
# Acceptable flags are BSD and SYSV.
#
OS = BSD
#
# Select whether you wish to use symbolic debugger or not.
# NOTE: UNIX System V Release 2.0 cannot do profiling on programs
# compiled with -g. Also, sdb will not be very useful if the
# symbols are stripped from the load module. (See STRIP)
#SDB = -g
SDB =
#
# Select whether code optimization is to be done.
OPT = -O
#OPT =
#
# Select whether profiling is to be done.
# NOTE: In System V Relase 2.0, this is incompatible with
# both SDB and STRIP.
# PROF = -p
PROF =
#
# Select whether or not the load module is to be stripped.
# This is incompatible with both SDB and PROF.
# Note: In BSD Unix, this option should always be blank
# STRIP = -s
STRIP =
#
# Select whether or not tracing mode is to be turned on.
# This is useful when testing new strategies.
TRACE = -DTRACE
DEFINES = -D${OS}
CFLAGS = ${DEFINES} ${SDB} ${OPT} ${PROF} ${STRIP}
T73OBJECTS = cmds1.o cmds2.o cmds3.o cmds4.o damage.o dist.o endgame.o\
enemycom.o firing.o globals.o init.o main.o misc.o mission.o\
moveships.o parseopts.o save.o ships.o special.o strat1.o\
subs.o vers.o
T73CFILES = cmds1.c cmds2.c cmds3.c cmds4.c damage.c dist.c endgame.c\
enemycom.c firing.c globals.c init.c main.c misc.c mission.c\
moveships.c parseopts.c save.c ships.c special.c strat1.c\
subs.c vers.c
BPVOBJECTS = bpv.o ships.o
BPVFILES = bpv.c ships.c
DYOOBJECTS = shipyard.o
DYOFILES = shipyard.c
HEADS= structs.h defines.h externs.h
RDIST = ${T73CFILES} ${BPVFILES} ${DYOFILES} ${HEADS}
LIBS= -lm
FLUFF = parsit.o make.out errs core lint.errs a.out tags\
shar.1 shar.2 shar.3 shar.4
BINS = trek73 bpv shipyard
all: trek73 bpv shipyard
trek73: ${T73OBJECTS} parsit.o
cc ${CFLAGS} ${T73OBJECTS} parsit.o ${LIBS}
install a.out trek73
bpv: ${BPVOBJECTS}
cc ${CFLAGS} ${BPVOBJECTS}
install a.out bpv
shipyard: ${DYOOBJECTS}
cc ${CFLAGS} ${DYOOBJECTS} -lm
install a.out shipyard
${T73OBJECTS}: ${HEADS}
${BPVOBJECTS}: ${HEADS}
${DYOOBJECTS}: ${HEADS}
parsit.o: parsit.c
cc -O -c parsit.c
tags: ${T73CFILES}
ctags ${T73CFILES} ${HEADS}
count:
wc ${T73CFILES} ${HEADS}
lint:
lint -abchx ${DEFINES} ${T73CFILES} > lint.errs
clean:
rm -f ${BINS} ${T73OBJECTS} ${DYOOBJECTS} ${BPVOBJECTS} ${FLUFF}
shar: shar.1 shar.2 shar.3 shar.4
shar.1: Makefile defines.h externs.h options.h structs.h cmds1.c cmds2.c
shar Makefile defines.h externs.h options.h structs.h cmds1.c cmds2.c >$@
shar.2: cmds3.c cmds4.c damage.c dist.c endgame.c enemycom.c
shar cmds3.c cmds4.c damage.c dist.c endgame.c enemycom.c >$@
shar.3: firing.c globals.c init.c main.c misc.c mission.c bpv.c shipyard.c
shar firing.c globals.c init.c main.c misc.c mission.c bpv.c shipyard.c >$@
shar.4: moveships.c parseopts.c parsit.c save.c ships.c special.c strat1.c subs.c vers.c
shar moveships.c parseopts.c parsit.c save.c ships.c special.c strat1.c subs.c vers.c >$@
SHAR_EOF
chmod +x 'Makefile'
fi # end of overwriting check
if test -f 'defines.h'
then
echo shar: will not over-write existing file "'defines.h'"
else
cat << \SHAR_EOF > 'defines.h'
/*
* TREK73: defines.h
*
* Defines for TREK73
*
*/
/* Globals externals */
extern char *strcpy(), *gets();
extern char *Gets();
extern float rectify(), bearing();
#ifdef BSD
extern long random();
#endif
#ifdef SYSV
#define random() ((long)(rand()))
#define srandom(seed) (srand((unsigned)(seed)))
#endif
#define is_dead(sp, sys) ((sp)->status[sys] == 100)
#define randm(x) ((int)random() % (x) + 1)
#define syswork(sp, sys) (randm(100) > (sp)->status[sys])
#define toradians(x) ((double)(x)*.0174533)
#define todegrees(x) ((double)(x)*57.2958)
#define betw(i, j, k) (((j) < (i)) && ((i) < (k)))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define cansee(x) ((x)->cloaking != C_ON)
#define cantsee(x) ((x)->cloaking == C_ON)
#define plural(n) (((n) > 1) ? "s" : "")
#ifndef NULL
#define NULL 0
#endif
/*
* for the item linked list
*/
#define I_UNDEFINED 0
#define I_SHIP 1
#define I_TORPEDO 2
#define I_PROBE 3
#define I_ENG 4
/*
* for the ship status word
*/
#define S_COMP 0
#define S_SENSOR 1
#define S_PROBE 2
#define S_WARP 3
#define S_ENG 4
#define S_DEAD 5
#define S_SURRENDER 6
/* The following define must also be in structs.h */
#define S_NUMSYSTEMS 4 /* Number of systems with damage descriptions */
#define MAXSYSTEMS 7
/*
* for the status message turn off array (shutup[])
*/
#define DISENGAGE 1 /* Autopilot disengaging */
#define SHIELDSF 2 /* Shields fluctuating */
#define PHASERS 3 /* Phasers disengaging */
#define TUBES (PHASERS + MAXPHASERS) /* Tubes disengaging */
#define SURRENDER (TUBES + MAXTUBES) /* Flag for enemy surrender */
#define SURRENDERP 20 /* Flag for our surrender */
#define PLAYDEAD 21 /* Flag for playing dead */
#define CORBOMITE 22 /* Flag for corbomite bluff */
#define BURNOUT 23 /* Flag for warp burnout */
#define HIGHSHUTUP (BURNOUT + 10) /* Burnout + 10 */
/*
* Multiplier for shield 1
*/
#define SHIELD1 1.5
/*
* Defines for the play status word
*/
#define NORMAL 000
#define F_SURRENDER 001
#define E_SURRENDER 002
/*
* Phaser statuses
*/
#define P_NORMAL 000
#define P_DAMAGED 001
#define P_FIRING 002
/*
* Tube statuses
*/
#define T_NORMAL 000
#define T_DAMAGED 001
#define T_FIRING 002
/*
* Probe launcher status
*/
#define PR_NORMAL 000
#define PR_LAUNCHING 001
#define PR_DETONATE 002
#define PR_LOCK 004
/*
* Cloaking device status / capability
*/
#define C_NONE 000
#define C_OFF 001
#define C_ON 002
#define CLOAK_DELAY 2 /*
* Number of turns after cloak is
* dropped before it can be reactivated
*/
/*
* For the damage routine
*/
#define D_PHASER 0
#define D_ANTIMATTER 1
/*
* Some necessary constants
*/
#define HIT_PER_POD 5
#define PROX_PER_POD 50
/*
* A handy little routine
*/
#define MKNODE(cast, star, number) (cast star)malloc(sizeof(cast) * number)
/*
* Definitions for the bad guys
*/
#define MAXESHIPS 9
#define MAXFEDS 9
#define MAXECAPS 8
#define MAXFOERACES 9
/*
* For the different ship classes
*/
#define MAXSHIPCLASS 4
#define MAXPHASERS 11
#define MAXTUBES 11
/*
* Turn costs (either takes a turn or is a free command)
*/
#define TURN 1
#define FREE 0
/*
* Type of torpedo object (can be probe, torpedo, or engineering)
*/
#define TP_TORPEDO 0
#define TP_PROBE 1
#define TP_ENGINEERING 2
/*
* Defines for the end of game calls to warn and final
*/
#define FIN_F_LOSE 0
#define FIN_E_LOSE 1
#define FIN_TACTICAL 2
#define FIN_F_SURRENDER 3
#define FIN_E_SURRENDER 4
#define FIN_COMPLETE 5
#define QUIT 6
/*
* Number of items we allow in space.
*/
#define HIGHSLOT 300
/*
* Trace flags
*/
#define TR_OFF 0
#define TR_ON 1
/*
* Some hard constants
*/
#define MIN_PHASER_SPREAD 10
#define MAX_PHASER_SPREAD 45
#define MAX_PHASER_RANGE 1000
#define MAX_PHASER_CHARGE 10.
#define MIN_PHASER_DRAIN -MAX_PHASER_CHARGE
#define MAX_PHASER_DRAIN MAX_PHASER_CHARGE
#define MAX_TUBE_CHARGE 10
#define MAX_TUBE_PROX 500 /* 50 times the number of pods */
#define MAX_TUBE_SPEED 12
#define MAX_TUBE_TIME 10.
#define MAX_PROBE_DELAY 15
#define MIN_PROBE_CHARGE 10
#define MIN_PROBE_PROX 50
#define MIN_SENSOR_RANGE 100
#define MAX_SENSOR_RANGE 50000
#define INIT_P_SPREAD MIN_PHASER_SPREAD
#define INIT_P_LOAD MAX_PHASER_CHARGE
#define INIT_P_DRAIN MAX_PHASER_DRAIN
#define INIT_P_PERCENT 100
#define INIT_T_LOAD 0
#define INIT_T_PROX 200
#define INIT_T_TIME MAX_TUBE_TIME
#define INIT_T_SPEED MAX_TUBE_SPEED
SHAR_EOF
chmod +x 'defines.h'
fi # end of overwriting check
if test -f 'externs.h'
then
echo shar: will not over-write existing file "'externs.h'"
else
cat << \SHAR_EOF > 'externs.h'
/*
* TREK73: externs.h
*
* External declarations for TREK73
*
*/
/* UNIX include files needed for most (if not all) of the C files */
#include
#ifdef SYSV
#include
#endif SYSV
#ifdef BSD
#include
#endif BSD
#include
/* UNIX extern declarations of functions used which do not
return int plus any extern variable declarations */
extern char *getenv(), *malloc();
extern long time();
extern unsigned sleep(), alarm();
extern void exit(), free(), perror();
#ifdef SYSV
extern void srand();
#endif SYSV
extern char *optarg;
/*
* Now continue with declarations specific to TREK73
*/
#include "structs.h"
extern char *Gets(), *vowelstr();
extern char *sysname[S_NUMSYSTEMS];
extern char *statmsg[S_NUMSYSTEMS + 1];
extern char *feds[];
extern char *options;
extern float init_p_turn[MAXPHASERS][MAXPHASERS];
extern float init_t_turn[MAXTUBES][MAXTUBES];
extern float segment, timeperturn;
extern float rectify(), bearing();
extern char home[256];
extern char savefile[256];
extern char captain[30];
extern char class[3];
extern char com[30];
extern char com_delay[6];
extern char empire[30];
extern char engineer[30];
extern char foeclass[3];
extern char foename[30];
extern char foerace[30];
extern char foestype[30];
extern char helmsman[30];
extern char nav[30];
extern char racename[20];
extern char savefile[256];
extern char science[30];
extern char sex[20];
extern char shipname[30];
extern char shutup[HIGHSHUTUP];
extern char slots[HIGHSLOT];
extern char title[9];
extern int cmdarraysize;
extern int corbomite;
extern int defenseless;
extern int enemynum;
extern int global;
extern int high_command;
extern int reengaged;
extern int restart;
extern int shipnum;
extern int silly;
extern int surrender;
extern int surrenderp;
extern int teletype;
extern int terse;
extern int time_delay;
extern int trace;
extern char can_cloak;
extern double o_bpv;
extern double e_bpv;
extern struct ship_stat us;
extern struct ship_stat them;
extern int (*strategies[])();
extern int rangefind();
extern struct cmd *scancmd(), cmds[];
extern struct race_info aliens[MAXFOERACES];
extern struct damage p_damage, a_damage;
extern struct list *newitem(), head, *tail;
extern struct ship *shiplist[10], *ship_name();
extern struct ship_stat stats[];
SHAR_EOF
chmod +x 'externs.h'
fi # end of overwriting check
if test -f 'options.h'
then
echo shar: will not over-write existing file "'options.h'"
else
cat << \SHAR_EOF > 'options.h'
/*
* TREK73: options.h
*
* Parse_opts defines
*
*/
#define BOOLEAN 0
#define STRING 1
SHAR_EOF
chmod +x 'options.h'
fi # end of overwriting check
if test -f 'structs.h'
then
echo shar: will not over-write existing file "'structs.h'"
else
cat << \SHAR_EOF > 'structs.h'
/*
* TREK73: structs.h
*
* Struct Defs for TREK73
*
*/
#include "defines.h"
struct phaser {
struct ship *target; /* who we're aimed at */
float bearing; /* direction aimed (if no target) */
int drain; /* Drain from engines (to if negative) */
short load; /* energy in phasers */
char status; /* Damaged, etc. */
} ;
struct tube {
struct ship *target; /* who we're aimed at */
float bearing; /* direction aimed (if no target) */
int load; /* energy in tubes */
char status; /* Damaged, etc */
} ;
struct shield {
float eff; /* efficiency from 0-1 */
float drain; /* Actual drain from engines */
float attemp_drain; /* Attempted drain from engines */
} ;
#define MAXWEAPONS 11
#define SHIELDS 4
struct ship {
char name[30]; /* name of ship */
char class[3]; /* Type of ship */
int x, y; /* location */
float warp; /* warp speed */
float newwarp; /* for speed changes */
float course; /* 0-360 */
float newcourse; /* for course changes */
struct ship *target; /* who we're pursuing */
float relbear; /* Relative bearing to keep */
struct phaser phasers[MAXWEAPONS]; /* phaser banks */
int p_spread; /* phaser spread */
int p_percent; /* phaser firing percentage */
int p_blind_left; /* phaser blind area, left side angle */
int p_blind_right; /* phaser blind area, right side angle */
struct tube tubes[MAXWEAPONS]; /* torpedo tubes */
int t_prox; /* proximity delay */
int t_delay; /* time delay to detonation */
int t_lspeed; /* launch speed */
int t_blind_left; /* tube blind area, left side angle */
int t_blind_right; /* tube blind area, right side angle */
struct shield shields[SHIELDS]; /* shields */
int probe_status; /* Probe launcher status */
float eff; /* efficiency */
float regen; /* regeneration (energy per turn) */
float energy; /* amount of effective energy */
float pods; /* max energy level */
int complement; /* crew left alive */
int status[MAXSYSTEMS]; /* Holds damage percentage of these systems */
float delay; /* how long 'till we blow up? */
int id; /* Unique identifier */
int num_phasers; /* Number of phasers */
int num_tubes; /* Number of tubes */
float orig_max; /* Maximum original warp */
float max_speed; /* Maximum warp */
float deg_turn; /* Degrees per warp turn */
float ph_damage; /* Damage divisor from phasers */
float tu_damage; /* Damage divisor from tubes */
int cloaking; /* Cloaking device status */
int cloak_energy; /* Energy needed to run cloak per segment */
int cloak_delay; /* Time until a cloak may be restarted */
int (*strategy)(); /* Which strategy to use */
struct pos { /* Last known position (before a cloak) */
int x,y; /* Coordinates */
float warp; /* Warp speed */
int range; /* Distance to ship */
float bearing; /* Bearing */
float course; /* Course */
} position ;
int p_firing_delay; /* Delay in segments for firing phasers */
int t_firing_delay; /* Delay in segments for firing torpedoes */
} ;
/*
* note that probes act like torpedos
* but have targets; torps only have
* courses
*/
struct torpedo {
struct ship *from; /* pointer to ship they're from */
int x, y; /* coords of object */
float course; /* where it's going */
float speed; /* how fast we're moving */
float newspeed; /* what our target speed is */
struct ship *target; /* who we're aimed at */
int fuel; /* how many antimatter pods it has */
float timedelay; /* seconds until detonation */
int prox; /* proximity fuse */
int id; /* Unique identifier */
int type; /* torpedo, probe, or engineering */
} ;
/*
* the list of what's in space -- depending on the type, we use
* differing parts of the union (data) structure. it's a linked
* list of all the stuff in space.
*/
struct list {
int type;
struct list *back, *fwd;
union {
struct torpedo *tp;
struct ship *sp;
} data;
} ;
struct cmd {
int (*routine)();
char *word1;
char *word2;
int turns;
} ;
/*
* for the phaser and anti-matter damage lists
*/
struct dam {
int roll;
char *mesg;
};
struct damage {
float eff;
float fuel;
float regen;
float crew;
float weapon;
struct dam stats[S_NUMSYSTEMS];
};
struct score {
int score;
int ships;
char captain[30];
char username[10];
};
struct rates {
char *rate;
int points;
};
struct ship_stat {
char abbr[4]; /* Abbreviation */
int class_num; /* Index into array */
int num_phaser; /* Number of phasers */
int num_torp; /* Number of tubes */
int o_warpmax; /* Own max speed */
int e_warpmax; /* Enemy max speed */
float o_eff; /* Own efficiency */
float e_eff; /* Enemy efficiency */
float regen; /* Regeneration */
float energy; /* Starting fuel */
float pods; /* Max pods */
int o_crew; /* Own crew */
int e_crew; /* Enemy crew */
float ph_shield; /* Divisor for phaser damage */
float tp_shield; /* Divisor for torp damage */
int turn_rate; /* Degrees per warp-second */
int cloaking_energy; /* Energy to run cloaking device */
int t_blind_left; /* Start of tube blind area left */
int t_blind_right; /* Start of tube blind area right */
int p_blind_left; /* Start of phaser blind area left */
int p_blind_right; /* Start of phaser blind area right */
/* Must change to absolute time */
int p_firing_delay; /* Delay in segments for firing phasers */
int t_firing_delay; /* Delay in segments for firing torpedoes */
};
struct race_info {
char race_name[30]; /* Name of the race */
char empire_name[30]; /* What they call themselves */
int id; /* Identifier number */
int surrender; /* Chance they will accept a surrender */
int surrenderp; /* Chance they will surrender to you */
int corbomite; /* Chance they fall for a corbomite bluff */
int defenseless; /* Chance they fall for a defenseless ruse */
int attitude; /* Attitude factor for strategies */
char *ship_names[MAXESHIPS]; /* Ship names */
char *ship_types[MAXSHIPCLASS]; /* Ship types */
char *captains[MAXECAPS]; /* Some exemplary captains */
/*
* For the strategic game that is to come. -Deep Thought
*/
int relation; /* Diplomatic relation with other races */
};
struct planet {
char name[30]; /* Planetary name */
int id; /* Unique identifier number */
int x; /* Location in the X plane */
int y; /* Location in the Y plane */
int radius; /* Planetary radius */
int mass; /* Planetary mass */
int race; /* Owner's race */
/*
* planetary weaponry goes here
*/
};
SHAR_EOF
chmod +x 'structs.h'
fi # end of overwriting check
if test -f 'cmds1.c'
then
echo shar: will not over-write existing file "'cmds1.c'"
else
cat << \SHAR_EOF > 'cmds1.c'
/*
* TREK73: cmds1.c
*
* User Commands
*
* fire_phasers, fire_tubes, lock_phasers, lock_tubes,
* turn_phasers, turn_tubes, load_tubes, launch_probe,
* probe_control
*
*/
#include "externs.h"
fire_phasers(sp)
struct ship *sp;
{
char buf1[20];
char buf2[20];
char c;
int typed[MAXPHASERS];
register int i;
register int k;
for (i=0; inum_phasers);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL) {
printf("%s: Belay that order!\n", captain);
return 0;
}
printf(" spread [10-45] ");
(void) Gets(buf2, sizeof(buf2));
if (buf2[0] == NULL) {
printf("%s: Belay that order!\n", captain);
return 0;
}
i = atoi(buf2);
if (i < 10 || i > 45)
return 0;
sp->p_spread = i;
if (strcmp(buf1, "all") && strcmp(buf1, "ALL"))
for (i=0; c = buf1[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_phasers - 1)
continue;
typed[k]++;
if (sp->phasers[k].status & (P_DAMAGED | P_FIRING))
continue;
sp->phasers[k].status |= P_FIRING;
}
else
for (i=0; inum_phasers; i++) {
typed[i]++;
if (sp->phasers[i].status & (P_DAMAGED | P_FIRING))
continue;
sp->phasers[i].status |= P_FIRING;
}
check_p_damage(typed, sp, "fire"); /* Type out if damaged */
check_p_turn(typed, sp, 1);
return 1;
}
fire_tubes(sp)
struct ship *sp;
{
char buf1[20];
char c;
int typed[MAXTUBES];
register int i;
register int j;
register int k;
for (i=0; inum_tubes);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL) {
printf("%s: Belay that order!\n", captain);
return 0;
}
if (strcmp(buf1, "all") && strcmp(buf1, "ALL"))
for (i=0; c = buf1[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_tubes - 1)
continue;
typed[k]++;
if (sp->tubes[k].status & (T_DAMAGED | T_FIRING))
continue;
sp->tubes[k].status |= T_FIRING;
}
else
for (i=0; inum_tubes; i++) {
typed[i]++;
if (sp->tubes[i].status & (T_DAMAGED | T_FIRING))
continue;
sp->tubes[i].status |= T_FIRING;
}
check_t_damage(typed, sp, "fire"); /* Type if damaged */
check_t_turn(typed, sp, 1);
j = 0;
for (i=0; i < sp->num_tubes; i++) {
if ((typed[i] == 0) || (!(sp->tubes[i].status & T_FIRING)))
continue;
if (sp->tubes[i].load == 0) {
if (!j)
printf("Computer: Tube(s) %d", i + 1);
else
printf(", %d", i + 1);
j++;
}
}
if (j > 1)
puts(" are not loaded.");
else if (j == 1)
puts(" is not loaded.");
return 0;
}
lock_phasers(sp)
struct ship *sp;
{
char buf1[20];
char buf2[20];
int typed[MAXPHASERS];
char c;
struct ship *ep;
register int i;
register int k;
for (i=0; inum_phasers);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
printf(" onto [whom] ");
(void) Gets(buf2, sizeof(buf2));
if (buf2[0] == NULL)
return 0;
ep = ship_name(buf2);
if (ep == NULL)
return 0;
if (cantsee(ep)) {
printf("%s: %s, unable to lock phasers onto %s.\n",
nav, title, ep->name);
return 0;
}
if (strcmp(buf1, "all") && strcmp(buf1, "ALL"))
for (i=0; c = buf1[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_phasers - 1)
continue;
typed[k]++;
if (sp->phasers[k].status & P_DAMAGED)
continue;
sp->phasers[k].target = ep;
}
else
for (i=0; inum_phasers; i++) {
typed[i]++;
if (sp->phasers[i].status & P_DAMAGED)
continue;
sp->phasers[i].target = ep;
}
check_p_damage(typed, sp, "lock");
check_p_turn(typed, sp, 0);
return 1;
}
lock_tubes(sp)
struct ship *sp;
{
char buf1[20];
char buf2[20];
int typed[MAXTUBES];
char c;
struct ship *ep;
register int i;
register int k;
for (i=0; inum_tubes; i++)
typed[i] = 0;
if (is_dead(sp, S_COMP)) {
printf("%s: Impossible %s, our computer is dead.\n", science, title);
return 0;
}
if (!syswork(sp, S_COMP)) {
printf("%s: Our computer is temporarily buggy", science);
return 0;
}
printf(" lock tubes [1-%d] ", sp->num_tubes);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
printf(" onto whom ");
(void) Gets(buf2, sizeof(buf2));
if (buf2[0] == NULL)
return 0;
ep = ship_name(buf2);
if (ep == NULL)
return 0;
if (cantsee(ep)) {
printf ("%s: %s, unable to lock tubes onto %s.",
nav, title, ep->name);
return 0;
}
if (strcmp(buf1, "all") && strcmp(buf1, "ALL"))
for (i=0; c = buf1[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_tubes - 1)
continue;
typed[k]++;
if (sp->tubes[k].status & T_DAMAGED)
continue;
sp->tubes[k].target = ep;
}
else
for (i=0; inum_tubes; i++) {
typed[i]++;
if (sp->tubes[i].status & T_DAMAGED)
continue;
sp->tubes[i].target = ep;
}
check_t_damage(typed, sp, "lock");
check_t_turn(typed, sp, 0);
return 1;
}
turn_phasers(sp)
struct ship *sp;
{
char buf1[20];
char buf2[20];
char c;
int typed[MAXPHASERS];
register int i;
register float j;
register int k;
for (i=0; inum_phasers);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
printf(" to [0-360] ");
(void) Gets(buf2, sizeof(buf2));
if (buf2[0] == NULL)
return 0;
j = atof(buf2);
if (j < 0.0 || j > 360.0)
return 0;
if (strcmp(buf1, "all") && strcmp(buf1, "ALL"))
for (i=0; c = buf1[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_phasers - 1)
continue;
typed[k]++;
if (sp->phasers[k].status & P_DAMAGED)
continue;
sp->phasers[k].target = NULL;
sp->phasers[k].bearing = j;
}
else
for (i=0; inum_phasers; i++) {
typed[i]++;
if (sp->phasers[i].status & P_DAMAGED)
continue;
sp->phasers[i].target = NULL;
sp->phasers[i].bearing = j;
}
check_p_damage(typed, sp, "turn");
check_p_turn(typed, sp, 0);
return 1;
}
turn_tubes(sp)
struct ship *sp;
{
char buf1[20];
char buf2[20];
char c;
int typed[MAXTUBES];
register int i;
register float j;
register int k;
for (i=0; inum_tubes);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
printf(" to [0-360] ");
(void) Gets(buf2, sizeof(buf2));
if (buf2[0] == NULL)
return 0;
j = atof(buf2);
if (j < 0.0 || j > 360.0)
return 0;
if (strcmp(buf1, "all") && strcmp(buf1, "ALL"))
for (i=0; c = buf1[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_tubes - 1)
continue;
typed[k]++;
if (sp->tubes[k].status & T_DAMAGED)
continue;
sp->tubes[k].target = NULL;
sp->tubes[k].bearing = j;
}
else
for (i=0; inum_tubes; i++) {
typed[i]++;
if (sp->tubes[i].status & T_DAMAGED)
continue;
sp->tubes[i].target = NULL;
sp->tubes[i].bearing = j;
}
check_t_damage(typed, sp, "turn");
check_t_turn(typed, sp, 0);
return 1;
}
load_tubes(sp)
struct ship *sp;
{
char buf1[20];
char buf2[20];
char c;
int load;
struct tube *tp;
int typed[MAXTUBES];
register int i;
register float j;
register int k;
for (i=0; inum_tubes);
(void) Gets(buf2, sizeof(buf2));
if (buf2[0] == NULL)
return 0;
if (strcmp(buf2, "all") && strcmp(buf2, "ALL"))
for (i=0; c = buf2[i]; i++) {
k = c - '1';
if (k < 0 || k > sp->num_tubes - 1)
continue;
typed[k]++;
}
else
for (i=0; inum_tubes; i++)
typed[i]++;
for (i = 0; i < sp->num_tubes; i++) {
tp = &sp->tubes[i];
if (!typed[i] || tp->status & T_DAMAGED)
continue;
if (load) {
j = min(sp->energy, MAX_TUBE_CHARGE - tp->load);
if (j <= 0)
continue;
sp->energy -= j;
sp->pods -= j;
tp->load += j;
} else {
j = tp->load;
if (j <= 0)
continue;
sp->energy += j;
sp->pods += j;
tp->load = 0;
}
}
printf("%s: Tubes now ", engineer);
for (i=0; inum_tubes; i++) {
if (sp->tubes[i].status & T_DAMAGED)
printf(" -- ");
else
printf(" %-2d ", sp->tubes[i].load);
}
printf(" energy at %d/%d\n", (int)sp->energy, (int)sp->pods);
return 1;
}
launch_probe(sp)
struct ship *sp;
{
char buf1[20];
int pods, delay, prox;
float course;
struct ship *target;
struct list *lp;
struct torpedo *pp;
pods = delay = prox = 0;
course = 0.0;
target = NULL;
if (is_dead(sp, S_PROBE)) {
printf("%s: Probe launcher destroyed!\n", engineer);
return 0;
}
if (!syswork(sp, S_PROBE)) {
printf("%s: Probe launcher temporarily disabled, %s\n",
engineer, title);
return 0;
}
if (sp->energy < MIN_PROBE_CHARGE) {
printf("%s: We've not enough power, Captain.\n", engineer);
return 0;
}
printf("%s: %d pods available.\n", engineer, (int)sp->energy);
printf("%s: Number to launch [%d+] is ", captain, MIN_PROBE_CHARGE);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
goto bad_param;
pods = atoi(buf1);
if (pods < MIN_PROBE_CHARGE || pods > sp->energy)
goto bad_param;
printf(" set time delay to [0-%d] ", MAX_PROBE_DELAY);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
goto bad_param;
delay = atoi(buf1);
if (delay < 0 || delay > MAX_PROBE_DELAY)
goto bad_param;
printf(" set proximity delay to [%d+] ", MIN_PROBE_PROX);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
goto bad_param;
prox = atoi(buf1);
if (prox < MIN_PROBE_PROX)
goto bad_param;
printf(" launch towards [whom, if anyone] ");
Gets(buf1, sizeof(buf1));
if (*buf1) {
target = ship_name(buf1);
if (target == NULL)
goto bad_param;
if (cantsee(target) || !syswork(sp, S_SENSOR)) {
printf("%s: %s, unable to lock probe onto the %s.\n",
helmsman, title, target->name);
return 0;
}
} else {
printf(" course [0-360] ");
if (gets(buf1) == NULL)
goto bad_param;
course = atof(buf1);
if (course < 0.0 || course > 360.0)
goto bad_param;
target = NULL;
}
/*
* add a new item to the list of items in space
*/
lp = newitem(I_PROBE);
lp->data.tp = MKNODE(struct torpedo, *, 1);
pp = lp->data.tp;
if (pp == (struct torpedo *)NULL) {
fprintf(stderr, "launch_probe: malloc failed\n");
exit(2);
}
pp->from = sp;
pp->fuel = pods;
pp->timedelay = delay;
pp->speed = sp->warp;
pp->newspeed = 3.0;
pp->prox = prox;
pp->target = target;
pp->course = course;
pp->x = sp->x;
pp->y = sp->y;
pp->id = new_slot();
pp->type = TP_PROBE;
/*
* subtract the pods used
*/
sp->pods -= pods;
sp->energy -= pods;
sp->probe_status = PR_LAUNCHING;
printf("%s: Probe %d away\n",engineer, pp->id);
return 1;
bad_param:
printf("%s: Bad parameters, %s.\n", science, title);
return 0;
}
probe_control(sp)
struct ship *sp;
{
register struct list *lp;
register int i;
register float j;
register struct torpedo *pp;
struct torpedo *probes[20];
int probenum;
struct ship *ep;
int pnum;
float bear;
int range;
char buf1[20];
char *bp;
pnum = 0;
for (lp = &head; lp != tail; lp = lp->fwd) {
if (lp->type != I_PROBE)
continue;
pp = lp->data.tp;
if (pp->from != sp)
continue;
if (!pnum)
printf("\nprobe bearng range course time prox units target\n");
if (pnum >= sizeof probes / sizeof probes[0]) {
printf("\n%s: There are other probes out but\n",
nav);
puts(" these are all we can control at one time.");
}
probes[pnum] = pp;
pnum++;
range = rangefind(sp->x, pp->x, sp->y, pp->y);
bear = bearing(sp->x, pp->x, sp->y, pp->y);
if (pp->target == NULL)
bp = "NONE";
else
bp = pp->target->name;
printf(" %2d %4.1f %5d %4.0f %4.1f %5d %3d %s\n",
pp->id, bear, range, pp->course, pp->timedelay,
pp->prox, pp->fuel, bp);
}
if (!pnum) {
printf("%s: What probes?\n", nav);
return 0;
}
printf("%s: Detonate all probes?\n", nav);
printf("%s: [yes or no] ", captain);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] != NULL && (*buf1 == 'Y' || *buf1 == 'y')) {
printf("%s: Aye, %s\n", nav, title);
for (i=0; itimedelay = 0.0;
sp->probe_status = PR_DETONATE;
return 1;
}
printf(" control probe [#] ");
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
probenum = atoi(buf1);
for (i=0; iid == probenum)
break;
if (i == pnum)
return 0;
probenum = i;
printf("%s: Detonate it?\n", nav);
printf("%s: [yes or no] ", captain);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] != NULL && (*buf1 == 'y' || *buf1 == 'Y')) {
probes[probenum]->timedelay = 0.;
sp->probe_status = PR_DETONATE;
return 1;
}
printf(" lock it onto [whom, if anyone] ");
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] != NULL) {
ep = ship_name(buf1);
if (ep != NULL) {
sp->probe_status = PR_LOCK;
if (cansee(ep) && syswork(sp, S_SENSOR)) {
probes[probenum]->target = ep;
printf("%s: locking.\n", nav);
return 1;
} else {
printf("%s: %s, unable to lock probe on the %s.\n",
helmsman, title, ep->name);
return 0;
}
}
}
printf(" set it to course [0-360] ");
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
sp->probe_status = PR_LOCK;
j = atof(buf1);
if (j < 0.0 || j > 360.0)
return 0;
probes[probenum]->course = j;
probes[probenum]->target = NULL;
printf("%s: setting in new course.\n", nav);
return 1;
}
SHAR_EOF
chmod +x 'cmds1.c'
fi # end of overwriting check
if test -f 'cmds2.c'
then
echo shar: will not over-write existing file "'cmds2.c'"
else
cat << \SHAR_EOF > 'cmds2.c'
/*
* TREK73: cmds2.c
*
* User Commands
*
* pos_report, pos_display, pursue, elude, helm, self_scan, scan
*
* (print_damages)
*
*/
#include "externs.h"
#include
pos_report(sp)
struct ship *sp;
{
struct ship *sp1;
struct torpedo *tp;
struct list *lp;
int x, y;
int range;
float bear;
float speed;
float course;
float relbear;
float revrelbear;
int maxlen = 0;
int incltorp = 0;
char whitespace[5], who[80];
#ifdef SHOWTORP
char buf[20];
#endif
#ifdef SHOWTORP
printf("%s: Include torpedoes?\n", science);
printf("%s: [yes or no] ", captain);
if (Gets(buf, sizeof buf) != NULL && (buf[0] == 'y' || buf[0] == 'Y'))
incltorp = 1;
#endif
/*
* Go through the list of objects and find out the longest
* name of any of them. This is to insure that no matter
* what the names of the ship, the position report will
* come out formatted.
*/
for (lp = &head; lp != tail; lp = lp->fwd)
switch(lp->type) {
case I_SHIP:
sp1 = lp->data.sp;
maxlen = max(maxlen, strlen(sp1->name));
break;
#ifdef SHOWTORP
case I_TORPEDO:
if (!incltorp)
break;
tp = lp->data.tp;
maxlen = max(maxlen, strlen(tp->from->name) + 8);
break;
#endif
case I_PROBE:
tp = lp->data.tp;
maxlen = max(maxlen, strlen(tp->from->name) + 9);
break;
case I_ENG:
tp = lp->data.tp;
maxlen = max(maxlen, strlen(tp->from->name) + 12);
break;
}
maxlen += 2; /* For "cloaked" column */
/*
* Construct a string %ns where n is the length of the
* longest name.
*/
(void) sprintf(whitespace, "%%%ds", maxlen);
/*
* And print out the position report
*/
printf(whitespace, " ");
puts(" abs rel rev rel");
printf(whitespace, " ");
puts(" class warp course bearing range bearing bearing");
for (lp = &head; lp != tail; lp = lp->fwd) {
if (lp->type == 0)
continue;
sp1 = NULL;
tp = NULL;
if (lp->type == I_SHIP) {
sp1 = lp->data.sp;
if (is_dead(sp1, S_DEAD))
continue;
if (cansee(sp1)) {
x = sp1->x;
y = sp1->y;
speed = sp1->warp;
course = sp1->course;
/* Reset what we know about his position */
sp1->position.x = sp1->x;
sp1->position.y = sp1->y;
sp1->position.warp = sp1->warp;
sp1->position.course = sp1->course;
sp1->position.bearing = bearing(sp->x,
sp1->x, sp->y, sp1->y);
sp1->position.range = rangefind(sp->x,
sp1->x, sp->y, sp1->y);
(void) sprintf(who, "%.*s ",
sizeof who - 3, sp1->name);
} else {
x = sp1->position.x;
y = sp1->position.y;
speed = sp1->position.warp;
course = sp1->position.course;
(void) sprintf(who, "%.*s *",
sizeof who - 3, sp1->name);
}
} else {
tp = lp->data.tp;
if (lp->type == I_TORPEDO && !incltorp)
continue;
x = tp->x;
y = tp->y;
speed = tp->speed;
course = tp->course;
switch(lp->type) {
#ifdef SHOWTORP
case I_TORPEDO:
(void) sprintf(who,"%.*s torp %d ",
sizeof who - 11, tp->from->name,
tp->id);
break;
#endif
case I_PROBE:
(void) sprintf(who, "%.*s probe %d ",
sizeof who - 12, tp->from->name,
tp->id);
break;
case I_ENG:
(void) sprintf(who,"%.*s engineering ",
sizeof who - 15, tp->from->name);
break;
default:
(void) sprintf(who, "lp->type = %d ",
lp->type);
break;
}
}
printf(whitespace, who);
if (sp1)
printf("%5s", sp1->class);
else
printf(" ");
printf("%6.1f %3.0f ", speed, course);
if (sp1 == sp) {
if (sp->target != NULL)
printf("helm locked on %s", sp->target->name);
putchar('\n');
} else {
bear = bearing(sp->x, x, sp->y, y);
range = rangefind(sp->x, x, sp->y, y);
relbear = rectify(round(bear - sp->course));
revrelbear = rectify(round(bear + 180.0 - course));
printf(" %3.0f %5d %3.0f %3.0f\n",
bear, range, relbear, revrelbear);
}
}
return 0;
}
pos_display(sp)
struct ship *sp;
{
register int i;
register int j;
int range;
char buf1[20];
int x, y;
float xf, yf;
int h, v;
int hpitch = 10;
int vpitch = 6;
char map[13][23]; /* [2*MAXvpitch + 1][2*MAXhpitch + 1] */
struct list *lp;
struct ship *sp1;
struct torpedo *tp;
char c;
if (is_dead(sp, S_SENSOR)) {
printf("%s: Sensors are damaged.\n", science);
return 0;
}
if (!syswork(sp, S_SENSOR)) {
printf("%s: Sensors are temporarily inoperative.\n",
science);
return 0;
}
printf(" display to [%d-%d] ", MIN_SENSOR_RANGE, MAX_SENSOR_RANGE);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
range = atoi(buf1);
if (range < MIN_SENSOR_RANGE || range > MAX_SENSOR_RANGE)
return 0;
/*
* Compensation for aspect ratio of the output device
*/
x = range/hpitch;
y = range/vpitch;
for (i=0; i<=2*vpitch; i++) {
if (i == 0 || i == 2*vpitch)
for(j=0; j<=2*hpitch; j++)
map[i][j] = '-';
else
for(j=0; j<=2*hpitch; j++)
map[i][j] = ' ';
}
map[vpitch][hpitch] = '+';
for (lp = &head; lp != tail; lp = lp->fwd) {
if (lp->data.sp == sp)
continue;
if (lp->type == I_SHIP) {
sp1 = lp->data.sp;
if (cansee(sp1)) {
/* Update the position */
sp1->position.x = sp1->x;
sp1->position.y = sp1->y;
sp1->position.warp = sp1->warp;
sp1->position.course = sp1->course;
sp1->position.bearing = bearing(sp->x, x, sp->y, y);
sp1->position.range = rangefind(sp->x, x, sp->y, y);
xf = sp1->x - sp->x;
yf = sp1->y - sp->y;
} else {
xf = sp1->position.x - sp->x;
yf = sp1->position.y - sp->y;
}
} else {
tp = lp->data.tp;
xf = tp->x - sp->x;
yf = tp->y - sp->y;
}
v = yf/y + vpitch + 0.5;
h = xf/x + hpitch + 0.5;
if (v < 0 || v > 2*vpitch)
continue;
if (h < 0 || h > 2*hpitch)
continue;
switch (lp->type) {
case I_SHIP:
c = lp->data.sp->name[0];
if (cantsee(lp->data.sp))
c = tolower(c);
break;
case I_TORPEDO:
c = ':';
break;
case I_ENG:
c = '#';
break;
case I_PROBE:
c = '*';
break;
default:
c = '?';
break;
}
map[2*vpitch - v][h] = c;
}
for (i=0; i<=2*vpitch; i++) {
for (j=0; j<=2*hpitch; j++)
if (map[i][j] != ' ')
break;
if (j <= 2*hpitch)
printf("%.*s", 2*hpitch + 1, map[i]);
putchar('\n');
}
return 0;
}
pursue(sp)
struct ship *sp;
{
register float i;
char buf1[20];
struct ship *ep;
float warp;
if (is_dead(sp, S_COMP)) {
printf("%s: Impossible, %s, our computer is dead\n",science ,title);
return 0;
}
if (!syswork(sp, S_COMP)) {
printf("%s: Main computer down, %s. Rebooting.\n",
science, title);
return 0;
}
printf(" Mr. %s, pursue [who] ", nav);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
ep = ship_name(buf1);
if (ep == NULL)
return 0;
if (cantsee(ep)) {
printf("%s: %s, unable to acquire helm lock.\n", nav, title);
return 0;
}
printf(" Mr. %s, warp factor [-%.2f to %.2f] ", helmsman,
sp->max_speed, sp->max_speed);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
warp = atof(buf1);
if (fabs(warp) > 1.0 && is_dead(sp, S_WARP)) {
printf("%s: Warp drive is dead, Captain.\n", science);
warp = (warp < 0.0) ? -1.0 : 1.0;
}
if (fabs(warp) > sp->max_speed) {
printf("%s: %s, the engines canna go that fast!\n",engineer, title);
warp = (warp < 0.0) ? -sp->max_speed : sp->max_speed;
}
sp->newwarp = warp;
sp->target = ep;
sp->relbear = 0.0;
i = bearing(sp->x, ep->x, sp->y, ep->y);
printf("%s: Aye, %s, coming to course %3.0f.\n", nav, title, i);
sp->newcourse = i;
return 1;
}
elude(sp)
struct ship *sp;
{
register float i;
char buf1[20];
struct ship *ep;
float warp;
if (is_dead(sp, S_COMP)) {
printf("%s: Impossible, %s, our computer is dead\n",
science, title);
return 0;
}
if (!syswork(sp, S_COMP)) {
printf("%s: Main computer down, %s. Rebooting.\n",
science, title);
return 0;
}
printf(" Mr. %s, elude [who] ", nav);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
ep = ship_name(buf1);
if (ep == NULL)
return 0;
if (cantsee(ep)) {
printf("%s: %s, unable to acquire helm lock.\n",
nav, title);
return 0;
}
printf(" Mr. %s, warp factor [-%.2f to %.2f] ", helmsman,
sp->max_speed, sp->max_speed);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
warp = (float) atof(buf1);
if (fabs(warp) > 1.0 && is_dead(sp, S_WARP)) {
printf("%s: Warp drive is dead, Captain.\n", science);
warp = (warp < 0.0) ? -1.0 : 1.0;
}
if (fabs(warp) > sp->max_speed) {
printf("%s: %s, the engines canna go that fast!\n",engineer, title);
warp = (warp < 0.0) ? -sp->max_speed : sp->max_speed;
}
sp->newwarp = warp;
sp->target = ep;
sp->relbear = 180.0;
i = bearing(sp->x, ep->x, sp->y, ep->y);
i = rectify(i + 180.0);
printf("%s: Aye, %s, coming to course %3.0f.\n", nav, title, i);
sp->newcourse = i;
return 1;
}
helm(sp)
struct ship *sp;
{
char buf1[20];
register float course;
float warp;
printf(" Mr. %s, come to course [0-359] ", nav);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
course = atof(buf1);
if (course < 0.0 || course >= 360.0)
return 0;
printf(" Mr. %s, warp factor [-%.2f to %.2f] ", helmsman,
sp->max_speed, sp->max_speed);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
warp = (float) atof(buf1);
if (fabs(warp) > 1.0 && is_dead(sp, S_WARP)) {
printf("%s: Warp drive is dead, Captain.\n", science);
warp = (warp < 0.0) ? -1.0 : 1.0;
}
if (fabs(warp) > sp->max_speed) {
printf("%s: %s, the engines canna go that fast!\n",engineer, title);
warp = (warp < 0.0) ? -sp->max_speed : sp->max_speed;
}
sp->newwarp = warp;
sp->newcourse = course;
sp->target = NULL;
sp->relbear = 0.0;
printf("%s: Aye, %s.\n", nav, title);
printf("%s: Aye, %s.\n", helmsman, title);
return 1;
}
self_scan(sp)
struct ship *sp;
{
(void) print_damage(sp);
return 1;
}
scan(sp)
struct ship *sp;
{
struct ship *ep = NULL;
struct torpedo *tp = NULL;
struct list *lp;
int item = I_UNDEFINED;
int probe_num;
char buf1[20];
printf(" %s, scan [who] ", science);
(void) Gets(buf1, sizeof(buf1));
if (buf1[0] == NULL)
return 0;
if (buf1[0] == '#') {
strcpy(buf1,buf1+1);
if (strlen(buf1) == 0) {
printf("%s: %s, scan whose engineering?\n", science, title);
return 0;
}
ep = ship_name(buf1);
if (ep == NULL) {
printf("%s: %s, no such ship as the %s.\n", science, title, buf1);
return 0;
}
for (lp = &head; lp != NULL; lp = lp->fwd) {
if (lp == tail)
break;
if (lp->type == I_UNDEFINED)
continue;
if (lp->type == I_ENG && lp->data.tp->from == ep) {
tp = lp->data.tp;
break;
}
}
if (tp == NULL) {
printf("%s: %s, the %s has not jettisoned it's engineering.\n",
science, title, ep->name);
return 0;
}
item = I_ENG;
} else if ((probe_num = atoi(buf1)) > 0) {
for (lp = &head; lp != NULL; lp = lp->fwd) {
if (lp == tail)
break;
if (lp->type != I_PROBE)
continue;
if (lp->data.tp->id == probe_num) {
tp = lp->data.tp;
break;
}
}
if (tp == NULL) {
printf("%s: %s, there is no probe %d", science, title, probe_num);
return 0;
}
item = I_PROBE;
} else {
ep = ship_name(buf1);
if (ep == NULL) {
printf("%s: %s, no such ship as the %s.\n", science, title, buf1);
return 0;
}
item = I_SHIP;
if (cantsee(ep)) {
printf("%s: %s, I am unable to scan the %s.\n",
science, title, ep->name);
return 0;
}
}
if ((sp != ep) && (is_dead(sp, S_SENSOR))) {
printf ("%s: The sensors are damaged, Captain.\n",
science);
return 0;
}
if ((sp != ep) && (!syswork(sp, S_SENSOR))) {
printf("%s: %s, sensors are temporarily out.\n",
science, title);
return 0;
}
if ((sp == ep) && (item == I_SHIP)) {
printf ("%s: Captain, don't you mean 'Damage Report'?\n", science);
return 0;
}
if (item == I_SHIP)
(void) print_damage(ep);
else
(void) scan_torpedo(tp);
return 1;
}
print_damage(ep)
struct ship *ep;
{
register int i;
register int j;
register float k;
printf("\n\nDamages to the %s\n", ep->name);
for (i=0; istatus[i] && i < S_NUMSYSTEMS)
printf("%s damaged %d%%\n", sysname[i], ep->status[i]);
}
printf("Survivors: %d\n", ep->complement);
printf("Helm lock: ");
if (ep->target == NULL)
printf("none.\n");
else
printf("%s\n",ep->target);
printf("\nPhasers Control");
for (i=0; inum_phasers; i++) {
if (ep->phasers[i].status & P_DAMAGED)
printf("\tdamaged");
else if (ep->phasers[i].target == NULL)
printf("\tmanual");
else
printf("\t%.7s", ep->phasers[i].target->name);
}
printf("\n\t turned");
for (i=0; inum_phasers; i++)
if (ep->phasers[i].status & P_DAMAGED)
printf("\t");
else if (ep->phasers[i].target == NULL)
printf("\t%.0f", ep->phasers[i].bearing);
else
printf("\tLOCKED");
printf("\n\t level");
for (i=0; inum_phasers; i++)
if (ep->phasers[i].status & P_DAMAGED)
printf("\t");
else
printf("\t%-2d", ep->phasers[i].load);
printf("\n");
printf("\nTubes\tcontrol");
for (i=0; inum_tubes; i++) {
if (ep->tubes[i].status & T_DAMAGED)
printf("\tdamaged");
else if (ep->tubes[i].target == NULL)
printf("\tmanual");
else
printf("\t%.7s", ep->tubes[i].target->name);
}
printf("\n\t turned");
for (i=0; inum_tubes; i++)
if (ep->tubes[i].status & T_DAMAGED)
printf("\t");
else if (ep->tubes[i].target == NULL)
printf("\t%.0f", ep->tubes[i].bearing);
else
printf("\tLOCKED");
printf("\n\t level");
for (i=0; inum_tubes; i++)
if (ep->tubes[i].status & T_DAMAGED)
printf("\t");
else
printf("\t%-2d", ep->tubes[i].load);
printf("\n");
printf("\nShields\t levels");
for (i=0; ishields[i].eff * ep->shields[i].drain;
printf("\t%-2d", j);
}
printf("\n\t drains");
for (i=0; ishields[i].attemp_drain;
printf("\t%-4.2f", k);
}
printf("\n\nEfficiency: %4.1f\tFuel remaining: %d\n",
ep->eff, (int)ep->energy);
printf("Regeneration: %4.1f\tFuel capacity: %d\n",
ep->regen, (int)ep->pods);
return 1;
}
scan_torpedo(pp)
struct torpedo *pp;
{
char kind[20];
char tgt[20];
printf("\nobject id time prox units target\n");
if (pp->type == TP_PROBE)
strcpy(kind, "probe");
else
strcpy(kind, "engng");
if (pp->target == NULL)
strcpy(tgt, "NONE");
else
strcpy(tgt, pp->target->name);
printf("%-7s%2d %2.1f %4d %3d %s\n",
kind, pp->id, pp->timedelay, pp->prox, pp->fuel, tgt);
return 1;
}
SHAR_EOF
chmod +x 'cmds2.c'
fi # end of overwriting check
# End of shell archive
exit 0