name = "crossfire"
version = 'MegaStar and edugamer63'
description = ('map of the game half life')

extensions = { 'water_damage' : 100 }
protected = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'D1', 'D2', 'D3', 'D6', 'D7', 'D8', 'E1', 'E2', 'E3', 'E6', 'E7', 'E8', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'H7', 'H8']

# script
from pyspades.server import ServerConnection
from pyspades.constants import *
import random


def get_entity_location(team, entity_id):
    if entity_id == GREEN_FLAG:
        z = team.protocol.map.get_z(0, 0)
        return ( 252, 167, 59)
    if entity_id == GREEN_BASE:
        z = team.protocol.map.get_z(0, 0)
        return ( 254, 181, 56)
    if entity_id == BLUE_FLAG:
        z = team.protocol.map.get_z(0, 0)
        return ( 260, 283, 48)
    if entity_id == BLUE_BASE:
        z = team.protocol.map.get_z(0, 0)
        return ( 260, 257, 58)


spawn_locations_blue = [
    ( 226, 277, 51),( 260, 282, 51),( 226, 246, 61),
]

spawn_locations_green = [
    ( 271, 160, 60),( 246, 223, 61),( 268, 180, 59),( 239, 180, 59),
]

def get_spawn_location(connection):
    if connection.team is connection.protocol.blue_team:
        x, y, z = random.choice(spawn_locations_blue)
    elif connection.team is connection.protocol.green_team:
        x, y, z = random.choice(spawn_locations_green)
    z -= 0 # magic numbers
    x += 0.5
    y += 0.5
    if connection.protocol.map.get_z(x, y) <= z:
        # allows spawning lower if the ground is destroyed
        return x, y, z
    else:
        return x, y, connection.protocol.map.get_z(x, y)