Refactoring + cnc weap
This commit is contained in:
@@ -76,18 +76,20 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
this.self = init.self;
|
this.self = init.self;
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
if (init.Contains<LocationInit>())
|
|
||||||
this.__fromCell = this.__toCell = init.Get<LocationInit,int2>();
|
|
||||||
|
|
||||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
|
||||||
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
|
||||||
|
|
||||||
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
||||||
uim = self.World.WorldActor.traits.Get<UnitInfluence>();
|
uim = self.World.WorldActor.traits.Get<UnitInfluence>();
|
||||||
bim = self.World.WorldActor.traits.Get<BuildingInfluence>();
|
bim = self.World.WorldActor.traits.Get<BuildingInfluence>();
|
||||||
canShareCell = self.traits.Contains<SharesCell>();
|
canShareCell = self.traits.Contains<SharesCell>();
|
||||||
|
|
||||||
|
if (init.Contains<LocationInit>())
|
||||||
|
{
|
||||||
|
this.__fromCell = this.__toCell = init.Get<LocationInit,int2>();
|
||||||
AddInfluence();
|
AddInfluence();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
||||||
|
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
||||||
|
|
||||||
TerrainCost = new Dictionary<string, float>();
|
TerrainCost = new Dictionary<string, float>();
|
||||||
TerrainSpeed = new Dictionary<string, float>();
|
TerrainSpeed = new Dictionary<string, float>();
|
||||||
|
|||||||
@@ -43,22 +43,19 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void DoProduction(Actor self, Actor newUnit, int2 exit, float2 spawn)
|
public void DoProduction(Actor self, Actor newUnit, int2 exit, float2 spawn)
|
||||||
{
|
{
|
||||||
Game.Debug("Creating actor {0}".F(newUnit.Info.Name));
|
var move = newUnit.traits.Get<IMove>();
|
||||||
|
var facing = newUnit.traits.GetOrDefault<IFacing>();
|
||||||
var mobile = newUnit.traits.Get<Mobile>();
|
|
||||||
|
|
||||||
// Unit can be built; add to the world
|
|
||||||
self.World.Add(newUnit);
|
|
||||||
Game.Debug("Added to world");
|
|
||||||
|
|
||||||
// Set the physical position of the unit as the exit cell
|
// Set the physical position of the unit as the exit cell
|
||||||
mobile.SetPosition(newUnit,exit);
|
move.SetPosition(newUnit,exit);
|
||||||
var to = Util.CenterOfCell(exit);
|
var to = Util.CenterOfCell(exit);
|
||||||
|
newUnit.CenterLocation = spawn;
|
||||||
|
if (facing != null)
|
||||||
|
facing.Facing = Util.GetFacing(to - spawn, facing.Facing);
|
||||||
|
self.World.Add(newUnit);
|
||||||
|
|
||||||
// Animate the spawn -> exit transition
|
// Animate the spawn -> exit transition
|
||||||
newUnit.CenterLocation = spawn;
|
var speed = move.MovementSpeedForCell(self, exit);
|
||||||
mobile.Facing = Util.GetFacing(to - spawn, mobile.Facing);
|
|
||||||
var speed = mobile.MovementSpeedForCell(self, exit);
|
|
||||||
var length = speed > 0 ? (int)( ( to - spawn ).Length*3 / speed ) : 0;
|
var length = speed > 0 ? (int)( ( to - spawn ).Length*3 / speed ) : 0;
|
||||||
newUnit.QueueActivity(new Activities.Drag(spawn, to, length));
|
newUnit.QueueActivity(new Activities.Drag(spawn, to, length));
|
||||||
|
|
||||||
@@ -68,6 +65,7 @@ namespace OpenRA.Traits
|
|||||||
if (rp != null)
|
if (rp != null)
|
||||||
{
|
{
|
||||||
target = rp.rallyPoint;
|
target = rp.rallyPoint;
|
||||||
|
// Todo: Move implies unit has Mobile
|
||||||
newUnit.QueueActivity(new Activities.Move(target, 1));
|
newUnit.QueueActivity(new Activities.Move(target, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +80,7 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var t in self.traits.WithInterface<INotifyProduction>())
|
foreach (var t in self.traits.WithInterface<INotifyProduction>())
|
||||||
t.UnitProduced(self, newUnit);
|
t.UnitProduced(self, newUnit, exit);
|
||||||
|
|
||||||
Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID);
|
Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID);
|
||||||
}
|
}
|
||||||
@@ -94,40 +92,26 @@ namespace OpenRA.Traits
|
|||||||
new OwnerInit( self.Owner ),
|
new OwnerInit( self.Owner ),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Todo: remove assumption on Mobile
|
// Todo: remove assumption on Mobile;
|
||||||
|
// required for 3-arg CanEnterCell
|
||||||
var mobile = newUnit.traits.Get<Mobile>();
|
var mobile = newUnit.traits.Get<Mobile>();
|
||||||
|
|
||||||
// Pick an exit that we can move to
|
// Pick a spawn/exit point pair
|
||||||
var exit = int2.Zero;
|
|
||||||
var spawn = float2.Zero;
|
|
||||||
var success = false;
|
|
||||||
|
|
||||||
// Pick a spawn/exit point
|
|
||||||
// Todo: Reorder in a synced random way
|
// Todo: Reorder in a synced random way
|
||||||
foreach (var s in Spawns)
|
foreach (var s in Spawns)
|
||||||
{
|
{
|
||||||
exit = self.Location + s.Value;
|
var exit = self.Location + s.Value;
|
||||||
spawn = self.CenterLocation + s.Key;
|
var spawn = self.CenterLocation + s.Key;
|
||||||
if (mobile.CanEnterCell(exit,self,true))
|
if (mobile.CanEnterCell(exit,self,true))
|
||||||
{
|
{
|
||||||
success = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
// Hack around mobile being a tard; remove from UIM (we shouldn't be there in the first place)
|
|
||||||
newUnit.traits.Get<Mobile>().RemoveInfluence();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DoProduction(self, newUnit, exit, spawn);
|
DoProduction(self, newUnit, exit, spawn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// "primary building" crap - perhaps this should be split?
|
// "primary building" crap - perhaps this should be split?
|
||||||
|
|
||||||
bool isPrimary = false;
|
bool isPrimary = false;
|
||||||
public bool IsPrimary { get { return isPrimary; } }
|
public bool IsPrimary { get { return isPrimary; } }
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Traits
|
|||||||
public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); }
|
public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); }
|
||||||
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
|
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
|
||||||
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
|
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
|
||||||
public interface INotifyProduction { void UnitProduced(Actor self, Actor other); }
|
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, int2 exit); }
|
||||||
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
|
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
|
||||||
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
|
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
|
||||||
public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); }
|
public interface INotifyEnterCell { void OnEnterCell(Actor self, int2 cell); }
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (var t in self.traits.WithInterface<INotifyProduction>())
|
foreach (var t in self.traits.WithInterface<INotifyProduction>())
|
||||||
t.UnitProduced(self, newUnit);
|
t.UnitProduced(self, newUnit, exit);
|
||||||
|
|
||||||
Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID);
|
Log.Write("debug", "{0} #{1} produced by {2} #{3}", newUnit.Info.Name, newUnit.ActorID, self.Info.Name, self.ActorID);
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
public Animation roof;
|
public Animation roof;
|
||||||
[Sync]
|
[Sync]
|
||||||
bool isOpen;
|
bool isOpen;
|
||||||
|
[Sync]
|
||||||
|
int2 openExit;
|
||||||
|
|
||||||
string GetPrefix(Actor self)
|
string GetPrefix(Actor self)
|
||||||
{
|
{
|
||||||
@@ -44,7 +46,7 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>()
|
if (isOpen && !self.World.WorldActor.traits.Get<UnitInfluence>()
|
||||||
.GetUnitsAt(((1f/Game.CellSize) * self.CenterLocation).ToInt2()).Any())
|
.GetUnitsAt(openExit).Any())
|
||||||
{
|
{
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top"));
|
roof.PlayBackwardsThen(GetPrefix(self) + "build-top", () => roof.Play(GetPrefix(self) + "idle-top"));
|
||||||
@@ -61,9 +63,9 @@ namespace OpenRA.Mods.RA.Render
|
|||||||
roof.ReplaceAnim(roof.CurrentSequence.Name.Replace("damaged-",""));
|
roof.ReplaceAnim(roof.CurrentSequence.Name.Replace("damaged-",""));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UnitProduced(Actor self, Actor other)
|
public void UnitProduced(Actor self, Actor other, int2 exit)
|
||||||
{
|
{
|
||||||
roof.PlayThen(GetPrefix(self) + "build-top", () => isOpen = true);
|
roof.PlayThen(GetPrefix(self) + "build-top", () => {isOpen = true; openExit = exit;});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Selling( Actor self )
|
public void Selling( Actor self )
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ AFLD:
|
|||||||
Range: 7
|
Range: 7
|
||||||
Bib:
|
Bib:
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
|
RallyPoint: 4,2
|
||||||
BelowUnits:
|
BelowUnits:
|
||||||
ProductionAirdrop:
|
ProductionAirdrop:
|
||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
@@ -241,9 +242,11 @@ WEAP:
|
|||||||
Bib:
|
Bib:
|
||||||
RenderWarFactory:
|
RenderWarFactory:
|
||||||
RallyPoint:
|
RallyPoint:
|
||||||
|
RallyPoint: 0,3
|
||||||
Production:
|
Production:
|
||||||
# ExitOffset:-1,1
|
|
||||||
Produces: Vehicle
|
Produces: Vehicle
|
||||||
|
SpawnOffsets: -8,-8
|
||||||
|
ExitCells: 0,2
|
||||||
HQ:
|
HQ:
|
||||||
RequiresPower:
|
RequiresPower:
|
||||||
CanPowerDown:
|
CanPowerDown:
|
||||||
|
|||||||
Reference in New Issue
Block a user