Skip to content

Commit

Permalink
loads of minor fixes here and there. fixed invalid corrections and st…
Browse files Browse the repository at this point in the history
…uff like that
  • Loading branch information
Magnus Auvinen committed Mar 17, 2008
1 parent 8cb74cf commit 511720b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
20 changes: 11 additions & 9 deletions scripts/netobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def emit_declaration(self):
return ["\tint %s;" % self.name]
def linedef(self):
return "#line %d" % self.line
def emit_secure(self):
def emit_secure(self, parent):
return []
def emit_unpack(self):
return ["msg.%s = msg_unpack_int();" % self.name]
Expand All @@ -32,8 +32,8 @@ def __init__(self, args, name):
self.max = args[1]
def emit_unpack_check(self):
return ["if(msg.%s < %s || msg.%s > %s) { msg_failed_on = \"%s\"; return 0; }" % (self.name, self.min, self.name, self.max, self.name)]
def emit_secure(self):
return [self.linedef(), "obj->%s = netobj_clamp_int(obj->%s, %s, %s);" % (self.name, self.name, self.min, self.max)]
def emit_secure(self, parent):
return [self.linedef(), "obj->%s = netobj_clamp_int(\"%s.%s\", obj->%s, %s, %s);" % (self.name, parent.name, self.name, self.name, self.min, self.max)]

class var_string(variable):
def __init__(self, args, name):
Expand Down Expand Up @@ -105,7 +105,7 @@ def emit_declaration(self):
def emit_secure(self):
lines = []
for m in self.members:
lines += m.emit_secure()
lines += m.emit_secure(self)
return lines

class message:
Expand Down Expand Up @@ -212,14 +212,13 @@ def load(filename):
# read the file
global line_count
line_count = 0
lines = [line.strip() for line in file(filename).readlines()]
lines = [line.split("//", 2)[0].strip() for line in file(filename).readlines()]

p = proto()

while len(lines):
line_count += 1
line = lines[0]
line = line.split("//", 2)[0] # strip comment

if not len(line):
del lines[0]
Expand Down Expand Up @@ -279,6 +278,7 @@ def emit_header_file(f, p):
print >>f, "int netobj_secure(int type, void *data, int size);"
print >>f, "const char *netobj_get_name(int type);"
print >>f, "int netobj_num_corrections();"
print >>f, "const char *netobj_corrected_on();"
print >>f, ""
print >>f, "void *netmsg_secure_unpack(int type);"
print >>f, "const char *netmsg_get_name(int type);"
Expand All @@ -302,14 +302,16 @@ def emit_source_file(f, p, protofilename):
print >>f, l

print >>f, "const char *msg_failed_on = \"\";"
print >>f, "const char *obj_corrected_on = \"\";"
print >>f, "static int num_corrections = 0;"
print >>f, "int netobj_num_corrections() { return num_corrections; }"
print >>f, "const char *netobj_corrected_on() { return obj_corrected_on; }"
print >>f, "const char *netmsg_failed_on() { return msg_failed_on; }"
print >>f, ""
print >>f, "static int netobj_clamp_int(int v, int min, int max)"
print >>f, "static int netobj_clamp_int(const char *error_msg, int v, int min, int max)"
print >>f, "{"
print >>f, "\tif(v<min) { num_corrections++; return min; }"
print >>f, "\tif(v>max) { num_corrections++; return max; }"
print >>f, "\tif(v<min) { obj_corrected_on = error_msg; num_corrections++; return min; }"
print >>f, "\tif(v>max) { obj_corrected_on = error_msg; num_corrections++; return max; }"
print >>f, "\treturn v;"
print >>f, "}"
print >>f, ""
Expand Down
7 changes: 2 additions & 5 deletions src/game/client/gc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1056,9 +1056,6 @@ void render_game()
gfx_mapscreen(0,0,300*gfx_screenaspect(),300);

// if weaponstage is active, put a "glow" around the stage ammo
select_sprite(SPRITE_TEE_BODY);
for (int i = 0; i < netobjects.local_character->weaponstage; i++)
gfx_quads_drawTL(x+netobjects.local_character->ammocount * 12 -i*12, y+22, 11, 11);
select_sprite(data->weapons[netobjects.local_character->weapon%data->num_weapons].sprite_proj);
for (int i = 0; i < min(netobjects.local_character->ammocount, 10); i++)
gfx_quads_drawTL(x+i*12,y+24,10,10);
Expand Down Expand Up @@ -1300,7 +1297,7 @@ void render_game()

