Skip to content

Commit

Permalink
lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Nov 5, 2023
1 parent ad18d14 commit 7a8e192
Show file tree
Hide file tree
Showing 39 changed files with 692 additions and 385 deletions.
Binary file modified Assemblies/ZombieLand.dll
Binary file not shown.
20 changes: 9 additions & 11 deletions Defs/Zombie_Hediffs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
</HediffDef>

<HediffDef ParentName="DiseaseBase">
<defName>Contamination</defName>
<defName>ContaminationEffect</defName>
<label>contamination</label>
<labelNoun>contamination</labelNoun>
<description>Zombie contamination in the brain and mind. Caused by touching and being exposed by contaminated things and places. This effect is terminal and does not wear off.</description>
<description>Zombie contamination in the brain and mind. Caused by touching and being exposed by contaminated things and places. It will increasingly affect overall effectiveness and will cause strange side effects. At 100% death will occur.</description>
<descriptionShort>Zombie contamination in the brain and mind.</descriptionShort>
<hediffClass>ZombieLand.Hediff_Contamination</hediffClass>
<defaultLabelColor>(0,0.75,0)</defaultLabelColor>
Expand All @@ -66,7 +66,7 @@
<capMods>
<li>
<capacity>Consciousness</capacity>
<offset>-0.05</offset>
<offset>-0.01</offset>
</li>
<li>
<capacity>Metabolism</capacity>
Expand All @@ -89,7 +89,7 @@
<capMods>
<li>
<capacity>Consciousness</capacity>
<offset>-0.1</offset>
<offset>-0.025</offset>
</li>
<li>
<capacity>Metabolism</capacity>
Expand All @@ -113,7 +113,7 @@
<capMods>
<li>
<capacity>Consciousness</capacity>
<offset>-0.15</offset>
<offset>-0.05</offset>
</li>
<li>
<capacity>Metabolism</capacity>
Expand Down Expand Up @@ -142,7 +142,7 @@
<capMods>
<li>
<capacity>Consciousness</capacity>
<offset>-0.2</offset>
<offset>-0.1</offset>
</li>
<li>
<capacity>Metabolism</capacity>
Expand Down Expand Up @@ -176,7 +176,7 @@
<capMods>
<li>
<capacity>Consciousness</capacity>
<offset>-0.3</offset>
<offset>-0.2</offset>
</li>
<li>
<capacity>Metabolism</capacity>
Expand Down Expand Up @@ -209,7 +209,7 @@
<capMods>
<li>
<capacity>Consciousness</capacity>
<offset>-0.5</offset>
<offset>-0.3</offset>
</li>
<li>
<capacity>Metabolism</capacity>
Expand All @@ -233,7 +233,7 @@
</statOffsets>
</li>
<li>
<minSeverity>0.9999</minSeverity>
<minSeverity>1</minSeverity>
<label>deadly</label>
<lifeThreatening>true</lifeThreatening>
<capMods>
Expand All @@ -246,8 +246,6 @@
<offset>-1</offset>
</li>
</capMods>
<deathMtbDays>0.0000000001</deathMtbDays>
<totalBleedFactor>10000</totalBleedFactor>
</li>
</stages>
</HediffDef>
Expand Down
7 changes: 7 additions & 0 deletions Defs/Zombie_Jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<allowOpportunisticPrefix>true</allowOpportunisticPrefix>
</JobDef>

<JobDef>
<defName>ContaminationJobForceRest</defName>
<driverClass>ZombieLand.JobDriver_ContaminationForceRest</driverClass>
<reportString>stopping for a while to rest.</reportString>
<suspendable>false</suspendable>
</JobDef>

<JobDef>
<defName>ContaminationJobHallucination</defName>
<driverClass>ZombieLand.JobDriver_ContaminationHallucination</driverClass>
Expand Down
15 changes: 15 additions & 0 deletions Defs/Zombie_MentalState.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>

