Beispiel #1
0
 public CaptureActor(Actor self, Actor target)
     : base(self, target)
 {
     actor = target;
     capturesInfo = self.Info.Traits.Get<CapturesInfo>();
     capturable = target.Trait<Capturable>();
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (currentActionCooldown <= 0)
        {
            if (Random.value < noActionChance)
            {
                List <Capturable> own = capturables.Where(c => c.owner == player).ToList();

                if (own.Count > 0)
                {
                    Capturable        selected = own[Random.Range(0, own.Count)];
                    List <Capturable> targets  = capturables.Where(c => c != selected && (c.owner != player || c.unitCount < c.unitCap)).ToList();
                    if (targets.Count > 0)
                    {
                        Capturable target = targets[Random.Range(0, targets.Count)];
                        selected.BeginRaid(target);
                    }
                }
            }

            currentActionCooldown = actionCooldown;
        }
        else
        {
            currentActionCooldown -= Time.deltaTime;
        }
    }
Beispiel #3
0
    // Attacking a hostile structure
    private void Attack()
    {
        List <Capturable> hostileCaps       = gameBoard.capturables.Where(c => c.owner != player).ToList();
        Capturable        weakestCap        = null;
        float             smallestUnitCount = Mathf.Infinity;
        Capturable        attackCap         = null;
        float             largestUnitCount  = 0;

        foreach (Capturable hostileCap in hostileCaps)
        {
            if (hostileCap.unitCount < smallestUnitCount)
            {
                weakestCap        = hostileCap;
                smallestUnitCount = hostileCap.unitCount;
            }
        }

        List <Capturable> attackCaps = gameBoard.capturables.Where(c => c.owner == player && !(c is Tower)).ToList();

        foreach (Capturable cap in attackCaps)
        {
            if (cap.unitCount > largestUnitCount)
            {
                attackCap        = cap;
                largestUnitCount = cap.unitCount;
            }
        }

        if (attackCap != null && weakestCap != null)
        {
            attackCap.BeginRaid(weakestCap);
        }
    }
Beispiel #4
0
 /// <summary>
 /// Move a squad from tyhe actual capturable to an other
 /// </summary>
 /// <param name="squad"></param>
 /// <param name="to"></param>
 public void MoveSquad(Squad squad, Capturable to)
 {
     to.AddSquad(squad);
     Units.Remove(squad);
     squad.Move(to.gameObject.transform.position);
     //Debug.Log("squad moved");
 }
Beispiel #5
0
    public void Reset()
    {
        foreach (Agent agent in agents)
        {
            agent.Done();
        }

        foreach (Capturable capturable in capturables)
        {
            capturable.Reset();
        }

        foreach (Raid raid in raids)
        {
            if (raid != null)
            {
                Destroy(raid.gameObject);
            }
        }
        raids.Clear();

        foreach (Player player in players)
        {
            player.Reset();
        }

        if (randomResets)
        {
            //Randomize all capturable statuses to let the AI see more states.
            List <Player>     playerBuffer     = new List <Player>(players);
            List <Capturable> capturableBuffer = new List <Capturable>(capturables);
            for (int i = 0; i < players.Count; ++i)
            {
                Player player = playerBuffer[Random.Range(0, playerBuffer.Count)];
                int    startingCapturables = Random.Range(0, capturableBuffer.Count);
                for (int j = 0; j < startingCapturables; ++j)
                {
                    Capturable capturable = capturableBuffer[Random.Range(0, capturableBuffer.Count)];
                    capturable.SetOwner(player);

                    capturableBuffer.Remove(capturable);
                }

                playerBuffer.Remove(player);
            }
        }
        else
        {
            List <Capturable> forts = capturables.Where(c => c.gameObject.name == "Fort").ToList();
            foreach (Player player in players)
            {
                //Randomize what forts the players start in to reduce risk of overfitting.
                Capturable fort = forts[Random.Range(0, forts.Count)];
                fort.SetOwner(player);
                forts.Remove(fort);
            }
        }

        currentTime = 0;
    }
Beispiel #6
0
 public CaptureActor(Actor self, Actor target)
     : base(self, target)
 {
     actor        = target;
     capturesInfo = self.Info.Traits.Get <CapturesInfo>();
     capturable   = target.Trait <Capturable>();
 }
Beispiel #7
0
 public TerrainStaticData(string name /*, TODO: icon */, int defense, Altitude altitude, Capturable isCapturable)
 {
     this.name = name;
     //this.icon = icon;
     this.defense      = defense;
     this.altitude     = altitude;
     this.isCapturable = isCapturable;
 }
