def order(request): '''Starts building land army units When: Resources met Requirements met''' mum = getCurrentMother(request) # Python will HTTP 500 on invalid GET data costs = getCosts(mum, getRace(request), int(request.GET['what'])) if not (int(request.GET['what']) in range(0,MGID+1)): return HttpResponse('WHATINVALID') if int(request.GET['amount']) < 1: return HttpResponse('INVALIDAMOUNT') if costs[0]*int(request.GET['amount']) > getResourceIndex(request).stateUpdate(): return HttpResponse('COSTS') if not getRequirements(mum, getRace(request), int(request.GET['what'])): return HttpResponse('REQUIREMENTS') note(request, LM_LANDARMY_TRAINING, mid=mum.id, what=int(request.GET['what']), amount=int(request.GET['amount'])) orderProduce(mum, getRace(request), int(request.GET['what']), int(request.GET['amount'])) return HttpResponse('OK')
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 land(request): mum = getCurrentMother(request) lpos = LandarmyProduceOrder.objects.filter(mother=mum.id).order_by('got__ordered_on') garn = {} for x in xrange(0, MGID+1): garn[x] = {} garn[x]['has'] = mum.garrison[x] garn[x]['creq'] = getRequirements(mum, getRace(request), x) garn[x]['req'] = garn[x]['creq'].validate(mum) garn[x]['cost'], garn[x]['time'] = getCosts(mum, getRace(request), x) return render_to_response('mother/garrison/land.html', {'mother':mum, 'garn':garn, 'lpos':lpos, 'pgo':PrimaryGUIObject(request, mum)})