From ef11f9d0c53cbdd9d88a99143de6f43f34d7e24d Mon Sep 17 00:00:00 2001 From: Einar Johan Trøan Sømåen Date: Thu, 26 Jul 2012 15:59:26 +0200 Subject: WINTERMUTE: Run Astyle with add-braces to break one-line statements into easier-to-read-code. --- engines/wintermute/ad/ad_actor.cpp | 408 ++++++---- engines/wintermute/ad/ad_entity.cpp | 270 +++++-- engines/wintermute/ad/ad_game.cpp | 614 ++++++++++----- engines/wintermute/ad/ad_inventory.cpp | 35 +- engines/wintermute/ad/ad_inventory_box.cpp | 35 +- engines/wintermute/ad/ad_item.cpp | 143 ++-- engines/wintermute/ad/ad_layer.cpp | 83 +- engines/wintermute/ad/ad_node_state.cpp | 53 +- engines/wintermute/ad/ad_object.cpp | 248 ++++-- engines/wintermute/ad/ad_object.h | 2 +- engines/wintermute/ad/ad_path.cpp | 21 +- engines/wintermute/ad/ad_region.cpp | 24 +- engines/wintermute/ad/ad_response.cpp | 8 +- engines/wintermute/ad/ad_response_box.cpp | 151 ++-- engines/wintermute/ad/ad_response_context.cpp | 8 +- engines/wintermute/ad/ad_response_context.h | 2 +- engines/wintermute/ad/ad_rot_level.cpp | 8 +- engines/wintermute/ad/ad_scale_level.cpp | 8 +- engines/wintermute/ad/ad_scene.cpp | 625 ++++++++++----- engines/wintermute/ad/ad_scene_state.cpp | 16 +- engines/wintermute/ad/ad_sentence.cpp | 102 ++- engines/wintermute/ad/ad_sprite_set.cpp | 100 ++- engines/wintermute/ad/ad_talk_def.cpp | 64 +- engines/wintermute/ad/ad_talk_holder.cpp | 107 ++- engines/wintermute/ad/ad_talk_node.cpp | 82 +- engines/wintermute/ad/ad_waypoint_group.cpp | 26 +- engines/wintermute/base/base.cpp | 28 +- engines/wintermute/base/base_active_rect.cpp | 8 +- engines/wintermute/base/base_dynamic_buffer.cpp | 28 +- engines/wintermute/base/base_fader.cpp | 45 +- engines/wintermute/base/base_file_manager.cpp | 52 +- engines/wintermute/base/base_frame.cpp | 124 ++- engines/wintermute/base/base_game.cpp | 859 ++++++++++++++------- engines/wintermute/base/base_keyboard_state.cpp | 24 +- engines/wintermute/base/base_named_object.cpp | 7 +- engines/wintermute/base/base_object.cpp | 291 ++++--- engines/wintermute/base/base_parser.cpp | 76 +- .../wintermute/base/base_persistence_manager.cpp | 97 ++- engines/wintermute/base/base_quick_msg.cpp | 8 +- engines/wintermute/base/base_region.cpp | 87 ++- engines/wintermute/base/base_registry.cpp | 43 +- engines/wintermute/base/base_save_thumb_helper.cpp | 4 +- engines/wintermute/base/base_script_holder.cpp | 55 +- engines/wintermute/base/base_scriptable.cpp | 39 +- engines/wintermute/base/base_sprite.cpp | 162 ++-- engines/wintermute/base/base_string_table.cpp | 49 +- engines/wintermute/base/base_sub_frame.cpp | 137 ++-- engines/wintermute/base/base_surface_storage.cpp | 45 +- .../wintermute/base/base_transition_manager.cpp | 17 +- engines/wintermute/base/file/base_disk_file.cpp | 11 +- engines/wintermute/base/file/base_file_entry.cpp | 4 +- engines/wintermute/base/file/base_package.cpp | 18 +- .../wintermute/base/file/base_save_thumb_file.cpp | 27 +- engines/wintermute/base/font/base_font.cpp | 7 +- engines/wintermute/base/font/base_font_bitmap.cpp | 115 ++- engines/wintermute/base/font/base_font_storage.cpp | 16 +- .../wintermute/base/font/base_font_truetype.cpp | 119 ++- engines/wintermute/base/font/base_font_truetype.h | 4 +- engines/wintermute/base/gfx/base_image.cpp | 76 +- engines/wintermute/base/gfx/base_renderer.cpp | 28 +- engines/wintermute/base/gfx/base_surface.cpp | 8 +- .../base/gfx/osystem/base_render_osystem.cpp | 55 +- .../base/gfx/osystem/base_surface_osystem.cpp | 41 +- engines/wintermute/base/particles/part_emitter.cpp | 140 +++- .../wintermute/base/particles/part_particle.cpp | 36 +- engines/wintermute/base/scriptables/script.cpp | 292 +++++-- .../wintermute/base/scriptables/script_engine.cpp | 167 ++-- .../wintermute/base/scriptables/script_engine.h | 8 +- .../base/scriptables/script_ext_array.cpp | 35 +- .../wintermute/base/scriptables/script_ext_array.h | 2 +- .../base/scriptables/script_ext_date.cpp | 9 +- .../base/scriptables/script_ext_file.cpp | 166 ++-- .../base/scriptables/script_ext_math.cpp | 8 +- .../base/scriptables/script_ext_mem_buffer.cpp | 118 +-- .../base/scriptables/script_ext_string.cpp | 120 +-- .../wintermute/base/scriptables/script_stack.cpp | 14 +- .../wintermute/base/scriptables/script_value.cpp | 197 +++-- engines/wintermute/base/sound/base_sound.cpp | 113 ++- .../wintermute/base/sound/base_sound_manager.cpp | 19 +- engines/wintermute/math/math_util.cpp | 8 +- engines/wintermute/system/sys_class.cpp | 19 +- engines/wintermute/system/sys_class_registry.cpp | 61 +- engines/wintermute/ui/ui_button.cpp | 391 +++++++--- engines/wintermute/ui/ui_edit.cpp | 252 ++++-- engines/wintermute/ui/ui_entity.cpp | 70 +- engines/wintermute/ui/ui_object.cpp | 143 +++- engines/wintermute/ui/ui_text.cpp | 91 ++- engines/wintermute/ui/ui_tiled_image.cpp | 51 +- engines/wintermute/ui/ui_window.cpp | 265 +++++-- engines/wintermute/utils/path_util.cpp | 14 +- engines/wintermute/utils/string_util.cpp | 22 +- engines/wintermute/utils/utils.cpp | 102 ++- engines/wintermute/video/video_player.cpp | 135 +++- engines/wintermute/video/video_theora_player.cpp | 96 ++- 94 files changed, 6430 insertions(+), 2791 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/ad/ad_actor.cpp b/engines/wintermute/ad/ad_actor.cpp index fe1948d3a8..d1e03eac3a 100644 --- a/engines/wintermute/ad/ad_actor.cpp +++ b/engines/wintermute/ad/ad_actor.cpp @@ -129,7 +129,9 @@ bool AdActor::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ACTOR file '%s'", filename); + } delete[] buffer; @@ -235,7 +237,9 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_X: @@ -255,7 +259,7 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - SetFont((char *)params); + setFont((char *)params); break; case TOKEN_SCALABLE: @@ -285,44 +289,62 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { delete _walkSprite; _walkSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) cmd = PARSERR_GENERIC; - else _walkSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texWalkLifeTime, CACHE_HALF))) { + cmd = PARSERR_GENERIC; + } else { + _walkSprite = spr; + } break; case TOKEN_TALK: spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } break; case TOKEN_TALK_SPECIAL: spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } break; case TOKEN_STAND: delete _standSprite; _standSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) cmd = PARSERR_GENERIC; - else _standSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true, adGame->_texStandLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _standSprite = spr; + } break; case TOKEN_TURN_LEFT: delete _turnLeftSprite; _turnLeftSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; - else _turnLeftSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { + cmd = PARSERR_GENERIC; + } else { + _turnLeftSprite = spr; + } break; case TOKEN_TURN_RIGHT: delete _turnRightSprite; _turnRightSprite = NULL; spr = new AdSpriteSet(_gameRef, this); - if (!spr || DID_FAIL(spr->loadBuffer(params, true))) cmd = PARSERR_GENERIC; - else _turnRightSprite = spr; + if (!spr || DID_FAIL(spr->loadBuffer(params, true))) { + cmd = PARSERR_GENERIC; + } else { + _turnRightSprite = spr; + } break; case TOKEN_SCRIPT: @@ -426,9 +448,12 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ANIMATION: { - AdSpriteSet *Anim = new AdSpriteSet(_gameRef, this); - if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) cmd = PARSERR_GENERIC; - else _anims.add(Anim); + AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); + if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } else { + _anims.add(anim); + } } break; } @@ -438,7 +463,9 @@ bool AdActor::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } if (cmd == PARSERR_GENERIC) { - if (spr) delete spr; + if (spr) { + delete spr; + } _gameRef->LOG(0, "Error loading ACTOR definition"); return STATUS_FAILED; } @@ -482,7 +509,9 @@ void AdActor::turnTo(TDirection dir) { ////////////////////////////////////////////////////////////////////////// void AdActor::goTo(int x, int y, TDirection afterWalkDir) { _afterWalkDir = afterWalkDir; - if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) return; + if (x == _targetPoint->x && y == _targetPoint->y && _state == STATE_FOLLOWING_PATH) { + return; + } _path->reset(); _path->setReady(false); @@ -499,11 +528,16 @@ void AdActor::goTo(int x, int y, TDirection afterWalkDir) { ////////////////////////////////////////////////////////////////////////// bool AdActor::display() { - if (_active) updateSounds(); + if (_active) { + updateSounds(); + } uint32 alpha; - if (_alphaColor != 0) alpha = _alphaColor; - else alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + if (_alphaColor != 0) { + alpha = _alphaColor; + } else { + alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY, true) : 0xFFFFFFFF; + } float scaleX, scaleY; getScale(&scaleX, &scaleY); @@ -511,15 +545,24 @@ bool AdActor::display() { float rotate; if (_rotatable) { - if (_rotateValid) rotate = _rotate; - else rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } else rotate = 0.0f; + if (_rotateValid) { + rotate = _rotate; + } else { + rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } + } else { + rotate = 0.0f; + } - if (_active) displaySpriteAttachments(true); + if (_active) { + displaySpriteAttachments(true); + } if (_currentSprite && _active) { bool reg = _registrable; - if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) reg = false; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { + reg = false; + } _currentSprite->display(_posX, _posY, @@ -532,8 +575,12 @@ bool AdActor::display() { } - if (_active) displaySpriteAttachments(false); - if (_active && _partEmitter) _partEmitter->display(); + if (_active) { + displaySpriteAttachments(false); + } + if (_active && _partEmitter) { + _partEmitter->display(); + } return STATUS_OK; @@ -567,17 +614,22 @@ bool AdActor::update() { _currentSprite = _animSprite2; } - if (_sentence && _state != STATE_TALKING) _sentence->finish(); + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } // default: stand animation if (!_currentSprite) { - if (_sprite) _currentSprite = _sprite; - else { + if (_sprite) { + _currentSprite = _sprite; + } else { if (_standSprite) { _currentSprite = _standSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } } } @@ -598,8 +650,11 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_TURNING_LEFT: if (_tempSprite2 == NULL || _tempSprite2->_finished) { - if (_dir > 0) _dir = (TDirection)(_dir - 1); - else _dir = (TDirection)(NUM_DIRECTIONS - 1); + if (_dir > 0) { + _dir = (TDirection)(_dir - 1); + } else { + _dir = (TDirection)(NUM_DIRECTIONS - 1); + } if (_dir == _targetDir) { _tempSprite2 = NULL; @@ -609,17 +664,23 @@ bool AdActor::update() { if (_turnLeftSprite) { _tempSprite2 = _turnLeftSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_turnLeftAnimName); - if (Anim) _tempSprite2 = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_turnLeftAnimName); + if (anim) { + _tempSprite2 = anim->getSprite(_dir); + } } if (_tempSprite2) { _tempSprite2->reset(); - if (_tempSprite2->_looping) _tempSprite2->_looping = false; + if (_tempSprite2->_looping) { + _tempSprite2->_looping = false; + } } _currentSprite = _tempSprite2; } - } else _currentSprite = _tempSprite2; + } else { + _currentSprite = _tempSprite2; + } break; @@ -628,7 +689,9 @@ bool AdActor::update() { if (_tempSprite2 == NULL || _tempSprite2->_finished) { _dir = (TDirection)(_dir + 1); - if ((int)_dir >= (int)NUM_DIRECTIONS) _dir = (TDirection)(0); + if ((int)_dir >= (int)NUM_DIRECTIONS) { + _dir = (TDirection)(0); + } if (_dir == _targetDir) { _tempSprite2 = NULL; @@ -638,32 +701,41 @@ bool AdActor::update() { if (_turnRightSprite) { _tempSprite2 = _turnRightSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_turnRightAnimName); - if (Anim) _tempSprite2 = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_turnRightAnimName); + if (anim) { + _tempSprite2 = anim->getSprite(_dir); + } } if (_tempSprite2) { _tempSprite2->reset(); - if (_tempSprite2->_looping) _tempSprite2->_looping = false; + if (_tempSprite2->_looping) { + _tempSprite2->_looping = false; + } } _currentSprite = _tempSprite2; } - } else _currentSprite = _tempSprite2; + } else { + _currentSprite = _tempSprite2; + } break; ////////////////////////////////////////////////////////////////////////// case STATE_SEARCHING_PATH: // keep asking scene for the path - if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) + if (((AdGame *)_gameRef)->_scene->getPath(BasePoint(_posX, _posY), *_targetPoint, _path, this)) { _state = STATE_WAITING_PATH; + } break; ////////////////////////////////////////////////////////////////////////// case STATE_WAITING_PATH: // wait until the scene finished the path - if (_path->_ready) followPath(); + if (_path->_ready) { + followPath(); + } break; @@ -676,7 +748,9 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_TALKING: { _sentence->update(_dir); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { @@ -703,13 +777,16 @@ bool AdActor::update() { ////////////////////////////////////////////////////////////////////////// case STATE_READY: if (!_animSprite && !_animSprite2) { - if (_sprite) _currentSprite = _sprite; - else { + if (_sprite) { + _currentSprite = _sprite; + } else { if (_standSprite) { _currentSprite = _standSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } } } @@ -745,7 +822,9 @@ void AdActor::followPath() { // skip current position _path->getFirst(); while (_path->getCurrent() != NULL) { - if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) break; + if (_path->getCurrent()->x != _posX || _path->getCurrent()->y != _posY) { + break; + } _path->getNext(); } @@ -754,8 +833,11 @@ void AdActor::followPath() { _state = STATE_FOLLOWING_PATH;; initLine(BasePoint(_posX, _posY), *_path->getCurrent()); } else { - if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); - else _state = STATE_READY; + if (_afterWalkDir != DI_NONE) { + turnTo(_afterWalkDir); + } else { + _state = STATE_READY; + } } } @@ -765,14 +847,20 @@ void AdActor::getNextStep() { if (_walkSprite) { _currentSprite = _walkSprite->getSprite(_dir); } else { - AdSpriteSet *Anim = getAnimByName(_walkAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(_walkAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } - if (!_currentSprite) return; + if (!_currentSprite) { + return; + } _currentSprite->GetCurrentFrame(_zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100, _zoomable ? ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) : 100); - if (!_currentSprite->_changed) return; + if (!_currentSprite->_changed) { + return; + } int maxStepX, maxStepY; @@ -813,12 +901,15 @@ void AdActor::getNextStep() { _posY = _targetPoint->y; _path->reset(); - if (_afterWalkDir != DI_NONE) turnTo(_afterWalkDir); - else { + if (_afterWalkDir != DI_NONE) { + turnTo(_afterWalkDir); + } else { _state = _nextState; _nextState = STATE_READY; } - } else initLine(BasePoint(_posX, _posY), *_path->getCurrent()); + } else { + initLine(BasePoint(_posX, _posY), *_path->getCurrent()); + } } } @@ -853,7 +944,9 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, int X = stack->pop()->getInt(); int Y = stack->pop()->getInt(); goTo(X, Y); - if (strcmp(name, "GoToAsync") != 0) script->waitForExclusive(this); + if (strcmp(name, "GoToAsync") != 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; } @@ -863,22 +956,27 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GoToObject") == 0 || strcmp(name, "GoToObjectAsync") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); - if (!Val->isNative()) { + ScValue *val = stack->pop(); + if (!val->isNative()) { script->runtimeError("actor.%s method accepts an entity refrence only", name); stack->pushNULL(); return STATUS_OK; } - AdObject *Obj = (AdObject *)Val->getNative(); - if (!Obj || Obj->_type != OBJECT_ENTITY) { + AdObject *obj = (AdObject *)val->getNative(); + if (!obj || obj->_type != OBJECT_ENTITY) { script->runtimeError("actor.%s method accepts an entity refrence only", name); stack->pushNULL(); return STATUS_OK; } - AdEntity *Ent = (AdEntity *)Obj; - if (Ent->_walkToX == 0 && Ent->_walkToY == 0) goTo(Ent->_posX, Ent->_posY); - else goTo(Ent->_walkToX, Ent->_walkToY, Ent->_walkToDir); - if (strcmp(name, "GoToObjectAsync") != 0) script->waitForExclusive(this); + AdEntity *ent = (AdEntity *)obj; + if (ent->_walkToX == 0 && ent->_walkToY == 0) { + goTo(ent->_posX, ent->_posY); + } else { + goTo(ent->_walkToX, ent->_walkToY, ent->_walkToDir); + } + if (strcmp(name, "GoToObjectAsync") != 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; } @@ -898,11 +996,15 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, dir = (int)angleToDirection(angle); } // otherwise turn to direction - else dir = val->getInt(); + else { + dir = val->getInt(); + } if (dir >= 0 && dir < NUM_DIRECTIONS) { turnTo((TDirection)dir); - if (strcmp(name, "TurnToAsync") != 0) script->waitForExclusive(this); + if (strcmp(name, "TurnToAsync") != 0) { + script->waitForExclusive(this); + } } stack->pushNULL(); return STATUS_OK; @@ -937,9 +1039,15 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, for (int i = 0; i < _anims.getSize(); i++) { if (scumm_stricmp(_anims[i]->getName(), AnimName) == 0) { // invalidate sprites in use - if (_anims[i]->containsSprite(_tempSprite2)) _tempSprite2 = NULL; - if (_anims[i]->containsSprite(_currentSprite)) _currentSprite = NULL; - if (_anims[i]->containsSprite(_animSprite2)) _animSprite2 = NULL; + if (_anims[i]->containsSprite(_tempSprite2)) { + _tempSprite2 = NULL; + } + if (_anims[i]->containsSprite(_currentSprite)) { + _currentSprite = NULL; + } + if (_anims[i]->containsSprite(_animSprite2)) { + _animSprite2 = NULL; + } delete _anims[i]; _anims[i] = NULL; @@ -960,9 +1068,9 @@ bool AdActor::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *AnimName = stack->pop()->getString(); stack->pushBool(getAnimByName(AnimName) != NULL); return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } - - else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } @@ -1022,9 +1130,9 @@ ScValue *AdActor::scGetProperty(const char *name) { else if (strcmp(name, "TurnRightAnimName") == 0) { _scValue->setString(_turnRightAnimName); return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); } - - else return AdTalkHolder::scGetProperty(name); } @@ -1035,7 +1143,9 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "Direction") == 0) { int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) _dir = (TDirection)dir; + if (dir >= 0 && dir < NUM_DIRECTIONS) { + _dir = (TDirection)dir; + } return STATUS_OK; } @@ -1043,8 +1153,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // TalkAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TalkAnimName") == 0) { - if (value->isNULL()) _talkAnimName = "talk"; - else _talkAnimName = value->getString(); + if (value->isNULL()) { + _talkAnimName = "talk"; + } else { + _talkAnimName = value->getString(); + } return STATUS_OK; } @@ -1052,8 +1165,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // WalkAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "WalkAnimName") == 0) { - if (value->isNULL()) _walkAnimName = "walk"; - else _walkAnimName = value->getString(); + if (value->isNULL()) { + _walkAnimName = "walk"; + } else { + _walkAnimName = value->getString(); + } return STATUS_OK; } @@ -1061,8 +1177,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // IdleAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IdleAnimName") == 0) { - if (value->isNULL()) _idleAnimName = "idle"; - else _idleAnimName = value->getString(); + if (value->isNULL()) { + _idleAnimName = "idle"; + } else { + _idleAnimName = value->getString(); + } return STATUS_OK; } @@ -1070,8 +1189,11 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // TurnLeftAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TurnLeftAnimName") == 0) { - if (value->isNULL()) _turnLeftAnimName = "turnleft"; - else _turnLeftAnimName = value->getString(); + if (value->isNULL()) { + _turnLeftAnimName = "turnleft"; + } else { + _turnLeftAnimName = value->getString(); + } return STATUS_OK; } @@ -1079,12 +1201,15 @@ bool AdActor::scSetProperty(const char *name, ScValue *value) { // TurnRightAnimName ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TurnRightAnimName") == 0) { - if (value->isNULL()) _turnRightAnimName = "turnright"; - else _turnRightAnimName = value->getString(); + if (value->isNULL()) { + _turnRightAnimName = "turnright"; + } else { + _turnRightAnimName = value->getString(); + } return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); } - - else return AdTalkHolder::scSetProperty(name, value); } @@ -1107,37 +1232,46 @@ BaseSprite *AdActor::getTalkStance(const char *stance) { _gameRef->LOG(res, "AdActor::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; - } else return _animSprite; + } else { + return _animSprite; + } } } // old way - if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) + if (_talkSprites.getSize() > 0 || _talkSpritesEx.getSize() > 0) { return getTalkStanceOld(stance); + } // new way BaseSprite *ret = NULL; // do we have an animation with this name? - AdSpriteSet *Anim = getAnimByName(stance); - if (Anim) ret = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(stance); + if (anim) { + ret = anim->getSprite(_dir); + } // not - get a random talk if (!ret) { - BaseArray TalkAnims; + BaseArray talkAnims; for (int i = 0; i < _anims.getSize(); i++) { - if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) - TalkAnims.add(_anims[i]); + if (_talkAnimName.compareToIgnoreCase(_anims[i]->getName()) == 0) { + talkAnims.add(_anims[i]); + } } - if (TalkAnims.getSize() > 0) { - int rnd = g_wintermute->randInt(0, TalkAnims.getSize() - 1); - ret = TalkAnims[rnd]->getSprite(_dir); + if (talkAnims.getSize() > 0) { + int rnd = g_wintermute->randInt(0, talkAnims.getSize() - 1); + ret = talkAnims[rnd]->getSprite(_dir); } else { - if (_standSprite) ret = _standSprite->getSprite(_dir); - else { - Anim = getAnimByName(_idleAnimName); - if (Anim) ret = Anim->getSprite(_dir); + if (_standSprite) { + ret = _standSprite->getSprite(_dir); + } else { + anim = getAnimByName(_idleAnimName); + if (anim) { + ret = anim->getSprite(_dir); + } } } } @@ -1169,8 +1303,9 @@ BaseSprite *AdActor::getTalkStanceOld(const char *stance) { // not a valid stance? get a random one if (ret == NULL) { - if (_talkSprites.getSize() < 1) ret = _standSprite->getSprite(_dir); - else { + if (_talkSprites.getSize() < 1) { + ret = _standSprite->getSprite(_dir); + } else { // TODO: remember last int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); ret = _talkSprites[rnd]->getSprite(_dir); @@ -1218,14 +1353,23 @@ bool AdActor::persist(BasePersistenceManager *persistMgr) { TDirection AdActor::angleToDirection(int angle) { TDirection ret = DI_DOWN;; - if (angle > -112 && angle <= -67) ret = DI_UP; - else if (angle > -67 && angle <= -22) ret = DI_UPRIGHT; - else if (angle > -22 && angle <= 22) ret = DI_RIGHT; - else if (angle > 22 && angle <= 67) ret = DI_DOWNRIGHT; - else if (angle > 67 && angle <= 112) ret = DI_DOWN; - else if (angle > 112 && angle <= 157) ret = DI_DOWNLEFT; - else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) ret = DI_LEFT; - else if (angle > -157 && angle <= -112) ret = DI_UPLEFT; + if (angle > -112 && angle <= -67) { + ret = DI_UP; + } else if (angle > -67 && angle <= -22) { + ret = DI_UPRIGHT; + } else if (angle > -22 && angle <= 22) { + ret = DI_RIGHT; + } else if (angle > 22 && angle <= 67) { + ret = DI_DOWNRIGHT; + } else if (angle > 67 && angle <= 112) { + ret = DI_DOWN; + } else if (angle > 112 && angle <= 157) { + ret = DI_DOWNLEFT; + } else if ((angle > 157 && angle <= 180) || (angle >= -180 && angle <= -157)) { + ret = DI_LEFT; + } else if (angle > -157 && angle <= -112) { + ret = DI_UPLEFT; + } return ret; } @@ -1235,10 +1379,13 @@ TDirection AdActor::angleToDirection(int angle) { int AdActor::getHeight() { // if no current sprite is set, set some if (_currentSprite == NULL) { - if (_standSprite) _currentSprite = _standSprite->getSprite(_dir); - else { - AdSpriteSet *Anim = getAnimByName(_idleAnimName); - if (Anim) _currentSprite = Anim->getSprite(_dir); + if (_standSprite) { + _currentSprite = _standSprite->getSprite(_dir); + } else { + AdSpriteSet *anim = getAnimByName(_idleAnimName); + if (anim) { + _currentSprite = anim->getSprite(_dir); + } } } // and get height @@ -1249,8 +1396,9 @@ int AdActor::getHeight() { ////////////////////////////////////////////////////////////////////////// AdSpriteSet *AdActor::getAnimByName(const Common::String &animName) { for (int i = 0; i < _anims.getSize(); i++) { - if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) + if (animName.compareToIgnoreCase(_anims[i]->getName()) == 0) { return _anims[i]; + } } return NULL; } @@ -1278,11 +1426,13 @@ bool AdActor::mergeAnims(const char *animsFilename) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_ANIMATION: { - AdSpriteSet *Anim = new AdSpriteSet(_gameRef, this); - if (!Anim || DID_FAIL(Anim->loadBuffer(params, false))) { + AdSpriteSet *anim = new AdSpriteSet(_gameRef, this); + if (!anim || DID_FAIL(anim->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; Ret = STATUS_FAILED; - } else _anims.add(Anim); + } else { + _anims.add(anim); + } } break; } @@ -1294,9 +1444,9 @@ bool AdActor::mergeAnims(const char *animsFilename) { ////////////////////////////////////////////////////////////////////////// bool AdActor::playAnim(const char *filename) { // if we have an anim with this name, use it - AdSpriteSet *Anim = getAnimByName(filename); - if (Anim) { - _animSprite2 = Anim->getSprite(_dir); + AdSpriteSet *anim = getAnimByName(filename); + if (anim) { + _animSprite2 = anim->getSprite(_dir); if (_animSprite2) { _animSprite2->reset(); _state = STATE_PLAYING_ANIM_SET; diff --git a/engines/wintermute/ad/ad_entity.cpp b/engines/wintermute/ad/ad_entity.cpp index 98fb296bf5..aa30a0096c 100644 --- a/engines/wintermute/ad/ad_entity.cpp +++ b/engines/wintermute/ad/ad_entity.cpp @@ -94,7 +94,9 @@ bool AdEntity::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ENTITY file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ENTITY file '%s'", filename); + } delete[] buffer; @@ -212,7 +214,9 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_X: @@ -227,22 +231,31 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { delete _sprite; _sprite = NULL; spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params))) cmd = PARSERR_GENERIC; - else _sprite = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } else { + _sprite = spr; + } } break; case TOKEN_TALK: { spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } } break; case TOKEN_TALK_SPECIAL: { spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, adGame->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } } break; @@ -259,7 +272,7 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - SetFont((char *)params); + setFont((char *)params); break; case TOKEN_SCALABLE: @@ -316,11 +329,14 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_REGION: { - if (_region) _gameRef->unregisterObject(_region); + if (_region) { + _gameRef->unregisterObject(_region); + } _region = NULL; BaseRegion *rgn = new BaseRegion(_gameRef); - if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) cmd = PARSERR_GENERIC; - else { + if (!rgn || DID_FAIL(rgn->loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } else { _region = rgn; _gameRef->registerObject(_region); } @@ -379,10 +395,15 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { _sprite = NULL; if (_gameRef->_editorMode) { spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) cmd = PARSERR_GENERIC; - else _sprite = spr; + if (!spr || DID_FAIL(spr->loadFile("entity_sound.sprite"))) { + cmd = PARSERR_GENERIC; + } else { + _sprite = spr; + } + } + if (_gameRef->_editorMode) { + _editorOnly = true; } - if (_gameRef->_editorMode) _editorOnly = true; _zoomable = false; _rotatable = false; _registrable = _gameRef->_editorMode; @@ -443,8 +464,12 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { case TOKEN_WALK_TO_DIR: { int i; parser.scanStr((char *)params, "%d", &i); - if (i < 0) i = 0; - if (i >= NUM_DIRECTIONS) i = DI_NONE; + if (i < 0) { + i = 0; + } + if (i >= NUM_DIRECTIONS) { + i = DI_NONE; + } _walkToDir = (TDirection)i; } break; @@ -456,7 +481,9 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { } if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading ENTITY definition"); - if (spr) delete spr; + if (spr) { + delete spr; + } return STATUS_FAILED; } @@ -472,7 +499,9 @@ bool AdEntity::loadBuffer(byte *buffer, bool complete) { _alphaColor = BYTETORGBA(ar, ag, ab, alpha); _state = STATE_READY; - if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) _active = false; + if (_item && ((AdGame *)_gameRef)->isItemTaken(_item)) { + _active = false; + } return STATUS_OK; } @@ -483,43 +512,55 @@ bool AdEntity::display() { if (_active) { updateSounds(); - uint32 Alpha; - if (_alphaColor != 0) Alpha = _alphaColor; - else Alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + uint32 alpha; + if (_alphaColor != 0) { + alpha = _alphaColor; + } else { + alpha = _shadowable ? ((AdGame *)_gameRef)->_scene->getAlphaAt(_posX, _posY) : 0xFFFFFFFF; + } - float ScaleX, ScaleY; - getScale(&ScaleX, &ScaleY); + float scaleX, scaleY; + getScale(&scaleX, &scaleY); - float Rotate; + float rotate; if (_rotatable) { - if (_rotateValid) Rotate = _rotate; - else Rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; - } else Rotate = 0.0f; + if (_rotateValid) { + rotate = _rotate; + } else { + rotate = ((AdGame *)_gameRef)->_scene->getRotationAt(_posX, _posY) + _relativeRotate; + } + } else { + rotate = 0.0f; + } - bool Reg = _registrable; - if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) Reg = false; + bool reg = _registrable; + if (_ignoreItems && ((AdGame *)_gameRef)->_selectedItem) { + reg = false; + } - if (_region && (Reg || _editorAlwaysRegister)) { + if (_region && (reg || _editorAlwaysRegister)) { _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, _registerAlias, _region, _gameRef->_offsetX, _gameRef->_offsetY)); } displaySpriteAttachments(true); if (_theora && (_theora->isPlaying() || _theora->isPaused())) { - _theora->display(Alpha); + _theora->display(alpha); } else if (_currentSprite) { _currentSprite->display(_posX, _posY, - (Reg || _editorAlwaysRegister) ? _registerAlias : NULL, - ScaleX, - ScaleY, - Alpha, - Rotate, + (reg || _editorAlwaysRegister) ? _registerAlias : NULL, + scaleX, + scaleY, + alpha, + rotate, _blendMode); } displaySpriteAttachments(false); - if (_partEmitter) _partEmitter->display(_region); + if (_partEmitter) { + _partEmitter->display(_region); + } } return STATUS_OK; @@ -541,10 +582,14 @@ bool AdEntity::update() { _currentSprite = _animSprite; } - if (_sentence && _state != STATE_TALKING) _sentence->finish(); + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } // default: stand animation - if (!_currentSprite) _currentSprite = _sprite; + if (!_currentSprite) { + _currentSprite = _sprite; + } switch (_state) { ////////////////////////////////////////////////////////////////////////// @@ -554,14 +599,17 @@ bool AdEntity::update() { ////////////////////////////////////////////////////////////////////////// case STATE_READY: - if (!_animSprite) + if (!_animSprite) { _currentSprite = _sprite; + } break; ////////////////////////////////////////////////////////////////////////// case STATE_TALKING: { _sentence->update(); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { @@ -630,8 +678,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (strcmp(name, "StopSound") == 0 && _subtype == ENTITY_SOUND) { stack->correctParams(0); - if (DID_FAIL(stopSFX(false))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(stopSFX(false))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -648,7 +699,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _theora; _theora = new VideoTheoraPlayer(_gameRef); if (_theora && DID_SUCCEED(_theora->initialize(filename))) { - if (!valAlpha->isNULL()) _theora->setAlphaImage(valAlpha->getString()); + if (!valAlpha->isNULL()) { + _theora->setAlphaImage(valAlpha->getString()); + } _theora->play(VID_PLAY_POS, 0, 0, false, false, looping, startTime, _scale >= 0.0f ? _scale : -1.0f, _sFXVolume); //if (_scale>=0) _theora->_playZoom = _scale; stack->pushBool(true); @@ -670,7 +723,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _theora; _theora = NULL; stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -680,8 +735,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IsTheoraPlaying") == 0) { stack->correctParams(0); - if (_theora && _theora->isPlaying()) stack->pushBool(true); - else stack->pushBool(false); + if (_theora && _theora->isPlaying()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -694,7 +752,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_theora && _theora->isPlaying()) { _theora->pause(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -707,7 +767,9 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_theora && _theora->isPaused()) { _theora->resume(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -717,8 +779,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IsTheoraPaused") == 0) { stack->correctParams(0); - if (_theora && _theora->isPaused()) stack->pushBool(true); - else stack->pushBool(false); + if (_theora && _theora->isPaused()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -733,8 +798,11 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack _region = new BaseRegion(_gameRef); _gameRef->registerObject(_region); } - if (_region) stack->pushNative(_region, true); - else stack->pushNULL(); + if (_region) { + stack->pushNative(_region, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -748,12 +816,14 @@ bool AdEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack _gameRef->unregisterObject(_region); _region = NULL; stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } - - else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } @@ -773,8 +843,11 @@ ScValue *AdEntity::scGetProperty(const char *name) { // Item ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Item") == 0) { - if (_item) _scValue->setString(_item); - else _scValue->setNULL(); + if (_item) { + _scValue->setString(_item); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -783,10 +856,11 @@ ScValue *AdEntity::scGetProperty(const char *name) { // Subtype (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Subtype") == 0) { - if (_subtype == ENTITY_SOUND) + if (_subtype == ENTITY_SOUND) { _scValue->setString("sound"); - else + } else { _scValue->setString("normal"); + } return _scValue; } @@ -819,12 +893,15 @@ ScValue *AdEntity::scGetProperty(const char *name) { // Region (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Region") == 0) { - if (_region) _scValue->setNative(_region, true); - else _scValue->setNULL(); + if (_region) { + _scValue->setNative(_region, true); + } else { + _scValue->setNULL(); + } return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); } - - else return AdTalkHolder::scGetProperty(name); } @@ -860,11 +937,13 @@ bool AdEntity::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "WalkToDirection") == 0) { int dir = value->getInt(); - if (dir >= 0 && dir < NUM_DIRECTIONS) _walkToDir = (TDirection)dir; + if (dir >= 0 && dir < NUM_DIRECTIONS) { + _walkToDir = (TDirection)dir; + } return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); } - - else return AdTalkHolder::scSetProperty(name, value); } @@ -878,8 +957,9 @@ const char *AdEntity::scToString() { bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ENTITY {\n"); buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); - if (_subtype == ENTITY_SOUND) + if (_subtype == ENTITY_SOUND) { buffer->putTextIndent(indent + 2, "SUBTYPE=\"SOUND\"\n"); + } buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "X=%d\n", _posX); @@ -888,23 +968,30 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "INTERACTIVE=%s\n", _registrable ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "COLORABLE=%s\n", _shadowable ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - if (_ignoreItems) + if (_ignoreItems) { buffer->putTextIndent(indent + 2, "IGNORE_ITEMS=%s\n", _ignoreItems ? "TRUE" : "FALSE"); - if (_rotatable) + } + if (_rotatable) { buffer->putTextIndent(indent + 2, "ROTATABLE=%s\n", _rotatable ? "TRUE" : "FALSE"); + } - if (!_autoSoundPanning) + if (!_autoSoundPanning) { buffer->putTextIndent(indent + 2, "SOUND_PANNING=%s\n", _autoSoundPanning ? "TRUE" : "FALSE"); + } - if (!_saveState) + if (!_saveState) { buffer->putTextIndent(indent + 2, "SAVE_STATE=%s\n", _saveState ? "TRUE" : "FALSE"); + } - if (_item && _item[0] != '\0') buffer->putTextIndent(indent + 2, "ITEM=\"%s\"\n", _item); + if (_item && _item[0] != '\0') { + buffer->putTextIndent(indent + 2, "ITEM=\"%s\"\n", _item); + } buffer->putTextIndent(indent + 2, "WALK_TO_X=%d\n", _walkToX); buffer->putTextIndent(indent + 2, "WALK_TO_Y=%d\n", _walkToY); - if (_walkToDir != DI_NONE) + if (_walkToDir != DI_NONE) { buffer->putTextIndent(indent + 2, "WALK_TO_DIR=%d\n", (int)_walkToDir); + } int i; @@ -912,8 +999,9 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) + if (_subtype == ENTITY_NORMAL && _sprite && _sprite->getFilename()) { buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _sprite->getFilename()); + } if (_subtype == ENTITY_SOUND && _sFX && _sFX->_soundFilename) { buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sFX->_soundFilename); @@ -922,29 +1010,39 @@ bool AdEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { } - if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) + if (RGBCOLGetR(_alphaColor) != 0 || RGBCOLGetG(_alphaColor) != 0 || RGBCOLGetB(_alphaColor) != 0) { buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alphaColor), RGBCOLGetG(_alphaColor), RGBCOLGetB(_alphaColor)); + } - if (RGBCOLGetA(_alphaColor) != 0) + if (RGBCOLGetA(_alphaColor) != 0) { buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alphaColor)); + } - if (_scale >= 0) + if (_scale >= 0) { buffer->putTextIndent(indent + 2, "SCALE = %d\n", (int)_scale); + } - if (_relativeScale != 0) + if (_relativeScale != 0) { buffer->putTextIndent(indent + 2, "RELATIVE_SCALE = %d\n", (int)_relativeScale); + } - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } AdTalkHolder::saveAsText(buffer, indent + 2); - if (_region) _region->saveAsText(buffer, indent + 2); + if (_region) { + _region->saveAsText(buffer, indent + 2); + } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } AdObject::saveAsText(buffer, indent + 2); @@ -959,7 +1057,9 @@ int AdEntity::getHeight() { if (_region && !_sprite) { return _region->_rect.bottom - _region->_rect.top; } else { - if (_currentSprite == NULL) _currentSprite = _sprite; + if (_currentSprite == NULL) { + _currentSprite = _sprite; + } return AdObject::getHeight(); } } diff --git a/engines/wintermute/ad/ad_game.cpp b/engines/wintermute/ad/ad_game.cpp index 259fc175ae..a6452e8837 100644 --- a/engines/wintermute/ad/ad_game.cpp +++ b/engines/wintermute/ad/ad_game.cpp @@ -142,7 +142,9 @@ bool AdGame::cleanup() { _scene = NULL; // remove items - for (i = 0; i < _items.getSize(); i++) _gameRef->unregisterObject(_items[i]); + for (i = 0; i < _items.getSize(); i++) { + _gameRef->unregisterObject(_items[i]); + } _items.removeAll(); @@ -181,13 +183,19 @@ bool AdGame::cleanup() { delete _sceneViewport; _sceneViewport = NULL; - for (i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + for (i = 0; i < _sceneStates.getSize(); i++) { + delete _sceneStates[i]; + } _sceneStates.removeAll(); - for (i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + for (i = 0; i < _responsesBranch.getSize(); i++) { + delete _responsesBranch[i]; + } _responsesBranch.removeAll(); - for (i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + for (i = 0; i < _responsesGame.getSize(); i++) { + delete _responsesGame[i]; + } _responsesGame.removeAll(); return BaseGame::cleanup(); @@ -207,9 +215,13 @@ bool AdGame::initLoop() { bool res; res = BaseGame::initLoop(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } - if (_scene) res = _scene->initLoop(); + if (_scene) { + res = _scene->initLoop(); + } _sentences.removeAll(); @@ -228,8 +240,10 @@ bool AdGame::addObject(AdObject *object) { bool AdGame::removeObject(AdObject *object) { // in case the user called Scene.CreateXXX() and Game.DeleteXXX() if (_scene) { - bool Res = _scene->removeObject(object); - if (DID_SUCCEED(Res)) return Res; + bool res = _scene->removeObject(object); + if (DID_SUCCEED(res)) { + return res; + } } for (int i = 0; i < _objects.getSize(); i++) { @@ -253,23 +267,31 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { setPrevSceneName(_scene->getName()); setPrevSceneFilename(_scene->getFilename()); - if (!_tempDisableSaveState) _scene->saveState(); + if (!_tempDisableSaveState) { + _scene->saveState(); + } _tempDisableSaveState = false; } if (_scene) { // reset objects - for (int i = 0; i < _objects.getSize(); i++) _objects[i]->reset(); + for (int i = 0; i < _objects.getSize(); i++) { + _objects[i]->reset(); + } // reset scene properties _scene->_sFXVolume = 100; - if (_scene->_scProp) _scene->_scProp->cleanup(); + if (_scene->_scProp) { + _scene->_scProp->cleanup(); + } bool ret; if (_initialScene && _debugDebugMode && _debugStartupScene) { _initialScene = false; ret = _scene->loadFile(_debugStartupScene); - } else ret = _scene->loadFile(filename); + } else { + ret = _scene->loadFile(filename); + } if (DID_SUCCEED(ret)) { // invalidate references to the original scene @@ -280,9 +302,13 @@ bool AdGame::changeScene(const char *filename, bool fadeIn) { _scene->loadState(); } - if (fadeIn) _gameRef->_transMgr->start(TRANSITION_FADE_IN); + if (fadeIn) { + _gameRef->_transMgr->start(TRANSITION_FADE_IN); + } return ret; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -295,8 +321,11 @@ void AdGame::addSentence(AdSentence *sentence) { ////////////////////////////////////////////////////////////////////////// bool AdGame::displaySentences(bool frozen) { for (int i = 0; i < _sentences.getSize(); i++) { - if (frozen && _sentences[i]->_freezable) continue; - else _sentences[i]->display(); + if (frozen && _sentences[i]->_freezable) { + continue; + } else { + _sentences[i]->display(); + } } return STATUS_OK; } @@ -307,7 +336,9 @@ void AdGame::finishSentences() { for (int i = 0; i < _sentences.getSize(); i++) { if (_sentences[i]->CanSkip()) { _sentences[i]->_duration = 0; - if (_sentences[i]->_sound) _sentences[i]->_sound->stop(); + if (_sentences[i]->_sound) { + _sentences[i]->_sound->stop(); + } } } } @@ -330,7 +361,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, bool transIn = valFadeIn->isNULL() ? true : valFadeIn->getBool(); scheduleChangeScene(filename, transIn); - if (transOut) _transMgr->start(TRANSITION_FADE_OUT, true); + if (transOut) { + _transMgr->start(TRANSITION_FADE_OUT, true); + } stack->pushNULL(); @@ -383,7 +416,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdObject *obj = (AdObject *)val->getNative(); removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } stack->pushNULL(); return STATUS_OK; @@ -398,7 +433,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdEntity *ent = new AdEntity(_gameRef); addObject(ent); - if (!val->isNULL()) ent->setName(val->getString()); + if (!val->isNULL()) { + ent->setName(val->getString()); + } stack->pushNative(ent, true); return STATUS_OK; } @@ -412,7 +449,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdItem *item = new AdItem(_gameRef); addItem(item); - if (!val->isNULL()) item->setName(val->getString()); + if (!val->isNULL()) { + item->setName(val->getString()); + } stack->pushNative(item, true); return STATUS_OK; } @@ -425,8 +464,11 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdItem *item = NULL; - if (val->isNative()) item = (AdItem *)val->getNative(); - else item = getItemByName(val->getString()); + if (val->isNative()) { + item = (AdItem *)val->getNative(); + } else { + item = getItemByName(val->getString()); + } if (item) { deleteItem(item); @@ -446,13 +488,18 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdItem *item = NULL; if (val->isInt()) { int index = val->getInt(); - if (index >= 0 && index < _items.getSize()) item = _items[index]; + if (index >= 0 && index < _items.getSize()) { + item = _items[index]; + } } else { item = getItemByName(val->getString()); } - if (item) stack->pushNative(item, true); - else stack->pushNULL(); + if (item) { + stack->pushNative(item, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -476,13 +523,24 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, res->_iD = id; res->setText(text); _stringTable->expand(&res->_text); - if (!val1->isNULL()) res->setIcon(val1->getString()); - if (!val2->isNULL()) res->setIconHover(val2->getString()); - if (!val3->isNULL()) res->setIconPressed(val3->getString()); - if (!val4->isNULL()) res->setFont(val4->getString()); + if (!val1->isNULL()) { + res->setIcon(val1->getString()); + } + if (!val2->isNULL()) { + res->setIconHover(val2->getString()); + } + if (!val3->isNULL()) { + res->setIconPressed(val3->getString()); + } + if (!val4->isNULL()) { + res->setFont(val4->getString()); + } - if (strcmp(name, "AddResponseOnce") == 0) res->_responseType = RESPONSE_ONCE; - else if (strcmp(name, "AddResponseOnceGame") == 0) res->_responseType = RESPONSE_ONCE_GAME; + if (strcmp(name, "AddResponseOnce") == 0) { + res->_responseType = RESPONSE_ONCE; + } else if (strcmp(name, "AddResponseOnceGame") == 0) { + res->_responseType = RESPONSE_ONCE_GAME; + } _responseBox->_responses.add(res); } @@ -577,7 +635,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, Common::String branchName; if (val->isNULL()) { branchName.format("line%d", script->_currentLine); - } else branchName = val->getString(); + } else { + branchName = val->getString(); + } startDlgBranch(branchName.c_str(), script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); stack->pushNULL(); @@ -593,7 +653,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *branchName = NULL; ScValue *val = stack->pop(); - if (!val->isNULL()) branchName = val->getString(); + if (!val->isNULL()) { + branchName = val->getString(); + } endDlgBranch(branchName, script->_filename == NULL ? "" : script->_filename, script->_threadEvent == NULL ? "" : script->_threadEvent); stack->pushNULL(); @@ -609,7 +671,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (_dlgPendingBranches.getSize() > 0) { stack->pushString(_dlgPendingBranches[_dlgPendingBranches.getSize() - 1]); - } else stack->pushNULL(); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -663,7 +727,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } } - } else script->runtimeError("Game.IsItemTaken: item name expected"); + } else { + script->runtimeError("Game.IsItemTaken: item name expected"); + } stack->pushBool(false); return STATUS_OK; @@ -674,10 +740,11 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetInventoryWindow") == 0) { stack->correctParams(0); - if (_inventoryBox && _inventoryBox->_window) + if (_inventoryBox && _inventoryBox->_window) { stack->pushNative(_inventoryBox->_window, true); - else + } else { stack->pushNULL(); + } return STATUS_OK; } @@ -687,10 +754,11 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetResponsesWindow") == 0 || strcmp(name, "GetResponseWindow") == 0) { stack->correctParams(0); - if (_responseBox && _responseBox->_window) + if (_responseBox && _responseBox->_window) { stack->pushNative(_responseBox->_window, true); - else + } else { stack->pushNULL(); + } return STATUS_OK; } @@ -781,11 +849,19 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, int width = stack->pop()->getInt(); int height = stack->pop()->getInt(); - if (width <= 0) width = _renderer->_width; - if (height <= 0) height = _renderer->_height; + if (width <= 0) { + width = _renderer->_width; + } + if (height <= 0) { + height = _renderer->_height; + } - if (!_sceneViewport) _sceneViewport = new BaseViewport(_gameRef); - if (_sceneViewport) _sceneViewport->setRect(x, y, x + width, y + height); + if (!_sceneViewport) { + _sceneViewport = new BaseViewport(_gameRef); + } + if (_sceneViewport) { + _sceneViewport->setRect(x, y, x + width, y + height); + } stack->pushBool(true); @@ -793,7 +869,9 @@ bool AdGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } - else return BaseGame::scCallMethod(script, stack, thisStack, name); + else { + return BaseGame::scCallMethod(script, stack, thisStack, name); + } } @@ -812,8 +890,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // Scene ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Scene") == 0) { - if (_scene) _scValue->setNative(_scene, true); - else _scValue->setNULL(); + if (_scene) { + _scValue->setNative(_scene, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -822,8 +903,11 @@ ScValue *AdGame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SelectedItem") == 0) { //if (_selectedItem) _scValue->setString(_selectedItem->_name); - if (_selectedItem) _scValue->setNative(_selectedItem, true); - else _scValue->setNULL(); + if (_selectedItem) { + _scValue->setNative(_selectedItem, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -854,8 +938,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // InventoryScrollOffset ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) _scValue->setInt(_inventoryBox->_scrollOffset); - else _scValue->setInt(0); + if (_inventoryBox) { + _scValue->setInt(_inventoryBox->_scrollOffset); + } else { + _scValue->setInt(0); + } return _scValue; } @@ -872,8 +959,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // PrevScene / PreviousScene (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "PrevScene") == 0 || strcmp(name, "PreviousScene") == 0) { - if (!_prevSceneName) _scValue->setString(""); - else _scValue->setString(_prevSceneName); + if (!_prevSceneName) { + _scValue->setString(""); + } else { + _scValue->setString(_prevSceneName); + } return _scValue; } @@ -881,8 +971,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // PrevSceneFilename / PreviousSceneFilename (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "PrevSceneFilename") == 0 || strcmp(name, "PreviousSceneFilename") == 0) { - if (!_prevSceneFilename) _scValue->setString(""); - else _scValue->setString(_prevSceneFilename); + if (!_prevSceneFilename) { + _scValue->setString(""); + } else { + _scValue->setString(_prevSceneFilename); + } return _scValue; } @@ -890,8 +983,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // LastResponse (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LastResponse") == 0) { - if (!_responseBox || !_responseBox->_lastResponseText) _scValue->setString(""); - else _scValue->setString(_responseBox->_lastResponseText); + if (!_responseBox || !_responseBox->_lastResponseText) { + _scValue->setString(""); + } else { + _scValue->setString(_responseBox->_lastResponseText); + } return _scValue; } @@ -899,8 +995,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // LastResponseOrig (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "LastResponseOrig") == 0) { - if (!_responseBox || !_responseBox->_lastResponseTextOrig) _scValue->setString(""); - else _scValue->setString(_responseBox->_lastResponseTextOrig); + if (!_responseBox || !_responseBox->_lastResponseTextOrig) { + _scValue->setString(""); + } else { + _scValue->setString(_responseBox->_lastResponseTextOrig); + } return _scValue; } @@ -908,8 +1007,11 @@ ScValue *AdGame::scGetProperty(const char *name) { // InventoryObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner == _invObject) _scValue->setNative(this, true); - else _scValue->setNative(_inventoryOwner, true); + if (_inventoryOwner == _invObject) { + _scValue->setNative(this, true); + } else { + _scValue->setNative(_inventoryOwner, true); + } return _scValue; } @@ -942,12 +1044,17 @@ ScValue *AdGame::scGetProperty(const char *name) { // StartupScene ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "StartupScene") == 0) { - if (!_startupScene) _scValue->setNULL(); - else _scValue->setString(_startupScene); + if (!_startupScene) { + _scValue->setNULL(); + } else { + _scValue->setString(_startupScene); + } return _scValue; } - else return BaseGame::scGetProperty(name); + else { + return BaseGame::scGetProperty(name); + } } @@ -958,8 +1065,9 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // SelectedItem ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "SelectedItem") == 0) { - if (value->isNULL()) _selectedItem = NULL; - else { + if (value->isNULL()) { + _selectedItem = NULL; + } else { if (value->isNative()) { _selectedItem = NULL; for (int i = 0; i < _items.getSize(); i++) { @@ -989,7 +1097,9 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // InventoryVisible ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryVisible") == 0) { - if (_inventoryBox) _inventoryBox->_visible = value->getBool(); + if (_inventoryBox) { + _inventoryBox->_visible = value->getBool(); + } return STATUS_OK; } @@ -997,16 +1107,24 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // InventoryObject ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryObject") == 0) { - if (_inventoryOwner && _inventoryBox) _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + if (_inventoryOwner && _inventoryBox) { + _inventoryOwner->getInventory()->_scrollOffset = _inventoryBox->_scrollOffset; + } - if (value->isNULL()) _inventoryOwner = _invObject; - else { - BaseObject *Obj = (BaseObject *)value->getNative(); - if (Obj == this) _inventoryOwner = _invObject; - else if (_gameRef->validObject(Obj)) _inventoryOwner = (AdObject *)Obj; + if (value->isNULL()) { + _inventoryOwner = _invObject; + } else { + BaseObject *obj = (BaseObject *)value->getNative(); + if (obj == this) { + _inventoryOwner = _invObject; + } else if (_gameRef->validObject(obj)) { + _inventoryOwner = (AdObject *)obj; + } } - if (_inventoryOwner && _inventoryBox) _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + if (_inventoryOwner && _inventoryBox) { + _inventoryBox->_scrollOffset = _inventoryOwner->getInventory()->_scrollOffset; + } return STATUS_OK; } @@ -1015,7 +1133,9 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // InventoryScrollOffset ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "InventoryScrollOffset") == 0) { - if (_inventoryBox) _inventoryBox->_scrollOffset = value->getInt(); + if (_inventoryBox) { + _inventoryBox->_scrollOffset = value->getInt(); + } return STATUS_OK; } @@ -1023,10 +1143,14 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { // TalkSkipButton ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TalkSkipButton") == 0) { - int Val = value->getInt(); - if (Val < 0) Val = 0; - if (Val > TALK_SKIP_NONE) Val = TALK_SKIP_NONE; - _talkSkipButton = (TTalkSkipButton)Val; + int val = value->getInt(); + if (val < 0) { + val = 0; + } + if (val > TALK_SKIP_NONE) { + val = TALK_SKIP_NONE; + } + _talkSkipButton = (TTalkSkipButton)val; return STATUS_OK; } @@ -1037,12 +1161,16 @@ bool AdGame::scSetProperty(const char *name, ScValue *value) { if (value == NULL) { delete[] _startupScene; _startupScene = NULL; - } else BaseUtils::setString(&_startupScene, value->getString()); + } else { + BaseUtils::setString(&_startupScene, value->getString()); + } return STATUS_OK; } - else return BaseGame::scSetProperty(name, value); + else { + return BaseGame::scSetProperty(name, value); + } } @@ -1075,7 +1203,9 @@ bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// // call parent - else return BaseGame::ExternalCall(script, stack, thisStack, name); + else { + return BaseGame::ExternalCall(script, stack, thisStack, name); + } return STATUS_OK; @@ -1084,7 +1214,9 @@ bool AdGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// bool AdGame::showCursor() { - if (_cursorHidden) return STATUS_OK; + if (_cursorHidden) { + return STATUS_OK; + } if (_selectedItem && _gameRef->_state == GAME_RUNNING && _stateEx == GAME_NORMAL && _interactive) { if (_selectedItem->_cursorCombined) { @@ -1093,12 +1225,17 @@ bool AdGame::showCursor() { _lastCursor = origLastCursor; } if (_activeObject && _selectedItem->_cursorHover && _activeObject->getExtendedFlag("usable")) { - if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) + if (!_smartItemCursor || _activeObject->canHandleEvent(_selectedItem->getName())) { return drawCursor(_selectedItem->_cursorHover); - else + } else { return drawCursor(_selectedItem->_cursorNormal); - } else return drawCursor(_selectedItem->_cursorNormal); - } else return BaseGame::showCursor(); + } + } else { + return drawCursor(_selectedItem->_cursorNormal); + } + } else { + return BaseGame::showCursor(); + } } @@ -1114,7 +1251,9 @@ bool AdGame::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + } delete[] buffer; @@ -1162,7 +1301,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_GAME: - if (DID_FAIL(BaseGame::loadBuffer(params, false))) cmd = PARSERR_GENERIC; + if (DID_FAIL(BaseGame::loadBuffer(params, false))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_AD_GAME: @@ -1171,9 +1312,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_RESPONSE_BOX: delete _responseBox; _responseBox = new AdResponseBox(_gameRef); - if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) + if (_responseBox && !DID_FAIL(_responseBox->loadFile((char *)params2))) { registerObject(_responseBox); - else { + } else { delete _responseBox; _responseBox = NULL; cmd = PARSERR_GENERIC; @@ -1183,9 +1324,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { case TOKEN_INVENTORY_BOX: delete _inventoryBox; _inventoryBox = new AdInventoryBox(_gameRef); - if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) + if (_inventoryBox && !DID_FAIL(_inventoryBox->loadFile((char *)params2))) { registerObject(_inventoryBox); - else { + } else { delete _inventoryBox; _inventoryBox = NULL; cmd = PARSERR_GENERIC; @@ -1203,16 +1344,24 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TALK_SKIP_BUTTON: - if (scumm_stricmp((char *)params2, "right") == 0) _talkSkipButton = TALK_SKIP_RIGHT; - else if (scumm_stricmp((char *)params2, "both") == 0) _talkSkipButton = TALK_SKIP_BOTH; - else _talkSkipButton = TALK_SKIP_LEFT; + if (scumm_stricmp((char *)params2, "right") == 0) { + _talkSkipButton = TALK_SKIP_RIGHT; + } else if (scumm_stricmp((char *)params2, "both") == 0) { + _talkSkipButton = TALK_SKIP_BOTH; + } else { + _talkSkipButton = TALK_SKIP_LEFT; + } break; case TOKEN_SCENE_VIEWPORT: { Rect32 rc; parser.scanStr((char *)params2, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_sceneViewport) _sceneViewport = new BaseViewport(_gameRef); - if (_sceneViewport) _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + if (!_sceneViewport) { + _sceneViewport = new BaseViewport(_gameRef); + } + if (_sceneViewport) { + _sceneViewport->setRect(rc.left, rc.top, rc.right, rc.bottom); + } } break; @@ -1252,7 +1401,9 @@ bool AdGame::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// bool AdGame::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->getIsSaving()) cleanup(); + if (!persistMgr->getIsSaving()) { + cleanup(); + } BaseGame::persist(persistMgr); _dlgPendingBranches.persist(persistMgr); @@ -1292,7 +1443,9 @@ bool AdGame::persist(BasePersistenceManager *persistMgr) { _speechDirs.persist(persistMgr); persistMgr->transfer(TMEMBER(_smartItemCursor)); - if (!persistMgr->getIsSaving()) _initialScene = false; + if (!persistMgr->getIsSaving()) { + _initialScene = false; + } persistMgr->transfer(TMEMBER(_startupScene)); @@ -1304,7 +1457,9 @@ bool AdGame::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdGame::loadGame(const char *filename) { bool ret = BaseGame::loadGame(filename); - if (DID_SUCCEED(ret)) SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "AdRegion", NULL); + if (DID_SUCCEED(ret)) { + SystemClassRegistry::getInstance()->enumInstances(afterLoadRegion, "AdRegion", NULL); + } return ret; } @@ -1327,7 +1482,9 @@ void AdGame::setPrevSceneName(const char *name) { _prevSceneName = NULL; if (name) { _prevSceneName = new char[strlen(name) + 1]; - if (_prevSceneName) strcpy(_prevSceneName, name); + if (_prevSceneName) { + strcpy(_prevSceneName, name); + } } } @@ -1338,7 +1495,9 @@ void AdGame::setPrevSceneFilename(const char *name) { _prevSceneFilename = NULL; if (name) { _prevSceneFilename = new char[strlen(name) + 1]; - if (_prevSceneFilename) strcpy(_prevSceneFilename, name); + if (_prevSceneFilename) { + strcpy(_prevSceneFilename, name); + } } } @@ -1348,8 +1507,9 @@ bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { delete[] _scheduledScene; _scheduledScene = NULL; - if (_scene && !_scene->_initialized) return changeScene(filename, fadeIn); - else { + if (_scene && !_scene->_initialized) { + return changeScene(filename, fadeIn); + } else { _scheduledScene = new char [strlen(filename) + 1]; strcpy(_scheduledScene, filename); @@ -1364,8 +1524,12 @@ bool AdGame::scheduleChangeScene(const char *filename, bool fadeIn) { bool AdGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { BaseGame::getVersion(verMajor, verMinor, NULL, NULL); - if (extMajor) *extMajor = 0; - if (extMinor) *extMinor = 0; + if (extMajor) { + *extMajor = 0; + } + if (extMinor) { + *extMinor = 0; + } return STATUS_OK; } @@ -1384,7 +1548,9 @@ bool AdGame::loadItemsFile(const char *filename, bool merge) { //_filename = new char [strlen(filename)+1]; //strcpy(_filename, filename); - if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + if (DID_FAIL(ret = loadItemsBuffer(buffer, merge))) { + _gameRef->LOG(0, "Error parsing ITEMS file '%s'", filename); + } delete[] buffer; @@ -1404,7 +1570,9 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { BaseParser parser(_gameRef); if (!merge) { - while (_items.getSize() > 0) deleteItem(_items[0]); + while (_items.getSize() > 0) { + deleteItem(_items[0]); + } } while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { @@ -1414,8 +1582,10 @@ bool AdGame::loadItemsBuffer(byte *buffer, bool merge) { if (item && !DID_FAIL(item->loadBuffer(params, false))) { // delete item with the same name, if exists if (merge) { - AdItem *PrevItem = getItemByName(item->getName()); - if (PrevItem) deleteItem(PrevItem); + AdItem *prevItem = getItemByName(item->getName()); + if (prevItem) { + deleteItem(prevItem); + } } addItem(item); } else { @@ -1446,7 +1616,9 @@ AdSceneState *AdGame::getSceneState(const char *filename, bool saving) { char *filenameCor = new char[strlen(filename) + 1]; strcpy(filenameCor, filename); for (uint32 i = 0; i < strlen(filenameCor); i++) { - if (filenameCor[i] == '/') filenameCor[i] = '\\'; + if (filenameCor[i] == '/') { + filenameCor[i] = '\\'; + } } for (int i = 0; i < _sceneStates.getSize(); i++) { @@ -1512,14 +1684,18 @@ bool AdGame::windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack *st ScValue *val = stack->pop(); UIEntity *ent = new UIEntity(_gameRef); - if (!val->isNULL()) ent->setName(val->getString()); + if (!val->isNULL()) { + ent->setName(val->getString()); + } stack->pushNative(ent, true); ent->_parent = win; win->_widgets.add(ent); return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -1550,7 +1726,9 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const } } - if (name == NULL) return STATUS_OK; + if (name == NULL) { + return STATUS_OK; + } int startIndex = -1; @@ -1571,11 +1749,15 @@ bool AdGame::endDlgBranch(const char *branchName, const char *scriptName, const // dialogue is over, forget selected responses if (_dlgPendingBranches.getSize() == 0) { - for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + for (int i = 0; i < _responsesBranch.getSize(); i++) { + delete _responsesBranch[i]; + } _responsesBranch.removeAll(); } - if (deleteName) delete[] name; + if (deleteName) { + delete[] name; + } return STATUS_OK; } @@ -1595,10 +1777,12 @@ bool AdGame::clearBranchResponses(char *name) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::addBranchResponse(int ID) { - if (branchResponseUsed(ID)) return STATUS_OK; +bool AdGame::addBranchResponse(int id) { + if (branchResponseUsed(id)) { + return STATUS_OK; + } AdResponseContext *r = new AdResponseContext(_gameRef); - r->_iD = ID; + r->_id = id; r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); _responsesBranch.add(r); return STATUS_OK; @@ -1606,11 +1790,13 @@ bool AdGame::addBranchResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::branchResponseUsed(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; +bool AdGame::branchResponseUsed(int id) { + char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; for (int i = 0; i < _responsesBranch.getSize(); i++) { - if (_responsesBranch[i]->_iD == ID) { - if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) return true; + if (_responsesBranch[i]->_id == id) { + if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { + return true; + } } } return false; @@ -1618,10 +1804,12 @@ bool AdGame::branchResponseUsed(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::addGameResponse(int ID) { - if (gameResponseUsed(ID)) return STATUS_OK; +bool AdGame::addGameResponse(int id) { + if (gameResponseUsed(id)) { + return STATUS_OK; + } AdResponseContext *r = new AdResponseContext(_gameRef); - r->_iD = ID; + r->_id = id; r->setContext(_dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL); _responsesGame.add(r); return STATUS_OK; @@ -1629,12 +1817,14 @@ bool AdGame::addGameResponse(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::gameResponseUsed(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; +bool AdGame::gameResponseUsed(int id) { + char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; for (int i = 0; i < _responsesGame.getSize(); i++) { - AdResponseContext *RespContext = _responsesGame[i]; - if (RespContext->_iD == ID) { - if ((Context == NULL && RespContext->_context == NULL) || ((Context != NULL && RespContext->_context != NULL) && scumm_stricmp(Context, RespContext->_context) == 0)) return true; + AdResponseContext *respContext = _responsesGame[i]; + if (respContext->_id == id) { + if ((context == NULL && respContext->_context == NULL) || ((context != NULL && respContext->_context != NULL) && scumm_stricmp(context, respContext->_context) == 0)) { + return true; + } } } return false; @@ -1642,14 +1832,12 @@ bool AdGame::gameResponseUsed(int ID) { ////////////////////////////////////////////////////////////////////////// -bool AdGame::resetResponse(int ID) { - char *Context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - - int i; +bool AdGame::resetResponse(int id) { + char *context = _dlgPendingBranches.getSize() > 0 ? _dlgPendingBranches[_dlgPendingBranches.getSize() - 1] : NULL; - for (i = 0; i < _responsesGame.getSize(); i++) { - if (_responsesGame[i]->_iD == ID) { - if ((Context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(Context, _responsesGame[i]->_context) == 0) { + for (int i = 0; i < _responsesGame.getSize(); i++) { + if (_responsesGame[i]->_id == id) { + if ((context == NULL && _responsesGame[i]->_context == NULL) || scumm_stricmp(context, _responsesGame[i]->_context) == 0) { delete _responsesGame[i]; _responsesGame.removeAt(i); break; @@ -1657,9 +1845,9 @@ bool AdGame::resetResponse(int ID) { } } - for (i = 0; i < _responsesBranch.getSize(); i++) { - if (_responsesBranch[i]->_iD == ID) { - if ((Context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(Context, _responsesBranch[i]->_context) == 0) { + for (int i = 0; i < _responsesBranch.getSize(); i++) { + if (_responsesBranch[i]->_id == id) { + if ((context == NULL && _responsesBranch[i]->_context == NULL) || scumm_stricmp(context, _responsesBranch[i]->_context) == 0) { delete _responsesBranch[i]; _responsesBranch.removeAt(i); break; @@ -1673,19 +1861,27 @@ bool AdGame::resetResponse(int ID) { ////////////////////////////////////////////////////////////////////////// bool AdGame::displayContent(bool doUpdate, bool displayAll) { // init - if (doUpdate) initLoop(); + if (doUpdate) { + initLoop(); + } // fill black _renderer->fill(0, 0, 0); - if (!_editorMode) _renderer->setScreenViewport(); + if (!_editorMode) { + _renderer->setScreenViewport(); + } // playing exclusive video? if (_videoPlayer->isPlaying()) { - if (doUpdate) _videoPlayer->update(); + if (doUpdate) { + _videoPlayer->update(); + } _videoPlayer->display(); } else if (_theoraPlayer) { if (_theoraPlayer->isPlaying()) { - if (doUpdate) _theoraPlayer->update(); + if (doUpdate) { + _theoraPlayer->update(); + } _theoraPlayer->display(); } if (_theoraPlayer->isFinished()) { @@ -1695,7 +1891,9 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { } else { // process scripts - if (doUpdate) _scEngine->tick(); + if (doUpdate) { + _scEngine->tick(); + } Point32 p; getMousePos(&p); @@ -1706,9 +1904,15 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { // display in-game windows displayWindows(true); - if (_inventoryBox) _inventoryBox->display(); - if (_stateEx == GAME_WAITING_RESPONSE) _responseBox->display(); - if (_indicatorDisplay) displayIndicator(); + if (_inventoryBox) { + _inventoryBox->display(); + } + if (_stateEx == GAME_WAITING_RESPONSE) { + _responseBox->display(); + } + if (_indicatorDisplay) { + displayIndicator(); + } if (doUpdate || displayAll) { @@ -1722,7 +1926,9 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { showCursor(); - if (_fader) _fader->display(); + if (_fader) { + _fader->display(); + } _transMgr->update(); } @@ -1741,7 +1947,9 @@ bool AdGame::displayContent(bool doUpdate, bool displayAll) { ////////////////////////////////////////////////////////////////////////// bool AdGame::registerInventory(AdInventory *inv) { for (int i = 0; i < _inventories.getSize(); i++) { - if (_inventories[i] == inv) return STATUS_OK; + if (_inventories[i] == inv) { + return STATUS_OK; + } } registerObject(inv); _inventories.add(inv); @@ -1778,7 +1986,9 @@ bool AdGame::isItemTaken(char *itemName) { ////////////////////////////////////////////////////////////////////////// AdItem *AdGame::getItemByName(const char *name) { for (int i = 0; i < _items.getSize(); i++) { - if (scumm_stricmp(_items[i]->getName(), name) == 0) return _items[i]; + if (scumm_stricmp(_items[i]->getName(), name) == 0) { + return _items[i]; + } } return NULL; } @@ -1806,19 +2016,27 @@ bool AdGame::resetContent() { } // clear scene states - for (int i = 0; i < _sceneStates.getSize(); i++) delete _sceneStates[i]; + for (int i = 0; i < _sceneStates.getSize(); i++) { + delete _sceneStates[i]; + } _sceneStates.removeAll(); // clear once responses - for (int i = 0; i < _responsesBranch.getSize(); i++) delete _responsesBranch[i]; + for (int i = 0; i < _responsesBranch.getSize(); i++) { + delete _responsesBranch[i]; + } _responsesBranch.removeAll(); // clear once game responses - for (int i = 0; i < _responsesGame.getSize(); i++) delete _responsesGame[i]; + for (int i = 0; i < _responsesGame.getSize(); i++) { + delete _responsesGame[i]; + } _responsesGame.removeAll(); // reload inventory items - if (_itemsFile) loadItemsFile(_itemsFile); + if (_itemsFile) { + loadItemsFile(_itemsFile); + } _tempDisableSaveState = true; @@ -1828,9 +2046,13 @@ bool AdGame::resetContent() { ////////////////////////////////////////////////////////////////////////// bool AdGame::deleteItem(AdItem *item) { - if (!item) return STATUS_FAILED; + if (!item) { + return STATUS_FAILED; + } - if (_selectedItem == item) _selectedItem = NULL; + if (_selectedItem == item) { + _selectedItem = NULL; + } _scene->handleItemAssociations(item->getName(), false); // remove from all inventories @@ -1853,12 +2075,15 @@ bool AdGame::deleteItem(AdItem *item) { ////////////////////////////////////////////////////////////////////////// bool AdGame::addSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') return STATUS_FAILED; + if (!dir || dir[0] == '\0') { + return STATUS_FAILED; + } char *temp = new char[strlen(dir) + 2]; strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { strcat(temp, "\\"); + } for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { @@ -1874,26 +2099,28 @@ bool AdGame::addSpeechDir(const char *dir) { ////////////////////////////////////////////////////////////////////////// bool AdGame::removeSpeechDir(const char *dir) { - if (!dir || dir[0] == '\0') return STATUS_FAILED; + if (!dir || dir[0] == '\0') { + return STATUS_FAILED; + } char *temp = new char[strlen(dir) + 2]; strcpy(temp, dir); - if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') + if (temp[strlen(temp) - 1] != '\\' && temp[strlen(temp) - 1] != '/') { strcat(temp, "\\"); + } - bool Found = false; + bool found = false; for (int i = 0; i < _speechDirs.getSize(); i++) { if (scumm_stricmp(_speechDirs[i], temp) == 0) { delete[] _speechDirs[i]; _speechDirs.removeAt(i); - Found = true; + found = true; break; } } delete[] temp; - if (Found) return STATUS_OK; - else return STATUS_FAILED; + return found; } @@ -1903,12 +2130,14 @@ char *AdGame::findSpeechFile(char *stringID) { for (int i = 0; i < _speechDirs.getSize(); i++) { sprintf(ret, "%s%s.ogg", _speechDirs[i], stringID); - if (_fileManager->hasFile(ret)) + if (_fileManager->hasFile(ret)) { return ret; + } sprintf(ret, "%s%s.wav", _speechDirs[i], stringID); - if (_fileManager->hasFile(ret)) + if (_fileManager->hasFile(ret)) { return ret; + } } delete[] ret; return NULL; @@ -1925,7 +2154,9 @@ bool AdGame::validMouse() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseLeftDown() { - if (!validMouse()) return STATUS_OK; + if (!validMouse()) { + return STATUS_OK; + } if (_state == GAME_RUNNING && !_interactive) { if (_talkSkipButton == TALK_SKIP_LEFT || _talkSkipButton == TALK_SKIP_BOTH) { finishSentences(); @@ -1933,7 +2164,9 @@ bool AdGame::onMouseLeftDown() { return STATUS_OK; } - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); if (!handled) { @@ -1944,7 +2177,9 @@ bool AdGame::onMouseLeftDown() { } } - if (_activeObject != NULL) _gameRef->_capturedObject = _gameRef->_activeObject; + if (_activeObject != NULL) { + _gameRef->_capturedObject = _gameRef->_activeObject; + } _mouseLeftDown = true; BasePlatform::setCapture(/*_renderer->_window*/); @@ -1953,7 +2188,9 @@ bool AdGame::onMouseLeftDown() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseLeftUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + } BasePlatform::releaseCapture(); _capturedObject = NULL; @@ -1972,11 +2209,17 @@ bool AdGame::onMouseLeftUp() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseLeftDblClick() { - if (!validMouse()) return STATUS_OK; + if (!validMouse()) { + return STATUS_OK; + } - if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); if (!handled) { @@ -1991,7 +2234,9 @@ bool AdGame::onMouseLeftDblClick() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseRightDown() { - if (!validMouse()) return STATUS_OK; + if (!validMouse()) { + return STATUS_OK; + } if (_state == GAME_RUNNING && !_interactive) { if (_talkSkipButton == TALK_SKIP_RIGHT || _talkSkipButton == TALK_SKIP_BOTH) { finishSentences(); @@ -1999,9 +2244,13 @@ bool AdGame::onMouseRightDown() { return STATUS_OK; } - if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) return STATUS_OK; + if ((_state == GAME_RUNNING && !_interactive) || _stateEx == GAME_WAITING_RESPONSE) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); if (!handled) { @@ -2016,7 +2265,9 @@ bool AdGame::onMouseRightDown() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onMouseRightUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); if (!handled) { @@ -2045,8 +2296,9 @@ bool AdGame::displayDebugInfo() { ////////////////////////////////////////////////////////////////////////// bool AdGame::onScriptShutdown(ScScript *script) { - if (_responseBox && _responseBox->_waitingScript == script) + if (_responseBox && _responseBox->_waitingScript == script) { _responseBox->_waitingScript = NULL; + } return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_inventory.cpp b/engines/wintermute/ad/ad_inventory.cpp index d79d171d02..aa6e0b6f0b 100644 --- a/engines/wintermute/ad/ad_inventory.cpp +++ b/engines/wintermute/ad/ad_inventory.cpp @@ -50,10 +50,14 @@ AdInventory::~AdInventory() { ////////////////////////////////////////////////////////////////////////// bool AdInventory::insertItem(const char *name, const char *insertAfter) { - if (name == NULL) return STATUS_FAILED; + if (name == NULL) { + return STATUS_FAILED; + } AdItem *item = ((AdGame *)_gameRef)->getItemByName(name); - if (item == NULL) return STATUS_FAILED; + if (item == NULL) { + return STATUS_FAILED; + } int insertIndex = -1; for (int i = 0; i < _takenItems.getSize(); i++) { @@ -62,12 +66,17 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { i--; continue; } - if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) insertIndex = i + 1; + if (insertAfter && scumm_stricmp(_takenItems[i]->getName(), insertAfter) == 0) { + insertIndex = i + 1; + } } - if (insertIndex == -1) _takenItems.add(item); - else _takenItems.insertAt(insertIndex, item); + if (insertIndex == -1) { + _takenItems.add(item); + } else { + _takenItems.insertAt(insertIndex, item); + } return STATUS_OK; } @@ -75,11 +84,15 @@ bool AdInventory::insertItem(const char *name, const char *insertAfter) { ////////////////////////////////////////////////////////////////////////// bool AdInventory::removeItem(const char *name) { - if (name == NULL) return STATUS_FAILED; + if (name == NULL) { + return STATUS_FAILED; + } for (int i = 0; i < _takenItems.getSize(); i++) { if (scumm_stricmp(_takenItems[i]->getName(), name) == 0) { - if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { + ((AdGame *)_gameRef)->_selectedItem = NULL; + } _takenItems.removeAt(i); return STATUS_OK; } @@ -92,11 +105,15 @@ bool AdInventory::removeItem(const char *name) { ////////////////////////////////////////////////////////////////////////// bool AdInventory::removeItem(AdItem *item) { - if (item == NULL) return STATUS_FAILED; + if (item == NULL) { + return STATUS_FAILED; + } for (int i = 0; i < _takenItems.getSize(); i++) { if (_takenItems[i] == item) { - if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i])((AdGame *)_gameRef)->_selectedItem = NULL; + if (((AdGame *)_gameRef)->_selectedItem == _takenItems[i]) { + ((AdGame *)_gameRef)->_selectedItem = NULL; + } _takenItems.removeAt(i); return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_inventory_box.cpp b/engines/wintermute/ad/ad_inventory_box.cpp index 60607c71c6..b8a3f1da22 100644 --- a/engines/wintermute/ad/ad_inventory_box.cpp +++ b/engines/wintermute/ad/ad_inventory_box.cpp @@ -86,7 +86,9 @@ bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { _scrollOffset = MAX(_scrollOffset, 0); } else if (scumm_stricmp(obj->getName(), "next") == 0) { _scrollOffset += _scrollBy; - } else return BaseObject::listen(param1, param2); + } else { + return BaseObject::listen(param1, param2); + } break; default: error("AdInventoryBox::Listen - Unhandled enum"); @@ -101,7 +103,9 @@ bool AdInventoryBox::listen(BaseScriptHolder *param1, uint32 param2) { bool AdInventoryBox::display() { AdGame *adGame = (AdGame *)_gameRef; - if (!_visible) return STATUS_OK; + if (!_visible) { + return STATUS_OK; + } int itemsX, itemsY; itemsX = (int)floor((float)((_itemsArea.right - _itemsArea.left + _spacing) / (_itemWidth + _spacing))); @@ -130,7 +134,9 @@ bool AdInventoryBox::display() { } // display items - if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + if (_window && _window->_alphaColor != 0) { + _gameRef->_renderer->_forceAlphaColor = _window->_alphaColor; + } int yyy = rect.top; for (int j = 0; j < itemsY; j++) { int xxx = rect.left; @@ -148,7 +154,9 @@ bool AdInventoryBox::display() { } yyy += (_itemHeight + _spacing); } - if (_window && _window->_alphaColor != 0) _gameRef->_renderer->_forceAlphaColor = 0; + if (_window && _window->_alphaColor != 0) { + _gameRef->_renderer->_forceAlphaColor = 0; + } return STATUS_OK; } @@ -166,7 +174,9 @@ bool AdInventoryBox::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing INVENTORY_BOX file '%s'", filename); + } delete[] buffer; @@ -227,7 +237,9 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -245,7 +257,9 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { delete _window; _window = NULL; cmd = PARSERR_GENERIC; - } else _gameRef->registerObject(_window); + } else { + _gameRef->registerObject(_window); + } break; case TOKEN_AREA: @@ -308,8 +322,9 @@ bool AdInventoryBox::loadBuffer(byte *buffer, bool complete) { if (_window) { for (int i = 0; i < _window->_widgets.getSize(); i++) { - if (!_window->_widgets[i]->_listenerObject) + if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } } } @@ -337,7 +352,9 @@ bool AdInventoryBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // window - if (_window) _window->saveAsText(buffer, indent + 2); + if (_window) { + _window->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); diff --git a/engines/wintermute/ad/ad_item.cpp b/engines/wintermute/ad/ad_item.cpp index cae974e152..c9e0d56b24 100644 --- a/engines/wintermute/ad/ad_item.cpp +++ b/engines/wintermute/ad/ad_item.cpp @@ -94,7 +94,9 @@ bool AdItem::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ITEM file '%s'", filename); + } delete[] buffer; @@ -178,7 +180,9 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -186,7 +190,7 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - SetFont((char *)params); + setFont((char *)params); break; case TOKEN_CAPTION: @@ -230,9 +234,13 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_AMOUNT_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) _amountAlign = TAL_LEFT; - else if (scumm_stricmp((char *)params, "right") == 0) _amountAlign = TAL_RIGHT; - else _amountAlign = TAL_CENTER; + if (scumm_stricmp((char *)params, "left") == 0) { + _amountAlign = TAL_LEFT; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _amountAlign = TAL_RIGHT; + } else { + _amountAlign = TAL_CENTER; + } break; case TOKEN_AMOUNT_STRING: @@ -241,15 +249,21 @@ bool AdItem::loadBuffer(byte *buffer, bool complete) { case TOKEN_TALK: { BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSprites.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSprites.add(spr); + } } break; case TOKEN_TALK_SPECIAL: { BaseSprite *spr = new BaseSprite(_gameRef, this); - if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) cmd = PARSERR_GENERIC; - else _talkSpritesEx.add(spr); + if (!spr || DID_FAIL(spr->loadFile((char *)params, ((AdGame *)_gameRef)->_texTalkLifeTime))) { + cmd = PARSERR_GENERIC; + } else { + _talkSpritesEx.add(spr); + } } break; @@ -331,10 +345,14 @@ bool AdItem::update() { _currentSprite = _animSprite; } - if (_sentence && _state != STATE_TALKING) _sentence->finish(); + if (_sentence && _state != STATE_TALKING) { + _sentence->finish(); + } // default: stand animation - if (!_currentSprite) _currentSprite = _sprite; + if (!_currentSprite) { + _currentSprite = _sprite; + } switch (_state) { ////////////////////////////////////////////////////////////////////////// @@ -345,15 +363,20 @@ bool AdItem::update() { ////////////////////////////////////////////////////////////////////////// case STATE_READY: if (!_animSprite) { - if (_gameRef->_activeObject == this && _spriteHover) _currentSprite = _spriteHover; - else _currentSprite = _sprite; + if (_gameRef->_activeObject == this && _spriteHover) { + _currentSprite = _spriteHover; + } else { + _currentSprite = _sprite; + } } break; ////////////////////////////////////////////////////////////////////////// case STATE_TALKING: { _sentence->update(); - if (_sentence->_currentSprite) _tempSprite2 = _sentence->_currentSprite; + if (_sentence->_currentSprite) { + _tempSprite2 = _sentence->_currentSprite; + } bool TimeIsUp = (_sentence->_sound && _sentence->_soundStarted && (!_sentence->_sound->isPlaying() && !_sentence->_sound->isPaused())) || (!_sentence->_sound && _sentence->_duration <= _gameRef->_timer - _sentence->_startTime); if (_tempSprite2 == NULL || _tempSprite2->_finished || (/*_tempSprite2->_looping &&*/ TimeIsUp)) { @@ -396,9 +419,11 @@ bool AdItem::display(int x, int y) { _posY = y; bool ret; - if (_currentSprite) + if (_currentSprite) { ret = _currentSprite->draw(x, y, this, 100, 100, _alphaColor); - else ret = STATUS_OK; + } else { + ret = STATUS_OK; + } if (_displayAmount) { int amountX = x; @@ -412,8 +437,9 @@ bool AdItem::display(int x, int y) { BaseFont *font = _font ? _font : _gameRef->_systemFont; if (font) { - if (_amountString) font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); - else { + if (_amountString) { + font->drawText((byte *)_amountString, amountX, amountY, width, _amountAlign); + } else { char Str[256]; sprintf(Str, "%d", _amount); font->drawText((byte *)Str, amountX, amountY, width, _amountAlign); @@ -436,7 +462,9 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->correctParams(1); bool setCurrent = false; - if (_currentSprite && _currentSprite == _spriteHover) setCurrent = true; + if (_currentSprite && _currentSprite == _spriteHover) { + setCurrent = true; + } const char *filename = stack->pop()->getString(); @@ -448,7 +476,9 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, script->runtimeError("Item.SetHoverSprite failed for file '%s'", filename); } else { _spriteHover = spr; - if (setCurrent) _currentSprite = _spriteHover; + if (setCurrent) { + _currentSprite = _spriteHover; + } stack->pushBool(true); } return STATUS_OK; @@ -460,8 +490,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverSprite") == 0) { stack->correctParams(0); - if (!_spriteHover || !_spriteHover->getFilename()) stack->pushNULL(); - else stack->pushString(_spriteHover->getFilename()); + if (!_spriteHover || !_spriteHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_spriteHover->getFilename()); + } return STATUS_OK; } @@ -470,8 +503,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetHoverSpriteObject") == 0) { stack->correctParams(0); - if (!_spriteHover) stack->pushNULL(); - else stack->pushNative(_spriteHover, true); + if (!_spriteHover) { + stack->pushNULL(); + } else { + stack->pushNative(_spriteHover, true); + } return STATUS_OK; } @@ -502,8 +538,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetNormalCursor") == 0) { stack->correctParams(0); - if (!_cursorNormal || !_cursorNormal->getFilename()) stack->pushNULL(); - else stack->pushString(_cursorNormal->getFilename()); + if (!_cursorNormal || !_cursorNormal->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorNormal->getFilename()); + } return STATUS_OK; } @@ -513,8 +552,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetNormalCursorObject") == 0) { stack->correctParams(0); - if (!_cursorNormal) stack->pushNULL(); - else stack->pushNative(_cursorNormal, true); + if (!_cursorNormal) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorNormal, true); + } return STATUS_OK; } @@ -545,8 +587,11 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverCursor") == 0) { stack->correctParams(0); - if (!_cursorHover || !_cursorHover->getFilename()) stack->pushNULL(); - else stack->pushString(_cursorHover->getFilename()); + if (!_cursorHover || !_cursorHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorHover->getFilename()); + } return STATUS_OK; } @@ -556,12 +601,15 @@ bool AdItem::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetHoverCursorObject") == 0) { stack->correctParams(0); - if (!_cursorHover) stack->pushNULL(); - else stack->pushNative(_cursorHover, true); + if (!_cursorHover) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorHover, true); + } return STATUS_OK; + } else { + return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } - - else return AdTalkHolder::scCallMethod(script, stack, thisStack, name); } @@ -629,8 +677,11 @@ ScValue *AdItem::scGetProperty(const char *name) { // AmountString ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "AmountString") == 0) { - if (!_amountString) _scValue->setNULL(); - else _scValue->setString(_amountString); + if (!_amountString) { + _scValue->setNULL(); + } else { + _scValue->setString(_amountString); + } return _scValue; } @@ -640,9 +691,9 @@ ScValue *AdItem::scGetProperty(const char *name) { else if (strcmp(name, "CursorCombined") == 0) { _scValue->setBool(_cursorCombined); return _scValue; + } else { + return AdTalkHolder::scGetProperty(name); } - - else return AdTalkHolder::scGetProperty(name); } @@ -715,9 +766,9 @@ bool AdItem::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "CursorCombined") == 0) { _cursorCombined = value->getBool(); return STATUS_OK; + } else { + return AdTalkHolder::scSetProperty(name, value); } - - else return AdTalkHolder::scSetProperty(name, value); } @@ -750,9 +801,13 @@ bool AdItem::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdItem::getExtendedFlag(const char *flagName) { - if (!flagName) return false; - else if (strcmp(flagName, "usable") == 0) return true; - else return AdObject::getExtendedFlag(flagName); + if (!flagName) { + return false; + } else if (strcmp(flagName, "usable") == 0) { + return true; + } else { + return AdObject::getExtendedFlag(flagName); + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_layer.cpp b/engines/wintermute/ad/ad_layer.cpp index 0a93edfb35..6c9e6381b2 100644 --- a/engines/wintermute/ad/ad_layer.cpp +++ b/engines/wintermute/ad/ad_layer.cpp @@ -53,8 +53,9 @@ AdLayer::AdLayer(BaseGame *inGame): BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdLayer::~AdLayer() { - for (int i = 0; i < _nodes.getSize(); i++) + for (int i = 0; i < _nodes.getSize(); i++) { delete _nodes[i]; + } _nodes.removeAll(); } @@ -71,7 +72,9 @@ bool AdLayer::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing LAYER file '%s'", filename); + } delete[] buffer; @@ -131,7 +134,9 @@ bool AdLayer::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -181,7 +186,9 @@ bool AdLayer::loadBuffer(byte *buffer, bool complete) { case TOKEN_ENTITY: { AdEntity *entity = new AdEntity(_gameRef); AdSceneNode *node = new AdSceneNode(_gameRef); - if (entity) entity->_zoomable = false; // scene entites default to NOT zoom + if (entity) { + entity->_zoomable = false; // scene entites default to NOT zoom + } if (!entity || !node || DID_FAIL(entity->loadBuffer(params, false))) { cmd = PARSERR_GENERIC; delete entity; @@ -233,8 +240,9 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); int node = -1; - if (val->_type == VAL_INT) node = val->getInt(); - else { // get by name + if (val->_type == VAL_INT) { + node = val->getInt(); + } else { // get by name for (int i = 0; i < _nodes.getSize(); i++) { if ((_nodes[i]->_type == OBJECT_ENTITY && scumm_stricmp(_nodes[i]->_entity->getName(), val->getString()) == 0) || (_nodes[i]->_type == OBJECT_REGION && scumm_stricmp(_nodes[i]->_region->getName(), val->getString()) == 0)) { @@ -244,8 +252,9 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } - if (node < 0 || node >= _nodes.getSize()) stack->pushNULL(); - else { + if (node < 0 || node >= _nodes.getSize()) { + stack->pushNULL(); + } else { switch (_nodes[node]->_type) { case OBJECT_ENTITY: stack->pushNative(_nodes[node]->_entity, true); @@ -270,12 +279,16 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdSceneNode *node = new AdSceneNode(_gameRef); if (strcmp(name, "AddRegion") == 0) { AdRegion *region = new AdRegion(_gameRef); - if (!val->isNULL()) region->setName(val->getString()); + if (!val->isNULL()) { + region->setName(val->getString()); + } node->setRegion(region); stack->pushNative(region, true); } else { AdEntity *entity = new AdEntity(_gameRef); - if (!val->isNULL()) entity->setName(val->getString()); + if (!val->isNULL()) { + entity->setName(val->getString()); + } node->setEntity(entity); stack->pushNative(entity, true); } @@ -294,18 +307,27 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdSceneNode *node = new AdSceneNode(_gameRef); if (strcmp(name, "InsertRegion") == 0) { AdRegion *region = new AdRegion(_gameRef); - if (!val->isNULL()) region->setName(val->getString()); + if (!val->isNULL()) { + region->setName(val->getString()); + } node->setRegion(region); stack->pushNative(region, true); } else { AdEntity *entity = new AdEntity(_gameRef); - if (!val->isNULL()) entity->setName(val->getString()); + if (!val->isNULL()) { + entity->setName(val->getString()); + } node->setEntity(entity); stack->pushNative(entity, true); } - if (index < 0) index = 0; - if (index <= _nodes.getSize() - 1) _nodes.insertAt(index, node); - else _nodes.add(node); + if (index < 0) { + index = 0; + } + if (index <= _nodes.getSize() - 1) { + _nodes.insertAt(index, node); + } else { + _nodes.add(node); + } return STATUS_OK; } @@ -347,9 +369,9 @@ bool AdLayer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } stack->pushBool(true); return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -411,9 +433,9 @@ ScValue *AdLayer::scGetProperty(const char *name) { else if (strcmp(name, "Active") == 0) { _scValue->setBool(_active); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -440,7 +462,9 @@ bool AdLayer::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Width") == 0) { _width = value->getInt(); - if (_width < 0) _width = 0; + if (_width < 0) { + _width = 0; + } return STATUS_OK; } @@ -449,7 +473,9 @@ bool AdLayer::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Height") == 0) { _height = value->getInt(); - if (_height < 0) _height = 0; + if (_height < 0) { + _height = 0; + } return STATUS_OK; } @@ -460,11 +486,13 @@ bool AdLayer::scSetProperty(const char *name, ScValue *value) { bool b = value->getBool(); if (b == false && _main) { _gameRef->LOG(0, "Warning: cannot deactivate scene's main layer"); - } else _active = b; + } else { + _active = b; + } return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -484,8 +512,9 @@ bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "HEIGHT=%d\n", _height); buffer->putTextIndent(indent + 2, "ACTIVE=%s\n", _active ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); - if (_closeUp) + if (_closeUp) { buffer->putTextIndent(indent + 2, "CLOSE_UP=%s\n", _closeUp ? "TRUE" : "FALSE"); + } int i; @@ -493,7 +522,9 @@ bool AdLayer::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } for (i = 0; i < _nodes.getSize(); i++) { switch (_nodes[i]->_type) { diff --git a/engines/wintermute/ad/ad_node_state.cpp b/engines/wintermute/ad/ad_node_state.cpp index 444373ea75..5a58dba5b1 100644 --- a/engines/wintermute/ad/ad_node_state.cpp +++ b/engines/wintermute/ad/ad_node_state.cpp @@ -44,8 +44,9 @@ IMPLEMENT_PERSISTENT(AdNodeState, false) AdNodeState::AdNodeState(BaseGame *inGame): BaseClass(inGame) { _name = NULL; _active = false; - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { _caption[i] = NULL; + } _alphaColor = 0; _filename = NULL; _cursor = NULL; @@ -100,8 +101,9 @@ bool AdNodeState::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_filename)); persistMgr->transfer(TMEMBER(_cursor)); persistMgr->transfer(TMEMBER(_alphaColor)); - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { persistMgr->transfer(TMEMBER(_caption[i])); + } return STATUS_OK; } @@ -109,10 +111,12 @@ bool AdNodeState::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// void AdNodeState::setCaption(const char *caption, int caseVal) { - if (caseVal == 0) + if (caseVal == 0) { caseVal = 1; - if (caseVal < 1 || caseVal > 7) + } + if (caseVal < 1 || caseVal > 7) { return; + } delete[] _caption[caseVal - 1]; _caption[caseVal - 1] = new char[strlen(caption) + 1]; @@ -125,44 +129,61 @@ void AdNodeState::setCaption(const char *caption, int caseVal) { ////////////////////////////////////////////////////////////////////////// char *AdNodeState::getCaption(int caseVal) { - if (caseVal == 0) caseVal = 1; - if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) + if (caseVal == 0) { + caseVal = 1; + } + if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) { return ""; - else + } else { return _caption[caseVal - 1]; + } } ////////////////////////////////////////////////////////////////////////// bool AdNodeState::transferEntity(AdEntity *entity, bool includingSprites, bool saving) { - if (!entity) return STATUS_FAILED; + if (!entity) { + return STATUS_FAILED; + } // HACK! - if (this->_gameRef != entity->_gameRef) + if (this->_gameRef != entity->_gameRef) { this->_gameRef = entity->_gameRef; + } if (saving) { for (int i = 0; i < 7; i++) { - if (entity->_caption[i]) setCaption(entity->_caption[i], i); + if (entity->_caption[i]) { + setCaption(entity->_caption[i], i); + } } if (!entity->_region && entity->_sprite && entity->_sprite->getFilename()) { - if (includingSprites) setFilename(entity->_sprite->getFilename()); - else setFilename(""); + if (includingSprites) { + setFilename(entity->_sprite->getFilename()); + } else { + setFilename(""); + } + } + if (entity->_cursor && entity->_cursor->getFilename()) { + setCursor(entity->_cursor->getFilename()); } - if (entity->_cursor && entity->_cursor->getFilename()) setCursor(entity->_cursor->getFilename()); _alphaColor = entity->_alphaColor; _active = entity->_active; } else { for (int i = 0; i < 7; i++) { - if (_caption[i]) entity->setCaption(_caption[i], i); + if (_caption[i]) { + entity->setCaption(_caption[i], i); + } } if (_filename && !entity->_region && includingSprites && strcmp(_filename, "") != 0) { - if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) + if (!entity->_sprite || !entity->_sprite->getFilename() || scumm_stricmp(entity->_sprite->getFilename(), _filename) != 0) { entity->setSprite(_filename); + } } if (_cursor) { - if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) + if (!entity->_cursor || !entity->_cursor->getFilename() || scumm_stricmp(entity->_cursor->getFilename(), _cursor) != 0) { entity->setCursor(_cursor); + } } entity->_active = _active; diff --git a/engines/wintermute/ad/ad_object.cpp b/engines/wintermute/ad/ad_object.cpp index fdbc987158..c6f0306cbb 100644 --- a/engines/wintermute/ad/ad_object.cpp +++ b/engines/wintermute/ad/ad_object.cpp @@ -94,7 +94,9 @@ AdObject::AdObject(BaseGame *inGame): BaseObject(inGame) { _inventory = NULL; - for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + _currentRegions[i] = NULL; + } _partEmitter = NULL; _partFollowParent = false; @@ -127,15 +129,18 @@ AdObject::~AdObject() { _tempSprite2 = NULL; // reference only _stickRegion = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } if (_inventory) { ((AdGame *)_gameRef)->unregisterInventory(_inventory); _inventory = NULL; } - if (_partEmitter) + if (_partEmitter) { _gameRef->unregisterObject(_partEmitter); + } for (int i = 0; i < _attachmentsPre.getSize(); i++) { @@ -194,9 +199,12 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "PlayAnim") == 0 || strcmp(name, "PlayAnimAsync") == 0) { stack->correctParams(1); - if (DID_FAIL(playAnim(stack->pop()->getString()))) stack->pushBool(false); - else { - if (strcmp(name, "PlayAnimAsync") != 0) script->waitFor(this); + if (DID_FAIL(playAnim(stack->pop()->getString()))) { + stack->pushBool(false); + } else { + if (strcmp(name, "PlayAnimAsync") != 0) { + script->waitFor(this); + } stack->pushBool(true); } return STATUS_OK; @@ -226,12 +234,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "StopTalk") == 0 || strcmp(name, "StopTalking") == 0) { stack->correctParams(0); - if (_sentence) _sentence->finish(); + if (_sentence) { + _sentence->finish(); + } if (_state == STATE_TALKING) { _state = _nextState; _nextState = STATE_READY; stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -265,15 +277,20 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int align = 0; ScValue *val = stack->pop(); - if (val->isNULL()) align = TAL_CENTER; - else align = val->getInt(); + if (val->isNULL()) { + align = TAL_CENTER; + } else { + align = val->getInt(); + } align = MIN(MAX(0, align), NUM_TEXT_ALIGN - 1); const char *sound = soundVal->isNULL() ? NULL : soundVal->getString(); talk(text, sound, duration, stances, (TTextAlign)align); - if (strcmp(name, "TalkAsync") != 0) script->waitForExclusive(this); + if (strcmp(name, "TalkAsync") != 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; @@ -315,7 +332,9 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } - if (!regFound) _stickRegion = NULL; + if (!regFound) { + _stickRegion = NULL; + } stack->pushBool(regFound); return STATUS_OK; } @@ -327,8 +346,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); ScValue *val = stack->pop(); - if (val->isNULL()) SetFont(NULL); - else SetFont(val->getString()); + if (val->isNULL()) { + setFont(NULL); + } else { + setFont(val->getString()); + } stack->pushNULL(); return STATUS_OK; @@ -339,8 +361,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetFont") == 0) { stack->correctParams(0); - if (_font && _font->getFilename()) stack->pushString(_font->getFilename()); - else stack->pushNULL(); + if (_font && _font->getFilename()) { + stack->pushString(_font->getFilename()); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -360,13 +385,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack const char *itemName = val->getString(); val = stack->pop(); const char *insertAfter = val->isNULL() ? NULL : val->getString(); - if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) script->runtimeError("Cannot add item '%s' to inventory", itemName); - else { + if (DID_FAIL(_inventory->insertItem(itemName, insertAfter))) { + script->runtimeError("Cannot add item '%s' to inventory", itemName); + } else { // hide associated entities ((AdGame *)_gameRef)->_scene->handleItemAssociations(itemName, false); } - } else script->runtimeError("TakeItem: item name expected"); + } else { + script->runtimeError("TakeItem: item name expected"); + } stack->pushNULL(); return STATUS_OK; @@ -385,12 +413,15 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); if (!val->isNULL()) { - if (DID_FAIL(_inventory->removeItem(val->getString()))) script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); - else { + if (DID_FAIL(_inventory->removeItem(val->getString()))) { + script->runtimeError("Cannot remove item '%s' from inventory", val->getString()); + } else { // show associated entities ((AdGame *)_gameRef)->_scene->handleItemAssociations(val->getString(), true); } - } else script->runtimeError("DropItem: item name expected"); + } else { + script->runtimeError("DropItem: item name expected"); + } stack->pushNULL(); return STATUS_OK; @@ -410,12 +441,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); if (val->_type == VAL_STRING) { AdItem *item = ((AdGame *)_gameRef)->getItemByName(val->getString()); - if (item) stack->pushNative(item, true); - else stack->pushNULL(); - } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) + if (item) { + stack->pushNative(item, true); + } else { + stack->pushNULL(); + } + } else if (val->isNULL() || val->getInt() < 0 || val->getInt() >= _inventory->_takenItems.getSize()) { stack->pushNULL(); - else + } else { stack->pushNative(_inventory->_takenItems[val->getInt()], true); + } return STATUS_OK; } @@ -442,7 +477,9 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack return STATUS_OK; } } - } else script->runtimeError("HasItem: item name expected"); + } else { + script->runtimeError("HasItem: item name expected"); + } stack->pushBool(false); return STATUS_OK; @@ -458,8 +495,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int offsetY = stack->pop()->getInt(); PartEmitter *emitter = createParticleEmitter(followParent, offsetX, offsetY); - if (emitter) stack->pushNative(_partEmitter, true); - else stack->pushNULL(); + if (emitter) { + stack->pushNative(_partEmitter, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -502,8 +542,11 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ent->_posY = offsetY; ent->_active = true; - if (preDisplay) _attachmentsPre.add(ent); - else _attachmentsPost.add(ent); + if (preDisplay) { + _attachmentsPre.add(ent); + } else { + _attachmentsPost.add(ent); + } stack->pushBool(true); } @@ -572,11 +615,15 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int index = val->getInt(); int currIndex = 0; for (int i = 0; i < _attachmentsPre.getSize(); i++) { - if (currIndex == index) ret = _attachmentsPre[i]; + if (currIndex == index) { + ret = _attachmentsPre[i]; + } currIndex++; } for (int i = 0; i < _attachmentsPost.getSize(); i++) { - if (currIndex == index) ret = _attachmentsPost[i]; + if (currIndex == index) { + ret = _attachmentsPost[i]; + } currIndex++; } } else { @@ -597,13 +644,16 @@ bool AdObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } - if (ret != NULL) stack->pushNative(ret, true); - else stack->pushNULL(); + if (ret != NULL) { + stack->pushNative(ret, true); + } else { + stack->pushNULL(); + } return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -695,8 +745,11 @@ ScValue *AdObject::scGetProperty(const char *name) { // ParticleEmitter (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ParticleEmitter") == 0) { - if (_partEmitter) _scValue->setNative(_partEmitter, true); - else _scValue->setNULL(); + if (_partEmitter) { + _scValue->setNative(_partEmitter, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -707,10 +760,9 @@ ScValue *AdObject::scGetProperty(const char *name) { else if (strcmp(name, "NumAttachments") == 0) { _scValue->setInt(_attachmentsPre.getSize() + _attachmentsPost.getSize()); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - - else return BaseObject::scGetProperty(name); } @@ -779,9 +831,9 @@ bool AdObject::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "SubtitlesPosXCenter") == 0) { _subtitlesModXCenter = value->getBool(); return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -792,8 +844,10 @@ const char *AdObject::scToString() { ////////////////////////////////////////////////////////////////////////// -bool AdObject::SetFont(const char *filename) { - if (_font) _gameRef->_fontStorage->removeFont(_font); +bool AdObject::setFont(const char *filename) { + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } if (filename) { _font = _gameRef->_fontStorage->addFont(filename); return _font == NULL ? STATUS_FAILED : STATUS_OK; @@ -806,8 +860,9 @@ bool AdObject::SetFont(const char *filename) { ////////////////////////////////////////////////////////////////////////// int AdObject::getHeight() { - if (!_currentSprite) return 0; - else { + if (!_currentSprite) { + return 0; + } else { BaseFrame *frame = _currentSprite->_frames[_currentSprite->_currentFrame]; int ret = 0; for (int i = 0; i < frame->_subframes.getSize(); i++) { @@ -825,8 +880,12 @@ int AdObject::getHeight() { ////////////////////////////////////////////////////////////////////////// void AdObject::talk(const char *text, const char *sound, uint32 duration, const char *stances, TTextAlign Align) { - if (!_sentence) _sentence = new AdSentence(_gameRef); - if (!_sentence) return; + if (!_sentence) { + _sentence = new AdSentence(_gameRef); + } + if (!_sentence) { + return; + } if (_forcedTalkAnimName && _forcedTalkAnimUsed) { delete[] _forcedTalkAnimName; @@ -855,7 +914,9 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const sound = ((AdGame *)_gameRef)->findSpeechFile(key); delete[] key; - if (sound) deleteSound = true; + if (sound) { + deleteSound = true; + } } } @@ -865,10 +926,14 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const if (snd && DID_SUCCEED(snd->setSound(sound, Audio::Mixer::kSpeechSoundType, true))) { _sentence->setSound(snd); if (_sentence->_duration <= 0) { - uint32 Length = snd->getLength(); - if (Length != 0) _sentence->_duration = Length; + uint32 length = snd->getLength(); + if (length != 0) { + _sentence->_duration = length; + } } - } else delete snd; + } else { + delete snd; + } } // set duration by text length @@ -888,11 +953,14 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const } - if (_subtitlesWidth > 0) width = _subtitlesWidth; - else { + if (_subtitlesWidth > 0) { + width = _subtitlesWidth; + } else { if ((x < _gameRef->_renderer->_width / 4 || x > _gameRef->_renderer->_width * 0.75) && !_gameRef->_touchInterface) { width = MAX(_gameRef->_renderer->_width / 4, MIN(x * 2, (_gameRef->_renderer->_width - x) * 2)); - } else width = _gameRef->_renderer->_width / 2; + } else { + width = _gameRef->_renderer->_width / 2; + } } height = _sentence->_font->getTextHeight((byte *)_sentence->_text, width); @@ -905,8 +973,9 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const x = _subtitlesModX; y = _subtitlesModY; } - if (_subtitlesModXCenter) + if (_subtitlesModXCenter) { x = x - width / 2; + } x = MIN(MAX(0, x), _gameRef->_renderer->_width - width); @@ -931,7 +1000,9 @@ void AdObject::talk(const char *text, const char *sound, uint32 duration, const _state = STATE_TALKING; - if (deleteSound) delete[] sound; + if (deleteSound) { + delete[] sound; + } } @@ -983,7 +1054,9 @@ bool AdObject::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_inventory)); persistMgr->transfer(TMEMBER(_partEmitter)); - for (int i = 0; i < MAX_NUM_REGIONS; i++) persistMgr->transfer(TMEMBER(_currentRegions[i])); + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + persistMgr->transfer(TMEMBER(_currentRegions[i])); + } _attachmentsPre.persist(persistMgr); _attachmentsPost.persist(persistMgr); @@ -999,8 +1072,9 @@ bool AdObject::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdObject::updateSounds() { - if (_sentence && _sentence->_sound) + if (_sentence && _sentence->_sound) { updateOneSound(_sentence->_sound); + } return BaseObject::updateSounds(); } @@ -1017,17 +1091,24 @@ bool AdObject::resetSoundPan() { ////////////////////////////////////////////////////////////////////////// bool AdObject::getExtendedFlag(const char *flagName) { - if (!flagName) return false; - else if (strcmp(flagName, "usable") == 0) return true; - - else return BaseObject::getExtendedFlag(flagName); + if (!flagName) { + return false; + } else if (strcmp(flagName, "usable") == 0) { + return true; + } else { + return BaseObject::getExtendedFlag(flagName); + } } ////////////////////////////////////////////////////////////////////////// bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { - if (_blockRegion) _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); - if (_wptGroup) _wptGroup->saveAsText(buffer, indent + 2); + if (_blockRegion) { + _blockRegion->saveAsText(buffer, indent + 2, "BLOCKED_REGION"); + } + if (_wptGroup) { + _wptGroup->saveAsText(buffer, indent + 2); + } BaseClass::saveAsText(buffer, indent + 2); @@ -1039,11 +1120,13 @@ bool AdObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { bool AdObject::updateBlockRegion() { AdGame *adGame = (AdGame *)_gameRef; if (adGame->_scene) { - if (_blockRegion && _currentBlockRegion) + if (_blockRegion && _currentBlockRegion) { _currentBlockRegion->mimic(_blockRegion, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } - if (_wptGroup && _currentWptGroup) + if (_wptGroup && _currentWptGroup) { _currentWptGroup->mimic(_wptGroup, _zoomable ? adGame->_scene->getScaleAt(_posY) : 100.0f, _posX, _posY); + } } return STATUS_OK; } @@ -1064,7 +1147,9 @@ bool AdObject::afterMove() { ((AdGame *)_gameRef)->_scene->getRegionsAt(_posX, _posY, newRegions, MAX_NUM_REGIONS); for (int i = 0; i < MAX_NUM_REGIONS; i++) { - if (!newRegions[i]) break; + if (!newRegions[i]) { + break; + } bool regFound = false; for (int j = 0; j < MAX_NUM_REGIONS; j++) { if (_currentRegions[j] == newRegions[i]) { @@ -1073,7 +1158,9 @@ bool AdObject::afterMove() { break; } } - if (!regFound) newRegions[i]->applyEvent("ActorEntry"); + if (!regFound) { + newRegions[i]->applyEvent("ActorEntry"); + } } for (int i = 0; i < MAX_NUM_REGIONS; i++) { @@ -1088,7 +1175,9 @@ bool AdObject::afterMove() { ////////////////////////////////////////////////////////////////////////// bool AdObject::invalidateCurrRegions() { - for (int i = 0; i < MAX_NUM_REGIONS; i++) _currentRegions[i] = NULL; + for (int i = 0; i < MAX_NUM_REGIONS; i++) { + _currentRegions[i] = NULL; + } return STATUS_OK; } @@ -1099,8 +1188,11 @@ bool AdObject::getScale(float *scaleX, float *scaleY) { if (_scaleX >= 0 || _scaleY >= 0) { *scaleX = _scaleX < 0 ? 100 : _scaleX; *scaleY = _scaleY < 0 ? 100 : _scaleY; - } else if (_scale >= 0) *scaleX = *scaleY = _scale; - else *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } else if (_scale >= 0) { + *scaleX = *scaleY = _scale; + } else { + *scaleX = *scaleY = ((AdGame *)_gameRef)->_scene->getZoomAt(_posX, _posY) + _relativeScale; + } } else { *scaleX = *scaleY = 100; } @@ -1134,7 +1226,9 @@ bool AdObject::displaySpriteAttachments(bool preDisplay) { ////////////////////////////////////////////////////////////////////////// bool AdObject::displaySpriteAttachment(AdObject *attachment) { - if (!attachment->_active) return STATUS_OK; + if (!attachment->_active) { + return STATUS_OK; + } float scaleX, scaleY; getScale(&scaleX, &scaleY); @@ -1188,7 +1282,9 @@ PartEmitter *AdObject::createParticleEmitter(bool followParent, int offsetX, int ////////////////////////////////////////////////////////////////////////// bool AdObject::updatePartEmitter() { - if (!_partEmitter) return STATUS_FAILED; + if (!_partEmitter) { + return STATUS_FAILED; + } if (_partFollowParent) { float scaleX, scaleY; diff --git a/engines/wintermute/ad/ad_object.h b/engines/wintermute/ad/ad_object.h index f26a29c8b2..58cb15fde3 100644 --- a/engines/wintermute/ad/ad_object.h +++ b/engines/wintermute/ad/ad_object.h @@ -73,7 +73,7 @@ public: virtual void talk(const char *text, const char *sound = NULL, uint32 duration = 0, const char *stances = NULL, TTextAlign align = TAL_CENTER); virtual int getHeight(); AdSentence *_sentence; - bool SetFont(const char *filename); + bool setFont(const char *filename); virtual bool update(); virtual bool display(); bool _drawn; diff --git a/engines/wintermute/ad/ad_path.cpp b/engines/wintermute/ad/ad_path.cpp index f7832d621d..89be10f0fb 100644 --- a/engines/wintermute/ad/ad_path.cpp +++ b/engines/wintermute/ad/ad_path.cpp @@ -48,8 +48,9 @@ AdPath::~AdPath() { ////////////////////////////////////////////////////////////////////////// void AdPath::reset() { - for (int i = 0; i < _points.getSize(); i++) + for (int i = 0; i < _points.getSize(); i++) { delete _points[i]; + } _points.removeAll(); _currIndex = -1; @@ -62,22 +63,30 @@ BasePoint *AdPath::getFirst() { if (_points.getSize() > 0) { _currIndex = 0; return _points[_currIndex]; - } else return NULL; + } else { + return NULL; + } } ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getNext() { _currIndex++; - if (_currIndex < _points.getSize()) return _points[_currIndex]; - else return NULL; + if (_currIndex < _points.getSize()) { + return _points[_currIndex]; + } else { + return NULL; + } } ////////////////////////////////////////////////////////////////////////// BasePoint *AdPath::getCurrent() { - if (_currIndex >= 0 && _currIndex < _points.getSize()) return _points[_currIndex]; - else return NULL; + if (_currIndex >= 0 && _currIndex < _points.getSize()) { + return _points[_currIndex]; + } else { + return NULL; + } } diff --git a/engines/wintermute/ad/ad_region.cpp b/engines/wintermute/ad/ad_region.cpp index eec25b2aaa..6b104d51ad 100644 --- a/engines/wintermute/ad/ad_region.cpp +++ b/engines/wintermute/ad/ad_region.cpp @@ -64,7 +64,9 @@ bool AdRegion::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + } delete[] buffer; @@ -126,7 +128,9 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { buffer = params; } - for (int i = 0; i < _points.getSize(); i++) delete _points[i]; + for (int i = 0; i < _points.getSize(); i++) { + delete _points[i]; + } _points.removeAll(); int ar = 255, ag = 255, ab = 255, alpha = 255; @@ -134,7 +138,9 @@ bool AdRegion::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -285,9 +291,9 @@ ScValue *AdRegion::scGetProperty(const char *name) { else if (strcmp(name, "AlphaColor") == 0) { _scValue->setInt((int)_alpha); return _scValue; + } else { + return BaseRegion::scGetProperty(name); } - - else return BaseRegion::scGetProperty(name); } @@ -331,9 +337,9 @@ bool AdRegion::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "AlphaColor") == 0) { _alpha = (uint32)value->getInt(); return STATUS_OK; + } else { + return BaseRegion::scSetProperty(name, value); } - - else return BaseRegion::scSetProperty(name, value); } @@ -361,7 +367,9 @@ bool AdRegion::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "SCRIPT=\"%s\"\n", _scripts[i]->_filename); } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } for (i = 0; i < _points.getSize(); i++) { buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); diff --git a/engines/wintermute/ad/ad_response.cpp b/engines/wintermute/ad/ad_response.cpp index fbfe828330..e954b0d44d 100644 --- a/engines/wintermute/ad/ad_response.cpp +++ b/engines/wintermute/ad/ad_response.cpp @@ -59,7 +59,9 @@ AdResponse::~AdResponse() { _icon = NULL; _iconHover = NULL; _iconPressed = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } } @@ -85,7 +87,9 @@ bool AdResponse::setIcon(const char *filename) { ////////////////////////////////////////////////////////////////////////// bool AdResponse::setFont(const char *filename) { - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont(filename); if (!_font) { _gameRef->LOG(0, "AdResponse::setFont failed for file '%s'", filename); diff --git a/engines/wintermute/ad/ad_response_box.cpp b/engines/wintermute/ad/ad_response_box.cpp index 22b40f3ea4..fe37002abb 100644 --- a/engines/wintermute/ad/ad_response_box.cpp +++ b/engines/wintermute/ad/ad_response_box.cpp @@ -81,8 +81,12 @@ AdResponseBox::~AdResponseBox() { delete[] _lastResponseTextOrig; _lastResponseTextOrig = NULL; - if (_font) _gameRef->_fontStorage->removeFont(_font); - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } clearResponses(); clearButtons(); @@ -137,12 +141,19 @@ bool AdResponseBox::createButtons() { // iconic if (_responses[i]->_icon) { btn->_image = _responses[i]->_icon; - if (_responses[i]->_iconHover) btn->_imageHover = _responses[i]->_iconHover; - if (_responses[i]->_iconPressed) btn->_imagePress = _responses[i]->_iconPressed; + if (_responses[i]->_iconHover) { + btn->_imageHover = _responses[i]->_iconHover; + } + if (_responses[i]->_iconPressed) { + btn->_imagePress = _responses[i]->_iconPressed; + } btn->setCaption(_responses[i]->_text); - if (_cursor) btn->_cursor = _cursor; - else if (_gameRef->_activeCursor) btn->_cursor = _gameRef->_activeCursor; + if (_cursor) { + btn->_cursor = _cursor; + } else if (_gameRef->_activeCursor) { + btn->_cursor = _gameRef->_activeCursor; + } } // textual else { @@ -152,21 +163,27 @@ bool AdResponseBox::createButtons() { btn->_fontPress = btn->_fontHover; btn->_align = _align; - if (_gameRef->_touchInterface) + if (_gameRef->_touchInterface) { btn->_fontHover = btn->_font; + } - if (_responses[i]->_font) btn->_font = _responses[i]->_font; + if (_responses[i]->_font) { + btn->_font = _responses[i]->_font; + } btn->_width = _responseArea.right - _responseArea.left; - if (btn->_width <= 0) btn->_width = _gameRef->_renderer->_width; + if (btn->_width <= 0) { + btn->_width = _gameRef->_renderer->_width; + } } btn->setName("response"); btn->correctSize(); // make the responses touchable - if (_gameRef->_touchInterface) + if (_gameRef->_touchInterface) { btn->_height = MAX(btn->_height, 50); + } //btn->SetListener(this, btn, _responses[i]->_iD); btn->setListener(this, btn, i); @@ -197,7 +214,9 @@ bool AdResponseBox::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing RESPONSE_BOX file '%s'", filename); + } delete[] buffer; @@ -253,7 +272,9 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_WINDOW: @@ -263,19 +284,29 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { delete _window; _window = NULL; cmd = PARSERR_GENERIC; - } else if (_shieldWindow) _shieldWindow->_parent = _window; + } else if (_shieldWindow) { + _shieldWindow->_parent = _window; + } break; case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; + if (!_font) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_HOVER: - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } _fontHover = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontHover) cmd = PARSERR_GENERIC; + if (!_fontHover) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_AREA: @@ -287,15 +318,23 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TEXT_ALIGN: - if (scumm_stricmp((char *)params, "center") == 0) _align = TAL_CENTER; - else if (scumm_stricmp((char *)params, "right") == 0) _align = TAL_RIGHT; - else _align = TAL_LEFT; + if (scumm_stricmp((char *)params, "center") == 0) { + _align = TAL_CENTER; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _align = TAL_RIGHT; + } else { + _align = TAL_LEFT; + } break; case TOKEN_VERTICAL_ALIGN: - if (scumm_stricmp((char *)params, "top") == 0) _verticalAlign = VAL_TOP; - else if (scumm_stricmp((char *)params, "center") == 0) _verticalAlign = VAL_CENTER; - else _verticalAlign = VAL_BOTTOM; + if (scumm_stricmp((char *)params, "top") == 0) { + _verticalAlign = VAL_TOP; + } else if (scumm_stricmp((char *)params, "center") == 0) { + _verticalAlign = VAL_CENTER; + } else { + _verticalAlign = VAL_BOTTOM; + } break; case TOKEN_SPACING: @@ -324,8 +363,9 @@ bool AdResponseBox::loadBuffer(byte *buffer, bool complete) { if (_window) { for (int i = 0; i < _window->_widgets.getSize(); i++) { - if (!_window->_widgets[i]->_listenerObject) + if (!_window->_widgets[i]->_listenerObject) { _window->_widgets[i]->setListener(this, _window->_widgets[i], 0); + } } } @@ -339,13 +379,16 @@ bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "AREA { %d, %d, %d, %d }\n", _responseArea.left, _responseArea.top, _responseArea.right, _responseArea.bottom); - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - if (_fontHover && _fontHover->getFilename()) + } + if (_fontHover && _fontHover->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } buffer->putTextIndent(indent + 2, "HORIZONTAL=%s\n", _horizontal ? "TRUE" : "FALSE"); @@ -381,7 +424,9 @@ bool AdResponseBox::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // window - if (_window) _window->saveAsText(buffer, indent + 2); + if (_window) { + _window->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); @@ -409,18 +454,22 @@ bool AdResponseBox::display() { // shift down if needed if (!_horizontal) { int total_height = 0; - for (i = 0; i < _respButtons.getSize(); i++) total_height += (_respButtons[i]->_height + _spacing); + for (i = 0; i < _respButtons.getSize(); i++) { + total_height += (_respButtons[i]->_height + _spacing); + } total_height -= _spacing; switch (_verticalAlign) { case VAL_BOTTOM: - if (yyy + total_height < rect.bottom) + if (yyy + total_height < rect.bottom) { yyy = rect.bottom - total_height; + } break; case VAL_CENTER: - if (yyy + total_height < rect.bottom) + if (yyy + total_height < rect.bottom) { yyy += ((rect.bottom - rect.top) - total_height) / 2; + } break; case VAL_TOP: @@ -467,7 +516,9 @@ bool AdResponseBox::display() { } // display window - if (_window) _window->display(); + if (_window) { + _window->display(); + } // display response buttons @@ -490,7 +541,9 @@ bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { } else if (scumm_stricmp(obj->getName(), "next") == 0) { _scrollOffset++; } else if (scumm_stricmp(obj->getName(), "response") == 0) { - if (_waitingScript) _waitingScript->_stack->pushInt(_responses[param2]->_iD); + if (_waitingScript) { + _waitingScript->_stack->pushInt(_responses[param2]->_iD); + } handleResponse(_responses[param2]); _waitingScript = NULL; _gameRef->_state = GAME_RUNNING; @@ -498,7 +551,9 @@ bool AdResponseBox::listen(BaseScriptHolder *param1, uint32 param2) { _ready = true; invalidateButtons(); clearResponses(); - } else return BaseObject::listen(param1, param2); + } else { + return BaseObject::listen(param1, param2); + } break; default: error("AdResponseBox::Listen - Unhandled enum"); @@ -597,13 +652,17 @@ BaseObject *AdResponseBox::getNextAccessObject(BaseObject *currObject) { BaseArray objects; getObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = 0; i < objects.getSize(); i++) { if (objects[i] == currObject) { - if (i < objects.getSize() - 1) return objects[i + 1]; - else break; + if (i < objects.getSize() - 1) { + return objects[i + 1]; + } else { + break; + } } } } @@ -617,13 +676,17 @@ BaseObject *AdResponseBox::getPrevAccessObject(BaseObject *currObject) { BaseArray objects; getObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = objects.getSize() - 1; i >= 0; i--) { if (objects[i] == currObject) { - if (i > 0) return objects[i - 1]; - else break; + if (i > 0) { + return objects[i - 1]; + } else { + break; + } } } } @@ -637,7 +700,9 @@ bool AdResponseBox::getObjects(BaseArray &objects, bool for (int i = 0; i < _respButtons.getSize(); i++) { objects.add(_respButtons[i]); } - if (_window) _window->getWindowObjects(objects, interactiveOnly); + if (_window) { + _window->getWindowObjects(objects, interactiveOnly); + } return STATUS_OK; } diff --git a/engines/wintermute/ad/ad_response_context.cpp b/engines/wintermute/ad/ad_response_context.cpp index 8d966e7a3e..41359fc0f0 100644 --- a/engines/wintermute/ad/ad_response_context.cpp +++ b/engines/wintermute/ad/ad_response_context.cpp @@ -35,7 +35,7 @@ IMPLEMENT_PERSISTENT(AdResponseContext, false) ////////////////////////////////////////////////////////////////////////// AdResponseContext::AdResponseContext(BaseGame *inGame): BaseClass(inGame) { - _iD = 0; + _id = 0; _context = NULL; } @@ -51,7 +51,7 @@ AdResponseContext::~AdResponseContext() { bool AdResponseContext::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_gameRef)); persistMgr->transfer(TMEMBER(_context)); - persistMgr->transfer(TMEMBER(_iD)); + persistMgr->transfer(TMEMBER(_id)); return STATUS_OK; } @@ -62,7 +62,9 @@ void AdResponseContext::setContext(const char *context) { _context = NULL; if (context) { _context = new char [strlen(context) + 1]; - if (_context) strcpy(_context, context); + if (_context) { + strcpy(_context, context); + } } } diff --git a/engines/wintermute/ad/ad_response_context.h b/engines/wintermute/ad/ad_response_context.h index d0dc1546b7..d5c8bb3fa3 100644 --- a/engines/wintermute/ad/ad_response_context.h +++ b/engines/wintermute/ad/ad_response_context.h @@ -37,7 +37,7 @@ namespace WinterMute { class AdResponseContext : public BaseClass { public: void setContext(const char *context); - int _iD; + int _id; char *_context; DECLARE_PERSISTENT(AdResponseContext, BaseClass) AdResponseContext(BaseGame *inGame); diff --git a/engines/wintermute/ad/ad_rot_level.cpp b/engines/wintermute/ad/ad_rot_level.cpp index 72fcaeff28..f04d379e6b 100644 --- a/engines/wintermute/ad/ad_rot_level.cpp +++ b/engines/wintermute/ad/ad_rot_level.cpp @@ -63,7 +63,9 @@ bool AdRotLevel::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ROTATION_LEVEL file '%s'", filename); + } delete[] buffer; @@ -104,7 +106,9 @@ bool AdRotLevel::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_X: diff --git a/engines/wintermute/ad/ad_scale_level.cpp b/engines/wintermute/ad/ad_scale_level.cpp index c390c6dc08..f9da6bba4a 100644 --- a/engines/wintermute/ad/ad_scale_level.cpp +++ b/engines/wintermute/ad/ad_scale_level.cpp @@ -61,7 +61,9 @@ bool AdScaleLevel::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SCALE_LEVEL file '%s'", filename); + } delete[] buffer; @@ -102,7 +104,9 @@ bool AdScaleLevel::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_Y: diff --git a/engines/wintermute/ad/ad_scene.cpp b/engines/wintermute/ad/ad_scene.cpp index 85c2341268..21f28b6247 100644 --- a/engines/wintermute/ad/ad_scene.cpp +++ b/engines/wintermute/ad/ad_scene.cpp @@ -148,31 +148,37 @@ void AdScene::cleanup() { _gameRef->unregisterObject(_fader); _fader = NULL; - for (i = 0; i < _layers.getSize(); i++) + for (i = 0; i < _layers.getSize(); i++) { _gameRef->unregisterObject(_layers[i]); + } _layers.removeAll(); - for (i = 0; i < _waypointGroups.getSize(); i++) + for (i = 0; i < _waypointGroups.getSize(); i++) { _gameRef->unregisterObject(_waypointGroups[i]); + } _waypointGroups.removeAll(); - for (i = 0; i < _scaleLevels.getSize(); i++) + for (i = 0; i < _scaleLevels.getSize(); i++) { _gameRef->unregisterObject(_scaleLevels[i]); + } _scaleLevels.removeAll(); - for (i = 0; i < _rotLevels.getSize(); i++) + for (i = 0; i < _rotLevels.getSize(); i++) { _gameRef->unregisterObject(_rotLevels[i]); + } _rotLevels.removeAll(); - for (i = 0; i < _pfPath.getSize(); i++) + for (i = 0; i < _pfPath.getSize(); i++) { delete _pfPath[i]; + } _pfPath.removeAll(); _pfPointsNum = 0; - for (i = 0; i < _objects.getSize(); i++) + for (i = 0; i < _objects.getSize(); i++) { _gameRef->unregisterObject(_objects[i]); + } _objects.removeAll(); delete _viewport; @@ -184,8 +190,9 @@ void AdScene::cleanup() { ////////////////////////////////////////////////////////////////////////// bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObject *requester) { - if (!_pfReady) return false; - else { + if (!_pfReady) { + return false; + } else { _pfReady = false; *_pfTarget = target; _pfTargetPath = path; @@ -258,10 +265,14 @@ bool AdScene::getPath(BasePoint source, BasePoint target, AdPath *path, BaseObje ////////////////////////////////////////////////////////////////////////// void AdScene::pfAddWaypointGroup(AdWaypointGroup *wpt, BaseObject *requester) { - if (!wpt->_active) return; + if (!wpt->_active) { + return; + } for (int i = 0; i < wpt->_points.getSize(); i++) { - if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) continue; + if (isBlockedAt(wpt->_points[i]->x, wpt->_points[i]->y, true, requester)) { + continue; + } //_pfPath.add(new AdPathPoint(Wpt->_points[i]->x, Wpt->_points[i]->y, INT_MAX)); pfPointsAdd(wpt->_points[i]->x, wpt->_points[i]->y, INT_MAX); @@ -286,7 +297,9 @@ float AdScene::getZoomAt(int x, int y) { } } } - if (!found) ret = getScaleAt(y); + if (!found) { + ret = getScaleAt(y); + } return ret; } @@ -294,17 +307,24 @@ float AdScene::getZoomAt(int x, int y) { ////////////////////////////////////////////////////////////////////////// uint32 AdScene::getAlphaAt(int x, int y, bool colorCheck) { - if (!_gameRef->_debugDebugMode) colorCheck = false; + if (!_gameRef->_debugDebugMode) { + colorCheck = false; + } uint32 ret; - if (colorCheck) ret = 0xFFFF0000; - else ret = 0xFFFFFFFF; + if (colorCheck) { + ret = 0xFFFF0000; + } else { + ret = 0xFFFFFFFF; + } if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && (colorCheck || !node->_region->_blocked) && node->_region->pointInRegion(x, y)) { - if (!node->_region->_blocked) ret = node->_region->_alpha; + if (!node->_region->_blocked) { + ret = node->_region->_alpha; + } break; } } @@ -321,13 +341,17 @@ bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *reque if (checkFreeObjects) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return true; + } } } AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return true; + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return true; + } } } } @@ -347,7 +371,9 @@ bool AdScene::isBlockedAt(int x, int y, bool checkFreeObjects, BaseObject *reque if (node->_region->_blocked) { ret = true; break; - } else ret = false; + } else { + ret = false; + } } } } @@ -362,13 +388,17 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ if (checkFreeObjects) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_active && _objects[i] != requester && _objects[i]->_currentBlockRegion) { - if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + if (_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return false; + } } } AdGame *adGame = (AdGame *)_gameRef; for (int i = 0; i < adGame->_objects.getSize(); i++) { if (adGame->_objects[i]->_active && adGame->_objects[i] != requester && adGame->_objects[i]->_currentBlockRegion) { - if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) return false; + if (adGame->_objects[i]->_currentBlockRegion->pointInRegion(x, y)) { + return false; + } } } } @@ -381,7 +411,9 @@ bool AdScene::isWalkableAt(int x, int y, bool checkFreeObjects, BaseObject *requ if (node->_region->_blocked) { ret = false; break; - } else ret = true; + } else { + ret = true; + } } } } @@ -413,7 +445,9 @@ int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { y = y1; for (xCount = x1; xCount < x2; xCount++) { - if (isBlockedAt(xCount, (int)y, true, requester)) return -1; + if (isBlockedAt(xCount, (int)y, true, requester)) { + return -1; + } y += yStep; } } else { @@ -426,7 +460,9 @@ int AdScene::getPointsDist(BasePoint p1, BasePoint p2, BaseObject *requester) { x = x1; for (yCount = y1; yCount < y2; yCount++) { - if (isBlockedAt((int)x, yCount, true, requester)) return -1; + if (isBlockedAt((int)x, yCount, true, requester)) { + return -1; + } x += xStep; } } @@ -488,10 +524,14 @@ bool AdScene::initLoop() { PathFinderStep(); nu_steps++; } - if (nu_steps > 0) _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); + if (nu_steps > 0) { + _gameRef->LOG(0, "STAT: PathFinder iterations in one loop: %d (%s) _pfMaxTime=%d", nu_steps, _pfReady ? "finished" : "not yet done", _pfMaxTime); + } #else uint32 start = _gameRef->_currentTime; - while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) pathFinderStep(); + while (!_pfReady && g_system->getMillis() - start <= _pfMaxTime) { + pathFinderStep(); + } #endif return STATUS_OK; @@ -510,7 +550,9 @@ bool AdScene::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SCENE file '%s'", filename); + } setFilename(filename); @@ -622,7 +664,9 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -815,8 +859,12 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { case TOKEN_VIEWPORT: { Rect32 rc; parser.scanStr((char *)params, "%d,%d,%d,%d", &rc.left, &rc.top, &rc.right, &rc.bottom); - if (!_viewport) _viewport = new BaseViewport(_gameRef); - if (_viewport) _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } + if (_viewport) { + _viewport->setRect(rc.left, rc.top, rc.right, rc.bottom, true); + } } case TOKEN_PERSISTENT_STATE: @@ -838,7 +886,9 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } - if (_mainLayer == NULL) _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); + if (_mainLayer == NULL) { + _gameRef->LOG(0, "Warning: scene '%s' has no main layer.", getFilename()); + } sortScaleLevels(); @@ -852,7 +902,9 @@ bool AdScene::loadBuffer(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// bool AdScene::traverseNodes(bool doUpdate) { - if (!_initialized) return STATUS_OK; + if (!_initialized) { + return STATUS_OK; + } int j, k; AdGame *adGame = (AdGame *)_gameRef; @@ -860,13 +912,13 @@ bool AdScene::traverseNodes(bool doUpdate) { ////////////////////////////////////////////////////////////////////////// // prepare viewport - bool PopViewport = false; + bool popViewport = false; if (_viewport && !_gameRef->_editorMode) { _gameRef->pushViewport(_viewport); - PopViewport = true; + popViewport = true; } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { _gameRef->pushViewport(adGame->_sceneViewport); - PopViewport = true; + popViewport = true; } @@ -905,8 +957,12 @@ bool AdScene::traverseNodes(bool doUpdate) { } } - if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) _ready = true; - } else _ready = true; // not scrolling, i.e. always ready + if (_offsetTop == _targetOffsetTop && _offsetLeft == _targetOffsetLeft) { + _ready = true; + } + } else { + _ready = true; // not scrolling, i.e. always ready + } } @@ -939,12 +995,16 @@ bool AdScene::traverseNodes(bool doUpdate) { /* int MainOffsetY = 0; */ for (j = 0; j < _layers.getSize(); j++) { - if (!_layers[j]->_active) continue; + if (!_layers[j]->_active) { + continue; + } // make layer exclusive if (!doUpdate) { if (_layers[j]->_closeUp && !_gameRef->_editorMode) { - if (!_shieldWindow) _shieldWindow = new UIWindow(_gameRef); + if (!_shieldWindow) { + _shieldWindow = new UIWindow(_gameRef); + } if (_shieldWindow) { _shieldWindow->_posX = _shieldWindow->_posY = 0; _shieldWindow->_width = _gameRef->_renderer->_width; @@ -979,16 +1039,25 @@ bool AdScene::traverseNodes(bool doUpdate) { if (node->_entity->_active && (_gameRef->_editorMode || !node->_entity->_editorOnly)) { _gameRef->_renderer->setup2D(); - if (doUpdate) node->_entity->update(); - else node->_entity->display(); + if (doUpdate) { + node->_entity->update(); + } else { + node->_entity->display(); + } } break; case OBJECT_REGION: { - if (node->_region->_blocked) break; - if (node->_region->_decoration) break; + if (node->_region->_blocked) { + break; + } + if (node->_region->_decoration) { + break; + } - if (!doUpdate) displayRegionContent(node->_region); + if (!doUpdate) { + displayRegionContent(node->_region); + } } break; default: @@ -1014,11 +1083,16 @@ bool AdScene::traverseNodes(bool doUpdate) { // display/update fader if (_fader) { - if (doUpdate) _fader->update(); - else _fader->display(); + if (doUpdate) { + _fader->update(); + } else { + _fader->display(); + } } - if (PopViewport) _gameRef->popViewport(); + if (popViewport) { + _gameRef->popViewport(); + } return STATUS_OK; } @@ -1037,7 +1111,9 @@ bool AdScene::updateFreeObjects() { // *** update all active objects is3DSet = false; for (int i = 0; i < adGame->_objects.getSize(); i++) { - if (!adGame->_objects[i]->_active) continue; + if (!adGame->_objects[i]->_active) { + continue; + } adGame->_objects[i]->update(); adGame->_objects[i]->_drawn = false; @@ -1045,7 +1121,9 @@ bool AdScene::updateFreeObjects() { for (int i = 0; i < _objects.getSize(); i++) { - if (!_objects[i]->_active) continue; + if (!_objects[i]->_active) { + continue; + } _objects[i]->update(); _objects[i]->_drawn = false; @@ -1090,11 +1168,15 @@ bool AdScene::displayRegionContent(AdRegion *region, bool display3DOnly) { for (int i = 0; i < objects.getSize(); i++) { obj = objects[i]; - if (display3DOnly && !obj->_is3D) continue; + if (display3DOnly && !obj->_is3D) { + continue; + } _gameRef->_renderer->setup2D(); - if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + if (_gameRef->_editorMode || !obj->_editorOnly) { + obj->display(); + } obj->_drawn = true; } @@ -1119,9 +1201,13 @@ int AdScene::compareObjs(const void *obj1, const void *obj2) { AdObject *object1 = *(AdObject **)obj1; AdObject *object2 = *(AdObject **)obj2; - if (object1->_posY < object2->_posY) return -1; - else if (object1->_posY > object2->_posY) return 1; - else return 0; + if (object1->_posY < object2->_posY) { + return -1; + } else if (object1->_posY > object2->_posY) { + return 1; + } else { + return 0; + } } ////////////////////////////////////////////////////////////////////////// @@ -1154,7 +1240,9 @@ bool AdScene::displayRegionContentOld(AdRegion *region) { if (obj != NULL) { _gameRef->_renderer->setup2D(); - if (_gameRef->_editorMode || !obj->_editorOnly) obj->display(); + if (_gameRef->_editorMode || !obj->_editorOnly) { + obj->display(); + } obj->_drawn = true; } } while (obj != NULL); @@ -1195,8 +1283,12 @@ void AdScene::scrollTo(int offsetX, int offsetY) { if (_gameRef->_mainObject && _gameRef->_mainObject->_is3D) { - if (abs(origOffsetLeft - _targetOffsetLeft) < 5) _targetOffsetLeft = origOffsetLeft; - if (abs(origOffsetTop - _targetOffsetTop) < 5) _targetOffsetTop = origOffsetTop; + if (abs(origOffsetLeft - _targetOffsetLeft) < 5) { + _targetOffsetLeft = origOffsetLeft; + } + if (abs(origOffsetTop - _targetOffsetTop) < 5) { + _targetOffsetTop = origOffsetTop; + } //_targetOffsetTop = 0; } @@ -1206,13 +1298,17 @@ void AdScene::scrollTo(int offsetX, int offsetY) { ////////////////////////////////////////////////////////////////////////// void AdScene::scrollToObject(BaseObject *object) { - if (object) scrollTo(object->_posX, object->_posY - object->getHeight() / 2); + if (object) { + scrollTo(object->_posX, object->_posY - object->getHeight() / 2); + } } ////////////////////////////////////////////////////////////////////////// void AdScene::skipToObject(BaseObject *object) { - if (object) skipTo(object->_posX, object->_posY - object->getHeight() / 2); + if (object) { + skipTo(object->_posX, object->_posY - object->getHeight() / 2); + } } @@ -1279,7 +1375,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdEntity *ent = new AdEntity(_gameRef); addObject(ent); - if (!val->isNULL()) ent->setName(val->getString()); + if (!val->isNULL()) { + ent->setName(val->getString()); + } stack->pushNative(ent, true); return STATUS_OK; } @@ -1292,7 +1390,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdObject *obj = (AdObject *)val->getNative(); removeObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } stack->pushNULL(); return STATUS_OK; @@ -1326,7 +1426,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } else { scrollTo(val1->getInt(), val2->getInt()); } - if (strcmp(name, "ScrollTo") == 0) script->waitForExclusive(this); + if (strcmp(name, "ScrollTo") == 0) { + script->waitForExclusive(this); + } stack->pushNULL(); return STATUS_OK; } @@ -1339,19 +1441,24 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); if (val->isInt()) { int layer = val->getInt(); - if (layer < 0 || layer >= _layers.getSize()) stack->pushNULL(); - else stack->pushNative(_layers[layer], true); + if (layer < 0 || layer >= _layers.getSize()) { + stack->pushNULL(); + } else { + stack->pushNative(_layers[layer], true); + } } else { - const char *LayerName = val->getString(); - bool LayerFound = false; + const char *layerName = val->getString(); + bool layerFound = false; for (int i = 0; i < _layers.getSize(); i++) { - if (scumm_stricmp(LayerName, _layers[i]->getName()) == 0) { + if (scumm_stricmp(layerName, _layers[i]->getName()) == 0) { stack->pushNative(_layers[i], true); - LayerFound = true; + layerFound = true; break; } } - if (!LayerFound) stack->pushNULL(); + if (!layerFound) { + stack->pushNULL(); + } } return STATUS_OK; } @@ -1362,8 +1469,11 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, else if (strcmp(name, "GetWaypointGroup") == 0) { stack->correctParams(1); int group = stack->pop()->getInt(); - if (group < 0 || group >= _waypointGroups.getSize()) stack->pushNULL(); - else stack->pushNative(_waypointGroups[group], true); + if (group < 0 || group >= _waypointGroups.getSize()) { + stack->pushNULL(); + } else { + stack->pushNative(_waypointGroups[group], true); + } return STATUS_OK; } @@ -1375,8 +1485,11 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, const char *nodeName = stack->pop()->getString(); BaseObject *node = getNodeByName(nodeName); - if (node) stack->pushNative((BaseScriptable *)node, true); - else stack->pushNULL(); + if (node) { + stack->pushNative((BaseScriptable *)node, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -1391,7 +1504,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, AdObject *ret = NULL; if (val->isInt()) { int index = val->getInt(); - if (index >= 0 && index < _objects.getSize()) ret = _objects[index]; + if (index >= 0 && index < _objects.getSize()) { + ret = _objects[index]; + } } else { const char *nodeName = val->getString(); for (int i = 0; i < _objects.getSize(); i++) { @@ -1401,8 +1516,11 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } } } - if (ret) stack->pushNative(ret, true); - else stack->pushNULL(); + if (ret) { + stack->pushNative(ret, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -1417,13 +1535,17 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); bool includeDecors = false; - if (!val->isNULL()) includeDecors = val->getBool(); + if (!val->isNULL()) { + includeDecors = val->getBool(); + } if (_mainLayer) { for (int i = _mainLayer->_nodes.getSize() - 1; i >= 0; i--) { AdSceneNode *node = _mainLayer->_nodes[i]; if (node->_type == OBJECT_REGION && node->_region->_active && node->_region->pointInRegion(x, y)) { - if (node->_region->_decoration && !includeDecors) continue; + if (node->_region->_decoration && !includeDecors) { + continue; + } stack->pushNative(node->_region, true); return STATUS_OK; @@ -1489,7 +1611,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->correctParams(0); bool ret = false; if (_autoScroll) { - if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) ret = true; + if (_targetOffsetLeft != _offsetLeft || _targetOffsetTop != _offsetTop) { + ret = true; + } } stack->pushBool(ret); @@ -1508,7 +1632,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, byte alpha = stack->pop()->getInt(0xFF); _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeOutAsync") != 0) script->waitFor(_fader); + if (strcmp(name, "FadeOutAsync") != 0) { + script->waitFor(_fader); + } stack->pushNULL(); return STATUS_OK; @@ -1526,7 +1652,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, byte alpha = stack->pop()->getInt(0xFF); _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration); - if (strcmp(name, "FadeInAsync") != 0) script->waitFor(_fader); + if (strcmp(name, "FadeInAsync") != 0) { + script->waitFor(_fader); + } stack->pushNULL(); return STATUS_OK; @@ -1562,11 +1690,19 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, int width = stack->pop()->getInt(); int height = stack->pop()->getInt(); - if (width <= 0) width = _gameRef->_renderer->_width; - if (height <= 0) height = _gameRef->_renderer->_height; + if (width <= 0) { + width = _gameRef->_renderer->_width; + } + if (height <= 0) { + height = _gameRef->_renderer->_height; + } - if (!_viewport) _viewport = new BaseViewport(_gameRef); - if (_viewport) _viewport->setRect(x, y, x + width, y + height); + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } + if (_viewport) { + _viewport->setRect(x, y, x + width, y + height); + } stack->pushBool(true); @@ -1581,7 +1717,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdLayer *layer = new AdLayer(_gameRef); - if (!val->isNULL()) layer->setName(val->getString()); + if (!val->isNULL()) { + layer->setName(val->getString()); + } if (_mainLayer) { layer->_width = _mainLayer->_width; layer->_height = _mainLayer->_height; @@ -1602,14 +1740,21 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ScValue *val = stack->pop(); AdLayer *layer = new AdLayer(_gameRef); - if (!val->isNULL()) layer->setName(val->getString()); + if (!val->isNULL()) { + layer->setName(val->getString()); + } if (_mainLayer) { layer->_width = _mainLayer->_width; layer->_height = _mainLayer->_height; } - if (index < 0) index = 0; - if (index <= _layers.getSize() - 1) _layers.insertAt(index, layer); - else _layers.add(layer); + if (index < 0) { + index = 0; + } + if (index <= _layers.getSize() - 1) { + _layers.insertAt(index, layer); + } else { + _layers.add(layer); + } _gameRef->registerObject(layer); @@ -1659,9 +1804,9 @@ bool AdScene::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } stack->pushBool(true); return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -1697,8 +1842,11 @@ ScValue *AdScene::scGetProperty(const char *name) { // MainLayer (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "MainLayer") == 0) { - if (_mainLayer) _scValue->setNative(_mainLayer, true); - else _scValue->setNULL(); + if (_mainLayer) { + _scValue->setNative(_mainLayer, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -1810,8 +1958,11 @@ ScValue *AdScene::scGetProperty(const char *name) { // Width (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Width") == 0) { - if (_mainLayer) _scValue->setInt(_mainLayer->_width); - else _scValue->setInt(0); + if (_mainLayer) { + _scValue->setInt(_mainLayer->_width); + } else { + _scValue->setInt(0); + } return _scValue; } @@ -1819,12 +1970,15 @@ ScValue *AdScene::scGetProperty(const char *name) { // Height (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Height") == 0) { - if (_mainLayer) _scValue->setInt(_mainLayer->_height); - else _scValue->setInt(0); + if (_mainLayer) { + _scValue->setInt(_mainLayer->_height); + } else { + _scValue->setInt(0); + } return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -1924,9 +2078,9 @@ bool AdScene::scSetProperty(const char *name, ScValue *value) { _targetOffsetTop = _offsetTop; return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -1964,11 +2118,13 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); - if (_persistentState) + if (_persistentState) { buffer->putTextIndent(indent + 2, "PERSISTENT_STATE=%s\n", _persistentState ? "TRUE" : "FALSE"); + } - if (!_persistentStateSprites) + if (!_persistentStateSprites) { buffer->putTextIndent(indent + 2, "PERSISTENT_STATE_SPRITES=%s\n", _persistentStateSprites ? "TRUE" : "FALSE"); + } // scripts @@ -1979,7 +2135,9 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); // properties - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } // viewport if (_viewport) { @@ -2018,21 +2176,29 @@ bool AdScene::saveAsText(BaseDynamicBuffer *buffer, int indent) { // waypoints buffer->putTextIndent(indent + 2, "; ----- waypoints\n"); - for (i = 0; i < _waypointGroups.getSize(); i++) _waypointGroups[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _waypointGroups.getSize(); i++) { + _waypointGroups[i]->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); // layers buffer->putTextIndent(indent + 2, "; ----- layers\n"); - for (i = 0; i < _layers.getSize(); i++) _layers[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _layers.getSize(); i++) { + _layers[i]->saveAsText(buffer, indent + 2); + } // scale levels buffer->putTextIndent(indent + 2, "; ----- scale levels\n"); - for (i = 0; i < _scaleLevels.getSize(); i++) _scaleLevels[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _scaleLevels.getSize(); i++) { + _scaleLevels[i]->saveAsText(buffer, indent + 2); + } // rotation levels buffer->putTextIndent(indent + 2, "; ----- rotation levels\n"); - for (i = 0; i < _rotLevels.getSize(); i++) _rotLevels[i]->saveAsText(buffer, indent + 2); + for (i = 0; i < _rotLevels.getSize(); i++) { + _rotLevels[i]->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent + 2, "\n"); @@ -2103,14 +2269,17 @@ float AdScene::getScaleAt(int Y) { for (int i = 0; i < _scaleLevels.getSize(); i++) { /* AdScaleLevel *xxx = _scaleLevels[i];*/ /* int j = _scaleLevels.getSize(); */ - if (_scaleLevels[i]->_posY < Y) prev = _scaleLevels[i]; - else { + if (_scaleLevels[i]->_posY < Y) { + prev = _scaleLevels[i]; + } else { next = _scaleLevels[i]; break; } } - if (prev == NULL || next == NULL) return 100; + if (prev == NULL || next == NULL) { + return 100; + } int delta_y = next->_posY - prev->_posY; float delta_scale = next->_scale - prev->_scale; @@ -2255,70 +2424,86 @@ bool AdScene::correctTargetPoint(int startX, int startY, int *argX, int *argY, b } // right - int length_right = 0; - bool found_right = false; - for (x = *argX, y = *argY; x < _mainLayer->_width; x++, length_right++) { + int lengthRight = 0; + bool foundRight = false; + for (x = *argX, y = *argY; x < _mainLayer->_width; x++, lengthRight++) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x - 5, y, checkFreeObjects, requester)) { - found_right = true; + foundRight = true; break; } } // left - int length_left = 0; - bool found_left = false; - for (x = *argX, y = *argY; x >= 0; x--, length_left--) { + int lengthLeft = 0; + bool foundLeft = false; + for (x = *argX, y = *argY; x >= 0; x--, lengthLeft--) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x + 5, y, checkFreeObjects, requester)) { - found_left = true; + foundLeft = true; break; } } // up - int length_up = 0; - bool found_up = false; - for (x = *argX, y = *argY; y >= 0; y--, length_up--) { + int lengthUp = 0; + bool foundUp = false; + for (x = *argX, y = *argY; y >= 0; y--, lengthUp--) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y + 5, checkFreeObjects, requester)) { - found_up = true; + foundUp = true; break; } } // down - int length_down = 0; - bool found_down = false; - for (x = *argX, y = *argY; y < _mainLayer->_height; y++, length_down++) { + int lengthDown = 0; + bool foundDown = false; + for (x = *argX, y = *argY; y < _mainLayer->_height; y++, lengthDown++) { if (isWalkableAt(x, y, checkFreeObjects, requester) && isWalkableAt(x, y - 5, checkFreeObjects, requester)) { - found_down = true; + foundDown = true; break; } } - if (!found_left && !found_right && !found_up && !found_down) { + if (!foundLeft && !foundRight && !foundUp && !foundDown) { return STATUS_OK; } - int OffsetX = INT_MAX, OffsetY = INT_MAX; + int offsetX = INT_MAX, offsetY = INT_MAX; - if (found_left && found_right) { - if (abs(length_left) < abs(length_right)) OffsetX = length_left; - else OffsetX = length_right; - } else if (found_left) OffsetX = length_left; - else if (found_right) OffsetX = length_right; + if (foundLeft && foundRight) { + if (abs(lengthLeft) < abs(lengthRight)) { + offsetX = lengthLeft; + } else { + offsetX = lengthRight; + } + } else if (foundLeft) { + offsetX = lengthLeft; + } else if (foundRight) { + offsetX = lengthRight; + } - if (found_up && found_down) { - if (abs(length_up) < abs(length_down)) OffsetY = length_up; - else OffsetY = length_down; - } else if (found_up) OffsetY = length_up; - else if (found_down) OffsetY = length_down; + if (foundUp && foundDown) { + if (abs(lengthUp) < abs(lengthDown)) { + offsetY = lengthUp; + } else { + offsetY = lengthDown; + } + } else if (foundUp) { + offsetY = lengthUp; + } else if (foundDown) { + offsetY = lengthDown; + } - if (abs(OffsetX) < abs(OffsetY)) - *argX = *argX + OffsetX; - else - *argY = *argY + OffsetY; + if (abs(offsetX) < abs(offsetY)) { + *argX = *argX + offsetX; + } else { + *argY = *argY + offsetY; + } - if (!isWalkableAt(*argX, *argY)) return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); - else return STATUS_OK; + if (!isWalkableAt(*argX, *argY)) { + return correctTargetPoint2(startX, startY, argX, argY, checkFreeObjects, requester); + } else { + return STATUS_OK; + } } @@ -2348,14 +2533,26 @@ void AdScene::pfPointsAdd(int x, int y, int distance) { bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { AdGame *adGame = (AdGame *)_gameRef; if (_viewport && !_gameRef->_editorMode) { - if (offsetX) *offsetX = _viewport->_offsetX; - if (offsetY) *offsetY = _viewport->_offsetY; + if (offsetX) { + *offsetX = _viewport->_offsetX; + } + if (offsetY) { + *offsetY = _viewport->_offsetY; + } } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (offsetX) *offsetX = adGame->_sceneViewport->_offsetX; - if (offsetY) *offsetY = adGame->_sceneViewport->_offsetY; + if (offsetX) { + *offsetX = adGame->_sceneViewport->_offsetX; + } + if (offsetY) { + *offsetY = adGame->_sceneViewport->_offsetY; + } } else { - if (offsetX) *offsetX = 0; - if (offsetY) *offsetY = 0; + if (offsetX) { + *offsetX = 0; + } + if (offsetY) { + *offsetY = 0; + } } return STATUS_OK; } @@ -2365,14 +2562,26 @@ bool AdScene::getViewportOffset(int *offsetX, int *offsetY) { bool AdScene::getViewportSize(int *width, int *height) { AdGame *adGame = (AdGame *)_gameRef; if (_viewport && !_gameRef->_editorMode) { - if (width) *width = _viewport->getWidth(); - if (height) *height = _viewport->getHeight(); + if (width) { + *width = _viewport->getWidth(); + } + if (height) { + *height = _viewport->getHeight(); + } } else if (adGame->_sceneViewport && !_gameRef->_editorMode) { - if (width) *width = adGame->_sceneViewport->getWidth(); - if (height) *height = adGame->_sceneViewport->getHeight(); + if (width) { + *width = adGame->_sceneViewport->getWidth(); + } + if (height) { + *height = adGame->_sceneViewport->getHeight(); + } } else { - if (width) *width = _gameRef->_renderer->_width; - if (height) *height = _gameRef->_renderer->_height; + if (width) { + *width = _gameRef->_renderer->_width; + } + if (height) { + *height = _gameRef->_renderer->_height; + } } return STATUS_OK; } @@ -2472,11 +2681,15 @@ bool AdScene::loadState() { ////////////////////////////////////////////////////////////////////////// bool AdScene::persistState(bool saving) { - if (!_persistentState) return STATUS_OK; + if (!_persistentState) { + return STATUS_OK; + } AdGame *adGame = (AdGame *)_gameRef; AdSceneState *state = adGame->getSceneState(getFilename(), saving); - if (!state) return STATUS_OK; + if (!state) { + return STATUS_OK; + } AdNodeState *nodeState; @@ -2487,7 +2700,9 @@ bool AdScene::persistState(bool saving) { AdSceneNode *node = layer->_nodes[j]; switch (node->_type) { case OBJECT_ENTITY: - if (!node->_entity->_saveState) continue; + if (!node->_entity->_saveState) { + continue; + } nodeState = state->getNodeState(node->_entity->getName(), saving); if (nodeState) { nodeState->transferEntity(node->_entity, _persistentStateSprites, saving); @@ -2496,11 +2711,16 @@ bool AdScene::persistState(bool saving) { } break; case OBJECT_REGION: - if (!node->_region->_saveState) continue; + if (!node->_region->_saveState) { + continue; + } nodeState = state->getNodeState(node->_region->getName(), saving); if (nodeState) { - if (saving) nodeState->_active = node->_region->_active; - else node->_region->_active = nodeState->_active; + if (saving) { + nodeState->_active = node->_region->_active; + } else { + node->_region->_active = nodeState->_active; + } } break; default: @@ -2512,7 +2732,9 @@ bool AdScene::persistState(bool saving) { // free entities for (int i = 0; i < _objects.getSize(); i++) { - if (!_objects[i]->_saveState) continue; + if (!_objects[i]->_saveState) { + continue; + } if (_objects[i]->_type == OBJECT_ENTITY) { nodeState = state->getNodeState(_objects[i]->getName(), saving); if (nodeState) { @@ -2527,8 +2749,11 @@ bool AdScene::persistState(bool saving) { for (int i = 0; i < _waypointGroups.getSize(); i++) { nodeState = state->getNodeState(_waypointGroups[i]->getName(), saving); if (nodeState) { - if (saving) nodeState->_active = _waypointGroups[i]->_active; - else _waypointGroups[i]->_active = nodeState->_active; + if (saving) { + nodeState->_active = _waypointGroups[i]->_active; + } else { + _waypointGroups[i]->_active = nodeState->_active; + } } } @@ -2544,14 +2769,17 @@ float AdScene::getRotationAt(int x, int y) { for (int i = 0; i < _rotLevels.getSize(); i++) { /* AdRotLevel *xxx = _rotLevels[i]; int j = _rotLevels.getSize();*/ - if (_rotLevels[i]->_posX < x) prev = _rotLevels[i]; - else { + if (_rotLevels[i]->_posX < x) { + prev = _rotLevels[i]; + } else { next = _rotLevels[i]; break; } } - if (prev == NULL || next == NULL) return 0; + if (prev == NULL || next == NULL) { + return 0; + } int delta_x = next->_posX - prev->_posX; float delta_rot = next->_rotation - prev->_rotation; @@ -2570,7 +2798,9 @@ bool AdScene::handleItemAssociations(const char *itemName, bool show) { if (layer->_nodes[j]->_type == OBJECT_ENTITY) { AdEntity *ent = layer->_nodes[j]->_entity; - if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + if (ent->_item && strcmp(ent->_item, itemName) == 0) { + ent->_active = show; + } } } } @@ -2578,7 +2808,9 @@ bool AdScene::handleItemAssociations(const char *itemName, bool show) { for (int i = 0; i < _objects.getSize(); i++) { if (_objects[i]->_type == OBJECT_ENTITY) { AdEntity *ent = (AdEntity *)_objects[i]; - if (ent->_item && strcmp(ent->_item, itemName) == 0) ent->_active = show; + if (ent->_item && strcmp(ent->_item, itemName) == 0) { + ent->_active = show; + } } } @@ -2596,7 +2828,9 @@ bool AdScene::getRegionsAt(int x, int y, AdRegion **regionList, int numRegions) if (numUsed < numRegions - 1) { regionList[numUsed] = node->_region; numUsed++; - } else break; + } else { + break; + } } } } @@ -2618,13 +2852,17 @@ BaseObject *AdScene::getNextAccessObject(BaseObject *currObject) { BaseArray objects; getSceneObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = 0; i < objects.getSize(); i++) { if (objects[i] == currObject) { - if (i < objects.getSize() - 1) return objects[i + 1]; - else break; + if (i < objects.getSize() - 1) { + return objects[i + 1]; + } else { + break; + } } } } @@ -2638,13 +2876,17 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { BaseArray objects; getSceneObjects(objects, true); - if (objects.getSize() == 0) return NULL; - else { + if (objects.getSize() == 0) { + return NULL; + } else { if (currObject != NULL) { for (int i = objects.getSize() - 1; i >= 0; i--) { if (objects[i] == currObject) { - if (i > 0) return objects[i - 1]; - else break; + if (i > 0) { + return objects[i - 1]; + } else { + break; + } } } } @@ -2658,7 +2900,9 @@ BaseObject *AdScene::getPrevAccessObject(BaseObject *currObject) { bool AdScene::getSceneObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _layers.getSize(); i++) { // close-up layer -> remove everything below it - if (interactiveOnly && _layers[i]->_closeUp) objects.removeAll(); + if (interactiveOnly && _layers[i]->_closeUp) { + objects.removeAll(); + } for (int j = 0; j < _layers[i]->_nodes.getSize(); j++) { @@ -2666,8 +2910,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i switch (node->_type) { case OBJECT_ENTITY: { AdEntity *ent = node->_entity; - if (ent->_active && (ent->_registrable || !interactiveOnly)) + if (ent->_active && (ent->_registrable || !interactiveOnly)) { objects.add(ent); + } } break; @@ -2682,7 +2927,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i break; } } - if (!found) objects.add(regionObj[newIndex]); + if (!found) { + objects.add(regionObj[newIndex]); + } } //if (RegionObj.getSize() > 0) Objects.Append(RegionObj); } @@ -2705,7 +2952,9 @@ bool AdScene::getSceneObjects(BaseArray &objects, bool i break; } } - if (!found) objects.add(regionObj[newIndex]); + if (!found) { + objects.add(regionObj[newIndex]); + } } @@ -2722,7 +2971,9 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray_objects.getSize(); i++) { obj = adGame->_objects[i]; if (obj->_active && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) continue; + if (interactiveOnly && !obj->_registrable) { + continue; + } objects.add(obj); } @@ -2732,7 +2983,9 @@ bool AdScene::getRegionObjects(AdRegion *region, BaseArray_active && !obj->_editorOnly && (obj->_stickRegion == region || region == NULL || (obj->_stickRegion == NULL && region->pointInRegion(obj->_posX, obj->_posY)))) { - if (interactiveOnly && !obj->_registrable) continue; + if (interactiveOnly && !obj->_registrable) { + continue; + } objects.add(obj); } diff --git a/engines/wintermute/ad/ad_scene_state.cpp b/engines/wintermute/ad/ad_scene_state.cpp index 617f247241..8a223150f2 100644 --- a/engines/wintermute/ad/ad_scene_state.cpp +++ b/engines/wintermute/ad/ad_scene_state.cpp @@ -47,7 +47,9 @@ AdSceneState::~AdSceneState() { delete[] _filename; _filename = NULL; - for (int i = 0; i < _nodeStates.getSize(); i++) delete _nodeStates[i]; + for (int i = 0; i < _nodeStates.getSize(); i++) { + delete _nodeStates[i]; + } _nodeStates.removeAll(); } @@ -65,14 +67,18 @@ bool AdSceneState::persist(BasePersistenceManager *persistMgr) { void AdSceneState::setFilename(const char *filename) { delete[] _filename; _filename = new char [strlen(filename) + 1]; - if (_filename) strcpy(_filename, filename); + if (_filename) { + strcpy(_filename, filename); + } } ////////////////////////////////////////////////////////////////////////// AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { for (int i = 0; i < _nodeStates.getSize(); i++) { - if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) return _nodeStates[i]; + if (scumm_stricmp(_nodeStates[i]->_name, name) == 0) { + return _nodeStates[i]; + } } if (saving) { @@ -81,7 +87,9 @@ AdNodeState *AdSceneState::getNodeState(const char *name, bool saving) { _nodeStates.add(ret); return ret; - } else return NULL; + } else { + return NULL; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_sentence.cpp b/engines/wintermute/ad/ad_sentence.cpp index a011db3f02..d429c1fedf 100644 --- a/engines/wintermute/ad/ad_sentence.cpp +++ b/engines/wintermute/ad/ad_sentence.cpp @@ -91,19 +91,29 @@ AdSentence::~AdSentence() { ////////////////////////////////////////////////////////////////////////// void AdSentence::setText(const char *text) { - if (_text) delete[] _text; + if (_text) { + delete[] _text; + } _text = new char[strlen(text) + 1]; - if (_text) strcpy(_text, text); + if (_text) { + strcpy(_text, text); + } } ////////////////////////////////////////////////////////////////////////// void AdSentence::setStances(const char *stances) { - if (_stances) delete[] _stances; + if (_stances) { + delete[] _stances; + } if (stances) { _stances = new char[strlen(stances) + 1]; - if (_stances) strcpy(_stances, stances); - } else _stances = NULL; + if (_stances) { + strcpy(_stances, stances); + } + } else { + _stances = NULL; + } } @@ -122,36 +132,55 @@ char *AdSentence::getNextStance() { ////////////////////////////////////////////////////////////////////////// char *AdSentence::getStance(int stance) { - if (_stances == NULL) return NULL; + if (_stances == NULL) { + return NULL; + } - if (_tempStance) delete[] _tempStance; + if (_tempStance) { + delete[] _tempStance; + } _tempStance = NULL; char *start; char *curr; int pos; - if (stance == 0) start = _stances; - else { + if (stance == 0) { + start = _stances; + } else { pos = 0; start = NULL; curr = _stances; while (pos < stance) { - if (*curr == '\0') break; - if (*curr == ',') pos++; + if (*curr == '\0') { + break; + } + if (*curr == ',') { + pos++; + } curr++; } - if (pos == stance) start = curr; + if (pos == stance) { + start = curr; + } } - if (start == NULL) return NULL; + if (start == NULL) { + return NULL; + } - while (*start == ' ' && *start != ',' && *start != '\0') start++; + while (*start == ' ' && *start != ',' && *start != '\0') { + start++; + } curr = start; - while (*curr != '\0' && *curr != ',') curr++; + while (*curr != '\0' && *curr != ',') { + curr++; + } - while (curr > start && *(curr - 1) == ' ') curr--; + while (curr > start && *(curr - 1) == ' ') { + curr--; + } _tempStance = new char [curr - start + 1]; if (_tempStance) { @@ -165,7 +194,9 @@ char *AdSentence::getStance(int stance) { ////////////////////////////////////////////////////////////////////////// bool AdSentence::display() { - if (!_font || !_text) return STATUS_FAILED; + if (!_font || !_text) { + return STATUS_FAILED; + } if (_sound && !_soundStarted) { _sound->play(); @@ -195,7 +226,9 @@ bool AdSentence::display() { ////////////////////////////////////////////////////////////////////////// void AdSentence::setSound(BaseSound *sound) { - if (!sound) return; + if (!sound) { + return; + } delete _sound; _sound = sound; _soundStarted = false; @@ -204,7 +237,9 @@ void AdSentence::setSound(BaseSound *sound) { ////////////////////////////////////////////////////////////////////////// bool AdSentence::finish() { - if (_sound) _sound->stop(); + if (_sound) { + _sound->stop(); + } return STATUS_OK; } @@ -242,7 +277,9 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { _talkDef = NULL; _currentSprite = NULL; - if (!soundFilename) return STATUS_OK; + if (!soundFilename) { + return STATUS_OK; + } AnsiString path = PathUtil::getDirectoryName(soundFilename); @@ -250,8 +287,9 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { AnsiString talkDefFileName = PathUtil::combine(path, name + ".talk"); - if (!_gameRef->_fileManager->hasFile(talkDefFileName)) - return STATUS_OK; // no talk def file found + if (!_gameRef->_fileManager->hasFile(talkDefFileName)) { + return STATUS_OK; // no talk def file found + } _talkDef = new AdTalkDef(_gameRef); if (!_talkDef || DID_FAIL(_talkDef->loadFile(talkDefFileName.c_str()))) { @@ -267,7 +305,9 @@ bool AdSentence::setupTalkFile(const char *soundFilename) { ////////////////////////////////////////////////////////////////////////// bool AdSentence::update(TDirection dir) { - if (!_talkDef) return STATUS_OK; + if (!_talkDef) { + return STATUS_OK; + } uint32 currentTime; // if sound is available, synchronize with sound, otherwise use timer @@ -284,10 +324,14 @@ bool AdSentence::update(TDirection dir) { talkNodeFound = true; BaseSprite *newSprite = _talkDef->_nodes[i]->getSprite(dir); - if (newSprite != _currentSprite) newSprite->reset(); + if (newSprite != _currentSprite) { + newSprite->reset(); + } _currentSprite = newSprite; - if (!_talkDef->_nodes[i]->_playToEnd) break; + if (!_talkDef->_nodes[i]->_playToEnd) { + break; + } } } @@ -296,9 +340,13 @@ bool AdSentence::update(TDirection dir) { if (!talkNodeFound) { BaseSprite *newSprite = _talkDef->getDefaultSprite(dir); if (newSprite) { - if (newSprite != _currentSprite) newSprite->reset(); + if (newSprite != _currentSprite) { + newSprite->reset(); + } _currentSprite = newSprite; - } else _currentSprite = NULL; + } else { + _currentSprite = NULL; + } } return STATUS_OK; diff --git a/engines/wintermute/ad/ad_sprite_set.cpp b/engines/wintermute/ad/ad_sprite_set.cpp index fcbf9af4eb..42409988a5 100644 --- a/engines/wintermute/ad/ad_sprite_set.cpp +++ b/engines/wintermute/ad/ad_sprite_set.cpp @@ -41,8 +41,9 @@ IMPLEMENT_PERSISTENT(AdSpriteSet, false) AdSpriteSet::AdSpriteSet(BaseGame *inGame, BaseObject *owner): BaseObject(inGame) { _owner = owner; - for (int i = 0; i < NUM_DIRECTIONS; i++) + for (int i = 0; i < NUM_DIRECTIONS; i++) { _sprites[i] = NULL; + } } @@ -67,7 +68,9 @@ bool AdSpriteSet::loadFile(const char *filename, int lifeTime, TSpriteCacheType bool ret; - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing SPRITESET file '%s'", filename); + } delete[] buffer; @@ -90,7 +93,7 @@ TOKEN_DEF(TEMPLATE) TOKEN_DEF(EDITOR_PROPERTY) TOKEN_DEF_END ////////////////////////////////////////////////////////////////////////// -bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType CacheType) { +bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCacheType cacheType) { TOKEN_TABLE_START(commands) TOKEN_TABLE(SPRITESET) TOKEN_TABLE(NAME) @@ -122,7 +125,9 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -133,64 +138,88 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC delete _sprites[DI_LEFT]; _sprites[DI_LEFT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_LEFT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_LEFT] = spr; + } break; case TOKEN_RIGHT: delete _sprites[DI_RIGHT]; _sprites[DI_RIGHT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_RIGHT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_RIGHT] = spr; + } break; case TOKEN_UP: delete _sprites[DI_UP]; _sprites[DI_UP] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UP] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UP] = spr; + } break; case TOKEN_DOWN: delete _sprites[DI_DOWN]; _sprites[DI_DOWN] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWN] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWN] = spr; + } break; case TOKEN_UP_LEFT: delete _sprites[DI_UPLEFT]; _sprites[DI_UPLEFT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UPLEFT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UPLEFT] = spr; + } break; case TOKEN_UP_RIGHT: delete _sprites[DI_UPRIGHT]; _sprites[DI_UPRIGHT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_UPRIGHT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_UPRIGHT] = spr; + } break; case TOKEN_DOWN_LEFT: delete _sprites[DI_DOWNLEFT]; _sprites[DI_DOWNLEFT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWNLEFT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWNLEFT] = spr; + } break; case TOKEN_DOWN_RIGHT: delete _sprites[DI_DOWNRIGHT]; _sprites[DI_DOWNRIGHT] = NULL; spr = new BaseSprite(_gameRef, _owner); - if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, CacheType))) cmd = PARSERR_GENERIC; - else _sprites[DI_DOWNRIGHT] = spr; + if (!spr || DID_FAIL(spr->loadFile((char *)params, lifeTime, cacheType))) { + cmd = PARSERR_GENERIC; + } else { + _sprites[DI_DOWNRIGHT] = spr; + } break; case TOKEN_EDITOR_PROPERTY: @@ -205,7 +234,9 @@ bool AdSpriteSet::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteC if (cmd == PARSERR_GENERIC) { _gameRef->LOG(0, "Error loading SPRITESET definition"); - if (spr) delete spr; + if (spr) { + delete spr; + } return STATUS_FAILED; } @@ -230,8 +261,12 @@ bool AdSpriteSet::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// BaseSprite *AdSpriteSet::getSprite(TDirection direction) { int dir = (int)direction; - if (dir < 0) dir = 0; - if (dir >= NUM_DIRECTIONS) dir = NUM_DIRECTIONS - 1; + if (dir < 0) { + dir = 0; + } + if (dir >= NUM_DIRECTIONS) { + dir = NUM_DIRECTIONS - 1; + } BaseSprite *ret = NULL; @@ -247,8 +282,11 @@ BaseSprite *AdSpriteSet::getSprite(TDirection direction) { for (int i = dir; i < NUM_DIRECTIONS; i++) { if (_sprites[i] != NULL) { - if (ret == NULL || numSteps > i - dir) return _sprites[i]; - else return ret; + if (ret == NULL || numSteps > i - dir) { + return _sprites[i]; + } else { + return ret; + } } } @@ -260,7 +298,9 @@ BaseSprite *AdSpriteSet::getSprite(TDirection direction) { ////////////////////////////////////////////////////////////////////////// bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "SPRITESET {\n"); - if (getName()) buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + if (getName()) { + buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); + } for (int i = 0; i < NUM_DIRECTIONS; i++) { if (_sprites[i]) { switch (i) { @@ -301,10 +341,14 @@ bool AdSpriteSet::saveAsText(BaseDynamicBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// bool AdSpriteSet::containsSprite(BaseSprite *sprite) { - if (!sprite) return false; + if (!sprite) { + return false; + } for (int i = 0; i < NUM_DIRECTIONS; i++) { - if (_sprites[i] == sprite) return true; + if (_sprites[i] == sprite) { + return true; + } } return false; } diff --git a/engines/wintermute/ad/ad_talk_def.cpp b/engines/wintermute/ad/ad_talk_def.cpp index 2b0c6c6c1b..fc057ba183 100644 --- a/engines/wintermute/ad/ad_talk_def.cpp +++ b/engines/wintermute/ad/ad_talk_def.cpp @@ -52,7 +52,9 @@ AdTalkDef::AdTalkDef(BaseGame *inGame): BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// AdTalkDef::~AdTalkDef() { - for (int i = 0; i < _nodes.getSize(); i++) delete _nodes[i]; + for (int i = 0; i < _nodes.getSize(); i++) { + delete _nodes[i]; + } _nodes.removeAll(); delete[] _defaultSpriteFilename; @@ -79,7 +81,9 @@ bool AdTalkDef::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing TALK file '%s'", filename); + } delete[] buffer; @@ -123,15 +127,18 @@ bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_ACTION: { - AdTalkNode *Node = new AdTalkNode(_gameRef); - if (Node && DID_SUCCEED(Node->loadBuffer(params, false))) _nodes.add(Node); - else { - delete Node; - Node = NULL; + AdTalkNode *node = new AdTalkNode(_gameRef); + if (node && DID_SUCCEED(node->loadBuffer(params, false))) { + _nodes.add(node); + } else { + delete node; + node = NULL; cmd = PARSERR_GENERIC; } } @@ -179,12 +186,16 @@ bool AdTalkDef::loadBuffer(byte *buffer, bool complete) { if (_defaultSpriteFilename) { _defaultSprite = new BaseSprite(_gameRef); - if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) return STATUS_FAILED; + if (!_defaultSprite || DID_FAIL(_defaultSprite->loadFile(_defaultSpriteFilename))) { + return STATUS_FAILED; + } } if (_defaultSpriteSetFilename) { _defaultSpriteSet = new AdSpriteSet(_gameRef); - if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) return STATUS_FAILED; + if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { + return STATUS_FAILED; + } } @@ -211,10 +222,15 @@ bool AdTalkDef::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdTalkDef::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "TALK {\n"); - if (_defaultSpriteFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + if (_defaultSpriteFilename) { + buffer->putTextIndent(indent + 2, "DEFAULT_SPRITE=\"%s\"\n", _defaultSpriteFilename); + } - if (_defaultSpriteSetFilename) buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); - else if (_defaultSpriteSet) _defaultSpriteSet->saveAsText(buffer, indent + 2); + if (_defaultSpriteSetFilename) { + buffer->putTextIndent(indent + 2, "DEFAULT_SPRITESET_FILE=\"%s\"\n", _defaultSpriteSetFilename); + } else if (_defaultSpriteSet) { + _defaultSpriteSet->saveAsText(buffer, indent + 2); + } for (int i = 0; i < _nodes.getSize(); i++) { _nodes[i]->saveAsText(buffer, indent + 2); @@ -236,24 +252,34 @@ bool AdTalkDef::loadDefaultSprite() { delete _defaultSprite; _defaultSprite = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } } else if (_defaultSpriteSetFilename && !_defaultSpriteSet) { _defaultSpriteSet = new AdSpriteSet(_gameRef); if (!_defaultSpriteSet || DID_FAIL(_defaultSpriteSet->loadFile(_defaultSpriteSetFilename))) { delete _defaultSpriteSet; _defaultSpriteSet = NULL; return STATUS_FAILED; - } else return STATUS_OK; - } else return STATUS_OK; + } else { + return STATUS_OK; + } + } else { + return STATUS_OK; + } } ////////////////////////////////////////////////////////////////////////// BaseSprite *AdTalkDef::getDefaultSprite(TDirection dir) { loadDefaultSprite(); - if (_defaultSprite) return _defaultSprite; - else if (_defaultSpriteSet) return _defaultSpriteSet->getSprite(dir); - else return NULL; + if (_defaultSprite) { + return _defaultSprite; + } else if (_defaultSpriteSet) { + return _defaultSpriteSet->getSprite(dir); + } else { + return NULL; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_talk_holder.cpp b/engines/wintermute/ad/ad_talk_holder.cpp index d47cbb446e..90435d7977 100644 --- a/engines/wintermute/ad/ad_talk_holder.cpp +++ b/engines/wintermute/ad/ad_talk_holder.cpp @@ -52,12 +52,14 @@ AdTalkHolder::~AdTalkHolder() { delete _sprite; _sprite = NULL; - for (int i = 0; i < _talkSprites.getSize(); i++) + for (int i = 0; i < _talkSprites.getSize(); i++) { delete _talkSprites[i]; + } _talkSprites.removeAll(); - for (int i = 0; i < _talkSpritesEx.getSize(); i++) + for (int i = 0; i < _talkSpritesEx.getSize(); i++) { delete _talkSpritesEx[i]; + } _talkSpritesEx.removeAll(); } @@ -77,7 +79,9 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { _gameRef->LOG(res, "AdTalkHolder::GetTalkStance: error loading talk sprite (object:\"%s\" sprite:\"%s\")", getName(), _forcedTalkAnimName); delete _animSprite; _animSprite = NULL; - } else return _animSprite; + } else { + return _animSprite; + } } } @@ -103,8 +107,9 @@ BaseSprite *AdTalkHolder::getTalkStance(const char *stance) { // not a valid stance? get a random one if (ret == NULL) { - if (_talkSprites.getSize() < 1) ret = _sprite; - else { + if (_talkSprites.getSize() < 1) { + ret = _sprite; + } else { // TODO: remember last int rnd = g_wintermute->randInt(0, _talkSprites.getSize() - 1); ret = _talkSprites[rnd]; @@ -128,14 +133,18 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS ScValue *val = stack->pop(); bool setCurrent = false; - if (_currentSprite && _currentSprite == _sprite) setCurrent = true; + if (_currentSprite && _currentSprite == _sprite) { + setCurrent = true; + } delete _sprite; _sprite = NULL; if (val->isNULL()) { _sprite = NULL; - if (setCurrent) _currentSprite = NULL; + if (setCurrent) { + _currentSprite = NULL; + } stack->pushBool(true); } else { const char *filename = val->getString(); @@ -145,7 +154,9 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS stack->pushBool(false); } else { _sprite = spr; - if (setCurrent) _currentSprite = _sprite; + if (setCurrent) { + _currentSprite = _sprite; + } stack->pushBool(true); } } @@ -158,8 +169,11 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS else if (strcmp(name, "GetSprite") == 0) { stack->correctParams(0); - if (!_sprite || !_sprite->getFilename()) stack->pushNULL(); - else stack->pushString(_sprite->getFilename()); + if (!_sprite || !_sprite->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_sprite->getFilename()); + } return STATUS_OK; } @@ -169,8 +183,11 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS else if (strcmp(name, "GetSpriteObject") == 0) { stack->correctParams(0); - if (!_sprite) stack->pushNULL(); - else stack->pushNative(_sprite, true); + if (!_sprite) { + stack->pushNULL(); + } else { + stack->pushNative(_sprite, true); + } return STATUS_OK; } @@ -181,15 +198,18 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS stack->correctParams(2); const char *filename = stack->pop()->getString(); - bool Ex = stack->pop()->getBool(); + bool ex = stack->pop()->getBool(); BaseSprite *spr = new BaseSprite(_gameRef, this); if (!spr || DID_FAIL(spr->loadFile(filename))) { stack->pushBool(false); script->runtimeError("AddTalkSprite method failed for file '%s'", filename); } else { - if (Ex) _talkSpritesEx.add(spr); - else _talkSprites.add(spr); + if (ex) { + _talkSpritesEx.add(spr); + } else { + _talkSprites.add(spr); + } stack->pushBool(true); } return STATUS_OK; @@ -210,10 +230,12 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS if (ex) { for (int i = 0; i < _talkSpritesEx.getSize(); i++) { if (scumm_stricmp(_talkSpritesEx[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSpritesEx[i]) + if (_currentSprite == _talkSpritesEx[i]) { setCurrent = true; - if (_tempSprite2 == _talkSpritesEx[i]) + } + if (_tempSprite2 == _talkSpritesEx[i]) { setTemp2 = true; + } delete _talkSpritesEx[i]; _talkSpritesEx.removeAt(i); break; @@ -222,10 +244,12 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } else { for (int i = 0; i < _talkSprites.getSize(); i++) { if (scumm_stricmp(_talkSprites[i]->getFilename(), filename) == 0) { - if (_currentSprite == _talkSprites[i]) + if (_currentSprite == _talkSprites[i]) { setCurrent = true; - if (_tempSprite2 == _talkSprites[i]) + } + if (_tempSprite2 == _talkSprites[i]) { setTemp2 = true; + } delete _talkSprites[i]; _talkSprites.removeAt(i); break; @@ -235,10 +259,12 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS } stack->pushBool(true); - if (setCurrent) + if (setCurrent) { _currentSprite = _sprite; - if (setTemp2) + } + if (setTemp2) { _tempSprite2 = _sprite; + } return STATUS_OK; } @@ -263,38 +289,47 @@ bool AdTalkHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS // delete current if (ex) { for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i] == _currentSprite) + if (_talkSpritesEx[i] == _currentSprite) { setCurrent = true; - if (_talkSpritesEx[i] == _tempSprite2) + } + if (_talkSpritesEx[i] == _tempSprite2) { setTemp2 = true; + } delete _talkSpritesEx[i]; } _talkSpritesEx.removeAll(); } else { for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i] == _currentSprite) setCurrent = true; - if (_talkSprites[i] == _tempSprite2) setTemp2 = true; + if (_talkSprites[i] == _currentSprite) { + setCurrent = true; + } + if (_talkSprites[i] == _tempSprite2) { + setTemp2 = true; + } delete _talkSprites[i]; } _talkSprites.removeAll(); } // set new - if (ex) + if (ex) { _talkSpritesEx.add(spr); - else + } else { _talkSprites.add(spr); + } stack->pushBool(true); - if (setCurrent) + if (setCurrent) { _currentSprite = spr; - if (setTemp2) + } + if (setTemp2) { _tempSprite2 = spr; + } } return STATUS_OK; + } else { + return AdObject::scCallMethod(script, stack, thisStack, name); } - - else return AdObject::scCallMethod(script, stack, thisStack, name); } @@ -308,9 +343,9 @@ ScValue *AdTalkHolder::scGetProperty(const char *name) { if (strcmp(name, "Type") == 0) { _scValue->setString("talk-holder"); return _scValue; + } else { + return AdObject::scGetProperty(name); } - - else return AdObject::scGetProperty(name); } @@ -338,13 +373,15 @@ const char *AdTalkHolder::scToString() { ////////////////////////////////////////////////////////////////////////// bool AdTalkHolder::saveAsText(BaseDynamicBuffer *buffer, int indent) { for (int i = 0; i < _talkSprites.getSize(); i++) { - if (_talkSprites[i]->getFilename()) + if (_talkSprites[i]->getFilename()) { buffer->putTextIndent(indent + 2, "TALK=\"%s\"\n", _talkSprites[i]->getFilename()); + } } for (int i = 0; i < _talkSpritesEx.getSize(); i++) { - if (_talkSpritesEx[i]->getFilename()) + if (_talkSpritesEx[i]->getFilename()) { buffer->putTextIndent(indent + 2, "TALK_SPECIAL=\"%s\"\n", _talkSpritesEx[i]->getFilename()); + } } return STATUS_OK; diff --git a/engines/wintermute/ad/ad_talk_node.cpp b/engines/wintermute/ad/ad_talk_node.cpp index 306825c439..ef30290b8c 100644 --- a/engines/wintermute/ad/ad_talk_node.cpp +++ b/engines/wintermute/ad/ad_talk_node.cpp @@ -142,7 +142,9 @@ bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_COMMENT: - if (_gameRef->_editorMode) BaseUtils::setString(&_comment, (char *)params); + if (_gameRef->_editorMode) { + BaseUtils::setString(&_comment, (char *)params); + } break; case TOKEN_EDITOR_PROPERTY: @@ -160,23 +162,26 @@ bool AdTalkNode::loadBuffer(byte *buffer, bool complete) { return STATUS_FAILED; } - if (_endTime == 0) + if (_endTime == 0) { _playToEnd = true; - else + } else { _playToEnd = false; + } if (_preCache && _spriteFilename) { delete _sprite; _sprite = new BaseSprite(_gameRef); - if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) + if (!_sprite || DID_FAIL(_sprite->loadFile(_spriteFilename))) { return STATUS_FAILED; + } } if (_preCache && _spriteSetFilename) { delete _spriteSet; _spriteSet = new AdSpriteSet(_gameRef); - if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) + if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { return STATUS_FAILED; + } } return STATUS_OK; @@ -202,13 +207,24 @@ bool AdTalkNode::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool AdTalkNode::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "ACTION {\n"); - if (_comment) buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + if (_comment) { + buffer->putTextIndent(indent + 2, "COMMENT=\"%s\"\n", _comment); + } buffer->putTextIndent(indent + 2, "START_TIME=%d\n", _startTime); - if (!_playToEnd) buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); - if (_spriteFilename) buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); - if (_spriteSetFilename) buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); - else if (_spriteSet) _spriteSet->saveAsText(buffer, indent + 2); - if (_preCache) buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + if (!_playToEnd) { + buffer->putTextIndent(indent + 2, "END_TIME=%d\n", _endTime); + } + if (_spriteFilename) { + buffer->putTextIndent(indent + 2, "SPRITE=\"%s\"\n", _spriteFilename); + } + if (_spriteSetFilename) { + buffer->putTextIndent(indent + 2, "SPRITESET_FILE=\"%s\"\n", _spriteSetFilename); + } else if (_spriteSet) { + _spriteSet->saveAsText(buffer, indent + 2); + } + if (_preCache) { + buffer->putTextIndent(indent + 2, "PRECACHE=\"%s\"\n", _preCache ? "TRUE" : "FALSE"); + } BaseClass::saveAsText(buffer, indent + 2); @@ -226,19 +242,21 @@ bool AdTalkNode::loadSprite() { delete _sprite; _sprite = NULL; return STATUS_FAILED; - } else return STATUS_OK; - } - - else if (_spriteSetFilename && !_spriteSet) { + } else { + return STATUS_OK; + } + } else if (_spriteSetFilename && !_spriteSet) { _spriteSet = new AdSpriteSet(_gameRef); if (!_spriteSet || DID_FAIL(_spriteSet->loadFile(_spriteSetFilename))) { delete _spriteSet; _spriteSet = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } + } else { + return STATUS_OK; } - - else return STATUS_OK; } @@ -246,20 +264,32 @@ bool AdTalkNode::loadSprite() { bool AdTalkNode::isInTimeInterval(uint32 time, TDirection dir) { if (time >= _startTime) { if (_playToEnd) { - if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) return true; - else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) return true; - else return false; - } else return _endTime >= time; - } else return false; + if ((_spriteFilename && _sprite == NULL) || (_sprite && _sprite->_finished == false)) { + return true; + } else if ((_spriteSetFilename && _spriteSet == NULL) || (_spriteSet && _spriteSet->getSprite(dir) && _spriteSet->getSprite(dir)->_finished == false)) { + return true; + } else { + return false; + } + } else { + return _endTime >= time; + } + } else { + return false; + } } ////////////////////////////////////////////////////////////////////////// BaseSprite *AdTalkNode::getSprite(TDirection dir) { loadSprite(); - if (_sprite) return _sprite; - else if (_spriteSet) return _spriteSet->getSprite(dir); - else return NULL; + if (_sprite) { + return _sprite; + } else if (_spriteSet) { + return _spriteSet->getSprite(dir); + } else { + return NULL; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ad/ad_waypoint_group.cpp b/engines/wintermute/ad/ad_waypoint_group.cpp index 7e5d8d29c6..bb1e9275f5 100644 --- a/engines/wintermute/ad/ad_waypoint_group.cpp +++ b/engines/wintermute/ad/ad_waypoint_group.cpp @@ -56,8 +56,9 @@ AdWaypointGroup::~AdWaypointGroup() { ////////////////////////////////////////////////////////////////////////// void AdWaypointGroup::cleanup() { - for (int i = 0; i < _points.getSize(); i++) + for (int i = 0; i < _points.getSize(); i++) { delete _points[i]; + } _points.removeAll(); _editorSelectedPoint = -1; } @@ -75,7 +76,9 @@ bool AdWaypointGroup::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing WAYPOINTS file '%s'", filename); + } delete[] buffer; @@ -122,7 +125,9 @@ bool AdWaypointGroup::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -169,8 +174,9 @@ bool AdWaypointGroup::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "EDITOR_SELECTED_POINT=%d\n", _editorSelectedPoint); - if (_scProp) + if (_scProp) { _scProp->saveAsText(buffer, indent + 2); + } BaseClass::saveAsText(buffer, indent + 2); for (int i = 0; i < _points.getSize(); i++) { @@ -217,9 +223,9 @@ ScValue *AdWaypointGroup::scGetProperty(const char *name) { else if (strcmp(name, "Active") == 0) { _scValue->setBool(_active); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -233,13 +239,17 @@ bool AdWaypointGroup::scSetProperty(const char *name, ScValue *value) { return STATUS_OK; } - else return BaseObject::scSetProperty(name, value); + else { + return BaseObject::scSetProperty(name, value); + } } ////////////////////////////////////////////////////////////////////////// bool AdWaypointGroup::mimic(AdWaypointGroup *wpt, float scale, int argX, int argY) { - if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) return STATUS_OK; + if (scale == _lastMimicScale && argX == _lastMimicX && argY == _lastMimicY) { + return STATUS_OK; + } cleanup(); diff --git a/engines/wintermute/base/base.cpp b/engines/wintermute/base/base.cpp index b81261cdaf..687d2d52e6 100644 --- a/engines/wintermute/base/base.cpp +++ b/engines/wintermute/base/base.cpp @@ -56,16 +56,19 @@ BaseClass::~BaseClass() { ////////////////////////////////////////////////////////////////////////// const char *BaseClass::getEditorProp(const char *propName, const char *initVal) { _editorPropsIter = _editorProps.find(propName); - if (_editorPropsIter != _editorProps.end()) + if (_editorPropsIter != _editorProps.end()) { return _editorPropsIter->_value.c_str(); - //return _editorPropsIter->second.c_str(); // <- TODO Clean - else return initVal; + } else { + return initVal; + } } ////////////////////////////////////////////////////////////////////////// bool BaseClass::setEditorProp(const char *propName, const char *propValue) { - if (propName == NULL) return STATUS_FAILED; + if (propName == NULL) { + return STATUS_FAILED; + } if (propValue == NULL) { _editorProps.erase(propName); @@ -91,8 +94,9 @@ bool BaseClass::parseEditorProperty(byte *buffer, bool complete) { TOKEN_TABLE_END - if (!_gameRef->_editorMode) + if (!_gameRef->_editorMode) { return STATUS_OK; + } byte *params; @@ -115,15 +119,21 @@ bool BaseClass::parseEditorProperty(byte *buffer, bool complete) { case TOKEN_NAME: delete[] propName; propName = new char[strlen((char *)params) + 1]; - if (propName) strcpy(propName, (char *)params); - else cmd = PARSERR_GENERIC; + if (propName) { + strcpy(propName, (char *)params); + } else { + cmd = PARSERR_GENERIC; + } break; case TOKEN_VALUE: delete[] propValue; propValue = new char[strlen((char *)params) + 1]; - if (propValue) strcpy(propValue, (char *)params); - else cmd = PARSERR_GENERIC; + if (propValue) { + strcpy(propValue, (char *)params); + } else { + cmd = PARSERR_GENERIC; + } break; } diff --git a/engines/wintermute/base/base_active_rect.cpp b/engines/wintermute/base/base_active_rect.cpp index 0283ee274e..0756d10698 100644 --- a/engines/wintermute/base/base_active_rect.cpp +++ b/engines/wintermute/base/base_active_rect.cpp @@ -97,8 +97,12 @@ void BaseActiveRect::clipRect() { rc.bottom -= Rend->_drawOffsetY; } - if (rc.left > _rect.left) _offsetX = rc.left - _rect.left; - if (rc.top > _rect.top) _offsetY = rc.top - _rect.top; + if (rc.left > _rect.left) { + _offsetX = rc.left - _rect.left; + } + if (rc.top > _rect.top) { + _offsetY = rc.top - _rect.top; + } BasePlatform::intersectRect(&_rect, &_rect, &rc); } diff --git a/engines/wintermute/base/base_dynamic_buffer.cpp b/engines/wintermute/base/base_dynamic_buffer.cpp index 8d6f88c9fe..a61227b0dc 100644 --- a/engines/wintermute/base/base_dynamic_buffer.cpp +++ b/engines/wintermute/base/base_dynamic_buffer.cpp @@ -53,7 +53,9 @@ BaseDynamicBuffer::~BaseDynamicBuffer() { ////////////////////////////////////////////////////////////////////////// void BaseDynamicBuffer::cleanup() { - if (_buffer) free(_buffer); + if (_buffer) { + free(_buffer); + } _buffer = NULL; _size = 0; _realSize = 0; @@ -72,7 +74,9 @@ uint32 BaseDynamicBuffer::getSize() { bool BaseDynamicBuffer::init(uint32 initSize) { cleanup(); - if (initSize == 0) initSize = _initSize; + if (initSize == 0) { + initSize = _initSize; + } _buffer = (byte *)malloc(initSize); if (!_buffer) { @@ -89,7 +93,9 @@ bool BaseDynamicBuffer::init(uint32 initSize) { ////////////////////////////////////////////////////////////////////////// bool BaseDynamicBuffer::putBytes(byte *buffer, uint32 size) { - if (!_initialized) init(); + if (!_initialized) { + init(); + } while (_offset + size > _realSize) { _realSize += _growBy; @@ -110,7 +116,9 @@ bool BaseDynamicBuffer::putBytes(byte *buffer, uint32 size) { ////////////////////////////////////////////////////////////////////////// bool BaseDynamicBuffer::getBytes(byte *buffer, uint32 size) { - if (!_initialized) init(); + if (!_initialized) { + init(); + } if (_offset + size > _size) { _gameRef->LOG(0, "BaseDynamicBuffer::GetBytes - Buffer underflow"); @@ -140,8 +148,9 @@ uint32 BaseDynamicBuffer::getDWORD() { ////////////////////////////////////////////////////////////////////////// void BaseDynamicBuffer::putString(const char *val) { - if (!val) putString("(null)"); - else { + if (!val) { + putString("(null)"); + } else { putDWORD(strlen(val) + 1); putBytes((byte *)val, strlen(val) + 1); } @@ -154,8 +163,11 @@ char *BaseDynamicBuffer::getString() { char *ret = (char *)(_buffer + _offset); _offset += len; - if (!strcmp(ret, "(null)")) return NULL; - else return ret; + if (!strcmp(ret, "(null)")) { + return NULL; + } else { + return ret; + } } diff --git a/engines/wintermute/base/base_fader.cpp b/engines/wintermute/base/base_fader.cpp index 10818abfb9..04fde5457c 100644 --- a/engines/wintermute/base/base_fader.cpp +++ b/engines/wintermute/base/base_fader.cpp @@ -59,23 +59,31 @@ BaseFader::~BaseFader() { ////////////////////////////////////////////////////////////////////////// bool BaseFader::update() { - if (!_active) return STATUS_OK; + if (!_active) { + return STATUS_OK; + } int alphaDelta = _targetAlpha - _sourceAlpha; uint32 time; - if (_system) time = g_system->getMillis() - _startTime; - else time = _gameRef->_timer - _startTime; + if (_system) { + time = g_system->getMillis() - _startTime; + } else { + time = _gameRef->_timer - _startTime; + } - if (time >= _duration) _currentAlpha = _targetAlpha; - else { + if (time >= _duration) { + _currentAlpha = _targetAlpha; + } else { _currentAlpha = (byte)(_sourceAlpha + (float)time / (float)_duration * alphaDelta); } _currentAlpha = MIN((unsigned char)255, MAX(_currentAlpha, (byte)0)); // TODO: clean _ready = time >= _duration; - if (_ready && _currentAlpha == 0x00) _active = false; + if (_ready && _currentAlpha == 0x00) { + _active = false; + } return STATUS_OK; } @@ -83,10 +91,13 @@ bool BaseFader::update() { ////////////////////////////////////////////////////////////////////////// bool BaseFader::display() { - if (!_active) return STATUS_OK; + if (!_active) { + return STATUS_OK; + } - if (_currentAlpha > 0x00) + if (_currentAlpha > 0x00) { _gameRef->_renderer->fadeToColor(_red, _green, _blue, _currentAlpha); + } return STATUS_OK; } @@ -114,8 +125,11 @@ bool BaseFader::fadeIn(uint32 sourceColor, uint32 duration, bool system) { _duration = duration; _system = system; - if (_system) _startTime = g_system->getMillis(); - else _startTime = _gameRef->_timer; + if (_system) { + _startTime = g_system->getMillis(); + } else { + _startTime = _gameRef->_timer; + } return STATUS_OK; } @@ -137,8 +151,11 @@ bool BaseFader::fadeOut(uint32 targetColor, uint32 duration, bool system) { _duration = duration; _system = system; - if (_system) _startTime = g_system->getMillis(); - else _startTime = _gameRef->_timer; + if (_system) { + _startTime = g_system->getMillis(); + } else { + _startTime = _gameRef->_timer; + } return STATUS_OK; @@ -167,7 +184,9 @@ bool BaseFader::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_targetAlpha)); persistMgr->transfer(TMEMBER(_system)); - if (_system && !persistMgr->getIsSaving()) _startTime = 0; + if (_system && !persistMgr->getIsSaving()) { + _startTime = 0; + } return STATUS_OK; } diff --git a/engines/wintermute/base/base_file_manager.cpp b/engines/wintermute/base/base_file_manager.cpp index c296f88699..ff693e055c 100644 --- a/engines/wintermute/base/base_file_manager.cpp +++ b/engines/wintermute/base/base_file_manager.cpp @@ -86,8 +86,9 @@ byte *BaseFileManager::readWholeFile(const Common::String &filename, uint32 *siz Common::SeekableReadStream *file = openFile(filename); if (!file) { - if (mustExist) + if (mustExist) { debugC(kWinterMuteDebugFileAccess | kWinterMuteDebugLog, "Error opening file '%s'", filename.c_str()); + } return NULL; } @@ -106,7 +107,9 @@ byte *BaseFileManager::readWholeFile(const Common::String &filename, uint32 *siz }; buffer[file->size()] = '\0'; - if (size != NULL) *size = file->size(); + if (size != NULL) { + *size = file->size(); + } closeFile(file); return buffer; @@ -114,8 +117,9 @@ byte *BaseFileManager::readWholeFile(const Common::String &filename, uint32 *siz ////////////////////////////////////////////////////////////////////////// bool BaseFileManager::addPath(TPathType type, const Common::FSNode &path) { - if (!path.exists()) + if (!path.exists()) { return STATUS_FAILED; + } switch (type) { case PATH_SINGLE: @@ -141,8 +145,9 @@ bool BaseFileManager::reloadPaths() { ////////////////////////////////////////////////////////////////////////// bool BaseFileManager::initPaths() { - if (!_gameRef) // This function only works when the game-registry is loaded + if (!_gameRef) { // This function only works when the game-registry is loaded return STATUS_FAILED; + } AnsiString pathList; @@ -210,15 +215,17 @@ bool BaseFileManager::registerPackages() { warning("Should register %s %s", (*it).getPath().c_str(), (*it).getName().c_str()); (*it).getChildren(files, Common::FSNode::kListFilesOnly); for (Common::FSList::iterator fileIt = files.begin(); fileIt != files.end(); fileIt++) { - if (!fileIt->getName().hasSuffix(".dcp")) + if (!fileIt->getName().hasSuffix(".dcp")) { continue; + } // Avoid registering all the language files // TODO: Select based on the gameDesc. if (fileIt->getParent().getName() == "language") { Common::String parentName = fileIt->getParent().getName(); Common::String dcpName = fileIt->getName(); - if (fileIt->getName() != "english.dcp") + if (fileIt->getName() != "english.dcp") { continue; + } } warning("Registering %s %s", (*fileIt).getPath().c_str(), (*fileIt).getName().c_str()); registerPackage((*fileIt)); @@ -247,8 +254,9 @@ Common::SeekableReadStream *BaseFileManager::openPkgFile(const Common::String &f // correct slashes for (int32 i = 0; i < upcName.size(); i++) { - if (upcName[i] == '/') + if (upcName[i] == '/') { upcName.setChar('\\', (uint32)i); + } } Common::ArchiveMemberPtr entry = _packages.getMember(upcName); file = entry->createReadStream(); @@ -256,23 +264,29 @@ Common::SeekableReadStream *BaseFileManager::openPkgFile(const Common::String &f } bool BaseFileManager::hasFile(const Common::String &filename) { - if (diskFileExists(filename)) + if (diskFileExists(filename)) { return true; - if (_packages.hasFile(filename)) - return true; // We don't bother checking if the file can actually be opened, something bigger is wrong if that is the case. - if (BaseResources::hasFile(filename)) + } + if (_packages.hasFile(filename)) { + return true; // We don't bother checking if the file can actually be opened, something bigger is wrong if that is the case. + } + if (BaseResources::hasFile(filename)) { return true; + } return false; } ////////////////////////////////////////////////////////////////////////// Common::SeekableReadStream *BaseFileManager::openFile(const Common::String &filename, bool absPathWarning, bool keepTrackOf) { - if (strcmp(filename.c_str(), "") == 0) + if (strcmp(filename.c_str(), "") == 0) { return NULL; + } debugC(kWinterMuteDebugFileAccess, "Open file %s", filename.c_str()); Common::SeekableReadStream *file = openFileRaw(filename); - if (file && keepTrackOf) _openFiles.push_back(file); + if (file && keepTrackOf) { + _openFiles.push_back(file); + } return file; } @@ -295,8 +309,9 @@ Common::SeekableReadStream *BaseFileManager::openFileRaw(const Common::String &f Common::SeekableReadStream *ret = NULL; if (scumm_strnicmp(filename.c_str(), "savegame:", 9) == 0) { - if (!_gameRef) + if (!_gameRef) { error("Attempt to load filename: %s without BaseGame-object, this is unsupported", filename.c_str()); + } BaseSaveThumbFile *SaveThumbFile = new BaseSaveThumbFile(_gameRef); if (DID_SUCCEED(SaveThumbFile->open(filename))) { ret = SaveThumbFile->getMemStream(); @@ -306,16 +321,19 @@ Common::SeekableReadStream *BaseFileManager::openFileRaw(const Common::String &f } ret = openDiskFile(filename); - if (ret) + if (ret) { return ret; + } ret = openPkgFile(filename); - if (ret) + if (ret) { return ret; + } ret = BaseResources::getFile(filename); - if (ret) + if (ret) { return ret; + } warning("BFileManager::OpenFileRaw - Failed to open %s", filename.c_str()); return NULL; diff --git a/engines/wintermute/base/base_frame.cpp b/engines/wintermute/base/base_frame.cpp index 67edccd041..68b866bbf5 100644 --- a/engines/wintermute/base/base_frame.cpp +++ b/engines/wintermute/base/base_frame.cpp @@ -61,8 +61,9 @@ BaseFrame::~BaseFrame() { delete _sound; _sound = NULL; - for (int i = 0; i < _subframes.getSize(); i++) + for (int i = 0; i < _subframes.getSize(); i++) { delete _subframes[i]; + } _subframes.removeAll(); for (int i = 0; i < _applyEvent.getSize(); i++) { @@ -79,7 +80,9 @@ bool BaseFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float for (int i = 0; i < _subframes.getSize(); i++) { res = _subframes[i]->draw(x, y, registerOwner, zoomX, zoomY, precise, alpha, rotate, blendMode); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } } return STATUS_OK; } @@ -88,7 +91,9 @@ bool BaseFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float ////////////////////////////////////////////////////////////////////////// bool BaseFrame::oneTimeDisplay(BaseObject *owner, bool muted) { if (_sound && !muted) { - if (owner) owner->updateOneSound(_sound); + if (owner) { + owner->updateOneSound(_sound); + } _sound->play(); /* if (_gameRef->_state == GAME_FROZEN) { @@ -240,7 +245,9 @@ bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { if (!subframe || DID_FAIL(subframe->loadBuffer((byte *)params, lifeTime, keepLoaded))) { delete subframe; cmd = PARSERR_GENERIC; - } else _subframes.add(subframe); + } else { + _subframes.add(subframe); + } } break; @@ -251,7 +258,9 @@ bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { } _sound = new BaseSound(_gameRef); if (!_sound || DID_FAIL(_sound->setSound(params, Audio::Mixer::kSFXSoundType, false))) { - if (_gameRef->_soundMgr->_soundAvailable) _gameRef->LOG(0, "Error loading sound '%s'.", params); + if (_gameRef->_soundMgr->_soundAvailable) { + _gameRef->LOG(0, "Error loading sound '%s'.", params); + } delete _sound; _sound = NULL; } @@ -291,8 +300,11 @@ bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { BaseSubFrame *sub = new BaseSubFrame(_gameRef); if (surface_file != NULL) { - if (custoTrans) sub->setSurface(surface_file, false, r, g, b, lifeTime, keepLoaded); - else sub->setSurface(surface_file, true, 0, 0, 0, lifeTime, keepLoaded); + if (custoTrans) { + sub->setSurface(surface_file, false, r, g, b, lifeTime, keepLoaded); + } else { + sub->setSurface(surface_file, true, 0, 0, 0, lifeTime, keepLoaded); + } if (!sub->_surface) { delete sub; @@ -301,11 +313,16 @@ bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { } sub->_alpha = BYTETORGBA(ar, ag, ab, alpha); - if (custoTrans) sub->_transparent = BYTETORGBA(r, g, b, 0xFF); + if (custoTrans) { + sub->_transparent = BYTETORGBA(r, g, b, 0xFF); + } } - if (BasePlatform::isRectEmpty(&rect)) sub->setDefaultRect(); - else sub->_rect = rect; + if (BasePlatform::isRectEmpty(&rect)) { + sub->setDefaultRect(); + } else { + sub->_rect = rect; + } sub->_hotspotX = hotspotX; sub->_hotspotY = hotspotY; @@ -325,7 +342,9 @@ bool BaseFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { ////////////////////////////////////////////////////////////////////////// bool BaseFrame::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, float scaleY) { - if (!rect) return false; + if (!rect) { + return false; + } BasePlatform::setRectEmpty(rect); Rect32 subRect; @@ -344,21 +363,27 @@ bool BaseFrame::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "FRAME {\n"); buffer->putTextIndent(indent + 2, "DELAY = %d\n", _delay); - if (_moveX != 0 || _moveY != 0) + if (_moveX != 0 || _moveY != 0) { buffer->putTextIndent(indent + 2, "MOVE {%d, %d}\n", _moveX, _moveY); + } - if (_sound && _sound->_soundFilename) + if (_sound && _sound->_soundFilename) { buffer->putTextIndent(indent + 2, "SOUND=\"%s\"\n", _sound->_soundFilename); + } buffer->putTextIndent(indent + 2, "KEYFRAME=%s\n", _keyframe ? "TRUE" : "FALSE"); - if (_killSound) + if (_killSound) { buffer->putTextIndent(indent + 2, "KILL_SOUND=%s\n", _killSound ? "TRUE" : "FALSE"); + } - if (_editorExpanded) + if (_editorExpanded) { buffer->putTextIndent(indent + 2, "EDITOR_EXPANDED=%s\n", _editorExpanded ? "TRUE" : "FALSE"); + } - if (_subframes.getSize() > 0) _subframes[0]->saveAsText(buffer, indent, false); + if (_subframes.getSize() > 0) { + _subframes[0]->saveAsText(buffer, indent, false); + } for (int i = 1; i < _subframes.getSize(); i++) { _subframes[i]->saveAsText(buffer, indent + 2); @@ -406,8 +431,11 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac if (strcmp(name, "GetSound") == 0) { stack->correctParams(0); - if (_sound && _sound->_soundFilename) stack->pushString(_sound->_soundFilename); - else stack->pushNULL(); + if (_sound && _sound->_soundFilename) { + stack->pushString(_sound->_soundFilename); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -426,8 +454,12 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac stack->pushBool(false); delete _sound; _sound = NULL; - } else stack->pushBool(true); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -440,7 +472,9 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac if (index < 0 || index >= _subframes.getSize()) { script->runtimeError("Frame.GetSubframe: Subframe index %d is out of range.", index); stack->pushNULL(); - } else stack->pushNative(_subframes[index], true); + } else { + stack->pushNative(_subframes[index], true); + } return STATUS_OK; } @@ -477,7 +511,9 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac stack->correctParams(1); ScValue *val = stack->pop(); const char *filename = NULL; - if (!val->isNULL()) filename = val->getString(); + if (!val->isNULL()) { + filename = val->getString(); + } BaseSubFrame *sub = new BaseSubFrame(_gameRef); if (filename != NULL) { @@ -496,19 +532,26 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac else if (strcmp(name, "InsertSubframe") == 0) { stack->correctParams(2); int index = stack->pop()->getInt(); - if (index < 0) index = 0; + if (index < 0) { + index = 0; + } ScValue *val = stack->pop(); const char *filename = NULL; - if (!val->isNULL()) filename = val->getString(); + if (!val->isNULL()) { + filename = val->getString(); + } BaseSubFrame *sub = new BaseSubFrame(_gameRef); if (filename != NULL) { sub->setSurface(filename); } - if (index >= _subframes.getSize()) _subframes.add(sub); - else _subframes.insertAt(index, sub); + if (index >= _subframes.getSize()) { + _subframes.add(sub); + } else { + _subframes.insertAt(index, sub); + } stack->pushNative(sub, true); return STATUS_OK; @@ -523,7 +566,9 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac if (index < 0 || index >= _applyEvent.getSize()) { script->runtimeError("Frame.GetEvent: Event index %d is out of range.", index); stack->pushNULL(); - } else stack->pushString(_applyEvent[index]); + } else { + stack->pushString(_applyEvent[index]); + } return STATUS_OK; } @@ -563,15 +608,20 @@ bool BaseFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStac ////////////////////////////////////////////////////////////////////////// else { - if (_subframes.getSize() == 1) return _subframes[0]->scCallMethod(script, stack, thisStack, name); - else return BaseScriptable::scCallMethod(script, stack, thisStack, name); + if (_subframes.getSize() == 1) { + return _subframes[0]->scCallMethod(script, stack, thisStack, name); + } else { + return BaseScriptable::scCallMethod(script, stack, thisStack, name); + } } } ////////////////////////////////////////////////////////////////////////// ScValue *BaseFrame::scGetProperty(const char *name) { - if (!_scValue) _scValue = new ScValue(_gameRef); + if (!_scValue) { + _scValue = new ScValue(_gameRef); + } _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -640,8 +690,11 @@ ScValue *BaseFrame::scGetProperty(const char *name) { ////////////////////////////////////////////////////////////////////////// else { - if (_subframes.getSize() == 1) return _subframes[0]->scGetProperty(name); - else return BaseScriptable::scGetProperty(name); + if (_subframes.getSize() == 1) { + return _subframes[0]->scGetProperty(name); + } else { + return BaseScriptable::scGetProperty(name); + } } } @@ -690,8 +743,11 @@ bool BaseFrame::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else { - if (_subframes.getSize() == 1) return _subframes[0]->scSetProperty(name, value); - else return BaseScriptable::scSetProperty(name, value); + if (_subframes.getSize() == 1) { + return _subframes[0]->scSetProperty(name, value); + } else { + return BaseScriptable::scSetProperty(name, value); + } } } diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp index b2b92d6de4..9de183660e 100644 --- a/engines/wintermute/base/base_game.cpp +++ b/engines/wintermute/base/base_game.cpp @@ -390,7 +390,9 @@ bool BaseGame::cleanup() { _fontStorage->removeFont(_videoFont); _videoFont = NULL; - for (int i = 0; i < _quickMessages.getSize(); i++) delete _quickMessages[i]; + for (int i = 0; i < _quickMessages.getSize(); i++) { + delete _quickMessages[i]; + } _quickMessages.removeAll(); _viewportStack.removeAll(); @@ -417,48 +419,59 @@ bool BaseGame::initialize1() { bool loaded = false; // Not really a loop, but a goto-replacement. while (!loaded) { _surfaceStorage = new BaseSurfaceStorage(this); - if (_surfaceStorage == NULL) + if (_surfaceStorage == NULL) { break; + } _fontStorage = new BaseFontStorage(this); - if (_fontStorage == NULL) + if (_fontStorage == NULL) { break; + } _fileManager = new BaseFileManager(this); - if (_fileManager == NULL) + if (_fileManager == NULL) { break; + } _soundMgr = new BaseSoundMgr(this); - if (_soundMgr == NULL) + if (_soundMgr == NULL) { break; + } _debugMgr = new BaseDebugger(this); - if (_debugMgr == NULL) + if (_debugMgr == NULL) { break; + } _mathClass = new SXMath(this); - if (_mathClass == NULL) + if (_mathClass == NULL) { break; + } _scEngine = new ScEngine(this); - if (_scEngine == NULL) + if (_scEngine == NULL) { break; + } _videoPlayer = new VideoPlayer(this); - if (_videoPlayer == NULL) + if (_videoPlayer == NULL) { break; + } _transMgr = new BaseTransitionMgr(this); - if (_transMgr == NULL) + if (_transMgr == NULL) { break; + } _keyboardState = new BaseKeyboardState(this); - if (_keyboardState == NULL) + if (_keyboardState == NULL) { break; + } _fader = new BaseFader(this); - if (_fader == NULL) + if (_fader == NULL) { break; + } registerObject(_fader); loaded = true; @@ -484,7 +497,9 @@ bool BaseGame::initialize1() { ////////////////////////////////////////////////////////////////////// bool BaseGame::initialize2() { // we know whether we are going to be accelerated _renderer = makeOSystemRenderer(this); - if (_renderer == NULL) return STATUS_FAILED; + if (_renderer == NULL) { + return STATUS_FAILED; + } return STATUS_OK; } @@ -495,9 +510,15 @@ bool BaseGame::initialize3() { // renderer is initialized _posX = _renderer->_width / 2; _posY = _renderer->_height / 2; - if (_indicatorY == -1) _indicatorY = _renderer->_height - _indicatorHeight; - if (_indicatorX == -1) _indicatorX = 0; - if (_indicatorWidth == -1) _indicatorWidth = _renderer->_width; + if (_indicatorY == -1) { + _indicatorY = _renderer->_height - _indicatorHeight; + } + if (_indicatorX == -1) { + _indicatorX = 0; + } + if (_indicatorWidth == -1) { + _indicatorWidth = _renderer->_width; + } return STATUS_OK; } @@ -567,7 +588,9 @@ void BaseGame::LOG(bool res, const char *fmt, ...) { if (_engineLogCallback) { _engineLogCallback(buff, res, _engineLogCallbackData); } - if (_debugMgr) _debugMgr->onLog(res, buff); + if (_debugMgr) { + _debugMgr->onLog(res, buff); + } debugCN(kWinterMuteDebugLog, "%02d:%02d:%02d: %s\n", hours, mins, secs, buff); @@ -615,7 +638,9 @@ bool BaseGame::initLoop() { _timerDelta = _timer - _timerLast; _timerLast = _timer; _timer += MIN((uint32)1000, _deltaTime); - } else _timerDelta = 0; + } else { + _timerDelta = 0; + } _framesRendered++; if (_fpsTime > 1000) { @@ -637,7 +662,9 @@ bool BaseGame::initLoop() { updateSounds(); - if (_fader) _fader->update(); + if (_fader) { + _fader->update(); + } return STATUS_OK; } @@ -663,8 +690,12 @@ void BaseGame::setOffset(int offsetX, int offsetY) { ////////////////////////////////////////////////////////////////////////// void BaseGame::getOffset(int *offsetX, int *offsetY) { - if (offsetX != NULL) *offsetX = _offsetX; - if (offsetY != NULL) *offsetY = _offsetY; + if (offsetX != NULL) { + *offsetX = _offsetX; + } + if (offsetY != NULL) { + *offsetY = _offsetY; + } } @@ -680,7 +711,9 @@ bool BaseGame::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing GAME file '%s'", filename); + } delete[] buffer; @@ -789,7 +822,9 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -801,14 +836,18 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_SYSTEM_FONT: - if (_systemFont) _fontStorage->removeFont(_systemFont); + if (_systemFont) { + _fontStorage->removeFont(_systemFont); + } _systemFont = NULL; _systemFont = _gameRef->_fontStorage->addFont((char *)params); break; case TOKEN_VIDEO_FONT: - if (_videoFont) _fontStorage->removeFont(_videoFont); + if (_videoFont) { + _fontStorage->removeFont(_videoFont); + } _videoFont = NULL; _videoFont = _gameRef->_fontStorage->addFont((char *)params); @@ -939,7 +978,9 @@ bool BaseGame::loadBuffer(byte *buffer, bool complete) { } } - if (!_systemFont) _systemFont = _gameRef->_fontStorage->addFont("system_font.fnt"); + if (!_systemFont) { + _systemFont = _gameRef->_fontStorage->addFont("system_font.fnt"); + } if (cmd == PARSERR_TOKENNOTFOUND) { @@ -994,10 +1035,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "RunScript") == 0) { _gameRef->LOG(0, "**Warning** The 'RunScript' method is now obsolete. Use 'AttachScript' instead (same syntax)"); stack->correctParams(1); - if (DID_FAIL(addScript(stack->pop()->getString()))) + if (DID_FAIL(addScript(stack->pop()->getString()))) { stack->pushBool(false); - else + } else { stack->pushBool(true); + } return STATUS_OK; } @@ -1008,16 +1050,20 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "LoadStringTable") == 0) { stack->correctParams(2); const char *filename = stack->pop()->getString(); - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); bool ClearOld; - if (Val->isNULL()) ClearOld = true; - else ClearOld = Val->getBool(); + if (val->isNULL()) { + ClearOld = true; + } else { + ClearOld = val->getBool(); + } - if (DID_FAIL(_stringTable->loadFile(filename, ClearOld))) + if (DID_FAIL(_stringTable->loadFile(filename, ClearOld))) { stack->pushBool(false); - else + } else { stack->pushBool(true); + } return STATUS_OK; } @@ -1028,8 +1074,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "ValidObject") == 0) { stack->correctParams(1); BaseScriptable *obj = stack->pop()->getNative(); - if (validObject((BaseObject *) obj)) stack->pushBool(true); - else stack->pushBool(false); + if (validObject((BaseObject *) obj)) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -1054,7 +1103,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); BaseObject *obj = (BaseObject *)val->getNative(); unregisterObject(obj); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } stack->pushNULL(); return STATUS_OK; @@ -1097,8 +1148,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "PlayMusic") == 0 || strcmp(name, "PlayMusicChannel") == 0) { int channel = 0; - if (strcmp(name, "PlayMusic") == 0) stack->correctParams(3); - else { + if (strcmp(name, "PlayMusic") == 0) { + stack->correctParams(3); + } else { stack->correctParams(4); channel = stack->pop()->getInt(); } @@ -1111,8 +1163,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack uint32 loopStart = (uint32)(valLoopStart->isNULL() ? 0 : valLoopStart->getInt()); - if (DID_FAIL(playMusic(channel, filename, looping, loopStart))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(playMusic(channel, filename, looping, loopStart))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -1122,14 +1177,18 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "StopMusic") == 0 || strcmp(name, "StopMusicChannel") == 0) { int channel = 0; - if (strcmp(name, "StopMusic") == 0) stack->correctParams(0); - else { + if (strcmp(name, "StopMusic") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (DID_FAIL(stopMusic(channel))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(stopMusic(channel))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -1139,14 +1198,18 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "PauseMusic") == 0 || strcmp(name, "PauseMusicChannel") == 0) { int channel = 0; - if (strcmp(name, "PauseMusic") == 0) stack->correctParams(0); - else { + if (strcmp(name, "PauseMusic") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (DID_FAIL(pauseMusic(channel))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(pauseMusic(channel))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -1155,14 +1218,18 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ResumeMusic") == 0 || strcmp(name, "ResumeMusicChannel") == 0) { int channel = 0; - if (strcmp(name, "ResumeMusic") == 0) stack->correctParams(0); - else { + if (strcmp(name, "ResumeMusic") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (DID_FAIL(resumeMusic(channel))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(resumeMusic(channel))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -1171,15 +1238,20 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetMusic") == 0 || strcmp(name, "GetMusicChannel") == 0) { int channel = 0; - if (strcmp(name, "GetMusic") == 0) stack->correctParams(0); - else { + if (strcmp(name, "GetMusic") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (channel < 0 || channel >= NUM_MUSIC_CHANNELS) stack->pushNULL(); - else { - if (!_music[channel] || !_music[channel]->_soundFilename) stack->pushNULL(); - else stack->pushString(_music[channel]->_soundFilename); + if (channel < 0 || channel >= NUM_MUSIC_CHANNELS) { + stack->pushNULL(); + } else { + if (!_music[channel] || !_music[channel]->_soundFilename) { + stack->pushNULL(); + } else { + stack->pushString(_music[channel]->_soundFilename); + } } return STATUS_OK; } @@ -1189,16 +1261,20 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetMusicPosition") == 0 || strcmp(name, "SetMusicChannelPosition") == 0 || strcmp(name, "SetMusicPositionChannel") == 0) { int channel = 0; - if (strcmp(name, "SetMusicPosition") == 0) stack->correctParams(1); - else { + if (strcmp(name, "SetMusicPosition") == 0) { + stack->correctParams(1); + } else { stack->correctParams(2); channel = stack->pop()->getInt(); } uint32 time = stack->pop()->getInt(); - if (DID_FAIL(setMusicStartTime(channel, time))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(setMusicStartTime(channel, time))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -1208,14 +1284,18 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetMusicPosition") == 0 || strcmp(name, "GetMusicChannelPosition") == 0) { int channel = 0; - if (strcmp(name, "GetMusicPosition") == 0) stack->correctParams(0); - else { + if (strcmp(name, "GetMusicPosition") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) stack->pushInt(0); - else stack->pushInt(_music[channel]->getPositionTime()); + if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) { + stack->pushInt(0); + } else { + stack->pushInt(_music[channel]->getPositionTime()); + } return STATUS_OK; } @@ -1224,14 +1304,18 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "IsMusicPlaying") == 0 || strcmp(name, "IsMusicChannelPlaying") == 0) { int channel = 0; - if (strcmp(name, "IsMusicPlaying") == 0) stack->correctParams(0); - else { + if (strcmp(name, "IsMusicPlaying") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) stack->pushBool(false); - else stack->pushBool(_music[channel]->isPlaying()); + if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) { + stack->pushBool(false); + } else { + stack->pushBool(_music[channel]->isPlaying()); + } return STATUS_OK; } @@ -1240,17 +1324,22 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetMusicVolume") == 0 || strcmp(name, "SetMusicChannelVolume") == 0) { int channel = 0; - if (strcmp(name, "SetMusicVolume") == 0) stack->correctParams(1); - else { + if (strcmp(name, "SetMusicVolume") == 0) { + stack->correctParams(1); + } else { stack->correctParams(2); channel = stack->pop()->getInt(); } int volume = stack->pop()->getInt(); - if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) stack->pushBool(false); - else { - if (DID_FAIL(_music[channel]->setVolumePercent(volume))) stack->pushBool(false); - else stack->pushBool(true); + if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) { + stack->pushBool(false); + } else { + if (DID_FAIL(_music[channel]->setVolumePercent(volume))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } } return STATUS_OK; } @@ -1260,14 +1349,18 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetMusicVolume") == 0 || strcmp(name, "GetMusicChannelVolume") == 0) { int channel = 0; - if (strcmp(name, "GetMusicVolume") == 0) stack->correctParams(0); - else { + if (strcmp(name, "GetMusicVolume") == 0) { + stack->correctParams(0); + } else { stack->correctParams(1); channel = stack->pop()->getInt(); } - if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) stack->pushInt(0); - else stack->pushInt(_music[channel]->getVolumePercent()); + if (channel < 0 || channel >= NUM_MUSIC_CHANNELS || !_music[channel]) { + stack->pushInt(0); + } else { + stack->pushInt(_music[channel]->getVolumePercent()); + } return STATUS_OK; } @@ -1350,8 +1443,12 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int right = stack->pop()->getInt(); int bottom = stack->pop()->getInt(); - if (right < left) BaseUtils::swap(&left, &right); - if (bottom < top) BaseUtils::swap(&top, &bottom); + if (right < left) { + BaseUtils::swap(&left, &right); + } + if (bottom < top) { + BaseUtils::swap(&top, &bottom); + } BasePlatform::setRect(&_mouseLockRect, left, top, right, bottom); @@ -1376,26 +1473,34 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack const char *filename = stack->pop()->getString(); warning("PlayVideo: %s - not implemented yet", filename); ScValue *valType = stack->pop(); - int Type; - if (valType->isNULL()) Type = (int)VID_PLAY_STRETCH; - else Type = valType->getInt(); + int type; + if (valType->isNULL()) { + type = (int)VID_PLAY_STRETCH; + } else { + type = valType->getInt(); + } int xVal = stack->pop()->getInt(); int yVal = stack->pop()->getInt(); - bool FreezeMusic = stack->pop()->getBool(true); + bool freezeMusic = stack->pop()->getBool(true); ScValue *valSub = stack->pop(); - const char *SubtitleFile = valSub->isNULL() ? NULL : valSub->getString(); + const char *subtitleFile = valSub->isNULL() ? NULL : valSub->getString(); - if (Type < (int)VID_PLAY_POS || Type > (int)VID_PLAY_CENTER) - Type = (int)VID_PLAY_STRETCH; + if (type < (int)VID_PLAY_POS || type > (int)VID_PLAY_CENTER) { + type = (int)VID_PLAY_STRETCH; + } - if (DID_SUCCEED(_gameRef->_videoPlayer->initialize(filename, SubtitleFile))) { - if (DID_SUCCEED(_gameRef->_videoPlayer->play((TVideoPlayback)Type, xVal, yVal, FreezeMusic))) { + if (DID_SUCCEED(_gameRef->_videoPlayer->initialize(filename, subtitleFile))) { + if (DID_SUCCEED(_gameRef->_videoPlayer->play((TVideoPlayback)type, xVal, yVal, freezeMusic))) { stack->pushBool(true); script->sleep(0); - } else stack->pushBool(false); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -1414,9 +1519,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack const char *filename = stack->pop()->getString(); ScValue *valType = stack->pop(); int type; - if (valType->isNULL()) + if (valType->isNULL()) { type = (int)VID_PLAY_STRETCH; - else type = valType->getInt(); + } else { + type = valType->getInt(); + } int xVal = stack->pop()->getInt(); int yVal = stack->pop()->getInt(); @@ -1426,7 +1533,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *valSub = stack->pop(); const char *SubtitleFile = valSub->isNULL() ? NULL : valSub->getString(); - if (type < (int)VID_PLAY_POS || type > (int)VID_PLAY_CENTER) type = (int)VID_PLAY_STRETCH; + if (type < (int)VID_PLAY_POS || type > (int)VID_PLAY_CENTER) { + type = (int)VID_PLAY_STRETCH; + } delete _theoraPlayer; _theoraPlayer = new VideoTheoraPlayer(this); @@ -1435,7 +1544,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (DID_SUCCEED(_theoraPlayer->play((TVideoPlayback)type, xVal, yVal, true, freezeMusic))) { stack->pushBool(true); script->sleep(0); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } } else { stack->pushBool(false); delete _theoraPlayer; @@ -1649,8 +1760,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetActiveCursor") == 0) { stack->correctParams(1); - if (DID_SUCCEED(setActiveCursor(stack->pop()->getString()))) stack->pushBool(true); - else stack->pushBool(false); + if (DID_SUCCEED(setActiveCursor(stack->pop()->getString()))) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -1660,8 +1774,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetActiveCursor") == 0) { stack->correctParams(0); - if (!_activeCursor || !_activeCursor->getFilename()) stack->pushNULL(); - else stack->pushString(_activeCursor->getFilename()); + if (!_activeCursor || !_activeCursor->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_activeCursor->getFilename()); + } return STATUS_OK; } @@ -1671,8 +1788,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetActiveCursorObject") == 0) { stack->correctParams(0); - if (!_activeCursor) stack->pushNULL(); - else stack->pushNative(_activeCursor, true); + if (!_activeCursor) { + stack->pushNULL(); + } else { + stack->pushNative(_activeCursor, true); + } return STATUS_OK; } @@ -1695,8 +1815,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "HasActiveCursor") == 0) { stack->correctParams(0); - if (_activeCursor) stack->pushBool(true); - else stack->pushBool(false); + if (_activeCursor) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -1710,8 +1833,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack // TODO: Replace with fileExists Common::SeekableReadStream *file = _fileManager->openFile(filename, false); - if (!file) stack->pushBool(false); - else { + if (!file) { + stack->pushBool(false); + } else { _fileManager->closeFile(file); stack->pushBool(true); } @@ -1732,7 +1856,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack bool system = (strcmp(name, "SystemFadeOut") == 0 || strcmp(name, "SystemFadeOutAsync") == 0); _fader->fadeOut(BYTETORGBA(red, green, blue, alpha), duration, system); - if (strcmp(name, "FadeOutAsync") != 0 && strcmp(name, "SystemFadeOutAsync") != 0) script->waitFor(_fader); + if (strcmp(name, "FadeOutAsync") != 0 && strcmp(name, "SystemFadeOutAsync") != 0) { + script->waitFor(_fader); + } stack->pushNULL(); return STATUS_OK; @@ -1752,7 +1878,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack bool system = (strcmp(name, "SystemFadeIn") == 0 || strcmp(name, "SystemFadeInAsync") == 0); _fader->fadeIn(BYTETORGBA(red, green, blue, alpha), duration, system); - if (strcmp(name, "FadeInAsync") != 0 && strcmp(name, "SystemFadeInAsync") != 0) script->waitFor(_fader); + if (strcmp(name, "FadeInAsync") != 0 && strcmp(name, "SystemFadeInAsync") != 0) { + script->waitFor(_fader); + } stack->pushNULL(); return STATUS_OK; @@ -1774,15 +1902,16 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); char filename[MAX_PATH_LENGTH]; - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); warning("BGame::ScCallMethod - Screenshot not reimplemented"); //TODO int fileNum = 0; while (true) { - sprintf(filename, "%s%03d.bmp", Val->isNULL() ? getName() : Val->getString(), fileNum); - if (!Common::File::exists(filename)) + sprintf(filename, "%s%03d.bmp", val->isNULL() ? getName() : val->getString(), fileNum); + if (!Common::File::exists(filename)) { break; + } fileNum++; } @@ -1791,7 +1920,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (image) { ret = DID_SUCCEED(image->saveBMPFile(filename)); delete image; - } else ret = false; + } else { + ret = false; + } stack->pushBool(ret); return STATUS_OK; @@ -1810,9 +1941,13 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack BaseImage *image = _gameRef->_renderer->takeScreenshot(); if (image) { ret = DID_SUCCEED(image->resize(sizeX, sizeY)); - if (ret) ret = DID_SUCCEED(image->saveBMPFile(filename)); + if (ret) { + ret = DID_SUCCEED(image->saveBMPFile(filename)); + } delete image; - } else ret = false; + } else { + ret = false; + } stack->pushBool(ret); return STATUS_OK; @@ -1828,7 +1963,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack UIWindow *win = new UIWindow(_gameRef); _windows.add(win); registerObject(win); - if (!val->isNULL()) win->setName(val->getString()); + if (!val->isNULL()) { + win->setName(val->getString()); + } stack->pushNative(win, true); return STATUS_OK; } @@ -1912,8 +2049,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetWaitCursor") == 0) { stack->correctParams(1); - if (DID_SUCCEED(setWaitCursor(stack->pop()->getString()))) stack->pushBool(true); - else stack->pushBool(false); + if (DID_SUCCEED(setWaitCursor(stack->pop()->getString()))) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -1936,8 +2076,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetWaitCursor") == 0) { stack->correctParams(0); - if (!_cursorNoninteractive || !_cursorNoninteractive->getFilename()) stack->pushNULL(); - else stack->pushString(_cursorNoninteractive->getFilename()); + if (!_cursorNoninteractive || !_cursorNoninteractive->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursorNoninteractive->getFilename()); + } return STATUS_OK; } @@ -1947,8 +2090,11 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetWaitCursorObject") == 0) { stack->correctParams(0); - if (!_cursorNoninteractive) stack->pushNULL(); - else stack->pushNative(_cursorNoninteractive, true); + if (!_cursorNoninteractive) { + stack->pushNULL(); + } else { + stack->pushNative(_cursorNoninteractive, true); + } return STATUS_OK; } @@ -2017,10 +2163,8 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "AccOutputText") == 0) { stack->correctParams(2); - /* const char *Str = */ - stack->pop()->getString(); - /* int Type = */ - stack->pop()->getInt(); + /* const char *Str = */ stack->pop()->getString(); + /* int type = */ stack->pop()->getInt(); // do nothing stack->pushNULL(); @@ -2038,7 +2182,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _cachedThumbnail; _cachedThumbnail = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -2083,12 +2229,15 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack char Hex[100]; sprintf(Hex, "%x", checksum); stack->pushString(Hex); - } else + } else { stack->pushInt(checksum); + } _fileManager->closeFile(file); file = NULL; - } else stack->pushNULL(); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -2139,9 +2288,9 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->pushNULL(); return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -2307,8 +2456,11 @@ ScValue *BaseGame::scGetProperty(const char *name) { // Keyboard (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Keyboard") == 0) { - if (_keyboardState) _scValue->setNative(_keyboardState, true); - else _scValue->setNULL(); + if (_keyboardState) { + _scValue->setNative(_keyboardState, true); + } else { + _scValue->setNULL(); + } return _scValue; } @@ -2530,9 +2682,9 @@ ScValue *BaseGame::scGetProperty(const char *name) { error("Request for a SXStore-object, which is not supported by ScummVM"); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -2579,7 +2731,9 @@ bool BaseGame::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "MainObject") == 0) { BaseScriptable *obj = value->getNative(); - if (obj == NULL || validObject((BaseObject *)obj)) _mainObject = (BaseObject *)obj; + if (obj == NULL || validObject((BaseObject *)obj)) { + _mainObject = (BaseObject *)obj; + } return STATUS_OK; } @@ -2655,10 +2809,14 @@ bool BaseGame::scSetProperty(const char *name, ScValue *value) { // TextEncoding ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "TextEncoding") == 0) { - int Enc = value->getInt(); - if (Enc < 0) Enc = 0; - if (Enc >= NUM_TEXT_ENCODINGS) Enc = NUM_TEXT_ENCODINGS - 1; - _textEncoding = (TTextEncoding)Enc; + int enc = value->getInt(); + if (enc < 0) { + enc = 0; + } + if (enc >= NUM_TEXT_ENCODINGS) { + enc = NUM_TEXT_ENCODINGS - 1; + } + _textEncoding = (TTextEncoding)enc; return STATUS_OK; } @@ -2725,9 +2883,9 @@ bool BaseGame::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "CursorHidden") == 0) { _cursorHidden = value->getBool(); return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -2741,7 +2899,9 @@ const char *BaseGame::scToString() { #define QUICK_MSG_DURATION 3000 ////////////////////////////////////////////////////////////////////////// bool BaseGame::displayQuickMsg() { - if (_quickMessages.getSize() == 0 || !_systemFont) return STATUS_OK; + if (_quickMessages.getSize() == 0 || !_systemFont) { + return STATUS_OK; + } // update for (int i = 0; i < _quickMessages.getSize(); i++) { @@ -2796,7 +2956,9 @@ bool BaseGame::registerObject(BaseObject *object) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::unregisterObject(BaseObject *object) { - if (!object) return STATUS_OK; + if (!object) { + return STATUS_OK; + } // is it a window? for (int i = 0; i < _windows.getSize(); i++) { @@ -2804,23 +2966,31 @@ bool BaseGame::unregisterObject(BaseObject *object) { _windows.removeAt(i); // get new focused window - if (_focusedWindow == object) _focusedWindow = NULL; + if (_focusedWindow == object) { + _focusedWindow = NULL; + } break; } } // is it active object? - if (_activeObject == object) _activeObject = NULL; + if (_activeObject == object) { + _activeObject = NULL; + } // is it main object? - if (_mainObject == object) _mainObject = NULL; + if (_mainObject == object) { + _mainObject = NULL; + } // destroy object for (int i = 0; i < _regObjects.getSize(); i++) { if (_regObjects[i] == object) { _regObjects.removeAt(i); - if (!_loadInProgress) SystemClassRegistry::getInstance()->enumInstances(invalidateValues, "ScValue", (void *)object); + if (!_loadInProgress) { + SystemClassRegistry::getInstance()->enumInstances(invalidateValues, "ScValue", (void *)object); + } delete object; return STATUS_OK; } @@ -2846,11 +3016,17 @@ void BaseGame::invalidateValues(void *value, void *data) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::validObject(BaseObject *object) { - if (!object) return false; - if (object == this) return true; + if (!object) { + return false; + } + if (object == this) { + return true; + } for (int i = 0; i < _regObjects.getSize(); i++) { - if (_regObjects[i] == object) return true; + if (_regObjects[i] == object) { + return true; + } } return false; } @@ -2946,7 +3122,9 @@ bool BaseGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); BaseScriptable *obj = stack->pop()->getNative(); - if (validObject((BaseObject *)obj)) script->waitForExclusive((BaseObject *)obj); + if (validObject((BaseObject *)obj)) { + script->waitForExclusive((BaseObject *)obj); + } stack->pushNULL(); } @@ -2982,8 +3160,11 @@ bool BaseGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack int b = stack->pop()->getInt(); int a; ScValue *val = stack->pop(); - if (val->isNULL()) a = 255; - else a = val->getInt(); + if (val->isNULL()) { + a = 255; + } else { + a = val->getInt(); + } stack->pushInt(BYTETORGBA(r, g, b, a)); } @@ -3142,15 +3323,23 @@ bool BaseGame::ExternalCall(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// bool BaseGame::showCursor() { - if (_cursorHidden) return STATUS_OK; + if (_cursorHidden) { + return STATUS_OK; + } if (!_interactive && _gameRef->_state == GAME_RUNNING) { - if (_cursorNoninteractive) return drawCursor(_cursorNoninteractive); + if (_cursorNoninteractive) { + return drawCursor(_cursorNoninteractive); + } } else { - if (_activeObject && !DID_FAIL(_activeObject->showCursor())) return STATUS_OK; - else { - if (_activeObject && _activeCursor && _activeObject->getExtendedFlag("usable")) return drawCursor(_activeCursor); - else if (_cursor) return drawCursor(_cursor); + if (_activeObject && !DID_FAIL(_activeObject->showCursor())) { + return STATUS_OK; + } else { + if (_activeObject && _activeCursor && _activeObject->getExtendedFlag("usable")) { + return drawCursor(_activeCursor); + } else if (_cursor) { + return drawCursor(_cursor); + } } } return STATUS_FAILED; @@ -3171,7 +3360,9 @@ bool BaseGame::saveGame(int slot, const char *desc, bool quickSave) { _indicatorDisplay = true; _indicatorProgress = 0; BasePersistenceManager *pm = new BasePersistenceManager(_gameRef); - if (DID_FAIL(ret = pm->initSave(desc))) goto save_finish; + if (DID_FAIL(ret = pm->initSave(desc))) { + goto save_finish; + } if (!quickSave) { delete _saveLoadImage; @@ -3186,9 +3377,15 @@ bool BaseGame::saveGame(int slot, const char *desc, bool quickSave) { } } - if (DID_FAIL(ret = SystemClassRegistry::getInstance()->saveTable(_gameRef, pm, quickSave))) goto save_finish; - if (DID_FAIL(ret = SystemClassRegistry::getInstance()->saveInstances(_gameRef, pm, quickSave))) goto save_finish; - if (DID_FAIL(ret = pm->saveFile(filename))) goto save_finish; + if (DID_FAIL(ret = SystemClassRegistry::getInstance()->saveTable(_gameRef, pm, quickSave))) { + goto save_finish; + } + if (DID_FAIL(ret = SystemClassRegistry::getInstance()->saveInstances(_gameRef, pm, quickSave))) { + goto save_finish; + } + if (DID_FAIL(ret = pm->saveFile(filename))) { + goto save_finish; + } _registry->writeInt("System", "MostRecentSaveSlot", slot); @@ -3240,11 +3437,17 @@ bool BaseGame::loadGame(const char *filename) { _indicatorDisplay = true; _indicatorProgress = 0; BasePersistenceManager *pm = new BasePersistenceManager(_gameRef); - if (DID_FAIL(ret = pm->initLoad(filename))) goto load_finish; + if (DID_FAIL(ret = pm->initLoad(filename))) { + goto load_finish; + } //if (DID_FAIL(ret = cleanup())) goto load_finish; - if (DID_FAIL(ret = SystemClassRegistry::getInstance()->loadTable(_gameRef, pm))) goto load_finish; - if (DID_FAIL(ret = SystemClassRegistry::getInstance()->loadInstances(_gameRef, pm))) goto load_finish; + if (DID_FAIL(ret = SystemClassRegistry::getInstance()->loadTable(_gameRef, pm))) { + goto load_finish; + } + if (DID_FAIL(ret = SystemClassRegistry::getInstance()->loadInstances(_gameRef, pm))) { + goto load_finish; + } // data initialization after load initAfterLoad(); @@ -3332,7 +3535,9 @@ bool BaseGame::displayWindows(bool inGame) { if (_windows[i]->_visible && _windows[i]->_inGame == inGame) { res = _windows[i]->display(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } } } @@ -3356,7 +3561,9 @@ bool BaseGame::playMusic(int channel, const char *filename, bool looping, uint32 _music[channel]->setPositionTime(_musicStartTime[channel]); _musicStartTime[channel] = 0; } - if (loopStart) _music[channel]->setLoopStart(loopStart); + if (loopStart) { + _music[channel]->setLoopStart(loopStart); + } return _music[channel]->play(looping); } else { delete _music[channel]; @@ -3378,7 +3585,9 @@ bool BaseGame::stopMusic(int channel) { delete _music[channel]; _music[channel] = NULL; return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -3389,8 +3598,11 @@ bool BaseGame::pauseMusic(int channel) { return STATUS_FAILED; } - if (_music[channel]) return _music[channel]->pause(); - else return STATUS_FAILED; + if (_music[channel]) { + return _music[channel]->pause(); + } else { + return STATUS_FAILED; + } } @@ -3401,8 +3613,11 @@ bool BaseGame::resumeMusic(int channel) { return STATUS_FAILED; } - if (_music[channel]) return _music[channel]->resume(); - else return STATUS_FAILED; + if (_music[channel]) { + return _music[channel]->resume(); + } else { + return STATUS_FAILED; + } } @@ -3414,8 +3629,11 @@ bool BaseGame::setMusicStartTime(int channel, uint32 time) { } _musicStartTime[channel] = time; - if (_music[channel] && _music[channel]->isPlaying()) return _music[channel]->setPositionTime(time); - else return STATUS_OK; + if (_music[channel] && _music[channel]->isPlaying()) { + return _music[channel]->setPositionTime(time); + } else { + return STATUS_OK; + } } @@ -3464,11 +3682,15 @@ bool BaseGame::loadSettings(const char *filename) { case TOKEN_GAME: delete[] _settingsGameFile; _settingsGameFile = new char[strlen((char *)params) + 1]; - if (_settingsGameFile) strcpy(_settingsGameFile, (char *)params); + if (_settingsGameFile) { + strcpy(_settingsGameFile, (char *)params); + } break; case TOKEN_STRING_TABLE: - if (DID_FAIL(_stringTable->loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(_stringTable->loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_RESOLUTION: @@ -3544,8 +3766,9 @@ bool BaseGame::loadSettings(const char *filename) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->getIsSaving()) + if (!persistMgr->getIsSaving()) { cleanup(); + } BaseObject::persist(persistMgr); @@ -3627,29 +3850,32 @@ bool BaseGame::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_autoSaveSlot)); persistMgr->transfer(TMEMBER(_cursorHidden)); - if (!persistMgr->getIsSaving()) + if (!persistMgr->getIsSaving()) { _quitting = false; + } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// -bool BaseGame::focusWindow(UIWindow *Window) { - UIWindow *Prev = _focusedWindow; +bool BaseGame::focusWindow(UIWindow *window) { + UIWindow *prev = _focusedWindow; for (int i = 0; i < _windows.getSize(); i++) { - if (_windows[i] == Window) { + if (_windows[i] == window) { if (i < _windows.getSize() - 1) { _windows.removeAt(i); - _windows.add(Window); + _windows.add(window); - _gameRef->_focusedWindow = Window; + _gameRef->_focusedWindow = window; } - if (Window->_mode == WINDOW_NORMAL && Prev != Window && _gameRef->validObject(Prev) && (Prev->_mode == WINDOW_EXCLUSIVE || Prev->_mode == WINDOW_SYSTEM_EXCLUSIVE)) - return focusWindow(Prev); - else return STATUS_OK; + if (window->_mode == WINDOW_NORMAL && prev != window && _gameRef->validObject(prev) && (prev->_mode == WINDOW_EXCLUSIVE || prev->_mode == WINDOW_SYSTEM_EXCLUSIVE)) { + return focusWindow(prev); + } else { + return STATUS_OK; + } } } return STATUS_FAILED; @@ -3674,7 +3900,9 @@ bool BaseGame::freeze(bool includingMusic) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::unfreeze() { - if (_freezeLevel == 0) return STATUS_OK; + if (_freezeLevel == 0) { + return STATUS_OK; + } _freezeLevel--; if (_freezeLevel == 0) { @@ -3691,8 +3919,9 @@ bool BaseGame::unfreeze() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::handleKeypress(Common::Event *event, bool printable) { if (isVideoPlaying()) { - if (event->kbd.keycode == Common::KEYCODE_ESCAPE) + if (event->kbd.keycode == Common::KEYCODE_ESCAPE) { stopVideo(); + } return true; } @@ -3708,10 +3937,11 @@ bool BaseGame::handleKeypress(Common::Event *event, bool printable) { if (_focusedWindow) { if (!_gameRef->_focusedWindow->handleKeypress(event, _keyboardState->_currentPrintable)) { /*if (event->type != SDL_TEXTINPUT) {*/ - if (_gameRef->_focusedWindow->canHandleEvent("Keypress")) + if (_gameRef->_focusedWindow->canHandleEvent("Keypress")) { _gameRef->_focusedWindow->applyEvent("Keypress"); - else + } else { applyEvent("Keypress"); + } /*}*/ } return true; @@ -3760,11 +3990,19 @@ bool BaseGame::handleMouseWheel(int Delta) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::getVersion(byte *verMajor, byte *verMinor, byte *extMajor, byte *extMinor) { - if (verMajor) *verMajor = DCGF_VER_MAJOR; - if (verMinor) *verMinor = DCGF_VER_MINOR; + if (verMajor) { + *verMajor = DCGF_VER_MAJOR; + } + if (verMinor) { + *verMinor = DCGF_VER_MINOR; + } - if (extMajor) *extMajor = 0; - if (extMinor) *extMinor = 0; + if (extMajor) { + *extMajor = 0; + } + if (extMinor) { + *extMinor = 0; + } return STATUS_OK; } @@ -3775,7 +4013,9 @@ void BaseGame::setWindowTitle() { if (_renderer) { char title[512]; strcpy(title, _caption[0]); - if (title[0] != '\0') strcat(title, " - "); + if (title[0] != '\0') { + strcat(title, " - "); + } strcat(title, "WME Lite"); @@ -3825,7 +4065,9 @@ bool BaseGame::getSaveSlotDescription(int slot, char *buffer) { char filename[MAX_PATH_LENGTH + 1]; getSaveSlotFilename(slot, filename); BasePersistenceManager *pm = new BasePersistenceManager(_gameRef); - if (!pm) return STATUS_FAILED; + if (!pm) { + return STATUS_FAILED; + } if (DID_FAIL(pm->initLoad(filename))) { delete pm; @@ -3845,9 +4087,11 @@ bool BaseGame::isSaveSlotUsed(int slot) { getSaveSlotFilename(slot, filename); warning("BaseGame::IsSaveSlotUsed(%d) - FIXME, ugly solution", slot); - Common::SeekableReadStream *File = g_wintermute->getSaveFileMan()->openForLoading(filename); - if (!File) return false; - delete File; + Common::SeekableReadStream *file = g_wintermute->getSaveFileMan()->openForLoading(filename); + if (!file) { + return false; + } + delete file; return true; } @@ -3870,9 +4114,13 @@ bool BaseGame::setActiveObject(BaseObject *obj) { obj = NULL; } - if (obj == _activeObject) return STATUS_OK; + if (obj == _activeObject) { + return STATUS_OK; + } - if (_activeObject) _activeObject->applyEvent("MouseLeave"); + if (_activeObject) { + _activeObject->applyEvent("MouseLeave"); + } //if (ValidObject(_activeObject)) _activeObject->applyEvent("MouseLeave"); _activeObject = obj; if (_activeObject) { @@ -3886,8 +4134,11 @@ bool BaseGame::setActiveObject(BaseObject *obj) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::pushViewport(BaseViewport *viewport) { _viewportSP++; - if (_viewportSP >= _viewportStack.getSize()) _viewportStack.add(viewport); - else _viewportStack[_viewportSP] = viewport; + if (_viewportSP >= _viewportStack.getSize()) { + _viewportStack.add(viewport); + } else { + _viewportStack[_viewportSP] = viewport; + } _renderer->setViewport(viewport->getRect()); @@ -3898,13 +4149,16 @@ bool BaseGame::pushViewport(BaseViewport *viewport) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::popViewport() { _viewportSP--; - if (_viewportSP < -1) _gameRef->LOG(0, "Fatal: Viewport stack underflow!"); + if (_viewportSP < -1) { + _gameRef->LOG(0, "Fatal: Viewport stack underflow!"); + } - if (_viewportSP >= 0 && _viewportSP < _viewportStack.getSize()) _renderer->setViewport(_viewportStack[_viewportSP]->getRect()); - else _renderer->setViewport(_renderer->_drawOffsetX, - _renderer->_drawOffsetY, - _renderer->_width + _renderer->_drawOffsetX, - _renderer->_height + _renderer->_drawOffsetY); + if (_viewportSP >= 0 && _viewportSP < _viewportStack.getSize()) { + _renderer->setViewport(_viewportStack[_viewportSP]->getRect()); + } else _renderer->setViewport(_renderer->_drawOffsetX, + _renderer->_drawOffsetY, + _renderer->_width + _renderer->_drawOffsetX, + _renderer->_height + _renderer->_drawOffsetY); return STATUS_OK; } @@ -3912,17 +4166,22 @@ bool BaseGame::popViewport() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::getCurrentViewportRect(Rect32 *rect, bool *custom) { - if (rect == NULL) return STATUS_FAILED; - else { + if (rect == NULL) { + return STATUS_FAILED; + } else { if (_viewportSP >= 0) { BasePlatform::copyRect(rect, _viewportStack[_viewportSP]->getRect()); - if (custom) *custom = true; + if (custom) { + *custom = true; + } } else { BasePlatform::setRect(rect, _renderer->_drawOffsetX, _renderer->_drawOffsetY, _renderer->_width + _renderer->_drawOffsetX, _renderer->_height + _renderer->_drawOffsetY); - if (custom) *custom = false; + if (custom) { + *custom = false; + } } return STATUS_OK; @@ -3933,11 +4192,19 @@ bool BaseGame::getCurrentViewportRect(Rect32 *rect, bool *custom) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::getCurrentViewportOffset(int *offsetX, int *offsetY) { if (_viewportSP >= 0) { - if (offsetX) *offsetX = _viewportStack[_viewportSP]->_offsetX; - if (offsetY) *offsetY = _viewportStack[_viewportSP]->_offsetY; + if (offsetX) { + *offsetX = _viewportStack[_viewportSP]->_offsetX; + } + if (offsetY) { + *offsetY = _viewportStack[_viewportSP]->_offsetY; + } } else { - if (offsetX) *offsetX = 0; - if (offsetY) *offsetY = 0; + if (offsetX) { + *offsetX = 0; + } + if (offsetY) { + *offsetY = 0; + } } return STATUS_OK; @@ -3959,7 +4226,9 @@ bool BaseGame::windowScriptMethodHook(UIWindow *win, ScScript *script, ScStack * ////////////////////////////////////////////////////////////////////////// void BaseGame::setInteractive(bool state) { _interactive = state; - if (_transMgr) _transMgr->_origInteractive = state; + if (_transMgr) { + _transMgr->_origInteractive = state; + } } @@ -3983,7 +4252,9 @@ bool BaseGame::displayContent(bool doUpdate, bool displayAll) { bool BaseGame::displayContentSimple() { // fill black _renderer->fill(0, 0, 0); - if (_indicatorDisplay) displayIndicator(); + if (_indicatorDisplay) { + displayIndicator(); + } return STATUS_OK; } @@ -3994,14 +4265,20 @@ bool BaseGame::displayIndicator() { if (_saveLoadImage) { Rect32 rc; BasePlatform::setRect(&rc, 0, 0, _saveLoadImage->getWidth(), _saveLoadImage->getHeight()); - if (_loadInProgress) _saveLoadImage->displayTrans(_loadImageX, _loadImageY, rc); - else _saveLoadImage->displayTrans(_saveImageX, _saveImageY, rc); + if (_loadInProgress) { + _saveLoadImage->displayTrans(_loadImageX, _loadImageY, rc); + } else { + _saveLoadImage->displayTrans(_saveImageX, _saveImageY, rc); + } } - if ((!_indicatorDisplay && _indicatorWidth <= 0) || _indicatorHeight <= 0) return STATUS_OK; + if ((!_indicatorDisplay && _indicatorWidth <= 0) || _indicatorHeight <= 0) { + return STATUS_OK; + } _renderer->setupLines(); - for (int i = 0; i < _indicatorHeight; i++) + for (int i = 0; i < _indicatorHeight; i++) { _renderer->drawLine(_indicatorX, _indicatorY + i, _indicatorX + (int)(_indicatorWidth * (float)((float)_indicatorProgress / 100.0f)), _indicatorY + i, _indicatorColor); + } _renderer->setup2D(); return STATUS_OK; @@ -4011,8 +4288,12 @@ bool BaseGame::displayIndicator() { bool BaseGame::updateMusicCrossfade() { /* byte GlobMusicVol = _soundMgr->getVolumePercent(SOUND_MUSIC); */ - if (!_musicCrossfadeRunning) return STATUS_OK; - if (_state == GAME_FROZEN) return STATUS_OK; + if (!_musicCrossfadeRunning) { + return STATUS_OK; + } + if (_state == GAME_FROZEN) { + return STATUS_OK; + } if (_musicCrossfadeChannel1 < 0 || _musicCrossfadeChannel1 >= NUM_MUSIC_CHANNELS || !_music[_musicCrossfadeChannel1]) { _musicCrossfadeRunning = false; @@ -4023,8 +4304,12 @@ bool BaseGame::updateMusicCrossfade() { return STATUS_OK; } - if (!_music[_musicCrossfadeChannel1]->isPlaying()) _music[_musicCrossfadeChannel1]->play(); - if (!_music[_musicCrossfadeChannel2]->isPlaying()) _music[_musicCrossfadeChannel2]->play(); + if (!_music[_musicCrossfadeChannel1]->isPlaying()) { + _music[_musicCrossfadeChannel1]->play(); + } + if (!_music[_musicCrossfadeChannel2]->isPlaying()) { + _music[_musicCrossfadeChannel2]->play(); + } uint32 currentTime = _gameRef->_liveTimer - _musicCrossfadeStartTime; @@ -4112,19 +4397,27 @@ bool BaseGame::setWaitCursor(const char *filename) { delete _cursorNoninteractive; _cursorNoninteractive = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } } ////////////////////////////////////////////////////////////////////////// bool BaseGame::isVideoPlaying() { - if (_videoPlayer->isPlaying()) return true; - if (_theoraPlayer && _theoraPlayer->isPlaying()) return true; + if (_videoPlayer->isPlaying()) { + return true; + } + if (_theoraPlayer && _theoraPlayer->isPlaying()) { + return true; + } return false; } ////////////////////////////////////////////////////////////////////////// bool BaseGame::stopVideo() { - if (_videoPlayer->isPlaying()) _videoPlayer->stop(); + if (_videoPlayer->isPlaying()) { + _videoPlayer->stop(); + } if (_theoraPlayer && _theoraPlayer->isPlaying()) { _theoraPlayer->stop(); delete _theoraPlayer; @@ -4136,7 +4429,9 @@ bool BaseGame::stopVideo() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::drawCursor(BaseSprite *cursor) { - if (!cursor) return STATUS_FAILED; + if (!cursor) { + return STATUS_FAILED; + } if (cursor != _lastCursor) { cursor->reset(); _lastCursor = cursor; @@ -4148,7 +4443,9 @@ bool BaseGame::drawCursor(BaseSprite *cursor) { ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// bool BaseGame::onActivate(bool activate, bool refreshMouse) { - if (_shuttingDown || !_renderer) return STATUS_OK; + if (_shuttingDown || !_renderer) { + return STATUS_OK; + } _renderer->_active = activate; @@ -4158,15 +4455,20 @@ bool BaseGame::onActivate(bool activate, bool refreshMouse) { setActiveObject(_renderer->getObjectAt(p.x, p.y)); } - if (activate) _soundMgr->resumeAll(); - else _soundMgr->pauseAll(); + if (activate) { + _soundMgr->resumeAll(); + } else { + _soundMgr->pauseAll(); + } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseLeftDown() { - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_LEFT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftClick")); if (!handled) { @@ -4175,7 +4477,9 @@ bool BaseGame::onMouseLeftDown() { } } - if (_activeObject != NULL) _capturedObject = _activeObject; + if (_activeObject != NULL) { + _capturedObject = _activeObject; + } _mouseLeftDown = true; BasePlatform::setCapture(/*_renderer->_window*/); @@ -4184,7 +4488,9 @@ bool BaseGame::onMouseLeftDown() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseLeftUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_LEFT); + } BasePlatform::releaseCapture(); _capturedObject = NULL; @@ -4201,9 +4507,13 @@ bool BaseGame::onMouseLeftUp() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseLeftDblClick() { - if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_LEFT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("LeftDoubleClick")); if (!handled) { @@ -4216,9 +4526,13 @@ bool BaseGame::onMouseLeftDblClick() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseRightDblClick() { - if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_DBLCLICK, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightDoubleClick")); if (!handled) { @@ -4231,7 +4545,9 @@ bool BaseGame::onMouseRightDblClick() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseRightDown() { - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightClick")); if (!handled) { @@ -4244,7 +4560,9 @@ bool BaseGame::onMouseRightDown() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseRightUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_RIGHT); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("RightRelease")); if (!handled) { @@ -4257,9 +4575,13 @@ bool BaseGame::onMouseRightUp() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseMiddleDown() { - if (_state == GAME_RUNNING && !_interactive) return STATUS_OK; + if (_state == GAME_RUNNING && !_interactive) { + return STATUS_OK; + } - if (_activeObject) _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_MIDDLE); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_CLICK, MOUSE_BUTTON_MIDDLE); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("MiddleClick")); if (!handled) { @@ -4272,7 +4594,9 @@ bool BaseGame::onMouseMiddleDown() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onMouseMiddleUp() { - if (_activeObject) _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_MIDDLE); + if (_activeObject) { + _activeObject->handleMouse(MOUSE_RELEASE, MOUSE_BUTTON_MIDDLE); + } bool handled = _state == GAME_RUNNING && DID_SUCCEED(applyEvent("MiddleRelease")); if (!handled) { @@ -4297,9 +4621,13 @@ bool BaseGame::onPaint() { ////////////////////////////////////////////////////////////////////////// bool BaseGame::onWindowClose() { if (canHandleEvent("QuitGame")) { - if (_state != GAME_FROZEN) _gameRef->applyEvent("QuitGame"); + if (_state != GAME_FROZEN) { + _gameRef->applyEvent("QuitGame"); + } return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// @@ -4312,10 +4640,11 @@ bool BaseGame::displayDebugInfo() { } if (_gameRef->_debugDebugMode) { - if (!_gameRef->_renderer->_windowed) + if (!_gameRef->_renderer->_windowed) { sprintf(str, "Mode: %dx%dx%d", _renderer->_width, _renderer->_height, _renderer->_bPP); - else + } else { sprintf(str, "Mode: %dx%d windowed", _renderer->_width, _renderer->_height); + } strcat(str, " ("); strcat(str, _renderer->getName().c_str()); @@ -4333,7 +4662,9 @@ bool BaseGame::displayDebugInfo() { sprintf(str, "Timer: %d", _timer); _gameRef->_systemFont->drawText((byte *)str, 0, 130, _renderer->_width, TAL_RIGHT); - if (_activeObject != NULL) _systemFont->drawText((byte *)_activeObject->getName(), 0, 150, _renderer->_width, TAL_RIGHT); + if (_activeObject != NULL) { + _systemFont->drawText((byte *)_activeObject->getName(), 0, 150, _renderer->_width, TAL_RIGHT); + } sprintf(str, "GfxMem: %dMB", _usedMem / (1024 * 1024)); _systemFont->drawText((byte *)str, 0, 170, _renderer->_width, TAL_RIGHT); @@ -4345,7 +4676,9 @@ bool BaseGame::displayDebugInfo() { ////////////////////////////////////////////////////////////////////////// BaseDebugger *BaseGame::getDebugMgr() { - if (!_debugMgr) _debugMgr = new BaseDebugger(this); + if (!_debugMgr) { + _debugMgr = new BaseDebugger(this); + } return _debugMgr; } @@ -4390,10 +4723,14 @@ void BaseGame::getMousePos(Point32 *pos) { ////////////////////////////////////////////////////////////////////////// bool BaseGame::miniUpdate() { - if (!_miniUpdateEnabled) return STATUS_OK; + if (!_miniUpdateEnabled) { + return STATUS_OK; + } if (g_system->getMillis() - _lastMiniUpdate > 200) { - if (_soundMgr) _soundMgr->initLoop(); + if (_soundMgr) { + _soundMgr->initLoop(); + } _lastMiniUpdate = g_system->getMillis(); } return STATUS_OK; @@ -4443,8 +4780,12 @@ void BaseGame::autoSaveOnExit() { _soundMgr->saveSettings(); _registry->saveValues(); - if (!_autoSaveOnExit) return; - if (_state == GAME_FROZEN) return; + if (!_autoSaveOnExit) { + return; + } + if (_state == GAME_FROZEN) { + return; + } saveGame(_autoSaveSlot, "autosave", true); } diff --git a/engines/wintermute/base/base_keyboard_state.cpp b/engines/wintermute/base/base_keyboard_state.cpp index 03f9929eee..3bad8f6012 100644 --- a/engines/wintermute/base/base_keyboard_state.cpp +++ b/engines/wintermute/base/base_keyboard_state.cpp @@ -84,9 +84,13 @@ bool BaseKeyboardState::scCallMethod(ScScript *script, ScStack *stack, ScStack * if (val->_type == VAL_STRING && strlen(val->getString()) > 0) { const char *str = val->getString(); char temp = str[0]; - if (temp >= 'A' && temp <= 'Z') temp += ('a' - 'A'); + if (temp >= 'A' && temp <= 'Z') { + temp += ('a' - 'A'); + } vKey = (int)temp; - } else vKey = val->getInt(); + } else { + vKey = val->getInt(); + } warning("BKeyboardState doesnt yet have state-support %d", vKey); //TODO; // Uint8 *state = SDL_GetKeyboardState(NULL); @@ -95,9 +99,9 @@ bool BaseKeyboardState::scCallMethod(ScScript *script, ScStack *stack, ScStack * stack->pushBool(isDown); return STATUS_OK; + } else { + return BaseScriptable::scCallMethod(script, stack, thisStack, name); } - - else return BaseScriptable::scCallMethod(script, stack, thisStack, name); } @@ -122,7 +126,9 @@ ScValue *BaseKeyboardState::scGetProperty(const char *name) { key[0] = (char)_currentCharCode; key[1] = '\0'; _scValue->setString(key); - } else _scValue->setString(""); + } else { + _scValue->setString(""); + } return _scValue; } @@ -165,9 +171,9 @@ ScValue *BaseKeyboardState::scGetProperty(const char *name) { else if (strcmp(name, "IsControl") == 0) { _scValue->setBool(_currentControl); return _scValue; + } else { + return BaseScriptable::scGetProperty(name); } - - else return BaseScriptable::scGetProperty(name); } @@ -255,7 +261,9 @@ bool BaseKeyboardState::isAltDown() { ////////////////////////////////////////////////////////////////////////// uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) { - if (event->type != Common::EVENT_KEYDOWN) return 0; + if (event->type != Common::EVENT_KEYDOWN) { + return 0; + } switch (event->kbd.keycode) { case Common::KEYCODE_KP_ENTER: diff --git a/engines/wintermute/base/base_named_object.cpp b/engines/wintermute/base/base_named_object.cpp index 0821c9325b..0873f090d0 100644 --- a/engines/wintermute/base/base_named_object.cpp +++ b/engines/wintermute/base/base_named_object.cpp @@ -58,11 +58,14 @@ void BaseNamedObject::setName(const char *name) { delete[] _name; _name = NULL; - if (name == NULL) + if (name == NULL) { return; + } _name = new char [strlen(name) + 1]; - if (_name != NULL) strcpy(_name, name); + if (_name != NULL) { + strcpy(_name, name); + } } } // end of namespace WinterMute diff --git a/engines/wintermute/base/base_object.cpp b/engines/wintermute/base/base_object.cpp index 44823acf1a..18619616fe 100644 --- a/engines/wintermute/base/base_object.cpp +++ b/engines/wintermute/base/base_object.cpp @@ -85,8 +85,9 @@ BaseObject::BaseObject(BaseGame *inGame): BaseScriptHolder(inGame) { _rotateValid = false; _relativeRotate = 0.0f; - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { _caption[i] = NULL; + } _saveState = true; _nonIntMouseEvents = false; @@ -107,8 +108,9 @@ BaseObject::~BaseObject() { ////////////////////////////////////////////////////////////////////////// bool BaseObject::cleanup() { - if (_gameRef && _gameRef->_activeObject == this) + if (_gameRef && _gameRef->_activeObject == this) { _gameRef->_activeObject = NULL; + } BaseScriptHolder::cleanup(); delete[] _soundEvent; @@ -137,9 +139,12 @@ bool BaseObject::cleanup() { ////////////////////////////////////////////////////////////////////////// void BaseObject::setCaption(const char *caption, int caseVal) { // TODO: rename Case to something usefull - if (caseVal == 0) caseVal = 1; - if (caseVal < 1 || caseVal > 7) + if (caseVal == 0) { + caseVal = 1; + } + if (caseVal < 1 || caseVal > 7) { return; + } delete[] _caption[caseVal - 1]; _caption[caseVal - 1] = new char[strlen(caption) + 1]; @@ -152,10 +157,14 @@ void BaseObject::setCaption(const char *caption, int caseVal) { // TODO: rename ////////////////////////////////////////////////////////////////////////// const char *BaseObject::getCaption(int caseVal) { - if (caseVal == 0) caseVal = 1; - if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) + if (caseVal == 0) { + caseVal = 1; + } + if (caseVal < 1 || caseVal > 7 || _caption[caseVal - 1] == NULL) { return ""; - else return _caption[caseVal - 1]; + } else { + return _caption[caseVal - 1]; + } } @@ -198,8 +207,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetCursor") == 0) { stack->correctParams(1); - if (DID_SUCCEED(setCursor(stack->pop()->getString()))) stack->pushBool(true); - else stack->pushBool(false); + if (DID_SUCCEED(setCursor(stack->pop()->getString()))) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -226,8 +238,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetCursor") == 0) { stack->correctParams(0); - if (!_cursor || !_cursor->getFilename()) stack->pushNULL(); - else stack->pushString(_cursor->getFilename()); + if (!_cursor || !_cursor->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_cursor->getFilename()); + } return STATUS_OK; } @@ -237,8 +252,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetCursorObject") == 0) { stack->correctParams(0); - if (!_cursor) stack->pushNULL(); - else stack->pushNative(_cursor, true); + if (!_cursor) { + stack->pushNULL(); + } else { + stack->pushNative(_cursor, true); + } return STATUS_OK; } @@ -249,8 +267,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "HasCursor") == 0) { stack->correctParams(0); - if (_cursor) stack->pushBool(true); - else stack->pushBool(false); + if (_cursor) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -272,10 +293,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "LoadSound") == 0) { stack->correctParams(1); const char *filename = stack->pop()->getString(); - if (DID_SUCCEED(playSFX(filename, false, false))) + if (DID_SUCCEED(playSFX(filename, false, false))) { stack->pushBool(true); - else + } else { stack->pushBool(false); + } return STATUS_OK; } @@ -299,15 +321,20 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta looping = val1->getBool(); loopStart = val2->getInt(); } else { - if (val1->isNULL()) filename = NULL; - else filename = val1->getString(); + if (val1->isNULL()) { + filename = NULL; + } else { + filename = val1->getString(); + } looping = val2->isNULL() ? false : val2->getBool(); loopStart = val3->getInt(); } - if (DID_FAIL(playSFX(filename, looping, true, NULL, loopStart))) + if (DID_FAIL(playSFX(filename, looping, true, NULL, loopStart))) { stack->pushBool(false); - else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -331,8 +358,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta eventName = val2->getString(); } - if (DID_FAIL(playSFX(filename, false, true, eventName))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(playSFX(filename, false, true, eventName))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -342,8 +372,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "StopSound") == 0) { stack->correctParams(0); - if (DID_FAIL(stopSFX())) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(stopSFX())) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -353,8 +386,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "PauseSound") == 0) { stack->correctParams(0); - if (DID_FAIL(pauseSFX())) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(pauseSFX())) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -364,8 +400,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "ResumeSound") == 0) { stack->correctParams(0); - if (DID_FAIL(resumeSFX())) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(resumeSFX())) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -375,8 +414,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "IsSoundPlaying") == 0) { stack->correctParams(0); - if (_sFX && _sFX->isPlaying()) stack->pushBool(true); - else stack->pushBool(false); + if (_sFX && _sFX->isPlaying()) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -387,8 +429,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta stack->correctParams(1); uint32 Time = stack->pop()->getInt(); - if (DID_FAIL(setSFXTime(Time))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(setSFXTime(Time))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -398,8 +443,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "GetSoundPosition") == 0) { stack->correctParams(0); - if (!_sFX) stack->pushInt(0); - else stack->pushInt(_sFX->getPositionTime()); + if (!_sFX) { + stack->pushInt(0); + } else { + stack->pushInt(_sFX->getPositionTime()); + } return STATUS_OK; } @@ -410,8 +458,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta stack->correctParams(1); int volume = stack->pop()->getInt(); - if (DID_FAIL(setSFXVolume(volume))) stack->pushBool(false); - else stack->pushBool(true); + if (DID_FAIL(setSFXVolume(volume))) { + stack->pushBool(false); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -421,8 +472,11 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "GetSoundVolume") == 0) { stack->correctParams(0); - if (!_sFX) stack->pushInt(_sFXVolume); - else stack->pushInt(_sFX->getVolumePercent()); + if (!_sFX) { + stack->pushInt(_sFXVolume); + } else { + stack->pushInt(_sFX->getVolumePercent()); + } return STATUS_OK; } @@ -470,9 +524,9 @@ bool BaseObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta stack->pushNULL(); return STATUS_OK; + } else { + return BaseScriptHolder::scCallMethod(script, stack, thisStack, name); } - - else return BaseScriptHolder::scCallMethod(script, stack, thisStack, name); } @@ -578,8 +632,11 @@ ScValue *BaseObject::scGetProperty(const char *name) { // Scale ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Scale") == 0) { - if (_scale < 0) _scValue->setNULL(); - else _scValue->setFloat((double)_scale); + if (_scale < 0) { + _scValue->setNULL(); + } else { + _scValue->setFloat((double)_scale); + } return _scValue; } @@ -587,8 +644,11 @@ ScValue *BaseObject::scGetProperty(const char *name) { // ScaleX ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ScaleX") == 0) { - if (_scaleX < 0) _scValue->setNULL(); - else _scValue->setFloat((double)_scaleX); + if (_scaleX < 0) { + _scValue->setNULL(); + } else { + _scValue->setFloat((double)_scaleX); + } return _scValue; } @@ -596,8 +656,11 @@ ScValue *BaseObject::scGetProperty(const char *name) { // ScaleY ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ScaleY") == 0) { - if (_scaleY < 0) _scValue->setNULL(); - else _scValue->setFloat((double)_scaleY); + if (_scaleY < 0) { + _scValue->setNULL(); + } else { + _scValue->setFloat((double)_scaleY); + } return _scValue; } @@ -613,8 +676,11 @@ ScValue *BaseObject::scGetProperty(const char *name) { // Rotate ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Rotate") == 0) { - if (!_rotateValid) _scValue->setNULL(); - else _scValue->setFloat((double)_rotate); + if (!_rotateValid) { + _scValue->setNULL(); + } else { + _scValue->setFloat((double)_rotate); + } return _scValue; } @@ -663,9 +729,9 @@ ScValue *BaseObject::scGetProperty(const char *name) { else if (strcmp(name, "AccCaption") == 0) { _scValue->setNULL(); return _scValue; + } else { + return BaseScriptHolder::scGetProperty(name); } - - else return BaseScriptHolder::scGetProperty(name); } @@ -742,7 +808,9 @@ bool BaseObject::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "BlendMode") == 0) { int i = value->getInt(); - if (i < BLEND_NORMAL || i >= NUM_BLEND_MODES) i = BLEND_NORMAL; + if (i < BLEND_NORMAL || i >= NUM_BLEND_MODES) { + i = BLEND_NORMAL; + } _blendMode = (TSpriteBlendMode)i; return STATUS_OK; } @@ -751,8 +819,11 @@ bool BaseObject::scSetProperty(const char *name, ScValue *value) { // Scale ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Scale") == 0) { - if (value->isNULL()) _scale = -1; - else _scale = (float)value->getFloat(); + if (value->isNULL()) { + _scale = -1; + } else { + _scale = (float)value->getFloat(); + } return STATUS_OK; } @@ -760,8 +831,11 @@ bool BaseObject::scSetProperty(const char *name, ScValue *value) { // ScaleX ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ScaleX") == 0) { - if (value->isNULL()) _scaleX = -1; - else _scaleX = (float)value->getFloat(); + if (value->isNULL()) { + _scaleX = -1; + } else { + _scaleX = (float)value->getFloat(); + } return STATUS_OK; } @@ -769,8 +843,11 @@ bool BaseObject::scSetProperty(const char *name, ScValue *value) { // ScaleY ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "ScaleY") == 0) { - if (value->isNULL()) _scaleY = -1; - else _scaleY = (float)value->getFloat(); + if (value->isNULL()) { + _scaleY = -1; + } else { + _scaleY = (float)value->getFloat(); + } return STATUS_OK; } @@ -817,7 +894,9 @@ bool BaseObject::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SoundPanning") == 0) { _autoSoundPanning = value->getBool(); - if (!_autoSoundPanning) resetSoundPan(); + if (!_autoSoundPanning) { + resetSoundPan(); + } return STATUS_OK; } @@ -842,9 +921,9 @@ bool BaseObject::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "AccCaption") == 0) { return STATUS_OK; + } else { + return BaseScriptHolder::scSetProperty(name, value); } - - else return BaseScriptHolder::scSetProperty(name, value); } @@ -856,8 +935,11 @@ const char *BaseObject::scToString() { ////////////////////////////////////////////////////////////////////////// bool BaseObject::showCursor() { - if (_cursor) return _gameRef->drawCursor(_cursor); - else return STATUS_FAILED; + if (_cursor) { + return _gameRef->drawCursor(_cursor); + } else { + return STATUS_FAILED; + } } @@ -871,8 +953,9 @@ bool BaseObject::saveAsText(BaseDynamicBuffer *buffer, int indent) { bool BaseObject::persist(BasePersistenceManager *persistMgr) { BaseScriptHolder::persist(persistMgr); - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { persistMgr->transfer(TMEMBER(_caption[i])); + } persistMgr->transfer(TMEMBER(_activeCursor)); persistMgr->transfer(TMEMBER(_alphaColor)); persistMgr->transfer(TMEMBER(_autoSoundPanning)); @@ -936,7 +1019,9 @@ bool BaseObject::setCursor(const char *filename) { delete _cursor; _cursor = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } } @@ -948,7 +1033,9 @@ bool BaseObject::setActiveCursor(const char *filename) { delete _activeCursor; _activeCursor = NULL; return STATUS_FAILED; - } else return STATUS_OK; + } else { + return STATUS_OK; + } } @@ -983,16 +1070,24 @@ bool BaseObject::playSFX(const char *filename, bool looping, bool playNow, const if (_gameRef->_editorMode || _sFXStart) { _sFX->setVolumePercent(_sFXVolume); _sFX->setPositionTime(_sFXStart); - if (!_gameRef->_editorMode) _sFXStart = 0; + if (!_gameRef->_editorMode) { + _sFXStart = 0; + } } if (playNow) { setSoundEvent(eventName); - if (loopStart) _sFX->setLoopStart(loopStart); + if (loopStart) { + _sFX->setLoopStart(loopStart); + } return _sFX->play(looping); - } else return STATUS_OK; + } else { + return STATUS_OK; + } } - if (filename == NULL) return STATUS_FAILED; + if (filename == NULL) { + return STATUS_FAILED; + } // create new sound delete _sFX; @@ -1007,9 +1102,13 @@ bool BaseObject::playSFX(const char *filename, bool looping, bool playNow, const _sFX->ApplyFX(_sFXType, _sFXParam1, _sFXParam2, _sFXParam3, _sFXParam4); if (playNow) { setSoundEvent(eventName); - if (loopStart) _sFX->setLoopStart(loopStart); + if (loopStart) { + _sFX->setLoopStart(loopStart); + } return _sFX->play(looping); - } else return STATUS_OK; + } else { + return STATUS_OK; + } } else { delete _sFX; _sFX = NULL; @@ -1027,37 +1126,51 @@ bool BaseObject::stopSFX(bool deleteSound) { _sFX = NULL; } return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// bool BaseObject::pauseSFX() { - if (_sFX) return _sFX->pause(); - else return STATUS_FAILED; + if (_sFX) { + return _sFX->pause(); + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// bool BaseObject::resumeSFX() { - if (_sFX) return _sFX->resume(); - else return STATUS_FAILED; + if (_sFX) { + return _sFX->resume(); + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// bool BaseObject::setSFXTime(uint32 time) { _sFXStart = time; - if (_sFX && _sFX->isPlaying()) return _sFX->setPositionTime(time); - else return STATUS_OK; + if (_sFX && _sFX->isPlaying()) { + return _sFX->setPositionTime(time); + } else { + return STATUS_OK; + } } ////////////////////////////////////////////////////////////////////////// bool BaseObject::setSFXVolume(int volume) { _sFXVolume = volume; - if (_sFX) return _sFX->setVolumePercent(volume); - else return STATUS_OK; + if (_sFX) { + return _sFX->setVolumePercent(volume); + } else { + return STATUS_OK; + } } @@ -1070,7 +1183,9 @@ bool BaseObject::updateSounds() { } } - if (_sFX) updateOneSound(_sFX); + if (_sFX) { + updateOneSound(_sFX); + } return STATUS_OK; } @@ -1080,8 +1195,9 @@ bool BaseObject::updateOneSound(BaseSound *sound) { bool Ret = STATUS_OK; if (sound) { - if (_autoSoundPanning) + if (_autoSoundPanning) { Ret = sound->setPan(_gameRef->_soundMgr->posToPan(_posX - _gameRef->_offsetX, _posY - _gameRef->_offsetY)); + } Ret = sound->ApplyFX(_sFXType, _sFXParam1, _sFXParam2, _sFXParam3, _sFXParam4); } @@ -1090,8 +1206,9 @@ bool BaseObject::updateOneSound(BaseSound *sound) { ////////////////////////////////////////////////////////////////////////// bool BaseObject::resetSoundPan() { - if (!_sFX) return STATUS_OK; - else { + if (!_sFX) { + return STATUS_OK; + } else { return _sFX->setPan(0.0f); } } @@ -1115,7 +1232,9 @@ void BaseObject::setSoundEvent(const char *eventName) { _soundEvent = NULL; if (eventName) { _soundEvent = new char[strlen(eventName) + 1]; - if (_soundEvent) strcpy(_soundEvent, eventName); + if (_soundEvent) { + strcpy(_soundEvent, eventName); + } } } diff --git a/engines/wintermute/base/base_parser.cpp b/engines/wintermute/base/base_parser.cpp index 12ed67ba2a..98d77f4ed5 100644 --- a/engines/wintermute/base/base_parser.cpp +++ b/engines/wintermute/base/base_parser.cpp @@ -50,7 +50,9 @@ BaseParser::BaseParser(BaseGame *inGame): BaseClass(inGame) { ////////////////////////////////////////////////////////////////////// BaseParser::~BaseParser() { - if (_whiteSpace != NULL) delete[] _whiteSpace; + if (_whiteSpace != NULL) { + delete[] _whiteSpace; + } } @@ -71,8 +73,9 @@ int32 BaseParser::getObject(char **buf, TokenDesc *tokens, char **name, char **d skipCharacters(buf, _whiteSpace); } - if (! **buf) // at end of file + if (! **buf) { // at end of file return PARSERR_EOF; + } // find the token. // for now just use brute force. Improve later. @@ -89,7 +92,9 @@ int32 BaseParser::getObject(char **buf, TokenDesc *tokens, char **name, char **d char *p = strchr(*buf, '\n'); if (p && p > *buf) { strncpy(_lastOffender, *buf, MIN((uint32)255, (uint32)(p - *buf))); // TODO, clean - } else strcpy(_lastOffender, ""); + } else { + strcpy(_lastOffender, ""); + } return PARSERR_TOKENNOTFOUND; } @@ -102,10 +107,11 @@ int32 BaseParser::getObject(char **buf, TokenDesc *tokens, char **name, char **d skipCharacters(buf, _whiteSpace); // get optional data - if (**buf == '=') // An assignment rather than a command/object. + if (**buf == '=') { // An assignment rather than a command/object. *data = getAssignmentText(buf); - else + } else { *data = getSubText(buf, '{', '}'); + } return tokens->id; } @@ -113,7 +119,9 @@ int32 BaseParser::getObject(char **buf, TokenDesc *tokens, char **name, char **d ////////////////////////////////////////////////////////////////////// int32 BaseParser::getCommand(char **buf, TokenDesc *tokens, char **params) { - if (!*buf) return PARSERR_TOKENNOTFOUND; + if (!*buf) { + return PARSERR_TOKENNOTFOUND; + } _gameRef->miniUpdate(); char *name; return getObject(buf, tokens, &name, params); @@ -124,9 +132,12 @@ int32 BaseParser::getCommand(char **buf, TokenDesc *tokens, char **params) { void BaseParser::skipCharacters(char **buf, const char *toSkip) { char ch; while ((ch = **buf) != 0) { - if (ch == '\n') _parserLine++; - if (strchr(toSkip, ch) == NULL) + if (ch == '\n') { + _parserLine++; + } + if (strchr(toSkip, ch) == NULL) { return; + } ++*buf; // skip this character } // we must be at the end of the buffer if we get here @@ -135,8 +146,9 @@ void BaseParser::skipCharacters(char **buf, const char *toSkip) { ////////////////////////////////////////////////////////////////////// char *BaseParser::getSubText(char **buf, char open, char close) { - if (**buf == 0 || **buf != open) + if (**buf == 0 || **buf != open) { return 0; + } ++*buf; // skip opening delimiter char *result = *buf; @@ -144,11 +156,13 @@ char *BaseParser::getSubText(char **buf, char open, char close) { char theChar; long skip = 1; - if (open == close) // we cant nest identical delimiters + if (open == close) { // we cant nest identical delimiters open = 0; + } while ((theChar = **buf) != 0) { - if (theChar == open) + if (theChar == open) { ++skip; + } if (theChar == close) { if (--skip == 0) { **buf = 0; // null terminate the result string @@ -176,13 +190,15 @@ char *BaseParser::getAssignmentText(char **buf) { char theChar; while ((theChar = **buf) != 0) { - if (theChar <= 0x20) // space and control chars + if (theChar <= 0x20) { // space and control chars break; + } ++*buf; } - **buf = 0; // null terminate it - if (theChar) // skip the terminator + **buf = 0; // null terminate it + if (theChar) { // skip the terminator ++*buf; + } } return result; @@ -195,10 +211,16 @@ char *BaseParser::getToken(char **buf) { static char token[100]; char *b = *buf, * t = token; while (true) { - while (*b && (*b == ' ' || *b == '\n' || *b == 13 || *b == 10 || *b == '\t')) b++; + while (*b && (*b == ' ' || *b == '\n' || *b == 13 || *b == 10 || *b == '\t')) { + b++; + } if (*b == ';') - while (*b && *b != '\n' && *b != 13 && *b != 10) b++; - else break; + while (*b && *b != '\n' && *b != 13 && *b != 10) { + b++; + } + else { + break; + } } if (*b == '\'') { @@ -207,7 +229,9 @@ char *BaseParser::getToken(char **buf) { *t++ = *b++; } *t++ = 0; - if (*b == '\'') b++; + if (*b == '\'') { + b++; + } } else if (*b == '(' || *b == ')' || *b == '=' || *b == ',' || *b == '[' || *b == ']' || *b == '%' || *b == ':' || *b == '{' || *b == '}') { *t++ = *b++; @@ -265,7 +289,9 @@ int BaseParser::getTokenInt(char **buf) { ////////////////////////////////////////////////////////////////////// void BaseParser::skipToken(char **buf, char *tok, char * /*msg*/) { char *t = getToken(buf); - if (strcmp(t, tok)) return; // Error + if (strcmp(t, tok)) { + return; // Error + } } @@ -299,7 +325,9 @@ int BaseParser::scanStr(const char *in, const char *format, ...) { list[i++] = atoi(in); in += strspn(in, "0123456789+-"); in += strspn(in, " \t\n\f"); - if (*in != ',') break; + if (*in != ',') { + break; + } in++; in += strspn(in, " \t\n\f"); } @@ -339,7 +367,9 @@ int BaseParser::scanStr(const char *in, const char *format, ...) { list[i++] = (float)atof(in); in += strspn(in, "0123456789.eE+-"); in += strspn(in, " \t\n\f"); - if (*in != ',') break; + if (*in != ',') { + break; + } in++; in += strspn(in, " \t\n\f"); } @@ -414,7 +444,9 @@ int BaseParser::scanStr(const char *in, const char *format, ...) { break; } } - if (*format) format++; + if (*format) { + format++; + } } else if (*format == ' ') { format++; in += strspn(in, " \t\n\f"); diff --git a/engines/wintermute/base/base_persistence_manager.cpp b/engines/wintermute/base/base_persistence_manager.cpp index cf7deb2970..d8f928b683 100644 --- a/engines/wintermute/base/base_persistence_manager.cpp +++ b/engines/wintermute/base/base_persistence_manager.cpp @@ -181,7 +181,9 @@ bool BasePersistenceManager::getSaveExists(int slot) { ////////////////////////////////////////////////////////////////////////// bool BasePersistenceManager::initSave(const char *desc) { - if (!desc) return STATUS_FAILED; + if (!desc) { + return STATUS_FAILED; + } cleanup(); _saving = true; @@ -232,7 +234,9 @@ bool BasePersistenceManager::initSave(const char *desc) { thumbnailOK = true; } } - if (!thumbnailOK) putDWORD(0); + if (!thumbnailOK) { + putDWORD(0); + } // in any case, destroy the cached thumbnail once used delete _gameRef->_cachedThumbnail; @@ -288,9 +292,13 @@ bool BasePersistenceManager::readHeader(const Common::String &filename) { _thumbnailData = new byte[_thumbnailDataSize]; if (_thumbnailData) { getBytes(_thumbnailData, _thumbnailDataSize); - } else _thumbnailDataSize = 0; + } else { + _thumbnailDataSize = 0; + } } - } else _savedVerBuild = 35; // last build with ver1 savegames + } else { + _savedVerBuild = 35; // last build with ver1 savegames + } uint32 dataOffset = getDWORD(); @@ -379,16 +387,18 @@ bool BasePersistenceManager::saveFile(const Common::String &filename) { ////////////////////////////////////////////////////////////////////////// bool BasePersistenceManager::putBytes(byte *buffer, uint32 size) { _saveStream->write(buffer, size); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// bool BasePersistenceManager::getBytes(byte *buffer, uint32 size) { _loadStream->read(buffer, size); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } @@ -407,8 +417,9 @@ uint32 BasePersistenceManager::getDWORD() { ////////////////////////////////////////////////////////////////////////// void BasePersistenceManager::putString(const Common::String &val) { - if (!val.size()) putString("(null)"); - else { + if (!val.size()) { + putString("(null)"); + } else { _saveStream->writeUint32LE(val.size()); _saveStream->writeString(val); } @@ -440,7 +451,9 @@ char *BasePersistenceManager::getString() { if (!strcmp(ret, "(null)")) { delete[] ret; return NULL; - } else return ret; + } else { + return ret; + } } bool BasePersistenceManager::putTimeDate(const TimeDate &t) { @@ -510,13 +523,15 @@ double BasePersistenceManager::getDouble() { bool BasePersistenceManager::transfer(const char *name, bool *val) { if (_saving) { _saveStream->writeByte(*val); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { *val = _loadStream->readByte(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -527,13 +542,15 @@ bool BasePersistenceManager::transfer(const char *name, bool *val) { bool BasePersistenceManager::transfer(const char *name, int *val) { if (_saving) { _saveStream->writeSint32LE(*val); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { *val = _loadStream->readSint32LE(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -544,13 +561,15 @@ bool BasePersistenceManager::transfer(const char *name, int *val) { bool BasePersistenceManager::transfer(const char *name, uint32 *val) { if (_saving) { _saveStream->writeUint32LE(*val); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { *val = _loadStream->readUint32LE(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -561,13 +580,15 @@ bool BasePersistenceManager::transfer(const char *name, uint32 *val) { bool BasePersistenceManager::transfer(const char *name, float *val) { if (_saving) { putFloat(*val); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { *val = getFloat(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -578,13 +599,15 @@ bool BasePersistenceManager::transfer(const char *name, float *val) { bool BasePersistenceManager::transfer(const char *name, double *val) { if (_saving) { putDouble(*val); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { *val = getDouble(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -667,7 +690,9 @@ bool BasePersistenceManager::transfer(const char *name, AnsiStringArray &val) { delete[] str; return STATUS_FAILED; } - if (str) val.push_back(str); + if (str) { + val.push_back(str); + } delete[] str; } } @@ -680,13 +705,15 @@ bool BasePersistenceManager::transfer(const char *name, AnsiStringArray &val) { bool BasePersistenceManager::transfer(const char *name, byte *val) { if (_saving) { _saveStream->writeByte(*val); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { *val = _loadStream->readByte(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -700,16 +727,18 @@ bool BasePersistenceManager::transfer(const char *name, Rect32 *val) { _saveStream->writeSint32LE(val->top); _saveStream->writeSint32LE(val->right); _saveStream->writeSint32LE(val->bottom); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { val->left = _loadStream->readSint32LE(); val->top = _loadStream->readSint32LE(); val->right = _loadStream->readSint32LE(); val->bottom = _loadStream->readSint32LE(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -721,14 +750,16 @@ bool BasePersistenceManager::transfer(const char *name, Point32 *val) { if (_saving) { _saveStream->writeSint32LE(val->x); _saveStream->writeSint32LE(val->y); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { val->x = _loadStream->readSint32LE(); val->y = _loadStream->readSint32LE(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -740,14 +771,16 @@ bool BasePersistenceManager::transfer(const char *name, Vector2 *val) { if (_saving) { putFloat(val->x); putFloat(val->y); - if (_saveStream->err()) + if (_saveStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } else { val->x = getFloat(); val->y = getFloat(); - if (_loadStream->err()) + if (_loadStream->err()) { return STATUS_FAILED; + } return STATUS_OK; } } @@ -779,13 +812,17 @@ bool BasePersistenceManager::transfer(const char *name, void *val) { ////////////////////////////////////////////////////////////////////////// bool BasePersistenceManager::checkVersion(byte verMajor, byte verMinor, byte verBuild) { - if (_saving) return true; + if (_saving) { + return true; + } // it's ok if we are same or newer than the saved game if (verMajor > _savedVerMajor || (verMajor == _savedVerMajor && verMinor > _savedVerMinor) || (verMajor == _savedVerMajor && verMinor == _savedVerMinor && verBuild > _savedVerBuild) - ) return false; + ) { + return false; + } return true; } diff --git a/engines/wintermute/base/base_quick_msg.cpp b/engines/wintermute/base/base_quick_msg.cpp index d672e39c6b..bf38adb578 100644 --- a/engines/wintermute/base/base_quick_msg.cpp +++ b/engines/wintermute/base/base_quick_msg.cpp @@ -34,14 +34,18 @@ namespace WinterMute { ////////////////////////////////////////////////////////////////////////// BaseQuickMsg::BaseQuickMsg(BaseGame *inGame, const char *text): BaseClass(inGame) { _text = new char [strlen(text) + 1]; - if (_text) strcpy(_text, text); + if (_text) { + strcpy(_text, text); + } _startTime = _gameRef->_currentTime; } ////////////////////////////////////////////////////////////////////////// BaseQuickMsg::~BaseQuickMsg() { - if (_text) delete[] _text; + if (_text) { + delete[] _text; + } } diff --git a/engines/wintermute/base/base_region.cpp b/engines/wintermute/base/base_region.cpp index f88de2ab91..67cda44ece 100644 --- a/engines/wintermute/base/base_region.cpp +++ b/engines/wintermute/base/base_region.cpp @@ -60,7 +60,9 @@ BaseRegion::~BaseRegion() { ////////////////////////////////////////////////////////////////////////// void BaseRegion::cleanup() { - for (int i = 0; i < _points.getSize(); i++) delete _points[i]; + for (int i = 0; i < _points.getSize(); i++) { + delete _points[i]; + } _points.removeAll(); BasePlatform::setRectEmpty(&_rect); @@ -76,7 +78,9 @@ bool BaseRegion::createRegion() { ////////////////////////////////////////////////////////////////////////// bool BaseRegion::pointInRegion(int x, int y) { - if (_points.getSize() < 3) return false; + if (_points.getSize() < 3) { + return false; + } Point32 pt; pt.x = x; @@ -88,8 +92,11 @@ bool BaseRegion::pointInRegion(int x, int y) { rect.top = y - 1; rect.bottom = y + 2; - if (BasePlatform::ptInRect(&_rect, pt)) return ptInPolygon(x, y); - else return false; + if (BasePlatform::ptInRect(&_rect, pt)) { + return ptInPolygon(x, y); + } else { + return false; + } } @@ -105,7 +112,9 @@ bool BaseRegion::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing REGION file '%s'", filename); + } delete[] buffer; @@ -153,13 +162,17 @@ bool BaseRegion::loadBuffer(byte *buffer, bool complete) { int i; - for (i = 0; i < _points.getSize(); i++) delete _points[i]; + for (i = 0; i < _points.getSize(); i++) { + delete _points[i]; + } _points.removeAll(); while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -240,7 +253,9 @@ bool BaseRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta createRegion(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -260,7 +275,9 @@ bool BaseRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta createRegion(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -280,7 +297,9 @@ bool BaseRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta createRegion(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -298,12 +317,14 @@ bool BaseRegion::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta val->setProperty("X", _points[index]->x); val->setProperty("Y", _points[index]->y); } - } else stack->pushNULL(); + } else { + stack->pushNULL(); + } return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -341,9 +362,9 @@ ScValue *BaseRegion::scGetProperty(const char *name) { else if (strcmp(name, "NumPoints") == 0) { _scValue->setInt(_points.getSize()); return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -363,9 +384,9 @@ bool BaseRegion::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "Active") == 0) { _active = value->getBool(); return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -377,8 +398,11 @@ const char *BaseRegion::scToString() { ////////////////////////////////////////////////////////////////////////// bool BaseRegion::saveAsText(BaseDynamicBuffer *buffer, int indent, const char *nameOverride) { - if (!nameOverride) buffer->putTextIndent(indent, "REGION {\n"); - else buffer->putTextIndent(indent, "%s {\n", nameOverride); + if (!nameOverride) { + buffer->putTextIndent(indent, "REGION {\n"); + } else { + buffer->putTextIndent(indent, "%s {\n", nameOverride); + } buffer->putTextIndent(indent + 2, "NAME=\"%s\"\n", getName()); buffer->putTextIndent(indent + 2, "CAPTION=\"%s\"\n", getCaption()); @@ -395,7 +419,9 @@ bool BaseRegion::saveAsText(BaseDynamicBuffer *buffer, int indent, const char *n buffer->putTextIndent(indent + 2, "POINT {%d,%d}\n", _points[i]->x, _points[i]->y); } - if (_scProp) _scProp->saveAsText(buffer, indent + 2); + if (_scProp) { + _scProp->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent, "}\n\n"); @@ -425,7 +451,9 @@ typedef struct { ////////////////////////////////////////////////////////////////////////// bool BaseRegion::ptInPolygon(int x, int y) { - if (_points.getSize() < 3) return false; + if (_points.getSize() < 3) { + return false; + } int counter = 0; double xinters; @@ -446,8 +474,9 @@ bool BaseRegion::ptInPolygon(int x, int y) { if (p.x <= MAX(p1.x, p2.x)) { if (p1.y != p2.y) { xinters = (p.y - p1.y) * (p2.x - p1.x) / (p2.y - p1.y) + p1.x; - if (p1.x == p2.x || p.x <= xinters) + if (p1.x == p2.x || p.x <= xinters) { counter++; + } } } } @@ -455,17 +484,19 @@ bool BaseRegion::ptInPolygon(int x, int y) { p1 = p2; } - if (counter % 2 == 0) + if (counter % 2 == 0) { return false; - else + } else { return true; + } } ////////////////////////////////////////////////////////////////////////// bool BaseRegion::getBoundingRect(Rect32 *rect) { - if (_points.getSize() == 0) BasePlatform::setRectEmpty(rect); - else { + if (_points.getSize() == 0) { + BasePlatform::setRectEmpty(rect); + } else { int MinX = INT_MAX, MinY = INT_MAX, MaxX = INT_MIN, MaxY = INT_MIN; for (int i = 0; i < _points.getSize(); i++) { @@ -483,7 +514,9 @@ bool BaseRegion::getBoundingRect(Rect32 *rect) { ////////////////////////////////////////////////////////////////////////// bool BaseRegion::mimic(BaseRegion *region, float scale, int x, int y) { - if (scale == _lastMimicScale && x == _lastMimicX && y == _lastMimicY) return STATUS_OK; + if (scale == _lastMimicScale && x == _lastMimicX && y == _lastMimicY) { + return STATUS_OK; + } cleanup(); diff --git a/engines/wintermute/base/base_registry.cpp b/engines/wintermute/base/base_registry.cpp index 7eb2685746..441d00c05b 100644 --- a/engines/wintermute/base/base_registry.cpp +++ b/engines/wintermute/base/base_registry.cpp @@ -61,8 +61,12 @@ AnsiString BaseRegistry::readString(const AnsiString &subKey, const AnsiString & bool found = false; ret = getValue(_localValues, subKey, key, found); - if (!found) ret = getValue(_values, subKey, key, found); - if (!found) ret = init; + if (!found) { + ret = getValue(_values, subKey, key, found); + } + if (!found) { + ret = init; + } return ret; } @@ -105,8 +109,11 @@ int BaseRegistry::readInt(const AnsiString &subKey, const AnsiString &key, int i } } AnsiString val = readString(subKey, key, ""); - if (val.empty()) return init; - else return atoi(val.c_str()); + if (val.empty()) { + return init; + } else { + return atoi(val.c_str()); + } } @@ -166,8 +173,11 @@ char *BaseRegistry::getIniName() { ////////////////////////////////////////////////////////////////////////// void BaseRegistry::loadValues(bool local) { - if (local) loadXml("settings.xml", _localValues); - else loadXml(PathUtil::combine(_gameRef->getDataDir(), "settings.xml"), _values); + if (local) { + loadXml("settings.xml", _localValues); + } else { + loadXml(PathUtil::combine(_gameRef->getDataDir(), "settings.xml"), _values); + } } ////////////////////////////////////////////////////////////////////////// @@ -186,12 +196,15 @@ void BaseRegistry::setBasePath(const char *basePath) { AnsiString BaseRegistry::getValue(PathValueMap &values, const AnsiString path, const AnsiString &key, bool &found) { found = false; PathValueMap::iterator it = values.find(path); - if (it == values.end()) return ""; + if (it == values.end()) { + return ""; + } KeyValuePair pairs = (*it)._value; KeyValuePair::iterator keyIt = pairs.find(key); - if (keyIt == pairs.end()) return ""; - else { + if (keyIt == pairs.end()) { + return ""; + } else { found = true; return (*keyIt)._value; } @@ -200,11 +213,14 @@ AnsiString BaseRegistry::getValue(PathValueMap &values, const AnsiString path, c ////////////////////////////////////////////////////////////////////////// void BaseRegistry::loadXml(const AnsiString fileName, PathValueMap &values) { TiXmlDocument doc(fileName.c_str()); - if (!doc.LoadFile()) return; + if (!doc.LoadFile()) { + return; + } TiXmlElement *rootElem = doc.RootElement(); - if (!rootElem || Common::String(rootElem->Value()) != "Settings") // TODO: Avoid this strcmp-use. (Hack for now, since we might drop TinyXML all together) + if (!rootElem || Common::String(rootElem->Value()) != "Settings") { // TODO: Avoid this strcmp-use. (Hack for now, since we might drop TinyXML all together) return; + } for (TiXmlElement *pathElem = rootElem->FirstChildElement(); pathElem != NULL; pathElem = pathElem->NextSiblingElement()) { for (TiXmlElement *keyElem = pathElem->FirstChildElement(); keyElem != NULL; keyElem = keyElem->NextSiblingElement()) { @@ -247,8 +263,9 @@ void BaseRegistry::saveXml(const AnsiString fileName, PathValueMap &values) { Common::DumpFile stream; stream.open(fileName.c_str()); - if (!stream.isOpen()) return; - else { + if (!stream.isOpen()) { + return; + } else { stream.write(printer.CStr(), printer.Size()); stream.close(); } diff --git a/engines/wintermute/base/base_save_thumb_helper.cpp b/engines/wintermute/base/base_save_thumb_helper.cpp index b63f280f05..5007b65422 100644 --- a/engines/wintermute/base/base_save_thumb_helper.cpp +++ b/engines/wintermute/base/base_save_thumb_helper.cpp @@ -60,7 +60,9 @@ bool BaseSaveThumbHelper::storeThumbnail(bool doFlip) { } BaseImage *screenshot = _gameRef->_renderer->takeScreenshot(); - if (!screenshot) return STATUS_FAILED; + if (!screenshot) { + return STATUS_FAILED; + } // normal thumbnail if (_gameRef->_thumbnailWidth > 0 && _gameRef->_thumbnailHeight > 0) { diff --git a/engines/wintermute/base/base_script_holder.cpp b/engines/wintermute/base/base_script_holder.cpp index d274f9df73..b90b4dc60a 100644 --- a/engines/wintermute/base/base_script_holder.cpp +++ b/engines/wintermute/base/base_script_holder.cpp @@ -75,10 +75,13 @@ void BaseScriptHolder::setFilename(const char *filename) { delete[] _filename; _filename = NULL; } - if (filename == NULL) + if (filename == NULL) { return; + } _filename = new char [strlen(filename) + 1]; - if (_filename != NULL) strcpy(_filename, filename); + if (_filename != NULL) { + strcpy(_filename, filename); + } } @@ -97,7 +100,9 @@ bool BaseScriptHolder::applyEvent(const char *eventName, bool unbreakable) { } } } - if (numHandlers > 0 && unbreakable) _gameRef->_scEngine->tickUnbreakable(); + if (numHandlers > 0 && unbreakable) { + _gameRef->_scEngine->tickUnbreakable(); + } return ret; } @@ -134,8 +139,11 @@ bool BaseScriptHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *t bool ret; ret = applyEvent(val->getString()); - if (DID_SUCCEED(ret)) stack->pushBool(true); - else stack->pushBool(false); + if (DID_SUCCEED(ret)) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -206,7 +214,9 @@ bool BaseScriptHolder::scCallMethod(ScScript *script, ScStack *stack, ScStack *t stack->pushBool(ret); return STATUS_OK; - } else return BaseScriptable::scCallMethod(script, stack, thisStack, name); + } else { + return BaseScriptable::scCallMethod(script, stack, thisStack, name); + } } @@ -236,9 +246,9 @@ ScValue *BaseScriptHolder::scGetProperty(const char *name) { else if (strcmp(name, "Filename") == 0) { _scValue->setString(_filename); return _scValue; + } else { + return BaseScriptable::scGetProperty(name); } - - else return BaseScriptable::scGetProperty(name); } @@ -250,7 +260,9 @@ bool BaseScriptHolder::scSetProperty(const char *name, ScValue *value) { if (strcmp(name, "Name") == 0) { setName(value->getString()); return STATUS_OK; - } else return BaseScriptable::scSetProperty(name, value); + } else { + return BaseScriptable::scSetProperty(name, value); + } } @@ -334,7 +346,9 @@ bool BaseScriptHolder::removeScript(ScScript *script) { ////////////////////////////////////////////////////////////////////////// bool BaseScriptHolder::canHandleEvent(const char *EventName) { for (int i = 0; i < _scripts.getSize(); i++) { - if (!_scripts[i]->_thread && _scripts[i]->canHandleEvent(EventName)) return true; + if (!_scripts[i]->_thread && _scripts[i]->canHandleEvent(EventName)) { + return true; + } } return false; } @@ -343,7 +357,9 @@ bool BaseScriptHolder::canHandleEvent(const char *EventName) { ////////////////////////////////////////////////////////////////////////// bool BaseScriptHolder::canHandleMethod(const char *MethodName) { for (int i = 0; i < _scripts.getSize(); i++) { - if (!_scripts[i]->_thread && _scripts[i]->canHandleMethod(MethodName)) return true; + if (!_scripts[i]->_thread && _scripts[i]->canHandleMethod(MethodName)) { + return true; + } } return false; } @@ -382,15 +398,21 @@ bool BaseScriptHolder::parseProperty(byte *buffer, bool complete) { case TOKEN_NAME: delete[] propName; propName = new char[strlen((char *)params) + 1]; - if (propName) strcpy(propName, (char *)params); - else cmd = PARSERR_GENERIC; + if (propName) { + strcpy(propName, (char *)params); + } else { + cmd = PARSERR_GENERIC; + } break; case TOKEN_VALUE: delete[] propValue; propValue = new char[strlen((char *)params) + 1]; - if (propValue) strcpy(propValue, (char *)params); - else cmd = PARSERR_GENERIC; + if (propValue) { + strcpy(propValue, (char *)params); + } else { + cmd = PARSERR_GENERIC; + } break; } @@ -430,8 +452,9 @@ bool BaseScriptHolder::parseProperty(byte *buffer, bool complete) { ////////////////////////////////////////////////////////////////////////// void BaseScriptHolder::makeFreezable(bool freezable) { _freezable = freezable; - for (int i = 0; i < _scripts.getSize(); i++) + for (int i = 0; i < _scripts.getSize(); i++) { _scripts[i]->_freezable = freezable; + } } diff --git a/engines/wintermute/base/base_scriptable.cpp b/engines/wintermute/base/base_scriptable.cpp index 4059abde3d..ad89b63d65 100644 --- a/engines/wintermute/base/base_scriptable.cpp +++ b/engines/wintermute/base/base_scriptable.cpp @@ -38,8 +38,11 @@ IMPLEMENT_PERSISTENT(BaseScriptable, false) BaseScriptable::BaseScriptable(BaseGame *inGame, bool noValue, bool persistable): BaseNamedObject(inGame) { _refCount = 0; - if (noValue) _scValue = NULL; - else _scValue = new ScValue(_gameRef); + if (noValue) { + _scValue = NULL; + } else { + _scValue = new ScValue(_gameRef); + } _persistable = persistable; @@ -74,17 +77,27 @@ bool BaseScriptable::scCallMethod(ScScript *script, ScStack *stack, ScStack *thi ////////////////////////////////////////////////////////////////////////// ScValue *BaseScriptable::scGetProperty(const char *name) { - if (!_scProp) _scProp = new ScValue(_gameRef); - if (_scProp) return _scProp->getProp(name); - else return NULL; + if (!_scProp) { + _scProp = new ScValue(_gameRef); + } + if (_scProp) { + return _scProp->getProp(name); + } else { + return NULL; + } } ////////////////////////////////////////////////////////////////////////// bool BaseScriptable::scSetProperty(const char *name, ScValue *value) { - if (!_scProp) _scProp = new ScValue(_gameRef); - if (_scProp) return _scProp->setProp(name, value); - else return STATUS_FAILED; + if (!_scProp) { + _scProp = new ScValue(_gameRef); + } + if (_scProp) { + return _scProp->setProp(name, value); + } else { + return STATUS_FAILED; + } } @@ -150,9 +163,13 @@ bool BaseScriptable::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// int BaseScriptable::scCompare(BaseScriptable *val) { - if (this < val) return -1; - else if (this > val) return 1; - else return 0; + if (this < val) { + return -1; + } else if (this > val) { + return 1; + } else { + return 0; + } } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/base/base_sprite.cpp b/engines/wintermute/base/base_sprite.cpp index c2e57f9fd6..2fda638665 100644 --- a/engines/wintermute/base/base_sprite.cpp +++ b/engines/wintermute/base/base_sprite.cpp @@ -89,8 +89,9 @@ void BaseSprite::setDefaults() { void BaseSprite::cleanup() { BaseScriptHolder::cleanup(); - for (int i = 0; i < _frames.getSize(); i++) + for (int i = 0; i < _frames.getSize(); i++) { delete _frames[i]; + } _frames.removeAll(); delete[] _editorBgFile; @@ -103,7 +104,9 @@ void BaseSprite::cleanup() { ////////////////////////////////////////////////////////////////////////// bool BaseSprite::draw(int x, int y, BaseObject *registerOwner, float zoomX, float zoomY, uint32 alpha) { GetCurrentFrame(zoomX, zoomY); - if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) return STATUS_OK; + if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) { + return STATUS_OK; + } // move owner if allowed to if (_changed && _owner && _owner->_movable) { @@ -125,8 +128,11 @@ bool BaseSprite::loadFile(const char *filename, int lifeTime, TSpriteCacheType c Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(filename); if (!file) { _gameRef->LOG(0, "BaseSprite::LoadFile failed for file '%s'", filename); - if (_gameRef->_debugDebugMode) return loadFile("invalid_debug.bmp", lifeTime, cacheType); - else return loadFile("invalid.bmp", lifeTime, cacheType); + if (_gameRef->_debugDebugMode) { + return loadFile("invalid_debug.bmp", lifeTime, cacheType); + } else { + return loadFile("invalid.bmp", lifeTime, cacheType); + } } else { _gameRef->_fileManager->closeFile(file); file = NULL; @@ -154,7 +160,9 @@ bool BaseSprite::loadFile(const char *filename, int lifeTime, TSpriteCacheType c } else { byte *buffer = _gameRef->_fileManager->readWholeFile(filename); if (buffer) { - if (DID_FAIL(ret = loadBuffer(buffer, true, lifeTime, cacheType))) _gameRef->LOG(0, "Error parsing SPRITE file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true, lifeTime, cacheType))) { + _gameRef->LOG(0, "Error parsing SPRITE file '%s'", filename); + } delete[] buffer; } } @@ -262,7 +270,9 @@ bool BaseSprite::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCa if (_gameRef->_editorMode) { delete[] _editorBgFile; _editorBgFile = new char[strlen((char *)params) + 1]; - if (_editorBgFile) strcpy(_editorBgFile, (char *)params); + if (_editorBgFile) { + strcpy(_editorBgFile, (char *)params); + } } break; @@ -282,7 +292,9 @@ bool BaseSprite::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCa case TOKEN_FRAME: { int FrameLifeTime = lifeTime; - if (cacheType == CACHE_HALF && frameCount % 2 != 1) FrameLifeTime = -1; + if (cacheType == CACHE_HALF && frameCount % 2 != 1) { + FrameLifeTime = -1; + } frame = new BaseFrame(_gameRef); @@ -294,7 +306,9 @@ bool BaseSprite::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCa _frames.add(frame); frameCount++; - if (_currentFrame == -1) _currentFrame = 0; + if (_currentFrame == -1) { + _currentFrame = 0; + } } break; @@ -316,8 +330,11 @@ bool BaseSprite::loadBuffer(byte *buffer, bool complete, int lifeTime, TSpriteCa ////////////////////////////////////////////////////////////////////// void BaseSprite::reset() { - if (_frames.getSize() > 0) _currentFrame = 0; - else _currentFrame = -1; + if (_frames.getSize() > 0) { + _currentFrame = 0; + } else { + _currentFrame = -1; + } killAllSounds(); @@ -331,11 +348,16 @@ void BaseSprite::reset() { bool BaseSprite::GetCurrentFrame(float zoomX, float zoomY) { //if (_owner && _owner->_freezable && _gameRef->_state == GAME_FROZEN) return true; - if (_currentFrame == -1) return false; + if (_currentFrame == -1) { + return false; + } uint32 timer; - if (_owner && _owner->_freezable) timer = _gameRef->_timer; - else timer = _gameRef->_liveTimer; + if (_owner && _owner->_freezable) { + timer = _gameRef->_timer; + } else { + timer = _gameRef->_liveTimer; + } int lastFrame = _currentFrame; @@ -343,7 +365,9 @@ bool BaseSprite::GetCurrentFrame(float zoomX, float zoomY) { if (!_paused && !_finished && timer >= _lastFrameTime + _frames[_currentFrame]->_delay && _lastFrameTime != 0) { if (_currentFrame < _frames.getSize() - 1) { _currentFrame++; - if (_continuous) _canBreak = (_currentFrame == _frames.getSize() - 1); + if (_continuous) { + _canBreak = (_currentFrame == _frames.getSize() - 1); + } } else { if (_looping) { _currentFrame = 0; @@ -362,7 +386,9 @@ bool BaseSprite::GetCurrentFrame(float zoomX, float zoomY) { if (_lastFrameTime == 0) { _lastFrameTime = timer; _changed = true; - if (_continuous) _canBreak = (_currentFrame == _frames.getSize() - 1); + if (_continuous) { + _canBreak = (_currentFrame == _frames.getSize() - 1); + } } if (_changed) { @@ -381,7 +407,9 @@ bool BaseSprite::GetCurrentFrame(float zoomX, float zoomY) { ////////////////////////////////////////////////////////////////////// bool BaseSprite::display(int X, int Y, BaseObject *Register, float ZoomX, float ZoomY, uint32 Alpha, float Rotate, TSpriteBlendMode BlendMode) { - if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) return STATUS_OK; + if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) { + return STATUS_OK; + } // on change... if (_changed) { @@ -400,18 +428,27 @@ bool BaseSprite::display(int X, int Y, BaseObject *Register, float ZoomX, float ////////////////////////////////////////////////////////////////////////// BaseSurface *BaseSprite::getSurface() { // only used for animated textures for 3D models - if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) return NULL; - BaseFrame *Frame = _frames[_currentFrame]; - if (Frame && Frame->_subframes.getSize() > 0) { - BaseSubFrame *Subframe = Frame->_subframes[0]; - if (Subframe) return Subframe->_surface; - else return NULL; - } else return NULL; + if (_currentFrame < 0 || _currentFrame >= _frames.getSize()) { + return NULL; + } + BaseFrame *frame = _frames[_currentFrame]; + if (frame && frame->_subframes.getSize() > 0) { + BaseSubFrame *subframe = frame->_subframes[0]; + if (subframe) { + return subframe->_surface; + } else { + return NULL; + } + } else { + return NULL; + } } ////////////////////////////////////////////////////////////////////////// bool BaseSprite::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, float scaleY) { - if (!rect) return false; + if (!rect) { + return false; + } BasePlatform::setRectEmpty(rect); for (int i = 0; i < _frames.getSize(); i++) { @@ -434,12 +471,14 @@ bool BaseSprite::saveAsText(BaseDynamicBuffer *buffer, int indent) { if (_streamed) { buffer->putTextIndent(indent + 2, "STREAMED=%s\n", _streamed ? "TRUE" : "FALSE"); - if (_streamedKeepLoaded) + if (_streamedKeepLoaded) { buffer->putTextIndent(indent + 2, "STREAMED_KEEP_LOADED=%s\n", _streamedKeepLoaded ? "TRUE" : "FALSE"); + } } - if (_editorMuted) + if (_editorMuted) { buffer->putTextIndent(indent + 2, "EDITOR_MUTED=%s\n", _editorMuted ? "TRUE" : "FALSE"); + } if (_editorBgFile) { buffer->putTextIndent(indent + 2, "EDITOR_BG_FILE=\"%s\"\n", _editorBgFile); @@ -514,7 +553,9 @@ bool BaseSprite::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta if (Index < 0 || Index >= _frames.getSize()) { script->runtimeError("Sprite.GetFrame: Frame index %d is out of range.", Index); stack->pushNULL(); - } else stack->pushNative(_frames[Index], true); + } else { + stack->pushNative(_frames[Index], true); + } return STATUS_OK; } @@ -523,17 +564,19 @@ bool BaseSprite::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "DeleteFrame") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); - if (Val->isInt()) { - int Index = Val->getInt(-1); - if (Index < 0 || Index >= _frames.getSize()) { - script->runtimeError("Sprite.DeleteFrame: Frame index %d is out of range.", Index); + ScValue *val = stack->pop(); + if (val->isInt()) { + int index = val->getInt(-1); + if (index < 0 || index >= _frames.getSize()) { + script->runtimeError("Sprite.DeleteFrame: Frame index %d is out of range.", index); } } else { - BaseFrame *Frame = (BaseFrame *)Val->getNative(); + BaseFrame *frame = (BaseFrame *)val->getNative(); for (int i = 0; i < _frames.getSize(); i++) { - if (_frames[i] == Frame) { - if (i == _currentFrame) _lastFrameTime = 0; + if (_frames[i] == frame) { + if (i == _currentFrame) { + _lastFrameTime = 0; + } delete _frames[i]; _frames.removeAt(i); break; @@ -561,7 +604,9 @@ bool BaseSprite::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta stack->correctParams(1); ScValue *val = stack->pop(); const char *filename = NULL; - if (!val->isNULL()) filename = val->getString(); + if (!val->isNULL()) { + filename = val->getString(); + } BaseFrame *frame = new BaseFrame(_gameRef); if (filename != NULL) { @@ -569,7 +614,9 @@ bool BaseSprite::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta if (DID_SUCCEED(sub->setSurface(filename))) { sub->setDefaultRect(); frame->_subframes.add(sub); - } else delete sub; + } else { + delete sub; + } } _frames.add(frame); @@ -583,24 +630,31 @@ bool BaseSprite::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta else if (strcmp(name, "InsertFrame") == 0) { stack->correctParams(2); int index = stack->pop()->getInt(); - if (index < 0) + if (index < 0) { index = 0; + } ScValue *val = stack->pop(); const char *filename = NULL; - if (!val->isNULL()) + if (!val->isNULL()) { filename = val->getString(); + } BaseFrame *frame = new BaseFrame(_gameRef); if (filename != NULL) { BaseSubFrame *sub = new BaseSubFrame(_gameRef); - if (DID_SUCCEED(sub->setSurface(filename))) frame->_subframes.add(sub); - else delete sub; + if (DID_SUCCEED(sub->setSurface(filename))) { + frame->_subframes.add(sub); + } else { + delete sub; + } } - if (index >= _frames.getSize()) + if (index >= _frames.getSize()) { _frames.add(frame); - else _frames.insertAt(index, frame); + } else { + _frames.insertAt(index, frame); + } stack->pushNative(frame, true); return STATUS_OK; @@ -624,9 +678,9 @@ bool BaseSprite::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSta _paused = false; stack->pushNULL(); return STATUS_OK; + } else { + return BaseScriptHolder::scCallMethod(script, stack, thisStack, name); } - - else return BaseScriptHolder::scCallMethod(script, stack, thisStack, name); } @@ -678,8 +732,11 @@ ScValue *BaseSprite::scGetProperty(const char *name) { // Owner (RO) ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Owner") == 0) { - if (_owner == NULL) _scValue->setNULL(); - else _scValue->setNative(_owner, true); + if (_owner == NULL) { + _scValue->setNULL(); + } else { + _scValue->setNative(_owner, true); + } return _scValue; } @@ -697,9 +754,9 @@ ScValue *BaseSprite::scGetProperty(const char *name) { else if (strcmp(name, "Paused") == 0) { _scValue->setBool(_paused); return _scValue; + } else { + return BaseScriptHolder::scGetProperty(name); } - - else return BaseScriptHolder::scGetProperty(name); } @@ -731,9 +788,9 @@ bool BaseSprite::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "Looping") == 0) { _looping = value->getBool(); return STATUS_OK; + } else { + return BaseScriptHolder::scSetProperty(name, value); } - - else return BaseScriptHolder::scSetProperty(name, value); } @@ -746,8 +803,9 @@ const char *BaseSprite::scToString() { ////////////////////////////////////////////////////////////////////////// bool BaseSprite::killAllSounds() { for (int i = 0; i < _frames.getSize(); i++) { - if (_frames[i]->_sound) + if (_frames[i]->_sound) { _frames[i]->_sound->stop(); + } } return STATUS_OK; } diff --git a/engines/wintermute/base/base_string_table.cpp b/engines/wintermute/base/base_string_table.cpp index 58cf046436..18a18fe0ba 100644 --- a/engines/wintermute/base/base_string_table.cpp +++ b/engines/wintermute/base/base_string_table.cpp @@ -51,8 +51,9 @@ BaseStringTable::~BaseStringTable() { ////////////////////////////////////////////////////////////////////////// bool BaseStringTable::addString(const char *key, const char *val, bool reportDuplicities) { - if (key == NULL || val == NULL) + if (key == NULL || val == NULL) { return STATUS_FAILED; + } if (scumm_stricmp(key, "@right-to-left") == 0) { _gameRef->_textRTL = true; @@ -63,8 +64,9 @@ bool BaseStringTable::addString(const char *key, const char *val, bool reportDup finalKey.toLowercase(); StringsIter it = _strings.find(finalKey); - if (it != _strings.end() && reportDuplicities) + if (it != _strings.end() && reportDuplicities) { _gameRef->LOG(0, " Warning: Duplicate definition of string '%s'.", finalKey.c_str()); + } _strings[finalKey] = val; @@ -73,12 +75,14 @@ bool BaseStringTable::addString(const char *key, const char *val, bool reportDup ////////////////////////////////////////////////////////////////////////// char *BaseStringTable::getKey(const char *str) const { - if (str == NULL || str[0] != '/') + if (str == NULL || str[0] != '/') { return NULL; + } const char *value = strchr(str + 1, '/'); - if (value == NULL) + if (value == NULL) { return NULL; + } char *key = new char[value - str]; Common::strlcpy(key, str + 1, (size_t)(value - str)); @@ -107,12 +111,14 @@ char *BaseStringTable::getKey(const char *str) const { ////////////////////////////////////////////////////////////////////////// void BaseStringTable::expand(char **str) const { - if (str == NULL || *str == NULL || *str[0] != '/') + if (str == NULL || *str == NULL || *str[0] != '/') { return; + } char *value = strchr(*str + 1, '/'); - if (value == NULL) + if (value == NULL) { return; + } char *key = new char[value - *str]; Common::strlcpy(key, *str + 1, (size_t)(value - *str)); @@ -136,19 +142,22 @@ void BaseStringTable::expand(char **str) const { delete[] *str; *str = newStr; - if (strlen(*str) > 0 && *str[0] == '/') + if (strlen(*str) > 0 && *str[0] == '/') { expand(str); + } } ////////////////////////////////////////////////////////////////////////// const char *BaseStringTable::expandStatic(const char *string) const { - if (string == NULL || string[0] == '\0' || string[0] != '/') + if (string == NULL || string[0] == '\0' || string[0] != '/') { return string; + } const char *value = strchr(string + 1, '/'); - if (value == NULL) + if (value == NULL) { return string; + } char *key = new char[value - string]; Common::strlcpy(key, string + 1, (size_t)(value - string - 1)); @@ -167,10 +176,11 @@ const char *BaseStringTable::expandStatic(const char *string) const { delete[] key; - if (strlen(newStr) > 0 && newStr[0] == '/') + if (strlen(newStr) > 0 && newStr[0] == '/') { return expandStatic(newStr); - else + } else { return newStr; + } } @@ -178,8 +188,9 @@ const char *BaseStringTable::expandStatic(const char *string) const { bool BaseStringTable::loadFile(const char *filename, bool clearOld) { _gameRef->LOG(0, "Loading string table..."); - if (clearOld) + if (clearOld) { _strings.clear(); + } uint32 size; byte *buffer = _gameRef->_fileManager->readWholeFile(filename, &size); @@ -197,27 +208,33 @@ bool BaseStringTable::loadFile(const char *filename, bool clearOld) { //_gameRef->_textEncoding = TEXT_ANSI; _gameRef->LOG(0, " UTF8 file detected, switching to UTF8 text encoding"); } - } else _gameRef->_textEncoding = TEXT_ANSI; + } else { + _gameRef->_textEncoding = TEXT_ANSI; + } uint32 lineLength = 0; while (pos < size) { lineLength = 0; - while (pos + lineLength < size && buffer[pos + lineLength] != '\n' && buffer[pos + lineLength] != '\0') + while (pos + lineLength < size && buffer[pos + lineLength] != '\n' && buffer[pos + lineLength] != '\0') { lineLength++; + } uint32 realLength = lineLength - (pos + lineLength >= size ? 0 : 1); char *line = new char[realLength + 1]; Common::strlcpy(line, (char *)&buffer[pos], realLength + 1); char *value = strchr(line, '\t'); - if (value == NULL) value = strchr(line, ' '); + if (value == NULL) { + value = strchr(line, ' '); + } if (line[0] != ';') { if (value != NULL) { value[0] = '\0'; value++; for (uint32 i = 0; i < strlen(value); i++) { - if (value[i] == '|') + if (value[i] == '|') { value[i] = '\n'; + } } addString(line, value, clearOld); } else if (line[0] != '\0') { diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index 523bbed866..e8290ee659 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -67,7 +67,9 @@ BaseSubFrame::BaseSubFrame(BaseGame *inGame): BaseScriptable(inGame, true) { ////////////////////////////////////////////////////////////////////////// BaseSubFrame::~BaseSubFrame() { - if (_surface) _gameRef->_surfaceStorage->removeSurface(_surface); + if (_surface) { + _gameRef->_surfaceStorage->removeSurface(_surface); + } delete[] _surfaceFilename; _surfaceFilename = NULL; } @@ -181,12 +183,17 @@ bool BaseSubFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { } if (surfaceFile != NULL) { - if (custoTrans) setSurface(surfaceFile, false, r, g, b, lifeTime, keepLoaded); - else setSurface(surfaceFile, true, 0, 0, 0, lifeTime, keepLoaded); + if (custoTrans) { + setSurface(surfaceFile, false, r, g, b, lifeTime, keepLoaded); + } else { + setSurface(surfaceFile, true, 0, 0, 0, lifeTime, keepLoaded); + } } _alpha = BYTETORGBA(ar, ag, ab, alpha); - if (custoTrans) _transparent = BYTETORGBA(r, g, b, 0xFF); + if (custoTrans) { + _transparent = BYTETORGBA(r, g, b, 0xFF); + } /* if (_surface == NULL) @@ -195,8 +202,11 @@ bool BaseSubFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { return STATUS_FAILED; } */ - if (BasePlatform::isRectEmpty(&rect)) setDefaultRect(); - else _rect = rect; + if (BasePlatform::isRectEmpty(&rect)) { + setDefaultRect(); + } else { + _rect = rect; + } return STATUS_OK; } @@ -204,7 +214,9 @@ bool BaseSubFrame::loadBuffer(byte *buffer, int lifeTime, bool keepLoaded) { ////////////////////////////////////////////////////////////////////// bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float zoomY, bool precise, uint32 alpha, float rotate, TSpriteBlendMode blendMode) { - if (!_surface) return STATUS_OK; + if (!_surface) { + return STATUS_OK; + } if (registerOwner != NULL && !_decoration) { if (zoomX == 100 && zoomY == 100) { @@ -213,18 +225,25 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, (int)(x - (_hotspotX + _rect.left) * (zoomX / 100)), (int)(y - (_hotspotY + _rect.top) * (zoomY / 100)), (int)((_rect.right - _rect.left) * (zoomX / 100)), (int)((_rect.bottom - _rect.top) * (zoomY / 100)), zoomX, zoomY, precise)); } } - if (_gameRef->_suspendedRendering) return STATUS_OK; + if (_gameRef->_suspendedRendering) { + return STATUS_OK; + } bool res; //if (Alpha==0xFFFFFFFF) Alpha = _alpha; // TODO: better (combine owner's and self alpha) - if (_alpha != 0xFFFFFFFF) alpha = _alpha; + if (_alpha != 0xFFFFFFFF) { + alpha = _alpha; + } if (rotate != 0.0f) { res = _surface->displayTransform((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _hotspotX, _hotspotY, _rect, zoomX, zoomY, alpha, rotate, blendMode, _mirrorX, _mirrorY); } else { - if (zoomX == 100 && zoomY == 100) res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, _rect, alpha, blendMode, _mirrorX, _mirrorY); - else res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _rect, zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY); + if (zoomX == 100 && zoomY == 100) { + res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, _rect, alpha, blendMode, _mirrorX, _mirrorY); + } else { + res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _rect, zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY); + } } return res; @@ -233,7 +252,9 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl ////////////////////////////////////////////////////////////////////////// bool BaseSubFrame::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, float scaleY) { - if (!rect) return false; + if (!rect) { + return false; + } float ratioX = scaleX / 100.0f; float ratioY = scaleY / 100.0f; @@ -249,52 +270,66 @@ bool BaseSubFrame::getBoundingRect(Rect32 *rect, int x, int y, float scaleX, flo ////////////////////////////////////////////////////////////////////////// bool BaseSubFrame::saveAsText(BaseDynamicBuffer *buffer, int indent, bool complete) { - if (complete) + if (complete) { buffer->putTextIndent(indent, "SUBFRAME {\n"); + } - if (_surface && _surface->getFileNameStr() != "") + if (_surface && _surface->getFileNameStr() != "") { buffer->putTextIndent(indent + 2, "IMAGE = \"%s\"\n", _surface->getFileName()); + } - if (_transparent != 0xFFFF00FF) + if (_transparent != 0xFFFF00FF) { buffer->putTextIndent(indent + 2, "TRANSPARENT { %d,%d,%d }\n", RGBCOLGetR(_transparent), RGBCOLGetG(_transparent), RGBCOLGetB(_transparent)); + } Rect32 rect; BasePlatform::setRectEmpty(&rect); - if (_surface) BasePlatform::setRect(&rect, 0, 0, _surface->getWidth(), _surface->getHeight()); - if (!(rect == _rect)) + if (_surface) { + BasePlatform::setRect(&rect, 0, 0, _surface->getWidth(), _surface->getHeight()); + } + if (!(rect == _rect)) { buffer->putTextIndent(indent + 2, "RECT { %d,%d,%d,%d }\n", _rect.left, _rect.top, _rect.right, _rect.bottom); + } - if (_hotspotX != 0 || _hotspotY != 0) + if (_hotspotX != 0 || _hotspotY != 0) { buffer->putTextIndent(indent + 2, "HOTSPOT {%d, %d}\n", _hotspotX, _hotspotY); + } if (_alpha != 0xFFFFFFFF) { buffer->putTextIndent(indent + 2, "ALPHA_COLOR { %d,%d,%d }\n", RGBCOLGetR(_alpha), RGBCOLGetG(_alpha), RGBCOLGetB(_alpha)); buffer->putTextIndent(indent + 2, "ALPHA = %d\n", RGBCOLGetA(_alpha)); } - if (_mirrorX) + if (_mirrorX) { buffer->putTextIndent(indent + 2, "MIRROR_X=%s\n", _mirrorX ? "TRUE" : "FALSE"); + } - if (_mirrorY) + if (_mirrorY) { buffer->putTextIndent(indent + 2, "MIRROR_Y=%s\n", _mirrorY ? "TRUE" : "FALSE"); + } - if (_2DOnly) + if (_2DOnly) { buffer->putTextIndent(indent + 2, "2D_ONLY=%s\n", _2DOnly ? "TRUE" : "FALSE"); + } - if (_3DOnly) + if (_3DOnly) { buffer->putTextIndent(indent + 2, "3D_ONLY=%s\n", _3DOnly ? "TRUE" : "FALSE"); + } - if (_decoration) + if (_decoration) { buffer->putTextIndent(indent + 2, "DECORATION=%s\n", _decoration ? "TRUE" : "FALSE"); + } - if (_editorSelected) + if (_editorSelected) { buffer->putTextIndent(indent + 2, "EDITOR_SELECTED=%s\n", _editorSelected ? "TRUE" : "FALSE"); + } BaseClass::saveAsText(buffer, indent + 2); - if (complete) + if (complete) { buffer->putTextIndent(indent, "}\n\n"); + } return STATUS_OK; } @@ -304,7 +339,9 @@ bool BaseSubFrame::saveAsText(BaseDynamicBuffer *buffer, int indent, bool comple void BaseSubFrame::setDefaultRect() { if (_surface) { BasePlatform::setRect(&_rect, 0, 0, _surface->getWidth(), _surface->getHeight()); - } else BasePlatform::setRectEmpty(&_rect); + } else { + BasePlatform::setRectEmpty(&_rect); + } } @@ -349,8 +386,11 @@ bool BaseSubFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS if (strcmp(name, "GetImage") == 0) { stack->correctParams(0); - if (!_surfaceFilename) stack->pushNULL(); - else stack->pushString(_surfaceFilename); + if (!_surfaceFilename) { + stack->pushNULL(); + } else { + stack->pushString(_surfaceFilename); + } return STATUS_OK; } @@ -359,31 +399,37 @@ bool BaseSubFrame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisS ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetImage") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); - if (Val->isNULL()) { - if (_surface) _gameRef->_surfaceStorage->removeSurface(_surface); + if (val->isNULL()) { + if (_surface) { + _gameRef->_surfaceStorage->removeSurface(_surface); + } delete[] _surfaceFilename; _surfaceFilename = NULL; stack->pushBool(true); } else { - const char *filename = Val->getString(); + const char *filename = val->getString(); if (DID_SUCCEED(setSurface(filename))) { setDefaultRect(); stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } } return STATUS_OK; + } else { + return BaseScriptable::scCallMethod(script, stack, thisStack, name); } - - else return BaseScriptable::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// ScValue *BaseSubFrame::scGetProperty(const char *name) { - if (!_scValue) _scValue = new ScValue(_gameRef); + if (!_scValue) { + _scValue = new ScValue(_gameRef); + } _scValue->setNULL(); ////////////////////////////////////////////////////////////////////////// @@ -465,9 +511,9 @@ ScValue *BaseSubFrame::scGetProperty(const char *name) { else if (strcmp(name, "HotspotY") == 0) { _scValue->setInt(_hotspotY); return _scValue; + } else { + return BaseScriptable::scGetProperty(name); } - - else return BaseScriptable::scGetProperty(name); } @@ -535,9 +581,9 @@ bool BaseSubFrame::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "HotspotY") == 0) { _hotspotY = value->getInt(); return STATUS_OK; + } else { + return BaseScriptable::scSetProperty(name, value); } - - else return BaseScriptable::scSetProperty(name, value); } @@ -570,7 +616,9 @@ bool BaseSubFrame::setSurface(const char *filename, bool defaultCK, byte ckRed, _keepLoaded = keepLoaded; return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -581,8 +629,11 @@ bool BaseSubFrame::setSurfaceSimple() { return STATUS_OK; } _surface = _gameRef->_surfaceStorage->addSurface(_surfaceFilename, _cKDefault, _cKRed, _cKGreen, _cKBlue, _lifeTime, _keepLoaded); - if (_surface) return STATUS_OK; - else return STATUS_FAILED; + if (_surface) { + return STATUS_OK; + } else { + return STATUS_FAILED; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/base/base_surface_storage.cpp b/engines/wintermute/base/base_surface_storage.cpp index d8ba0cbbce..3d878b1346 100644 --- a/engines/wintermute/base/base_surface_storage.cpp +++ b/engines/wintermute/base/base_surface_storage.cpp @@ -52,7 +52,9 @@ BaseSurfaceStorage::~BaseSurfaceStorage() { ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceStorage::cleanup(bool warn) { for (uint32 i = 0; i < _surfaces.size(); i++) { - if (warn) _gameRef->LOG(0, "BaseSurfaceStorage warning: purging surface '%s', usage:%d", _surfaces[i]->getFileName(), _surfaces[i]->_referenceCount); + if (warn) { + _gameRef->LOG(0, "BaseSurfaceStorage warning: purging surface '%s', usage:%d", _surfaces[i]->getFileName(), _surfaces[i]->_referenceCount); + } delete _surfaces[i]; } _surfaces.clear(); @@ -67,7 +69,9 @@ bool BaseSurfaceStorage::initLoop() { _lastCleanupTime = _gameRef->_liveTimer; sortSurfaces(); for (uint32 i = 0; i < _surfaces.size(); i++) { - if (_surfaces[i]->_lifeTime <= 0) break; + if (_surfaces[i]->_lifeTime <= 0) { + break; + } if (_surfaces[i]->_lifeTime > 0 && _surfaces[i]->_valid && _gameRef->_liveTimer - _surfaces[i]->_lastUsedTime >= _surfaces[i]->_lifeTime) { //_gameRef->QuickMessageForm("Invalidating: %s", _surfaces[i]->_filename); @@ -105,17 +109,22 @@ BaseSurface *BaseSurfaceStorage::addSurface(const char *filename, bool defaultCK } if (!_gameRef->_fileManager->hasFile(filename)) { - if (filename) _gameRef->LOG(0, "Missing image: '%s'", filename); - if (_gameRef->_debugDebugMode) + if (filename) { + _gameRef->LOG(0, "Missing image: '%s'", filename); + } + if (_gameRef->_debugDebugMode) { return addSurface("invalid_debug.bmp", defaultCK, ckRed, ckGreen, ckBlue, lifeTime, keepLoaded); - else + } else { return addSurface("invalid.bmp", defaultCK, ckRed, ckGreen, ckBlue, lifeTime, keepLoaded); + } } BaseSurface *surface; surface = _gameRef->_renderer->createSurface(); - if (!surface) return NULL; + if (!surface) { + return NULL; + } if (DID_FAIL(surface->create(filename, defaultCK, ckRed, ckGreen, ckBlue, lifeTime, keepLoaded))) { delete surface; @@ -171,18 +180,28 @@ int BaseSurfaceStorage::surfaceSortCB(const void *arg1, const void *arg2) { BaseSurface *s2 = *((BaseSurface **)arg2); // sort by life time - if (s1->_lifeTime <= 0 && s2->_lifeTime > 0) return 1; - else if (s1->_lifeTime > 0 && s2->_lifeTime <= 0) return -1; + if (s1->_lifeTime <= 0 && s2->_lifeTime > 0) { + return 1; + } else if (s1->_lifeTime > 0 && s2->_lifeTime <= 0) { + return -1; + } // sort by validity - if (s1->_valid && !s2->_valid) return -1; - else if (!s1->_valid && s2->_valid) return 1; + if (s1->_valid && !s2->_valid) { + return -1; + } else if (!s1->_valid && s2->_valid) { + return 1; + } // sort by time - else if (s1->_lastUsedTime > s2->_lastUsedTime) return 1; - else if (s1->_lastUsedTime < s2->_lastUsedTime) return -1; - else return 0; + else if (s1->_lastUsedTime > s2->_lastUsedTime) { + return 1; + } else if (s1->_lastUsedTime < s2->_lastUsedTime) { + return -1; + } else { + return 0; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/base/base_transition_manager.cpp b/engines/wintermute/base/base_transition_manager.cpp index eeaacd2063..7a78865552 100644 --- a/engines/wintermute/base/base_transition_manager.cpp +++ b/engines/wintermute/base/base_transition_manager.cpp @@ -57,7 +57,9 @@ bool BaseTransitionMgr::isReady() { ////////////////////////////////////////////////////////////////////////// bool BaseTransitionMgr::start(TTransitionType type, bool nonInteractive) { - if (_state != TRANS_MGR_READY) return STATUS_OK; + if (_state != TRANS_MGR_READY) { + return STATUS_OK; + } if (type == TRANSITION_NONE || type >= NUM_TRANSITION_TYPES) { _state = TRANS_MGR_READY; @@ -82,7 +84,9 @@ bool BaseTransitionMgr::start(TTransitionType type, bool nonInteractive) { ////////////////////////////////////////////////////////////////////////// bool BaseTransitionMgr::update() { - if (isReady()) return STATUS_OK; + if (isReady()) { + return STATUS_OK; + } if (!_started) { _started = true; @@ -100,8 +104,9 @@ bool BaseTransitionMgr::update() { alpha = MIN(255, MAX(alpha, 0)); _gameRef->_renderer->fade((uint16)alpha); - if (time > FADE_DURATION) + if (time > FADE_DURATION) { _state = TRANS_MGR_READY; + } } break; @@ -111,8 +116,9 @@ bool BaseTransitionMgr::update() { alpha = MIN(255, MAX(alpha, 0)); _gameRef->_renderer->fade((uint16)alpha); - if (time > FADE_DURATION) + if (time > FADE_DURATION) { _state = TRANS_MGR_READY; + } } break; default: @@ -120,8 +126,9 @@ bool BaseTransitionMgr::update() { } if (isReady()) { - if (_preserveInteractive) + if (_preserveInteractive) { _gameRef->_interactive = _origInteractive; + } } return STATUS_OK; } diff --git a/engines/wintermute/base/file/base_disk_file.cpp b/engines/wintermute/base/file/base_disk_file.cpp index bb8504d2f4..7d805aedb5 100644 --- a/engines/wintermute/base/file/base_disk_file.cpp +++ b/engines/wintermute/base/file/base_disk_file.cpp @@ -41,7 +41,9 @@ namespace WinterMute { void correctSlashes(char *fileName) { for (size_t i = 0; i < strlen(fileName); i++) { - if (fileName[i] == '\\') fileName[i] = '/'; + if (fileName[i] == '\\') { + fileName[i] = '/'; + } } } @@ -51,8 +53,9 @@ static Common::FSNode getNodeForRelativePath(const Common::String &filename) { // specifies to follow the Windows-convention of folder\subfolder\file (absolute paths should not happen) // Absolute path: TODO: Add specific fallbacks here. - if (filename.contains(':')) + if (filename.contains(':')) { error("openDiskFile::Absolute path or invalid filename used in %s", filename.c_str()); + } // Relative path: if (filename.contains('\\')) { @@ -132,7 +135,9 @@ Common::SeekableReadStream *openDiskFile(const Common::String &filename) { magic2 = file->readUint32LE(); bool compressed = false; - if (magic1 == DCGF_MAGIC && magic2 == COMPRESSED_FILE_MAGIC) compressed = true; + if (magic1 == DCGF_MAGIC && magic2 == COMPRESSED_FILE_MAGIC) { + compressed = true; + } if (compressed) { uint32 dataOffset, compSize, uncompSize; diff --git a/engines/wintermute/base/file/base_file_entry.cpp b/engines/wintermute/base/file/base_file_entry.cpp index 8282079c86..7bf635b858 100644 --- a/engines/wintermute/base/file/base_file_entry.cpp +++ b/engines/wintermute/base/file/base_file_entry.cpp @@ -61,7 +61,9 @@ public: Common::SeekableReadStream *BaseFileEntry::createReadStream() const { Common::SeekableReadStream *file = _package->getFilePointer(); - if (!file) return NULL; + if (!file) { + return NULL; + } // TODO: Cleanup bool compressed = (_compressedLength != 0); diff --git a/engines/wintermute/base/file/base_package.cpp b/engines/wintermute/base/file/base_package.cpp index f2d2378c6a..b41ae3c1bd 100644 --- a/engines/wintermute/base/file/base_package.cpp +++ b/engines/wintermute/base/file/base_package.cpp @@ -64,7 +64,9 @@ static bool findPackageSignature(Common::SeekableReadStream *f, uint32 *offset) uint32 toRead = MIN((unsigned int)32768, fileSize - bytesRead); f->seek((int32)startPos, SEEK_SET); uint32 actuallyRead = f->read(buf, toRead); - if (actuallyRead != toRead) return false; + if (actuallyRead != toRead) { + return false; + } for (uint32 i = 0; i < toRead - 8; i++) if (!memcmp(buf + i, signature, 8)) { @@ -85,8 +87,9 @@ PackageSet::PackageSet(Common::FSNode file, const Common::String &filename, bool _priority = 0; bool boundToExe = false; Common::SeekableReadStream *stream = file.createReadStream(); - if (!stream) + if (!stream) { return; + } if (searchSignature) { uint32 offset; if (!findPackageSignature(stream, &offset)) { @@ -121,7 +124,9 @@ PackageSet::PackageSet(Common::FSNode file, const Common::String &filename, bool assert(hdr._numDirs == 1); for (uint32 i = 0; i < hdr._numDirs; i++) { BasePackage *pkg = new BasePackage(); - if (!pkg) return; + if (!pkg) { + return; + } pkg->_fsnode = file; pkg->_boundToExe = boundToExe; @@ -136,7 +141,9 @@ PackageSet::PackageSet(Common::FSNode file, const Common::String &filename, bool delete[] pkgName; pkgName = NULL; - if (!hdr._masterIndex) pkg->_cd = 0; // override CD to fixed disk + if (!hdr._masterIndex) { + pkg->_cd = 0; // override CD to fixed disk + } _packages.push_back(pkg); // read file entries @@ -242,8 +249,9 @@ Common::SeekableReadStream *PackageSet::createReadStreamForMember(const Common:: upcName.toUppercase(); Common::HashMap::const_iterator it; it = _files.find(upcName.c_str()); - if (it != _files.end()) + if (it != _files.end()) { return it->_value->createReadStream(); + } return NULL; } diff --git a/engines/wintermute/base/file/base_save_thumb_file.cpp b/engines/wintermute/base/file/base_save_thumb_file.cpp index 0a0d0cac09..e067241589 100644 --- a/engines/wintermute/base/file/base_save_thumb_file.cpp +++ b/engines/wintermute/base/file/base_save_thumb_file.cpp @@ -53,7 +53,9 @@ BaseSaveThumbFile::~BaseSaveThumbFile() { bool BaseSaveThumbFile::open(const Common::String &filename) { close(); - if (scumm_strnicmp(filename.c_str(), "savegame:", 9) != 0) return STATUS_FAILED; + if (scumm_strnicmp(filename.c_str(), "savegame:", 9) != 0) { + return STATUS_FAILED; + } char *tempFilename = new char[strlen(filename.c_str()) - 8]; strcpy(tempFilename, filename.c_str() + 9); @@ -70,7 +72,9 @@ bool BaseSaveThumbFile::open(const Common::String &filename) { BasePersistenceManager *pm = new BasePersistenceManager(_gameRef); Common::String slotFilename = pm->getFilenameForSlot(slot); - if (!pm) return STATUS_FAILED; + if (!pm) { + return STATUS_FAILED; + } if (DID_FAIL(pm->initLoad(slotFilename))) { delete pm; @@ -84,7 +88,9 @@ bool BaseSaveThumbFile::open(const Common::String &filename) { memcpy(_data, pm->_thumbnailData, pm->_thumbnailDataSize); _size = pm->_thumbnailDataSize; res = STATUS_OK; - } else res = STATUS_FAILED; + } else { + res = STATUS_FAILED; + } delete pm; return res; @@ -105,7 +111,9 @@ bool BaseSaveThumbFile::close() { ////////////////////////////////////////////////////////////////////////// bool BaseSaveThumbFile::read(void *buffer, uint32 size) { - if (!_data || _pos + size > _size) return STATUS_FAILED; + if (!_data || _pos + size > _size) { + return STATUS_FAILED; + } memcpy(buffer, (byte *)_data + _pos, size); _pos += size; @@ -116,7 +124,9 @@ bool BaseSaveThumbFile::read(void *buffer, uint32 size) { ////////////////////////////////////////////////////////////////////////// bool BaseSaveThumbFile::seek(uint32 pos, int whence) { - if (!_data) return STATUS_FAILED; + if (!_data) { + return STATUS_FAILED; + } uint32 newPos = 0; @@ -132,8 +142,11 @@ bool BaseSaveThumbFile::seek(uint32 pos, int whence) { break; } - if (newPos > _size) return STATUS_FAILED; - else _pos = newPos; + if (newPos > _size) { + return STATUS_FAILED; + } else { + _pos = newPos; + } return STATUS_OK; } diff --git a/engines/wintermute/base/font/base_font.cpp b/engines/wintermute/base/font/base_font.cpp index d576b834a2..937557f4d7 100644 --- a/engines/wintermute/base/font/base_font.cpp +++ b/engines/wintermute/base/font/base_font.cpp @@ -187,7 +187,9 @@ bool BaseFont::isTrueType(BaseGame *gameRef, const char *filename) { byte *buffer = gameRef->_fileManager->readWholeFile(filename); - if (buffer == NULL) return false; + if (buffer == NULL) { + return false; + } byte *WorkBuffer = buffer; @@ -195,8 +197,9 @@ bool BaseFont::isTrueType(BaseGame *gameRef, const char *filename) { BaseParser parser(gameRef); bool ret = false; - if (parser.getCommand((char **)&WorkBuffer, commands, (char **)¶ms) == TOKEN_TTFONT) + if (parser.getCommand((char **)&WorkBuffer, commands, (char **)¶ms) == TOKEN_TTFONT) { ret = true; + } delete[] buffer; return ret; diff --git a/engines/wintermute/base/font/base_font_bitmap.cpp b/engines/wintermute/base/font/base_font_bitmap.cpp index dd6c6da327..9cce8ca9ee 100644 --- a/engines/wintermute/base/font/base_font_bitmap.cpp +++ b/engines/wintermute/base/font/base_font_bitmap.cpp @@ -91,8 +91,9 @@ int BaseFontBitmap::getTextWidth(byte *text, int maxLength) { str = AnsiString((char *)text); } - if (maxLength >= 0 && str.size() > (uint32)maxLength) + if (maxLength >= 0 && str.size() > (uint32)maxLength) { str = Common::String(str.c_str(), (uint32)maxLength); + } //str.substr(0, maxLength); // TODO: Remove int textWidth = 0; @@ -106,9 +107,13 @@ int BaseFontBitmap::getTextWidth(byte *text, int maxLength) { ////////////////////////////////////////////////////////////////////// int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAlign align, bool draw, int maxHeight, int maxLength) { - if (maxLength == 0) return 0; + if (maxLength == 0) { + return 0; + } - if (text == NULL || text[0] == '\0') return _tileHeight; + if (text == NULL || text[0] == '\0') { + return _tileHeight; + } AnsiString str; @@ -118,7 +123,9 @@ int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAli } else { str = AnsiString((char *)text); } - if (str.empty()) return 0; + if (str.empty()) { + return 0; + } int LineLength = 0; int RealLength = 0; @@ -135,11 +142,15 @@ int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAli bool new_line = false; bool long_line = false; - if (draw) _gameRef->_renderer->startSpriteBatch(); + if (draw) { + _gameRef->_renderer->startSpriteBatch(); + } while (!done) { if (maxHeight > 0 && (NumLines + 1)*_tileHeight > maxHeight) { - if (draw) _gameRef->_renderer->endSpriteBatch(); + if (draw) { + _gameRef->_renderer->endSpriteBatch(); + } return NumLines * _tileHeight; } @@ -170,10 +181,14 @@ int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAli LineLength += getCharWidth(str[index]); RealLength = LineLength; } - } else LineLength += getCharWidth(str[index]); + } else { + LineLength += getCharWidth(str[index]); + } if ((LineLength > width) || done || new_line) { - if (end < 0) done = true; + if (end < 0) { + done = true; + } int StartX; switch (align) { case TAL_CENTER: @@ -190,12 +205,16 @@ int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAli break; } for (i = start; i < end + 1; i++) { - if (draw) drawChar(str[i], StartX, y); + if (draw) { + drawChar(str[i], StartX, y); + } StartX += getCharWidth(str[i]); } y += _tileHeight; last_end = end; - if (long_line) end--; + if (long_line) { + end--; + } start = end + 2; index = end + 1; LineLength = 0; @@ -205,7 +224,9 @@ int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAli } } - if (draw) _gameRef->_renderer->endSpriteBatch(); + if (draw) { + _gameRef->_renderer->endSpriteBatch(); + } return NumLines * _tileHeight; } @@ -213,7 +234,9 @@ int BaseFontBitmap::textHeightDraw(byte *text, int x, int y, int width, TTextAli ////////////////////////////////////////////////////////////////////// void BaseFontBitmap::drawChar(byte c, int x, int y) { - if (_fontextFix) c--; + if (_fontextFix) { + c--; + } int row, col; @@ -223,8 +246,11 @@ void BaseFontBitmap::drawChar(byte c, int x, int y) { Rect32 rect; /* l t r b */ int tileWidth; - if (_wholeCell) tileWidth = _tileWidth; - else tileWidth = _widths[c]; + if (_wholeCell) { + tileWidth = _tileWidth; + } else { + tileWidth = _widths[c]; + } BasePlatform::setRect(&rect, col * _tileWidth, row * _tileHeight, col * _tileWidth + tileWidth, (row + 1)*_tileHeight); bool handled = false; @@ -237,7 +263,9 @@ void BaseFontBitmap::drawChar(byte c, int x, int y) { handled = true; } } - if (!handled && _subframe) _subframe->_surface->displayTrans(x, y, rect); + if (!handled && _subframe) { + _subframe->_surface->displayTrans(x, y, rect); + } } @@ -253,7 +281,9 @@ bool BaseFontBitmap::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer))) _gameRef->LOG(0, "Error parsing FONT file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer))) { + _gameRef->LOG(0, "Error parsing FONT file '%s'", filename); + } delete[] buffer; @@ -408,8 +438,11 @@ bool BaseFontBitmap::loadBuffer(byte *buffer) { if (surfaceFile != NULL && !_sprite) { _subframe = new BaseSubFrame(_gameRef); - if (custoTrans) _subframe->setSurface(surfaceFile, false, r, g, b); - else _subframe->setSurface(surfaceFile); + if (custoTrans) { + _subframe->setSurface(surfaceFile, false, r, g, b); + } else { + _subframe->setSurface(surfaceFile); + } } @@ -425,25 +458,32 @@ bool BaseFontBitmap::loadBuffer(byte *buffer) { // do we need to modify widths? if (expandWidth != 0) { for (i = 0; i < NUM_CHARACTERS; i++) { - int NewWidth = (int)_widths[i] + expandWidth; - if (NewWidth < 0) NewWidth = 0; + int newWidth = (int)_widths[i] + expandWidth; + if (newWidth < 0) { + newWidth = 0; + } - _widths[i] = (byte)NewWidth; + _widths[i] = (byte)newWidth; } } // handle space character uint32 spaceChar = ' '; - if (_fontextFix) spaceChar--; + if (_fontextFix) { + spaceChar--; + } - if (spaceWidth != 0) _widths[spaceChar] = spaceWidth; - else { + if (spaceWidth != 0) { + _widths[spaceChar] = spaceWidth; + } else { if (_widths[spaceChar] == expandWidth || _widths[spaceChar] == 0) { _widths[spaceChar] = (_widths['m'] + _widths['i']) / 2; } } } else { - for (i = lastWidth; i < NUM_CHARACTERS; i++) _widths[i] = default_width; + for (i = lastWidth; i < NUM_CHARACTERS; i++) { + _widths[i] = default_width; + } } @@ -463,10 +503,11 @@ bool BaseFontBitmap::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_sprite)); persistMgr->transfer(TMEMBER(_widthsFrame)); - if (persistMgr->getIsSaving()) + if (persistMgr->getIsSaving()) { persistMgr->putBytes(_widths, sizeof(_widths)); - else + } else { persistMgr->getBytes(_widths, sizeof(_widths)); + } persistMgr->transfer(TMEMBER(_fontextFix)); @@ -479,7 +520,9 @@ bool BaseFontBitmap::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// int BaseFontBitmap::getCharWidth(byte index) { - if (_fontextFix) index--; + if (_fontextFix) { + index--; + } return _widths[index]; } @@ -495,8 +538,12 @@ bool BaseFontBitmap::getWidths() { } } } - if (surf == NULL && _subframe) surf = _subframe->_surface; - if (!surf || DID_FAIL(surf->startPixelOp())) return STATUS_FAILED; + if (surf == NULL && _subframe) { + surf = _subframe->_surface; + } + if (!surf || DID_FAIL(surf->startPixelOp())) { + return STATUS_FAILED; + } for (int i = 0; i < NUM_CHARACTERS; i++) { @@ -507,14 +554,18 @@ bool BaseFontBitmap::getWidths() { int minCol = -1; for (int row = 0; row < _tileHeight; row++) { for (int col = _tileWidth - 1; col >= minCol + 1; col--) { - if (xxx + col < 0 || xxx + col >= surf->getWidth() || yyy + row < 0 || yyy + row >= surf->getHeight()) continue; + if (xxx + col < 0 || xxx + col >= surf->getWidth() || yyy + row < 0 || yyy + row >= surf->getHeight()) { + continue; + } if (!surf->isTransparentAtLite(xxx + col, yyy + row)) { //min_col = col; minCol = MAX(col, minCol); break; } } - if (minCol == _tileWidth - 1) break; + if (minCol == _tileWidth - 1) { + break; + } } _widths[i] = minCol + 1; diff --git a/engines/wintermute/base/font/base_font_storage.cpp b/engines/wintermute/base/font/base_font_storage.cpp index 84c80c73cb..8b4fa74181 100644 --- a/engines/wintermute/base/font/base_font_storage.cpp +++ b/engines/wintermute/base/font/base_font_storage.cpp @@ -52,7 +52,9 @@ BaseFontStorage::~BaseFontStorage() { ////////////////////////////////////////////////////////////////////////// bool BaseFontStorage::cleanup(bool warn) { for (int i = 0; i < _fonts.getSize(); i++) { - if (warn) _gameRef->LOG(0, "Removing orphan font '%s'", _fonts[i]->getFilename()); + if (warn) { + _gameRef->LOG(0, "Removing orphan font '%s'", _fonts[i]->getFilename()); + } delete _fonts[i]; } _fonts.removeAll(); @@ -70,7 +72,9 @@ bool BaseFontStorage::initLoop() { ////////////////////////////////////////////////////////////////////////// BaseFont *BaseFontStorage::addFont(const char *filename) { - if (!filename) return NULL; + if (!filename) { + return NULL; + } for (int i = 0; i < _fonts.getSize(); i++) { if (scumm_stricmp(_fonts[i]->getFilename(), filename) == 0) { @@ -104,7 +108,9 @@ BaseFont *BaseFontStorage::addFont(const char *filename) { ////////////////////////////////////////////////////////////////////////// bool BaseFontStorage::removeFont(BaseFont *font) { - if (!font) return STATUS_FAILED; + if (!font) { + return STATUS_FAILED; + } for (int i = 0; i < _fonts.getSize(); i++) { if (_fonts[i] == font) { @@ -123,7 +129,9 @@ bool BaseFontStorage::removeFont(BaseFont *font) { ////////////////////////////////////////////////////////////////////////// bool BaseFontStorage::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->getIsSaving()) cleanup(false); + if (!persistMgr->getIsSaving()) { + cleanup(false); + } persistMgr->transfer(TMEMBER(_gameRef)); _fonts.persist(persistMgr); diff --git a/engines/wintermute/base/font/base_font_truetype.cpp b/engines/wintermute/base/font/base_font_truetype.cpp index 0a97370cb7..420df58b74 100644 --- a/engines/wintermute/base/font/base_font_truetype.cpp +++ b/engines/wintermute/base/font/base_font_truetype.cpp @@ -57,7 +57,9 @@ BaseFontTT::BaseFontTT(BaseGame *inGame): BaseFont(inGame) { _fallbackFont = NULL; _deletableFont = NULL; - for (int i = 0; i < NUM_CACHED_TEXTS; i++) _cachedTexts[i] = NULL; + for (int i = 0; i < NUM_CACHED_TEXTS; i++) { + _cachedTexts[i] = NULL; + } #if 0 _fTFace = NULL; @@ -98,7 +100,9 @@ BaseFontTT::~BaseFontTT(void) { ////////////////////////////////////////////////////////////////////////// void BaseFontTT::clearCache() { for (int i = 0; i < NUM_CACHED_TEXTS; i++) { - if (_cachedTexts[i]) delete _cachedTexts[i]; + if (_cachedTexts[i]) { + delete _cachedTexts[i]; + } _cachedTexts[i] = NULL; } } @@ -109,12 +113,16 @@ void BaseFontTT::initLoop() { if (_gameRef->_constrainedMemory) { // purge all cached images not used in the last frame for (int i = 0; i < NUM_CACHED_TEXTS; i++) { - if (_cachedTexts[i] == NULL) continue; + if (_cachedTexts[i] == NULL) { + continue; + } if (!_cachedTexts[i]->_marked) { delete _cachedTexts[i]; _cachedTexts[i] = NULL; - } else _cachedTexts[i]->_marked = false; + } else { + _cachedTexts[i]->_marked = false; + } } } } @@ -123,11 +131,15 @@ void BaseFontTT::initLoop() { int BaseFontTT::getTextWidth(byte *text, int maxLength) { WideString textStr; - if (_gameRef->_textEncoding == TEXT_UTF8) textStr = StringUtil::utf8ToWide((char *)text); - else textStr = StringUtil::ansiToWide((char *)text); + if (_gameRef->_textEncoding == TEXT_UTF8) { + textStr = StringUtil::utf8ToWide((char *)text); + } else { + textStr = StringUtil::ansiToWide((char *)text); + } - if (maxLength >= 0 && textStr.size() > (uint32)maxLength) + if (maxLength >= 0 && textStr.size() > (uint32)maxLength) { textStr = Common::String(textStr.c_str(), (uint32)maxLength); + } //text = text.substr(0, MaxLength); // TODO: Remove int textWidth, textHeight; @@ -140,8 +152,11 @@ int BaseFontTT::getTextWidth(byte *text, int maxLength) { int BaseFontTT::getTextHeight(byte *text, int width) { WideString textStr; - if (_gameRef->_textEncoding == TEXT_UTF8) textStr = StringUtil::utf8ToWide((char *)text); - else textStr = StringUtil::ansiToWide((char *)text); + if (_gameRef->_textEncoding == TEXT_UTF8) { + textStr = StringUtil::utf8ToWide((char *)text); + } else { + textStr = StringUtil::ansiToWide((char *)text); + } int textWidth, textHeight; @@ -153,7 +168,9 @@ int BaseFontTT::getTextHeight(byte *text, int width) { ////////////////////////////////////////////////////////////////////////// void BaseFontTT::drawText(byte *text, int x, int y, int width, TTextAlign align, int maxHeight, int maxLength) { - if (text == NULL || strcmp((char *)text, "") == 0) return; + if (text == NULL || strcmp((char *)text, "") == 0) { + return; + } WideString textStr = (char *)text; @@ -161,8 +178,9 @@ void BaseFontTT::drawText(byte *text, int x, int y, int width, TTextAlign align, /* if (_gameRef->_textEncoding == TEXT_UTF8) text = StringUtil::Utf8ToWide((char *)Text); else text = StringUtil::AnsiToWide((char *)Text);*/ - if (maxLength >= 0 && textStr.size() > (uint32)maxLength) + if (maxLength >= 0 && textStr.size() > (uint32)maxLength) { textStr = Common::String(textStr.c_str(), (uint32)maxLength); + } //text = text.substr(0, MaxLength); // TODO: Remove BaseRenderer *renderer = _gameRef->_renderer; @@ -199,7 +217,9 @@ void BaseFontTT::drawText(byte *text, int x, int y, int width, TTextAlign align, surface = renderTextToTexture(textStr, width, align, maxHeight, textOffset); if (surface) { // write surface to cache - if (_cachedTexts[minIndex] != NULL) delete _cachedTexts[minIndex]; + if (_cachedTexts[minIndex] != NULL) { + delete _cachedTexts[minIndex]; + } _cachedTexts[minIndex] = new BaseCachedTTFontText; _cachedTexts[minIndex]->_surface = surface; @@ -261,10 +281,11 @@ BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, debugC(kWinterMuteDebugFont, "%s %d %d %d %d", text.c_str(), RGBCOLGetR(_layers[0]->_color), RGBCOLGetG(_layers[0]->_color), RGBCOLGetB(_layers[0]->_color), RGBCOLGetA(_layers[0]->_color)); // void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = true) const; Graphics::Surface *surface = new Graphics::Surface(); - if (_deletableFont) // We actually have a TTF + if (_deletableFont) { // We actually have a TTF surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)); - else // We are using a fallback, they can't do 32bpp + } else { // We are using a fallback, they can't do 32bpp surface->create((uint16)width, (uint16)(_lineHeight * lines.size()), Graphics::PixelFormat(2, 5, 5, 5, 1, 11, 6, 1, 0)); + } uint32 useColor = 0xffffffff; Common::Array::iterator it; int heightOffset = 0; @@ -309,7 +330,9 @@ BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, wchar_t ch = line->GetText()[i]; GlyphInfo *glyph = _glyphCache->GetGlyph(ch); - if (!glyph) continue; + if (!glyph) { + continue; + } textOffset = MAX(textOffset, glyph->GetBearingY()); } @@ -322,10 +345,14 @@ BaseSurface *BaseFontTT::renderTextToTexture(const WideString &text, int width, wchar_t ch = line->GetText()[i]; GlyphInfo *glyph = _glyphCache->GetGlyph(ch); - if (!glyph) continue; + if (!glyph) { + continue; + } float kerning = 0; - if (prevChar != L'\0') kerning = GetKerning(prevChar, ch); + if (prevChar != L'\0') { + kerning = GetKerning(prevChar, ch); + } posX += (int)kerning; @@ -381,7 +408,9 @@ void BaseFontTT::blitSurface(Graphics::Surface *src, Graphics::Surface *target, warning("BaseFontTT::BlitSurface - not ported yet"); #if 0 for (int y = 0; y < src->h; y++) { - if (targetRect->y + y < 0 || targetRect->y + y >= target->h) continue; + if (targetRect->y + y < 0 || targetRect->y + y >= target->h) { + continue; + } uint8 *srcBuf = (uint8 *)src->pixels + y * src->pitch; @@ -391,7 +420,9 @@ void BaseFontTT::blitSurface(Graphics::Surface *src, Graphics::Surface *target, uint32 *tgtBuf32 = (uint32 *)tgtBuf; for (int x = 0; x < src->w; x++) { - if (targetRect->x + x < 0 || targetRect->x + x >= target->w) continue; + if (targetRect->x + x < 0 || targetRect->x + x >= target->w) { + continue; + } tgtBuf32[x + targetRect->x] = srcBuf32[x]; } @@ -417,7 +448,9 @@ bool BaseFontTT::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer))) _gameRef->LOG(0, "Error parsing TTFONT file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer))) { + _gameRef->LOG(0, "Error parsing TTFONT file '%s'", filename); + } delete[] buffer; @@ -468,7 +501,7 @@ bool BaseFontTT::loadBuffer(byte *buffer) { } buffer = (byte *)params; - uint32 BaseColor = 0x00000000; + uint32 baseColor = 0x00000000; while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { @@ -507,23 +540,24 @@ bool BaseFontTT::loadBuffer(byte *buffer) { case TOKEN_COLOR: { int r, g, b; parser.scanStr(params, "%d,%d,%d", &r, &g, &b); - BaseColor = BYTETORGBA(r, g, b, RGBCOLGetA(BaseColor)); + baseColor = BYTETORGBA(r, g, b, RGBCOLGetA(baseColor)); } break; case TOKEN_ALPHA: { int a; parser.scanStr(params, "%d", &a); - BaseColor = BYTETORGBA(RGBCOLGetR(BaseColor), RGBCOLGetG(BaseColor), RGBCOLGetB(BaseColor), a); + baseColor = BYTETORGBA(RGBCOLGetR(baseColor), RGBCOLGetG(baseColor), RGBCOLGetB(baseColor), a); } break; case TOKEN_LAYER: { - BaseTTFontLayer *Layer = new BaseTTFontLayer; - if (Layer && DID_SUCCEED(parseLayer(Layer, (byte *)params))) _layers.add(Layer); - else { - delete Layer; - Layer = NULL; + BaseTTFontLayer *layer = new BaseTTFontLayer; + if (layer && DID_SUCCEED(parseLayer(layer, (byte *)params))) { + _layers.add(layer); + } else { + delete layer; + layer = NULL; cmd = PARSERR_TOKENNOTFOUND; } } @@ -538,12 +572,14 @@ bool BaseFontTT::loadBuffer(byte *buffer) { // create at least one layer if (_layers.getSize() == 0) { - BaseTTFontLayer *Layer = new BaseTTFontLayer; - Layer->_color = BaseColor; - _layers.add(Layer); + BaseTTFontLayer *layer = new BaseTTFontLayer; + layer->_color = baseColor; + _layers.add(layer); } - if (!_fontFile) BaseUtils::setString(&_fontFile, "arial.ttf"); + if (!_fontFile) { + BaseUtils::setString(&_fontFile, "arial.ttf"); + } return initFont(); } @@ -587,8 +623,11 @@ bool BaseFontTT::parseLayer(BaseTTFontLayer *layer, byte *buffer) { break; } } - if (cmd != PARSERR_EOF) return STATUS_FAILED; - else return STATUS_OK; + if (cmd != PARSERR_EOF) { + return STATUS_FAILED; + } else { + return STATUS_OK; + } } @@ -609,7 +648,9 @@ bool BaseFontTT::persist(BasePersistenceManager *persistMgr) { if (persistMgr->getIsSaving()) { numLayers = _layers.getSize(); persistMgr->transfer(TMEMBER(numLayers)); - for (int i = 0; i < numLayers; i++) _layers[i]->persist(persistMgr); + for (int i = 0; i < numLayers; i++) { + _layers[i]->persist(persistMgr); + } } else { numLayers = _layers.getSize(); persistMgr->transfer(TMEMBER(numLayers)); @@ -621,7 +662,9 @@ bool BaseFontTT::persist(BasePersistenceManager *persistMgr) { } if (!persistMgr->getIsSaving()) { - for (int i = 0; i < NUM_CACHED_TEXTS; i++) _cachedTexts[i] = NULL; + for (int i = 0; i < NUM_CACHED_TEXTS; i++) { + _cachedTexts[i] = NULL; + } _fallbackFont = _font = _deletableFont = NULL; } @@ -636,7 +679,9 @@ void BaseFontTT::afterLoad() { ////////////////////////////////////////////////////////////////////////// bool BaseFontTT::initFont() { - if (!_fontFile) return STATUS_FAILED; + if (!_fontFile) { + return STATUS_FAILED; + } Common::SeekableReadStream *file = _gameRef->_fileManager->openFile(_fontFile); if (!file) { diff --git a/engines/wintermute/base/font/base_font_truetype.h b/engines/wintermute/base/font/base_font_truetype.h index 8a8459b070..f8c5eee74d 100644 --- a/engines/wintermute/base/font/base_font_truetype.h +++ b/engines/wintermute/base/font/base_font_truetype.h @@ -67,7 +67,9 @@ private: } virtual ~BaseCachedTTFontText() { - if (_surface) delete _surface; + if (_surface) { + delete _surface; + } } }; diff --git a/engines/wintermute/base/gfx/base_image.cpp b/engines/wintermute/base/gfx/base_image.cpp index 09a78a748b..571deed793 100644 --- a/engines/wintermute/base/gfx/base_image.cpp +++ b/engines/wintermute/base/gfx/base_image.cpp @@ -53,15 +53,11 @@ BaseImage::BaseImage(BaseFileManager *fileManager) { ////////////////////////////////////////////////////////////////////// BaseImage::~BaseImage() { - /* delete _bitmap; */ delete _decoder; if (_deletableSurface) { _deletableSurface->free(); } delete _deletableSurface; -#if 0 - if (_bitmap) FreeImage_Unload(_bitmap); -#endif } bool BaseImage::loadFile(const Common::String &filename) { @@ -82,7 +78,9 @@ bool BaseImage::loadFile(const Common::String &filename) { } _filename = filename; Common::SeekableReadStream *file = _fileManager->openFile(filename.c_str()); - if (!file) return false; + if (!file) { + return false; + } _decoder->loadStream(*file); _surface = _decoder->getSurface(); @@ -93,7 +91,9 @@ bool BaseImage::loadFile(const Common::String &filename) { } byte BaseImage::getAlphaAt(int x, int y) const { - if (!_surface) return 0xFF; + if (!_surface) { + return 0xFF; + } uint32 color = *(uint32 *)_surface->getBasePtr(x, y); byte r, g, b, a; _surface->format.colorToARGB(color, a, r, g, b); @@ -107,12 +107,6 @@ void BaseImage::copyFrom(const Graphics::Surface *surface) { ////////////////////////////////////////////////////////////////////////// bool BaseImage::saveBMPFile(const char *filename) const { -#if 0 - if (!_bitmap) return STATUS_FAILED; - - if (FreeImage_Save(FIF_BMP, _bitmap, filename)) return STATUS_OK; - else return STATUS_FAILED; -#endif warning("BaseImage::saveBMPFile - stubbed"); // TODO return false; } @@ -121,10 +115,16 @@ bool BaseImage::saveBMPFile(const char *filename) const { ////////////////////////////////////////////////////////////////////////// bool BaseImage::resize(int newWidth, int newHeight) { #if 0 - if (!_bitmap) return STATUS_FAILED; + if (!_bitmap) { + return STATUS_FAILED; + } - if (newWidth == 0) NewWidth = FreeImage_GetWidth(_bitmap); - if (newHeight == 0) NewHeight = FreeImage_GetHeight(_bitmap); + if (newWidth == 0) { + NewWidth = FreeImage_GetWidth(_bitmap); + } + if (newHeight == 0) { + NewHeight = FreeImage_GetHeight(_bitmap); + } FIBITMAP *newImg = FreeImage_Rescale(_bitmap, NewWidth, NewHeight, FILTER_BILINEAR); @@ -132,7 +132,9 @@ bool BaseImage::resize(int newWidth, int newHeight) { FreeImage_Unload(_bitmap); _bitmap = newImg; return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } #endif return false; } @@ -140,7 +142,9 @@ bool BaseImage::resize(int newWidth, int newHeight) { ////////////////////////////////////////////////////////////////////////// bool BaseImage::writeBMPToStream(Common::WriteStream *stream) const { - if (!_surface) return false; + if (!_surface) { + return false; + } /* The following is just copied over and inverted to write-ops from the BMP-decoder */ stream->writeByte('B'); @@ -164,8 +168,9 @@ bool BaseImage::writeBMPToStream(Common::WriteStream *stream) const { stream->writeUint32LE(width); stream->writeUint32LE((uint32)height); - if (width == 0 || height == 0) + if (width == 0 || height == 0) { return false; + } if (height < 0) { warning("Right-side up bitmaps not supported"); @@ -194,8 +199,9 @@ bool BaseImage::writeBMPToStream(Common::WriteStream *stream) const { Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8(); // BGRA for 24bpp - if (bitsPerPixel == 24) + if (bitsPerPixel == 24) { format = Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0); + } Graphics::Surface *surface = _surface->convertTo(format); @@ -219,36 +225,22 @@ bool BaseImage::writeBMPToStream(Common::WriteStream *stream) const { surface->free(); delete surface; return true; - - //*BufferSize = 0; -#if 0 - FIMEMORY *fiMem = FreeImage_OpenMemory(); - FreeImage_SaveToMemory(FIF_PNG, _bitmap, fiMem); - uint32 size; - byte *data; - FreeImage_AcquireMemory(fiMem, &data, &size); - - - byte *Buffer = new byte[size]; - memcpy(Buffer, data, size); - - FreeImage_CloseMemory(fiMem); - - if (BufferSize) *BufferSize = size; - - return Buffer; -#endif - return false; } ////////////////////////////////////////////////////////////////////////// bool BaseImage::copyFrom(BaseImage *origImage, int newWidth, int newHeight) { #if 0 - if (_bitmap) FreeImage_Unload(_bitmap); + if (_bitmap) { + FreeImage_Unload(_bitmap); + } - if (NewWidth == 0) NewWidth = FreeImage_GetWidth(OrigImage->GetBitmap()); - if (NewHeight == 0) NewHeight = FreeImage_GetHeight(OrigImage->GetBitmap()); + if (NewWidth == 0) { + NewWidth = FreeImage_GetWidth(OrigImage->GetBitmap()); + } + if (NewHeight == 0) { + NewHeight = FreeImage_GetHeight(OrigImage->GetBitmap()); + } _bitmap = FreeImage_Rescale(OrigImage->GetBitmap(), NewWidth, NewHeight, FILTER_BILINEAR); #endif diff --git a/engines/wintermute/base/gfx/base_renderer.cpp b/engines/wintermute/base/gfx/base_renderer.cpp index 66b7f513bf..168aa75d91 100644 --- a/engines/wintermute/base/gfx/base_renderer.cpp +++ b/engines/wintermute/base/gfx/base_renderer.cpp @@ -89,13 +89,19 @@ BaseObject *BaseRenderer::getObjectAt(int x, int y) { yy = height - yy; } - if (!_rectList[i]->_frame->_surface->isTransparentAt(xx, yy)) return _rectList[i]->_owner; + if (!_rectList[i]->_frame->_surface->isTransparentAt(xx, yy)) { + return _rectList[i]->_owner; + } } // region else if (_rectList[i]->_region) { - if (_rectList[i]->_region->pointInRegion(x + _rectList[i]->_offsetX, y + _rectList[i]->_offsetY)) return _rectList[i]->_owner; + if (_rectList[i]->_region->pointInRegion(x + _rectList[i]->_offsetX, y + _rectList[i]->_offsetY)) { + return _rectList[i]->_owner; + } } - } else return _rectList[i]->_owner; + } else { + return _rectList[i]->_owner; + } } } @@ -208,10 +214,18 @@ bool BaseRenderer::unclipCursor() { ////////////////////////////////////////////////////////////////////////// bool BaseRenderer::pointInViewport(Point32 *p) { - if (p->x < _drawOffsetX) return false; - if (p->y < _drawOffsetY) return false; - if (p->x > _drawOffsetX + _width) return false; - if (p->y > _drawOffsetY + _height) return false; + if (p->x < _drawOffsetX) { + return false; + } + if (p->y < _drawOffsetY) { + return false; + } + if (p->x > _drawOffsetX + _width) { + return false; + } + if (p->y > _drawOffsetY + _height) { + return false; + } return true; } diff --git a/engines/wintermute/base/gfx/base_surface.cpp b/engines/wintermute/base/gfx/base_surface.cpp index 684236ac7f..68e3e3d26c 100644 --- a/engines/wintermute/base/gfx/base_surface.cpp +++ b/engines/wintermute/base/gfx/base_surface.cpp @@ -54,7 +54,9 @@ BaseSurface::BaseSurface(BaseGame *inGame): BaseClass(inGame) { ////////////////////////////////////////////////////////////////////// BaseSurface::~BaseSurface() { - if (_pixelOpReady) endPixelOp(); + if (_pixelOpReady) { + endPixelOp(); + } } @@ -139,7 +141,9 @@ bool BaseSurface::prepareToDraw() { if (!_valid) { //_gameRef->LOG(0, "Reviving: %s", _filename); return create(_filename.c_str(), _ckDefault, _ckRed, _ckGreen, _ckBlue, _lifeTime, _keepLoaded); - } else return STATUS_OK; + } else { + return STATUS_OK; + } } diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 43cf66d053..e465194e58 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -44,10 +44,12 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s _srcRect(*srcRect), _dstRect(*dstRect), _drawNum(0), _isValid(true), _wantsDraw(true), _hasAlpha(true) { _colorMod = 0; _mirror = TransparentSurface::FLIP_NONE; - if (mirrorX) + if (mirrorX) { _mirror |= TransparentSurface::FLIP_V; - if (mirrorY) + } + if (mirrorY) { _mirror |= TransparentSurface::FLIP_H; + } if (surf) { _surface = new Graphics::Surface(); _surface->create((uint16)srcRect->width(), (uint16)srcRect->height(), surf->format); @@ -113,8 +115,12 @@ BaseRenderOSystem::~BaseRenderOSystem() { _renderSurface->free(); delete _renderSurface; #if 0 - if (_renderer) SDL_DestroyRenderer(_renderer); - if (_win) SDL_DestroyWindow(_win); + if (_renderer) { + SDL_DestroyRenderer(_renderer); + } + if (_win) { + SDL_DestroyWindow(_win); + } SDL_Quit(); #endif } @@ -212,7 +218,9 @@ bool BaseRenderOSystem::initRenderer(int width, int height, bool windowed) { _realWidth, _realHeight, flags); - if (!_win) return STATUS_FAILED; + if (!_win) { + return STATUS_FAILED; + } #endif g_system->showMouse(false); @@ -226,7 +234,9 @@ bool BaseRenderOSystem::initRenderer(int width, int height, bool windowed) { #if 0 _renderer = SDL_CreateRenderer(_win, -1, 0); - if (!_renderer) return STATUS_FAILED; + if (!_renderer) { + return STATUS_FAILED; + } #endif _renderSurface->create(g_system->getWidth(), g_system->getHeight(), g_system->getScreenFormat()); _active = true; @@ -273,8 +283,9 @@ bool BaseRenderOSystem::fill(byte r, byte g, byte b, Common::Rect *rect) { //SDL_SetRenderDrawColor(_renderer, r, g, b, 0xFF); //SDL_RenderClear(_renderer); _clearColor = _renderSurface->format.ARGBToColor(0xFF, r, g, b); - if (!_disableDirtyRects) + if (!_disableDirtyRects) { return STATUS_OK; + } if (!rect) { rect = &_renderRect; } @@ -320,9 +331,9 @@ void BaseRenderOSystem::fadeToColor(byte r, byte g, byte b, byte a, Common::Rect //TODO: This is only here until I'm sure about the final pixelformat uint32 col = _renderSurface->format.ARGBToColor(a, r, g, b); - if (_disableDirtyRects) + if (_disableDirtyRects) { _renderSurface->fillRect(fillRect, col); - else { + } else { setAlphaMod(a); setColorMod(r, g, b); Graphics::Surface surf; @@ -468,8 +479,9 @@ void BaseRenderOSystem::drawTickets() { it++; } } - if (!_dirtyRect || _dirtyRect->width() == 0 || _dirtyRect->height() == 0) + if (!_dirtyRect || _dirtyRect->width() == 0 || _dirtyRect->height() == 0) { return; + } // The color-mods are stored in the RenderTickets on add, since we set that state again during // draw, we need to keep track of what it was prior to draw. uint32 oldColorMod = _colorMod; @@ -518,8 +530,9 @@ void BaseRenderOSystem::drawFromSurface(const Graphics::Surface *surf, Common::R } src.blit(*_renderSurface, dstRect->left, dstRect->top, mirror, clipRect, _colorMod, clipRect->width(), clipRect->height()); - if (doDelete) + if (doDelete) { delete clipRect; + } } ////////////////////////////////////////////////////////////////////////// @@ -566,9 +579,13 @@ BaseImage *BaseRenderOSystem::takeScreenshot() { SDL_RenderGetViewport(_renderer, &viewport); SDL_Surface *surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, 0x00000000); - if (!surface) return NULL; + if (!surface) { + return NULL; + } - if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) < 0) return NULL; + if (SDL_RenderReadPixels(_renderer, NULL, surface->format->format, surface->pixels, surface->pitch) < 0) { + return NULL; + } FIBITMAP *dib = FreeImage_Allocate(viewport.w, viewport.h, 24, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK); @@ -643,7 +660,9 @@ void BaseRenderOSystem::dumpData(const char *filename) { warning("BaseRenderOSystem::DumpData(%s) - not reimplemented yet", filename); // TODO #if 0 FILE *f = fopen(filename, "wt"); - if (!f) return; + if (!f) { + return; + } BaseSurfaceStorage *Mgr = _gameRef->_surfaceStorage; @@ -652,8 +671,12 @@ void BaseRenderOSystem::dumpData(const char *filename) { fprintf(f, "Filename;Usage;Size;KBytes\n"); for (int i = 0; i < Mgr->_surfaces.getSize(); i++) { BaseSurfaceOSystem *Surf = (BaseSurfaceOSystem *)Mgr->_surfaces[i]; - if (!Surf->_filename) continue; - if (!Surf->_valid) continue; + if (!Surf->_filename) { + continue; + } + if (!Surf->_valid) { + continue; + } fprintf(f, "%s;%d;", Surf->_filename, Surf->_referenceCount); fprintf(f, "%dx%d;", Surf->getWidth(), Surf->getHeight()); diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index 36213dfde1..4b680e2793 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -107,11 +107,14 @@ bool BaseSurfaceOSystem::create(const char *filename, bool defaultCK, byte ckRed _ckGreen = ckGreen; _ckBlue = ckBlue; - if (_lifeTime == 0 || lifeTime == -1 || lifeTime > _lifeTime) + if (_lifeTime == 0 || lifeTime == -1 || lifeTime > _lifeTime) { _lifeTime = lifeTime; + } _keepLoaded = keepLoaded; - if (_keepLoaded) _lifeTime = -1; + if (_keepLoaded) { + _lifeTime = -1; + } return STATUS_OK; } @@ -201,7 +204,9 @@ void BaseSurfaceOSystem::genAlphaMask(Graphics::Surface *surface) { delete[] _alphaMask; _alphaMask = NULL; - if (!surface) return; + if (!surface) { + return; + } #if 0 SDL_LockSurface(surface); #endif @@ -224,11 +229,14 @@ void BaseSurfaceOSystem::genAlphaMask(Graphics::Surface *surface) { surface->format.colorToARGB(pixel, a, r, g, b); //SDL_GetRGBA(pixel, surface->format, &r, &g, &b, &a); - if (hasColorKey && r == ckRed && g == ckGreen && b == ckBlue) + if (hasColorKey && r == ckRed && g == ckGreen && b == ckBlue) { a = 0; + } _alphaMask[y * surface->w + x] = a; - if (a < 255) hasTransparency = true; + if (a < 255) { + hasTransparency = true; + } } } #if 0 @@ -331,7 +339,9 @@ bool BaseSurfaceOSystem::isTransparentAt(int x, int y) { int width, height; //SDL_QueryTexture(_texture, NULL, &access, &width, &height); //TODO //if (access != SDL_TEXTUREACCESS_STREAMING) return false; - if (X < 0 || X >= width || Y < 0 || Y >= height) return true; + if (X < 0 || X >= width || Y < 0 || Y >= height) { + return true; + } StartPixelOp(); @@ -371,10 +381,15 @@ bool BaseSurfaceOSystem::isTransparentAtLite(int x, int y) { //SDL_QueryTexture(_texture, &format, &access, &width, &height); //if (access != SDL_TEXTUREACCESS_STREAMING) return false; - if (X < 0 || X >= width || Y < 0 || Y >= height) return true; + if (X < 0 || X >= width || Y < 0 || Y >= height) { + return true; + } - if (!_alphaMask) return false; - else return _alphaMask[Y * width + X] <= 128; + if (!_alphaMask) { + return false; + } else { + return _alphaMask[Y * width + X] <= 128; + } #endif return false; /* @@ -447,8 +462,9 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo finishLoad(); } - if (renderer->_forceAlphaColor != 0) + if (renderer->_forceAlphaColor != 0) { alpha = renderer->_forceAlphaColor; + } // This particular warning is rather messy, as this function is called a ton, // thus we avoid printing it more than once. @@ -469,10 +485,11 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo SDL_SetTextureColorMod(_texture, r, g, b); SDL_SetTextureAlphaMod(_texture, a); - if (AlphaDisable) + if (alphaDisable) { SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_NONE); - else + } else { SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_BLEND); + } #endif // TODO: This _might_ miss the intended behaviour by 1 in each direction // But I think it fits the model used in Wintermute. diff --git a/engines/wintermute/base/particles/part_emitter.cpp b/engines/wintermute/base/particles/part_emitter.cpp index 1ddefec610..b16fb83abf 100644 --- a/engines/wintermute/base/particles/part_emitter.cpp +++ b/engines/wintermute/base/particles/part_emitter.cpp @@ -116,11 +116,15 @@ PartEmitter::~PartEmitter(void) { ////////////////////////////////////////////////////////////////////////// bool PartEmitter::addSprite(const char *filename) { - if (!filename) return STATUS_FAILED; + if (!filename) { + return STATUS_FAILED; + } // do we already have the file? for (int i = 0; i < _sprites.getSize(); i++) { - if (scumm_stricmp(filename, _sprites[i]) == 0) return STATUS_OK; + if (scumm_stricmp(filename, _sprites[i]) == 0) { + return STATUS_OK; + } } // check if file exists @@ -128,7 +132,9 @@ bool PartEmitter::addSprite(const char *filename) { if (!File) { _gameRef->LOG(0, "Sprite '%s' not found", filename); return STATUS_FAILED; - } else _gameRef->_fileManager->closeFile(File); + } else { + _gameRef->_fileManager->closeFile(File); + } char *Str = new char[strlen(filename) + 1]; strcpy(Str, filename); @@ -151,24 +157,37 @@ bool PartEmitter::removeSprite(const char *filename) { ////////////////////////////////////////////////////////////////////////// bool PartEmitter::initParticle(PartParticle *particle, uint32 currentTime, uint32 timerDelta) { - if (!particle) return STATUS_FAILED; - if (_sprites.getSize() == 0) return STATUS_FAILED; + if (!particle) { + return STATUS_FAILED; + } + if (_sprites.getSize() == 0) { + return STATUS_FAILED; + } int posX = BaseUtils::randomInt(_posX, _posX + _width); int posY = BaseUtils::randomInt(_posY, _posY + _height); float posZ = BaseUtils::randomFloat(0.0f, 100.0f); float velocity; - if (_velocityZBased) velocity = _velocity1 + posZ * (_velocity2 - _velocity1) / 100; - else velocity = BaseUtils::randomFloat(_velocity1, _velocity2); + if (_velocityZBased) { + velocity = _velocity1 + posZ * (_velocity2 - _velocity1) / 100; + } else { + velocity = BaseUtils::randomFloat(_velocity1, _velocity2); + } float scale; - if (_scaleZBased) scale = _scale1 + posZ * (_scale2 - _scale1) / 100; - else scale = BaseUtils::randomFloat(_scale1, _scale2); + if (_scaleZBased) { + scale = _scale1 + posZ * (_scale2 - _scale1) / 100; + } else { + scale = BaseUtils::randomFloat(_scale1, _scale2); + } int lifeTime; - if (_lifeTimeZBased) lifeTime = (int)(_lifeTime2 - posZ * (_lifeTime2 - _lifeTime1) / 100); - else lifeTime = BaseUtils::randomInt(_lifeTime1, _lifeTime2); + if (_lifeTimeZBased) { + lifeTime = (int)(_lifeTime2 - posZ * (_lifeTime2 - _lifeTime1) / 100); + } else { + lifeTime = BaseUtils::randomInt(_lifeTime1, _lifeTime2); + } float angle = BaseUtils::randomAngle(_angle1, _angle2); int spriteIndex = BaseUtils::randomInt(0, _sprites.getSize() - 1); @@ -220,14 +239,20 @@ bool PartEmitter::initParticle(PartParticle *particle, uint32 currentTime, uint3 particle->fadeIn(currentTime, _fadeInTime); - if (particle->_isDead) return STATUS_FAILED; - else return STATUS_OK; + if (particle->_isDead) { + return STATUS_FAILED; + } else { + return STATUS_OK; + } } ////////////////////////////////////////////////////////////////////////// bool PartEmitter::update() { - if (!_running) return STATUS_OK; - else return updateInternal(_gameRef->_timer, _gameRef->_timerDelta); + if (!_running) { + return STATUS_OK; + } else { + return updateInternal(_gameRef->_timer, _gameRef->_timerDelta); + } } ////////////////////////////////////////////////////////////////////////// @@ -237,7 +262,9 @@ bool PartEmitter::updateInternal(uint32 currentTime, uint32 timerDelta) { for (int i = 0; i < _particles.getSize(); i++) { _particles[i]->update(this, currentTime, timerDelta); - if (!_particles[i]->_isDead) numLive++; + if (!_particles[i]->_isDead) { + numLive++; + } } @@ -263,8 +290,9 @@ bool PartEmitter::updateInternal(uint32 currentTime, uint32 timerDelta) { } PartParticle *particle; - if (firstDeadIndex >= 0) particle = _particles[firstDeadIndex]; - else { + if (firstDeadIndex >= 0) { + particle = _particles[firstDeadIndex]; + } else { particle = new PartParticle(_gameRef); _particles.add(particle); } @@ -274,12 +302,15 @@ bool PartEmitter::updateInternal(uint32 currentTime, uint32 timerDelta) { toGen--; } } - if (needsSort && (_scaleZBased || _velocityZBased || _lifeTimeZBased)) + if (needsSort && (_scaleZBased || _velocityZBased || _lifeTimeZBased)) { sortParticlesByZ(); + } // we actually generated some particles and we're not in fast-forward mode if (needsSort && _overheadTime == 0) { - if (_owner && _emitEvent) _owner->applyEvent(_emitEvent); + if (_owner && _emitEvent) { + _owner->applyEvent(_emitEvent); + } } } @@ -288,17 +319,23 @@ bool PartEmitter::updateInternal(uint32 currentTime, uint32 timerDelta) { ////////////////////////////////////////////////////////////////////////// bool PartEmitter::display(BaseRegion *region) { - if (_sprites.getSize() <= 1) _gameRef->_renderer->startSpriteBatch(); + if (_sprites.getSize() <= 1) { + _gameRef->_renderer->startSpriteBatch(); + } for (int i = 0; i < _particles.getSize(); i++) { if (region != NULL && _useRegion) { - if (!region->pointInRegion((int)_particles[i]->_pos.x, (int)_particles[i]->_pos.y)) continue; + if (!region->pointInRegion((int)_particles[i]->_pos.x, (int)_particles[i]->_pos.y)) { + continue; + } } _particles[i]->display(this); } - if (_sprites.getSize() <= 1) _gameRef->_renderer->endSpriteBatch(); + if (_sprites.getSize() <= 1) { + _gameRef->_renderer->endSpriteBatch(); + } return STATUS_OK; } @@ -339,9 +376,13 @@ int PartEmitter::compareZ(const void *obj1, const void *obj2) { PartParticle *p1 = *(PartParticle **)obj1; PartParticle *p2 = *(PartParticle **)obj2; - if (p1->_posZ < p2->_posZ) return -1; - else if (p1->_posZ > p2->_posZ) return 1; - else return 0; + if (p1->_posZ < p2->_posZ) { + return -1; + } else if (p1->_posZ > p2->_posZ) { + return 1; + } else { + return 0; + } } ////////////////////////////////////////////////////////////////////////// @@ -385,7 +426,9 @@ PartForce *PartEmitter::addForceByName(const char *name) { ////////////////////////////////////////////////////////////////////////// bool PartEmitter::addForce(const char *name, PartForce::TForceType type, int posX, int posY, float angle, float strength) { PartForce *force = addForceByName(name); - if (!force) return STATUS_FAILED; + if (!force) { + return STATUS_FAILED; + } force->_type = type; force->_pos = Vector2(posX, posY); @@ -554,9 +597,9 @@ bool PartEmitter::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt stack->pushBool(DID_SUCCEED(removeForce(forceName))); return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } ////////////////////////////////////////////////////////////////////////// @@ -745,7 +788,9 @@ ScValue *PartEmitter::scGetProperty(const char *name) { else if (strcmp(name, "NumLiveParticles") == 0) { int numAlive = 0; for (int i = 0; i < _particles.getSize(); i++) { - if (_particles[i] && !_particles[i]->_isDead) numAlive++; + if (_particles[i] && !_particles[i]->_isDead) { + numAlive++; + } } _scValue->setInt(numAlive); return _scValue; @@ -822,12 +867,15 @@ ScValue *PartEmitter::scGetProperty(const char *name) { // EmitEvent ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "EmitEvent") == 0) { - if (!_emitEvent) _scValue->setNULL(); - else _scValue->setString(_emitEvent); + if (!_emitEvent) { + _scValue->setNULL(); + } else { + _scValue->setString(_emitEvent); + } return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -978,8 +1026,12 @@ bool PartEmitter::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Alpha1") == 0) { _alpha1 = value->getInt(); - if (_alpha1 < 0) _alpha1 = 0; - if (_alpha1 > 255) _alpha1 = 255; + if (_alpha1 < 0) { + _alpha1 = 0; + } + if (_alpha1 > 255) { + _alpha1 = 255; + } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// @@ -987,8 +1039,12 @@ bool PartEmitter::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Alpha2") == 0) { _alpha2 = value->getInt(); - if (_alpha2 < 0) _alpha2 = 0; - if (_alpha2 > 255) _alpha2 = 255; + if (_alpha2 < 0) { + _alpha2 = 0; + } + if (_alpha2 > 255) { + _alpha2 = 255; + } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// @@ -1080,11 +1136,13 @@ bool PartEmitter::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "EmitEvent") == 0) { delete[] _emitEvent; _emitEvent = NULL; - if (!value->isNULL()) BaseUtils::setString(&_emitEvent, value->getString()); + if (!value->isNULL()) { + BaseUtils::setString(&_emitEvent, value->getString()); + } return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } diff --git a/engines/wintermute/base/particles/part_particle.cpp b/engines/wintermute/base/particles/part_particle.cpp index b63a82f926..4a5239edfe 100644 --- a/engines/wintermute/base/particles/part_particle.cpp +++ b/engines/wintermute/base/particles/part_particle.cpp @@ -99,24 +99,29 @@ bool PartParticle::update(PartEmitter *emitter, uint32 currentTime, uint32 timer if (currentTime - _fadeStart >= (uint32)_fadeTime) { _state = PARTICLE_NORMAL; _currentAlpha = _alpha1; - } else _currentAlpha = (int)(((float)currentTime - (float)_fadeStart) / (float)_fadeTime * _alpha1); + } else { + _currentAlpha = (int)(((float)currentTime - (float)_fadeStart) / (float)_fadeTime * _alpha1); + } return STATUS_OK; } else if (_state == PARTICLE_FADEOUT) { if (currentTime - _fadeStart >= (uint32)_fadeTime) { _isDead = true; return STATUS_OK; - } else _currentAlpha = _fadeStartAlpha - (int)(((float)currentTime - (float)_fadeStart) / (float)_fadeTime * _fadeStartAlpha); + } else { + _currentAlpha = _fadeStartAlpha - (int)(((float)currentTime - (float)_fadeStart) / (float)_fadeTime * _fadeStartAlpha); + } return STATUS_OK; } else { // time is up if (_lifeTime > 0) { if (currentTime - _creationTime >= (uint32)_lifeTime) { - if (emitter->_fadeOutTime > 0) + if (emitter->_fadeOutTime > 0) { fadeOut(currentTime, emitter->_fadeOutTime); - else + } else { _isDead = true; + } } } @@ -125,10 +130,13 @@ bool PartParticle::update(PartEmitter *emitter, uint32 currentTime, uint32 timer Point32 p; p.x = (int32)_pos.x; p.y = (int32)_pos.y; - if (!BasePlatform::ptInRect(&_border, p)) + if (!BasePlatform::ptInRect(&_border, p)) { fadeOut(currentTime, emitter->_fadeOutTime); + } + } + if (_state != PARTICLE_NORMAL) { + return STATUS_OK; } - if (_state != PARTICLE_NORMAL) return STATUS_OK; // update alpha if (_lifeTime > 0) { @@ -166,13 +174,15 @@ bool PartParticle::update(PartEmitter *emitter, uint32 currentTime, uint32 timer _rotation = BaseUtils::normalizeAngle(_rotation); // update scale - if (_exponentialGrowth) + if (_exponentialGrowth) { _scale += _scale / 100.0f * _growthRate * elapsedTime; - else + } else { _scale += _growthRate * elapsedTime; + } - if (_scale <= 0.0f) + if (_scale <= 0.0f) { _isDead = true; + } return STATUS_OK; @@ -181,8 +191,12 @@ bool PartParticle::update(PartEmitter *emitter, uint32 currentTime, uint32 timer ////////////////////////////////////////////////////////////////////////// bool PartParticle::display(PartEmitter *emitter) { - if (!_sprite) return STATUS_FAILED; - if (_isDead) return STATUS_OK; + if (!_sprite) { + return STATUS_FAILED; + } + if (_isDead) { + return STATUS_OK; + } _sprite->GetCurrentFrame(); return _sprite->display(_pos.x, _pos.y, diff --git a/engines/wintermute/base/scriptables/script.cpp b/engines/wintermute/base/scriptables/script.cpp index a519da5832..4deeb0bf39 100644 --- a/engines/wintermute/base/scriptables/script.cpp +++ b/engines/wintermute/base/scriptables/script.cpp @@ -249,17 +249,23 @@ bool ScScript::create(const char *filename, byte *buffer, uint32 size, BaseScrip _threadEvent = NULL; _filename = new char[strlen(filename) + 1]; - if (_filename) strcpy(_filename, filename); + if (_filename) { + strcpy(_filename, filename); + } _buffer = new byte [size]; - if (!_buffer) return STATUS_FAILED; + if (!_buffer) { + return STATUS_FAILED; + } memcpy(_buffer, buffer, size); _bufferSize = size; bool res = initScript(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } // establish global variables table _globals = new ScValue(_gameRef); @@ -277,22 +283,30 @@ bool ScScript::createThread(ScScript *original, uint32 initIP, const char *event _thread = true; _methodThread = false; _threadEvent = new char[strlen(eventName) + 1]; - if (_threadEvent) strcpy(_threadEvent, eventName); + if (_threadEvent) { + strcpy(_threadEvent, eventName); + } // copy filename _filename = new char[strlen(original->_filename) + 1]; - if (_filename) strcpy(_filename, original->_filename); + if (_filename) { + strcpy(_filename, original->_filename); + } // copy buffer _buffer = new byte [original->_bufferSize]; - if (!_buffer) return STATUS_FAILED; + if (!_buffer) { + return STATUS_FAILED; + } memcpy(_buffer, original->_buffer, original->_bufferSize); _bufferSize = original->_bufferSize; // initialize bool res = initScript(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } // copy globals _globals = original->_globals; @@ -317,29 +331,39 @@ bool ScScript::createThread(ScScript *original, uint32 initIP, const char *event ////////////////////////////////////////////////////////////////////////// bool ScScript::createMethodThread(ScScript *original, const char *methodName) { uint32 ip = original->getMethodPos(methodName); - if (ip == 0) return STATUS_FAILED; + if (ip == 0) { + return STATUS_FAILED; + } cleanup(); _thread = true; _methodThread = true; _threadEvent = new char[strlen(methodName) + 1]; - if (_threadEvent) strcpy(_threadEvent, methodName); + if (_threadEvent) { + strcpy(_threadEvent, methodName); + } // copy filename _filename = new char[strlen(original->_filename) + 1]; - if (_filename) strcpy(_filename, original->_filename); + if (_filename) { + strcpy(_filename, original->_filename); + } // copy buffer _buffer = new byte [original->_bufferSize]; - if (!_buffer) return STATUS_FAILED; + if (!_buffer) { + return STATUS_FAILED; + } memcpy(_buffer, original->_buffer, original->_bufferSize); _bufferSize = original->_bufferSize; // initialize bool res = initScript(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } // copy globals _globals = original->_globals; @@ -360,17 +384,25 @@ bool ScScript::createMethodThread(ScScript *original, const char *methodName) { ////////////////////////////////////////////////////////////////////////// void ScScript::cleanup() { - if (_buffer) delete[] _buffer; + if (_buffer) { + delete[] _buffer; + } _buffer = NULL; - if (_filename) delete[] _filename; + if (_filename) { + delete[] _filename; + } _filename = NULL; - if (_symbols) delete[] _symbols; + if (_symbols) { + delete[] _symbols; + } _symbols = NULL; _numSymbols = 0; - if (_globals && !_thread) delete _globals; + if (_globals && !_thread) { + delete _globals; + } _globals = NULL; delete _scopeStack; @@ -385,22 +417,30 @@ void ScScript::cleanup() { delete _stack; _stack = NULL; - if (_functions) delete[] _functions; + if (_functions) { + delete[] _functions; + } _functions = NULL; _numFunctions = 0; - if (_methods) delete[] _methods; + if (_methods) { + delete[] _methods; + } _methods = NULL; _numMethods = 0; - if (_events) delete[] _events; + if (_events) { + delete[] _events; + } _events = NULL; _numEvents = 0; if (_externals) { for (uint32 i = 0; i < _numExternals; i++) { - if (_externals[i].nu_params > 0) delete[] _externals[i].params; + if (_externals[i].nu_params > 0) { + delete[] _externals[i].params; + } } delete[] _externals; } @@ -423,7 +463,7 @@ void ScScript::cleanup() { _waitScript = NULL; _parentScript = NULL; // ref only - + delete _scriptStream; } @@ -460,7 +500,9 @@ double ScScript::getFloat() { ////////////////////////////////////////////////////////////////////////// char *ScScript::getString() { char *ret = (char *)(_buffer + _iP); - while (*(char *)(_buffer + _iP) != '\0') _iP++; + while (*(char *)(_buffer + _iP) != '\0') { + _iP++; + } _iP++; // string terminator _scriptStream->seek(_iP); @@ -489,12 +531,14 @@ bool ScScript::executeInstruction() { dw = getDWORD(); if (_scopeStack->_sP < 0) { _globals->setProp(_symbols[dw], _operand); - if (_gameRef->getDebugMgr()->_enabled) + if (_gameRef->getDebugMgr()->_enabled) { _gameRef->getDebugMgr()->onVariableInit(WME_DBGVAR_SCRIPT, this, NULL, _globals->getProp(_symbols[dw]), _symbols[dw]); + } } else { _scopeStack->getTop()->setProp(_symbols[dw], _operand); - if (_gameRef->getDebugMgr()->_enabled) + if (_gameRef->getDebugMgr()->_enabled) { _gameRef->getDebugMgr()->onVariableInit(WME_DBGVAR_SCOPE, this, _scopeStack->getTop(), _scopeStack->getTop()->getProp(_symbols[dw]), _symbols[dw]); + } } break; @@ -508,8 +552,9 @@ bool ScScript::executeInstruction() { _operand->setNULL(); _engine->_globals->setProp(_symbols[dw], _operand, false, inst == II_DEF_CONST_VAR); - if (_gameRef->getDebugMgr()->_enabled) + if (_gameRef->getDebugMgr()->_enabled) { _gameRef->getDebugMgr()->onVariableInit(WME_DBGVAR_GLOBAL, this, NULL, _engine->_globals->getProp(_symbols[dw]), _symbols[dw]); + } } break; } @@ -521,14 +566,20 @@ bool ScScript::executeInstruction() { _scopeStack->pop(); _iP = (uint32)_callStack->pop()->getInt(); - if (_scopeStack->_sP < 0) _gameRef->getDebugMgr()->onScriptChangeScope(this, NULL); - else _gameRef->getDebugMgr()->onScriptChangeScope(this, _scopeStack->getTop()); + if (_scopeStack->_sP < 0) { + _gameRef->getDebugMgr()->onScriptChangeScope(this, NULL); + } else { + _gameRef->getDebugMgr()->onScriptChangeScope(this, _scopeStack->getTop()); + } } else { if (_thread) { _state = SCRIPT_THREAD_FINISHED; } else { - if (_numEvents == 0 && _numMethods == 0) _state = SCRIPT_FINISHED; - else _state = SCRIPT_PERSISTENT; + if (_numEvents == 0 && _numMethods == 0) { + _state = SCRIPT_FINISHED; + } else { + _state = SCRIPT_PERSISTENT; + } } } @@ -557,7 +608,9 @@ bool ScScript::executeInstruction() { strcpy(MethodName, str); ScValue *var = _stack->pop(); - if (var->_type == VAL_VARIABLE_REF) var = var->_valRef; + if (var->_type == VAL_VARIABLE_REF) { + var = var->_valRef; + } bool res = STATUS_FAILED; bool TriedNative = false; @@ -612,7 +665,9 @@ bool ScScript::executeInstruction() { */ else { res = STATUS_FAILED; - if (var->_type == VAL_NATIVE && !TriedNative) res = var->_valNative->scCallMethod(this, _stack, _thisStack, MethodName); + if (var->_type == VAL_NATIVE && !TriedNative) { + res = var->_valNative->scCallMethod(this, _stack, _thisStack, MethodName); + } if (DID_FAIL(res)) { _stack->correctParams(0); @@ -631,7 +686,9 @@ bool ScScript::executeInstruction() { TExternalFunction *f = getExternal(_symbols[SymbolIndex]); if (f) { externalCall(_stack, _thisStack, f); - } else _gameRef->ExternalCall(this, _stack, _thisStack, _symbols[SymbolIndex]); + } else { + _gameRef->ExternalCall(this, _stack, _thisStack, _symbols[SymbolIndex]); + } break; } @@ -639,8 +696,11 @@ bool ScScript::executeInstruction() { _operand->setNULL(); _scopeStack->push(_operand); - if (_scopeStack->_sP < 0) _gameRef->getDebugMgr()->onScriptChangeScope(this, NULL); - else _gameRef->getDebugMgr()->onScriptChangeScope(this, _scopeStack->getTop()); + if (_scopeStack->_sP < 0) { + _gameRef->getDebugMgr()->onScriptChangeScope(this, NULL); + } else { + _gameRef->getDebugMgr()->onScriptChangeScope(this, _scopeStack->getTop()); + } break; @@ -663,7 +723,9 @@ bool ScScript::executeInstruction() { if (false && /*var->_type==VAL_OBJECT ||*/ var->_type == VAL_NATIVE) { _operand->setReference(var); _stack->push(_operand); - } else _stack->push(var); + } else { + _stack->push(var); + } break; } @@ -683,15 +745,19 @@ bool ScScript::executeInstruction() { runtimeError("Script stack corruption detected. Please report this script at WME bug reports forum."); var->setNULL(); } else { - if (val->getType() == VAL_VARIABLE_REF) val = val->_valRef; - if (val->_type == VAL_NATIVE) var->setValue(val); - else { + if (val->getType() == VAL_VARIABLE_REF) { + val = val->_valRef; + } + if (val->_type == VAL_NATIVE) { + var->setValue(val); + } else { var->copy(val); } } - if (_gameRef->getDebugMgr()->_enabled) + if (_gameRef->getDebugMgr()->_enabled) { _gameRef->getDebugMgr()->onVariableChangeValue(var, val); + } } break; @@ -740,8 +806,11 @@ bool ScScript::executeInstruction() { case II_PUSH_BY_EXP: { str = _stack->pop()->getString(); ScValue *val = _stack->pop()->getProp(str); - if (val) _stack->push(val); - else _stack->pushNULL(); + if (val) { + _stack->push(val); + } else { + _stack->pushNULL(); + } break; } @@ -754,10 +823,13 @@ bool ScScript::executeInstruction() { if (val == NULL) { runtimeError("Script stack corruption detected. Please report this script at WME bug reports forum."); var->setNULL(); - } else var->setProp(str, val); + } else { + var->setProp(str, val); + } - if (_gameRef->getDebugMgr()->_enabled) + if (_gameRef->getDebugMgr()->_enabled) { _gameRef->getDebugMgr()->onVariableChangeValue(var, NULL); + } break; } @@ -781,7 +853,9 @@ bool ScScript::executeInstruction() { if (!val) { runtimeError("Script corruption detected. Did you use '=' instead of '==' for comparison?"); } else { - if (!val->getBool()) _iP = dw; + if (!val->getBool()) { + _iP = dw; + } } break; } @@ -790,17 +864,19 @@ bool ScScript::executeInstruction() { op2 = _stack->pop(); op1 = _stack->pop(); - if (op1->isNULL() || op2->isNULL()) + if (op1->isNULL() || op2->isNULL()) { _operand->setNULL(); - else if (op1->getType() == VAL_STRING || op2->getType() == VAL_STRING) { + } else if (op1->getType() == VAL_STRING || op2->getType() == VAL_STRING) { char *tempStr = new char [strlen(op1->getString()) + strlen(op2->getString()) + 1]; strcpy(tempStr, op1->getString()); strcat(tempStr, op2->getString()); _operand->setString(tempStr); delete[] tempStr; - } else if (op1->getType() == VAL_INT && op2->getType() == VAL_INT) + } else if (op1->getType() == VAL_INT && op2->getType() == VAL_INT) { _operand->setInt(op1->getInt() + op2->getInt()); - else _operand->setFloat(op1->getFloat() + op2->getFloat()); + } else { + _operand->setFloat(op1->getFloat() + op2->getFloat()); + } _stack->push(_operand); @@ -810,11 +886,13 @@ bool ScScript::executeInstruction() { op2 = _stack->pop(); op1 = _stack->pop(); - if (op1->isNULL() || op2->isNULL()) + if (op1->isNULL() || op2->isNULL()) { _operand->setNULL(); - else if (op1->getType() == VAL_INT && op2->getType() == VAL_INT) + } else if (op1->getType() == VAL_INT && op2->getType() == VAL_INT) { _operand->setInt(op1->getInt() - op2->getInt()); - else _operand->setFloat(op1->getFloat() - op2->getFloat()); + } else { + _operand->setFloat(op1->getFloat() - op2->getFloat()); + } _stack->push(_operand); @@ -824,10 +902,13 @@ bool ScScript::executeInstruction() { op2 = _stack->pop(); op1 = _stack->pop(); - if (op1->isNULL() || op2->isNULL()) _operand->setNULL(); - else if (op1->getType() == VAL_INT && op2->getType() == VAL_INT) + if (op1->isNULL() || op2->isNULL()) { + _operand->setNULL(); + } else if (op1->getType() == VAL_INT && op2->getType() == VAL_INT) { _operand->setInt(op1->getInt() * op2->getInt()); - else _operand->setFloat(op1->getFloat() * op2->getFloat()); + } else { + _operand->setFloat(op1->getFloat() * op2->getFloat()); + } _stack->push(_operand); @@ -837,11 +918,15 @@ bool ScScript::executeInstruction() { op2 = _stack->pop(); op1 = _stack->pop(); - if (op2->getFloat() == 0.0f) + if (op2->getFloat() == 0.0f) { runtimeError("Division by zero."); + } - if (op1->isNULL() || op2->isNULL() || op2->getFloat() == 0.0f) _operand->setNULL(); - else _operand->setFloat(op1->getFloat() / op2->getFloat()); + if (op1->isNULL() || op2->isNULL() || op2->getFloat() == 0.0f) { + _operand->setNULL(); + } else { + _operand->setFloat(op1->getFloat() / op2->getFloat()); + } _stack->push(_operand); @@ -851,12 +936,15 @@ bool ScScript::executeInstruction() { op2 = _stack->pop(); op1 = _stack->pop(); - if (op2->getInt() == 0) + if (op2->getInt() == 0) { runtimeError("Division by zero."); + } - if (op1->isNULL() || op2->isNULL() || op2->getInt() == 0) + if (op1->isNULL() || op2->isNULL() || op2->getInt() == 0) { _operand->setNULL(); - else _operand->setInt(op1->getInt() % op2->getInt()); + } else { + _operand->setInt(op1->getInt() % op2->getInt()); + } _stack->push(_operand); @@ -865,8 +953,11 @@ bool ScScript::executeInstruction() { case II_NOT: op1 = _stack->pop(); //if (op1->isNULL()) _operand->setNULL(); - if (op1->isNULL()) _operand->setBool(true); - else _operand->setBool(!op1->getBool()); + if (op1->isNULL()) { + _operand->setBool(true); + } else { + _operand->setBool(!op1->getBool()); + } _stack->push(_operand); break; @@ -1060,8 +1151,9 @@ bool ScScript::executeInstruction() { ////////////////////////////////////////////////////////////////////////// uint32 ScScript::getFuncPos(const char *name) { for (uint32 i = 0; i < _numFunctions; i++) { - if (strcmp(name, _functions[i].name) == 0) + if (strcmp(name, _functions[i].name) == 0) { return _functions[i].pos; + } } return 0; } @@ -1070,8 +1162,9 @@ uint32 ScScript::getFuncPos(const char *name) { ////////////////////////////////////////////////////////////////////////// uint32 ScScript::getMethodPos(const char *name) { for (uint32 i = 0; i < _numMethods; i++) { - if (strcmp(name, _methods[i].name) == 0) + if (strcmp(name, _methods[i].name) == 0) { return _methods[i].pos; + } } return 0; } @@ -1083,20 +1176,23 @@ ScValue *ScScript::getVar(char *name) { // scope locals if (_scopeStack->_sP >= 0) { - if (_scopeStack->getTop()->propExists(name)) + if (_scopeStack->getTop()->propExists(name)) { ret = _scopeStack->getTop()->getProp(name); + } } // script globals if (ret == NULL) { - if (_globals->propExists(name)) + if (_globals->propExists(name)) { ret = _globals->getProp(name); + } } // engine globals if (ret == NULL) { - if (_engine->_globals->propExists(name)) + if (_engine->_globals->propExists(name)) { ret = _engine->_globals->getProp(name); + } } if (ret == NULL) { @@ -1162,7 +1258,9 @@ bool ScScript::finish(bool includingThreads) { if (_state != SCRIPT_FINISHED && includingThreads) { _state = SCRIPT_FINISHED; finishThreads(); - } else _state = SCRIPT_FINISHED; + } else { + _state = SCRIPT_FINISHED; + } return STATUS_OK; @@ -1188,8 +1286,9 @@ void ScScript::runtimeError(const char *fmt, ...) { _gameRef->LOG(0, "Runtime error. Script '%s', line %d", _filename, _currentLine); _gameRef->LOG(0, " %s", buff); - if (!_gameRef->_suppressScriptErrors) + if (!_gameRef->_suppressScriptErrors) { _gameRef->quickMessage("Script runtime error. View log for details."); + } } @@ -1217,8 +1316,8 @@ bool ScScript::persist(BasePersistenceManager *persistMgr) { initTables(); } else { _buffer = NULL; - _scriptStream = NULL; - } + _scriptStream = NULL; + } } persistMgr->transfer(TMEMBER(_callStack)); @@ -1249,7 +1348,9 @@ bool ScScript::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_unbreakable)); persistMgr->transfer(TMEMBER(_parentScript)); - if (!persistMgr->getIsSaving()) _tracingMode = false; + if (!persistMgr->getIsSaving()) { + _tracingMode = false; + } return STATUS_OK; } @@ -1260,7 +1361,9 @@ ScScript *ScScript::invokeEventHandler(const char *eventName, bool unbreakable) //if (_state!=SCRIPT_PERSISTENT) return NULL; uint32 pos = getEventPos(eventName); - if (!pos) return NULL; + if (!pos) { + return NULL; + } ScScript *thread = new ScScript(_gameRef, _engine); if (thread) { @@ -1274,7 +1377,9 @@ ScScript *ScScript::invokeEventHandler(const char *eventName, bool unbreakable) delete thread; return NULL; } - } else return NULL; + } else { + return NULL; + } } @@ -1282,7 +1387,9 @@ ScScript *ScScript::invokeEventHandler(const char *eventName, bool unbreakable) ////////////////////////////////////////////////////////////////////////// uint32 ScScript::getEventPos(const char *name) { for (int i = _numEvents - 1; i >= 0; i--) { - if (scumm_stricmp(name, _events[i].name) == 0) return _events[i].pos; + if (scumm_stricmp(name, _events[i].name) == 0) { + return _events[i].pos; + } } return 0; } @@ -1307,7 +1414,9 @@ bool ScScript::pause() { return STATUS_FAILED; } - if (!_freezable || _state == SCRIPT_PERSISTENT) return STATUS_OK; + if (!_freezable || _state == SCRIPT_PERSISTENT) { + return STATUS_OK; + } _origState = _state; _state = SCRIPT_PAUSED; @@ -1318,7 +1427,9 @@ bool ScScript::pause() { ////////////////////////////////////////////////////////////////////////// bool ScScript::resume() { - if (_state != SCRIPT_PAUSED) return STATUS_OK; + if (_state != SCRIPT_PAUSED) { + return STATUS_OK; + } _state = _origState; return STATUS_OK; @@ -1328,8 +1439,9 @@ bool ScScript::resume() { ////////////////////////////////////////////////////////////////////////// ScScript::TExternalFunction *ScScript::getExternal(char *name) { for (uint32 i = 0; i < _numExternals; i++) { - if (strcmp(name, _externals[i].name) == 0) + if (strcmp(name, _externals[i].name) == 0) { return &_externals[i]; + } } return NULL; } @@ -1354,7 +1466,9 @@ bool ScScript::copyParameters(ScStack *stack) { } _stack->pushInt(NumParams); - for (i = 0; i < NumParams; i++) stack->pop(); + for (i = 0; i < NumParams; i++) { + stack->pop(); + } return STATUS_OK; } @@ -1364,8 +1478,9 @@ bool ScScript::copyParameters(ScStack *stack) { bool ScScript::finishThreads() { for (int i = 0; i < _engine->_scripts.getSize(); i++) { ScScript *scr = _engine->_scripts[i]; - if (scr->_thread && scr->_state != SCRIPT_FINISHED && scr->_owner == _owner && scumm_stricmp(scr->_filename, _filename) == 0) + if (scr->_thread && scr->_state != SCRIPT_FINISHED && scr->_owner == _owner && scumm_stricmp(scr->_filename, _filename) == 0) { scr->finish(true); + } } return STATUS_OK; } @@ -1385,9 +1500,13 @@ const char *ScScript::dbgGetFilename() { ////////////////////////////////////////////////////////////////////////// bool ScScript::dbgSendScript(IWmeDebugClient *client) { - if (_methodThread) client->onScriptMethodThreadInit(this, _parentScript, _threadEvent); - else if (_thread) client->onScriptEventThreadInit(this, _parentScript, _threadEvent); - else client->onScriptInit(this); + if (_methodThread) { + client->onScriptMethodThreadInit(this, _parentScript, _threadEvent); + } else if (_thread) { + client->onScriptEventThreadInit(this, _parentScript, _threadEvent); + } else { + client->onScriptInit(this); + } return dbgSendVariables(client); return STATUS_OK; @@ -1421,8 +1540,11 @@ int ScScript::dbgGetNumBreakpoints() { ////////////////////////////////////////////////////////////////////////// int ScScript::dbgGetBreakpoint(int index) { - if (index >= 0 && index < _breakpoints.getSize()) return _breakpoints[index]; - else return -1; + if (index >= 0 && index < _breakpoints.getSize()) { + return _breakpoints[index]; + } else { + return -1; + } } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/base/scriptables/script_engine.cpp b/engines/wintermute/base/scriptables/script_engine.cpp index 792dfd4589..356617094d 100644 --- a/engines/wintermute/base/scriptables/script_engine.cpp +++ b/engines/wintermute/base/scriptables/script_engine.cpp @@ -47,8 +47,11 @@ IMPLEMENT_PERSISTENT(ScEngine, true) ScEngine::ScEngine(BaseGame *inGame): BaseClass(inGame) { _gameRef->LOG(0, "Initializing scripting engine..."); - if (_compilerAvailable) _gameRef->LOG(0, " Script compiler bound successfuly"); - else _gameRef->LOG(0, " Script compiler is NOT available"); + if (_compilerAvailable) { + _gameRef->LOG(0, " Script compiler bound successfuly"); + } else { + _gameRef->LOG(0, " Script compiler is NOT available"); + } _globals = new ScValue(_gameRef); @@ -68,7 +71,9 @@ ScEngine::ScEngine(BaseGame *inGame): BaseClass(inGame) { } // prepare script cache - for (int i = 0; i < MAX_CACHED_SCRIPTS; i++) _cachedScripts[i] = NULL; + for (int i = 0; i < MAX_CACHED_SCRIPTS; i++) { + _cachedScripts[i] = NULL; + } _currentScript = NULL; @@ -99,7 +104,9 @@ ScEngine::~ScEngine() { ////////////////////////////////////////////////////////////////////////// bool ScEngine::cleanup() { for (int i = 0; i < _scripts.getSize(); i++) { - if (!_scripts[i]->_thread && _scripts[i]->_owner) _scripts[i]->_owner->removeScript(_scripts[i]); + if (!_scripts[i]->_thread && _scripts[i]->_owner) { + _scripts[i]->_owner->removeScript(_scripts[i]); + } delete _scripts[i]; _scripts.removeAt(i); i--; @@ -143,7 +150,9 @@ ScScript *ScEngine::runScript(const char *filename, BaseScriptHolder *owner) { // get script from cache compBuffer = getCompiledScript(filename, &compSize); - if (!compBuffer) return NULL; + if (!compBuffer) { + return NULL; + } // add new script ScScript *script = new ScScript(_gameRef, this); @@ -155,8 +164,11 @@ ScScript *ScEngine::runScript(const char *filename, BaseScriptHolder *owner) { } else { // publish the "self" pseudo-variable ScValue val(_gameRef); - if (owner)val.setNative(owner, true); - else val.setNULL(); + if (owner) { + val.setNative(owner, true); + } else { + val.setNULL(); + } script->_globals->setProp("self", &val); script->_globals->setProp("this", &val); @@ -226,7 +238,9 @@ byte *ScEngine::getCompiledScript(const char *filename, uint32 *outSize, bool ig } } - if (_cachedScripts[index] != NULL) delete _cachedScripts[index]; + if (_cachedScripts[index] != NULL) { + delete _cachedScripts[index]; + } _cachedScripts[index] = cachedScript; ret = cachedScript->_buffer; @@ -244,8 +258,9 @@ byte *ScEngine::getCompiledScript(const char *filename, uint32 *outSize, bool ig ////////////////////////////////////////////////////////////////////////// bool ScEngine::tick() { - if (_scripts.getSize() == 0) + if (_scripts.getSize() == 0) { return STATUS_OK; + } // resolve waiting scripts @@ -267,16 +282,24 @@ bool ScEngine::tick() { if (!obj_found) _scripts[i]->finish(); // _waitObject no longer exists */ if (_gameRef->validObject(_scripts[i]->_waitObject)) { - if (_scripts[i]->_waitObject->isReady()) _scripts[i]->run(); - } else _scripts[i]->finish(); + if (_scripts[i]->_waitObject->isReady()) { + _scripts[i]->run(); + } + } else { + _scripts[i]->finish(); + } break; } case SCRIPT_SLEEPING: { if (_scripts[i]->_waitFrozen) { - if (_scripts[i]->_waitTime <= g_system->getMillis()) _scripts[i]->run(); + if (_scripts[i]->_waitTime <= g_system->getMillis()) { + _scripts[i]->run(); + } } else { - if (_scripts[i]->_waitTime <= _gameRef->_timer) _scripts[i]->run(); + if (_scripts[i]->_waitTime <= _gameRef->_timer) { + _scripts[i]->run(); + } } break; } @@ -309,7 +332,9 @@ bool ScEngine::tick() { for (int i = 0; i < _scripts.getSize(); i++) { // skip paused scripts - if (_scripts[i]->_state == SCRIPT_PAUSED) continue; + if (_scripts[i]->_state == SCRIPT_PAUSED) { + continue; + } // time sliced script if (_scripts[i]->_timeSlice > 0) { @@ -318,20 +343,26 @@ bool ScEngine::tick() { _currentScript = _scripts[i]; _scripts[i]->executeInstruction(); } - if (_isProfiling && _scripts[i]->_filename) addScriptTime(_scripts[i]->_filename, g_system->getMillis() - StartTime); + if (_isProfiling && _scripts[i]->_filename) { + addScriptTime(_scripts[i]->_filename, g_system->getMillis() - StartTime); + } } // normal script else { uint32 startTime = 0; bool isProfiling = _isProfiling; - if (isProfiling) startTime = g_system->getMillis(); + if (isProfiling) { + startTime = g_system->getMillis(); + } while (_scripts[i]->_state == SCRIPT_RUNNING) { _currentScript = _scripts[i]; _scripts[i]->executeInstruction(); } - if (isProfiling && _scripts[i]->_filename) addScriptTime(_scripts[i]->_filename, g_system->getMillis() - startTime); + if (isProfiling && _scripts[i]->_filename) { + addScriptTime(_scripts[i]->_filename, g_system->getMillis() - startTime); + } } _currentScript = NULL; } @@ -346,7 +377,9 @@ bool ScEngine::tick() { bool ScEngine::tickUnbreakable() { // execute unbreakable scripts for (int i = 0; i < _scripts.getSize(); i++) { - if (!_scripts[i]->_unbreakable) continue; + if (!_scripts[i]->_unbreakable) { + continue; + } while (_scripts[i]->_state == SCRIPT_RUNNING) { _currentScript = _scripts[i]; @@ -366,7 +399,9 @@ bool ScEngine::removeFinishedScripts() { // remove finished scripts for (int i = 0; i < _scripts.getSize(); i++) { if (_scripts[i]->_state == SCRIPT_FINISHED || _scripts[i]->_state == SCRIPT_ERROR) { - if (!_scripts[i]->_thread && _scripts[i]->_owner) _scripts[i]->_owner->removeScript(_scripts[i]); + if (!_scripts[i]->_thread && _scripts[i]->_owner) { + _scripts[i]->_owner->removeScript(_scripts[i]); + } _gameRef->getDebugMgr()->onScriptShutdown(_scripts[i]); delete _scripts[i]; _scripts.removeAt(i); @@ -382,7 +417,9 @@ int ScEngine::getNumScripts(int *running, int *waiting, int *persistent) { int numRunning = 0, numWaiting = 0, numPersistent = 0, numTotal = 0; for (int i = 0; i < _scripts.getSize(); i++) { - if (_scripts[i]->_state == SCRIPT_FINISHED) continue; + if (_scripts[i]->_state == SCRIPT_FINISHED) { + continue; + } switch (_scripts[i]->_state) { case SCRIPT_RUNNING: case SCRIPT_SLEEPING: @@ -401,9 +438,15 @@ int ScEngine::getNumScripts(int *running, int *waiting, int *persistent) { } numTotal++; } - if (running) *running = numRunning; - if (waiting) *waiting = numWaiting; - if (persistent) *persistent = numPersistent; + if (running) { + *running = numRunning; + } + if (waiting) { + *waiting = numWaiting; + } + if (persistent) { + *persistent = numPersistent; + } return numTotal; } @@ -426,7 +469,9 @@ bool ScEngine::resetObject(BaseObject *Object) { // terminate all scripts waiting for this object for (int i = 0; i < _scripts.getSize(); i++) { if (_scripts[i]->_state == SCRIPT_WAITING && _scripts[i]->_waitObject == Object) { - if (!_gameRef->_compatKillMethodThreads) resetScript(_scripts[i]); + if (!_gameRef->_compatKillMethodThreads) { + resetScript(_scripts[i]); + } bool IsThread = _scripts[i]->_methodThread || _scripts[i]->_thread; _scripts[i]->finish(!IsThread); // 1.9b1 - top-level script kills its threads as well @@ -448,7 +493,9 @@ bool ScEngine::resetScript(ScScript *script) { ////////////////////////////////////////////////////////////////////////// bool ScEngine::persist(BasePersistenceManager *persistMgr) { - if (!persistMgr->getIsSaving()) cleanup(); + if (!persistMgr->getIsSaving()) { + cleanup(); + } persistMgr->transfer(TMEMBER(_gameRef)); persistMgr->transfer(TMEMBER(_currentScript)); @@ -474,7 +521,9 @@ void ScEngine::editorCleanup() { ////////////////////////////////////////////////////////////////////////// bool ScEngine::pauseAll() { for (int i = 0; i < _scripts.getSize(); i++) { - if (_scripts[i] != _currentScript) _scripts[i]->pause(); + if (_scripts[i] != _currentScript) { + _scripts[i]->pause(); + } } return STATUS_OK; @@ -483,8 +532,9 @@ bool ScEngine::pauseAll() { ////////////////////////////////////////////////////////////////////////// bool ScEngine::resumeAll() { - for (int i = 0; i < _scripts.getSize(); i++) + for (int i = 0; i < _scripts.getSize(); i++) { _scripts[i]->resume(); + } return STATUS_OK; } @@ -493,7 +543,9 @@ bool ScEngine::resumeAll() { ////////////////////////////////////////////////////////////////////////// bool ScEngine::isValidScript(ScScript *script) { for (int i = 0; i < _scripts.getSize(); i++) { - if (_scripts[i] == script) return true; + if (_scripts[i] == script) { + return true; + } } return false; } @@ -511,14 +563,17 @@ bool ScEngine::dbgSendScripts(IWmeDebugClient *client) { // process normal scripts first for (int i = 0; i < _scripts.getSize(); i++) { - if (_scripts[i]->_thread || _scripts[i]->_methodThread) continue; + if (_scripts[i]->_thread || _scripts[i]->_methodThread) { + continue; + } _scripts[i]->dbgSendScript(client); } // and threads later for (int i = 0; i < _scripts.getSize(); i++) { - if (_scripts[i]->_thread || _scripts[i]->_methodThread) + if (_scripts[i]->_thread || _scripts[i]->_methodThread) { _scripts[i]->dbgSendScript(client); + } } return STATUS_OK; @@ -526,7 +581,9 @@ bool ScEngine::dbgSendScripts(IWmeDebugClient *client) { ////////////////////////////////////////////////////////////////////////// bool ScEngine::addBreakpoint(const char *scriptFilename, int line) { - if (!_gameRef->getDebugMgr()->_enabled) return STATUS_OK; + if (!_gameRef->getDebugMgr()->_enabled) { + return STATUS_OK; + } CScBreakpoint *bp = NULL; for (int i = 0; i < _breakpoints.getSize(); i++) { @@ -541,7 +598,9 @@ bool ScEngine::addBreakpoint(const char *scriptFilename, int line) { } for (int i = 0; i < bp->_lines.getSize(); i++) { - if (bp->_lines[i] == line) return STATUS_OK; + if (bp->_lines[i] == line) { + return STATUS_OK; + } } bp->_lines.add(line); @@ -553,7 +612,9 @@ bool ScEngine::addBreakpoint(const char *scriptFilename, int line) { ////////////////////////////////////////////////////////////////////////// bool ScEngine::removeBreakpoint(const char *scriptFilename, int line) { - if (!_gameRef->getDebugMgr()->_enabled) return STATUS_OK; + if (!_gameRef->getDebugMgr()->_enabled) { + return STATUS_OK; + } for (int i = 0; i < _breakpoints.getSize(); i++) { if (scumm_stricmp(_breakpoints[i]->_filename.c_str(), scriptFilename) == 0) { @@ -578,7 +639,9 @@ bool ScEngine::removeBreakpoint(const char *scriptFilename, int line) { ////////////////////////////////////////////////////////////////////////// bool ScEngine::refreshScriptBreakpoints() { - if (!_gameRef->getDebugMgr()->_enabled) return STATUS_OK; + if (!_gameRef->getDebugMgr()->_enabled) { + return STATUS_OK; + } for (int i = 0; i < _scripts.getSize(); i++) { refreshScriptBreakpoints(_scripts[i]); @@ -588,9 +651,13 @@ bool ScEngine::refreshScriptBreakpoints() { ////////////////////////////////////////////////////////////////////////// bool ScEngine::refreshScriptBreakpoints(ScScript *script) { - if (!_gameRef->getDebugMgr()->_enabled) return STATUS_OK; + if (!_gameRef->getDebugMgr()->_enabled) { + return STATUS_OK; + } - if (!script || !script->_filename) return STATUS_FAILED; + if (!script || !script->_filename) { + return STATUS_FAILED; + } for (int i = 0; i < _breakpoints.getSize(); i++) { if (scumm_stricmp(_breakpoints[i]->_filename.c_str(), script->_filename) == 0) { @@ -598,14 +665,18 @@ bool ScEngine::refreshScriptBreakpoints(ScScript *script) { return STATUS_OK; } } - if (script->_breakpoints.getSize() > 0) script->_breakpoints.removeAll(); + if (script->_breakpoints.getSize() > 0) { + script->_breakpoints.removeAll(); + } return STATUS_OK; } ////////////////////////////////////////////////////////////////////////// bool ScEngine::saveBreakpoints() { - if (!_gameRef->getDebugMgr()->_enabled) return STATUS_OK; + if (!_gameRef->getDebugMgr()->_enabled) { + return STATUS_OK; + } char text[512]; @@ -628,7 +699,9 @@ bool ScEngine::saveBreakpoints() { ////////////////////////////////////////////////////////////////////////// bool ScEngine::loadBreakpoints() { - if (!_gameRef->getDebugMgr()->_enabled) return STATUS_OK; + if (!_gameRef->getDebugMgr()->_enabled) { + return STATUS_OK; + } char key[100]; @@ -641,7 +714,9 @@ bool ScEngine::loadBreakpoints() { char *path = BaseUtils::strEntry(0, breakpoint.c_str(), ':'); char *line = BaseUtils::strEntry(1, breakpoint.c_str(), ':'); - if (path != NULL && line != NULL) addBreakpoint(path, atoi(line)); + if (path != NULL && line != NULL) { + addBreakpoint(path, atoi(line)); + } delete[] path; delete[] line; path = NULL; @@ -654,7 +729,9 @@ bool ScEngine::loadBreakpoints() { ////////////////////////////////////////////////////////////////////////// void ScEngine::addScriptTime(const char *filename, uint32 time) { - if (!_isProfiling) return; + if (!_isProfiling) { + return; + } AnsiString fileName = filename; fileName.toLowercase(); @@ -664,7 +741,9 @@ void ScEngine::addScriptTime(const char *filename, uint32 time) { ////////////////////////////////////////////////////////////////////////// void ScEngine::enableProfiling() { - if (_isProfiling) return; + if (_isProfiling) { + return; + } // destroy old data, if any _scriptTimes.clear(); @@ -676,7 +755,9 @@ void ScEngine::enableProfiling() { ////////////////////////////////////////////////////////////////////////// void ScEngine::disableProfiling() { - if (!_isProfiling) return; + if (!_isProfiling) { + return; + } dumpStats(); _isProfiling = false; diff --git a/engines/wintermute/base/scriptables/script_engine.h b/engines/wintermute/base/scriptables/script_engine.h index e443ec5832..fc441347df 100644 --- a/engines/wintermute/base/scriptables/script_engine.h +++ b/engines/wintermute/base/scriptables/script_engine.h @@ -48,13 +48,17 @@ public: CScCachedScript(const char *filename, byte *buffer, uint32 size) { _timestamp = g_system->getMillis(); _buffer = new byte[size]; - if (_buffer) memcpy(_buffer, buffer, size); + if (_buffer) { + memcpy(_buffer, buffer, size); + } _size = size; _filename = filename; }; ~CScCachedScript() { - if (_buffer) delete[] _buffer; + if (_buffer) { + delete[] _buffer; + } }; uint32 _timestamp; diff --git a/engines/wintermute/base/scriptables/script_ext_array.cpp b/engines/wintermute/base/scriptables/script_ext_array.cpp index 41059b2d80..0380103cd4 100644 --- a/engines/wintermute/base/scriptables/script_ext_array.cpp +++ b/engines/wintermute/base/scriptables/script_ext_array.cpp @@ -47,8 +47,9 @@ SXArray::SXArray(BaseGame *inGame, ScStack *stack): BaseScriptable(inGame) { int numParams = stack->pop()->getInt(0); - if (numParams == 1) _length = stack->pop()->getInt(0); - else if (numParams > 1) { + if (numParams == 1) { + _length = stack->pop()->getInt(0); + } else if (numParams > 1) { _length = numParams; char paramName[20]; for (int i = 0; i < numParams; i++) { @@ -86,7 +87,9 @@ const char *SXArray::scToString() { } } - if (i < _length - 1 && strlen(dummy) + 1 < 32768) strcat(dummy, ","); + if (i < _length - 1 && strlen(dummy) + 1 < 32768) { + strcat(dummy, ","); + } } return dummy; } @@ -124,12 +127,14 @@ bool SXArray::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->push(_values->getProp(paramName)); _values->deleteProp(paramName); _length--; - } else stack->pushNULL(); + } else { + stack->pushNULL(); + } return STATUS_OK; + } else { + return STATUS_FAILED; } - - else return STATUS_FAILED; } @@ -160,7 +165,9 @@ ScValue *SXArray::scGetProperty(const char *name) { char ParamName[20]; if (validNumber(name, ParamName)) { return _values->getProp(ParamName); - } else return _scValue; + } else { + return _scValue; + } } } @@ -190,10 +197,14 @@ bool SXArray::scSetProperty(const char *name, ScValue *value) { else { char paramName[20]; if (validNumber(name, paramName)) { - int Index = atoi(paramName); - if (Index >= _length) _length = Index + 1; + int index = atoi(paramName); + if (index >= _length) { + _length = index + 1; + } return _values->setProp(paramName, value); - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } } @@ -223,7 +234,9 @@ bool SXArray::validNumber(const char *origStr, char *outStr) { int index = atoi(origStr); sprintf(outStr, "%d", index); return true; - } else return false; + } else { + return false; + } } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/base/scriptables/script_ext_array.h b/engines/wintermute/base/scriptables/script_ext_array.h index 8eb86c4e69..67a1104b46 100644 --- a/engines/wintermute/base/scriptables/script_ext_array.h +++ b/engines/wintermute/base/scriptables/script_ext_array.h @@ -35,7 +35,7 @@ namespace WinterMute { class SXArray : public BaseScriptable { public: - bool push(ScValue *Val); + bool push(ScValue *val); bool validNumber(const char *origStr, char *outStr); DECLARE_PERSISTENT(SXArray, BaseScriptable) SXArray(BaseGame *inGame, ScStack *stack); diff --git a/engines/wintermute/base/scriptables/script_ext_date.cpp b/engines/wintermute/base/scriptables/script_ext_date.cpp index d2fd3663c7..a3bb7e2183 100644 --- a/engines/wintermute/base/scriptables/script_ext_date.cpp +++ b/engines/wintermute/base/scriptables/script_ext_date.cpp @@ -199,10 +199,9 @@ bool SXDate::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, g_system->getTimeAndDate(_tm); stack->pushNULL(); return STATUS_OK; - } - - else + } else { return STATUS_FAILED; + } } @@ -216,9 +215,9 @@ ScValue *SXDate::scGetProperty(const char *name) { if (strcmp(name, "Type") == 0) { _scValue->setString("date"); return _scValue; + } else { + return _scValue; } - - else return _scValue; } diff --git a/engines/wintermute/base/scriptables/script_ext_file.cpp b/engines/wintermute/base/scriptables/script_ext_file.cpp index 7da1601bdc..437fbb64a2 100644 --- a/engines/wintermute/base/scriptables/script_ext_file.cpp +++ b/engines/wintermute/base/scriptables/script_ext_file.cpp @@ -51,10 +51,12 @@ BaseScriptable *makeSXFile(BaseGame *inGame, ScStack *stack) { ////////////////////////////////////////////////////////////////////////// SXFile::SXFile(BaseGame *inGame, ScStack *stack): BaseScriptable(inGame) { stack->correctParams(1); - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); _filename = NULL; - if (!Val->isNULL()) BaseUtils::setString(&_filename, Val->getString()); + if (!val->isNULL()) { + BaseUtils::setString(&_filename, val->getString()); + } _readFile = NULL; _writeFile = NULL; @@ -94,8 +96,11 @@ void SXFile::close() { ////////////////////////////////////////////////////////////////////////// const char *SXFile::scToString() { - if (_filename) return _filename; - else return "[file object]"; + if (_filename) { + return _filename; + } else { + return "[file object]"; + } } #define FILE_BUFFER_SIZE 32768 @@ -129,24 +134,37 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (!_readFile) { //script->runtimeError("File.%s: Error opening file '%s' for reading.", Name, _filename); close(); - } else _textMode = strcmp(name, "OpenAsText") == 0; + } else { + _textMode = strcmp(name, "OpenAsText") == 0; + } } else { if (strcmp(name, "OpenAsText") == 0) { - if (_mode == 2) _writeFile = openForWrite(_filename, false); - else _writeFile = openForAppend(_filename, false); + if (_mode == 2) { + _writeFile = openForWrite(_filename, false); + } else { + _writeFile = openForAppend(_filename, false); + } } else { - if (_mode == 2) _writeFile = openForWrite(_filename, true); - else _writeFile = openForAppend(_filename, true); + if (_mode == 2) { + _writeFile = openForWrite(_filename, true); + } else { + _writeFile = openForAppend(_filename, true); + } } if (!_writeFile) { //script->runtimeError("File.%s: Error opening file '%s' for writing.", Name, _filename); close(); - } else _textMode = strcmp(name, "OpenAsText") == 0; + } else { + _textMode = strcmp(name, "OpenAsText") == 0; + } } - if (_readFile || _writeFile) stack->pushBool(true); - else stack->pushBool(false); + if (_readFile || _writeFile) { + stack->pushBool(true); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -221,7 +239,9 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, bool ret = STATUS_FAILED; do { ret = _readFile->read(&b, 1); - if (ret != 1) break; + if (ret != 1) { + break; + } if (counter > bufSize) { buf = (byte *)realloc(buf, bufSize + FILE_BUFFER_SIZE); @@ -231,8 +251,9 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, buf[counter] = '\0'; foundNewLine = true; break; - } else if (b == 0x0D) continue; - else { + } else if (b == 0x0D) { + continue; + } else { buf[counter] = b; counter++; } @@ -244,8 +265,11 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } buf[counter] = '\0'; - if (!foundNewLine && counter == 0) stack->pushNULL(); - else stack->pushString((char *)buf); + if (!foundNewLine && counter == 0) { + stack->pushNULL(); + } else { + stack->pushString((char *)buf); + } free(buf); @@ -272,14 +296,17 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, bool ret = STATUS_FAILED; while (counter < (uint32)textLen) { ret = _readFile->read(&b, 1); - if (ret != 1) break; + if (ret != 1) { + break; + } if (counter > bufSize) { buf = (byte *)realloc(buf, bufSize + FILE_BUFFER_SIZE); bufSize += FILE_BUFFER_SIZE; } - if (b == 0x0D) continue; - else { + if (b == 0x0D) { + continue; + } else { buf[counter] = b; counter++; } @@ -291,8 +318,11 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, } buf[counter] = '\0'; - if (textLen > 0 && counter == 0) stack->pushNULL(); - else stack->pushString((char *)buf); + if (textLen > 0 && counter == 0) { + stack->pushNULL(); + } else { + stack->pushString((char *)buf); + } free(buf); @@ -335,8 +365,11 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, return STATUS_OK; } bool val; - if (_readFile->read(&val, sizeof(bool)) == sizeof(bool)) stack->pushBool(val); - else stack->pushNULL(); + if (_readFile->read(&val, sizeof(bool)) == sizeof(bool)) { + stack->pushBool(val); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -355,8 +388,8 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (!_readFile->err()) { stack->pushInt(val); } else { - stack->pushNULL(); - } + stack->pushNULL(); + } return STATUS_OK; } @@ -375,7 +408,7 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (!_readFile->err()) { stack->pushInt(65536 + val); } else { - stack->pushNULL(); + stack->pushNULL(); } return STATUS_OK; } @@ -411,7 +444,7 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, return STATUS_OK; } float val; - (*(uint32*)&val) = _readFile->readUint32LE(); + (*(uint32 *)&val) = _readFile->readUint32LE(); if (!_readFile->err()) { stack->pushFloat(val); } else { @@ -433,8 +466,11 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, return STATUS_OK; } double val; - if (_readFile->read(&val, sizeof(double)) == sizeof(double)) stack->pushFloat(val); - else stack->pushNULL(); + if (_readFile->read(&val, sizeof(double)) == sizeof(double)) { + stack->pushFloat(val); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -458,8 +494,12 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->pushString((char *)str); } delete[] str; - } else stack->pushNULL(); - } else stack->pushNULL(); + } else { + stack->pushNULL(); + } + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -548,7 +588,7 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->pushBool(false); return STATUS_OK; } - uint32 *ptr = (uint32*)&val; + uint32 *ptr = (uint32 *)&val; _writeFile->writeUint32LE(*ptr); stack->pushBool(true); @@ -594,10 +634,9 @@ bool SXFile::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->pushBool(true); return STATUS_OK; + } else { + return BaseScriptable::scCallMethod(script, stack, thisStack, name); } - - - else return BaseScriptable::scCallMethod(script, stack, thisStack, name); } @@ -651,9 +690,9 @@ ScValue *SXFile::scGetProperty(const char *name) { else if (strcmp(name, "AccessMode") == 0) { _scValue->setInt(_mode); return _scValue; + } else { + return BaseScriptable::scGetProperty(name); } - - else return BaseScriptable::scGetProperty(name); } @@ -681,43 +720,46 @@ bool SXFile::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// uint32 SXFile::getPos() { - if (_mode == 1 && _readFile) + if (_mode == 1 && _readFile) { return _readFile->pos(); - else if ((_mode == 2 || _mode == 3) && _writeFile) { + } else if ((_mode == 2 || _mode == 3) && _writeFile) { error("SXFile - getPos for WriteFile not supported"); return 0; // return ftell((FILE *)_writeFile); - } else { + } else { return 0; } } ////////////////////////////////////////////////////////////////////////// bool SXFile::setPos(uint32 pos, int whence) { - if (_mode == 1 && _readFile) + if (_mode == 1 && _readFile) { return _readFile->seek(pos, whence); - else if ((_mode == 2 || _mode == 3) && _writeFile) { + } else if ((_mode == 2 || _mode == 3) && _writeFile) { error("SXFile - seeking in WriteFile not supported"); return false; // return fseek((FILE *)_writeFile, pos, (int)origin) == 0; + } else { + return false; } - else return false; } ////////////////////////////////////////////////////////////////////////// uint32 SXFile::getLength() { - if (_mode == 1 && _readFile) + if (_mode == 1 && _readFile) { return _readFile->size(); - else if ((_mode == 2 || _mode == 3) && _writeFile) { + } else if ((_mode == 2 || _mode == 3) && _writeFile) { error("SXFile - reading length for WriteFile not supported"); return 0; -/* - uint32 currentPos = ftell((FILE *)_writeFile); - fseek((FILE *)_writeFile, 0, SEEK_END); - int ret = ftell((FILE *)_writeFile); - fseek((FILE *)_writeFile, CurrentPos, SEEK_SET); - return Ret;*/ - } else return 0; + /* + uint32 currentPos = ftell((FILE *)_writeFile); + fseek((FILE *)_writeFile, 0, SEEK_END); + int ret = ftell((FILE *)_writeFile); + fseek((FILE *)_writeFile, CurrentPos, SEEK_SET); + return Ret;*/ + } else { + return 0; + } } ////////////////////////////////////////////////////////////////////////// @@ -744,24 +786,28 @@ bool SXFile::persist(BasePersistenceManager *persistMgr) { // open for reading if (_mode == 1) { _readFile = _gameRef->_fileManager->openFile(_filename); - if (!_readFile) + if (!_readFile) { close(); + } } // open for writing / appending else { if (_textMode) { - if (_mode == 2) + if (_mode == 2) { _writeFile = openForWrite(_filename, false); - else + } else { _writeFile = openForAppend(_filename, false); + } } else { - if (_mode == 2) + if (_mode == 2) { _writeFile = openForWrite(_filename, true); - else + } else { _writeFile = openForAppend(_filename, true); + } } - if (_writeFile) + if (_writeFile) { close(); + } } setPos(pos); } @@ -777,7 +823,7 @@ Common::WriteStream *SXFile::openForWrite(const Common::String &filename, bool b // Should replace fopen(..., "ab+") and fopen(..., "a+") Common::WriteStream *SXFile::openForAppend(const Common::String &filename, bool binary) { - error("SXFile::openForAppend - WriteFiles not supported"); + error("SXFile::openForAppend - WriteFiles not supported"); } } // end of namespace WinterMute diff --git a/engines/wintermute/base/scriptables/script_ext_math.cpp b/engines/wintermute/base/scriptables/script_ext_math.cpp index 1c37a15aa9..525b43434f 100644 --- a/engines/wintermute/base/scriptables/script_ext_math.cpp +++ b/engines/wintermute/base/scriptables/script_ext_math.cpp @@ -243,9 +243,9 @@ bool SXMath::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, stack->correctParams(1); stack->pushFloat(radianToDegree(stack->pop()->getFloat())); return STATUS_OK; + } else { + return STATUS_FAILED; } - - else return STATUS_FAILED; } @@ -267,9 +267,9 @@ ScValue *SXMath::scGetProperty(const char *name) { else if (strcmp(name, "PI") == 0) { _scValue->setFloat(M_PI); return _scValue; + } else { + return _scValue; } - - else return _scValue; } diff --git a/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp b/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp index 3d3f0b218b..e15af3446e 100644 --- a/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp +++ b/engines/wintermute/base/scriptables/script_ext_mem_buffer.cpp @@ -70,7 +70,9 @@ void *SXMemBuffer::scToMemBuffer() { ////////////////////////////////////////////////////////////////////////// void SXMemBuffer::cleanup() { - if (_size) free(_buffer); + if (_size) { + free(_buffer); + } _buffer = NULL; _size = 0; } @@ -81,14 +83,18 @@ bool SXMemBuffer::resize(int newSize) { if (_size == 0) { _buffer = malloc(newSize); - if (_buffer) _size = newSize; + if (_buffer) { + _size = newSize; + } } else { void *newBuf = realloc(_buffer, newSize); if (!newBuf) { if (newSize == 0) { _buffer = newBuf; _size = newSize; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } else { _buffer = newBuf; _size = newSize; @@ -107,14 +113,16 @@ bool SXMemBuffer::checkBounds(ScScript *script, int start, int length) { script->runtimeError("Cannot use Set/Get methods on an uninitialized memory buffer"); return false; } - if (_size == 0) + if (_size == 0) { return true; + } if (start < 0 || length == 0 || start + length > _size) { script->runtimeError("Set/Get method call is out of bounds"); return false; - } else + } else { return true; + } } ////////////////////////////////////////////////////////////////////////// @@ -132,10 +140,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt stack->correctParams(1); int newSize = stack->pop()->getInt(); newSize = MAX(0, newSize); - if (DID_SUCCEED(resize(newSize))) + if (DID_SUCCEED(resize(newSize))) { stack->pushBool(true); - else + } else { stack->pushBool(false); + } return STATUS_OK; } @@ -146,10 +155,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetBool") == 0) { stack->correctParams(1); int start = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(bool))) + if (!checkBounds(script, start, sizeof(bool))) { stack->pushNULL(); - else + } else { stack->pushBool(*(bool *)((byte *)_buffer + start)); + } return STATUS_OK; } @@ -160,10 +170,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetByte") == 0) { stack->correctParams(1); int start = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(byte))) + if (!checkBounds(script, start, sizeof(byte))) { stack->pushNULL(); - else + } else { stack->pushInt(*(byte *)((byte *)_buffer + start)); + } return STATUS_OK; } @@ -174,10 +185,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetShort") == 0) { stack->correctParams(1); int Start = stack->pop()->getInt(); - if (!checkBounds(script, Start, sizeof(short))) + if (!checkBounds(script, Start, sizeof(short))) { stack->pushNULL(); - else + } else { stack->pushInt(65536 + * (short *)((byte *)_buffer + Start)); + } return STATUS_OK; } @@ -188,10 +200,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetInt") == 0 || strcmp(name, "GetLong") == 0) { stack->correctParams(1); int start = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(int))) + if (!checkBounds(script, start, sizeof(int))) { stack->pushNULL(); - else + } else { stack->pushInt(*(int *)((byte *)_buffer + start)); + } return STATUS_OK; } @@ -202,10 +215,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetFloat") == 0) { stack->correctParams(1); int start = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(float))) + if (!checkBounds(script, start, sizeof(float))) { stack->pushNULL(); - else + } else { stack->pushFloat(*(float *)((byte *)_buffer + start)); + } return STATUS_OK; } @@ -216,10 +230,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetDouble") == 0) { stack->correctParams(1); int start = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(double))) + if (!checkBounds(script, start, sizeof(double))) { stack->pushNULL(); - else + } else { stack->pushFloat(*(double *)((byte *)_buffer + start)); + } return STATUS_OK; } @@ -242,9 +257,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt } } - if (!checkBounds(script, start, length)) + if (!checkBounds(script, start, length)) { stack->pushNULL(); - else { + } else { char *str = new char[length + 1]; strncpy(str, (const char *)_buffer + start, length); str[length] = '\0'; @@ -260,9 +275,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "GetPointer") == 0) { stack->correctParams(1); int start = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(void *))) + if (!checkBounds(script, start, sizeof(void *))) { stack->pushNULL(); - else { + } else { void *pointer = *(void **)((byte *)_buffer + start); SXMemBuffer *buf = new SXMemBuffer(_gameRef, pointer); stack->pushNative(buf, false); @@ -278,9 +293,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); bool val = stack->pop()->getBool(); - if (!checkBounds(script, start, sizeof(bool))) + if (!checkBounds(script, start, sizeof(bool))) { stack->pushBool(false); - else { + } else { *(bool *)((byte *)_buffer + start) = val; stack->pushBool(true); } @@ -295,9 +310,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); byte val = (byte)stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(byte))) + if (!checkBounds(script, start, sizeof(byte))) { stack->pushBool(false); - else { + } else { *(byte *)((byte *)_buffer + start) = val; stack->pushBool(true); } @@ -312,9 +327,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); short val = (short)stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(short))) + if (!checkBounds(script, start, sizeof(short))) { stack->pushBool(false); - else { + } else { *(short *)((byte *)_buffer + start) = val; stack->pushBool(true); } @@ -329,9 +344,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); int val = stack->pop()->getInt(); - if (!checkBounds(script, start, sizeof(int))) + if (!checkBounds(script, start, sizeof(int))) { stack->pushBool(false); - else { + } else { *(int *)((byte *)_buffer + start) = val; stack->pushBool(true); } @@ -346,9 +361,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); float val = (float)stack->pop()->getFloat(); - if (!checkBounds(script, start, sizeof(float))) + if (!checkBounds(script, start, sizeof(float))) { stack->pushBool(false); - else { + } else { *(float *)((byte *)_buffer + start) = val; stack->pushBool(true); } @@ -363,9 +378,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); double val = stack->pop()->getFloat(); - if (!checkBounds(script, start, sizeof(double))) + if (!checkBounds(script, start, sizeof(double))) { stack->pushBool(false); - else { + } else { *(double *)((byte *)_buffer + start) = val; stack->pushBool(true); } @@ -380,9 +395,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt int start = stack->pop()->getInt(); const char *val = stack->pop()->getString(); - if (!checkBounds(script, start, strlen(val) + 1)) + if (!checkBounds(script, start, strlen(val) + 1)) { stack->pushBool(false); - else { + } else { memcpy((byte *)_buffer + start, val, strlen(val) + 1); stack->pushBool(true); } @@ -395,11 +410,11 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt else if (strcmp(name, "SetPointer") == 0) { stack->correctParams(2); int start = stack->pop()->getInt(); - /* ScValue *Val = */ stack->pop(); + /* ScValue *val = */ stack->pop(); - if (!checkBounds(script, start, sizeof(void *))) + if (!checkBounds(script, start, sizeof(void *))) { stack->pushBool(false); - else { + } else { /* int Pointer = (int)Val->getMemBuffer(); memcpy((byte *)_buffer+Start, &Pointer, sizeof(void*)); @@ -426,9 +441,9 @@ bool SXMemBuffer::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisSt } stack->pushNULL(); return STATUS_OK; + } else { + return STATUS_FAILED; } - - else return STATUS_FAILED; } @@ -450,9 +465,9 @@ ScValue *SXMemBuffer::scGetProperty(const char *name) { if (strcmp(name, "Size") == 0) { _scValue->setInt(_size); return _scValue; + } else { + return BaseScriptable::scGetProperty(name); } - - else return BaseScriptable::scGetProperty(name); } @@ -487,12 +502,16 @@ bool SXMemBuffer::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_size)); if (persistMgr->getIsSaving()) { - if (_size > 0) persistMgr->putBytes((byte *)_buffer, _size); + if (_size > 0) { + persistMgr->putBytes((byte *)_buffer, _size); + } } else { if (_size > 0) { _buffer = malloc(_size); persistMgr->getBytes((byte *)_buffer, _size); - } else _buffer = NULL; + } else { + _buffer = NULL; + } } return STATUS_OK; @@ -501,8 +520,11 @@ bool SXMemBuffer::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// int SXMemBuffer::scCompare(BaseScriptable *val) { - if (_buffer == val->scToMemBuffer()) return 0; - else return 1; + if (_buffer == val->scToMemBuffer()) { + return 0; + } else { + return 1; + } } } // end of namespace WinterMute diff --git a/engines/wintermute/base/scriptables/script_ext_string.cpp b/engines/wintermute/base/scriptables/script_ext_string.cpp index 385d7ca746..1c7349bd8d 100644 --- a/engines/wintermute/base/scriptables/script_ext_string.cpp +++ b/engines/wintermute/base/scriptables/script_ext_string.cpp @@ -61,13 +61,17 @@ SXString::SXString(BaseGame *inGame, ScStack *stack): BaseScriptable(inGame) { setStringVal(val->getString()); } - if (_capacity == 0) setStringVal(""); + if (_capacity == 0) { + setStringVal(""); + } } ////////////////////////////////////////////////////////////////////////// SXString::~SXString() { - if (_string) delete[] _string; + if (_string) { + delete[] _string; + } } @@ -87,8 +91,11 @@ void SXString::setStringVal(const char *val) { ////////////////////////////////////////////////////////////////////////// const char *SXString::scToString() { - if (_string) return _string; - else return "[null string]"; + if (_string) { + return _string; + } else { + return "[null string]"; + } } @@ -108,22 +115,26 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int start = stack->pop()->getInt(); int end = stack->pop()->getInt(); - if (end < start) BaseUtils::swap(&start, &end); + if (end < start) { + BaseUtils::swap(&start, &end); + } //try { WideString str; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { str = StringUtil::utf8ToWide(_string); - else + } else { str = StringUtil::ansiToWide(_string); + } //WideString subStr = str.substr(start, end - start + 1); WideString subStr(str.c_str() + start, end - start + 1); - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { stack->pushString(StringUtil::wideToUtf8(subStr).c_str()); - else + } else { stack->pushString(StringUtil::wideToAnsi(subStr).c_str()); + } // } catch (std::exception &) { // stack->pushNULL(); // } @@ -146,22 +157,26 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack return STATUS_OK; } - if (val->isNULL()) len = strlen(_string) - start; + if (val->isNULL()) { + len = strlen(_string) - start; + } // try { WideString str; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { str = StringUtil::utf8ToWide(_string); - else + } else { str = StringUtil::ansiToWide(_string); + } // WideString subStr = str.substr(start, len); WideString subStr(str.c_str() + start, len); - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { stack->pushString(StringUtil::wideToUtf8(subStr).c_str()); - else + } else { stack->pushString(StringUtil::wideToAnsi(subStr).c_str()); + } // } catch (std::exception &) { // stack->pushNULL(); // } @@ -176,17 +191,19 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(0); WideString str; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { str = StringUtil::utf8ToWide(_string); - else + } else { str = StringUtil::ansiToWide(_string); + } str.toUppercase(); - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { stack->pushString(StringUtil::wideToUtf8(str).c_str()); - else + } else { stack->pushString(StringUtil::wideToAnsi(str).c_str()); + } return STATUS_OK; } @@ -198,17 +215,19 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(0); WideString str; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { str = StringUtil::utf8ToWide(_string); - else + } else { str = StringUtil::ansiToWide(_string); + } str.toLowercase(); - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { stack->pushString(StringUtil::wideToUtf8(str).c_str()); - else + } else { stack->pushString(StringUtil::wideToAnsi(str).c_str()); + } return STATUS_OK; } @@ -223,16 +242,18 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack int index = stack->pop()->getInt(); WideString str; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { str = StringUtil::utf8ToWide(_string); - else + } else { str = StringUtil::ansiToWide(_string); + } WideString toFind; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { toFind = StringUtil::utf8ToWide(strToFind); - else + } else { toFind = StringUtil::ansiToWide(strToFind); + } int indexOf = StringUtil::indexOf(str, toFind, index); stack->pushInt(indexOf); @@ -247,7 +268,9 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); ScValue *val = stack->pop(); char separators[MAX_PATH_LENGTH] = ","; - if (!val->isNULL()) strcpy(separators, val->getString()); + if (!val->isNULL()) { + strcpy(separators, val->getString()); + } SXArray *array = new SXArray(_gameRef); if (!array) { @@ -257,16 +280,18 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack WideString str; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { str = StringUtil::utf8ToWide(_string); - else + } else { str = StringUtil::ansiToWide(_string); + } WideString delims; - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { delims = StringUtil::utf8ToWide(separators); - else + } else { delims = StringUtil::ansiToWide(separators); + } Common::Array parts; @@ -298,10 +323,11 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack for (Common::Array::iterator it = parts.begin(); it != parts.end(); ++it) { WideString &part = (*it); - if (_gameRef->_textEncoding == TEXT_UTF8) + if (_gameRef->_textEncoding == TEXT_UTF8) { val = new ScValue(_gameRef, StringUtil::wideToUtf8(part).c_str()); - else + } else { val = new ScValue(_gameRef, StringUtil::wideToAnsi(part).c_str()); + } array->push(val); delete val; @@ -310,9 +336,9 @@ bool SXString::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->pushNative(array, false); return STATUS_OK; + } else { + return STATUS_FAILED; } - - else return STATUS_FAILED; } @@ -334,8 +360,9 @@ ScValue *SXString::scGetProperty(const char *name) { if (_gameRef->_textEncoding == TEXT_UTF8) { WideString wstr = StringUtil::utf8ToWide(_string); _scValue->setInt(wstr.size()); - } else + } else { _scValue->setInt(strlen(_string)); + } return _scValue; } @@ -345,9 +372,9 @@ ScValue *SXString::scGetProperty(const char *name) { else if (strcmp(name, "Capacity") == 0) { _scValue->setInt(_capacity); return _scValue; + } else { + return _scValue; } - - else return _scValue; } @@ -358,8 +385,9 @@ bool SXString::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "Capacity") == 0) { int32 newCap = (uint32)value->getInt(); - if (newCap < (int32)(strlen(_string) + 1)) _gameRef->LOG(0, "Warning: cannot lower string capacity"); - else if (newCap != _capacity) { + if (newCap < (int32)(strlen(_string) + 1)) { + _gameRef->LOG(0, "Warning: cannot lower string capacity"); + } else if (newCap != _capacity) { char *newStr = new char[newCap]; if (newStr) { memset(newStr, 0, newCap); @@ -370,9 +398,9 @@ bool SXString::scSetProperty(const char *name, ScValue *value) { } } return STATUS_OK; + } else { + return STATUS_FAILED; } - - else return STATUS_FAILED; } @@ -384,12 +412,16 @@ bool SXString::persist(BasePersistenceManager *persistMgr) { persistMgr->transfer(TMEMBER(_capacity)); if (persistMgr->getIsSaving()) { - if (_capacity > 0) persistMgr->putBytes((byte *)_string, _capacity); + if (_capacity > 0) { + persistMgr->putBytes((byte *)_string, _capacity); + } } else { if (_capacity > 0) { _string = new char[_capacity]; persistMgr->getBytes((byte *)_string, _capacity); - } else _string = NULL; + } else { + _string = NULL; + } } return STATUS_OK; diff --git a/engines/wintermute/base/scriptables/script_stack.cpp b/engines/wintermute/base/scriptables/script_stack.cpp index 74cc7a57ee..0d4ea54b8c 100644 --- a/engines/wintermute/base/scriptables/script_stack.cpp +++ b/engines/wintermute/base/scriptables/script_stack.cpp @@ -96,16 +96,22 @@ ScValue *ScStack::getPushValue() { ////////////////////////////////////////////////////////////////////////// ScValue *ScStack::getTop() { - if (_sP < 0 || _sP >= _values.getSize()) return NULL; - else return _values[_sP]; + if (_sP < 0 || _sP >= _values.getSize()) { + return NULL; + } else { + return _values[_sP]; + } } ////////////////////////////////////////////////////////////////////////// ScValue *ScStack::getAt(int index) { index = _sP - index; - if (index < 0 || index >= _values.getSize()) return NULL; - else return _values[index]; + if (index < 0 || index >= _values.getSize()) { + return NULL; + } else { + return _values[index]; + } } diff --git a/engines/wintermute/base/scriptables/script_value.cpp b/engines/wintermute/base/scriptables/script_value.cpp index 5e824cd10c..01cb4044ff 100644 --- a/engines/wintermute/base/scriptables/script_value.cpp +++ b/engines/wintermute/base/scriptables/script_value.cpp @@ -122,7 +122,9 @@ ScValue::ScValue(BaseGame *inGame, const char *val): BaseClass(inGame) { void ScValue::cleanup(bool ignoreNatives) { deleteProps(); - if (_valString) delete[] _valString; + if (_valString) { + delete[] _valString; + } if (!ignoreNatives) { if (_valNative && !_persistent) { @@ -157,7 +159,9 @@ ScValue::~ScValue() { ////////////////////////////////////////////////////////////////////////// ScValue *ScValue::getProp(const char *name) { - if (_type == VAL_VARIABLE_REF) return _valRef->getProp(name); + if (_type == VAL_VARIABLE_REF) { + return _valRef->getProp(name); + } if (_type == VAL_STRING && strcmp(name, "Length") == 0) { _gameRef->_scValue->_type = VAL_INT; @@ -178,18 +182,24 @@ ScValue *ScValue::getProp(const char *name) { ScValue *ret = NULL; - if (_type == VAL_NATIVE && _valNative) ret = _valNative->scGetProperty(name); + if (_type == VAL_NATIVE && _valNative) { + ret = _valNative->scGetProperty(name); + } if (ret == NULL) { _valIter = _valObject.find(name); - if (_valIter != _valObject.end()) ret = _valIter->_value; + if (_valIter != _valObject.end()) { + ret = _valIter->_value; + } } return ret; } ////////////////////////////////////////////////////////////////////////// bool ScValue::deleteProp(const char *name) { - if (_type == VAL_VARIABLE_REF) return _valRef->deleteProp(name); + if (_type == VAL_VARIABLE_REF) { + return _valRef->deleteProp(name); + } _valIter = _valObject.find(name); if (_valIter != _valObject.end()) { @@ -204,8 +214,9 @@ bool ScValue::deleteProp(const char *name) { ////////////////////////////////////////////////////////////////////////// bool ScValue::setProp(const char *name, ScValue *val, bool copyWhole, bool setAsConst) { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->setProp(name, val); + } bool ret = STATUS_FAILED; if (_type == VAL_NATIVE && _valNative) { @@ -219,15 +230,19 @@ bool ScValue::setProp(const char *name, ScValue *val, bool copyWhole, bool setAs if (_valIter != _valObject.end()) { newVal = _valIter->_value; } - if (!newVal) + if (!newVal) { newVal = new ScValue(_gameRef); - else newVal->cleanup(); + } else { + newVal->cleanup(); + } newVal->copy(val, copyWhole); newVal->_isConstVar = setAsConst; _valObject[name] = newVal; - if (_type != VAL_NATIVE) _type = VAL_OBJECT; + if (_type != VAL_NATIVE) { + _type = VAL_OBJECT; + } /* _valIter = _valObject.find(Name); @@ -250,8 +265,9 @@ bool ScValue::setProp(const char *name, ScValue *val, bool copyWhole, bool setAs ////////////////////////////////////////////////////////////////////////// bool ScValue::propExists(const char *name) { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->propExists(name); + } _valIter = _valObject.find(name); return (_valIter != _valObject.end()); @@ -273,15 +289,18 @@ void ScValue::deleteProps() { void ScValue::CleanProps(bool includingNatives) { _valIter = _valObject.begin(); while (_valIter != _valObject.end()) { - if (!_valIter->_value->_isConstVar && (!_valIter->_value->isNative() || includingNatives)) _valIter->_value->setNULL(); + if (!_valIter->_value->_isConstVar && (!_valIter->_value->isNative() || includingNatives)) { + _valIter->_value->setNULL(); + } _valIter++; } } ////////////////////////////////////////////////////////////////////////// bool ScValue::isNULL() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isNULL(); + } return (_type == VAL_NULL); } @@ -289,8 +308,9 @@ bool ScValue::isNULL() { ////////////////////////////////////////////////////////////////////////// bool ScValue::isNative() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isNative(); + } return (_type == VAL_NATIVE); } @@ -298,8 +318,9 @@ bool ScValue::isNative() { ////////////////////////////////////////////////////////////////////////// bool ScValue::isString() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isString(); + } return (_type == VAL_STRING); } @@ -307,8 +328,9 @@ bool ScValue::isString() { ////////////////////////////////////////////////////////////////////////// bool ScValue::isFloat() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isFloat(); + } return (_type == VAL_FLOAT); } @@ -316,8 +338,9 @@ bool ScValue::isFloat() { ////////////////////////////////////////////////////////////////////////// bool ScValue::isInt() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isInt(); + } return (_type == VAL_INT); } @@ -325,8 +348,9 @@ bool ScValue::isInt() { ////////////////////////////////////////////////////////////////////////// bool ScValue::isBool() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isBool(); + } return (_type == VAL_BOOL); } @@ -334,8 +358,9 @@ bool ScValue::isBool() { ////////////////////////////////////////////////////////////////////////// bool ScValue::isObject() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->isObject(); + } return (_type == VAL_OBJECT); } @@ -343,8 +368,9 @@ bool ScValue::isObject() { ////////////////////////////////////////////////////////////////////////// TValType ScValue::getTypeTolerant() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->getType(); + } return _type; } @@ -414,8 +440,11 @@ void ScValue::setString(const char *val) { } setStringVal(val); - if (_valString) _type = VAL_STRING; - else _type = VAL_NULL; + if (_valString) { + _type = VAL_STRING; + } else { + _type = VAL_NULL; + } } void ScValue::setString(const Common::String &val) { @@ -450,7 +479,9 @@ void ScValue::setNULL() { if (_valNative && !_persistent) { _valNative->_refCount--; - if (_valNative->_refCount <= 0) delete _valNative; + if (_valNative->_refCount <= 0) { + delete _valNative; + } } _valNative = NULL; deleteProps(); @@ -472,7 +503,9 @@ void ScValue::setNative(BaseScriptable *val, bool persistent) { if (_valNative && !_persistent) { _valNative->_refCount--; if (_valNative->_refCount <= 0) { - if (_valNative != val) delete _valNative; + if (_valNative != val) { + delete _valNative; + } _valNative = NULL; } } @@ -481,7 +514,9 @@ void ScValue::setNative(BaseScriptable *val, bool persistent) { _persistent = persistent; _valNative = val; - if (_valNative && !_persistent) _valNative->_refCount++; + if (_valNative && !_persistent) { + _valNative->_refCount++; + } } } @@ -507,8 +542,9 @@ void ScValue::setReference(ScValue *val) { ////////////////////////////////////////////////////////////////////////// bool ScValue::getBool(bool defaultVal) { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->getBool(); + } switch (_type) { case VAL_BOOL: @@ -534,7 +570,9 @@ bool ScValue::getBool(bool defaultVal) { ////////////////////////////////////////////////////////////////////////// int ScValue::getInt(int defaultVal) { - if (_type == VAL_VARIABLE_REF) return _valRef->getInt(); + if (_type == VAL_VARIABLE_REF) { + return _valRef->getInt(); + } switch (_type) { case VAL_BOOL: @@ -560,8 +598,9 @@ int ScValue::getInt(int defaultVal) { ////////////////////////////////////////////////////////////////////////// double ScValue::getFloat(double defaultVal) { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->getFloat(); + } switch (_type) { case VAL_BOOL: @@ -586,19 +625,23 @@ double ScValue::getFloat(double defaultVal) { ////////////////////////////////////////////////////////////////////////// void *ScValue::getMemBuffer() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->getMemBuffer(); + } - if (_type == VAL_NATIVE) + if (_type == VAL_NATIVE) { return _valNative->scToMemBuffer(); - else return (void *)NULL; + } else { + return (void *)NULL; + } } ////////////////////////////////////////////////////////////////////////// const char *ScValue::getString() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->getString(); + } switch (_type) { case VAL_OBJECT: @@ -647,11 +690,15 @@ const char *ScValue::getString() { ////////////////////////////////////////////////////////////////////////// BaseScriptable *ScValue::getNative() { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->getNative(); + } - if (_type == VAL_NATIVE) return _valNative; - else return NULL; + if (_type == VAL_NATIVE) { + return _valNative; + } else { + return NULL; + } } @@ -668,12 +715,16 @@ void ScValue::copy(ScValue *orig, bool copyWhole) { if (_valNative && !_persistent) { _valNative->_refCount--; if (_valNative->_refCount <= 0) { - if (_valNative != orig->_valNative) delete _valNative; + if (_valNative != orig->_valNative) { + delete _valNative; + } _valNative = NULL; } } - if (orig->_type == VAL_VARIABLE_REF && orig->_valRef && copyWhole) orig = orig->_valRef; + if (orig->_type == VAL_VARIABLE_REF && orig->_valRef && copyWhole) { + orig = orig->_valRef; + } cleanup(true); @@ -687,7 +738,9 @@ void ScValue::copy(ScValue *orig, bool copyWhole) { _persistent = orig->_persistent; _valNative = orig->_valNative; - if (_valNative && !_persistent) _valNative->_refCount++; + if (_valNative && !_persistent) { + _valNative->_refCount++; + } //!!!! ref->native++ // copy properties @@ -698,7 +751,9 @@ void ScValue::copy(ScValue *orig, bool copyWhole) { _valObject[orig->_valIter->_key]->copy(orig->_valIter->_value); orig->_valIter++; } - } else _valObject.clear(); + } else { + _valObject.clear(); + } } @@ -730,7 +785,9 @@ void ScValue::setValue(ScValue *val) { } } // otherwise just copy everything - else copy(val); + else { + copy(val); + } } @@ -841,39 +898,60 @@ int ScValue::compare(ScValue *val1, ScValue *val2) { // same class? if (strcmp(val1->getNative()->getClassName(), val2->getNative()->getClassName()) == 0) { return val1->getNative()->scCompare(val2->getNative()); - } else return strcmp(val1->getString(), val2->getString()); + } else { + return strcmp(val1->getString(), val2->getString()); + } } // both objects? - if (val1->isObject() && val2->isObject()) return -1; + if (val1->isObject() && val2->isObject()) { + return -1; + } // null states - if (val1->isNULL() && !val2->isNULL()) return -1; - else if (!val1->isNULL() && val2->isNULL()) return 1; - else if (val1->isNULL() && val2->isNULL()) return 0; + if (val1->isNULL() && !val2->isNULL()) { + return -1; + } else if (!val1->isNULL() && val2->isNULL()) { + return 1; + } else if (val1->isNULL() && val2->isNULL()) { + return 0; + } // one of them is string? convert both to string - if (val1->isString() || val2->isString()) return strcmp(val1->getString(), val2->getString()); + if (val1->isString() || val2->isString()) { + return strcmp(val1->getString(), val2->getString()); + } // one of them is float? if (val1->isFloat() || val2->isFloat()) { - if (val1->getFloat() < val2->getFloat()) return -1; - else if (val1->getFloat() > val2->getFloat()) return 1; - else return 0; + if (val1->getFloat() < val2->getFloat()) { + return -1; + } else if (val1->getFloat() > val2->getFloat()) { + return 1; + } else { + return 0; + } } // otherwise compare as int's - if (val1->getInt() < val2->getInt()) return -1; - else if (val1->getInt() > val2->getInt()) return 1; - else return 0; + if (val1->getInt() < val2->getInt()) { + return -1; + } else if (val1->getInt() > val2->getInt()) { + return 1; + } else { + return 0; + } } ////////////////////////////////////////////////////////////////////////// int ScValue::compareStrict(ScValue *val1, ScValue *val2) { - if (val1->getTypeTolerant() != val2->getTypeTolerant()) return -1; - else return ScValue::compare(val1, val2); + if (val1->getTypeTolerant() != val2->getTypeTolerant()) { + return -1; + } else { + return ScValue::compare(val1, val2); + } } @@ -1013,16 +1091,18 @@ bool ScValue::dbgSetVal() { ////////////////////////////////////////////////////////////////////////// int ScValue::dbgGetNumProperties() { - if (_valNative && _valNative->_scProp) + if (_valNative && _valNative->_scProp) { return _valNative->_scProp->dbgGetNumProperties(); - else return _valObject.size(); + } else { + return _valObject.size(); + } } ////////////////////////////////////////////////////////////////////////// bool ScValue::dbgGetProperty(int index, const char **name, IWmeDebugProp **value) { - if (_valNative && _valNative->_scProp) + if (_valNative && _valNative->_scProp) { return _valNative->_scProp->dbgGetProperty(index, name, value); - else { + } else { int count = 0; _valIter = _valObject.begin(); while (_valIter != _valObject.end()) { @@ -1040,8 +1120,9 @@ bool ScValue::dbgGetProperty(int index, const char **name, IWmeDebugProp **value ////////////////////////////////////////////////////////////////////////// bool ScValue::dbgGetDescription(char *buf, int bufSize) { - if (_type == VAL_VARIABLE_REF) + if (_type == VAL_VARIABLE_REF) { return _valRef->dbgGetDescription(buf, bufSize); + } if (_type == VAL_NATIVE) { _valNative->scDebuggerDesc(buf, bufSize); diff --git a/engines/wintermute/base/sound/base_sound.cpp b/engines/wintermute/base/sound/base_sound.cpp index 8cc8c21948..9cd9e4cc75 100644 --- a/engines/wintermute/base/sound/base_sound.cpp +++ b/engines/wintermute/base/sound/base_sound.cpp @@ -57,7 +57,9 @@ BaseSound::BaseSound(BaseGame *inGame): BaseClass(inGame) { ////////////////////////////////////////////////////////////////////////// BaseSound::~BaseSound() { - if (_sound) _gameRef->_soundMgr->removeSound(_sound); + if (_sound) { + _gameRef->_soundMgr->removeSound(_sound); + } _sound = NULL; delete[] _soundFilename; @@ -83,7 +85,9 @@ bool BaseSound::setSound(const char *filename, Audio::Mixer::SoundType type, boo _soundStreamed = streamed; return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -91,22 +95,32 @@ bool BaseSound::setSound(const char *filename, Audio::Mixer::SoundType type, boo bool BaseSound::setSoundSimple() { _sound = _gameRef->_soundMgr->addSound(_soundFilename, _soundType, _soundStreamed); if (_sound) { - if (_soundPosition) _sound->setPosition(_soundPosition); + if (_soundPosition) { + _sound->setPosition(_soundPosition); + } _sound->setLooping(_soundLooping); _sound->setPrivateVolume(_soundPrivateVolume); _sound->setLoopStart(_soundLoopStart); _sound->_freezePaused = _soundFreezePaused; - if (_soundPlaying) return _sound->resume(); - else return STATUS_OK; - } else return STATUS_FAILED; + if (_soundPlaying) { + return _sound->resume(); + } else { + return STATUS_OK; + } + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// uint32 BaseSound::getLength() { - if (_sound) return _sound->getLength(); - else return 0; + if (_sound) { + return _sound->getLength(); + } else { + return 0; + } } @@ -115,7 +129,9 @@ bool BaseSound::play(bool looping) { if (_sound) { _soundPaused = false; return _sound->play(looping, _soundPosition); - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -124,7 +140,9 @@ bool BaseSound::stop() { if (_sound) { _soundPaused = false; return _sound->stop(); - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -132,9 +150,13 @@ bool BaseSound::stop() { bool BaseSound::pause(bool freezePaused) { if (_sound) { _soundPaused = true; - if (freezePaused) _sound->_freezePaused = true; + if (freezePaused) { + _sound->_freezePaused = true; + } return _sound->pause(); - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -143,7 +165,9 @@ bool BaseSound::resume() { if (_sound && _soundPaused) { _soundPaused = false; return _sound->resume(); - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } @@ -153,8 +177,9 @@ bool BaseSound::persist(BasePersistenceManager *persistMgr) { _soundPlaying = _sound->isPlaying(); _soundLooping = _sound->_looping; _soundPrivateVolume = _sound->_privateVolume; - if (_soundPlaying) + if (_soundPlaying) { _soundPosition = _sound->getPosition(); + } _soundLoopStart = _sound->_loopStart; _soundFreezePaused = _sound->_freezePaused; } @@ -195,64 +220,81 @@ bool BaseSound::isPaused() { ////////////////////////////////////////////////////////////////////////// bool BaseSound::setPositionTime(uint32 time) { - if (!_sound) return STATUS_FAILED; + if (!_sound) { + return STATUS_FAILED; + } _soundPosition = time; bool ret = _sound->setPosition(_soundPosition); - if (_sound->isPlaying()) + if (_sound->isPlaying()) { _soundPosition = 0; + } return ret; } ////////////////////////////////////////////////////////////////////////// uint32 BaseSound::getPositionTime() { - if (!_sound) return 0; + if (!_sound) { + return 0; + } - if (!_sound->isPlaying()) + if (!_sound->isPlaying()) { return 0; - else return _sound->getPosition(); + } else { + return _sound->getPosition(); + } } ////////////////////////////////////////////////////////////////////////// bool BaseSound::setVolumePercent(int percent) { - if (!_sound) + if (!_sound) { return STATUS_FAILED; - else return _sound->setPrivateVolume(percent * 255 / 100); + } else { + return _sound->setPrivateVolume(percent * 255 / 100); + } } ////////////////////////////////////////////////////////////////////////// bool BaseSound::setVolume(int volume) { - if (!_sound) + if (!_sound) { return STATUS_FAILED; - else return _sound->setPrivateVolume(volume); + } else { + return _sound->setPrivateVolume(volume); + } } ////////////////////////////////////////////////////////////////////////// bool BaseSound::setPrivateVolume(int volume) { - if (!_sound) + if (!_sound) { return STATUS_FAILED; - else return _sound->_privateVolume = volume; + } else { + return _sound->_privateVolume = volume; + } } ////////////////////////////////////////////////////////////////////////// int BaseSound::getVolumePercent() { - if (!_sound) + if (!_sound) { return 0; - else return _sound->_privateVolume * 100 / 255; + } else { + return _sound->_privateVolume * 100 / 255; + } } ////////////////////////////////////////////////////////////////////////// int BaseSound::getVolume() { - if (!_sound) + if (!_sound) { return 0; - else return _sound->_privateVolume; + } else { + return _sound->_privateVolume; + } } ////////////////////////////////////////////////////////////////////////// bool BaseSound::setLoopStart(uint32 pos) { - if (!_sound) + if (!_sound) { return STATUS_FAILED; - else { + } else { _sound->setLoopStart(pos); return STATUS_OK; } @@ -260,16 +302,19 @@ bool BaseSound::setLoopStart(uint32 pos) { ////////////////////////////////////////////////////////////////////////// bool BaseSound::setPan(float pan) { - if (_sound) + if (_sound) { return _sound->setPan(pan); - else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// bool BaseSound::ApplyFX(TSFXType type, float param1, float param2, float param3, float param4) { - if (!_sound) + if (!_sound) { return STATUS_OK; + } if (type != _sFXType || param1 != _sFXParam1 || param2 != _sFXParam2 || param3 != _sFXParam3 || param4 != _sFXParam4) { bool ret = _sound->applyFX(type, param1, param2, param3, param4); diff --git a/engines/wintermute/base/sound/base_sound_manager.cpp b/engines/wintermute/base/sound/base_sound_manager.cpp index cebc3a3765..74aae59e3d 100644 --- a/engines/wintermute/base/sound/base_sound_manager.cpp +++ b/engines/wintermute/base/sound/base_sound_manager.cpp @@ -61,8 +61,9 @@ BaseSoundMgr::~BaseSoundMgr() { ////////////////////////////////////////////////////////////////////////// bool BaseSoundMgr::cleanup() { - for (uint32 i = 0; i < _sounds.size(); i++) + for (uint32 i = 0; i < _sounds.size(); i++) { delete _sounds[i]; + } _sounds.clear(); #if 0 BASS_Free(); @@ -93,8 +94,9 @@ bool BaseSoundMgr::initialize() { ////////////////////////////////////////////////////////////////////////// bool BaseSoundMgr::initLoop() { - if (!_soundAvailable) + if (!_soundAvailable) { return STATUS_OK; + } #if 0 BASS_Update(500); @@ -105,8 +107,9 @@ bool BaseSoundMgr::initLoop() { ////////////////////////////////////////////////////////////////////////// BaseSoundBuffer *BaseSoundMgr::addSound(const char *filename, Audio::Mixer::SoundType type, bool streamed) { - if (!_soundAvailable) + if (!_soundAvailable) { return NULL; + } BaseSoundBuffer *sound; @@ -123,7 +126,9 @@ BaseSoundBuffer *BaseSoundMgr::addSound(const char *filename, Audio::Mixer::Soun } sound = new BaseSoundBuffer(_gameRef); - if (!sound) return NULL; + if (!sound) { + return NULL; + } sound->setStreaming(streamed); sound->setType(type); @@ -149,8 +154,9 @@ BaseSoundBuffer *BaseSoundMgr::addSound(const char *filename, Audio::Mixer::Soun ////////////////////////////////////////////////////////////////////////// bool BaseSoundMgr::addSound(BaseSoundBuffer *sound, Audio::Mixer::SoundType type) { - if (!sound) + if (!sound) { return STATUS_FAILED; + } // Make sure the master-volume is applied to the sound. sound->updateVolume(); @@ -177,8 +183,9 @@ bool BaseSoundMgr::removeSound(BaseSoundBuffer *sound) { ////////////////////////////////////////////////////////////////////////// bool BaseSoundMgr::setVolume(Audio::Mixer::SoundType type, int volume) { - if (!_soundAvailable) + if (!_soundAvailable) { return STATUS_OK; + } switch (type) { case Audio::Mixer::kSFXSoundType: diff --git a/engines/wintermute/math/math_util.cpp b/engines/wintermute/math/math_util.cpp index fe7325baa4..ef5b676662 100644 --- a/engines/wintermute/math/math_util.cpp +++ b/engines/wintermute/math/math_util.cpp @@ -34,14 +34,18 @@ namespace WinterMute { ////////////////////////////////////////////////////////////////////////// float MathUtil::round(float val) { float result = floor(val); - if (val - result >= 0.5) result += 1.0; + if (val - result >= 0.5) { + result += 1.0; + } return result; } ////////////////////////////////////////////////////////////////////////// float MathUtil::roundUp(float val) { float result = floor(val); - if (val - result > 0) result += 1.0; + if (val - result > 0) { + result += 1.0; + } return result; } diff --git a/engines/wintermute/system/sys_class.cpp b/engines/wintermute/system/sys_class.cpp index 32704e0a0e..21578320c7 100644 --- a/engines/wintermute/system/sys_class.cpp +++ b/engines/wintermute/system/sys_class.cpp @@ -85,7 +85,9 @@ SystemInstance *SystemClass::addInstance(void *instance, int id, int savedId) { ////////////////////////////////////////////////////////////////////////// bool SystemClass::removeInstance(void *instance) { InstanceMap::iterator mapIt = _instanceMap.find(instance); - if (mapIt == _instanceMap.end()) return false; + if (mapIt == _instanceMap.end()) { + return false; + } Instances::iterator it = _instances.find((mapIt->_value)); if (it != _instances.end()) { @@ -101,8 +103,11 @@ bool SystemClass::removeInstance(void *instance) { ////////////////////////////////////////////////////////////////////////// int SystemClass::getInstanceID(void *pointer) { InstanceMap::iterator mapIt = _instanceMap.find(pointer); - if (mapIt == _instanceMap.end()) return -1; - else return (mapIt->_value)->getID(); + if (mapIt == _instanceMap.end()) { + return -1; + } else { + return (mapIt->_value)->getID(); + } } ////////////////////////////////////////////////////////////////////////// @@ -110,7 +115,9 @@ void *SystemClass::idToPointer(int savedID) { //slow Instances::iterator it; for (it = _instances.begin(); it != _instances.end(); ++it) { - if ((it->_value)->getSavedID() == savedID) return (it->_value)->getInstance(); + if ((it->_value)->getSavedID() == savedID) { + return (it->_value)->getInstance(); + } } return NULL; } @@ -157,7 +164,9 @@ void SystemClass::loadTable(BaseGame *gameRef, BasePersistenceManager *persistMg if (it != _instances.end()) { (it->_value)->setSavedID(instID); SystemClassRegistry::getInstance()->addInstanceToTable((it->_value), (it->_value)->getInstance()); - } else gameRef->LOG(0, "Warning: instance %d of persistent class %s not found", i, _name.c_str()); + } else { + gameRef->LOG(0, "Warning: instance %d of persistent class %s not found", i, _name.c_str()); + } } // normal instances, create empty objects else { diff --git a/engines/wintermute/system/sys_class_registry.cpp b/engines/wintermute/system/sys_class_registry.cpp index 7f7814f75c..47910af4e8 100644 --- a/engines/wintermute/system/sys_class_registry.cpp +++ b/engines/wintermute/system/sys_class_registry.cpp @@ -77,7 +77,9 @@ bool SystemClassRegistry::registerClass(SystemClass *classObj) { bool SystemClassRegistry::unregisterClass(SystemClass *classObj) { Classes::iterator it = _classes.find(classObj); - if (it == _classes.end()) return false; + if (it == _classes.end()) { + return false; + } if (classObj->getNumInstances() != 0) { char str[MAX_PATH_LENGTH]; @@ -87,10 +89,14 @@ bool SystemClassRegistry::unregisterClass(SystemClass *classObj) { _classes.erase(it); NameMap::iterator mapIt = _nameMap.find(classObj->getName()); - if (mapIt != _nameMap.end()) _nameMap.erase(mapIt); + if (mapIt != _nameMap.end()) { + _nameMap.erase(mapIt); + } IdMap::iterator idIt = _idMap.find(classObj->getID()); - if (idIt != _idMap.end()) _idMap.erase(idIt); + if (idIt != _idMap.end()) { + _idMap.erase(idIt); + } return true; @@ -99,10 +105,14 @@ bool SystemClassRegistry::unregisterClass(SystemClass *classObj) { ////////////////////////////////////////////////////////////////////////// bool SystemClassRegistry::registerInstance(const char *className, void *instance) { - if (_disabled) return true; + if (_disabled) { + return true; + } NameMap::iterator mapIt = _nameMap.find(className); - if (mapIt == _nameMap.end()) return false; + if (mapIt == _nameMap.end()) { + return false; + } SystemInstance *inst = (*mapIt)._value->addInstance(instance, _count++); return (inst != NULL); @@ -112,8 +122,9 @@ bool SystemClassRegistry::registerInstance(const char *className, void *instance void SystemClassRegistry::addInstanceToTable(SystemInstance *instance, void *pointer) { _instanceMap[pointer] = instance; - if (instance->getSavedID() >= 0) + if (instance->getSavedID() >= 0) { _savedInstanceMap[instance->getSavedID()] = instance; + } } ////////////////////////////////////////////////////////////////////////// @@ -124,23 +135,31 @@ int SystemClassRegistry::getNextID() { ////////////////////////////////////////////////////////////////////////// bool SystemClassRegistry::unregisterInstance(const char *className, void *instance) { NameMap::iterator mapIt = _nameMap.find(className); - if (mapIt == _nameMap.end()) return false; + if (mapIt == _nameMap.end()) { + return false; + } (*mapIt)._value->removeInstance(instance); InstanceMap::iterator instIt = _instanceMap.find(instance); if (instIt != _instanceMap.end()) { _instanceMap.erase(instIt); return true; - } else return false; + } else { + return false; + } } ////////////////////////////////////////////////////////////////////////// bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanceID) { - if (pointer == NULL) return true; + if (pointer == NULL) { + return true; + } InstanceMap::iterator it = _instanceMap.find(pointer); - if (it == _instanceMap.end()) return false; + if (it == _instanceMap.end()) { + return false; + } SystemInstance *inst = (*it)._value; @@ -153,8 +172,11 @@ bool SystemClassRegistry::getPointerID(void *pointer, int *classID, int *instanc ////////////////////////////////////////////////////////////////////////// void *SystemClassRegistry::idToPointer(int classID, int instanceID) { SavedInstanceMap::iterator it = _savedInstanceMap.find(instanceID); - if (it == _savedInstanceMap.end()) return NULL; - else return (*it)._value->getInstance(); + if (it == _savedInstanceMap.end()) { + return NULL; + } else { + return (*it)._value->getInstance(); + } } bool checkHeader(const char *tag, BasePersistenceManager *pm) { @@ -203,7 +225,9 @@ bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *p } for (it = _classes.begin(); it != _classes.end(); ++it) { - if ((it->_value)->isPersistent()) continue; + if ((it->_value)->isPersistent()) { + continue; + } (it->_value)->removeAllInstances(); } @@ -218,7 +242,9 @@ bool SystemClassRegistry::loadTable(BaseGame *gameRef, BasePersistenceManager *p Common::String className = persistMgr->getStringObj(); NameMap::iterator mapIt = _nameMap.find(className); - if (mapIt != _nameMap.end())(*mapIt)._value->loadTable(gameRef, persistMgr); + if (mapIt != _nameMap.end()) { + (*mapIt)._value->loadTable(gameRef, persistMgr); + } } checkHeader("", persistMgr); @@ -298,7 +324,9 @@ bool SystemClassRegistry::loadInstances(BaseGame *gameRef, BasePersistenceManage ////////////////////////////////////////////////////////////////////////// bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const char *className, void *lpData) { NameMap::iterator mapIt = _nameMap.find(className); - if (mapIt == _nameMap.end()) return STATUS_FAILED; + if (mapIt == _nameMap.end()) { + return STATUS_FAILED; + } (*mapIt)._value->instanceCallback(lpCallback, lpData); return STATUS_OK; @@ -308,8 +336,9 @@ bool SystemClassRegistry::enumInstances(SYS_INSTANCE_CALLBACK lpCallback, const ////////////////////////////////////////////////////////////////////////// void SystemClassRegistry::dumpClasses(Common::WriteStream *stream) { Classes::iterator it; - for (it = _classes.begin(); it != _classes.end(); ++it) + for (it = _classes.begin(); it != _classes.end(); ++it) { (it->_value)->dump(stream); + } } } // end of namespace WinterMute diff --git a/engines/wintermute/ui/ui_button.cpp b/engines/wintermute/ui/ui_button.cpp index 2c4cecdc85..706b0d3c00 100644 --- a/engines/wintermute/ui/ui_button.cpp +++ b/engines/wintermute/ui/ui_button.cpp @@ -77,10 +77,18 @@ UIButton::~UIButton() { delete _backFocus; if (!_sharedFonts) { - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); - if (_fontPress) _gameRef->_fontStorage->removeFont(_fontPress); - if (_fontDisable) _gameRef->_fontStorage->removeFont(_fontDisable); - if (_fontFocus) _gameRef->_fontStorage->removeFont(_fontFocus); + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } + if (_fontPress) { + _gameRef->_fontStorage->removeFont(_fontPress); + } + if (_fontDisable) { + _gameRef->_fontStorage->removeFont(_fontDisable); + } + if (_fontFocus) { + _gameRef->_fontStorage->removeFont(_fontFocus); + } } if (!_sharedImages) { @@ -104,7 +112,9 @@ bool UIButton::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing BUTTON file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing BUTTON file '%s'", filename); + } delete[] buffer; @@ -206,7 +216,9 @@ bool UIButton::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -318,33 +330,53 @@ bool UIButton::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; + if (!_font) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_HOVER: - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } _fontHover = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontHover) cmd = PARSERR_GENERIC; + if (!_fontHover) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_PRESS: - if (_fontPress) _gameRef->_fontStorage->removeFont(_fontPress); + if (_fontPress) { + _gameRef->_fontStorage->removeFont(_fontPress); + } _fontPress = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontPress) cmd = PARSERR_GENERIC; + if (!_fontPress) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_DISABLE: - if (_fontDisable) _gameRef->_fontStorage->removeFont(_fontDisable); + if (_fontDisable) { + _gameRef->_fontStorage->removeFont(_fontDisable); + } _fontDisable = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontDisable) cmd = PARSERR_GENERIC; + if (!_fontDisable) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_FOCUS: - if (_fontFocus) _gameRef->_fontStorage->removeFont(_fontFocus); + if (_fontFocus) { + _gameRef->_fontStorage->removeFont(_fontFocus); + } _fontFocus = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontFocus) cmd = PARSERR_GENERIC; + if (!_fontFocus) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_TEXT: @@ -353,9 +385,13 @@ bool UIButton::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TEXT_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) _align = TAL_LEFT; - else if (scumm_stricmp((char *)params, "right") == 0) _align = TAL_RIGHT; - else _align = TAL_CENTER; + if (scumm_stricmp((char *)params, "left") == 0) { + _align = TAL_LEFT; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _align = TAL_RIGHT; + } else { + _align = TAL_CENTER; + } break; case TOKEN_X: @@ -445,47 +481,64 @@ bool UIButton::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); - if (_back && _back->getFilename()) + if (_back && _back->getFilename()) { buffer->putTextIndent(indent + 2, "BACK=\"%s\"\n", _back->getFilename()); - if (_backHover && _backHover->getFilename()) + } + if (_backHover && _backHover->getFilename()) { buffer->putTextIndent(indent + 2, "BACK_HOVER=\"%s\"\n", _backHover->getFilename()); - if (_backPress && _backPress->getFilename()) + } + if (_backPress && _backPress->getFilename()) { buffer->putTextIndent(indent + 2, "BACK_PRESS=\"%s\"\n", _backPress->getFilename()); - if (_backDisable && _backDisable->getFilename()) + } + if (_backDisable && _backDisable->getFilename()) { buffer->putTextIndent(indent + 2, "BACK_DISABLE=\"%s\"\n", _backDisable->getFilename()); - if (_backFocus && _backFocus->getFilename()) + } + if (_backFocus && _backFocus->getFilename()) { buffer->putTextIndent(indent + 2, "BACK_FOCUS=\"%s\"\n", _backFocus->getFilename()); + } - if (_image && _image->getFilename()) + if (_image && _image->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE=\"%s\"\n", _image->getFilename()); - if (_imageHover && _imageHover->getFilename()) + } + if (_imageHover && _imageHover->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE_HOVER=\"%s\"\n", _imageHover->getFilename()); - if (_imagePress && _imagePress->getFilename()) + } + if (_imagePress && _imagePress->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE_PRESS=\"%s\"\n", _imagePress->getFilename()); - if (_imageDisable && _imageDisable->getFilename()) + } + if (_imageDisable && _imageDisable->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE_DISABLE=\"%s\"\n", _imageDisable->getFilename()); - if (_imageFocus && _imageFocus->getFilename()) + } + if (_imageFocus && _imageFocus->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE_FOCUS=\"%s\"\n", _imageFocus->getFilename()); + } - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - if (_fontHover && _fontHover->getFilename()) + } + if (_fontHover && _fontHover->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_HOVER=\"%s\"\n", _fontHover->getFilename()); - if (_fontPress && _fontPress->getFilename()) + } + if (_fontPress && _fontPress->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_PRESS=\"%s\"\n", _fontPress->getFilename()); - if (_fontDisable && _fontDisable->getFilename()) + } + if (_fontDisable && _fontDisable->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_DISABLE=\"%s\"\n", _fontDisable->getFilename()); - if (_fontFocus && _fontFocus->getFilename()) + } + if (_fontFocus && _fontFocus->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_FOCUS=\"%s\"\n", _fontFocus->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } buffer->putTextIndent(indent + 2, "\n"); - if (_text) + if (_text) { buffer->putTextIndent(indent + 2, "TEXT=\"%s\"\n", _text); + } switch (_align) { case TAL_LEFT: @@ -539,17 +592,25 @@ void UIButton::correctSize() { Rect32 rect; BaseSprite *img = NULL; - if (_image) img = _image; - else if (_imageDisable) img = _imageDisable; - else if (_imageHover) img = _imageHover; - else if (_imagePress) img = _imagePress; - else if (_imageFocus) img = _imageFocus; + if (_image) { + img = _image; + } else if (_imageDisable) { + img = _imageDisable; + } else if (_imageHover) { + img = _imageHover; + } else if (_imagePress) { + img = _imagePress; + } else if (_imageFocus) { + img = _imageFocus; + } if (_width <= 0) { if (img) { img->getBoundingRect(&rect, 0, 0); _width = rect.right - rect.left; - } else _width = 100; + } else { + _width = 100; + } } if (_height <= 0) { @@ -561,22 +622,32 @@ void UIButton::correctSize() { if (_text) { int text_height; - if (_font) text_height = _font->getTextHeight((byte *)_text, _width); - else text_height = _gameRef->_systemFont->getTextHeight((byte *)_text, _width); + if (_font) { + text_height = _font->getTextHeight((byte *)_text, _width); + } else { + text_height = _gameRef->_systemFont->getTextHeight((byte *)_text, _width); + } - if (text_height > _height) _height = text_height; + if (text_height > _height) { + _height = text_height; + } } - if (_height <= 0) _height = 100; + if (_height <= 0) { + _height = 100; + } - if (_back) _back->correctSize(&_width, &_height); + if (_back) { + _back->correctSize(&_width, &_height); + } } ////////////////////////////////////////////////////////////////////////// bool UIButton::display(int offsetX, int offsetY) { - if (!_visible) + if (!_visible) { return STATUS_OK; + } UITiledImage *back = NULL; BaseSprite *image = NULL; @@ -588,32 +659,65 @@ bool UIButton::display(int offsetX, int offsetY) { _hover = (!_disable && _gameRef->_activeObject == this && (_gameRef->_interactive || _gameRef->_state == GAME_SEMI_FROZEN)); if ((_press && _hover && !_gameRef->_mouseLeftDown) || - (_oneTimePress && g_system->getMillis() - _oneTimePressTime >= 100)) press(); + (_oneTimePress && g_system->getMillis() - _oneTimePressTime >= 100)) { + press(); + } if (_disable) { - if (_backDisable) back = _backDisable; - if (_imageDisable) image = _imageDisable; - if (_text && _fontDisable) font = _fontDisable; + if (_backDisable) { + back = _backDisable; + } + if (_imageDisable) { + image = _imageDisable; + } + if (_text && _fontDisable) { + font = _fontDisable; + } } else if (_press || _oneTimePress || _stayPressed) { - if (_backPress) back = _backPress; - if (_imagePress) image = _imagePress; - if (_text && _fontPress) font = _fontPress; + if (_backPress) { + back = _backPress; + } + if (_imagePress) { + image = _imagePress; + } + if (_text && _fontPress) { + font = _fontPress; + } } else if (_hover) { - if (_backHover) back = _backHover; - if (_imageHover) image = _imageHover; - if (_text && _fontHover) font = _fontHover; + if (_backHover) { + back = _backHover; + } + if (_imageHover) { + image = _imageHover; + } + if (_text && _fontHover) { + font = _fontHover; + } } else if (_canFocus && isFocused()) { - if (_backFocus) back = _backFocus; - if (_imageFocus) image = _imageFocus; - if (_text && _fontFocus) font = _fontFocus; + if (_backFocus) { + back = _backFocus; + } + if (_imageFocus) { + image = _imageFocus; + } + if (_text && _fontFocus) { + font = _fontFocus; + } } - if (!back && _back) back = _back; - if (!image && _image) image = _image; + if (!back && _back) { + back = _back; + } + if (!image && _image) { + image = _image; + } if (_text && !font) { - if (_font) font = _font; - else font = _gameRef->_systemFont; + if (_font) { + font = _font; + } else { + font = _gameRef->_systemFont; + } } int imageX = offsetX + _posX; @@ -626,23 +730,39 @@ bool UIButton::display(int offsetX, int offsetY) { imageY += (_height - (rc.bottom - rc.top)) / 2; } - if (back) back->display(offsetX + _posX, offsetY + _posY, _width, _height); + if (back) { + back->display(offsetX + _posX, offsetY + _posY, _width, _height); + } //if (image) image->Draw(ImageX +((_press||_oneTimePress)&&back?1:0), ImageY +((_press||_oneTimePress)&&back?1:0), NULL); - if (image) image->draw(imageX + ((_press || _oneTimePress) && back ? 1 : 0), imageY + ((_press || _oneTimePress) && back ? 1 : 0), _pixelPerfect ? this : NULL); + if (image) { + image->draw(imageX + ((_press || _oneTimePress) && back ? 1 : 0), imageY + ((_press || _oneTimePress) && back ? 1 : 0), _pixelPerfect ? this : NULL); + } if (font && _text) { int text_offset = (_height - font->getTextHeight((byte *)_text, _width)) / 2; font->drawText((byte *)_text, offsetX + _posX + ((_press || _oneTimePress) ? 1 : 0), offsetY + _posY + text_offset + ((_press || _oneTimePress) ? 1 : 0), _width, _align); } - if (!_pixelPerfect || !_image) _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, this, NULL, offsetX + _posX, offsetY + _posY, _width, _height, 100, 100, false)); + if (!_pixelPerfect || !_image) { + _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, this, NULL, offsetX + _posX, offsetY + _posY, _width, _height, 100, 100, false)); + } // reset unused sprites - if (_image && _image != image) _image->reset(); - if (_imageDisable && _imageDisable != image) _imageDisable->reset(); - if (_imageFocus && _imageFocus != image) _imageFocus->reset(); - if (_imagePress && _imagePress != image) _imagePress->reset(); - if (_imageHover && _imageHover != image) _imageHover->reset(); + if (_image && _image != image) { + _image->reset(); + } + if (_imageDisable && _imageDisable != image) { + _imageDisable->reset(); + } + if (_imageFocus && _imageFocus != image) { + _imageFocus->reset(); + } + if (_imagePress && _imagePress != image) { + _imagePress->reset(); + } + if (_imageHover && _imageHover != image) { + _imageHover->reset(); + } _press = _hover && _gameRef->_mouseLeftDown && _gameRef->_capturedObject == this; @@ -653,8 +773,12 @@ bool UIButton::display(int offsetX, int offsetY) { ////////////////////////////////////////////////////////////////////////// void UIButton::press() { applyEvent("Press"); - if (_listenerObject) _listenerObject->listen(_listenerParamObject, _listenerParamDWORD); - if (_parentNotify && _parent) _parent->applyEvent(getName()); + if (_listenerObject) { + _listenerObject->listen(_listenerParamObject, _listenerParamDWORD); + } + if (_parentNotify && _parent) { + _parent->applyEvent(getName()); + } _oneTimePress = false; } @@ -669,14 +793,16 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "SetDisabledFont") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); - if (_fontDisable) _gameRef->_fontStorage->removeFont(_fontDisable); - if (Val->isNULL()) { + if (_fontDisable) { + _gameRef->_fontStorage->removeFont(_fontDisable); + } + if (val->isNULL()) { _fontDisable = NULL; stack->pushBool(true); } else { - _fontDisable = _gameRef->_fontStorage->addFont(Val->getString()); + _fontDisable = _gameRef->_fontStorage->addFont(val->getString()); stack->pushBool(_fontDisable != NULL); } return STATUS_OK; @@ -689,7 +815,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); ScValue *val = stack->pop(); - if (_fontHover) _gameRef->_fontStorage->removeFont(_fontHover); + if (_fontHover) { + _gameRef->_fontStorage->removeFont(_fontHover); + } if (val->isNULL()) { _fontHover = NULL; stack->pushBool(true); @@ -705,14 +833,16 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SetPressedFont") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); - if (_fontPress) _gameRef->_fontStorage->removeFont(_fontPress); - if (Val->isNULL()) { + if (_fontPress) { + _gameRef->_fontStorage->removeFont(_fontPress); + } + if (val->isNULL()) { _fontPress = NULL; stack->pushBool(true); } else { - _fontPress = _gameRef->_fontStorage->addFont(Val->getString()); + _fontPress = _gameRef->_fontStorage->addFont(val->getString()); stack->pushBool(_fontPress != NULL); } return STATUS_OK; @@ -725,7 +855,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->correctParams(1); ScValue *val = stack->pop(); - if (_fontFocus) _gameRef->_fontStorage->removeFont(_fontFocus); + if (_fontFocus) { + _gameRef->_fontStorage->removeFont(_fontFocus); + } if (val->isNULL()) { _fontFocus = NULL; stack->pushBool(true); @@ -749,7 +881,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _imageDisable; _imageDisable = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -759,8 +893,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetDisabledImage") == 0) { stack->correctParams(0); - if (!_imageDisable || !_imageDisable->getFilename()) stack->pushNULL(); - else stack->pushString(_imageDisable->getFilename()); + if (!_imageDisable || !_imageDisable->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_imageDisable->getFilename()); + } return STATUS_OK; } @@ -770,8 +907,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetDisabledImageObject") == 0) { stack->correctParams(0); - if (!_imageDisable) stack->pushNULL(); - else stack->pushNative(_imageDisable, true); + if (!_imageDisable) { + stack->pushNULL(); + } else { + stack->pushNative(_imageDisable, true); + } return STATUS_OK; } @@ -790,7 +930,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _imageHover; _imageHover = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -800,8 +942,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetHoverImage") == 0) { stack->correctParams(0); - if (!_imageHover || !_imageHover->getFilename()) stack->pushNULL(); - else stack->pushString(_imageHover->getFilename()); + if (!_imageHover || !_imageHover->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_imageHover->getFilename()); + } return STATUS_OK; } @@ -811,8 +956,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetHoverImageObject") == 0) { stack->correctParams(0); - if (!_imageHover) stack->pushNULL(); - else stack->pushNative(_imageHover, true); + if (!_imageHover) { + stack->pushNULL(); + } else { + stack->pushNative(_imageHover, true); + } return STATUS_OK; } @@ -830,7 +978,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _imagePress; _imagePress = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -840,8 +990,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetPressedImage") == 0) { stack->correctParams(0); - if (!_imagePress || !_imagePress->getFilename()) stack->pushNULL(); - else stack->pushString(_imagePress->getFilename()); + if (!_imagePress || !_imagePress->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_imagePress->getFilename()); + } return STATUS_OK; } @@ -851,8 +1004,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetPressedImageObject") == 0) { stack->correctParams(0); - if (!_imagePress) stack->pushNULL(); - else stack->pushNative(_imagePress, true); + if (!_imagePress) { + stack->pushNULL(); + } else { + stack->pushNative(_imagePress, true); + } return STATUS_OK; } @@ -870,7 +1026,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _imageFocus; _imageFocus = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -880,8 +1038,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetFocusedImage") == 0) { stack->correctParams(0); - if (!_imageFocus || !_imageFocus->getFilename()) stack->pushNULL(); - else stack->pushString(_imageFocus->getFilename()); + if (!_imageFocus || !_imageFocus->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_imageFocus->getFilename()); + } return STATUS_OK; } @@ -891,8 +1052,11 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetFocusedImageObject") == 0) { stack->correctParams(0); - if (!_imageFocus) stack->pushNULL(); - else stack->pushNative(_imageFocus, true); + if (!_imageFocus) { + stack->pushNULL(); + } else { + stack->pushNative(_imageFocus, true); + } return STATUS_OK; } @@ -910,10 +1074,9 @@ bool UIButton::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack stack->pushNULL(); return STATUS_OK; + } else { + return UIObject::scCallMethod(script, stack, thisStack, name); } - - - else return UIObject::scCallMethod(script, stack, thisStack, name); } @@ -957,9 +1120,9 @@ ScValue *UIButton::scGetProperty(const char *name) { else if (strcmp(name, "PixelPerfect") == 0) { _scValue->setBool(_pixelPerfect); return _scValue; + } else { + return UIObject::scGetProperty(name); } - - else return UIObject::scGetProperty(name); } @@ -970,7 +1133,9 @@ bool UIButton::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "TextAlign") == 0) { int i = value->getInt(); - if (i < 0 || i >= NUM_TEXT_ALIGN) i = 0; + if (i < 0 || i >= NUM_TEXT_ALIGN) { + i = 0; + } _align = (TTextAlign)i; return STATUS_OK; } @@ -995,9 +1160,9 @@ bool UIButton::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "PixelPerfect") == 0) { _pixelPerfect = value->getBool(); return STATUS_OK; + } else { + return UIObject::scSetProperty(name, value); } - - else return UIObject::scSetProperty(name, value); } diff --git a/engines/wintermute/ui/ui_edit.cpp b/engines/wintermute/ui/ui_edit.cpp index 988f56ae17..22d477bc31 100644 --- a/engines/wintermute/ui/ui_edit.cpp +++ b/engines/wintermute/ui/ui_edit.cpp @@ -81,7 +81,9 @@ UIEdit::UIEdit(BaseGame *inGame): UIObject(inGame) { ////////////////////////////////////////////////////////////////////////// UIEdit::~UIEdit() { if (!_sharedFonts) { - if (_fontSelected) _gameRef->_fontStorage->removeFont(_fontSelected); + if (_fontSelected) { + _gameRef->_fontStorage->removeFont(_fontSelected); + } } delete[] _cursorChar; @@ -101,7 +103,9 @@ bool UIEdit::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing EDIT file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing EDIT file '%s'", filename); + } delete[] buffer; @@ -175,7 +179,9 @@ bool UIEdit::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -203,15 +209,23 @@ bool UIEdit::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; + if (!_font) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_SELECTED: - if (_fontSelected) _gameRef->_fontStorage->removeFont(_fontSelected); + if (_fontSelected) { + _gameRef->_fontStorage->removeFont(_fontSelected); + } _fontSelected = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontSelected) cmd = PARSERR_GENERIC; + if (!_fontSelected) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_TEXT: @@ -306,24 +320,30 @@ bool UIEdit::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); - if (_back && _back->getFilename()) + if (_back && _back->getFilename()) { buffer->putTextIndent(indent + 2, "BACK=\"%s\"\n", _back->getFilename()); + } - if (_image && _image->getFilename()) + if (_image && _image->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE=\"%s\"\n", _image->getFilename()); + } - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - if (_fontSelected && _fontSelected->getFilename()) + } + if (_fontSelected && _fontSelected->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_SELECTED=\"%s\"\n", _fontSelected->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } buffer->putTextIndent(indent + 2, "\n"); - if (_text) + if (_text) { buffer->putTextIndent(indent + 2, "TEXT=\"%s\"\n", _text); + } buffer->putTextIndent(indent + 2, "\n"); @@ -363,14 +383,16 @@ bool UIEdit::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, if (strcmp(name, "SetSelectedFont") == 0) { stack->correctParams(1); - if (_fontSelected) _gameRef->_fontStorage->removeFont(_fontSelected); + if (_fontSelected) { + _gameRef->_fontStorage->removeFont(_fontSelected); + } _fontSelected = _gameRef->_fontStorage->addFont(stack->pop()->getString()); stack->pushBool(_fontSelected != NULL); return STATUS_OK; + } else { + return UIObject::scCallMethod(script, stack, thisStack, name); } - - else return UIObject::scCallMethod(script, stack, thisStack, name); } @@ -445,9 +467,9 @@ ScValue *UIEdit::scGetProperty(const char *name) { _scValue->setString(_text); } return _scValue; + } else { + return UIObject::scGetProperty(name); } - - else return UIObject::scGetProperty(name); } @@ -459,7 +481,7 @@ bool UIEdit::scSetProperty(const char *name, ScValue *value) { if (strcmp(name, "SelStart") == 0) { _selStart = value->getInt(); _selStart = MAX(_selStart, 0); - _selStart = MIN((size_t)_selStart, strlen(_text)); + _selStart = (int)MIN((size_t)_selStart, strlen(_text)); return STATUS_OK; } @@ -469,7 +491,7 @@ bool UIEdit::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "SelEnd") == 0) { _selEnd = value->getInt(); _selEnd = MAX(_selEnd, 0); - _selEnd = MIN((size_t)_selEnd, strlen(_text)); + _selEnd = (int)MIN((size_t)_selEnd, strlen(_text)); return STATUS_OK; } @@ -477,7 +499,7 @@ bool UIEdit::scSetProperty(const char *name, ScValue *value) { // CursorBlinkRate ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "CursorBlinkRate") == 0) { - _cursorBlinkRate = value->getInt(); + _cursorBlinkRate = (uint32)value->getInt(); return STATUS_OK; } @@ -516,9 +538,9 @@ bool UIEdit::scSetProperty(const char *name, ScValue *value) { setText(value->getString()); } return STATUS_OK; + } else { + return UIObject::scSetProperty(name, value); } - - else return UIObject::scSetProperty(name, value); } @@ -530,42 +552,58 @@ const char *UIEdit::scToString() { ////////////////////////////////////////////////////////////////////////// void UIEdit::setCursorChar(const char *character) { - if (!character) return; + if (!character) { + return; + } delete[] _cursorChar; _cursorChar = new char [strlen(character) + 1]; - if (_cursorChar) strcpy(_cursorChar, character); + if (_cursorChar) { + strcpy(_cursorChar, character); + } } ////////////////////////////////////////////////////////////////////////// bool UIEdit::display(int offsetX, int offsetY) { - if (!_visible) return STATUS_OK; + if (!_visible) { + return STATUS_OK; + } // hack! TTextEncoding OrigEncoding = _gameRef->_textEncoding; _gameRef->_textEncoding = TEXT_ANSI; - if (_back) _back->display(offsetX + _posX, offsetY + _posY, _width, _height); - if (_image) _image->draw(offsetX + _posX, offsetY + _posY, NULL); + if (_back) { + _back->display(offsetX + _posX, offsetY + _posY, _width, _height); + } + if (_image) { + _image->draw(offsetX + _posX, offsetY + _posY, NULL); + } // prepare fonts BaseFont *font; BaseFont *sfont; - if (_font) font = _font; - else font = _gameRef->_systemFont; + if (_font) { + font = _font; + } else { + font = _gameRef->_systemFont; + } - if (_fontSelected) sfont = _fontSelected; - else sfont = font; + if (_fontSelected) { + sfont = _fontSelected; + } else { + sfont = font; + } bool focused = isFocused(); _selStart = MAX(_selStart, 0); _selEnd = MAX(_selEnd, 0); - _selStart = MIN((size_t)_selStart, strlen(_text)); - _selEnd = MIN((size_t)_selEnd, strlen(_text)); + _selStart = (int)MIN((size_t)_selStart, strlen(_text)); + _selEnd = (int)MIN((size_t)_selEnd, strlen(_text)); //int CursorWidth = font->GetCharWidth(_cursorChar[0]); int cursorWidth = font->getTextWidth((byte *)_cursorChar); @@ -576,7 +614,9 @@ bool UIEdit::display(int offsetX, int offsetY) { if (_selStart >= _selEnd) { while (font->getTextWidth((byte *)_text + _scrollOffset, MAX(0, _selEnd - _scrollOffset)) > _width - cursorWidth - 2 * _frameWidth) { _scrollOffset++; - if (_scrollOffset >= (int)strlen(_text)) break; + if (_scrollOffset >= (int)strlen(_text)) { + break; + } } _scrollOffset = MIN(_scrollOffset, _selEnd); @@ -590,7 +630,9 @@ bool UIEdit::display(int offsetX, int offsetY) { > _width - cursorWidth - 2 * _frameWidth) { _scrollOffset++; - if (_scrollOffset >= (int)strlen(_text)) break; + if (_scrollOffset >= (int)strlen(_text)) { + break; + } } _scrollOffset = MIN(_scrollOffset, _selEnd); @@ -601,9 +643,9 @@ bool UIEdit::display(int offsetX, int offsetY) { } - int AlignOffset = 0; + int alignOffset = 0; - for (int Count = 0; Count < 2; Count++) { + for (int count = 0; count < 2; count++) { // draw text int xxx, yyy, width, height; @@ -613,61 +655,73 @@ bool UIEdit::display(int offsetX, int offsetY) { width = _posX + _width + offsetX - _frameWidth; height = MAX(font->getLetterHeight(), sfont->getLetterHeight()); - if (_gameRef->_textRTL) xxx += AlignOffset; + if (_gameRef->_textRTL) { + xxx += alignOffset; + } - TTextAlign Align = TAL_LEFT; + TTextAlign align = TAL_LEFT; // unselected 1 if (s1 > _scrollOffset) { - if (Count) font->drawText((byte *)_text + _scrollOffset, xxx, yyy, width - xxx, Align, height, s1 - _scrollOffset); + if (count) { + font->drawText((byte *)_text + _scrollOffset, xxx, yyy, width - xxx, align, height, s1 - _scrollOffset); + } xxx += font->getTextWidth((byte *)_text + _scrollOffset, s1 - _scrollOffset); - AlignOffset += font->getTextWidth((byte *)_text + _scrollOffset, s1 - _scrollOffset); + alignOffset += font->getTextWidth((byte *)_text + _scrollOffset, s1 - _scrollOffset); } // cursor if (focused && curFirst) { - if (Count) { + if (count) { if (g_system->getMillis() - _lastBlinkTime >= _cursorBlinkRate) { _lastBlinkTime = g_system->getMillis(); _cursorVisible = !_cursorVisible; } - if (_cursorVisible) - font->drawText((byte *)_cursorChar, xxx, yyy, width - xxx, Align, height, 1); + if (_cursorVisible) { + font->drawText((byte *)_cursorChar, xxx, yyy, width - xxx, align, height, 1); + } } xxx += cursorWidth; - AlignOffset += cursorWidth; + alignOffset += cursorWidth; } // selected int s3 = MAX(s1, _scrollOffset); if (s2 - s3 > 0) { - if (Count) sfont->drawText((byte *)_text + s3, xxx, yyy, width - xxx, Align, height, s2 - s3); + if (count) { + sfont->drawText((byte *)_text + s3, xxx, yyy, width - xxx, align, height, s2 - s3); + } xxx += sfont->getTextWidth((byte *)_text + s3, s2 - s3); - AlignOffset += sfont->getTextWidth((byte *)_text + s3, s2 - s3); + alignOffset += sfont->getTextWidth((byte *)_text + s3, s2 - s3); } // cursor if (focused && !curFirst) { - if (Count) { + if (count) { if (g_system->getMillis() - _lastBlinkTime >= _cursorBlinkRate) { _lastBlinkTime = g_system->getMillis(); _cursorVisible = !_cursorVisible; } - if (_cursorVisible) - font->drawText((byte *)_cursorChar, xxx, yyy, width - xxx, Align, height, 1); + if (_cursorVisible) { + font->drawText((byte *)_cursorChar, xxx, yyy, width - xxx, align, height, 1); + } } xxx += cursorWidth; - AlignOffset += cursorWidth; + alignOffset += cursorWidth; } // unselected 2 - if (Count) font->drawText((byte *)_text + s2, xxx, yyy, width - xxx, Align, height); - AlignOffset += font->getTextWidth((byte *)_text + s2); + if (count) { + font->drawText((byte *)_text + s2, xxx, yyy, width - xxx, align, height); + } + alignOffset += font->getTextWidth((byte *)_text + s2); - AlignOffset = (_width - 2 * _frameWidth) - AlignOffset; - if (AlignOffset < 0) AlignOffset = 0; + alignOffset = (_width - 2 * _frameWidth) - alignOffset; + if (alignOffset < 0) { + alignOffset = 0; + } } @@ -702,10 +756,17 @@ bool UIEdit::handleKeypress(Common::Event *event, bool printable) { case Common::KEYCODE_BACKSPACE: if (_selStart == _selEnd) { - if (_gameRef->_textRTL) deleteChars(_selStart, _selStart + 1); - else deleteChars(_selStart - 1, _selStart); - } else deleteChars(_selStart, _selEnd); - if (_selEnd >= _selStart) _selEnd -= MAX(1, _selEnd - _selStart); + if (_gameRef->_textRTL) { + deleteChars(_selStart, _selStart + 1); + } else { + deleteChars(_selStart - 1, _selStart); + } + } else { + deleteChars(_selStart, _selEnd); + } + if (_selEnd >= _selStart) { + _selEnd -= MAX(1, _selEnd - _selStart); + } _selStart = _selEnd; handled = true; @@ -714,24 +775,32 @@ bool UIEdit::handleKeypress(Common::Event *event, bool printable) { case Common::KEYCODE_LEFT: case Common::KEYCODE_UP: _selEnd--; - if (!BaseKeyboardState::isShiftDown()) _selStart = _selEnd; + if (!BaseKeyboardState::isShiftDown()) { + _selStart = _selEnd; + } handled = true; break; case Common::KEYCODE_RIGHT: case Common::KEYCODE_DOWN: _selEnd++; - if (!BaseKeyboardState::isShiftDown()) _selStart = _selEnd; + if (!BaseKeyboardState::isShiftDown()) { + _selStart = _selEnd; + } handled = true; break; case Common::KEYCODE_HOME: if (_gameRef->_textRTL) { _selEnd = strlen(_text); - if (!BaseKeyboardState::isShiftDown()) _selStart = _selEnd; + if (!BaseKeyboardState::isShiftDown()) { + _selStart = _selEnd; + } } else { _selEnd = 0; - if (!BaseKeyboardState::isShiftDown()) _selStart = _selEnd; + if (!BaseKeyboardState::isShiftDown()) { + _selStart = _selEnd; + } } handled = true; break; @@ -739,10 +808,14 @@ bool UIEdit::handleKeypress(Common::Event *event, bool printable) { case Common::KEYCODE_END: if (_gameRef->_textRTL) { _selEnd = 0; - if (!BaseKeyboardState::isShiftDown()) _selStart = _selEnd; + if (!BaseKeyboardState::isShiftDown()) { + _selStart = _selEnd; + } } else { _selEnd = strlen(_text); - if (!BaseKeyboardState::isShiftDown()) _selStart = _selEnd; + if (!BaseKeyboardState::isShiftDown()) { + _selStart = _selEnd; + } } handled = true; break; @@ -752,10 +825,18 @@ bool UIEdit::handleKeypress(Common::Event *event, bool printable) { if (_gameRef->_textRTL) { deleteChars(_selStart - 1, _selStart); _selEnd--; - if (_selEnd < 0) _selEnd = 0; - } else deleteChars(_selStart, _selStart + 1); - } else deleteChars(_selStart, _selEnd); - if (_selEnd > _selStart) _selEnd -= (_selEnd - _selStart); + if (_selEnd < 0) { + _selEnd = 0; + } + } else { + deleteChars(_selStart, _selStart + 1); + } + } else { + deleteChars(_selStart, _selEnd); + } + if (_selEnd > _selStart) { + _selEnd -= (_selEnd - _selStart); + } _selStart = _selEnd; handled = true; @@ -765,15 +846,20 @@ bool UIEdit::handleKeypress(Common::Event *event, bool printable) { } return handled; } else if (event->type == Common::EVENT_KEYDOWN && printable) { - if (_selStart != _selEnd) deleteChars(_selStart, _selEnd); + if (_selStart != _selEnd) { + deleteChars(_selStart, _selEnd); + } //WideString wstr = StringUtil::Utf8ToWide(event->kbd.ascii); WideString wstr; wstr += (char)event->kbd.ascii; _selEnd += insertChars(_selEnd, (byte *)StringUtil::wideToAnsi(wstr).c_str(), 1); - if (_gameRef->_textRTL) _selEnd = _selStart; - else _selStart = _selEnd; + if (_gameRef->_textRTL) { + _selEnd = _selStart; + } else { + _selStart = _selEnd; + } return true; } @@ -785,20 +871,26 @@ bool UIEdit::handleKeypress(Common::Event *event, bool printable) { ////////////////////////////////////////////////////////////////////////// int UIEdit::deleteChars(int start, int end) { - if (start > end) BaseUtils::swap(&start, &end); + if (start > end) { + BaseUtils::swap(&start, &end); + } start = MAX(start, (int)0); end = MIN((size_t)end, strlen(_text)); char *str = new char[strlen(_text) - (end - start) + 1]; if (str) { - if (start > 0) memcpy(str, _text, start); + if (start > 0) { + memcpy(str, _text, start); + } memcpy(str + MAX(0, start), _text + end, strlen(_text) - end + 1); delete[] _text; _text = str; } - if (_parentNotify && _parent) _parent->applyEvent(getName()); + if (_parentNotify && _parent) { + _parent->applyEvent(getName()); + } return end - start; } @@ -815,7 +907,9 @@ int UIEdit::insertChars(int pos, byte *chars, int num) { char *str = new char[strlen(_text) + num + 1]; if (str) { - if (pos > 0) memcpy(str, _text, pos); + if (pos > 0) { + memcpy(str, _text, pos); + } memcpy(str + pos + num, _text + pos, strlen(_text) - pos + 1); memcpy(str + pos, chars, num); @@ -823,7 +917,9 @@ int UIEdit::insertChars(int pos, byte *chars, int num) { delete[] _text; _text = str; } - if (_parentNotify && _parent) _parent->applyEvent(getName()); + if (_parentNotify && _parent) { + _parent->applyEvent(getName()); + } return num; } diff --git a/engines/wintermute/ui/ui_entity.cpp b/engines/wintermute/ui/ui_entity.cpp index 21fa3120ba..c2438b0fc6 100644 --- a/engines/wintermute/ui/ui_entity.cpp +++ b/engines/wintermute/ui/ui_entity.cpp @@ -49,7 +49,9 @@ UIEntity::UIEntity(BaseGame *inGame): UIObject(inGame) { ////////////////////////////////////////////////////////////////////////// UIEntity::~UIEntity() { - if (_entity) _gameRef->unregisterObject(_entity); + if (_entity) { + _gameRef->unregisterObject(_entity); + } _entity = NULL; } @@ -66,7 +68,9 @@ bool UIEntity::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing ENTITY container file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing ENTITY container file '%s'", filename); + } delete[] buffer; @@ -117,7 +121,9 @@ bool UIEntity::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -141,7 +147,9 @@ bool UIEntity::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_ENTITY: - if (DID_FAIL(setEntity((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(setEntity((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_SCRIPT: @@ -187,8 +195,9 @@ bool UIEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "DISABLED=%s\n", _disable ? "TRUE" : "FALSE"); buffer->putTextIndent(indent + 2, "VISIBLE=%s\n", _visible ? "TRUE" : "FALSE"); - if (_entity && _entity->getFilename()) + if (_entity && _entity->getFilename()) { buffer->putTextIndent(indent + 2, "ENTITY=\"%s\"\n", _entity->getFilename()); + } buffer->putTextIndent(indent + 2, "\n"); @@ -208,7 +217,9 @@ bool UIEntity::saveAsText(BaseDynamicBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// bool UIEntity::setEntity(const char *filename) { - if (_entity) _gameRef->unregisterObject(_entity); + if (_entity) { + _gameRef->unregisterObject(_entity); + } _entity = new AdEntity(_gameRef); if (!_entity || DID_FAIL(_entity->loadFile(filename))) { delete _entity; @@ -225,19 +236,25 @@ bool UIEntity::setEntity(const char *filename) { ////////////////////////////////////////////////////////////////////////// bool UIEntity::display(int offsetX, int offsetY) { - if (!_visible) return STATUS_OK; + if (!_visible) { + return STATUS_OK; + } if (_entity) { _entity->_posX = offsetX + _posX; _entity->_posY = offsetY + _posY; - if (_entity->_scale < 0) _entity->_zoomable = false; + if (_entity->_scale < 0) { + _entity->_zoomable = false; + } _entity->_shadowable = false; _entity->update(); bool origReg = _entity->_registrable; - if (_entity->_registrable && _disable) _entity->_registrable = false; + if (_entity->_registrable && _disable) { + _entity->_registrable = false; + } _entity->display(); _entity->_registrable = origReg; @@ -257,8 +274,11 @@ bool UIEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (strcmp(name, "GetEntity") == 0) { stack->correctParams(0); - if (_entity) stack->pushNative(_entity, true); - else stack->pushNULL(); + if (_entity) { + stack->pushNative(_entity, true); + } else { + stack->pushNULL(); + } return STATUS_OK; } @@ -271,15 +291,16 @@ bool UIEntity::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack const char *filename = stack->pop()->getString(); - if (DID_SUCCEED(setEntity(filename))) + if (DID_SUCCEED(setEntity(filename))) { stack->pushBool(true); - else + } else { stack->pushBool(false); + } return STATUS_OK; + } else { + return UIObject::scCallMethod(script, stack, thisStack, name); } - - else return UIObject::scCallMethod(script, stack, thisStack, name); } @@ -299,12 +320,15 @@ ScValue *UIEntity::scGetProperty(const char *name) { // Freezable ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Freezable") == 0) { - if (_entity) _scValue->setBool(_entity->_freezable); - else _scValue->setBool(false); + if (_entity) { + _scValue->setBool(_entity->_freezable); + } else { + _scValue->setBool(false); + } return _scValue; + } else { + return UIObject::scGetProperty(name); } - - else return UIObject::scGetProperty(name); } @@ -314,9 +338,13 @@ bool UIEntity::scSetProperty(const char *name, ScValue *value) { // Freezable ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "Freezable") == 0) { - if (_entity) _entity->makeFreezable(value->getBool()); + if (_entity) { + _entity->makeFreezable(value->getBool()); + } return STATUS_OK; - } else return UIObject::scSetProperty(name, value); + } else { + return UIObject::scSetProperty(name, value); + } } diff --git a/engines/wintermute/ui/ui_object.cpp b/engines/wintermute/ui/ui_object.cpp index ed58079ad2..e44bb0f741 100644 --- a/engines/wintermute/ui/ui_object.cpp +++ b/engines/wintermute/ui/ui_object.cpp @@ -71,14 +71,24 @@ UIObject::UIObject(BaseGame *inGame): BaseObject(inGame) { ////////////////////////////////////////////////////////////////////////// UIObject::~UIObject() { - if (!_gameRef->_loadInProgress) SystemClassRegistry::getInstance()->enumInstances(BaseGame::invalidateValues, "ScValue", (void *)this); + if (!_gameRef->_loadInProgress) { + SystemClassRegistry::getInstance()->enumInstances(BaseGame::invalidateValues, "ScValue", (void *)this); + } - if (_back) delete _back; - if (_font && !_sharedFonts) _gameRef->_fontStorage->removeFont(_font); + if (_back) { + delete _back; + } + if (_font && !_sharedFonts) { + _gameRef->_fontStorage->removeFont(_font); + } - if (_image && !_sharedImages) delete _image; + if (_image && !_sharedImages) { + delete _image; + } - if (_text) delete[] _text; + if (_text) { + delete[] _text; + } _focusedWidget = NULL; // ref only } @@ -86,12 +96,16 @@ UIObject::~UIObject() { ////////////////////////////////////////////////////////////////////////// void UIObject::setText(const char *text) { - if (_text) delete[] _text; + if (_text) { + delete[] _text; + } _text = new char [strlen(text) + 1]; if (_text) { strcpy(_text, text); for (int i = 0; i < strlen(_text); i++) { - if (_text[i] == '|') _text[i] = '\n'; + if (_text[i] == '|') { + _text[i] = '\n'; + } } } } @@ -119,7 +133,9 @@ void UIObject::correctSize() { if (_image) { _image->getBoundingRect(&rect, 0, 0); _width = rect.right - rect.left; - } else _width = 100; + } else { + _width = 100; + } } if (_height <= 0) { @@ -129,7 +145,9 @@ void UIObject::correctSize() { } } - if (_back) _back->correctSize(&_width, &_height); + if (_back) { + _back->correctSize(&_width, &_height); + } } @@ -143,14 +161,16 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "SetFont") == 0) { stack->correctParams(1); - ScValue *Val = stack->pop(); + ScValue *val = stack->pop(); - if (_font) _gameRef->_fontStorage->removeFont(_font); - if (Val->isNULL()) { + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } + if (val->isNULL()) { _font = NULL; stack->pushBool(true); } else { - _font = _gameRef->_fontStorage->addFont(Val->getString()); + _font = _gameRef->_fontStorage->addFont(val->getString()); stack->pushBool(_font != NULL); } return STATUS_OK; @@ -177,7 +197,9 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _image; _image = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -187,8 +209,11 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetImage") == 0) { stack->correctParams(0); - if (!_image || !_image->getFilename()) stack->pushNULL(); - else stack->pushString(_image->getFilename()); + if (!_image || !_image->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_image->getFilename()); + } return STATUS_OK; } @@ -198,8 +223,11 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetImageObject") == 0) { stack->correctParams(0); - if (!_image) stack->pushNULL(); - else stack->pushNative(_image, true); + if (!_image) { + stack->pushNULL(); + } else { + stack->pushNative(_image, true); + } return STATUS_OK; } @@ -251,8 +279,12 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack bool done = false; for (int j = 0; j < win->_widgets.getSize(); j++) { if (win->_widgets[j] == this) { - if (strcmp(name, "MoveAfter") == 0) i++; - if (j >= i) j++; + if (strcmp(name, "MoveAfter") == 0) { + i++; + } + if (j >= i) { + j++; + } win->_widgets.insertAt(i, this); win->_widgets.removeAt(j); @@ -262,10 +294,16 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack break; } } - if (!done) stack->pushBool(false); - } else stack->pushBool(false); + if (!done) { + stack->pushBool(false); + } + } else { + stack->pushBool(false); + } - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -286,7 +324,9 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; } @@ -307,12 +347,14 @@ bool UIObject::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack } } stack->pushBool(true); - } else stack->pushBool(false); + } else { + stack->pushBool(false); + } return STATUS_OK; + } else { + return BaseObject::scCallMethod(script, stack, thisStack, name); } - - else return BaseObject::scCallMethod(script, stack, thisStack, name); } @@ -402,18 +444,22 @@ ScValue *UIObject::scGetProperty(const char *name) { for (int i = 0; i < win->_widgets.getSize(); i++) { if (win->_widgets[i] == this) { if (strcmp(name, "NextSibling") == 0) { - if (i < win->_widgets.getSize() - 1) _scValue->setNative(win->_widgets[i + 1], true); + if (i < win->_widgets.getSize() - 1) { + _scValue->setNative(win->_widgets[i + 1], true); + } } else { - if (i > 0) _scValue->setNative(win->_widgets[i - 1], true); + if (i > 0) { + _scValue->setNative(win->_widgets[i - 1], true); + } } break; } } } return _scValue; + } else { + return BaseObject::scGetProperty(name); } - - else return BaseObject::scGetProperty(name); } @@ -473,9 +519,9 @@ bool UIObject::scSetProperty(const char *name, ScValue *value) { else if (strcmp(name, "Text") == 0) { setText(value->getString()); return STATUS_OK; + } else { + return BaseObject::scSetProperty(name, value); } - - else return BaseObject::scSetProperty(name, value); } @@ -487,13 +533,20 @@ const char *UIObject::scToString() { ////////////////////////////////////////////////////////////////////////// bool UIObject::isFocused() { - if (!_gameRef->_focusedWindow) return false; - if (_gameRef->_focusedWindow == this) return true; + if (!_gameRef->_focusedWindow) { + return false; + } + if (_gameRef->_focusedWindow == this) { + return true; + } UIObject *obj = _gameRef->_focusedWindow; while (obj) { - if (obj == this) return true; - else obj = obj->_focusedWidget; + if (obj == this) { + return true; + } else { + obj = obj->_focusedWidget; + } } return false; } @@ -524,9 +577,13 @@ bool UIObject::focus() { obj = this; while (obj) { if (obj->_parent) { - if (!obj->_disable && obj->_canFocus) obj->_parent->_focusedWidget = obj; + if (!obj->_disable && obj->_canFocus) { + obj->_parent->_focusedWidget = obj; + } } else { - if (obj->_type == UI_WINDOW) _gameRef->focusWindow((UIWindow *)obj); + if (obj->_type == UI_WINDOW) { + _gameRef->focusWindow((UIWindow *)obj); + } } obj = obj->_parent; @@ -547,8 +604,12 @@ bool UIObject::getTotalOffset(int *offsetX, int *offsetY) { obj = obj->_parent; } - if (offsetX) *offsetX = offX; - if (offsetY) *offsetY = offY; + if (offsetX) { + *offsetX = offX; + } + if (offsetY) { + *offsetY = offY; + } return STATUS_OK; } diff --git a/engines/wintermute/ui/ui_text.cpp b/engines/wintermute/ui/ui_text.cpp index 6d838b8d37..25fef4fd93 100644 --- a/engines/wintermute/ui/ui_text.cpp +++ b/engines/wintermute/ui/ui_text.cpp @@ -62,14 +62,22 @@ UIText::~UIText() { ////////////////////////////////////////////////////////////////////////// bool UIText::display(int offsetX, int offsetY) { - if (!_visible) return STATUS_OK; + if (!_visible) { + return STATUS_OK; + } BaseFont *font = _font; - if (!font) font = _gameRef->_systemFont; + if (!font) { + font = _gameRef->_systemFont; + } - if (_back) _back->display(offsetX + _posX, offsetY + _posY, _width, _height); - if (_image) _image->draw(offsetX + _posX, offsetY + _posY, NULL); + if (_back) { + _back->display(offsetX + _posX, offsetY + _posY, _width, _height); + } + if (_image) { + _image->draw(offsetX + _posX, offsetY + _posY, NULL); + } if (font && _text) { int textOffset; @@ -105,7 +113,9 @@ bool UIText::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing STATIC file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing STATIC file '%s'", filename); + } delete[] buffer; @@ -175,7 +185,9 @@ bool UIText::loadBuffer(byte *buffer, bool complete) { while (cmd > 0 && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -207,9 +219,13 @@ bool UIText::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; + if (!_font) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_TEXT: @@ -218,15 +234,23 @@ bool UIText::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TEXT_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) _textAlign = TAL_LEFT; - else if (scumm_stricmp((char *)params, "right") == 0) _textAlign = TAL_RIGHT; - else _textAlign = TAL_CENTER; + if (scumm_stricmp((char *)params, "left") == 0) { + _textAlign = TAL_LEFT; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _textAlign = TAL_RIGHT; + } else { + _textAlign = TAL_CENTER; + } break; case TOKEN_VERTICAL_ALIGN: - if (scumm_stricmp((char *)params, "top") == 0) _verticalAlign = VAL_TOP; - else if (scumm_stricmp((char *)params, "bottom") == 0) _verticalAlign = VAL_BOTTOM; - else _verticalAlign = VAL_CENTER; + if (scumm_stricmp((char *)params, "top") == 0) { + _verticalAlign = VAL_TOP; + } else if (scumm_stricmp((char *)params, "bottom") == 0) { + _verticalAlign = VAL_BOTTOM; + } else { + _verticalAlign = VAL_CENTER; + } break; case TOKEN_X: @@ -300,20 +324,25 @@ bool UIText::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); - if (_back && _back->getFilename()) + if (_back && _back->getFilename()) { buffer->putTextIndent(indent + 2, "BACK=\"%s\"\n", _back->getFilename()); + } - if (_image && _image->getFilename()) + if (_image && _image->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE=\"%s\"\n", _image->getFilename()); + } - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } - if (_text) + if (_text) { buffer->putTextIndent(indent + 2, "TEXT=\"%s\"\n", _text); + } switch (_textAlign) { case TAL_LEFT: @@ -390,12 +419,14 @@ bool UIText::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack, ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "HeightToFit") == 0) { stack->correctParams(0); - if (_font && _text) _height = _font->getTextHeight((byte *)_text, _width); + if (_font && _text) { + _height = _font->getTextHeight((byte *)_text, _width); + } stack->pushNULL(); return STATUS_OK; + } else { + return UIObject::scCallMethod(script, stack, thisStack, name); } - - else return UIObject::scCallMethod(script, stack, thisStack, name); } @@ -425,9 +456,9 @@ ScValue *UIText::scGetProperty(const char *name) { else if (strcmp(name, "VerticalAlign") == 0) { _scValue->setInt(_verticalAlign); return _scValue; + } else { + return UIObject::scGetProperty(name); } - - else return UIObject::scGetProperty(name); } @@ -438,7 +469,9 @@ bool UIText::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// if (strcmp(name, "TextAlign") == 0) { int i = value->getInt(); - if (i < 0 || i >= NUM_TEXT_ALIGN) i = 0; + if (i < 0 || i >= NUM_TEXT_ALIGN) { + i = 0; + } _textAlign = (TTextAlign)i; return STATUS_OK; } @@ -448,12 +481,14 @@ bool UIText::scSetProperty(const char *name, ScValue *value) { ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "VerticalAlign") == 0) { int i = value->getInt(); - if (i < 0 || i >= NUM_VERTICAL_ALIGN) i = 0; + if (i < 0 || i >= NUM_VERTICAL_ALIGN) { + i = 0; + } _verticalAlign = (TVerticalAlign)i; return STATUS_OK; + } else { + return UIObject::scSetProperty(name, value); } - - else return UIObject::scSetProperty(name, value); } diff --git a/engines/wintermute/ui/ui_tiled_image.cpp b/engines/wintermute/ui/ui_tiled_image.cpp index e0b2a75ee4..c11361de8d 100644 --- a/engines/wintermute/ui/ui_tiled_image.cpp +++ b/engines/wintermute/ui/ui_tiled_image.cpp @@ -64,7 +64,9 @@ UITiledImage::~UITiledImage() { ////////////////////////////////////////////////////////////////////////// bool UITiledImage::display(int x, int y, int width, int height) { - if (!_image) return STATUS_FAILED; + if (!_image) { + return STATUS_FAILED; + } int tileWidth = _middleMiddle.right - _middleMiddle.left; int tileHeight = _middleMiddle.bottom - _middleMiddle.top; @@ -129,7 +131,9 @@ bool UITiledImage::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing TILED_IMAGE file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing TILED_IMAGE file '%s'", filename); + } delete[] buffer; @@ -193,7 +197,9 @@ bool UITiledImage::loadBuffer(byte *buffer, bool complete) { while ((cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) > 0) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_IMAGE: @@ -288,17 +294,35 @@ bool UITiledImage::loadBuffer(byte *buffer, bool complete) { int width = _image->_surface->getWidth() / 3; int height = _image->_surface->getHeight() / 3; - if (BasePlatform::isRectEmpty(&_upLeft)) BasePlatform::setRect(&_upLeft, 0, 0, width, height); - if (BasePlatform::isRectEmpty(&_upMiddle)) BasePlatform::setRect(&_upMiddle, width, 0, 2 * width, height); - if (BasePlatform::isRectEmpty(&_upRight)) BasePlatform::setRect(&_upRight, 2 * width, 0, 3 * width, height); + if (BasePlatform::isRectEmpty(&_upLeft)) { + BasePlatform::setRect(&_upLeft, 0, 0, width, height); + } + if (BasePlatform::isRectEmpty(&_upMiddle)) { + BasePlatform::setRect(&_upMiddle, width, 0, 2 * width, height); + } + if (BasePlatform::isRectEmpty(&_upRight)) { + BasePlatform::setRect(&_upRight, 2 * width, 0, 3 * width, height); + } - if (BasePlatform::isRectEmpty(&_middleLeft)) BasePlatform::setRect(&_middleLeft, 0, height, width, 2 * height); - if (BasePlatform::isRectEmpty(&_middleMiddle)) BasePlatform::setRect(&_middleMiddle, width, height, 2 * width, 2 * height); - if (BasePlatform::isRectEmpty(&_middleRight)) BasePlatform::setRect(&_middleRight, 2 * width, height, 3 * width, 2 * height); + if (BasePlatform::isRectEmpty(&_middleLeft)) { + BasePlatform::setRect(&_middleLeft, 0, height, width, 2 * height); + } + if (BasePlatform::isRectEmpty(&_middleMiddle)) { + BasePlatform::setRect(&_middleMiddle, width, height, 2 * width, 2 * height); + } + if (BasePlatform::isRectEmpty(&_middleRight)) { + BasePlatform::setRect(&_middleRight, 2 * width, height, 3 * width, 2 * height); + } - if (BasePlatform::isRectEmpty(&_downLeft)) BasePlatform::setRect(&_downLeft, 0, 2 * height, width, 3 * height); - if (BasePlatform::isRectEmpty(&_downMiddle)) BasePlatform::setRect(&_downMiddle, width, 2 * height, 2 * width, 3 * height); - if (BasePlatform::isRectEmpty(&_downRight)) BasePlatform::setRect(&_downRight, 2 * width, 2 * height, 3 * width, 3 * height); + if (BasePlatform::isRectEmpty(&_downLeft)) { + BasePlatform::setRect(&_downLeft, 0, 2 * height, width, 3 * height); + } + if (BasePlatform::isRectEmpty(&_downMiddle)) { + BasePlatform::setRect(&_downMiddle, width, 2 * height, 2 * width, 3 * height); + } + if (BasePlatform::isRectEmpty(&_downRight)) { + BasePlatform::setRect(&_downRight, 2 * width, 2 * height, 3 * width, 3 * height); + } } return STATUS_OK; @@ -309,8 +333,9 @@ bool UITiledImage::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent, "TILED_IMAGE\n"); buffer->putTextIndent(indent, "{\n"); - if (_image && _image->_surfaceFilename) + if (_image && _image->_surfaceFilename) { buffer->putTextIndent(indent + 2, "IMAGE=\"%s\"\n", _image->_surfaceFilename); + } int h1, h2, h3; int v1, v2, v3; diff --git a/engines/wintermute/ui/ui_window.cpp b/engines/wintermute/ui/ui_window.cpp index b14c832397..f221405f15 100644 --- a/engines/wintermute/ui/ui_window.cpp +++ b/engines/wintermute/ui/ui_window.cpp @@ -103,10 +103,16 @@ void UIWindow::cleanup() { _viewport = NULL; delete _backInactive; - if (!_sharedFonts && _fontInactive) _gameRef->_fontStorage->removeFont(_fontInactive); - if (!_sharedImages && _imageInactive) delete _imageInactive; + if (!_sharedFonts && _fontInactive) { + _gameRef->_fontStorage->removeFont(_fontInactive); + } + if (!_sharedImages && _imageInactive) { + delete _imageInactive; + } - for (int i = 0; i < _widgets.getSize(); i++) delete _widgets[i]; + for (int i = 0; i < _widgets.getSize(); i++) { + delete _widgets[i]; + } _widgets.removeAll(); } @@ -115,7 +121,9 @@ void UIWindow::cleanup() { bool UIWindow::display(int offsetX, int offsetY) { // go exclusive if (_mode == WINDOW_EXCLUSIVE || _mode == WINDOW_SYSTEM_EXCLUSIVE) { - if (!_shieldWindow) _shieldWindow = new UIWindow(_gameRef); + if (!_shieldWindow) { + _shieldWindow = new UIWindow(_gameRef); + } if (_shieldWindow) { _shieldWindow->_posX = _shieldWindow->_posY = 0; _shieldWindow->_width = _gameRef->_renderer->_width; @@ -139,8 +147,9 @@ bool UIWindow::display(int offsetX, int offsetY) { } } - if (!_visible) + if (!_visible) { return STATUS_OK; + } if (_fadeBackground) { Graphics::PixelFormat format = _gameRef->_renderer->getPixelFormat(); @@ -166,7 +175,9 @@ bool UIWindow::display(int offsetX, int offsetY) { bool popViewport = false; if (_clipContents) { - if (!_viewport) _viewport = new BaseViewport(_gameRef); + if (!_viewport) { + _viewport = new BaseViewport(_gameRef); + } if (_viewport) { _viewport->setRect(_posX + offsetX, _posY + offsetY, _posX + _width + offsetX, _posY + _height + offsetY); _gameRef->pushViewport(_viewport); @@ -180,34 +191,46 @@ bool UIWindow::display(int offsetX, int offsetY) { BaseFont *font = _font; if (!isFocused()) { - if (_backInactive) back = _backInactive; - if (_imageInactive) image = _imageInactive; - if (_fontInactive) font = _fontInactive; + if (_backInactive) { + back = _backInactive; + } + if (_imageInactive) { + image = _imageInactive; + } + if (_fontInactive) { + font = _fontInactive; + } } - if (_alphaColor != 0) + if (_alphaColor != 0) { _gameRef->_renderer->_forceAlphaColor = _alphaColor; - if (back) + } + if (back) { back->display(_posX + offsetX, _posY + offsetY, _width, _height); - if (image) + } + if (image) { image->draw(_posX + offsetX, _posY + offsetY, _transparent ? NULL : this); + } if (!BasePlatform::isRectEmpty(&_titleRect) && font && _text) { font->drawText((byte *)_text, _posX + offsetX + _titleRect.left, _posY + offsetY + _titleRect.top, _titleRect.right - _titleRect.left, _titleAlign, _titleRect.bottom - _titleRect.top); } - if (!_transparent && !image) + if (!_transparent && !image) { _gameRef->_renderer->addRectToList(new BaseActiveRect(_gameRef, this, NULL, _posX + offsetX, _posY + offsetY, _width, _height, 100, 100, false)); + } for (int i = 0; i < _widgets.getSize(); i++) { _widgets[i]->display(_posX + offsetX, _posY + offsetY); } - if (_alphaColor != 0) + if (_alphaColor != 0) { _gameRef->_renderer->_forceAlphaColor = 0; + } - if (popViewport) + if (popViewport) { _gameRef->popViewport(); + } return STATUS_OK; } @@ -225,7 +248,9 @@ bool UIWindow::loadFile(const char *filename) { setFilename(filename); - if (DID_FAIL(ret = loadBuffer(buffer, true))) _gameRef->LOG(0, "Error parsing WINDOW file '%s'", filename); + if (DID_FAIL(ret = loadBuffer(buffer, true))) { + _gameRef->LOG(0, "Error parsing WINDOW file '%s'", filename); + } delete[] buffer; @@ -330,7 +355,9 @@ bool UIWindow::loadBuffer(byte *buffer, bool complete) { while (cmd >= PARSERR_TOKENNOTFOUND && (cmd = parser.getCommand((char **)&buffer, commands, (char **)¶ms)) >= PARSERR_TOKENNOTFOUND) { switch (cmd) { case TOKEN_TEMPLATE: - if (DID_FAIL(loadFile((char *)params))) cmd = PARSERR_GENERIC; + if (DID_FAIL(loadFile((char *)params))) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_NAME: @@ -382,15 +409,23 @@ bool UIWindow::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_FONT: - if (_font) _gameRef->_fontStorage->removeFont(_font); + if (_font) { + _gameRef->_fontStorage->removeFont(_font); + } _font = _gameRef->_fontStorage->addFont((char *)params); - if (!_font) cmd = PARSERR_GENERIC; + if (!_font) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_FONT_INACTIVE: - if (_fontInactive) _gameRef->_fontStorage->removeFont(_fontInactive); + if (_fontInactive) { + _gameRef->_fontStorage->removeFont(_fontInactive); + } _fontInactive = _gameRef->_fontStorage->addFont((char *)params); - if (!_fontInactive) cmd = PARSERR_GENERIC; + if (!_fontInactive) { + cmd = PARSERR_GENERIC; + } break; case TOKEN_TITLE: @@ -399,9 +434,13 @@ bool UIWindow::loadBuffer(byte *buffer, bool complete) { break; case TOKEN_TITLE_ALIGN: - if (scumm_stricmp((char *)params, "left") == 0) _titleAlign = TAL_LEFT; - else if (scumm_stricmp((char *)params, "right") == 0) _titleAlign = TAL_RIGHT; - else _titleAlign = TAL_CENTER; + if (scumm_stricmp((char *)params, "left") == 0) { + _titleAlign = TAL_LEFT; + } else if (scumm_stricmp((char *)params, "right") == 0) { + _titleAlign = TAL_RIGHT; + } else { + _titleAlign = TAL_CENTER; + } break; case TOKEN_TITLE_RECT: @@ -572,8 +611,9 @@ bool UIWindow::loadBuffer(byte *buffer, bool complete) { } _alphaColor = BYTETORGBA(ar, ag, ab, alpha); - if (_fadeBackground) + if (_fadeBackground) { _fadeColor = BYTETORGBA(fadeR, fadeG, fadeB, fadeA); + } _focusedWidget = NULL; @@ -590,28 +630,36 @@ bool UIWindow::saveAsText(BaseDynamicBuffer *buffer, int indent) { buffer->putTextIndent(indent + 2, "\n"); - if (_back && _back->getFilename()) + if (_back && _back->getFilename()) { buffer->putTextIndent(indent + 2, "BACK=\"%s\"\n", _back->getFilename()); - if (_backInactive && _backInactive->getFilename()) + } + if (_backInactive && _backInactive->getFilename()) { buffer->putTextIndent(indent + 2, "BACK_INACTIVE=\"%s\"\n", _backInactive->getFilename()); + } - if (_image && _image->getFilename()) + if (_image && _image->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE=\"%s\"\n", _image->getFilename()); - if (_imageInactive && _imageInactive->getFilename()) + } + if (_imageInactive && _imageInactive->getFilename()) { buffer->putTextIndent(indent + 2, "IMAGE_INACTIVE=\"%s\"\n", _imageInactive->getFilename()); + } - if (_font && _font->getFilename()) + if (_font && _font->getFilename()) { buffer->putTextIndent(indent + 2, "FONT=\"%s\"\n", _font->getFilename()); - if (_fontInactive && _fontInactive->getFilename()) + } + if (_fontInactive && _fontInactive->getFilename()) { buffer->putTextIndent(indent + 2, "FONT_INACTIVE=\"%s\"\n", _fontInactive->getFilename()); + } - if (_cursor && _cursor->getFilename()) + if (_cursor && _cursor->getFilename()) { buffer->putTextIndent(indent + 2, "CURSOR=\"%s\"\n", _cursor->getFilename()); + } buffer->putTextIndent(indent + 2, "\n"); - if (_text) + if (_text) { buffer->putTextIndent(indent + 2, "TITLE=\"%s\"\n", _text); + } switch (_titleAlign) { case TAL_LEFT: @@ -675,8 +723,9 @@ bool UIWindow::saveAsText(BaseDynamicBuffer *buffer, int indent) { BaseClass::saveAsText(buffer, indent + 2); // controls - for (int i = 0; i < _widgets.getSize(); i++) + for (int i = 0; i < _widgets.getSize(); i++) { _widgets[i]->saveAsText(buffer, indent + 2); + } buffer->putTextIndent(indent, "}\n"); @@ -686,7 +735,9 @@ bool UIWindow::saveAsText(BaseDynamicBuffer *buffer, int indent) { ////////////////////////////////////////////////////////////////////////// bool UIWindow::enableWidget(const char *name, bool Enable) { for (int i = 0; i < _widgets.getSize(); i++) { - if (scumm_stricmp(_widgets[i]->getName(), name) == 0) _widgets[i]->_disable = !Enable; + if (scumm_stricmp(_widgets[i]->getName(), name) == 0) { + _widgets[i]->_disable = !Enable; + } } return STATUS_OK; } @@ -695,7 +746,9 @@ bool UIWindow::enableWidget(const char *name, bool Enable) { ////////////////////////////////////////////////////////////////////////// bool UIWindow::showWidget(const char *name, bool Visible) { for (int i = 0; i < _widgets.getSize(); i++) { - if (scumm_stricmp(_widgets[i]->getName(), name) == 0) _widgets[i]->_visible = Visible; + if (scumm_stricmp(_widgets[i]->getName(), name) == 0) { + _widgets[i]->_visible = Visible; + } } return STATUS_OK; } @@ -713,8 +766,11 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); if (val->getType() == VAL_INT) { int widget = val->getInt(); - if (widget < 0 || widget >= _widgets.getSize()) stack->pushNULL(); - else stack->pushNative(_widgets[widget], true); + if (widget < 0 || widget >= _widgets.getSize()) { + stack->pushNULL(); + } else { + stack->pushNative(_widgets[widget], true); + } } else { for (int i = 0; i < _widgets.getSize(); i++) { if (scumm_stricmp(_widgets[i]->getName(), val->getString()) == 0) { @@ -734,7 +790,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack else if (strcmp(name, "SetInactiveFont") == 0) { stack->correctParams(1); - if (_fontInactive) _gameRef->_fontStorage->removeFont(_fontInactive); + if (_fontInactive) { + _gameRef->_fontStorage->removeFont(_fontInactive); + } _fontInactive = _gameRef->_fontStorage->addFont(stack->pop()->getString()); stack->pushBool(_fontInactive != NULL); @@ -754,7 +812,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack delete _imageInactive; _imageInactive = NULL; stack->pushBool(false); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -764,8 +824,11 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetInactiveImage") == 0) { stack->correctParams(0); - if (!_imageInactive || !_imageInactive->getFilename()) stack->pushNULL(); - else stack->pushString(_imageInactive->getFilename()); + if (!_imageInactive || !_imageInactive->getFilename()) { + stack->pushNULL(); + } else { + stack->pushString(_imageInactive->getFilename()); + } return STATUS_OK; } @@ -775,8 +838,11 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "GetInactiveImageObject") == 0) { stack->correctParams(0); - if (!_imageInactive) stack->pushNULL(); - else stack->pushNative(_imageInactive, true); + if (!_imageInactive) { + stack->pushNULL(); + } else { + stack->pushNative(_imageInactive, true); + } return STATUS_OK; } @@ -834,7 +900,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack cleanup(); if (!val->isNULL()) { stack->pushBool(DID_SUCCEED(loadFile(val->getString()))); - } else stack->pushBool(true); + } else { + stack->pushBool(true); + } return STATUS_OK; } @@ -847,7 +915,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); UIButton *btn = new UIButton(_gameRef); - if (!val->isNULL()) btn->setName(val->getString()); + if (!val->isNULL()) { + btn->setName(val->getString()); + } stack->pushNative(btn, true); btn->_parent = this; @@ -864,7 +934,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); UIText *sta = new UIText(_gameRef); - if (!val->isNULL()) sta->setName(val->getString()); + if (!val->isNULL()) { + sta->setName(val->getString()); + } stack->pushNative(sta, true); sta->_parent = this; @@ -881,7 +953,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); UIEdit *edi = new UIEdit(_gameRef); - if (!val->isNULL()) edi->setName(val->getString()); + if (!val->isNULL()) { + edi->setName(val->getString()); + } stack->pushNative(edi, true); edi->_parent = this; @@ -898,7 +972,9 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack ScValue *val = stack->pop(); UIWindow *win = new UIWindow(_gameRef); - if (!val->isNULL()) win->setName(val->getString()); + if (!val->isNULL()) { + win->setName(val->getString()); + } stack->pushNative(win, true); win->_parent = this; @@ -919,14 +995,20 @@ bool UIWindow::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack if (_widgets[i] == obj) { delete _widgets[i]; _widgets.removeAt(i); - if (val->getType() == VAL_VARIABLE_REF) val->setNULL(); + if (val->getType() == VAL_VARIABLE_REF) { + val->setNULL(); + } } } stack->pushNULL(); return STATUS_OK; - } else if DID_SUCCEED(_gameRef->windowScriptMethodHook(this, script, stack, name)) return STATUS_OK; + } else if DID_SUCCEED(_gameRef->windowScriptMethodHook(this, script, stack, name)) { + return STATUS_OK; + } - else return UIObject::scCallMethod(script, stack, thisStack, name); + else { + return UIObject::scCallMethod(script, stack, thisStack, name); + } } @@ -1012,9 +1094,9 @@ ScValue *UIWindow::scGetProperty(const char *name) { else if (strcmp(name, "FadeColor") == 0) { _scValue->setInt((int)_fadeColor); return _scValue; + } else { + return UIObject::scGetProperty(name); } - - else return UIObject::scGetProperty(name); } @@ -1081,9 +1163,9 @@ bool UIWindow::scSetProperty(const char *name, ScValue *value) { // Exclusive ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "Exclusive") == 0) { - if (value->getBool()) + if (value->getBool()) { goExclusive(); - else { + } else { close(); _visible = true; } @@ -1094,16 +1176,16 @@ bool UIWindow::scSetProperty(const char *name, ScValue *value) { // SystemExclusive ////////////////////////////////////////////////////////////////////////// else if (strcmp(name, "SystemExclusive") == 0) { - if (value->getBool()) + if (value->getBool()) { goSystemExclusive(); - else { + } else { close(); _visible = true; } return STATUS_OK; + } else { + return UIObject::scSetProperty(name, value); } - - else return UIObject::scSetProperty(name, value); } @@ -1119,8 +1201,11 @@ bool UIWindow::handleKeypress(Common::Event *event, bool printable) { if (event->type == Common::EVENT_KEYDOWN && event->kbd.keycode == Common::KEYCODE_TAB) { return DID_SUCCEED(moveFocus(!BaseKeyboardState::isShiftDown())); } else { - if (_focusedWidget) return _focusedWidget->handleKeypress(event, printable); - else return false; + if (_focusedWidget) { + return _focusedWidget->handleKeypress(event, printable); + } else { + return false; + } } return false; } @@ -1128,8 +1213,11 @@ bool UIWindow::handleKeypress(Common::Event *event, bool printable) { ////////////////////////////////////////////////////////////////////////// bool UIWindow::handleMouseWheel(int Delta) { - if (_focusedWidget) return _focusedWidget->handleMouseWheel(Delta); - else return false; + if (_focusedWidget) { + return _focusedWidget->handleMouseWheel(Delta); + } else { + return false; + } } @@ -1204,11 +1292,16 @@ bool UIWindow::moveFocus(bool forward) { break; } } - if (!found) _focusedWidget = NULL; + if (!found) { + _focusedWidget = NULL; + } if (!_focusedWidget) { - if (_widgets.getSize() > 0) i = 0; - else return STATUS_OK; + if (_widgets.getSize() > 0) { + i = 0; + } else { + return STATUS_OK; + } } int numTries = 0; @@ -1223,10 +1316,14 @@ bool UIWindow::moveFocus(bool forward) { if (forward) { i++; - if (i >= _widgets.getSize()) i = 0; + if (i >= _widgets.getSize()) { + i = 0; + } } else { i--; - if (i < 0) i = _widgets.getSize() - 1; + if (i < 0) { + i = _widgets.getSize() - 1; + } } numTries++; } @@ -1237,7 +1334,9 @@ bool UIWindow::moveFocus(bool forward) { ////////////////////////////////////////////////////////////////////////// bool UIWindow::goExclusive() { - if (_mode == WINDOW_EXCLUSIVE) return STATUS_OK; + if (_mode == WINDOW_EXCLUSIVE) { + return STATUS_OK; + } if (_mode == WINDOW_NORMAL) { _ready = false; @@ -1246,13 +1345,17 @@ bool UIWindow::goExclusive() { _disable = false; _gameRef->focusWindow(this); return STATUS_OK; - } else return STATUS_FAILED; + } else { + return STATUS_FAILED; + } } ////////////////////////////////////////////////////////////////////////// bool UIWindow::goSystemExclusive() { - if (_mode == WINDOW_SYSTEM_EXCLUSIVE) return STATUS_OK; + if (_mode == WINDOW_SYSTEM_EXCLUSIVE) { + return STATUS_OK; + } makeFreezable(false); @@ -1287,8 +1390,11 @@ bool UIWindow::listen(BaseScriptHolder *param1, uint32 param2) { switch (obj->_type) { case UI_BUTTON: - if (scumm_stricmp(obj->getName(), "close") == 0) close(); - else return BaseObject::listen(param1, param2); + if (scumm_stricmp(obj->getName(), "close") == 0) { + close(); + } else { + return BaseObject::listen(param1, param2); + } break; default: return BaseObject::listen(param1, param2); @@ -1300,8 +1406,9 @@ bool UIWindow::listen(BaseScriptHolder *param1, uint32 param2) { ////////////////////////////////////////////////////////////////////////// void UIWindow::makeFreezable(bool freezable) { - for (int i = 0; i < _widgets.getSize(); i++) + for (int i = 0; i < _widgets.getSize(); i++) { _widgets[i]->makeFreezable(freezable); + } BaseObject::makeFreezable(freezable); } @@ -1311,7 +1418,9 @@ void UIWindow::makeFreezable(bool freezable) { bool UIWindow::getWindowObjects(BaseArray &objects, bool interactiveOnly) { for (int i = 0; i < _widgets.getSize(); i++) { UIObject *control = _widgets[i]; - if (control->_disable && interactiveOnly) continue; + if (control->_disable && interactiveOnly) { + continue; + } switch (control->_type) { case UI_WINDOW: @@ -1324,7 +1433,9 @@ bool UIWindow::getWindowObjects(BaseArray &objects, bool break; default: - if (!interactiveOnly) objects.add(control); + if (!interactiveOnly) { + objects.add(control); + } } } return STATUS_OK; diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp index 27b2b0b727..51f0f5817e 100644 --- a/engines/wintermute/utils/path_util.cpp +++ b/engines/wintermute/utils/path_util.cpp @@ -37,8 +37,9 @@ AnsiString PathUtil::unifySeparators(const AnsiString &path) { AnsiString newPath = path; for (uint32 i = 0; i < newPath.size(); i++) { - if (newPath[i] == '\\') + if (newPath[i] == '\\') { newPath.setChar('/', i); + } } return newPath; @@ -56,8 +57,9 @@ AnsiString PathUtil::combine(const AnsiString &path1, const AnsiString &path2) { AnsiString newPath1 = unifySeparators(path1); AnsiString newPath2 = unifySeparators(path2); - if (!StringUtil::endsWith(newPath1, "/", true) && !StringUtil::startsWith(newPath2, "/", true)) + if (!StringUtil::endsWith(newPath1, "/", true) && !StringUtil::startsWith(newPath2, "/", true)) { newPath1 += "/"; + } return newPath1 + newPath2; } @@ -79,10 +81,11 @@ AnsiString PathUtil::getFileName(const AnsiString &path) { //size_t pos = newPath.find_last_of(L'/'); TODO REMOVE. Common::String lastPart = Common::lastPathComponent(newPath, '/'); - if (lastPart[lastPart.size() - 1 ] != '/') + if (lastPart[lastPart.size() - 1 ] != '/') { return lastPart; - else + } else { return path; + } //if (pos == AnsiString::npos) return path; //else return newPath.substr(pos + 1); } @@ -183,8 +186,9 @@ AnsiString PathUtil::getUserDirectory() { if (error == noErr) { char buffer[MAX_PATH_LENGTH]; error = FSRefMakePath(&fileRef, (UInt8 *)buffer, sizeof(buffer)); - if (error == noErr) + if (error == noErr) { userDir = buffer; + } } #elif __IPHONEOS__ diff --git a/engines/wintermute/utils/string_util.cpp b/engines/wintermute/utils/string_util.cpp index 748016d9c4..f864a8480a 100644 --- a/engines/wintermute/utils/string_util.cpp +++ b/engines/wintermute/utils/string_util.cpp @@ -215,14 +215,15 @@ bool StringUtil::startsWith(const AnsiString &str, const AnsiString &pattern, bo if (ignoreCase) return CompareNoCase(startPart, pattern); else return (startPart == pattern);*/ - if (!ignoreCase) + if (!ignoreCase) { return str.hasPrefix(pattern); - else { + } else { size_t strLength = str.size(); size_t patternLength = pattern.size(); - if (strLength < patternLength || patternLength == 0) + if (strLength < patternLength || patternLength == 0) { return false; + } AnsiString startPart(str.c_str(), patternLength); uint32 likeness = startPart.compareToIgnoreCase(pattern.c_str()); @@ -248,8 +249,9 @@ bool StringUtil::endsWith(const AnsiString &str, const AnsiString &pattern, bool size_t strLength = str.size(); size_t patternLength = pattern.size(); - if (strLength < patternLength || patternLength == 0) + if (strLength < patternLength || patternLength == 0) { return false; + } Common::String endPart(str.c_str() + (strLength - patternLength), patternLength); uint32 likeness = str.compareToIgnoreCase(pattern.c_str()); @@ -259,8 +261,11 @@ bool StringUtil::endsWith(const AnsiString &str, const AnsiString &pattern, bool ////////////////////////////////////////////////////////////////////////// bool StringUtil::isUtf8BOM(const byte *Buffer, uint32 BufferSize) { - if (BufferSize > 3 && Buffer[0] == 0xEF && Buffer[1] == 0xBB && Buffer[2] == 0xBF) return true; - else return false; + if (BufferSize > 3 && Buffer[0] == 0xEF && Buffer[1] == 0xBB && Buffer[2] == 0xBF) { + return true; + } else { + return false; + } } ////////////////////////////////////////////////////////////////////////// @@ -269,10 +274,11 @@ int StringUtil::indexOf(const WideString &str, const WideString &toFind, size_t if (pos == str.npos) return -1; else return pos;*/ const char *index = strstr(str.c_str(), toFind.c_str()); - if (index == NULL) + if (index == NULL) { return -1; - else + } else { return index - str.c_str(); + } } diff --git a/engines/wintermute/utils/utils.cpp b/engines/wintermute/utils/utils.cpp index a4751ef11b..39bb1d7137 100644 --- a/engines/wintermute/utils/utils.cpp +++ b/engines/wintermute/utils/utils.cpp @@ -48,8 +48,12 @@ void BaseUtils::swap(int *a, int *b) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::normalizeAngle(float angle) { - while (angle > 360) angle -= 360; - while (angle < 0) angle += 360; + while (angle > 360) { + angle -= 360; + } + while (angle < 0) { + angle += 360; + } return angle; } @@ -81,7 +85,9 @@ void BaseUtils::debugMessage(const char *text) { char *BaseUtils::setString(char **string, const char *value) { delete[] *string; *string = new char[strlen(value) + 1]; - if (*string) strcpy(*string, value); + if (*string) { + strcpy(*string, value); + } return *string; } @@ -89,7 +95,9 @@ char *BaseUtils::setString(char **string, const char *value) { int BaseUtils::strNumEntries(const char *str, const char delim) { int numEntries = 1; for (uint32 i = 0; i < strlen(str); i++) { - if (str[i] == delim) numEntries++; + if (str[i] == delim) { + numEntries++; + } } return numEntries; } @@ -104,8 +112,11 @@ char *BaseUtils::strEntry(int entry, const char *str, const char delim) { for (uint32 i = 0; i <= strlen(str); i++) { if (numEntries == entry) { - if (!start) start = str + i; - else len++; + if (!start) { + start = str + i; + } else { + len++; + } } if (str[i] == delim || str[i] == '\0') { numEntries++; @@ -159,35 +170,46 @@ bool BaseUtils::matchesPattern(const char *pattern, const char *string) { return (stringc == 0); case '?': - if (stringc == 0) return false; + if (stringc == 0) { + return false; + } break; case '*': - if (!*pattern) return true; + if (!*pattern) { + return true; + } if (*pattern == '.') { char *dot; - if (pattern[1] == '*' && pattern[2] == 0) return true; + if (pattern[1] == '*' && pattern[2] == 0) { + return true; + } dot = (char *)strchr(string, '.'); - if (pattern[1] == 0) return (dot == NULL || dot[1] == 0); + if (pattern[1] == 0) { + return (dot == NULL || dot[1] == 0); + } if (dot != NULL) { string = dot; - if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) + if (strpbrk(pattern, "*?[") == NULL && strchr(string + 1, '.') == NULL) { return(scumm_stricmp(pattern + 1, string + 1) == 0); + } } } while (*string) - if (BaseUtils::matchesPattern(pattern, string++)) + if (BaseUtils::matchesPattern(pattern, string++)) { return true; + } return false; default: if (patternc != stringc) - if (patternc == '.' && stringc == 0) + if (patternc == '.' && stringc == 0) { return(BaseUtils::matchesPattern(pattern, string)); - else + } else { return false; + } break; } } @@ -222,19 +244,30 @@ void BaseUtils::RGBtoHSL(uint32 RGBColor, byte *outH, byte *outS, byte *outL) { } //Chromatic data... else { - if (L < 0.5f) S = delMax / (varMax + varMin); - else S = delMax / (2.0f - varMax - varMin); + if (L < 0.5f) { + S = delMax / (varMax + varMin); + } else { + S = delMax / (2.0f - varMax - varMin); + } float delR = (((varMax - varR) / 6.0f) + (delMax / 2.0f)) / delMax; float delG = (((varMax - varG) / 6.0f) + (delMax / 2.0f)) / delMax; float delB = (((varMax - varB) / 6.0f) + (delMax / 2.0f)) / delMax; - if (varR == varMax) H = delB - delG; - else if (varG == varMax) H = (1.0f / 3.0f) + delR - delB; - else if (varB == varMax) H = (2.0f / 3.0f) + delG - delR; + if (varR == varMax) { + H = delB - delG; + } else if (varG == varMax) { + H = (1.0f / 3.0f) + delR - delB; + } else if (varB == varMax) { + H = (2.0f / 3.0f) + delG - delR; + } - if (H < 0) H += 1; - if (H > 1) H -= 1; + if (H < 0) { + H += 1; + } + if (H > 1) { + H -= 1; + } } *outH = (byte)(H * 255); @@ -259,8 +292,11 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { } else { float var_1, var_2; - if (L < 0.5) var_2 = L * (1.0 + S); - else var_2 = (L + S) - (S * L); + if (L < 0.5) { + var_2 = L * (1.0 + S); + } else { + var_2 = (L + S) - (S * L); + } var_1 = 2.0f * L - var_2; @@ -274,11 +310,21 @@ uint32 BaseUtils::HSLtoRGB(byte InH, byte InS, byte InL) { ////////////////////////////////////////////////////////////////////////// float BaseUtils::Hue2RGB(float v1, float v2, float vH) { - if (vH < 0.0f) vH += 1.0f; - if (vH > 1.0f) vH -= 1.0f; - if ((6.0f * vH) < 1.0f) return (v1 + (v2 - v1) * 6.0f * vH); - if ((2.0f * vH) < 1.0f) return (v2); - if ((3.0f * vH) < 2.0f) return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + if (vH < 0.0f) { + vH += 1.0f; + } + if (vH > 1.0f) { + vH -= 1.0f; + } + if ((6.0f * vH) < 1.0f) { + return (v1 + (v2 - v1) * 6.0f * vH); + } + if ((2.0f * vH) < 1.0f) { + return (v2); + } + if ((3.0f * vH) < 2.0f) { + return (v1 + (v2 - v1) * ((2.0f / 3.0f) - vH) * 6.0f); + } return (v1); } diff --git a/engines/wintermute/video/video_player.cpp b/engines/wintermute/video/video_player.cpp index 464cbec7ff..7affd91013 100644 --- a/engines/wintermute/video/video_player.cpp +++ b/engines/wintermute/video/video_player.cpp @@ -92,28 +92,46 @@ VideoPlayer::~VideoPlayer() { ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::cleanup() { #if 0 - if (_sound) _sound->Stop(); - if (_videoPGF) AVIStreamGetFrameClose(_videoPGF); + if (_sound) { + _sound->Stop(); + } + if (_videoPGF) { + AVIStreamGetFrameClose(_videoPGF); + } _videoPGF = NULL; _playing = false; - if (_aviFile) AVIFileRelease(m_AviFile); + if (_aviFile) { + AVIFileRelease(m_AviFile); + } - if (_audioStream) AVIStreamRelease(m_AudioStream); - if (_videoStream) AVIStreamRelease(m_VideoStream); + if (_audioStream) { + AVIStreamRelease(m_AudioStream); + } + if (_videoStream) { + AVIStreamRelease(m_VideoStream); + } - if (_audioFormat) delete[](byte *)m_AudioFormat; - if (_videoFormat) delete[](byte *)m_VideoFormat; - if (_targetFormat) delete[](byte *)m_TargetFormat; + if (_audioFormat) { + delete[](byte *)m_AudioFormat; + } + if (_videoFormat) { + delete[](byte *)m_VideoFormat; + } + if (_targetFormat) { + delete[](byte *)m_TargetFormat; + } SAFE_DELETE(_sound); SAFE_DELETE(_vidRenderer); SAFE_DELETE_ARRAY(_filename); - for (int i = 0; i < _subtitles.getSize(); i++) delete _subtitles[i]; + for (int i = 0; i < _subtitles.getSize(); i++) { + delete _subtitles[i]; + } _subtitles.removeAll(); return SetDefaults(); @@ -144,10 +162,11 @@ bool VideoPlayer::initialize(const char *inFilename, const char *SubtitleFile) { _totalVideoTime = AVIStreamEndTime(_videoStream); // get audio stream - if (_gameRef->m_SoundMgr->_soundAvailable && AVIFileGetStream(_aviFile, &_audioStream, streamtypeAUDIO, 0) == 0) + if (_gameRef->m_SoundMgr->_soundAvailable && AVIFileGetStream(_aviFile, &_audioStream, streamtypeAUDIO, 0) == 0) { _soundAvailable = true; - else + } else { _soundAvailable = false; + } LONG Size; @@ -169,10 +188,11 @@ bool VideoPlayer::initialize(const char *inFilename, const char *SubtitleFile) { m_TargetFormat->bV4BitCount = 24; m_TargetFormat->bV4V4Compression = BI_RGB; - if (_gameRef->m_UseD3D) + if (_gameRef->m_UseD3D) { m_VidRenderer = new CVidRendererD3D(_gameRef); - else + } else { m_VidRenderer = new CVidRendererDD(_gameRef); + } if (!m_VidRenderer || DID_FAIL(m_VidRenderer->Initialize(m_VideoFormat, m_TargetFormat))) { _gameRef->LOG(0, "Error initializing video renderer for AVI file '%s'", filename); @@ -193,10 +213,14 @@ bool VideoPlayer::initialize(const char *inFilename, const char *SubtitleFile) { } } - if (_gameRef->_videoSubtitles) LoadSubtitles(inFilename, SubtitleFile); + if (_gameRef->_videoSubtitles) { + LoadSubtitles(inFilename, SubtitleFile); + } _filename = new char[strlen(filename) + 1]; - if (_filename) strcpy(_filename, filename); + if (_filename) { + strcpy(_filename, filename); + } #endif return STATUS_OK; } @@ -205,13 +229,17 @@ bool VideoPlayer::initialize(const char *inFilename, const char *SubtitleFile) { ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::update() { #if 0 - if (!m_Playing) return STATUS_OK; + if (!m_Playing) { + return STATUS_OK; + } bool res; if (_soundAvailable && m_Sound) { res = _sound->update(); - if (DID_FAIL(res)) return res; + if (DID_FAIL(res)) { + return res; + } } @@ -263,10 +291,17 @@ bool VideoPlayer::update() { // render frame LPBITMAPINFOHEADER FrameData = (LPBITMAPINFOHEADER)AVIStreamGetFrame(m_VideoPGF, sample); if (FrameData) { - if (_slowRendering) return _vidRenderer->ProcessFrameSlow(FrameData); - else return _vidRenderer->ProcessFrame(FrameData); - } else return STATUS_FAILED; - } else return STATUS_OK; + if (_slowRendering) { + return _vidRenderer->ProcessFrameSlow(FrameData); + } else { + return _vidRenderer->ProcessFrame(FrameData); + } + } else { + return STATUS_FAILED; + } + } else { + return STATUS_OK; + } #endif return 0; } @@ -275,11 +310,16 @@ bool VideoPlayer::update() { ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::display() { #if 0 - if (!m_Playing) return STATUS_OK; + if (!m_Playing) { + return STATUS_OK; + } bool res; - if (_vidRenderer) res = _vidRenderer->display(m_PlayPosX, m_PlayPosY, m_PlayZoom); - else res = STATUS_FAILED; + if (_vidRenderer) { + res = _vidRenderer->display(m_PlayPosX, m_PlayPosY, m_PlayZoom); + } else { + res = STATUS_FAILED; + } // display subtitle if (m_ShowSubtitle) { @@ -299,7 +339,9 @@ bool VideoPlayer::display() { ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::play(TVideoPlayback Type, int X, int Y, bool FreezeMusic) { #if 0 - if (!_videoStream || !_vidRenderer) return STATUS_FAILED; + if (!_videoStream || !_vidRenderer) { + return STATUS_FAILED; + } switch (Type) { case VID_PLAY_POS: @@ -339,7 +381,9 @@ bool VideoPlayer::play(TVideoPlayback Type, int X, int Y, bool FreezeMusic) { _gameRef->LOG(0, "Performance warning: non-optimal AVI format, using generic (i.e. slow) rendering routines (file '%s')", m_Filename); _slowRendering = true; } - } else _slowRendering = false; + } else { + _slowRendering = false; + } // HACK!!! _slowRendering = true; @@ -350,7 +394,9 @@ bool VideoPlayer::play(TVideoPlayback Type, int X, int Y, bool FreezeMusic) { _gameRef->Freeze(FreezeMusic); _playing = true; - if (_sound) _sound->Play(); + if (_sound) { + _sound->Play(); + } _startTime = timeGetTime(); #endif return STATUS_OK; @@ -360,7 +406,9 @@ bool VideoPlayer::play(TVideoPlayback Type, int X, int Y, bool FreezeMusic) { ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::stop() { #if 0 - if (!_playing) return STATUS_OK; + if (!_playing) { + return STATUS_OK; + } cleanup(); @@ -379,7 +427,9 @@ bool VideoPlayer::isPlaying() { ////////////////////////////////////////////////////////////////////////// bool VideoPlayer::loadSubtitles(const char *filename, const char *SubtitleFile) { #if 0 - if (!Filename) return STATUS_OK; + if (!Filename) { + return STATUS_OK; + } char NewFile[MAX_PATH_LENGTH]; char drive[_MAX_DRIVE]; @@ -395,7 +445,9 @@ bool VideoPlayer::loadSubtitles(const char *filename, const char *SubtitleFile) DWORD Size; BYTE *Buffer = _gameRef->m_FileManager->readWholeFile(NewFile, &Size, false); - if (Buffer == NULL) return STATUS_OK; // no subtitles + if (Buffer == NULL) { + return STATUS_OK; // no subtitles + } LONG Start, End; @@ -414,7 +466,9 @@ bool VideoPlayer::loadSubtitles(const char *filename, const char *SubtitleFile) TextLength = 0; LineLength = 0; - while (Pos + LineLength < Size && Buffer[Pos + LineLength] != '\n' && Buffer[Pos + LineLength] != '\0') LineLength++; + while (Pos + LineLength < Size && Buffer[Pos + LineLength] != '\n' && Buffer[Pos + LineLength] != '\0') { + LineLength++; + } int RealLength = LineLength - (Pos + LineLength >= Size ? 0 : 1); char *Text = new char[RealLength + 1]; @@ -427,15 +481,20 @@ bool VideoPlayer::loadSubtitles(const char *filename, const char *SubtitleFile) TokenStart = line + i + 1; TokenLength = 0; TokenPos++; - } else TokenLength++; + } else { + TokenLength++; + } } else if (line[i] == '}') { if (InToken) { InToken = false; char *Token = new char[TokenLength + 1]; strncpy(Token, TokenStart, TokenLength); Token[TokenLength] = '\0'; - if (TokenPos == 0) Start = atoi(Token); - else if (TokenPos == 1) End = atoi(Token); + if (TokenPos == 0) { + Start = atoi(Token); + } else if (TokenPos == 1) { + End = atoi(Token); + } delete[] Token; } else { @@ -447,14 +506,18 @@ bool VideoPlayer::loadSubtitles(const char *filename, const char *SubtitleFile) TokenLength++; } else { Text[TextLength] = line[i]; - if (Text[TextLength] == '|') Text[TextLength] = '\n'; + if (Text[TextLength] == '|') { + Text[TextLength] = '\n'; + } TextLength++; } } } Text[TextLength] = '\0'; - if (Start != -1 && TextLength > 0) _subtitles.add(new CVidSubtitle(_gameRef, Text, Start, End)); + if (Start != -1 && TextLength > 0) { + _subtitles.add(new CVidSubtitle(_gameRef, Text, Start, End)); + } delete[] Text; diff --git a/engines/wintermute/video/video_theora_player.cpp b/engines/wintermute/video/video_theora_player.cpp index 91703e40b7..07e2fc022d 100644 --- a/engines/wintermute/video/video_theora_player.cpp +++ b/engines/wintermute/video/video_theora_player.cpp @@ -138,7 +138,9 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: _filename = filename; _file = _gameRef->_fileManager->openFile(filename, true, false); - if (!_file) return STATUS_FAILED; + if (!_file) { + return STATUS_FAILED; + } //if (Filename != _filename) BaseUtils::setString(&_filename, filename); #if defined (USE_THEORADEC) @@ -148,8 +150,9 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: #endif _theoraDecoder->loadStream(_file); - if (!_theoraDecoder->isVideoLoaded()) + if (!_theoraDecoder->isVideoLoaded()) { return STATUS_FAILED; + } _state = THEORA_STATE_PAUSED; @@ -165,9 +168,13 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: cleanup(); _file = _gameRef->_fileManager->openFile(filename); - if (!_file) return STATUS_FAILED; + if (!_file) { + return STATUS_FAILED; + } - if (Filename != _filename) BaseUtils::setString(&_filename, filename); + if (filename != _filename) { + BaseUtils::setString(&_filename, filename); + } // start up Ogg stream synchronization layer ogg_sync_init(&m_OggSyncState); @@ -187,8 +194,10 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: ogg_packet TempOggPacket; bool IsDone = false; while (!IsDone) { - int BytesRead = BufferData(&m_OggSyncState); - if (BytesRead == 0) break; + int bytesRead = BufferData(&m_OggSyncState); + if (bytesRead == 0) { + break; + } while (ogg_sync_pageout(&m_OggSyncState, &m_OggPage) > 0) { ogg_stream_state OggStateTest; @@ -313,10 +322,11 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: // create texture if (m_TheoraStreams && !m_Texture) { - if (_gameRef->m_UseD3D) + if (_gameRef->m_UseD3D) { m_Texture = new BaseSurfaceD3D(_gameRef); - else + } else { m_Texture = new BaseSurfaceDD(_gameRef); + } if (!m_Texture || DID_FAIL(Res = m_Texture->Create(m_TheoraInfo.width, m_TheoraInfo.height))) { SAFE_DELETE(m_Texture); @@ -337,7 +347,9 @@ bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common: bool VideoTheoraPlayer::resetStream() { warning("VidTheoraPlayer::resetStream - stubbed"); #if 0 - if (_sound) _sound->Stop(); + if (_sound) { + _sound->Stop(); + } m_TimeOffset = 0.0f; Initialize(m_Filename); @@ -348,16 +360,20 @@ bool VideoTheoraPlayer::resetStream() { ////////////////////////////////////////////////////////////////////////// bool VideoTheoraPlayer::play(TVideoPlayback type, int x, int y, bool freezeGame, bool freezeMusic, bool looping, uint32 startTime, float forceZoom, int volume) { - if (forceZoom < 0.0f) + if (forceZoom < 0.0f) { forceZoom = 100.0f; - if (volume < 0) + } + if (volume < 0) { _volume = _gameRef->_soundMgr->getVolumePercent(Audio::Mixer::kSFXSoundType); - else _volume = volume; + } else { + _volume = volume; + } _freezeGame = freezeGame; - if (!_playbackStarted && _freezeGame) + if (!_playbackStarted && _freezeGame) { _gameRef->freeze(freezeMusic); + } _playbackStarted = false; float width, height; @@ -469,11 +485,17 @@ bool VideoTheoraPlayer::stop() { bool VideoTheoraPlayer::update() { _currentTime = _freezeGame ? _gameRef->_liveTimer : _gameRef->_timer; - if (!isPlaying()) return STATUS_OK; + if (!isPlaying()) { + return STATUS_OK; + } - if (_playbackStarted /*&& m_Sound && !m_Sound->IsPlaying()*/) return STATUS_OK; + if (_playbackStarted /*&& m_Sound && !m_Sound->IsPlaying()*/) { + return STATUS_OK; + } - if (_playbackStarted && !_freezeGame && _gameRef->_state == GAME_FROZEN) return STATUS_OK; + if (_playbackStarted && !_freezeGame && _gameRef->_state == GAME_FROZEN) { + return STATUS_OK; + } if (_theoraDecoder) { if (_theoraDecoder->endOfVideo() && _looping) { @@ -483,7 +505,9 @@ bool VideoTheoraPlayer::update() { warning("Finished movie"); _state = THEORA_STATE_FINISHED; _playbackStarted = false; - if (_freezeGame) _gameRef->unfreeze(); + if (_freezeGame) { + _gameRef->unfreeze(); + } } if (_state == THEORA_STATE_PLAYING) { if (_theoraDecoder->getTimeToNextFrame() == 0) { @@ -500,7 +524,9 @@ bool VideoTheoraPlayer::update() { // end playback if (!_looping) { _state = THEORA_STATE_FINISHED; - if (_freezeGame) _gameRef->unfreeze(); + if (_freezeGame) { + _gameRef->unfreeze(); + } return STATUS_OK; } else { resetStream(); @@ -615,7 +641,9 @@ uint32 VideoTheoraPlayer::getMovieFrame() { ////////////////////////////////////////////////////////////////////////// bool VideoTheoraPlayer::WriteVideo() { - if (!_texture) return STATUS_FAILED; + if (!_texture) { + return STATUS_FAILED; + } _texture->startPixelOp(); @@ -657,11 +685,18 @@ bool VideoTheoraPlayer::display(uint32 alpha) { if (_texture && _videoFrameReady) { BasePlatform::setRect(&rc, 0, 0, _texture->getWidth(), _texture->getHeight()); - if (_playZoom == 100.0f) res = _texture->displayTrans(_posX, _posY, rc, alpha); - else res = _texture->displayTransZoom(_posX, _posY, rc, _playZoom, _playZoom, alpha); - } else res = STATUS_FAILED; + if (_playZoom == 100.0f) { + res = _texture->displayTrans(_posX, _posY, rc, alpha); + } else { + res = _texture->displayTransZoom(_posX, _posY, rc, _playZoom, _playZoom, alpha); + } + } else { + res = STATUS_FAILED; + } #if 0 - if (m_Subtitler && _gameRef->m_VideoSubtitles) m_Subtitler->display(); + if (m_Subtitler && _gameRef->m_VideoSubtitles) { + m_Subtitler->display(); + } #endif return res; } @@ -699,8 +734,11 @@ bool VideoTheoraPlayer::setAlphaImage(const Common::String &filename) { ////////////////////////////////////////////////////////////////////////// byte VideoTheoraPlayer::getAlphaAt(int x, int y) { - if (_alphaImage) return _alphaImage->getAlphaAt(x, y); - else return 0xFF; + if (_alphaImage) { + return _alphaImage->getAlphaAt(x, y); + } else { + return 0xFF; + } } @@ -834,9 +872,13 @@ bool VideoTheoraPlayer::persist(BasePersistenceManager *persistMgr) { ////////////////////////////////////////////////////////////////////////// bool VideoTheoraPlayer::initializeSimple() { if (DID_SUCCEED(initialize(_filename))) { - if (_alphaFilename != "") setAlphaImage(_alphaFilename); + if (_alphaFilename != "") { + setAlphaImage(_alphaFilename); + } play(_playbackType, _posX, _posY, false, false, _looping, _savedPos, _playZoom); - } else _state = THEORA_STATE_FINISHED; + } else { + _state = THEORA_STATE_FINISHED; + } return STATUS_OK; } -- cgit v1.2.3