<MentalStateDef>
<defName>ContaminationStateForceRest</defName>
<label>resting</label>
<stateClass>ZombieLand.MentalState_Contamination</stateClass>
<category>Misc</category>
<minTicksBeforeRecovery>99999999</minTicksBeforeRecovery>
<blockNormalThoughts>true</blockNormalThoughts>
<nameColor>(0.65, 0.9, 0.93)</nameColor>
<beginLetterLabel>resting</beginLetterLabel>
<beginLetter>{0} needs some rest.</beginLetter>
<beginLetterDef>NegativeEvent</beginLetterDef>
<recoveryMessage>{0} no longer needs resting.</recoveryMessage>
<baseInspectLine>Mental state: Resting</baseInspectLine>
</MentalStateDef>

<MentalStateDef>
<defName>ContaminationStateHallucination</defName>
<label>hallucinating</label>
Expand Down
2 changes: 1 addition & 1 deletion Defs/Zombie_Things.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<altitudeLayer>FloorEmplacement</altitudeLayer>
<pathCost>120</pathCost>
<pathCost>300</pathCost>
<pathCostIgnoreRepeat>false</pathCostIgnoreRepeat>
<useHitPoints>True</useHitPoints>
<size>(1,1)</size>
Expand Down
1 change: 1 addition & 0 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<ContaminationEnabled>Globally enabled</ContaminationEnabled>
<ZombielandRestartRequired>Changing this setting requires a restart of RimWorld</ZombielandRestartRequired>
<ZombielandContamination>Intensity</ZombielandContamination>
<ContaminationEffectiveness>Total effectiveness {0}%</ContaminationEffectiveness>

<WhenDoZombiesSpawn>When do zombies appear?</WhenDoZombiesSpawn>
<SpawnWhenType_AllTheTime>All the time</SpawnWhenType_AllTheTime>
Expand Down
31 changes: 4 additions & 27 deletions Source/Chainsaw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,49 +357,26 @@ void Slaughter(Pawn victim)
var head = victim?.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).FirstOrDefault((BodyPartRecord x) => x.def == BodyPartDefOf.Head);
if (head != null)
{
var mat = GetHead(victim);
var pos = victim.DrawPos;
pos.y = Altitudes.AltitudeFor(AltitudeLayer.MoteOverhead);
victim.Map?.GetComponent<TickManager>()?.victimHeads.Add(new VictimHead()
{
t = 0,
material = mat,
alpha = 1f,
position = pos,
quat = Quaternion.AngleAxis(victim.Rotation.AsAngle, Vector3.up),
rotAngle = Rand.Range(-10f, 10f)
});
victim.Map?.GetComponent<TickManager>()?.victimHeads.Add(new VictimHead(victim));

var part2 = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, victim, null);
part2.IsFresh = true;
part2.lastInjury = HediffDefOf.Shredded;
part2.Part = head;
victim.health.hediffSet.AddDirect(part2, null, null);
}

CustomDefs.Crush.PlayOneShot(SoundInfo.InMap(victim));
_ = FilthMaker.TryMakeFilth(victim.Position, victim.Map, ThingDefOf.Human.race.BloodDef, 4, FilthSourceFlags.None, true);
victim.Kill(null);

if (Damage(1))
return;

if (victim is not Zombie zombie)
Drop(victim.RaceProps.IsMechanoid);
else if (zombie.IsTanky)
Drop(true);
}

static Material GetHead(Pawn victim)
{
var renderTexture = RenderTexture.GetTemporary(128, 128, 32, RenderTextureFormat.ARGB32);
Find.PawnCacheRenderer.RenderPawn(victim, renderTexture, new Vector3(0, 0, 0.4f), 1.75f, 0f, Rot4.South, true, false, true, false, true, default, null, null, false);
Graphics.Blit(Constants.blood, renderTexture, MaterialPool.MatFrom(ShaderDatabase.Wound));
var texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false) { name = "Chainsaw Victim Head" };
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0f, 0f, renderTexture.width, renderTexture.height), 0, 0);
texture.Apply();
RenderTexture.active = null;
RenderTexture.ReleaseTemporary(renderTexture);

