<commit_before>"""

  laby.py

From babel_script.py by Yourself (anti grief by izzy)
   + onectf.py by Yourself
   + intelrpg.py by Danke

Adapted to labyrinth map by ponce
 - all players have two powers: +3 HP/sec and grenade-teleport

"""

from pyspades.constants import *
from random import randint
from twisted.internet import reactor
from commands import add, admin
from pyspades.collision import vector_collision, distance_3d_vector
from pyspades.server import grenade_packet, block_action, set_tool
from pyspades.world import Grenade
from pyspades.common import Vertex3
import random
import commands

SPAWN_SIZE = 7
HIDE_POS = (0, 0, 63)

def get_entity_location(self, entity_id):

    if entity_id == BLUE_BASE:
        return self.protocol.blue_base_coord
    elif entity_id == GREEN_BASE:
        return self.protocol.green_base_coord
    elif entity_id == BLUE_FLAG:
        return (256 - 2 + 1, 256, 0)
    elif entity_id == GREEN_FLAG:
        return (256 + 2 - 1, 256, 0)

def get_spawn_location(connection):
    xb = connection.team.base.x
    yb = connection.team.base.y
    xb += randint(-SPAWN_SIZE, SPAWN_SIZE)
    yb += randint(-SPAWN_SIZE, SPAWN_SIZE)
    zb = 63 - 7
    while connection.protocol.map.get_solid(xb, yb, zb-1):
        (xb, yb) = (xb + randint(-1, 1), yb + randint(-1, 1))
    return (xb, yb, zb)


def intel_spawn_location(self):
    loop = 0
    while True:
        AREA = 20 
        x = randint(254 - AREA, 254 + AREA)
        y = randint(254 - AREA, 254 + AREA)
        lvl = randint(0, self.num_floors)
        z = 3 +  self.cell_size[2] * lvl
        z = 63 - z
        loop = loop + 1
        if (loop < 1000): # detect infinite loop (never happened yet)
            if self.map.get_solid(x, y, z):
                continue
            if self.map.get_solid(x+1, y, z):
                continue
            if self.map.get_solid(x, y+1, z):
                continue
            if self.map.get_solid(x+1, y+1, z):
                continue
            if self.map.get_solid(x, y, z-1):
                continue
            if self.map.get_solid(x+1, y, z-1):
                continue
            if self.map.get_solid(x, y+1, z-1):
                continue
            if self.map.get_solid(x+1, y+1, z-1):
                continue

        # find  floor
        while z < 63 and not self.map.get_solid(x, y, z):
            z = z + 1
            
        self.send_chat("The intel spawned " + self.level_to_floor(lvl) + ".")
        return (x, y, z)



def apply_script(protocol, connection, config):

    class LabyrinthConnection(connection):
        
        def on_flag_take(self):
            flag = self.team.flag
            if flag.player is None:
                flag.set(*HIDE_POS)
                flag.update()
            else:
                return False
            return connection.on_flag_take(self)
        
        def on_flag_drop(self):

            # move both intel
            position = self.world_object.position
            x = int(position.x)
            y = int(position.y)
            z =  max(0, int(position.z))

            # find  floor
            while z < 63 and not self.protocol.map.get_solid(x, y, z):
                z = z + 1

            flag = self.team.flag
            flag.set(x, y, z)
            flag.update()

            other_flag = self.team.other.flag
            other_flag.set(x, y, z)
            other_flag.update()

            return connection.on_flag_drop(self)

        def on_flag_capture(self):
            self.protocol.one_ctf_spawn_pos = intel_spawn_location(self.protocol)
            self.protocol.onectf_reset_flags()
            return connection.on_flag_capture(self)
        
        def intel_every_second(self):
            if self is None or self.hp <= 0:
                return
            self.set_hp(self.hp + 3, type = FALL_KILL)

        def on_grenade_thrown(self, grenade):
            grenade.callback = self.explosion
            connection.on_grenade_thrown(self, grenade)

        def explosion(self, grenade):
            x, y, z = (int(n) for n in grenade.position.get())
            self.set_location_safe((x, y, z - 1))


    class LabyrinthProtocol(protocol):
        intel_second_counter = 0<commit_msg>kill intel holder after 3 minutes<commit_after>"""

  laby.py

From babel_script.py by Yourself (anti grief by izzy)
   + onectf.py by Yourself
   + intelrpg.py by Danke

Adapted to labyrinth map by ponce
 - all players have two powers: +3 HP/sec and grenade-teleport

"""

from pyspades.constants import *
from random import randint
from twisted.internet import reactor
from commands import add, admin
from pyspades.collision import vector_collision, distance_3d_vector
from pyspades.server import grenade_packet, block_action, set_tool
from pyspades.world import Grenade
from pyspades.common import Vertex3
import random
import commands

