-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBATMaps.cpp
161 lines (136 loc) · 4.4 KB
/
BATMaps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* ======== Basic Admin tool ========
* Copyright (C) 2004-2007 Erling K. Sæterdal
* No warranties of any kind
*
* License: zlib/libpng
*
* Author(s): Erling K. Sæterdal ( EKS )
* Credits:
* Menu code based on code from CSDM ( http://www.tcwonline.org/~dvander/cssdm ) Created by BAILOPAN
* Helping on misc errors/functions: BAILOPAN,karma,LDuke,sslice,devicenull,PMOnoTo,cybermind ( most who idle in #sourcemod on GameSurge realy )
* ============================ */
#include "BATCore.h"
#include "BATMaps.h"
#include "const.h"
//#include "convar.h"
#include "sh_string.h"
#include <sh_vector.h>
char g_CurrentMapName[MAX_MAPNAMELEN+1];
SourceHook::CVector<MapStuct *>g_MapList;
SourceHook::CVector<MapsVotesStruct *>g_VotesOnMap;
int g_MapCount=0;
int g_CurrentMapIndex;
int g_NextMapIndex;
char g_NextMapName[MAX_MAPNAMELEN+1]; // Used if the map is out of mapcycle
void BATMaps::LoadMapFiles()
{
char TempMapCycle[256],TempAdminMaps[256],TempVoteMaps[256] ,tdir[256]; //This gets the actual path to the users.ini file.
g_BATCore.GetEngine()->GetGameDir(tdir,255);
_snprintf(TempMapCycle,255,"%s/%s",tdir,g_BATCore.GetBATVar().GetCvarString("mapcyclefile"));
FILE *fMapCycleFile = fopen(TempMapCycle,"rt");
g_BATCore.GetFilePath(FILE_VOTEMAP,TempVoteMaps);
FILE *fVoteMaps = fopen(TempVoteMaps,"rt");
g_BATCore.GetFilePath(FILE_ADMINMAPS,TempAdminMaps);
FILE *fAdminMaps = fopen(TempAdminMaps,"rt");
if (!fMapCycleFile)
{
g_BATCore.AddLogEntry("ERROR! Unable to find mapcycle file, should be in ( %s )",TempMapCycle);
}
if (!fAdminMaps)
{
g_BATCore.AddLogEntry("ERROR! Unable to find admin map file, should be in ( %s )",TempAdminMaps);
}
if (!fVoteMaps)
{
g_BATCore.AddLogEntry("ERROR! Unable to find vote map file, should be in ( %s )",TempVoteMaps);
}
int LastMapCount = g_MapCount;
g_MapCount = 0;
if(fMapCycleFile)
ReadFile(fMapCycleFile,MAPTYPE_MAPCYCLEMAP);
if(fVoteMaps)
ReadFile(fVoteMaps,MAPTYPE_VOTEMAP);
if(fAdminMaps)
ReadFile(fAdminMaps,MAPTYPE_ADMINMAP);
g_BATCore.AddLogEntry("Loaded a total of %d maps from mapcycle",g_MapCount);
}
void BATMaps::ReadFile(FILE *in,_MapType MapType)
{
char line[256];
int LineLen=0;
while (!feof(in))
{
line[0] = '\0';
fgets(line,255,in);
LineLen = strlen(line);
if (line[0] == '\0' ||line[0] == '/' || line[0] == ';' || LineLen <= 2)
continue;
if(g_MapCount >= (int)g_MapList.size()-1 || g_MapList.size() == 0)
{
g_MapList.push_back(new MapStuct);
g_VotesOnMap.push_back(new MapsVotesStruct);
}
_snprintf(g_MapList[g_MapCount]->MapName,MAX_MAPNAMELEN,"%s",line);
g_BATCore.StrTrim(g_MapList[g_MapCount]->MapName);
if(g_BATCore.GetEngine()->IsMapValid(g_MapList[g_MapCount]->MapName))
{
#if BAT_DEBUG == 1
g_BATCore.ServerCommand("echo Debug - %d)Added map '%s' to %s",g_MapCount,g_MapList[g_MapCount]->MapName,GetMapTypeName(MapType));
#endif
if( GetMapIndex(g_MapList[g_MapCount]->MapName) != -1)
{
int MapIndex = GetMapIndex(g_MapList[g_MapCount]->MapName);
g_BATCore.AddLogEntry("Warning: %s is in %s and %s duplicate entries are ignored",g_MapList[g_MapCount]->MapName,GetMapTypeName(MapType),GetMapTypeName(g_MapList[MapIndex]->MapType));
return;
}
g_MapList[g_MapCount]->MapType = MapType;
g_MapList[g_MapCount]->TextLen = strlen(g_MapList[g_MapCount]->MapName);
g_MapCount++;
}
else
g_BATCore.AddLogEntry("'%s' is not a valid map was in %s",g_MapList[g_MapCount]->MapName,GetMapTypeName(MapType));
}
fclose(in);
}
int BATMaps::GetMapIndex(const char *CurMap)
{
int TextLen = strlen(CurMap);
for(int i=0;i<g_MapCount;i++)
{
if(TextLen == g_MapList[i]->TextLen && strcmp(CurMap,g_MapList[i]->MapName) == 0)
return i;
}
return -1;
}
const char *BATMaps::GetMapTypeName(int MapType)
{
switch(MapType)
{
case MAPTYPE_MAPCYCLEMAP:
return "mapcycle file";
case MAPTYPE_ADMINMAP:
return "adminmaps.ini";
case MAPTYPE_VOTEMAP:
return "votemaps.ini";
}
return "ERROR Faulty Maptype";
}
int BATMaps::GetNextmap()
{
if(g_MapCount == 0)
return 0;
int NextMap = g_CurrentMapIndex + 1;
if(NextMap == g_MapCount)
NextMap = 0;
int CPS=0;
while(g_MapList[NextMap]->MapType != MAPTYPE_MAPCYCLEMAP)
{
NextMap++;
CPS++;
if(NextMap == g_MapCount)
NextMap = 0;
if(CPS == g_MapCount)
return 0;
}
return NextMap;
}