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 )); } } } }
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 SetNetForceAndWaypoint(GameState g) { CollisionGrid cg = g.CGrid; // TODO: Make The Routine Below Fast Enough To Use //int tempIdx = 0; //Vector2 waypoint = Waypoints[tempIdx]; //float r = unit.CollisionGeometry.BoundingRadius; //while(IsValid(tempIdx)) { // // Get The Waypoint Closest To The Goal That This Unit Can Straight-Shot // if(CoastIsClear(unit.GridPosition, waypoint, r, r, cg)) { // CurrentWaypointIndex = tempIdx; // break; // } // tempIdx++; //} Vector2 waypoint = Waypoints[CurrentWaypointIndex]; #if DEBUG Vector2 first = Waypoints[Waypoints.Count - 1]; Vector3 oFirst = new Vector3(first.X, g.CGrid.HeightAt(first), first.Y); g.AddParticle(new AlertParticle(oFirst, 1f, Color.Red, oFirst + Vector3.Up, 0.2f, Color.Green, g.TotalGameTime, 1f)); Vector3 oWP = new Vector3(waypoint.X, g.CGrid.HeightAt(waypoint), waypoint.Y); g.AddParticle(new AlertParticle(oWP, 1f, Color.Blue, oWP + Vector3.Up, 0.2f, Color.Purple, g.TotalGameTime, 3f)); #endif if(Query != null && !Query.IsOld && Query.IsComplete) { Query.IsOld = true; // Only Do This Once Per Query Waypoints = Query.waypoints; CurrentWaypointIndex = Waypoints.Count - 1; } // Set Net Force... NetForce = pForce * UnitForce(unit.GridPosition, waypoint); Point unitCell = HashHelper.Hash(unit.GridPosition, cg.numCells, cg.size); //// Apply Forces From Other Units In This One's Cell //foreach(var otherUnit in cg.EDynamic[unitCell.X, unitCell.Y]) { // NetForce += dForce * UnitForce(unit.GridPosition, otherUnit.GridPosition); //} //// Apply Forces From Buildings And Other Units Near This One //foreach(Point n in Pathfinder.Neighborhood(unitCell)) { // RTSBuilding b = cg.EStatic[n.X, n.Y]; // if(b != null) // NetForce += sForce * UnitForce(unit.GridPosition, b.GridPosition); // foreach(var otherUnit in cg.EDynamic[n.X, n.Y]) { // NetForce += sForce * UnitForce(unit.GridPosition, otherUnit.GridPosition); // } //} // Set Waypoint... Point currWaypointCell = HashHelper.Hash(waypoint, cg.numCells, cg.size); float sqr2 = unit.Squad.Radius(); sqr2 *= sqr2; bool inGoalCell = unitCell.X == currWaypointCell.X && unitCell.Y == currWaypointCell.Y; bool withinCellDistSq = (waypoint - unit.GridPosition).LengthSquared() < cg.cellSize; bool withinSquad = (waypoint - unit.GridPosition).LengthSquared() < 1.5 * sqr2; if(inGoalCell || (!wasStuck && (withinSquad || withinCellDistSq))) { CurrentWaypointIndex--; if(CurrentWaypointIndex < 0) Waypoints = null; wasStuck = false; } }
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; }