1 /* bzflag
2 * Copyright (c) 1993-2021 Tim Riker
3 *
4 * This package is free software; you can redistribute it and/or
5 * modify it under the terms of the license found in the file
6 * named COPYING that should have accompanied this file.
7 *
8 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 */
12
13 /* interface header */
14 #include "CustomWorld.h"
15
16 /* system implementation headers */
17 #include <string.h>
18
19 /* common implementation headers */
20 #include "StateDatabase.h"
21 #include "BZDBCache.h"
22 #include "TextUtils.h"
23
24
CustomWorld()25 CustomWorld::CustomWorld()
26 {
27 // initialize with database defaults
28 _size = BZDBCache::worldSize;
29 _fHeight = BZDB.eval(StateDatabase::BZDB_FLAGHEIGHT);
30 }
31
32
read(const char * cmd,std::istream & input)33 bool CustomWorld::read(const char *cmd, std::istream& input)
34 {
35 if (strcasecmp(cmd, "size") == 0)
36 {
37 input >> _size;
38 _size *= 2.0;
39 BZDB.set(StateDatabase::BZDB_WORLDSIZE, TextUtils::format("%f", _size));
40 }
41 else if (strcasecmp(cmd, "flagHeight") == 0)
42 {
43 input >> _fHeight;
44 BZDB.set(StateDatabase::BZDB_FLAGHEIGHT, TextUtils::format("%f", _fHeight));
45 }
46 else if (strcasecmp(cmd, "noWalls") == 0)
47 BZDB.setBool("noWalls", true);
48 else if (strcasecmp(cmd, "freeCtfSpawns") == 0)
49 BZDB.setBool("freeCtfSpawns", true);
50 else
51 return WorldFileObject::read(cmd, input);
52 return true;
53 }
54
55
writeToWorld(WorldInfo *) const56 void CustomWorld::writeToWorld(WorldInfo*) const
57 {
58 }
59
60 std::map<std::string,bz_CustomMapObjectHandler*> customObjectMap;
61
registerCustomMapObject(const char * object,bz_CustomMapObjectHandler * handler)62 void registerCustomMapObject ( const char* object, bz_CustomMapObjectHandler *handler )
63 {
64 std::string objectName = object;
65
66 customObjectMap[TextUtils::toupper(objectName)] = handler;
67 }
68
removeCustomMapObject(const char * object)69 void removeCustomMapObject ( const char* object )
70 {
71 std::string objectName = object;
72
73 if ( customObjectMap.find(TextUtils::toupper(objectName)) != customObjectMap.end() )
74 customObjectMap.erase(customObjectMap.find(TextUtils::toupper(objectName)));
75 }
76
77 // Local variables: ***
78 // mode: C++ ***
79 // tab-width: 4***
80 // c-basic-offset: 4 ***
81 // indent-tabs-mode: nil ***
82 // End: ***
83 // ex: shiftwidth=4 tabstop=4
84