diff options
| author | Olle Rosenquist <phobos99@gmail.com> | 2007-10-14 13:54:02 +0000 |
|---|---|---|
| committer | Olle Rosenquist <phobos99@gmail.com> | 2007-10-14 13:54:02 +0000 |
| commit | eba83b7e194cc6b4ba76fd5e048d81279becfc35 (patch) | |
| tree | 86d1a3dc38bcb7cc85744a68159f35d9023587e8 /src/game/server | |
| parent | 20680df032daed0d3ac9c598d2a47db5b3dd4781 (diff) | |
| download | zcatch-eba83b7e194cc6b4ba76fd5e048d81279becfc35.tar.gz zcatch-eba83b7e194cc6b4ba76fd5e048d81279becfc35.zip | |
Sniper
Diffstat (limited to 'src/game/server')
| -rw-r--r-- | src/game/server/game_server.cpp | 72 | ||||
| -rw-r--r-- | src/game/server/srv_common.h | 14 |
2 files changed, 85 insertions, 1 deletions
diff --git a/src/game/server/game_server.cpp b/src/game/server/game_server.cpp index 9821c87f..13ea42de 100644 --- a/src/game/server/game_server.cpp +++ b/src/game/server/game_server.cpp @@ -489,6 +489,8 @@ void player::try_respawn() weapons[WEAPON_HAMMER].ammo = -1; weapons[WEAPON_GUN].got = true; weapons[WEAPON_GUN].ammo = data->weapons[WEAPON_GUN].maxammo; + + active_weapon = WEAPON_GUN; last_weapon = WEAPON_HAMMER; @@ -626,6 +628,68 @@ static input_count count_input(int prev, int cur) return c; } +int player::handle_sniper() +{ + struct input_count button = count_input(previnput.fire, input.fire); + if (button.releases) + { + vec2 direction = normalize(vec2(input.target_x, input.target_y)); + // Check if we were charging, if so fire + if (weapons[WEAPON_SNIPER].weaponstage >= WEAPONSTAGE_SNIPER_CHARGING) + { + new projectile(projectile::WEAPON_PROJECTILETYPE_SNIPER, + client_id, pos+vec2(0,0), direction*50.0f, + 100 + weapons[WEAPON_SNIPER].weaponstage * 20,this, weapons[WEAPON_SNIPER].weaponstage, 0, 0, -1, WEAPON_SNIPER); + create_sound(pos, SOUND_SNIPER_FIRE); + } + // Add blowback + core.vel = -direction * 10.0f * weapons[WEAPON_SNIPER].weaponstage; + + // update ammo and stuff + weapons[WEAPON_SNIPER].ammo = max(0,weapons[WEAPON_SNIPER].ammo - weapons[WEAPON_SNIPER].weaponstage); + weapons[WEAPON_SNIPER].weaponstage = WEAPONSTAGE_SNIPER_NEUTRAL; + weapons[WEAPON_SNIPER].chargetick = 0; + } + else if (input.fire & 1) + { + // Charge!! (if we are on the ground) + if (is_grounded() && weapons[WEAPON_SNIPER].ammo > 0) + { + if (!weapons[WEAPON_SNIPER].chargetick) + { + weapons[WEAPON_SNIPER].chargetick = server_tick(); + dbg_msg("game", "Chargetick='%d:'", server_tick()); + } + if ((server_tick() - weapons[WEAPON_SNIPER].chargetick) > server_tickspeed() * data->weapons[active_weapon].chargetime) + { + if (weapons[WEAPON_SNIPER].ammo > weapons[WEAPON_SNIPER].weaponstage) + { + weapons[WEAPON_SNIPER].weaponstage++; + weapons[WEAPON_SNIPER].chargetick = server_tick(); + } + else if ((server_tick() - weapons[WEAPON_SNIPER].chargetick) > server_tickspeed() * data->weapons[active_weapon].overchargetime) + { + // Ooopsie, weapon exploded + create_explosion(pos, client_id, WEAPON_SNIPER, false); + create_sound(pos, SOUND_ROCKET_EXPLODE); + // remove this weapon and change weapon to gun + weapons[WEAPON_SNIPER].got = false; + weapons[WEAPON_SNIPER].ammo = 0; + last_weapon = active_weapon; + active_weapon = WEAPON_GUN; + return 0; + } + } + + // While charging, don't move + return MODIFIER_RETURNFLAGS_OVERRIDEVELOCITY|MODIFIER_RETURNFLAGS_NOHOOK; + } + else if (weapons[WEAPON_SNIPER].weaponstage) + weapons[WEAPON_SNIPER].weaponstage = WEAPONSTAGE_SNIPER_NEUTRAL; + } + return 0; +} + int player::handle_weapons() { vec2 direction = normalize(vec2(input.target_x, input.target_y)); @@ -686,6 +750,12 @@ int player::handle_weapons() active_weapon = new_weapon; } } + + if (active_weapon == WEAPON_SNIPER) + { + // don't update other weapons while sniper is active + return handle_sniper(); + } if(count_input(previnput.fire, input.fire).presses) //previnput.fire != input.fire && (input.fire&1)) { @@ -881,7 +951,6 @@ void player::tick() core.input = input; core.tick(); - // handle weapons handle_weapons(); /* @@ -1042,6 +1111,7 @@ void player::snap(int snaping_client) player->latency_flux = latency_max-latency_min; player->ammocount = weapons[active_weapon].ammo; + player->weaponstage = weapons[active_weapon].weaponstage; player->health = 0; player->armor = 0; player->local = 0; diff --git a/src/game/server/srv_common.h b/src/game/server/srv_common.h index 8cef2cf8..1e544753 100644 --- a/src/game/server/srv_common.h +++ b/src/game/server/srv_common.h @@ -166,6 +166,11 @@ public: enum { PROJECTILE_FLAGS_EXPLODE = 1 << 0, + + WEAPON_PROJECTILETYPE_GUN = 0, + WEAPON_PROJECTILETYPE_ROCKET = 1, + WEAPON_PROJECTILETYPE_SHOTGUN = 2, + WEAPON_PROJECTILETYPE_SNIPER = 6, }; vec2 vel; @@ -198,6 +203,12 @@ public: MODIFIER_RETURNFLAGS_OVERRIDEVELOCITY = 1 << 0, MODIFIER_RETURNFLAGS_OVERRIDEPOSITION = 1 << 1, MODIFIER_RETURNFLAGS_OVERRIDEGRAVITY = 1 << 2, + + MODIFIER_RETURNFLAGS_NOHOOK = 1 << 3, + + + WEAPONSTAGE_SNIPER_NEUTRAL = 0, + WEAPONSTAGE_SNIPER_CHARGING = 1, }; // weapon info @@ -208,6 +219,8 @@ public: int ammoregenstart; int ammo; int ammocost; + int weaponstage; + int chargetick; bool got; } weapons[NUM_WEAPONS]; int active_weapon; @@ -281,6 +294,7 @@ public: int handle_weapons(); int handle_ninja(); + int handle_sniper(); virtual void tick(); virtual void tick_defered(); |