mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-06-22 19:55:33 +00:00
restructure codebase according to vcproj filters
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
|
||||
|
||||
#include "../../../../net/minecraft/client/Minecraft.h"
|
||||
#include "../../../../net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.h"
|
||||
#include "AreaConstraint.h"
|
||||
#include "../../../../../Minecraft.World/net/minecraft/world/phys/AABB.h"
|
||||
|
||||
AreaConstraint::AreaConstraint(int descriptionId, double x0, double y0,
|
||||
double z0, double x1, double y1, double z1,
|
||||
bool contains /*= true*/,
|
||||
bool restrictsMovement /*=true*/)
|
||||
: TutorialConstraint(descriptionId) {
|
||||
messageArea = AABB(x0 + 2, y0 + 2, z0 + 2, x1 - 2, y1 - 2, z1 - 2);
|
||||
movementArea = AABB(x0, y0, z0, x1, y1, z1);
|
||||
|
||||
this->contains = contains;
|
||||
m_restrictsMovement = restrictsMovement;
|
||||
}
|
||||
|
||||
bool AreaConstraint::isConstraintSatisfied(int iPad) {
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
|
||||
// TODO: check if this can be elided
|
||||
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
|
||||
return messageArea.contains(ipad_player) == contains;
|
||||
}
|
||||
|
||||
bool AreaConstraint::isConstraintRestrictive(int iPad) {
|
||||
return m_restrictsMovement;
|
||||
}
|
||||
|
||||
bool AreaConstraint::canMoveToPosition(double xo, double yo, double zo,
|
||||
double xt, double yt, double zt) {
|
||||
if (!m_restrictsMovement) return true;
|
||||
|
||||
Vec3 targetPos(xt, yt, zt);
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
|
||||
if (movementArea.contains(targetPos) == contains) {
|
||||
return true;
|
||||
}
|
||||
Vec3 origPos(xo, yo, zo);
|
||||
|
||||
double currDist = origPos.distanceTo(&movementArea);
|
||||
double targetDist = targetPos.distanceTo(&movementArea);
|
||||
return targetDist < currDist;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "TutorialConstraint.h"
|
||||
|
||||
class AABB;
|
||||
|
||||
class AreaConstraint : public TutorialConstraint {
|
||||
private:
|
||||
AABB movementArea;
|
||||
AABB messageArea;
|
||||
bool contains; // If true we must stay in this area, if false must stay out
|
||||
// of this area
|
||||
bool m_restrictsMovement;
|
||||
|
||||
public:
|
||||
virtual ConstraintType getType() { return e_ConstraintArea; }
|
||||
|
||||
AreaConstraint(int descriptionId, double x0, double y0, double z0,
|
||||
double x1, double y1, double z1, bool contains = true,
|
||||
bool restrictsMovement = true);
|
||||
|
||||
virtual bool isConstraintSatisfied(int iPad);
|
||||
virtual bool isConstraintRestrictive(int iPad);
|
||||
virtual bool canMoveToPosition(double xo, double yo, double zo, double xt,
|
||||
double yt, double zt);
|
||||
};
|
||||
@@ -0,0 +1,158 @@
|
||||
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
|
||||
|
||||
#include "../Tutorial.h"
|
||||
#include "../../../../net/minecraft/client/Minecraft.h"
|
||||
#include "../../../../net/minecraft/client/multiplayer/MultiPlayerLocalPlayer.h"
|
||||
#include "../../../../../Minecraft.World/net/minecraft/world/level/net.minecraft.world.level.h"
|
||||
#include "ChangeStateConstraint.h"
|
||||
#include "../../../../../Minecraft.World/net/minecraft/world/phys/AABB.h"
|
||||
#include "../../../../net/minecraft/client/multiplayer/ClientConnection.h"
|
||||
#include "../../../../../Minecraft.World/net/minecraft/network/packet/net.minecraft.network.packet.h"
|
||||
|
||||
ChangeStateConstraint::ChangeStateConstraint(
|
||||
Tutorial* tutorial, eTutorial_State targetState,
|
||||
eTutorial_State sourceStates[], std::size_t sourceStatesCount, double x0,
|
||||
double y0, double z0, double x1, double y1, double z1,
|
||||
bool contains /*= true*/, bool changeGameMode /*= false*/,
|
||||
GameType* targetGameMode /*= 0*/)
|
||||
: TutorialConstraint(-1) {
|
||||
movementArea = AABB(x0, y0, z0, x1, y1, z1);
|
||||
|
||||
this->contains = contains;
|
||||
|
||||
m_changeGameMode = changeGameMode;
|
||||
m_targetGameMode = targetGameMode;
|
||||
m_changedFromGameMode = 0;
|
||||
|
||||
m_tutorial = tutorial;
|
||||
m_targetState = targetState;
|
||||
m_sourceStatesCount = sourceStatesCount;
|
||||
|
||||
m_bHasChanged = false;
|
||||
m_changedFromState = e_Tutorial_State_None;
|
||||
|
||||
m_bComplete = false;
|
||||
|
||||
m_sourceStates = new eTutorial_State[m_sourceStatesCount];
|
||||
for (unsigned int i = 0; i < m_sourceStatesCount; i++) {
|
||||
m_sourceStates[i] = sourceStates[i];
|
||||
}
|
||||
}
|
||||
|
||||
ChangeStateConstraint::~ChangeStateConstraint() {
|
||||
if (m_sourceStatesCount > 0) delete[] m_sourceStates;
|
||||
}
|
||||
|
||||
void ChangeStateConstraint::tick(int iPad) {
|
||||
if (m_bComplete) return;
|
||||
|
||||
if (m_tutorial->isStateCompleted(m_targetState)) {
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
if (m_changeGameMode) {
|
||||
unsigned int playerPrivs =
|
||||
minecraft->localplayers[iPad]->getAllPlayerGamePrivileges();
|
||||
Player::setPlayerGamePrivilege(
|
||||
playerPrivs, Player::ePlayerGamePrivilege_CreativeMode,
|
||||
m_changedFromGameMode == GameType::CREATIVE);
|
||||
|
||||
unsigned int originalPrivileges =
|
||||
minecraft->localplayers[iPad]->getAllPlayerGamePrivileges();
|
||||
if (originalPrivileges != playerPrivs) {
|
||||
// Send update settings packet to server
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
std::shared_ptr<MultiplayerLocalPlayer> player =
|
||||
minecraft->localplayers[iPad];
|
||||
if (player != nullptr && player->connection &&
|
||||
player->connection->getNetworkPlayer() != nullptr) {
|
||||
player->connection->send(
|
||||
std::shared_ptr<PlayerInfoPacket>(new PlayerInfoPacket(
|
||||
player->connection->getNetworkPlayer()
|
||||
->GetSmallId(),
|
||||
-1, playerPrivs)));
|
||||
}
|
||||
}
|
||||
}
|
||||
m_bComplete = true;
|
||||
return;
|
||||
}
|
||||
|
||||
bool inASourceState = false;
|
||||
Minecraft* minecraft = Minecraft::GetInstance();
|
||||
for (std::size_t i = 0; i < m_sourceStatesCount; ++i) {
|
||||
if (m_sourceStates[i] == m_tutorial->getCurrentState()) {
|
||||
inASourceState = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check if this can be elided
|
||||
Vec3 ipad_player = minecraft->localplayers[iPad]->getPos(1);
|
||||
if (!m_bHasChanged && inASourceState &&
|
||||
movementArea.contains(ipad_player) == contains) {
|
||||
m_bHasChanged = true;
|
||||
m_changedFromState = m_tutorial->getCurrentState();
|
||||
m_tutorial->changeTutorialState(m_targetState);
|
||||
|
||||
if (m_changeGameMode) {
|
||||
if (minecraft->localgameModes[iPad] != nullptr) {
|
||||
m_changedFromGameMode =
|
||||
minecraft->localplayers[iPad]->abilities.instabuild
|
||||
? GameType::CREATIVE
|
||||
: GameType::SURVIVAL;
|
||||
|
||||
unsigned int playerPrivs =
|
||||
minecraft->localplayers[iPad]->getAllPlayerGamePrivileges();
|
||||
Player::setPlayerGamePrivilege(
|
||||
playerPrivs, Player::ePlayerGamePrivilege_CreativeMode,
|
||||
m_targetGameMode == GameType::CREATIVE);
|
||||
|
||||
unsigned int originalPrivileges =
|
||||
minecraft->localplayers[iPad]->getAllPlayerGamePrivileges();
|
||||
if (originalPrivileges != playerPrivs) {
|
||||
// Send update settings packet to server
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
std::shared_ptr<MultiplayerLocalPlayer> player =
|
||||
minecraft->localplayers[iPad];
|
||||
if (player != nullptr && player->connection &&
|
||||
player->connection->getNetworkPlayer() != nullptr) {
|
||||
player->connection->send(
|
||||
std::shared_ptr<PlayerInfoPacket>(
|
||||
new PlayerInfoPacket(
|
||||
player->connection->getNetworkPlayer()
|
||||
->GetSmallId(),
|
||||
-1, playerPrivs)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (m_bHasChanged &&
|
||||
movementArea.contains(ipad_player) != contains) {
|
||||
m_bHasChanged = false;
|
||||
m_tutorial->changeTutorialState(m_changedFromState);
|
||||
|
||||
if (m_changeGameMode) {
|
||||
unsigned int playerPrivs =
|
||||
minecraft->localplayers[iPad]->getAllPlayerGamePrivileges();
|
||||
Player::setPlayerGamePrivilege(
|
||||
playerPrivs, Player::ePlayerGamePrivilege_CreativeMode,
|
||||
m_changedFromGameMode == GameType::CREATIVE);
|
||||
|
||||
unsigned int originalPrivileges =
|
||||
minecraft->localplayers[iPad]->getAllPlayerGamePrivileges();
|
||||
if (originalPrivileges != playerPrivs) {
|
||||
// Send update settings packet to server
|
||||
Minecraft* pMinecraft = Minecraft::GetInstance();
|
||||
std::shared_ptr<MultiplayerLocalPlayer> player =
|
||||
minecraft->localplayers[iPad];
|
||||
if (player != nullptr && player->connection &&
|
||||
player->connection->getNetworkPlayer() != nullptr) {
|
||||
player->connection->send(
|
||||
std::shared_ptr<PlayerInfoPacket>(new PlayerInfoPacket(
|
||||
player->connection->getNetworkPlayer()
|
||||
->GetSmallId(),
|
||||
-1, playerPrivs)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include "../TutorialEnum.h"
|
||||
#include "TutorialConstraint.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class AABB;
|
||||
class Tutorial;
|
||||
class GameType;
|
||||
|
||||
class ChangeStateConstraint : public TutorialConstraint {
|
||||
private:
|
||||
AABB movementArea;
|
||||
bool contains; // If true we must stay in this area, if false must stay out
|
||||
// of this area
|
||||
bool m_changeGameMode;
|
||||
GameType* m_targetGameMode;
|
||||
GameType* m_changedFromGameMode;
|
||||
|
||||
eTutorial_State m_targetState;
|
||||
eTutorial_State* m_sourceStates;
|
||||
std::size_t m_sourceStatesCount;
|
||||
|
||||
bool m_bHasChanged;
|
||||
eTutorial_State m_changedFromState;
|
||||
|
||||
bool m_bComplete;
|
||||
|
||||
Tutorial* m_tutorial;
|
||||
|
||||
public:
|
||||
virtual ConstraintType getType() { return e_ConstraintChangeState; }
|
||||
|
||||
ChangeStateConstraint(Tutorial* tutorial, eTutorial_State targetState,
|
||||
eTutorial_State sourceStates[],
|
||||
std::size_t sourceStatesCount, double x0, double y0,
|
||||
double z0, double x1, double y1, double z1,
|
||||
bool contains = true, bool changeGameMode = false,
|
||||
GameType* targetGameMode = nullptr);
|
||||
~ChangeStateConstraint();
|
||||
|
||||
virtual void tick(int iPad);
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "../../../../../Minecraft.World/Header Files/stdafx.h"
|
||||
#include "InputConstraint.h"
|
||||
|
||||
bool InputConstraint::isMappingConstrained(int iPad, int mapping) {
|
||||
// If it's a menu button, then we ignore all inputs
|
||||
if ((m_inputMapping == mapping) || (mapping < ACTION_MAX_MENU)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise see if they map to the same actual button
|
||||
unsigned char layoutMapping = InputManager.GetJoypadMapVal(iPad);
|
||||
|
||||
// 4J HEG - Replaced the equivalance test with bitwise AND, important in
|
||||
// some mapping configurations (e.g. when comparing two action map values
|
||||
// and one has extra buttons mapped)
|
||||
return (InputManager.GetGameJoypadMaps(layoutMapping, m_inputMapping) &
|
||||
InputManager.GetGameJoypadMaps(layoutMapping, mapping)) > 0;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "TutorialConstraint.h"
|
||||
|
||||
class InputConstraint : public TutorialConstraint {
|
||||
private:
|
||||
int m_inputMapping; // Should be one of the EControllerActions
|
||||
public:
|
||||
virtual ConstraintType getType() { return e_ConstraintInput; }
|
||||
|
||||
InputConstraint(int mapping)
|
||||
: TutorialConstraint(-1), m_inputMapping(mapping) {}
|
||||
|
||||
virtual bool isMappingConstrained(int iPad, int mapping);
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
// 4J Stu - An abstract class that represents a constraint on what the user is
|
||||
// able to do
|
||||
class TutorialConstraint {
|
||||
private:
|
||||
int descriptionId;
|
||||
bool m_deleteOnDeactivate;
|
||||
bool m_queuedForRemoval;
|
||||
|
||||
public:
|
||||
enum ConstraintType {
|
||||
e_ConstraintInput = 0, // Constraint on controller input
|
||||
e_ConstraintArea,
|
||||
e_ConstraintAllInput,
|
||||
e_ConstraintXuiInput,
|
||||
e_ConstraintChangeState,
|
||||
};
|
||||
|
||||
TutorialConstraint(int descriptionId)
|
||||
: descriptionId(descriptionId),
|
||||
m_deleteOnDeactivate(false),
|
||||
m_queuedForRemoval(false) {}
|
||||
virtual ~TutorialConstraint() {}
|
||||
|
||||
int getDescriptionId() { return descriptionId; }
|
||||
|
||||
virtual ConstraintType getType() = 0;
|
||||
|
||||
virtual void tick(int iPad) {}
|
||||
virtual bool isConstraintSatisfied(int iPad) { return true; }
|
||||
virtual bool isConstraintRestrictive(int iPad) { return true; }
|
||||
|
||||
virtual bool isMappingConstrained(int iPad, int mapping) { return false; }
|
||||
virtual bool isXuiInputConstrained(int vk) { return false; }
|
||||
|
||||
void setDeleteOnDeactivate(bool deleteOnDeactivated) {
|
||||
m_deleteOnDeactivate = deleteOnDeactivated;
|
||||
}
|
||||
bool getDeleteOnDeactivate() { return m_deleteOnDeactivate; }
|
||||
|
||||
void setQueuedForRemoval(bool queued) { m_queuedForRemoval = queued; }
|
||||
bool getQueuedForRemoval() { return m_queuedForRemoval; }
|
||||
|
||||
virtual bool canMoveToPosition(double xo, double yo, double zo, double xt,
|
||||
double yt, double zt) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
#include "TutorialConstraint.h"
|
||||
#include "AreaConstraint.h"
|
||||
#include "ChangeStateConstraint.h"
|
||||
#include "InputConstraint.h"
|
||||
Reference in New Issue
Block a user