forked from tidalwaave/AOCE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModel.py
136 lines (109 loc) · 4.73 KB
/
Model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# --- Imports ---
from map.map import Map
from map.procedural_map import process_array2
from utils.vector import Vector
from entity.Unit import *
from entity.Zone import *
from utils.isometric import *
# -- Constants ---
from CONSTANTS import DEFAULT_MAP_SIZE, TILE_HEIGHT_HALF
# --- Launch setup ---
from LAUNCH_SETUP import LAUNCH_DEFAULT_MAP
#########################################################################
# MODEL CLASS #
#########################################################################
class Model():
def __init__(self, aoce_game):
""" Initializer """
self.game = aoce_game
self.unit_list = []
self.tile_list = []
self.zone_list = []
self.map = Map(self.tile_list, self.zone_list, DEFAULT_MAP_SIZE)
def __getstate__(self):
return [self.unit_list, self.tile_list, self.zone_list, self.map]
def __setstate__(self, data):
self.unit_list = data[0]
self.tile_list = data[1]
self.zone_list = data[2]
self.map = data[3]
def reset(self):
# clear old lists
self.unit_list.clear()
self.tile_list.clear()
self.zone_list.clear()
self.reset_zone_globals()
self.reset_unit_globals()
def reset_zone_globals(self) :
# ICI on doit reset tout ce que les amliorations de batiments peuvent modifier
TownCenter.upgrade_level = 0
Barracks.upgrade_level = 0
StoragePit.upgrade_level = 0
StoragePit.creation_cost = {Res.FOOD : 0, Res.WOOD : 120, Res.GOLD : 0, Res.STONE : 0}
Granary.upgrade_level = 0
Granary.creation_cost = {Res.FOOD : 0, Res.WOOD : 120, Res.GOLD : 0, Res.STONE : 0}
House.upgrade_level = 0
House.creation_cost = {Res.FOOD : 0, Res.WOOD : 30, Res.GOLD : 0, Res.STONE : 0}
def reset_unit_globals(self) :
# ICI on doit reset tout ce que les amliorations de batiments peuvent modifier
Villager.creation_cost = {Res.FOOD : 50, Res.WOOD : 0, Res.GOLD : 0, Res.STONE : 0}
Militia.creation_time = 21
Spearman.creation_time = 22
Archer.creation_time = 35
Skirmisher.creation_time = 22
ScoutCavalry.creation_time = 30
Knight.creation_time = 30
def setup(self, ressources, players, map_seed):
self.reset()
# pre game view infos
self.players = players
self.map_seed = map_seed
#print(ressources)
# Set up the villager and add it to the unit_list.
# self.map = Map(self.tile_list, self.zone_list, DEFAULT_MAP_SIZE)
use_default = LAUNCH_DEFAULT_MAP
if use_default :
self.map.setup(None)
else:
self.map.setup(process_array2(seed=self.map_seed, size=(DEFAULT_MAP_SIZE, DEFAULT_MAP_SIZE), nbr_players=len(self.players)))
for pos_spawn in self.map.spawn_array:
if "player" in self.players:
faction = "player" if pos_spawn[1] == "0" else "ai_" + pos_spawn[1]
self.game.game_controller.add_entity_to_game(TownCenter(pos_spawn[0], faction))
else:
faction = f"ai_{int(pos_spawn[1]) + 1}"
self.game.game_controller.add_entity_to_game(TownCenter(pos_spawn[0], faction))
start_villagers = (Villager(grid_pos_to_iso(pos_spawn[0] - Vector(1, 1)), faction),
Villager(grid_pos_to_iso(pos_spawn[0] - Vector(0, 1)), faction),
Villager(grid_pos_to_iso(pos_spawn[0] - Vector(1, 0)), faction))
for v in start_villagers:
self.game.game_controller.add_entity_to_game(v)
# units = (Villager(Vector(100, 100), "player"),
# Villager(Vector(50, 50), "player"),
# Villager(grid_pos_to_iso(Vector(3, 2)) + Vector(0, TILE_HEIGHT_HALF),"player"))
# for unit in units:
# self.game.game_controller.add_entity_to_game(unit)
# #military
# militaries = (Militia(grid_pos_to_iso(Vector(10, 2)) + Vector(0, TILE_HEIGHT_HALF), "player"),
# Archer(grid_pos_to_iso(Vector(13, 2)) + Vector(0, TILE_HEIGHT_HALF), "player"),
# Knight(grid_pos_to_iso(Vector(16, 2)) + Vector(0, TILE_HEIGHT_HALF), "player")
# )
# for military in militaries:
# self.game.game_controller.add_entity_to_game(military)
def add_entity(self, new_entity):
if isinstance(new_entity, Unit) and new_entity not in self.unit_list:
self.unit_list.append(new_entity)
elif isinstance(new_entity, Zone) and new_entity not in self.zone_list:
self.zone_list.append(new_entity)
self.map.add_entity_to_pos(new_entity)
self.map.reserve_tile_at(new_entity.grid_position, new_entity.tile_size)
if isinstance(new_entity, (TownCenter, Barracks, WorkSite)):
self.map.set_build_guard(new_entity.grid_position - Vector(1,1))
def discard_entity(self, dead_entity):
if isinstance(dead_entity, Unit) and dead_entity in self.unit_list:
self.unit_list.remove(dead_entity)
elif isinstance(dead_entity, Zone) and dead_entity in self.zone_list:
self.zone_list.remove(dead_entity)
self.map.free_tile_at(dead_entity.grid_position, dead_entity.tile_size)
if isinstance(dead_entity, (TownCenter, Barracks, WorkSite)):
self.map.remove_build_guard(dead_entity.grid_position - Vector(1,1))