Changeset - r12077:baf868e4baf0
[Not reviewed]
src/ai/api/ai_order.cpp
Show inline comments
 
@@ -110,36 +110,36 @@ static const Order *ResolveOrder(Vehicle
 
{
 
	if (!AIVehicle::IsValidVehicle(vehicle_id)) return ORDER_INVALID;
 

	
 
	if (order_position == ORDER_CURRENT) return (AIOrder::OrderPosition)::Vehicle::Get(vehicle_id)->cur_order_index;
 
	return (order_position >= 0 && order_position < ::Vehicle::Get(vehicle_id)->GetNumOrders()) ? order_position : ORDER_INVALID;
 
}
 

	
 

	
 
/* static */ bool AIOrder::AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags)
 
{
 
	switch (::GetOrderTypeByTile(destination)) {
 
		case OT_GOTO_STATION:
 
			return ((order_flags & ~(AIOF_NON_STOP_FLAGS | AIOF_UNLOAD_FLAGS | AIOF_LOAD_FLAGS)) == 0) &&
 
			return (order_flags & ~(AIOF_NON_STOP_FLAGS | AIOF_UNLOAD_FLAGS | AIOF_LOAD_FLAGS)) == 0 &&
 
					/* Test the different mutual exclusive flags. */
 
					(((order_flags & AIOF_TRANSFER)      == 0) || ((order_flags & AIOF_UNLOAD)    == 0)) &&
 
					(((order_flags & AIOF_TRANSFER)      == 0) || ((order_flags & AIOF_NO_UNLOAD) == 0)) &&
 
					(((order_flags & AIOF_UNLOAD)        == 0) || ((order_flags & AIOF_NO_UNLOAD) == 0)) &&
 
					(((order_flags & AIOF_UNLOAD)        == 0) || ((order_flags & AIOF_NO_UNLOAD) == 0)) &&
 
					(((order_flags & AIOF_NO_UNLOAD)     == 0) || ((order_flags & AIOF_NO_LOAD)   == 0)) &&
 
					(((order_flags & AIOF_FULL_LOAD_ANY) == 0) || ((order_flags & AIOF_NO_LOAD)   == 0));
 
					((order_flags & AIOF_TRANSFER)      == 0 || (order_flags & AIOF_UNLOAD)    == 0) &&
 
					((order_flags & AIOF_TRANSFER)      == 0 || (order_flags & AIOF_NO_UNLOAD) == 0) &&
 
					((order_flags & AIOF_UNLOAD)        == 0 || (order_flags & AIOF_NO_UNLOAD) == 0) &&
 
					((order_flags & AIOF_UNLOAD)        == 0 || (order_flags & AIOF_NO_UNLOAD) == 0) &&
 
					((order_flags & AIOF_NO_UNLOAD)     == 0 || (order_flags & AIOF_NO_LOAD)   == 0) &&
 
					((order_flags & AIOF_FULL_LOAD_ANY) == 0 || (order_flags & AIOF_NO_LOAD)   == 0);
 

	
 
		case OT_GOTO_DEPOT:
 
			return ((order_flags & ~(AIOF_NON_STOP_FLAGS | AIOF_DEPOT_FLAGS)) == 0) &&
 
					(((order_flags & AIOF_SERVICE_IF_NEEDED) == 0) || ((order_flags & AIOF_STOP_IN_DEPOT) == 0));
 
			return (order_flags & ~(AIOF_NON_STOP_FLAGS | AIOF_DEPOT_FLAGS)) == 0 &&
 
					((order_flags & AIOF_SERVICE_IF_NEEDED) == 0 || (order_flags & AIOF_STOP_IN_DEPOT) == 0);
 

	
 
		case OT_GOTO_WAYPOINT: return (order_flags & ~(AIOF_NON_STOP_FLAGS)) == 0;
 
		default:               return false;
 
	}
 
}
 

	
 
/* static */ bool AIOrder::IsValidConditionalOrder(OrderCondition condition, CompareFunction compare)
 
{
 
	switch (condition) {
 
		case OC_LOAD_PERCENTAGE:
 
		case OC_RELIABILITY:
 
		case OC_MAX_SPEED:
src/ai/api/ai_town.cpp
Show inline comments
 
@@ -174,23 +174,23 @@
 
/* static */ int AITown::GetAllowedNoise(TownID town_id)
 
{
 
	if (!IsValidTown(town_id)) return -1;
 

	
 
	const Town *t = ::Town::Get(town_id);
 
	if (_settings_game.economy.station_noise_level) {
 
		return t->MaxTownNoise() - t->noise_reached;
 
	}
 

	
 
	int num = 0;
 
	const Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++;
 
		if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport_type != AT_OILRIG) num++;
 
	}
 
	return max(0, 2 - num);
 
}
 

	
 
/* static */ AITown::RoadLayout AITown::GetRoadLayout(TownID town_id)
 
{
 
	if (!IsValidTown(town_id)) return ROAD_LAYOUT_INVALID;
 

	
 
	return (AITown::RoadLayout)((TownLayout)::Town::Get(town_id)->layout);
 
}
src/aircraft_cmd.cpp
Show inline comments
 
@@ -101,52 +101,51 @@ static StationID FindNearestHangar(const
 
{
 
	const Station *st;
 
	uint best = 0;
 
	StationID index = INVALID_STATION;
 
	TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
 

	
 
	FOR_ALL_STATIONS(st) {
 
		if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT)) continue;
 

	
 
		const AirportFTAClass *afc = st->Airport();
 
		if (afc->nof_depots == 0 || (
 
					/* don't crash the plane if we know it can't land at the airport */
 
					afc->flags & AirportFTAClass::SHORT_STRIP &&
 
					AircraftVehInfo(v->engine_type)->subtype & AIR_FAST &&
 
					!_cheats.no_jetcrash.value
 
				)) {
 
					(afc->flags & AirportFTAClass::SHORT_STRIP) &&
 
					(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
 
					!_cheats.no_jetcrash.value)) {
 
			continue;
 
		}
 

	
 
		/* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */
 
		uint distance = DistanceSquare(vtile, st->airport_tile);
 
		if (distance < best || index == INVALID_STATION) {
 
			best = distance;
 
			index = st->index;
 
		}
 
	}
 
	return index;
 
}
 

	
 
#if 0
 
/** Check if given vehicle has a goto hangar in his orders
 
 * @param v vehicle to inquiry
 
 * @return true if vehicle v has an airport in the schedule, that has a hangar */
 
static bool HaveHangarInOrderList(Aircraft *v)
 
