Exemplo n.º 1
0
def whatToDo(account, target_province, designation):

    if designation == 0: designation = 1    # because heading back for all intents counts as Attack/Reinforce

    try:
        target_province.presence
    except:
        is_occupied = False
    else:
        is_occupied = True


    if designation == 5:        # debug
        return 'FALLBACK'

    if not is_occupied:
        return 'ASSAULT'

    if designation == 4:
            return 'REINFORCE'

    if target_province.presence.owner == account:
        return 'REINFORCE'

    if designation == 2:
        return 'ASSAULT'

    if designation == 1:
        if isAllied(account, target_province.presence.owner):
            return 'REINFORCE'
        else:
            return 'ASSAULT'

    if designation == 3:
        if isAllied(account, target_province.presence.owner):
            return 'REINFORCE'
        else:
            return 'FALLBACK'

    raise Exception, 'Unexpected designation: '+str(designation)
    
Exemplo n.º 2
0
def p_plm(request, planet, highlight_preference=None):
    '''Generate planet map
    highlight preference is a province instance'''
    allegiance_tab = {}
    for province in planet.province_set.all():
        # 0 - MINE, 1 - ENEMY, 2 - ALLIED, 3 - NOBODYS
        try:
            province.provintionalpresence
        except:
           allegiance_tab[province.id] = 'gray'
        else:
            if province.provintionalpresence.owner == getAccount(request):
                allegiance_tab[province.id] = 'green'
            elif isAllied(getAccount(request), province.provintionalpresence.owner):
                allegiance_tab[province.id] = 'blue'
            else:
                allegiance_tab[province.id] = 'red'

    x = render_to_string('space/troopmove/generator/pla.html', {'planet':planet,
                                                                'wctg':lambda x: int((x+100.0)*(345.0/200.0)),
                                                                'allegiance_strings':allegiance_tab,
                                                                'highlight_preference':highlight_preference})
    return x
Exemplo n.º 3
0
def process(request, planet_id, province_id=None):
    try:    # check planet
        planet = Planet.objects.get(id=planet_id)
    except:
        return redirect('/')

    provinces = Province.objects.filter(planet=planet)
    provinces_postprocessed = {}
    prov = None

    try:    # faciliates GET getting province to zoom onto
        if province_id != None:
            provgrabber = province_id
        else:
            provgrabber = int(request.GET['province'])
    except:
        provgrabber = None

    for province in provinces:
            # 0 - MINE, 1 - ENEMY, 2 - ALLIED, 3 - NOBODYS
        try:
            province.provintionalpresence
        except:
            pv = 'gray'
        else:
            if province.provintionalpresence.owner == getAccount(request):
                pv = 'green'
            elif isAllied(getAccount(request), province.provintionalpresence.owner):
                pv = 'blue'
            else:
                pv = 'red'

        provinces_postprocessed[province.id] = [pv, False]

        if province.id == provgrabber:
            prov = province

        try:
            if province.provintionalpresence.owner == getAccount(request):
                if prov == None:
                       prov = province
        except:
            pass

    if prov == None:
        prov = provinces[0]

    provinces_postprocessed[prov.id][1] = True
    mum = getCurrentMother(request)

    sfx = dx_html(request, prov, mum).decode('utf8')

    # can relocate?
    can_relocate = False
    relocation_time = None
    if (planet != mum.duePosition()):   # Different position than current
        can_relocate = mum.canRelocate()
        if can_relocate:
            relocation_time = getRelocationTime(mum, getRace(request), mum.orbiting, planet)

    # can scan?
    can_scan = False
    if getRace(request) == 1:
        if mum.isRelocating() == False:
            if mum.orbiting == planet:
                can_scan = True
        

    return render_to_response('space/planetview/planetview.html', {'htmldata':sfx,
                                                                   'race':getRace(request),
                                                                   'planet':planet,
                                                                   'postprocessed':provinces_postprocessed,
                                                                   'can_scan':can_scan,
                                                                   'firstprovince':prov,
                                                                   'can_relocate':can_relocate,
                                                                   'relocation_time':relocation_time,
                                                                   'wctg':lambda x: int((x+100.0)*(345.0/200.0)),
                                                                   'pgo':PrimaryGUIObject(request)})
