📄 scourge.cpp
字号:
/*************************************************************************** scourge.cpp - description ------------------- begin : Sat May 3 2003 copyright : (C) 2003 by Gabor Torok email : cctorok@yahoo.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "scourge.h"#include "events/thirsthungerevent.h"// 2,3 2,6 3,6* 5,1+ 6,3 8,3*// good for debugging blendingint Scourge::blendA = 2;int Scourge::blendB = 6; // 3int Scourge::blend[] = { GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA_SATURATE};void Scourge::setBlendFunc() { glBlendFunc(blend[blendA], blend[blendB]);}Scourge::Scourge(int argc, char *argv[]){ lastTick = lastProjectileTick = 0; messageWin = NULL; movingX = movingY = movingZ = MAP_WIDTH + 1; movingItem = NULL; nextMission = -1; // in HQ map inHq = true; currentMission = NULL; isInfoShowing = true; // what is this? info_dialog_showing = false; // new item and creature references itemCount = creatureCount = 0; // we're not in target selection mode targetSelectionFor = NULL; // Reads the user configuration from a file userConfiguration = new UserConfiguration(); userConfiguration->loadConfiguration(); userConfiguration->parseCommandLine(argc, argv); // Initialize the video mode sdlHandler = new SDLHandler(); sdlHandler->setVideoMode(userConfiguration); shapePal = sdlHandler->getShapePalette(); // init characters first. Items use it for acl Character::initCharacters(); // initialize the items Item::initItems(shapePal); // initialize magic MagicSchool::initMagic(); // initialize the monsters (they use items, magic) Monster::initMonsters(); // create the mission board board = new Board(this); // do this before the inventory and optionsdialog (so Z is less than of those) party = new Party(this); createUI(); move = 0; battleCount = 0; inventory = NULL; containerGuiCount = 0; changingStory = false; // show the main menu mainMenu = new MainMenu(this); optionsMenu = new OptionsMenu(this); while(true) { map = new Map(this); mainMenu->show(); sdlHandler->setHandlers((SDLEventHandler *)mainMenu, (SDLScreenView *)mainMenu); sdlHandler->mainLoop(); mainMenu->hide(); // evaluate results and start a missions if(mainMenu->getValue() == NEW_GAME) { party->reset(); party->getCalendar()->reset(true); // reset the time board->reset(); // inventory needs the party if(!inventory) { inventory = new Inventory(this); } // always start in hq nextMission = -1; inHq = true; delete map; startMission(); } else if(mainMenu->getValue() == OPTIONS) { optionsMenu->show(); } else if(mainMenu->getValue() == QUIT) { sdlHandler->quit(0); } }} Scourge::~Scourge(){ delete mainMenu; delete optionsMenu; delete userConfiguration; delete board;}void Scourge::startMission() { while(true) { // add gui party->getWindow()->setVisible(true); messageWin->setVisible(true); // create the map map = new Map(this); miniMap = new MiniMap(this); //miniMap->show(); // ready the party party->startPartyOnMission(); // position the players move = 0; battleCount = 0; containerGuiCount = 0; lastMapX = lastMapY = lastMapZ = lastX = lastY = -1; teleporting = false; changingStory = false; mouseMoveScreen = true; targetSelectionFor = NULL; if(nextMission == -1) { currentMission = NULL; missionWillAwardExpPoints = false; // in HQ map inHq = true; // init the missions board board->initMissions(); // display the HQ map dg = new DungeonGenerator(this, 2, false, false); // level 2 is a big enough map for HQ_LOCATION... this is hacky dg->toMap(map, getShapePalette(), DungeonGenerator::HQ_LOCATION); } else { // in HQ map inHq = false; // Initialize the map with a random dunegeon currentMission = board->getMission(nextMission); missionWillAwardExpPoints = (!currentMission->isCompleted()); cerr << "Starting mission: level=" << currentMission->getLevel() << " stories=" << currentMission->getDungeonStoryCount() << " current story=" << currentStory << endl; dg = new DungeonGenerator(this, currentMission->getLevel(), (currentStory < currentMission->getDungeonStoryCount() - 1), (currentStory > 0), currentMission); dg->toMap(map, getShapePalette()); } // center map on the player map->center(party->getPlayer()->getX(), party->getPlayer()->getY(), true); // Must be called after MiniMap has been built by dg->toMap() !!! miniMap->computeDrawValues(); // set to receive events here sdlHandler->setHandlers((SDLEventHandler *)this, (SDLScreenView *)this); // hack to unfreeze animations, etc. party->forceStopRound(); // show an info dialog if(nextMission == -1) { sprintf(infoMessage, "Welcome to the S.C.O.U.R.G.E. Head Quarters"); } else { sprintf(infoMessage, "Entering dungeon level %d", currentStory); } showMessageDialog(infoMessage); info_dialog_showing = true; // run mission sdlHandler->mainLoop(); // remove gui party->getWindow()->setVisible(false); messageWin->setVisible(false); closeAllContainerGuis(); if(inventory->isVisible()) inventory->hide(); if(board->boardWin->isVisible()) board->boardWin->setVisible(false); //miniMap->hide(); // clean up after the mission delete map; delete miniMap; delete dg; // delete the items and creatures created for this mission // (except items in inventory) for(int i = 0; i < itemCount; i++) { bool inInventory = false; for(int t = 0; t < party->getPartySize(); t++) { if(party->getParty(t)->isItemInInventory(items[i])) { inInventory = true; break; } } if(!inInventory) { delete items[i]; itemCount--; for(int t = i; t < itemCount; t++) { items[t] = items[t + 1]; } i--; } } for(int i = 0; i < creatureCount; i++) { delete creatures[i]; } creatureCount = 0; /* cerr << "After mission: " << " creatureCount=" << creatureCount << " itemCount=" << itemCount << endl; */ if(!changingStory) { if(!inHq) { if(teleporting) { // go back to HQ when coming from a mission nextMission = -1; } else { break; } } else if(nextMission == -1) { // if quiting in HQ, exit loop break; } } }}void Scourge::endMission() { party->getPlayer()->setSelXY(-1, -1); // stop moving movingItem = NULL; // stop moving items // move = 0; }// items created for the missionItem *Scourge::newItem(RpgItem *rpgItem, Spell *spell) { items[itemCount] = new Item(rpgItem); if(spell) items[itemCount]->setSpell(spell); itemCount++; return items[itemCount - 1];}// creatures created for the missionCreature *Scourge::newCreature(Character *character, char *name) { creatures[creatureCount++] = new Creature(this, character, name); return creatures[creatureCount - 1];}// creatures created for the missionCreature *Scourge::newCreature(Monster *monster) { creatures[creatureCount++] = new Creature(this, monster); return creatures[creatureCount - 1];}void Scourge::drawView() { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // make a move (player, monsters, etc.) playRound(); party->drawView(); map->draw(); glDisable( GL_DEPTH_TEST ); glDisable( GL_TEXTURE_2D ); if(isInfoShowing) { map->initMapView(); for(int i = 0; i < party->getPartySize(); i++) { if(!party->getParty(i)->getStateMod(Constants::dead)) { map->showCreatureInfo(party->getParty(i), (party->getPlayer() == party->getParty(i)), (map->getSelectedDropTarget() && map->getSelectedDropTarget()->creature == party->getParty(i)), !party->isPlayerOnly()); } } glDisable( GL_CULL_FACE ); } map->drawDescriptions(messageList); miniMap->draw(0, 400); // if(inventory->isVisible()) inventory->drawInventory(); glEnable( GL_DEPTH_TEST ); glEnable( GL_TEXTURE_2D ); }void Scourge::drawAfter() { map->drawDraggedItem();}bool Scourge::handleEvent(SDL_Event *event) { int ea; if(containerGuiCount > 0) { for(int i = 0; i < containerGuiCount; i++) { if(containerGui[i]->handleEvent(event)) { closeContainerGui(containerGui[i]); } } } if(inventory->isVisible()) { inventory->handleEvent(event); // return false; } if(optionsMenu->isVisible()) { optionsMenu->handleEvent(event); return false; } int mx, my; switch(event->type) { case SDL_MOUSEMOTION: //sdlHandler->applyMouseOffset(event->motion.x, event->motion.y, &mx, &my); mx = event->motion.x; my = event->motion.y; if(mx < 10) { mouseMoveScreen = true; setMove(Constants::MOVE_LEFT); } else if(mx >= sdlHandler->getScreen()->w - 10) { mouseMoveScreen = true; setMove(Constants::MOVE_RIGHT); } else if(my < 10) { mouseMoveScreen = true; setMove(Constants::MOVE_UP); } else if(my >= sdlHandler->getScreen()->h - 10) { mouseMoveScreen = true; setMove(Constants::MOVE_DOWN); } else { if(mouseMoveScreen) { mouseMoveScreen = false; removeMove(Constants::MOVE_LEFT | Constants::MOVE_RIGHT); removeMove(Constants::MOVE_UP | Constants::MOVE_DOWN); map->setYRot(0.0f); map->setZRot(0.0f); } } processGameMouseMove(mx, my); break; case SDL_MOUSEBUTTONDOWN: sdlHandler->applyMouseOffset(event->motion.x, event->motion.y, &mx, &my); if(event->button.button) { processGameMouseDown(mx, my, event->button.button);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -