Esempio n. 1
0
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()
Esempio n. 2
0
def doResourceSendOrder(entry):
    mob = ResourceSendOrder.objects.get(got=entry)
    rsTuple = ResourceIndex(titan=mob.titan, pluton=mob.pluton, men=mob.men)
    
    targetResourceIndex = mob.send_to.owner.resources
    targetResourceIndex += rsTuple
    
    targetResourceIndex.save()

    note(None, LM_RCVD_RESOURCE, mfrom=mob.send_from,
                                 target=mob.send_to,
                                 resources=rsTuple)
    
    mob.delete()
Esempio n. 3
0
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()
Esempio n. 4
0
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')
Esempio n. 5
0
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()