/// <summary> /// Creates bridges in a line /// </summary> /// <param name="triggerX"></param> /// <param name="triggerY"></param> void CreateBridges(int triggerX, int triggerY) { int dirX = 0; int dirY = 0; GetDirectionsForBridgeTrap(ref dirX, ref dirY); for (int i = 0; i < quality; i++) { int tileX = triggerX + dirX * i; int tileY = triggerY + dirY * i; if (TileMap.ValidTile(tileX, tileY)) { //Create a bridge at this tile. Only if no bridge is already there. if (ObjectLoader.findObjectByTypeInTile(CurrentObjectList().objInfo, (short)tileX, (short)tileY, ObjectInteraction.BRIDGE) == -1) { ObjectLoaderInfo newObj = ObjectLoader.newObject(356, 40, 0, 0, 256); newObj.xpos = 4; newObj.ypos = 4; newObj.zpos = zpos; // bridge texture will be set by (bridge.enchantment << 3) | bridge.flags & 0x3F; newObj.flags = (short)(owner & 0x7); newObj.enchantment = (short)((owner >> 3) & 0x1); newObj.heading = heading; newObj.ObjectTileX = (short)tileX; newObj.ObjectTileY = (short)tileY; Vector3 pos = ObjectLoader.CalcObjectXYZ(newObj.index, 0); ObjectInteraction.CreateNewObject(CurrentTileMap(), newObj, CurrentObjectList().objInfo, GameWorldController.instance.LevelModel, pos); } } } }
public void SpillContentsX() { //Removes the contents of a container out in the real world. int counter; TileMap tm = GameWorldController.instance.currentTileMap(); //GameObject.Find("Tilemap").GetComponent<TileMap>(); GameWorldController.FreezeMovement(this.gameObject); ObjectInteraction objInt = this.gameObject.GetComponent <ObjectInteraction>(); objInt.SetWorldDisplay(objInt.GetEquipDisplay()); for (short i = 0; i <= MaxCapacity(); i++) { GameObject Spilled = GetGameObjectAt(i); //GameObject.Find (GetItemAt (i)); if (Spilled != null) { if (Spilled.GetComponent <trigger_base>() != null) { Spilled.GetComponent <trigger_base>().Activate(this.gameObject); } bool flag = false; Vector3 randomPoint = this.transform.position; counter = 0; while ((flag == false) && (counter < 25)) { randomPoint = this.transform.position + Random.insideUnitSphere; if (randomPoint.y < this.transform.position.y) { randomPoint.y = this.transform.position.y + 0.1f; } flag = ((!Physics.CheckSphere(randomPoint, 0.5f)) && (tm.ValidTile(randomPoint))); counter++; } if (flag == true) { //No object interferes with the spill RemoveItemFromContainer(i); Spilled.transform.position = randomPoint; Spilled.GetComponent <ObjectInteraction>().PickedUp = false; GameWorldController.UnFreezeMovement(Spilled); } else { //No where to put the item. Put it at the containers position. RemoveItemFromContainer(i); Spilled.transform.position = this.transform.position; Spilled.GetComponent <ObjectInteraction>().PickedUp = false; GameWorldController.UnFreezeMovement(Spilled); } } } GameWorldController.UnFreezeMovement(this.gameObject); }
/// <summary> /// Destroys the bridges in a line /// </summary> /// <param name="triggerX"></param> /// <param name="triggerY"></param> void DestroyBridges(int triggerX, int triggerY) { int dirX = 0; int dirY = 0; GetDirectionsForBridgeTrap(ref dirX, ref dirY); for (int i = 0; i < quality; i++) { int tileX = triggerX + dirX * i; int tileY = triggerY + dirY * i; if (TileMap.ValidTile(tileX, tileY)) { int index = ObjectLoader.findObjectByTypeInTile(CurrentObjectList().objInfo, (short)tileX, (short)tileY, ObjectInteraction.BRIDGE); //Create a bridge at this tile. Only if no bridge is already there. if (index != -1) { ObjectInteraction obj = ObjectLoader.getObjectIntAt(index); obj.consumeObject(); } } } }
protected void AdjustModelPos() { //Line up decals to walls where the decal is set to be on an edge. int tileX = objInt().tileX; int tileY = objInt().tileY; int x = objInt().x; int y = objInt().y; //int heading = objInt ().heading * 45; Vector3 objPos = this.transform.position; Vector3 adjustment = Vector3.zero; if (TileMap.ValidTile(tileX, tileY)) { if ((y == 0)) { //Move object Right. adjustment += new Vector3(0, 0, 0.06f); } if ((y == 7)) { //Move object left. adjustment += new Vector3(0, 0, -0.06f); } if ((x == 0)) { //move object forward adjustment += new Vector3(0.06f, 0, 0); } if ((x == 7)) { //Move object backward.. adjustment += new Vector3(-0.06f, 0, 0); } } this.transform.position = objPos + adjustment; }
public void UpdateTile() { int DimX = 0; int DimY = 0; int FloorHeight = 0; int WallTexture = WallTextureSelect.value; int FloorTexture = FloorTextureSelect.value; int TileTypeSelected = TileTypeSelect.value; int.TryParse(TileHeightDetails.text, out FloorHeight); if (LockTileHeight.isOn) { FloorHeight = -1; } if (LockTileType.isOn) { TileTypeSelected = -1; } if (LockFloorTextures.isOn) { FloorTexture = -1; } if (LockWallTextures.isOn) { WallTexture = -1; } if (!int.TryParse(TileRangeX.text, out DimX)) { DimX = 0; } if (!int.TryParse(TileRangeY.text, out DimY)) { DimY = 0; } if ((DimX == 0) && (DimY == 0)) { //Just update the specified tile UpdateTile(TileX, TileY, TileTypeSelected, FloorTexture, WallTexture, FloorHeight); } else { //Find min and max, x & y values int MinX = Mathf.Min(TileX, TileX + DimX); int MaxX = Mathf.Max(TileX, TileX + DimX); int MinY = Mathf.Min(TileY, TileY + DimY); int MaxY = Mathf.Max(TileY, TileY + DimY); switch (TileTypeSelected) { case -1: //Not tile type change. case TileMap.TILE_SOLID: case TileMap.TILE_OPEN: for (int x = MinX; x <= MaxX; x++) { for (int y = MinY; y <= MaxY; y++) { if (TileMap.ValidTile(x, y)) { if (FloorHeight != -1) { GameWorldController.instance.currentTileMap().Tiles[x, y].floorHeight = (short)FloorHeight; } if ((TileTypeSelected == TileMap.TILE_OPEN) || (TileTypeSelected == -1)) { GameWorldController.instance.currentTileMap().Tiles[x, y].VisibleFaces[TileMap.vTOP] = true; } else { GameWorldController.instance.currentTileMap().Tiles[x, y].VisibleFaces[TileMap.vTOP] = false; } UpdateTile(x, y, TileTypeSelected, FloorTexture, WallTexture, FloorHeight); } } } break; case TileMap.TILE_SLOPE_E: { int HeightToSet = FloorHeight; if (MinX < TileX) { //Slopes up to this point HeightToSet = (HeightToSet + (Mathf.Abs(DimX) * -1)); } //else //{//slopes up from this point // HeightToSet= HeightToSet;//Mathf.Min(15, (HeightToSet + (DimX * 1))); //} for (int x = MinX; x <= MaxX; x++) { for (int y = MinY; y <= MaxY; y++) { if ( (TileMap.ValidTile(x, y)) && (HeightToSet >= 0) && (HeightToSet <= 15) ) { GameWorldController.instance.currentTileMap().Tiles[x, y].VisibleFaces[TileMap.vTOP] = true; if (FloorHeight != -1) { GameWorldController.instance.currentTileMap().Tiles[x, y].floorHeight = (short)HeightToSet; } GameWorldController.instance.currentTileMap().Tiles[x, y].shockSteep = 2; UpdateTile(x, y, TileTypeSelected, FloorTexture, WallTexture, HeightToSet); } } HeightToSet++; } } break; case TileMap.TILE_SLOPE_W: { int HeightToSet = FloorHeight; if (MinX < TileX) { //Slopes down this point HeightToSet = (HeightToSet + (Mathf.Abs(DimX) * +1)); } //else //{//slopes down from this point // HeightToSet= HeightToSet;//Mathf.Min(15, (HeightToSet + (DimX * 1))); //} for (int x = MinX; x <= MaxX; x++) { for (int y = MinY; y <= MaxY; y++) { if ( (TileMap.ValidTile(x, y)) && (HeightToSet >= 0) && (HeightToSet <= 15) ) { GameWorldController.instance.currentTileMap().Tiles[x, y].VisibleFaces[TileMap.vTOP] = true; if (FloorHeight != -1) { GameWorldController.instance.currentTileMap().Tiles[x, y].floorHeight = (short)HeightToSet; } GameWorldController.instance.currentTileMap().Tiles[x, y].shockSteep = 2; UpdateTile(x, y, TileTypeSelected, FloorTexture, WallTexture, HeightToSet); } } HeightToSet--; } } break; case TileMap.TILE_SLOPE_N: { int HeightToSet = FloorHeight; if (MinY < TileY) { //Slopes up to this point HeightToSet = (HeightToSet + (Mathf.Abs(DimY) * -1)); } //else //{//slopes up from this point // HeightToSet= HeightToSet;//Mathf.Min(15, (HeightToSet + (DimX * 1))); //} for (int y = MinY; y <= MaxY; y++) { for (int x = MinX; x <= MaxX; x++) { if ( (TileMap.ValidTile(x, y)) && (HeightToSet >= 0) && (HeightToSet <= 15) ) { GameWorldController.instance.currentTileMap().Tiles[x, y].VisibleFaces[TileMap.vTOP] = true; if (FloorHeight != -1) { GameWorldController.instance.currentTileMap().Tiles[x, y].floorHeight = (short)HeightToSet; } GameWorldController.instance.currentTileMap().Tiles[x, y].shockSteep = 2; UpdateTile(x, y, TileTypeSelected, FloorTexture, WallTexture, HeightToSet); } } HeightToSet++; } } break; case TileMap.TILE_SLOPE_S: { int HeightToSet = FloorHeight; if (MinX < TileX) { //Slopes down this point HeightToSet = (HeightToSet + (Mathf.Abs(DimY) * +1)); } //else //{//slopes down from this point // HeightToSet= HeightToSet;//Mathf.Min(15, (HeightToSet + (DimX * 1))); //} for (int y = MinY; y <= MaxY; y++) { for (int x = MinX; x <= MaxX; x++) { if ( (TileMap.ValidTile(x, y)) && (HeightToSet >= 0) && (HeightToSet <= 15) ) { GameWorldController.instance.currentTileMap().Tiles[x, y].VisibleFaces[TileMap.vTOP] = true; if (FloorHeight != -1) { GameWorldController.instance.currentTileMap().Tiles[x, y].floorHeight = (short)HeightToSet; } GameWorldController.instance.currentTileMap().Tiles[x, y].shockSteep = 2; UpdateTile(x, y, TileTypeSelected, FloorTexture, WallTexture, HeightToSet); } } HeightToSet--; } } break; case TileMap.TILE_DIAG_SE: case TileMap.TILE_DIAG_NW: { //Turns the smallest square of this tile type in the tile int MinSquare = Mathf.Abs(Mathf.Min(DimX, DimY)); for (int xy = 0; xy <= MinSquare; xy++) { if (TileMap.ValidTile(MinX + xy, MinY + xy)) { GameWorldController.instance.currentTileMap().Tiles[MinX + xy, MinY + xy].VisibleFaces[TileMap.vTOP] = true; UpdateTile(MinX + xy, MinY + xy, TileTypeSelected, FloorTexture, WallTexture, FloorHeight); } } break; } case TileMap.TILE_DIAG_SW: case TileMap.TILE_DIAG_NE: { //Turns the smallest square of this tile type in the tile int MinSquare = Mathf.Abs(Mathf.Min(DimX, DimY)); for (int xy = 0; xy <= MinSquare; xy++) { if (TileMap.ValidTile(MaxX - xy, MinY + xy)) { GameWorldController.instance.currentTileMap().Tiles[MaxX - xy, MinY + xy].VisibleFaces[TileMap.vTOP] = true; UpdateTile(MaxX - xy, MinY + xy, TileTypeSelected, FloorTexture, WallTexture, FloorHeight); } } break; } } } }
protected override void Start() { base.Start(); //Line up decals to walls where the decal is set to be on an edge. int tileX = ObjectTileX; int tileY = ObjectTileY; int x = xpos; int y = ypos; int decalheading = heading * 45; Vector3 objPos = this.transform.position; Vector3 adjustment = Vector3.zero; if (TileMap.ValidTile(tileX, tileY)) {//TODO:this is probably wrong!! switch (CurrentTileMap().Tiles[tileX, tileY].tileType) { case TileMap.TILE_OPEN: { if ((x == 0) && ((decalheading == ObjectInteraction.HEADINGSOUTH) || (decalheading == ObjectInteraction.HEADINGNORTH))) { //Move object Right. adjustment += new Vector3(0.2f, 0, 0); } if ((x == 7) && ((decalheading == ObjectInteraction.HEADINGSOUTH) || (decalheading == ObjectInteraction.HEADINGNORTH))) { //Move object left. adjustment += new Vector3(-0.2f, 0, 0); } if ((y == 0) && ((decalheading == ObjectInteraction.HEADINGEAST) || (decalheading == ObjectInteraction.HEADINGWEST))) { //move object forward adjustment += new Vector3(0, 0, 0.2f); } if ((y == 7) && ((decalheading == ObjectInteraction.HEADINGEAST) || (decalheading == ObjectInteraction.HEADINGWEST))) { //Move object backward.. adjustment += new Vector3(0, 0, -0.2f); } break; } case TileMap.TILE_DIAG_NW: if ((decalheading == ObjectInteraction.HEADINGNORTHWEST)) { //This decal clips into the wall adjustment += new Vector3(-0.02f, 0, +0.02f); } break; case TileMap.TILE_DIAG_NE: if ((decalheading == ObjectInteraction.HEADINGNORTHEAST)) { //This decal is out from the wall. adjustment += new Vector3(+0.02f, 0, +0.02f); } break; case TileMap.TILE_DIAG_SE: if ((decalheading == ObjectInteraction.HEADINGSOUTHEAST)) { //This decal is out from the wall. adjustment += new Vector3(-0.08f, 0, +0.08f); } break; case TileMap.TILE_DIAG_SW: if ((decalheading == ObjectInteraction.HEADINGSOUTHWEST)) { //This decal is out from the wall. adjustment += new Vector3(+0.08f, 0, +0.08f); } break; default: break; } this.transform.position = objPos + adjustment; } }
//cycles the tile textures between owner and quality. Mainly used in Talorus public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State) { TileMap tm = CurrentTileMap(); short maxTexture = quality; short minTexture = owner; for (int x = triggerX; x <= triggerX + 4; x++) { for (int y = triggerY; y <= triggerY + 4; y++) { if (TileMap.ValidTile(x, y)) { tm.Tiles[x, y].floorTexture++; if (tm.Tiles[x, y].floorTexture > maxTexture) { tm.Tiles[x, y].floorTexture = minTexture; } tm.Tiles[x, y].wallTexture++; if (tm.Tiles[x, y].wallTexture > maxTexture) { tm.Tiles[x, y].wallTexture = minTexture; } } } } CurrentTileMap().SetTileMapWallFacesUW(); //Tell the tells and their neighbours to rerender. for (int x = triggerX - 1; x <= triggerX + 5; x++) { for (int y = triggerY - 1; y <= triggerY + 5; y++) { if (TileMap.ValidTile(x, y)) { tm.Tiles[x, y].TileNeedsUpdate(); GameObject tile = null; GameObject tileWall = null; switch (tm.Tiles[x, y].tileType) { case TileMap.TILE_DIAG_NE: case TileMap.TILE_DIAG_SE: case TileMap.TILE_DIAG_NW: case TileMap.TILE_DIAG_SW: tile = GameWorldController.FindTile(x, y, TileMap.SURFACE_FLOOR); tileWall = GameWorldController.FindTile(x, y, TileMap.SURFACE_WALL); break; default: tile = GameWorldController.FindTile(x, y, TileMap.SURFACE_FLOOR); break; //default: } if (tile != null) { Destroy(tile); } if (tileWall != null) { Destroy(tileWall); } } } } }