internal static void Setup() { DefaultMessageRaiser.EarlySetup(); LSDatabaseManager.Setup(); Command.Setup(); UnityInstance = GameObject.CreatePrimitive(PrimitiveType.Quad).AddComponent <MonoBehaviour>(); GameObject.Destroy(UnityInstance.GetComponent <Collider>()); UnityInstance.GetComponent <Renderer>().enabled = false; GameObject.DontDestroyOnLoad(UnityInstance.gameObject); GridManager.Setup(); AbilityDataItem.Setup(); AgentController.Setup(); TeamManager.Setup(); ProjectileManager.Setup(); EffectManager.Setup(); PhysicsManager.Setup(); ClientManager.Setup(); Application.targetFrameRate = 60; Time.fixedDeltaTime = BaseDeltaTime; Time.maximumDeltaTime = Time.fixedDeltaTime * 2; InputCodeManager.Setup(); DefaultMessageRaiser.LateSetup(); }
protected void ProcessSpawnQueue() { currentSpawnProgress += spawnIncrement; if (currentSpawnProgress > _maxSpawnProgress) { if (Agent.GetCommander()) { //if (audioElement != null) //{ // audioElement.Play(finishedJobSound); //} Vector2d spawnOutside = new Vector2d(this.transform.position); RTSAgent agent = Agent.Controller.CreateAgent(spawnQueue.Dequeue(), spawnOutside); agent.SetProvision(true); if (cachedRally) { if (cachedRally.spawnPoint != cachedRally.rallyPoint) { Command moveCom = new Command(AbilityDataItem.FindInterfacer("Move").ListenInputID); moveCom.Add <Vector2d>(new Vector2d(cachedRally.rallyPoint)); moveCom.ControllerID = agent.Controller.ControllerID; moveCom.Add <Influence>(new Influence(agent)); CommandManager.SendCommand(moveCom); } } } currentSpawnProgress = 0; } }
internal static void Setup() { DefaultMessageRaiser.EarlySetup(); LSDatabaseManager.Setup(); Command.Setup(); UnityInstance = GameObject.CreatePrimitive(PrimitiveType.Sphere).AddComponent <FillerComponent> (); GameObject.Destroy(UnityInstance.GetComponent <Collider> ()); UnityInstance.GetComponent <Renderer> ().enabled = false; GameObject.DontDestroyOnLoad(UnityInstance.gameObject); GridManager.Setup(); AbilityDataItem.Setup(); AgentController.Setup(); ProjectileManager.Setup(); EffectManager.Setup(); PhysicsManager.Setup(); ClientManager.Setup(); Time.fixedDeltaTime = BaseDeltaTime; Time.maximumDeltaTime = Time.fixedDeltaTime * 2; InputCodeManager.Setup(); DefaultMessageRaiser.LateSetup(); if (onSetup != null) { onSetup(); } }
internal void Setup(LSAgent agent, int id) { System.Type mainType = this.GetType(); if (mainType.IsSubclassOf(typeof(ActiveAbility))) { while (mainType.BaseType != typeof(ActiveAbility) && mainType.GetCustomAttributes(typeof(CustomActiveAbilityAttribute), false).Length == 0) { mainType = mainType.BaseType; } Data = AbilityDataItem.FindInterfacer(mainType); if (Data == null) { throw new System.ArgumentException("The Ability of type " + mainType + " has not been registered in database"); } this.MyAbilityCode = Data.Name; } else { this.MyAbilityCode = mainType.Name; } _agent = agent; ID = id; TemplateSetup(); OnSetup(); this.VariableContainerTicket = LSVariableManager.Register(this); this._variableContainer = LSVariableManager.GetContainer(VariableContainerTicket); }
// public static void Reset () // { // LockstepManager.Deactivate (); // GameObject.Instantiate (MainGameManager.gameObject); // } internal static void Setup() { DefaultMessageRaiser.EarlySetup(); LSDatabaseManager.Setup(); Command.Setup(); GridManager.Setup(); InputCodeManager.Setup(); AbilityDataItem.Setup(); AgentController.Setup(); ProjectileManager.Setup(); EffectManager.Setup(); PhysicsManager.Setup(); ClientManager.Setup(); Time.fixedDeltaTime = DeltaTimeF; Time.maximumDeltaTime = Time.fixedDeltaTime * 2; DefaultMessageRaiser.LateSetup(); if (onSetup != null) { onSetup(); } }
static void Setup() { QuickPos = AbilityDataItem.FindInterfacer("Move"); QuickTarget = AbilityDataItem.FindInterfacer("Scan"); Setted = true; }
private void DrawActions(string[] actions) { GUIStyle buttons = new GUIStyle(); buttons.hover.background = buttonHover; buttons.active.background = buttonClick; GUI.skin.button = buttons; int numActions = actions.Length; //define the area to draw the actions inside GUI.BeginGroup(new Rect(BUILD_IMAGE_WIDTH, 0, ORDERS_BAR_WIDTH, buildAreaHeight)); //draw scroll bar for the list of actions if need be if (numActions >= MaxNumRows(buildAreaHeight)) { DrawSlider(buildAreaHeight, numActions / 2.0f); } //display possible actions as buttons and handle the button click for each for (int i = 0; i < numActions; i++) { int column = i % 2; int row = i / 2; Rect pos = GetButtonPos(row, column); Texture2D action = GameResourceManager.GetBuildImage(actions[i]); if (action) { //create the button and handle the click of that button if (GUI.Button(pos, action)) { RTSAgent agent = Selector.MainSelectedAgent as RTSAgent; if (agent) { PlayClick(); if (agent.MyAgentType == AgentType.Unit && agent.GetAbility <Construct>() && !ConstructionHandler.IsFindingBuildingLocation()) { ConstructionHandler.CreateStructure(actions[i], agent, agent.GetPlayerArea()); } else if (agent.MyAgentType == AgentType.Building && !agent.GetAbility <Structure>().NeedsConstruction && agent.GetAbility <Spawner>()) { // send spawn command Command spawnCom = new Command(AbilityDataItem.FindInterfacer("Spawner").ListenInputID); spawnCom.Add <DefaultData>(new DefaultData(DataType.String, actions[i])); UserInputHelper.SendCommand(spawnCom); } } } } } GUI.EndGroup(); }
public virtual void InfluenceAttack() { // send attack command Command attackCom = new Command(AbilityDataItem.FindInterfacer("Attack").ListenInputID); attackCom.Add <DefaultData>(new DefaultData(DataType.UShort, nearbyAgent.GlobalID)); attackCom.ControllerID = cachedAgent.Controller.ControllerID; attackCom.Add <Influence>(new Influence(cachedAgent)); CommandManager.SendCommand(attackCom); }
public static void SendConstructCommand(bool startConstruction = true) { //Reset construction handler Reset(); // send construct command Command constructCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); constructCom.Add(new DefaultData(DataType.Bool, startConstruction)); UserInputHelper.SendCommand(constructCom); }
protected void Setup() { QuickMove = AbilityDataItem.FindInterfacer("Move"); QuickTarget = AbilityDataItem.FindInterfacer("Attack"); QuickHarvest = AbilityDataItem.FindInterfacer("Harvest"); QuickBuild = AbilityDataItem.FindInterfacer("Construct"); QuickRally = AbilityDataItem.FindInterfacer("Spawner"); if (GUIManager == null) { GUIManager = new RTSGUIManager(); } Setted = true; cachedCommander = PlayerManager.MainController.Commander; }
public static Command GetProcessInterfacer(AbilityDataItem facer) { if (facer == null) { Debug.LogError("Interfacer does not exist. Can't generate command."); return(null); } Command curCom = null; switch (facer.InformationGather) { case InformationGatherType.Position: curCom = new Command(facer.ListenInputID); curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition)); break; case InformationGatherType.Target: curCom = new Command(facer.ListenInputID); if (RTSInterfacing.MousedAgent.IsNotNull()) { curCom.SetData <DefaultData>(new DefaultData(DataType.UShort, RTSInterfacing.MousedAgent.LocalID)); } break; case InformationGatherType.PositionOrTarget: curCom = new Command(facer.ListenInputID); if (RTSInterfacing.MousedAgent.IsNotNull()) { curCom.Add <DefaultData>(new DefaultData(DataType.UShort, RTSInterfacing.MousedAgent.GlobalID)); } break; case InformationGatherType.PositionOrAction: curCom = new Command(facer.ListenInputID); curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition)); break; case InformationGatherType.None: curCom = new Command(facer.ListenInputID); break; } return(curCom); }
private void InfluenceConstruction() { if (nearbyAgent) { Structure closestBuilding = nearbyAgent.GetComponent <Structure>(); if (closestBuilding) { // send construct command Command constructCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); constructCom.Add <DefaultData>(new DefaultData(DataType.UShort, nearbyAgent.GlobalID)); constructCom.ControllerID = cachedAgent.Controller.ControllerID; constructCom.Add <Influence>(new Influence(cachedAgent)); CommandManager.SendCommand(constructCom); } } }
public static void SetConstructionQueue(GameObject buildingProject, long adjustHalfWidth = 0, long adjustHalfLength = 0) { QStructure qStructure = new QStructure(); qStructure.StructureName = buildingProject.gameObject.name; qStructure.BuildPoint = new Vector2d(buildingProject.transform.localPosition.x, buildingProject.transform.localPosition.z); qStructure.RotationPoint = new Vector2d(buildingProject.transform.localRotation.w, buildingProject.transform.localRotation.y); qStructure.LocalScale = new Vector3d(buildingProject.transform.localScale); qStructure.HalfWidth = adjustHalfWidth > 0 ? adjustHalfWidth : tempStructureBody.HalfWidth; qStructure.HalfLength = adjustHalfLength > 0 ? adjustHalfLength : tempStructureBody.HalfLength; Command queueCommand = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); queueCommand.Add(new QueueStructure(qStructure)); UserInputHelper.SendCommand(queueCommand); }
protected void Setup() { QuickMove = AbilityDataItem.FindInterfacer("Move"); QuickTarget = AbilityDataItem.FindInterfacer("Attack"); QuickHarvest = AbilityDataItem.FindInterfacer("Harvest"); QuickBuild = AbilityDataItem.FindInterfacer("Construct"); QuickRally = AbilityDataItem.FindInterfacer("Rally"); if (GUIManager == null) { GUIManager = new RTSGUIManager(); } Setted = true; // set to starting camera angels yaw = GUIManager.MainCam.transform.eulerAngles.y; pitch = GUIManager.MainCam.transform.eulerAngles.x; }
private void InfluenceHarvest() { if (nearbyAgent) { ResourceDeposit closestResource = nearbyAgent.GetAbility <ResourceDeposit>(); Structure closestResourceStore = nearbyAgent.GetAbility <Structure>(); if (closestResource && closestResource.ResourceType == cachedHarvest.HarvestType || closestResourceStore && nearbyAgent.GetAbility <Structure>().CanStoreResources(cachedAgent.GetAbility <Harvest>().HarvestType)) { // send harvest command Command harvestCom = new Command(AbilityDataItem.FindInterfacer("Harvest").ListenInputID); harvestCom.Add(new DefaultData(DataType.UShort, nearbyAgent.GlobalID)); harvestCom.ControllerID = cachedAgent.Controller.ControllerID; harvestCom.Add(new Influence(cachedAgent)); CommandManager.SendCommand(harvestCom); } } }
// move to build ability? public void StartConstruction() { findingPlacement = false; Vector2d buildPoint = new Vector2d(tempBuilding.transform.position.x, tempBuilding.transform.position.z); RTSAgent newBuilding = cachedCommander.CachedController.CreateAgent(tempBuilding.gameObject.name, buildPoint, Vector2d.right) as RTSAgent; Destroy(tempBuilding.gameObject); newBuilding.SetState(AnimState.Building); newBuilding.RestoreMaterials(); newBuilding.SetPlayingArea(tempCreator.GetPlayerArea()); newBuilding.GetAbility <Health>().HealthAmount = FixedMath.Create(0); newBuilding.SetCommander(); // send build command Command buildCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); buildCom.Add <DefaultData>(new DefaultData(DataType.UShort, newBuilding.GlobalID)); UserInputHelper.SendCommand(buildCom); newBuilding.GetAbility <Structure>().StartConstruction(); // check that the Player has the resources available before allowing them to create a new Unit / Building cachedCommander.RemoveResource(ResourceType.Gold, newBuilding.cost); }
private static void ProcessInterfacer(AbilityDataItem facer) { switch (facer.InformationGather) { case InformationGatherType.Position: curCom = new Command(facer.ListenInputID); curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition)); break; case InformationGatherType.Target: curCom = new Command(facer.ListenInputID); if (RTSInterfacing.MousedAgent.IsNotNull()) { curCom.SetData <DefaultData>(new DefaultData(DataType.UShort, RTSInterfacing.MousedAgent.LocalID)); } break; case InformationGatherType.PositionOrTarget: curCom = new Command(facer.ListenInputID); if (RTSInterfacing.MousedAgent.IsNotNull()) { curCom.Add <DefaultData>(new DefaultData(DataType.UShort, RTSInterfacing.MousedAgent.GlobalID)); } else { curCom.Add <Vector2d>(RTSInterfacing.GetWorldPosD(Input.mousePosition)); } break; case InformationGatherType.None: curCom = new Command(facer.ListenInputID); break; } Send(curCom); }
//Helper function that takes in a type rather than AbilityDataItem to cast an ability public static void CastAbility <TAbility> () where TAbility : ActiveAbility { CurrentInterfacer = AbilityDataItem.FindInterfacer <TAbility>(); }
public static void ProcessInterfacer(AbilityDataItem facer) { Command com = RTSInterfacing.GetProcessInterfacer(facer); Send(com); }
public override void DecideWhatToDo() { base.DecideWhatToDo(); if (Agent.Tag == AgentTag.Harvester && cachedHarvest.IsFocused) { //convert to fast list... List <RTSAgent> resources = new List <RTSAgent>(); foreach (RTSAgent nearbyObject in nearbyObjects) { ResourceDeposit resource = nearbyObject.GetAbility <ResourceDeposit>(); if (resource && !resource.IsEmpty()) { resources.Add(nearbyObject); } } RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(resources, transform.position); if (nearestObject) { ResourceDeposit closestResource = nearestObject.GetAbility <ResourceDeposit>(); // only harvest resources the worker is assigned to if (closestResource && closestResource.ResourceType == cachedHarvest.HarvestType) { // send harvest command Command harvestCom = new Command(AbilityDataItem.FindInterfacer("Harvest").ListenInputID); harvestCom.Add <DefaultData>(new DefaultData(DataType.UShort, nearestObject.GlobalID)); UserInputHelper.SendCommand(harvestCom); } } } if (Agent.Tag == AgentTag.Builder && cachedBuild.IsFocused) { //convert to fast array List <RTSAgent> buildings = new List <RTSAgent>(); foreach (RTSAgent nearbyObject in nearbyObjects) { if (nearbyObject.GetCommander() != Agent.Controller.Commander) { continue; } RTSAgent nearbyBuilding = nearbyObject.GetComponent <RTSAgent>(); if (nearbyBuilding && nearbyBuilding.GetAbility <Structure>().UnderConstruction()) { buildings.Add(nearbyObject); } } RTSAgent nearestObject = WorkManager.FindNearestWorldObjectInListToPosition(buildings, transform.position); if (nearestObject) { RTSAgent closestBuilding = nearestObject.GetComponent <RTSAgent>(); if (closestBuilding) { // send build command Command buildCom = new Command(AbilityDataItem.FindInterfacer("Construct").ListenInputID); buildCom.Add <DefaultData>(new DefaultData(DataType.UShort, closestBuilding.GlobalID)); UserInputHelper.SendCommand(buildCom); } } else { cachedBuild.SetCurrentProject(null); } } }