Exemple #1
0
void AnalyseCaveMapForStructureInfo()
{
	LEVELNODE *pStruct;
	UINT32 uiTileType;
	INT32 iMapIndex;
	for( iMapIndex = 0; iMapIndex < WORLD_MAX; iMapIndex++ )
	{
		pStruct = gpWorldLevelData[ iMapIndex ].pStructHead;
		while( pStruct )
		{
			if ( pStruct->usIndex != NO_TILE )
			{
				GetTileType( pStruct->usIndex, &uiTileType );
				if( uiTileType == FIRSTWALL )
				{
					UINT16 usSubIndex;
					GetSubIndexFromTileIndex( pStruct->usIndex, &usSubIndex );
					if( usSubIndex >= 60 && usSubIndex <= 65 )
					{
						pStruct->uiFlags |= LEVELNODE_CAVE;
					}
				}
			}
			pStruct = pStruct->pNext;
		}
	}
}
Exemple #2
0
/*
void TerrainTest::_recalculateType(int x, int y)
{
	tile* t = GetTile(x, y);
	tile* t2;
	if (t)
		t->type = type;
	
	if (t->type == TILE_NORTHEDGE)
	{
		
	}
}
*/
void TerrainTest::Repair()
{
	tiletype type;
	tile* t;
	
	//fix invalid types
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{	
			_repairTile(x, y);	
		}	
	}
	
	//set types
	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{	
			t = GetTile(x, y);
			type = GetTileType(x, y);
			if (t)
				t->type = type;
		}		
	}
	
	//after all types are set, go again and reload
/*	for (int y = 0; y < height; y++)
	{
		for (int x = 0; x < width; x++)
		{	
			_recalculateType(x, y);
		}		
	}*/
}
Exemple #3
0
static void DisasterClearSquare(TileIndex tile)
{
	if (EnsureNoVehicleOnGround(tile).Failed()) return;

	switch (GetTileType(tile)) {
		case MP_RAILWAY:
			if (Company::IsHumanID(GetTileOwner(tile))) {
				Backup<CompanyByte> cur_company(_current_company, OWNER_WATER, FILE_LINE);
				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
				cur_company.Restore();

				/* update signals in buffer */
				UpdateSignalsInBuffer();
			}
			break;

		case MP_HOUSE: {
			Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
			cur_company.Restore();
			break;
		}

		case MP_TREES:
		case MP_CLEAR:
			DoClearSquare(tile);
			break;

		default:
			break;
	}
}
Exemple #4
0
		TILE(TileIndex tile, Trackdir td)
		{
			this->tile = tile;
			this->td = td;
			this->tile_type = GetTileType(tile);
			this->rail_type = GetTileRailType(tile);
		}
Exemple #5
0
/**
 * Clean up a depot
 */
Depot::~Depot()
{
	if (CleaningPool()) return;

	if (!IsDepotTile(this->xy) || GetDepotIndex(this->xy) != this->index) {
		/* It can happen there is no depot here anymore (TTO/TTD savegames) */
		return;
	}

	/* Clear the order backup. */
	OrderBackup::Reset(this->xy, false);

	/* Clear the depot from all order-lists */
	RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);

	/* Delete the depot-window */
	DeleteWindowById(WC_VEHICLE_DEPOT, this->xy);

	/* Delete the depot list */
	VehicleType vt;
	switch (GetTileType(this->xy)) {
		default: NOT_REACHED();
		case MP_RAILWAY: vt = VEH_TRAIN; break;
		case MP_ROAD:    vt = VEH_ROAD;  break;
		case MP_WATER:   vt = VEH_SHIP;  break;
	}
	DeleteWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(this->xy), this->index).Pack());
}
/**
 * Creates a tree tile
 * Ground type and density is preserved.
 *
 * @pre the tile must be suitable for trees.
 *
 * @param tile where to plant the trees.
 * @param treetype The type of the tree
 * @param count the number of trees (minus 1)
 * @param growth the growth status
 */
