Command *Command::opItemLookDirection(Script *script, const ResourceReference &itemRef, int32 direction, bool suspend) { FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>(); Current *current = StarkGlobal->getCurrent(); Camera *camera = current->getCamera(); Math::Angle cameraAngle = camera->getHorizontalAngle(); Math::Angle targetAngle = direction + cameraAngle; Math::Matrix3 rot; rot.buildAroundZ(-targetAngle); Math::Vector3d directionVector(1.0, 0.0, 0.0); rot.transformVector(&directionVector); Turn *movement = new Turn(item); movement->setTargetDirection(directionVector); movement->start(); item->setMovement(movement); if (suspend) { script->suspend(item); item->setMovementSuspendedScript(script); return this; // Stay on the same command while suspended } else { return nextCommand(); } }
void GameInterface::setAprilRunning() { Current *current = StarkGlobal->getCurrent(); Resources::ModelItem *april = current->getInteractive(); Movement *movement = april->getMovement(); Walk *walk = dynamic_cast<Walk *>(movement); walk->setRunning(); }
void ResourceProvider::shutdown() { _stateProvider->clear(); // Flush the locations list for (CurrentList::const_iterator it = _locations.begin(); it != _locations.end(); it++) { Current *location = *it; _archiveLoader->returnRoot(_archiveLoader->buildArchiveName(location->getLevel(), location->getLocation())); _archiveLoader->returnRoot(_archiveLoader->buildArchiveName(location->getLevel())); delete location; } _locations.clear(); // Return the global resources if (_global->getLevel()) { _archiveLoader->returnRoot(_archiveLoader->buildArchiveName(_global->getLevel())); _global->setLevel(nullptr); } if (_global->getRoot()) { _archiveLoader->returnRoot("x.xarc"); _global->setRoot(nullptr); } _global->setCurrent(nullptr); _global->setInventory(nullptr); _global->setApril(nullptr); _archiveLoader->unloadUnused(); }
Resources::Level *ResourceProvider::getLevel(uint16 level) const { Current *current = findLevel(level); if (current) { return current->getLevel(); } return nullptr; }
Resources::Location *ResourceProvider::getLocation(uint16 level, uint16 location) const { Current *current = findLocation(level, location); if (current) { return current->getLocation(); } return nullptr; }
Command *Command::opItemPlaceDirection(const ResourceReference &itemRef, int32 direction) { FloorPositionedItem *item = itemRef.resolve<FloorPositionedItem>(); Current *current = StarkGlobal->getCurrent(); Camera *camera = current->getCamera(); Math::Angle cameraAngle = camera->getHorizontalAngle(); item->setDirection(direction + cameraAngle); return nextCommand(); }
Command *Command::opRumbleScene(Script *script, int32 rumbleDuration, int32 pause) { Current *current = StarkGlobal->getCurrent(); Location *location = current->getLocation(); location->startRumble(rumbleDuration); if (pause) { script->pause(rumbleDuration); return this; // Stay on this command while the script is suspended } else { return nextCommand(); } }
ItemVisual *Speech::getCharacterItem() const { Current *current = StarkGlobal->getCurrent(); if (!current) { return nullptr; } Location *location = current->getLocation(); if (!location) { return nullptr; } return location->getCharacterItem(_character); }
bool Console::Cmd_Location(int argc, const char **argv) { if (argc != 1) { debugPrintf("Display the current location.\n"); debugPrintf("Usage :\n"); debugPrintf("location\n"); return true; } Current *current = StarkGlobal->getCurrent(); debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex()); return true; }
void Wire::sendCurrent(double speed, int charges, Chip *source, Chip *target, CurrentCallback cb){ bool reverse = false; if (source == this->target) { reverse = true; } /* unsigned int charges = (source->chargeCount/2);*/ source->chargeCount -= charges; Current* c = new Current(this,1,speed,reverse,cb,charges); c->changeOwner(source->getOwner()); c->game = game; currents.push_back(c); }
void ResourceProvider::commitActiveLocationsState() { // Save active location states for (CurrentList::const_iterator it = _locations.begin(); it != _locations.end(); it++) { _stateProvider->saveLocationState((*it)->getLevel(), (*it)->getLocation()); _stateProvider->saveLevelState((*it)->getLevel()); } _stateProvider->saveLevelState(_global->getLevel()); // Save the current location "extended" state, to be able to restore them to the exact same state. Current *location = _global->getCurrent(); _stateProvider->saveCurrentLocationState(location->getLevel(), location->getLocation()); _stateProvider->saveCurrentLevelState(location->getLevel()); _stateProvider->saveGlobalState(_global->getLevel()); }
Command *Command::opFadeScene(Script *script, bool fadeOut, int32 fadeDuration, bool pause) { Current *current = StarkGlobal->getCurrent(); Location *location = current->getLocation(); if (fadeOut) { location->fadeOutInit(fadeDuration); } else { location->fadeInInit(fadeDuration); } if (pause) { script->pause(fadeDuration); return this; // Stay on this command while the script is suspended } else { return nextCommand(); } }
Command *Command::opFullMotionVideoPlay(Script *script, const ResourceReference &movieRef, int32 unknown) { // Stop skipping frames StarkGlobal->setNormalSpeed(); // Characters don't need to continue their previous action after the FMV ends Current *current = StarkGlobal->getCurrent(); Location *location = current->getLocation(); location->resetAnimationBlending(); FMV *movie = movieRef.resolve<FMV>(); movie->requestPlayback(); // Unconditional suspension script->suspend(movie); return this; // Stay on the same command while suspended }
void GameInterface::skipCurrentSpeeches() { Current *current = StarkGlobal->getCurrent(); if (!current) { return; // No current location, nothing to do } // Get all speeches Common::Array<Resources::Speech *> speeches; speeches.push_back(StarkGlobal->getLevel()->listChildrenRecursive<Resources::Speech>()); speeches.push_back(current->getLevel()->listChildrenRecursive<Resources::Speech>()); speeches.push_back(current->getLocation()->listChildrenRecursive<Resources::Speech>()); // Stop them for (uint i = 0; i < speeches.size(); i++) { Resources::Speech *speech = speeches[i]; if (speech->isPlaying()) { speech->stop(); } } }
Math::Vector3d StringPullingPath::computeWalkTarget(const Math::Vector3d &fromPosition) { Current *current = StarkGlobal->getCurrent(); Resources::Floor *floor = current->getFloor(); // HACK: Sometimes the character gets stuck because of rounding errors // If we detect the character is stuck on a step, just make it go to the next one. // TODO: Improve the string pulling code so that the targets can also be points between two steps. if (fromPosition.getDistanceTo(_steps[_targetStep]) < 1.0 && _targetStep < _steps.size() - 1) { _targetStep++; } for (uint i = _targetStep + 1; i < _steps.size(); i++) { Math::Line3d testSegment = Math::Line3d(fromPosition, _steps[i]); if (!floor->isSegmentInside(testSegment)) { break; } _targetStep = i; } return _steps[_targetStep]; }
void ResourceProvider::setAprilInitialPosition() { Current *current = _global->getCurrent(); Resources::ModelItem *april = current->getInteractive(); if (!april) { return; // No character } // Set the initial position for April if (!_nextPositionBookmarkReference.empty()) { Resources::Bookmark *position = _nextPositionBookmarkReference.resolve<Resources::Bookmark>(); april->placeOnBookmark(position); Resources::Camera *camera = current->getCamera(); Math::Angle cameraAngle = camera->getHorizontalAngle(); april->setDirection(_nextDirection + cameraAngle); } else if (april->getFloorFaceIndex() <= 0) { // No target location provided, place April on the first floor face april->placeDefaultPosition(); } _nextPositionBookmarkReference = ResourceReference(); _nextDirection = 0; }
bool GameInterface::isAprilWalking() const { Current *current = StarkGlobal->getCurrent(); if (!current) { return false; } Resources::ModelItem *april = current->getInteractive(); if (!april) { return false; } Movement *movement = april->getMovement(); if (!movement) { return false; } Walk *walk = dynamic_cast<Walk *>(movement); if (!walk) { return false; } return !walk->hasEnded(); }
void ResourceProvider::purgeOldLocations() { while (_locations.size() > 2) { Current *location = _locations.front(); _stateProvider->saveLocationState(location->getLevel(), location->getLocation()); _stateProvider->saveLevelState(location->getLevel()); _archiveLoader->returnRoot(_archiveLoader->buildArchiveName(location->getLevel(), location->getLocation())); _archiveLoader->returnRoot(_archiveLoader->buildArchiveName(location->getLevel())); delete location; _locations.pop_front(); } _archiveLoader->unloadUnused(); }
void Consolidate::action() const { current.consolidate(journal); queue.add(new Consolidate(timeMod(var.sampleFrequency, 0))); }
static type apply(const Current& current, const Next& next) { return type(current.get_head(), chain_type::apply(current.get_tail(), next)); }
void Sockconn::logon(int fd, const char * msg) { // Process logon. Set device number in map con[]. // 2.10 handles unit logon where controllernum is 0.0, 2.1 or similar. char typeStr[10]; enum DeviceType type; int pid, device, unit, numread, major, minor; unit = 0; numread = sscanf(msg, "logon %9s %d.%d %d %d.%d", typeStr, &major, &minor, &pid, &device, &unit); if (numread != 5 && numread != 6) { fprintf(stderr, "Logon: only got %d fields not 5 or 6 from '%s'\n", numread, msg); return; } if (device < 0 || device >= MAXDEVICES) { cerr << "Socks.login: invalid device number " << device << " in " << msg << endl; return; } type = noDevice; // ADD CONTROLLER if (strncmp(typeStr, "steca", 5) == 0) type = steca_t; else if (strncmp(typeStr, "victron", 7) == 0) type = victron_t; else if (strncmp(typeStr, "turbine", 7) == 0) type = turbine_t; else if (strncmp(typeStr, "fronius", 7) == 0) type = fronius_t; else if (strncmp(typeStr, "davis", 5) == 0) type = davis_t; else if (strncmp(typeStr, "pulse", 5) == 0) type = pulse_t; else if (strncmp(typeStr, "rico", 4) == 0) type = rico_t; else if (strncmp(typeStr, "generic", 7) == 0) type = generic_t; else if (strncmp(typeStr, "owl", 3) == 0) type = owl_t; else if (strncmp(typeStr, "soladin", 7) == 0) type = soladin_t; else if (strncmp(typeStr, "sevenseg", 8) == 0) type = sevenseg_t; else if (strncmp(typeStr, "meter", 5) == 0) type = meter_t; else if (strncmp(typeStr, "resol", 5) == 0) type = resol_t; else if (strncmp(typeStr, "sma", 3) == 0) type = sma_t; else if (strncmp(typeStr, "inverter", 8) == 0) type = inverter_t; else if (strncmp(typeStr, "thermal", 7) == 0) type = thermal_t; else if (strncmp(typeStr, "sensor", 6) == 0) type = sensor_t; else fprintf(stderr, "ERROR logon name %s not recognised", typeStr); DEBUG fprintf(stderr, "Logon: Device %d.%d (%d.%d) %s on FD %d, type %d\n", device, unit, major, minor, typeStr, fd, type); // sockconn[device].type = type; ostringstream error; // If the config is Generic, permit the logon to be different and set the conf[] appropriately if (type != conf.getType(device)) { if (conf.getType(device) == generic_t) { conf[device].type = type; // Doesn't bounds or sanity check unit index. // Units cannot have different types. current.setDevice(device, unit, type); } else { error << "event WARN logon: mismatch. Logon " << deviceStr[type] << " (" << type << ") Config " << deviceStr[conf.getType(device)] << " (" << conf.getType(device) << ")"; journal.add(new Message(error.str())); } } if (conf[device].units < unit + 1) { error << "event WARN logon: Device " << device << " (" << deviceStr[type] << ") Unit " << unit << " Only " << conf[device].units << " configured"; journal.add(new Message(error.str())); } fd2contr[fd] = device; fd2unit[fd] = unit; // Usually 0. if (unit == 0) contr2fd[device] = fd; conf[device].major = major; conf[device].minor = minor; conf[device].pid = pid; }
void ResourceProvider::requestLocationChange(uint16 level, uint16 location) { Current *currentLocation = new Current(); _locations.push_back(currentLocation); // Retrieve the level archive name Resources::Root *root = _global->getRoot(); Resources::Level *rootLevelResource = root->findChildWithIndex<Resources::Level>(level); Common::String levelArchive = _archiveLoader->buildArchiveName(rootLevelResource); // Load the archive, and get the resource sub-tree root bool newlyLoaded = _archiveLoader->load(levelArchive); currentLocation->setLevel(_archiveLoader->useRoot<Resources::Level>(levelArchive)); // If we just loaded a resource tree, restore its state if (newlyLoaded) { currentLocation->getLevel()->onAllLoaded(); _stateProvider->restoreLevelState(currentLocation->getLevel()); } // Retrieve the location archive name Resources::Level *levelResource = currentLocation->getLevel(); Resources::Location *levelLocationResource = levelResource->findChildWithIndex<Resources::Location>(location); Common::String locationArchive = _archiveLoader->buildArchiveName(levelResource, levelLocationResource); // Load the archive, and get the resource sub-tree root newlyLoaded = _archiveLoader->load(locationArchive); currentLocation->setLocation(_archiveLoader->useRoot<Resources::Location>(locationArchive)); if (currentLocation->getLocation()->has3DLayer()) { Resources::Layer3D *layer = currentLocation->getLocation()->findChildWithSubtype<Resources::Layer3D>(Resources::Layer::kLayer3D); currentLocation->setFloor(layer->findChild<Resources::Floor>()); currentLocation->setCamera(layer->findChild<Resources::Camera>()); } else { currentLocation->setFloor(nullptr); currentLocation->setCamera(nullptr); } // If we just loaded a resource tree, restore its state if (newlyLoaded) { currentLocation->getLocation()->onAllLoaded(); _stateProvider->restoreLocationState(currentLocation->getLevel(), currentLocation->getLocation()); } _locationChangeRequest = true; }
~AutoRebind(void) { _obj.Bind(_target); }
void ResourceProvider::performLocationChange() { Current *current = _locations.back(); Current *previous = _global->getCurrent(); bool levelChanged = !previous || previous->getLevel() != current->getLevel(); // Exit the previous location if (previous) { // Trigger location change scripts if (levelChanged) { runLocationChangeScripts(previous->getLevel(), Resources::Script::kCallModeExitLocation); } runLocationChangeScripts(previous->getLocation(), Resources::Script::kCallModeExitLocation); // Resources lifecycle update previous->getLocation()->onExitLocation(); previous->getLevel()->onExitLocation(); _global->getLevel()->onExitLocation(); } // Clear all pointers to location objects in the UI instances StarkUserInterface->clearLocationDependentState(); // Set the new current location _global->setCurrent(current); // Resources lifecycle update _global->getLevel()->onEnterLocation(); current->getLevel()->onEnterLocation(); current->getLocation()->onEnterLocation(); if (current->getLocation()->has3DLayer()) { // Fetch the scene item for April current->setInteractive(Resources::Object::cast<Resources::ModelItem>(_global->getApril()->getSceneInstance())); } if (_restoreCurrentState) { _stateProvider->restoreGlobalState(_global->getLevel()); _stateProvider->restoreCurrentLevelState(current->getLevel()); _stateProvider->restoreCurrentLocationState(current->getLevel(), current->getLocation()); _restoreCurrentState = false; } else { setAprilInitialPosition(); setScrollInitialPosition(); // Trigger location change scripts if (levelChanged) { runLocationChangeScripts(current->getLevel(), Resources::Script::kCallModeEnterLocation); } runLocationChangeScripts(current->getLocation(), Resources::Script::kCallModeEnterLocation); } purgeOldLocations(); _locationChangeRequest = false; }
int main(int argc, char *argv[]) { PolycodeView *view = new PolycodeView("Current"); Current *app = new Current(view); while(app->Update()) {} return 0; }
Command *Command::opIsLocation2D() { Current *current = StarkGlobal->getCurrent(); Location *location = current->getLocation(); return nextCommandIf(!location->has3DLayer()); }
void ResourceProvider::setScrollInitialPosition() { Current *current = _global->getCurrent(); Resources::Location *location = current->getLocation(); location->scrollToCharacterImmediate(); }