コード例 #1
0
ファイル: btools.py プロジェクト: joskid/bellum
def order(request, pp):
    mum = getCurrentMother(request)
    slot = int(request.GET['slot'])

    otype, olvl = pp.getPair(slot)

    if otype == 0:
        return HttpResponse('ZEROSLOT')     # Cannot upgrade something that doesnt exist

    costs = getCosts(pp, getRace(request), olvl, otype)
    
    if pp.owner != getAccount(request):
        return HttpResponse('ACCOUNT')
    if costs[0] > getResourceIndex(request).stateUpdate():
        return HttpResponse('COSTS')
    if pp.getPendingBuildingsCount() > 0:
        return HttpResponse('QUEUE')

    note(request, LP_BUILD_ORDERED, pid=pp.province.id,
                                    slot=slot,
                                    what=otype,
                                    levelfrom=olvl)
    
    orderBuild(pp, mum, otype, slot, costs)
    return HttpResponse('OK')
コード例 #2
0
ファイル: ttools.py プロジェクト: joskid/bellum
def order(request):
    '''Starts a technology research.
            When:
                    Resources met
                    Not researching any other technology worldwide
                    Requirements met'''
                    
    mum = getCurrentMother(request)
    
    costs = getCosts(mum.owner.technology, getRace(request), int(request.GET['what'])) 
    
    if costs[0] > getResourceIndex(request).stateUpdate():
        return HttpResponse('COSTS')

    if int(request.GET['what']) == 12:            # supercomputer
        if getAccount(request).getPendingResearchesCount() > 0:
            return HttpResponse('QUEUE')
    else:
        if getAccount(request).getPendingResearchesCount() > mum.owner.technology.o_12:
            return HttpResponse('QUEUE')
        

    if not getRequirements(mum.owner.technology, getRace(request), int(request.GET['what'])).validate(mum):
        return HttpResponse('REQUIREMENTS')

    if not canAdvance(mum.owner.technology, getRace(request), int(request.GET['what'])):
        return HttpResponse('ADVANCE')

    note(request, LM_RESEARCH_ORDERED, mid=mum.id,
                                       what=int(request.GET['what']),
                                       levelfrom=mum.owner.technology.__dict__['o_'+request.GET['what']])
    
    orderResearch(mum, int(request.GET['what']), costs)
    return HttpResponse('OK')
コード例 #3
0
ファイル: latools.py プロジェクト: joskid/bellum
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')
コード例 #4
0
ファイル: btools.py プロジェクト: joskid/bellum
def order(request):    
    mum = getCurrentMother(request)
    
    costs = getCosts(mum, getRace(request), int(request.GET['what'])) 
    
    if costs[0] > getResourceIndex(request).stateUpdate():
        return HttpResponse('COSTS')
    if mum.getPendingConstructionsCount() > 0:
        return HttpResponse('QUEUE')
    if not getRequirements(mum, getRace(request), int(request.GET['what'])).validate(mum):
        return HttpResponse('REQUIREMENTS')   

    note(request, LM_CONSTRUCTION_ORDERED, mid=mum.id,
                                           what=int(request.GET['what']),
                                           levelfrom=mum.__dict__['b_'+request.GET['what']])
    
    orderConstruct(mum, int(request.GET['what']), costs)
    return HttpResponse('OK')
コード例 #5
0
ファイル: sendres.py プロジェクト: joskid/bellum
def process(request):
    try:
        titan = int(request.GET['titan'])
    except:
        titan = 0

    try:
        pluton = int(request.GET['pluton'])
    except:
        pluton = 0

    try:
        manpower = int(request.GET['men'])
    except:
        manpower = 0

    try:
        target = Account.objects.get(id=int(request.GET['target']))
    except:
        return HttpResponse('FAIL')

    my_mum = getCurrentMother(request)

    acc = getAccount(request)
    if acc == target: return HttpResponse('SELF')

    rindex = getResourceIndex(request)
    rindex.stateUpdate()

    sending_res = ResourceIndex(titan=titan, pluton=pluton, men=manpower)
    if (sending_res == 0): return HttpResponse('NULL')
    if (sending_res > rindex): return HttpResponse('TOOMUCH')

    tg_mother = Mother.objects.get(owner=target)
    note(request, LM_SENT_RESOURCE, mid=my_mum.id,
                                    target=tg_mother.id,
                                    resources=sending_res)

    orderResourceSend(my_mum, tg_mother, sending_res.titan, sending_res.pluton, sending_res.men)

    return HttpResponse('OK')
コード例 #6
0
ファイル: btools.py プロジェクト: joskid/bellum
def erect(request, pp):  
    mum = getCurrentMother(request)

    slot = None
    for i in xrange(0, pp.province.slots):
        if pp.getPair(i)[0] == 0:
            slot = i
            break
    if slot == None:
        return HttpResponse('NOFREESLOTS')

    what = int(request.GET['what'])

    otype, olvl = pp.getPair(slot)

    if otype != 0:
        return HttpResponse('NONZEROSLOT') # Can't build in occupied space

    costs = getCosts(pp, getRace(request), 0, what)

    if pp.owner != getAccount(request):
        return HttpResponse('ACCOUNT')
    if costs[0] > getResourceIndex(request).stateUpdate():
        return HttpResponse('COSTS')
    if pp.getPendingBuildingsCount() > 0:
        return HttpResponse('QUEUE')

    if (otype == 1) and (pp.province.titan_coef == 0):
        return HttpResponse('RSFAIL_TITAN')
    if (otype == 2) and (pp.province.pluton_coef == 0):
        return HttpResponse('RSFAIL_TITAN')
    if (otype == 3) and (pp.province.town_coef == 0):
        return HttpResponse('RSFAIL_TITAN')

    note(request, LP_BUILD_ORDERED, pid=pp.province.id,
                                    slot=slot,
                                    what=what,
                                    levelfrom=olvl)

    orderBuild(pp, mum, what, slot, costs)
    return HttpResponse('OK')
コード例 #7
0
ファイル: resource_mod.py プロジェクト: joskid/bellum
def plug_in(primaryguiobject):
    primaryguiobject.registerObject('resources', getResourceIndex(primaryguiobject._request).stateUpdate())