static void PlantTreesOnTile(TileIndex tile, TreeType treetype, uint count, uint growth)
{
	assert(treetype != TREE_INVALID);
	assert(CanPlantTreesOnTile(tile, true));

	TreeGround ground;
	uint density = 3;

	switch (GetTileType(tile)) {
		case MP_WATER:
			ground = TREE_GROUND_SHORE;
			break;

		case MP_CLEAR:
			switch (GetClearGround(tile)) {
				case CLEAR_GRASS:  ground = TREE_GROUND_GRASS;       break;
				case CLEAR_ROUGH:  ground = TREE_GROUND_ROUGH;       break;
				case CLEAR_SNOW:   ground = GetRawClearGround(tile) == CLEAR_ROUGH ? TREE_GROUND_ROUGH_SNOW : TREE_GROUND_SNOW_DESERT; break;
				default:           ground = TREE_GROUND_SNOW_DESERT; break;
			}
			if (GetClearGround(tile) != CLEAR_ROUGH) density = GetClearDensity(tile);
			break;

		default: NOT_REACHED();
	}

	MakeTree(tile, treetype, count, growth, ground, density);
}
Exemple #7
0
/**
 * Finds out if a given company's vehicles are allowed to enter a given tile.
 * @param owner    The owner of the vehicle.
 * @param tile     The tile that is about to be entered.
 * @param enterdir The direction in which the vehicle wants to enter the tile.
 * @return         true if the vehicle can enter the tile.
 * @todo           This function should be used in other places than just NPF,
 *                 maybe moved to another file too.
 */
static bool CanEnterTileOwnerCheck(Owner owner, TileIndex tile, DiagDirection enterdir)
{
	if (IsTileType(tile, MP_RAILWAY) || // Rail tile (also rail depot)
			HasStationTileRail(tile) ||     // Rail station tile/waypoint
			IsRoadDepotTile(tile) ||        // Road depot tile
			IsStandardRoadStopTile(tile)) { // Road station tile (but not drive-through stops)
		return IsTileOwner(tile, owner);  // You need to own these tiles entirely to use them
	}

	switch (GetTileType(tile)) {
		case MP_ROAD:
			/* rail-road crossing : are we looking at the railway part? */
			if (IsLevelCrossing(tile) &&
					DiagDirToAxis(enterdir) != GetCrossingRoadAxis(tile)) {
				return IsTileOwner(tile, owner); // Railway needs owner check, while the street is public
			}
			break;

		case MP_TUNNELBRIDGE:
			if (GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL) {
				return IsTileOwner(tile, owner);
			}
			break;

		default:
			break;
	}

	return true; // no need to check
}
Exemple #8
0
static void DisasterClearSquare(TileIndex tile)
{
	if (!EnsureNoVehicleOnGround(tile)) return;

	switch (GetTileType(tile)) {
		case MP_RAILWAY:
			if (Company::IsHumanID(GetTileOwner(tile))) {
				CompanyID old_company = _current_company;
				_current_company = OWNER_WATER;
				DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
				_current_company = old_company;

				/* update signals in buffer */
				UpdateSignalsInBuffer();
			}
			break;

		case MP_HOUSE: {
			CompanyID old_company = _current_company;
			_current_company = OWNER_NONE;
			DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
			_current_company = old_company;
			break;
		}

		case MP_TREES:
		case MP_CLEAR:
			DoClearSquare(tile);
			break;

		default:
			break;
	}
}
Exemple #9
0
/**
 * Mark tiles by mowing the grass when npf debug level >= 1.
 * Will not work for multiplayer games, since it can (will) cause desyncs.
 */
