| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/entropy/EntropyPackets.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003/08/26 03:57:41 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * <insert description of file here> |
| 26 | * |
| 27 | * $Log: EntropyPackets.cpp,v $ |
| 28 | * Revision 1.1.1.1 2003/08/26 03:57:41 kevinb |
| 29 | * initial 1.5 import |
| 30 | * |
| 31 | * |
| 32 | * 10 5/21/99 10:03a Jeff |
| 33 | * hopefully filled in any remaining gaps related to have more than you |
| 34 | * can carry virus loads |
| 35 | * |
| 36 | * 9 5/12/99 11:04p Jeff |
| 37 | * dmfc and multiplayer games now have endian friendly packets (*whew*) |
| 38 | * |
| 39 | * 8 5/12/99 11:28a Jeff |
| 40 | * added sourcesafe comment block |
| 41 | * |
| 42 | * $NoKeywords: $ |
| 43 | */ |
| 44 | |
| 45 | #include "gamedll_header.h" |
| 46 | #include <string.h> |
| 47 | #include "idmfc.h" |
| 48 | #include "Entropystr.h" |
| 49 | #include "EntropyAux.h" |
| 50 | |
| 51 | extern IDMFC *DMFCBase; |
| 52 | extern room *dRooms; |
| 53 | extern object *dObjects; |
| 54 | |
| 55 | void SendTakeOverPacket(int newteam, int oldteam, int room, int victor) { |
| 56 | int count = 0; |
| 57 | |
| 58 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 59 | DMFCBase->StartPacket(data, SPID_TAKEOVER, &count); |
| 60 | |
| 61 | MultiAddByte(newteam, data, &count); |
| 62 | MultiAddByte(oldteam, data, &count); |
| 63 | MultiAddByte(victor, data, &count); |
| 64 | MultiAddInt(room, data, &count); |
| 65 | |
| 66 | DMFCBase->SendPacket(data, count, SP_ALL); |
| 67 | } |
| 68 | |
| 69 | void ReceiveTakeOverPacket(uint8_t *data) { |
| 70 | uint8_t newteam, oldteam; |
| 71 | int room; |
| 72 | int count = 0; |
| 73 | int victor; |
| 74 | |
| 75 | newteam = MultiGetByte(data, &count); |
| 76 | oldteam = MultiGetByte(data, &count); |
| 77 | victor = MultiGetByte(data, &count); |
| 78 | room = MultiGetInt(data, &count); |
| 79 | TakeOverRoom(newteam, oldteam, room, victor); |
| 80 | } |
| 81 | |
| 82 | // Handles when we get a new player packet |
| 83 | void GetGameStartPacket(uint8_t *data) { |
| 84 | int i, count = 0; |
| 85 | |
| 86 | for (i = 0; i < DLLMAX_PLAYERS; i++) { |
| 87 | if (MultiGetByte(data, &count)) { |
| 88 | NumberOfKillsSinceLastDeath[i] = MultiGetInt(data, &count); |
| 89 | int num_virus = MultiGetInt(data, &count); |
| 90 | int v_count; |
| 91 | RemoveVirusFromPlayer(i, true); |
| 92 | |
| 93 | for (v_count = 0; v_count < num_virus; v_count++) { |
| 94 | DLLInvAddTypeID(i, OBJ_POWERUP, virus_id, -1, -1, 0, TXT_VIRUS); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | for (i = 0; i < NUM_TEAMS; i++) { |
| 100 | TeamScore[i] = MultiGetInt(data, &count); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Handles sending a new player packet |
| 105 | void SendGameStartPacket(int pnum) { |
| 106 | int count = 0; |
| 107 | int i; |
| 108 | |
| 109 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 110 | DMFCBase->StartPacket(data, SPID_NEWPLAYER, &count); |
| 111 | |
| 112 | for (i = 0; i < DLLMAX_PLAYERS; i++) { |
| 113 | if (DMFCBase->CheckPlayerNum(i)) { |
| 114 | MultiAddByte(1, data, &count); |
| 115 | MultiAddInt(NumberOfKillsSinceLastDeath[i], data, &count); |
| 116 | MultiAddInt(DLLInvGetTypeIDCount(i, OBJ_POWERUP, virus_id), data, &count); |
| 117 | } else { |
| 118 | MultiAddByte(0, data, &count); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | for (i = 0; i < NUM_TEAMS; i++) { |
| 123 | MultiAddInt(TeamScore[i], data, &count); |
| 124 | } |
| 125 | |
| 126 | DMFCBase->SendPacket(data, count, pnum); |
| 127 | |
| 128 | // send over the rest |
| 129 | SendRoomInfo(pnum); |
| 130 | } |
| 131 | |
| 132 | void SendClientPickupVirus(int player_num) { |
| 133 | int start, count = 0; |
| 134 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 135 | DMFCBase->StartPacket(data, SPID_PICKUPVIRUS, &count); |
| 136 | start = count; |
| 137 | |
| 138 | MultiAddByte(player_num, data, &count); |
| 139 | ReceivePickupVirus(&data[start]); |
| 140 | DMFCBase->SendPacket(data, count, SP_ALL); |
| 141 | } |
| 142 | |
| 143 | void ReceivePickupVirus(uint8_t *data) { |
| 144 | int player_num, count = 0; |
| 145 | player_num = MultiGetByte(data, &count); |
| 146 | |
| 147 | DLLInvAddTypeID(player_num, OBJ_POWERUP, virus_id, -1, -1, 0, TXT_VIRUS); |
| 148 | |
| 149 | if (player_num == DMFCBase->GetPlayerNum()) { |
| 150 | DLLAddHUDMessage(TXT_PICKUPVIRUS); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | #define RT_REDLAB 0 |
| 155 | #define RT_REDREP 1 |
| 156 | #define RT_REDENG 2 |
| 157 | #define RT_BLULAB 3 |
| 158 | #define RT_BLUREP 4 |
| 159 | #define RT_BLUENG 5 |
| 160 | |
| 161 | // MTS: only used in this file. |
| 162 | void SendRoomInfo(int pnum) { |
| 163 | char *room_info = NULL; |
| 164 | int flags, r, i; |
| 165 | room_info = (char *)malloc(sizeof(char) * RoomCount); |
| 166 | if (!room_info) |
| 167 | return; |
| 168 | |
| 169 | for (r = 0; r < RoomCount; r++) { |
| 170 | flags = dRooms[RoomList[r]].flags; |
| 171 | |
| 172 | if (flags & RF_SPECIAL1) { |
| 173 | room_info[r] = RT_REDLAB; |
| 174 | } |
| 175 | if (flags & RF_SPECIAL2) { |
| 176 | room_info[r] = RT_REDENG; |
| 177 | } |
| 178 | if (flags & RF_SPECIAL3) { |
| 179 | room_info[r] = RT_REDREP; |
| 180 | } |
| 181 | if (flags & RF_SPECIAL4) { |
| 182 | room_info[r] = RT_BLULAB; |
| 183 | } |
| 184 | if (flags & RF_SPECIAL5) { |
| 185 | room_info[r] = RT_BLUENG; |
| 186 | } |
| 187 | if (flags & RF_SPECIAL6) { |
| 188 | room_info[r] = RT_BLUREP; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | int count = 0; |
| 193 | |
| 194 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 195 | DMFCBase->StartPacket(data, SPID_ROOMINFO, &count); |
| 196 | |
| 197 | for (i = 0; i < RoomCount; i++) { |
| 198 | MultiAddByte(room_info[i], data, &count); |
| 199 | } |
| 200 | |
| 201 | for (i = 0; i < NUM_TEAMS; i++) { |
| 202 | MultiAddInt(TeamOwnedRooms[i], data, &count); |
| 203 | } |
| 204 | |
| 205 | DMFCBase->SendPacket(data, count, pnum); |
| 206 | |
| 207 | free(room_info); |
| 208 | } |
| 209 | |
| 210 | void ReceiveRoomInfo(uint8_t *data) { |
| 211 | int i, count = 0; |
| 212 | int flag; |
| 213 | char *room_info; |
| 214 | room_info = (char *)malloc(sizeof(char) * RoomCount); |
| 215 | if (!room_info) { |
| 216 | FatalError("Out of Memory"); |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | for (i = 0; i < RoomCount; i++) { |
| 221 | room_info[i] = MultiGetByte(data, &count); |
| 222 | |
| 223 | switch (room_info[i]) { |
| 224 | case RT_REDLAB: |
| 225 | flag = RF_SPECIAL1; |
| 226 | PaintRoomWithTexture(LabText[RED_TEAM], RoomList[i]); |
| 227 | break; |
| 228 | case RT_REDENG: |
| 229 | flag = RF_SPECIAL2; |
| 230 | PaintRoomWithTexture(EnergyText[RED_TEAM], RoomList[i]); |
| 231 | break; |
| 232 | case RT_REDREP: |
| 233 | flag = RF_SPECIAL3; |
| 234 | PaintRoomWithTexture(RepairText[RED_TEAM], RoomList[i]); |
| 235 | break; |
| 236 | case RT_BLULAB: |
| 237 | flag = RF_SPECIAL4; |
| 238 | PaintRoomWithTexture(LabText[BLUE_TEAM], RoomList[i]); |
| 239 | break; |
| 240 | case RT_BLUENG: |
| 241 | flag = RF_SPECIAL5; |
| 242 | PaintRoomWithTexture(EnergyText[BLUE_TEAM], RoomList[i]); |
| 243 | break; |
| 244 | case RT_BLUREP: |
| 245 | flag = RF_SPECIAL6; |
| 246 | PaintRoomWithTexture(RepairText[BLUE_TEAM], RoomList[i]); |
| 247 | break; |
| 248 | default: |
| 249 | flag = 0; |
| 250 | } |
| 251 | room *rp = &dRooms[RoomList[i]]; |
| 252 | rp->flags &= ~RF_SPECIAL1; |
| 253 | rp->flags &= ~RF_SPECIAL2; |
| 254 | rp->flags &= ~RF_SPECIAL3; |
| 255 | rp->flags &= ~RF_SPECIAL4; |
| 256 | rp->flags &= ~RF_SPECIAL5; |
| 257 | rp->flags &= ~RF_SPECIAL6; |
| 258 | rp->flags |= flag; |
| 259 | rp->room_change_flags |= RCF_GOALSPECIAL_FLAGS; |
| 260 | } |
| 261 | free(room_info); |
| 262 | |
| 263 | for (i = 0; i < NUM_TEAMS; i++) { |
| 264 | TeamOwnedRooms[i] = MultiGetInt(data, &count); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | void SendVirusCreate(object *obj) { |
| 269 | int start, count = 0; |
| 270 | |
| 271 | uint8_t data[MAX_GAME_DATA_SIZE]; |
| 272 | DMFCBase->StartPacket(data, SPID_VIRUSCREATE, &count); |
| 273 | start = count; |
| 274 | |
| 275 | int objnum = obj - dObjects; |
| 276 | MultiAddInt(objnum, data, &count); |
| 277 | DoVirusCreate(&data[start]); |
| 278 | DMFCBase->SendPacket(data, count, SP_ALL); |
| 279 | } |
| 280 | |
| 281 | void DoVirusCreate(uint8_t *data) { |
| 282 | int s_objnum, l_objnum, count = 0; |
| 283 | |
| 284 | s_objnum = MultiGetInt(data, &count); |
| 285 | |
| 286 | l_objnum = DMFCBase->ConvertServerToLocalObjnum(s_objnum); |
| 287 | |
| 288 | if (l_objnum != -1) { |
| 289 | DLLCreateRandomSparks(rand() % 150 + 100, &dObjects[l_objnum].pos, dObjects[l_objnum].roomnum, HOT_SPARK_INDEX, |
| 290 | (rand() % 3) + 2); |
| 291 | } |
| 292 | } |