Updated stuff

This commit is contained in:
Olle Rosenquist 2007-07-22 11:53:15 +00:00
parent 2165a728c2
commit 26dd1c20ce
8 changed files with 725 additions and 569 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,48 @@
#ifndef __CLIENT_H
#define __CLIENT_H
#include <engine/network.h>
// --- client ---
// TODO: remove this class
class client
{
public:
int info_request_begin;
int info_request_end;
int snapshot_part;
int debug_font; // TODO: rfemove this line
// data to hold three snapshots
// previous,
void send_info();
void send_entergame();
void send_error(const char *error);
void send_input();
void disconnect();
bool load_data();
void debug_render();
void render();
void run(const char *direct_connect_server);
void error(const char *msg);
void serverbrowse_request(int id);
void serverbrowse_update();
void process_packet(NETPACKET *packet);
void pump_network();
};
#endif

View file

@ -249,7 +249,7 @@ public:
reporttime += time_freq()*reportinterval;
}
totaltime += time_get()-t;
thread_sleep(1);
//thread_sleep(1);
}
mods_shutdown();

View file

@ -4,11 +4,15 @@
#include <stdio.h>
#include <string.h>
#include <engine/config.h>
#include <engine/client/ui.h>
#include <engine/client/client.h>
#include "../game.h"
#include "mapres_image.h"
#include "mapres_tilemap.h"
#include "data.h"
#include "menu.h"
extern client main_client;
using namespace baselib;
data_container *data = 0x0;
@ -17,6 +21,11 @@ int charids[16] = {2,10,0,4,12,6,14,1,9,15,13,11,7,5,8,3};
static int gametype = GAMETYPE_DM;
static int skinseed = 0;
static int menu_team = 0;
static int menu_quit = 0;
static bool chat_active = false;
static bool menu_active = false;
static vec2 mouse_pos;
static vec2 local_player_pos;
@ -25,6 +34,7 @@ static obj_player *local_player;
struct client_data
{
char name[64];
int team;
} client_datas[MAX_CLIENTS];
inline float frandom() { return rand()/(float)(RAND_MAX); }
@ -373,7 +383,6 @@ public:
};
static projectile_particles proj_particles;
static bool chat_active = false;
static char chat_input[512];
static unsigned chat_input_len;
static const int chat_max_lines = 10;
@ -436,7 +445,10 @@ void modc_entergame()
chat_reset();
for(int i = 0; i < MAX_CLIENTS; i++)
{
client_datas[i].name[0] = 0;
client_datas[i].team = 0;
}
for(int i = 0; i < killmsg_max; i++)
killmsgs[i].tick = -100000;
@ -909,7 +921,7 @@ static void render_player(obj_player *prev, obj_player *player)
draw_sprite(p.x, p.y, data->weapons[iw].visual_size);
}
if (player->weapon == WEAPON_TYPE_GUN || player->weapon == WEAPON_TYPE_SHOTGUN)
if (player->weapon == WEAPON_GUN || player->weapon == WEAPON_SHOTGUN)
{
// check if we're firing stuff
if (true)///prev->attackticks)
@ -987,54 +999,116 @@ void render_sun(float x, float y)
gfx_quads_end();
}
void ingamemenu_render()
{
if (!local_player)
return;
gfx_mapscreen(0, 0, 800, 600);
// Ingame menu - quit and change team (if tdm)
float mx,my;
int rx, ry;
inp_mouse_relative(&rx, &ry);
mouse_pos.x += rx;
mouse_pos.y += ry;
if(mouse_pos.x < 0) mouse_pos.x = 0;
if(mouse_pos.y < 0) mouse_pos.y = 0;
if(mouse_pos.x > gfx_screenwidth()) mouse_pos.x = gfx_screenwidth();
if(mouse_pos.y > gfx_screenheight()) mouse_pos.y = gfx_screenheight();
// update the ui
mx = (mouse_pos.x/(float)gfx_screenwidth())*800.0f;
my = (mouse_pos.y/(float)gfx_screenheight())*600.0f;
int buttons = 0;
if(inp_key_pressed(input::mouse_1)) buttons |= 1;
if(inp_key_pressed(input::mouse_2)) buttons |= 2;
if(inp_key_pressed(input::mouse_3)) buttons |= 4;
ui_update(mx,my,mx*3.0f,my*3.0f,buttons);
gfx_texture_set(cursor_texture);
gfx_quads_begin();
gfx_quads_setcolor(1,1,1,1);
gfx_quads_drawTL(mx,my,24,24);
gfx_quads_end();
char buf[128];
if (gametype == GAMETYPE_TDM)
{
// Switch team
ui_do_label(100,100,"Switch Team",40);
sprintf(buf,"Team: %s",local_player->team ? "A" : "B");
if (ui_do_button(&menu_team, buf, 0, 30, 150, 170, 48, draw_teewars_button))
{
msg_pack_start(MSG_SWITCHTEAM, MSGFLAG_VITAL);
msg_pack_end();
client_send_msg();
menu_active = false;
}
}
if (ui_do_button(&menu_quit, "Quit", 0, 30, 350, 170, 48, draw_teewars_button))
{
//if (get_state() == STATE_CONNECTING || get_state() == STATE_ONLINE)
main_client.disconnect();
}
}
void modc_render()
{
animstate idlestate;
anim_eval(&data->animations[ANIM_BASE], 0, &idlestate);
anim_eval_add(&idlestate, &data->animations[ANIM_IDLE], 0, 1.0f);
if(inp_key_down(input::enter))
{
if(chat_active)
{
// send message
msg_pack_start(MSG_SAY, MSGFLAG_VITAL);
msg_pack_string(chat_input, 512);
msg_pack_end();
client_send_msg();
}
else
{
mem_zero(chat_input, sizeof(chat_input));
chat_input_len = 0;
}
chat_active = !chat_active;
}
if(chat_active)
{
int c = input::last_char(); // TODO: bypasses the engine interface
int k = input::last_key(); // TODO: bypasses the engine interface
if (c >= 32 && c < 255)
{
if (chat_input_len < sizeof(chat_input) - 1)
{
chat_input[chat_input_len] = c;
chat_input[chat_input_len+1] = 0;
chat_input_len++;
}
}
if(k == input::backspace)
if (inp_key_down(input::esc))
{
menu_active = !menu_active;
}
if (!menu_active)
{
if(inp_key_down(input::enter))
{
if(chat_input_len > 0)
if(chat_active)
{
chat_input[chat_input_len-1] = 0;
chat_input_len--;
// send message
msg_pack_start(MSG_SAY, MSGFLAG_VITAL);
msg_pack_string(chat_input, 512);
msg_pack_end();
client_send_msg();
}
else
{
mem_zero(chat_input, sizeof(chat_input));
chat_input_len = 0;
}
chat_active = !chat_active;
}
if(chat_active)
{
int c = input::last_char(); // TODO: bypasses the engine interface
int k = input::last_key(); // TODO: bypasses the engine interface
if (c >= 32 && c < 255)
{
if (chat_input_len < sizeof(chat_input) - 1)
{
chat_input[chat_input_len] = c;
chat_input[chat_input_len+1] = 0;
chat_input_len++;
}
}
if(k == input::backspace)
{
if(chat_input_len > 0)
{
chat_input[chat_input_len-1] = 0;
chat_input_len--;
}
}
}
}
input::clear_char(); // TODO: bypasses the engine interface
@ -1063,7 +1137,7 @@ void modc_render()
input.target_y = (int)mouse_pos.y; //(int)(a*256.0f);
input.activeweapon = -1;
if(!chat_active)
if(!chat_active && !menu_active)
{
input.left = inp_key_pressed(config.key_move_left);
input.right = inp_key_pressed(config.key_move_right);
@ -1157,7 +1231,10 @@ void modc_render()
{
void *prev = snap_find_item(SNAP_PREV, item.type, item.id);
if(prev)
{
client_datas[((obj_player *)data)->clientid].team = ((obj_player *)data)->team;
render_player((obj_player *)prev, (obj_player *)data);
}
}
else if(item.type == OBJTYPE_PROJECTILE)
{
@ -1188,9 +1265,12 @@ void modc_render()
gfx_quads_begin();
// render cursor
select_sprite(data->weapons[local_player->weapon%data->num_weapons].sprite_cursor);
float cursorsize = 64;
draw_sprite(local_player_pos.x+mouse_pos.x, local_player_pos.y+mouse_pos.y, cursorsize);
if (!menu_active)
{
select_sprite(data->weapons[local_player->weapon%data->num_weapons].sprite_cursor);
float cursorsize = 64;
draw_sprite(local_player_pos.x+mouse_pos.x, local_player_pos.y+mouse_pos.y, cursorsize);
}
// render ammo count
// render gui stuff
@ -1252,22 +1332,26 @@ void modc_render()
// render victim tee
x -= 24.0f;
//int skin = gametype == GAMETYPE_TDM ? skinseed + player->team : player->clientid;
render_tee(&idlestate, killmsgs[r].victim, vec2(1,0), vec2(x, y+28));
int skin = gametype == GAMETYPE_TDM ? skinseed + client_datas[killmsgs[r].victim].team : killmsgs[r].victim;
render_tee(&idlestate, skin, vec2(1,0), vec2(x, y+28));
x -= 32.0f;
// render weapon
x -= 44.0f;
gfx_texture_set(data->images[IMAGE_WEAPONS].id);
gfx_quads_begin();
select_sprite(data->weapons[killmsgs[r].weapon].sprite_body);
draw_sprite(x, y+28, 96);
gfx_quads_end();
if (killmsgs[r].weapon >= 0)
{
gfx_texture_set(data->images[IMAGE_WEAPONS].id);
gfx_quads_begin();
select_sprite(data->weapons[killmsgs[r].weapon].sprite_body);
draw_sprite(x, y+28, 96);
gfx_quads_end();
}
x -= 52.0f;
// render killer tee
x -= 24.0f;
render_tee(&idlestate, killmsgs[r].killer, vec2(1,0), vec2(x, y+28));
skin = gametype == GAMETYPE_TDM ? skinseed + client_datas[killmsgs[r].killer].team : killmsgs[r].killer;
render_tee(&idlestate, skin, vec2(1,0), vec2(x, y+28));
x -= 32.0f;
// render killer name
@ -1277,6 +1361,12 @@ void modc_render()
y += 44;
}
}
if (menu_active)
{
ingamemenu_render();
return;
}
// render chat
{
@ -1410,7 +1500,8 @@ void modc_render()
// Team deathmatch
gfx_blend_normal();
float x = 50.0f;
float w = 650.0f;
float x = width-w-50.0f;
float y = 150.0f;
gfx_texture_set(-1);
@ -1483,7 +1574,12 @@ void modc_render()
gfx_pretty_text(offsetx + x+128, offsets[player->team], 48, client_datas[player->clientid].name);
int skin = skinseed + player->team;
render_tee(&idlestate, skin, vec2(1,0), vec2(offsetx + x+90, y+24));
render_tee(&idlestate, skin, vec2(1,0), vec2(offsetx + x+90, offsets[player->team]+24));
sprintf(buf, "%4d", player->latency);
float tw = gfx_pretty_text_width(48.0f, buf);
gfx_pretty_text(offsetx + x + 220, y, 48, buf);
offsets[player->team] += 58.0f;
}
}

17
src/game/client/menu.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef __MENU_H
#define __MENU_H
extern int cursor_texture;
void draw_image_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
void draw_single_part_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
void draw_menu_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
void draw_teewars_button(void *id, const char *text, int checked, float x, float y, float w, float h, void *extra);
int ui_do_key_reader(void *id, float x, float y, float w, float h, int key);
int ui_do_combo_box(void *id, float x, float y, float w, char *lines, int line_count, int selected_index);
int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int str_size);
int ui_do_check_box(void *id, float x, float y, float w, float h, int value);
int do_scroll_bar_horiz(void *id, float x, float y, float width, int steps, int last_index);
int do_scroll_bar_vert(void *id, float x, float y, float height, int steps, int last_index);
#endif

