mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r17016) -Add [NoAI]: AICompany::Get/Set PresidentGender
This commit is contained in:
parent
ae71df349e
commit
fc03fef4ae
|
@ -8,6 +8,7 @@
|
|||
#include "../../command_func.h"
|
||||
#include "../../company_func.h"
|
||||
#include "../../company_base.h"
|
||||
#include "../../company_manager_face.h"
|
||||
#include "../../economy_func.h"
|
||||
#include "../../strings_func.h"
|
||||
#include "../../tile_map.h"
|
||||
|
@ -72,6 +73,27 @@
|
|||
return president_name;
|
||||
}
|
||||
|
||||
/* static */ bool AICompany::SetPresidentGender(Gender gender)
|
||||
{
|
||||
EnforcePrecondition(false, gender == GENDER_MALE || gender == GENDER_FEMALE);
|
||||
EnforcePrecondition(false, GetPresidentGender(AICompany::COMPANY_SELF) != gender);
|
||||
|
||||
CompanyManagerFace cmf;
|
||||
GenderEthnicity ge = (GenderEthnicity)((gender == GENDER_FEMALE ? (1 << ::GENDER_FEMALE) : 0) | (::InteractiveRandom() & (1 << ETHNICITY_BLACK)));
|
||||
RandomCompanyManagerFaceBits(cmf, ge, false);
|
||||
|
||||
return AIObject::DoCommand(0, 0, cmf, CMD_SET_COMPANY_MANAGER_FACE);
|
||||
}
|
||||
|
||||
/* static */ AICompany::Gender AICompany::GetPresidentGender(CompanyID company)
|
||||
{
|
||||
company = ResolveCompanyID(company);
|
||||
if (company == COMPANY_INVALID) return GENDER_INVALID;
|
||||
|
||||
GenderEthnicity ge = (GenderEthnicity)GetCompanyManagerFaceBits(Company::Get(company)->face, CMFV_GEN_ETHN, GE_WM);
|
||||
return HasBit(ge, ::GENDER_FEMALE) ? GENDER_FEMALE : GENDER_MALE;
|
||||
}
|
||||
|
||||
/* static */ Money AICompany::GetCompanyValue(AICompany::CompanyID company)
|
||||
{
|
||||
company = ResolveCompanyID(company);
|
||||
|
|
|
@ -26,6 +26,13 @@ public:
|
|||
COMPANY_SELF = 254, //!< Constant that gets resolved to the correct company index for your company.
|
||||
};
|
||||
|
||||
/** Possible genders for company presidents. */
|
||||
enum Gender {
|
||||
GENDER_MALE, //!< A male person.
|
||||
GENDER_FEMALE, //!< A female person.
|
||||
GENDER_INVALID = -1, //!< An invalid gender.
|
||||
};
|
||||
|
||||
/**
|
||||
* Resolved the given company index to the correct index for the company. If
|
||||
* the company index was COMPANY_SELF it will be resolved to the index of
|
||||
|
@ -78,6 +85,22 @@ public:
|
|||
*/
|
||||
static char *GetPresidentName(CompanyID company);
|
||||
|
||||
/**
|
||||
* Set the gender of the president of your company.
|
||||
* @param gender The new gender for your president.
|
||||
* @pre GetPresidentGender(AICompany.COMPANY_SELF) != gender.
|
||||
* @return True if the gender was changed.
|
||||
* @note When succesfull a random face will be created.
|
||||
*/
|
||||
static bool SetPresidentGender(Gender gender);
|
||||
|
||||
/**
|
||||
* Get the gender of the president of the given company.
|
||||
* @param company The company to get the presidents gender off.
|
||||
* @return The gender of the president.
|
||||
*/
|
||||
static Gender GetPresidentGender(CompanyID company);
|
||||
|
||||
/**
|
||||
* Sets the amount to loan.
|
||||
* @param loan The amount to loan (multiplier of GetLoanInterval()).
|
||||
|
|
|
@ -7,6 +7,8 @@ namespace SQConvert {
|
|||
/* Allow enums to be used as Squirrel parameters */
|
||||
template <> AICompany::CompanyID GetParam(ForceType<AICompany::CompanyID>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AICompany::CompanyID)tmp; }
|
||||
template <> int Return<AICompany::CompanyID>(HSQUIRRELVM vm, AICompany::CompanyID res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
template <> AICompany::Gender GetParam(ForceType<AICompany::Gender>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AICompany::Gender)tmp; }
|
||||
template <> int Return<AICompany::Gender>(HSQUIRRELVM vm, AICompany::Gender res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
|
||||
/* Allow AICompany to be used as Squirrel parameter */
|
||||
template <> AICompany *GetParam(ForceType<AICompany *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AICompany *)instance; }
|
||||
|
@ -25,6 +27,9 @@ void SQAICompany_Register(Squirrel *engine) {
|
|||
SQAICompany.DefSQConst(engine, AICompany::COMPANY_FIRST, "COMPANY_FIRST");
|
||||
SQAICompany.DefSQConst(engine, AICompany::COMPANY_LAST, "COMPANY_LAST");
|
||||
SQAICompany.DefSQConst(engine, AICompany::COMPANY_SELF, "COMPANY_SELF");
|
||||
SQAICompany.DefSQConst(engine, AICompany::GENDER_MALE, "GENDER_MALE");
|
||||
SQAICompany.DefSQConst(engine, AICompany::GENDER_FEMALE, "GENDER_FEMALE");
|
||||
SQAICompany.DefSQConst(engine, AICompany::GENDER_INVALID, "GENDER_INVALID");
|
||||
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::ResolveCompanyID, "ResolveCompanyID", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::IsMine, "IsMine", 2, ".i");
|
||||
|
@ -32,6 +37,8 @@ void SQAICompany_Register(Squirrel *engine) {
|
|||
SQAICompany.DefSQStaticMethod(engine, &AICompany::GetName, "GetName", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentName, "SetPresidentName", 2, ".s");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentName, "GetPresidentName", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::SetPresidentGender, "SetPresidentGender", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::GetPresidentGender, "GetPresidentGender", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::SetLoanAmount, "SetLoanAmount", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::SetMinimumLoanAmount, "SetMinimumLoanAmount", 2, ".i");
|
||||
SQAICompany.DefSQStaticMethod(engine, &AICompany::GetLoanAmount, "GetLoanAmount", 1, ".");
|
||||
|
|
Loading…
Reference in New Issue