Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - smoq2

#1
Help / Re: Best way for script "ticking"?
February 04, 2015, 08:54:47 AM
Quote from: Rikiki on February 04, 2015, 08:23:12 AM
It is compatible if you follow the instructions provided in Haplo miscellaneous or Caveworld flora mod (read the "Compatibility" section).

Hah, yeah I thought as much that it's possible to edit a save file and force the script to run. That's not the most user-friendly solution though. As much as I know I can do it, I won't force or expect others to, thus I have to find some other method.

[EDIT]

I'm actually leaning towards the "Building" ticker from this tutorial. The problem with it, is that it doesn't seem to spawn on its own.
#2
Help / Re: Best way for script "ticking"?
February 04, 2015, 06:23:23 AM
Thanks for the help!

Unfortunately, both of the methods ("hidden building" or MapComponent) work only with newly started colonies. I need something that will be compatible with old saves.
#3
Help / Best way for script "ticking"?
February 03, 2015, 05:26:04 PM
What is the best way for a piece of code to run with each tick? I used this class:

    class MapComponent_AutoHaul : MapComponent
    {
public override void MapComponentOnGui()
        {
                 blah blah blah
         }
     }


But it seems to run only with newly created colonies. Any better suggestions?
#4
Ok, I did it. My changes:

* unforbid all dead animals that aren't in a stockpile regardless of where they are on the map
* unforbid everything in home zone if the item is not in a stockpile
* designate chunks for hauling in home zone if the item is not in a stockpile

There is a problem however. The mod seems to work only with colonies created after the installation. Loading an older colony causes the script not to update.

I don't know why and do not wish to upload it anywhere until someone tells me why it is so.
#5
Quote from: SilverDragon on February 03, 2015, 09:09:13 AM
Quote from: smoq2 on February 03, 2015, 09:00:50 AM
Quote from: Asfalto on February 03, 2015, 08:48:56 AM
*snip
*snip

So basicly you just want to add a check to the dll that looks if the found chunk is on home region, if so, it ignores it? :)

Precisely! You can find that bit of code here.
#6
Quote from: Asfalto on February 03, 2015, 08:48:56 AM
Actually, i do like the autohauler function (with many attackers it's very useful), i just don't understand why it keeps reselecting for hauling the chunks i already moved into the designed storage

Hm?

Because there is no filter for items already in the storage. A design oversight probably. I'm trying to fix it on behalf of the author as my C# learning exercise. It should be ready today, once I get back from work.
#7
Help / Help with Things and Pawns and Corpses
February 03, 2015, 08:02:37 AM
Will the code below work?

            var homeCells = Find.HomeRegionGrid.ActiveCells;
            if (homeCells == null)
                return;

            var haulables = Find.Map.listerThings.ThingsInGroup(ThingRequestGroup.HaulableEver);

            if (haulables == null)
            {
                return;
            }


var thingsInStockpiles = from stockpile in Find.ZoneManager.ZonesOfType<Zone_Stockpile>()
where stockpile.GetSlotGroup() != null
from thing in stockpile.GetSlotGroup().HeldThings
select thing;

            var forbiddenHaulablesInHomeZone = from thing in haulables
                                               join cell in homeCells on thing.Position equals cell
                                               where thing.IsForbidden(Faction.OfColony) == true
                                               select thing;

//forbiddenHaulablesInHomeZone = forbiddenHaulablesInHomeZone.Except(thingsInStockpiles);    
   
   
            foreach (Thing thing in forbiddenHaulablesInHomeZone)
            {
                GenThing.TrySetForbidden(thing, false);
            }


My 1st question is: Are the things in thingsInStockpiles the same things as in forbiddenHaulablesInHomeZone so that the (commented out) except() method can compare them?

The aim of the code is to ignore items that are in a Stockpile zone as well as Home zone.

My 2nd question is: How do I get a Pawn or a Corpse from a Thing? I know I have to check if the said Thing even has a Pawn or Corpse - how to do that too?

Thanks to anyone willing to help. :)
#8
Quote from: frenchiveruti on February 02, 2015, 12:12:22 AM
Hello there! I've been using the mod for a few colonies, and I have to say that i'm totally happy with it, but, as always, there's some minor problems that at least should have an easy solution, so the auto-haul system isn't bothering all the time. But I would like to suggest some workarounds:

  • When a chunk is in a zone "reserve" or "crap" zone, the system should ignore them, that way, If I build a floor or a wall nearby the stash, i don't have to go and delete the home zone that involves the slags.
  • It would be great, if the system checks around for dead animal corpses, it would be an amazing combination with the Auto-Hunt Beacon Mod, so if there's a collateral animal death, the auto-haul will simply make those poor animal don't die for nothing
If I came up with more ideas, I'll tell you.
Thanks again! I hope my suggestion is welcome, have a nice weekend.

That's exactly what I'm trying to add:

* Add dead animals on the map to the check, regardless of within Home Zone or not.
* Remove items within a Stockpile zone from the check.

However, I seem to have a problem.
After I rebuilt the dll with my changes from the source file, the script stopped working. I added some console notifications, but they don't show up, just as if the script wasn't there.
#9
Help / Re: Console Debugging
February 03, 2015, 03:36:01 AM
Yep, works fine. Didn't know you have to use capital letters. Thanks for the help.
#10
Help / Re: Console Debugging
February 02, 2015, 05:43:35 PM
Quote from: skullywag on February 02, 2015, 05:40:48 PM
log.error();

Are you sure? Xamarin Studio doesn't let me compile with that.
#11
Help / Console Debugging
February 02, 2015, 05:35:42 PM
Is there a way to get your code to print something in the console? Console.WriteLine (string); doesn't seem to work.
#12
I'm trying to modify your Auto Hauler code in order to include dead animals outside of home base, but my knowledge of C# is lacking and I would appreciate a bit of help.

            var forbiddenHaulablesInHomeZone = from thing in haulables
                                               //join cell in homeCells on thing.Position equals cell

