This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/AndroidQuazar/VanillaExpa…
- Loading branch information
Showing
8 changed files
with
408 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using HarmonyLib; | ||
using RimWorld; | ||
using Verse; | ||
|
||
namespace VFECore | ||
{ | ||
public class TraitEntryBackstory | ||
{ | ||
public TraitDef defName; | ||
|
||
public int degree; | ||
|
||
public int chance; | ||
} | ||
public class BackstoryDef : Def | ||
{ | ||
public override void ResolveReferences() | ||
{ | ||
if (BackstoryDatabase.allBackstories.ContainsKey(this.saveKeyIdentifier)) | ||
{ | ||
Log.Error(this.defName + " contains a saveKeyIdentifier value " + saveKeyIdentifier + " which is used already. It won't be added as a def. Make sure that the identifier is unique."); | ||
return; | ||
} | ||
|
||
Backstory backstory = new Backstory(); | ||
if (this.forcedTraits?.Any() ?? false) | ||
{ | ||
backstory.forcedTraits = new List<TraitEntry>(); | ||
foreach (var trait in this.forcedTraits.Where(x => Rand.RangeInclusive(0, 100) < x.chance)) | ||
{ | ||
backstory.forcedTraits.Add(new TraitEntry(trait.defName, trait.degree)); | ||
} | ||
} | ||
|
||
if (this.disallowedTraits?.Any() ?? false) | ||
{ | ||
backstory.disallowedTraits = new List<TraitEntry>(); | ||
foreach (var trait in this.disallowedTraits.Where(x => Rand.RangeInclusive(0, 100) < x.chance)) | ||
{ | ||
backstory.disallowedTraits.Add(new TraitEntry(trait.defName, trait.degree)); | ||
} | ||
} | ||
|
||
backstory.SetTitle(this.title, this.title); | ||
if (!GenText.NullOrEmpty(this.titleShort)) | ||
{ | ||
backstory.SetTitleShort(this.titleShort, this.titleShort); | ||
} | ||
else | ||
{ | ||
backstory.SetTitleShort(backstory.title, backstory.title); | ||
} | ||
if (!GenText.NullOrEmpty(this.baseDescription)) | ||
{ | ||
backstory.baseDesc = this.baseDescription; | ||
} | ||
|
||
Traverse.Create(backstory).Field("bodyTypeGlobal").SetValue(this.bodyTypeGlobal); | ||
Traverse.Create(backstory).Field("bodyTypeMale").SetValue(this.bodyTypeMale); | ||
Traverse.Create(backstory).Field("bodyTypeFemale").SetValue(this.bodyTypeFemale); | ||
if (skillGains?.Any() ?? false) | ||
{ | ||
var skillGainsDict = skillGains.ToDictionary(x => x.skill.defName, y => y.minLevel); | ||
Traverse.Create(backstory).Field("skillGains").SetValue(skillGainsDict); | ||
} | ||
|
||
backstory.slot = this.slot; | ||
backstory.shuffleable = this.shuffleable; | ||
backstory.spawnCategories = this.spawnCategories; | ||
|
||
if (this.workDisables.Any()) | ||
{ | ||
foreach (var workTag in this.workDisables) | ||
{ | ||
backstory.workDisables |= workTag; | ||
} | ||
} | ||
else | ||
{ | ||
backstory.workDisables = WorkTags.None; | ||
} | ||
|
||
backstory.PostLoad(); | ||
backstory.ResolveReferences(); | ||
backstory.identifier = this.saveKeyIdentifier; | ||
|
||
if (!backstory.ConfigErrors(true).Any()) | ||
{ | ||
BackstoryDatabase.AddBackstory(backstory); | ||
} | ||
else | ||
{ | ||
foreach (var err in backstory.ConfigErrors(true)) | ||
{ | ||
Log.Error(backstory + " - " + err); | ||
} | ||
} | ||
} | ||
|
||
public string baseDescription; | ||
|
||
public string bodyTypeGlobal = ""; | ||
|
||
public string bodyTypeMale = "Male"; | ||
|
||
public string bodyTypeFemale = "Female"; | ||
|
||
public string title; | ||
|
||
public string titleShort; | ||
|
||
public BackstorySlot slot = BackstorySlot.Childhood; | ||
|
||
public bool shuffleable = true; | ||
|
||
public List<WorkTags> workDisables = new List<WorkTags>(); | ||
|
||
public List<string> spawnCategories = new List<string>(); | ||
|
||
public List<SkillRequirement> skillGains; | ||
|
||
public List<TraitEntryBackstory> forcedTraits = new List<TraitEntryBackstory>(); | ||
|
||
public List<TraitEntryBackstory> disallowedTraits = new List<TraitEntryBackstory>(); | ||
|
||
public string saveKeyIdentifier; | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
Source/VFECore/VFECore/MapExtender/MapGenerator_GenerateMap_Patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using RimWorld; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Verse; | ||
using UnityEngine; | ||
using RimWorld.Planet; | ||
using HarmonyLib; | ||
|
||
// Copyright Sarg - Alpha Biomes 2020 & Taranchuck | ||
|
||
namespace VFECore | ||
{ | ||
[HarmonyPatch(typeof(MapGenerator), nameof(MapGenerator.GenerateMap))] | ||
public static class MapGenerator_GenerateMap_Patch | ||
{ | ||
public static void Postfix(Map __result) | ||
{ | ||
DoMapSpawns(__result); | ||
} | ||
public static bool CanSpawnAt(IntVec3 c, Map map, ObjectSpawnsDef element) | ||
{ | ||
if (!element.allowOnChunks) | ||
{ | ||
foreach (var item in c.GetThingList(map)) | ||
{ | ||
if (item?.def?.thingCategories != null) | ||
{ | ||
foreach (var category in item.def.thingCategories) | ||
{ | ||
if (category == ThingCategoryDefOf.Chunks || category == ThingCategoryDefOf.StoneChunks) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
TerrainDef terrain = c.GetTerrain(map); | ||
|
||
bool flagAllowed = true; | ||
|
||
foreach (string allowed in element.allowedTerrains) | ||
{ | ||
if (terrain.defName == allowed) | ||
{ | ||
break; | ||
} | ||
else flagAllowed = false; | ||
} | ||
if (!flagAllowed) return false; | ||
|
||
foreach (string notAllowed in element.disallowedTerrainTags) | ||
{ | ||
if (terrain.HasTag(notAllowed)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
if (!element.allowOnWater && terrain.IsWater) | ||
{ | ||
return false; | ||
} | ||
|
||
if (element.findCellsOutsideColony) | ||
{ | ||
if (!OutOfCenter(c, map, 60)) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
public static void DoMapSpawns(Map map) | ||
{ | ||
int spawnCounter = 0; | ||
foreach (ObjectSpawnsDef element in DefDatabase<ObjectSpawnsDef>.AllDefs.Where(element => element.allowedBiomes.Contains(map.Biome))) | ||
{ | ||
if (element.spawnOnlyInPlayerMaps && !map.IsPlayerHome) | ||
{ | ||
continue; | ||
} | ||
IEnumerable<IntVec3> tmpTerrain = map.AllCells.InRandomOrder(); | ||
if (spawnCounter == 0) | ||
{ | ||
spawnCounter = element.numberToSpawn.RandomInRange; | ||
} | ||
foreach (IntVec3 c in tmpTerrain) | ||
{ | ||
bool canSpawn = CanSpawnAt(c, map, element); | ||
if (canSpawn) | ||
{ | ||
Thing thing = (Thing)ThingMaker.MakeThing(element.thingDef, null); | ||
CellRect occupiedRect = GenAdj.OccupiedRect(c, thing.Rotation, thing.def.Size); | ||
if (occupiedRect.InBounds(map)) | ||
{ | ||
canSpawn = true; | ||
foreach (IntVec3 c2 in occupiedRect) | ||
{ | ||
if (!CanSpawnAt(c2, map, element)) | ||
{ | ||
canSpawn = false; | ||
break; | ||
} | ||
} | ||
if (canSpawn) | ||
{ | ||
if (element.randomRotation) | ||
{ | ||
GenPlace.TryPlaceThing(thing, c, map, ThingPlaceMode.Direct, null, null, Rot4.Random); | ||
} | ||
else | ||
{ | ||
GenSpawn.Spawn(thing, c, map); | ||
} | ||
spawnCounter--; | ||
} | ||
} | ||
} | ||
|
||
if (canSpawn && spawnCounter <= 0) | ||
{ | ||
spawnCounter = 0; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static bool OutOfCenter(IntVec3 c, Map map, int centerDist) | ||
{ | ||
IntVec3 CenterPoint = map.Center; | ||
return c.x < CenterPoint.x - centerDist || c.z < CenterPoint.z - centerDist || c.x >= CenterPoint.x + centerDist || c.z >= CenterPoint.z + centerDist; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using RimWorld; | ||
using UnityEngine; | ||
using Verse; | ||
|
||
// Copyright Sarg - Alpha Biomes 2020 & Taranchuck | ||
|
||
namespace VFECore | ||
{ | ||
public class ObjectSpawnsDef : Def | ||
{ | ||
public ThingDef thingDef; | ||
public bool allowOnWater; | ||
public bool allowOnChunks; | ||
public IntRange numberToSpawn; | ||
public List<string> allowedTerrains; | ||
public List<string> disallowedTerrainTags; | ||
public List<BiomeDef> allowedBiomes; | ||
public bool findCellsOutsideColony = false; | ||
public bool spawnOnlyInPlayerMaps = false; | ||
public bool randomRotation; | ||
} | ||
} |
Oops, something went wrong.