EmitInfantryOnSell moved to RA

This commit is contained in:
Chris Forbes
2010-05-20 17:56:44 +12:00
parent 342ef2a498
commit 248eba20fa
6 changed files with 31 additions and 12 deletions

View File

@@ -25,7 +25,7 @@ using OpenRA.Traits;
namespace OpenRA.GameRules
{
static class Footprint
public static class Footprint
{
public static IEnumerable<int2> Tiles( string name, BuildingInfo buildingInfo, int2 topLeft )
{

View File

@@ -82,7 +82,6 @@
<Compile Include="Group.cs" />
<Compile Include="Orders\GenericSelectTarget.cs" />
<Compile Include="Traits\Activities\Leap.cs" />
<Compile Include="Traits\AI\EmitInfantryOnSell.cs" />
<Compile Include="Traits\AI\ReturnOnIdle.cs" />
<Compile Include="Traits\Attack\AttackLeap.cs" />
<Compile Include="Traits\DetectCloaked.cs" />

View File

@@ -1,51 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRA.GameRules;
namespace OpenRA.Traits.AI
{
class EmitInfantryOnSellInfo : TraitInfo<EmitInfantryOnSell>
{
public readonly float ValueFraction = .4f;
public readonly float MinHpFraction = .3f;
public readonly string[] ActorTypes = { "e1" }; // todo: cN as well
}
class EmitInfantryOnSell : INotifySold, INotifyDamage
{
public void Selling(Actor self) { }
void Emit(Actor self)
{
var info = self.Info.Traits.Get<EmitInfantryOnSellInfo>();
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
var cost = csv != null ? csv.Value : self.Info.Traits.Get<ValuedInfo>().Cost;
var hp = self.Info.Traits.Get<OwnedActorInfo>().HP;
var hpFraction = Math.Max(info.MinHpFraction, hp / self.GetMaxHP());
var dudesValue = (int)(hpFraction * info.ValueFraction * cost);
var eligibleLocations = Footprint.Tiles(self).ToList();
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = Rules.Info[a].Traits.Get<ValuedInfo>().Cost }).ToArray();
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
{
var at = actorTypes.Where(a => a.Cost <= dudesValue).Random(self.World.SharedRandom);
var loc = eligibleLocations.Random(self.World.SharedRandom);
eligibleLocations.Remove(loc);
dudesValue -= at.Cost;
self.World.AddFrameEndTask(w => w.CreateActor(at.Name, loc, self.Owner));
}
}
public void Sold(Actor self) { Emit(self); }
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageStateChanged && e.DamageState == DamageState.Dead)
Emit(self);
}
}
}

View File

@@ -20,7 +20,7 @@
namespace OpenRA.Traits
{
class ValuedInfo : ITraitInfo
public class ValuedInfo : ITraitInfo
{
public readonly int Cost = 0;
public readonly string Description = "";

View File

@@ -23,10 +23,10 @@ namespace OpenRA.Traits
// allow a nonstandard sell/repair value to avoid
// buy-sell exploits like c&c's PROC.
class CustomSellValueInfo : TraitInfo<CustomSellValue>
public class CustomSellValueInfo : TraitInfo<CustomSellValue>
{
public readonly int Value = 0;
}
class CustomSellValue {}
public class CustomSellValue { }
}