v02i037: multiplayer startrek game, Part03/07

Mike Wexler mikew at wyse.wyse.com
Fri Dec 9 12:00:32 AEST 1988


Submitted-by: ddickey at gonzo.eta.com (Dan A. Dickey)
Posting-number: Volume 2, Issue 37
Archive-name: xtrek/part03

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 7)."
# Contents:  detonate.c doc redraw.c
# Wrapped by mikew at wyse on Thu Dec  8 17:51:40 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'detonate.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'detonate.c'\"
else
echo shar: Extracting \"'detonate.c'\" \(2878 characters\)
sed "s/^X//" >'detonate.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)detonate.c	1.1";
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#include <sys/shm.h>
X#include "defs.h"
X#include "data.h"
X
X/* Detonate torp */
X
X/*
X** Detonating torps have become a difficult part of the game.  Players
X** quickly learned that detonating their own torps when the cloud was
X** around another player, caused that player to die very quickly.  I
X** removed that feature because it lead to people not having to shoot
X** well to collect kills.  Now when players detonate their own torps,
X** the torps just vanish and become available for future firing.
X** NOTE:  BOOO!  Put this back in!
X*/
X
Xdetmine(p)
Xregister struct player	*p;
X{
X    register int i;
X
X    if (p->p_flags & PFWEP) {
X	warning(p, "Weapons overheated");
X	return;
X    }
X    for (i = 0; i < MAXTORP; i++) {
X	if (torps[i + (p->p_no * MAXTORP)].t_status == TMOVE) {
X	    torps[i + (p->p_no * MAXTORP)].t_status = TOFF;
X	}
X	else if (torps[i + (p->p_no * MAXTORP)].t_status == TSTRAIGHT) {
X	    torps[i + (p->p_no * MAXTORP)].t_status = TOFF;
X	}
X    }
X}
X
X/*
X** Here we have another flaw.  Detonating other players torps can be a
X** very quick way to die.  Why?  Because you always take some damage.
X** Experienced players never detonate other players' torps.  Balance is
X** really hard to obtain with this type of function.  Technically, a
X** player could nearly continuously detonate torps (at least faster than
X** they could be fired) and never be hurt, if I allowed less damage as
X** a possible result.  So here it sits.
X*/
X
Xdetothers(p)
Xregister struct player	*p;
X{
X    register int h, i;
X    int dx, dy;
X    register struct torp *j;
X
X    if (p->p_fuel < p->p_ship.s_detcost) {
X	warning(p, "Not enough fuel to detonate");
X	return;
X    }
X    if (p->p_flags & PFWEP) {
X	warning(p, "Weapons overheated");
X	return;
X    }
X    p->p_fuel -= p->p_ship.s_detcost;
X    p->p_wtemp += p->p_ship.s_detcost / 5;
X
X    for (h = 0; h < MAXPLAYER; h++) {
X	if ((players[h].p_status == PFREE) || (h == p->p_no))
X	    continue;
X	for (i = h * MAXTORP; i < MAXTORP * (h + 1); i++) {
X	    j = &torps[i];
X	    if ((j->t_status == TMOVE) || (j->t_status == TSTRAIGHT)) {
X		dx = j->t_x - p->p_x;
X		dy = j->t_y - p->p_y;
X		if (ABS(dx) > DETDIST || ABS(dy) > DETDIST) /* XXX */
X		    continue;
X		if (dx * dx + dy * dy < DETDIST * DETDIST)
X		    j->t_status = TDET;
X	    }
X	}
X    }
X}
END_OF_FILE
if test 2878 -ne `wc -c <'detonate.c'`; then
    echo shar: \"'detonate.c'\" unpacked with wrong size!
