Skip to content

Commit

Permalink
item: Implement CoinCollectEmpty2D
Browse files Browse the repository at this point in the history
  • Loading branch information
german77 committed Jan 4, 2025
1 parent d692c63 commit 2454772
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 12 deletions.
24 changes: 12 additions & 12 deletions data/odyssey_functions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10885,18 +10885,18 @@ Address,Quality,Size,Name
0x00000071001c1704,U,000072,_ZNK12_GLOBAL__N_123CoinCollectEmptyNrvWait7executeEPN2al11NerveKeeperE
0x00000071001c174c,U,000008,_ZNK12_GLOBAL__N_126CoinCollectEmptyNrvCountUp7executeEPN2al11NerveKeeperE
0x00000071001c1754,U,000008,_ZNK12_GLOBAL__N_122CoinCollectEmptyNrvGot7executeEPN2al11NerveKeeperE
0x00000071001c175c,U,000160,_ZN18CoinCollectEmpty2DC2EPKcS1_
0x00000071001c17fc,U,000148,_ZN18CoinCollectEmpty2DC1EPKcS1_
0x00000071001c1890,U,000200,_ZN18CoinCollectEmpty2D4initERKN2al13ActorInitInfoE
0x00000071001c1958,U,000220,_ZN18CoinCollectEmpty2D18initAfterPlacementEv
0x00000071001c1a34,U,000044,_ZN18CoinCollectEmpty2D10endClippedEv
0x00000071001c1a60,U,000120,_ZN18CoinCollectEmpty2D10receiveMsgEPKN2al9SensorMsgEPNS0_9HitSensorES5_
0x00000071001c1ad8,U,000016,_ZN18CoinCollectEmpty2D7exeWaitEv
0x00000071001c1ae8,U,000140,_ZN18CoinCollectEmpty2D6exeGotEv
0x00000071001c1b74,U,000008,_ZNK18CoinCollectEmpty2D23getActorDimensionKeeperEv
0x00000071001c1b7c,U,000008,_ZThn264_NK18CoinCollectEmpty2D23getActorDimensionKeeperEv
0x00000071001c1b84,U,000020,_ZNK12_GLOBAL__N_125CoinCollectEmpty2DNrvWait7executeEPN2al11NerveKeeperE
0x00000071001c1b98,U,000008,_ZNK12_GLOBAL__N_124CoinCollectEmpty2DNrvGot7executeEPN2al11NerveKeeperE
0x00000071001c175c,O,000160,_ZN18CoinCollectEmpty2DC2EPKcS1_
0x00000071001c17fc,O,000148,_ZN18CoinCollectEmpty2DC1EPKcS1_
0x00000071001c1890,O,000200,_ZN18CoinCollectEmpty2D4initERKN2al13ActorInitInfoE
0x00000071001c1958,O,000220,_ZN18CoinCollectEmpty2D18initAfterPlacementEv
0x00000071001c1a34,O,000044,_ZN18CoinCollectEmpty2D10endClippedEv
0x00000071001c1a60,O,000120,_ZN18CoinCollectEmpty2D10receiveMsgEPKN2al9SensorMsgEPNS0_9HitSensorES5_
0x00000071001c1ad8,O,000016,_ZN18CoinCollectEmpty2D7exeWaitEv
0x00000071001c1ae8,O,000140,_ZN18CoinCollectEmpty2D6exeGotEv
0x00000071001c1b74,O,000008,_ZNK18CoinCollectEmpty2D23getActorDimensionKeeperEv
0x00000071001c1b7c,O,000008,_ZThn264_NK18CoinCollectEmpty2D23getActorDimensionKeeperEv
0x00000071001c1b84,O,000020,_ZNK12_GLOBAL__N_125CoinCollectEmpty2DNrvWait7executeEPN2al11NerveKeeperE
0x00000071001c1b98,O,000008,_ZNK12_GLOBAL__N_124CoinCollectEmpty2DNrvGot7executeEPN2al11NerveKeeperE
0x00000071001c1ba0,U,000064,_ZN20CoinCollectHintStateC2EPN2al9LiveActorE
0x00000071001c1be0,U,000016,_ZN20CoinCollectHintState4initEv
0x00000071001c1bf0,U,000072,_ZN20CoinCollectHintState6appearEv
Expand Down
10 changes: 10 additions & 0 deletions lib/al/Library/Model/ModelShapeUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <math/seadMatrix.h>

namespace al {
class ModelKeeper;

void setModelProjMtx0(const ModelKeeper*, const sead::Matrix44f&);

} // namespace al
104 changes: 104 additions & 0 deletions src/Item/CoinCollectEmpty2D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#include "Item/CoinCollectEmpty2D.h"

#include <math/seadMatrix.h>
#include <math/seadVector.h>

#include "Library/Collision/PartsConnector.h"
#include "Library/LiveActor/ActorActionFunction.h"
#include "Library/LiveActor/ActorClippingFunction.h"
#include "Library/LiveActor/ActorInitInfo.h"
#include "Library/LiveActor/ActorPoseKeeper.h"
#include "Library/LiveActor/ActorSensorMsgFunction.h"
#include "Library/Matrix/MatrixUtil.h"
#include "Library/Model/ModelShapeUtil.h"
#include "Library/Nerve/NerveSetupUtil.h"
#include "Library/Nerve/NerveUtil.h"