View file

@ -49,6 +49,7 @@ enum
MSG_CHAT,
MSG_SETNAME,
MSG_KILLMSG,
MSG_SWITCHTEAM,
};
enum
@ -157,11 +158,6 @@ struct obj_player
enum
{
WEAPON_TYPE_GUN = 0,
WEAPON_TYPE_ROCKET = 1,
WEAPON_TYPE_SHOTGUN = 2,
WEAPON_TYPE_MELEE = 3,
WEAPON_NUMWEAPONS,
//WEAPON_TYPE_SNIPER = 2,
POWERUP_TYPE_HEALTH = 0,

View file

@ -4,5 +4,5 @@ MACRO_CONFIG_INT(key_jump, 32, 32, 512)
MACRO_CONFIG_INT(key_fire, 384, 32, 512)
MACRO_CONFIG_INT(key_hook, 385, 32, 512)
MACRO_CONFIG_INT(scorelimit, 20, 0, 1000)
MACRO_CONFIG_INT(scorelimit, 2, 0, 1000)
MACRO_CONFIG_INT(timelimit, 0, 0, 1000)

View file

@ -1640,6 +1640,13 @@ void mods_message(int msg, int client_id)
msg_pack_end();
server_send_msg(-1);
}
else if (msg == MSG_SWITCHTEAM)
{
// Switch team on given client and kill/respawn him
players[client_id].team = !players[client_id].team;
players[client_id].die(client_id, -1);
players[client_id].score--;
}
}
void mods_init()
@ -1662,19 +1669,19 @@ void mods_init()
{
case ITEM_WEAPON_GUN:
type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_GUN;
subtype = WEAPON_GUN;
break;
case ITEM_WEAPON_SHOTGUN:
type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_SHOTGUN;
subtype = WEAPON_SHOTGUN;
break;
case ITEM_WEAPON_ROCKET:
type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_ROCKET;
subtype = WEAPON_ROCKET;
break;
case ITEM_WEAPON_HAMMER:
type = POWERUP_TYPE_WEAPON;
subtype = WEAPON_TYPE_MELEE;
subtype = WEAPON_HAMMER;
break;
case ITEM_HEALTH:
@ -1684,6 +1691,10 @@ void mods_init()
case ITEM_ARMOR:
type = POWERUP_TYPE_ARMOR;
break;
case ITEM_NINJA:
type = POWERUP_TYPE_NINJA;
subtype = WEAPON_NINJA;
break;
};
powerup *ppower = new powerup(type, subtype);