fixed 4tnk

This commit is contained in:
Chris Forbes
2010-01-08 11:58:20 +13:00
parent 39de75047e
commit 69da6fdd2d
6 changed files with 44 additions and 21 deletions

View File

@@ -45,7 +45,7 @@ namespace OpenRa.Game.Effects
} }
const int MissileCloseEnough = 7; const int MissileCloseEnough = 7;
const float Scale = .3f; const float Scale = .2f;
public void Tick() public void Tick()
{ {
@@ -71,8 +71,10 @@ namespace OpenRa.Game.Effects
return; return;
} }
var speed = Weapon.Speed * ((targetAltitude > 0 && Weapon.TurboBoost) ? 1.5f : 1f); var speed = Scale * Weapon.Speed * ((targetAltitude > 0 && Weapon.TurboBoost) ? 1.5f : 1f);
var move = (Scale * speed / dist.Length) * dist;
var angle = Facing / 128f * Math.PI;
var move = speed * -float2.FromAngle((float)angle);
Pos += move; Pos += move;
if (Projectile.Animates) if (Projectile.Animates)

View File

@@ -59,6 +59,10 @@ namespace OpenRa.Game.GameRules
public readonly int UnloadFacing = 0; public readonly int UnloadFacing = 0;
public readonly UnitMovementType[] PassengerTypes = null; public readonly UnitMovementType[] PassengerTypes = null;
// weapon origins and firing angles within the turrets. 3 values per position.
public readonly int[] PrimaryLocalOffset = { };
public readonly int[] SecondaryLocalOffset = { };
public UnitInfo(string name) { Name = name; } public UnitInfo(string name) { Name = name; }
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using IjwFramework.Types; using IjwFramework.Types;
using OpenRa.Game.Effects; using OpenRa.Game.Effects;
@@ -72,7 +73,7 @@ namespace OpenRa.Game.Traits
var unit = self.traits.GetOrDefault<Unit>(); var unit = self.traits.GetOrDefault<Unit>();
if (self.Info.Primary != null && CheckFire(self, unit, self.Info.Primary, ref primaryFireDelay, if (self.Info.Primary != null && CheckFire(self, unit, self.Info.Primary, ref primaryFireDelay,
self.Info.PrimaryOffset, ref primaryBurst)) self.Info.PrimaryOffset, ref primaryBurst, self.Info.PrimaryLocalOffset))
{ {
secondaryFireDelay = Math.Max(4, secondaryFireDelay); secondaryFireDelay = Math.Max(4, secondaryFireDelay);
primaryRecoil = 1; primaryRecoil = 1;
@@ -80,7 +81,7 @@ namespace OpenRa.Game.Traits
} }
if (self.Info.Secondary != null && CheckFire(self, unit, self.Info.Secondary, ref secondaryFireDelay, if (self.Info.Secondary != null && CheckFire(self, unit, self.Info.Secondary, ref secondaryFireDelay,
self.Info.SecondaryOffset ?? self.Info.PrimaryOffset, ref secondaryBurst)) self.Info.SecondaryOffset ?? self.Info.PrimaryOffset, ref secondaryBurst, self.Info.SecondaryLocalOffset))
{ {
if (self.Info.SecondaryOffset != null) secondaryRecoil = 1; if (self.Info.SecondaryOffset != null) secondaryRecoil = 1;
else primaryRecoil = 1; else primaryRecoil = 1;
@@ -88,7 +89,7 @@ namespace OpenRa.Game.Traits
} }
} }
bool CheckFire(Actor self, Unit unit, string weaponName, ref int fireDelay, int[] offset, ref int burst) bool CheckFire(Actor self, Unit unit, string weaponName, ref int fireDelay, int[] offset, ref int burst, int[] localOffset)
{ {
if (fireDelay > 0) return false; if (fireDelay > 0) return false;
@@ -101,6 +102,17 @@ namespace OpenRa.Game.Traits
if (!Combat.WeaponValidForTarget(weapon, target)) return false; if (!Combat.WeaponValidForTarget(weapon, target)) return false;
var numOffsets = (localOffset.Length + 2) / 3;
if (numOffsets == 0) numOffsets = 1;
var localOffsetForShot = burst % numOffsets;
var thisLocalOffset = localOffset.Skip(3 * localOffsetForShot).Take(3).ToArray();
var fireOffset = new[] {
offset.ElementAtOrDefault(0) + thisLocalOffset.ElementAtOrDefault(0),
offset.ElementAtOrDefault(1) + thisLocalOffset.ElementAtOrDefault(1),
offset.ElementAtOrDefault(2),
offset.ElementAtOrDefault(3) };
if (--burst > 0) if (--burst > 0)
fireDelay = 5; fireDelay = 5;
else else
@@ -109,7 +121,7 @@ namespace OpenRa.Game.Traits
burst = weapon.Burst; burst = weapon.Burst;
} }
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, offset, 0f).ToInt2(); var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, fireOffset, 0f).ToInt2();
var thisTarget = target; // closure. var thisTarget = target; // closure.
var destUnit = thisTarget.traits.GetOrDefault<Unit>(); var destUnit = thisTarget.traits.GetOrDefault<Unit>();
@@ -118,15 +130,17 @@ namespace OpenRa.Game.Traits
var srcAltitude = unit != null ? unit.Altitude : 0; var srcAltitude = unit != null ? unit.Altitude : 0;
var destAltitude = destUnit != null ? destUnit.Altitude : 0; var destAltitude = destUnit != null ? destUnit.Altitude : 0;
var fireFacing = self.traits.Contains<Turreted>()
? self.traits.Get<Turreted>().turretFacing : unit.Facing;
if( weapon.RenderAsTesla ) if( weapon.RenderAsTesla )
Game.world.Add( new TeslaZap( firePos, thisTarget.CenterLocation.ToInt2() ) ); Game.world.Add( new TeslaZap( firePos, thisTarget.CenterLocation.ToInt2() ) );
if( Rules.ProjectileInfo[ weapon.Projectile ].ROT != 0 ) if (Rules.ProjectileInfo[weapon.Projectile].ROT != 0)
{
var fireFacing = thisLocalOffset.ElementAtOrDefault(2) +
(self.traits.Contains<Turreted>() ? self.traits.Get<Turreted>().turretFacing : unit.Facing);
Game.world.Add(new Missile(weaponName, self.Owner, self, Game.world.Add(new Missile(weaponName, self.Owner, self,
firePos, thisTarget, srcAltitude, fireFacing)); firePos, thisTarget, srcAltitude, fireFacing));
}
else else
Game.world.Add(new Bullet(weaponName, self.Owner, self, Game.world.Add(new Bullet(weaponName, self.Owner, self,
firePos, thisTarget.CenterLocation.ToInt2(), srcAltitude, destAltitude)); firePos, thisTarget.CenterLocation.ToInt2(), srcAltitude, destAltitude));

