Example #1
0
            public static void Prefix(ref IEnumerable <Thing> things)
            {
                List <Thing> replacementList = new List <Thing>();

                foreach (Thing item in things)
                {
                    Thing toReturn = item;
                    if (item.def.mineable && (!StaticMineral.isMineral(item)))
                    {
                        // check if any of the minerals replace this one
                        foreach (ThingDef_StaticMineral mineralType in DefDatabase <ThingDef_StaticMineral> .AllDefs)
                        {
                            if (mineralType.ThingsToReplace == null || mineralType.ThingsToReplace.Count == 0)
                            {
                                continue;
                            }

                            if (mineralType.ThingsToReplace.Any(item.def.defName.Equals))
                            {
                                toReturn = (StaticMineral)ThingMaker.MakeThing(mineralType);
                                break;
                            }
                        }
                    }
                    replacementList.Add(toReturn);
                }
                things = replacementList;
            }
Example #2
0
        public override Thing ThingToReplaceAtPos(Map map, IntVec3 position)
        {
            // if (defName == "BigColdstoneCrystal") Log.Message("ThingToReplaceAtPos (bg): checking for " + defName +  " at " + position);
            Thing toReplace = base.ThingToReplaceAtPos(map, position);

            if (toReplace == null)
            {
                return(null);
            }
            // if (defName == "BigColdstoneCrystal") Log.Message("ThingToReplaceAtPos (bg): found thing to replace at " + position, true);
            int   spotsChecked = 0;
            float replaceCount = 0;

            for (int xOffset = -replaceRadius; xOffset <= replaceRadius; xOffset++)
            {
                for (int zOffset = -replaceRadius; zOffset <= replaceRadius; zOffset++)
                {
                    spotsChecked = spotsChecked + 1;
                    IntVec3 checkedPosition = position + new IntVec3(xOffset, 0, zOffset);
                    if (checkedPosition.InBounds(map))
                    {
                        foreach (Thing thing in map.thingGrid.ThingsListAt(checkedPosition))
                        {
                            if (thing == null || thing.def == null)
                            {
                                continue;
                            }

                            if (ThingsToReplace.Any(thing.def.defName.Equals))
                            {
                                if (StaticMineral.isMineral(thing))
                                {
                                    replaceCount += ((StaticMineral)thing).size;
                                }
                                else
                                {
                                    replaceCount += 1;
                                }
                            }
                        }
                    }
                }
            }
            if (((float)replaceCount) / ((float)spotsChecked) > repalceThreshold)
            {
                //Log.Message(this.defName + " can replace at " + position, true);
                return(toReplace);
            }
            else
            {
                //Log.Message(this.defName + " can not replace at " + position + " with density " + ((float)replaceCount) / ((float)spotsChecked), true);
                return(null);
            }
        }