Skip to content

Commit

Permalink
#90: Changed warp to land entities near the warp radius of the celest…
Browse files Browse the repository at this point in the history
…ial. (#91)

* Created spacegame.commands package and moved warp commands into it.

* Changed warp command to land entities around the limits of the destination celestial's warp radius.
  • Loading branch information
ecdavis committed Oct 20, 2016
1 parent 6ab6b70 commit 07f76d0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
author_email="me@ezdwt.com",
url="http://github.com/ecdavis/spacegame",
download_url="https://github.com/ecdavis/spacegame/tarball/master",
packages=["spacegame", "spacegame.core", "spacegame.modules", "spacegame.universe"],
packages=["spacegame", "spacegame.commands", "spacegame.core", "spacegame.modules", "spacegame.universe"],
test_suite="tests.get_all_tests",
install_requires=["pants >= 1.0", "pantsmud >= 0.5.0"],
tests_require=['mock'],
Expand Down
4 changes: 3 additions & 1 deletion spacegame/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import spacegame.commands
import spacegame.core
import spacegame.modules

def init():
spacegame.core.init()
spacegame.modules.init()
spacegame.modules.init() # Init modules after core
spacegame.commands.init() # Init commands after modules


def start():
Expand Down
5 changes: 5 additions & 0 deletions spacegame/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from spacegame.commands import warp


def init():
warp.init()
34 changes: 34 additions & 0 deletions spacegame/commands/warp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from pantsmud.driver import command, parser
from pantsmud.util import message
from spacegame.modules import warp


def warp_command(brain, cmd, args):
params = parser.parse([("destination_uuid", parser.UUID)], args)
result = warp.do_warp(brain.mobile, params["destination_uuid"])
message.command_success(brain, cmd, result)


def warp_beacon_command(brain, cmd, args):
parser.parse([], args)
result = warp.do_warp_beacon(brain.mobile)
message.command_success(brain, cmd, result)


def warp_scan_command(brain, cmd, args):
parser.parse([], args)
result = warp.do_warp_scan(brain.mobile)
message.command_success(brain, cmd, result)


def warp_scan_activate_command(brain, cmd, args):
parser.parse([], args)
result = warp.do_warp_scan_activate(brain.mobile)
message.command_success(brain, cmd, result)


def init():
command.add_command("warp", warp_command)
command.add_command("warp.beacon", warp_beacon_command)
command.add_command("warp.scan", warp_scan_command)
command.add_command("warp.scan.activate", warp_scan_activate_command)
43 changes: 19 additions & 24 deletions spacegame/modules/warp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random
import pantsmud.game
from pantsmud.driver import auxiliary, command, hook, parser
from pantsmud.util import error, message
from pantsmud.driver import auxiliary, hook
from pantsmud.util import error
from spacegame.core import aux_types, hook_types
from spacegame.universe import entity

Expand All @@ -17,16 +17,14 @@ def save_data(self):
return {}


def warp_command(brain, cmd, args):
params = parser.parse([("destination_uuid", parser.UUID)], args)
mobile = brain.mobile
destination, position = _find_warp_destination(mobile, params["destination_uuid"])
def do_warp(mobile, destination_uuid):
destination, position = _find_warp_destination(mobile, destination_uuid)
if destination is None or position is None:
raise error.CommandFail("no destination")
hook.run(hook_types.CELESTIAL_EXIT, mobile)
mobile.celestial = destination
mobile.position = position
message.command_success(mobile, cmd)
return None


def _find_warp_destination(mobile, destination_uuid):
Expand All @@ -37,7 +35,7 @@ def _find_warp_destination(mobile, destination_uuid):
celestials = mobile.star_system.get_celestials(uuids=mobile.aux["warp"].scanner)
for celestial in celestials:
if celestial.uuid == destination_uuid:
return celestial, _random_position_around((0, 0, 0))
return celestial, _random_position_around((0+celestial.warp_radius, 0, 0))
return None, None


Expand All @@ -50,35 +48,36 @@ def _random_position_around(position):
)


def warp_beacon_command(brain, cmd, args):
parser.parse([], args)
mobile = brain.mobile
def do_warp_beacon(mobile):
beacon = entity.Entity(is_warp_beacon=True)
beacon.celestial = mobile.celestial
beacon.position = mobile.position
pantsmud.game.environment.add_entity(beacon)
message.command_success(mobile, cmd, {"beacon_uuid": str(beacon.uuid)})
return {
"beacon_uuid": str(beacon.uuid)
}


def warp_scan_command(brain, cmd, args):
parser.parse([], args)
mobile = brain.mobile
def do_warp_scan(mobile):
beacons = mobile.star_system.get_entities(is_warp_beacon=True)
beacon_data = {b.name: str(b.uuid) for b in beacons if b.celestial is not mobile.celestial}
celestials = mobile.star_system.get_celestials(uuids=mobile.aux["warp"].scanner)
celestial_data = {c.name: str(c.uuid) for c in celestials if c is not mobile.celestial}
message.command_success(mobile, cmd, {"beacons": beacon_data, "celestials": celestial_data})
return {
"beacons": beacon_data,
"celestials": celestial_data
}


def warp_scan_activate_command(brain, cmd, args):
parser.parse([], args)
mobile = brain.mobile
def do_warp_scan_activate(mobile):
celestials = mobile.star_system.get_celestials()
celestial_data = {c.name: c.uuid for c in celestials if c is not mobile.celestial}
mobile.aux["warp"].scanner = celestial_data.values()[:]
for k, v in celestial_data.items(): # TODO ugh
celestial_data[k] = str(v)
message.command_success(mobile, cmd, {"celestials": celestial_data})
return {
"celestials": celestial_data
}


def clear_warp_scanner(_, mobile):
Expand All @@ -87,9 +86,5 @@ def clear_warp_scanner(_, mobile):

def init():
auxiliary.install(aux_types.AUX_TYPE_ENTITY, "warp", WarpAux)
command.add_command("warp", warp_command)
command.add_command("warp.beacon", warp_beacon_command)
command.add_command("warp.scan", warp_scan_command)
command.add_command("warp.scan.activate", warp_scan_activate_command)
hook.add(hook_types.CELESTIAL_EXIT, clear_warp_scanner)
hook.add(hook_types.STAR_SYSTEM_EXIT, clear_warp_scanner)

0 comments on commit 07f76d0

Please sign in to comment.