SPAWN_SIZE = 7
HIDE_POS = (0, 0, 63)

def get_entity_location(self, entity_id):

    if entity_id == BLUE_BASE:
        return self.protocol.blue_base_coord
    elif entity_id == GREEN_BASE:
        return self.protocol.green_base_coord
    elif entity_id == BLUE_FLAG:
        return (256 - 2 + 1, 256, 0)
    elif entity_id == GREEN_FLAG:
        return (256 + 2 - 1, 256, 0)

def get_spawn_location(connection):
    xb = connection.team.base.x
    yb = connection.team.base.y
    xb += randint(-SPAWN_SIZE, SPAWN_SIZE)
    yb += randint(-SPAWN_SIZE, SPAWN_SIZE)
    zb = 63 - 7
    while connection.protocol.map.get_solid(xb, yb, zb-1):
        (xb, yb) = (xb + randint(-1, 1), yb + randint(-1, 1))
    return (xb, yb, zb)


def intel_spawn_location(self):
    loop = 0
    while True:
        AREA = 20 
        x = randint(254 - AREA, 254 + AREA)
        y = randint(254 - AREA, 254 + AREA)
        lvl = randint(0, self.num_floors)
        z = 3 +  self.cell_size[2] * lvl
        z = 63 - z
        loop = loop + 1
        if (loop < 1000): # detect infinite loop (never happened yet)
            if self.map.get_solid(x, y, z):
                continue
            if self.map.get_solid(x+1, y, z):
                continue
            if self.map.get_solid(x, y+1, z):
                continue
            if self.map.get_solid(x+1, y+1, z):
                continue
            if self.map.get_solid(x, y, z-1):
                continue
            if self.map.get_solid(x+1, y, z-1):
                continue
            if self.map.get_solid(x, y+1, z-1):
                continue
            if self.map.get_solid(x+1, y+1, z-1):
                continue

        # find  floor
        while z < 63 and not self.map.get_solid(x, y, z):
            z = z + 1
            
        self.send_chat("The intel spawned " + self.level_to_floor(lvl) + ".")
        return (x, y, z)



def apply_script(protocol, connection, config):

    class LabyrinthConnection(connection):

        allowed_intel_hold_time = 180
        auto_kill_intel_hog_call = None


        def auto_kill_intel_hog(self):
            self.auto_kill_intel_hog_call = None
            self.kill()
            self.protocol.send_chat('%s was punished for holding the intel too long' % (self.name))

        def cancel_auto_kill(self):
            if self.auto_kill_intel_hog_call is not None:
                self.auto_kill_intel_hog_call.cancel()
                self.auto_kill_intel_hog_call = None
        
        def on_flag_take(self):
            flag = self.team.flag
            if flag.player is None:
                flag.set(*HIDE_POS)
                flag.update()
            else:
                return False

            self.cancel_auto_kill()
            self.auto_kill_intel_hog_call = reactor.callLater(self.allowed_intel_hold_time, self.auto_kill_intel_hog)

            return connection.on_flag_take(self)
        
        def on_flag_drop(self):

            self.cancel_auto_kill()

            # move both intel
            position = self.world_object.position
            x = int(position.x)
            y = int(position.y)
            z =  max(0, int(position.z))

            # find  floor
            while z < 63 and not self.protocol.map.get_solid(x, y, z):
                z = z + 1

            flag = self.team.flag
            flag.set(x, y, z)
            flag.update()

            other_flag = self.team.other.flag
            other_flag.set(x, y, z)
            other_flag.update()

            return connection.on_flag_drop(self)

        def on_flag_capture(self):
            self.cancel_auto_kill()
            self.protocol.one_ctf_spawn_pos = intel_spawn_location(self.protocol)
            self.protocol.onectf_reset_flags()
            return connection.on_flag_capture(self)

        def on_reset(self):
            self.cancel_auto_kill()
        
        def intel_every_second(self):
            if self is None or self.hp <= 0:
                return
            self.set_hp(self.hp + 3, type = FALL_KILL)

        def on_grenade_thrown(self, grenade):
            grenade.callback = self.explosion
            connection.on_grenade_thrown(self, grenade)

        def explosion(self, grenade):
            x, y, z = (int(n) for n in grenade.position.get())
            self.set_location_safe((x, y, z - 1))


    class LabyrinthProtocol(protocol):
        intel_second_counter = 0
{'fraction_non_alphanumeric': 0.09563253012048192, 'fraction_numerical': 0.018072289156626505, 'mean_word_length': 1.8685590867016353, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2525965', 'n_tokens_mistral': 3174, 'n_tokens_neox': 2958, 'n_words': 738}