Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public override Thing ThingToReplaceAtPos(Map map, IntVec3 position)
        {
            Thing toReplace = base.ThingToReplaceAtPos(map, position);

            if (toReplace == null)
            {
                return(null);
            }
            int spotsChecked = 0;
            int 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))
                            {
                                replaceCount += 1;
                            }
                        }
                    }
                }
            }
            if (((float)replaceCount) / ((float)spotsChecked) > repalceThreshold)
            {
                return(toReplace);
            }
            else
            {
                return(null);
            }
        }