Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
New additions
Browse files Browse the repository at this point in the history
  • Loading branch information
matpow2 committed Mar 10, 2012
1 parent f2cfd5e commit 2010dc7
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 47 deletions.
13 changes: 6 additions & 7 deletions experimental/test_world_visual.py
Expand Up @@ -19,7 +19,7 @@
sys.path.append('..')

from pyspades.common import *
from pyspades.load import VXLData, get_color_tuple
from pyspades.vxl import VXLData, get_color_tuple
from pyspades import world
import pyglet
from pyglet.window import key
Expand All @@ -43,7 +43,8 @@
def on_fall(damage):
print 'on fall:', damage

new_world = world.World(map)
new_world = world.World()
new_world.map = map
character = new_world.create_object(world.Character,
Vertex3(20.0, 20.0, 5.0), Vertex3(0.999992012978, 0.0, -0.00399998947978),
on_fall)
Expand Down Expand Up @@ -99,7 +100,7 @@ def on_draw():
for x, z, color in block_cache.blocks:
draw_block(x, map_y, z, color)

x, y = get_position(position.x, position.y, character.guess_z)
x, y = get_position(position.x, position.y, position.z)
add_height = 0
if not character.crouch:
add_height = (0.9 / scale) * 600
Expand All @@ -120,7 +121,7 @@ def on_nade(nade):

def on_key_press(symbol, modifiers):
if symbol == key.SPACE:
character.set_animation(jump = True)
character.jump = True
elif symbol == key.F:
character.throw_grenade(5, on_nade)
elif symbol == key.X:
Expand All @@ -137,9 +138,7 @@ def update(dt):
keyboard[key.UP],
keyboard[key.DOWN]
)
character.set_animation(
crouch = keyboard[key.Z]
)
character.set_crouch(keyboard[key.Z])
new_world.update(dt)

# setup :)
Expand Down
8 changes: 7 additions & 1 deletion feature_server/run.py
Expand Up @@ -224,12 +224,18 @@ def on_command(self, command, parameters):
self.send_chat(result)
print log_message.encode('ascii', 'replace')

def on_block_build_attempt(self, x, y, z):
def _can_build(self):
if not self.building:
return False
if not self.god and not self.protocol.building:
return False

def on_block_build_attempt(self, x, y, z):
return self._can_build()

def on_line_build_attempt(self, points):
return self._can_build()

def on_block_build(self, x, y, z):
if self.god:
self.refill()
Expand Down
11 changes: 11 additions & 0 deletions feature_server/scripts/protect.py
Expand Up @@ -20,10 +20,21 @@ def protect(connection, value = None):

def apply_script(protocol, connection, config):
class ProtectConnection(connection):
def _block_available(self, x, y, z):
if not self.god and self.protocol.is_protected(x, y):
return False

def on_block_build_attempt(self, x, y, z):
if not self.god and self.protocol.is_protected(x, y):
return False
return connection.on_block_build_attempt(self, x, y, z)

def on_line_build_attempt(self, points):
if not self.god:
for point in points:
if self.protocol.is_protected(point.x, point.y):
return False
return connection.on_line_build_attempt(self, points)

class ProtectProtocol(protocol):
protected = None
Expand Down
2 changes: 1 addition & 1 deletion pyspades/constants.py
Expand Up @@ -23,7 +23,7 @@
SPADE_TOOL, BLOCK_TOOL, WEAPON_TOOL, GRENADE_TOOL = xrange(4)
BUILD_BLOCK, DESTROY_BLOCK, SPADE_DESTROY, GRENADE_DESTROY = xrange(4)
BLUE_FLAG, GREEN_FLAG, BLUE_BASE, GREEN_BASE = xrange(4)
(CHAT_UNKNOWN, CHAT_ALL, CHAT_TEAM, CHAT_SYSTEM) = xrange(4)
CHAT_ALL, CHAT_TEAM, CHAT_SYSTEM = xrange(3)
(WEAPON_KILL, HEADSHOT_KILL, MELEE_KILL, GRENADE_KILL, FALL_KILL,
TEAM_CHANGE_KILL, CLASS_CHANGE_KILL) = xrange(7)
CTF_MODE, TC_MODE = xrange(2)
Expand Down
3 changes: 2 additions & 1 deletion pyspades/contained.pyx
Expand Up @@ -338,7 +338,8 @@ cdef class CreatePlayer(Loader):
id = id_iter.next()

cdef public:
unsigned int player_id, weapon, team
unsigned int player_id, weapon
int team
float x, y, z
object name

