src/newgrf_station.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6683 7ec558346172
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
    59 	station_classes[1].spec[0] = NULL;
    59 	station_classes[1].spec[0] = NULL;
    60 }
    60 }
    61 
    61 
    62 /**
    62 /**
    63  * Allocate a station class for the given class id.
    63  * Allocate a station class for the given class id.
    64  * @param classid A 32 bit value identifying the class.
    64  * @param cls A 32 bit value identifying the class.
    65  * @return Index into station_classes of allocated class.
    65  * @return Index into station_classes of allocated class.
    66  */
    66  */
    67 StationClassID AllocateStationClass(uint32 cls)
    67 StationClassID AllocateStationClass(uint32 cls)
    68 {
    68 {
    69 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
    69 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
   136 	return station_classes[sclass].stations;
   136 	return station_classes[sclass].stations;
   137 }
   137 }
   138 
   138 
   139 /**
   139 /**
   140  * Tie a station spec to its station class.
   140  * Tie a station spec to its station class.
   141  * @param spec The station spec.
   141  * @param statspec The station spec.
   142  */
   142  */
   143 void SetCustomStationSpec(StationSpec *statspec)
   143 void SetCustomStationSpec(StationSpec *statspec)
   144 {
   144 {
   145 	StationClass *station_class;
   145 	StationClass *station_class;
   146 	int i;
   146 	int i;
   182 
   182 
   183 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
   183 	for (StationClassID i = STAT_CLASS_BEGIN; i < STAT_CLASS_MAX; i++) {
   184 		for (j = 0; j < station_classes[i].stations; j++) {
   184 		for (j = 0; j < station_classes[i].stations; j++) {
   185 			const StationSpec *statspec = station_classes[i].spec[j];
   185 			const StationSpec *statspec = station_classes[i].spec[j];
   186 			if (statspec == NULL) continue;
   186 			if (statspec == NULL) continue;
   187 			if (statspec->grfid == grfid && statspec->localidx == localidx) return statspec;
   187 			if (statspec->grffile->grfid == grfid && statspec->localidx == localidx) return statspec;
   188 		}
   188 		}
   189 	}
   189 	}
   190 
   190 
   191 	return NULL;
   191 	return NULL;
   192 }
   192 }
   305 
   305 
   306 	uint32 res = 0;
   306 	uint32 res = 0;
   307 	uint i;
   307 	uint i;
   308 
   308 
   309 	for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
   309 	for (i = 0; i < lengthof(x_dir); i++, dir++, diagdir++) {
   310 		uint32 ts = GetTileTrackStatus(tile + TileOffsByDir(*dir), TRANSPORT_RAIL);
   310 		uint32 ts = GetTileTrackStatus(tile + TileOffsByDir(*dir), TRANSPORT_RAIL, 0);
   311 		if (ts != 0) {
   311 		if (ts != 0) {
   312 			/* If there is any track on the tile, set the bit in the second byte */
   312 			/* If there is any track on the tile, set the bit in the second byte */
   313 			SETBIT(res, i + 8);
   313 			SETBIT(res, i + 8);
   314 
   314 
   315 			/* If any track reaches our exit direction, set the bit in the lower byte */
   315 			/* If any track reaches our exit direction, set the bit in the lower byte */
   407 			return value;
   407 			return value;
   408 		}
   408 		}
   409 		case 0x49: return GetPlatformInfoHelper(tile, false, true, false);
   409 		case 0x49: return GetPlatformInfoHelper(tile, false, true, false);
   410 
   410 
   411 		/* Variables which use the parameter */
   411 		/* Variables which use the parameter */
   412 		case 0x60: return GB(st->goods[parameter].waiting_acceptance, 0, 12);
   412 		/* Variables 0x60 to 0x65 are handled separately below */
   413 		case 0x61: return st->goods[parameter].days_since_pickup;
       
   414 		case 0x62: return st->goods[parameter].rating;
       
   415 		case 0x63: return st->goods[parameter].enroute_time;
       
   416 		case 0x64: return st->goods[parameter].last_speed | (st->goods[parameter].last_age << 8);
       
   417 		case 0x65: return GB(st->goods[parameter].waiting_acceptance, 12, 4);
       
   418 
   413 
   419 		/* General station properties */
   414 		/* General station properties */
   420 		case 0x82: return 50;
   415 		case 0x82: return 50;
   421 		case 0x84: return st->string_id;
   416 		case 0x84: return st->string_id;
   422 		case 0x86: return 0;
   417 		case 0x86: return 0;
   428 		case 0xF6: return st->airport_flags;
   423 		case 0xF6: return st->airport_flags;
   429 		case 0xF7: return GB(st->airport_flags, 8, 8);
   424 		case 0xF7: return GB(st->airport_flags, 8, 8);
   430 		case 0xFA: return max(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
   425 		case 0xFA: return max(st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0);
   431 	}
   426 	}
   432 
   427 
       
   428 	/* Handle cargo variables with parameter, 0x60 to 0x65 */
       
   429 	if (variable >= 0x60 && variable <= 0x65) {
       
   430 		CargoID c = GetCargoTranslation(parameter, object->u.station.statspec->grffile);
       
   431 
       
   432 		if (c == CT_INVALID) return 0;
       
   433 		const GoodsEntry *ge = &st->goods[c];
       
   434 
       
   435 		switch (variable) {
       
   436 			case 0x60: return GB(ge->waiting_acceptance, 0, 12);
       
   437 			case 0x61: return ge->days_since_pickup;
       
   438 			case 0x62: return ge->rating;
       
   439 			case 0x63: return ge->enroute_time;
       
   440 			case 0x64: return ge->last_speed | (ge->last_age << 8);
       
   441 			case 0x65: return GB(ge->waiting_acceptance, 12, 4);
       
   442 		}
       
   443 	}
       
   444 
   433 	/* Handle cargo variables (deprecated) */
   445 	/* Handle cargo variables (deprecated) */
   434 	if (variable >= 0x8C && variable <= 0xEC) {
   446 	if (variable >= 0x8C && variable <= 0xEC) {
   435 		const GoodsEntry *g = &st->goods[GB(variable - 0x8C, 3, 4)];
   447 		const GoodsEntry *g = &st->goods[GB(variable - 0x8C, 3, 4)];
   436 		switch (GB(variable - 0x8C, 0, 3)) {
   448 		switch (GB(variable - 0x8C, 0, 3)) {
   437 			case 0: return g->waiting_acceptance;
   449 			case 0: return g->waiting_acceptance;
   600 }
   612 }
   601 
   613 
   602 
   614 
   603 /**
   615 /**
   604  * Allocate a StationSpec to a Station. This is called once per build operation.
   616  * Allocate a StationSpec to a Station. This is called once per build operation.
   605  * @param spec StationSpec to allocate.
   617  * @param statspec StationSpec to allocate.
   606  * @param st Station to allocate it to.
   618  * @param st Station to allocate it to.
   607  * @param exec Whether to actually allocate the spec.
   619  * @param exec Whether to actually allocate the spec.
   608  * @return Index within the Station's spec list, or -1 if the allocation failed.
   620  * @return Index within the Station's spec list, or -1 if the allocation failed.
   609  */
   621  */
   610 int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec)
   622 int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec)
   636 				st->speclist[0].localidx = 0;
   648 				st->speclist[0].localidx = 0;
   637 			}
   649 			}
   638 		}
   650 		}
   639 
   651 
   640 		st->speclist[i].spec     = statspec;
   652 		st->speclist[i].spec     = statspec;
   641 		st->speclist[i].grfid    = statspec->grfid;
   653 		st->speclist[i].grfid    = statspec->grffile->grfid;
   642 		st->speclist[i].localidx = statspec->localidx;
   654 		st->speclist[i].localidx = statspec->localidx;
   643 	}
   655 	}
   644 
   656 
   645 	return i;
   657 	return i;
   646 }
   658 }
   681 		}
   693 		}
   682 	}
   694 	}
   683 }
   695 }
   684 
   696 
   685 /** Draw representation of a station tile for GUI purposes.
   697 /** Draw representation of a station tile for GUI purposes.
   686  * @param x, y Position of image.
   698  * @param x Position x of image.
   687  * @param dir Direction.
   699  * @param y Position y of image.
       
   700  * @param axis Axis.
   688  * @param railtype Rail type.
   701  * @param railtype Rail type.
   689  * @param sclass, station Type of station.
   702  * @param sclass, station Type of station.
       
   703  * @param station station ID
   690  * @return True if the tile was drawn (allows for fallback to default graphic)
   704  * @return True if the tile was drawn (allows for fallback to default graphic)
   691  */
   705  */
   692 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
   706 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
   693 {
   707 {
   694 	const StationSpec *statspec;
   708 	const StationSpec *statspec;