#include "System/GameDataFunction.h"
#include "Util/ActorDimensionKeeper.h"
#include "Util/ActorDimensionUtil.h"
#include "Util/ItemUtil.h"
#include "Util/SensorMsgFunction.h"

namespace {
NERVE_IMPL(CoinCollectEmpty2D, Wait);
NERVE_IMPL(CoinCollectEmpty2D, Got);

struct {
NERVE_MAKE(CoinCollectEmpty2D, Wait);
NERVE_MAKE(CoinCollectEmpty2D, Got);
} NrvCoinCollectEmpty2D;

} // namespace

CoinCollectEmpty2D::CoinCollectEmpty2D(const char* name, const char* archiveName)
: al::LiveActor(name), IUseDimension(), mArchiveName(archiveName) {}

void CoinCollectEmpty2D::init(const al::ActorInitInfo& initInfo) {
al::initActorSceneInfo(this, initInfo);
al::initActorWithArchiveName(this, initInfo, mArchiveName, nullptr);
al::tryAddDisplayOffset(this, initInfo);
mMtxConnector = al::tryCreateMtxConnector(this, initInfo);
mDimensionKeeper = rs::createDimensionKeeper(this);
rs::updateDimensionKeeper(mDimensionKeeper);
rs::snap2DParallelizeFront(this, this, 500.0f);
al::initNerve(this, &NrvCoinCollectEmpty2D.Wait, 0);
al::startAction(this, "Wait");
makeActorAlive();
}

void CoinCollectEmpty2D::initAfterPlacement() {
if (mMtxConnector != nullptr) {
al::attachMtxConnectorToCollision(mMtxConnector, this, false);
}

sead::Matrix44f matrix = sead::Matrix44f::ident;
sead::Vector3f frontDir = sead::Vector3f::zero;
sead::Vector3f upDir = sead::Vector3f::zero;
al::calcFrontDir(&frontDir, this);
al::calcUpDir(&upDir, this);
const sead::Vector2f aDir(100.0f, 100.0f);
al::makeMtxProj(&matrix, aDir, frontDir, upDir);
const sead::Vector3f& objTrans = al::getTrans(this);
matrix.setCol(3, sead::Vector4f(objTrans.x, objTrans.y, objTrans.z, 1.0f));
al::setModelProjMtx0(getModelKeeper(), matrix);
}

bool CoinCollectEmpty2D::receiveMsg(const al::SensorMsg* message, al::HitSensor* other,
al::HitSensor* self) {
if (rs::isMsgItemGet2D(message) && al::isNerve(this, &NrvCoinCollectEmpty2D.Wait)) {
al::invalidateClipping(this);
al::setNerve(this, &NrvCoinCollectEmpty2D.Got);
return 1;
}
return al::isMsgPlayerDisregard(message);
}

void CoinCollectEmpty2D::endClipped() {
rs::syncCoin2DAnimFrame(this, "Wait");
al::LiveActor::endClipped();
}

ActorDimensionKeeper* CoinCollectEmpty2D::getActorDimensionKeeper() const {
return mDimensionKeeper;
}

void CoinCollectEmpty2D::exeWait() {
if (mMtxConnector == nullptr) {
return;
}
al::connectPoseQT(this, mMtxConnector);
}

void CoinCollectEmpty2D::exeGot() {
if (al::isFirstStep(this)) {
al::startAction(this, "Got");
}
if (al::isActionEnd(this)) {
GameDataHolderAccessor gameData(this);
GameDataFunction::addCoin(gameData, 1);
GameDataHolderAccessor gameData2(this);
GameDataFunction::addCoin(gameData2, 1);
kill();
}
}
35 changes: 35 additions & 0 deletions src/Item/CoinCollectEmpty2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "Library/LiveActor/LiveActor.h"

#include "Util/IUseDimension.h"

namespace al {
class ActorInitInfo;
class HitSensor;
class MtxConnector;
class SensorMsg;
} // namespace al

class ActorDimensionKeeper;

class CoinCollectEmpty2D : public al::LiveActor, public IUseDimension {
public:
CoinCollectEmpty2D(const char* name, const char* archiveName);

void init(const al::ActorInitInfo& initInfo) override;
void initAfterPlacement() override;
bool receiveMsg(const al::SensorMsg* message, al::HitSensor* other,
al::HitSensor* self) override;
void endClipped() override;

ActorDimensionKeeper* getActorDimensionKeeper() const override;

void exeWait();
void exeGot();

private:
al::MtxConnector* mMtxConnector = nullptr;
ActorDimensionKeeper* mDimensionKeeper = nullptr;
const char* mArchiveName = nullptr;
};
15 changes: 15 additions & 0 deletions src/Util/ActorDimensionUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <basis/seadTypes.h>

namespace al {
class LiveActor;
} // namespace al

class IUseDimension;

namespace rs {

void snap2DParallelizeFront(al::LiveActor*, const IUseDimension*, f32);

} // namespace rs
1 change: 1 addition & 0 deletions src/Util/SensorMsgFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SensorMsg;

namespace rs {

bool isMsgItemGet2D(const al::SensorMsg* msg);
bool isMsgPlayerDisregardTargetMarker(const al::SensorMsg* msg);

void requestHitReactionToAttacker(const al::SensorMsg*, const al::HitSensor*,
Expand Down

0 comments on commit 2454772

Please sign in to comment.