Patch: Conversion from normal to electrified rail

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Patch: Conversion from normal to electrified rail

Post 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 ;)
Attachments
convert_to_electric.diff
for r4766
(716 Bytes) Downloaded 259 times
Moriarty
Tycoon
Tycoon
Posts: 1395
Joined: 12 Jun 2004 00:37
Location: United Kingdom of Great Britain and Northern Ireland
Contact:

Post 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.
Haukinger
Engineer
Engineer
Posts: 110
Joined: 15 Mar 2006 16:38

Post 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.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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 :wink:
Sacro
Tycoon
Tycoon
Posts: 1145
Joined: 18 Jun 2005 21:08
Location: Here
Contact:

Post by Sacro »

Bjarni (or any other dev): Any chance this patch can be added? It'd be brilliantly useful :)
We Am De Best

Host of ThroughTheTube site
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1796
Joined: 30 Mar 2005 09:43

Post by peter1138 »

I already accidentally committed it once ;-P

I reverted it because the patch is... overcomplex.
He's like, some kind of OpenTTD developer.
Costas
Engineer
Engineer
Posts: 105
Joined: 31 Mar 2006 17:03

Post 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!
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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 :P

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
Costas
Engineer
Engineer
Posts: 105
Joined: 31 Mar 2006 17:03

Post 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 :P
cool flame war!!! :twisted:

not really :D

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! :oops: :P

but small is simple sometimes :P
User avatar
BoominGranny
Engineer
Engineer
Posts: 85
Joined: 18 Apr 2006 02:16
Location: Wellington, New Zealand
Contact:

Post 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?
peter1138
OpenTTD Developer
OpenTTD Developer
Posts: 1796
Joined: 30 Mar 2005 09:43

Post 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;
He's like, some kind of OpenTTD developer.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
BoominGranny
Engineer
Engineer
Posts: 85
Joined: 18 Apr 2006 02:16
Location: Wellington, New Zealand
Contact:

Post 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.
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
dev|ant
Traffic Manager
Traffic Manager
Posts: 140
Joined: 30 Nov 2005 11:26
Location: melbourne.au

Post 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.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5631
Joined: 13 Sep 2004 13:21
Location: The Moon

Post 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. :roll:
DaleStan
TTDPatch Developer
TTDPatch Developer
Posts: 10285
Joined: 18 Feb 2004 03:06
Contact:

Post 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.
To get a good answer, ask a Smart Question. Similarly, if you want a bug fixed, write a Useful Bug Report. No TTDPatch crashlog? Then follow directions.
Projects: NFORenum (download) | PlaneSet (Website) | grfcodec (download) | grfdebug.log parser
User avatar
Born Acorn
Tycoon
Tycoon
Posts: 7597
Joined: 10 Dec 2002 20:36
Skype: bornacorn
Location: Wrexham, Wales
Contact:

Post 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.
Image
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 3 guests