public override void Init(GameState s, GameplayController c)
 {
     ActivityInterval = 10;
     ExtractAmount = 10;
     currTime = 0;
     Enabled = true;
 }
示例#2
0
        public override void ApplyAction(GameState g, float dt)
        {
            if(resources.Count < 1) return;

            if(g.CurrentFrame % 300 == 0) {
                g.AddParticle(new AlertParticle(
                    building.WorldPosition + Vector3.Up * 0.2f, 0.1f, Color.White,
                    building.WorldPosition + Vector3.Up * 0.2f, harvestradius * 1.4f, Color.Transparent,
                    g.TotalGameTime, 2f
                    ));
                foreach(var b in resources) {
                    if(r.NextDouble() > 0.5) {
                        building.Team.Input.AddEvent(new CapitalEvent(
                            building.Team.Index,
                            b.Data.Index == 0 ? 5 : 20
                            ));
                        building.Team.Input.AddEvent(new DamageEvent(
                            building.Team.Index,
                            b.UUID,
                            10
                            ));
                        g.AddParticle(new AlertParticle(
                            b.WorldPosition + Vector3.Up * 0.2f, 2f, Color.White,
                            b.WorldPosition + Vector3.Up * 3.2f, 1f, Color.Black,
                            g.TotalGameTime, 2f
                            ));
                    }
                }
            }
        }
 public override void Init(GameState s, GameplayController c, object args)
 {
     ButtonQueue = new Queue<ACBuildingButtonController>();
     QueueTimer = float.MaxValue;
     CurrentButton = null;
     QueueCap = 5;
 }
        public override void ApplyAction(GameState g, float dt)
        {
            if (CurrentButton != null) {
                // If The Unit Is Still Being Produced
                if (QueueTimer != float.MaxValue && QueueTimer > 0) {
                    QueueTimer -= dt;
                }
                // If Finished Building The Unit
                if(QueueTimer <= 0 && CurrentButton.CanFinish(g)) {
                    CurrentButton.OnQueueFinished(g);
                    QueueTimer = float.MaxValue;
                    CurrentButton = null;
                }
            }

            // Add New Buttons To The Queue
            for(int i = 0; i < building.ButtonControllers.Count; i++) {
                int ec = building.ButtonControllers[i].GetEnqueueCount();
                while(ec > 0) {
                    ButtonQueue.Enqueue(building.ButtonControllers[i]);
                    ec--;
                }
            }

            // Get New Button
            if(CurrentButton == null && ButtonQueue.Count > 0) {
                CurrentButton = ButtonQueue.Dequeue();
                QueueTimer = CurrentButton.QueueTime;
            }
        }
 public override void ApplyAction(GameState g, float dt)
 {
     if (Enabled) {
         currTime += dt;
         if (currTime >= ActivityInterval) {
             currTime = 0;
             building.Team.Input.AddEvent(new CapitalEvent(building.Team.Index, ExtractAmount));
             building.Team.Input.AddEvent(new ImpactEvent(building.Team.Index, building.GridPosition, ExtractAmount));
         }
     }
 }
示例#6
0
        public override int? GetVictoriousTeam(GameState s)
        {
            // Mercy Time
            if(s.CurrentFrame < 100) return null;

            // If All The Buildings And Units Are Destroyed
            foreach(var e in pTeam.Units) {
                if(e.WorldPosition.Y < targetHeight)
                    return null;
            }
            return 1;
        }
示例#7
0
 public override void Init(GameState s, GameplayController c, object initArgs)
 {
     resources = new List<RTSBuilding>();
     Point p = HashHelper.Hash(building.GridStartPos, s.CGrid.numCells, s.CGrid.size);
     harvestradius = 5;
     hStart = new Point(
         Math.Max(0, p.X - harvestradius),
         Math.Max(0, p.Y - harvestradius)
         );
     hEnd = new Point(
         Math.Min(s.CGrid.numCells.X - 1, p.X + harvestradius),
         Math.Min(s.CGrid.numCells.Y - 1, p.Y + harvestradius)
         );
 }
示例#8
0
        public override void DecideAction(GameState g, float dt)
        {
            resources = new List<RTSBuilding>();
            if(!building.IsBuilt) return;

            for(int x = hStart.X; x <= hEnd.X; x++) {
                for(int y = hStart.Y; y <= hEnd.Y; y++) {
                    var b = g.CGrid.EStatic[x, y];
                    if(b != null && b.IsResource && !resources.Contains(b)) {
                        resources.Add(b);
                    }
                }
            }
        }
