Cracking the Terrority Control Code

Incomplete code that isn't ready for use.
35 posts Page 2 of 3
SeriousSimFR
Mapper
Mapper
Posts: 14
Joined: Fri Nov 09, 2012 4:17 pm


This looks great ! I've been looking forward a way to customise the TC tents locations, you guys rock. The only thing that could make this even better would be to be able to choose the tent you'd like to respawn on death.
Ki11aWi11
Mapper
Mapper
Posts: 106
Joined: Tue Nov 20, 2012 12:39 am


I'm having trouble with understanding what I need to do, I've basically gone into tow.py and basically pasted this on top of the old def get_cp_entities(self):
Code: Select all
      def get_cp_entities(self):
         entities = []
         for i, (x, y) in enumerate(locations):
            entity = Territory(i, self, *(x, y, self.map.get_z(x, y)))
            if i % 2 == 0:
               entity.team = self.blue_team
               self.blue_team.cp = entity
               self.blue_team.spawn_cp = entity
               self.blue_team.cp.disabled = False
            else:
               entity.team = self.green_team
               self.green_team.cp = entity
               self.green_team.spawn_cp = entity
               self.green_team.cp.disabled = False
            entities.append(entity)
         return entities
I'm doing it wrong, how do I do it right?
BR_
Coder
Coder
Posts: 41
Joined: Wed Nov 14, 2012 3:52 pm


Challenge 3 (also the solution to Ki11aWi11a's problem):
Code: Select all
rom pyspades.constants import *
from pyspades.server import Territory

def apply_script(protocol, connection, config):
	class CPProtocol(protocol):
		def get_cp_entities(self):
			cp = []
			for i in self.map_info.extensions.get('tc_blue', []):
				entity = NoCapTerritory(len(cp), self, *i, map.get_z(*i))
				entity.team = self.blue_team
				entity.cap = True
				cp.append(entity)
			for i in self.map_info.extensions.get('tc_blue_uncap', []):
				entity = NoCapTerritory(len(cp), self, *i, map.get_z(*i))
				entity.team = self.blue_team
				entity.cap = False
				cp.append(entity)
			for i in self.map_info.extensions.get('tc_green', []):
				entity = NoCapTerritory(len(cp), self, *i, map.get_z(*i))
				entity.team = self.green_team
				entity.cap = True
				cp.append(entity)
			for i in self.map_info.extensions.get('tc_green_uncap', []):
				entity = NoCapTerritory(len(cp), self, *i, map.get_z(*i))
				entity.team = self.green_team
				entity.cap = False
				cp.append(entity)
			return cp
	return CPProtocol, connection
	
class NoCapTerritory(Territory):
	cap = False

	def add_player(self, player):
		if self.cap:
			Territory.add_player(self, player)
You may want to add a Z.
Ki11aWi11
Mapper
Mapper
Posts: 106
Joined: Tue Nov 20, 2012 12:39 am


Okay, so I've got it running, however, could you alter it so that if I have a map extension, it grabs the intel locations from that?

i.e.
Code: Select all
Name = 'Trenches'
Author = 'Ki11aWi11'
Version = '1.1'
Description = 'Charge across No Man's Land to seize the enemies War Plans!'
locations = ((30, 255, 53), (169, 255, 53), (343, 128, 53), (482, 384, 53))
HoboHob
Winter Celebration 2013
Winter Celebration 2013
Posts: 979
Joined: Mon Nov 05, 2012 5:02 pm


Okay so I have this slight leetle problem. I created 16 CP's, the only problem is, I they are unconquerable.
TheGeekZeke101
Deuced Up
Posts: 116
Joined: Sun Dec 02, 2012 6:54 pm


I don't know if you guys are familiar with Domination, one of CoD's most popular game modes, but it's simple.

There are three, or so, flags (in this case tents) on the map. Neither teams start off with any of the flags. The goal is to take and defend the flags. While you hold a flag you receive a point every five seconds you have it. You want to get so many points before the other team.

Something I'd kinda like to see done. I don't know what everyone is working on, but it's something to try when there's nothing else left.
Chameleon
Modder
Modder
Posts: 601
Joined: Thu Nov 22, 2012 6:41 pm


Hey, I have a suggestion for TOW: Make it impossible for players to go behind other team's front lines. Game's ain't good when you're being shot at from everywhere.
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


The game will be even less good when you have tons of confusing invisible walls.
Name Here
Deuce
Posts: 12
Joined: Fri Mar 22, 2013 2:32 pm


Personally would love to see the map narrow and long, that goes from above ground to underground, serrounded with death water maybe.
or sections , each cp you conquer opens the next segment, and moves the enemy spawn one cp back....
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1709
Joined: Wed Oct 03, 2012 12:09 am


Neat idea
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1709
Joined: Wed Oct 03, 2012 12:09 am


So, I have been thinking about how to set control points via map extensions and determine capture order for TOW and I think I figured out what to do. I think we can do it with one line in map extensions and let the script figure out the rest.

The map extensions would list the x and y locations of all the cp's for TOW starting with the leftmost cp and move towards the rightmost in an array or tuple or whatever stupid name python has for arrays. The script can determine the center command post /posts and have the teams start the match one command post away from the center. As long as the as the cp's are listed in order, the blue team will increment up the the array of cp locations after they capture a point and the green will decrement down the array after a capture.
Code: Select all
tow_locations = ((128, 128), (128, 384), (384, 128), (384, 384))
I forget what challenge number I am on but this is the TOW fixed location challenge.
BR_
Coder
Coder
Posts: 41
Joined: Wed Nov 14, 2012 3:52 pm


Try this, not sure if it'll work (I can't test right now):
Code: Select all
"""
Tug of War game mode, where you must progressively capture the enemy CPs in a 
straight line to win.

Maintainer: mat^2
"""

