Lots of changes; notes coming soon.
[asgard.git] / Database.cpp
blobfc801946d14da80dedbba1ae66dbc24ee69af684
1 /*****************************************************************************
2 * Copyright (c) 2007 Russ Adams, Sean Eubanks, Asgard Contributors
3 * This file is part of Asgard.
4 *
5 * Asgard 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 2 of the License, or
8 * (at your option) any later version.
10 * Asgard 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.
15 * You should have received a copy of the GNU General Public License
16 * along with Asgard; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 ****************************************************************************/
20 #include <cassert>
21 #include "Database.h"
22 #include "MapObjectFactory.h"
23 #include "MapObjectType.h"
24 #include "QueryGenerator.h"
25 #include "DatabaseColumnMap.h"
26 #include "GameEngine.h"
28 Database* Database::instance = NULL;
30 Database::Database()
32 int status = sqlite3_open(ASGARD_DATABASE, &this->asgardDb);
34 if(status != SQLITE_OK)
36 sqlite3_close(this->asgardDb);
39 // TODO: Add some type of logging for status
42 Database::~Database()
44 sqlite3_close(this->asgardDb);
47 Database* Database::getInstance()
49 if(instance == NULL) instance = new Database();
50 return instance;
53 void Database::determineVisibleBoxes(Coordinate currentPosition, int *visibleBoxes, int numVisibleBoxes)
58 bool Database::loadBoundingBox(int boxId)
60 char **sqliteErrorCode;
62 sqlite3_exec(this->asgardDb, QueryGenerator::container(boxId), MapObjectFactory::processRow, (void*)(MAP_OBJECT_TYPE_CONTAINER), sqliteErrorCode);
63 sqlite3_exec(this->asgardDb, QueryGenerator::nonPlayerCharacter(boxId), MapObjectFactory::processRow, (void*)MAP_OBJECT_TYPE_NON_PLAYER_CHARACTER, sqliteErrorCode);
64 sqlite3_exec(this->asgardDb, QueryGenerator::staticMapObject(boxId), MapObjectFactory::processRow, (void*)MAP_OBJECT_TYPE_STATIC_MAP_OBJECT, sqliteErrorCode);
65 sqlite3_exec(this->asgardDb, QueryGenerator::tile(boxId), MapObjectFactory::processRow, (void*)MAP_OBJECT_TYPE_TILE, sqliteErrorCode);
67 return true;
70 char*** Database::loadHardpoints(int smoId)
72 char*** table = NULL;
73 int* numRows;
74 int* numColumns;
75 char** sqliteErrorCode;
77 sqlite3_get_table(this->asgardDb, QueryGenerator::hardpoint(smoId), table, numRows, numColumns, sqliteErrorCode);
79 assert(*numColumns == CONTAINER_COLUMN_COUNT);
81 return table;
84 char*** Database::loadNonPlayerCharacterPath(int npcId)
86 char*** table = NULL;
87 int* numRows;
88 int* numColumns;
89 char** sqliteErrorCode;
91 sqlite3_get_table(this->asgardDb, QueryGenerator::nonPlayerCharacterPath(npcId), table, numRows, numColumns, sqliteErrorCode);
93 assert(*numColumns == HARDPOINT_COLUMN_COUNT);
95 return table;