const MapFailedReason& Map::getFailReason (const Player* player) const { if (player->isCrashed()) { switch (player->getCrashReason()) { case CRASH_NPC_WALKING: return MapFailedReasons::FAILED_NPC_WALKING; case CRASH_NPC_MAMMUT: return MapFailedReasons::FAILED_NPC_MAMMUT; case CRASH_NPC_FISH: return MapFailedReasons::FAILED_NPC_FISH; case CRASH_NPC_FLYING: return MapFailedReasons::FAILED_NPC_FLYING; case CRASH_MAP_FAILED: return MapFailedReasons::FAILED_SIDESCROLL; default: return MapFailedReasons::FAILED_HITPOINTS; } } if (getWaterHeight() <= 0) { return MapFailedReasons::FAILED_WATER_HEIGHT; } return MapFailedReasons::FAILED_NO_MORE_PLAYERS; }
void peanoclaw::native::scenarios::CalmOcean::initializePatch(peanoclaw::Patch& patch) { const tarch::la::Vector<DIMENSIONS, double> patchPosition = patch.getPosition(); const tarch::la::Vector<DIMENSIONS, double> meshWidth = patch.getSubcellSize(); peanoclaw::grid::SubgridAccessor& accessor = patch.getAccessor(); tarch::la::Vector<DIMENSIONS, int> subcellIndex; for (int yi = 0; yi < patch.getSubdivisionFactor()(1); yi++) { for (int xi = 0; xi < patch.getSubdivisionFactor()(0); xi++) { subcellIndex(0) = xi; subcellIndex(1) = yi; double X = patchPosition(0) + xi*meshWidth(0); double Y = patchPosition(1) + yi*meshWidth(1); double q0 = getWaterHeight(X, Y); double q1 = 0.0; double q2 = 0.0; accessor.setValueUNew(subcellIndex, 0, q0); accessor.setValueUNew(subcellIndex, 1, q1); accessor.setValueUNew(subcellIndex, 2, q2); accessor.setParameterWithGhostlayer(subcellIndex, 0, 0.0); assertion2(tarch::la::equals(accessor.getValueUNew(subcellIndex, 0), q0, 1e-5), accessor.getValueUNew(subcellIndex, 0), q0); assertion2(tarch::la::equals(accessor.getValueUNew(subcellIndex, 1), q1, 1e-5), accessor.getValueUNew(subcellIndex, 1), q1); assertion2(tarch::la::equals(accessor.getValueUNew(subcellIndex, 2), q2, 1e-5), accessor.getValueUNew(subcellIndex, 2), q2); } } }
void Map::handleFishNPC () { if (!_activateFishNPC) return; const float waterBodyY = getWaterHeight(); // no fish if water is too low if (waterBodyY <= 0.5f) return; if (_spawnFishNPCTime > _time) return; const float gap = 2.0f; if (_fishNPC == nullptr) { if (_players.empty()) return; const int index = rand() % _players.size(); const Player* player = _players[index]; const b2Vec2& pos = player->getPos(); const float mapHeight = static_cast<float>(getMapHeight()); float y = std::min(waterBodyY, std::max(mapHeight, mapHeight - 0.5f)); if (y < 0.f) { return; } float x; if (pos.x > getMapWidth() / 2.0) x = -gap; else x = getMapWidth() + gap; const b2Vec2 npcSpawnPos(x, y); _fishNPC = createFishNPC(npcSpawnPos); } else { const b2Vec2 &pos = _fishNPC->getPos(); const float x = pos.x; const float y = pos.y; if (x < -gap || y < 0 || x > getMapWidth() + gap || y > getMapHeight()) { _fishNPC->setRemove(); _spawnFishNPCTime = _time + 2000 + rand() % SPAWN_FISH_NPC_DELAY; _fishNPC = nullptr; } } }
void Map::handleFlyingNPC () { if (!_activateflyingNPC) return; if (_spawnFlyingNPCTime > _time) return; const float gap = 2.0f; if (_flyingNPC == nullptr) { if (_players.empty()) return; const int index = rand() % _players.size(); const Player* player = _players[index]; const b2Vec2& pos = player->getPos(); const float waterBodyY = getWaterHeight(); float y = pos.y; if (y >= waterBodyY) { y = waterBodyY - 1.0f; } if (y < 0.f) { return; } float x; if (pos.x > getMapWidth() / 2.0) x = -gap; else x = getMapWidth() + gap; const b2Vec2 npcSpawnPos(x, y); _flyingNPC = createFlyingNPC(npcSpawnPos); } else { const b2Vec2 &pos = _flyingNPC->getPos(); const float x = pos.x; const float y = pos.y; if (x < -gap || y < 0 || x > getMapWidth() + gap || y > getMapHeight()) { _flyingNPC->setRemove(); _spawnFlyingNPCTime = _time + 2000 + rand() % SPAWN_FLYING_NPC_DELAY; _flyingNPC = nullptr; } } }
bool Map::isFailed () const { if (getWaterHeight() <= 0) { debug(LOG_MAP, "failed because water hit the top"); return true; } if (_players.empty()) return true; for (PlayerListConstIter i = _players.begin(); i != _players.end(); ++i) { const Player* player = *i; if (!player->isCrashed()) { return false; } } debug(LOG_MAP, String::format("failed because all %i players crashed", (int)_players.size())); return true; }
BOOL LLSurface::generateWaterTexture(const F32 x, const F32 y, const F32 width, const F32 height) { if (!getWaterTexture()) { return FALSE; } S32 tex_width = mWaterTexturep->getWidth(); S32 tex_height = mWaterTexturep->getHeight(); S32 tex_comps = mWaterTexturep->getComponents(); S32 tex_stride = tex_width * tex_comps; LLPointer<LLImageRaw> raw = new LLImageRaw(tex_width, tex_height, tex_comps); U8 *rawp = raw->getData(); F32 scale = 256.f * getMetersPerGrid() / (F32)tex_width; F32 scale_inv = 1.f / scale; S32 x_begin, y_begin, x_end, y_end; x_begin = llround(x * scale_inv); y_begin = llround(y * scale_inv); x_end = llround((x + width) * scale_inv); y_end = llround((y + width) * scale_inv); if (x_end > tex_width) { x_end = tex_width; } if (y_end > tex_width) { y_end = tex_width; } LLVector3d origin_global = from_region_handle(getRegion()->getHandle()); // OK, for now, just have the composition value equal the height at the point. LLVector3 location; LLColor4U coloru; const F32 WATER_HEIGHT = getWaterHeight(); S32 i, j, offset; for (j = y_begin; j < y_end; j++) { for (i = x_begin; i < x_end; i++) { //F32 nv[2]; //nv[0] = i/256.f; //nv[1] = j/256.f; // const S32 modulation = noise2(nv)*40; offset = j*tex_stride + i*tex_comps; location.mV[VX] = i*scale; location.mV[VY] = j*scale; // Sample multiple points const F32 height = resolveHeightRegion(location); if (height > WATER_HEIGHT) { // Above water... coloru = MAX_WATER_COLOR; coloru.mV[3] = ABOVE_WATERLINE_ALPHA; *(rawp + offset++) = coloru.mV[0]; *(rawp + offset++) = coloru.mV[1]; *(rawp + offset++) = coloru.mV[2]; *(rawp + offset++) = coloru.mV[3]; } else { // Want non-linear curve for transparency gradient coloru = MAX_WATER_COLOR; const F32 frac = 1.f - 2.f/(2.f - (height - WATER_HEIGHT)); S32 alpha = 64 + llround((255-64)*frac); alpha = llmin(llround((F32)MAX_WATER_COLOR.mV[3]), alpha); alpha = llmax(64, alpha); coloru.mV[3] = alpha; *(rawp + offset++) = coloru.mV[0]; *(rawp + offset++) = coloru.mV[1]; *(rawp + offset++) = coloru.mV[2]; *(rawp + offset++) = coloru.mV[3]; } } } if (!mWaterTexturep->hasGLTexture()) { mWaterTexturep->createGLTexture(0, raw); } mWaterTexturep->setSubImage(raw, x_begin, y_begin, x_end - x_begin, y_end - y_begin); return TRUE; }
float peanoclaw::native::scenarios::CalmOcean::waterHeightAtRest() { return getWaterHeight(0, 0); }