-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanet.py
More file actions
79 lines (66 loc) · 2.9 KB
/
Copy pathplanet.py
File metadata and controls
79 lines (66 loc) · 2.9 KB
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
from vector import Vector as Vec
from map_on_planet import MapOnPlanet
from buildings import (Farm, Building, Mine, CoalGenerator, WindGenerator,
NuclearGenerator, RobotProduction, SpaceshipProduction)
class Planet():
def __init__(self, pos, id, size):
print('LOADING: planet: generate', id)
self.id = id
self.pos = Vec(pos)
self.owner = None
self.resources = {'energy':0, 'steel':0, 'food':0,
'coal':0, 'uranium':0, 'people':0,
'robots':0, 'spaceships':0}
self.buildings = [
Farm, Building, Mine, CoalGenerator, WindGenerator,
NuclearGenerator, RobotProduction, SpaceshipProduction
]
self.satellites = {}
self.size = size
self.map_ = MapOnPlanet(size)
#self.build_building(self.owner, Vec((0, 0)), Farm)
#print(self.map_)
def get_defence(self):
defence = 0
if self.resources['robots'] >= self.resources['energy']:
defence += self.resources['energy']
else:
defence += self.resources['robots']
defence += round(self.resources['people']*1.25)
#add here builidng defence
return defence
def to_start_planet(self, new_owner):
self.owner = new_owner
def turn_start(self, player):
if not (self.owner == player):
return
self.map_.turn_start(self.resources)
def attack(self, obj):
robots = self.resources['robots']
people = self.resources['people']
if self.get_defence() < 1:
damage = 1000
else:
damage = obj.get_attack() / self.get_defence()
if self.owner and self.owner.name == 'fred':
print('player attack', obj.people, people, self.pos, damage)
if self.get_defence() >= obj.get_attack():
people = round(people*(1-damage))
robots = round(robots*(1-damage))
else: #capture!
people = obj.people
robots = obj.robots
self.owner = obj.owner
self.resources['robots'] = robots
self.resources['people'] = people
def __repr__(self):
return '<Planet: id:{},pos:{},people:{},owner:{}>'.format(
self.id, self.pos, self.people, self.owner)
def build_building(self, player, pos, building_class):
print('planet: check buildable:',
'player == self.owner and building_class in self.buildings',
player == self.owner, building_class in self.buildings)
print('planet: playercheck:', id(player), id(self.owner))
if player == self.owner and building_class in self.buildings:
print('planet: build', building_class)
self.map_.build_building(pos, building_class, self.resources)