from pyspades.constants import *
from pyspades.server import Territory
import random
import math
from math import pi

HELP = [
    "In Tug of War, you capture your opponents' front CP to advance."
]

class TugTerritory(Territory):
    disabled = True
    
    def add_player(self, player):
        if self.disabled:
            return
        Territory.add_player(self, player)
    
    def enable(self):
        self.disabled = False
    
    def disable(self):
        for player in self.players.copy():
            self.remove_player(player)
        self.disabled = True
        self.progress = float(self.team.id)

def get_index(value):
    if value < 0:
        raise IndexError()
    return value

def apply_script(protocol, connection, config):
    class TugConnection(connection):
        def get_spawn_location(self):
            if self.team.spawn_cp is None:
                base = self.team.last_spawn
            else:
                base = self.team.spawn_cp
            return base.get_spawn_location()
            
        def on_spawn(self, pos):
            for line in HELP:
                self.send_chat(line)
            return connection.on_spawn(self, pos)
            
    class TugProtocol(protocol):
        game_mode = TC_MODE
        
        def get_cp_entities(self):
            # generate positions
            
            map = self.map
            blue_cp = []
            green_cp = []

            points = self.protocol.map_info.tow_locations
            
            for i, point in enumerate(points):
                if i < len(points) / 2:
                    blue_cp.append(point)
                else:
                    green_cp.append(point)
            
            # make entities
            
            index = 0
            entities = []
            
            for i, (x, y) in enumerate(blue_cp):
                entity = TugTerritory(index, self, *(x, y, map.get_z(x, y)))
                entity.team = self.blue_team
                if i == 0:
                    self.blue_team.last_spawn = entity
                    entity.id = -1
                else:
                    entities.append(entity)
                    index += 1
            
            self.blue_team.cp = entities[-1]
            self.blue_team.cp.disabled = False
            self.blue_team.spawn_cp = entities[-2]
                
            for i, (x, y) in enumerate(green_cp):
                entity = TugTerritory(index, self, *(x, y, map.get_z(x, y)))
                entity.team = self.green_team
                if i == len(green_cp) - 1:
                    self.green_team.last_spawn = entity
                    entity.id = index
                else:
                    entities.append(entity)
                    index += 1

            self.green_team.cp = entities[-(len(points)-2)/2]
            self.green_team.cp.disabled = False
            self.green_team.spawn_cp = entities[-(len(points)-2)/2 + 1]
            
            return entities
    
        def on_cp_capture(self, territory):
            team = territory.team
            if team.id:
                move = -1
            else:
                move = 1
            for team in [self.blue_team, self.green_team]:
                try:
                    team.cp = self.entities[get_index(team.cp.id + move)]
                    team.cp.enable()
                except IndexError:
                    pass
                try:
                    team.spawn_cp = self.entities[get_index(
                        team.spawn_cp.id + move)]
                except IndexError:
                    team.spawn_cp = team.last_spawn
            cp = (self.blue_team.cp, self.green_team.cp)
            for entity in self.entities:
                if not entity.disabled and entity not in cp:
                    entity.disable()

    return TugProtocol, TugConnection
TB_
Post Demon
Post Demon
Posts: 998
Joined: Tue Nov 20, 2012 6:59 pm


