1
0
Fork 0

(svn r24406) -Feature: Allow game scripts to monitor cargo pickups and deliveries done by companies.

release/1.3
alberth 2012-07-15 17:11:14 +00:00
parent 05aaf18d38
commit eb56e5c0b1
7 changed files with 193 additions and 0 deletions

View File

@ -733,6 +733,7 @@ script/api/script_bridge.hpp
script/api/script_bridgelist.hpp
script/api/script_cargo.hpp
script/api/script_cargolist.hpp
script/api/script_cargomonitor.hpp
script/api/script_company.hpp
script/api/script_companymode.hpp
script/api/script_controller.hpp
@ -796,6 +797,7 @@ script/api/script_bridge.cpp
script/api/script_bridgelist.cpp
script/api/script_cargo.cpp
script/api/script_cargolist.cpp
script/api/script_cargomonitor.cpp
script/api/script_company.cpp
script/api/script_companymode.cpp
script/api/script_controller.cpp

View File

@ -33,6 +33,7 @@
#include "../script/api/game/game_bridgelist.hpp.sq"
#include "../script/api/game/game_cargo.hpp.sq"
#include "../script/api/game/game_cargolist.hpp.sq"
#include "../script/api/game/game_cargomonitor.hpp.sq"
#include "../script/api/game/game_company.hpp.sq"
#include "../script/api/game/game_companymode.hpp.sq"
#include "../script/api/game/game_controller.hpp.sq"
@ -113,6 +114,7 @@ void GameInstance::RegisterAPI()
SQGSCargoList_IndustryAccepting_Register(this->engine);
SQGSCargoList_IndustryProducing_Register(this->engine);
SQGSCargoList_StationAccepting_Register(this->engine);
SQGSCargoMonitor_Register(this->engine);
SQGSCompany_Register(this->engine);
SQGSCompanyMode_Register(this->engine);
SQGSDate_Register(this->engine);

View File

@ -0,0 +1,31 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
#include "../script_cargomonitor.hpp"
#include "../template/template_cargomonitor.hpp.sq"
template <> const char *GetClassName<ScriptCargoMonitor, ST_GS>() { return "GSCargoMonitor"; }
void SQGSCargoMonitor_Register(Squirrel *engine)
{
DefSQClass<ScriptCargoMonitor, ST_GS> SQGSCargoMonitor("GSCargoMonitor");
SQGSCargoMonitor.PreRegister(engine);
SQGSCargoMonitor.AddConstructor<void (ScriptCargoMonitor::*)(), 1>(engine, "x");
SQGSCargoMonitor.DefSQStaticMethod(engine, &ScriptCargoMonitor::GetTownDeliveryAmount, "GetTownDeliveryAmount", 5, ".iiib");
SQGSCargoMonitor.DefSQStaticMethod(engine, &ScriptCargoMonitor::GetIndustryDeliveryAmount, "GetIndustryDeliveryAmount", 5, ".iiib");
SQGSCargoMonitor.DefSQStaticMethod(engine, &ScriptCargoMonitor::GetTownPickupAmount, "GetTownPickupAmount", 5, ".iiib");
SQGSCargoMonitor.DefSQStaticMethod(engine, &ScriptCargoMonitor::GetIndustryPickupAmount, "GetIndustryPickupAmount", 5, ".iiib");
SQGSCargoMonitor.DefSQStaticMethod(engine, &ScriptCargoMonitor::StopAllMonitoring, "StopAllMonitoring", 1, ".");
SQGSCargoMonitor.PostRegister(engine);
}

View File

@ -20,6 +20,7 @@
* 1.3.0 is not yet released. The following changes are not set in stone yet.
*
* API additions:
* \li GSCargoMonitor
* \li GSEventExclusiveTransportRights
* \li GSEventRoadReconstruction
* \li GSNews::NT_ACCIDENT, GSNews::NT_COMPANY_INFO, GSNews::NT_ADVICE, GSNews::NT_ACCEPTANCE

View File

@ -0,0 +1,44 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_cargomonitor.cpp Code to monitor cargo pickup and deliveries by companies. */
#include "../../stdafx.h"
#include "script_cargomonitor.hpp"
/* static */ uint32 ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
{
CargoMonitorID monitor = EncodeCargoTownMonitor(static_cast<CompanyID>(company), cargo, town_id);
return GetDeliveryAmount(monitor, keep_monitoring);
}
/* static */ uint32 ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring)
{
CargoMonitorID monitor = EncodeCargoIndustryMonitor(static_cast<CompanyID>(company), cargo, industry_id);
return GetDeliveryAmount(monitor, keep_monitoring);
}
/* static */ uint32 ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring)
{
CargoMonitorID monitor = EncodeCargoTownMonitor(static_cast<CompanyID>(company), cargo, town_id);
return GetPickupAmount(monitor, keep_monitoring);
}
/* static */ uint32 ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring)
{
CargoMonitorID monitor = EncodeCargoIndustryMonitor(static_cast<CompanyID>(company), cargo, industry_id);
return GetPickupAmount(monitor, keep_monitoring);
}
/* static */ void ScriptCargoMonitor::StopAllMonitoring()
{
ClearCargoPickupMonitoring();
ClearCargoDeliveryMonitoring();
}

