Bernhard
Forum-Team
Beiträge: 9.373
Registriert seit: Jan 2004
|
hier ist der Thread. Bei mir ist es allerdings nie gelaufen .
http://www.tt-forums.net/viewtopic.php?t=9293
und hier die Diff http://www.tt-forums.net//files/usedtracksv1.diff
Code:
Index: OpenTTD_UsedTracks/ttd.h
===================================================================
--- OpenTTD_UsedTracks/ttd.h (revision 71)
+++ OpenTTD_UsedTracks/ttd.h (working copy)
@@ -472,7 +472,8 @@
enum Sprites {
SPR_CANALS_BASE = 0x1406,
SPR_SLOPES_BASE = SPR_CANALS_BASE + 70,
- SPR_OPENTTD_BASE = SPR_SLOPES_BASE + 74,
+ SPR_OPENTTD_BASE = SPR_SLOPES_BASE + 74,
+ SPR_USED_TRACKS_BASE = SPR_OPENTTD_BASE + 75,
};
enum MAP_OWNERS {
Index: OpenTTD_UsedTracks/variables.h
===================================================================
--- OpenTTD_UsedTracks/variables.h (revision 71)
+++ OpenTTD_UsedTracks/variables.h (working copy)
@@ -397,7 +397,9 @@
extern byte _map3_hi[TILES_X * TILES_Y];
extern byte _map_owner[TILES_X * TILES_Y];
extern byte _map2[TILES_X * TILES_Y];
-extern byte _map_extra_bits[TILES_X * TILES_Y/4];
+extern byte _map_extra_bits[TILES_X * TILES_Y/4];
+// usage of tracks need bits
+extern byte _map_usage[TILES_X * TILES_Y];
static const byte _inclined_tileh[] = {
3,9,3,6,12,6,12,9,
Index: OpenTTD_UsedTracks/gfx.h
===================================================================
--- OpenTTD_UsedTracks/gfx.h (revision 71)
+++ OpenTTD_UsedTracks/gfx.h (working copy)
@@ -102,6 +102,7 @@
//enum { NUM_SPRITES = 0x1320 };
//enum { NUM_SPRITES = 0x1500 };
enum { NUM_SPRITES = 0x3500 }; // 1500 + space for custom GRF sets
+
/* tables.h */
extern byte _palettes[4][256 * 3];
Index: OpenTTD_UsedTracks/train_cmd.c
===================================================================
--- OpenTTD_UsedTracks/train_cmd.c (revision 71)
+++ OpenTTD_UsedTracks/train_cmd.c (working copy)
@@ -2096,6 +2096,9 @@
AffectSpeedByDirChange(v, chosen_dir);
}
+ // al is ok, update track usage:
+ UpdateTrackUsage(v->tile,1);
+
v->direction = chosen_dir;
}
} else {
Index: OpenTTD_UsedTracks/rail_cmd.c
===================================================================
--- OpenTTD_UsedTracks/rail_cmd.c (revision 71)
+++ OpenTTD_UsedTracks/rail_cmd.c (working copy)
@@ -31,6 +31,14 @@
RAIL_CHECKPOINT_TRACK_MASK = 1,
RAIL_CHECKPOINT_UNUSED_BITS = 0x3E,
};
+
+enum { /* track usage */
+ USAGE_NEVER = 0,
+ USAGE_RARE = 5,
+ USAGE_NORMAL = 50,
+ USAGE_OFTEN = 100,
+};
+
#define IS_RAIL_DEPOT(x) (((x) & (RAIL_TYPE_DEPOT|RAIL_DEPOT_UNUSED_BITS)) == RAIL_TYPE_DEPOT)
#define IS_RAIL_CHECKPOINT(x) (((x) & (RAIL_TYPE_CHECKPOINT|RAIL_CHECKPOINT_UNUSED_BITS)) == RAIL_TYPE_CHECKPOINT)
@@ -92,8 +100,37 @@
* 01abcdef => rail w/ signals
* 10uuuuuu => unused
* 11uuuudd => rail depot
- */
+ */
+
+// return (new) state of track
+int UpdateTrackUsage(uint tile, int amount)
+{
+ int before = _map_usage[tile];
+
+ // do nothing.
+ if (amount >=0 ) {
+ if (_map_usage[tile] >= 200 ) amount = 0;
+ }else{// decrease
+ if (_map_usage[tile] == USAGE_NEVER ) amount = 0;
+ }
+
+ _map_usage[tile] += amount;
+
+ if (before != _map_usage[tile])
+ MarkTileDirtyByTile(tile);
+
+
+ if (_map_usage[tile]== USAGE_NEVER) return USAGE_NEVER;
+
+ else if (_map_usage[tile] < USAGE_NORMAL) return USAGE_RARE;
+
+ else if (_map_usage[tile] < USAGE_OFTEN) return USAGE_NORMAL;
+
+ else return USAGE_OFTEN;
+
+}
+
static bool CheckTrackCombination(byte map5, byte trackbits, byte flags)
{
_error_message = STR_1001_IMPOSSIBLE_TRACK_COMBINATION;
@@ -364,7 +401,9 @@
_map_type_and_height[tile] &= 0xF;
_map_type_and_height[tile] |= MP_RAILWAY << 4;
_map5[tile] |= rail_bit;
- _map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK;
+ _map2[tile] &= ~RAIL_MAP2LO_GROUND_MASK;
+
+ _map_usage[tile] = (USAGE_NORMAL + USAGE_OFTEN)/2; // start in between
// In case it's a tile without signals, clear the signal bits. Why?
if ((_map5[tile] & RAIL_TYPE_MASK) != RAIL_TYPE_SIGNALS)
@@ -1403,72 +1442,89 @@
DetTrackDrawProc_Null,
DetTrackDrawProc_Null,
};
+
+
static void DrawTile_Track(TileInfo *ti)
-{
+{
+ // never, rarely, normal, often, standard, monorail, maglev
+ int usage_offs[4] = {0,59,118,177 };
uint32 tracktype_offs, image;
- byte m5;
+ byte m5;
+ int u = 3; //0-3
_drawtile_track_palette = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_map_owner[ti->tile]));
+
+ if ( _map3_lo[ti->tile] & 0xF ){ //mono/maglev
+ tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
+ }else{ // normal rail
+ switch (UpdateTrackUsage(ti->tile,0)){
+ case USAGE_NEVER: u = 0; break;
+ case USAGE_RARE: u = 1; break;
+ case USAGE_NORMAL: u = 2; break;
+ case USAGE_OFTEN: u = 3; break;
+ }
+ tracktype_offs = SPR_USED_TRACKS_BASE + usage_offs[u] + 7 - 0x3F3;
+ }
- tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
m5 = (byte)ti->map5;
if (!(m5 & RAIL_TYPE_SPECIAL)) {
- bool special;
-
+ bool special;
+
m5 &= RAIL_BIT_MASK;
+
special = false;
- // select the sprite to use based on the map5 byte.
- (image = 0x3F3, m5 == RAIL_BIT_DIAG2) ||
- (image++, m5 == RAIL_BIT_DIAG1) ||
- (image++, m5 == RAIL_BIT_UPPER) ||
- (image++, m5 == RAIL_BIT_LOWER) ||
- (image++, m5 == RAIL_BIT_RIGHT) ||
- (image++, m5 == RAIL_BIT_LEFT) ||
- (image++, m5 == (RAIL_BIT_DIAG1|RAIL_BIT_DIAG2)) ||
-
- (image = 0x40B, m5 == (RAIL_BIT_UPPER|RAIL_BIT_LOWER)) ||
- (image++, m5 == (RAIL_BIT_LEFT|RAIL_BIT_RIGHT)) ||
-
- (special=true, false) ||
-
- (image = 0x3FA, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_UPPER|RAIL_BIT_DIAG1))) ||
- (image++, !(m5 & (RAIL_BIT_LEFT|RAIL_BIT_LOWER|RAIL_BIT_DIAG1))) ||
- (image++, !(m5 & (RAIL_BIT_LEFT|RAIL_BIT_UPPER|RAIL_BIT_DIAG2))) ||
- (image++, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_LOWER|RAIL_BIT_DIAG2))) ||
- (image++, true);
-
- if (ti->tileh != 0) {
- int f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
- if (f) DrawFoundation(ti, f);
-
- // default sloped sprites.
- if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
+ // select the sprite to use based on the map5 byte.
+ (image = 0x3F3, m5 == RAIL_BIT_DIAG2) ||
+ (image++, m5 == RAIL_BIT_DIAG1) ||
+ (image++, m5 == RAIL_BIT_UPPER) ||
+ (image++, m5 == RAIL_BIT_LOWER) ||
+ (image++, m5 == RAIL_BIT_RIGHT) ||
+ (image++, m5 == RAIL_BIT_LEFT) ||
+ (image++, m5 == (RAIL_BIT_DIAG1|RAIL_BIT_DIAG2)) ||
+
+ (image = 0x40B, m5 == (RAIL_BIT_UPPER|RAIL_BIT_LOWER)) ||
+ (image++, m5 == (RAIL_BIT_LEFT|RAIL_BIT_RIGHT)) ||
+
+ (special=true, false) ||
+
+ (image = 0x3FA, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_UPPER|RAIL_BIT_DIAG1))) ||
+ (image++, !(m5 & (RAIL_BIT_LEFT|RAIL_BIT_LOWER|RAIL_BIT_DIAG1))) ||
+ (image++, !(m5 & (RAIL_BIT_LEFT|RAIL_BIT_UPPER|RAIL_BIT_DIAG2))) ||
+ (image++, !(m5 & (RAIL_BIT_RIGHT|RAIL_BIT_LOWER|RAIL_BIT_DIAG2))) ||
+ (image++, true);
+
+ if (ti->tileh != 0) {
+ int f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
+ if (f) DrawFoundation(ti, f);
+
+ // default sloped sprites.
+ if (ti->tileh != 0) image = _track_sloped_sprites[ti->tileh - 1] + 0x3F3;
+ }
+
+ if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN)
+ image = (image & 0xFFFF) | 0x3178000; // use a brown palette
+ else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT)
+ image += 26;
+
+ DrawGroundSprite(image + tracktype_offs);
+
+ if (special) {
+ if (m5 & RAIL_BIT_DIAG1) DrawGroundSprite(0x3ED + tracktype_offs);
+ if (m5 & RAIL_BIT_DIAG2) DrawGroundSprite(0x3EE + tracktype_offs);
+ if (m5 & RAIL_BIT_UPPER) DrawGroundSprite(0x3EF + tracktype_offs);
+ if (m5 & RAIL_BIT_LOWER) DrawGroundSprite(0x3F0 + tracktype_offs);
+ if (m5 & RAIL_BIT_LEFT) DrawGroundSprite(0x3F2 + tracktype_offs);
+ if (m5 & RAIL_BIT_RIGHT) DrawGroundSprite(0x3F1 + tracktype_offs);
+ }
+
+ if (_display_opt & DO_FULL_DETAIL) {
+ _detailed_track_proc[_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK](ti);
}
- if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_BROWN)
- image = (image & 0xFFFF) | 0x3178000; // use a brown palette
- else if ((_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK)==RAIL_GROUND_ICE_DESERT)
- image += 26;
-
- DrawGroundSprite(image + tracktype_offs);
-
- if (special) {
- if (m5 & RAIL_BIT_DIAG1) DrawGroundSprite(0x3ED + tracktype_offs);
- if (m5 & RAIL_BIT_DIAG2) DrawGroundSprite(0x3EE + tracktype_offs);
- if (m5 & RAIL_BIT_UPPER) DrawGroundSprite(0x3EF + tracktype_offs);
- if (m5 & RAIL_BIT_LOWER) DrawGroundSprite(0x3F0 + tracktype_offs);
- if (m5 & RAIL_BIT_LEFT) DrawGroundSprite(0x3F2 + tracktype_offs);
- if (m5 & RAIL_BIT_RIGHT) DrawGroundSprite(0x3F1 + tracktype_offs);
- }
-
- if (_display_opt & DO_FULL_DETAIL) {
- _detailed_track_proc[_map2[ti->tile] & RAIL_MAP2LO_GROUND_MASK](ti);
- }
-
/* draw signals also? */
if (!(ti->map5 & RAIL_TYPE_SIGNALS))
return;
@@ -1511,8 +1567,12 @@
}
} else {
const byte *s;
- const DrawTrackSeqStruct *drss;
+ const DrawTrackSeqStruct *drss;
+
+ // to normal value again(depots and stuff)
+ tracktype_offs = (_map3_lo[ti->tile] & 0xF) * TRACKTYPE_SPRITE_PITCH;
+
if (!(m5 & (RAIL_TYPE_MASK&~RAIL_TYPE_SPECIAL)))
return;
@@ -1854,7 +1914,9 @@
byte m2;
byte owner;
- m2 = _map2[tile] & 0xF;
+ m2 = _map2[tile] & 0xF;
+
+ UpdateTrackUsage(tile,-1);
/* special code for alps landscape */
if (_opt.landscape == LT_HILLY) {
Index: OpenTTD_UsedTracks/landscape.c
===================================================================
--- OpenTTD_UsedTracks/landscape.c (revision 71)
+++ OpenTTD_UsedTracks/landscape.c (working copy)
@@ -12,7 +12,8 @@
byte _map3_hi[TILES_X * TILES_Y];
byte _map_owner[TILES_X * TILES_Y];
byte _map2[TILES_X * TILES_Y];
-byte _map_extra_bits[TILES_X * TILES_Y/4];
+byte _map_extra_bits[TILES_X * TILES_Y/4];
+byte _map_usage[TILES_X * TILES_Y];
extern const TileTypeProcs
_tile_type_clear_procs,
@@ -499,7 +500,8 @@
for(i=0; i!=TILES_Y-1; i++)
memset(_map_type_and_height + i*TILES_X, 0, TILES_X-1);
- memset(_map5, 3, sizeof(_map5));
+ memset(_map5, 3, sizeof(_map5));
+ memset(_map_usage,0,sizeof(_map_usage));
}
void ConvertGroundTilesIntoWaterTiles()
Index: OpenTTD_UsedTracks/spritecache.c
===================================================================
--- OpenTTD_UsedTracks/spritecache.c (revision 71)
+++ OpenTTD_UsedTracks/spritecache.c (working copy)
@@ -699,7 +699,11 @@
load_index = SPR_CANALS_BASE;
load_index += LoadGrfFile("canalsw.grf", load_index, i++);
/* XXX: Only for debugging. Will be more generic. */
-
+
+ // Dribbel: Used Tracks
+ load_index = SPR_USED_TRACKS_BASE;
+ load_index += LoadGrfFile("used.grf", load_index, i++);
+
for(j=0; j!=lengthof(_newgrf_files) && _newgrf_files[j]; j++)
load_index += LoadGrfFile(_newgrf_files[j], load_index, i++);
@@ -714,7 +718,8 @@
FioOpenFile(i,_filename_list[i]);
FioOpenFile(i, "openttd.grf");
- FioOpenFile(i+1, "canalsw.grf");
+ FioOpenFile(i+1, "canalsw.grf");
+ FioOpenFile(i+2, "used.grf");
if (_sprite_page_to_load != 0)
FioOpenFile(i+2, _landscape_filenames[_sprite_page_to_load-1]);
"Das Böse triumphiert alleine dadurch, daß gute Menschen nichts unternehmen!" Edward Burke, 1729-1797
"Wir leben alle unter dem gleichen Himmel, aber wir haben nicht alle den gleichen Horizont!" Konrad Adenauer, 1876-1976
|
|