Facing -> new trait ("Unit")
This commit is contained in:
@@ -21,6 +21,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public IActivity Tick( Actor self, Mobile mobile )
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
if (Target == null || Target.IsDead)
|
||||
return NextActivity;
|
||||
|
||||
@@ -30,7 +32,7 @@ namespace OpenRa.Game.Traits.Activities
|
||||
var desiredFacing = Util.GetFacing((Target.Location - self.Location).ToFloat2(), 0);
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First();
|
||||
|
||||
if (Util.QuantizeFacing(mobile.facing, renderUnit.anim.CurrentSequence.Length)
|
||||
if (Util.QuantizeFacing(unit.Facing, renderUnit.anim.CurrentSequence.Length)
|
||||
!= Util.QuantizeFacing(desiredFacing, renderUnit.anim.CurrentSequence.Length))
|
||||
{
|
||||
return new Turn( desiredFacing ) { NextActivity = this };
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public IActivity Tick( Actor self, Mobile mobile )
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
if( isDone )
|
||||
{
|
||||
self.traits.Get<Harvester>().Deliver( self, refinery );
|
||||
@@ -61,7 +63,7 @@ namespace OpenRa.Game.Traits.Activities
|
||||
// no refineries reachable?
|
||||
return null;
|
||||
}
|
||||
else if( mobile.facing != 64 )
|
||||
else if( unit.Facing != 64 )
|
||||
return new Turn( 64 ) { NextActivity = this };
|
||||
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First();
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public IActivity Tick( Actor self, Mobile mobile )
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
if( isHarvesting ) return null;
|
||||
|
||||
if( NextActivity != null )
|
||||
@@ -26,7 +28,7 @@ namespace OpenRa.Game.Traits.Activities
|
||||
if( Rules.Map.ContainsResource( self.Location ) &&
|
||||
Rules.Map.Harvest( self.Location, out isGem ) )
|
||||
{
|
||||
var harvestAnim = "harvest" + Util.QuantizeFacing( mobile.facing, 8 );
|
||||
var harvestAnim = "harvest" + Util.QuantizeFacing( unit.Facing, 8 );
|
||||
var renderUnit = self.traits.WithInterface<RenderUnit>().First(); /* better have one of these! */
|
||||
if( harvestAnim != renderUnit.anim.CurrentSequence.Name )
|
||||
{
|
||||
|
||||
@@ -51,6 +51,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public IActivity Tick( Actor self, Mobile mobile )
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
if( move != null )
|
||||
{
|
||||
move.TickMove( self, mobile, this );
|
||||
@@ -79,8 +81,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
return null;
|
||||
|
||||
int2 dir = nextCell.Value - mobile.fromCell;
|
||||
var firstFacing = Util.GetFacing( dir, mobile.facing );
|
||||
if( firstFacing != mobile.facing )
|
||||
var firstFacing = Util.GetFacing( dir, unit.Facing );
|
||||
if( firstFacing != unit.Facing )
|
||||
{
|
||||
path.Add( nextCell.Value );
|
||||
|
||||
@@ -92,8 +94,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
move = new MoveFirstHalf(
|
||||
CenterOfCell( mobile.fromCell ),
|
||||
BetweenCells( mobile.fromCell, mobile.toCell ),
|
||||
mobile.facing,
|
||||
mobile.facing,
|
||||
unit.Facing,
|
||||
unit.Facing,
|
||||
0 );
|
||||
|
||||
Game.UnitInfluence.Update( mobile );
|
||||
@@ -183,13 +185,14 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
void UpdateCenterLocation( Actor self, Mobile mobile )
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
var frac = (float)moveFraction / moveFractionTotal;
|
||||
|
||||
self.CenterLocation = float2.Lerp( from, to, frac );
|
||||
if( moveFraction >= moveFractionTotal )
|
||||
mobile.facing = toFacing & 0xFF;
|
||||
unit.Facing = toFacing & 0xFF;
|
||||
else
|
||||
mobile.facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF;
|
||||
unit.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF;
|
||||
}
|
||||
|
||||
protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent );
|
||||
@@ -204,6 +207,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
|
||||
{
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
var nextCell = parent.PopPath( self, mobile );
|
||||
if( nextCell != null )
|
||||
{
|
||||
@@ -212,8 +217,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
var ret = new MoveFirstHalf(
|
||||
BetweenCells( mobile.fromCell, mobile.toCell ),
|
||||
BetweenCells( mobile.toCell, nextCell.Value ),
|
||||
mobile.facing,
|
||||
Util.GetNearestFacing( mobile.facing, Util.GetFacing( nextCell.Value - mobile.toCell, mobile.facing ) ),
|
||||
unit.Facing,
|
||||
Util.GetNearestFacing( unit.Facing, Util.GetFacing( nextCell.Value - mobile.toCell, unit.Facing ) ),
|
||||
moveFraction - moveFractionTotal );
|
||||
mobile.fromCell = mobile.toCell;
|
||||
mobile.toCell = nextCell.Value;
|
||||
@@ -226,8 +231,8 @@ namespace OpenRa.Game.Traits.Activities
|
||||
var ret2 = new MoveSecondHalf(
|
||||
BetweenCells( mobile.fromCell, mobile.toCell ),
|
||||
CenterOfCell( mobile.toCell ),
|
||||
mobile.facing,
|
||||
mobile.facing,
|
||||
unit.Facing,
|
||||
unit.Facing,
|
||||
moveFraction - moveFractionTotal );
|
||||
mobile.fromCell = mobile.toCell;
|
||||
Game.UnitInfluence.Update( mobile );
|
||||
|
||||
@@ -18,16 +18,20 @@ namespace OpenRa.Game.Traits.Activities
|
||||
|
||||
public IActivity Tick( Actor self, Mobile mobile )
|
||||
{
|
||||
if( desiredFacing == mobile.facing )
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
if( desiredFacing == unit.Facing )
|
||||
return NextActivity;
|
||||
|
||||
Util.TickFacing( ref mobile.facing, desiredFacing, self.unitInfo.ROT );
|
||||
Util.TickFacing( ref unit.Facing, desiredFacing, self.unitInfo.ROT );
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Cancel( Actor self, Mobile mobile )
|
||||
{
|
||||
desiredFacing = mobile.facing;
|
||||
var unit = self.traits.Get<Unit>();
|
||||
|
||||
desiredFacing = unit.Facing;
|
||||
NextActivity = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user