示例#9
0
 public Pathfinder(GameState g)
 {
     // A*
     gameState = g;
     prev = new Point[World.numCells.X, World.numCells.Y];
     fScore = new int[World.numCells.X, World.numCells.Y];
     gScore = new int[World.numCells.X, World.numCells.Y];
     // Threading
     running = true;
     queries = new ConcurrentQueue<PathQuery>();
     thread = new Thread(WorkThread);
     thread.Priority = ThreadPriority.Normal;
     thread.IsBackground = true;
     thread.Start();
 }
示例#10
0
        public override void Load(GameState s, DirectoryInfo mapDir)
        {
            // Give The Player Team Starting Capital
            pTeam = null;
            for(int i = 0; i < s.activeTeams.Length; i++) {
                var at = s.activeTeams[i];
                if(pTeam == null && at.Team.Type == RTSInputType.Player) {
                    pTeam = at.Team;
                    pTeam.Input.AddEvent(new CapitalEvent(pTeam.Index, 1000));
                    pTeam.PopulationCap = 100;
                }
            }

            float[] heights = new float[s.CGrid.numCells.X * s.CGrid.numCells.Y];
            Vector2[] p = new Vector2[heights.Length];
            for(int y = 0, i = 0; y < s.CGrid.numCells.Y; y++) {
                for(int x = 0; x < s.CGrid.numCells.X; x++) {
                    p[i] = new Vector2(x + 0.5f, y + 0.5f) * s.CGrid.cellSize;
                    heights[i] = s.CGrid.HeightAt(p[i]);
                    i++;
                }
            }
            Array.Sort(heights, p, 0, heights.Length);
            int cS = 1, cE = 1;
            while(cS < heights.Length && heights[cS] == heights[0])
                cS++;
            while(cE < heights.Length && heights[heights.Length - 1 - cE] == heights[heights.Length - 1])
                cE++;
            Random r = new Random();
            Vector2 spawnPos = p[r.Next(cS)];
            int ti = heights.Length - 1 - r.Next(cE);
            targetHeight = heights[ti] - 0.5f;
            fireLocation = new Vector3(p[ti].X, targetHeight, p[ti].Y);

            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            pTeam.Input.AddEvent(new SpawnUnitEvent(pTeam.Index, 0, spawnPos));
            DevConsole.AddCommand("franz ferdinand");
            pTeam.Input.OnNewSelection += (ic, ns) => {
                if(ns.Count < 1) return;
                s.SendPopup(@"Packs\presets\Tutorial0\2.png", new Rectangle(10, 60, 400, 300));
                System.Threading.Interlocked.Exchange(ref state, 3);
                s.AddParticle(new AlertParticle(fireLocation, 2, Color.Transparent, fireLocation + Vector3.Up * 3, 1, Color.OrangeRed, s.TotalGameTime, 4f));
            };
            state = 0;
        }
示例#11
0
        public static void BuildLocal(GameState state, EngineLoadData eld, DirectoryInfo root, Dictionary<string, FileInfo> races)
        {
            // Copy Over All The Scripts
            foreach(KeyValuePair<string, ReflectedScript> kv in Scripts)
                state.Scripts.Add(kv.Key, kv.Value);

            // Load The Map
            BuildMap(state, eld.MapFile);

            BuildTeams(state, eld, races);
            state.UpdateActiveTeams();

            // Hook Building Spawn Events To Collision Grid
            foreach(var team in (from t in state.activeTeams select t.Team)) {
                team.OnBuildingSpawn += state.CGrid.OnBuildingSpawn;
            }
        }
示例#12
0
        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;
        }
