[Patch] Lord Aro's Patches. Current: DLC Textfiles

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

User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

[Patch] Lord Aro's Patches. Current: DLC Textfiles

Post by Lord Aro »

[second half of conversation]
Zuu [url=http://www.tt-forums.net/viewtopic.php?f=33&t=51363]here[/url] wrote:
Yexo wrote:But it already is available to players. When you click on a town the caption of the town details window is "name" for towns and "name (City)" for cities.
Sorry, didn't knew it was already available.
ok, here goes:

I'm having trouble understanding OpenTTD's datatypes so, would this work? :

Code: Select all

/* static */ bool AITown::IsCity(TownID town_id)
{
	if (!IsValidTown(town_id)) return false;

	if (town_id->larger_town) return true;
	else return false;
}
i'm suspecting not... :lol:
Last edited by Lord Aro on 02 Jul 2012 11:45, edited 2 times in total.
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: [Patch] AI function: IsCity

Post by MagicBuzz »

It's exactly what I did with my "ratings in town list" patch, and it looks to work.
So I guess it will work for you too ;)
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] AI function: IsCity

Post by Lord Aro »

cool!

i personally think there should be a "main" function for this somewhere... (in town_cmd.cpp for example)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: [Patch] AI function: IsCity

Post by Eddi »

Lord Aro wrote: ok, here goes:

Code: Select all

	if (town_id->larger_town) return true;
	else return false;
i haven't checked the correctness of this, but assuming it is, you can shorten this to:

Code: Select all

	return (bool)town_id->larger_town;
also, "else" after a "return" is usually redundant:

Code: Select all

	if (a) return b;
	return c;
has the same execution paths.

other than that, the openttd code style requires that if you have an "else" section, you must use {} to enclose the statements, even if it's only a single one.

that is your friendly programming lesson for today, thanks for your attention.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: [Patch] AI function: IsCity

Post by MagicBuzz »

I didn't know that for tha else with {}

I'll have to make some clean up in my patches :D
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: [Patch] AI function: IsCity

Post by Michi_cc »

Eddi wrote:i haven't checked the correctness of this, but assuming it is, you can shorten this to:

Code: Select all

	return (bool)town_id->larger_town;
The (bool) is superfluous as larger_town already is a bool thus no cast is needed.

-- Michael Lutz
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] AI function: IsCity

Post by Lord Aro »

ok,
compilation failed fairly spectacularly with this:

Code: Select all

D:/MinGW/msys/1.0/home/****/ottdsrc/trunk/src/ai/api/ai_town.cpp: In static member function 'static bool AITown::IsCity(TownID)':
D:/MinGW/msys/1.0/home/****/ottdsrc/trunk/src/ai/api/ai_town.cpp:136:16: error: base operand of '->' is not a pointer
D:/MinGW/msys/1.0/home/****/ottdsrc/trunk/src/ai/api/ai_town.cpp:137:1: warning: control reaches end of non-void function
make[1]: *** [ai/api/ai_town.o] Error 1
make[1]: Leaving directory `/home/Margo/ottdsrc/trunk/objs/release'
make: *** [all] Error 1
here be patch...
Attachments
aitown.iscity_r21362.diff
(2.17 KiB) Downloaded 105 times
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [Patch] AI function: IsCity

Post by Zuu »

The TownID datatype implies that town_id is just a number and not a class instance. Furthermore if TownID was a class type, you would either declare town_id as a pointer using a * or use a dot "." instead of "->" before "larger_town".

In this case you need to lookup which class or struct larger_town is member of and how to get hold of that data structure using a town id.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] AI function: IsCity

Post by Lord Aro »

um help? :lol:

this is a bit beyond me
i'll give it a go though...
(don't mind if someone else gets there first!)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: [Patch] AI function: IsCity

Post by Eddi »

it'd probably be something along the lines of

Code: Select all

Town.Get(town_id)->larger_town
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: [Patch] AI function: IsCity

Post by Zuu »

I would start looking at the place where you found out that the 'larger_town' property exists. If you don't remember, run a grep through the entire source code.

Edit: I see you run msys, in that case you probably have the grep command installed there.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] AI function: IsCity

Post by Lord Aro »

Zuu: I also have Notepad++, with Explorer plugin :wink:

Thanks to Eddi, and looking at the other functions, i believe i have a working patch :D

Now, who knows how to edit regression?...
Attachments
aitown.iscity_r21365.diff
(2.2 KiB) Downloaded 103 times
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Kogut »

Attached here
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Lord Aro »

No one knows how to modify regression?
However, i have noticed that it 'dies unexpectantly' Is this proper?

Kogut: Thanks for that. I don't agree with your function though, what's wrong with mine?
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Kogut »

Lord Aro wrote:Kogut: Thanks for that. I don't agree with your function though, what's wrong with mine?
IMHO nothing. My function? What, where, why, wtf?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Lord Aro »

The function name on the API request thread, that you seem to have made up

Still waiting for regression instructions ;)
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Kogut »

Lord Aro wrote:The function name on the API request thread, that you seem to have made up

Still waiting for regression instructions ;)
It was not my idea and name is changed.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Lord Aro »

update:
Attachments
aitown.iscity_r21646.diff
(2.18 KiB) Downloaded 110 times
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Lord Aro »

final update, now with regression modifications :D :
Attachments
aitown.iscity_r21653.diff
(8.66 KiB) Downloaded 121 times
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
User avatar
Lord Aro
Tycoon
Tycoon
Posts: 2369
Joined: 25 Jun 2009 16:42
Location: Location, Location
Contact:

Re: [Patch] Lord Aro's Patches. Current: AITown.IsCity

Post by Lord Aro »

Grave dig!

Hello,

I'm currently attempting to give OTTD the ability to view textfiles in the download content window, but have run into some problems (why else would i be posting about it? :P )
view_content_textfile.diff
hg/git patch, r24358
(7.85 KiB) Downloaded 106 times
I'm having trouble finding the filename of the Content, as this->filename (as seen in patch) seems to be valid only when the file download is in progress

ANyone got any ideas?
AroAI - A really feeble attempt at an AI

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration. --Edsger Dijkstra
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 39 guests