Really nice work BR_
I'm looking forward to see all the different types of gamemodes/objectives we'll get from this!
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1709
Joined: Wed Oct 03, 2012 12:09 am


Update on the TOW script

Had to make a few changes from the script BR made to get the map extensions to load. However in my map extensions I had 6 points but on the server it only showed 4. And the spawn logic seemed to be broken as well.
Code: Select all
"""
Tug of War game mode, where you must progressively capture the enemy CPs in a 
straight line to win.

Maintainer: mat^2
"""

from pyspades.constants import *
from pyspades.server import Territory
import random
import math
from math import pi

HELP = [
    "In Tug of War, you capture your opponents' front CP to advance."
]

class TugTerritory(Territory):
    disabled = True
    
    def add_player(self, player):
        if self.disabled:
            return
        Territory.add_player(self, player)
    
    def enable(self):
        self.disabled = False
    
    def disable(self):
        for player in self.players.copy():
            self.remove_player(player)
        self.disabled = True
        self.progress = float(self.team.id)

def get_index(value):
    if value < 0:
        raise IndexError()
    return value

def apply_script(protocol, connection, config):
    class TugConnection(connection):
        def get_spawn_location(self):
            if self.team.spawn_cp is None:
                base = self.team.last_spawn
            else:
                base = self.team.spawn_cp
            return base.get_spawn_location()
            
        def on_spawn(self, pos):
            for line in HELP:
                self.send_chat(line)
            return connection.on_spawn(self, pos)
            
    class TugProtocol(protocol):
        game_mode = TC_MODE
        
        def get_cp_entities(self):
            # generate positions
            
            map = self.map
            blue_cp = []
            green_cp = []

            points = self.map_info.extensions
            
            for i, point in enumerate(points['tow_locations']):
                if i < len(points['tow_locations']) / 2:
                    blue_cp.append(point)
                else:
                    green_cp.append(point)
            
            # make entities
            
            index = 0
            entities = []
            
            for i, (x, y) in enumerate(blue_cp):
                entity = TugTerritory(index, self, *(x, y, map.get_z(x, y)))
                entity.team = self.blue_team
                if i == 0:
                    self.blue_team.last_spawn = entity
                    entity.id = -1
                else:
                    entities.append(entity)
                    index += 1
            
            self.blue_team.cp = entities[-1]
            self.blue_team.cp.disabled = False
            self.blue_team.spawn_cp = entities[-2]
                
            for i, (x, y) in enumerate(green_cp):
                entity = TugTerritory(index, self, *(x, y, map.get_z(x, y)))
                entity.team = self.green_team
                if i == len(green_cp) - 1:
                    self.green_team.last_spawn = entity
                    entity.id = index
                else:
                    entities.append(entity)
                    index += 1

            self.green_team.cp = entities[-(len(points)-2)/2]
            self.green_team.cp.disabled = False
            self.green_team.spawn_cp = entities[-(len(points)-2)/2 + 1]
            
            return entities
    
        def on_cp_capture(self, territory):
            team = territory.team
            if team.id:
                move = -1
            else:
                move = 1
            for team in [self.blue_team, self.green_team]:
                try:
                    team.cp = self.entities[get_index(team.cp.id + move)]
                    team.cp.enable()
                except IndexError:
                    pass
                try:
                    team.spawn_cp = self.entities[get_index(
                        team.spawn_cp.id + move)]
                except IndexError:
                    team.spawn_cp = team.last_spawn
            cp = (self.blue_team.cp, self.green_team.cp)
            for entity in self.entities:
                if not entity.disabled and entity not in cp:
                    entity.disable()

    return TugProtocol, TugConnection
http://pastebin.com/rDt8WG1W <- link to the code above


Also here is the map extension I used:
Code: Select all
Name = 'Isthmos Edificans'
Author = 'Ki11aWi11'
Version = '1.0'
Description = 'Fight your way across the Isthmos!'
extensions = {

'tow_locations' : ((62, 256),(97, 256),(162, 256),(345, 256),(417, 256),(448, 256)),

'water_damage' : 20

}
http://pastebin.com/AY0xTefz

anyway if you like to check it out [aos]aos://2686459584:32887[/aos]
danhezee
Former Admin / Co-founder
Former Admin / Co-founder
Posts: 1709
Joined: Wed Oct 03, 2012 12:09 am


Figured I moved this to the pysnip scripts section so it would get lost in the general discussion session.
35 posts Page 2 of 3
Return to “Work In Progress”

Who is online

Users browsing this forum: No registered users and 1 guest