30 lines
793 B
Python
30 lines
793 B
Python
from base_agent import BaseAgent
|
|
class AutoProductionAgent(BaseAgent):
|
|
"""
|
|
Automaticaly produces commodity if in business inventory
|
|
"""
|
|
|
|
|
|
def __init__(self,business) -> None:
|
|
super().__init__()
|
|
self.business=business
|
|
self.prod=business.production
|
|
|
|
|
|
|
|
def can_produce(self):
|
|
# If can produce item
|
|
for k,cost in self.prod.items():
|
|
if cost > self.business.inventory[k]:
|
|
return False
|
|
return True
|
|
|
|
def tick(self):
|
|
if not self.can_produce():
|
|
return
|
|
# remove cost from inventory
|
|
for k,cost in self.prod.items():
|
|
self.business.inventory[k]-=cost
|
|
# add commodity
|
|
self.business.inventory[self.prod['name']]+=self.prod["amount"]
|