1
from django.db import models
4
class Tribe(models.Model):
5
name = models.CharField(max_length=100)
6
displayname = models.CharField(max_length=100)
7
descr = models.TextField()
8
icon_url = models.CharField(max_length=256)
9
network_pdf_url = models.CharField(max_length=256)
10
network_gif_url = models.CharField(max_length=256)
16
def __unicode__(self):
17
return u'%s' % self.name
20
class Worker(models.Model):
22
name = models.CharField(max_length=100)
23
displayname = models.CharField(max_length=100)
24
tribe = models.ForeignKey(Tribe)
25
# URL to include this, i wasn't able to feed django local images
26
image_url = models.CharField(max_length=256)
27
graph_url = models.CharField(max_length=256) # URL to the help graph
28
imagemap = models.TextField() # the image map for the help graph
30
# This limit shall probably cover the longest help (found 209, nothing
32
help = models.TextField(max_length=256)
33
exp = models.TextField(max_length=8) # Just in case
34
becomes = models.OneToOneField(
35
'self', related_name='trained_by_experience', blank=True, null=True)
41
def __unicode__(self):
42
return u'%s' % self.name
45
class Ware(models.Model):
46
name = models.CharField(max_length=100)
47
displayname = models.CharField(max_length=100)
48
tribe = models.ForeignKey(Tribe)
49
# URL to include this, i wasn't able to feed django local images
50
image_url = models.CharField(max_length=256)
51
graph_url = models.CharField(max_length=256) # URL to the help graph
52
imagemap = models.TextField() # the image map for the help graph
54
# This limit shall probably cover the longest help (found 209, nothing
56
help = models.TextField(max_length=256)
62
def __unicode__(self):
63
return u'%s' % self.name
66
class BuildingManager(models.Manager):
69
return self.all().filter(size='S')
72
return self.all().filter(size='M')
75
return self.all().filter(size='B')
78
return self.all().filter(size='I')
81
return self.all().filter(size='P')
83
def headquarters(self):
84
return self.all().filter(size='H')
86
# return self.build_wares.count()
91
class Building(models.Model):
98
('H', 'headquarters'),
101
('P', 'productionsite'),
103
('M', 'militarysite'),
104
('T', 'trainingsite'),
108
objects = BuildingManager()
110
name = models.CharField(max_length=100)
111
displayname = models.CharField(max_length=100)
112
tribe = models.ForeignKey(Tribe)
113
# URL to include this, i wasn't able to feed django local images
114
image_url = models.CharField(max_length=256)
115
graph_url = models.CharField(max_length=256) # URL to the help graph
116
imagemap = models.TextField() # the image map for the help graph
118
size = models.CharField(max_length=1, choices=SIZES)
119
type = models.CharField(max_length=1, choices=TYPES) # productionsite...
121
help = models.TextField(blank=True)
124
enhancement = models.OneToOneField(
125
'self', related_name='enhanced_from', blank=True, null=True)
128
build_wares = models.ManyToManyField(
129
Ware, related_name='build_ware_for_buildings', blank=True)
130
# ' '.joined() integer strings
131
build_costs = models.CharField(max_length=100, blank=True)
134
workers_types = models.ManyToManyField(
135
Worker, related_name='workers_for_buildings', blank=True)
136
# ' '.joined() integer strings
137
workers_count = models.CharField(max_length=100, blank=True)
140
store_wares = models.ManyToManyField(
141
Ware, related_name='stored_ware_for_buildings', blank=True)
142
# ' '.joined() integer strings
143
store_count = models.CharField(max_length=100, blank=True)
146
output_wares = models.ManyToManyField(
147
Ware, related_name='produced_by_buildings', blank=True)
148
output_workers = models.ManyToManyField(
149
Worker, related_name='trained_by_buildings', blank=True)
155
def save(self, *args, **kwargs):
157
tdict = dict((b, a) for a, b in self.TYPES)
158
sdict = dict((b, a) for a, b in self.SIZES)
160
self.type = tdict.get(self.type, self.type)
161
self.size = sdict.get(self.size, self.size)
163
return models.Model.save(self, *args, **kwargs)
165
def has_build_cost(self):
166
return (self.build_wares.all().count() != 0)
168
def get_build_cost(self):
169
# Creating the relation between build_cost and build_wares
170
# Querying the wares returns the wares in alphabetical order!
171
count = map(int, self.build_costs.split())
172
for c, w in zip(count, self.build_wares.all()):
175
def has_workers(self):
176
return (self.workers_types.all().count() != 0)
178
def get_workers(self):
179
count = map(int, self.workers_count.split())
180
for c, wor in zip(count, self.workers_types.all()):
184
return (self.output_wares.all().count() != 0)
186
def get_ware_outputs(self):
187
return self.output_wares.all()
190
return (self.output_workers.all().count() != 0)
192
def get_worker_outputs(self):
193
return self.output_workers.all()
195
def has_outputs(self):
196
return (self.output_workers.all().count() != 0 or self.output_wares.all().count() != 0)
198
def has_stored_wares(self):
199
return (self.store_wares.all().count() != 0)
201
def get_stored_wares(self):
202
count = map(int, self.store_count.split())
203
for c, w in zip(count, self.store_wares.all()):
206
def __unicode__(self):
207
return u"%s/%s" % (self.tribe.name, self.name)