Page 1 of 1
Patch: Conversion from normal to electrified rail
Posted: 07 May 2006 08:11
by Haukinger
Hi all !
I've made a tiny patch to allow conversion of normal tracks to electrified with trains present.
It works for me, but perhaps I'm missing something... it's just too simple

Posted: 07 May 2006 11:45
by Moriarty
Excellent Idea. From a game-play perspective, there's no reason not to upgrade the track from regular to electric if there's a train on it.
All that does is make the player's life harder for no good reason.
Assuming this patch works it should be added to the nightlies immediatly.
Posted: 07 May 2006 12:04
by Haukinger
Look at the game on Brianettas server, I have trains running one after another with 2..3 tiles between over nearly all the map. Now imagine the fun it was to convert that to electrified

Inspired me to look at the code and see if anything can be done...
The patch works for me, at least in single player. I couldn't test it in MP by now.
Posted: 07 May 2006 14:10
by Bjarni
well, in real life you stop the trains while you add the catenary, but we play to have a fun time, so I guess it's a nice patch.
This reminds me of the time when I joined a server and took over a large company that didn't have an owner (he left). It had nothing but trains and all the engines were outdated, so I spent half an hour replacing them with new ones. The next day, I started work on autoreplace

Posted: 07 May 2006 14:30
by Sacro
Bjarni (or any other dev): Any chance this patch can be added? It'd be brilliantly useful

Posted: 07 May 2006 21:25
by peter1138
I already accidentally committed it once ;-P
I reverted it because the patch is... overcomplex.
Posted: 07 May 2006 21:57
by Costas
was urs overcomplex? will this patch be easier to implement? it looks very small and i would say simple but cant understand much out of it!
Posted: 07 May 2006 23:43
by Bjarni
Costas wrote:it looks very small and i would say simple but cant understand much out of it!
I wonder why people don't read what they write. Costas claims that it's simple, yet he don't understand it. It makes you wonder about his coding skills
the patch IS simple. Instead of checking if there is a train on the tile, it checks if there is a vehicle and if there is one, it check if it's normal rail and if the train can drive on the new type.
Now the question is if it can cause any bugs
Posted: 08 May 2006 00:31
by Costas
Bjarni wrote:Costas wrote:it looks very small and i would say simple but cant understand much out of it!
I wonder why people don't read what they write. Costas claims that it's simple, yet he don't understand it. It makes you wonder about his coding skills
cool flame war!!!
not really
despite living in UK for 11y i still make gramatical mistakes, what i should have written: "i would have said its simple"
and yes just cause i am posting here it doesnt mean i have any coding skills whatsoever!
but small is simple sometimes

Posted: 08 May 2006 04:05
by BoominGranny
A designer knows he has reached perfection not when there is nothing left to add, but when there is nothing left to take away
if you can code it in 3 lines instead of 10 lines then it is usually more efficient and therefore better - i presume that is the logic you are suggesting here?
Posted: 08 May 2006 06:26
by peter1138
It's overcomplex compared to the correct change:
Code: Select all
- if (!EnsureNoVehicle(tile) && (!IsCompatibleRail(GetRailType(tile), totype) || IsPlainRailTile(tile))) return CMD_ERROR;
+ if (!EnsureNoVehicle(tile) && !IsCompatibleRail(GetRailType(tile), totype)) return CMD_ERROR;
Posted: 08 May 2006 06:36
by DaleStan
BoominGranny wrote:if you can code it in 3 lines instead of 10 lines then it is usually more efficient and therefore better
YesIthinkthatiswonderfullogic,don'tyou?
Take, for example:
if(...||sprite[firstnotpseudo]=='"'?(SetVersion(5),true):false||...)
if(...||(offs=meta.find('('))==NPOS||(var_list[var]=DoCalc(meta,offs),offs==NPOS))
i+=extract_len(data,++i);
int extract=1<<((nument1>>2)&3);
off+=2+(shift&0xC0?3:1)*extract;
All of that is or was live code, with the exception of "..." used to eliminate code that isn't anywhere near as interesting.
Posted: 08 May 2006 07:41
by BoominGranny
you didn't quite understand what i meant...
what i meant was why code it using 1000 characters when you can code it in 300 - which is exactly what peter1138 is doing.
and i don't mean by reducing the spaces either. and yes i understand readability is important, and so are comments.
Posted: 08 May 2006 16:36
by DaleStan
My point is that those lines are horrendously difficult to follow, even with comments and appropriate whitespace. Each is only one line, but collectively, they should probably be at least 20 statements.
Especially the two if conditions.
Posted: 11 May 2006 22:14
by dev|ant
DaleStan wrote:...
/sigh... I've been away for a month, only to come back to this.
Sad to see some things never change. DaleStan you should probably know that your continued trolling of the OTTD forums is the number one reason I will never use TTDP.
Posted: 11 May 2006 22:25
by PikkaBird
dev|ant wrote:DaleStan you should probably know that your continued trolling of the OTTD forums is the number one reason I will never use TTDP.
Which is
perfectly logical...
In any case, DaleStan's posting style is no different in the TTDP section than it is in here.

Posted: 11 May 2006 23:14
by DaleStan
dev|ant wrote:DaleStan wrote:...
/sigh... I've been away for a month, only to come back to this.
That's *MY* code, and it lives (or lived) in NFORenum.
As anyone with a working copy of grep would know, that code lives nowhere in the OTTD source tree. (And then there's the fact that, although all of them are valid C, at least one of them can not possibly be meaningful C.)
My point is that code written for the sole purpose of being short is not necessarily readable, nor necessarily the correct way to do things, and I took the best example I had to hand. Specifically, the code for NFORenum. I could just have well linked to
The Story of Mel, but I thought specific C/C++ examples would hammer the point home far better than abstract discussion about the RPC-4000's machine language.
Code written to be short and concise, OTOH is usually good code.
Posted: 17 May 2006 12:26
by Born Acorn
dev|ant wrote:DaleStan you should probably know that your continued trolling of the OTTD forums is the number one reason I will never use TTDP.
That makes a whole bunch of sense. Dalestan isn't trolling, his posts make sense.