Skip to content

Commit

Permalink
Merge pull request #11 from dcvz/chore/game-interactor
Browse files Browse the repository at this point in the history
Chore/game interactor
  • Loading branch information
aMannus authored Jan 16, 2023
2 parents ab10462 + 6254907 commit 310c9a5
Show file tree
Hide file tree
Showing 9 changed files with 492 additions and 255 deletions.
14 changes: 14 additions & 0 deletions soh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ set(Header_Files__soh__Enhancements__item_tables

source_group("Header Files\\soh\\Enhancements\\item-tables" FILES ${Header_Files__soh__Enhancements__item_tables})

set(Header_Files__soh__Enhancements__game_interactor
"soh/Enhancements/game-interactor/GameInteractor.h"
"soh/Enhancements/game-interactor/GameInteractionEffect.h"
)
source_group("Header Files\\soh\\Enhancements\\game-interactor" FILES ${Header_Files__soh__Enhancements__game_interactor})

if (BUILD_CROWD_CONTROL)
set(Header_Files__soh__Enhancements__crowd_control
"soh/Enhancements/crowd-control/CrowdControl.h"
Expand Down Expand Up @@ -411,6 +417,12 @@ set(Source_Files__soh__Enhancements__item_tables

source_group("Source Files\\soh\\Enhancements\\item-tables" FILES ${Source_Files__soh__Enhancements__item_tables})

set(Source_Files__soh__Enhancements__game_interactor
"soh/Enhancements/game-interactor/GameInteractor.cpp"
"soh/Enhancements/game-interactor/GameInteractionEffect.cpp"
)
source_group("Source Files\\soh\\Enhancements\\game-interactor" FILES ${Source_Files__soh__Enhancements__game_interactor})

if (BUILD_CROWD_CONTROL)
set(Source_Files__soh__Enhancements__crowd_control
"soh/Enhancements/crowd-control/CrowdControl.cpp"
Expand Down Expand Up @@ -1629,6 +1641,7 @@ set(ALL_FILES
${Header_Files__soh__Enhancements__randomizer__3drando}
${Header_Files__soh__Enhancements__item_tables}
${Header_Files__soh__Enhancements__custom_message}
${Header_Files__soh__Enhancements__game_interactor}
${Header_Files__soh__Enhancements__crowd_control}
${Source_Files__soh}
${Source_Files__soh__Enhancements}
Expand All @@ -1642,6 +1655,7 @@ set(ALL_FILES
${Source_Files__soh__Enhancements__randomizer__3drando__location_access}
${Source_Files__soh__Enhancements__item_tables}
${Source_Files__soh__Enhancements__custom_message}
${Source_Files__soh__Enhancements__game_interactor}
${Source_Files__soh__Enhancements__crowd_control}
${Source_Files__src__boot}
${Source_Files__src__buffers}
Expand Down
531 changes: 284 additions & 247 deletions soh/soh/Enhancements/crowd-control/CrowdControl.cpp

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions soh/soh/Enhancements/crowd-control/CrowdControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <chrono>
#include <future>

#include "../game-interactor/GameInteractor.h"

class CrowdControl {
private:
enum EffectResult {
Expand Down Expand Up @@ -61,10 +63,9 @@ class CrowdControl {

typedef struct Effect {
uint32_t id;
std::string type;
uint32_t value;
std::string category;
long timeRemaining;
GameInteractionEffectBase *giEffect;

// Metadata used while executing (only for timed effects)
bool isPaused;
Expand All @@ -88,11 +89,13 @@ class CrowdControl {
void ListenToServer();
void ProcessActiveEffects();

void EmitMessage(TCPsocket socket, uint32_t eventId, long timeRemaining,
CrowdControl::EffectResult status);
void EmitMessage(TCPsocket socket, uint32_t eventId, long timeRemaining, EffectResult status);
void EmitMessage(TCPsocket socket, uint32_t eventId, long timeRemaining, GameInteractionEffectQueryResult status);
Effect* ParseMessage(char payload[512]);
EffectResult ExecuteEffect(std::string effectId, uint32_t value, bool dryRun);
void RemoveEffect(std::string effectId);
EffectResult ExecuteEffect(Effect* effect);
void RemoveEffect(Effect* effect);
// EffectResult ExecuteEffect(std::string effectId, uint32_t value, bool dryRun);
// void RemoveEffect(std::string effectId);
bool SpawnEnemy(std::string effectId);

public:
Expand Down
68 changes: 68 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractionEffect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// GameInteractionEffect.cpp
// soh
//
// Created by David Chavez on 15.12.22.
//

#include "GameInteractionEffect.h"
#include "GameInteractor.h"

extern "C" {
#include <z64.h>
#include "variables.h"
#include "functions.h"
#include "macros.h"
extern PlayState* gPlayState;
}

// Effect State

uint32_t GameInteractor_NoUI;

// AddHeartContainer

namespace GameInteractionEffect {
GameInteractionEffectQueryResult AddHeartContainer::CanBeApplied() {
return gSaveContext.healthCapacity >= 0x140
? GameInteractionEffectQueryResult::NotPossibe
: GameInteractionEffectQueryResult::Possible;
}

void AddHeartContainer::Apply() {
Health_GiveHearts(1);
}

// RemoveHeartContainer

GameInteractionEffectQueryResult RemoveHeartContainer::CanBeApplied() {
return ((gSaveContext.healthCapacity - 0x10) <= 0)
? GameInteractionEffectQueryResult::NotPossibe
: GameInteractionEffectQueryResult::Possible;
}

void RemoveHeartContainer::Apply() {
Health_RemoveHearts(1);
}

// GiveRupees

GameInteractionEffectQueryResult GiveRupees::CanBeApplied() {
return GameInteractionEffectQueryResult::Possible;
}

void GiveRupees::Apply() {
Rupees_ChangeBy(amount);
}


// NoUIEffect

GameInteractionEffectQueryResult NoUI::CanBeApplied() {
return GameInteractionEffectQueryResult::Possible;
}

void NoUI::Apply() {
GameInteractor_NoUI = 1;
}
}
67 changes: 67 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractionEffect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// GameInteractionEffect.h
// soh
//
// Created by David Chavez on 15.12.22.
//

#ifndef GameInteractionEffect_h
#define GameInteractionEffect_h

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t GameInteractor_NoUI;
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
enum GameInteractionEffectQueryResult {
Possible = 0x00,
TemporarilyNotPossible = 0x01,
NotPossibe = 0xFF
};

class GameInteractionEffectBase {
public:
virtual GameInteractionEffectQueryResult CanBeApplied() = 0;
virtual void Apply() = 0;
};

namespace GameInteractionEffect {
class AddHeartContainer: public GameInteractionEffectBase {
GameInteractionEffectQueryResult CanBeApplied() override;
void Apply() override;
};

class RemoveHeartContainer: public GameInteractionEffectBase {
GameInteractionEffectQueryResult CanBeApplied() override;
void Apply() override;
};

class AddOrRemoveHeartContainer: public GameInteractionEffectBase {
int32_t amount;

GameInteractionEffectQueryResult CanBeApplied() override;
void Apply() override;
};

class GiveRupees: public GameInteractionEffectBase {
public:
uint32_t amount;

GameInteractionEffectQueryResult CanBeApplied() override;
void Apply() override;
};

class NoUI: public GameInteractionEffectBase {
GameInteractionEffectQueryResult CanBeApplied() override;
void Apply() override;
};
}

#endif /* __cplusplus */
#endif /* GameInteractionEffect_h */
16 changes: 16 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GameInteractor.cpp
// soh
//
// Created by David Chavez on 07.12.22.
//

#include "GameInteractor.h"

GameInteractionEffectQueryResult GameInteractor::CanApplyEffect(GameInteractionEffectBase effect) {
return effect.CanBeApplied();
}

void GameInteractor::ApplyEffect(GameInteractionEffectBase effect) {
return effect.Apply();
}
27 changes: 27 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// GameInteractor.h
// soh
//
// Created by David Chavez on 07.12.22.
//

#ifndef GameInteractor_h
#define GameInteractor_h

#include "GameInteractionEffect.h"

#ifdef __cplusplus
class GameInteractor {
public:
static GameInteractor* Instance;

static GameInteractionEffectQueryResult CanApplyEffect(GameInteractionEffectBase effect);
static void ApplyEffect(GameInteractionEffectBase effect);
static void RemoveEffect();

static bool CanSpawnEnemy();
static void SpawnEnemy();
};

#endif
#endif /* GameInteractor_h */
6 changes: 5 additions & 1 deletion soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "OTRGlobals.h"
#include "OTRGlobals.h"
#include "OTRAudio.h"
#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -78,10 +78,13 @@
CrowdControl* CrowdControl::Instance;
#endif

#include "Enhancements/game-interactor/GameInteractor.h"

OTRGlobals* OTRGlobals::Instance;
SaveManager* SaveManager::Instance;
CustomMessageManager* CustomMessageManager::Instance;
ItemTableManager* ItemTableManager::Instance;
GameInteractor* GameInteractor::Instance;

OTRGlobals::OTRGlobals() {
std::vector<std::string> OTRFiles;
Expand Down Expand Up @@ -434,6 +437,7 @@ extern "C" void InitOTR() {
SaveManager::Instance = new SaveManager();
CustomMessageManager::Instance = new CustomMessageManager();
ItemTableManager::Instance = new ItemTableManager();
GameInteractor::Instance = new GameInteractor();

clearMtx = (uintptr_t)&gMtxClear;
OTRMessage_Init();
Expand Down
3 changes: 2 additions & 1 deletion soh/src/code/z_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#endif

#include "soh/Enhancements/debugconsole.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"


static uint16_t _doActionTexWidth, _doActionTexHeight = -1;
Expand Down Expand Up @@ -4962,7 +4963,7 @@ void Interface_Draw(PlayState* play) {
s16 svar6;
bool fullUi = !CVar_GetS32("gMinimalUI", 0) || !R_MINIMAP_DISABLED || play->pauseCtx.state != 0;

if (chaosEffectNoUI) {
if (GameInteractor_NoUI) {
return;
}

Expand Down

0 comments on commit 310c9a5

Please sign in to comment.