forked from IamFlea/bartender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc_player.py
225 lines (210 loc) · 12 KB
/
aoc_player.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" aoc_game.py: parsing aoc memory of recordgames by Flea """
from pymemory import pymemory as pm
from aoc_diplomacy import *
from aoc_resources import *
from aoc_color import *
from aoc_civ import *
from aoc_object_building_research import BuildingResearch
from aoc_object_consts import *
from aoc_objects import Objects
from aoc_research import Research
class Player(object):
""" Player strucutre
Attributes
public
ptr Pointer to player structure
name Name of the player
diplomacy Diplomacy struct
resources Resources struct
color Color struct
research Research struct
objects List of player's objects (units, buildings, treees whatever)
log Some kind of log if diplomacy changed.. # maybe removei t
selected Selected units pointers
buildings Buildings
farm_reseeds Number of reseeds in a mill
pov Boolean
Public object lists
buildings_all All buildings without trebuchets (not a joke, they are implemented as moving building)
buildings All buildings without towers, walls, trebuchets
units Units + trebuchets
civilians Vills + fishing ships + trades
villagers Vills only
military Military + transport ship
Villagers
vill_wood Vills marked as Lumberjack
vill_food Vills marked as Fisher, Farmer, Hunter, Cannibal
vill_gold Vills marked as Gold Miner
vill_stone Vills marked as Stone miner
trade Trade cogs + trade carts
fish Fishing ships
Buildings
monastery Monstry buildings
stables Stable buildings
archery Archery Ranges
barracks Barracks
siege Siege workshops
castle Castles
docks Docks
lumber_camps Lumbercamps
mining_camps Mining camps
mill Mills
market Markets
blacksmiths Blacksmiths
university Universities
town_centers Town Centers
towers Towers
constructions Buildings which are under the construction.
Methods
public
__init__(ptr, number)
Creates this object.
ptr is a pointer to Player structure
number is a number of the player, if none it assumes it is a gaia
update(market) Updates all players data
private
__get_name__ Used for setting `name` attribute
__analyze_objects__
Fills all the lists
"""
SINGLE_PLAYER = True
def __get_name__(number, ptr_ai):
""" Get players name, if AI grabs """
ptr = pm.pointer(pm.base_address + 0x006EEFB4)
ptr = pm.pointer(ptr + 0x0)
ptr = pm.pointer(ptr + 0x60)
ptr = pm.pointer(ptr + 0xCE4)
ptr = pm.pointer(ptr + 0xb0 + 0x68*(number-1) + 0xC)
try:
name = pm.string(ptr, 32)
except:
name = ""
name = name if name else f"Player #{number}"
if pm.int32(ptr_ai + 0x8) == 3:
name += " [AI]"
return name
def __init__(self, ptr, number=None):
super(Player, self).__init__()
self.ptr = ptr
self.name = "Gaia" if number is None else Player.__get_name__(number, ptr)
self.pov = False
self.diplomacy = Diplomacy(self)
self.resources = Resources(self)
self.color = Color(self)
self.civ = Civilization(self)
self.research = Research(self)
#self.map = Map(ptr)
self.objects = Objects(pm.pointer(ptr + 0x18), self)
self.log = []
#BuildingResearch.log[self] = [] # Better access for researches
Objects._all[self] = {} # Dictionary of used objects
self.housed = False
self.farm_reseeds = 0
self.selected = None
def __analyze_objects__(self):
#import time
#now = time.time()
# This algorithms are optimal in the terms of typing...
# else it sucks cuy it has a big time complexity, could be reduced 20 times..
self.buildings_all = list(filter(lambda obj: obj.udata.superclass == SuperclassData.building, self.objects))
self.buildings = list(filter(lambda obj: obj.udata.class_ in ClassData.building, self.objects)) # filters walls, gates, twoers..
self.units = list(filter(lambda obj: obj.udata.superclass == SuperclassData.combatant, self.objects))
# We need to filter units...
#self.units = list(filter(lambda obj: obj.status in [0,1,2], self.units)) # meeh i am lazy to do comparasion logic
self.civilians = list(filter(lambda obj: obj.udata.class_ in ClassData.civilians, self.units))
self.villagers = list(filter(lambda obj: obj.udata.class_ in ClassData.villagers, self.civilians))
self.military = list(filter(lambda obj: obj.udata.class_ in ClassData.military, self.units))
#self.military = set(self.units) - set(self.civilians) # counts sheep as military units too hahahha
#self.pikes = list(filter(lambda obj: obj.udata.class_ == , self.military))
# Villagers (with idles!)
self.vill_wood = list(filter(lambda obj: obj.udata.id in IdData.vill_wood, self.villagers))
self.vill_food = list(filter(lambda obj: obj.udata.id in IdData.vill_food, self.villagers))
self.vill_gold = list(filter(lambda obj: obj.udata.id in IdData.vill_gold, self.villagers))
self.vill_stone = list(filter(lambda obj: obj.udata.id in IdData.vill_stone, self.villagers))
self.trade = list(filter(lambda obj: obj.udata.id in IdData.trade, self.units))
self.fish = list(filter(lambda obj: obj.udata.id in IdData.fish, self.units))
# Buildings
self.monastery = list(filter(lambda obj: obj.udata.id in IdData.monastery, self.buildings))
self.stables = list(filter(lambda obj: obj.udata.id in IdData.stables, self.buildings))
self.archery = list(filter(lambda obj: obj.udata.id in IdData.archery, self.buildings))
self.barracks = list(filter(lambda obj: obj.udata.id in IdData.barracks, self.buildings))
self.siege = list(filter(lambda obj: obj.udata.id in IdData.siege_workshop, self.buildings))
self.castle = list(filter(lambda obj: obj.udata.id in IdData.castle, self.buildings))
self.docks = list(filter(lambda obj: obj.udata.id in IdData.dock, self.buildings))
self.lumber_camps = list(filter(lambda obj: obj.udata.id in IdData.lumber_camps, self.buildings))
self.mining_camps = list(filter(lambda obj: obj.udata.id in IdData.mining_camps, self.buildings))
self.mill = list(filter(lambda obj: obj.udata.id in IdData.mill, self.buildings))
self.market = list(filter(lambda obj: obj.udata.id in IdData.market, self.buildings))
self.blacksmiths = list(filter(lambda obj: obj.udata.id in IdData.blacksmiths, self.buildings))
self.university = list(filter(lambda obj: obj.udata.id in IdData.university, self.buildings))
self.town_centers = list(filter(lambda obj: obj.udata.id in IdData.town_centers, self.buildings))
self.towers = list(filter(lambda obj: obj.udata.id in IdData.towers, self.buildings_all))
self.gates = list(filter(lambda obj: obj.udata.id in IdData.gates, self.buildings_all))
self.walls = list(filter(lambda obj: obj.udata.id in IdData.walls, self.buildings_all))
self.swordsmen = list(filter(lambda obj: obj.udata.id in IdData.swordsmen, self.units))
self.pikemen = list(filter(lambda obj: obj.udata.id in IdData.pikemen, self.units))
self.eagles = list(filter(lambda obj: obj.udata.id in IdData.eagles, self.units))
self.huskarls = list(filter(lambda obj: obj.udata.id in IdData.huskarls, self.units))
self.condottieros = list(filter(lambda obj: obj.udata.id in IdData.condottieros, self.units))
self.light_cavalry = list(filter(lambda obj: obj.udata.id in IdData.light_cavalry, self.units))
self.heavy_cavalry = list(filter(lambda obj: obj.udata.id in IdData.heavy_cavalry, self.units))
self.camels = list(filter(lambda obj: obj.udata.id in IdData.camels, self.units))
self.tarkans = list(filter(lambda obj: obj.udata.id in IdData.tarkans, self.units))
self.slingers = list(filter(lambda obj: obj.udata.id in IdData.slingers, self.units))
self.archers = list(filter(lambda obj: obj.udata.id in IdData.archers, self.units))
self.skirmishers = list(filter(lambda obj: obj.udata.id in IdData.skirmishers, self.units))
self.cavalry_archers = list(filter(lambda obj: obj.udata.id in IdData.cavalry_archers, self.units))
self.genitours = list(filter(lambda obj: obj.udata.id in IdData.genitours, self.units))
self.hand_cannoneers = list(filter(lambda obj: obj.udata.id in IdData.hand_cannoneers, self.units))
self.siege_rams = list(filter(lambda obj: obj.udata.id in IdData.rams, self.units))
self.onagers = list(filter(lambda obj: obj.udata.id in IdData.onagers, self.units))
self.scorpions = list(filter(lambda obj: obj.udata.id in IdData.scorpions, self.units))
self.bombard_cannons = list(filter(lambda obj: obj.udata.id in IdData.bombard_cannons, self.units))
self.siege_towers = list(filter(lambda obj: obj.udata.id in IdData.siege_towers, self.units))
self.war_ships = list(filter(lambda obj: obj.udata.id in IdData.war_ships, self.units))
self.fire_ships = list(filter(lambda obj: obj.udata.id in IdData.fire_ships, self.units))
self.demolition_ships = list(filter(lambda obj: obj.udata.id in IdData.demolition_ships, self.units))
self.cannon_galleons = list(filter(lambda obj: obj.udata.id in IdData.cannon_galleons, self.units))
self.unique_unit_ships = list(filter(lambda obj: obj.udata.id in IdData.dock_unique_units, self.units))
self.petards = list(filter(lambda obj: obj.udata.id in IdData.petards, self.units))
self.trebuchets = list(filter(lambda obj: obj.udata.id in IdData.trebuchets, self.units))
self.unique_units = list(filter(lambda obj: obj.udata.id in IdData.caslte_unique_units, self.units))
self.monks = list(filter(lambda obj: obj.udata.id in IdData.monks, self.units))
self.transport_ships = list(filter(lambda obj: obj.udata.id in IdData.transport_ships, self.units))
self.livestock = list(filter(lambda obj: obj.udata.class_ in ClassData.livestock, self.units))
#self.constructions = list(filter(lambda obj: obj.construction, self.buildings_all))
# get army
#self.army = {}
#for unit in self.military:
# if unit.udata.id in self.army:
# self.army[unit.udata.id] += [unit]
# else:
# self.army[unit.udata.id] = [unit]
#print(time.time()-now)
def update(self, market):
self.housed = False
self.diplomacy.update(self.log)
self.resources.update()
self.color.update()
with self.objects:
if Player.SINGLE_PLAYER:
if self.pov:
self.objects.update()
else:
self.objects.update()
self.__analyze_objects__()
self.research.update()
self.farm_reseeds = pm.int16(self.ptr + 0x2708)
self.selected = Objects.selected
#self.selected = [item for item in objects.selected] # if buggy
#print(self.selected)
if __name__ == '__main__' and True:
import bartender
if __name__ == '__main__' and False:
from aoc_game import Game
proc_name = "AoK HD.exe"
pm.load_process(proc_name)
game = Game()
game.update()