示例#13
0
 public void FindTarget(GameState g, float dt)
 {
     IEntity target = null;
     // If enemy unit is around, target him automatically
     float minDistSq = unit.Data.BaseCombatData.MaxRange;
     minDistSq *= minDistSq;
     foreach (IndexedTeam t in g.activeTeams.ToArray()) {
         RTSTeam team = t.Team;
         if(teamIndex != t.Index && team.Input.Type != RTSInputType.Environment) { // Enemy team check
             foreach (RTSUnit enemy in team.Units.ToArray()) {
                 if(g.CGrid.GetFogOfWar(enemy.GridPosition, teamIndex) != FogOfWar.Active)
                     continue;
                 if(!enemy.IsAlive) continue;
                 float d = (enemy.GridPosition - unit.GridPosition).LengthSquared();
                 if (d <= minDistSq) {
                     target = enemy;
                     minDistSq = d;
                 }
             }
         }
     }
     // If no unit target was found, search for building target
     if(target == null) {
         minDistSq = unit.Data.BaseCombatData.MaxRange;
         minDistSq *= minDistSq;
         foreach(IndexedTeam t in g.activeTeams.ToArray()) {
             RTSTeam team = t.Team;
             if(teamIndex != t.Index && team.Input.Type != RTSInputType.Environment) { // Enemy team check
                 foreach(RTSBuilding enemy in g.teams[t.Index].Buildings.ToArray()) {
                     if(g.CGrid.GetFogOfWar(enemy.GridPosition, teamIndex) != FogOfWar.Active)
                         continue;
                     if(!enemy.IsAlive) continue;
                     float d = (enemy.GridPosition - unit.GridPosition).LengthSquared();
                     if (d <= minDistSq) {
                         target = enemy;
                         minDistSq = d;
                     }
                 }
             }
         }
     }
     unit.Target = target;
 }