static void NPFMarkTile(TileIndex tile)
{
#ifndef NO_DEBUG_MESSAGES
	if (_debug_npf_level < 1 || _networking) return;
	switch (GetTileType(tile)) {
		case MP_RAILWAY:
			/* DEBUG: mark visited tiles by mowing the grass under them ;-) */
			if (!IsRailDepot(tile)) {
				SetRailGroundType(tile, RAIL_GROUND_BARREN);
				MarkTileDirtyByTile(tile);
			}
			break;

		case MP_ROAD:
			if (!IsRoadDepot(tile)) {
				SetRoadside(tile, ROADSIDE_BARREN);
				MarkTileDirtyByTile(tile);
			}
			break;

		default:
			break;
	}
#endif
}
BOOLEAN CalcBrokenWallInfoUsingSmartMethod( INT32 iMapIndex, UINT16 *pusWallType, UINT16 *pusIndex )
{
	LEVELNODE *pWall = NULL;
	UINT32 uiTileType;
	UINT16 usWallOrientation;

	if( gubBrokenWallUIValue == 2 ) //the hole in the wall
	{
		*pusWallType = 0xffff;
		*pusIndex = 0xffff;	//but it won't draw it.
		return TRUE;
	}

	pWall = GetVerticalWall( iMapIndex );
	if( pWall )
	{
		GetTileType( pWall->usIndex, &uiTileType );
		*pusWallType = (UINT16)uiTileType;
		if( uiTileType >= FIRSTDOOR && uiTileType <= LASTDOOR )
		{
			//We want to be able to replace doors with a walltype, however, the doors do not
			//contain the wall type, so we have to search for the nearest wall to extract it.
			*pusWallType = SearchForWallType( iMapIndex );
		}
		GetWallOrientation( pWall->usIndex, &usWallOrientation );
		*pusIndex = CalcSmartBrokenWallIndex( usWallOrientation ) - 1;
		return TRUE;
	}
	pWall = GetHorizontalWall( iMapIndex );
	if( pWall )
	{
		GetTileType( pWall->usIndex, &uiTileType );
		*pusWallType = (UINT16)uiTileType;
		if( uiTileType >= FIRSTDOOR && uiTileType <= LASTDOOR )
		{
			//We want to be able to replace doors with a walltype, however, the doors do not
			//contain the wall type, so we have to search for the nearest wall to extract it.
			*pusWallType = SearchForWallType( iMapIndex );
		}
		GetWallOrientation( pWall->usIndex, &usWallOrientation );
		*pusIndex = CalcSmartBrokenWallIndex( usWallOrientation ) - 1;
		return TRUE;
	}
	return FALSE;
}
Exemple #11
0
/**
 * Clean up unnecessary RoadBits of a planed tile.
 * @param tile current tile
 * @param org_rb planed RoadBits
 * @return optimised RoadBits
 */
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb)
{
	if (!IsValidTile(tile)) return ROAD_NONE;
	for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) {
		const TileIndex neighbor_tile = TileAddByDiagDir(tile, dir);

		/* Get the Roadbit pointing to the neighbor_tile */
		const RoadBits target_rb = DiagDirToRoadBits(dir);

		/* If the roadbit is in the current plan */
		if (org_rb & target_rb) {
			bool connective = false;
			const RoadBits mirrored_rb = MirrorRoadBits(target_rb);

			if (IsValidTile(neighbor_tile)) {
				switch (GetTileType(neighbor_tile)) {
					/* Always connective ones */
					case MP_CLEAR: case MP_TREES:
						connective = true;
						break;

					/* The conditionally connective ones */
					case MP_TUNNELBRIDGE:
					case MP_STATION:
					case MP_ROAD:
						if (IsNormalRoadTile(neighbor_tile)) {
							/* Always connective */
							connective = true;
						} else {
							const RoadBits neighbor_rb = GetAnyRoadBits(neighbor_tile, ROADTYPE_ROAD) | GetAnyRoadBits(neighbor_tile, ROADTYPE_TRAM);

							/* Accept only connective tiles */
							connective = (neighbor_rb & mirrored_rb) != ROAD_NONE;
						}
						break;

					case MP_RAILWAY:
						connective = IsPossibleCrossing(neighbor_tile, DiagDirToAxis(dir));
						break;

					case MP_WATER:
						/* Check for real water tile */
						connective = !IsWater(neighbor_tile);
						break;

					/* The definitely not connective ones */
					default: break;
				}
			}

			/* If the neighbor tile is inconnective, remove the planed road connection to it */
			if (!connective) org_rb ^= target_rb;
		}
	}

	return org_rb;
}
int CASW_Hack_Wire_Tile::GetTileType(int iWire, int x, int y)
{
	if (x < 0 || x>=m_iNumColumns || y<0 || y >= m_iNumRows)
	{
		Msg("Tile coords out of bounds! %d,%d\n", x, y);
		return -1;
	}
	return GetTileType(iWire, y * m_iNumColumns + x);
}
Exemple #13
0
/* Determine the cost of this node, for road tracks */
static int32 NPFRoadPathCost(AyStar *as, AyStarNode *current, OpenListNode *parent)
{
	TileIndex tile = current->tile;
	int32 cost = 0;

	/* Determine base length */
	switch (GetTileType(tile)) {
		case MP_TUNNELBRIDGE:
			cost = IsTunnel(tile) ? NPFTunnelCost(current) : NPFBridgeCost(current);
			break;

		case MP_ROAD:
			cost = NPF_TILE_LENGTH;
			/* Increase the cost for level crossings */
			if (IsLevelCrossing(tile)) cost += _settings_game.pf.npf.npf_crossing_penalty;
			break;

		case MP_STATION: {
			cost = NPF_TILE_LENGTH;
			const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
			if (IsDriveThroughStopTile(tile)) {
				/* Increase the cost for drive-through road stops */
				cost += _settings_game.pf.npf.npf_road_drive_through_penalty;
				DiagDirection dir = TrackdirToExitdir(current->direction);
				if (!RoadStop::IsDriveThroughRoadStopContinuation(tile, tile - TileOffsByDiagDir(dir))) {
					/* When we're the first road stop in a 'queue' of them we increase
					 * cost based on the fill percentage of the whole queue. */
					const RoadStop::Entry *entry = rs->GetEntry(dir);
					cost += entry->GetOccupied() * _settings_game.pf.npf.npf_road_dt_occupied_penalty / entry->GetLength();
				}
			} else {
				/* Increase cost for filled road stops */
				cost += _settings_game.pf.npf.npf_road_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
			}
			break;
		}

		default:
			break;
	}

	/* Determine extra costs */

	/* Check for slope */
	cost += NPFSlopeCost(current);

	/* Check for turns. Road vehicles only really drive diagonal, turns are
	 * represented by non-diagonal tracks */
	if (!IsDiagonalTrackdir(current->direction)) {
		cost += _settings_game.pf.npf.npf_road_curve_penalty;
	}

	NPFMarkTile(tile);
	DEBUG(npf, 4, "Calculating G for: (%d, %d). Result: %d", TileX(current->tile), TileY(current->tile), cost);
	return cost;
}
Exemple #14
0
//this is moving in X direction
bool Character::CheckNextXPositionGoingLeft(float nextPosX, float nextPosY)
{
    float height = GetHeight()*Constants::TileSize();

    //check if tile is going off bounds return false;
    if ((nextPosX) / Constants::TileSize() < 0) {
        return false;
    }

    for (int i = 0; i < height; i++)
    {
        auto cellFuture = &cellMap_->at((nextPosX) / Constants::TileSize()).at((nextPosY + i) / Constants::TileSize());
        if (cellFuture->GetTileType() == TILETYPE::SOLIDTILE || cellFuture->GetTileType() == TILETYPE::COLLISIONRIGHTTILE)
        {
            return false;
        }
    }
    return true;
}
// check if the top left tile is connected on the left
bool CASW_Hack_Wire_Tile::StartTileConnected(int iWire)
{
	int iTileType1 = GetTileType(iWire, 0, 0);
	int iTileRotation1 = GetTileRotation(iWire, 0, 0);
	
	int i = 3 - iTileRotation1;
	if (i < 0)
		i += 4;	
	//Msg("start tile type %d rot %d modified %d\n", iTileType1, iTileRotation1, i);

	return g_TileConnections[iTileType1][i];
}
bool CASW_Hack_Wire_Tile::EndTileConnected(int iWire)
{
	int iTileType1 = GetTileType(iWire, m_iNumColumns-1, m_iNumRows-1);
	int iTileRotation1 = GetTileRotation(iWire, m_iNumColumns-1, m_iNumRows-1);
	
	int i = 1 - iTileRotation1;
	if (i < 0)
		i += 4;	
	//Msg("end tile type %d rot %d modified %d\n", iTileType1, iTileRotation1, i);

	return g_TileConnections[iTileType1][i];
}
void
TiledDeprecatedTextureHostOGL::DeleteTextures()
{
  if (mTextureHandle) {
    mGL->MakeCurrent();
    mGL->fDeleteTextures(1, &mTextureHandle);

    gl::GLContext::UpdateTextureMemoryUsage(gl::GLContext::MemoryFreed, mGLFormat,
                                            GetTileType(), TILEDLAYERBUFFER_TILE_SIZE);
    mTextureHandle = 0;
  }
}
Exemple #18
0
void Player::WalkPlayer(Direction::Direction direction) {
   auto currentLandmark = GameState::Get().GetCurrentLandmark();
   auto newX = 0, newY = 0;
   switch (direction) {
      case Direction::Up:
         if (this->PositionX == 0)
            return;
         newX = this->GetPositionX();
         newY = this->GetPositionY() - 1;
         break;

      case Direction::Down:
         if (this->PositionY == (currentLandmark->GetHeight() - 1))
            return;
         newX = this->GetPositionX();
         newY = this->GetPositionY() + 1;
         break;

      case Direction::Left:
         if (this->PositionX == 0)
            return;
         newX = this->GetPositionX() - 1;
         newY = this->GetPositionY();
         break;

      case Direction::Right:
         if (this->PositionX == (currentLandmark->GetWidth() - 1))
            return;
         newX = this->GetPositionX() + 1;
         newY = this->GetPositionY();
         break;
   }

   if (!this->IsPassable(newX, newY)) {

      auto prop = currentLandmark->GetProp(newX, newY);
      if (prop != nullptr &&
            !Tile::HasSurfaceAttribute(Tile::FromTileType(prop->GetTileType()), SurfaceAttribute::Walkable)) {

         bool startsWithVowel = prop->GetName().find_first_of("aAeEiIoOuU") == 0;
         GameState::Get().AddLogMessageFmt("You are blocked by %s %s.", (startsWithVowel ? "an" : "a"),
                                           prop->GetName().c_str());
         return;
      }

      auto tile = currentLandmark->GetTile(newX, newY);
      bool startsWithVowel = tile.Name.find_first_of("aAeEiIoOuU") == 0;
      GameState::Get().AddLogMessageFmt("You are blocked by %s %s.", (startsWithVowel ? "an" : "a"), tile.Name.c_str());
      return;
   }

   this->WarpPlayer(newX, newY);
}
Exemple #19
0
bool Player::IsPassable(int x, int y) {
   auto currentLandmark = GameState::Get().GetCurrentLandmark();
   auto tile = currentLandmark->GetTile(x, y);
   if (!Tile::HasSurfaceAttribute(tile, SurfaceAttribute::Walkable)) {
      return false;
   }
   auto prop = currentLandmark->GetProp(x, y);
   if (prop == nullptr) {
      return true;
   }

   return Tile::HasSurfaceAttribute(Tile::FromTileType(prop->GetTileType()), SurfaceAttribute::Walkable);
}
/**
 * Tests if a tile can be converted to MP_TREES
 * This is true for clear ground without farms or rocks.
 *
 * @param tile the tile of interest
 * @param allow_desert Allow planting trees on CLEAR_DESERT?
 * @return true if trees can be built.
 */
