Debian Codegraph @

Descent3/marker.cpp

raw symbols SCIP
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
19 #include "object.h"
20 #include "marker.h"
21 #include "polymodel.h"
22 #include "player.h"
23 #include "multi.h"
24 #include "game.h"
25 #ifdef _DEBUG
26 #include "AIMain.h"
27 #endif
28
29 int Marker_polynum;
30 int Marker_message = 0;
31
32 char MarkerMessages[MAX_PLAYERS * 2][MAX_MARKER_MESSAGE_LENGTH];
33
34 // Drops a market at the players current position
35 void DropMarker(char *message) {
36 int cur_marker_num;
37
38 #ifdef _DEBUG
39 char teststring[80];
40 strcpy(teststring, message);
41 teststring[8] = '\0';
42
43 if (strcmp("ai debug", teststring) == 0) {
44 sscanf(message, "ai debug %d", &AI_debug_robot_index);
45 mprintf(0, "Debug robot is object index %d\n", AI_debug_robot_index);
46 }
47 #endif
48
49 if (Player_object->type != OBJ_PLAYER)
50 return;
51
52 if (Game_mode & GM_MULTI) {
53 MultiSendRequestForMarker(message);
54 return;
55 }
56
57 int limit = 8;
58
59 if (Players[Player_num].num_markers >= limit) {
60 // Delete the oldest marker
61 int found = -1;
62 float low_time = 999999999.0f;
63 for (int i = 0; i <= Highest_object_index; i++) {
64 if (Objects[i].type == OBJ_MARKER && Objects[i].parent_handle == Player_object->handle &&
65 Objects[i].creation_time < low_time) {
66 found = i;
67 low_time = Objects[i].creation_time;
68 }
69 }
70
71 ASSERT(found != -1);
72
73 ObjDelete(found);
74
75 cur_marker_num = Objects[found].id;
76 } else {
77 cur_marker_num = Players[Player_num].num_markers;
78 Players[Player_num].num_markers++;
79 }
80
81 int objnum = ObjCreate(OBJ_MARKER, cur_marker_num, Player_object->roomnum, &Player_object->pos,
82 &Player_object->orient, Player_object->handle);
83 if (objnum >= 0) {
84 mprintf(0, "Marker %d created!\n", cur_marker_num);
85 strcpy(MarkerMessages[(Player_num * 2) + cur_marker_num], message);
86 } else
87 mprintf(0, "Marker NOT created!\n");
88 }
89
90 // Resets markers before a level stars
91 void ResetMarkers() { Marker_message = 0; }
92
93 // Inits markers at game load
94 void InitMarkers() {
95 Marker_polynum = LoadPolyModel("marker.oof", 0);
96 ASSERT(Marker_polynum >= 0);
97 }