1
1
from django.db import models
4
if settings.USE_SPHINX:
5
from djangosphinx.models import SphinxSearch
7
4
class Tribe(models.Model):
8
5
name = models.CharField(max_length=100)
9
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)
17
return '%s' % self.name
12
20
class Worker(models.Model):
13
if settings.USE_SPHINX:
14
search = SphinxSearch(
22
22
name = models.CharField(max_length=100)
23
23
displayname = models.CharField(max_length=100)
24
24
tribe = models.ForeignKey(Tribe)
25
image_url = models.CharField( max_length=256 ) # URL to include this, i wasn't able to feed django local images
26
graph_url = models.CharField( max_length=256 ) # URL to the help graph
27
imagemap = models.TextField() # the image map for the help graph
29
help = models.TextField(max_length=256) # This limit shall probably cover the longest help (found 209, nothing more)
30
exp = models.TextField(max_length=8) # Just in case
31
becomes = models.OneToOneField('self', related_name="trained_by_experience", blank=True, null=True)
33
def __unicode__(self):
34
return u'%s' % self.name
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)
42
return '%s' % self.name
37
45
class Ware(models.Model):
38
46
name = models.CharField(max_length=100)
39
47
displayname = models.CharField(max_length=100)
40
48
tribe = models.ForeignKey(Tribe)
41
image_url = models.CharField( max_length=256 ) # URL to include this, i wasn't able to feed django local images
42
graph_url = models.CharField( max_length=256 ) # URL to the help graph
43
imagemap = models.TextField() # the image map for the help graph
45
help = models.TextField(max_length=256) # This limit shall probably cover the longest help (found 209, nothing more)
47
if settings.USE_SPHINX:
48
search = SphinxSearch(
57
def __unicode__(self):
58
return u'%s' % self.name
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)
63
return '%s' % self.name
61
66
class BuildingManager(models.Manager):
63
return self.all().filter(size="S")
69
return self.all().filter(size='S')
65
return self.all().filter(size="M")
72
return self.all().filter(size='M')
67
return self.all().filter(size="B")
75
return self.all().filter(size='B')
69
return self.all().filter(size="I")
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')
72
86
# return self.build_wares.count()
76
91
class Building(models.Model):
98
('H', 'headquarters'),
84
101
('P', 'productionsite'),
85
102
('W', 'warehouse'),
86
('M', 'military site'),
87
('T', 'trainings site'),
103
('M', 'militarysite'),
104
('T', 'trainingsite'),
90
108
objects = BuildingManager()
92
if settings.USE_SPHINX:
93
search = SphinxSearch(
102
110
name = models.CharField(max_length=100)
103
111
displayname = models.CharField(max_length=100)
104
112
tribe = models.ForeignKey(Tribe)
105
image_url = models.CharField( max_length=256 ) # URL to include this, i wasn't able to feed django local images
106
graph_url = models.CharField( max_length=256 ) # URL to the help graph
107
imagemap = models.TextField() # the image map for the help graph
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
109
size = models.CharField(max_length=1,choices=SIZES)
110
type = models.CharField( max_length=1, choices=TYPES) # productionsite...
118
size = models.CharField(max_length=1, choices=SIZES)
119
type = models.CharField(max_length=1, choices=TYPES) # productionsite...
112
121
help = models.TextField(blank=True)
115
enhancement = models.OneToOneField('self', related_name='enhanced_from', blank=True, null=True)
124
enhancement = models.OneToOneField(
125
'self', related_name='enhanced_from', blank=True, null=True)
118
build_wares = models.ManyToManyField(Ware, related_name="build_ware_for_buildings", blank=True)
119
build_costs = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
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)
122
workers_types = models.ManyToManyField(Worker, related_name="workers_for_buildings", blank=True)
123
workers_count = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
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)
126
store_wares = models.ManyToManyField(Ware, related_name="stored_ware_for_buildings", blank=True)
127
store_count = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
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)
130
output_wares = models.ManyToManyField(Ware, related_name="produced_by_buildings", blank=True)
131
output_workers = models.ManyToManyField(Worker, related_name="trained_by_buildings", 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)
133
155
def save(self, *args, **kwargs):
135
tdict = dict((b,a) for a,b in self.TYPES)
136
sdict = dict((b,a) for a,b in self.SIZES)
157
tdict = dict((b, a) for a, b in self.TYPES)
158
sdict = dict((b, a) for a, b in self.SIZES)
138
160
self.type = tdict.get(self.type, self.type)
139
161
self.size = sdict.get(self.size, self.size)
143
165
def has_build_cost(self):
144
166
return (self.build_wares.all().count() != 0)
145
168
def get_build_cost(self):
146
count = map(int,self.build_costs.split( ))
147
for c,w in zip(count,self.build_wares.all()):
169
# Creating the relation between build_cost and build_wares
170
# Querying the wares returns the wares in alphabetical order!
171
count = list(map(int, self.build_costs.split()))
172
for c, w in zip(count, self.build_wares.all()):
150
175
def has_workers(self):
151
176
return (self.workers_types.all().count() != 0)
152
178
def get_workers(self):
153
count = map(int,self.workers_count.split( ))
154
for c,wor in zip(count,self.workers_types.all()):
179
count = list(map(int, self.workers_count.split()))
180
for c, wor in zip(count, self.workers_types.all()):
157
183
def produces(self):
158
184
return (self.output_wares.all().count() != 0)
159
def get_outputs(self):
186
def get_ware_outputs(self):
160
187
return self.output_wares.all()
161
189
def trains(self):
162
190
return (self.output_workers.all().count() != 0)
163
192
def get_worker_outputs(self):
164
193
return self.output_workers.all()
165
195
def has_outputs(self):
166
196
return (self.output_workers.all().count() != 0 or self.output_wares.all().count() != 0)
168
198
def has_stored_wares(self):
169
199
return (self.store_wares.all().count() != 0)
170
201
def get_stored_wares(self):
171
count = map(int,self.store_count.split( ))
172
for c,w in zip(count,self.store_wares.all()):
176
def __unicode__(self):
177
return u"%s/%s" %(self.tribe.name,self.name)
202
count = list(map(int, self.store_count.split()))
203
for c, w in zip(count, self.store_wares.all()):
207
return "%s/%s" % (self.tribe.name, self.name)