void CRigidBody::UpdateCollisionReaction() { CVehicle* Car = (CVehicle*)this; Vector3f OldPosition = m_vPosition; // update reflection motion m_vReflection *= RIGIDBODY_REFLECTION_ENTROPY_FACTOR; m_vPosition = m_translate + m_vReflection; m_vDirectionWhenDisturbed = m_vPosition - OldPosition; m_translate = m_vPosition; m_box.Center() = m_vPosition; m_sphere.Center() = m_vPosition; Car->SetVehiclePositionLC(Vector3f(m_vPosition.X(), m_vPosition.Z(), m_vPosition.Y())); // update angular velocity m_vRotation *= RIGIDBODY_ROTATION_ENTROPY_FACTOR; Car->GetRotationLC().Z() += m_vRotation.Y(); // see if reflection has dissipated enough to stop if (m_vReflection.Length() < RIGIDBODY_REFLECTION_DEATH_FACTOR) { disturbed = false; } }
CClientProjectile* CClientProjectileManager::Create(CClientEntity* pCreator, eWeaponType eWeapon, CVector& vecOrigin, float fForce, CVector* target, CClientEntity* pTargetEntity) { m_bCreating = true; m_pLastCreated = NULL; CEntity* pGameCreator = pCreator->GetGameEntity(); CEntity* pGameTargetEntity = NULL; if (pTargetEntity) pGameTargetEntity = pTargetEntity->GetGameEntity(); if (pGameCreator) { // Peds and players if (pCreator->GetType() == CCLIENTPED || pCreator->GetType() == CCLIENTPLAYER) { CPed* pPed = dynamic_cast<CPed*>(pGameCreator); if (pPed) pPed->AddProjectile(eWeapon, vecOrigin, fForce, target, pGameTargetEntity); } // Vehicles else if (pCreator->GetType() == CCLIENTVEHICLE) { CVehicle* pVehicle = dynamic_cast<CVehicle*>(pGameCreator); if (pVehicle) pVehicle->AddProjectile(eWeapon, vecOrigin, fForce, target, pGameTargetEntity); } } m_bCreating = false; return m_pLastCreated; }
void CServerRPCHandler::EmptyVehicleSync(CBitStream * pBitStream, CPlayerSocket * pSenderSocket) { // Ensure we have a valid bit stream if(!pBitStream) return; EntityId playerId = pSenderSocket->playerId; if(CVAR_GET_BOOL("frequentevents")) { CSquirrelArguments pArguments; pArguments.push(playerId); if(g_pEvents->Call("playerEmptyVehicleSyncReceived", &pArguments).GetInteger() != 1 || g_pEvents->Call("playerSyncReceived", &pArguments).GetInteger() != 1) return; } CBitStream bsSend; EMPTYVEHICLESYNCPACKET syncPacket; if(!pBitStream->Read((PCHAR)&syncPacket, sizeof(EMPTYVEHICLESYNCPACKET))) return; CVehicle * pVehicle = g_pVehicleManager->GetAt(syncPacket.vehicleId); if(pVehicle && g_pVehicleManager->DoesExist(syncPacket.vehicleId)) pVehicle->StoreEmptyVehicle(&syncPacket); //bsSend.Write((char *)&syncPacket, sizeof(EMPTYVEHICLESYNCPACKET)); //g_pNetworkManager->RPC(RPC_EmptyVehicleSync, &bsSend, PRIORITY_LOW, RELIABILITY_UNRELIABLE_SEQUENCED, playerId, false); }
void CVehicleUpgrades::ForceAddUpgrade ( unsigned short usUpgrade ) { unsigned char ucSlot; if ( GetSlotFromUpgrade ( usUpgrade, ucSlot ) ) { CVehicle* pVehicle = m_pVehicle->GetGameVehicle (); if ( pVehicle ) { // Grab the upgrade model CModelInfo* pModelInfo = g_pGame->GetModelInfo ( usUpgrade ); if ( pModelInfo ) { if ( !g_pGame->IsASyncLoadingEnabled () || !pModelInfo->IsLoaded () ) { // Request and load now pModelInfo->RequestVehicleUpgrade (); g_pGame->GetStreaming()->LoadAllRequestedModels (); } // Add the upgrade pVehicle->AddVehicleUpgrade ( usUpgrade ); } } // Add it to the slot m_SlotStates [ ucSlot ] = usUpgrade; } }
bool CLightsyncPacket::Write(NetBitStreamInterface& BitStream) const { bool bSyncPosition; if (Count() == 0) return false; for (std::vector<CPlayer*>::const_iterator iter = m_players.begin(); iter != m_players.end(); ++iter) { CPlayer* pPlayer = *iter; CPlayer::SLightweightSyncData& data = pPlayer->GetLightweightSyncData(); CVehicle* pVehicle = pPlayer->GetOccupiedVehicle(); // Find the difference between now and the time the position last changed for the player long long llTicksDifference = GetTickCount64_() - pPlayer->GetPositionLastChanged(); // Right we need to sync the position if there is no vehicle or he's in a vehicle and the difference between setPosition is less than or equal to the // slow sync rate i.e. make sure his position has been updated more than 0.001f in the last 1500ms plus a small margin for error (probably not needed). // This will ensure we only send positions when the position has changed. bSyncPosition = (!pVehicle || pPlayer->GetOccupiedVehicleSeat() == 0) && llTicksDifference <= g_TickRateSettings.iLightSync + 100; BitStream.Write(pPlayer->GetID()); BitStream.Write((unsigned char)pPlayer->GetSyncTimeContext()); unsigned short usLatency = pPlayer->GetPing(); BitStream.WriteCompressed(usLatency); BitStream.WriteBit(data.health.bSync); if (data.health.bSync) { SPlayerHealthSync health; health.data.fValue = pPlayer->GetHealth(); BitStream.Write(&health); SPlayerArmorSync armor; armor.data.fValue = pPlayer->GetArmor(); BitStream.Write(&armor); } BitStream.WriteBit(bSyncPosition); if (bSyncPosition) { SLowPrecisionPositionSync pos; pos.data.vecPosition = pPlayer->GetPosition(); BitStream.Write(&pos); bool bSyncVehicleHealth = data.vehicleHealth.bSync && pVehicle; BitStream.WriteBit(bSyncVehicleHealth); if (bSyncVehicleHealth) { SLowPrecisionVehicleHealthSync health; health.data.fValue = pVehicle->GetHealth(); BitStream.Write(&health); } } } return true; }
void CMapManager::LinkupElements ( void ) { // * Link up all the attaching elements list < CVehicle* > ::const_iterator iterVehicles = m_pVehicleManager->IterBegin (); for ( ; iterVehicles != m_pVehicleManager->IterEnd (); iterVehicles++ ) { CVehicle* pVehicle = *iterVehicles; char* szAttachToID = pVehicle->GetAttachToID (); if ( szAttachToID [ 0 ] ) { CElement* pElement = g_pGame->GetMapManager ()->GetRootElement ()->FindChild ( szAttachToID, 0, true ); if ( pElement ) pVehicle->AttachTo ( pElement ); } } list < CPlayer* > ::const_iterator iterPlayers = m_pPlayerManager->IterBegin (); for ( ; iterPlayers != m_pPlayerManager->IterEnd (); iterPlayers++ ) { CPlayer* pPlayer = *iterPlayers; // Link up all the attaching elements char* szAttachToID = pPlayer->GetAttachToID (); if ( szAttachToID [ 0 ] ) { CElement* pElement = g_pGame->GetMapManager ()->GetRootElement ()->FindChild ( szAttachToID, 0, true ); if ( pElement ) pPlayer->AttachTo ( pElement ); } } CObjectListType::const_iterator iterObjects = m_pObjectManager->IterBegin (); for ( ; iterObjects != m_pObjectManager->IterEnd (); iterObjects++ ) { CObject* pObject = *iterObjects; // Link up all the attaching elements char* szAttachToID = pObject->GetAttachToID (); if ( szAttachToID [ 0 ] ) { CElement* pElement = g_pGame->GetMapManager ()->GetRootElement ()->FindChild ( szAttachToID, 0, true ); if ( pElement ) pObject->AttachTo ( pElement ); } } list < CBlip* > ::const_iterator iterBlips = m_pBlipManager->IterBegin (); for ( ; iterBlips != m_pBlipManager->IterEnd (); iterBlips++ ) { CBlip* pBlip = *iterBlips; // Link up all the attaching elements char* szAttachToID = pBlip->GetAttachToID (); if ( szAttachToID [ 0 ] ) { CElement* pElement = g_pGame->GetMapManager ()->GetRootElement ()->FindChild ( szAttachToID, 0, true ); if ( pElement ) pBlip->AttachTo ( pElement ); } } }
int main () { CVehicle *vehicle = new CShip("1234,887 @", 2005, "Spb", 30); Coord coord = {123.45, 65.56}; vehicle->setCoord(coord); vehicle->setSpeed(456.9); vehicle->printParam(); }
//////////////////////////////////////////////////// // // CMouseControl::ProcessMouseMove // // Process a windows mouse movement message and turn it into control // //////////////////////////////////////////////////// bool CMouseControl::ProcessMouseMove ( UINT uMsg, WPARAM wParam, LPARAM lParam ) { if ( uMsg != WM_MOUSEMOVE ) return false; if ( g_pCore->GetGame ()->GetSystemState () != 9 ) return false; // HACK: Grab our local player, and check his vehicle CPed* pPed = g_pCore->GetGame ()->GetPools ()->GetPedFromRef ( (DWORD)1 ); if ( !pPed ) return false; CVehicle* pVehicle = pPed->GetVehicle (); if ( !pVehicle ) return false; CModelInfo* pModelInfo = g_pCore->GetGame ()->GetModelInfo( pVehicle->GetModelIndex() ); bool bVar; CVARS_GET ( "fly_with_mouse", bVar ); if ( pModelInfo->IsPlane() || pModelInfo->IsHeli() && !bVar ) // Are we in a plane, but not have mouse flight enabled? return false; CVARS_GET ( "steer_with_mouse", bVar ); if ( !bVar ) // Are we in another type of vehicle, but not have mouse steering enabled? return false; // Let's calculate our mouse movement directions CVector2D resolution = g_pCore->GetGUI()->GetResolution(); int iX = LOWORD ( lParam ), iY = HIWORD ( lParam ); float fX = (iX - resolution.fX*0.5f)/resolution.fX; fX *= MOUSE_CONTROL_MULTIPLIER; float fMouseSensitivity = g_pCore->GetGame ( )->GetSettings()->GetMouseSensitivity (); fX *= fMouseSensitivity; m_usLeftStickX += fX*128; m_usLeftStickX = Clamp < const short > ( -128, m_usLeftStickX, 128 ); // Only process Y input if we're in a vehicle that requires it if ( pModelInfo->IsPlane() || pModelInfo->IsHeli() || pModelInfo->IsBike() || pModelInfo->IsBmx() || pModelInfo->IsQuadBike() ) { float fY = (resolution.fY*0.5f - iY)/resolution.fY; fY *= MOUSE_CONTROL_MULTIPLIER; fY *= fMouseSensitivity; CVARS_GET ( "invert_mouse", bVar ); fY = bVar ? -fY : fY; m_usLeftStickY += fY*128; m_usLeftStickY = Clamp < const short > ( -128, m_usLeftStickY, 128 ); } return true; }
//------------------------------------------------------------------------ int CScriptBind_Vehicle::OnUsed(IFunctionHandler* pH, ScriptHandle userHandle, int index) { CVehicle* pVehicle = GetVehicle(pH); if (!pVehicle || !userHandle.n) return pH->EndFunction(0); int ret = pVehicle->OnUsed((EntityId)userHandle.n, index); return pH->EndFunction(ret); }
int CVehicleModuleNatives::GetRespawnDelay(EntityId vehicleId) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) return pVehicle->GetRespawnDelay(); return -1; }
//------------------------------------------------------------------------ int CScriptBind_Vehicle::IsUsable(IFunctionHandler* pH, ScriptHandle userHandle) { CVehicle* pVehicle = GetVehicle(pH); if (!pVehicle || !userHandle.n) return pH->EndFunction(0); int ret = pVehicle->IsUsable((EntityId)userHandle.n); return pH->EndFunction(ret); }
// popVehicleTrunk void Script_popVehicleTrunk(RakNet::BitStream *bitStream, Packet *packet) { BYTE vehicle; bitStream->Read(vehicle); CVehicle *pVehicle = pNetowkManager->GetVehicleManager()->GetAt(vehicle); pVehicle->PopTrunk(); }
int CVehicleModuleNatives::GetDimension(EntityId vehicleId) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) return pVehicle->GetDimension(); return -1; }
/////////////////////////////////////////////////////////////////////////// // // CSimPlayerManager::UpdateSimPlayer // // Thread: main // CS should be locked: no // // Update matching sim player object with new datum // /////////////////////////////////////////////////////////////////////////// void CSimPlayerManager::UpdateSimPlayer ( CPlayer* pPlayer ) { LockSimSystem (); // TODO - only lock the CSimPlayer // Get matching sim player CSimPlayer* pSim = pPlayer->m_pSimPlayer; // Validate if ( !pSim ) { UnlockSimSystem (); return; } // // Copy relevant data // CVehicle* pVehicle = pPlayer->GetOccupiedVehicle (); pSim->m_iStatus = pPlayer->GetStatus (); pSim->m_usBitStreamVersion = pPlayer->GetBitStreamVersion (); pSim->m_bHasOccupiedVehicle = pVehicle != NULL; pSim->m_PlayerID = pPlayer->GetID (); pSim->m_usLatency = pPlayer->GetPing (); pSim->m_ucWeaponType = pPlayer->GetWeaponType (); pSim->m_usVehicleModel = pVehicle ? pVehicle->GetModel () : 0; pSim->m_ucSyncTimeContext = pPlayer->GetSyncTimeContext (); pSim->m_ucOccupiedVehicleSeat = pPlayer->GetOccupiedVehicleSeat (); pSim->m_fWeaponRange = pPlayer->GetWeaponRangeFromSlot(); pSim->m_bVehicleHasHydraulics = pVehicle ? pVehicle->GetUpgrades ()->HasUpgrade ( 1087 ) : false; pSim->m_bVehicleIsPlaneOrHeli = pVehicle ? pVehicle->GetVehicleType () == VEHICLE_PLANE || pVehicle->GetVehicleType () == VEHICLE_HELI : false; pSim->m_sharedControllerState.Copy ( pPlayer->GetPad ()->GetCurrentControllerState () ); pSim->m_fCameraRotation = pPlayer->GetCameraRotation (); pSim->m_fPlayerRotation = pPlayer->GetRotation (); // Update Puresync send list if ( pPlayer->m_bPureSyncSimSendListDirty ) { pPlayer->m_bPureSyncSimSendListDirty = false; pSim->m_PuresyncSendListFlat.clear (); pSim->m_bSendListChanged = true; for ( CFastHashSet < CPlayer* > ::const_iterator iter = pPlayer->m_PureSyncSimSendList.begin (); iter != pPlayer->m_PureSyncSimSendList.end (); ++iter ) { CSimPlayer* pSendSimPlayer = (*iter)->m_pSimPlayer; if ( pSendSimPlayer && pSendSimPlayer->m_bDoneFirstUpdate ) pSim->m_PuresyncSendListFlat.push_back ( pSendSimPlayer ); else pPlayer->m_bPureSyncSimSendListDirty = true; // Retry next time } } // Set this flag pSim->m_bDoneFirstUpdate = true; UnlockSimSystem (); }
static void DoubleCarSpeed(void) { CPlayerPed* pLocalPlayer = pGame->FindPlayerPed(); if (pLocalPlayer->IsInVehicle()) { CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool(); CVehicle* pVehicle = pVehiclePool->GetAt(pVehiclePool->FindIDFromGtaPtr(pLocalPlayer->GetGtaVehicle())); pVehicle->DoubleSpeed(); } }
bool CVehicleModuleNatives::GetTaxiLights(EntityId vehicleId) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) { return pVehicle->GetTaxiLights(); } return false; }
// SetVehicleHealth void Script_SetVehicleHealth(RakNet::BitStream *bitStream, Packet *packet) { BYTE vehicle; float newHealth; bitStream->Read(vehicle); bitStream->Read(newHealth); CVehicle *pVehicle = pNetowkManager->GetVehicleManager()->GetAt(vehicle); pVehicle->SetHealth(newHealth); }
void CVehiclePool::SetForRespawn(BYTE byteVehicleID) { CVehicle *pVehicle = m_pVehicles[byteVehicleID]; if(pVehicle->IsOkToRespawn()) { m_bIsActive[byteVehicleID] = FALSE; m_bIsWasted[byteVehicleID] = TRUE; m_iRespawnDelay[byteVehicleID] = 150; } }
static void Fix(void) { CPlayerPed* pLocalPlayer = pGame->FindPlayerPed(); if (pLocalPlayer->IsInVehicle()) { CVehiclePool* pVehiclePool = pNetGame->GetVehiclePool(); CVehicle* pVehicle = pVehiclePool->GetAt(pVehiclePool->FindIDFromGtaPtr(pLocalPlayer->GetGtaVehicle())); pVehicle->SetHealth(5000); } }
int CVehicleNatives::GetId(SQVM * pVM) { CVehicle * pVehicle = sq_tovehicle(pVM, 2); if(pVehicle) sq_pushinteger(pVM, pVehicle->GetID()); else sq_pushnull(pVM); return 1; }
void CAIUnitList::AddUnit( DWORD dwID ) { int iPlayer = 0; int iType = 0xFFFE; int iUnitType = 0xFFFE; BOOL bControl = FALSE; EnterCriticalSection (&cs); CVehicle *pVehicle = theVehicleMap.GetVehicle( dwID ); if( pVehicle != NULL ) { iPlayer = pVehicle->GetOwner()->GetPlyrNum(); iType = CUnit::vehicle; iUnitType = pVehicle->GetData()->GetType(); bControl = pVehicle->GetOwner()->IsAI(); } else { CBuilding *pBldg = theBuildingMap.GetBldg( dwID ); if( pBldg != NULL ) { iPlayer = pBldg->GetOwner()->GetPlyrNum(); iType = CUnit::building; iUnitType = pBldg->GetData()->GetType(); bControl = pBldg->GetOwner()->IsAI(); } else return; } LeaveCriticalSection (&cs); if( !iPlayer ) return; CAIUnit *pUnit = NULL; try { // CAIUnit( DWORD dwID, int iOwner, class, type ); pUnit = new CAIUnit( dwID, iPlayer, iType, iUnitType ); ASSERT_VALID( pUnit ); AddTail( (CObject *)pUnit ); } catch( CException e ) { // need to report this error occurred throw(ERR_CAI_BAD_NEW); } if( pUnit == NULL ) return; // indicate what controls this unit pUnit->SetControl(bControl); }
// setVehicleLocked(vehicleid, locked) bool CVehicleModuleNatives::SetLocked(EntityId vehicleId, int iLocked) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) { return pVehicle->SetLocked(iLocked); } return false; }
//------------------------------------------------------------------------ int CScriptBind_Vehicle::ChangeSeat(IFunctionHandler* pH, ScriptHandle actorHandle, int seatId, bool isAnimationEnabled) { CVehicle* pVehicle = GetVehicle(pH); if (!pVehicle || !actorHandle.n) return pH->EndFunction(0); bool ret = true; pVehicle->ChangeSeat((EntityId)actorHandle.n, seatId, 0 ); return pH->EndFunction(ret); }
// getVehicleSirenState(vehicleid) bool CVehicleModuleNatives::GetSirenState(EntityId vehicleId) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) { return pVehicle->GetSirenState(); } return false; }
// SetVehicleColor void Script_SetVehicleColor(RakNet::BitStream *bitStream, Packet *packet) { BYTE vehicle; int color1, color2; bitStream->Read(vehicle); bitStream->Read(color1); bitStream->Read(color2); CVehicle *pVehicle = pNetowkManager->GetVehicleManager()->GetAt(vehicle); pVehicle->SetColor(color1, color2); }
// isVehicleOccupied(vehicleid) bool CVehicleModuleNatives::IsOccupied(EntityId vehicleId) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) { return pVehicle->IsOccupied(); } return false; }
int CVehicleModuleNatives::GetVariation(EntityId vehicleId) { CVehicle * pVehicle = g_pVehicleManager->GetAt(vehicleId); if(pVehicle) { return pVehicle->GetVariation(); } return -1; }
//------------------------------------------------------------------------ int CScriptBind_Vehicle::OnSpawnComplete(IFunctionHandler* pH) { CVehicle* pVehicle = GetVehicle(pH); if (!pVehicle) return pH->EndFunction(); pVehicle->OnSpawnComplete(); return pH->EndFunction(); }
//------------------------------------------------------------------------ int CScriptBind_Vehicle::Destroy(IFunctionHandler* pH) { CVehicle* pVehicle = GetVehicle(pH); if (!pVehicle) return pH->EndFunction(); pVehicle->Destroy(); return pH->EndFunction(); }
//------------------------------------------------------------------------ int CScriptBind_Vehicle::GetComponentDamageRatio(IFunctionHandler* pH, const char* pComponentName) { CVehicle* pVehicle = GetVehicle(pH); if (!pVehicle) return pH->EndFunction(); if (IVehicleComponent* pComponent = pVehicle->GetComponent(pComponentName)) return pH->EndFunction(pComponent->GetDamageRatio()); return pH->EndFunction(); }