{
 
	const Order *order;
 

	
 
	FOR_VEHICLE_ORDERS(v, order) {
 
		const Station *st = Station::Get(order->station);
 
		if (st->owner == v->owner && st->facilities & FACIL_AIRPORT) {
 
		if (st->owner == v->owner && (st->facilities & FACIL_AIRPORT)) {
 
			/* If an airport doesn't have a hangar, skip it */
 
			if (st->Airport()->nof_depots != 0)
 
				return true;
 
		}
 
	}
 

	
 
	return false;
 
}
 
#endif
 

	
 
SpriteID Aircraft::GetImage(Direction direction) const
 
{
 
@@ -1048,25 +1047,25 @@ static bool AircraftController(Aircraft 
 
	if (amd->flag & AMED_LAND)       { speed_limit = SPEED_LIMIT_APPROACH; hard_limit = false; }
 
	if (amd->flag & AMED_BRAKE)      { speed_limit = SPEED_LIMIT_TAXI;     hard_limit = false; }
 

	
 
	count = UpdateAircraftSpeed(v, speed_limit, hard_limit);
 
	if (count == 0) return false;
 

	
 
	if (v->load_unload_time_rem != 0) v->load_unload_time_rem--;
 

	
 
	do {
 

	
 
		GetNewVehiclePosResult gp;
 

	
 
		if (dist < 4 || amd->flag & AMED_LAND) {
 
		if (dist < 4 || (amd->flag & AMED_LAND)) {
 
			/* move vehicle one pixel towards target */
 
			gp.x = (v->x_pos != (x + amd->x)) ?
 
					v->x_pos + ((x + amd->x > v->x_pos) ? 1 : -1) :
 
					v->x_pos;
 
			gp.y = (v->y_pos != (y + amd->y)) ?
 
					v->y_pos + ((y + amd->y > v->y_pos) ? 1 : -1) :
 
					v->y_pos;
 

	
 
			/* Oilrigs must keep v->tile as st->airport_tile, since the landing pad is in a non-airport tile */
 
			gp.new_tile = (st->airport_type == AT_OILRIG) ? st->airport_tile : TileVirtXY(gp.x, gp.y);
 

	
 
		} else {
 
@@ -1325,26 +1324,26 @@ static void CrashAirplane(Aircraft *v)
 
		v->index,
 
		st != NULL ? st->index : INVALID_STATION);
 

	
 
	SndPlayVehicleFx(SND_12_EXPLOSION, v);
 
}
 

	
 
static void MaybeCrashAirplane(Aircraft *v)
 
{
 
	Station *st = Station::Get(v->targetairport);
 

	
 
	/* FIXME -- MaybeCrashAirplane -> increase crashing chances of very modern airplanes on smaller than AT_METROPOLITAN airports */
 
	uint16 prob = 0x10000 / 1500;
 
	if (st->Airport()->flags & AirportFTAClass::SHORT_STRIP &&
 
			AircraftVehInfo(v->engine_type)->subtype & AIR_FAST &&
 
	if ((st->Airport()->flags & AirportFTAClass::SHORT_STRIP) &&
 
			(AircraftVehInfo(v->engine_type)->subtype & AIR_FAST) &&
 
			!_cheats.no_jetcrash.value) {
 
		prob = 0x10000 / 20;
 
	}
 

	
 
	if (GB(Random(), 0, 16) > prob) return;
 

	
 
	/* Crash the airplane. Remove all goods stored at the station. */
 
	for (CargoID i = 0; i < NUM_CARGO; i++) {
 
		st->goods[i].rating = 1;
 
		st->goods[i].cargo.Truncate(0);
 
	}
 

	
 
@@ -1608,25 +1607,25 @@ static void AircraftEventHandler_HeliTak
 
	if (CheckSendAircraftToHangarForReplacement(v)) {
 
		_current_company = v->owner;
 
		DoCommand(v->tile, v->index, DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, DC_EXEC, CMD_SEND_AIRCRAFT_TO_HANGAR);
 
		_current_company = OWNER_NONE;
 
	}
 
}
 

	
 
static void AircraftEventHandler_Flying(Aircraft *v, const AirportFTAClass *apc)
 
{
 
	Station *st = Station::Get(v->targetairport);
 

	
 
	/* runway busy or not allowed to use this airstation, circle */
 
	if (apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES) &&
 
	if ((apc->flags & (v->subtype == AIR_HELICOPTER ? AirportFTAClass::HELICOPTERS : AirportFTAClass::AIRPLANES)) &&
 
			st->airport_tile != INVALID_TILE &&
 
			(st->owner == OWNER_NONE || st->owner == v->owner)) {
 
		/* {32,FLYING,NOTHING_block,37}, {32,LANDING,N,33}, {32,HELILANDING,N,41},
 
		 * if it is an airplane, look for LANDING, for helicopter HELILANDING
 
		 * it is possible to choose from multiple landing runways, so loop until a free one is found */
 
		byte landingtype = (v->subtype == AIR_HELICOPTER) ? HELILANDING : LANDING;
 
		const AirportFTA *current = apc->layout[v->pos].next;
 
		while (current != NULL) {
 
			if (current->heading == landingtype) {
 
				/* save speed before, since if AirportHasBlock is false, it resets them to 0
 
				 * we don't want that for plane in air
 
				 * hack for speed thingie */
src/economy.cpp
Show inline comments
 
@@ -1116,25 +1116,25 @@ void VehiclePayment(Vehicle *front_v)
 
	/* At this moment loading cannot be finished */
 
	ClrBit(front_v->vehicle_flags, VF_LOADING_FINISHED);
 

	
 
	/* Start unloading in at the first possible moment */
 
	front_v->load_unload_time_rem = 1;
 

	
 
	/* Collect delivered industries */
 
	static SmallIndustryList industry_set;
 
	industry_set.Clear();
 

	
 
	for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
 
		/* No cargo to unload */
 
		if (v->cargo_cap == 0 || v->cargo.Empty() || front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD) continue;
 
		if (v->cargo_cap == 0 || v->cargo.Empty() || (front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD)) continue;
 

	
 
		/* All cargo has already been paid for, no need to pay again */
 
		if (!v->cargo.UnpaidCargo()) {
 
			SetBit(v->vehicle_flags, VF_CARGO_UNLOADING);
 
			continue;
 
		}
 

	
 
		GoodsEntry *ge = &st->goods[v->cargo_type];
 
		const CargoList::List *cargos = v->cargo.Packets();
 

	
 
		for (CargoList::List::const_iterator it = cargos->begin(); it != cargos->end(); it++) {
 
			CargoPacket *cp = *it;
 
@@ -1271,25 +1271,25 @@ static void LoadUnloadVehicle(Vehicle *v
 
				/* The cargo has reached it's final destination, the packets may now be destroyed */
 
				remaining = v->cargo.MoveTo(NULL, amount_unloaded, CargoList::MTA_FINAL_DELIVERY, last_visited);
 

	
 
				result |= 1;
 
				accepted = true;
 
			}
 

	
 
			/* The !accepted || v->cargo.Count == cargo_count clause is there
 
			 * to make it possible to force unload vehicles at the station where
 
			 * they were loaded, but to not force unload the vehicle when the
 
			 * station is still accepting the cargo in the vehicle. It doesn't
 
			 * accept cargo that was loaded at the same station. */
 
			if (u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER) && (!accepted || v->cargo.Count() == cargo_count)) {
 
			if ((u->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) && (!accepted || v->cargo.Count() == cargo_count)) {
 
				remaining = v->cargo.MoveTo(&ge->cargo, amount_unloaded);
 
				SetBit(ge->acceptance_pickup, GoodsEntry::PICKUP);
 

	
 
				result |= 2;
 
			} else if (!accepted) {
 
				/* The order changed while unloading (unset unload/transfer) or the
 
				 * station does not accept goods anymore. */
 
				ClrBit(v->vehicle_flags, VF_CARGO_UNLOADING);
 
				continue;
 
			}
 

	
 
			/* Deliver goods to the station */
src/engine.cpp
Show inline comments
 
@@ -683,25 +683,25 @@ static void NewVehicleAvailable(Engine *
 

	
 
	SetDParam(0, GetEngineCategoryName(index));
 
	SetDParam(1, index);
 
	AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, NR_ENGINE, index);
 
}
 

	
 
void EnginesMonthlyLoop()
 
{
 
	if (_cur_year < _year_engine_aging_stops) {
 
		Engine *e;
 
		FOR_ALL_ENGINES(e) {
 
			/* Age the vehicle */
 
			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
 
			if ((e->flags & ENGINE_AVAILABLE) && e->age != 0xFFFF) {
 
				e->age++;
 
				CalcEngineReliability(e);
 
			}
 

	
 
			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + DAYS_IN_YEAR)) {
 
				/* Introduce it to all companies */
 
				NewVehicleAvailable(e);
 
			} else if (!(e->flags & (ENGINE_AVAILABLE | ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
 
				/* Introduction date has passed.. show introducing dialog to one companies. */
 
				e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
 

	
 
				/* Do not introduce new rail wagons */
src/industry_cmd.cpp
Show inline comments
 
@@ -1190,28 +1190,28 @@ static const Town *CheckMultipleIndustry
 

	
 
	return t;
 
}
 

	
 
bool IsSlopeRefused(Slope current, Slope refused)
 
{
 
	if (IsSteepSlope(current)) return true;
 
	if (current != SLOPE_FLAT) {
 
		if (IsSteepSlope(refused)) return true;
 

	
 
		Slope t = ComplementSlope(current);
 

	
 
		if (refused & SLOPE_W && (t & SLOPE_NW)) return true;
 
		if (refused & SLOPE_S && (t & SLOPE_NE)) return true;
 
		if (refused & SLOPE_E && (t & SLOPE_SW)) return true;
 
		if (refused & SLOPE_N && (t & SLOPE_SE)) return true;
 
		if ((refused & SLOPE_W) && (t & SLOPE_NW)) return true;
 
		if ((refused & SLOPE_S) && (t & SLOPE_NE)) return true;
 
		if ((refused & SLOPE_E) && (t & SLOPE_SW)) return true;
 
		if ((refused & SLOPE_N) && (t & SLOPE_SE)) return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check = NULL)
 
{
 
	_error_message = STR_ERROR_SITE_UNSUITABLE;
 
	bool refused_slope = false;
 
	bool custom_shape = false;
 

	
 
	do {
 
@@ -1677,25 +1677,25 @@ CommandCost CmdBuildIndustry(TileIndex t
 
		int num = Clamp(GB(p1, 16, 16), 0, count - 1);
 

	
 
		_error_message = STR_ERROR_SITE_UNSUITABLE;
 
		do {
 
			if (--count < 0) return CMD_ERROR;
 
			if (--num < 0) num = indspec->num_table - 1;
 
		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
 

	
 
		ind = CreateNewIndustryHelper(tile, p1, flags, indspec, num, p2, _current_company);
 
		if (ind == NULL) return CMD_ERROR;
 
	}
 

	
 
	if (flags & DC_EXEC && _game_mode != GM_EDITOR && ind != NULL) {
 
	if ((flags & DC_EXEC) && _game_mode != GM_EDITOR && ind != NULL) {
 
		SetDParam(0, indspec->name);
 
		if (indspec->new_industry_text > STR_LAST_STRINGID) {
 
			SetDParam(1, STR_TOWN);
 
			SetDParam(2, ind->town->index);
 
		} else {
 
			SetDParam(1, ind->town->index);
 
		}
 
		AddIndustryNewsItem(indspec->new_industry_text, NS_INDUSTRY_OPEN, ind->index);
 
		AI::BroadcastNewEvent(new AIEventIndustryOpen(ind->index));
 
	}
 

	
 
	return CommandCost(EXPENSES_OTHER, indspec->GetConstructionCost());
 
@@ -1907,25 +1907,25 @@ static void MaybeNewIndustry()
 
 * Protects an industry from closure if the appropriate flags and conditions are met
 
 * INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the
 
 * count of industries of this type must one (or lower) in order to be protected
 
 * against closure.
 
 * @param type IndustryType been queried
 
 * @result true if protection is on, false otherwise (except for oil wells)
 
 */
 
static bool CheckIndustryCloseDownProtection(IndustryType type)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 

	
 
	/* oil wells (or the industries with that flag set) are always allowed to closedown */
 
	if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _settings_game.game_creation.landscape == LT_TEMPERATE) return false;
 
	if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _settings_game.game_creation.landscape == LT_TEMPERATE) return false;
 
	return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE) == 0 && GetIndustryTypeCount(type) <= 1;
 
}
 

	
 
/**
 
 * Can given cargo type be accepted or produced by the industry?
 
 * @param cargo: Cargo type
 
 * @param ind: Industry
 
 * @param *c_accepts: Pointer to boolean for acceptance of cargo
 
 * @param *c_produces: Pointer to boolean for production of cargo
 
 * @return: \c *c_accepts is set when industry accepts the cargo type,
 
 *          \c *c_produces is set when the industry produces the cargo type
 
 */
 
@@ -2165,25 +2165,25 @@ static void ChangeIndustryProduction(Ind
 
		} else {
 
			if (only_decrease || Chance16(1, 3)) {
 
				/* If more than 60% transported, 66% chance of increase, else 33% chance of increase */
 
				if (!only_decrease && (i->last_month_pct_transported[0] > PERCENT_TRANSPORTED_60) != Chance16(1, 3)) {
 
					mul = 1; // Increase production
 
				} else {
 
					div = 1; // Decrease production
 
				}
 
			}
 
		}
 
	}
 

	
 
	if (!callback_enabled && indspec->life_type & INDUSTRYLIFE_PROCESSING) {
 
	if (!callback_enabled && (indspec->life_type & INDUSTRYLIFE_PROCESSING)) {
 
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && Chance16(1, smooth_economy ? 180 : 2)) {
 
			closeit = true;
 
		}
 
	}
 

	
 
	/* Increase if needed */
 
	while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
 
		i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM);
 
		recalculate_multipliers = true;
 
		if (str == STR_NULL) str = indspec->production_up_text;
 
	}
 

	
src/network/core/host.cpp
Show inline comments
 
@@ -164,25 +164,25 @@ static void NetworkFindBroadcastIPsInter
 
		return;
 
	}
 

	
 
	const char *buf_end = buf + ifconf.ifc_len;
 
	for (const char *p = buf; p < buf_end;) {
 
		const struct ifreq *req = (const struct ifreq*)p;
 

	
 
		if (req->ifr_addr.sa_family == AF_INET) {
 
			struct ifreq r;
 

	
 
			strecpy(r.ifr_name, req->ifr_name, lastof(r.ifr_name));
 
			if (ioctl(sock, SIOCGIFFLAGS, &r) != -1 &&
 
					r.ifr_flags & IFF_BROADCAST &&
 
					(r.ifr_flags & IFF_BROADCAST) &&
 
					ioctl(sock, SIOCGIFBRDADDR, &r) != -1) {
 
				NetworkAddress addr(&r.ifr_broadaddr, sizeof(sockaddr));
 
				if (!broadcast->Contains(addr)) *broadcast->Append() = addr;
 
			}
 
		}
 

	
 
		p += sizeof(struct ifreq);
 
#if defined(AF_LINK) && !defined(SUNOS)
 
		p += req->ifr_addr.sa_len - sizeof(struct sockaddr);
 
#endif
 
	}
 

	
src/network/network.cpp
Show inline comments
 
@@ -453,25 +453,25 @@ void NetworkCloseClient(NetworkClientSoc
 

	
 
		NetworkTextMessage(NETWORK_ACTION_LEAVE, CC_DEFAULT, false, client_name, NULL, STR_NETWORK_ERR_CLIENT_CONNECTION_LOST);
 

	
 
		/* Inform other clients of this... strange leaving ;) */
 
		FOR_ALL_CLIENT_SOCKETS(new_cs) {
 
			if (new_cs->status > STATUS_AUTH && cs != new_cs) {
 
				SEND_COMMAND(PACKET_SERVER_ERROR_QUIT)(new_cs, cs->client_id, NETWORK_ERROR_CONNECTION_LOST);
 
			}
 
		}
 
	}
 

	
 
	/* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */
 
	if (cs->status == STATUS_PRE_ACTIVE && _pause_mode & PM_PAUSED_JOIN) {
 
	if (cs->status == STATUS_PRE_ACTIVE && (_pause_mode & PM_PAUSED_JOIN)) {
 
		DoCommandP(0, PM_PAUSED_JOIN, 0, CMD_PAUSE);
 
		NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "", CLIENT_ID_SERVER, NETWORK_SERVER_MESSAGE_GAME_UNPAUSED_CONNECT_FAIL);
 
	}
 

	
 
	if (_network_server) {
 
		/* We just lost one client :( */
 
		if (cs->status >= STATUS_AUTH) _network_game_info.clients_on--;
 
		_network_clients_connected--;
 

	
 
		InvalidateWindow(WC_CLIENT_LIST, 0);
 
	}
 

	
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -87,25 +87,25 @@ void CDECL NetworkAddChatMessage(TextCol
 
	if (lines > MAX_CHAT_MESSAGES - msg_count) {
 
		int i = lines - (MAX_CHAT_MESSAGES - msg_count);
 
		memmove(&_chatmsg_list[0], &_chatmsg_list[i], sizeof(_chatmsg_list[0]) * (msg_count - i));
 
		msg_count = MAX_CHAT_MESSAGES - lines;
 
	}
 

	
 
	for (bufp = buf; lines != 0; lines--) {
 
		ChatMessage *cmsg = &_chatmsg_list[msg_count++];
 
		strecpy(cmsg->message, bufp, lastof(cmsg->message));
 

	
 
		/* The default colour for a message is company colour. Replace this with
 
		 * white for any additional lines */
 
		cmsg->colour = (bufp == buf && colour & IS_PALETTE_COLOUR) ? colour : TC_WHITE;
 
		cmsg->colour = (bufp == buf && (colour & IS_PALETTE_COLOUR)) ? colour : TC_WHITE;
 
		cmsg->end_date = _date + duration;
 

	
 
		bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
 
	}
 

	
 
	_chatmessage_dirty = true;
 
}
 

	
 
void NetworkInitChatMessage()
 
{
 
	MAX_CHAT_MESSAGES   = _settings_client.gui.network_chat_box_height;
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -857,26 +857,26 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT
 

	
 
	if (cs->HasClientQuit()) return;
 

	
 
	NetworkClientInfo *ci = cs->GetInfo();
 

	
 
	if (err != NULL) {
 
		IConsolePrintF(CC_ERROR, "WARNING: %s from client %d (IP: %s).", err, ci->client_id, GetClientIP(ci));
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED);
 
		return;
 
	}
 

	
 

	
 
	if (GetCommandFlags(cp.cmd) & CMD_SERVER && ci->client_id != CLIENT_ID_SERVER) {
 
		IConsolePrintF(CC_ERROR, "WARNING: server only command from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
 
	if ((GetCommandFlags(cp.cmd) & CMD_SERVER) && ci->client_id != CLIENT_ID_SERVER) {
 
		IConsolePrintF(CC_ERROR, "WARNING: server only command from: client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_KICKED);
 
		return;
 
	}
 

	
 
	if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
 
		IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
 
		SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_KICKED);
 
		return;
 
	}
 

	
 
	/** Only CMD_COMPANY_CTRL is always allowed, for the rest, playas needs
 
	 * to match the company in the packet. If it doesn't, the client has done
src/order_cmd.cpp
Show inline comments
 
@@ -1193,25 +1193,25 @@ CommandCost CmdOrderRefit(TileIndex tile
 

	
 
	Order *order = v->GetOrder(order_number);
 
	if (order == NULL) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		order->SetRefit(cargo, subtype);
 

	
 
		for (Vehicle *u = v->FirstShared(); u != NULL; u = u->NextShared()) {
 
			/* Update any possible open window of the vehicle */
 
			InvalidateVehicleOrder(u, 0);
 

	
 
			/* If the vehicle already got the current depot set as current order, then update current order as well */
 
			if (u->cur_order_index == order_number && u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) {
 
			if (u->cur_order_index == order_number && (u->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
 
				u->current_order.SetRefit(cargo, subtype);
 
			}
 
		}
 
	}
 

	
 
	return CommandCost();
 
}
 

	
 
/**
 
 *
 
 * Backup a vehicle order-list, so you can replace a vehicle
 
 *  without losing the order-list
 
@@ -1370,25 +1370,25 @@ static TileIndex GetStationTileForVehicl
 
 * Check the orders of a vehicle, to see if there are invalid orders and stuff
 
 *
 
 */
 
void CheckOrders(const Vehicle *v)
 
{
 
	/* Does the user wants us to check things? */
 
	if (_settings_client.gui.order_review_system == 0) return;
 

	
 
	/* Do nothing for crashed vehicles */
 
	if (v->vehstatus & VS_CRASHED) return;
 

	
 
	/* Do nothing for stopped vehicles if setting is '1' */
 
	if (_settings_client.gui.order_review_system == 1 && v->vehstatus & VS_STOPPED)
 
	if (_settings_client.gui.order_review_system == 1 && (v->vehstatus & VS_STOPPED))
 
		return;
 

	
 
	/* do nothing we we're not the first vehicle in a share-chain */
 
	if (v->FirstShared() != v) return;
 

	
 
	/* Only check every 20 days, so that we don't flood the message log */
 
	if (v->owner == _local_company && v->day_counter % 20 == 0) {
 
		int n_st, problem_type = -1;
 
		const Order *order;
 
		int message = 0;
 

	
 
		/* Check the order list */
src/rail_cmd.cpp
Show inline comments
 
@@ -125,25 +125,25 @@ static bool CheckTrackCombination(TileIn
 
	 * what tracks first */
 
	current = GetTrackBits(tile);
 
	future = current | to_build;
 

	
 
	/* Are we really building something new? */
 
	if (current == future) {
 
		/* Nothing new is being built */
 
		_error_message = STR_ERROR_ALREADY_BUILT;
 
		return false;
 
	}
 

	
 
	/* Let's see if we may build this */
 
	if (flags & DC_NO_RAIL_OVERLAP || HasSignals(tile)) {
 
	if ((flags & DC_NO_RAIL_OVERLAP) || HasSignals(tile)) {
 
		/* If we are not allowed to overlap (flag is on for ai companies or we have
 
		 * signals on the tile), check that */
 
		return future == TRACK_BIT_HORZ || future == TRACK_BIT_VERT;
 
	} else {
 
		/* Normally, we may overlap and any combination is valid */
 
		return true;
 
	}
 
}
 

	
 

	
 
/** Valid TrackBits on a specific (non-steep)-slope without foundation */
 
static const TrackBits _valid_tracks_without_foundation[15] = {
src/road_cmd.cpp
Show inline comments
 
@@ -128,28 +128,28 @@ bool CheckAllowRemoveRoad(TileIndex tile
 
	if (_cheats.magic_bulldozer.value) return true;
 

	
 
	Town *t = ClosestTownFromTile(tile, UINT_MAX);
 
	if (t == NULL) return true;
 

	
 
	/* check if you're allowed to remove the street owned by a town
 
	 * removal allowance depends on difficulty setting */
 
	if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return false;
 

	
 
	/* Get a bitmask of which neighbouring roads has a tile */
 
	RoadBits n = ROAD_NONE;
 
	RoadBits present = GetAnyRoadBits(tile, rt);
 
	if (present & ROAD_NE && GetAnyRoadBits(TILE_ADDXY(tile, -1,  0), rt) & ROAD_SW) n |= ROAD_NE;
 
	if (present & ROAD_SE && GetAnyRoadBits(TILE_ADDXY(tile,  0,  1), rt) & ROAD_NW) n |= ROAD_SE;
 
	if (present & ROAD_SW && GetAnyRoadBits(TILE_ADDXY(tile,  1,  0), rt) & ROAD_NE) n |= ROAD_SW;
 
	if (present & ROAD_NW && GetAnyRoadBits(TILE_ADDXY(tile,  0, -1), rt) & ROAD_SE) n |= ROAD_NW;
 
	if ((present & ROAD_NE) && (GetAnyRoadBits(TILE_ADDXY(tile, -1,  0), rt) & ROAD_SW)) n |= ROAD_NE;
 
	if ((present & ROAD_SE) && (GetAnyRoadBits(TILE_ADDXY(tile,  0,  1), rt) & ROAD_NW)) n |= ROAD_SE;
 
	if ((present & ROAD_SW) && (GetAnyRoadBits(TILE_ADDXY(tile,  1,  0), rt) & ROAD_NE)) n |= ROAD_SW;
 
	if ((present & ROAD_NW) && (GetAnyRoadBits(TILE_ADDXY(tile,  0, -1), rt) & ROAD_SE)) n |= ROAD_NW;
 

	
 
	int rating_decrease = RATING_ROAD_DOWN_STEP_EDGE;
 
	/* If 0 or 1 bits are set in n, or if no bits that match the bits to remove,
 
	 * then allow it */
 
	if (KillFirstBit(n) != ROAD_NONE && (n & remove) != ROAD_NONE) {
 
		/* you can remove all kind of roads with extra dynamite */
 
		if (!_settings_game.construction.extra_dynamite) {
 
			SetDParam(0, t->index);
 
			_error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS;
 
			return false;
 
		}
 
		rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
 
@@ -485,25 +485,25 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
					if (rt != ROADTYPE_TRAM && (GetDisallowedRoadDirections(tile) != DRD_NONE || toggle_drd != DRD_NONE) && crossing) {
 
						/* Junctions cannot be one-way */
 
						return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
 
					}
 
					if ((existing & pieces) == pieces) {
 
						/* We only want to set the (dis)allowed road directions */
 
						if (toggle_drd != DRD_NONE && rt != ROADTYPE_TRAM && IsRoadOwner(tile, ROADTYPE_ROAD, _current_company)) {
 
							if (crossing) return_cmd_error(STR_ERROR_ONEWAY_ROADS_CAN_T_HAVE_JUNCTION);
 

	
 
							if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
							/* Ignore half built tiles */
 
							if (flags & DC_EXEC && rt != ROADTYPE_TRAM && IsStraightRoad(existing)) {
 
							if ((flags & DC_EXEC) && rt != ROADTYPE_TRAM && IsStraightRoad(existing)) {
 
								SetDisallowedRoadDirections(tile, GetDisallowedRoadDirections(tile) ^ toggle_drd);
 
								MarkTileDirtyByTile(tile);
 
							}
 
							return CommandCost();
 
						}
 
						return_cmd_error(STR_ERROR_ALREADY_BUILT);
 
					}
 
				} break;
 

	
 
				case ROAD_TILE_CROSSING:
 
					other_bits = GetCrossingRoadBits(tile);
 
					if (pieces & ComplementRoadBits(other_bits)) goto do_clear;
src/roadveh_cmd.cpp
Show inline comments
 
@@ -431,26 +431,26 @@ CommandCost CmdSendRoadVehToDepot(TileIn
 

	
 
/** Turn a roadvehicle around.
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 vehicle ID to turn
 
 * @param p2 unused
 
 */
 
CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	RoadVehicle *v = RoadVehicle::GetIfValid(p1);
 
	if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR;
 

	
 
	if (v->vehstatus & VS_STOPPED ||
 
			v->vehstatus & VS_CRASHED ||
 
	if ((v->vehstatus & VS_STOPPED) ||
 
			(v->vehstatus & VS_CRASHED) ||
 
			v->breakdown_ctr != 0 ||
 
			v->overtaking != 0 ||
 
			v->state == RVSB_WORMHOLE ||
 
			v->IsInDepot() ||
 
			v->cur_speed < 5) {
 
		return CMD_ERROR;
 
	}
 

	
 
	if (IsNormalRoadTile(v->tile) && GetDisallowedRoadDirections(v->tile) != DRD_NONE) return CMD_ERROR;
 

	
 
	if (IsTileType(v->tile, MP_TUNNELBRIDGE) && DirToDiagDir(v->direction) == GetTunnelBridgeDirection(v->tile)) return CMD_ERROR;
 

	
 
@@ -926,25 +926,25 @@ static void RoadVehCheckOvertake(RoadVeh
 
	/* Are the current and the next tile suitable for overtaking?
 
	 *  - Does the track continue along od.trackdir
 
	 *  - No junctions
 
	 *  - No barred levelcrossing
 
	 *  - No other vehicles in the way
 
	 */
 
	od.tile = v->tile;
 
	if (CheckRoadBlockedForOvertaking(&od)) return;
 

	
 
	od.tile = v->tile + TileOffsByDiagDir(DirToDiagDir(v->direction));
 
	if (CheckRoadBlockedForOvertaking(&od)) return;
 

	
 
	if (od.u->cur_speed == 0 || od.u->vehstatus& VS_STOPPED) {
 
	if (od.u->cur_speed == 0 || (od.u->vehstatus & VS_STOPPED)) {
 
		v->overtaking_ctr = 0x11;
 
		v->overtaking = 0x10;
 
	} else {
 
//		if (CheckRoadBlockedForOvertaking(&od)) return;
 
		v->overtaking_ctr = 0;
 
		v->overtaking = 0x10;
 
	}
 
}
 

	
 
static void RoadZPosAffectSpeed(RoadVehicle *v, byte old_z)
 
{
 
	if (old_z == v->z_pos) return;
 
@@ -1123,25 +1123,25 @@ static Trackdir RoadFindPathToDest(RoadV
 
					dir = GetRoadDepotDirection(desttile);
 
					goto do_it;
 
				}
 
			} else if (IsTileType(desttile, MP_STATION)) {
 
				/* For drive-through stops we can head for the actual station tile */
 
				if (IsStandardRoadStopTile(desttile)) {
 
					dir = GetRoadStopDir(desttile);
 
do_it:;
 
					/* When we are heading for a depot or station, we just
 
					 * pretend we are heading for the tile in front, we'll
 
					 * see from there */
 
					desttile += TileOffsByDiagDir(dir);
 
					if (desttile == tile && trackdirs & _road_exit_dir_to_incoming_trackdirs[dir]) {
 
					if (desttile == tile && (trackdirs & _road_exit_dir_to_incoming_trackdirs[dir])) {
 
						/* If we are already in front of the
 
						 * station/depot and we can get in from here,
 
						 * we enter */
 
						return_track(FindFirstBit2x64(trackdirs & _road_exit_dir_to_incoming_trackdirs[dir]));
 
					}
 
				}
 
			}
 
			/* Do some pathfinding */
 
			frd.dest = desttile;
 

	
 
			best_track = INVALID_TRACKDIR;
 
			uint best_dist = UINT_MAX;
src/saveload/oldloader.cpp
Show inline comments
 
@@ -96,26 +96,26 @@ byte ReadByte(LoadgameState *ls)
 
}
 

	
 
/**
 
 *
 
 * Loads a chunk from the old savegame
 
 *
 
 */
 
bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
 
{
 
	byte *base_ptr = (byte*)base;
 

	
 
	for (const OldChunks *chunk = chunks; chunk->type != OC_END; chunk++) {
 
		if (((chunk->type & OC_TTD) && (_savegame_type == SGT_TTO)) ||
 
				((chunk->type & OC_TTO) && (_savegame_type != SGT_TTO))) {
 
		if (((chunk->type & OC_TTD) && _savegame_type == SGT_TTO) ||
 
				((chunk->type & OC_TTO) && _savegame_type != SGT_TTO)) {
 
			/* TTD(P)-only chunk, but TTO savegame || TTO-only chunk, but TTD/TTDP savegame */
 
			continue;
 
		}
 

	
 
		byte *ptr = (byte*)chunk->ptr;
 
		if (chunk->type & OC_DEREFERENCE_POINTER) ptr = *(byte**)ptr;
 

	
 
		for (uint i = 0; i < chunk->amount; i++) {
 
			if (ls->failed) return false;
 

	
 
			/* Handle simple types */
 
			if (GetOldChunkType(chunk->type) != 0) {
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -156,25 +156,25 @@ void UpdateOldAircraft()
 
	/* set airport_flags to 0 for all airports just to be sure */
 
	Station *st;
 
	FOR_ALL_STATIONS(st) {
 
		st->airport_flags = 0; // reset airport
 
	}
 

	
 
	Aircraft *a;
 
	FOR_ALL_AIRCRAFT(a) {
 
		/* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor)
 
		 * skip those */
 
		if (IsNormalAircraft(a)) {
 
			/* airplane in terminal stopped doesn't hurt anyone, so goto next */
 
			if (a->vehstatus & VS_STOPPED && a->state == 0) {
 
			if ((a->vehstatus & VS_STOPPED) && a->state == 0) {
 
				a->state = HANGAR;
 
				continue;
 
			}
 

	
 
			AircraftLeaveHangar(a); // make airplane visible if it was in a depot for example
 
			a->vehstatus &= ~VS_STOPPED; // make airplane moving
 
			a->cur_speed = a->max_speed; // so aircraft don't have zero speed while in air
 
			if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) {
 
				/* reset current order so aircraft doesn't have invalid "station-only" order */
 
				a->current_order.MakeDummy();
 
			}
 
			a->state = FLYING;
src/signal.cpp
Show inline comments
 
@@ -332,25 +332,25 @@ static SigFlags ExploreSegment(Owner own
 
							flags |= SF_EXIT; // found at least one exit - allow for compiler optimizations
 
							if (GetSignalStateByTrackdir(tile, trackdir) == SIGNAL_STATE_GREEN) { // found green presignal exit
 
								if (flags & SF_GREEN) flags |= SF_GREEN2;
 
								flags |= SF_GREEN;
 
							}
 
						}
 

	
 
						continue;
 
					}
 
				}
 

	
 
				for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { // test all possible exit directions
 
					if (dir != enterdir && tracks & _enterdir_to_trackbits[dir]) { // any track incidating?
 
					if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
 
						TileIndex newtile = tile + TileOffsByDiagDir(dir);  // new tile to check
 
						DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
 
						if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) return flags | SF_FULL;
 
					}
 
				}
 

	
 
				continue; // continue the while() loop
 
				}
 

	
 
			case MP_STATION:
 
				if (!IsRailwayStation(tile)) continue;
 
				if (GetTileOwner(tile) != owner) continue;
 
@@ -416,33 +416,33 @@ static void UpdateSignalsAroundSegment(S
 

	
 
		SignalType sig = GetSignalType(tile, TrackdirToTrack(trackdir));
 
		SignalState newstate = SIGNAL_STATE_GREEN;
 

	
 
		/* determine whether the new state is red */
 
		if (flags & SF_TRAIN) {
 
			/* train in the segment */
 
			newstate = SIGNAL_STATE_RED;
 
		} else {
 
			/* is it a bidir combo? - then do not count its other signal direction as exit */
 
			if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
 
				/* at least one more exit */
 
				if (flags & SF_EXIT2 &&
 
				if ((flags & SF_EXIT2) &&
 
						/* no green exit */
 
						(!(flags & SF_GREEN) ||
 
						/* only one green exit, and it is this one - so all other exits are red */
 
						(!(flags & SF_GREEN2) && GetSignalStateByTrackdir(tile, ReverseTrackdir(trackdir)) == SIGNAL_STATE_GREEN))) {
 
					newstate = SIGNAL_STATE_RED;
 
				}
 
			} else { // entry, at least one exit, no green exit
 
				if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && flags & SF_EXIT && !(flags & SF_GREEN)) newstate = SIGNAL_STATE_RED;
 
				if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && (flags & SF_EXIT) && !(flags & SF_GREEN)) newstate = SIGNAL_STATE_RED;
 
			}
 
		}
 

	
 
		/* only when the state changes */
 
		if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
 
			if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
 
				/* for pre-signal exits, add block to the global set */
 
				DiagDirection exitdir = TrackdirToExitdir(ReverseTrackdir(trackdir));
 
				_globset.Add(tile, exitdir); // do not check for full global set, first update all signals
 
			}
 
			SetSignalStateByTrackdir(tile, trackdir, newstate);
 
			MarkTileDirtyByTile(tile);
 
@@ -526,25 +526,25 @@ static SigSegState UpdateSignalsInBuffer
 
		}
 

	
 
		assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
 
		assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
 

	
 
		SigFlags flags = ExploreSegment(owner);
 

	
 
		if (first) {
 
			first = false;
 
			/* SIGSEG_FREE is set by default */
 
			if (flags & SF_PBS) {
 
				state = SIGSEG_PBS;
 
			} else if (flags & SF_TRAIN || (flags & SF_EXIT && !(flags & SF_GREEN)) || flags & SF_FULL) {
 
			} else if ((flags & SF_TRAIN) || ((flags & SF_EXIT) && !(flags & SF_GREEN)) || (flags & SF_FULL)) {
 
				state = SIGSEG_FULL;
 
			}
 
		}
 

	
 
		/* do not do anything when some buffer was full */
 
		if (flags & SF_FULL) {
 
			ResetSets(); // free all sets
 
			break;
 
		}
 

	
 
		UpdateSignalsAroundSegment(flags);
 
	}
src/station_cmd.cpp
Show inline comments
 
@@ -374,25 +374,25 @@ static Station *GetClosestDeletedStation
 

	
 
	return best_station;
 
}
 

	
 
/** Update the virtual coords needed to draw the station sign.
 
 * @param st Station to update for.
 
 */
 
static void UpdateStationVirtCoord(Station *st)
 
{
 
	Point pt = RemapCoords2(TileX(st->xy) * TILE_SIZE, TileY(st->xy) * TILE_SIZE);
 

	
 
	pt.y -= 32;
 
	if (st->facilities & FACIL_AIRPORT && st->airport_type == AT_OILRIG) pt.y -= 16;
 
	if ((st->facilities & FACIL_AIRPORT) && st->airport_type == AT_OILRIG) pt.y -= 16;
 

	
 
	SetDParam(0, st->index);
 
	SetDParam(1, st->facilities);
 
	UpdateViewportSignPos(&st->sign, pt.x, pt.y, STR_STATION_SIGN);
 
}
 

	
 
/** Update the virtual coords needed to draw the station sign for all stations. */
 
void UpdateAllStationVirtCoord()
 
{
 
	Station *st;
 

	
 
	FOR_ALL_STATIONS(st) {
 
@@ -1840,25 +1840,25 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	/* Check if local auth would allow a new airport */
 
	StringID authority_refuse_message = STR_NULL;
 

	
 
	if (_settings_game.economy.station_noise_level) {
 
		/* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */
 
		if ((nearest->noise_reached + newnoise_level) > nearest->MaxTownNoise()) {
 
			authority_refuse_message = STR_LOCAL_AUTHORITY_REFUSES_NOISE;
 
		}
 
	} else {
 
		uint num = 0;
 
		const Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			if (st->town == t && st->facilities & FACIL_AIRPORT && st->airport_type != AT_OILRIG) num++;
 
			if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport_type != AT_OILRIG) num++;
 
		}
 
		if (num >= 2) {
 
			authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT;
 
		}
 
	}
 

	
 
	if (authority_refuse_message != STR_NULL) {
 
		SetDParam(0, t->index);
 
		return_cmd_error(authority_refuse_message);
 
	}
 

	
 
	if (!_settings_game.station.adjacent_stations || !HasBit(p2, 0)) {
src/town_cmd.cpp
Show inline comments
 
@@ -478,25 +478,25 @@ static void TileLoop_Town(TileIndex tile
 

	
 
		if (GB(r, 8, 8) < hs->mail_generation) {
 
			uint amt = GB(r, 8, 8) / 8 + 1;
 

	
 
			if (_economy.fluct <= 0) amt = (amt + 1) >> 1;
 
			t->new_max_mail += amt;
 
			t->new_act_mail += MoveGoodsToStation(tile, 1, 1, CT_MAIL, amt);
 
		}
 
	}
 

	
 
	_current_company = OWNER_TOWN;
 

	
 
	if (hs->building_flags & BUILDING_HAS_1_TILE &&
 
	if ((hs->building_flags & BUILDING_HAS_1_TILE) &&
 
			HasBit(t->flags12, TOWN_IS_FUNDED) &&
 
			CanDeleteHouse(tile) &&
 
			GetHouseAge(tile) >= hs->minimum_life &&
 
			--t->time_until_rebuild == 0) {
 
		t->time_until_rebuild = GB(r, 16, 8) + 192;
 

	
 
		ClearTownHouse(t, tile);
 

	
 
		/* Rebuild with another house? */
 
		if (GB(r, 24, 8) >= 12) BuildTownHouse(t, tile);
 
	}
 

	
src/train_cmd.cpp
Show inline comments
 
@@ -1534,25 +1534,25 @@ CommandCost CmdSellRailWagon(TileIndex t
 
						continue;
 
					}
 
				}
 

	
 
				cost.AddCost(-v->value);
 
				if (flags & DC_EXEC) {
 
					first = UnlinkWagon(v, first);
 
					delete v;
 
				}
 
			}
 

	
 
			/* 3. If it is still a valid train after selling, update its acceleration and cached values */
 
			if (flags & DC_EXEC && first != NULL) {
 
			if ((flags & DC_EXEC) && first != NULL) {
 
				NormaliseTrainConsist(first);
 
				TrainConsistChanged(first, false);
 
				UpdateTrainGroupID(first);
 
				InvalidateWindow(WC_VEHICLE_REFIT, first->index);
 
			}
 
		} break;
 
	}
 
	return cost;
 
}
 

	
 
void Train::UpdateDeltaXY(Direction direction)
 
{
 
@@ -1696,25 +1696,25 @@ static Vehicle *TrainOnTileEnum(Vehicle 
 
}
 

	
 

	
 
/**
 
 * Checks if a train is approaching a rail-road crossing
 
 * @param v vehicle on tile
 
 * @param data tile with crossing we are testing
 
 * @return v if it is approaching a crossing, NULL otherwise
 
 */
 
static Vehicle *TrainApproachingCrossingEnum(Vehicle *v, void *data)
 
{
 
	/* not a train || not front engine || crashed */
 
	if (v->type != VEH_TRAIN || !IsFrontEngine(v) || v->vehstatus & VS_CRASHED) return NULL;
 
	if (v->type != VEH_TRAIN || !IsFrontEngine(v) || (v->vehstatus & VS_CRASHED)) return NULL;
 

	
 
	TileIndex tile = *(TileIndex*)data;
 

	
 
	if (TrainApproachingCrossingTile((Train *)v) != tile) return NULL;
 

	
 
	return v;
 
}
 

	
 

	
 
/**
 
 * Finds a vehicle approaching rail-road crossing
 
 * @param tile tile to test
 
@@ -1965,25 +1965,25 @@ CommandCost CmdReverseTrainDirection(Til
 
		/* make sure the vehicle is stopped in the depot */
 
		if (CheckTrainStoppedInDepot(front) < 0) {
 
			return_cmd_error(STR_ERROR_TRAINS_CAN_ONLY_BE_ALTERED_INSIDE_A_DEPOT);
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			ToggleBit(v->flags, VRF_REVERSE_DIRECTION);
 
			InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
			InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		}
 
	} else {
 
		/* turn the whole train around */
 
		if (v->vehstatus & VS_CRASHED || v->breakdown_ctr != 0) return CMD_ERROR;
 
		if ((v->vehstatus & VS_CRASHED) || v->breakdown_ctr != 0) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			/* Properly leave the station if we are loading and won't be loading anymore */
 
			if (v->current_order.IsType(OT_LOADING)) {
 
				const Vehicle *last = v;
 
				while (last->Next() != NULL) last = last->Next();
 

	
 
				/* not a station || different station --> leave the station */
 
				if (!IsTileType(last->tile, MP_STATION) || GetStationIndex(last->tile) != GetStationIndex(v->tile)) {
 
					v->LeaveStation();
 
				}
 
			}
 
@@ -2248,25 +2248,25 @@ void OnTick_Train()
 
{
 
	_age_cargo_skip_counter = (_age_cargo_skip_counter == 0) ? 184 : (_age_cargo_skip_counter - 1);
 
}
 

	
 
static const int8 _vehicle_smoke_pos[8] = {
 
	1, 1, 1, 0, -1, -1, -1, 0
 
};
 

	
 
static void HandleLocomotiveSmokeCloud(const Train *v)
 
{
 
	bool sound = false;
 

	
 
	if (v->vehstatus & VS_TRAIN_SLOWING || v->load_unload_time_rem != 0 || v->cur_speed < 2) {
 
	if ((v->vehstatus & VS_TRAIN_SLOWING) || v->load_unload_time_rem != 0 || v->cur_speed < 2) {
 
		return;
 
	}
 

	
 
	const Train *u = v;
 

	
 
	do {
 
		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
 
		int effect_offset = GB(v->tcache.cached_vis_effect, 0, 4) - 8;
 
		byte effect_type = GB(v->tcache.cached_vis_effect, 4, 2);
 
		bool disable_effect = HasBit(v->tcache.cached_vis_effect, 6);
 

	
 
		/* no smoke? */
 
@@ -2344,25 +2344,25 @@ void Train::PlayLeaveStationSound() cons
 

	
 
	EngineID engtype = this->engine_type;
 
	SndPlayVehicleFx(sfx[RailVehInfo(engtype)->engclass], this);
 
}
 

	
 
/** Check if the train is on the last reserved tile and try to extend the path then. */
 
static void CheckNextTrainTile(Train *v)
 
{
 
	/* Don't do any look-ahead if path_backoff_interval is 255. */
 
	if (_settings_game.pf.path_backoff_interval == 255) return;
 

	
 
	/* Exit if we reached our destination depot or are inside a depot. */
 
	if ((v->tile == v->dest_tile && v->current_order.IsType(OT_GOTO_DEPOT)) || v->track & TRACK_BIT_DEPOT) return;
 
	if ((v->tile == v->dest_tile && v->current_order.IsType(OT_GOTO_DEPOT)) || (v->track & TRACK_BIT_DEPOT)) return;
 
	/* Exit if we are on a station tile and are going to stop. */
 
	if (IsRailwayStationTile(v->tile) && v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile))) return;
 
	/* Exit if the current order doesn't have a destination, but the train has orders. */
 
	if ((v->current_order.IsType(OT_NOTHING) || v->current_order.IsType(OT_LEAVESTATION) || v->current_order.IsType(OT_LOADING)) && v->GetNumOrders() > 0) return;
 

	
 
	Trackdir td = v->GetVehicleTrackdir();
 

	
 
	/* On a tile with a red non-pbs signal, don't look ahead. */
 
	if (IsTileType(v->tile, MP_RAILWAY) && HasSignalOnTrackdir(v->tile, td) &&
 
			!IsPbsSignal(GetSignalType(v->tile, TrackdirToTrack(td))) &&
 
			GetSignalStateByTrackdir(v->tile, td) == SIGNAL_STATE_RED) return;
 

	
 
@@ -3296,25 +3296,25 @@ void Train::MarkDirty()
 
 * and subspeed) variables. Furthermore, it returns the distance that
 
 * the train can drive this tick. This distance is expressed as 256 * n,
 
 * where n is the number of straight (long) tracks the train can
 
 * traverse. This means that moving along a straight track costs 256
 
 * "speed" and a diagonal track costs 192 "speed".
 
 * @param v The vehicle to update the speed of.
 
 * @return distance to drive.
 
 */
 
static int UpdateTrainSpeed(Train *v)
 
{
 
	uint accel;
 

	
 
	if (v->vehstatus & VS_STOPPED || HasBit(v->flags, VRF_REVERSING) || HasBit(v->flags, VRF_TRAIN_STUCK)) {
 
	if ((v->vehstatus & VS_STOPPED) || HasBit(v->flags, VRF_REVERSING) || HasBit(v->flags, VRF_TRAIN_STUCK)) {
 
		switch (_settings_game.vehicle.train_acceleration_model) {
 
			default: NOT_REACHED();
 
			case TAM_ORIGINAL:  accel = v->acceleration * -4; break;
 
			case TAM_REALISTIC: accel = GetTrainAcceleration(v, AM_BRAKE); break;
 
		}
 
	} else {
 
		switch (_settings_game.vehicle.train_acceleration_model) {
 
			default: NOT_REACHED();
 
			case TAM_ORIGINAL:  accel = v->acceleration * 2; break;
 
			case TAM_REALISTIC: accel = GetTrainAcceleration(v, AM_ACCEL); break;
 
		}
 
	}
 
@@ -3695,25 +3695,25 @@ static void TrainController(Train *v, Ve
 
				/* Check if the new tile contrains tracks that are compatible
 
				 * with the current train, if not, bail out. */
 
				if (!CheckCompatibleRail(v, gp.new_tile)) goto invalid_rail;
 

	
 
				TrackBits chosen_track;
 
				if (prev == NULL) {
 
					/* Currently the locomotive is active. Determine which one of the
 
					 * available tracks to choose */
 
					chosen_track = TrackToTrackBits(ChooseTrainTrack(v, gp.new_tile, enterdir, bits, false, NULL, true));
 
					assert(chosen_track & (bits | GetReservedTrackbits(gp.new_tile)));
 

	
 
					/* Check if it's a red signal and that force proceed is not clicked. */
 
					if (red_signals & chosen_track && v->force_proceed == 0) {
 
					if ((red_signals & chosen_track) && v->force_proceed == 0) {
 
						/* In front of a red signal */
 
						Trackdir i = FindFirstTrackdir(trackdirbits);
 

	
 
						/* Don't handle stuck trains here. */
 
						if (HasBit(v->flags, VRF_TRAIN_STUCK)) return;
 

	
 
						if (!HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(i))) {
 
							v->cur_speed = 0;
 
							v->subspeed = 0;
 
							v->progress = 255 - 100;
 
							if (_settings_game.pf.wait_oneway_signal == 255 || ++v->load_unload_time_rem < _settings_game.pf.wait_oneway_signal * 20) return;
 
						} else if (HasSignalOnTrackdir(gp.new_tile, i)) {
 
@@ -4276,25 +4276,25 @@ static bool TrainLocoHandler(Train *v, b
 
		if (v->breakdown_ctr <= 2) {
 
			HandleBrokenTrain(v);
 
			return true;
 
		}
 
		if (!v->current_order.IsType(OT_LOADING)) v->breakdown_ctr--;
 
	}
 

	
 
	if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
 
		ReverseTrainDirection(v);
 
	}
 

	
 
	/* exit if train is stopped */
 
	if (v->vehstatus & VS_STOPPED && v->cur_speed == 0) return true;
 
	if ((v->vehstatus & VS_STOPPED) && v->cur_speed == 0) return true;
 

	
 
	bool valid_order = !v->current_order.IsType(OT_NOTHING) && v->current_order.GetType() != OT_CONDITIONAL;
 
	if (ProcessOrders(v) && CheckReverseTrain(v)) {
 
		v->load_unload_time_rem = 0;
 
		v->cur_speed = 0;
 
		v->subspeed = 0;
 
		ReverseTrainDirection(v);
 
		return true;
 
	}
 

	
 
	v->HandleLoading(mode);
 

	
 
@@ -4341,25 +4341,25 @@ static bool TrainLocoHandler(Train *v, b
 
		}
 
	}
 

	
 
	if (v->current_order.IsType(OT_LEAVESTATION)) {
 
		v->current_order.Free();
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
		return true;
 
	}
 

	
 
	int j = UpdateTrainSpeed(v);
 

	
 
	/* we need to invalidate the widget if we are stopping from 'Stopping 0 km/h' to 'Stopped' */
 
	if (v->cur_speed == 0 && v->tcache.last_speed == 0 && v->vehstatus & VS_STOPPED) {
 
	if (v->cur_speed == 0 && v->tcache.last_speed == 0 && (v->vehstatus & VS_STOPPED)) {
 
		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
 
	}
 

	
 
	int adv_spd = (v->direction & 1) ? 192 : 256;
 
	if (j < adv_spd) {
 
		/* if the vehicle has speed 0, update the last_speed field. */
 
		if (v->cur_speed == 0) SetLastSpeed(v, v->cur_speed);
 
	} else {
 
		TrainCheckIfLineEnds(v);
 
		/* Loop until the train has finished moving. */
 
		for (;;) {
 
			j -= adv_spd;
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -423,25 +423,25 @@ not_valid_below:;
 
				ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
				if (CmdFailed(ret)) return ret;
 
				cost.AddCost(ret);
 
				break;
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			SetBridgeMiddle(tile, direction);
 
			MarkTileDirtyByTile(tile);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC && transport_type == TRANSPORT_RAIL) {
 
	if ((flags & DC_EXEC) && transport_type == TRANSPORT_RAIL) {
 
		Track track = AxisToTrack(direction);
 
		AddSideToSignalBuffer(tile_start, INVALID_DIAGDIR, _current_company);
 
		YapfNotifyTrackLayoutChange(tile_start, track);
 
	}
 

	
 
	/* for human player that builds the bridge he gets a selection to choose from bridges (DC_QUERY_COST)
 
	 * It's unnecessary to execute this command every time for every bridge. So it is done only
 
	 * and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
 
	 */
 
	Company *c = Company::GetIfValid(_current_company);
 
	if (!(flags & DC_QUERY_COST) || (c != NULL && c->is_ai)) {
 
		bridge_len += 2; // begin and end tiles/ramps
src/unmovable_cmd.cpp
Show inline comments
 
@@ -264,25 +264,25 @@ static CommandCost ClearTile_Unmovable(T
 
		if (_current_company == OWNER_WATER) {
 
			return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
 
		} else {
 
			return_cmd_error(flags & DC_AUTO ? STR_ERROR_COMPANY_HEADQUARTERS_IN : INVALID_STRING_ID);
 
		}
 
	}
 

	
 
	if (IsOwnedLand(tile)) {
 
		return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
 
	}
 

	
 
	/* checks if you're allowed to remove unmovable things */
 
	if (_game_mode != GM_EDITOR && _current_company != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) )
 
	if (_game_mode != GM_EDITOR && _current_company != OWNER_WATER && ((flags & DC_AUTO) || !_cheats.magic_bulldozer.value) )
 
		return_cmd_error(flags & DC_AUTO ? STR_ERROR_OBJECT_IN_THE_WAY : INVALID_STRING_ID);
 

	
 
	if (IsStatue(tile)) {
 
		if (flags & DC_AUTO) return_cmd_error(STR_ERROR_OBJECT_IN_THE_WAY);
 

	
 
		TownID town = GetStatueTownID(tile);
 
		ClrBit(Town::Get(town)->statues, GetTileOwner(tile));
 
		InvalidateWindow(WC_TOWN_AUTHORITY, town);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		DoClearSquare(tile);
src/vehicle.cpp
Show inline comments
 
@@ -855,25 +855,25 @@ static const byte _breakdown_chance[64] 
 
	 72,  80,  90, 100, 110, 120, 130, 140,
 
	150, 170, 190, 210, 230, 250, 250, 250,
 
};
 

	
 
void CheckVehicleBreakdown(Vehicle *v)
 
{
 
	int rel, rel_old;
 

	
 
	/* decrease reliability */
 
	v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0);
 
	if ((rel_old >> 8) != (rel >> 8)) InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 

	
 
	if (v->breakdown_ctr != 0 || v->vehstatus & VS_STOPPED ||
 
	if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) ||
 
			_settings_game.difficulty.vehicle_breakdowns < 1 ||
 
			v->cur_speed < 5 || _game_mode == GM_MENU) {
 
		return;
 
	}
 

	
 
	uint32 r = Random();
 

	
 
	/* increase chance of failure */
 
	int chance = v->breakdown_chance + 1;
 
	if (Chance16I(1, 25, r)) chance += 25;
 
	v->breakdown_chance = min(255, chance);
 

	
src/vehicle_cmd.cpp
Show inline comments
 
@@ -58,25 +58,25 @@ const uint32 _send_to_depot_proc_table[]
 
 * @return result of operation.  Nothing if everything went well
 
 */
 
CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	/* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
 
	if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
 

	
 
	Vehicle *v = Vehicle::GetIfValid(p1);
 
	if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR;
 

	
 
	switch (v->type) {
 
		case VEH_TRAIN:
 
			if (v->vehstatus & VS_STOPPED && ((Train *)v)->tcache.cached_power == 0) return_cmd_error(STR_TRAIN_START_NO_CATENARY);
 
			if ((v->vehstatus & VS_STOPPED) && ((Train *)v)->tcache.cached_power == 0) return_cmd_error(STR_TRAIN_START_NO_CATENARY);
 
			break;
 

	
 
		case VEH_SHIP:
 
		case VEH_ROAD:
 
			break;
 

	
 
		case VEH_AIRCRAFT: {
 
			Aircraft *a = (Aircraft *)v;
 
			/* cannot stop airplane when in flight, or when taking off / landing */
 
			if (a->state >= STARTTAKEOFF && a->state < TERM7) return_cmd_error(STR_ERROR_AIRCRAFT_IS_IN_FLIGHT);
 
		} break;
 

	
 
@@ -396,25 +396,25 @@ CommandCost CmdCloneVehicle(TileIndex ti
 
					DoCommand(w_front->tile, w->index,       1, flags, GetCmdSellVeh(w));
 
					return result; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE
 
				}
 
			} else {
 
				/* this is a front engine or not a train. */
 
				w_front = w;
 
				w->service_interval = v->service_interval;
 
			}
 
			w_rear = w; // trains needs to know the last car in the train, so they can add more in next loop
 
		}
 
	} while (v->type == VEH_TRAIN && (v = GetNextVehicle((Train *)v)) != NULL);
 

	
 
	if (flags & DC_EXEC && v_front->type == VEH_TRAIN) {
 
	if ((flags & DC_EXEC) && v_front->type == VEH_TRAIN) {
 
		/* for trains this needs to be the front engine due to the callback function */
 
		_new_vehicle_id = w_front->index;
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Cloned vehicles belong to the same group */
 
		DoCommand(0, v_front->group_id, w_front->index, flags, CMD_ADD_VEHICLE_GROUP);
 
	}
 

	
 

	
 
	/* Take care of refitting. */
 
	w = w_front;
src/video/allegro_v.cpp
Show inline comments
 
@@ -318,25 +318,25 @@ static void PollEvent()
 

	
 
	bool mouse_action = false;
 

	
 
	/* Mouse buttons */
 
	static int prev_button_state;
 
	if (prev_button_state != mouse_b) {
 
		uint diff = prev_button_state ^ mouse_b;
 
		while (diff != 0) {
 
			int button = FindFirstBit(diff);
 
			ClrBit(diff, button);
 
			if (HasBit(mouse_b, button)) {
 
				/* Pressed mouse button */
 
				if (_rightclick_emulate && key_shifts & KB_CTRL_FLAG) {
 
				if (_rightclick_emulate && (key_shifts & KB_CTRL_FLAG)) {
 
					button = RIGHT_BUTTON;
 
					ClrBit(diff, RIGHT_BUTTON);
 
				}
 
				switch (button) {
 
					case LEFT_BUTTON:
 
						_left_button_down = true;
 
						break;
 

	
 
					case RIGHT_BUTTON:
 
						_right_button_down = true;
 
						_right_button_clicked = true;
 
						break;
 
@@ -382,25 +382,25 @@ static void PollEvent()
 
	}
 

	
 
	static int prev_mouse_z = 0;
 
	if (prev_mouse_z != mouse_z) {
 
		_cursor.wheel = (prev_mouse_z - mouse_z) < 0 ? -1 : 1;
 
		prev_mouse_z = mouse_z;
 
		mouse_action = true;
 
	}
 

	
 
	if (mouse_action) HandleMouseEvents();
 

	
 
	poll_keyboard();
 
	if (key_shifts & KB_ALT_FLAG && (key[KEY_ENTER] || key[KEY_F])) {
 
	if ((key_shifts & KB_ALT_FLAG) && (key[KEY_ENTER] || key[KEY_F])) {
 
		ToggleFullScreen(!_fullscreen);
 
	} else if (keypressed()) {
 
		HandleKeypress(ConvertAllegroKeyIntoMy());
 
	}
 
}
 

	
 
/** There are multiple modules that might be using Allegro and
 
 * Allegro can only be initiated once. */
 
int _allegro_instance_count = 0;
 

	
 
const char *VideoDriver_Allegro::Start(const char * const *parm)
 
{
src/widget.cpp
Show inline comments
 
@@ -132,30 +132,28 @@ void ScrollbarClickHandler(Window *w, co
 
	w->SetDirty();
 
}
 

	
 
/** Returns the index for the widget located at the given position
 
 * relative to the window. It includes all widget-corner pixels as well.
 
 * @param *w Window to look inside
 
 * @param  x The Window client X coordinate
 
 * @param  y The Window client y coordinate
 
 * @return A widget index, or -1 if no widget was found.
 
 */
 
int GetWidgetFromPos(const Window *w, int x, int y)
 
{
 
	uint index;
 
	int found_index = -1;
 

	
 
	/* Go through the widgets and check if we find the widget that the coordinate is
 
	 * inside. */
 
	for (index = 0; index < w->widget_count; index++) {
 
	/* Go through the widgets and check if we find the widget that the coordinate is inside. */
 
	for (uint index = 0; index < w->widget_count; index++) {
 
		const Widget *wi = &w->widget[index];
 
		if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
 

	
 
		if (x >= wi->left && x <= wi->right && y >= wi->top &&  y <= wi->bottom &&
 
				!w->IsWidgetHidden(index)) {
 
			found_index = index;
 
		}
 
	}
 

	
 
	return found_index;
 
}
 

	
src/window.cpp
Show inline comments
 
@@ -317,33 +317,33 @@ static void DispatchLeftClickEvent(Windo
 
		if (w->desc_flags & WDF_STD_BTN) {
 
			if (widget_type == WWT_CLOSEBOX) { // 'X'
 
				delete w;
 
				return;
 
			}
 

	
 
			if (widget_type == WWT_CAPTION) { // 'Title bar'
 
				StartWindowDrag(w);
 
				return;
 
			}
 
		}
 

	
 
		if (w->desc_flags & WDF_RESIZABLE && widget_type == WWT_RESIZEBOX) {
 
		if ((w->desc_flags & WDF_RESIZABLE) && widget_type == WWT_RESIZEBOX) {
 
			/* When the resize widget is on the left size of the window
 
			 * we assume that that button is used to resize to the left. */
 
			StartWindowSizing(w, wi->left < (w->width / 2));
 
			w->InvalidateWidget(widget_index);
 
			return;
 
		}
 

	
 
		if (w->desc_flags & WDF_STICKY_BUTTON && widget_type == WWT_STICKYBOX) {
 
		if ((w->desc_flags & WDF_STICKY_BUTTON) && widget_type == WWT_STICKYBOX) {
 
			w->flags4 ^= WF_STICKY;
 
			w->InvalidateWidget(widget_index);
 
			return;
 
		}
 
	}
 

	
 
	Point pt = { x, y };
 

	
 
	if (double_click) {
 
		w->OnDoubleClick(pt, widget_index);
 
	} else {
 
		w->OnClick(pt, widget_index);
 
@@ -1231,25 +1231,25 @@ static void DecreaseWindowCounters()
 
{
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		/* Unclick scrollbar buttons if they are pressed. */
 
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
 
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
 
			w->SetDirty();
 
		}
 
		w->OnMouseLoop();
 
	}
 

	
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		if (w->flags4 & WF_TIMEOUT_MASK && !(--w->flags4 & WF_TIMEOUT_MASK)) {
 
		if ((w->flags4 & WF_TIMEOUT_MASK) && !(--w->flags4 & WF_TIMEOUT_MASK)) {
 
			w->OnTimeout();
 
			if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons();
 
		}
 
	}
 
}
 

	
 
Window *GetCallbackWnd()
 
{
 
	return FindWindowById(_thd.window_class, _thd.window_number);
 
}
 

	
 
static void HandlePlacePresize()
 
@@ -1542,25 +1542,25 @@ static bool HandleWindowDragging()
 
			if ((int)w->width + x < (int)w->resize.width) {
 
				x = w->resize.width - w->width;
 
			}
 
			if ((int)w->height + y < (int)w->resize.height) {
 
				y = w->resize.height - w->height;
 
			}
 

	
 
			/* Window already on size */
 
			if (x == 0 && y == 0) return false;
 

	
 
			/* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
 
			_drag_delta.y += y;
 
			if (w->flags4 & WF_SIZING_LEFT && x != 0) {
 
			if ((w->flags4 & WF_SIZING_LEFT) && x != 0) {
 
				_drag_delta.x -= x; // x > 0 -> window gets longer -> left-edge moves to left -> subtract x to get new position.
 
				w->SetDirty();
 
				w->left -= x;  // If dragging left edge, move left window edge in opposite direction by the same amount.
 
				/* ResizeWindow() below ensures marking new position as dirty. */
 
			} else {
 
				_drag_delta.x += x;
 
			}
 

	
 
			/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
 
			ResizeWindow(w, x, y);
 

	
 
			Point diff;
0 comments (0 inline, 0 general)