From 070e367ca161882f69e80a0df1f98644dc5c98e9 Mon Sep 17 00:00:00 2001 From: rustushki Date: Thu, 13 Sep 2007 04:26:17 +0000 Subject: [PATCH] To create the test database: cd /trunk/database make make create make install This creates asgard.db3, and puts it in trunk/src. MapObjectFactory should now be able to create NonPlayerCharacters, Containers, StaticMapObjects, and Tiles (i.e. the four current types of MapObjects). Release to be in the next few days. --- database/Makefile | 11 +++- database/createdb.sql | 13 ++--- database/populatedb.sql | 61 ++++++++++++++++++++ src/Container.h | 2 +- src/Database.cpp | 3 +- src/GameEngine.cpp | 8 +++ src/MapObjectFactory.cpp | 146 ++++++++++++++++++++++++++++++++++++++--------- src/MapObjectFactory.h | 1 + src/NonPlayerCharacter.h | 2 +- src/StaticMapObject.h | 2 +- 10 files changed, 208 insertions(+), 41 deletions(-) create mode 100644 database/populatedb.sql diff --git a/database/Makefile b/database/Makefile index a4cd80b..bb6a26b 100644 --- a/database/Makefile +++ b/database/Makefile @@ -1,5 +1,10 @@ all: g++ -o runquery sqlite3.cpp -lsqlite3 -run: - ./runquery test.db test.sql - ls -al test.db +create: + ./runquery asgard.db3 createdb.sql + ./runquery asgard.db3 populatedb.sql +install: + mv asgard.db3 ../src +clean: + rm runquery + rm asgard.db3 diff --git a/database/createdb.sql b/database/createdb.sql index 6b61961..ab3bafc 100644 --- a/database/createdb.sql +++ b/database/createdb.sql @@ -25,7 +25,7 @@ create table NonPlayerCharacterPath create table BoundingBox ( - BoundingBoxID integer(10) not null, + BoundingBoxId integer(10) primary key, WC_X integer(10) null, WC_Y integer(10) null, Height integer(10) null, @@ -34,18 +34,17 @@ create table BoundingBox create table MapObject ( - MapObjectID integer(10) not null, + MapObjectId integer primary key, WC_X integer(10) null, WC_Y integer(10) null, Height integer(10) null, Width integer(10) null, - BoundingBoxID integer(10) null, - primary key(MapObjectID) + BoundingBoxId integer(10) null ); create table Container ( - MapObjectID integer(10) null, + MapObjectId integer(10) null, item0 integer(10) null, item1 integer(10) null, item2 integer(10) null, @@ -61,7 +60,7 @@ create table Container item12 integer(10) null, item13 integer(10) null, item14 integer(10) null, - foreign key(MapObjectID) references MapObject(MapObjectID) + foreign key(MapObjectId) references MapObject(MapObjectId) ); create table Hardpoints @@ -79,7 +78,7 @@ create table Hardpoints create table Tiles ( - MapObjectID integer(10) not null, + MapObjectId integer(10) not null, TileType integer(10) null, foreign key (MapObjectId) references MapObject(MapObjectId) ); diff --git a/database/populatedb.sql b/database/populatedb.sql new file mode 100644 index 0000000..e1449c8 --- /dev/null +++ b/database/populatedb.sql @@ -0,0 +1,61 @@ +--Tropical Island +insert into BoundingBox +(BoundingBoxId,WC_X,WC_Y,Height,Width) +values(NULL,0,0,100,100); + +--Palm Tree (id = 1) +insert into MapObject +(MapObjectId,WC_X,WC_Y,Height,Width,BoundingBoxId) +values(NULL,3,5,5,5,1); + +--Treasure Chest (id = 2) +insert into MapObject +(MapObjectId,WC_X,WC_Y,Height,Width,BoundingBoxId) +values(NULL,40,40,3,7,1); + +--Hand (id = 3) +insert into MapObject +(MapObjectId,WC_X,WC_Y,Height,Width,BoundingBoxId) +values(NULL,23,47,3,3,1); + +--Treasure Chest's Container (Saftey Match) +insert into Container +(item0) +values(1); + +--Hand's NPC +insert into NonPlayerCharacter +(MapObjectId,Speed) +values(3,1); + +--Hand's NPC Path +insert into NonPlayerCharacterPath +(MapObjectId,WC_X,WC_Y,PathIndex) +values(1,43,43,0); +insert into NonPlayerCharacterPath +(MapObjectId,WC_X,WC_Y,PathIndex) +values(1,33,25,1); +insert into NonPlayerCharacterPath +(MapObjectId,WC_X,WC_Y,PathIndex) +values(1,55,3,2); +insert into NonPlayerCharacterPath +(MapObjectId,WC_X,WC_Y,PathIndex) +values(1,23,47,3); + +--Palm Tree's Hardpoint +--Hardpoint Type = 2 = CircHardPoint +insert into Hardpoints +(MapObjectId,HardpointType,RelativeX,RelativeY,Radius) +values(1,2,0,0,3); + +--Treasure Chest's Hardpoint +--Hardpoint Type = 1 = CircHardPoint +insert into Hardpoints +(MapObjectId,HardpointType,RelativeX,RelativeY,Height,Width) +values(2,1,0,0,5,5); + +--Hand's Hardpoint +--Hardpoint Type = 2 = CircHardPoint +insert into Hardpoints +(MapObjectId,HardpointType,RelativeX,RelativeY,Radius) +values(3,2,0,0,3); diff --git a/src/Container.h b/src/Container.h index 32105c5..ce64187 100644 --- a/src/Container.h +++ b/src/Container.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors + * Copyright (c) 2007 Russ Adams, Sean Eubanks, Asgard Contributors * This file is part of Asgard. * * Asgard is free software; you can redistribute it and/or modify diff --git a/src/Database.cpp b/src/Database.cpp index ff5491e..b671d41 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -52,7 +52,8 @@ Database* Database::getInstance() void Database::determineVisibleBoxes(Coordinate currentPosition, int *visibleBoxes, int numVisibleBoxes) { - + // Map as of 0.3.0 is 1 boundbox, 0. + visibleBoxes[0] = 0; } bool Database::loadBoundingBox(int boxId) diff --git a/src/GameEngine.cpp b/src/GameEngine.cpp index 45a9cae..40f591c 100644 --- a/src/GameEngine.cpp +++ b/src/GameEngine.cpp @@ -2,16 +2,19 @@ GameEngine* GameEngine::instance = NULL; + GameEngine* GameEngine::getInstance() { if(instance == NULL) instance = new GameEngine(); return instance; } + GameEngine::GameEngine() { } + void GameEngine::loadGame() { } @@ -20,12 +23,17 @@ void GameEngine::loadVisibleBoxes() { Database* db = Database::getInstance(); db->determineVisibleBoxes(this->currentPosition,this->visibleBoxes,VISIBLE_BOUNDING_BOXES); + + for (int slot = 0; slot < VISIBLE_BOUNDING_BOXES; slot++) + db->loadBoundingBox(this->visibleBoxes[slot]); } + void GameEngine::addMapObject(MapObject* object) { } + void GameEngine::removeBoundingBoxObjects(int boundingBoxID) { } diff --git a/src/MapObjectFactory.cpp b/src/MapObjectFactory.cpp index 6daced5..20d63f9 100644 --- a/src/MapObjectFactory.cpp +++ b/src/MapObjectFactory.cpp @@ -33,6 +33,7 @@ #include "RectHardpoint.h" #include "Database.h" + int MapObjectFactory::processRow(void *mapObjectType, int columnCount, char **columnValue, char **columnName) { MapObjectType *type = static_cast(mapObjectType); @@ -49,10 +50,17 @@ int MapObjectFactory::processRow(void *mapObjectType, int columnCount, char **co return true; } + void MapObjectFactory::createTile(char **columnValue) { // Create new tile Tile *tile; + + // MapObject Req'd Members + int wc_x; + int wc_y; + int height; + int width; TileType tileType = (TileType)atoi(columnValue[TILE_COLUMN_TILE_TYPE]); @@ -66,9 +74,15 @@ void MapObjectFactory::createTile(char **columnValue) if(tile != NULL) { + wc_x = atoi(columnValue[TILE_COLUMN_WC_X]); + wc_y = atoi(columnValue[TILE_COLUMN_WC_Y]); + width = atoi(columnValue[TILE_COLUMN_WIDTH]); + height = atoi(columnValue[TILE_COLUMN_HEIGHT]); + // Set tile Map Object variables - tile->setWidth(atoi(columnValue[TILE_COLUMN_WIDTH])); - tile->setHeight(atoi(columnValue[TILE_COLUMN_HEIGHT])); + tile->setLeftCorner(Coordinate(wc_x, wc_y)); + tile->setWidth(width); + tile->setHeight(height); // Get reference to GameEngine GameEngine *gameEngine = GameEngine::getInstance(); @@ -79,12 +93,19 @@ void MapObjectFactory::createTile(char **columnValue) } + void MapObjectFactory::createContainer(char **columnValue) { Database* db = Database::getInstance(); char*** table; int* rowCount; + // MapObject Req'd Members + int wc_x; + int wc_y; + int height; + int width; + // Objects to Create Container* container = new Container(); @@ -93,57 +114,114 @@ void MapObjectFactory::createContainer(char **columnValue) for (int row = 0; row < *rowCount; row++) container->addHardpoint(createHardpoint(table[row])); - // TODO: Create Items + // TODO: Create Items; Not 0.3.0 + - // Get reference to GameEngine - GameEngine *gameEngine = GameEngine::getInstance(); - - // Add container to gameEngine - gameEngine->addMapObject((MapObject*)container); + if (container != NULL) + { + // Set MapObject Members + wc_x = atoi(columnValue[CONTAINER_COLUMN_WC_X]); + wc_y = atoi(columnValue[CONTAINER_COLUMN_WC_Y]); + width = atoi(columnValue[CONTAINER_COLUMN_WIDTH]); + height = atoi(columnValue[CONTAINER_COLUMN_HEIGHT]); + + container->setLeftCorner(Coordinate(wc_x, wc_y)); + container->setWidth(width); + container->setHeight(height); + + // Get reference to GameEngine + GameEngine *gameEngine = GameEngine::getInstance(); + + // Add container to gameEngine + gameEngine->addMapObject((MapObject*)container); + } } + void MapObjectFactory::createNonPlayerCharacter(char **columnValue) { Database* db = Database::getInstance(); char*** table; int* rowCount; + // MapObject Req'd Members + int wc_x; + int wc_y; + int height; + int width; + NonPlayerCharacter *npc = new NonPlayerCharacter(); - // Create Hardpoints - table = db->loadHardpoints(atoi(columnValue[CONTAINER_COLUMN_MAP_OBJECT_ID]),rowCount); - for (int row = 0; row < *rowCount; row++) - npc->addHardpoint(createHardpoint(table[row])); - - // Get reference to GameEngine - GameEngine *gameEngine = GameEngine::getInstance(); + if (npc != NULL) + { + // Create Hardpoints + table = db->loadHardpoints(atoi(columnValue[NON_PLAYER_CHARACTER_COLUMN_MAP_OBJECT_ID]),rowCount); + for (int row = 0; row < *rowCount; row++) + npc->addHardpoint(createHardpoint(table[row])); + + // Create NonPlayerCharacterPath + table = db->loadNonPlayerCharacterPath(atoi(columnValue[NON_PLAYER_CHARACTER_COLUMN_MAP_OBJECT_ID]),rowCount); + for (int row = 0; row < *rowCount; row++) + npc->addCoordinateToPath(createNonPlayerCharacterPathPoint(table[row])); - // Add container to gameEngine - gameEngine->addMapObject((MapObject*)npc); + wc_x = atoi(columnValue[NON_PLAYER_CHARACTER_COLUMN_WC_X]); + wc_y = atoi(columnValue[NON_PLAYER_CHARACTER_COLUMN_WC_Y]); + width = atoi(columnValue[NON_PLAYER_CHARACTER_COLUMN_WIDTH]); + height = atoi(columnValue[NON_PLAYER_CHARACTER_COLUMN_HEIGHT]); + + npc->setLeftCorner(Coordinate(wc_x, wc_y)); + npc->setWidth(width); + npc->setHeight(height); + + // Get reference to GameEngine + GameEngine *gameEngine = GameEngine::getInstance(); + + // Add container to gameEngine + gameEngine->addMapObject((MapObject*)npc); + } } + void MapObjectFactory::createStaticMapObject(char **columnValue) { Database* db = Database::getInstance(); char*** table; int* rowCount; + + // MapObject Req'd Members + int wc_x; + int wc_y; + int height; + int width; StaticMapObject *staticMapObject = new StaticMapObject(); - // Create Hardpoints - table = db->loadHardpoints(atoi(columnValue[CONTAINER_COLUMN_MAP_OBJECT_ID]),rowCount); - for (int row = 0; row < *rowCount; row++) - staticMapObject->addHardpoint(createHardpoint(table[row])); - - - // Get reference to GameEngine - GameEngine *gameEngine = GameEngine::getInstance(); + if (staticMapObject != NULL) + { + // Create Hardpoints + table = db->loadHardpoints(atoi(columnValue[CONTAINER_COLUMN_MAP_OBJECT_ID]),rowCount); + for (int row = 0; row < *rowCount; row++) + staticMapObject->addHardpoint(createHardpoint(table[row])); - // Add container to gameEngine - gameEngine->addMapObject((MapObject*)staticMapObject); + wc_x = atoi(columnValue[STATIC_MAP_OBJECT_COLUMN_WC_X]); + wc_y = atoi(columnValue[STATIC_MAP_OBJECT_COLUMN_WC_Y]); + width = atoi(columnValue[STATIC_MAP_OBJECT_COLUMN_WIDTH]); + height = atoi(columnValue[STATIC_MAP_OBJECT_COLUMN_HEIGHT]); + + staticMapObject->setLeftCorner(Coordinate(wc_x, wc_y)); + staticMapObject->setWidth(width); + staticMapObject->setHeight(height); + + // Get reference to GameEngine + GameEngine *gameEngine = GameEngine::getInstance(); + + // Add container to gameEngine + gameEngine->addMapObject((MapObject*)staticMapObject); + } } + Hardpoint* MapObjectFactory::createHardpoint(char **columnValue) { int x = 0; @@ -153,21 +231,25 @@ Hardpoint* MapObjectFactory::createHardpoint(char **columnValue) double r = 0; int type = 0; + // Rect and Circ Hardpoints need these. type = atoi(columnValue[HARDPOINT_COLUMN_HARDPOINT_TYPE]); x = atoi(columnValue[HARDPOINT_COLUMN_RELATIVE_X]); y = atoi(columnValue[HARDPOINT_COLUMN_RELATIVE_Y]); + // Only RectHardpoints if (type == HARDPOINT_TYPE_RECT) { height = atoi(columnValue[HARDPOINT_COLUMN_WIDTH]); width = atoi(columnValue[HARDPOINT_COLUMN_HEIGHT]); return new RectHardpoint(x,y,height,width); } + // Only CircHardpoints else if (type == HARDPOINT_TYPE_CIRC) { r = atof(columnValue[HARDPOINT_COLUMN_RADIUS]); return new RectHardpoint(x,y,height,width); } + // Default else { return new RectHardpoint(); @@ -175,3 +257,13 @@ Hardpoint* MapObjectFactory::createHardpoint(char **columnValue) } +Coordinate* MapObjectFactory::createNonPlayerCharacterPathPoint(char **columnValue) +{ + int wc_x = 0; + int wc_y = 0; + + wc_x = atoi(columnValue[NON_PLAYER_CHARACTER_PATH_COLUMN_WC_X]); + wc_y = atoi(columnValue[NON_PLAYER_CHARACTER_PATH_COLUMN_WC_Y]); + + return new Coordinate(wc_x, wc_y); +} diff --git a/src/MapObjectFactory.h b/src/MapObjectFactory.h index 9685dbc..955f1f8 100644 --- a/src/MapObjectFactory.h +++ b/src/MapObjectFactory.h @@ -30,6 +30,7 @@ class MapObjectFactory static void createNonPlayerCharacter(char **columnValue); static void createStaticMapObject(char **columnValue); static Hardpoint* createHardpoint(char **columnValue); + static Coordinate* createNonPlayerCharacterPathPoint(char **columnValue); public: static int processRow(void *mapObjectType, int columnCount, char **columnValue, char **columnName); diff --git a/src/NonPlayerCharacter.h b/src/NonPlayerCharacter.h index 543034a..ef542f1 100644 --- a/src/NonPlayerCharacter.h +++ b/src/NonPlayerCharacter.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors + * Copyright (c) 2007 Russ Adams, Sean Eubanks, Asgard Contributors * This file is part of Asgard. * * Asgard is free software; you can redistribute it and/or modify diff --git a/src/StaticMapObject.h b/src/StaticMapObject.h index a6100f7..86edb95 100644 --- a/src/StaticMapObject.h +++ b/src/StaticMapObject.h @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2006 Russ Adams, Sean Eubanks, Asgard Contributors + * Copyright (c) 2007 Russ Adams, Sean Eubanks, Asgard Contributors * This file is part of Asgard. * * Asgard is free software; you can redistribute it and/or modify -- 2.11.4.GIT