Skip to content

Commit

Permalink
Fixed lon command, added heading commands, untested
Browse files Browse the repository at this point in the history
  • Loading branch information
QBFreak committed Oct 10, 2019
1 parent 8baac0b commit 16a4fdf
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 6 deletions.
183 changes: 178 additions & 5 deletions commands/spaceshipconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from evennia import CmdSet
from evennia import Command
from typeclasses.spaceship import SpaceShipHull
from world.space import SpaceRoom


class SSCCmdSet(CmdSet):
Expand All @@ -22,6 +24,13 @@ def at_cmdset_creation(self):
"""
self.add(CmdSSCLat())
self.add(CmdSSCLon())
self.add(CmdSSCStep())
self.add(CmdSSCPort())
self.add(CmdSSCStarboard())
self.add(CmdSSCUp())
self.add(CmdSSCDown())

# TODO: Lat/Lon command adjusting for entries > 360 using `% 360`


class CmdSSCLat(Command):
Expand Down Expand Up @@ -85,12 +94,176 @@ def func(self):
"Display or verify and set the longitude"
caller = self.caller
if not self.target:
if not self.obj.db.lat:
self.obj.db.lat = 0
caller.msg("The current longitude is {}".format(self.obj.db.lat))
if not self.obj.db.lon:
self.obj.db.lon = 0
caller.msg("The current longitude is {}".format(self.obj.db.lon))
else:
if int(self.target) % 45 != 0:
caller.msg("Longitude must be entered in increments of 45 degrees")
else:
self.obj.db.lat = int(self.target)
caller.msg("The current longitude has been set to {}".format(self.obj.db.lat))
self.obj.db.lon = int(self.target) % 360
caller.msg("The current longitude has been set to {}".format(self.obj.db.lon))


class CmdSSCStep(Command):
"""
Take a step into the next system, along the ship's current course. This is a
temporary command.
Usage:
step
Temporary command to step the ship into the next system along it's current
course.
"""

key = "step"
aliases = []
locks = "cmd:all()"
help_category = "General"

def parse(self):
"Very trivial parser"
self.target = self.args.strip()

def func(self):
"Take a step towards the next system"
caller = self.caller
if self.target:
caller.msg("Step does not take any parameters")
return
ship = self.obj.db.hull
if not isinstance(ship, SpaceShipHull):
caller.msg("Error locating ship!")
return
if not isinstance(ship.location, SpaceRoom):
caller.msg("Cannot step ship that is not in space!")
return
coordinates = list(ship.location.coordinates)
x = 0
y = 0
z = 0
# Lat == 0 or Lat == 180: Ship upside down re ecliptic
if self.obj.db.lat > 0 and self.obj.db.lat < 180:
z = 1
if self.obj.db.lat > 180 and self.obj.db.lat < 360:
z = -1
if self.obj.db.lon > 270 or self.obj.db.lon < 90:
y = 1
if self.obj.db.lon > 90 and self.obj.db.lon < 270:
y = -1
if self.obj.db.lon > 0 and self.obj.db.lon < 180:
x = 1
if self.obj.db.lon > 180 and self.obj.db.lon < 360:
x = -1
coordinates[0] += x
coordinates[1] += y
coordinates[2] += z
coordinates = tuple(coordinates)
caller.msg("The new coordinates are {}, {}, {}".format(
coordinates[0], coordinates[1], coordinates[2]
))


class CmdSSCPort(Command):
"""
Turn the ship to port, 45 degrees
Usage:
port
This command may be temporary. It adjusts the ships longitude towards port
by 45 degrees.
"""

key = "port"
aliases = []
locks = "cmd:all()"
help_category = "General"

def parse(self):
"Very trivial parser"
self.target = self.args.strip()

def func(self):
"Turn ship to port"
self.obj.db.lon = (self.obj.db.lon - 45 + 360) % 360
self.caller.msg("The ship is now oriented to {} longitude.".format(self.obj.db.lon))


class CmdSSCStarboard(Command):
"""
Turn the ship to starboard, 45 degrees
Usage:
starboard
This command may be temporary. It adjusts the ships longitude towards
starboard by 45 degrees.
"""

key = "starboard"
aliases = ["star"]
locks = "cmd:all()"
help_category = "General"

def parse(self):
"Very trivial parser"
self.target = self.args.strip()

def func(self):
"Turn ship to starboard"
self.obj.db.lon = (self.obj.db.lon + 45) % 360
self.caller.msg("The ship is now oriented to {} longitude.".format(self.obj.db.lon))


class CmdSSCUp(Command):
"""
Pitch the ship to up, 45 degrees
Usage:
up
This command may be temporary. It adjusts the ships latitude upward by 45
degrees.
"""

key = "up"
aliases = []
locks = "cmd:all()"
help_category = "General"

def parse(self):
"Very trivial parser"
self.target = self.args.strip()

def func(self):
"Pitch ship up"
self.obj.db.lat = (self.obj.db.lat + 45) % 360
self.caller.msg("The ship is now oriented to {} latitude.".format(self.obj.db.lat))


class CmdSSCDown(Command):
"""
Pitch the ship to down, 45 degrees
Usage:
down
This command may be temporary. It adjusts the ships latitude downwards by 45
degrees.
"""

key = "down"
aliases = []
locks = "cmd:all()"
help_category = "General"

def parse(self):
"Very trivial parser"
self.target = self.args.strip()

def func(self):
"Pitch ship down"
self.obj.db.lat = (self.obj.db.lat - 45 + 360) % 360
self.caller.msg("The ship is now oriented to {} latitude.".format(self.obj.db.lat))
2 changes: 1 addition & 1 deletion typeclasses/spaceship.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def at_object_creation(self):
"""

# Add the Command Set for the Console
self.cmdset.add("spaceshipconsole.SSCCmdSet")
self.cmdset.add("spaceshipconsole.SSCCmdSet", permanent=True)

def return_appearance(self, looker):
"""
Expand Down

0 comments on commit 16a4fdf

Please sign in to comment.