4
4
if settings.USE_SPHINX:
5
from djangosphinx.models import SphinxSearch
5
from djangosphinx import SphinxSearch
7
7
class Tribe(models.Model):
8
8
name = models.CharField(max_length=100)
9
9
displayname = models.CharField(max_length=100)
12
class Worker(models.Model):
13
if settings.USE_SPHINX:
14
search = SphinxSearch(
22
name = models.CharField(max_length=100)
23
displayname = models.CharField(max_length=100)
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
37
12
class Ware(models.Model):
38
13
name = models.CharField(max_length=100)
39
14
displayname = models.CharField(max_length=100)
40
15
tribe = models.ForeignKey(Tribe)
41
16
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
18
help = models.TextField(max_length=256) # This limit shall probably cover the longest help (found 209, nothing more)
47
20
if settings.USE_SPHINX:
48
21
search = SphinxSearch(
103
76
displayname = models.CharField(max_length=100)
104
77
tribe = models.ForeignKey(Tribe)
105
78
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
109
80
size = models.CharField(max_length=1,choices=SIZES)
110
81
type = models.CharField( max_length=1, choices=TYPES) # productionsite...
112
83
help = models.TextField(blank=True)
115
enhancement = models.OneToOneField('self', related_name='enhanced_from', blank=True, null=True)
86
enhancement = models.OneToOneField('self',related_name='enhanced_from', blank=True, null=True)
118
89
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
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
90
build_costs = models.CharField(max_length=100,blank=True) # ' '.joined() integer strings
126
store_wares = models.ManyToManyField(Ware, related_name="stored_ware_for_buildings", blank=True)
93
store_wares = models.ManyToManyField(Ware, related_name="stored_ware_for_buildings",blank=True)
127
94
store_count = models.CharField(max_length=100, blank=True) # ' '.joined() integer strings
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)
133
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)
138
self.type = tdict.get(self.type, self.type)
139
self.size = sdict.get(self.size, self.size)
141
return models.Model.save(self, *args, **kwargs)
97
output_wares = models.ManyToManyField(Ware, related_name="produced_by_buildings",blank=True)
143
99
def has_build_cost(self):
144
100
return (self.build_wares.all().count() != 0)
146
102
count = map(int,self.build_costs.split( ))
147
103
for c,w in zip(count,self.build_wares.all()):
150
def has_workers(self):
151
return (self.workers_types.all().count() != 0)
152
def get_workers(self):
153
count = map(int,self.workers_count.split( ))
154
for c,wor in zip(count,self.workers_types.all()):
157
106
def produces(self):
158
107
return (self.output_wares.all().count() != 0)
159
108
def get_outputs(self):
160
109
return self.output_wares.all()
162
return (self.output_workers.all().count() != 0)
163
def get_worker_outputs(self):
164
return self.output_workers.all()
165
def has_outputs(self):
166
return (self.output_workers.all().count() != 0 or self.output_wares.all().count() != 0)
168
111
def has_stored_wares(self):
169
112
return (self.store_wares.all().count() != 0)
170
113
def get_stored_wares(self):