public Stack <Frame> callStack; // the stack of functions this processor is running. // Use this for initialization public Processor_Bot_Basic(Core_Bot_Basic owner, Function root) { callStack = new Stack <Frame>(); main_function = root; timeToNextStep = 0; bot = owner; }
public override float run(Core_Bot_Basic bot) { // if the condition fails, abort this function: if (!operation.operation(left, right)) { bot.processor.callStack.Pop(); return(1f); } // if the condition is true, do nothing. return(.5f); }
public Stack <Frame> callStack; // the stack of functions this processor is running. // Use this for initialization public Processor_Bot_Basic(Core_Bot_Basic owner, Function root) { callStack = new Stack <Frame>(); main_function = root; timeToNextStep = 0; bot = owner; channels = new BotVariable[3]; for (int i = 0; i < channels.Length; i++) { channels[0] = new BotVariable(); } }
// checks if the bot's channel var types match the requirements of this instruction. // subClasses that have channel requirements should check this first, and return or // explode or something if the requirements are not met. public bool checkChannelRequirements(Core_Bot_Basic bot) { for (int i = 0; i < 3; i++) { if (requiresChannelTypes[i] != null) { if (string.Compare(requiresChannelTypes[i], bot.processor.channels[i].type) != 0) { return(false); } } } return(true); }
public override float run(Core_Bot_Basic bot) { // if the condition fails, abort this function: if (!operation.operation(left, right)) { bot.processor.callStack.Pop(); return(1f); } // if the condition is true, make a new frame with this function, // add it to the top of the callStack with the instruction pointer // pointing AFTER the while. Then move this frame's instruction pointer // to point at this while again. Result should be that it runs a dummy // copy of this function, then returns to check this while again. else { Frame thisFrame = bot.processor.callStack.Peek(); bot.processor.callStack.Push(new Frame(thisFrame.function)); bot.processor.callStack.Peek().instructionPointer++; thisFrame.instructionPointer--; return(.5f); } }
// Send a signal to all bots within range. // The bots all get thier .processor.channels[channel] = data;. // This should eventually get moved out of control tower into some more global place. private void SendSignal(Vector3 origin, float strength, int channel, BotVariable data) { Debug.Log("Control Tower sending signal."); // get the list of bots from Factory: Core_Bot_Basic[] bots = FindObjectsOfType(typeof(Core_Bot_Basic)) as Core_Bot_Basic[]; Debug.Log("bots: " + bots); //for each bot, if it's in range: for (int i = 0; i < bots.Length; i++) { Core_Bot_Basic bot = bots[i]; if (Vector3.Distance(origin, bot.transform.position) < strength) { // set the data to the selected channel: if (bot.processor == null) { Debug.Log("this bot has a null processor! " + bot); } bot.processor.channels[channel] = data; Debug.Log("signal recieved by bot"); } } }
// Runs return on the bot. public override float run(Core_Bot_Basic bot) { // remove the current frame from the bot's callstack bot.processor.callStack.Pop(); return(0); }
// When a function is run, it pushes itself onto the // bot's callstack. public override float run(Core_Bot_Basic bot) { bot.processor.callStack.Push(new Frame(this)); return(0); }
public override float run(Core_Bot_Basic bot) { bot.SetBreaks(20F); return(.5f); }
// throttle forward at 50. public override float run(Core_Bot_Basic bot) { bot.SetThrottle(50); return(1f); }
// throttle forward at 50. public override float run(Core_Bot_Basic bot) { return(0f); }
// Runs this instruction on the bot. // should be overridden by subclasses. // returns the amount of time before the bot should run Step() again. public abstract float run(Core_Bot_Basic bot);