001 #ifndef GREEN_GUN_HH 002 #define GREEN_GUN_HH 'gghh' 003 #include "Utils.HC" 004 #include "Common"; 005 //Green weapon,spreads out 006 007 008 009 010 <1>011 012 013 014 015 016 017 018 019 020 021 022 023 024 U8 *green_mesh; 025 026 U0 InitGreenMesh() { 027 green_mesh=PrimitiveSphere3D(25); 028 CD6SetColor(green_mesh,LTGREEN); 029 } 030 031 032 #define GREEN_PUFF_TIME .1 033 class CGreenShot:CGameThing { 034 CGameThing *who_shot; 035 F64 explosion_force; 036 F64 initial_tS; 037 F64 next_puff_tS; 038 }; 039 040 #define PW_GREEN_SHOT_IDENT 'GrnShot' 041 042 U0 GreenFireGunSmoke(CGreenShot *shot) { 043 if(Game_tS<shot->next_puff_tS) 044 return; 045 F64 angle=Arg(shot->mass.DxDt,shot->mass.DyDt)+pi; 046 shot->next_puff_tS=GREEN_PUFF_TIME*(Rand+.5)+Game_tS; 047 CParticle *p; 048 I64 cnt=3; 049 while(--cnt>=0) { 050 p=ParticleNew(shot->mass.x,shot->mass.y,angle,25.*30,LTGRAY); 051 p->duration=.5; 052 p->dz=5*Sin((Rand-Rand)*pi); 053 p->dx=30*Cos(angle+(Rand-Rand)*pi/5); 054 p->dy=30.*Sin(angle+(Rand-Rand)*pi/5); 055 } 056 } 057 U0 GreenShotExplode(CGreenShot *cur,...) { 058 CExplosion *exp; 059 if(!(cur->flags&THINGF_EXPLODED)) { 060 cur->flags|=THINGF_EXPLODED; 061 exp=ExplosionNew(cur->mass.x,cur->mass.y,cur->who_shot,125); 062 //Decrease radius before it renders 063 exp->rad=25.; 064 //Lots of explosions,so dont let them bounce off of each otheR(remove mass) 065 QueRem(&cur->mass); 066 QueInit(&cur->mass); //Allow for repeat querem 067 ThingDel(cur,FALSE); //soft delete 068 } 069 } 070 U0 GreenShotHitThing(CGreenShot *gs,...) { 071 CGreenShot *who=argv[0]; 072 if(who&&gs->who_shot!=who&&who->ident!=PW_GREEN_SHOT_IDENT) 073 GreenShotExplode(gs); 074 } 075 U0 GreenShotHitLine(CGreenShot *gs,...) { 076 GreenShotExplode(gs); 077 } 078 U0 GreenShotAnimate(CGreenShot *gs,...) { 079 if(Game_tS-gs->initial_tS>3.) { 080 ThingDel(gs,FALSE); 081 return; 082 } 083 if(!(gs->flags&THINGF_EXPLODED)) 084 GreenFireGunSmoke(gs); 085 } 086 087 CGreenShot *GreenShotFire0(F64 x,F64 y,F64 force,F64 angle,CGameThing *from) { 088 CGreenShot *green=GCCAlloc(sizeof(CRocket)); 089 green->ident=PW_GREEN_SHOT_IDENT; 090 green->who_shot=from; 091 green->explosion_force=100.; 092 green->initial_tS=Game_tS; 093 green->mass.x=x+30*Cos(angle); 094 green->mass.y=y+30*Sin(angle); 095 green->mass.mass=20; 096 green->mass.who=green; 097 green->mass.DxDt=force*Cos(angle); 098 green->mass.DyDt=force*Sin(angle); 099 green->next_puff_tS=GREEN_PUFF_TIME*(Rand+.5)+Game_tS; 100 green->animate=&GreenShotAnimate; 101 green->collide_line=&GreenShotHitLine; 102 green->collide_thing=&GreenShotHitThing; 103 AddMass(&green->mass); 104 105 QueIns(&green->qnext,&game.objects); 106 green->obj=C2DObjectNewFromMesh(green_mesh); 107 AddObjectToWorld(green->obj,world); 108 } 109 U0 GreenFire(F64 x,F64 y,F64 angle,CGameThing *from) { 110 I64 cnt=7,idx; 111 F64 force,spread=pi/5; 112 angle-=spread/2; 113 spread/=ToF64(cnt); 114 for(idx=0;idx<cnt;++idx) { 115 if(idx&1==0) 116 force=200.*30; 117 else 118 force=150.*30; 119 GreenShotFire0(x,y,force,angle,from); 120 angle+=spread; 121 } 122 } 123 124 InitGreenMesh; 125 126 U0 GreenFireFinal(CWeapon *weapon,CPinworm *pw) { 127 if(pw->last_rocket_tS+.3>Game_tS) 128 return; 129 pw->last_rocket_tS=Game_tS; 130 Sweep(250,70,50); 131 GreenFire(pw->mass.x, 132 pw->mass.y, 133 pw->angle, 134 pw 135 ); 136 if(--weapon->ammo>=0) { 137 UIGridItemRemove(weapon); 138 } 139 } 140 141 CWeapon *green_weapon=WeaponTemplateNew(<1>, 142 25, 143 &GreenFireFinal 144 ); 145 146 #endif