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); }
public CommandCenterBuilding(string configName) : base(configName) { ConfigFile config = new ConfigFile(configName); m_MaxPower = config.GetKey_Float("Power", "MaxEnergy"); m_IsPowered = true; }
public ShipyardBuilding(string configName) : base(configName) { ConfigFile configFile = new ConfigFile(configName); m_ShipCapacity = configFile.GetKey_Int("Shipyard", "ShipCapacity"); m_BuildCoolDown = configFile.GetKey_Float("Shipyard", "BuildCoolDown"); m_ShipConfig = configFile.GetKey_String("Shipyard", "ShipConfig"); }
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); }
// 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 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 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); } } }