bool Settings::SaveToFile(const std::string &file) { if (file.empty()) return false; std::ofstream fileStream(file.c_str(), std::ios_base::trunc | std::ios_base::binary); if (fileStream.is_open()) { int soundEnabled = (IsSoundEnabled() ? 1 : 0); int noAs = GetNoInitialAsteroids(); fileStream.write(reinterpret_cast<const char*>(&soundEnabled), sizeof(soundEnabled)); fileStream.write(reinterpret_cast<const char*>(&noAs), sizeof(noAs)); fileStream.close(); return true; } return false; }
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select/* =true */, bool keepHistory/* =true */, const char *setup /*= NULL*/) { CActor *pActor=GetActor(pickerId); if (!pActor) return; TriggerRespawn(); GetEntity()->EnablePhysics(false); Physicalize(false, false); bool soundEnabled = IsSoundEnabled(); EnableSound(sound); SetViewMode(0); SetOwnerId(pickerId); CopyRenderFlags(GetOwner()); Hide(true); m_stats.dropped = false; m_stats.detached = false; m_stats.brandnew = false; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) { GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName()); return; } if (!pActor->IsPlayer() || pActor->IsClient() || gEnv->bMultiplayer) { bool hasAccessory = pInventory->HasAccessory(GetEntity()->GetClass()); bool hasAccessoryForThisWeapon = pInventory->HasAccessory(GetEntity()->GetClass()); if (!hasAccessoryForThisWeapon) pInventory->AddAccessory(GetEntity()->GetClass()); if (!hasAccessory) ProcessAccessoryAmmoCapacities(pInventory, true); if (!hasAccessoryForThisWeapon) ProcessAccessoryAmmo(pInventory); } OnPickedUp(pickerId, m_sharedparams->params.unique); if (select) { PlayAction(GetFragmentIds().pickedup); } EnableSound(soundEnabled); bool isLocalEntity = GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY) ? true : false; if (IsServer() && !IsDemoPlayback()) { if(!gEnv->bMultiplayer || isLocalEntity) RemoveEntity(); else if(g_pGame->GetGameRules()) g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg } if (IsServer()) { GetGameObject()->SetNetworkParent(pickerId); if (!isLocalEntity) { pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId()); } } }
//------------------------------------------------------------------------ tSoundID CItem::PlayAction(const ItemString &actionName, int layer, bool loop, uint32 flags, float speedOverride) { if(!m_enableAnimations || !IsOwnerInGame()) return (tSoundID)-1; TActionMap::iterator it = m_sharedparams->actions.find(CONST_TEMPITEM_STRING(actionName)); if(it == m_sharedparams->actions.end()) { // GameWarning("Action '%s' not found on item '%s'!", actionName, GetEntity()->GetName()); for(int i=0; i<eIGS_Last; i++) { m_animationTime[i]=0; m_animationSpeed[i]=1.0f; m_animationEnd[i]=0; } return 0; } bool fp = m_stats.fp; if(m_parentId) { CItem *pParent=static_cast<CItem *>(m_pItemSystem->GetItem(m_parentId)); if(pParent) fp=pParent->GetStats().fp; } if(flags&eIPAF_ForceFirstPerson) fp = true; if(flags&eIPAF_ForceThirdPerson) fp = false; int sid=fp?eIGS_FirstPerson:eIGS_ThirdPerson; SAction &action = it->second; tSoundID result = INVALID_SOUNDID; if((flags&eIPAF_Sound) && !action.sound[sid].name.empty() && IsSoundEnabled() && g_pGameCVars->i_soundeffects) { int nSoundFlags = FLAG_SOUND_DEFAULT_3D; nSoundFlags |= flags&eIPAF_SoundStartPaused?FLAG_SOUND_START_PAUSED:0; IEntitySoundProxy *pSoundProxy = GetSoundProxy(true); //GetSound proxy from dualwield master if neccesary if(IsDualWieldSlave()) { CItem *pMaster = static_cast<CItem *>(GetDualWieldMaster()); if(pMaster) { pSoundProxy = pMaster->GetSoundProxy(true); } } EntityId pSkipEnts[3]; int nSkipEnts = 0; // TODO for Marcio :) // check code changes // Skip the Item pSkipEnts[nSkipEnts] = GetEntity()->GetId(); ++nSkipEnts; // Skip the Owner if(GetOwner()) { pSkipEnts[nSkipEnts] = GetOwner()->GetId(); ++nSkipEnts; } if(pSoundProxy) { TempResourceName name; FixResourceName(action.sound[sid].name, name, flags); //nSoundFlags = nSoundFlags | (fp?FLAG_SOUND_DEFAULT_3D|FLAG_SOUND_RELATIVE:FLAG_SOUND_DEFAULT_3D); Vec3 vOffset(0,0,0); if(fp) vOffset.x = 0.3f; // offset for first person weapon to the front if(!g_pGameCVars->i_staticfiresounds) { result = pSoundProxy->PlaySoundEx(name, vOffset, FORWARD_DIRECTION, nSoundFlags, 1.0f, 0, 0, eSoundSemantic_Weapon, pSkipEnts, nSkipEnts); ISound *pSound = pSoundProxy->GetSound(result); if(pSound && action.sound[sid].sphere>0.0f) pSound->SetSphereSpec(action.sound[sid].sphere); } else { SInstanceAudio *pInstanceAudio=0; if(action.sound[sid].isstatic) { TInstanceActionMap::iterator iit = m_instanceActions.find(CONST_TEMPITEM_STRING(actionName)); if(iit == m_instanceActions.end()) { std::pair<TInstanceActionMap::iterator, bool> insertion=m_instanceActions.insert(TInstanceActionMap::value_type(actionName, SInstanceAction())); pInstanceAudio=&insertion.first->second.sound[sid]; } else pInstanceAudio=&iit->second.sound[sid]; } if(pInstanceAudio && (pInstanceAudio->id != INVALID_SOUNDID) && (name != pInstanceAudio->static_name)) ReleaseStaticSound(pInstanceAudio); if(!pInstanceAudio || pInstanceAudio->id == INVALID_SOUNDID) { result = pSoundProxy->PlaySoundEx(name, vOffset, FORWARD_DIRECTION, nSoundFlags, 1.0f, 0, 0, eSoundSemantic_Weapon, pSkipEnts, nSkipEnts); ISound *pSound = pSoundProxy->GetSound(result); if(pSound && action.sound[sid].sphere>0.0f) pSound->SetSphereSpec(action.sound[sid].sphere); } if(action.sound[sid].isstatic) { if(pInstanceAudio->id == INVALID_SOUNDID) { if(pSoundProxy->SetStaticSound(result, true)) { pInstanceAudio->id = result; pInstanceAudio->static_name = name; pInstanceAudio->synch = action.sound[sid].issynched; } } else { ISound *pSound = pSoundProxy->GetSound(pInstanceAudio->id); if(pSound) pSound->Play(1.0, true, true, pSoundProxy); } } } if(gEnv->pAISystem && action.sound[sid].airadius > 0.0f) { EntityId ownerId = GetOwner() ? GetOwner()->GetId() : 0; // associate sound event with vehicle if the shooter is in a vehicle (tank cannon shot, etc) if(CActor *pOwnerActor = GetOwnerActor()) { IVehicle *pOwnerVehicle = pOwnerActor->GetLinkedVehicle(); if(pOwnerVehicle && pOwnerVehicle->GetEntityId()) ownerId = pOwnerVehicle->GetEntityId(); } SAIStimulus stim(AISTIM_SOUND, AISOUND_WEAPON, ownerId?ownerId:GetEntityId() , 0, GetEntity()->GetWorldPos(), ZERO, action.sound[sid].airadius); gEnv->pAISystem->RegisterStimulus(stim); } } } if(flags&eIPAF_Animation) { TempResourceName name; // generate random number only once per call to allow animations to // match across geometry slots (like first person and third person) float randomNumber = Random(); for(int i=0; i<eIGS_Last; i++) { if(!(flags&(1<<i))) continue; int nanimations=action.animation[i].size(); if(nanimations <= 0) continue; int anim = int(randomNumber * float(nanimations)); if(action.animation[i][anim].name.empty()) continue; FixResourceName(action.animation[i][anim].name, name, flags); if((i == eIGS_Owner) || (i == eIGS_OwnerLooped)) { if(!action.animation[i][anim].name.empty()) { bool looping=(eIGS_OwnerLooped==i); CActor *pOwner = GetOwnerActor(); if(pOwner) { if(IsDualWield() && !m_sharedparams->params.dual_wield_pose.empty()) pOwner->PlayAction(name, m_sharedparams->params.dual_wield_pose.c_str(), looping); else pOwner->PlayAction(name, m_sharedparams->params.pose.c_str(), looping); } } continue; } else if(i == eIGS_OffHand) { if(!action.animation[eIGS_OffHand][anim].name.empty()) { CActor *pOwner = GetOwnerActor(); if(pOwner) { CItem *pOffHand = pOwner->GetItemByClass(CItem::sOffHandClass); if(pOffHand && pOffHand!=this) { uint32 ohflags=eIPAF_Default; if(action.animation[eIGS_OffHand][anim].blend==0.0f) ohflags|=eIPAF_NoBlend; pOffHand->PlayAction(action.animation[eIGS_OffHand][anim].name, 0, false, ohflags); } } } continue; } SAnimation &animation=action.animation[i][anim]; if(!animation.name.empty()) { float blend = animation.blend; if(flags&eIPAF_NoBlend) blend = 0.0f; if(speedOverride > 0.0f) PlayAnimationEx(name, i, layer, loop, blend, speedOverride, flags); else PlayAnimationEx(name, i, layer, loop, blend, animation.speed, flags); } if((m_stats.fp || m_stats.viewmode&eIVM_FirstPerson) && i==eIGS_FirstPerson && !animation.camera_helper.empty()) { m_camerastats.animating=true; m_camerastats.helper=animation.camera_helper; m_camerastats.position=animation.camera_pos; m_camerastats.rotation=animation.camera_rot; m_camerastats.follow=animation.camera_follow; m_camerastats.reorient=animation.camera_reorient; } else if(m_camerastats.animating) m_camerastats=SCameraAnimationStats(); } } if(flags&eIPAF_Effect && !action.effect[sid].name.empty()) { // change this to attach, if needed SpawnEffect(sid, action.effect[sid].name.c_str(), action.effect[sid].helper.c_str()); } if(action.children) { for(TAccessoryMap::iterator ait=m_accessories.begin(); ait!=m_accessories.end(); ait++) { EntityId aId=(EntityId)ait->second; CItem *pAccessory=static_cast<CItem *>(m_pItemSystem->GetItem(aId)); if(pAccessory) pAccessory->PlayAction(actionName, layer, loop, flags, speedOverride); } } return result; }
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char *setup) { CActor *pActor=GetActor(pickerId); if (!pActor) return; if(!CheckAmmoRestrictions(pickerId)) { if (IsServer()) g_pGame->GetGameRules()->SendTextMessage(eTextMessageCenter, "@ammo_maxed_out", eRMI_ToClientChannel, pActor->GetChannelId(), (string("@")+GetEntity()->GetClass()->GetName()).c_str()); return; } TriggerRespawn(); GetEntity()->EnablePhysics(false); Physicalize(false, false); bool soundEnabled = IsSoundEnabled(); EnableSound(sound); SetViewMode(0); SetOwnerId(pickerId); CopyRenderFlags(GetOwner()); Hide(true); m_stats.dropped = false; m_stats.brandnew = false; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) { GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName()); return; } if(!pInventory->HasAccessory(GetEntity()->GetClass())) { pInventory->AddAccessory(GetEntity()->GetClass()); } OnPickedUp(pickerId, m_sharedparams->params.unique); PlayAction(g_pItemStrings->pickedup); EnableSound(soundEnabled); if (IsServer() && !IsDemoPlayback()) { if(!gEnv->bMultiplayer) RemoveEntity(); else if(g_pGame->GetGameRules()) g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg } if (IsServer()) { GetGameObject()->SetNetworkParent(pickerId); if ((GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY)) == 0) { pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId()); const char *displayName=GetDisplayName(); } } }