public static RoomGroup FromTing(Ting pTing) { D.isNull(pTing, "pTing is null in RoomGroup.FromTing()"); if (pTing.tile == null) { (pTing as MimanTing).MaybeFixGroupIfOutsideIslandOfTiles(); // only do this on stationary things that are never moved during the whole game } if (pTing.tile == null) { D.Log(pTing.name + " is on null tile, will find a close alternative tile"); PointTileNode alternativeTile; if (FindCloseAlternativeTile(pTing, out alternativeTile)) { D.Log("Will use tile " + alternativeTile + " instead"); return(new RoomGroup(pTing.room, alternativeTile.group)); } } if (pTing.tile == null) { D.Log(pTing.name + " is still on null tile, will fail."); // TODO: what is the correct default tile group?! return(new RoomGroup(pTing.room, -1)); } else { return(new RoomGroup(pTing.room, pTing.tile.group)); } }
/*private bool HasBeenVisited(List<Node> pVisitedNodes, Node pNode) { * foreach (Node n in pVisitedNodes) { * if (n.ting == pNode.ting) { * return true; * } * } * return false; * }*/ private bool LinkAllowed(Ting a, Ting b) { // Nullcheck not needed? /*a == null || b == null || */ if (a.tile == null || b.tile == null) { #if LOG Console.WriteLine("Link between " + a + " and " + b + " not allowed"); #endif return(false); } int groupA = a.tile.group; int groupB = b.tile.group; if (groupA == -1) { D.Log("Found tile " + a.tile + " with group -1"); } else if (groupB == -1) { D.Log("Found tile " + b.tile + " with group -1"); } return(groupA == groupB); }
static bool FindCloseAlternativeTile(Ting pTing, out PointTileNode tile) { var room = pTing.room; int x = pTing.localPoint.x; int y = pTing.localPoint.y; for (int dist = 1; dist < 20; dist++) { var north = room.GetTile(new IntPoint(x, y + 1)); var east = room.GetTile(new IntPoint(x + 1, y)); var south = room.GetTile(new IntPoint(x, y - 1)); var west = room.GetTile(new IntPoint(x - 1, y)); var tiles = new List <PointTileNode>() { north, east, south, west }; Shuffle(tiles); foreach (var t in tiles) { if (t != null && t.group > -1) { tile = t; return(true); } } } tile = new PointTileNode(IntPoint.Zero, pTing.room); return(false); }
public void API_Send(float connection) { if (stuff == null) { throw new Error("Nothing to send"); } if (connection < 0) { throw new Error("Connection id too low: " + connection); } if (connection >= connectedTings.Length) { throw new Error("Connection id too high: " + connection); } var target = connectedTings[(int)connection]; if (target == null) { throw new Error("Invalid target"); } else if (target is SendPipe) { var targetPipe = target as SendPipe; targetPipe.stuff = stuff; } var pos = target.position; stuff.position = pos; stuff = null; }
private HashSet <Ting> GetLinkedExitsInOtherRooms(Ting pTing) { var exitNodes = new HashSet <Ting>(); if (pTing is IExit) { var target = (pTing as IExit).GetLinkTarget(); if (target != null) { exitNodes.Add(target); } // Extra exits if it's an elevator door var elevator = pTing as Door; if (elevator != null && elevator.elevatorAlternatives.Length > 0) { foreach (var alternative in elevator.elevatorAlternatives) { var elevatorExit = _tingRunner.GetTing(alternative); exitNodes.Add(elevatorExit); } #if LOG string[] exitsAsStrings = exitNodes.Select(n => n.ToString()).ToArray(); //D.Log("Elevator " + elevator + " has exits: " + string.Join(", ", exitsAsStrings)); #endif } } return(exitNodes); }
public void PutStuffIntoIt(Ting pStuff) { pStuff.isBeingHeld = false; pStuff.position = position; stuff = pStuff; masterProgram.Start(); }
public override void InteractWith(Ting pTingToInteractWith) { if (pTingToInteractWith is Sink) { amount = 100f; } }
public void GetTingFromObjectId() { TingRunner tingRunner = CreateTingRunnerWithSomeRoom(); Ting puma = tingRunner.CreateTing <Animal>("Puma", new WorldCoordinate("SomeRoom", IntPoint.Zero)); Ting samePuma = tingRunner.GetTing(puma.name); Assert.AreSame(puma, samePuma); }
public void GetCurrentTile() { Ting t = _tingRunner.GetTing("Ting0"); PointTileNode n = t.tile; Assert.NotNull(n); Assert.AreEqual(t.localPoint, n.localPoint); }
public void SettingNameOfTing() { Ting t = InstantiatorTwo.Create <MyTing>(_table); t.SetInitCreateValues("Monkey", WorldCoordinate.NONE, Direction.UP); t.CreateNewRelayEntry(_table, "MyTing"); Assert.AreEqual("Monkey", t.name); }
public void ProcessGoods(Goods pGoods) { currentGoods = pGoods; currentGoods.isBeingHeld = false; currentGoods.position = goodsPointInWorld; masterProgram.executionsPerFrame = 5; masterProgram.Start(); }
public override void Update(float dt) { if (currentGoods == null) { MimanTing goodsAtPosition = null; var occupants = room.GetTile(localPoint).GetOccupants(); foreach (var o in occupants) { if (o is Machine) { // ignore } else { goodsAtPosition = o as MimanTing; break; } } if (goodsAtPosition != null && !goodsAtPosition.isBeingHeld && !goodsAtPosition.isDeleted) { currentGoods = goodsAtPosition; masterProgram.executionsPerFrame = 10; masterProgram.Start(); } } else if (currentGoods.isBeingHeld) { D.Log("is being held"); RemovedGoods(); } else if (currentGoods.position != goodsPointInWorld) { D.Log("different pos: " + currentGoods.position + " goods point: " + goodsPointInWorld); RemovedGoods(); } else { // Check for several goods at machine position /*var occupants = room.GetTile (localPoint).GetOccupants (); * if (occupants.Length > 2) { // 1 for the machine, one for the goods that should be there * foreach (var o in occupants) { * if (o is Machine) { * // ignore * } else { * if (o == currentGoods) { * o.position = new WorldCoordinate (this.room.name, this.interactionPoints [0]); * currentGoods = null; * D.Log ("Pushed out current goods!"); * break; * } * } * } * }*/ } }
private HashSet <Node> GetLinkedExitNodes(Ting pTing) { //D.isNull(pTing, "pTing is null"); var exitNodes = new HashSet <Node>(); foreach (var exit in GetExits(pTing.room)) { if (LinkAllowed(pTing, exit)) { exitNodes.Add(new Node() { ting = exit }); } } if (pTing is IExit) { var target = (pTing as IExit).GetLinkTarget(); if (target != null) { if (IsTargetDoorInABusyElevator(target as Door)) { //D.Log("Target door " + target + " is in a busy elevator"); } else { exitNodes.Add(new Node() { ting = target }); } } // Extra exits if it's an elevator door var elevator = pTing as Door; if (elevator != null && elevator.elevatorAlternatives.Length > 0) { foreach (var alternative in elevator.elevatorAlternatives) { var elevatorExit = _tingRunner.GetTing(alternative); exitNodes.Add(new Node() { ting = elevatorExit }); } #if LOG string[] exitsAsStrings = exitNodes.Select(n => n.ToString()).ToArray(); //D.Log("Elevator " + elevator + " has exits: " + string.Join(", ", exitsAsStrings)); #endif } } return(exitNodes); }
public override bool CanInteractWith(Ting pTingToInteractWith) { /*var computer = pTingToInteractWith as Computer; * * if (computer != null && computer.hasFloppyAPI) { * return true; * }*/ return(pTingToInteractWith is Locker || pTingToInteractWith is TrashCan || pTingToInteractWith is SendPipe || pTingToInteractWith is Stove); }
public override void PrepareForBeingHacked() { // Accessing the getter to make sure that a program is generated if (masterProgram == null) { logger.Log("There was a problem generating the master program"); } _user = null; }
public override string UseTingOnTingDescription(Ting pOtherTing) { if (pOtherTing is Door) { return(((pOtherTing as Door).isLocked ? "unlock" : "lock") + " door"); } else { return(base.UseTingOnTingDescription(pOtherTing)); } }
private void SetupRunners(Ting pTing) { if (pTing is Character) { (pTing as Character).SetTimetableRunner(_timetableRunner); } if (pTing is MimanTing) { (pTing as MimanTing).SetMimanRunners(_programRunner, _sourceCodeDispenser, _dialogueRunner, _worldSettings); (pTing as MimanTing).Init(); } }
public void TingOccupyingATile() { IntPoint p = new IntPoint(5, 3); Ting t = _tingRunner.GetTing("Ting0"); t.position = new WorldCoordinate(ROOM_NAME, p); Room room = _roomRunner.GetRoom(ROOM_NAME); PointTileNode tileNode = room.GetTile(p); Ting[] occupants = tileNode.GetOccupants(); Assert.AreEqual(1, occupants.Length); Assert.AreSame(t, occupants[0]); }
private float CostEstimate(Ting pStart, Ting pGoal) { var start = (pStart as IExit); if (start != null && start.GetLinkTarget() == pGoal) { return(0f); } int dx = pStart.worldPoint.x - pGoal.worldPoint.x; int dy = pStart.worldPoint.y - pGoal.worldPoint.y; return(Math.Abs(dx) + Math.Abs(dy)); }
public override void InteractWith(Ting pTingToInteractWith) { Door door = pTingToInteractWith as Door; if (door == null) { D.Log("The ting key is interacting with is not a door."); return; } actionOtherObject = door; masterProgram.executionsPerFrame = 50; masterProgram.maxExecutionTime = -1; // must be able to run indefinitely? masterProgram.Start(); }
private HashSet <Ting> GetLinkedExitsInSameRoom(Ting pTing) { D.isNull(pTing, "pTing is null in GetLinkedExitNodes"); var exitNodes = new HashSet <Ting>(); foreach (var exit in GetExits(pTing.room)) { if (InSameRoomAndLinked(pTing, exit)) { exitNodes.Add(exit); } } return(exitNodes); }
public override string UseTingOnTingDescription(Ting pOtherTing) { if (pOtherTing is Locker && this.CanInteractWith(pOtherTing)) { return("put " + this.tooltipName + " into locker"); } else if (pOtherTing is SendPipe && this.CanInteractWith(pOtherTing)) { return("put " + this.tooltipName + " into pipe"); } else if (pOtherTing is TrashCan && this.CanInteractWith(pOtherTing)) { return("throw " + this.tooltipName + " into trash can"); } return(base.UseTingOnTingDescription(pOtherTing)); }
public void PushButton(Ting pUser) { logger.Log(name + " is getting used in hand"); var user = (pUser as Character); if (user != null && user.creditCardUsageAmount != 0f) { RunMakeTransactionFunction(user.creditCardUsageAmount); user.creditCardUsageAmount = 0f; } else { masterProgram.maxExecutionTime = 10f; masterProgram.StartAtFunction("CheckBalance", new object[] {}, null); } }
public MimanPath Search(Ting pStart, Ting pGoal) { #if PROFILE Stopwatch sw = new Stopwatch(); sw.Start(); #endif var path = AStar(pStart, pGoal); #if PROFILE sw.Stop(); if (sw.Elapsed.TotalSeconds > 0.0f) { D.Log("Search from " + pStart.name + " at " + pStart.position + " to " + pGoal.name + " at " + pGoal.position + " with result: " + path.status + " took " + sw.Elapsed.TotalSeconds + " s. Iterations: " + path.iterations); } #endif return(path); }
Ting[] GetListOfTingsLeadingThroughRoomGroups(RoomGroupNode current) { #if LOG D.Log("Will GetListOfTingsLeadingThroughRoomGroups!"); D.Log("Starting at goal of " + current); #endif var roomGroupsPath = new List <RoomGroup>(); while (current.prev != null) { roomGroupsPath.Add(current.roomGroup); current = current.prev; } roomGroupsPath.Add(current.roomGroup); roomGroupsPath.Reverse(); // REVERSE! string[] roomGroupsAsStrings = roomGroupsPath.Select(r => r.ToString()).ToArray(); #if LOG D.Log("Room groups to go through: " + string.Join(", ", roomGroupsAsStrings)); #endif List <Ting> tingsToInteractWith = new List <Ting>(); for (int i = 0; i < roomGroupsPath.Count - 1; i++) { var a = roomGroupsPath[i]; var b = roomGroupsPath[i + 1]; #if LOG D.Log("Will find ting that connects " + a + " with " + b); #endif var connections = _roomNetwork.linkedRoomGroups[a]; Ting ting = connections[b]; tingsToInteractWith.Add(ting); } return(tingsToInteractWith.ToArray()); }
private Ting[] SearchBackwardsForTingsOnTheWay(Node pFinalNode) { var tings = new List <Ting>(); var n = pFinalNode; while (n.prev != null) { tings.Add(n.ting); n = n.prev; } // At this point the list is backwards and contains all the pairs of linked portals/doors // Let's fix that now: tings.Reverse(); var fixedTings = new List <Ting>(); Ting prevTing = null; foreach (var t in tings) { if (prevTing != null && (prevTing as IExit).GetLinkTarget() == t) { #if LOG Console.WriteLine("Skipping " + t + " since it's pointed to by previous ting in the list"); #endif } else { fixedTings.Add(t); } prevTing = t; } return(fixedTings.ToArray()); }
public float AddConnectionToTing(Ting pTing) { if (pTing == this) { //return "Can't connect to self"; // can't connect to self return(-1f); } D.isNull(pTing, "Can't connect to null"); string tingName = pTing.name; string[] oldTingNames = CELL_connectedTings.data; int index = 0; foreach (string name in oldTingNames) { if (tingName == name) { //return "Already connected to " + name; // already has a connection to this ting return((float)index); } index++; } string[] newTingNames = new string[oldTingNames.Length + 1]; int i = 0; foreach (string name in oldTingNames) { newTingNames[i++] = name; } newTingNames[i] = tingName; CELL_connectedTings.data = newTingNames; //return "Connected successfully to " + tingName; return((float)i); }
public void TingChangesTileToOccupy() { Ting ting = _tingRunner.GetTing("Ting0"); Room room = _roomRunner.GetRoom(ROOM_NAME); IntPoint p1 = new IntPoint(2, 2); IntPoint p2 = new IntPoint(4, 4); PointTileNode tileNode1 = room.GetTile(p1); PointTileNode tileNode2 = room.GetTile(p2); Assert.AreEqual(0, tileNode1.GetOccupants().Length); Assert.AreEqual(0, tileNode2.GetOccupants().Length); ting.position = new WorldCoordinate(ROOM_NAME, p1); Assert.AreEqual(1, tileNode1.GetOccupants().Length); Assert.AreEqual(0, tileNode2.GetOccupants().Length); ting.position = new WorldCoordinate(ROOM_NAME, p2); Assert.AreEqual(0, tileNode1.GetOccupants().Length); Assert.AreEqual(1, tileNode2.GetOccupants().Length); }
private float ActualCost(Ting pStart, Ting pGoal) { var start = (pStart as IExit); if (start != null && start.GetLinkTarget() == pGoal) { return(0f); } Dictionary <Ting, float> innerCache; if (_costCache.TryGetValue(pStart, out innerCache)) { float cachedCost; if (innerCache.TryGetValue(pGoal, out cachedCost)) { return(cachedCost); } } // int dx = pStart.worldPoint.x - pGoal.worldPoint.x; // int dy = pStart.worldPoint.y - pGoal.worldPoint.y; // float cost = (float)Math.Sqrt(dx * dx + dy * dy); float cost = pStart.room == pGoal.room ? 0.1f : 1.0f; if (innerCache == null) { innerCache = new Dictionary <Ting, float> (); _costCache.Add(pStart, innerCache); } innerCache [pGoal] = cost; return(cost); }
private bool InSameRoomAndLinked(Ting a, Ting b) { if (a.tile == null || b.tile == null) { #if LOG Console.WriteLine("Link between " + a + " and " + b + " not allowed"); #endif return(false); } int groupA = a.tile.group; int groupB = b.tile.group; if (groupA == -1) { D.Log("Found tile " + a.tile + " with group -1"); } else if (groupB == -1) { D.Log("Found tile " + b.tile + " with group -1"); } return(groupA == groupB); }