//called when ammo (for the vulcan cannon) is picked up // Returns the amount picked up int PickupAmmo (int classFlag, int nWeaponIndex, int ammoCount, const char *pszMsg, int nPlayer) { int nMaxAmmo, nCutPoint, nSupposedWeapon = gameData.weapons.nPrimary; int nOldAmmo = classFlag; //kill warning tPlayer *playerP = gameData.multiplayer.players + nPlayer; Assert(classFlag==CLASS_PRIMARY && nWeaponIndex==VULCAN_INDEX); nMaxAmmo = nMaxPrimaryAmmo [nWeaponIndex]; if (playerP->flags & PLAYER_FLAGS_AMMO_RACK) nMaxAmmo *= 2; if (playerP->primaryAmmo [nWeaponIndex] == nMaxAmmo) return 0; nOldAmmo = playerP->primaryAmmo [nWeaponIndex]; playerP->primaryAmmo [nWeaponIndex] += ammoCount; if (playerP->primaryAmmo [nWeaponIndex] > nMaxAmmo) { ammoCount += (nMaxAmmo - playerP->primaryAmmo [nWeaponIndex]); playerP->primaryAmmo [nWeaponIndex] = nMaxAmmo; } if ((nPlayer = gameData.multiplayer.nLocalPlayer)) { nCutPoint = POrderList (255); if ((gameData.weapons.nPrimary == LASER_INDEX) && (playerP->laserLevel >= 4)) nSupposedWeapon = SUPER_LASER_INDEX; // allotment for stupid way of doing super laser if ((playerP->primaryWeaponFlags & (1<<nWeaponIndex)) && (nWeaponIndex > gameData.weapons.nPrimary) && (nOldAmmo == 0) && (POrderList (nWeaponIndex) < nCutPoint) && (POrderList (nWeaponIndex) < POrderList (nSupposedWeapon))) SelectWeapon (nWeaponIndex,0,0,1); } return ammoCount; //return amount used }
void CItemSelectAction::OnAnimationEvent(ICharacterInstance *pCharacter, const AnimEventInstance &event) { const SActorAnimationEvents& animEventsTable = CActor::GetAnimationEventsTable(); if (animEventsTable.m_stowId == event.m_EventNameLowercaseCRC32) { SelectWeapon(); } }
// Called when the bot has a touch marker set static void BotTouchMarkerLogic() { TargetEnemyLogic(self); if (PAST(goal_refresh_time)) { UpdateGoal(self); } if (self->fb.path_state & BOTPATH_RJ_IN_PROGRESS) { if (self->s.v.velocity[2] <= 0) { self->fb.path_state &= ~BOTPATH_RJ_IN_PROGRESS; } } if (! (self->fb.path_state & BOTPATH_RJ_IN_PROGRESS)) { if (PAST (linked_marker_time)) { self->fb.old_linked_marker = NULL; } if (self->fb.old_linked_marker != self->fb.touch_marker) { ProcessNewLinkedMarker (self); } } if (FUTURE(arrow_time)) { if (self->isBot && self->fb.debug_path) { G_bprint(PRINT_HIGH, "%3.2f: arrow_time is %3.2f\n", g_globalvars.time, self->fb.arrow_time); } if (FUTURE(arrow_time2)) { if (g_random() < 0.5) { SetLinkedMarker (self, self->fb.touch_marker, "BotTouchMarkerLogic"); self->fb.old_linked_marker = self->fb.linked_marker; self->fb.path_state = 0; self->fb.linked_marker_time = g_globalvars.time + 0.3; } } } else if (self->fb.linked_marker) { vec3_t dir_move; BotMoveTowardsLinkedMarker(self, dir_move); BotOnGroundMovement(self, dir_move); SetDirectionMove (self, dir_move, ((int)self->s.v.flags & FL_ONGROUND) ? "OnGround" : "InAir"); } else { // The map is, imo, broken at this point, but some old fbca maps are missing links // and at this point would use 'world' // Deliberately don't move and hope that the fall gets us somewhere vec3_t dir_move = { 0, 0, 0 }; SetDirectionMove(self, dir_move, "NoLinkedMarker!"); } SelectWeapon(); }
void TriFusionCheat (int bVerbose) { tPlayer *playerP = &LOCALPLAYER; if (gameStates.players [gameData.multiplayer.nLocalPlayer].bTripleFusion) return; playerP->primaryWeaponFlags |= 1 << FUSION_INDEX; gameStates.players [gameData.multiplayer.nLocalPlayer].bTripleFusion = 1; SelectWeapon (4, 0, 1, 1); DoCheatPenalty (); }
//----------------------------------------------------------------------------- // Purpose: Selects the next item in the weapon menu //----------------------------------------------------------------------------- void CBaseHudWeaponSelection::UserCmd_NextWeapon(void) { // If we're not allowed to draw, ignore weapon selections if ( !BaseClass::ShouldDraw() ) return; CycleToNextWeapon(); if( hud_fastswitch.GetInt() > 0 ) { SelectWeapon(); } UpdateSelectionTime(); }
//----------------------------------------------------------------------------- // Purpose: Think used for selection of weapon menu item. //----------------------------------------------------------------------------- void CBaseHudWeaponSelection::ProcessInput() { C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; // Check to see if the player is in VGUI mode... if ( pPlayer->IsInVGuiInputMode() && !pPlayer->IsInViewModelVGuiInputMode() ) { // If so, close weapon selection when they press fire if ( gHUD.m_iKeyBits & IN_ATTACK ) { if ( HUDTYPE_PLUS != hud_fastswitch.GetInt() ) { // Swallow the button gHUD.m_iKeyBits &= ~IN_ATTACK; input->ClearInputButton( IN_ATTACK ); } engine->ClientCmd( "cancelselect\n" ); } return; } // Has the player selected a weapon? if ( gHUD.m_iKeyBits & (IN_ATTACK | IN_ATTACK2) ) { if ( IsWeaponSelectable() ) { #ifndef TF_CLIENT_DLL if ( HUDTYPE_PLUS != hud_fastswitch.GetInt() ) #endif { // Swallow the button gHUD.m_iKeyBits &= ~(IN_ATTACK | IN_ATTACK2); input->ClearInputButton( IN_ATTACK ); input->ClearInputButton( IN_ATTACK2 ); } // select weapon SelectWeapon(); } } }
//called when a primary weapon is picked up //returns true if actually picked up int PickupPrimary (int nWeaponIndex, int nPlayer) { tPlayer *playerP = gameData.multiplayer.players + nPlayer; //ushort oldFlags = LOCALPLAYER.primaryWeaponFlags; ushort flag = 1 << nWeaponIndex; int nCutPoint; int nSupposedWeapon = gameData.weapons.nPrimary; int bTripleFusion = !gameData.multiplayer.weaponStates [nPlayer].bTripleFusion && (nWeaponIndex == FUSION_INDEX) && EGI_FLAG (bTripleFusion, 0, 0, 0); if ((nWeaponIndex != LASER_INDEX) && (playerP->primaryWeaponFlags & flag) && !bTripleFusion) { if (ISLOCALPLAYER (nPlayer)) HUDInitMessage ("%s %s!", TXT_ALREADY_HAVE_THE, PRIMARY_WEAPON_NAMES (nWeaponIndex)); return 0; } if (!(playerP->primaryWeaponFlags & flag)) playerP->primaryWeaponFlags |= flag; else if (bTripleFusion) { if (nPlayer == gameData.multiplayer.nLocalPlayer) gameData.weapons.bTripleFusion = 1; else gameData.multiplayer.weaponStates [nPlayer].bTripleFusion = 1; } if (ISLOCALPLAYER (nPlayer)) { nCutPoint = POrderList (255); if ((gameData.weapons.nPrimary == LASER_INDEX) && (playerP->laserLevel >= 4)) nSupposedWeapon = SUPER_LASER_INDEX; // allotment for stupid way of doing super laser if ((gameOpts->gameplay.nAutoSelectWeapon == 2) && (POrderList (nWeaponIndex) < nCutPoint) && (POrderList (nWeaponIndex) < POrderList (nSupposedWeapon))) SelectWeapon (nWeaponIndex, 0, 0, 1); PALETTE_FLASH_ADD (7,14,21); if (nWeaponIndex != LASER_INDEX) HUDInitMessage ("%s!", PRIMARY_WEAPON_NAMES (nWeaponIndex)); } return 1; }
void AAgent::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); SensingComp->RequestStimuliListenerUpdate(); if (bPlayerSeen) { // Check our LoS to the player and act accordingly when broken. CheckLoS(); // Inside the bPlayerSeen check because there is no point in the agent // changing weapon if they cannot see the weapon FVector AgentPos = GetActorLocation(); FVector PlayerPos = FVector(0.0f, 0.0f, 0.0f); AAgentController* Controller = Cast<AAgentController>(GetController()); if (Controller != NULL) PlayerPos = Controller->GetFocalPoint(); // Get the vector from the agent to the player FVector AgentToPlayer = PlayerPos - AgentPos; // Pass the distance between the agent and the player (magnitude of the vector) // Continiously make choices on which weapon to select SelectWeapon(AgentToPlayer.Size()); } }
void TacRefDlg::OnSelect(AWEvent* event) { if (lst_designs) { int seln = lst_designs->GetSelection(); DWORD dsn = lst_designs->GetItemData(seln); if (mode == MODE_SHIPS) { ship_index = seln; if (dsn) { SelectShip((ShipDesign*) dsn); } } else if (mode == MODE_WEAPONS) { weap_index = seln; if (dsn) { SelectWeapon((WeaponDesign*) dsn); } } } }
// --------------------------------------------------------------------- //called when one of these weapons is picked up //when you pick up a secondary, you always get the weapon & ammo for it // Returns true if powerup picked up, else returns false. int PickupSecondary (tObject *objP, int nWeaponIndex, int nAmount, int nPlayer) { int nMaxAmount; int nPickedUp; int nCutPoint, bEmpty = 0, bSmokeGrens; tPlayer *playerP = gameData.multiplayer.players + nPlayer; if ((nWeaponIndex == PROXMINE_INDEX) && !COMPETITION && EGI_FLAG (bSmokeGrenades, 0, 0, 0)) { bSmokeGrens = 1; nMaxAmount = 4; } else { bSmokeGrens = 0; nMaxAmount = nMaxSecondaryAmmo [nWeaponIndex]; if (playerP->flags & PLAYER_FLAGS_AMMO_RACK) nMaxAmount *= 2; } if (playerP->secondaryAmmo [nWeaponIndex] >= nMaxAmount) { if (ISLOCALPLAYER (nPlayer)) HUDInitMessage("%s %i %ss!", TXT_ALREADY_HAVE, playerP->secondaryAmmo [nWeaponIndex], bSmokeGrens ? TXT_SMOKE_GRENADE : SECONDARY_WEAPON_NAMES (nWeaponIndex)); return 0; } playerP->secondaryWeaponFlags |= (1 << nWeaponIndex); playerP->secondaryAmmo [nWeaponIndex] += nAmount; nPickedUp = nAmount; if (playerP->secondaryAmmo [nWeaponIndex] > nMaxAmount) { nPickedUp = nAmount - (playerP->secondaryAmmo [nWeaponIndex] - nMaxAmount); playerP->secondaryAmmo [nWeaponIndex] = nMaxAmount; if ((nPickedUp < nAmount) && (nWeaponIndex != PROXMINE_INDEX) && (nWeaponIndex != SMARTMINE_INDEX)) { short nObject = OBJ_IDX (objP); gameData.multiplayer.leftoverPowerups [nObject].nCount = nAmount - nPickedUp; gameData.multiplayer.leftoverPowerups [nObject].nType = secondaryWeaponToPowerup [nWeaponIndex]; gameData.multiplayer.leftoverPowerups [nObject].spitterP = OBJECTS + playerP->nObject; } } if (ISLOCALPLAYER (nPlayer)) { nCutPoint = SOrderList (255); bEmpty = playerP->secondaryAmmo [gameData.weapons.nSecondary] == 0; if (gameOpts->gameplay.nAutoSelectWeapon) { if (gameOpts->gameplay.nAutoSelectWeapon == 1) { if (bEmpty) SelectWeapon (nWeaponIndex, 1, 0, 1); } else if ((SOrderList (nWeaponIndex) < nCutPoint) && (bEmpty || (SOrderList (nWeaponIndex) < SOrderList (gameData.weapons.nSecondary)))) SelectWeapon (nWeaponIndex,1, 0, 1); else { //if we don't auto-select this weapon, but it's a proxbomb or smart mine, //we want to do a mini-auto-selection that applies to the drop bomb key if ((nWeaponIndex == PROXMINE_INDEX || nWeaponIndex == SMARTMINE_INDEX) && !(gameData.weapons.nSecondary == PROXMINE_INDEX || gameData.weapons.nSecondary == SMARTMINE_INDEX)) { int cur = bLastSecondaryWasSuper [PROXMINE_INDEX] ? PROXMINE_INDEX : SMARTMINE_INDEX; if (SOrderList (nWeaponIndex) < SOrderList (cur)) bLastSecondaryWasSuper[PROXMINE_INDEX] = (nWeaponIndex == SMARTMINE_INDEX); } } } //note: flash for all but concussion was 7,14,21 if (nAmount>1) { PALETTE_FLASH_ADD (15,15,15); HUDInitMessage("%d %s%s", nPickedUp, bSmokeGrens ? TXT_SMOKE_GRENADES : SECONDARY_WEAPON_NAMES (nWeaponIndex), TXT_SX); } else { PALETTE_FLASH_ADD (10,10,10); HUDInitMessage("%s!", bSmokeGrens ? TXT_SMOKE_GRENADE : SECONDARY_WEAPON_NAMES (nWeaponIndex)); } } return 1; }
void AutoSelectWeapon (int nWeaponType, int bAutoSelect) { int r; int nCutPoint; int bLooped = 0; if (bAutoSelect && !gameOpts->gameplay.nAutoSelectWeapon) return; if (!nWeaponType) { r = PlayerHasWeapon (WeaponId (gameData.weapons.nPrimary), 0, -1, 0); if ((r != HAS_ALL) || bCycling) { int bTryAgain = 1; int iCurWeapon = POrderList (WeaponId (gameData.weapons.nOverridden)); int iNewWeapon = iCurWeapon; int nCurWeapon, nNewWeapon; nCurWeapon = primaryOrder [iCurWeapon]; nCutPoint = POrderList (255); while (bTryAgain) { if (++iNewWeapon >= nCutPoint) { if (bLooped) { if (bCycling) SelectWeapon (gameData.weapons.nPrimary, 0, 0, 1); else { HUDInitMessage (TXT_NO_PRIMARY); #ifdef TACTILE if (TactileStick) ButtonReflexClear(0); #endif SelectWeapon (0, 0, 0, 1); } return; } iNewWeapon = 0; bLooped = 1; } if (iNewWeapon == MAX_PRIMARY_WEAPONS) iNewWeapon = 0; // Hack alert! Because the fusion uses 0 energy at the end (it's got the weird chargeup) // it looks like it takes 0 to fire, but it doesn't, so never auto-select. // if (primaryOrder [iNewWeapon] == FUSION_INDEX) // continue; nNewWeapon = primaryOrder [iNewWeapon]; if (nNewWeapon == gameData.weapons.nPrimary) { if ((nCurWeapon == SUPER_LASER_INDEX) && (nNewWeapon == LASER_INDEX)) continue; else if (bCycling) SelectWeapon (gameData.weapons.nPrimary, 0, 0, 1); else { HUDInitMessage (TXT_NO_PRIMARY); #ifdef TACTILE if (TactileStick) ButtonReflexClear (0); #endif // if (POrderList(0)<POrderList(255)) SelectWeapon(0, 0, 0, 1); } return; // Tried all weapons! } else { if ((nNewWeapon != 255) && (PlayerHasWeapon (nNewWeapon, 0, -1, 0) == HAS_ALL)) { SelectWeapon ((nNewWeapon == SUPER_LASER_INDEX) ? LASER_INDEX : nNewWeapon, 0, 1, 1); bLastPrimaryWasSuper [nNewWeapon % SUPER_WEAPON] = (nNewWeapon >= SUPER_WEAPON); return; } } } } } else { Assert(nWeaponType==1); r = PlayerHasWeapon (gameData.weapons.nSecondary, 1, -1, 0); if (r != HAS_ALL || bCycling) { int bTryAgain = 1; int iCurWeapon = SOrderList (gameData.weapons.nSecondary); nCutPoint = SOrderList (255); while (bTryAgain) { if (++iCurWeapon >= nCutPoint) { if (bLooped) { if (bCycling) SelectWeapon (gameData.weapons.nSecondary, 1, 0, 1); else HUDInitMessage (TXT_NO_SECSELECT); return; } iCurWeapon = 0; bLooped = 1; } if (iCurWeapon == MAX_SECONDARY_WEAPONS) iCurWeapon = 0; if (secondaryOrder [iCurWeapon] == gameData.weapons.nSecondary) { if (bCycling) SelectWeapon (gameData.weapons.nSecondary, 1, 0, 1); else HUDInitMessage (TXT_NO_SECAVAIL); return; // Tried all weapons! } else if (PlayerHasWeapon (secondaryOrder [iCurWeapon], 1, -1, 0) == HAS_ALL) { SelectWeapon (secondaryOrder [iCurWeapon], 1, 1, 1); bTryAgain = 0; } } } } }
//flags whether the last time we use this weapon, it was the 'super' version // ------------------------------------------------------------------------------------ // Select a weapon, primary or secondary. void DoSelectWeapon (int nWeapon, int bSecondary) { int nWeaponSave = nWeapon; int nWeaponStatus, nCurrent, hasFlag; ubyte bLastWasSuper; if (!bSecondary) { nCurrent = gameData.weapons.nPrimary; if ((nCurrent == LASER_INDEX) && (LOCALPLAYER.laserLevel > MAX_LASER_LEVEL)) nCurrent = SUPER_LASER_INDEX; bLastWasSuper = bLastPrimaryWasSuper [nWeapon]; if ((nWeapon == LASER_INDEX) && (LOCALPLAYER.laserLevel > MAX_LASER_LEVEL)) nWeapon = SUPER_LASER_INDEX; hasFlag = HAS_WEAPON_FLAG; LOCALPLAYER.energy += gameData.fusion.xCharge; gameData.fusion.xCharge = 0; } else if (nWeapon == 2) { ToggleBomb (); return; } else { nCurrent = gameData.weapons.nSecondary; bLastWasSuper = bLastSecondaryWasSuper [nWeapon % SUPER_WEAPON]; hasFlag = HAS_WEAPON_FLAG + HAS_AMMO_FLAG; } if ((nCurrent == nWeapon) || (nCurrent == nWeapon + SUPER_WEAPON)) { //already have this selected, so toggle to other of Normal/super version if (!bSecondary && (nCurrent == SUPER_LASER_INDEX)) return; nWeapon %= SUPER_WEAPON; if (!bLastWasSuper) nWeapon += SUPER_WEAPON; nWeaponStatus = PlayerHasWeapon (nWeapon, bSecondary, -1, 0); } else { //go to last-select version of requested missile if (bLastWasSuper && (nWeapon < SUPER_WEAPON)) nWeapon += SUPER_WEAPON; nWeaponStatus = PlayerHasWeapon (nWeapon, bSecondary, -1, 0); //if don't have last-selected, try other version if ((nWeaponStatus & hasFlag) != hasFlag) { nWeapon = 2 * nWeaponSave + SUPER_WEAPON - nWeapon; nWeaponStatus = PlayerHasWeapon (nWeapon, bSecondary, -1, 0); if ((nWeaponStatus & hasFlag) != hasFlag) nWeapon = 2 * nWeaponSave + SUPER_WEAPON - nWeapon; } } //if we don't have the weapon we're switching to, give error & bail if ((nWeaponStatus & hasFlag) != hasFlag) { if (!bSecondary) { if (nWeapon == SUPER_LASER_INDEX) return; //no such thing as super laser, so no error HUDInitMessage ("%s %s!", TXT_DONT_HAVE, PRIMARY_WEAPON_NAMES (nWeapon)); } else HUDInitMessage ("%s %s%s",TXT_HAVE_NO, SECONDARY_WEAPON_NAMES (nWeapon), TXT_SX); DigiPlaySample (SOUND_BAD_SELECTION, F1_0); return; } //now actually select the weapon SelectWeapon (nWeapon, bSecondary, 1, 1); }
/* ** GroundClass Exec() function. ** NOTE: returns TRUE if we've processed this frame. FALSE if we're to do ** dead reckoning (in VU) */ int GroundClass::Exec (void) { //RV - I-Hawk - Added a 0 vector for RV new PS calls Tpoint PSvec; PSvec.x = 0; PSvec.y = 0; PSvec.z = 0; Tpoint pos; Tpoint vec; float speedScale; float groundZ; float labelLOD; float drawLOD; RadarClass *radar = NULL; SoundPos.UpdatePos((SimBaseClass *)this); //Cobra pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f; // MLR 5/23/2004 - pos.x = XPos(); pos.y = YPos(); pos.z = OTWDriver.GetApproxGroundLevel( pos.x, pos.y ); // pos.z = -10.0f;//Cobra trying to fix the stupid uninit CTD SetPosition(pos.x, pos.y, pos.z); // dead? -- we do nothing if ( IsDead() ){ return FALSE; } // if damaged if ( pctStrength < 0.5f ){ if (sfxTimer > 1.5f - gai->distLOD * 1.3){ // reset the timer sfxTimer = 0.0f; pos.z -= 10.0f; // VP_changes this shoud be checked why have GetGroundLevel been subtracted by 10.0F // Sometimes the trails seem strange vec.x = PRANDFloat() * 20.0f; vec.y = PRANDFloat() * 20.0f; vec.z = PRANDFloat() * 20.0f; /* OTWDriver.AddSfxRequest( new SfxClass( SFX_TRAILSMOKE, // type SFX_MOVES | SFX_NO_GROUND_CHECK, // flags &pos, // world pos &vec, // vector 3.5f, // time to live 4.5f // scale ) ); */ DrawableParticleSys::PS_AddParticleEx((SFX_TRAILSMOKE + 1), &pos, &vec); } } if (IsExploding()){ // KCK: I've never seen this section of code executed. Maybe it gets hit, but I doubt // it. if (!IsSetFlag( SHOW_EXPLOSION )){ // Show the explosion Tpoint pos, vec; Falcon4EntityClassType *classPtr = (Falcon4EntityClassType *)EntityType(); //DrawableGroundVehicle *destroyedPtr; // FRB //Cobra TJL 11/07/04 CTD point initialize here pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f; // MLR 5/23/2004 - uncommented out the x, y pos.x = XPos(); pos.y = YPos(); pos.z = OTWDriver.GetApproxGroundLevel( pos.x, pos.y ) - 10.0f; vec.x = 0.0f; vec.y = 0.0f; vec.z = 0.0f; // create a new drawable for destroyed vehicle // sometimes..... //RV - I-Hawk - Commenting all this if statement... not necessary /* if ( rand() & 1 ){ destroyedPtr = new DrawableGroundVehicle( classPtr->visType[3], &pos, Yaw(), 1.0f ); groundZ = PRANDFloatPos() * 60.0f + 15.0f; /* OTWDriver.AddSfxRequest( new SfxClass ( SFX_BURNING_PART, // type &pos, // world pos &vec, // (DrawableBSP *)destroyedPtr, groundZ, // time to live 1.0f // scale ) ); */ /* DrawableParticleSys::PS_AddParticleEx((SFX_BURNING_PART + 1), &pos, &vec); pos.z += 10.0f; /* OTWDriver.AddSfxRequest( new SfxClass( SFX_FEATURE_EXPLOSION, // type &pos, // world pos groundZ, // time to live 100.0f // scale ) ); */ /* DrawableParticleSys::PS_AddParticleEx((SFX_FEATURE_EXPLOSION + 1), &pos, &PSvec); } */ //RV - I-Hawk - seperating explosion type for ground/sea domains. also //adding a check so soldiers will not explode like ground vehicles... if (GetDomain() == DOMAIN_LAND && GetType() != TYPE_FOOT) { //pos.z -= 20.0f; /* OTWDriver.AddSfxRequest( new SfxClass( SFX_VEHICLE_EXPLOSION, // type &pos, // world pos 1.5f, // time to live 100.0f // scale ) ); */ DrawableParticleSys::PS_AddParticleEx((SFX_VEHICLE_EXPLOSION + 1), &pos, &PSvec); } else if ( GetDomain() == DOMAIN_SEA ) { DrawableParticleSys::PS_AddParticleEx((SFX_WATER_FIREBALL + 1), &pos, &PSvec); } // make sure we don't do it again... SetFlag( SHOW_EXPLOSION ); // we can now kill it immediately SetDead(TRUE); } return FALSE; } // exec any base functionality SimVehicleClass::Exec(); // Sept 30, 2002 // VP_changes: Frequently Z value is not in the correct place. It should follow the terrain. if ( drawPointer ){ drawPointer->GetPosition( &pos ); } else { return FALSE; } //JAM 27Sep03 - Let's try this groundZ = pos.z; // - 0.7f; KCK: WTF is this? //VP_changes Sept 25 groundZ = OTWDriver.GetGroundLevel( pos.x, pos.y ); // Movement/Targeting for local entities if (IsLocal() && SimDriver.MotionOn()) { //I commented this out, because it is done in gai->ProcessTargeting down below DSP 4/30/99 // Refresh our target pointer (if any) //SetTarget( SimCampHandoff( targetPtr, targetList, HANDOFF_RANDOM ) ); // Look for someone to do radar fire control for us FindBattalionFireControl(); // RV - Biker - Switch on lights for ground/naval vehicles int isNight = TimeOfDayGeneral(TheCampaign.CurrentTime) < TOD_DAWNDUSK ? true : false; if (drawPointer && ((DrawableBSP *)drawPointer)->GetNumSwitches() >= AIRDEF_LIGHT_SWITCH) { if (isShip) { isNight = (TimeOfDayGeneral(TheCampaign.CurrentTime) <= TOD_DAWNDUSK || realWeather->weatherCondition == INCLEMENT) ? true : false; if (pctStrength > 0.50f) { ((DrawableBSP *)drawPointer)->SetSwitchMask(0, isNight); ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, isNight); } } else if (GetVt() > 1.0f) { VuListIterator vehicleWalker(SimDriver.combinedList); FalconEntity* object = (FalconEntity*)vehicleWalker.GetFirst(); bool hasThreat = false; float range = 999.9f * NM_TO_FT; // Consider each potential target in our environment while (object && !hasThreat) { // Skip sleeping sim objects if (object->IsSim()) { if (!((SimBaseClass*)object)->IsAwake()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } } // Fow now we skip missles -- might want to display them eventually... if (object->IsMissile() || object->IsBomb()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } if (object->GetTeam() == GetTeam()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } float dx = object->XPos() - XPos(); float dy = object->YPos() - YPos(); float dz = object->ZPos() - ZPos(); range = (float)sqrt(dx*dx + dy*dy + dz*dz); if (range < 5.0f * NM_TO_FT) hasThreat = true; object = (FalconEntity*)vehicleWalker.GetNext(); } // If no enemy nearby and not heavy damaged switch on lights if (!hasThreat && pctStrength > 0.75f) { ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, isNight); } else { ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } else { ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } // RV - Biker - Do also switch on lights for tractor vehicles if (truckDrawable && truckDrawable->GetNumSwitches() >= AIRDEF_LIGHT_SWITCH) { if (GetVt() > 1.0f) { VuListIterator vehicleWalker(SimDriver.combinedList); FalconEntity* object = (FalconEntity*)vehicleWalker.GetFirst(); bool hasThreat = false; float range = 999.9f * NM_TO_FT; // Consider each potential target in our environment while (object && !hasThreat) { // Skip sleeping sim objects if (object->IsSim()) { if (!((SimBaseClass*)object)->IsAwake()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } } // Fow now we skip missles -- might want to display them eventually... if (object->IsMissile() || object->IsBomb()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } if (object->GetTeam() == GetTeam()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } float dx = object->XPos() - XPos(); float dy = object->YPos() - YPos(); float dz = object->ZPos() - ZPos(); range = (float)sqrt(dx*dx + dy*dy + dz*dz); if (range < 5.0f * NM_TO_FT) hasThreat = true; object = (FalconEntity*)vehicleWalker.GetNext(); } // If no enemy nearby and not heavy damaged switch on lights if (!hasThreat && pctStrength > 0.75f) { truckDrawable->SetSwitchMask(AIRDEF_LIGHT_SWITCH, isNight); } else { truckDrawable->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } else { truckDrawable->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } // RV - Biker - Shut down ship radar if damaged if (isShip && radarDown == false && pctStrength < 0.9f && rand()%50 > (pctStrength - 0.50f)*100) { isEmitter = false; RadarClass *radar = (RadarClass*)FindSensor(this, SensorClass::Radar); if (radar) { radarDown = true; radar->SetDesiredTarget(NULL); radar->SetEmitting(FALSE); } if (targetPtr) { SelectWeapon(true); } } // 2001-03-26 ADDED BY S.G. NEED TO KNOW IF THE RADAR CALLED SetSpotted // RV - Biker - Rotate radars float deltaDOF; float curDOF = GetDOFValue(5); deltaDOF = 180.0f * DTR * SimLibMajorFrameTime; curDOF += deltaDOF; if ( curDOF > 360.0f * DTR ) curDOF -= 360.0f * DTR; SetDOF(5, curDOF); int spottedSet = FALSE; // END OF ADDED SECTION // 2002-03-21 ADDED BY S.G. // If localData only has zeros, // there is a good chance they are not valid (should not happen here though)... if (targetPtr) { SimObjectLocalData* localData= targetPtr->localData; if ( localData->ataFrom == 0.0f && localData->az == 0.0f && localData->el == 0.0f && localData->range == 0.0f ) { CalcRelAzElRangeAta(this, targetPtr); } } // END OF ADDED SECTION 2002-03-21 // check for sending radar emmisions // 2002-02-26 MODIFIED BY S.G. // Added the nextTargetUpdate check to prevent the radar code to run on every frame! if ( isEmitter && nextTargetUpdate < SimLibElapsedTime){ // 2002-02-26 ADDED BY S.G. Next radar scan is 1 sec for aces, 2 for vets, etc ... nextTargetUpdate = SimLibElapsedTime + (5 - gai->skillLevel) * SEC_TO_MSEC; radar = (RadarClass*)FindSensor( this, SensorClass::Radar ); ShiAssert( radar ); if (radar){ radar->Exec( targetList ); } // 2001-03-26 ADDED BY S.G. // IF WE CAN SEE THE RADAR'S TARGET AND WE ARE A AIR DEFENSE THINGY // NOT IN A BKOGEN MORAL STATE, MARK IT AS SPOTTED IF WE'RE BRIGHT ENOUGH if ( radar && radar->CurrentTarget() && gai->skillLevel >= 3 && ((UnitClass *)GetCampaignObject())->GetSType() == STYPE_UNIT_AIR_DEFENSE && !((UnitClass *)GetCampaignObject())->Broken() ){ CampBaseClass *campBaseObj; if (radar->CurrentTarget()->BaseData()->IsSim()){ campBaseObj = ((SimBaseClass *)radar->CurrentTarget()->BaseData())->GetCampaignObject(); } else{ campBaseObj = (CampBaseClass *)radar->CurrentTarget()->BaseData(); } // JB 011002 If campBaseObj is NULL the target may be chaff if (campBaseObj && !(campBaseObj->GetSpotted(GetTeam())) && campBaseObj->IsFlight()){ RequestIntercept((FlightClass *)campBaseObj, GetTeam()); } spottedSet = TRUE; if (campBaseObj && radar->GetRadarDatFile()){ campBaseObj->SetSpotted( GetTeam(), TheCampaign.CurrentTime, (radar->radarData->flag & RAD_NCTR) != 0 && radar->CurrentTarget()->localData && radar->CurrentTarget()->localData->ataFrom < 45.0f * DTR && radar->CurrentTarget()->localData->range < radar->GetRadarDatFile()->MaxNctrRange / (2.0f * (16.0f - (float)gai->skillLevel) / 16.0f) ); } // 2002-03-05 MODIFIED BY S.G. target's aspect and skill used in the equation } // END OF ADDED SECTION } // 2001-03-26 ADDED BY S.G. // IF THE BATTALION LEAD HAS LOS // ON IT AND WE ARE A AIR DEFENSE THINGY NOT IN A BKOGEN MORAL STATE, // MARK IT AS SPOTTED IF WE'RE BRIGHT ENOUGH // 2002-02-11 MODIFED BY S.G. // Since I only identify visually, need to perform this even if spotted by radar in case I can ID it. if ( /*!spottedSet && gai->skillLevel >= 3 && */ ((UnitClass *)GetCampaignObject())->GetSType() == STYPE_UNIT_AIR_DEFENSE && gai == gai->battalionCommand && !((UnitClass *)GetCampaignObject())->Broken() && gai->GetAirTargetPtr() && CheckLOS(gai->GetAirTargetPtr()) ){ CampBaseClass *campBaseObj; if (gai->GetAirTargetPtr()->BaseData()->IsSim()) campBaseObj = ((SimBaseClass *)gai->GetAirTargetPtr()->BaseData())->GetCampaignObject(); else campBaseObj = (CampBaseClass *)gai->GetAirTargetPtr()->BaseData(); // JB 011002 If campBaseObj is NULL the target may be chaff if (!spottedSet && campBaseObj && !(campBaseObj->GetSpotted(GetTeam())) && campBaseObj->IsFlight()) RequestIntercept((FlightClass *)campBaseObj, GetTeam()); if (campBaseObj) campBaseObj->SetSpotted(GetTeam(),TheCampaign.CurrentTime, 1); // 2002-02-11 MODIFIED BY S.G. Visual detection means identified as well } // END OF ADDED SECTION // KCK: When should we run a target update cycle? if (SimLibElapsedTime > lastProcess){ gai->ProcessTargeting(); lastProcess = SimLibElapsedTime + processRate; } // KCK: Check if it's ok to think if (SimLibElapsedTime > lastThought ){ // do movement and (possibly) firing.... gai->Process (); lastThought = SimLibElapsedTime + thoughtRate; } // RV - Biker - Only allow SAM fire if radar still does work SimWeaponClass *theWeapon = Sms->GetCurrentWeapon(); // FRB - This version seems to give SAMs a little more activity if(SimLibElapsedTime > nextSamFireTime && !allowSamFire){ allowSamFire = TRUE; } // Biker's version //if(SimLibElapsedTime > nextSamFireTime && !allowSamFire) //{ // if (radarDown == false || (theWeapon && theWeapon->IsMissile() && theWeapon->sensorArray[0]->Type() == SensorClass::IRST)) // allowSamFire = TRUE; //} // Move and update delta; gai->Move_Towards_Dest(); // edg: always insure that our Z position is valid for the entity. // the draw pointer should have this value // KCK NOTE: The Z we have is actually LAST FRAME's Z. Probably not a big deal. SetPosition( XPos() + XDelta() * SimLibMajorFrameTime, YPos() + YDelta() * SimLibMajorFrameTime, groundZ ); // do firing // this also does weapon keep alive if ( Sms ){ gai->Fire(); } } // KCK: I simplified this some. This is now speed squared. speedScale = XDelta()*XDelta() + YDelta()*YDelta(); // set our level of detail if ( gai == gai->battalionCommand ){ gai->SetDistLOD(); } else{ gai->distLOD = gai->battalionCommand->distLOD; } // do some extra LOD stuff: if the unit is not a lead veh amd the // distLOD is less than a certain value, remove it from the draw // list. if (drawPointer && gai->rank != GNDAI_BATTALION_COMMANDER){ // distLOD cutoff by ranking (KCK: This is explicit for testing, could be a formula/table) if (gai->rank & GNDAI_COMPANY_LEADER){ labelLOD = .5F; drawLOD = .25F; } else if (gai->rank & GNDAI_PLATOON_LEADER){ labelLOD = .925F; drawLOD = .5F; } else { labelLOD = 1.1F; drawLOD = .75F; } // RV - Biker - Why do this maybe helpful knowing which vehicle has problems // Determine wether to draw label or not if (gai->distLOD < labelLOD){ if (!IsSetLocalFlag(NOT_LABELED)){ drawPointer->SetLabel ("", 0xff00ff00); // Don't label SetLocalFlag(NOT_LABELED); } } else if (IsSetLocalFlag(NOT_LABELED)){ SetLabel(this); UnSetLocalFlag(NOT_LABELED); } //if (IsSetLocalFlag(NOT_LABELED)) { // SetLabel(this); // UnSetLocalFlag(NOT_LABELED); //} } if (!targetPtr){ //rotate turret to be pointing forward again float maxAz = TURRET_ROTATE_RATE * SimLibMajorFrameTime; float maxEl = TURRET_ELEVATE_RATE * SimLibMajorFrameTime; float newEl; if (isAirDefense){ newEl = 60.0F*DTR; } else { newEl = 0.0F; } float delta = newEl - GetDOFValue(AIRDEF_ELEV); if(delta > 180.0F*DTR){ delta -= 180.0F*DTR; } else if(delta < -180.0F*DTR){ delta += 180.0F*DTR; } // Do elevation adjustments if (delta > maxEl){ SetDOFInc(AIRDEF_ELEV, maxEl); } else if (delta < -maxEl){ SetDOFInc(AIRDEF_ELEV, -maxEl); } else { SetDOF(AIRDEF_ELEV, newEl); } SetDOF(AIRDEF_ELEV, min(85.0F*DTR, max(GetDOFValue(AIRDEF_ELEV), 0.0F))); SetDOF(AIRDEF_ELEV2, GetDOFValue(AIRDEF_ELEV)); delta = 0.0F - GetDOFValue(AIRDEF_AZIMUTH); if(delta > 180.0F*DTR){ delta -= 180.0F*DTR; } else if(delta < -180.0F*DTR){ delta += 180.0F*DTR; } // Now do the azmuth adjustments if (delta > maxAz){ SetDOFInc(AIRDEF_AZIMUTH, maxAz); } else if (delta < -maxAz){ SetDOFInc(AIRDEF_AZIMUTH, -maxAz); } // RV - Biker - Don't do this //else // SetDOF(AIRDEF_AZIMUTH, 0.0F); } // Special shit by ground type if ( isFootSquad ){ if ( speedScale > 0.0f ){ // Couldn't this be done in the drawable class's update function??? ((DrawableGuys*)drawPointer)->SetSquadMoving( TRUE ); } else { // Couldn't this be done in the drawable class's update function??? ((DrawableGuys*)drawPointer)->SetSquadMoving( FALSE ); } // If we're less than 80% of the way from "FAR" toward the viewer, just draw one guy // otherwise, put 5 guys in a squad. if (gai->distLOD < 0.8f) { ((DrawableGuys*)drawPointer)->SetNumInSquad( 1 ); } else { ((DrawableGuys*)drawPointer)->SetNumInSquad( 5 ); } } // We're not a foot squad, so do the vehicle stuff else if ( !IsSetLocalFlag( IS_HIDDEN ) && speedScale > 300.0f ) { // speedScale /= ( 900.0f * KPH_TO_FPS * KPH_TO_FPS); // essentially 1.0F at 30 mph // JPO - for engine noise VehicleClassDataType *vc = GetVehicleClassData(Type() - VU_LAST_ENTITY_TYPE); ShiAssert(FALSE == F4IsBadReadPtr(vc, sizeof *vc)); // (a) Make sound: // everything sounds like a tank right now if ( GetCampaignObject()->IsBattalion() ){ //if (vc) if (vc && vc->EngineSound!=34){ // kludge prevent 34 from playing SoundPos.Sfx( vc->EngineSound, 0, 1.0, 0); // MLR 5/16/2004 - } else{ SoundPos.Sfx( SFX_TANK, 0, 1.0, 0); // MLR 5/16/2004 - } // (b) Make dust // dustTimer += SimLibMajorFrameTime; // if ( dustTimer > max( 0.2f, 4.5f - speedScale - gai->distLOD * 3.3f ) ) if ( ((rand() & 7) == 7) && gSfxCount[ SFX_GROUND_DUSTCLOUD ] < gSfxLODCutoff && gTotSfx < gSfxLODTotCutoff ){ // reset the timer // dustTimer = 0.0f; pos.x += PRANDFloat() * 5.0f; pos.y += PRANDFloat() * 5.0f; pos.z = groundZ; // RV - Biker - Move that smoke more behind the vehicle mlTrig trig; mlSinCos (&trig, Yaw()); pos.x -= 15.0f*trig.cos; pos.y -= 15.0f*trig.sin; vec.x = PRANDFloat() * 5.0f; vec.y = PRANDFloat() * 5.0f; vec.z = -20.0f; //JAM 24Oct03 - No dust trails when it's raining. if(realWeather->weatherCondition < INCLEMENT){ /* OTWDriver.AddSfxRequest( new SfxClass (SFX_VEHICLE_DUST, // type //JAM 03Oct03 // new SfxClass (SFX_GROUND_DUSTCLOUD, // type SFX_USES_GRAVITY | SFX_NO_DOWN_VECTOR | SFX_MOVES | SFX_NO_GROUND_CHECK, &pos, // world pos &vec, 1.0f, // time to live 1.f)); //JAM 03Oct03 8.5f )); // scale */ DrawableParticleSys::PS_AddParticleEx((SFX_VEHICLE_DUST + 1), &pos, &vec); } } // (c) Make sure we're using our 'Moving' model (i.e. Trucked artillery, APC, etc) if (truckDrawable){ // Keep truck 20 feet behind us (HACK HACK) Tpoint truckPos; mlTrig trig; mlSinCos (&trig, Yaw()); truckPos.x = XPos()-20.0F*trig.cos; truckPos.y = YPos()-20.0F*trig.sin; truckPos.z = ZPos(); truckDrawable->Update(&truckPos, Yaw()+PI); } if (isTowed || hasCrew){ SetSwitch(0,0x2); } } else // itsa task force { if (vc){ SoundPos.Sfx( vc->EngineSound, 0, 1.0, 0); } else { SoundPos.Sfx( SFX_SHIP, 0, 1.0, 0); } //RV - I-Hawk - Do wakes only at some cases if ( (rand() & 7) == 7 ) { //I-Hawk - not using all this anymore // // reset the timer // dustTimer = 0.0f; //float ttl; //static float trailspd = 5.0f; //static float bowfx = 0.92f; //static float sternfx = 0.75f; //float spdratio = GetVt() / ((UnitClass*)GetCampaignObject())->GetMaxSpeed(); float radius; if ( drawPointer ){ radius = drawPointer->Radius(); // JPO from 0.15 - now done inline } else{ radius = 90.0f; } //I-Hawk - Fixed position for ships wakes, effect "delay" in position is //handled by PS now. No more the "V shape" of water wakes. pos.x = XPos() + XDelta() * SimLibMajorFrameTime; pos.y = YPos() + YDelta() * SimLibMajorFrameTime; pos.z = groundZ; //// JPO - think this is sideways on. ///* //vec.x = dmx[1][0] * spdratio * PRANDFloat() * trailspd; //vec.y = dmx[1][1] * spdratio * PRANDFloat() * trailspd; //vec.z = 0.5f; // from -20 JPO //*/ //I-Hawk - More correct vector for wakes vec.x = XDelta(); vec.y = YDelta(); vec.z = 0.0f; //I-Hawk - Separate wake effect for different ships size int theSFX; if ( radius < 200.0f ) { theSFX = SFX_WATER_WAKE_SMALL; } else if ( radius >= 200.0f && radius < 400.0f ) { theSFX = SFX_WATER_WAKE_MEDIUM; } else if ( radius >= 400.0f ) { theSFX = SFX_WATER_WAKE_LARGE; } //I-Hawk - The PS DrawableParticleSys::PS_AddParticleEx((theSFX + 1), &pos, &vec); } } } // Otherwise, we're not moving or are hidden. Do some stuff else { // (b) Make sure we're using our 'Holding' model (i.e. Unlimbered artillery, troops prone, etc) if (truckDrawable){ // Once we stop, our truck doesn't move at all - but sits further away than when moving Tpoint truckPos; truckPos.x = XPos() + 40.0F; truckPos.y = YPos(); truckPos.z = 0.0F; truckDrawable->Update(&truckPos, Yaw()); } if (isTowed || hasCrew){ SetSwitch(0,0x1); } } // ACMI Output if (gACMIRec.IsRecording() && (SimLibFrameCount & 0x0f ) == 0){ ACMIGenPositionRecord genPos; genPos.hdr.time = SimLibElapsedTime * MSEC_TO_SEC + OTWDriver.todOffset; genPos.data.type = Type(); genPos.data.uniqueID = ACMIIDTable->Add(Id(),NULL,TeamInfo[GetTeam()]->GetColor());//.num_; genPos.data.x = XPos(); genPos.data.y = YPos(); genPos.data.z = ZPos(); genPos.data.roll = Roll(); genPos.data.pitch = Pitch(); genPos.data.yaw = Yaw(); // Remove genPos.data.teamColor = TeamInfo[GetTeam()]->GetColor(); gACMIRec.GenPositionRecord( &genPos ); } return IsLocal(); }
void CItemSelectAction::ItemSelectCancelled() { ForceFinish(); SelectWeapon(); }
void CItemSelectAction::Exit() { SelectWeapon(); BaseClass::Exit(); }
void TacRefDlg::OnMode(AWEvent* event) { if (event->window == btn_ships && mode != MODE_SHIPS) { mode = MODE_SHIPS; if (lst_designs) { lst_designs->ClearItems(); List<Text> designs; for (int n = 0; n < 16; n++) { int type = 1 << n; ShipDesign::GetDesignList(type, designs); ListIter<Text> iter = designs; while (++iter) { Text* val = iter.value(); const ShipDesign* dsn = ShipDesign::Get(*val); if (dsn) { char txt[256]; sprintf_s(txt, "%s %s", dsn->abrv, dsn->DisplayName()); lst_designs->AddItemWithData(txt, (DWORD) dsn); } else { lst_designs->AddItemWithData(*val, 0); } } } lst_designs->SetSelected(ship_index); } if (beauty) { beauty->AddView(camview); beauty->DelView(imgview); } DWORD dsn = lst_designs->GetItemData(ship_index); if (dsn) { SelectShip((ShipDesign*) dsn); } } else if (event->window == btn_weaps && mode != MODE_WEAPONS) { mode = MODE_WEAPONS; const WeaponDesign* design = 0; if (lst_designs) { lst_designs->ClearItems(); List<Text> designs; WeaponDesign::GetDesignList(designs); ListIter<Text> iter = designs; while (++iter) { Text* val = iter.value(); if (val->contains("Zolon") || val->contains("Inverted")) continue; const WeaponDesign* dsn = WeaponDesign::Find(*val); if (dsn && !dsn->secret) { lst_designs->AddItemWithData(*val, (DWORD) dsn); if (!design) design = dsn; } } lst_designs->SetSelected(weap_index); } if (beauty) { beauty->DelView(camview); beauty->AddView(imgview); } DWORD dsn = lst_designs->GetItemData(weap_index); if (dsn) { SelectWeapon((WeaponDesign*) dsn); } } btn_ships->SetButtonState(mode == MODE_SHIPS); btn_weaps->SetButtonState(mode == MODE_WEAPONS); }