Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.30 KB | None | 0 0
  1. /*
  2. Returns false if multiple fogs are already in the map,
  3. in which case we won't bother messing with fogs.
  4.  
  5. */
  6. bool:InitFogs()
  7. {
  8.     new iEnt;
  9.     new bool:bFoundMaster = false;     // Does a master fog exist?
  10.     new bool:bFoundCustom = false;     // Does a custom fog exist?
  11.     new iExtraFogs = 0;                // How many miscellaneous fogs have been found. First one is set to master, usually.
  12.  
  13.     DOWHILE_ENTFOUND(iEnt, "env_fog_controller")            // m_spawnflags
  14.     {
  15.         decl String:sFog[MAX_TARGETNAME];
  16.         GetEntPropString(iEnt, Prop_Data, "m_iName", sFog, sizeof(sFog));
  17.  
  18.         new iSpawnFlags = GetEntProp(iEnt, Prop_Data, "m_spawnflags");
  19.  
  20.         // If the plugin had to be reloaded, this helps avoid creating extraneous fogs
  21.         if (iSpawnFlags & 1)
  22.         {
  23. #if defined DEBUG
  24.             LogMessage("Found existing master %s: %i", sFog, iEnt);
  25.             if (g_bDebugOn) CPrintToChdata("Found existing master %s: %i", sFog, iEnt);
  26. #endif
  27.             strcopy(g_sMasterFog, sizeof(g_sMasterFog), sFog);
  28.  
  29.             if (g_sMasterFog[0] == 0)
  30.             {
  31.                 DispatchKeyValue(iEnt, "targetname", "fog_master");
  32.                 strcopy(g_sMasterFog, sizeof(g_sMasterFog), "fog_master");
  33.             }
  34.  
  35.             bFoundMaster = true;
  36.             continue;
  37.         }
  38.         else if (StrEqual(sFog, "fog_data"))
  39.         {
  40. #if defined DEBUG
  41.             LogMessage("Found existing custom %s: %i", sFog, iEnt);
  42.             if (g_bDebugOn) CPrintToChdata("Found existing custom %s: %i", sFog, iEnt);
  43. #endif
  44.             g_iCustomFogEntRef = EntIndexToEntRef(iEnt);
  45.             bFoundCustom = true;
  46.             continue;
  47.         }
  48.  
  49. #if defined DEBUG
  50.         LogMessage("Found miscellaneous %s: %i #%i", sFog, iEnt, iExtraFogs+1);       // Report any other fogs we find
  51.         if (g_bDebugOn) CPrintToChdata("Found miscellaneous %s: %i #%i", sFog, iEnt, iExtraFogs+1);
  52. #endif
  53.  
  54.         if (++iExtraFogs > 1)   // The first unmarked fog will become the master, so it's safe to continue
  55.         {
  56.             return false;       // Stop the process
  57.         }
  58.  
  59.         // This assumes that the first fog we touch will always be the one that was meant to be the master.
  60.         // I don't know if this is accurate for custom maps.
  61.         // This code is reached while a fog is found, but we haven't set our flag saying we found one
  62.         if (!bFoundMaster)
  63.         {
  64.             strcopy(g_sMasterFog, sizeof(g_sMasterFog), sFog);
  65.  
  66.             if (g_sMasterFog[0] == EOS)                               // If it had no name...
  67.             {
  68.                 DispatchKeyValue(iEnt, "targetname", "fog_master");
  69.                 strcopy(g_sMasterFog, sizeof(g_sMasterFog), "fog_master");
  70.             }
  71.  
  72. #if defined DEBUG
  73.             LogMessage("Setting new master %s: %i", g_sMasterFog, iEnt);
  74.             if (g_bDebugOn) CPrintToChdata("Setting new master %s: %i", g_sMasterFog, iEnt);
  75. #endif
  76.  
  77.             decl String:sSpawnFlags[8];
  78.  
  79.             IntToString((iSpawnFlags|1), sSpawnFlags, sizeof(sSpawnFlags));
  80.  
  81.             DispatchKeyValue(iEnt, "spawnflags", sSpawnFlags);   // If there's already a fog controller, set it to master
  82.  
  83.             bFoundMaster = true;
  84.         }
  85.     }
  86.  
  87.     // End DOWHILE
  88.  
  89.     // If there was no fog at all in the map, this is ran to create a master fog
  90.     if (!bFoundMaster)
  91.     {
  92.         iEnt = CreateEntityByName("env_fog_controller");
  93.         DispatchSpawn(iEnt);
  94.  
  95.         DispatchKeyValue(iEnt, "spawnflags", "1");          // Set new fog to master
  96.         DispatchKeyValue(iEnt, "fogenable", "0");           // The map originally had no fog, so keep this one disabled
  97.         DispatchKeyValue(iEnt, "targetname", "fog_master");
  98.         strcopy(g_sMasterFog, sizeof(g_sMasterFog), "fog_master");
  99.  
  100. #if defined DEBUG
  101.         LogMessage("Created new master %s: %i", g_sMasterFog, iEnt);
  102.         if (g_bDebugOn) CPrintToChdata("Created new master %s: %i", g_sMasterFog, iEnt);
  103. #endif
  104.     }
  105.  
  106.     if (!bFoundCustom)   // If we haven't created a custom fog yet...  (OnMapStart is re-ran if the plugin is reloaded/loaded midgame)
  107.     {
  108.         iEnt = CreateEntityByName("env_fog_controller");        // Make a second fog with custom effects for this mod
  109.         DispatchSpawn(iEnt);
  110.  
  111.         DispatchKeyValue(iEnt, "spawnflags", "0");              // Fog is not master
  112.         DispatchKeyValue(iEnt, "fogenable", "1");               // Enable this fog
  113.         DispatchKeyValue(iEnt, "targetname", "fog_data");       // Important, so we can switch clients to this fog later
  114.  
  115.         DispatchKeyValue(iEnt, "fogmaxdensity", "1");
  116.         //DispatchKeyValue(iEnt, "fogstart", "0");
  117.         //DispatchKeyValue(iEnt, "fogend", "300");                // How far away you can see 350
  118.         DispatchKeyValue(iEnt, "fogdir", "1 0 0");
  119.         //DispatchKeyValue(iEnt, "fogcolor", "2 2 6");
  120.         //DispatchKeyValue(iEnt, "fogcolor2", "6 2 2");
  121.         DispatchKeyValue(iEnt, "fogblend", "1");                // Should turn out to be a dark fog
  122.         DispatchKeyValue(iEnt, "farz", "-1");                   // 2016 commented these because we control it dynamically now.
  123.         DispatchKeyValue(iEnt, "use_angles", "1");
  124.         DispatchKeyValue(iEnt, "angles", "0 270 0");
  125.  
  126.         g_iCustomFogEntRef = EntIndexToEntRef(iEnt);
  127.  
  128. #if defined DEBUG
  129.         LogMessage("Created new custom fog_data: %i", iEnt);
  130.         if (g_bDebugOn) CPrintToChdata("Created new custom fog_data: %i", iEnt);
  131. #endif
  132.     }
  133.  
  134.     /*g_iSkyCameraEntref = -1;
  135.     DOWHILE_ENTFOUND(iEnt, "sky_camera")
  136.     {
  137.         g_iSkyCameraEntref = EntIndexToEntRef(iEnt); // There should only be one in any map. I assume all maps have one???
  138.         g_iSkyFogEnable = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.enable");
  139.         g_iSkyFogBlend = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.blend");
  140.         g_iSkyFogColor[0] = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.colorPrimary");
  141.         g_iSkyFogColor2[0] = GetEntProp(iEnt, Prop_Data, "m_skyboxData.fog.colorSecondary");
  142.         g_flSkyFogStart = GetEntPropFloat(iEnt, Prop_Data, "m_skyboxData.fog.start");
  143.         g_flSkyFogEnd = GetEntPropFloat(iEnt, Prop_Data, "m_skyboxData.fog.end");
  144.         g_flSkyFogMaxDensity = GetEntPropFloat(iEnt, Prop_Data, "m_skyboxData.fog.maxdensity");
  145.     }*/
  146.  
  147.     return true;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement