This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
aoc_object_building_research.py
65 lines (56 loc) · 2.1 KB
/
aoc_object_building_research.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" aoc_object_building_research.py: checks building research """
from math import isnan
from pymemory import NullAddress
from pymemory import pymemory as pm
class BuildingResearch(object):
""" Building researches
Attributes
Public
building `Buidling` structure
id ID of research
time The time spend researching
total_time Time required for research
cooldown Remaining time
icon Research icon ID
Methods
Public
__init__(building) Constructor
create() Returns None or self with filled attributes.
How to use this
r = Training(building).create()
if r:
print(r.icon, r.id, r.cooldown)
"""
def __init__(self, building):
super(BuildingResearch, self).__init__()
self.building = building
self.id = -1
self.icon = 0
self.time = 0
self.total_time = 0
self.cooldown = 0
def create(self): # some kind of constructor.. returns None if none research
try:
ptr = pm.pointer(self.building.ptr + 0x1f0)
ptr = pm.pointer(ptr + 0x8)
ptr = pm.pointer(ptr)
self.id = pm.int16(ptr + 0x40)
if self.id > 800:
return None
ptr = pm.pointer(self.building.owner.ptr + 0x1ae8)
time = pm.float(pm.pointer(ptr) + 16 * self.id)
ptr = pm.pointer(pm.pointer(ptr + 8))
except NullAddress:
return None
self.building.owner.research.add(self.id)
self.total_time = pm.int16(ptr + 0x54 * self.id + 0x26)
self.icon = pm.int16(ptr + 0x54 * self.id + 0x2C)
self.time = self.total_time if isnan(time) else time # NaN occurs in the end of the research
self.cooldown = int(self.total_time - self.time)
# if ptr not in BuildingResearch.log[self.building.owner]:
# BuildingResearch.log[self.building.owner].append(self)
return self
if __name__ == '__main__':
pass