def orderProduce(mother, race, what, amount): '''orders a production. Costs are expected to be an tuple with: unbound bellum.common.models.ResourceIndex instance integer item representing build length in seconds''' mother.owner.resources.stateUpdate() cost_res, ctime = getCosts(mother, race, what) cost_res *= amount mother.owner.resources -= cost_res mother.owner.resources.save() note(mother.owner.id, cost_res, 'landarmy') try: lpmax = LandarmyProduceOrder.objects.filter(mother=mother.id).order_by('-got__ordered_on')[0] except: subfox = datetime.now() else: subfox = lpmax.got.ordered_on + timedelta(0, lpmax.maketime * lpmax.amount) got = GenericOrderTable(None, subfox + timedelta(0, ctime), subfox, 5) got.save() lpo = LandarmyProduceOrder(None, got.id, mother.id, what, amount, ctime ) lpo.save()
def orderRelocate(mother, race, target_planet): now = time() relTime = getRelocationTime(mother, race, mother.orbiting, target_planet) completion = now + relTime got = GenericOrderTable(None, datetime.fromtimestamp(completion), datetime.fromtimestamp(now), 0) got.save() mro = MotherRelocationOrder(None, got.id, mother.orbiting.id, target_planet.id, mother.id) mro.save()
def orderBuild(ppresence, mother, what, slot, costs): mother.owner.resources.stateUpdate() mother.owner.resources -= costs[0] mother.owner.resources.save() note(mother.owner.id, costs[0], 'province') willFinish = datetime.fromtimestamp(int(costs[1] + time())) got = GenericOrderTable(None, willFinish, datetime.now(), 3) got.save() mbo = ProvinceBuildOrder(None, got.id, ppresence.id, what, slot, ) mbo.save()
def orderMotherPickup(presence, garrison, mother, race=None): presence.garrison -= garrison presence.garrison.save() garrison.save() willFinish = datetime.fromtimestamp(int(pmmovelen(presence.province, mother, garrison, race=race) + time())) got = GenericOrderTable(None, willFinish, datetime.now(), 8) got.save() lmpo = LandarmyMotherPickupOrder(None, got.id, mother.id, presence.province.id, garrison.id) lmpo.save()
def orderResourceSend(mother_from, mother_to, titan, pluton, men): '''orders a resource send''' got = GenericOrderTable(None, datetime.now()+timedelta(0, getResourceTravelTime(mother_from, mother_to)), datetime.now(), 4) got.save() mbo = ResourceSendOrder(None, got.id, titan, pluton, men, mother_to.id, mother_from.id) mbo.save() rindex = mother_from.owner.resources rindex -= ResourceIndex(titan=titan, pluton=pluton, men=men) rindex.save() note(mother_from.owner.id, ResourceIndex(titan=titan, pluton=pluton, men=men), 'sent')
def orderPlanetaryStrike(garrison, mother, province, designation, orders, race=None): mother.garrison -= garrison mother.garrison.save() garrison.save() willFinish = datetime.fromtimestamp(int(mpstrikelen(mother, province, garrison, orders, race=race) + time())) got = GenericOrderTable(None, willFinish, datetime.now(), 6) got.save() lpso = LandarmyPlanetaryStrikeOrder(None, got.id, mother.id, province.id, garrison.id, designation, orders) lpso.save()
def orderConstruct(mother, what, costs): '''orders a build. Costs are expected to be an tuple with: unbound bellum.common.models.ResourceIndex instance integer item representing build length in seconds''' mother.owner.resources.stateUpdate() mother.owner.resources -= costs[0] mother.owner.resources.save() note(mother.owner.id, costs[0], 'mother') willFinish = datetime.fromtimestamp(int(costs[1] + time())) got = GenericOrderTable(None, willFinish, datetime.now(), 1) got.save() mbo = MotherConstructionOrder(None, got.id, what, mother.id ) mbo.save()
def orderProvintionalStrike(garrison, src_prov, dst_prov, designation, orders, race=None): pugs = src_prov.presence.garrison pugs -= garrison pugs.save() garrison.save() willFinish = datetime.fromtimestamp(int(ppstrikelen(src_prov, dst_prov, garrison, orders, race=race) + time())) got = GenericOrderTable(None, willFinish, datetime.now(), 7) got.save() lpso = LandarmyProvintionalStrikeOrder(None, got.id, src_prov.presence.owner.id, src_prov.id, dst_prov.id, garrison.id, designation, orders) lpso.save()
def orderReinforcementsPickup(presence, garrison, mother, reinforcement, race=None): reinforcement.garrison -= garrison if reinforcement.garrison.isZero(): reinforcement.garrison.delete() reinforcement.delete() else: reinforcement.garrison.save() garrison.save() willFinish = datetime.fromtimestamp(int(pmmovelen(presence.province, mother, garrison, race=race) + time())) got = GenericOrderTable(None, willFinish, datetime.now(), 8) got.save() lmpo = LandarmyMotherPickupOrder(None, got.id, mother.id, presence.province.id, garrison.id) lmpo.save()