src/engine.cpp
branchnoai
changeset 9722 ebf0ece7d8f6
parent 9694 e72987579514
child 9723 eee46cb39750
equal deleted inserted replaced
9721:9a27928bcd5e 9722:ebf0ece7d8f6
   163 		}
   163 		}
   164 
   164 
   165 		e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
   165 		e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
   166 
   166 
   167 		/* prevent certain engines from ever appearing. */
   167 		/* prevent certain engines from ever appearing. */
   168 		if (!HASBIT(ei->climates, _opt.landscape)) {
   168 		if (!HasBit(ei->climates, _opt.landscape)) {
   169 			e->flags |= ENGINE_AVAILABLE;
   169 			e->flags |= ENGINE_AVAILABLE;
   170 			e->player_avail = 0;
   170 			e->player_avail = 0;
   171 		}
   171 		}
   172 
   172 
   173 		/* This sets up type for the engine
   173 		/* This sets up type for the engine
   181 static void AcceptEnginePreview(EngineID eid, PlayerID player)
   181 static void AcceptEnginePreview(EngineID eid, PlayerID player)
   182 {
   182 {
   183 	Engine *e = GetEngine(eid);
   183 	Engine *e = GetEngine(eid);
   184 	Player *p = GetPlayer(player);
   184 	Player *p = GetPlayer(player);
   185 
   185 
   186 	SETBIT(e->player_avail, player);
   186 	SetBit(e->player_avail, player);
   187 	if (e->type == VEH_TRAIN) {
   187 	if (e->type == VEH_TRAIN) {
   188 		const RailVehicleInfo *rvi = RailVehInfo(eid);
   188 		const RailVehicleInfo *rvi = RailVehInfo(eid);
   189 
   189 
   190 		assert(rvi->railtype < RAILTYPE_END);
   190 		assert(rvi->railtype < RAILTYPE_END);
   191 		SETBIT(p->avail_railtypes, rvi->railtype);
   191 		SetBit(p->avail_railtypes, rvi->railtype);
   192 	} else if (e->type == VEH_ROAD) {
   192 	} else if (e->type == VEH_ROAD) {
   193 		SETBIT(p->avail_roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   193 		SetBit(p->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   194 	}
   194 	}
   195 
   195 
   196 	e->preview_player = INVALID_PLAYER;
   196 	e->preview_player = INVALID_PLAYER;
   197 	if (player == _local_player) {
   197 	if (player == _local_player) {
   198 		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
   198 		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
   208 
   208 
   209 	do {
   209 	do {
   210 		best_hist = -1;
   210 		best_hist = -1;
   211 		best_player = PLAYER_SPECTATOR;
   211 		best_player = PLAYER_SPECTATOR;
   212 		FOR_ALL_PLAYERS(p) {
   212 		FOR_ALL_PLAYERS(p) {
   213 			if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) &&
   213 			if (p->is_active && p->block_preview == 0 && !HasBit(mask, p->index) &&
   214 					p->old_economy[0].performance_history > best_hist) {
   214 					p->old_economy[0].performance_history > best_hist) {
   215 				best_hist = p->old_economy[0].performance_history;
   215 				best_hist = p->old_economy[0].performance_history;
   216 				best_player = p->index;
   216 				best_player = p->index;
   217 			}
   217 			}
   218 		}
   218 		}
   219 
   219 
   220 		if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR;
   220 		if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR;
   221 
   221 
   222 		SETBIT(mask, best_player);
   222 		SetBit(mask, best_player);
   223 	} while (pp--, pp != 0);
   223 	} while (pp--, pp != 0);
   224 
   224 
   225 	return best_player;
   225 	return best_player;
   226 }
   226 }
   227 
   227 
   298 	 * prevent that player from getting future intro periods for a while. */
   298 	 * prevent that player from getting future intro periods for a while. */
   299 	if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
   299 	if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
   300 		FOR_ALL_PLAYERS(p) {
   300 		FOR_ALL_PLAYERS(p) {
   301 			uint block_preview = p->block_preview;
   301 			uint block_preview = p->block_preview;
   302 
   302 
   303 			if (!HASBIT(e->player_avail, p->index)) continue;
   303 			if (!HasBit(e->player_avail, p->index)) continue;
   304 
   304 
   305 			/* We assume the user did NOT build it.. prove me wrong ;) */
   305 			/* We assume the user did NOT build it.. prove me wrong ;) */
   306 			p->block_preview = 20;
   306 			p->block_preview = 20;
   307 
   307 
   308 			FOR_ALL_VEHICLES(v) {
   308 			FOR_ALL_VEHICLES(v) {
   330 	if (index < NUM_TRAIN_ENGINES) {
   330 	if (index < NUM_TRAIN_ENGINES) {
   331 		/* maybe make another rail type available */
   331 		/* maybe make another rail type available */
   332 		RailType railtype = RailVehInfo(index)->railtype;
   332 		RailType railtype = RailVehInfo(index)->railtype;
   333 		assert(railtype < RAILTYPE_END);
   333 		assert(railtype < RAILTYPE_END);
   334 		FOR_ALL_PLAYERS(p) {
   334 		FOR_ALL_PLAYERS(p) {
   335 			if (p->is_active) SETBIT(p->avail_railtypes, railtype);
   335 			if (p->is_active) SetBit(p->avail_railtypes, railtype);
   336 		}
   336 		}
   337 	}
   337 	}
   338 	if ((index - NUM_TRAIN_ENGINES) < NUM_ROAD_ENGINES) {
   338 	if ((index - NUM_TRAIN_ENGINES) < NUM_ROAD_ENGINES) {
   339 		/* maybe make another road type available */
   339 		/* maybe make another road type available */
   340 		FOR_ALL_PLAYERS(p) {
   340 		FOR_ALL_PLAYERS(p) {
   341 			if (p->is_active) SETBIT(p->avail_roadtypes, HASBIT(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   341 			if (p->is_active) SetBit(p->avail_roadtypes, HasBit(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   342 		}
   342 		}
   343 	}
   343 	}
   344 	AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL), 0, 0);
   344 	AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL), 0, 0);
   345 }
   345 }
   346 
   346 
   434 
   434 
   435 	/* check if it's an engine of specified type */
   435 	/* check if it's an engine of specified type */
   436 	if (e->type != type) return false;
   436 	if (e->type != type) return false;
   437 
   437 
   438 	/* check if it's available */
   438 	/* check if it's available */
   439 	if (!HASBIT(e->player_avail, player)) return false;
   439 	if (!HasBit(e->player_avail, player)) return false;
   440 
   440 
   441 	if (type == VEH_TRAIN) {
   441 	if (type == VEH_TRAIN) {
   442 		/* Check if the rail type is available to this player */
   442 		/* Check if the rail type is available to this player */
   443 		const Player *p = GetPlayer(player);
   443 		const Player *p = GetPlayer(player);
   444 		if (!HASBIT(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
   444 		if (!HasBit(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
   445 	}
   445 	}
   446 
   446 
   447 	return true;
   447 	return true;
   448 }
   448 }
   449 
   449