Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 134 lines (108 sloc) 4.517 kB
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
1 /*
2 * Illarionserver - server for the game Illarion
3 * Copyright 2011 Illarion e.V.
4 *
5 * This file is part of Illarionserver.
6 *
7 * Illarionserver is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option) any
10 * later version.
11 *
12 * Illarionserver is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * Illarionserver. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "data/TilesTable.hpp"
22
23 #include <iostream>
24 #include <string>
25
26 #include "db/SelectQuery.hpp"
27 #include "db/Result.hpp"
28
c81ac7e removed prefix C from files, changed all headers to hpp files
vilarion authored
29 #include "script/LuaTileScript.hpp"
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
30
c81ac7e removed prefix C from files, changed all headers to hpp files
vilarion authored
31 #include "constants.hpp"
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
32 #include "TableStructs.hpp"
c81ac7e removed prefix C from files, changed all headers to hpp files
vilarion authored
33 #include "Logger.hpp"
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
34
32dbcd3 removed prefix C from class names
vilarion authored
35 TilesTable::TilesTable() : m_dataOK(false) {
3a4253e @vilarion Create a formatting ruleset
authored
36 reload();
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
37 }
38
39
32dbcd3 removed prefix C from class names
vilarion authored
40 void TilesTable::reload() {
41 #ifdef DataConnect_DEBUG
3a4253e @vilarion Create a formatting ruleset
authored
42 std::cout << "TilesTable: reload" << std::endl;
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
43 #endif
44
3a4253e @vilarion Create a formatting ruleset
authored
45 try {
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
46 Database::SelectQuery query;
47 query.addColumn("tiles", "til_id");
48 query.addColumn("tiles", "til_isnotpassable");
49 query.addColumn("tiles", "til_isnottransparent");
50 query.addColumn("tiles", "til_isnotpenetrateable");
51 query.addColumn("tiles", "til_specialtile");
52 query.addColumn("tiles", "til_groundlevel");
53 query.addColumn("tiles", "til_german");
54 query.addColumn("tiles", "til_english");
55 query.addColumn("tiles", "til_french");
56 query.addColumn("tiles", "til_walkingcost");
57 query.addColumn("tiles", "til_script");
58 query.addServerTable("tiles");
59
60 Database::Result results = query.execute();
61
62 if (!results.empty()) {
3a4253e @vilarion Create a formatting ruleset
authored
63 clearOldTable();
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
64 TilesStruct temprecord;
65 std::string scriptname;
66 TYPE_OF_ITEM_ID tileId;
67
8aa410f @vilarion fixing some typedefs in Result.hpp
authored
68 for (Database::ResultConstIterator itr = results.begin();
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
69 itr != results.end(); ++itr) {
70 tileId = (*itr)["til_id"].as<TYPE_OF_ITEM_ID>();
71 temprecord.flags = (uint8_t)((*itr)["til_groundlevel"].as<uint16_t>());
72 temprecord.flags |= (*itr)["til_isnotpassable"].as<bool>() ? FLAG_PASSABLE : 0;
73 temprecord.flags |= (*itr)["til_isnottransparent"].as<bool>() ? FLAG_TRANSPARENT : 0;
74 temprecord.flags |= (*itr)["til_isnotpenetrateable"].as<bool>() ? FLAG_TRANSPARENT : 0;
75 temprecord.flags |= (*itr)["til_specialtile"].as<bool>() ? FLAG_SPECIALITEM : 0;
76 temprecord.German = (*itr)["til_german"].as<std::string>();
77 temprecord.English = (*itr)["til_english"].as<std::string>();
78 temprecord.French = (*itr)["til_french"].as<std::string>();
79 temprecord.walkingCost = (TYPE_OF_WALKINGCOST)((*itr)["til_walkingcost"].as<int16_t>());
80
81 if (!(*itr)["til_script"].is_null()) {
82 scriptname = (*itr)["til_script"].as<std::string>();
83
84 if (!scriptname.empty()) {
85 try {
86 boost::shared_ptr<LuaTileScript> script(new LuaTileScript(scriptname, temprecord));
87 temprecord.script = script;
88 } catch (ScriptException &e) {
402ca45 @vilarion make script loading errors more verbose
authored
89 Logger::writeError("scripts", "Error while loading tiles script: " + scriptname + ":\n" + e.what() + "\n");
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
90 }
3a4253e @vilarion Create a formatting ruleset
authored
91 }
92 }
93
748c227 @mkaring Implemented new database interface to the tiles table
mkaring authored
94 m_table[tileId] = temprecord;
3a4253e @vilarion Create a formatting ruleset
authored
95 }
96
97 m_dataOK = true;
98 } else {
99 m_dataOK = false;
100 }
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
101
102
32dbcd3 removed prefix C from class names
vilarion authored
103 #ifdef DataConnect_DEBUG
3a4253e @vilarion Create a formatting ruleset
authored
104 std::cout << "loaded " << rows << " rows into TilesTable" << std::endl;
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
105 #endif
106
3a4253e @vilarion Create a formatting ruleset
authored
107 } catch (std::exception &e) {
108 std::cout << "exception in tiles loading: " << e.what() << std::endl;
109 m_dataOK = false;
110 }
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
111
112
113 }
114
3a4253e @vilarion Create a formatting ruleset
authored
115 bool TilesTable::find(TYPE_OF_ITEM_ID Id, TilesStruct &ret) {
116 TABLE::iterator iterator;
117 iterator = m_table.find(Id);
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
118
3a4253e @vilarion Create a formatting ruleset
authored
119 if (iterator == m_table.end()) {
120 return false;
121 } else {
122 ret = (*iterator).second;
123 return true;
124 }
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
125 }
126
32dbcd3 removed prefix C from class names
vilarion authored
127 void TilesTable::clearOldTable() {
3a4253e @vilarion Create a formatting ruleset
authored
128 m_table.clear();
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
129 }
130
32dbcd3 removed prefix C from class names
vilarion authored
131 TilesTable::~TilesTable() {
3a4253e @vilarion Create a formatting ruleset
authored
132 clearOldTable();
b834c3d @vilarion Loading transitional server version 0.8.5 into git
authored
133 }
Something went wrong with that request. Please try again.