public BaseBuilding(string configFilename) { ConfigFile config = new ConfigFile(configFilename); m_Name = config.GetKey_String("General", "Name"); m_MaxHealth = m_Health = config.GetKey_Int("General", "Health"); m_Armor = config.GetKey_Int("General", "Armor"); m_ConsumptionRate = config.GetKey_Float("General", "ConsumptionRate"); m_MaxUpgradeLevels = config.GetKey_Int("General", "MaxUpgradeLevels"); m_UpgradeMagnitude = config.GetKey_Int("General", "UpgradeMagnitude"); m_MaxConnDist = config.GetKey_Float("General", "MaxConnDist"); m_MinConnDist = config.GetKey_Float("General", "MinConnDist"); Vector2 tempPrice = config.GetKey_Vector2("General", "Price"); m_MineralPrice = (int)tempPrice.x; m_GasPrice = (int)tempPrice.y; m_Sprite = new Sprite("Textures/" + config.GetKey_String("General", "Texture")); m_Sprite.SetGeometrySize(config.GetKey_Vector2("General", "Size")); m_Sprite.SetRotationCenter(m_Sprite.GetGeometrySize() / 2); Globals.WorldView.SManager.AddSprite(m_Sprite); }
public TurretBuilding(string configName) : base(configName) { ConfigFile config = new ConfigFile(configName); m_AlertRadius = config.GetKey_Float("Turret", "AlertRadius"); m_FireRadius = config.GetKey_Float("Turret", "FireRadius"); int numGuns = config.GetKey_Int("Turret", "NumGuns"); BaseShip_Weapon currWeapon = null; string gunGroup = "Gun"; string gunType = ""; for(int i = 0; i < numGuns; ++i) { gunGroup += (i+1).ToString(); gunType = config.GetKey_String(gunGroup, "Type"); currWeapon = new BaseShip_Weapon(); //currWeapon.CanRotate = ((config.GetKey_Int(gunGroup, "CanRotate") == 1) ? true : false); currWeapon.CoolDownRate = config.GetKey_Float(gunType , "CoolDown");; currWeapon.Position = config.GetKey_Vector2(gunGroup, "Pos"); currWeapon.WeaponSprite = new Sprite("Textures/" + config.GetKey_String(gunType, "Texture")); currWeapon.WeaponSprite.SetSpriteSize(currWeapon.WeaponSprite.GetTextureSize());//config.GetKey_Vector2(gunGroup, "Size")); currWeapon.WeaponSprite.SetSpritePos(Position); currWeapon.WeaponSprite.SetGeometrySize(currWeapon.WeaponSprite.GetSpriteSize() / 2); currWeapon.WeaponSprite.SetRotationCenter(currWeapon.WeaponSprite.GetGeometrySize() / 2.0f); currWeapon.WeaponSprite.SetDepth(Globals.WeaponsDepth); Globals.WorldView.SManager.AddSprite(currWeapon.WeaponSprite); gunType.ToLower(); if(gunType == "gatling") currWeapon.WeaponType = BaseShip_WeaponTypes.Gatling; else if(gunType == "rail") currWeapon.WeaponType = BaseShip_WeaponTypes.RailGun; else if(gunType == "missile") currWeapon.WeaponType = BaseShip_WeaponTypes.Missile; else currWeapon.WeaponType = BaseShip_WeaponTypes.Laser; m_Guns.Add(currWeapon); } Sprite.SetDepth(Globals.BuildingDepth); }
// Load a weapon based on the current group name (and does the internal sprite loading too) private BaseShip_Weapon LoadWeapon(ConfigFile Info, String GroupName) { // Ignore if not weapon if(GroupName.ToLower().StartsWith("weapon") == false) return null; // Load from config files BaseShip_Weapon Weapon = new BaseShip_Weapon(); String Type = Info.GetKey_String(GroupName, "Type"); Weapon.Position = Info.GetKey_Vector2(GroupName, "Pos"); // Get sprite info ConfigFile SpriteInfo = new ConfigFile("Config/Weapons/WeaponsConfig"); String TextureName = SpriteInfo.GetKey_String(Type, "Texture"); Weapon.CoolDownRate = SpriteInfo.GetKey_Float(Type, "CoolDown"); Vector2 SPos = SpriteInfo.GetKey_Vector2(Type, "Pos"); Vector2 SSize = SpriteInfo.GetKey_Vector2(Type, "Size"); //Vector2 SCenter = SpriteInfo.GetKey_Vector2(Type, "Center"); // Todo, so we rotate about a point, not center int SCount = SpriteInfo.GetKey_Int(Type, "Count"); float STime = SpriteInfo.GetKey_Float(Type, "Time"); // Load the sprite Weapon.WeaponSprite = new Sprite("Textures/" + TextureName); Weapon.WeaponSprite.SetSpritePos(SPos); Weapon.WeaponSprite.SetSpriteSize(SSize); Weapon.WeaponSprite.SetGeometrySize(Weapon.WeaponSprite.GetSpriteSize()); Weapon.WeaponSprite.SetRotationCenter(Weapon.WeaponSprite.GetGeometrySize() / 2.0f); // Set animation (if any) Weapon.WeaponSprite.SetAnimation(SPos, SSize, SCount, STime); // Right above regular ships Weapon.WeaponSprite.SetDepth(Globals.WeaponsDepth); // Register with renderer Globals.WorldView.SManager.AddSprite(Weapon.WeaponSprite); // Weapon type String WeaponType = SpriteInfo.GetKey_String(Type, "Projectile"); if(WeaponType.ToLower().CompareTo("gatling") == 0) Weapon.WeaponType = BaseShip_WeaponTypes.Gatling; else if(WeaponType.ToLower().CompareTo("laser") == 0) Weapon.WeaponType = BaseShip_WeaponTypes.Laser; else if(WeaponType.ToLower().CompareTo("missile") == 0) Weapon.WeaponType = BaseShip_WeaponTypes.Missile; else if(WeaponType.ToLower().CompareTo("railgun") == 0) Weapon.WeaponType = BaseShip_WeaponTypes.RailGun; // All done! return Weapon; }
// Load a ship hull animation set // Note: this is the only LoadXYZ function that does NOT do the internal group type check private BaseShip_Hull LoadHullType(ConfigFile Info, String GroupName) { // Alloc a new hull BaseShip_Hull Hull = new BaseShip_Hull(); // Load the animation basics Hull.Pos = Info.GetKey_Vector2(GroupName, "Pos"); Hull.Size = Info.GetKey_Vector2(GroupName, "Size"); Hull.FrameCount = Info.GetKey_Int(GroupName, "Count"); Hull.FrameTime = Info.GetKey_Float(GroupName, "Time"); // All done! return Hull; }
// Load a detail described in the config file private BaseShip_Detail LoadDetail(ConfigFile Info, String GroupName) { // Ignore if not a detail if(GroupName.ToLower().StartsWith("detail") == false) return null; // Create a new detail obj to return BaseShip_Detail Detail = new BaseShip_Detail(); // All we need is a reference to the detail's name Detail.Position = Info.GetKey_Vector2(GroupName, "Pos"); // Load a new sprite, and default it to animation state String DetailName = Info.GetKey_String(GroupName, "Type"); Detail.DetailSprite = new AnimatedSprite("Config/" + DetailName); Detail.DetailSprite.SetAnimation("Animation"); Detail.DetailSprite.SetDepth(Globals.ShipDetailsDepth); // Get the active animation, and see if(Detail.DetailSprite.GetRotationRate() == 0.0f) Detail.Fixed = true; else Detail.Fixed = false; // Set scale and center Detail.DetailSprite.SetGeometrySize(Detail.DetailSprite.GetSpriteSize()); Detail.DetailSprite.SetRotationCenter(Detail.DetailSprite.GetGeometrySize() / 2.0f); // Register sprite Globals.WorldView.SManager.AddSprite(Detail.DetailSprite); // Load the animated sprite return Detail; }
// Load a contrail based on the current group name private BaseShip_Contrail LoadContrail(ConfigFile Info, String GroupName) { // Ignore if not contrail if(GroupName.ToLower().StartsWith("contrail") == false) return null; // Alloc a new contrail BaseShip_Contrail Contrail = new BaseShip_Contrail(); // Get color, width, and ship position Vector3 ContrailColor = Info.GetKey_Vector3(GroupName, "Color"); float ContrailWidth = Info.GetKey_Float(GroupName, "Width"); Contrail.ContrailShipPos = Info.GetKey_Vector2(GroupName, "Pos"); // Initialize the contrail objects Contrail.ContrailObject = new GameObject("Contrail"); Contrail.Contrail = Contrail.ContrailObject.AddComponent("LineRenderer") as LineRenderer; Contrail.Contrail.material = new Material(Shader.Find("Particles/Additive"));//("Particles/Additive")); Contrail.Contrail.SetColors(new Color(ContrailColor.x, ContrailColor.y, ContrailColor.z), Color.clear); Contrail.Contrail.SetWidth(ContrailWidth, 2.0f); Contrail.Contrail.SetVertexCount(BaseShip_Contrail.ContrailLength - 1); // -1 since we are lerp-ing Contrail.ContrailPoints = new Vector2[BaseShip_Contrail.ContrailLength]; Contrail.ContrailTime = 0.0f; // Reset trail SetPos(ShipPosition); // All done! return Contrail; }
/*** Public ***/ // Standard constructor: needs to have a paried config file name // which should implement all of the groups and key-value pairs // found in the ship demo config file public BaseShip(String ConfigFileName) { // Load the ship's properties this.ConfigFileName = ConfigFileName; ConfigFile Info = new ConfigFile(ConfigFileName); /*** General Init. ***/ // Save the health components ShieldHealth = ShieldMaxHealth = Info.GetKey_Int("General", "Shield"); HullHealth = HullMaxHealth = Info.GetKey_Int("General", "Hull"); // Save velicity limit and default pos to center MaxVelocity = Info.GetKey_Vector2("General", "MaxVelocity"); ShipAcceleration = new Vector2(); ShipVelocity = new Vector2(); ShipPosition = new Vector3(); // Get all group names to load up specialty geometry String TextureName = Info.GetKey_String("General", "Texture"); String[] GroupNames = Info.GetGroupNames(); /*** Frame, Shield & Hull ***/ // For each group, look just for "Frame" and "Shield" foreach(String GroupName in GroupNames) { // If shield if(GroupName.ToLower().StartsWith("shield") == true) { // Get animation / frame info ShieldAnimation = LoadHullType(Info, GroupName); // Register the sprite with the sprite manager ShieldSprite = new Sprite("Textures/" + TextureName); ShieldSprite.SetAnimation(ShieldAnimation.Pos, ShieldAnimation.Size, ShieldAnimation.FrameCount, ShieldAnimation.FrameTime); ShieldSprite.SetGeometrySize(ShieldSprite.GetSpriteSize()); ShieldSprite.SetRotationCenter(ShieldSprite.GetGeometrySize() / 2.0f); ShieldSprite.SetDepth(Globals.ShieldDepth); Globals.WorldView.SManager.AddSprite(ShieldSprite); } // Elif base frame else if(GroupName.ToLower().StartsWith("frame") == true) { // Get animation / frame info FrameAnimation = LoadHullType(Info, GroupName); // Register the sprite with the sprite manager FrameSprite = new Sprite("Textures/" + TextureName); FrameSprite.SetAnimation(FrameAnimation.Pos, FrameAnimation.Size, FrameAnimation.FrameCount, FrameAnimation.FrameTime); FrameSprite.SetGeometrySize(FrameSprite.GetSpriteSize()); FrameSprite.SetRotationCenter(FrameSprite.GetGeometrySize() / 2.0f); FrameSprite.SetDepth(Globals.FrameDepth); Globals.WorldView.SManager.AddSprite(FrameSprite); } } // Load all the hulls HullList = new List<BaseShip_Hull>(); foreach(String GroupName in GroupNames) { if(GroupName.ToLower().StartsWith("hull") == true) { BaseShip_Hull Hull = LoadHullType(Info, GroupName); HullList.Add(Hull); } } // Default to initial hull HullSprite = new Sprite("Textures/" + TextureName); HullSkinIndex = 0; // Index grows while health goes down BaseShip_Hull HullAnimation = HullList[HullSkinIndex]; HullSprite.SetAnimation(HullAnimation.Pos, HullAnimation.Size, HullAnimation.FrameCount, HullAnimation.FrameTime); HullSprite.SetGeometrySize(HullSprite.GetSpriteSize()); HullSprite.SetRotationCenter(HullSprite.GetGeometrySize() / 2.0f); HullSprite.SetDepth(Globals.HullDepth); Globals.WorldView.SManager.AddSprite(HullSprite); /*** Contrails ***/ // Load all contrails ContrailList = new List<BaseShip_Contrail>(); foreach(String GroupName in GroupNames) { BaseShip_Contrail NewContrail = LoadContrail(Info, GroupName); if(NewContrail != null) ContrailList.Add(NewContrail); } /*** Weapons ***/ // Load all weapons WeaponsList = new List<BaseShip_Weapon>(); foreach(String GroupName in GroupNames) { BaseShip_Weapon NewWeapon = LoadWeapon(Info, GroupName); if(NewWeapon != null) WeaponsList.Add(NewWeapon); } /*** Animation Entities ***/ // Load all animations DetailsList = new List<BaseShip_Detail>(); foreach(String GroupName in GroupNames) { BaseShip_Detail Detail = LoadDetail(Info, GroupName); if(Detail != null) DetailsList.Add(Detail); } /*** Misc. ***/ // Chunk count foreach(String GroupName in GroupNames) { if(GroupName.ToLower().StartsWith("chunk")) ChunkCount++; } // Generate unique ship name NameGenerator NameGen = new NameGenerator(); ShipName = NameGen.generateName(); }
public void AddScenery(String ConfigFileName, String GroupName, Vector3 Position, Vector3 Velocity) { // Load the config file name ConfigFile Info = new ConfigFile(ConfigFileName); String TypeString = Info.GetKey_String(GroupName, "Type"); if(TypeString == null) TypeString = "hull"; // Force hull usage else TypeString = TypeString.ToLower(); // Get texture name from group, if it does not exist in the group, get it from the general:texture tag String TextureName = Info.GetKey_String(GroupName, "Texture"); if(TextureName == null) TextureName = Info.GetKey_String("General", "Texture"); // If no texture name, complete failure if(TextureName == null) Debug.LogError("Unable to load texture for given scenery item"); // Set common properties SceneryManager_Scenery SceneryItem = new SceneryManager_Scenery(); SceneryItem.ScenerySprite = new Sprite("Textures/" + TextureName); SceneryItem.ScenerySprite.SetSpritePos(Info.GetKey_Vector2(GroupName, "Pos")); SceneryItem.ScenerySprite.SetSpriteSize(Info.GetKey_Vector2(GroupName, "Size")); SceneryItem.ScenerySprite.SetGeometrySize(SceneryItem.ScenerySprite.GetSpriteSize()); SceneryItem.ScenerySprite.SetRotationCenter(SceneryItem.ScenerySprite.GetGeometrySize() / 2.0f); SceneryItem.ScenerySprite.SetPosition(Position); SceneryItem.ScenerySprite.SetRotation(Position.z); SceneryItem.ScenerySprite.SetDepth(Globals.JunkDepth); // If mineral if(TypeString.CompareTo("mineral") == 0) { SceneryItem.Type = SceneryType.Mineral; SceneryItem.Minerals = SceneryItem.MaxMinerals = Info.GetKey_Int(GroupName, "Resources"); SceneryItem.Radius = Info.GetKey_Float(GroupName, "Radius"); // No rotation for minerals SceneryItem.Velocity = new Vector3(0, 0, Velocity.z); } // Else, junk else if(TypeString.CompareTo("junk") == 0) { SceneryItem.Type = SceneryType.Junk; SceneryItem.Velocity = Velocity; } // Else, hull else if(TypeString.CompareTo("hull") == 0) { SceneryItem.Type = SceneryType.Hull; SceneryItem.Age = 0.0f; SceneryItem.MaxAge = 3.0f; SceneryItem.Velocity = Velocity; } // Add scenery SceneryList.Add(SceneryItem); Globals.WorldView.SManager.AddSprite(SceneryItem.ScenerySprite); }
// Load all animations and properties from the configuration file private void LoadConfig(string FileName) { // Load config Config = new ConfigFile(FileName); // Get the texture name TextureName = Config.GetKey_String("General", "Texture"); // Create new animations dictionary, loosing the rest Animations = new Dictionary<string, SpriteAnimation>(); // Get all group names for the animations set String[] Groups = Config.GetGroupNames(); foreach(String Group in Groups) { // Ignore if non-animation group if(Group == "general") continue; else { // Fill a sprite animation struct and save it as the group's name SpriteAnimation Animation = new SpriteAnimation(); Animation.Name = Group; Animation.Pos = Config.GetKey_Vector2(Group, "Pos"); Animation.Rotation = Config.GetKey_Float(Group, "Rotation"); Animation.Frame = Config.GetKey_Vector2(Group, "Size"); Animation.FrameCount = Config.GetKey_Int(Group, "Count"); Animation.FrameTime = Config.GetKey_Float(Group, "Time"); // Save Animations.Add(Group, Animation); } } }