static bool CanPlantTreesOnTile(TileIndex tile, bool allow_desert)
{
	switch (GetTileType(tile)) {
		case MP_WATER:
			return !IsBridgeAbove(tile) && IsCoast(tile) && !IsSlopeWithOneCornerRaised(GetTileSlope(tile, NULL));

		case MP_CLEAR:
			return !IsBridgeAbove(tile) && !IsClearGround(tile, CLEAR_FIELDS) && GetRawClearGround(tile) != CLEAR_ROCKS &&
			       (allow_desert || !IsClearGround(tile, CLEAR_DESERT));

		default: return false;
	}
}
Exemple #21
0
//this is moving in Y direction
bool Character::CheckNextYPositionFalling(float nextPosX, float nextPosY)
{
    float width = GetWidth()*Constants::TileSize();
    //check if tile is going off bounds return false;
    if ((nextPosY) / Constants::TileSize() + GetHeight() >= mapHeight_) {
        SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERONGROUND);
        SetVelocityY(0.125);
        //set no moving
        return false;
    }
    for (int i = 0; i < width; i++)
    {
        auto cellFuture = &cellMap_->at((nextPosX + i) / Constants::TileSize()).at((nextPosY) / Constants::TileSize() + GetHeight());
        if (cellFuture->GetTileType() == TILETYPE::SOLIDTILE || cellFuture->GetTileType() == TILETYPE::COLLISIONTOPTILE)
        {
            SetCurrentPositionY(cellFuture->GetCurrentPositionY() - GetHeight());
            SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERONGROUND);
            SetVelocityY(0.125);
            return false;
        }
    }
    return true;
}
ScriptVehicleList_Depot::ScriptVehicleList_Depot(TileIndex tile)
{
	if (!ScriptMap::IsValidTile(tile)) return;

	DestinationID dest;
	VehicleType type;

	switch (GetTileType(tile)) {
		case MP_STATION: // Aircraft
			if (!IsAirport(tile)) return;
			type = VEH_AIRCRAFT;
			dest = GetStationIndex(tile);
			break;

		case MP_RAILWAY:
			if (!IsRailDepot(tile)) return;
			type = VEH_TRAIN;
			dest = GetDepotIndex(tile);
			break;

		case MP_ROAD:
			if (!IsRoadDepot(tile)) return;
			type = VEH_ROAD;
			dest = GetDepotIndex(tile);
			break;

		case MP_WATER:
			if (!IsShipDepot(tile)) return;
			type = VEH_SHIP;
			dest = GetDepotIndex(tile);
			break;

		default: // No depot
			return;
	}

	const Vehicle *v;
	FOR_ALL_VEHICLES(v) {
		if ((v->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && v->IsPrimaryVehicle() && v->type == type) {
			const Order *order;

			FOR_VEHICLE_ORDERS(v, order) {
				if (order->IsType(OT_GOTO_DEPOT) && order->GetDestination() == dest) {
					this->AddItem(v->index);
					break;
				}
			}
		}
	}
}
void AfterLoadLabelMaps()
{
	if (NeedRailTypeConversion()) {
		SmallVector<RailType, RAILTYPE_END> railtype_conversion_map;

		for (uint i = 0; i < _railtype_list.Length(); i++) {
			RailType r = GetRailTypeByLabel(_railtype_list[i]);
			if (r == INVALID_RAILTYPE) r = RAILTYPE_BEGIN;

			*railtype_conversion_map.Append() = r;
		}

		for (TileIndex t = 0; t < MapSize(); t++) {
			switch (GetTileType(t)) {
				case MP_RAILWAY:
					SetRailType(t, railtype_conversion_map[GetRailType(t)]);
					break;

				case MP_ROAD:
					if (IsLevelCrossing(t)) {
						SetRailType(t, railtype_conversion_map[GetRailType(t)]);
					}
					break;

				case MP_STATION:
					if (HasStationRail(t)) {
						SetRailType(t, railtype_conversion_map[GetRailType(t)]);
					}
					break;

				case MP_TUNNELBRIDGE:
					if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
						SetRailType(t, railtype_conversion_map[GetRailType(t)]);
					}
					break;

				default:
					break;
			}
		}
	}

	_railtype_list.Clear();
}
    /** return one tile cost */
    inline int OneTileCost(TileIndex tile, Trackdir trackdir)
    {
        int cost = 0;
        /* set base cost */
        if (IsDiagonalTrackdir(trackdir)) {
            cost += YAPF_TILE_LENGTH;
            switch (GetTileType(tile)) {
            case MP_ROAD:
                /* Increase the cost for level crossings */
                if (IsLevelCrossing(tile)) {
                    cost += Yapf().PfGetSettings().road_crossing_penalty;
                }
                break;

            case MP_STATION: {
                const RoadStop *rs = RoadStop::GetByTile(tile, GetRoadStopType(tile));
                if (IsDriveThroughStopTile(tile)) {
                    /* Increase the cost for drive-through road stops */
                    cost += Yapf().PfGetSettings().road_stop_penalty;
                    DiagDirection dir = TrackdirToExitdir(trackdir);
                    if (!RoadStop::IsDriveThroughRoadStopContinuation(tile, tile - TileOffsByDiagDir(dir))) {
                        /* When we're the first road stop in a 'queue' of them we increase
                         * cost based on the fill percentage of the whole queue. */
                        const RoadStop::Entry *entry = rs->GetEntry(dir);
                        cost += entry->GetOccupied() * Yapf().PfGetSettings().road_stop_occupied_penalty / entry->GetLength();
                    }
                } else {
                    /* Increase cost for filled road stops */
                    cost += Yapf().PfGetSettings().road_stop_bay_occupied_penalty * (!rs->IsFreeBay(0) + !rs->IsFreeBay(1)) / 2;
                }
                break;
            }

            default:
                break;
            }
        } else {
            /* non-diagonal trackdir */
            cost = YAPF_TILE_CORNER_LENGTH + Yapf().PfGetSettings().road_curve_penalty;
        }
        return cost;
    }
