diff options
author | yexo <yexo@openttd.org> | 2009-08-01 00:28:21 +0000 |
---|---|---|
committer | yexo <yexo@openttd.org> | 2009-08-01 00:28:21 +0000 |
commit | fc03fef4aee9b069bf4f1e8c2109d127246a973a (patch) | |
tree | a9b87cbe46c314a6b6d76193a9144b56d12694f8 /src/ai | |
parent | ae71df349ebeeb1732525f34b88ab8d2782f57a4 (diff) | |
download | openttd-fc03fef4aee9b069bf4f1e8c2109d127246a973a.tar.xz |
(svn r17016) -Add [NoAI]: AICompany::Get/Set PresidentGender
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/api/ai_company.cpp | 22 | ||||
-rw-r--r-- | src/ai/api/ai_company.hpp | 23 | ||||
-rw-r--r-- | src/ai/api/ai_company.hpp.sq | 7 |
3 files changed, 52 insertions, 0 deletions
diff --git a/src/ai/api/ai_company.cpp b/src/ai/api/ai_company.cpp index ca11b7f73..73207fbbf 100644 --- a/src/ai/api/ai_company.cpp +++ b/src/ai/api/ai_company.cpp @@ -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); diff --git a/src/ai/api/ai_company.hpp b/src/ai/api/ai_company.hpp index b75fa5fff..feccd6f49 100644 --- a/src/ai/api/ai_company.hpp +++ b/src/ai/api/ai_company.hpp @@ -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 @@ -79,6 +86,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()). * @pre 'loan' must be non-negative. diff --git a/src/ai/api/ai_company.hpp.sq b/src/ai/api/ai_company.hpp.sq index 3c99dd2ff..9441fb317 100644 --- a/src/ai/api/ai_company.hpp.sq +++ b/src/ai/api/ai_company.hpp.sq @@ -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, "."); |