diff options
Diffstat (limited to 'src')
27 files changed, 503 insertions, 473 deletions
diff --git a/src/engine/client/ec_client.c b/src/engine/client/ec_client.c index 6d3a400b..8872d5f4 100644 --- a/src/engine/client/ec_client.c +++ b/src/engine/client/ec_client.c @@ -770,7 +770,7 @@ static void client_process_packet(NETCHUNK *packet) { int sys; int msg = msg_unpack_start(packet->data, packet->data_size, &sys); - + if(sys) { /* system message */ diff --git a/src/engine/e_network.c b/src/engine/e_network.c index 9ebeba61..51fcbd75 100644 --- a/src/engine/e_network.c +++ b/src/engine/e_network.c @@ -19,7 +19,6 @@ CURRENT: unsigned char flags_size; // 2bit flags, 6 bit size unsigned char size_seq; // 4bit size, 4bit seq (unsigned char seq;) // 8bit seq, if vital flag is set - */ enum @@ -216,6 +215,25 @@ struct NETCLIENT_t static IOHANDLE datalog = 0; static HUFFSTATE huffmanstate; +#define COMPRESSION 0 + +typedef struct pcap_hdr_s { + unsigned magic_number; /* magic number */ + short version_major; /* major version number */ + short version_minor; /* minor version number */ + int thiszone; /* GMT to local correction */ + unsigned sigfigs; /* accuracy of timestamps */ + unsigned snaplen; /* max length of captured packets, in octets */ + unsigned network; /* data link type */ +} pcap_hdr_t; + +typedef struct pcaprec_hdr_s { + unsigned ts_sec; /* timestamp seconds */ + unsigned ts_usec; /* timestamp microseconds */ + unsigned incl_len; /* number of octets of packet saved in file */ + unsigned orig_len; /* actual length of packet */ +} pcaprec_hdr_t; + /* packs the data tight and sends it */ static void send_packet(NETSOCKET socket, NETADDR4 *addr, NETPACKETCONSTRUCT *packet) { @@ -229,14 +247,14 @@ static void send_packet(NETSOCKET socket, NETADDR4 *addr, NETPACKETCONSTRUCT *pa io_write(datalog, &packet->chunk_data, packet->data_size); } - if(1) + if(COMPRESSION) { int compressed_size = (huffman_compress(&huffmanstate, packet->chunk_data, packet->data_size, &buffer[4], NET_MAX_PACKETSIZE-4)+7)/8; net_udp4_send(socket, addr, buffer, NET_PACKETHEADERSIZE+compressed_size); } else { - mem_copy(&buffer[4], packet->chunk_data, packet->data_size); + mem_copy(&buffer[3], packet->chunk_data, packet->data_size); net_udp4_send(socket, addr, buffer, NET_PACKETHEADERSIZE+packet->data_size); } } @@ -246,7 +264,10 @@ static int unpack_packet(unsigned char *buffer, int size, NETPACKETCONSTRUCT *pa { /* check the size */ if(size < NET_PACKETHEADERSIZE || size > NET_MAX_PACKETSIZE) + { + dbg_msg("", "packet too small"); return -1; + } /* read the packet */ packet->flags = buffer[0]>>4; @@ -254,12 +275,12 @@ static int unpack_packet(unsigned char *buffer, int size, NETPACKETCONSTRUCT *pa packet->num_chunks = buffer[2]; packet->data_size = size - NET_PACKETHEADERSIZE; - if(1) + if(COMPRESSION) { - huffman_decompress(&huffmanstate, &buffer[4], packet->data_size, packet->chunk_data, sizeof(packet->chunk_data)); + huffman_decompress(&huffmanstate, &buffer[3], packet->data_size, packet->chunk_data, sizeof(packet->chunk_data)); } else - mem_copy(packet->chunk_data, &buffer[4], packet->data_size); + mem_copy(packet->chunk_data, &buffer[3], packet->data_size); /* return success */ return 0; @@ -435,6 +456,7 @@ static void conn_send_control(NETCONNECTION *conn, int controlmsg, const void *e static void conn_resend(NETCONNECTION *conn) { + int resend_count = 0; int max = 10; RINGBUFFER_ITEM *item = conn->buffer.first; while(item) @@ -443,9 +465,12 @@ static void conn_resend(NETCONNECTION *conn) conn_queue_chunk(conn, resend->flags|NET_CHUNKFLAG_RESEND, resend->data_size, resend->data); item = item->next; max--; + resend_count++; if(!max) break; } + + dbg_msg("conn", "resent %d packets", resend_count); } static int conn_connect(NETCONNECTION *conn, NETADDR4 *addr) diff --git a/src/engine/server/es_server.c b/src/engine/server/es_server.c index 0d2200c3..ac1a79a1 100644 --- a/src/engine/server/es_server.c +++ b/src/engine/server/es_server.c @@ -226,6 +226,9 @@ void server_setclientname(int client_id, const char *name) if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY) return; + if(!name) + return; + str_copy(nametry, name, MAX_NAME_LENGTH); if(server_try_setclientname(client_id, nametry)) { diff --git a/src/game/client/gc_anim.h b/src/game/client/gc_anim.h index 115f7353..f6e9aac3 100644 --- a/src/game/client/gc_anim.h +++ b/src/game/client/gc_anim.h @@ -1,14 +1,14 @@ -struct animstate +struct ANIM_STATE { - keyframe body; - keyframe back_foot; - keyframe front_foot; - keyframe attach; + ANIM_KEYFRAME body; + ANIM_KEYFRAME back_foot; + ANIM_KEYFRAME front_foot; + ANIM_KEYFRAME attach; }; -void anim_seq_eval(sequence *seq, float time, keyframe *frame); -void anim_eval(animation *anim, float time, animstate *state); -void anim_add_keyframe(keyframe *seq, keyframe *added, float amount); -void anim_add(animstate *state, animstate *added, float amount); -void anim_eval_add(animstate *state, animation *anim, float time, float amount); +void anim_seq_eval(ANIM_SEQUENCE *seq, float time, ANIM_KEYFRAME *frame); +void anim_eval(ANIMATION *anim, float time, ANIM_STATE *state); +void anim_add_keyframe(ANIM_KEYFRAME *seq, ANIM_KEYFRAME *added, float amount); +void anim_add(ANIM_STATE *state, ANIM_STATE *added, float amount); +void anim_eval_add(ANIM_STATE *state, ANIMATION *anim, float time, float amount); diff --git a/src/game/client/gc_client.cpp b/src/game/client/gc_client.cpp index ae22a479..89c7ffcd 100644 --- a/src/game/client/gc_client.cpp +++ b/src/game/client/gc_client.cpp @@ -24,7 +24,7 @@ extern "C" { #include "gc_anim.h" #include "gc_console.h" -struct data_container *data = 0; +//struct data_container *data = 0; int64 debug_firedelay = 0; NETOBJ_PLAYER_INPUT input_data = {0}; @@ -39,7 +39,7 @@ int emoticon_selector_active = 0; int scoreboard_active = 0; static int emoticon_selected_emote = -1; -tuning_params tuning; +TUNING_PARAMS tuning; vec2 mouse_pos; vec2 local_character_pos; @@ -53,12 +53,12 @@ const NETOBJ_FLAG *flags[2] = {0,0}; const NETOBJ_GAME *gameobj = 0; */ -snapstate netobjects; +SNAPSTATE netobjects; int picked_up_weapon = -1; -client_data client_datas[MAX_CLIENTS]; -void client_data::update_render_info() +CLIENT_DATA client_datas[MAX_CLIENTS]; +void CLIENT_DATA::update_render_info() { render_info = skin_info; @@ -82,7 +82,7 @@ int64 broadcast_time = 0; void snd_play_random(int chn, int setid, float vol, vec2 pos) { - soundset *set = &data->sounds[setid]; + SOUNDSET *set = &data->sounds[setid]; if(!set->num_sounds) return; @@ -280,7 +280,7 @@ void chat_add_line(int client_id, int team, const char *line) } -killmsg killmsgs[killmsg_max]; +KILLMSG killmsgs[killmsg_max]; int killmsg_current = 0; //bool add_trail = false; @@ -347,18 +347,18 @@ void line_input::process_input(INPUT_EVENT e) } } -input_stack_handler::input_stack_handler() +INPUT_STACK_HANDLER::INPUT_STACK_HANDLER() { num_handlers = 0; } -void input_stack_handler::add_handler(callback cb, void *user) +void INPUT_STACK_HANDLER::add_handler(CALLBACK cb, void *user) { user_data[num_handlers] = user; handlers[num_handlers++] = cb; } -void input_stack_handler::dispatch_input() +void INPUT_STACK_HANDLER::dispatch_input() { for(int i = 0; i < inp_num_events(); i++) { @@ -378,7 +378,7 @@ void input_stack_handler::dispatch_input() } -input_stack_handler input_stack; +INPUT_STACK_HANDLER input_stack; extern int render_popup(const char *caption, const char *text, const char *button_text); @@ -395,7 +395,7 @@ void process_events(int snaptype) NETEVENT_DAMAGEIND *ev = (NETEVENT_DAMAGEIND *)data; effect_damage_indicator(vec2(ev->x, ev->y), get_direction(ev->angle)); } - else if(item.type == NETEVENTTYPE_AIR_JUMP) + else if(item.type == NETEVENTTYPE_AIRJUMP) { NETEVENT_COMMON *ev = (NETEVENT_COMMON *)data; effect_air_jump(vec2(ev->x, ev->y)); @@ -420,9 +420,9 @@ void process_events(int snaptype) NETEVENT_DEATH *ev = (NETEVENT_DEATH *)data; effect_playerdeath(vec2(ev->x, ev->y), ev->cid); } - else if(item.type == NETEVENTTYPE_SOUND_WORLD) + else if(item.type == NETEVENTTYPE_SOUNDWORLD) { - NETEVENT_SOUND_WORLD *ev = (NETEVENT_SOUND_WORLD *)data; + NETEVENT_SOUNDWORLD *ev = (NETEVENT_SOUNDWORLD *)data; snd_play_random(CHN_WORLD, ev->soundid, 1.0f, vec2(ev->x, ev->y)); } } @@ -474,7 +474,7 @@ void send_kill(int client_id) client_send_msg(); } -void anim_seq_eval(sequence *seq, float time, keyframe *frame) +void anim_seq_eval(ANIM_SEQUENCE *seq, float time, ANIM_KEYFRAME *frame) { if(seq->num_frames == 0) { @@ -490,8 +490,8 @@ void anim_seq_eval(sequence *seq, float time, keyframe *frame) else { //time = max(0.0f, min(1.0f, time / duration)); // TODO: use clamp - keyframe *frame1 = 0; - keyframe *frame2 = 0; + ANIM_KEYFRAME *frame1 = 0; + ANIM_KEYFRAME *frame2 = 0; float blend = 0.0f; // TODO: make this smarter.. binary search @@ -516,7 +516,7 @@ void anim_seq_eval(sequence *seq, float time, keyframe *frame) } } -void anim_eval(animation *anim, float time, animstate *state) +void anim_eval(ANIMATION *anim, float time, ANIM_STATE *state) { anim_seq_eval(&anim->body, time, &state->body); anim_seq_eval(&anim->back_foot, time, &state->back_foot); @@ -524,14 +524,14 @@ void anim_eval(animation *anim, float time, animstate *state) anim_seq_eval(&anim->attach, time, &state->attach); } -void anim_add_keyframe(keyframe *seq, keyframe *added, float amount) +void anim_add_keyframe(ANIM_KEYFRAME *seq, ANIM_KEYFRAME *added, float amount) { seq->x += added->x*amount; seq->y += added->y*amount; seq->angle += added->angle*amount; } -void anim_add(animstate *state, animstate *added, float amount) +void anim_add(ANIM_STATE *state, ANIM_STATE *added, float amount) { anim_add_keyframe(&state->body, &added->body, amount); anim_add_keyframe(&state->back_foot, &added->back_foot, amount); @@ -539,9 +539,9 @@ void anim_add(animstate *state, animstate *added, float amount) anim_add_keyframe(&state->attach, &added->attach, amount); } -void anim_eval_add(animstate *state, animation *anim, float time, float amount) +void anim_eval_add(ANIM_STATE *state, ANIMATION *anim, float time, float amount) { - animstate add; + ANIM_STATE add; anim_eval(anim, time, &add); anim_add(state, &add, amount); } @@ -694,7 +694,7 @@ void render_spectators(float x, float y, float w) void render_scoreboard(float x, float y, float w, int team, const char *title) { - animstate idlestate; + ANIM_STATE idlestate; anim_eval(&data->animations[ANIM_BASE], 0, &idlestate); anim_eval_add(&idlestate, &data->animations[ANIM_IDLE], 0, 1.0f); @@ -892,7 +892,7 @@ void render_game() if(netobjects.local_info && netobjects.local_info->team == -1) spectate = true; - animstate idlestate; + ANIM_STATE idlestate; anim_eval(&data->animations[ANIM_BASE], 0, &idlestate); anim_eval_add(&idlestate, &data->animations[ANIM_IDLE], 0, 1.0f); @@ -1117,7 +1117,7 @@ void render_game() // render cursor if (!menu_active && !emoticon_selector_active) { - select_sprite(data->weapons[netobjects.local_character->weapon%data->num_weapons].sprite_cursor); + select_sprite(data->weapons.id[netobjects.local_character->weapon%NUM_WEAPONS].sprite_cursor); float cursorsize = 64; draw_sprite(local_target_pos.x, local_target_pos.y, cursorsize); } @@ -1132,7 +1132,7 @@ void render_game() gfx_mapscreen(0,0,300*gfx_screenaspect(),300); // if weaponstage is active, put a "glow" around the stage ammo - select_sprite(data->weapons[netobjects.local_character->weapon%data->num_weapons].sprite_proj); + select_sprite(data->weapons.id[netobjects.local_character->weapon%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); @@ -1215,7 +1215,7 @@ void render_game() { gfx_texture_set(data->images[IMAGE_GAME].id); gfx_quads_begin(); - select_sprite(data->weapons[killmsgs[r].weapon].sprite_body); + select_sprite(data->weapons.id[killmsgs[r].weapon].sprite_body); draw_sprite(x, y+28, 96); gfx_quads_end(); } @@ -1410,7 +1410,7 @@ void render_game() const char *name = client_datas[id].name; float w = gfx_text_width(0, 10, name, -1); gfx_text(0, whole-40-5-w, 300-40-15+t*20+2, 10, name, -1); - tee_render_info info = client_datas[id].render_info; + TEE_RENDER_INFO info = client_datas[id].render_info; info.size = 18.0f; render_tee(&idlestate, &info, EMOTE_NORMAL, vec2(1,0), @@ -1588,11 +1588,11 @@ void render_game() gfx_text(0, 150*gfx_screenaspect()-w/2, 35, 14, broadcast_text, -1); } - tuning_params standard_tuning; + TUNING_PARAMS standard_tuning; // render warning about non standard tuning bool flash = time_get()/(time_freq()/2)%2 == 0; - if(config.cl_warning_tuning && memcmp(&standard_tuning, &tuning, sizeof(tuning_params)) != 0) + if(config.cl_warning_tuning && memcmp(&standard_tuning, &tuning, sizeof(TUNING_PARAMS)) != 0) { const char *text = "Warning! Server is running non-standard tuning."; if(flash) diff --git a/src/game/client/gc_client.h b/src/game/client/gc_client.h index 15df5dc2..bb8a69cf 100644 --- a/src/game/client/gc_client.h +++ b/src/game/client/gc_client.h @@ -13,14 +13,14 @@ enum CHN_GLOBAL, }; -extern struct data_container *data; +//extern struct data_container *data; extern vec2 mouse_pos; extern vec2 local_character_pos; extern vec2 local_target_pos; // snap pointers -struct snapstate +struct SNAPSTATE { const NETOBJ_PLAYER_CHARACTER *local_character; const NETOBJ_PLAYER_CHARACTER *local_prev_character; @@ -33,7 +33,7 @@ struct snapstate int num_players; }; -extern snapstate netobjects; +extern SNAPSTATE netobjects; /* extern const NETOBJ_PLAYER_CHARACTER *local_character; @@ -43,11 +43,11 @@ extern const NETOBJ_FLAG *flags[2]; extern const NETOBJ_GAME *gameobj; * */ -extern tuning_params tuning; +extern TUNING_PARAMS tuning; // predicted players -extern player_core predicted_prev_player; -extern player_core predicted_player; +extern PLAYER_CORE predicted_prev_player; +extern PLAYER_CORE predicted_player; // input extern NETOBJ_PLAYER_INPUT input_data; @@ -112,13 +112,13 @@ public: unsigned cursor_offset() const { return cursor_pos; } }; -class input_stack_handler +class INPUT_STACK_HANDLER { public: - typedef bool (*callback)(INPUT_EVENT e, void *user); + typedef bool (*CALLBACK)(INPUT_EVENT e, void *user); - input_stack_handler(); - void add_handler(callback cb, void *user_data); + INPUT_STACK_HANDLER(); + void add_handler(CALLBACK cb, void *user_data); void dispatch_input(); private: @@ -127,19 +127,19 @@ private: MAX_HANDLERS=16 }; - callback handlers[MAX_HANDLERS]; + CALLBACK handlers[MAX_HANDLERS]; void *user_data[MAX_HANDLERS]; int num_handlers; }; -extern input_stack_handler input_stack; +extern INPUT_STACK_HANDLER input_stack; extern int emoticon_selector_active; // TODO: ugly extern int scoreboard_active; // TODO: ugly // client data -struct client_data +struct CLIENT_DATA { char name[64]; char skin_name[64]; @@ -148,20 +148,20 @@ struct client_data int team; int emoticon; int emoticon_start; - player_core predicted; + PLAYER_CORE predicted; - tee_render_info skin_info; // this is what the server reports - tee_render_info render_info; // this is what we use + TEE_RENDER_INFO skin_info; // this is what the server reports + TEE_RENDER_INFO render_info; // this is what we use float angle; void update_render_info(); }; -extern client_data client_datas[MAX_CLIENTS]; +extern CLIENT_DATA client_datas[MAX_CLIENTS]; // kill messages -struct killmsg +struct KILLMSG { int weapon; int victim; @@ -171,7 +171,7 @@ struct killmsg }; const int killmsg_max = 5; -extern killmsg killmsgs[killmsg_max]; +extern KILLMSG killmsgs[killmsg_max]; extern int killmsg_current; // @@ -205,7 +205,7 @@ void effect_playerdeath(vec2 pos, int cid); void effect_powerupshine(vec2 pos, vec2 size); // particles -struct particle +struct PARTICLE { void set_default() { @@ -255,7 +255,7 @@ enum NUM_PARTGROUPS }; -void particle_add(int group, particle *part); +void particle_add(int group, PARTICLE *part); void particle_render(int group); void particle_update(float time_passed); void particle_reset(); diff --git a/src/game/client/gc_effects.cpp b/src/game/client/gc_effects.cpp index 79bac29e..5a9ebfc6 100644 --- a/src/game/client/gc_effects.cpp +++ b/src/game/client/gc_effects.cpp @@ -8,7 +8,7 @@ static bool add_100hz = false; void effect_air_jump(vec2 pos) { - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_AIRJUMP; p.pos = pos + vec2(-6.0f, 16.0f); @@ -32,7 +32,7 @@ void effect_powerupshine(vec2 pos, vec2 size) if(!add_50hz) return; - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_SLICE; p.pos = pos + vec2((frandom()-0.5f)*size.x, (frandom()-0.5f)*size.y); @@ -53,7 +53,7 @@ void effect_smoketrail(vec2 pos, vec2 vel) if(!add_50hz) return; - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_SMOKE; p.pos = pos; @@ -72,7 +72,7 @@ void effect_skidtrail(vec2 pos, vec2 vel) if(!add_100hz) return; - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_SMOKE; p.pos = pos; @@ -91,7 +91,7 @@ void effect_bullettrail(vec2 pos) if(!add_100hz) return; - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_BALL; p.pos = pos; @@ -106,7 +106,7 @@ void effect_playerspawn(vec2 pos) { for(int i = 0; i < 32; i++) { - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_SHELL; p.pos = pos; @@ -137,7 +137,7 @@ void effect_playerdeath(vec2 pos, int cid) for(int i = 0; i < 64; i++) { - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_SPLAT01 + (rand()%3); p.pos = pos; @@ -170,7 +170,7 @@ void effect_explosion(vec2 pos) } // add the explosion - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_EXPL01; p.pos = pos; @@ -183,7 +183,7 @@ void effect_explosion(vec2 pos) // add the smoke for(int i = 0; i < 24; i++) { - particle p; + PARTICLE p; p.set_default(); p.spr = SPRITE_PART_SMOKE; p.pos = pos; diff --git a/src/game/client/gc_hooks.cpp b/src/game/client/gc_hooks.cpp index 36e166d4..61e5f2e8 100644 --- a/src/game/client/gc_hooks.cpp +++ b/src/game/client/gc_hooks.cpp @@ -83,7 +83,7 @@ extern "C" void modc_init() snd_set_channel(CHN_GLOBAL, 1.0f, 0.0f); // load the data container - data = load_data_from_memory(internal_data); + //data = load_data_from_memory(internal_data); // TODO: should be removed snd_set_listener_pos(0.0f, 0.0f); @@ -128,18 +128,18 @@ extern "C" void modc_shutdown() } -player_core predicted_prev_player; -player_core predicted_player; +PLAYER_CORE predicted_prev_player; +PLAYER_CORE predicted_player; static int predicted_tick = 0; static int last_new_predicted_tick = -1; extern "C" void modc_predict() { - player_core before_prev_player = predicted_prev_player; - player_core before_player = predicted_player; + PLAYER_CORE before_prev_player = predicted_prev_player; + PLAYER_CORE before_player = predicted_player; // repredict player - world_core world; + WORLD_CORE world; world.tuning = tuning; int local_cid = -1; @@ -271,10 +271,10 @@ extern "C" void modc_newsnapshot() { SNAP_ITEM item; void *data = snap_get_item(SNAP_CURRENT, index, &item); - if(netobj_secure(item.type, data, item.datasize) != 0) + if(netobj_validate(item.type, data, item.datasize) != 0) { if(config.debug) - dbg_msg("game", "invalidated %d %d (%s) %d", index, item.type, netobj_get_name(item.type), item.id); + dbg_msg("game", "invalidated index=%d type=%d (%s) size=%d id=%d", index, item.type, netobj_get_name(item.type), item.datasize, item.id); snap_invalidate_item(SNAP_CURRENT, index); } } @@ -477,7 +477,7 @@ int64 server_motd_time = 0; extern "C" void modc_message(int msgtype) { // special messages - if(msgtype == NETMSGTYPE_SV_EXTRA_PROJECTILE) + if(msgtype == NETMSGTYPE_SV_EXTRAPROJECTILE) { int num = msg_unpack_int(); @@ -499,12 +499,12 @@ extern "C" void modc_message(int msgtype) return; } - else if(msgtype == NETMSGTYPE_SV_TUNE_PARAMS) + else if(msgtype == NETMSGTYPE_SV_TUNEPARAMS) { // unpack the new tuning - tuning_params new_tuning; + TUNING_PARAMS new_tuning; int *params = (int *)&new_tuning; - for(unsigned i = 0; i < sizeof(tuning_params)/sizeof(int); i++) + for(unsigned i = 0; i < sizeof(TUNING_PARAMS)/sizeof(int); i++) params[i] = msg_unpack_int(); // check for unpacking errors @@ -595,13 +595,13 @@ extern "C" void modc_message(int msgtype) client_datas[msg->cid].update_render_info(); } - else if(msgtype == NETMSGTYPE_SV_WEAPON_PICKUP) + else if(msgtype == NETMSGTYPE_SV_WEAPONPICKUP) { - NETMSG_SV_WEAPON_PICKUP *msg = (NETMSG_SV_WEAPON_PICKUP *)rawmsg; + NETMSG_SV_WEAPONPICKUP *msg = (NETMSG_SV_WEAPONPICKUP *)rawmsg; if(config.cl_autoswitch_weapons) input_data.wanted_weapon = msg->weapon+1; } - else if(msgtype == NETMSGTYPE_SV_READY_TO_ENTER) + else if(msgtype == NETMSGTYPE_SV_READYTOENTER) { client_entergame(); } @@ -610,7 +610,7 @@ extern "C" void modc_message(int msgtype) NETMSG_SV_KILLMSG *msg = (NETMSG_SV_KILLMSG *)rawmsg; // unpack messages - killmsg kill; + KILLMSG kill; kill.killer = msg->killer; kill.victim = msg->victim; kill.weapon = msg->weapon; @@ -629,9 +629,9 @@ extern "C" void modc_message(int msgtype) client_datas[msg->cid].emoticon = msg->emoticon; client_datas[msg->cid].emoticon_start = client_tick(); } - else if(msgtype == NETMSGTYPE_SV_SOUND_GLOBAL) + else if(msgtype == NETMSGTYPE_SV_SOUNDGLOBAL) { - NETMSG_SV_SOUND_GLOBAL *msg = (NETMSG_SV_SOUND_GLOBAL *)rawmsg; + NETMSG_SV_SOUNDGLOBAL *msg = (NETMSG_SV_SOUNDGLOBAL *)rawmsg; snd_play_random(CHN_GLOBAL, msg->soundid, 1.0f, vec2(0,0)); } } diff --git a/src/game/client/gc_menu.cpp b/src/game/client/gc_menu.cpp index 10319f0b..3a41aee4 100644 --- a/src/game/client/gc_menu.cpp +++ b/src/game/client/gc_menu.cpp @@ -25,7 +25,7 @@ extern "C" { #include "gc_client.h" #include <mastersrv/mastersrv.h> -extern data_container *data; +//extern data_container *data; extern bool menu_active; //extern bool menu_game_active; @@ -959,7 +959,7 @@ static void menu2_render_serverbrowser(RECT main_view) if (selected_server) { RECT row; - static char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" }; + static const char *labels[] = { "Version:", "Game Type:", "Progression:", "Ping:" }; RECT left_column; RECT right_column; @@ -977,7 +977,7 @@ static void menu2_render_serverbrowser(RECT main_view) ui_do_label(&row, selected_server->version, font_size, -1); ui_hsplit_t(&right_column, 15.0f, &row, &right_column); - static char *game_types[] = { "DM", "TDM", "CTF" }; + static const char *game_types[] = { "DM", "TDM", "CTF" }; if (selected_server->game_type >= 0 && selected_server->game_type < (int)(sizeof(game_types)/sizeof(*game_types))) ui_do_label(&row, game_types[selected_server->game_type], font_size, -1); @@ -1285,7 +1285,7 @@ static void menu2_render_settings_player(RECT main_view) if(start < 0) start = 0; - animstate state; + ANIM_STATE state; anim_eval(&data->animations[ANIM_BASE], 0, &state); anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f); //anim_eval_add(&state, &data->animations[ANIM_WALK], fmod(client_localtime(), 1.0f), 1.0f); @@ -1307,7 +1307,7 @@ static void menu2_render_settings_player(RECT main_view) if(strcmp(s->name, config.player_skin) == 0) selected = 1; - tee_render_info info; + TEE_RENDER_INFO info; info.texture = s->org_texture; info.color_body = vec4(1,1,1,1); info.color_feet = vec4(1,1,1,1); @@ -1831,7 +1831,7 @@ int menu2_render() gfx_mapscreen(0,0,10*4/3.0f,10); gfx_clear(gui_color.r, gui_color.g, gui_color.b); - animstate state; + ANIM_STATE state; anim_eval(&data->animations[ANIM_BASE], 0, &state); anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f); //anim_eval_add(&state, &data->animations[ANIM_WALK], fmod(client_localtime(), 1.0f), 1.0f); @@ -1846,7 +1846,7 @@ int menu2_render() //int colors[2] = {65432, 9895832}; // NEW int colors[2] = {65387, 10223467}; // NEW - tee_render_info info; + TEE_RENDER_INFO info; info.texture = skin_get(i)->color_texture; info.color_feet = info.color_body = skin_get_color(colors[c]); //info.color_feet = info.color_body = vec4(1,1,1,1); diff --git a/src/game/client/gc_particles.cpp b/src/game/client/gc_particles.cpp index a0b1ff92..2c3ef36c 100644 --- a/src/game/client/gc_particles.cpp +++ b/src/game/client/gc_particles.cpp @@ -9,7 +9,7 @@ enum MAX_PARTICLES=1024*8, }; -static particle particles[MAX_PARTICLES]; +static PARTICLE particles[MAX_PARTICLES]; static int first_free = -1; static int first_part[NUM_PARTGROUPS] = {-1}; @@ -31,7 +31,7 @@ void particle_reset() } -void particle_add(int group, particle *part) +void particle_add(int group, PARTICLE *part) { if (first_free == -1) return; diff --git a/src/game/client/gc_render.cpp b/src/game/client/gc_render.cpp index 91986b6f..364b33eb 100644 --- a/src/game/client/gc_render.cpp +++ b/src/game/client/gc_render.cpp @@ -14,7 +14,7 @@ static float sprite_w_scale; static float sprite_h_scale; -void select_sprite(sprite *spr, int flags, int sx, int sy) +void select_sprite(SPRITE *spr, int flags, int sx, int sy) { int x = spr->x+sx; int y = spr->y+sy; @@ -134,7 +134,7 @@ void ui_draw_rect(const RECT *r, vec4 color, int corners, float rounding) gfx_quads_end(); } -void render_tee(animstate *anim, tee_render_info *info, int emote, vec2 dir, vec2 pos) +void render_tee(ANIM_STATE *anim, TEE_RENDER_INFO *info, int emote, vec2 dir, vec2 pos) { vec2 direction = dir; vec2 position = pos; @@ -196,7 +196,7 @@ void render_tee(animstate *anim, tee_render_info *info, int emote, vec2 dir, vec } // draw feet - keyframe *foot = f ? &anim->front_foot : &anim->back_foot; + ANIM_KEYFRAME *foot = f ? &anim->front_foot : &anim->back_foot; float w = basesize; float h = basesize/2; @@ -433,11 +433,11 @@ static void render_items() { render_projectile((const NETOBJ_PROJECTILE *)data, item.id); } - else if(item.type == NETOBJTYPE_POWERUP) + else if(item.type == NETOBJTYPE_PICKUP) { const void *prev = snap_find_item(SNAP_PREV, item.type, item.id); if(prev) - render_powerup((const NETOBJ_POWERUP *)prev, (const NETOBJ_POWERUP *)data); + render_pickup((const NETOBJ_PICKUP *)prev, (const NETOBJ_PICKUP *)data); } else if(item.type == NETOBJTYPE_LASER) { diff --git a/src/game/client/gc_render.h b/src/game/client/gc_render.h index b3439e93..508ab195 100644 --- a/src/game/client/gc_render.h +++ b/src/game/client/gc_render.h @@ -6,9 +6,9 @@ #include "../g_mapitems.h" #include "gc_ui.h" -struct tee_render_info +struct TEE_RENDER_INFO { - tee_render_info() + TEE_RENDER_INFO() { texture = -1; color_body = vec4(1,1,1,1); @@ -36,9 +36,9 @@ enum TILERENDERFLAG_EXTEND=4, }; -typedef struct sprite; +typedef struct SPRITE; -void select_sprite(sprite *spr, int flags=0, int sx=0, int sy=0); +void select_sprite(SPRITE *spr, int flags=0, int sx=0, int sy=0); void select_sprite(int id, int flags=0, int sx=0, int sy=0); void draw_sprite(float x, float y, float size); @@ -60,9 +60,9 @@ void render_particles(); void render_tilemap_generate_skip(); // object render methods (gc_render_obj.cpp) -void render_tee(class animstate *anim, tee_render_info *info, int emote, vec2 dir, vec2 pos); +void render_tee(class ANIM_STATE *anim, TEE_RENDER_INFO *info, int emote, vec2 dir, vec2 pos); void render_flag(const struct NETOBJ_FLAG *prev, const struct NETOBJ_FLAG *current); -void render_powerup(const struct NETOBJ_POWERUP *prev, const struct NETOBJ_POWERUP *current); +void render_pickup(const struct NETOBJ_PICKUP *prev, const struct NETOBJ_PICKUP *current); void render_projectile(const struct NETOBJ_PROJECTILE *current, int itemid); void render_laser(const struct NETOBJ_LASER *current); void render_player( diff --git a/src/game/client/gc_render_obj.cpp b/src/game/client/gc_render_obj.cpp index 580ca259..a6cd2b69 100644 --- a/src/game/client/gc_render_obj.cpp +++ b/src/game/client/gc_render_obj.cpp @@ -49,7 +49,7 @@ void render_projectile(const NETOBJ_PROJECTILE *current, int itemid) vec2 pos = calc_pos(startpos, startvel, curvature, speed, ct); vec2 prevpos = calc_pos(startpos, startvel, curvature, speed, ct-0.001f); - select_sprite(data->weapons[clamp(current->type, 0, NUM_WEAPONS-1)].sprite_proj); + select_sprite(data->weapons.id[clamp(current->type, 0, NUM_WEAPONS-1)].sprite_proj); vec2 vel = pos-prevpos; //vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick()); @@ -78,7 +78,7 @@ void render_projectile(const NETOBJ_PROJECTILE *current, int itemid) gfx_quads_end(); } -void render_powerup(const NETOBJ_POWERUP *prev, const NETOBJ_POWERUP *current) +void render_pickup(const NETOBJ_PICKUP *prev, const NETOBJ_PICKUP *current) { gfx_texture_set(data->images[IMAGE_GAME].id); gfx_quads_begin(); @@ -88,21 +88,20 @@ void render_powerup(const NETOBJ_POWERUP *prev, const NETOBJ_POWERUP *current) if (current->type == POWERUP_WEAPON) { angle = 0; //-pi/6;//-0.25f * pi * 2.0f; - select_sprite(data->weapons[clamp(current->subtype, 0, NUM_WEAPONS-1)].sprite_body); - size = data->weapons[clamp(current->subtype, 0, NUM_WEAPONS-1)].visual_size; + select_sprite(data->weapons.id[clamp(current->subtype, 0, NUM_WEAPONS-1)].sprite_body); + size = data->weapons.id[clamp(current->subtype, 0, NUM_WEAPONS-1)].visual_size; } else { const int c[] = { - SPRITE_POWERUP_HEALTH, - SPRITE_POWERUP_ARMOR, - SPRITE_POWERUP_WEAPON, - SPRITE_POWERUP_NINJA, - SPRITE_POWERUP_TIMEFIELD + SPRITE_PICKUP_HEALTH, + SPRITE_PICKUP_ARMOR, + SPRITE_PICKUP_WEAPON, + SPRITE_PICKUP_NINJA }; select_sprite(c[current->type]); - if(c[current->type] == SPRITE_POWERUP_NINJA) + if(c[current->type] == SPRITE_PICKUP_NINJA) { effect_powerupshine(pos, vec2(96,18)); size *= 2.0f; @@ -157,7 +156,7 @@ void render_laser(const struct NETOBJ_LASER *current) vec2 from = vec2(current->from_x, current->from_y); vec2 dir = normalize(pos-from); - float ticks = client_tick() + client_intratick() - current->eval_tick; + float ticks = client_tick() + client_intratick() - current->start_tick; float ms = (ticks/50.0f) * 1000.0f; float a = ms / tuning.laser_bounce_delay; a = clamp(a, 0.0f, 1.0f); @@ -222,7 +221,7 @@ void render_laser(const struct NETOBJ_LASER *current) -static void render_hand(tee_render_info *info, vec2 center_pos, vec2 dir, float angle_offset, vec2 post_rot_offset) +static void render_hand(TEE_RENDER_INFO *info, vec2 center_pos, vec2 dir, float angle_offset, vec2 post_rot_offset) { // for drawing hand //const skin *s = skin_get(skin_id); @@ -278,7 +277,7 @@ void render_player( player = *player_char; NETOBJ_PLAYER_INFO info = *player_info; - tee_render_info render_info = client_datas[info.cid].render_info; + TEE_RENDER_INFO render_info = client_datas[info.cid].render_info; // check for teamplay modes bool is_teamplay = false; @@ -353,7 +352,7 @@ void render_player( // evaluate animation float walk_time = fmod(position.x, 100.0f)/100.0f; - animstate state; + ANIM_STATE state; anim_eval(&data->animations[ANIM_BASE], 0, &state); if(inair) @@ -445,7 +444,7 @@ void render_player( // normal weapons int iw = clamp(player.weapon, 0, NUM_WEAPONS-1); - select_sprite(data->weapons[iw].sprite_body, direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); + select_sprite(data->weapons.id[iw].sprite_body, direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); vec2 dir = direction; float recoil = 0.0f; @@ -454,28 +453,28 @@ void render_player( { // Static position for hammer p = position + vec2(state.attach.x, state.attach.y); - p.y += data->weapons[iw].offsety; + p.y += data->weapons.id[iw].offsety; // if attack is under way, bash stuffs if(direction.x < 0) { gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2); - p.x -= data->weapons[iw].offsetx; + p.x -= data->weapons.id[iw].offsetx; } else { gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2); } - draw_sprite(p.x, p.y, data->weapons[iw].visual_size); + draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size); } else if (player.weapon == WEAPON_NINJA) { p = position; - p.y += data->weapons[iw].offsety; + p.y += data->weapons.id[iw].offsety; if(direction.x < 0) { gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2); - p.x -= data->weapons[iw].offsetx; + p.x -= data->weapons.id[iw].offsetx; effect_powerupshine(p+vec2(32,0), vec2(32,12)); } else @@ -483,24 +482,24 @@ void render_player( gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2); effect_powerupshine(p-vec2(32,0), vec2(32,12)); } - draw_sprite(p.x, p.y, data->weapons[iw].visual_size); + draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size); // HADOKEN - if ((client_tick()-player.attacktick) <= (SERVER_TICK_SPEED / 6) && data->weapons[iw].nummuzzlesprites) + if ((client_tick()-player.attacktick) <= (SERVER_TICK_SPEED / 6) && data->weapons.id[iw].num_sprite_muzzles) { - int itex = rand() % data->weapons[iw].nummuzzlesprites; + int itex = rand() % data->weapons.id[iw].num_sprite_muzzles; float alpha = 1.0f; - if (alpha > 0.0f && data->weapons[iw].sprite_muzzle[itex].psprite) + if (alpha > 0.0f && data->weapons.id[iw].sprite_muzzles[itex]) { vec2 dir = vec2(player_char->x,player_char->y) - vec2(prev_char->x, prev_char->y); dir = normalize(dir); float hadokenangle = get_angle(dir); gfx_quads_setrotation(hadokenangle); //float offsety = -data->weapons[iw].muzzleoffsety; - select_sprite(data->weapons[iw].sprite_muzzle[itex].psprite, 0); + select_sprite(data->weapons.id[iw].sprite_muzzles[itex], 0); vec2 diry(-dir.y,dir.x); p = position; - float offsetx = data->weapons[iw].muzzleoffsetx; + float offsetx = data->weapons.id[iw].muzzleoffsetx; p -= dir * offsetx; draw_sprite(p.x, p.y, 160.0f); } @@ -513,36 +512,37 @@ void render_player( float a = (client_tick()-player.attacktick+intratick)/5.0f; if(a < 1) recoil = sinf(a*pi); - p = position + dir * data->weapons[iw].offsetx - dir*recoil*10.0f; - p.y += data->weapons[iw].offsety; - draw_sprite(p.x, p.y, data->weapons[iw].visual_size); + p = position + dir * data->weapons.id[iw].offsetx - dir*recoil*10.0f; + p.y += data->weapons.id[iw].offsety; + draw_sprite(p.x, p.y, data->weapons.id[iw].visual_size); } if (player.weapon == WEAPON_GUN || player.weapon == WEAPON_SHOTGUN) { // check if we're firing stuff - if (true)//prev.attackticks) + if(data->weapons.id[iw].num_sprite_muzzles)//prev.attackticks) { float alpha = 0.0f; int phase1tick = (client_tick() - player.attacktick); - if (phase1tick < (data->weapons[iw].muzzleduration + 3)) + if (phase1tick < (data->weapons.id[iw].muzzleduration + 3)) { - float t = ((((float)phase1tick) + intratick)/(float)data->weapons[iw].muzzleduration); + float t = ((((float)phase1tick) + intratick)/(float)data->weapons.id[iw].muzzleduration); alpha = LERP(2.0, 0.0f, min(1.0f,max(0.0f,t))); } - int itex = rand() % data->weapons[iw].nummuzzlesprites; - if (alpha > 0.0f && data->weapons[iw].sprite_muzzle[itex].psprite) + int itex = rand() % data->weapons.id[iw].num_sprite_muzzles; + if (alpha > 0.0f && data->weapons.id[iw].sprite_muzzles[itex]) { - float offsety = -data->weapons[iw].muzzleoffsety; - select_sprite(data->weapons[iw].sprite_muzzle[itex].psprite, direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); + float offsety = -data->weapons.id[iw].muzzleoffsety; + select_sprite(data->weapons.id[iw].sprite_muzzles[itex], direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); if(direction.x < 0) offsety = -offsety; vec2 diry(-dir.y,dir.x); - vec2 muzzlepos = p + dir * data->weapons[iw].muzzleoffsetx + diry * offsety; + vec2 muzzlepos = p + dir * data->weapons.id[iw].muzzleoffsetx + diry * offsety; - draw_sprite(muzzlepos.x, muzzlepos.y, data->weapons[iw].visual_size); + dbg_msg("", "%d", data->weapons.id[iw].num_sprite_muzzles); + draw_sprite(muzzlepos.x, muzzlepos.y, data->weapons.id[iw].visual_size); } } } @@ -561,7 +561,7 @@ void render_player( if(info.local && config.debug) { vec2 ghost_position = mix(vec2(prev_char->x, prev_char->y), vec2(player_char->x, player_char->y), client_intratick()); - tee_render_info ghost = render_info; + TEE_RENDER_INFO ghost = render_info; ghost.color_body.a = 0.5f; ghost.color_feet.a = 0.5f; render_tee(&state, &ghost, player.emote, direction, ghost_position); // render ghost diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 8b514c88..3632a034 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -139,7 +139,7 @@ int LAYERGROUP::swap_layers(int index0, int index1) return index1; } -void IMAGE::analyse_tileflags() +void EDITOR_IMAGE::analyse_tileflags() { mem_zero(tileflags, sizeof(tileflags)); @@ -1470,11 +1470,11 @@ static void extract_name(const char *filename, char *name) static void replace_image(const char *filename) { - IMAGE imginfo; + EDITOR_IMAGE imginfo; if(!gfx_load_png(&imginfo, filename)) return; - IMAGE *img = editor.map.images[editor.selected_image]; + EDITOR_IMAGE *img = editor.map.images[editor.selected_image]; gfx_unload_texture(img->tex_id); *img = imginfo; extract_name(filename, img->name); @@ -1483,11 +1483,11 @@ static void replace_image(const char *filename) static void add_image(const char *filename) { - IMAGE imginfo; + EDITOR_IMAGE imginfo; if(!gfx_load_png(&imginfo, filename)) return; - IMAGE *img = new IMAGE; + EDITOR_IMAGE *img = new EDITOR_IMAGE; *img = imginfo; img->tex_id = gfx_load_texture_raw(imginfo.width, imginfo.height, imginfo.format, imginfo.data, IMG_AUTO, 0); img->external = 1; // external by default @@ -1513,7 +1513,7 @@ static int popup_image(RECT view) RECT slot; ui_hsplit_t(&view, 2.0f, &slot, &view); ui_hsplit_t(&view, 12.0f, &slot, &view); - IMAGE *img = editor.map.images[editor.selected_image]; + EDITOR_IMAGE *img = editor.map.images[editor.selected_image]; static int external_button = 0; if(img->external) diff --git a/src/game/editor/ed_editor.hpp b/src/game/editor/ed_editor.hpp index 23dbd382..62f8871a 100644 --- a/src/game/editor/ed_editor.hpp +++ b/src/game/editor/ed_editor.hpp @@ -217,10 +217,10 @@ public: } }; -class IMAGE : public IMAGE_INFO +class EDITOR_IMAGE : public IMAGE_INFO { public: - IMAGE() + EDITOR_IMAGE() { tex_id = -1; name[0] = 0; @@ -231,7 +231,7 @@ public: format = 0; } - ~IMAGE() + ~EDITOR_IMAGE() { gfx_unload_texture(tex_id); } @@ -255,7 +255,7 @@ public: } array<LAYERGROUP*> groups; - array<IMAGE*> images; + array<EDITOR_IMAGE*> images; array<ENVELOPE*> envelopes; class LAYER_GAME *game_layer; diff --git a/src/game/editor/ed_io.cpp b/src/game/editor/ed_io.cpp index 9e0cd4a3..b27dd25e 100644 --- a/src/game/editor/ed_io.cpp +++ b/src/game/editor/ed_io.cpp @@ -133,7 +133,7 @@ void editor_load_old(DATAFILE *df, MAP *map) mapres_image *imgres = (mapres_image *)datafile_get_item(df, start+i, 0, 0); void *data = datafile_get_data(df, imgres->image_data); - IMAGE *img = new IMAGE; + EDITOR_IMAGE *img = new EDITOR_IMAGE; img->width = imgres->width; img->height = imgres->height; img->format = IMG_RGBA; @@ -213,7 +213,7 @@ int MAP::save(const char *filename) // save images for(int i = 0; i < images.len(); i++) { - IMAGE *img = images[i]; + EDITOR_IMAGE *img = images[i]; // analyse the image for when saving (should be done when we load the image) // TODO! @@ -392,7 +392,7 @@ int MAP::load(const char *filename) char *name = (char *)datafile_get_data(df, item->image_name); // copy base info - IMAGE *img = new IMAGE; + EDITOR_IMAGE *img = new EDITOR_IMAGE; img->external = item->external; if(item->external) @@ -401,7 +401,7 @@ int MAP::load(const char *filename) sprintf(buf, "data/mapres/%s.png", name); // load external - IMAGE imginfo; + EDITOR_IMAGE imginfo; if(gfx_load_png(&imginfo, buf)) { *img = imginfo; diff --git a/src/game/g_game.cpp b/src/game/g_game.cpp index 71ddc1a2..b5b37918 100644 --- a/src/game/g_game.cpp +++ b/src/game/g_game.cpp @@ -2,7 +2,7 @@ #include <string.h> #include "g_game.h" -const char *tuning_params::names[] = +const char *TUNING_PARAMS::names[] = { #define MACRO_TUNING_PARAM(name,value) #name, #include "g_tuning.h" @@ -10,7 +10,7 @@ const char *tuning_params::names[] = }; -bool tuning_params::set(int index, float value) +bool TUNING_PARAMS::set(int index, float value) { if(index < 0 || index >= num()) return false; @@ -18,7 +18,7 @@ bool tuning_params::set(int index, float value) return true; } -bool tuning_params::get(int index, float *value) +bool TUNING_PARAMS::get(int index, float *value) { if(index < 0 || index >= num()) return false; @@ -26,7 +26,7 @@ bool tuning_params::get(int index, float *value) return true; } -bool tuning_params::set(const char *name, float value) +bool TUNING_PARAMS::set(const char *name, float value) { for(int i = 0; i < num(); i++) if(strcmp(name, names[i]) == 0) @@ -34,7 +34,7 @@ bool tuning_params::set(const char *name, float value) return false; } -bool tuning_params::get(const char *name, float *value) +bool TUNING_PARAMS::get(const char *name, float *value) { for(int i = 0; i < num(); i++) if(strcmp(name, names[i]) == 0) @@ -166,7 +166,7 @@ float velocity_ramp(float value, float start, float range, float curvature) return 1.0f/pow(curvature, (value-start)/range); } -void player_core::reset() +void PLAYER_CORE::reset() { pos = vec2(0,0); vel = vec2(0,0); @@ -179,7 +179,7 @@ void player_core::reset() triggered_events = 0; } -void player_core::tick() +void PLAYER_CORE::tick() { float phys_size = 28.0f; triggered_events = 0; @@ -273,7 +273,7 @@ void player_core::tick() // Check against other players first for(int i = 0; i < MAX_CLIENTS; i++) { - player_core *p = world->players[i]; + PLAYER_CORE *p = world->players[i]; if(!p || p == this) continue; @@ -312,7 +312,7 @@ void player_core::tick() { if(hooked_player != -1) { - player_core *p = world->players[hooked_player]; + PLAYER_CORE *p = world->players[hooked_player]; if(p) hook_pos = p->pos; else @@ -366,7 +366,7 @@ void player_core::tick() { for(int i = 0; i < MAX_CLIENTS; i++) { - player_core *p = world->players[i]; + PLAYER_CORE *p = world->players[i]; if(!p) continue; @@ -414,7 +414,7 @@ void player_core::tick() vel = normalize(vel) * 6000; } -void player_core::move() +void PLAYER_CORE::move() { float rampvalue = velocity_ramp(length(vel)*50, world->tuning.velramp_start, world->tuning.velramp_range, world->tuning.velramp_curvature); @@ -423,7 +423,7 @@ void player_core::move() vel.x = vel.x*(1.0f/rampvalue); } -void player_core::write(NETOBJ_PLAYER_CORE *obj_core) +void PLAYER_CORE::write(NETOBJ_PLAYER_CORE *obj_core) { obj_core->x = (int)pos.x; obj_core->y = (int)pos.y; @@ -450,7 +450,7 @@ void player_core::write(NETOBJ_PLAYER_CORE *obj_core) obj_core->angle = (int)(a*256.0f); } -void player_core::read(const NETOBJ_PLAYER_CORE *obj_core) +void PLAYER_CORE::read(const NETOBJ_PLAYER_CORE *obj_core) { pos.x = obj_core->x; pos.y = obj_core->y; @@ -466,7 +466,7 @@ void player_core::read(const NETOBJ_PLAYER_CORE *obj_core) jumped = obj_core->jumped; } -void player_core::quantize() +void PLAYER_CORE::quantize() { NETOBJ_PLAYER_CORE c; write(&c); diff --git a/src/game/g_game.h b/src/game/g_game.h index 9803d6a2..414dfdbf 100644 --- a/src/game/g_game.h +++ b/src/game/g_game.h @@ -9,9 +9,9 @@ #include "g_collision.h" #include "g_protocol.h" -struct tuning_params +struct TUNING_PARAMS { - tuning_params() + TUNING_PARAMS() { const float ticks_per_second = 50.0f; #define MACRO_TUNING_PARAM(name,value) name.set((int)(value*100.0f)); @@ -25,7 +25,7 @@ struct tuning_params #include "g_tuning.h" #undef MACRO_TUNING_PARAM - static int num() { return sizeof(tuning_params)/sizeof(int); } + static int num() { return sizeof(TUNING_PARAMS)/sizeof(int); } bool set(int index, float value); bool set(const char *name, float value); bool get(int index, float *value); @@ -109,22 +109,22 @@ enum COREEVENT_HOOK_RETRACT=0x20, }; -class world_core +class WORLD_CORE { public: - world_core() + WORLD_CORE() { mem_zero(players, sizeof(players)); } - tuning_params tuning; - class player_core *players[MAX_CLIENTS]; + TUNING_PARAMS tuning; + class PLAYER_CORE *players[MAX_CLIENTS]; }; -class player_core +class PLAYER_CORE { public: - world_core *world; + WORLD_CORE *world; vec2 pos; vec2 vel; diff --git a/src/game/server/gs_common.h b/src/game/server/gs_common.h index efebe384..6b307cdf 100644 --- a/src/game/server/gs_common.h +++ b/src/game/server/gs_common.h @@ -3,7 +3,7 @@ #include "../generated/gs_data.h" -extern tuning_params tuning; +extern TUNING_PARAMS tuning; void create_sound_global(int sound, int target=-1); @@ -13,7 +13,7 @@ inline int cmask_all_except_one(int cid) { return 0x7fffffff^cmask_one(cid); } inline bool cmask_is_set(int mask, int cid) { return (mask&cmask_one(cid)) != 0; } // -class event_handler +class EVENT_HANDLER { static const int MAX_EVENTS = 128; static const int MAX_DATASIZE = 128*64; @@ -27,25 +27,25 @@ class event_handler int current_offset; int num_events; public: - event_handler(); + EVENT_HANDLER(); void *create(int type, int size, int mask = -1); void clear(); void snap(int snapping_client); }; -extern event_handler events; +extern EVENT_HANDLER events; // a basic entity -class entity +class ENTITY { private: - friend class game_world; - friend class player; - entity *prev_entity; - entity *next_entity; + friend class GAMEWORLD; // thy these? + friend class PLAYER; + ENTITY *prev_entity; + ENTITY *next_entity; - entity *prev_type_entity; - entity *next_type_entity; + ENTITY *prev_type_entity; + ENTITY *next_type_entity; protected: int id; public: @@ -60,8 +60,8 @@ public: FLAG_PHYSICS=0x00000002, }; - entity(int objtype); - virtual ~entity(); + ENTITY(int objtype); + virtual ~ENTITY(); virtual void reset() {} virtual void post_reset() {} @@ -79,7 +79,7 @@ public: }; -class game_world +class GAMEWORLD { void reset(); void remove_entities(); @@ -90,32 +90,32 @@ public: }; // TODO: two lists seams kinda not good, shouldn't be needed - entity *first_entity; - entity *first_entity_types[NUM_ENT_TYPES]; + ENTITY *first_entity; + ENTITY *first_entity_types[NUM_ENT_TYPES]; bool paused; bool reset_requested; - world_core core; + WORLD_CORE core; - game_world(); - ~game_world(); - int find_entities(vec2 pos, float radius, entity **ents, int max); - int find_entities(vec2 pos, float radius, entity **ents, int max, const int* types, int maxtypes); + GAMEWORLD(); + ~GAMEWORLD(); + int find_entities(vec2 pos, float radius, ENTITY **ents, int max); + int find_entities(vec2 pos, float radius, ENTITY **ents, int max, const int* types, int maxtypes); - void insert_entity(entity *ent); - void destroy_entity(entity *ent); - void remove_entity(entity *ent); + void insert_entity(ENTITY *ent); + void destroy_entity(ENTITY *ent); + void remove_entity(ENTITY *ent); // void snap(int snapping_client); void tick(); }; -extern game_world *world; +extern GAMEWORLD *world; // game object // TODO: should change name of this one -class gameobject : public entity +class GAMECONTROLLER : public ENTITY { protected: void cyclemap(); @@ -134,7 +134,7 @@ protected: public: int gametype; - gameobject(); + GAMECONTROLLER(); void do_team_score_wincheck(); void do_player_score_wincheck(); @@ -151,10 +151,10 @@ public: virtual void post_reset(); virtual void tick(); - virtual void on_player_spawn(class player *p) {} - virtual int on_player_death(class player *victim, class player *killer, int weapon); + virtual void on_player_spawn(class PLAYER *p) {} + virtual int on_player_death(class PLAYER *victim, class PLAYER *killer, int weapon); - virtual void on_player_info_change(class player *p); + virtual void on_player_info_change(class PLAYER *p); virtual void snap(int snapping_client); virtual int get_auto_team(int notthisid); @@ -162,11 +162,11 @@ public: int clampteam(int team); }; -extern gameobject *gameobj; +extern GAMECONTROLLER *gamecontroller; // TODO: move to seperate file -class powerup : public entity +class PICKUP : public ENTITY { public: static const int phys_size = 14; @@ -174,7 +174,7 @@ public: int type; int subtype; // weapon type for instance? int spawntick; - powerup(int _type, int _subtype = 0); + PICKUP(int _type, int _subtype = 0); virtual void reset(); virtual void tick(); @@ -182,7 +182,7 @@ public: }; // projectile entity -class projectile : public entity +class PROJECTILE : public ENTITY { public: enum @@ -191,7 +191,7 @@ public: }; vec2 direction; - entity *powner; // this is nasty, could be removed when client quits + ENTITY *powner; // this is nasty, could be removed when client quits int lifespan; int owner; int type; @@ -203,7 +203,7 @@ public: float force; int start_tick; - projectile(int type, int owner, vec2 pos, vec2 vel, int span, entity* powner, + PROJECTILE(int type, int owner, vec2 pos, vec2 vel, int span, ENTITY* powner, int damage, int flags, float force, int sound_impact, int weapon); vec2 get_pos(float time); @@ -214,21 +214,21 @@ public: virtual void snap(int snapping_client); }; -class laser : public entity +class LASER : public ENTITY { vec2 from; vec2 dir; float energy; int bounces; int eval_tick; - player *owner; + PLAYER *owner; bool hit_player(vec2 from, vec2 to); void do_bounce(); public: - laser(vec2 pos, vec2 direction, float start_energy, player *owner); + LASER(vec2 pos, vec2 direction, float start_energy, PLAYER *owner); virtual void reset(); virtual void tick(); @@ -236,15 +236,15 @@ public: }; // player entity -class player : public entity +class PLAYER : public ENTITY { public: static const int phys_size = 28; // weapon info - entity *hitobjects[10]; + ENTITY *hitobjects[10]; int numobjectshit; - struct weaponstat + struct WEAPONSTAT { int ammoregenstart; int ammo; @@ -316,13 +316,13 @@ public: int latency_max; // the player core for the physics - player_core core; + PLAYER_CORE core; // int64 last_chat; // - player(); + PLAYER(); void init(); virtual void reset(); virtual void destroy(); @@ -354,4 +354,4 @@ public: virtual void snap(int snaping_client); }; -extern player *players; +extern PLAYER *players; diff --git a/src/game/server/gs_game.cpp b/src/game/server/gs_game.cpp index 1f5456c3..4a8aa9bd 100644 --- a/src/game/server/gs_game.cpp +++ b/src/game/server/gs_game.cpp @@ -5,8 +5,8 @@ #include <game/g_mapitems.h> #include "gs_common.h" -gameobject::gameobject() -: entity(NETOBJTYPE_GAME) +GAMECONTROLLER::GAMECONTROLLER() +: ENTITY(NETOBJTYPE_GAME) { // select gametype if(strcmp(config.sv_gametype, "ctf") == 0) @@ -40,7 +40,7 @@ gameobject::gameobject() extern vec2 spawn_points[3][64]; extern int num_spawn_points[3]; -bool gameobject::on_entity(int index, vec2 pos) +bool GAMECONTROLLER::on_entity(int index, vec2 pos) { int type = -1; int subtype = 0; @@ -78,15 +78,15 @@ bool gameobject::on_entity(int index, vec2 pos) if(type != -1) { - powerup *ppower = new powerup(type, subtype); - ppower->pos = pos; + PICKUP *pickup = new PICKUP(type, subtype); + pickup->pos = pos; return true; } return false; } -void gameobject::endround() +void GAMECONTROLLER::endround() { if(warmup) // game can't end when we are running warmup return; @@ -96,14 +96,14 @@ void gameobject::endround() sudden_death = 0; } -void gameobject::resetgame() +void GAMECONTROLLER::resetgame() { world->reset_requested = true; } static bool is_separator(char c) { return c == ';' || c == ' ' || c == ',' || c == '\t'; } -void gameobject::startround() +void GAMECONTROLLER::startround() { resetgame(); @@ -116,7 +116,7 @@ void gameobject::startround() round_count++; } -void gameobject::cyclemap() +void GAMECONTROLLER::cyclemap() { if(!strlen(config.sv_maprotation)) return; @@ -174,7 +174,7 @@ void gameobject::cyclemap() str_copy(config.sv_map, &buf[i], sizeof(config.sv_map)); } -void gameobject::post_reset() +void GAMECONTROLLER::post_reset() { for(int i = 0; i < MAX_CLIENTS; i++) { @@ -183,7 +183,7 @@ void gameobject::post_reset() } } -void gameobject::on_player_info_change(class player *p) +void GAMECONTROLLER::on_player_info_change(class PLAYER *p) { const int team_colors[2] = {65387, 10223467}; if(is_teamplay) @@ -198,7 +198,7 @@ void gameobject::on_player_info_change(class player *p) } -int gameobject::on_player_death(class player *victim, class player *killer, int weapon) +int GAMECONTROLLER::on_player_death(class PLAYER *victim, class PLAYER *killer, int weapon) { // do scoreing if(!killer) @@ -215,12 +215,12 @@ int gameobject::on_player_death(class player *victim, class player *killer, int return 0; } -void gameobject::do_warmup(int seconds) +void GAMECONTROLLER::do_warmup(int seconds) { warmup = seconds*server_tickspeed(); } -bool gameobject::is_friendly_fire(int cid1, int cid2) +bool GAMECONTROLLER::is_friendly_fire(int cid1, int cid2) { if(cid1 == cid2) return false; @@ -234,7 +234,7 @@ bool gameobject::is_friendly_fire(int cid1, int cid2) return false; } -void gameobject::tick() +void GAMECONTROLLER::tick() { // do warmup if(warmup) @@ -283,7 +283,7 @@ void gameobject::tick() server_setbrowseinfo(gametype, prog); } -void gameobject::snap(int snapping_client) +void GAMECONTROLLER::snap(int snapping_client) { NETOBJ_GAME *game = (NETOBJ_GAME *)snap_new_item(NETOBJTYPE_GAME, 0, sizeof(NETOBJ_GAME)); game->paused = world->paused; @@ -301,7 +301,7 @@ void gameobject::snap(int snapping_client) game->teamscore_blue = teamscore[1]; } -int gameobject::get_auto_team(int notthisid) +int GAMECONTROLLER::get_auto_team(int notthisid) { int numplayers[2] = {0,0}; for(int i = 0; i < MAX_CLIENTS; i++) @@ -322,7 +322,7 @@ int gameobject::get_auto_team(int notthisid) return -1; } -bool gameobject::can_join_team(int team, int notthisid) +bool GAMECONTROLLER::can_join_team(int team, int notthisid) { (void)team; int numplayers[2] = {0,0}; @@ -338,7 +338,7 @@ bool gameobject::can_join_team(int team, int notthisid) return (numplayers[0] + numplayers[1]) < config.sv_max_clients-config.sv_spectator_slots; } -void gameobject::do_player_score_wincheck() +void GAMECONTROLLER::do_player_score_wincheck() { if(game_over_tick == -1 && !warmup) { @@ -371,7 +371,7 @@ void gameobject::do_player_score_wincheck() } } -void gameobject::do_team_score_wincheck() +void GAMECONTROLLER::do_team_score_wincheck() { if(game_over_tick == -1 && !warmup) { @@ -387,7 +387,7 @@ void gameobject::do_team_score_wincheck() } } -int gameobject::clampteam(int team) +int GAMECONTROLLER::clampteam(int team) { if(team < 0) // spectator return -1; @@ -396,4 +396,4 @@ int gameobject::clampteam(int team) return 0; } -gameobject *gameobj = 0; +GAMECONTROLLER *gamecontroller = 0; diff --git a/src/game/server/gs_game_ctf.cpp b/src/game/server/gs_game_ctf.cpp index 5c9545fb..59ec3981 100644 --- a/src/game/server/gs_game_ctf.cpp +++ b/src/game/server/gs_game_ctf.cpp @@ -4,16 +4,16 @@ #include "gs_common.h" #include "gs_game_ctf.h" -gameobject_ctf::gameobject_ctf() +GAMECONTROLLER_CTF::GAMECONTROLLER_CTF() { flags[0] = 0; flags[1] = 0; is_teamplay = true; } -bool gameobject_ctf::on_entity(int index, vec2 pos) +bool GAMECONTROLLER_CTF::on_entity(int index, vec2 pos) { - if(gameobject::on_entity(index, pos)) + if(GAMECONTROLLER::on_entity(index, pos)) return true; int team = -1; @@ -22,26 +22,26 @@ bool gameobject_ctf::on_entity(int index, vec2 pos) if(team == -1) return false; - flag *f = new flag(team); + FLAG *f = new FLAG(team); f->stand_pos = pos; f->pos = pos; flags[team] = f; return true; } -void gameobject_ctf::on_player_spawn(class player *p) +void GAMECONTROLLER_CTF::on_player_spawn(class PLAYER *p) { } -int gameobject_ctf::on_player_death(class player *victim, class player *killer, int weaponid) +int GAMECONTROLLER_CTF::on_player_death(class PLAYER *victim, class PLAYER *killer, int weaponid) { - gameobject::on_player_death(victim, killer, weaponid); + GAMECONTROLLER::on_player_death(victim, killer, weaponid); int had_flag = 0; // drop flags for(int fi = 0; fi < 2; fi++) { - flag *f = flags[fi]; + FLAG *f = flags[fi]; if(f && f->carrying_player == killer) had_flag |= 2; if(f && f->carrying_player == victim) @@ -61,15 +61,15 @@ int gameobject_ctf::on_player_death(class player *victim, class player *killer, return had_flag; } -void gameobject_ctf::tick() +void GAMECONTROLLER_CTF::tick() { - gameobject::tick(); + GAMECONTROLLER::tick(); do_team_score_wincheck(); for(int fi = 0; fi < 2; fi++) { - flag *f = flags[fi]; + FLAG *f = flags[fi]; if(!f) continue; @@ -99,9 +99,9 @@ void gameobject_ctf::tick() } else { - player *close_players[MAX_CLIENTS]; + PLAYER *close_players[MAX_CLIENTS]; int types[] = {NETOBJTYPE_PLAYER_CHARACTER}; - int num = world->find_entities(f->pos, 32.0f, (entity**)close_players, MAX_CLIENTS, types, 1); + int num = world->find_entities(f->pos, 32.0f, (ENTITY**)close_players, MAX_CLIENTS, types, 1); for(int i = 0; i < num; i++) { if(close_players[i]->team == f->team) @@ -109,7 +109,7 @@ void gameobject_ctf::tick() // return the flag if(!f->at_stand) { - player *p = close_players[i]; + PLAYER *p = close_players[i]; p->score += 1; dbg_msg("game", "flag_return player='%d:%s'", p->client_id, server_clientname(p->client_id)); @@ -161,8 +161,8 @@ void gameobject_ctf::tick() } // Flag -flag::flag(int _team) -: entity(NETOBJTYPE_FLAG) +FLAG::FLAG(int _team) +: ENTITY(NETOBJTYPE_FLAG) { team = _team; proximity_radius = phys_size; @@ -174,7 +174,7 @@ flag::flag(int _team) world->insert_entity(this); } -void flag::reset() +void FLAG::reset() { carrying_player = 0; at_stand = 1; @@ -182,7 +182,7 @@ void flag::reset() vel = vec2(0,0); } -void flag::snap(int snapping_client) +void FLAG::snap(int snapping_client) { NETOBJ_FLAG *flag = (NETOBJ_FLAG *)snap_new_item(NETOBJTYPE_FLAG, team, sizeof(NETOBJ_FLAG)); flag->x = (int)pos.x; diff --git a/src/game/server/gs_game_ctf.h b/src/game/server/gs_game_ctf.h index 107c000d..6d512815 100644 --- a/src/game/server/gs_game_ctf.h +++ b/src/game/server/gs_game_ctf.h @@ -1,26 +1,26 @@ /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ // game object -class gameobject_ctf : public gameobject +class GAMECONTROLLER_CTF : public GAMECONTROLLER { public: - class flag *flags[2]; + class FLAG *flags[2]; - gameobject_ctf(); + GAMECONTROLLER_CTF(); virtual void tick(); virtual bool on_entity(int index, vec2 pos); - virtual void on_player_spawn(class player *p); - virtual int on_player_death(class player *victim, class player *killer, int weapon); + virtual void on_player_spawn(class PLAYER *p); + virtual int on_player_death(class PLAYER *victim, class PLAYER *killer, int weapon); }; // TODO: move to seperate file -class flag : public entity +class FLAG : public ENTITY { public: static const int phys_size = 14; - player *carrying_player; + PLAYER *carrying_player; vec2 vel; vec2 stand_pos; @@ -28,7 +28,7 @@ public: int at_stand; int drop_tick; - flag(int _team); + FLAG(int _team); virtual void reset(); virtual void snap(int snapping_client); diff --git a/src/game/server/gs_game_dm.cpp b/src/game/server/gs_game_dm.cpp index 49de6b56..1d565372 100644 --- a/src/game/server/gs_game_dm.cpp +++ b/src/game/server/gs_game_dm.cpp @@ -3,8 +3,8 @@ #include "gs_common.h" #include "gs_game_dm.h" -void gameobject_dm::tick() +void GAMECONTROLLER_DM::tick() { do_player_score_wincheck(); - gameobject::tick(); + GAMECONTROLLER::tick(); } diff --git a/src/game/server/gs_game_dm.h b/src/game/server/gs_game_dm.h index 96bff3ae..99ceaec1 100644 --- a/src/game/server/gs_game_dm.h +++ b/src/game/server/gs_game_dm.h @@ -1,6 +1,6 @@ /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ // game object -class gameobject_dm : public gameobject +class GAMECONTROLLER_DM : public GAMECONTROLLER { public: virtual void tick(); diff --git a/src/game/server/gs_game_tdm.cpp b/src/game/server/gs_game_tdm.cpp index fb2f569b..10c5a7dc 100644 --- a/src/game/server/gs_game_tdm.cpp +++ b/src/game/server/gs_game_tdm.cpp @@ -3,14 +3,14 @@ #include "gs_common.h" #include "gs_game_tdm.h" -gameobject_tdm::gameobject_tdm() +GAMECONTROLLER_TDM::GAMECONTROLLER_TDM() { is_teamplay = true; } -int gameobject_tdm::on_player_death(class player *victim, class player *killer, int weapon) +int GAMECONTROLLER_TDM::on_player_death(class PLAYER *victim, class PLAYER *killer, int weapon) { - gameobject::on_player_death(victim, killer, weapon); + GAMECONTROLLER::on_player_death(victim, killer, weapon); if(weapon >= 0) { @@ -23,8 +23,8 @@ int gameobject_tdm::on_player_death(class player *victim, class player *killer, return 0; } -void gameobject_tdm::tick() +void GAMECONTROLLER_TDM::tick() { do_team_score_wincheck(); - gameobject::tick(); + GAMECONTROLLER::tick(); } diff --git a/src/game/server/gs_game_tdm.h b/src/game/server/gs_game_tdm.h index 70b4646e..516b581c 100644 --- a/src/game/server/gs_game_tdm.h +++ b/src/game/server/gs_game_tdm.h @@ -1,10 +1,10 @@ /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ // game object -class gameobject_tdm : public gameobject +class GAMECONTROLLER_TDM : public GAMECONTROLLER { public: - gameobject_tdm(); + GAMECONTROLLER_TDM(); - int on_player_death(class player *victim, class player *killer, int weapon); + int on_player_death(class PLAYER *victim, class PLAYER *killer, int weapon); virtual void tick(); }; diff --git a/src/game/server/gs_server.cpp b/src/game/server/gs_server.cpp index 5550f1a6..86d7fe32 100644 --- a/src/game/server/gs_server.cpp +++ b/src/game/server/gs_server.cpp @@ -13,21 +13,20 @@ #include "gs_game_tdm.h" #include "gs_game_dm.h" -data_container *data = 0x0; +TUNING_PARAMS tuning; -tuning_params tuning; - -class player* get_player(int index); void create_damageind(vec2 p, float angle_mod, int amount); void create_explosion(vec2 p, int owner, int weapon, bool bnodamage); void create_smoke(vec2 p); void create_playerspawn(vec2 p); void create_death(vec2 p, int who); void create_sound(vec2 pos, int sound, int mask=-1); -class player *intersect_player(vec2 pos0, vec2 pos1, float radius, vec2 &new_pos, class entity *notthis = 0); -class player *closest_player(vec2 pos, float radius, entity *notthis); -game_world *world; +PLAYER *get_player(int index); +class PLAYER *intersect_player(vec2 pos0, vec2 pos1, float radius, vec2 &new_pos, class ENTITY *notthis = 0); +class PLAYER *closest_player(vec2 pos, float radius, ENTITY *notthis); + +GAMEWORLD *world; enum { @@ -95,7 +94,7 @@ void send_emoticon(int cid, int emoticon) void send_weapon_pickup(int cid, int weapon) { - NETMSG_SV_WEAPON_PICKUP msg; + NETMSG_SV_WEAPONPICKUP msg; msg.weapon = weapon; msg.pack(MSGFLAG_VITAL); server_send_msg(cid); @@ -112,23 +111,25 @@ void send_broadcast(const char *text, int cid) void send_tuning_params(int cid) { + /* msg_pack_start(NETMSGTYPE_SV_TUNE_PARAMS, MSGFLAG_VITAL); int *params = (int *)&tuning; for(unsigned i = 0; i < sizeof(tuning_params)/sizeof(int); i++) msg_pack_int(params[i]); msg_pack_end(); server_send_msg(cid); + */ } ////////////////////////////////////////////////// // Event handler ////////////////////////////////////////////////// -event_handler::event_handler() +EVENT_HANDLER::EVENT_HANDLER() { clear(); } -void *event_handler::create(int type, int size, int mask) +void *EVENT_HANDLER::create(int type, int size, int mask) { if(num_events == MAX_EVENTS) return 0; @@ -145,13 +146,13 @@ void *event_handler::create(int type, int size, int mask) return p; } -void event_handler::clear() +void EVENT_HANDLER::clear() { num_events = 0; current_offset = 0; } -void event_handler::snap(int snapping_client) +void EVENT_HANDLER::snap(int snapping_client) { for(int i = 0; i < num_events; i++) { @@ -167,12 +168,12 @@ void event_handler::snap(int snapping_client) } } -event_handler events; +EVENT_HANDLER events; ////////////////////////////////////////////////// // Entity ////////////////////////////////////////////////// -entity::entity(int objtype) +ENTITY::ENTITY(int objtype) { this->objtype = objtype; pos = vec2(0,0); @@ -187,7 +188,7 @@ entity::entity(int objtype) next_type_entity = 0; } -entity::~entity() +ENTITY::~ENTITY() { world->remove_entity(this); snap_free_id(id); @@ -196,7 +197,7 @@ entity::~entity() ////////////////////////////////////////////////// // game world ////////////////////////////////////////////////// -game_world::game_world() +GAMEWORLD::GAMEWORLD() { paused = false; reset_requested = false; @@ -205,19 +206,19 @@ game_world::game_world() first_entity_types[i] = 0; } -game_world::~game_world() +GAMEWORLD::~GAMEWORLD() { // delete all entities while(first_entity) delete first_entity; } -int game_world::find_entities(vec2 pos, float radius, entity **ents, int max) +int GAMEWORLD::find_entities(vec2 pos, float radius, ENTITY **ents, int max) { int num = 0; - for(entity *ent = first_entity; ent; ent = ent->next_entity) + for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) { - if(!(ent->flags&entity::FLAG_PHYSICS)) + if(!(ent->flags&ENTITY::FLAG_PHYSICS)) continue; if(distance(ent->pos, pos) < radius+ent->proximity_radius) @@ -232,14 +233,14 @@ int game_world::find_entities(vec2 pos, float radius, entity **ents, int max) return num; } -int game_world::find_entities(vec2 pos, float radius, entity **ents, int max, const int* types, int maxtypes) +int GAMEWORLD::find_entities(vec2 pos, float radius, ENTITY **ents, int max, const int* types, int maxtypes) { int num = 0; for(int t = 0; t < maxtypes; t++) { - for(entity *ent = first_entity_types[types[t]]; ent; ent = ent->next_type_entity) + for(ENTITY *ent = first_entity_types[types[t]]; ent; ent = ent->next_type_entity) { - if(!(ent->flags&entity::FLAG_PHYSICS)) + if(!(ent->flags&ENTITY::FLAG_PHYSICS)) continue; if(distance(ent->pos, pos) < radius+ent->proximity_radius) @@ -255,9 +256,9 @@ int game_world::find_entities(vec2 pos, float radius, entity **ents, int max, co return num; } -void game_world::insert_entity(entity *ent) +void GAMEWORLD::insert_entity(ENTITY *ent) { - entity *cur = first_entity; + ENTITY *cur = first_entity; while(cur) { dbg_assert(cur != ent, "err"); @@ -279,12 +280,12 @@ void game_world::insert_entity(entity *ent) first_entity_types[ent->objtype] = ent; } -void game_world::destroy_entity(entity *ent) +void GAMEWORLD::destroy_entity(ENTITY *ent) { - ent->set_flag(entity::FLAG_DESTROY); + ent->set_flag(ENTITY::FLAG_DESTROY); } -void game_world::remove_entity(entity *ent) +void GAMEWORLD::remove_entity(ENTITY *ent) { // not in the list if(!ent->next_entity && !ent->prev_entity && first_entity != ent) @@ -312,34 +313,34 @@ void game_world::remove_entity(entity *ent) } // -void game_world::snap(int snapping_client) +void GAMEWORLD::snap(int snapping_client) { - for(entity *ent = first_entity; ent; ent = ent->next_entity) + for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) ent->snap(snapping_client); } -void game_world::reset() +void GAMEWORLD::reset() { // reset all entities - for(entity *ent = first_entity; ent; ent = ent->next_entity) + for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) ent->reset(); remove_entities(); - for(entity *ent = first_entity; ent; ent = ent->next_entity) + for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) ent->post_reset(); remove_entities(); reset_requested = false; } -void game_world::remove_entities() +void GAMEWORLD::remove_entities() { // destroy objects marked for destruction - entity *ent = first_entity; + ENTITY *ent = first_entity; while(ent) { - entity *next = ent->next_entity; - if(ent->flags&entity::FLAG_DESTROY) + ENTITY *next = ent->next_entity; + if(ent->flags&ENTITY::FLAG_DESTROY) { remove_entity(ent); ent->destroy(); @@ -348,7 +349,7 @@ void game_world::remove_entities() } } -void game_world::tick() +void GAMEWORLD::tick() { if(reset_requested) reset(); @@ -382,7 +383,7 @@ void game_world::tick() perf_start(&tick_scope);*/ // update all objects - for(entity *ent = first_entity; ent; ent = ent->next_entity) + for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) { /*if(ent->objtype >= 0 && ent->objtype < OBJTYPE_FLAG) perf_start(&scopes[ent->objtype]);*/ @@ -396,7 +397,7 @@ void game_world::tick() static PERFORMACE_INFO deftick_scope = {"tick_defered", 0}; perf_start(&deftick_scope);*/ - for(entity *ent = first_entity; ent; ent = ent->next_entity) + for(ENTITY *ent = first_entity; ent; ent = ent->next_entity) { /*if(ent->objtype >= 0 && ent->objtype < OBJTYPE_FLAG) perf_start(&scopes_def[ent->objtype]);*/ @@ -410,15 +411,15 @@ void game_world::tick() remove_entities(); } -struct input_count +struct INPUT_COUNT { int presses; int releases; }; -static input_count count_input(int prev, int cur) +static INPUT_COUNT count_input(int prev, int cur) { - input_count c = {0,0}; + INPUT_COUNT c = {0,0}; prev &= INPUT_STATE_MASK; cur &= INPUT_STATE_MASK; int i = prev; @@ -438,9 +439,9 @@ static input_count count_input(int prev, int cur) ////////////////////////////////////////////////// // projectile ////////////////////////////////////////////////// -projectile::projectile(int type, int owner, vec2 pos, vec2 dir, int span, entity* powner, +PROJECTILE::PROJECTILE(int type, int owner, vec2 pos, vec2 dir, int span, ENTITY* powner, int damage, int flags, float force, int sound_impact, int weapon) -: entity(NETOBJTYPE_PROJECTILE) +: ENTITY(NETOBJTYPE_PROJECTILE) { this->type = type; this->pos = pos; @@ -458,12 +459,12 @@ projectile::projectile(int type, int owner, vec2 pos, vec2 dir, int span, entity world->insert_entity(this); } -void projectile::reset() +void PROJECTILE::reset() { world->destroy_entity(this); } -vec2 projectile::get_pos(float time) +vec2 PROJECTILE::get_pos(float time) { float curvature = 0; float speed = 0; @@ -487,7 +488,7 @@ vec2 projectile::get_pos(float time) } -void projectile::tick() +void PROJECTILE::tick() { float pt = (server_tick()-start_tick-1)/(float)server_tickspeed(); @@ -500,7 +501,7 @@ void projectile::tick() int collide = col_intersect_line(prevpos, curpos, &curpos); //int collide = col_check_point((int)curpos.x, (int)curpos.y); - entity *targetplayer = (entity*)intersect_player(prevpos, curpos, 6.0f, curpos, powner); + ENTITY *targetplayer = (ENTITY*)intersect_player(prevpos, curpos, 6.0f, curpos, powner); if(targetplayer || collide || lifespan < 0) { if (lifespan >= 0 || weapon == WEAPON_GRENADE) @@ -517,7 +518,7 @@ void projectile::tick() } } -void projectile::fill_info(NETOBJ_PROJECTILE *proj) +void PROJECTILE::fill_info(NETOBJ_PROJECTILE *proj) { proj->x = (int)pos.x; proj->y = (int)pos.y; @@ -527,7 +528,7 @@ void projectile::fill_info(NETOBJ_PROJECTILE *proj) proj->type = type; } -void projectile::snap(int snapping_client) +void PROJECTILE::snap(int snapping_client) { float ct = (server_tick()-start_tick)/(float)server_tickspeed(); @@ -542,8 +543,8 @@ void projectile::snap(int snapping_client) ////////////////////////////////////////////////// // laser ////////////////////////////////////////////////// -laser::laser(vec2 pos, vec2 direction, float start_energy, player *owner) -: entity(NETOBJTYPE_LASER) +LASER::LASER(vec2 pos, vec2 direction, float start_energy, PLAYER *owner) +: ENTITY(NETOBJTYPE_LASER) { this->pos = pos; this->owner = owner; @@ -556,10 +557,10 @@ laser::laser(vec2 pos, vec2 direction, float start_energy, player *owner) } -bool laser::hit_player(vec2 from, vec2 to) +bool LASER::hit_player(vec2 from, vec2 to) { vec2 at; - player *hit = intersect_player(pos, to, 0.0f, at, owner); + PLAYER *hit = intersect_player(pos, to, 0.0f, at, owner); if(!hit) return false; @@ -570,7 +571,7 @@ bool laser::hit_player(vec2 from, vec2 to) return true; } -void laser::do_bounce() +void LASER::do_bounce() { eval_tick = server_tick(); @@ -619,12 +620,12 @@ void laser::do_bounce() //dbg_msg("laser", "%d done %f %f %f %f", server_tick(), from.x, from.y, pos.x, pos.y); } -void laser::reset() +void LASER::reset() { world->destroy_entity(this); } -void laser::tick() +void LASER::tick() { if(server_tick() > eval_tick+(server_tickspeed()*tuning.laser_bounce_delay)/1000.0f) { @@ -633,7 +634,7 @@ void laser::tick() } -void laser::snap(int snapping_client) +void LASER::snap(int snapping_client) { if(distance(players[snapping_client].pos, pos) > 1000.0f) return; @@ -643,7 +644,7 @@ void laser::snap(int snapping_client) obj->y = (int)pos.y; obj->from_x = (int)from.x; obj->from_y = (int)from.y; - obj->eval_tick = eval_tick; + obj->start_tick = eval_tick; } @@ -651,13 +652,13 @@ void laser::snap(int snapping_client) // player ////////////////////////////////////////////////// // TODO: move to separate file -player::player() -: entity(NETOBJTYPE_PLAYER_CHARACTER) +PLAYER::PLAYER() +: ENTITY(NETOBJTYPE_PLAYER_CHARACTER) { init(); } -void player::init() +void PLAYER::init() { proximity_radius = phys_size; client_id = -1; @@ -673,7 +674,7 @@ void player::init() reset(); } -void player::reset() +void PLAYER::reset() { pos = vec2(0.0f, 0.0f); core.reset(); @@ -684,7 +685,7 @@ void player::reset() //direction = vec2(0.0f, 1.0f); score = 0; dead = true; - clear_flag(entity::FLAG_PHYSICS); + clear_flag(ENTITY::FLAG_PHYSICS); spawning = false; die_tick = 0; die_pos = vec2(0,0); @@ -709,9 +710,9 @@ void player::reset() queued_weapon = -1; } -void player::destroy() { } +void PLAYER::destroy() { } -void player::set_weapon(int w) +void PLAYER::set_weapon(int w) { if(w == active_weapon) return; @@ -725,14 +726,14 @@ void player::set_weapon(int w) create_sound(pos, SOUND_WEAPON_SWITCH); } -void player::respawn() +void PLAYER::respawn() { spawning = true; } const char *get_team_name(int team) { - if(gameobj->gametype == GAMETYPE_DM) + if(gamecontroller->gametype == GAMETYPE_DM) { if(team == 0) return "game"; @@ -748,10 +749,10 @@ const char *get_team_name(int team) return "spectators"; } -void player::set_team(int new_team) +void PLAYER::set_team(int new_team) { // clamp the team - new_team = gameobj->clampteam(new_team); + new_team = gamecontroller->clampteam(new_team); if(team == new_team) return; @@ -764,7 +765,7 @@ void player::set_team(int new_team) score = 0; dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team); - gameobj->on_player_info_change(&players[client_id]); + gamecontroller->on_player_info_change(&players[client_id]); // send all info to this client for(int i = 0; i < MAX_CLIENTS; i++) @@ -777,9 +778,9 @@ void player::set_team(int new_team) vec2 spawn_points[3][64]; int num_spawn_points[3] = {0}; -struct spawneval +struct SPAWNEVAL { - spawneval() + SPAWNEVAL() { got = false; friendly_team = -1; @@ -794,7 +795,7 @@ struct spawneval vec2 die_pos; }; -static float evaluate_spawn(spawneval *eval, vec2 pos) +static float evaluate_spawn(SPAWNEVAL *eval, vec2 pos) { float score = 0.0f; @@ -804,7 +805,7 @@ static float evaluate_spawn(spawneval *eval, vec2 pos) continue; // don't count dead people - if(!(players[c].flags&entity::FLAG_PHYSICS)) + if(!(players[c].flags&ENTITY::FLAG_PHYSICS)) continue; // team mates are not as dangerous as enemies @@ -829,7 +830,7 @@ static float evaluate_spawn(spawneval *eval, vec2 pos) return score; } -static void evaluate_spawn_type(spawneval *eval, int t) +static void evaluate_spawn_type(SPAWNEVAL *eval, int t) { // get spawn point /* @@ -853,17 +854,17 @@ static void evaluate_spawn_type(spawneval *eval, int t) } } -void player::try_respawn() +void PLAYER::try_respawn() { vec2 spawnpos = vec2(100.0f, -60.0f); // get spawn point - spawneval eval; + SPAWNEVAL eval; eval.die_pos = die_pos; eval.pos = vec2(100, 100); - if(gameobj->gametype == GAMETYPE_CTF) + if(gamecontroller->gametype == GAMETYPE_CTF) { eval.friendly_team = team; @@ -878,7 +879,7 @@ void player::try_respawn() } else { - if(gameobj->gametype == GAMETYPE_TDM) + if(gamecontroller->gametype == GAMETYPE_TDM) eval.friendly_team = team; evaluate_spawn_type(&eval, 0); @@ -889,7 +890,7 @@ void player::try_respawn() spawnpos = eval.pos; // check if the position is occupado - entity *ents[2] = {0}; + ENTITY *ents[2] = {0}; int types[] = {NETOBJTYPE_PLAYER_CHARACTER}; int num_ents = world->find_entities(spawnpos, 64, ents, 2, types, 1); for(int i = 0; i < num_ents; i++) @@ -912,7 +913,7 @@ void player::try_respawn() mem_zero(&ninja, sizeof(ninja)); dead = false; - set_flag(entity::FLAG_PHYSICS); + set_flag(ENTITY::FLAG_PHYSICS); player_state = PLAYERSTATE_PLAYING; core.hook_state = HOOK_IDLE; @@ -924,7 +925,7 @@ void player::try_respawn() weapons[WEAPON_HAMMER].got = true; weapons[WEAPON_HAMMER].ammo = -1; weapons[WEAPON_GUN].got = true; - weapons[WEAPON_GUN].ammo = data->weapons[WEAPON_GUN].maxammo; + weapons[WEAPON_GUN].ammo = 10; /*weapons[WEAPON_RIFLE].got = true; weapons[WEAPON_RIFLE].ammo = -1;*/ @@ -939,10 +940,10 @@ void player::try_respawn() create_sound(pos, SOUND_PLAYER_SPAWN); create_playerspawn(pos); - gameobj->on_player_spawn(this); + gamecontroller->on_player_spawn(this); } -bool player::is_grounded() +bool PLAYER::is_grounded() { if(col_check_point((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2+5))) return true; @@ -952,11 +953,11 @@ bool player::is_grounded() } -int player::handle_ninja() +int PLAYER::handle_ninja() { vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); - if ((server_tick() - ninja.activationtick) > (data->weapons[WEAPON_NINJA].duration * server_tickspeed() / 1000)) + if ((server_tick() - ninja.activationtick) > (data->weapons.ninja.duration * server_tickspeed() / 1000)) { // time's up, return weapons[WEAPON_NINJA].got = false; @@ -976,8 +977,8 @@ int player::handle_ninja() // ok then, activate ninja attack_tick = server_tick(); ninja.activationdir = direction; - ninja.currentmovetime = data->weapons[WEAPON_NINJA].movetime * server_tickspeed() / 1000; - ninja.currentcooldown = data->weapons[WEAPON_NINJA].firedelay * server_tickspeed() / 1000 + server_tick(); + ninja.currentmovetime = data->weapons.ninja.movetime * server_tickspeed() / 1000; + ninja.currentcooldown = data->weapons.ninja.base->firedelay * server_tickspeed() / 1000 + server_tick(); // reset hit objects numobjectshit = 0; @@ -1001,7 +1002,7 @@ int player::handle_ninja() if (ninja.currentmovetime > 0) { // Set player velocity - core.vel = ninja.activationdir * data->weapons[WEAPON_NINJA].velocity; + core.vel = ninja.activationdir * data->weapons.ninja.velocity; vec2 oldpos = pos; move_box(&core.pos, &core.vel, vec2(phys_size, phys_size), 0.0f); // reset velocity so the client doesn't predict stuff @@ -1014,7 +1015,7 @@ int player::handle_ninja() // check if we hit anything along the way { int type = NETOBJTYPE_PLAYER_CHARACTER; - entity *ents[64]; + ENTITY *ents[64]; vec2 dir = pos - oldpos; float radius = phys_size * 2.0f; //length(dir * 0.5f); vec2 center = oldpos + dir * 0.5f; @@ -1044,7 +1045,7 @@ int player::handle_ninja() // set his velocity to fast upward (for now) if(numobjectshit < 10) hitobjects[numobjectshit++] = ents[i]; - ents[i]->take_damage(vec2(0,10.0f), data->weapons[WEAPON_NINJA].meleedamage, client_id,WEAPON_NINJA); + ents[i]->take_damage(vec2(0,10.0f), data->weapons.ninja.base->damage, client_id,WEAPON_NINJA); } } return 0; @@ -1054,7 +1055,7 @@ int player::handle_ninja() } -void player::do_weaponswitch() +void PLAYER::do_weaponswitch() { if(reload_timer != 0) // make sure we have reloaded return; @@ -1069,7 +1070,7 @@ void player::do_weaponswitch() set_weapon(queued_weapon); } -void player::handle_weaponswitch() +void PLAYER::handle_weaponswitch() { int wanted_weapon = active_weapon; if(queued_weapon != -1) @@ -1110,7 +1111,7 @@ void player::handle_weaponswitch() do_weaponswitch(); } -void player::fire_weapon() +void PLAYER::fire_weapon() { if(reload_timer != 0 || active_weapon == WEAPON_NINJA) return; @@ -1149,12 +1150,12 @@ void player::fire_weapon() create_sound(pos, SOUND_HAMMER_FIRE); int type = NETOBJTYPE_PLAYER_CHARACTER; - entity *ents[64]; + ENTITY *ents[64]; int num = world->find_entities(pos+direction*phys_size*0.75f, phys_size*0.5f, ents, 64, &type, 1); for (int i = 0; i < num; i++) { - player *target = (player*)ents[i]; + PLAYER *target = (PLAYER*)ents[i]; if (target == this) continue; @@ -1163,7 +1164,7 @@ void player::fire_weapon() // set his velocity to fast upward (for now) create_sound(pos, SOUND_HAMMER_HIT); - ents[i]->take_damage(vec2(0,-1.0f), data->weapons[active_weapon].meleedamage, client_id, active_weapon); + ents[i]->take_damage(vec2(0,-1.0f), data->weapons.hammer.base->damage, client_id, active_weapon); vec2 dir; if (length(target->pos - pos) > 0.0f) dir = normalize(target->pos - pos); @@ -1177,7 +1178,7 @@ void player::fire_weapon() case WEAPON_GUN: { - projectile *proj = new projectile(WEAPON_GUN, + PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, client_id, projectile_startpos, direction, @@ -1189,7 +1190,7 @@ void player::fire_weapon() NETOBJ_PROJECTILE p; proj->fill_info(&p); - msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0); + msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); @@ -1203,7 +1204,7 @@ void player::fire_weapon() { int shotspread = 2; - msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0); + msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) @@ -1213,7 +1214,7 @@ void player::fire_weapon() a += spreading[i+2]; float v = 1-(abs(i)/(float)shotspread); float speed = mix((float)tuning.shotgun_speeddiff, 1.0f, v); - projectile *proj = new projectile(WEAPON_SHOTGUN, + PROJECTILE *proj = new PROJECTILE(WEAPON_SHOTGUN, client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, @@ -1237,19 +1238,19 @@ void player::fire_weapon() case WEAPON_GRENADE: { - projectile *proj = new projectile(WEAPON_GRENADE, + PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, client_id, projectile_startpos, direction, (int)(server_tickspeed()*tuning.grenade_lifetime), this, - 1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); + 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); - msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0); + msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); @@ -1261,7 +1262,7 @@ void player::fire_weapon() case WEAPON_RIFLE: { - new laser(pos, direction, tuning.laser_reach, this); + new LASER(pos, direction, tuning.laser_reach, this); create_sound(pos, SOUND_RIFLE_FIRE); } break; @@ -1270,10 +1271,10 @@ void player::fire_weapon() 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; + reload_timer = data->weapons.id[active_weapon].firedelay * server_tickspeed() / 1000; } -int player::handle_weapons() +int PLAYER::handle_weapons() { vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); @@ -1306,7 +1307,8 @@ int player::handle_weapons() fire_weapon(); // ammo regen - if (data->weapons[active_weapon].ammoregentime) + int ammoregentime = data->weapons.id[active_weapon].ammoregentime; + if(ammoregentime) { // If equipped and not active, regen ammo? if (reload_timer <= 0) @@ -1314,10 +1316,10 @@ int player::handle_weapons() if (weapons[active_weapon].ammoregenstart < 0) weapons[active_weapon].ammoregenstart = server_tick(); - if ((server_tick() - weapons[active_weapon].ammoregenstart) >= data->weapons[active_weapon].ammoregentime * server_tickspeed() / 1000) + if ((server_tick() - weapons[active_weapon].ammoregenstart) >= ammoregentime * server_tickspeed() / 1000) { // Add some ammo - weapons[active_weapon].ammo = min(weapons[active_weapon].ammo + 1, data->weapons[active_weapon].maxammo); + weapons[active_weapon].ammo = min(weapons[active_weapon].ammo + 1, 10); weapons[active_weapon].ammoregenstart = -1; } } @@ -1330,7 +1332,7 @@ int player::handle_weapons() return 0; } -void player::on_direct_input(NETOBJ_PLAYER_INPUT *new_input) +void PLAYER::on_direct_input(NETOBJ_PLAYER_INPUT *new_input) { mem_copy(&latest_previnput, &latest_input, sizeof(latest_input)); mem_copy(&latest_input, new_input, sizeof(latest_input)); @@ -1341,7 +1343,7 @@ void player::on_direct_input(NETOBJ_PLAYER_INPUT *new_input) } } -void player::tick() +void PLAYER::tick() { server_setclientscore(client_id, score); @@ -1433,7 +1435,7 @@ void player::tick() return; } -void player::tick_defered() +void PLAYER::tick_defered() { if(!dead) { @@ -1466,7 +1468,7 @@ void player::tick_defered() if(events&COREEVENT_AIR_JUMP) { create_sound(pos, SOUND_PLAYER_AIRJUMP, mask); - NETEVENT_COMMON *c = (NETEVENT_COMMON *)::events.create(NETEVENTTYPE_AIR_JUMP, sizeof(NETEVENT_COMMON), mask); + NETEVENT_COMMON *c = (NETEVENT_COMMON *)::events.create(NETEVENTTYPE_AIRJUMP, sizeof(NETEVENT_COMMON), mask); if(c) { c->x = (int)pos.x; @@ -1488,12 +1490,12 @@ void player::tick_defered() } } -void player::die(int killer, int weapon) +void PLAYER::die(int killer, int weapon) { if (dead || team == -1) return; - int mode_special = gameobj->on_player_death(this, get_player(killer), weapon); + int mode_special = gamecontroller->on_player_death(this, get_player(killer), weapon); dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", killer, server_clientname(killer), @@ -1519,11 +1521,11 @@ void player::die(int killer, int weapon) create_death(pos, client_id); } -bool player::take_damage(vec2 force, int dmg, int from, int weapon) +bool PLAYER::take_damage(vec2 force, int dmg, int from, int weapon) { core.vel += force; - if(gameobj->is_friendly_fire(client_id, from) && !config.sv_teamdamage) + if(gamecontroller->is_friendly_fire(client_id, from) && !config.sv_teamdamage) return false; // player only inflicts half damage on self @@ -1587,7 +1589,7 @@ bool player::take_damage(vec2 force, int dmg, int from, int weapon) // set attacker's face to happy (taunt!) if (from >= 0 && from != client_id) { - player *p = get_player(from); + PLAYER *p = get_player(from); p->emote_type = EMOTE_HAPPY; p->emote_stop = server_tick() + server_tickspeed(); @@ -1608,7 +1610,7 @@ bool player::take_damage(vec2 force, int dmg, int from, int weapon) return true; } -void player::snap(int snaping_client) +void PLAYER::snap(int snaping_client) { if(1) { @@ -1679,13 +1681,13 @@ void player::snap(int snaping_client) } } -player *players; +PLAYER *players; ////////////////////////////////////////////////// // powerup ////////////////////////////////////////////////// -powerup::powerup(int _type, int _subtype) -: entity(NETOBJTYPE_POWERUP) +PICKUP::PICKUP(int _type, int _subtype) +: ENTITY(NETOBJTYPE_PICKUP) { type = _type; subtype = _subtype; @@ -1697,10 +1699,10 @@ powerup::powerup(int _type, int _subtype) world->insert_entity(this); } -void powerup::reset() +void PICKUP::reset() { - if (data->powerupinfo[type].startspawntime > 0) - spawntick = server_tick() + server_tickspeed() * data->powerupinfo[type].startspawntime; + if (data->pickups[type].spawndelay > 0) + spawntick = server_tick() + server_tickspeed() * data->pickups[type].spawndelay; else spawntick = -1; } @@ -1708,7 +1710,7 @@ void powerup::reset() void send_weapon_pickup(int cid, int weapon); -void powerup::tick() +void PICKUP::tick() { // wait for respawn if(spawntick > 0) @@ -1725,7 +1727,7 @@ void powerup::tick() return; } // Check if a player intersected us - player* pplayer = closest_player(pos, 20.0f, 0); + PLAYER* pplayer = closest_player(pos, 20.0f, 0); if (pplayer) { // player picked us up, is someone was hooking us, let them go @@ -1736,27 +1738,27 @@ void powerup::tick() if(pplayer->health < 10) { create_sound(pos, SOUND_PICKUP_HEALTH); - pplayer->health = min(10, pplayer->health + data->powerupinfo[type].amount); - respawntime = data->powerupinfo[type].respawntime; + pplayer->health = min(10, pplayer->health + 1); + respawntime = data->pickups[type].respawntime; } break; case POWERUP_ARMOR: if(pplayer->armor < 10) { create_sound(pos, SOUND_PICKUP_ARMOR); - pplayer->armor = min(10, pplayer->armor + data->powerupinfo[type].amount); - respawntime = data->powerupinfo[type].respawntime; + pplayer->armor = min(10, pplayer->armor + 1); + respawntime = data->pickups[type].respawntime; } break; case POWERUP_WEAPON: if(subtype >= 0 && subtype < NUM_WEAPONS) { - if(pplayer->weapons[subtype].ammo < data->weapons[subtype].maxammo || !pplayer->weapons[subtype].got) + if(pplayer->weapons[subtype].ammo < data->weapons.id[subtype].maxammo || !pplayer->weapons[subtype].got) { pplayer->weapons[subtype].got = true; - pplayer->weapons[subtype].ammo = min(data->weapons[subtype].maxammo, pplayer->weapons[subtype].ammo + data->powerupinfo[type].amount); - respawntime = data->powerupinfo[type].respawntime; + pplayer->weapons[subtype].ammo = min(data->weapons.id[subtype].maxammo, pplayer->weapons[subtype].ammo + 10); + respawntime = data->pickups[type].respawntime; // TODO: data compiler should take care of stuff like this if(subtype == WEAPON_GRENADE) @@ -1777,16 +1779,16 @@ void powerup::tick() pplayer->weapons[WEAPON_NINJA].got = true; pplayer->last_weapon = pplayer->active_weapon; pplayer->active_weapon = WEAPON_NINJA; - respawntime = data->powerupinfo[type].respawntime; + respawntime = data->pickups[type].respawntime; create_sound(pos, SOUND_PICKUP_NINJA); // loop through all players, setting their emotes - entity *ents[64]; + ENTITY *ents[64]; const int types[] = {NETOBJTYPE_PLAYER_CHARACTER}; int num = world->find_entities(vec2(0, 0), 1000000, ents, 64, types, 1); for (int i = 0; i < num; i++) { - player *p = (player *)ents[i]; + PLAYER *p = (PLAYER *)ents[i]; if (p != pplayer) { p->emote_type = EMOTE_SURPRISE; @@ -1812,12 +1814,12 @@ void powerup::tick() } } -void powerup::snap(int snapping_client) +void PICKUP::snap(int snapping_client) { if(spawntick != -1) return; - NETOBJ_POWERUP *up = (NETOBJ_POWERUP *)snap_new_item(NETOBJTYPE_POWERUP, id, sizeof(NETOBJ_POWERUP)); + NETOBJ_PICKUP *up = (NETOBJ_PICKUP *)snap_new_item(NETOBJTYPE_PICKUP, id, sizeof(NETOBJ_PICKUP)); up->x = (int)pos.x; up->y = (int)pos.y; up->type = type; // TODO: two diffrent types? what gives? @@ -1826,7 +1828,7 @@ void powerup::snap(int snapping_client) // POWERUP END /////////////////////// -player *get_player(int index) +PLAYER *get_player(int index) { return &players[index]; } @@ -1863,7 +1865,7 @@ void create_explosion(vec2 p, int owner, int weapon, bool bnodamage) if (!bnodamage) { // deal damage - entity *ents[64]; + ENTITY *ents[64]; float radius = 128.0f; float innerradius = 42.0f; @@ -1924,7 +1926,7 @@ void create_sound(vec2 pos, int sound, int mask) return; // create a sound - NETEVENT_SOUND_WORLD *ev = (NETEVENT_SOUND_WORLD *)events.create(NETEVENTTYPE_SOUND_WORLD, sizeof(NETEVENT_SOUND_WORLD), mask); + NETEVENT_SOUNDWORLD *ev = (NETEVENT_SOUNDWORLD *)events.create(NETEVENTTYPE_SOUNDWORLD, sizeof(NETEVENT_SOUNDWORLD), mask); if(ev) { ev->x = (int)pos.x; @@ -1938,31 +1940,31 @@ void create_sound_global(int sound, int target) if (sound < 0) return; - NETMSG_SV_SOUND_GLOBAL msg; + NETMSG_SV_SOUNDGLOBAL msg; msg.soundid = sound; msg.pack(MSGFLAG_VITAL); server_send_msg(target); } // TODO: should be more general -player *intersect_player(vec2 pos0, vec2 pos1, float radius, vec2& new_pos, entity *notthis) +PLAYER *intersect_player(vec2 pos0, vec2 pos1, float radius, vec2& new_pos, ENTITY *notthis) { // Find other players float closest_len = distance(pos0, pos1) * 100.0f; vec2 line_dir = normalize(pos1-pos0); - player *closest = 0; + PLAYER *closest = 0; for(int i = 0; i < MAX_CLIENTS; i++) { - if(players[i].client_id < 0 || (entity *)&players[i] == notthis) + if(players[i].client_id < 0 || (ENTITY *)&players[i] == notthis) continue; - if(!(players[i].flags&entity::FLAG_PHYSICS)) + if(!(players[i].flags&ENTITY::FLAG_PHYSICS)) continue; vec2 intersect_pos = closest_point_on_line(pos0, pos1, players[i].pos); float len = distance(players[i].pos, intersect_pos); - if(len < player::phys_size+radius) + if(len < PLAYER::phys_size+radius) { if(len < closest_len) { @@ -1977,22 +1979,22 @@ player *intersect_player(vec2 pos0, vec2 pos1, float radius, vec2& new_pos, enti } -player *closest_player(vec2 pos, float radius, entity *notthis) +PLAYER *closest_player(vec2 pos, float radius, ENTITY *notthis) { // Find other players float closest_range = radius*2; - player *closest = 0; + PLAYER *closest = 0; for(int i = 0; i < MAX_CLIENTS; i++) { - if(players[i].client_id < 0 || (entity *)&players[i] == notthis) + if(players[i].client_id < 0 || (ENTITY *)&players[i] == notthis) continue; - if(!(players[i].flags&entity::FLAG_PHYSICS)) + if(!(players[i].flags&ENTITY::FLAG_PHYSICS)) continue; float len = distance(pos, players[i].pos); - if(len < player::phys_size+radius) + if(len < PLAYER::phys_size+radius) { if(len < closest_range) { @@ -2012,7 +2014,7 @@ void mods_tick() world->tick(); if(world->paused) // make sure that the game object always updates - gameobj->tick(); + gamecontroller->tick(); } void mods_snap(int client_id) @@ -2075,7 +2077,7 @@ void mods_connected(int client_id) if(config.sv_tournament_mode) players[client_id].team = -1; else - players[client_id].team = gameobj->get_auto_team(client_id); + players[client_id].team = gamecontroller->get_auto_team(client_id); // send motd NETMSG_SV_MOTD msg; @@ -2092,7 +2094,7 @@ void mods_client_drop(int client_id) dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id)); - gameobj->on_player_death(&players[client_id], 0, -1); + gamecontroller->on_player_death(&players[client_id], 0, -1); world->remove_entity(&players[client_id]); world->core.players[client_id] = 0x0; players[client_id].client_id = -1; @@ -2131,7 +2133,7 @@ void mods_message(int msgtype, int client_id) NETMSG_CL_SETTEAM *msg = (NETMSG_CL_SETTEAM *)rawmsg; // Switch team on given client and kill/respawn him - if(gameobj->can_join_team(msg->team, client_id)) + if(gamecontroller->can_join_team(msg->team, client_id)) players[client_id].set_team(msg->team); else { @@ -2172,7 +2174,7 @@ void mods_message(int msgtype, int client_id) // set skin str_copy(players[client_id].skin_name, msg->skin, sizeof(players[client_id].skin_name)); - gameobj->on_player_info_change(&players[client_id]); + gamecontroller->on_player_info_change(&players[client_id]); if(msgtype == NETMSGTYPE_CL_STARTINFO) { @@ -2189,7 +2191,7 @@ void mods_message(int msgtype, int client_id) send_tuning_params(client_id); // - NETMSG_SV_READY_TO_ENTER m; + NETMSG_SV_READYTOENTER m; m.pack(MSGFLAG_VITAL|MSGFLAG_FLUSH); server_send_msg(client_id); } @@ -2203,7 +2205,7 @@ void mods_message(int msgtype, int client_id) } else if (msgtype == NETMSGTYPE_CL_KILL) { - player *pplayer = get_player(client_id); + PLAYER *pplayer = get_player(client_id); pplayer->die(client_id, -1); } } @@ -2227,7 +2229,7 @@ static void con_tune_param(void *result, void *user_data) static void con_tune_reset(void *result, void *user_data) { - tuning_params p; + TUNING_PARAMS p; tuning = p; send_tuning_params(-1); console_print("tuning reset"); @@ -2247,9 +2249,9 @@ static void con_tune_dump(void *result, void *user_data) static void con_restart(void *result, void *user_data) { if(console_arg_num(result)) - gameobj->do_warmup(console_arg_int(result, 0)); + gamecontroller->do_warmup(console_arg_int(result, 0)); else - gameobj->startround(); + gamecontroller->startround(); } static void con_broadcast(void *result, void *user_data) @@ -2289,22 +2291,22 @@ void mods_console_init() void mods_init() { - if(!data) /* only load once */ - data = load_data_from_memory(internal_data); + //if(!data) /* only load once */ + //data = load_data_from_memory(internal_data); layers_init(); col_init(); - world = new game_world; - players = new player[MAX_CLIENTS]; + world = new GAMEWORLD; + players = new PLAYER[MAX_CLIENTS]; // select gametype if(strcmp(config.sv_gametype, "ctf") == 0) - gameobj = new gameobject_ctf; + gamecontroller = new GAMECONTROLLER_CTF; else if(strcmp(config.sv_gametype, "tdm") == 0) - gameobj = new gameobject_tdm; + gamecontroller = new GAMECONTROLLER_TDM; else - gameobj = new gameobject_dm; + gamecontroller = new GAMECONTROLLER_DM; // setup core world for(int i = 0; i < MAX_CLIENTS; i++) @@ -2324,11 +2326,11 @@ void mods_init() { int index = tiles[y*tmap->width+x].index - ENTITY_OFFSET; vec2 pos(x*32.0f+16.0f, y*32.0f+16.0f); - gameobj->on_entity(index, pos); + gamecontroller->on_entity(index, pos); } } - world->insert_entity(gameobj); + world->insert_entity(gamecontroller); if(config.dbg_dummies) { @@ -2336,7 +2338,7 @@ void mods_init() { mods_connected(MAX_CLIENTS-i-1); mods_client_enter(MAX_CLIENTS-i-1); - if(gameobj->gametype != GAMETYPE_DM) + if(gamecontroller->gametype != GAMETYPE_DM) players[MAX_CLIENTS-i-1].team = i&1; } } @@ -2345,9 +2347,9 @@ void mods_init() void mods_shutdown() { delete [] players; - delete gameobj; + delete gamecontroller; delete world; - gameobj = 0; + gamecontroller = 0; players = 0; world = 0; } |