View File

@ -0,0 +1,92 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_cargomonitor.hpp Everything to monitor cargo pickup and deliveries by companies. */
#ifndef SCRIPT_CARGO_MONITOR_HPP
#define SCRIPT_CARGO_MONITOR_HPP
#include "script_list.hpp"
#include "script_object.hpp"
#include "script_company.hpp"
#include "../../cargomonitor.h"
/**
* Class that handles all cargo movement monitoring related functions.
*
* To get an understanding of what users are transporting, this class provides cargo pick-up and delivery monitoring functions.
* It works as follows:
* - Select a company, a cargo-type, and an industry that gets the cargo triplet.
* - Perform a call to #GetIndustryDeliveryAmount, setting 'keep_monitoring' to \c true.
* The return value is not important, but from this moment the program accumulates all deliveries by
* the given company to the given industry of the given cargo type.
* - Some time later, perform another call to #GetIndustryDeliveryAmount. It returns the accumulated
* amount of cargo that the company has delivered.
* The call causes the collected amount to be reset. On the next call you will thus always get the
* delivered amount since the previous call.
* - When monitoring the deliveries is not interesting any more, set 'keep_monitoring' to \c false.
* The collecting process that happens between calls is stopped.
*
* In the same way you can monitor town deliveries, and you can monitor pick-up from towns and industries.
* The latter get added at the moment the cargo is delivered. This prevents users from getting credit for
* picking up cargo without delivering it.
*
* The active monitors are saved and loaded. You can reset to the empty state with #StopAllMonitoring.
*
* @api game
*/
class ScriptCargoMonitor : public ScriptObject {
public:
/**
* Get the amount of cargo delivered to a town by a company since the last query, and update the monitoring state.
* @param company %Company to query.
* @param cargo Cargo type to query.
* @param town_id %Town to query.
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
* @return Amount of delivered cargo of the given cargo type to the given town by the given company since the last call.
*/
static uint32 GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring);
/**
* Get the amount of cargo delivered to an industry by a company since the last query, and update the monitoring state.
* @param company %Company to query.
* @param cargo Cargo type to query.
* @param industry_id %Industry to query.
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
* @return Amount of delivered cargo of the given cargo type to the given industry by the given company since the last call.
*/
static uint32 GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring);
/**
* Get the amount of cargo picked up (and delivered) from a town by a company since the last query, and update the monitoring state.
* @param company %Company to query.
* @param cargo Cargo type to query.
* @param town_id %Town to query.
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
* @return Amount of picked up cargo of the given cargo type to the given town by the given company since the last call.
* @note Amounts of picked-up cargo are added during final delivery of it, to prevent users from getting credit for picking up without delivering it.
*/
static uint32 GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring);
/**
* Get the amount of cargo picked up (and delivered) from an industry by a company since the last query, and update the monitoring state.
* @param company %Company to query.
* @param cargo Cargo type to query.
* @param industry_id %Industry to query.
* @param keep_monitoring If \c true, the given combination continues to be monitored for the next call. If \c false, monitoring ends.
* @return Amount of picked up cargo of the given cargo type to the given industry by the given company since the last call.
* @note Amounts of picked-up cargo are added during final delivery of it, to prevent users from getting credit for picking up without delivering it.
*/
static uint32 GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring);
/** Stop monitoring everything. */
static void StopAllMonitoring();
};
#endif /* SCRIPT_CARGO_MONITOR_HPP */

View File

@ -0,0 +1,21 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */
#include "../script_cargomonitor.hpp"
namespace SQConvert {
/* Allow ScriptCargoMonitor to be used as Squirrel parameter */
template <> inline ScriptCargoMonitor *GetParam(ForceType<ScriptCargoMonitor *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptCargoMonitor *)instance; }
template <> inline ScriptCargoMonitor &GetParam(ForceType<ScriptCargoMonitor &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptCargoMonitor *)instance; }
template <> inline const ScriptCargoMonitor *GetParam(ForceType<const ScriptCargoMonitor *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptCargoMonitor *)instance; }
template <> inline const ScriptCargoMonitor &GetParam(ForceType<const ScriptCargoMonitor &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptCargoMonitor *)instance; }
template <> inline int Return<ScriptCargoMonitor *>(HSQUIRRELVM vm, ScriptCargoMonitor *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "CargoMonitor", res, NULL, DefSQDestructorCallback<ScriptCargoMonitor>, true); return 1; }
} // namespace SQConvert