Example #1
0
 public static void Serialize(BinaryWriter s, RTSTeam team)
 {
     s.Write(team.Type);
     RTSRace.Serialize(s, team.Race);
     if (team.Input != null)
     {
         s.Write(true);
         s.Write(ReflectedScript.GetKey(team.Input));
         team.Input.Serialize(s);
     }
     else
     {
         s.Write(false);
     }
     s.Write(team.ColorScheme.Name);
     s.Write(team.ColorScheme.Primary);
     s.Write(team.ColorScheme.Secondary);
     s.Write(team.ColorScheme.Tertiary);
     s.Write(team.Buildings.Count);
     foreach (var building in team.Buildings)
     {
         RTSBuilding.Serialize(s, building);
     }
     s.Write(team.Units.Count);
     foreach (var unit in team.Units)
     {
         RTSUnit.Serialize(s, unit);
     }
     s.Write(team.Squads.Count);
     foreach (var squad in team.Squads)
     {
         RTSSquad.Serialize(s, squad);
     }
 }
Example #2
0
 public static void Serialize(BinaryWriter s, RTSBuilding e)
 {
     s.Write(e.Data.Index);
     s.Write(e.UUID);
     s.Write(e.State);
     s.Write(e.ViewDirection);
     s.Write(e.GridPosition);
     s.Write(e.Height);
     if (e.Target != null)
     {
         s.Write(true);
         s.Write(e.Target.UUID);
     }
     else
     {
         s.Write(false);
     }
     s.Write(e.Health);
     for (int i = 0; i < GameState.MAX_PLAYERS; i++)
     {
         s.Write(e.viewedInfo.Get(i));
     }
     if (e.ActionController != null)
     {
         s.Write(true);
         e.ActionController.Serialize(s);
     }
     else
     {
         s.Write(false);
     }
 }
Example #3
0
 private void OnBuildingFinished(RTSBuilding b)
 {
     if (b.Data.PopCapChange != 0)
     {
         PopulationCap += b.Data.PopCapChange;
     }
 }
 public BarracksController(AI input, RTSBuilding b)
 {
     army = new List<IEntity>();
     sentArmy = new List<IEntity>();
     AIInput = input;
     barracks = b;
     currentTarget = null;
     active = false;
 }
        public override void Init(RTSEngine.Data.GameState s, RTSEngine.Controllers.GameplayController c, object args)
        {
            cc = unit.CombatController;
            mc = unit.MovementController;

            unit.TargetingOrders = BehaviorFSM.TargetPassively;
            unit.CombatOrders = BehaviorFSM.UseMeleeAttack;
            unit.MovementOrders = BehaviorFSM.JustMove;
            SetState(BehaviorFSM.Rest);

            teamIndex = unit.Team.Index;

            // Worker Specific Stuff
            targetResource = null;
            targetDistro = null;
            depositing = false;
        }
Example #6
0
        // Building Addition And Removal
        public RTSBuilding AddBuilding(int type, Vector2 pos)
        {
            // Check For Building Type Existence
            RTSBuildingData data = Race.Buildings[type];

            if (data == null)
            {
                return(null);
            }

            // Check For Building Cap
            if (data.CurrentCount >= data.MaxCount)
            {
                return(null);
            }

            // Check For Capital Cost
            if (data.CapitalCost > Capital)
            {
                return(null);
            }

            // Produce Building
            Capital -= data.CapitalCost;
            data.CurrentCount++;

            RTSBuilding b = new RTSBuilding(this, data, pos);

            b.OnBuildingFinished += OnBuildingFinished;
            b.ActionController    = data.DefaultActionController.CreateInstance <ACBuildingActionController>();
            for (int i = 0; i < data.DefaultButtonControllers.Count; i++)
            {
                b.AddButton(data.DefaultButtonControllers[i].CreateInstance <ACBuildingButtonController>());
            }
            Buildings.Add(b);
            if (OnBuildingSpawn != null)
            {
                OnBuildingSpawn(b);
            }
            return(b);
        }
Example #7
0
        public static RTSBuilding Deserialize(BinaryReader s, RTSTeam team, out int?target)
        {
            int         type = s.ReadInt32();
            RTSBuilding e    = team.AddBuilding(type, Vector2.Zero);

            if (e == null)
            {
                throw new Exception("Could Not Create A Building That Was Previously Created");
            }
            e.UUID          = s.ReadInt32();
            e.State         = s.ReadInt32();
            e.ViewDirection = s.ReadVector2();
            e.GridPosition  = s.ReadVector2();
            e.Height        = s.ReadSingle();
            if (s.ReadBoolean())
            {
                target = s.ReadInt32();
            }
            else
            {
                target = null;
            }
            e.Health = s.ReadInt32();
            for (int i = 0; i < GameState.MAX_PLAYERS; i++)
            {
                e.viewedInfo.Set(i, s.ReadBoolean());
            }
            if (s.ReadBoolean())
            {
                if (e.ActionController != null)
                {
                    e.ActionController.Deserialize(s);
                }
            }
            else
            {
                e.ActionController = null;
            }
            return(e);
        }
