Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
Lots of assorted hooks for status/contacts. Both are pulling mocked v…
Browse files Browse the repository at this point in the history
…alues from the correct functions.
  • Loading branch information
gtaylor committed Oct 3, 2013
1 parent ea1afd8 commit b0dfbec
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 17 deletions.
63 changes: 49 additions & 14 deletions src/game/parents/space/ships/interior/bridge.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from src.daemons.server.ansi import ANSI_NORMAL
from src.game.parents.space.hangar import HangarMixin
from src.game.parents.space.solar_system import SolarSystemPlaceObject
from src.daemons.server.commands.cmdtable import CommandTable
from src.daemons.server.commands.command import BaseCommand
from src.game.parents.space.ships.interior.base import SpaceShipInteriorObject
from src.daemons.server.commands.exceptions import CommandError
from src.daemons.server.objects.exceptions import NoSuchObject
from src.game.parents.utils.text_elements import progress_bar_str
from src.game.parents.space.solar_system import SolarSystemPlaceObject
from src.game.parents.space.ships.interior.base import SpaceShipInteriorObject
from src.game.player_orgs.standings import get_standing_value_cosmetics


class CmdLaunch(BaseCommand):
Expand Down Expand Up @@ -144,7 +144,6 @@ def func(self, invoker, parsed_cmd):

max_shield_hp = ship.get_max_shield_hp()
current_shield_hp = ship.get_current_shield_hp()
print "SHIELD HP", current_shield_hp, max_shield_hp
shield_bar, shield_perc, shield_color = progress_bar_str(
24, max_shield_hp, current_shield_hp)
max_hull_hp = ship.get_max_hull_hp()
Expand All @@ -171,11 +170,20 @@ def func(self, invoker, parsed_cmd):
hull_bar=hull_bar,
hull_perc=hull_perc,
hull_color=hull_color,
escape_color=ANSI_NORMAL,
)
escape_color=ANSI_NORMAL)
buf += self._get_footer_str(pad_char='-')
buf += '\n Reactor Utilization: 3 of 10 units'
buf += '\n Shields: 1 Engines: 1 Weapons: 1 Drones: 1 Specials: 0'
buf += '\n Reactor Utilization: {power_util} of {max_power} units'.format(
power_util=ship.get_total_power_unit_usage(),
max_power=ship.get_max_power_units())
buf += (
'\n Shields: {shield_units:<3} Engines: {engine_units:<3} '
'Weapons: {weapon_units:<3} Drones: {drone_units:<3} '
'Specials: {special_units:<3}'.format(
shield_units=ship.get_shield_power_unit_usage(),
engine_units=ship.get_engine_power_unit_usage(),
weapon_units=ship.get_weapon_power_unit_usage(),
drone_units=ship.get_drone_power_unit_usage(),
special_units=ship.get_specials_power_unit_usage()))
buf += self._get_footer_str()
buf += '\n----- Weapon ----------- [##] Power --- Status ||--- Ammo Type ---- Rounds'
buf += '\n {weapon_name:<23} [{weapon_num:>2}] 1 unit {cycle_state:<6}'.format(
Expand Down Expand Up @@ -206,17 +214,44 @@ def func(self, invoker, parsed_cmd):

buf = self._get_header_str("Contacts near %s" % ship.location.get_appearance_name(invoker))
for contact in ship.get_visible_contacts():
shield_bar, shield_perc, shield_color = progress_bar_str(
12, contact.get_max_shield_hp(), contact.get_current_shield_hp())
hull_bar, hull_perc, hull_color = progress_bar_str(
12, contact.get_max_hull_hp(), contact.get_current_hull_hp())
standing_val = contact.check_ship_standing(ship)
standing_str, standing_color = get_standing_value_cosmetics(standing_val)
status_flags = self._get_short_status_flags(contact)

buf += (
"\n {id:>5}]{ship_class_code:<1} {ship_reference:<10} "
"{display_name:<20} S:[==========] H:[==========] S:".format(
id=contact.id,
ship_class_code=contact.ship_class_code,
ship_reference=contact.ship_reference,
display_name=contact.display_name))
"\n {standing_color}{id:>5}]{ship_class_code:<1} {ship_reference:<10} "
"{display_name:<20} S:{shield_bar} H:{hull_bar} "
"S:{status_flags}{escape_color}".format(
standing_color=standing_color,
id=contact.id,
ship_class_code=contact.ship_class_code,
ship_reference=contact.ship_reference,
display_name=contact.display_name,
shield_bar=shield_bar,
hull_bar=hull_bar,
status_flags=status_flags,
escape_color=ANSI_NORMAL))
buf += self._get_footer_str()

invoker.emit_to(buf)

def _get_short_status_flags(self, contact):
"""
:rtype: basestring
:returns: A short string containing various status flags. Each character
in the string represents another state/condition that is readable
on the contacts list.
"""

buf = ""
if contact.is_ship_destroyed():
buf += "D"
return buf