/**
 * Rename a depot.
 * @param tile unused
 * @param flags type of operation
 * @param p1 id of depot
 * @param p2 unused
 * @param text the new name or an empty string when resetting to the default
 * @return the cost of this operation or an error
 */
CommandCost CmdRenameDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
	Depot *d = Depot::GetIfValid(p1);
	if (d == NULL) return CMD_ERROR;

	CommandCost ret = CheckTileOwnership(d->xy);
	if (ret.Failed()) return ret;

	bool reset = StrEmpty(text);

	if (!reset) {
		if (Utf8StringLength(text) >= MAX_LENGTH_DEPOT_NAME_CHARS) return CMD_ERROR;
		if (!IsUniqueDepotName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
	}

	if (flags & DC_EXEC) {
		free(d->name);

		if (reset) {
			d->name = NULL;
			MakeDefaultName(d);
		} else {
			d->name = strdup(text);
		}

		/* Update the orders and depot */
		SetWindowClassesDirty(WC_VEHICLE_ORDERS);
		SetWindowDirty(WC_VEHICLE_DEPOT, d->xy);

		/* Update the depot list */
		VehicleType vt;
		switch (GetTileType(d->xy)) {
			default: NOT_REACHED();
			case MP_RAILWAY: vt = VEH_TRAIN; break;
			case MP_ROAD:    vt = VEH_ROAD;  break;
			case MP_WATER:   vt = VEH_SHIP;  break;
		}
		SetWindowDirty(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_DEPOT_LIST, vt, GetTileOwner(d->xy), d->index).Pack());
	}
	return CommandCost();
}
Exemple #26
0
//this is moving in Y direction
bool Character::CheckNextYPositionJumping(float nextPosX, float nextPosY)
{
    float width = GetWidth()*Constants::TileSize();
    //check if tile is going off bounds return false;
    if ((nextPosY) / Constants::TileSize() < 0) {
        SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);
        SetVelocityY(0.125);
        //set no moving
        return false;
    }
    for (int i = 0; i < width; i++)
    {
        auto cellFuture = &cellMap_->at((nextPosX + i) / Constants::TileSize()).at((nextPosY) / Constants::TileSize() );
        if (cellFuture->GetTileType() == TILETYPE::SOLIDTILE)
        {
            SetCharacterYAxisState(CHARACTERYAXISSTATES::CHARACTERFALLING);
            SetVelocityY(0.125);
            return false;
        }
    }
    return true;
}
void
TiledDeprecatedTextureHostOGL::Update(gfxReusableSurfaceWrapper* aReusableSurface, TextureFlags aFlags, const gfx::IntSize& aSize)
{
  mSize = aSize;
  mGL->MakeCurrent();
  if (aFlags & TEXTURE_NEW_TILE) {
    SetFlags(aFlags);
    mGL->fGenTextures(1, &mTextureHandle);
    mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
    mGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
    mGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
    mGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
    mGL->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
  } else {
    mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextureHandle);
    // We're re-using a texture, but the format may change. Update the memory
    // reporter with a free and alloc (below) using the old and new formats.
    gl::GLContext::UpdateTextureMemoryUsage(gl::GLContext::MemoryFreed, mGLFormat,
                                            GetTileType(), TILEDLAYERBUFFER_TILE_SIZE);
  }

  GLenum type;
  GetFormatAndTileForImageFormat(aReusableSurface->Format(), mGLFormat, type);

  const unsigned char* buf = aReusableSurface->GetReadOnlyData();
  mGL->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, mGLFormat,
                   TILEDLAYERBUFFER_TILE_SIZE, TILEDLAYERBUFFER_TILE_SIZE, 0,
                   mGLFormat, type, buf);

  gl::GLContext::UpdateTextureMemoryUsage(gl::GLContext::MemoryAllocated, mGLFormat,
                                          type, TILEDLAYERBUFFER_TILE_SIZE);

  if (mGLFormat == LOCAL_GL_RGB) {
    mFormat = FORMAT_R8G8B8X8;
  } else {
    mFormat = FORMAT_B8G8R8A8;
  }
}
Exemple #28
0
	/** Return one tile cost (base cost + level crossing penalty). */
	inline int OneTileCost(TileIndex& tile, Trackdir trackdir)
	{
		int cost = 0;
		/* set base cost */
		if (IsDiagonalTrackdir(trackdir)) {
			cost += YAPF_TILE_LENGTH;
			switch (GetTileType(tile)) {
				case MP_ROAD:
					/* Increase the cost for level crossings */
					if (IsLevelCrossing(tile)) {
						cost += Yapf().PfGetSettings().rail_crossing_penalty;
					}
					break;

				default:
					break;
			}
		} else {
			/* non-diagonal trackdir */
			cost = YAPF_TILE_CORNER_LENGTH;
		}
		return cost;
	}
