Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Returns false if multiple fogs are already in the map,
- in which case we won't bother messing with fogs.
- */
- bool:InitFogs()
- {
- new iEnt;
- new bool:bFoundMaster = false; // Does a master fog exist?
- new bool:bFoundCustom = false; // Does a custom fog exist?
- new iExtraFogs = 0; // How many miscellaneous fogs have been found. First one is set to master, usually.
- DOWHILE_ENTFOUND(iEnt, "env_fog_controller") // m_spawnflags
- {
- decl String:sFog[MAX_TARGETNAME];
- GetEntPropString(iEnt, Prop_Data, "m_iName", sFog, sizeof(sFog));
- new iSpawnFlags = GetEntProp(iEnt, Prop_Data, "m_spawnflags");
- // If the plugin had to be reloaded, this helps avoid creating extraneous fogs
- if (iSpawnFlags & 1)
- {
- #if defined DEBUG
- LogMessage("Found existing master %s: %i", sFog, iEnt);
- if (g_bDebugOn) CPrintToChdata("Found existing master %s: %i", sFog, iEnt);
- #endif
- strcopy(g_sMasterFog, sizeof(g_sMasterFog), sFog);
- if (g_sMasterFog[0] == 0)
- {
- DispatchKeyValue(iEnt, "targetname", "fog_master");
- strcopy(g_sMasterFog, sizeof(g_sMasterFog), "fog_master");
- }
- bFoundMaster = true;
- continue;
- }
- else if (StrEqual(sFog, "fog_data"))
- {
- #if defined DEBUG
- LogMessage("Found existing custom %s: %i", sFog, iEnt);
- if (g_bDebugOn) CPrintToChdata("Found existing custom %s: %i", sFog, iEnt);
- #endif
- g_iCustomFogEntRef = EntIndexToEntRef(iEnt);
- bFoundCustom = true;
- continue;
- }
- #if defined DEBUG
- LogMessage("Found miscellaneous %s: %i #%i", sFog, iEnt, iExtraFogs+1); // Report any other fogs we find
- if (g_bDebugOn) CPrintToChdata("Found miscellaneous %s: %i #%i", sFog, iEnt, iExtraFogs+1);
- #endif
- if (++iExtraFogs > 1) // The first unmarked fog will become the master, so it's safe to continue
- {
- return false; // Stop the process
- }
- // This assumes that the first fog we touch will always be the one that was meant to be the master.
- // I don't know if this is accurate for custom maps.
- // This code is reached while a fog is found, but we haven't set our flag saying we found one
- if (!bFoundMaster)
- {
- strcopy(g_sMasterFog, sizeof(g_sMasterFog), sFog);
- if (g_sMasterFog[0] == EOS) // If it had no name...
- {
- DispatchKeyValue(iEnt, "targetname", "fog_master");
- strcopy(g_sMasterFog, sizeof(g_sMasterFog), "fog_master");
- }
- #if defined DEBUG
- LogMessage("Setting new master %s: %i", g_sMasterFog, iEnt);
- if (g_bDebugOn) CPrintToChdata("Setting new master %s: %i", g_sMasterFog, iEnt);
- #endif
- decl String:sSpawnFlags[8];
- IntToString((iSpawnFlags|1), sSpawnFlags, sizeof(sSpawnFlags));
- DispatchKeyValue(iEnt, "spawnflags", sSpawnFlags); // If there's already a fog controller, set it to master
- bFoundMaster = true;
- }
- }
- // End DOWHILE
- // If there was no fog at all in the map, this is ran to create a master fog
- if (!bFoundMaster)
- {
- iEnt = CreateEntityByName("env_fog_controller");
- DispatchSpawn(iEnt);
- DispatchKeyValue(iEnt, "spawnflags", "1"); // Set new fog to master
- DispatchKeyValue(iEnt, "fogenable", "0"); // The map originally had no fog, so keep this one disabled
- DispatchKeyValue(iEnt, "targetname", "fog_master");
- strcopy(g_sMasterFog, sizeof(g_sMasterFog), "fog_master");
- #if defined DEBUG
- LogMessage("Created new master %s: %i", g_sMasterFog, iEnt);
- if (g_bDebugOn) CPrintToChdata("Created new master %s: %i", g_sMasterFog, iEnt);
- #endif
- }
- if (!bFoundCustom) // If we haven't created a custom fog yet... (OnMapStart is re-ran if the plugin is reloaded/loaded midgame)
- {
- iEnt = CreateEntityByName("env_fog_controller"); // Make a second fog with custom effects for this mod
- DispatchSpawn(iEnt);
- DispatchKeyValue(iEnt, "spawnflags", "0"); // Fog is not master
- DispatchKeyValue(iEnt, "fogenable", "1"); // Enable this fog
- DispatchKeyValue(iEnt, "targetname", "fog_data"); // Important, so we can switch clients to this fog later
- DispatchKeyValue(iEnt, "fogmaxdensity", "1");
- //DispatchKeyValue(iEnt, "fogstart", "0");
- //DispatchKeyValue(iEnt, "fogend", "300"); // How far away you can see 350
- DispatchKeyValue(iEnt, "fogdir", "1 0 0");
- //DispatchKeyValue(iEnt, "fogcolor", "2 2 6");
- //DispatchKeyValue(iEnt, "fogcolor2", "6 2 2");
- DispatchKeyValue(iEnt, "fogblend", "1"); // Should turn out to be a dark fog
- DispatchKeyValue(iEnt, "farz", "-1"); // 2016 commented these because we control it dynamically now.
- DispatchKeyValue(iEnt, "use_angles", "1");
- DispatchKeyValue(iEnt, "angles", "0 270 0");
- g_iCustomFogEntRef = EntIndexToEntRef(iEnt);
- #if defined DEBUG
- LogMessage("Created new custom fog_data: %i", iEnt);
- if (g_bDebugOn) CPrintToChdata("Created new custom fog_data: %i", iEnt);
- #endif
- }
- /*g_iSkyCameraEntref = -1;
- DOWHILE_ENTFOUND(iEnt, "sky_camera")
- {
- g_iSkyCameraEntref = EntIndexToEntRef(iEnt); // There should only be one in any map. I assume all maps have one???
- g_iSkyFogEnable = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.enable");
- g_iSkyFogBlend = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.blend");
- g_iSkyFogColor[0] = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.colorPrimary");
- g_iSkyFogColor2[0] = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.colorSecondary");
- g_flSkyFogStart = GetEntPropFloat(iEnt, Prop_Data, "m_skyboxData.fog.start");
- g_flSkyFogEnd = GetEntPropFloat(iEnt, Prop_Data, "m_skyboxData.fog.end");
- g_flSkyFogMaxDensity = GetEntPropFloat(iEnt, Prop_Data, "m_skyboxData.fog.maxdensity");
- }*/
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement