void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_SAY, flags); msg_pack_int(team); msg_pack_string(message, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_CALLVOTE, flags); msg_pack_string(type, -1); msg_pack_string(value, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_EMOTICON, flags); msg_pack_int(cid); msg_pack_int(emoticon); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_VOTE_SET, flags); msg_pack_int(timeout); msg_pack_string(description, -1); msg_pack_string(command, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_CHAT, flags); msg_pack_int(team); msg_pack_int(cid); msg_pack_string(message, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_KILLMSG, flags); msg_pack_int(killer); msg_pack_int(victim); msg_pack_int(weapon); msg_pack_int(mode_special); msg_pack_end(); }
void send_tuning_params(int cid) { msg_pack_start(NETMSGTYPE_SV_TUNEPARAMS, MSGFLAG_VITAL); int *params = (int *)&tuning; for(unsigned i = 0; i < sizeof(tuning)/sizeof(int); i++) msg_pack_int(params[i]); msg_pack_end(); server_send_msg(cid); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_VOTE_STATUS, flags); msg_pack_int(yes); msg_pack_int(no); msg_pack_int(pass); msg_pack_int(total); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_CHANGEINFO, flags); msg_pack_string(name, -1); msg_pack_string(skin, -1); msg_pack_int(use_custom_color); msg_pack_int(color_body); msg_pack_int(color_feet); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_VOTE, flags); msg_pack_int(vote); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_KILL, flags); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_CL_SETTEAM, flags); msg_pack_int(team); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_SOUNDGLOBAL, flags); msg_pack_int(soundid); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_TUNEPARAMS, flags); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_VOTE_OPTION, flags); msg_pack_string(command, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_BROADCAST, flags); msg_pack_string(message, -1); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, flags); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_WEAPONPICKUP, flags); msg_pack_int(weapon); msg_pack_end(); }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_READYTOENTER, flags); msg_pack_end(); }
void CHARACTER::fire_weapon() { if(reload_timer != 0 || freezetime > 0) return; do_weaponswitch(); vec2 direction = normalize(vec2(latest_input.target_x, latest_input.target_y)); bool fullauto = false; if(active_weapon == WEAPON_GRENADE || active_weapon == WEAPON_SHOTGUN || active_weapon == WEAPON_RIFLE) fullauto = true; if(active_weapon == WEAPON_GUN && player->ak==1) fullauto = true; if(active_weapon == WEAPON_NINJA && col_get_ninjafly((int)pos.x, (int)pos.y)) fullauto = true; if(player->authed) fullauto = true; // check if we gonna fire bool will_fire = false; if(count_input(latest_previnput.fire, latest_input.fire).presses) will_fire = true; if(fullauto && (latest_input.fire&1) && weapons[active_weapon].ammo) will_fire = true; if(!will_fire) return; // check for ammo if(!weapons[active_weapon].ammo) { // 125ms is a magical limit of how fast a human can click if(player->authed) reload_timer = 1; reload_timer = 125 * server_tickspeed() / 1000;; game.create_sound(pos, SOUND_WEAPON_NOAMMO); return; } vec2 projectile_startpos = pos+direction*phys_size*0.75f; switch(active_weapon) { case WEAPON_HAMMER: { if(player->authed) { game.create_explosion(pos, 0, 0, true); game.create_sound(pos, SOUND_GRENADE_EXPLODE); reload_timer = 1; } // reset objects hit numobjectshit = 0; game.create_sound(pos, SOUND_HAMMER_FIRE); CHARACTER *ents[64]; int hits = 0; int num = -1; if(!game.controller->is_race() || (game.controller->is_race() && (config.sv_teamdamage || config.sv_enemy_damage))) num = game.world.find_entities(pos+direction*phys_size*0.75f, phys_size*0.5f, (ENTITY**)ents, 64, NETOBJTYPE_CHARACTER); for (int i = 0; i < num; i++) { CHARACTER *target = ents[i]; if (target == this) continue; // hit a player, give him damage and stuffs... vec2 fdir = normalize(ents[i]->pos - pos); // set his velocity to fast upward (for now) game.create_hammerhit(pos); if(config.sv_water_insta && ents[i]->team != team) { ents[i]->take_damage(vec2(0,-1.0f), 0, player->client_id, active_weapon); if(config.sv_water_strip && ents[i]->team != team && ents[i]->weapons[WEAPON_RIFLE].got) { ents[i]->weapons[WEAPON_RIFLE].got = false; //ents[i]->freezetime = config.sv_water_freezetime*2; if(ents[i]->active_weapon == WEAPON_RIFLE) ents[i]->active_weapon=WEAPON_HAMMER; } ents[i]->freezetime = config.sv_water_freezetime; game.send_emoticon(ents[i]->player->client_id, 12); } else ents[i]->take_damage(vec2(0,-1.0f), data->weapons.hammer.base->damage, player->client_id, active_weapon); vec2 dir; if (length(target->pos - pos) > 0.0f) dir = normalize(target->pos - pos); else dir = vec2(0,-1); target->core.vel += normalize(dir + vec2(0,-1.1f)) * 10.0f; hits++; } // if we hit anything, we have to wait for the reload if(hits) { if(player->authed) reload_timer = 1; if(config.sv_water_insta) { reload_timer = config.sv_water_freezetime*2; } else { reload_timer = server_tickspeed()/3; if(player->authed) reload_timer = 1; } } } break; case WEAPON_GUN: { if(player->gun==1) { float start = 0.0f; if (2%2==0) start = (-2/2 + 0.5)*135*0.001; else start = (-(2-1)/2)*135*0.001; for (float i = 0; i < 2; i+=1.0f) { float a = start+get_angle(direction)+i*135*0.001; float speed = 1.0f; float v = 1-fabs((i*135*0.001f+start)/start); if (0) speed = mix((float)750*0.001f, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, player->client_id, projectile_startpos, vec2(cos(a), sin(a))*speed+vec2(0, -0*0.001f), (int)(server_tickspeed()*tuning.gun_lifetime), 5, 0, 0, SOUND_GRENADE_EXPLODE, WEAPON_GUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); 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]); msg_pack_end(); server_send_msg(player->client_id); } } if(player->authed) { float start = 0.0f; if (3%2==0) start = (-3/2 + 0.5)*70*0.001; else start = (-(3-1)/2)*70*0.001; for (float i = 0; i < 3; i+=1.0f) { float a = start+get_angle(direction)+i*70*0.001; float speed = 1.0f; float v = 1-fabs((i*70*0.001f+start)/start); if (0) speed = mix((float)750*0.001f, 1.0f, v); PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, player->client_id, projectile_startpos, vec2(cos(a), sin(a))*speed+vec2(0, -0*0.001f), (int)(server_tickspeed()*tuning.gun_lifetime), 5, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); 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]); msg_pack_end(); server_send_msg(player->client_id); reload_timer = 5; } } PROJECTILE *proj = new PROJECTILE(WEAPON_GUN, player->client_id, projectile_startpos, direction, (int)(server_tickspeed()*tuning.gun_lifetime), 1, 0, 0, -1, WEAPON_GUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(5); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); game.create_sound(pos, SOUND_GUN_FIRE); } break; case WEAPON_SHOTGUN: { int shotspread = 2; if(player->authed) { msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) { float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; float a = get_angle(direction); 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, player->client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); reload_timer = config.sv_reload_shotgun_admin; } } if(player->shotgun==1) { msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) { float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; float a = get_angle(direction); 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, player->client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); } } msg_pack_start(NETMSGTYPE_SV_EXTRAPROJECTILE, 0); msg_pack_int(shotspread*2+1); for(int i = -shotspread; i <= shotspread; i++) { float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f}; float a = get_angle(direction); 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, player->client_id, projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), 1, 0, 0, -1, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly NETOBJ_PROJECTILE p; proj->fill_info(&p); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); } msg_pack_end(); server_send_msg(player->client_id); game.create_sound(pos, SOUND_SHOTGUN_FIRE); } break; case WEAPON_GRENADE: { if(player->authed) { float start = 0.0f; if (5%2==0) start = (-5/2 + 0.5)*75*0.001; else start = (-(5-1)/2)*75*0.001; for (float i = 0; i < 5; i+=1.0f) { PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, player->client_id, projectile_startpos, direction+vec2(start + i*75*0.001, -100*0.001f), (int)(server_tickspeed()*tuning.grenade_lifetime), 5, 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_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); reload_timer = config.sv_reload_grenade_admin; } game.create_sound(pos, SOUND_GRENADE_FIRE); } if(player->grenade==1) { float start = 0.0f; if (2%2==0) start = (-2/2 + 0.5)*130*0.001; else start = (-(2-1)/2)*130*0.001; for (float i = 0; i < 2; i+=1.0f) { PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, player->client_id, projectile_startpos, direction+vec2(start + i*130*0.001, -100*0.001f), (int)(server_tickspeed()*tuning.grenade_lifetime), 5, 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_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); } game.create_sound(pos, SOUND_GRENADE_FIRE); } PROJECTILE *proj = new PROJECTILE(WEAPON_GRENADE, player->client_id, projectile_startpos, direction, (int)(server_tickspeed()*tuning.grenade_lifetime), 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_EXTRAPROJECTILE, 0); msg_pack_int(1); for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++) msg_pack_int(((int *)&p)[i]); msg_pack_end(); server_send_msg(player->client_id); game.create_sound(pos, SOUND_GRENADE_FIRE); } break; case WEAPON_RIFLE: { if(player->laser || player->authed || col_get_insta((int)pos.x, (int)pos.y)) { new LASER(pos, direction, tuning.laser_reach, player->client_id, is_water); game.create_sound(pos, SOUND_RIFLE_FIRE); if(player->authed) reload_timer = config.sv_reload_laser_admin; } else game.send_chat_target(player->client_id, "Please buy Laser in the Shop!"); } break; case WEAPON_NINJA: { attack_tick = server_tick(); ninja.activationdir = direction; ninja.currentmovetime = data->weapons.ninja.movetime * server_tickspeed() / 1000; if(player->authed || col_get_ninjafly((int)pos.x, (int)pos.y)) { ninja.currentmovetime = data->weapons.ninja.movetime * server_tickspeed() / 2875; reload_timer = 1; game.create_explosion(pos, 0, 0, true); game.create_sound(pos, SOUND_GRENADE_EXPLODE); } game.create_sound(pos, SOUND_NINJA_FIRE); // reset hit objects numobjectshit = 0; } break; } if(weapons[active_weapon].ammo > 0 && (!game.controller->is_race() || !config.sv_infinite_ammo)) // -1 == unlimited weapons[active_weapon].ammo--; attack_tick = server_tick(); if(!reload_timer) reload_timer = data->weapons.id[active_weapon].firedelay * server_tickspeed() / 1000; }
void pack(int flags) { msg_pack_start(NETMSGTYPE_SV_VOTE_CLEAROPTIONS, flags); msg_pack_end(); }