where (Find.HomeRegionGrid.ActiveCells.Contains(thing.Position) || thing.innerPawn.get_RaceProps().get_IsAnimal()) && thing.IsForbidden(Faction.OfColony) == true

                                               select thing;


The problem is with thing.innerPawn.get_RaceProps().get_IsAnimal(). As you probably already see, thing is not a corpse, therefore has no innerPawn.

How do I extrapolate a pawn or corpse from thing?
#13
Help / Re: Unforbidding pawns on death
February 02, 2015, 11:37:37 AM
Quote from: Rikiki on February 02, 2015, 11:28:02 AM
In Pawn_HealthTracker, you have a function:
private void PawnKilled(DamageInfo? dinfo, HealthDiff healthDiff)
But this is private! ;) So you would have to overwrite the callers... and so on!

Anyway, to get those functions called, you have to overwrite the core Pawn class which is not a good idea to maintain mods compatibility. >:(
There is already a mod which automatically do this kind of thing.

Yep, figured it would be better to just make a periodic check which would just see if there are any forbidden corpses around every now and then - that's what the "auto hauler" mod you mentioned does.

Anyway, thanks a lot. I'll go on from here. Oh, and many thanks to the author of the aforementioned mod for supplying his source code.

[EDIT]

However, this solution does not suit me in the long term, as it prevents the player from forbidding a corpse (should he wish to do so), as the method would just unforbid it during the next planned check. Hence I wanted it to be unforbid only once (on death). Unless there is some way to either: check if the forbidding was done by the player OR store a bool whether the corpse was already unfrobidden once, it won't do.
#14
Help / Re: Unforbidding pawns on death
February 02, 2015, 09:52:01 AM
Ok, no luck finding help with this solution, so I'll try differently.

Is there some kind of trigger that is called in case of pawn's death? Somewhere within the Defs or within the code.

I could bind my code that will unforbid a pawn if killed under specific circumstances.
#15
Help / Re: Remove body part conditions
January 24, 2015, 10:22:03 AM
Well, it is somewhat better, but too much of the code is still obscured. Check the IsClean method - that's probably the one I need.

namespace RimWorld
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using Verse;

    internal class MedicalRecipesUtility
    {
        public static bool IsClean(Pawn pawn, BodyPartRecord part)
        {
            <IsClean>c__AnonStorey170 storey = new <IsClean>c__AnonStorey170 {
                part = part
            };
            if (pawn.Dead)
            {
                return false;
            }
            return !pawn.healthTracker.bodyModel.healthDiffs.Where<HealthDiff>(new Func<HealthDiff, bool>(storey.<>m__DC)).Any<HealthDiff>();
        }

        public static bool IsCleanAndDroppable(Pawn pawn, BodyPartRecord part)
        {
            if (pawn.Dead)
            {
                return false;
            }
            return ((part.def.spawnThingOnRemoved != null) && IsClean(pawn, part));
        }

        public static void RestorePartAndSpawnAllPreviousParts(Pawn pawn, BodyPartRecord part, IntVec3 pos)
        {
            SpawnNaturalPartIfClean(pawn, part, pos);
            SpawnAddedParts(pawn, part, pos);
            BodyPartDamageInfo info = new BodyPartDamageInfo(part, false, null);
            DamageInfo dinfo = new DamageInfo(DamageTypeDefOf.RestoringBodyPart, 0, null, new BodyPartDamageInfo?(info), null);
            pawn.TakeDamage(dinfo);
        }

        public static void SpawnAddedParts(Pawn pawn, BodyPartRecord part, IntVec3 pos)
        {
            <SpawnAddedParts>c__AnonStorey171 storey = new <SpawnAddedParts>c__AnonStorey171 {
                part = part
            };
            if (pawn.healthTracker.bodyModel.GetNotMissingParts(null, null).Contains<BodyPartRecord>(storey.part))
            {
                IEnumerator<AddedBodyPart> enumerator = pawn.healthTracker.bodyModel.healthDiffs.Where<HealthDiff>(new Func<HealthDiff, bool>(storey.<>m__DD)).Cast<AddedBodyPart>().GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        AddedBodyPart current = enumerator.Current;
                        if (current.def.addedBodyPart.spawnThingOnRemoved != null)
                        {
                            GenSpawn.Spawn(current.def.addedBodyPart.spawnThingOnRemoved, pos);
                        }
                    }
                }
                finally
                {
                    if (enumerator == null)
                    {
                    }
                    enumerator.Dispose();
                }
                for (int i = 0; i < storey.part.parts.Count; i++)
                {
                    SpawnAddedParts(pawn, storey.part.parts[i], pos);
                }
            }
        }

        public static Thing SpawnNaturalPartIfClean(Pawn pawn, BodyPartRecord part, IntVec3 pos)
        {
            if (IsCleanAndDroppable(pawn, part))
            {
                return GenSpawn.Spawn(part.def.spawnThingOnRemoved, pos);
            }
            return null;
        }

        [CompilerGenerated]
        private sealed class <IsClean>c__AnonStorey170
        {
            internal BodyPartRecord part;

            internal bool <>m__DC(HealthDiff x)
            {
                return (x.Part == this.part);
            }
        }

        [CompilerGenerated]
        private sealed class <SpawnAddedParts>c__AnonStorey171
        {
            internal BodyPartRecord part;

            internal bool <>m__DD(HealthDiff x)
            {
                return ((x.Part == this.part) && (x is AddedBodyPart));
            }
        }
    }
}