Self sustaining AI village

Published by mark on

Self sustaining AI village

Meta Data

Teamsize: 2 devs

Project Length: 2 weeks, 30h a week.

Duties: everything, but in collaboration with teammate

Engine: unity

this prototype is a collaboration between me and Mark de kuijer. in this prototype we both wanted to learn things from each other and we thought just about creating a fun engaging prototype togheter to be able to collaborate and share knowledge.

This prototype features a village, where at the start of the program you can select how many resources the village needs to start with. after that, the village will come to life and Ai will spawn and will gather resources and will slowly build new buildings after some time the village will have grown and will be full of even more life.

Screenshots

Sample Code

  using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Inventory : MonoBehaviour
{
    private List m_InInventory;
    public List GetIntentoryItems { get { return m_InInventory; } }

    private void Awake()
    {
        m_InInventory = new List();
    }

    public void Pickup(Pickup_Item PickupItem, int Amount = 0)
    {
        if (!Contains(PickupItem))
        {
            Inventory_Item item = gameObject.AddComponent();
            item.SendMessage("Create_item", new string[3] { PickupItem.GetName, "0", GameManager.GetMaxInventory(PickupItem.GetName).ToString() }, SendMessageOptions.DontRequireReceiver);
            m_InInventory.Add(item);
        }
        for (int i = 0; i < m_InInventory.Count; i++)
        {
            if (m_InInventory[i].GetName == PickupItem.GetName)
            {
                if (m_InInventory[i].GetAmount + Amount <= m_InInventory[i].GetMaxAmount && Amount <= PickupItem.GetAmount && Amount > 0)
                {
                    m_InInventory[i].Pick_amount = PickupItem.GetAmount;
                    PickupItem.Use_amount = PickupItem.GetAmount;
                }
                else if (m_InInventory[i].GetAmount + PickupItem.GetAmount <= m_InInventory[i].GetMaxAmount)
                {
                    m_InInventory[i].Pick_amount = PickupItem.GetAmount;
                    PickupItem.Use_amount = PickupItem.GetAmount;
                }
                else if (m_InInventory[i].GetAmount < m_InInventory[i].GetMaxAmount)
                {
                    int difrence = m_InInventory[i].GetMaxAmount - m_InInventory[i].GetAmount;
                    PickupItem.Use_amount = difrence;
                    m_InInventory[i].Pick_amount = difrence;
                    GameManager.Manager_instance.AvaliblePickups.Add(PickupItem);
                }
                //else if (m_InInventory[i].GetAmount + PickupItem.GetAmount > m_InInventory[i].GetMaxAmount)
                //{
                //    //Debug.LogError("Inventory full Can't pick up item");
                //}
                return;
            }
        }
    }

    private bool Contains(Pickup_Item ItemName)
    {
        for (int i = 0; i < m_InInventory.Count; i++)
        {
            if (ItemName.GetName == m_InInventory[i].GetName)
                return true;
        }
        return false;
    }
}
}

Workflow

We both worked on our own task, then if we needed help or we wanted to know how someone else created something we took a seat with each other and showed eachother how we created something. once we were done with a task, we asked eachother what else we would like to see in the village.

Categories: Prototype