Merge branch 'master' of git://github.com/chrisforbes/OpenRA

This commit is contained in:
Chris Forbes
2009-12-23 21:08:36 +13:00
15 changed files with 177 additions and 53 deletions

View File

@@ -45,8 +45,10 @@ namespace OpenRa.Game.Traits.Activities
static bool CanEnterCell( int2 c, Actor self )
{
if (!Game.BuildingInfluence.CanMoveHere(c)) return false;
var u = Game.UnitInfluence.GetUnitAt( c );
return (u == null || u == self);
// Cannot enter a cell if any unit inside is uncrushable
// This will need to be updated for multiple-infantry-in-a-cell
return (!Game.UnitInfluence.GetUnitsAt(c).Any(a => a != self && !Game.IsActorCrushableByActor(a, self)));
}
public IActivity Tick( Actor self )
@@ -68,7 +70,7 @@ namespace OpenRa.Game.Traits.Activities
path = getPath( self, mobile ).TakeWhile( a => a != self.Location ).ToList();
SanityCheckPath( mobile );
}
if( path.Count == 0 )
{
destination = mobile.toCell;

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OpenRa.Game.Traits
{
class Infantry : ICrushable
{
readonly Actor self;
public Infantry(Actor self)
{
this.self = self;
}
public bool IsCrushableByFriend()
{
// HACK: should be false
return true;
}
public bool IsCrushableByEnemy()
{
// HACK: should be based off crushable tag
return true;
}
public void OnCrush(Actor crusher)
{
self.InflictDamage(crusher, self.Health, Rules.WarheadInfo["Crush"]);
}
public IEnumerable<UnitMovementType> CrushableBy()
{
yield return UnitMovementType.Track;
//yield return UnitMovementType.Wheel; // Can infantry be crushed by wheel?
}
}
}

View File

@@ -80,9 +80,27 @@ namespace OpenRa.Game.Traits
}
}
public bool CanEnterCell(int2 location)
public bool CanEnterCell(int2 a)
{
return Game.IsCellBuildable( location, GetMovementType(), self );
if (Game.BuildingInfluence.GetBuildingAt(a) != null) return false;
var crushable = true;
foreach (Actor actor in Game.UnitInfluence.GetUnitsAt(a))
{
if (actor == self) continue;
if (!Game.IsActorCrushableByActor(actor, self))
{
crushable = false;
break;
}
}
if (!crushable) return false;
return Rules.Map.IsInMap(a.X, a.Y) &&
TerrainCosts.Cost(GetMovementType(),
Rules.TileSet.GetWalkability(Rules.Map.MapTiles[a.X, a.Y])) < double.PositiveInfinity;
}
public IEnumerable<int2> GetCurrentPath()

View File

@@ -21,7 +21,7 @@ namespace OpenRa.Game.Traits
public bool Produce( Actor self, UnitInfo producee )
{
var location = CreationLocation( self, producee );
if( location == null || Game.UnitInfluence.GetUnitAt( location.Value ) != null )
if( location == null || Game.UnitInfluence.GetUnitsAt( location.Value ).Any() )
return false;
var newUnit = new Actor( producee, location.Value, self.Owner );

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
@@ -35,7 +36,7 @@ namespace OpenRa.Game.Traits
if (doneBuilding) roof.Tick();
var b = self.Bounds;
if (isOpen && null == Game.UnitInfluence.GetUnitAt(((1/24f) * self.CenterLocation).ToInt2()))
if (isOpen && !Game.UnitInfluence.GetUnitsAt(((1/24f) * self.CenterLocation).ToInt2()).Any())
{
isOpen = false;
roof.PlayBackwardsThen(prefix + "build-top", () => roof.Play(prefix + "idle-top"));

View File

@@ -58,4 +58,12 @@ namespace OpenRa.Game.Traits
UnitMovementType GetMovementType();
bool CanEnterCell(int2 location);
}
interface ICrushable
{
bool IsCrushableByFriend();
bool IsCrushableByEnemy();
void OnCrush(Actor crusher);
IEnumerable<UnitMovementType>CrushableBy();
}
}