#noinspection PyAttributeOutsideInit
class CmdWarp(BaseCommand):
Expand Down
102 changes: 100 additions & 2 deletions src/game/parents/space/ships/ship_classes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,42 @@ def get_visible_contacts(self):
"""

assert not self.is_ship_landed(), "Attempting to get contacts while landed."
return [obj for obj in self.location.get_contents() if isinstance(obj, InSpaceObject)]
return [obj for obj in self.location.get_contents()
if isinstance(obj, InSpaceObject) and obj.id != self.id]

def check_ship_standing(self, inquiring_ship):
"""
Used by other ships to check their standing with this ship.
:param BaseSpaceShipObject inquiring_ship: The ship that wants to
know their standing to this one.
:rtype: float
:returns: A scale between 0.0 and 1.0, with 0.0 being extremely
hostile, 0.5 being neutral, and 1.0 being extremely friendly.
"""

# TODO: Make this work.
return 0.5

#
## Ship vitals

def is_ship_destroyed(self):
"""
:rtype: bool
:returns: True if this ship is destroyed, False if not.
"""

# TODO: Make this work.
return False

def get_max_shield_hp(self):
"""
:rtype: int
:returns: The maximum shield HPs for this ship, as currently configured.
"""

# TODO: Make this work.
return 100

def get_current_shield_hp(self):
Expand All @@ -165,6 +193,7 @@ def get_current_shield_hp(self):
:returns: The current shield HPs for this ship.
"""

# TODO: Make this work.
return 80

def get_max_hull_hp(self):
Expand All @@ -173,6 +202,7 @@ def get_max_hull_hp(self):
:returns: The maximum hull HPs for this ship, as currently configured.
"""

# TODO: Make this work.
return 100

def get_current_hull_hp(self):
Expand All @@ -181,4 +211,72 @@ def get_current_hull_hp(self):
:returns: The current hull HPs for this ship.
"""

return 50
# TODO: Make this work.
return 50

def get_max_power_units(self):
"""
:rtype: int
:returns: The maximum number of power units the ship is capable of
producing in its current state.
"""

# TODO: Make this work.
return 10

def get_total_power_unit_usage(self):
"""
:rtype: int
:returns: The current power usage in power units.
"""

return self.get_shield_power_unit_usage() + \
self.get_engine_power_unit_usage() + \
self.get_weapon_power_unit_usage() + \
self.get_drone_power_unit_usage() + \
self.get_specials_power_unit_usage()

def get_shield_power_unit_usage(self):
"""
:rtype: int
:returns: The current shield system power usage in power units.
"""

# TODO: Make this work.
return 0

def get_engine_power_unit_usage(self):
"""
:rtype: int
:returns: The current engine system power usage in power units.
"""

# TODO: Make this work.
return 0

def get_weapon_power_unit_usage(self):
"""
:rtype: int
:returns: The current weapon system power usage in power units.
"""

# TODO: Make this work.
return 0

def get_drone_power_unit_usage(self):
"""
:rtype: int
:returns: The current drone system power usage in power units.
"""

# TODO: Make this work.
return 0

def get_specials_power_unit_usage(self):
"""
:rtype: int
:returns: The current special system power usage in power units.
"""

# TODO: Make this work.
return 0
3 changes: 3 additions & 0 deletions src/game/parents/space/solar_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def get_dockable_obj_list(self, invoker_ship):
# BaseObject sub-classes, and run some checks to make sure we can
# dock there.
for space_obj_id, hangar_ids in grouped_hangars.items():
if space_obj_id == invoker_ship.id:
# The invoker can't dock in itself.
continue
space_obj_hangar_objs = []
for hangar_id in hangar_ids:
hangar_obj = self.mud_service.object_store.get_object(hangar_id)
Expand Down
2 changes: 1 addition & 1 deletion src/game/parents/utils/text_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ def progress_bar_str(char_limit, max_value, current_value):

buf = ANSI_HI_WHITE + '[' + bar_color
buf += ('=' * bar_width) + (' ' * (max_bar_width - bar_width))
buf += ANSI_HI_WHITE + ']'
buf += ANSI_HI_WHITE + ']' + ANSI_NORMAL
return buf, int(math.floor(perc * 100)), bar_color
1 change: 1 addition & 0 deletions src/game/player_orgs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'gtaylor'
29 changes: 29 additions & 0 deletions src/game/player_orgs/standings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Various inter-organization standings functions and utilities.
"""

from src.daemons.server.ansi import ANSI_HI_CYAN, ANSI_HI_GREEN, ANSI_HI_WHITE, ANSI_NORMAL, ANSI_HI_YELLOW, ANSI_HI_RED


def get_standing_value_cosmetics(standing_val):
"""
Given a standing value between 0.0 and 1.0, return a text label for the
value and a color that may be optionally used.
:param float standing_val: The standing value to return cosmetics for.
:rtype: tuple
:returns: A tuple in the format of (standing_name, standing_color).
"""

if standing_val >= 0.9:
return "Allied", ANSI_HI_GREEN
elif standing_val >= 0.75:
return "Friendly", ANSI_HI_CYAN
elif standing_val > 0.5:
return "Cordial", ANSI_HI_WHITE
elif standing_val == 0.5:
return "Neutral", ANSI_NORMAL
elif standing_val >= 0.45:
return "Disliked", ANSI_HI_YELLOW
else:
return "Hated", ANSI_HI_RED

0 comments on commit b0dfbec

Please sign in to comment.