Skip to content

Commit

Permalink
fixing network graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
felixvonsamson committed Dec 22, 2024
1 parent d411c58 commit 2b9690b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
10 changes: 5 additions & 5 deletions energetica/init_test_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def climate_events_scenario(engine):
add_asset(player1, "coal_mine", 2)
add_asset(player1, "uranium_mine", 1)
add_asset(player1, "warehouse", 1)
add_asset(player1, "industry", 16)
add_asset(player1, "industry", 12)
add_asset(player1, "laboratory", 4)
add_asset(player1, "gas_burner", 1)
add_asset(player1, "mechanical_engineering", 1)
Expand Down Expand Up @@ -159,10 +159,10 @@ def climate_events_scenario(engine):
add_asset(player1, "chemistry", 5)
add_asset(player1, "nuclear_engineering", 1)

add_asset(player1, "molten_salt", 1)
add_asset(player1, "hydrogen_storage", 1)
add_asset(player1, "solid_state_batteries", 1)
add_asset(player1, "gas_drilling_site", 1)
# add_asset(player1, "molten_salt", 1)
# add_asset(player1, "hydrogen_storage", 1)
# add_asset(player1, "solid_state_batteries", 1)
# add_asset(player1, "gas_drilling_site", 1)

# Player 2
player2.money = 1_000_000_000
Expand Down
21 changes: 11 additions & 10 deletions energetica/production_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,21 +433,21 @@ class all capacity offers in ascending order of price
Sell all capacities that are below market price at market price.
"""

def add_to_market_data(quantity, export=True):
def add_to_market_data(player_id, quantity, facility, export=True):
"""Adds the exported or imported quantity to the market data so that it can be shown in the charts."""
import_export = "player_imports"
generation_consumption = "consumption"
if export:
import_export = "player_exports"
generation_consumption = "generation"
if row.player_id in market[import_export]:
market[import_export][row.player_id] += quantity
if player_id in market[import_export]:
market[import_export][player_id] += quantity
else:
market[import_export][row.player_id] = quantity
if row.facility in market[generation_consumption]:
market[generation_consumption][row.facility] += quantity
market[import_export][player_id] = quantity
if facility in market[generation_consumption]:
market[generation_consumption][facility] += quantity
else:
market[generation_consumption][row.facility] = quantity
market[generation_consumption][facility] = quantity

def sell(row, market_price, quantity=None):
"""Sell and produce offered power capacity."""
Expand All @@ -462,7 +462,7 @@ def sell(row, market_price, quantity=None):
demand["exports"] += quantity
player.money += quantity * market_price / 3600 * engine.in_game_seconds_per_tick / 1_000_000
revenue["exports"] += quantity * market_price / 3600 * engine.in_game_seconds_per_tick / 1_000_000
add_to_market_data(quantity, export=True)
add_to_market_data(player.id, quantity, row.facility, export=True)

def buy(row, market_price, quantity=None):
"""Buy demanded power capacity."""
Expand All @@ -474,7 +474,7 @@ def buy(row, market_price, quantity=None):
generation["imports"] += quantity
player.money -= quantity * market_price / 3600 * engine.in_game_seconds_per_tick / 1_000_000
revenue["imports"] -= quantity * market_price / 3600 * engine.in_game_seconds_per_tick / 1_000_000
add_to_market_data(quantity, export=False)
add_to_market_data(player.id, quantity, row.facility, export=False)

market["player_exports"] = {}
market["player_imports"] = {}
Expand Down Expand Up @@ -508,7 +508,8 @@ def buy(row, market_price, quantity=None):
player.money -= dump_cap * 5 / 3600 * engine.in_game_seconds_per_tick / 1_000_000
revenue = new_values[row.player_id]["revenues"]
revenue["dumping"] -= dump_cap * 5 / 3600 * engine.in_game_seconds_per_tick / 1_000_000
add_to_market_data(dump_cap, export=False)
add_to_market_data(player.id, dump_cap, "dumping", export=False)
add_to_market_data(player.id, dump_cap, row.facility, export=True)
continue
break
sell(row, market_price)
Expand Down

0 comments on commit 2b9690b

Please sign in to comment.