g_turret.cpp 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516
  1. // leave this line at the top for all g_xxxx.cpp files...
  2. #include "g_headers.h"
  3. #include "g_local.h"
  4. #include "g_functions.h"
  5. #include "b_local.h"
  6. extern cvar_t *g_spskill;
  7. void G_SetEnemy( gentity_t *self, gentity_t *enemy );
  8. void finish_spawning_turret( gentity_t *base );
  9. void ObjectDie (gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath );
  10. //special routine for tracking angles between client and server -rww
  11. void turret_SetBoneAngles(gentity_t *ent, char *bone, const vec3_t angles);
  12. #define ARM_ANGLE_RANGE 60
  13. #define HEAD_ANGLE_RANGE 90
  14. #define SPF_TURRETG2_TURBO 4
  15. #define SPF_TURRETG2_LEAD_ENEMY 8
  16. #define name "models/map_objects/imp_mine/turret_canon.glm"
  17. #define name2 "models/map_objects/imp_mine/turret_damage.md3"
  18. #define name3 "models/map_objects/wedge/laser_cannon_model.glm"
  19. //------------------------------------------------------------------------------------------------------------
  20. void TurretPain( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, const vec3_t point, int damage, int mod, int hitLoc )
  21. //------------------------------------------------------------------------------------------------------------
  22. {
  23. vec3_t dir;
  24. VectorSubtract( point, self->currentOrigin, dir );
  25. VectorNormalize( dir );
  26. if ( mod == MOD_DEMP2 || mod == MOD_DEMP2_ALT )
  27. {
  28. // DEMP2 makes the turret stop shooting for a bit..and does extra feedback
  29. self->attackDebounceTime = level.time + 800 + random() * 500;
  30. G_PlayEffect( "sparks/spark_exp_nosnd", point, dir );
  31. }
  32. if ( !self->enemy )
  33. {//react to being hit
  34. G_SetEnemy( self, attacker );
  35. }
  36. G_PlayEffect( "sparks/spark_exp_nosnd", point, dir );
  37. }
  38. //------------------------------------------------------------------------------------------------------------
  39. void turret_die ( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath,int dFlags,int hitLoc )
  40. //------------------------------------------------------------------------------------------------------------
  41. {
  42. vec3_t forward = { 0,0,-1 }, pos;
  43. // Turn off the thinking of the base & use it's targets
  44. self->e_ThinkFunc = thinkF_NULL;
  45. self->e_UseFunc = useF_NULL;
  46. // clear my data
  47. self->e_DieFunc = dieF_NULL;
  48. self->takedamage = qfalse;
  49. self->health = 0;
  50. self->s.loopSound = 0;
  51. // hack the effect angle so that explode death can orient the effect properly
  52. if ( self->spawnflags & 2 )
  53. {
  54. VectorSet( forward, 0, 0, 1 );
  55. }
  56. // VectorCopy( self->currentOrigin, self->s.pos.trBase );
  57. if ( self->spawnflags & SPF_TURRETG2_TURBO )
  58. {
  59. G_PlayEffect( G_EffectIndex( "explosions/fighter_explosion2" ), self->currentOrigin, self->currentAngles );
  60. }
  61. else
  62. {
  63. if ( self->fxID > 0 )
  64. {
  65. VectorMA( self->currentOrigin, 12, forward, pos );
  66. G_PlayEffect( self->fxID, pos, forward );
  67. }
  68. }
  69. if ( self->splashDamage > 0 && self->splashRadius > 0 )
  70. {
  71. G_RadiusDamage( self->currentOrigin, attacker, self->splashDamage, self->splashRadius, attacker, MOD_UNKNOWN );
  72. }
  73. if ( self->s.eFlags & EF_SHADER_ANIM )
  74. {
  75. self->s.frame = 1; // black
  76. }
  77. self->s.weapon = 0; // crosshair code uses this to mark crosshair red
  78. if ( self->s.modelindex2 )
  79. {
  80. // switch to damage model if we should
  81. self->s.modelindex = self->s.modelindex2;
  82. VectorCopy( self->currentAngles, self->s.apos.trBase );
  83. VectorClear( self->s.apos.trDelta );
  84. if ( self->target )
  85. {
  86. G_UseTargets( self, attacker );
  87. }
  88. }
  89. else
  90. {
  91. ObjectDie( self, inflictor, attacker, damage, meansOfDeath );
  92. }
  93. }
  94. //start an animation on model_root both server side and client side
  95. void TurboLaser_SetBoneAnim(gentity_t *eweb, int startFrame, int endFrame)
  96. {
  97. //set info on the entity so it knows to start the anim on the client next snapshot.
  98. //eweb->s.eFlags |= EF_G2ANIMATING;
  99. if (eweb->s.torsoAnim == startFrame && eweb->s.legsAnim == endFrame)
  100. { //already playing this anim, let's flag it to restart
  101. //eweb->s.torsoFlip = !eweb->s.torsoFlip;
  102. }
  103. else
  104. {
  105. eweb->s.torsoAnim = startFrame;
  106. eweb->s.legsAnim = endFrame;
  107. }
  108. //now set the animation on the server ghoul2 instance.
  109. assert(&eweb->ghoul2[0]);
  110. gi.G2API_SetBoneAnim(&eweb->ghoul2[0], "model_root", startFrame, endFrame,
  111. (BONE_ANIM_OVERRIDE_FREEZE|BONE_ANIM_BLEND), 1.0f, level.time, -1, 100);
  112. }
  113. #define START_DIS 15
  114. extern void WP_FireTurboLaserMissile( gentity_t *ent, vec3_t start, vec3_t dir );
  115. //----------------------------------------------------------------
  116. static void turret_fire ( gentity_t *ent, vec3_t start, vec3_t dir )
  117. //----------------------------------------------------------------
  118. {
  119. vec3_t org, ang;
  120. gentity_t *bolt;
  121. if ( (gi.pointcontents( start, ent->s.number )&MASK_SHOT) )
  122. {
  123. return;
  124. }
  125. VectorMA( start, -START_DIS, dir, org ); // dumb....
  126. if ( ent->random )
  127. {
  128. vectoangles( dir, ang );
  129. ang[PITCH] += Q_flrand( -ent->random, ent->random );
  130. ang[YAW] += Q_flrand( -ent->random, ent->random );
  131. AngleVectors( ang, dir, NULL, NULL );
  132. }
  133. vectoangles(dir, ang);
  134. if ( (ent->spawnflags&SPF_TURRETG2_TURBO) )
  135. {
  136. //muzzle flash
  137. G_PlayEffect( G_EffectIndex( "turret/turb_muzzle_flash" ), org, ang );
  138. G_SoundOnEnt( ent, CHAN_LESS_ATTEN, "sound/vehicles/weapons/turbolaser/fire1" );
  139. WP_FireTurboLaserMissile( ent, start, dir );
  140. if ( ent->alt_fire )
  141. {
  142. TurboLaser_SetBoneAnim( ent, 2, 3 );
  143. }
  144. else
  145. {
  146. TurboLaser_SetBoneAnim( ent, 0, 1 );
  147. }
  148. }
  149. else
  150. {
  151. G_PlayEffect( "blaster/muzzle_flash", org, dir );
  152. bolt = G_Spawn();
  153. bolt->classname = "turret_proj";
  154. bolt->nextthink = level.time + 10000;
  155. bolt->e_ThinkFunc = thinkF_G_FreeEntity;
  156. bolt->s.eType = ET_MISSILE;
  157. bolt->s.weapon = WP_BLASTER;
  158. bolt->owner = ent;
  159. bolt->damage = ent->damage;
  160. bolt->dflags = DAMAGE_NO_KNOCKBACK | DAMAGE_HEAVY_WEAP_CLASS; // Don't push them around, or else we are constantly re-aiming
  161. bolt->splashDamage = 0;
  162. bolt->splashRadius = 0;
  163. bolt->methodOfDeath = MOD_ENERGY;
  164. bolt->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
  165. bolt->trigger_formation = qfalse; // don't draw tail on first frame
  166. VectorSet( bolt->maxs, 1.5, 1.5, 1.5 );
  167. VectorScale( bolt->maxs, -1, bolt->mins );
  168. bolt->s.pos.trType = TR_LINEAR;
  169. bolt->s.pos.trTime = level.time;
  170. VectorCopy( start, bolt->s.pos.trBase );
  171. VectorScale( dir, 1100, bolt->s.pos.trDelta );
  172. SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
  173. VectorCopy( start, bolt->currentOrigin);
  174. }
  175. }
  176. //-----------------------------------------------------
  177. void turret_head_think( gentity_t *self )
  178. //-----------------------------------------------------
  179. {
  180. // if it's time to fire and we have an enemy, then gun 'em down! pushDebounce time controls next fire time
  181. if ( self->enemy && self->pushDebounceTime < level.time && self->attackDebounceTime < level.time )
  182. {
  183. // set up our next fire time
  184. self->pushDebounceTime = level.time + self->wait;
  185. vec3_t fwd, org;
  186. mdxaBone_t boltMatrix;
  187. // Getting the flash bolt here
  188. gi.G2API_GetBoltMatrix( self->ghoul2,
  189. 0,
  190. (self->spawnflags&SPF_TURRETG2_TURBO) ? ( (self->alt_fire ? gi.G2API_AddBolt( &self->ghoul2[0], "*muzzle2" ) : gi.G2API_AddBolt( &self->ghoul2[0], "*muzzle1" )) ) : gi.G2API_AddBolt( &self->ghoul2[0], "*flash03" ),
  191. &boltMatrix,
  192. self->currentAngles,
  193. self->currentOrigin,
  194. level.time,
  195. NULL,
  196. self->modelScale );
  197. if ( (self->spawnflags&SPF_TURRETG2_TURBO) )
  198. {
  199. self->alt_fire = !self->alt_fire;
  200. }
  201. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org );
  202. if ( (self->spawnflags&SPF_TURRETG2_TURBO) )
  203. {
  204. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, NEGATIVE_Y, fwd );
  205. }
  206. else
  207. {
  208. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, POSITIVE_Y, fwd );
  209. }
  210. VectorMA( org, START_DIS, fwd, org );
  211. turret_fire( self, org, fwd );
  212. self->fly_sound_debounce_time = level.time;//used as lastShotTime
  213. }
  214. }
  215. //-----------------------------------------------------
  216. static void turret_aim( gentity_t *self )
  217. //-----------------------------------------------------
  218. {
  219. vec3_t enemyDir, org, org2;
  220. vec3_t desiredAngles, setAngle;
  221. float diffYaw = 0.0f, diffPitch = 0.0f;
  222. float maxYawSpeed = ( self->spawnflags & SPF_TURRETG2_TURBO ) ? 30.0f : 14.0f;
  223. float maxPitchSpeed = ( self->spawnflags & SPF_TURRETG2_TURBO ) ? 15.0f : 3.0f;
  224. // move our gun base yaw to where we should be at this time....
  225. EvaluateTrajectory( &self->s.apos, level.time, self->currentAngles );
  226. self->currentAngles[YAW] = AngleNormalize360( self->currentAngles[YAW] );
  227. self->speed = AngleNormalize360( self->speed );
  228. if ( self->enemy )
  229. {
  230. // ...then we'll calculate what new aim adjustments we should attempt to make this frame
  231. // Aim at enemy
  232. if ( self->enemy->client )
  233. {
  234. VectorCopy( self->enemy->client->renderInfo.eyePoint, org );
  235. }
  236. else
  237. {
  238. VectorCopy( self->enemy->currentOrigin, org );
  239. }
  240. if ( self->spawnflags & 2 )
  241. {
  242. org[2] -= 15;
  243. }
  244. else
  245. {
  246. org[2] -= 5;
  247. }
  248. mdxaBone_t boltMatrix;
  249. // Getting the "eye" here
  250. gi.G2API_GetBoltMatrix( self->ghoul2,
  251. 0,
  252. (self->spawnflags&SPF_TURRETG2_TURBO) ? ( (self->alt_fire ? gi.G2API_AddBolt( &self->ghoul2[0], "*muzzle2" ) : gi.G2API_AddBolt( &self->ghoul2[0], "*muzzle1" )) ) : gi.G2API_AddBolt( &self->ghoul2[0], "*flash03" ),
  253. &boltMatrix,
  254. self->currentAngles,
  255. self->s.origin,
  256. level.time,
  257. NULL,
  258. self->modelScale );
  259. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org2 );
  260. VectorSubtract( org, org2, enemyDir );
  261. vectoangles( enemyDir, desiredAngles );
  262. diffYaw = AngleSubtract( self->currentAngles[YAW], desiredAngles[YAW] );
  263. diffPitch = AngleSubtract( self->speed, desiredAngles[PITCH] );
  264. }
  265. else
  266. {
  267. // no enemy, so make us slowly sweep back and forth as if searching for a new one
  268. // diffYaw = sin( level.time * 0.0001f + self->count ) * 5.0f; // don't do this for now since it can make it go into walls.
  269. }
  270. if ( diffYaw )
  271. {
  272. // cap max speed....
  273. if ( fabs(diffYaw) > maxYawSpeed )
  274. {
  275. diffYaw = ( diffYaw >= 0 ? maxYawSpeed : -maxYawSpeed );
  276. }
  277. // ...then set up our desired yaw
  278. VectorSet( setAngle, 0.0f, diffYaw, 0.0f );
  279. VectorCopy( self->currentAngles, self->s.apos.trBase );
  280. VectorScale( setAngle,- 5, self->s.apos.trDelta );
  281. self->s.apos.trTime = level.time;
  282. self->s.apos.trType = TR_LINEAR;
  283. }
  284. if ( diffPitch )
  285. {
  286. if ( fabs(diffPitch) > maxPitchSpeed )
  287. {
  288. // cap max speed
  289. self->speed += (diffPitch > 0.0f) ? -maxPitchSpeed : maxPitchSpeed;
  290. }
  291. else
  292. {
  293. // small enough, so just add half the diff so we smooth out the stopping
  294. self->speed -= ( diffPitch );//desiredAngles[PITCH];
  295. }
  296. // Note that this is NOT interpolated, so it will be less smooth...On the other hand, it does use Ghoul2 to blend, so it may smooth it out a bit?
  297. if ( (self->spawnflags&SPF_TURRETG2_TURBO) )
  298. {
  299. if ( self->spawnflags & 2 )
  300. {
  301. VectorSet( desiredAngles, 0.0f, 0.0f, -self->speed );
  302. }
  303. else
  304. {
  305. VectorSet( desiredAngles, 0.0f, 0.0f, self->speed );
  306. }
  307. turret_SetBoneAngles(self, "pitch", desiredAngles);
  308. }
  309. else
  310. {
  311. // Note that this is NOT interpolated, so it will be less smooth...On the other hand, it does use Ghoul2 to blend, so it may smooth it out a bit?
  312. if ( self->spawnflags & 2 )
  313. {
  314. VectorSet( desiredAngles, self->speed, 0.0f, 0.0f );
  315. }
  316. else
  317. {
  318. VectorSet( desiredAngles, -self->speed, 0.0f, 0.0f );
  319. }
  320. gi.G2API_SetBoneAngles( &self->ghoul2[0], "Bone_body", desiredAngles,
  321. BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL, 100, cg.time );
  322. }
  323. }
  324. if ( diffYaw || diffPitch )
  325. {
  326. self->s.loopSound = G_SoundIndex( "sound/chars/turret/move.wav" );
  327. }
  328. else
  329. {
  330. self->s.loopSound = 0;
  331. }
  332. }
  333. //-----------------------------------------------------
  334. static void turret_turnoff( gentity_t *self )
  335. //-----------------------------------------------------
  336. {
  337. if ( self->enemy == NULL )
  338. {
  339. // we don't need to turnoff
  340. return;
  341. }
  342. if ( (self->spawnflags&SPF_TURRETG2_TURBO) )
  343. {
  344. TurboLaser_SetBoneAnim( self, 4, 5 );
  345. }
  346. // shut-down sound
  347. G_Sound( self, G_SoundIndex( "sound/chars/turret/shutdown.wav" ));
  348. // make turret play ping sound for 5 seconds
  349. self->aimDebounceTime = level.time + 5000;
  350. // Clear enemy
  351. self->enemy = NULL;
  352. }
  353. //-----------------------------------------------------
  354. static qboolean turret_find_enemies( gentity_t *self )
  355. //-----------------------------------------------------
  356. {
  357. // HACK for t2_wedge!!!
  358. if ( self->spawnflags & SPF_TURRETG2_TURBO )
  359. return qfalse;
  360. qboolean found = qfalse;
  361. int count;
  362. float bestDist = self->radius * self->radius;
  363. float enemyDist;
  364. vec3_t enemyDir, org, org2;
  365. gentity_t *entity_list[MAX_GENTITIES], *target, *bestTarget = NULL;
  366. if ( self->aimDebounceTime > level.time ) // time since we've been shut off
  367. {
  368. // We were active and alert, i.e. had an enemy in the last 3 secs
  369. if ( self->painDebounceTime < level.time )
  370. {
  371. G_Sound(self, G_SoundIndex( "sound/chars/turret/ping.wav" ));
  372. self->painDebounceTime = level.time + 1000;
  373. }
  374. }
  375. VectorCopy( self->currentOrigin, org2 );
  376. if ( self->spawnflags & 2 )
  377. {
  378. org2[2] += 20;
  379. }
  380. else
  381. {
  382. org2[2] -= 20;
  383. }
  384. count = G_RadiusList( org2, self->radius, self, qtrue, entity_list );
  385. for ( int i = 0; i < count; i++ )
  386. {
  387. target = entity_list[i];
  388. if ( !target->client )
  389. {
  390. // only attack clients
  391. continue;
  392. }
  393. if ( target == self || !target->takedamage || target->health <= 0 || ( target->flags & FL_NOTARGET ))
  394. {
  395. continue;
  396. }
  397. if ( target->client->playerTeam == self->noDamageTeam )
  398. {
  399. // A bot we don't want to shoot
  400. continue;
  401. }
  402. if ( !gi.inPVS( org2, target->currentOrigin ))
  403. {
  404. continue;
  405. }
  406. VectorCopy( target->client->renderInfo.eyePoint, org );
  407. if ( self->spawnflags & 2 )
  408. {
  409. org[2] -= 15;
  410. }
  411. else
  412. {
  413. org[2] += 5;
  414. }
  415. trace_t tr;
  416. gi.trace( &tr, org2, NULL, NULL, org, self->s.number, MASK_SHOT );
  417. if ( !tr.allsolid && !tr.startsolid && ( tr.fraction == 1.0 || tr.entityNum == target->s.number ))
  418. {
  419. // Only acquire if have a clear shot, Is it in range and closer than our best?
  420. VectorSubtract( target->currentOrigin, self->currentOrigin, enemyDir );
  421. enemyDist = VectorLengthSquared( enemyDir );
  422. if ( enemyDist < bestDist )// all things equal, keep current
  423. {
  424. if ( self->attackDebounceTime < level.time )
  425. {
  426. // We haven't fired or acquired an enemy in the last 2 seconds-start-up sound
  427. G_Sound( self, G_SoundIndex( "sound/chars/turret/startup.wav" ));
  428. // Wind up turrets for a bit
  429. self->attackDebounceTime = level.time + 1400;
  430. }
  431. bestTarget = target;
  432. bestDist = enemyDist;
  433. found = qtrue;
  434. }
  435. }
  436. }
  437. if ( found )
  438. {
  439. if ( !self->enemy )
  440. {//just aquired one
  441. AddSoundEvent( bestTarget, self->currentOrigin, 256, AEL_DISCOVERED );
  442. AddSightEvent( bestTarget, self->currentOrigin, 512, AEL_DISCOVERED, 20 );
  443. }
  444. G_SetEnemy( self, bestTarget );
  445. if ( VALIDSTRING( self->target2 ))
  446. {
  447. G_UseTargets2( self, self, self->target2 );
  448. }
  449. }
  450. return found;
  451. }
  452. //-----------------------------------------------------
  453. void turret_base_think( gentity_t *self )
  454. //-----------------------------------------------------
  455. {
  456. qboolean turnOff = qtrue;
  457. float enemyDist;
  458. vec3_t enemyDir, org, org2;
  459. self->nextthink = level.time + FRAMETIME;
  460. if ( self->spawnflags & 1 )
  461. {
  462. // not turned on
  463. turret_turnoff( self );
  464. turret_aim( self );
  465. // No target
  466. self->flags |= FL_NOTARGET;
  467. return;
  468. }
  469. else
  470. {
  471. // I'm all hot and bothered
  472. self->flags &= ~FL_NOTARGET;
  473. }
  474. if ( !self->enemy )
  475. {
  476. if ( turret_find_enemies( self ))
  477. {
  478. turnOff = qfalse;
  479. }
  480. }
  481. else
  482. {
  483. if ( self->enemy->health > 0 )
  484. {
  485. // enemy is alive
  486. VectorSubtract( self->enemy->currentOrigin, self->currentOrigin, enemyDir );
  487. enemyDist = VectorLengthSquared( enemyDir );
  488. if ( enemyDist < self->radius * self->radius )
  489. {
  490. // was in valid radius
  491. if ( gi.inPVS( self->currentOrigin, self->enemy->currentOrigin ) )
  492. {
  493. // Every now and again, check to see if we can even trace to the enemy
  494. trace_t tr;
  495. if ( self->enemy->client )
  496. {
  497. VectorCopy( self->enemy->client->renderInfo.eyePoint, org );
  498. }
  499. else
  500. {
  501. VectorCopy( self->enemy->currentOrigin, org );
  502. }
  503. VectorCopy( self->currentOrigin, org2 );
  504. if ( self->spawnflags & 2 )
  505. {
  506. org2[2] += 10;
  507. }
  508. else
  509. {
  510. org2[2] -= 10;
  511. }
  512. gi.trace( &tr, org2, NULL, NULL, org, self->s.number, MASK_SHOT );
  513. if ( self->spawnflags & SPF_TURRETG2_TURBO || ( !tr.allsolid && !tr.startsolid && tr.entityNum == self->enemy->s.number ) )
  514. {
  515. turnOff = qfalse; // Can see our enemy
  516. }
  517. }
  518. }
  519. }
  520. turret_head_think( self );
  521. }
  522. if ( turnOff )
  523. {
  524. if ( self->bounceCount < level.time ) // bounceCount is used to keep the thing from ping-ponging from on to off
  525. {
  526. turret_turnoff( self );
  527. }
  528. }
  529. else
  530. {
  531. // keep our enemy for a minimum of 2 seconds from now
  532. self->bounceCount = level.time + 2000 + random() * 150;
  533. }
  534. turret_aim( self );
  535. }
  536. //-----------------------------------------------------------------------------
  537. void turret_base_use( gentity_t *self, gentity_t *other, gentity_t *activator )
  538. //-----------------------------------------------------------------------------
  539. {
  540. // Toggle on and off
  541. self->spawnflags = (self->spawnflags ^ 1);
  542. if (( self->s.eFlags & EF_SHADER_ANIM ) && ( self->spawnflags & 1 )) // Start_Off
  543. {
  544. self->s.frame = 1; // black
  545. }
  546. else
  547. {
  548. self->s.frame = 0; // glow
  549. }
  550. }
  551. //special routine for tracking angles between client and server -rww
  552. void turret_SetBoneAngles(gentity_t *ent, char *bone, const vec3_t angles)
  553. {
  554. /*
  555. #ifdef _XBOX
  556. byte *thebone = &ent->s.boneIndex1;
  557. byte *firstFree = NULL;
  558. #else
  559. int *thebone = &ent->s.boneIndex1;
  560. int *firstFree = NULL;
  561. #endif
  562. int i = 0;
  563. int boneIndex = G_BoneIndex(bone);
  564. int flags;
  565. Eorientations up, right, forward;
  566. vec3_t *boneVector = &ent->s.boneAngles1;
  567. vec3_t *freeBoneVec = NULL;
  568. while (thebone)
  569. {
  570. if (!*thebone && !firstFree)
  571. { //if the value is 0 then this index is clear, we can use it if we don't find the bone we want already existing.
  572. firstFree = thebone;
  573. freeBoneVec = boneVector;
  574. }
  575. else if (*thebone)
  576. {
  577. if (*thebone == boneIndex)
  578. { //this is it
  579. break;
  580. }
  581. }
  582. switch (i)
  583. {
  584. case 0:
  585. thebone = &ent->s.boneIndex2;
  586. boneVector = &ent->s.boneAngles2;
  587. break;
  588. case 1:
  589. thebone = &ent->s.boneIndex3;
  590. boneVector = &ent->s.boneAngles3;
  591. break;
  592. case 2:
  593. thebone = &ent->s.boneIndex4;
  594. boneVector = &ent->s.boneAngles4;
  595. break;
  596. default:
  597. thebone = NULL;
  598. boneVector = NULL;
  599. break;
  600. }
  601. i++;
  602. }
  603. if (!thebone)
  604. { //didn't find it, create it
  605. if (!firstFree)
  606. { //no free bones.. can't do a thing then.
  607. Com_Printf("WARNING: NPC has no free bone indexes\n");
  608. return;
  609. }
  610. thebone = firstFree;
  611. *thebone = boneIndex;
  612. boneVector = freeBoneVec;
  613. }
  614. //If we got here then we have a vector and an index.
  615. //Copy the angles over the vector in the entitystate, so we can use the corresponding index
  616. //to set the bone angles on the client.
  617. VectorCopy(angles, *boneVector);
  618. */
  619. //Now set the angles on our server instance if we have one.
  620. if ( !ent->ghoul2.size() )
  621. {
  622. return;
  623. }
  624. int flags = BONE_ANGLES_POSTMULT;
  625. Eorientations up, right, forward;
  626. up = POSITIVE_Y;
  627. right = NEGATIVE_Z;
  628. forward = NEGATIVE_X;
  629. //first 3 bits is forward, second 3 bits is right, third 3 bits is up
  630. //ent->s.boneOrient = ((forward)|(right<<3)|(up<<6));
  631. gi.G2API_SetBoneAngles( &ent->ghoul2[0], bone, angles, flags, up,
  632. right, forward, NULL, 100, level.time );
  633. }
  634. void turret_set_models( gentity_t *self, qboolean dying )
  635. {
  636. if ( dying )
  637. {
  638. if ( !(self->spawnflags&SPF_TURRETG2_TURBO) )
  639. {
  640. self->s.modelindex = G_ModelIndex( name2 );
  641. self->s.modelindex2 = G_ModelIndex( name );
  642. }
  643. gi.G2API_RemoveGhoul2Model( self->ghoul2, 0 );
  644. /*G_KillG2Queue( self->s.number );
  645. self->s.modelGhoul2 = 0;
  646. gi.G2API_InitGhoul2Model( &self->ghoul2,
  647. name2,
  648. 0, //base->s.modelindex,
  649. //note, this is not the same kind of index - this one's referring to the actual
  650. //index of the model in the g2 instance, whereas modelindex is the index of a
  651. //configstring -rww
  652. 0,
  653. 0,
  654. 0,
  655. 0);
  656. */
  657. }
  658. else
  659. {
  660. if ( !(self->spawnflags&SPF_TURRETG2_TURBO) )
  661. {
  662. self->s.modelindex = G_ModelIndex( name );
  663. self->s.modelindex2 = G_ModelIndex( name2 );
  664. //set the new onw
  665. gi.G2API_InitGhoul2Model( self->ghoul2,
  666. name,
  667. 0, //base->s.modelindex,
  668. //note, this is not the same kind of index - this one's referring to the actual
  669. //index of the model in the g2 instance, whereas modelindex is the index of a
  670. //configstring -rww
  671. 0,
  672. 0,
  673. 0,
  674. 0);
  675. }
  676. else
  677. {
  678. self->s.modelindex = G_ModelIndex( name3 );
  679. //set the new onw
  680. gi.G2API_InitGhoul2Model( self->ghoul2,
  681. name3,
  682. 0, //base->s.modelindex,
  683. //note, this is not the same kind of index - this one's referring to the actual
  684. //index of the model in the g2 instance, whereas modelindex is the index of a
  685. //configstring -rww
  686. 0,
  687. 0,
  688. 0,
  689. 0);
  690. }
  691. /*self->s.modelGhoul2 = 1;
  692. if ( (self->spawnflags&SPF_TURRETG2_TURBO) )
  693. {//larger
  694. self->s.g2radius = 128;
  695. }
  696. else
  697. {
  698. self->s.g2radius = 80;
  699. }*/
  700. if ( (self->spawnflags&SPF_TURRETG2_TURBO) )
  701. {//different pitch bone and muzzle flash points
  702. turret_SetBoneAngles(self, "pitch", vec3_origin);
  703. //self->genericValue11 = gi.G2API_AddBolt( self->ghoul2, 0, "*muzzle1" );
  704. //self->genericValue12 = gi.G2API_AddBolt( self->ghoul2, 0, "*muzzle2" );
  705. }
  706. else
  707. {
  708. turret_SetBoneAngles(self, "Bone_body", vec3_origin);
  709. //self->genericValue11 = gi.G2API_AddBolt( self->ghoul2, 0, "*flash03" );
  710. }
  711. }
  712. }
  713. /*QUAKED misc_turret (1 0 0) (-8 -8 -22) (8 8 0) START_OFF UPSIDE_DOWN TURBO
  714. Turret that hangs from the ceiling, will aim and shoot at enemies
  715. START_OFF - Starts off
  716. UPSIDE_DOWN - make it rest on a surface/floor instead of hanging from the ceiling
  717. TURBO - Big-ass, Boxy Death Star Turbo Laser version
  718. radius - How far away an enemy can be for it to pick it up (default 512)
  719. wait - Time between shots (default 150 ms)
  720. dmg - How much damage each shot does (default 5)
  721. health - How much damage it can take before exploding (default 100)
  722. splashDamage - How much damage the explosion does
  723. splashRadius - The radius of the explosion
  724. NOTE: If either of the above two are 0, it will not make an explosion
  725. targetname - Toggles it on/off
  726. target - What to use when destroyed
  727. target2 - What to use when it decides to start shooting at an enemy
  728. team - team that is not targeted by and does not take damage from this turret
  729. "player",
  730. "enemy", (default)
  731. "neutral"
  732. */
  733. //-----------------------------------------------------
  734. void SP_misc_turret( gentity_t *base )
  735. //-----------------------------------------------------
  736. {
  737. /*base->s.modelindex = G_ModelIndex( "models/map_objects/imp_mine/turret_canon.glm" );
  738. base->s.modelindex2 = G_ModelIndex( "models/map_objects/imp_mine/turret_damage.md3" );
  739. base->playerModel = gi.G2API_InitGhoul2Model( base->ghoul2, "models/map_objects/imp_mine/turret_canon.glm", base->s.modelindex );
  740. base->s.radius = 80.0f;*/
  741. turret_set_models( base, qfalse );
  742. gi.G2API_SetBoneAngles( &base->ghoul2[base->playerModel], "Bone_body", vec3_origin, BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL );
  743. base->torsoBolt = gi.G2API_AddBolt( &base->ghoul2[base->playerModel], "*flash03" );
  744. finish_spawning_turret( base );
  745. if (( base->spawnflags & 1 )) // Start_Off
  746. {
  747. base->s.frame = 1; // black
  748. }
  749. else
  750. {
  751. base->s.frame = 0; // glow
  752. }
  753. base->s.eFlags |= EF_SHADER_ANIM;
  754. }
  755. //-----------------------------------------------------
  756. void finish_spawning_turret( gentity_t *base )
  757. {
  758. vec3_t fwd;
  759. if ( base->spawnflags & 2 )
  760. {
  761. base->s.angles[ROLL] += 180;
  762. base->s.origin[2] -= 22.0f;
  763. }
  764. G_SetAngles( base, base->s.angles );
  765. AngleVectors( base->currentAngles, fwd, NULL, NULL );
  766. G_SetOrigin(base, base->s.origin);
  767. base->noDamageTeam = TEAM_ENEMY;
  768. base->s.eType = ET_GENERAL;
  769. if ( base->team && base->team[0] )
  770. {
  771. base->noDamageTeam = (team_t)GetIDForString( TeamTable, base->team );
  772. base->team = NULL;
  773. }
  774. // Set up our explosion effect for the ExplodeDeath code....
  775. base->fxID = G_EffectIndex( "turret/explode" );
  776. G_EffectIndex( "sparks/spark_exp_nosnd" );
  777. base->e_UseFunc = useF_turret_base_use;
  778. base->e_PainFunc = painF_TurretPain;
  779. // don't start working right away
  780. base->e_ThinkFunc = thinkF_turret_base_think;
  781. base->nextthink = level.time + FRAMETIME * 5;
  782. // this is really the pitch angle.....
  783. base->speed = 0;
  784. G_SpawnFloat( "shotspeed", "0", &base->mass );
  785. if ( (base->spawnflags&SPF_TURRETG2_TURBO) )
  786. {
  787. if ( !base->random )
  788. {//error worked into projectile direction
  789. base->random = 2.0f;
  790. }
  791. if ( !base->mass )
  792. {//misnomer: speed of projectile
  793. base->mass = 4000;
  794. }
  795. if ( !base->health )
  796. {
  797. base->health = 2000;
  798. }
  799. // search radius
  800. if ( !base->radius )
  801. {
  802. base->radius = 32768;
  803. }
  804. // How quickly to fire
  805. if ( !base->wait )
  806. {
  807. base->wait = 500;// + random() * 500;
  808. }
  809. if ( !base->splashDamage )
  810. {
  811. base->splashDamage = 200;
  812. }
  813. if ( !base->splashRadius )
  814. {
  815. base->splashRadius = 500;
  816. }
  817. // how much damage each shot does
  818. if ( !base->damage )
  819. {
  820. base->damage = 10;
  821. }
  822. VectorSet( base->s.modelScale, 2.0f, 2.0f, 2.0f );
  823. VectorSet( base->maxs, 128.0f, 128.0f, 120.0f );
  824. VectorSet( base->mins, -128.0f, -128.0f, -120.0f );
  825. // Cull Radius.
  826. base->s.radius = 256;
  827. //start in "off" anim
  828. TurboLaser_SetBoneAnim( base, 4, 5 );
  829. // Make sure it doesn't do sparks and such when saber contacts with it.
  830. base->flags = FL_DMG_BY_HEAVY_WEAP_ONLY;
  831. base->takedamage = qfalse;
  832. base->contents = CONTENTS_BODY|CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP|CONTENTS_SHOTCLIP;
  833. base->noDamageTeam = TEAM_NEUTRAL;
  834. base->team = NULL;
  835. }
  836. else
  837. {
  838. // this is a random time offset for the no-enemy-search-around-mode
  839. base->count = random() * 9000;
  840. if ( !base->health )
  841. {
  842. base->health = 100;
  843. }
  844. // search radius
  845. if ( !base->radius )
  846. {
  847. base->radius = 512;
  848. }
  849. // How quickly to fire
  850. if ( !base->wait )
  851. {
  852. base->wait = 150 + random() * 55;
  853. }
  854. if ( !base->splashDamage )
  855. {
  856. base->splashDamage = 10;
  857. }
  858. if ( !base->splashRadius )
  859. {
  860. base->splashRadius = 25;
  861. }
  862. // how much damage each shot does
  863. if ( !base->damage )
  864. {
  865. base->damage = 5;
  866. }
  867. if ( base->spawnflags & 2 )
  868. {//upside-down, invert mins and maxe
  869. VectorSet( base->maxs, 10.0f, 10.0f, 30.0f );
  870. VectorSet( base->mins, -10.0f, -10.0f, 0.0f );
  871. }
  872. else
  873. {
  874. VectorSet( base->maxs, 10.0f, 10.0f, 0.0f );
  875. VectorSet( base->mins, -10.0f, -10.0f, -30.0f );
  876. }
  877. base->takedamage = qtrue;
  878. base->contents = CONTENTS_BODY|CONTENTS_PLAYERCLIP|CONTENTS_MONSTERCLIP|CONTENTS_SHOTCLIP;
  879. }
  880. // Precache special FX and moving sounds
  881. if ( (base->spawnflags&SPF_TURRETG2_TURBO) )
  882. {
  883. G_EffectIndex( "turret/turb_muzzle_flash" );
  884. G_EffectIndex( "turret/turb_shot" );
  885. G_EffectIndex( "turret/turb_impact" );
  886. //FIXME: Turbo Laser Cannon sounds!
  887. G_SoundIndex( "sound/vehicles/weapons/turbolaser/turn.wav" );
  888. G_EffectIndex( "explosions/fighter_explosion2" );
  889. RegisterItem( FindItemForWeapon( WP_TIE_FIGHTER ));
  890. }
  891. else
  892. {
  893. // Precache moving sounds
  894. G_SoundIndex( "sound/chars/turret/startup.wav" );
  895. G_SoundIndex( "sound/chars/turret/shutdown.wav" );
  896. G_SoundIndex( "sound/chars/turret/ping.wav" );
  897. G_SoundIndex( "sound/chars/turret/move.wav" );
  898. }
  899. base->max_health = base->health;
  900. base->e_DieFunc = dieF_turret_die;
  901. base->material = MAT_METAL;
  902. if ( (base->spawnflags&SPF_TURRETG2_TURBO) )
  903. {
  904. RegisterItem( FindItemForWeapon( WP_TURRET ));
  905. base->svFlags |= SVF_NO_TELEPORT|SVF_SELF_ANIMATING;
  906. }
  907. else
  908. {
  909. // Register this so that we can use it for the missile effect
  910. RegisterItem( FindItemForWeapon( WP_BLASTER ));
  911. base->svFlags |= SVF_NO_TELEPORT|SVF_NONNPC_ENEMY|SVF_SELF_ANIMATING;
  912. }
  913. // But set us as a turret so that we can be identified as a turret
  914. base->s.weapon = WP_TURRET;
  915. gi.linkentity( base );
  916. }
  917. /*QUAKED misc_ns_turret (1 0 0) (-8 -8 -32) (8 8 29) START_OFF
  918. NS turret that only hangs from the ceiling, will aim and shoot at enemies
  919. START_OFF - Starts off
  920. radius - How far away an enemy can be for it to pick it up (default 512)
  921. wait - Time between shots (default 150 ms)
  922. dmg - How much damage each shot does (default 5)
  923. health - How much damage it can take before exploding (default 100)
  924. splashDamage - How much damage the explosion does
  925. splashRadius - The radius of the explosion
  926. NOTE: If either of the above two are 0, it will not make an explosion
  927. targetname - Toggles it on/off
  928. target - What to use when destroyed
  929. team - team that is not targeted by and does not take damage from this turret
  930. "player",
  931. "enemy", (default)
  932. "neutral"
  933. */
  934. //-----------------------------------------------------
  935. void SP_misc_ns_turret( gentity_t *base )
  936. //-----------------------------------------------------
  937. {
  938. base->s.modelindex = G_ModelIndex( "models/map_objects/nar_shaddar/turret/turret.glm" );
  939. base->s.modelindex2 = G_ModelIndex( "models/map_objects/imp_mine/turret_damage.md3" ); // FIXME!
  940. base->playerModel = gi.G2API_InitGhoul2Model( base->ghoul2, "models/map_objects/nar_shaddar/turret/turret.glm", base->s.modelindex );
  941. base->s.radius = 80.0f;
  942. gi.G2API_SetBoneAngles( &base->ghoul2[base->playerModel], "Bone_body", vec3_origin, BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL );
  943. base->torsoBolt = gi.G2API_AddBolt( &base->ghoul2[base->playerModel], "*flash02" );
  944. finish_spawning_turret( base );
  945. }
  946. //--------------------------------------
  947. void laser_arm_fire (gentity_t *ent)
  948. {
  949. vec3_t start, end, fwd, rt, up;
  950. trace_t trace;
  951. if ( ent->attackDebounceTime < level.time && ent->alt_fire )
  952. {
  953. // If I'm firing the laser and it's time to quit....then quit!
  954. ent->alt_fire = qfalse;
  955. // ent->e_ThinkFunc = thinkF_NULL;
  956. // return;
  957. }
  958. ent->nextthink = level.time + FRAMETIME;
  959. // If a fool gets in the laser path, fry 'em
  960. AngleVectors( ent->currentAngles, fwd, rt, up );
  961. VectorMA( ent->currentOrigin, 20, fwd, start );
  962. //VectorMA( start, -6, rt, start );
  963. //VectorMA( start, -3, up, start );
  964. VectorMA( start, 4096, fwd, end );
  965. gi.trace( &trace, start, NULL, NULL, end, ENTITYNUM_NONE, MASK_SHOT );//ignore
  966. ent->fly_sound_debounce_time = level.time;//used as lastShotTime
  967. // Only deal damage when in alt-fire mode
  968. if ( trace.fraction < 1.0 && ent->alt_fire )
  969. {
  970. if ( trace.entityNum < ENTITYNUM_WORLD )
  971. {
  972. gentity_t *hapless_victim = &g_entities[trace.entityNum];
  973. if ( hapless_victim && hapless_victim->takedamage && ent->damage )
  974. {
  975. G_Damage( hapless_victim, ent, ent->nextTrain->activator, fwd, trace.endpos, ent->damage, DAMAGE_IGNORE_TEAM, MOD_UNKNOWN );
  976. }
  977. }
  978. }
  979. if ( ent->alt_fire )
  980. {
  981. // CG_FireLaser( start, trace.endpos, trace.plane.normal, ent->nextTrain->startRGBA, qfalse );
  982. }
  983. else
  984. {
  985. // CG_AimLaser( start, trace.endpos, trace.plane.normal );
  986. }
  987. }
  988. void laser_arm_use (gentity_t *self, gentity_t *other, gentity_t *activator)
  989. {
  990. vec3_t newAngles;
  991. self->activator = activator;
  992. switch( self->count )
  993. {
  994. case 0:
  995. default:
  996. //Fire
  997. //gi.Printf("FIRE!\n");
  998. // self->lastEnemy->lastEnemy->e_ThinkFunc = thinkF_laser_arm_fire;
  999. // self->lastEnemy->lastEnemy->nextthink = level.time + FRAMETIME;
  1000. //For 3 seconds
  1001. self->lastEnemy->lastEnemy->alt_fire = qtrue; // Let 'er rip!
  1002. self->lastEnemy->lastEnemy->attackDebounceTime = level.time + self->lastEnemy->lastEnemy->wait;
  1003. G_Sound(self->lastEnemy->lastEnemy, G_SoundIndex("sound/chars/l_arm/fire.wav"));
  1004. break;
  1005. case 1:
  1006. //Yaw left
  1007. //gi.Printf("LEFT...\n");
  1008. VectorCopy( self->lastEnemy->currentAngles, newAngles );
  1009. newAngles[1] += self->speed;
  1010. G_SetAngles( self->lastEnemy, newAngles );
  1011. // bolt_head_to_arm( self->lastEnemy, self->lastEnemy->lastEnemy, LARM_FOFS, LARM_ROFS, LARM_UOFS );
  1012. G_Sound( self->lastEnemy, G_SoundIndex( "sound/chars/l_arm/move.wav" ) );
  1013. break;
  1014. case 2:
  1015. //Yaw right
  1016. //gi.Printf("RIGHT...\n");
  1017. VectorCopy( self->lastEnemy->currentAngles, newAngles );
  1018. newAngles[1] -= self->speed;
  1019. G_SetAngles( self->lastEnemy, newAngles );
  1020. // bolt_head_to_arm( self->lastEnemy, self->lastEnemy->lastEnemy, LARM_FOFS, LARM_ROFS, LARM_UOFS );
  1021. G_Sound( self->lastEnemy, G_SoundIndex( "sound/chars/l_arm/move.wav" ) );
  1022. break;
  1023. case 3:
  1024. //pitch up
  1025. //gi.Printf("UP...\n");
  1026. //FIXME: Clamp
  1027. VectorCopy( self->lastEnemy->lastEnemy->currentAngles, newAngles );
  1028. newAngles[0] -= self->speed;
  1029. if ( newAngles[0] < -45 )
  1030. {
  1031. newAngles[0] = -45;
  1032. }
  1033. G_SetAngles( self->lastEnemy->lastEnemy, newAngles );
  1034. G_Sound( self->lastEnemy->lastEnemy, G_SoundIndex( "sound/chars/l_arm/move.wav" ) );
  1035. break;
  1036. case 4:
  1037. //pitch down
  1038. //gi.Printf("DOWN...\n");
  1039. //FIXME: Clamp
  1040. VectorCopy( self->lastEnemy->lastEnemy->currentAngles, newAngles );
  1041. newAngles[0] += self->speed;
  1042. if ( newAngles[0] > 90 )
  1043. {
  1044. newAngles[0] = 90;
  1045. }
  1046. G_SetAngles( self->lastEnemy->lastEnemy, newAngles );
  1047. G_Sound( self->lastEnemy->lastEnemy, G_SoundIndex( "sound/chars/l_arm/move.wav" ) );
  1048. break;
  1049. }
  1050. }
  1051. /*QUAKED misc_laser_arm (1 0 0) (-8 -8 -8) (8 8 8)
  1052. What it does when used depends on it's "count" (can be set by a script)
  1053. count:
  1054. 0 (default) - Fire in direction facing
  1055. 1 turn left
  1056. 2 turn right
  1057. 3 aim up
  1058. 4 aim down
  1059. speed - How fast it turns (degrees per second, default 30)
  1060. dmg - How much damage the laser does 10 times a second (default 5 = 50 points per second)
  1061. wait - How long the beam lasts, in seconds (default is 3)
  1062. targetname - to use it
  1063. target - What thing for it to be pointing at to start with
  1064. "startRGBA" - laser color, Red Green Blue Alpha, range 0 to 1 (default 1.0 0.85 0.15 0.75 = Yellow-Orange)
  1065. */
  1066. void laser_arm_start (gentity_t *base)
  1067. {
  1068. vec3_t armAngles;
  1069. vec3_t headAngles;
  1070. base->e_ThinkFunc = thinkF_NULL;
  1071. //We're the base, spawn the arm and head
  1072. gentity_t *arm = G_Spawn();
  1073. gentity_t *head = G_Spawn();
  1074. VectorCopy( base->s.angles, armAngles );
  1075. VectorCopy( base->s.angles, headAngles );
  1076. if ( base->target && base->target[0] )
  1077. {//Start out pointing at something
  1078. gentity_t *targ = G_Find( NULL, FOFS(targetname), base->target );
  1079. if ( !targ )
  1080. {//couldn't find it!
  1081. Com_Printf(S_COLOR_RED "ERROR : laser_arm can't find target %s!\n", base->target);
  1082. }
  1083. else
  1084. {//point at it
  1085. vec3_t dir, angles;
  1086. VectorSubtract(targ->currentOrigin, base->s.origin, dir );
  1087. vectoangles( dir, angles );
  1088. armAngles[1] = angles[1];
  1089. headAngles[0] = angles[0];
  1090. headAngles[1] = angles[1];
  1091. }
  1092. }
  1093. //Base
  1094. //Base does the looking for enemies and pointing the arm and head
  1095. G_SetAngles( base, base->s.angles );
  1096. //base->s.origin[2] += 4;
  1097. G_SetOrigin(base, base->s.origin);
  1098. gi.linkentity(base);
  1099. //FIXME: need an actual model
  1100. base->s.modelindex = G_ModelIndex("models/mapobjects/dn/laser_base.md3");
  1101. base->s.eType = ET_GENERAL;
  1102. G_SpawnVector4( "startRGBA", "1.0 0.85 0.15 0.75", (float *)&base->startRGBA );
  1103. //anglespeed - how fast it can track the player, entered in degrees per second, so we divide by FRAMETIME/1000
  1104. if ( !base->speed )
  1105. {
  1106. base->speed = 3.0f;
  1107. }
  1108. else
  1109. {
  1110. base->speed *= FRAMETIME/1000.0f;
  1111. }
  1112. base->e_UseFunc = useF_laser_arm_use;
  1113. base->nextthink = level.time + FRAMETIME;
  1114. //Arm
  1115. //Does nothing, not solid, gets removed when head explodes
  1116. G_SetOrigin( arm, base->s.origin );
  1117. gi.linkentity(arm);
  1118. G_SetAngles( arm, armAngles );
  1119. // bolt_head_to_arm( arm, head, LARM_FOFS, LARM_ROFS, LARM_UOFS );
  1120. arm->s.modelindex = G_ModelIndex("models/mapobjects/dn/laser_arm.md3");
  1121. //Head
  1122. //Fires when enemy detected, animates, can be blown up
  1123. //Need to normalize the headAngles pitch for the clamping later
  1124. if ( headAngles[0] < -180 )
  1125. {
  1126. headAngles[0] += 360;
  1127. }
  1128. else if ( headAngles[0] > 180 )
  1129. {
  1130. headAngles[0] -= 360;
  1131. }
  1132. G_SetAngles( head, headAngles );
  1133. head->s.modelindex = G_ModelIndex("models/mapobjects/dn/laser_head.md3");
  1134. head->s.eType = ET_GENERAL;
  1135. // head->svFlags |= SVF_BROADCAST;// Broadcast to all clients
  1136. VectorSet( head->mins, -8, -8, -8 );
  1137. VectorSet( head->maxs, 8, 8, 8 );
  1138. head->contents = CONTENTS_BODY;
  1139. gi.linkentity(head);
  1140. //dmg
  1141. if ( !base->damage )
  1142. {
  1143. head->damage = 5;
  1144. }
  1145. else
  1146. {
  1147. head->damage = base->damage;
  1148. }
  1149. base->damage = 0;
  1150. //lifespan of beam
  1151. if ( !base->wait )
  1152. {
  1153. head->wait = 3000;
  1154. }
  1155. else
  1156. {
  1157. head->wait = base->wait * 1000;
  1158. }
  1159. base->wait = 0;
  1160. //Precache firing and explode sounds
  1161. G_SoundIndex("sound/weapons/explosions/cargoexplode.wav");
  1162. G_SoundIndex("sound/chars/l_arm/fire.wav");
  1163. G_SoundIndex("sound/chars/l_arm/move.wav");
  1164. //Link them up
  1165. base->lastEnemy = arm;
  1166. arm->lastEnemy = head;
  1167. head->owner = arm;
  1168. arm->nextTrain = head->nextTrain = base;
  1169. // The head should always think, since it will be either firing a damage laser or just a target laser
  1170. head->e_ThinkFunc = thinkF_laser_arm_fire;
  1171. head->nextthink = level.time + FRAMETIME;
  1172. head->alt_fire = qfalse; // Don't do damage until told to
  1173. }
  1174. void SP_laser_arm (gentity_t *base)
  1175. {
  1176. base->e_ThinkFunc = thinkF_laser_arm_start;
  1177. base->nextthink = level.time + START_TIME_LINK_ENTS;
  1178. }
  1179. //--------------------------
  1180. // PERSONAL ASSAULT SENTRY
  1181. //--------------------------
  1182. #define PAS_DAMAGE 2
  1183. //-----------------------------------------------------------------------------
  1184. void pas_use( gentity_t *self, gentity_t *other, gentity_t *activator )
  1185. //-----------------------------------------------------------------------------
  1186. {
  1187. // Toggle on and off
  1188. self->spawnflags = (self->spawnflags ^ 1);
  1189. if ( self->spawnflags & 1 )
  1190. {
  1191. self->nextthink = 0; // turn off and do nothing
  1192. self->e_ThinkFunc = thinkF_NULL;
  1193. }
  1194. else
  1195. {
  1196. self->nextthink = level.time + 50;
  1197. self->e_ThinkFunc = thinkF_pas_think;
  1198. }
  1199. }
  1200. //----------------------------------------------------------------
  1201. void pas_fire( gentity_t *ent )
  1202. //----------------------------------------------------------------
  1203. {
  1204. vec3_t fwd, org;
  1205. mdxaBone_t boltMatrix;
  1206. // Getting the flash bolt here
  1207. gi.G2API_GetBoltMatrix( ent->ghoul2, ent->playerModel,
  1208. ent->torsoBolt,
  1209. &boltMatrix, ent->currentAngles, ent->s.origin, (cg.time?cg.time:level.time),
  1210. NULL, ent->s.modelScale );
  1211. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org );
  1212. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, POSITIVE_Y, fwd );
  1213. G_PlayEffect( "turret/muzzle_flash", org, fwd );
  1214. gentity_t *bolt;
  1215. bolt = G_Spawn();
  1216. bolt->classname = "turret_proj";
  1217. bolt->nextthink = level.time + 10000;
  1218. bolt->e_ThinkFunc = thinkF_G_FreeEntity;
  1219. bolt->s.eType = ET_MISSILE;
  1220. bolt->s.weapon = WP_TURRET;
  1221. bolt->owner = ent;
  1222. bolt->damage = PAS_DAMAGE;
  1223. bolt->dflags = DAMAGE_NO_KNOCKBACK; // Don't push them around, or else we are constantly re-aiming
  1224. bolt->splashDamage = 0;
  1225. bolt->splashRadius = 0;
  1226. bolt->methodOfDeath = MOD_ENERGY;
  1227. bolt->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
  1228. VectorSet( bolt->maxs, 1, 1, 1 );
  1229. VectorScale( bolt->maxs, -1, bolt->mins );
  1230. bolt->s.pos.trType = TR_LINEAR;
  1231. bolt->s.pos.trTime = level.time; // move a bit on the very first frame
  1232. VectorCopy( org, bolt->s.pos.trBase );
  1233. VectorScale( fwd, 900, bolt->s.pos.trDelta );
  1234. SnapVector( bolt->s.pos.trDelta ); // save net bandwidth
  1235. VectorCopy( org, bolt->currentOrigin);
  1236. }
  1237. //-----------------------------------------------------
  1238. static qboolean pas_find_enemies( gentity_t *self )
  1239. //-----------------------------------------------------
  1240. {
  1241. qboolean found = qfalse;
  1242. int count;
  1243. float bestDist = self->radius * self->radius;
  1244. float enemyDist;
  1245. vec3_t enemyDir, org, org2;
  1246. gentity_t *entity_list[MAX_GENTITIES], *target;
  1247. if ( self->aimDebounceTime > level.time ) // time since we've been shut off
  1248. {
  1249. // We were active and alert, i.e. had an enemy in the last 3 secs
  1250. if ( self->painDebounceTime < level.time )
  1251. {
  1252. G_Sound(self, G_SoundIndex( "sound/chars/turret/ping.wav" ));
  1253. self->painDebounceTime = level.time + 1000;
  1254. }
  1255. }
  1256. mdxaBone_t boltMatrix;
  1257. // Getting the "eye" here
  1258. gi.G2API_GetBoltMatrix( self->ghoul2, self->playerModel,
  1259. self->torsoBolt,
  1260. &boltMatrix, self->currentAngles, self->s.origin, (cg.time?cg.time:level.time),
  1261. NULL, self->s.modelScale );
  1262. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org2 );
  1263. count = G_RadiusList( org2, self->radius, self, qtrue, entity_list );
  1264. for ( int i = 0; i < count; i++ )
  1265. {
  1266. target = entity_list[i];
  1267. if ( !target->client )
  1268. {
  1269. continue;
  1270. }
  1271. if ( target == self || !target->takedamage || target->health <= 0 || ( target->flags & FL_NOTARGET ))
  1272. {
  1273. continue;
  1274. }
  1275. if ( target->client->playerTeam == self->noDamageTeam )
  1276. {
  1277. // A bot we don't want to shoot
  1278. continue;
  1279. }
  1280. if ( !gi.inPVS( org2, target->currentOrigin ))
  1281. {
  1282. continue;
  1283. }
  1284. if ( target->client )
  1285. {
  1286. VectorCopy( target->client->renderInfo.eyePoint, org );
  1287. org[2] -= 15;
  1288. }
  1289. else
  1290. {
  1291. VectorCopy( target->currentOrigin, org );
  1292. }
  1293. trace_t tr;
  1294. gi.trace( &tr, org2, NULL, NULL, org, self->s.number, MASK_SHOT );
  1295. if ( !tr.allsolid && !tr.startsolid && ( tr.fraction == 1.0 || tr.entityNum == target->s.number ))
  1296. {
  1297. // Only acquire if have a clear shot, Is it in range and closer than our best?
  1298. VectorSubtract( target->currentOrigin, self->currentOrigin, enemyDir );
  1299. enemyDist = VectorLengthSquared( enemyDir );
  1300. if ( target->s.number ) // don't do this for the player
  1301. {
  1302. G_StartFlee( target, self, self->currentOrigin, AEL_DANGER, 3000, 5000 );
  1303. }
  1304. if ( enemyDist < bestDist )// all things equal, keep current
  1305. {
  1306. if ( self->attackDebounceTime + 2000 < level.time )
  1307. {
  1308. // We haven't fired or acquired an enemy in the last 2 seconds-start-up sound
  1309. G_Sound( self, G_SoundIndex( "sound/chars/turret/startup.wav" ));
  1310. // Wind up turrets for a bit
  1311. self->attackDebounceTime = level.time + 900 + random() * 200;
  1312. }
  1313. G_SetEnemy( self, target );
  1314. bestDist = enemyDist;
  1315. found = qtrue;
  1316. }
  1317. }
  1318. }
  1319. if ( found && VALIDSTRING( self->target2 ))
  1320. {
  1321. G_UseTargets2( self, self, self->target2 );
  1322. }
  1323. return found;
  1324. }
  1325. //---------------------------------
  1326. void pas_adjust_enemy( gentity_t *ent )
  1327. //---------------------------------
  1328. {
  1329. qboolean keep = qtrue;
  1330. if ( ent->enemy->health <= 0 )
  1331. {
  1332. keep = qfalse;
  1333. }
  1334. else// if ( random() > 0.5f )
  1335. {
  1336. // do a trace every now and then.
  1337. mdxaBone_t boltMatrix;
  1338. vec3_t org, org2;
  1339. // Getting the "eye" here
  1340. gi.G2API_GetBoltMatrix( ent->ghoul2, ent->playerModel,
  1341. ent->torsoBolt,
  1342. &boltMatrix, ent->currentAngles, ent->s.origin, (cg.time?cg.time:level.time),
  1343. NULL, ent->s.modelScale );
  1344. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org2 );
  1345. if ( ent->enemy->client )
  1346. {
  1347. VectorCopy( ent->enemy->client->renderInfo.eyePoint, org );
  1348. org[2] -= 15;
  1349. }
  1350. else
  1351. {
  1352. VectorCopy( ent->enemy->currentOrigin, org );
  1353. }
  1354. trace_t tr;
  1355. gi.trace( &tr, org2, NULL, NULL, org, ent->s.number, MASK_SHOT );
  1356. if ( tr.allsolid || tr.startsolid || tr.entityNum != ent->enemy->s.number )
  1357. {
  1358. // trace failed
  1359. keep = qfalse;
  1360. }
  1361. }
  1362. if ( keep )
  1363. {
  1364. ent->bounceCount = level.time + 500 + random() * 150;
  1365. }
  1366. else if ( ent->bounceCount < level.time ) // don't ping pong on and off
  1367. {
  1368. ent->enemy = NULL;
  1369. // shut-down sound
  1370. G_Sound( ent, G_SoundIndex( "sound/chars/turret/shutdown.wav" ));
  1371. // make turret play ping sound for 5 seconds
  1372. ent->aimDebounceTime = level.time + 5000;
  1373. }
  1374. }
  1375. //---------------------------------
  1376. void pas_think( gentity_t *ent )
  1377. //---------------------------------
  1378. {
  1379. if ( !ent->damage )
  1380. {
  1381. // let us do our animation, then we are good to go in terms of pounding the crap out of enemies.
  1382. ent->damage = 1;
  1383. gi.G2API_SetBoneAnimIndex( &ent->ghoul2[ent->playerModel], ent->rootBone, 0, 11, BONE_ANIM_OVERRIDE_FREEZE, 0.8f, cg.time );
  1384. ent->nextthink = level.time + 1200;
  1385. return;
  1386. }
  1387. if ( !ent->count )
  1388. {
  1389. // turrets that have no ammo may as well do nothing
  1390. return;
  1391. }
  1392. ent->nextthink = level.time + FRAMETIME;
  1393. if ( ent->enemy )
  1394. {
  1395. // make sure that the enemy is still valid
  1396. pas_adjust_enemy( ent );
  1397. }
  1398. if ( !ent->enemy )
  1399. {
  1400. pas_find_enemies( ent );
  1401. }
  1402. qboolean moved = qfalse;
  1403. float diffYaw = 0.0f, diffPitch = 0.0f;
  1404. vec3_t enemyDir, org;
  1405. vec3_t frontAngles, backAngles;
  1406. vec3_t desiredAngles;
  1407. ent->speed = AngleNormalize360( ent->speed );
  1408. ent->random = AngleNormalize360( ent->random );
  1409. if ( ent->enemy )
  1410. {
  1411. // ...then we'll calculate what new aim adjustments we should attempt to make this frame
  1412. // Aim at enemy
  1413. if ( ent->enemy->client )
  1414. {
  1415. VectorCopy( ent->enemy->client->renderInfo.eyePoint, org );
  1416. org[2] -= 40;
  1417. }
  1418. else
  1419. {
  1420. VectorCopy( ent->enemy->currentOrigin, org );
  1421. }
  1422. VectorSubtract( org, ent->currentOrigin, enemyDir );
  1423. vectoangles( enemyDir, desiredAngles );
  1424. diffYaw = AngleSubtract( ent->speed, desiredAngles[YAW] );
  1425. diffPitch = AngleSubtract( ent->random, desiredAngles[PITCH] );
  1426. }
  1427. else
  1428. {
  1429. // no enemy, so make us slowly sweep back and forth as if searching for a new one
  1430. diffYaw = sin( level.time * 0.0001f + ent->count ) * 2.0f;
  1431. }
  1432. if ( fabs(diffYaw) > 0.25f )
  1433. {
  1434. moved = qtrue;
  1435. if ( fabs(diffYaw) > 10.0f )
  1436. {
  1437. // cap max speed
  1438. ent->speed += (diffYaw > 0.0f) ? -10.0f : 10.0f;
  1439. }
  1440. else
  1441. {
  1442. // small enough
  1443. ent->speed -= diffYaw;
  1444. }
  1445. }
  1446. if ( fabs(diffPitch) > 0.25f )
  1447. {
  1448. moved = qtrue;
  1449. if ( fabs(diffPitch) > 4.0f )
  1450. {
  1451. // cap max speed
  1452. ent->random += (diffPitch > 0.0f) ? -4.0f : 4.0f;
  1453. }
  1454. else
  1455. {
  1456. // small enough
  1457. ent->random -= diffPitch;
  1458. }
  1459. }
  1460. // the bone axes are messed up, so hence some dumbness here
  1461. VectorSet( frontAngles, -ent->random, 0.0f, 0.0f );
  1462. VectorSet( backAngles, 0.0f, 0.0f, ent->speed - ent->s.angles[YAW] );
  1463. gi.G2API_SetBoneAngles( &ent->ghoul2[ent->playerModel], "bone_barrel", frontAngles,
  1464. BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, NEGATIVE_X, NULL,100,cg.time);
  1465. gi.G2API_SetBoneAngles( &ent->ghoul2[ent->playerModel], "bone_gback", frontAngles,
  1466. BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, NEGATIVE_X, NULL,100,cg.time);
  1467. gi.G2API_SetBoneAngles( &ent->ghoul2[ent->playerModel], "bone_hinge", backAngles,
  1468. BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL,100,cg.time);
  1469. if ( moved )
  1470. {
  1471. //ent->s.loopSound = G_SoundIndex( "sound/chars/turret/move.wav" );
  1472. }
  1473. else
  1474. {
  1475. ent->s.loopSound = 0;
  1476. }
  1477. if ( ent->enemy && ent->attackDebounceTime < level.time && random() > 0.3f )
  1478. {
  1479. ent->count--;
  1480. if ( ent->count )
  1481. {
  1482. pas_fire( ent );
  1483. ent->fly_sound_debounce_time = level.time;//used as lastShotTime
  1484. }
  1485. else
  1486. {
  1487. ent->nextthink = 0;
  1488. G_Sound( ent, G_SoundIndex( "sound/chars/turret/shutdown.wav" ));
  1489. }
  1490. }
  1491. }
  1492. /*QUAKED misc_sentry_turret (1 0 0) (-16 -16 0) (16 16 24) START_OFF RESERVED
  1493. personal assault sentry, like the ones you can carry in your inventory
  1494. RESERVED - do no use this flag for anything, does nothing..etc.
  1495. radius - How far away an enemy can be for it to pick it up (default 512)
  1496. count - number of shots before thing deactivates. -1 = infinite, default 150
  1497. health - How much damage it can take before exploding (default 50)
  1498. splashDamage - How much damage the explosion does
  1499. splashRadius - The radius of the explosion
  1500. NOTE: If either of the above two are 0, it will not make an explosion
  1501. target - What to use when destroyed
  1502. target2 - What to use when it decides to fire at an enemy
  1503. team - team that does not take damage from this item
  1504. "player",
  1505. "enemy",
  1506. "neutral"
  1507. */
  1508. //---------------------------------
  1509. void SP_PAS( gentity_t *base )
  1510. //---------------------------------
  1511. {
  1512. base->classname = "PAS";
  1513. G_SetOrigin( base, base->s.origin );
  1514. G_SetAngles( base, base->s.angles );
  1515. base->speed = base->s.angles[YAW];
  1516. base->s.modelindex = G_ModelIndex( "models/items/psgun.glm" );
  1517. base->playerModel = gi.G2API_InitGhoul2Model( base->ghoul2, "models/items/psgun.glm", base->s.modelindex );
  1518. base->s.radius = 30.0f;
  1519. VectorSet( base->s.modelScale, 1.0f, 1.0f, 1.0f );
  1520. base->rootBone = gi.G2API_GetBoneIndex( &base->ghoul2[base->playerModel], "model_root", qtrue );
  1521. gi.G2API_SetBoneAngles( &base->ghoul2[base->playerModel], "bone_hinge", vec3_origin, BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL );
  1522. gi.G2API_SetBoneAngles( &base->ghoul2[base->playerModel], "bone_gback", vec3_origin, BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL );
  1523. gi.G2API_SetBoneAngles( &base->ghoul2[base->playerModel], "bone_barrel", vec3_origin, BONE_ANGLES_POSTMULT, POSITIVE_Y, POSITIVE_Z, POSITIVE_X, NULL );
  1524. base->torsoBolt = gi.G2API_AddBolt( &base->ghoul2[base->playerModel], "*flash02" );
  1525. base->s.eType = ET_GENERAL;
  1526. if ( !base->radius )
  1527. {
  1528. base->radius = 512;
  1529. }
  1530. if ( base->count == 0 )
  1531. {
  1532. // give ammo
  1533. base->count = 150;
  1534. }
  1535. base->e_UseFunc = useF_pas_use;
  1536. base->damage = 0; // start animation flag
  1537. base->contents = CONTENTS_SHOTCLIP|CONTENTS_CORPSE;//for certain traces
  1538. VectorSet( base->mins, -8, -8, 0 );
  1539. VectorSet( base->maxs, 8, 8, 18 );
  1540. if ( !(base->spawnflags & 1 )) // START_OFF
  1541. {
  1542. base->nextthink = level.time + 1000; // we aren't starting off, so start working right away
  1543. base->e_ThinkFunc = thinkF_pas_think;
  1544. }
  1545. // Set up our explosion effect for the ExplodeDeath code....
  1546. base->fxID = G_EffectIndex( "turret/explode" );
  1547. G_EffectIndex( "sparks/spark_exp_nosnd" );
  1548. if ( !base->health )
  1549. {
  1550. base->health = 50;
  1551. }
  1552. base->max_health = base->health;
  1553. base->takedamage = qtrue;
  1554. base->e_PainFunc = painF_TurretPain;
  1555. base->e_DieFunc = dieF_turret_die;
  1556. // hack this flag on so that when it calls the turret die code, it will orient the effect up
  1557. // HACK
  1558. //--------------------------------------
  1559. base->spawnflags |= 2;
  1560. // Use this for our missile effect
  1561. RegisterItem( FindItemForWeapon( WP_TURRET ));
  1562. base->s.weapon = WP_TURRET;
  1563. base->svFlags |= SVF_NONNPC_ENEMY;
  1564. base->noDamageTeam = TEAM_NEUTRAL;
  1565. if ( base->team && base->team[0] )
  1566. {
  1567. base->noDamageTeam = (team_t)GetIDForString( TeamTable, base->team );
  1568. base->team = NULL;
  1569. }
  1570. gi.linkentity( base );
  1571. }
  1572. //------------------------------------------------------------------------
  1573. qboolean place_portable_assault_sentry( gentity_t *self, vec3_t origin, vec3_t angs )
  1574. //------------------------------------------------------------------------
  1575. {
  1576. vec3_t fwd, pos;
  1577. vec3_t mins, maxs;
  1578. trace_t tr;
  1579. gentity_t *pas;
  1580. VectorSet( maxs, 9, 9, 0 );
  1581. VectorScale( maxs, -1, mins );
  1582. angs[PITCH] = 0;
  1583. angs[ROLL] = 0;
  1584. AngleVectors( angs, fwd, NULL, NULL );
  1585. // and move a consistent distance away from us so we don't have the dumb thing spawning inside of us.
  1586. VectorMA( origin, 30, fwd, pos );
  1587. gi.trace( &tr, origin, NULL, NULL, pos, self->s.number, MASK_SHOT );
  1588. // find the ground
  1589. tr.endpos[2] += 20;
  1590. VectorCopy( tr.endpos, pos );
  1591. pos[2] -= 64;
  1592. gi.trace( &tr, tr.endpos, mins, maxs, pos, self->s.number, MASK_SHOT );
  1593. // check for a decent surface, meaning mostly flat...should probably also check surface parms so we don't set us down on lava or something.
  1594. if ( !tr.startsolid && !tr.allsolid && tr.fraction < 1.0f && tr.plane.normal[2] > 0.9f && tr.entityNum >= ENTITYNUM_WORLD )
  1595. {
  1596. // Then spawn us if it seems cool.
  1597. pas = G_Spawn();
  1598. if ( pas )
  1599. {
  1600. VectorCopy( tr.endpos, pas->s.origin );
  1601. SP_PAS( pas );
  1602. pas->contents |= CONTENTS_PLAYERCLIP; // player placed ones can block players but not npcs
  1603. pas->e_UseFunc = useF_NULL; // placeable ones never need to be used
  1604. // we don't hurt us or anyone who belongs to the same team as us.
  1605. if ( self->client )
  1606. {
  1607. pas->noDamageTeam = self->client->playerTeam;
  1608. }
  1609. G_Sound( self, G_SoundIndex( "sound/player/use_sentry" ));
  1610. pas->activator = self;
  1611. return qtrue;
  1612. }
  1613. }
  1614. return qfalse;
  1615. }
  1616. //-------------
  1617. // ION CANNON
  1618. //-------------
  1619. //----------------------------------------
  1620. void ion_cannon_think( gentity_t *self )
  1621. //----------------------------------------
  1622. {
  1623. if ( self->spawnflags & 2 )
  1624. {
  1625. if ( self->count )
  1626. {
  1627. // still have bursts left, so keep going
  1628. self->count--;
  1629. }
  1630. else
  1631. {
  1632. // done with burst, so wait delay amount, plus a random bit
  1633. self->nextthink = level.time + ( self->delay + crandom() * self->random );
  1634. self->count = Q_irand(0,5); // 0-5 bursts
  1635. // Not firing this time
  1636. return;
  1637. }
  1638. }
  1639. if ( self->fxID )
  1640. {
  1641. vec3_t fwd, org;
  1642. mdxaBone_t boltMatrix;
  1643. // Getting the flash bolt here
  1644. gi.G2API_GetBoltMatrix( self->ghoul2, self->playerModel,
  1645. self->torsoBolt,
  1646. &boltMatrix, self->s.angles, self->s.origin, (cg.time?cg.time:level.time),
  1647. NULL, self->s.modelScale );
  1648. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, ORIGIN, org );
  1649. gi.G2API_GiveMeVectorFromMatrix( boltMatrix, POSITIVE_Y, fwd );
  1650. G_PlayEffect( self->fxID, org, fwd );
  1651. }
  1652. if ( self->target2 )
  1653. {
  1654. // If we have a target2 fire it off in sync with our gun firing
  1655. G_UseTargets2( self, self, self->target2 );
  1656. }
  1657. gi.G2API_SetBoneAnimIndex( &self->ghoul2[self->playerModel], self->rootBone, 0, 8, BONE_ANIM_OVERRIDE_FREEZE, 0.6f, cg.time );
  1658. self->nextthink = level.time + self->wait + crandom() * self->random;
  1659. }
  1660. //----------------------------------------------------------------------------------------------
  1661. void ion_cannon_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod,int dFlags,int hitLoc )
  1662. //----------------------------------------------------------------------------------------------
  1663. {
  1664. vec3_t org;
  1665. // dead, so nuke the ghoul model and put in the damage md3 version
  1666. if ( self->playerModel >= 0 )
  1667. {
  1668. gi.G2API_RemoveGhoul2Model( self->ghoul2, self->playerModel );
  1669. }
  1670. self->s.modelindex = self->s.modelindex2;
  1671. self->s.modelindex2 = 0;
  1672. // Turn off the thinking of the base & use it's targets
  1673. self->e_ThinkFunc = thinkF_NULL;
  1674. self->e_UseFunc = useF_NULL;
  1675. if ( self->target )
  1676. {
  1677. G_UseTargets( self, attacker );
  1678. }
  1679. // clear my data
  1680. self->e_DieFunc = dieF_NULL;
  1681. self->takedamage = qfalse;
  1682. self->health = 0;
  1683. self->takedamage = qfalse;//stop chain reaction runaway loops
  1684. self->s.loopSound = 0;
  1685. // not solid anymore
  1686. self->contents = 0;
  1687. VectorCopy( self->currentOrigin, self->s.pos.trBase );
  1688. VectorCopy( self->currentOrigin, org );
  1689. org[2] += 20;
  1690. G_PlayEffect( "env/ion_cannon_explosion", org );
  1691. if ( self->splashDamage > 0 && self->splashRadius > 0 )
  1692. {
  1693. G_RadiusDamage( self->currentOrigin, attacker, self->splashDamage, self->splashRadius,
  1694. attacker, MOD_UNKNOWN );
  1695. }
  1696. gi.linkentity( self );
  1697. }
  1698. //----------------------------------------------------------------------------
  1699. void ion_cannon_use( gentity_t *self, gentity_t *other, gentity_t *activator )
  1700. //----------------------------------------------------------------------------
  1701. {
  1702. // toggle
  1703. if ( self->e_ThinkFunc == thinkF_NULL )
  1704. {
  1705. // start thinking now
  1706. self->e_ThinkFunc = thinkF_ion_cannon_think;
  1707. self->nextthink = level.time + FRAMETIME; // fires right on being used
  1708. }
  1709. else
  1710. {
  1711. self->e_ThinkFunc = thinkF_NULL;
  1712. }
  1713. }
  1714. /*QUAKED misc_ion_cannon (1 0 0) (-280 -280 0) (280 280 640) START_OFF BURSTS SHIELDED
  1715. Huge ion cannon, like the ones at the rebel base on Hoth.
  1716. START_OFF - Starts off
  1717. BURSTS - adds more variation, shots come out in bursts
  1718. SHIELDED - cannon is shielded, any kind of shot bounces off.
  1719. wait - How fast it shoots (default 1500 ms between shots, can't be less than 500 ms)
  1720. random - milliseconds wait variation (default 400 ms...up to plus or minus .4 seconds)
  1721. delay - Number of milliseconds between bursts (default 6000 ms, can't be less than 1000 ms, only works when BURSTS checked)
  1722. health - default 2000
  1723. splashDamage - how much damage to do when it dies, must be greater than 0 to actually work
  1724. splashRadius - damage radius, must be greater than 0 to actually work
  1725. targetname - Toggles it on/off
  1726. target - What to use when destroyed
  1727. target2 - What to use when it fires a shot.
  1728. */
  1729. //-----------------------------------------------------
  1730. void SP_misc_ion_cannon( gentity_t *base )
  1731. //-----------------------------------------------------
  1732. {
  1733. G_SetAngles( base, base->s.angles );
  1734. G_SetOrigin(base, base->s.origin);
  1735. base->s.modelindex = G_ModelIndex( "models/map_objects/imp_mine/ion_cannon.glm" );
  1736. base->playerModel = gi.G2API_InitGhoul2Model( base->ghoul2, "models/map_objects/imp_mine/ion_cannon.glm", base->s.modelindex );
  1737. base->s.radius = 320.0f;
  1738. VectorSet( base->s.modelScale, 2.0f, 2.0f, 2.0f );
  1739. base->rootBone = gi.G2API_GetBoneIndex( &base->ghoul2[base->playerModel], "model_root", qtrue );
  1740. base->torsoBolt = gi.G2API_AddBolt( &base->ghoul2[base->playerModel], "*flash02" );
  1741. // register damage model
  1742. base->s.modelindex2 = G_ModelIndex( "models/map_objects/imp_mine/ion_cannon_damage.md3" );
  1743. base->e_UseFunc = useF_ion_cannon_use;
  1744. // How quickly to fire
  1745. if ( base->wait == 0.0f )
  1746. {
  1747. base->wait = 1500.0f;
  1748. }
  1749. else if ( base->wait < 500.0f )
  1750. {
  1751. base->wait = 500.0f;
  1752. }
  1753. if ( base->random == 0.0f )
  1754. {
  1755. base->random = 400.0f;
  1756. }
  1757. if ( base->delay == 0 )
  1758. {
  1759. base->delay = 6000;
  1760. }
  1761. else if ( base->delay < 1000 )
  1762. {
  1763. base->delay = 1000;
  1764. }
  1765. // we only take damage from a heavy weapon class missile
  1766. base->flags |= FL_DMG_BY_HEAVY_WEAP_ONLY;
  1767. if ( base->spawnflags & 4 )//shielded
  1768. {
  1769. base->flags |= FL_SHIELDED; //technically, this would only take damage from a lightsaber, but the other flag just above would cancel that out too.
  1770. }
  1771. G_SpawnInt( "health", "2000", &base->health );
  1772. base->e_DieFunc = dieF_ion_cannon_die;
  1773. base->takedamage = qtrue;
  1774. // Start Off?
  1775. if ( base->spawnflags & 1 )
  1776. {
  1777. base->e_ThinkFunc = thinkF_NULL;
  1778. }
  1779. else
  1780. {
  1781. // start thinking now, otherwise, we'll wait until we are used
  1782. base->e_ThinkFunc = thinkF_ion_cannon_think;
  1783. base->nextthink = level.time + base->wait + crandom() * base->random;
  1784. }
  1785. // Bursts?
  1786. if ( base->spawnflags & 2 )
  1787. {
  1788. base->count = Q_irand(0,5); // 0-5 bursts
  1789. }
  1790. // precache
  1791. base->fxID = G_EffectIndex( "env/ion_cannon" );
  1792. // Set up our explosion effect for the ExplodeDeath code....
  1793. G_EffectIndex( "env/ion_cannon_explosion" );
  1794. base->contents = CONTENTS_BODY;
  1795. VectorSet( base->mins, -141.0f, -148.0f, 0.0f );
  1796. VectorSet( base->maxs, 142.0f, 135.0f, 245.0f );
  1797. gi.linkentity( base );
  1798. }
  1799. //-----------------------------------------------------
  1800. void spotlight_use( gentity_t *self, gentity_t *other, gentity_t *activator )
  1801. {
  1802. if ( self->e_ThinkFunc == thinkF_NULL )
  1803. {
  1804. // start thinking now, otherwise, we'll wait until we are used
  1805. self->e_ThinkFunc = thinkF_spotlight_think;
  1806. self->nextthink = level.time + FRAMETIME;
  1807. }
  1808. else
  1809. {
  1810. self->e_ThinkFunc = thinkF_NULL;
  1811. self->s.eFlags &= ~EF_ALT_FIRING;
  1812. }
  1813. }
  1814. //-----------------------------------------------------
  1815. void spotlight_think( gentity_t *ent )
  1816. {
  1817. vec3_t dir, end;
  1818. trace_t tr;
  1819. // dumb hack flag so that we can draw an interpolated light cone cgame side.
  1820. ent->s.eFlags |= EF_ALT_FIRING;
  1821. VectorSubtract( ent->enemy->currentOrigin, ent->currentOrigin, dir );
  1822. VectorNormalize( dir );
  1823. vectoangles( dir, ent->s.apos.trBase );
  1824. ent->s.apos.trType = TR_INTERPOLATE;
  1825. VectorMA( ent->currentOrigin, 2048, dir, end ); // just pick some max trace distance
  1826. gi.trace( &tr, ent->currentOrigin, vec3_origin, vec3_origin, end, ent->s.number, CONTENTS_SOLID );
  1827. ent->radius = tr.fraction * 2048.0f;
  1828. if ( tr.fraction < 1 )
  1829. {
  1830. if ( DistanceSquared( tr.endpos, g_entities[0].currentOrigin ) < 140 * 140 )
  1831. {
  1832. // hit player--use target2
  1833. G_UseTargets2( ent, &g_entities[0], ent->target2 );
  1834. #ifndef FINAL_BUILD
  1835. if ( g_developer->integer == PRINT_DEVELOPER )
  1836. {
  1837. Com_Printf( S_COLOR_MAGENTA "Spotlight hit player at time: %d!!!\n", level.time );
  1838. }
  1839. #endif
  1840. }
  1841. }
  1842. ent->nextthink = level.time + 50;
  1843. }
  1844. //-----------------------------------------------------
  1845. void spotlight_link( gentity_t *ent )
  1846. {
  1847. gentity_t *target = 0;
  1848. target = G_Find( target, FOFS(targetname), ent->target );
  1849. if ( !target )
  1850. {
  1851. Com_Printf( S_COLOR_RED "ERROR: spotlight_link: bogus target %s\n", ent->target );
  1852. G_FreeEntity( ent );
  1853. return;
  1854. }
  1855. ent->enemy = target;
  1856. // Start Off?
  1857. if ( ent->spawnflags & 1 )
  1858. {
  1859. ent->e_ThinkFunc = thinkF_NULL;
  1860. ent->s.eFlags &= ~EF_ALT_FIRING;
  1861. }
  1862. else
  1863. {
  1864. // start thinking now, otherwise, we'll wait until we are used
  1865. ent->e_ThinkFunc = thinkF_spotlight_think;
  1866. ent->nextthink = level.time + FRAMETIME;
  1867. }
  1868. }
  1869. /*QUAKED misc_spotlight (1 0 0) (-10 -10 0) (10 10 10) START_OFF
  1870. model="models/map_objects/imp_mine/spotlight.md3"
  1871. Search spotlight that must be targeted at a func_train or other entity
  1872. Uses its target2 when it detects the player
  1873. START_OFF - Starts off
  1874. targetname - Toggles it on/off
  1875. target - What to point at
  1876. target2 - What to use when detects player
  1877. */
  1878. //-----------------------------------------------------
  1879. void SP_misc_spotlight( gentity_t *base )
  1880. //-----------------------------------------------------
  1881. {
  1882. if ( !base->target )
  1883. {
  1884. Com_Printf( S_COLOR_RED "ERROR: misc_spotlight must have a target\n" );
  1885. G_FreeEntity( base );
  1886. return;
  1887. }
  1888. G_SetAngles( base, base->s.angles );
  1889. G_SetOrigin( base, base->s.origin );
  1890. base->s.modelindex = G_ModelIndex( "models/map_objects/imp_mine/spotlight.md3" );
  1891. G_SpawnInt( "health", "300", &base->health );
  1892. // Set up our lightcone effect, though we will have it draw cgame side so it looks better
  1893. G_EffectIndex( "env/light_cone" );
  1894. base->contents = CONTENTS_BODY;
  1895. base->e_UseFunc = useF_spotlight_use;
  1896. // the thing we need to target may not have spawned yet, so try back in a bit
  1897. base->e_ThinkFunc = thinkF_spotlight_link;
  1898. base->nextthink = level.time + 100;
  1899. gi.linkentity( base );
  1900. }
  1901. /*QUAKED misc_panel_turret (0 0 1) (-8 -8 -12) (8 8 16) HEALTH
  1902. Creates a turret that, when the player uses a panel, takes control of this turret and adopts the turret view
  1903. HEALTH - gun turret has health and displays a hud with its current health
  1904. "target" - thing to use when player enters the turret view
  1905. "target2" - thing to use when player leaves the turret view
  1906. "target3" - thing to use when it dies.
  1907. radius - the max yaw range in degrees, (default 90) which means you can move 90 degrees on either side of the start angles.
  1908. random - the max pitch range in degrees, (default 60) which means you can move 60 degrees above or below the start angles.
  1909. delay - time between shots, in milliseconds (default 200).
  1910. damage - amount of damage shots do, (default 50).
  1911. speed - missile speed, (default 3000)
  1912. heatlh - how much heatlh the thing has, (default 200) only works if HEALTH is checked, otherwise it can't be destroyed.
  1913. */
  1914. extern gentity_t *player;
  1915. extern qboolean G_ClearViewEntity( gentity_t *ent );
  1916. extern void G_SetViewEntity( gentity_t *self, gentity_t *viewEntity );
  1917. extern gentity_t *CreateMissile( vec3_t org, vec3_t dir, float vel, int life, gentity_t *owner, qboolean altFire = qfalse );
  1918. void panel_turret_shoot( gentity_t *self, vec3_t org, vec3_t dir)
  1919. {
  1920. gentity_t *missile = CreateMissile( org, dir, self->speed, 10000, self );
  1921. missile->classname = "b_proj";
  1922. missile->s.weapon = WP_TIE_FIGHTER;
  1923. VectorSet( missile->maxs, 9, 9, 9 );
  1924. VectorScale( missile->maxs, -1, missile->mins );
  1925. missile->bounceCount = 0;
  1926. missile->damage = self->damage;
  1927. missile->dflags = DAMAGE_DEATH_KNOCKBACK;
  1928. missile->methodOfDeath = MOD_ENERGY;
  1929. missile->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
  1930. G_SoundOnEnt( self, CHAN_AUTO, "sound/movers/objects/ladygun_fire" );
  1931. VectorMA( org, 32, dir, org );
  1932. org[2] -= 4;
  1933. G_PlayEffect( "ships/imp_blastermuzzleflash", org, dir );
  1934. }
  1935. //-----------------------------------------
  1936. void misc_panel_turret_die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int mod, int dFlags, int hitLoc )
  1937. {
  1938. if ( self->target3 )
  1939. {
  1940. G_UseTargets2( self, player, self->target3 );
  1941. }
  1942. // FIXME: might need some other kind of logic or functionality in here??
  1943. G_UseTargets2( self, player, self->target2 );
  1944. G_ClearViewEntity( player );
  1945. cg.overrides.active &= ~CG_OVERRIDE_FOV;
  1946. cg.overrides.fov = 0;
  1947. }
  1948. //-----------------------------------------
  1949. void panel_turret_think( gentity_t *self )
  1950. {
  1951. // Ensure that I am the viewEntity
  1952. if ( player && player->client && player->client->ps.viewEntity == self->s.number )
  1953. {
  1954. usercmd_t *ucmd = &player->client->usercmd;
  1955. // We are the viewEnt so update our new viewangles based on the sum of our start angles and the ucmd angles
  1956. for ( int i = 0; i < 3; i++ )
  1957. {
  1958. // convert our base angle to a short, add with the usercmd.angle ( a short ), then switch use back to a real angle
  1959. self->s.apos.trBase[i] = AngleNormalize180( SHORT2ANGLE( ucmd->angles[i] + ANGLE2SHORT( self->s.angles[i] ) + self->pos3[i] ));
  1960. }
  1961. // Only clamp if we have a PITCH clamp
  1962. if ( self->random != 0.0f )
  1963. // Angle clamping -- PITCH
  1964. {
  1965. if ( self->s.apos.trBase[PITCH] > self->random ) // random is PITCH
  1966. {
  1967. self->pos3[PITCH] += ANGLE2SHORT( AngleNormalize180( self->random - self->s.apos.trBase[PITCH]));
  1968. self->s.apos.trBase[PITCH] = self->random;
  1969. }
  1970. else if ( self->s.apos.trBase[PITCH] < -self->random )
  1971. {
  1972. self->pos3[PITCH] -= ANGLE2SHORT( AngleNormalize180( self->random + self->s.apos.trBase[PITCH]));
  1973. self->s.apos.trBase[PITCH] = -self->random;
  1974. }
  1975. }
  1976. // Only clamp if we have a YAW clamp
  1977. if ( self->radius != 0.0f )
  1978. {
  1979. float yawDif = AngleSubtract( self->s.apos.trBase[YAW], self->s.angles[YAW] );
  1980. // Angle clamping -- YAW
  1981. if ( yawDif > self->radius ) // radius is YAW
  1982. {
  1983. self->pos3[YAW] += ANGLE2SHORT( self->radius - yawDif );
  1984. self->s.apos.trBase[YAW] = AngleNormalize180( self->s.angles[YAW] + self->radius );
  1985. }
  1986. else if ( yawDif < -self->radius ) // radius is YAW
  1987. {
  1988. self->pos3[YAW] -= ANGLE2SHORT( self->radius + yawDif );
  1989. self->s.apos.trBase[YAW] = AngleNormalize180( self->s.angles[YAW] - self->radius );
  1990. }
  1991. }
  1992. // Let cgame interpolation smooth out the angle changes
  1993. self->s.apos.trType = TR_INTERPOLATE;
  1994. self->s.pos.trType = TR_INTERPOLATE; // not really moving, but this fixes an interpolation bug in cg_ents.
  1995. // Check for backing out of turret
  1996. if ( ( self->useDebounceTime < level.time ) && ((ucmd->buttons & BUTTON_USE) || ucmd->forwardmove || ucmd->rightmove || ucmd->upmove) )
  1997. {
  1998. self->useDebounceTime = level.time + 200;
  1999. G_UseTargets2( self, player, self->target2 );
  2000. G_ClearViewEntity( player );
  2001. G_Sound( player, self->soundPos2 );
  2002. cg.overrides.active &= ~CG_OVERRIDE_FOV;
  2003. cg.overrides.fov = 0;
  2004. if ( ucmd->upmove > 0 )
  2005. {//stop player from doing anything for a half second after
  2006. player->aimDebounceTime = level.time + 500;
  2007. }
  2008. // can be drawn
  2009. // self->s.eFlags &= ~EF_NODRAW;
  2010. }
  2011. else
  2012. {
  2013. // don't draw me when being looked through
  2014. // self->s.eFlags |= EF_NODRAW;
  2015. // self->s.modelindex = 0;
  2016. // we only need to think when we are being used
  2017. self->nextthink = level.time + 50;
  2018. cg.overrides.active |= CG_OVERRIDE_FOV;
  2019. cg.overrides.fov = 90;
  2020. }
  2021. if ( ucmd->buttons & BUTTON_ATTACK || ucmd->buttons & BUTTON_ALT_ATTACK )
  2022. {
  2023. if ( self->attackDebounceTime < level.time )
  2024. {
  2025. vec3_t dir, pt;
  2026. AngleVectors( self->s.apos.trBase, dir, NULL, NULL );
  2027. VectorCopy( self->currentOrigin, pt );
  2028. pt[2] -= 4;
  2029. panel_turret_shoot( self, pt, dir );
  2030. self->attackDebounceTime = level.time + self->delay;
  2031. }
  2032. }
  2033. }
  2034. }
  2035. //-----------------------------------------
  2036. void panel_turret_use( gentity_t *self, gentity_t *other, gentity_t *activator )
  2037. {
  2038. // really only usable by the player
  2039. if ( !activator || !activator->client || activator->s.number )
  2040. {
  2041. return;
  2042. }
  2043. if ( self->useDebounceTime > level.time )
  2044. {
  2045. // can't use it again right away.
  2046. return;
  2047. }
  2048. if ( self->spawnflags & 1 ) // health...presumably the lady luck gun
  2049. {
  2050. G_Sound( self, G_SoundIndex( "sound/movers/objects/ladygun_on" ));
  2051. }
  2052. self->useDebounceTime = level.time + 200;
  2053. // Compensating for the difference between the players view at the time of use and the start angles that the gun object has
  2054. self->pos3[PITCH] = -activator->client->usercmd.angles[PITCH];
  2055. self->pos3[YAW] = -activator->client->usercmd.angles[YAW];
  2056. self->pos3[ROLL] = 0;
  2057. // set me as view entity
  2058. G_UseTargets2( self, activator, self->target );
  2059. G_SetViewEntity( activator, self );
  2060. G_Sound( activator, self->soundPos1 );
  2061. self->e_ThinkFunc = thinkF_panel_turret_think;
  2062. // panel_turret_think( self );
  2063. self->nextthink = level.time + 150;
  2064. }
  2065. //-----------------------------------------
  2066. void SP_misc_panel_turret( gentity_t *self )
  2067. {
  2068. G_SpawnFloat( "radius", "90", &self->radius ); // yaw
  2069. G_SpawnFloat( "random", "60", &self->random ); // pitch
  2070. G_SpawnFloat( "speed" , "3000", &self->speed );
  2071. G_SpawnInt( "delay", "200", &self->delay );
  2072. G_SpawnInt( "damage", "50", &self->damage );
  2073. VectorSet( self->pos3, 0.0f, 0.0f, 0.0f );
  2074. if ( self->spawnflags & 1 ) // heatlh
  2075. {
  2076. self->takedamage = qtrue;
  2077. self->contents = CONTENTS_SHOTCLIP;
  2078. G_SpawnInt( "health", "200", &self->health );
  2079. self->max_health = self->health;
  2080. self->dflags |= DAMAGE_CUSTOM_HUD; // dumb, but we draw a custom hud
  2081. G_SoundIndex( "sound/movers/objects/ladygun_on" );
  2082. }
  2083. self->s.modelindex = G_ModelIndex( "models/map_objects/imp_mine/ladyluck_gun.md3" );
  2084. self->soundPos1 = G_SoundIndex( "sound/movers/camera_on.mp3" );
  2085. self->soundPos2 = G_SoundIndex( "sound/movers/camera_off.mp3" );
  2086. G_SoundIndex( "sound/movers/objects/ladygun_fire" );
  2087. G_EffectIndex("ships/imp_blastermuzzleflash");
  2088. G_SetOrigin( self, self->s.origin );
  2089. G_SetAngles( self, self->s.angles );
  2090. VectorSet( self->mins, -8, -8, -12 );
  2091. VectorSet( self->maxs, 8, 8, 0 );
  2092. self->contents = CONTENTS_SOLID;
  2093. self->s.weapon = WP_TURRET;
  2094. RegisterItem( FindItemForWeapon( WP_EMPLACED_GUN ));
  2095. gi.linkentity( self );
  2096. self->e_UseFunc = useF_panel_turret_use;
  2097. self->e_DieFunc = dieF_misc_panel_turret_die;
  2098. }
  2099. #undef name
  2100. #undef name2
  2101. #undef name3