Skip to content

Commit

Permalink
Import version 88.10.2
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@71 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
chmallon committed Aug 20, 2006
1 parent 2c1facb commit 0d7defc
Show file tree
Hide file tree
Showing 47 changed files with 843 additions and 545 deletions.
4 changes: 2 additions & 2 deletions besch/reader/factory_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ factory_reader_t::read_node(FILE *fp, obj_node_info_t &node)
besch->produktivitaet = decode_uint16(p);
besch->bereich = decode_uint16(p);
besch->gewichtung = decode_uint16(p);
besch->kennfarbe = decode_uint16(p);
besch->kennfarbe = (uint8)decode_uint16(p);
besch->lieferanten = decode_uint16(p);
besch->produkte = decode_uint16(p);
besch->pax_level = decode_uint16(p);
Expand All @@ -183,7 +183,7 @@ DBG_DEBUG("factory_reader_t::read_node()","version=0");
besch->produktivitaet = decode_uint16(p)|0x8000;
besch->bereich = decode_uint16(p);
besch->gewichtung = decode_uint16(p);
besch->kennfarbe = decode_uint16(p);
besch->kennfarbe = (uint8)decode_uint16(p);
besch->lieferanten = decode_uint16(p);
besch->produkte = decode_uint16(p);
besch->pax_level = 12;
Expand Down
2 changes: 1 addition & 1 deletion besch/reader/tree_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ obj_besch_t * tree_reader_t::read_node(FILE *fp, obj_node_info_t &node)
besch->distribution_weight = (uint8)decode_uint8(p);
} else {
// old node, version 0
besch->hoehenlage = (uint16)v;
besch->hoehenlage = (uint8)v;
besch->distribution_weight = 3;
}
DBG_DEBUG("tree_reader_t::read_node()", "hoehe=%i and weight=%i (ver=%i, node.size=%i)",besch->hoehenlage,besch->distribution_weight, version, node.size);
Expand Down
12 changes: 6 additions & 6 deletions besch/reader/vehicle_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,16 @@ obj_besch_t * vehicle_reader_t::read_node(FILE *fp, obj_node_info_t &node)
} else {
// old node, version 0

besch->typ = v;
besch->typ = (sint8)v;
besch->zuladung = decode_uint16(p);
besch->preis = decode_uint32(p);
besch->geschw = decode_uint16(p);
besch->gewicht = decode_uint16(p);
besch->leistung = decode_uint16(p);
besch->betriebskosten = decode_uint16(p);
besch->sound = decode_sint16(p);
besch->vorgaenger = decode_uint16(p);
besch->nachfolger = decode_uint16(p);
besch->sound = (sint8)decode_sint16(p);
besch->vorgaenger = (sint8)decode_uint16(p);
besch->nachfolger = (sint8)decode_uint16(p);

besch->intro_date = DEFAULT_INTRO_DATE*16;
besch->obsolete_date = (DEFAULT_RETIRE_DATE*16);
Expand Down Expand Up @@ -325,12 +325,12 @@ obj_besch_t * vehicle_reader_t::read_node(FILE *fp, obj_node_info_t &node)
for(uint8 i=0; i<len; i++) {
wavname[i] = decode_sint8(p);
}
besch->sound = sound_besch_t::gib_sound_id(wavname);
besch->sound = (sint8)sound_besch_t::gib_sound_id(wavname);
DBG_MESSAGE("vehicle_reader_t::register_obj()","sound %s to %i",wavname,besch->sound);
}
else if(besch->sound>=0 && besch->sound<=MAX_OLD_SOUNDS) {
sint16 old_id = besch->sound;
besch->sound = sound_besch_t::get_compatible_sound_id(old_id);
besch->sound = (sint8)sound_besch_t::get_compatible_sound_id(old_id);
DBG_MESSAGE("vehicle_reader_t::register_obj()","old sound %i to %i",old_id,besch->sound);
}

