1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010-2019 EDuke32 developers and contributors
4 Copyright (C) 2019 Nuke.YKT
5 
6 This file is part of NBlood.
7 
8 NBlood is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License version 2
10 as published by the Free Software Foundation.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 */
22 //-------------------------------------------------------------------------
23 #pragma once
24 #include "callback.h"
25 
26 enum {
27 kChannelZero                        = 0,
28 kChannelSetTotalSecrets,
29 kChannelSecretFound,
30 kChannelTextOver,
31 kChannelLevelExitNormal,
32 kChannelLevelExitSecret,
33 kChannelModernEndLevelCustom, // custom level end
34 kChannelLevelStart,
35 kChannelLevelStartMatch, // DM and TEAMS
36 kChannelLevelStartCoop,
37 kChannelLevelStartTeamsOnly,
38 kChannelPlayerDeathTeamA            = 15,
39 kChannelPlayerDeathTeamB,
40 /////////////////////////////
41 // channels of players to send commands on
42 kChannelPlayer0                     = 30,
43 kChannelPlayer1,
44 kChannelPlayer2,
45 kChannelPlayer3,
46 kChannelPlayer4,
47 kChannelPlayer5,
48 kChannelPlayer6,
49 kChannelPlayer7,
50 kChannelAllPlayers                  = kChannelPlayer0 + kMaxPlayers,
51 // channel of event causer
52 kChannelEventCauser                 = 50,
53 // map requires modern features to work properly
54 kChannelMapModernize                = 60,
55 /////////////////////////////
56 kChannelTeamAFlagCaptured           = 80,
57 kChannelTeamBFlagCaptured,
58 kChannelRemoteBomb0                 = 90,
59 kChannelRemoteBomb1,
60 kChannelRemoteBomb2,
61 kChannelRemoteBomb3,
62 kChannelRemoteBomb4,
63 kChannelRemoteBomb5,
64 kChannelRemoteBomb6,
65 kChannelRemoteBomb7,
66 kChannelUser                        = 100,
67 kChannelUserMax                     = 1024,
68 kChannelMax                         = 4096,
69 };
70 
71 struct RXBUCKET
72 {
73     unsigned int index : 14;
74     unsigned int type : 3;
75 };
76 extern RXBUCKET rxBucket[];
77 extern unsigned short bucketHead[];
78 
79 enum COMMAND_ID {
80 kCmdOff                     = 0,
81 kCmdOn                      = 1,
82 kCmdState                   = 2,
83 kCmdToggle                  = 3,
84 kCmdNotState                = 4,
85 kCmdLink                    = 5,
86 kCmdLock                    = 6,
87 kCmdUnlock                  = 7,
88 kCmdToggleLock              = 8,
89 kCmdStopOff                 = 9,
90 kCmdStopOn                  = 10,
91 kCmdStopNext                = 11,
92 kCmdCounterSector           = 12,
93 kCmdCallback                = 20,
94 kCmdRepeat                  = 21,
95 
96 
97 kCmdSpritePush              = 30,
98 kCmdSpriteImpact            = 31,
99 kCmdSpritePickup            = 32,
100 kCmdSpriteTouch             = 33,
101 kCmdSpriteSight             = 34,
102 kCmdSpriteProximity         = 35,
103 kCmdSpriteExplode           = 36,
104 
105 kCmdSectorPush              = 40,
106 kCmdSectorImpact            = 41,
107 kCmdSectorEnter             = 42,
108 kCmdSectorExit              = 43,
109 
110 kCmdWallPush                = 50,
111 kCmdWallImpact              = 51,
112 kCmdWallTouch               = 52,
113 #ifdef NOONE_EXTENSIONS
114 kCmdSectorMotionPause       = 13,   // stops motion of the sector
115 kCmdSectorMotionContinue    = 14,   // continues motion of the sector
116 kCmdDudeFlagsSet            = 15,   // copy dudeFlags from sprite to dude
117 kCmdModernUse               = 53,   // used by most of modern types
118 #endif
119 
120 kCmdNumberic                = 64, // 64: 0, 65: 1 and so on up to 255
121 kCmdModernFeaturesEnable    = 100, // must be in object with kChannelMapModernize RX / TX
122 kCmdModernFeaturesDisable   = 200, // must be in object with kChannelMapModernize RX / TX
123 kCmdNumbericMax             = 255,
124 };
125 
playerRXRngIsFine(int rx)126 inline bool playerRXRngIsFine(int rx) {
127     return (rx >= kChannelPlayer0 && rx < kChannelPlayer7);
128 }
129 
channelRangeIsFine(int channel)130 inline bool channelRangeIsFine(int channel) {
131     return (channel >= kChannelUser && channel < kChannelUserMax);
132 }
133 
134 struct EVENT {
135     unsigned int index:     14; // index
136     unsigned int type:      3; // type
137     unsigned int cmd:       8; // cmd
138     unsigned int funcID:    8; // callback
139 };
140 
141 void evInit(void);
142 char evGetSourceState(int nType, int nIndex);
143 void evSend(int nIndex, int nType, int rxId, COMMAND_ID command);
144 void evPost(int nIndex, int nType, unsigned int nDelta, COMMAND_ID command);
145 void evPost(int nIndex, int nType, unsigned int nDelta, CALLBACK_ID callback);
146 void evProcess(unsigned int nTime);
147 void evKill(int a1, int a2);
148 void evKill(int a1, int a2, CALLBACK_ID a3);