Example #8
0
 public static void Serialize(BinaryWriter s, RTSBuilding e)
 {
     s.Write(e.Data.Index);
     s.Write(e.UUID);
     s.Write(e.State);
     s.Write(e.ViewDirection);
     s.Write(e.GridPosition);
     s.Write(e.Height);
     if(e.Target != null) {
         s.Write(true);
         s.Write(e.Target.UUID);
     }
     else {
         s.Write(false);
     }
     s.Write(e.Health);
     for(int i = 0; i < GameState.MAX_PLAYERS; i++) {
         s.Write(e.viewedInfo.Get(i));
     }
     if(e.ActionController != null) {
         s.Write(true);
         e.ActionController.Serialize(s);
     }
     else {
         s.Write(false);
     }
 }
 public override void SetBuilding(RTSBuilding b)
 {
     base.SetBuilding(b);
 }
 public void OnBuildingSpawn(RTSBuilding b)
 {
     //DevConsole.AddCommand("added barracks");
     barracksControllers.Add(new BarracksController(this, b));
     Team.Buildings.Add(b);
     b.OnDestruction += OnBuildingDestruction;
 }
 public BTaskBuildingDecision(GameState g, RTSBuilding b)
     : base(1)
 {
     building = b;
     state = g;
 }
        private void AddTask(GameState s, RTSBuilding building)
        {
            // Init The Building
            if(building.ActionController != null) building.ActionController.Init(s, this, building.Data.ActionControllerInitArgs);
            for(int i = 0; i < building.ButtonControllers.Count; i++)
                building.ButtonControllers[i].Init(s, this, building.Data.DefaultButtonControllerInitArgs[i]);

            var btu = new BTaskBuildingDecision(s, building);
            building.OnDestruction += (o) => {
                tbEntityDecisions.RemoveTask(btu);
            };
            tbEntityDecisions.AddTask(btu);
        }
Example #13
0
        public EnemyBuildingUpdater(GameState s, int tIndex, ViewedBuilding _vb, RTSBuilding b)
            : base(1)
        {
            state = s;
            teamIndex = tIndex;
            Added = false;
            isDead = false;
            vb = _vb;
            building = b;

            if(b != null) b.OnDestruction += OnBuildingDeath;
            else isDead = true;

            RTSBuildingData data = state.teams[vb.Team].Race.Buildings[vb.Type];
            grids = new Point[data.GridSize.X * data.GridSize.Y];
            Point p = vb.CellPoint;
            int pi = 0;
            for(int y = 0; y < data.GridSize.Y; y++) {
                for(int x = 0; x < data.GridSize.X; x++) {
                    grids[pi++] = new Point(p.X + x, p.Y + y);
                }
            }
        }
Example #14
0
 public static float GetBuildRatio(this RTSBuilding b)
 {
     return((float)(b.Data.BuildAmount - b.BuildAmountLeft) / (float)b.Data.BuildAmount);
 }
Example #15
0
        // Building Addition And Removal
        public RTSBuilding AddBuilding(int type, Vector2 pos)
        {
            // Check For Building Type Existence
            RTSBuildingData data = Race.Buildings[type];
            if(data == null) return null;

            // Check For Building Cap
            if(data.CurrentCount >= data.MaxCount) return null;

            // Check For Capital Cost
            if(data.CapitalCost > Capital) return null;

            // Produce Building
            Capital -= data.CapitalCost;
            data.CurrentCount++;

            RTSBuilding b = new RTSBuilding(this, data, pos);
            b.OnBuildingFinished += OnBuildingFinished;
            b.ActionController = data.DefaultActionController.CreateInstance<ACBuildingActionController>();
            for(int i = 0; i < data.DefaultButtonControllers.Count; i++) {
                b.AddButton(data.DefaultButtonControllers[i].CreateInstance<ACBuildingButtonController>());
            }
            Buildings.Add(b);
            if(OnBuildingSpawn != null)
                OnBuildingSpawn(b);
            return b;
        }
Example #16
0
 private void OnBuildingFinished(RTSBuilding b)
 {
     if(b.Data.PopCapChange != 0)
         PopulationCap += b.Data.PopCapChange;
 }