if(gametype == GAMETYPE_CTF)
{
gfx_text(0, whole-20-w/2+5, 300-40-15+t*20+2, 14, buf, -1);
gfx_text(0, whole-20-w/2+5, 300-40-15+t*20, 14, buf, -1);
if(netobjects.flags[t])
{
if(netobjects.flags[t]->carried_by == -2 || (netobjects.flags[t]->carried_by == -1 && ((client_tick()/10)&1)))
Expand Down Expand Up @@ -1398,7 +1395,7 @@ void render_game()
float ramp = velocity_ramp(velspeed, tuning.velramp_start, tuning.velramp_range, tuning.velramp_curvature);

char buf[512];
str_format(buf, sizeof(buf), "%.0f\n%.0f\n%.2f\n%d", velspeed, velspeed*ramp, ramp, netobj_num_corrections());
str_format(buf, sizeof(buf), "%.0f\n%.0f\n%.2f\n%d %s", velspeed, velspeed*ramp, ramp, netobj_num_corrections(), netobj_corrected_on());
gfx_text(0, 150, 50, 12, buf, -1);
}

Expand Down
7 changes: 3 additions & 4 deletions src/game/g_protocol.def
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
object projectile
any x, y
any vx, vy
range(0, NUM_WEAPONS) type
range(0, NUM_WEAPONS-1) type
range(0, max_int) start_tick
end

Expand All @@ -85,7 +85,7 @@ end
object flag
any x, y
range(0, 1) team
range(-1,MAX_CLIENTS-1) carried_by
range(-2,MAX_CLIENTS-1) carried_by // -2 == at stand -1 == on the field
end

object game
Expand Down Expand Up @@ -114,7 +114,7 @@ object player_core
range(0, 3) jumped

range(-1,MAX_CLIENTS-1) hooked_player
range(0, 3) hook_state
range(-1,2) hook_state
range(0, max_int) hook_tick

any hook_x
Expand All @@ -136,7 +136,6 @@ object player_character extends player_core
range(0, NUM_WEAPONS-1) weapon
range(0, NUM_EMOTES-1) emote

range(0, 10) weaponstage
range(0, max_int) attacktick
end

Expand Down
20 changes: 7 additions & 13 deletions src/game/server/gs_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ void player::try_respawn()
weapons[WEAPON_GUN].ammo = data->weapons[WEAPON_GUN].maxammo;

weapons[WEAPON_RIFLE].got = true;
weapons[WEAPON_RIFLE].ammo = 100000; //data->weapons[WEAPON_LASER].maxammo;
weapons[WEAPON_RIFLE].ammo = -1;

active_weapon = WEAPON_GUN;
last_weapon = WEAPON_HAMMER;
Expand Down Expand Up @@ -1101,7 +1101,8 @@ void player::fire_weapon()

}

weapons[active_weapon].ammo--;
if(weapons[active_weapon].ammo > 0) // -1 == unlimited
weapons[active_weapon].ammo--;
attack_tick = server_tick();
reload_timer = data->weapons[active_weapon].firedelay * server_tickspeed() / 1000;
}
Expand Down Expand Up @@ -1622,7 +1623,7 @@ void player::snap(int snaping_client)
info->local = 1;
}

if(health > 0 && team >= 0 && distance(players[snaping_client].pos, pos) < 1000.0f)
if(!dead && health > 0 && team >= 0 && distance(players[snaping_client].pos, pos) < 1000.0f)
{
NETOBJ_PLAYER_CHARACTER *character = (NETOBJ_PLAYER_CHARACTER *)snap_new_item(NETOBJTYPE_PLAYER_CHARACTER, client_id, sizeof(NETOBJ_PLAYER_CHARACTER));

Expand All @@ -1643,7 +1644,7 @@ void player::snap(int snaping_client)

character->emote = emote_type;

character->ammocount = weapons[active_weapon].ammo;
character->ammocount = 0;
character->health = 0;
character->armor = 0;

Expand All @@ -1661,17 +1662,10 @@ void player::snap(int snaping_client)
{
character->health = health;
character->armor = armor;
if(weapons[active_weapon].ammo > 0)
character->ammocount = weapons[active_weapon].ammo;
}

if(dead)
character->health = -1;

//if(length(vel) > 15.0f)
// player->emote = EMOTE_HAPPY;

//if(damage_taken_tick+50 > server_tick())
// player->emote = EMOTE_PAIN;

if (character->emote == EMOTE_NORMAL)
{
if(250 - ((server_tick() - last_action)%(250)) < 5)
Expand Down

0 comments on commit 511720b

Please sign in to comment.