示例#14
0
        public override void Update(GameState s, float dt)
        {
            if(lastState != unit.State) {
                // A New Animation State If Provided
                SetAnimation(unit.State);
                if(lastState == BehaviorFSM.None) {
                    rt = r.Next(120, 350) / 10f;
                }
            }

            // Save Last State
            lastState = unit.State;

            // Step The Current Animation
            if(alCurrent != null) {
                alCurrent.Step(dt);
                AnimationFrame = alCurrent.CurrentFrame;
            }

            if(lastState == BehaviorFSM.None) {
                // Check For A Random Animation
                if(alCurrent == null) {
                    rt -= dt;
                    if(rt <= 0) {
                        rt = r.Next(120, 350) / 10f;
                        alCurrent = alRest;
                        alCurrent.Restart(false);
                    }
                }
                else {
                    // Check If At The End Of The Loop
                    if(AnimationFrame == alCurrent.EndFrame) {
                        alCurrent = null;
                        rt = r.Next(120, 350) / 10f;
                    }
                }
            }
        }
 public BTaskUnitDecision(GameState g, RTSUnit u)
     : base(1)
 {
     unit = u;
     state = g;
 }
 public void BeginPlaying(GameState s)
 {
     // Start The Various Threaded Elements
     for(int ti = 0; ti < s.activeTeams.Length; ti++) {
         s.activeTeams[ti].Team.Input.Begin();
     }
     s.VoxState.VWorkPool.Start(1, System.Threading.ThreadPriority.BelowNormal);
     s.gtC.Start(s);
 }
 public BTaskBuildingDecision(GameState g, RTSBuilding b)
     : base(1)
 {
     building = b;
     state = g;
 }
 public BTaskSquadDecision(GameState g, RTSSquad s)
     : base(s.Units.Count)
 {
     squad = s;
     state = g;
 }
        // Physics Stage
        private void ResolvePhysics(GameState s, float dt)
        {
            RTSTeam team;

            // Initialize hash grid
            var hashGrid = s.CGrid;
            hashGrid.ClearDynamic();

            // Move Geometry To The Unit's Location and hash into the grid
            for(int ti = 0; ti < s.activeTeams.Length; ti++) {
                team = s.activeTeams[ti].Team;
                foreach(RTSUnit unit in team.Units) {
                    unit.CollisionGeometry.Center = unit.GridPosition;
                    hashGrid.Add(unit);
                }
            }

            // Use hash grid to perform collision using 3 by 3 grid around the geometry
            for(int i = 0; i < hashGrid.ActiveGrids.Count; i++) {
                Point p = hashGrid.ActiveGrids[i];
                hashGrid.HandleGridCollision(p.X, p.Y);
                hashGrid.HandleGridCollision(p.X, p.Y, -1, -1);
                hashGrid.HandleGridCollision(p.X, p.Y, -1, 0);
                hashGrid.HandleGridCollision(p.X, p.Y, -1, 1);
                hashGrid.HandleGridCollision(p.X, p.Y, 0, -1);
                hashGrid.HandleGridCollision(p.X, p.Y, 0, 1);
                hashGrid.HandleGridCollision(p.X, p.Y, 1, -1);
                hashGrid.HandleGridCollision(p.X, p.Y, 1, 0);
                hashGrid.HandleGridCollision(p.X, p.Y, 1, 1);
            }

            // Move Unit's Location To The Geometry After Heightmap Collision
            for(int ti = 0; ti < s.activeTeams.Length; ti++) {
                team = s.activeTeams[ti].Team;
                foreach(RTSUnit unit in team.Units) {
                    CollisionController.CollideHeightmap(unit.CollisionGeometry, s.CGrid);
                    unit.GridPosition = unit.CollisionGeometry.Center;
                    unit.Height = unit.CollisionGeometry.Height;

                    // Check To Make Sure Unit Is Inside The Map
                    if(unit.GridPosition.X < 0 || unit.GridPosition.X > s.CGrid.size.X ||
                       unit.GridPosition.Y < 0 || unit.GridPosition.Y > s.CGrid.size.Y
                       ) {
                        // Damage The Unit If It Is Outside
                        unit.Damage(1);
                    }
                }
            }
        }
 private void SendSquadQuery(GameState s, RTSSquad squad, GameInputEvent e)
 {
     squad.RecalculateGridPosition();
     Vector2 start = squad.GridPosition;
     var swe = e as SetWayPointEvent;
     var ste = e as SetTargetEvent;
     Vector2 goal = start;
     if(swe != null)
         goal = swe.Waypoint;
     else if(ste != null && ste.Target != null)
         goal = ste.Target.GridPosition;
     float minDistSq = float.MaxValue;
     for(int u = 0; u < squad.Units.Count; u++) {
         RTSUnit unit = squad.Units[u];
         float distSq = (goal - unit.GridPosition).LengthSquared();
         if(distSq < minDistSq) {
             minDistSq = distSq;
             start = unit.GridPosition;
         }
     }
     var query = pathfinder.ReissuePathQuery(new PathQuery(start, goal, e.Team), start, goal, e.Team);
     squadQueries.Add(new SquadQuery(squad, query));
 }
 // Cleanup Stage
 private void Cleanup(GameState s, float dt)
 {
     // Remove All Dead Entities
     for(int ti = 0; ti < s.activeTeams.Length; ti++) {
         RTSTeam team = s.activeTeams[ti].Team;
         team.RemoveAll(IsUnitDead, (i) => { s.EntityHashSet.Remove(i); });
         team.RemoveAll(IsBuildingDead, (i) => { s.EntityHashSet.Remove(i); });
         team.RemoveAll(IsSquadEmpty);
     }
 }
        // Logic Stage
        private void ApplyLogic(GameState s, float dt)
        {
            RTSTeam team = null;

            // Apply Dev Commands
            int c = commands.Count;
            for(int i = 0; i < c; i++) {
                var comm = commands.Dequeue();
                switch(comm.Type) {
                    case DevCommandType.Spawn:
                        ApplyLogic(s, dt, comm as DevCommandSpawn);
                        break;
                    case DevCommandType.StopMotion:
                        ApplyLogic(s, dt, comm as DevCommandStopMotion);
                        break;
                    case DevCommandType.KillUnits:
                        ApplyLogic(s, dt, comm as DevCommandKillUnits);
                        break;
                    case DevCommandType.KillBuildings:
                        ApplyLogic(s, dt, comm as DevCommandKillBuildings);
                        break;
                    case DevCommandType.FOW:
                        ApplyLogic(s, dt, comm as DevCommandFOW);
                        break;
                    case DevCommandType.Save:
                        ApplyLogic(s, dt, comm as DevCommandSave);
                        break;
                    case DevCommandType.Capital:
                        ApplyLogic(s, dt, comm as DevCommandCapital);
                        break;
                }
            }

            // Find Decisions For Currently Budgeted Tasks
            tbSquadDecisions.DoTasks(dt);
            tbEntityDecisions.DoTasks(dt);

            // Apply Decisions For Squads
            for(int ti = 0; ti < s.activeTeams.Length; ti++) {
                team = s.activeTeams[ti].Team;
                for(int i = 0; i < team.Squads.Count; i++)
                    if(team.Squads[i].ActionController != null)
                        team.Squads[i].ActionController.ApplyAction(s, dt);
            }
            // Apply Decisions For Units And Buildings
            for(int ti = 0; ti < s.activeTeams.Length; ti++) {
                team = s.activeTeams[ti].Team;
                for(int i = 0; i < team.Units.Count; i++)
                    if(team.Units[i].ActionController != null)
                        team.Units[i].ActionController.ApplyAction(s, dt);
                for(int i = 0; i < team.Buildings.Count; i++)
                    if(team.Buildings[i].ActionController != null)
                        team.Buildings[i].ActionController.ApplyAction(s, dt);
            }

            // Calculate FOW
            tbFOWCalculations.DoTasks(dt);

            // Calculate Memorizations
            if(s.CurrentFrame % GameState.BUILDING_MEMORIZATION_LATENCY == 0)
                s.tbMemBuildings.ResortBins();
            s.tbMemBuildings.DoTasks(dt);
        }
 private void ApplyLogic(GameState s, float dt, DevCommandSave c)
 {
     GameEngine.Save(s, c.file.FullName);
 }
 private void ApplyLogic(GameState s, float dt, DevCommandCapital c)
 {
     foreach(var t in s.activeTeams) {
         t.Team.Input.AddEvent(new CapitalEvent(t.Team.Index, c.change));
     }
 }
 private void ApplyLogic(GameState s, float dt, DevCommandFOW c)
 {
     foreach(var task in tbFOWCalculations.Tasks) {
         var t = task as FOWTask;
         t.SetAllFOW(c.fow, s.CGrid);
     }
 }
 private void ApplyLogic(GameState s, float dt, DevCommandKillBuildings c)
 {
     RTSTeam team;
     for(int ti = 0; ti < s.activeTeams.Length; ti++) {
         team = s.activeTeams[ti].Team;
         foreach(var building in team.Buildings) {
             building.Damage(9001); // OVER 9000
         }
     }
 }
 private void ApplyLogic(GameState s, float dt, DevCommandKillUnits c)
 {
     RTSTeam team;
     for(int ti = 0; ti < s.activeTeams.Length; ti++) {
         team = s.activeTeams[ti].Team;
         foreach(var unit in team.Units) {
             unit.Damage(9001); // OVER 9000
         }
     }
 }
