fuck man major readjustment but it is running again...

This commit is contained in:
2023-06-28 19:40:42 +02:00
parent b7dc7b99d1
commit 509c59bb88
25 changed files with 353 additions and 147 deletions

View File

@@ -5,7 +5,7 @@ class AutoProductionAgent(BaseAgent):
"""
def __init__(self,sim,business,worker=1,employment_rate=0) -> None:
def __init__(self,sim,business,worker=-1,employment_rate=0) -> None:
super().__init__(sim)
self.business=business
self.prod=business.production
@@ -13,32 +13,56 @@ class AutoProductionAgent(BaseAgent):
self.employment_rate=employment_rate
self.employment_index=worker
self.target=0
self.prod_counter=0
def set_worker(self,workers):
if workers>1:
self.worker=workers
elif workers==-1:
self.worker=-1
else:
self.worker=1
def set_target(self,qty):
self.target=qty
def can_produce(self):
# If can produce item
for com in self.prod["prod"]:
for k,v in com.items():
if v > self.business.inventory[k]:
return False
# how much can we produce
minprod=[]
for k,v in self.prod["prod"].items():
minprod.append(self.business.inventory[k]/v)
possibleProds=int(min(minprod))
return possibleProds*self.prod["amount"]
def should_produce(self):
# check if we should produce
if self.business.resource_in_possesion()>self.target:
return False
return True
if self.business.resource_in_possesion()>=self.target:
return 0
return self.can_produce()
def tick(self,step,epi):
for i in range(self.worker):
if not self.can_produce():
continue
can=self.should_produce()
if can==0:
return
run=True
i=self.worker
while run:
if self.should_produce()==0:
return
if i==0:
return
# remove cost from inventory
for com in self.prod["prod"]:
for k,cost in com.items():
self.business.inventory[k]-=cost
for k,cost in self.prod["prod"].items():
self.business.inventory[k]-=cost
# add commodity
self.business.inventory[self.prod['name']]+=self.prod["amount"]
self.prod_counter+=1
i-=1
def reset_qty(self):
self.prod_counter=0
def qty(self):
return self.prod_counter