/**
 * Do a sequential copy-pasting by calling appropriate CopyPasteCommandProc on each selected tile.
 * @param copy_paste What, where and how we are copying.
 */
static inline void DoCopyPaste(const CopyPasteParams &copy_paste)
{
	/* Copying to the clipboard buffer should always success.
	 * Some content may be intransformable (e.g. airport) so we can't use any transformation. */
	assert(IsMainMapTile(copy_paste.dst_area.tile) || (copy_paste.transformation == DTR_IDENTITY && (copy_paste.mode & CPM_TERRAFORM_MASK) == CPM_TERRAFORM_FULL));

	if ((copy_paste.mode & CPM_TERRAFORM_MASK) == CPM_TERRAFORM_FULL) {
		CopyPasteHeights(copy_paste.src_area, copy_paste.dst_area.tile, copy_paste.transformation, copy_paste.height_delta);
		if (IsPastingInterrupted()) return;
	}

	for (TransformationTileIteratorT<true, true> ti(copy_paste.src_area, copy_paste.src_area.TransformedNorth(copy_paste.dst_area.tile, copy_paste.transformation), copy_paste.transformation); IsValidTileIndex(ti); ++ti) {
		CopyPasteTileProc *proc = _tile_type_procs[GetTileType(ti.SrcTile())]->copy_paste_tile_proc;
		if (proc == NULL) continue;
		proc(ti.SrcTile(), ti.DstTile(), copy_paste);
		if (IsPastingInterrupted()) break;
	}

	if (IsMainMapTile(copy_paste.dst_area.tile)) {
		AfterPastingStations(copy_paste);
	} else {
		AfterCopyingStations(copy_paste);
	}
}
Exemple #30
0
void GPath::FindTile(GNode* gnode, int x, int y, int dir) {
  if(TileInBounds(x, y)) {
    //check whether we already have it
    GNode* node = GetNode(x, y);
    if (NULL == node) {     
      int type = GetTileType(x, y);
      if (!IsWrongType(type)) {
	GNode* node = new GNode(x, y);
	node->SetParent(gnode);
	node->CalcF(DestX, DestY, dir);
  	App->Log << "**********\n";
  	App->Log << "Open tile:\n";
	App->Log << "x: " << node->GetX();
	App->Log << " y: " << node->GetY();
	App->Log << " G: " << node->GetG();
	App->Log << " H: " << node->GetH();
	App->Log << " F: " << node->GetF() << std::endl;
	SetNode(node);
	Open.push(node);
      }
    } // null == node
    else if (node->IsOpen()) {      
      //check if this path is better
      int pts;
      if (DIR_HV == dir) 
	pts = PTS_HV;
      else
	pts = PTS_DIAG; 

      if (gnode->GetG() + pts < node->GetG()) {
	node->SetParent(gnode);
	node->CalcF(DestX, DestY, dir);	
      }	
    } //IsOpen()
  } // in bounds
}