mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-02-11 00:34:27 +00:00
Add: AI functions to get current and last year profit of a group.
This commit is contained in:
parent
b62452903a
commit
3c047b124e
@ -42,6 +42,8 @@ void SQAIGroup_Register(Squirrel *engine)
|
|||||||
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::SetAutoReplace, "SetAutoReplace", 4, ".iii");
|
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::SetAutoReplace, "SetAutoReplace", 4, ".iii");
|
||||||
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetEngineReplacement, "GetEngineReplacement", 3, ".ii");
|
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetEngineReplacement, "GetEngineReplacement", 3, ".ii");
|
||||||
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::StopAutoReplace, "StopAutoReplace", 3, ".ii");
|
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::StopAutoReplace, "StopAutoReplace", 3, ".ii");
|
||||||
|
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetProfitThisYear, "GetProfitThisYear", 2, ".i");
|
||||||
|
SQAIGroup.DefSQStaticMethod(engine, &ScriptGroup::GetProfitLastYear, "GetProfitLastYear", 2, ".i");
|
||||||
|
|
||||||
SQAIGroup.PostRegister(engine);
|
SQAIGroup.PostRegister(engine);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "../../strings_func.h"
|
#include "../../strings_func.h"
|
||||||
#include "../../autoreplace_func.h"
|
#include "../../autoreplace_func.h"
|
||||||
#include "../../settings_func.h"
|
#include "../../settings_func.h"
|
||||||
|
#include "../../vehicle_base.h"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
#include "../../safeguards.h"
|
#include "../../safeguards.h"
|
||||||
@ -148,3 +149,27 @@
|
|||||||
|
|
||||||
return ScriptObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE);
|
return ScriptObject::DoCommand(0, group_id << 16, (::INVALID_ENGINE << 16) | engine_id, CMD_SET_AUTOREPLACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ Money ScriptGroup::GetProfitThisYear(GroupID group_id)
|
||||||
|
{
|
||||||
|
if (!IsValidGroup(group_id)) return -1;
|
||||||
|
|
||||||
|
Money profit = 0;
|
||||||
|
|
||||||
|
const Vehicle *v;
|
||||||
|
FOR_ALL_VEHICLES(v) {
|
||||||
|
if (v->group_id != group_id) continue;
|
||||||
|
if (!v->IsPrimaryVehicle()) continue;
|
||||||
|
|
||||||
|
profit += v->GetDisplayProfitThisYear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return profit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ Money ScriptGroup::GetProfitLastYear(GroupID group_id)
|
||||||
|
{
|
||||||
|
if (!IsValidGroup(group_id)) return -1;
|
||||||
|
|
||||||
|
return ::Group::Get(group_id)->statistics.profit_last_year;
|
||||||
|
}
|
||||||
|
@ -189,6 +189,22 @@ public:
|
|||||||
* @return True if and if the replacing was successfully stopped.
|
* @return True if and if the replacing was successfully stopped.
|
||||||
*/
|
*/
|
||||||
static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
|
static bool StopAutoReplace(GroupID group_id, EngineID engine_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current profit of a group.
|
||||||
|
* @param group_id The group to get the profit of.
|
||||||
|
* @pre IsValidGroup(group_id).
|
||||||
|
* @return The current profit the group has.
|
||||||
|
*/
|
||||||
|
static Money GetProfitThisYear(GroupID group_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the profit of last year of a group.
|
||||||
|
* @param group_id The group to get the profit of.
|
||||||
|
* @pre IsValidGroup(group_id).
|
||||||
|
* @return The current profit the group had last year.
|
||||||
|
*/
|
||||||
|
static Money GetProfitLastYear(GroupID group_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SCRIPT_GROUP_HPP */
|
#endif /* SCRIPT_GROUP_HPP */
|
||||||
|
Loading…
Reference in New Issue
Block a user