Exemplo n.º 4
0
def process(request):
    mother = getCurrentMother(request)              # The most basic issues
    account = getAccount(request)

    try:                                            # Alliance issues
        alliance = AllianceMembership.objects.get(account=account)
    except ObjectDoesNotExist:
        alliance = None


    presences = ProvintionalPresence.objects.filter(owner=account)  # Get all my provinces

    # Get all build orders on those
    province_builds = ProvinceBuildOrder.objects.filter(ppresence__in=presences)

    planets = []                        # Get raw planets handle, will be useful in counting them
    provinces = []                      # BTW, get province handles.
    for presence in presences:
        if not presence.province.planet in planets: planets.append(presence.province.planet)
        provinces.append(presence.province)
        # Provinces table is needed down there for some freaky shit concerning troops.
        # I'm quite sure those provinces thingy could be fixed by some annotation shit, but it would
        # utterly and terribly confuse me, and affect code readability

                                        # Get researches/builds on my mother
    researches = TechnologyResearchOrder.objects.filter(mother=mother)
    builds = MotherConstructionOrder.objects.filter(mother=mother)
    
                                        # Get troop building queues
    troop_training = LandarmyProduceOrder.objects.filter(mother=mother).order_by('-got__to_be_completed')
                                        # Calculate number of troops in training
    x = troop_training.aggregate(amount=Sum('amount'))['amount']
    if x == None:
        queued_troop_count = 0
    else:
        queued_troop_count = x

                                        # Rock'n'roll here!
                        # Get my outbound salads
    outbound_salad = ResourceSendOrder.objects.filter(send_from=mother)
    inbound_salad = ResourceSendOrder.objects.filter(send_to=mother)
    
    my_outbounds = LandarmyProvintionalStrikeOrder.objects.filter(attacker=account)
        # Select movements TOWARDS MY PROVINCES [supplied by a province list] which are NOT MINE
    inbounds_concerning_me = LandarmyProvintionalStrikeOrder.objects.filter(dstprovince__in=provinces).exclude(attacker=account)
    my_strikes = LandarmyPlanetaryStrikeOrder.objects.filter(mother=mother)
    strikes_concerning_me = LandarmyPlanetaryStrikeOrder.objects.filter(province__in=provinces).exclude(mother__owner=account)
    evacs = LandarmyMotherPickupOrder.objects.filter(mother=mother)
    # Sorry sad statemento follows.
    # This view, by the virtue of it's existence, f***s the database without any contraception.
    # And she will be hurt.

    # I will get back to optimizing this some other time.

    # I promise.
    # TODO: Optimize this view

    allegiance_tab = {}
    for planet in planets:
        for province in planet.province_set.all():
            # 0 - MINE, 1 - ENEMY, 2 - ALLIED, 3 - NOBODYS
            try:
                province.presence
            except:
               allegiance_tab[province.id] = 3
            else:
                # get allegiance
                if province.presence.owner == getAccount(request):
                    allegiance_tab[province.id] = 0
                elif isAllied(getAccount(request), province.presence.owner):
                    allegiance_tab[province.id] = 2
                else:
                    allegiance_tab[province.id] = 1

    if alliance == None:  # alliance is a presence object
        alliance_o = None
    else:
        alliance_o = alliance.alliance # true Alliance object

    try:        # Get alliance ranking
        alliance_ranking = RankingAlliance.objects.get(alliance=alliance_o)
    except:
        alliance_ranking = None

    try:
        player_ranking = RankingNone.objects.get(account=getAccount(request))
    except:
        player_ranking = None
    

    return render_to_response('stats/empire/empire.html',{'pgo':PrimaryGUIObject(request),
                                                          'alliance_m':alliance,
                                                          'alliance_ranking':alliance_ranking,
                                                          'player_ranking':player_ranking,
                                                          'alliance':alliance_o,
                                                          'race':getRace(request),
                                                          'mother':mother,
                                                          'account':account,
                                                          'province_count':presences.count(),
                                                          'planet_count':len(planets),
                                                          'queued_troop_count':queued_troop_count,
                                                          'troop_count':0,
                                                          'troops_training':troop_training,
                                                          'outbound_salad':outbound_salad,
                                                          'inbound_salad':inbound_salad,
                                                          'researches':researches,
                                                          'mother_builds':builds,
                                                          'prov_outbounds':my_outbounds,
                                                          'prov_inbounds':inbounds_concerning_me,
                                                          'prov_builds':province_builds,
                                                          'mother_inbounds':my_strikes,
                                                          'foreign_mother_inbounds':strikes_concerning_me,
                                                          'my_evacs':evacs,
                                                          'mother_name':mother.name,
                                                          'planets':planets,
                                                          'allegiance_tab':allegiance_tab,
                                                          })