game/ 40775 767 767 0 7141217223 7576 5 ustar mux mux game/space/ 40775 767 767 0 7141217223 10671 5 ustar mux mux game/space/hspace.cnf 100664 767 767 34155 7141162735 12760 0 ustar mux mux # Configuration file for Hemlock Space (HSPACE). # Change any options as you feel necessary, but be sure you are aware of # the effects the change will have. # # Please note that many of these configuration options are not currently # implemented. They come from version 3.x of HSpace and will probably # be used once again in the future. In any case, set the options you # want to change in case they are currently used (most are). # Set this to 1 if you want all space commands to be logged to # the log file. LOG_COMMANDS=0 # The name of the unit of distance in your game. This is the abbreviation # of the unit (e.g. km). UNIT_NAME=hm # By setting this variable to 1, HSpace will age and decay ships for # you by a predefined aging algorithm. Attributes of wear and tear # for each ship component are stored on the navigation console. If # you won't be using any sort of ship component repair system, it is # recommended that you keep this turned off by leaving it set to 0. DECAY_SHIPS=0 # Set this to 1 if you want fuel systems to present both reactable and # burnable fuels for ship reactors, engines, etc. If this is set to 0, # then only one fuel source (burnable) is presented and used by systems. USE_TWO_FUELS=1 # This is the fuel ratio, which you can change to increase or decrease # fuel used by a ship's reactor. The number here is the number of # units of power a reactor can produce per unit of fuel per hour. For # example, a value of 50 indicates a ratio of 1:50. That is, 1 unit of # fuel is used by the reactor each hour for each 50 units of power it # currently outputs. If you've specified that the fuel system should # model two fuels, this fuel is deducted from reactable fuels and not # burnable. FUEL_RATIO=200 # Set this to the sublight to hyperspace speed ratio for when jump # drives are engaged. For example, if you're traveling at 100 units/hour, # and this value is set to 500, then you'll travel 50,000 units/hour in # hyperspace. JUMP_SPEED_MULTIPLIER=20 # Set this to 2 if you want vessels in hyperspace to identified fully # on other vessels' sensors. # Set it to 1 if you want vessels in hyperspace to only be detected. # Set it to 0 if you don't want vessels in hyperspace to be seen # at all on other vessels' sensors. # These settings work vice versa for vessels in hyperspace detecting # objects not in hyperspace. SENSE_HYPERVESSELS=1 # Set this to the maximum distance you want any ship sensors to see. # This is useful for filtering out big objects (like stars) that # would normally appear on sensors from far, far away. MAX_SENSOR_RANGE=5000 # Afterburning allows ships to increase their speed by some factor # while still at sublight speeds. In real life it is accomplished # by dumping fuel into the engines, essentially turning the engines into # big rockets. Engines in HSpace can be capable of afterburning. Set # this value to the increase in speed you want engines to experience # when afterburning. This value is multiplied by the maximum capable # speed of the engines to determine afterburn speed. If the engines # aren't capable of afterburning, this value is ignored. AFTERBURN_RATIO=2 # Set this to the ratio of fuel consumption increase that you # want engines to experience while afterburning. If you set it # to a value of 1, engines just consume fuel during afterburn # like they do during non-afterburn. Anything greater than 1 # multiplies fuel consumption during afterburn. AFTERBURN_FUEL_RATIO=7 # The minimum flight training is a handy way of restricting brand newbies # from hopping in a space ship when they have no business being in real # space. This is not the number of minutes, hours, or days that a player # must spend in a simulator before being able to "man" the navigation of # a real ship. Rather, it is an arbitary level to which a player must # attain by using various space commands in a simulator. Each command is # worth a very small number of points. As the players use various commands # in a simulator, they gain more points until this number is reached. If # you do not wish to restrict players to gaining simulator time, set this # to 0. MIN_TRAINING=10 # If you are using commlinks in your game and the HSPACE_COMM # flag, set this option value to 1. If you do not intend to use # commlinks, then set it to 0. Enabling this option does consume # extra processing time when messages are broadcast through space, # so you don't want to enable it unless you're going to use it. USE_COMM_OBJECTS=1 # Some games allow puppets to fly ships. Others do not. If you # prefer to restrict use of any ship consoles to only players, set # this variable to 1. FORBID_PUPPETS=0 # When one ship scans another, HSpace can notify the target ship that # they are being scanned. If you would like this, change this option # to a value of 1. Otherwise, set it to 0 for no notification. NOTIFY_SHIPSCAN=1 # The following variables can be modified to change how # cloaking operates in your game. # # CLOAK_STYLE can be set to 0 or 1, indicating either that # cloaking is disabled or enabled in the game. CLOAK_STYLE=1 # CLOAK_LOW_SIZE indicates to HSpace the lowest size ship in the game # that can cloak. CLOAK_LOW_SIZE=0 # CLOAK_OPT_SIZE indicates to HSpace the optimal ship size that cloaking # operates on in the game. That is, what size of ship most effectively # cloaks. CLOAK_OPT_SIZE=8 # Set this to 1 if you want ships to be able to pick up sensor contacts # while cloaked. Otherwise, set this to 0. SEE_WHILE_CLOAKED=1 # Set this to 1 if you want to allow firing weapons while cloaked. Else, # set it to 0 to disallow this feature. FIRE_WHILE_CLOAKED=0 # This is the amount of time that must pass before a sim user's simtime # may increase. Essentially, it sets training increase per time and # prevents sim users from looping a lot of commands to increae their # sim training. If you're not partaking of sim training and such, this # can be ignored or set to 0. TRAIN_INTERVAL=5 # Set this to 0 if you do not want to allow pilots to strafe fuel # from nearby planets. This is typically disabled if you want to # use your own ship refueling scenario. Leave it set to 1 if you # want to use the HSpace strafing ability. ALLOW_STRAFING=0 # Set this to the total number of seconds you want to have between # the time a ship begins drop-to-planet procedures and the time they # touch the ground. SECONDS_TO_DROP=30 # Set this as the maximum distance a vessel can be away from its target # vessel and still be able to dock in that target vessel. This is measured # in whole hetrameres. MAX_DOCK_DIST=5 # Set this to the maximum speed you wish vessels to be traveling when # they attempt to land on a planet. Thus, if they're going too fast # they cannot begin to land. MAX_LAND_SPEED=2000 # Set this as the maximum distance a vessel can be away from a target # planet and still commence landing procedures. MAX_DROP_DIST=20 # Set this to the maximum distance two vessels can be from each other # and still aqcuire a boarding link. MAX_BOARD_DIST=5 # This is the maximum distance a vessel may be from a planet to strafe # fuel from its atmosphere. This has no effect if ALLOW_STRAFING is # set to 0. MAX_STRAFE_DIST=500 # Set this to the maximum distance two ships may be apart from each other # and still transfer cargo between the ships. MAX_CARGO_DIST=2 # Set this to the maximum size ship that can dock in another ship. This # exists for realism. How realistic is it for a battleship to dock in a # destroyer? The size is on a scale from 1 - 10 and is recorded for each # ship in the ship classes database. Size 4 is approximately a corvette, # which is considered to be about the upper range of dockable vessels. MAX_DOCK_SIZE=4 # This is probably set fine, but you may want to change it if you are on # a machine with low CPU availability. This setting is measured in # seconds and is the time between each cycle of the space system. The # higher this number, the "slower" the space system is. Ships change # coordinates only once per cycle, sensors are sweeped once per cycle, etc. CYCLE_INTERVAL=1 # By default, HSpace allows 15 universes to exist in the game. Increase # or decrease as you desire, but do not decrease it below the number of # universe you already have in the game. Otherwise, bad things are # going to befall you. MAX_UNIVERSES=15 # When your universes become too full of ships, you will probably want # to increase this variable. Try to keep it lower to avoid unnecessarily # eating up system memory. You must reboot your game after changing this # number. If you modify this number while the game is running, do NOT # reload the configuration file. Shutdown and reboot. MAX_SHIPS=500 # Active ships are those that are undocked and should be checked for # things like traveling and other active-ship sorts of status checks. # By decreasing this, you can speed your game up slightly. You may # need to increase it if you have a lot of people traveling around in # the universes. This will typically be just a fraction of MAX_SHIPS, # because it's unusual to have every ship in the universe out running # around. If you modify this number while the game is running, do NOT # reload the configuration file. Shutdown and reboot. MAX_ACTIVE_SHIPS=50 # Specify the maximum number of planets you want to allow per universe # here. Like MAX_SHIPS, try to keep this number lower to avoid eating # up system memory. If you run out of room in your universes, increase # this number and reboot your game. If you modify this number while the # game is running, do NOT reload the configuration file. Shutdown and # reboot. MAX_PLANETS=50 # If you want the space system to start cycling immediately upon reboot, # set this to 1. Else, set this to 0. AUTOSTART=1 # The AFTERWORLD. Set this to the dbref number of the room where players # go when they die in space. You will most definitely need to change this. AFTERWORLD=71 # Set this to the dbref number of your space administrator. The player # who this dbref refers to must be set with the WIZARD flag unless the # player is god (dbref 1). SPACE_WIZ=1 # The following are various messages that can be changed. # This message is given to a console operator when an illegal action is # attempted while the ship is in hyperspace. SHIP_IS_JUMPING=Ship is currently traveling in hyperspace. # This is the message shown to players inside the ship when the ship # goes into jump mode. SHIP_JUMPS=The ship hums loudly as it enters into hyperspace. # This message is shown to players inside the ship when it drops out # of hyperspace. END_JUMP=The ship reverberates as it drops out of hyperspace. # This is the message shown to players in the ship rooms when # the afterburners are engaged. AFTERBURN_ENGAGE=The ship shudders as the afterburners are engaged. # This is the message shown to players in the ship rooms when # the afterburners are disengaged. AFTERBURN_DISENGAGE=The ship shakes as the afterburners are disengaged. # This is the message shown to players inside the ship when the ship # lifts off from the ground. LIFT_OFF=The ship sways and bumps as it lifts from the surface of the ground. # This message is shown to players inside the ship when it lands on # a celestial surface. LANDING_MSG=The ship sways and bumps as it makes contact with the ground surface. # This is the message shown to players inside the ship when the ship # begins the drop toward a planet. BEGIN_DESCENT=The ship shudders as the drop rockets engage and the ship begins its descent. # This message is shown to players in the ship when power to life # support is cut. LIFE_CUT=The air suddenly becomes stale as life support loses power. # This message is shown to players in the ship when power to the # jump drives is cut. JUMPERS_CUT=You hear a large powerdrop as the jump drives power down. # This message is shown to players in the ship when power to the # engines is cut. ENGINES_CUT=The incessant hum from the ship's engines suddenly fades away. # This is the message that everyone sees when the ship's engines # activate. ENGINES_ACTIVATING=You feel a sudden rumble as the engines activate. # This message is shown to players in the ship when the ship speeds # up. SPEED_INCREASE=You feel a sudden jerk as the ship speeds up. # This message is shown to players in the ship when the ship's speed # decreases. SPEED_DECREASE=You feel the ship begin to slow. # This message is shown to players in the ship when the ship's # engines switch from forward to reverse momentum. ENGINE_REVERSE=You feel a sudden and powerful force as the reverse thrusters engage. # This message is shown to players in the ship when the ship's engines # switch from reverse to forward momentum. ENGINE_FORWARD=You feel a sudden and powerful force as the main engines engage. # This is the message that players inside the ship receive when the # ship stops. SPEED_HALT=You feel a slight force as the ship glides to a halt ... # Console operators receive this message when a movement action is # attempted while the engines are offline. ENGINES_OFFLINE=Engines are currently offline. # Console operators receive this message when an action is attempted # while the main power system is offline on the ship. REACTOR_OFFLINE=Main reactor is currently offline. # Console operators receive this message when an illegal action is # attempted while the ship is docking. SHIP_IS_DOCKING=The ship is currently in docking procedures ... # Console operators receive this message when an illegal action is # attempted while the ship is undocking. SHIP_IS_UNDOCKING=The ship is currently undocking ... # Console operators receive this message when an illegal action is # attempted while the ship is docked. SHIP_IS_DOCKED=Ship is currently docked. # The following configurations probably shouldn't be changed unless you # are sure of what you're doing. OBJECTDB=space/objectdb CLASSDB=space/classdb WEAPONDB=space/weapondb UNIVDB=space/univdb PICTURE_DIR=space/pics TERRITORYDB=space/territorydb game/space/weapondb 100664 767 767 6 7141202736 12427 0 ustar mux mux *END* game/space/objectdb 100664 767 767 24 7141175606 12431 0 ustar mux mux DBVERSION=4.0 *END* game/space/territorydb 100664 767 767 0 7141175606 13200 0 ustar mux mux game/space/univdb 100664 767 767 24 7141202732 12133 0 ustar mux mux DBVERSION=4.0 *END* game/space/classdb 100664 767 767 24 7141202715 12260 0 ustar mux mux DBVERSION=4.0 *END* game/text/ 40775 767 767 0 7141220517 10562 5 ustar mux mux game/text/help.txt 100664 767 767 1435215 7141213643 12445 0 ustar mux mux & help This is the MUX online help facility. Notes on help descriptions: [text] - Text enclosed in []'s is optional. The []'s are never typed in as part of the command. <parameter> - Information parameter for a command. The <>'s are never typed in as part of the command. - Syntax of help command: help [<command>] - To get a list of MUX topics: help topics - To get a list of Comsystem commands: help comsys - To get a list of MUX Commands: help commands (or @list commands) - For information about HSpace: help hspace Some of the configuration shown in the help.txt might not be the same as the configuration of this MUX. If you notice any errors, contact an Admin. & commands Help available for MUX Commands: Note: Some commands are @-related. drop enter examine get give goto help inventory kill leave LOGOUT look move news OUTPUTPREFIX OUTPUTSUFFIX page pose QUIT read say score SESSION take think throw use version whisper WHO " : ; & # \\ @@ @cemit @chown @chzone @clone @cpattr @create @decompile @destroy @dig @doing @dolist @drain @edit @emit @entrances @femit @find @force @fpose @fsay @halt @last @link @list @listmotd @lock @mail @mvattr @name @notify @npemit @oemit @open @parent @password @pemit @power @program @ps @quitprogram @quota @remit @robot @search @set @stats @sweep @switch @teleport @trigger @unlink @unlock @verb @wait @wipe { 'help commands2' for more } & commands2 Help available for MUX Commands (continued): @aahear @aclone @aconnect @adescribe @adfail @adisconnect @adrop @aefail @aenter @afail @agfail @ahear @akill @aleave @alfail @alias @amail @amhear @amove @apay @arfail @asuccess @atfail @atofail @atport @aufail @ause @away @charges @cost @daily @describe @dfail @drop @ealias @efail @enter @fail @filter @forwardlist @gfail @idesc @idle @idletimeout @infilter @inprefix @kill @lalias @leave @lfail @listen @mailsucc @move @odescribe @odfail @odrop @oefail @oenter @ofail @ogfail @okill @oleave @olfail @omove @opay @orfail @osuccess @otfail @otofail @otport @oufail @ouse @oxenter @oxleave @oxtport @pay @prefix @reject @rfail @runout @sex @signature @startup @success @tfail @tofail @tport @ufail @use & topics Help available on the following Topics: ARBITRARY COMMANDS ATTRIBUTE OWNERSHIP BEING KILLED BOGUS COMMANDS BOOLEAN VALUES COMMAND EVALUATION COMSYS CONTROL COSTS CREDITS DROP-TO ENACTOR EXITS FAILURE FLAG LIST FLAGS FUNCTION LIST FUNCTIONS GENDER GOALS HERE HOMES LINKING LISTENING LISTS LOOPING ME MONEY MOVING OBJECT STACK OBJECT TYPES PARENT OBJECTS PARENT ROOMS PIPING POWERS LIST PUEBLO PUPPETS REGEXPS ROBBERY SEARCH CLASSES SEMAPHORES SPOOFING STACK SUBSTITUTIONS SUCCESS SWITCHES VERBS WIZARDS ZONE OBJECTS & PIPING Command piping in MUX is similar to piping in a UNIX shell. You string two or more commands together using the ;| symbol, much as you would using a semicolon. The output from the previous command in a pipe is accessable using the %| substitution. This output contains the raw ASCII codes that would normally be directly output to your terminal. You may use the translate() function to either convert the raw characters in the output to MUX substitutions, or strip them out altogether. Like the semicolon, the ;| symbol in MUX is taken literally if you type it on the terminal. Currently you may only pipe 20 commands in a row. Examples: > &MAILDESC me=$+maildesc *=*:look %0 ;| @mail/quick %1/Description=[translate(%|,1)] > &SAYDESC me=$+saydesc *:look %0 ;| say %r%| > +saydesc me You say " Lauren(#5PXMWc) You see nothing special. " See also: translate(). & PUEBLO Details on Pueblo support in TinyMUX: @VRML_URL is the URL of a VRML scene for a particular room. @HTDesc is an alternate description for players who are logged in using Pueblo. @pemit/html and @emit/html allow outputting unescaped HTML strings. Please see http://www.chaco.com/pueblo/doc/enhancing.html for more details. & ZONE OBJECTS ZONE OBJECTS Zones are areas of the MUX which may be controlled by many people. Essentially, they allow group ownership of objects. The default zone is NOTHING. Any building done by a player defaults to belonging to the same zone that the player belongs to. Every zone is defined by a Zone Master Object (ZMO). The ZMO is an ordinary MUX object owned by some player. A wizard may change the zone of an object or player to a ZMO. If the ZMO is a room, it is called a "Parent room." Most of the statements about ZMOs also apply to parent rooms; for details, see the help topic PARENT ROOMS. See ZONES2. & ZONES2 Anyone who can pass the Enter lock of the ZMO has control over all objects in that zone. This, in essence, gives that player wizard powers within that zone. For this reason, one must be extremely careful with the enter locks of ZMOs! Also, $commands on a ZMO are treated as global within that zone. The game attempts to match $commands for the ZMO of the player's location, as well as $commands for the player's own zone. For some suggestions on how to use zones, see "help ZONES3". & ZONES3 Some suggested uses of zones: 1. If you are working on a building project with several people, it may be useful to create a zone object and @elock it to all of you, and ask a wizard to @chzone the players involved to the zone object. That way, all of the players working on the project will be able to modify the building. 2. On a similar thread, if several players are working on a project involving only a few objects, it may be simpler to create a zone object and @chzone those few objects to the ZMO instead of resetting the zones of the players. Note that a player does not have to belong to a zone in order to change objects in that zone; all is merely required to pass the ZMO's enter lock. See ZONES4. & ZONES4 More possible uses for zones: 3. If local wizards are desired, a zone object may be created and enter locked to the local wizard. Players building within that zone should be @chzone'd to that ZMO. The local wizard will then be able to control anything within that domain. 4. If you want restricted global commands defined over only a small area, you can define that area to be part of a zone, and place the desired $commands upon the ZMO. & parent rooms Parent rooms are a subset of zones. If a room is used as as zone object, it is a parent room (PR). PRs are like local "master" rooms. Exits in the PR are global to that zone, and $commands on objects in the PR are global to that zone. Parent rooms are only defined if globals are used. Parent rooms should only be used for very large zones which have a lot of global exits. Otherwise, a ZMO thing should be used, because command evaluation on a parent room is slower than command evaluation on a ZMO. Large numbers of parent rooms may slow down the game significantly. See ZONE OBJECTS and COMMAND EVALUATION for more information. & comsys This is the help for the MUX comsystem. Note that the channel names and aliases are case-sensitive. Upon creation, new players automatically join the "Public" channel, while guest characters join channel "Guests" when they connect. Note: <alias> is the alias you choose for the channel. The "Public" channel for new players is aliased to "pub". The "Guests" channel for guests is aliases to "g". Aliases are the most common way to manipulate channels, and may be used in 2 different ways: <alias> <who|on|off> <alias> <message> { 'help comsys2' for more } & comsys2 For example: > pub off [Public] Foobar has left this channel. > pub on You have joined channel Public. [Public] Foobar has joined this channel. > pub who -- Players -- Foobar(#23PWc) Wizard(#1PWc) -- Objects -- -- Public -- > pub Hello world! [Public] Foobar says, "Hello world!" { 'help comsys commands' for more } & comsys commands These are the topics for the MUX comsystem: addcom allcom alias comlist comtitle clearcom delcom @ccreate @cboot @ccharge @cchown @cdestroy @clist @coflags @cpflags @cset @cwho & @cboot Command: @cboot <channel>=<object> Only wizards, or the owner of the channel can use this command. It forcefully removes an object from that channel. Note: You may specify a player name as <object> if you prefix it with an '*'. Otherwise, <object> should be a dbref, or a name of an object if you are nearby it. & addcom Command: addcom <alias>=<channel> This command joins you to an existing channel with <alias>. You should avoid having multiple aliases for a channel, although it is allowed. See also: delcom, comlist, alias, comtitle. & alias Command: <channel alias> <on|off|who|message|:pose|;pose> 'on' allows you to turn an alias on. 'off' lets you temporarily leave that channel. 'who' shows you who is on that channel. You may send a message over the channel with <alias> <text>, where <text> is the message to be sent, or you can pose on a channel with <alias> :<text> or <alias> ;<text> See also: allcom, comlist, addcom, delcom. & allcom Command: allcom <on|off|who> This works like using a single alias, except it does an action for every alias you have. You can turn every alias on, or off, or see who is on every channel you subscribe to. See also: alias, comtitle, delcom, addcom. & comlist Command: comlist Displays a list of all the aliases you are using, whether you are 'on' or 'off' the channel, and some information about them, such as your channel title and status. See also: comtitle, addcom, alias, delcom. & comtitle Command: comtitle <alias>=<title> This command allows you to prefix your name on a channel with a title. For example: > comtitle pub=The Great and Powerful Title set to 'The Great and Powerful' on channel Public. > pub :waves to everyone. [Public] The Great and Powerful Foobar waves to everyone. See also: comlist, addcom, alias, delcom. & clearcom Command: clearcom Removes all your aliases for channels. You should be extremely careful about this command, as it will wipe out all of your channel information. See also: addcom, delcom. & delcom Command: delcom <alias> Deletes <alias> from your list of channel aliases. If <alias> was the only alias you had for a certain channel, you may no longer use that channel until you add a new alias for it. See also: addcom, comlist, clearcom. & @ccreate Command: @ccreate <channel name> Creates a channel with default settings. Only wizards can create a channel. See also: @cdestroy, @clist, @cchown. & @cdestroy Command: @cdestroy <channel> Deletes <channel> permanently from the comsystem database. It does not destroy all aliases that exist for <channel>, which is left to the owners of those aliases. Players are notified at login when they own aliases for which a channel no longer exists. See also: @clist, @ccreate, @cchown. & @clist Command: @clist[/full] Without any switches, it will display the list of public channels with their owner, and description. It will also display all channels you own. With the /full switch, it will display the various channel statistics. See also: @ccreate, @cdestroy, @cchown. & @cwho Command: @cwho <channel>[/all] For channels that you own, identifies all connected players on the channel and their stats for the channel. If switch is /all, then it also displays unconnected players. See also: @clist. & @cchown Command: @cchown <channel>=<player> Changes ownership of <channel> to <player>. See also: @clist, @cwho. & @ccharge Command: @ccharge <channel>=<amount> This command imposes a charge of <amount> coins on transmitting over a channel. The default fee when a channel is created is 0. All proceeds benefit the channel owner. & @cpflags Command: @cpflags <channel>=[!]flag Sets player flags for that channel. The flag can be one of: join, transmit, or receive. Transmit: Whether a player can broadcast things over the channel. Join: Whether a player can join the channel. Receive: Whether a player can receive messages over the channel. If it is !flag, then that flag is reset. Note that channel flags ALWAYS override locks on channel objects. See also: @coflags, @clist, CHANNEL OBJECT. & @coflags Command: @coflags <channel>=[!]flag Sets object flags for that channel. The flag can be one of: join, transmit, or receive. Transmit: Whether an object can broadcast things over the channel. Join: Whether an object can join the channel. Receive: Whether a object can receive messages over the channel. If it is !flag, then that flag is reset. Note that channel flags ALWAYS override locks on channel objects. See also: @coflags, @clist, CHANNEL OBJECT. & @cset Command: @cset/<option> <channel> Changes the way a channel behaves. <option> can be one of the following: public, private, loud, mute, quiet, object, spoof, anon or nospoof. Public makes it show up on everyone's @clist, private hides it. Loud makes it announce connects/disconnects. Mute/quiet, shuts them off. Spoof/anon allows the comtitle to replace the player's name. Nospoof makes it prepend the comtitle to the player's name. The object switch sets the channel object to whatever you specify. It will allow you to set a description for the @clist, by @descing the object. Also, the lock will be used to check to see if people should be able to join the channel or not. See help channel object for more. & channel object In the comsystem, you may specify a channel object for each channel. (@cset/object channel=<object>). Channel objects allow you to specify a description for a channel, and place certain restrictions on joining, transmitting, and receiving. NOTE: If a channel flag is set by @cpflags/@coflags, it will ALWAYS override the equivalent lock. The flags are set by default, so you will have to clear them before your locks work. The join lock for a channel is a normal @lock on the channel object. The transmit lock for a channel is a use @lock on the channel object. The receive lock for a channel is an enter @lock on the channel object. The description of a channel is the @desc of the channel object. & cwho() Function: cwho(<channel>) Returns a list of dbrefs who are connected, and on that channel. This is limited to wizards and channel owners. & @malias Command: @malias This allows you to generate and maintain mailing lists with the mail system. All mail aliases start with '*', and are case-sensitive. (*dir is different than *Dir). There are two kinds of mail aliases, Personnal and Global. Global mailing lists are owned and maintained by the god (#1) char and are available for anyone to use. Generally there will be *Wizards, *Admin, *Roleplay, and things of that nature. Personal mailing aliases are mailing lists that you have defined with the @malias commad. Currently there is no limit to the number of people you can have on a mailing alias. To begin sending mail to a mailing list, use @mail *<alias>=subject. Usage: @malias Displays a list of all mail aliases. @malias *<alias> Displays a list of people on that alias. @malias *<alias>=<list> Creates that mailing list, using <list>. For more help, see the following help topics. All errors can be sent to *Bugs, or Lauren. { 'help @malias2' for more } & @malias2 You can add, remove, rename, chown, redescribe, and delete mailing lists with a switch. @malias/remove *<alias>=<player> Removes <player> from *<alias>. @malias/desc *<alias>=<description> Changes the description for *<alias>. @malias/add *<alias>=<player> Adds <player> to *<alias>. @malias/rename *<alias>=<name> Renames that alias. Names must always begin with '*'. @malias/delete *<alias> Deletes <alias>. @malias/chown *<alias>=<player> Changes the owner of <alias> to <player>. Wizards can use all of the malias commands on any mail alias. Instead of trying to figure out different mailing lists with the same name, wizards may use #<MALIAS NUMBER> instead of *alias in regards to the command. Remember that the alias commands will only recognize aliases owned by #1, owned by you, or by number. @malias/list When invoked by a wizard, it will list all mailing aliases currently defined by their number. & drop Command: drop[/<switch>] <object> drop[/<switch>] <exit> The first form removes <object> from your inventory and puts it in your location, except for the following special cases: Dropping a STICKY thing sends it home, and dropping a thing in a room with a drop-to sends the thing to the drop-to location. The second form removes <exit> from your list of exits and adds it to the list of exits for the current location. Anyone in the same location as you may then use the exit to travel to the exit's destination. You can only drop exits when you own the location where you are dropping them. The following switch is recognized: /quiet - Don't perform the @odrop/@adrop attributes on the dropped object. This switch only works if you control the object. 'throw' is the same as 'drop'. See also: get, @adrop, @drop, @odrop, DROP-TO, STICKY. & enter Command: enter[/<switch>] <object> The enter command is used to enter an object. Insides of objects are best used for vehicles, or storage spaces when you don't have a home (or even as a floating home). In order to enter an object you must either own it or it must have its ENTER_OK flag set, and you must also pass the object's EnterLock (if it has one). The following switch is recognized: /quiet - Don't perform the @oenter/@aenter or @oefail/@aefail attributes on the entered object, and don't perform the @oxleave attribute on your current location. This switch only works if you control the object being entered. See also: leave, @aefail, @aenter, @efail, @enter, @idesc, @lock, @oefail, @oenter, @oxleave, ENTER_OK. & examine Command: examine[/<switches>] <object>[/<wild-attrib>] Displays all available information about <object>. <object> may be an object, 'me' or 'here'. You must control the object to examine it, or it must be set VISUAL. If you do not own the object, you will just see the name of the object's owner, and optionally any public attributes and attributes owned by you set on the object. If an attribute is owned by a player other than the owner of the object, the number of the attribute owner is shown in parentheses immediately following the attribute name. Flag letters may appear in parentheses also, to indicate the status of the attribute: + - The attribute is locked, it does not change ownership when the object is @chowned and may not be modified. $ - The attribute is not checked when looking for $-commands. Note that the predefined attributes DESC, IDESC, ODESC, FAIL, OFAIL, SUCC, OSUCC, DROP, ODROP, SEX, and CHARGES are never checked. I - This attribute is not inherited by children of the object. V - The attribute is visible to anyone who examines you. Note that the predefined attributes DESC, SEX, and LAST are always VISUAL. { 'help examine2' for more } & examine2 If you specify a wildcarded attribute name, then only those attributes that match are shown. So, 'exam me/v?' will show all your attributes that start with v and are two characters long. The following switches are available: /brief - Shows everything except attributes. /full - When examining an object you don't control, show any public attributes set on the object in addition to the owner's name. /parent - Includes attributes that are not present on the object itself but which are inherited from the object's parent. See also: look, @decompile, VISUAL, ATTRIBUTE OWNERSHIP. & get Command: get[/<switch>] <object> get[/<switch>] <exit> get[/<switch>] <object>'s <sub-object> The first form picks up <object> from your location and adds it to your inventory. It will fail if the object is locked against you, or if you are inside a player or object that you don't control and which isn't set ENTER_OK. The second form takes an exit from your location and adds it to you. Anyone inside you may then use the exit to travel to the exit's destination. You may take exits that you own, and exits owned by others in locations that you own. The third form takes <sub-object> from <object> and adds it to your inventory. <object> must be ENTER_OK and <sub-object> must not be locked against you for this to work. The lock on <object> is not checked. { 'help get2' for more } & get2 The following switch is recognized: /quiet - Don't perform the @osucc/@asucc or @ofail/@afail attributes on the target object. This switch only works if you control the object. <object> and <sub-object> may be either players or things. 'take' is the same as 'get'. See also: drop, @afail, @asucc, @fail, @ofail, @osucc, @succ, ENTER_OK, FAILURE, SUCCESS. & give Command: give <player>=<amount/object> Gives player the specified amount of money or <object>. You can't give someone money if their new total would be greater than 10000 (No reason to get greedy). You may also give players objects, but the other player must be set ENTER_OK to receive something you give. See also: @apay, @cost, @opay, @pay, ENTER_OK. & goto Command: goto[/<switch>] <direction> goto[/<switch>] home <direction> home Moves you in the specified direction, assuming that the direction is not locked against you. 'move home' is a special command that returns you to your home. The word 'move' may be omitted. The following switch is recognized: /quiet - Don't perform the @osucc/@asucc/@odrop/@adrop or @ofail/@afail attributes on the exit being used. This switch only works if you control the exit. 'move' is the same as 'goto'. See also: enter, home, leave, & inventory Command: inventory Lists what you are carrying and how much money you have. & kill Command: kill <player> [=<cost>] Attempts to kill the specified player. Killing costs <cost> coins, which gives you a <cost>% chance of killing the player. Thus, spending 100 coins always works (except against wizards and immortals, who can never be killed). Players cannot be killed in rooms which have been set HAVEN or which they control. If you don't specify a cost, the default is 10 (for a 10% chance of success). The player, if killed, receives <cost>/2 coins in insurance. See also: @akill, @kill, @okill, BEING KILLED, IMMORTAL, WIZARD. & leave Command: leave[/<switch>] This command leave allows you to exit an object you have entered, arriving in the same location as the object. You may not leave an object if you fail that object's LeaveLock (but you may still @teleport out, use an exit inside the object, or go home). The following switch is recognized: /quiet - Don't perform the @oleave/@aleave or @olfail/@alfail attributes on the entered object, and don't perform the @oxenter attribute on your new location. This switch only works if you control your current location. See also: enter, @lock, ENTER_OK, @aleave, @alfail, @leave, @lfail, @oleave, @olfail, @oxenter. & LOGOUT Command: LOGOUT Disconnects you from your character without breaking the network connection to the game. You may then log in to another character. The LOGOUT command must be entered in all capitals. See also: QUIT. & look Command: look[/<switches>] [<object>] Displays the description of <object>, or the room you're in if you don't specify an object. Specifying object as <name> or #<dbref> or 'me' or 'here' is legal. You can also use look to look at objects held by other people, just use 'look <person>'s <object>'. You may use the /outside switch to look at the location of your current location (useful if you are inside a vehicle or other object). You may also look at other objects in the 'outer' location, but you may not use the possessive form with the /outside switch (ie: "look/outside <person>'s <object>" won't work). 'read' is the same as 'look'. See also: @adesc, @describe, @odesc. & move Command: move[/<switch>] <direction> move[/<switch>] home <direction> home Moves you in the specified direction, assuming that the direction is not locked against you. 'move home' is a special command that returns you to your home. The word 'move' may be omitted. The following switch is recognized: /quiet - Don't perform the @osucc/@asucc/@odrop/@adrop or @ofail/@afail attributes on the exit being used. This switch only works if you control the exit. 'goto' is the same as 'move'. See also: enter, home, leave. & news Command: news [<topic>] Shows you the current news for the MUX. It is highly recommended that you check the news daily for new information. Otherwise, the wizards will have no pity on you for messing up with the new commands. & OUTPUTPREFIX Command: OUTPUTPREFIX <string> Causes <string> to be output on a line by itself before printing the results of each command. This command is intended for use by external robot programs, and may be restricted to players whose ROBOT flag is set. The OUTPUTPREFIX command must be entered in all capitals. See also; @robot, OUTPUTSUFFIX, ROBOT. & OUTPUTSUFFIX Command: OUTPUTSUFFIX <string> Causes <string> to be output on a line by itself after printing the results of each command. This command is intended for use by external robot programs, and may be restricted to players whose ROBOT flag is set. The OUTPUTSUFFIX command must be entered in all capitals. See also; @robot, OUTPUTPREFIX, ROBOT. & page Command: page <player-list> [=[<control>]<message>] This command sends <message> to <player-list>. If you do not specify a name, it defaults to the players you last paged. You may use either the player's name or alias, a list of names and/or aliases, and you may also give a string that uniquely matches the start of a player's name on the WHO list. You can format the message one of several ways by specifying ':', ';', or '"' as the first character of the message. ':' and ';' format the message as 'From afar, <player> <message>', with ';' omitting the space between <player> and <message>. '"' formats the message in normal page format (this is the default). If your Idle attribute is set to something, then it is sent to anyone who successfully pages you. This is useful for when you are away from your terminal for a short while. { 'help page2' for more } & page2 You can selectively disable pages from certain players with the '@lock/page' command (players must pass the lock in order to page you). If someone cannot page you, they will be sent a message including of your Reject attribute if they try. If someone pages you while you are not connected, they are sent a message including your Away attribute. { 'help page3' for more. } & page3 You can also page many players at one time, where all the players you page will see the message. Ex: > p darkenelf lauren = Hi You paged (Darkenelf Lauren) with 'Hi'. To (Darkenelf Lauren), Dreamline pages: Hi You only need to type the player-list once, then the next time you page that player or set of players, you can abbreviate it with: "p :waves." or, "p I'm back." This will work until you page another player or list of players. See also: pose, say, whisper, :, ;, ", @pemit, @away, @idle, @idletimeout, @reject. & pose Command: pose[/<switches>] <message> Displays <message> to everyone in your current room, preceded by your name and optionally a space. Example: the command 'pose jumps for joy' produces '<yourname> jumps for joy'. The following switches are available: /default - (default) Put a space between your name and the message (ie, display '<name> <message>'). /nospace - Don't put a space between your name and the message (ie, display '<name><message>'). See also: page, say, whisper, :, ;, ". & QUIT Command: QUIT Logs you out and disconnects you from the game. Must be in all capitals. See also: LOGOUT. & read Command: read [<object>] Displays the description of <object>, or the room you're in if you don't specify an object. Specifying object as <name> or #<dbref> or 'me' or 'here' is legal. You can also use look to look at objects held by other people, just use 'read <person>'s <object>'. You may use the /outside switch to look at the location of your current location (useful if you are inside a vehicle or other object). You may also look at other objects in the 'outer' location, but you may not use the possessive form with the /outside switch (ie: "read/outside <person>'s <object>" won't work). 'look' is the same as 'read'. & ; Command: ;<message> This command is much like the ':' command, except that no space is inserted between your name and the action. Example: the command ';'s watch beeps.' produces '<yourname>'s watch beeps.'. Warning: This command does not work in command lists run from an attribute because the ';' is treated as the command separator. Use pose/nospace instead. See also: page, pose, say, whisper, :, ". & : Command: :<message> Displays <message> to everyone in your current room, preceded by your name and a space. Example: the command ':jumps for joy' produces '<yourname> jumps for joy'. See also: page, pose, say, whisper, ;, ". & " Command: "<message> Says <message> out loud to everyone in your current room. Example: the command '"Where is the movie theater?' produces '<yourname> says "Where is the movie theater>"'. Note that the closing double quote is automatically added. See also: page, pose, say, :, ". & # Command: #<number> <command> Forces the object whose database number is <number> to perform <command>. Example: '#1033 move north' forces object #1033 to go north (assuming that you control it). The same restrictions that apply to @force also apply to this command. See also: @force. & \\ Command: \\<message> Outputs <message> to everyone in your current room without embellishment. Example: the command '\\A chill falls over the room.' produces 'A chill falls over the room.' See also: @emit, @oemit, NOSPOOF. & say Command: say <message> Says <message> out loud to everyone in your current room. You can also use '"<message>'. See also: page, pose, whisper, :, ;, ". & score Command: score Displays how much money you have. Helpful to see if any machines are looping. See also: @ps, LOOPING. & SESSION Command: SESSION Displays information on how many characters you have sent and received during this session, and which (Internal) port you are connected to on the MUX. It must be typed in all uppercase. Example: > SESSION Characters Input---- Characters Output--- Player Name On For Idle Port Pend Lost Total Pend Lost Total Mortal 00:06 0s 16 0 0 44 156 0 2679 2 Players logged in. Pending characters are those waiting to be acted on as commands (for input) or waiting to be sent out over the network (output). Lost characters are due to overflowing either the MUX's input or output buffers, either as the result of running a single command that produces too much output (such as @find and @search commands that match a large number of objects), or from typing too much on one line. Note: your Pending count for output will always be nonzero, as the output of the SESSION command hasn't been sent out over the network yet. & take Command: take[/<switch>] <object> take[/<switch>] <exit> take[/<switch>] <object>'s <sub-object> The first form picks up <object> from your location and adds it to your inventory. It will fail if the object is locked against you, or if you are inside a player or object that you don't control and which isn't set ENTER_OK. The second form takes an exit from your location and adds it to you. Anyone inside you may then use the exit to travel to the exit's destination. You may take exits that you own, and exits owned by others in locations that you own. The third form takes <sub-object> from <object> and adds it to your inventory. <object> must be ENTER_OK and <sub-object> must not be locked against you for this to work. The lock on <object> is not checked. { 'help take2' for more } & take2 The following switch is recognized: /quiet - Don't perform the @osucc/@asucc or @ofail/@afail attributes on the target object. This switch only works if you control the object. <object> and <sub-object> may be either players or things. 'get' is the same as 'take'. See also: drop, @afail, @asucc, @fail, @ofail, @osucc, @succ, ENTER_OK, FAILURE, SUCCESS. & think Command: think <message> You can use this command to send a private message to yourself. Pronoun substitution is performed. This is essentially equivalent to "@pemit me=<message>", but with "think", there is no prepended text. One possible use: "@adesc me=think --> %n(%#[flags(%#)]) just looked at you." & throw Command: throw[/<switch>] <object> throw[/<switch>] <exit> The first form removes <object> from your inventory and puts it in your location, except for the following special cases: Dropping a STICKY thing sends it home, and dropping a thing in a room with a drop-to sends the thing to the drop-to location. The second form removes <exit> from your list of exits and adds it to the list of exits for the current location. Anyone in the same location as you may then use the exit to travel to the exit's destination. You can only drop exits when you own the location where you are dropping them. The following switch is recognized: /quiet - Don't perform the @odrop/@adrop attributes on the dropped object. This switch only works if you control the object. 'drop' is the same as 'throw'. See also: get, @adrop, @drop, @odrop, DROP-TO, STICKY. & use Command: use <object> Uses <object>. Some objects will do interesting, useful, or dangerous things when used, for instance, using a camera should result in a picture being taken. See also: @ause, @ouse, @use. & version Command: version Displays the version of MUX that is running and the date it was last rebuilt. & whisper Command: whisper <player>=<message> Whispers the message to the named person, if they are in the same room as you. No one else can see the message that you whisper. You can format the message one of several ways by specifying ':', ';', or '"' as the first character of the message. ':' and ';' format the message as 'You sense <player> <message>', with ';' omitting the space between <player> and <message>. '"' formats the message in normal whisper format (this is the default). See also: page, pose, say, :, ;, ". & WHO Command: WHO <prefix> Displays a list of players currently connected to the MUX. The WHO report tells you how long a player has been on, how long they have been inactive, and what they are doing (if they have used the @doing command). If <prefix> is specified, only players whose names start with <prefix> are listed. The WHO command must be entered in all capitals. See also: @doing. & & Command: &<attribute> <object>[=<value>] Synonym: @set <object> = <attribute>:[<value>] Sets the attribute named <attribute> on <object> to <value>. If <attribute> is not a predefined attribute (like ofail or va), then it is created. Attributes so created are called user-named attributes. Attribute names may only contain letters, numbers, and the characters < -_.@#$^&*~?=+| >, and must start with a letter. The names of user-named attributes may not be abbreviated (an attempt to get the value of the attribute will fail, and an attempt to set will create a new attribute). The & command may be used to set predefined attributes (in this instance, '&<attr> <object>=<value>' is equivalent to '@<attr> <object>=<value>'). See also: @set. & @@ Command: @@ <args> This command does nothing, therefore it is useful for putting comments into a MUX program. Be careful that ()'s and {}'s in the (otherwise ignored) arguments are nested correctly, lest your command-ending ; be trapped inside. Example: @va me=$foobar *:@fo #1234=%0;@@ This controls my foobar puppet. & @chown Command: @chown <object>[=<player>] @chown <object>/<attr>[=<player>] The first form changes the ownership of <object> to <player> (default is to yourself). Objects may be things, rooms or exits. To chown things, you have to be carrying the thing. For rooms or exits, you have to be in the room. Objects must have the CHOWN_OK flag set before they may be @chowned. In a room, the command used must be @chown here = <name>, and for an object, you must be very specific. The second form changes the ownership of the indicated attribute on <object> to <player> (default is the owner of the object). You may only @chown unlocked attributes. You may @chown unlocked attributes on objects that you own to yourself, and you may also @chown attributes that you own on objects owned by others to the owner of the object. When an object is @chowned, all unlocked attributes on the object are automatically @chowned as well, locked attributes remain owned by their original owners. The HALTED flag is automatically set on the new copy of the object. Players can't be @chowned; they always own themselves. See also: @lock, @Unlock, CHOWN_OK, ATTRIBUTE OWNERSHIP. & @chzone Command: @chzone <object>=<zone object>. Changes the zone of <object> to <zone object>. If <zone object> is "none", the zone is reset to NOTHING. @chzone'ing a player does not automatically change the zone of their objects. Anyone may reset the zone of an object they own; <zone object> must either be "none", or must be owned by them. Only wizards may @chzone an object to an arbitrary zone object. Players may @chzone themselves to an object they own; otherwise, only wizards may @chzone players. @chzone'ing resets the WIZARD, ROYALTY, and INHERIT flags on non-player objects. See also: ZONE OBJECTS & @clone Command: @clone[/<switches>] <object>[=<newname/cost>] Creates an exact duplicate of <object> that is owned by you and (for things and exits) puts it in your current location. You may have the object put in your inventory (or your exitlist in the case of cloning exits) by using the /inventory switch. You may clone your own objects, plus VISUAL objects owned by others. The INHERIT and WIZARD bits of the (new) object are cleared when the object is cloned. If <newname> is specified, it is used as the name instead of the original name. If you clone a linked exit, an attempt is made to link the clone to the same location. Except when using the /inventory switch, you can only clone exits when you own your current location. If you clone a room with a drop-to, an attempt is made to link the drop-to to the same location. If the original object was owned by you, then the ACLONE attribute is run in the new attribute, otherwise the new object is set HALTED. Exits and contents of cloned objects are not cloned, and LOCKED attributes are not copied. { 'help @clone2' for more } & @clone2 The following switches are available: /cost - Treat the argument after the = as the cost of the new object, not the name. /inherit - Don't reset the INHERIT bit on the new object. /inventory - Create the new object in your inventory (or your exitlist, in the case of cloning exits). /location - Create the new object in your location (default). /parent - Set the new object's parent to be the template object and don't copy the attributes. See also: @create, @decompile, @destroy, VISUAL. & @cpattr @cpattr <obj>/<attr> = <obj1>/<attr1> [,<obj2>/<attr2>,<obj3>/<attr3>,...] @cpattr <obj>/<attr> = <obj1> [,<obj2>,<obj3>,...] @cpattr <attr> = <obj1>/<attr1> [,<obj2>/<attr2>,<obj3>/<attr3>,...] @cpattr <attr> = <obj1> [,<obj2>,<obj3>,...] The first form of this command is used to copy <attr> on <obj> to the object-attribute pairs in a comma-separated list. For example: @cpattr test/va = test/vb, cube/va, tribble/foo would copy the VA attribute from object "test" to VB on "test", VA on "cube", and FOO on "tribble". <objN> is matched as if you were performing a @set on it. The second form copies <attr> to the list of objects, with the name <attr>. The third form copies <attr> from the object that executes the @cpattr, to the object-attribute pairs in the list. Finally, the third form copies <attr> from the object that executes the @cpattr to the objects in the list, with the name <attr>. & @create Command: @create <name> [=<cost>] Creates a thing with the specified name. Creation costs either <cost> or 10 coins, whichever is greater. The value of a thing is proportional to its cost, specifically, value=(cost/5)-1. The value may not be greater than 100, values that would be greater than 100 are rounded down to 100. See also: @destroy, TYPES OF OBJECTS. & @decompile Command: @decompile[/dbref] <thing>[/attr] [=<newname>] Dumps the sequence of commands you would have to type to clone <thing>. This is handy for saving your objects in a text file in case the MUX dies a horrible death, or for moving your pride-and-joy creation from one MUX to another. @decompile works on all object types. If you specify <newname>, then the commands emitted will set attributes, locks, and flags on an object named <newname> and will omit the command to create the object. If you specify <thing>/<attr>, <attr> accepts wildcards. If you specify the /dbref switch, you will get output using the dbref number instead of the object name. See also: examine, look. & @destroy Command: @destroy[/<switches>] <object> This command destroys <object> and refunds its cost of creation to its owner. You must own <object> in order to @destroy it, unless its DESTROY_OK flag is set, in which case anyone holding it may @destroy it. Rooms, exits, and objects may be destroyed, although the the actual destruction of rooms is delayed for up to ten minutes and the GOING flag is set on the victim room. Clearing the GOING flag on the room spares it from destruction. If a thing OR it's owner is set DESTROY_OK, the thing will be destroyed with no delay. The @destroy command will not destroy objects with the SAFE flag set unless the /override switch is specified. The DESTROY_OK flag overrides the protection given by the SAFE flag. The following switches are available: /override - Negate protection offered by the SAFE flag. See also: DESTROY_OK, SAFE. & @dig Command: @dig[/<switches>] <name> [= <exitlist> [, <exitlist>] ] Creates a new room with the specified name and displays its number. This command costs 10 coins. If the [= <exitlist>] option is used, an exit will be opened from the current room to the new room automatically. If the second <exitlist> option (after the comma) is specified, an exit from the new room back to the current room with the specified [Exits] name is opened. Either exit creation may fail if you do not have sufficient rights to the current room to open or link the new exit. Example: The command @dig Kitchen = Kitchen;k;north;n,south;s will dig a room called Kitchen, and open an exit called 'Kitchen' in your current room. The ; symbol means that you may enter the exit by typing 'k', 'north' or 'n' also. This command also opens the exit 'south;s' from 'Kitchen' back to where you are. Only the first Exit name is displayed in the Obvious exits list. If you specify the /teleport switch, then you are @teleported to the room after it is created and any exits are opened. See also: @destroy, @link, @open, LINKING, TYPES OF OBJECTS. & @doing Command: @doing[/<switches>] [<message>] Sets your doing message, which appears after your name in the WHO report. The following switches are available: /message - Sets your Doing string in the WHO report. (default) /poll - Displays the current Doing poll from the WHO report. See also: WHO, @poll. & @dolist Command: @dolist[/<switch>] [<delimiter>] <list>=<action> <list> is a list of strings, which can be object numbers, attributes, or arbitrary words. <action> is a command to perform once for each item in <list>, replacing the special symbol ## with the corresponding item from <list>, and the symbol #@ with the position in the list, starting with one. By default, @dolist considers each item in <list> to be separated with spaces. If you specify the /delimit switch, then each item is considered to be separated by <delimiter>. <delimiter> must be a single character. If present, <switch> can be any of: /space - (Default) List elements are separated by spaces. /delimit - List elements are separated by <delimiter>. This command is particularly handy with lcon() and lexits(). A few examples: @dolist [lcon(here)] = "[name(##)](##) @dolist [lcon(here)] = @switch [get(##/last)]=*1990*,"[name(##)] @va me = va vb vc @dolist [get(me/va)] = @emit [get(me/##)] @dolist Frodo Bilbo Gandalf = page ## = HELP!!!! I've fallen into a pit. @dolist/delimit , {Frodo, Bilbo Baggins, Gandalf} = page ## = HELP!!!! See also: iter(), parse(). & @drain Command: @drain <object> Discards all commands waiting on the semaphore <object> and resets the semaphore to its initial state. See also: @notify, @ps, SEMAPHORES & @edit Command: @edit <object>/<wild-attr> = <search>,<replace> @edit <object>/<wild-attr> = ^,<text> @edit <object>/<wild-attr> = $,<text> This command edits the contents of one or more attributes of an object, eliminating the need to retype a long attribute in order to make a simple change. In the first form, all occurrences of <search> in the specified attribute of the named object are replaced with <replace>. Use curly braces ({ and }) around <search> or <replace> if they contain commas. The second and third form prepend and append <text> to the selected attributes, respectively. If <wild-attr> contains wildcard characters, then all attributes that match are edited. & @cemit Command: @cemit[/<switches>] <channel>=<message> Sends <message> over <channel> prefixed by the channel's name. You must own or control the channel to do this. The following switches are available: /noheader - Sends the message to everyone on <channel>, without the channel's name prefixed. & @emit Command: @emit[/<switches>] <message> Sends <message> to everyone in your current location without prefixing it by your character name. You can also send the message to everyone in the room that contains the object you are inside with the /room switch. The following switches are available: /here - Sends the message to everyone in the same location as you. /room - Sends the message to everyone in the room that contains the object you are in. Starting from your location, this switch 'leaves' objects until it reaches a room, and @emits the message there. If both switches are specified, the message is sent to both places. If neither is specified, /here is assumed. Some MUXes may restrict the use of this command. See also: @femit, @oemit, @pemit, @npemit, @remit, SPOOFING. & @remit Command: @remit <room dbref#> = <message> Sends <message> to the contents of <room>. See also: @femit, @oemit, @pemit, @npemit, @emit, SPOOFING. & @entrances Command: @entrances [[<object>][,<low>[,<high>]]] Lists links from elsewhere to the specified object (default: your current room). For rooms, exits and drop-to's, leading to the room and players and objects whose home is in the room are listed. For players and objects, lists exits leading to them. Because this command is computationally expensive, it costs 100 coins. <low> and <high> can be used to indicate where to start and stop the search, respectively. Examples: > @entrances <- all links to here > @entrances object <- all links to object > @entrances ,100,200 <- all links to here from #100 to #200 > @entrances me,1000 <- all links to me from #1000 and above. See also: @link, @unlink. & @femit Command: @femit[/<switches>] <object>=<message> Forces <object> to emit <message>. This command is similar to the command '@force <object> = @emit <message>', except that it will work so long as you own the object, whereas @force may fail if the object has its INHERIT flag set and the object performing the @force does not. The following switches are available: /here - Sends the message to everyone in the same location as <object>. /room - Sends the message to everyone in the room that contains the object that <object> is in. Starting from your location, this switch 'leaves' objects until it reaches a room, and @emits the message there. If both switches are specified, the message is sent to both places. If neither is specified, /here is assumed. Some MUXes may restrict the use of this command. See also: @remit, @emit, @fpose, @fsay, INHERIT, SPOOFING. & @find Command: @find <name>[,<low>[,<high>]] Displays the name and number of every room, thing, or player that you control whose name matches <name>. Because the command is computationally expensive, it costs 100 coins. <low> and <high> may be used to restrict the range of objects that are searched, if they are given then the search starts at object #<low> and ends at object #<high>. Examples: > @find Lost Room > @find Secret Device,12000,14000 See also: @search. & @force Command: @force <player/object>=<command> Forces the game to act as though <player/object> had entered <command>. You may only force objects that you control. Objects may not force players unless either the object or the player has their INHERIT flag set, and objects that do not have their INHERIT flag set may not force objects that do. If the victim is specified by number, you may use an alternate form of the command, '#<number> <command>'. See also: puppets. & @fpose Command: @fpose[/<switches>] <object>=<message> Forces <object> to pose <message>. This command is similar to the command '@force <object> = :<message>', except that it will work so long as you own the object, whereas @force may fail if the object has its INHERIT flag set and the object performing the @force does not. The following switches are available: /default - (default) Put a space between the name of the object and the message (ie, send '<name> <message>'). /nospace - Don't put a space between the name of the object and the message (ie, send '<name><message>'). See also: @femit, @fsay, pose, :, ;, INHERIT. & @halt Command: @halt [<object>] Halts all commands being run by <object>, or by the object running the command if no <object> is given. If the object to be halted is a player, then all commands being run by objects owned by that player are halted. Use this command to stop runaway objects and infinite loops. The process of halting an object involves removing all commands waiting to be run by the object from the queue and refunding the queue deposit. Halting an object does not affect commands waiting on it as a semaphore. See also: @drain, @notify, kill, HALTED, SEMAPHORES. & @last Command: @last <player> This command displays a short 'connection history' for <player>, showing recent successful and failed connection attempts, as well as the total number of successful and failed connections. You can only display information about yourself. & @link Command: @link <object>=#<number>/here/home When used on a player or a thing, this command sets the object's home to the indicated location. The destination must be owned by you or be an ABODE room, and you must pass the destination's LinkLock. When used on a room, this command sets the room's drop-to, where objects dropped in the room go. The destination must be a room that is either owned by you or is LINK_OK, and you must pass the destination's LinkLock. For exits, this command sets the destination if the exit is currently unlinked, you control the destination or it is set LINK_OK, and you pass the destination's LinkLock. You can @link an unlinked exit regardless of who owns it or the lock set on it, you are made the owner if you successfully link to the destination. Linking an exit costs 1 coin, and if the exit was owned by someone else, you also reimburse the the former owner 1 coin (making the total cost to you 2 coins). { 'help @link2' for more } & @link2 Note that in all the above cases that it is the player performing the @link command that must pass the LinkLock, not the object being linked. Therefore, you should use the '$' lock qualifier if you want to prevent specific players from linking to your LINK_OK locations, as simply locking against '*<playername>' does not lock out their puppets. See also: @dig, @open, @unlink, DROP-TOS, HOMES, LINKING. & @list Command: @list [<option>] Lists information from internal databases. Information is available about the following options: attributes - Valid object attributes. commands - Commands that you may use (excluding the attribute-setting commands as well as any exits, and $-commands available). costs - Lists the costs associated with many commands and actions. default_flags - Lists the flags that new objects receive by default when created. flags - Lists the name and letter of all the flags. functions - Lists all the available functions. options - Lists several global options and limits. powers - Lists all powers. switches - Lists what commands support switches and the switches that they do support. The information provided by the @list command is definitive, as it reads the internal tables to produce the information it displays. Specifying @list with no argument lists the options you may use. & @listmotd Command: @listmotd Displays the current message-of-the-day. Note that it is displayed when you connect to your character. This will also display the "motd.txt" file. & @lock Command: @lock[/<whichlock>] <object>=<key> @lock <object>/<attrib> The first form locks <object> to a specific key(s). Type 'help @lock keys' for a list of the keys you may use. <whichlock> indicates which lock you want to set on the object. If you don't specify one, you set the Default lock. Type 'help @lock locks' for a list of the locks you may set and what they are used for. The second form locks the indicated attribute of the named object, so that when the object is @chowned, the attribute will remain owned by you. It may also be used when you own an attribute on an object that you do not own, in this case it prevents the object's owner from @chowning the attribute to himself, and prevents anyone from modifying or removing the attribute. See also: @chown, @unlock. & @lock locks You can set the following locks: DefaultLock: Exits: controls who may traverse the exit to its destination. Rooms: controls whether the player sees the SUCC or FAIL message for the room following the room description when looking at the room. Players/Things: controls who may GET the object. EnterLock: Players/Things: controls who may ENTER the object if the object is ENTER_OK. Also, the enter lock of an object being used as a Zone Master Object determines control of that zone. GiveLock: Players/Things: controls who may give the object. LeaveLock: Players/Things: controls who may LEAVE the object. LinkLock: All but Exits: controls who may link to the location if the location is LINK_OK (for linking exits or setting drop-tos) or ABODE (for setting homes) PageLock: Players: controls who may page the player. ParentLock: All: controls who may make @parent links to the object. ReceiveLock: Players/Things: controls who may give things to the object. { 'help @lock locks2' for more } & @lock locks2 SpeechLock: All but Exits: controls who may speak in that location (only checked if AUDITORIUM flag is set on that location) TeloutLock: All but Exits: controls who may teleport out of the location. TportLock: Rooms/Things: controls who may teleport there if the location is JUMP_OK. UseLock: All but Exits: controls who may USE the object, GIVE the object money and have the PAY attributes run, have their messages heard and possibly acted on by LISTEN and AxHEAR, and invoke $-commands stored on the object. DropLock: All but rooms: controls who may drop that object. UserLock: All: Not used by MUX, is intended to be used in MUX programming where a user-defined lock is needed. Note: If a player fails the UseLock on a parent of an object being searched for $-commands, then the search for attributes stops and the parent chain is not searched further for matches. & @Lock keys You may use the following keys when setting locks. For information about a particular type of key, type 'help @lock <keytype>'. Key Type Form in @Lock Command ---------- ------------------------------ Normal <object> Is =<object> Carry +<object> Ownership $<object> Indirect @<object> Attribute <attribute>:<wildcard-pattern> +<attribute>:<wildcard-pattern> =<attribute>:<wildcard-pattern> Evaluation <attribute>/<value> Compound <key> & <key> <key> | <key> !<key> ( <key> ) & @lock attribute ATTRIBUTE LOCKS: Key: <attribute>:<pattern> +<attribute>:<wildcard-pattern> =<attribute>:<wildcard-pattern> You may lock on whether a specific attribute on the player attempting to pass the lock matches a pattern. Example: '@lock thing=sex:m*' will lock thing to anyone whose sex starts with an M. Wild cards, greater than and less than may be used, for example: '@lock a-f=name:<g' will lock the exit a-f against any one whose name is higher than f. Both the player testing the lock and every object in his inventory is checked, the player passes the lock if any of those objects passes the lock. If the attribute name is prefixed by a = then only the player is checked. Similarly, if the attribute name is prefixed by a + then only objects in the player's inventory are tested. { 'help @lock attribute2' for more } & @lock attribute2 Note: you may lock against any attribute, but the locked object must be able to read the attribute from the player attempting to pass the lock or the lock will fail. Examples: > @lock men's room=sex:m* > @lock a-f=name:<g > @lock post office=email:*@* See also: ATTRIBUTE OWNERSHIP, @lock evaluation. & @lock evaluation EVALUATION LOCKS: Key: <attribute>/<value> Evaluation locks let you evaluate one of your attributes and compare the result against a value stored in the lock. The result must be an exact match (no wildcarding allowed, but uppercase and lowercase are considered to be the same). When evaluating the attribute the enactor substitutions (%#/%n/etc) are replaced with information about the player trying to pass the lock, and 'me' and %! refer to the locked object or exit. If you call an indirect lock and the indirect lock is an evaluation lock (or is a compound lock that includes an evaluation lock), then the original lock object is checked for the attribute first, followed by the object that has the actual evaluation lock. If there are multiple levels of indirection the intermediate locks are not checked. { 'help @lock evaluation2' for more } & @lock evaluation2 Examples: > @lock bank=checkmoney/1 > &checkmoney bank=[gt(money(%#),5000)] Only people and objects with more than 5000 pennies may pass. Note: this lock requires wizard privileges to read the worth of other players. > @lock divisible_by_five_club = checkdiv/0 > &checkdiv divisible_by_five_club = [mod(mid(%#,2,20),5)] Only objects whose db-number is divisible by 5 may pass. See also: @lock attributes. & @lock indirect INDIRECT LOCKS: Key: @<object> You may reference the lock on another object and use the result of evaluating that other object's lock. You pass an indirect lock if you pass the default lock on <object>. This is especially useful if you have a large number of objects or exits that want to have the same lock, and you want to be able to update one object and have all the other locks change at the same time. <object> is searched for when you enter the @lock command and its database number is stored in the lock, so something like '@Lock north=@master.lock' is safe even if you are going to move master.lock to another location. Examples: > @lock master.lock = me > @lock north = @master.lock > @lock south = @master.lock North and south all reference the lock on master.lock, so you may change the lock on all three exits by changing master.lock. See also: @lock normal. & @lock normal NORMAL LOCKS: Key: <object> You pass a normal lock if you either are the named object or if you carry the named object. <object> may be the name or #number of a thing, a playername prefixed by an asterisk (*<playername>), 'me', or 'here'. Examples: > @lock treasure room = secret key > @lock private area = me See also: @lock is, @lock carry. & @lock is IS LOCKS: Key: =<object> You pass an is lock only if you are the named object. Example: > @lock mystical highway = =magic bus Only the magic bus may travel down the mystical highway. You cannot travel the highway if you are carrying the bus. See also: @lock carry, @lock normal. & @lock carry CARRY LOCKS: Key: +<object> You pass a carry lock if you are carrying the named object. Example: > @lock secret passage = +magic bus You can only traverse the secret passage if you are carrying the magic bus. The bus cannot enter the passage on its own (perhaps when you are driving it). See also: @lock is, @lock normal. & @lock ownership OWNERSHIP LOCKS: Key: $<object> You pass an ownership lock if you have the same owner as <object>. Examples: > @lock mystuff=$me Only objects you own may use the mystuff exit. > @lock/page me = !$*TinyJerk Neither TinyJerk nor any of his objects may page you. See also: @lock normal. & @lock compound COMPOUND LOCKS: Key: <key> & <key> <key> | <key> !<key> ( <key> ) You can make complex locks by combining keys with the logical AND and OR operators (& and ! respectively), or by using the NOT operator. You may also group complex locks with parentheses. Examples: > @lock exit = me & !me An impossible lock, nothing can be both you and not you. > @lock message = me | *recipient Both you and the player recipient may get the msssage. & @mail @mail[/<switches>] <player-list> = <subject> @mail[/<switches>] [<msg-list> [= <target>]] @mail invokes the built-in MUX mailer, which allows players to send and receive mail. Pronoun/function substitution is performed on any messages you may try to send. A <player-list> is a space-separated list of recipients, which may be: Player names (names with spaces in them should be put in double quotes, ex: "Foo Bar") Player dbref #'s Message numbers to be replied to. A mix of the above, and mail aliases (see @malias) A <msg-list> is one of the following: A single msg # (ex: 3) A message range (ex: 2-5, -7, 3-) A sender (ex: *lauren) An age of mail in days (ex: ~3 (exactly 3), <2, >1) "days" here means 24-hour periods from the current time. One of the following: "read", "unread", "cleared", "tagged", "urgent" For certain commands, "all". See the following topics: mail-sending mail-reading mail-folders mail-other mail-admin @malias mail-reviewing mail-examples & mail-reviewing @mail/review <player> Reviews the messages you have sent to <player>. @mail/review <player>=<msglist> Reads the messages you have sent to <player>. @mail/retract <player>=<msglist> Retracts (deletes) unread messages you have sent to <player>. & mail-reading @mail <msg #> @mail/read <msg-list> This displays messages which match the msg# or msg-list from your current folder. @mail @mail <msg-list, but not a single msg #> This gives a brief list of all mail in the current folder, with sender name, a list of receiving players, subject, and message status. @mail/list [<msg-list>] This gives the same list, but with time sent instead of subject. The status field is a set of characters (ex: NC-UF+) which mean: N = New (unread) message C = Cleared message U = Urgent message F = Forwarded message + = Tagged message The opposites of these (read messages, etc.) are indicated with a '-' in the status field in that position. & mail-sending @mail[/switch] <player-list> = <subject> This begins a message to all players in <player-list>. -<text> adds text to the message in progress, for example -This is a test would add the text 'This is a test' to the end of your @mail message, likewise, ~<text> prepends the text. @mail/send This sends the message that is currently in progress. -- is the equivalent of @mail/send. @mail/urgent sends the message as urgent, and should not be used often. @mail/cc <player-list> This replaces the currect player list with a new one for carbon copying. It does _not_ add onto the existing list. See mail-sending2. & mail-sending2 @mail/proof This shows you the message that is currently in progress, as it would be read by whomever received it. @mail/edit <old text> = <new text> Like @edit, but edits the message in process. @mail/abort This aborts the message currently in progress, allowing you to start a new one. @mail/fwd <msg> = <player-list> This sends a copy of <msg> to all the players in <player-list>. The copy will appear to have been sent by you (not the original sender), and its status will be "Forwarded". Note that this places the message to be forwarded into your mail buffer, where you can edit it with @mail/edit, add text with '-', or prepend text with '~'. You have to use '--' or @mail/send to send the message. @mail/quick <player-list>/<subject> = <message> Sends <message> to the list of players. See mail-sending3. & mail-sending3 @mail/reply[/quote] <message> This starts a working message to the person who sent you <msg>. @mail/replyall[/quote] This starts a working message to the person who sent you <msg> and to every other recipient of <message>. In both cases, because this is a reply, the subject line will be: 'Re: <subject line from original message>' Also, in both cases, if /quote is specified, the original message will be quoted into the working message with a header and footer much like the following: On Thu Apr 27 21:33:04 2000, Gordon wrote: <quoted message from original message> ********** End of included message from Gordon You can add additional text above or below the quoted material with the postpend ('-') and prepend ('~') @mail commands. Like, normal outgoing @mail, the reply is finished and sent with '--' on a line by itself & mail-other @mail/clear [<msg-list | all>] @mail/unclear [<msg-list> | all>] These commands mark mail in the current folder as cleared or uncleared. Mail marked for clearing is deleted when you disconnect, or if you use @mail/purge. If no msg-list is specified, all mail in your current folder is cleared. If "all" is given instead of a msg-list, all mail in *all* folders is cleared/uncleared. @mail/purge Actually deletes all messages marked for clearing with @mail/clear. This is done automatically when you log out. @mail/tag [<msg-list | all>] @mail/untag [<msg-list> | all>] These commands tag or untag mail in the current folder. Tagged mail can be later acted on en masse by using "tagged" as the msg-list for other commands (which does *not* untag them afterward). If no msg-list is specified, all messages in the current folder are tagged/untagged. If "all" is given as the msg-list, all mail in *all* folders is tagged/untagged. (Ex: To clear all mail from Lauren and Crusade, @mail/tag *lauren, @mail/tag *crusade, @mail/clear tagged, @mail/untag all). { 'help mail-other2' for more } & mail-other2 @mail/safe [<msg-list> | all>] This command marks a message as being safe from mail expiration. It should be used sparingly and only for very imporatant messages. & mail-folders The MUX mail system allows each player 16 folders, numbered from 0 to 15. Mail can only be in 1 folder at a time. Folder 0 is the "inbox" where new mail is received. Most @mail commands operate on only the current folder. @mail/folder This commands lists all folders which contain mail, telling how many messages are in each, and what the current folder is. @mail/folder <folder#|foldername> This command sets your current folder to <folder#>. @mail/folder <folder#> = <foldername> This command gives <folder#> a name. @mail/file <msg-list>=<folder#> This command moves all messages in msg-list from the current folder to a new folder, <folder#>. & mail-admin The @mail command can also take the following switches: @mail/stats [<player>] -- Basic mail statistics. @mail/dstats [<player>] -- Also provides read/unread count. @mail/fstats [<player>] -- Does all that, plus gives space usage. @mail/debug <action>[=<player>] @mail/nuke Only wizards may stats players other than themselves. The mail statistics commands are computationally expensive, and thus are subject to "daytime" restrictions. They also cost the same as a @find (100 credits). The /debug switch does sanity checking on the mail database, and may only be used by a wizard. "@mail/debug sanity" just does the check; the command "@mail/debug clear=<player name or dbref number>" wipes mail for an object. "@mail/debug fix" attempts to repair problems noted in the sanity check. The /nuke switch destroys the post office, erasing all @mail everywhere. It may only be used by a wizard. Also, admin may set the @amail attrib on their char. When somebody sends you mail, it will trigger that attrib if it exists. & mail-examples Here is an example of mailing a player, where is the player will be "bob", and sending the mail. > @mail bob = The MUX - This is the Subject line. Sending mail to player 'Bob' > -Hi bob. - This is where you will enter the body of the message. Text Added. > @send - Basically, sends the @mail. MAIL: You sent your message to 'Bob'. & @mvattr Command: @mvattr <object>=<old>,<new>[,<copy1>]... This command moves attributes around on an object. The attribute <old> is renamed <new> (and is copied to <copy1>, <copy2> and so on if specified). If you cannot modify the <old> attribute (for instance if you are trying to move the Last attribute, or if it were owned by another player), then a new copy is made and the original is not removed. See also: @set. & @name Command: @name <object> = <new name> Changes the name of <object>. <object> can be a thing, player, exit, or room, specified as <name> or #<dbref> or 'me' or 'here'. See '@list options' as to whether or not a player name may contain spaces. & @notify Command: @notify[/<switches>] <object>[/<attribute>][=<count>] Notifies the semaphore <object>, running the first command that waited on <object> using the '@wait <object>=<command>' or ' @wait <object>/<time>=<command>' forms of the @wait command. If <count> is specified, it indicates the number of times the semaphore is notified. If there are no commands (or less than <count> commands) pending for <object>, then subsequent @waits will not block until the semaphore count reaches zero again. @notify may also take an argument of the form <object>/<attribute>, which notifies commands that are being blocked on an attribute other than the default 'Semaphore'. This allows blocking of muliple sets of commands on a single object, using different attributes. The following switches are available: /first - (default) Notify the first command waiting on the indicated semaphore (or the first <count> commands). /all - Notify all commands waiting on the semaphore and reset the semaphore count to zero. <count> is ignored. See also: @drain, @ps, @wait, SEMAPHORES & @oemit Command: @oemit <player>=<message> Emits <message> to everyone in the current location of <player> except <player>. See also: @remit, @emit, @pemit, @npemit, SPOOFING. & @open Command: @open[/<switches>] <direction list> [=<number>[,<direction list>]] Creates an exit in the specified direction(s). If <number> is specified, it is linked to that room. Otherwise, it is created unlinked. You or anyone else may use the '@link' command to specify where the unlinked exit leads. Opening an exit costs 1 coin. If you specify <number>, linking costs 1 more coin. You can specify a second direction list (after the comma), which is automatically opened in the room that the new exit goes TO and which is linked back to where you are. I.e. @open north;n=#1234,south;s would open exit 'north;n' from here to #1234, and an exit 'south;s' from #1234 to here, assuming you have rights to open exits and link to the rooms in question. The following switches are available: /location - Create the exit in your location (default). /inventory - Create the exit on yourself. See also: @dig, @link, LINKING. & @parent Command: @parent <object> [=<parent>] This command sets the parent of <object> to <parent> (or clears the parent if <parent> is omitted. You must control <object>, and must own <parent>. See also: PARENT OBJECTS. & PARENT OBJECTS Topic: PARENT OBJECTS Parent objects provide a way for several objects to inherit common attributes, exits, and $-commands from a single object, so that changing the parent object affects all of its children. When searching for attributes or exits, first the object itself is checked, then the parent is checked only if the object does not have what was searched for. Any attribute the parent object has will be passed down to its children, if they don't already have one. For instance, if the child object has no description, it will inherit the description of its parent. Any exits the parent object has will show up in the exit list of the child, and may be used as normal exits. The parent is searched for $-commands as well as the child, and only attributes that are unique to the parent are checked, so that conflicting attribute names are skipped. If both have an attribute named "cmd1", only the child's "cmd1" attributes is checked for a $-command. { 'help parent2' for more } & PARENT2 Topic: PARENT OBJECTS (continued) A parent object may itself have a parent, up to a configurable limit (usually 10 levels). The parent need not be the same type as its children, and flags and locks are not inherited from parent objects. You may not create parent loops. See also: @parent, parent(). & @password Command: @password <old password> = <new password> This command changes your password. & @pemit Command: @pemit[/switches] <what>=<message> Emits <message> only to <what>, or to <what>'s contents of the /contents switch is given. <what> must be either in the same location as you or be something you own. You can also @pemit to distant players if pagelocks allow you to page them, and this costs as much as a page <This feature is not present in all MUXes>. You cannot @pemit to the contents of something you don't own. The /list switch to this command allows you to @pemit a message to a list: @pemit/list <object 1> [<object 2> <object N>] = <message> There can be any number of objects in the list. The objects must be specified by dbref number. This can be combined with other switches. The following switches are also available: /contents - Send the message to the contents of the named object. /html - Send the message in HTML format (Pueblo). /noeval - Do not parse the message. /object - Send the message to the named object. See also: page, @remit, @emit, @oemit, SPOOFING. & @npemit Command: @npemit[/switches] <what>=<message> Almost exactly like @pemit and it takes the same switches. However, it does not evaluate <message> at all. So, @npemit differs from @npemit/noeval in that no space compression is done. See also: @pemit & @power Command: @power <object>=[!]<power> This is a command that allows the granting of special powers to objects of any type. See also: powers list & powers list announce Can use the @wall command. boot Can use the @boot command. builder Can build, if the builder power is enabled. chown_anything Can @chown anything to anyone. comm_all Like a wizard with respect to channels. control_all Can modify any object in the database. expanded_who Sees the wizard WHO, and SESSION commands. find_unfindable Can locate unfindable people. free_money Unlimited money. free_quota Unlimited quota. guest Is this a guest character? halt Can @halt anything, and @halt/all. hide Can set themselves DARK. idle No idle timeout. long_fingers Can get, look, whisper, etc from a distance. { 'help powers list2' for more } & powers list2 monitor Can set or reset monitor flag. poll Can set the @poll. prog Can use @program on players other than themself. search Can @search anyone. see_all Can examine and see attributes like a wizard. see_queue Can @ps/all or @ps any player. stat_any Can @stat any player. steal_money Can give negative money. tel_anywhere Can teleport anywhere. tel_anything Can teleport anything (includes tel_anywhere) unkillable Cannot be killed with the 'kill' command. See also: @power & @program Command: @program <player>=<obj/attr>[:<prefix>] This command allows for small 'programs' within MUX. To understand this command, you must first understand the fact that it completely bypasses any commands, built-in or otherwise, and allows you to send user-input directly into your code. A simple example: @va me=$start:@prog %#=me/vb:Please enter a word: @vb me=@emit You entered %0!;@prog %#=me/vc:Please enter another word: @vc me=@emit This time, you entered %0. You're done! > start Please enter a word: > foobar (Note that @program literally gives you a '>' prompt.) You entered foobar! Please enter another word: > hoopla This time you entered hoopla. You're done! { 'help @program2' for more } & @program2 As you can see, this command basically takes what a user types at the prompt, stuffs it into %0 in the code in <obj/attr>, and then triggers that attribute. Note that when @program triggers an attribute, the enactor of that triggered attribute is <player>, and is inserted into %#. r-registers are preserved when @program triggers an attribute. An optional message, <prefix>, may be specified and will be output before the @program prompt. This is useful for telling the user what information they need to supply. A player caught in @program may send a command through to the normal command processor at the @program prompt by prefixing it with the '|' character, for example, '|WHO'. See also: @quitprogram. & @ps Command: @ps[/<switches>] [<object>] Lists information about the commands you have on each of the queues. Unless the /summary switch is used, this command lists all the commands you have on the queues, optionally along with their enactor and arguments. Commands scheduled to be executed at a later time (by the @wait command) also show the number of seconds until they will be executed and/or the semaphore on which they are waiting. If <object> is specified, only commands run by <object> are listed, otherwise all commands run by any of your objects is listed. A summary of the number of commands listed and the total number of commands in the queues is also displayed. This command is useful for identifying infinite loops in programs. The following switches are available: /brief - (default) Display a brief summary that shows the semaphore number, time-to-wait, object running the command, and the command to be run. /long - In addition to the information in the /brief report, display the name and number of the object that caused the command to be run (the enactor) and the arguments to the command. /summary - Display just the queue counts. See also: @notify, @wait. & @quitprogram Command: @quitprogram <player> Terminates the @program for player. If <player> is not specified, then it works upon the enactor (a player may quit a program while they are in it by piping out @quitprogram, see 'help @program'). See also: @program. & @quota Command: @quota Lists your total building quota and the amount you have remaining. Creating objects, digging rooms, and opening exits all consume quota. See also: @create, @dig, @open. & @robot Command: @robot <name>=<password> Creates a robot player owned by you. The robot has its ROBOT flag set, so it may use the OUTPUTPREFIX and OUTPUTSUFFIX commands that most publicly available robot programs require. This command costs 1000 coins. Note that some sites do not restrict OUTPUTSUFFIX and OUTPUTPREFIX to robots. See also: OUTPUTPREFIX, OUTPUTSUFFIX, ROBOT, TYPES OF OBJECTS. & @search Command: @search [<player>] [<class>=<restriction>[,<low>[,<high>]]] Displays information about objects that meet the search criteria. Because this command is computationally expensive, it costs 100 coins. <player> restricts the search to the named player, while <class> and <restriction> control the objects listed. Type 'help search classes' for a list of the classes you may use. Except when getting lists of players ('@search type=player' or '@search flags=P'), you may only search for objects that you own. You may limit the range of the search with <low> and <high>, which specify the objects to start and stop the search at, respectively. The default for <low> is #0 and the default for <high> is the last object in the database. Examples: @search flags=PWc <-- search for connected wizards. @search type=room <-- list all rooms owned by me. @search eval=gt(money(##),10) <-- search for things worth more than 10. @search type=room,100,300 <-- Rooms between #100 and #300, inclusive @search object=Test,5000 <-- Things starting with Test from object #5000 to the end of the database. See also: @find, search(). & @set Command: @set[/<switch>] <object>=[!]<flag> @set[/<switch>] <object>=<attribute>:<value> @set[/<switch>] <object>=<attribute>:_<fromobj>/<fromattr> @set[/<switch>] <object>/<attr>=[!]<attrflag> The first form sets (or clears) the indicated flag on <object>, the second form sets the <attribute> attribute on <object> to <value>, creating a new user-named attribute if there is no attribute named <attribute>. The third form copies an attribute from another object, and the fourth form sets (or clears) an attribute flag on the <attr> attribute of <object>. When setting attributes on an object, you may also use the command '@<attribute> <object> = <value>' if the attribute is a predefined attribute. You may also use the command '&<attribute> <object> = <value>' to set either predefined attributes or user-named attributes. Either of these is equivalent to the second form of the @set command. { 'help @set2' for more } & @set2 The following flags may be set using the fourth form of the @set command: no_command - Prevent $-commands and ^-patterns defined in the attribute from being performed. no_inherit - Prevents children of the object from obtaining the attribute. From their perspective the attribute does not exist. visual - Anyone may see the attribute when they examine you, and may get the attribute with get(). hidden - The attribute is only visable to wizards. regexp - When $-commands are matched, treat the pattern as a regular expression rather than a wildcard glob pattern. wizard - The attribute may only be changed by wizards. The @set command takes the following switch: quiet - Inhibit 'Set.' acknowledgement messages. See also: @lock, @lock, examine, FLAGS, &. & @stats Command: @stats[/all] [<player>] Display the number of objects in the game. @stats/all gives a breakdown by object types. If <player> is specified, the breakdown for the named player is given. You may only list individual counts for yourself. If invoked with no arguments or switches this command is free, but if you specify either /all or <player>, then this command costs 100 coins to run, because it is computationally expensive. See also: stats(). & @sweep Command: @sweep[/<switches>] This command tells you all of the objects, players, and exits that are listening in the room you are currently in, as well as the objects you are carrying. Most objects only listen for a particular string or phrase, so they normally do not pose a problem if you need privacy. You will have to be careful of players, puppets, and audible exits since they will hear everything you say and do. There are several switches that may be used to limit the type of listeners that are checked for. They are: /here - Check the room I am in. /inventory - Check my inventory. /exits - Check exits in the room. /commands - Check for objects that have $-commands set on them. /connected - Check for connected players and their puppets. /listeners - Check for objects with @listen set to something. /players - Check for players and their puppets, whether or not they are connected. The default is to search for everything. If you specify one or more switches from either category (either location or listener type then only that location or listener type is checked. See also: @listen, AUDIBLE, PUPPETS. & @switch Command: @switch[/<switches>] <string>=<t1>,<c1> [,<tN>,<cN>]... [,<cD>] Compares <string> against the targets <t1>, <t2>, etc, until a match is found, at which time the corresponding list of commands is performed. Wildcards, and the < and > operators are allowed in the targets. By default, any list whose target matches the string is executed (the targets are not mutually exclusive). If no target matches, the default list <cD> is executed. The following switches are available: /all - (default) Perform the actionlists associated with all targets that match <string>. /first - Perform only the actionlist associated with the first target that matches <string>. & @teleport Command: @teleport [<object>=] <room/thing> @teleport [<object>=] <exit> @teleport [<object>=] home The first form of the @teleport command moves <object> (or you) to the named room or thing. The second form sends <object> (or you) to the destination of the named exit, while the third form sends <object> (or you) home. If the destination room has a drop-to, the object will go to the drop-to instead of the named location. For the first form of the @teleport command, the object being teleported must pass its location's TeloutLock; and you must control the destination, or it must be JUMP_OK and you must pass the destination's TportLock. The second and third forms let you remove any object from locations you control by sending them through an exit or to their home. The following switch is available: /quiet - Teleports without setting off success or failure messages. See also: JUMP_OK, @lock (tport and telout), @tfail, @otfail, @atfail, @tofail, @otofail, @atofail. & @trigger Command: @trigger[/<switch>] <object>/<attr> [=<param> [, <param>]... ] Invokes an action list stored in an attribute on an object. The triggering object becomes the enactor and the positional parameters %0 through %9 are set to the supplied parameters. The @trigger command supports the following switch: quiet - Inhibit 'Triggered.' acknowledgement messages. See also: LOOPING. & @unlink Command: @unlink <room/exit> This command removes drop-tos on rooms and clears the destination on exits. Once unlinked, an exit may be taken over by anyone with the @link command. See also: @link, LINKING. & @unlock Command: @unlock <object> @unlock <object>/<attrib> The first form removes the lock on <object>, so that anyone may pass through (if an exit) or pick it up (if a player or an object). The second form clears the locked flag on the indicated attribute of the named object. This allows the attribute to change ownership to the new owner automatically when the object is @chowned, and allows the owner of the object to @chown the attribute to themself or to overwrite it. You must own the attribute to be unlocked, but you do not need to own the object. See also: @chown, @lock, ATTRIBUTE OWNERSHIP. & @verb Command: @verb <victim>=<actor>,<what>,<def>,<owhat>,<odef>,<awhat>,<args> This command provides a way to do user-defined verbs with associated @attr/@oattr/@aattr groups. Invoking it does the following: <actor> sees the contents of <victim>'s <what> attribute, or the <def> string if you can't read <victim>'s <what> attribute. Everyone in the same room as <actor> sees the contents of <victim>'s <owhat> attribute, with <actor>'s name prepended, or <odef>, also with <actor>'s name prepended, if you can't read <victim>'s <owhat> attribute. If you control <victim>, then he executes the contents of his <awhat> attribute. By supplying up to nine <args>, you may pass those values on the stack (i.e. %0, %1, %2, etc. up through %9). You must control the actor, but need not control the victim. Note that if you don't have the ability to read the appropriate attributes (whether because you control the victim, he is VISUAL, or the attributes are set VISUAL), the default messages will be used. { 'help @verb2' for more } & @verb2 Here is a description of the arguments to @verb: victim - The object that is searched for attributes, and which runs the <awhat> attribute if it is found. actor - The object that 'did' the verb, this is the value for %#/%n/etc in substitutions, and this object's name is included in the message to others in the same location. what - The name of the attribute containing the message to be delivered to the actor. whatd - The message to deliver to the actor if the victim does not have a <what> attribute, or if it cannot be read. owhat - The name of the attribute containing the message (prefixed by the actor's name) that is sent to everyone in the room with the actor. owhatd - The message (prefixed by the actor's name) to deliver to others in the room with the actor if the victim does not have an <owhat> attribute, or it cannot be read. awhat - The name of the attribute that is to be executed by the victim. args - The comma-separated arguments to be passed for substitution (%0-%9). If there is more than one argument, enclose all the arguments within curly braces. Any argument that contains an embedded comma needs to be enclosed in curly braces as well. { 'help @verb3' for more } & @verb3 Examples: > &xtest test1=You just xtested test1. > &oxtest test1=just xtested test1. > &axtest test1="I was xtested. Yikes. Arg1=%0, Arg2=%1, Arg3=%2. > @verb test1=me,xtest,XTEST DFLT,oxtest,OXTEST DFLT,axtest,{a,b c,de} You just xtested test1. test1 says "I was xtested. Yikes. Arg1=a, Arg2=b c, Arg3=de." > &xtest test1 > @verb test1=me,xtest,XTEST DFLT,oxtest,OXTEST DFLT,axtest,{a,b c,de} XTEST DFLT test1 says "I was xtested. Yikes. Arg1=a, Arg2=b c, Arg3=de." > @fo test1={@verb test1=me,xtest,XTEST D,oxtest,OXTEST D,axtest,{a,b,de}} test1 just xtested test1. test1 says "I was xtested. Yikes. Arg1=a, Arg2=b, Arg3=de." See also: locate(). & @wait Command: @wait <seconds>=<command> @wait <object>[/<seconds>]=<command> @wait <object>/<attribute>=<command> The first form of @wait executes <command> after <seconds> seconds. The second form increments the semaphore count for <object> and executes <command> after <object> is notified with the @notify command. If the semaphore count for <object> is negative (because it has been notified more times than it has been waited on), then <command> is run immediately. If <seconds> is specified in the second form, the command is automatically run after <seconds> seconds even if the semaphore isn't notified. The third form allows for blocking multiple sets of commands on the same object, using seperate attributes to keep track of the semaphore. This command charges a deposit of 10 coins, which is refunded when <command> is executed. See also: @drain, @notify, @ps, SEMAPHORES. & @wipe Command: @wipe <object>[/<wild-attr>] This command erases attributes from an object. All attributes that match <wild-attr> (or all attributes, if <wild-attr> is not specified) are removed from <object>. Attributes that you do not have permission to modify (such as read-only or locked attributes) are not removed. & @aahear Command: @aahear <object> = <command-list> Attribute: Aahear An Aahear on an object is activated whenever the listen pattern matches anything done/said by anything else in the room, including itself. (The Ahear ignores itself, helpful for keeping machines from triggering itself) Example: @aahear listener = "I heard someone (maybe me?) say the word! See also: @ahear, @amhear, @listen. & @aclone Command: @aclone <object> = <command-list> Attribute: Aclone Sets the actions to be taken by a new object that has just been created as the result of a @clone command. The contents of the Aclone attribute are run by the new object and not by the old object. This attribute is only meaningful for things, and will never be automatically triggered on other object types. It is also possible to check the zone object/objects in the zone parent room for an @adisconnect. If one is found, it will be executed when a player disconnects in that zone. Example: @aclone Time bomb = @wait 600=@trig me/va;@wait 10=@trig me/vb @va time bomb = :EXPLODES with a thundering roar;@destroy me @vb time bomb = :ticks.; @wait 10=@trig me/vb See also: @clone. & @aconnect Command: @aconnect <object> = <command-list> Attribute: Aconnect Sets the actions to be taken by a player right after connecting to the game. This attribute is only meaningful for players, and will never be automatically triggered on other object types. It is also possible to check the zone object/objects in the zone parent room for an @aconnect. If one is found, it will be executed when a player connects in that zone. Example: @aconnect me = check.my.mailbox See also: @adisconnect. & @adescribe Command: @adescribe <object> = <command-list> Attribute: Adescribe Sets the actions to be taken when <object> is looked at. Example: @adesc kitten = :rubs against %n's legs affectionately. See also: look, @desc, @idesc, @odesc. See also "help think" & @adfail Command: @adfail <object> = <command-list> Attribute: Adfail Sets the action to be taken by an object when someone tries to drop it but fails because they didn't pass the object's drop lock. Example: @adfail sword = @name me=Cursed Sword;:laughs maniacally. See also: drop, @dfail, @odfail, @lock. & @adisconnect Command: @adisconnect <object> = <command-list> Attribute: Adisconnect Sets the actions to be taken by a player right after disconnecting from the game. This attribute is only meaningful for players, and will never be automatically triggered on other object types. Example: @adisconnect me = home See also: @aconnect. & @adrop Command: @adrop <object> = <command-list> Attribute: Adrop Sets the action to be taken by an object when it is dropped, or by an exit when it is successfully used. Example: @adrop plastique = kill %n=100; @destroy me See also: drop, @drop, @odrop, DROP-TO, EXITS. & @aefail Command: @aefail <object> = <command-list> Attribute: Aefail Sets the action to be taken by an object when someone tries to enter it but fails because the object is not ENTER_OK or the player fails the object's enter lock. The enter lock only affects the 'enter' command and its aliases (set via the @ealias command), it does not affect exits that lead to the object or teleporting in. This attribute is meaningful for players and things, and will never be automatically triggered on rooms or exits. Example: @aefail car = @emit ;'s alarm starts wailing when %n tries to break in. See also: @aenter, @efail, @ealias, @enter, @oefail, @oenter, enter, ENTER_OK. & @aenter Command: @aenter <object> = <command-list> Attribute: Aenter Sets the action to be taken by an object or room when someone enters it, whether by using an exit, the enter or leave commands, or by teleporting. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @aenter car = :starts its engine, eagerly awaiting a road trip.; "Beep Beep! See also: enter, @enter, @oenter, ENTER_OK. & @afail Command: @afail <object> = <command-list> Attribute: Afail Sets the commands to be performed by <object> when one of these events occurs: - For exits: Someone tries to traverse the exit but cannot because they fail the exit's default lock or the exit is not linked. - For players and things: Someone tries to pick up the object but cannot because they fail the object's default lock. - For rooms, players, and things: Someone looks around inside the room, player, or thing and fails the object's default lock. Example: > @afail vase = :falls to the floor and smashes to pieces.;@destroy me See also: @fail, @ofail, FAILURE. & @agfail Command: @agfail <object> = <command-list> Attribute: Agfail Sets the action to be taken by an object when someone tries to give it away but fails because they didn't pass the object's give lock. Example: @agfail sword = @name me=Cursed Sword;:laughs maniacally. See also: give, @gfail, @ogfail, @lock. & @ahear Command: @ahear <object> = <command-list> Attribute: Ahear Sets the actions to be taken after the object hears a string that matches the pattern in the Listen attribute which was not produced by the object itself. Messages that are produced by the object itself are ignored. Example: @ahear clock = "The time is now [time()]. >> BONNNNGGGGG << See also: @aahear, @amhear, @listen. & @akill Command: @akill <object> = <command-list> Attribute: Akill Sets the actions to be taken by an object after it is killed and has returned to its home. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @akill lion = south; :leaps onto %n, roaring loudly.;kill %n=100 See also: kill, @kill and @okill, BEING KILLED, IMMORTAL, WIZARD. & @aleave Command: @aleave <object> = <command-list> Attribute: Aleave Sets the action to be taken by an object or room when someone leaves it, whether by using an exit, the enter or leave commands, or by teleporting. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @aleave car = :stops to let %n out.;:revs its engine, hoping another brave soul would like a ride. See also: leave, @leave, @oleave. & @alfail Command: @alfail <object> = <command-list> Attribute: Alfail Sets the action to be taken by an object when someone tries to leave it but fails because the player fails the object's leave lock. The leave lock only affects the 'leave' command and its aliases (set via the @ealias command), it does not affect going home, using an exit in the location, or teleporting out. This attribute is meaningful for players and things, and will never be automatically triggered on rooms or exits. Example: @alfail box = :rattles around as %n tries to escape. See also: @aleave, @lalias, @leave, @lfail, @oleave, @olfail, leave. & @alias Command: @alias <player> = <name> Attribute: Alias Provides an alternate name by which the player is known. The alternate name is only used for players when referenced as '*<name>' or by commands that only take playernames (such as page or @stats). You may not set an alias on any other object type. When setting an alias, the alias is checked to see that it is both a legal player name and not already in use. Only if both checks succeed is the alias set. & @amail Command: @amail <player> = <command-list> Attribute: Amail Sets the actions to be taken after a player receives @mail. This should *never* @mail another player, as this could cause an infinite loop. Example: @amail me=@mail/file [mail()]=2 This would place all incoming messages in folder #2. See also: @mailsucc, @signature, @mail. & @mailsucc Command: @mailsucc <player> = <message> Attribute: Mailsucc Sets a message to be displayed to the sender whenever <player> receives mail. Example: @mailsucc me=Thanks for the mail. See also: @amail, @signature, @mail. & @signature Command: @signature <player> = <message> Attribute: Signature Sets a message to be appended to ever @mail message you send. It is appended directly at the end of the message, so if you wish to start the signature on a new line you should begin it with a %r. Example: @signature me=%rThis is a mail signature. (Note: You might want to include the %r at the front of the signature, other wise it will be combined with the @mail message.) See also: @mailsucc, @amail, @mail. & @amhear Command: @amhear <object> = <command-list> Attribute: Amhear Sets the actions to be taken after the object hears a string that matches the pattern in the Listen attribute which was produced by the object itself. Messages that are produced by anything other than the object itself are ignored. Example: @amhear listener = "Wait a minute. I said the trigger word! See also: @aahear, @ahear, @listen. & @amove Command: @amove <object> = <command-list> Attribute: Amove Sets the action to be taken by an object whenever it moves from one location to another, whether by using an exit, entering or leaving an object, teleporting, or going home. This attribute is meaningful for players, and things and will never be automatically triggered on other object types. Example: @amove car = @vz me=[extract(%vz,1,19)] [loc(me)] See also: @move, @omove. & @apay Command: @apay <object> = <command-list> Attribute: Apay Sets the actions to be taken after the object is given the number of coins specified in its Cost attribute. If the giver tries to give more than that number of coins, the excess is refunded, and if less than the necessary amount is given then it is all given back and a snide message is sent to the giver. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @apay Coke machine = @clone Can of Coke; :drops a can on the floor. See also: give, @cost, @opay, @pay. & @arfail Command: @arfail <object> = <command-list> Attribute: Arfail Sets the action to be taken by an object when someone tries to give it something that fails its give lock. Example: @arfail merchant = "I don't buy such junk. Begone!; @tel %#=cheater_exit See also: give, @agfail, @gfail, @ogfail, @orfail, @rfail, @lock. & @asuccess Command: @asuccess <object> = <command-list> Attribute: Asucc Sets the actions to be taken by an object when someone successfully picks it up (because they passed the lock), by an exit when someone passes through it, or when someone looks at a room and passes the room's lock. Example: @asucc kitten = :climbs up your sleeve and nuzzles your face. See also: @osucc, @success, SUCCESS. & @atfail Command: @atfail <object> = <command-list> Attribute: Atfail Sets the action to be taken by an object when someone tries to teleport there but fails. Example: @atfail here = @page [owner(me)]=%N tried to teleport here. See also: @teleport, @tfail, @otfail, @lock. & @atofail Command: @atofail <object> = <command-list> Attribute: Atofail Sets the action to be taken by an object when someone tries to teleport out but fails. Example: @atofail here = @page [owner(me)]=%N tried to teleport out. See also: @teleport, @tofail, @otofail, @lock. & @atport Command: @atport <object> = <command-list> Attribute: Atport Sets the actions to be performed by object whenever it teleports. The actions are performed after the object moves to its new location. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @atport me = &TEL.COUNT me=add(v(TEL.COUNT),1) See also: @otport, @oxtport, @tport, @teleport. & @aufail Command: @aufail <object> = <command-list> Attribute: Aufail Sets the list of commands to be run when someone 'use's the object but fails the object's use lock. Note that the other functions controlled by the use lock (paying, listening, and $-commands) do not trigger Aufail. Example: @aufail robot = "I _told_ you to leave me alone; kill %n=100 See also: @oufail, @ufail, @use. & @ause Command: @ause <object> = <command-list> Attribute: Ause Sets the actions to be taken when someone uses the object with the use command. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @ause grenade = :EXPLODES with a thundering roar; kill %n=100; @destroy me See also: use, @ouse, @use. & @away Command: @away <object> = <message> Attribute: Away This attribute is sent as a message to anyone who tries to page you when you are not connected. This attribute is only meaningful for players, and will never be automatically referenced on other object types. Example: @away me = Hey, I'm not even connected. So why are you paging me? See also: @idle, @idletimeout, @reject, page. & @charges Command: @charges <object> = <count> Attribute: Charges This attribute allows you to limit the number of times an object can be used. If there is a charges attribute it is decremented each time an action on the object is triggered. Once it reaches zero, normal triggering stops and the Runout attribute (if one is present) is run instead. Example: @charges Fireball wand = 5 See also: @runout. & @cost Command: @cost <object> = <amount> Attribute: Cost Sets the number of coins that need to be given to an object to trigger the Pay, Opay, and Apay attributes. If the object is given more than this amount, the excess is returned to the giver, while if less than this amount is given the entire amount is returned, a snide message is sent to the giver, and the Apay, Opay, and Pay attributes are not used. This attribute is only meaningful for things, and will never be automatically triggered on other object types. Example: @cost Coke machine = 25 See also: give, @apay, @opay, @pay. & @daily Command: @daily <object>=<command-list> Attribute: Daily This attribute is automatically triggered once per day. No guarantees are made as to what time it will execute. & @describe Command: @describe <object> = <description> Attribute: Desc Sets the description for <object>, which others see when they look at the object. Giving all your objects, rooms, and exits good descriptions is considered to be good building practice. Function references and %-substitutions are allowed in descriptions, and are evaluated when someone looks at the object. In function references, 'me' refers to the object being looked at, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the looker. Examples: <object> @desc vase = You see a delicate Ming vase. <exit> @desc elevator = There is an elevator to the east. See also: look, @adescribe, @odescribe. & @dfail Command: @dfail <object> = <message> Attribute: Dfail Sets the message that a player sees when he tries to drop the object but fails because he didn't pass the object's drop lock. Function references and %-substitutions are allowed in drop failure messages, and are evaluated when someone drops the object. In function references, 'me' refers to the object being dropped, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the dropper. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @dfail sword = The sword has welded itself to your hand. See also: drop, @adfail, @odfail, @lock. & @drop Command: @drop <object> = <message> Attribute: Drop Sets the message that a player sees when he drops the object, or after he goes through the exit. Function references and %-substitutions are allowed in drop messages, and are evaluated when someone drops the object. In function references, 'me' refers to the object being dropped, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the dropper. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Examples: <object> @drop vase = You gently put down the delicate vase. <exit> @drop elevator = The elevator doors close behind you. See also: drop, @adrop, @odrop, DROP-TO, EXITS. & @ealias Command: @ealias <object> = <entrance-list> Attribute: Ealias Sets up a set of alternate commands that may be used as synonynms for the command 'enter <object>' when you are in the same location as the object. The alternate commands are separated by semicolons just like in exit names. Entry aliases are checked for after exitnames, builtin MUX commands, and leave aliases for the current location, but before $-commands. If more than one object has an entry alias that matches a player's command, the one on the object that occurs first in the location contents list is used. This attribute is meaningful for players and things, and will never be automatically looked at on rooms or exits. Example: @ealias car = get in car; car; climb in; go for a ride See also: @lalias, enter, leave. & @efail Command: @efail <object> = <command-list> Attribute: Efail Sets the message that a player sees when he tries to enter the object but fails because the object is not ENTER_OK or the player fails the object's enter lock. Function references and %-substitutions are allowed in efail messages, and are evaluated when someone fails to enter the object. In function references, 'me' refers to the object that the enactor tried to enter, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the the player who tried (and failed) to enter. The enter lock only affects the 'enter' command and its aliases (set via the @ealias command), it does not affect exits that lead to the object or teleporting in. This attribute is meaningful for players and things, and will never be automatically triggered on rooms or exits. Example: @efail car = The car's door is locked. See also: @aefail, @aenter, @ealias, @enter, @oefail, @oenter, enter, ENTER_OK. & @enter Command: @enter <object> = <message> Attribute: Enter Sets the message that a player sees when entering an object or room, whether by using an exit, the enter or leave commands, or by teleporting. Function references and %-substitutions are allowed in enter messages, and are evaluated when someone enters the object. In function references, 'me' refers to the object being entered, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player entering the object. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @enter car = You climb into the car and buckle your seatbelt. See also: enter, @aenter, @oenter, ENTER_OK. & @fail Command: @fail <object> = <message> Attribute: Fail Sets the failure message for <object>. This message is seen by the actor when one of these events occurs: - For exits: Someone tries to traverse the exit but cannot because they fail the exit's default lock or the exit is not linked. - For players and things: Someone tries to pick up the object but cannot because they fail the object's default lock. - For rooms, players, and things: Someone looks around inside the room, player, or thing and fails the object's default lock. Substitution and evaluation is performed on the message before it is shown. Example: > @fail table = It's too heavy to lift! <thing> > @fail doorway = The doorknob does not turn. <exit> See also: get, @afail, @ofail, FAILURE. & @filter Command: @filter <object> = <pattern>[, <pattern>...] Attribute: Filter This attribute specifies a series of patterns to be used to suppress text normally forwarded by the AUDIBLE flag. If the desired pattern contains a comma, the pattern may be enclosed in curly braces {}. Example: > @fo test=out > @set #378=puppet test> test grows ears and can now hear. > @filter out = {* has arrived.},{* has left.} Set. > :has not arrived. Wizard has not arrived. test> From a distance, Wizard has not arrived. > :has arrived. Wizard has arrived. See also: AUDIBLE, @forwardlist, @infilter, @inprefix, @prefix. & @forwardlist Command: @forwardlist <object> = <dbref-list> Attribute: Forwardlist Specifies a list of locations (specified by their db numbers) that are to receive messages heard by <object> (filtered by the @filter attribute and prefixed by the @prefix attribute). The messages are only forwarded if <object> has its AUDIBLE flag set. See also: @filter, @prefix, AUDIBLE. & @gfail Command: @gfail <object> = <message> Attribute: Gfail Sets the message that a player sees when he tries to give away the object but fails because he didn't pass the object's give lock. Function references and %-substitutions are allowed in give failure messages, and are evaluated when someone tries to give away the object. In function references, 'me' refers to the object being given away, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the (attempted) giver. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @gfail sword = You can't give away a cursed sword! See also: give, @agfail, @ogfail, @lock. & @idesc Command: @idesc <object> = <message> Attribute: Idesc Sets the internal description for <object>. The internal description of an object will be shown to any player entering it. If not set, the regular description in the Desc attribute is shown instead. Function references and %-substitutions are allowed in inside descriptions, and are evaluated when someone fails to get or look at the object. In function references, 'me' refers to the object being looked at, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player doing the looking. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @idesc car = You are sitting in the driver's seat of a Volkswagen Beetle. See also: enter, @describe, ENTER_OK. & @idle Command: @idle <object> = <message> Attribute: Idle This attribute is sent as a message to anyone who successfully pages you. It can be used to tell someone who pages you when you will return (if you are going to be away for a while). This attribute is only meaningful for players, and will never be automatically referenced on other object types. If an @idletimeout is set on the person being paged, you will only see the @idle message if that person is more idle than the specified amount of time. Example: @idle me = At dinner. Back about 7PM. See also: @away, @idletimeout, @reject, page. & @idletimeout Command: @idletimeout <object> = <seconds> Attribute: IdleTimeout This attribute is used to determine if your @idle message is sent to a player who successfully pages you. If you're online and working at the same time, you can set the minimum idle time to allow your message to show. so whilst you're not idle your @idle message will not show without you having to delete it to hide it. This attribute is only meaningful for players, and will never be automatically referenced on other object types. Example: @idle me = Working IRL. Monitoring this window from time to time. @idletimeout me = 60 See also: @away, @idle, @reject, page. & @infilter Command: @infilter <object> = <pattern>[, <pattern>...] Attribute: Infilter This attribute specifies a series of patterns to be used to suppress text normally sent to the contents of <object> by @listen. If the desired pattern contains a comma, the pattern may be enclosed in curly braces {}. Example: > @listen sports car=* > @fo test=enter sports car test has left. test> Sports Car(#383Q) > :waves. test> Wizard waves. Wizard waves. > @infilter sports = *waves* > :waves. Wizard waves. > :knocks on the window. test> Wizard knocks on the window. Wizard knocks on the window. See also: @filter, @inprefix, @listen, @prefix. & @inprefix Command: @inprefix <object> = <prefix text> Attribute: Inprefix This attribute, when set, will prefix all text that is sent to the contents of <object> by @listen. The default is to have no prefix, the text is forwarded unadorned. Example: > @listen sports car=* > @fo test=enter sports car test has left. test> Sports Car(#383Q) > :waves. test> Wizard waves. Wizard waves. > @inprefix sports car = In the mundane world outside, test> In the mundane world outside, Wizard waves some more. Wizard waves some more. See also: @filter, @infilter, @listen, @prefix. & @kill Command: @kill <object> = <message> Attribute: Kill This command sets the message that is shown to anyone who kills <object>. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Function references and %-substitutions are allowed in kill messages, and are evaluated when someone kills the object. In function references, 'me' refers to the object that was killed, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player doing the killing. Example: @kill guard = The guard says "I'll get.. you... for... this... %n" as he falls down and dies. See also: kill, @akill, @okill, BEING KILLED, IMMORTAL, WIZARD. & @Lalias Command: @lalias <object> = <entrance-list> Attribute: Lalias Sets up a set of alternate commands that may be used as synonynms for the command 'leave' when you are inside a player or a thing. The alternate commands are separated by semicolons just like in exit names. Leave aliases are checked for after exitnames and builtin MUX commands, but before enter aliases and $-commands. This attribute is meaningful for players and things, and will never be automatically looked at on rooms or exits. Example: @lalias car = get out;climb out;out;open door;outside See also: @ealias, enter, leave. & @leave Command: @leave <object> = <message> Attribute: Leave Sets the message that a player sees when leaving an object or room, whether by using an exit, the enter or leave commands, or by teleporting. Function references and %-substitutions are allowed in leave messages, and are evaluated when someone leaves the object. In function references, 'me' refers to the object being left, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player leaving the object. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @leave car = You unbuckle your seatbelt and climb out of the car. See also: leave, @aleave, @oleave. & @lfail Command: @lfail <object> = <command-list> Attribute: Lfail Sets the message that a player sees when he tries to leave it but fails because the player fails the object's leave lock. The leave lock only affects the 'leave' command and its aliases (set via the @ealias command), it does not affect going home, using an exit in the location, or teleporting out. This attribute is meaningful for players and things, and will never be automatically triggered on rooms or exits. Example: @lfail plane = You don't have a parachute! See also: @aleave, @alfail, @lalias, @leave, @oleave, @olfail, leave. & @listen Command: @listen <object> = <string> Attribute: Listen This attribute contains a wildcard pattern that the object listens for. Anything spoken, posed, emitted, or whispered in the room that <object> is in, as well as messages resulting from using objects (such as Opay and Succ messages) are checked against the Listen attribute. When the object hears something that matches the pattern, it triggers the Ahear attribute, as well as either the Amhear or Aahear attributes, as appropriate, substituting %0 the string that matched the first wildcard character in the Listen, %1 for the second. etc. If the pattern in the Listen attribute is matched, objects in <object>'s inventory will also hear the message and have a chance to match it. Objects whose Listen attribute is set to anything will be listed when a @sweep command is run by someone in the same room. If the @listen pattern is matched, then the object's contents will hear the message also, prefixed by the text in @inprefix if it is set. Any text that matches any pattern specified in @infilter will not be sent to the contents. Example: @listen camera = * has arrived. @ahear camera = @va me = %va %0 See also: @aahear, @ahear, @amhear, @sweep, @inprefix, @infilter. & @move Command: @move <object> = <command-list> Attribute: Move Sets the message that an object sees after it moves from one location to another, whether by using an exit, entering or leaving an object, teleporting, or going home. This attribute is meaningful for players, and things and will never be automatically triggered on other object types. Example: @move bopper = OK. You're there now. See also: @amove, @omove. & @odescribe Command: @odescribe <object> = <message> Attribute: Odesc Sets the message (prefixed by the player's name) that is shown to others in the room when someone looks at <object>. Example: @odesc vase = carefully inspects the vase. See also: look, @adescribe, @describe, @idesc. & @odfail Command: @odfail <object> = <message> Attribute: Odfail Sets the message (prefixed by the player's name) that is shown to others in the same room when someone tries to drop <object> but fails because they didn't pass the object's drop lock. Function references and %-substitutions are allowed in drop failure messages, and are evaluated when someone drops the object. In function references, 'me' refers to the object being dropped, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the dropper. Example: @odfail sword = tries to put down the sword but it leaps back into %p hand. See also: drop, @adfail, @dfail, @lock. & @odrop Command: @odrop <object> = <message> Attribute: Odrop Sets the message (prefixed by the player's name) that is shown to others in the room when someone drops <object>, or to others in the room that the player arrives in after taking an exit. Example: <object> @odrop loadstone = puts down the loadstone and then wipes sweat from %p brow. <exit> @odrop elevator = enters the elevator from the lobby. See also: drop, @adrop, @drop, DROP-TO, EXITS. & @oefail Command: @oefail <object> = <command-list> Attribute: Oefail Sets the message (prefixed by the player's name) that is shown to others in the same room as the player when he tries to enter the object but fails because the object is not ENTER_OK or the player fails the object's enter lock. The enter lock only affects the 'enter' command and its aliases (set via the @ealias command), it does not affect exits that lead to the object or teleporting in. This attribute is meaningful for players and things, and will never be automatically triggered on rooms or exits. Example: @oefail car = tries to open the car's door, but it is locked. See also: @aefail, @aenter, @ealias, @efail, @enter, @oenter, enter, ENTER_OK. & @oenter Command: @oenter <object> = <message> Attribute: Oenter Sets the message (prefixed by the player's name) that is shown to others in the location being entered when someone enters <object>. Note that the message is shown to those inside the object, not those outside. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @oxenter wormhole = enters the wormhole from normal space. See also: enter, @aenter, @enter, @oxenter. & @ofail Command: @ofail <object> = <message> Attribute: Ofail Sets the others failure message for <object>. This message is seen others in the same location as the actor when one of these events occurs: - For exits: Someone tries to traverse the exit but cannot because they fail the exit's default lock or the exit is not linked. - For players and things: Someone tries to pick up the object but cannot because they fail the object's default lock. - For rooms, players, and things: Someone looks around inside the room, player, or thing and fails the object's default lock. Substitution and evaluation is performed on the message before it is shown. Examples: > @ofail table = tries to pick up the table, but it is too heavy. <thing> > @ofail doorway = tries the knob on the door, to no avail. <exit> See also: get, look, @afail, @fail, FAILURE. & @ogfail Command: @ogfail <object> = <message> Attribute: Ogfail Sets the message (prefixed by the player's name) that is shown to others in the same room when someone tries to give away <object> but fails because they didn't pass the object's give lock. Function references and %-substitutions are allowed in give failure messages, and are evaluated when someone tries to give away the object. In function references, 'me' refers to the object being given away, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the (attempted) giver. Example: @ogfail blob = tries to give away a sticky blob of goo. See also: give, @agfail, @gfail, @lock. & @okill Command: @okill <object> = <message> Attribute: Okill Sets the message (prefixed by the player's name) that is shown to others in the room when someone kills <object>. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @okill guard = bashes in the guard's skull, killing him. See also: kill, @akill, @kill, BEING KILLED, IMMORTAL, WIZARD. & @oleave Command: @oleave <object> = <message> Attribute: Oleave Sets the message (prefixed by the player's name) that is shown to others in the location being left when someone leaves <object>. Note that the message is shown to those inside the object, not those outside. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @oleave wormhole = departs the wormhole to return to normal space. See also: leave, @aleave, @leave, @oxleave. & @olfail Command: @olfail <object> = <command-list> Attribute: Olfail Sets the message (prefixed by the player's name) that is shown to others in the same room as the player when he tries to leave it but fails because the player fails the object's leave lock. The leave lock only affects the 'leave' command and its aliases (set via the @ealias command), it does not affect going home, using an exit in the location, or teleporting out. This attribute is meaningful for players and things, and will never be automatically triggered on rooms or exits. Example: @olfail plane = thinks about jumping out of the plane without a parachute, but wisely reconsiders. See also: @aleave, @alfail, @lalias, @leave, @lfail, @oleave, leave. & @omove Command: @omove <object> = <command-list> Attribute: Move Sets the message that others in the same location see after the object has moved to that location from somewhere else, whether by using an exit, entering or leaving an object, teleporting, or going home. This attribute is meaningful for players, and things and will never be automatically triggered on other object types. Example: @omove car = coasts to a stop. See also: @amove, @move. & @opay @opay <object> = <message> Attribute: Opay Sets the message (prefixed by the player's name) that is shown to others in the room when someone pays <object> enough to satisfy its Cost attribute. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @opay Coke machine = slips some change into the coin slot on the Coke machine. You hear some rumbling from inside the machine and a can of Coke appears in the tray at the bottom of the machine. See also: give, @cost, @apay, @pay. & @orfail Command: @orfail <object> = <message> Attribute: Orfail Sets the message (prefixed by the player's name) that is shown to others in the same room when someone tries to give <object> a thing that does not pass <object>'s receive lock. Function references and %-substitutions are allowed in receive failure messages, and are evaluated when someone tries to give away the object. In function references, 'me' refers to the intended recipient of the object, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the (attempted) giver. Example: @orfail merchant = tries to unload some worthless trash on Astinous. See also: give, @agfail, @arfail, @gfail, @ogfail, @rfail, @lock. & @osuccess Command: @osuccess <object> = <message>] Attribute: Osucc Sets the message (prefixed by the player's name) that is shown to others in the room when someone picks up the named player or thing, goes through the named exit, or looks at the room and passes the room's lock. Setting Osuccess messages on all takeable objects and usable exits is considered good building practice. Examples: <object> @osucc vase = carefully picks up the vase. <exit> @osucc doorway = opens the door and leaves the room. The door closes behind %o with a click. See also: get, look, @asuccess, @success, SUCCESS. & @otfail Command: @otfail <object> = <message> Attribute: Otfail Sets the message (prefixed by the player's name) that is shown to others in the same room when someone tries to teleport to somewhere he does not have permission. You do not see this message if they couldn't teleport out of their present location. Function references and %-substitutions are allowed in teleport failure messages, and are evaluated when someone attempts to teleport to the specified destination. In function references, 'me' refers to the teleport destination, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player attempting the teleport. When a player teleports another object (@tel <object>=<destination>), the lock is checked against the player, not the object. Example: @otfail here = thinks about teleporting to the Magic Room, but decides against it at the last moment. See also: @teleport, @atfail, @tfail, @lock. & @otofail Command: @otofail <object> = <message> Attribute: Otofail Sets the message (prefixed by the player's name) that is shown to others in the same room when someone tries to teleport out of somewhere they do not have permission. Function references and %-substitutions are allowed in teleport failure messages, and are evaluated when someone attempts to teleport from their location. In function references, 'me' refers to the player's location, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player attempting the teleport. Example: @otofail here = thinks about teleporting from the Magic Room, but decides against it at the last moment. See also: @teleport, @atofail, @tofail, @lock. & @otport Command: @otport <object> = <message> Attribute: Otport Sets the message (prefixed by your name) that others in the room to which the object goes see when the object teleports there. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @otport me = appears in a flash of non-wizardly brilliance. See also: @atport, @oxtport, @tport, @teleport. & @oufail Command: @oufail <object> = <message> Attribute: Oufail Sets the message that others in the same room see when someone tries to use object but fails the object's use lock. Note that the other functions controlled by the use lock (paying, listening, and $-commands) do not trigger Oufail. Example: @oufail robot = tries to activate the robot, but to no avail. See also: @aufail, @ufail, @use. & @ouse Command: @ouse <object> = <message> Attribute: Ouse Sets the message (prefixed by the player's name) that is shown to others in the room when someone uses <object>. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @ouse camera = takes a picture with the camera. See also: use, @ause, @use. & @oxenter Command: @oxenter <object> = <message> Attribute: Oxenter Sets the message (prefixed by the player's name) that is shown to others in the location being left when someone enters <object>. Note that the message is shown to those outside the object, not those inside. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @oxenter wormhole = climbs into the wormhole and vanishes. See also: enter, @aenter, @enter, @oenter. & @oxleave Command: @oxleave <object> = <message> Attribute: Oxleave Sets the message (prefixed by the player's name) that is shown to others in the location being entered when someone leaves <object>. Note that the message is shown to those outside the object, not those inside. This attribute is meaningful for players, things, and rooms, and will never be automatically triggered on exits. Example: @oxleave wormhole = steps out of a hyperspatial wormhole. See also: leave, @aleave, @leave, @oleave. & @oxtport Command: @oxtport <object> = <message> Attribute: Oxtport Sets the message (prefixed by your name) that others in the room from which the object comes see when the object teleports out. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @oxtport me = disappears in a flash of non-wizardly brilliance. See also: @atport, @otport, @tport, @teleport. & @pay Command: @pay <object> = <message> Attribute: Pay Sets the message that is shown to the player who gives <object> enough money to satisfy its Cost attribute. This attribute is only meaningful for things, and will never be automatically triggered on other object types. Example: @pay Coke machine = You slip some change into the slot. See also: give, @apay, @cost, @opay. & @prefix Command: @prefix <object> = <prefix text> Attribute: Prefix This attribute, when set, will be used as a prefix for all text forwarded by the 'audible' flag on an object or exit. The default if this attribute is not set is 'From <object name>,' for objects, and 'From a distance,' for exits. Example: > @fo test=out > @set #378=puppet test> test grows ears and can now hear. > :does something silly. Wizard does something silly. test> From a distance, Wizard does something silly. > @prefix out=From some strange place Set. > :does something even sillier. Wizard does something even sillier. test> From some strange place Wizard does something even sillier. See also: AUDIBLE, @filter, @forwardlist, @infilter, @inprefix. & @reject Command: @reject <object> = <message> Attribute: Reject This attribute is sent as a message to anyone who tries to page you but you have prevented them from paging you via your page lock (@lock/page). This attribute is only meaningful for players, and will never be automatically referenced on other object types. Example: @reject me = I _told_ you not to page me anymore... See also: @away, @idle, page. & @rfail Command: @rfail <object> = <message> Attribute: Rfail Sets the message that a player sees when he tries to give an object to someone else, but the receiver refuses to accept the object because the object didn't pass its receive lock. Function references and %-substitutions are allowed in receive failure messages, and are evaluated when someone tries to give away the object. In function references, 'me' refers to the intended recipient of the object, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the (attempted) giver. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @gfail merchant = The merchant doesn't want your worthless trash. See also: give, @agfail, @arfail, @gfail, @ogfail, @orfail, @lock. & @runout Command: @runout <object> = <command list> Attribute: Runout Sets the actions to be taken by <object> when another of its attributes is triggered (either automatically or via the @trigger command) and its Charges attribute is zero. When this occurs, the Runout attribute is run INSTEAD OF the attribute that would have run normally. Example: @runout magic wand = :fizzles and turns to dust.; @destroy me See also: @charges. & @sex Command: @sex <object> = <gender> Attribute: Sex Sets the gender for <object>, which is used to determine which pronouns to use when replacing %p, %o, %s, and %a parameters in messages that apply to <object>. Genders that start with M or m are considered male, those starting with F, f, W, or w are considered female, those starting with P or p are considered plural, and anything else is considered neuter. Example: @sex me = female @sex me = No thank you (Silly, but possible. Treated as neuter) See also: GENDER. & @startup Command: @startup <object> = <command list> Attribute: Startup Sets a list of commands to be performed by <object> when the game is started up. Typical actions include going home, cleaning visitors out of a room, resetting a puzzle or complex object to its initial state, or starting up an object that wants to run continuously. Example: @startup me = @vz me=MUX was last restarted at [time()]. @startup me = home & @success Command: @success <object> = <message> Attribute: Succ Sets the message that is shown to the player who successfully picks up the named player or thing, goes through the named exit, or looks at the room and passes the room's lock. Example: <object> @succ vase = You carefully pick up the delicate vase. <exit> @succ doorway = You open the door and walk through the doorway. See also: get, look, @asuccess, @osuccess, SUCCESS. & @tfail Command: @tfail <object> = <message> Attribute: Tfail Sets the message that a player sees when he tries to teleport to somewhere he does not have permission. You do not see this message if you couldn't teleport out of your present location. Function references and %-substitutions are allowed in teleport failure messages, and are evaluated when someone attempts to teleport to the specified destination. In function references, 'me' refers to the teleport destination, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player attempting the teleport. When a player teleports another object (@tel <object>=<destination>), the lock is checked against the player, not the object. Example: @tfail here = A psychic barrier prevents you from teleporting there. See also: @teleport, @atfail, @otfail, @lock. & @tofail Command: @tofail <object> = <message> Attribute: Tofail Sets the message that a player sees when he tries to teleport from somewhere he does not have permission. Function references and %-substitutions are allowed in teleport failure messages, and are evaluated when someone attempts to teleport out of their location. In function references, 'me' refers to the player's current location, while %-substitutions that refer to the enactor (such as %n, %#, %p, etc) refer to the player attempting the teleport. Example: @tofail here = A psychic barrier prevents you from teleporting out. See also: @teleport, @atofail, @otofail, @lock. & @tport Command: @tport <object> = <message> Attribute: Tport Sets the message that an object sees whenever it teleports. The message is displayed after the object moves to its new location. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @tport me = Hey! I teleported. Wow! See also: @atport, @otport, @oxtport, @teleport. & @ufail Command: @ufail <object> = <message> Attribute: Ufail Sets the message that someone sees when they try to use object but fail the object's use lock. Note that the other functions controlled by the use lock (paying, listening, and $-commands) do not trigger Oufail. Example: @ufail robot = The robot pointedly ignores you. See also: @aufail, @oufail, @use. & @use Command: @use <object> = <message> Attribute: Use Sets the message that is shown to the player who uses <object>. This attribute is only meaningful for players and things, and will never be automatically triggered on other object types. Example: @use camera = You take a picture with the camera. Click. See also: use, @ause, @ouse. & ABODE ABODE If a room is set ABODE, players can set their homes there, and can set the homes of objects there. It does not mean that a player can open an exit to that room, only that they can set their home there. & AUDIBLE Flag: AUDIBLE(a) (all types) When set on an object, player, or room everything from a say, pose, or emit inside the object will be sent to every object in the location of that object (except for rooms which have no location) as well as to all objects mentioned in the object's Forwardlist attribute. When set on an exit, everything from a say, pose, or emit in the room the exit is in will be forwarded to the room the exit points to. In both cases the @prefix attribute will be inserted in front of the text, or a default prefix if no @prefix attribute is set. If the @filter attribute is present, it will be used to suppress those messages matching any of the patterns specified. See also: @filter, @forwardlist, @prefix. & CHOWN_OK CHOWN_OK This flag, when set, allows you to transfer ownership to another player. To set it, you must be carrying the object. You also have to be in the room if you want to set this flag on rooms or exits. After this flag is set, the new player may gain ownership of the object by using the @chown command (See @chown). & CONNECTED CONNECTED This flag applies only to players and it shows if the player is connected or not. Thus, each time you are connected to the game, you should see the 'c' flag set, otherwise, you are DEAD! You cannot reset this flag, and it is used internally by the code for things like tabulating players for the WHO list, etc. & DARK DARK If a room is DARK, then no items are shown when a person 'looks' there. If a thing is DARK, then "look" does not list that object in the room's Contents:, and if an exit is DARK, it doesn't show up in the Obvious Exits: list. Puppets and objects that can listen cannot be DARK. & DESTROY_OK DESTROY_OK When set on an object, it allows any player to destroy it as long as the object is not locked against them. This is good for things like notes, whereby the recipient can destroy the note after reading it, instead of having to look for you to destroy it. The DESTROY_OK flag overrides the SAFE flag, so that you do not need to give the /override switch to @destroy to destroy a thing that is both DESTROY_OK and SAFE. When it is set on any object or the owner of that object, that object is destroyed immediately, without delay. See also: @destroy, SAFE. & ENTER_OK ENTER_OK If an object or person is ENTER_OK, other players may enter the object or person by using 'enter <object/person>. Players must also have the ENTER_OK set if they wish to be able to receive things given to them by other players via the 'give <player> = <object>'. & GAGGED GAGGED When a player is set GAGGED, they cannot speak or pose under any circumstances. This flag has no meaning for objects, exits, or rooms. & GOING GOING Used internally for the @destroy command, it is set on rooms that are set to be destroyed. In the event that a player decides they don't want to destroy the room after all then they can unset it. & HAVEN HAVEN @set here=haven;@set me=haven. If a location is HAVEN, you cannot kill in that location. The HAVEN flag no longer blocks pages or @pemits, use @lock/page instead. See also: @lock/page. & KEY KEY When set on an object prevents puppets from picking it up. & LINK_OK LINK_OK If a room is LINK_OK, anyone can link exits to it (but still not from it). It has no meaning for people, things, or exits. See @link. & UNFINDABLE If a player is set UNFINDABLE, he cannot be found by the loc() or room() functions. If a room is set UNFINDABLE, players in that room (or inside objects in the room) cannot be found by loc()/room(). & FLOATING If a room is set floating, you will not be notified every 10 minutes or so that you have a disconnected room. & OPAQUE OPAQUE When set on a player, it prevents other players from seeing what you are carrying in your inventory. Only exception is when the object you are carrying belongs to the other player looking at you. & PLAYER PLAYER The PLAYER flag identifies you as a player. This flag cannot be reset by any player, not even a Wizard (not, yet, anyway *grin*). It is used mainly by the MUX code to identify your commands, check for validity of commands or locks etc. Generally, just pretend it isn't even there. & JUMP_OK When a room or thing is set JUMP_OK, then that location can be teleported into by anyone. See @teleport. & PUPPET PUPPET @set <object> = puppet. Causes an object to grow eyes and ears, and relay all it sees and hears to its owner. See: @force, PUPPETS & ROOM ROOM This flag is automatically set on rooms when you @dig a new room. It cannot be changed. Rooms have the added advantage that they can be saved from destruction by setting the room to !GOING (SEE GOING). However, this can only be done if no other room/object was created that overwrote your room when it was set for destruction. & VISUAL VISUAL The flag a lot of players have been waiting for. When set on your object, it allows other players to examine it and see all the object's attributes as if they owned the object. They cannot make any changes to the object. & VACATION VACATION This flag can only be set by wizards. It is usually used to mark players who will be inactive for a long period of time. It is automatically cleared when the character logs on. & QUIET QUIET This flag when set on yourself prevents you from hearing the 'set' or 'triggered' messages from any objects you own. When set on an object, only that object will not relay its messages. & HALTED HALTED While this flag is set, the object cannot perform any MUX actions, listen, be triggered, etc. & STICKY STICKY If a thing is STICKY, it goes home when dropped (See HOMES). If a room is STICKY, its drop-to is delayed until the last person leaves (See DROP-TOs). Only meaningful for things and rooms. & TEMPLE Flag: TEMPLE The TEMPLE flag is no longer a part of TinyMUX. & ROYALTY ROYALTY If a person is ROYALTY, they can see and examine things, and teleport anywhere or anything, like a wizard can. They cannot modify objects or players they do not control, and cannot use wizard commands. This flag may only be set by a wizard. & AUDITORIUM AUDITORIUM When set on a room, object, or player, it enables the checking of speechlocks. & STAFF STAFF This flag can be used to mark players who serve as staff on the MUX. It is wizard-settable only. & ANSI ANSI When set on a player, it will enable the player to see ANSI color. If you have TinyFugue and you do not wish to see ANSI color, please leave this flag set and /set catch_ctrls=ansi. The reason for this is when the ANSI flag is unset, the server must go through every line of text you see and strip the ANSI codes from it. With the ANSI flag set and /set catch_ctrls=ansi, TinyFugue will strip the ANSI and save the MUX from having to do it, resulting in less lag for everyone. See also: ansi(), NOBLEED. & NOBLEED NOBLEED When set on a player, it will append an ANSI white character to the normal ANSI 'normal' character, so it will fix ANSI color 'bleed' on most terminals. (Bleed occurs when a color extends into text it was not meant to.) Do not set this flag unless you have to, it tends to slow down the text display for the MUX. & HEAD HEAD This is another marker flag, for faction heads and the like. As with STAFF, no powers come with it, it is purely a marker. & FIXED FIXED No object may teleport or go home when this flag is set. This flag may only be set by a wizard. If set on a player, neither they nor any of their objects may teleport or go home. & UNINSPECTED UNINSPECTED This flag is typically set on rooms that need to be inspected for good building practices. This flag may only be set by wizards and royalty. & no_command NO_COMMAND The NO_COMMAND flag disables the checking of $-commands on an object. Most MUXes will be configured to automatically set this flag on rooms and players. The server runs faster when fewer objects are checked for $-commands; thus, any object which does not have $-commands on it should be set NO_COMMAND. & ANSI() ansi(<codes>,<string>) This allows you to highlight a string using ANSI terminal effects. The string is terminated with a "return to normal" code, and the codes are utilized in the order they are specified. The codes are: f - flash i - inverse h - hilite n - normal x - black foreground X - black background r - red foreground R - red background g - green foreground G - green background y - yellow foreground Y - yellow background b - blue foreground B - blue background m - magenta foreground M - magenta background c - cyan foreground C - cyan background w - white foreground W - white background For example, "ansi(fc, Test)" would hilight "Test" in flashing cyan. { 'help ansi2' for more } & ANSI2 The percent substitution %c<color code> can be used instead of ansi(), and is more efficient. For example, the equivalent to [ansi(rBf,Color!)] would be: %cr%cB%cfColor!%cn The %cn (to return to normal) is not necessary, but if it is not specified the ansi color codes will continue to the end of the string. See also: ANSI & BUILDER BUILDER The BUILDER flag has been changed into a power. See power list. & WIZARD WIZARD If a person is WIZARD, they are a wizard, unkillable, subject to fewer restrictions, and able to use wizard commands. In general, WIZARDs can do anything using #<number> or *<player>. Only player #1 can set and unset the WIZARD flag of other players. No WIZARD can turn their own WIZARD flag off. & IMMORTAL IMMORTAL Objects set immortal cannot be killed and don't use up money. Only settable by wizards. This is useful when an object's location shouldn't be changed by Joe Player, but you don't want to have to relink it to its current location whenever it moves. & VERBOSE VERBOSE This flag causes all commands executed by the object having the flag to be sent to the owner of the object. i.e.: @create foo @set foo=VERBOSE @force foo="Hi. foo] "Hi. foo says "Hi." See also: TRACE & INHERIT INHERIT Previously, Wizard-owned objects had wizard powers. This was a problem in many cases, so that behavior has changed. Now, only Wizard objects or Wizard-owned Inherit-set objects have wizard powers. Only players can set the Inherit flag, and the Inherit flag is reset during @chown. If a player is set Inherit, all his stuff is assumed to be inherit, so his objects can control him. If a player is NOT Inherit, his stuff does NOT control him. (i.e. cannot @force him.) This flag is not especially useful for non-wizards. & MONITOR Flag: MONITOR(M) Objects: When set, anytime the object hears something from someone who passes the object's use lock, the object's attributes are scanned for attributes of the form '^<pattern>:<commandlist>'. If the message matches the wildcarded <pattern>, then <commandlist> is executed, substituting %0 for the text that matched the first wildcard, %1 for the second, and so on. All matching attributes are executed, not just the first. Parents of MONITOR objects are never checked for ^-patterns. Players: When set on a player, this flag notifies that player whenever someone connects or disconnects from the MUX. It is valid only for players, and must be set by a wizard. See also: LISTENING. & TRACE Flag: TRACE(T) When a thing is set TRACE, it will report to its owner the result of all substitutions that it performs that change the original string. The order for displaying nested evaluations (such as when evaluating the arguments to a function) is a site-selected configuration parameter. Example: > @set object = trace > @va object = say The result is [add(4,mul(3,%0))]. > @trig object/va = 7 object(#322)} '%0' -> '7' object(#322)} 'mul(3,%0)' -> '21' object(#322)} 'add(4,mul(3,%0))' -> '25' object(#322)} 'The result is [add(4,mul(3,%0))].' -> 'The result is 25.' object says "The result is 25." { 'help trace2' for more } & trace2 When trace output is displayed in top-down order (final evaluation first, followed by the 'smaller' evaluations needed to perform it), then the total number of trace ouput lines that may be produced by an evaluation is limited to 200. Bottom-up trace output is not limited. See also: VERBOSE. & NOSPOOF Flag: NOSPOOF(N) This flag gives you mucho output when people @emit. It can be annoying, but you'll know who's spoofing. See also: @emit, @femit, @oemit, @pemit. & PARENT_OK Flag: PARENT_OK(Y) If an object is set PARENT_OK, then any other object that passes the object's ParentLock may make this object a parent of any object that it controls. Caution: allowing others to use your objects as parents lets them read the attributes on the object (as well as any parents of the object). See also: @lock/parent. & LIGHT Flag: LIGHT(l) An object or exit that is set LIGHT is visible even when inside a DARK location. If an object is set both DARK and LIGHT, then its contents are visible even though the object itself is not. & MYOPIC Flag: MYOPIC(m) If you are set MYOPIC, then you are treated as if you did not own anything when you use the LOOK command or when you automatically look at a location when entering it. Other commands (such as EXAMINE) are not affected. & TERSE Flag: TERSE(q) If you are set TERSE then you are not shown the description, success/failure messages, contents, or exits of locations you enter. You must use the LOOK or EXAMINE commands to see this information. Others in the location still get the osucc/ofail messages and the asucc or afail command list is still run. See also: examine, look. & ROBOT Flag: ROBOT(r) If set on a player, indicates that the player is a robot and is allowed to use the OUTPUTPREFIX and OUTPUTSUFFIX commands that many publicly available robot programs require. Some MUXes do not restrict access to the OUTPUTPREFIX and OUTPUTSUFFIX commands. If set on an exit or a thing, indicates that robot players may not use the exit or pick up the thing, the player is treated as having failed the lock. See also: OUTPUTPREFIX, OUTPUTSUFFIX, @robot. & SAFE Flag: SAFE(s) When set, requires the use of the /override switch to @destroy in order to destroy the object. It does not prevent the destruction of the object, but merely requires some additional effort. If a thing is set DESTROY_OK, its SAFE flag is ignored and it may be destroyed without using the /override switch. See also: @destroy, DESTROY_OK. & TRANSPARENT Flag: TRANSPARENT(t) If an exit is TRANSPARENT, then when you look at it you see the description of the room on the other side of the exit in addition to the description of the exit. When a room is TRANSPARENT, you see a 'long' listing of exits, including their destinations. & SLAVE Flag: SLAVE(x) If set on a player, neither the player nor any of his objects may perform any commands that change the database. Some sites may restrict additional commands. This flag may only be set or cleared by wizards. & ARBITRARY COMMANDS Topic: ARBITRARY COMMANDS You may define commands that are triggered whenever someone enters a command that matches the command template (wildcarding allowed). These commands are called arbitrary commands, user-defined commands, or $-commands (for how they are defined), and they are checked for only after the check for single-character commands, exits, and internal commands have been performed and have failed (so an arbitrary command that matches 'page *' will never be performed). You define an arbitrary command by storing a string of the form '$<template>:<commandlist>' in an attribute of an object, then the command will be available to anyone who carries the object, is in the same room as the object, or is inside the object. Only use user-named attributes and VA-VZ for arbitrary commands, as many of the predefined attributes are not for arbitrary commands. <template> is the pattern to check for (it may contain wildcards), and <commandlist> is a semicolon-separated list of commands to perform. The text that the wildcard characters matched are available in the variables %0 through %9. { 'help arbitrary2' for more } & arbitrary2 Example: > @va testobj = $foobar *:"I was foobar'ed with %0. Set. > foobar xyzzy testobj says "I was foobar'ed with xyzzy" You can prevent individual attributes from being checked for $-commands with the command '@set <obj>/<attr> = no_program'. Attributes so set are reported with ($) following the attribute name when examined. The command '@set <obj>/<attr> = !no_program' clears the flag. You can also match a regular expression rather than wildcards. See 'help Regular Expressions' for details. The following attributes are never checked for $-commands: ALIAS CHARGES DESC DROP FAIL IDESC ODESC ODROP OFAIL OSUCC SEX SUCC. See also: @set. & REGEXPS Topic: REGEXPS (Regular Expressions) The majority of matching in MUSH is done with wildcard ("globbing") patterns. There is a second type of matching, using regular expressions, that is available in certain circumstances. For attributes that are $-commands or ^-listen-patterns, setting that attribute "regexp" (with '@set <object>/<attribute>=regexp') causes patterns to be matched using regular expressions rather than globbing. In a regular expression match, the substring of the string which matched the regexp pattern is %0; %1 through %9 are the substrings of the string which matched parenthesized expressions within the regexp pattern. Continued in 'help regexps2'. & REGEXPS2 Regular expressions are extremely useful when you want to enforce a data type. For example, if you have a command where you want a player to enter a string and a number ('+setnum <player>=<number>', for example), you might do it like this: &DO_NUM Command Object=$+setnum (.+)=([0-9]*): @va me=Data: %1 = %2 @set Command Object/DO_NUM = regexp Then, '+setnum cookies=30' would set VA to "Data: cookies = 30". This eliminates your having to check to see if the player entered a number, since the regular expression matches only numbers. Furthermore, the '+' guarantees that there needs to be at least one character there, so a player can't enter '+setnum cookies=' or '+setnum =10' or similarly malformed input. Also note that regexps are case-sensitive, but wildcard globbing is not. Regular expression syntax is explained in 'help regexp syntax'. & REGEXP SYNTAX Topic: REGEXP SYNTAX The following explanation is taken from Henry Spencer's regexp(3) package, the regular expression library used in TinyMUSH 2.2. A regular expression is zero or more branches, separated by `|'. It matches anything that matches one of the branches. A branch is zero or more pieces, concatenated. It matches a match for the first, followed by a match for the second, etc. A piece is an atom possibly followed by `*', `+', or `?'. An atom followed by `*' matches a sequence of 0 or more matches of the atom. An atom followed by `+' matches a sequence of 1 or more matches of the atom. An atom followed by `?' matches a match of the atom, or the null string. Continued in 'help regexp syntax2'. & REGEXP SYNTAX2 An atom is a regular expression in parentheses (matching a match for the regular expression), a range (see below), `.' (matching any single character), `^' (matching the null string at the beginning of the input string), `$' (matching the null string at the end of the input string), a `\' followed by a single character (matching that character), or a single character with no other significance (matching that character). A range is a sequence of characters enclosed in `[]'. It normally matches any single character from the sequence. If the sequence begins with `^', it matches any single character not from the rest of the sequence. If two characters in the sequence are separated by `-', this is shorthand for the full list of ASCII characters between them (e.g. `[0-9]' matches any decimal digit). To include a literal `]' in the sequence, make it the first character (following a possible `^'). To include a literal `-', make it the first or last character. Continued in 'help regexp ambiguity' and 'help regexp examples'. & REGEXP AMBIGUITY Topic: REGEXP AMBIGUITY If a regular expression could match two different parts of the input string, it will match the one which begins earliest. If both begin in the same place but match different lengths, or match the same length in different ways, life gets messier, as follows. In general, the possibilities in a list of branches are considered in left-to-right order, the possibilities for `*', `+', and `?' are considered longest-first, nested constructs are considered from the outermost in, and concatenated constructs are considered leftmost-first. The match that will be chosen is the one that uses the earliest possibility in the first choice that has to be made. If there is more than one choice, the next will be made in the same manner (earliest possibility) subject to the decision on the first choice. And so forth. Continued in 'help regexp ambiguity2'. & REGEXP AMBIGUITY2 For example, `(ab|a)b*c' could match `abc' in one of two ways. The first choice is between `ab' and `a'; since `ab' is earlier, and does lead to a successful overall match, it is chosen. Since the `b' is already spoken for, the `b*' must match its last possibility-the empty string-since it must respect the earlier choice. In the particular case where no `|'s are present and there is only one `*', `+', or `?', the net effect is that the longest possible match will be chosen. So `ab*', presented with `xabbbby', will match `abbbb'. Note that if `ab*' is tried against `xabyabbbz', it will match `ab' just after `x', due to the begins-earliest rule. (In effect, the decision on where to start the match is the first choice to be made, hence subsequent choices must respect it even if this leads them to less-preferred alternatives.) & REGEXP EXAMPLES Topic: REGEXP EXAMPLES The regexp pattern '.' is equivalent to the wildcard '?'; it matches one and only one of an arbitrary character. The regexp pattern '.+' is equivalent to the wildcard '*'; it matches one or more arbitrary characters. To match zero or more arbitrary characters, the regexp pattern is '.*'. To match a string of numbers, use: [0-9]+ To match a string of letters only, use: [A-Za-z]+ See 'help regexp syntax' for a more detailed explanation. & ATTRIBUTE OWNERSHIP Topic: ATTRIBUTE OWNERSHIP The attributes on an object may be owned independently from the object. Normally, the owner of the object owns all of its attributes. In addition to an owner, each attribute also has a locked flag, set or cleared with @lock <obj>/<attr> and @unlock <obj>/<attr>. This flag controls whether or not the owner of the object may @chown the attribute to himself with @chown <object>/<attrib>, as well as whether or not the attribute is automatically @chowned to the new owner when the object is @chowned. You may lock and unlock attributes that you own on any object (whether you own the object or not), and you may @chown an attribute that you own to the owner of the object if it is unlocked. The examine command will show you all attributes that you own on an object, even if you don't own the object. { 'help attrib2' for more } & attrib2 Locked attributes may not be modified or removed, and do not change ownership when the object containing them is @chowned. You may not modify or remove attributes that you own that are stored on objects that you do not own, but you may modify or remove attributes owned by others on your objects (if you do this, the attribute becomes owned by you). If an attribute is owned by someone other than the object's owner, then the number of the attribute's owner is shown in parentheses immediately after the attribute name. If there are any flags set on the attribute, those flags are indicated in the parentheses too. The + flag means means that the attribute is locked (so that it will not change ownership of the object is @chowned), the $ flag means that $-commands are not checked for that attribute. The I flag indicates that the attribute is not inherited by children of the object, and the V flag shows that the attribute is publically visible. { 'help attrib3' for more } & attrib3 When checking an attribute lock against an object, the lock will always fail if the locked object is not owned by the same player as the attribute being tested. The comparison specified in the lock is only performed if the owner of the locked object also owns the attribute on the object being checked. See also: @chown, @lock, @set, @unlock, examine. & BEING KILLED Topic: BEING KILLED Getting killed is no big deal. If you are killed, you return to your home, and all things you carry return to their homes. You also collect 50 coins in insurance money (unless you have >= 10000 coins or you were killed via the Wizard slay command). Generally, killing is not encouraged unless absolutely necessary. (Note: Killing a wizard is a quick way to discover the many uses of the @boot command... and killing anyone can be very rude.) See also: kill, @akill, @kill, @okill, IMMORTAL, WIZARD. & BOGUS COMMANDS Topic: BOGUS COMMANDS Bogus commands can be made using exits. For example, to make a 'sit' command, one could "@open sit", then "@link sit=here" (because unlinked exits can be stolen), "@lock sit=#0" (impossible for a room to pass a lock, #0 is always a room, therefore the lock always fails), and "@fail sit=You sit on the chair."; "@ofail sit=sits on the chair.". Since nobody can go through it, it always fails. The @fail message is displayed to the player, and the @ofail message (preceded by the player's name) to everyone else. See also: @afail, @fail, @link, @lock, @ofail, @open. & BOOLEAN VALUES Topic: BOOLEAN VALUES Boolean values are internally considered to be either 1, generally interpreted as being true, and 0, which is generally interpreted as being false. Now, any string is interpreted as true(1), except for the null string (whose length is 0), which is false(0). A #-1 is interpreted as false(0), and any other #<dbref> is interpreted as true(1). Any number except 0 is interpreted as true(1), except 0 which is false(0). (Yes, even negative numbers are true(1)) Examples: not(foo) = 0 not(<null string>) = 1 not(-66) = 0 not(0) = 1 not(#-1) = 1 not(#12) = 0 And so on... Note: These rules only apply when a function expects a Boolean value, not for strings that expect other values. & CONTROL Topic: CONTROL There are 6 rules to controlling objects: 1) You control anything you own. 2) Anything you own that has its INHERIT flag set controls anything you own (including you). 3) Anything you own that does not have its INHERIT flag set only controls other things that you own that do not have their INHERIT flag set and do not control you, unless YOU have your inherit flag set. 4) A wizard controls everything. 5) Anybody controls an unlinked exit, even if it is locked. 6) The object is in a part of a zone tree that you control. Builders should beware of 5, lest their exits be linked or stolen. Most of the commands for altering the database and many commands and functions that retrieve information only work on objects that you control. & COSTS Topic: COSTS Certain commands cost money to use, they will fail if you don't have enough. Use the @list costs command to find out what these commands are and how much they cost. See also: @list. & CREDITS Topic: CREDITS TinyMUX 1.0 is derived from TinyMUSH 2.0.10 patchlevel 6. It is maintained by Lauren (Children of the Atom) and would not exist without the generous contributions of many individuals. Ideas for features (and occasionally code) came from many places, including TinyMUSE, and PennMUSH. We would like to thank the following people: - Dave Peterson (Evinar) who maintained TinyMUSH 2.0 in its later incarnations. - James Callahan (Darkenelf), who contributed many patches, and ideas (@teleport/quiet, @readcache fixes, side effect functions, many bug fixes) - Chris (Children of the Atom) who had many, many, many ideas and found many, many, many bugs, in his own gleeful manner of crashing our site. - Alan Schwartz (Javelin/Paul) and Lydia Leong (Amberyl), whose extended mailer from PennMUSH is the basis for MUX's @mail system. Also, Brandy (CrystalMUSH) who's +mail system inspired many of the features. - Ethaniel and Kayan Telva (BTech3056) for the basic comsystem and macro code. (continued in 'CREDITS2') & CREDITS2 - Kalkin(DarkZone) and Harlock(StarWarsII) who extended the comsystem and added tons of new commands, which is basically unchanged here. - Kalkin(DarkZone) for writing the mail alias and guest code. - Mike(StarWars), idea for not saving GOING objects. Following is the original credits for TinyMUSH 2.0: TinyMUSH 2.0 is derived from Larry Foard's TinyMUSH (which was itself derived from TinyMUD, written by Jim Aspnes). Ideas for features (and occasionally code) came from many places, including TinyMUSE, PernMUSH, and TinyTIM. We would like to thank the following people: - Jim Aspnes, for the original TinyMUD (from which TinyMUSH was derived) - Larry Foard, for the original implementation of TinyMUSH. (continued in 'CREDITS3') & CREDITS3 - Marcus Ranum for the original Untermud database layer code, and Andrew Molitor for getting it to work with TinyMUSH. - Andrew Molitor (again) for the VMS port. - Russ(Random) and Jennifer(Moira) Smith, for ideas, comments, and coding help. - R'nice(TinyTIM) for more good ideas than we could shake a wand of coding at. (@doing, @edit enhancements, a REAL use command, lotsa minor fixes and tweaks) - Coyote(TinyTIM, DungeonMUSH, NarniaMUSH), for finding some nasty bugs and NOT using them for evil purposes. - Ambar, Amberyl, Sh'dow, Jellan, and Miritha (all from PernMUSH) for numerous bug fixes, enhancements, and ideas. - Sketch(TinyTIM) for rewriting some of the more confusing help file entries. - Hcobb(TinyTIM) and Furie(DungeonMUSH) for inspiring the parser rewrite and other security-related fixes and enhancements. - The many other people who have contributed ideas, comments, or complaints about bugs. & DROP-TOS Topic: DROP-TOS When the @link command is used on a room, it sets a drop-to location. Any object dropped in the room (if it isn't STICKY) will go to that location. If the room is STICKY, the drop-to will be delayed until the last person in the room has left. See also: @link, STICKY. & ENACTOR Topic: ENACTOR The enactor is the object that caused an action list to be performed. So, the enactor of the Ahear action list is the player or object who said/emoted/etc the message that matched the Listen attribute, the enactor of the Apay attribute is the player who gave the object money, etc. The enactor of an attribute that is run by a @trigger command is the object that ran the @trigger command. The following substitutions can be performed in an action list to return information about the enactor: %# or [v(#)] - Database number of the enactor %N/%n or [v(N)]/[v(n)] - Name of the enactor. %O/%o ... - Objective pronoun for the enactor (him her it them) %P/%p ... - Possessive pronoun (his her its their) %S/%s ... - Subjective pronoun (he she it they) %A/%a ... - Absolute possessive pronoun (his hers its theirs) See also: SUBSTITUTION. & MOVING Topic: MOVING A number of things happen when you leave one location and enter another (assuming you pass the lock on the exit or have permission to enter the object or to teleport to the location). The following list describes the actions that MUX takes when an object moves from one place to another. Note that if an indicated attribute is not set, no message is displayed (or no action is performed). - If you are using an exit (as opposed to teleporting, entering an object, or going home), You receive the SUCC message for the exit, others in the old location receive the exit's OSUCC message, and the exit runs its ASUCC action list. - If you are teleporting or being teleported, others in the old location receive your OXTPORT attribute. - If you are a player or have your LISTEN attribute set to something, and if the old location is not dark and you are not dark, you receive the LEAVE message for the old location, others in the old location receive the OLEAVE message, and the old location runs its ALEAVE action list. Others in the new location receive the OXENTER message from the old location, and others in the old location receive the message '<yourname> has left.' { 'help moving2' for more } & moving2 - You are moved to the new location. If you are entering an object, teleporting, or going home, all KEY objects are stripped from you. - If the new location is a room, you receive the room's DESC, others in the room receive the ODESC, and the room runs its ADESC. If you pass the room's lock do the same with SUCC, OSUCC, and ASUCC, otherwise use FAIL, OFAIL, and AFAIL. - If the new location is a player or an object, you receive the location's IDESC (or DESC if the IDESC is not set). In either event, others in the same location see the ODESC message and the location runs its ADESC action list. - You are shown the contents and visible exits if the location is not DARK. - If you used an exit, then you receive the DROP message for the exit, others in the new room receive the exit's ODROP message, and the exit runs its ADROP action list. - If you are teleporting or being teleported, you receive your TPORT attribute, others in your new location receive your OTPORT attribute, and your ATPORT attribute is run. - You receive your MOVE attribute, others in your new location receive your OMOVE attribute, and your AMOVE attribute is run. { 'help moving3' for more } & moving3 - If you are a player, or have your LISTEN attribute set to something, and if the old location is not dark and you are not dark, you receive the ENTER message for the new room, others in the new room receive the OENTER message, and the new room runs its AENTER action list. Others in the room you just left receive the new room's OXLEAVE message, and others in the old location receive the message '<yourname> has arrived.' - If the old location is a STICKY room and has its drop-to set, see if objects in that room should be sent to the drop-to location. If so, do it. - If you are a player, you have a chance of finding some money. See also: @adesc, @adrop, @aenter, @afail, @aleave, @asucc, @atport, @desc, @drop, @enter, @fail, @leave, @listen, @odesc, @odrop, @oenter, @ofail, @oleave, @osucc, @oxenter, @oxleave, @oxtport, @succ, @tport, move, @teleport, home, KEY, STICKY, DROP-TOS, FAILURE, SUCCESS. & EXITS Topic: EXITS An exit links one location to another location, providing a way to travel on the MUX. Although normally used to link rooms together, exits can be made to and from players and objects. You may pick up exits that you own, and drop exits into locations that you own. When you pick up or drop an exit, anyone in the exit's new location may use the exit and travel to its destination. If an exit is set DARK it will not show up in the list of obvious exits in a room. See also: @link, @open. & FAILURE Topic: FAILURE You fail to use a player or a thing when you cannot take it (because it's lock fails). You fail to use an exit when you cannot go through it (because it is unlinked or locked). You fail to use a room when you fail to look around (because it's locked). See also: get, look, @afail, @fail, @lock, @ofail, STRINGS. & FLAGS Topic: FLAGS Everything in the universe of this MUX (Rooms, Exits, Things, Players, etc) are represented in the same way at the program level. A room merely has the room flag set and a player has the player flag set. In addition, flags also give objects abilities or qualities. For instance, a wizard has the wizard flag set. That is what lets the program know he may use wizard abilities. An object or room may have the dark flag set. In the case of an object, this makes the object invisible to normal eye-sight. In the case of a room, the room becomes too dark to see other objects or players. To get a list of the flags that are available, type '@list flags' or 'help flag list'. For more specific information on a particular flag, request help on the flag's name, as in 'help ENTER_OK'. & FLAG LIST Topic: FLAG LIST Flag Title Flag Title Flag Title Flag Title ------------------------------------------------------------------------- A - ABODE | C - CHOWN_OK | D - DARK | E - EXIT F - FLOATING | G - GOING | H - HAVEN | I - INHERIT J - JUMP_OK | K - KEY | L - LINK_OK | M - MONITOR N - NOSPOOF | O - OPAQUE | P - PLAYER | Q - QUIET R - ROOM | S - STICKY | T - TRACE | U - UNFINDABLE V - VISUAL | W - WIZARD | X - ANSI | Y - PARENT_OK Z - ROYALTY | a - AUDIBLE | b - AUDITORIUM | c - CONNECTED d - DESTROY_OK | e - ENTER_OK | f - FIXED | g - UNINSPECTED h - HALTED | i - IMMORTAL | j - GAGGED | l - LIGHT m - MYOPIC | n - NO_COMMAND | p - PUPPET | q - TERSE r - ROBOT | s - SAFE | t - TRANSPARENT| u - SUSPECT v - VERBOSE | w - STAFF | x - SLAVE | z - CONTROL_OK | ? - HEAD | - - NOBLEED | | - VACATION ------------------------------------------------------------------------ Realms Patch Flags: o - OBF | k - HSS | y - UMBRA | $ - SHROUD / - MATRIX | ^ - MEDIUM | _ - DEAD | 0 - FAE 1 - CHIMERA | 2 - PEERING | | ------------------------------------------------------------------------ For information on a particular flag, type 'help <flagname>'. Some flags may be disabled at the MUX you are located. & FUNCTIONS Topic: FUNCTIONS Functions are specialized commands used to manipulate strings and other input. The format for a function is of this form: [fun-name(<input>)] Although usually the []'s indicate an input that is optional, in this case they are necessary and tell the MUX that this is a function, although nested functions (like [first(rest(This is a nice day))] returns 'is') do not require more than one pair of []'s. Nested brackets may be used when it is necessary to insert a function call in the middle of an argument, like [get(me/[get(me/vz)])], which returns the contents of the attribute named in the VZ attribute. For help on a particular function, type 'help <functionname>'. You may need to include the parentheses with the function name, ie. 'help <functionname>()'. Type 'help function list' or '@list functions' for a list of the available functions. 'help function classes' will show a list of the functions broken down into classes. See also: @list functions, FUNCTION CLASSES, FUNCTION LIST. & FUNCTION LIST Topic: FUNCTION LIST Help is available for the following functions: ABS() ACOS() ADD() AFTER() ALPHAMAX() ALPHAMIN() AND() ANDFLAGS() ANSI() APOSS() ART() ASIN() ATAN() BAND() BEEP() BEFORE() BNAND() BOR() CAPSTR() CASE() CAT() CEIL() CENTER() CHANNELS() CHILDREN() CMDS() COLUMNS() COMALIAS() COMP() COMTITLE() CON() CONN() CONNLAST() CONNLEFT() CONNMAX() CONNNUM() CONNTOTAL() CONTROLS() CONVSECS() CONVTIME() COS() CREATE() CWHO() DEC() DECRYPT() DEFAULT() DELETE() DIE() DIGITTIME() DIST2D() DIST3D() DIV() DOING() E() EDEFAULT() EDIT() ELEMENTS() ELOCK() EMPTY() ENCRYPT() EQ() ESCAPE() EXIT() EXP() EXPTIME() EXTRACT() EVAL() FDIV() FILTER() FINDABLE() FIRST() FLAGS() FLOOR() FOLD() FOREACH() FULLNAME() GET() GET_EVAL() GRAB() GREP() GREPI() GT() GTE() HASATTR() HASATTRP() HASFLAG() HASPOWER() HASTYPE() HOME() IADD() IDIV() IDLE() IFELSE() IMUL() INC() INDEX() INSERT() INZONE() ISDBREF() ISNUM() ISUB() ISWORD() ITER() ITEMS() LAST() LATTR() LATTRCMDS() LCMDS() LCON() LCSTR() LDELETE() LEXITS() LFLAGS() LIST() LIT() LJUST() LN() LNUM() LOC() LOCATE() LOCK() LOG() LPARENT() LPOS() LSTACK() LT() ("help function list2" for more) & FUNCTION LIST2 LTE() LWHO() MAIL() MAILFROM() MAP() MATCH() MATCHALL() MAX() MEMBER() MERGE() MID() MIN() MIX() MOD() MONEY() MOTD() MUDNAME() MUL() MUNGE() NAME() NEARBY() NEQ() NEXT() NOT() NUM() OBJ() OBJEVAL() OBJMEM() OR() ORFLAGS() OWNER() PARENT() PARSE() PEEK() PEMIT() PI() PLAYMEM() PMATCH() POLL() POP() PORTS() POS() POSS() POWER() PUSH() R() RAND() REGMATCH() REMOVE() REPEAT() REPLACE() REST() REVERSE() REVWORDS() RJUST() RLOC() ROOM() ROUND() S() SCRAMBLE() SEARCH() SECS() SECURE() SET() SETDIFF() SETINTER() SETQ() SETR() SETUNION() SHL() SHR() SHUFFLE() SIGN() SIN() SINGLETIME()SORT() SORTBY() SPACE() SPLICE() SQRT() SQUISH() STARTSECS() STARTTIME() STATS() STRCAT() STRIPANSI() STRLEN() STRMATCH() STRTRUNC() SUB() SUBJ() SWITCH() TAN() TIME() TRANSLATE() TRIM() TRUNC() TYPE() U() ULOCAL() UCSTR() UDEFAULT() V() VADD() VALID() VCROSS() VDIM() VDOT() VERSION() VISIBLE() VMAG() VMUL() VSUB() VUNIT() WHERE() WORDPOS() WORDS() WRITETIME() XGET() XOR() ZONE() ZWHO() & FUNCTION CLASSES Topic: FUNCTION CLASSES Arithmetic: ABS ADD BAND BNAND BOR DEC DIE DIV FDIV IADD IDIV IMUL INC ISUB MOD MUL POWER RAND SHL SHR SIGN SUB SQRT Comsystem Information: CHANNELS COMALIAS COMTITLE CWHO Database Information: EXIT INZONE LOC LOCATE MAIL NEARBY NEXT NUM RLOC ROOM SEARCH STATS VALID WHERE ZONE ZWHO Floating Point Conversion: FLOOR ROUND TRUNC Game Information: CWHO MOTD MUDNAME POLL VERSION Lists: COLUMNS EXTRACT ELEMENTS FOREACH FILTER FIRST FOLD GRAB INDEX ITER LAST LNUM MAP MATCH MATCHALL MEMBER MIX MUNGE PARSE REMOVE REST REVWORDS SETDIFF SETINTER SETUNION SHUFFLE SORT SORTBY SPLICE WORDS Logarithms: E EXP LOG LN Logical: AND NOT OR XOR Miscellaneous: ART R SETQ ANSI BEEP CREATE ISDBREF ISNUM ISWORD LIT SETR SUBEVAL { 'help function classes2' for more } & FUNCTION CLASSES2 Object Information: ANDFLAGS APOSS CONTROLS DEFAULT EDEFAULT ELOCK FLAGS GET GET_EVAL GREP GREPI HASATTR HASATTRP HASFLAG HASPOWER HASTYPE HOME LATTR LCON LEXITS LPARENT LOCK MONEY NAME OBJ OBJEVAL OBJMEM ORFLAGS OWNER PARENT PMATCH POSS S SUBJ TYPE U UDEFAULT ULOCAL V VISIBLE Player Information: CONN DOING FINDABLE IDLE LWHO PLAYMEM PORTS Relational: EQ GT GTE LT LTE MAX MIN NEQ SORT Side-Effect Functions: LINK TEL Strings: AFTER ALPHAMAX ALPHAMIN BEFORE CAPSTR CAT COMP DELETE EDIT ESCAPE IFELSE LCSTR LPOS MERGE MID POS REPEAT REPLACE REVERSE SCRAMBLE SECURE SPACE SQUISH STRCAT STRLEN STRMATCH TRANSLATE STRTRUNC SWITCH UCSTR ENCRYPT DECRYPT VALID Time: CONVSECS CONVTIME SECS STARTTIME TIME Trigonometry: ACOS ASIN ATAN COS DIST2D DIST3D PI SIN TAN VADD VCROSS VDIM VDOT VMAG VMUL VSUB VUNIT & GENDER Topic: GENDER A player's (virtual) gender is specified in the Sex attribute. This attribute controls how gender-specific pronoun substitutions are evaluated for the player. If the player's Sex attribute starts with an 'M' or an 'm' then the player is assumed to be male, 'F', 'f', 'W', and 'w' indicate female, and anything else indicates neuter. See also: SUBSTITUTIONS. & GOALS Topic: GOALS There is no ultimate goal to this game, except to have fun. There are objects and places to build, puzzles to solve, scenery to visit, and people to meet. There are no winners or losers, only fellow players. Enjoy. & HERE Topic: HERE The word 'here' refers to the room you are in (if you are inside an object, it refers to the object that you are in, not the room that the object is in). For example, to rename the room you are in (if you control it), you could enter '@name here= <new name>'. & HOMES Topic: HOMES Every thing or player has a home. This is where players when they go home, or things with the STICKY flag set go when dropped. Homes are set with the @link command. A thing's home defaults to the room where it was created, if you control that room, or your home. You can link an exit to send players home with '@link <dir>=home'. Drop-tos can also be set to 'home'. See also: @link, DROP-TO, STICKY. & LINKING Topic: LINKING You can link to a room if you control it, or if it is set LINK_OK or ABODE. Being able to link means you can set the homes of objects or yourself to that room if it is set ABODE, and that you can set the destination of exits to that room if it is LINK_OK. See also: @link, ABODE, LINK_OK. & LISTENING Topic: LISTENING Thee are two ways to listen for something in a room. The easiest way is to use a combination of @listen and @ahear/@aahear/@amhear. The second way is to use a "^" pattern in an attribute, similar to the way "$" is used for user-defined commands. The attribute takes the form: '^<pattern>:<action>'. The ^-pattern check is only performed on objects with their MONITOR flag set. The criterion for triggering a pattern-listen is the same as that for triggering an @ahear - the object cannot trigger its own listen patterns. All matching attributes have their <action>s performed, not just the first. Also, attributes with the no_command flag set are not checked for ^-patterns, and neither are objects' parents. Example: > @va test = ^* says "foo *":say I got a foo with %1!. Set. > @set test=monitor test grows ears and can now hear. > say foo bar You say "foo bar" test says "I got a foo with bar!." See also: @ahear, @listen, @set. & LISTS Topic: LISTS A list is a string, usually stored in an attribute (currently any of the va-vz attributes), which is a series of words, separated by one or more spaces. The following would be a list (denoted on the ends by ', which is not actually in the string): 'one two three four five'. The functions first(), rest(), cat(), member(), and remove(), all work on lists. See also: cat(), first(), member(), remove(), rest(). & LOOPING Topic: LOOPING Looping in an object can have its good parts and its bad parts. The good part is when you activate part of a program multiple times to exhaustively perform an operation. This is usually done by: @va object = <list of commands>;@trigger me/vb @vb object = @switch <test> = <false>,@trigger me/va,<otherwise go on> Looping can be a problem when it goes on without stopping. The @ps command can be used to see if you are looping. Beware! A looping machine that isn't @halt'ed will drain your money supply while you are away! See also: @halt, @ps. & ME Topic: ME The word 'me' refers to yourself. Some things to do when starting out: 1) give yourself a description with '@describe me = <description>', then look at yourself with 'look me'. 2) set your gender, if you wish it known, with '@set me=male' or '@set me=female' (or '@set me=neuter' to be an 'it'). & MONEY Topic: MONEY You need money to build within the game, to run programmed objects or use certain other commands, or to buy things from vendors set up by other players. You can get money via one or more of these methods: 1. You receive a daily allowance for each day you connect. 2. You have a chance of finding money as you wander around areas that other people have built. 3. Some MUXes may implement a place where you can sell valuable objects for money. See also: @list costs, COSTS. & PUPPETS Topic: PUPPETS An object is made into a puppet by doing '@set <object>=puppet', once an object is a puppet it will relay all that it sees and hears to its master. All objects created by a puppet are owned by its master, when puppets spend or earn money, they use their master's money supply. In order to prevent puppets from screwing up puzzles, objects may have the KEY flag set, this will prevent puppets from picking the object up. A puppet may be commanded by its master by '@force <object>=command', or by the shorthand version, '#<number of puppet> command'. The puppet flag is handy for debugging, as it allows you to see the result messages your object generates. Example: @force fred="hi there. -or- #4342 "hi there. See also: VERBOSE. & ROBBERY Topic: ROBBERY Robbing is not allowed on this MUX. If you really need money, ask your friendly neighborhood wizard. See also: MONEY. & search classes Topic: SEARCH CLASSES You may use the following classes in @search commands and search() function calls: TYPE - Restricts to objects of the indicated type (OBJECTS, ROOMS, EXITS, PLAYERS, GARBAGE). THINGS may be used as an alias for OBJECTS. NAME - Restricts to objects whose names start with <restriction>. OBJECTS - A combination of TYPE=OBJECT and NAME=<restriction>. THINGS - An alias for OBJECTS. ROOMS - A combination of TYPE=ROOM and NAME=<restriction>. EXITS - A combination of TYPE=EXIT and NAME=<restriction>. PLAYERS - A combination of TYPE=PLAYER and NAME=<restriction>. FLAGS - Restricts to objects which have the flags listed in <restriction> set.. POWER - Restricts to objects which have the specified power. EVAL - Evaluates the restriction for each object, replacing ## with the object's database number. Evaluations that return TRUE (ie, not 0 or #-1) are selected. ZONE - Restricts to objects that are in the indicated zone. { 'help search classes2' for more } & search classes2 EOBJECT - A combination of TYPE=OBJECT and EVAL=<restriction>. ETHING - An alias for OBJECTS. EROOM - A combination of TYPE=ROOM and EVAL=<restriction>. EEXIT - A combination of TYPE=EXIT and EVAL=<restriction>. EPLAYER - A combination of TYPE=PLAYER and EVAL=<restriction>. PARENT - Restricts to the parent designated by <restriction>. ZONE - Restricts to the zone designated by <restriction>. & SEMAPHORES Topic: SEMAPHORES Semaphores may be used for synchronizing complex objects or for enforcing mutual exclusion. You may use any object you own or any LINK_OK object as a semaphore, and any type of object (thing, room, player, or exit) may be used. The semaphore state of an object is shown by the Semaphore attribute (which is read-only); a positive number indicates the number of commands awaiting notifies, and a negative number indicates the number of waits on that semaphore that will not block. Use the '@wait <object>' form of the @wait command to request a command be delayed until <object> is notified with the @notify command. The @drain and @notify/all commands clear the semaphore on <object>, either discarding or executing all pending commands. Remember that the object performing the @wait executes the command, not the object used as a semaphore. { 'help semaphores2' for more } & semaphores2 You may also combine the semaphore and timer options of @wait with '@wait <object>/<timeout> = <command>' If the time period expires before the semaphore is notified, then the command is executed and the semaphore count is decremented, just as if the command had been run because the semaphore had been notified. Examples: <simple> @wait semaphore="Foo @notify semaphore <mutex lock> @va mutex lock=@wait me=@trig me/vb @vb mutex lock="Got it!;@notify me @startup mutex lock=@notify me <timed wait> @wait timer/60 = "Sixty Second Timer. In the above examples you will say "Foo" after semaphore is notified, you will say "Got it" when you have the mutual exclusion lock mutex lock (You could have also modified object registers that need to be protected from concurrent update), and you will say "Sixty Second Timer." either when timer is notified or after sixty seconds pass. See also: @drain, @notify, @wait. & SPOOFING Topic: SPOOFING Spoofing is the act of making other characters think that a person said or did something that they did not. This is very easy to accomplish, and has some good effects, which is why it is allowed. Note that the NOSPOOF flag allows players to see exactly who is spoofing what. Example: ... From TinyJerk's perspective ... > @emit Wizard is a jerk! Wizard is a jerk. ... From Wizard's perspective, Wizard is set NOSPOOF ... [TinyJerk(#226)] Wizard is a jerk! > @boot tinyjerk You booted TinyJerk off! TinyJerk has disconnected. 1 connection closed. ... TinyJerk's perspective again ... Wizard gently shows you the door. *** Disconnected *** & STACK Topic: STACK Command lists that are run on objects can have up to 10 stack values named %0 through %9 (or [v(0)] through [v(9)]). Stack values can be set by the @trigger command, or by matching wildcard characters in the Listen attribute (in the case of the Ahear, Aahear, and Amhear attributes). Example: > @listen item = * foo * Set. > @ahear item = "-->[v(1)]<-- bar -->[v(0)]<-- Set. > say Fee fie foo fum You say "Fee fie foo fum" item says "-->fum"<-- bar -->Wizard says "Fee fie<--" & SUBSTITUTIONS Topic: SUBSTITUTIONS All messages may contain %-substitutions, which evaluate to gender-specific pronouns if the player's gender is set or to other useful information. Information returned is based on the player that caused the message to be displayed, not the object that stored the message or which is running the action list. The substutitions available are: %s, %S = Name, he, she, it, they. (subjective) %o, %O = Name, him, her, it, them. (objective) %p, %P = Name's, his, her, its, their. (possessive) %a, %A = Name's, his, hers, its, theirs. (absolute possessive) %n, %N = the player's name. %r = carriage return %t = tab character %b = space character %% = literal '%' character %0-%9 = Value of positional parameter/stack location 0 through 9. %q0-%q9 = Value of temporary (setq) register 0 through 9. %va-%vz = Contents of attribute va through vz { 'help substitutions2' for more } & substitutions2 %# = Database number of the object that caused the message to be displayed or the action list to be run. %l = Database number of the location of the object that caused the message to be displayed or the action list to be run. %! = Database number of the object holding the message or running the action list. %c = ANSI color codes. See 'help ansi()' for more information. %| = A string piped from the previous command in a pipe. If the letter following the % is capitalized, the first letter of the result of the substitution is also capitalized. Note: %<whatever> is equivalent to [v(<whatever>)], but is more efficient. See also: GENDER, V(). & SUCCESS Topic: SUCCESS You successfully use a player or a thing when you take it (because you passed the lock). You successfully use an exit when you go through it. You successfully use a room when you look around and the room is not locked against you. See also: get, look, @asuccess, @lock, @osuccess, @success. & SWITCHES Topic: SWITCHES Some commands have command switches associated with them that can be used to modify their behavior. For instance, switches on the @ps command control the amount of information displayed, and switches on the @switch command indicate whether to perform all actionlists whose targets match the search string, or just the first. See also: @list. & OBJECT TYPES Topic: OBJECT TYPES There are 4 types of objects: things, players, exits, and rooms. The first letter following an object's ID number indicates the type: P(layer), E(xit), R(oom), otherwise, thing. Things are inanimate objects that can be carried. Players are animate objects that can move and carry. Exits are the means by which objects move from room to room. Rooms are locations that contain objects and linked exits. & COMMAND EVALUATION Topic: COMMAND EVALUATION When you submit a command to be executed by MUX (whether by typing it in or by having a machine run it, the following steps are performed, in sequence. If the command matches something in a step, the matching actions are performed and the walk down the list stops. - The first letter of the command is checked to see if it is a single- character command (", :, etc). If so, %-substitution and function evaluation may be performed (depending on the command), and the command is executed. - The comsystem checks for a channel alias. - The command is checked to see if it is the 'home' command. If so, the player or object performing the command goes home. - The command is checked against the exits in its current room. If one matches, it is performed. If more than one matches, one is picked randomly from the exits for which the player passes the lock (If the player does not pass any locks, then the exit to be tried is picked randomly. { 'help command evaluation2' for more } & command evaluation2 - The first word of the command is checked to see if it is an internal MUX command. If so, the remainder of the command is broken up into arguments, %-substitution and function evaluation may be performed on the (split up) arguments, and the command is executed. - %-substitution and function evaluation is performed on the command. - All objects in the player's inventory, all objects in the player's location, and the location itself are searched for $-commands that match the command. All that match are performed. The player may or may not be checked, depending on how the MUX is configured. - The commands defined in the zone tree you or your location is in. Note: Commands that can cause other commands to be executed (such as @wait, @switch, @trigger, etc) never perform substitution on their arguments, they leave the evaluation to the command that is to be executed. This prevents most of the problems with getting objects to perform unintended commands by putting a ';', '}', or ',' in an argument. The @force command is an exception in that it evaluates its argument, so it should be used with caution (preferably by never using it to pass information that someone else entered, use @trigger instead). Also, the construct '$xx *:%0' does not work (and is very dangerous programming), use '$xx *:@force me=%0' if you need this functionality. & VERBS Topic: VERBS For many verbs there are three attributes that specify messages and actions associated with the verb in addition to the verb's builtin action. The attributes are named Verb, Overb, and Averb. Verb is the message that the enactor sees, Overb is the message that everyone else in the same room as the enactor sees, and Averb is a list of commands that are run. These attributes may be set using the @<attribute> command, so the commands to set the attributes related to the 'drop' command are @drop, @odrop, and @adrop. & WIZARDS Topic: WIZARDS Wizards are the people that help run the game and make sure that everything is working properly. They have special powers to tweak reality in ways mortals can only dream of. Be nice to them, they are going out of their way to help keep the game running smoothly. And remember, if you have any problems or just want to talk to someone, they will be there for you as well. & V() Function: v(<string>) The V function can be used as an alternative for percent (%) substitution and also as a replacement for get(me/<arg>). If the argument is two characters long or longer and starts with a letter, then the object performing the v() call (and its parent, if necessary) is searched for the named attribute, and its value is returned if possible. Otherwise, a percent substitution is performed on the argument (so that v(o) is equivalent to %o, for instance). The percent form (%o in the previous example) is preferred as it is faster, and there are no longer any security problems associated with it. Note that attributes with single-character names cannot be retrieved with v(). See also: GENDER, SUBSTITUTION, PARENT OBJECTS. & beep() Function: beep() This function simply outputs the beep character, which on most terminals with sound, will emit a short beep. Only wizards may use this function. & create() Function: create(<object>, <cost>[, <type>]) Works the same as @create <object>, but returns the database number of the object created. <cost> is the cost of making the object. <type> is an optional parameter, 'r' for rooms, 't' for things, and 'e' for exits. If no <type> is specified, then a thing will be created by default. This is a side effect function, and should only be used when necessary. & set() Function: set(<name>, <string>) Works the same as @set, <name> and <string> are equivalent to what comes before and after the '=' sign. Returns nothing. This is a side effect function, and should only be used when necessary. & cwho() Function: cwho(<channel>) This returns a list of connected players who are on <channel>. Note that this function returns the _names_ of the players, not the dbrefs. When used by mortals, hidden ("dark") players do not appear on the list. & wordpos() Function: wordpos(<string>, <charpos>[, <delim>) Returns the number of the word within <string> where the character position <charpos> falls. Spaces between words are treated as belonging to the word that follows them. If <charpos> is not within the string, the value #-1 is returned. Both words and characters are numbered starting at 1. <delim> may be used to specify a delimiter other than a space. Example: > say wordpos(This is a test, 4) You say "1" > say wordpos(This is a test, 5) You say "2" > say wordpos(This is a test, 6) You say "2" > say wordpos(This is a test, 20) You say "#-1" & type() Function: type(<object>) Returns a string indicating the object type of <object>, either EXIT, PLAYER, ROOM, or THING. Example: > say type(me) You say "PLAYER" > say type(here) You say "ROOM" & hasflag() Function: hasflag(<object>,<flag>) Returns true if object <object> has the flag named <flag> set on it. You may not be able to retrieve information for objects that you do not own. Example: > say hasflag(me, wizard) You say "0" > say hasflag(me, connect) You say "1" & haspower() Function: haspower(<object>,<power>) Returns true if object <object> has the power named <power> set on it. You may not be able to retrieve information for objects that you do not own. Example: > say haspower(me, announce) You say "0" > say hasflag(me, extended_who) You say "1" & delete() Function: delete(<string>,<first>,<len>) Returns <string>, but with <len> characters starting after the character at position <first> removed. In other words, this function copies <first> characters, skips <len> characters, and then copies the remainder of the string. Example: > say delete(abcdefgh, 3, 2) You say "abcfgh" > say delete(Would you like coffee or perhaps tea?, 15, 18) You say "Would you like tea?" & lock() Function: lock(<object>[/<whichlock>]) Returns the named lock on <object>. If you don't specify the lock to get, the default lock is returned. You must control <object>. & elock() Function: elock(<object>[/<whichlock>],<victim>) Checks if <victim> would pass the named lock on <object>. Only the object's owner may test locks other than the default lock. & lwho() Function: lwho() Returns a list of the db numbers of connected players. Example: > WHO Player Name On For Idle Doing Mortal 00:11 0s Evinar 00:12 6m Wizard 00:32 6s 3 Players logged in. > say lwho() You say "#226 #271 #1" See also: WHO, conn(), idle(). & OBJ() Function: obj(<object>) Returns the proper objective pronoun (him, her, it, them) for referring to <object>, based on the object's Sex attribute. You must either control or be near <object>. & POSS() Function: poss(<object>) Returns the proper possessive pronoun (his, her, its, their) for referring to <object>, based on the object's Sex attribute. You must either control or be near <object>. & APOSS() Function: aposs(<object>) Returns the proper absolute possessive pronoun (his, hers, its, theirs) for referring to <object>, based on the object's Sex attribute. You must either control or be near <object>. & SUBJ() Function: subj(<object>) Returns the proper subjective pronoun (he, she, it, they) for referring to <object>, based on the object's Sex attribute. You must either control or be near <object>. & LIT() lit(<string>) This function returns the string literally - without even squishing spaces, and without evaluating *anything*. This can be useful for writing ASCII maps with spaces or whatever. It can be a bit tricky to get a literal string with spaces into an attrib, however, since spaces are usually squished in setting an attribute. This example illustrates how to make it work: > @va me=$test: think {[lit(near far)]} Set. > ex me/va VA [#1]: $test: think {[lit(near far)]} > test near far Leaving out the {}'s will not work in the above. & GREPI() grepi(<object>,<attrs>,<pattern>) This function works exactly like grep, but is case-insensitive. See "help grep()" for details. & GREP() grep(<object>,<attrs>,<pattern>) This function returns a list of attributes on <object> containing <pattern>. <attrs> is a wildcard pattern for attribute names to search; if you want to search all attributes, use "*". Parsing _does_ occur before this function is invoked. Therefore, "special" characters will need to be escaped out. <pattern> is NOT wildcard matched. This function is case-sensitive. grepi() is a case-insensitive version. & LPARENT() lparent(<object>) This function returns a list consisting of the object's db# (as per num()), the db# of its parent, grandparent, greatgrandparent, etc. The list will not, however, show parents of objects which the player is not privileged to examine. & STRCAT() strcat(<string1>, <stringN>, ...) Concatanates two or more strings together, with no space between them. For example, strcat(foo,bar,baz,blech) will return the string "foobarbazblech". & STRIPANSI() stripansi(<string>) Strips the ansi codes from <string>. & PMATCH() pmatch(<string>) Given the partial name of a player, it returns that player's dbref number. This partial name completion works identically to the partial name completion of the "page" command - i.e. it first attempts to match the normal names of all players (connected or not), and if that fails, it tries to match the partial names of connected players. If no player is matched, it returns "#-1". If more than one match is possible for a partial name, it returns "#-2". Pmatch() will also accept *<player> or #<db#>. If given a non-player dbref #, pmatch() will return #-1. & DIE() die(<number of times to roll die>, <number of sides on die>) This function simulates rolling dice. It "rolls" a die with a given number of sides, a certain number of times, and sums the results. For example, DIE(2, 6) would roll "2d6" - two six-sided dice, generating a result in the range 2-12. & ALPHAMIN() alphamin(<word1>, <word2>, <word3>, ...) Takes up to ten word arguments, and returns the word which is lexicographically smallest. & ALPHAMAX() alphamax(<word1>, <word2>, <word3>, ...) Takes up to ten word arguments, and returns the word which is lexicographically biggest. & ART() art(<string>) This function returns the proper article, "a" or "an", based on whether or not <string> begins with a vowel. & HASATTR() hasattr(<object>, <attribute name>) Returns 1 if the object has the named attribute, and 0 if it does not. If the object does not exist or the player does not have the ability to examine the object, #-1 will be returned. Hasattr() doesn't check for attributes inherited from parent objects. Use hasattrp() for that. & HASATTRP() hasattrp(<object>, <attribute name>) Returns 1 if the object or its parent has the named attribute, and 0 if it does not. If the object does not exist or the player does not have the ability to examine the object, #-1 will be returned. Use hasattr() to check for attributes without checking parents. & HASTYPE() hastype(<object>, <type>) Returns 1 if the object is of the named type, otherwise 0. Valid types are: ROOM, EXIT, PLAYER, THING. If an invalid type is given, #-1 is returned. & SHL() shl(<number>,<count>) Performs a leftwards bit-shift on <number>, shifting it <count> times. This is equivalent to imul(<number>,pow(2,<count>), but much faster. > think shl(2,10) 2048 See also: shr(), band(), bnand(), bor(). & SHR() shr(<number>,<count>) Performs a rightwards bit-shift on <number>, shifting it <count> times. This is equivalent to div(<number>,pow(2,<count>), but much faster. > think shr(1309,5) 40 See also: shl(), band(), bnand(), bor(). & BAND() band(<number>, <number>) Both arguments are an integer that is treated as a bitfield. It performs a bitwise logical AND between these two bitfields and returns the resulting bitfield as an integer which can be further treated as an integer, a bitfield, or a logical boolean depending on your intentions. > think band(922,785) 784 In the above example, 922 in base 10 is equivalent to 39A in base 16 or 0011 1001 1010 in base 2. Likewise, 785 in base 10 is the same as 311 in base 16 and or 0011 0001 0001 in base 2. 0011 1001 1010 (922) (BAND) 0011 0001 0001 (785) -------------- 0011 0001 0000 (784) The result may be expressed as 310 in base 16 or 784 in base 10. So, this function is useful for testing whether a particular bit in the field is 'on' or 'off'. More than one bit can be tested at a time. If all bits are 'off', the result is zero which can also be interpreted as a boolean false in softcode. See also: shl(), shr(), bnand(), bor(). & BNAND() band(<number1>, <number2>) Both arguments are an integer that is treated as a bitfield. It performs a bitwise logical AND between <number1> and the complement of <number2> which has the effect of forcing certain bits in <number1> off in the result. > think bnand(922,785) 138 In the above example, 922 in base 10 is equivalent to 39A in base 16 or 0011 1001 1010 in base 2. Likewise, 785 in base 10 is the same as 311 in base 16 and or 0011 0001 0001 in base 2. The complement of 785 (specifically the one's complement) is 1100 1110 1110 in base 2, and is a simple bitwise reversal of 1's and 0's. 0011 1001 1010 (922) (BAND) 1100 1110 1110 (Complement of 785) -------------- 0000 1000 1010 (138) The result may be expressed as 08A in base 16 or 138 in base 10. See also: shl(), shr(), band(), bor(). & BOR() bor(<number>, <number>) Both arguments are an integer that is treated as a bitfield. It performs a bitwise logical OR which has the effect of forcing certain bits on in the result. > think bor(922,785) 923 In the above example, 922 in base 10 is equivalent to 39A in base 16 or 0011 1001 1010 in base 2. Likewise, 785 in base 10 is the same as 311 in base 16 and or 0011 0001 0001 in base 2. 0011 1001 1010 (922) (BOR) 0011 0001 0001 (785) -------------- 0011 1001 1011 (923) The result may be expressed as 39B in base 16 or 923 in base 10. See also: shl(), shr(), band(), bnand(). & VADD() vadd(<vector>,<vector>[,<delim>][,<output delim>]) Returns the sum of two vectors. A vector is a list of numbers separated by spaces or a delimiter, and may have up to 20 dimensions. > @pemit me=vadd(1 2 3,4 5 6) 5 7 9 > @pemit me=vadd(0|0|0,1|2|3,|,-) 1-2-3 & VCROSS() vcross(<vector>,<vector>[,<delim>][,<output delim>]) Returns the cross product of two vectors. The cross product of two vectors is a vector. | a b c | (a,b,c) X (d,e,f) = det | d e f | = i(bf-ce) + j(cd-af) + k(ae-bd) | i j k | where i, j, and k are taken as unit vectors in cartisian space. > @pemit me=vcross(1 2 3,2 3 4) -1 2 -1 & VDIM() vdim(<vector>[,<delim>]) Returns the dimensions of a vector. > @pemit me=vdim(1 2 3 4) 4 & VDOT() vdot(<vector>,<vector>[,<delim>][,<output delim>]) Returns the dot product of two vectors. The dot product of two vectors is a scalar. (a,b,c) * (x,y,z) = aw + bx + cz > @pemit me=vdot(1 2 3,2 3 4) 20 & VMAG() vmag(<vector>[,<delim>] Returns the magnitude of a vector using a euclidean distance metric. That is, for vector a b c d, returns sqrt(a^2+b^2+c^2+d^2). > @pemit me=vmag(3 4) 5 & VMUL() vmul(<vector|number>,<vector|number>[,<delim>][,<output delim>]) Returns the result of either multiplying a vector by a number (scalar multiplication), or an elementwise multiplication of two vectors. > @pemit me=vmul(1 2 3,2) 2 4 6 > @pemit me=vmul(1 2 3,2 3 4) 2 6 12 & VSUB() vsub(<vector>,<vector>[,<delim>][,<output delim>]) Returns the difference between two vectors. > @pemit me=vsub(3 4 5,3 2 1) 0 2 4 > @pemit me=vsub(6-4-2,5-2-0,-) 1-2-2 & VUNIT() vunit(<vector>[,<delim>][,<output delim>]) Returns the unit vector (a vector of magnitude 1) which points in the same direction as the given vector. > @pemit me=vunit(2 0 0) 1 0 0 > @pemit me=vmul(vunit(5 6 7),vmag(5 6 7)) 5 6 7 & NEARBY() Function: nearby(obj1,obj2) Tests if obj1 is near obj2 (if it is in the same location, in obj2's inventory, or is obj2's location). You must control either obj1 or obj2, or be near either one of them, if both of these tests fail then 0 is returned. This function returns 1 if the two objects are nearby and 0 if not. & GET() Function: get(<object>/<attribute>) The get function fetches the specified attribute from the named object. It can be used to get attributes from objects you own, public and visual attributes of objects near you, and public and visual attributes other than the description of players wherever they may be. If the attribute is not present on <object>, its parent is searched for the attribute. Example: > read me > say get(me/desc) See also: get_eval(), eval(), xget(). & XGET() Function: xget(<object>,<attribute>) This function works exactly like get(), but uses the object and attribute seperated into two arguments. See also: get(), eval(), get_eval(). & EVAL() Function: eval(<object>,<attribute>) eval(<string>) The first form of the eval function works exactly like the get_eval function, but takes the object and attribute in two seperate arguments instead of an obj/attr pair. It is mainly used for compatibility with PennMUSH 1.50. The second form simply evaluates <string>. This is normally done when a function is called, however, it is useful in evaluating %q and %v substitutions. See also: get_eval(), get(), xget(). & GET_EVAL() Function: get_eval(<object>/<attribute>) The get_eval function returns the specified attribute from the named object (just like the get function), except that function references and %-substitutions have already been performed. In function references, 'me' refers to the object being looked at, and %-substitutions that refer to the enactor (such as %n, %#, etc) refer to the object making the get_eval call. If the attribute is not present on <object>, its parent is searched for the attribute. Example: > @va test = This is a get_eval test on %n. The vb is [get(me/vb)] > @vb test = VB from test > @vb me = VB from me > say get(test/va) You say "This is a get_eval test on %n. The vb is [get(me/vb)]" > say get_eval(test/va) You say "This is a get_eval test on Foobar. The vb is VB from test" See also: get(), get_eval(), xget(). & TIME() Function: time([<zonename>]) The optional <zonename> parameter may be "utc" or "local". If no <zonename> is given, "local" is assumed. local - Gives you the current local time string of the machine the MUX is running on. This time is affected by the daylight savings time (or 'summer') rules in force at the server's location. utc - Gives you the time string for the UTC time zone. Example: > say time() You say "Fri May 05 13:05:39 2000" > say time(utc) You say "Fri May 05 20:05:39 2000" See also: convsecs(), convtime(), secs(). & RAND() Function: rand(<num>) Rand returns an integer between 0 and num-1. Example: > say rand(10) You say "6" > say rand(10) You say "1" > say rand(10) You say "4" > say rand(10) You say "9" > say rand(10) You say "1" & EXIT() Function: exit(<object>) Exit returns the first exit on the list of exits in the object. Dark exits are not listed, unless you own the object. Unlike LEXITS(), this function does not provide information about exits in parent objects. See also: con(), lcon(), lexits(), next(). & ABS() Function: abs(<number>) Returns the absolute value of its argument. <number> may be a floating point number, and a floating point result is returned. Examples: > say abs(4) You say "4" > say abs(-4) You say "4" > say abs(0) You say "0" & MAX() Function: max(<number1>,<number2>[,<numberN]...) Returns the largest integer from among its arguments. Up to 30 arguments may be specified. <numberN> may be a floating point number, and a floating point result is returned. Examples: > say max(2,4) You say "4" > say max(-100,50,0,25) You say "50" See also: min() & MIN() Function: min(<number1>,<number2>[,<numberN]...) Returns the smallest integer from among its arguments. Up to 30 arguments may be specified. <numberN> may be a floating point number, and a floating point result is returned. Examples: > say min(2,4) You say "2" > say min(-100,50,0,25) You say "-10" See also: max() & ADD() Function: add(<number1>,<number2>[,<numberN>]...) Returns the result of adding its arguments together. You may add up to 30 numbers in one add() call. <numberN> may be a floating point number, and a floating point result is returned. Example: > say add(2,4) You say "6" > say add(5,3,7,-4) You say "11" See also: dec(), div(), iadd(), idiv(), imul(), inc(), isub(), mod(), mul(), sub(). & IADD() Function: iadd(<number1>,<number2>[,<numberN>]...) Returns the result of adding its integer arguments together. You may add up to 30 numbers in one add() call. Similiar to add() except that the addition is done with faster integer math. Example: > say iadd(2,4) You say "6" > say iadd(5,3,7,-4) You say "11" See also: add(), dec(), div(), idiv(), imul(), inc(), isub(), mod(), mul(), sub(). & INC() Function: inc(<number>) Returns <number> plus 1. Much faster and more efficient than add(<number>,1). Decimal places will be truncated. See also: add(), dec(), iadd(), isub(), sub(). & DEC() Function: dec(<number>) Returns <number> minus 1. Much faster and more efficient than sub(<number>,1). Decimal places will be truncated. See also: add(), iadd(), inc(), isub(), sub(). & SUB() Function: sub(<number1>,<number2>) Returns the result of subtracting <number2> from <number1>. The numbers may be floating point numbers, and a floating point result is returned. Example: > say sub(5,2) You say "3" See also: add(), dec(), div(), iadd(), idiv(), imul(), inc(), isub(), mod(), mul(). & ISUB() Function: isub(<number1>,<number2>) Returns the result of subtracting integer <number2> from integer <number1>. Similiar to sub() except that the addition is done with faster integer math. Example: > say isub(5,2) You say "3" See also: add(), dec(), div(), iadd(), idiv(), imul(), inc(), mod(), mul(), sub(). & MUL() Function: mul(<number1>,<number2>[,<numberN>]...) Returns the result of multiplying its arguments together. <numberN> may be a floating point number, and a floating point result is returned. Example: > say mul(3,5) You say "15" > say mul(3,5,-2) You say "-30" See also: add(), div(), fdiv(), iadd(), imul(), isub(), mod(), round(), sub(), trunc(). & IMUL() Function: imul(<number1>,<number2>[,<numberN>]...) Returns the result of multiplying its integer arguments together. Similiar to mul() except that the mulitplication is done with faster integer math. Examples: > say imul(3,5) You say "15" > say imul(3,5,-2) You say "-30" See also: add(), div(), fdiv(), iadd(), isub(), mod(), mul(), round(), sub(), trunc(). & DIV() Function: div(<number1>,<number2>) Returns the integer quotient from dividing <number1> by <number2>. Examples: > say div(15,3) You say "5" > say div(16,3) You say "5" > say div(17,3) You say "5" > say div(18,3) You say "6" > say div(-17,3) You say "-5" See also: add(), div(), fdiv(), iadd(), imul(), isub(), mod(), mul(), round(), sub(), trunc(). & IDIV() Function: idiv(<number1>,<number2>) Returns the integer quotient from dividing <number1> by <number2>. Examples: > say idiv(15,3) You say "5" > say idiv(16,3) You say "5" > say idiv(17,3) You say "5" > say idiv(18,3) You say "6" > say idiv(-17,3) You say "-5" See also: add(), div(), fdiv(), iadd(), imul(), isub(), mod(), mul(), round(), sub(), trunc(). & FDIV() Function: fdiv(<number1>,<number2>) Returns the floating point quotient from dividing <number1> by <number2>. <number> may be a floating point number, and a floating point result is returned. Examples: > say fdiv(15,3) You say "5" > say fdiv(16,3) You say "5.333333" > say fdiv(17,3) You say "5.666667" > say fdiv(18,3) You say "6" > say fdiv(-17,3) You say "-5.666667" > say fdiv(10,3.5) You say "2.857143" See also: add(), div(), mod(), mul(), round(), sub(), trunc(). & MOD() Function: mod(<integer1>,<integer2>) Returns the integer remainder from dividing <integer1> by <integer2>. Example: > say mod(15,3) You say "0" > say mod(16,3) You say "1" > say mod(17,3) You say "2" > say mod(18,3) You say "0" See also: add(), fdiv(),div(), mul(), round(), sub(), trunc(). & DIST2D() Function: dist2d(x1, y1, x2, y2) Returns the integer distance between the Cartesian points in two dimensions (x1,y1) and (x2,y2). Example: > say dist2d(0,0,3,4) You say "5" See also: dist3d() & DIST3D() Function: dist3d(x1, y1, z1, x2, y2, z2) Returns the integer distance between the Cartesian points in three dimensions (x1,y1,z1) and (x2,y2,z2). Example: > say dist3d(0,0,0,10,15,20) You say "27" See also: dist2d() & FIRST() Function: first(<string>[, <delim>]) Returns the first word of a string, that is, everything to the left of the first space in the string, or the entire string if there are no spaces in the string. <delim> may be used to specify a word delimiter other than a space. Example: > say first(This is a test) You say "This" > say first(Would you like coffee, or perhaps tea) You say "Would" > say first(List&with&nonstandard&delimiters,&) You say "List" See also: rest(). & REST() Function: rest(<string>[, <delim>]) The rest function takes a string, returns all the string except the first word, that is, everything to the right of the first space, or an empty string, or the empty string if there are no spaces in the string. <delim> may be used to specify a word delimiter other than a space. Example: > say rest(This is a test) You say "is a test" > say rest(Would you like coffee, or perhaps tea) You say "you like coffee, or perhaps tea" > say rest(List!with!different!delimiters,!) You say "with!different!delimiters" See also: first(). & STRLEN() Function: strlen(<string>) Returns the number of characters in <string>. Example: > say strlen(This is a test) You say "14" > say strlen(Would you like coffee, or perhaps tea) You say "37" & STRTRUNC() Function: strtrunc(<string>,<number>) This function returns <string> truncated if it is longer than <number>. If <number> is greater than the length of <string>, it just returns <string>. Much more efficient than the equivalent mid(). See also: mid(), ljust(). & MID() mid(<string>, <first>, <length>) Mid returns a segment of the string, the <length> characters to the right of the <first> character. Note that the first character in a string is numbered zero, and not one. & COMP() comp(<string1>, <string2>) Comp compares two strings. It returns 0 if they are the same, 1 if string2 is less than/precedes alphabetically string1, and -1 otherwise. & S() s(string) This function performs pronoun substitution in a string, and then returns that string. As usually, %n is the name, %s the subjective pronoun, %o the objective, %p the possessive, and %a the absolute possessive. It is important to note that the pronoun is that of the triggering object. So, if the ve of an object were: "[s(This is %n)], and I were to type @trigger <object>/ve, it would return "This is <myname>", but if vf were @trigger me/ve, then triggering the vf makes the ve return "This is <object>" & LPOS() lpos(<string>, <character>) This function returns a list of the positions that <character> occupies in <string>, with the first character of the string being 0. (Note that this differs from the pos() function, but it consistent with functions such as mid().) If <character> is null, a space is assumed. Example: > say lpos(a-bc-def-g,-) You say "1 4 8" & POS() pos(<string1>,<string2>) This function returns the position that string1 begins in string2, with the first position being 1. If string1 is not in string2, then it returns -1. Example: pos(man,superman) returns 6 & MATCH() Function: match(<string>, <pattern>[, <delim>]) This function matches <pattern> against each word of <string>, returning the number of the first word that matches. If no words match then 0 is returned. The case of the characters being matched is not significant. The pattern may contain the wildcards '*' and '?'. '?' matches any one character, while '*' matches any number of characters, including none. So 's?x' would match 'sex' or 'six', but not to 'socx', but 's*x' would match any of them. <delim> may be used specified to specify a delimiter other than a space. Examples: > say match(This is a test, test) You say "4" > say match(This is a test, is) You say "2" > say match(This is a test, *is*) You say "1" > say match(This is a test, *not*) You say "0" > say match(This is a test, is a) You say "0" See also: LISTS, member(), strmatch(). & STRMATCH() Function: strmatch(<string>,<pattern>) This function matches <pattern> against the entire <string>, returning 1 if it matches and 0 if it does not. The case of the characters being matched is not significant. The pattern may contain the wildcards '*' and '?'. '?' matches any one character, while '*' matches any number of characters, including none. So 's?x' would match 'sex' or 'six', but not to 'socx', but 's*x' would match any of them. Examples: > say strmatch(This is a test,*Test) You say "1" > say strmatch(This is a test,*This) You say "0" > say strmatch(This is a test,*is*is*) You say "1" See also: match(), member(), regmatch(). & REGMATCH() regmatch(<string>,<regexp>[,<register list>]) This function matches the regular expression <regexp> against the entirety of <string>, returning 1 if it matches and 0 if it does not. If <register list> is specified, there is a side-effect: any parenthesized substrings within the regular expression will be set into the specified local registers, in the order they were specified in the list. <register list> can be a list of one through nine numbers. If the specified register is -1, the substring is not copied into a register. For example, if <string> is 'cookies=30', and <regexp> is '(.+)=([0-9]*)' (parsed; note that escaping may be necessary), then the 0th substring matched is 'cookies=30', the 1st substring is 'cookies', and the 2nd substring is '30'. If <register list> is '0 3 5', then %q0 will become "cookies=30", %q3 will become "cookies", and %q5 will become "30". If <register list> was '0 -1 5', then the "cookies" substring would simply be discarded. See 'help regexp syntax' for an explanation of regular expressions. & COLUMNS() columns(<list>, <width>[, <delim>]) Columns displays <list> formatted into columns containing <width> number of characters. As many columns as possible will be fit onto the screen. Columns takes an optional delimiter. & FOREACH() foreach([<object>/]<attribute>,<string>[,<begin>, <end>]) Maps a function onto a string. Each character in <string> has the user-defined function of the first argument performed on it; the character is passed to the function as %0. The results are concatenated. If <begin> and <end> are specified, only the characters between <begin> and <end> are parsed, other characters are concatenated as they are. This allows a rudimentary form of tokens and speeds up the evaluation greatly if tokenizing is your purpose. Examples: > &add_one me=[add(%0,1)] > say [foreach(add_one, 54321)] You say, "65432" > &add_one me=[add(%0,1)] > say [foreach(add_one, This adds #0# to numbers in this string,#,#)] You say, "This adds 1 to numbers in this string." & MIX() mix([<object>/]<attribute>,<list 1>,<list 2>[,<delim>]) This function is similar to MAP(), except that it takes the elements of both lists, one by one, and passes them to the user-defined function as %0 and %1, respectively, for elements of <list 1> and <list 2>. <delim> is used to separate elements; if it is not specified, it defaults to a space. The lists must have the same number of elements. Examples: > &add_nums me=[add(%0,%1)] > say [mix(add_nums,1 2 3 4 5,2 4 6 8 10)] You say, "3 6 9 12 15" > say [mix(add_nums,1:3:5:7,0:2:4:6,:)] You say, "1:5:9:13" & MUNGE() munge([<object>/]<attribute>,<list 1>,<list 2>[,<delimiter>]) This function takes two lists of equal length. It passes the entirety of <list 1> to the user-defined function as %0. Then, this resulting list is matched with elements in <list 2>, and the rearranged <list 2> is returned. This is useful for doing things like sorting a list, and then returning the correspoding elements in the other list. If a resulting element from the user-defined function doesn't match an element in the original <list 1>, a corresponding element from <list 2> does not appear in the final result. For example: Consider attribute PLACES, which contains "Fort Benden Ista", and another attribute DBREFS contains the dbrefs of the main JUMP_OK location of these areas, "#20 #9000 #5000". We want to return a list of dbrefs, corresponding to the names of the places sorted alphabetically. The places sorted this way would be "Benden Fort Ista", so we want the final list to be "#9000 #20 #5000". The functions, using munge(), are simple: > &sort_alpha me=[sort(%0)] > say [munge(sort_alpha,v(places),v(dbrefs))] You say, "#9000 #20 #5000" & OBJEVAL() objeval(<object>,<expression>) Allows you to evaluate <expression> from the viewpoint of <object>. You must be a wizard or own <object> to use this function. If <object> does not exist or you don't meet the criterion, the function evaluates with your privileges. No one may use this function on #1. This function is useful for securing objects which need to evaluate attributes on things owned by others. & OBJMEM() objmem(<object>) Returns the size in bytes of <object>. Note that this is the complete struct size of the object, and not just the attribute values. & PLAYMEM() playmem(<player>) Returns the size in bytes of <player>. Note that this is the total number of bytes that the player uses, including all objects that they own. You must be a Wizard, or have the search power to use this function on another player. & ANDFLAGS() andflags(<object>,<list of flags>) This function returns 1 if <object> has all the flags in a specified list, and 0 if it does not. The list is specified with a single letter standing for each flag, like the output of the FLAGS() function. A '!' preceding a flag letter means "not flag". Thus, ANDFLAGS(me,WD) would return 1 if I was set WIZARD and DARK. ANDFLAGS(me,W!Dc) would return 1 if I was set WIZARD, not DARK, and CONNECTED. If a letter does not correspond to any flag, <object> doesn't have it, so the function returns 0. There can be an arbitrary number of flags. Do not put spaces between flag letters. & ORFLAGS() orflags(<object>,<list of flags>) This function returns 1 if <object> has at least one of the flags in a specified list, and 0 if it does not. The list is specified with a single letter standing for each flag, like the output of the FLAGS() function. A '!' preceding a flag letter means "not flag". Thus, ORFLAGS(me,Wr) would return 1 if I am set WIZARD or ROYALTY. ORFLAGS(me,D!c) would return 1 if I am DARK or not CONNECTED. If a letter does not correspond to any flag, <object> doesn't have it, so it is simply ignored. There can be an arbitrary number of flags. Do not put spaces between flag letters. & EXTRACT() extract(<string>, <first>, <length>[, <delim>]) Extract returns a string of length words, starting with the first word. Unlike letters, the first word in a string is number 1, instead of 0. <delim> may be used to specify a delimiter other than a space. Examples: > say extract(This is a really neat example, 4, 2) You say "really neat" > say extract(Another@funky@test@for@extract, 3, 3) You say "test@for@extract" See also: index(), insert(), ldelete(), replace(). & INDEX() Function: index(<list>,<character>,<first>,<length>) This function is similar to EXTRACT(), except that an item in the list may be more than one word; instead of a space being used to separate items in the list, <character> is used. The function returns <length> items starting from that in the <first> position. Trailing spaces are trimmed. The comma cannot be used as the <character> separator. Example: > say [index(Cup of Tea | Mug of Beer | Glass of Wine, |, 2, 1)] You say, "Mug of Beer" See also: extract(). & FLAGS() flags(<object>) Flags returns a string consisting of the flags attached to the object. The string is, however, just one word. Note that @switch is case-INsensitive. i.e. p=P as far as it is concerned. I wish that P=NP.... & NUM() num(<object>) Returns the dbref number of <object>. See also: locate(). & CON() con(<object>) Con returns the first object in the list of objects carried by thing. Just the first, and only the first. See NEXT. & LOC() Function: loc(<object>) Returns the number of the location where <object> is. You must either control the object or be nearby for it to work. When used on an exit it returns the destination of the exit. You can also use loc() to find the location of players that are not set UNFINDABLE. Example: > look Mortal's Room(#367R) A bare room with nothing in it but a bed and a chair. Contents: hat(#368) > say loc(me) You say "#367" > enter hat hat(#368) Contents: cat(#325) > say loc(me) You say "#368" > say loc(here) You say "#367" See also: rloc(), room(), where(). & RLOC() Function: rloc(<object>,<levels>) This function may be used to get the location of an object's location (for which you would previously use 'loc(loc(<object>))', which fails if you don't control <object>'s location). <levels> indicates the number of nested 'loc' calls to make, so 'loc(loc(<object>))' could be replaced with 'rloc(<object>,2)'. If rloc() encounters a room, the dbref of the room is returned. You must either control the object or be nearby for it to work. When used on an exit it returns the destination of the exit. You can also use rloc() to find the location of players that are not set UNFINDABLE. rloc(<object>,0) is the same as num(<object>), and rloc(<object>,1) is the same as loc(<object>). See also: loc(), where(). & WHERE() Function: where(<object>) This function returns the "true" location of an object. You must control the object or be near it in order for it to work. For players and things, the "true" location is the normal location of the object. For exits, the "true" location is the source room. For rooms, it is #-1. See also: loc(), rloc(). & OWNER() Function: owner(<object>) owner(<object>/<attrib>) The first form of the owner() function returns the dbref of the owner of the object. The object must either be yours or nearby. The second form returns the owner of an attribute on the named object. You must own either the object or the attribute. & NAME() name(<dbref>) This function returns the name of the indicated object. When called with an exit it returns the only the first alias. See also: fullname(). & FULLNAME() Function: fullname(<dbref>) This function returns the full name of the indicated object. This is the same as name() in all cases except when <dbref> is an exit, then all the aliases are returned as well. See also: name(). & NEXT() next(<thing>) If thing is an exit in a room, then next will return the next nondark exit in the list of exits for that room. If thing is an object, then next will return the next object in the inventory list that the object is in. Otherwise, it returns a '#-1' string. & AND() Function: and(<boolean1>,<boolean2>[,<booleanN>]...) Takes two or more booleans, and returns 1 if they are all each equivalent to true(1). See also: BOOLEAN VALUES, or(), not(), xor(). & OR() Function: or(<boolean1>,<boolean2>[,<booleanN>]...) Takes two or more booleans, and returns 1 if at least one is equivalent to true(1). See also: BOOLEAN VALUES, and(), not(), xor(). & NOT() Function: not(<boolean>) Takes a boolean value, and returns its inverse. So, if the input is equivalent to true(1) it returns a 0, and if the input is equivalent to false(0), it returns a 1. See also: BOOLEAN VALUES, and(), or(), xor(). & XOR() Function: xor(<boolean1>,<boolean2>[,<booleanN>]...) Takes two or more booleans, and returns 1 if an odd number of them are equivalent to true(1). See also: BOOLEAN VALUES, and(), nor(), or(). & gt() Function: gt(<integer1>,<integer2>) Takes two integers, and returns 1 if and only if <integer1> is greater than <integer2>, and 0 otherwise. Warning: passing anything but integers will produce unexpected results, as non-numeric strings usually are treated as numeric 0. Example: > say gt(4,5) You say "0" > say gt(5,5) You say "0" > say gt(6,5) You say "1" > say gt(foo, bar) You say "0" See also: lt(), lte(), gte(), eq(), neq(). & gte() Function: gte(<integer1>,<integer2>) Takes two integers, and returns 1 if and only if <integer1> is greater than or equal to <integer2>, and 0 otherwise. Warning: passing anything but integers will produce unexpected results, as non-numeric strings usually are treated as numeric 0. Example: > say gte(4,5) You say "0" > say gte(5,5) You say "1" > say gte(6,5) You say "1" > say gte(foo, bar) You say "1" See also: lt(), lte(), gt(), eq(), neq(). & lt() Function: lt(<integer1>,<integer2>) Takes two integers, and returns 1 if and only if <integer1> is less than <integer2>, and 0 otherwise. Warning: passing anything but integers will produce unexpected results, as non-numeric strings usually are treated as numeric 0. Example: > say lt(4,5) You say "1" > say lt(5,5) You say "0" > say lt(6,5) You say "0" > say lt(foo, bar) You say "0" See also: lte(), gte(), gt(), eq(), neq(). & lte() Function: lte(<integer1>,<integer2>) Takes two integers, and returns 1 if and only if <integer1> is less than or equal to <integer2>, and 0 otherwise. Warning: passing anything but integers will produce unexpected results, as non-numeric strings usually are treated as numeric 0. Example: > say lte(4,5) You say "1" > say lte(5,5) You say "1" > say lte(6,5) You say "0" > say lte(foo, bar) You say "1" See also: lt(), gte(), gt(), eq(), neq(). & EQ() Function: eq(<integer1>,<integer2>) Takes two integers, and returns 1 if they are equal and 0 if they are not. Warning: passing anything but integers will produce unexpected results, as non-numeric strings usually are treated as numeric 0. Example: > say eq(1,-1) You say "0" > say eq(5,5) You say "1" > say eq(foo, bar) You say "1" See also: lt(), lte(), gte(), gt(), neq(). & NEQ() Function: neq(<integer1>,<integer2>) Takes two integers, and returns 1 if they are not equal and 0 if they are equal. Warning: passing anything but integers will produce unexpected results, as non-numeric strings usually are treated as numeric 0. Examples: > say neq(1,-1) You say "1" > say neq(5,5) You say "0" > say neq(foo, bar) You say "0" See also: lt(), lte(), gte(), gt(), eq(), not(). & CAT() Function: cat(<string>[,<stringN>]) cat returns a string made up of the contents of string1 through stringN, with each string separated from its neighbors by a space. Example: > say cat(this is, a test) You say "this is a test" > say cat(This is,another,test of the,CAT function) You say "This is another test of the CAT function" & MEMBER() Function: member(<list>, <word>[, <delim>]) Member takes a list and a word, and returns the position of that word within the list. If the word does not occur in the list, then 0 is returned. Unlike match(), member() does not check for wildcarding, and the cases of <list> and <word> are significant. A word is defined as a string which has no interior spaces. So 'hello' would be one word, while 'hello there' would be two. <delim> may be used to specify a delimiter other than a space. Example: > say member(This is a member test, member) You say "4" > say member(This is a member test, Member) You say "0" > say member(This is a member test, *e*) You say "0" > say member(This is a member test, is a) You say "#-1 CAN ONLY TEST ONE ELEMENT" See also: LISTS, findelem(), match(), strmatch(). & REMOVE() Function: remove(<list>, <word>[, <delim>]) Remove takes a list and a word, and returns the list, with the word deleted from it. <delim> may be used to specify a delimiter other than a space. Example: > say remove(this is a test, is) You say "this a test" > say remove(You can't remove, this) You say "You can't remove" > say remove(You can't remove multiple words, You can't) You say "#-1 CAN ONLY DELETE ONE ELEMENT" > say remove(How about an o-separated list, w ab, o) You say "Hout an o-separated list" & STARTTIME() Function: starttime() Returns a string which is the time the MUX last rebooted. The time is in the same format as the TIME() function returns. Example: > say starttime() You say "Sat Dec 7 00:09:13 1991 See also: convtime(). & SECS() Function: secs([<zonename>]) The optional <zonename> parameter may be "utc" or "local". If no <zonename> is given, "utc" is assumed. local - Returns an integer which corresponds to the current local time on the machine running the MUX. This integer is affected by timezones and daylight savings time and is therefore primarily useful in conjunction with convsecs(..,utc). utc - Returns the number of seconds (not counting leap seconds) since Jan 01 00:00:00 1970 UTC. This count of seconds is not affected by timezone or daylight savings time and is useful for calculating durations between two absolute points in time. Example: > say secs() You say "957557434" ... wait a bit ... > say secs() You say "957557447" > say secs(local) You say "957532580" See also: convsecs(), convtime(), time(). & WORDS() words(<string>[, <delim>]) Returns the number of words in <string>. <delim> may be used to specify a delimiter other than a space. Example: > say words(This is a test) You say "4" say words(Would you like coffee or perhaps tea?) > You say "7" say words(This:is:a:colon:separated:list,:) > You say "6" & VERSION() Function: version() Returns a string which contains various version information for the MUX you're on. Example: > version TinyMUX Beta version 2.0 patchlevel 0 #3 Build date: Thu Dec 5 10:10:07 EST 1991 > say version() You say "TinyMUX Beta version 2.0 patchlevel 0 #3" & HOME() home(<object>) Returns the object's home. Example: > exam me Mortal(#226Pc) Type: PLAYER Flags: CONNECTED Desc:Just a plain, old boring Mortal. You know. Owner: Mortal Key: VA:foobar Clams: 920 Last:Thu Dec 19 08:57:21 1991 Home: Mortal's Room(#367R) Location: The Town Square > say home(me) You say "#367" & MONEY() Function: money(<object>) Returns an integer equal to the amount of money <object> has (if it is a player) or is worth (otherwise). Example: > score You have 1052 clams. > say money(me) You say "1052" > exam sac test Sac Test(#287V) Type: THING Flags: VISUAL Owner: Beaker Key: *UNLOCKED* Clams: 20 Home: Limbo(#0RLDAJ) Location: The Town Square > say money(sac test) You say "20" & LCON() Function: lcon(<object>) Returns a space-separated list of the contents of <object> which are visible to the person running the function. Example: > i t1(#366) radio(#223) The Wizard's Pointy Hat(#188SO) You have 42463 clams. > say lcon(me) You say "#366 #223 #188" See also: lexits(), @dolist. & LEXITS() Function: lexits(<loc>) Returns a space-separated list of the exits in <loc> and its parents. Dark exits are not returned unless you own the location. Example: > look here The Town Square You are in the town square. All around you ..... Obvious exits: foo up southeast sw north > say lexits(here) You say "#302 #10 #9 #8 #6" See also: lcon(), @dolist, PARENT OBJECTS. & SECURE() Function: secure(<string>) Returns <string> after replacing the characters [](){};%\$ with spaces. This prevents strings entered by players from causing undesired side effects when used, such as making your object perform unintended commands or give out information to which you have access. Note that this function is only needed when the resulting string is to be passed through the @force command or be used as an attribute for an object (like the success message for a mail message object). > @va me=Sneak a peek at Wiz's desc... [get(#1/desc)] > say secure(%va) You say "Sneak a peek at Wiz's desc... get #1/desc " > say secure($foobar:this {is} a really, tough ; test.) You say " foobar:this is a really tough test." Note: 'say secure(Sneak a peek at Wiz's desc... [get(#1/desc)])' does not produce the expected result because the argument is evaluated BEFORE being processed by secure(), therefore the [get()] call has already been performed. See also: escape(). & ESCAPE() Function: escape(<string>) Returns <string> after adding an escape character (\) at the start of the string and also before each of the characters %;[]{}\ that appear in the string. This prevents strings entered by players from causing undesired side effects when used, such as making your object perform unintended commands or give out information to which you have access. Note that this function is only needed when the resulting string is to be passed through the @force command or be used as an attribute for an object (like the success message for a mail message object). This function has the advantage over the secure() function in that the string the user sees after evaluating it is the same as the original string. Example: You say "\Sneak a peek at Wiz's desc... \[get(#1/desc)\]" Note: 'say escape(Sneak a peek at Wiz's desc... [get(#1/desc)])' does not produce the expected result because the argument is evaluated BEFORE being processed by escape(), therefore the [get()] call has already been performed. See also: secure(). & MUDNAME() Function: mudname() Returns the name of the MUD. This is usually (but not necessarily) the name that appears in the various mud lists, and is the name that the mud is listed under in reports from RWHO servers (that is, if the mud sends its WHO information to an RWHO server). Example: > say mudname() You say "TestMUX" & CAPSTR() Function: capstr(<string>) Returns <string> with the first character capitalized. If the first character is not a letter, this function returns the string unmodified. Example: > say capstr(this is a string I want capitalized) You say "This is a string I want capitalized" See also: lcstr(), ucstr(). & LCSTR() Function: lcstr(<string>) Returns <string> with all letters converted to lowercase. Example: > say lcstr(This is something I want to TEST) You say "this is something i want to test" See also: capstr(), ucstr(). & UCSTR() Function: ucstr(<string>) Returns <string> with all letters converted to uppercase. Example: > say ucstr(This is a test, really!) You say "THIS IS A TEST, REALLY!" See also: capstr(), lcstr(). & LNUM() Function: lnum(<number1>[,<number2>][,<sep>]) If only given one argument, this function returns a list of numbers from 0 to <number1>-1. If <number1> less than 1, nothing is returned. If given at least two arguments, this function returns a list of numbers from <number1> to <number2>. If <number2> is less than <number1>, the list will be in descending order, otherwise, the list will be in ascending order. Negative integers are valid. <sep> is used as the separator character, if given. Examples: > say lnum(5) You say "0 1 2 3 4" > say lnum(3,7) You say "3 4 5 6 7" > say lnum(4,-2,|) You say "4|3|1|0|-1|-2" > say lnum(2,6,@@) You say "23456" & LATTR() Function: lattr(<object>[/<wild-pattern>]) Returns a list of the attributes set on <object>. If <wild-pattern> is given, only attributes matching it are returned. Example: > ex me Mortal(#226Pc) .... VC:Mon Sep 9 12:09:01 1991 VE:baz Last:Thu Dec 19 08:57:21 1991 VV(#2+):Foof! Domain:Abusees .... > say lattr(me) You say "Desc VC VE Last VV Domain" > say lattr(me/v*) You say "VC VE VV" See also: @dolist. & REVERSE() Function: reverse(<string>) Reverses the order of the characters of <string>. Examples: > say reverse(This is a test) You say "tset a si sihT" > say reverse(This is a test, Really...) You say "...yllaeR ,tset a si sihT" > say reverse(A man, a plan, a canal -- Panama!) You say "!amanaP -- lanac a ,nalp a ,nam A" See also: revwords(). & REVWORDS() Function: revwords(<string>[, <delim>]) Reverses the order of the words of <string>. A word is considered to be any sequence of nonblank characters, separated by blanks, so punctuation characters that follow a word are considered part of the word. <delim> may be used to specify a delimiter other than a space. Examples: > say revwords(This is a test. Really...) You say "Really... test, a is This" > say revwords(Was it a cat I saw?) You say "saw? I cat a it Was" See also: reverse(). & BEFORE() Function: before(<string1>, <string2>) Returns the portion of <string1> that occurs before <string2>. If <string2> does not occur in <string1>, the entire string is returned. If you want to return the portion of the string after the first space, use the first() function instead. This function is case sensitive. Examples: > say before(This is a test,a) You say "This is " > say before(This is a test,is) You say "Th" > say before(This is a test, nope) You say "This is a test" See also: after(), first(), rest(). & AFTER() Function: after(<string1>, <string2>) Returns the portion of <string1> that occurs after <string2>. If <string2> does not occur in <string1>, a null string is returned. If you want to return the portion of the string after the first space, use the rest() function instead. This function is case sensitive. Examples: > say after(This is a test,a) You say " test" > say after(This is a test,is) You say " is a test" > say after(This is a test, nope) You say "" See also: before(), first(), rest(). & ROOM() Function: room(obj) Returns the number of the room that <obj> is in, or would be in if it executed LEAVE commands until it got to a room. You can find out the containing room of objects you own, nearby objects, and findable players. Example: > i You are carrying: hat(#368) cat(#325) > look Mortal's Room(#367R) A bare room with nothing in it but a bed and a chair. > say I am in [room(me)], the cat is in room [room(cat)]. You say "I am in #367, the cat is in room #367." > @fo hat=get cat cat has left. > say The cat is in [loc(#325)] within room [room(#325)]. You say "The cat is in #368 within room #367." See also: loc(), UNFINDABLE. & SEARCH() Function: search([<player>] [<class>=<restriction>[,<low>[,<high>]]]) The search() function returns a list of objects that match the search criteria, which are the same as with the @search command. This function costs as much as the @search command, so repeated use is expensive. Caution: if you use the [ and ] characters in an Eval selection you will need to escape them. Examples: > say search() You say "#226 #289 #325 #364 #368 #369" > @stats me 6 objects = 0 rooms, 0 exits, 5 things, 1 players. (0 garbage) > say search(eval=\[eq(money(##),1)\]) You say "#289 #325 #364 #368 #369" > say search(player=wizard) You say "#1" See also: @search, SEARCH CLASSES. & STATS() Function: stats([<player>]) This function returns information about the number of objects on the MUX, much like the @stats command. If the argument is omitted or is 'all', then the stats for the entire MUX are returned, otherwise the stats for the named player are returned. You can only get stats for yourself. The stats are returned as a set of 6 numbers, in the same order as reported by the @stats command: total objects, rooms, exits, things, players, and garbage. This command costs as much as the equivalent @stats command (ie: '@stats/all' or '@stats <player>', not the free '@stats'). Examples: > @stats me 6 objects = 0 rooms, 0 exits, 5 things, 1 players. (0 garbage) > say stats(me) You say "6 0 0 5 1 0" > say stats() You say "377 51 165 134 20 7" > @stats/all 377 objects = 51 rooms, 165 exits, 134 things, 20 players. (7 garbage) See also: @stats. & ITER() Function: iter(<list>, <eval>[, <delim>]) <list> is a <delimter>-separated list of strings, which can be object numbers, attributes, or arbitrary words. <eval> is a string that is to be evaluated once for each item in <list>, replacing the special symbol ## with the corresponding item from <list>, and the symbol #@ with the position within the list being iterated. A space-separated list of the results of these evaluations is returned to the caller. The effect is very similar to @dolist, except that the results are made into a list and returned, not executed. Examples: > say iter(This is a test,strlen(##)) You say "4 2 1 4" > say iter(This is a test,{strlen(##)}) You say "4 2 1 4" > say iter(lnum(10),mul(mul(##,##),10)) You say "0 10 40 90 160 250 360 490 640 810" > say iter(lcon(me),[name(##)]..[money(##)]) You say "test..1 t1..1 radio..1 The Wizard's Pointy Hat..1" > say iter(Was it a cat I saw,[words(##)] #@,s) You say "1 1 4 2 1 3" See also: @dolist, list(), parse(). & LIST() Function: list(<list>, <eval>[, <delim>]) This function is exactly like iter() but serves a specialized purpose: MUX has a buffer limit, and for things like lists of players, iter() can quickly become inadequate, since the output is cut off before the listing is finished. The normal way to handle this is to use a @dolist/@pemit combination, but that takes many queue cycles. list() takes <list>, <eval>, and an optional delimiter, and evaluates them exactly like iter(). The difference is the output: iter() produces a space seperated list, while list() outputs each list item on a new row of the screen. NOTE: This is a side effect function. It does not return anything, instead, it prints its output directly to the screen of the player causing the function to be evaluated. Since it does this, it is not hampered by the buffer limit. See also: iter(), @dolist, parse(). & LOCATE() Function: locate(<looker>,<string>,<where>) The locate function is used to look for an object from the perspective of <looker> (You must own <looker>). The database number of the item that is found is returned. The <where> parameter specifies a list of places to look, from this list: a - Look for absolute references (#<number>) c - Look for exits carried by <looker> (and by <looker>'s parents). e - Look for exits in <looker>'s location (and the location's parents). h - Look for 'here', which matches <looker>'s location. i - Look in <looker>'s inventory. m - Look for 'me', which matches <looker>. n - Look for <looker>'s neighbors (other objects in the same location). p - Look for player names prefixed by a '*' * - Look for everything in the above list. { 'help locate2' for more } & locate2 You may also specify qualifiers in <where> to help resolve possible ambiguities: E - Prefer exits over other types. L - Prefer unlocked exits over locked exits. P - Prefer players over other types. R - Prefer rooms over other types. T - Prefer things over other types. V - Report "Can't find..." and "Which one..." errors to <looker>. X - Select randomly if search finds multiple matches. If nothing matches, the value #-1 is returned. If more than one thing of the preferred type matches, but nothing matches exactly, the value #-2 is returned, except if the X qualifier was specified in which case one is chosen at random. If more than one thing exactly matches, one is chosen at random. If you specify more than one type preference (E, P, R, or T), then the last one entered is the one that is obeyed. The default is for no type to be preferred. { 'help locate3' for more } & locate3 Examples: > i test1(#378) test(#376) You have 42463 clams. > look Nullspace(#250R) test1(#382) > say locate(me,test,i) > say locate(me,tes,in) You say "#376" You say "#-2" > say locate(me,test,n) > say locate(here,tes,*) You say "#382" You say "#382" > say locate(me,test1,in) > say locate(me,out,e) You say "#378" You say "#252" > say locate(me,test1,in) > say locate(me,here,*) You say "#382" You say "#250" See also: num(), PARENT OBJECTS. & EDIT() Function: edit(<string>,<from>,<to>) This function edits <string>, replacing all occurrences of the substring <from> with the string <to>. If <from> is '$', then <to> is appended to <string>, while if <from> is '^', then it is prepended. Examples: > say edit(This is a test,is,x) You say "Thx x a test" > say edit(Atlantic,^,Trans) You say "TransAtlantic" See also: @edit. & U() Function: u([<obj>/]<attr>[,<arg>]...) The u function evaluates an attribute, either from the object performing the function or from another object you own, passing in arguments and returning the result. When evaluating the fetched attribute, %# refers to the original enactor and not the 'calling' object, and 'me' refers to the object that supplied the attribute. Examples: > @va me=Word is [extract(v(vb),add(%0,1),1)], arg2 is %1. > @vb me=This is a test of the u function. > say u(va,4,Testing 123) You say "Word is of, arg2 is Testing 123." > say u(va,7) You say "Word is function., arg2 is ." > say u(me/va,6,Foobar) You say "Word is u, arg2 is Foobar." See also: s(), v(), get(), get_eval(), map(). & SWITCH() Function: switch(<str>[,<pat1>,<res1>]...[,<dflt>]) The switch function compares <str> against <pat1>, <pat2>, etc (allowing * to match any number of characters and ? to match any 1 character), and returns the corresponding <resN> parameter for the first <patN> pattern that matches. If none match, then the default result <dflt> is returned. Example: > say switch(c,*a*,A,*b*,B,*c*,C,*d*,D,E) You say "C" > say switch(f,*a*,A,*b*,B,*c*,C,*d*,D,E) You say "E" > say switch(cab,*a*,A,*b*,B,*c*,C,*d*,D,E) You say "A" > say switch(f,*a*,A,*b*,B,*c*,C,*d*,D) You say "" See also: @switch, match(), ifelse(), case(). & CASE() Function: case(<str>[,<pat1>,<res1>]...[,<dflt>]) case() is like switch() but does not do wildcard matching (i.e., using *). In cases where wildcards are not needed, it performs marginally faster. See also: @switch, match(), ifelse(), switch(). & IFELSE() Function: ifelse(<expression>,<true string>,<false string>) This function returns <true string> if <expression> is true (greater than 0), <false string> otherwise. Much more efficient than an equivalent switch(). It can also return different messages based on whether <expression> is nothing or contains text. For example, ifelse(v(test),Test exists!,Test doesn't exist.) See also: switch(). & SPACE() Function: space(<count>) Returns the number of indicated spaces. If <count> is missing, negative, or cannot be converted to a number, one space is returned. This function is useful when you want to pass a single space (or more than one) as a function to an argument, because normally leading and trailing spaces are stripped from function arguments. Examples: > say space(4) You say " " > say edit(Foo bar bletch, space(), X) You say "FooXbarXbletch" & PARENT() Function: parent(<obj>) Returns the parent of <obj>. Returns #-1 if <obj> cannot be found or if you do not own <obj> and it is not set VISUAL. Example: > say parent(me) You say "#-1" > say My va is [v(va)]. You say "My va is " > @parent me=test Parent set. > say parent(me) You say "#323" > say My va is [v(va)]. You say "My va is Testing 123" See also: @parent, PARENT OBJECTS. & SIGN() Function: sign(<number>) Returns -1, 0, or 1 depending on whether its argument is negative, zero, or positive (respectively). Example: > say sign(-4) You say "-1" > say sign(4) You say "1" > say sign(0) You say "0" > say sign(-1) You say "-1" & CONN() Function: conn(<player>) Returns the number of seconds that <player> has been connected. If <player> is not connected then -1 is returned. If <player> is connected more than once, the longest connect time is returned. Example: > WHO Player Name On For Idle Doing Wizard 00:04 1m Mortal 00:11 0s Evinar 00:12 6m Idle. :) frobozz 00:32 6s 4 Players logged in. > say conn(wiz) You say "251" > say conn(e) You say "770" > say conn(frobozz) You say "-1" See also: WHO, idle(), lwho(). & IDLE() Function: idle(<player>) Returns the number of seconds that <player> has been idle. If <player> is not connected then -1 is returned. If <player> is connected more than once, the smallest idle time is returned. Example: > WHO Player Name On For Idle Doing Wizard 00:04 1m Mortal 00:11 0s Evinar 00:12 6m frobozz 00:32 6s 4 Players logged in. > say idle(wiz) You say "6" > say idle(e) You say "371" > say idle(frobozz) You say "-1" See also: WHO, conn(), lwho(). & CONVSECS() Function: convsecs(<seconds> [, <zonename>]) By default, this function converts an integer (representing a count of seconds from Jan 01 00:00:00 1970 UTC) to a local time string -- where local time is the time at the machine running the MUX. This conversion includes a timezone/daylight savings time conversion between UTC and the local time zone. If a second argument is given, it is the <zonename>: local - indicates that a conversion for timezone/DST of the 'local' server time should be applied (the default). utc - indicates that no timezone/DST conversions should be applied. When used this way, there is a unique one-to-one relationship between an integer and it's corresponding text-string which may be useful for handling other timezones and fictional settings. Example: > say secs() You say "957558109" > say secs(local) You say "957532909" > say convsecs(957558109) You say "Fri May 05 13:21:49 2000" > say convsecs(957532909, utc) You say "Fri May 05 13:21:49 2000" See also: convtime(), secs(), time(). & CONVTIME() Function: convtime(<time string> [, <zonename>]) By default, this function converts a time string (of format [Ddd] Mmm DD HH:MM:SS YYYY) into an integer which represents a count of seconds since Jan 01 00:00:00 1970 UTC not including leap secs. Where Ddd, if given, is the day of the week. Mmm is the month name, DD is the day of the month, HH is the hour in 24-hour time, MM is the minutes, SS is the seconds, and YYYY is the year. Keep in mind that the year may not be exactly four characters and it can also be negative. This server provides a proleptic Gregorian calendar with a range of supported years between 27257 BC and 30826 AD. Year 0 is 1 BC, -1 is 2 BC, ..., so 27257 BC should be given as -27256. This follows the astronomical conventions. If a second argument is given, it is the <zonename>: local - indicates that a conversion for timezone/DST of the 'local' server time should be applied (the default). utc - indicates that no timezone/DST conversions should be applied. When used this way, there is a unique one-to-one relationship between an integer and it's corresponding text-string which may be useful for handling other timezones and fictional settings. Example: > say time() You say "Wed Jun 24 10:22:54 1992" > say convtime(Wed Jun 24 10:22:54 1992) You say "709395774" > say convtime(Wed Jun 24 10:22:54 1992, utc) You say "709381374" See also: convsecs(), secs(), time(). & SORT() Function: sort(<list>[, <sort type>[, <delim>]]) Takes a list of words, numbers, or dbref, and sorts them into ascending order. Lexicographic order is used for words, and numeric order is used for numbers and dbrefs. <sort type> may be used to specify the type of sort to perform (use d for dbref, n for integer numeric, f for floating numeric, and a for alphanumeric). If omitted or left blank, the sort() function will automatically determine the type of sort to perform. If <delim> is specified, it (rather than a space) is used to separate items in the list. You may specify an alternate delimiter without specifying a sort type by passing a null <sort type> parameter. Examples: > say sort(This is a test) You say "This a is test" > say sort(98 99 100 101) You say "98 99 100 102" > say sort(foo-bar-bletch,,-) You say "bar-bletch-foo" & SETDIFF() Function: setdiff(<list1>, <list2>[, <delim>]) This function returns the difference of two sets -- i.e., the elements in <list1> that aren't in <list2>. The list that is returned is sorted. If <delim> is specified, it (rather than a space) is used to separate items in the list. Example: > say setdiff(foo baz gleep bar, bar moof gleep) You say, "baz foo" See also: setinter(), setunion(), sort(). & SETINTER() Function: setinter(<list1>, <list2>[, <delim>]) This function returns the intersection of two sets -- i.e., the elements that are in both <list1> and <list2>. The list that is returned is sorted. If <delim> is specified, it (rather than a space) is used to separate items in the list. Example: > say setinter(foo baz gleep bar, bar moof gleep) You say, "bar gleep" See also: setdiff(), setunion(), sort(). & SETUNION() Function: setunion(<list1>, <list2>[, <delim>]) This function returns the union of two sets -- i.e., all the elements of both <list1> and <list2>, minus any duplicate elements. Think of it as CAT() without duplicated words. The list returned is sorted. If <delim> is specified, it (rather than a space) is used to separate items in the list. Example: > say setunion(foo baz gleep bar, bar moof gleep) You say, "bar baz foo gleep moof" See also: setdiff(), setinter(), sort(). & MERGE() Function: merge(<string1>,<string2>,<character>) This function merges <string1> and <string2>, depending on <character>. If a character in <string1> is the same as <character>, it is replaced by the character in the corresponding position in <string2>. The two strings must be of the same length. Spaces need to be treated specially. A null character is considered to equal a space, for <character>. Examples: > say merge(AB--EF,abcdef,-) You say, "ABcdEF" > say merge(AB[space(2)]EF,abcdef,) You say, "ABcdEF" See also: splice(). & REPEAT() Function: repeat(<string>,<number>) This function simply repeats <string>, <number> times. No spaces are inserted between each repetition. Example: > say repeat(Test, 5) You say, "TestTestTestTestTest" & SPLICE() Function: splice(<list1>, <list2>, <word>[, <delim>]) This function splices <list1> and <list2> together. <list1> and <list2> are space-separated lists of words If a word in <list1> is the same as <word>, it is replaced by the word in the corresponding position in <list2>. Both lists must have the same number of words. <delim> may be used to specify a delimiter other than a space. Example: > say splice(foo bar baz,eek moof gleep,bar) You say, "foo moof baz" See also: merge(). & PI() Function: pi() Returns the value of the trigonometric constant pi to nine decimal places. Example: > say pi() You say "3.141562654" See also: acos(), asin(), atan(), cos(), sin(), tan(). & E() Function: e() Returns the value of the numeric constant e to nine decimal places. Example: > say e() You say "2.718281828" See also: exp(), ln(), log(), power(). & SIN() Function: sin(<number>) Returns the sine of <number>, expressed in radians. Examples: > say sin(0) You say "0" > say sin(fdiv(pi(),2)) You say "1" > say sin(fdiv(pi(),4)) You say "0.707107" > say sin(fdiv(pi(),6)) You say "0.5" See also: acos(), asin(), atan(), cos(), pi(), tan(). & COS() Function: cos(<number>) Returns the cosine of <number>, expressed in radians. Examples: > say cos(0) You say "1" > say cos(fdiv(pi(),2)) You say "0" > say cos(fdiv(pi(),4)) You say "0.707107" > say cos(fdiv(pi(),6)) You say "0.866025" See also: acos(), asin(), atan(), pi(), sin(), tan(). & TAN() Function: tan(<number>) Returns the tangent of <number>, expressed in radians. Examples: > say tan(0) You say "0" > say tan(1) You say "1.557408" > say tan(fdiv(pi(),4)) You say "1" See also: acos(), asin(), atan(), cos(), pi(), sin(). & ASIN() Function: asin(<number>) Returns the arcsine of <number>, expressed in radians. Examples: > say asin(0) You say "0" > say asin(1) You say "1.570796" > say asin(0.707101) You say "0.78539" > say asin(0.5) You say "0.523599" See also: acos(), atan(), cos(), pi(), sin(), tan(). & ACOS() Function: acos(<number>) Returns the arc-cosine of <number>, expressed in radians. Examples: > say acos(0) You say "1.570796" > say acos(1) You say "0" > say acos(0.707101) You say "0.785406" > say acos(0.866025) You say "0.5236" See also: asin(), atan(), cos(), pi(), sin(), tan(). & ATAN() Function: atan(<number>) Returns the arctangent of <number>, expressed in radians. Examples: > say atan(0) You say "0" > say atan(1) You say "0.785398" > say atan(1.557408) You say "1" See also: acos(), asin(), cos(), pi(), sin(), tan(). & FLOOR() Function: floor(<number>) Returns the largest integer less than or equal to <number>. <number> may be a floating point number, and an integer result is returned. Examples: > say floor(5) You say "5" > say floor(5.2) You say "5" > say floor(5.8) You say "5" > say floor(-5) You say "-5" > say floor(-5.2) You say "-6" See also: ceil(), div(), mod(), round(), trunc(). & CEIL() Function: ceil(<number>) Returns the smallest integer greater than or equal to <number>. <number> may be a floating point number, and an integer result is returned. Examples: > say ceil(5) You say "5" > say ceil(5.2) You say "6" > say ceil(5.8) You say "6" > say ceil(-5) You say "-5" > say ceil(-5.2) You say "-5" See also: div(), floor(), mod(), round(), trunc(). & TRUNC() Function: trunc(<number>) Returns the value of <number> after truncating off any fractional value. <number> may be a floating point number, and an integer result is returned. Examples: > say trunc(5) You say "5" > say trunc(5.2) You say "5" > say trunc(5.8) You say "5" > say trunc(-5) You say "-5" > say trunc(-5.2) You say "-5" See also: div(), floor(), mod(), round(). & ROUND() Function: round(<number>,<places>) Rounds <number> to <places> decimal places. <number> may be a floating point number, and an integer result is returned. Examples: > say round(5,0) You say "5" > say round(5.123,1) You say "5.1" > say round(9.8765,3) You say "9.877" > say round(5.5,0) You say "6" > say round(-5.5,0) You say "-6" See also: div(), floor(), mod(), trunc(). & SQRT() Function: sqrt(<number>) Returns the square root of <number>. <number> may be a floating point number, and a floating point result is returned. <number> may not be negative. Examples: > say sqrt(2) You say "1.414214" > say sqrt(100) You say "10" > say sqrt(0) You say "0" > say sqrt(-1) You say "#-1 SQUARE ROOT OF NEGATIVE" See also: power(). & SQUISH() Function: squish(<text>) This function literally 'squishes' the given text, reducing multiple instances of spaces to a single space, after evaluating everything normally. & POWER() Function: power(<number>, <power>) Returns the result of raising <number> to the <power>'th power. <number> may not be negative. <number> and <power> may be floating point numbers, and a floating point result is returned. Examples: > say power(2,3) You say "8" > say power(9, 0.5) You say "3" > say power(100,pi()) You say "1919487.587204" > say power(5, 0) You say "1" > say power(0, 0) You say "1" > say power(2,-3) You say "0.125" > say power(-2,3) You say "#-1 POWER OF NEGATIVE" See also: exp(), ln(), log(), sqrt() & LN() Function: ln(<number>) Returns the result of taking the natural logarithm (base e) of <number>. <number> may be a floating point number, and a floating point result is returned. Examples: > say ln(0) You say "#-1 LN OF NEGATIVE OR ZERO" > say ln(1) You say "0" > say ln(e()) You say "1" > say ln(10) You say "2.302585" See also: e(), exp(), log(), power(). & LOG() Function: log(<number>) Returns the result of taking the common logarithm (base 10) of <number>. <number> may be a floating point number, and a floating point result is returned. Examples: > say log(0) You say "#-1 LOG OF NEGATIVE OR ZERO" > say log(1) You say "0" > say log(10) You say "1" > say log(e()) You say "0.434294" See also: e(), exp(), ln(), power(). & EXP() Function: exp(<power>) Returns the result of raising the numeric constant e to <power>. <power> may be a floating point number, and a floating point result is returned. Examples: > say exp(0) You say "1" > say exp(1) You say "2.718282" > say exp(2) You say "7.389056" See also: e(), log(), ln(), power(). & PARSE() Function: parse(<list>,<eval>[,<delimiter>]) This function takes each element of <list>, evaluates <eval> after substituting it for ##, and constructs a space-separated list of the results. Examples: > say parse(1 2 3 4 5,add(##,1)) You say "2 3 4 5 6" > say parse(This|is|a|string|length|test,strlen(##),|) You say "4 2 1 6 6 4" See also: @dolist, iter(), map(). & CONTROLS() Function: controls(<object>,<victim>) Returns 1 if <object> controls <victim>, 0 otherwise. Examples: > say controls(me,me) You say "1" > say controls(me,#1) You say "0" > say controls(#1,me) You say "1" See also: CONTROL. & map() Function: map([<obj>/]<attr>, <list>[, <delim>]) This function is nearly identical to an iter() operating on u() function. Each member of <list> is passed to the result of fetching <attr> as %0, and the results are used to form a new list, separated by the delimiter character. <delimiter> may be used to specify a delimiter other than space. Examples: > &ADD_ONE object=add(%0,1) > say map(object/add_one,1 2 3 4 5) You say "2 3 4 5 6" See also: filter(), fold(), iter(), parse(), u(). & filter() Function: filter([<obj>/]<attr>, <list>[, <delim>]) This function evaluates the contents of <attr> for each element of <list>, passing it in as %0. A <delimiter>-separated list is returned of those elements for which the evaluation returns the value 1. <delimiter> may be used to specify a delimiter other than space. Examples: > &IS_ODD object=mod(%0,2) > say filter(object/is_odd,1 2 3 4 5) You say "1 3 5" See also: u(), map(), fold() & fold() Function: fold([<obj>/]<attr>, <list>[, <base-case>[, <delim>]) This function iteratively processes a list through a function, feeding the result of one step into the next step as %0, passing in the next element from the list as %1. If a base case is provided, it is used as the initial %0. If not, the first list element is passed as %0 and the second is passed as %1, and subsequent iterations proceed normally. <delimiter> may be used to specify a delimiter other than space, but you must specify a base case in order to specify the delimiter. Examples: > &REP_NUM object=[%0][repeat(%1,%1)] > say fold(object/rep_num,1 2 3 4 5,->) You say "->122333444455555" > &ADD_NUMS object=add(%0,%1) > say fold(object/add_nums,1 2 3 4 5) You say "15" See also: u(), iter(), map(), filter() & RJUST() Function: rjust(<string>, <length>[, <fill>]) This function pads a string with leading <fill> characters, or with spaces if no fill character is given) ("right-justifies") so it is <length> long. If <string> is longer than <length>, the <string> is returned; it is not truncated. Examples: > say -[rjust(foo,6)]- You say "- foo-" > say %r0[rjust(foo,6)]7%r01234567 You say " 0 foo7 01234567" > say =[rjust(bar,5,.)]= You say "=..bar=" See also: ljust(), strlen(). & LJUST() Functions: ljust(<string>, <length>[, <fill>]) This function pads a string with trailing <fill> characters, or with spaces if no fill character is given) ("left-justifies") so it is <length> long. If <string> is longer than <length>, the <string> is returned; it is not truncated. Examples: > say -[ljust(foo,6)]- You say "-foo -" > say %r0[ljust(foo,6)]7%r01234567 You say " 0foo 7 01234567" > say =[ljust(bar,5,.)]= You say "=bar..=" See also: rjust(), strlen(). & R() Function: r(<number>) The r() function is used to access "local registers", and returns the contents of the specified register. There are ten such registers, numbered 0 through 9. The local registers are normally cleared at the start of each command, but are preserved across the commands that compose an actionlist, as well as commands that directly trigger actionlists, such as @switch, @trigger, and @dolist. See also: setq(), setr(). & SETQ() Function: setq(<number>,<string>) The setq() function is used to copy strings into local registers. It returns a null string; it is a purely "side effect" function. There are ten local registers, numbered 0 through 9. They are cleared at the start of each interactive command, but are preserved across the command queue. They are most useful for storing complex function evaluations which are used repeatedly within a single command. The local registers may be read via the r() function, and a common use of setq()/r() is to temporarily store the result of a complex evaluation whose result is needed more than once. setq() can be used to improve the readability of MUX code, as well as to cut down the amount of time needed to do complex evaluations. Example: > &TEST me=Test on [mudname()] at [time()]. > say [setq(0,u(TEST))]'[r(0)]' has length [strlen(r(0))]. You say "'Test on TestMUX at Tue Feb 23 17:00:51 1993.' has length 45." See also: r(), setr(). & SETR() Function: setr(<number>,<string>) This function is identical to setq(), but returns <string>. See also: setq(), r(). & SHUFFLE() Function: shuffle(<word1> <word2> <...<wordN>[,<delimiter>]) This function shuffles the order of words in a list, returning a random permutation of its elements. Example: > say shuffle(foo bar baz gleep) You say "baz foo gleep bar" & SCRAMBLE() Function: scramble(<string>) This function scrambles a string, returning a random permutation of its characters. Note that this function does not pay any attention to spaces or other special characters; it will scramble these characters just like normal characters. Example: > say scramble(abcdef) You say "cfaedb" See also: SHUFFLE() & SORTBY() Function: sortby([<obj>/]<attrib>,<list>[,<delimiter>]) This sorts an arbitrary list according to the u-function <obj>/<attrib>. This u-function should compare two arbitrary elements, %0 and %1, and return zero (equal), a negative integer (element 1 is less than element 2) or a positive integer (element 1 is greater than element 2). A simple example, which imitates a normal alphabetic sort: > &ALPHASORT test=[comp(%0,%1)] > say [sortby(test/ALPHASORT,foo bar baz)] You say "bar baz foo" A slightly more complicated sort. #1 is "God", #2 is "Amby", "#3" is "Bob": > &NAMESORT me=[comp(name(%0),name(%1))] > say [sortby(NAMESORT,#1 #2 #3)] You say "#2 #3 #1" Warning: the function invocation limit applies to this function. If this limit is exceeded, the function will fail _silently_. List and function sizes should be kept reasonable. & TRANSLATE() Function: translate(<string>, <type>) This function takes <string>, and converts all raw ANSI color codes and carriage returns to either MUX substitutions, or to spaces. If <type> is 0 or 's', the raw codes are converted to spaces, if it is 1 or 'p', the codes are converted to MUX %c and %r substitutions. & TRIM() Function: trim(<string> [,<trim style> [,<trim character>]]) This function will trim trailing and/or lead characters on the string that you specify. <trim character> specifies the character to trim (default is space), and <trim style> tells the kind of trimming to perform (default is trim both sides of the string). The following values for <trim style> are recognized: 'b' : Trim both ends of the string (default) 'l' : Trim the left end of the string. 'r' : Trim the right end of the string. Note: anything else specified for <trim style> will trim both sides. Example: > say trim(;;;Wacka;;;,;) You say "Wacka" > say trim(%b%b%b Polly Parrot %b%b%b%b,,r) You say " Polly Parrot" > say trim(---Trim Rules!---,-,l) You say "Trim Rules!---" See also: center(), ljust(), rjust(). & CENTER() Function: center(<string>,<width>[,<fill>]) This function will center a string in a string <width> characters wide, using <fil> characters for padding on either end of the string for centering. If no fill character is specified then a space is used. If <string> is longer than <width> characters, the string is returned unmodified. Example: > say center(a,5,-) You say "--a--" > say center(*BAMF*,15) You say " *BAMF* " & INSERT() Function: insert(<list>, <pos>, <word>[, <sep>]) This function inserts a word into <list> so that the word becomes the <pos>'th element of the list, and all subsequent list elements are moved down. This means that it appears between the <pos-1>'th and <pos>'th elements of the original list. This function may also be used to append a word to a list. <delim> may be used to specify a delimiter other than a space. Examples: > say insert(This is a test, 4, new) You say "This is a new test" > say insert(Yet@Another@List, 3, Funky, @) You say "Yet@Another@Funky@List" See also: extract(), ldelete(), replace(). & REPLACE() Function: replace(<list>, <pos>, <word>[, <sep>]) This function inserts a word into <list> so that the word becomes the <pos>'th element of the list, and the word previously in that position is removed. This means that it appears between the <pos-1>'th and <pos+1>'th elements of the original list, replacing the word at that position. This function may not be used to append a word to a list. <delim> may be used to specify a delimiter other than a space. Examples: > say replace(This is a test, 4, quiz) You say "This is a quiz" > say replace(Yet@Another@Mundane@List, 3, Funky, @) You say "Yet@Another@Funky@List" See also: extract(), insert(), ldelete(). & LDELETE() Function: ldelete(<list>, <pos>[, <sep>]) This function removes a word from <list> by position. <delim> may be used to specify a delimiter other than a space. Examples: > say ldelete(This is not a test, 3) You say "This is a test" > say ldelete(Yet@Another@Mundane@List, 3, @) You say "Yet@Another@List" See also: extract(), insert(), replace(). & ISDBREF() Function: isdbref(<string>) This function will return 1 if the string passed to it is a valid dbref. To be a valid dbref the string must begin with '#' and be followed by an interger. Also, the dbref must exist in the current database as a valid object. If the object fails either of these criteria, then a 0 is returned. Example: > say isdbref(#-1) You say "0" > say isdbref(#1) You say "1" > say isdbref(This is not a dbref) You say "0" & ISNUM() Function: isnum(<string>) This function will return return 1 if the argument is a valid number and 0 if it is not. Example: > say isnum(22223.0000) You say "1" > say isnum(77) You say "1" > say isnum(22 L) You say "0" >say isnum(Bad Numbers!) You say "0" & ZONE() Function: zone(<object>) Returns the object's 'zone'. This is the dbref of the master object which defines the zone. & ZWHO() Function: zwho(<object>) Returns a list of players who are in the zone defined by <object>. Currently a wizard/royalty only function. & INZONE() Function: inzone(<object>) Returns a list of rooms in the zone defined by <object>. Currently a wizard/royalty only function. & CHILDREN() Function: children(<object>) Returns a list of objects that are parented to <object>. Currently a wizard/royalty only function. & ENCRYPT() Function: encrypt(<text>,<key>) Encrypts <text> using <key>. The text can only be unlocked with <key>, and <key> is case-sensitive. & DECRYPT() Function: decrypt(<text>,<key>) Decrypts <text> using <key>. <key> should be the same one used to encrypt the text, and is case sensitive. & MAIL() mail(<mail message #>) mail(<player name>) mail(<player>, <mail message #>) mail() The first form returns a message corresponding to that mail message number in your MUX mailbox. This function can be used to forward mail, or as a way to simply transfer mail messages to attributes on an object. The second form returns three numbers, corresponding to the number of read, unread, and cleared messages <player> has. The third form returns <player>'s <mail message #>. It works like the first form except it applies to another player. The last form returns the number of messages the evaluating player has. Only wizards can use the second and third forms of the function on other players. & MAILFROM() Function: mailfrom(<msg #>) Returns the dbref # of the player who sent you <msg #>. Wizards may specify mailfrom(<player>,<msg #>). & DEFAULT() Function: default(<obj>/<attr>,<default case>) This function returns the value of <obj>/<attr>, as if retrieved via the get() function, if the attribute exists and is readable by you. Otherwise, it evaluates the default case, and returns that. Note that the default case is only evaluated if the attribute does not exist or cannot be read. This is useful for code that needs to return the value of an attribute, or an error message or default case, if that attribute does not exist. Examples: > &TEST me=apple orange banana > say default(me/Test, No fruits!) You say "apple orange banana" > &TEST ME > say default(me/Test, No fruits!) You say "No fruits!" See also: get(), get_eval(), u(), edefault(), udefault(). & EDEFAULT() Function: edefault(<obj>/<attr>,<default case>) This function returns the evaluated value of <obj>/<attr>, as if retrieved via the get_eval() function, if the attribute exists and is readable by you. Otherwise, it evaluates the default case, and returns that. The default case is only evaluated if the attribute does not exist or cannot be read. Example: > &TEST me=You have lost [rand(10)] marbles. > say edefault(me/Test,You have no marbles.) You say "You have lost 6 marbles." > &TEST me > say edefault(me/Test,You have no marbles.) You say "You have no marbles." See also: get(), get_eval(), u(), default(), udefault(). & UDEFAULT() Function: udefault([<obj>/]<attr>,<default case>[,<arg>]...) This function returns the value of the user-defined function as defined by <attr> (or <obj>/<attr>), as if retrieved via the u() function, with <args>, if the attribute exists and is readable by you. Otherwise, it evaluates the default case, and returns that. The default case is only evaluated if the attribute does not exist or cannot be read. Examples: > &TEST me=[center(%0,5,*)] > say udefault(Test,-- BOOM --,ACK) You say "*ACK*" > &TEST me > say udefault(me/Test,-- BOOM --,ACK) You say "-- BOOM --" See also: get(), get_eval(), u(), default(), edefault(). & ULOCAL() Function: ulocal([<obj>/]<attr>[,<arg>]...) The ulocal() function is almost identical to u() in function: it evaluates an attribute, either from the object performing the function, or another object that you control or has the same owner as you, passing in arguments and returning the result. When evaluating the fetched attribute, %# refers to the original enactor and not the 'calling' object; 'me' refers to the object that supplied the attribute. However, unlike the u() function, the global registers r(0) through r(9) (%q0 - %q9) are preserved in their initial state. This means that functions "below" the level of the u() can reset global registers for temporary calculations, without needing to worry about "clobbering" the original values. This makes ulocal() particularly useful for global or shared code which calls arbitrary u() functions, where global register values need to be preserved from accidental user clobbering. See "help ulocal2" for examples. & ULOCAL2 Example of ulocal(): > &FRUIT me=apples bananas oranges pears > &SUB-FUNCTION me=[setq(0,v(FRUIT))][extract(%q0,match(%q0,%0),1)] > &TOP-FUNCTION me=[setq(0,are delicious!)][ulocal(SUB-FUNCTION,%0)] %q0 > say u(TOP-FUNCTION,b*) You say "bananas are delicious!" If SUB-FUNCTION had been called with u() instead of ulocal(): > &TOP-FUNCTION me=[setq(0,are delicious!)][u(SUB-FUNCTION,%0)] %q0 > say u(TOP-FUNCTION,b*) You say "bananas apples bananas oranges pears" In this second example, in SUB-FUNCTION, %q0 was set to "apples bananas oranges pears", so that when the u() "returned" and TOP-FUNCTION evaluated %q0, this is what was printed. In the first example, ulocal() reset the value of %q0 to its original "are delicious!" See also: u(), setq(), r() & FINDABLE() Function: findable(<object>,<victim>) Returns 1 if <object> can locate <victim>, or 0 otherwise. This checks wizard status of <object>, UNFINDABLE status of <victim>, and other related factors. If <object> would not be able to see <victim> were they in the same location a 0 will be returned. & VISIBLE() Function: visible(<object>,<victim>[/<attr>]) Returns 1 if <object> can examine <victim>, or 0 otherwise. If <object> or <victim> do not exist, 0 is returned. If an object-attribute pair is provided, 1 is returned if <object> can see <attr> on <victim>. If <attr> is not present on <victim>, 1 is returned if <object> can examine <victim>. & LAST() Function: last(<string>[, <delim>]) Returns the last word of a string, that is, everything to the right of the last space in the string, or the entire string if there are no spaces in the string. <delim> may be used to specify a word delimiter other than a space. Example: > say last(This is a test) You say "test" > say last(Happy-Fun-Test-Thing,-) You say "Thing" See also: first(), rest(). & MATCHALL() Function: matchall(<string>,<pattern>[,<delim>]) This function works identically to the match() function, save that it returns all matches, not just the first: It returns the index numbers of all words in the list <string> which match <pattern>. Examples: > say matchall(This is a test of a test,test) You say "4 7" > say matchall(This is testing a test,tes*) You say "3 5" See also: LISTS, match(), strmatch(). & PORTS() ports(<player name>) This function returns the list of descriptors ("ports") that a player, specified by full player name, or by dbref, is connected to. Only Wizards may use this function; if a user lacks the privileges, or the player is not connected, an empty list is returned. Otherwise, a list of ports is returned in order of most recent connection to least recent connection. These ports correspond to those given by the SESSION command. & ELEMENTS() elements(<list of words>,<list of numbers>[,<delim>]) This function returns the words in <list of words> that are in the positions specified by <list of numbers>. Optionally, a list delimiter other than a space can be separated. Examples: > say elements(Foo Ack Beep Moo Zot,2 4) You say "Ack Moo" > say elements(Foof|Ack|Beep|Moo,3 1,|) You say "Beep|Foof" & GRAB() Function: grab(<list>, <pattern>[, <delim>]) This function matches <pattern> against each word in <list>, returning the first word that matches. If no words match, then an empty string is returned. The match is not case-sensitive, and wildcard characters are permitted. <delim> may be used to specify a list delimiter other than a space. Examples: > say grab(This is a new test,?e*) You say "new" > say grab(Holodeck:#10~Airlock:#58~Dorm:#12~Brig:#83,Airlock:*,~) You say "Airlock:#58" See also: LISTS, match(). & PEMIT() Function: pemit(<list of objects>, <message>) A side effect function, with the same effect as @pemit/list <list of objects> = <message>. See also: @pemit. & EMPTY() Function: empty([<object>]) This function completely empties the stack for the calling object. If <object> is specified, and you control it, it empties the stack for <object>. See also: lstack(), items(), peek(), pop(), push(), OBJECT STACK. & ITEMS() Function: items([<object>]) items() returns the number of items that the stack of the calling object contains. If <object> is specified and you control it, then it returns the number of items in the stack of that object. See also: lstack(), empty(), peek(), pop(), push(), OBJECT STACK. & LSTACK() Function: lstack([<object>]) This function returns the contents of an object's stack as a list. If <object> is not specified, then it returns the stack of the executing object. See also: push(), pop(), peek(), empty(), items(), OBJECT STACK. & PEEK() Function: peek([<object>], [<position>]) peek() returns an item from the caller's stack without removing it from the stack. If <position> is specified, it returns the item from that position in the stack (items in the stack are numbered with 0 being the most recently push()ed item), otherwise, it returns position 0. If <object> is specified and you control it, then it returns an item from <object>'s stack. See also: lstack(), empty(), items(), pop(), push(), OBJECT STACK. & POP() Function: pop([<object>], [<position>]) pop() returns an item from the caller's stack and removes it from the stack. If <position> is specified, it returns the item from that position in the stack (items in the stack are numbered with 0 being the most recently push()ed item) and removes it, otherwise, it returns position 0. If <object> is specified and you control it, then it returns an item from <object>'s stack. See also: lstack(), empty(), items(), peek(), push(), OBJECT STACK. & PUSH() Function: push(<data>) push(<object>, <data>) push() places <data> onto the calling object's stack. If the second form is used, it places data onto <object>'s stack. See also: lstack(), empty(), items(), peek(), pop(), OBJECT STACK. & COMALIAS() Function: comalias(<player>, <channel>) comalias() returns the alias the player uses to access the named channel. Non-wizards can only use it to return their own alias. See also: comtitle() & CHANNELS() Function: channels() This function lists all the channels known to the MUX (that you can see). & COMTITLE() Function: comtitle(<player>, <channel>) comtitle() returns the comtitle the player has set on the named channel. Non-wizards can only use it to return their own comtitles. See also: comalias() & DOING() Function: doing(<player>) doing() returns the connected player's @doing entry. See also: poll() & MOTD() Function: motd() motd() returns the current MOTD as set using @motd. & POLL() Function: poll() poll() returns the current poll (the top of the @doing column in WHO) as set with the @poll command. See also: doing() & OBJECT STACK NOTE: The object stack is completely different from the command stack ('help stack'). A stack is a LIFO structure, meaning that the last, most recent thing you place into it is the first thing you get out of it. You 'push' an item onto the stack, and you can 'pop' it off, or merely take a 'peek' at it. If you pushed the word 'foo', and then the word 'bar', and popped something off the stack, you would first pop 'bar', then 'foo'. You pop or peek in the reverse order that you pushed. The object stack can hold any kind of information. In this manner they are similar to r-registers, but are more flexible. There is a high limit to the number of stack entries you can have (usually 100), and stack entries are preserved until you pop them off or empty the stack. { 'help OBJECT STACK2' for more } & OBJECT STACK2 Example: > say [push(world!)][push(Hello)]We'll print these... We'll print these... > say [pop()] [pop()] Hello world! empty() is used to clear the stack, items() shows the number of entries in the stack. See also: lstack(), empty(), items(), push(), peek(), pop(). & OBF The OBF Flag is used to denote someone using a form of invisibility, most commonly the vampiric discipline of Obfuscate. They must also have an attribute set on them, OBF_LEVEL, which denotes the level of invisibility they posses. When this attribute is present and the flag is set on them they do not show up in the contents list of rooms. If a player moves through an exit and has OBF_LEVEL of 1 then they will no longer be invisible and will trigger the exit message. OBF_LEVEL of 2 or higher will no longer do this. At OBF_LEVEL is 3 or higher they can set their true desc in the attribute OBFDESC so that it will only be seen by those with the ability to see through their disguise. See also: HSS & HSS The HSS flag denotes someone who can see through certain levels of invisibility. They must have the HSS_LEVEL attribute set. If they have this flag and attribute set they will see anyone with a lower OBF_LEVEL then their HSS_LEVEL attribute, they will also see the OBFDESC if it is present, showing the invisible character's true appearance. However, if HSS_LEVEL is equal to OBF_LEVEL then there is a random chance that they will see through the invisibility. See also: OBF & UMBRA The UMBRA flag is used to denote an object which is in the umbra. They will see the room's UMBRADESC if it is present and will not see or be seen by those not set UMBRA. & SHROUD The SHROUD flag is used to denote an object who is in the shroud. They can be heard by those set MEDIUM but not seen. They see the WRAITHDESC of the room if it is present and they see anything set SHROUD as well as other normally visible objects. & MEDIUM The MEDIUM flag denotes a player who is a medium. With this flag set they can hear what is said by those set SHROUD but not see them. They can see those who are visible normally only. & MATRIX The MATRIX flag is used to denote an object who is in the Matrix or Digital Web. Rooms will list contents as |Icons| and will only list players and objects also set MATRIX. MATRIXDESC can be set on a player or object as the description of their icon. & FAE The FAE flag is used to denote an object which is visible to others with a regular description but see's FAEDESC's and those set CHIMERA. Most commonly used for Changelings and those who have been Enchanted by one. & CHIMERA The CHIMERA flag is used to denote an object who is invisible to all but those set CHIMERA and FAE. & PEERING The PEERING flag is used to denote an object which is looking into another realm but is not visible there. It requires the attribute PEERING_REALM be set with a value of the realm being watched. The value MUST be in all uppercase letters. & CANSEE() Syntax: CANSEE(looker, lookee[,lookee_action]) This is useful for wizard code in the master room, help it decide who/what should be able to see who/what, and saves the softcoders the hassle of duplicating these rules in softcode. The third parameter is optional, but if present should be 0 for standing still, 1 for moving, and 2 for talking. CANSEE returns 1 or 0 depending on whether it's possible or not to see, respectively. & LINK() LINK() Function: link(<name>,<destination>) Works the same as @link, <name> and <destination> are equivalent to what comes before and after the '=' sign. Returns nothing. This is a side effect function, and should only be used when necessary. Related Topics: @link & SUBEVAL() SUBEVAL() Function: subeval(<string>) This function's usefulness is primarily useful in conjunction with v() as a way to control when evalution occurs. Escapes are evaluated, but and functions are not. The location escape is also not evaluated. When used from the command line, it's use is limited to nil because evaluation of subeval's parameters occurs before the subeval() function is called. & TEL() TEL() Function: tel(<name>,<destination>) Works the same as @tel, <name> and <destination> are equivalent to what comes before and after the '=' sign. Returns nothing. This is a side effect function, and should only be used when necessary. Related Topics: @teleport & VALID() VALID() Function: valid(<name>,<argument>) This returns true or false depending on whether the characters and arrangement of characters in <argument> satisfy the restrictions implied by <name> For example, A <name> of 'name' causes <argument> to be validated as an object name. Valid() does not check the database for existance and it does not guarantee that if you try to create such an object that the attempt will succeed. It only looks at <argument> as a string of characters. & CMDS() Function: cmds(<player>) Example: > say cmds(me) You say "100" > say cmds(me) You say "101" Returns the number of commands entered by a connected 'player'. This function returns -1 if the enactor has insufficient permission (i.e., not self and no Wizard_Who power). NOTE: Only available if server built with GAME_DOOFERMUX. & LCMDS() Function: lcmds(<object>) Returns the attribute names of any commands on a specific <object> Example: > &CMD1 me=$command1:@pemit me=blah Set. > &CMD2 me=$command2:@pemit me=blah blah Set. > say lcmds(me) You say "command1 command2" NOTE: Only available if server built with GAME_DOOFERMUX. See also: lattrcmds(). & STARTSECS() Function: startsecs() Returns the number of seconds that represents the time the MUX last rebooted. The time is measured in the same way as the secs() function. This is easier and more efficient than using convtime(starttime()). Example: > say startsecs() You say "959093815" NOTE: Only available if server built with GAME_DOOFERMUX. See also: secs(). & LATTRCMDS() Function: lcmds(<object>) Returns the names of the attributes that contain commands on a specific <object>. Example: > &CMD1 me=$command1:@pemit me=blah Set. > &CMD2 me=$command2:@pemit me=blah blah Set. > say lcmds(me) You say "CMD1 CMD2" NOTE: Only available if server built with GAME_DOOFERMUX. See also: lcmds(). & DIGITTIME() Function: digittime(<seconds>) This function converts a number of <seconds> to a digital time string and prepends the number of days if the time is greater than 23:59. Example: > say digittime(2345) You say "00:39" > say digittime(123456) You say "1d 10:18" NOTE: Only available if server built with GAME_DOOFERMUX. See also: writetime(), singletime(), exptime(), secs(), time(). & WRITETIME() Function: exptime(<seconds>) This function converts seconds to a number of time elements (hours, minutes, seconds) that is equivalent to the given number of <seconds>. This is very similar to the exptime() function, but the elements are given their long names instead of short names. Example: > say exptime(45) You say "45 seconds" > say exptime(12345) You say "3 hours 25 minutes 45 seconds" > say exptime(123456) You say "1 day 10 hours 17 minutes 36 seconds" NOTE: Only available if server built with GAME_DOOFERMUX. See also: writetime(), singletime(), digittime(), secs(), time(). & EXPTIME() Function: exptime(<seconds>) This function converts seconds to a number of time elements (hours, minutes, seconds) that is equivalent to the given number of <seconds>. This is very similar to the writetime() function, but the elements are given their short names instead of long names. Example: > say exptime(45) You say "45s" > say exptime(12345) You say "3h 25m 45s" > say exptime(123456) You say "1d 10h 17m 36s" NOTE: Only available if server built with GAME_DOOFERMUX. See also: writetime(), singletime(), digittime(), secs(), time(). & SINGLETIME() Function: singletime(<seconds>) This function converts seconds to a single time element which is the lowest approximation to the given number of <seconds>. Example: > say singletime(45) You say "45s" > say singletime(12345) You say "3h" > say singletime(123456) You say "1d" NOTE: Only available if server built with GAME_DOOFERMUX. See also: writetime(), exptime(), digittime(), secs(), time(). & LFLAGS() Function lflags(<object>) Returns the flags of <object> written out with their actual names. Example: > say flags(me) You say "PXNWcis" > say lflags(me) You say "ANSI NOSPOOF WIZARD CONNECTED IMMORTAL SAFE" NOTE: Only available if server built with GAME_DOOFERMUX. See also: flags(), type(). & CONNTOTAL() Function conntotal(<player>) Returns the number of seconds that <player> has been connected to the MUX. This also includes the current connection time. NOTE: Only available if server built with GAME_DOOFERMUX. See also: connmax(), connlast(), connnum(), connleft(), secs(), conn(). & CONNMAX() Function connmax(<player>) Returns the longest connection time that <player> has been connected to the MUX -- perhaps even the current session. NOTE: Only available if server built with GAME_DOOFERMUX. See also: conntotal(), connlast(), connnum(), connleft(), secs(), conn(). & CONNLAST() Function connlast(<player>) Returns the number of seconds that <player>'s last connection to the MUX was. NOTE: Only available if server built with GAME_DOOFERMUX. See also: conntotal(), connmax(), connnum(), connleft(), secs(), conn(). & CONNNUM() Function connnum(<player>) Returns the number connections that <player> has had to the MUX including the current connection. NOTE: Only available if server built with GAME_DOOFERMUX. See also: conntotal(), connmax(), connlast(), connleft(), secs(), conn(). & CONNLEFT() Function connleft(<player>) Returns the time stamp (number of seconds elapsed since midnight, January 1, 1970) that represents when the <player> last disconnected from the MUX. NOTE: Only available if server built with GAME_DOOFERMUX. See also: conntotal(), connmax(), connlast(), connnum(), secs(), conn(). ******************** HSPACE BASE *************************** & HSPACE Topic: HSpace Welcome to HSpace version 4.0 -- new and improved with a lemon scent. HSpace represents years of diligent work by many people and just as many years of hard play by the players who have enjoyed it! You may read the following topics: WHAT-IS-HSPACE HSADMIN HS-COMMANDS HS-NEWBIE & HS-COMMANDS Topic: HSpace Commands The following is a list of all commands that may exist on a given console. Although many commands are considered specified to a certain type of console (e.g. engineering), they may be available from other types of consoles. Where applicable, a G, E, or N has been placed next to the command to indicate a general (G) console command, an engineering (E) command, or a navigation (N) command. UNLOCK(G) UNLOAD(G) TARGET(G) QREP(G) CPOWER(G) CHEAD(G) GREP(G) FIRE(G) CONFIGURE(G) AUTOLOAD(G) LOCK(G) LOAD(G) AUTOROTATE(G) SYSREP(E) SYSPOWER(E) SYSPERC(E) VSTATS(G) SS(N) HEAD(N) AFTERBURN(N) VIEW(N) SCAN(N) LAND(N) DOCK(N) MAPRANGE(N) ABORT(N) JUMP(N) BLINK(N) BUNLINK(N) STAT(N) NOBURN(N) UNDOCK(N) TAXI(N) SREP(G) CSTAT(G) SPOSE(N) ICOM(G) BLINKS(N) CLINK(N) CSCAN(N) CGET(N) The following are quickstart commands: POWER COMPUTER SENSOR ENGINES THRUST LIFE FORE AFT PORT STAR COMM The following are general ship usage commands: BOARD DISEMBARK BOARDING CODE SECURITY SHIPNAME CHOWN SPECS DEADMAN You may get help on any of these commands with 'help <command>' If you are brand new to flying with HSpace, refer to the "HS-NEWBIE" section of the help files: help hs-newbie & HS-WEAPON-ATTRS Topic: HSpace weapon attributes Weapons loaded from the weapons database contain a variety of attributes to govern how they respond when fired. Each weapon type has a different set of attributes, but all weapons share some base sets of attributes. The following attributes can be set and retrieved for all weapon types: Gettable/Settable attributes: NAME : The name of the weapon. Gettable attributes only: TYPE : The type of the weapon (0 = lasers, 1 = missiles) See Also: HS-LASER-ATTRS, HS-MISSILE-ATTRS & HS-LASER-ATTRS Topic: HSpace laser attributes The following attributes may be set and retrieved on laser weapons loaded from the database: Gettable/Settable attributes: REGEN TIME: Time it takes for the weapon to regenerate. RANGE : Range of the weapon for attacking. STRENGTH : Damage strength when attacking. ACCURACY : Accuracy of the laser. POWER : How much reactor power is required to power up. & HS-MISSILE-ATTRS Topic: HSpace missile attributes The following attributes may be set and retrieved on missile weapons loaded from the database: Gettable/Settable attributes: RELOAD TIME: Time it takes for the weapon to reload. RANGE : Maximum range the missile can reach. STRENGTH : Damage strength when the missile hits. TURNRATE : The degrees the missile can turn at one time. SPEED : Speed of the missile in units per hour. See Also: HS-WEAPON-ATTRS, HS-LASER-ATTRS & WHAT-IS-HSPACE Topic: What is HSpace? What is HSpace? Simply put, HSpace is a space simulation package that is an easy addition to your MU*. It is fully 3-dimensional with full combat and navigation support for space vessels. Not only does it allow game players to travel realistically through space, but HSpace also provides many flexible methods for building your own tools and MU* code to produce things like ship upgrade terminals, navigational aids, etc. HSpace comes from the name Hemlock Space, and it was first developed on the Hemlock MUSH series of games. It was released in 1997 and has been increasing in popularity ever since. Now, it is written in a more object-oriented gaming language -- C++. This allows even more realistic and flexible space modeling to enhance your gaming experience! The goals of HSpace development are: easy administration, quick installation, realistic but simple playability. & HS-NEWBIE Topic: HSpace newbie Flying through space in an HSpace ship may initially seem difficult and complex, but it's really not! You simply must remember the following things: * HSpace is 3D, that means X, Y, and Z coordinates. * Most flight is based on headings and bearings. - Headings are where you want to go. - Bearings are where some object is located relative to you. * All headings and bearings have two parts: an XY angle and a Z angle. * You need speed to move. Assuming you are in your vessel and "manning" a navigation console, here are some simple things you can do to get going: 1) type sysrep This shows you your current engineering systems status. You need power to use your systems. 2) type sysperc reactor=100 This sets your reactor to 100% desired power output. You're going to need a lot of power from it to power your other systems. You can also use syspower <system>=<#> to set a fixed amount of power allocated to the system. 3) type computer If the game tells you there is insufficient power, wait a while for the reactor to power up more. You can use sysrep to keep checking your power output. 4) type cpower on This tells the computer to allocate power to your console and all of its gadgets. 5) type stat You get a navigation status display, indicating your current heading, speed, etc. 6) If you're landed on the ground, type undock. These are just some of the basic commands to get you started. From here, you'll probably want to power up the rest of your systems, set a heading, and set your speed. You can get a full listing of commands by typing help hs-commands. Enjoy! & HSADMIN Topic: HSpace Administration These HSpace administrative documents are techinical documents. While they may include some discussion of approaches and various tips for running HSpace, they are intended more as a reference guide for command usage and step by step management of the various HSpace components. This guide is divided into the following sections: HS-QUICKSTART HS-FUNCTIONS HS-OBJECTS HS-CLASSES HS-SYSTEMS HS-UNIVERSES HS-TYPES HS-CONSOLES HS-WEAPONS HS-SHIELDS HS-TERRITORIES CLASS PICTURES HS-CLONING Type 'help <section>' for information on each section. & HS-TERRITORIES Topic: HSpace Territories What is a territory? A territory is some piece of space, defined by specified boundaries. HSpace models space territories through one of two ways. These are radial and cubic territories. A radial territory defines a center of the territory and a radius to which the boundaries extend from that center. A cubic territory defines a minimum and maximum set of 3D coordinates (6 coordinates in all) that define a cube in space. When a ship travels, HSpace looks through the territories in the game to determine which territory the ship is in. If the ship enters or leaves a territory, a message is displayed to the console users on the ship. Further, HSpace triggers an attribute on the game object representing the territory, which can be useful for softcoding border alerts, welcome messages, etc. The ENTER and LEAVE (@enter, @leave) messages are displayed to console users on the ship when entering or leaving a territory, and the AENTER and ALEAVE attributes are likewise triggered. See Also: TERRITORY-SETUP, TERRITORY-ATTRS & TERRITORY-SETUP Topic: Territory setup Setting up a territory is much like setting up any other object in HSpace. You first need to create a game object to represent your territory. Perform the following steps: 1) @create My Territory 2) @space/addterritory My Territory=0 (A radial .. 1 for cubic). 3) @space/set My Territory/uid=0 (or a valid universe you have) 4) @space/set My Territory/cx=0 5) @space/set My Territory/cy=0 6) @space/set My Territory/cz=0 7) @space/set My Territory/radius=1000 There you go! You now have a radial territory with its center at 0,0,0 and a radius of 1000 units. To set the entering and leaving messages, just set the ENTER and LEAVE attributes on the object to some messages. If you want, you can set the AENTER and ALEAVE attributes with some code that gets run when a ship enters or leaves. See Also: HS-TERRITORIES, TERRITORY-ATTRS & TERRITORY-ATTRS Topic: Territory Attributes The following territories have the following attributes that can be set or retrieved. Radial:: - CX: The central X coordinate. - CY: The central Y coordinate. - CZ: The central Z coordinate. - RADIUS: The radius of the territory boundaries. - UID: The universe ID of the territory. CUBIC: - MINX: Minimum X coordinate of the boundaries. - MINY: Minimum Y coordinate of the boundaries. - MINZ: Minimum Z coordinate of the boundaries. - MAXX: Maximum X coordinate of the boundaries. - MAXY: Maximum Y coordinate of the boundaries. - MAXZ: Maximum Z coordinate of the boundaries. - UID : The universe ID of the territory. See Also: @SPACE-SET, HS_GET_ATTR(), HS_SET_ATTR() & HS-WEAPONS Topic: HSpace weapons Weapons in HSpace provide the essential means for intervessel combat, and thus may vary in nature. While most weapons will be provided by the HSpace software, it is entirely possible to create your own, softcoded weapons using the provided HSpace interface functions. Querying and damaging systems can easily be performed, making softcoded weapons possible. This help file will clearly only discuss weapons provided with the HSpace software. All weapons are stored in the weapondb located in your game/space/ directory. At present it is necessary to hand edit this database to add weapons. This will not be necessary in the final release of HSpace 4.0. The following types of weapons are currently supported: Lasers : Energy based weapons in the form of a gun. These weapons fire blasts of energy at the target and may or may not be strong enough to break through the target's shields. Missiles : Also known as torpedos, these are large projectile weapons that must be loaded onto a hardpoint and fired at the target. Missiles are limited in supply. They also possess a limited "turning rate," which means they must steer toward a target. This also makes it possible to evade less maneuverably missiles. See Also: HS-WEAPON-ATTRS, HS-LASER-ATTRS, HS-MISSILE-ATTRS & HS-QUICKSTART Topic: HSpace Quickstart Looking for a quick start for your day? Here are some quickstart answers to HSpace admin questions to get you moving along quickly. Q: I've got HSpace installed, and I've rebooted my game. Here I am, what do I do? A: Type @space. You'll see all of the current HSpace information presented to you. You'll have no classes, no universes, no ships, no planets, and some default weapons that HSpace offers. Your first step is to create a universe, so checkout the 'help hs-universes' help file. Q: What are the HSpace commands I'll want to know first? A: There's one command you'll use, and she's called @space. Refer to 'help @space' for the usage of this command and all of the wonderful options it provides. Q: Where can I set all of the configuration options I want for HSpace? A: HSpace comes with an hspace.cnf file that you can use to configure HSpace. Q: How do consoles interact with HSpace? A: Checkout the 'help hs-consoles' help file, but here's your answer. Consoles use the @nav, @eng, and @console commands to tell HSpace what they (or their users) want to do. Q: Is HSpace hard to administrate? Am I going to spend my life trying to figure out how to do everything and get it all setup? A: We hope not! Just keep a tight grip on that @space command and follow the many examples in the help files, and you will fairly easily setup your ships, planets, and other HSpace goodies. & HS-CONSOLES Topic: HSpace consoles Consoles in HSpace allow players to interact with objects in HSpace. For example, a player on a ship may want to navigate that ship, so a navigation console could be created with a set of commands to allow the player to navigate the vessel. In HSpace version 3.x and earlier, the navigation console was the "heart" of any vessel. In HSpace 4.0 this concept ceases to exist. It is the "ship object" which is the heart of the ship. All consoles on a ship then belong to that ship object (a MUSH object). Any HSpace console can use any of the @nav, @eng, and @console commands, thus allowing you to derive many types of consoles from navigation to engineering and so on. Consoles possess an added ability to make administration and development of MUSH tools easier. Most @space commands will work on consoles as if those consoles were the ship. For example, using the @space/set command requires that the ship object be specified, but any console on the ship can serve in its place. See also: HS-CONSOLE-ATTRS, HS-CONSOLE-OFFSETS &HS-CONSOLE-ATTRS Topic: HSpace console attributes Consoles provide the following attributes for setting and retrieving: Settable Attributes: XYHEADING : The current XY angle heading of the console. ZHEADING : The current Z angle heading of the console. XYOFFSET : The XY offset angle from the front of the ship. ZOFFSET : The Z offset angle from the front of the ship. CAN ROTATE: A value of 1 if the console can change headings. Otherwise, a value of 0. Gettable Attributes: CXYHEADING : The XY angle heading of the console. CZHEADING : The Z angle heading of the console. XYOFFSET : The XY offset angle from the front of the ship. ZOFFSET : The Z offset angle from the front of the ship. CAN ROTATE : A value of if the console can change headings. Otherwise, a value of 0. LOCK : The current sensor contact ID of the console target lock. WEAPONS : A list of weapon types currently on the console. See also: HS-CONSOLE-OFFSETS &HS-CONSOLE-OFFSETS Topic: HSpace console offsets HSpace consoles can serve many functions for the vessel they are attached to. They may serve as navigation consoles, engineering consoles, communications consoles, or gunnery consoles. For the latter type, the gunnery console, it is desirable to have the console turn as if it were a turret on a ship. To this end HSpace allows consoles to have XY and Z heading attributes that indicate where they are currently facing (if we can imagine a huge gun projecting out from the turret). If the CAN ROTATE attribute of a console is set to 1, the console can change its heading with the @console/head command. If set to 0, the console can not change its heading, which may be appropriate if the guns are in a fixed position or the console has no weaponry. For example, engineering consoles don't need to change headings -- there is no purpose served by this feature. The idea of a console offset is not quickly evident, but it will be evident after a short explanation. Every console that serves as a gunnery turret somewhere on the ship has a limited ability to turn to various angles. Even a turret located on the bottom of the ship can only attack targets relatively below the ship. Why? Because the bottom of the ship that the turret is attached to prevents that turret from rotating upward, into the ship, and firing at targets above the ship. Thus, each turret has an effective "hemisphere" of rotate angles. That is to say that it can rotate to angles on its side of the ship, which is 90 degrees left, 90 degrees right, 90 degrees up, and 90 degrees down. It cannot turn 120 degrees right because it would be pointing into the ship it is attached to. But how do consoles know where they are located on a vessel? We must tell the console where it is located with the two offset attributes. The first, the XYOFFSET, indicates which side of the vessel the console is on based on an offset value from the front of the ship on the XY plane. That is to say that when you are standing in the middle of the ship, where is the console located to your left and right? A value of 0 indicates that the console is in front of you (on the XY plane), while a value of 90 indicates the console is directly to you right. A value of -90 indicates the console is directly to your left, and a value of 180 (or -180) indicates the console is located behind you. Similarly, the ZOFFSET attribute indicates where the console is located in the up and down directions. A value of 0 indicates the console is directly in front of you, while values of 90 and -90 indicate the console is either directly above you or directly below you. Again, these are OFFSET values from the front of the ship, such that XYOFFSET/ZOFFSET values of 0 put the console at the front of the ship. Whatever offset values the console possesses indicates its natural heading. Thus, offset values of 90/0 indicate that the console naturally points 90 degrees clockwise from the current ship heading and in the same Z heading of the ship. By specifying combinations of the XY and Z offset values, you can position your console anywhere on the sides of the vessel. See also: HS-CONSOLE-ATTRS &HS-UNIVERSES Topic: HSpace universes The universe is the spice. The spice is the universe .. or something like that. A universe is just that .. a universe. HSpace objects exist within universes, so they have to exist before any objects can exist. Whether a ship is flying through space or sitting on the surface of a planet, it belongs to a universe. Each universe in HSpace relates to exactly one room in the game, created for the sole purpose of having a universe in the game. For each universe that exists, there must exist a room for that universe. This is needed for when ships are actively flying through space. It is also useful for looking at the room and the contents of that room to see what objects are actively in the universe. You may have many universes, or you may have one. Often it is helpful to have at least two universes, one for real ships flying through space, and one for simulator combat that shouldn't interfere with the real universe(s). See also: @SPACE-NEWUNIVERSE, @SPACE-DELUNIVERSE &HS-SYSTEMS Topic: HSpace engineering systems Engineering systems in HSpace are very conveniently modeled to provide the highest level of flexibility. Objects, such as ships, can often be very different from one another, and thus there is no way to predict which engineering systems will be present on a given space object. For all of our examples, we will refer to ships, since they are most likely to possess systems. What is an engineering system? An engineering system is really any "system" on the ship that helps it function. This may be a computer, a sensor array, a fuel management system, shields, etc. The list is nearly endless, though fortunately it's not! Systems can be given power, or they may provide power, such as with a ship's reactor. Systems may be stressed, and how easily they stress depends on how tolerant they are. Each engineering system at least possesses the following attributes: OPTIMAL POWER, TOLERANCE, STRESS, DAMAGE LEVEL, CURRENT POWER, NAME, VISIBLE "Visible" systems are those systems that you can interact with -- you can transfer power to and from it. Not all systems are visible, such as with an internal fuel management system. It manages itself and doesn't let you touch it. A ship may possess from none to many engineering systems, depending on how functional that ship is. For example, it may have jump drives, allowing it to travel at faster than light (FTL) speeds. It may, or may not, have engines, allowing it to move at sublight speeds. Many systems are included in HSpace that can be added to some HSpace objects, such as ships. See also: @SPACE-ADDSYSCLASS, @SPACE-SYSSETCLASS, @SPACE-SYSSET, HS-SYSTEM-TYPES HS-SYSTEM-ATTRS & HS-SYSTEM-TYPES Topic: HSpace system types HSpace currently supports the following types of engineering systems. Most are recommended for the common space vessel. Life Support : Supplies life support to people on the ship. Engines : Moves the ship (possibly afterburn) Jump Drive : Allows the ship to travel in hyperspace Fuel System : Provides fuel storage and allocation for the ship. Reactor : Provides power for the ship's engineering systems. Fore Shield : Protects the front of the ship. Aft shield : Protects the aft of the ship. Starboard Shield: Protects the starboard side of the ship. Port Shield : Protects the port side of the ship. Maneuv. Thrusters: Allows the ship to turn/maneuver. Sensor Array : Provides the ability to sensor sweep. Internal Computer: Provides power to consoles and ship logic. It is important to note that the absence of port and starboard shields leaves the fore and aft shields to protect the entire ship. Thus, the starboard and port shields are not required to fully protect the ship, though they may be desired for added flexibility. System names can be abbreviated for any @space commands. See Also: HS-SYSTEM-ATTRS & HS-SYSTEM-ATTRS Topic: HSpace system attributes While each of the engineering systems available is derived from the generic engineering system object, each system may have additional attributes that can be set beyond the standard tolerance, stress, damage, etc. All systems have the following attributes: OPTIMAL POWER, TOLERANCE, STRESS, DAMAGE LEVEL, CURRENT POWER, NAME, VISIBLE Additionally the following systems provide additional attributes as indicated: * Sensor Array: SENSOR RATING * Reactor: MAX OUTPUT, DESIRED OUTPUT, CURRENT OUTPUT * Maneuvering Thrusters: TURNING RATE * All Shields: REGEN RATE, SHIELD TYPE, MAX STRENGTH, STRENGTH Refer to HS-SHIELDS for more information. * Engines: MAX VELOCITY, ACCELERATION, DESIRED SPEED, CURRENT SPEED, CAN AFTERBURN, AFTERBURNING, EFFICIENCY * Jump Drive: ENGAGED, MIN SPEED, EFFICIENCY * Fuel System: BURNABLE FUEL, REACTABLE FUEL, MAX REACTABLE FUEL, MAX BURNABLE FUEL & HS-SHIELDS Topic: HSpace shields HSpace supports two types of shields on vessels: Deflector(0) and Absorption(1). Ships that have shields must possess pairs of shields. That is, they must either have no (0) shields or 2 or 4 shields. HSpace does not currently support odd numbers of shields nor greater than 4 shields. Absorption shields were used in versions of HSpace less than 4.0, and they work much like the skin on your body. The only difference is that you can't take your skin off, but let us pretend you can. When power is initially supplied to the absorption shield, the shield generator slowly begins to form a protective layer, the absorption shield. While the regeneration process may be slow, the shield can be lowered and raised subsequently without losing the charge of the shield. That is to say that the skin can be taken off and put back on without losing the strength of the skin. When an absorption shield is hit by an object or blast, it weakens. The shield regenerators will slowly begin to regenerate the shield. The shield loses effectiveness when its strength reduces to 0, at which point any objects or blasts pierce the shield to the underlying hull. Deflector shields work by producing a semi-permeable shielding layer around the ship. They can be raised and lowered quickly and never need to recharge. They work by deflecting all incoming objects and blasts up to a given strength, which is their deflection strength. For example, a small deflector shield may be able to deflect the normal space debris that the ship encounters, but it may not be able to fully deflect a laser blast from another ship. The deflector shield will deflect all damage up to its strength value. Additional damage pierces the shield to the underlying hull. If the shield regenerators are damaged, the strength of the deflector shield is weakened. &HS-OBJECTS Topics: HSpace objects Everything in HSpace is modeled as an object, thus making it an object-oriented system. Everything from a ship, to a planet, to the smallest particle of bug goo hitting the foreward shield of your vessel is modeled as an object in space. Each object has its own behavior and attributes, though many objects may be very similar to other objects (e.g. stars and planets). Each object in space must belong to a universe, and it has one of two states: active or inactive. Active objects are those that can be seen (generally speaking) in space. They are not docked in another ship. They are not landed on the surface of a planet. They are, essentially, actively in the space that makes up the universe the object belongs to. Each object in the HSpace must also have an object in the game. For example, a planet called Planet X must have an actual "thing" in the game called Planet X. The object creation command will require that you specify the object # to identify that HSpace object. Some objects, like ships, can possess engineering systems and engage in combat, while other objects, such as worm holes, serve entirely different purposes. For this reason, each object must be "setup" differently than other objects. When you create a new object, you will most likely have to initialize that object's attributes, just like assembling a new car. You must paint the car, install the radio, etc. Just as you may set an attribute on an object, you can also retrieve attributes from objects. Each object provides a variety of attributes that can, then, be set and retrieved, though these to sets of attributes may not be identical. See also: @SPACE-ADDOBJECT, @SPACE-ACTIVATE, HS-TYPES &HS-TYPES Topics: HSpace object types Many types of HSpace objects can exist in the game. The following types are currently supported by HSpace code: Type Description 0 No Type (any object) 1 Ship 2 Missile 3 Planet 4 Wormhole 5 Blackhole 6 Nebula 7 Asteroid Belt - LandingLoc For any commands that require an object type, the above types can be used. The "No Type," or type 0, can often be specified to represent all objects. Each object has its own attributes that can be set and retrieved. Because all HSpace objects are derived from a single, NOTYPE base object, they all share some similar attributes that can be set and retrieved. Some objects, such as celestial objects, will share similar celestial attributes that can be set and retrieved. See also: HS-OBJECT-ATTRS &HS-LANDINGLOC-ATTRS Topic: HSpace landingloc attributes Landing locations are a generic type of HSpace object that allows ships to dock in the bays of other ships or to land on planets. Landing locations, like all HSpace objects, have attributes that can be set and retrieved. These are as follows: Settable AND Gettable attributes: CODE : Code required to land in the location. ACTIVE : 1 if location is open for landing, 0 otherwise. CAPACITY : Object size capacity of the location. MAX CAPACITY : Maximum object size capacity of the location. The "object size capacity" refers to the volume of the landing location and its ability to hold HSpace objects (i.e. ships). For each unit of "size capacity," the location can hold 1 unit of an HSpace object size. Thus, a landing location with a current capacity of 2 could hold two, size 1 objects or one, size 2 object. As objects (ships) enter and leave the landing location, the current capacity decreases and increases to reflect the space taken up in the location by the object. &HS-SHIP-ATTRS Topic: HSpace ship attributes Ship objects in HSpace provide the following attributes that are settable and retrievable. Settable attributes: IDENT : Identification string for the ship. DESTROYED : 1 if the ship is destroyed, 0 otherwise. BOARDING CODE : Boarding code for the ship. CAN DROP : 1 if the ship can land, 0 otherwise. This attribute overrides the setting in the ship's class. DROPLOC : Dbref of the landing pad where the ship is located. DOCKLOC : Dbref of the docking bay where the ship is located. HULL : Current hull points for the ship. Gettable attributes (All of the above, plus): XYHEADING : The current XY angle heading of the ship. ZHEADING : The current Z angle heading of the ship. DXYHEADING: The desired XY angle heading of the ship. DZHEADING : The desired Z angle heading of the ship. CONSOLES : A list of console dbrefs on the ship. SROOMS : A list of registered rooms on the ship. &HS-MISSILE-OBJ-ATTRS Topic: HSpace missile object attributes Missile objects do not provide any attributes beyond the basic NOTYPE attributes of the generic HSpace object. &HS-PLANET-ATTRS Topic: HSpace planet attributes The following attributes are settable and retrievable for planet objects. Gettable attributes: LANDINGLOCS: A list of landing locations (rooms) on that planet. &HS-WORMHOLE-ATTRS Topic: HSpace wormhold attributes This object not yet implemented. &HS-BLACKHOLE-ATTRS Topic: HSpace blackhole attributes This object not yet implemented. &HS-NEBULA-ATTRS Topic: HSpace nebula attributes This object not yet implemented. &HS-ASTEROID-ATTRS Topic: HSpace asteroid attributes This object not yet implemented. &HS-OBJECT-ATTRS Topic: HSpace object attributes Probably one of the most enjoyable features of HSpace is that every object can be manipulated and modified through its attributes. From changing the name of the object to changing the size, most aspects of an object are available to change. Each type of HSpace object, be it a ship, a nebula, or a missile, possesses attributes that you can change and retrieve. Because objects are often derived from "base objects," many objects will share similar attributes with other objects. All objects share at least the base, NOTYPE object attributes. These are as follows: NAME : Name of the object as viewed in space. SIZE : Size of the object from 1 .. n. X : X coordinate of the object in space. Y : Y coordinate of the object in space. Z : Z coordinate of the object in space. UID : Universe ID of the universe the object belongs to. Beyond these attributes, the various types of objects may provide a plethora of additional attributes for you to modify and manipulate. Some objects may provide many attributes, while others may provide few. For a list of attributes that are settable and retrievable for each object, refer to each object's attributes section: HS-<OBJECT>-ATTRS See also: HS-OBJECTS, HS-TYPES &HS-CLASSES Topic: HSpace classes What is a class? A "class" is an abbreviated reference to a ship class, so the next question is what is a ship class? We can think of a ship class by taking a simple look at modern day naval vessels. We have a variety of naval vessels present today, many of which are commonly known, such as the destroyer and battleship. Typically, each naval vessel belongs to a certain class of ship. For example, we may find some ship traveling the oceans called the USS Onlooker. It is a large ship, classified as a battleship. However, battleships can vary in how they're designed and what detailed purposes they serve. Thus, each type of battleship belongs to a "class" of battleship. The USS Onlooker might be of the Jersey Class Battleship, which means that it possesses certain attributes common to all battleships of the Jersey class. Why the use of classes? It is typically uncommon to produce a single vessel with a given set of attributes and characteristics. Often we find at least several vessels that share similarities, and manufacturers can refer to designs for a class of vessel rather than a specific, single vessel. A manufacturer may produce 20, Tiger class sailboats rather than just a single sailboat called the Tiger. The manufacturer, then, profits from the ability to produce multiple ships of that design with relative ease. In HSpace it is no different. Designing and constructing the initial ship class may be slightly tedious, but the work is much less for producing vessels of that class. Once the base class is in place, vessels of that class can be created quickly. After each vessel is created, administrators have the option to slight alter, or "componentize," pieces of each vessel to make them unique. In addition to a variety of attributes that can be set on a given ship class, engineering systems must also be added to the class. This is because each type of vessel may contain its own set of engineering systems that differ from other ship classes. For example, ships of Ship Class A may possess jump drives, while ships of Ship Class B do not. For this reason, it is necessary to add engineering systems to the ship class that all ships of that class should possess. When ships of that class are created, they will possess the engineering systems given to that class. To create a new ship class, refer to the '@SPACE-NEWCLASS' help file. Refer to 'HS-CLASS-ATTRIBUTES' for information on setting specific attributes for classes once created. &HS-CLASS-ATTRIBUTES Topic: HSpace class attributes The following attributes may current be set for any ship class: MAXHULL : Maximum number of hull points. NAME : Name of the class (e.g. Onlooker Class Battleship) SIZE : Size of the vessel from 1 .. n. CREWS : Number of repair crews stationed on the ship. CARGO : Size of the cargo bay on the ship. CAN DROP: Whether the ship can drop to a planet or not. Classes may also possess engineering systems. Refer to the @SPACE-ADDSYSCLASS help file for information about this feature. &HS-FUNCTIONS Topic: HSpace functions Functions in HSpace allow administrators and players alike to develop "softcode" for working with HSpace. The following functions are currently provided: HS_GET_ATTR HS_SET_ATTR HS_SPACEMSG XYANG HS_SREP HS_ENG_SYS ZANG HS_ADD_WEAPON HS_WEAPON_ATTR HS_SYS_ATTR HS_SYSSET HS_GET_MISSILE HS_COMM_MSG HS_CLONE() For more information on a specific function, refer to each function's help file. For example 'help HS_SPACEMSG()'. & CLASS PICTURES Topic: HSpace class pictures The Vstats command that comes with HSpace 4.0 provides the ability for you to show a picture of the ship class to the player. This is easily accomplished by creating a pics directory in your space directory (configurable in hspace.cnf) that will include your class pictures. For each ship class (0 .. n), you simply create a file called class_#.pic, containing the ASCII art you wish to have displayed. Additionally, you can have the hull and shield strength percentages displayed by using the %h (hull), %f (foreshield), %p (port shield), %a (aft shield), and %s (starboard shield) substitutions. For each of these substitions, a 4 character percentage (e.g 100%) will be put in its place. Thus, keep this 4 character requirement in mind when drawing your art. What you see may not be what you get when it is displayed. You do not need to reboot your game for changes to the artwork to be displayed. It is taken directly from the file when the vstats command is issued. & HS-CLONING Topic: HSpace cloning Cloning makes ship creation easy, once you have the template ship created. The process of cloning begins by using the @space/clone command on a ship that has already been built. The clone command will attempt to clone all of the rooms and consoles that are a part of that ship. The following things do not currently get cloned: * Console weapons (cloned if ship exists for one @dump) * Fuel supply (cloned ship is not refueled) * Missile storage settings * Landing bays In general, however, the @space/clone will adequately clone your ship to save you a lot of time in creating ships. Typically you will want to save a model version of each ship class that you create. You can then clone from those models to prevent unwanted attributes from getting included in the newly cloned ship. Here are the steps that I follow to properly clone a ship: 1) @space/clone on the model ship object -> produces a dbref 2) Refuel the ship 3) Set the coordinates and universe (the default location is the location of the ship being cloned). 4) Verify missile bay settings 5) Verify weapons on the consoles (this is not necessary if the ship being cloned has existed for one database save period. This is because weapons information is retained on the consoles in attributes and get loaded during a clone.). 6) Add the landing bay if applicable (the room will exist, it simply needs the @space/addlandingloc to register it). & @SPACE Command: @space/<switch> [<parameters>] The almighty @space command controls just about every administrative aspect of the system. There is no other command in the software that allows so much. The command has the following switches: ACTIVATE ADDCONSOLE ADDLANDINGLOC ADDOBJECT ADDSROOM ADDSYSCLASS ADDWEAPON DELCLASS DELCONSOLE DELSROOM DELUNIVERSE DUMPCLASS HALT LIST SETMISSILE MOTHBALL NEWCLASS NEWUNIVERSE REPAIR SET SETCLASS SYSINFOCLASS SYSINFO SYSSET SYSSETCLASS START CLONE ADDTERRITORY NEWWEAPON SETWEAPON DELWEAPON For help on each command switch, refer to the help files with the following syntax 'help @space-<switch>'. & @SPACE-DELWEAPON Command: @space/delweapon <console>=<weapon #> Deletes the weapon in the slot indicated by <weapon #> from the console indicated by <console>. Ex: > @space/delweapon gunnery turret=1 & @SPACE-CLONE Command: @space/clone <ship> Clones the ship represented by the object <ship>, including rooms, exits, attributes on rooms and exits, and consoles. The command returns the dbref of the new ship object and places the new ship in the universe and location of the cloned ship. & @SPACE-SYSSETCLASS Command: @space/syssetclass <class ID>:<system>/<attr>=<value> The @space/syssetclass works identically to the @space/sysset command, except that it functions with ship classes instead of individual ship. Each HSpace engineering system has a set of attributes that can be set and retrieved. Ship classes are responsible for providing default information to ships of their class, and this includes default engineering system information. Ex. @space/syssetclass 0:engines/acceleration=50 See also: @SPACE-SYSSET, HS-SYSTEMS & @SPACE-SYSSET Command: @space/sysset <object>:<system>/<attr>=<value> The sysset command is similar to the @space/set command, except that it works at the system level for the ship. Systems are smaller pieces located on an HSpace object (typically a ship) and not part of the standard attributes of an HSpace object. Thus, it is necessary to specify the <object>, which is an HSpace object, the <system>, which is the name of a system on that object (e.g. engines), the <attr>, which is a valid attribute name for that system, and the <value> for that attribute. Any attributes set at the individual ship system level override those of the ship's class systems. For example, the acceleration rate of the engines of Class 0 may be 50. By setting the acceleration rate of the engines on Ship B, which is of Class 0, to 100, that ship will no longer refer to Class 0's engine acceleration rate for accelerating. This is called "overriding" the class information. Ex. @space/sysset navigation console:engines/acceleration=100 See also: @SPACE-SYSSETCLASS, HS-SYSTEMS & @SPACE-SYSINFO Command: @space/sysinfo <object>=<system name> Prints the current settings for the specified <system name> on the given HSpace object -- usually a ship. Each engineering system has its own attributes that can be set and retrieved. All systems are also derived from a base, generic engineering system type. Thus, base engineering system information is printed along with specific information for that type of engineering system. See also: HS-SYSTEMS & @SPACE-SYSINFOCLASS Command: @space/sysinfoclass <class ID>=<system name> Prints the current settings for the specified <system name> on the class with the specified ship <class ID>. Each ship class contains a list of default systems for ships of that class. Further, these systems must provide default system values for the systems on those ships. The @space/sysinfoclass command allows system information for the classes to be retrieved. The <system name> should be one of the valid engineering systems in HSpace. See also: HS-SYSTEMS, @SPACE-ADDSYSCLASS, @SPACE-SYSSETCLASS & @SPACE-SETCLASS Command: @space/setclass <class ID>/<attr>=<value> Like @space/set, the @space/setclass sets the <value> of the specified <attr> but for the given <class ID> instead of a given HSpace object. This is useful only for ship classes, which provide the foundation attributes for all ships in the game. Rather than setting attributes on each individual ship, setting the attribute on the class allows all ships of that class to use the value. The only exception is when the class attributes are "overridden" by using @space/set with the same attribute name on the ship object. The value is then set on the specific ship instead of for the class. Any changes to the same attribute on the class will no longer affect the ship. See also: @SPACE-SET, @SPACE-SYSSETCLASS & @SPACE-SET Command: @space/set <object>/<attr>=<value> Allows the specified <attr> on the given <object> to be set to <value>. All HSpace objects have attributes that can be set and retrieved. The @space/set command is a powerful tool for changing the behavior and appearance of any HSpace object. For a list of attributes for the various types of HSpace objects, refer to HS-OBJECT-ATTRS. For ships, attributes in the class of that ship can often be "overridden" at the ship level to provide more individuality for the ship. For example, the ability to drop to a planet or not is an attribute settable at the class level and also at the ship level. If the attribute is set on the ship, it overrides any setting on the ship's class, allowing that ship to perform unlike most ships of its class. This remains in effect until the attribute is reset on the specific ship by specifying no <value> parameter for the given attribute. Ex. @space/set Navigation Console/name=USS Excalibur See also: @SPACE-SETCLASS, @SPACE-SYSSET & @SPACE-REPAIR Command: @space/repair <object> Completely repairs all parts of the specified <object>, which is any HSpace object (typically a ship) that may be damaged. Any engineering systems belonging to that object are also repaired. & @SPACE-SETMISSILE Command: @space/setmissile <object>/<weapon ID>=<value> Manipulates the munitions storage on the specified <object>, which is usually a ship, to set the current storage value for the given <weapon ID> (a missile type) to the specified <value>. The <weapon ID> is a the ID of the weapon in the weapons database, which can be printed with the @space/list command. If the type of weapon is not already found in the object's munitions storage (missile bay), then the type is added to the storage and the max value set. If the value of the storage is greater than the current maximum storage value, the maximum value is raised to the value given. See also: @SPACE-LIST, @SPACE-ADDWEAPON & @SPACE-HALT Command: @space/halt Halts the HSpace cycle, which moves ships and performs general cyclic things. This does not prevent players from using HSpace comands, it only prevents HSpace from cycling. See also: @SPACE-START & @SPACE-START Command: @space/start Starts the main HSpace cycle, which is responsible for all cyclic activity in HSpace (e.g. moving ships, moving missiles, sweeping for sensor contacts, etc.). Without this cycle, nothing in HSpace moves or gets updated. See also: @SPACE-HALT & @SPACE-DUMPCLASS Command: @space/dumpclass <class ID> Prints the information for the specified <class ID>, including what the current attribute settings are for that class and what engineering systems the class possesses. See also: @SPACE-ADDSYSCLASS, @SPACE-SETCLASS, @SPACE-SYSSETCLASS & @SPACE-DELSROOM Command: @space/delsroom <object>=<room #> Deletes the given <room #> from the list of srooms for the specified <object>, typically a ship object. See also: @SPACE-ADDSROOM & @SPACE-DELCLASS Command: @space/delclass <class ID> Deletes the specified class of type <class ID> from the game. This can only be performed after all ships of the given class are changed to a new class or deleted from the game. See also: @SPACE-NEWCLASS & @SPACE-ADDWEAPON Command: @space/addweapon <console>=<weapon ID> Adds a weapon of type <weapon ID> to the specified HSpace console. Only consoles can possess weapons, and all consoles are "things" in the game. A console can possess any type of HSpace weapon. & @SPACE-ADDSROOM Command: @space/addsroom <object>=<room> Adds a "sroom" to the given HSpace <object>, which is typically a ship. Srooms stand for "ship rooms" are are nothing more than the rooms the make up a vessel. By registering your ship rooms with the given ship <object>, HSpace will be able to determine which game rooms belong to your ship. Thus, when the ship is destroyed, players in the rooms can be killed. Messages are also sent to all rooms on the ships sometimes, so any non- registered rooms won't receive these messages. See also: @SPACE-DELSROOM & @SPACE-ADDCONSOLE Command: @space/addconsole <ship obj>=<console> Adds a new HSpace console, specified by the name or dbref of <console>, to the specifed <ship obj>, which represents an HSpace ship in the game. Consoles can use any of the HSpace commands (includng @space if the console is set with the WIZARD flag) to perform a variety of functions. See also: HS-CONSOLES, @SPACE-DELCONSOLE & @SPACE-ADDLANDINGLOC Command: @space/addlandingloc <object>=<room> Adds a new landing location (a bay or drop pad), represented by <room> to the given HSpace <object>, which may be a ship or a planet. Like all HSpace objects, landing locations have their own attributes that can be set and retrieved. Ships and planets can support up to 15 landing locations at one time. See also: HS-LANDINGLOC-ATTRS &@SPACE-NEWCLASS Command: @space/newclass <name> The @space/newclass command allows a new ship class to be added to the game. The <name> parameter specifies the name for the new class. Once a new class is created, its attributes must be set, and engineering systems must be added to it. For example: 1) @space/newclass Test Class 1 (creates class 0) 2) @space/setclass 0/maxhull = 300 3) @space/addsysclass 0=Internal Computer 4) @space/sysinfoclass 0=Internal Computer 5) @space/syssetclass 0:intern/tolerance=1 See also: @SPACE-SETCLASS, @SPACE-SYSSETCLASS, @SPACE-ADDSYSCLASS, @SPACE-DELCLASS &@SPACE-NEWUNIVERSE Command: @space/newuniverse <room #> Creates a new universe, represented by the room with the specified <room #>. Each universe in HSpace must have a room in the game that corresponds to it. Do NOT delete this room once the universe is created. Universes allow HSpace objects to exist because every HSpace object must belong to a universe. See also: @SPACE-DELUNIVERSE, HS-UNIVERSES &@SPACE-DELUNIVERSE Command: @space/deluniverse <#> Deletes the universe specified by the supplied <#>. Universes must be completely empty before they are deleted. See also: @SPACE-LIST, @SPACE-NEWUNIVERSE, HS-UNIVERSES &@SPACE-LIST Command: @space/list <database> Allows items in the specified <database> to be listed. The <database> argument may be one of the following: Objects: @space/list objects/<uid>=<type> Where <uid> is a universe ID and <type> is a type of HSpace object. Weapons: @space/list weapons Classes: @space/list classes Destroyed: @space/list destroyed Universes: @space/list universes See also: HS-TYPES &@SPACE-ADDSYSCLASS Command: @space/addsysclass <class>=<system> Adds the specified <system> to the specified <class> ID. The <system> parameter must be the name of a valid ship system. Ex: @space/addsysclass 0=int Notice that the name "Internal Computer" can be abbreviated as simply "int." HSpace uses the first system name matched by the specified <system> parameter. Thus, int, in, inter, internal computer all work for the Internal Computer name. After a system is added to a class, ships of that class will not reflect the changes until a reboot of the game is performed. This is because systems for a ship get loaded when the game reboots and the ship examines its class information. &@SPACE-SYSSETCLASS Command: @space/syssetclass <class>:<system>/<attr>=<value> Sets the value of a given attribute for the specified system on the specified ship class ID. After an engineering system is added to a ship class, its variables must be set. For example: @space/syssetclass 0:reactor/max output=100 The above command sets the maximum reactor output to 100 MW for ship class 0. See also: @SPACE-SYSSET &@SPACE-SYSSET Command: @space/sysset <obj>:<system>/<attr>=<value> Sets the attribute value of a given system on the specified HSpace object (typically a ship). This can be used to either change the current value (e.g. damage) of a variable on the system or to override the value specified in the base ship class. Ex. @space/sysset Test Ship:reactor/damage=0 See also: @SPACE-SYSSETCLASS &@SPACE-ADDOBJECT Command: @space/addobject <thing>=<type> Adds a new HSpace object to HSpace of the given <type>. The <thing> parameter must be a MUSH object that was created with the @create command. Do not destroy this MUSH object while the HSpace object still exists. You should destroy the HSpace object first with @space/mothball and then @nuke the MUSH object. Ex. @space/addobject Wormhole Alpha=4 Do not use this command for ships. See also: HS-TYPES, @SPACE-ACTIVATE, @SPACE-MOTHBALL &@SPACE-MOTHBALL Command: @space/mothball <thing> Destroys the HSpace object associated with the MUSH object <thing>. The MUSH object is not destroyed, only the HSpace object it represents. Once an HSpace object is mothballed, it is gone forever. Ex. @space/mothball Test Ship &@SPACE-ACTIVATE Command: @space/activate <thing>=<class> Activates <thing> as a ship with the given <class> identifier. Ex. @space/activate Test Ship=0 The specified class must have already been created. The <thing> is a MUSH object that will represent the ship. In HSpace 3.x this was referred to as the ship object, and the navigation console was the heart of the ship. In HSpace 4.0 and later the shipobj is the heart of the ship, and the navigation console is like any other console on the ship. The <thing> will be placed in rooms as the ship moves from active space to docking and landing locations. When docked or landed, <thing> will be placed in that room where the ship has landed. Players can use the board command with the object to board the ship. Once the object is activated as a ship, consoles can be added to it and attributes can be set for it. !! DO NOT !! use the <thing> as a console. Because it is automatically moved around the game by HSpace, it will normally not be available for use as a console. See also: HS-SHIP-ATTRS, @SPACE-MOTHBALL &@SPACE-ADDTERRITORY Usate: @space/addterritory <object>=<type> Adds a new territory to space, represented by the MUSH object <object>. Type <type> must be a valid territory type, which is 0 for radial and 1 for cubic. See Also: HS_TERRITORIES, TERRITORY-ATTRS, TERRITORY-SETUP &@SPACE-NEWWEAPON Command: @space/newweapon <type>=<name> Adds a new weapon to the list of available ship weapons. The <type> must be a valid weapon type, and the <name> is the initial name of the weapon. You can use @space/setweapon to set the attributes on the new weapon after creation. Valid weapon types: 0 = Laser 1 = Missile See Also: HS-WEAPONS, HS-WEAPON-ATTRS &@SPACE-SETWEAPON Command: @space/setweapon <id>/<attr>=<value> Sets an attribute value for the specified weapon <id>, which may be listed with the @space/list command. The <attr> must be a valid attribute for that type of weapon, and <value> is the new value for that attribute. See Also: HS-WEAPON-ATTRS, HS_WEAPON_ATTR() &@SPACE-DELCONSOLE Command: @space/delconsole <object>=<dbref> Deletes a registered ship console from the specified space object, which is typically a ship. The <dbref> is the dbref number of the console that is registered with the ship. Ex: @space/delconsole myship=#1102 & CLINK Command: clink <contact #> Attempts to establish a cargo link with a target vessel, indicated by the <contact #> on sensors. A cargo link takes time to establish, and the two vessels may not move during this time. If the vessels do not remain still during the linking procedure, the link fails. Once a cargo link is established, use cscan and cget to scan and transfer cargo. Use cunlink to break the link, or the ship performing the cargo link can simply set a speed to break the link. & CSCAN Command: cscan Provides a cargo report for a vessel that has been cargo linked by another vessel. Use cget to take cargo. & CGET Command: cget <commodity> Takes one (1) unit of <commodity> from a target vessel with which you have established a cargo link (clink). You must have enough storage left in your cargo bay to transfer the cargo. & BLINKS Command: blinks Displays a list of boarding links currently active between the current ship and other ships in the area. & DEADMAN Command: deadman Purpose, to make you dead! Just kidding. The deadman command allows you to safely leave your ship in space when needed (certainly useful for capital ships that cannot land). The deadman command takes 2 minutes to go into affect, preventing someone from using it instantly to avoid getting shot at. Once the deadman mode is activated for the ship, the ship cannot be locked on by another ship who has not already locked weapons (ships with locks maintain them and can continue attacking). The ship cannot be used again by the crew without deactivating the deadman mode. Thus, setting deadman mode requires that you discontinue using the ship once the mode is active. & ICOM Command: icom <message> Allows consoles on multi-console ships to communicate with each other. & SPOSE Command: spose <action> Emits a pose for your ship into the nearby space so that other vessels who have you identified on sensors see the message. Ex: spose flies near you, blazing its laser cannons. & CSTAT Command: cstat Shows the current communications array status, including transmission and receiving frequencies. & CHOWN Command: chown <player name> Allows the owner of a ship to change the ownership to another player in the game. & SPECS Command: specs [<system>] Provides vessel statistics in general or, if <system> is specified, for a specific system on the vessel. & SHIPNAME Command: shipname <name> Sets the name of the vessel from that navigation console. The name is limited to a length of 32 characters. & BOARDING CODE Command: boarding code boarding code <code> Sets the boarding code for the vessel, which means that a player wishing to board the vessel from the outside will need to specify a code. By supplying no <code>, the boarding code for the vessel will be deleted, and anyone may board. See Also: BOARD, SECURITY & SECURITY Command: security <on/off> Turns the ship security on or off, effectively activated or deactivating the required boarding code. If no boarding code is set on the ship, this command has no effect. If a boarding code is set, and security is turned off, the boarding code is not required for players wanted to board. Once security is turned on, the boarding code is reactivated and required. See Also: BOARD, BOARDING CODE & BOARD Command: board <ship>[=<code>] Allows you to board the given ship with a specified name. The ship will obviously be docked in a docking bay or landed on a planet landing pad. An optional code may be required to board the vessel. See Also: DISEMBARK, BOARDING CODE, SECURITY & DISEMBARK Command: disembark When located in a room on a ship marked as a disembarking room, the disembark command will take you from the ship to the docking bay or planet room where the ship is docked. This command will not work if the ship is actively in space. See Also: BOARD & ENGINES Command: engines Sets engine power to 100% of capable power level. & LIFE Command: life Sets life support power to 100% of capable. & THRUST Command: thrust Sets maneuvering thruster power to 100% of capable. & COMPUTER Command: computer Sets computer power to 100% of capable. & PORT & FORE & AFT & STARBOARD Command: <shield> Sets the specified shield power to 100% of capable power. & POWER Command: power Sets the desired reactor output to 100% of capable power. & SENSOR Command: sensor Sets the sensor array power to 100% of capable. & LAND Command: land <contact>/<location>=[<code>] The land command attempts to land the vessel at the given contact number, which could be a planet or another vessel. The <location> refers to which of the landing pads or docking bays is desired, beginning with 1. To land at the given location, a code may need to be given. If a code is not required for the location, this parameter is ignored. The LAND and DOCK commands are identical and work for both planets and vessels. & DOCK See LAND. & UNDOCK Command: undock Undocks a landed or docked vessel from its location, which must be either a docking bay or landing pad on a planet. & STAT Command: stat Gives the navigation status display for the vessel, including current course and velocity. If present, shield information is included. A map of the surrounding space is available for navigation, and the "map range" can be set to change the scale and limits of the area within the map. & VSTATS Command: vstats Displays a picture of the ship class for the ship, upon which shield and hull information may be included. & VIEW Command: view Provides a description of the surrounding area where the vessel is currently docked or landed. This is useful in combination with the taxi command. & TAXI Command: taxi <direction> Taxis a docked or landing ship in the <direction> desired, whch is the name of an exit in the room where the ship is located. & SCAN Command: scan <contact ID> Scans a target object in space to provide information about that contact. The <contact ID> comes from the sensor report for the vessel doing the scanning. & LAND Command: land <contact>/<location>=<code> Attempts to land the vessel on the given space object with the <contact> ID on sensors. The <location> parameter specifies which of the landing locations should be targeted and ranges from 1 to N. A code may or may not be required for landing. If not required, this parameter is ignored. & DOCK Command: dock <contact>/<location>=<code> Attempts to dock the vessel in the given space object with the <contact> ID on sensors. The <location> parameter specifies which of the landing bays should be targeted and ranges from 1 to N. A code may or may not be required for docking. If not required, this parameter is ignored. & MAPRANGE Command: maprange <range> The maprange command allows the scale and limits of navigation map to be changed. The <range> indicates how far from the ship objects are included in the map. For example, a range of 100 means that any objects on sensors within 100 units of the ship will be displayed in the map. To view close range objects, it may be necessary to reduce the <range> so that those objects appear more "spread out" on the map. As the <range> increases, objects near to each other will get grouped into the same location on the map. & ABORT Command: abort Takes the ship out of hyperspace if the ship is currently "jumping." & JUMP Command: jump Takes the vessel into hyperspace if jump drives are present. The vessel much first achieve a minimum sublight speed before jumping to hyperspace. & AFTERBURN Command: afterburn If afterburners are present on the vessel, this command puts the vessel into afterburn mode, which basically dumps fuel into the engines to create additional thrust. Afterburning significantly increases the speed of the vessel but typically results in poor fuel efficiency. & BLINK Command: blink <contact ID> Attempts to establish a "boarding link" with anothe vessel on sensors with the specified <contact ID>. Ships can support up to 5 simultaneous boarding links. & BUNLINK Command: bunlink <link ID> Attempts to break the boarding link previously established with another ship. Valid <link ID> values range from 1 to 5, which is the maximum number of links that can be supported at a given time. & SREP Command: srep Prints a sensor report for the vessel's sensor array, if present. Administrators may or may not have customized this command to print only certain contact types. & SS Command: ss <velocity> Sets the desired velocity for the vessel, assuming the <velocity> is valid. Engine damage, available power, and other factors may limit the maximum capable speed of the engines. & NOBURN Command: noburn If the ship is currently afterburning, this command will cease the process and take the ship back into regular speed levels. & UNLOCK Command: unlock If the console is currently locked onto a target object, the unlock command disengages the console's lock. This need not be used before establishing another target lock. If another lock is obtained while currently locked on a target, the lock is changed from the previous to the new target. & LOCK Command: lock <contact ID> Locks the console's weapons (if available) on the target object with the given <contact ID> on sensors. The contact must be within range of the console's weapons, which is determined by the weapon on the console with the maximum range. & TARGET Command: target <system name> Attempts to target the given <system name> on the target object. Any weapons on the console that support system targeting will attempt to do damage to that system on the enemy object. Not all weapons may support system targeting. To break a system target lock, specify a value of "none" for the system name. & QREP Command: qrep Displays a gunnery heads-up for the current target lock. The heads up contains a forward display of where the target is located relative to the current heading of the console. Information about your heading and the target status is also displayed. & CPOWER Command: cpower <on/off> Turns the console on or off. This is required before using any navigation or console commands. Engineering commands do not require console power. Power for consoles is extracted from the internal computer. For each of the weapons located on a console, additional power is typically needed. Thus, if damage to the internal computer is encountered or the internal computer, for whatever reason, cannot accomodate enough power, some consoles may not be able to obtain the needed power. & LOAD Command: load <weapon #> Attempts to load the given weapon, provided sufficient munition is available and the weapon can be loaded. & UNLOAD Command: Unload <weapon #> Attempts to unload the currently loaded weapon. This is only applicable for weapons that support this feature. Once unload, the munition from the weapon is put back into the ship's munitions storage for later use. & CHEAD Usage the same as HEAD. Refer to HEAD help file. & HEAD Command: head <XY> mark <Z> head <contact #> (Navigation only) Changes the ship's or console's heading to the desired angles. Valid XY angles are from 0 to 359, while valid Z angles are from 90 to -90 (straight up, straight down). Many consoles can move independently of where the ship is heading, thus making gunnery turrets possible. Even though the ship may be heading 0 mark 0, it is possible for a side-facing turret to turn in other directions to defend from attacking enemies. For consoles, it may or may not be possible to turn to the desired heading due to restrictions on where the console is located on the sides of the ship. If the console has been setup setup to deny rotation, it may not be rotated from the current heading. & GREP Command: grep For consoles controlling weapons, the grep command gives a gunnery report, indicating which weapons are present, their status, weapon attributes, and other information about the gunnery status of the console. Information about the ship's munitions storage is also presented. & FIRE Command: fire <weapon #> Attempts to fire the given <weapon #> on the console. This assumes that weapons are present. Some weapons may require a target lock, while others may not. & CONFIGURE Command: configure <weapon #>=<munitions #> Attempts to configure the given weapon on the grep display to the specified <munitions #>, which is a type of munition in the ship's storage. Typically the weapon must be empty before it can be reconfigured. Once configured, the weapon will load and fire that munitions type. & AUTOLOAD Command: autoload <on/off> Sets the console's autoloading status to on or off. If set to on, the console will automatically attempt to load any loadable weapons after they are fired. If no munitions for that weapon remain in the ship's munitions storage, autoloading fails. If set to off, loading must be performed manually with the load command. & AUTOROTATE Command: autorotate <on/off> Sets the console's autorotating status to on or off. Autorotating is a convenient way to avoid manually changing the heading of the console each time you want to attack a target on sensors. If autorotating is turned on, the console automatically determines the needed heading to attack the target and attempts to turn to that heading. & SYSPRIORITY Command: syspriority <system name><+/-> Changes the system priority of the specified system for the ship. The <system name> must be one of the systems listed on the sysrep display for the ship. It's status can be changed upward (+) or download (-) on the list. This is useful for when the ship may lose power. If power is lost for any reason, the ship's computer will begin deallocating power from systems at the top of the sysrep list. For systems you do not want power immediately drained from, lower their priority on the list. For example, you may want life support to be the last thing that gets power drained from it. Thus, you can lower it's priority repeatedly with: syspriority life support- Do this until the priority is lowered to your satisfaction. & SYSPOWER Command: syspower <system name>=<#> Sets the megawatts of power allocated to a given system on the ship. If insufficient power is available from the reactor, this operation fails. Ex. syspower life support=10 You can abbreviate system names with most engineering commands. For example, you can specify life instead of life support. & SYSPERC Command: sysperc <system name>=<% power> Sets the power allocation for the given system to a percentage of the maximum power needs for the system. If 100% is specified, the reactor attempts to allocate 100% of the system's power needs to it. This is useful for when you want to quickly set a system's power usage to a given level (e.g. 100%). Ex. sysperc life support=100 & SYSREP Command: sysrep Displays a list of systems currently present on the ship, information about their status, damage, and power allocation. *************************** HSPACE FUNCTIONS ************************ & HS_CLONE() HS_CLONE(<obj>) Currently only works on ships. The hs_clone() function is a handy way of using @space/clone within a function. If successful, the dbref of the new clone is returned. & HS_SET_MISSILE() HS_SET_MISSILE(<obj>, <type>, <num>) Sets the current storage for the given weapon type (a missile) on the object (a ship). If <num> is greater than the current maximum storage value, the maximum value is raised to <num>. See Also: HS_GET_MISSILE() & HS_COMM_MSG() HS_COMM_MSG(<SID>,<DID>,<X>,<Y>,<Z>,<RANGE>,<FRQ>,<MSG>) Sends a communications message into space, to be received by any objects with communications capability. The object sending the message MUST have the HSPACE_COMM flag, or the message will be rejected. The parameters are: SID: Source universe ID. DID: Destination universe ID. X : Source X coordinate. Y : Source Y coordinate. Z : Source Z coordinate. Range: Maximum range to transmit. FRQ: Frequency upon which to transmit the message. MSG: Message to transmit. & HS_GET_MISSILE() HS_GET_MISSILE(<obj>,<ID>) Retrieves the current and maximum missile storage values for the specified weapon ID, which can be obtained from @space/list weapons. The values are returned as: <current>/<max> See Also: @space-setmissile & HS_SYSSET() HS_SYSSET(<obj>/<system>, <attr name>[:<value>]) Sets the <value> of the given <attr name> for the specified <system> on the <obj>, which is usually a ship of sorts. The <value> can be left empty to clear the attribute and reset the system values to the defaults of the class it belongs to. For example, a ship of a certain class has default maximum speed values, but setting this value on the ship overrides the setting of the class. Clearing the value resets the maximum speed to that of the ship class. See Also: HS_SYS_ATTR() & HS_SYS_ATTR() HS_SYS_ATTR(<obj>/<system>, <attr name>, <adjusted>) Returns the value of the requested attribute with <attr name> if the system is present on <obj> (typically a ship) and possesses the specified attribute. The <system> must be a valid engineering system. The <adjusted> parameter can be set to 0 (unadjusted) or 1 (adjusted) to return the system information according to current damage and power levels. A value of 1 specifies that adjusted values should be returned, while a value of 0 specifies that the raw attribute value should be returned. See Also: HS_SYSSET() & HS_ADD_WEAPON() HS_ADD_WEAPON(<console>, <class>) Allows a weapon of ID <class> on the global list of weapons to be added to the console specified by <console>. This is identical to the @space/addweapon command. To be able to add a weapon, the player or object using the function must control the object the weapon is being added to. & HS_WEAPON_ATTR() HS_WEAPON_ATTR(<class>,<attrname>[:<value>]) Allows information to be retrieved and set on a weapon loaded from the weapon database. The <class> is the ID of the weapon as shown on the @space/list weapons command. The <attrname> is a valid attribute that contains information on the weapon. Optionally, a value can be specified to set the new value for that attribute on that weapon. This is restricted to wizards only. See Also: HS-WEAPON-ATTRS & HS_GET_ATTR() HS_GET_ATTR(<object>, <attr>) The HS_GET_ATTR function allows attributes for the specified object to be retrieved. The <object> parameter is any object in the game that represents an HSpace object (e.g. a ship). The <attr> parameter is the name of a valid, retrievable attribute for that type of HSpace object. For ships, any console can be used in place of the ship object to allow players without see_all powers to get attributes from the ship through the consoles. Players may only get attributes from HSpace objects they are standing in the same room as, unless they are granted the ability to see anywhere in the game. & HS_SET_ATTR() HS_SET_ATTR(<object>/<attr>, <value>) Only wizards may set attributes attributes on the specified game <object>, which represents an object in HSpace (e.g a ship). The <attr> parameter is any valid, settable attribute for that type of HSpace object, while <value> is a valid value for that attribute. Not all attributes that are retrievable for an object are settable and vice versa. & HS_SPACEMSG() HS_SPACEMSG(0, <uid>, <X>, <Y>, <Z>, <dist>, <msg>) HS_SPACEMSG(1, <msg>) HS_SPACEMSG(2, <msg>) The HS_SPACEMSG function allows messages to be sent into space in a variety of ways. This can allow what is commonly referred to as "ship posing" such that players can type a command and have the ship send a message as if it were performing some action in space. The first form of the function allows a wizard or HSpace object to send a message into the universe with the given <uid>, starting at the specified X, Y, and Z coordinates, and reaching all other HSpace objects within the specified <dist> range. The second and third forms of the function allow an HSpace object to send a message from itself into space such that other objects with sensors receive the message. The second form sends a message to all HSpace objects with the source object on sensors, while the third form sends to all HSpace objects that have the source object IDENTIFIED on sensors. Thus, the third form is very useful for ship posing. Ex: think hs_spacemsg(2, The Excalibur comes screaming in for the kill.) & HS_SREP() HS_SREP(<object>, <type>) Retrieves the current sensor contacts for the specified HSpace <object>. The <type> parameter specifies the type of object contacts you wish to retrieve from the sensors. Refer to HS-TYPES for each of the HSpace types of objects. If the No Type of object is specified for the <type>, all sensor contacts are retrieved. A list of contacts is returned in the following format: <contact> <contact> .. <contact> Where <contact> contains the following information: ID:Dbref:Type:Name:XY Bearing:Z Bearing:Distance & HS_ENG_SYS HS_ENG_SYS(<object>) Returns a comma delimited list of engineering systems located on the given HSpace <object>. & XYANG() XYANG(<X1>, <Y1>, <X2>, <Y2>) Returns the XY planar angle from the first pair of XY coordinates to the second. & ZANG() ZANG(<X1>, <Y1>, <Z1>, <X2>, <Y2>, <Z2>) Returns the Z planar angle from the first pair of XYZ coordinates to the second. hspace40-b12.patch 100664 767 767 36337 7142346217 12037 0 ustar mux mux diff -c src.old/Makefile.in src/Makefile.in *** src.old/Makefile.in Thu Aug 3 19:34:12 2000 --- src/Makefile.in Thu Aug 3 18:23:27 2000 *************** *** 25,30 **** --- 25,35 ---- LIBOBJS = @LIBOBJS@ .SUFFIXES: .cpp + # If you decide you don't want to use HSpace after all, comment this out: + USE_HSPACE = YES + # Without this, HSPACE will not be defined and the HSpace files will not + # be compiled. + # After we finish beta testing, we'll take away the debugging -g flag. # If you don't use GCC, don't use -g. Add -pg for profiling (gprof netmux # gmon.out) *************** *** 168,174 **** LIB_SRC = LIB_INC = DEBUG = $(OPTIM) ! ALLCXXFLAGS = $(CXXFLAGS) $(DEBUG) $(DEFS) $(COMPRESS_DEFS) $(BASED) $(MALLOC_DEFS) $(CONC_DEFS) $(MOREDEFS) $(RLIM_F) #Auxiliary files A_INST = README NOTES HIGHLIGHTS CREDITS CHANGES --- 173,187 ---- LIB_SRC = LIB_INC = DEBUG = $(OPTIM) ! ifdef USE_HSPACE ! HSPACE_DEFS = -DHSPACE ! HSPACE_PLATFORM = -DMUX ! else ! HSPACE_DEFS = ! endif ! ALLCXXFLAGS_NORMAL = $(CXXFLAGS) $(DEBUG) $(DEFS) $(COMPRESS_DEFS) $(BASED) $(MALLOC_DEFS) $(CONC_DEFS) $(MOREDEFS) $(RLIM_F) ! ALLCXXFLAGS_HSPACE = $(ALLCXXFLAGS_NORMAL) $(HSPACE_PLATFORM) ! ALLCXXFLAGS = $(ALLCXXFLAGS_NORMAL) $(HSPACE_DEFS) #Auxiliary files A_INST = README NOTES HIGHLIGHTS CREDITS CHANGES *************** *** 184,198 **** AUXIL = $(A_INST) $(A_TXT) $(A_SH) $(A_CONF) $(A_MISC) $(A_RT) $(A_VMS) \ $(A_AUTO) #Installation files INSTALL_PROG = Startmux netmux dbconvert mkindx db_load db_unload db_check $(R_SERV) INSTALL_TARG = $(INSTALL_PROG) *.txt *.conf REINSTALL_TARG = $(INSTALL_PROG) help.txt wizhelp.txt alias.conf compat.conf #compiliation source files ! ALLSRC = $(D_SRC) $(VER_SRC) $(COM_SRC) $(SA_SRC) $(AUX_SRC) $(LIB_SRC) SRC = $(D_SRC) $(COM_SRC) $(MALLOC_S) $(CONC_S) $(C_COMPRESS_S) OBJ = $(D_OBJ) $(COM_OBJ) $(MALLOC_O) $(CONC_O) $(C_COMPRESS_O) ifdef SWITCH_RADIX_COMPRESSION OUT = netmux mkindx dbconvert a --- 197,231 ---- AUXIL = $(A_INST) $(A_TXT) $(A_SH) $(A_CONF) $(A_MISC) $(A_RT) $(A_VMS) \ $(A_AUTO) + #HSpace Files + HS_OBJS = hspace/hscelestial.o hspace/hsclass.o hspace/hscmds.o hspace/hsconf.o hspace/hsconsole.o \ + hspace/hsconsolecmds.o hspace/hsdb.o hspace/hseng.o hspace/hsengcmds.o hspace/hsengines.o \ + hspace/hsfuel.o hspace/hsfuncs.o hspace/hsinterface.o hspace/hsmain.o hspace/hsmissile.o hspace/hsnavcmds.o \ + hspace/hsuniverse.o hspace/hsobjects.o hspace/hspace.o hspace/hsplanet.o hspace/hsship.o hspace/hsshipeng.o \ + hspace/hsshipnav.o hspace/hstrig.o hspace/hsutils.o hspace/hsweapon.o hspace/hscomm.o hspace/hsterritory.o + + HS_SRC = hspace/hscelestial.cpp hspace/hsdb.cpp hspace/hsmain.cpp hspace/hsshipeng.cpp hspace/hsclass.cpp \ + hspace/hseng.cpp hspace/hsmissile.cpp hspace/hsshipnav.cpp hspace/hscmds.cpp hspace/hsengcmds.cpp \ + hspace/hsnavcmds.cpp hspace/hsterritory.cpp hspace/hscomm.cpp hspace/hsengines.cpp hspace/hsobjects.cpp \ + hspace/hstrig.cpp hspace/hsconf.cpp hspace/hsfuel.cpp hspace/hspace.cpp hspace/hsuniverse.cpp \ + hspace/hsconsole.cpp hspace/hsfuncs.cpp hspace/hsplanet.cpp hspace/hsutils.cpp hspace/hsconsolecmds.cpp \ + hspace/hsinterface.cpp hspace/hsship.cpp hspace/hsweapon.cpp + + #Installation files INSTALL_PROG = Startmux netmux dbconvert mkindx db_load db_unload db_check $(R_SERV) INSTALL_TARG = $(INSTALL_PROG) *.txt *.conf REINSTALL_TARG = $(INSTALL_PROG) help.txt wizhelp.txt alias.conf compat.conf #compiliation source files ! ALLSRC = $(D_SRC) $(VER_SRC) $(COM_SRC) $(SA_SRC) $(AUX_SRC) $(LIB_SRC) SRC = $(D_SRC) $(COM_SRC) $(MALLOC_S) $(CONC_S) $(C_COMPRESS_S) OBJ = $(D_OBJ) $(COM_OBJ) $(MALLOC_O) $(CONC_O) $(C_COMPRESS_O) + ifdef USE_HSPACE + OUTPUT_OBJ = $(OBJ) $(HS_OBJS) + else + OUTPUT_OBJ = $(OBJ) + endif ifdef SWITCH_RADIX_COMPRESSION OUT = netmux mkindx dbconvert a *************** *** 243,252 **** $(CXX) $(ALLCXXFLAGS) -o a a.o radix.o endif ! netmux: $(OBJ) $(LIBOBJS) $(VER_SRC) $(CXX) $(ALLCXXFLAGS) $(VER_FLG) -c $(VER_SRC) ( if [ -f netmux ]; then mv -f netmux netmux~ ; fi ) ! $(CXX) $(ALLCXXFLAGS) -o netmux $(OBJ) $(LIBOBJS) $(VER_OBJ) $(LIBS) $(MORELIBS) cvs: rm -f buildnum.data --- 276,285 ---- $(CXX) $(ALLCXXFLAGS) -o a a.o radix.o endif ! netmux: hspace-build $(OBJ) $(LIBOBJS) $(VER_SRC) $(CXX) $(ALLCXXFLAGS) $(VER_FLG) -c $(VER_SRC) ( if [ -f netmux ]; then mv -f netmux netmux~ ; fi ) ! $(CXX) $(ALLCXXFLAGS) -o netmux $(OUTPUT_OBJ) $(LIBOBJS) $(VER_OBJ) $(LIBS) $(MORELIBS) cvs: rm -f buildnum.data *************** *** 275,279 **** --- 308,315 ---- clean: -rm -f *.o a.out core gmon.out mux.*log mux.*sum slave conc $(OUT) + + hspace-build: + ( cd hspace; make hspace "CXX=$(CXX)" "CCFLAGS=$(ALLCXXFLAGS_HSPACE)" "LDFLAGS=$(LDFLAGS)" "CLIBS=$(LIBS)" ) include .depend Only in src.old: autoconf.h diff -c src.old/buildnum.data src/buildnum.data *** src.old/buildnum.data Thu Aug 3 19:34:12 2000 --- src/buildnum.data Thu Aug 3 18:27:27 2000 *************** *** 1 **** ! 0 --- 1 ---- ! 1 diff -c src.old/command.cpp src/command.cpp *** src.old/command.cpp Thu Aug 3 19:34:11 2000 --- src/command.cpp Thu Aug 3 18:23:27 2000 *************** *** 462,467 **** --- 462,483 ---- { NULL, 0, 0, 0} }; + #ifdef HSPACE + extern NAMETAB hsNav_sw[]; + extern NAMETAB hsEng_sw[]; + extern NAMETAB hsSpace_sw[]; + extern NAMETAB hsConsole_sw[]; + + CMD_ONE_ARG(do_hs_man); + CMD_ONE_ARG(do_hs_unman); + CMD_ONE_ARG(do_hs_disembark); + CMD_TWO_ARG(do_hs_board); + + CMD_TWO_ARG(do_hs_space_commands); + CMD_TWO_ARG(do_hs_console_commands); + CMD_TWO_ARG(do_hs_nav_commands); + CMD_TWO_ARG(do_hs_eng_commands); + #endif /* --------------------------------------------------------------------------- * Command table: Definitions for builtin commands, used to build the command *************** *** 563,568 **** --- 579,589 ---- {(char *)"\"", NULL, CA_LOCATION|CF_DARK|CA_NO_SLAVE, SAY_PREFIX, CS_ONE_ARG|CS_INTERP|CS_LEADIN, do_say}, {(char *)"-", NULL, CA_NO_GUEST|CA_NO_SLAVE|CF_DARK, 0, CS_ONE_ARG|CS_LEADIN, do_postpend}, {(char *)"~", NULL, CA_NO_GUEST|CA_NO_SLAVE|CF_DARK, 0, CS_ONE_ARG|CS_LEADIN, do_prepend}, + #ifdef HSPACE + {(char *)"man", NULL, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_ONE_ARG, do_hs_man}, + {(char *)"unman", NULL, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_ONE_ARG, do_hs_unman}, + {(char *)"disembark", NULL, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_ONE_ARG, do_hs_disembark}, + #endif {(char *)NULL, NULL, 0, 0, 0, NULL} }; *************** *** 628,633 **** --- 649,661 ---- {(char *)"slay", NULL, CA_WIZARD, KILL_SLAY, CS_TWO_ARG|CS_INTERP, do_kill}, {(char *)"whisper", NULL, CA_LOCATION|CA_NO_SLAVE, PEMIT_WHISPER, CS_TWO_ARG|CS_INTERP, do_pemit}, {(char *)"&", NULL, CA_NO_GUEST|CA_NO_SLAVE|CF_DARK, 0, CS_TWO_ARG|CS_LEADIN, do_setvattr}, + #ifdef HSPACE + {(char *)"board", NULL, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_TWO_ARG, do_hs_board}, + {(char *)"@space", hsSpace_sw, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_TWO_ARG, do_hs_space_commands}, + {(char *)"@nav", hsNav_sw, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_TWO_ARG, do_hs_nav_commands}, + {(char *)"@eng", hsEng_sw, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_TWO_ARG, do_hs_eng_commands}, + {(char *)"@console", hsConsole_sw, CA_NO_GUEST|CA_NO_SLAVE, 0, CS_TWO_ARG, do_hs_console_commands}, + #endif {(char *)NULL, NULL, 0, 0, 0, NULL} }; diff -c src.old/cque.cpp src/cque.cpp *** src.old/cque.cpp Thu Aug 3 19:34:11 2000 --- src/cque.cpp Thu Aug 3 18:23:27 2000 *************** *** 873,878 **** --- 873,881 ---- #ifndef MEMORY_BASED void dispatch_CacheTick(void *pUnused, int iUnused); #endif + #ifdef HSPACE + void dispatch_HSpace(void *pUnused, int iUnused); + #endif int CallBack_ShowDispatches(PTASK_RECORD p) { *************** *** 910,915 **** --- 913,924 ---- notify(Show_Player, tprintf("[%d]Delayed descriptor deallocation", ltd.ReturnSeconds())); } #endif // WIN32 + #ifdef HSPACE + else if (p->fpTask = dispatch_HSpace ) + { + notify(Show_Player, tprintf("[%d]HSpace Cycle", ltd.ReturnSeconds())); + } + #endif // HSPACE else { Total_SystemTasks--; diff -c src.old/create.cpp src/create.cpp *** src.old/create.cpp Thu Aug 3 19:34:11 2000 --- src/create.cpp Thu Aug 3 18:23:27 2000 *************** *** 166,172 **** * * home(player,thing) */ ! static void link_exit(dbref player, dbref exit, dbref dest) { int cost, quot; --- 166,172 ---- * * home(player,thing) */ ! void link_exit(dbref player, dbref exit, dbref dest) { int cost, quot; diff -c src.old/functions.cpp src/functions.cpp *** src.old/functions.cpp Thu Aug 3 19:34:12 2000 --- src/functions.cpp Thu Aug 3 18:23:27 2000 *************** *** 25,30 **** --- 25,34 ---- #include "ansi.h" #include "comsys.h" + #ifdef HSPACE + #include "hspace/hspace.h" + #endif + UFUN *ufun_head; extern NAMETAB indiv_attraccess_nametab[]; *************** *** 142,147 **** --- 146,169 ---- XFUNCTION(fun_connnum); XFUNCTION(fun_connleft); #endif // GAME_DOOFERMUX + + #ifdef HSPACE + XFUNCTION(hs_clone); + XFUNCTION(hs_set_missile); + XFUNCTION(hs_sysset); + XFUNCTION(hs_sys_attr); + XFUNCTION(hs_get_missile); + XFUNCTION(hs_weapon_attr); + XFUNCTION(hs_add_weapon); + XFUNCTION(hs_get_attr); + XFUNCTION(hs_xyang); + XFUNCTION(hs_zang); + XFUNCTION(hs_spacemsg); + XFUNCTION(hs_eng_systems); + XFUNCTION(hs_set_attr); + XFUNCTION(hs_srep); + XFUNCTION(hs_comm_msg); + #endif // Trim off leading and trailing spaces if the separator char is a // space -- known length version. *************** *** 6248,6253 **** --- 6270,6292 ---- {"CONNNUM", fun_connnum, 1, 0, CA_PUBLIC}, {"CONNLEFT", fun_connleft, 1, 0, CA_PUBLIC}, #endif // GAME_DOOFERMUX + #ifdef HSPACE + {"HS_CLONE", hs_clone, 1, 0, CA_PUBLIC}, + {"HS_COMM_MSG", hs_comm_msg, 8, 0, CA_PUBLIC}, + {"HS_SET_MISSILE", hs_set_missile, 3, 0, CA_PUBLIC}, + {"HS_GET_MISSILE", hs_get_missile, 2, 0, CA_PUBLIC}, + {"HS_SYSSET", hs_sysset, 2, 0, CA_PUBLIC}, + {"HS_SYS_ATTR", hs_sys_attr, 3, 0, CA_PUBLIC}, + {"HS_WEAPON_ATTR", hs_weapon_attr, 2, 0, CA_PUBLIC}, + {"HS_ADD_WEAPON", hs_add_weapon, 2, 0, CA_PUBLIC}, + {"HS_GET_ATTR", hs_get_attr, 2, 0, CA_PUBLIC}, + {"HS_SPACEMSG", hs_spacemsg, -1, FN_VARARGS, CA_PUBLIC}, + {"HS_ENG_SYS", hs_eng_systems, 1, 0, CA_PUBLIC}, + {"HS_SET_ATTR", hs_set_attr, 2, 0, CA_PUBLIC}, + {"HS_SREP", hs_srep, 2, 0, CA_PUBLIC}, + {"XYANG", hs_xyang, 4, 0, CA_PUBLIC}, + {"ZANG", hs_zang, 6, 0, CA_PUBLIC}, + #endif {NULL, NULL, 0, 0, 0} }; *************** *** 7046,7048 **** --- 7085,7181 ---- } #endif // GAME_DOOFERMUX + + #ifdef HSPACE + FUNCTION(hs_clone) + { + safe_str(HSpace.DoFunction("CLONE", player, fargs), + buff, bufc); + } + + FUNCTION(hs_set_missile) + { + safe_str(HSpace.DoFunction("SETMISSILE", player, fargs), + buff, bufc); + } + + FUNCTION(hs_sysset) + { + safe_str(HSpace.DoFunction("SYSSET", player, fargs), + buff, bufc); + } + + FUNCTION(hs_sys_attr) + { + safe_str(HSpace.DoFunction("SYSATTR", player, fargs), + buff, bufc); + } + + FUNCTION(hs_get_missile) + { + safe_str(HSpace.DoFunction("GETMISSILE", player, fargs), + buff, bufc); + } + + FUNCTION(hs_weapon_attr) + { + safe_str(HSpace.DoFunction("WEAPONATTR", player, fargs), + buff, bufc); + } + + FUNCTION(hs_add_weapon) + { + safe_str(HSpace.DoFunction("ADDWEAPON", player, fargs), + buff, bufc); + } + FUNCTION(hs_get_attr) + { + safe_str(HSpace.DoFunction("GETATTR", player, fargs), + buff, bufc); + } + + FUNCTION(hs_xyang) + { + safe_str(HSpace.DoFunction("XYANG", player, fargs), + buff, bufc); + } + + FUNCTION(hs_zang) + { + safe_str(HSpace.DoFunction("ZANG", player, fargs), + buff, bufc); + } + + FUNCTION(hs_spacemsg) + { + if( nfargs < 2 || nfargs > 7 ) + safe_str("#-1 FUNCTION (HS_SPACEMSG) EXPECTS BETWEEN 2 AND 7 ARGUMENTS", buff, bufc); + else + safe_str(HSpace.DoFunction("SPACEMSG", player, fargs), + buff, bufc); + } + + FUNCTION(hs_eng_systems) + { + safe_str(HSpace.DoFunction("GETENGSYSTEMS", player, fargs), + buff, bufc); + } + + FUNCTION(hs_set_attr) + { + safe_str(HSpace.DoFunction("SETATTR", player, fargs), + buff, bufc); + } + + FUNCTION(hs_srep) + { + safe_str(HSpace.DoFunction("SENSORCONTACTS", player, fargs), + buff, bufc); + } + + FUNCTION(hs_comm_msg) + { + safe_str(HSpace.DoFunction("COMMMSG", player, fargs), + buff, bufc); + } + #endif diff -c src.old/game.cpp src/game.cpp *** src.old/game.cpp Thu Aug 3 19:34:12 2000 --- src/game.cpp Thu Aug 3 18:23:27 2000 *************** *** 23,28 **** --- 23,32 ---- #include "comsys.h" #include "vattr.h" + #ifdef HSPACE + #include "hspace/hspace.h" + #endif + #ifdef RADIX_COMPRESSION #include "radix.h" #endif *************** *** 1119,1124 **** --- 1123,1133 ---- return; } + #ifdef HSPACE + // Save HSpace databases. Whee. + HSpace.DumpDatabases(); + #endif + BOOL bPotentialConflicts = FALSE; #if !defined(VMS) && !defined(WIN32) // If we are already dumping for some reason, and suddenly get a type 1 or *************** *** 2122,2127 **** --- 2131,2141 ---- ENDLOG; } #endif // CONCENTRATE && !WIN32 + + #ifdef HSPACE + // Initialize and load HSpace databases. + HSpace.InitSpace(mudstate.restarting); + #endif // go do it. // Only in src: hspace diff -c src.old/timer.cpp src/timer.cpp *** src.old/timer.cpp Thu Aug 3 19:34:12 2000 --- src/timer.cpp Thu Aug 3 18:23:27 2000 *************** *** 25,30 **** --- 25,34 ---- #include "command.h" #include "comsys.h" + #ifdef HSPACE + #include "hspace/hspace.h" + #endif + extern void NDECL(pool_reset); extern void FDECL(fork_and_dump, (int key)); extern void NDECL(pcache_trim); *************** *** 175,180 **** --- 179,203 ---- } #endif + #ifdef HSPACE + void dispatch_HSpace(void *pUnused, int iUnused) + { + char *cmdsave = mudstate.debug_cmd; + mudstate.debug_cmd = (char *)"< HSpace Cycle >"; + HSpace.DoCycle(); + + CLinearTimeAbsolute ltaNextTime; + ltaNextTime.GetUTC(); + + CLinearTimeDelta ltd; + ltd.SetSeconds(1); + ltaNextTime += ltd; + scheduler.DeferTask(ltaNextTime, PRIORITY_SYSTEM, dispatch_HSpace, 0, 0); + mudstate.debug_cmd = cmdsave; + } + #endif + + void init_timer(void) { CLinearTimeAbsolute ltaNow; *************** *** 217,222 **** --- 240,250 ---- // ltd.SetSeconds(45); scheduler.DeferTask(ltaNow+ltd, PRIORITY_SYSTEM, dispatch_CleanChannels, 0, 0); + #endif + + #ifdef HSPACE + ltd.SetSeconds(1); + scheduler.DeferTask(ltaNow+ltd, PRIORITY_SYSTEM, dispatch_HSpace, 0, 0); #endif } Common subdirectories: src.old/tools and src/tools src/ 40775 767 767 0 7142320144 7452 5 ustar mux mux src/hspace/ 40775 767 767 0 7141305173 10721 5 ustar mux mux src/hspace/Makefile 100644 767 767 5015 7141305141 12450 0 ustar mux mux # Makefile for HSpace # stupid SYS V shell SHELL=/bin/sh CFLAGS=$(CCFLAGS) -DHSPACE CXX=gcc # Used for protoizing .cpp.o: $(CXX) $(CFLAGS) -w -c $< SPACE_O=hscelestial.o hsclass.o hscmds.o hsconf.o \ hsconsole.o hsconsolecmds.o hsdb.o hseng.o hsengcmds.o \ hsengines.o hsfuel.o hsfuncs.o hsinterface.o hsmain.o \ hsmissile.o hsnavcmds.o hsobjects.o hspace.o \ hsplanet.o hsship.o hsshipnav.o hsshipeng.o hstrig.o \ hsuniverse.o hsutils.o hsweapon.o hscomm.o \ hsterritory.o all: (cd ..; make) hspace: $(SPACE_O) @echo "Done with HSpace." clean: @rm -f *.o @echo "Temporarily files removed." hscmds.o: hscmds.h hsuniverse.h hspace.h hsdb.h hsinterface.h hsutils.h hsconf.h hscelestial.o: hscelestial.h hsinterface.h hsutils.h hsobjects.h hsclass.o: hsclass.h hsengines.h hsutils.h hsconf.h hstypes.h hseng.h hsfuel.h hsconf.o: hsconf.h hsutils.h hstypes.h hsconsole.o: hsobjects.h hsutils.h hsinterface.h hsconsolecmds.o: hstypes.h hsdb.h hscmds.h hsobjects.h hsutils.h hsinterface.h hsdb.o: hsdb.h hsweapon.h hsinterface.h hsutils.h hsuniverse.h hstypes.h hsobjects.h hscelestial.h hseng.o: hseng.h hsutils.h hsuniverse.h hsengines.h hsconf.h hspace.h hstypes.h hsengcmds.o: hscmds.h hsdb.h hseng.h hsinterface.h hsutils.h hsengines.o: hsengines.h hsobjects.h hspace.h hsconf.h hsfuel.h hsfuel.o: hsfuel.h hstypes.h hseng.h hsfuncs.o: hstypes.h hsfuncs.h hsinterface.h hsobjects.h hsdb.h hsutils.h hsuniverse.h hspace.h hscomm.h hsinterface.o: hstypes.h hsinterface.h hsmain.o: hspace.h hsmissile.o: hsmissile.h hsuniverse.h hsutils.h hsinterface.h hspace.h hsweapon.h hsobjects.h hsnavcmds.o: hscmds.h hsdb.h hseng.h hsinterface.h hsutils.h hsconf.h hsobjects.o: hsobjects.h hsinterface.h hsutils.h hsuniverse.h hstypes.h hsclass.h hsweapon.h hsfuel.h hspace.o: hspace.h hsuniverse.h hscmds.h hsfuncs.h hsconf.h hsdb.h hstypes.h hsplanet.o: hsobjects.h hsuniverse.h hsinterface.h hsutils.h hsship.o: hsobjects.h hsinterface.h hsuniverse.h hsutils.h hsconf.h hspace.h hsengines.h hscomm.h hsshipnav.o: hsobjects.h hscelestial.h hsinterface.h hsutils.h hsconf.h hsengines.h hsdb.h hspace.h hsshipnav.o: hsuniverse.h hsshipeng.o: hsobjects.h hsinterface.h hsutils.h hsconf.h hspace.h hstrig.o: hscopyright.h hsuniverse.o: hsuniverse.h hsutils.h hspace.h hseng.h hsconf.h hsinterface.h hsobjects.h hscelestial.h hsutils.o: hstypes.h hsutils.h hsweapon.o: hsweapon.h hsobjects.h hsinterface.h hspace.h hsutils.h hsmissile.h hstypes.h hscomm.o: hsobjects.h hsuniverse.h hsterritory.o: hsterritory.h hsobjects.h hsconf.h hsuniverse.h hsinterface.h hsutils.h src/hspace/hscelestial.cpp 100644 767 767 3126 7141305141 14015 0 ustar mux mux #include "hscopyright.h" #include "hscelestial.h" #include <stdlib.h> #include "hsinterface.h" #include "hsutils.h" #include "hsexterns.h" CHSCelestial::CHSCelestial(void) { } CHSCelestial::~CHSCelestial(void) { } // Overridden from the CHSObject class BOOL CHSCelestial::HandleKey(int key, char *strValue, FILE *fp) { // Find the key and handle it switch(key) { default: // Pass it up to CHSObject return (CHSObject::HandleKey(key, strValue, fp)); } } // Basic celestial objects are cyan char *CHSCelestial::GetObjectColor(void) { static char tbuf[32]; sprintf(tbuf, "%s%s", ANSI_HILITE, ANSI_CYAN); return tbuf; } // Returns the character representing celestials in general char CHSCelestial::GetObjectCharacter(void) { // How about a simple star return '*'; } // Overridden from the CHSObject class void CHSCelestial::WriteToFile(FILE *fp) { // Write base class info first, then our's. CHSObject::WriteToFile(fp); } void CHSCelestial::ClearObjectAttrs(void) { CHSObject::ClearObjectAttrs(); // Clear the attributes hsInterface.AtrAdd(m_objnum, "HSDB_X", NULL, GOD); hsInterface.AtrAdd(m_objnum, "HSDB_Y", NULL, GOD); hsInterface.AtrAdd(m_objnum, "HSDB_Z", NULL, GOD); hsInterface.AtrAdd(m_objnum, "HSDB_UID", NULL, GOD); } UINT CHSCelestial::GetType(void) { return m_type; } BOOL CHSCelestial::SetAttributeValue(char *strName, char *strValue) { return CHSObject::SetAttributeValue(strName, strValue); } char *CHSCelestial::GetAttributeValue(char *strName) { return CHSObject::GetAttributeValue(strName); } src/hspace/hscelestial.h 100664 767 767 2610 7141305141 13461 0 ustar mux mux #ifndef __HSCELESTIAL_INCLUDED__ #define __HSCELESTIAL_INCLUDED__ #include "hsobjects.h" // The CHSCelestial object is derived from the base object class and // is used to derive other types of celestial objects. class CHSCelestial : public CHSObject { public: CHSCelestial(void); virtual ~CHSCelestial(void); // Methods virtual void WriteToFile(FILE *); virtual char *GetAttributeValue(char *); virtual BOOL SetAttributeValue(char *, char *); virtual void ClearObjectAttrs(void); virtual char *GetObjectColor(void); virtual char GetObjectCharacter(void); UINT GetType(void); protected: virtual BOOL HandleKey(int, char *, FILE *fp = NULL); }; // The CHSPlanet object is derived from the celestial object // to handle functions and information specific to planets. class CHSPlanet : public CHSCelestial { public: CHSPlanet(void); ~CHSPlanet(void); BOOL AddLandingLoc(dbref); void ClearObjectAttrs(void); void WriteToFile(FILE *); void GiveScanReport(CHSObject *, dbref, BOOL); char *GetObjectColor(void); char GetObjectCharacter(void); char *GetAttributeValue(char *); BOOL SetAttributeValue(char *, char *); CHSLandingLoc *FindLandingLoc(dbref); CHSLandingLoc *GetLandingLoc(int); protected: CHSLandingLoc *NewLandingLoc(void); BOOL HandleKey(int, char *, FILE *); // Attributes CHSLandingLoc *m_landing_locs[HS_MAX_LANDING_LOCS]; }; #endif // __HSCELESTIAL_INCLUDED__ src/hspace/hsclass.cpp 100644 767 767 21670 7141305141 13201 0 ustar mux mux #include "hscopyright.h" #include <stdlib.h> #include "hsexterns.h" #ifdef I_STRING #include <string.h> #else #include <strings.h> #endif #include "hsclass.h" #include "hsengines.h" #include "hsutils.h" #include "hsconf.h" CHSClassArray caClasses; // One instance of this .. right here! CHSClassArray::CHSClassArray(void) { UINT idx; for (idx = 0; idx < HS_MAX_CLASSES; idx++) m_classes[idx] = NULL; m_num_classes = 0; } BOOL CHSClassArray::LoadFromFile(char *lpstrPath) { FILE *fp; UINT idx; int ok; char tbuf[LBUF_SIZE]; char lbuf[256]; char strKey[64]; char strValue[64]; HS_DBKEY key; CHSEngSystem *cSys; sprintf(tbuf, "LOADING: %s", lpstrPath); hs_log(tbuf); idx = 0; fp = fopen(lpstrPath, "r"); if (!fp) { sprintf(tbuf, "ERROR: Couldn't open %s for loading.", lpstrPath); hs_log(tbuf); return FALSE; } // Load database version for possible conversion. strcpy(tbuf, getstr(fp)); extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); if (strcasecmp(strKey, "DBVERSION")) { // Pre-4.0 database } else { // 4.0 and later strcpy(tbuf, getstr(fp)); // Beginning ! mark } if (*tbuf == EOF) { ok = 0; } else { if( strcasecmp(tbuf, "*END*") ) { ok = 1; m_classes[idx] = new HSSHIPCLASS; SetClassDefaults(m_classes[idx]); } else ok = 0; } while (ok) { strcpy(tbuf, getstr(fp)); if (*tbuf == '!') { idx++; m_classes[idx] = new HSSHIPCLASS; SetClassDefaults(m_classes[idx]); continue; } else if (!strcasecmp(tbuf, "*END*")) { ok = 0; idx++; continue; } // Must be a key/value pair, so work with that. extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); // Figure out the key type, and see what we can // do with it. key = HSFindKey(strKey); switch(key) { case HSK_NAME: strcpy(m_classes[idx]->m_name, strValue); break; case HSK_DROP_CAPABLE: m_classes[idx]->m_can_drop = atoi(strValue); break; case HSK_CARGOSIZE: m_classes[idx]->m_cargo_size = atoi(strValue); break; case HSK_MAXFUEL: m_classes[idx]->m_maxfuel = atoi(strValue); break; case HSK_NUMCREWS: m_classes[idx]->m_ncrews = atoi(strValue); break; case HSK_MAXHULL: m_classes[idx]->m_maxhull = atoi(strValue); break; case HSK_SIZE: m_classes[idx]->m_size = atoi(strValue); break; case HSK_SYSTEMDEF: // Input a list of systems cSys = LoadSystem(fp, idx); if (cSys) { m_classes[idx]->m_systems.AddSystem(cSys); } break; default: sprintf(lbuf, "WARNING: Invalid db key \"%s\" encountered.", strKey); hs_log(lbuf); break; } } fclose(fp); m_classes[idx] = NULL; m_num_classes = idx; sprintf(lbuf, "LOADING: %s - %d classes loaded (done)", lpstrPath, idx); hs_log(lbuf); return TRUE; } // Prints information about all of the loaded classes to // the specified player. void CHSClassArray::PrintInfo(int player) { if (m_num_classes <= 0) { notify((int)player, (char *)"No ship classes loaded."); return; } // Print the header notify(player, "[ID ] Name"); int idx; for (idx = 0; idx < HS_MAX_CLASSES; idx++) { if (m_classes[idx]) { notify(player, tprintf("[%3d] %s", idx, m_classes[idx]->m_name)); } } } // Attempts to allocate space for a new class in the // array and returns a pointer to that class structure. HSSHIPCLASS *CHSClassArray::NewClass(void) { // Is the array full? if (m_num_classes >= (HS_MAX_CLASSES -1)) return NULL; m_classes[m_num_classes] = new HSSHIPCLASS; SetClassDefaults(m_classes[m_num_classes]); m_num_classes++; m_classes[m_num_classes] = NULL; return m_classes[m_num_classes - 1]; } // Can be used to delete an existing class. Give it a class // number, and it will try to delete it. It does NOT do any // operations with objects of this class. It is your responsibility // to make sure objects of that class are appropriately handled. BOOL CHSClassArray::RemoveClass(UINT uClass) { int idx; // Error check if (!GoodClass(uClass)) return FALSE; // Delete the class, then move the rest above it down // one slot. delete m_classes[uClass]; for (idx = uClass+1; idx < HS_MAX_CLASSES; idx++) { m_classes[idx-1] = m_classes[idx]; } // There's definitely a free spot at the end, so NULLify it. m_classes[HS_MAX_CLASSES-1] = NULL; m_num_classes--; return TRUE; } // When the LoadFromFile() encounters a SYSTEMDEF key, it // calls upon this function to load the system information // from the file, construct a CHSEngSystem of some type, load // it with information, and return that system. CHSEngSystem *CHSClassArray::LoadSystem(FILE *fp, int slot) { CHSEngSystem *cSys; char strKey[64]; char strValue[64]; char *ptr; char tbuf[256]; HS_DBKEY key; HSS_TYPE type; cSys = NULL; // We start here, after LoadFromFile() already encountered // the SYSTEMDEF keyword. We figure out the type of system, // which should be the first keyword, and then we load // according to that. // // We have NO WAY of knowing what kind of information each // system needs. We ONLY know what types of systems exist // because this is defined in hseng.h. Thus, we simply // figure out the type of system, and then pass the key/value // information to the system as if it were setting attributes. while(fgets(tbuf, 256, fp)) { // Truncate newlines if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); key = HSFindKey(strKey); // Check for end of database .. would be an error if (!strcmp(strKey, "*END*")) { hs_log( "ERROR: Encountered end of classdb before loading specified system list."); break; } switch(key) { case HSK_SYSTYPE: type = (HSS_TYPE) atoi(strValue); cSys = m_classes[slot]->m_systems.NewSystem(type); if (!cSys) { sprintf(tbuf, "ERROR: Invalid system type %d encountered.", type); hs_log(tbuf); } break; case HSK_SYSTEMEND: return cSys; default: // Simply call upon the object to set it's // own attributes. We don't know what they // are. if (cSys) { cSys->SetAttributeValue(strKey, strValue); } break; } } return cSys; } // Saves class information to the class database. To do this, // we just run down the list of classes, outputting some standard // variables, and then running down the system array for each // class, using the Sys->SaveToFile() to output system information. void CHSClassArray::SaveToFile(char *lpstrPath) { FILE *fp; UINT i; char tbuf[512]; // Open output file. fp = fopen(lpstrPath, "w"); if (!fp) { sprintf(tbuf, "ERROR: Unable to write classes to %s.", lpstrPath); hs_log(tbuf); return; } // Write out the database version fprintf(fp, "DBVERSION=4.0\n"); // Ok. Now just run through the classes, outputting information. for (i = 0; i < m_num_classes; i++) { // Output standard variables for each class fprintf(fp, "!\n"); fprintf(fp, "NAME=%s\n", m_classes[i]->m_name); fprintf(fp, "CARGOSIZE=%d\n", m_classes[i]->m_cargo_size); fprintf(fp, "SIZE=%d\n", m_classes[i]->m_size); fprintf(fp, "NUMCREWS=%d\n", m_classes[i]->m_ncrews); fprintf(fp, "MAXHULL=%d\n", m_classes[i]->m_maxhull); fprintf(fp, "MAXFUEL=%d\n", m_classes[i]->m_maxfuel); fprintf(fp, "DROP CAPABLE=%d\n", m_classes[i]->m_can_drop); // Now output system information m_classes[i]->m_systems.SaveToFile(fp); } fprintf(fp, "*END*\n"); fclose(fp); } BOOL CHSClassArray::GoodClass(UINT uClass) { if (uClass < 0 || uClass >= m_num_classes) return FALSE; return TRUE; } HSSHIPCLASS *CHSClassArray::GetClass(UINT uClass) { if (!GoodClass(uClass)) return NULL; return m_classes[uClass]; } UINT CHSClassArray::NumClasses(void) { return m_num_classes; } // Attempts to load a picture from the account into the // supplied buffer. BOOL CHSClassArray::LoadClassPicture(int iClass, char **buff) { FILE *fp; char tbuf[512]; char *ptr; int idx; sprintf(tbuf, "%s/class_%d.pic", HSCONF.picture_dir, iClass); fp = fopen(tbuf, "r"); if (!fp) return FALSE; // Load the file idx = 0; while(fgets(tbuf, 512, fp)) { if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; buff[idx] = new char[strlen(tbuf) + 1]; strcpy(buff[idx], tbuf); idx++; } buff[idx] = NULL; return TRUE; } // Sets some default values for the supplied ship class // structure. Since ship classes are just structs and // not class objects, we have to initialize them a bit with // some viable default values. void CHSClassArray::SetClassDefaults(HSSHIPCLASS *sClass) { // Don't allow sizes of 0 sClass->m_size = 1; sClass->m_name[0] = '\0'; sClass->m_ncrews = 0; sClass->m_cargo_size = 0; sClass->m_maxhull = 1; sClass->m_can_drop = FALSE; } src/hspace/hsclass.h 100644 767 767 3636 7141305141 12630 0 ustar mux mux #ifndef __HSCLASS_INCLUDED__ #define __HSCLASS_INCLUDED__ #include "hstypes.h" #include "hseng.h" #include "hsfuel.h" #define SHIP_CLASS_NAME_LEN 32 /* A ship class */ typedef struct { char m_name[SHIP_CLASS_NAME_LEN]; UINT m_size; /* Scale of the vessel */ UINT m_ncrews; /* Number of damage crews */ UINT m_cargo_size; /* Size of the cargo bay */ UINT m_maxhull; /* Maximum hull pts */ UINT m_maxfuel; /* Maximum amount of fuel that can be stored */ BOOL m_can_drop; /* Has drop jets or not */ // The following are handled by systems UINT m_acceleration;/* Acceleration rate */ float m_turnrate; /* Turn rate of the ship */ float m_max_velocity;/* Maximum velocity */ float m_maxfore; /* Maximum foreshield pts */ int m_maxpower; /* Maximum power output */ float m_maxaft; /* Maximum aftshield pts */ float m_fore_regen; /* Forward shield regeneration rate */ float m_aft_regen; /* Aft shield regeneration rate */ int m_can_jump; /* Has jump drives or not */ int m_fuel_eff; /* Fuel consumption rate in thousands */ int m_min_jump_speed;/* Minimum speed to enter hyperspace */ int m_can_cloak; /* Cloakable or not */ int m_sensor_rating;/* Sensor array rating */ char m_fuel_xfer; /* Has fuel transfer systems or not */ CHSSystemArray m_systems; // Array of available systems }HSSHIPCLASS; #define HS_MAX_CLASSES 100 class CHSClassArray { public: CHSClassArray(void); BOOL LoadFromFile(char *); BOOL GoodClass(UINT); BOOL RemoveClass(UINT); UINT NumClasses(void); BOOL LoadClassPicture(int, char **); void SaveToFile(char *); void PrintInfo(int); CHSEngSystem *LoadSystem(FILE *, int); HSSHIPCLASS *GetClass(UINT); HSSHIPCLASS *NewClass(void); protected: void SetClassDefaults(HSSHIPCLASS *); UINT m_num_classes; HSSHIPCLASS *m_classes[HS_MAX_CLASSES]; }; extern CHSClassArray caClasses; #endif src/hspace/hscmds.cpp 100644 767 767 144442 7141305141 13045 0 ustar mux mux #include "hscopyright.h" #include <stdlib.h> #include <string.h> #include "hscmds.h" #include "hsuniverse.h" #include "hspace.h" #include "hsdb.h" #include "hsinterface.h" #include "hsutils.h" #include "hsconf.h" #include "hsterritory.h" #include "hsexterns.h" // To add a new HSpace command, add it's prototype here, then // add it to the hsSpaceCommandArray below. HSPACE_COMMAND_PROTO(hscNewWeapon) HSPACE_COMMAND_PROTO(hscCloneObject) HSPACE_COMMAND_PROTO(hscCheckSpace) HSPACE_COMMAND_PROTO(hscStartSpace) HSPACE_COMMAND_PROTO(hscHaltSpace) HSPACE_COMMAND_PROTO(hscActivateShip) HSPACE_COMMAND_PROTO(hscMothballObject) HSPACE_COMMAND_PROTO(hscNewUniverse) HSPACE_COMMAND_PROTO(hscDelUniverse) HSPACE_COMMAND_PROTO(hscSetAttribute) HSPACE_COMMAND_PROTO(hscAddLandingLoc) HSPACE_COMMAND_PROTO(hscAddSroom) HSPACE_COMMAND_PROTO(hscDelSroom) HSPACE_COMMAND_PROTO(hscAddConsole) HSPACE_COMMAND_PROTO(hscDelConsole) HSPACE_COMMAND_PROTO(hscDelClass) HSPACE_COMMAND_PROTO(hscAddObject) HSPACE_COMMAND_PROTO(hscRepairShip) HSPACE_COMMAND_PROTO(hscSetSystemAttr) HSPACE_COMMAND_PROTO(hscAddWeapon) HSPACE_COMMAND_PROTO(hscSetMissile) HSPACE_COMMAND_PROTO(hscNewClass) HSPACE_COMMAND_PROTO(hscDumpClassInfo) HSPACE_COMMAND_PROTO(hscAddSysClass) HSPACE_COMMAND_PROTO(hscSysInfoClass) HSPACE_COMMAND_PROTO(hscSysInfo) HSPACE_COMMAND_PROTO(hscSetSystemAttrClass) HSPACE_COMMAND_PROTO(hscSetAttrClass) HSPACE_COMMAND_PROTO(hscListDatabase) HSPACE_COMMAND_PROTO(hscDelWeapon) HSPACE_COMMAND_PROTO(hscAddTerritory) HSPACE_COMMAND_PROTO(hscDelTerritory) HSPACE_COMMAND_PROTO(hscSetAttrWeapon) // For external calling from C code #ifdef PENNMUSH extern "C" { #endif HSPACE_COMMAND_PROTO(hscManConsole) // Not an @space command HSPACE_COMMAND_PROTO(hscUnmanConsole) // Not either. HSPACE_COMMAND_PROTO(hscDisembark) // Nope, not one. HSPACE_COMMAND_PROTO(hscBoardShip) // Nope. #ifdef PENNMSUH } #endif #ifdef MUX NAMETAB hsSpace_sw[] = { {(char *)"activate", 2, CA_WIZARD, 1}, {(char *)"addconsole", 4, CA_WIZARD, 2}, {(char *)"addlandingloc", 4, CA_WIZARD, 3}, {(char *)"addobject", 4, CA_WIZARD, 4}, {(char *)"addsroom", 5, CA_WIZARD, 5}, {(char *)"addsysclass", 5, CA_WIZARD, 6}, {(char *)"addterritory", 4, CA_WIZARD, 7}, {(char *)"addweapon", 4, CA_WIZARD, 8}, {(char *)"clone", 1, CA_WIZARD, 9}, {(char *)"delclass", 5, CA_WIZARD, 10}, {(char *)"delconsole", 5, CA_WIZARD, 11}, {(char *)"delsroom", 4, CA_WIZARD, 12}, {(char *)"delterritory", 4, CA_WIZARD, 13}, {(char *)"deluniverse", 4, CA_WIZARD, 14}, {(char *)"delweapon", 4, CA_WIZARD, 15}, {(char *)"dumpclass", 2, CA_WIZARD, 16}, {(char *)"halt", 1, CA_WIZARD, 17}, {(char *)"list", 1, CA_WIZARD, 18}, {(char *)"mothball", 1, CA_WIZARD, 19}, {(char *)"newclass", 4, CA_WIZARD, 20}, {(char *)"newuniverse", 4, CA_WIZARD, 21}, {(char *)"newweapon", 4, CA_WIZARD, 22}, {(char *)"repair", 1, CA_WIZARD, 23}, {(char *)"set", 3, CA_WIZARD, 24}, {(char *)"setclass", 4, CA_WIZARD, 25}, {(char *)"setmissile", 4, CA_WIZARD, 26}, {(char *)"setweapon", 4, CA_WIZARD, 27}, {(char *)"sysinfo", 7, CA_WIZARD, 28}, {(char *)"sysinfoclass", 8, CA_WIZARD, 29}, {(char *)"sysset", 6, CA_WIZARD, 30}, {(char *)"syssetclass", 7, CA_WIZARD, 31}, {(char *)"start", 2, CA_WIZARD, 32}, {NULL, 0, 0, 0} }; extern NAMETAB hsConsole_sw[]; extern NAMETAB hsNav_sw[]; extern NAMETAB hsEng_sw[]; extern hs_command hConsoleCommands[]; extern hs_command hNavCommands[]; extern hs_command hEngCommands[]; hs_command hSpaceCommands[] = { hscCheckSpace, hscActivateShip, hscAddConsole, hscAddLandingLoc, hscAddObject, hscAddSroom, hscAddSysClass, hscAddTerritory, hscAddWeapon, hscCloneObject, hscDelClass, hscDelConsole, hscDelSroom, hscDelTerritory, hscDelUniverse, hscDelWeapon, hscDumpClassInfo, hscHaltSpace, hscListDatabase, hscMothballObject, hscNewClass, hscNewUniverse, hscNewWeapon, hscRepairShip, hscSetAttribute, hscSetAttrClass, hscSetMissile, hscSetAttrWeapon, hscSysInfo, hscSysInfoClass, hscSetSystemAttr, hscSetSystemAttrClass, hscStartSpace }; NAMETAB* CommandTabs[] = { hsNav_sw, hsEng_sw, hsSpace_sw, hsConsole_sw }; hs_command* hCommands[] = { hNavCommands, hEngCommands, hSpaceCommands, hConsoleCommands }; int CommandsMax = 3; int SubCommandsMax[] = { 14, 4, 32, 12}; char* CommandNames[] = { "@NAV", "@ENG", "@SPACE", "@CONSOLE" }; hs_command LookupCommand(int command, int subcommand) { if( command > CommandsMax ) return NULL; if( subcommand > SubCommandsMax[command ] ) return NULL; return hCommands[command][subcommand]; } char* LookupCommandName(int command) { if( command > CommandsMax ) return NULL; return CommandNames[command]; } char* LookupSubCommandName(int command, int subcommand) { if( command > CommandsMax ) return NULL; if( subcommand > SubCommandsMax[command] ) return NULL; return CommandTabs[command][subcommand].name; } void do_hs_space_commands(dbref player, dbref thing, int key, char* arg1, char* arg2) { HSpace.DoCommand(2, key, arg1, arg2, player); } void do_hs_console_commands(dbref player, dbref thing, int key, char* arg1, char* arg2) { HSpace.DoCommand(3, key, arg1, arg2, player); } void do_hs_nav_commands(dbref player, dbref thing, int key, char* arg1, char* arg2) { HSpace.DoCommand(0, key, arg1, arg2, player); } void do_hs_eng_commands(dbref player, dbref thing, int key, char* arg1, char* arg2) { HSpace.DoCommand(1, key, arg1, arg2, player); } void do_hs_man(dbref player, dbref thing, int key, char* arg) { hscManConsole(player, arg, NULL); } void do_hs_unman(dbref player, dbref thing, int key, char* arg) { hscUnmanConsole(player, arg, NULL); } void do_hs_disembark(dbref player, dbref thing, int key, char* arg) { hscDisembark(player, arg, NULL); } void do_hs_board(dbref player, dbref thing, int key, char* arg1, char* arg2) { hscBoardShip(player, arg1, arg2); } #endif #ifdef PENNMUSH HSPACE_COMMAND hsSpaceCommandArray[] = { "", hscCheckSpace, HCP_ANY, "ACTIVATE", hscActivateShip, HCP_WIZARD, "ADDCONSOLE", hscAddConsole, HCP_WIZARD, "ADDLANDINGLOC", hscAddLandingLoc, HCP_WIZARD, "ADDOBJECT", hscAddObject, HCP_WIZARD, "ADDSROOM", hscAddSroom, HCP_WIZARD, "ADDSYSCLASS", hscAddSysClass, HCP_WIZARD, "ADDTERRITORY", hscAddTerritory, HCP_WIZARD, "ADDWEAPON", hscAddWeapon, HCP_WIZARD, "CLONE", hscCloneObject, HCP_WIZARD, "DELCLASS", hscDelClass, HCP_WIZARD, "DELCONSOLE", hscDelConsole, HCP_WIZARD, "DELSROOM", hscDelSroom, HCP_WIZARD, "DELTERRITORY", hscDelTerritory, HCP_WIZARD, "DELUNIVERSE", hscDelUniverse, HCP_WIZARD, "DELWEAPON", hscDelWeapon, HCP_WIZARD, "DUMPCLASS", hscDumpClassInfo, HCP_WIZARD, "HALT", hscHaltSpace, HCP_WIZARD, "LIST", hscListDatabase, HCP_WIZARD, "MOTHBALL", hscMothballObject, HCP_WIZARD, "NEWCLASS", hscNewClass, HCP_WIZARD, "NEWUNIVERSE", hscNewUniverse, HCP_WIZARD, "NEWWEAPON", hscNewWeapon, HCP_WIZARD, "REPAIR", hscRepairShip, HCP_WIZARD, "SET", hscSetAttribute, HCP_WIZARD, "SETCLASS", hscSetAttrClass, HCP_WIZARD, "SETMISSILE", hscSetMissile, HCP_WIZARD, "SETWEAPON", hscSetAttrWeapon, HCP_WIZARD, "SYSINFO", hscSysInfo, HCP_WIZARD, "SYSINFOCLASS", hscSysInfoClass, HCP_WIZARD, "SYSSET", hscSetSystemAttr, HCP_WIZARD, "SYSSETCLASS", hscSetSystemAttrClass, HCP_WIZARD, "START", hscStartSpace, HCP_WIZARD, NULL, NULL, 0 }; // Finds a command with a given switch in the supplied command array. HSPACE_COMMAND *hsFindCommand(char *switches, HSPACE_COMMAND *cmdlist) { HSPACE_COMMAND *ptr; int len; len = switches ? strlen(switches) : 0; for (ptr = cmdlist; ptr->key; ptr++) { // Check to see if the key is empty AND the switch is null if (!*ptr->key && (len == 0)) return ptr; // Straight comparison of switch and key if (!strncmp(switches, ptr->key, len)) return ptr; } return NULL; } #endif // Called from the game to give a status of HSpace HSPACE_COMMAND_HDR(hscCheckSpace) { UINT uActiveShips; UINT uShips; UINT uCelestials; CHSUniverse *cUniv; int i; // If not a wizard, then just print out the HSpace version // and activity status. notify(player, HSPACE_VERSION); notify(player, tprintf(" The system is currently %s.", HSpace.Active() ? "ACTIVE" : "INACTIVE")); if (!Wizard(player)) { return; } // Cycle time notify(player, tprintf(" Time per cycle: %.1fms", HSpace.CycleTime())); // Tally up active ships in universes. uActiveShips = 0; uShips = 0; uCelestials = 0; for (i = 0; i < HS_MAX_UNIVERSES; i++) { cUniv = uaUniverses.GetUniverse(i); if (cUniv) { uActiveShips += cUniv->NumActiveObjects(HST_SHIP); uShips += cUniv->NumObjects(HST_SHIP); uCelestials += cUniv->NumObjects(HST_PLANET); } } // DB information notify(player, "HSpace Database Report:"); notify(player, tprintf(" Weapons : %4d", dbHSDB.NumWeapons())); notify(player, tprintf(" Classes : %4d", caClasses.NumClasses())); notify(player, tprintf(" Universes : %4d", dbHSDB.NumUniverses())); notify(player, tprintf(" Ships : %4d (%d)",uShips,uActiveShips)); notify(player, tprintf(" Celestials : %4d", uCelestials)); notify(player, tprintf(" Territories: %4d", taTerritories.NumTerritories())); } // Start HSpace HSPACE_COMMAND_HDR(hscStartSpace) { if (HSpace.Active()) notify(player, "HSpace: System already active."); else { HSpace.SetCycle(TRUE); notify(player, "HSpace: System started."); } } // Stop HSpace HSPACE_COMMAND_HDR(hscHaltSpace) { if (!HSpace.Active()) notify(player, "HSpace: System already inactive."); else { HSpace.SetCycle(FALSE); notify(player, "HSpace: System halted."); } } // Activates a new ship HSPACE_COMMAND_HDR(hscActivateShip) { CHSShip *newShip; int iClass; dbref dbConsole; CHSUniverse *unDest; int idx; // Find the console dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; if (Typeof(dbConsole) != TYPE_THING) { notify(player, tprintf("%s(#%d) is not of type THING.", Name(dbConsole), dbConsole)); return; } // See if it's already a ship. if (dbHSDB.FindShip(dbConsole)) { notify(player, "That object is already an HSpace ship."); return; } // Check the class if (!arg_right || !*arg_right) iClass = -1; else iClass = atoi(arg_right); if (!caClasses.GoodClass(iClass)) { notify(player, "Invalid ship class specified."); return; } // Allocate the new ship newShip = new CHSShip; newShip->SetDbref(dbConsole); // Set the class info if (!newShip->SetClassInfo(iClass)) { notify(player, "Error setting class info. Aborting."); delete newShip; return; } // Add the ship to the first available universe unDest = NULL; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (unDest = uaUniverses.GetUniverse(idx)) break; } if (!unDest) { notify(player, "No valid universe for this ship exists."); delete newShip; return; } if (!unDest->AddObject(newShip)) { notify(player, "Ship could not be added to default universe."); delete newShip; return; } // Set the universe id for the ship newShip->SetUID(unDest->GetID()); // Set the flag hsInterface.SetFlag(dbConsole, THING_HSPACE_OBJECT); // Fully repair the ship newShip->TotalRepair(); notify(player, tprintf("%s (#%d) - activated with class %d.", Name(dbConsole), dbConsole, iClass)); } // Deactivates any HSpace object. HSPACE_COMMAND_HDR(hscMothballObject) { CHSObject *cObj; dbref dbObj; // Find the object dbObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbObj == NOTHING) return; if (Typeof(dbObj) != TYPE_THING) { notify(player, tprintf("%s(#%d) is not of type THING.", Name(dbObj), dbObj)); return; } // See if it's a space object. if (!(cObj = dbHSDB.FindObject(dbObj))) { notify(player, "That is either not a space object, or it has no HSDB_TYPE attribute."); return; } // Find the universe it's in. CHSUniverse *uSource; uSource = uaUniverses.FindUniverse(cObj->GetUID()); // Remove it from the universe. if (uSource) uSource->RemoveObject(cObj); // Delete the object. This is the end of it all. delete cObj; notify(player, tprintf("HSpace object(#%d) mothballed.", dbObj)); } // Allows the creation of a new universe. HSPACE_COMMAND_HDR(hscNewUniverse) { dbHSDB.CreateNewUniverse(player, arg_left); } // Allows the destruction of an existing universe. HSPACE_COMMAND_HDR(hscDelUniverse) { dbHSDB.DeleteUniverse(player, arg_left); } // Allows the addition of a new landing location to a planet or // ship. HSPACE_COMMAND_HDR(hscAddLandingLoc) { dbref dbConsole; dbref dbRoom; CHSObject *cObj; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; dbRoom = hsInterface.NoisyMatchRoom(player, arg_right); if (dbRoom == NOTHING) return; if (Typeof(dbRoom) != TYPE_ROOM) { notify(player, "You may only add rooms as landing locations."); return; } // Find the planet or ship cObj = dbHSDB.FindObject(dbConsole); if (!cObj) { notify(player, tprintf("That thing(#%d) is not an HSpace object.", dbConsole)); return; } // Determine type of object, and try to add the landing loc switch(cObj->GetType()) { case HST_SHIP: CHSShip *cShip; cShip = (CHSShip *)cObj; if (!cShip->AddLandingLoc(dbRoom)) notify(player, "Failed to add landing loc. Check log for details."); else notify(player, "Landing location added to ship."); break; case HST_PLANET: CHSPlanet *cPlanet = (CHSPlanet *)cObj; if (!cPlanet->AddLandingLoc(dbRoom)) notify(player, "Failed to add landing loc. Check log for details."); else notify(player, "Landing location added to planet."); break; } } // Allows an attribute to be modified on any type of HSpace object. HSPACE_COMMAND_HDR(hscSetAttribute) { dbref dbConsole; char left_switch[64]; char right_switch[64]; char *ptr, *dptr; // We have to pull out the left and right parts of // the @space/set <console>/<attrib> format. dptr = left_switch; for (ptr = arg_left; *ptr && *ptr != '/'; ptr++) { // Check for buffer overflow if ((dptr - left_switch) > 62) { notify(player, "Invalid object/attribute pair supplied."); return; } *dptr++ = *ptr; } *dptr = '\0'; // Right side. if (!*ptr) { notify(player, "Invalid object/attribute pair supplied."); return; } ptr++; dptr = right_switch; while (*ptr) { *dptr++ = *ptr++; } *dptr = '\0'; dbConsole = hsInterface.NoisyMatchThing(player, left_switch); if (dbConsole == NOTHING) return; if (!*right_switch) { notify(player, "Invalid or no attribute name supplied."); return; } // Ok, find the HSpace object, and set the attribute. // Check flags first. if (hsInterface.HasFlag(dbConsole, TYPE_ROOM, ROOM_HSPACE_LANDINGLOC)) { CHSLandingLoc *llLoc; llLoc = dbHSDB.FindLandingLoc(dbConsole); if (!llLoc) { notify(player, "That thing appears to be a landing location, but it's not."); return; } if (!llLoc->SetAttributeValue(right_switch, arg_right)) notify(player, "Attribute - failed."); else if (!*arg_right) notify(player, "Attribute - cleared."); else notify(player, "Attribute - set."); } else if (hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_OBJECT)) { CHSObject *cObj; cObj = dbHSDB.FindObject(dbConsole); if (!cObj) { notify(player, "That thing is not a true HSpace object."); return; } if (!cObj->SetAttributeValue(right_switch, arg_right)) notify(player, "Attribute - failed."); else if (!*arg_right) notify(player, "Attribute - cleared."); else notify(player, "Attribute - set."); } else if (hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_CONSOLE)) { CHSObject *cObj; CHSConsole *cConsole; cObj = dbHSDB.FindObjectByConsole(dbConsole); cConsole = dbHSDB.FindConsole(dbConsole); if (!cConsole) { notify(player, "That console does not belong to any HSpace object."); return; } if (!cObj) { notify(player, "That thing is not a true HSpace object."); return; } // Try to set the attribute on the console first. // If that fails, set it on the object. if (!cConsole->SetAttributeValue(right_switch, arg_right)) { if (!cObj->SetAttributeValue(right_switch, arg_right)) notify(player, "Attribute - failed."); else if (!*arg_right) notify(player, tprintf("%s Attribute - cleared.", cObj->GetName())); else notify(player, tprintf("%s Attribute - set.", cObj->GetName())); } else notify(player, "Console Attribute - set."); } else if (hsInterface.HasFlag(dbConsole, TYPE_ROOM, ROOM_HSPACE_UNIVERSE)) { // Set a universe attribute CHSUniverse *uDest; uDest = uaUniverses.FindUniverse(dbConsole); if (!uDest) { notify(player, "That room has a universe flag, but it's not a valid universe."); return; } if (!uDest->SetAttributeValue(right_switch, arg_right)) notify(player, "Attribute - failed."); else notify(player, "Attribute - set."); } else if (hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_TERRITORY)) { // Find the territory. CHSTerritory *territory; territory = taTerritories.FindTerritory(dbConsole); if (!territory) { notify(player, "That object has a territory flag, but it's not a valid territory."); return; } if (!territory->SetAttributeValue(right_switch, arg_right)) notify(player, "Attribute - failed."); else notify(player, "Attribute - set."); } else notify(player, "That thing does not appear to be an HSpace object."); } // Adds a room to a ship object HSPACE_COMMAND_HDR(hscAddSroom) { dbref dbConsole; dbref dbRoom; CHSShip *cShip; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; dbRoom = hsInterface.NoisyMatchRoom(player, arg_right); if (dbRoom == NOTHING) return; if (Typeof(dbRoom) != TYPE_ROOM) { notify(player, "You may only register rooms with this command."); return; } cShip = dbHSDB.FindShip(dbConsole); if (!cShip) { notify(player, "That is not a HSpace ship."); return; } if (cShip->AddSroom(dbRoom)) notify(player, "Room - added."); else notify(player, "Room - failed."); } // Deletes an sroom from a ship object HSPACE_COMMAND_HDR(hscDelSroom) { dbref dbConsole; dbref dbRoom; CHSShip *cShip; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; if (!arg_right || !*arg_right) { notify(player, "No room number specified."); return; } dbRoom = strtodbref(arg_right); cShip = dbHSDB.FindShip(dbConsole); if (!cShip) { notify(player, "That is not a HSpace ship."); return; } if (cShip->DeleteSroom(dbRoom)) notify(player, "Room - deleted."); else notify(player, "Room - not found."); } // Called to allow a player to man a console. HSPACE_COMMAND_HDR(hscManConsole) { dbref dbConsole; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; if (!hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_CONSOLE)) { notify(player, "That thing is not an HSpace console."); return; } // Can puppets man the console? if (Typeof(player) != TYPE_PLAYER && HSCONF.forbid_puppets) { notify(player, "Only players may man this console."); return; } if (hsInterface.GetLock(dbConsole, LOCK_USE) == player) { notify(player, "You are already manning that console."); return; } #ifdef ONLINE_REG // Unregistered players can't use the system. if (hsInterface.HasFlag(player, TYPE_PLAYER, PLAYER_UNREG)) { notify(player, "Unregistered players are not allowed to use the space system."); return; } #endif // Set the lock. hsInterface.SetLock(dbConsole, player, LOCK_USE); // Give some messages notify(player, tprintf("You man the %s.", Name(dbConsole))); notify_except(db[Location(dbConsole)].contents, player, player, tprintf("%s mans the %s.", Name(player), Name(dbConsole)), 0); } // Called to allow a player to unman a console. HSPACE_COMMAND_HDR(hscUnmanConsole) { dbref dbConsole; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; if (!hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_CONSOLE)) { notify(player, "You are not manning that object."); return; } if (hsInterface.GetLock(dbConsole, LOCK_USE) != player) { notify(player, "You are not manning that console."); return; } // Set the lock, give some messages. hsInterface.SetLock(dbConsole, dbConsole, LOCK_USE); notify(player, tprintf("You unman the %s.", Name(dbConsole))); notify_except(db[Location(dbConsole)].contents, player, player, tprintf("%s unmans the %s.", Name(player), Name(dbConsole)), 0); } // Called to add a given object as a new console for the // space object. HSPACE_COMMAND_HDR(hscAddConsole) { dbref dbShip; dbref dbConsole; CHSObject *cObj; dbShip = hsInterface.NoisyMatchThing(player, arg_left); if (dbShip == NOTHING) return; dbConsole = hsInterface.NoisyMatchThing(player, arg_right); if (dbConsole == NOTHING) return; cObj = dbHSDB.FindObject(dbShip); if (!cObj) { notify(player, "That thing is not an HSpace object."); return; } switch(cObj->GetType()) { case HST_SHIP: CHSShip *ptr; ptr = (CHSShip *)cObj; if (!ptr->AddConsole(dbConsole)) notify(player, "Console - failed."); else notify(player, "Console - added."); break; default: notify(player, "That HSpace object does not support that operation."); return; } } // Called to delete a given console object from a space object HSPACE_COMMAND_HDR(hscDelConsole) { dbref dbObj; dbref dbConsole; CHSObject *cObj; dbObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbObj == NOTHING) return; if (!arg_right || !*arg_right) { notify(player, "No console number specified."); return; } dbConsole = strtodbref(arg_right); cObj = dbHSDB.FindObject(dbObj); if (!cObj) { notify(player, "That is not a HSpace object."); return; } switch(cObj->GetType()) { case HST_SHIP: CHSShip *ptr; ptr = (CHSShip *)cObj; if (!ptr->RemoveConsole(dbConsole)) notify(player, "Console - not found."); else notify(player, "Console - deleted."); break; default: notify(player, "That HSpace object does not support that operation."); break; } } // Called to delete a given class from the game HSPACE_COMMAND_HDR(hscDelClass) { UINT uClass; CHSShip *cShip; CHSUniverse *uSource; int idx, jdx; if (!arg_left || !*arg_left) { notify(player, "Must specify a class number to delete."); return; } uClass = atoi(arg_left); // Check to see if any ships remain with that class. // If so, don't allow it to be deleted. for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { uSource = uaUniverses.GetUniverse(idx); if (!uSource) continue; // Search ships in the universe for (jdx = 0; jdx < HS_MAX_OBJECTS; jdx++) { cShip = (CHSShip *)uSource->GetUnivObject(jdx, HST_SHIP); if (!cShip) continue; if (cShip->ClassNum() == uClass) { notify(player, "You may not delete a class still in use."); return; } } } // If we're here, then no ships of the class were found. // Delete it! if (!caClasses.RemoveClass(uClass)) notify(player, "Class - failed."); else notify(player, "Class - deleted."); } // Called to add a new space object to the game. HSPACE_COMMAND_HDR(hscAddObject) { CHSObject *cObj; dbref dbObj; CHSUniverse *unDest; char strName[32]; int idx; // Find the game object representing the new celestial dbObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbObj == NOTHING) return; if (Typeof(dbObj) != TYPE_THING) { notify(player, tprintf("%s(#%d) is not of type THING.", Name(dbObj), dbObj)); return; } // See if it's already an object. if (dbHSDB.FindObject(dbObj)) { notify(player, "That object is already an HSpace object."); return; } // Check the type to turn it into if (!arg_right || !*arg_right) { notify(player, "You must specify a type of object."); return; } cObj = NULL; // Figure out the type of object, allocate the // object, etc. switch(atoi(arg_right)) { case HST_SHIP: notify(player, "You must use @space/activate for that type."); return; case HST_PLANET: strcpy(strName, "planet"); cObj = new CHSPlanet; break; case HST_NOTYPE: // Generic object cObj = new CHSObject; strcpy(strName, "space object"); break; default: notify(player, "Invalid type of object specified."); return; } // Add the object to the first available universe unDest = NULL; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (unDest = uaUniverses.GetUniverse(idx)) break; } if (!unDest) { notify(player, "No valid universe for this object exists."); delete cObj; return; } if (!unDest->AddObject(cObj)) { notify(player, "Object could not be added to default universe."); delete cObj; return; } // Set the UID of the default universe for this object. cObj->SetUID(unDest->GetID()); cObj->SetDbref(dbObj); // Set the flag hsInterface.SetFlag(dbObj, THING_HSPACE_OBJECT); notify(player, tprintf("%s (#%d) - is now a new %s in universe 0.", Name(dbObj), dbObj, strName)); } // Called to completely repair a ship. HSPACE_COMMAND_HDR(hscRepairShip) { dbref dbConsole; CHSShip *cShip; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; cShip = dbHSDB.FindShip(dbConsole); if (!cShip) { notify(player, "That is not a HSpace ship."); return; } // Tell the ship to repair! cShip->TotalRepair(); notify(player, "Ship - repaired."); } // Allows an attribute for a particular engineering // system to be changed. HSPACE_COMMAND_HDR(hscSetSystemAttr) { CHSObject *cObj; char *sptr, *dptr; char tbuf[256]; char sysname[64]; char attrname[64]; dbref dbObj; // Parse out the parts of the command. // Command format is: // // @space/sysset obj:system/attr=value if (!arg_left || !arg_left) { notify(player, "You must specify an object and system name."); return; } // Pull out the object of interest dptr = tbuf; for (sptr = arg_left; *sptr; sptr++) { if (*sptr == ':') { *dptr = '\0'; break; } else *dptr++ = *sptr; } *dptr = '\0'; dbObj = hsInterface.NoisyMatchThing(player, tbuf); if (dbObj == NOTHING) return; // Pull out the system name dptr = sysname; if (!*sptr) { notify(player, "Invalid system specified."); return; } sptr++; while(*sptr) { if ((*sptr == '/') || ((dptr - sysname) > 63)) // Don't allow overflow { break; } else *dptr++ = *sptr++; } *dptr = '\0'; // Now pull out the attribute name if (!*sptr || (*sptr != '/')) { notify(player, "Invalid command format given."); return; } sptr++; dptr = attrname; while(*sptr) { if ((dptr - attrname) > 63) break; else *dptr++ = *sptr++; } *dptr = '\0'; // If we're setting the attribute based on a console // object, try to find the CHSObject for that console. if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) cObj = dbHSDB.FindObjectByConsole(dbObj); else cObj = dbHSDB.FindObject(dbObj); if (!cObj) { notify(player, "That thing does not appear to be an HSpace object."); return; } // Currently only support ships if (cObj->GetType() != HST_SHIP) { notify(player, "That HSpace object does not currently support that operation."); return; } // Try to set the attribute CHSShip *cShip; cShip = (CHSShip *)cObj; if (!cShip->SetSystemAttribute(sysname, attrname, arg_right)) notify(player, "SystemAttribute - failed."); else notify(player, "SystemAttribute - set."); } // Allows a player to disembark from a ship. HSPACE_COMMAND_HDR(hscDisembark) { dbref dbRoom; dbref dbShip; CHSShip *cShip; int id; // Grab the location of the player. dbRoom = Location(player); // See if the room has a SHIP attribute on it. if (!hsInterface.AtrGet(dbRoom, "SHIP")) { notify(player, "You cannot disembark from here."); return; } // Convert the dbref string to a ship dbref dbShip = strtodbref(hsInterface.m_buffer); // Find the ship. cShip = dbHSDB.FindShip(dbShip); if (!cShip) { notify(player, "This room is setup as a disembarking location, but its SHIP attribute does not reference an actual ship."); return; } // The player can optionally supply and ID for disembarking // through a specific board link. if (arg_left && *arg_left) id = atoi(arg_left); else id = NOTHING; cShip->DisembarkPlayer(player, id); } // Called to allow a player board a ship. HSPACE_COMMAND_HDR(hscBoardShip) { dbref dbShipObj; dbref dbBay; CHSShip *cShip; char *ptr; dbShipObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbShipObj == NOTHING) return; // Check to be sure it's a ship object if (!hsInterface.HasFlag(dbShipObj, TYPE_THING, THING_HSPACE_OBJECT)) { notify(player, "That thing is not a space vessel."); return; } // Find the CHSShip object based on the ship dbref cShip = dbHSDB.FindShip(dbShipObj); if (!cShip) { notify(player, "That thing seems to be a space vessel, but I couldn't find the ship it belongs to."); return; } // Check to see if the ship object has a boarding loc if (!hsInterface.AtrGet(dbShipObj, "BAY")) { notify(player, "That thing has no BAY attribute to indicate where to put you."); return; } dbBay = strtodbref(hsInterface.m_buffer); // Check boarding code needs ptr = cShip->GetBoardingCode(); if (ptr) { if (!arg_right) { notify(player, "You must specify a boarding code for this vessel."); return; } if (strcmp(arg_right, ptr)) { notify(player, "Invalid boarding code -- permission denied."); return; } } // At this point all is ok. // Tell the player about boarding. notify(player, tprintf("You board the %s.", Name(dbShipObj))); // Tell the players inside that the player is boarding. hsInterface.NotifyContents(dbBay, tprintf("%s boards the ship from the outside.", Name(player))); dbref dbPrevLoc = Location(player); // Move the player move_object(player, dbBay); // Tell the players in the previous location that // the player boarded. hsInterface.NotifyContents(dbPrevLoc, tprintf("%s boards the %s.", Name(player), Name(dbShipObj))); // Set the player's HSPACE_LOCATION attr. hsInterface.AtrAdd(player, "HSPACE_LOCATION", tprintf("#%d", dbShipObj), GOD, AF_MDARK | AF_WIZARD); } // Called to allow an administrator to add a weapon to a console. HSPACE_COMMAND_HDR(hscAddWeapon) { CHSConsole *cConsole; dbref dbConsole; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; // Check to be sure it's a ship object if (!hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_CONSOLE)) { notify(player, "That thing is not a HSpace console."); return; } // Find the CHSConsole object based on the console dbref cConsole = dbHSDB.FindConsole(dbConsole); if (!cConsole) { notify(player, "That thing has a console flag, but it's not a console."); return; } // Proper command usage if (!arg_right || !*arg_right) { notify(player, "You must specify the ID of a weapon type to add."); return; } cConsole->AddWeapon(player, atoi(arg_right)); } // Called to allow an administrator to delete a weapon // from a console. HSPACE_COMMAND_HDR(hscDelWeapon) { CHSConsole *cConsole; dbref dbConsole; dbConsole = hsInterface.NoisyMatchThing(player, arg_left); if (dbConsole == NOTHING) return; // Check to be sure it's a console object if (!hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_CONSOLE)) { notify(player, "That thing is not a HSpace console."); return; } // Find the CHSConsole object based on the console dbref cConsole = dbHSDB.FindConsole(dbConsole); if (!cConsole) { notify(player, "That thing has a console flag, but it's not a console."); return; } // Proper command usage if (!arg_right || !*arg_right) { notify(player, "You must specify the ID of a weapon type to add."); return; } cConsole->DeleteWeapon(player, atoi(arg_right)); } // Called to allow an administrator set the // number of a specific type of munition on a ship. HSPACE_COMMAND_HDR(hscSetMissile) { CHSShip *cShip; dbref dbConsole; char strObj[64]; char strType[8]; char *sptr, *dptr; // Command usage check. if (!arg_left || !*arg_left || !arg_right || !*arg_right) { notify(player, "Invalid command usage."); return; } // Pull out the object dptr = strObj; for (sptr = arg_left; *sptr; sptr++) { if (*sptr == '/' || ((dptr - strObj) > 63)) break; else *dptr++ = *sptr; } *dptr = '\0'; // Pull out the weapon id if (!*sptr) { notify(player, "Must specify a weapon type."); return; } sptr++; dptr = strType; while(*sptr) { if ((dptr - strType) > 7) break; else *dptr++ = *sptr++; } *dptr = '\0'; dbConsole = hsInterface.NoisyMatchThing(player, strObj); if (dbConsole == NOTHING) return; // Is the target object a console? If so, find // the ship through the console. if (hsInterface.HasFlag(dbConsole, TYPE_THING, THING_HSPACE_CONSOLE)) { CHSObject *cObj; cObj = dbHSDB.FindObjectByConsole(dbConsole); if (cObj && cObj->GetType() != HST_SHIP) { notify(player, "You can only do that for ships."); return; } cShip = (CHSShip *) cObj; } else cShip = dbHSDB.FindShip(dbConsole); if (!cShip) { notify(player, "That is not an HSpace ship."); return; } cShip->SetNumMissiles(player, atoi(strType), atoi(arg_right)); } // Adds a new class with the specified name to the game HSPACE_COMMAND_HDR(hscNewClass) { HSSHIPCLASS *pClass; // Must specify a name if (!arg_left || !*arg_left) { notify(player, "Must specify a name for the class."); return; } // Name limits if (strlen(arg_left) > (SHIP_CLASS_NAME_LEN - 1)) { notify(player, tprintf("Name length may not exceed %d characters.", SHIP_CLASS_NAME_LEN - 1)); return; } // Grab a new class. pClass = caClasses.NewClass(); if (!pClass) { notify(player, "Failed to allocate a new slot for this class. Probably too many classes already."); return; } // Zero out the class memset(pClass, 0, sizeof(HSSHIPCLASS)); // Set size to default of 1 pClass->m_size = 1; // Set the name strcpy(pClass->m_name, arg_left); notify(player, tprintf("Ship class \"%s\" - added.", arg_left)); } // Prints out information about a given class HSPACE_COMMAND_HDR(hscDumpClassInfo) { HSSHIPCLASS *pClass; int iClass; // Find the class based on the number iClass = atoi(arg_left); pClass = caClasses.GetClass(iClass); if (!pClass) { notify(player, "Ship class non-existent."); return; } // Print out the info notify(player, tprintf("Ship Class: %d %s", iClass, pClass->m_name)); notify(player, "------------------------------------------------------------"); notify(player, tprintf("Ship Size : %-3d Cargo Size: %d", pClass->m_size, pClass->m_cargo_size)); notify(player, tprintf("Ship Crews: %-3d Max Hull : %d", pClass->m_ncrews, pClass->m_maxhull)); notify(player, tprintf("Can Drop : %-3s", pClass->m_can_drop ? "YES" : "NO")); // print out systems info notify(player, "\n- Engineering Systems -"); CHSEngSystem *cSys, *cNext; cSys = pClass->m_systems.GetHead(); while(cSys) { cNext = cSys->GetNext(); // Print out two per line or just one? if (cNext) notify(player, tprintf("*%-30s*%s", cSys->GetName(), cNext->GetName())); else notify(player, tprintf("*%s", cSys->GetName())); if (!cNext) break; else cSys = cNext->GetNext(); } } HSPACE_COMMAND_HDR(hscAddSysClass) { int iClass; HSSHIPCLASS *pClass; // Find the class iClass = atoi(arg_left); pClass = caClasses.GetClass(iClass); if (!pClass) { notify(player, "Ship class non-existent."); return; } // Find the system based on the name HSS_TYPE type; if (!arg_right || !*arg_right) { notify(player, "Must specify a system name to add."); return; } type = hsGetEngSystemType(arg_right); if (type == HSS_NOTYPE) { notify(player, "Invalid system name specified."); return; } // Try to find the system already on the class CHSEngSystem *cSys; cSys = pClass->m_systems.GetSystem(type); if (cSys) { notify(player, "That system already exists for that class."); return; } // Add the system cSys = pClass->m_systems.NewSystem(type); if (!cSys) { notify(player, "Failed to add the system to the specified class."); return; } pClass->m_systems.AddSystem(cSys); notify(player, tprintf("%s system added to class %d.", cSys->GetName(), iClass)); } // Prints systems information for a given system on a given class. HSPACE_COMMAND_HDR(hscSysInfoClass) { int iClass; HSSHIPCLASS *pClass; iClass = atoi(arg_left); if (!arg_right || !*arg_right) { notify(player, "Must specify a system name."); return; } // Find the class pClass = caClasses.GetClass(iClass); if (!pClass) { notify(player, "Ship class non-existent."); return; } // Find the system type based on the name HSS_TYPE type; type = hsGetEngSystemType(arg_right); if (type == HSS_NOTYPE) { notify(player, "Invalid system name specified."); return; } CHSEngSystem *cSys; // Grab the system from the class cSys = pClass->m_systems.GetSystem(type); if (!cSys) { notify(player, "That system does not exist for that class."); return; } // Print the info notify(player, "----------------------------------------"); cSys->GiveSystemInfo(player); notify(player, "----------------------------------------"); } // Allows an attribute for a particular engineering // system to be changed on a given ship class. HSPACE_COMMAND_HDR(hscSetSystemAttrClass) { HSSHIPCLASS *pClass; char *sptr, *dptr; char tbuf[256]; char sysname[64]; char attrname[64]; int iClass; // Parse out the parts of the command. // Command format is: // // @space/syssetclass class#:system/attr=value if (!arg_left || !arg_left) { notify(player, "You must specify an class number and system name."); return; } // Pull out the class of interest dptr = tbuf; for (sptr = arg_left; *sptr; sptr++) { if (*sptr == ':') { *dptr = '\0'; break; } else *dptr++ = *sptr; } *dptr = '\0'; iClass = atoi(tbuf); pClass = caClasses.GetClass(iClass); if (!pClass) { notify(player, "Ship class non-existent."); return; } // Pull out the system name dptr = sysname; if (!*sptr) { notify(player, "Invalid system specified."); return; } sptr++; while(*sptr) { if ((*sptr == '/') || ((dptr - sysname) > 63)) // Don't allow overflow { break; } else *dptr++ = *sptr++; } *dptr = '\0'; // Now pull out the attribute name if (!*sptr || (*sptr != '/')) { notify(player, "Invalid command format given."); return; } sptr++; dptr = attrname; while(*sptr) { if ((dptr - attrname) > 63) break; else *dptr++ = *sptr++; } *dptr = '\0'; // Find the system type HSS_TYPE type; type = hsGetEngSystemType(sysname); if (type == HSS_NOTYPE) { notify(player, "Invalid system name specified."); return; } // Find the system on the class CHSEngSystem *cSys; cSys = pClass->m_systems.GetSystem(type); if (!cSys) { notify(player, "That system does not exist on that class."); return; } // Try to set the attribute if (!cSys->SetAttributeValue(attrname, arg_right)) notify(player, "SystemAttribute - failed."); else notify(player, "SystemAttribute - set."); } // Sets an attribute for a specified class. HSPACE_COMMAND_HDR(hscSetAttrClass) { int iClass; HSSHIPCLASS *pClass; char *sptr, *dptr; char tbuf[64]; // Command format is: // // @space/setclass #/attr=value // if (!arg_left || !*arg_left) { notify(player, "You must specify a class number and attribute name."); return; } dptr = tbuf; for (sptr = arg_left; *sptr; sptr++) { if ((dptr - tbuf) > 63) break; if (*sptr == '/') break; *dptr++ = *sptr; } *dptr = '\0'; iClass = atoi(tbuf); // Find the class pClass = caClasses.GetClass(iClass); if (!pClass) { notify(player, "Ship class non-existent."); return; } // Pull out the attr name char attrname[64]; if (!*sptr) { notify(player, "You must specify an attribute name."); return; } sptr++; dptr = attrname; while(*sptr) { if ((dptr - attrname) > 63) break; *dptr++ = *sptr++; } *dptr = '\0'; // Match the attribute name int len; int iVal; len = strlen(attrname); if (!strncasecmp(attrname, "NAME", len)) { if (strlen(arg_right) > (SHIP_CLASS_NAME_LEN -1)) { notify(player, tprintf("Class name length may not exceed %d characters.", SHIP_CLASS_NAME_LEN - 1)); return; } strcpy(pClass->m_name, arg_right); } else if (!strncasecmp(attrname, "SIZE", len)) { iVal = atoi(arg_right); if (iVal < 1) { notify(player, "Sizes must be greater than 0."); return; } pClass->m_size = iVal; } else if (!strncasecmp(attrname, "CREWS", len)) { iVal = atoi(arg_right); if (iVal < 0) { notify(player, "Crews must be >= 0."); return; } pClass->m_ncrews = iVal; } else if (!strncasecmp(attrname, "MAXHULL", len)) { pClass->m_maxhull = atoi(arg_right); } else if (!strncasecmp(attrname, "CAN DROP", len)) { pClass->m_can_drop = atoi(arg_right); } else if (!strncasecmp(attrname, "CARGO", len)) { pClass->m_cargo_size = atoi(arg_right); } else { notify(player, "Invalid attribute specified."); return; } notify(player, "Class attribute - set."); } // Allows an administrator to list information contained // within a given database (e.g. weapons). HSPACE_COMMAND_HDR(hscListDatabase) { // Command usage? if (!arg_left || !*arg_left) { notify(player, "You must specify a given database to list."); return; } // Match the database name int len; char *ptr, *dptr; char strName[32]; dptr = strName; for (ptr = arg_left; *ptr; ptr++) { if ((dptr - strName) > 31) break; if (*ptr == '/') break; *dptr++ = *ptr; } *dptr = '\0'; len = strlen(strName); if (!strncasecmp(strName, "objects", len)) { // Command usage for this is: // // @space/list objects/uid=type HS_TYPE type; if (!arg_right || !*arg_right) type = HST_NOTYPE; else type = (HS_TYPE)atoi(arg_right); // Pull out the universe id char *dptr; for (dptr = arg_left; *dptr; dptr++) { if (*dptr == '/') break; } if (*dptr != '/') { notify(player, "You must specify a valid universe ID."); return; } dptr++; int uid; uid = atoi(dptr); // If uid is < 0, list all universes if (uid < 0) { // Print the header notify(player, "[Dbref#] Name X Y Z UID Active"); CHSUniverse *uSource; int idx; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { uSource = uaUniverses.GetUniverse(idx); if (!uSource) continue; int jdx; CHSObject *cObj; for (jdx = 0; jdx < HS_MAX_OBJECTS; jdx++) { cObj = uSource->GetUnivObject(jdx); if (!cObj) continue; if (type != HST_NOTYPE && cObj->GetType() != type) continue; // Print object info notify(player, tprintf( "[%6d] %-24s%-9.0f%-9.0f%-9.0f%-5d %s", cObj->GetDbref(), cObj->GetName(), cObj->GetX(), cObj->GetY(), cObj->GetZ(), cObj->GetUID(), cObj->IsActive() ? "YES" : "NO")); } } } else { // List just one universe // Print the header notify(player, "[Dbref#] Name X Y Z UID Active"); CHSUniverse *uSource; uSource = uaUniverses.FindUniverse(uid); if (!uSource) { notify(player, "Invalid universe ID specified."); return; } int jdx; CHSObject *cObj; for (jdx = 0; jdx < HS_MAX_OBJECTS; jdx++) { cObj = uSource->GetUnivObject(jdx); if (!cObj) continue; if (type != HST_NOTYPE && cObj->GetType() != type) continue; // Print object info notify(player, tprintf( "[%6d] %-24s%-9.0f%-9.0f%-9.0f%-5d %s", cObj->GetDbref(), cObj->GetName(), cObj->GetX(), cObj->GetY(), cObj->GetZ(), cObj->GetUID(), cObj->IsActive() ? "YES" : "NO")); } } } else if (!strncasecmp(strName, "weapons", len)) { waWeapons.PrintInfo(player); } else if (!strncasecmp(strName, "universes", len)) { uaUniverses.PrintInfo(player); } else if (!strncasecmp(strName, "classes", len)) { caClasses.PrintInfo(player); } else if (!strncasecmp(strName, "territories", len)) { taTerritories.PrintInfo(player); } else if (!strncasecmp(strName, "destroyed", len)) { // Print the header notify(player, "[Dbref#] Name X Y Z UID"); CHSUniverse *uSource; int idx; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { uSource = uaUniverses.GetUniverse(idx); if (!uSource) continue; int jdx; CHSObject *cObj; for (jdx = 0; jdx < HS_MAX_OBJECTS; jdx++) { cObj = uSource->GetUnivObject(jdx); if (!cObj) continue; if (cObj->GetType() != HST_SHIP) continue; CHSShip *cShip; cShip = (CHSShip *)cObj; if (!cShip->IsDestroyed()) continue; // Print object info notify(player, tprintf( "[%6d] %-24s%-9.0f%-9.0f%-9.0f%d", cObj->GetDbref(), cObj->GetName(), cObj->GetX(), cObj->GetY(), cObj->GetZ(), cObj->GetUID())); } } } else notify(player, "Must specify one of: objects, weapons, universes, classes, or destroyed."); } // Prints systems information for a given system on a given object. HSPACE_COMMAND_HDR(hscSysInfo) { CHSObject *cObj; dbref dbObj; // Find the object dbObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbObj == NOTHING) return; if (Typeof(dbObj) != TYPE_THING) { notify(player, tprintf("%s(#%d) is not of type THING.", Name(dbObj), dbObj)); return; } // See if it's a console. If so, find the ship based on the console. if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) { cObj = dbHSDB.FindObjectByConsole(dbObj); } else { cObj = dbHSDB.FindObject(dbObj); } // See if it's a space object. if (!cObj) { notify(player, "That is either not a space object, or it has no HSDB_TYPE attribute."); return; } // Find the system type based on the name HSS_TYPE type; type = hsGetEngSystemType(arg_right); if (type == HSS_NOTYPE) { notify(player, "Invalid system name specified."); return; } CHSEngSystem *cSys; // Grab the system from the object cSys = cObj->GetEngSystem(type); if (!cSys) { notify(player, "That system does not exist for that object."); return; } // Print the info notify(player, "----------------------------------------"); cSys->GiveSystemInfo(player); notify(player, "----------------------------------------"); } // Deactivates any HSpace object. HSPACE_COMMAND_HDR(hscCloneObject) { CHSObject *cObj; dbref dbObj; // Find the object dbObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbObj == NOTHING) return; // See if it's a space object. if (!(cObj = dbHSDB.FindObject(dbObj))) { notify(player, "That is either not a space object, or it has no HSDB_TYPE attribute."); return; } // Only clone ships right now. if (cObj->GetType() != HST_SHIP) { notify(player, "You may only clone ships at this time."); return; } CHSShip *cShip; cShip = (CHSShip *)cObj; // Clone it! dbref dbShipObj = cShip->Clone(); if (dbShipObj == NOTHING) notify(player, "Clone ship - failed."); else notify(player, tprintf("Clone ship - cloned #%d", dbShipObj)); } HSPACE_COMMAND_HDR(hscAddTerritory) { dbref dbObj; // Find the object dbObj = hsInterface.NoisyMatchThing(player, arg_left); if (dbObj == NOTHING) return; // Check to see if it's already a territory. CHSTerritory *territory; territory = taTerritories.FindTerritory(dbObj); if (territory) { notify(player, "That object is already a space territory."); return; } // Proper command usage. if (!arg_right || !*arg_right) { notify(player, "Must specify type of territory to add."); return; } // Grab a new territory territory = taTerritories.NewTerritory(dbObj, (TERRTYPE)atoi(arg_right)); if (!territory) notify(player, "Territory - failed."); else notify(player, tprintf("%s (#%d) added as a new territory.", Name(dbObj), dbObj)); } HSPACE_COMMAND_HDR(hscDelTerritory) { dbref dbObj; dbObj = strtodbref(arg_left); // Check to see if it's a territory. CHSTerritory *territory; territory = taTerritories.FindTerritory(dbObj); if (!territory) { notify(player, "No such territory with that dbref."); return; } if (!taTerritories.RemoveTerritory(dbObj)) notify(player, "Delete territory - failed."); else notify(player, "Delete territory - deleted."); } // Allows an admin to add a new weapon to the weapondb HSPACE_COMMAND_HDR(hscNewWeapon) { CHSDBWeapon *cWeap; // Command usage. if (!arg_left || !*arg_left) { notify(player, "Must specify the type of weapon to create."); return; } if (!arg_right || !*arg_right) { notify(player, "Must specify the name of the new weapon."); return; } // Try to get a new weapon. cWeap = waWeapons.NewWeapon(atoi(arg_left)); if (!cWeap) { notify(player, "Failed to create new weapon by specified type."); return; } notify(player, "Weapon - created."); // Set the name of the weapon. if (!cWeap->SetAttributeValue("NAME", arg_right)) notify(player, "WARNING: Failed to set weapon name as specified."); } // Sets an attribute for a specified weapon. HSPACE_COMMAND_HDR(hscSetAttrWeapon) { int iWeapon; char *ptr; char name[64]; // Command format is: // // @space/setweapon #/attr=value // if (!arg_left || !*arg_left) { notify(player, "You must specify a weapon number and attribute name."); return; } // Pull out the weapon id and attribute name. ptr = strchr(arg_left, '/'); if (!ptr) { notify(player, "Invalid weapon/attribute combination."); return; } *ptr = '\0'; iWeapon = atoi(arg_left); ptr++; strncpy(name, ptr, 62); name[63] = '\0'; // See if the weapon exists. CHSDBWeapon *cWeap; cWeap = waWeapons.GetWeapon(iWeapon, HSW_NOTYPE); if (!cWeap) { notify(player, "Invalid weapon ID specified."); return; } // Tell the weapon to set the attribute value. if (!cWeap->SetAttributeValue(name, arg_right)) notify(player, "Attribute - failed."); else notify(player, "Attribute - set."); } src/hspace/hscmds.h 100644 767 767 2003 7141305141 12434 0 ustar mux mux #ifndef __HSCMDS_INCLUDED__ #define __HSCMDS_INCLUDED__ // A handy prototyper #define HSPACE_COMMAND_PROTO(x) void x(int, char *, char *); #define HSPACE_COMMAND_HDR(x) void x(int player, char *arg_left, char *arg_right) typedef void (* hs_command)(int, char *, char *); #ifdef MUX extern hs_command LookupCommand(int command, int subcommand); extern char* LookupCommandName(int command); extern char* LookupSubCommandName(int command, int subcommand); #endif #ifdef PENNMUSH // Command permissions #define HCP_WIZARD 0x1 // Only wizards can use the command #define HCP_ANY 0x2 // Anyone can use the command #define HCP_GOD 0x4 // Only God can use the command // A command entry in the array struct HSPACE_COMMAND { char *key; hs_command func; int perms; }; extern HSPACE_COMMAND hsSpaceCommandArray[]; extern HSPACE_COMMAND hsNavCommandArray[]; extern HSPACE_COMMAND hsEngCommandArray[]; extern HSPACE_COMMAND hsConCommandArray[]; extern HSPACE_COMMAND *hsFindCommand(char *, HSPACE_COMMAND *); #endif #endif src/hspace/hscomm.cpp 100644 767 767 10347 7141305141 13026 0 ustar mux mux #include "hscomm.h" #include "hsuniverse.h" #include "hspace.h" #include "hsconf.h" #include "hsinterface.h" #include "hsutils.h" #include <stdlib.h> #include <string.h> CHSCommRelay cmRelay; // Our global relay object. // Default constructor CHSCommRelay::CHSCommRelay(void) { } // Relays a comm message to all commlinks in the game. void CHSCommRelay::RelayCommlinks(HSCOMM *commdata) { if (!HSCONF.use_comm_objects) return; int idx; int uid; int tX, tY, tZ; char *s; char strFrq[16]; char strDbref[16]; // Setup some strings to pass into the COMM_HANDLER. sprintf(strDbref, "#%d", commdata->dbSource); sprintf(strFrq, "%.2f", commdata->frq); for (idx = 0; idx < hsInterface.MaxObjects(); idx++) { if (!hsInterface.HasFlag(idx, TYPE_THING, THING_HSPACE_COMM) || hsInterface.HasFlag(idx, TYPE_THING, THING_HSPACE_CONSOLE)) continue; // Check attributes if (!hsInterface.AtrGet(idx, "UID")) continue; uid = atoi(hsInterface.m_buffer); // Get coordinates if (!hsInterface.AtrGet(idx, "X")) continue; s = hsInterface.EvalExpression(hsInterface.m_buffer, idx, idx, idx, NULL, 0); tX = atoi(s); if (!hsInterface.AtrGet(idx, "Y")) continue; s = hsInterface.EvalExpression(hsInterface.m_buffer, idx, idx, idx, NULL, 0); tY = atoi(s); if (!hsInterface.AtrGet(idx, "Z")) continue; s = hsInterface.EvalExpression(hsInterface.m_buffer, idx, idx, idx, NULL, 0); tZ = atoi(s); // Target within range? double dDistance; dDistance = Dist3D(commdata->sX, commdata->sY, commdata->sZ, tX, tY, tZ); if (dDistance > commdata->dMaxDist) continue; if (!OnFrq(idx, commdata->frq)) continue; // Call the object's handler function. if (!hsInterface.AtrGet(idx, "COMM_HANDLER")) continue; // In normal HSpace we set values to a structure // wenv. In MUX2 we need to create a char** holding args // and pass this on to TinyExec. char* pArgs[3] = { commdata->msg, strFrq, strDbref }; hsInterface.EvalExpression(hsInterface.m_buffer, idx, idx, idx, pArgs, 3); } } // Relays a message throughout the game givin the input data. BOOL CHSCommRelay::RelayMessage(HSCOMM *commdata) { // Relay to commlinks RelayCommlinks(commdata); // Find the destination universe for the message CHSUniverse *uDest; uDest = uaUniverses.FindUniverse(commdata->duid); if (!uDest) return FALSE; // Find all objects in the destination universe that // are within range, and relay the message to them. CHSObject *cObj; int idx; double dX, dY, dZ; // Destination object coords double dDist; // Distance between coords double dMaxDist; // Squared max distance to target objs dMaxDist = commdata->dMaxDist * commdata->dMaxDist; for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { cObj = uDest->GetUnivObject(idx); if (!cObj) continue; dX = cObj->GetX(); dY = cObj->GetY(); dZ = cObj->GetZ(); // Calculate squared distance between objects. Don't // bother doing sqrt, cause it's slow as a snail! dDist = ((commdata->sX - dX) * (commdata->sX - dX) + (commdata->sY - dY) * (commdata->sY - dY) + (commdata->sZ - dZ) * (commdata->sZ - dZ)); if (dDist > dMaxDist) continue; // Give the object the message. cObj->HandleMessage(commdata->msg, MSG_COMMUNICATION, (long *)commdata); } return TRUE; } // Indicates whether the commlink object is on a given frequency. BOOL CHSCommRelay::OnFrq(int obj, double frq) { // Check for the COMM_FRQS attr. if (!hsInterface.AtrGet(obj, "COMM_FRQS")) return FALSE; // Separate the string into blocks of spaces char *ptr; char *bptr; // Points to the first char in the frq string double cfrq; ptr = strchr(hsInterface.m_buffer, ' '); bptr = hsInterface.m_buffer; while(ptr) { *ptr = '\0'; cfrq = atof(bptr); // Do we have a match, Johnny? if (cfrq == frq) return TRUE; // Find the next frq in the string. bptr = ptr+1; ptr = strchr(bptr, ' '); } // Last frq in the string. cfrq = atof(bptr); if (cfrq == frq) return TRUE; // No match! return FALSE; } src/hspace/hscomm.h 100644 767 767 1522 7141305141 12446 0 ustar mux mux #ifndef __HSCOMM_INCLUDED__ #define __HSCOMM_INCLUDED__ #include "hsobjects.h" // The structure that contains communications information typedef struct { CHSObject *cObj; // Object that sent the message. dbref dbSource; // Source dbref object UINT suid; // Source uid of message UINT duid; // Destination uid of message. double frq; double sX, sY, sZ; // Source coords; double dMaxDist; // Max dist to send the message. char *msg; // Ptr to the message to send. }HSCOMM; // The class that handles all communications message relay // in HSpace. All messages are sent to this thing to be // relayed to objects in the game. class CHSCommRelay { public: CHSCommRelay(void); BOOL RelayMessage(HSCOMM *); private: BOOL OnFrq(int, double); void RelayCommlinks(HSCOMM *); }; extern CHSCommRelay cmRelay; #endif // __HSCOMM_INCLUDED__ src/hspace/hsconf.cpp 100644 767 767 15702 7141305141 13020 0 ustar mux mux #include "hscopyright.h" #include <stdlib.h> #include "hsconf.h" #include "hsutils.h" #include <string.h> CHSConf HSCONF; void HSCfInt(int *, char *); void HSCfStr(int *, char *); HCONF hspace_conflist[] = { (char *) "afterburn_engage", HSCfStr, (int *) HSCONF.afterburn_engage, (char *) "afterburn_disengage", HSCfStr, (int *) HSCONF.afterburn_disengage, (char *) "lift_off", HSCfStr, (int *) HSCONF.lift_off, (char *) "landing_msg", HSCfStr, (int *) HSCONF.landing_msg, (char *) "end_jump", HSCfStr, (int *) HSCONF.end_jump, (char *) "begin_descent", HSCfStr, (int *) HSCONF.begin_descent, (char *) "ship_jumps", HSCfStr, (int *) HSCONF.ship_jumps, (char *) "life_cut", HSCfStr, (int *) HSCONF.life_cut, (char *) "jumpers_cut", HSCfStr, (int *) HSCONF.jumpers_cut, (char *) "engines_cut", HSCfStr, (int *) HSCONF.engines_cut, (char *) "reactor_offline", HSCfStr, (int *) HSCONF.reactor_offline, (char *) "engines_offline", HSCfStr, (int *) HSCONF.engines_offline, (char *) "ship_is_jumping", HSCfStr, (int *) HSCONF.ship_is_jumping, (char *) "engines_activating", HSCfStr, (int *) HSCONF.engines_activating, (char *) "speed_increase", HSCfStr, (int *) HSCONF.speed_increase, (char *) "speed_decrease", HSCfStr, (int *) HSCONF.speed_decrease, (char *) "engine_reverse", HSCfStr, (int *) HSCONF.engine_reverse, (char *) "engine_forward", HSCfStr, (int *) HSCONF.engine_forward, (char *) "speed_halt", HSCfStr, (int *) HSCONF.speed_halt, (char *) "ship_is_docking", HSCfStr, (int *) HSCONF.ship_is_docking, (char *) "ship_is_undocking", HSCfStr, (int *) HSCONF.ship_is_undocking, (char *) "ship_is_docked", HSCfStr, (int *) HSCONF.ship_is_docked, (char *) "unit_name", HSCfStr, (int *) HSCONF.unit_name, (char *) "classdb", HSCfStr, (int *) HSCONF.classdb, (char *) "objectdb", HSCfStr, (int *) HSCONF.objectdb, (char *) "weapondb", HSCfStr, (int *) HSCONF.weapondb, (char *) "univdb", HSCfStr, (int *) HSCONF.univdb, (char *) "territorydb", HSCfStr, (int *) HSCONF.territorydb, (char *) "picture_dir", HSCfStr, (int *) HSCONF.picture_dir, (char *) "cycle_interval", HSCfInt, &HSCONF.cyc_interval, (char *) "train_interval", HSCfInt, &HSCONF.train_interval, (char *) "jump_wait", HSCfInt, &HSCONF.jump_wait, (char *) "max_ships", HSCfInt, &HSCONF.max_ships, (char *) "max_active_ships", HSCfInt, &HSCONF.max_active_ships, (char *) "max_planets", HSCfInt, &HSCONF.max_planets, (char *) "max_universes", HSCfInt, &HSCONF.max_universes, (char *) "max_strafe_dist", HSCfInt, &HSCONF.max_strafe_dist, (char *) "max_cargo_dist", HSCfInt, &HSCONF.max_cargo_dist, (char *) "max_board_dist", HSCfInt, &HSCONF.max_board_dist, (char *) "max_dock_size", HSCfInt, &HSCONF.max_dock_size, (char *) "max_land_speed", HSCfInt, &HSCONF.max_land_speed, (char *) "afterworld", HSCfInt, &HSCONF.afterworld, (char *) "autostart", HSCfInt, (int *)&HSCONF.autostart, (char *) "log_commands", HSCfInt, (int *)&HSCONF.log_commands, (char *) "notify_shipscan", HSCfInt, &HSCONF.notify_shipscan, (char *) "space_wiz", HSCfInt, &HSCONF.space_wiz, (char *) "max_dock_dist", HSCfInt, &HSCONF.max_dock_dist, (char *) "max_drop_dist", HSCfInt, &HSCONF.max_drop_dist, (char *) "allow_strafing", HSCfInt, &HSCONF.allow_strafing, (char *) "forbid_puppets", HSCfInt, &HSCONF.forbid_puppets, (char *) "decay_ships", HSCfInt, &HSCONF.decay_ships, (char *) "min_training", HSCfInt, (int *) &HSCONF.min_flight_training, (char *) "cloak_low_size", HSCfInt, &HSCONF.cloak_low_size, (char *) "cloak_opt_size", HSCfInt, &HSCONF.cloak_opt_size, (char *) "cloak_style", HSCfInt, &HSCONF.cloak_style, (char *) "fire_while_cloaked", HSCfInt, &HSCONF.fire_while_cloaked, (char *) "see_while_cloaked", HSCfInt, &HSCONF.see_while_cloaked, (char *) "use_comm_objects", HSCfInt, &HSCONF.use_comm_objects, (char *) "seconds_to_drop", HSCfInt, &HSCONF.seconds_to_drop, (char *) "use_two_fuels", HSCfInt, &HSCONF.use_two_fuels, (char *) "fuel_ratio", HSCfInt, &HSCONF.fuel_ratio, (char *) "max_sensor_range", HSCfInt, &HSCONF.max_sensor_range, (char *) "sense_hypervessels", HSCfInt, &HSCONF.sense_hypervessels, (char *) "afterburn_ratio", HSCfInt, &HSCONF.afterburn_ratio, (char *) "afterburn_fuel_ratio", HSCfInt, &HSCONF.afterburn_fuel_ratio, (char *) "jump_speed_multiplier", HSCfInt, &HSCONF.jump_speed_multiplier, NULL, NULL, NULL }; CHSConf::CHSConf(void) { } /* * Places a string from the configuration file into its storage location. */ void HSCfStr(int *des, char *value) { strcpy((char *) des, value); } /* * Places a float from the configuration file into its storage location. */ void HSCfFloat(double *des, char *value) { double fval; fval = atof(value); *des = fval; } /* * Places an int from the configuration file into its storage location. */ void HSCfInt(int *des, char *value) { int ival; ival = atoi(value); *des = ival; } /* * Takes an option string loaded from the config file and * figures out where to put it in hs_options. */ BOOL CHSConf::InputOption(char *option, char *value) { HCONF *cfptr; for (cfptr = hspace_conflist; cfptr->name; cfptr++) { if (!strcasecmp(option, cfptr->name)) { cfptr->func(cfptr->des, value); return TRUE; } } return FALSE; } /* * Opens the HSpace configuration file, loading in option strings and * sending them to hspace_input_option(). */ BOOL CHSConf::LoadConfigFile(char *lpstrPath) { FILE *fp; char tbuf[1024]; char tbuf2[256]; char option[256]; char value[1024]; char *ptr, *ptr2; hs_log((char *) "LOADING: HSpace configuration file."); /* * Open the configuration file for reading */ fp = fopen(lpstrPath, "r"); if (!fp) { hs_log((char *) "ERROR: Unable to open hspace configuration file."); return FALSE; } /* * Read the entire file in. Parse lines that have something in them * and don't begin with a '#' */ while (fgets(tbuf, 256, fp)) { /* * Truncate at the newline */ if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; /* * Strip leading spaces */ ptr = tbuf; while (*ptr == ' ') ptr++; /* * Determine if the line is valid */ if (!*ptr || *ptr == '#') continue; /* * Parse out the option and value */ ptr2 = option; for (; *ptr && *ptr != ' ' && *ptr != '='; ptr++) { *ptr2 = *ptr; ptr2++; } *ptr2 = '\0'; if (!*ptr) { sprintf(tbuf2, "ERROR: Invalid configuration at option: %s", option); hs_log(tbuf2); continue; } ptr2 = value; while(*ptr && (*ptr == ' ' || *ptr == '=')) ptr++; for (; *ptr; ptr++) { *ptr2 = *ptr; ptr2++; } *ptr2 = '\0'; if (!InputOption(option, value)) { sprintf(tbuf2, "ERROR: Invalid config option \"%s\"", option); hs_log(tbuf2); } } fclose(fp); return TRUE; } src/hspace/hsconf.h 100644 767 767 4020 7141305141 12434 0 ustar mux mux #ifndef __HSCONF_INCLUDED__ #define __HSCONF_INCLUDED__ #include "hsexterns.h" #include "hstypes.h" #define HSPACE_CONFIG_FILE "space/hspace.cnf" // A listing in the configuration array typedef struct { char *name; void (*func)(int *, char *); int *des; }HCONF; class CHSConf { public: // Methods CHSConf(void); BOOL LoadConfigFile(char *); // Attributes dbref afterworld; dbref space_wiz; BOOL autostart; BOOL log_commands; BOOL use_two_fuels; int afterburn_fuel_ratio; int sense_hypervessels; int max_sensor_range; int afterburn_ratio; int fuel_ratio; int min_flight_training; int max_universes; int cyc_interval; int train_interval; int max_ships; int max_active_ships; int max_planets; int max_land_speed; int max_dock_dist; int max_drop_dist; int max_board_dist; int max_dock_size; int max_cargo_dist; int max_strafe_dist; int jump_wait; int decay_ships; int allow_strafing; int notify_shipscan; int forbid_puppets; int use_comm_objects; int cloak_opt_size; int cloak_low_size; int cloak_style; int see_while_cloaked; int fire_while_cloaked; int jump_speed_multiplier; int seconds_to_drop; char univdb[256]; char territorydb[256]; char classdb[256]; char weapondb[256]; char objectdb[256]; char picture_dir[256]; char unit_name[32]; /* Messages */ char ship_is_jumping[256]; char engines_activating[256]; char engines_offline[256]; char life_cut[256]; char jumpers_cut[256]; char engines_cut[256]; char reactor_offline[256]; char speed_increase[256]; char speed_decrease[256]; char engine_reverse[256]; char engine_forward[256]; char speed_halt[256]; char ship_is_docking[256]; char ship_is_docked[256]; char ship_is_undocking[256]; char lift_off[256]; char begin_descent[256]; char landing_msg[256]; char end_jump[256]; char ship_jumps[256]; char afterburn_engage[256]; char afterburn_disengage[256]; protected: BOOL InputOption(char *, char *); }; extern CHSConf HSCONF; #endif src/hspace/hsconsole.cpp 100644 767 767 133573 7141305141 13564 0 ustar mux mux #include "hscopyright.h" #include "hsobjects.h" #include "hsutils.h" #include "hsinterface.h" #include "hsexterns.h" #include <stdlib.h> #include <math.h> #include <string.h> // Extern trig stuff extern double d2cos_table[]; extern double d2sin_table[]; // // CHSConsole Stuff // CHSConsole::CHSConsole(void) { m_weapon_array = NULL; m_xyheading = 0; m_zheading = 0; m_xyoffset = 0; // Front of ship by default m_zoffset = 0; m_arc = 30; // Default of 30 degree arc m_objnum = NOTHING; m_ownerObj = NULL; m_missile_bay = NULL; m_target_lock = NULL; m_can_rotate = FALSE; m_online = FALSE; m_autoload = FALSE; m_computer = NULL; m_targetting = HSS_NOTYPE; } CHSConsole::~CHSConsole(void) { // Clear attributes and flags ClearObjectAttrs(); hsInterface.UnsetFlag(m_objnum, THING_HSPACE_CONSOLE); } // Indicates if the console is powered up. If there is // no computer, the console requires no power. BOOL CHSConsole::IsOnline(void) { if (!m_computer) return TRUE; return m_online; } // Sets the computer source for the console. If no // source is set, the console requires no computer. void CHSConsole::SetComputer(CHSSysComputer *cComputer) { m_computer = cComputer; } // Saves information in the form of attributes on the // object for this console. void CHSConsole::WriteObjectAttrs(void) { int idx; char tbuf[256]; char tbuf2[32]; if (m_objnum == NOTHING) return; hsInterface.AtrAdd(m_objnum, "HSDB_XYHEADING", tprintf("%d", m_xyheading), GOD); hsInterface.AtrAdd(m_objnum, "HSDB_ZHEADING", tprintf("%d", m_zheading), GOD); hsInterface.AtrAdd(m_objnum, "HSDB_XYOFFSET", tprintf("%d", m_xyoffset), GOD); hsInterface.AtrAdd(m_objnum, "HSDB_ZOFFSET", tprintf("%d", m_zoffset), GOD); hsInterface.AtrAdd(m_objnum, "HSDB_CAN_ROTATE", tprintf("%d", m_can_rotate), GOD); // Write weapons info if (m_weapon_array) { CHSWeapon *cWeap; char strWeaponID[32]; *tbuf = '\0'; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (cWeap = m_weapon_array->GetWeapon(idx)) { if (!*tbuf) sprintf(tbuf2, "%d", cWeap->m_class); else sprintf(tbuf2, " %d", cWeap->m_class); strcat(tbuf, tbuf2); // Save the weapon status sprintf(tbuf2, "%d", cWeap->GetStatusInt()); sprintf(strWeaponID, "WEAPON_STAT_%d", idx); hsInterface.AtrAdd(m_objnum, strWeaponID, tbuf2, GOD); } } hsInterface.AtrAdd(m_objnum, "HSDB_WEAPONS", tbuf, GOD); } else hsInterface.AtrAdd(m_objnum, "HSDB_WEAPONS", NULL, GOD); } // Takes a string of space delimited weapon IDs and loads // them into the weapons array. void CHSConsole::LoadWeapons(char *strWeapons) { char tbuf[32]; int idx; int iVal; // Do we have a weapons array? if (!m_weapon_array) m_weapon_array = new CHSWeaponArray; // Extract the IDs from the list, and load // them into the array. idx = 0; extract(strWeapons, tbuf, 0, 1, ' '); while(*tbuf) { iVal = atoi(tbuf); m_weapon_array->NewWeapon(iVal); idx++; extract(strWeapons, tbuf, idx, 1, ' '); } } // Clears the attributes from the object void CHSConsole::ClearObjectAttrs(void) { if (m_objnum == NOTHING) return; // Set the attributes on the console object. hsInterface.AtrAdd(m_objnum, "HSDB_XYHEADING", NULL, GOD); hsInterface.AtrAdd(m_objnum, "HSDB_ZHEADING", NULL, GOD); hsInterface.AtrAdd(m_objnum, "HSDB_XYOFFSET", NULL, GOD); hsInterface.AtrAdd(m_objnum, "HSDB_ZOFFSET", NULL, GOD); } // Gets the owner of the console .. the dbref of the owner dbref CHSConsole::GetOwner(void) { return m_owner; } // Sets the owner of the console to a specific object in the game void CHSConsole::SetOwner(dbref obj) { m_owner = obj; // Set my owner attribute if (m_objnum != NOTHING) hsInterface.AtrAdd(m_objnum, "HSDB_OWNER", tprintf("#%d", obj), GOD); } // Loads information from a game object into the // console object in memory. BOOL CHSConsole::LoadFromObject(dbref objnum) { // Set our object number m_objnum = objnum; // Load attributes if (hsInterface.AtrGet(objnum, "HSDB_XYHEADING")) m_xyheading = atoi(hsInterface.m_buffer); if (hsInterface.AtrGet(objnum, "HSDB_ZHEADING")) m_zheading = atoi(hsInterface.m_buffer); if (hsInterface.AtrGet(objnum, "HSDB_XYOFFSET")) m_xyoffset = atoi(hsInterface.m_buffer); if (hsInterface.AtrGet(objnum, "HSDB_ZOFFSET")) m_zoffset = atoi(hsInterface.m_buffer); if (hsInterface.AtrGet(objnum, "HSDB_CAN_ROTATE")) m_can_rotate = atoi(hsInterface.m_buffer); // Any weapons to load? if (hsInterface.AtrGet(objnum, "HSDB_WEAPONS")) LoadWeapons(hsInterface.m_buffer); // Load weapon stats int idx; if (m_weapon_array) { char strWeaponID[32]; CHSWeapon *cWeap; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { cWeap = m_weapon_array->GetWeapon(idx); if (cWeap) { sprintf(strWeaponID, "WEAPON_STAT_%d", idx); if (hsInterface.AtrGet(m_objnum, strWeaponID)) cWeap->SetStatus(atoi(hsInterface.m_buffer)); } } } // Set the console flag hsInterface.SetFlag(objnum, THING_HSPACE_CONSOLE); ClearObjectAttrs(); return TRUE; } // Call this function to have the console handle a message, // which is usually given to the user of the console in some // form. void CHSConsole::HandleMessage(char *strMsg, int type) { dbref dbUser; dbUser = hsInterface.ConsoleUser(m_objnum); if (dbUser == NOTHING) return; // Is the console online? if (!IsOnline()) return; notify(dbUser, strMsg); } // Returns the power needs for the console, which includes // a base amount plus any weapon needs. UINT CHSConsole::GetMaximumPower(void) { UINT uPower; uPower = 2; // Console requires at least 2 MW of power // Figure in weapon needs if (m_weapon_array) { uPower += m_weapon_array->GetTotalPower(); } return uPower; } // Can be used to tell the console to adjust its heading, for // example, when the ship it belongs to turns. void CHSConsole::AdjustHeading(int iXY, int iZ) { m_xyheading += iXY; m_zheading += iZ; if (m_xyheading > 359) m_xyheading -= 360; else if (m_xyheading < 0) m_xyheading += 360; } // Returns a character string containing the value of // the requested console attribute. char *CHSConsole::GetAttributeValue(char *strName) { static char rval[64]; char tmp[32]; int idx; *rval = '\0'; if (!strcasecmp(strName, "CXYHEADING")) { sprintf(rval, "%d", m_xyheading); } else if (!strcasecmp(strName, "CZHEADING")) { sprintf(rval, "%d", m_zheading); } else if (!strcasecmp(strName, "WEAPONS")) { CHSWeapon *cWeap; // If we have a weapons array, run through // the weapons, pulling out their types. if (m_weapon_array) { for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { cWeap = m_weapon_array->GetWeapon(idx); if (!cWeap) continue; // Add the class of the weapon to the list if (!*rval) sprintf(tmp, "%d", cWeap->m_class); else sprintf(tmp, " %d", cWeap->m_class); strcat(rval, tmp); } } } else if (!strcasecmp(strName, "XYOFFSET")) { sprintf(rval, "%d", m_xyoffset); } else if (!strcasecmp(strName, "ZOFFSET")) { sprintf(rval, "%d", m_zoffset); } else if (!strcasecmp(strName, "CAN ROTATE")) { sprintf(rval, "%d", m_can_rotate ? 1 : 0); } else if (!strcasecmp(strName, "LOCK")) { // Are we locked? if (!m_target_lock) return "#-1"; CHSSysSensors *cSensors; // Get the sensors from our owner cSensors = (CHSSysSensors *)m_ownerObj->GetEngSystem(HSS_SENSORS); if (!cSensors) return ""; SENSOR_CONTACT *cContact; cContact = cSensors->GetContact(m_target_lock); if (!cContact) return ""; sprintf(rval, "%d", cContact->m_id); } else return NULL; return rval; } // Attempts to set an attribute with a value for the // console. BOOL CHSConsole::SetAttributeValue(char *strName, char *strValue) { int iVal; // Find the attribute name, set the value. if (!strcasecmp(strName, "XYHEADING")) { iVal = atoi(strValue); if (iVal < 0 || iVal > 359) return FALSE; m_xyheading = iVal; return TRUE; } else if (!strcasecmp(strName, "ZHEADING")) { iVal = atoi(strValue); if (iVal > 90 || iVal < -90) return FALSE; m_zheading = iVal; return TRUE; } else if (!strcasecmp(strName, "XYOFFSET")) { iVal = atoi(strValue); if (iVal < 0 || iVal > 359) return FALSE; m_xyoffset = iVal; return TRUE; } else if (!strcasecmp(strName, "CAN ROTATE")) { m_can_rotate = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "ZOFFSET")) { iVal = atoi(strValue); if (iVal < -90 || iVal > 90) return FALSE; m_zoffset = iVal; return TRUE; } return FALSE; } // Sets the CHSObject pointer for the object that this // console belongs to. void CHSConsole::SetOwnerObj(CHSObject *cObj) { m_ownerObj = cObj; } // Tries to lock the console onto a target ID. This is only // possible if the console belongs to a certain object type // which has sensors. void CHSConsole::LockTargetID(dbref player, int ID) { UINT uMaxRange; double sX, sY, sZ; // Our owner's coords. double tX, tY, tZ; // Target's coords double dDistance; // Do we have an owner object? if (!m_ownerObj) { hsStdError(player, "This console doesn't belong to an HSpace object."); return; } // Does the object type support sensors? if (m_ownerObj->GetType() != HST_SHIP) { hsStdError(player, "Only consoles on space vessels support that command."); return; } // Do we have weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Try to find the sensor contact for the vessel. CHSShip *cShip; SENSOR_CONTACT *cContact; cShip = (CHSShip *)m_ownerObj; cContact = cShip->GetSensorContact(ID); if (!cContact) { hsStdError(player, "No such contact ID on sensors."); return; } // Grab the CHSObject pointer from the sensor contact CHSObject *cTarget; cTarget = cContact->m_obj; // Find max weapon range uMaxRange = m_weapon_array->GetMaxRange(); // Calculate distance to target sX = cShip->GetX(); sY = cShip->GetY(); sZ = cShip->GetZ(); tX = cTarget->GetX(); tY = cTarget->GetY(); tZ = cTarget->GetZ(); dDistance = Dist3D(sX, sY, sZ, tX, tY, tZ); // Distance greater than max weapon range? if (dDistance > uMaxRange) { hsStdError(player, "Target is out of our max weapons range."); return; } // Already locked onto that target? if (m_target_lock) { if (m_target_lock->GetDbref() == cTarget->GetDbref()) { hsStdError(player, "Weapons are already locked onto that target."); return; } } // Lock onto the object CHSObject *cPrevLock; cPrevLock = m_target_lock; m_target_lock = cTarget; // Tell the old target we've unlocked? if (cPrevLock) cPrevLock->HandleLock(m_ownerObj, FALSE); // Tell the new target we've locked. cTarget->HandleLock(m_ownerObj, TRUE); hsStdError(player, "Weapons now locked on specified target contact."); } // Returns the weapons array object for the console CHSWeaponArray *CHSConsole::GetWeaponArray(void) { return m_weapon_array; } // Gives the gunnery readout report for the console. void CHSConsole::GiveGunneryReport(dbref player) { int idx; CHSWeapon *cWeap; char tbuf[256]; // Do we have weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Print out the header. sprintf(tbuf, "%s%s.-----------------------------------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Console Weaponry Report %39s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, m_ownerObj->GetName(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >---------------------------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Print weapon info header sprintf(tbuf, "%s%s| %s[%s%sID%s] Name Status Weapon Attributes %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Run down the weapons in the array, calling on them for // information. char lpstrName[64]; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { cWeap = m_weapon_array->GetWeapon(idx); if (!cWeap) continue; // Copy in the weapon name, and truncate it strcpy(lpstrName, cWeap->GetName()); lpstrName[28] = '\0'; // Print weapon info. It's up to the weapon to // give us most of the info. The ID of the weapon // is array notation + 1. sprintf(tbuf, "%s%s|%s [%2d] %-29s%-15s%-27s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, idx+1, lpstrName, cWeap->GetStatus(), cWeap->GetAttrInfo(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Give autoload status sprintf(tbuf, "%s%s| %75s |%s", ANSI_HILITE, ANSI_BLUE, " ", ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sAutoloading:%s %-3s %s%sAutorotate:%s %-3s %40s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, m_autoload ? "ON" : "OFF", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, m_autorotate ? "ON" : "OFF", " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // If there's a missile bay, give info for that if (m_missile_bay) { HSMISSILESTORE *mStore; int nStores = 0; BOOL bHeaderPrinted = FALSE; CHSDBWeapon *cDBWeap; // Print out storage info for (idx = 0; idx < HS_MAX_MISSILES; idx++) { mStore = m_missile_bay->GetStorage(idx); if (!mStore) continue; // Has the header been printed? if (!bHeaderPrinted) { bHeaderPrinted = TRUE; // Print missile bay header info sprintf(tbuf, "%s%s >---------------------------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s %s+%s- Munitions Storage -%s%s+ %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%77s|%s", ANSI_HILITE, ANSI_BLUE, " ", ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %s[%s%sID%s] Munitions Type Max Remaining%19s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, " ", ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Give the information cDBWeap = waWeapons.GetWeapon(mStore->m_class, HSW_NOTYPE); sprintf(tbuf,"%s%s|%s [%2d] %-34s%2d %2d%23s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, idx+1, cDBWeap->m_name, mStore->m_maximum, mStore->m_remaining, " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } } // Finish off the report. sprintf(tbuf, "%s%s`-----------------------------------------------------------------------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Allows a player (admin) to delete the specified weapon slot // from the console. The gunnery report lists weapons from 1 .. n, // so we expect the same here. However, weapon slots are from // 0 .. n, so that adjustment is made. void CHSConsole::DeleteWeapon(dbref player, int slot) { // Do we have a weapons array? if (!m_weapon_array) { notify(player, "This console is not equipped with weaponry."); return; } // Decrement slot by 1. slot--; if (slot < 0) slot = 0; // Check to see if the weapon exists. if (!m_weapon_array->GetWeapon(slot)) { notify(player, "That weapon slot does not exist on that console."); return; } if (!m_weapon_array->DeleteWeapon(slot)) { notify(player, "Failed to delete the weapon in that slot."); return; } notify(player, "Weapon deleted."); // Check to see if there is a weapon in slot 0. If not, // then there are no weapons left, and we can delete the // weapons array. if (!m_weapon_array->GetWeapon(0)) { delete m_weapon_array; m_weapon_array = NULL; } } // Allows a player (admin) to add a weapon of a certain type // to the console. All error checking is performed. BOOL CHSConsole::AddWeapon(dbref player, int type) { // Valid weapon type? if (!waWeapons.GoodWeapon(type)) { notify(player, "Invalid weapon type specified."); return FALSE; } // Do we have a weapons array? if (!m_weapon_array) { m_weapon_array = new CHSWeaponArray; // Tell the console array of our missile bay m_weapon_array->SetMissileBay(m_missile_bay); } if (!m_weapon_array->NewWeapon(type)) notify(player, "Failed to add specified weapon type to console."); else notify(player, tprintf("Weapon type %d added to console.", type)); return TRUE; } // Tells the console where the missile bay is for its weapons // to grab missiles from. void CHSConsole::SetMissileBay(CHSMissileBay *mBay) { m_missile_bay = mBay; if (m_weapon_array) m_weapon_array->SetMissileBay(mBay); } // Configures a weapon so that it takes on the attributes // of a specified weapon, usually a missile. void CHSConsole::ConfigureWeapon(dbref player, int weapon, int type) { CHSWeapon *cWeap; // Weapon and type are specified from 1 .. n, but weapons // are stored as 0 .. n-1, so decrement. type--; weapon--; // Do we have any weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Does the weapon exist? cWeap = m_weapon_array->GetWeapon(weapon); if (!cWeap) { hsStdError(player, "Invalid weapon ID specified."); return; } // Does the weapon support configuration? if (!cWeap->Configurable()) { hsStdError(player, "That weapon type cannot be configured."); return; } // Do we have the type in storage? if (!m_missile_bay) { hsStdError(player, "No munitions storage available."); return; } // Grab the storage slot. HSMISSILESTORE *mStore; mStore = m_missile_bay->GetStorage(type); if (!mStore) { hsStdError(player, tprintf("Invalid munitions ID (%d) specified.", type+1)); return; } // Try to configure it. if (!cWeap->Configure(mStore->m_class)) { hsStdError(player, "Failed to configure weapon to specified munitions type."); return; } // All went ok. hsStdError(player, "Weapon configured to specified munitions type."); } // Allows a player to load a specific weapon. void CHSConsole::LoadWeapon(dbref player, int weapon) { CHSWeapon *cWeap; // Do we have weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Find the weapon. Decrement weapon variable to go // to array notation. weapon--; cWeap = m_weapon_array->GetWeapon(weapon); if (!cWeap) { hsStdError(player, "Invalid weapon ID specified."); return; } // Is the weapon loadable? if (!cWeap->Loadable()) { hsStdError(player, "That weapon cannot be loaded."); return; } // Is it already reloading if (cWeap->Reloading()) { hsStdError(player, "That weapon is already currently loading."); return; } // Try to load it. if (!cWeap->Reload()) { hsStdError(player, "Unable to reload that weapon at this time."); return; } // Went ok. hsStdError(player, "Reloading weapon ..."); } // Handles cyclic stuff for consoles void CHSConsole::DoCycle(void) { dbref dbUser; // Verify that the computer has enough power to // power us. int need; need = GetMaximumPower(); // Check target lock. if (m_target_lock) { BOOL bUnlock = FALSE; // Target still active? if (!m_target_lock->IsActive()) bUnlock = TRUE; // Find max weapon range UINT uMaxRange; if (m_weapon_array) uMaxRange = m_weapon_array->GetMaxRange(); else uMaxRange = 0; // Calculate distance to target double sX, sY, sZ; double tX, tY, tZ; sX = m_ownerObj->GetX(); sY = m_ownerObj->GetY(); sZ = m_ownerObj->GetZ(); tX = m_target_lock->GetX(); tY = m_target_lock->GetY(); tZ = m_target_lock->GetZ(); double dDistance; dDistance = Dist3D(sX, sY, sZ, tX, tY, tZ); // Distance greater than max weapon range? if (dDistance > uMaxRange) bUnlock = TRUE; // Is our owner still active? if (!m_ownerObj->IsActive()) bUnlock = TRUE; // Unlock weapons? if (bUnlock) { dbref dbUser; dbUser = hsInterface.ConsoleUser(m_objnum); m_target_lock->HandleLock(m_ownerObj, FALSE); m_target_lock = NULL; if (dbUser != NOTHING) hsStdError(dbUser, "Target lock no longer capable."); } } if (!IsOnline()) return; // If we have a weapons array, tell it to cycle. if (m_weapon_array) { m_weapon_array->DoCycle(); // Indicate any weapons that just became ready; int idx; CHSWeapon *cWeap; char tbuf[64]; // Find the console's user. dbUser = hsInterface.ConsoleUser(m_objnum); if (dbUser != NOTHING) { for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (cWeap = m_weapon_array->GetWeapon(idx)) { if (cWeap->GetStatusChange() == STAT_READY) { if (cWeap->Loadable()) sprintf(tbuf, "%s%s[%s%s%d%s]%s - Weapon loaded.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, idx+1, ANSI_GREEN, ANSI_NORMAL); else sprintf(tbuf, "%s%s[%s%s%d%s]%s - Weapon ready.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, idx+1, ANSI_GREEN, ANSI_NORMAL); notify(dbUser, tbuf); } } } } } } // Unlocks the weapons (if locked) from the locked // target. void CHSConsole::UnlockWeapons(dbref player) { // Do we have an owner object? if (!m_ownerObj) { hsStdError(player, "This console doesn't belong to an HSpace object."); return; } // Do we have weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Are we currently locked? if (!m_target_lock) { hsStdError(player, "Weapons are not currently locked onto a target."); return; } // Tell the target we've unlocked m_target_lock->HandleLock(m_ownerObj, FALSE); m_target_lock = NULL; // Tell the player hsStdError(player, "Weapons now unlocked from previous target."); } // Changes the heading of the console (in this case, a turret) // to a given angle. Error checking is performed to ensure // that it doesn't turn into the ship it's on. void CHSConsole::ChangeHeading(dbref player, int iXY, int iZ) { int iXYAngle; int iZAngle; double is, js, ks; // Ship vector double ic, jc, kc; // Turret vector; // Do we have an owner object? if (!m_ownerObj) { hsStdError(player, "This console does not belong to any HSpace object."); return; } // Can the console rotate like a turret? if (!m_can_rotate) { hsStdError(player, "This console does not have rotate capability."); return; } // Do we belong to a ship? if (m_ownerObj->GetType() != HST_SHIP) { hsStdError(player, "This command only applies to consoles located on ships."); return; } CHSShip *cShip; cShip = (CHSShip *)m_ownerObj; // Do some error checking. if (iXY < 0) iXY = m_xyheading; else if (iXY > 359) iXY = 359; if (iZ < -90) iZ = m_zheading; else if (iZ > 90) iZ = 90; // The following code computes a normal vector for // the side of the ship we're located on. We'll // then compute the normal vector for where the // console wants to turn to. If the dot product // of the two vectors is negative, the console is // trying to turn into the ship. iXYAngle = cShip->GetXYHeading() + m_xyoffset; iZAngle = cShip->GetZHeading() + m_zoffset; // Make sure angles fall within specifications if (iXYAngle > 359) iXYAngle -= 360; else if (iXYAngle < 0) iXYAngle += 360; if (iZAngle < 0) iZAngle += 360; // Compute normal vector for the side of the ship // we're on. is = d2sin_table[iXYAngle] * d2cos_table[iZAngle]; js = d2cos_table[iXYAngle] * d2cos_table[iZAngle]; ks = d2sin_table[iZAngle]; // Find normal vector for where we want to head. if (iZ < 0) iZ += 360; ic = d2sin_table[iXY] * d2cos_table[iZ]; jc = d2cos_table[iXY] * d2cos_table[iZ]; kc = d2sin_table[iZ]; // Compute the dot product between the two vectors double dp; dp = (is * ic) + (js * jc) + (ks * kc); if (dp < 0) { hsStdError(player, "This console cannot currently rotate to that angle."); return; } // Set the heading m_xyheading = iXY; if (iZ > 90) iZ -= 360; m_zheading = iZ; char tbuf[128]; sprintf(tbuf, "Console heading changed to %d mark %d.", iXY, iZ); hsStdError(player, tbuf); } // Allows a player to fire a specified weapon number. void CHSConsole::FireWeapon(dbref player, int weapon) { // Weapons are specified from 1 .. n, but they're // stored in the array as 0 .. n-1, so decrement. weapon--; // Do we have weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Is it a valid weapon? CHSWeapon *cWeap; cWeap = m_weapon_array->GetWeapon(weapon); if (!cWeap) { hsStdError(player, "Invalid weapon ID specified."); return; } // Does the weapon require a target lock? if (cWeap->RequiresLock() && !m_target_lock) { hsStdError(player, "You must be locked onto a target to fire that weapon."); return; } // Can the weapon attack that type of object? if (!cWeap->CanAttackObject(m_target_lock)) { hsStdError(player, "You cannot attack that target with that weapon."); return; } // Is the weapon ready? if (!cWeap->IsReady()) { hsStdError(player, "That weapon is not ready for firing."); return; } // Do we try to autorotate to the target? if (m_target_lock && m_autorotate) { // Calculate the bearing to the target. int iXY, iZ; double sX, sY, sZ; // Our coords double tX, tY, tZ; // Target coords sX = m_ownerObj->GetX(); sY = m_ownerObj->GetY(); sZ = m_ownerObj->GetZ(); tX = m_target_lock->GetX(); tY = m_target_lock->GetY(); tZ = m_target_lock->GetZ(); iXY = XYAngle(sX, sY, tX, tY); iZ = ZAngle(sX, sY, sZ, tX, tY, tZ); ChangeHeading(player, iXY, iZ); } // Is the target in the cone? if (m_target_lock && !IsInCone(m_target_lock)) { hsStdError(player, "Target is not currently within firing cone."); return; } // Tell the weapon to fire. cWeap->AttackObject(m_ownerObj, m_target_lock, this, m_targetting); // Is the weapon loadable, and should we reload? if (m_autoload && cWeap->Loadable()) cWeap->Reload(); } // Indicates whether a given CHSObject is within the firing // cone of the console. To do this, we calculate the vector // to the target, use the dot product to get the difference // between that vector and the console heading vector, and // then convert the dot product to an angle. We use this // angle to see if it's larger than the cone. BOOL CHSConsole::IsInCone(CHSObject *cTarget) { double ic, jc, kc; // Console heading vector double it, jt, kt; // Target vector int iXY, iZ; double tX, tY, tZ; // Target coords. double sX, sY, sZ; // Source (our) coords if (!cTarget) return FALSE; if (!m_ownerObj) return FALSE; sX = m_ownerObj->GetX(); sY = m_ownerObj->GetY(); sZ = m_ownerObj->GetZ(); tX = cTarget->GetX(); tY = cTarget->GetY(); tZ = cTarget->GetZ(); // Calculate the vector for where the console is // pointing. iZ = m_zheading; if (iZ < 0) iZ += 360; ic = d2sin_table[m_xyheading] * d2cos_table[iZ]; jc = d2cos_table[m_xyheading] * d2cos_table[iZ]; kc = d2sin_table[iZ]; // Now calculate the vector to the target. iXY = XYAngle(sX, sY, tX, tY); if (iXY > 359) iXY -= 360; else if (iXY < 0) iXY += 360; iZ = ZAngle(sX, sY, sZ, tX, tY, tZ); if (iZ < 0) iZ += 360; it = d2sin_table[iXY] * d2cos_table[iZ]; jt = d2cos_table[iXY] * d2cos_table[iZ]; kt = d2sin_table[iZ]; // Calculate the dot product of the two vectors. double dp; dp = (ic * it) + (jc * jt) + (kc * kt); if (dp > 1) dp = 1; else if (dp < -1) dp = -1; // Determine the angular difference between the vectors // based on the dot product. double diff; diff = acos(dp) * RADTODEG; // If the absolute difference between the vectors is // greater than 1/2 the firing arc, it's out of the cone. if (diff < 0) diff *= -1; if (diff > (m_arc * .5)) return FALSE; return TRUE; } // Returns the current XYHeading of the console int CHSConsole::GetXYHeading(void) { return m_xyheading; } // Returns the ZHeading of the console int CHSConsole::GetZHeading(void) { return m_zheading; } // Allows a player to power up the console void CHSConsole::PowerUp(dbref player) { int maxpower; // Are we already online? if (IsOnline()) { hsStdError(player, "This console is already online."); return; } // Does the computer have enough power? if (m_computer) { maxpower = GetMaximumPower(); if (!m_computer->DrainPower(maxpower)) { hsStdError(player, "Insufficient computer power to power console."); return; } } // Bring it online m_online = TRUE; hsStdError(player, tprintf("%s now online.", Name(m_objnum))); } // Powers down the console, releasing power to the computer void CHSConsole::PowerDown(dbref player) { int maxpower; if (!IsOnline()) { hsStdError(player, "This console is not currently online."); return; } // Do we have a computer? if (m_computer) { maxpower = GetMaximumPower(); m_computer->ReleasePower(maxpower); m_online = FALSE; hsStdError(player, tprintf("%s powered down.", Name(m_objnum))); } else hsStdError(player, "That's not necessary with this console."); } // Gives a quick, target report for when the weapons are // locked onto a target. void CHSConsole::GiveTargetReport(dbref player) { SENSOR_CONTACT *cContact; // Are we locked onto a target? if (!m_target_lock) { hsStdError(player, "Weapons are not currently locked onto a target."); return; } // Find the contact in the owner's sensor array CHSShip *cShip; cShip = (CHSShip *)m_ownerObj; cContact = cShip->GetSensorContact(m_target_lock); char tbuf[256]; // For printing info double sX, sY, sZ; // Owner's coords double tX, tY, tZ; // Target's coords sX = m_ownerObj->GetX(); sY = m_ownerObj->GetY(); sZ = m_ownerObj->GetZ(); tX = m_target_lock->GetX(); tY = m_target_lock->GetY(); tZ = m_target_lock->GetZ(); // Calculate distance to target double dDistance; dDistance = Dist3D(sX, sY, sZ, tX, tY, tZ); // Print the header info sprintf(tbuf, "%s%s.----------------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Target Info Report ID: %-4d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, cContact ? cContact->m_id : -1, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >--------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Is the target in the firing cone? if (IsInCone(m_target_lock)) { sprintf(tbuf, "%s%s|%s %s%s* IN CONE * %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_RED, ANSI_BLUE, ANSI_NORMAL); } else sprintf(tbuf, "%s%s| %56s |%s", ANSI_HILITE, ANSI_BLUE, " ", ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| ______________________ |%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Before printing the rest of the display, calculate // which vertical line and horizontal slot the indicators // are going into. double dx, dy, dz; // Determine vector from us to target dx = (int)((tX - sX) / dDistance); dy = (int)((tY - sY) / dDistance); dz = (int)((tZ - sZ) / dDistance); CHSVector tVec(dx, dy, dz); // Determine our heading vector for the console int iZAngle = m_zheading; if (iZAngle < 0) iZAngle += 360; dx = d2sin_table[m_xyheading] * d2cos_table[iZAngle]; dy = d2cos_table[m_xyheading] * d2cos_table[iZAngle]; dz = d2sin_table[iZAngle]; CHSVector hVec(dx, dy, dz); // Calculate dot product between both vectors double dp; dp = hVec.DotProduct(tVec); // Determine target bearing int iXYAngle; iZAngle = ZAngle(sX, sY, sZ, tX, tY, tZ); iXYAngle = XYAngle(sX, sY, tX, tY); // If the dot product is positive, the target is // on our visual screen. int iVertLine = -1; int iHorzSlot = -1; if (dp > 0) { // Determine which vertical line the target falls into iVertLine = ((iZAngle - m_zheading) - 90) * .05 * -1; // Determine which horizontal slot it goes into iHorzSlot = ((iXYAngle - m_xyheading) + 90) * .166667; } char tbuf2[32]; // Used for printing out the target strcpy(tbuf2, " "); if (iVertLine == 0) tbuf2[iHorzSlot - 3] = 'X'; sprintf(tbuf, "%s%s| /%s%s%s\\ |%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); strcpy(tbuf2, " "); if (iVertLine == 1) tbuf2[iHorzSlot - 1] = 'X'; sprintf(tbuf, "%s%s| /%s%s%s\\ |%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); char lbuf[32]; // Used for printing out a line in pieces char rbuf[32]; if (iVertLine == 2) { strcpy(tbuf2, " - "); if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) { // Just print everything in red tbuf2[iHorzSlot] = 'X'; sprintf(tbuf, "%s%s| %sYou: %s|%s%s%s| %sTarget: %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); } else { // Target red, crosshairs white. We have // to split the line up into three pieces strcpy(lbuf, " "); strcpy(rbuf, " "); if (iHorzSlot < 11) lbuf[iHorzSlot] = 'X'; else rbuf[iHorzSlot - 20] = 'X'; sprintf(tbuf, "%s%s| %sYou: %s|%s%s%s - %s%s%s| %sTarget: %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_RED, lbuf, ANSI_WHITE, ANSI_RED, rbuf, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); } } else { // Print all in red or all in white if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) sprintf(tbuf, "%s%s| %sYou: %s|%s - %s| %sTarget: %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_RED, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); else sprintf(tbuf, "%s%s| %sYou: %s|%s - %s| %sTarget: %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); } notify(player, tbuf); // Figure out the heading of the target. This code // is fairly slow, but we have no choice. CHSVector thVec = m_target_lock->GetMotionVector(); int tXYHeading; int tZHeading; tXYHeading = atan(thVec.i() / thVec.j()) * RADTODEG; if (tXYHeading < 0) tXYHeading += 360; tZHeading = asin(thVec.k()) * RADTODEG; if (iVertLine == 3) { strcpy(tbuf2, " --- "); if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) { // Just print everything in red tbuf2[iHorzSlot] = 'X'; sprintf(tbuf, "%s%s| %sH:%s %3dm%-3d %s%s|%s%s%s| %sH:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_xyheading, m_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, tXYHeading, tZHeading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } else { // Target red, crosshairs white. We have // to split the line up into three pieces strcpy(lbuf, " "); strcpy(rbuf, " "); if (iHorzSlot < 11) lbuf[iHorzSlot] = 'X'; else rbuf[iHorzSlot - 20] = 'X'; sprintf(tbuf, "%s%s| %sH:%s %3dm%-3d %s%s|%s%s%s --- %s%s%s| %sH:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_xyheading, m_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_RED, lbuf, ANSI_WHITE, ANSI_RED, rbuf, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, tXYHeading, tZHeading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } } else { // Print all in red or all in white if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) sprintf(tbuf, "%s%s| %sH:%s %3dm%-3d %s%s|%s --- %s| %sH:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_xyheading, m_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_RED, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, tXYHeading, tZHeading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); else sprintf(tbuf, "%s%s| %sH:%s %3dm%-3d %s%s|%s --- %s| %sH:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_xyheading, m_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, tXYHeading, tZHeading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } notify(player, tbuf); if (iVertLine == 4) { strcpy(tbuf2, " ( ( + ) ) "); if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) { // Just print everything in red tbuf2[iHorzSlot] = 'X'; sprintf(tbuf, "%s%s| %sV:%s %-7d %s%s|%s%s%s| %sV:%s %-7d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_ownerObj->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_target_lock->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } else { // Target red, crosshairs white. We have // to split the line up into three pieces strcpy(lbuf, " "); strcpy(rbuf, " "); if (iHorzSlot < 11) lbuf[iHorzSlot] = 'X'; else rbuf[iHorzSlot - 20] = 'X'; sprintf(tbuf, "%s%s| %sV:%s %-7d %s%s|%s%s%s( ( + ) )%s%s%s| %sV:%s %-7d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_ownerObj->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_RED, lbuf, ANSI_WHITE, ANSI_RED, rbuf, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_target_lock->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } } else { // Print all in red or all in white if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) sprintf(tbuf, "%s%s| %sV:%s %-7d %s%s|%s ( ( + ) ) %s| %sV:%s %-7d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_ownerObj->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_RED, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_target_lock->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); else sprintf(tbuf, "%s%s| %sV:%s %-7d %s%s|%s ( ( + ) ) %s| %sV:%s %-7d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_ownerObj->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, m_target_lock->GetSpeed(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } notify(player, tbuf); if (iVertLine == 5) { strcpy(tbuf2, " ___ "); if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) { // Just print everything in red tbuf2[iHorzSlot] = 'X'; sprintf(tbuf, "%s%s| |%s%s%s| %sR:%s %-5.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } else { // Target red, crosshairs white. We have // to split the line up into three pieces strcpy(lbuf, " "); strcpy(rbuf, " "); if (iHorzSlot < 11) lbuf[iHorzSlot] = 'X'; else rbuf[iHorzSlot - 20] = 'X'; sprintf(tbuf, "%s%s| |%s%s%s ___ %s%s%s| %sR:%s %-5.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, lbuf, ANSI_WHITE, ANSI_RED, rbuf, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } } else { // Print all in red or all in white if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) sprintf(tbuf, "%s%s| |%s ___ %s| %sR:%s %-5.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); else sprintf(tbuf, "%s%s| |%s ___ %s| %sR:%s %-5.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } notify(player, tbuf); if (iVertLine == 6) { strcpy(tbuf2, " _ "); if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) { // Just print everything in red tbuf2[iHorzSlot] = 'X'; sprintf(tbuf, "%s%s| |%s%s%s| %sB:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, iXYAngle, iZAngle, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } else { // Target red, crosshairs white. We have // to split the line up into three pieces strcpy(lbuf, " "); strcpy(rbuf, " "); if (iHorzSlot < 11) lbuf[iHorzSlot] = 'X'; else rbuf[iHorzSlot - 20] = 'X'; sprintf(tbuf, "%s%s| |%s%s%s _ %s%s%s| %sB:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, lbuf, ANSI_WHITE, ANSI_RED, rbuf, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, iXYAngle, iZAngle, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } } else { // Print all in red or all in white if (iHorzSlot > 10 && iHorzSlot < 20 && iVertLine > 1 && iVertLine < 7) sprintf(tbuf, "%s%s| |%s _ %s| %sB:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, iXYAngle, iZAngle, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); else sprintf(tbuf, "%s%s| |%s _ %s| %sB:%s %3dm%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_WHITE, ANSI_NORMAL, iXYAngle, iZAngle, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); } notify(player, tbuf); strcpy(tbuf2, " "); if (iVertLine == 7) tbuf2[iHorzSlot] = 'X'; sprintf(tbuf, "%s%s| |%s%s%s| |%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); strcpy(tbuf2, " "); if (iVertLine == 8) tbuf2[iHorzSlot - 1] = 'X'; sprintf(tbuf, "%s%s| \\%s%s%s/ |%s", ANSI_HILITE, ANSI_BLUE, ANSI_RED, tbuf2, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s`---------------\\\\.______________________.//---------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Indicates whether the console is on a given frequency. BOOL CHSConsole::OnFrq(double frq) { // Check for the COMM_FRQS attr. if (!hsInterface.AtrGet(m_objnum, "COMM_FRQS")) return FALSE; // Separate the string into blocks of spaces char *ptr; char *bptr; // Points to the first char in the frq string double cfrq; ptr = strchr(hsInterface.m_buffer, ' '); bptr = hsInterface.m_buffer; while(ptr) { *ptr = '\0'; cfrq = atof(bptr); // Do we have a match, Johnny? if (cfrq == frq) return TRUE; // Find the next frq in the string. bptr = ptr+1; ptr = strchr(bptr, ' '); } // Last frq in the string. cfrq = atof(bptr); if (cfrq == frq) return TRUE; // No match! return FALSE; } // Attempts to unload a given weapon, if that weapon is // a loadable type of weapon. void CHSConsole::UnloadWeapon(dbref player, int weapon) { // Do we have any weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry"); return; } // Find the weapon. weapon--; CHSWeapon *cWeap; cWeap = m_weapon_array->GetWeapon(weapon); if (!cWeap) { hsStdError(player, "Invalid weapon ID specified."); return; } // Is the weapon loadable and, therefore, unloadable? if (!cWeap->Loadable()) { hsStdError(player, "That weapon cannot be unloaded."); return; } if (!cWeap->Unload()) hsStdError(player, "Failed to unload specified weapon."); else hsStdError(player, "Weapon unloaded."); } // Sets the autoloading status for the console. This is a // level higher than letting the weapon handle it. The console // tries to reload any loadable weapons when they're fired. void CHSConsole::SetAutoload(dbref player, BOOL bStat) { if (!bStat) { m_autoload = FALSE; hsStdError(player, "Autoloading deactivated."); } else { m_autoload = TRUE; hsStdError(player, "Autoloading activated."); } } // Sets the autorotate status for the console. If activated, // the turret automatically tries to rotate to the target // when the fire command is issued. void CHSConsole::SetAutoRotate(dbref player, BOOL bStat) { if (!bStat) { m_autorotate = FALSE; hsStdError(player, "Autorotate deactivated."); } else { m_autorotate = TRUE; hsStdError(player, "Autorotate activated."); } } // Sets the system that the player wishes to target when // firing a targetable weapon. void CHSConsole::SetSystemTarget(dbref player, int type) { char *ptr; // Do we have weapons? if (!m_weapon_array) { hsStdError(player, "This console is not equipped with weaponry."); return; } // Are weapons locked? if (!m_target_lock) { hsStdError(player, "Weapons are not currently locked on a target."); return; } if (type == HSS_NOTYPE) { m_targetting = HSS_NOTYPE; hsStdError(player, "System targetting disabled."); } else { // Find the system name. ptr = hsGetEngSystemName(type); m_targetting = type; if (!ptr) hsStdError(player, "Targetting unknown system on enemy target."); else hsStdError(player, tprintf("Weapons now targeting %s system on enemy target.", ptr)); } } // Returns a CHSVector object based on the current heading. CHSVector &CHSConsole::GetHeadingVector(void) { double i, j, k; int zang; zang = m_zheading; if (zang < 0) zang += 360; // Calculate coefficients i = d2sin_table[m_xyheading] * d2cos_table[zang]; j = d2cos_table[m_xyheading] * d2cos_table[zang]; k = d2sin_table[zang]; static CHSVector tvec(i, j, k); return tvec; } // Returns the current target lock. CHSObject *CHSConsole::GetObjectLock(void) { return m_target_lock; } src/hspace/hsconsole.h 100664 767 767 0 7141305141 13065 0 ustar mux mux src/hspace/hsconsolecmds.cpp 100664 767 767 25666 7141305141 14420 0 ustar mux mux #include "hscopyright.h" #include "hstypes.h" #include "hsdb.h" #include "hscmds.h" #include "hsobjects.h" #include "hsutils.h" #include "hsinterface.h" #include <stdlib.h> #include <string.h> HSPACE_COMMAND_PROTO(hscLockID) HSPACE_COMMAND_PROTO(hscGunneryReport) HSPACE_COMMAND_PROTO(hscConfigureWeapon) HSPACE_COMMAND_PROTO(hscLoadWeapon) HSPACE_COMMAND_PROTO(hscUnlockWeapons) HSPACE_COMMAND_PROTO(hscChangeHeading) HSPACE_COMMAND_PROTO(hscFireWeapon) HSPACE_COMMAND_PROTO(hscSetConsPower) HSPACE_COMMAND_PROTO(hscTargetReport) HSPACE_COMMAND_PROTO(hscUnload) HSPACE_COMMAND_PROTO(hscSetAutoload) HSPACE_COMMAND_PROTO(hscSetAutoRotate) HSPACE_COMMAND_PROTO(hscTargetSystem) #ifdef MUX NAMETAB hsConsole_sw[] = { {(char *)"autoload", 5, CA_PUBLIC, 1}, {(char *)"autorotate", 5, CA_PUBLIC, 2}, {(char *)"configure", 1, CA_PUBLIC, 3}, {(char *)"fire", 1, CA_PUBLIC, 4}, {(char *)"grep", 1, CA_PUBLIC, 5}, {(char *)"head", 1, CA_PUBLIC, 6}, {(char *)"lock", 1, CA_PUBLIC, 7}, {(char *)"power", 1, CA_PUBLIC, 8}, {(char *)"qrep", 1, CA_PUBLIC, 9}, {(char *)"target", 1, CA_PUBLIC, 10}, {(char *)"unload", 5, CA_PUBLIC, 11}, {(char *)"unlock", 5, CA_PUBLIC, 12}, {NULL, 0, 0, 0} }; hs_command hConsoleCommands[] = { NULL, hscSetAutoload, hscSetAutoRotate, hscConfigureWeapon, hscFireWeapon, hscGunneryReport, hscChangeHeading, hscLoadWeapon, hscLockID, hscSetConsPower, hscTargetReport, hscTargetSystem, hscUnload, hscUnlockWeapons }; #endif #ifdef PENNMUSH // The hsConCommandArray holds all externally callable // @console commands. HSPACE_COMMAND hsConCommandArray[] = { "AUTOLOAD", hscSetAutoload, HCP_ANY, "AUTOROTATE", hscSetAutoRotate, HCP_ANY, "CONFIGURE", hscConfigureWeapon, HCP_ANY, "FIRE", hscFireWeapon, HCP_ANY, "GREP", hscGunneryReport, HCP_ANY, "HEAD", hscChangeHeading, HCP_ANY, "LOAD", hscLoadWeapon, HCP_ANY, "LOCK", hscLockID, HCP_ANY, "POWER", hscSetConsPower, HCP_ANY, "QREP", hscTargetReport, HCP_ANY, "TARGET", hscTargetSystem, HCP_ANY, "UNLOAD", hscUnload, HCP_ANY, "UNLOCK", hscUnlockWeapons, HCP_ANY, NULL, NULL, 0 }; #endif // Allows a console to lock on to a target with a given // contact ID on sensors. HSPACE_COMMAND_HDR(hscLockID) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Proper command usage. if (!arg_left || !*arg_left) { hsStdError(dbUser, "You must specify a target ID to lock onto."); return; } cConsole->LockTargetID(dbUser, atoi(arg_left)); } // Allows a console to lock on to a target with a given // contact ID on sensors. HSPACE_COMMAND_HDR(hscGunneryReport) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } cConsole->GiveGunneryReport(dbUser); } // Allows a player to configure a given weapon on the console HSPACE_COMMAND_HDR(hscConfigureWeapon) { CHSConsole *cConsole; dbref dbUser; int weapon; int type; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Proper command usage? if (!arg_left || !*arg_left || !arg_right || !*arg_right) { notify(dbUser, "You must specify a weapon ID and a munitions ID."); return; } weapon = atoi(arg_left); type = atoi(arg_right); cConsole->ConfigureWeapon(dbUser, weapon, type); } // Allows a player to load a specified weapon. HSPACE_COMMAND_HDR(hscLoadWeapon) { CHSConsole *cConsole; dbref dbUser; int weapon; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } weapon = atoi(arg_left); // Tell the console to load a weapon cConsole->LoadWeapon(dbUser, weapon); } // Allows a player to unlock the weapons from a target. HSPACE_COMMAND_HDR(hscUnlockWeapons) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Tell the console to unlock weapons. cConsole->UnlockWeapons(dbUser); } // Allows a player to turn the console (turret) HSPACE_COMMAND_HDR(hscChangeHeading) { CHSConsole *cConsole; dbref dbUser; int xy, z; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Determine how to change the angles if (!arg_left || !*arg_left) xy = NOTHING; else xy = atoi(arg_left); if (!arg_right || !*arg_right) z = -91; // Because -1 is a possible angle else z = atoi(arg_right); // Tell the console to change the heading cConsole->ChangeHeading(dbUser, xy, z); } // Allows a player to fire a given weapon. HSPACE_COMMAND_HDR(hscFireWeapon) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Tell the console to unlock weapons. cConsole->FireWeapon(dbUser, atoi(arg_left)); } // Allows a player to power up/down the console. HSPACE_COMMAND_HDR(hscSetConsPower) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Command usage? if (!arg_left || !*arg_left) { notify(dbUser, "You must specify 1/0 for power status."); return; } int stat; stat = atoi(arg_left); if (!stat) cConsole->PowerDown(dbUser); else cConsole->PowerUp(dbUser); } // Gives a target (quick) report to the player HSPACE_COMMAND_HDR(hscTargetReport) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } cConsole->GiveTargetReport(dbUser); } // Allows a player to unload a given weapon HSPACE_COMMAND_HDR(hscUnload) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } cConsole->UnloadWeapon(dbUser, atoi(arg_left)); } // Toggles the autoloading for the console. HSPACE_COMMAND_HDR(hscSetAutoload) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } int stat; stat = atoi(arg_left); cConsole->SetAutoload(dbUser, stat); } // Toggles the autorotate for the console. HSPACE_COMMAND_HDR(hscSetAutoRotate) { CHSConsole *cConsole; dbref dbUser; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } int stat; stat = atoi(arg_left); cConsole->SetAutoRotate(dbUser, stat); } // Allows the player to target a given system on an enemy ship. HSPACE_COMMAND_HDR(hscTargetSystem) { CHSConsole *cConsole; dbref dbUser; int type; // player is the dbref of the console issuing the command cConsole = dbHSDB.FindConsole(player); if (!cConsole) { notify(player, "Go away! You're not an HSpace console."); return; } // Grab the user of the console dbUser = hsInterface.ConsoleUser(player); // Is the console online? if (!cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Find the type of system based on the name if (!strcasecmp(arg_left, "none")) type = HSS_NOTYPE; else type = hsGetEngSystemType(arg_left); cConsole->SetSystemTarget(dbUser, type); } src/hspace/hscopyright.h 100664 767 767 1564 7141305141 13533 0 ustar mux mux /* * HSCopyright.h */ /* * HSpace 4.0 for MUX2 * Derived from Hemlock Space 4.0(Copyright Kyle Forbes, 1999) * * Portions copyright (c) 2000 James Perry (Morgan) <morgan@muxn.org> * */ /* * Copyright for the Hemlock Space (HSpace) simulation package. * * HSpace 4.x * Copyright (c) 1999 Kyle Forbes (Gepht) <kforbes@calmit.unl.edu> * All rights reserved. * * * * HSpace is a product of the HSpace development team, freely * available for public use, distribution, and enhancement subject * to the following regulations: * * 1) Operators (users of the package) must cease use and * uninstall HSpace imediately upon the request of the * development team. * * 2) Any variants of the HSpace package must include reference to * this copyright file. * * 3) Persons modifying the package may do so without permission * of the development team. */ src/hspace/hsdb.cpp 100644 767 767 33314 7141305141 12457 0 ustar mux mux #include "hscopyright.h" #include <stdlib.h> #include "hsdb.h" #include "hsconf.h" #include "hsweapon.h" #include "hsinterface.h" #include "hsutils.h" #include "hsuniverse.h" #include "hsterritory.h" #include <string.h> // The HSpace database object instance CHSDB dbHSDB; CHSDB::CHSDB(void) { m_nWeapons = 0; } BOOL CHSDB::LoadDatabases(void) { char tbuf[256]; int cnt; // Load classes if (!LoadClassDB(HSCONF.classdb)) return FALSE; // Load weapons if (!LoadWeaponDB(HSCONF.weapondb)) return FALSE; m_nWeapons = waWeapons.NumWeapons(); // Load universes if (!LoadUniverseDB(HSCONF.univdb)) return FALSE; m_nUniverses = uaUniverses.NumUniverses(); // Load planets LoadObjectDB(); // Load Territories sprintf(tbuf, "LOADING: %s", HSCONF.territorydb); hs_log(tbuf); LoadTerritoryDB(HSCONF.territorydb); cnt = taTerritories.NumTerritories(); sprintf(tbuf, "LOADING: %d %s loaded.", cnt, cnt == 1 ? "territory" : "territories"); hs_log(tbuf); return TRUE; } BOOL CHSDB::LoadUniverseDB(char *lpstrDBPath) { return uaUniverses.LoadFromFile(lpstrDBPath); } void CHSDB::DumpUniverseDB(char *lpstrDBPath) { uaUniverses.SaveToFile(lpstrDBPath); } BOOL CHSDB::LoadClassDB(char *lpstrDBPath) { return caClasses.LoadFromFile(lpstrDBPath); } void CHSDB::DumpClassDB(char *lpstrDBPath) { caClasses.SaveToFile(lpstrDBPath); } BOOL CHSDB::LoadWeaponDB(char *lpstrDBPath) { return waWeapons.LoadFromFile(lpstrDBPath); } void CHSDB::DumpWeaponDB(char *lpstrDBPath) { waWeapons.SaveToFile(lpstrDBPath); } BOOL CHSDB::LoadTerritoryDB(char *lpstrDBPath) { return taTerritories.LoadFromFile(lpstrDBPath); } void CHSDB::DumpTerritoryDB(char *lpstrDBPath) { taTerritories.SaveToFile(lpstrDBPath); } BOOL CHSDB::LoadObjectDB(void) { FILE *fp; char tbuf[256]; char strKey[64]; char strValue[64]; char *ptr; UINT type; HS_DBKEY key; UINT nShips, nCelestials, nObjs; CHSObject *newObj; sprintf(tbuf, "LOADING: %s ...", HSCONF.objectdb); hs_log(tbuf); // Load the object database, pulling out key/value pairs. // There should be an OBJECTTYPE attribute after each // new object definition. Thus, we just allocate that // type of object, and tell it to load from the file. nShips = nCelestials = nObjs = 0; fp = fopen(HSCONF.objectdb, "r"); if (!fp) { hs_log("ERROR: Unable to open object database for loading!"); return FALSE; } while(fgets(tbuf, 256, fp)) { // Truncate newline chars if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; // Check for end of DB if (!strcmp(tbuf, "*END*")) break; // Extract key and value extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); // Determine key type, then do something. key = HSFindKey(strKey); switch(key) { case HSK_NOKEY: sprintf(tbuf, "WARNING: Invalid key \"%s\" encountered.", strKey); hs_log(tbuf); break; case HSK_DBVERSION: // This should be the first line, if present break; case HSK_OBJECTTYPE: // NEW OBJECT! // Determine type, allocate object, and tell // it to load. type = atoi(strValue); switch(type) { case HST_SHIP: newObj = new CHSShip; if (newObj->LoadFromFile(fp)) nShips++; break; case HST_PLANET: newObj = new CHSPlanet; if (newObj->LoadFromFile(fp)) nCelestials++; break; default: // Generic CHSObject newObj = new CHSObject; if (newObj->LoadFromFile(fp)) nObjs++; break; } break; default: sprintf(tbuf, "WARNING: Key \"%s\" encountered but not handled.", strKey); hs_log(tbuf); break; } } fclose(fp); sprintf(tbuf, "LOADING: %d generic objects loaded.", nObjs); hs_log(tbuf); sprintf(tbuf, "LOADING: %d celestial objects loaded.", nCelestials); hs_log(tbuf); sprintf(tbuf, "LOADING: %d ship objects loaded (Done).", nShips); hs_log(tbuf); return TRUE; } void CHSDB::DumpObjectDB(void) { FILE *fp; CHSUniverse *cUniv; CHSObject *cObj; UINT i,j; char tbuf[256]; fp = fopen(HSCONF.objectdb, "w"); if (!fp) { sprintf(tbuf, "ERROR: Unable to open object db \"%s\" for writing.", HSCONF.objectdb); hs_log(tbuf); return; } // DBVERSION marker fprintf(fp, "DBVERSION=4.0\n"); // Now write out all of the objects in all of the universes for (i = 0; i < HS_MAX_UNIVERSES; i++) { // Grab the universe cUniv = uaUniverses.GetUniverse(i); if (!cUniv) continue; // Now grab all of the objects in the universe, and // call upon them to dump their attributes. for (j = 0; j < HS_MAX_OBJECTS; j++) { cObj = cUniv->GetUnivObject(j); if (!cObj) continue; fprintf(fp, "OBJECTTYPE=%d\n", cObj->GetType()); cObj->WriteToFile(fp); fprintf(fp, "OBJECTEND\n"); } } fprintf(fp, "*END*\n"); fclose(fp); } void CHSDB::DumpDatabases(void) { // Save classes DumpClassDB(HSCONF.classdb); // Save weapons DumpWeaponDB(HSCONF.weapondb); // Save universes DumpUniverseDB(HSCONF.univdb); // Save planets DumpObjectDB(); // Territories taTerritories.SaveToFile(HSCONF.territorydb); } // Call this member function to clean up attributes that are // written to objects during a database save. void CHSDB::CleanupDBAttrs() { CHSUniverse *uSource; UINT idx; UINT jdx; CHSObject *cObj; // Loop through all universes and all objects in those // universes, clearing attributes. for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { uSource = uaUniverses.GetUniverse(idx); if (!uSource) continue; // Grab all objects, and tell them to cleanup their acts! for (jdx = 0; jdx < HS_MAX_OBJECTS; jdx++) { cObj = uSource->GetUnivObject(jdx); if (!cObj) continue; cObj->ClearObjectAttrs(); } } } UINT CHSDB::NumWeapons(void) { return m_nWeapons; } UINT CHSDB::NumUniverses(void) { return m_nUniverses; } CHSShip *CHSDB::FindShip(int objnum) { CHSUniverse *unDest; CHSShip *rShip; int idx; // Traverse all universes, looking for the ship for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (!(unDest = uaUniverses.GetUniverse(idx))) continue; if ((rShip = (CHSShip *)unDest->FindObject(objnum, HST_SHIP))) return rShip; } // No ship found return NULL; } CHSCelestial *CHSDB::FindCelestial(int objnum) { CHSUniverse *unDest; CHSCelestial *rCel; int idx; // Traverse all universes, looking for the celestial for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (!(unDest = uaUniverses.GetUniverse(idx))) continue; // We can use HST_PLANET here because the FindObject() // returns a generic celestial given any of the celestial // types. if ((rCel= (CHSCelestial *)unDest->FindObject(objnum, HST_PLANET))) return rCel; } // No celestial found return NULL; } // Generically looks for an object in the universes. It is // slightly optimized to save time by looking at the HSDB_TYPE // attribute of the object and only looking through those types // of objects. CHSObject *CHSDB::FindObject(int objnum) { HS_TYPE hstType; CHSObject *cObj; // Grab the TYPE attribute if (!hsInterface.AtrGet(objnum, "HSDB_TYPE")) return NULL; hstType = (HS_TYPE) atoi(hsInterface.m_buffer); // Depending on the type of attribute, call a variety of // functions. switch(hstType) { case HST_SHIP: cObj = FindShip(objnum); break; case HST_PLANET: cObj = FindCelestial(objnum); break; default: CHSUniverse *unDest; CHSObject *cObj; int idx; // Traverse all universes, looking for the object for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (!(unDest = uaUniverses.GetUniverse(idx))) continue; if (cObj = unDest->FindObject(objnum)) return cObj; } return NULL; } return cObj; } // Call this function to allow a player to create a new universe // with a given room #. void CHSDB::CreateNewUniverse(dbref player, char *strRoom) { CHSUniverse *uDest; dbref dbRoom; // Room to use as universe // arg_left is the dbref of the room to represent the // universe. dbRoom = hsInterface.NoisyMatchRoom(player, strRoom); if (dbRoom == NOTHING) return; if (Typeof(dbRoom) != TYPE_ROOM) { notify(player, "You must specify a room to represent this universe."); return; } // Grab a new universe, but check that it was created uDest = uaUniverses.NewUniverse(); if (!uDest) { notify(player, "Unable to create new universe. Check log for errors."); return; } // Set the objnum uDest->SetID(dbRoom); // Set the name uDest->SetName((char *)Name(dbRoom)); // Set the flag on the room hsInterface.SetFlag(dbRoom, ROOM_HSPACE_UNIVERSE); // Increment number of universes m_nUniverses++; notify(player, tprintf("Universe %s (#%d) created. Behold!", uDest->GetName(), uDest->GetID())); } // Call this function to allow a player to delete an existing // universe with a given universe ID. void CHSDB::DeleteUniverse(dbref player, char *strID) { int uid; if (!strID || !*strID) { notify(player, "You must specify the uid of a universe."); return; } uid = atoi(strID); /* Check to see if the universe even exists */ if (!uaUniverses.FindUniverse(uid)) { notify(player, tprintf("No such universe with id %d.", uid)); return; } if (uaUniverses.DeleteUniverse(uid)) { m_nUniverses--; notify(player, "BOOM! You have destroyed the universe!"); } else notify(player, "Unable to delete that universe at this time."); } // Returns the CHSObject that controls the specified landing // location. CHSObject *CHSDB::FindObjectByLandingLoc(int loc) { int objnum; // Check for which type of object it's a part of. if (hsInterface.AtrGet(loc, "HSDB_PLANET")) { // Find landing location in planet. CHSPlanet *cPlanet; objnum = strtodbref(hsInterface.m_buffer); cPlanet = (CHSPlanet *)FindObject(objnum); return (CHSObject *)cPlanet; } else if (hsInterface.AtrGet(loc, "HSDB_SHIP")) { // Find landing location in a ship // Find landing location in planet. CHSShip *cShip; objnum = strtodbref(hsInterface.m_buffer); cShip = (CHSShip *)FindObject(objnum); return (CHSObject *)cShip; } else return NULL; // Landing location of .. ? } // Call this function to find a landing location based on object // dbref. CHSLandingLoc *CHSDB::FindLandingLoc(int obj) { int objnum; // Check for which type of object it's a part of. if (hsInterface.AtrGet(obj, "HSDB_PLANET")) { // Find landing location in planet. CHSPlanet *cPlanet; objnum = strtodbref(hsInterface.m_buffer); cPlanet = (CHSPlanet *)FindObject(objnum); if (!cPlanet) return NULL; // Now pull the landing location object from the planet. return (cPlanet->FindLandingLoc(obj)); } else if (hsInterface.AtrGet(obj, "HSDB_SHIP")) { // Find landing location in a ship // Find landing location in planet. CHSShip *cShip; objnum = strtodbref(hsInterface.m_buffer); cShip = (CHSShip *)FindObject(objnum); if (!cShip) return NULL; // Now pull the landing location object from the planet. return (cShip->FindLandingLoc(obj)); } else return NULL; // Landing location of .. ? } // Call this function to find a console object based on the // object dbref. CHSConsole *CHSDB::FindConsole(int obj) { dbref owner; CHSObject *cObj; // Make sure it's a console if (!hsInterface.AtrGet(obj, "HSDB_OWNER")) return NULL; // Grab the dbref of the owner owner = strtodbref(hsInterface.m_buffer); // Now we can use FindObject() to locate the object // that owns the console. cObj = FindObject(owner); if (!cObj) return NULL; return (cObj->FindConsole(obj)); } // Call this function to find an HSpace object based on // a given console. Generally used to find ships based // on a ship console. CHSObject *CHSDB::FindObjectByConsole(dbref obj) { dbref owner; CHSObject *cObj; // Make sure it's a console if (!hsInterface.AtrGet(obj, "HSDB_OWNER")) return NULL; // Grab the dbref of the owner owner = strtodbref(hsInterface.m_buffer); // Now we can use FindObject() to locate the object // that owns the console. cObj = FindObject(owner); return cObj; } #define HS_MAX_ROOM_SEARCH 256 // Max rooms to check for ownership // Given a room #, this function will attempt to find the space // object it belongs to. Why? This is useful for determining // which planet a general room may belong to or which ship a room // is on. CHSObject *CHSDB::FindObjectByRoom(dbref room) { int iRoomsChecked[HS_MAX_ROOM_SEARCH]; iRoomsChecked[0] = NOTHING; return FindRoomOwner(room, iRoomsChecked); } CHSObject *CHSDB::FindRoomOwner(dbref room, int *iRoomsChecked) { CHSObject *cOwner; // Did we check this room already? int idx; for (idx = 0; idx < HS_MAX_ROOM_SEARCH; idx++) { if (iRoomsChecked[idx] == room) return NULL; } // Check attrs to see if this room indicates who // it belongs to. dbref dbOwner; if (hsInterface.AtrGet(room, "HSDB_PLANET")) { dbOwner = strtodbref(hsInterface.m_buffer); return FindObject(dbOwner); } if (hsInterface.AtrGet(room, "HSDB_SHIP")) { dbOwner = strtodbref(hsInterface.m_buffer); return FindObject(dbOwner); } // We're gonna have to search for another room that // As the given attribute. for (idx = 0; idx < HS_MAX_ROOM_SEARCH; idx++) { if (iRoomsChecked[idx] == NOTHING) { iRoomsChecked[idx] = room; break; } } // Did we reach our limit? idx++; if (idx == HS_MAX_ROOM_SEARCH) return NULL; // Ok to look for more rooms, so check the exits // and check their destination rooms. dbref exit_m; dbref dbDest; for (exit_m = Exits(room); exit_m && exit_m != NOTHING; exit_m = Next(exit_m)) { // Get the destination of the exit. dbDest = Location(exit_m); if (dbDest == NOTHING) continue; // Call ourself with the new room. cOwner = FindRoomOwner(dbDest, iRoomsChecked); if (cOwner) return cOwner; } // Nothing found return NULL; } src/hspace/hsdb.h 100644 767 767 2231 7141305141 12076 0 ustar mux mux #ifndef __HSDB_INCLUDED__ #define __HSDB_INCLUDED__ #define HSPACE_VERSION "HSpace v4.0" #include "hstypes.h" #include "hsobjects.h" #include "hscelestial.h" class CHSDB { public: CHSDB(void); BOOL LoadDatabases(void); void DumpDatabases(void); UINT NumWeapons(void); UINT NumUniverses(void); void CreateNewUniverse(dbref, char *); void DeleteUniverse(dbref, char *); void CleanupDBAttrs(void); CHSObject *FindObjectByConsole(dbref); CHSObject *FindObject(int); CHSObject *FindObjectByLandingLoc(int); CHSObject *FindObjectByRoom(int); CHSLandingLoc *FindLandingLoc(int); CHSCelestial *FindCelestial(int); CHSShip *FindShip(int); CHSConsole *FindConsole(int); protected: //Loading BOOL LoadUniverseDB(char *); BOOL LoadClassDB(char *); BOOL LoadWeaponDB(char *); BOOL LoadObjectDB(void); BOOL LoadTerritoryDB(char *); // Saving void DumpUniverseDB(char *); void DumpClassDB(char *); void DumpWeaponDB(char *); void DumpObjectDB(void); void DumpTerritoryDB(char *); // Misc CHSObject *FindRoomOwner(dbref, int *); // Attributes UINT m_nWeapons; UINT m_nUniverses; UINT m_nSystems; }; extern CHSDB dbHSDB; #endif // __HSDB_INCLUDED__ src/hspace/hseng.cpp 100644 767 767 172110 7141305141 12661 0 ustar mux mux #include "hscopyright.h" #include <stdlib.h> #ifndef WIN32 #include <strings.h> #endif #include "hseng.h" #include "hsutils.h" #include "hsuniverse.h" #include "hsengines.h" #include "hsconf.h" #include "hspace.h" struct SYSTEMTYPE { char *name; HSS_TYPE type; }; // An array of available systems that can exist on ships. // If you create a new system type, you need to add its name // here. SYSTEMTYPE hs_system_list[] = { "Reactor", HSS_REACTOR, "Life Support", HSS_LIFE_SUPPORT, "Internal Computer", HSS_COMPUTER, "Engines", HSS_ENGINES, "Sensor Array", HSS_SENSORS, "Maneuv. Thrusters", HSS_THRUSTERS, "Fore Shield", HSS_FORE_SHIELD, "Aft Shield", HSS_AFT_SHIELD, "Starboard Shield", HSS_STARBOARD_SHIELD, "Port Shield", HSS_PORT_SHIELD, "Fuel System", HSS_FUEL_SYSTEM, "Jump Drive", HSS_JUMP_DRIVE, "Comm. Array", HSS_COMM, NULL }; char *hsGetEngSystemName(int type) { int idx; for (idx = 0; hs_system_list[idx].name; idx++) { if (hs_system_list[idx].type == type) return hs_system_list[idx].name; } return NULL; } HSS_TYPE hsGetEngSystemType(char *name) { int idx; int len; len = strlen(name); for (idx = 0; hs_system_list[idx].name; idx++) { if (!strncasecmp(name, hs_system_list[idx].name, len)) return hs_system_list[idx].type; } return HSS_NOTYPE; } // // CHSSystemArray stuff // CHSSystemArray::CHSSystemArray(void) { m_SystemHead = m_SystemTail = NULL; m_nSystems = 0; m_uPowerUse = 0; } // Returns one of the random systems CHSEngSystem *CHSSystemArray::GetRandomSystem(void) { int iRoll; CHSEngSystem *ptr; int idx; // Roll the dice from 1 .. nSystems iRoll = (int) RandomLong(0, m_nSystems); // Resulting iRoll is 0 .. n-1. Find the system. idx = 0; for (ptr = m_SystemHead; ptr; ptr = ptr->GetNext()) { if (idx == iRoll) return ptr; idx++; } // Hrm. No system found, so return NULL. return NULL; } BOOL CHSSystemArray::AddSystem(CHSEngSystem *cSys) { // Either start a new list or add it to the existing // one. if (!m_SystemHead) { m_SystemHead = cSys; m_SystemTail = cSys; } else { m_SystemTail->SetNext(cSys); cSys->SetPrev(m_SystemTail); m_SystemTail = cSys; } m_nSystems++; return TRUE; } // This operator can be used to duplicate the contents // of this array into another array that was passed in. void CHSSystemArray::operator =(CHSSystemArray &cCopyFrom) { CHSEngSystem *ptr; CHSEngSystem *tmp; // Delete any systems we have loaded already. ptr = m_SystemHead; while(ptr) { tmp = ptr; ptr = ptr->GetNext(); delete tmp; } m_SystemHead = m_SystemTail = NULL; // Copy number of systems m_nSystems = cCopyFrom.m_nSystems; // Now duplicate the systems for (ptr = cCopyFrom.m_SystemHead; ptr; ptr = ptr->GetNext()) { // Dup the system tmp = ptr->Dup(); // If the system we're cloning doesn't have a parent, // then it's a default system, so it's now our parent. tmp->SetParentSystem(ptr); // Add it to our linked list. if (!m_SystemHead) { m_SystemHead = m_SystemTail = tmp; } else { tmp->SetPrev(m_SystemTail); m_SystemTail->SetNext(tmp); m_SystemTail = tmp; } } // We're finished! } // Handles cycling systems, powering them down, etc. void CHSSystemArray::DoCycle(void) { CHSEngSystem *cSys; // Tell the systems to cycle. At the same time, // calculate power used. m_uPowerUse = 0; for (cSys = m_SystemHead; cSys; cSys = cSys->GetNext()) { cSys->DoCycle(); m_uPowerUse += cSys->GetCurrentPower(); } } // Updates the current power usage. Call this after // changing a power setting on a system. void CHSSystemArray::UpdatePowerUse(void) { CHSEngSystem *cSys; m_uPowerUse = 0; for (cSys = m_SystemHead; cSys; cSys = cSys->GetNext()) { m_uPowerUse += cSys->GetCurrentPower(); } } // Returns current power usage UINT CHSSystemArray::GetPowerUse(void) { return m_uPowerUse; } // Returns the head of the linked list of systems CHSEngSystem *CHSSystemArray::GetHead(void) { return m_SystemHead; } // Returns number of systems UINT CHSSystemArray::NumSystems(void) { return m_nSystems; } void CHSSystemArray::SaveToFile(FILE *fp) { UINT priority = 0; CHSEngSystem *ptr; for (ptr = GetHead(); ptr; ptr = ptr->GetNext()) { fprintf(fp, "SYSTEMDEF\n"); fprintf(fp, "SYSTYPE=%d\n", ptr->GetType()); ptr->SaveToFile(fp); // Record the system priority for rebuilding priority // on reload. if (ptr->GetType() != HSS_REACTOR) fprintf(fp, "PRIORITY=%d\n", priority++); fprintf(fp, "SYSTEMEND\n"); } } // Looks for, and returns, a system given a specific system // type. CHSEngSystem *CHSSystemArray::GetSystem(HSS_TYPE systype) { CHSEngSystem *ptr; // Run down the list, looking for a match on the type for (ptr = m_SystemHead; ptr; ptr = ptr->GetNext()) { if (ptr->GetType() == systype) return ptr; } // Not found. return NULL; } // Attempts to allocate a new system of the // given type. The new system pointer is returned. CHSEngSystem *CHSSystemArray::NewSystem(HSS_TYPE tType) { CHSEngSystem *cSys; // Determine type, and allocate system. switch(tType) { case HSS_ENGINES: cSys = new CHSSysEngines; break; case HSS_SENSORS: cSys = new CHSSysSensors; break; case HSS_COMPUTER: cSys = new CHSSysComputer; break; case HSS_THRUSTERS: cSys = new CHSSysThrusters; break; case HSS_COMM: cSys = new CHSSysComm; break; case HSS_LIFE_SUPPORT: cSys = new CHSSysLifeSupport; break; case HSS_REACTOR: cSys = new CHSReactor; break; case HSS_FUEL_SYSTEM: cSys = new CHSFuelSystem; break; case HSS_FORE_SHIELD: cSys = new CHSSysShield; cSys->SetType(HSS_FORE_SHIELD); break; case HSS_AFT_SHIELD: cSys = new CHSSysShield; cSys->SetType(HSS_AFT_SHIELD); break; case HSS_PORT_SHIELD: cSys = new CHSSysShield; cSys->SetType(HSS_PORT_SHIELD); break; case HSS_STARBOARD_SHIELD: cSys = new CHSSysShield; cSys->SetType(HSS_STARBOARD_SHIELD); break; case HSS_JUMP_DRIVE: cSys = new CHSJumpDrive; break; default: cSys = NULL; break; } return cSys; } // Looks for, and returns, a system by name. That name // must only match the first n characters of the string // passed in. The first system name to at least match the // characters in the given string is returned. CHSEngSystem *CHSSystemArray::GetSystemByName(char *strName) { CHSEngSystem *ptr; int len; len = strlen(strName); for (ptr = m_SystemHead; ptr; ptr = ptr->GetNext()) { if (!strncasecmp(strName, ptr->GetName(), len)) return ptr; } return NULL; } // Allows a given system to be bumped up or down in the // array. If iDir is negative, the system moves down, otherwise // up. BOOL CHSSystemArray::BumpSystem(CHSEngSystem *cSys, int iDir) { CHSEngSystem *ptr; CHSEngSystem *ptr2; if (!m_SystemHead) return FALSE; if (iDir < 0) { // Move the system down if (!cSys->GetNext()) // System is tail? return FALSE; ptr = cSys->GetNext(); if (!ptr->GetNext()) // Next system is tail? { m_SystemTail = cSys; cSys->SetNext(NULL); } else { ptr2 = ptr->GetNext(); ptr2->SetPrev(cSys); cSys->SetNext(ptr2); } if (!cSys->GetPrev()) // System is head? { m_SystemHead = ptr; ptr->SetPrev(NULL); } else { ptr2 = cSys->GetPrev(); ptr2->SetNext(ptr); ptr->SetPrev(ptr2); } // Swap the two systems. ptr->SetNext(cSys); cSys->SetPrev(ptr); } else if (iDir > 0) { // Move the system up if (!cSys->GetPrev()) // System is head? return FALSE; ptr = cSys->GetPrev(); if (!ptr->GetPrev()) // Prev system is head? { m_SystemHead = cSys; cSys->SetPrev(NULL); } else { ptr2 = ptr->GetPrev(); ptr2->SetNext(cSys); cSys->SetPrev(ptr2); } if (!cSys->GetNext()) // System is tail? { m_SystemTail = ptr; ptr->SetNext(NULL); } else { ptr2 = cSys->GetNext(); ptr2->SetPrev(ptr); ptr->SetNext(ptr2); } // Swap the two systems. ptr->SetPrev(cSys); cSys->SetNext(ptr); } // System was either moved, or iDir was 0. return TRUE; } // // Generic CHSEngSystem stuff // CHSEngSystem::CHSEngSystem(void) { // Initialize our attributes m_optimal_power = NULL; m_tolerance = NULL; m_current_power = 0; m_stress = 0; m_damage_level = DMG_NONE; m_name = NULL; // This is NULL, indicating a default system with default // values. m_parent = NULL; m_ownerObj = NULL; // No one owns us right now m_next = m_prev = NULL; // By default, systems are visible to the players m_bVisible = TRUE; } // Destructor CHSEngSystem::~CHSEngSystem(void) { // Free up our variables if (m_optimal_power) delete m_optimal_power; if (m_tolerance) delete m_tolerance; } // We can use this function to have the system force a power check // to be the power levels are wacky. void CHSEngSystem::CheckSystemPower(void) { UINT max; max = GetOptimalPower(); // Don't allow levels below 0. Level 0 is just deactivation. if (m_current_power < 0) { m_current_power = 0; return; } // Only allow overloading to 150%. if (m_current_power > (max * 1.5)) { m_current_power = (int) (max * 1.5); return; } } void CHSEngSystem::SetOwner(CHSObject *cOwner) { m_ownerObj = cOwner; } // Returns TRUE or FALSE for whether the system is "visible" // for use by players, power allocation, etc. BOOL CHSEngSystem::IsVisible(void) { return m_bVisible; } // Returns the status of the system, which is usually Online // or Offline. If you overload this, don't return damage and // stuff like that. This is just a general system status // string. char *CHSEngSystem::GetStatus(void) { if (m_current_power > 0) return "Online"; else return "Offline"; } // Call this function when you want the system to update itself // during a cycle (usually each second). It handles recharging, // stress calculation, etc. // // If you're deriving a new system from CHSEngSystem, you _can_ // override this to handle your own cyclic stuff. void CHSEngSystem::DoCycle(void) { float fVal; int iOptPower; char tbuf[128]; // If the system is inoperable .. do nothing. if (GetDamageLevel() == DMG_INOPERABLE) return; // Do Anything? if (!m_stress && !m_current_power) return; // Calculate stress iOptPower = GetOptimalPower(); // Optimal power including damage if ((m_current_power > iOptPower) || (m_stress > 0)) { // Calculate percent overload/underload fVal = (m_current_power - iOptPower) / (float) iOptPower; fVal *= 100; // If overloaded, tolerance hinders stress. // If underloaded, tolerance reduces stress faster. if (fVal > 0) fVal *= (float)(HS_STRESS_INCREASE / (float)GetTolerance()); else { // Make sure stress is reduced at least minimally // at 100% power allocation. if (!fVal) fVal = -1; fVal *= (float)(HS_STRESS_INCREASE * GetTolerance()); } m_stress += fVal; if (m_stress > 100) m_stress = 100; if (m_stress < 0) m_stress = 0; // Check to see if system gets damaged. HAHAHAHA! int iDmgRoll; int iStressRoll; time_t tCurrentSecs; tCurrentSecs = time(NULL); // We check every 15 seconds if (!(tCurrentSecs % 15)) { // Roll the dice for damage iDmgRoll = RandomLong(0, 100); // Roll for stress .. mama needs a new car! iStressRoll = (int) m_stress; iStressRoll = RandomLong(0, iStressRoll); // Did we damage? if (iDmgRoll < iStressRoll) { // Ouch. Hurt. HS_DAMAGE prev; HS_DAMAGE newlvl; prev = GetDamageLevel(); newlvl = DoDamage(); if (newlvl != prev) { // Damage changed, so give some messages. if (m_ownerObj && (m_ownerObj->GetType() == HST_SHIP)) { CHSShip *cShip; cShip = (CHSShip *)m_ownerObj; sprintf(tbuf, "%s%s-%s A warning light flashes, indicating that the %s system has taken damaged.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, GetName()); cShip->HandleMessage(tbuf, MSG_ENGINEERING, NULL); // Force a power check CheckSystemPower(); } } } } } } // Allows the type of system to be set. // Only do this if it's not a derived system. void CHSEngSystem::SetType(HSS_TYPE systype) { m_type = systype; } // Prints out system information to a player void CHSEngSystem::GiveSystemInfo(int player) { notify(player, tprintf("Name : %s", GetName())); notify(player, tprintf("Visible : %s", m_bVisible ? "YES" : "NO")); notify(player, tprintf("Damage : %d", m_damage_level)); notify(player, tprintf("Tolerance: %d", GetTolerance())); notify(player, tprintf("Opt Power: %d", GetOptimalPower(FALSE))); notify(player, tprintf("Cur Power: %d", m_current_power)); notify(player, tprintf("Stress : %.1f", m_stress)); } // Returns a comma-delimited list of system attributes and // values. char *CHSEngSystem::GetAttrValueString(void) { static char rval[512]; sprintf(rval, "VISIBLE=%s,DAMAGE=%d,TOLERANCE=%d,OPTIMAL POWER=%d,CURRENT POWER=%d,STRESS=%.1f", m_bVisible ? "YES" : "NO", m_damage_level, GetTolerance(), GetOptimalPower(FALSE), m_current_power, m_stress); return rval; } // Allocates a new CHSEngSystem object, copies in some // important information from this object, and gives it // back to the calling function. CHSEngSystem *CHSEngSystem::Dup(void) { CHSEngSystem *ptr; ptr = new CHSEngSystem; ptr->SetType(m_type); // For custom systems added from the game side, // we need to check for the name. if (m_name) { ptr->m_name = new char[strlen(m_name) + 1]; strcpy(ptr->m_name, m_name); } ptr->m_bVisible = m_bVisible; // There's no initialization here that wasn't // already done by the constructor. Just return // the variable. return ptr; } HS_DAMAGE CHSEngSystem::GetDamageLevel(void) { return m_damage_level; } // // Linked list stuff with CHSEngSystem CHSEngSystem *CHSEngSystem::GetNext(void) { return m_next; } CHSEngSystem *CHSEngSystem::GetPrev(void) { return m_prev; } void CHSEngSystem::SetNext(CHSEngSystem *cObj) { m_next = cObj; } void CHSEngSystem::SetPrev(CHSEngSystem *cObj) { m_prev = cObj; } // // End linked list stuff // void CHSEngSystem::SetParentSystem(CHSEngSystem *cSys) { m_parent = cSys; } // // Value access functions // int CHSEngSystem::GetCurrentPower(void) { return m_current_power; } // Sets the name of the system. void CHSEngSystem::SetName(char *strName) { if (!strName) return; if (m_name) delete [] m_name; m_name = new char[strlen(strName) + 1]; strcpy(m_name, strName); } // Does one level of damage to the system and returns the // new damage level. HS_DAMAGE CHSEngSystem::DoDamage(void) { HS_DAMAGE lvl; // Get the current level lvl = GetDamageLevel(); // If it's not inoperable, increase it if (lvl != DMG_INOPERABLE) { switch(lvl) { case DMG_NONE: m_damage_level = DMG_LIGHT; break; case DMG_LIGHT: m_damage_level = DMG_MEDIUM; break; case DMG_MEDIUM: m_damage_level = DMG_HEAVY; break; case DMG_HEAVY: m_damage_level = DMG_INOPERABLE; break; } } return GetDamageLevel(); } // Reduces the damage on the system one level and returns the // new damage level. HS_DAMAGE CHSEngSystem::ReduceDamage(void) { HS_DAMAGE lvl; // Get the current level. lvl = GetDamageLevel(); // If damaged, reduce it if (lvl != DMG_NONE) { switch(lvl) { case DMG_LIGHT: m_damage_level = DMG_NONE; break; case DMG_MEDIUM: m_damage_level = DMG_LIGHT; break; case DMG_HEAVY: m_damage_level = DMG_MEDIUM; break; case DMG_INOPERABLE: m_damage_level = DMG_HEAVY; break; } } return GetDamageLevel(); } // Reduces the damage on the system to the specified level // and returns the previous damage level. HS_DAMAGE CHSEngSystem::ReduceDamage(HS_DAMAGE lvl) { HS_DAMAGE prev; // Store previous level prev = GetDamageLevel(); // Set current level .. we perform no error checking. m_damage_level = lvl; return prev; } char *CHSEngSystem::GetName(void) { int idx; if (!m_name) { // Search for the name in the global list for (idx = 0; hs_system_list[idx].name; idx++) { if (hs_system_list[idx].type == m_type) return hs_system_list[idx].name; } } // System not found in the list return "No Name"; } // Returns the optimal (maximum, no damage) power level for // the system. The bAdjusted variable can be set to TRUE to return // the optimal power for the current damage level. If this variable // is false, then the optimal power not including damage is returned. int CHSEngSystem::GetOptimalPower(BOOL bAdjusted) { int lvl; // Use some logic here. if (!m_optimal_power) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. lvl = 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. lvl = m_parent->GetOptimalPower(); } } else lvl = *m_optimal_power; // Calculate damage? if (bAdjusted) { lvl = (int) (lvl * (1 - (.25 * GetDamageLevel()))); } return lvl; } int CHSEngSystem::GetTolerance(void) { // Use some logic here. if (!m_tolerance) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. return m_parent->GetTolerance(); } } else return *m_tolerance; } float CHSEngSystem::GetStress(void) { return m_stress; } HSS_TYPE CHSEngSystem::GetType(void) { return m_type; } // // End value access functions // // Sets the current power level for the system. BOOL CHSEngSystem::SetCurrentPower(int level) { UINT max; max = GetOptimalPower(); // Don't allow levels below 0. Level 0 is just deactivation. if (level < 0) return FALSE; // Only allow overloading to 150%. if (level > (max * 1.5)) return FALSE; m_current_power = level; return TRUE; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSEngSystem::SetAttributeValue(char *strName, char *strValue) { int iVal; float fVal; // Match the name .. set the value if (!strcasecmp(strName, "CURRENT POWER")) { iVal = atoi(strValue); if (iVal < 0) return FALSE; m_current_power = iVal; return TRUE; } else if (!strcasecmp(strName, "DAMAGE")) { iVal = atoi(strValue); m_damage_level = (HS_DAMAGE)iVal; return TRUE; } else if (!strcasecmp(strName, "OPTIMAL POWER")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_optimal_power) { delete m_optimal_power; m_optimal_power = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_optimal_power) m_optimal_power = new int; *m_optimal_power = iVal; return TRUE; } else if (!strcasecmp(strName, "TOLERANCE")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_tolerance) { delete m_tolerance; m_tolerance = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_tolerance) m_tolerance = new int; *m_tolerance = iVal; return TRUE; } else if (!strcasecmp(strName, "STRESS")) { fVal = (float)atof(strValue); if ((fVal < 0) || (fVal > 100)) return FALSE; m_stress = fVal; return TRUE; } else if (!strcasecmp(strName, "VISIBLE")) { m_bVisible = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "NAME")) { SetName(strValue); } return FALSE; // Attr name not matched } // Returns the value of the specified attribute or NULL if // not a valid attribute. char *CHSEngSystem::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Look for the attribute *rval = '\0'; if (!strcasecmp(strName, "CURRENT POWER")) { sprintf(rval, "%d", m_current_power); } else if (!strcasecmp(strName, "DAMAGE")) { sprintf(rval, "%d", m_damage_level); } else if (!strcasecmp(strName, "OPTIMAL POWER")) { sprintf(rval, "%d", GetOptimalPower(bAdjusted)); } else if (!strcasecmp(strName, "TOLERANCE")) { sprintf(rval, "%d", GetTolerance()); } else if (!strcasecmp(strName, "STRESS")) { sprintf(rval, "%.2f", m_stress); } else return NULL; // No attribute found return rval; // Contains something, even if null. } // Outputs system information to a file. This could be // the class database or another database of objects that // contain systems. void CHSEngSystem::SaveToFile(FILE *fp) { // Output RAW values. Do not call any Get() functions, // because those will return local or parent values. We // ONLY want to output local values. if (m_name) fprintf(fp, "NAME=%s\n", m_name); if (m_tolerance) fprintf(fp, "TOLERANCE=%d\n", *m_tolerance); if (m_optimal_power) fprintf(fp, "OPTIMAL POWER=%d\n", *m_optimal_power); fprintf(fp, "STRESS=%.2f\n", m_stress); fprintf(fp, "DAMAGE=%d\n", m_damage_level); fprintf(fp, "CURRENT POWER=%d\n", m_current_power); fprintf(fp, "VISIBLE=%d\n", m_bVisible); } // // CHSSysSensors stuff // CHSSysSensors::CHSSysSensors(void) { int idx; m_type = HSS_SENSORS; m_sensor_rating = NULL; m_nContacts = 0; // Initialize contact arrays for (idx = 0; idx < HS_MAX_CONTACTS; idx++) m_contact_list[idx] = NULL; for (idx = 0; idx < HS_MAX_NEW_CONTACTS; idx++) { m_new_contacts[idx] = NULL; m_lost_contacts[idx] = NULL; } } // Outputs system information to a file. This could be // the class database or another database of objects that // contain systems. void CHSSysSensors::SaveToFile(FILE *fp) { // Call base class FIRST CHSEngSystem::SaveToFile(fp); // Ok to output, so we print out our information // specific to this system. if (m_sensor_rating) fprintf(fp, "SENSOR RATING=%d\n", *m_sensor_rating); } // Prints out system information to a player void CHSSysSensors::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); notify(player, tprintf("SENSOR RATING: %d", GetSensorRating())); } // Returns a comma-delimited list of system attributes and // values. char *CHSSysSensors::GetAttrValueString(void) { static char rval[512]; // Base information plus our's. sprintf(rval, "%s,SENSOR RATING=%d", CHSEngSystem::GetAttrValueString(), GetSensorRating()); return rval; } // This just sets the index to the first lost contact slot. // Always use GetNextLostContact() to retrieve the first and // all subsequent contacts. SENSOR_CONTACT *CHSSysSensors::GetFirstLostContact(void) { for (uContactSlot = 0; uContactSlot < HS_MAX_NEW_CONTACTS; uContactSlot++) { if (m_lost_contacts[uContactSlot]) return m_lost_contacts[uContactSlot]; } return NULL; } SENSOR_CONTACT *CHSSysSensors::GetNextLostContact(void) { while(uContactSlot < HS_MAX_NEW_CONTACTS) { if (m_lost_contacts[uContactSlot]) { uContactSlot++; return m_lost_contacts[uContactSlot-1]; } uContactSlot++; } return NULL; } // This just sets the index to the first new contact slot. // Always use GetNextNewContact() to retrieve the first and // all subsequent contacts. SENSOR_CONTACT *CHSSysSensors::GetFirstNewContact(void) { for (uContactSlot = 0; uContactSlot < HS_MAX_NEW_CONTACTS; uContactSlot++) { if (m_new_contacts[uContactSlot]) return m_new_contacts[uContactSlot]; } return NULL; } SENSOR_CONTACT *CHSSysSensors::GetNextNewContact(void) { while(uContactSlot < HS_MAX_NEW_CONTACTS) { if (m_new_contacts[uContactSlot]) { uContactSlot++; return m_new_contacts[uContactSlot-1]; } uContactSlot++; } return NULL; } void CHSSysSensors::ClearContacts(void) { int idx; // Clear out our current contact array. for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { m_contact_list[idx] = NULL; if (m_contact_list[idx]) { delete m_contact_list[idx]; m_contact_list[idx] = NULL; } } // Clear out any lost contacts that were moved // out of the current contact array. for (idx = 0; idx < HS_MAX_NEW_CONTACTS; idx++) { m_lost_contacts[idx] = NULL; if (m_lost_contacts[idx]) { delete m_lost_contacts[idx]; m_lost_contacts[idx] = NULL; } } m_nContacts = 0; } // This will handle sensor sweeping. void CHSSysSensors::DoCycle(void) { int idx; CHSUniverse *uSource; CHSObject *cObj; SENSOR_CONTACT *cContact; int iDetectLevel; // 0, 1, or 2 for how to detect it. double MyX, MyY, MyZ; double TargetX, TargetY, TargetZ; double dIdentDist, dDetectDist, dDistance; float fCloakEffect; double dOverload; // Call the base class first to handle stress CHSEngSystem::DoCycle(); // No power? Don't cycle. if (!m_current_power) { // Check to be sure the user didn't turn off power to // save sensor contacts for a later time. if (m_nContacts > 0) ClearContacts(); return; } // If we have no owner, then we're not sweeping // for contacts. if (!m_ownerObj) return; // If the owner is not active, then we're not sweeping. if (!m_ownerObj->IsActive()) { if (m_nContacts > 0) { ClearContacts(); } return; } // If we belong to a ship, and we're in hyperspace, // figure out what to do. int iDetectCap; iDetectCap = 2; // Fully sense by default if (m_ownerObj && m_ownerObj->GetType() == HST_SHIP) { CHSShip *cShip; cShip = (CHSShip *)m_ownerObj; // Figure out if we should sweep at all if (cShip->InHyperspace()) { if (HSCONF.sense_hypervessels == 0) iDetectCap = 0; else if (HSCONF.sense_hypervessels == 1) iDetectCap = 1; } } // If we have no power, don't sweep. if (m_current_power <= 0) { if (m_nContacts > 0) ClearContacts(); return; } // Calculate overload (or underload) int iOptPower = GetOptimalPower(FALSE); dOverload = m_current_power / (float)(iOptPower + .00001); // Clear out our new and lost contact arrays. for (idx = 0; idx < HS_MAX_NEW_CONTACTS; idx++) { m_new_contacts[idx] = NULL; if (m_lost_contacts[idx]) { delete m_lost_contacts[idx]; m_lost_contacts[idx] = NULL; } } // Flag all of our current contacts as unverified m_nContacts = 0; for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (m_contact_list[idx]) { m_nContacts++; m_contact_list[idx]->bVerified = FALSE; // Change updated statuses to IDENTIFIED if (m_contact_list[idx]->status == UPDATED) m_contact_list[idx]->status = IDENTIFIED; } } // Look for objects in our universe uSource = uaUniverses.FindUniverse(m_ownerObj->GetUID()); if (!uSource) return; // Run through all active objects, checking distance, // and seeing if they're on sensors. MyX = m_ownerObj->GetX(); MyY = m_ownerObj->GetY(); MyZ = m_ownerObj->GetZ(); for (idx = 0; iDetectCap && (idx < HS_MAX_ACTIVE_OBJECTS); idx++) { cObj = uSource->GetActiveUnivObject(idx); if (!cObj) continue; iDetectLevel = iDetectCap; // Sense only to our ability // Object visible? if (!cObj->IsVisible()) continue; // Is it us? if (cObj->GetDbref() == m_ownerObj->GetDbref()) continue; // Grab target coordinates TargetX = cObj->GetX(); TargetY = cObj->GetY(); TargetZ = cObj->GetZ(); // If it's a ship, check for cloaking. if (cObj->GetType() == HST_SHIP) { CHSShip *ptr; ptr = (CHSShip *)cObj; // Check if the ship is in hyperspace and // how we should handle it. if (ptr->InHyperspace()) { // Determine what to do with the // contact. if (HSCONF.sense_hypervessels == 0) continue; else if (HSCONF.sense_hypervessels == 1) iDetectLevel = 1; } // Grab cloaking effect, where 1 is complete // visibility. fCloakEffect = 1 - ptr->CloakingEffect(); } else { // Just some object fCloakEffect = 1; } // Calculate distance to object dDistance = Dist3D(MyX, MyY, MyZ, TargetX, TargetY, TargetZ); // Calculate ranges, including cloaking. dDetectDist = cObj->GetSize() / 2.0 * fCloakEffect * 1800 * GetSensorRating(); dIdentDist = cObj->GetSize() / 2.0 * fCloakEffect * 600 * GetSensorRating(); // Range is increased (or decreased) based on overloading. dDetectDist *= dOverload; dIdentDist *= dOverload; // Now see if the object is currently on sensors. cContact = GetContact(cObj); // Object out of range? if ((dDistance > dDetectDist) || (dDistance > HSCONF.max_sensor_range)) { // Do nothing. It'll get lost from sensors // simply because it hasn't been flagged // as verified. } else { // On sensors now? if (cContact) { // Check to see if we need to update its status. if ((cContact->status == DETECTED) && (dDistance <= dIdentDist) && (iDetectLevel == 2)) { UpdateContact(cContact); } // This contact is a sure bet. cContact->bVerified = TRUE; } else { // New contact // Is it immediately in identification range? if ((dDistance <= dIdentDist) && (iDetectLevel == 2)) NewContact(cObj, IDENTIFIED); else NewContact(cObj, DETECTED); m_nContacts++; } } } // Check for any unverified contacts for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (m_contact_list[idx] && (!m_contact_list[idx]->bVerified)) { LoseContact(m_contact_list[idx]); m_nContacts--; } } } // Returns the number of contacts on sensors. UINT CHSSysSensors::NumContacts(void) { return m_nContacts; } // Returns a 4-digit, random sensor id for a new contact. // This id will not match any other on sensors. UINT CHSSysSensors::RandomSensorID(void) { UINT idx; UINT num; BOOL bInUse; bInUse = TRUE; while(bInUse) { num = RandomLong(1000, 10000); bInUse = FALSE; // Make sure it's not in use for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (m_contact_list[idx] && m_contact_list[idx]->m_id == num) { bInUse = TRUE; break; } } } // It's ok. return num; } // Adds a new CHSObject to the list of contacts. void CHSSysSensors::NewContact(CHSObject *cObj, CONTACT_STATUS stat) { SENSOR_CONTACT *cNewContact; int idx; // Allocate a new contact object cNewContact = new SENSOR_CONTACT; cNewContact->m_obj = cObj; cNewContact->status = stat; cNewContact->m_id = RandomSensorID(); // Now add it to the contact list and new contact list for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (!m_contact_list[idx]) { m_contact_list[idx] = cNewContact; break; } } // Error check if (idx == HS_MAX_CONTACTS) { hs_log("WARNING: Sensor array has reached maximum number of contacts."); delete cNewContact; } // New contacts list for (idx = 0; idx < HS_MAX_NEW_CONTACTS; idx++) { if (!m_new_contacts[idx]) { m_new_contacts[idx] = cNewContact; break; } } // The contact is definitely on sensors. cNewContact->bVerified = TRUE; } // Updates the status of an existing contact to indicate // identified. This is similar to obtaining a new contact. void CHSSysSensors::UpdateContact(SENSOR_CONTACT *cContact) { int idx; cContact->status = UPDATED; // Add it to the new list. It's not really new, but // other functions can query it for the UPDATED status // to see that it's not really a new contact. for (idx = 0; idx < HS_MAX_NEW_CONTACTS; idx++) { if (!m_new_contacts[idx]) { m_new_contacts[idx] = cContact; break; } } } // Can be called externally to force the removal of an // object from sensors. void CHSSysSensors::LoseObject(CHSObject *cObj) { int idx; // Run down the contact list, looking for this object. for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (m_contact_list[idx]) { CHSObject *cTmp; cTmp = m_contact_list[idx]->m_obj; if (cTmp->GetDbref() == cObj->GetDbref()) { delete m_contact_list[idx]; m_contact_list[idx] = NULL; break; } } } } // Removes a contact from sensors and indicates that it's lost. void CHSSysSensors::LoseContact(SENSOR_CONTACT *cContact) { int idx; // Run down the contact list, looking for it. for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (m_contact_list[idx] && (m_contact_list[idx]->m_id == cContact->m_id)) { m_contact_list[idx] = NULL; break; } } // Now add it to the lost contact list for (idx = 0; idx < HS_MAX_NEW_CONTACTS; idx++) { if (!m_lost_contacts[idx]) { m_lost_contacts[idx] = cContact; break; } } } // Tries to find a sensor contact given a contact id SENSOR_CONTACT *CHSSysSensors::GetContactByID(int id) { int idx; for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (!m_contact_list[idx]) continue; if (m_contact_list[idx]->m_id == id) return m_contact_list[idx]; } // Not found return NULL; } // Tries to find a sensor contact given an object. SENSOR_CONTACT *CHSSysSensors::GetContact(CHSObject *cObj) { int idx; for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { if (!m_contact_list[idx]) continue; // Compare dbrefs if (m_contact_list[idx]->m_obj->GetDbref() == cObj->GetDbref()) return m_contact_list[idx]; } return NULL; } // Returns the sensor contact in a given array slot. SENSOR_CONTACT *CHSSysSensors::GetContact(int slot) { if ((slot < 0) || (slot >= HS_MAX_CONTACTS)) return NULL; return m_contact_list[slot]; } // A derived implementation of the Dup() in the base class. CHSEngSystem *CHSSysSensors::Dup(void) { CHSSysSensors *ptr; ptr = new CHSSysSensors; // No initialization to do. return (CHSEngSystem *) ptr; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSSysSensors::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name .. set the value if (!strcasecmp(strName, "SENSOR RATING")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_sensor_rating) { delete m_sensor_rating; m_sensor_rating = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_sensor_rating) m_sensor_rating = new int; *m_sensor_rating = iVal; return TRUE; } // Attr name not matched, so pass it to the base class return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSSysSensors::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "SENSOR RATING")) sprintf(rval, "%d", GetSensorRating()); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } UINT CHSSysSensors::GetSensorRating(void) { // Use some logic here. if (!m_sensor_rating) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { CHSSysSensors *ptr = (CHSSysSensors *)m_parent; // Yes, this system exists on a ship, so // find the default values on the parent. return ptr->GetSensorRating(); } } else return *m_sensor_rating; } // // CHSReactor implementation // CHSReactor::CHSReactor(void) { m_type = HSS_REACTOR; m_maximum_output = NULL; m_desired_output = 0; m_output = 0; // The reactor is not visible as other systems are m_bVisible = FALSE; // By default, no fuel source .. unlimited fuel m_fuel_source = NULL; } CHSReactor::~CHSReactor(void) { if (m_maximum_output) delete m_maximum_output; } void CHSReactor::SetFuelSource(CHSFuelSystem *cSource) { m_fuel_source = cSource; } // Returns the desired output setting for the reactor UINT CHSReactor::GetDesiredOutput(void) { return m_desired_output; } // Returns the current output for the reactor UINT CHSReactor::GetOutput(void) { return m_output; } // Returns the status of the reactor char *CHSReactor::GetStatus(void) { if (IsOnline()) return "Online"; else return "Offline"; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSReactor::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name .. set the value if (!strcasecmp(strName, "MAX OUTPUT")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_maximum_output) { delete m_maximum_output; m_maximum_output = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_maximum_output) m_maximum_output = new int; *m_maximum_output = iVal; return TRUE; } else if (!strcasecmp(strName, "DESIRED OUTPUT")) { iVal = atoi(strValue); m_desired_output = iVal; return TRUE; } else if (!strcasecmp(strName, "CURRENT OUTPUT")) { iVal = atoi(strValue); m_output = iVal; return TRUE; } // Attr name not matched, so pass it to the base class return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSReactor::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "MAX OUTPUT")) sprintf(rval, "%d", GetMaximumOutput(bAdjusted)); else if (!strcasecmp(strName, "DESIRED OUTPUT")) sprintf(rval, "%d", m_desired_output); else if (!strcasecmp(strName, "CURRENT OUTPUT")) sprintf(rval, "%d", m_output); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } // Prints out system information to a player void CHSReactor::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); notify(player, tprintf("MAX OUTPUT: %d", GetMaximumOutput(FALSE))); notify(player, tprintf("DESIRED OUTPUT: %d", m_desired_output)); notify(player, tprintf("CURRENT OUTPUT: %d", m_output)); } // Returns a comma-delimited list of system attributes and // values. char *CHSReactor::GetAttrValueString(void) { static char rval[512]; // Base information plus our's. sprintf(rval, "%s,MAX OUTPUT=%d,DESIRED OUTPUT=%d,CURRENT OUTPUT=%d", CHSEngSystem::GetAttrValueString(), GetMaximumOutput(FALSE), m_desired_output, m_output); return rval; } // A derived implementation of the Dup() in the base class. CHSEngSystem *CHSReactor::Dup(void) { CHSReactor *ptr; ptr = new CHSReactor; // No initialization to do. return (CHSEngSystem *) ptr; } // Outputs system information to a file. This could be // the class database or another database of objects that // contain systems. void CHSReactor::SaveToFile(FILE *fp) { // Call base class FIRST CHSEngSystem::SaveToFile(fp); // Ok to output, so we print out our information // specific to this system. if (m_maximum_output) fprintf(fp, "MAX OUTPUT=%d\n", *m_maximum_output); fprintf(fp, "DESIRED OUTPUT=%d\n", m_desired_output); fprintf(fp, "CURRENT OUTPUT=%d\n", m_output); } // Attempts to set the reactor to a given output level BOOL CHSReactor::SetOutputLevel(int level) { UINT max; max = GetMaximumOutput(); // Don't allow levels below 0. Level 0 is just deactivation. if (level < 0) return FALSE; // Only allow overloading to 150%. if (level > (max * 1.5)) return FALSE; m_desired_output = level; // If desired output is less than level, just cut // the power right to that level. Cyclic update is // only for powering up, not powering down. if (m_desired_output < m_output) { m_output = m_desired_output; } return TRUE; } // Returns the maximum output capability of the reactor, // accounting for damage that has occurred. UINT CHSReactor::GetMaximumOutput(BOOL bWithDamage) { double dmgperc; UINT uVal; // Use some logic here. if (!m_maximum_output) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { CHSReactor *ptr = (CHSReactor *)m_parent; // Yes, this system exists on a ship, so // find the default values on the parent. uVal = ptr->GetMaximumOutput(); } } else uVal = *m_maximum_output; if (bWithDamage) { // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (UINT) (uVal * dmgperc); } return uVal; } // This is overridden from the base class because reactors // work much different than other systems. We have to power // up, calculate stress based on output (not usage), etc. void CHSReactor::DoCycle(void) { UINT max; float fVal; // Check to see if we need to do anything at all. if (!m_output && !m_desired_output && !m_stress) return; // Maybe we incurred damage, so check to // see if we should cut power. Remember, we can // overload to 150%, so allow for that. max = GetMaximumOutput(); max = (UINT) (max * 1.5); // 150% allowance if (m_output > max) { // Cut power m_output = max; } // Check to see if we should increase or decrease // power output. if (m_output < m_desired_output) { if (m_output < max) { // It's ok to increase m_output++; } } else if (m_output > m_desired_output) { // Decrease output to desired level. m_output = m_desired_output; } // Calculate stress. In this case we don't // allow for 150% overload. If it's anything over // 100%, we stress it. max = GetMaximumOutput(); if ((m_output > max) || (m_stress > 0)) { // Calculate percent overload/underload. Have to // use some extra float variables here because of // some funky problems with subtracting unsigned ints. float fVal2; fVal = (float) max; fVal2 = (float)m_output; fVal2 = fVal2 - max; fVal = fVal2 / fVal; fVal *= 100; // If overloaded, tolerance hinders stress. // If underloaded, tolerance reduces stress faster. if (fVal > 0) fVal *= (float)(HS_STRESS_INCREASE / (float)GetTolerance()); else { // Make sure stress is reduced at least minimally // at 100% power allocation. if (!fVal) fVal = -1; fVal *= (float)(HS_STRESS_INCREASE * GetTolerance()); } m_stress += fVal; if (m_stress > 100) m_stress = 100; if (m_stress < 0) m_stress = 0; } // Figure out fuel usage, and consume it. if (m_fuel_source) { float fRealized; float fNeeded; // Compute fuel usage based on the ratio of consumption // The .0002778 is 1/3600.0 precomputed for speed fNeeded = (float)HSCONF.fuel_ratio; fNeeded = m_output / fNeeded; fNeeded *= (float).0002778; if (fNeeded > 0) { // Model two fuels? if (HSCONF.use_two_fuels) fRealized = m_fuel_source->ExtractFuelUnit(fNeeded, FL_REACTABLE); else fRealized = m_fuel_source->ExtractFuelUnit(fNeeded); // If the fuel realized (expended) is less than // requested, the fuel tank is "empty." Thus, // set the desired reactor power to 0. if (fRealized < fNeeded) { char tbuf[128]; sprintf(tbuf, "%s%s-%s A warning light flashes, indicating that reactable fuel supplies are depleted.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL); if (m_ownerObj) m_ownerObj->HandleMessage( tbuf, MSG_ENGINEERING, NULL); m_desired_output = 0; } } } } // Indicates if the reactor is "online" or not. This doesn't // mean whether it's powering or not. The state of being // online is whether the reactor can now begin to allocate // power to other systems. It is defined as 5% powered. BOOL CHSReactor::IsOnline(void) { UINT max; // Get max reactor output, not with damage max = GetMaximumOutput(FALSE); if (m_output >= (max * .05)) return TRUE; return FALSE; } // // CHSSysComputer stuff // CHSSysComputer::CHSSysComputer(void) { m_power_used = 0; m_type = HSS_COMPUTER; } CHSEngSystem *CHSSysComputer::Dup(void) { CHSSysComputer *ptr; ptr = new CHSSysComputer; // No initialization to do. return (CHSSysComputer *) ptr; } // Call this function to drain power from the computer // to your system. If enough power is available, TRUE // is returned, and the power is deducted from the // total power available. BOOL CHSSysComputer::DrainPower(int amt) { if ((m_power_used + amt) > m_current_power) return false; m_power_used += amt; return TRUE; } // Call this function to release power you've drained. // If you don't, the computer gets confused about how // much power is used. Kind of like a memory leak! void CHSSysComputer::ReleasePower(int amt) { m_power_used -= amt; } // Returns the surplus (or deficit) between power allocated // to the computer and power drained. If this is negative, // your system should consider releasing the power. The // computer won't do it. int CHSSysComputer::GetPowerSurplus(void) { return (m_current_power - m_power_used); } // Returns the power usage for the computer system. This // can vary depending on the owner object for the system. // For example, ships have consoles, weapons, etc. int CHSSysComputer::GetOptimalPower(BOOL bDamage) { UINT uPower; if (!m_ownerObj) return 0; // Computer requires 5 MW base power uPower = 5; // We currently only support ship computers switch(m_ownerObj->GetType()) { case HST_SHIP: uPower += TotalShipPower(); break; } return uPower; } // Support for ship objects with computers. This will // query various parts of the ship (e.g. consoles) for // power requirements. UINT CHSSysComputer::TotalShipPower(void) { UINT uPower; CHSShip *cShip; int idx; CHSConsole *cCons; cShip = (CHSShip *) m_ownerObj; uPower = 0; // Query consoles for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { cCons = cShip->GetConsole(idx); if (cCons) uPower += cCons->GetMaximumPower(); } return uPower; } // // CHSSysThrusters implementation // CHSSysThrusters::CHSSysThrusters(void) { m_turning_rate = NULL; m_type = HSS_THRUSTERS; } CHSSysThrusters::~CHSSysThrusters(void) { if (m_turning_rate) delete m_turning_rate; } // Prints out system information to a player void CHSSysThrusters::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); notify(player, tprintf("TURNING RATE: %d", GetRate(FALSE))); } // Returns a comma-delimited list of system attributes and // values. char *CHSSysThrusters::GetAttrValueString(void) { static char rval[512]; // Base information plus our's. sprintf(rval, "%s,TURNING RATE=%d", CHSEngSystem::GetAttrValueString(), GetRate(FALSE)); return rval; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSSysThrusters::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name .. set the value if (!strcasecmp(strName, "TURNING RATE")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_turning_rate) { delete m_turning_rate; m_turning_rate = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_turning_rate) m_turning_rate = new int; *m_turning_rate = iVal; return TRUE; } // Attr name not matched, so pass it to the base class return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSSysThrusters::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "TURNING RATE")) sprintf(rval, "%d", GetRate(bAdjusted)); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } // A derived implementation of the Dup() in the base class. CHSEngSystem *CHSSysThrusters::Dup(void) { CHSSysThrusters *ptr; ptr = new CHSSysThrusters; // No initialization to do. return (CHSEngSystem *) ptr; } // Returns the turning rate for the thrusters system. If bAdjusted // is set to false, then the maximum raw turning rate is returned, // otherwise, it is adjusted for damage and power levels. UINT CHSSysThrusters::GetRate(BOOL bAdjusted) { double dmgperc; CHSSysThrusters *ptr; UINT uVal; int iOptPower; // Use some logic here. if (!m_turning_rate) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysThrusters *)m_parent; uVal = ptr->GetRate(FALSE); } } else uVal = *m_turning_rate; // Make overloading and damage adjustments? if (bAdjusted) { float fVal; iOptPower = GetOptimalPower(FALSE); fVal = (float)m_current_power; fVal /= (float)iOptPower; uVal = (UINT) (uVal * fVal); // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (UINT) (uVal * dmgperc); } return uVal; } // Outputs system information to a file. This could be // the class database or another database of objects that // contain systems. void CHSSysThrusters::SaveToFile(FILE *fp) { // Call base class FIRST CHSEngSystem::SaveToFile(fp); // Now output our local values. if (m_turning_rate) fprintf(fp, "TURNING RATE=%d\n", *m_turning_rate); } // // CHSSysLifeSupport Stuff // CHSSysLifeSupport::CHSSysLifeSupport(void) { m_type = HSS_LIFE_SUPPORT; // Initially 100% air left m_perc_air = 100; } CHSEngSystem *CHSSysLifeSupport::Dup(void) { CHSSysLifeSupport *ptr; ptr = new CHSSysLifeSupport; // No initialization to do. return (CHSEngSystem *) ptr; } // The DoCycle() for life support will handle increasing or // decreasing life support percentages (e.g. air). void CHSSysLifeSupport::DoCycle(void) { double dLifePerc; // Do base cycle stuff CHSEngSystem::DoCycle(); // Based on power availability, determine what // percentage of life support should be maintained. dLifePerc = (double)GetOptimalPower() + .00001; dLifePerc = (m_current_power / dLifePerc) * 100; // Handle life support goodies if (m_perc_air < dLifePerc) { // Increase air availability by 1 percent m_perc_air += 1; // Did we increase too much? if (m_perc_air > dLifePerc) m_perc_air = (float)dLifePerc; } else if (m_perc_air > dLifePerc) { // Decrease air availability by 1/3 percent because // of people breathing. m_perc_air = (float) (m_perc_air - .33333); // Did we decrease too much? if (m_perc_air < dLifePerc) m_perc_air = (float)dLifePerc; } } // Returns the current 0 - 100 percentage of air in the system double CHSSysLifeSupport::GetAirLeft(void) { return m_perc_air; } // // CHSSysShield stuff // CHSSysShield::CHSSysShield(void) { m_type = HSS_FORE_SHIELD; m_shield_type = ST_ABSORPTION; // Might as well choose a default m_strength = 0; m_max_strength = NULL; m_regen_rate = NULL; } CHSEngSystem *CHSSysShield::Dup(void) { CHSSysShield *ptr; ptr = new CHSSysShield; ptr->m_shield_type = m_shield_type; ptr->m_type = m_type; // Needs to be set for shield location // No initialization to do. return (CHSEngSystem *) ptr; } void CHSSysShield::DoCycle(void) { double rate; int max; // Do base stuff first CHSEngSystem::DoCycle(); // Do anything? if (!m_current_power) return; // Depending on the type of shield, we have // to do different things. if (m_shield_type == ST_ABSORPTION) { // Regen if we have power. rate = GetRegenRate(); max = (int)GetMaxStrength(); if ((m_strength < max) && (rate > 0)) { // Increase by the given point rate m_strength += rate; if (m_strength > max) m_strength = max; } } // Don't do anything for deflector shields } // Does damage to the shield (maybe), and returns the number // of points not handled by the shield. UINT CHSSysShield::DoDamage(int iPts) { int rval; // What type of shield are we? if (m_shield_type == ST_DEFLECTOR) { // Subtract our shield strength from the damage // points. rval = iPts - m_strength; if (rval < 0) rval = 0; return rval; } else if (m_shield_type == ST_ABSORPTION) { // Knock off points from the shields. m_strength -= iPts; // If the strength has gone negative, that means // the damage points were too much for the shield // to handle. Thus, return the absolute value of // the shield strength, and set it to zero. if (m_strength < 0) { rval = (int)(m_strength * -1); m_strength = 0; return rval; } else return 0; } // Who knows what type of shield we are. Let's just // say we have none. return iPts; } // Returns the type of shield. HS_SHIELDTYPE CHSSysShield::GetShieldType(void) { return m_shield_type; } void CHSSysShield::SaveToFile(FILE *fp) { // Call base class next CHSEngSystem::SaveToFile(fp); // Ok to output, so we print out our information // specific to this system. fprintf(fp, "SHIELD TYPE=%d\n", (int)m_shield_type); fprintf(fp, "STRENGTH=%.2f\n", m_strength); if (m_regen_rate) fprintf(fp, "REGEN RATE=%.4f\n", *m_regen_rate); if (m_max_strength) fprintf(fp, "MAX STRENGTH=%.2f\n", *m_max_strength); } // Returns the regen rate for the shield system. If bAdjusted // is set to false, then the maximum regen rate is returned, // otherwise, it is adjusted for damage and power levels. // Rates are stored as points per second. double CHSSysShield::GetRegenRate(BOOL bAdjusted) { double dmgperc; CHSSysShield *ptr; double rate; int iOptPower; // Use some logic here. if (!m_regen_rate) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysShield *)m_parent; rate = ptr->GetRegenRate(FALSE); } } else rate = *m_regen_rate; // Make overloading and damage adjustments? if (bAdjusted) { float fVal; iOptPower = GetOptimalPower(FALSE); fVal = (float)m_current_power; fVal /= (float)iOptPower; rate *= fVal; // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); rate = (rate * dmgperc); } return rate; } // Returns the current shield percentage from 0 - 100. double CHSSysShield::GetShieldPerc(void) { double perc; // If we don't have at least 1 MW charge, shields are // down. if (m_current_power <= 0) return 0; perc = GetMaxStrength() + .00001; perc = m_strength / perc; perc *= 100; return (perc); } // Returns the maximum strength of the shield. There is NO // adjustment that can be made to this. The shield regenerators // ALWAYS recharge to full value, just maybe more slowly if damaged. double CHSSysShield::GetMaxStrength(void) { CHSSysShield *ptr; // Use some logic here. if (!m_max_strength) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysShield *)m_parent; return (ptr->GetMaxStrength()); } } else return (*m_max_strength); } // Prints out system information to a player void CHSSysShield::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); notify(player, tprintf("REGEN RATE: %.2f", GetRegenRate(FALSE))); notify(player, tprintf("STRENGTH: %.0f", m_strength)); notify(player, tprintf("MAX STRENGTH: %.0f", GetMaxStrength())); notify(player, tprintf("SHIELD TYPE: %s (%d)", m_shield_type == ST_DEFLECTOR ? "Deflector" : "Absorption", m_shield_type)); } // Returns a comma-delimited list of system attributes and // values. char *CHSSysShield::GetAttrValueString(void) { static char rval[512]; // Base information plus our's. sprintf(rval, "%s,REGEN RATE=%.2f,STRENGTH=%.2f,MAX STRENGTH=%.2f,SHIELD TYPE=%d", CHSEngSystem::GetAttrValueString(), GetRegenRate(FALSE), m_strength, GetMaxStrength(), m_shield_type); return rval; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSSysShield::SetAttributeValue(char *strName, char *strValue) { int iVal; double dVal; // Match the name .. set the value if (!strcasecmp(strName, "REGEN RATE")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_regen_rate) { delete m_regen_rate; m_regen_rate = NULL; return TRUE; } return FALSE; } dVal = atof(strValue); if (dVal < 0) return FALSE; if (!m_regen_rate) m_regen_rate = new double; *m_regen_rate = dVal; return TRUE; } else if (!strcasecmp(strName, "STRENGTH")) { dVal = atof(strValue); if (dVal < 0) return FALSE; m_strength = dVal; return TRUE; } else if (!strcasecmp(strName, "SHIELD TYPE")) { iVal = atoi(strValue); if (iVal != 0 && iVal != 1) return FALSE; m_shield_type = (HS_SHIELDTYPE)iVal; return TRUE; } else if (!strcasecmp(strName, "MAX STRENGTH")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_max_strength) { delete m_max_strength; m_max_strength = NULL; return TRUE; } return FALSE; } dVal = atoi(strValue); if (dVal < 0) return FALSE; if (!m_max_strength) m_max_strength = new double; *m_max_strength = dVal; return TRUE; } // Attr name not matched, so pass it to the base class return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSSysShield::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "REGEN RATE")) sprintf(rval, "%.2f", GetRegenRate(bAdjusted)); else if (!strcasecmp(strName, "STRENGTH")) sprintf(rval, "%.2f", m_strength); else if (!strcasecmp(strName, "SHIELD TYPE")) sprintf(rval, "%d", m_shield_type); else if (!strcasecmp(strName, "MAX STRENGTH")) sprintf(rval, "%.2f", GetMaxStrength()); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } // We override the SetCurrentPower() function so that we can // do different types of shield things. BOOL CHSSysShield::SetCurrentPower(int level) { UINT max; max = GetOptimalPower(); // Don't allow levels below 0. Level 0 is just deactivation. if (level < 0) return FALSE; // Only allow overloading to 150%. if (level > (max * 1.5)) return FALSE; m_current_power = level; // Now, depending on the type of shield we are, set // the strength. if (m_shield_type == ST_DEFLECTOR) { double dPerc; // Grab the absolute maximum power level dPerc = GetOptimalPower(FALSE); dPerc = m_current_power / dPerc; // Deflector shield strength is determined by // maximum possible strength multiplied by current // power settings. If shield generators get damaged, // this doesn't allow as much power to be allocated, // and thus results in less shield strength. m_strength = GetMaxStrength() * dPerc; } // Don't do anything for absorption shields. return TRUE; } // // CHSSysComm implementation // CHSSysComm::CHSSysComm(void) { m_comm_range = NULL; m_type = HSS_COMM; } CHSSysComm::~CHSSysComm(void) { if (m_comm_range) delete m_comm_range; } // Prints out system information to a player void CHSSysComm::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); notify(player, tprintf("MAX RANGE: %d", GetMaxRange(FALSE))); } // Returns a comma-delimited list of system attributes and // values. char *CHSSysComm::GetAttrValueString(void) { static char rval[512]; // Base information plus our's. sprintf(rval, "%s,MAX RANGE=%d", CHSEngSystem::GetAttrValueString(), GetMaxRange(FALSE)); return rval; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSSysComm::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name .. set the value if (!strcasecmp(strName, "MAX RANGE")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_comm_range) { delete m_comm_range; m_comm_range = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_comm_range) m_comm_range = new UINT; *m_comm_range = iVal; return TRUE; } // Attr name not matched, so pass it to the base class return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSSysComm::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "MAX RANGE")) sprintf(rval, "%d", GetMaxRange(bAdjusted)); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } // A derived implementation of the Dup() in the base class. CHSEngSystem *CHSSysComm::Dup(void) { CHSSysComm *ptr; ptr = new CHSSysComm; // No initialization to do. return (CHSEngSystem *) ptr; } // Returns the maximum transmission range for the system. If bAdjusted // is set to false, then the maximum raw turning rate is returned, // otherwise, it is adjusted for damage and power levels. UINT CHSSysComm::GetMaxRange(BOOL bAdjusted) { double dmgperc; CHSSysComm *ptr; UINT uVal; int iOptPower; // Use some logic here. if (!m_comm_range) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysComm *)m_parent; uVal = ptr->GetMaxRange(FALSE); } } else uVal = *m_comm_range; // Make overloading and damage adjustments? No need // to figure in damage, cause that's figured into // optimal power and overloading. If they overload // a damaged system, it stresses, so we just need to // check current power over undamaged optimal power. if (bAdjusted) { float fVal; iOptPower = GetOptimalPower(FALSE); fVal = (float)m_current_power; fVal /= (float)iOptPower; uVal = (UINT) (uVal * fVal); } return uVal; } // Outputs system information to a file. This could be // the class database or another database of objects that // contain systems. void CHSSysComm::SaveToFile(FILE *fp) { // Call base class FIRST CHSEngSystem::SaveToFile(fp); // Now output our local values. if (m_comm_range) fprintf(fp, "MAX RANGE=%d\n", *m_comm_range); } src/hspace/hseng.h 100644 767 767 27542 7141305141 12316 0 ustar mux mux #ifndef __HSENG_INCLUDED__ #define __HSENG_INCLUDED__ #include "hstypes.h" #include <stdio.h> class CHSObject; // Types of systems. If you add a new system, you'll want // to add it's type here so that the system array can search // for it by ID. You'll also have to add support for it in // the CHSSystemArray class for creating a new system of that // type. And, of course, you'll have to add support for it // wherever you want it to work in the code. enum HSS_TYPE { HSS_ENGINES = 0, HSS_COMPUTER, HSS_SENSORS, HSS_LIFE_SUPPORT, HSS_REACTOR, HSS_THRUSTERS, HSS_FORE_SHIELD, HSS_AFT_SHIELD, HSS_STARBOARD_SHIELD, HSS_PORT_SHIELD, HSS_FUEL_SYSTEM, HSS_JUMP_DRIVE, HSS_COMM, HSS_NOTYPE }; extern char *hsGetEngSystemName(int); extern HSS_TYPE hsGetEngSystemType(char *); // Used to indicate how much damage a system has enum HS_DAMAGE { DMG_NONE = 0, DMG_LIGHT, DMG_MEDIUM, DMG_HEAVY, DMG_INOPERABLE }; // This is the percent of stress increase per cycle per percent // overload. So if you overload systems by 1%, then stress // increases .012% per cycle up to 100% stress. If you overload // 150%, then it increases .6% each cycle, which gives you about // 2.8 minutes of heavy overloading before full system stress, // assuming cycles are 1 second intervals. As tolerance increases, // though, the stress increases more slow. In fact, it's divided // by tolerance, so the above information applies only for a tolerance // of 1. #define HS_STRESS_INCREASE .012 // A specific system, though general, that will // be contained in the system array. Systems can be // derived from this base type. class CHSEngSystem { public: CHSEngSystem(void); ~CHSEngSystem(void); // This function MUST be implemented in any class you // derive from it. It allows the SystemArray duplicator // to clone systems without having to know their types. virtual CHSEngSystem *Dup(void); // If you're deriving an object from this base class, // you should implement this function. That's only // if you want the classdb to contain default information // for your system on the ship classes. If not, then // you need to have your object constructor initialize // your variables to something meaningful, cause the // classdb loader won't do it without this function. virtual void SaveToFile(FILE *); // This doesn't have to be overloaded, but if you're // providing any strange name handling for your system, // you can override it to return the system name. virtual char *GetName(void); // If your system has any specific variables not covered // by this generic CHSEngSystem, you'll need to implement // this in your derived class to handle setting those // variables, especially when the system gets loaded // from the DB. virtual BOOL SetAttributeValue(char *, char *); // Override this to provide information about variables // specific to your system. Refer to one of the other, // standard systems for implementation examples. virtual char *GetAttributeValue(char *, BOOL); // If you're doing any cyclic stuff that is different // from the cycle in CHSEngSystem, you'll want to // implement this function in your derived class. Typically, // you'll call CHSEngSystem::DoCycle() in your overridden // function to handle stress and such, but you don't have to. virtual void DoCycle(void); // You can override this in your derived class to // return optimal power in a different way than normal. virtual int GetOptimalPower(BOOL bAdjusted = TRUE); // You can override this to provide custom status information // for your derived system. virtual char *GetStatus(void); // You can override this to handle anything specific to // your system when the power level is changed. The // basic CHSEngSystem just does some error checking and // sets the power. virtual BOOL SetCurrentPower(int); // Override this in your derived class to print out // current system information such as max values. // The only parameter passed to this function is a // player dbref to print to. virtual void GiveSystemInfo(int); // Override this to provide a string containing // a delimited list of attribute names and values for // the system. virtual char *GetAttrValueString(void); // These functions are not overridable. BOOL IsVisible(void); void SetName(char *); void SetOwner(CHSObject *); void SetType(HSS_TYPE); void SetNext(CHSEngSystem *); void SetPrev(CHSEngSystem *); void SetParentSystem(CHSEngSystem *); // Indicates a default // parent system with vals. int GetCurrentPower(void); int GetTolerance(void); float GetStress(void); HSS_TYPE GetType(void); HS_DAMAGE GetDamageLevel(void); HS_DAMAGE DoDamage(void); HS_DAMAGE ReduceDamage(HS_DAMAGE lvl); HS_DAMAGE ReduceDamage(void); CHSEngSystem *GetPrev(void); CHSEngSystem *GetNext(void); protected: HSS_TYPE m_type; BOOL m_bVisible; // Users can see it in the list and use it. char *m_name; // System name CHSObject *m_ownerObj; // Indicates the CHSObject owning the system // These variables are defined as pointers. Why? Well, // that's so we can override them specifically at the ship // level. When a system tries to return a value to a calling // function, it checks to see if these variables are NULL. If // so, it returns the default value from the class for that // ship. Otherwise, we have no way of knowing whether a variable // is overridden on the ship or not. int *m_optimal_power; // Optimal power to allocate int *m_tolerance; // How quickly the system stresses (1 .. n) // Variables used locally float m_stress; // 0 - 100 for amount of stress incurred int m_current_power; // Power allocated HS_DAMAGE m_damage_level; // Current damage level CHSEngSystem *m_parent; // Parent system to retrieve default vals. CHSEngSystem *m_next; // Ptrs for the linked list CHSEngSystem *m_prev; // implementation. void CheckSystemPower(void); // Prevents inadvertent overloading }; // A sensor contact, stored in the sensor system enum CONTACT_STATUS { UPDATED = 0, // It was detected, now identified DETECTED, // Only detected IDENTIFIED, // Instantly detected AND identified }; typedef struct { UINT m_id; // Contact number CHSObject *m_obj; BOOL bVerified; // Used each cycle to indicate object still on sensors CONTACT_STATUS status; }SENSOR_CONTACT; #define HS_MAX_CONTACTS 40 #define HS_MAX_NEW_CONTACTS 20 // A system specifically for sensors, derived from // the base CHSEngSystem class. This class handles the // list of contacts currently on sensors. class CHSSysSensors : public CHSEngSystem { public: CHSSysSensors(void); ~CHSSysSensors(void); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); UINT GetSensorRating(void); UINT NumContacts(void); void SaveToFile(FILE *); void DoCycle(void); void ClearContacts(void); void GiveSystemInfo(int); char *GetAttrValueString(void); void LoseObject(CHSObject *); SENSOR_CONTACT *GetFirstNewContact(void); SENSOR_CONTACT *GetNextNewContact(void); SENSOR_CONTACT *GetFirstLostContact(void); SENSOR_CONTACT *GetNextLostContact(void); SENSOR_CONTACT *GetContact(int); // Retrieves by slot SENSOR_CONTACT *GetContact(CHSObject *); // Retrieves by object SENSOR_CONTACT *GetContactByID(int); // Retrives by ID CHSEngSystem *Dup(void); protected: // Methods void NewContact(CHSObject *, CONTACT_STATUS); void UpdateContact(SENSOR_CONTACT *); void LoseContact(SENSOR_CONTACT *); UINT RandomSensorID(void); // Overridable variables at the ship level int *m_sensor_rating; SENSOR_CONTACT *m_contact_list[HS_MAX_CONTACTS]; // Contact list // Stores new contacts SENSOR_CONTACT *m_new_contacts[HS_MAX_NEW_CONTACTS]; SENSOR_CONTACT *m_lost_contacts[HS_MAX_NEW_CONTACTS]; // Index to the current sensor contact slot being queried UINT uContactSlot; UINT m_nContacts; }; // Thrusters, which control steering for the ship. class CHSSysThrusters : public CHSEngSystem { public: CHSSysThrusters(void); ~CHSSysThrusters(void); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); UINT GetRate(BOOL bAdjusted = TRUE); void SaveToFile(FILE *); void GiveSystemInfo(int); char *GetAttrValueString(void); CHSEngSystem *Dup(void); protected: int *m_turning_rate; }; // The computer system, which handles a lot of internal // ship power allocation and information handling. class CHSSysComputer : public CHSEngSystem { public: CHSSysComputer(void); int GetOptimalPower(BOOL bDamage = TRUE); int GetPowerSurplus(void); BOOL DrainPower(int); void ReleasePower(int); CHSEngSystem *Dup(void); protected: int m_power_used; UINT TotalShipPower(void); }; // An array of systems that can exist for a ship. // In fact, the systems are stored in a linked list. class CHSSystemArray { public: CHSSystemArray(void); BOOL AddSystem(CHSEngSystem *); void operator =(CHSSystemArray &); // Duplicates this array void DoCycle(void); void UpdatePowerUse(void); void SaveToFile(FILE *); BOOL BumpSystem(CHSEngSystem *, int); UINT GetPowerUse(void); UINT NumSystems(void); CHSEngSystem *NewSystem(HSS_TYPE); CHSEngSystem *GetSystem(HSS_TYPE); CHSEngSystem *GetSystemByName(char *); CHSEngSystem *GetHead(void); CHSEngSystem *GetRandomSystem(void); protected: CHSEngSystem *m_SystemHead; CHSEngSystem *m_SystemTail; UINT m_nSystems; UINT m_uPowerUse; }; // The life support system, which provides life supporting // goodies to a vessel. class CHSSysLifeSupport : public CHSEngSystem { public: CHSSysLifeSupport(void); CHSEngSystem *Dup(void); void DoCycle(void); double GetAirLeft(void); protected: float m_perc_air; // Amount of air in the vessel }; // There are currently two types of shields. These are // their enums enum HS_SHIELDTYPE { ST_DEFLECTOR = 0, ST_ABSORPTION }; // The shield class. class CHSSysShield : public CHSEngSystem { public: CHSSysShield(void); CHSEngSystem *Dup(void); HS_SHIELDTYPE GetShieldType(void); UINT DoDamage(int); void DoCycle(void); void SaveToFile(FILE *); void GiveSystemInfo(int); char *GetAttrValueString(void); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); BOOL SetCurrentPower(int); double GetMaxStrength(void); double GetRegenRate(BOOL bAdjusted = TRUE); double GetShieldPerc(void); protected: double *m_max_strength; double m_strength; double *m_regen_rate; HS_SHIELDTYPE m_shield_type; // Type of shield }; class CHSFuelSystem; // The HSpace Reactor Class. Power me up, Scotty! // This object is found on ships to supply power that // can be transferred to various systems. It is actually // a sort of system because it's derived from CHSEngSystem, // but we'll ultimately use it differently. It will provide // power, not consume it. class CHSReactor : public CHSEngSystem { public: CHSReactor(void); ~CHSReactor(void); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); BOOL SetOutputLevel(int); BOOL IsOnline(void); UINT GetOutput(void); UINT GetDesiredOutput(void); UINT GetMaximumOutput(BOOL bWithDamage = TRUE); void SaveToFile(FILE *); void DoCycle(void); // Overridden from base class void SetFuelSource(CHSFuelSystem *); void GiveSystemInfo(int); char *GetAttrValueString(void); char *GetStatus(void); CHSEngSystem *Dup(void); protected: UINT m_output; // Power output UINT m_desired_output; // Desired output level // These variables are overridable at the ship level int *m_maximum_output; // Maximum operating level CHSFuelSystem *m_fuel_source; // Optional fuel source }; // The communications system simply indicates if the // parent object can receive and transmit. class CHSSysComm : public CHSEngSystem { public: CHSSysComm(void); ~CHSSysComm(void); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); UINT GetMaxRange(BOOL bAdjusted = TRUE); void SaveToFile(FILE *); void GiveSystemInfo(int); char *GetAttrValueString(void); CHSEngSystem *Dup(void); protected: UINT *m_comm_range; }; #endif // __HSENG_INCLUDED__ src/hspace/hsengcmds.cpp 100664 767 767 7457 7141305141 13505 0 ustar mux mux #include "hscopyright.h" #include "hscmds.h" #include "hsdb.h" #include "hseng.h" #include "hsinterface.h" #include "hsutils.h" #include <stdlib.h> HSPACE_COMMAND_PROTO(hscSetSystemPower) HSPACE_COMMAND_PROTO(hscSystemReport) HSPACE_COMMAND_PROTO(hscSetSystemPriority) HSPACE_COMMAND_PROTO(hscShipStats) #ifdef MUX NAMETAB hsEng_sw[] = { {(char *)"setsyspower", 2, CA_PUBLIC, 1}, {(char *)"shipstats", 2, CA_PUBLIC, 2}, {(char *)"systemreport", 7, CA_PUBLIC, 3}, {(char *)"systempriority", 7, CA_PUBLIC, 4}, {NULL, 0, 0, 0} }; hs_command hEngCommands[] = { NULL, hscSetSystemPower, hscShipStats, hscSystemReport, hscSetSystemPriority }; #endif #ifdef PENNMUSH // The hsCommandArray holds all externally callable @eng commands. HSPACE_COMMAND hsEngCommandArray[] = { "SETSYSPOWER", hscSetSystemPower, HCP_ANY, "SHIPSTATS", hscShipStats, HCP_ANY, "SYSTEMREPORT", hscSystemReport, HCP_ANY, "SYSTEMPRIORITY", hscSetSystemPriority, HCP_ANY, NULL, NULL, 0 }; #endif HSPACE_COMMAND_HDR(hscSetSystemPower) { dbref dbUser; CHSShip *cShip; int iLvl; // arg_left is the system name // arg_right is the level to set // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } if (!arg_left || !*arg_left || !arg_right || !*arg_right) { hsStdError(dbUser, "You must specify both a system name and power level."); return; } iLvl = atoi(arg_right); if (arg_right[strlen(arg_right)-1] == '%') cShip->SetSystemPower(dbUser, arg_left, iLvl, TRUE); else cShip->SetSystemPower(dbUser, arg_left, iLvl, FALSE); } HSPACE_COMMAND_HDR(hscSystemReport) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } cShip->GiveEngSysReport(dbUser); } HSPACE_COMMAND_HDR(hscSetSystemPriority) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } if (!arg_left || !*arg_left || !arg_right || !*arg_right) { hsStdError(dbUser, "You must specify both a system name and priority change."); return; } cShip->ChangeSystemPriority(dbUser, arg_left, atoi(arg_right)); } HSPACE_COMMAND_HDR(hscShipStats) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } cShip->GiveVesselStats(dbUser); } src/hspace/hsengines.cpp 100644 767 767 51067 7141305141 13527 0 ustar mux mux #include "hscopyright.h" #include "hsengines.h" #include "hsobjects.h" #include "hspace.h" #include "hsexterns.h" #include "hsconf.h" #include <stdlib.h> #ifndef WIN32 #include <strings.h> #endif CHSSysEngines::CHSSysEngines(void) { m_type = HSS_ENGINES; m_max_velocity = NULL; m_acceleration = NULL; m_efficiency = NULL; m_current_speed = 0; m_desired_speed = 0; m_fuel_source = NULL; m_can_afterburn = NULL; m_afterburning = FALSE; } // Destructor CHSSysEngines::~CHSSysEngines(void) { // Free up our variables if (m_max_velocity) delete m_max_velocity; if (m_acceleration) delete m_acceleration; if (m_efficiency) delete m_efficiency; if (m_can_afterburn) delete m_can_afterburn; } // Sets a specific attribute value for the system. This // also allows system default values to be overridden at the // ship level. BOOL CHSSysEngines::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name .. set the value if (!strcasecmp(strName, "MAX VELOCITY")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_max_velocity) { delete m_max_velocity; m_max_velocity = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_max_velocity) m_max_velocity = new int; *m_max_velocity = iVal; return TRUE; } else if (!strcasecmp(strName, "ACCELERATION")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_acceleration) { delete m_acceleration; m_acceleration = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_acceleration) m_acceleration = new int; *m_acceleration = iVal; return TRUE; } else if (!strcasecmp(strName, "DESIRED SPEED")) { m_desired_speed = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "CURRENT SPEED")) { m_current_speed = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "CAN AFTERBURN")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_can_afterburn) { delete m_can_afterburn; m_can_afterburn = NULL; return TRUE; } return FALSE; } if (!m_can_afterburn) m_can_afterburn = new BOOL; *m_can_afterburn = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "AFTERBURNING")) { m_afterburning = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "EFFICIENCY")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_efficiency) { delete m_efficiency; m_efficiency = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (iVal < 0) return FALSE; if (!m_efficiency) m_efficiency = new int; *m_efficiency = iVal; return TRUE; } // Attr name not matched, so pass it to the base class return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSSysEngines::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "MAX VELOCITY")) sprintf(rval, "%d", GetMaxVelocity(bAdjusted)); else if (!strcasecmp(strName, "ACCELERATION")) sprintf(rval, "%d", GetAcceleration(bAdjusted)); else if (!strcasecmp(strName, "DESIRED SPEED")) sprintf(rval, "%.2f", m_desired_speed); else if (!strcasecmp(strName, "CURRENT SPEED")) sprintf(rval, "%.2f", m_current_speed); else if (!strcasecmp(strName, "CAN AFTERBURN")) sprintf(rval, "%d", CanBurn()); else if (!strcasecmp(strName, "AFTERBURNING")) sprintf(rval, "%d", GetAfterburning()); else if (!strcasecmp(strName, "EFFICIENCY")) sprintf(rval, "%d", GetEfficiency()); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } // Prints out system information to the specified player void CHSSysEngines::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); // Now our info notify(player, tprintf("MAX VELOCITY: %d", GetMaxVelocity(FALSE))); notify(player, tprintf("ACCELERATION: %d", GetAcceleration(FALSE))); notify(player, tprintf("DESIRED SPEED: %.0f", m_desired_speed)); notify(player, tprintf("CURRENT SPEED: %.0f", m_current_speed)); notify(player, tprintf("CAN AFTERBURN: %s", CanBurn() ? "YES" : "NO")); notify(player, tprintf("AFTERBURNING : %s", GetAfterburning() ? "YES" : "NO")); notify(player, tprintf("EFFICIENCY : %d", GetEfficiency())); } // Returns the current speed (thrust) of the engines double CHSSysEngines::GetCurrentSpeed(void) { return m_current_speed; } // Indicates whether the engines are afterburning or not BOOL CHSSysEngines::GetAfterburning(void) { return m_afterburning; } // Indicates whether the engines are capable of afterburning // or not. BOOL CHSSysEngines::CanBurn(void) { // Do we have a local value? if (!m_can_afterburn) { // No local value. Do we have a parent? if (!m_parent) return FALSE; // Get the parent's value. CHSSysEngines *ptr; ptr = (CHSSysEngines *)m_parent; return ptr->CanBurn(); } else return *m_can_afterburn; } // Sets the burn/no-burn status of the engine afterburners. BOOL CHSSysEngines::SetAfterburn(BOOL bStat) { UINT uMax; if (!CanBurn()) return FALSE; uMax = GetMaxVelocity(); if (bStat) { m_desired_speed = uMax * HSCONF.afterburn_ratio; m_afterburning = TRUE; } else { m_afterburning = FALSE; m_desired_speed = uMax; } return TRUE; } // Sets the desired speed of the engines BOOL CHSSysEngines::SetDesiredSpeed(int speed) { int iMaxVelocity; iMaxVelocity = GetMaxVelocity(); if ((speed > iMaxVelocity) || (speed < (-1 * (iMaxVelocity / 2.0)))) { return FALSE; } // If desired speed is 0, turn off afterburners if (speed == 0) SetAfterburn(FALSE); m_desired_speed = (double)speed; return TRUE; } // Returns the current, desired speed of the engines double CHSSysEngines::GetDesiredSpeed(void) { return m_desired_speed; } // Handles cyclic stuff for engines void CHSSysEngines::DoCycle(void) { int iFuel; // Do base class stuff first CHSEngSystem::DoCycle(); // Do anything? if (!m_current_speed && !m_current_power) return; // Change our speed if needed ChangeSpeed(); // Consume fuel. Yummy. if (m_current_speed) { iFuel = m_current_speed; if (GetAfterburning()) iFuel *= HSCONF.afterburn_fuel_ratio; ConsumeFuelBySpeed((int)m_current_speed); } } // Handles slowing or speeding up the engines void CHSSysEngines::ChangeSpeed(void) { UINT uMax; UINT uAccel; // Grab maximum velocity uMax = GetMaxVelocity(); // If afterburning, max is increased by some // ratio. if (m_afterburning) uMax *= HSCONF.afterburn_ratio; // Make sure the desired speed doesn't currently // exceed the maximum speed limits. if (m_desired_speed > uMax) { m_desired_speed = uMax; } else if (m_desired_speed < (uMax * -.5)) { m_desired_speed = uMax * -.5; } // This has to come after the checking of uMax. Otherwise, // the ship could be at top speed, power is taken away from // engines, but the speed doesn't change because the desired // and current speed are already equal. if (m_desired_speed == m_current_speed) return; // Change the speed closer to the desired speed if (m_current_speed > m_desired_speed) { // Grab deceleration rate, which is always the // same as maximum acceleration. Deceleration is // not affected by engine damage or power. uAccel = GetAcceleration(FALSE); m_current_speed -= uAccel; // Did we go too far? if (m_current_speed < m_desired_speed) m_current_speed = m_desired_speed; } else if (m_current_speed < m_desired_speed) { // Grab the acceleration rate, which is affected // by power and damage. uAccel = GetAcceleration(TRUE); m_current_speed += uAccel; // Did we go too far? if (m_current_speed > m_desired_speed) m_current_speed = m_desired_speed; } } // Tells the engines that they need to gobble up some fuel // from the fuel source. The engines know their efficiency // and such, so they just drain the fuel from the fuel system. // Speed here should be given in units per hour. void CHSSysEngines::ConsumeFuelBySpeed(int speed) { float fConsume; float fRealized; // Do we have a fuel system? if (!m_fuel_source || (m_fuel_source->GetFuelRemaining() <= 0)) return; // Calculate per second travel rate fConsume = (float) (speed * .0002778); // Divide by efficiency fConsume = (float)(fConsume / (1000.0 * GetEfficiency())); fRealized = m_fuel_source->ExtractFuelUnit(fConsume); if (fRealized < fConsume) { // Out of gas. Set desired speed to 0. m_desired_speed = 0; char tbuf[128]; sprintf(tbuf, "%s%s-%s A warning light flashing, indicating engines have run out of fuel.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL); if (m_ownerObj) m_ownerObj->HandleMessage(tbuf, MSG_ENGINEERING, NULL); } } // Sets the fuel system source for the engines. If this // is NULL, engines don't consume fuel .. duh. void CHSSysEngines::SetFuelSource(CHSFuelSystem *cFuel) { m_fuel_source = cFuel; } // Returns the efficiency of the engines, which is a // number specifying thousands of units of distance travel // per unit of fuel consumption .. just like gas mileage on // a car. For example 1000km/gallon. This would be returned // here as just 1. int CHSSysEngines::GetEfficiency(void) { // Do we have a local value? if (!m_efficiency) { // Do we have a parent? if (m_parent) { CHSSysEngines *ptr; ptr = (CHSSysEngines *)m_parent; return ptr->GetEfficiency(); } else return 1; // default of 1000 (1k) } else return *m_efficiency; } // A derived implementation of the Dup() in the base class. CHSEngSystem *CHSSysEngines::Dup(void) { CHSSysEngines *ptr; ptr = new CHSSysEngines; // No initialization to do. return (CHSEngSystem *) ptr; } // Returns maximum velocity for the engines. Since this // variable is overridable at the ship level, we need to // do some logic to determine whether to return a default // value or not. UINT CHSSysEngines::GetMaxVelocity(BOOL bAdjusted) { double dmgperc; CHSSysEngines *ptr; UINT uVal; int iOptPower; // Use some logic here. if (!m_max_velocity) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysEngines *)m_parent; uVal = ptr->GetMaxVelocity(FALSE); } } else uVal = *m_max_velocity; // Make overloading and damage adjustments? if (bAdjusted) { // At this point, uVal is the maximum velocity assuming // 100% power level. We have to adjust for power level // now. The speed inrcreases proportional to overload // percentage. float fVal; iOptPower = GetOptimalPower(TRUE); fVal = (float)m_current_power; fVal /= (float)iOptPower; uVal = (UINT) (fVal * uVal); // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (UINT) (uVal * dmgperc); // Check for fuel source and 0 fuel condition if (m_fuel_source) { if (m_fuel_source->GetFuelRemaining() <= 0) return 0; } } return uVal; } // Returns the acceleration rate for the engines. If the // bAdjusted variable is set to FALSE, no damage or power level // adjustments are made. UINT CHSSysEngines::GetAcceleration(BOOL bAdjusted) { double dmgperc; CHSSysEngines *ptr; UINT uVal; int iOptPower; // Use some logic here. if (!m_acceleration) { // Go to the parent's setting? if (!m_parent) { // No. We are the default values. return 0; } else { // Yes, this system exists on a ship, so // find the default values on the parent. ptr = (CHSSysEngines *)m_parent; uVal = ptr->GetAcceleration(FALSE); } } else uVal = *m_acceleration; // Make overloading and damage adjustments? if (bAdjusted) { // If afterburning, acceleration is increased // like speed. if (GetAfterburning()) { uVal *= HSCONF.afterburn_ratio; } float fVal; iOptPower = GetOptimalPower(FALSE); fVal = (float)m_current_power; fVal /= (float)iOptPower; uVal = (UINT) (uVal * fVal); // Figure in damage. 1/4 reduction per level of damage dmgperc = 1 - (.25 * GetDamageLevel()); uVal = (UINT) (uVal * dmgperc); } return uVal; } // Outputs system information to a file. This could be // the class database or another database of objects that // contain systems. void CHSSysEngines::SaveToFile(FILE *fp) { // Call base class FIRST CHSEngSystem::SaveToFile(fp); // Ok to output, so we print out our information // specific to this system. if (m_max_velocity) fprintf(fp, "MAX VELOCITY=%d\n", *m_max_velocity); if (m_acceleration) fprintf(fp, "ACCELERATION=%d\n", *m_acceleration); if (m_efficiency) fprintf(fp, "EFFICIENCY=%d\n", *m_efficiency); if (m_can_afterburn) fprintf(fp, "CAN AFTERBURN=%d\n", *m_can_afterburn); fprintf(fp, "DESIRED SPEED=%.0f\n", m_desired_speed); fprintf(fp, "CURRENT SPEED=%.0f\n", m_current_speed); fprintf(fp, "AFTERBURNING=%d\n", m_afterburning); } // // CHSJumpDrive stuff // CHSJumpDrive::CHSJumpDrive(void) { m_type = HSS_JUMP_DRIVE; m_charge_level = 0; m_engaged = FALSE; m_min_jump_speed = NULL; m_efficiency = NULL; m_sublight_speed = 0; m_fuel_source = NULL; } CHSEngSystem *CHSJumpDrive::Dup(void) { CHSJumpDrive *ptr; ptr = new CHSJumpDrive; return (CHSEngSystem *) ptr; } // Prints out system information to the specified player void CHSJumpDrive::GiveSystemInfo(int player) { // Print base class info CHSEngSystem::GiveSystemInfo(player); // Now our info notify(player, tprintf("CHARGE: %.2f", m_charge_level)); notify(player, tprintf("ENGAGED: %s", m_engaged ? "YES" : "NO")); notify(player, tprintf("MIN SPEED: %d", GetMinJumpSpeed())); notify(player, tprintf("EFFICIENCY: %d", GetEfficiency())); } BOOL CHSJumpDrive::SetAttributeValue(char *strName, char *strValue) { if (!strcasecmp(strName, "CHARGE")) { m_charge_level = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "ENGAGED")) { m_engaged = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "MIN SPEED")) { if (!m_min_jump_speed) m_min_jump_speed = new int; *m_min_jump_speed = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "EFFICIENCY")) { if (!m_efficiency) m_efficiency = new int; *m_efficiency = atoi(strValue); return TRUE; } else return CHSEngSystem::SetAttributeValue(strName, strValue); } void CHSJumpDrive::SaveToFile(FILE *fp) { // Save the base first CHSEngSystem::SaveToFile(fp); // Save our stuff fprintf(fp, "CHARGE=%.2f\n", m_charge_level); fprintf(fp, "ENGAGED=%d\n", m_engaged); if (m_min_jump_speed) fprintf(fp, "MIN SPEED=%d\n", *m_min_jump_speed); if (m_efficiency) fprintf(fp, "EFFICIENCY=%d\n", *m_efficiency); } // Returns the charge rate for the jump drives. If bAdjusted // is set to TRUE, damage and power level adjustements are // made to the value before returning it. double CHSJumpDrive::GetChargeRate(BOOL bAdjusted) { double rate; // Base rate of 1/2 percent per second rate = 0.5; // Adjust? if (bAdjusted) { // Damage adjustment rate *= 1 - (.25 * GetDamageLevel()); // Power adjustment. Add .00001 just in case // optimal power is 0. float fPower; fPower = (float)(GetOptimalPower(FALSE) + .00001); fPower = m_current_power / fPower; rate *= fPower; } return rate; } void CHSJumpDrive::DoCycle(void) { double rate; // Do base stuff first CHSEngSystem::DoCycle(); // Charge jumpers? if ((m_current_power > 0) && (m_charge_level < 100)) { rate = GetChargeRate(TRUE); if (rate > 0) { m_charge_level += rate; // Make sure we don't overcharge if (m_charge_level > 100) m_charge_level = 100; } } // If engaged, consume fuel. if (m_engaged) { ConsumeFuelBySpeed(m_sublight_speed * HSCONF.jump_speed_multiplier); } } char *CHSJumpDrive::GetStatus(void) { static char tbuf[32]; if (m_charge_level == 100) return "Charged"; else if (m_current_power <= 0) return "Offline"; else { sprintf(tbuf, "%.0f/100%%", m_charge_level); return tbuf; } } BOOL CHSJumpDrive::SetCurrentPower(int level) { UINT max; max = GetOptimalPower(); // Don't allow levels below 0. Level 0 is just deactivation. if (level < 0) return FALSE; // Only allow overloading to 150%. if (level > (max * 1.5)) return FALSE; m_current_power = level; if (!m_current_power ) { // Set charge level to 0. m_charge_level = 0; // If jumpers are engaged and power is set to 0, then // disengage. if (GetEngaged()) { char tbuf[128]; m_engaged = FALSE; sprintf(tbuf, "%s%s-%s Jump drive disengaged.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); if (m_ownerObj) m_ownerObj->HandleMessage(tbuf, MSG_ENGINEERING); } } return TRUE; } // Indicates whether jump drive is engaged or not. BOOL CHSJumpDrive::GetEngaged(void) { return m_engaged; } // Attempts to set the engaged status BOOL CHSJumpDrive::SetEngaged(BOOL bStat) { if (bStat) { // Already engaged? if (GetEngaged()) return FALSE; // Not enough power? if (m_charge_level < 100) return FALSE; // Engage em. m_engaged = TRUE; // Drain power m_charge_level = 0; return TRUE; } else { // Not engaged? if (!GetEngaged()) return FALSE; // Disengage m_engaged = FALSE; return TRUE; } } // Returns the current charge percentage from 0 - 100. int CHSJumpDrive::GetChargePerc(void) { return (int)(m_charge_level); } // Returns the minimum jump speed for the drive. int CHSJumpDrive::GetMinJumpSpeed(void) { // Do we have a local value? if (!m_min_jump_speed) { // Do we have a parent? if (!m_parent) return 0; else { CHSJumpDrive *ptr; ptr = (CHSJumpDrive *)m_parent; return ptr->GetMinJumpSpeed(); } } else return *m_min_jump_speed; } // Tells the engines that they need to gobble up some fuel // from the fuel source. The engines know their efficiency // and such, so they just drain the fuel from the fuel system. // Speed here should be given in units per hour. void CHSJumpDrive::ConsumeFuelBySpeed(int speed) { float fConsume; float fRealized; // Do we have a fuel system? if (!m_fuel_source || (m_fuel_source->GetFuelRemaining() <= 0)) return; // Calculate per second travel rate fConsume = (float) (speed * .0002778); // Divide by efficiency fConsume = (float)(fConsume / (1000.0 * GetEfficiency())); fRealized = m_fuel_source->ExtractFuelUnit(fConsume); if (fRealized < fConsume) { // Out of gas. Disengage. m_engaged = FALSE; char tbuf[128]; sprintf(tbuf, "%s%s-%s A warning light flashing, indicating jump drives have run out of fuel.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL); if (m_ownerObj) m_ownerObj->HandleMessage(tbuf, MSG_ENGINEERING, NULL); } } // Returns the efficiency of the jump drive, which is a // number specifying thousands of units of distance travel // per unit of fuel consumption .. just like gas mileage on // a car. For example 1000km/gallon. This would be returned // here as just 1. int CHSJumpDrive::GetEfficiency(void) { // Do we have a local value? if (!m_efficiency) { // Do we have a parent? if (m_parent) { CHSJumpDrive *ptr; ptr = (CHSJumpDrive *)m_parent; return ptr->GetEfficiency(); } else return 1; // default of 1000 (1k) } else return *m_efficiency; } // Sets the fuel system source for the engines. If this // is NULL, engines don't consume fuel .. duh. void CHSJumpDrive::SetFuelSource(CHSFuelSystem *cFuel) { m_fuel_source = cFuel; } // Tells the jump drive the current sublight speed so that // it can calculate fuel consumption and hyperspace speed. void CHSJumpDrive::SetSublightSpeed(int iSpeed) { // Has to be positive if (iSpeed < 0) iSpeed *= -1; m_sublight_speed = iSpeed; } src/hspace/hsengines.h 100644 767 767 4217 7141305141 13147 0 ustar mux mux #ifndef __HSENGINES_INCLUDED__ #define __HSENGINES_INCLUDED__ #include "hsfuel.h" // A system specifically for engines, derived from // the base CHSEngSystem class. The engines aren't like // car engines. They basically handle velocity. class CHSSysEngines : public CHSEngSystem { public: CHSSysEngines(void); ~CHSSysEngines(void); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); BOOL SetDesiredSpeed(int); BOOL CanBurn(void); BOOL SetAfterburn(BOOL); BOOL GetAfterburning(void); UINT GetMaxVelocity(BOOL bAdjusted = TRUE); UINT GetAcceleration(BOOL bAdjusted = TRUE); double GetDesiredSpeed(void); double GetCurrentSpeed(void); int GetEfficiency(void); void SetFuelSource(CHSFuelSystem *); void SaveToFile(FILE *); void ConsumeFuelBySpeed(int); void DoCycle(void); void GiveSystemInfo(int); CHSEngSystem *Dup(void); protected: void ChangeSpeed(void); // Source of fuel CHSFuelSystem *m_fuel_source; double m_current_speed; double m_desired_speed; BOOL m_afterburning; // Overridable variables at the ship level int *m_max_velocity; int *m_acceleration; int *m_efficiency; // Thousands of distance units per fuel unit BOOL *m_can_afterburn; }; // Hyperspace jump drives. They're basically like the // generic CHSEngSystem with some enhancements. class CHSJumpDrive : public CHSEngSystem { public: CHSJumpDrive(void); BOOL SetAttributeValue(char *, char *); BOOL GetEngaged(void); BOOL SetEngaged(BOOL); BOOL SetCurrentPower(int); int GetMinJumpSpeed(void); int GetChargePerc(void); int GetEfficiency(void); char *GetStatus(void); void SaveToFile(FILE *); void DoCycle(void); void ConsumeFuelBySpeed(int); void SetFuelSource(CHSFuelSystem *); void SetSublightSpeed(int); void GiveSystemInfo(int); double GetChargeRate(BOOL bAdjust = TRUE); CHSEngSystem *Dup(void); protected: // Source of fuel CHSFuelSystem *m_fuel_source; BOOL m_engaged; int *m_min_jump_speed; // Overridable at the ship level int *m_efficiency; // Thousands of distance units per fuel unit double m_charge_level; int m_sublight_speed; // Set this to indicate fuel consumption }; #endif // __HSENGINES_INCLUDED__ src/hspace/hsfuel.cpp 100644 767 767 13540 7141305141 13024 0 ustar mux mux #include "hscopyright.h" #include "hsfuel.h" #include <string.h> #include <stdlib.h> CHSFuelSystem::CHSFuelSystem(void) { m_burnable_fuel = 0; m_reactable_fuel = 0; m_max_burnable_fuel = NULL; m_max_reactable_fuel = NULL; m_type = HSS_FUEL_SYSTEM; // Fuel systems are not visible as other // systems are. They are more of an // interal use system. m_bVisible = FALSE; } // Returns a pointer to a new CHSFuelSystem that's just // like this one. CHSEngSystem *CHSFuelSystem::Dup(void) { CHSFuelSystem *ptr; ptr = new CHSFuelSystem; ptr->m_bVisible = m_bVisible; return (CHSEngSystem *)ptr; } void CHSFuelSystem::GiveSystemInfo(int player) { // Print base system info first CHSEngSystem::GiveSystemInfo(player); // Now our information notify(player, tprintf("BURNABLE FUEL: %.2f", m_burnable_fuel)); notify(player, tprintf("REACTABLE FUEL: %.2f", m_reactable_fuel)); notify(player, tprintf("MAX REACTABLE FUEL: %d", GetMaxFuel(FL_REACTABLE))); notify(player, tprintf("MAX BURNABLE FUEL: %d",GetMaxFuel(FL_BURNABLE))); } BOOL CHSFuelSystem::SetAttributeValue(char *strName, char *strValue) { int iVal; // Find the attribute name, and set the value. if (!strcasecmp(strName, "BURNABLE FUEL")) { m_burnable_fuel = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "REACTABLE FUEL")) { m_reactable_fuel = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "MAX REACTABLE FUEL")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_max_reactable_fuel) { delete m_max_reactable_fuel; m_max_reactable_fuel = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (!m_max_reactable_fuel) m_max_reactable_fuel = new int; *m_max_reactable_fuel = iVal; return TRUE; } else if (!strcasecmp(strName, "MAX BURNABLE FUEL")) { // If strValue contains a null, clear our local setting if (!*strValue) { if (m_max_burnable_fuel) { delete m_max_burnable_fuel; m_max_burnable_fuel = NULL; return TRUE; } return FALSE; } iVal = atoi(strValue); if (!m_max_burnable_fuel) m_max_burnable_fuel = new int; *m_max_burnable_fuel = iVal; return TRUE; } return CHSEngSystem::SetAttributeValue(strName, strValue); } // Returns the value for the specified attribute, or NULL if // invalid attribute. char *CHSFuelSystem::GetAttributeValue(char *strName, BOOL bAdjusted) { static char rval[32]; // Find the attribute name. if (!strcasecmp(strName, "MAX BURNABLE FUEL")) sprintf(rval, "%d", GetMaxFuel(FL_BURNABLE)); else if (!strcasecmp(strName, "MAX REACTABLE FUEL")) sprintf(rval, "%d", GetMaxFuel(FL_REACTABLE)); else if (!strcasecmp(strName, "BURNABLE FUEL")) sprintf(rval, "%.2f", m_burnable_fuel); else if (!strcasecmp(strName, "REACTABLE FUEL")) sprintf(rval, "%.2f", m_reactable_fuel); else return CHSEngSystem::GetAttributeValue(strName, bAdjusted); return rval; } // Returns the maximum fuel of a given type. If no type // is specified, it defaults to burnable fuel. int CHSFuelSystem::GetMaxFuel(HS_FUELTYPE tType) { // We have to determine type and then see if // we have to return the value from the parent or // not. if (tType == FL_BURNABLE) { if (!m_max_burnable_fuel) { if (!m_parent) return 0; else { CHSFuelSystem *cFuel; cFuel = (CHSFuelSystem *)m_parent; return cFuel->GetMaxFuel(tType); } } else return *m_max_burnable_fuel; } else if (tType == FL_REACTABLE) { if (!m_max_reactable_fuel) { if (!m_parent) return 0; else { CHSFuelSystem *cFuel; cFuel = (CHSFuelSystem *)m_parent; return cFuel->GetMaxFuel(tType); } } else return *m_max_reactable_fuel; } // An unsupported fuel type return 0; } // Returns the current fuel levels of a given type. If // not type is specified, this defaults to burnable fuel. float CHSFuelSystem::GetFuelRemaining(HS_FUELTYPE tType) { if (tType == FL_BURNABLE) return m_burnable_fuel; else if (tType == FL_REACTABLE) return m_reactable_fuel; else return 0; } // ATTEMPTS to extract a given amount of fuel from the // system for a certain type. If type is not specified, // it defaults to burnable fuel. The return value is // the level of fuel actually given, which may not be // the same as requested. float CHSFuelSystem::ExtractFuelUnit(float amt, HS_FUELTYPE tType) { float rval; if (amt < 0) return 0; if (tType == FL_BURNABLE) { if (amt > m_burnable_fuel) { rval = m_burnable_fuel; m_burnable_fuel = 0; return rval; } else { m_burnable_fuel -= amt; return amt; } } else if (tType == FL_REACTABLE) { if (amt > m_reactable_fuel) { rval = m_reactable_fuel; m_reactable_fuel = 0; return rval; } else { m_reactable_fuel -= amt; return amt; } } else return 0; } // Writes the fuel system attributes to the specified // file stream. void CHSFuelSystem::SaveToFile(FILE *fp) { // Save base class info first CHSEngSystem::SaveToFile(fp); // Output RAW values. Do not call any Get() functions, // because those will return local or parent values. We // ONLY want to output local values. if (m_max_burnable_fuel) fprintf(fp, "MAX BURNABLE FUEL=%d\n", *m_max_burnable_fuel); if (m_max_reactable_fuel) fprintf(fp, "MAX REACTABLE FUEL=%d\n", *m_max_reactable_fuel); fprintf(fp, "REACTABLE FUEL=%.2f\n", m_reactable_fuel); fprintf(fp, "BURNABLE FUEL=%.2f\n", m_burnable_fuel); } src/hspace/hsfuel.h 100644 767 767 1564 7141305141 12454 0 ustar mux mux #ifndef __HSFUEL_INCLUDED__ #define __HSFUEL_INCLUDED__ #include "hstypes.h" #include "hseng.h" // Types of fuel. enum HS_FUELTYPE { FL_BURNABLE = 0, FL_REACTABLE, }; // This is derived an engineering system, // even though it is quite different. // // The CHSFuelSystem handles fuel storage, transfer, // etc. class CHSFuelSystem : public CHSEngSystem { public: CHSFuelSystem(void); int GetMaxFuel(HS_FUELTYPE type=FL_BURNABLE); float ExtractFuelUnit(float, HS_FUELTYPE type=FL_BURNABLE); float GetFuelRemaining(HS_FUELTYPE type=FL_BURNABLE); BOOL SetAttributeValue(char *, char *); char *GetAttributeValue(char *, BOOL); void SaveToFile(FILE *); void GiveSystemInfo(int); CHSEngSystem *Dup(void); protected: float m_burnable_fuel; float m_reactable_fuel; // Overridables int *m_max_burnable_fuel; int *m_max_reactable_fuel; }; #endif // __HSFUEL_INCLUDED__ src/hspace/hsfuncs.cpp 100664 767 767 52120 7141305141 13206 0 ustar mux mux #include "hscopyright.h" #include "hstypes.h" #include "hsfuncs.h" #include "hsinterface.h" #include "hsobjects.h" #include "hsdb.h" #include "hsutils.h" #include "hsuniverse.h" #include "hspace.h" #include "hseng.h" #include "hscomm.h" #include <string.h> #include <stdlib.h> #include <ctype.h> HSPACE_FUNC_PROTO(hsfGetMissile) HSPACE_FUNC_PROTO(hsfGetAttr) HSPACE_FUNC_PROTO(hsfCalcXYAngle) HSPACE_FUNC_PROTO(hsfCalcZAngle) HSPACE_FUNC_PROTO(hsfSpaceMsg) HSPACE_FUNC_PROTO(hsfGetEngSystems) HSPACE_FUNC_PROTO(hsfSetAttr) HSPACE_FUNC_PROTO(hsfGetSensorContacts) HSPACE_FUNC_PROTO(hsfAddWeapon) HSPACE_FUNC_PROTO(hsfWeaponAttr) HSPACE_FUNC_PROTO(hsfSysAttr) HSPACE_FUNC_PROTO(hsfSysSet) HSPACE_FUNC_PROTO(hsfCommMsg) HSPACE_FUNC_PROTO(hsfSetMissile) HSPACE_FUNC_PROTO(hsfClone) HSFUNC hs_func_list[] = { "ADDWEAPON", hsfAddWeapon, "CLONE", hsfClone, "COMMMSG", hsfCommMsg, "GETATTR", hsfGetAttr, "GETENGSYSTEMS", hsfGetEngSystems, "GETMISSILE", hsfGetMissile, "SENSORCONTACTS", hsfGetSensorContacts, "SETATTR", hsfSetAttr, "SETMISSILE", hsfSetMissile, "SPACEMSG", hsfSpaceMsg, "SYSATTR", hsfSysAttr, "SYSSET", hsfSysSet, "WEAPONATTR", hsfWeaponAttr, "XYANG", hsfCalcXYAngle, "ZANG", hsfCalcZAngle, NULL }; // Finds a function with a given name. HSFUNC *hsFindFunction(char *name) { HSFUNC *ptr; for (ptr = hs_func_list; ptr->name; ptr++) { // Straight comparison of names if (!strcasecmp(name, ptr->name)) return ptr; } return NULL; } // Gets or sets an attribute on one of the globally loaded database // weapons. HSPACE_FUNC_HDR(hsfWeaponAttr) { int iWclass; char arg_left[32]; // left of colon char arg_right[32]; // right of colon // Find a colon (:) in the attrname parameter. If one // exists, this is a set operation as opposed to get. *arg_left = *arg_right = '\0'; char *ptr; ptr = strchr(args[1], ':'); if (ptr) { // Split args[1] in half at the colon. Copy the left // side into arg_left and the right side into .. arg_right. *ptr = '\0'; strncpy(arg_left, args[1], 31); arg_left[31] = '\0'; // Increment ptr and copy arg_right stuff. ptr++; strncpy(arg_right, ptr, 31); arg_right[31] = '\0'; } else { // This is a GET operation. Args[1] is an attrname and // no more. strncpy(arg_left, args[1], 31); arg_left[31] = '\0'; } // Determine weapon class # iWclass = atoi(args[0]); // See if it's a valid weapon. if (!waWeapons.GoodWeapon(iWclass)) return "#-1 Bad weapon identifier."; CHSDBWeapon *cWeap; cWeap = waWeapons.GetWeapon(iWclass, HSW_NOTYPE); if (!cWeap) return "#-1 Failed to retrieve specified weapon object."; // If this is a GET, then just ask the weapon for the // info. if (!*arg_right) { char *ptr; ptr = cWeap->GetAttributeValue(arg_left); if (!ptr) return "#-1 Attribute not found."; else return ptr; } else { // Executor must be a wizard if (!Wizard(executor)) return "#-1 Permission denied."; if (!cWeap->SetAttributeValue(arg_left, arg_right)) return "#-1 Failed to set attribute."; else return "Weapon attribute - Set."; } } HSPACE_FUNC_HDR(hsfAddWeapon) { dbref dbObj; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; // Executor must control the object if (!controls(executor, dbObj)) { return "#-1 Permission denied."; } if (!nearby(executor, dbObj) && !See_All(executor)) { notify(executor, "I don't see that here."); return "#-1"; } // If object is not a console, don't do it. if (!hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) { return "#-1 Target object must be a ship console."; } // Find the console object CHSConsole *cConsole; cConsole = dbHSDB.FindConsole(dbObj); if (!cConsole) return "#-1 Invalid HSpace console."; // Tell the console to add the weapon if (!cConsole->AddWeapon(executor, atoi(args[1]))) return "#-1 Failed to add weapon."; else return "Weapon - Added."; } HSPACE_FUNC_HDR(hsfCalcXYAngle) { double x1, y1; double x2, y2; // Grab coordinate input values x1 = atof(args[0]); y1 = atof(args[1]); x2 = atof(args[2]); y2 = atof(args[3]); static char rval[8]; sprintf(rval, "%d", XYAngle(x1, y1, x2, y2)); return rval; } HSPACE_FUNC_HDR(hsfCalcZAngle) { double x1, y1, z1; double x2, y2, z2; // Grab coordinate input values x1 = atof(args[0]); y1 = atof(args[1]); z1 = atof(args[2]); x2 = atof(args[3]); y2 = atof(args[4]); z2 = atof(args[5]); static char rval[8]; sprintf(rval, "%d", ZAngle(x1, y1, z1, x2, y2, z2)); return rval; } HSPACE_FUNC_HDR(hsfGetMissile) { dbref dbObj; static char rval[32]; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; if (!nearby(executor, dbObj) && !See_All(executor)) { notify(executor, "I don't see that here."); return "#-1"; } // Determine type of object if (!hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_OBJECT)) return "#-1 Not an HSpace object."; CHSObject *cObj; cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; if (cObj->GetType() != HST_SHIP) return "#-1 Not an HSpace ship."; CHSShip *cShip; cShip = (CHSShip *)cObj; // Grab the missile bay from the ship CHSMissileBay *mBay; mBay = cShip->GetMissileBay(); // Ask the missile bay for the maximum and current values. UINT max; UINT left; int iClass; iClass = atoi(args[1]); max = mBay->GetMaxMissiles(iClass); left = mBay->GetMissilesLeft(iClass); sprintf(rval, "%d/%d", left, max); return rval; } HSPACE_FUNC_HDR(hsfGetAttr) { dbref dbObj; char *ptr; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; if (!nearby(executor, dbObj) && !See_All(executor)) { notify(executor, "I don't see that here."); return "#-1"; } // Determine type of object if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_OBJECT)) { CHSObject *cObj; cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; // Disable access to some attrs if (!strcasecmp(args[1], "BOARDING CODE") && !See_All(executor) && !controls(executor, dbObj)) { return "#-1 Permission Denied."; } ptr = cObj->GetAttributeValue(args[1]); } else if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) { CHSConsole *cConsole; cConsole = dbHSDB.FindConsole(dbObj); if (!cConsole) return "#-1 Invalid HSpace console."; // Disable access to some attrs if (!strcasecmp(args[1], "BOARDING CODE") && !See_All(executor) && !controls(executor, dbObj)) { return "#-1 Permission Denied."; } // Try to get the attribute from the console. ptr = cConsole->GetAttributeValue(args[1]); // If attribute not found, try the ship object // the console belongs to. if (!ptr) { CHSObject *cObj; cObj = dbHSDB.FindObjectByConsole(dbObj); if (cObj) ptr = cObj->GetAttributeValue(args[1]); } } else if (hsInterface.HasFlag(dbObj, TYPE_ROOM, ROOM_HSPACE_LANDINGLOC)) { CHSLandingLoc *cLoc; cLoc = dbHSDB.FindLandingLoc(dbObj); if (!cLoc) return "#-1 Invalid HSpace landing location."; ptr = cLoc->GetAttributeValue(args[1]); } else return "#-1 Not an HSpace object."; if (!ptr) return "#-1 Attribute not found."; return ptr; } HSPACE_FUNC_HDR(hsfSetAttr) { dbref dbObj; char *ptr, *dptr; char strName[32]; char strAttr[32]; // The object/attribute pair is specified by a slash // in between. Separate them. dptr = strName; for (ptr = args[0]; *ptr; ptr++) { if ((dptr - strName) > 31) break; if (*ptr == '/') break; *dptr++ = *ptr; } *dptr = '\0'; if (!*ptr) return "#-1 Invalid object/attribute pair specified."; dptr = strAttr; ptr++; while(*ptr) { if ((dptr - strAttr) > 31) break; *dptr++ = *ptr++; } *dptr = '\0'; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, strName); if (dbObj == NOTHING) return "#-1"; // Executor must control the object if (!controls(executor, dbObj)) { return "#-1 Permission denied."; } if (!nearby(executor, dbObj) && !See_All(executor)) { notify(executor, "I don't see that here."); return "#-1"; } // Determine type of object if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_OBJECT)) { CHSObject *cObj; cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; if (cObj->SetAttributeValue(strAttr, args[1])) return "Attribute - set."; else return "Attribute - failed."; } else if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) { CHSConsole *cConsole; cConsole = dbHSDB.FindConsole(dbObj); if (!cConsole) return "#-1 Invalid HSpace console."; // Try to get the attribute from the console. if (cConsole->SetAttributeValue(strAttr, args[1])) return "Attribute - set."; else { // If attribute not found, try the ship object // the console belongs to. CHSObject *cObj; cObj = dbHSDB.FindObjectByConsole(dbObj); if (cObj) { if (cObj->SetAttributeValue(strAttr, args[1])) { static char rbuf[32]; sprintf(rbuf, "%s Attribute - set.", cObj->GetName()); return rbuf; } else return "Attribute - failed."; } else return "Attribute - failed."; } } else if (hsInterface.HasFlag(dbObj, TYPE_ROOM, ROOM_HSPACE_LANDINGLOC)) { CHSLandingLoc *cLoc; cLoc = dbHSDB.FindLandingLoc(dbObj); if (!cLoc) return "#-1 Invalid HSpace landing location."; if (cLoc->SetAttributeValue(strAttr, args[1])) return "Attribute - set."; else return "Attribute - failed."; } else return "#-1 Not an HSpace object."; } // Sends a message into space by 1 of 3 possible ways. HSPACE_FUNC_HDR(hsfSpaceMsg) { CHSObject *cObj; // Check flags on the object to see if it's an // actual object or maybe a console. if (hsInterface.HasFlag(executor, TYPE_THING, THING_HSPACE_OBJECT)) cObj = dbHSDB.FindObject(executor); else if (hsInterface.HasFlag(executor, TYPE_THING, THING_HSPACE_CONSOLE)) cObj = dbHSDB.FindObjectByConsole(executor); else cObj = NULL; if (!Wizard(executor) && !cObj) { return "#-1 Permission denied."; } // Methods of sending: // // 0 = Blind message sent to all ships within a specified // distance of the given coordinates. // 1 = Message sent to all ships who have the source object // on sensors. // 2 = Message sent to all ships who have the source object // identified on sensors. int how = atoi(args[0]); CHSUniverse *uDest; int i; CHSObject *cTarget; switch(how) { case 0: if (!args[1] || !isdigit(*args[1])) return "#-1 Invalid universe ID specified."; int uid; uid = atoi(args[1]); uDest = uaUniverses.FindUniverse(uid); if (!uDest) return "#-1 Invalid universe ID specified."; if (!args[2] || !isdigit(*args[2]) || !args[3] || !isdigit(*args[3]) || !args[4] || !isdigit(*args[4])) return "#-1 Invalid coordinate parameters supplied."; double sX, sY, sZ; // Source coords sX = atof(args[2]); sY = atof(args[3]); sZ = atof(args[4]); if (!args[5] || !isdigit(*args[5])) return "#-1 Invalid distance parameter value."; double dMaxDist; dMaxDist = atof(args[5]); double tX, tY, tZ; // Target object coords if (!args[6]) return "#-1 No message to send."; double dDistance; for (i = 0; i < HS_MAX_ACTIVE_OBJECTS; i++) { cTarget = uDest->GetActiveUnivObject(i); if (!cTarget) continue; tX = cTarget->GetX(); tY = cTarget->GetY(); tZ = cTarget->GetZ(); dDistance = Dist3D(sX, sY, sZ, tX, tY, tZ); if (dDistance > dMaxDist) continue; cTarget->HandleMessage(args[6], MSG_GENERAL, NULL); } break; case 1: case 2: if (!cObj) return "#-1 You are not a HSpace object."; // Grab the source universe uDest = uaUniverses.FindUniverse(cObj->GetUID()); if (!uDest) return "#-1 Object universe could not be found."; CHSSysSensors *cSensors; SENSOR_CONTACT *cContact; for (i = 0; i < HS_MAX_ACTIVE_OBJECTS; i++) { cTarget = uDest->GetActiveUnivObject(i); if (!cTarget) continue; cSensors = (CHSSysSensors *)cTarget->GetEngSystem(HSS_SENSORS); if (!cSensors) continue; cContact = cSensors->GetContact(cObj); if (!cContact) continue; if (cContact->status == DETECTED && how == 1) cTarget->HandleMessage(args[1], MSG_SENSOR, (long *)cObj); else if (cContact->status == IDENTIFIED && how == 2) cTarget->HandleMessage(args[1], MSG_SENSOR, (long *)cObj); } break; default: return "#-1 Invalid sending method specified."; } return "Message sent."; } // Returns a comma delimited list of engineering systems // located on the object. HSPACE_FUNC_HDR(hsfGetEngSystems) { CHSObject *cObj; dbref dbObj; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; if (!nearby(executor, dbObj) && !See_All(executor)) { notify(executor, "I don't see that here."); return "#-1"; } if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_OBJECT)) cObj = dbHSDB.FindObject(dbObj); else if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) cObj = dbHSDB.FindObjectByConsole(dbObj); else cObj = NULL; if (!cObj) return "#-1 Target object is not an HSpace object."; // Now get the engineering systems list from the object int iEngList[32]; // 32 possible eng systems allowed by us int nSystems; nSystems = cObj->GetEngSystemTypes(iEngList); // We've got the list, now translate the types into // names, and put them in the return buffer. static char rbuf[512]; *rbuf = '\0'; int idx; char *ptr; char tbuf[32]; for (idx = 0; idx < nSystems; idx++) { // Find the system name ptr = hsGetEngSystemName(iEngList[idx]); if (!*rbuf) sprintf(tbuf, "%s", ptr ? ptr : "Unknown"); else sprintf(tbuf, ",%s", ptr ? ptr : "Unknown"); strcat(rbuf, tbuf); } return rbuf; } HSPACE_FUNC_HDR(hsfGetSensorContacts) { dbref dbObj; int oType; // Type of object to report dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1 No object found."; CHSObject *cObj; if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) cObj = dbHSDB.FindObjectByConsole(dbObj); else cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Not a HSpace object."; // Grab the sensors from the object CHSSysSensors *cSensors; cSensors = (CHSSysSensors *)cObj->GetEngSystem(HSS_SENSORS); if (!cSensors) return "#-1 Object has no sensors."; int nContacts; nContacts = cSensors->NumContacts(); if (!nContacts) return ""; oType = atoi(args[1]); int idx; SENSOR_CONTACT *cContact; CHSObject *cTarget; static char rbuf[1024]; char tbuf[128]; *rbuf = '\0'; double sX, sY, sZ; // Source coords double tX, tY, tZ; // Contact coords sX = cObj->GetX(); sY = cObj->GetY(); sZ = cObj->GetZ(); for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { // Grab the next contact cContact = cSensors->GetContact(idx); if (!cContact) continue; // Does the type match what is requested? cTarget = cContact->m_obj; if (oType != HST_NOTYPE && (cTarget->GetType() != oType)) continue; // Grab target coords tX = cTarget->GetX(); tY = cTarget->GetY(); tZ = cTarget->GetZ(); // Print out object info if (!*rbuf) sprintf(tbuf, "%d:#%d:%d:%s:%d:%d:%.0f", cContact->m_id, cTarget->GetDbref(), cTarget->GetType(), cContact->status == DETECTED ? "Unknown" : cTarget->GetName(), XYAngle(sX, sY, tX, tY), ZAngle(sX, sY, sZ, tX, tY, tZ), Dist3D(sX, sY, sZ, tX, tY, tZ)); else sprintf(tbuf, "|%d:#%d:%d:%s:%d:%d:%.0f", cContact->m_id, cTarget->GetDbref(), cTarget->GetType(), cContact->status == DETECTED ? "Unknown" : cTarget->GetName(), XYAngle(sX, sY, tX, tY), ZAngle(sX, sY, sZ, tX, tY, tZ), Dist3D(sX, sY, sZ, tX, tY, tZ)); strcat(rbuf, tbuf); } return rbuf; } HSPACE_FUNC_HDR(hsfSysAttr) { dbref dbObj; char *ptr; char lpstrAttr[32]; // Args[0] should be obj/attr, so drop a null in the // split. ptr = strchr(args[0], '/'); if (!ptr) return "#-1 Invalid object/system combination."; *ptr = '\0'; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; if (!nearby(executor, dbObj) && !See_All(executor)) { notify(executor, "I don't see that here."); return "#-1"; } CHSObject *cObj; // If it's a console, search for the object based on // the console. if (hsInterface.HasFlag(dbObj, TYPE_THING, THING_HSPACE_CONSOLE)) cObj = dbHSDB.FindObjectByConsole(dbObj); else cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; // The rest of the string (after the /) should be // the attribute name. ptr++; strncpy(lpstrAttr, ptr, 31); lpstrAttr[31] = '\0'; // Determine what type of system is being queried. HSS_TYPE type; type = hsGetEngSystemType(lpstrAttr); if (type == HSS_NOTYPE) return "#-1 Invalid system specified."; // Ask the object for the system. CHSEngSystem *cSys; cSys = cObj->GetEngSystem(type); if (!cSys) return "#-1 System not present."; ptr = cSys->GetAttributeValue(args[1], atoi(args[2])); if (!ptr) return "#-1 Attribute not found."; return ptr; } HSPACE_FUNC_HDR(hsfSysSet) { dbref dbObj; char *ptr; char strSysName[32]; // The object/attribute pair is specified by a slash // in between. Separate them. ptr = strchr(args[0], '/'); if (!ptr) return "#-1 Invalid object/system pair specified."; *ptr = '\0'; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; // Executor must control the object if (!controls(executor, dbObj)) { return "#-1 Permission denied."; } CHSObject *cObj; cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; // The rest of the string (after the /) should be // the system name. ptr++; strncpy(strSysName, ptr, 31); strSysName[31] = '\0'; // Determine what type of system is being queried. HSS_TYPE type; type = hsGetEngSystemType(strSysName); if (type == HSS_NOTYPE) return "#-1 Invalid system specified."; // Ask the object for the system CHSEngSystem *cSys; cSys = cObj->GetEngSystem(type); if (!cSys) return "#-1 System not present."; // Now set the attribute value char strAttr[32]; char strValue[32]; // Look for a colon separating the attr:value pair. It's // ok to have an empty value. ptr = strchr(args[1], ':'); if (!ptr) { strncpy(strAttr, args[1], 31); strAttr[31] = '\0'; strValue[0] = '\0'; } else { *ptr = '\0'; strncpy(strAttr, args[1], 31); strAttr[31] = '\0'; ptr++; strncpy(strValue, ptr, 31); strValue[31] = '\0'; } // Tell the system to set the attribute if (!cSys->SetAttributeValue(strAttr, strValue)) return "Attribute - failed."; else return "Attribute - set."; } HSPACE_FUNC_HDR(hsfCommMsg) { // See if the executor is a COMM console if (!hsInterface.HasFlag(executor, TYPE_THING, THING_HSPACE_COMM)) return "#-1 Must have HSPACE_COMM flag to do that."; // Grab an HSCOMM struct and fill in the info. HSCOMM commdata; // Try to find a source HSpace obj based on the executor. CHSObject *cObj; cObj = dbHSDB.FindObjectByConsole(executor); if (cObj) { commdata.cObj = cObj; commdata.dbSource = cObj->GetDbref(); } else { commdata.cObj = NULL; commdata.dbSource = executor; } // Source UID commdata.suid = atoi(args[0]); // Dest UID commdata.duid = atoi(args[1]); // Source coords commdata.sX = atoi(args[2]); commdata.sY = atoi(args[3]); commdata.sZ = atoi(args[4]); // Max range commdata.dMaxDist = atoi(args[5]); // Frequency commdata.frq = atof(args[6]); // Message commdata.msg = args[7]; if (cmRelay.RelayMessage(&commdata)) return "Sent."; else return "Failed."; } HSPACE_FUNC_HDR(hsfSetMissile) { dbref dbObj; char *ptr; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; // Executor must control the object if (!controls(executor, dbObj)) { return "#-1 Permission denied."; } CHSObject *cObj; cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; // The object must be a ship. if (cObj->GetType() != HST_SHIP) return "#-1 Not an HSpace ship."; CHSShip *cShip; cShip = (CHSShip *)cObj; if (cShip->SetNumMissiles(executor, atoi(args[1]), atoi(args[2]))) return "Value - set."; else return "Value - failed."; } HSPACE_FUNC_HDR(hsfClone) { dbref dbObj; // Find the object in question dbObj = hsInterface.NoisyMatchThing(executor, args[0]); if (dbObj == NOTHING) return "#-1"; // Executor must be wizard if (!Wizard(executor)) { return "#-1 Permission denied."; } CHSObject *cObj; cObj = dbHSDB.FindObject(dbObj); if (!cObj) return "#-1 Invalid HSpace object."; // The object must be a ship. if (cObj->GetType() != HST_SHIP) return "#-1 Not an HSpace ship."; CHSShip *cShip; cShip = (CHSShip *)cObj; // Clone the ship. dbObj = cShip->Clone(); static char tbuf[64]; sprintf(tbuf, "#%d", dbObj); return tbuf; } src/hspace/hsfuncs.h 100664 767 767 472 7141305141 12616 0 ustar mux mux #ifndef __HSFUNCS_INCLUDED__ #define __HSFUNCS_INCLUDED__ typedef struct { char *name; char *(*func)(int, char **); }HSFUNC; extern HSFUNC *hsFindFunction(char *); #define HSPACE_FUNC_PROTO(x) char *x(int, char **); #define HSPACE_FUNC_HDR(x) char *x(int executor, char **args) #endif // __HSFUNCS_INCLUDED__ src/hspace/hsinterface.cpp 100664 767 767 22425 7141305141 14035 0 ustar mux mux #include "hscopyright.h" #include <string.h> #include "hstypes.h" #include "hsinterface.h" #ifdef PENNMUSH extern "C" { #include "match.h" extern void process_expression (char *, char **, char const **, dbref, dbref, dbref, int, int, PE_Info *); } #endif #ifdef MUX extern void link_exit(dbref player, dbref exit, dbref dest); #endif CHSInterface hsInterface; // One instance of this. // Adds an attribute with a value to an object. int CHSInterface::AtrAdd(int obj, char *atrname, char *val, int owner, int flags) { #ifdef MUX int atr = mkattr(atrname); if( atr <= 0 ) return -1; atr_add(obj, atr, val, owner, flags); return 0; #endif } // Clones an object and returns the dbref of the new clone. dbref CHSInterface::CloneThing(dbref model) { dbref clone; #ifdef PENNMUSH struct lock_list *ll; clone = new_object(); memcpy(&db[clone], &db[model], sizeof(struct object)); db[clone].name = NULL; SET(db[clone].name, Name(model)); s_Pennies(clone, Pennies(model)); atr_cpy(clone, model); db[clone].locks = NULL; for (ll = Locks(model); ll; ll = ll->next) { add_lock(clone, ll->type, dup_bool(ll->key)); } db[clone].zone = db[model].zone; db[clone].parent = db[model].parent; #ifdef USE_WARNINGS db[clone].warnings = 0; /* * zap warnings */ #endif #ifdef CREATION_TIMES /* * We give the clone the same modification time that its * other clone has, but update the creation time */ db[clone].creation_time = time((time_t *) 0); #endif db[clone].contents = db[clone].location = db[clone].next = NOTHING; #endif #ifdef MUX int cost; switch(Typeof(model)) { case TYPE_THING: cost = OBJECT_DEPOSIT((mudconf.clone_copy_cost) ? Pennies(model) : 1); break; case TYPE_ROOM: cost = mudconf.digcost; break; case TYPE_EXIT: cost = mudconf.opencost; break; default: // If it's a player or garbage return *NOTHING*. return NOTHING; } if( (clone = create_obj(Owner(model), Typeof(model), Name(model), cost)) == NOTHING ) return NOTHING; atr_free(clone); atr_cpy(Owner(model), clone, model); s_Name(clone, Name(model)); s_Pennies(clone, OBJECT_ENDOWMENT(cost)); switch(Typeof(clone)) { case TYPE_THING: s_Home(clone, clone_home(Owner(model), model)); move_via_generic(clone, Location(model), Owner(model), 0); break; case TYPE_ROOM: s_Dropto(clone, NOTHING); if( Dropto(model) != NOTHING ) link_exit(Owner(model), clone, Dropto(model)); break; case TYPE_EXIT: s_Exits(Location(model), insert_first(Exits(Location(model)), clone)); s_Exits(clone, Location(model)); s_Location(clone, NOTHING); if( Location(model) != NOTHING) link_exit(Owner(model), clone, Location(model)); break; }; s_Parent(clone, Parent(model)); // did_it(Owner(clone), clone, 0, NULL, 0, NULL, A_ACLONE, NULL, 0); #endif return clone; } // Gets an attribute from an object and stores the value // in the buffer. It returns FALSE if the attribute was // not found. Otherwise, TRUE. BOOL CHSInterface::AtrGet(int obj, char *atrname) { #ifdef PENNMUSH ATTR *a; a = atr_get(obj, atrname); if (!a) return FALSE; strcpy(m_buffer, uncompress(a->value)); return TRUE; #endif #ifdef MUX ATTR* attr; int aowner, aflags; attr = atr_str(atrname); if( !attr ) return FALSE; if( atr_get_str(m_buffer, obj, attr->number, &aowner, &aflags) ) return TRUE; else return FALSE; #endif } int CHSInterface::MaxObjects(void) { #ifdef PENNMUSH return db_top; #endif #ifdef MUX return mudstate.db_top; #endif } dbref CHSInterface::NoisyMatchThing(dbref player, char *name) { dbref console; #ifdef PENNMUSH console = noisy_match_result(player, name, TYPE_THING, MAT_NEAR_THINGS); #endif #ifdef MUX init_match(player, name, TYPE_THING); match_neighbor(); match_absolute(); console = noisy_match_result(); #endif if (console == AMBIGUOUS) console = NOTHING; return console; } dbref CHSInterface::NoisyMatchRoom(dbref player, char *name) { dbref room; #ifdef PENNMUSH room = noisy_match_result(player, name, TYPE_ROOM, MAT_ABSOLUTE | MAT_HERE); #endif #ifdef MUX init_match(player, name, TYPE_ROOM); match_absolute(); match_here(); room = noisy_match_result(); #endif if (room == AMBIGUOUS) room = NOTHING; return room; } // Specifically matches an exit for a given game driver dbref CHSInterface::NoisyMatchExit(dbref player, char *name) { dbref exit_m; #ifdef PENNMUSH exit_m = match_result(player, name, TYPE_EXIT, MAT_EXIT); #endif #ifdef MUX init_match(player, name, TYPE_EXIT); match_absolute(); match_carried_exit_with_parents(); match_exit_with_parents(); exit_m = noisy_match_result(); #endif if (exit_m == AMBIGUOUS) exit_m = NOTHING; return exit_m; } void CHSInterface::SetFlag(int objnum, int flag) { #ifdef PENNMUSH Toggles(objnum) |= flag; #endif #ifdef MUX HSPACE_FLAG_WORD(objnum) |= flag; #endif } void CHSInterface::UnsetFlag(int objnum, int flag) { #ifdef PENNMUSH Toggles(objnum) &= ~flag; #endif #ifdef MUX HSPACE_FLAG_WORD(objnum) &= ~flag; #endif } // Checks to see if the specified object exists, isn't garbage, // etc. BOOL CHSInterface::ValidObject(dbref objnum) { if(HS_GOOD_OBJ(objnum) && HS_ISGARBAGE(objnum)) return TRUE; else return FALSE; } // Returns TRUE or FALSE depending on whether the object has // the specified flag or not. BOOL CHSInterface::HasFlag(dbref objnum, int type, int flag) { int iFlagWord; #ifdef PENNMUSH iFlagWord = Toggles(objnum); #endif #ifdef MUX iFlagWord = HSPACE_FLAG_WORD(objnum); #endif //if (iFlagWord & flag) && (Typeof(objnum) == type) ) // return TRUE; //return FALSE; return (BOOL) ((iFlagWord & flag) && (Typeof(objnum) == type)); } // Can be used to set a type of lock on an object void CHSInterface::SetLock(int objnum, int lockto, HS_LOCKTYPE lock) { #ifdef PENNMUSH char tmp[32]; struct boolexp *key; sprintf(tmp, "#%d", lockto); key = parse_boolexp(lockto, tmp); switch(lock) { case LOCK_USE: add_lock(objnum, Use_Lock, key); break; } #endif #ifdef MUX int key; BOOLEXP* pBoolExp; pBoolExp = parse_boolexp(objnum, tprintf("#%d", lockto), 0); if( pBoolExp != TRUE_BOOLEXP ) { //switch(lock) // { // case LOCK_NORMAL: // key = A_LOCK; // break; // //case LOCK_USE: // key = A_LUSE; //}; if( lock != LOCK_USE ) return; key = A_LUSE; atr_add_raw(objnum, key, unparse_boolexp_quiet(objnum, pBoolExp)); } free_boolexp(pBoolExp); #endif } dbref CHSInterface::GetLock(int objnum, HS_LOCKTYPE lock) { #ifdef PENNMUSH if (Usekey(objnum) == TRUE_BOOLEXP) return NOTHING; else return Usekey(objnum)->thing; #endif #ifdef MUX char* pBuff; dbref target; int key, aflags; BOOLEXP* pBoolExp; //switch(lock) // { // case LOCK_NORMAL: // key = A_LOCK; // break; // // case LOCK_USE: // key = A_LUSE; // }; if( lock != LOCK_USE ) return NOTHING; key = A_LUSE; pBuff = atr_get(objnum, key, &target, &aflags); pBoolExp = parse_boolexp(objnum, pBuff, 1); target = (pBoolExp->type == BOOLEXP_CONST) ? pBoolExp->thing : NOTHING; free_boolexp(pBoolExp); return target; #endif } dbref CHSInterface::ConsoleUser(int objnum) { dbref dbUser; dbUser = GetLock(objnum, LOCK_USE); // If the user is not in the same location as the object, // set the lock to the object and return NOTHING. if (Location(dbUser) != Location(objnum)) { SetLock(objnum, objnum, LOCK_USE); return NOTHING; } return dbUser; } // Sends a message to the contents of an object, which is usually // a room. void CHSInterface::NotifyContents(int objnum, char *strMsg) { #ifdef PENNMUSH notify_except(db[objnum].contents, NOTHING, strMsg); #endif #ifdef MUX notify_check(objnum, objnum, strMsg, MSG_F_CONTENTS|MSG_NBR_EXITS); #endif } // Handles getting the contents of an object, which is often // specific to each game driver. void CHSInterface::GetContents(int loc, int *iArray, int iArraySize, int type) { int thing; int idx; idx = 0; if( type == NOTYPE ) { for( thing = Contents(loc); HS_GOOD_OBJ(thing) && (idx < iArraySize); thing = Next(thing)) iArray[idx++] = thing; } else for (thing = Contents(loc); HS_GOOD_OBJ(thing) && (idx < iArraySize); thing = Next(thing)) { if (Typeof(thing) == type) iArray[idx++] = thing; } iArray[idx] = -1; } // Call this function to see if a given object can // pass a type of lock on a target object. BOOL CHSInterface::PassesLock(int obj, int target, HS_LOCKTYPE locktype) { #ifdef PENNMUSH return could_doit(obj, target); #endif #ifdef MUX int key; //switch(locktype) // { // case LOCK_NORMAL: // key = A_LOCK; // break; // // case LOCK_USE: // key = A_LUSE; // }; if( locktype != LOCK_USE ) return FALSE; key = A_LUSE; return could_doit(obj, target, key); #endif } char *CHSInterface::EvalExpression(char *input, dbref executor, dbref caller, dbref enactor, char** cargs, int ncargs) { static char buff[HS_BUFFER_SIZE]; *buff = '\0'; char* bufc = buff; #ifdef PENNMUSH process_expression(buff, &bufc, &input, executor, caller, enactor, PE_DEFAULT, PT_DEFAULT, NULL); #endif #ifdef MUX TinyExec(buff, &bufc, 0, executor, enactor, EV_FCHECK | EV_EVAL, &input, cargs, ncargs); #endif *bufc = '\0'; return buff; } src/hspace/hsinterface.h 100664 767 767 2152 7141305141 13455 0 ustar mux mux #ifndef __HSINTERFACE_INCLUDED__ #define __HSINTERFACE_INCLUDED__ #include "hsexterns.h" enum HS_LOCKTYPE { LOCK_NORMAL = 0, LOCK_USE }; // The CHSInterface class is used to allow HSpace to easily // port to other types of game drivers. Any game driver specific // access methods should go in here whenever possible. class CHSInterface { public: int AtrAdd(int, char *, char *, int, int flags = NOTHING); void SetFlag(int, int); void UnsetFlag(int, int); void SetLock(int, int, HS_LOCKTYPE); // Sets an object lock void NotifyContents(int, char *); void GetContents(int, int *, int, int); int MaxObjects(void); dbref CloneThing(dbref); dbref NoisyMatchThing(dbref, char *); dbref NoisyMatchRoom(dbref, char *); dbref NoisyMatchExit(dbref, char *); dbref GetLock(int, HS_LOCKTYPE); dbref ConsoleUser(int); BOOL PassesLock(int, int, HS_LOCKTYPE); BOOL HasFlag(int, int, int); BOOL ValidObject(dbref); BOOL AtrGet(int, char *); char *EvalExpression(char *, int, int, int, char** cargs, int ncargs); char m_buffer[HS_BUFFER_SIZE]; }; extern CHSInterface hsInterface; #endif // __HSINTERFACE_INCLUDED__ src/hspace/hsmain.cpp 100664 767 767 1416 7141305141 12776 0 ustar mux mux // This file will serve as our connection between PennMUSH and // HSpace. #include "hscopyright.h" #include "hspace.h" #ifdef PENNMUSH extern "C" { void hsInit(int); void hsDumpDatabases(void); void hsCommand(char *, char *, char *, char *, dbref); void hsCycle(void); char *hsFunction(char *, dbref, char **); } void hsInit(int reboot) { HSpace.InitSpace(reboot); } void hsDumpDatabases(void) { HSpace.DumpDatabases(); } void hsCommand(char *strCmd, char *switches, char *arg_left, char *arg_right, dbref player) { HSpace.DoCommand(strCmd, switches, arg_left, arg_right, player); } char *hsFunction(char *strFunc, dbref executor, char **args) { return HSpace.DoFunction(strFunc, executor, args); } void hsCycle(void) { HSpace.DoCycle(); } #endif src/hspace/hsmissile.cpp 100644 767 767 44377 7141305141 13552 0 ustar mux mux #include "hscopyright.h" #include "hsmissile.h" #include "hsuniverse.h" #include "hsutils.h" #include "hsinterface.h" #include "hspace.h" #include "hsconf.h" #include "hsexterns.h" #include <stdlib.h> #include <string.h> extern double d2cos_table[]; extern double d2sin_table[]; // // CHSMTube stuff // CHSMTube::CHSMTube(void) { m_loaded = FALSE; m_reloading = FALSE; m_time_to_reload = 0; m_missile_bay = NULL; } // Returns an integer indicating the status of the tube. int CHSMTube::GetStatusInt(void) { // Loaded? if (m_loaded) return 0; // Reloading? if (m_reloading) return m_time_to_reload; // Must be empty and not loading return -1; } // Missiles require a target lock to fire BOOL CHSMTube::RequiresLock(void) { return TRUE; } // Indicates whether the missile tube can fire upon the // given type of CHSObject. BOOL CHSMTube::CanAttackObject(CHSObject *cObj) { // Only attack ships if (cObj->GetType() == HST_SHIP) return TRUE; return FALSE; } BOOL CHSMTube::IsReady(void) { if (m_reloading) return FALSE; if (!m_loaded) return FALSE; return TRUE; } // Handles the status integer sent to the weapon from an // outside function. void CHSMTube::SetStatus(int stat) { // 0 indicates loaded. // -1 indicates not loaded. // Any other number indicates loading time if (!stat) { m_loaded = TRUE; } else if (stat < 0) { m_loaded = FALSE; } else { m_loaded = FALSE; m_reloading = TRUE; m_time_to_reload = stat; } } // Cyclic stuff for missile tubes void CHSMTube::DoCycle(void) { m_change = STAT_NOCHANGE; if (m_reloading) Reload(); } // Missile types are configurable BOOL CHSMTube::Configurable(void) { return TRUE; } // Returns the status of the missile tube char *CHSMTube::GetStatus(void) { static char tbuf[32]; if (m_loaded) return "Loaded"; if (m_reloading) { sprintf(tbuf, "(%d) Loading", m_time_to_reload); return tbuf; } return "Empty"; } // Configures the missile tube to a given type of // weapon. BOOL CHSMTube::Configure(int type) { CHSDBWeapon *cDBWeap; // Are we loaded? if (m_loaded) return FALSE; // Are we reloading? if (m_reloading) return FALSE; // Find the weapon in the global array. It has to // be a missile. cDBWeap = waWeapons.GetWeapon(type, HSW_MISSILE); if (!cDBWeap) return FALSE; // Set our parent, which is the missile m_parent = cDBWeap; // Set the class m_class = type; return TRUE; } // If the missile tube has no parent, it is not configured // for a specific type of missile, so handle this for the // name. char *CHSMTube::GetName(void) { if (!m_parent) return "Not Configured"; return m_parent->m_name; } BOOL CHSMTube::Unload(void) { if (!m_loaded) return FALSE; // If reloading, cancel it, and give the missile back // to storage. if (m_reloading) { m_time_to_reload = 0; m_reloading = FALSE; m_loaded = FALSE; // Give the missile back if (m_missile_bay) m_missile_bay->GetMissile(m_class, -1); return TRUE; } else { m_loaded = FALSE; if (m_missile_bay) m_missile_bay->GetMissile(m_class, -1); return TRUE; } } void CHSMTube::AttackObject(CHSObject *cSource, CHSObject *cTarget, CHSConsole *cConsole, int iSysType) { dbref dbUser; // Grab the user of the console. dbUser = hsInterface.ConsoleUser(cConsole->m_objnum); // Can we attack that object? if (!CanAttackObject(cTarget)) { if (dbUser != NOTHING) hsStdError(dbUser, "You cannot attack that target with that weapon."); } // Create a missile object, and put it in space CHSMissile *cMiss; cMiss = new CHSMissile; cMiss->SetUID(cSource->GetUID()); // Add it to the universe CHSUniverse *uDest; uDest = uaUniverses.FindUniverse(cMiss->GetUID()); if (!uDest) { if (dbUser != NOTHING) notify(dbUser, "Error finding a universe to put the missile in."); delete cMiss; return; } uDest->AddObject(cMiss); // Set missile coords cMiss->SetX(cSource->GetX()); cMiss->SetY(cSource->GetY()); cMiss->SetZ(cSource->GetZ()); // Set missile type cMiss->SetParent((CHSDBMissile *)m_parent); // Set source info cMiss->SetSourceConsole(cConsole); cMiss->SetSourceObject(cSource); cMiss->SetTargetObject(cTarget); cMiss->SetName(m_parent->m_name); // Set missile dbref to some very high number that's // probably not duplicated. cMiss->SetDbref(RandomLong(8534, 18535)); if (dbUser != NOTHING) hsStdError(dbUser, "Missile launched."); m_loaded = FALSE; } BOOL CHSMTube::Reload(void) { // Check to see if we're reloading. // If not, then begin it. if (!m_reloading) { // Are we already loaded? if (m_loaded) return FALSE; // Pull a missile from storage .. or try to. if (!m_missile_bay) return FALSE; if (!m_missile_bay->GetMissile(m_class)) return FALSE; m_reloading = TRUE; m_time_to_reload = GetReloadTime(); } else { m_time_to_reload--; if (m_time_to_reload <= 0) { m_change = STAT_READY; m_reloading = FALSE; m_loaded = TRUE; } } return TRUE; } // Returns attribute information in a string. char *CHSMTube::GetAttrInfo(void) { static char rval[128]; sprintf(rval, "R: %-5d S: %-3d V : %d", GetRange(), GetStrength(), GetSpeed()); return rval; } BOOL CHSMTube::Loadable(void) { return TRUE; } int CHSMTube::Reloading(void) { if (!m_reloading) return 0; return m_time_to_reload; } UINT CHSMTube::GetReloadTime(void) { CHSDBMissile *dbMis; if (!m_parent) return 0; // Return the reload time dbMis = (CHSDBMissile *)m_parent; return dbMis->m_reload_time; } UINT CHSMTube::GetRange(void) { CHSDBMissile *dbMis; if (!m_parent) return 0; dbMis = (CHSDBMissile *)m_parent; return dbMis->m_range; } UINT CHSMTube::GetStrength(void) { CHSDBMissile *dbMis; if (!m_parent) return 0; dbMis = (CHSDBMissile *)m_parent; return dbMis->m_strength; } UINT CHSMTube::GetSpeed(void) { CHSDBMissile *dbMis; if (!m_parent) return 0; dbMis = (CHSDBMissile *)m_parent; return dbMis->m_speed; } UINT CHSMTube::GetTurnRate(void) { CHSDBMissile *dbMis; if (!m_parent) return 0; dbMis = (CHSDBMissile *)m_parent; return dbMis->m_turnrate; } // Sets the missile bay source for the tube, which is where // the tube will draw its missiles from. void CHSMTube::SetMissileBay(CHSMissileBay *mBay) { m_missile_bay = mBay; } // // CHSMissileBay stuff // CHSMissileBay::CHSMissileBay(void) { int idx; // Initialize storage for (idx = 0; idx < HS_MAX_MISSILES; idx++) m_storage[idx] = NULL; } CHSMissileBay::~CHSMissileBay(void) { int idx; // Free up any missile storage slots for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (m_storage[idx]) delete m_storage[idx]; } } // Tries to set a remaining missile storage value for // the given type of missile. If the type isn't // already shown in storage, the type is added IF the // weapon type is valid. If the remaining value is greater // than the maximum storage value, then the maximum is raised. BOOL CHSMissileBay::SetRemaining(int type, int remaining) { UINT idx; // Try to find the type in storage for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (m_storage[idx]) { if (m_storage[idx]->m_class == type) { // If remaining is negative, erase // the storage. if (remaining < 0) { delete m_storage[idx]; m_storage[idx] = NULL; } else { m_storage[idx]->m_remaining = remaining; // Is number larger than max? If so, raise // max. if (remaining > m_storage[idx]->m_maximum) m_storage[idx]->m_maximum = remaining; } // We're done, so return. return TRUE; } } } // Type was not found, so let's see if the missile // is a valid type. if (!waWeapons.GetWeapon(type, HSW_MISSILE)) return FALSE; // Find the first available slot for storage for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (!m_storage[idx]) break; } if (idx == HS_MAX_MISSILES) return FALSE; // Allocate space m_storage[idx] = new HSMISSILESTORE; m_storage[idx]->m_class = type; m_storage[idx]->m_maximum = remaining; m_storage[idx]->m_remaining = remaining; // Looks good. return TRUE; } // Tries to pull a missile from storage. If the missile // doesn't exist or the slot is empty, FALSE is returned. // Otherwise, a value of TRUE indicates success, and the // storage slot is decremented. BOOL CHSMissileBay::GetMissile(int type, int amt) { UINT idx; // Find the storage slot for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (m_storage[idx]) { // Right type of weapon? if (m_storage[idx]->m_class == type) { // Enough left? if (m_storage[idx]->m_remaining >= amt) { m_storage[idx]->m_remaining -= amt; return TRUE; } else { // Not enough left return FALSE; } } } } // Not found return FALSE; } // Saves missile bay information to the specified file stream. void CHSMissileBay::SaveToFile(FILE *fp) { int idx; // Write out our missile storage infos for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (!m_storage[idx]) continue; fprintf(fp, "MISSILETYPE=%d\n", m_storage[idx]->m_class); fprintf(fp, "MISSILEMAX=%d\n", m_storage[idx]->m_maximum); fprintf(fp, "MISSILEREMAINING=%d\n", m_storage[idx]->m_remaining); } fprintf(fp, "MISSILEBAYEND\n"); } // Loads missile bay information from the specified file stream. void CHSMissileBay::LoadFromFile(FILE *fp) { char tbuf[128]; char strKey[64]; char strValue[64]; char *ptr; int type; // Load from the file stream until end of file or, more // like, MISSILEBAYEND indicator. type = -1; while(fgets(tbuf, 128, fp)) { // Strip newline chars if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; // Extract key/value pairs extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); // Check for key match if (!strcmp(strKey, "MISSILEBAYEND")) { // This is the end. return; } else if (!strcmp(strKey, "MISSILETYPE")) { type = atoi(strValue); } else if (!strcmp(strKey, "MISSILEMAX")) { // Set the maximum value for the type. // No need to error check. SetRemaining(type, atoi(strValue)); } else if (!strcmp(strKey, "MISSILEREMAINING")) { // Set missiles remaining for the type. SetRemaining(type, atoi(strValue)); } } } // Returns the number of missiles left for the given type of missile. UINT CHSMissileBay::GetMissilesLeft(int iclass) { int idx; for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (m_storage[idx] && m_storage[idx]->m_class == iclass) return m_storage[idx]->m_remaining; } return 0; } // Reteurns the maximum storage value for the given type of missile. UINT CHSMissileBay::GetMaxMissiles(int iclass) { int idx; for (idx = 0; idx < HS_MAX_MISSILES; idx++) { if (m_storage[idx] && m_storage[idx]->m_class == iclass) return m_storage[idx]->m_maximum; } return 0; } // Retrieves the HSMISSILESTORE structure for a given // slot. HSMISSILESTORE *CHSMissileBay::GetStorage(int slot) { if (slot < 0 || slot >= HS_MAX_MISSILES) return NULL; return m_storage[slot]; } // // CHSMissile implementation // CHSMissile::CHSMissile(void) { m_target = NULL; m_source_object = NULL; m_source_console = NULL; m_parent = NULL; m_timeleft = -1; m_delete_me = FALSE; m_target_hit = FALSE; m_type = HST_MISSILE; CHSVector cvTmp(1,0,0); m_motion_vector = cvTmp; m_xyheading = m_zheading = 0; } void CHSMissile::SetSourceObject(CHSObject *cSource) { m_source_object = cSource; } void CHSMissile::SetSourceConsole(CHSConsole *cConsole) { m_source_console = cConsole; } void CHSMissile::SetTargetObject(CHSObject *cObj) { m_target = cObj; } void CHSMissile::DoCycle(void) { // Do we need to delete ourselves? if (m_delete_me) { delete this; return; } // If we have no target or no parent, remove us // from space. if (!m_target || !m_parent || !m_target->IsActive()) { CHSUniverse *uSource; uSource = uaUniverses.FindUniverse(m_uid); if (uSource) uSource->RemoveObject(this); // Delete me m_delete_me = TRUE; return; } // Do we know how much time is left until we die? if (m_timeleft < 0) { CalculateTimeLeft(); } else m_timeleft--; // Missile depleted? if (m_timeleft == 0) { // Remove us from space CHSUniverse *cSource; cSource = uaUniverses.FindUniverse(m_uid); if (cSource) cSource->RemoveObject(this); m_delete_me = TRUE; return; } // Change the missile heading toward the target ChangeHeading(); // Move us closer to the target. MoveTowardTarget(); // The MoveTowardTarget() checks to see if the missile hits, // so we just have to check our flag. if (m_target_hit) { // BOOM! HitTarget(); // Remove us from space CHSUniverse *cSource; cSource = uaUniverses.FindUniverse(m_uid); if (cSource) cSource->RemoveObject(this); m_delete_me = TRUE; // Delete next time around } } // Moves the missile along the current trajectory. void CHSMissile::MoveTowardTarget(void) { // Grab parent missile object CHSDBMissile *dbMiss; dbMiss = (CHSDBMissile *)m_parent; // Calculate per second speed double speed; speed = dbMiss->m_speed * (.0002778 * HSCONF.cyc_interval); double tX, tY, tZ; double dist; tX = m_target->GetX(); tY = m_target->GetY(); tZ = m_target->GetZ(); dist = Dist3D(m_x, m_y, m_z, tX, tY, tZ); // Determine if speed is > distance, which might indicate // that the missile is within hitting range. If this is // true, move the missile just the distance to the target // and see if the coordinates are relatively close. It's // possible that the missile is close, but the target is // evading, in which case we just have to move the missile // it's regular distance. if (speed > dist) { // Move just the distance double n_x, n_y, n_z; n_x = m_x + m_motion_vector.i() * dist; n_y = m_y + m_motion_vector.j() * dist; n_z = m_z + m_motion_vector.k() * dist; // Is new distance within 1 unit? dist = Dist3D(n_x, n_y, n_z, tX, tY, tZ); if (dist <= 1) { m_target_hit = TRUE; return; } } // At this point we know we didn't hit, so just move // regularly. m_x += m_motion_vector.i() * speed; m_y += m_motion_vector.j() * speed; m_z += m_motion_vector.k() * speed; } // Changes the heading of the missile to head toward the target. void CHSMissile::ChangeHeading(void) { BOOL bChange; // Indicates if any turning has occurred; // Calculate X, Y, and Z difference vector double tX, tY, tZ; tX = m_target->GetX(); tY = m_target->GetY(); tZ = m_target->GetZ(); int xyang = XYAngle(m_x, m_y, tX, tY); int zang = ZAngle(m_x, m_y, m_z, tX, tY, tZ); // Get the turn rate CHSDBMissile *dbMiss; dbMiss = (CHSDBMissile *)m_parent; int iTurnRate = dbMiss->m_turnrate; bChange = FALSE; // Check for change in zheading if (zang != m_zheading) { if (zang > m_zheading) { if ((zang - m_zheading) > iTurnRate) m_zheading += iTurnRate; else m_zheading = zang; } else { if ((m_zheading - zang) > iTurnRate) m_zheading -= iTurnRate; else m_zheading = zang; } bChange = TRUE; } // Now handle any changes in the XY plane. int iDiff; if (xyang != m_xyheading) { if (abs(m_xyheading - xyang) < 180) { if (abs(m_xyheading - xyang) < iTurnRate) m_xyheading = xyang; else if (m_xyheading > xyang) { m_xyheading -= iTurnRate; if (m_xyheading < 0) m_xyheading += 360; } else { m_xyheading += iTurnRate; if (m_xyheading > 359) m_xyheading -= 360; } } else if (((360 - xyang) + m_xyheading) < 180) { iDiff = (360 - xyang) + m_xyheading; if (iDiff < iTurnRate) { m_xyheading = xyang; } else { m_xyheading -= iTurnRate; if (m_xyheading < 0) m_xyheading += 360; } } else if (((360 - m_xyheading) + xyang) < 180) { iDiff = (360 - m_xyheading) + xyang; if (iDiff < iTurnRate) { m_xyheading = xyang; } else { m_xyheading += iTurnRate; if (m_xyheading > 359) m_xyheading -= 360; } } else // This should never be true, but just in case. { m_xyheading += iTurnRate; if (m_xyheading > 359) m_xyheading -= 360; } bChange = TRUE; } // Check to see if we need to recompute trajectory. if (bChange) { zang = m_zheading; if (zang < 0) zang += 360; CHSVector tvec( d2sin_table[m_xyheading] * d2cos_table[zang], d2cos_table[m_xyheading] * d2cos_table[zang], d2sin_table[zang]); m_motion_vector = tvec; } } // Sets the current heading of the missile, which is usually // used when the missile is launched toward a target. void CHSMissile::SetHeading(int xy, int z) { m_xyheading = xy; m_zheading = z; } // Handles hitting the target and contacting the target // object to negotiate damage. void CHSMissile::HitTarget(void) { CHSDBMissile *dbMiss; dbMiss = (CHSDBMissile *)m_parent; // Tell the target it's damaged m_target->HandleDamage(m_source_object, (CHSWeapon *)this, dbMiss->m_strength, m_source_console, HSS_NOTYPE); } void CHSMissile::CalculateTimeLeft(void) { double speed; int range; // Time until our death is calculated by // speed and range. CHSDBMissile *dbMiss; dbMiss = (CHSDBMissile *)m_parent; speed = dbMiss->m_speed; range = dbMiss->m_range; // Bring speed down to per second level. speed = speed * .0002778; m_timeleft = (int)(range / speed); } char CHSMissile::GetObjectCharacter(void) { return 'x'; } char *CHSMissile::GetObjectColor(void) { static char tbuf[32]; sprintf(tbuf, "%s%s", ANSI_HILITE, ANSI_YELLOW); return tbuf; } void CHSMissile::HandleDamage(CHSObject *cSource, CHSWeapon *cWeapon, int strength, CHSConsole *cConsole, int iSysType) { int player; player = hsInterface.ConsoleUser(cConsole->m_objnum); // Any hit destroys the missile. hsStdError(player, "Your shot explodes the target missile!"); // Remove the missile from space CHSUniverse *uSource; // Find my universe uSource = uaUniverses.FindUniverse(m_uid); if (uSource) { // Remove me from active space. uSource->RemoveObject(this); } // Delete me m_delete_me = TRUE; } src/hspace/hsmissile.h 100644 767 767 3761 7141305141 13167 0 ustar mux mux #ifndef __HSMISSILE_INCLUDED__ #define __HSMISSILE_INCLUDED__ #include "hsweapon.h" #include "hsobjects.h" // A missile that gets fired from a missile tube class CHSMissile : public CHSObject, public CHSWeapon { public: CHSMissile(void); void DoCycle(void); void SetTargetObject(CHSObject *); void SetSourceObject(CHSObject *); void SetSourceConsole(CHSConsole *); void HandleDamage(CHSObject *, CHSWeapon *, int, CHSConsole *, int); char *GetObjectColor(void); char GetObjectCharacter(void); void SetHeading(int, int); // Sets the current heading of the missile protected: void CalculateTimeLeft(void); void HitTarget(void); void Expire(void); void ChangeHeading(void); void MoveTowardTarget(void); // Attributes CHSObject *m_source_object; CHSObject *m_target; CHSConsole *m_source_console; BOOL m_delete_me; // Internal use. BOOL m_target_hit; // Flag to mark if target is hit int m_timeleft; int m_xyheading; int m_zheading; }; // CHSMTube is a strange name for a weapons class, but that's what it // really is .. a missile tube, not a missile. Missiles are stored // in the ship's ammunition storage, and each missile tube just loads // and fires them. class CHSMTube : public CHSWeapon { public: CHSMTube(void); // Methods UINT GetReloadTime(void); UINT GetRange(void); UINT GetStrength(void); UINT GetTurnRate(void); UINT GetSpeed(void); int Reloading(void); int GetStatusInt(void); char *GetName(void); char *GetStatus(void); char *GetAttrInfo(void); void SetMissileBay(CHSMissileBay *); void DoCycle(void); void SetStatus(int); void AttackObject(CHSObject *, CHSObject *, CHSConsole *, int); BOOL RequiresLock(void); BOOL IsReady(void); BOOL CanAttackObject(CHSObject *cObj); BOOL Reload(void); BOOL Configurable(void); BOOL Configure(int); BOOL Loadable(void); BOOL Unload(void); protected: // Attributes UINT m_time_to_reload; BOOL m_loaded; BOOL m_reloading; CHSMissileBay *m_missile_bay; // Source of missiles }; #endif // __HSMISSILE_INCLUDED__ src/hspace/hsnavcmds.cpp 100664 767 767 42413 7141305141 13527 0 ustar mux mux #include "hscopyright.h" #include "hscmds.h" #include "hsdb.h" #include "hseng.h" #include "hsinterface.h" #include "hsutils.h" #include "hsconf.h" #include <stdlib.h> HSPACE_COMMAND_PROTO(hscSetVelocity) HSPACE_COMMAND_PROTO(hscSetHeading) HSPACE_COMMAND_PROTO(hscSensorReport) HSPACE_COMMAND_PROTO(hscNavStatus) HSPACE_COMMAND_PROTO(hscSetMapRange) HSPACE_COMMAND_PROTO(hscLandVessel) HSPACE_COMMAND_PROTO(hscUndockVessel) HSPACE_COMMAND_PROTO(hscDoAfterburn) HSPACE_COMMAND_PROTO(hscDoJump) HSPACE_COMMAND_PROTO(hscDoBoardLink) HSPACE_COMMAND_PROTO(hscBreakBoardLink) HSPACE_COMMAND_PROTO(hscTaxiVessel) HSPACE_COMMAND_PROTO(hscDoView) HSPACE_COMMAND_PROTO(hscScan) #ifdef MUX NAMETAB hsNav_sw[] = { {(char *)"afterburn", 1, CA_PUBLIC, 1}, {(char *)"boardlink", 6, CA_PUBLIC, 2}, {(char *)"boardunlink", 6, CA_PUBLIC, 3}, {(char *)"jump", 1, CA_PUBLIC, 4}, {(char *)"land", 1, CA_PUBLIC, 5}, {(char *)"setheading", 4, CA_PUBLIC, 6}, {(char *)"maprange", 1, CA_PUBLIC, 7}, {(char *)"scan", 2, CA_PUBLIC, 8}, {(char *)"sensorreport", 3, CA_PUBLIC, 9}, {(char *)"setvelocity", 4, CA_PUBLIC, 10}, {(char *)"status", 2, CA_PUBLIC, 11}, {(char *)"taxi", 1, CA_PUBLIC, 12}, {(char *)"undock", 1, CA_PUBLIC, 13}, {(char *)"view", 1, CA_PUBLIC, 14}, {NULL, 0, 0 , 0} }; hs_command hNavCommands[] = { NULL, hscDoAfterburn, hscDoBoardLink, hscBreakBoardLink, hscDoJump, hscLandVessel, hscSetHeading, hscSetMapRange, hscScan, hscSensorReport, hscSetVelocity, hscNavStatus, hscTaxiVessel, hscUndockVessel, hscDoView }; #endif #ifdef PENNMUSH // The hsNavCommandArray holds all externally callable // @nav commands. HSPACE_COMMAND hsNavCommandArray[] = { "AFTERBURN", hscDoAfterburn, HCP_ANY, "BOARDLINK", hscDoBoardLink, HCP_ANY, "BOARDUNLINK", hscBreakBoardLink, HCP_ANY, "JUMP", hscDoJump, HCP_ANY, "LAND", hscLandVessel, HCP_ANY, "SETHEADING", hscSetHeading, HCP_ANY, "MAPRANGE", hscSetMapRange, HCP_ANY, "SCAN", hscScan, HCP_ANY, "SENSORREPORT", hscSensorReport, HCP_ANY, "SETVELOCITY", hscSetVelocity, HCP_ANY, "STATUS", hscNavStatus, HCP_ANY, "TAXI", hscTaxiVessel, HCP_ANY, "UNDOCK", hscUndockVessel, HCP_ANY, "VIEW", hscDoView, HCP_ANY, NULL, NULL, 0 }; #endif // Sets the velocity of a vessel HSPACE_COMMAND_HDR(hscSetVelocity) { dbref dbUser; CHSShip *cShip; int iVel; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } iVel = atoi(arg_left); cShip->SetVelocity(dbUser, iVel); } // Sets the heading of a vessel HSPACE_COMMAND_HDR(hscSetHeading) { dbref dbUser; CHSShip *cShip; int xy, z; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) xy = NOTHING; else xy = atoi(arg_left); if (!arg_right || !*arg_right) z = NOTHING; else z = atoi(arg_right); cShip->SetHeading(dbUser, xy, z); } // Prints out a sensor report, perhaps for a specific object type. HSPACE_COMMAND_HDR(hscSensorReport) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) cShip->GiveSensorReport(dbUser); else cShip->GiveSensorReport(dbUser, (HS_TYPE)atoi(arg_left)); } // Gives the big navigation status display HSPACE_COMMAND_HDR(hscNavStatus) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } cShip->GiveNavigationStatus(dbUser); } // Allows the player to set the ship's map range HSPACE_COMMAND_HDR(hscSetMapRange) { dbref dbUser; CHSShip *cShip; char tbuf[64]; int units; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } units = atoi(arg_left); if (!cShip->SetMapRange(dbUser, units)) hsStdError(dbUser, "Failed to set map range."); else { sprintf(tbuf, "Map range now set to %d %s.", units, HSCONF.unit_name); hsStdError(dbUser, tbuf); } } // Allows a player to land the vessel on some object, at some // location, with a code (if needed) HSPACE_COMMAND_HDR(hscLandVessel) { dbref dbUser; CHSShip *cShip; char *sptr, *dptr; int id, loc; char tbuf[64]; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify a target ID/location."); return; } // The format of the landing command is: // // @nav/land ID/loc=code // // Parse out this info dptr = tbuf; for (sptr = arg_left; *sptr; sptr++) { if (*sptr == '/') { *dptr = '\0'; id = atoi(tbuf); break; } else *dptr++ = *sptr; } // Was a location specified? if (!*sptr) { notify(player, "You must specify the number of a location at that target."); return; } // Skip the slash sptr++; dptr = tbuf; while(*sptr) { *dptr++ = *sptr++; } *dptr = '\0'; loc = atoi(tbuf); // Tell the ship to land. cShip->LandVessel(dbUser, id, loc, arg_right); } // Allows the player to undock/lift off the vessel HSPACE_COMMAND_HDR(hscUndockVessel) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } cShip->UndockVessel(dbUser); } // Allows a player to engage/disengage the afterburners. HSPACE_COMMAND_HDR(hscDoAfterburn) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify 0 or 1 for afterburn status."); return; } cShip->EngageAfterburn(dbUser, atoi(arg_left)); } // Allows a player to engage/disengage the jump drive. HSPACE_COMMAND_HDR(hscDoJump) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify 0 or 1 for jump drive engage status."); return; } cShip->EngageJumpDrive(dbUser, atoi(arg_left)); } HSPACE_COMMAND_HDR(hscDoBoardLink) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify a target contact number."); return; } // Tell the ship to board link. cShip->DoBoardLink(dbUser, atoi(arg_left)); } HSPACE_COMMAND_HDR(hscBreakBoardLink) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify a target contact number."); return; } // Tell the ship to board link. cShip->DoBreakBoardLink(dbUser, atoi(arg_left)); } HSPACE_COMMAND_HDR(hscTaxiVessel) { dbref dbUser; CHSShip *cShip; dbref dbObj; dbref dbExit; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify a direction to taxi."); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } // Ship must not be in space if (!cShip->Landed()) { hsStdError(dbUser, "Must be landed or docked to taxi."); return; } // Grab the ship's shipobj dbObj = cShip->GetDbref(); if (dbObj == NOTHING) { notify(dbUser, "Your ship has no ship object to taxi around."); return; } // Find the exit dbExit = hsInterface.NoisyMatchExit(dbObj, arg_left); if (dbExit == NOTHING || Typeof(dbExit) != TYPE_EXIT) { notify(dbUser, "That is not a valid direction to taxi."); return; } // Try to move the ship object if (Location(dbExit) == NOTHING) { notify(dbUser, "That location leads to nowhere. You don't want to go there."); return; } // See if the object passes the lock if (!hsInterface.PassesLock(dbObj, dbExit, LOCK_NORMAL)) { hsStdError(dbUser, "That location is blocked to our departure."); return; } move_object(dbObj, Location(dbExit)); hsInterface.NotifyContents(Location(dbObj), tprintf("The %s fires is vector rockets and taxis to %s.", cShip->GetName(), Name(Location(dbExit)))); move_object(dbObj, Location(dbExit)); hsInterface.NotifyContents(Location(dbExit), tprintf("The %s taxis in, firing its vector rockets.", cShip->GetName())); hsStdError(dbUser, "You fire the vector rockets and taxi onward."); look_in(dbUser, Location(dbExit), 0); } HSPACE_COMMAND_HDR(hscDoView) { dbref dbUser; CHSShip *cShip; dbref dbObj; dbref dbLoc; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Ship must not be in space if (!cShip->Landed()) { hsStdError(dbUser, "This vessel is not currently landed."); return; } // Grab the ship's shipobj dbObj = cShip->GetDbref(); if (dbObj == NOTHING) { notify(dbUser, "Your ship has no ship object. Don't know where you're landed."); return; } // Find the location of the shipobj dbLoc = Location(dbObj); notify(dbUser, "Outside the vessel you see ..."); look_in(dbUser, dbLoc, 0); } // Allows a player to scan an object on sensors HSPACE_COMMAND_HDR(hscScan) { dbref dbUser; CHSShip *cShip; // Find the ship based on the console cShip = (CHSShip *) dbHSDB.FindObjectByConsole(player); if (!cShip || (cShip->GetType() != HST_SHIP)) { notify(player, "Go away! You are not an HSpace ship!"); return; } // Find the user of the console. dbUser = hsInterface.ConsoleUser(player); if (dbUser == NOTHING) return; // Is the ship destroyed? if (cShip->IsDestroyed()) { notify(dbUser, "This vessel has been destroyed!"); return; } // Find the console object CHSConsole *cConsole; cConsole = cShip->FindConsole(player); if (cConsole && !cConsole->IsOnline()) { hsStdError(dbUser, tprintf("%s is currently powered down.", Name(player))); return; } if (!arg_left || !*arg_left) { notify(dbUser, "You must specify a target contact number."); return; } // Tell the ship to board link. cShip->ScanObjectID(dbUser, atoi(arg_left)); } src/hspace/hsobjects.cpp 100664 767 767 36657 7141305141 13542 0 ustar mux mux #include "hscopyright.h" #include "hsobjects.h" #include "hsinterface.h" #include <stdlib.h> #include "hsutils.h" #include "hsexterns.h" #include "hsuniverse.h" #include <string.h> CHSObject::CHSObject(void) { m_x = 0; m_y = 0; m_z = 0; m_objnum = NOTHING; m_uid = 0; m_visible= TRUE; m_size = 1; m_name = NULL; m_current_speed = 0; // No speed m_type = HST_NOTYPE; m_next = m_prev = NULL; } CHSObject::~CHSObject(void) { if (m_name) delete [] m_name; if (m_objnum != NOTHING) { // Reset object flag if (hsInterface.ValidObject(m_objnum)) hsInterface.UnsetFlag(m_objnum, THING_HSPACE_OBJECT); } } // Indicates whether the object is actively in space or not. BOOL CHSObject::IsActive(void) { // By default, all objects are active return TRUE; } // Indicates whether the object is visible or not. BOOL CHSObject::IsVisible(void) { return m_visible; } // A general message handler for all CHSObjects. It does // absosmurfly nothing. If you implement this function in your // derived class, the long pointer points to whatever data are // passed in. It's up to you to know what is being passed. void CHSObject::HandleMessage(char *lpstrMsg, int msgType, long *data) { // Do nothing. } // Can be overridden in derived classes to retrieve // engineering systems. Generic CHSObjects have no // engineering systems. CHSEngSystem *CHSObject::GetEngSystem(int type) { return NULL; } // Can be overridden in derived classes to retrieve // the engineering systems array. Generic CHSObjects have // no engineering systems array. CHSSystemArray *CHSObject::GetEngSystemArray(void) { return NULL; } // Can be overridden in derived classes to retrieve // a list of engineering system types available on // the object. Generic CHSObjects have no engineering // systems. // // The return value is the number of systems returned. UINT CHSObject::GetEngSystemTypes(int *iBuff) { return 0; } // ATTEMPTS to set a given attribute with the specified value. // If the attribute doesn't exist or the value is invalid, it // return FALSE. Otherwise, TRUE. BOOL CHSObject::SetAttributeValue(char *strName, char *strValue) { int iVal; // Look for the attribute if (!strcasecmp(strName, "X")) { m_x = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "Y")) { m_y = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "Z")) { m_z = atof(strValue); return TRUE; } else if (!strcasecmp(strName, "NAME")) { if (m_name) delete [] m_name; if (strValue) { m_name = new char[strlen(strValue) + 1]; strcpy(m_name, strValue); // Change the name of the MUSH object if (m_objnum != NOTHING) { s_Name(m_objnum, strValue); } } return TRUE; } else if (!strcasecmp(strName, "UID")) { iVal = atoi(strValue); // Check to see if the universe exists. CHSUniverse *uSource; CHSUniverse *uDest; uDest = uaUniverses.FindUniverse(iVal); if (!uDest) return FALSE; // Grab the source universe uSource = uaUniverses.FindUniverse(m_uid); // Now pull it from one, and put it in another uSource->RemoveObject(this); m_uid = iVal; return (uDest->AddObject(this)); } else if (!strcasecmp(strName, "SIZE")) { iVal = atoi(strValue); if (iVal < 1) return FALSE; m_size = iVal; return TRUE; } else return FALSE; } // Returns a character value for the requested object // attribute. If the attribute is not valid, the string // contains a single null character. char *CHSObject::GetAttributeValue(char *strName) { static char rval[64]; *rval = '\0'; if (!strcasecmp(strName, "X")) { sprintf(rval, "%.2f", m_x); } else if (!strcasecmp(strName, "Y")) { sprintf(rval, "%.2f", m_y); } else if (!strcasecmp(strName, "Z")) { sprintf(rval, "%.2f", m_z); } else if (!strcasecmp(strName, "NAME")) { strcpy(rval, GetName()); } else if (!strcasecmp(strName, "UID")) { sprintf(rval, "%d", m_uid); } else if (!strcasecmp(strName, "SIZE")) { sprintf(rval, "%d", GetSize()); } else return NULL; return rval; } // This function does nothing at present, but it // can be overridden in the derived classes. void CHSObject::ClearObjectAttrs(void) { } // Given a key and a value, the function tries to // load the value. If the key is not recognized by the // object, it returns FALSE. // // If you implement the WriteToFile() function, you MUST // have this function present to handle loading the values // in the database. They are in the form of key=value. BOOL CHSObject::HandleKey(int key, char *strValue, FILE *fp) { // Determine key, load value switch(key) { case HSK_X: m_x = atof(strValue); return TRUE; case HSK_Y: m_y = atof(strValue); return TRUE; case HSK_Z: m_z = atof(strValue); return TRUE; case HSK_NAME: if (m_name) delete [] m_name; m_name = new char [strlen(strValue) + 1]; strcpy(m_name, strValue); return TRUE; case HSK_UID: m_uid = atoi(strValue); return TRUE; case HSK_OBJNUM: m_objnum = atoi(strValue); return TRUE; case HSK_SIZE: m_size = atoi(strValue); return TRUE; case HSK_VISIBLE: m_visible = atoi(strValue); return TRUE; } return FALSE; } // You can override this function in your base class IF YOU WANT. // However, if you implement the HandleKey(), that's enough. // Override it if you want some extra initialization when your // derived object is loaded from the database. // // This function is called by some database loading routine, and passed // a file pointer which it uses to load variables from the database. // The variables are in key=value form, and this function just passes // the key and value to the HandleKey() function. If you haven't // overridden it, then the CHSObject handles everything that it can. // If you have overridden the HandleKey(), then the key and values // are passed to your function first. You can then pass unhandled // keys to the base object. BOOL CHSObject::LoadFromFile(FILE *fp) { char tbuf[256]; char strKey[64]; char strValue[64]; char *ptr; HS_DBKEY key; CHSUniverse *uDest; // Load until end of file or, more likely, an OBJECTEND // key. If we don't find the OBJECTEND key, the object // is incomplete. while(fgets(tbuf, 256, fp)) { // Strip newlines if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; // Extract key/value pairs extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); // Determine key, and handle it. key = HSFindKey(strKey); if (key == HSK_OBJECTEND) { // Exit loading EndLoadObject(); break; } else if (!HandleKey(key, strValue, fp)) { sprintf(tbuf, "WARNING: Object key \"%s\" found but not handled.", strKey); hs_log(tbuf); } } // Ensure that object is complete if (key != HSK_OBJECTEND) return FALSE; // Check to be sure the objnum is valid. if (!hsInterface.ValidObject(m_objnum)) return FALSE; // Set flags hsInterface.SetFlag(m_objnum, THING_HSPACE_OBJECT); // Set type hsInterface.AtrAdd(m_objnum, "HSDB_TYPE", tprintf("%d", m_type), GOD); // Add to universe uDest = uaUniverses.FindUniverse(m_uid); if (!uDest) { sprintf(tbuf, "WARNING: HSpace object #%d has an invalid UID. Adding to default universe.", m_objnum); hs_log(tbuf); uDest = NULL; for (int jdx = 0; jdx < HS_MAX_UNIVERSES; jdx++) { if (uDest = uaUniverses.GetUniverse(jdx)) break; } if (!uDest) { hs_log("ERROR: Unable to find default universe."); return FALSE; } if (!uDest->AddObject(this)) { hs_log("ERROR: Failed to add to default universe."); return FALSE; } // Set the new ID of the valid universe. m_uid = uDest->GetID(); } else { if (!uDest->AddObject(this)) { sprintf(tbuf, "WARNING: HSpace object #%d was not be added to universe.", m_objnum); hs_log(tbuf); } } return TRUE; } // This function is called by some database saving routine. If // you have derived an object from CHSObject and have attributes // that you want written to the database, you MUST override this // in your derived class. You must also, then, implement the // HandleKey() function to handle loading those values. void CHSObject::WriteToFile(FILE *fp) { // Write attributes to file fprintf(fp, "OBJNUM=%d\n", m_objnum); if (m_name) fprintf(fp, "NAME=%s\n", m_name); fprintf(fp, "X=%.2f\n", m_x); fprintf(fp, "Y=%.2f\n", m_y); fprintf(fp, "Z=%.2f\n", m_z); fprintf(fp, "UID=%d\n", m_uid); fprintf(fp, "VISIBLE=%d\n", m_visible); fprintf(fp, "SIZE=%d\n", m_size); } // Returns the name of the object. char *CHSObject::GetName(void) { if (!m_name) return "No Name"; return m_name; } // Sets the name of the object. void CHSObject::SetName(char *strName) { if (!strName) return; if (m_name) delete [] m_name; m_name = new char [strlen(strName) + 1]; strcpy(m_name, strName); } // This function does nothing, but it can be overridden by // derived objects to handle HSpace cycles. For example, ships // want to travel, do sensor sweeps, etc. The generic CHSObject // doesn't have any cyclic stuff to do. void CHSObject::DoCycle(void) { // Do nothing } // Returns TRUE if the two objects are equal. That is to say that // their object dbrefs are equal. BOOL CHSObject::operator ==(CHSObject &cRVal) { if (cRVal.GetDbref() == m_objnum) return TRUE; return FALSE; } BOOL CHSObject::operator ==(CHSObject *cRVal) { if (cRVal->GetDbref() == m_objnum) return TRUE; return FALSE; } UINT CHSObject::GetSize(void) { return m_size; } HS_TYPE CHSObject::GetType(void) { return m_type; } double CHSObject::GetX(void) { return m_x; } double CHSObject::GetY(void) { return m_y; } double CHSObject::GetZ(void) { return m_z; } // Returns the ANSI character string used to define the // color of the object. Each object should have its own color .. // or none at all. Basic objects have no color. Override this // member function in your base class to provide a color. char *CHSObject::GetObjectColor(void) { return ANSI_HILITE; } // Returns the character representation of the object. This can // be used in maps and whatever. char CHSObject::GetObjectCharacter(void) { return '.'; } UINT CHSObject::GetUID(void) { return m_uid; } dbref CHSObject::GetDbref(void) { return m_objnum; } void CHSObject::SetDbref(dbref objnum) { m_objnum = objnum; // Set the type attribute on the object if (hsInterface.ValidObject(objnum)) hsInterface.AtrAdd(objnum, "HSDB_TYPE", tprintf("%d", m_type), GOD); } void CHSObject::SetUID(UINT uid) { m_uid = uid; } void CHSObject::SetX(double x) { m_x = x; } void CHSObject::SetY(double y) { m_y = y; } void CHSObject::SetZ(double z) { m_z = z; } // This function returns NULL because the function should // be implemented specifically on the derived class. CHSConsole *CHSObject::FindConsole(dbref obj) { return NULL; } // // Linked list functions // CHSObject *CHSObject::GetNext(void) { return m_next; } CHSObject *CHSObject::GetPrev(void) { return m_prev; } void CHSObject::SetNext(CHSObject *cObj) { m_next = cObj; } void CHSObject::SetPrev(CHSObject *cObj) { m_prev = cObj; } // Override this function in your derived object class to handle // when another object locks onto it (or unlocks). void CHSObject::HandleLock(CHSObject *cLocker, BOOL bLocking) { // cLocker is the other object that is locking onto // us. // // bLocking is TRUE if the object is locking. FALSE, // if unlocking. // Do nothing } // Override this function in your derived object class to // handle damage from another object that is attacking. void CHSObject::HandleDamage(CHSObject *cSource, CHSWeapon *cWeapon, int strength, CHSConsole *cConsole, int iSysType) { // Strength is the amount of damage inflicted. It is // up to you to handle that damage in some way. // You can use cConsole to get the console that // fired the shot. // iSysType is the type of system preferred to damage. } // Can be used to explode the object, for whatever reason. void CHSObject::ExplodeMe(void) { CHSUniverse *uSource; // Find my universe uSource = uaUniverses.FindUniverse(m_uid); if (uSource) { // Remove me from active space. uSource->RemoveActiveObject(this); } } // Override this function in your derived class to handle // the end of an object loading from the database. When // the loader for the object database encounters the end // of the object definition, it'll call this routine to // let your object handle any final changes. void CHSObject::EndLoadObject(void) { // Nothing to do for base objects } // This function can be called by a scanning object to // get a scan report. Because scan reports can be different // for each derived type of object, you should override this // function to give custom scanning information. The // information should be sent to the player variable // supplied. The id variable indicates whether the object // being scanned is on the scanning objects sensors and how // well it has been identified. void CHSObject::GiveScanReport(CHSObject *cScanner, dbref player, BOOL id) { char tbuf[256]; // Print a header sprintf(tbuf, "%s%s.------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Scan Report %30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, id ? GetName() : "Unknown", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >----------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Give object info sprintf(tbuf, "%s%s| %sX:%s %9.0f %s%sSize:%s %-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetX(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, GetSize(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sY:%s %9.0f%35s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetY(), " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sZ:%s %9.0f%35s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetZ(), " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Finish the report sprintf(tbuf, "%s%s`------------------------------------------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Returns the motion vector for the object. CHSVector &CHSObject::GetMotionVector(void) { return m_motion_vector; } // Returns the current velocity for the object int CHSObject::GetSpeed(void) { return m_current_speed; } // // CHSVector implementation // CHSVector::CHSVector(void) { ci = cj = ck = 0; } CHSVector::CHSVector(double ii, double jj, double kk) { ci = ii; cj = jj; ck = kk; } BOOL CHSVector::operator == (CHSVector &vec) { if (vec.ci == ci && vec.cj == cj && vec.ck == ck) return TRUE; return FALSE; } void CHSVector::operator = (CHSVector &vec) { ci = vec.ci; cj = vec.cj; ck = vec.ck; } CHSVector &CHSVector::operator +(CHSVector &vec) { int ti, tj, tk; ti = ci + vec.ci; tj = cj + vec.cj; tk = ck + vec.ck; static CHSVector newVec(ti, tj, tk); return newVec; } double CHSVector::i(void) { return ci; } double CHSVector::j(void) { return cj; } double CHSVector::k(void) { return ck; } void CHSVector::operator +=(CHSVector &vec) { ci += vec.ci; cj += vec.cj; ck += vec.ck; } double CHSVector::DotProduct(CHSVector &vec) { double rval; rval = (ci * vec.ci) + (cj * vec.cj) + (ck * vec.ck); if (rval > 1) rval = 1; else if (rval < -1) rval = -1; return rval; } src/hspace/hsobjects.h 100664 767 767 25702 7141305141 13174 0 ustar mux mux #ifndef __HSOBJECTS_INCLUDED__ #define __HSOBJECTS_INCLUDED__ #include "hstypes.h" #include "hsclass.h" #include "hsweapon.h" #include "hsfuel.h" // A class that represents a vector. You can do lots of // things with this class. class CHSVector { public: CHSVector(void); CHSVector(double, double, double); double i(void); double j(void); double k(void); void operator=(CHSVector &); BOOL operator==(CHSVector &); CHSVector &operator+(CHSVector &); void operator+=(CHSVector &); double DotProduct(CHSVector &); protected: double ci, cj, ck; // The coefficients for the vector }; // Possible object types. If you're adding any new types of objects // to space, you have to add a listing here. enum HS_TYPE { HST_NOTYPE = 0, HST_SHIP, HST_MISSILE, HST_PLANET, HST_WORMHOLE, HST_BLACKHOLE, HST_NEBULA, HST_ASTEROID }; class CHSConsole; // Base HSpace object class class CHSObject { public: CHSObject(void); virtual ~CHSObject(void); // Access methods double GetX(void); double GetY(void); double GetZ(void); UINT GetUID(void); dbref GetDbref(void); char *GetName(void); void SetX(double); void SetY(double); void SetZ(double); void SetUID(UINT); void SetName(char *); void SetDbref(dbref); BOOL IsVisible(void); CHSVector &GetMotionVector(void); // Operator to compare objects. BOOL operator==(CHSObject &); BOOL operator==(CHSObject *); virtual int GetSpeed(void); virtual void HandleMessage(char *, int, long *data = NULL); virtual void DoCycle(void); virtual void ClearObjectAttrs(void); virtual void WriteToFile(FILE *); // Override this. virtual void HandleLock(CHSObject *, BOOL); virtual void HandleDamage(CHSObject *, CHSWeapon *, int, CHSConsole *, int); virtual void ExplodeMe(void); virtual void GiveScanReport(CHSObject *, dbref, BOOL); virtual void EndLoadObject(void); virtual char *GetObjectColor(void); // oooh Color. virtual char GetObjectCharacter(void); virtual char *GetAttributeValue(char *); virtual BOOL SetAttributeValue(char *, char *); virtual BOOL IsActive(void); virtual BOOL LoadFromFile(FILE *); // Can be overridden if you want virtual UINT GetEngSystemTypes(int *); virtual UINT GetSize(void); virtual CHSSystemArray *GetEngSystemArray(void); virtual CHSConsole *FindConsole(dbref); virtual CHSEngSystem *GetEngSystem(int); HS_TYPE GetType(void); // Linked list access functions (if needed) void SetNext(CHSObject *); void SetPrev(CHSObject *); CHSObject *GetNext(void); CHSObject *GetPrev(void); protected: // Methods // You MUST implement this function in your derived // object if you have custom information that's loaded // from the object db. Otherwise, you can just initialize // your variables in the constructor and let the CHSObject // handle any keyed information in the database. virtual BOOL HandleKey(int, char *, FILE *); dbref m_objnum; // Unique object identifier double m_x; // Coordinate locations double m_y; double m_z; UINT m_uid; // Universe membership BOOL m_visible; int m_size; int m_current_speed; char *m_name; enum HS_TYPE m_type; CHSVector m_motion_vector; // These can be used to implement a linked list, // but they may not be used. CHSObject *m_prev; CHSObject *m_next; }; // A generic console object class CHSConsole { public: CHSConsole(void); ~CHSConsole(void); void WriteObjectAttrs(void); void ClearObjectAttrs(void); void SetOwner(dbref); void HandleMessage(char *, int); void AdjustHeading(int, int); void SetOwnerObj(CHSObject *); void SetMissileBay(CHSMissileBay *); void DoCycle(void); void SetComputer(CHSSysComputer *); char *GetAttributeValue(char *); BOOL SetAttributeValue(char *, char *); UINT GetMaximumPower(void); BOOL LoadFromObject(dbref); BOOL IsOnline(void); BOOL OnFrq(double); // On a given frequency or not. int GetXYHeading(void); int GetZHeading(void); dbref GetOwner(void); CHSObject *GetObjectLock(void); CHSVector &GetHeadingVector(void); CHSWeaponArray *GetWeaponArray(void); // These commands interact with players in the game. BOOL AddWeapon(dbref, int); void LockTargetID(dbref, int); void UnlockWeapons(dbref); void GiveGunneryReport(dbref); void DeleteWeapon(dbref, int); void ConfigureWeapon(dbref, int, int); void LoadWeapon(dbref, int); void ChangeHeading(dbref, int, int); void FireWeapon(dbref, int); void PowerUp(dbref); void PowerDown(dbref); void GiveTargetReport(dbref); void UnloadWeapon(dbref, int); void SetAutoload(dbref, BOOL); void SetAutoRotate(dbref, BOOL); void SetSystemTarget(dbref, int); // Attributes dbref m_objnum; protected: // Member functions void LoadWeapons(char *); BOOL IsInCone(CHSObject *); // Attributes dbref m_owner; BOOL m_online; CHSSysComputer *m_computer; // Source of information int m_xyheading; int m_xyoffset; // XY offset from front of ship int m_zoffset; // Z offset from front of ship int m_zheading; int m_arc; // Firing arc int m_targetting; // Which system is being targetted BOOL m_can_rotate; // Console can rotate like a turret BOOL m_autoload; BOOL m_autorotate; CHSObject *m_target_lock; CHSWeaponArray *m_weapon_array; CHSObject *m_ownerObj; CHSMissileBay *m_missile_bay; }; // This generic landing location class can be used for landing // pads on planets or as landing bays in a ship. #define HS_LANDING_CODE_LEN 8 #define HS_MAX_LANDING_LOCS 15 class CHSLandingLoc { public: // Methods CHSLandingLoc(void); ~CHSLandingLoc(void); void ClearObjectAttrs(void); void WriteObjectAttrs(void); void WriteToFile(FILE *); void HandleMessage(char *, int); void DeductCapacity(int); void SetActive(BOOL); void SetOwnerObject(CHSObject *); BOOL HandleKey(int, char *, FILE *); char *GetAttributeValue(char *); BOOL SetAttributeValue(char *, char *); BOOL CodeRequired(void); BOOL LoadFromObject(dbref); BOOL IsActive(void); BOOL CodeClearance(char *); BOOL CanAccomodate(CHSObject *); CHSObject *GetOwnerObject(void); // Attributes dbref objnum; protected: CHSObject *m_ownerObj; int m_capacity; int m_max_capacity; // -1 for unlimited char strCode[9]; BOOL bActive; }; #define MAX_SHIP_ROOMS 250 #define MAX_SHIP_CONSOLES 20 #define MAX_BOARD_LINKS 5 class CHSTerritory; // From hsterritory.h // The generic ship object, which contains information about its // class, weapons, etc. class CHSShip : public CHSObject { public: CHSShip(void); ~CHSShip(void); float CloakingEffect(void); // 0 - 1.00 UINT ClassNum(void); UINT GetXYHeading(void); UINT GetMaxHullPoints(void); UINT GetHullPoints(void); UINT GetSize(void); // Overrides the base class UINT GetEngSystemTypes(int *); int GetZHeading(void); int GetSpeed(void); dbref GetDockedLocation(void); dbref Clone(void); BOOL LoadFromObject(dbref); BOOL IsActive(void); BOOL SetClassInfo(UINT); BOOL AddConsole(dbref); BOOL RemoveConsole(dbref); BOOL SetAttributeValue(char *, char *); BOOL SetSystemAttribute(char *, char *, char *); BOOL AddSroom(dbref); BOOL DeleteSroom(dbref); BOOL CanDrop(void); BOOL AddLandingLoc(dbref); BOOL InHyperspace(void); BOOL IsDestroyed(void); BOOL MakeBoardLink(CHSShip *, BOOL); BOOL Landed(void); BOOL IsObjectLocked(CHSObject *); void KillShipCrew(const char *); void EndLoadObject(void); void MoveShipObject(dbref); void TotalRepair(void); // Repairs everything void DoCycle(void); void ClearObjectAttrs(void); void WriteObjectAttrs(void); void WriteToFile(FILE *); void SetHeadingVector(int, int, int); char *GetObjectColor(void); char *GetBoardingCode(void); char *GetAttributeValue(char *); char GetObjectCharacter(void); void HandleMessage(char *, int, long *data = NULL); void HandleLock(CHSObject *, BOOL); void HandleDamage(CHSObject *, CHSWeapon *, int, CHSConsole *, int); void ExplodeMe(void); void GiveScanReport(CHSObject *, dbref, BOOL); CHSConsole *GetConsole(UINT); CHSConsole *FindConsole(dbref); // Locates a console object CHSLandingLoc *GetLandingLoc(int); CHSLandingLoc *FindLandingLoc(dbref); CHSEngSystem *GetEngSystem(int); CHSSystemArray *GetEngSystemArray(void); SENSOR_CONTACT *GetSensorContact(CHSObject *); SENSOR_CONTACT *GetSensorContact(int); // Methods that players interact with void GiveEngSysReport(dbref); void SetSystemPower(dbref, char *, int, BOOL); void ChangeSystemPriority(dbref, char *, int); void SetVelocity(dbref, int); void SetHeading(dbref, int xy = -1, int z = -1); void GiveSensorReport(dbref, HS_TYPE tType = HST_NOTYPE); void GiveVesselStats(dbref); void GiveNavigationStatus(dbref); void LandVessel(dbref, int, int, char *); void UndockVessel(dbref); void EngageAfterburn(dbref, BOOL); void EngageJumpDrive(dbref, BOOL); void DoBoardLink(dbref, int); void DoBreakBoardLink(dbref, int); void DisembarkPlayer(dbref, int); void ScanObjectID(dbref, int); BOOL SetNumMissiles(dbref, int, int); BOOL SetMapRange(dbref, int); CHSMissileBay *GetMissileBay(void); protected: // Methods CHSSysShield *DetermineHitShield(int, int); dbref CloneRoom(dbref, int *, CHSShip *); // Clones a specific room recursively BOOL HandleKey(int, char *, FILE *); BOOL LoadSystem(FILE *); void EnterHyperspace(void); void ExitHyperspace(void); void Travel(void); void SensorSweep(void); void HandleSensors(void); void HandleSystems(void); void HandleLifeSupport(void); void NotifyConsoles(char *, int); // Sends a message to all consoles void NotifySrooms(char *); // Send a message to all ship rooms void ChangeHeading(void); void RecomputeVectors(void); void InitLanding(dbref, SENSOR_CONTACT *, CHSLandingLoc *); void HandleLanding(void); void HandleUndocking(void); void ConfirmBoardLinks(void); void ResurrectMe(void); void HandleCommMsg(const char *, long *); CHSLandingLoc *NewLandingLoc(void); // Attributes dbref m_objlocation; // Dbref where it's docked or dropped char *m_ident; char *m_boarding_code; BOOL *m_can_drop; int *m_cargo_size; CHSTerritory *m_territory; // Territory we're in. CHSLandingLoc *m_landing_target; // Valid only during landing int m_current_xyheading; int m_desired_xyheading; int m_current_zheading; int m_desired_zheading; int m_drop_status; int m_dock_status; int m_class; int m_hull_points; int m_map_range; int m_current_speed; BOOL bGhosted; // Life support failed? BOOL bReactorOnline; BOOL m_destroyed; BOOL m_docked; BOOL m_dropped; BOOL m_in_space; BOOL m_hyperspace; // In warp/hyperspace or not. CHSObject *m_target; // Used for locking onto a target. // Registered ship rooms dbref m_ship_rooms[MAX_SHIP_ROOMS]; // Registered consoles. NOTE: Ships initially // start with NO consoles. The object representing // the ship may or may NOT be a console. CHSConsole *m_console_array[MAX_SHIP_CONSOLES]; // Landing bays CHSLandingLoc *m_landing_locs[HS_MAX_LANDING_LOCS]; // Boarding links with other ships CHSShip *m_board_links[MAX_BOARD_LINKS]; // Ship class info HSSHIPCLASS *m_classinfo; // Engineering systems CHSSystemArray m_systems; // Missile bay for the ship CHSMissileBay m_missile_bay; }; #endif // __HSOBJECTS_INCLUDED__ src/hspace/hspace.cpp 100644 767 767 11072 7141305141 12777 0 ustar mux mux #include "hscopyright.h" // This has to come before the other includes, // or Windows really screws up #ifdef WIN32 #include <winsock.h> #undef OPAQUE /* Clashes with flags.h */ #endif #ifndef WIN32 #include <strings.h> #endif #include "hspace.h" #include "hsuniverse.h" #include "hscmds.h" #include "hsfuncs.h" #include "hsconf.h" #include "hsdb.h" #include "hsutils.h" // The one and only, HSpace instance! CHSpace HSpace; CHSpace::CHSpace(void) { m_cycling = FALSE; m_cycle_ms = 0; m_attrs_need_cleaning = FALSE; } // Initializes HSpace. The reboot variable indicates whether the // server is in reboot mode, in which the proceses will be swapped // instead of starting from cold boot. void CHSpace::InitSpace(int reboot) { // Load the config file first. if (!HSCONF.LoadConfigFile(HSPACE_CONFIG_FILE)) return; if (!dbHSDB.LoadDatabases()) return; // Auto cycle? if (HSCONF.autostart) m_cycling = TRUE; } double CHSpace::CycleTime(void) { return m_cycle_ms; } // Called once per second externally to do all of the stuff that // HSpace needs to do each cycle. void CHSpace::DoCycle(void) { #ifndef WIN32 struct timeval tv; #endif double firstms, secondms; CHSObject *cObj; UINT idx, jdx; CHSUniverse *uSrc; if (!m_cycling) return; // Grab the current milliseconds #ifdef WIN32 firstms = timeGetTime(); #else gettimeofday(&tv, (struct timezone *) NULL); firstms = (tv.tv_sec * 1000000) + tv.tv_usec; #endif // If attributes need cleaned up, do that. if (m_attrs_need_cleaning) { dbHSDB.CleanupDBAttrs(); m_attrs_need_cleaning = FALSE; } // Do cyclic stuff for space objects. for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { uSrc = uaUniverses.GetUniverse(idx); if (!uSrc) continue; // Grab all of the objects in the universe, and tell them // to cycle. for (jdx = 0; jdx < HS_MAX_OBJECTS; jdx++) { cObj = uSrc->GetUnivObject(jdx); if (!cObj) continue; cObj->DoCycle(); } } // Cycle stuff done for CHSObjects // Grab the current milliseconds, and subtract from the first #ifdef WIN32 secondms = timeGetTime(); m_cycle_ms = secondms - firstms; #else gettimeofday(&tv, (struct timezone *) NULL); secondms = (tv.tv_sec * 1000000) + tv.tv_usec; m_cycle_ms = (secondms - firstms) * .001; #endif } void CHSpace::DumpDatabases(void) { dbHSDB.DumpDatabases(); m_attrs_need_cleaning = TRUE; } BOOL CHSpace::LoadConfigFile(char *lpstrPath) { return TRUE; } char *CHSpace::DoFunction(char *func, dbref executor, char **args) { HSFUNC *hFunc; hFunc = hsFindFunction(func); if (!hFunc) return "#-1 HSpace function not found."; else return hFunc->func(executor, args); } #ifdef MUX void CHSpace::DoCommand(int command, int subcommand, char *arg1, char *arg2, dbref player) { hs_command hCommand; hCommand = LookupCommand(command, subcommand); if( !hCommand ) { notify(player, "HSpace command not found."); return; } // Log the command first if (HSCONF.log_commands) hs_log(tprintf("CMD: (#%d) %s/%s %s=%s", player, LookupCommandName(command), LookupSubCommandName(command, subcommand) ,arg1, arg2)); hCommand(player, arg1, arg2); } #endif #ifdef PENNMUSH void CHSpace::DoCommand(char *cmd, char *switches, char *arg_left, char *arg_right, dbref player) { HSPACE_COMMAND *hCmd; if (!strcasecmp(cmd, "@space")) { hCmd = hsFindCommand(switches, hsSpaceCommandArray); } else if (!strcasecmp(cmd, "@nav")) { hCmd = hsFindCommand(switches, hsNavCommandArray); } else if (!strcasecmp(cmd, "@console")) { hCmd = hsFindCommand(switches, hsConCommandArray); } else if (!strcasecmp(cmd, "@eng")) { hCmd = hsFindCommand(switches, hsEngCommandArray); } else { notify(player, "Invalid HSpace command."); return; } if (!hCmd) { notify(player, "Invalid HSpace switch supplied with command."); return; } // Check the permissions of the command if (hCmd->perms & HCP_GOD) { if (!God(player)) { notify(player, "HSpace command restricted to God."); return; } } if (hCmd->perms & HCP_WIZARD) { if (!Wizard(player)) { notify(player, "HSpace command restricted to wizards."); return; } } // Log the command first if (HSCONF.log_commands) { char tbuf[1024]; sprintf(tbuf, "CMD: (#%d) %s/%s %s=%s", player, cmd, switches, arg_left, arg_right); hs_log(tbuf); } // Perms look ok, call the function. hCmd->func(player, arg_left, arg_right); } #endif BOOL CHSpace::Active(void) { return m_cycling; } // Turns the space cycle on/off void CHSpace::SetCycle(BOOL bStart) { m_cycling = bStart; } src/hspace/hspace.h 100644 767 767 1617 7141305141 12430 0 ustar mux mux #ifndef __HSPACE_INCLUDED__ #define __HSPACE_INCLUDED__ #include "hstypes.h" // Message definitions, used when notifying consoles, etc. enum HS_MESSAGE { MSG_GENERAL = 0, MSG_SENSOR, MSG_ENGINEERING, MSG_COMBAT, MSG_COMMUNICATION }; // The CHSpace Object is the master object for all of HSpace. // It rules all!!! class CHSpace { public: CHSpace(void); // Methods void InitSpace(int rebooting = 0); void DumpDatabases(void); #ifdef PENNMUSH void DoCommand(char *, char *, char *, char *, dbref); #endif #ifdef MUX void DoCommand(int, int, char *, char *, dbref); #endif char *DoFunction(char *, dbref, char **); void DoCycle(void); void SetCycle(BOOL); double CycleTime(void); BOOL Active(void); private: // Methods BOOL LoadConfigFile(char *); //Attributes BOOL m_cycling; BOOL m_attrs_need_cleaning; double m_cycle_ms; }; extern CHSpace HSpace; #endif // __HSPACE_INCLUDED__ src/hspace/hsplanet.cpp 100664 767 767 27576 7141305141 13374 0 ustar mux mux // // hsplanet.cpp // // Handles all of the methods for the CHSPlanet object. // // #include "hscopyright.h" #include "hsobjects.h" #include "hsuniverse.h" #include <stdlib.h> #include "hsinterface.h" #include "hsutils.h" #include "hsexterns.h" #include <string.h> // Constructor CHSPlanet::CHSPlanet(void) { int idx; m_type = HST_PLANET; for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) m_landing_locs[idx] = NULL; } CHSPlanet::~CHSPlanet(void) { int idx; // Delete landing locations for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) delete m_landing_locs[idx]; } } // Planets are green char *CHSPlanet::GetObjectColor(void) { static char tbuf[32]; sprintf(tbuf, "%s%s", ANSI_HILITE, ANSI_GREEN); return tbuf; } // Planets are little o's char CHSPlanet::GetObjectCharacter(void) { return 'o'; } // Overridden from the CHSCelestial class BOOL CHSPlanet::HandleKey(int key, char *strValue, FILE *fp) { CHSLandingLoc *cLoc; dbref objnum; // Find the key and handle it switch(key) { case HSK_SIZE: m_size = atoi(strValue); return TRUE; case HSK_LANDINGLOC: cLoc = NewLandingLoc(); if (!cLoc) { hs_log("ERROR: Couldn't add specified landing location."); } else { objnum = atoi(strValue); if (!hsInterface.ValidObject(objnum)) return TRUE; cLoc->SetOwnerObject(this); cLoc->LoadFromObject(objnum); // Set the planet attribute hsInterface.AtrAdd(objnum, "HSDB_PLANET", tprintf("#%d", m_objnum), GOD); } return TRUE; default: // Pass it up to CHSCelestial return (CHSCelestial::HandleKey(key, strValue, fp)); } } // Overridden from the CHSCelestial class void CHSPlanet::WriteToFile(FILE *fp) { int idx; // Write base class info first, then our's. CHSCelestial::WriteToFile(fp); // Now our's // Landing locs for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) { fprintf(fp, "LANDINGLOC=%d\n", m_landing_locs[idx]->objnum); m_landing_locs[idx]->WriteObjectAttrs(); } } } // Call this function to find a landing location based on its // room number. CHSLandingLoc *CHSPlanet::FindLandingLoc(dbref objnum) { int idx; for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]->objnum == objnum) return m_landing_locs[idx]; } return NULL; } // Clears attributes specific to the planet object void CHSPlanet::ClearObjectAttrs() { int idx; CHSCelestial::ClearObjectAttrs(); // Clear landing location attrs for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) m_landing_locs[idx]->ClearObjectAttrs(); } } CHSLandingLoc *CHSPlanet::NewLandingLoc(void) { int idx; // Check to see if it'll fit for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx] == NULL) break; } if (idx == HS_MAX_LANDING_LOCS) { return NULL; } m_landing_locs[idx] = new CHSLandingLoc; return m_landing_locs[idx]; } BOOL CHSPlanet::AddLandingLoc(dbref room) { CHSLandingLoc *cLoc; char tbuf[256]; // Temp string storage // Grab a new landing loc cLoc = NewLandingLoc(); if (!cLoc) { sprintf(tbuf, "WARNING: Maximum landing locations reached for planet %s.", m_name); hs_log(tbuf); return FALSE; } // Initialize some attrs cLoc->SetActive(TRUE); cLoc->objnum = room; // Set the flag hsInterface.SetFlag(room, ROOM_HSPACE_LANDINGLOC); // Set it's owner to us. cLoc->SetOwnerObject(this); // Set the planet attribute hsInterface.AtrAdd(room, "HSDB_PLANET", tprintf("#%d", m_objnum), GOD); return TRUE; } // Called upon to set an attribute on the planet object. If // the attribute name is not found, it's passed up the object // hierarchy to the base objects. BOOL CHSPlanet::SetAttributeValue(char *strName, char *strValue) { return (CHSCelestial::SetAttributeValue(strName, strValue)); } // Returns a character string containing the value of the // requested attribute. char *CHSPlanet::GetAttributeValue(char *strName) { static char rval[256]; int idx; *rval = '\0'; if (!strcasecmp(strName, "LANDINGLOCS")) { char tmp[16]; for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) { if (!*rval) sprintf(tmp, "#%d", m_landing_locs[idx]->objnum); else sprintf(tmp, " #%d", m_landing_locs[idx]->objnum); strcat(rval, tmp); } } } else return CHSCelestial::GetAttributeValue(strName); return rval; } // Retrieves a landing location given a slot number (0 - n) CHSLandingLoc *CHSPlanet::GetLandingLoc(int which) { if (which < 0 || which >= HS_MAX_LANDING_LOCS) return NULL; return m_landing_locs[which]; } void CHSPlanet::GiveScanReport(CHSObject *cScanner, dbref player, BOOL id) { char tbuf[256]; int nLocs; // Determine how many landing locs we have int idx; nLocs = 0; for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) nLocs++; } // Print a header sprintf(tbuf, "%s%s.------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Scan Report %30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, id ? GetName() : "Unknown", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >----------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Give object info sprintf(tbuf, "%s%s| %sX:%s %9.0f %s%sSize:%s %-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetX(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, GetSize(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sY:%s %9.0f%35s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetY(), " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sZ:%s %9.0f%35s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetZ(), " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Do we have any landing locs to report? if (nLocs > 0) { // Print em baby. notify(player, tprintf("%s%s|%48s|%s", ANSI_HILITE, ANSI_BLUE, " ", ANSI_NORMAL)); sprintf(tbuf, "%s%s| %sLanding Locations:%s %-2d%26s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, nLocs, " ", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %s[%s##%s] Name Active Code %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_WHITE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); char strPadName[32]; for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) { strncpy(strPadName, Name(m_landing_locs[idx]->objnum), 32); strPadName[23] = '\0'; sprintf(tbuf, "%s%s|%s %2d %-25s %3s %3s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, idx + 1, strPadName, m_landing_locs[idx]->IsActive() ? "Yes" : "No", m_landing_locs[idx]->CodeRequired() ? "Yes" : "No", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } } } // Finish the report sprintf(tbuf, "%s%s`------------------------------------------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // // CHSLandingLoc stuff // CHSLandingLoc::CHSLandingLoc(void) { objnum = -1; *strCode = '\0'; bActive = TRUE; m_max_capacity = -1; // Unlimited m_capacity = 0; m_ownerObj = NULL; } CHSLandingLoc::~CHSLandingLoc(void) { // Clear attributes and flags hsInterface.UnsetFlag(objnum, ROOM_HSPACE_LANDINGLOC); ClearObjectAttrs(); } BOOL CHSLandingLoc::LoadFromObject(dbref obj) { objnum = obj; if (hsInterface.AtrGet(obj, "HSDB_CODE")) { strcpy(strCode, hsInterface.m_buffer); } if (hsInterface.AtrGet(obj, "HSDB_ACTIVE")) { bActive = hsInterface.m_buffer[0] == '1' ? TRUE : FALSE; } if (hsInterface.AtrGet(obj, "HSDB_MAX_CAPACITY")) { m_max_capacity = atoi(hsInterface.m_buffer); } if (hsInterface.AtrGet(obj, "HSDB_CAPACITY")) { m_capacity = atoi(hsInterface.m_buffer); } // Set some default info on the room hsInterface.SetFlag(obj, ROOM_HSPACE_LANDINGLOC); // Clear attributes ClearObjectAttrs(); return TRUE; } void CHSLandingLoc::WriteObjectAttrs(void) { hsInterface.AtrAdd(objnum, "HSDB_CODE", strCode, GOD); hsInterface.AtrAdd(objnum, "HSDB_ACTIVE", tprintf("%s", bActive ? "1" : "0"), GOD); hsInterface.AtrAdd(objnum, "HSDB_MAX_CAPACITY", tprintf("%d", m_max_capacity), GOD); hsInterface.AtrAdd(objnum, "HSDB_CAPACITY", tprintf("%d", m_capacity), GOD); } void CHSLandingLoc::ClearObjectAttrs(void) { hsInterface.AtrAdd(objnum, "HSDB_CODE", NULL, GOD); hsInterface.AtrAdd(objnum, "HSDB_ACTIVE", NULL, GOD); hsInterface.AtrAdd(objnum, "HSDB_CAPACITY", NULL, GOD); hsInterface.AtrAdd(objnum, "HSDB_MAX_CAPACITY", NULL, GOD); } // Returns a character string containing the value of the // requested attribute. char *CHSLandingLoc::GetAttributeValue(char *strName) { static char rval[32]; *rval = '\0'; if (!strcasecmp(strName, "CODE")) strcpy(rval, strCode); else if (!strcasecmp(strName, "ACTIVE")) sprintf(rval, "%d", bActive ? 1 : 0); else if (!strcasecmp(strName, "CAPACITY")) sprintf(rval, "%d", m_capacity); else if (!strcasecmp(strName, "MAX CAPACITY")) sprintf(rval, "%d", m_max_capacity); else return NULL; return rval; } // Set a value for a given attribute on the landing location BOOL CHSLandingLoc::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name .. set the value if (!strcasecmp(strName, "CODE")) { if (strlen(strValue) > 8) return FALSE; strcpy(strCode, strValue); return TRUE; } else if (!strcasecmp(strName, "ACTIVE")) { iVal = atoi(strValue); if (iVal == 0) bActive = FALSE; else bActive = TRUE; return TRUE; } else if (!strcasecmp(strName, "CAPACITY")) { iVal = atoi(strValue); m_capacity = iVal; return TRUE; } else if (!strcasecmp(strName, "MAX CAPACITY")) { iVal = atoi(strValue); m_max_capacity = iVal; return TRUE; } else return FALSE; } // Indicates whether the landing location is actively open or // not. BOOL CHSLandingLoc::IsActive(void) { return bActive; } // Indicates whether the supplied code matches the currently // set code. If no code is set, this always returns TRUE. BOOL CHSLandingLoc::CodeClearance(char *lpstrCode) { if (!*strCode) return TRUE; if (!strcasecmp(strCode, lpstrCode)) return TRUE; return FALSE; } // Handles a message, which for now is just giving it to the room void CHSLandingLoc::HandleMessage(char *lpstrMsg, int type) { hsInterface.NotifyContents(objnum, lpstrMsg); } // Indicates whether the landing location can accomodate // the given object based on size. BOOL CHSLandingLoc::CanAccomodate(CHSObject *cObj) { // Unlimited capacity? if (m_max_capacity < 0) return TRUE; // Compare current capacity and object size if (m_capacity < cObj->GetSize()) return FALSE; return TRUE; } void CHSLandingLoc::DeductCapacity(int change) { // If unlimited, do nothing. if (m_max_capacity < 0) return; m_capacity -= change; } // Sets the active status of the landing location void CHSLandingLoc::SetActive(BOOL bStat) { bActive = bStat; } // Sets the CHSObject that owns the landing location. void CHSLandingLoc::SetOwnerObject(CHSObject *cObj) { m_ownerObj = cObj; } // Returns the CHSObject that controls the landing location. CHSObject *CHSLandingLoc::GetOwnerObject(void) { return m_ownerObj; } // Returns TRUE or FALSE to indicate if a code is required. BOOL CHSLandingLoc::CodeRequired(void) { if (*strCode) return TRUE; else return FALSE; } src/hspace/hsship.cpp 100644 767 767 213011 7141305141 13047 0 ustar mux mux #include "hscopyright.h" #include "hsobjects.h" #include "hsinterface.h" #include "hsuniverse.h" #include <stdlib.h> #include "hsutils.h" #include "hsconf.h" #include "hspace.h" #include "hsexterns.h" #include "hsengines.h" #include <string.h> #include "hscomm.h" #include "hsdb.h" CHSShip::CHSShip(void) { int idx; // Initialize a slew of variables m_type = HST_SHIP; m_ident = NULL; m_target = NULL; m_current_xyheading = 0; m_desired_xyheading = 0; m_current_zheading = 0; m_desired_zheading = 0; m_hull_points = 1; m_map_range = 1000; m_drop_status = 0; m_dock_status = 0; bReactorOnline = FALSE; bGhosted = FALSE; m_in_space = TRUE; m_docked = FALSE; m_dropped = FALSE; m_destroyed = FALSE; m_hyperspace= FALSE; m_class = 0; m_boarding_code = NULL; m_territory = NULL; m_objlocation = NOTHING; // Overridables m_can_drop = NULL; m_cargo_size = NULL; memset(&m_classinfo, 0, sizeof(m_classinfo)); SetHeadingVector(0,0,0); // Initialize board links for (idx = 0; idx < MAX_BOARD_LINKS; idx++) m_board_links[idx] = NULL; // Initialize consoles for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) m_console_array[idx] = NULL; // Initialize ship rooms for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) m_ship_rooms[idx] = NOTHING; // Initialize landing locations for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) m_landing_locs[idx] = NULL; } CHSShip::~CHSShip(void) { int idx; if (m_ident) delete [] m_ident; // Delete consoles for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) delete m_console_array[idx]; } } // Determines whether the ship is actively in space or, perhaps, // docked or dropped. BOOL CHSShip::IsActive(void) { if (!m_docked && !m_dropped && m_in_space && !m_destroyed) return TRUE; return FALSE; } // Sets the heading vector on the ship to new coefficients void CHSShip::SetHeadingVector(int i, int j, int k) { CHSVector vec(i, j, k); m_motion_vector = vec; } // Given a class number, this function will setup the // appropriate pointers and system information so that // the ship becomes of that class type. The function // is not just used for changing a class. It's also // used when the ship is loaded from the database and // needs its class information setup. BOOL CHSShip::SetClassInfo(UINT uClass) { HSSHIPCLASS *hsClass; char tbuf[64]; CHSEngSystem *cSys; // Grab the class from the global array hsClass = caClasses.GetClass(uClass); if (!hsClass) { sprintf(tbuf, "Class info for class #%d not found.", uClass); hs_log(tbuf); return FALSE; } // Set the pointer to the class. m_classinfo = hsClass; // Set the class id in case it hasn't already m_class = uClass; // Now duplicate the systems information found in the // class. This is accomplished with the operator '=' // created in the CHSSystemArray object. m_systems = hsClass->m_systems; // Run through the systems, setting the owner to us. for (cSys = m_systems.GetHead(); cSys; cSys = cSys->GetNext()) cSys->SetOwner(this); // Do some fuel systems handling CHSFuelSystem *cFuel; cFuel = (CHSFuelSystem *)m_systems.GetSystem(HSS_FUEL_SYSTEM); if (cFuel) { CHSReactor *cReactor; cReactor = (CHSReactor *)m_systems.GetSystem(HSS_REACTOR); // Tell the reactor where to get fuel if (cReactor) { cReactor->SetFuelSource(cFuel); } // Tell the engines where to get fuel CHSSysEngines *cEngines; cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (cEngines) { cEngines->SetFuelSource(cFuel); } // Tell jump drives where to get fuel CHSJumpDrive *cJumpers; cJumpers = (CHSJumpDrive *)m_systems.GetSystem(HSS_JUMP_DRIVE); if (cJumpers) { cJumpers->SetFuelSource(cFuel); } } return TRUE; } BOOL CHSShip::AddConsole(dbref objnum) { int idx; int slot; // Verify that it's a good object if (!hsInterface.ValidObject(objnum)) return FALSE; // Find a slot slot = MAX_SHIP_CONSOLES; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { // Empty slot? if (!m_console_array[idx] && (slot == MAX_SHIP_CONSOLES)) slot = idx; // Console already in array? if (m_console_array[idx] && (m_console_array[idx]->m_objnum == objnum)) return FALSE; } if (slot == MAX_SHIP_CONSOLES) { char tbuf[256]; sprintf(tbuf, "WARNING: Maximum consoles for ship #%d reached.", m_objnum); hs_log(tbuf); return FALSE; } // Make a new console .. set the variables m_console_array[slot] = new CHSConsole; // Tell the console to load attributes from the object. // Even if it's a new console and new object, that's ok. m_console_array[slot]->LoadFromObject(objnum); // Record it's owner for later use in finding the // actual console object. m_console_array[slot]->SetOwner(m_objnum); // Record it's CHSObject owner m_console_array[slot]->SetOwnerObj(this); // Tell the console where our missile bay is m_console_array[slot]->SetMissileBay(&m_missile_bay); // Tell the console where our computer is CHSSysComputer *cComputer; cComputer = (CHSSysComputer *)m_systems.GetSystem(HSS_COMPUTER); if (cComputer) m_console_array[slot]->SetComputer(cComputer); return TRUE; } // Call this to have the object clear its attributes AND // all attrs in the base objects that were saved to objects // in the game. void CHSShip::ClearObjectAttrs(void) { UINT idx; CHSObject::ClearObjectAttrs(); // Clear console attributes for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) m_console_array[idx]->ClearObjectAttrs(); } } // Called upon to set an attribute value. If the attribute // name is not found, it's passed up to the base CHSObject // for handling. BOOL CHSShip::SetAttributeValue(char *strName, char *strValue) { int iVal; if (!strcasecmp(strName, "IDENT")) { if (m_ident) delete [] m_ident; if (strValue) { m_ident = new char[strlen(strValue) + 1]; strcpy(m_ident, strValue); } return TRUE; } else if (!strcasecmp(strName, "ZHEADING")) { iVal = atoi(strValue); if (iVal < -90 || iVal > 90) return FALSE; m_current_zheading = iVal; return TRUE; } else if (!strcasecmp(strName, "XYHEADING")) { iVal = atoi(strValue); if (iVal < 0 || iVal > 359) return FALSE; m_current_xyheading = iVal; return TRUE; } else if (!strcasecmp(strName, "DESTROYED")) { iVal = atoi(strValue); if (m_destroyed && !iVal) ResurrectMe(); m_destroyed = iVal; return TRUE; } else if (!strcasecmp(strName, "BOARDING CODE")) { if (m_boarding_code) delete [] m_boarding_code; if (strValue) { m_boarding_code = new char[strlen(strValue) + 1]; strcpy(m_boarding_code, strValue); } return TRUE; } else if (!strcasecmp(strName, "CARGO SIZE")) { if (!strValue || !*strValue) { if (m_cargo_size) { delete m_cargo_size; m_cargo_size = NULL; } return TRUE; } if (!m_cargo_size) m_cargo_size = new int; *m_cargo_size = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "CAN DROP")) { if (!strValue || !*strValue) { if (m_can_drop) { delete m_can_drop; m_can_drop = NULL; } return TRUE; } if (!m_can_drop) m_can_drop = new BOOL; *m_can_drop = atoi(strValue); return TRUE; } else if (!strcasecmp(strName, "DROPLOC")) { CHSUniverse *uDest; iVal = strtodbref(strValue); // If iVal < 0, then we set the vessel's // status to not-dropped. if (iVal < 0) { if (!m_dropped) // Do nothing return TRUE; uDest = uaUniverses.FindUniverse(m_uid); if (!uDest) return FALSE; uDest->AddActiveObject(this); // Put the ship into space. MoveShipObject(uDest->GetID()); m_dropped = FALSE; if (!m_docked) { m_objlocation = NOTHING; m_in_space = TRUE; } return TRUE; } else { if (!hsInterface.ValidObject(iVal)) return FALSE; MoveShipObject(iVal); m_dropped = TRUE; uDest = uaUniverses.FindUniverse(m_uid); if (uDest) uDest->RemoveActiveObject(this); m_in_space = FALSE; // See if we can find what HSpace object // we're on now. CHSObject *cDest; cDest = dbHSDB.FindObjectByRoom(iVal); if (!cDest) { m_objlocation = NOTHING; } else m_objlocation = cDest->GetDbref(); return TRUE; } } else if (!strcasecmp(strName, "HULL")) { iVal = atoi(strValue); m_hull_points = iVal; if (m_hull_points < 0 && !m_destroyed) ExplodeMe(); return TRUE; } else if (!strcasecmp(strName, "DOCKLOC")) { CHSUniverse *uDest; iVal = strtodbref(strValue); // If iVal < 0, then we set the vessel's // status to not-docked. if (iVal < 0) { if (!m_docked) // Do nothing return TRUE; uDest = uaUniverses.FindUniverse(m_uid); if (!uDest) return FALSE; uDest->AddActiveObject(this); // Put the ship into space. MoveShipObject(uDest->GetID()); m_docked = FALSE; if (!m_dropped) { m_objlocation = NOTHING; m_in_space = TRUE; } return TRUE; } else { if (!hsInterface.ValidObject(iVal)) return FALSE; MoveShipObject(iVal); m_docked = TRUE; uDest = uaUniverses.FindUniverse(m_uid); if (uDest) uDest->RemoveActiveObject(this); m_in_space = FALSE; // See if we can find what HSpace object // we're on now. CHSObject *cDest; cDest = dbHSDB.FindObjectByRoom(iVal); if (!cDest) { m_objlocation = NOTHING; } else m_objlocation = cDest->GetDbref(); return TRUE; } } else return CHSObject::SetAttributeValue(strName, strValue); } // Returns a character string containing the value of the // requested attribute. char *CHSShip::GetAttributeValue(char *strName) { static char rval[2048]; char tmp[32]; int idx; *rval = 0; if (!strcasecmp(strName, "IDENT")) { if (m_ident) strcpy(rval, m_ident); } else if (!strcasecmp(strName, "BLINKS")) { for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (m_board_links[idx]) { if (!*rval) sprintf(tmp, "#%d", m_board_links[idx]->GetDbref()); else sprintf(tmp, " #%d", m_board_links[idx]->GetDbref()); strcat(rval, tmp); } } } else if (!strcasecmp(strName, "SROOMS")) { for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (m_ship_rooms[idx] != NOTHING) { if (!*rval) sprintf(tmp, "#%d", m_ship_rooms[idx]); else sprintf(tmp, " #%d", m_ship_rooms[idx]); strcat(rval, tmp); } } } else if (!strcasecmp(strName, "CONSOLES")) { for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) { if (!*rval) sprintf(tmp, "#%d", m_console_array[idx]->m_objnum); else sprintf(tmp, " #%d", m_console_array[idx]->m_objnum); strcat(rval, tmp); } } } else if (!strcasecmp(strName, "DESTROYED")) { sprintf(rval, "%d", m_destroyed ? 1 : 0); } else if (!strcasecmp(strName, "BOARDING CODE")) { if (m_boarding_code) strcpy(rval, m_boarding_code); } else if (!strcasecmp(strName, "CAN DROP")) { sprintf(rval, "%d", m_can_drop ? *m_can_drop : m_classinfo->m_can_drop); } else if (!strcasecmp(strName, "OBJLOC")) { sprintf(rval, "#%d", m_objlocation); } else if (!strcasecmp(strName, "DROPLOC")) { sprintf(rval, "#%d", m_dropped ? Location(m_objnum) : -1); } else if (!strcasecmp(strName, "MAXHULL")) { sprintf(rval, "%d", GetMaxHullPoints()); } else if (!strcasecmp(strName, "HULL")) { sprintf(rval, "%d", GetHullPoints()); } else if (!strcasecmp(strName, "DOCKLOC")) { sprintf(rval, "#%d", m_docked ? Location(m_objnum) : -1); } else if (!strcasecmp(strName, "DXYHEADING")) sprintf(rval, "%d", m_desired_xyheading); else if (!strcasecmp(strName, "DZHEADING")) sprintf(rval, "%d", m_desired_zheading); else if (!strcasecmp(strName, "XYHEADING")) sprintf(rval, "%d", m_current_xyheading); else if (!strcasecmp(strName, "ZHEADING")) sprintf(rval, "%d", m_current_zheading); else if (!strcasecmp(strName, "CARGO SIZE")) { sprintf(rval, "%d", m_cargo_size ? *m_cargo_size : m_classinfo->m_cargo_size); } else if (!strcasecmp(strName, "CLASS")) sprintf(rval, "%d", m_class); else if (!strcasecmp(strName, "CLASSNAME")) strcpy(rval, m_classinfo->m_name); else return CHSObject::GetAttributeValue(strName); return rval; } // Adds a registered room to a ship BOOL CHSShip::AddSroom(dbref dbRoom) { int idx; // Find a slot for the room for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (m_ship_rooms[idx] == NOTHING) break; } if (idx >= MAX_SHIP_ROOMS) return FALSE; m_ship_rooms[idx] = dbRoom; return TRUE; } // Deletes a given console from the registered consoles BOOL CHSShip::RemoveConsole(dbref dbConsole) { int idx; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx] && (m_console_array[idx]->m_objnum == dbConsole)) { // Reset the flag hsInterface.UnsetFlag(dbConsole, THING_HSPACE_CONSOLE); // Free the object delete m_console_array[idx]; m_console_array[idx] = NULL; return TRUE; } } return FALSE; } UINT CHSShip::ClassNum(void) { return m_class; } // Deletes a given room from the registered srooms BOOL CHSShip::DeleteSroom(dbref dbRoom) { int idx; BOOL bFound = FALSE; // Run through the list, deleting any rooms that match. for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (m_ship_rooms[idx] == dbRoom) { bFound = TRUE; m_ship_rooms[idx] = NOTHING; } } if (bFound) return TRUE; else return FALSE; } CHSConsole *CHSShip::FindConsole(dbref dbConsole) { UINT idx; // Traverse our console array, looking for consoles // with matching dbrefs. for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx] && (m_console_array[idx]->m_objnum == dbConsole)) return m_console_array[idx]; } // Not found return NULL; } // Passed keys and values by the CHSObject LoadFromFile(). // We just have to handle them. BOOL CHSShip::HandleKey(int key, char *strValue, FILE *fp) { dbref obj; // Determine key and handle it switch(key) { case HSK_MISSILEBAY: // Load in missile bay info m_missile_bay.LoadFromFile(fp); return TRUE; case HSK_IDENT: if (m_ident) delete [] m_ident; m_ident = new char [strlen(strValue) + 1]; strcpy(m_ident, strValue); return TRUE; case HSK_BOARDING_CODE: if (m_boarding_code) delete [] m_boarding_code; m_boarding_code = new char [strlen(strValue) + 1]; strcpy(m_boarding_code, strValue); return TRUE; case HSK_LANDINGLOC: CHSLandingLoc *cLoc; dbref objnum; cLoc = NewLandingLoc(); if (!cLoc) { hs_log("ERROR: Couldn't add specified landing location."); } else { objnum = atoi(strValue); if (!hsInterface.ValidObject(objnum)) return TRUE; cLoc->SetOwnerObject(this); cLoc->LoadFromObject(objnum); // Set the planet attribute hsInterface.AtrAdd(objnum, "HSDB_SHIP", tprintf("#%d", m_objnum), GOD); } return TRUE; case HSK_CARGOSIZE: if (!m_cargo_size) m_cargo_size = new int; *m_cargo_size = atoi(strValue); return TRUE; case HSK_DROP_CAPABLE: if (!m_can_drop) m_can_drop = new BOOL; *m_can_drop = atoi(strValue); return TRUE; case HSK_HULL_POINTS: m_hull_points = atoi(strValue); return TRUE; case HSK_OBJLOCATION: m_objlocation = atoi(strValue); if (!hsInterface.ValidObject(m_objlocation)) m_objlocation = NOTHING; return TRUE; case HSK_CLASSID: m_class = atoi(strValue); SetClassInfo(m_class); return TRUE; case HSK_DROPPED: m_dropped = atoi(strValue); if (m_dropped) m_in_space = FALSE; return TRUE; case HSK_DOCKED: m_docked = atoi(strValue); if (m_docked) m_in_space = FALSE; return TRUE; case HSK_DESTROYED: m_destroyed = atoi(strValue); return TRUE; case HSK_XYHEADING: m_current_xyheading = atoi(strValue); m_desired_xyheading = m_current_xyheading; // Recompute heading vectors RecomputeVectors(); return TRUE; case HSK_ZHEADING: m_current_zheading = atoi(strValue); m_desired_zheading = m_current_zheading; // Recompute heading vectors RecomputeVectors(); return TRUE; case HSK_ROOM: obj = atoi(strValue); if (!hsInterface.ValidObject(obj)) return TRUE; AddSroom(obj); return TRUE; case HSK_CONSOLE: obj = atoi(strValue); if (!hsInterface.ValidObject(obj)) return TRUE; AddConsole(obj); return TRUE; case HSK_SYSTEMDEF: // Handle a system! LoadSystem(fp); return TRUE; default: // Just call the base function return (CHSObject::HandleKey(key, strValue, fp)); } } // Cleans up any final ship details after it is loaded from // the database. void CHSShip::EndLoadObject(void) { // If we have a computer and any consoles, // set the computer for the consoles. CHSSysComputer *cComputer; cComputer = (CHSSysComputer *)m_systems.GetSystem(HSS_COMPUTER); if (cComputer) { int idx; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) m_console_array[idx]->SetComputer(cComputer); } } } // Overridden from the base CHSObject class, but we'll call up // to that object as well. void CHSShip::WriteToFile(FILE *fp) { int idx; // Call the base class first, then output our // stuff. It's best to do it that way, but not // really necessary. CHSObject::WriteToFile(fp); // Now our's if (m_ident) fprintf(fp, "IDENT=%s\n", m_ident); if (m_boarding_code) fprintf(fp, "BOARDING_CODE=%s\n", m_boarding_code); fprintf(fp, "HULL_POINTS=%d\n", m_hull_points); fprintf(fp, "CLASSID=%d\n", m_class); fprintf(fp, "DROPPED=%d\n", m_dropped); fprintf(fp, "DOCKED=%d\n", m_docked); fprintf(fp, "DESTROYED=%d\n", m_destroyed); fprintf(fp, "XYHEADING=%d\n", m_current_xyheading); fprintf(fp, "ZHEADING=%d\n", m_current_zheading); if (m_objlocation != NOTHING) fprintf(fp, "OBJLOCATION=%d\n", m_objlocation); if (m_can_drop) fprintf(fp, "DROP CAPABLE=%d\n", *m_can_drop); if (m_cargo_size) fprintf(fp, "CARGOSIZE=%d\n", *m_cargo_size); // Write out missile bay info. This needs to come // before consoles. fprintf(fp, "MISSILEBAY\n"); m_missile_bay.SaveToFile(fp); // Write out rooms for (idx = 0; m_ship_rooms[idx] != NOTHING; idx++) { fprintf(fp, "ROOM=%d\n", m_ship_rooms[idx]); } // Write out consoles for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) { fprintf(fp, "CONSOLE=%d\n", m_console_array[idx]->m_objnum); m_console_array[idx]->WriteObjectAttrs(); } } // Landing locs for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx]) { fprintf(fp, "LANDINGLOC=%d\n", m_landing_locs[idx]->objnum); m_landing_locs[idx]->WriteObjectAttrs(); } } // Output system information m_systems.SaveToFile(fp); } // When the HandleKey() encounters a SYSTEMDEF key, it // calls this function to load the system information into // a system that already exists on the ship. BOOL CHSShip::LoadSystem(FILE *fp) { CHSEngSystem *cSys; CHSEngSystem *cSysTmp; char strKey[64]; char strValue[64]; char *ptr; char tbuf[256]; HS_DBKEY key; int iCurSlot; int iPriority; HSS_TYPE type; cSys = NULL; // We have NO WAY of knowing what kind of information each // system needs. We ONLY know what types of systems exist // because this is defined in hseng.h. Thus, we simply // figure out the type of system, and then pass the key/value // information to the system as if it were setting attributes. while(fgets(tbuf, 256, fp)) { // Truncate newlines if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); key = HSFindKey(strKey); // Check for end of database .. would be an error if (!strcmp(strKey, "*END*")) { hs_log( "ERROR: Encountered end of objectdb before loading specified system info."); break; } // Check the key, and do something switch(key) { case HSK_SYSTYPE: // Find the system on the ship type = (HSS_TYPE) atoi(strValue); cSys = m_systems.GetSystem(type); // Don't exit if system not found, just // warning. if (!cSys) { hs_log( "WARNING: System definition but no system found."); } break; case HSK_SYSTEMEND: return TRUE; case HSK_PRIORITY: // Put this system back into it's proper slot. // Initially it is in the priority position specified // by how it was loaded in the class object. That // may or may not be the position it was at for the // specific ship. Thus, we have to handle that. iPriority = atoi(strValue); // If no system, then do nothing if (!cSys) break; // Find the current priority level iCurSlot = 0; for (cSysTmp = m_systems.GetHead(); cSysTmp; cSysTmp = cSysTmp->GetNext()) { if (!strcmp(cSysTmp->GetName(), cSys->GetName())) { // System match. break; } else iCurSlot++; } if (iCurSlot > iPriority) { // Move the system up in priority while(iCurSlot > iPriority) { if (!m_systems.BumpSystem(cSys, 1)) break; iCurSlot--; } } else if (iCurSlot < iPriority) { // Move the system down while(iCurSlot < iPriority) { if (!m_systems.BumpSystem(cSys, -1)) break; iCurSlot++; } } break; default: // Simply call upon the object to set it's // own attributes. We don't know what they // are. if (cSys && !cSys->SetAttributeValue(strKey, strValue)) { sprintf(tbuf, "WARNING: System type %d unable to handle attribute \"%s\"", type, strKey); hs_log(tbuf); } break; } } return FALSE; } // Does various system stuff each cycle. void CHSShip::HandleSystems(void) { CHSSysEngines *cEngines; CHSReactor *cReactor; CHSJumpDrive *cJumpers; int iPowerDeficit; int iSysPower; int iSpeed; BOOL bStat; char tbuf[256]; CHSEngSystem *cSys; // Find the regular engines. cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (cEngines) iSpeed = (int)cEngines->GetCurrentSpeed(); // Find jump drives to see if we get a disengage status. BOOL bEngaged = FALSE; cJumpers = (CHSJumpDrive *)m_systems.GetSystem(HSS_JUMP_DRIVE); if (cJumpers) { bEngaged = cJumpers->GetEngaged(); if (bEngaged) { // Tell the jumpers our current sublight speed. cJumpers->SetSublightSpeed(iSpeed); } } // Tell the systems to do their cycle stuff m_systems.DoCycle(); // Check various jump conditions. if (bEngaged) { if (!cJumpers->GetEngaged()) { ExitHyperspace(); } else if (cEngines) { if (cEngines->GetCurrentSpeed() < cJumpers->GetMinJumpSpeed()) { cJumpers->SetEngaged(FALSE); ExitHyperspace(); } } } cReactor = (CHSReactor *)m_systems.GetSystem(HSS_REACTOR); if (cReactor) { bStat = cReactor->IsOnline(); if (!bReactorOnline && bStat) { bReactorOnline = TRUE; sprintf(tbuf, "%s%s-%s A light flashes on your console, indicating that the main reactor is now online.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_ENGINEERING); // Give an outside effects message dbref loc; loc = GetDockedLocation(); if (loc != NOTHING) { char tbuf[128]; sprintf(tbuf, "Lights flicker on the %s as its reactor comes online.", GetName()); hsInterface.NotifyContents(loc, tbuf); } } else if (bReactorOnline && !bStat) bReactorOnline = FALSE; // Check power availability. If the reactor is producing // less power than we're using, we have to start drawing power // from systems. iPowerDeficit = m_systems.GetPowerUse() - cReactor->GetOutput(); if (iPowerDeficit > 0) { // Start drawing power from systems cSys = m_systems.GetHead(); while(cSys && (iPowerDeficit > 0)) { // Don't draw power from non-visible systems if (!cSys->IsVisible()) { cSys = cSys->GetNext(); continue; } iSysPower = cSys->GetCurrentPower(); // Can we get enough power from this system? if (iSysPower >= iPowerDeficit) { // Draw the needed power from this system. iSysPower -= iPowerDeficit; iPowerDeficit -= cSys->GetCurrentPower(); cSys->SetCurrentPower(iSysPower); sprintf(tbuf, "%s%s-%s A warning light flashes, indicating that the %s system has lost power.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, cSys->GetName()); NotifyConsoles(tbuf, MSG_ENGINEERING); } else if (iSysPower > 0) { // Draw ALL power from this system. iPowerDeficit -= iSysPower; cSys->SetCurrentPower(0); sprintf(tbuf, "%s%s-%s A warning light flashes, indicating that the %s system has lost power.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, cSys->GetName()); NotifyConsoles(tbuf, MSG_ENGINEERING); } cSys = cSys->GetNext(); } } } // Now do stuff for each system. // Do sensor stuff (this isn't finding contacts. // That's done in the DoCycle() of systems.). HandleSensors(); // Life support HandleLifeSupport(); } // This is THE CYCLE for ships. It handles everything from // traveling to sensor sweeping. void CHSShip::DoCycle(void) { int idx; // Don't do anything if we're destroyed if (m_destroyed) return; // System stuff first. HandleSystems(); // See if we're landing or taking off if (m_drop_status > 0 || m_dock_status > 0) { HandleLanding(); } else if (m_drop_status < 0 || m_dock_status < 0) { HandleUndocking(); } // Change the heading of the ship. ChangeHeading(); // Move the ship to new coordinates Travel(); // Check boarding link validity ConfirmBoardLinks(); // Consoles for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) { m_console_array[idx]->DoCycle(); } } } // Call this function to completely repair everything on the ship. void CHSShip::TotalRepair(void) { CHSEngSystem *cSys; // Not destroyed m_destroyed = FALSE; // Repair all systems for (cSys = m_systems.GetHead(); cSys; cSys = cSys->GetNext()) { cSys->ReduceDamage(DMG_NONE); cSys->SetAttributeValue("STRESS", "0"); } // Repair hull m_hull_points = GetMaxHullPoints(); // Put the ship into space if it's not docked or dropped if (!m_docked && !m_dropped) { ResurrectMe(); } } // Returns the current cloaking efficiency for the ship. // If the ship cannot cloak or isn't cloaked, this is just 0. // This value ranges from 0 - 1.00, where 1.00 is 100% visible. float CHSShip::CloakingEffect(void) { // Cloaking not implemented. Return 0. return 0; } // Used to query sensors, give messages to the ship consoles, etc. void CHSShip::HandleSensors(void) { CHSSysSensors *cSensors; SENSOR_CONTACT *cContact; char tbuf[512]; char name[64]; cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) return; // Set the sensors to the first new contact. cContact = cSensors->GetFirstNewContact(); // This is ok to do because the Next and First functions // return the same first contact. while(cContact = cSensors->GetNextNewContact()) { // Special name handling for ships. if (cContact->m_obj->GetType() == HST_SHIP) sprintf(name, "the %s", cContact->m_obj->GetName()); else strcpy(name, cContact->m_obj->GetName()); if (cContact->status == DETECTED) sprintf(tbuf, "%s[%s%s%d%s%s]%s - Unidentified contact has appeared on sensors.", cContact->m_obj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cContact->m_obj->GetObjectColor(), ANSI_NORMAL); else if (cContact->status == UPDATED) sprintf(tbuf, "%s[%s%s%d%s%s]%s - Contact identified as %s.", cContact->m_obj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cContact->m_obj->GetObjectColor(), ANSI_NORMAL, name); else sprintf(tbuf, "%s[%s%s%d%s%s]%s - New contact identified as %s.", cContact->m_obj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cContact->m_obj->GetObjectColor(), ANSI_NORMAL, name); NotifyConsoles(tbuf, MSG_SENSOR); } // Now lost contacts // Set the sensors to the first lost contact. cContact = cSensors->GetFirstLostContact(); // This is ok to do because the Next and First functions // return the same first contact. while(cContact = cSensors->GetNextLostContact()) { // Special name handling for ships. if (cContact->m_obj->GetType() == HST_SHIP) sprintf(name, "The %s", cContact->m_obj->GetName()); else { strncpy(name, cContact->m_obj->GetName(), 63); name[63] = '\0'; } if (cContact->status == DETECTED) sprintf(tbuf, "%s[%s%s%d%s%s]%s - Unidentified contact has been lost from sensors.", cContact->m_obj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cContact->m_obj->GetObjectColor(), ANSI_NORMAL); else sprintf(tbuf, "%s[%s%s%d%s%s]%s - %s has been lost from sensors.", cContact->m_obj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cContact->m_obj->GetObjectColor(), ANSI_NORMAL, name); NotifyConsoles(tbuf, MSG_SENSOR); } } // Sends a message to all consoles on a ship void CHSShip::NotifyConsoles(char *strMsg, int msgLevel) { int idx; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) { m_console_array[idx]->HandleMessage(strMsg, msgLevel); } } } // Sends a message to all registered ship rooms void CHSShip::NotifySrooms(char *strMsg) { int idx; for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (m_ship_rooms[idx] != NOTHING) { hsInterface.NotifyContents(m_ship_rooms[idx], strMsg); } } } // Returns the color of the ship object char *CHSShip::GetObjectColor(void) { static char tbuf[32]; sprintf(tbuf, "%s%s", ANSI_HILITE, ANSI_RED); return tbuf; } // Returns the CHSConsole object in a given slot in the // ship's console array. CHSConsole *CHSShip::GetConsole(UINT slot) { if ((slot < 0) || (slot >= MAX_SHIP_CONSOLES)) return NULL; return m_console_array[slot]; } // Returns TRUE if any of the ship's console are locked // on the given target object. BOOL CHSShip::IsObjectLocked(CHSObject *cObj) { if (!cObj) return FALSE; // Run through our consoles, checking their locks. int idx; CHSObject *cTarget; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) { cTarget = m_console_array[idx]->GetObjectLock(); if (cTarget && (cTarget->GetDbref() == cObj->GetDbref())) return TRUE; } } return FALSE; } // Gives a report of sensor contacts to a player. An object // type can be specified to only display sensor contacts with // a certain type of object class. If this variable is not // set, all types are displayed. void CHSShip::GiveSensorReport(dbref player, HS_TYPE tType) { CHSSysSensors *cSensors; SENSOR_CONTACT *cContact; int idx; BOOL bHeaderGiven; char tbuf[512]; double rangelist[64]; char *bufflist[64]; // Used to sort output UINT uBuffIdx; static char strSizes[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; double dDistance; double dX, dY, dZ; int iXYBearing, iZBearing; char sizesymbol; char lockchar; BOOL bLinked; cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) { hsStdError(player, "This vessel has no sensor array."); return; } if (!cSensors->GetCurrentPower()) { hsStdError(player, "Sensor array is not currently online."); return; } // No contacts on sensors? if (!cSensors->NumContacts()) { if (tType == HST_NOTYPE) hsStdError(player, "No contacts currently on sensors."); else hsStdError(player, "No contacts of that type currently on sensors."); return; } bufflist[0] = NULL; uBuffIdx = 0; // All looks good. Give the report. bHeaderGiven = FALSE; for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { // Grab the contact cContact = cSensors->GetContact(idx); if (!cContact) continue; // Store a pointer to the object for ease of use. CHSObject *cObj; cObj = cContact->m_obj; // Be sure it's the proper type. if (tType != HST_NOTYPE) { if (cObj->GetType() != tType) continue; } // The object is of our type, now give the header. // We do it here because if tType is not of NOTYPE, // we need to query the CHSObject to know what color // it displays as. if (!bHeaderGiven) { if (tType != HST_NOTYPE) sprintf(tbuf, "%sSensor Contacts:%s %d", cObj->GetObjectColor(), ANSI_NORMAL, cSensors->NumContacts()); else sprintf(tbuf, "%sContacts:%s %d", ANSI_HILITE, ANSI_NORMAL, cSensors->NumContacts()); notify(player, tbuf); sprintf(tbuf, "%s%s-------------------------------------------------------------------------------%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); bHeaderGiven = TRUE; } // Calculate a variety of information. dX = cObj->GetX(); dY = cObj->GetY(); dZ = cObj->GetZ(); // Distance dDistance = Dist3D(m_x, m_y, m_z, dX, dY, dZ); // Bearing iXYBearing = XYAngle(m_x, m_y, dX, dY); iZBearing = ZAngle(m_x, m_y, m_z, dX, dY, dZ); // Symbol representing the size if (cObj->GetSize() > 27) sizesymbol = '+'; else sizesymbol = strSizes[cObj->GetSize() - 1]; // Is it a ship, and is it locked on us? bLinked = FALSE; if (cObj->GetType() == HST_SHIP) { CHSShip *source; source = (CHSShip *) cObj; if (source->IsObjectLocked(this)) lockchar = '*'; else lockchar = ' '; // Do we have a boarding link with the object? bLinked = FALSE; for (int jdx = 0; jdx < MAX_BOARD_LINKS; jdx++) { if (m_board_links[jdx] && (m_board_links[jdx]->GetDbref() == cObj->GetDbref())) { bLinked = TRUE; break; } } } else lockchar = ' '; // Based on the type of object, given one of a variety // of print outs. Not all objects may be supported, in // which case a generic report is given. bufflist[uBuffIdx] = new char[512]; rangelist[uBuffIdx] = dDistance; switch(cObj->GetType()) { case HST_SHIP: CHSShip *cShip; cShip = (CHSShip *)cObj; sprintf(bufflist[uBuffIdx], "%c%s%c%s%c%s[%s%d%s]%s %-24s %s%sB:%s %-3d%s%sm%s%-3d %s%sR:%s %-8.0f %s%sH:%s %-3d%s%sm%s%-3d %s%sS:%s %-7.0d", sizesymbol, ANSI_HILITE, lockchar, ANSI_NORMAL, bLinked ? 'b' : ' ', cObj->GetObjectColor(), ANSI_NORMAL, cContact->m_id, cObj->GetObjectColor(), ANSI_NORMAL, cContact->status == DETECTED ? "Unknown" : cObj->GetName(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iXYBearing, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iZBearing, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, cShip->GetXYHeading(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, cShip->GetZHeading(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, cShip->GetSpeed()); break; case HST_PLANET: sprintf(bufflist[uBuffIdx], "%c %s[%s%d%s]%s %-24s %s%sB:%s %-3d%s%sm%s%-3d %s%sR:%s %-8.0f %s%sSize:%s %d", sizesymbol, cObj->GetObjectColor(), ANSI_NORMAL, cContact->m_id, cObj->GetObjectColor(), ANSI_NORMAL, cContact->status == DETECTED ? "Unknown" : cObj->GetName(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iXYBearing, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iZBearing, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, cObj->GetSize()); break; default: sprintf(bufflist[uBuffIdx], "%c %s[%s%d%s]%s %-24s %s%sB:%s %-3d%s%sm%s%-3d %s%sR:%s %.0f", sizesymbol, cObj->GetObjectColor(), ANSI_NORMAL, cContact->m_id, cObj->GetObjectColor(), ANSI_NORMAL, cContact->status == DETECTED ? "Unknown" : cObj->GetName(), ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iXYBearing, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iZBearing, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, dDistance, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); break; } uBuffIdx++; } // Now sort the contacts according to range. This is your // pretty standard, very inefficient bubble-sort. int i, j; char *ptr; for (i = 0; i < uBuffIdx; i++) { for (j = i+1; j < uBuffIdx; j++) { // Compare element ranges if (rangelist[i] > rangelist[j]) { // Swap elements dDistance = rangelist[i]; ptr = bufflist[i]; rangelist[i] = rangelist[j]; bufflist[i] = bufflist[j]; bufflist[j] = ptr; rangelist[j] = dDistance; } } } // List sorted, now print it out to the player for (i = 0; i < uBuffIdx; i++) { notify(player, bufflist[i]); // Free the buffer delete [] bufflist[i]; } // Print the closing line sprintf(tbuf, "%s%s-------------------------------------------------------------------------------%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Handles life support for the vessel, which basically // just means checking to see if there's any life support // left .. oh, and killing players. void CHSShip::HandleLifeSupport(void) { CHSSysLifeSupport *cLife; char tbuf[256]; // Find the system cLife = (CHSSysLifeSupport *)m_systems.GetSystem(HSS_LIFE_SUPPORT); if (!cLife || !IsActive()) return; // Is there air left? if (cLife->GetAirLeft() <= 0) { if (bGhosted) { // Do nothing return; } // Kill people on the ship. bGhosted = TRUE; sprintf(tbuf, "%s%s%s*%s LIFE SUPPORT SYSTEMS FAILURE %s%s%s*%s", ANSI_HILITE, ANSI_BLINK, ANSI_RED, ANSI_NORMAL, ANSI_HILITE, ANSI_BLINK, ANSI_RED, ANSI_NORMAL); NotifySrooms(tbuf); KillShipCrew("YOU HAVE SUFFOCATED!"); } else if (cLife->GetCurrentPower() == 0) { double remainder; int airleft; airleft = (int)(cLife->GetAirLeft() / 10); remainder = (cLife->GetAirLeft() * .1) - airleft; // Send out a warning each 10 percent drop in life support. // Because life support may be decremented each cycle by // something that doesn't always add up to 1%, we need to // account for some minor error. For example, decreasing // 1% over 3 cycles is .3333 each cycle, for a total of // .9999% over 3 cycles. That gives an error of .0001%, // so the remainder will never be exactly 0. if (remainder < .001) { sprintf(tbuf, "%s%s%s*%s %s%sWARNING%s %s%s%s*%s Life support systems are failing.", ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL); NotifySrooms(tbuf); } } else if (bGhosted) bGhosted = FALSE; } // Returns the maximum hull points for the vessel UINT CHSShip::GetMaxHullPoints(void) { return m_classinfo->m_maxhull; } // Returns the current hull points for the vessel UINT CHSShip::GetHullPoints(void) { return m_hull_points; } // Returns the drop capable status of the ship BOOL CHSShip::CanDrop(void) { if (m_can_drop) return *m_can_drop; else return m_classinfo->m_can_drop; } // Ships are represented as a plus sign. char CHSShip::GetObjectCharacter(void) { return '+'; } // Retrieves a landing location (a bay) given a slot number (0 - n) CHSLandingLoc *CHSShip::GetLandingLoc(int which) { if (which < 0 || which >= HS_MAX_LANDING_LOCS) return NULL; return m_landing_locs[which]; } // Moves the ship object, which represents the ship, to a location. void CHSShip::MoveShipObject(dbref whereto) { if (!hsInterface.ValidObject(whereto)) return; if (m_objnum != NOTHING) move_object(m_objnum, whereto); } // Adds a landing location (a bay) to the ship. BOOL CHSShip::AddLandingLoc(dbref room) { CHSLandingLoc *cLoc; char tbuf[256]; // Temp string storage // Grab a new landing loc cLoc = NewLandingLoc(); if (!cLoc) { sprintf(tbuf, "WARNING: Maximum landing locations reached for ship #%d.", m_objnum); hs_log(tbuf); return FALSE; } // Initialize some attrs cLoc->SetActive(TRUE); cLoc->objnum = room; cLoc->SetOwnerObject(this); // Set the flag hsInterface.SetFlag(room, ROOM_HSPACE_LANDINGLOC); // Set the planet attribute hsInterface.AtrAdd(room, "HSDB_SHIP", tprintf("#%d", m_objnum), GOD); return TRUE; } // Allocates a new landing location, if possible, in the // ship's landing bay array. CHSLandingLoc *CHSShip::NewLandingLoc(void) { int idx; // Check to see if it'll fit for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx] == NULL) break; } if (idx == HS_MAX_LANDING_LOCS) { return NULL; } m_landing_locs[idx] = new CHSLandingLoc; return m_landing_locs[idx]; } // Call this function to find a landing location based on its // room number. CHSLandingLoc *CHSShip::FindLandingLoc(dbref objnum) { int idx; for (idx = 0; idx < HS_MAX_LANDING_LOCS; idx++) { if (m_landing_locs[idx] && m_landing_locs[idx]->objnum == objnum) return m_landing_locs[idx]; } return NULL; } // Overrides the base class GetSize() because we derive our // size from the class information. UINT CHSShip::GetSize(void) { return m_classinfo->m_size; } // Takes a message and propogates it to the consoles. If the // cObj variable is not NULL, the ship will attempt to find // the sensor contact for that object and prefix the message // with a contact id. The long pointer points to whatever // data were passed to the function. void CHSShip::HandleMessage(char *lpstrMsg, int msgType, long *data) { SENSOR_CONTACT *cContact; CHSSysSensors *cSensors; char tbuf[512]; // Determine message type switch(msgType) { case MSG_SENSOR: case MSG_GENERAL: case MSG_ENGINEERING: case MSG_COMBAT: if (strlen(lpstrMsg) > 400) lpstrMsg[400] = '\0'; CHSObject *cObj; cObj = (CHSObject *)data; // Find our sensors cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors || !cObj) cContact = NULL; else cContact = cSensors->GetContact(cObj); if (cContact) { sprintf(tbuf, "%s[%s%s%4d%s%s]%s - %s", cObj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cObj->GetObjectColor(), ANSI_NORMAL, lpstrMsg); } else strcpy(tbuf, lpstrMsg); NotifyConsoles(tbuf, msgType); break; case MSG_COMMUNICATION: HandleCommMsg(lpstrMsg, data); break; } } // Runs through the boarding links, confirming their // validity. void CHSShip::ConfirmBoardLinks(void) { int idx; BOOL bBreak; CHSShip *cShip; double sX, sY, sZ; // Our coords double tX, tY, tZ; // Other ship's coords double dDist; sX = GetX(); sY = GetY(); sZ = GetZ(); // Run through boarding links, checking conditions. for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (!m_board_links[idx]) continue; cShip = m_board_links[idx]; bBreak = FALSE; // Don't break link by default. tX = cShip->GetX(); tY = cShip->GetY(); tZ = cShip->GetZ(); // Check to see if the other ship is destroyed if (cShip->IsDestroyed()) bBreak = TRUE; // Check to see if we're still in space else if (!IsActive()) bBreak = TRUE; // Are we dropping or docking? else if (m_drop_status || m_dock_status) bBreak = TRUE; // Check to see if the other guy is still // in space. else if (!cShip->IsActive()) bBreak = TRUE; // Check distance else { dDist = Dist3D(sX, sY, sZ, tX, tY, tZ); if (dDist > HSCONF.max_board_dist) bBreak = TRUE; } // If we need to break the boarding link, break it. if (bBreak) MakeBoardLink(cShip, FALSE); } } // Indicates if the ship is destroyed or not. BOOL CHSShip::IsDestroyed(void) { return m_destroyed; } // Allows other ships (or ourself) to establish a boarding // link or break an existing one. BOOL CHSShip::MakeBoardLink(CHSShip *cSource, BOOL bStat) { int idx; char tbuf[128]; // If bStat is TRUE, other ship is trying to link with us. if (bStat) { // See if we have room for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (!m_board_links[idx]) { sprintf(tbuf, "The %s has established a boarding link with us.", cSource->GetName()); HandleMessage(tbuf, MSG_SENSOR, (long *)cSource); m_board_links[idx] = cSource; return TRUE; } } return FALSE; } else { // Break a link. Always returns TRUE. for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (m_board_links[idx] && (m_board_links[idx]->GetDbref() == cSource->GetDbref())) { sprintf(tbuf, "The %s has broken its boarding link with us.", cSource->GetName()); HandleMessage(tbuf, MSG_SENSOR, (long *)cSource); m_board_links[idx] = NULL; } } return TRUE; } } // Allows a player to disembark from the ship. This could // be if the ship is docked, dropped, or boardlinked. void CHSShip::DisembarkPlayer(dbref player, int id) { int idx; dbref dbLoc; dbref dbDestObj; // If the ship is docked or dropped, find the location // of the ship object, and put the player there. if (m_docked || m_dropped) { if (m_objnum == NOTHING) { notify(player, "This ship has no ship object, so I don't know where to put you."); return; } dbLoc = Location(m_objnum); dbDestObj = m_objlocation; } else { UINT nBoardLinks = 0; // Check boarding links for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (m_board_links[idx]) nBoardLinks++; } // If no board links, player can't disembark. if (!nBoardLinks) { notify(player, "You cannot disembark from the vessel at this time."); return; } // Valid id? id--; // For array notation if (id < 0 || id >= MAX_BOARD_LINKS || !m_board_links[id]) { notify(player, "Invalid board link identifier specified for disembarking"); return; } // Get the other ship's ship object dbDestObj = m_board_links[id]->GetDbref(); if (dbDestObj == NOTHING) { notify(player, "Target vessel has no indication of where to board."); return; } // Find the bay attribute on the ship object if (!hsInterface.AtrGet(dbDestObj, "BAY")) { notify(player, "Target vessel's ship object has no BAY attribute."); return; } dbLoc = strtodbref(hsInterface.m_buffer); } // At this point, dbLoc should be set to a // location. if (!hsInterface.ValidObject(dbLoc)) { notify(player, "Erg. The location of this vessel's ship object is invalid."); return; } // Tell the player of the disembarking notify(player, "You disembark from the vessel."); // Tell players in the other location of the disembarking. hsInterface.NotifyContents(dbLoc, tprintf("%s disembarks from the %s.", Name(player), GetName())); dbref dbPrevLoc = Location(player); // Move the player move_object(player, dbLoc); // Tell players in the previous location that the // player disembarked. hsInterface.NotifyContents(dbPrevLoc, tprintf("%s disembarks from the vessel.", Name(player))); // Set the location attribute on the player. hsInterface.AtrAdd(player, "HSPACE_LOCATION", tprintf("#%d", dbDestObj), GOD, AF_MDARK | AF_WIZARD); } // Returns the boarding code for the vessel. char *CHSShip::GetBoardingCode(void) { return m_boarding_code; } // Returns TRUE or FALSE to indicate whether the ship is // landed or docked. BOOL CHSShip::Landed(void) { if ((m_docked || m_dropped) && !m_in_space) return TRUE; return FALSE; } // When another object locks onto the ship, this function // can be called to handle that situation. void CHSShip::HandleLock(CHSObject *cLocker, BOOL bStat) { SENSOR_CONTACT *cContact; CHSSysSensors *cSensors; char tbuf[256]; // bStat could be TRUE for locking, or FALSE // for unlocking. // Find our sensors cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) return; // Find the contact on sensors cContact = cSensors->GetContact(cLocker); // If not on sensors, give a general message if (!cContact) { if (bStat) sprintf(tbuf, "%s%s-%s An unknown contact has locked weapons!", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL); else sprintf(tbuf, "%s%s-%s An unknown contact has released weapons lock.", ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL); } else if (cContact->status == DETECTED) { if (bStat) sprintf(tbuf, "%s[%s%s%d%s%s]%s - Contact has locked weapons!", cLocker->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cLocker->GetObjectColor(), ANSI_NORMAL); else sprintf(tbuf, "%s[%s%s%d%s%s]%s - Contact has released weapons lock.", cLocker->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cLocker->GetObjectColor(), ANSI_NORMAL); } else { char name[64]; if (cLocker->GetType() == HST_SHIP) sprintf(name, "The %s", cLocker->GetName()); else strcpy(name, cLocker->GetName()); if (bStat) sprintf(tbuf, "%s[%s%s%d%s%s]%s - %s has locked weapons!", cLocker->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cLocker->GetObjectColor(), ANSI_NORMAL, name); else sprintf(tbuf, "%s[%s%s%d%s%s]%s - %s has released weapons lock.", cLocker->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cLocker->GetObjectColor(), ANSI_NORMAL, name); } // Notify the consoles of this message NotifyConsoles(tbuf, MSG_SENSOR); } // Handles damage from an attacker, with a weapon, and a given // level of damage. void CHSShip::HandleDamage(CHSObject *cSource, CHSWeapon *cWeapon, int strength, CHSConsole *cConsole, int iSysType) { dbref dbAttacker; CHSSysShield *cShield; char msgUs[256]; // Message gets sent to our ship char msgThem[256];// Message gets sent back to attacker // Get the attacking player. dbAttacker = hsInterface.ConsoleUser(cConsole->m_objnum); // Determine which shield is hit. To do that, we // supply the XY and Z angles from the attacker to // us. int iXYAngle; int iZAngle; iXYAngle = XYAngle(cSource->GetX(), cSource->GetY(), GetX(), GetY()); iZAngle = ZAngle(cSource->GetX(), cSource->GetY(), cSource->GetZ(), GetX(), GetY(), GetZ()); cShield = DetermineHitShield(iXYAngle, iZAngle); // It's possible the ship has no shields char strShieldType[32]; if (cShield) { // Tell the shield to take damage, and record // how much damage was not handled. strength = cShield->DoDamage(strength); int shieldtype = cShield->GetShieldType(); if (shieldtype == ST_DEFLECTOR) strcpy(strShieldType, "deflected"); else strcpy(strShieldType, "absorbed"); } if (cShield && strength <= 0) { // Shields absorbed damage // Customize message for type of weapon. switch(cWeapon->GetType()) { case HSW_LASER: sprintf(msgUs, "%s have %s an incoming energy blast.", cShield->GetName(), strShieldType); sprintf(msgThem, "Your energy blast has been %s by the enemy's shields.", strShieldType); break; case HSW_MISSILE: sprintf(msgUs, "Our shields have %s the impact from an inbound missile.", strShieldType); sprintf(msgThem, "The impact of your missile has been %s by the enemy's shields.", strShieldType); break; } // Give messages HandleMessage(msgUs, MSG_COMBAT, (long *)cSource); if (dbAttacker != NOTHING) hsStdError(dbAttacker, msgThem); } else { // Some damage to the hull occurs. If it's greater // than a critical hit value, then systems take // damage. // Deduct from hull m_hull_points -= strength; // Is hull < 0? if (m_hull_points < 0) { ExplodeMe(); KillShipCrew("YOU HAVE BEEN BLOWN TO TINY BITS!"); // Trigger akill did_it(dbAttacker, m_objnum, 0, NULL, 0, NULL, A_AKILL, NULL, 0); } else { // Was the hit strong enough to do critical // damage? Critical damage is defined as // 1/10th the hull value. double dCritStrength; dCritStrength = m_hull_points * .1; if (strength >= dCritStrength) { // Damage a system. CHSEngSystem *cSys; // Try to get the system of choice if (iSysType != HSS_NOTYPE) { cSys = m_systems.GetSystem((HSS_TYPE)iSysType); // If the system wasn't found, grab a // random one. if (!cSys) cSys = m_systems.GetRandomSystem(); } else cSys = m_systems.GetRandomSystem(); if (!cSys) { // Odd. No system found? Just give // a hull-like message. notify(1, "NO SYSTEM"); switch(cWeapon->GetType()) { case HSW_LASER: strcpy(msgUs, "An incoming energy blast has damaged the hull."); strcpy(msgThem, "Your energy blast has landed damage to the enemy's hull."); break; case HSW_MISSILE: strcpy(msgUs, "An inbound missile has landed damage to our hull."); strcpy(msgThem, "Your missile has landed damage to the enemy's hull."); break; } } else { // Give a message switch(cWeapon->GetType()) { case HSW_LASER: sprintf(msgUs, "An incoming energy blast has damaged the %s.", cSys->GetName()); sprintf(msgThem, "Your energy blast has landed damage to the enemy's %s.", cSys->GetName()); break; case HSW_MISSILE: sprintf(msgUs, "An inbound missile has landed damage to our %s.", cSys->GetName()); sprintf(msgThem, "Your missile has landed damage to the enemy's %s.", cSys->GetName()); break; } // Damage the system cSys->DoDamage(); } HandleMessage(msgUs, MSG_COMBAT, (long *)cSource); if (dbAttacker != NOTHING) hsStdError(dbAttacker, msgThem); } else { // Just hull damage switch(cWeapon->GetType()) { case HSW_LASER: strcpy(msgUs, "An incoming energy blast has damaged the hull."); strcpy(msgThem, "Your energy blast has landed damage to the enemy's hull."); break; case HSW_MISSILE: strcpy(msgUs, "An inbound missile has landed damage to our hull."); strcpy(msgThem, "Your missile has landed damage to the enemy's hull."); break; } HandleMessage(msgUs, MSG_COMBAT, (long *)cSource); if (dbAttacker != NOTHING) hsStdError(dbAttacker, msgThem); } } } } // Can be used to explode the ship, for whatever reason. void CHSShip::ExplodeMe(void) { CHSUniverse *uSource; char tbuf[128]; // Find my universe uSource = uaUniverses.FindUniverse(m_uid); if (uSource) { // Give out a message sprintf(tbuf, "You gaze in awe as the %s explodes before your eyes.", GetName()); uSource->SendContactMessage(tbuf, IDENTIFIED, this); // Remove me from active space. uSource->RemoveActiveObject(this); m_in_space = FALSE; } // I'm destroyed m_destroyed = TRUE; // Clear any weapons locks consoles may have int idx; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx] && m_console_array[idx]->GetObjectLock()) m_console_array[idx]->UnlockWeapons(NOTHING); } } // Can be used to resurrect the ship, which just means // it's no longer destroyed and is now in active space void CHSShip::ResurrectMe(void) { CHSUniverse *uDest; m_destroyed = FALSE; // Put us into our universe, or a default one if // needed. uDest = uaUniverses.FindUniverse(m_uid); if (!uDest) { // Find the first available universe uDest = NULL; for (int idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (uDest = uaUniverses.GetUniverse(idx)) break; } if (!uDest) return; // Since we had to find this universe, that also // means this ship is not in that universe, so add // it. uDest->AddObject(this); } // A universe exists, so add it. uDest->AddActiveObject(this); m_in_space = TRUE; // Be sure to verify the UID m_uid = uDest->GetID(); } // Called by another object to give a scan report. We // decide what information to include in the scan. void CHSShip::GiveScanReport(CHSObject *cScanner, dbref player, BOOL id) { char tbuf[256]; CHSSysEngines *cEngines; // Find our engines for speed info cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); // Give the header info sprintf(tbuf, "%s%s.-----------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Vessel Scan Report %30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, id ? GetName() : "Name Unknown", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >---------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Give the vessel class sprintf(tbuf, "%s%s|%s %-30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, id ? m_classinfo->m_name : "Vessel Class Unknown", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Give coordinate and heading information. sprintf(tbuf, "%s%s| %sX:%s %9.0f%23s%s%sSize:%s %-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetX(), " ", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, GetSize(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sY:%s %9.0f%23s%s%sHeading:%s %3d/%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetY(), " ", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, m_current_xyheading, m_current_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sZ:%s %9.0f%23s%s%sVelocity:%s %-6.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, GetZ(), " ", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, cEngines ? cEngines->GetCurrentSpeed() : 0.0, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // If we're identified, give systems information if (id) { CHSEngSystem *cSys; char strDamage[64]; CHSSysShield *cFore; CHSSysShield *cAft; CHSSysShield *cStar; CHSSysShield *cPort; sprintf(tbuf, "%s%s >---------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Find the shields cFore = (CHSSysShield *) m_systems.GetSystem(HSS_FORE_SHIELD); cAft = (CHSSysShield *) m_systems.GetSystem(HSS_AFT_SHIELD); cStar = (CHSSysShield *) m_systems.GetSystem(HSS_STARBOARD_SHIELD); cPort = (CHSSysShield *) m_systems.GetSystem(HSS_PORT_SHIELD); // Give hull, shield info sprintf(tbuf, "%s%s| %sHull Status Shield Status %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); char strFore[8]; // Shield status strings char strAft[8]; char strStar[8]; char strPort[8]; if (cFore) { sprintf(strFore, "%.0f%%", cFore->GetShieldPerc()); } else strcpy(strFore, "N/A"); if (cAft) { sprintf(strAft, "%.0f%%", cAft->GetShieldPerc()); } else strcpy(strAft, "N/A"); if (cPort) { sprintf(strPort, "%.0f%%", cPort->GetShieldPerc()); } else strcpy(strPort, "N/A"); if (cStar) { sprintf(strStar, "%.0f%%", cStar->GetShieldPerc()); } else strcpy(strStar, "N/A"); int hullperc; hullperc = (int)(100 * GetHullPoints() / (float)GetMaxHullPoints()); sprintf(tbuf, "%s%s|%s %3d%% %s%sF:%s %-4s %s%sA:%s %-4s %s%sP:%s %-4s %s%sS:%s %-4s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, hullperc, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, strFore, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, strAft, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, strPort, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, strStar, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // print systems header sprintf(tbuf, "%s%s|%53s|%s", ANSI_HILITE, ANSI_BLUE, " ", ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s| %sSystem Name Status Damage %8s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, " ", ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Run down the list of systems, giving info for // visible ones (or reactor). for (cSys = m_systems.GetHead(); cSys; cSys = cSys->GetNext()) { if (cSys->IsVisible() || cSys->GetType() == HSS_REACTOR) { // Setup damage indicator switch(cSys->GetDamageLevel()) { case DMG_LIGHT: sprintf(strDamage, "%s%s LIGHT %s", ANSI_HILITE, ANSI_BGREEN, ANSI_NORMAL); break; case DMG_MEDIUM: sprintf(strDamage, "%s%s MEDIUM %s", ANSI_HILITE, ANSI_BYELLOW, ANSI_NORMAL); break; case DMG_HEAVY: sprintf(strDamage, "%s%s HEAVY %s", ANSI_HILITE, ANSI_BRED, ANSI_NORMAL); break; case DMG_INOPERABLE: sprintf(strDamage, "%s%sINOPERABLE%s", ANSI_HILITE, ANSI_BBLACK, ANSI_NORMAL); break; default: strcpy(strDamage, "None "); } sprintf(tbuf, "%s%s|%s %-20s %-12s %-10s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, cSys->GetName(), cSys->GetStatus(), strDamage, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } } } // Finish the report sprintf(tbuf, "%s%s`-----------------------------------------------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Do we notify consoles that we're being scanned? if (HSCONF.notify_shipscan) { CHSSysSensors *cSensors; cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (cSensors && cSensors->GetCurrentPower() > 0) HandleMessage("We are being scanned by another contact.", MSG_SENSOR, (long *)cScanner); } } // Sets the number of a specific type of missile // in the missile storage bay. BOOL CHSShip::SetNumMissiles(dbref player, int type, int max) { // Valid type of weapon? CHSDBWeapon *cWeap; if (!(cWeap = waWeapons.GetWeapon(type, HSW_MISSILE))) { notify(player, "Invalid weapon type specified."); return FALSE; } if (!m_missile_bay.SetRemaining(type, max)) { notify(player, "Failed to set storage value for that weapon type."); return FALSE; } else notify(player, "Missile storage value - set."); return TRUE; } // Retrieves the missile bay for the ship, or NULL if none. CHSMissileBay *CHSShip::GetMissileBay(void) { return &m_missile_bay; } // Runs through the registered rooms on the ship, moving the // contents to the afterworld. The ship is dead. The msg // is what is shown to the player/object when it is killed. void CHSShip::KillShipCrew(const char *msg) { dbref contents[50]; int idx; int jdx; for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (m_ship_rooms[idx] != NOTHING) { hsInterface.GetContents(m_ship_rooms[idx], contents, 50, NOTYPE); for (jdx = 0; contents[jdx] != -1; jdx++) { if (hsInterface.HasFlag(contents[jdx], TYPE_THING, THING_HSPACE_CONSOLE)) continue; notify(contents[jdx], msg); move_object(contents[jdx], HSCONF.afterworld); } } } } // Clones the ship, including all registered rooms and objects. // It's handy! dbref CHSShip::Clone(void) { int rooms_visited[MAX_SHIP_ROOMS]; // Rooms already cloned. // Clone the ship object. dbref dbShipObj = hsInterface.CloneThing(m_objnum); // Allocate the new ship CHSShip *newShip; newShip = new CHSShip; newShip->SetDbref(dbShipObj); // Set the class info if (!newShip->SetClassInfo(m_class)) { delete newShip; return NOTHING; } // Add the ship to the first available universe CHSUniverse *unDest; unDest = NULL; unDest = uaUniverses.FindUniverse(m_uid); unDest->AddObject(newShip); // Set the UID of the ship. newShip->SetUID(unDest->GetID()); // Repair the ship newShip->TotalRepair(); move_object(dbShipObj, Location(m_objnum)); // Set droploc or dock loc if (m_dropped) { newShip->m_dropped = TRUE; newShip->m_in_space = FALSE; } if (m_docked) { newShip->m_in_space = FALSE; newShip->m_docked = TRUE; } // Start with the first registered room, and recursively // clone through the exits until all rooms are visited. rooms_visited[0] = NOTHING; dbref dbFirstRoom = CloneRoom(m_ship_rooms[0], rooms_visited, newShip); return dbShipObj; } // Recursive function to clone a specific room. The return // value is the dbref of the cloned room. dbref CHSShip::CloneRoom(dbref room, int rooms_visited[], CHSShip *newShip) { // Check to see if the room is already visited. int idx; for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (rooms_visited[idx] == room) { // This room has been visited. We're done here! return NOTHING; } } // Room is new, so clone it, find exits, and clone their // rooms. dbref dbNewRoom = create_obj(Owner(room), TYPE_ROOM, Name(room), Pennies(room)); atr_free(dbNewRoom); atr_cpy(Owner(room), dbNewRoom, room); s_Name(dbNewRoom, Name(room)); s_Parent(dbNewRoom, Parent(room)); s_Zone(dbNewRoom, Zone(room)); s_Pennies(dbNewRoom, Pennies(room)); s_Flags(dbNewRoom, Flags(room) & ~(WIZARD | INHERIT | IMMORTAL) ); // Add the new room to the ship newShip->AddSroom(dbNewRoom); // Get the dbref of the shipobj for the new ship. dbref dbShipObj = newShip->GetDbref(); // Now see if this room has a SHIP attr on it. If so, // set it to the new ship. if (hsInterface.AtrGet(dbNewRoom, "SHIP")) hsInterface.AtrAdd(dbNewRoom, "SHIP", tprintf("#%d", dbShipObj), GOD); // See if this model room is designated as our bay of // our shipobj. If so, then set the bay of the new // shipobj. if (hsInterface.AtrGet(m_objnum, "BAY")) { dbref dbOurBay = strtodbref(hsInterface.m_buffer); if (room == dbOurBay) // Set the bay attr on the new ship obj to this // new room. hsInterface.AtrAdd(dbShipObj, "BAY", tprintf("#%d", dbNewRoom), GOD); } // Room cloned for (idx = 0; idx < MAX_SHIP_ROOMS; idx++) { if (rooms_visited[idx] == NOTHING) { rooms_visited[idx] = room; rooms_visited[idx + 1] = NOTHING; break; } } // Clone any consoles that might be in the room. This // is not a very robust clone. Only the console object // gets cloned and added to the ship. It does not // clone the total information (weapons) of the console. // That needs to be added still. dbref thing; dbref dbNewConsole; DOLIST(thing, Contents(room)) { if (hsInterface.HasFlag(thing, TYPE_THING, THING_HSPACE_CONSOLE)) { // Potential console found. Look for it in our // console list. for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx] && m_console_array[idx]->m_objnum == thing) { // Definite console. Clone it and add // it to the new ship. dbNewConsole = hsInterface.CloneThing(thing); newShip->AddConsole(dbNewConsole); move_object(dbNewConsole, dbNewRoom); } } } } // Now run through the exits on the model room, and // clone them for the new room. dbref exit_m; dbref loc; dbref rRoom; dbref dbNewExit; for (exit_m = Exits(room); exit_m && exit_m != NOTHING; exit_m = Next(exit_m)) { // Grab the location of the exit .. the next room // to clone. Clone that room, and open an exit // to it. loc = Location(exit_m); rRoom = CloneRoom(loc, rooms_visited, newShip); if (rRoom != NOTHING) { // Open an exit to the new room. dbNewExit = create_obj(Owner(exit_m), TYPE_EXIT, Name(exit_m), Pennies(exit_m)); /* * initialize everything */ atr_free(dbNewExit); atr_cpy(Owner(exit_m), dbNewExit, exit_m); s_Name(dbNewExit, Name(exit_m)); s_Owner(dbNewExit, Owner(exit_m)); s_Zone(dbNewExit, Zone(exit_m)); s_Exits(dbNewExit, dbNewRoom); s_Flags(dbNewExit, Flags(exit_m)); /* * link it in */ s_Next(dbNewExit, Exits(loc)); s_Exits(loc, dbNewExit); s_Location(dbNewExit, rRoom); // Now! Open a return exit from that room, // to us. dbref exit_opposite; // Search the location for a return exit to // this model room. for (exit_opposite = Exits(loc); exit_opposite && exit_opposite != NOTHING; exit_opposite = Next(exit_opposite)) { if (Location(exit_opposite) == room) { // Found a return exit to model! dbNewExit = create_obj(Owner(exit_opposite), TYPE_EXIT, Name(exit_opposite), Pennies(exit_opposite)); // Copy attributes atr_free(dbNewExit); atr_cpy(Owner(exit_opposite), dbNewExit, exit_opposite); /* * initialize everything */ s_Name(dbNewExit, Name(exit_opposite)); s_Owner(dbNewExit, Owner(exit_opposite)); s_Zone(dbNewExit, Zone(exit_opposite)); s_Exits(dbNewExit, rRoom); s_Flags(dbNewExit, TYPE_EXIT); /* * link it in */ s_Next(dbNewExit, Exits(rRoom)); s_Exits(rRoom, dbNewExit); s_Location(dbNewExit, dbNewRoom); } } } } return dbNewRoom; } // Handles any communications messages that were sent to the // ship. The long pointer points to a HSCOMM structure with // the information needed. void CHSShip::HandleCommMsg(const char *msg, long *data) { HSCOMM *hsComm; char tbuf[1024]; char strName[64]; int idx; CHSSysSensors *cSensors; hsComm = (HSCOMM *)data; // Do we have a comm array, and is it on? CHSSysComm *cComm; cComm = (CHSSysComm *)m_systems.GetSystem(HSS_COMM); if (!cComm || !cComm->GetCurrentPower()) return; // Setup the message of how it will be printed to people // who get it. hsComm->msg[900] = '\0'; // Just in case it's a long one. // Find the source object on sensors, if applicable. if (!hsComm->cObj) strcpy(strName, "Unknown"); else { // Are we the source object? if (hsComm->cObj->GetDbref() == m_objnum) return; // Find our sensors. cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) strcpy(strName, "Unknown"); else { SENSOR_CONTACT *cContact; cContact = cSensors->GetContact(hsComm->cObj); if (!cContact) strcpy(strName, "Unknown"); else { // Determine if contact is id'd or not. if (cContact->status == IDENTIFIED) strcpy(strName, hsComm->cObj->GetName()); else sprintf(strName, "%d", cContact->m_id); } } } sprintf(tbuf, "%s[COMM Frq:%s %.2f %sSource:%s %s%s]%s\n%s\n%s*EOT*%s", ANSI_CYAN, ANSI_NORMAL, hsComm->frq, ANSI_CYAN, ANSI_NORMAL, strName, ANSI_CYAN, ANSI_NORMAL, hsComm->msg, ANSI_CYAN, ANSI_NORMAL); // Run through our consoles, looking for comm consoles on this // frequency. for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) { // Is it a COMM console, and is it on this frq? if (hsInterface.HasFlag(m_console_array[idx]->m_objnum, TYPE_THING, THING_HSPACE_COMM) && m_console_array[idx]->OnFrq(hsComm->frq)) { // Give the user the message. m_console_array[idx]->HandleMessage(tbuf, MSG_COMMUNICATION); } } } } src/hspace/hsshipeng.cpp 100664 767 767 60166 7141305141 13536 0 ustar mux mux #include "hscopyright.h" #include "hsobjects.h" #include "hsinterface.h" #include <stdlib.h> #include "hsutils.h" #include "hsconf.h" #include "hspace.h" #include "hsexterns.h" #include <string.h> extern double d2sin_table[]; extern double d2cos_table[]; // Gives the engineering system report for the ship void CHSShip::GiveEngSysReport(dbref player) { char tbuf[512]; char strTmp[32]; char strStress[256]; char strDamage[256]; char strPower[32]; CHSEngSystem *cSys; CHSReactor *cReactor; int idx; // Give the header info sprintf(tbuf, "%s%s.--------------------------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Engineering Systems Report %30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, GetName(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >------------------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Print system list and information sprintf(tbuf, "%s%s|%s %s%sSystem Status Power Stress Damage%s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // A variety of temporarily used variables float stress; int nslots; char pbuf[8]; char *ptr; int len; // Loop through the systems, giving info for (cSys = m_systems.GetHead(); cSys; cSys = cSys->GetNext()) { if (!cSys->IsVisible()) continue; // Setup the stress indicator *strStress = '\0'; stress = (float)(cSys->GetStress() * .10); // Use some tricks to print out the numerical stress as well. nslots = (int)(stress - .01); if (nslots < 10) nslots++; sprintf(pbuf, "%.0f%%", cSys->GetStress()); ptr = pbuf; len = strlen(pbuf); // Here's what we'll do. The stress bar is going // to take up 11 characters, regardless of how much // color is included. We want to print a color indicator // AND a number in the bar. Thus, we have to determine // how many color slots will be shown and keep track of // where we want to put the number, which will always // appear at the end of the color. char c; for (idx = 0; idx < 11; idx++) { if (*ptr && (nslots <= len)) c = *ptr++; else c = ' '; if (idx < stress) { if (idx < 3) { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BGREEN, c, ANSI_NORMAL); } else if (idx < 7) { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BYELLOW, c, ANSI_NORMAL); } else { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BRED, c, ANSI_NORMAL); } } else { strTmp[0] = c; strTmp[1] = '\0'; } strcat(strStress, strTmp); nslots--; } // Setup damage indicator switch(cSys->GetDamageLevel()) { case DMG_LIGHT: sprintf(strDamage, "%s%s LIGHT %s", ANSI_HILITE, ANSI_BGREEN, ANSI_NORMAL); break; case DMG_MEDIUM: sprintf(strDamage, "%s%s MEDIUM %s", ANSI_HILITE, ANSI_BYELLOW, ANSI_NORMAL); break; case DMG_HEAVY: sprintf(strDamage, "%s%s HEAVY %s", ANSI_HILITE, ANSI_BRED, ANSI_NORMAL); break; case DMG_INOPERABLE: sprintf(strDamage, "%s%sINOPERABLE%s", ANSI_HILITE, ANSI_BBLACK, ANSI_NORMAL); break; default: strcpy(strDamage, "None "); } strcat(strDamage, " "); // Setup power output string, which can vary in length sprintf(strPower, "%3d (%d)", cSys->GetCurrentPower(), cSys->GetOptimalPower()); sprintf(tbuf, "%s%s|%s %-20s %-9s %-10s %-11s %-13s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, cSys->GetName(), cSys->GetStatus(), strPower, strStress, strDamage, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Give reactor information cReactor = (CHSReactor *)m_systems.GetSystem(HSS_REACTOR); if (cReactor) { sprintf(tbuf, "%s%s >------------------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s %s+%s- Reactor Status -%s%s+ %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(strPower, "%d/%d (%d/%d)", cReactor->GetOutput(), cReactor->GetDesiredOutput(), cReactor->GetOutput() - m_systems.GetPowerUse(), cReactor->GetMaximumOutput()); sprintf(tbuf, "%s%s|%s Type : %-30s Output: %-19s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, "Fusion", strPower, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Setup the stress indicator *strStress = '\0'; stress = (float)(cReactor->GetStress() * .10); // Use some tricks to print out the numerical stress as well. nslots = (int)(stress - .01); if (nslots < 10) nslots++; sprintf(pbuf, "%.0f%%", cReactor->GetStress()); ptr = pbuf; len = strlen(pbuf); char c; for (idx = 0; idx < 30; idx++) { if (*ptr && (nslots <= len)) c = *ptr++; else c = ' '; if (idx < stress) { if (idx < 3) { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BGREEN, c, ANSI_NORMAL); } else if (idx < 7) { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BYELLOW, c, ANSI_NORMAL); } else { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BRED, c, ANSI_NORMAL); } } else { strTmp[0] = c; strTmp[1] = '\0'; } strcat(strStress, strTmp); nslots--; } // Setup damage indicator switch(cReactor->GetDamageLevel()) { case DMG_LIGHT: sprintf(strDamage, "%s%s LIGHT %s", ANSI_HILITE, ANSI_BGREEN, ANSI_NORMAL); break; case DMG_MEDIUM: sprintf(strDamage, "%s%s MEDIUM %s", ANSI_HILITE, ANSI_BYELLOW, ANSI_NORMAL); break; case DMG_HEAVY: sprintf(strDamage, "%s%s HEAVY %s", ANSI_HILITE, ANSI_BRED, ANSI_NORMAL); break; case DMG_INOPERABLE: sprintf(strDamage, "%s%sINOPERABLE%s", ANSI_HILITE, ANSI_BBLACK, ANSI_NORMAL); break; default: strcpy(strDamage, "None"); } strcat(strDamage, " "); sprintf(tbuf, "%s%s|%s Stress: %-30s Damage: %-19s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, strStress, strDamage, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } CHSFuelSystem *cFuel; cFuel = (CHSFuelSystem *)m_systems.GetSystem(HSS_FUEL_SYSTEM); if (cFuel) { // Give a fuel systems report sprintf(tbuf, "%s%s >------------------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s %s+%s- Fuel Status -%s%s+ %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Setup the fuel indicator *strStress = '\0'; float fLvl; float fPerc; fPerc = cFuel->GetFuelRemaining(FL_BURNABLE); fPerc = fPerc / cFuel->GetMaxFuel(FL_BURNABLE); fPerc *= 100; fLvl = (float)(fPerc * .10); // Use some tricks to print out the numerical fuel as well. nslots = (int)(fLvl - .01); if (nslots < 10) nslots++; sprintf(pbuf, "%.0f%%", fPerc); ptr = pbuf; len = strlen(pbuf); char c; for (idx = 0; idx < 10; idx++) { if (*ptr && (nslots <= len)) c = *ptr++; else c = ' '; if (idx < fLvl) { if (idx < 3) { sprintf(strTmp, "%s%s%s%c%s", ANSI_HILITE, ANSI_WHITE, ANSI_BRED, c, ANSI_NORMAL); } else if (idx < 7) { sprintf(strTmp, "%s%s%s%c%s", ANSI_HILITE, ANSI_WHITE, ANSI_BYELLOW, c, ANSI_NORMAL); } else { sprintf(strTmp, "%s%s%s%c%s", ANSI_HILITE, ANSI_WHITE, ANSI_BGREEN, c, ANSI_NORMAL); } } else { strTmp[0] = c; strTmp[1] = '\0'; } strcat(strStress, strTmp); nslots--; } // Burnable fuel indicator setup. char strBurn[256]; strcpy(strBurn, strStress); // Print out two fuel types? if (HSCONF.use_two_fuels) { // Setup reactable fuel indicator *strStress = '\0'; float fLvl; float fPerc; fPerc = cFuel->GetFuelRemaining(FL_REACTABLE); fPerc = (float)(fPerc / (cFuel->GetMaxFuel(FL_REACTABLE) + .001)); fPerc *= 100; fLvl = (float)(fPerc * .10); // Use some tricks to print out the numerical fuel as well. nslots = (int)(fLvl - .01); if (nslots < 10) nslots++; sprintf(pbuf, "%.0f%%", fPerc); ptr = pbuf; len = strlen(pbuf); char c; for (idx = 0; idx < 10; idx++) { if (*ptr && (nslots <= len)) c = *ptr++; else c = ' '; if (idx < fLvl) { if (idx < 3) { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BRED, c, ANSI_NORMAL); } else if (idx < 7) { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BYELLOW, c, ANSI_NORMAL); } else { sprintf(strTmp, "%s%s%c%s", ANSI_HILITE, ANSI_BGREEN, c, ANSI_NORMAL); } } else { strTmp[0] = c; strTmp[1] = '\0'; } strcat(strStress, strTmp); nslots--; } sprintf(tbuf, "%s%s|%s Reactor Fuel: %-10s Engine Fuel: %-10s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, strStress, strBurn, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } else { sprintf(tbuf, "%s%s|%s Storage Level: %-30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, strBurn, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } } // Finish the report sprintf(tbuf, "%s%s`--------------------------------------------------------------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Allows a player to try to set the desired system power // level. If the bPercent variable is TRUE, then iLvl is // specified in percentage of optimal power. void CHSShip::SetSystemPower(dbref player, char *lpstrName, int iLvl, BOOL bPercent) { CHSEngSystem *cSys; CHSReactor *cReactor; int iPowerLeft; char tbuf[64]; // Look for the system cSys = m_systems.GetSystemByName(lpstrName); if (!cSys) { hsStdError(player, "Invalid system specified."); return; } // Find the reactor to see how much power we have cReactor = (CHSReactor *)m_systems.GetSystem(HSS_REACTOR); if (!cReactor) { hsStdError(player, "This vessel has no power reactor."); return; } // Calculate power available. iPowerLeft = cReactor->GetOutput() - m_systems.GetPowerUse(); // Special case for setting reactor output if (cSys->GetType() == HSS_REACTOR) { // Translate iLvl to actual output? if (bPercent) { iLvl = (int)(cReactor->GetMaximumOutput() * (iLvl / 100.0)); } if (!cReactor->SetOutputLevel(iLvl)) { hsStdError(player, "Failed to set desired output level."); } else { sprintf(tbuf, "Desired reactor output level now set to %d MW.", iLvl); hsStdError(player, tbuf); } } else if (cSys->IsVisible()) // Has to be visible { // It's a regular system, so try to set the desired // power level. // Translate iLvl to actual output? if (bPercent) { iLvl = (int)(cSys->GetOptimalPower(TRUE) * (iLvl / 100.0)); } // Power available? if ((iLvl - cSys->GetCurrentPower()) > iPowerLeft) { hsStdError(player, "Insufficient power available for that operation."); return; } if (!cSys->SetCurrentPower(iLvl)) { hsStdError(player, "Failed to set desired power level."); } else { sprintf(tbuf, "%s power now set to %d MW.", cSys->GetName(), iLvl); hsStdError(player, tbuf); } } else { hsStdError(player, "Invalid system specified."); return; } // Update total power usage m_systems.UpdatePowerUse(); } // Allows a player to move an engineering system up or down // in the list, which will force the ship to draw power from // certain systems first, preserving more important systems. void CHSShip::ChangeSystemPriority(dbref player, char *lpstrName, int iChange) { CHSEngSystem *cSys; cSys = m_systems.GetSystemByName(lpstrName); if (!cSys || !cSys->IsVisible()) { hsStdError(player, "Invalid system specified."); return; } if (!m_systems.BumpSystem(cSys, iChange)) { hsStdError(player, "Failed to modify system priority."); return; } hsStdError(player, "System priority modified."); } // Prints a generic picture of the ship, giving hull and shield // percentages. void CHSShip::GiveVesselStats(dbref player) { int iFore; int iAft; int iPort; int iStar; int iHull; CHSSysShield *cShield; char tbuf[512]; char *picture[64]; // Initially, all values are -1 to indicate the shield // doesn't exist. iFore = iAft = iPort = iStar = -1; // Look for each shield cShield = (CHSSysShield *)m_systems.GetSystem(HSS_FORE_SHIELD); if (cShield) iFore = (int)cShield->GetShieldPerc(); cShield = (CHSSysShield *)m_systems.GetSystem(HSS_AFT_SHIELD); if (cShield) iAft = (int)cShield->GetShieldPerc(); cShield = (CHSSysShield *)m_systems.GetSystem(HSS_STARBOARD_SHIELD); if (cShield) iStar = (int)cShield->GetShieldPerc(); cShield = (CHSSysShield *)m_systems.GetSystem(HSS_PORT_SHIELD); if (cShield) iPort = (int)cShield->GetShieldPerc(); iHull = 100*(GetHullPoints() / GetMaxHullPoints()); // Give the header info sprintf(tbuf, "%s%s.--------------------------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s Vessel Statistics %30s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, GetName(), ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >------------------------------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Now draw a pretty picture if (!caClasses.LoadClassPicture(m_class, picture)) { sprintf(tbuf, "%s%s|%s No picture available %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } else { int idx; char *ptr, *dptr; char valbuf[64]; char tbuf2[256]; int len; for (idx = 0; picture[idx]; idx++) { // Parse the buffer line for special chars len = 0; dptr = tbuf2; for (ptr = picture[idx]; *ptr; ptr++) { // Look for tokens if (*ptr == '%') { switch(*(ptr+1)) { case 'h': // HULL case 'H': if (iHull < 25) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_RED, iHull, ANSI_NORMAL); else if (iHull < 50) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_YELLOW, iHull, ANSI_NORMAL); else sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_GREEN, iHull, ANSI_NORMAL); len += 4; break; case 'a': // Aft shield case 'A': if (iAft < 0) strcpy(valbuf, "---%"); else if (iAft < 25) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_RED, iAft, ANSI_NORMAL); else if (iAft < 50) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_YELLOW, iAft, ANSI_NORMAL); else sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_GREEN, iAft, ANSI_NORMAL); len += 4; break; case 'f': // Fore shield case 'F': if (iFore < 0) strcpy(valbuf, "---%"); if (iFore < 25) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_RED, iFore, ANSI_NORMAL); else if (iFore < 50) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_YELLOW, iFore, ANSI_NORMAL); else sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_GREEN, iFore, ANSI_NORMAL); len += 4; break; case 's': // Starboard shield case 'S': if (iStar < 0) strcpy(valbuf, "---%"); if (iStar < 25) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_RED, iStar, ANSI_NORMAL); else if (iStar < 50) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_YELLOW, iStar, ANSI_NORMAL); else sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_GREEN, iStar, ANSI_NORMAL); len += 4; break; case 'p': // Port shield case 'P': if (iPort < 0) strcpy(valbuf, "---%"); if (iPort < 25) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_RED, iPort, ANSI_NORMAL); else if (iPort < 50) sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_YELLOW, iPort, ANSI_NORMAL); else sprintf(valbuf, "%s%s%3d%%%s", ANSI_HILITE, ANSI_GREEN, iPort, ANSI_NORMAL); len += 4; break; default: // Not a token valbuf[0] = *ptr; valbuf[1] = *(ptr + 1); valbuf[2] = '\0'; break; } ptr++; char *sptr; for (sptr = valbuf; *sptr; sptr++) *dptr++ = *sptr; } else { len+=2; *dptr++ = *ptr; } } // Make sure we have the 68 printable characters needed // for the display. while(len < 68) { *dptr++ = ' '; len++; } *dptr = '\0'; sprintf(tbuf, "%s%s|%s%-68s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf2, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); delete [] picture[idx]; } } // Finish the report sprintf(tbuf, "%s%s`--------------------------------------------------------------------'%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Allows an attribute to be set for a specified system // on the ship. BOOL CHSShip::SetSystemAttribute(char *lpstrSysName, char *lpstrAttr, char *lpstrValue) { CHSEngSystem *cSys; // Look for the system cSys = m_systems.GetSystemByName(lpstrSysName); if (!cSys) return FALSE; // System found, try to set the attr. return (cSys->SetAttributeValue(lpstrAttr, lpstrValue)); } // Retrieves a SENSOR_CONTACT structure from the sensor // array for the given CHSObject. SENSOR_CONTACT *CHSShip::GetSensorContact(CHSObject *cObj) { CHSSysSensors *cSensors; // Get the sensor array cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) return NULL; return cSensors->GetContact(cObj); } // Retrieves a SENSOR_CONTACT structure from the sensor // array for the given an id. SENSOR_CONTACT *CHSShip::GetSensorContact(int id) { CHSSysSensors *cSensors; // Get the sensor array cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) return NULL; return cSensors->GetContactByID(id); } // Determines which shield on the ship is hit based on an // incoming XY and Z angle and a given number of shields // on the ship. CHSSysShield *CHSShip::DetermineHitShield(int iXYAngle, int iZAngle) { CHSSysShield *cFore; CHSSysShield *cAft; CHSSysShield *cPort; CHSSysShield *cStar; double iVec[4]; double jVec[4]; // Vector storage double kVec[4]; // Find our shields cFore = (CHSSysShield *)m_systems.GetSystem(HSS_FORE_SHIELD); cAft = (CHSSysShield *)m_systems.GetSystem(HSS_AFT_SHIELD); cPort = (CHSSysShield *)m_systems.GetSystem(HSS_PORT_SHIELD); cStar = (CHSSysShield *)m_systems.GetSystem(HSS_STARBOARD_SHIELD); // How many shields do we have? It should be an even number int nShields = 0; if (cFore) nShields++; if (cAft) nShields++; if (cPort) nShields++; if (cStar) nShields++; // Now, based on the number of shields, calculate normal // vectors. Right now, we're only supporting 2 or 4 // shields. if (!nShields) return NULL; if (nShields == 1) return cFore; if (nShields == 3) nShields = 2; // Make incoming z angle positive if (iZAngle < 0) iZAngle += 360; int zang; int xyang; if (nShields == 2) { // Calculate positive zheading zang = m_current_zheading; if (zang < 0) zang += 360; // Forward normal vector is the ship's heading iVec[0] = d2sin_table[m_current_xyheading] * d2cos_table[zang]; jVec[0] = d2cos_table[m_current_xyheading] * d2cos_table[zang]; kVec[0] = d2sin_table[zang]; // Aft normal vector is ship's heading - 180 xyang = m_current_xyheading + 180; if (xyang > 359) xyang -= 360; // Flip the zheading sign zang = m_current_zheading * -1; if (zang < 0) zang += 360; iVec[1] = d2sin_table[xyang] * d2cos_table[zang]; jVec[1] = d2cos_table[xyang] * d2cos_table[zang]; kVec[1] = d2sin_table[zang]; // Calculate incoming vector. double i, j, k; i = d2sin_table[iXYAngle] * d2cos_table[iZAngle]; j = d2cos_table[iXYAngle] * d2cos_table[iZAngle]; k = d2sin_table[iZAngle]; // Now see which dot product is negative. That's // our shield. We only have to calculate one. double dp1; dp1 = (iVec[0] * i) + (jVec[0] * j) + (kVec[0] * k); // Check to see if it's negative to save another // calculation. if (dp1 < 0) return cFore; else return cAft; } else { // Calculate two normal vectors to represent two // intersecting planes. // Add 45 degrees to XY to get the normal // vector for plane 1. xyang = m_current_xyheading + 45; // Reduce zheading to 1/2 for plane 1. zang = m_current_zheading * .5; // Now calculate normal vector 1 (N1) if (xyang > 359) xyang -= 360; if (zang < 0) zang += 360; iVec[0] = d2sin_table[xyang] * d2cos_table[zang]; jVec[0] = d2cos_table[xyang] * d2cos_table[zang]; kVec[0] = d2sin_table[zang]; // Subtract 45 degrees for XY of normal vector 2 xyang = m_current_xyheading - 45; zang = m_current_zheading * .5; if (xyang < 0) xyang += 360; if (zang < 0) zang += 360; // Calculate normal vector 2 (N2) iVec[1] = d2sin_table[xyang] * d2cos_table[zang]; jVec[1] = d2cos_table[xyang] * d2cos_table[zang]; kVec[1] = d2sin_table[zang]; // Calculate vector of incoming angle double i, j, k; i = d2sin_table[iXYAngle] * d2cos_table[iZAngle]; j = d2cos_table[iXYAngle] * d2cos_table[iZAngle]; k = d2sin_table[iZAngle]; // Calculate two dot products, which can result // in 4 sign (negative/positive) combinations. These // combos will tell us which shield. double dp1, dp2; dp1 = (iVec[0] * i) + (jVec[0] * j) + (kVec[0] * k); dp2 = (iVec[1] * i) + (jVec[1] * j) + (kVec[1] * k); if (dp1 > 1) dp1 = 1; else if (dp1 < -1) dp1 = -1; if (dp2 > 1) dp2 = 1; else if (dp2 < -1) dp2 = -1; // Determine shield based on sign combo if (dp1 > 0) { if (dp2 >= 0) return cAft; else return cPort; } else { if (dp2 <= 0) return cFore; else return cStar; } } } // Returns a pointer to an engineering system on the ship. CHSEngSystem *CHSShip::GetEngSystem(int type) { return m_systems.GetSystem((HSS_TYPE)type); } // Returns a pointer to the ship's engineering systems array. CHSSystemArray *CHSShip::GetEngSystemArray(void) { return &m_systems; } // Returns a list of engineering system types on the // ship, which are stored in the buffer supplied to // the function. The return value is the number of // systems found on the ship. UINT CHSShip::GetEngSystemTypes(int *iBuff) { CHSEngSystem *cSys; int nSystems; nSystems = 0; for (cSys = m_systems.GetHead(); cSys; cSys = cSys->GetNext()) { iBuff[nSystems] = cSys->GetType(); nSystems++; } return nSystems; } src/hspace/hsshipnav.cpp 100664 767 767 163552 7141305141 13574 0 ustar mux mux #include "hscopyright.h" #include "hsobjects.h" #include "hscelestial.h" #include "hsinterface.h" #include <stdlib.h> #include "hsutils.h" #include "hsconf.h" #include "hsengines.h" #include "hsdb.h" #include "hspace.h" #include "hsexterns.h" #include "hsuniverse.h" #include "hsterritory.h" #include <string.h> extern double d2cos_table[]; extern double d2sin_table[]; // Allows a player to set a desired velocity for the ship. void CHSShip::SetVelocity(dbref player, int iVel) { CHSSysEngines *cEngines; int iMaxVelocity; double dCurrentSpeed; char tbuf[256]; // Check to see if we're dropping or lifting off if (m_drop_status) { hsStdError(player, "Unable to set speed during surface exchange."); return; } if (m_dock_status) { hsStdError(player, "Unable to set speed while docking."); return; } // Find the engines cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) { hsStdError(player, "This vessel has no engines."); return; } if (!cEngines->GetCurrentPower()) { hsStdError(player, HSCONF.engines_offline); return; } if (cEngines->GetDamageLevel() == DMG_INOPERABLE) { hsStdError(player, "The engines have been destroyed!"); return; } if (m_docked || m_dropped) { hsStdError(player, HSCONF.ship_is_docked); return; } if (m_dock_status) { hsStdError(player, HSCONF.ship_is_docking); return; } // Is the ship afterburning? if (cEngines->GetAfterburning()) { hsStdError(player, "Cannot set speed while afterburners are engaged."); return; } iMaxVelocity = cEngines->GetMaxVelocity(); if ((iVel > iMaxVelocity) || (iVel < (-1 * (iMaxVelocity / 2.0)))) { sprintf(tbuf, "Specified velocity must range from %d to %d.", (int)(-1 * (iMaxVelocity / 2.0)), iMaxVelocity); hsStdError(player, tbuf); return; } if (cEngines->SetDesiredSpeed(iVel)) { sprintf(tbuf, "Desired velocity now set to %d hph.", iVel); hsStdError(player, tbuf); } else { hsStdError(player, "Failed to set desired velocity."); return; } dCurrentSpeed = cEngines->GetCurrentSpeed(); /* * Give some effects messages */ if ((iVel > 0) && (dCurrentSpeed < 0)) NotifySrooms(HSCONF.engine_forward); else if ((iVel < 0) && (dCurrentSpeed > 0)) NotifySrooms(HSCONF.engine_reverse); else if (iVel > dCurrentSpeed) NotifySrooms(HSCONF.speed_increase); else NotifySrooms(HSCONF.speed_decrease); } // Sets the heading of the ship to a desired XY and Z angle. // Either variable can be ignored, resulting in no change // for the angle represented by that variable. void CHSShip::SetHeading(dbref player, int iXYAngle, int iZAngle) { CHSSysThrusters *cThrust; if (m_hyperspace) { hsStdError(player, HSCONF.ship_is_jumping); return; } if (m_drop_status) { hsStdError(player, "Unable to change course during surface exchange."); return; } if (m_dock_status) { hsStdError(player, "Unable to change course while docking."); return; } // Find the thrusters system cThrust = (CHSSysThrusters *) m_systems.GetSystem(HSS_THRUSTERS); if (!cThrust) { hsStdError(player, "This vessel has no maneuvering thrusters."); return; } if (!cThrust->GetCurrentPower()) { hsStdError(player, "Thrusters are not currently online."); return; } if (cThrust->GetDamageLevel() == DMG_INOPERABLE) { hsStdError(player, "The maneuvering thrusters have been destroyed!"); return; } if (iXYAngle == NOTHING) iXYAngle = m_desired_xyheading; if (iZAngle == NOTHING) iZAngle = m_desired_zheading; if ((iXYAngle < 0) || (iXYAngle > 359)) { notify(player, "Valid XY headings range from 0 - 359."); return; } if ((iZAngle < -90) || (iZAngle > 90)) { notify(player, "Valid Z headings range from -90 - 90."); return; } m_desired_xyheading = iXYAngle; m_desired_zheading = iZAngle; char tbuf[256]; sprintf(tbuf, "Course heading changed to %d mark %d.", iXYAngle, iZAngle); hsStdError(player, tbuf); // increase_training(player, tship, .01); } // Cyclicly changes the heading of the ship. void CHSShip::ChangeHeading(void) { CHSSysThrusters *cThrust; int iTurnRate; int iZChange; int iXYChange; int iDiff; BOOL bChanged; cThrust = (CHSSysThrusters *)m_systems.GetSystem(HSS_THRUSTERS); if (!cThrust || !cThrust->GetCurrentPower()) return; iTurnRate = cThrust->GetRate(); bChanged = FALSE; iXYChange = iZChange = 0; // Check the zheading first because this will affect the // trig for the XY plane. if (m_current_zheading != m_desired_zheading) { bChanged = TRUE; if (m_desired_zheading > m_current_zheading) { if ((m_desired_zheading - m_current_zheading) > iTurnRate) { m_current_zheading += iTurnRate; iZChange = iTurnRate; } else { iZChange = m_desired_zheading - m_current_zheading; m_current_zheading = m_desired_zheading; } } else { if ((m_current_zheading - m_desired_zheading) > iTurnRate) { m_current_zheading -= iTurnRate; iZChange = -iTurnRate; } else { iZChange = m_desired_zheading - m_current_zheading; m_current_zheading = m_desired_zheading; } } } // Now handle any changes in the XY plane. if (m_desired_xyheading != m_current_xyheading) { bChanged = TRUE; if (abs(m_current_xyheading - m_desired_xyheading) < 180) { if (abs(m_current_xyheading - m_desired_xyheading) < iTurnRate) { iXYChange = m_desired_xyheading - m_current_xyheading; m_current_xyheading = m_desired_xyheading; } else if (m_current_xyheading > m_desired_xyheading) { iXYChange = -iTurnRate; m_current_xyheading -= iTurnRate; } else { iXYChange = iTurnRate; m_current_xyheading += iTurnRate; } } else if (((360 - m_desired_xyheading) + m_current_xyheading) < 180) { iDiff = (360 - m_desired_xyheading) + m_current_xyheading; if (iDiff < iTurnRate) { iXYChange = -iDiff; m_current_xyheading = m_desired_xyheading; } else { iXYChange = -iTurnRate; m_current_xyheading -= iTurnRate; } } else if (((360 - m_current_xyheading) + m_desired_xyheading) < 180) { iDiff = (360 - m_current_xyheading) + m_desired_xyheading; if (iDiff < iTurnRate) { iXYChange = iDiff; m_current_xyheading = m_desired_xyheading; } else { iXYChange = iTurnRate; m_current_xyheading += iTurnRate; } } else // This should never be true, but just in case. { iXYChange = iTurnRate; m_current_xyheading += iTurnRate; } // Check to make sure angles are 0-359 if (m_current_xyheading > 359) m_current_xyheading -= 360; else if (m_current_xyheading < 0) m_current_xyheading += 360; } // If nothing was changed, do nothing, else update stuff. if (bChanged) { // Run through any consoles, changing their headings int idx; for (idx = 0; idx < MAX_SHIP_CONSOLES; idx++) { if (m_console_array[idx]) m_console_array[idx]->AdjustHeading(iXYChange, iZChange); } // Recompute heading vector. Necessary for any heading change. RecomputeVectors(); } } // Returns the current speed of the ship. int CHSShip::GetSpeed(void) { CHSSysEngines *cEngines; // Find the engines cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) return 0; else { int speed; speed = (int)cEngines->GetCurrentSpeed(); return speed; } } // Returns the XY heading of the ship. UINT CHSShip::GetXYHeading(void) { return m_current_xyheading; } // Returns the current Z heading of the ship int CHSShip::GetZHeading(void) { return m_current_zheading; } // Moves the ship according to engine settings, heading vectors, // all that good stuff. void CHSShip::Travel(void) { double speed; double dCurrentSpeed; CHSSysEngines *cEngines; // Find the engines cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) dCurrentSpeed = 0; else dCurrentSpeed = cEngines->GetCurrentSpeed(); /* * Speed is measured in Hetramere per hour */ if (dCurrentSpeed ) { double oldx, oldy, oldz; // New coords after movement. // Save current coords in case we need them. oldx = m_x; oldy = m_y; oldz = m_z; // Bring speed down to the unit per second level // The .0002778 is actually 1/3600.0 precomputed // to save time. speed = (dCurrentSpeed) * (.0002778 * HSCONF.cyc_interval); /* * If the ship is jumping, everything is accelerated */ if (m_hyperspace) speed *= HSCONF.jump_speed_multiplier; // Add to the current position .. heading vector * speed. m_x += m_motion_vector.i() * speed; m_y += m_motion_vector.j() * speed; m_z += m_motion_vector.k() * speed; // See if we've moved into a new territory. CHSTerritory *newterritory; newterritory = taTerritories.InTerritory(this); dbref oldterr, newterr; // Check to see if we've moved in or out of a territory if (!m_territory) oldterr = NOTHING; else oldterr = m_territory->GetDbref(); if (newterritory) newterr = newterritory->GetDbref(); else newterr = NOTHING; if (oldterr != newterr) { // We've crossed borders. // If entering a new territory, only give that // message. Else, give a leave message for the // old one. char *s; if (newterr && hsInterface.ValidObject(newterr)) { if (hsInterface.AtrGet(newterr, "ENTER")) { s = hsInterface.EvalExpression( hsInterface.m_buffer, newterr, m_objnum, m_objnum, NULL, 0); NotifyConsoles(s, MSG_GENERAL); } did_it(m_objnum, newterr, 0, NULL, 0, NULL, A_AENTER, NULL, 0); } else if (hsInterface.ValidObject(oldterr)) { if (hsInterface.AtrGet(oldterr, "LEAVE")) { s = hsInterface.EvalExpression( hsInterface.m_buffer, oldterr, m_objnum, m_objnum, NULL, 0); NotifyConsoles(s, MSG_GENERAL); } } // Always trigger ALEAVE for territory left. if (oldterr != NOTHING && hsInterface.ValidObject(oldterr)) did_it(m_objnum, oldterr, 0, NULL, 0, NULL, A_ALEAVE, NULL, 0); } // Set our new territory m_territory = newterritory; } } // Handles recomputing the current heading vectors. Handy function. void CHSShip::RecomputeVectors(void) { int zhead; int xyhead; zhead = m_current_zheading; if (zhead < 0) zhead += 360; xyhead = m_current_xyheading; CHSVector tvec( d2sin_table[xyhead] * d2cos_table[zhead], d2cos_table[xyhead] * d2cos_table[zhead], d2sin_table[zhead]); m_motion_vector = tvec; } // Gives the big, navigation status report for the vessel. void CHSShip::GiveNavigationStatus(dbref player) { CHSSysComputer *cComputer; CHSSysSensors *cSensors; CHSSysShield *cShield; CHSSysEngines *cEngines; // Lines that will get printed in the map portion char mLine1[128]; char mLine2[128]; char mLine3[128]; char mLine4[128]; char mLine5[128]; char mLine6[128]; char mLine7[128]; char mLine8[128]; char charcolors[64][64]; // Used to store object chars and colors char tbuf[256]; int insX, insY; // Where to insert into the map int idx; int tdx; char *ptr; // Find a variety of systems we'll need. cComputer = (CHSSysComputer *) m_systems.GetSystem(HSS_COMPUTER); if (!cComputer) { hsStdError(player, "This vessel has no internal computer."); return; } cSensors = (CHSSysSensors *) m_systems.GetSystem(HSS_SENSORS); cEngines = (CHSSysEngines *) m_systems.GetSystem(HSS_ENGINES); charcolors[0][0] = '\0'; // We have to spend the majority of this function // just shoving characters into the map, so that's what we'll // start with. memset(mLine1, '\0', 128); memset(mLine2, '\0', 128); for (idx = 0; idx < 32; idx++) mLine1[idx] = ' '; for (idx = 0; idx < 34; idx++) mLine2[idx] = ' '; for (idx = 0; idx < 35; idx++) { mLine3[idx] = ' '; mLine4[idx] = ' '; mLine5[idx] = ' '; mLine6[idx] = ' '; mLine7[idx] = ' '; } mLine3[idx] = '\0'; mLine4[idx] = '\0'; mLine5[idx] = '\0'; mLine6[idx] = '\0'; mLine7[idx] = '\0'; for (idx = 0; idx < 34; idx++) mLine8[idx] = ' '; mLine8[idx] = '\0'; // Ok, now we need to run through sensor contacts and // insert them into the map. Each object has a certain // character and color, and we need to map it's real world // coordinates into the map. The map range specifies the // scale of the map, so if the object maps to a location // outside of the scale, it's excluded. if (cSensors) { SENSOR_CONTACT *cContact; CHSObject *cObj; double dX, dY, dZ; char filler; for (idx = 0; idx < HS_MAX_CONTACTS; idx++) { cContact = cSensors->GetContact(idx); if (!cContact) continue; cObj = cContact->m_obj; // Grab it's coordinates dX = cObj->GetX(); dY = cObj->GetY(); dZ = cObj->GetZ(); // Check to see if it's within our map range if ((m_x - dX) > m_map_range || (m_x - dX) < -m_map_range|| (m_y - dY) > m_map_range || (m_y - dY) < -m_map_range) continue; filler = cObj->GetObjectCharacter(); // See if we need to store color and character // info for this object type. for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == filler) break; } if (!charcolors[tdx][0]) { // Store it ptr = charcolors[tdx]; charcolors[tdx][0] = filler; charcolors[tdx][1] = '\0'; strcat(charcolors[tdx], cObj->GetObjectColor()); charcolors[tdx+1][0] = '\0'; } // Determine where to put the object in the ASCII map. insX = (int)((((dX - m_x) / (m_map_range * 2)) * 34) + 17); insY = (int)((((m_y - dY) / (m_map_range * 2)) * 8) + 4); switch(insY) { case 0: if (insX > 2 && insX < 32) mLine1[insX] = filler; break; case 1: if (insX > 0 && insX < 34) mLine2[insX] = filler; break; case 2: mLine3[insX] = filler; break; case 3: mLine4[insX] = filler; break; case 4: mLine5[insX] = filler; break; case 5: mLine6[insX] = filler; break; case 6: mLine7[insX] = filler; break; default: if (insX > 2 && insX < 34) mLine8[insX] = filler; break; } } } // Now do HUD stuff // XY HUD first int x1, x2, x3; x2 = (int) ((m_current_xyheading / 10.0) * 10); x1 = x2 - 10; x3 = x2 + 10; if (x1 < 0) x1 += 360; else if (x1 > 359) x1 -= 360; if (x2 < 0) x2 += 360; else if (x2 > 359) x2 -= 360; if (x3 < 0) x3 += 360; else if (x3 > 359) x3 -= 360; // Now Z HUD stuff int z1, z2, z3; // This are the little ticks on the heading bar z2 = (int)((m_current_zheading / 10.0) * 10); z1 = z2 + 10; z3 = z2 - 10; // Now print the display. char tbuf2[256]; sprintf(tbuf, "%s%s.---------------------------------------------------------------------------.%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf2, "%s (%s)", GetName(), m_ident ? m_ident : "--"); sprintf(tbuf, "%s%s|%s %-29s %s%s|%s %40s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf2, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, m_classinfo->m_name, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s >---%sNavigation Status Report%s---%s+%s------------------------------------------<%s", ANSI_HILITE, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_WHITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); char tnum1[32]; char tnum2[32]; char tnum3[32]; if (x1 < 10) sprintf(tnum1, " %d ", x1); else sprintf(tnum1, "%-3d", x1); if (x2 < 10) sprintf(tnum2, " %d ", x2); else sprintf(tnum2, "%3d", x2); if (x3 < 10) sprintf(tnum3, " %d ", x3); else sprintf(tnum3, "%3d", x3); sprintf(tbuf, "%s%s|%s %s %s %s %s%s| %sX:%s %10.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tnum1, tnum2, tnum3, ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, m_x, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s %4d%s%s__ |____%s%s.%s_____|_____%s%s.%s____| %s| %sY:%s %10.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, z1, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, m_y, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); if (m_current_xyheading < 10) sprintf(tnum1, " %d ", m_current_xyheading); else sprintf(tnum1, "%3d", m_current_xyheading); sprintf(tbuf, "%s%s| %s|%s > %s < %s%s| %sZ:%s %10.0f %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, tnum1, ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, m_z, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s|%s %s-%s| %s___________________________ |%s %s+%s- Course -%s%s+ %s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Now we have to print out the map lines. Phew. char tbuf3[256]; // Line 1 *tbuf2 = '\0'; for (idx = 3; mLine1[idx]; idx++) { if (mLine1[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine1[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tbuf3, "%s%c%s", ptr, mLine1[idx], ANSI_NORMAL); else sprintf(tbuf3, "%s%c%s", ANSI_HILITE, mLine1[idx], ANSI_NORMAL); } else sprintf(tbuf3, " "); strcat(tbuf2, tbuf3); } sprintf(tbuf, "%s%s|%s %4d%s%s-->%s %-3d %s%s/%s%s%s%s\\ | %sC:%s %3d/%-3d %s%sD:%s %3d/%-3d %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, z2, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, m_current_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf2, ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, m_current_xyheading, m_current_zheading, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, m_desired_xyheading, m_desired_zheading, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Line 2 *tbuf3 = '\0'; for (idx = 1; mLine2[idx]; idx++) { if (mLine2[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine2[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine2[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine2[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } if (cEngines && cEngines->CanBurn()) { sprintf(tbuf2, "%.0f/%s%.0f%s (%.0f)", cEngines ? cEngines->GetCurrentSpeed() : 0.0, cEngines->GetAfterburning() ? "*" : "", cEngines ? cEngines->GetDesiredSpeed() : 0.0, cEngines->GetAfterburning() ? "*" : "", cEngines ? cEngines->GetMaxVelocity() : 0.0); } else sprintf(tbuf2, "%.0f/%.0f (%.0f)", cEngines ? cEngines->GetCurrentSpeed() : 0.0, cEngines ? cEngines->GetDesiredSpeed() : 0.0, cEngines ? cEngines->GetMaxVelocity() : 0.0); sprintf(tbuf, "%s%s|%s %s-%s|%s %s%s/%s%s%s%s\\| %sV:%s %-21s%s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, tbuf2, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Line 3 *tbuf3 = '\0'; for (idx = 0; mLine3[idx]; idx++) { if (mLine3[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine3[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine3[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine3[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } sprintf(tbuf, "%s%s| %s__| %s|%s%s%s%s| |%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Line 4 *tbuf3 = '\0'; for (idx = 0; mLine4[idx]; idx++) { if (mLine4[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine4[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine4[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine4[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } cShield = (CHSSysShield *) m_systems.GetSystem(HSS_FORE_SHIELD); if (!cShield) strcpy(tnum1, " * "); else sprintf(tnum1, "%.0f%%", cShield->GetShieldPerc()); sprintf(tbuf, "%s%s|%s %4d %s%s|%s%s%s%s| %sShields%s %4s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, z3, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, tnum1, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Line 5 *tbuf3 = '\0'; for (idx = 0; mLine5[idx]; idx++) { if (idx == 17) sprintf(tnum1, "%s+%s", ANSI_HILITE, ANSI_NORMAL); else if (mLine5[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine5[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine5[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine5[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } sprintf(tbuf, "%s%s| |%s%s%s%s|%s | %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Line 6 *tbuf3 = '\0'; for (idx = 0; mLine6[idx]; idx++) { if (mLine6[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine6[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine6[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine6[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } cShield = (CHSSysShield *) m_systems.GetSystem(HSS_PORT_SHIELD); if (cShield) sprintf(tnum1, "%.0f%%", cShield->GetShieldPerc()); else strcpy(tnum1, " *"); cShield = (CHSSysShield *) m_systems.GetSystem(HSS_STARBOARD_SHIELD); if (cShield) sprintf(tnum2, "%.0f%%", cShield->GetShieldPerc()); else strcpy(tnum2, "* "); double perc; perc = GetMaxHullPoints(); perc = 100 * (GetHullPoints() / perc); sprintf(tbuf, "%s%s| %sHP:%s %3.0f%% %s%s|%s%s%s%s|%s %4s -%s+%s- %-4s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, perc, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tnum1, ANSI_HILITE, ANSI_NORMAL, tnum2, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Line 7 *tbuf3 = '\0'; for (idx = 0; mLine7[idx]; idx++) { if (mLine7[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine7[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine7[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine7[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } sprintf(tbuf, "%s%s| %sMR:%s %-8d%s%s|%s%s%s%s|%s | %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_NORMAL, m_map_range, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); // Finally, line 8. *tbuf3 = '\0'; for (idx = 1; mLine8[idx]; idx++) { if (mLine8[idx] != ' ') { // Find the character type and color ptr = NULL; for (tdx = 0; charcolors[tdx][0]; tdx++) { if (charcolors[tdx][0] == mLine8[idx]) { ptr = charcolors[tdx]; ptr++; break; } } if (ptr) sprintf(tnum1, "%s%c%s", ptr, mLine8[idx], ANSI_NORMAL); else sprintf(tnum1, "%s%c%s", ANSI_HILITE, mLine8[idx], ANSI_NORMAL); } else sprintf(tnum1, " "); strcat(tbuf3, tnum1); } cShield = (CHSSysShield *) m_systems.GetSystem(HSS_AFT_SHIELD); if (!cShield) strcpy(tnum1, " * "); else sprintf(tnum1, "%.0f%%", cShield->GetShieldPerc()); sprintf(tbuf, "%s%s| %s %s\\%s%s%s%s/%s %4s %s%s|%s", ANSI_HILITE, ANSI_BLUE, ANSI_GREEN, ANSI_BLUE, ANSI_NORMAL, tbuf3, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL, tnum1, ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); sprintf(tbuf, "%s%s`---------------\\\\.___________________________.//--------------------------`%s", ANSI_HILITE, ANSI_BLUE, ANSI_NORMAL); notify(player, tbuf); } // Sets the map range of the ship to a given distance. // This distance is like a scale. It specifies, basically, // a clipping region such that objects further than this // distance are not included in the map. At the same time, // it maps objects within the clipping range to the map // on the navigation display. BOOL CHSShip::SetMapRange(dbref player, int range) { // Have to have a real range if (range <= 0) return FALSE; // We can handle up to 8 digit ranges if (range > 99999999) return FALSE; m_map_range = range; return TRUE; } // Attempts to land the ship in another ship or on a // celestial surface. void CHSShip::LandVessel(dbref player, int id, int loc, char *lpstrCode) { SENSOR_CONTACT *cContact; CHSSysSensors *cSensors; CHSSysEngines *cEngines; CHSObject *cObj; char tbuf[256]; HS_TYPE tType; CHSLandingLoc *cLocation; // Perform some situational error checking if (m_drop_status) { hsStdError(player, "You may not do that during surface exchange."); return; } if (m_dock_status) { hsStdError(player, "Ship is currently in docking/undocking procedures."); return; } // Find the sensors, so we can grab the contact cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) { hsStdError(player, "This vessel has no sensors. Contact not found."); return; } // Find the sensor contact based on the given number. cContact = cSensors->GetContactByID(id); if (!cContact) { sprintf(tbuf, "%s%s[%s%4d%s%s]%s - No such contact on sensors.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, id, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); notify(player, tbuf); return; } // Are our engines online? cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) { hsStdError(player, "This vessel has no engines. Unable to land."); return; } if (cEngines->GetCurrentPower() == 0) { hsStdError(player, "Engines are currently offline."); return; } // Contact found, so let's see if it's an object // we can land on. We support ships and planets. cObj = cContact->m_obj; tType = cObj->GetType(); if (tType != HST_SHIP && tType != HST_PLANET) { sprintf(tbuf, "%s%s[%s%4d%s%s]%s - Cannot land on that type of object.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, id, ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); notify(player, tbuf); return; } // Do some ship to ship error checking. if (cObj->GetType() == HST_SHIP) { // Are we too big? if (GetSize() > HSCONF.max_dock_size) { hsStdError(player, "Our vessel is too large to dock in another vessel."); return; } // Are they too small? if (GetSize() >= cObj->GetSize()) { hsStdError(player, "That vessel is too small to accomodate us."); return; } // Is it within range? double dDist; dDist = Dist3D(m_x, m_y, m_z, cObj->GetX(), cObj->GetY(), cObj->GetZ()); if (dDist > HSCONF.max_dock_dist) { sprintf(tbuf, "Location must be within %d %s to commence docking.", HSCONF.max_dock_dist, HSCONF.unit_name); hsStdError(player, tbuf); return; } // Must be at a full stop to dock. if (cEngines && cEngines->GetCurrentSpeed()) { hsStdError(player, "Must be at a full stop to commence docking."); return; } // Find the landing location CHSShip *cShip; cShip = (CHSShip *)cObj; // The landing locations are specified by the player as // 1 .. n, but we store them in array notation 0..n-1. // Thus, subtract 1 from location when retrieving. cLocation = cShip->GetLandingLoc(loc-1); } else // Must be a planet { // Do we have drop rockets? if (!CanDrop()) { hsStdError(player, "This vessel does not have drop capability."); return; } // Is it within range? double dDist; dDist = Dist3D(m_x, m_y, m_z, cObj->GetX(), cObj->GetY(), cObj->GetZ()); if (dDist > HSCONF.max_drop_dist) { sprintf(tbuf, "Location must be within %d %s to commence landing.", HSCONF.max_drop_dist, HSCONF.unit_name); hsStdError(player, tbuf); return; } // Are we too fast to land? if (cEngines && cEngines->GetCurrentSpeed() > HSCONF.max_land_speed) { sprintf(tbuf, "Must be traveling at less than %d %s to commence landing.", HSCONF.max_land_speed, HSCONF.unit_name); hsStdError(player, tbuf); return; } // Find the landing location CHSPlanet *cPlanet; cPlanet = (CHSPlanet *)cObj; cLocation = cPlanet->GetLandingLoc(loc-1); } // Location exists? if (!cLocation) { hsStdError(player, "That landing location does not exist."); return; } // See if the landing site is active. if (!cLocation->IsActive()) { hsStdError(player, "That landing site is currently not open for landing."); return; } // See if we have code clearance? if (!cLocation->CodeClearance(lpstrCode)) { hsStdError(player, "Invalid landing code -- permission denied."); return; } // See if the landing site can accomodate us. if (!cLocation->CanAccomodate(this)) { hsStdError(player, "Landing site cannot accomodate this vessel."); return; } // Set desired and current speed to 0 to stop the ship. cEngines->SetDesiredSpeed(0); cEngines->SetAttributeValue("CURRENT SPEED", "0"); // Ok. Everything checks out, so begin landing procedures. InitLanding(player, cContact, cLocation); } // Initializes the landing procedures, be it for a planet or ship. void CHSShip::InitLanding(dbref player, SENSOR_CONTACT *cContact, CHSLandingLoc *cLocation) { HS_TYPE tType; CHSObject *cObj; char tbuf[256]; CHSUniverse *uDest; // Grab a few variables from the contact cObj = cContact->m_obj; tType = cObj->GetType(); // Get our universe uDest = uaUniverses.FindUniverse(m_uid); // Now, what type of object is it? We need to set some // variables. m_drop_status = 0; m_dock_status = 0; switch(tType) { case HST_SHIP: CHSShip *cShip; cShip = (CHSShip *)cObj; // Give some messages sprintf(tbuf, "%s[%s%s%d%s%s]%s - Docking request accepted .. beginning docking procedures.", cObj->GetObjectColor(), ANSI_NORMAL, ANSI_HILITE, cContact->m_id, ANSI_NORMAL, cObj->GetObjectColor(), ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); sprintf(tbuf, "The %s is beginning docking procedures at this location.", GetName()); cShip->HandleMessage(tbuf, MSG_SENSOR, (long *)this); // Set the dock status to 8, which is the number // of seconds it takes to dock. Undocking is a // negative number, so sign matters! m_dock_status = 8; m_docked = FALSE; m_landing_target = cLocation; break; case HST_PLANET: // Give some messages sprintf(tbuf, "%s-%s Beginning descent to the surface of %s ...", cObj->GetObjectColor(), ANSI_NORMAL, cObj->GetName()); NotifyConsoles(tbuf, MSG_GENERAL); NotifySrooms(HSCONF.begin_descent); sprintf(tbuf, "In the distance, the %s begins its descent toward the surface of %s.", GetName(), cObj->GetName()); if (uDest) uDest->SendContactMessage(tbuf, IDENTIFIED, this); // Set the drop status to the positive number // of seconds it takes to drop. This is specified // in the config file. m_drop_status = HSCONF.seconds_to_drop; m_dropped = FALSE; m_landing_target = cLocation; break; default: // Who knows! notify(player, "Help! What type of HSpace object are you landing on?"); return; } } // Handles landing the ship, be it to a planet or another ship. void CHSShip::HandleLanding(void) { CHSSysShield *cShield; CHSUniverse *uSource; char tbuf[256]; // Determine which procedure we're in. if (m_dock_status > 0) { // We're landing in a ship. m_dock_status--; switch(m_dock_status) { case 6: // Bay doors open NotifyConsoles( "The enormous bay doors slowly begin to slide open in front of the ship.\n", MSG_GENERAL); m_landing_target->HandleMessage( "The enormous bay doors slowly begin to slide open ...", MSG_GENERAL); break; case 3: // Shields are dropped BOOL bShields; BOOL bShieldsUp; bShields = FALSE; bShieldsUp = FALSE; // If no shields present, go to docking cShield = (CHSSysShield *) m_systems.GetSystem(HSS_FORE_SHIELD); if (cShield) { if (cShield->GetCurrentPower() > 0) bShieldsUp = TRUE; cShield->SetCurrentPower(0); bShields = TRUE; } cShield = (CHSSysShield *) m_systems.GetSystem(HSS_AFT_SHIELD); if (cShield) { if (cShield->GetCurrentPower() > 0) bShieldsUp = TRUE; cShield->SetCurrentPower(0); bShields = TRUE; } cShield = (CHSSysShield *) m_systems.GetSystem(HSS_PORT_SHIELD); if (cShield) { if (cShield->GetCurrentPower() > 0) bShieldsUp = TRUE; cShield->SetCurrentPower(0); bShields = TRUE; } cShield = (CHSSysShield *) m_systems.GetSystem(HSS_STARBOARD_SHIELD); if (cShield) { if (cShield->GetCurrentPower() > 0) bShieldsUp = TRUE; cShield->SetCurrentPower(0); bShields = TRUE; } if (!bShields) { m_dock_status = 1; // Skip quickly to docking } else { sprintf(tbuf, "%s%s-%s Shield check ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); if (bShieldsUp) { sprintf(tbuf, " %s%s-%s lowering shields ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); } else { sprintf(tbuf, " %s%s-%s shields down.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); } } break; case 0: // Ship docks sprintf(tbuf, "Through the bay doors, the %s comes in and docks.", GetName()); m_landing_target->HandleMessage(tbuf, MSG_GENERAL); sprintf(tbuf, "The %s pushes forward as it glides in and docks.", GetName()); NotifyConsoles(tbuf, MSG_GENERAL); m_docked = TRUE; MoveShipObject(m_landing_target->objnum); // Set our location CHSObject *cOwner; cOwner = m_landing_target->GetOwnerObject(); if (cOwner) m_objlocation = cOwner->GetDbref(); else m_objlocation = NOTHING; // Remove us from active space uSource = uaUniverses.FindUniverse(m_uid); if (uSource) uSource->RemoveActiveObject(this); // Deduct the capacity from the landing loc m_landing_target->DeductCapacity(GetSize()); break; } } else if (m_drop_status > 0) { int iHalfMarker; // We're dropping to a planet. m_drop_status--; iHalfMarker = (int)(HSCONF.seconds_to_drop / 2.0); // At the half way point, give another message if (m_drop_status == iHalfMarker) { CHSSysSensors *cSensors; sprintf(tbuf, "%s%s-%s Surface contact in %d seconds ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, iHalfMarker); NotifyConsoles(tbuf, MSG_GENERAL); sprintf(tbuf, "In the sky above, a dropship comes into view as it descends toward the surface."); m_landing_target->HandleMessage(tbuf, MSG_GENERAL); // Clear the sensors if needed cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (cSensors) cSensors->ClearContacts(); // Remove us from the active universe. We're in // the atmosphere now. uSource = uaUniverses.FindUniverse(m_uid); if (uSource) uSource->RemoveActiveObject(this); // Indicate that we're no longer in space. We're // somewhere between heaven and hell! m_in_space = FALSE; } else if (m_drop_status == 0) { NotifySrooms(HSCONF.landing_msg); sprintf(tbuf, "You take a step back as the %s fires its drop rockets and lands before you.", GetName()); m_landing_target->HandleMessage(tbuf, MSG_GENERAL); MoveShipObject(m_landing_target->objnum); m_dropped = TRUE; // Set our location CHSObject *cOwner; cOwner = m_landing_target->GetOwnerObject(); m_objlocation = cOwner->GetDbref(); m_landing_target->DeductCapacity(GetSize()); } } } // Allows a player to undock, or lift off, a ship that is // docked or dropped. void CHSShip::UndockVessel(dbref player) { CHSSysEngines *cEngines; CHSLandingLoc *cLocation; CHSSysComputer *cComputer; CHSObject *cObj; dbref dbRoom; char tbuf[256]; // Determine our status. if (!m_dropped && !m_docked) { // We're not docked or dropped. hsStdError(player, "This vessel is not currently docked or landed."); return; } // Make sure we're not docking or dropping if (m_dock_status) { if (m_dock_status < 0) hsStdError(player, HSCONF.ship_is_undocking); else hsStdError(player, HSCONF.ship_is_docking); return; } if (m_drop_status) { if (m_drop_status > 0) hsStdError(player, "Vessel is currently descending to the surface."); else hsStdError(player, "Vessel is already lifting off from the surface."); return; } // Find the current landing location based on the // location of the ship object. if (m_objnum == NOTHING) { notify(player, "Help! I can't find the ship object for your vessel."); return; } dbRoom = Location(m_objnum); cLocation = dbHSDB.FindLandingLoc(dbRoom); if (!cLocation) { hsStdError(player, "You may not undock from this location."); return; } // Determine the owner of the landing location. cObj = cLocation->GetOwnerObject(); if (!cObj) { notify(player, "Help! I can't figure out which planet/ship this landing location belongs to."); return; } // Make sure engines and computer are online. cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); cComputer= (CHSSysComputer*)m_systems.GetSystem(HSS_COMPUTER); if (!cEngines || !cComputer) { hsStdError(player, "This vessel is either missing the engines or computer needed to take off."); return; } if (!cEngines->GetCurrentPower() || !cComputer->GetCurrentPower()) { hsStdError(player, "Engines and computer systems must first be online."); return; } // We've got the location. // We've got the CHSObject that owns the location. // Figure out the type of object and undock/lift off. if (cObj->GetType() == HST_SHIP) { // Takes 15 seconds to undock, so set that variable. m_dock_status = -15; sprintf(tbuf, "%s%s-%s Undocking .. systems check initiating ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); } else if (cObj->GetType() == HST_PLANET) { // Set the lift off time plus 5 seconds systems check m_drop_status = -(HSCONF.seconds_to_drop) - 5; sprintf(tbuf, "%s%s-%s Commencing lift off procedures ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); sprintf(tbuf, "Smoke begins to trickle from the lift rockets of the %s ...", GetName()); hsInterface.NotifyContents(dbRoom, tbuf); } else { notify(player, "What the ..? This landing location isn't on a planet or ship."); return; } // We'll use the landing target variable to indicate // the location we're coming from. m_landing_target = cLocation; } // Handles the undocking/lift off continuation procedures such // as systems checking, putting the ship into space, etc. void CHSShip::HandleUndocking(void) { char tbuf[256]; double dVal; // Determine our status if (m_dock_status < 0) { m_dock_status++; switch(m_dock_status) { case -13: // Hull check dVal = GetMaxHullPoints(); dVal = 100 * (GetHullPoints() / dVal); sprintf(tbuf, " %s%s-%s Hull at %.0f%% integrity ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, dVal); NotifyConsoles(tbuf, MSG_GENERAL); break; case -10: // Reactor check CHSReactor *cReactor; cReactor = (CHSReactor *)m_systems.GetSystem(HSS_REACTOR); if (!cReactor) sprintf(tbuf, " %s%s-%s Reactor not present .. ?", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); else { dVal = cReactor->GetMaximumOutput(FALSE); dVal = 100 * cReactor->GetOutput() / dVal; sprintf(tbuf, " %s%s-%s Reactor online at %.0f%% power ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, dVal); } NotifyConsoles(tbuf, MSG_GENERAL); break; case -7: // Life support check CHSSysLifeSupport *cLife; cLife = (CHSSysLifeSupport *)m_systems.GetSystem(HSS_LIFE_SUPPORT); if (!cLife || !cLife->GetCurrentPower()) sprintf(tbuf, " %s%s%s*%s %s%sWARNING%s %s%s%s*%s Life support systems are not online.", ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL); else sprintf(tbuf, " %s%s-%s Life support systems -- online.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); break; case -4: // Engine status report CHSSysEngines *cEngines; cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) sprintf(tbuf, " %s%s-%s Engines not present .. ?", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); else { dVal = cEngines->GetOptimalPower(FALSE); dVal = 100 * cEngines->GetCurrentPower() / dVal; sprintf(tbuf, " %s%s-%s Engines online at %.0f%% power ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, dVal); } NotifyConsoles(tbuf, MSG_GENERAL); break; case -2: // Bay doors open sprintf(tbuf, "\nThe bay doors begin to slide open as the %s prepares for departure ...\n", GetName()); NotifyConsoles(tbuf, MSG_GENERAL); sprintf(tbuf, "The bay doors begin to slide open as the %s prerares for departure ...", GetName()); hsInterface.NotifyContents(m_landing_target->objnum, tbuf); break; case 0: sprintf(tbuf, "You feel a sudden lift as the %s glides forth from the docking bay.", GetName()); NotifySrooms(tbuf); sprintf(tbuf, "The %s fires its engines as it departs through the docking bay doors.", GetName()); hsInterface.NotifyContents(m_landing_target->objnum, tbuf); // Find the object we're undocking from. CHSObject *cUndockingFrom; cUndockingFrom = dbHSDB.FindObjectByLandingLoc(m_landing_target->objnum); CHSUniverse *uDest; if (cUndockingFrom) { uDest = uaUniverses.FindUniverse(cUndockingFrom->GetUID()); m_x = cUndockingFrom->GetX(); m_y = cUndockingFrom->GetY(); m_z = cUndockingFrom->GetZ(); } else { NotifyConsoles( "Unable to find source ship. Putting you where you docked at.", MSG_GENERAL); uDest = uaUniverses.FindUniverse(m_uid); } // Add us to the univeres's active list. if (!uDest) { NotifyConsoles( "Help! I can't find your universe!", MSG_GENERAL); return; } uDest->AddActiveObject(this); // We're in space now m_in_space = TRUE; m_docked = FALSE; // Move the ship object to the // universe room. MoveShipObject(uDest->GetID()); m_uid = uDest->GetID(); // Clear our location m_objlocation = NOTHING; // Add to the landing loc capacity int iSize; iSize = GetSize(); m_landing_target->DeductCapacity(-iSize); break; } } else if (m_drop_status < 0) { m_drop_status++; int iLifeCheck; int iTestLifters; int iHalfWay; iHalfWay = (int)(-HSCONF.seconds_to_drop / 2.0); iLifeCheck = -HSCONF.seconds_to_drop - 4; iTestLifters = -HSCONF.seconds_to_drop - 2; if (m_drop_status == iLifeCheck) { CHSSysLifeSupport *cLife; // Check life support. cLife = (CHSSysLifeSupport *)m_systems.GetSystem(HSS_LIFE_SUPPORT); if (!cLife) { sprintf(tbuf, " %s%s%s*%s %s%sWARNING%s %s%s%s*%s Life support systems non-existant!", ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); } else if (!cLife->GetCurrentPower()) { sprintf(tbuf, " %s%s%s*%s %s%sWARNING%s %s%s%s*%s Life support systems are not online.", ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_YELLOW, ANSI_NORMAL, ANSI_HILITE, ANSI_BLINK, ANSI_YELLOW, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); } else { sprintf(tbuf, " %s%s-%s Life support systems check - OK.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); } } else if (m_drop_status == iTestLifters) { // Test lift rockets. sprintf(tbuf, " %s%s-%s Testing lift rockets ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); sprintf(tbuf, "Flames spurt intermittently from the lift rockets of the %s ...", GetName()); hsInterface.NotifyContents( m_landing_target->objnum, tbuf); } else if (m_drop_status == -HSCONF.seconds_to_drop) { // LIFT OFF! sprintf(tbuf, "%s%s-%s Lift off procedures complete .. %d seconds to orbit.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, HSCONF.seconds_to_drop); NotifyConsoles(tbuf, MSG_GENERAL); NotifySrooms(HSCONF.lift_off); sprintf(tbuf, "The wind suddenly picks up as the %s fires its lift rockets and begins its climb upward.", GetName()); hsInterface.NotifyContents(m_landing_target->objnum, tbuf); // We're not dropped right now, but we're not in // space. m_dropped = FALSE; m_in_space = FALSE; // Clear our location m_objlocation = NOTHING; // Move the ship object to the // universe room. MoveShipObject(m_uid); } else if (m_drop_status == iHalfWay) { sprintf(tbuf, "%s%s-%s Orbit in %d seconds ...", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, -iHalfWay); NotifyConsoles(tbuf, MSG_GENERAL); sprintf(tbuf, "The %s disappears in the sky above as it continues its climb into orbit.", GetName()); hsInterface.NotifyContents(m_landing_target->objnum, tbuf); } else if (!m_drop_status) { int iSize; sprintf(tbuf, "%s%s-%s Ship is now in orbit above the celestial surface.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_GENERAL); // Add us to the univeres's active list. CHSUniverse *uDest; uDest = uaUniverses.FindUniverse(m_uid); if (!uDest) { NotifyConsoles( "Help! I can't find your universe!", MSG_GENERAL); return; } uDest->AddActiveObject(this); // We're in space now. m_in_space = TRUE; // Add to the landing loc capacity iSize = GetSize(); m_landing_target->DeductCapacity(-iSize); } } } // Returns the current location where the ship is docked/dropped, // or NOTHING if not applicable. dbref CHSShip::GetDockedLocation(void) { if (m_objnum == NOTHING) return NOTHING; if (m_dropped) { return Location(m_objnum); } else if (m_docked) { return Location(m_objnum); } else return NOTHING; } // Attempts to engage or disengage the afterburners. // Set bStat to TRUE to engage, FALSE to disengage. void CHSShip::EngageAfterburn(dbref player, BOOL bStat) { CHSSysEngines *cEngines; // Look for the engines cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) { hsStdError(player, "This vessel has no engines."); return; } // Can't afterburn while not in space if (!m_in_space && bStat) { hsStdError(player, "Unable to engage afterburners when not actively in space."); return; } // Can't afterburn when docking/dropping if (bStat && (m_drop_status || m_dock_status)) { hsStdError(player, "Unable to engage afterburners at this time."); return; } // Can the engines burn? if (!cEngines->CanBurn()) { hsStdError(player, "Our engines are not capable of afterburning."); return; } // Are engines online? if (!cEngines->GetCurrentPower()) { hsStdError(player, "Engines are not currently online."); return; } // Are the engines burning already? if (bStat && cEngines->GetAfterburning()) { hsStdError(player, "Afterburners already engaged."); return; } else if (!bStat && !cEngines->GetAfterburning()) { hsStdError(player, "The afterburners are not currently engaged."); return; } // Find our universe to give some messages CHSUniverse *uDest; char tbuf[256]; uDest = uaUniverses.FindUniverse(m_uid); // What change do we want to make? if (bStat) { // Engage. if (!cEngines->SetAfterburn(TRUE)) hsStdError(player, "Failed to engage afterburners."); else { sprintf(tbuf, "%s%s-%s Afterburners engaged.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_ENGINEERING); NotifySrooms(HSCONF.afterburn_engage); // Give some effects messages if (uDest) { sprintf(tbuf, "Flames roar from the engines of the %s as it engages its afterburners.", GetName()); uDest->SendContactMessage(tbuf, IDENTIFIED, this); } } } else { // Disengage if (!cEngines->SetAfterburn(FALSE)) hsStdError(player, "Failed to disengage afterburners."); else { sprintf(tbuf, "%s%s-%s Afterburners disengaged.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_ENGINEERING); NotifySrooms(HSCONF.afterburn_disengage); // Give some effects messages if (uDest) { sprintf(tbuf, "The roaring flames from the engines of the %s cease as it disengages afterburners.", GetName()); uDest->SendContactMessage(tbuf, IDENTIFIED, this); } } } } // Attempts to engage or disengage the jump drive. // Set bStat to TRUE to engage, FALSE to disengage. void CHSShip::EngageJumpDrive(dbref player, BOOL bStat) { CHSJumpDrive *cJumpers; CHSSysEngines *cEngines; char tbuf[128]; // Look for the jumpers cJumpers = (CHSJumpDrive *)m_systems.GetSystem(HSS_JUMP_DRIVE); if (!cJumpers) { hsStdError(player, "This vessel has no jump drive."); return; } // Can't jump while not in space if (!m_in_space && bStat) { hsStdError(player, "Unable to engage jump drive when not actively in space."); return; } // Can't jump when docking/dropping if (bStat && (m_drop_status || m_dock_status)) { hsStdError(player, "Unable to engage jump drive at this time."); return; } // Are jumpers online? if (!cJumpers->GetCurrentPower()) { hsStdError(player, "Jump drive is not currently online."); return; } // Are the jumpers engaged already? if (bStat && cJumpers->GetEngaged()) { hsStdError(player, "Jump drive already engaged."); return; } else if (!bStat && !cJumpers->GetEngaged()) { hsStdError(player, "The jump drive is not currently engaged."); return; } // What change do we want to make? if (bStat) { // Make sure we're at a good speed. cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); if (!cEngines) { hsStdError(player, "This vessel doesn't even have engines."); return; } if (cEngines->GetCurrentSpeed() < cJumpers->GetMinJumpSpeed()) { sprintf(tbuf, "Minimum sublight speed of %d %s/hr required to engage jump drive.", cJumpers->GetMinJumpSpeed(), HSCONF.unit_name); hsStdError(player, tbuf); return; } // Engage. if (!cJumpers->SetEngaged(TRUE)) hsStdError(player, "Failed to engage jump drive."); else { // Put us in hyperspace EnterHyperspace(); } } else { // Disengage if (!cJumpers->SetEngaged(FALSE)) hsStdError(player, "Failed to disengage jump drive"); else { ExitHyperspace(); } } } // Handles putting the ship into hyperspace, including effects // messages. void CHSShip::EnterHyperspace(void) { char tbuf[128]; CHSUniverse *uSource; if (m_hyperspace) return; m_hyperspace = TRUE; // Effects messages sprintf(tbuf, "%s%s-%s Jump drive engaged.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_ENGINEERING); NotifySrooms(HSCONF.ship_jumps); // Notify ships with us on sensors that // we've jumped. uSource = uaUniverses.FindUniverse(m_uid); if (uSource) { sprintf(tbuf, "You see a flash of blue light as the %s engages its jump drives.", GetName()); uSource->SendContactMessage(tbuf, IDENTIFIED, this); } } // Handles taking the ship out of hyperspace, including effects // messages. void CHSShip::ExitHyperspace(void) { CHSUniverse *uSource; char tbuf[128]; if (!m_hyperspace) return; m_hyperspace = FALSE; sprintf(tbuf, "%s%s-%s Jump drive disengaged.", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL); NotifyConsoles(tbuf, MSG_ENGINEERING); NotifySrooms(HSCONF.end_jump); // Notify ships with us on sensors that // we've come out of hyperspace. uSource = uaUniverses.FindUniverse(m_uid); if (uSource) { sprintf(tbuf, "You see a flash of blue light as a vessel comes out of hyperspace."); uSource->SendMessage(tbuf, 1000, this); } } // Returns TRUE or FALSE for whether the ship is in hyperspace // or not. BOOL CHSShip::InHyperspace(void) { return m_hyperspace; } // Allows a player to break a boarding link with a ship // in the specified boarding link slot. void CHSShip::DoBreakBoardLink(dbref player, int slot) { // Valid slot ID? Slots are specified from 1 .. n, // but they're stored as 0 .. n-1. if (slot < 1 || slot > MAX_BOARD_LINKS) { hsStdError(player, "Invalid boarding link ID specified."); return; } // Decrement slot for array notation. slot--; // Link exists? if (!m_board_links[slot]) { hsStdError(player, "No such boarding link with that ID."); return; } // Break it. m_board_links[slot]->MakeBoardLink(this, FALSE); m_board_links[slot] = NULL; hsStdError(player, "Boarding link connection terminated."); } // Attempts to establish a boarding connection with // another vessel. void CHSShip::DoBoardLink(dbref player, int id) { int idx; CHSJumpDrive *cJumpers; CHSSysEngines *cEngines; CHSSysSensors *cSensors; SENSOR_CONTACT *cContact; CHSObject *cObj; CHSShip *cShip; char tbuf[128]; // Look for the jumpers cJumpers = (CHSJumpDrive *)m_systems.GetSystem(HSS_JUMP_DRIVE); cEngines = (CHSSysEngines *)m_systems.GetSystem(HSS_ENGINES); cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); // Are they on sensors? cContact = NULL; if (cSensors) { cContact = cSensors->GetContactByID(id); } if (!cContact) { hsStdError(player, "No such contact id on sensors."); return; } cObj = cContact->m_obj; // Do we already have a boarding link with that thing? for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (m_board_links[idx]) { if (m_board_links[idx]->GetDbref() == cObj->GetDbref()) { hsStdError(player, "Boarding link already established with that contact."); return; } } } // Other object must be capable of board linking. if (cObj->GetType() != HST_SHIP) { hsStdError(player, "You may not establish a boarding link with that."); return; } cShip = (CHSShip *)cObj; // Are the jumpers engaged? if (cJumpers && cJumpers->GetEngaged()) { hsStdError(player, "Cannot make a boarding link while in hyperspace."); return; } // Are the afterburners engaged? if (cEngines && cEngines->GetAfterburning()) { hsStdError(player, "Cannot make a boarding link while afterburning."); return; } // See if we have room to make a boarding link. for (idx = 0; idx < MAX_BOARD_LINKS; idx++) { if (!m_board_links[idx]) break; } if (idx == MAX_BOARD_LINKS) { hsStdError(player, "Too many boarding links already established with other vessels."); return; } // See if the distance is ok if (Dist3D(GetX(), GetY(), GetZ(), cObj->GetX(), cObj->GetY(), cObj->GetZ()) > HSCONF.max_board_dist) { sprintf(tbuf, "Vessel must be within %d %s to establish boarding link.", HSCONF.max_board_dist, HSCONF.unit_name); hsStdError(player, tbuf); return; } // See if they have room for us. if (!cShip->MakeBoardLink(this, TRUE)) { hsStdError(player, "Target vessel cannot accomodate another boarding link."); return; } // Boarding link made with them. Store it for us. m_board_links[idx] = cShip; hsStdError(player, "Boarding link established."); } // Scans a target ID on sensors and gives the player a // scan report. void CHSShip::ScanObjectID(dbref player, int id) { CHSSysSensors *cSensors; SENSOR_CONTACT *cContact; // Do we have sensors? cSensors = (CHSSysSensors *)m_systems.GetSystem(HSS_SENSORS); if (!cSensors) { hsStdError(player, "This vessel is not equipped with sensors."); return; } // Are sensors online? if (!cSensors->GetCurrentPower()) { hsStdError(player, "Sensors are currently offline."); return; } // Find the contact. cContact = cSensors->GetContactByID(id); if (!cContact) { hsStdError(player, "No such contact ID on sensors."); return; } // Scan the object if (cContact->status == IDENTIFIED) cContact->m_obj->GiveScanReport(this, player, TRUE); else cContact->m_obj->GiveScanReport(this, player, FALSE); } src/hspace/hsterritory.cpp 100644 767 767 27564 7141305141 14147 0 ustar mux mux #include "hscopyright.h" #include "hsterritory.h" #include "hsutils.h" #include "hsinterface.h" #include <string.h> #include <stdlib.h> CHSTerritoryArray taTerritories; // Global instance // // CHSTerritoryArray // CHSTerritoryArray::CHSTerritoryArray(void) { // Initialize territories int idx; for (idx = 0; idx < HS_MAX_TERRITORIES; idx++) { m_territories[idx] = NULL; } } // Attempts to allocate a new territory in the array of the // specified type. CHSTerritory *CHSTerritoryArray::NewTerritory(int objnum, TERRTYPE type) { // Do we have any free slots? int idx; for (idx = 0; idx < HS_MAX_TERRITORIES; idx++) { if (!m_territories[idx]) break; } if (idx == HS_MAX_TERRITORIES) return NULL; // Determine type of territory switch(type) { case T_RADIAL: m_territories[idx] = new CHSRadialTerritory; break; case T_CUBIC: m_territories[idx] = new CHSCubicTerritory; break; default: // What is this territory type? return NULL; } // Set object num m_territories[idx]->SetDbref(objnum); // Set the territory flag if (objnum != NOTHING) hsInterface.SetFlag(m_territories[idx]->GetDbref(), THING_HSPACE_TERRITORY); return (CHSTerritory *)m_territories[idx]; } // Saves territories to the specified file path. void CHSTerritoryArray::SaveToFile(const char *lpstrPath) { int idx; FILE *fp; // Try to open the specified file for writing. fp = fopen(lpstrPath, "w"); if (!fp) return; // bummer // Run through our territories, telling them to write // to the file. for (idx = 0; idx < HS_MAX_TERRITORIES; idx++) { if (m_territories[idx]) { fprintf(fp, "TERRITORY=%d\n", m_territories[idx]->GetType()); // Our indicator m_territories[idx]->SaveToFile(fp); } } fclose(fp); } // Returns the number of territories loaded. UINT CHSTerritoryArray::NumTerritories(void) { int idx; int cnt = 0; // Count em. for (idx = 0; idx < HS_MAX_TERRITORIES;idx++) { if (m_territories[idx]) cnt++; } return cnt; } // Prints information about the loaded territories to the // specified player. void CHSTerritoryArray::PrintInfo(int player) { int idx; notify(player, "[Dbref] Name Type UID Specifications"); for (idx = 0; idx < HS_MAX_TERRITORIES; idx++) { if (m_territories[idx]) { switch(m_territories[idx]->GetType()) { case T_RADIAL: CHSRadialTerritory *cRadial; cRadial = (CHSRadialTerritory *)m_territories[idx]; notify(player, tprintf("[%5d] %-18s RADIAL %-3d Center: %d,%d,%d Radius: %d", m_territories[idx]->GetDbref(), Name(m_territories[idx]->GetDbref()), m_territories[idx]->GetUID(), cRadial->GetX(), cRadial->GetY(), cRadial->GetZ(), cRadial->GetRadius())); break; case T_CUBIC: CHSCubicTerritory *cCubic; cCubic = (CHSCubicTerritory *)m_territories[idx]; notify(player, tprintf("[%5d] %-18s CUBIC %-3d Min: %d,%d,%d Max: %d,%d,%d", m_territories[idx]->GetDbref(), Name(m_territories[idx]->GetDbref()), m_territories[idx]->GetUID(), cCubic->GetMinX(), cCubic->GetMinY(), cCubic->GetMinZ(), cCubic->GetMaxX(), cCubic->GetMaxY(), cCubic->GetMaxZ())); break; } } } } // Loads territories from the specified file. BOOL CHSTerritoryArray::LoadFromFile(const char *lpstrPath) { FILE *fp; // Try to open the specified file. fp = fopen(lpstrPath, "r"); if (!fp) return FALSE; // Drat // Read in the territories file, looking for TERRITORY // keywords. char key[128]; char value[128]; char tbuf[256]; char *ptr; CHSTerritory *cTerritory = NULL; while(fgets(tbuf, 128, fp)) { // Strip returns if (ptr = strchr(tbuf, '\r')) *ptr = '\0'; if (ptr = strchr(tbuf, '\n')) *ptr = '\0'; // Pull out the key and value. extract(tbuf, key, 0, 1, '='); extract(tbuf, value, 1, 1, '='); // Is it a new territory? if (!strcasecmp(key, "TERRITORY")) { // Grab a new territory. cTerritory = NewTerritory(NOTHING, (TERRTYPE)atoi(value)); if (!cTerritory) { hs_log("ERROR: Error encountered while loading territories."); break; } } else { // Assumed to be a territory key=value pair. // Pass it to the current territory. if (cTerritory) { if (!cTerritory->SetAttributeValue(key, value)) { sprintf(tbuf, "WARNING: Failed to set attribute \"%s\" on territory.", key); hs_log(tbuf); } } } } fclose(fp); return TRUE; } // Returns the territory that the given object falls within, // or NULL if none matched. CHSTerritory *CHSTerritoryArray::InTerritory(CHSObject *cObj) { // Run through our territories, asking them for a match. double x, y, z; int uid; x = cObj->GetX(); y = cObj->GetY(); z = cObj->GetZ(); uid = cObj->GetUID(); for (int idx = 0; idx < HS_MAX_TERRITORIES; idx++) { if (m_territories[idx]) { if (m_territories[idx]->PtInTerritory( uid, x, y, z)) return m_territories[idx]; } } return NULL; // No match } // Returns a CHSTerritory given the object number representing // the territory. CHSTerritory *CHSTerritoryArray::FindTerritory(int objnum) { for (int idx = 0; idx < HS_MAX_TERRITORIES; idx++) { if (m_territories[idx] && m_territories[idx]->GetDbref() == objnum) return m_territories[idx]; } // No match return NULL; } // Removes the territory with the specified object number BOOL CHSTerritoryArray::RemoveTerritory(int objnum) { int idx; for (idx = 0; idx < HS_MAX_TERRITORIES; idx++) { if (m_territories[idx] && m_territories[idx]->GetDbref() == objnum) { // Remove the flag if the object is good. if (hsInterface.ValidObject(m_territories[idx]->GetDbref())) hsInterface.UnsetFlag(m_territories[idx]->GetDbref(), THING_HSPACE_TERRITORY); delete m_territories[idx]; m_territories[idx] = NULL; return TRUE; } } return FALSE; // Not found } // // CHSTerritory // CHSTerritory::CHSTerritory(void) { m_objnum = -1; m_uid = -1; m_type = T_CUBIC; } // Returns TRUE if the given point is in this territory. // Base class returns FALSE always. BOOL CHSTerritory::PtInTerritory(int uid, double x, double y, double z) { return FALSE; } // Sets the object dbref representing the territory void CHSTerritory::SetDbref(int objnum) { m_objnum = objnum; } // Returns the dbref of the object representing the territory int CHSTerritory::GetDbref(void) { return m_objnum; } // Returns the territory type for the territory. TERRTYPE CHSTerritory::GetType(void) { return m_type; } // Returns the UID of the territory. int CHSTerritory::GetUID(void) { return m_uid; } // Attempts to set the given attribute name to the specified // value. If successful, TRUE is returned, otherwise FALSE. BOOL CHSTerritory::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name if (!strcasecmp(strName, "UID")) { iVal = atoi(strValue); m_uid = iVal; return TRUE; } else if (!strcasecmp(strName, "OBJNUM")) { iVal = atoi(strValue); m_objnum = iVal; // Set the territory flag hsInterface.SetFlag(m_objnum, THING_HSPACE_TERRITORY); return TRUE; } return FALSE; } // Writes attributes out for the territory to the given file pointer. void CHSTerritory::SaveToFile(FILE *fp) { fprintf(fp, "UID=%d\n", m_uid); fprintf(fp, "OBJNUM=%d\n", m_objnum); } // // CHSRadialTerritory // CHSRadialTerritory::CHSRadialTerritory(void) { m_radius = 0; m_cx = m_cy = m_cz = 0; m_type = T_RADIAL; } // Returns the central X value for the territory. int CHSRadialTerritory::GetX(void) { return m_cx; } // Returns the central Y value for the territory. int CHSRadialTerritory::GetY(void) { return m_cy; } // Returns the central Z value for the territory. int CHSRadialTerritory::GetZ(void) { return m_cz; } // Returns the radius of the territory int CHSRadialTerritory::GetRadius(void) { return m_radius; } // Saves all radial territory attrs to the file stream. void CHSRadialTerritory::SaveToFile(FILE *fp) { // Write base attrs first CHSTerritory::SaveToFile(fp); // Now ours fprintf(fp, "CX=%d\n", m_cx); fprintf(fp, "CY=%d\n", m_cy); fprintf(fp, "CZ=%d\n", m_cz); fprintf(fp, "RADIUS=%d\n", m_radius); } // Attempts to set the given attribute name to the specified // value. If successful, TRUE is returned, otherwise FALSE. BOOL CHSRadialTerritory::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name if (!strcasecmp(strName, "CX")) { iVal = atoi(strValue); m_cx = iVal; return TRUE; } else if (!strcasecmp(strName, "CY")) { iVal = atoi(strValue); m_cy = iVal; return TRUE; } else if (!strcasecmp(strName, "CZ")) { iVal = atoi(strValue); m_cz = iVal; return TRUE; } else if (!strcasecmp(strName, "RADIUS")) { iVal = atoi(strValue); m_radius = iVal; return TRUE; } else return CHSTerritory::SetAttributeValue(strName, strValue); } // Returns TRUE if the given point is in this territory. BOOL CHSRadialTerritory::PtInTerritory(int uid, double x, double y, double z) { // In our universe? if (uid != m_uid) return FALSE; // TRUE will be returned if the distance to the point is // less than our radius. double objDist; // Calculate squared distance from our center to point. objDist = ((m_cx - x) * (m_cx - x) + (m_cy - y) * (m_cy - y) + (m_cz - z) * (m_cz - z)); // Square radius double rad = (m_radius * m_radius); // Compare if (objDist <= rad) return TRUE; else return FALSE; } // // CHSCubicTerritory // CHSCubicTerritory::CHSCubicTerritory(void) { m_maxx = m_maxy = m_maxz = m_minx = m_miny = m_minz = 0; m_type = T_CUBIC; } // Saves all cubic territory attrs to the file stream. void CHSCubicTerritory::SaveToFile(FILE *fp) { // Write base attrs first CHSTerritory::SaveToFile(fp); // Now ours fprintf(fp, "MINX=%d\n", m_minx); fprintf(fp, "MINY=%d\n", m_miny); fprintf(fp, "MINZ=%d\n", m_minz); fprintf(fp, "MAXX=%d\n", m_maxx); fprintf(fp, "MAXY=%d\n", m_maxy); fprintf(fp, "MAXZ=%d\n", m_maxz); } // Attempts to set the given attribute name to the specified // value. If successful, TRUE is returned, otherwise FALSE. BOOL CHSCubicTerritory::SetAttributeValue(char *strName, char *strValue) { int iVal; // Match the name if (!strcasecmp(strName, "MINX")) { iVal = atoi(strValue); m_minx = iVal; return TRUE; } else if (!strcasecmp(strName, "MINY")) { iVal = atoi(strValue); m_miny = iVal; return TRUE; } else if (!strcasecmp(strName, "MINZ")) { iVal = atoi(strValue); m_minz = iVal; return TRUE; } else if (!strcasecmp(strName, "MAXX")) { iVal = atoi(strValue); m_maxx = iVal; return TRUE; } else if (!strcasecmp(strName, "MAXY")) { iVal = atoi(strValue); m_maxy = iVal; return TRUE; } else if (!strcasecmp(strName, "MAXZ")) { iVal = atoi(strValue); m_maxz = iVal; return TRUE; } else return CHSTerritory::SetAttributeValue(strName, strValue); } // Returns TRUE if the given point is in this territory. BOOL CHSCubicTerritory::PtInTerritory(int uid, double x, double y, double z) { // In our universe? if (uid != m_uid) return FALSE; // TRUE will be returned if the point is between the min // and max coordinates of us. if ((x <= m_maxx) && (x >= m_minx) && (y <= m_maxy) && (y >= m_miny) && (z <= m_maxz) && (z >= m_minz)) return TRUE; return FALSE; } // Returns the specified minimum value for the territory. int CHSCubicTerritory::GetMinX(void) { return m_minx; } // Returns the specified minimum value for the territory. int CHSCubicTerritory::GetMinY(void) { return m_miny; } // Returns the specified minimum value for the territory. int CHSCubicTerritory::GetMinZ(void) { return m_minz; } // Returns the specified maximum value for the territory. int CHSCubicTerritory::GetMaxX(void) { return m_maxx; } // Returns the specified maximum value for the territory. int CHSCubicTerritory::GetMaxY(void) { return m_maxy; } // Returns the specified maximum value for the territory. int CHSCubicTerritory::GetMaxZ(void) { return m_maxz; } src/hspace/hsterritory.h 100644 767 767 4273 7141305141 13564 0 ustar mux mux #ifndef __HSTERRITORY_INCLUDED__ #define __HSTERRITORY_INCLUDED__ #include "hstypes.h" #include "hsobjects.h" #define HS_MAX_TERRITORIES 20 enum TERRTYPE { T_RADIAL = 0, T_CUBIC, }; // A base territory class, from which other types of // territories can be derived. class CHSTerritory { public: CHSTerritory(void); void SetDbref(int); int GetDbref(void); int GetUID(void); TERRTYPE GetType(void); // Overridables virtual void SaveToFile(FILE *); virtual BOOL SetAttributeValue(char *, char *); virtual BOOL PtInTerritory(int, double, double, double); protected: UINT m_uid; // Universe territory is in int m_objnum; // Object in the game that represents this territory TERRTYPE m_type; }; // A radial territory that defines a sphere of ownership class CHSRadialTerritory : public CHSTerritory { public: CHSRadialTerritory(void); BOOL SetAttributeValue(char *, char *); BOOL PtInTerritory(int, double, double, double); int GetX(void); int GetY(void); int GetZ(void); int GetRadius(void); void SaveToFile(FILE *); protected: int m_cx; // Center coords int m_cy; int m_cz; UINT m_radius; }; // A cubic territory that defines a cube of ownership class CHSCubicTerritory : public CHSTerritory { public: CHSCubicTerritory(void); BOOL SetAttributeValue(char *, char *); BOOL PtInTerritory(int, double, double, double); int GetMinX(void); int GetMinY(void); int GetMinZ(void); int GetMaxX(void); int GetMaxY(void); int GetMaxZ(void); void SaveToFile(FILE *); protected: int m_minx; // Bounding coords. int m_miny; int m_minz; int m_maxx; int m_maxy; int m_maxz; }; // The CHSTerritoryArray stores a list of all territories in // the game and provides that information to whomever // requests it. class CHSTerritoryArray { public: CHSTerritoryArray(void); CHSTerritory *NewTerritory(int, TERRTYPE type = T_RADIAL); CHSTerritory *InTerritory(CHSObject *cObj); CHSTerritory *FindTerritory(int); UINT NumTerritories(void); BOOL LoadFromFile(const char *); BOOL RemoveTerritory(int); void SaveToFile(const char *); void PrintInfo(int); protected: CHSTerritory *m_territories[HS_MAX_TERRITORIES]; }; extern CHSTerritoryArray taTerritories; #endif // __HSTERRITORY_INCLUDED__ src/hspace/hstrig.cpp 100664 767 767 12702 7141305141 13037 0 ustar mux mux #include "hscopyright.h" double d2cos_table[360] = { 1, 1, 0.999, 0.999, 0.998, 0.996, 0.995, 0.993, 0.990, 0.988, 0.985, 0.982, 0.978, 0.974, 0.970, 0.966, 0.961, 0.956, 0.951, 0.946, 0.940, 0.934, 0.927, 0.921, 0.914, 0.906, 0.899, 0.891, 0.883, 0.875, 0.866, 0.857, 0.848, 0.839, 0.829, 0.819, 0.809, 0.799, 0.788, 0.777, 0.766, 0.755, 0.743, 0.731, 0.719, 0.707, 0.695, 0.682, 0.669, 0.656, 0.643, 0.629, 0.616, 0.602, 0.588, 0.574, 0.559, 0.545, 0.530, 0.515, 0.500, 0.485, 0.469, 0.454, 0.438, 0.423, 0.407, 0.391, 0.375, 0.358, 0.342, 0.326, 0.309, 0.292, 0.276, 0.259, 0.242, 0.225, 0.208, 0.191, 0.174, 0.156, 0.139, 0.122, 0.105, 0.087, 0.070, 0.052, 0.035, 0.017, 0, -0.017, -0.035, -0.052, -0.070, -0.087, -0.104, -0.122, -0.139, -0.156, -0.174, -0.191, -0.208, -0.225, -0.242, -0.259, -0.276, -0.292, -0.309, -0.326, -0.342, -0.358, -0.375, -0.391, -0.407, -0.423, -0.438, -0.454, -0.469, -0.485, -0.500, -0.515, -0.530, -0.545, -0.559, -0.574, -0.588, -0.602, -0.616, -0.629, -0.643, -0.656, -0.669, -0.682, -0.695, -0.707, -0.719, -0.731, -0.743, -0.755, -0.766, -0.777, -0.788, -0.799, -0.809, -0.819, -0.829, -0.839, -0.848, -0.857, -0.866, -0.875, -0.883, -0.891, -0.899, -0.906, -0.914, -0.920, -0.927, -0.934, -0.940, -0.945, -0.951, -0.956, -0.961, -0.966, -0.970, -0.974, -0.978, -0.982, -0.985, -0.988, -0.990, -0.993, -0.995, -0.996, -0.998, -0.999, -0.999, -1, -1, -1, -0.999, -0.999, -0.998, -0.996, -0.995, -0.993, -0.990, -0.988, -0.985, -0.982, -0.978, -0.974, -0.970, -0.966, -0.961, -0.956, -0.951, -0.946, -0.940, -0.934, -0.927, -0.921, -0.914, -0.906, -0.899, -0.891, -0.883, -0.875, -0.866, -0.857, -0.848, -0.839, -0.829, -0.819, -0.809, -0.799, -0.788, -0.777, -0.766, -0.755, -0.743, -0.731, -0.719, -0.707, -0.695, -0.682, -0.669, -0.656, -0.643, -0.629, -0.616, -0.602, -0.588, -0.574, -0.559, -0.545, -0.530, -0.515, -0.500, -0.485, -0.470, -0.454, -0.438, -0.423, -0.407, -0.391, -0.375, -0.358, -0.342, -0.326, -0.309, -0.292, -0.276, -0.259, -0.242, -0.225, -0.208, -0.191, -0.174, -0.157, -0.139, -0.122, -0.105, -0.087, -0.070, -0.052, -0.035, -0.018, -0, 0.017, 0.035, 0.052, 0.070, 0.087, 0.104, 0.122, 0.139, 0.156, 0.174, 0.191, 0.208, 0.225, 0.242, 0.259, 0.275, 0.292, 0.309, 0.325, 0.342, 0.358, 0.374, 0.391, 0.407, 0.422, 0.438, 0.454, 0.469, 0.485, 0.500, 0.515, 0.530, 0.545, 0.559, 0.573, 0.588, 0.602, 0.616, 0.629, 0.643, 0.656, 0.669, 0.682, 0.695, 0.707, 0.719, 0.731, 0.743, 0.755, 0.766, 0.777, 0.788, 0.799, 0.809, 0.819, 0.829, 0.839, 0.848, 0.857, 0.866, 0.875, 0.883, 0.891, 0.899, 0.906, 0.913, 0.920, 0.927, 0.934, 0.940, 0.945, 0.951, 0.956, 0.961, 0.966, 0.970, 0.974, 0.978, 0.982, 0.985, 0.988, 0.990, 0.993, 0.995, 0.996, 0.998, 0.999, 0.999, 1 }; double d2sin_table[360] = { 0,0.017, 0.035, 0.052, 0.070, 0.087, 0.105, 0.122, 0.139, 0.156, 0.174, 0.191, 0.208, 0.225, 0.242, 0.259, 0.276, 0.292, 0.309, 0.326, 0.342, 0.358, 0.375, 0.391, 0.407, 0.423, 0.438, 0.454, 0.469, 0.485, 0.500, 0.515, 0.530, 0.545, 0.559, 0.574, 0.588, 0.602, 0.616, 0.629, 0.643, 0.656, 0.669, 0.682, 0.695, 0.707, 0.719, 0.731, 0.743, 0.755, 0.766, 0.777, 0.788, 0.799, 0.809, 0.819, 0.829, 0.839, 0.848, 0.857, 0.866, 0.875, 0.883, 0.891, 0.899, 0.906, 0.914, 0.920, 0.927, 0.934, 0.940, 0.946, 0.951, 0.956, 0.961, 0.966, 0.970, 0.974, 0.978, 0.982, 0.985, 0.988, 0.990, 0.993, 0.995, 0.996, 0.998, 0.999, 0.999, 1, 1, 1, 0.999, 0.999, 0.998, 0.996, 0.995, 0.993, 0.990, 0.988, 0.985, 0.982, 0.978, 0.974, 0.970, 0.966, 0.961, 0.956, 0.951, 0.946, 0.940, 0.934, 0.927, 0.921, 0.914, 0.906, 0.899, 0.891, 0.883, 0.875, 0.866, 0.857, 0.848, 0.839, 0.829, 0.819, 0.809, 0.799, 0.788, 0.777, 0.766, 0.755, 0.743, 0.731, 0.719, 0.707, 0.695, 0.682, 0.669, 0.656, 0.643, 0.629, 0.616, 0.602, 0.588, 0.574, 0.559, 0.545, 0.530, 0.515, 0.500, 0.485, 0.470, 0.454, 0.438, 0.423, 0.407, 0.391, 0.375, 0.358, 0.342, 0.326, 0.309, 0.292, 0.276, 0.259, 0.242, 0.225, 0.208, 0.191, 0.174, 0.157, 0.139, 0.122, 0.105, 0.087, 0.070, 0.052, 0.035, 0.018, 0, -0.017, -0.035, -0.052, -0.070, -0.087, -0.104, -0.122, -0.139, -0.156, -0.174, -0.191, -0.208, -0.225, -0.242, -0.259, -0.276, -0.292, -0.309, -0.325, -0.342, -0.358, -0.375, -0.391, -0.407, -0.423, -0.438, -0.454, -0.469, -0.485, -0.500, -0.515, -0.530, -0.545, -0.559, -0.573, -0.588, -0.602, -0.616, -0.629, -0.643, -0.656, -0.669, -0.682, -0.695, -0.707, -0.719, -0.731, -0.743, -0.755, -0.766, -0.777, -0.788, -0.799, -0.809, -0.819, -0.829, -0.839, -0.848, -0.857, -0.866, -0.875, -0.883, -0.891, -0.899, -0.906, -0.913, -0.920, -0.927, -0.934, -0.940, -0.945, -0.951, -0.956, -0.961, -0.966, -0.970, -0.974, -0.978, -0.982, -0.985, -0.988, -0.990, -0.993, -0.995, -0.996, -0.998, -0.999, -0.999, -1, -1, -1, -0.999, -0.999, -0.998, -0.996, -0.995, -0.993, -0.990, -0.988, -0.985, -0.982, -0.978, -0.974, -0.970, -0.966, -0.961, -0.956, -0.951, -0.946, -0.940, -0.934, -0.927, -0.921, -0.914, -0.906, -0.899, -0.891, -0.883, -0.875, -0.866, -0.857, -0.848, -0.839, -0.829, -0.819, -0.809, -0.799, -0.788, -0.777, -0.766, -0.755, -0.743, -0.731, -0.719, -0.707, -0.695, -0.682, -0.669, -0.656, -0.643, -0.629, -0.616, -0.602, -0.588, -0.574, -0.559, -0.545, -0.530, -0.515, -0.500, -0.485, -0.470, -0.454, -0.439, -0.423, -0.407, -0.391, -0.375, -0.359, -0.342, -0.326, -0.309, -0.293, -0.276, -0.259, -0.242, -0.225, -0.208, -0.191, -0.174, -0.157, -0.139, -0.122, -0.105, -0.087, -0.070, -0.053, -0.035, -0.018}; src/hspace/hstypes.h 100644 767 767 404 7141305141 12635 0 ustar mux mux #ifndef __HSTYPES_INCLUDED__ #define __HSTYPES_INCLUDED__ #include "hsexterns.h" typedef int BOOL; typedef unsigned int UINT; #define TRUE 1 #define FALSE 0 #ifdef WIN32 #include <string.h> #define strcasecmp stricmp #endif #endif // __HSTYPES_INCLUDED__ src/hspace/hsuniverse.cpp 100664 767 767 45453 7141305141 13743 0 ustar mux mux #include "hscopyright.h" #include "hsuniverse.h" #include "hsutils.h" #include "hspace.h" #include "hseng.h" #include "hsconf.h" #include "hsinterface.h" #include <stdlib.h> #include <string.h> CHSUniverseArray uaUniverses; // One instance of this .. right here! CHSUniverseArray::CHSUniverseArray(void) { UINT idx; m_universes = new CHSUniverse *[HS_MAX_UNIVERSES]; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) m_universes[idx] = NULL; } CHSUniverseArray::~CHSUniverseArray(void) { UINT idx; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (m_universes[idx]) delete m_universes[idx]; } delete [] m_universes; } UINT CHSUniverseArray::NumUniverses(void) { return m_num_universes; } // Prints information about all of the universes in the array // to a given player. void CHSUniverseArray::PrintInfo(int player) { if (m_num_universes <= 0) { notify(player, "No universes currently loaded."); return; } notify(player, "[Room#] Name Objects Active"); int idx; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (m_universes[idx]) { notify(player, tprintf( "[%5d] %-32s%3d/%-3d %3d/%-3d", m_universes[idx]->GetID(), m_universes[idx]->GetName(), m_universes[idx]->NumObjects(), HS_MAX_OBJECTS, m_universes[idx]->NumActiveObjects(), HS_MAX_ACTIVE_OBJECTS)); } } } CHSUniverse *CHSUniverseArray::NewUniverse(void) { UINT idx; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (!m_universes[idx]) { m_universes[idx] = new CHSUniverse; m_num_universes++; // Give it a default ID. m_universes[idx]->SetID(idx); return m_universes[idx]; } } return NULL; } BOOL CHSUniverseArray::AddUniverse(CHSUniverse *un) { char tbuf[256]; UINT uUID; // Make sure we don't go past the array limitations uUID = un->GetID(); if ((uUID < 0) || (uUID >= HS_MAX_UNIVERSES)) { sprintf(tbuf, "WARNING: Invalid universe ID detected. Discarding %s.", un->GetName()); hs_log(tbuf); return FALSE; } // Looks ok, but we have to verify that there's not already // a universe in the slot that this one wants to go into. // Universes HAVE to go into the slot of their UID. if (m_universes[un->GetID()]) { sprintf(tbuf, "WARNING: Duplicate universe ID detected. Discarding %s.", un->GetName()); hs_log(tbuf); return FALSE; } m_universes[uUID] = un; m_num_universes++; return TRUE; } // Returns a pointer to a CHSUniverse given a universe dbref. CHSUniverse *CHSUniverseArray::FindUniverse(dbref objnum) { int idx; // Run through the list of universes for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (m_universes[idx]) { if (m_universes[idx]->GetID() == objnum) return m_universes[idx]; } } return NULL; } // Loads universes from the universe db. It does this by // loading each line in the db and splitting it up into // a key/value pair. BOOL CHSUniverseArray::LoadFromFile(char *lpstrPath) { char tbuf[256]; char strKey[256]; char strValue[256]; FILE *fp; char *ptr; CHSUniverse *uDest; HS_DBKEY key; UINT nLoaded; sprintf(tbuf, "LOADING: %s", lpstrPath); hs_log(tbuf); fp = fopen(lpstrPath, "r"); if (!fp) { hs_log("ERROR: Unable to open object database for loading!"); return FALSE; } uDest = NULL; nLoaded = 0; // Load in the lines from the database, splitting the // line into key/value pairs. Each OBJNUM key specifies // the beginning of a new universe definition. while(fgets(tbuf, 256, fp)) { // Truncate newline chars if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; // Check for end of DB if (!strcmp(tbuf, "*END*")) break; // Extract key and value extract(tbuf, strKey, 0, 1, '='); extract(tbuf, strValue, 1, 1, '='); // Determine key type, then do something. key = HSFindKey(strKey); switch(key) { case HSK_NOKEY: sprintf(tbuf, "WARNING: Invalid key \"%s\" encountered.", strKey); hs_log(tbuf); break; case HSK_DBVERSION: // This should be the first line, if present break; case HSK_OBJNUM: // NEW UNIVERSE! uDest = NewUniverse(); if (!uDest) { sprintf(tbuf, "ERROR: Unable to load universe #%d. Possibly ran out slots.", atoi(strValue)); hs_log(tbuf); } else { dbref dbRoom; dbRoom = atoi(strValue); uDest->SetID(dbRoom); hsInterface.SetFlag(dbRoom, ROOM_HSPACE_UNIVERSE); nLoaded++; } break; default: // Just try to set the attribute on the // universe. if (uDest && !uDest->SetAttributeValue(strKey, strValue)) { sprintf(tbuf, "WARNING: Key \"%s\" encountered but not handled.", strKey); hs_log(tbuf); } break; } } fclose(fp); sprintf(tbuf, "LOADING: %d universes loaded.", nLoaded); hs_log(tbuf); return TRUE; } // Returns the universe object in the given UID slot. CHSUniverse *CHSUniverseArray::GetUniverse(UINT uid) { // Error check if (uid < 0 || uid >= HS_MAX_UNIVERSES) return NULL; return m_universes[uid]; } BOOL CHSUniverseArray::DeleteUniverse(UINT uid) { // Find the universe int idx; CHSUniverse *uSource; for (idx = 0; idx < HS_MAX_UNIVERSES; idx++) { if (!m_universes[idx]) continue; uSource = m_universes[idx]; if (uSource->GetID() == uid) break; } if (idx == HS_MAX_UNIVERSES) return FALSE; // Check to see if the universe is empty if (!uSource->IsEmpty()) return FALSE; // Delete it delete uSource; m_universes[idx] = NULL; m_num_universes--; return TRUE; } // Runs through the list of universes, telling them to // save to the specified file. void CHSUniverseArray::SaveToFile(char *lpstrPath) { FILE *fp; int i; char tbuf[256]; // Open the database fp = fopen(lpstrPath, "w"); if (!fp) { sprintf(tbuf, "ERROR: Unable to write universes to %s.", lpstrPath); hs_log(tbuf); return; } // Print dbversion fprintf(fp, "DBVERSION=4.0\n"); // Run down the list of univereses, demanding they save! for (i = 0; i < HS_MAX_UNIVERSES; i++) { if (!m_universes[i]) continue; m_universes[i]->SaveToFile(fp); } fprintf(fp, "*END*\n"); fclose(fp); } CHSUniverse::CHSUniverse(void) { UINT idx; // Allocate storage arrays. The m_objlist and // m_active_objlist arrays are necessary. Everything // else is used to optimize searching for objects. m_objlist = new CHSObject *[HS_MAX_OBJECTS]; m_active_objlist = new CHSObject *[HS_MAX_ACTIVE_OBJECTS]; m_shiplist = new CHSShip *[HS_MAX_OBJECTS]; m_celestials = new CHSCelestial *[HS_MAX_OBJECTS]; // Initialize arrays for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { m_shiplist[idx] = NULL; m_objlist[idx] = NULL; m_celestials[idx] = NULL; } for (idx = 0; idx < HS_MAX_ACTIVE_OBJECTS; idx++) { m_active_objlist[idx] = NULL; } m_name = NULL; m_nCelestials = 0; m_nShips = 0; m_nObjects = 0; m_objnum = -1; } UINT CHSUniverse::GetID(void) { return m_objnum; } void CHSUniverse::SetID(int id) { m_objnum = id; } // Sets the name of the universe void CHSUniverse::SetName(char *strName) { if (m_name) { delete [] m_name; m_name = NULL; } if (strName) { m_name = new char[strlen(strName) + 1]; strcpy(m_name, strName); } } CHSUniverse::~CHSUniverse(void) { if (m_objlist) delete [] m_objlist; if (m_active_objlist) delete [] m_active_objlist; if (m_celestials) delete [] m_celestials; if (m_shiplist) delete [] m_shiplist; } char *CHSUniverse::GetName(void) { return m_name; } // Used to add a celestial to the list of celestials. The // celestial first exists in the object array. It's here // so that we can specifically search for just a celestial // if we want. BOOL CHSUniverse::AddCelestial(CHSCelestial *cObj) { UINT idx; // Check to see if it'll fit and that it's not already there. for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (!m_celestials[idx]) break; } if (idx == HS_MAX_OBJECTS) { hs_log((char *) "WARNING: Universe at celestial capacity."); return FALSE; } m_celestials[idx] = cObj; m_nCelestials++; return TRUE; } // This function is protected because any caller should call // the generic AddObject() function, which will then call this // function. This function, then, adds a ship (if possible) // to the universe ship list. BOOL CHSUniverse::AddShip(CHSShip *cObj) { UINT idx; // Check to see if it'll fit and that it's not already there. for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (!m_shiplist[idx]) break; } if (idx == HS_MAX_OBJECTS) { hs_log((char *) "WARNING: Universe at ship capacity."); return FALSE; } m_shiplist[idx] = cObj; m_nShips++; return TRUE; } // Finds a given object with a dbref number CHSObject *CHSUniverse::FindObject(dbref objnum, HS_TYPE type) { int idx; switch(type) { case HST_SHIP: return FindShip(objnum); case HST_PLANET: case HST_WORMHOLE: case HST_NEBULA: case HST_ASTEROID: case HST_BLACKHOLE: return FindCelestial(objnum); default: // Generic object for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (m_objlist[idx] && (m_objlist[idx]->GetDbref() == objnum)) return m_objlist[idx]; } return NULL; } } // Looks for a ship with the given object dbref CHSShip *CHSUniverse::FindShip(dbref objnum) { UINT idx; for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (!m_shiplist[idx]) continue; if (m_shiplist[idx]->GetDbref() == objnum) { return m_shiplist[idx]; } } return NULL; } // Looks for a celestial with the given object dbref CHSCelestial *CHSUniverse::FindCelestial(dbref objnum) { UINT idx; for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (!m_celestials[idx]) continue; if (m_celestials[idx]->GetDbref() == objnum) return m_celestials[idx]; } return NULL; } // Call this function to remove an object from the // "active" list for the universe, which stores all // objects that aren't docked, aren't dropped, etc. void CHSUniverse::RemoveActiveObject(CHSObject *cObj) { UINT idx; // Simply run down the list until we find the // object. Then yank it. for (idx = 0; idx < HS_MAX_ACTIVE_OBJECTS; idx++) { if (m_active_objlist[idx]) { // If this is the object being removed, remove it. // Otherwise, force its removal from the sensors // of other objects. if (m_active_objlist[idx]->GetDbref() == cObj->GetDbref()) { m_active_objlist[idx] = NULL; break; } else { CHSSysSensors *cSensors; cSensors = (CHSSysSensors *) m_active_objlist[idx]->GetEngSystem(HSS_SENSORS); if (cSensors) cSensors->LoseObject(cObj); } } } } // This is a public function that should be called to // remove ANY object from the universe. void CHSUniverse::RemoveObject(CHSObject *cObj) { int idx; // Determine the type of object, then call // the appropriate function. If you haven't // implemented your own storage arrays for // your type of object (like a ship or planet), // then don't worry about this. switch(cObj->GetType()) { case HST_SHIP: RemoveShip((CHSShip *)cObj); break; case HST_PLANET: break; } // Now remove the object from the object lists for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (!m_objlist[idx]) continue; if (m_objlist[idx]->GetDbref() == cObj->GetDbref()) { m_objlist[idx] = NULL; m_nObjects--; // Make sure it's out of the active list RemoveActiveObject(cObj); } } } // Adds an object to the active list of objects. BOOL CHSUniverse::AddActiveObject(CHSObject *cObj) { int idx; int slot; char tbuf[128]; // Find a slot, and also check to see if the object // is already on the list. slot = -1; for (idx = 0; idx < HS_MAX_ACTIVE_OBJECTS; idx++) { if (m_active_objlist[idx]) { if (m_active_objlist[idx]->GetDbref() == cObj->GetDbref()) return FALSE; } else if (slot == -1) slot = idx; } if (slot == -1) { // No more space sprintf(tbuf, "WARNING: Universe #%d at maximum object capacity.", m_objnum); hs_log(tbuf); return FALSE; } m_active_objlist[slot] = cObj; return TRUE; } // Allows any object to be generically added to the universe. // The function determines the type of object and then calls // a more specific adding function. It also adds the object // to the linked list of objects. BOOL CHSUniverse::AddObject(CHSObject *cObj) { int idx; int slot; char tbuf[128]; // Add it to the object list first. If we // don't have anymore room, then don't call // any specific object functions. Also make // sure the object isn't already in the list. // Determine the type of object, then call // the appropriate function. slot = -1; for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (!m_objlist[idx] && (slot == -1)) slot = idx; // Object already in the list? if (m_objlist[idx] && (m_objlist[idx]->GetDbref() == cObj->GetDbref())) return FALSE; } if (slot == -1) { // No space left sprintf(tbuf, "WARNING: Universe #%d at maximum object count.", m_objnum); hs_log(tbuf); return FALSE; } // Add the object m_objlist[slot] = cObj; m_nObjects++; // Add it to the active list? if (cObj->IsActive()) AddActiveObject(cObj); // If you have any specific adding functions for a // type of object, add it here. For ships and planets, // we have additional arrays for quick searching, thus // we implement that here. switch(cObj->GetType()) { case HST_SHIP: return (AddShip((CHSShip *)cObj)); case HST_PLANET: return (AddCelestial((CHSCelestial *)cObj)); default: return TRUE; // Generic object break; } } // Specifically removes a ship from the universe. void CHSUniverse::RemoveShip(CHSShip *cShip) { UINT idx; // Now just go down the list, find the ship, and yank it. for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (m_shiplist[idx]) { if (m_shiplist[idx]->GetDbref() == cShip->GetDbref()) { m_shiplist[idx] = NULL; m_nShips--; break; } } } } // Specifically removes a celestial from the universe. void CHSUniverse::RemoveCelestial(CHSCelestial *cCel) { UINT idx; // Run down the list of celestials, find this one, yank it. for (idx = 0; idx < HS_MAX_OBJECTS; idx++) { if (m_celestials[idx]) { if (m_celestials[idx]->GetDbref() == cCel->GetDbref()) { m_celestials[idx] = NULL; break; } } } } // Returns TRUE or FALSE depending on whether the universe // has no objects in it. BOOL CHSUniverse::IsEmpty(void) { if (m_nObjects <= 0) return TRUE; return FALSE; } // Return number of objects, perhaps for a specific type. UINT CHSUniverse::NumObjects(HS_TYPE type) { switch(type) { case HST_NOTYPE: return m_nObjects; case HST_SHIP: return m_nShips; case HST_PLANET: case HST_WORMHOLE: case HST_NEBULA: case HST_ASTEROID: case HST_BLACKHOLE: return m_nCelestials; default: return -1; } } // Returns the ship object at a given slot, which could be NULL. CHSShip *CHSUniverse::GetShip(UINT slot) { if ((slot < 0) || (slot >= HS_MAX_OBJECTS)) return NULL; return m_shiplist[slot]; } // Returns the celestial object at a given slot, which could be NULL. CHSCelestial *CHSUniverse::GetCelestial(UINT slot) { if ((slot < 0) || (slot >= HS_MAX_OBJECTS)) return NULL; return m_celestials[slot]; } // Returns the number of active objects, perhaps for a specific type. UINT CHSUniverse::NumActiveObjects(HS_TYPE type) { int idx; int num; num = 0; for (idx = 0; idx < HS_MAX_ACTIVE_OBJECTS; idx++) { if (m_active_objlist[idx]) { if (type == HST_NOTYPE) num++; else if (m_active_objlist[idx]->GetType() == type) num++; } } return num; } // Returns the object at a given slot, which could be NULL. CHSObject *CHSUniverse::GetUnivObject(UINT slot, HS_TYPE tType) { // Call a subfunction? switch(tType) { case HST_SHIP: return GetShip(slot); case HST_PLANET: case HST_WORMHOLE: case HST_NEBULA: case HST_BLACKHOLE: case HST_ASTEROID: return GetCelestial(slot); default: // Return any CHSObject if ((slot < 0) || (slot >= HS_MAX_OBJECTS)) return NULL; return m_objlist[slot]; } } // Returns the object at a given slot in the active array. CHSObject *CHSUniverse::GetActiveUnivObject(UINT slot) { if ((slot < 0) || (slot >= HS_MAX_OBJECTS)) return NULL; return m_active_objlist[slot]; } // Sends a message to every object within a given distance // from the supplied CHSObject. void CHSUniverse::SendMessage(char *strMsg, int iDist, CHSObject *cSource) { double sX, sY, sZ; // Source coords double tX, tY, tZ; // Target coords double dDistance; CHSObject *cObj; int idx; // If a CHSObject was supplied, get its coords. if (cSource) { sX = cSource->GetX(); sY = cSource->GetY(); sZ = cSource->GetZ(); } else sX = sY = sZ = 0; // Run through all active objects, checking distance for (idx = 0; idx < HS_MAX_ACTIVE_OBJECTS; idx++) { if (!m_active_objlist[idx]) continue; cObj = m_active_objlist[idx]; // Make sure it's not the source object if (cObj->GetDbref() == cSource->GetDbref()) continue; // Calculate distance between coords, if needed if (iDist > 0) { tX = cObj->GetX(); tY = cObj->GetY(); tZ = cObj->GetZ(); dDistance = Dist3D(sX, sY, sZ, tX, tY, tZ); if (dDistance > iDist) continue; } // At this point, the distance is ok. Give the // message cObj->HandleMessage(strMsg, MSG_GENERAL, (long *)cSource); } } // Sends a message to every ship that has the supplied // CHSObject on sensors with the given status. void CHSUniverse::SendContactMessage(char *strMsg, int status, CHSObject *cSource) { CHSObject *cObj; CHSShip *cShip; SENSOR_CONTACT *cContact; int idx; // Run through all active objects, checking distance for (idx = 0; idx < HS_MAX_ACTIVE_OBJECTS; idx++) { if (!m_active_objlist[idx]) continue; cObj = m_active_objlist[idx]; // Is it an object with sensors? if (cObj->GetType() != HST_SHIP) continue; cShip = (CHSShip *)cObj; // Grab the sensor contact for the source object // in the sensor array of the target object. cContact = cShip->GetSensorContact(cSource); if (cContact && (cContact->status == status)) cObj->HandleMessage(strMsg, MSG_GENERAL, (long *)cSource); } } // Allows an attribute with a given name to be set to // a specified value. BOOL CHSUniverse::SetAttributeValue(char *strName, char *strValue) { // Try to match the attribute name if (!strcasecmp(strName, "NAME")) { if (m_name) delete [] m_name; if (strValue && *strValue) { m_name = new char[strlen(strValue) + 1]; strcpy(m_name, strValue); } return TRUE; } else if (!strcasecmp(strName, "OBJNUM")) { m_objnum = strtodbref(strValue); return TRUE; } return FALSE; } // Tells the universe to save its information to the // specified file stream. void CHSUniverse::SaveToFile(FILE *fp) { if (!fp) return; // Write out our attrs fprintf(fp, "OBJNUM=%d\n", m_objnum); if (m_name) fprintf(fp, "NAME=%s\n", m_name); } src/hspace/hsuniverse.h 100664 767 767 4144 7141305141 13360 0 ustar mux mux #ifndef __HSUNIVERSE_INCLUDED__ #define __HSUNIVERSE_INCLUDED__ #include "hsobjects.h" #include "hscelestial.h" #define HS_MAX_OBJECTS 200 #define HS_MAX_ACTIVE_OBJECTS 50 #define HS_MAX_UNIVERSES 10 class CHSUniverse { public: CHSUniverse(void); ~CHSUniverse(void); char *GetName(void); UINT GetID(void); UINT NumObjects(HS_TYPE type = HST_NOTYPE); UINT NumActiveObjects(HS_TYPE type = HST_NOTYPE); void RemoveObject(CHSObject *); void RemoveActiveObject(CHSObject *); void SendMessage(char *, int, CHSObject *); void SendContactMessage(char *, int, CHSObject *); void SetID(int); void SetName(char *); void SaveToFile(FILE *); BOOL AddActiveObject(CHSObject *); BOOL AddObject(CHSObject *); BOOL IsEmpty(void); BOOL SetAttributeValue(char *, char *); // This function can't be named GetObject(), or it will // conflict with something stupid in Windows. CHSObject *GetUnivObject(UINT, HS_TYPE tType = HST_NOTYPE); CHSObject *GetActiveUnivObject(UINT); CHSObject *FindObject(dbref, HS_TYPE type = HST_NOTYPE); protected: // Member Functions void RemoveShip(CHSShip *); void RemoveCelestial(CHSCelestial *); BOOL AddCelestial(CHSCelestial *); BOOL AddShip(CHSShip *); CHSCelestial *FindCelestial(dbref); CHSCelestial *GetCelestial(UINT); CHSShip *FindShip(dbref); CHSShip *GetShip(UINT); // Attributes dbref m_objnum; char *m_name; UINT m_nCelestials; UINT m_nShips; UINT m_nObjects; // Storage arrays CHSObject **m_objlist; CHSObject **m_active_objlist; CHSShip **m_shiplist; CHSCelestial **m_celestials; }; class CHSUniverseArray { public: CHSUniverseArray(void); ~CHSUniverseArray(void); // Public Methods CHSUniverse *NewUniverse(void); CHSUniverse *GetUniverse(UINT); // Gets a universe in a slot CHSUniverse *FindUniverse(dbref); // Finds a universe by ID UINT NumUniverses(void); void SaveToFile(char *); void PrintInfo(int); BOOL AddUniverse(CHSUniverse *); BOOL DeleteUniverse(UINT); BOOL LoadFromFile(char *); protected: CHSUniverse **m_universes; UINT m_num_universes; }; extern CHSUniverseArray uaUniverses; #endif // __UNIVERSE_INCLUDED__ src/hspace/hsutils.cpp 100664 767 767 15507 7141305141 13240 0 ustar mux mux #include "hscopyright.h" #include "hstypes.h" #include "hsutils.h" #include <stdlib.h> #include <math.h> #include <time.h> #include <ctype.h> #include "hsexterns.h" #include <string.h> #ifdef PENNMUSH extern "C" { FILE *spacelog_fp; } #endif int hs_num_keys = -1; // Key/Value pairs we expect to find in the various // databases for HSpace. // // IF YOU ADD ANYTHING HERE, you need to add it in alphabetical // order. The HSFindKey() function uses a binary search algorithm. struct HSKEYVALUEPAIR hsdbkeypairs[] = { "BOARDING_CODE", HSK_BOARDING_CODE, "CARGOSIZE", HSK_CARGOSIZE, "CLASSID", HSK_CLASSID, "CONSOLE", HSK_CONSOLE, "DBVERSION", HSK_DBVERSION, "DESTROYED", HSK_DESTROYED, "DOCKED", HSK_DOCKED, "DROP CAPABLE", HSK_DROP_CAPABLE, "DROPPED", HSK_DROPPED, "HULL_POINTS", HSK_HULL_POINTS, "IDENT", HSK_IDENT, "LANDINGLOC", HSK_LANDINGLOC, "MAXFUEL", HSK_MAXFUEL, "MAXHULL", HSK_MAXHULL, "MISSILEBAY", HSK_MISSILEBAY, "NAME", HSK_NAME, "NUMCREWS", HSK_NUMCREWS, "OBJECTEND", HSK_OBJECTEND, "OBJECTTYPE", HSK_OBJECTTYPE, "OBJLOCATION", HSK_OBJLOCATION, "OBJNUM", HSK_OBJNUM, "PRIORITY", HSK_PRIORITY, "ROOM", HSK_ROOM, "SIZE", HSK_SIZE, "SYSTEMDEF", HSK_SYSTEMDEF, "SYSTEMEND", HSK_SYSTEMEND, "SYSTYPE", HSK_SYSTYPE, "UID", HSK_UID, "VISIBLE", HSK_VISIBLE, "X", HSK_X, "XYHEADING", HSK_XYHEADING, "Y", HSK_Y, "Z", HSK_Z, "ZHEADING", HSK_ZHEADING, NULL }; int load_int(FILE *fp) { char word[512]; if (!fgets(word, 512, fp)) return SPACE_ERR; else return atoi(word); } float load_float(FILE *fp) { char word[512]; if (!fgets(word, 512, fp)) return SPACE_ERR; else return (float)atof(word); } double load_double(FILE *fp) { char word[512]; if (!fgets(word, 512, fp)) return SPACE_ERR; else return atof(word); } const char *getstr(FILE *fp) { static char word[4096]; char *ptr; fgets(word, 4096, fp); // Strip newlines if ((ptr = strchr(word, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(word, '\r')) != NULL) *ptr = '\0'; return word; } void hs_log(char *str) { struct tm *ttm; time_t tt; tt = time(NULL); ttm = localtime(&tt); #ifdef PENNMUSH char timebuf[256]; char tbuf[512]; sprintf(timebuf, "%d%d/%d%d %d%d:%d%d:%d%d", (((ttm->tm_mon) + 1) / 10), (((ttm->tm_mon) + 1) % 10), (ttm->tm_mday / 10), (ttm->tm_mday % 10), (ttm->tm_hour / 10), (ttm->tm_hour % 10), (ttm->tm_min / 10), (ttm->tm_min % 10), (ttm->tm_sec / 10), (ttm->tm_sec % 10)); sprintf(tbuf, "%s: %s", timebuf, str); fprintf(spacelog_fp, "%s\n", tbuf); fflush(spacelog_fp); #endif #ifdef MUX Log.printf("%04d.%02d%02d:%02d%02d%02d HSpace: %s\n", ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, ttm->tm_hour, ttm->tm_min, ttm->tm_sec, str); Log.Flush(); #endif } /* * Pulls a delimited number of words out of a string at * a given location and for a given number of delimiters. */ void extract(char *string, char *into, int start, int num, char delim) { UINT uDelimsEncountered; char *dptr; char *sptr; uDelimsEncountered = 0; dptr = into; *dptr = '\0'; for (sptr = string; *sptr; sptr++) { if (*sptr == delim) { uDelimsEncountered++; if ((uDelimsEncountered - start) == num) { *dptr = '\0'; return; } else if (uDelimsEncountered > start) *dptr++ = delim; } else { if (uDelimsEncountered >= start) *dptr++ = *sptr; } } *dptr = '\0'; } // Takes a string and strips off the leading # sign, turning // the rest into an integer(dbref) int strtodbref(char *string) { char *ptr; ptr = string; if (*ptr == '#') ptr++; return atoi(ptr); } // Looks for a key based on the key string. Since the key // strings are sorted, we can use some intelligent searching here. HS_DBKEY HSFindKey(char *strKeyName) { int top, middle, bottom; int ival; // If hs_num_keys is -1, then we have to initialize it. if (hs_num_keys < 0) { for (ival = 0; hsdbkeypairs[ival].name; ival++) {}; hs_num_keys = ival; } bottom = 0; top = hs_num_keys; // Look for the key name while(bottom < top) { // Split the array in two middle = ((top - bottom) / 2) + bottom; // Check to see if the middle is the match ival = strcasecmp(hsdbkeypairs[middle].name, strKeyName); if (!ival) return (hsdbkeypairs[middle].key); // Not a match, so check to see where we go next. // Down or up in the array. if (ival > 0) { // Lower portion // Check to see if it's redundant if (top == middle) break; top = middle; } else { // Upper portion // Check to see if it's redundant if (bottom == middle) break; bottom = middle; } } return HSK_NOKEY; } // Returns the 3D distance between two sets of coordinates double Dist3D(double x1, double y1, double z1, double x2, double y2, double z2) { double dist; dist = ((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)) + ((z2 - z1) * (z2 - z1)); return sqrt(dist); } // Returns the Z angle between the given coordinates. Six points // are needed for this operation. int ZAngle(double fx, double fy, double fz, double sx, double sy, double sz) { char tbuf[8]; // Used to round the number if (fz == sz) // On the same XY plane return 0; else { // Objects are on different XY planes. // Are they at the same 2D location? If so, that's easy! if (sy == fy && sx == fx) { if (sz > fz) return 90; else return -90; } else { // They're not at the same 2D location. sprintf(tbuf, "%.0f", RADTODEG * atan((sz - fz) / sqrt(((sx - fx) * (sx - fx)) + ((sy - fy) * (sy - fy))))); return atoi(tbuf); } } } // Returns the XY angle between the given coordinates. Four points // are needed for this operation. int XYAngle(double fx, double fy, double sx, double sy) { char tbuf[8]; int ang; if (sx - fx == 0) { if (sy - fy == 0) return 0; else if (sy > fy) return 0; else return 180; } else if (sy - fy == 0) { if (sx > fx) return 90; else return 270; } else if (sx < fx) { sprintf(tbuf, "%.0f", 270 - RADTODEG * atan((sy - fy) / (sx - fx))); ang = atoi(tbuf); if (ang < 0) ang += 360; else if (ang > 359) ang -= 360; return ang; } else { sprintf(tbuf, "%.0f", 90 - RADTODEG * atan((sy - fy) / (sx - fx))); ang = atoi(tbuf); if (ang < 0) ang += 360; else if (ang > 359) ang -= 360; return ang; } } // Gives a standard format error message to a player. void hsStdError(int player, char *strMsg) { char *strNewMsg; strNewMsg = new char[strlen(strMsg) + 32]; sprintf(strNewMsg, "%s%s-%s %s", ANSI_HILITE, ANSI_GREEN, ANSI_NORMAL, strMsg); notify(player, strNewMsg); delete [] strNewMsg; } src/hspace/hsutils.h 100644 767 767 2340 7141305141 12652 0 ustar mux mux #ifndef __HSUTILS_INCLUDED__ #define __HSUTILS_INCLUDED__ #include <stdio.h> #define SPACE_ERR -534234 // Just some random number #define RADTODEG 57.296 // 180 / pi int load_int(FILE *); double load_double(FILE *); float load_float(FILE *); const char *getstr(FILE *); void hs_log(char *); void extract(char *, char *, int, int, char); int strtodbref(char *); double Dist3D(double, double, double, double, double, double); int XYAngle(double, double, double, double); int ZAngle(double, double, double, double, double, double); void hsStdError(int, char *); // Various keys found in our databases enum HS_DBKEY { HSK_NOKEY = 0, HSK_BOARDING_CODE, HSK_CARGOSIZE, HSK_CLASSID, HSK_CONSOLE, HSK_DBVERSION, HSK_DESTROYED, HSK_DOCKED, HSK_DROP_CAPABLE, HSK_DROPPED, HSK_HULL_POINTS, HSK_IDENT, HSK_LANDINGLOC, HSK_MAXHULL, HSK_MAXFUEL, HSK_MISSILEBAY, HSK_NAME, HSK_NUMCREWS, HSK_OBJECTEND, HSK_OBJECTTYPE, HSK_OBJLOCATION, HSK_OBJNUM, HSK_PRIORITY, HSK_ROOM, HSK_SIZE, HSK_SYSTEMDEF, HSK_SYSTEMEND, HSK_SYSTYPE, HSK_UID, HSK_VISIBLE, HSK_X, HSK_XYHEADING, HSK_Y, HSK_Z, HSK_ZHEADING }; HS_DBKEY HSFindKey(char *); // A key/value pair structure struct HSKEYVALUEPAIR { char *name; HS_DBKEY key; }; #endif src/hspace/hsweapon.cpp 100644 767 767 67374 7141305141 13400 0 ustar mux mux #include "hscopyright.h" #include "hsweapon.h" #include "hsobjects.h" #include "hsinterface.h" #include "hspace.h" #include "hsexterns.h" #include <math.h> #ifdef I_STDLIB #include <stdlib.h> #endif #ifdef I_STRING #include <string.h> #else #include <strings.h> #endif #include "hsutils.h" #include "hsmissile.h" CHSWeaponDBArray waWeapons; // One instance of this .. right here. CHSDBWeapon::CHSDBWeapon(void) { } // Returns the request attribute value, or NULL if the attribute // name is not valid. char *CHSDBWeapon::GetAttributeValue(char *strName) { static char rval[64]; *rval = '\0'; if (!strcasecmp(strName, "NAME")) return m_name; else if (!strcasecmp(strName, "TYPE")) { sprintf(rval, "%d", m_type); } else return NULL; return rval; } // Attempts to set the value of the given attribute. If successful, TRUE // is returned, else FALSE. BOOL CHSDBWeapon::SetAttributeValue(char *strName, char *strValue) { // Try to match the name if (!strcasecmp(strName, "NAME")) { strncpy(m_name, strValue, HS_WEAPON_NAME_LEN); m_name[HS_WEAPON_NAME_LEN-1] = '\0'; return TRUE; } return FALSE; } CHSDBLaser::CHSDBLaser(void) { m_regen_time = 1; m_range = 1; m_strength = 1; m_accuracy = 1; m_powerusage = 1; } // Returns the request attribute value, or NULL if the attribute // name is not valid. char *CHSDBLaser::GetAttributeValue(char *strName) { static char rval[64]; *rval = '\0'; if (!strcasecmp(strName, "REGEN TIME")) { sprintf(rval, "%d", m_regen_time); } else if (!strcasecmp(strName, "RANGE")) { sprintf(rval, "%d", m_range); } else if (!strcasecmp(strName, "STRENGTH")) { sprintf(rval, "%d", m_strength); } else if (!strcasecmp(strName, "ACCURACY")) { sprintf(rval, "%d", m_accuracy); } else if (!strcasecmp(strName, "POWER")) { sprintf(rval, "%d", m_powerusage); } else return CHSDBWeapon::GetAttributeValue(strName); return rval; } // Attempts to set the value of the given attribute. If successful, TRUE // is returned, else FALSE. BOOL CHSDBLaser::SetAttributeValue(char *strName, char *strValue) { int iVal; // Try to match the name if (!strcasecmp(strName, "REGEN TIME")) { iVal = atoi(strValue); if (iVal < 0) iVal = 0; m_regen_time = iVal; return TRUE; } else if (!strcasecmp(strName, "RANGE")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_range = iVal; return TRUE; } else if (!strcasecmp(strName, "STRENGTH")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_strength = iVal; return TRUE; } else if (!strcasecmp(strName, "ACCURACY")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_accuracy = iVal; return TRUE; } else if (!strcasecmp(strName, "POWER")) { iVal = atoi(strValue); if (iVal < 0) iVal = 0; m_powerusage = iVal; return TRUE; } return CHSDBWeapon::SetAttributeValue(strName, strValue); } CHSDBMissile::CHSDBMissile(void) { m_reload_time = 1; m_range = 1; m_strength = 1; m_turnrate = 0; m_speed = 1; } // Returns the request attribute value, or NULL if the attribute // name is not valid. char *CHSDBMissile::GetAttributeValue(char *strName) { static char rval[64]; *rval = '\0'; if (!strcasecmp(strName, "RELOAD TIME")) { sprintf(rval, "%d", m_reload_time); } else if (!strcasecmp(strName, "RANGE")) { sprintf(rval, "%d", m_range); } else if (!strcasecmp(strName, "STRENGTH")) { sprintf(rval, "%d", m_strength); } else if (!strcasecmp(strName, "TURN RATE")) { sprintf(rval, "%d", m_turnrate); } else if (!strcasecmp(strName, "SPEED")) { sprintf(rval, "%d", m_speed); } else return CHSDBWeapon::GetAttributeValue(strName); return rval; } // Attempts to set the value of the given attribute. If successful, TRUE // is returned, else FALSE. BOOL CHSDBMissile::SetAttributeValue(char *strName, char *strValue) { int iVal; // Try to match the name if (!strcasecmp(strName, "RELOAD TIME")) { iVal = atoi(strValue); if (iVal < 0) iVal = 0; m_reload_time = iVal; return TRUE; } else if (!strcasecmp(strName, "RANGE")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_range = iVal; return TRUE; } else if (!strcasecmp(strName, "STRENGTH")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_strength = iVal; return TRUE; } else if (!strcasecmp(strName, "TURN RATE")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_turnrate = iVal; return TRUE; } else if (!strcasecmp(strName, "SPEED")) { iVal = atoi(strValue); if (iVal < 1) iVal = 1; m_speed = iVal; return TRUE; } return CHSDBWeapon::SetAttributeValue(strName, strValue); } CHSWeaponDBArray::CHSWeaponDBArray(void) { UINT idx; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) m_weapons[idx] = NULL; m_num_weapons = 0; } // Returns the HSW type of the weapon in a given slot UINT CHSWeaponDBArray::GetType(int slot) { if (!GoodWeapon(slot)) return HSW_NOTYPE; return m_weapons[slot]->m_type; } // Prints info to a given player for all of the weapons // in the database. void CHSWeaponDBArray::PrintInfo(int player) { int idx; char strType[32]; notify(player, "[ID] Weapon Name Type"); for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (!m_weapons[idx]) continue; switch(m_weapons[idx]->m_type) { case HSW_LASER: strcpy(strType, "Laser"); break; case HSW_MISSILE: strcpy(strType, "Missile"); break; default: strcpy(strType, "Unknown"); break; } notify(player, tprintf("[%2d] %-32s%s", idx, m_weapons[idx]->m_name, strType)); } } // Gets the CSHDBWeapon structure from the WeaponDBArray, // but first verifies that it is actually of the appropriate type. CHSDBWeapon *CHSWeaponDBArray::GetWeapon(int slot, UINT type) { if (!GoodWeapon(slot)) return NULL; if ((type != HSW_NOTYPE) && (m_weapons[slot]->m_type != type)) return NULL; return (m_weapons[slot]); } // Load the weapons database file, creating all of the weapons from it. BOOL CHSWeaponDBArray::LoadFromFile(char *lpstrPath) { FILE *fp; char tbuf[LBUF_SIZE]; UINT idx; char *ptr; hs_log(tprintf("LOADING: %s", lpstrPath)); fp = fopen(lpstrPath, "r"); if (!fp) { sprintf(tbuf, "ERROR: Couldn't open %s for reading.", lpstrPath); hs_log(tbuf); return FALSE; } // Ok, start loading lines from the file. idx = 0; while (fgets(tbuf, LBUF_SIZE-1, fp)) { // Chop the newline if ((ptr = strchr(tbuf, '\n')) != NULL) *ptr = '\0'; if ((ptr = strchr(tbuf, '\r')) != NULL) *ptr = '\0'; // Check for the end of the file. if (!strcasecmp(tbuf, "*END*")) break; // Pass the string to the CreateWeapon() function to create // the weapon for us. if (!(m_weapons[idx] = CreateWeapon(tbuf))) { sprintf(tbuf, "ERROR: Invalid weapon specification at line %d.\n", idx); hs_log(tbuf); } idx++; } fclose(fp); m_weapons[idx] = NULL; m_num_weapons = idx; sprintf(tbuf, "LOADING: %s - %d weapons loaded (done)", lpstrPath, m_num_weapons); hs_log(tbuf); return TRUE; } void CHSWeaponDBArray::SaveToFile(char *lpstrPath) { UINT idx; FILE *fp; char tbuf[512]; fp = fopen(lpstrPath, "w"); if (!fp) { sprintf(tbuf, "ERROR: Unable to write weapons to %s.", lpstrPath); hs_log(tbuf); return; } for (idx = 0; idx < m_num_weapons; idx++) { if (m_weapons[idx]->m_type == HSW_LASER) { WriteLaser((CHSDBLaser *) m_weapons[idx], fp); } else if (m_weapons[idx]->m_type == HSW_MISSILE) { WriteMissile((CHSDBMissile *) m_weapons[idx], fp); } } fprintf(fp, "*END*\n"); fclose(fp); } void CHSWeaponDBArray::WriteLaser(CHSDBLaser *weapon, FILE *fp) { fprintf(fp, "0\"%s\" %d %d %d %d %d\n", weapon->m_name, weapon->m_strength, weapon->m_regen_time, weapon->m_range, weapon->m_accuracy, weapon->m_powerusage); } void CHSWeaponDBArray::WriteMissile(CHSDBMissile *weapon, FILE *fp) { fprintf(fp, "1\"%s\" %d %d %d %d %d\n", weapon->m_name, weapon->m_strength, weapon->m_reload_time, weapon->m_range, weapon->m_turnrate, weapon->m_speed); } // Creates a new weapon, based on the specified type. If the // type is invalid, or the weapon couldn't be created, NULL is // returned. CHSDBWeapon *CHSWeaponDBArray::NewWeapon(UINT type) { // Do we have any space left in the array? int idx; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (!m_weapons[idx]) break; } if (idx == HS_MAX_WEAPONS) { hs_log("WARNING: Maximum number of weapons reached."); return NULL; } // Determine type, allocate the new weapon. switch(type) { case HSW_LASER: m_weapons[idx] = new CHSDBLaser; break; case HSW_MISSILE: m_weapons[idx] = new CHSDBMissile; break; return NULL; } m_num_weapons++; m_weapons[idx]->m_type = type; return m_weapons[idx]; } // // CreateWeapon() simply takes a line from the weapons database and pulls out // the information for the different weapons. It then determines the type // of weapon that should be created from the loaded string and calls the // specific function for that type of weapon, passing to it the values from // the database. // CHSDBWeapon *CHSWeaponDBArray::CreateWeapon(char *items) { int iValArray[30]; // Gets loaded with field values char tbuf[32]; // Temporary string storage char strName[256]; // Gets loaded with the weapon name. UINT idx; UINT ok; UINT j; char *ptr; UINT type; ptr = items; // Grab the type of weapon, which is the first char. type = *ptr - '0'; ptr++; // Next, we should have the name surrounded by quotes. if (*ptr != '"') { return NULL; } ptr++; idx = 0; while (*ptr && ((ptr - items) < HS_WEAPON_NAME_LEN) && (*ptr != '"')) { strName[idx++] = *ptr++; } strName[idx] = NULL; // Got the weapon name! if (!*ptr) { return NULL; } // Increment past the quotes. if (*ptr == '"') ptr++; else { while (*ptr != '"') ptr++; ptr++; } // We're finished with the name here. // Skip a white space ptr++; /* * Now start pulling out numbers and putting them in the array */ ok = 1; j = 0; while (ok) { // Extract the value extract(ptr, tbuf, j, 1, ' '); // Check to see if we've reached the end of the string. if (!*tbuf) break; // Shove the val into the array iValArray[j] = atoi(tbuf); j++; } iValArray[j] = -1; // Determine the type of weapon, and call the appropriate handler // for creating that weapon type. Pass the name and the values extracted // from the database string. if (type == HSW_LASER) { return CreateLaser(strName, iValArray); } else if (type == HSW_MISSILE) { return CreateMissile(strName, iValArray); } else return NULL; } UINT CHSWeaponDBArray::NumWeapons(void) { return m_num_weapons; } // Specifically creates a standard laser, loaded from the weapons // database. This handler really just has to allocate the memory, // copy the name into the new weapon, and copy all of the values. CHSDBWeapon *CHSWeaponDBArray::CreateLaser(char *strName, int *iVals) { CHSDBLaser *weapon; int idx; // Check the number of values passed. We should have 5; for (idx = 0; iVals[idx] != -1; idx++){}; if (idx != 5) return NULL; // Allocate space weapon = new CHSDBLaser; // Now just initialize and set the appropriate variables weapon->m_type = HSW_LASER; strcpy(weapon->m_name, strName); weapon->m_strength = iVals[0]; weapon->m_regen_time = iVals[1]; weapon->m_range = iVals[2]; weapon->m_accuracy = iVals[3]; weapon->m_powerusage = iVals[4]; return (CHSDBWeapon *)weapon; } // Called upon to create a missile that was loaded from the weapons // database. CHSDBWeapon *CHSWeaponDBArray::CreateMissile(char *strName, int *iVals) { UINT idx; CHSDBMissile *weapon; // Check for the number of values passed in. Should have 5. for (idx = 0; iVals[idx] != -1; idx++){}; if (idx != 5) return NULL; // Allocate space weapon = new CHSDBMissile; // Now just initialize and set the appropriate variables weapon->m_type = HSW_MISSILE; strcpy(weapon->m_name, strName); weapon->m_strength = iVals[0]; weapon->m_reload_time = iVals[1]; weapon->m_range = iVals[2]; weapon->m_turnrate = iVals[3]; weapon->m_speed = iVals[4]; return (CHSDBWeapon *)weapon; } BOOL CHSWeaponDBArray::GoodWeapon(int type) { // Simply check to see if the weapon type is within bounds if (type >= 0 && type < m_num_weapons) return TRUE; return FALSE; } // // CHSWeaponArray stuff // // CHSWeaponArray::CHSWeaponArray(void) { m_nWeapons = 0; m_missile_bay = NULL; // Initialize the array int idx; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) m_weapons[idx] = NULL; } // Attempts to remove the weapon in the specified slot. BOOL CHSWeaponArray::DeleteWeapon(int slot) { int idx; if ((slot < 0) || (slot >= HS_MAX_WEAPONS)) return FALSE; if (m_weapons[slot] = NULL) return TRUE; // Delete the weapon in the slot and move all other // weapons above it down one slot. delete m_weapons[slot]; for (idx = slot; idx < (HS_MAX_WEAPONS-1); idx++) m_weapons[idx] = m_weapons[idx + 1]; m_weapons[idx] = NULL; m_nWeapons--; return TRUE; } // Returns the weapon in a given slot. CHSWeapon *CHSWeaponArray::GetWeapon(int slot) { if ((slot < 0) || (slot >= HS_MAX_WEAPONS)) return NULL; return m_weapons[slot]; } // Takes a missile bay object and sets that bay as the // source for all missile weapons in the array. void CHSWeaponArray::SetMissileBay(CHSMissileBay *cBay) { int idx; CHSMTube *mTube; // Run through the array, looking for missiles. for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (!m_weapons[idx]) continue; if (m_weapons[idx]->GetType() == HSW_MISSILE) { mTube = (CHSMTube *)m_weapons[idx]; mTube->SetMissileBay(cBay); } } m_missile_bay = cBay; } // Returns the total power usage for all weapons in the array. UINT CHSWeaponArray::GetTotalPower(void) { UINT uPower; int idx; uPower = 0; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (m_weapons[idx]) uPower += m_weapons[idx]->GetPowerUsage(); } return uPower; } void CHSWeaponArray::ClearArray(void) { UINT idx; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (m_weapons[idx]) delete m_weapons[idx]; } } // The NewWeapon() function makes it easy to add a new weapon to // the console's weapons array. Simply pass in the class of weapon, // which must be one of the weapons loaded into the WeaponDBArray object, // and the new weapon appears in the console's weapon array. Presto magic! BOOL CHSWeaponArray::NewWeapon(int wclass) { // Check to see if it's a valid weapon in the global database if (!waWeapons.GoodWeapon(wclass)) return FALSE; // Just check the type and call the appropriate handler switch(waWeapons.GetType(wclass)) { case HSW_LASER: NewLaser(wclass); m_nWeapons++; break; case HSW_MISSILE: NewMTube(wclass); CHSMTube *mtube; mtube = (CHSMTube *)m_weapons[m_nWeapons]; mtube->SetMissileBay(m_missile_bay); m_nWeapons++; break; } return TRUE; } // Adds a new laser to the weapons array on a console. This function // gets called by NewWeapon, which is the generic handler. void CHSWeaponArray::NewLaser(int wclass) { CHSLaser *newLas; // Allocate a new object newLas = new CHSLaser; // Add it to the array m_weapons[m_nWeapons] = newLas; // Initialize some variables newLas->m_class = wclass; // Set the parent m_weapons[m_nWeapons]->SetParent( waWeapons.GetWeapon(wclass, HSW_LASER)); } // Adds a new missile tube to the weapons array on a console. This function // gets called by NewWeapon, which is the generic handler. void CHSWeaponArray::NewMTube(int wclass) { m_weapons[m_nWeapons] = new CHSMTube; m_weapons[m_nWeapons]->m_class = wclass; // Set the parent, which is the missile type // this tube is configured for. m_weapons[m_nWeapons]->SetParent( waWeapons.GetWeapon(wclass, HSW_MISSILE)); } // Runs through the list of weapons, searching out the maximum // weapon range. UINT CHSWeaponArray::GetMaxRange(void) { UINT range; UINT tRange; // Temp holder int idx; range = 0; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (m_weapons[idx]) { tRange = m_weapons[idx]->GetRange(); if (tRange > range) range = tRange; } } return range; } // Handles cyclic stuff for the weapons in the array void CHSWeaponArray::DoCycle(void) { // Run through our weapons, telling them to cycle. int idx; for (idx = 0; idx < HS_MAX_WEAPONS; idx++) { if (m_weapons[idx]) m_weapons[idx]->DoCycle(); } } // // CHSWeapon stuff // CHSWeapon::CHSWeapon(void) { m_parent = NULL; m_change = STAT_NOCHANGE; } UINT CHSWeapon::GetPowerUsage(void) { // Generic weapons require no power return 0; } // Indicates whether the object can attack the specified // type of CHSObject. Override this in your derived weapon // class to have your weapon respond to different types of // objects. BOOL CHSWeapon::CanAttackObject(CHSObject *cObj) { // Generic weapons can't attack anything. return FALSE; } // Returns the recent status change of the weapon. int CHSWeapon::GetStatusChange(void) { return m_change; } // Sets the status of the weapon by an integer identifier. // It's up to the weapon to determine what it should do with // that integer. void CHSWeapon::SetStatus(int stat) { // Generic weapons don't handle this. } // The generic weapon has no cyclic stuff void CHSWeapon::DoCycle(void) { } UINT CHSWeapon::GetRange(void) { // Generic weapons have no range return 0; } BOOL CHSWeapon::IsReady(void) { return TRUE; } // Returns the type of the weapon, which is taken from // the parent. int CHSWeapon::GetType(void) { if (!m_parent) return HSW_NOTYPE; return m_parent->m_type; } // Sets the parent of the weapon to a CHSDBWeapon object void CHSWeapon::SetParent(CHSDBWeapon *parent) { m_parent = parent; } // Override this function in your derived weapon class // to return a custom name. char *CHSWeapon::GetName(void) { if (!m_parent) return "No Name"; // Return the name from the parent return m_parent->m_name; } // Indicates whether the weapon needs a target to be // fired. BOOL CHSWeapon::RequiresLock(void) { return FALSE; } // Override this function in your derived weapon class // to return custom attribute information about the weapon, // such as strength, regeneration time, etc. char *CHSWeapon::GetAttrInfo(void) { // Generic weapons have no attributes return "No information available."; } // Override this function in your derived weapon class // to return custom status info such as time left to // recharge, etc. char *CHSWeapon::GetStatus(void) { // Generic weapons have unknown status return "Unknown"; } // Returns an integer that is meaningful only to the weapon. // The status is saved during shutdown and passed back to // the weapon on reboot for handling. int CHSWeapon::GetStatusInt(void) { return 0; } // Indicates whether the weapon is configurable or not. BOOL CHSWeapon::Configurable(void) { // Generic weapons are not configurable return FALSE; } BOOL CHSWeapon::Configure(int type) { // Generic weapons cannot be configured. return FALSE; } BOOL CHSWeapon::Loadable(void) { // Generic weapons are not loadable return FALSE; } BOOL CHSWeapon::Reload(void) { // Generic weapons are not loadable return FALSE; } BOOL CHSWeapon::Unload(void) { // Generic weapons can't unload return FALSE; } // Returns the number of seconds until reload, or 0 if // not reloading. int CHSWeapon::Reloading(void) { // Generic weapons are never reloading return 0; } // Use this routine to instruct the weapon to attack a given // object. Supply the dbref of the console the weapon should // send messages back to as well. void CHSWeapon::AttackObject(CHSObject *cSource, CHSObject *cTarget, CHSConsole *cConsole, int iSysType) { dbref dbUser; dbUser = hsInterface.ConsoleUser(cConsole->m_objnum); if (dbUser != NOTHING) hsStdError(dbUser, "I don't know how to attack. I'm just a plain old weapon."); } // // CHSLaser stuff // CHSLaser::CHSLaser(void) { m_regenerating = FALSE; } // Cyclic stuff for lasers void CHSLaser::DoCycle(void) { m_change = STAT_NOCHANGE; if (m_regenerating) Regenerate(); } // Attacks a target object. void CHSLaser::AttackObject(CHSObject *cSource, CHSObject *cTarget, CHSConsole *cConsole, int iSysType) { dbref dbUser; int iAttackRoll; int iDefendRoll; double sX, sY, sZ; // Source object coords double tX, tY, tZ; // Target object coords; // Grab the user of the console. dbUser = hsInterface.ConsoleUser(cConsole->m_objnum); // Can we attack that object? if (!CanAttackObject(cTarget)) { if (dbUser != NOTHING) hsStdError(dbUser, "You cannot attack that target with that weapon."); } // Calculate distance to object sX = cSource->GetX(); sY = cSource->GetY(); sZ = cSource->GetZ(); tX = cTarget->GetX(); tY = cTarget->GetY(); tZ = cTarget->GetZ(); double dDistance; dDistance = Dist3D(sX, sY, sZ, tX, tY, tZ) + .00001; // Size of a target ship matters relative to distance. // The closer a target gets to the ship, the larger // it effectively is. That is to say it takes up more // of the view angle. When the target is right next // to the ship, in front of the gun, it is essentially // the broad side of a barn, which everyone can hit. // Thus, to handle this we'll calculate the size of // the target and the viewing angle it takes up. double dSize; // Size of the side of the target double dAngle; // Amount of viewing angle taken up by size dSize = cTarget->GetSize(); dSize = (.7 * dSize) * (.7 * dSize); // Halve the size, and divide by distance. This // gives us the tangent of the angle taken up by // the target. dSize = (dSize * .5) / dDistance; // Take the inverse tangent to get angle. dAngle = atan(dSize); // Double the angle because we used half of the size // to get the angle of a right triangle. dAngle *= 2; // We now have the viewing angle consumed by the // target. There's a maximum possible value of 180, // so divide by that to determine how much of the viewing // angle is taken up by the target. dSize = dAngle * .005555; // Subtract from 1 to get maximum values of 1 when the // angle is small. dSize = 1 - dSize; // Now multiply by 6 to get relative difficulty of hitting // target. int iTemp = 6 * dSize; iDefendRoll = (int) RandomLong(iTemp, iTemp + 6); iTemp = GetAccuracy(); iAttackRoll = (int) RandomLong(iTemp, iTemp + 6); // Simulate difficulty when a target is moving. // If the target is moving toward or away from the // attacker, it's not very difficult. Thus, we // calculate the change in angle for the target // during one cycle. The maximum change is 180 // degrees. CHSVector tVec; CHSVector aVec; tVec = cTarget->GetMotionVector(); aVec = cSource->GetMotionVector(); // Calculate vector to target now. double dx, dy, dz; dx = tX - sX; dy = tY - sY; dz = tZ - sZ; // Make a unit vector dx /= dDistance; dy /= dDistance; dz /= dDistance; CHSVector nowVec(dx, dy, dz); // Now calculate coordinate for source and target // in one cycle. double sX2, sY2, sZ2; double tX2, tY2, tZ2; double aSpeed, tSpeed; // Grab both object speeds, and bring them down // to per-second levels. aSpeed = cSource->GetSpeed() * .0002778; tSpeed = cTarget->GetSpeed() * .0002778; // Calculate coordinates for next cycle. sX2 = sX + (aVec.i() * aSpeed); sY2 = sY + (aVec.j() * aSpeed); sZ2 = sZ + (aVec.k() * aSpeed); tX2 = tX + (tVec.i() * tSpeed); tY2 = tY + (tVec.j() * tSpeed); tZ2 = tZ + (tVec.k() * tSpeed); // Calculate vector to target after next cycle dx = tX2 - sX2; dy = tY2 - sY2; dz = tZ2 - sZ2; // Divide by distance to make a unit vector double dDistance2; dDistance2 = Dist3D(sX2, sY2, sZ2, tX2, tY2, tZ2); dx /= dDistance2; dy /= dDistance2; dz /= dDistance2; CHSVector nextVec(dx, dy, dz); // Calculate the dot product between the previous // and the next cycle vectors. double dp; dp = nowVec.DotProduct(nextVec); // Calculate the angle change. This is in radians. dAngle = acos(dp); // Now divide angle change by 2pi to get change in angle // from 0 to 1, where 1 is a huge change in angle and, // therefore, high difficulty. dAngle *= .15915; // Add up to 6 points of defense for "evasion" by angle // change. iDefendRoll += (int) (6 * dAngle); // If distance is farther than our range, the shot always // misses. double range; range = GetRange(); char tbuf[256]; if (dDistance >= range) { if (dbUser != NOTHING) hsStdError( dbUser, "Your shot dissipates short of its target."); strcpy(tbuf, "An incoming energy shot has missed us."); cTarget->HandleMessage(tbuf, MSG_COMBAT, (long *)cSource); } else if (iAttackRoll > iDefendRoll) { // The weapon hits! // Determine strength based on base weapon // strength and range to target. int strength; strength = GetStrength(); if (dDistance > (range * .333)) { strength = (int)(strength * (.333 + (1 - (dDistance / (range + .0001))))); } // If iSysType is not HSS_NOTYPE, then do a roll // against the accuracy of the weapon to see if // the system gets hit. if (iSysType != HSS_NOTYPE) { UINT ARoll, SRoll; ARoll = (int) RandomLong(0, GetAccuracy()); SRoll = (int) RandomLong(0, 10); if (SRoll > ARoll) iSysType = HSS_NOTYPE; // Didn't succeed } // Tell the target to take damage cTarget->HandleDamage(cSource, this, strength, cConsole, iSysType); } else { // The weapon misses. :( if (dbUser != NOTHING) hsStdError(dbUser, "Your shot skims past your target and out into space."); strcpy(tbuf, "An incoming energy shot has missed us."); cTarget->HandleMessage(tbuf, MSG_COMBAT, (long *)cSource); } Regenerate(); } // Lasers require a target lock BOOL CHSLaser::RequiresLock(void) { return TRUE; } // Handles the status integer sent to the weapon from // some calling functions. void CHSLaser::SetStatus(int stat) { // Any integer indicates a reloading // status. if (stat > 0) { m_regenerating = TRUE; m_time_to_regen = stat; } } // Returns attribute information in a string. char *CHSLaser::GetAttrInfo(void) { static char rval[128]; sprintf(rval, "R: %-5d S: %-3d Rt: %d", GetRange(), GetStrength(), GetRegenTime()); return rval; } BOOL CHSLaser::IsReady(void) { if (!m_regenerating) return TRUE; return FALSE; } void CHSLaser::Regenerate(void) { // Check to see if we're regenerating. // If not, then begin it. if (!m_regenerating) { m_regenerating = TRUE; m_time_to_regen = GetRegenTime(); } else { m_time_to_regen--; if (m_time_to_regen <= 0) { m_change = STAT_READY; m_regenerating = FALSE; } } } // Indicates whether the laser can attack the given type // of space object. BOOL CHSLaser::CanAttackObject(CHSObject *cObj) { // Only attack ships and missiles if (cObj->GetType() == HST_SHIP || cObj->GetType() == HST_MISSILE) { return TRUE; } return FALSE; } // Returns an integer representing the status of the laser. // This integer is meaningful only to the laser code. int CHSLaser::GetStatusInt(void) { // Regenerating? if (m_regenerating) return m_time_to_regen; return 0; // Not regenerating } // Returns the status of the laser char *CHSLaser::GetStatus(void) { static char tbuf[32]; if (m_regenerating) { sprintf(tbuf, "(%d) Charging", m_time_to_regen); return tbuf; } else return "Ready"; } UINT CHSLaser::GetRegenTime(void) { CHSDBLaser *dbLas; if (!m_parent) return 0; // Return the regen time dbLas = (CHSDBLaser *)m_parent; return dbLas->m_regen_time; } UINT CHSLaser::GetRange(void) { CHSDBLaser *dbLas; if (!m_parent) return 0; // Return the range dbLas = (CHSDBLaser *)m_parent; return dbLas->m_range; } UINT CHSLaser::GetStrength(void) { CHSDBLaser *dbLas; if (!m_parent) return 0; // Return the strength dbLas = (CHSDBLaser *)m_parent; return dbLas->m_strength; } UINT CHSLaser::GetPowerUsage(void) { CHSDBLaser *dbLas; // Return the power usage dbLas = (CHSDBLaser *)m_parent; return dbLas->m_powerusage; } UINT CHSLaser::GetAccuracy(void) { CHSDBLaser *dbLas; if (!m_parent) return 0; // Return the accuracy dbLas = (CHSDBLaser *)m_parent; return dbLas->m_accuracy; } src/hspace/hsweapon.h 100644 767 767 12724 7141305141 13032 0 ustar mux mux #ifndef __HSWEAPON_INCLUDED__ #define __HSWEAPON_INCLUDED__ #include <stdio.h> #include "hstypes.h" // // To implement a new type of weapon: // // Derive a weapon from the generic CHSDBWeapon. These are stored // in the global CHSWeaponDBArray and contain the information loaded // from the weapon database. // // Modify the CHSWeaponDBArray to implement a Create.. function // to handle the creation of your weapon. Use CreateLaser() or // CreateMissile() as examples. // // Derive a console weapon class from CHSWeapon, which is the // weapon object that gets added to a console. This is different // from CHSDBWeapon because it has a more diverse interface, whereas // CHSDBWeapon simply contains database information for the weapon. // Administrators can add multiple CHSWeapon's to consoles. // // Overload the necessary functions to make the weapon work as // you want. #define HS_MAX_WEAPONS 50 #define HS_WEAPON_NAME_LEN 32 #define HSW_NOTYPE 999 #define HSW_LASER 0 #define HSW_MISSILE 1 enum WEAPSTAT_CHANGE { STAT_NOCHANGE = 0, STAT_READY }; class CHSConsole; // A generic weapon in the weapons database. From this, we'll // derive many other types of weapons. class CHSDBWeapon { public: CHSDBWeapon(void); // Methods virtual char *GetAttributeValue(char *); virtual BOOL SetAttributeValue(char *, char *); UINT m_type; char m_name[HS_WEAPON_NAME_LEN]; }; // A derived weapon type: LASER class CHSDBLaser : public CHSDBWeapon { public: CHSDBLaser(void); char *GetAttributeValue(char *); BOOL SetAttributeValue(char *, char *); UINT m_regen_time; UINT m_range; UINT m_strength; UINT m_accuracy; UINT m_powerusage; }; class CHSDBMissile : public CHSDBWeapon { public: CHSDBMissile(void); char *GetAttributeValue(char *); BOOL SetAttributeValue(char *, char *); UINT m_reload_time; UINT m_range; UINT m_strength; UINT m_turnrate; UINT m_speed; }; // A missile storage slot in the missile bay typedef struct { UINT m_maximum; UINT m_class; UINT m_remaining; }HSMISSILESTORE; class CHSWeaponDBArray // Not to be confused with CHSWeaponArray { public: CHSWeaponDBArray(void); void SaveToFile(char *); void WriteLaser(CHSDBLaser *, FILE *); void WriteMissile(CHSDBMissile *, FILE *); void PrintInfo(int); BOOL LoadFromFile(char *); BOOL GoodWeapon(int); // Weapon exists or not UINT NumWeapons(void); UINT GetType(int); CHSDBWeapon *GetWeapon(int, UINT); CHSDBWeapon *NewWeapon(UINT); protected: UINT m_num_weapons; CHSDBWeapon *m_weapons[HS_MAX_WEAPONS]; CHSDBWeapon *CreateWeapon(char *); CHSDBWeapon *CreateLaser(char *, int *); CHSDBWeapon *CreateMissile(char *, int *); }; class CHSObject; // Fills a slot in the CHSWeaponArray. Other weapons // are derived from this. class CHSWeapon { public: CHSWeapon(void); // Overridable functions. virtual UINT GetPowerUsage(void); virtual UINT GetRange(void); virtual char *GetName(void); virtual char *GetAttrInfo(void); virtual char *GetStatus(void); virtual void SetParent(CHSDBWeapon *); virtual void DoCycle(void); virtual void SetStatus(int); virtual void AttackObject(CHSObject *, CHSObject *, CHSConsole *, int); virtual BOOL RequiresLock(void); virtual BOOL Configurable(void); virtual BOOL Configure(int); virtual BOOL Loadable(void); virtual BOOL Reload(void); virtual BOOL Unload(void); virtual BOOL CanAttackObject(CHSObject *); virtual BOOL IsReady(void); virtual int Reloading(void); virtual int GetStatusInt(void); virtual int GetStatusChange(void); int GetType(void); // Attributes UINT m_class; protected: WEAPSTAT_CHANGE m_change; CHSDBWeapon *m_parent; // Parent to retrieve values from. }; class CHSLaser : public CHSWeapon { public: CHSLaser(void); // Methods UINT GetRegenTime(void); UINT GetRange(void); UINT GetStrength(void); UINT GetAccuracy(void); UINT GetPowerUsage(void); BOOL CanAttackObject(CHSObject *cObj); BOOL IsReady(void); BOOL RequiresLock(void); void AttackObject(CHSObject *, CHSObject *, CHSConsole *, int); void Regenerate(void); void DoCycle(void); void SetStatus(int); char *GetStatus(void); char *GetAttrInfo(void); int GetStatusInt(void); protected: // Attributes UINT m_time_to_regen; BOOL m_regenerating; }; #define HS_MAX_MISSILES 15 // Maximum number of missile types in a bay // Can be used on an object to store/retrieve missles. class CHSMissileBay { public: CHSMissileBay(void); ~CHSMissileBay(void); BOOL GetMissile(int, int amt=1); // Pulls a new missile from storage BOOL SetRemaining(int, int); // Sets # of missiles remaining UINT GetMaxMissiles(int); UINT GetMissilesLeft(int); HSMISSILESTORE *GetStorage(int); void SaveToFile(FILE *); void LoadFromFile(FILE *); protected: HSMISSILESTORE *m_storage[HS_MAX_MISSILES]; // Missle storage }; // A weapons array that can exist on any console class CHSWeaponArray { public: CHSWeaponArray(void); BOOL NewWeapon(int); // Calls for a new weapon BOOL DeleteWeapon(int); // Deletes a weapon in a given slot void ClearArray(void); void SetMissileBay(CHSMissileBay *); void DoCycle(void); UINT GetTotalPower(void); // Total power needed by all weapons UINT GetMaxRange(void); CHSWeapon *GetWeapon(int); // Returns the weapon in a given slot protected: void NewLaser(int); // Creates a new laser in the array void NewMTube(int); // Creates a new missile in the array CHSWeapon *m_weapons[HS_MAX_WEAPONS]; // The weapons array UINT m_nWeapons; CHSMissileBay *m_missile_bay; }; extern CHSWeaponDBArray waWeapons; #endif // __HSWEAPON_INCLUDED__ src/hspace/hsexterns.h 100664 767 767 1575 7141305141 13215 0 ustar mux mux #ifndef __HSEXTERNS_INCLUDED__ #define __HSEXTERNS_INCLUDED__ #ifdef MUX #include "../autoconf.h" #include "../copyright.h" #include "../config.h" #include "../externs.h" #include "../powers.h" #include "../attrs.h" #include "../ansi.h" #include "../htab.h" #include "../command.h" #include "../match.h" #define HSPACE_FLAG_WORD(t) db[t].flags3 #define THING_HSPACE_OBJECT 0x00000400 #define THING_HSPACE_CONSOLE 0x00000800 #define THING_HSPACE_COMM 0x00001000 #define THING_HSPACE_TERRITORY 0x00002000 #define ROOM_HSPACE_LANDINGLOC 0x00004000 #define ROOM_HSPACE_UNIVERSE 0x00008000 #define HS_GOOD_OBJ(thing) Good_obj(thing) #define HS_ISGARBAGE(thing) isGarbage(thing) #define HS_BUFFER_SIZE LBUF_SIZE #endif #ifdef PENNMUSH #define HS_GOOD_OBJ(thing) GoodObject(thing) #define HS_ISGARBAGE(thing) IsGarbage(thing) #define HS_BUFFER_SIZE BUFFER_SIZE #endif #endif