Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into nick
  • Loading branch information
nicholas-pfeifer committed Feb 8, 2020
2 parents 190c901 + 879064d commit dafa77e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
1 change: 1 addition & 0 deletions game/common/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class EventType:
building_upgrade = 2
disaster_spawned = 3
disaster_eliminated = 4
effort_applied = 5


class ObjectType:
Expand Down
40 changes: 40 additions & 0 deletions game/controllers/effort_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,24 @@ def apply_disaster_effort(self, player, lasting_disaster, number):

lasting_disaster.reduce(number)

# log upgrade
if number >= 0:
self.event_controller.add_event({
"event_type": EventType.effort_applied,
"object_or_ActionType": lasting_disaster.to_json(),
"amount": number
})

def apply_no_effort(self, player, number):
if number > 0:
self.print(f"{number} population allocated towards ActionType.none by player {player}. "
f"Are you sure the population should be doing nothing?")
# log upgrade
self.event_controller.add_event({
"event_type": EventType.effort_applied,
"object_or_ActionType": ActionType.none,
"amount": number
})

# Increase population level given effort
def apply_population_effort(self, player, number):
Expand All @@ -113,6 +127,12 @@ def apply_population_effort(self, player, number):
increase = math.floor(number * GameStats.effort_population_multiplier)
# Update population without going over structure
player.city.population = clamp(player.city.population+increase, min_value=0, max_value=player.city.structure)
# log upgrade
self.event_controller.add_event({
"event_type": EventType.effort_applied,
"object_or_ActionType": ActionType.regain_population,
"amount": number
})

def apply_structure_effort(self, player, number):
if number < 0:
Expand All @@ -127,6 +147,12 @@ def apply_structure_effort(self, player, number):

# Update population without going over structure
player.city.structure = clamp(player.city.structure+increase, min_value=0, max_value=player.city.max_structure)
# log upgrade
self.event_controller.add_event({
"event_type": EventType.effort_applied,
"object_or_ActionType": ActionType.repair_structure,
"amount": number
})

# Upgrades a building, city, or sensor given inputted effort (and available wealth, for buildings)
def apply_upgrade_effort(self, player, obj, number):
Expand Down Expand Up @@ -215,6 +241,13 @@ def apply_upgrade_effort(self, player, obj, number):
# Move all the effort from number to the upgradable object
obj.effort_remaining -= number

# log upgrade
self.event_controller.add_event({
"event_type": EventType.effort_applied,
"object_or_ActionType": obj.to_json(),
"amount": number
})

number = 0 # For now, set number to 0. If there's left over allocation, we pull it back from the object

# if limit maxed, begin upgrade
Expand Down Expand Up @@ -268,6 +301,13 @@ def apply_wealth_effort(self, player, number):

player.city.gold += increase

# log upgrade
self.event_controller.add_event({
"event_type": EventType.effort_applied,
"object_or_ActionType": ActionType.accumulate_wealth,
"amount": increase
})

def __reverse_obfuscation(self, player):
new_actions = list()
for allocation in player.action.get_allocation_list():
Expand Down
6 changes: 3 additions & 3 deletions game/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random


def clamp(value, min_value=None, max_value=None):
def clamp(value, min_value=float('-inf'), max_value=float('inf')):
"""
Restricts a given value from going outside the range, default of 0 and 100
:param value: given value to be clamped
Expand All @@ -12,9 +12,9 @@ def clamp(value, min_value=None, max_value=None):
:return: the value given but restricted to max or min if it goes outside the range
"""
if min_value is None:
min_value = value
min_value = -1 * float('inf')
if max_value is None:
max_value = value
max_value = float('inf')
return min(max_value, max(value, min_value))


Expand Down
8 changes: 7 additions & 1 deletion game/visualizer/worker_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ def __init__(self, turn, display_size, parser, assets):
info = parser.get_turn(turn)

total_effort_expended = 0
# {event['object_or_ActionType'], event['amount'] for event in info['events'] if event['turn'] == turn and event['event_type'] == EventType.effort_applied}
for event in info['events']:
if event['event_type'] is not EventType.effort_applied:
continue

for item, amount in info['player']['action']['effort']:
item = event['object_or_ActionType']
amount = event['amount']

x = 0
y = 0
max_x = 0
Expand Down

0 comments on commit dafa77e

Please sign in to comment.