View File

@@ -33,6 +33,7 @@ namespace OpenRa.Game.Traits
public Animation Animation; public Animation Animation;
public Func<float2> OffsetFunc; public Func<float2> OffsetFunc;
public Func<bool> DisableFunc; public Func<bool> DisableFunc;
public int ZOffset;
public AnimationWithOffset( Animation a ) public AnimationWithOffset( Animation a )
: this( a, null, null ) : this( a, null, null )
@@ -48,10 +49,9 @@ namespace OpenRa.Game.Traits
public Renderable Image( Actor self ) public Renderable Image( Actor self )
{ {
if( OffsetFunc != null ) var r = Util.Centered( self, Animation.Image, self.CenterLocation
return Util.Centered( self, Animation.Image, self.CenterLocation + OffsetFunc() ); + (OffsetFunc != null ? OffsetFunc() : float2.Zero) );
else return ZOffset != 0 ? r.WithZOffset(ZOffset) : r;
return Util.Centered( self, Animation.Image, self.CenterLocation );
} }
public static implicit operator AnimationWithOffset( Animation a ) public static implicit operator AnimationWithOffset( Animation a )

View File

@@ -19,16 +19,16 @@ namespace OpenRa.Game.Traits
turretAnim.PlayFacing( "turret", () => turreted.turretFacing ); turretAnim.PlayFacing( "turret", () => turreted.turretFacing );
if( self.Info.PrimaryOffset != null ) if( self.Info.PrimaryOffset != null )
anims.Add( "turret_1", new AnimationWithOffset( anims.Add("turret_1", new AnimationWithOffset(
turretAnim, turretAnim,
() => Util.GetTurretPosition( self, unit, self.Info.PrimaryOffset, attack.primaryRecoil ), () => Util.GetTurretPosition(self, unit, self.Info.PrimaryOffset, attack.primaryRecoil),
null ) ); null) { ZOffset = 1 });
if( self.Info.SecondaryOffset != null ) if( self.Info.SecondaryOffset != null )
anims.Add( "turret_2", new AnimationWithOffset( anims.Add("turret_2", new AnimationWithOffset(
turretAnim, turretAnim,
() => Util.GetTurretPosition( self, unit, self.Info.SecondaryOffset, attack.secondaryRecoil ), () => Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, attack.secondaryRecoil),
null ) ); null) { ZOffset = 1 });
if( self.Info.MuzzleFlash ) if( self.Info.MuzzleFlash )
{ {

View File

@@ -42,6 +42,9 @@ Description=Mammoth Tank
Traits=Unit, Mobile, Turreted, AttackTurreted, RenderUnitTurreted, AutoTarget, Repairable, Chronoshiftable, Passenger, IronCurtainable Traits=Unit, Mobile, Turreted, AttackTurreted, RenderUnitTurreted, AutoTarget, Repairable, Chronoshiftable, Passenger, IronCurtainable
Voice=VehicleVoice Voice=VehicleVoice
LongDesc=Big and slow tank, with anti-air capability.\n Strong vs Tanks, Aircraft\n Weak vs Infantry LongDesc=Big and slow tank, with anti-air capability.\n Strong vs Tanks, Aircraft\n Weak vs Infantry
PrimaryLocalOffset=-4,-5,0,4,-5,0
SecondaryLocalOffset=-7,2,25,7,2,-25
Recoil=4
[ARTY] [ARTY]
Description=Artillery Description=Artillery
Traits=Unit, Mobile, AttackBase, RenderUnit, Explodes, AutoTarget, Repairable, Chronoshiftable, Passenger, IronCurtainable Traits=Unit, Mobile, AttackBase, RenderUnit, Explodes, AutoTarget, Repairable, Chronoshiftable, Passenger, IronCurtainable