Expand Down
2 changes: 1 addition & 1 deletion pyspades/packet.pyx
@@ -1 +1 @@
# Copyright (c) Mathias Kaerlev 2011-2012.# This file is part of pyspades.# pyspades program is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.# pyspades is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# You should have received a copy of the GNU General Public License# along with pyspades. If not, see <http://www.gnu.org/licenses/>.from pyspades.common import *from pyspades.loaders cimport Loaderfrom pyspades import debugfrom pyspades.bytes cimport ByteReader, ByteWriterfrom pyspades import containedCONTAINED_LIST = [ contained.PositionData, contained.OrientationData, contained.WorldUpdate, contained.InputData, contained.WeaponInput, contained.GrenadePacket, contained.SetTool, contained.SetColor, contained.ExistingPlayer, contained.MoveObject, contained.CreatePlayer, contained.BlockAction, contained.BlockLine, contained.StateData, contained.KillAction, contained.ChatMessage, contained.MapStart, contained.MapChunk, contained.PlayerLeft, contained.TerritoryCapture, contained.ProgressBar, contained.IntelCapture, contained.IntelPickup, contained.IntelDrop, contained.Restock, contained.FogColor, contained.WeaponReload, contained.ChangeTeam, contained.ChangeWeapon]CONTAINED_LOADERS = {}for item in CONTAINED_LIST: CONTAINED_LOADERS[item.id] = itemSERVER_LOADERS = CONTAINED_LOADERS.copy()for item in (contained.SetHP,): SERVER_LOADERS[item.id] = itemCLIENT_LOADERS = CONTAINED_LOADERS.copy()for item in (contained.HitPacket,): CLIENT_LOADERS[item.id] = itemdef load_server_packet(data): return load_contained_packet(data, SERVER_LOADERS)def load_client_packet(data): return load_contained_packet(data, CLIENT_LOADERS)cdef inline Loader load_contained_packet(ByteReader data, dict table): type = data.readByte(True) return table[type](data)
# Copyright (c) Mathias Kaerlev 2011-2012.# This file is part of pyspades.# pyspades program is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.# pyspades is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# You should have received a copy of the GNU General Public License# along with pyspades. If not, see <http://www.gnu.org/licenses/>.from pyspades.common import *from pyspades.loaders cimport Loaderfrom pyspades import debugfrom pyspades.bytes cimport ByteReader, ByteWriterfrom pyspades import containedCONTAINED_LIST = [ contained.PositionData, contained.OrientationData, contained.WorldUpdate, contained.InputData, contained.WeaponInput, contained.GrenadePacket, contained.SetTool, contained.SetColor, contained.ExistingPlayer, contained.MoveObject, contained.CreatePlayer, contained.BlockAction, contained.BlockLine, contained.ShortPlayerData, contained.StateData, contained.KillAction, contained.ChatMessage, contained.MapStart, contained.MapChunk, contained.PlayerLeft, contained.TerritoryCapture, contained.ProgressBar, contained.IntelCapture, contained.IntelPickup, contained.IntelDrop, contained.Restock, contained.FogColor, contained.WeaponReload, contained.ChangeTeam, contained.ChangeWeapon]CONTAINED_LOADERS = {}for item in CONTAINED_LIST: CONTAINED_LOADERS[item.id] = itemSERVER_LOADERS = CONTAINED_LOADERS.copy()for item in (contained.SetHP,): SERVER_LOADERS[item.id] = itemCLIENT_LOADERS = CONTAINED_LOADERS.copy()for item in (contained.HitPacket,): CLIENT_LOADERS[item.id] = itemdef load_server_packet(data): return load_contained_packet(data, SERVER_LOADERS)def load_client_packet(data): return load_contained_packet(data, CLIENT_LOADERS)cdef inline Loader load_contained_packet(ByteReader data, dict table): type = data.readByte(True) return table[type](data)
Expand Down
71 changes: 38 additions & 33 deletions pyspades/server.py
Expand Up @@ -218,7 +218,6 @@ def on_connect(self):
def loader_received(self, loader):
if self.player_id is not None:
contained = load_client_packet(ByteReader(loader.data))
print 'received:', contained
if contained.id in (loaders.ExistingPlayer.id,
loaders.ShortPlayerData.id):
team = self.protocol.teams[contained.team]
Expand All @@ -242,8 +241,7 @@ def loader_received(self, loader):
if self.world_object is not None:
self.world_object.delete()
self.world_object = None
else:
self.spawn()
self.spawn()
return
if self.hp:
world_object = self.world_object
Expand Down Expand Up @@ -490,20 +488,16 @@ def loader_received(self, loader):
if not points:
return
if len(points) > (self.blocks + BUILD_TOLERANCE):
print len(points), self.blocks
return
map = self.protocol.map
if self.on_line_build_attempt(points) == False:
return
for point in points:
self.blocks -= 1
x, y, z = point.x, point.y, point.z
if self.on_block_build_attempt(x, y, z) == False:
break
elif not map.set_point(x, y, z, self.color + (255,)):
if not map.set_point(x, y, z, self.color + (255,)):
break
self.on_block_build(x, y, z)
contained.x2 = x
contained.y2 = y
contained.z2 = z
self.blocks -= len(points)
self.on_line_build(points)
contained.player_id = self.player_id
self.protocol.send_contained(contained, save = True)
if self.name:
Expand Down Expand Up @@ -630,32 +624,35 @@ def get_respawn_time(self):