Example #17
0
        public static RTSTeam Deserialize(BinaryReader s, int index, GameState state)
        {
            int     t    = s.ReadInt32();
            RTSTeam team = new RTSTeam(index, t);

            team.Race = RTSRace.Deserialize(s, state);
            if (s.ReadBoolean())
            {
                string it = s.ReadString();
                team.Input = state.Scripts[it].CreateInstance <ACInputController>();
                team.Input.Deserialize(s);
                team.Input.Init(state, index, null);
            }

            RTSColorScheme scheme = new RTSColorScheme();

            scheme.Name      = s.ReadString();
            scheme.Primary   = s.ReadVector3();
            scheme.Secondary = s.ReadVector3();
            scheme.Tertiary  = s.ReadVector3();
            team.ColorScheme = scheme;

            int?       target;
            var        du = new Dictionary <int, RTSUnit>();
            List <int> su;

            int         c = s.ReadInt32();
            RTSBuilding building;

            for (int i = 0; i < c; i++)
            {
                building = RTSBuilding.Deserialize(s, team, out target);
                team.buildings.Add(building);
                if (target.HasValue)
                {
                    // TODO: Add A Target Binding
                }
                state.CGrid.Add(building);
            }

            c = s.ReadInt32();
            RTSUnit unit;

            for (int i = 0; i < c; i++)
            {
                unit = RTSUnit.Deserialize(s, team, out target);
                du.Add(unit.UUID, unit);
                team.units.Add(unit);
                if (target.HasValue)
                {
                    // TODO: Add A Target Binding
                }
            }

            c = s.ReadInt32();
            RTSSquad squad;

            for (int i = 0; i < c; i++)
            {
                squad = RTSSquad.Deserialize(s, team, out su);
                team.squads.Add(squad);
                foreach (int uuid in su)
                {
                    if (du.TryGetValue(uuid, out unit))
                    {
                        squad.Add(unit);
                    }
                    else
                    {
                        throw new Exception("Could Not Find A Unit With The Specified UUID");
                    }
                }
            }
            return(team);
        }
Example #18
0
 private void OnBuildingDeath(IEntity o)
 {
     isDead = true;
     o.OnDestruction -= OnBuildingDeath;
     building = null;
 }
Example #19
0
 void DecideWorkerAction(GameState g, float dt)
 {
     if (unit.Target == null)
         SetState(BehaviorFSM.Rest);
     RTSBuilding targetB = unit.Target as RTSBuilding;
     // If Target Is On The Same Team -> Might Be A Depositable Building, Etc.
     if (unit.Target.Team.Index == teamIndex) {
         if(targetB != null) {
             // Prioritize Building Unbuilt Buildings
             if(!targetB.IsBuilt) {
                 SetState(BehaviorFSM.Build);
             }
             // If Target Is Player's Depositable Building
             else if(targetB.Data.Depositable) {
                 targetDistro = targetB;
                 SetState(BehaviorFSM.Harvest); // TODO: Make This Harvest Only Once
                 depositing = true;
             }
             // If Target Is The Player's Undepositable Building, Repair
             else {
                 SetState(BehaviorFSM.Repair);
             }
         }
     }
     // If Target Is On Another Team
     else {
         if(targetB != null) {
             if (targetB.IsResource) {
                 SetState(BehaviorFSM.Harvest);
                 depositing = false;
             }
         }
         else {
             SetState(BehaviorFSM.CombatMelee);
         }
     }
 }
 private void AddTask(GameState s, RTSBuilding building, int fTeam, int type)
 {
     AddTask(s, building);
     ViewedBuilding vb = new ViewedBuilding();
     vb.Team = fTeam;
     vb.Type = type;
     vb.ViewDirection = building.ViewDirection;
     vb.WorldPosition = building.WorldPosition;
     vb.CellPoint = HashHelper.Hash(building.GridPosition, s.CGrid.numCells, s.CGrid.size);
     for(int i = 0; i < s.teams.Length; i++) {
         if(i == fTeam || s.teams[i] == null) continue;
         var ebu = new EnemyBuildingUpdater(s, i, vb, building);
         s.tbMemBuildings.AddTask(ebu);
     }
 }
Example #21
0
 void DSHarvest(GameState g, float dt)
 {
     // Look For A Distro
     if(unit.Resources > unit.Data.CarryingCapacity) {
         // Always Go To Nearest Distro
         targetDistro = GetClosestDepository();
         unit.Target = targetDistro;
         SetState(BehaviorFSM.Rest);
     }
     else if(unit.Target == null || !unit.Target.IsAlive) {
         // Look For More Harvestable Stuff
         if(targetResource == null) // Only Target A New Resource If The Old One Is Bad
             targetResource = GetClosestResource(g);
         unit.Target = GetClosestResource(g);
         if(unit.Target == null) { // No Resources Found
             targetDistro = GetClosestDepository();
             unit.Target = targetDistro;
         }
         SetState(BehaviorFSM.Rest);
     }
     depositing = unit.Target == targetDistro;
 }
 public static bool IsBuildingDead(RTSBuilding b)
 {
     return IsEntityDead(b);
 }
 private int ClosestBuilding(RTSBuilding b1, RTSBuilding b2)
 {
     BoundingBox bb1 = b1.BBox;
     BoundingBox bb2 = b2.BBox;
     float d1 = (0.5f * (bb1.Max + bb1.Min) - Camera.CamOrigin).LengthSquared();
     float d2 = (0.5f * (bb2.Max + bb2.Min) - Camera.CamOrigin).LengthSquared();
     return d1.CompareTo(d2);
 }