示例#28
0
 public override void Init(GameState s, GameplayController c, object args)
 {
 }
 // Input Stage
 private void ResolveInput(GameState s, float dt)
 {
     events = new LinkedList<GameInputEvent>();
     for(int i = 0; i < s.activeTeams.Length; i++) {
         var team = s.activeTeams[i].Team;
         if(team.Input != null)
             team.Input.AppendEvents(events);
     }
 }
 private void ApplyLogic(GameState s, float dt, DevCommandStopMotion c)
 {
     // TODO: Deprecate ?
     for(int z = 0; z < s.CGrid.numCells.Y; z++) {
         for(int x = 0; x < s.CGrid.numCells.X; x++) {
             Point p = new Point(x, z);
             Vector3 pos = new Vector3(x * 2 + 1, 0, z * 2 + 1);
             pos.Y = s.CGrid.HeightAt(new Vector2(pos.X, pos.Z));
             if(!s.CGrid.CanMoveTo(p, CollisionGrid.Direction.XP)) {
                 s.AddParticle(new LightningParticle(
                     pos + Vector3.UnitX, 1f, 12f, MathHelper.PiOver2,
                     5f, 1, Color.LightBlue
                     ));
             }
             if(!s.CGrid.CanMoveTo(p, CollisionGrid.Direction.XN)) {
                 s.AddParticle(new LightningParticle(
                     pos - Vector3.UnitX, 1f, 12f, MathHelper.PiOver2,
                     5f, 1, Color.LightBlue
                     ));
             }
             if(!s.CGrid.CanMoveTo(p, CollisionGrid.Direction.ZP)) {
                 s.AddParticle(new LightningParticle(
                     pos + Vector3.UnitZ, 1f, 12f, 0f,
                     5f, 1, Color.LightBlue
                     ));
             }
             if(!s.CGrid.CanMoveTo(p, CollisionGrid.Direction.ZN)) {
                 s.AddParticle(new LightningParticle(
                     pos - Vector3.UnitZ, 1f, 12f, 0f,
                     5f, 1, Color.LightBlue
                     ));
             }
         }
     }
 }
 private void ApplyLogic(GameState s, float dt, DevCommandSpawn c)
 {
     // Multiple Spawn Events
     SpawnUnitEvent e = new SpawnUnitEvent(c.TeamIndex, c.UnitIndex, new Vector2(c.X, c.Z));
     for(int i = 0; i < c.Count; i++) ApplyInput(s, dt, e);
 }