[Fixing indentation]

This commit is contained in:
Bob
2009-11-19 15:02:04 +13:00
parent e427e6b16e
commit a17296ff8a
13 changed files with 244 additions and 249 deletions

View File

@@ -1,49 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using IjwFramework.Types;
using OpenRa.Game.Graphics;
namespace OpenRa.Game
{
interface IEffect
{
void Tick();
IEnumerable<Tuple<Sprite, float2, int>> Render();
Player Owner { get; }
}
class Bullet : IEffect
{
public Player Owner { get; private set; }
readonly Actor FiredBy;
readonly WeaponInfo Weapon;
readonly ProjectileInfo Projectile;
readonly WarheadInfo Warhead;
readonly int2 Src;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using IjwFramework.Types;
using OpenRa.Game.Graphics;
namespace OpenRa.Game
{
interface IEffect
{
void Tick();
IEnumerable<Tuple<Sprite, float2, int>> Render();
Player Owner { get; }
}
class Bullet : IEffect
{
public Player Owner { get; private set; }
readonly Actor FiredBy;
readonly WeaponInfo Weapon;
readonly ProjectileInfo Projectile;
readonly WarheadInfo Warhead;
readonly int2 Src;
readonly int2 Dest;
readonly int2 VisualDest;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
/* src, dest are *pixel* coords */
public Bullet(string weapon, Player owner, Actor firedBy,
int2 src, int2 dest)
{
Owner = owner;
FiredBy = firedBy;
Src = src;
readonly int2 VisualDest;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
/* src, dest are *pixel* coords */
public Bullet(string weapon, Player owner, Actor firedBy,
int2 src, int2 dest)
{
Owner = owner;
FiredBy = firedBy;
Src = src;
Dest = dest;
VisualDest = Dest + new int2(
Game.CosmeticRandom.Next(-10, 10),
Game.CosmeticRandom.Next(-10, 10));
Weapon = Rules.WeaponInfo[weapon];
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
Game.CosmeticRandom.Next(-10, 10));
Weapon = Rules.WeaponInfo[weapon];
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
Warhead = Rules.WarheadInfo[Weapon.Warhead];
if (Projectile.Image != null && Projectile.Image != "none")
@@ -56,19 +56,19 @@ namespace OpenRa.Game
anim.CurrentSequence.Length));
else
anim.PlayRepeating("idle");
}
}
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick()
{
if (t == 0)
Game.PlaySound(Weapon.Report + ".aud", false);
t += 40;
if (t > TotalTime()) /* remove finished bullets */
}
}
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick()
{
if (t == 0)
Game.PlaySound(Weapon.Report + ".aud", false);
t += 40;
if (t > TotalTime()) /* remove finished bullets */
{
Game.world.AddFrameEndTask(w =>
{
@@ -86,19 +86,19 @@ namespace OpenRa.Game
if (impact != null)
Game.PlaySound(impact+ ".aud", false);
});
var maxSpread = GetMaximumSpread();
var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread());
foreach (var victim in hitActors)
victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim));
}
});
var maxSpread = GetMaximumSpread();
var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread());
foreach (var victim in hitActors)
victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim));
}
}
const float height = .1f;
public IEnumerable<Tuple<Sprite, float2, int>> Render()
const float height = .1f;
public IEnumerable<Tuple<Sprite, float2, int>> Render()
{
if (anim != null)
{
@@ -119,25 +119,25 @@ namespace OpenRa.Game
}
else
yield return Tuple.New(anim.Image, pos, Owner.Palette);
}
}
float GetMaximumSpread()
{
return (int)(Warhead.Spread * Math.Log(Weapon.Damage, 2));
}
float GetDamageToInflict(Actor target)
}
}
float GetMaximumSpread()
{
return (int)(Warhead.Spread * Math.Log(Weapon.Damage, 2));
}
float GetDamageToInflict(Actor target)
{
if( target.unitInfo == null ) // tree or other doodad
return 0;
/* todo: some things can't be damaged AT ALL by certain weapons! */
var distance = (target.CenterLocation - Dest).Length;
var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread);
var multiplier = Warhead.EffectivenessAgainst(target.unitInfo.Armor);
return rawDamage * multiplier;
}
}
}
return 0;
/* todo: some things can't be damaged AT ALL by certain weapons! */
var distance = (target.CenterLocation - Dest).Length;
var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread);
var multiplier = Warhead.EffectivenessAgainst(target.unitInfo.Armor);
return rawDamage * multiplier;
}
}
}