GLint CRoomManager::getRoomCount(GLint owner, GLint type) { GLint count = 0; for (roomIter=allRooms.begin(); roomIter!=allRooms.end(); roomIter++) { CRoom *room = roomIter->second; // extract owner info the first tile. this is safe since no room can have 0 tiles. CBlock *roomTile = (*room->getRoomTilesVector())[0]; count+=(roomTile->getOwner() == owner && roomTile->getType() == type && !(roomTile->getType() == CV_BLOCK_TYPE_HEART_ID || roomTile->getType() == CV_BLOCK_TYPE_PORTAL_ID))?1:0; } return count; }
bool CRoomManager::init() { // register to console: TODO register some usefull stuff CV_GAME_MANAGER->getConsole()->registerClass(this,"ROOM MANAGER"); CV_GAME_MANAGER->getConsole()->addParam(RLROOM,"() Reloads the rooms."); CV_GAME_MANAGER->getConsole()->addParam(RC,"() Prints room count."); CV_GAME_MANAGER->getConsole()->addParam(RC,"() Prints room count."); CV_GAME_MANAGER->getConsole()->addParam(SRA,"() Shows room area."); // construct new rooms CLevelManager *lManager = CV_GAME_MANAGER->getLevelManager(); for (GLuint y=0; y<CV_LEVEL_MAP_SIZE; y++) { for (GLuint x=0; x<CV_LEVEL_MAP_SIZE; x++) { CBlock *block = lManager->getBlock(x,y); if (block->isRoom() && !block->isInRoom()) { if(block->getType() == CV_BLOCK_TYPE_HEART_ID && block->getOwner() == CV_PLAYER_0) { cml::vector3f position = block->getRealPosition(); CV_GAME_MANAGER->getControlManager()->getCamera()->setPosition(cml::vector3f(position[0]+0.3, CV_CAMERA_INITIAL_HEIGHT, position[2]+1)); } // we found a room tile that isn't in a room yet. we create a new room. CRoom *newRoom = new CRoom(); newRoom->init(block); allRooms[newRoom->getIndex()] = newRoom; roomColors[newRoom->getIndex()] = vector3f((GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f); } } } return true; }
CBlock *CRoomManager::getRoom(GLint roomType, GLubyte owner) { for (roomIter=allRooms.begin(); roomIter!=allRooms.end(); roomIter++) { CRoom *room = roomIter->second; CBlock *roomTile = (*room->getRoomTilesVector())[0]; if (roomTile->getType() == roomType && roomTile->getOwner() == owner) { return roomTile; } } return NULL; }
GLvoid CRenderManager::handlePickedObjects() { // if we are ower the menu we do not have to proccess things under the cursor if (CV_GAME_MANAGER->getGUIManager()->getPlayGUI()->is_mouse_over_gui()) { return; } // if we are not selling or buying we don't have to process blocks (just objects TODO) ACTION_EVENT *ae = CV_GAME_MANAGER->getGUIManager()->getLastActionEvent(); // get the block we have our cousor on CBlock *pickedBlock = CV_GAME_MANAGER->getPickingManager()->getLastPickedBlock(); if (pickedBlock) { GLint type = pickedBlock->getType(); /*if (!pickedBlock->isSellable()) { return; }*/ sBoundingBox *bbox = pickedBlock->getBoundingBox(); vector3f a(bbox->A); vector3f b(bbox->B); vector3f c(bbox->C); vector3f d(bbox->D); vector3f e(bbox->E); vector3f f(bbox->F); vector3f g(bbox->G); vector3f h(bbox->H); a[1]=b[1]=c[1]=d[1]=CV_BLOCK_HEIGHT+CV_BLOCK_HEIGHT/4.0f+CV_BLOCK_HEIGHT/32.0f; e[1]=f[1]=g[1]=h[1]=CV_BLOCK_HEIGHT/4.0f+CV_BLOCK_HEIGHT/32.0f; glLineWidth(4.0f); if (pickedBlock->isLow()) { if (!(ae->message_group==AEMG_BUILD_ROOMS || ae->message_group==AEMG_BUILD_DOORS || ae->message_group==AEMG_BUILD_TRAPS)) { return; } // draw the selection box if (pickedBlock->isSellable(CV_CURRENT_PLAYER_ID) && ae->message == AEM_SELL) { glColor3f(0.0f,1.0f,0.0f); } else if (pickedBlock->isBuildable(CV_CURRENT_PLAYER_ID) && ae->message != AEM_SELL) { glColor3f(0.0f,1.0f,0.0f); } else { glColor3f(1.0f,0.0f,0.0f); } glBegin(GL_LINES); { /*glVertex3fv(&a[0]); glVertex3fv(&b[0]); glVertex3fv(&b[0]); glVertex3fv(&c[0]); glVertex3fv(&c[0]); glVertex3fv(&d[0]); glVertex3fv(&d[0]); glVertex3fv(&a[0]);*/ glVertex3fv(&e[0]); glVertex3fv(&f[0]); glVertex3fv(&f[0]); glVertex3fv(&g[0]); glVertex3fv(&g[0]); glVertex3fv(&h[0]); glVertex3fv(&h[0]); glVertex3fv(&e[0]); /*glVertex3fv(&a[0]); glVertex3fv(&e[0]); glVertex3fv(&b[0]); glVertex3fv(&f[0]); glVertex3fv(&c[0]); glVertex3fv(&g[0]); glVertex3fv(&d[0]); glVertex3fv(&h[0]);*/ } glEnd(); } else { if (!(ae->message_group==AEMG_BUILD_ROOMS || ae->message_group==AEMG_BUILD_DOORS || ae->message_group==AEMG_BUILD_TRAPS)) glColor3f(type==CV_BLOCK_TYPE_ROCK_ID?1.0f:0.0f,type==CV_BLOCK_TYPE_ROCK_ID?0.0f:1.0f,0.0f); else glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINES); { glVertex3fv(&a[0]); glVertex3fv(&b[0]); glVertex3fv(&b[0]); glVertex3fv(&c[0]); glVertex3fv(&c[0]); glVertex3fv(&d[0]); glVertex3fv(&d[0]); glVertex3fv(&a[0]); glVertex3fv(&e[0]); glVertex3fv(&f[0]); glVertex3fv(&f[0]); glVertex3fv(&g[0]); glVertex3fv(&g[0]); glVertex3fv(&h[0]); glVertex3fv(&h[0]); glVertex3fv(&e[0]); glVertex3fv(&a[0]); glVertex3fv(&e[0]); glVertex3fv(&b[0]); glVertex3fv(&f[0]); glVertex3fv(&c[0]); glVertex3fv(&g[0]); glVertex3fv(&d[0]); glVertex3fv(&h[0]); } glEnd(); } glLineWidth(1.0f); } }
GLvoid CRoomManager::addRoomTile(CBlock *block) { CLevelManager *lManager = CV_GAME_MANAGER->getLevelManager(); vector2i pos = block->getLogicalPosition(); vector2i posses[] = {vector2i(-1,0),vector2i(1,0),vector2i(0,-1),vector2i(0,1)}; bool nbrs[4]; nbrs[0] = lManager->isSameTypeAndOwner(pos[0]-1,pos[1],block); nbrs[1] = lManager->isSameTypeAndOwner(pos[0]+1,pos[1],block); nbrs[2] = lManager->isSameTypeAndOwner(pos[0],pos[1]-1,block); nbrs[3] = lManager->isSameTypeAndOwner(pos[0],pos[1]+1,block); GLint cnt = 0; cnt+=nbrs[0]?1:0; cnt+=nbrs[1]?1:0; cnt+=nbrs[2]?1:0; cnt+=nbrs[3]?1:0; if (cnt==0) { // create a new room CRoom *newRoom = new CRoom(); newRoom->getRoomTilesVector()->push_back(block); newRoom->reownTiles(); allRooms[newRoom->getIndex()] = newRoom; roomColors[newRoom->getIndex()] = vector3f((GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f,(GLfloat)(rand()%101)/100.0f); CV_GAME_MANAGER->getConsole()->writeLine("A new room!"); } else { GLint owner = -1; GLint roomIndex = -1; GLint type = -1; bool set = false; bool ok[] = {true, true, true}; CBlock *testBlock = NULL; for (int i=0; i<4; i++) { if (nbrs[i]) { testBlock = lManager->getBlock(pos+posses[i]); if (!set) { set = true; owner = testBlock->getOwner(); roomIndex = testBlock->getRoomIndex(); type = testBlock->getType(); } else { ok[0] &= (owner == testBlock->getOwner()); ok[1] &= (roomIndex == testBlock->getRoomIndex()); ok[2] &= (type == testBlock->getType()); } } } if (ok[0]&&ok[1]&&ok[2]) { // all of same type, owner and room. just add this tile to this existing room allRooms[testBlock->getRoomIndex()]->getRoomTilesVector()->push_back(block); allRooms[testBlock->getRoomIndex()]->reownTiles(); CV_GAME_MANAGER->getConsole()->writeLine("Tile added to the existing room."); } else { std::map<GLint, CBlock*> blockPerRoom; // we must make some merging for (int i=0; i<4; i++) { if (nbrs[i]) { testBlock = lManager->getBlock(pos+posses[i]); blockPerRoom[testBlock->getRoomIndex()] = testBlock; } } // on this stage there are at least 2 elements in blockPerRoom. // take the first room and add it it all other room tiles. // then delete other rooms std::map<GLint, CBlock*>::iterator irIter = blockPerRoom.begin(); CRoom *targetRoom = allRooms[irIter->first]; irIter++; for (irIter; irIter!=blockPerRoom.end(); irIter++) { CRoom *room = allRooms[irIter->first]; for (GLuint t=0; t<room->getRoomTilesVector()->size(); t++) { targetRoom->getRoomTilesVector()->push_back((*room->getRoomTilesVector())[t]); } // delete the unwanted room allRooms.erase(allRooms.find(irIter->first)); } targetRoom->getRoomTilesVector()->push_back(block); targetRoom->reownTiles(); CV_GAME_MANAGER->getConsole()->writeLine("Rooms merged."); } } }