return MaterialPool.MatFrom(new MaterialRequest(texture, ShaderDatabase.Mote, Color.white));
}
}
}
49 changes: 40 additions & 9 deletions Source/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static Constants()
}
}
Save(settings);
Apply(settings);
if (Apply(settings))
Save(settings);
}

// grid debugging
Expand All @@ -95,8 +96,8 @@ static Constants()
public static int MAX_CELLS_FOR_DETAILED_CONTAMINATION = 6400;

// contamination
[Constant(1, "Contamination (0=off, 1=basic, 2=development)")]
public static int CONTAMINATION = 1;
[Constant(2, "Enable to play with contamination")]
public static bool CONTAMINATION = true;

// general debugging/testing
//
Expand Down Expand Up @@ -351,6 +352,15 @@ static Constants()
public static readonly Texture2D healthBarFrame = SolidColorMaterials.NewSolidColorTexture(Color.black);
public static readonly Color healthBarBG = new(1, 1, 1, 0.25f);

public static readonly Texture2D[] thingIconTextures = new[]
{
SolidColorMaterials.NewSolidColorTexture(new Color(0, 1, 0, 0f).ToTransparent(0.5f)),
SolidColorMaterials.NewSolidColorTexture(new Color(0, 1, 0, 0.25f).ToTransparent(0.5f)),
SolidColorMaterials.NewSolidColorTexture(new Color(0, 1, 0, 0.5f).ToTransparent(0.5f)),
SolidColorMaterials.NewSolidColorTexture(new Color(0, 1, 0, 0.75f).ToTransparent(0.5f)),
SolidColorMaterials.NewSolidColorTexture(new Color(0, 1, 0, 1f).ToTransparent(0.5f))
};

public static Texture2D zoneZombie = ContentFinder<Texture2D>.Get("ZoneZombie", true);
public static Texture2D blood = ContentFinder<Texture2D>.Get("Blood", true);

Expand Down Expand Up @@ -419,36 +429,57 @@ public static void Save(Dictionary<string, VersionedValue> dict)
var serializer = new JsonSerializer();
using var writer = new StreamWriter(SettingsFilePath);
using var jsonWriter = new JsonTextWriter(writer);
jsonWriter.Indentation = 1;
jsonWriter.IndentChar = '\t';
jsonWriter.Formatting = Formatting.Indented;
serializer.Serialize(jsonWriter, dict);
}

public static void Apply(Dictionary<string, VersionedValue> dict)
public static bool Apply(Dictionary<string, VersionedValue> dict)
{
var trv = Traverse.Create(typeof(Constants));
foreach (var info in dict)
var needsSave = false;
var keys = dict.Keys.ToList();
foreach (var key in keys)
{
var value = info.Value.value;
var field = trv.Field(key);
var info = dict[key];
var value = info.value;

var valueVersion = info.version;
var fieldVersion = AccessTools.Field(typeof(Constants), key).GetCustomAttribute<ConstantAttribute>().Version;
if (valueVersion != fieldVersion)
{
needsSave = true;
value = field.GetValue();
dict[key] = new VersionedValue() { version = fieldVersion, value = value };
continue;
}

if (value is double doubleValue)
value = (float)doubleValue;
if (value is long longValue)
value = (int)longValue;

if (value is JArray jArray)
{
var type = trv.Field(info.Key).GetValueType().GetElementType();
var type = field.GetValueType().GetElementType();
if (type == typeof(int))
value = jArray.Select(jToken => (int)jToken).ToArray();
if (type == typeof(float))
value = jArray.Select(jToken => (float)jToken).ToArray();
}

try
{
_ = trv.Field(info.Key).SetValue(value);
_ = field.SetValue(value);
}
catch (Exception ex)
{
Log.Error($"Ex: {info.Key}:{info.Value.value} => {ex.Message}");
Log.Error($"Ex: {key}:{info.value} => {ex.Message}");
}
}
return needsSave;
}
}
}
32 changes: 24 additions & 8 deletions Source/ContaminationEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public ContaminationRangeAttribute(float min, float max)
[DefOf]
public static class EffectDefs
{
public static MentalStateDef ContaminationStateForceRest;
public static MentalStateDef ContaminationStateHallucination;
public static MentalStateDef ContaminationStateSleepwalking;
public static MentalStateDef ContaminationStateHoarding;
public static MentalStateDef ContaminationStateMimicing;
public static MentalStateDef ContaminationStateBreakdown;

public static JobDef ContaminationJobForceRest;
public static JobDef ContaminationJobHallucination;
public static JobDef ContaminationJobSleepwalk;
public static JobDef ContaminationJobHoard;
Expand Down Expand Up @@ -94,7 +96,7 @@ public void Tick()
}
}