Beispiel #8
0
 private void Deselect()
 {
     if (selected)
     {
         selected.OnDeselected();
     }
     selected = null;
 }
Beispiel #9
0
 public void Init(Player owner, Transform parent, Capturable target, int units)
 {
     this.owner        = owner;
     transform.parent  = parent;
     dest              = target;
     unitCount         = units;
     distanceRemaining = Vector3.Distance(transform.position, dest.transform.position);
 }
Beispiel #10
0
 public void Capture(Capturable c)
 {
     if (captured == null)
     {
         captured = c;
         c.Capture();
     }
 }
Beispiel #11
0
 public CaptureActor(Actor self, Actor target)
     : base(self, target, EnterBehaviour.Dispose)
 {
     actor      = target;
     building   = actor.TraitOrDefault <Building>();
     captures   = self.TraitsImplementing <Captures>().ToArray();
     capturable = target.Trait <Capturable>();
     health     = actor.Trait <Health>();
 }
Beispiel #12
0
 public CaptureActor(Actor self, Actor target)
     : base(self, target)
 {
     actor        = target;
     building     = actor.TraitOrDefault <Building>();
     capturesInfo = self.Info.Traits.Get <CapturesInfo>();
     capturable   = target.Trait <Capturable>();
     health       = actor.Trait <Health>();
 }
Beispiel #13
0
 public void Release()
 {
     if (captured != null)
     {
         captured.transform.position = this.gameObject.transform.position - Vector3.up * dropOffset;
         captured.Release();
         captured = null;
     }
 }
Beispiel #14
0
 public CaptureActor(Actor self, Actor target)
     : base(self, target, EnterBehaviour.Dispose)
 {
     actor        = target;
     building     = actor.TraitOrDefault <Building>();
     capturesInfo = self.Info.TraitInfo <CapturesInfo>();
     capturable   = target.Trait <Capturable>();
     health       = actor.Trait <Health>();
 }
    public void CreateHealthBar(Capturable cPoint)
    {
        GameObject newObj = Instantiate(progressPrefab);
        newObj.transform.SetParent(team1Spawn, false);
        newObj.GetComponent<ProgressBar>().Init(cPoint);

        newObj = Instantiate(progressPrefab);
        newObj.transform.SetParent(team2Spawn, false);
        newObj.GetComponent<ProgressBar>().Init(cPoint);
    }
Beispiel #16
0
    /// <summary>
    /// 対象の捕獲を試行する。捕獲できたらTrue。
    /// </summary>
    /// <param name="target"></param>
    protected void TryCaptureTarget(GameObject target)
    {
        Capturable capturable = target.GetComponent <Capturable>();

        if (capturable == null)
        {
            return;
        }

        capturable.BeCaptured();
        actor.CanAction = false;
    }
    void Awake()
    {
        capturable            = GetComponentInChildren <Capturable>();
        setMaterialProperties = GetComponent <SetMaterialProperties>();
        uiController          = UIController.Instance;

        if (!StartCaptured)
        {
            Team = 2;
        }

        capturable.Captured += OnCaptured;
    }
Beispiel #18
0
    public int lengthofprediction = 100; //BAD: constant should be moved to top

    // Use this for initialization
    void Start()
    {
        rb            = gameObject.GetComponent <Rigidbody2D>();
        lr            = gameObject.GetComponent <LineRenderer>();
        cap           = gameObject.GetComponent <Capturable>();
        shooterradius = gameObject.GetComponent <CircleCollider2D>().radius;
        if (cap.team > 0)
        {
            canShoot = true;
        }
        mansloaded      = 0;
        manstoload      = 0;
        velocitytoshoot = new Vector2(0, 0);
    }
Beispiel #19
0
    public void BeginRaid(Capturable target)
    {
        int raidCount = unitCount / 2;

        if (raidCount > 0 && (target.owner != owner || target.unitCount < target.unitCap) && target != this)
        {
            unitCount -= raidCount;

            Vector3 targetVector = target.transform.position - transform.position;
            Raid    raid         = Instantiate(raidPrefab, transform.position, Quaternion.LookRotation(targetVector, Vector3.up));

            raid.Init(owner, transform.parent, target, raidCount);
            unitIndicator.UpdateText(trainingID + ": (" + unitCount.ToString() + ")", owner);
        }
    }
