- Jul 20, 2018
- 653
- 1,129
So I have a building function to build new stuff and a different function to have a timer run out before the space is available.
I made a little test screen to build stuff and notice that if I use the function several times in a row it will trigger correctly (as I see the space available decrease) but it is a guess if eventually all buildings actually show up. (e.g. if I build 10 cabinet offices 5-8 are actually build eventually). Now I don't know yet how often players will run into this issue but it seems wise to prevent the issue in the first place. This happens both if I use it 5 times in a row or wait for the maintenance function to trigger in between.
P.s. I know the code is not the most amazing as I should probably parent the commenhandlerclass but this way I understand what I'm doing...
All relevant code (I think):
I made a little test screen to build stuff and notice that if I use the function several times in a row it will trigger correctly (as I see the space available decrease) but it is a guess if eventually all buildings actually show up. (e.g. if I build 10 cabinet offices 5-8 are actually build eventually). Now I don't know yet how often players will run into this issue but it seems wise to prevent the issue in the first place. This happens both if I use it 5 times in a row or wait for the maintenance function to trigger in between.
P.s. I know the code is not the most amazing as I should probably parent the commenhandlerclass but this way I understand what I'm doing...
All relevant code (I think):
Python:
init python:
#the building function does the building the maintenance is triggered once per day.
class commonhandlerclass:
def building(self, OID, amount, what, remove=False): #building new buildings/offices/classrooms etc
if what == None:
if remove == False:
globals()[OID].money -= globals()[OID].space['unallocated']['icps'] * amount * globals()[OID].mod['constructioncost']
globals()[OID].store['timers']['building'].append(('unallocated',globals()[OID].space['unallocated']['T'],amount))
else:
globals()[OID].money = globals()[OID].base['removalcost'] * amount * globals()[OID].mod['constructioncost'] * 10
globals()[OID].space['unallocated']['total'] -= amount
else:
if remove == False:
size = globals()[OID].space[what]['size'] * amount
cost = globals()[OID].space[what]['icps'] * size * globals()[OID].mod['constructioncost']
if globals()[OID].space['unallocated']['total'] >= size:
globals()[OID].space['unallocated']['total'] -= size
globals()[OID].money -= cost
globals()[OID].store['timers']['building'].append((what, globals()[OID].space[what]['T'],amount))
else:
size = globals()[OID].space[what]['size'] * amount
cost = globals()[OID].base['removalcost'] * size * globals()[OID].mod['constructioncost']
globals()[OID].space['unallocated']['total'] += size
globals()[OID].space[what]['total'] -= amount
globals()[OID].money -= cost
def transfer(self, OID, tuple): #transfering money/buildingspace/ etc
pass
def maintenance(self, OID):
temp = []
for i in globals()[OID].store['timers']['building']:
if i[1] <= 0:
globals()[OID].space[i[0]]['total'] += i[2]
globals()[OID].store['timers']['building'].remove(i)
else:
temp.append((i[0],i[1]-1,i[2]))
globals()[OID].store['timers']['building'] = temp
class campusclass: #population = students + workers
def __init__(self, OID='campus', name='Turner University', money=250, corruption=0, prestige=-1000, space={}, base={}, mod={}, store={}, stats={}):
self.OID = OID
self.name = name
self.money = money
self.corruption = corruption
self.prestige = prestige
self.space = space
self.base = base
self.mod = mod
self.store = store
self.stats = stats
if not 'timers' in store: store['timers'] = {'building':[]}
if not 'constructioncost' in mod: mod['constructioncost']= 1
if not 'total' in space: space['total'] = 0
if not 'unallocated' in space: space['unallocated'] = {'total':0, 'T':15,'icps':1500, 'ccps':1.0}
if not 'cabinetoffice' in space: space['cabinetoffice'] = {'total':0, 'seats':1, 'size':10, 'T':2, 'icps':1000.0, 'ccps':10.0, 'ccpo':10.0, 'pop':'cabinet', 'demand':1.0} #cost per size vs cost per occupant negative numbers give income.
if not 'supportoffice' in space: space['supportoffice'] = {'total':0, 'seats':5, 'size':25, 'T':3, 'icps':100.0, 'ccps':1.5, 'ccpo':1.0, 'pop':'admin', 'demand':1.0} #pop means who uses this, demand is how likely to use/want this. If demand is not met happiness will drop
if not 'toilet' in space: space['toilet'] = {'total':0, 'seats':9, 'size':10, 'T':5, 'icps':200.0, 'ccps':2.5, 'ccpo':5.0, 'pop':'population', 'demand':0.063}
if not 'storage' in space: space['storage'] = {'total':0, 'seats':2, 'size':10, 'T':1, 'icps':20.0, 'ccps':1.1, 'ccpo':1.0, 'pop':'janitor', 'demand':1.0} #150m2 per hour 1200m2 per shift
def EOD(self):
commonhandler.maintenance(self.OID)
screen TSTbuildSCR():
$renpy.retain_after_load()
$unallocated = globals()['campus'].space['unallocated']['total']
$CO = globals()['campus'].space['cabinetoffice']['total']
$SO = globals()['campus'].space['supportoffice']['total']
vbox:
hbox:
text "you currently have [CO] cabinetoffices and [SO] supportoffices. there is [unallocated] space left"
hbox:
button:
action Function(globals()['commonhandler'].building, 'campus', 200, None)
text 'build 200m2 of building space.'
hbox:
button:
action Function(globals()['commonhandler'].building, 'campus', 1, 'cabinetoffice')
text 'build a cabinetoffice'
hbox:
button:
action Function(globals()['commonhandler'].building, 'campus', 5, 'supportoffice')
text 'build 5 supportoffices'
hbox:
button:
action ToggleScreen("TSTbuildSCR"), ToggleScreen('TSToverlaySCR')
text 'back'
Last edited: