Cavestory Mod API
CustomPlayerStates.h
Go to the documentation of this file.
1 /*
2  Cavestory Multiplayer API
3  Copyright (C) 2021 Johnny Ledger
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
26 #ifndef CAVESTORY_MOD_API_H_
27 #error "Please include CavestoryModAPI.h before including sub-classes."
28 #endif
29 
30 #include <CSMAPI_begincode.h>
31 
32 #pragma once
33 
37 
38 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
39 
40 // Macros
41 #define NULL_DRAW_FUNC(NAME)
42 #define USE_DRAW_FUNC(NAME) void __DRAW__##NAME(int, int, MYCHAR*, SafeClientInterface*);
43 #define DECLARE_PLAYER_STATE(NAME, CUSTOM_DRAW) void __ACT__##NAME(BOOL, SafeClientInterface*, MYCHAR*, const MYCHAR_PHYSICS*);\
44  unsigned int __ANIMATE__##NAME(BOOL, MYCHAR*, SafeClientInterface*);\
45  static int PLAYER_STATE_##NAME;\
46  CUSTOM_DRAW(NAME)
47 
48 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
49 
50 #define NULL_DRAW_FUNC_IMPLEMENT(NAME) PlayerStates::__ACT__##NAME,\
51  PlayerStates::__ANIMATE__##NAME,\
52  NULL
53 #define USE_DRAW_FUNC_IMPLEMENT(NAME) PlayerStates::__ACT__##NAME,\
54  PlayerStates::__ANIMATE__##NAME,\
55  PlayerStates::__DRAW__##NAME
56 #define IMPLEMENT_PLAYER_STATE(NAME, FLAGS, TRANSMIT_FLAGS, CUSTOM_DRAW, OVERRIDE, ANIMATE_TYPE)\
57  CSM_RegisterPlayerState(\
58  "PLAYER_STATE_" #NAME,\
59  FLAGS,\
60  TRANSMIT_FLAGS,\
61  CUSTOM_DRAW##_IMPLEMENT(NAME),\
62  &PlayerStates::PLAYER_STATE_##NAME,\
63  OVERRIDE,\
64  PlayerStateAnimator_OutputType::PSAOT_##ANIMATE_TYPE\
65  );
66 
67 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
68 
72 #define PROCESS_WATER_SPLASHING()\
73  if (!pMC->ignore_water && !pMC->sprash && (pMC->flag & GMC_flag::gmc_flag_on_water_tile)){\
74  int dir = ((pMC->flag & 0x800) ? 2 : 0);\
75  if ((pMC->flag & 8) == 0 && pMC->ym > 0x200){for (int a = 0; a < 8; a++){int x = pMC->x + (Random(-8, 8) * 0x200);SetNpChar(73, x, pMC->y, pMC->xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - pMC->ym / 2, dir, 0, 0);}PlaySoundObject(56, 1);}\
76  else{if (pMC->xm > 0x200 || pMC->xm < -0x200){for (int a = 0; a < 8; a++){int x = pMC->x + (Random(-8, 8) * 0x200);SetNpChar(73, x, pMC->y, pMC->xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0);}PlaySoundObject(56, 1);}}\
77  pMC->sprash = 1;}\
78  if (!(pMC->flag & 0x100))pMC->sprash = 0;
79 
83 #define PROCESS_MOVEMENT_TILES()\
84  if (pMC->flag & GMC_flag::gmc_flag_in_current_left)\
85  pMC->xm -= 0x88;\
86  if (pMC->flag & GMC_flag::gmc_flag_in_current_up)\
87  pMC->ym -= 0x80;\
88  if (pMC->flag & GMC_flag::gmc_flag_in_current_right)\
89  pMC->xm += 0x88;\
90  if (pMC->flag & GMC_flag::gmc_flag_in_current_down)\
91  pMC->ym += 0x55;
92 
96 #define PROCESS_DAMAGE_TILES()\
97  if (pMC->flag & GMC_flag::gmc_flag_on_damage_tile)\
98  {\
99  if (!CaveNet::Client::IsConnected() || CaveNet::Server::IsHosting())\
100  pInterface->DamagePlayer(10);\
101  }
102 
106 #define LIMIT_VELOCITY(MULT)\
107  if (pMC->ym > (physics->max_move * MULT))\
108  pMC->ym = (physics->max_move * MULT);\
109  if (pMC->ym < -(physics->max_move * MULT))\
110  pMC->ym = -(physics->max_move * MULT);\
111  if (pMC->xm > (physics->max_move * MULT))\
112  pMC->xm = (physics->max_move * MULT);\
113  if (pMC->xm < -(physics->max_move * MULT))\
114  pMC->xm = -(physics->max_move * MULT);
115 
119 #define LIMIT_VELOCITY_NORMAL()\
120  if (pMC->ym > physics->max_move)\
121  pMC->ym = physics->max_move;\
122  if (pMC->ym < -physics->max_move)\
123  pMC->ym = -physics->max_move;\
124  if (pMC->xm > physics->max_move)\
125  pMC->xm = physics->max_move;\
126  if (pMC->xm < -physics->max_move)\
127  pMC->xm = -physics->max_move;
128 
129 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
130 
131 #define IMPLEMENT_PLAYER_STATE_ANIM(NAME) unsigned int PlayerStates::__ANIMATE__##NAME(BOOL bKey, MYCHAR* pMC, SafeClientInterface* pInterface)
132 #define IMPLEMENT_PLAYER_STATE_ACT(NAME) void PlayerStates::__ACT__##NAME(BOOL bKey, SafeClientInterface* pInterface, MYCHAR* pMC, const MYCHAR_PHYSICS* physics)
133 #define IMPLEMENT_PLAYER_STATE_DRAW(NAME) void PlayerStates::__DRAW__##NAME(int iFrameX, int iFrameY, MYCHAR* pMC, SafeClientInterface* pInterface)
134 #define GAMEFLAGS (*pInterface->mGameFlags)
135 #define KEY (*pInterface->mKey)
136 #define KEYTRG (*pInterface->mKeyTrg)
137 #define CLIENT pInterface->mClient
138 #define ARMS_TABLE pInterface->mArms
139 #define SELECTED_WEAPON (*pInterface->mSelectedArms)
140 
141 //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
142 
143 #include <CSMAPI_endcode.h>
144 
146 ///