1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

How to spawn migrants for factories

Discussion in 'Modding Help' started by Tsilliev, Aug 17, 2013.

  1. Tsilliev

    Tsilliev Haxor

    Messages:
    414
    The title says it all, now I can show what I have done so far, yesterday I started playing around with the files for the first time and I made a craftable migrant from the workbench :D
    [​IMG]
    [​IMG]
    [​IMG]
    And I have also made a craftable dorm
    [​IMG]
    [​IMG]
    I am trying to get more migrants so we can have more factories.
    I understand that the migrants in the hall are actually hall workers and not migrants.
    If I create a dorm no migrant is spawned and if I craft a migrant from the workbench he dies.
    So let's go in order now shall we.
    A. Spawn more workers using Dorms
    or
    B.Make migrants work in factories as well.
    B1. Stop Migrants from Dying
    B2. Spawn Migrants from Dorms.
    And if we are really good
    C. Sell seeds from the trader (little offtopic but that would be my next question)
    C1. Sell migrants from the trader, quickest fix?
    So for (A) let's see how workers are actually being spawned:
    Code:
    /**
        * Construct a hall worker set from an owner
        * Automatically constructs the workers from the
        * migrants properties vars.
        */
        HallWorkerSet(CBlob@ owner)
        {
            ownerID = owner.getNetworkID();
            u8 count = owner.get_u8("migrants max");
            for(uint i = 0; i < count; ++i)
            {
                HallWorker w(owner);
                workers.push_back(w);
            }
    
            lastRespawnTime = 0;
            under_raid = false;
        }
    So from this code I can see that there is "migrants max" or limit on migrants, we should uplift this restriction? But if we do they will just spawn in the hall and we don't want that we want to spawn them from Dorms.
    So let's see the dorms code:
    Code:
    const int migrant_tickets = 1;
    const int migrant_replenish_ticks = 300;
    I tried changing the tickets to 10 but no migrants are spawning maybe because of the "migrants max" restriction?
    I can also see this from the Migrant Code
    Code:
    shared CBlob@ CreateMigant( Vec2f pos, int team )
    {
        CBlob@ blob = server_CreateBlobNoInit( "migrant" );
        if (blob !is null) {
            //setup ready for init
            blob.setSexNum(XORRandom(2));
            blob.server_setTeamNum(team);
            blob.setPosition(pos);
    
            blob.Init();
    
            blob.SetFacingLeft(XORRandom(2) == 0);
    
            SetMigrant( blob, true ); //requires brain -> after init
        }
        return blob;
    }
    And that
    Code:
    bool isRoomFullOfMigrants( CBlob@ this )
    {
        return this.get_u8("migrants count") >= this.get_u8("migrants max");
    }
    
    bool needsReplenishMigrant( CBlob@ this )
    {
        return this.get_u8("migrants count") < this.get_u8("migrants max");
    }
    
    void AddMigrantCount( CBlob@ this, int add = 1 )
    {
        this.set_u8("migrants count", this.get_u8("migrants count")+add );
    }
    
    void DecMigrantCount( CBlob@ this, int dec = 1 )
    {
        this.set_u8("migrants count", this.get_u8("migrants count")-dec );
    }
    So what about (B) (Make migrants work in factories as well.)?
    Code:
    int getWorkers( CBlob@ this )
    {
        int workers = 0;
        CBlob@[] blobs;
        if (this.getMap().getBlobsInRadius( this.getPosition(), this.getRadius(), @blobs ))
        {
            for (uint step = 0; step < blobs.length; ++step)
            {
                CBlob@ b = blobs[step];
                if (b.hasTag("migrant") && !b.hasTag("dead"))
                {
                    workers++;
                }
            }
        }
        return workers;
    }
    But! In the Hall code we can see this
    Code:
    shared void getFactories(CBlob@ hall, CBlob@[]@ factories)
    {
        HallWorkerSet@ workersSet;
        if(!hall.get("hall workers", @workersSet) || workersSet is null) return;
    
        for(uint i = 0 ; i < workersSet.workers.length; ++i)
        {
            HallWorker@ worker = workersSet.workers[i];
            CBlob@ blob = worker.getUser();
            if (blob !is null && blob.getName() == "factory")
                factories.push_back( blob );
        }
    }
    So I am getting little confused, but we can see that it uses the term workers, so I must change everything to migrant?

    And for (B1) (Stop Migrants from Dying.):
    Code:
    if(owner is null || //no owner
            //or not overlapping owner (or glued somewhere)
            (!this.getShape().isStatic() && !this.isOverlapping(owner)) )
        {
            SelfDamage( this );
    
            this.Tag(pickable_tag);
            this.Sync(pickable_tag, true);
        }
        else
        {
            this.Untag(pickable_tag);
            this.Sync(pickable_tag, true);
        }
    }
    So if they don't have an owner they die? And if they do they can be picked? Right now they cannot be picked so actually they don't have an owner?
    For (B2) same as (A).
    About (C) I searched around the Trader code I couldn't find how items are put in the trader menu its not the same as the workbench with the addshop. Or i can just put the seed in the workbench and put a gold tag on it, but! I tried with
    Code:
    {
            ShopItem@ s = addShopItem( this, "Seed", "$seed$", "seed", descriptions[54], false );
            AddRequirement( s.requirements, "blob", "mat_wood", "Wood", 30 );
        }
    And it gives me grain seed and not tree seed :D
    And (C1) Maybe we could add migrant in the trader menu as well? If we don't want to build dorms? It is like when you purchase a migrant the size of the workers in the hall are increased by 1.