Beispiel #20
0
    /// <summary>
    /// show info about the actuale area selected
    /// </summary>
    /// <param name="capturable">the area you want show</param>
    public void ShowCapturable(Capturable capturable)
    {
        capturablePanel.SetActive(true);

        nameC.text         = capturable.name;
        teamC.text         = capturable.team.ToString();
        this.building.text = capturable.HasBuilding? "Yes" : "No";
        if (capturable.Units.Count > 0)
        {
            this.units.text = "Yes";
        }
        else
        {
            this.units.text = "No";
        }
    }
    //Captures a boy
    void Capture()
    {
        if (capturable != null)
        {
            Capturable c = capturable.GetComponent <Capturable>();
            c.GetCaptured(this);

            if (!captured.Contains(capturable))
            {
                captured.Add(capturable);
                if (IsOutlet(capturable))
                {
                    outlets++;
                }
            }
        }
    }
Beispiel #22
0
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        if (currentActionCooldown <= 0)
        {
            base.AgentAction(vectorAction, textAction);
            Capturable selected = board.capturables[(int)vectorAction[0]];
            Capturable target   = board.capturables[(int)vectorAction[1]];

            if (selected.owner == player)
            {
                if (selected.unitCount > 1 && target.owner != player)
                {
                    //Encourage attacking
                    AddReward(0.1f);
                }
                selected.BeginRaid(target);
            }

            int capturablesOwned = board.capturables.Count(c => c.owner == player);
            if (capturablesOwned > previousCapturables)
            {
                //Heavily encourage taking buildings.
                AddReward((capturablesOwned - previousCapturables) * 1.0f);
            }

            previousCapturables = capturablesOwned;

            //Check if we have won, or lost.
            if (board.capturables.All(c => c.owner == player) && !board.raids.Any(r => r.owner != player))
            {
                //Super-heavily encourage winning.
                AddReward(100.0f);
                Done();
            }
            else if (board.capturables.All(c => c.owner != player) && !board.raids.Any(r => r.owner == player))
            {
                //Defeat
                Done();
            }

            currentActionCooldown = actionCooldown;
        }

        currentActionCooldown -= Time.deltaTime;
    }
Beispiel #23
0
 private void HandleRightClick()
 {
     if (selected != null)
     {
         if (Input.GetMouseButtonDown(1))
         {
             var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out RaycastHit rayHit))
             {
                 Capturable c = rayHit.collider.GetComponent <Capturable>();
                 if (c != null)
                 {
                     selected.BeginRaid(c);
                 }
             }
         }
     }
 }
Beispiel #24
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        Capturable cap = collision.gameObject.GetComponent <Capturable>();

        if (cap != null)
        {
            cap.landMans(res, team);
            Destroy(gameObject);
        }
        else
        {
            Munition mun = collision.gameObject.GetComponent <Munition>();
            if (mun == null)
            {
                Destroy(gameObject);
            }
        }
    }
Beispiel #25
0
    public static GameObject CreateAndRegisterBaggedCreature(GameObject creature, bool must_stand_on_top_for_pickup, bool allow_mark_for_capture, bool use_gun_for_pickup = false)
    {
        KPrefabID creature_prefab_id = creature.GetComponent <KPrefabID>();

        creature_prefab_id.AddTag(GameTags.BagableCreature, false);
        Baggable baggable = creature.AddOrGet <Baggable>();

        baggable.mustStandOntopOfTrapForPickup = must_stand_on_top_for_pickup;
        baggable.useGunForPickup = use_gun_for_pickup;
        Capturable capturable = creature.AddOrGet <Capturable>();

        capturable.allowCapture           = allow_mark_for_capture;
        creature_prefab_id.prefabSpawnFn += delegate
        {
            WorldInventory.Instance.Discover(creature_prefab_id.PrefabTag, WorldInventory.GetCategoryForTags(creature_prefab_id.Tags));
        };
        return(creature);
    }
Beispiel #26
0
 void SetupAlliedBase()
 {
     foreach (var actor in world.Actors.Where(a => a.Owner == allies && a != allies.PlayerActor))
     {
         actor.ChangeOwner(allies2);
         Capturable.ChangeCargoOwner(actor, allies2);
         if (actor.Info.Name == "proc")
         {
             actor.QueueActivity(new Transform(actor, "proc")
             {
                 SkipMakeAnims = true
             });                                                                                             // for harv spawn
         }
         foreach (var c in actor.TraitsImplementing <INotifyCapture>())
         {
             c.OnCapture(actor, actor, allies, allies2);
         }
     }
 }
