Skip to content

Commit

Permalink
Added Research.
Browse files Browse the repository at this point in the history
  • Loading branch information
JBurlison committed Sep 24, 2017
1 parent 2bf0452 commit 12e74c5
Show file tree
Hide file tree
Showing 21 changed files with 1,137 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public interface ISpawnSettlerEvaluator
{
string Name { get; }

double SpawnChance(Players.Player p, Colony c, PlayerState state);
float SpawnChance(Players.Player p, Colony c, PlayerState state);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@

namespace Pandaros.Settlers.Chance
{
public class SettelerEvaluation : ISpawnSettlerEvaluator
public class SettlerEvaluation : ISpawnSettlerEvaluator
{
public string Name => "SettelerEvaluation";
public string Name => "SettlerEvaluation";

public double SpawnChance(Players.Player p, Colony c, PlayerState state)
public float SpawnChance(Players.Player p, Colony c, PlayerState state)
{
double chance = .5;
float chance = .3f;
var remainingBeds = BedBlockTracker.GetCount(p) - state.ColonistCount;

if (remainingBeds < 1)
chance -= 0.1;
chance -= 0.1f;

if (remainingBeds >= state.MaxPerSpawn)
chance += 0.1;
chance += 0.1f;

var hoursofFood = Stockpile.GetStockPile(p).TotalFood / c.FoodUsePerHour;

if (hoursofFood < 48)
chance -= 0.4;
chance -= 0.4f;
else
chance += 0.2;
chance += 0.2f;

if (JobTracker.GetCount(p) > state.MaxPerSpawn)
chance += .4;
if (JobTracker.GetCount(p) > SettlerManager.MIN_PERSPAWN)
chance += .4f;
else
chance -= .2;
chance -= .2f;

if (state.Difficulty != GameDifficulty.Easy)
if (c.InSiegeMode ||
c.LastSiegeModeSpawn != 0 &&
Pipliz.Time.SecondsSinceStartDouble - c.LastSiegeModeSpawn > TimeSpan.FromMinutes(5).TotalSeconds)
chance -= 0.4;
chance -= 0.4f;

return chance;
}
Expand Down
4 changes: 2 additions & 2 deletions Pandaros.Settlers/Pandaros.Settlers/Entities/ColonyState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public int MaxPerSpawn
{
var max = SettlerManager.MIN_PERSPAWN;

if (ColonistCount > SettlerManager.MAX_BUYABLE)
if (ColonistCount >= SettlerManager.MAX_BUYABLE)
{
var maxAdd = (int)Math.Ceiling(ColonistCount / (decimal)10);

if (maxAdd > SettlerManager.ABSOLUTE_MAX_PERSPAWN)
maxAdd = SettlerManager.ABSOLUTE_MAX_PERSPAWN;

max += Rand.Next(0, maxAdd);
max += Rand.Next(0 + ColonyInterface.Colony.Owner.GetTemporaryValue<int>(Research.MinSettlers.TEMP_VAL_KEY), maxAdd + ColonyInterface.Colony.Owner.GetTemporaryValue<int>(Research.MaxSettlers.TEMP_VAL_KEY));
}

return max;
Expand Down
124 changes: 124 additions & 0 deletions Pandaros.Settlers/Pandaros.Settlers/GameLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using Pipliz.JSON;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Pandaros.Settlers
{
[ModLoader.ModManager]
public static class GameLoader
{
public static string ICON_FOLDER_PANDA_REL = @"..\..\mods\Pandaros\settlers\icons";
public static string LOCALIZATION_FOLDER_PANDA = @"gamedata\mods\Pandaros\settlers\localization";
public static string MOD_FOLDER = @"gamedata\mods\Pandaros";

public const string NAMESPACE = "Pandaros.Settlers";

[ModLoader.ModCallback(ModLoader.EModCallbackType.OnAssemblyLoaded, "Pandaros.Settlers.OnAssemblyLoaded")]
public static void OnAssemblyLoaded(string path)
{
MOD_FOLDER = Path.GetDirectoryName(path);
PandaLogger.Log(string.Format("Found mod in {0}", MOD_FOLDER));
LOCALIZATION_FOLDER_PANDA = Path.Combine(MOD_FOLDER, "localization");
Localize();
}

public static void Localize()
{
PandaLogger.Log(string.Format("Localization directory: {0}", LOCALIZATION_FOLDER_PANDA));
try
{
string[] array = new string[]
{
"types.json",
"typeuses.json",
"localization.json"
};
for (int i = 0; i < array.Length; i++)
{
string text = array[i];
string[] files = Directory.GetFiles(LOCALIZATION_FOLDER_PANDA, text, SearchOption.AllDirectories);
string[] array2 = files;
for (int j = 0; j < array2.Length; j++)
{
string text2 = array2[j];
try
{
JSONNode jsonFromMod;
if (JSON.Deserialize(text2, out jsonFromMod, false))
{
string name = Directory.GetParent(text2).Name;
PandaLogger.Log(string.Format("Found mod localization file for '{0}' localization", name));
localize(name, text, jsonFromMod);
}
}
catch (Exception ex)
{
PandaLogger.Log(string.Format("Exception reading localization from {0}; {1}", text2, ex.Message));
}
}
}
}
catch (DirectoryNotFoundException)
{
PandaLogger.Log(string.Format("Localization directory not found at {0}", LOCALIZATION_FOLDER_PANDA));
}
}

public static void localize(string locName, string locFilename, JSONNode jsonFromMod)
{
try
{
string text = CombinePaths(new string[]
{
"gamedata",
"localization",
locName,
locFilename
});

JSONNode jSONNode;

if (JSON.Deserialize(text, out jSONNode, false))
{
foreach (KeyValuePair<string, JSONNode> modNode in jsonFromMod.LoopObject())
{
PandaLogger.Log(string.Format("localization '{0}' added to '{1}'. This will apply AFTER next restart!!!", modNode.Key, Path.Combine(locName, locFilename)));
jSONNode[modNode.Key] = modNode.Value;
}

JSON.Serialize(text, jSONNode, 2);
PandaLogger.Log(string.Format("Patched mod localization file '{0}/{1}' into '{2}'", locName, locFilename, text));
}
else
{
PandaLogger.Log(string.Format("Could not deserialize json from '{0}'", text));
}
}
catch (Exception ex)
{
PandaLogger.LogError(string.Format("Exception while localizing {0}", Path.Combine(locName, locFilename)), ex);
}
}

public static string CombinePaths(params string[] pathParts)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < pathParts.Length; i++)
{
string text = pathParts[i];
stringBuilder.Append(text.TrimEnd(new char[]
{
'/',
'\\'
})).Append(Path.DirectorySeparatorChar);
}
return stringBuilder.ToString().TrimEnd(new char[]
{
Path.DirectorySeparatorChar
});
}
}
}
2 changes: 1 addition & 1 deletion Pandaros.Settlers/Pandaros.Settlers/PandaLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Pandaros.Settlers
{
internal class PandaLogger
{
internal static void Log(string message, ChatColor color, params object[] args)
internal static void Log(ChatColor color, string message, params object[] args)
{
ServerLog.LogAsyncMessage(new Pipliz.LogMessage(PandaChat.BuildMessage(GetFormattedMessage(string.Format(message, args)), color), UnityEngine.LogType.Log));
}
Expand Down
26 changes: 25 additions & 1 deletion Pandaros.Settlers/Pandaros.Settlers/Pandaros.Settlers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,26 @@
<Compile Include="Entities\ColonyState.cs" />
<Compile Include="Chance\ISpawnSettlerChance.cs" />
<Compile Include="GameDifficulty.cs" />
<Compile Include="GameLoader.cs" />
<Compile Include="PandaChat.cs" />
<Compile Include="PandaLogger.cs" />
<Compile Include="Research\ColonyBuiltIn.cs" />
<Compile Include="Research\MinSettlers.cs" />
<Compile Include="Research\MaxSettlers.cs" />
<Compile Include="Research\TimeBetween.cs" />
<Compile Include="Research\ReducedWaste.cs" />
<Compile Include="Research\SettlerChance.cs" />
<Compile Include="SaveManager.cs" />
<Compile Include="Chance\SettelerEvaluation.cs" />
<Compile Include="Chance\SettlerEvaluation.cs" />
<Compile Include="SettlerReasoning.cs" />
<Compile Include="SettlerManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SerializableDictionary.cs" />
</ItemGroup>
<ItemGroup>
<None Include="localization\en-US\localization.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="modinfo.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -207,6 +216,21 @@
<Content Include="icons\SkilledLaborer5.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\TimeBetween1.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\TimeBetween2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\TimeBetween3.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\TimeBetween4.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\TimeBetween5.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Pandaros.Settlers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("A Colony Survival mod")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Pandaros.Settlers")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyCopyright("Copyright © 2017 Jim Burlison")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
23 changes: 23 additions & 0 deletions Pandaros.Settlers/Pandaros.Settlers/Research/ColonyBuiltIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pandaros.Settlers.Research
{
public static class ColonyBuiltIn
{
public const string healthsize1 = "pipliz.baseresearch.healthsize1";
public const string healthsize2 = "pipliz.baseresearch.healthsize2";
public const string healthsize3 = "pipliz.baseresearch.healthsize3";
public const string healthsize4 = "pipliz.baseresearch.healthsize4";
public const string healthregensize1 = "pipliz.baseresearch.healthregensize1";
public const string healthregensize2 = "pipliz.baseresearch.healthregensize2";
public const string healthregensize3 = "pipliz.baseresearch.healthregensize3";
public const string healthregensize4 = "pipliz.baseresearch.healthregensize4";
public const string healthregenspeed1 = "pipliz.baseresearch.healthregenspeed1";
public const string healthregenspeed2 = "pipliz.baseresearch.healthregenspeed2";
public const string healthregenspeed3 = "pipliz.baseresearch.healthregenspeed3";
public const string healthregenspeed4 = "pipliz.baseresearch.healthregenspeed4";
}
}
Loading

0 comments on commit 12e74c5

Please sign in to comment.