fi
# end of 'detonate.c'
fi
if test -f 'doc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'doc'\"
else
echo shar: Extracting \"'doc'\" \(23937 characters\)
sed "s/^X//" >'doc' <<'END_OF_FILE'
X.\"Xtrek -- a multiplayer, space shoot 'em up game.
X.\"by Chris Guthrie
X.\"with assistance of Ed James and playtesting of the XCF
X.\"Copyright (c) 1986 Chris Guthrie
X.\"static char sccsid[] = "@(#)doc	1.1";
X
X.sh 1 "Introduction"
X.pp
XWelcome to xtrek.
XXtrek is the latest in a line of games based on Empire on the PLATO
Xsystem.
XMost of the ideas are stolen from the unix game
X.i Trek83
Xby David Davis and Chris Guthrie and the VMS game
X.i Conquest
Xby Jef Poskanzer and Craig Leres.
XXtrek is a multi-player, real-time game which uses System V
Xshared memory segments.
XIt currently runs under Ultrix 2.0, Suns 3's running 3.2,
Xand HP 320 systems running HP-UX 5.2.
XSince the game uses shared memory for communications,
Xthe daemon and
Xplayer processes must be run on an an appropriate host.
XHowever, the player program,
X.i xtrek,
Xthrows an X window up on any workstation running X.
XPlease send any ideas/comments to chris at ic.berkeley.edu.
X
X.sh 1 "The Basic Idea"
X.pp
XWhen you play Xtrek, you enter a galaxy as one of four competing
Xraces.
XYou have a warship at your command.
XThe galaxy contains forty planets which start divided evenly between
Xthe four teams.
XThe eventual goal of the game is to conquer the other teams' planets
Xand protect your own.
XUsually this will involve frequently destroying other players'
Xships while avoiding their efforts to destroy yours.
X
X.sh 1 "Starting the Game"
X.pp
XTo enter the game type
X.b "xtrek monitor:0"
Xmuch like any X tool.
XThe program will use the $DISPLAY variable in your environment if
Xit is set.
XIf there is room in the game, you will see an entry window which may
Xcontain some random status information and a choice of teams.
XClick a mouse button in the box of the team you wish to join.
XIn terms of ship and planet abilities, all teams are identical.
XAssuming everything is working properly (including xhosts) you
Xwill be placed in the game.
X
X.sh 1 "The Display"
X.pp
XWhen you start the game, you are given five or six windows.
XThe big left window is the local view from your ship.
XYou will see a number of objects in it.
XFirst, your ship will always appear the center of the window.
XOther ships will look like yours except that each
Xteam has a different ship design.
XOn color workstations, each team also has a different color.
XThe small hex character to the right of the ship represents
Xthe player number.
XRound objects with names on them are planets.
XThey also are the color of their owning team.
XSmall dots on the screen are torpedos.
XYou will come to recognize these after they kill you a few
Xtimes.
XEnemy torpedoes are a small cross while friendly torpedoes are a small dot.
XFriendly torpedoes will not explode if they hit you.
XSmall circles are exploding torpedoes.
XLines between ships are phaser shots which hit.
XLines from a ship into space are phaser shots which miss.
X
X.pp
XThe large window on the right is a map of the whole galaxy.
XOnly ships and planets appear on it.
XShips are just a player number (in hex) and team letter.
X
X.pp
XDirectly below the galaxy window is a small window which
Xwill occasionally contain warning messages like "Not enough
Xfuel to fire torp."
XYou will probably be killed shortly after this particular message.
X
X.pp
XBelow the warning window is a message window.  This window
Xwill be described later.
X
X.pp
XThe small window on the left side is your status window.  It's
Xcontents will also be described later.
X
X.sh 1 "User Interface"
X.pp
XThe mouse is the most important interface.
XWhenever the game needs a direction -- to turn your ship, for instance --
Xit will use the mouse's position relative to your ship, in either large
Xwindow.
XTorpedos and phasers will be fired toward the mouse's cursor, and
Xyour ship will turn in the direction of the cursor when
Xappropriate keys are hit.
XCommands are issued through the keyboard and mouse
Xbuttons.
X
X.sh 1 "Quick Instructions for Beginning Players"
X.pp
XSince no normal computer user will want to read the rest
Xof this document, the following is a quick explanation of
Xcombat.  Try it for awhile, then come back and search the
Xdocument for more features.
X
X.sh 2 "Help Window"
X.pp
XTyping 'h' will pop up a help window below the normal window.
XThe help window lists commands you can type.
XIt's useful for small problems like forgetting how to put
Xyour shields up.
XTyping 'h' again will get rid of it.
X
X.sh 2 "Combat"
X.pp
XTo survive in combat, keep moving.  This is done by typing the
Xnumber keys, 0-9.  Ships can fly at warp five indefinitely.
XEngines will eventually overheat at higher speeds.  Turning
Xis easier at low speeds.  Particularly good is warp three or
Xfour.  You turn by pointing your mouse in the direction you
Xwish to go, and typing the rightmost mouse key.  You will
Xturn relative to whatever window you happen to have the mouse
Xin.  When there is an opponent on the screen with you, you
Xprobably want to start firing torpedoes at him.  Again, point the
Xmouse where you want the torpedoes to go and push the leftmost
Xmouse button.  If you get close enough, you might want to
Xtry phasers.  Point the mouse directly at your opponent and
Xpush the middle button.  A line will shoot out and you will
Xget a report on your damage, if you hit.
XAs a default, you will be hostile towards all other teams.
XThis can be changed later.
X
X.pp
XTorpedos that hit each do thirty points of damage to the
Xtarget.  Damage first comes off of shields, and when those
Xreach zero, damage comes directly off the damage stat.  When
Xyour damage hits 100, your ship explodes and your opponent
Xgets credit for killing you.  You can repair damage by going
Xinto repair mode (type 'R') but it will also leave you a
Xsitting duck for other players.  When you finish repairing,
Xuse 'u' or '+' to put your shields back up.
X
X.pp
XFinally, if you get tired of playing, you can quit by typing 
X.b Q
Xand waiting to self-destruct.
XIn the entry window, click the mouse in the 'quit' window to
Xexit the game.
X
X.sh 1 "Status Line"
X.pp
XNow for some of the more technical details.
XThe status line appears below the local window
Xand contains the following useful information:
X
X.sh 2 "Flags -- ship status flags"
X.pp
XVarious flags tell the player about his ship.
X.(l
XS     -- Shields up
X[GYR] -- Alert status
XL     -- Locked onto a target
XR     -- In Repair mode
XB     -- Bombing a planet
XO     -- Orbiting a planet
XC     -- Cloaked
XW     -- Weapons overheated 
XE     -- Engines overheated
Xu     -- Beaming up armies
Xd     -- Beaming down armies
XP     -- Copilot permitted
X.)l
X
X.sh 2 "speed - ship's speed"
X.pp
XThis is the speed your ship is currently travelling.
XShips move between warps 0 and 9.
X
X.sh 2 "dam - current damage"
X.pp
XThis is how much damage your ship has taken.
XIf it gets over 100, you die.
XDamage repairs slowly if shields are down, faster if
Xship is in repair mode.
X
X.sh 2 "shd - current shields"
X.pp
XShields start out at 100 and take damage when they are up.
XWhen they hit 0, damage will come off your damage rating.
XThey repair faster than real damage.
X
X.sh 2 "torps -- number of torpedoes launched"
X.pp
XEach player is limited to twelve torpedoes flying at any given
Xtime.
XThis is a count of the torpedoes you currently have in the air.
X
X.sh 2 "armies -- armies on board"
X.pp
XThis is a count of the number of armies you have on your ship.
XYour ship can carry two times your current number of kills.
XThe maximum number of armies it can carry is ten.
X
X.sh 2 "fuel -- how much fuel you have left"
X.pp
XWeapons and engines take fuel to run.
XThis is a count of the amount of fuel left on the ship.
XFuel regenerates slowly in space, but faster when orbiting a fuel planet.
X
X.sh 2 "wtemp -- weapons temperature"
X.pp
XUsing weapons drives up this stat.
XIf it goes over 100, there is a good chance your weapons will
Xfreeze up for a random amount of time.
XThe temperature drops over time.
X
X.sh 2 "etemp -- engine temperature"
X.pp
XRunning your engines at speeds over five cause engine temperature
Xto climb.
XRunning at less than five causes them to cool.
XOver 100, engines can freeze up for a random amount of time.
X
X.sh 1 "The Commands"
X.pp
XThese are the various key and button commands in the game.
XThey are not currently remappable other than through the XKeyMap
Xfunction.
X
X.sh 2 "0-9 Ship's speed"
X.pp
XThe numbers zero through nine set your ship's speed.
XIt takes time for your ship to accelerate or decelerate to the desired
Xspeed.
XDamaged ships can't use higher speeds.
XWhen engines freeze, you can't set speed.
XSetting speed breaks you out of a planet's orbit.
X
X.sh 2 "k - set course"
X.pp
XThe letter
X.b k
Xor the right mouse button will set your course towards the current
Xmouse position.
XTurning towards the desired course can take time, depending on 
Xyour current speed and damage.
X
X.sh 2 "t - launch torpedo"
X.pp
XThe letter
X.b t
Xor the left mouse button will launch a torpedo towards the current
Xmouse position if you have enough fuel and less than twelve torpedoes
Xcurrently out.
XTorpedos travel at warp twelve and do thirty points of
Xdamage when they hit someone.
XYou cannot be hurt by your own torpedoes.
XTorpedos tend to wobble a bit in flight so they won't always
Xgo straight in the direction you want them to.
XThe effect does create nice clouds of them, though.
X
X.sh 2 "p - fire phaser"
X.pp
XThe letter
X.b p
Xand the middle mouse button will fire your phasers towards the current
Xmouse position if you have enough fuel.
XYou may only fire phasers once per second.
XThey cost a good deal of fuel.
XIf they hit someone, they will do 0-100 points of damage depending on the
Xrange.
X
X.sh 2 "d - detonate other torpedoes"
X.pp
XThis command will detonate other torpedoes near you, doing less
Xthan maximum damage to you.
X
X.sh 2 "D - detonate your own torpedoes"
X.pp
XThis will turn your own torpedoes off (if you've missed)
Xso that you can fire new ones.
X
X.sh 2 "+ - put shields up"
X.pp
XThis key will put your shields up.
XRaised shields will take damage.
X
X.sh 2 "-- - put shields down"
X.pp
XThis key will put your shields down.
XAll damage will go directly to your damage stat.
X
X.sh 2 "u - toggle shields"
X.pp
XThis key will toggle your shields up and down.
X
X.sh 2 "R - repair damage"
X.pp
XYour ship must be going warp zero to repair.  Hitting this key will
Xstop your ship and start repairing.  Your shields are down when you
Xare repairing and you cannot fire weapons.  In a nutshell, you are
Xa sitting duck.  Putting your shields up or moving is the best
Xway to get out of repair mode.
XIf your ship is orbiting a friendly repair planet, damage will repair
Xat a faster rate.
X
X.sh 2 "o - orbit a planet"
X.pp
XIf you are near a planet and going warp two or less this will
Xput in orbit around it.
XYou must be in orbit around a planet to bomb it, beam armies up
Xor down to it, repair at it, or get fuel from it.
XEnemy planets will damage you if you get near them.
XSetting a speed will break out of orbit.
X
X.sh 2 "b - bomb a planet"
X.pp
XIf an enemy planet has more than four armies, you can bomb
Xthem.
XWith four or less armies, you must beam down armies
Xto defeat them.
XYour shields will go down to bomb, and you will
Xtake damage from the planet.
XYou get kills for the armies destroyed.
X
X.sh 2 "z - beam up armies"
X.pp
XIf the planet you are orbiting is owned by your team and
Xhas more than four armies, you can beam
Xthem to your ship to carry to other planets.
XYou must be orbiting to beam up armies.
XThe number of armies you can carry is equal to your kills * 2.
XYou can never carry more than ten armies.
X
X.sh 2 "x - beam down armies"
X.pp
XThis command will beam the armies that are on your ship down to a 
Xplanet you are orbiting.
XIf it is an hostile planet, you will kill his armies.
XIf all enemy armies are killed and you land an army, you take the planet
Xfor your team.
XIf it is a planet you own, you will simply add to the armies
Xalready there.
XIf it is a friendly planet, owned by other teams, you cannot
Xbeam armies down.
X
X.sh 2 "L - get player list"
X.pp
XThis gives you a quick list of other players.
XTo remove this window, just type 'L' again.
X
X.sh 2 "P - get planet list"
X.pp
XThis gives you a list of planets.
XYou get information only on planets which your team
Xowns or has previously orbited.  To remove this window,
Xjust type 'P' again.
X
X.sh 2 "i - info on object"
X.pp
XThis will pop up a window near the mouse cursor which contains
Xinformation about the nearest object (planet or ship).
XTo remove this window, just type 'i' again.
X
X.sh 2 "l - lock onto an object"
X.pp
XThis will lock your ship onto the object nearest the mouse cursor.
XIf you are moving you will turn towards the object your are locked
Xonto.
XIf it is a planet, you will automatically go into orbit around it.
XIf it is another player, your course will constantly be adjusted if
Xhe is moving.
XTo break the lock, just set course normally.
XYou cannot lock onto cloaked ships.
X
X.sh 2 "C - throw a coup"
X.pp
XSometimes players will discover that all their planets have been
Xtaken, or have been left with no armies.
XIn order to allow the team some form of return you can hold a coup
Xon your home planet assuming that the following criterion are met:
X.(l
XYour team must have armies on no planets.
XYou must have more than one kill.
XThere must be less than five enemy armies (or zero friendly, should
Xyou still own it) on your home planet.
XYou must be orbiting your home planet.
X.)l
XAfter the coup, the planet will have four of your armies on it.
XAs they come back you can take over more of your occupied worlds.
X
XWhen your last planet is taken, you will have to wait from thirty
Xminutes to an hour before you can have a coup.
X
X.sh 2 "? - repeat all of the previous messages"
X.pp
XMessage sending is detailed below.  This command allows you to
Xreview the current set of them.
X
X.sh 2 "c - cloak your ship"
X.pp
XThis nifty command allows you to remain invisible on the local
Xwindow of every player.  This would be nice except that you cannot
Xfire weapons while cloaked, and you use more fuel.
XFinally good players can shoot at you on the galaxy map window
Xwhere you will appear as
X.b "??."
XTyping 
X.b 'c'
Xagain will turn cloaking off.
X
X.sh 2 "@ - allow/disallow copilots"
X.pp
XThis feature allows more than one player to fly a ship.  It will
Xbe discussed near the end of this document.
X
X.sh 2 "S - Toggle visual status window"
X.pp
XThis will turn a visually oriented status window on and off.
X
X.sh 2 "w - Set war status"
X.pp
XThis command will give you a window that you can use to declare
Xwar and peace with other teams.  It will be fully detailed below.
X
X.sh 2 "* - Bring in a practice robot"
X.pp
XIf you are the only ship in the game, this command will send a
Xpractice robot into the game.
XThe robot will come in on your team, and be hostile towards you.
XThese robots are not as deadly as the ones which pop up to defend planets.
XHowever, you don't get any credit for killing them -- just practice.
X
X.sh 1 "Nitty Gritty Details"
X.pp
XThis section contains the details on certain features.
X
X.sh 2 "Planets and Armies"
X.pp
XPlanets are updated every minute.  There is a random chance
Xthat the number of armies will increase.  There is also a random
Xchance, that there will be a major die-off of armies.  This later
Xevent is more likely on planets with many armies.
XIf you have less than three armies on the planet, they will not
Xgrow as fast.
XPlanets with no armies are owned by the independent team and will
Xhave no armies on them until someone beams one down.
X
X.pp
XEnemy planets do damage based on the number of armies they have.
XThis means planets with no armies do no damage.  Those with armies
Xwill do (armies / 10) + 2 points of damage twice each second.
X
X.pp
XThe teams' home planets and randomly, others, will provide
Xfuel and repair services.  Obviously, this makes these planets
Xparticularly valuable.  These planets are selected up when the galaxy
Xis reset.
X
X.sh 2 "Messages"
X.pp
XMessages are sent both from the daemon and from other players.
XThey appear in the message window at the bottom, right side of the display.
XTo send messages, just put the mouse into the message window.
XYou must type a character in that represents the recipient of your
Xmessage.  This can be 'A' for everyone.  [FRKO] to send to all members
Xof a given team.  [0-9abcdef] will send a message to an individual
Xplayer.  When you've typed this in, it will map to a proper address
Xand wait for you to type in some text.  When you type in a return,
Xyour message is sent.
XTyping an escape will abort the message in progress.
X
X.pp
XNow obviously, the next question is, "What if someone starts shooting
Xat me while I'm typing in my message?  Am I hosed?"
XSimply move the mouse out of the window to defend yourself.  Messages
Xare only dealt with if the mouse is in the window.  You can stop
Xin the middle of the input.
X
X.sh 2 "Robots"
X.pp
XRobots are an attempt to allow/prevent certain things.  First, we want
Xbeginning players to have some lousy competition so they can get some
Xpractice without simply being targets for better players.  Secondly,
Xwe want to make sure that taking over the galaxy is not a midnight
Xwaltz.
X
X.pp
XIn order to invite a robot into the game, players are advised
Xto use the '*' command (described above) to bring in a practice
Xrobot.
XThese robots are relatively easy to kill.
XThe second way to get a robot is to go into another team's space
Xand bomb one of
X.i their
Xplanets.
XA robot will promptly show up and kill you.
XOr at least try to kill you.
XThese defender robots are particularly nasty.
XGood luck.
X
X.pp
XRobots are very much like other players.  The only advantage they
Xhave over other players is that they don't use fuel.  Otherwise,
Xtheir torpedoes do the same damage.  They are also somewhat better shots.
XTheir torpedoes don't wobble, and they never miss with their phasers.
X
X.sh 2 "War and Peace"
X.pp
XYou can declare war and peace with other teams.
XThe greatest use of this is that you can use planets belonging
Xto teams you are at peace with for fuel and repair.
XIt also allows two teams to gang up on another without risking
Xkilling each other.
X
X.pp
XThere are three states a player can be in versus any other team:
XPeace, Hostile, and War.  Being at War is irrevocable.  You cannot
Xchange to any other state until you reenter the game.  You get to
Xwar when you are hostile to a team and you either bomb one of their
Xplanets, damage one of their players with weapons, or beam armies
Xdown to one of their planets.
X
X.pp
XIf you are hostile towards a team, your weapons will hurt all members of
Xthat team (whether or not they are at peace with you).  As soon as
Xyou hurt them, you will be at war.
X
X.pp
XIf you are peaceful towards a team, your weapons will only hurt members
Xof that team who are not peaceful towards you.  In other words, two
Xplayers who are at peace towards each other cannot fight each other.
X
X.pp
XPlayers default to being at peace with their own team and hostile
Xtowards all the others.  Obviously, they can declare war on their own
Xteam.
X
X.pp
XTo change your settings, type 'w' and a war window will pop up.
XClick the mouse in the boxes of the teams you want to change.
XClick in "re-program" to save the results.  Teams will be notified
Xof your changes.  Finally, there is a ten second delay to declare
Xhostility towards another team so don't get too close while you make
Xthe changes.
X
X.pp
XThe easiest way to know if someone near you is hostile is to use
Xthe alert status described below.  Info on a player will tell you
Xtheir status towards you.
X
X.sh 2 "Weapons"
X.pp
XTorpedos move at warp twelve and have a random life of three to five
Xseconds.  They tend to wobble a bit, so their accuracy goes down
Xat longer ranges.  Torpedoes will detonate and do full damage if
Xthey get close to a ship.  They will do less damage to objects at a
Xslightly longer distance.  Torpedos will not be detonated by a non-hostile
Xplayer, but they will do damage if something causes them to explode.
X
X.pp
XWhen exploding, torpedoes can damage everyone who is near them except
Xthe person who launched them.  Thus it is possible to kill your own
Xteammates and people you are at peace with.
X
X.pp
XPhasers must be within about 10 degrees of their target to hit.
XPhasers that hit will maintain a line between the two ships.
XOnes that miss will stick out to nowhere and look stupid.
XAll phasers cost a good deal of fuel.  It takes one second
Xto recharge your phasers for another shot.
XYour phasers will affect teams you are at war with, or those
Xwho are at war with you.
X
X.pp
XShips that explode cause 100 points of damage with about the same
Xrange as a torpedo.  Don't get too near one.
X
X.sh 2 "The Galaxy"
X.pp
XYou will bounce off the edge of the galaxy if you run into it.
XTorpedos explode if they hit it.
X
X.sh 2 "Planet information"
X.pp
XYou can get information about any planet your team has orbited.
XHowever, if the planet is taken by any other team, you will
Xlose information about the planet until it is reorbited.
X
X.sh 2 "Ship's Status"
X.pp
XYour ship's alert status will tell you how close you are to hostile
Xships.  Yellow alert represents about two screens distance.  Red
Xalert means that the enemy is on your local screen (even if cloaked).
XBesides the status line, the border of your window tells you what
Xyour alert status is.  This also works for the border of the icon.
XThe border patterns are discussed below.
X
X.sh 2 "Xdefaults and options"
X.pp
XYou can put the following options into your .Xdefaults
X.(l
Xxtrek.boldfont:		6x10b
Xxtrek.font:		6x10
Xxtrek.name:		DragonSlayer
Xxtrek.reverseVideo:	off
Xxtrek.showShields:	on
Xxtrek.showStats:		on
Xxtrek.stats.geometry:	+0+655
Xxtrek.GAlertPattern:	0xf
Xxtrek.YAlertPattern:	0xa 0x5
Xxtrek.RAlertPattern:	0x0f 0x0f 0x0f 0x0f 0xf0 0xf0 0xf0 0xf0
Xxtrek.ralert:		red
Xxtrek.yalert:		yellow
Xxtrek.galert:		green
Xxtrek.border:		blue
Xxtrek.background:	black
Xxtrek.text:		white
Xxtrek.fed:		yellow
Xxtrek.rom:		red
Xxtrek.kli:		green
Xxtrek.ori:		slate blue
Xxtrek.warning:		red
Xxtrek.unknown:		light grey
Xxtrek.me:		white
X.)l
X
X.sh 3 "Fonts"
X.pp
XThese options allow you to change fonts used in the game.
XOur advice: "Don't."
X
X.sh 3 "name"
X.pp
XThis is your playername.
X
X.sh 3 "reversevideo"
X.pp
XOn black and white monitors this can ease eye-strain.
X
X.sh 3 "showShields"
X.pp
XThis causes the shields of you and other players to appear
Xas a circle around your ship when they are up.
X
X.sh 3 "showStats"
X.pp
XThis option will put up a visual status window above your display.
XSome players find this easier to read than numbers.
XThe stats.geometry uses standard X syntax for a screen position.
X
X.sh 3 "Alert Patterns"
X.pp
XThese patterns are useful for showing your current alert status
Xbased on the border pattern.  It is used for black and white
Xmonitors only.
XThe alert colors are used for color monitors.  I think changing
Xthem would be silly.
X
X.sh 3 "The remaining color definitions"
X.pp
XThese options allow you to set colors on various objects
Xso you can get much more information from your display.
XObviously, these only matter for color monitors.
X
X.sh 2 "Other programs related to xtrek"
X.pp
XThere are few other programs that come with xtrek that
Xhave some use in the game.  They are described below.
X
X.sh 3 "Copilot"
X.pp
XThis program, started with the command:
X
X.ti 1i
X.b "xtrek -c pno monitor:0"
X
Xwill allow you to fly a ship with player number pno
Xif he so permits.  This command is pretty robust.
XTwo players flying a ship can be very deadly.
XTypically, one steers and one shoots.
X
X.sh 3 "scores"
X.pp
XXtrek does, in fact keep some statistics around in the
Xfile .scores.  Scores can be used to print this information out.
XIt obviously should have been built into xtrek itself.
X
X.sh 3 "robot"
X.pp
XThis is the program xtrek uses to send robots into the game.
XRobots come with gobs of command line options, but you'll have
Xto look at the code to see what they do.
X
X.sh 3 "watch"
X.pp
XLike copilot, watch mode can be entered directly from
Xxtrek using the command:
X
X.ti 1i
X.b "xtrek -w pno monitor:0"
X
XThis allows you to watch all the actions taken by the particular
Xplayer (without him knowing it).
XYou can change the player being viewed by clicking on a new
Xplayer.
END_OF_FILE
if test 23937 -ne `wc -c <'doc'`; then
    echo shar: \"'doc'\" unpacked with wrong size!
fi
# end of 'doc'
fi
if test -f 'redraw.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'redraw.c'\"
else
echo shar: Extracting \"'redraw.c'\" \(25146 characters\)
sed "s/^X//" >'redraw.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)redraw.c	1.1";
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <signal.h>
X#include <math.h>
X#include "defs.h"
X#include "data.h"
X#include "bitmaps.h"
X
X#define WINSIDE 500
X
X/* NOTE: This definition depends on MAXPLAYERS! */
Xstatic char *shipnos = "0123456789abcdef";
X
Xstatic short nplayers;
Xstatic int stlinecount = 1;
X
Xextern unsigned char	newcourse();	/* Down below... */
X
Xintrupt()
X{
X    register int		i;
X    register struct player	*p;
X
X    udcounter++;
X    move();
X    for (i = 0, p = &players[i]; i < MAXPLAYER; i++, p++) {
X#ifdef notdef
X	    auto_features(p);	/* Called in move() */
X	    redraw(p);
X#endif
X    }
X    ++stlinecount;
X}
X
Xredraw(j)
Xregister struct player	*j;
X{
X    /* erase warning line if necessary */
X    if ((j->warntimer <= udcounter) && (j->warncount > 0)) {
X	XClearWindow(j->display, j->warnw);
X	j->warncount = 0;
X    }
X
X    if (j->clearcount) {
X	XFillRectangles(j->display, j->w, j->cleargc,
X		j->clearzone, j->clearcount);
X	j->clearcount = 0;
X    }
X
X/* NOTE: Can this be made into an XDrawLines? */
X    while (j->clearlcount) {
X	j->clearlcount--;
X	XDrawLine(j->display, j->w, j->cleargc,
X	    j->clearline[0][j->clearlcount],
X	    j->clearline[1][j->clearlcount],
X	    j->clearline[2][j->clearlcount],
X	    j->clearline[3][j->clearlcount]);
X    }
X
X    if ((j->mapmode) && (udcounter % ((nplayers == 0) ? 1 : nplayers) == 0))
X	map(j);
X
X    /* Display a new message every MESSTIME/UPS seconds */
X    if ((udcounter % MESSTIME) == 0)
X	dmessage(j);
X
X    local(j);	/* redraw local window */
X
X    if ((stlinecount&02) == 0)
X	stline(j);	/* update every 4 times we update the window */
X
X    if (j->p_flags & PFSHOWSTATS)
X	updateStats(j, j->statwin);
X}
X
XdrawPartialPhaser(p, j)
Xregister struct player *p, *j;
X{
Xint	sx,ex,sy,ey;
Xstruct	phaser *php;
X
X
X    sx= j->p_x - p->p_x;
X    sy= j->p_y - p->p_y;
X    /* Now draw his phaser (if it exists) */
X    php = &phasers[j->p_no];
X    if (php->ph_status == PHMISS) {
X	/* Here I will have to compute end coordinate */
X	phasedist(j, php, &ex, &ey);
X	ex -= p->p_x;
X	ey -= p->p_y;
X    }
X    else {
X	ex = (players[php->ph_target].p_x) - p->p_x;
X	ey = (players[php->ph_target].p_y) - p->p_y;
X    }
X    /* phaser end points are now relative to our position, make them
X     * relative to window origin (so X clips them correctly)
X     */
X    sx= sx/SCALE+WINSIDE/2; sy= sy/SCALE+WINSIDE/2;
X    ex= ex/SCALE+WINSIDE/2; ey= ey/SCALE+WINSIDE/2;
X    if ((sx<0)&&(ex<0))	return;
X    if ((sy<0)&&(ey<0))	return;
X    if ((sx>WINSIDE)&&(ex>WINSIDE))	return;
X    if ((sy>WINSIDE)&&(ey>WINSIDE))	return;
X    XSetForeground(p->display, p->xfgc, phaserColor(php));
X    XDrawLine(p->display, p->w, p->xfgc,
X	    sx, sy, ex, ey);
X/*
X    p->clearline[p->clearlcount].x1 = sx;
X    p->clearline[p->clearlcount].y1 = sy;
X    p->clearline[p->clearlcount].x2 = ex;
X    p->clearline[p->clearlcount].y2 = ey;
X*/
X    p->clearline[0][p->clearlcount] = sx;
X    p->clearline[1][p->clearlcount] = sy;
X    p->clearline[2][p->clearlcount] = ex;
X    p->clearline[3][p->clearlcount] = ey;
X    p->clearlcount++;
X}
X
Xlocal(p)
Xregister struct player *p;
X{
X    register int h, i;
X    register struct player *j;
X    register struct torp *k;
X    register struct planet *l;
X    register struct phaser *php;
X    char glyph;
X    int dx, dy;
X    int view;
X
X    /* Draw Planets */
X    view = SCALE * WINSIDE / 2;
X    for (i = 0, l = &planets[0]; i < MAXPLANETS; i++, l++) {
X	dx = l->pl_x - p->p_x;
X	dy = l->pl_y - p->p_y;
X	if (dx > view || dx < -view || dy > view || dy < -view)
X	    continue;
X	dx = dx / SCALE + WINSIDE / 2;
X	dy = dy / SCALE + WINSIDE / 2;
X	glyph = planetGlyph(l);
X	XSetForeground(p->display, p->xfgc, planetColor(l));
X	XDrawString(p->display, p->w, p->xfgc, dx - (planet_width/2),
X		dy - (planet_height/2), &glyph, 1);
X	if (p->namemode) {
X	    XDrawImageString(p->display, p->w, p->dfgc, dx - (planet_width/2), dy + (planet_height/2 + p->dfont->ascent),
X		l->pl_name, l->pl_namelen);
X	    p->clearzone[p->clearcount].x = dx - (planet_width/2);
X	    p->clearzone[p->clearcount].y = dy + (planet_height/2);
X	    /*NOTE: put this calculation into the player data */
X	    p->clearzone[p->clearcount].width = XTextWidth(p->dfont, l->pl_name, l->pl_namelen);
X	    p->clearzone[p->clearcount].height = fontHeight(p->dfont);
X	    p->clearcount++;
X	}
X	p->clearzone[p->clearcount].x = dx - (planet_width/2);
X	p->clearzone[p->clearcount].y = dy - (planet_height/2);
X	p->clearzone[p->clearcount].width = planet_width;
X	p->clearzone[p->clearcount].height = planet_height;
X	p->clearcount++;
X    }
X
X    /* Draw ships */
X    nplayers = 0;
X    view = SCALE * WINSIDE / 2;
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	int tx, ty;
X	if ((j->p_status != PALIVE) && (j->p_status != PEXPLODE))
X	    continue;
X	if ((j->p_flags & PFCLOAK) && (j != p))
X	    continue;
X	nplayers++;
X	dx = j->p_x - p->p_x;
X	dy = j->p_y - p->p_y;
X	if (dx > view || dx < -view || dy > view || dy < -view) {
X	    if (phasers[j->p_no].ph_status != PHFREE)
X		drawPartialPhaser(p, j);
X	    continue;
X	}
X	XSetForeground(p->display, p->xfgc, playerColor(j));
X	dx = dx / SCALE + WINSIDE / 2;
X	dy = dy / SCALE + WINSIDE / 2;
X	if (j->p_status == PALIVE) {
X	    switch (j->p_team) {
X		case FED: glyph = FED_GLYPHS + rosette(j->p_dir); break;
X		case ROM: glyph = ROM_GLYPHS + rosette(j->p_dir); break;
X		case KLI: glyph = KLI_GLYPHS + rosette(j->p_dir); break;
X		case ORI: glyph = ORI_GLYPHS + rosette(j->p_dir); break;
X	    }
X	    XDrawString(p->display, p->w, p->xfgc, dx - (ship_width/2),
X		dy - (ship_height/2), &glyph, 1);
X	/* NOTE: This DrawImageString doesn't use the right GC */
X	    XDrawImageString(p->display, p->w, p->dfgc, dx + (ship_width/2), dy - (ship_height/2 - p->dfont->ascent),
X		shipnos + j->p_no, 1);
X	       
X/* NOTE: fix to change shield color depending on damage.. */
X	    if (p->showShields && j->p_flags & PFSHIELD) {
X		if (j == p) {
X		    if (j->p_damage > (j->p_ship.s_maxdamage / 2))
X			glyph = RSHIELD_GLYPH;
X		    else if (j->p_shield < (j->p_ship.s_maxshields / 2))
X			glyph = YSHIELD_GLYPH;
X		    else
X			glyph = SHIELD_GLYPH;
X		} else
X		    glyph = SHIELD_GLYPH;
X		XDrawString(p->display, p->w, p->xfgc, dx - (shield_width / 2),
X			dy - (shield_height / 2), &glyph, 1);
X	    }
X
X	    p->clearzone[p->clearcount].x = dx + (ship_width/2);
X	    p->clearzone[p->clearcount].y = dy - (ship_height/2);
X	    /* NOTE: put this calculattion into  player data */
X	    p->clearzone[p->clearcount].width = XTextWidth(p->dfont, shipnos + j->p_no, 1);
X	    p->clearzone[p->clearcount].height = fontHeight(p->dfont);
X	    p->clearcount++;
X	    p->clearzone[p->clearcount].x = dx - (shield_width/2);
X	    p->clearzone[p->clearcount].y = dy - (shield_height/2);
X	    p->clearzone[p->clearcount].width = shield_width;
X	    p->clearzone[p->clearcount].height = shield_height;
X	    p->clearcount++;
X	}
X	else if (j->p_status == PEXPLODE) {
X	    glyph = EXP_GLYPHS_LEFT + (10 - j->p_explode)/2;
X	    XDrawString(p->display, p->w, p->xfgc, dx - (ex_width / 2),
X		dy - (ex_height / 2), &glyph, 1);
X
X	    glyph = EXP_GLYPHS_RIGHT + (10 - j->p_explode)/2;
X	    XDrawString(p->display, p->w, p->xfgc, dx,
X		dy - (ex_height / 2), &glyph, 1);
X
X	    p->clearzone[p->clearcount].x = dx - (ex_width/2);
X	    p->clearzone[p->clearcount].y = dy - (ex_height/2);
X	    p->clearzone[p->clearcount].width = ex_width;
X	    p->clearzone[p->clearcount].height = ex_height;
X	    p->clearcount++;
X	}
X	/* Now draw his phaser (if it exists) */
X	php = &phasers[j->p_no];
X	if (php->ph_status != PHFREE) {
X	    if (php->ph_status == PHMISS) {
X		/* Here I will have to compute end coordinate */
X		phasedist(j, php, &tx, &ty);
X		tx = (tx - p->p_x) / SCALE + WINSIDE / 2;
X		ty = (ty - p->p_y) / SCALE + WINSIDE / 2;
X		XSetForeground(p->display, p->xfgc, phaserColor(php));
X		XDrawLine(p->display, p->w, p->xfgc, dx, dy, tx, ty);
X	    }
X	    else { /* Start point is dx, dy */
X		tx = (players[php->ph_target].p_x - p->p_x) /
X		    SCALE + WINSIDE / 2;
X		ty = (players[php->ph_target].p_y - p->p_y) /
X		    SCALE + WINSIDE / 2;
X		XSetForeground(p->display, p->xfgc, phaserColor(php));
X		XDrawLine(p->display, p->w, p->xfgc, dx, dy, tx, ty);
X	    }
X	    p->clearline[0][p->clearlcount] = dx;
X	    p->clearline[1][p->clearlcount] = dy;
X	    p->clearline[2][p->clearlcount] = tx;
X	    p->clearline[3][p->clearlcount] = ty;
X	    p->clearlcount++;
X	}
X    }
X    /* Draw torps */
X    view = SCALE * WINSIDE / 2;
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	if (!j->p_ntorp)
X	    continue;
X	for (h = 0, k = &torps[MAXTORP * i + h]; h < MAXTORP; h++, k++) {
X	    if (!k->t_status)
X		continue;
X	    dx = k->t_x - p->p_x;
X	    dy = k->t_y - p->p_y;
X	    if (dx > view || dx < -view || dy > view || dy < -view)
X		continue;
X	    XSetForeground(p->display, p->xfgc, torpColor(k));
X	    dx = dx / SCALE + WINSIDE / 2;
X	    dy = dy / SCALE + WINSIDE / 2;
X	    if (k->t_status == TEXPLODE) {
X		glyph = CLOUD_GLYPH;
X		XDrawString(p->display, p->w, p->xfgc, dx - (cloud_width / 2),
X			dy - (cloud_height / 2), &glyph, 1);
X
X		p->clearzone[p->clearcount].x = dx - (cloud_width/2);
X		p->clearzone[p->clearcount].y = dy - (cloud_height/2);
X		p->clearzone[p->clearcount].width = cloud_width;
X		p->clearzone[p->clearcount].height = cloud_height;
X		p->clearcount++;
X	    }
X	    else if (k->t_owner != p->p_no && ((k->t_war & p->p_team) ||
X		      (k->t_team & (p->p_hostile | p->p_swar))))
X	    {
X		glyph = ETORP_GLYPH;
X		XDrawString(p->display, p->w, p->xfgc, dx - (etorp_width / 2),
X			dy - (etorp_height / 2), &glyph, 1);
X
X		p->clearzone[p->clearcount].x = dx - (etorp_width/2);
X		p->clearzone[p->clearcount].y = dy - (etorp_height/2);
X		p->clearzone[p->clearcount].width = etorp_width;
X		p->clearzone[p->clearcount].height = etorp_height;
X		p->clearcount++;
X	    }
X	    else {
X		glyph = MTORP_GLYPH;
X		XDrawString(p->display, p->w, p->xfgc, dx - (mtorp_width / 2),
X			dy - (mtorp_height / 2), &glyph, 1);
X
X		p->clearzone[p->clearcount].x = dx - (mtorp_width/2);
X		p->clearzone[p->clearcount].y = dy - (mtorp_height/2);
X		p->clearzone[p->clearcount].width = mtorp_width;
X		p->clearzone[p->clearcount].height = mtorp_height;
X		p->clearcount++;
X	    }
X	}
X    }
X    /* Draw Edges */
X    XSetForeground(p->display, p->xfgc, p->warningColor);
X    if (p->p_x < (WINSIDE / 2) * SCALE) {
X	int	sy, ey;
X
X	dx = (WINSIDE / 2) - (p->p_x) / SCALE;
X	sy = (WINSIDE / 2) + (0 - p->p_y) / SCALE;
X	ey = (WINSIDE / 2) + (GWIDTH - p->p_y) / SCALE;
X	if (sy < 0) sy = 0;
X	if (ey > WINSIDE - 1) ey = WINSIDE - 1;
X	XDrawLine(p->display, p->w, p->xfgc, dx, sy, dx, ey);
X	p->clearline[0][p->clearlcount] = dx;
X	p->clearline[1][p->clearlcount] = sy;
X	p->clearline[2][p->clearlcount] = dx;
X	p->clearline[3][p->clearlcount] = ey;
X	p->clearlcount++;
X    }
X    if ((GWIDTH - p->p_x) < (WINSIDE / 2) * SCALE) {
X	int	sy, ey;
X
X	dx = (WINSIDE / 2) + (GWIDTH - p->p_x) / SCALE;
X	sy = (WINSIDE / 2) + (0 - p->p_y) / SCALE;
X	ey = (WINSIDE / 2) + (GWIDTH - p->p_y) / SCALE;
X	if (sy < 0) sy = 0;
X	if (ey > WINSIDE - 1) ey = WINSIDE - 1;
X	XDrawLine(p->display, p->w, p->xfgc, dx, sy, dx, ey);
X	p->clearline[0][p->clearlcount] = dx;
X	p->clearline[1][p->clearlcount] = sy;
X	p->clearline[2][p->clearlcount] = dx;
X	p->clearline[3][p->clearlcount] = ey;
X	p->clearlcount++;
X    }
X    if (p->p_y < (WINSIDE / 2) * SCALE) {
X	int	sx, ex;
X
X	dy = (WINSIDE / 2) - (p->p_y) / SCALE;
X	sx = (WINSIDE / 2) + (0 - p->p_x) / SCALE;
X	ex = (WINSIDE / 2) + (GWIDTH - p->p_x) / SCALE;
X	if (sx < 0) sx = 0;
X	if (ex > WINSIDE - 1) ex = WINSIDE - 1;
X	XDrawLine(p->display, p->w, p->xfgc, sx, dy, ex, dy);
X	p->clearline[0][p->clearlcount] = sx;
X	p->clearline[1][p->clearlcount] = dy;
X	p->clearline[2][p->clearlcount] = ex;
X	p->clearline[3][p->clearlcount] = dy;
X	p->clearlcount++;
X    }
X    if ((GWIDTH - p->p_y) < (WINSIDE / 2) * SCALE) {
X	int	sx, ex;
X
X	dy = (WINSIDE / 2) + (GWIDTH - p->p_y) / SCALE;
X	sx = (WINSIDE / 2) + (0 - p->p_x) / SCALE;
X	ex = (WINSIDE / 2) + (GWIDTH - p->p_x) / SCALE;
X	if (sx < 0) sx = 0;
X	if (ex > WINSIDE - 1) ex = WINSIDE - 1;
X	XDrawLine(p->display, p->w, p->xfgc, sx, dy, ex, dy);
X	p->clearline[0][p->clearlcount] = sx;
X	p->clearline[1][p->clearlcount] = dy;
X	p->clearline[2][p->clearlcount] = ex;
X	p->clearline[3][p->clearlcount] = dy;
X	p->clearlcount++;
X    }
X
X    /* Change border color to signify alert status */
X
X    if (p->oldalert != (p->p_flags & (PFGREEN|PFYELLOW|PFRED))) {
X        p->oldalert = (p->p_flags & (PFGREEN|PFYELLOW|PFRED));
X	switch (p->oldalert) {
X	    case PFGREEN:
X	        if (!p->mono) {
X		    XSetWindowBorder(p->display, p->baseWin, p->gColor);
X		    XSetWindowBorder(p->display, p->iconWin, p->gColor);
X	        } else {
X		    XSetWindowBorderPixmap(p->display, p->baseWin, p->gTile);
X		    XSetWindowBorderPixmap(p->display, p->iconWin, p->gTile);
X		}
X		break;
X	    case PFYELLOW:
X	        if (!p->mono) {
X		    XSetWindowBorder(p->display, p->baseWin, p->yColor);
X		    XSetWindowBorder(p->display, p->iconWin, p->yColor);
X	        } else {
X		    XSetWindowBorderPixmap(p->display, p->baseWin, p->yTile);
X		    XSetWindowBorderPixmap(p->display, p->iconWin, p->yTile);
X		}
X		break;
X	    case PFRED:
X	        if (!p->mono) {
X		    XSetWindowBorder(p->display, p->baseWin, p->rColor);
X		    XSetWindowBorder(p->display, p->iconWin, p->rColor);
X	        } else {
X		    XSetWindowBorderPixmap(p->display, p->baseWin, p->rTile);
X		    XSetWindowBorderPixmap(p->display, p->iconWin, p->rTile);
X		}
X		break;
X	}
X    }
X}
X
X/*
X * compute position of the end of the phasor
X * and return in tx and ty.
X */
Xphasedist(j, php, tx, ty)
X    struct player *j;
X    struct phaser *php;
X    int *tx, *ty;
X{
X	*tx = j->p_x + (int) ((j->p_ship.s_phasedist) * Cos[php->ph_dir]);
X	*ty = j->p_y + (int) ((j->p_ship.s_phasedist) * Sin[php->ph_dir]);
X}
X
Xmap(p)
Xregister struct player	*p;
X{
X    register int		i;
X    register struct player	*j;
X    register struct planet	*l;
X    int				dx, dy;
X    char			glyph;
X
X    if (p->mclearcount) {
X	XFillRectangles(p->display, p->mapw, p->cleargc,
X		p->mclearzone, p->mclearcount);
X	p->mclearcount = 0;
X    }
X
X    /* Draw Planets */
X    for (i = 0, l = &planets[0]; i < MAXPLANETS; i++, l++) {
X	if (!(l->pl_flags & PLREDRAW) && (!p->redrawall))
X	    continue;
X	dx = l->pl_x * WINSIDE / GWIDTH;
X	dy = l->pl_y * WINSIDE / GWIDTH;
X
X	glyph = mplanetGlyph(l);
X	XSetForeground(p->display, p->xfgc, planetColor(l));
X	XDrawString(p->display, p->mapw, p->xfgc, dx - (mplanet_width / 2),
X		dy - (mplanet_height / 2), &glyph, 1);
X	XDrawImageString(p->display, p->mapw, p->dfgc, dx - (mplanet_width/2), dy + (mplanet_height/2 + p->dfont->ascent),
X	    l->pl_name, 3);
X
X/*
X		p->mclearzone[p->mclearcount].x = dx - (mplanet_width/2);
X		p->mclearzone[p->mclearcount].y = dy + (mplanet_height/2);
X		NOTE: Put this calculation into player data
X		p->mclearzone[p->mclearcount].width = XTextWidth(p->dfont, l->pl_name, 3);
X		p->mclearzone[p->mclearcount].height = fontHeight(p->dfont);
X		p->mclearcount++;
X		p->mclearzone[p->mclearcount].x = dx - (mplanet_width/2);
X		p->mclearzone[p->mclearcount].y = dy - (mplanet_height/2);
X		p->mclearzone[p->mclearcount].width = mplanet_width;
X		p->mclearzone[p->mclearcount].height = mplanet_height;
X		p->mclearcount++;
X*/
X    }
X    p->redrawall = 0;
X
X    /* Draw ships */
X    nplayers = 0;
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	char	*str;
X
X	if (j->p_status != PALIVE)
X	    continue;
X	nplayers++;
X	dx = j->p_x * WINSIDE / GWIDTH;
X	dy = j->p_y * WINSIDE / GWIDTH;
X	if (!(j->p_flags & PFCLOAK)) {
X		/* NOTE: put these calculations into the player data */
X	    XDrawImageString(p->display, p->mapw, p->dfgc, dx - XTextWidth(p->dfont, j->p_mapchars, 2), dy - fontHeight(p->dfont)/2 + p->dfont->ascent,
X		str = j->p_mapchars, 2);
X	    p->mclearzone[p->mclearcount].x = dx - XTextWidth(p->dfont, j->p_mapchars, 2);
X	    p->mclearzone[p->mclearcount].y = dy - fontHeight(p->dfont)/2;
X	    p->mclearzone[p->mclearcount].width = XTextWidth(p->dfont, str, 2);
X	    p->mclearzone[p->mclearcount].height = fontHeight(p->dfont);
X	    p->mclearcount++;
X	}
X    }
X}
X
Xstline(p)
Xregister struct player	*p;
X{
X    static char buf[80] = "               0    0    0  0    0.00   0        0    0     0";
X
X    /* Instead of one sprintf, we do all this by hand for optimization */
X
X    if (buf[0] == 0) {
X	int i;
X	for (i = 0; i < 63; ++i)
X	    buf[i] = ' ';
X    }
X
X    buf[0] = (p->p_flags & PFSHIELD ? 'S': ' ');
X    if (p->p_flags & PFGREEN)
X	buf[1] = 'G';
X    else if (p->p_flags & PFYELLOW)
X	buf[1] = 'Y';
X    else if (p->p_flags & PFRED)
X	buf[1] = 'R';
X    buf[2] = (p->p_flags & (PFPLLOCK | PFPLOCK) ? 'L': ' ');
X    buf[3] = (p->p_flags & PFREPAIR ? 'R': ' ');
X    buf[4] = (p->p_flags & PFBOMB ? 'B': ' ');
X    buf[5] = (p->p_flags & PFORBIT ? 'O': ' ');
X    buf[6] = (p->p_flags & PFCLOAK ? 'C': ' ');
X    buf[7] = (p->p_flags & PFWEP ? 'W': ' ');
X    buf[8] = (p->p_flags & PFENG ? 'E': ' ');
X    buf[9] = (p->p_flags & PFBEAMUP ? 'u': ' ');
X    buf[10] = (p->p_flags & PFBEAMDOWN ? 'd': ' ');
X    buf[11] = (p->p_flags & PFCOPILOT ? 'P' : ' ');
X    buf[12] = ' ';
X    buf[13] = ' ';
X    buf[14] = '0' + p->p_speed;	/* speed */
X    buf[15] = ' ';
X    buf[16] = ' ';
X    buf[17] = ' ';
X    buf[18] = ' ';
X    buf[19] = '0' + (p->p_damage / 100);
X    if (buf[19] == '0')
X	buf[19] = ' ';
X    buf[20] = '0' + ((p->p_damage % 100) / 10);
X    if ((buf[20] == '0') && (p->p_damage < 100))
X	buf[20] = ' ';
X    buf[21] = '0' + (p->p_damage % 10);
X    buf[22] = ' ';
X    buf[23] = '0' + (p->p_shield / 100);
X    if (buf[23] == '0')
X	buf[23] = ' ';
X    buf[24] = '0' + ((p->p_shield % 100) / 10);
X    if ((buf[24] == '0') && (p->p_shield < 100))
X	buf[24] = ' ';
X    buf[25] = '0' + (p->p_shield % 10);
X    buf[26] = ' ';
X    buf[27] = ' ';
X    buf[28] = '0' + ((p->p_ntorp % 100) / 10);
X    if (buf[28] == '0')
X	buf[28] = ' ';
X    buf[29] = '0' + (p->p_ntorp % 10);
X    buf[30] = ' ';
X    buf[31] = ' ';
X    buf[32] = ' ';
X    buf[33] = '0' + ((int) (p->p_kills / 10));
X    if (buf[33] == '0')
X	buf[33] = ' ';
X    buf[34] = '0' + (((int) p->p_kills) % 10);
X    buf[35] = '.';
X    buf[36] = '0' + (((int) (p->p_kills * 10)) % 10);
X    buf[37] = '0' + (((int) (p->p_kills * 100)) % 10);
X    buf[38] = ' ';
X    buf[39] = ' ';
X    buf[40] = ' ';
X    buf[41] = '0' + ((p->p_armies % 100) / 10);
X    if (buf[41] == '0')
X	buf[41] = ' ';
X    buf[42] = '0' + (p->p_armies % 10);
X    buf[43] = ' ';
X    buf[44] = ' ';
X
X    buf[45] = '0' + (p->p_fuel / 10000);
X    if (buf[45] == '0')
X	buf[45] = ' ';
X    buf[46] = '0' + ((p->p_fuel % 10000) / 1000);
X    if ((buf[46] == '0') && (p->p_fuel < 10000))
X	buf[46] = ' ';
X    buf[47] = '0' + ((p->p_fuel % 1000) / 100);
X    if ((buf[47] == '0') && (p->p_fuel < 1000))
X	buf[47] = ' ';
X    buf[48] = '0' + ((p->p_fuel % 100) / 10);
X    if ((buf[48] == '0') && (p->p_fuel < 100))
X	buf[48] = ' ';
X    buf[49] = '0' + (p->p_fuel % 10);
X    buf[50] = ' ';
X    buf[51] = ' ';
X
X    buf[52] = '0' + ((p->p_wtemp / 10) / 100);
X    if (buf[52] == '0')
X	buf[52] = ' ';
X    buf[53] = '0' + (((p->p_wtemp / 10) % 100) / 10);
X    if ((buf[53] == '0') && (p->p_wtemp < 1000))
X	buf[53] = ' ';
X    buf[54] = '0' + ((p->p_wtemp / 10) % 10);
X
X    buf[55] = ' ';
X    buf[56] = ' ';
X    buf[57] = ' ';
X
X    buf[58] = '0' + ((p->p_etemp / 10) / 100);
X    if (buf[58] == '0')
X	buf[58] = ' ';
X    buf[59] = '0' + (((p->p_etemp / 10) % 100) / 10);
X    if ((buf[59] == '0') && (p->p_etemp < 1000))
X	buf[59] = ' ';
X    buf[60] = '0' + ((p->p_etemp / 10) % 10);
X    buf[61] = '\0';
X
X    /* Draw status line */
X    if (!p->ts_offset)
X	redrawTstats(p);
X    XDrawImageString(p->display, p->tstatw, p->dfgc, p->ts_offset, 20 + p->dfont->ascent, buf, 61);
X
X#ifdef notdef
X
X    /* This code is being left around because it is much more elegant
X    ** than that above.  However, it lacks a tremendous amount in efficiency.
X    */
X    char alertchar = '?';
X
X    if (me->p_flags & PFGREEN)
X	alertchar = 'G';
X    else if (me->p_flags & PFYELLOW)
X	alertchar = 'Y';
X    else if (me->p_flags & PFRED)
X	alertchar = 'R';
X    /* Draw status line */
X    sprintf(buf,
X"%c%c%c%c%c%c%c%c%c%c%c%c   %1d  %3d %3d  %2d    %5.2f  %2d    %5d   %3d   %3d",
X	(me->p_flags & PFSHIELD ? 'S': ' '),
X	alertchar,
X	(me->p_flags & (PFPLLOCK | PFPLOCK) ? 'L': ' '),
X	(me->p_flags & PFREPAIR ? 'R': ' '),
X	(me->p_flags & PFBOMB ? 'B': ' '),
X	(me->p_flags & PFORBIT ? 'O': ' '),
X	(me->p_flags & PFCLOAK ? 'C': ' '),
X	(me->p_flags & PFWEP ? 'W': ' '),
X	(me->p_flags & PFENG ? 'E': ' '),
X	(me->p_flags & PFBEAMUP ? 'u': ' '),
X	(me->p_flags & PFBEAMDOWN ? 'd': ' '),
X	(me->p_flags & PFCOPILOT ? 'P' : ' '),
X	me->p_speed,
X	me->p_damage,
X	me->p_shield,
X	me->p_ntorp,
X	me->p_kills,
X	me->p_armies,
X	me->p_fuel,
X	me->p_wtemp/10,
X	me->p_etemp/10);
X    XDrawImageString(display, tstatw, dfgc, 50, 20, buf, strlen(buf));
X    XFlush();
X
X#endif notdef
X}
X
X/* These are routines that need to be done on interrupts but
X   don't belong in the redraw routine and particularly don't
X   belong in the daemon. */
X
Xauto_features(p)
Xregister struct player	*p;
X{
X    register int		i;
X    char buf[80];
X    struct player *pl;
X    struct planet *pln;
X
X#ifdef notdef
X	/* NOTE: this will be handled elsewhere */
X    if (p->copilot && (!(me->p_flags & PFCOPILOT))) {
X	printf("Owning player has kicked you out\n");
X	exit(0);
X    }
X#endif
X    if (p->p_flags & PFSELFDEST) {
X#ifdef notdef
X	if ((p->p_updates >= p->selfdest) ||
X	    ((p->p_flags & PFGREEN) && (p->p_damage == 0)
X		&& (p->p_shield == 100))) {
X#endif
X	if (p->p_updates >= p->selfdest) {
X	    p->p_flags &= ~PFSELFDEST;
X	    p->p_explode = 10;
X	    p->p_whydead = KQUIT;
X	    p->p_status = PEXPLODE;
X	}
X	else {
X	    sprintf(buf, "Self Destruct in %d seconds",
X		(p->selfdest - p->p_updates) / UPS);
X	    warning(p, buf);
X	}
X    }
X    /* give certain information about bombing or beaming */
X    if (p->p_flags & PFBOMB) {
X	if (planets[p->p_planet].pl_armies < 5) {
X	    sprintf(buf, "Cannot bomb %s while armies are less than 5",
X		planets[p->p_planet].pl_name);
X	    warning(p, buf);
X	    p->p_flags &= ~PFBOMB;
X	}
X	else {
X	    sprintf(buf, "Bombing %s.  %d armies left",
X		planets[p->p_planet].pl_name,
X		planets[p->p_planet].pl_armies);
X	    warning(p, buf);
X	}
X    }
X
X    if (p->p_flags & PFBEAMUP) {
X	if (planets[p->p_planet].pl_armies < 5) {
X	    sprintf(buf, "%s: Too few armies to beam up",
X		planets[p->p_planet].pl_name);
X	    warning(p, buf);
X	    p->p_flags &= ~PFBEAMUP;
X	}
X	else if ((p->p_armies == (int) (p->p_kills * 2)) ||
X	    (p->p_armies == p->p_ship.s_maxarmies)) {
X		sprintf(buf, "No more room on board for armies");
X	    warning(p, buf);
X	    p->p_flags &= ~PFBEAMUP;
X	}
X	else {
X	    sprintf(buf, "Beaming up.  (%d/%d)", p->p_armies,
X		((p->p_kills * 2) > p->p_ship.s_maxarmies) ?
X		    p->p_ship.s_maxarmies : (int) (p->p_kills * 2));
X	    warning(p, buf);
X	}
X    }
X    if (p->p_flags & PFBEAMDOWN) {
X	if (p->p_armies == 0) {
X	    sprintf(buf, "No more armies to beam down to %s.",
X		planets[p->p_planet].pl_name);
X	    warning(p, buf);
X	    p->p_flags &= ~PFBEAMDOWN;
X	}
X	else {
X	    sprintf(buf, "Beaming down.  (%d/%d) %s has %d armies left",
X		p->p_armies,
X		((p->p_kills * 2) > p->p_ship.s_maxarmies) ?
X		    p->p_ship.s_maxarmies : (int) (p->p_kills * 2),
X		planets[p->p_planet].pl_name,
X		planets[p->p_planet].pl_armies);
X	    warning(p, buf);
X	}
X    }
X    if (p->p_flags & PFREPAIR) {
X	if ((p->p_damage == 0) && (p->p_shield == 100))
X		p->p_flags &= ~PFREPAIR;
X    }
X    if (p->p_flags & PFPLOCK) { 	/* set course to player x */
X	pl = &players[p->p_playerl];
X	if (pl->p_status != PALIVE)
X	    p->p_flags &= ~PFPLOCK;
X	set_course(p, newcourse(p, pl->p_x, pl->p_y));
X    }
X    if (p->p_flags & PFPLLOCK) { 	/* set course to planet x */
X	int dist;
X	pln = &planets[p->p_planet];
X	dist = hypot((double) (p->p_x - pln->pl_x),
X	    (double) (p->p_y - pln->pl_y));
X
X	/* This is magic.  It should be based on defines, but it slows
X	   the ship down to warp two an appropriate distance from the
X	   planet for orbit */
X
X	if (dist < (50 * ((p->p_speed * (p->p_speed+1)) + 10)))
X	    set_speed(p, ORBSPEED);
X	if ((dist < ORBDIST) && (p->p_speed <= ORBSPEED))  {
X	    p->p_flags &= ~PFPLLOCK;
X	    orbit(p);
X	}
X	else {
X	    set_course(p, newcourse(p, pln->pl_x, pln->pl_y));
X	}
X    }
X}
X
Xunsigned char
Xnewcourse(p, x, y)
Xregister struct player	*p;
Xregister int		x, y;
X{
X	return((unsigned char) (atan2((double) (x - p->p_x),
X	    (double) (p->p_y - y)) / 3.14159 * 128.));
X}
X
XredrawTstats(p)
Xregister struct player	*p;
X{
X    char	buf[BUFSIZ];
X
X    sprintf(buf, 
X	"Flags        warp  dam shd torps kills armies fuel wtemp etemp");
X    if (!p->ts_offset)
X	p->ts_offset = (WINSIDE - XTextWidth(p->dfont, buf, strlen(buf))) / 2;
X    XDrawImageString(p->display, p->tstatw, p->dfgc, p->ts_offset, 10 + p->dfont->ascent, buf, strlen(buf));
X}
END_OF_FILE
if test 25146 -ne `wc -c <'redraw.c'`; then
    echo shar: \"'redraw.c'\" unpacked with wrong size!
fi
# end of 'redraw.c'
fi
echo shar: End of archive 3 \(of 7\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x



More information about the Comp.sources.x mailing list