def spawn(self, pos = None):
self.spawn_call = None
if pos is None:
x, y, z = self.get_spawn_location()
z -= 1.4 # super magic value
else:
x, y, z = pos
if self.world_object is not None:
self.world_object.set_position(x, y, z, True)
else:
position = Vertex3(x, y, z)
self.world_object = self.protocol.world.create_object(
world.Character, position, None, self._on_fall)
self.world_object.dead = False
self.tool = WEAPON_TOOL
self.refill(True)
spectator = self.team.spectator
if not spectator:
if pos is None:
x, y, z = self.get_spawn_location()
z -= 1.4 # super magic value
else:
x, y, z = pos
if self.world_object is not None:
self.world_object.set_position(x, y, z, True)
else:
position = Vertex3(x, y, z)
self.world_object = self.protocol.world.create_object(
world.Character, position, None, self._on_fall)
self.world_object.dead = False
self.tool = WEAPON_TOOL
self.refill(True)
create_player.x = x + 0.5
create_player.y = y + 0.5
create_player.z = z - 0.5
create_player.weapon = self.weapon
create_player.player_id = self.player_id
create_player.name = self.name
create_player.x = x + 0.5
create_player.y = y + 0.5
create_player.z = z - 0.5
create_player.weapon = self.weapon
create_player.team = self.team.id
if self.filter_visibility_data:
if self.filter_visibility_data and not spectator:
self.send_contained(create_player)
else:
self.protocol.send_contained(create_player, save = True)
self.on_spawn((x, y, z))
if not spectator:
self.on_spawn((x, y, z))

def take_flag(self):
if not self.hp:
Expand Down Expand Up @@ -1041,6 +1038,12 @@ def on_block_build_attempt(self, x, y, z):

def on_block_build(self, x, y, z):
pass

def on_line_build_attempt(self, points):
pass

def on_line_build(self, points):
pass

def on_block_destroy(self, x, y, z, mode):
pass
Expand Down Expand Up @@ -1336,6 +1339,7 @@ class ServerProtocol(BaseProtocol):
loop_count = 0
melee_damage = 100
version = GAME_VERSION
respawn_waves = False

def __init__(self, *arg, **kw):
self.max_connections = self.max_players
Expand Down Expand Up @@ -1416,7 +1420,8 @@ def update_network(self):
position = orientation = None
try:
player = self.players[i]
if not player.filter_visibility_data:
if (not player.filter_visibility_data and
not player.team.spectator):
world_object = player.world_object
position = world_object.position.get()
orientation = world_object.orientation.get()
Expand Down
10 changes: 8 additions & 2 deletions pyspades/world.pyx
Expand Up @@ -103,7 +103,6 @@ cdef class Character(Object):
PlayerType * player
cdef public:
Vertex3 position, orientation, velocity
bint dead
object fall_callback

def initialize(self, Vertex3 position, Vertex3 orientation,
Expand Down Expand Up @@ -158,7 +157,8 @@ cdef class Character(Object):
self.up = self.down = self.left = self.right = False

def set_orientation(self, x, y, z):
self.orientation.set(x, y, z)
cdef Vertex3 v = Vertex3(x, y, z)
reorient_player(self.player, v.value)

def throw_grenade(self, time_left, callback = None):
item = self.world.create_object(Grenade, time_left, self.position,
Expand Down Expand Up @@ -243,6 +243,12 @@ cdef class Character(Object):
return self.player.mr
def __set__(self, value):
self.player.mr = value

property dead:
def __get__(self):
return not self.player.alive
def __set__(self, bint value):
self.set_dead(value)

property jump:
def __get__(self):
Expand Down
2 changes: 1 addition & 1 deletion pyspades/world_c.cpp
Expand Up @@ -161,7 +161,7 @@ long clipworld(long x, long y, long z)
if(sz == 63)
sz=62;
else if (sz >= 63)
return 0;
return 1;
return get_solid((int)x, (int)y, sz, global_map);
}

Expand Down

0 comments on commit 2010dc7

Please sign in to comment.