void GlobalTimer::Freeze() { unsigned long thisTime; unsigned long advance; thisTime = GetTickCount(); advance = thisTime - startTime; if ( advance < interval) { return; } startTime = thisTime; Game* game = core->GetGame(); if (!game) { return; } game->RealTime++; ieDword count = advance/interval; // pst/bg2 do this, if you fix it for another game, wrap it in a check DoFadeStep(count); // show scrolling cursor while paused GameControl* gc = core->GetGameControl(); if (gc) gc->UpdateScrolling(); }
int SaveGameIterator::CreateSaveGame(int index, bool mqs) { AutoTable tab("savegame"); const char *slotname = NULL; int qsave = 0; if (tab) { slotname = tab->QueryField(index); qsave = atoi(tab->QueryField(index, 1)); } if (mqs) { assert(qsave); PruneQuickSave(slotname); } if (int cansave = CanSave()) return cansave; //if index is not an existing savegame, we create a unique slotname for (size_t i = 0; i < save_slots.size(); ++i) { Holder<SaveGame> save = save_slots[i]; if (save->GetSaveID() == index) { DeleteSaveGame(save); break; } } char Path[_MAX_PATH]; GameControl *gc = core->GetGameControl(); if (!CreateSavePath(Path, index, slotname)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } if (!DoSaveGame(Path)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } // Save succesful / Quick-save succesful if (qsave) { displaymsg->DisplayConstantString(STR_QSAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_QSAVESUCCEED, 30); } } else { displaymsg->DisplayConstantString(STR_SAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_SAVESUCCEED, 30); } } return 0; }
/** Mouse Button Up */ void TextArea::OnMouseUp(unsigned short x, unsigned short y, unsigned short /*Button*/, unsigned short /*Mod*/) { if (( x <= Width ) && ( y <= ( Height - 5 ) ) && ( seltext != -1 )) { Value = (unsigned int) seltext; Changed = true; if (strnicmp( lines[seltext], "[s=", 3 ) == 0) { if (minrow > seltext) return; int idx; sscanf( lines[seltext], "[s=%d,", &idx ); GameControl* gc = core->GetGameControl(); if (gc && (gc->GetDialogueFlags()&DF_IN_DIALOG) ) { if (idx==-1) { //this kills this object, don't use any more data! gc->EndDialog(); return; } gc->DialogChoose( idx ); return; } } } if (VarName[0] != 0) { core->GetDictionary()->SetAt( VarName, Value ); } RunEventHandler( TextAreaOnChange ); }
bool GlobalTimer::Update() { Map *map; Game *game; GameControl* gc; unsigned long thisTime; unsigned long advance; gc = core->GetGameControl(); if (gc) gc->UpdateScrolling(); UpdateAnimations(); thisTime = GetTickCount(); if (!startTime) { startTime = thisTime; return false; } advance = thisTime - startTime; if ( advance < interval) { return false; } ieDword count = advance/interval; DoStep(count); DoFadeStep(count); if (!gc) { goto end; } game = core->GetGame(); if (!game) { goto end; } map = game->GetCurrentArea(); if (!map) { goto end; } //do spell effects expire in dialogs? //if yes, then we should remove this condition if (!(gc->GetDialogueFlags()&DF_IN_DIALOG) ) { map->UpdateFog(); map->UpdateEffects(); if (thisTime) { //this measures in-world time (affected by effects, actions, etc) game->AdvanceTime(1); } } //this measures time spent in the game (including pauses) if (thisTime) { game->RealTime++; } end: startTime = thisTime; return true; }
/** BroadCast Mouse Move Event */ void EventMgr::MouseMove(unsigned short x, unsigned short y) { if (windows.size() == 0) { return; } if (!last_win_focused) { return; } GameControl *gc = core->GetGameControl(); if (gc) { // for scrolling gc->OnGlobalMouseMove(x, y); } std::vector< int>::iterator t; std::vector< Window*>::iterator m; for (t = topwin.begin(); t != topwin.end(); ++t) { m = windows.begin(); m += ( *t ); Window *win = *m; if (win == NULL) continue; if (!win->Visible) continue; if (( win->XPos <= x ) && ( win->YPos <= y )) { //Maybe we are on the window, let's check if (( win->XPos + win->Width >= x ) && ( win->YPos + win->Height >= y )) { //Yes, we are on the Window //Let's check if we have a Control under the Mouse Pointer Control* ctrl = win->GetControl( x, y, true ); //look for the low priority flagged controls (mostly static labels) if (ctrl == NULL) { ctrl = win->GetControl( x, y, false ); } if (win != last_win_over || ctrl != win->GetOver()) { // Remove tooltip if mouse moved to different control core->DisplayTooltip( 0, 0, NULL ); if (last_win_over) { last_win_over->OnMouseLeave( x, y ); } last_win_over = win; win->OnMouseEnter( x, y, ctrl ); } if (ctrl != NULL) { win->OnMouseOver( x, y ); } RefreshCursor(win->Cursor); return; } } //stop going further if (( *m )->Visible == WINDOW_FRONT) break; } core->DisplayTooltip( 0, 0, NULL ); }
int SaveGameIterator::CreateSaveGame(Holder<SaveGame> save, const char *slotname) { if (!slotname) { return -1; } if (int cansave = CanSave()) return cansave; GameControl *gc = core->GetGameControl(); int index; if (save) { index = save->GetSaveID(); DeleteSaveGame(save); save.release(); } else { //leave space for autosaves //probably the hardcoded slot names should be read by this object //in that case 7 == size of hardcoded slot names array (savegame.2da) index = 7; for (size_t i = 0; i < save_slots.size(); ++i) { Holder<SaveGame> save = save_slots[i]; if (save->GetSaveID() >= index) { index = save->GetSaveID() + 1; } } } char Path[_MAX_PATH]; if (!CreateSavePath(Path, index, slotname)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } if (!DoSaveGame(Path)) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_CANTSAVE, 30); } return -1; } // Save succesful displaymsg->DisplayConstantString(STR_SAVESUCCEED, DMC_BG2XPGREEN); if (gc) { gc->SetDisplayText(STR_SAVESUCCEED, 30); } return 0; }
/** Key Press Event */ void TextArea::OnKeyPress(unsigned char Key, unsigned short /*Mod*/) { if (Flags & IE_GUI_TEXTAREA_EDITABLE) { if (Key >= 0x20) { Owner->Invalidate(); Changed = true; int len = GetRowLength(CurLine); //printf("len: %d Before: %s\n",len, lines[CurLine]); lines[CurLine] = (char *) realloc( lines[CurLine], len + 2 ); for (int i = len; i > CurPos; i--) { lines[CurLine][i] = lines[CurLine][i - 1]; } lines[CurLine][CurPos] = Key; lines[CurLine][len + 1] = 0; CurPos++; //printf("pos: %d After: %s\n",CurPos, lines[CurLine]); CalcRowCount(); RunEventHandler( TextAreaOnChange ); } return; } //Selectable=false for dialogs, rather unintuitive, but fact if ((Flags & IE_GUI_TEXTAREA_SELECTABLE) || ( Key < '1' ) || ( Key > '9' )) return; GameControl *gc = core->GetGameControl(); if (gc && (gc->GetDialogueFlags()&DF_IN_DIALOG) ) { Changed = true; seltext=minrow-1; if ((unsigned int) seltext>=lines.size()) { return; } for(int i=0;i<Key-'0';i++) { do { seltext++; if ((unsigned int) seltext>=lines.size()) { return; } } while (strnicmp( lines[seltext], "[s=", 3 ) != 0 ); } int idx=-1; sscanf( lines[seltext], "[s=%d,", &idx); if (idx==-1) { //this kills this object, don't use any more data! gc->EndDialog(); return; } gc->DialogChoose( idx ); } }
int main(){ window.create(sf::VideoMode((unsigned int)windowWidth,(unsigned int)windowHeight),"MyWindow"); window.setFramerateLimit(60); Setup(); running=true; while(running){ while(window.pollEvent(event)){ if(event.type==sf::Event::Closed) running=false; else if(event.type==sf::Event::Resized) ReshapeWindow((float)event.size.width,(float)event.size.height); } if (currentState == MAIN) { cmain.HandleKeyboard(); cmain.mouseControl(); } else if (currentState == GAME) { cgame.HandleKeyboard(); handleKeyboard(); } Display(); window.display(); } return 0; }
int main() { //---- creates object of the class that controls the game ----// GameControl Game; //---- load sounds ----// Game.LoadingMenuSounds(); //---- load images ----// Game.LoadingMenuImages(); //---- call the mainmenu ----// Game.MainMenuChoice(); return 0; }
int main(int argc, char* argv[]) { MinimaxSearcher ms; AlphaBetaSearcher abs; NegamaxSearcher ns; NegamaxAlphaBetaSearcher nabs; AlphaBetaSearcher as; HumanPlayer human("张三"); //ComputerPlayer computer1("KA47"); //computer1.SetSearcher(&as, SEARCH_DEPTH); ComputerPlayer computer("ThinkPad X200"); computer.SetSearcher(&nabs, SEARCH_DEPTH); WzEvaluator wzFunc; FeEvaluator feFunc; GameState init_state; init_state.InitGameState(PLAYER_A); init_state.SetEvaluator(&feFunc); /* init_state.SetGameCell(0, PLAYER_A); init_state.SetGameCell(1, PLAYER_B); init_state.SetGameCell(3, PLAYER_B); init_state.SetGameCell(4, PLAYER_B); init_state.SetGameCell(5, PLAYER_A); init_state.SetGameCell(6, PLAYER_A); */ /* init_state.SetGameCell(0, PLAYER_B); init_state.SetGameCell(3, PLAYER_B); init_state.SetGameCell(4, PLAYER_A); init_state.SetGameCell(5, PLAYER_A); init_state.SetGameCell(6, PLAYER_A); init_state.SetGameCell(8, PLAYER_B); */ GameControl gc; gc.SetPlayer(&computer, PLAYER_A); gc.SetPlayer(&human, PLAYER_B); //gc.SetPlayer(&computer1, PLAYER_B); gc.InitGameState(init_state); gc.Run(); return 0; }
int CanSave() { //some of these restrictions might not be needed Store * store = core->GetCurrentStore(); if (store) { return 1; //can't save while store is open } GameControl *gc = core->GetGameControl(); if (!gc) { return -1; //no gamecontrol!!! } if (gc->GetDialogueFlags()&DF_IN_DIALOG) { return 2; //can't save while in dialog? } //TODO: can't save while in combat //TODO: can't save while (party) actors are in helpless states //TODO: can't save while AOE spells are in effect //TODO: can't save while IF_NOINT is set on an actor return 0; }
void Button::OnMouseOver(unsigned short x, unsigned short y) { Owner->Cursor = IE_CURSOR_NORMAL; if (State == IE_GUI_BUTTON_DISABLED) { return; } if ( RunEventHandler( MouseOverButton )<0) { //event handler destructed this object return; } //well, no more flags for buttons, and the portraits we can perform action on //are in fact 'draggable multiline pictures' (with image) if ((Flags & IE_GUI_BUTTON_DISABLED_P) == IE_GUI_BUTTON_PORTRAIT) { GameControl *gc = core->GetGameControl(); if (gc) { Owner->Cursor = gc->GetDefaultCursor(); } } if (State == IE_GUI_BUTTON_LOCKED) { return; } //portrait buttons are draggable and locked if ((Flags & IE_GUI_BUTTON_DRAGGABLE) && (State == IE_GUI_BUTTON_PRESSED || State ==IE_GUI_BUTTON_LOCKED_PRESSED)) { // We use absolute screen position here, so drag_start // remains valid even after window/control is moved int dx = Owner->XPos + XPos + x - drag_start.x; int dy = Owner->YPos + YPos + y - drag_start.y; core->GetDictionary()->SetAt( "DragX", dx ); core->GetDictionary()->SetAt( "DragY", dy ); drag_start.x = (ieWord) (drag_start.x + dx); drag_start.y = (ieWord) (drag_start.y + dy); RunEventHandler( ButtonOnDrag ); } }
int main() { { loadSettings(); WinStyle::CreationData cd("Plunder (NM i Gameplay build)", 1280, 720, WinStyle::WINDOWED); cd.forcedAspectRatio = true; cd.aspectRatio = 1280.f / 720.f; cd.renderResolution = Vec2(1280.f, 720.f); if (globalSettings.fullscreen) { cd.winStyle = WinStyle::BORDERLESS_WINDOWED; } GameControl *gc = new GameControl; gc->go(new MainMenuScene, cd, false); delete gc; } _CrtDumpMemoryLeaks(); }
NextLevelDialog(GameControl* game) : Dialog("BRAVO!!!",Event::NOP,Event::MENU), m_game(game) { rightControl()->text("<--"); char buf[32]; const GameStats& stats = m_game->stats(); int time = (stats.endTime - stats.startTime)/1000; int h = time/60/60; int m = time/60 - h*60; int s = time - m*60; Box *vbox = new VBox(); vbox->add(new Spacer(),10,1); if (h > 0) { sprintf(buf,"time: %dh %dm %ds",m,h,s); } else if (m > 0) { int m = time/60/1000; sprintf(buf,"time: %dm %ds",m,s); } else { sprintf(buf,"time: %ds",s); } vbox->add(new Label(buf),20,0); sprintf(buf,"%d stroke%s",stats.strokeCount,stats.strokeCount==1?"":"s"); vbox->add(new Label(buf),20,0); if (stats.pausedStrokes) { sprintf(buf," (%d while paused)",stats.pausedStrokes); vbox->add(new Label(buf),20,0); } sprintf(buf,"%d undo%s",stats.undoCount,stats.undoCount==1?"":"s"); vbox->add(new Label(buf),20,0); vbox->add(new Spacer(),10,1); Box *hbox2 = new HBox(); hbox2->add(new Spacer(),20,0); hbox2->add(new Button("review",Event(Event::REPLAY,game->m_level)),BUTTON_WIDTH,0); hbox2->add(new Spacer(),1,1); hbox2->add(new Button("again",Event::RESET),BUTTON_WIDTH,0); hbox2->add(new Spacer(),1,1); hbox2->add(new Button("next",Event::NEXT),BUTTON_WIDTH,0); hbox2->add(new Spacer(),20,0); vbox->add(hbox2,BUTTON_HEIGHT,0); vbox->add(new Spacer(),10,0); content()->add(vbox,0,0); m_targetPos = Vec2( 150, 70); sizeTo(Vec2(500,240)); }
int main(void) { GameControl game; game.RunGame(); return 0; }
//層次 void experimentWorkSpace(){ //A是產生完 B是計算完branch and dead ends //phase A GameControl* gameControl = GameControl::getInstance(); //gameControl->file.open(".\\data\\gameboard20\\db_13.dat");//設定自動產生的關卡要存在哪邊 //db_release = new GameDB(10, 10); //db_release->loadGames(".\\data\\gameboard10\\db_release10_phaseA.dat"); //loadScore(); /*GameDB* db = new GameDB(10, 10); db->loadGames(".\\data\\gameboard10\\db_release10_phaseB.dat"); PersonalData* personalData = new PersonalData(".\\data\\gameboard10\\db_ALL_GAME_remove_same.dat"); personalData->loadScore(".\\statistic\\"); //personalData->printAllScore(); Statistic ss; for(int i = 0; i < personalData->datas.size(); i ++){ vector<ScoreData*> sortedScore = personalData->sortbyDifficulty(PersonalData::DIFFICULTY, personalData->datas[i]); vector<GameState*> complexState = GameControl::getInstance()-> sortbyComplexity(GameControl::ASCENT, personalData->getState(sortedScore)); }*/ //SimulationAnnealing sa(personalData); //GameParameter* p = new GameParameter(1); //sa.begin(p); GameDB* veryEasyDB = new GameDB(); veryEasyDB->loadGames(".\\data\\gameboard10\\db_e2_VeryEasy.dat"); GameDB* easyDB = new GameDB(); easyDB->loadGames(".\\data\\gameboard10\\db_e2_Easy.dat"); GameDB* normalDB = new GameDB(); normalDB->loadGames(".\\data\\gameboard10\\db_e2_Normal.dat"); GameDB* hardDB = new GameDB(); hardDB->loadGames(".\\data\\gameboard10\\db_e2_Hard.dat"); GameDB* veryHardDB = new GameDB(); veryHardDB->loadGames(".\\data\\gameboard10\\db_e2_VeryHard.dat"); vector<GameState*> pickVeryEasyStates = veryEasyDB->getRandomStates(2); vector<GameState*> pickEasyStates = easyDB->getRandomStates(3); vector<GameState*> pickNormalStates = normalDB->getRandomStates(3); vector<GameState*> pickHardStates = hardDB->getRandomStates(1); vector<GameState*> pickVeryHardStates = veryHardDB->getRandomStates(1); vector<GameState*> releaseStates = easyDB->merge(pickVeryEasyStates, pickEasyStates); releaseStates = easyDB->merge(releaseStates, pickNormalStates); releaseStates = easyDB->merge(releaseStates, pickHardStates); releaseStates = easyDB->merge(releaseStates, pickVeryHardStates); releaseStates = GameControl::getInstance()->sortbyComplexity(GameControl::ASCENT, releaseStates); easyDB->saveGames(".\\data\\gameboard10\\db_e2_release_random10.dat", releaseStates); Statistic ss; cout << ss.mean(Statistic::BRANCH, veryEasyDB->states) << endl; cout << ss.mean(Statistic::BRANCH, easyDB->states) << endl; cout << ss.mean(Statistic::BRANCH, normalDB->states) << endl; cout << ss.mean(Statistic::BRANCH, hardDB->states) << endl; cout << ss.mean(Statistic::BRANCH, veryHardDB->states) << endl; cout << "==============" << endl; cout << ss.mean(Statistic::DEADEND, veryEasyDB->states) << endl; cout << ss.mean(Statistic::DEADEND, easyDB->states) << endl; cout << ss.mean(Statistic::DEADEND, normalDB->states) << endl; cout << ss.mean(Statistic::DEADEND, hardDB->states) << endl; cout << ss.mean(Statistic::DEADEND, veryHardDB->states) << endl; cout << "==============" << endl; cout << ss.mean(Statistic::COMPLEXITY, veryEasyDB->states) << endl; cout << ss.mean(Statistic::COMPLEXITY, easyDB->states) << endl; cout << ss.mean(Statistic::COMPLEXITY, normalDB->states) << endl; cout << ss.mean(Statistic::COMPLEXITY, hardDB->states) << endl; cout << ss.mean(Statistic::COMPLEXITY, veryHardDB->states) << endl; //vector<GameState*> states = db->pickStates(personalData->puzzleDB->states, db->states); GameControl::getInstance()->states = veryEasyDB->states; gameControl->setStateIndex(0); //GameControl::getInstance()->sortSolvedSequence(); //db->saveGames(".\\data\\gameboard10\\db_ALL_GAME_remove_same.dat", db->states); //system("pause"); }
int main(int argc, char** argv) { ros::init(argc, argv, "AI"); ros::NodeHandle ros_node; ros::Rate loop_rate(20); GameControl gameControl; Sensors sensor(gameControl); BrianParser parser(gameControl, sensor); clock_t startGame = clock(); ros::Publisher motion = ros_node.advertise<SpyKee::Motion>("spykee_motion", 1000); ros::Subscriber sonar_sub = ros_node.subscribe("sonar_data", 1000, &Sensors::sonarCallBack, &sensor); ros::Subscriber rfid_sub = ros_node.subscribe("rfid_data", 1000, &Sensors::rfidCallBack, &sensor); ros::Subscriber bt_sub = ros_node.subscribe("bt_data", 1000, &Sensors::btCallBack, &sensor); ros::Subscriber ir_sub = ros_node.subscribe("ir_data", 1000, &Sensors::irCallBack, &sensor); ros::Subscriber video_sub = ros_node.subscribe("vision_results", 1000, &Sensors::videoCallBack, &sensor); /* ros::ServiceClient redLedClient = ros_node.serviceClient<Echoes::FixedLed>("red_led"); ros::ServiceClient greenLedClient = ros_node.serviceClient<Echoes::BlinkingLed>("green_led"); ros::ServiceClient redResetClient = ros_node.serviceClient<Echoes::ResetLed>("reset_led"); */ while(ros::ok()) { parser.go(); SpyKee::Motion msg; msg.tanSpeed = parser.getTanSpeed(); msg.rotSpeed = parser.getRotSpeed(); //msg.tanSpeed = 0; //msg.rotSpeed = 0; /* if (gameControl.isSuperMode()) { Echoes::FixedLed service; service.request.numOn = 4; redLedClient.call(service); } else { Echoes::ResetLed service; redResetClient.call(service); } */ if (sensor.getContact()) { if (gameControl.isSuperMode()) cout << "The winner is PacBot" << endl; else cout << "The winner is GhostBot" << endl; exit(EXIT_SUCCESS); } if (sensor.finishedPacDots()) { cout << "Finished Pac Dots.\nThe winner is PacBot" << endl; exit(EXIT_SUCCESS); } if (100 * (clock() - startGame) / (double) CLOCKS_PER_SEC > 15) motion.publish(msg); ros::spinOnce(); loop_rate.sleep(); } return 0; }
static int CanSave() { //some of these restrictions might not be needed Store * store = core->GetCurrentStore(); if (store) { displaymsg->DisplayConstantString(STR_CANTSAVESTORE, DMC_BG2XPGREEN); return 1; //can't save while store is open } GameControl *gc = core->GetGameControl(); if (!gc) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return -1; //no gamecontrol!!! } if (gc->GetDialogueFlags()&DF_IN_DIALOG) { displaymsg->DisplayConstantString(STR_CANTSAVEDIALOG, DMC_BG2XPGREEN); return 2; //can't save while in dialog } //TODO: can't save while in combat Game *game = core->GetGame(); if (!game) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return -1; } if (game->CombatCounter) { displaymsg->DisplayConstantString(STR_CANTSAVECOMBAT, DMC_BG2XPGREEN); return 3; } Map *map = game->GetCurrentArea(); if (!map) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return -1; } if (map->AreaFlags&AF_SAVE) { //cannot save in area displaymsg->DisplayConstantString(STR_CANTSAVEMONS, DMC_BG2XPGREEN); return 4; } int i = game->GetPartySize(true); while(i--) { Actor *actor = game->GetPC(i, true); //TODO: can't save while (party) actors are in helpless states if (actor->GetStat(IE_STATE_ID) & STATE_NOSAVE) { //some actor is in nosave state displaymsg->DisplayConstantString(STR_CANTSAVENOCTRL, DMC_BG2XPGREEN); return 5; } if (actor->GetCurrentArea()!=map) { //scattered displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return 6; } } //TODO: can't save while AOE spells are in effect -> CANTSAVE //TODO: can't save while IF_NOINT is set on any actor -> CANTSAVEDIALOG2 (dialog about to start) //TODO: can't save during a rest, chapter information or movie -> CANTSAVEMOVIE //TODO: can't save while enemies are visible? AnyPCSeesEnemy -> CANTSAVEMONS return 0; }
static int CanSave() { //some of these restrictions might not be needed Store * store = core->GetCurrentStore(); if (store) { displaymsg->DisplayConstantString(STR_CANTSAVESTORE, DMC_BG2XPGREEN); return 1; //can't save while store is open } GameControl *gc = core->GetGameControl(); if (!gc) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return -1; //no gamecontrol!!! } if (gc->GetDialogueFlags()&DF_IN_DIALOG) { displaymsg->DisplayConstantString(STR_CANTSAVEDIALOG, DMC_BG2XPGREEN); return 2; //can't save while in dialog } Game *game = core->GetGame(); if (!game) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return -1; } if (game->CombatCounter) { displaymsg->DisplayConstantString(STR_CANTSAVECOMBAT, DMC_BG2XPGREEN); return 3; } Map *map = game->GetCurrentArea(); if (!map) { displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return -1; } if (map->AreaFlags&AF_NOSAVE) { //cannot save in area displaymsg->DisplayConstantString(STR_CANTSAVEMONS, DMC_BG2XPGREEN); return 4; } int i = game->GetPartySize(true); while(i--) { Actor *actor = game->GetPC(i, true); // can't save while (party) actors are in helpless or dead states // STATE_NOSAVE tracks actors not to be stored in GAM, not game saveability if (actor->GetStat(IE_STATE_ID) & (STATE_NOSAVE|STATE_MINDLESS)) { //some actor is in nosave state displaymsg->DisplayConstantString(STR_CANTSAVENOCTRL, DMC_BG2XPGREEN); return 5; } if (actor->GetCurrentArea()!=map) { //scattered displaymsg->DisplayConstantString(STR_CANTSAVE, DMC_BG2XPGREEN); return 6; } if (map->AnyEnemyNearPoint(actor->Pos)) { displaymsg->DisplayConstantString( STR_CANTSAVEMONS, DMC_BG2XPGREEN ); return 7; } } Point pc1 = game->GetPC(0, true)->Pos; Actor **nearActors = map->GetAllActorsInRadius(pc1, GA_NO_DEAD|GA_NO_UNSCHEDULED, 15*10); i = 0; while (nearActors[i]) { Actor *actor = nearActors[i]; if (actor->GetInternalFlag() & IF_NOINT) { // dialog about to start or similar displaymsg->DisplayConstantString(STR_CANTSAVEDIALOG2, DMC_BG2XPGREEN); return 8; } i++; } free(nearActors); //TODO: can't save while AOE spells are in effect -> CANTSAVE //TODO: can't save during a rest, chapter information or movie -> CANTSAVEMOVIE return 0; }
void TextArea::CalcRowCount() { int tr; int w = Width; if (Flags&IE_GUI_TEXTAREA_SPEAKER) { const char *portrait = NULL; Actor *actor = NULL; GameControl *gc = core->GetGameControl(); if (gc) { actor = gc->GetTarget(); } if (actor) { portrait = actor->GetPortrait(1); } if (portrait) { RefreshSprite(portrait); } if (AnimPicture) { w-=AnimPicture->Width; } } rows = 0; if (lines.size() != 0) { for (size_t i = 0; i < lines.size(); i++) { // rows++; tr = 0; int len = ( int ) strlen( lines[i] ); char* tmp = (char *) malloc( len + 1 ); memcpy( tmp, lines[i], len + 1 ); ftext->SetupString( tmp, w ); for (int p = 0; p <= len; p++) { if (( ( unsigned char ) tmp[p] ) == '[') { p++; //char tag[256]; int k = 0; for (k = 0; k < 256; k++) { if (tmp[p] == ']') { //tag[k] = 0; break; } p++; //tag[k] = tmp[p++]; } continue; } if (tmp[p] == 0) { // if (p != len) // rows++; tr++; } } lrows[i] = tr; rows += tr; free( tmp ); } } if (lines.size()) { if (CurLine>=lines.size()) { CurLine=lines.size()-1; } w = strlen(lines[CurLine]); if (CurPos>w) { CurPos = w; } } else { CurLine=0; CurPos=0; } if (!sb) { return; } ScrollBar* bar = ( ScrollBar* ) sb; tr = rows - Height/ftext->size[1].h + 1; if (tr<0) { tr = 0; } bar->SetMax( (ieWord) tr ); }