45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
from .base_agent import BaseAgent
|
|
class AutoProductionAgent(BaseAgent):
|
|
"""
|
|
Automaticaly produces commodity if in business inventory
|
|
"""
|
|
|
|
|
|
def __init__(self,sim,business,worker=1,employment_rate=0) -> None:
|
|
super().__init__(sim)
|
|
self.business=business
|
|
self.prod=business.production
|
|
self.worker=worker
|
|
self.employment_rate=employment_rate
|
|
self.employment_index=worker
|
|
self.target=0
|
|
|
|
def set_worker(self,workers):
|
|
if workers>1:
|
|
self.worker=workers
|
|
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
|
|
# check if we should produce
|
|
if self.business.resource_in_possesion()>self.target:
|
|
return False
|
|
return True
|
|
|
|
def tick(self,step,epi):
|
|
for i in range(self.worker):
|
|
if not self.can_produce():
|
|
continue
|
|
# remove cost from inventory
|
|
for com in self.prod["prod"]:
|
|
for k,cost in com.items():
|
|
self.business.inventory[k]-=cost
|
|
# add commodity
|
|
self.business.inventory[self.prod['name']]+=self.prod["amount"]
|