static bool Prepare(Pawn pawn, int expiryInterval, MentalStateDef mentalDef, JobDef jobDef, Func<bool> check)
static bool ApplyJob(Pawn pawn, int expiryInterval, MentalStateDef mentalDef, JobDef jobDef, Func<bool> check)
{
if (pawn?.Map == null || pawn.health.healthState != PawnHealthState.Mobile)
return false;
Expand All @@ -119,27 +121,41 @@ static bool Prepare(Pawn pawn, int expiryInterval, MentalStateDef mentalDef, Job
return true;
}

[ContaminationRange(0.35f, 0.50f)]
[ContaminationRange(0.15f, 0.40f)]
public static bool ForceRest(Pawn pawn, float factor)
{
var interval = GenDate.TicksPerHour / 10;
var expiryInterval = interval * (int)(1 + factor * 7);

return ApplyJob(
pawn, expiryInterval,
EffectDefs.ContaminationStateForceRest,
EffectDefs.ContaminationJobForceRest,
() => true
);
}

[ContaminationRange(0.25f, 0.50f)]
public static bool Hallucination(Pawn pawn, float factor)
{
var interval = GenDate.TicksPerHour / 10;
var expiryInterval = interval * (int)(1 + factor * 7);

return Prepare(
return ApplyJob(
pawn, expiryInterval,
EffectDefs.ContaminationStateHallucination,
EffectDefs.ContaminationJobHallucination,
() => true
);
}

[ContaminationRange(0.40f, 0.50f)]
[ContaminationRange(0.35f, 0.50f)]
public static bool Sleepwalk(Pawn pawn, float factor)
{
var interval = GenDate.TicksPerHour / 10;
var expiryInterval = interval * (int)(1 + factor * 7);

return Prepare(
return ApplyJob(
pawn, expiryInterval,
EffectDefs.ContaminationStateSleepwalking,
EffectDefs.ContaminationJobSleepwalk,
Expand All @@ -159,7 +175,7 @@ bool HasRoom()
.FirstOrDefault(bed => bed.GetAssignedPawn() == pawn) != null;
}

return Prepare(
return ApplyJob(
pawn, expiryInterval,
EffectDefs.ContaminationStateHoarding,
EffectDefs.ContaminationJobHoard,
Expand All @@ -173,7 +189,7 @@ public static bool Mimicing(Pawn pawn, float factor)
var interval = GenDate.TicksPerHour / 10;
var expiryInterval = interval * (int)(1 + factor * 7);

return Prepare(
return ApplyJob(
pawn, expiryInterval,
EffectDefs.ContaminationStateMimicing,
EffectDefs.ContaminationJobMimic,
Expand All @@ -187,7 +203,7 @@ public static bool Breakdown(Pawn pawn, float factor)
var interval = GenDate.TicksPerHour / 10;
var expiryInterval = interval * (int)(1 + factor * 7);

return Prepare(
return ApplyJob(
pawn, expiryInterval,
EffectDefs.ContaminationStateBreakdown,
EffectDefs.ContaminationJobBreakdown,
Expand Down
Loading

0 comments on commit 7a8e192

Please sign in to comment.