using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using IjwFramework.Types; using OpenRa.FileFormats; using OpenRa.Game.GameRules; using OpenRa.Game.Graphics; using System.Drawing; namespace OpenRa.Game { class Actor { public readonly TypeDictionary traits = new TypeDictionary(); public readonly UnitInfo unitInfo; public int2 Location; public Player Owner; public Actor( string name, int2 location, Player owner ) { unitInfo = Rules.UnitInfo[ name ]; Location = location; CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location; Owner = owner; switch( name ) { ///// vehicles ///// case "mcv": traits.Add( new Traits.Mobile( this ) ); traits.Add( new Traits.RenderUnit( this ) ); traits.Add( new Traits.McvDeploy( this ) ); break; case "mnly": case "apc": case "v2rl": case "arty": traits.Add( new Traits.Mobile( this ) ); traits.Add( new Traits.RenderUnit( this ) ); break; case "jeep": case "1tnk": case "2tnk": case "3tnk": case "4tnk": traits.Add( new Traits.Mobile( this ) ); traits.Add( new Traits.Turreted( this ) ); traits.Add( new Traits.AttackTurreted( this ) ); traits.Add( new Traits.RenderUnitTurreted( this ) ); break; case "mrj": case "mgg": // TODO: these aren't actually turreted; they just have spinning-things traits.Add( new Traits.Mobile( this ) ); traits.Add( new Traits.Turreted( this ) ); traits.Add( new Traits.RenderUnitTurreted( this ) ); break; case "harv": traits.Add( new Traits.Mobile( this ) ); traits.Add( new Traits.RenderUnit( this ) ); break; ///// TODO: infantry ///// ///// TODO: boats ///// ///// TODO: planes ///// ///// buildings ///// //TODO: SBAG, BRIK, FENC, etc case "iron": case "pdox": case "mslo": case "atek": case "stek": case "fact": case "proc": case "hpad": case "afld": case "dome": case "powr": case "apwr": case "barr": case "tent": case "kenn": case "fix": case "spen": case "syrd": case "gap": case "pbox": case "hbox": case "tsla": case "ftur": case "facf": case "syrf": case "spef": case "domf": traits.Add( new Traits.Building( this ) ); traits.Add( new Traits.RenderBuilding( this ) ); break; case "weap": case "weaf": traits.Add( new Traits.Building( this ) ); traits.Add( new Traits.RenderWarFactory( this ) ); break; case "gun": case "agun": case "sam": traits.Add( new Traits.Building( this ) ); traits.Add( new Traits.Turreted( this ) ); traits.Add( new Traits.RenderBuildingTurreted( this ) ); break; case "silo": traits.Add(new Traits.Building(this)); traits.Add(new Traits.RenderBuildingOre(this)); break; case "fcom": traits.Add( new Traits.Building( this ) ); traits.Add( new Traits.RenderBuilding( this ) ); break; default: throw new NotImplementedException( "Actor traits for " + name ); } } public Actor( TreeReference tree, TreeCache treeRenderer, int2 mapOffset ) { Location = new int2( tree.Location ) - mapOffset; traits.Add( new Traits.Tree( treeRenderer.GetImage( tree.Image ) ) ); } public void Tick( Game game ) { foreach( var tick in traits.WithInterface() ) tick.Tick( this, game ); } public float2 CenterLocation; public float2 SelectedSize { get { return Render().LastOrDefault().First.size; } } public IEnumerable> Render() { return traits.WithInterface().SelectMany( x => x.Render( this ) ); } public Order Order( Game game, int2 xy ) { return traits.WithInterface() .Select( x => x.Order( this, game, xy ) ) .Where( x => x != null ) .FirstOrDefault(); } public RectangleF Bounds { get { var size = SelectedSize; var loc = CenterLocation - 0.5f * size; return new RectangleF(loc.X, loc.Y, size.X, size.Y); } } } }