Beispiel #27
0
    void Awake()
    {
        capturable     = transform.parent.gameObject.GetComponentInChildren <Capturable>();
        health         = transform.parent.gameObject.GetComponentInChildren <Health>();
        spriteRenderer = GetComponent <SpriteRenderer>();
        uiController   = UIController.Instance;

        uiController.StoreUpdated += OnStoreChanged;

        if (capturable)
        {
            capturable.Captured += OnCaptured;
        }

        if (health)
        {
            health.Died += OnDied;
        }
    }
Beispiel #28
0
 private void HandleLeftClick()
 {
     if (Input.GetMouseButtonDown(0))
     {
         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out RaycastHit rayHit))
         {
             Capturable c = rayHit.collider.GetComponent <Capturable>();
             if (c != null)
             {
                 if (c.owner == player)
                 {
                     Select(c);
                     return;
                 }
             }
         }
         Deselect();
     }
 }
Beispiel #29
0
    // Take over neutral buildings
    private void Expand()
    {
        List <Capturable> neutralCaps   = gameBoard.capturables.Where(c => c.owner == null && !(c is Tower)).ToList();
        List <Capturable> neutralTowers = gameBoard.capturables.Where(c => c.owner == null && c is Tower).ToList();
        List <Capturable> ownCaps       = gameBoard.capturables.Where(c => c.owner == player && !(c is Tower)).ToList();
        float             smallestDist  = Mathf.Infinity;
        Capturable        origin        = null;
        Capturable        destination   = null;


        List <Capturable> sixtyPlusCaps = gameBoard.capturables.Where(c => c.owner == player && c.unitCount > 60).ToList();

        if (neutralTowers.Count > 0 && sixtyPlusCaps.Count > 0)
        {
            neutralCaps = neutralTowers;
            ownCaps     = sixtyPlusCaps;
        }

        if (neutralCaps.Count > 0)
        {
            foreach (var ownCap in ownCaps)
            {
                foreach (var neutralCap in neutralCaps)
                {
                    float tempDist = Vector3.Distance(ownCap.transform.position, neutralCap.transform.position);
                    if (tempDist < smallestDist)
                    {
                        smallestDist = tempDist;
                        origin       = ownCap;
                        destination  = neutralCap;
                    }
                }
            }
        }

        if (origin != null && destination != null)
        {
            origin.BeginRaid(destination);
        }
    }
    void Awake()
    {
        capturable            = GetComponentInChildren <Capturable>();
        setMaterialProperties = GetComponent <SetMaterialProperties>();
        selectable            = GetComponentInChildren <Selectable>();
        uiController          = UIController.Instance;

        CurrentShip = ShipDataset[0];

        if (!StartCaptured)
        {
            Team = 2;
        }

        if (Team == 2)
        {
            selectable.gameObject.SetActive(false);
        }

        capturable.Captured       += OnCaptured;
        uiController.StoreUpdated += OnStoreUpdated;
    }
Beispiel #31
0
    // Move units to a building to increase their unit count
    private void Reinforce()
    {
        List <Capturable> fullCaps          = gameBoard.capturables.Where(c => c.owner == player && c.unitCount >= c.unitCap).ToList();
        List <Capturable> noneFullCaps      = gameBoard.capturables.Where(c => c.owner == player && c.unitCount < c.unitCap).ToList();
        Capturable        weakestCap        = null;
        float             smallestUnitCount = Mathf.Infinity;
        Capturable        supportCap        = null;
        float             smallestDist      = Mathf.Infinity;

        foreach (Capturable cap in noneFullCaps)
        {
            if (cap.unitCount < smallestUnitCount)
            {
                weakestCap        = cap;
                smallestUnitCount = cap.unitCount;
            }
        }

        foreach (Capturable cap in fullCaps)
        {
            float tempDist = Mathf.Infinity;
            if (weakestCap != null)
            {
                tempDist = Vector3.Distance(weakestCap.transform.position, cap.transform.position);
            }

            if (tempDist < smallestDist)
            {
                smallestDist = tempDist;
                supportCap   = cap;
            }
        }

        if (supportCap != null && weakestCap != null)
        {
            supportCap.BeginRaid(weakestCap);
        }
    }
 public void Init(Capturable _cap)
 {
     cap = _cap;
 }
Beispiel #33
0
 public TerrainStaticData(string name/*, TODO: icon */, int defense, Altitude altitude, Capturable isCapturable)
 {
     this.name = name;
     //this.icon = icon;
     this.defense = defense;
     this.altitude = altitude;
     this.isCapturable = isCapturable;
 }
 static void Postfix(Capturable __instance)
 {
     __instance.gameObject.AddComponent <CritterSuppressionButton>();
 }