Skip to content

Commit

Permalink
Implements IsEligibleForAllyBuilding for BuildingTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed Oct 15, 2021
1 parent e4dc424 commit 530c32e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/extensions/buildingtype/buildingtypeext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ ExtensionMap<BuildingTypeClass, BuildingTypeClassExtension> BuildingTypeClassExt
*/
BuildingTypeClassExtension::BuildingTypeClassExtension(BuildingTypeClass *this_ptr) :
Extension(this_ptr),

GateUpSound(VOC_NONE),
GateDownSound(VOC_NONE),
ProduceCashStartup(0),
ProduceCashAmount(0),
ProduceCashDelay(0),
ProduceCashBudget(0),
IsStartupCashOneTime(false),
IsResetBudgetOnCapture(false)
IsResetBudgetOnCapture(false),
IsEligibleForAllyBuilding(false)
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("BuildingTypeClassExtension constructor - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));
Expand Down Expand Up @@ -165,6 +165,8 @@ void BuildingTypeClassExtension::Compute_CRC(WWCRCEngine &crc) const
{
ASSERT(ThisPtr != nullptr);
//DEV_DEBUG_TRACE("BuildingTypeClassExtension::Compute_CRC - Name: %s (0x%08X)\n", ThisPtr->Name(), (uintptr_t)(ThisPtr));

crc(IsEligibleForAllyBuilding);
}


Expand Down Expand Up @@ -194,6 +196,9 @@ bool BuildingTypeClassExtension::Read_INI(CCINIClass &ini)
ProduceCashBudget = ini.Get_Int(ini_name, "ProduceCashBudget", ProduceCashBudget);
IsStartupCashOneTime = ini.Get_Int(ini_name, "ProduceCashStartupOneTime", IsStartupCashOneTime);
IsResetBudgetOnCapture = ini.Get_Bool(ini_name, "ProduceCashResetOnCapture", IsResetBudgetOnCapture);

IsEligibleForAllyBuilding = ini.Get_Bool(ini_name, "EligibleForAllyBuilding",
ThisPtr->IsConstructionYard ? true : IsEligibleForAllyBuilding);

return true;
}
5 changes: 5 additions & 0 deletions src/extensions/buildingtype/buildingtypeext.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class BuildingTypeClassExtension final : public Extension<BuildingTypeClass>
* Reset the available budget when captured?
*/
bool IsResetBudgetOnCapture;

/**
* Is this building eligible for proximity checks by players who are its owner's allies?
*/
bool IsEligibleForAllyBuilding;
};


Expand Down
71 changes: 71 additions & 0 deletions src/extensions/display/displayext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
#include "tibsun_util.h"
#include "display.h"
#include "iomap.h"
#include "cell.h"
#include "building.h"
#include "buildingtype.h"
#include "buildingtypeext.h"
#include "house.h"
#include "housetype.h"
#include "session.h"
#include "sessionext.h"
#include "wwmouse.h"
#include "fatal.h"
#include "debughandler.h"
Expand All @@ -40,6 +48,68 @@
#include "hooker_macros.h"


/**
* #issue-171
*
* Adds game option to control if allies can build off each others bases.
*
* @author: CCHyper
*/
DECLARE_PATCH(_DisplayClass_Passes_Proximity_Passes_Check_Patch)
{
//GET_REGISTER_STATIC(DisplayClass *, this_ptr, ?); // No access to "this".
GET_REGISTER_STATIC(BuildingClass *, base, eax);
GET_STACK_STATIC(HousesType, house, esp, 0x38);
//GET_STACK_STATIC8(bool, passes, esp, 0x3C);
static BuildingTypeClassExtension *buildingtypeext;
static HouseClass *hptr;

/**
* Store the proximity check result.
*/
#define passes() _asm { mov byte ptr [esp+0x3C], 1 }

hptr = Houses[house];

/**
* Stolen bytes/code.
*
* Ensure the building is considered eligible for adjacency checks.
*/
if (base->House->ID == house && base->Class->IsBase) {
passes();
}

/**
* If the build-off-ally option is enabled, ensure the building is
* owned by an ally house and is eligible for adjacent building before
* passing the check.
*
* #NOTE: This feature is only available for multiplayer games.
*/
if (Session.Type != GAME_NORMAL) {
if (SessionExtension && SessionExtension->ExtOptions.IsBuildOffAlly) {

if (base->House != hptr && base->House->Is_Ally(hptr)) {

buildingtypeext = BuildingTypeClassExtensions.find(base->Class);
if (buildingtypeext && buildingtypeext->IsEligibleForAllyBuilding) {
#ifndef NDEBUG
//DEV_DEBUG_INFO("Ally \"%s's\" building \"%s\" is eligible for building off.\n", base->House->IniName, base->Name());
#endif
passes();
}
}
}
}

#undef passes

continue_scan:
JMP(0x00476308);
}


/**
* #issue-344
*
Expand Down Expand Up @@ -179,6 +249,7 @@ void DisplayClassExtension_Hooks()
{
Patch_Jump(0x0047AFA6, &_DisplayClass_Help_Text_GetCursorPosition_Patch);
Patch_Jump(0x00478974, &_DisplayClass_Mouse_Left_Release_PlaceAnywhere_BugFix_Patch);
Patch_Jump(0x004762E4, &_DisplayClass_Passes_Proximity_Passes_Check_Patch);

/**
* #issue-76
Expand Down

0 comments on commit 530c32e

Please sign in to comment.