1 /*****************************************************************************
2 * Copyright (c) 2007 Russ Adams, Sean Eubanks, Asgard Contributors
3 * This file is part of Asgard.
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 ****************************************************************************/
22 #include "MapObjectFactory.h"
23 #include "MapObjectType.h"
24 #include "QueryGenerator.h"
25 #include "DatabaseColumnMap.h"
26 #include "GameEngine.h"
29 Database
* Database::instance
= NULL
;
33 int status
= sqlite3_open(ASGARD_DATABASE
, &this->asgardDb
);
35 if(status
!= SQLITE_OK
)
37 sqlite3_close(this->asgardDb
);
40 // TODO: Add some type of logging for status
45 sqlite3_close(this->asgardDb
);
48 Database
* Database::getInstance()
50 if(instance
== NULL
) instance
= new Database();
54 void Database::determineVisibleBoxes(Coordinate currentPosition
, int *visibleBoxes
, int numVisibleBoxes
)
56 // Map as of 0.3.0 is 1 boundbox, 0.
60 bool Database::loadBoundingBox(int boxId
)
64 char *sqliteErrorCode
;
66 // Invalid Bounding Box
71 query
= QueryGenerator::nonPlayerCharacter(boxId
);
72 type
= MAP_OBJECT_TYPE_NON_PLAYER_CHARACTER
;
73 sqlite3_exec(this->asgardDb
, query
, MapObjectFactory::processRow
, (void*)&type
, &sqliteErrorCode
);
77 query
= QueryGenerator::container(boxId
);
78 type
= MAP_OBJECT_TYPE_CONTAINER
;
79 sqlite3_exec(this->asgardDb
, query
, MapObjectFactory::processRow
, (void*)&type
, &sqliteErrorCode
);
83 query
= QueryGenerator::staticMapObject(boxId
);
84 type
= MAP_OBJECT_TYPE_STATIC_MAP_OBJECT
;
85 sqlite3_exec(this->asgardDb
, query
, MapObjectFactory::processRow
, (void*)&type
, &sqliteErrorCode
);
89 query
= QueryGenerator::tile(boxId
);
90 type
= MAP_OBJECT_TYPE_TILE
;
91 sqlite3_exec(this->asgardDb
, query
, MapObjectFactory::processRow
, (void*)&type
, &sqliteErrorCode
);
94 sqlite3_free(sqliteErrorCode
);
99 RowSet
* Database::loadHardpoints(int smoId
)
101 RowSet
* rs
= new RowSet();
105 query
= QueryGenerator::hardpoint(smoId
);
106 rc
= rs
->select(this->asgardDb
, query
);
111 assert(rs
->getColCount() == HARDPOINT_COLUMN_COUNT
);
117 RowSet
* Database::loadNonPlayerCharacterPath(int npcId
)
119 RowSet
* rs
= new RowSet();
123 query
= QueryGenerator::nonPlayerCharacterPath(npcId
);
124 rc
= rs
->select(this->asgardDb
, query
);
129 assert(rs
->getColCount() == NON_PLAYER_CHARACTER_PATH_COLUMN_COUNT
);