/* * Copyright (c) 2016-2020 Marco Cawthorne * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /*QUAKED weapon_legolauncher (0 0 1) (-16 -16 0) (16 16 32) "model" "models/w_legolauncher.mdl" Household DEATH! (2003) ENTITY Lego Launcher Weapon */ enum { LEGOLAUNCHER_IDLE, LEGOLAUNCHER_SHOOT, LEGOLAUNCHER_DRAW, LEGOLAUNCHER_HOLSTER }; void w_legolauncher_precache(void) { #ifdef SERVER Sound_Precache("weapon_legolauncher.fire"); Sound_Precache("weapon_legolauncher.hit"); Sound_Precache("weapon_legolauncher.hitbody"); precache_model("models/w_legolauncher.mdl"); precache_model("models/lego.mdl"); #else precache_model("models/v_legolauncher.mdl"); precache_model("models/p_legolauncher.mdl"); #endif } void w_legolauncher_updateammo(player pl) { Weapons_UpdateAmmo(pl, __NULL__, pl.ammo_legos, __NULL__); } string w_legolauncher_wmodel(void) { return "models/w_legolauncher.mdl"; } string w_legolauncher_pmodel(player pl) { return "models/p_legolauncher.mdl"; } string w_legolauncher_deathmsg(void) { return ""; } int w_legolauncher_pickup(player pl, int new, int startammo) { #ifdef SERVER if (pl.ammo_legos < MAX_A_LEGOS) { pl.ammo_legos = bound(0, pl.ammo_legos + 40, MAX_A_LEGOS); } else { return (0); } #endif return (1); } void w_legolauncher_draw(player pl) { Weapons_SetModel("models/v_legolauncher.mdl"); Weapons_ViewAnimation(pl, LEGOLAUNCHER_DRAW); } void w_legolauncher_holster(player pl) { Weapons_ViewAnimation(pl, LEGOLAUNCHER_HOLSTER); } #ifdef SERVER void w_legolauncher_shootlego(player pl) { static void Lego_Touch(void) { FX_LegoPiece(trace_endpos); /* different effects/sounds for players and walls */ if (trace_ent.iBleeds) { FX_Blood(trace_endpos, [1,0,0]); } else { SurfData_Impact(trace_ent, trace_endpos, trace_plane_normal); } if (other.takedamage == DAMAGE_YES) { Damage_Apply(other, self.owner, 15, WEAPON_LEGOLAUNCHER, DMG_GENERIC); Sound_Play(self, CHAN_WEAPON, "weapon_legolauncher.hitbody"); } else { Sound_Play(self, CHAN_WEAPON, "weapon_legolauncher.hit"); } remove(self); } Weapons_MakeVectors(pl); entity lego = spawn(); setmodel(lego, "models/lego.mdl"); /* TODO needs to spawn more to the right */ setorigin(lego, Weapons_GetCameraPos(pl) + (v_forward * 16) + (v_right * 4) + (v_up * -8)); lego.owner = self; lego.velocity = v_forward * 2000; lego.movetype = MOVETYPE_FLY; lego.solid = SOLID_BBOX; lego.angles = vectoangles(lego.velocity); lego.avelocity[2] = 10; lego.touch = Lego_Touch; setsize(lego, [0,0,0], [0,0,0]); } #endif void w_legolauncher_primary(player pl) { if (pl.w_attack_next > 0.0) { return; } /* Ammo check */ #ifdef CLIENT if (pl.ammo_legos <= 0) { return; } #else if (pl.ammo_legos <= 0) { return; } #endif /* Actual firing */ #ifdef SERVER w_legolauncher_shootlego(pl); pl.ammo_legos--; Sound_Play(pl, CHAN_WEAPON, "weapon_legolauncher.fire"); #endif Weapons_ViewPunchAngle(pl, [-2,0,0]); Weapons_ViewAnimation(pl, LEGOLAUNCHER_SHOOT); if (self.flags & FL_CROUCHING) Animation_PlayerTop(pl, ANIM_SHOOT1HAND, 0.45f); else Animation_PlayerTop(pl, ANIM_CR_SHOOT1HAND, 0.45f); pl.w_attack_next = 0.15f; pl.w_idle_next = 5.0f; } void w_legolauncher_release(player pl) { if (pl.w_idle_next > 0.0) { return; } Weapons_ViewAnimation(pl, LEGOLAUNCHER_IDLE); pl.w_idle_next = 3.0f; } void w_legolauncher_crosshair(player pl) { #ifdef CLIENT vector aicon_pos; static vector cross_pos; cross_pos = g_hudmins + (g_hudres / 2) + [-12,-12]; drawsubpic( cross_pos, [32,32], g_crossSoda, [0,0], [1, 1], [1,0,0], 1, DRAWFLAG_NORMAL ); HUD_DrawAmmo2(); aicon_pos = g_hudmins + [g_hudres[0] - 48, g_hudres[1] - 42]; drawsubpic( aicon_pos, [52,20], "sprites/640_death.spr_0.tga", [0/128,100/128], [60/128,20/128], [1,1,1], pSeatLocal->m_flAmmo2Alpha, 0 ); #endif } float w_legolauncher_aimanim(player pl) { return self.flags & FL_CROUCHING ? ANIM_CR_AIMBOW : ANIM_AIMBOW; } int w_legolauncher_isempty(player pl) { return (pl.ammo_legos <= 0) ? true : false; } void w_legolauncher_hudpic(player pl, int selected, vector pos, float a) { #ifdef CLIENT if (w_legolauncher_isempty(pl)) { drawsubpic( pos, [80,40], g_sprWeapons, [160/256,120/256], [80/256,40/256], [1,1,1], a, DRAWFLAG_NORMAL ); } else { drawsubpic( pos, [80,40], g_sprWeapons, [160/256,80/256], [80/256,40/256], [1,1,1], a, DRAWFLAG_NORMAL ); } #endif } weapontype_t w_legolauncher_type(player pl) { return WPNTYPE_RANGED; } weapon_t w_legolauncher = { .name = "legoblock", .id = ITEM_LEGOLAUNCHER, .slot = 0, .slot_pos = 7, .draw = w_legolauncher_draw, .holster = w_legolauncher_holster, .primary = w_legolauncher_primary, .secondary = __NULL__, .reload = __NULL__, .release = w_legolauncher_release, .postdraw = w_legolauncher_crosshair, .precache = w_legolauncher_precache, .pickup = w_legolauncher_pickup, .updateammo = w_legolauncher_updateammo, .wmodel = w_legolauncher_wmodel, .pmodel = w_legolauncher_pmodel, .deathmsg = w_legolauncher_deathmsg, .aimanim = w_legolauncher_aimanim, .hudpic = w_legolauncher_hudpic, .weight = -10, .isempty = w_legolauncher_isempty, .type = w_legolauncher_type }; #ifdef SERVER void weapon_legolauncher(void) { Weapons_InitItem(WEAPON_LEGOLAUNCHER); /*item_pickup item = (item_pickup)self; item.SetRenderMode(RM_FULLBRIGHT); item.SetRenderAmt(1.0f);*/ } #endif