Expand Down
183 changes: 94 additions & 89 deletions besch/reader/way_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,102 +61,107 @@ bool way_reader_t::successfully_loaded() const
*/
obj_besch_t * way_reader_t::read_node(FILE *fp, obj_node_info_t &node)
{
// DBG_DEBUG("way_reader_t::read_node()", "called");

#ifdef _MSC_VER /* no var array on the stack supported */
char *besch_buf = static_cast<char *>(alloca(node.size));
#else
// Hajo: reading buffer is better allocated on stack
char besch_buf [node.size];
#endif


char *info_buf = new char[sizeof(obj_besch_t) + node.children * sizeof(obj_besch_t *)];

weg_besch_t *besch = new weg_besch_t();

besch->node_info = reinterpret_cast<obj_besch_info_t *>(info_buf);

// DBG_DEBUG("way_reader_t::read_node()", "node size = %d", node.size);

// Hajo: Read data
fread(besch_buf, node.size, 1, fp);

char * p = besch_buf;

// Hajo: old versions of PAK files have no version stamp.
// But we know, the higher most bit was always cleared.

int version = 0;

if(node.size == 0) {
// old node, version 0, compatibility code

besch->price = 10000;
besch->maintenance = 800;
besch->topspeed = 999;
besch->max_weight = 999;
besch->intro_date = DEFAULT_INTRO_DATE*12;
besch->obsolete_date = DEFAULT_RETIRE_DATE*12;
besch->wtyp = weg_t::strasse;
besch->styp = 0;

/*
if(tstrequ(besch->gib_name(), "road")) {
besch->wtyp = weg_t::strasse;
besch->max_speed = 130;
} else {
besch->wtyp = weg_t::schiene;
besch->max_speed = 450;
}
*/

} else {

const uint16 v = decode_uint16(p);
version = v & 0x7FFF;

if(version == 2) {
// Versioned node, version 2

besch->price = decode_uint32(p);
besch->maintenance = decode_uint32(p);
besch->topspeed = decode_uint32(p);
besch->max_weight = decode_uint32(p);
besch->intro_date = decode_uint16(p);
besch->obsolete_date = decode_uint16(p);
besch->wtyp = decode_uint8(p);
besch->styp = decode_uint8(p);

} else if(version == 1) {
// Versioned node, version 1

besch->price = decode_uint32(p);
besch->maintenance = decode_uint32(p);
besch->topspeed = decode_uint32(p);
besch->max_weight = decode_uint32(p);
uint32 intro_date= decode_uint32(p);
besch->intro_date = (intro_date/16)*12 + (intro_date%16);
besch->wtyp = decode_uint8(p);
besch->styp = decode_uint8(p);
besch->obsolete_date = DEFAULT_RETIRE_DATE*12;

} else {
dbg->fatal("way_reader_t::read_node()","Invalid version %d", version);
}
}
if(besch->wtyp==weg_t::schiene_strab) {
besch->styp = 7;
besch->wtyp = weg_t::schiene;
}
else if(besch->styp==5 && besch->wtyp==weg_t::schiene) {
besch->wtyp = weg_t::monorail;
besch->styp = 0;
}
if(version<=2 && besch->wtyp==weg_t::luft && besch->topspeed>=250) {
// runway!
besch->styp = 1;
}
char *info_buf = new char[sizeof(obj_besch_t) + node.children * sizeof(obj_besch_t *)];
weg_besch_t *besch = new weg_besch_t();
besch->node_info = reinterpret_cast<obj_besch_info_t *>(info_buf);
// DBG_DEBUG("way_reader_t::read_node()", "node size = %d", node.size);

// Hajo: Read data
fread(besch_buf, node.size, 1, fp);
char * p = besch_buf;

// Hajo: old versions of PAK files have no version stamp.
// But we know, the higher most bit was always cleared.
int version = 0;

if(node.size == 0) {
// old node, version 0, compatibility code
besch->price = 10000;
besch->maintenance = 800;
besch->topspeed = 999;
besch->max_weight = 999;
besch->intro_date = DEFAULT_INTRO_DATE*12;
besch->obsolete_date = DEFAULT_RETIRE_DATE*12;
besch->wtyp = weg_t::strasse;
besch->styp = 0;
besch->draw_as_ding = false;
/*
if(tstrequ(besch->gib_name(), "road")) {
besch->wtyp = weg_t::strasse;
besch->max_speed = 130;
} else {
besch->wtyp = weg_t::schiene;
besch->max_speed = 450;
}
*/
}
else {

const uint16 v = decode_uint16(p);
version = v & 0x7FFF;

if(version==3) {
// Versioned node, version 3
besch->price = decode_uint32(p);
besch->maintenance = decode_uint32(p);
besch->topspeed = decode_uint32(p);
besch->max_weight = decode_uint32(p);
besch->intro_date = decode_uint16(p);
besch->obsolete_date = decode_uint16(p);
besch->wtyp = decode_uint8(p);
besch->styp = decode_uint8(p);
besch->draw_as_ding = decode_uint8(p);
}
else if(version==2) {
// Versioned node, version 2
besch->price = decode_uint32(p);
besch->maintenance = decode_uint32(p);
besch->topspeed = decode_uint32(p);
besch->max_weight = decode_uint32(p);
besch->intro_date = decode_uint16(p);
besch->obsolete_date = decode_uint16(p);
besch->wtyp = decode_uint8(p);
besch->styp = decode_uint8(p);
besch->draw_as_ding = false;
}
else if(version == 1) {
// Versioned node, version 1
besch->price = decode_uint32(p);
besch->maintenance = decode_uint32(p);
besch->topspeed = decode_uint32(p);
besch->max_weight = decode_uint32(p);
uint32 intro_date= decode_uint32(p);
besch->intro_date = (intro_date/16)*12 + (intro_date%16);
besch->wtyp = decode_uint8(p);
besch->styp = decode_uint8(p);
besch->obsolete_date = DEFAULT_RETIRE_DATE*12;
besch->draw_as_ding = false;
}
else {
dbg->fatal("way_reader_t::read_node()","Invalid version %d", version);
}
}

// some internal corrections to pay for orevious confusion with two waytypes
if(besch->wtyp==weg_t::schiene_strab) {
besch->styp = 7;
besch->wtyp = weg_t::schiene;
}
else if(besch->styp==5 && besch->wtyp==weg_t::schiene) {
besch->wtyp = weg_t::monorail;
besch->styp = 0;
}
if(version<=2 && besch->wtyp==weg_t::luft && besch->topspeed>=250) {
// runway!
besch->styp = 1;
}

DBG_DEBUG("way_reader_t::read_node()",
"version=%d price=%d maintenance=%d topspeed=%d max_weight=%d "
Expand Down
7 changes: 6 additions & 1 deletion besch/roadsign_besch.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class roadsign_besch_t : public obj_besch_t {
friend class roadsign_writer_t;
friend class roadsign_reader_t;

enum types {ONE_WAY=1, FREE_ROUTE=2 };
enum types {ONE_WAY=1, FREE_ROUTE=2, PRIVATE_ROAD=4 };

uint8 flags;
uint16 min_speed; // 0: unused
Expand Down Expand Up @@ -75,6 +75,11 @@ class roadsign_besch_t : public obj_besch_t {
return (flags&ONE_WAY)!=0;
}

bool is_private_way() const
{
return (flags&PRIVATE_ROAD)!=0;
}

int gib_min_speed() const
{
return min_speed;
Expand Down
53 changes: 31 additions & 22 deletions besch/weg_besch.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class weg_besch_t : public obj_besch_t {
*/
uint8 styp;

/* true, if a tile with this way should be always drawn as a thing
*/
uint8 draw_as_ding;

public:

int gib_preis() const
Expand Down Expand Up @@ -195,32 +199,37 @@ class weg_besch_t : public obj_besch_t {
}


/**
* @return introduction year
* @author Hj. Malthaner
*/
int get_intro_year_month() const {
return intro_date;
}
/**
* @return introduction year
* @author Hj. Malthaner
*/
int get_intro_year_month() const {
return intro_date;
}

/**
* @return introduction month
* @author Hj. Malthaner
*/
int get_retire_year_month() const {
return obsolete_date;
}

/**
* @return introduction month
* @author Hj. Malthaner
*/
int get_retire_year_month() const {
return obsolete_date;
}
/* true, if this tile is to be drawn as lie a normal thing */
bool is_draw_as_ding() const
{
return draw_as_ding;
}

/**
* Skin: cursor (index 0) and icon (index 1)
* @author Hj. Malthaner
*/
const skin_besch_t * gib_cursor() const
{
return (const skin_besch_t *)(gib_kind(5));
}

/**
* Skin: cursor (index 0) and icon (index 1)
* @author Hj. Malthaner
*/
const skin_besch_t * gib_cursor() const
{
return (const skin_besch_t *)(gib_kind(5));
}
};

#endif // __WEG_BESCH_H
2 changes: 1 addition & 1 deletion besch/writer/roadsign_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void roadsign_writer_t::write_obj(FILE *fp, obj_node_t &parent, tabfileobj_t &ob
roadsign_besch_t besch;
besch.cost = obj.get_int("cost", 500)*100;
besch.min_speed = obj.get_int("min_speed", 0);
besch.flags = (obj.get_int("single_way", 0)>0) + (obj.get_int("free_route", 0)>0)*2;
besch.flags = (obj.get_int("single_way", 0)>0) + (obj.get_int("free_route", 0)>0)*2 + (obj.get_int("is_private", 0)>0)*4;

// Hajo: temp vars of appropriate size
uint32 v32;
Expand Down
Loading

0 comments on commit 0d7defc

Please sign in to comment.