Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Wed Dec 12, 2018 1:23 pm

All times are UTC




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [GS] FGCargoMonitor
PostPosted: Sat Nov 02, 2013 6:27 pm 
Offline
Engineer
Engineer

Joined: Mon Jun 21, 2010 11:54 am
Posts: 58
I created a library to help monitoring the cargo changes: FGCargoMonitor
Minimum system: OpenTTD 1.3.0


Version 2 changes:
- minor bug fixes

Vesrion 3 changes:
- minor bug fixes
- the log automatically display the game date now
- with DisableGameDateFromLog() you can set to back the original log format.

Vesrion 4 changes:
- I fixed a bug: after bankrupt a company, an other company is removed from monitoring.


Links, dokcumetntations:
Full documentation: http://feca.homedns.org/documentations/ ... index.html
Full example: http://feca.homedns.org/documentations/ ... ample.html
Available on bananas: http://www.openttd.org/en/bananas/gslibrary/


Details:
With this library you can easily create own Cargo Goal type game in 5 steps:
- Create instance:
Code:
this.cargoMonitor = FGCargoMonitor(this, FGCargoMonitor.LOGLEVEL_ALL);

- Update every day:
Code:
this.cargoMonitor.Update();

- Subscribe to monitoring:
Code:
this.cargoMonitor.SubscribeToMonitor(company_id, cargo_id, goal_id, FGCargoMonitor.REFRESH_IMMEDIATELY, FGCargoMonitor.MONITOR_ALL_PICKUP, null);

- Create a delegate method to tracking changes:
Code:
function FGCargoMonitorTest::SendCargoUpdate(company_id, goal_id, transported)

- And unsubscribe if you don’t need anymore this update:
Code:
this.cargoMonitor.UnSubscribeFromMonitor(company_id, goal_id);



You can subscribe to specific transport goals, example:
- How much coal transported from this city?
- How much steel transported from this industry?
- How much passenger picked up (and delivered) from all city?, etc…

Of course you can subscribe more than one monitor type to specific cargo, example:
- How much coal transported from this coal mine and how much coal transported from all coal mine?

You can subscribe to immediately updates or you can choice the monthly, yearly, etc… updates (REFRESH_TYPES)

Many functions are available to query a specific company and cargo, or given goal of company. But you must subscribe before qurey these monitor types. Example funcitons:
Code:
FGCargoMonitor::AmountOfAllPickedupCargo(company_id, cargo_id)

Code:
FGCargoMonitor::AmountOfAllGoal(company_id, goal_id)
, etc…

The save and load are easily:
Code:
function FGCargoMonitorTeszt::Save() {
   return {
      cargoMonitor = this.cargoMonitor.SaveData(),
   }
}
function FGCargoMonitorTeszt::Load(version, table) {
   this.cargoMonitor.LoadFromData(table.cargoMonitor);
}



You can unsubscribe the speceific company with specefic goal:
- FGCargoMonitor::UnSubscribeFromMonitor(company_id, goal_id)
Also you can unsubscribe all monitor of specific company (if the company went bankrupt or merged):
- FGCargoMonitor::UnSubscribeCompanyFromMonitor(company_id)
Or you can stop all monitoring at the end of the game:
- FGCargoMonitor::UnSubscribeAllFromMonitor()


I tested all function, but errors may occur…
Have fun! :D


Attachments:
File comment: Example how can use
Example.zip [2.52 KiB]
Downloaded 139 times

_________________
Sorry my bad english, I don't speak english!


Last edited by idioty on Sat Jan 11, 2014 3:49 pm, edited 4 times in total.
Top
   
 Post subject: Re: [GS] FGCargoMonitor
PostPosted: Thu Nov 07, 2013 12:32 pm 
Offline
Transport Coordinator
Transport Coordinator

Joined: Wed Apr 14, 2004 3:18 pm
Posts: 312
Location: Fr
Hello,
Subscribing without any Goal isn't possible ?
for example to compute town growing based upon given cargo ? (gamescript)
Regards.


Top
   
 Post subject: Re: [GS] FGCargoMonitor
PostPosted: Sat Dec 14, 2013 8:54 pm 
Offline
Engineer
Engineer

Joined: Mon Jun 21, 2010 11:54 am
Posts: 58
fabca2 wrote:
Hello,
Subscribing without any Goal isn't possible ?
for example to compute town growing based upon given cargo ? (gamescript)
Regards.


Sorry, I I did'nt notice your comment.
Yes, you can subscribe without valid GSGoal, but this function required unique own goal ID per company.
Example:
SubscribeToMonitor(company_id_1, cargo_id_1, "goal_id_1", FGCargoMonitor.REFRESH_IMMEDIATELY, FGCargoMonitor.MONITOR_TOWN_DELIVERY, town_id_1);
SubscribeToMonitor(company_id_1, cargo_id_2, "goal_id_2", FGCargoMonitor.REFRESH_IMMEDIATELY, FGCargoMonitor.MONITOR_TOWN_DELIVERY, town_id_1);
SubscribeToMonitor(company_id_2, cargo_id_1, "goal_id_1", FGCargoMonitor.REFRESH_IMMEDIATELY, FGCargoMonitor.MONITOR_TOWN_DELIVERY, town_id_2);
SubscribeToMonitor(company_id_2, cargo_id_2, "goal_id_2", FGCargoMonitor.REFRESH_IMMEDIATELY, FGCargoMonitor.MONITOR_TOWN_DELIVERY, town_id_2);

As you can see, the goal_id can be string (or integer).
And with this goal_id can be identify which goal (town) updated: SendCargoUpdate(company_id, goal_id, transported)

_________________
Sorry my bad english, I don't speak english!


Top
   
 Post subject: Re: [GS] FGCargoMonitor
PostPosted: Sun Dec 15, 2013 12:03 pm 
Offline
Engineer
Engineer

Joined: Mon Jun 21, 2010 11:54 am
Posts: 58
I created a new version (3) of this script, the details readable in first post.

_________________
Sorry my bad english, I don't speak english!


Top
   
 Post subject: Re: [GS] FGCargoMonitor
PostPosted: Sat Jan 11, 2014 3:50 pm 
Offline
Engineer
Engineer

Joined: Mon Jun 21, 2010 11:54 am
Posts: 58
I created a new version (4) of this script, the details readable in first post.

_________________
Sorry my bad english, I don't speak english!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2018 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2018.
Hosted by Zernebok Hosting.