void Weather::print(){ Serial.print(pNoon()); Serial.print(" "); Serial.print(weatherType()); Serial.print(" "); Serial.print(lightning()); Serial.println(); }
void Thunderstorm::update(float ) { if (!running) return; if (time_to_thunder.check()) { thunder(); time_to_lightning.start(LIGHTNING_DELAY); } if (time_to_lightning.check()) { lightning(); time_to_thunder.start(interval); } }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // „Ƕ„Ç£„É≥„Éâ„Ƕ„ÅÆËÉåÊôØ„Çí°ó„Çä„ŧ„Å∂„Å? & Èö†Èù¢Âá¶ÁêÅEÇíÂèØËÉΩ„Å´„Åô„Çã glEnable(GL_DEPTH_TEST); // Èö†Èù¢Âá¶ÁêÅEñãÂß? glEnable(GL_NORMALIZE); glEnable(GL_LIGHTING); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glPushMatrix(); glTranslatef(0.0, 1.0, 0.0); polarview(); // „Éù„ÅE„É©„ɺ„Éì„É•„ɺ„Å∏„ÅÆ„Éì„É•„ɺ„ǧ„É≥„Ç∞§âÊèõ glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, light0); glPopMatrix(); shading(5); drawGround2D(); shading(6); glDisable(GL_LIGHTING); drawGrass(); glEnable(GL_LIGHTING); shading(5); drawPlant(); if (rainFlag == GL_TRUE) drawRain(); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); drawCloud(); if (thunderFlag == GL_TRUE && rainFlag == GL_TRUE) { if (lightningnum == 0 || lightningnum == 4) lightning(); lightningnum++; if (lightningnum == 5) { lightningnum = 0; thunderFlag = GL_FALSE; } if (rand() % 10 == 4) fallFlag = GL_TRUE; } else thunderFlag = GL_FALSE; glPopMatrix(); glutSwapBuffers(); }
void altar() { char line[DEFLEN]; int temp; char * p; stile(player->y, player->x, TL_GR_HL); /* Praying increases piety (hidden from the player); when the player has enough it will cause a beneficial effect. If the player chooses to loot the altar they will lose all piety. */ if (psel("YOU APPROACH THE ALTAR\n" "\n" "<- LOOT IT#PRAY ->") == 0) { stile(player->y - 2, player->x - 3, TL_VOID); stile(player->y - 2, player->x + 3, TL_VOID); stile(player->y - 3, player->x, TL_VOID); stile(player->y - 2, player->x - 1, TL_VOID); stile(player->y - 2, player->x, TL_VOID); stile(player->y - 2, player->x + 1, TL_VOID); draw_board(); give_gold("YOU LOOT THE ALTAR\n\n", 1 + rand() % ALTAR_LOOT_GOLD); game->piety -= ALTAR_LOOT_PENALTY + (rand() % ALTAR_LOOT_PENALTY); if (game->piety < -3000 && rand() % 3 == 0) { draw_board(); pwait("A MIGHTY VOICE BOOMS OUT:\n" "\"THOU HATH DEFILED MY ALTAR\n" " TOO MANY TIMES, MORTAL!\""); draw_board(); if (rand() % 2 == 0) { pwait("YOU ARE STRUCK BY LIGHTNING!"); draw_board(); lightning(player->y - view_y, player->x - view_x); player->hp -= 25 + rand() % 46; if (player->hp <= 0) game_over("YOU DIED FOR YOUR SINS", false); draw_bars(); } else { pwait("YOU FEEL WEAK!"); player->strength = MAX(1, player->strength - 1 - rand() % 3); player->speed = MAX(1, player->speed - 1 - rand() % 3); } } else if (game->piety < -2000 && rand() % 3 == 0) { tremor(5); draw_board(); pwait("YOU HEAR A RUMBLE IN THE DISTANCE"); } else if (game->piety < -1000 && rand() % 3 == 0) { draw_board(); pwait("YOU GET AN UNEASY FEELING"); } } else { stile(player->y - 3, player->x - 1, TL_YDOT); stile(player->y - 3, player->x, TL_YDOT); stile(player->y - 3, player->x + 1, TL_YDOT); // Update board with lit candles draw_board(); strcpy(line, "YOU PRAY AT THE ALTAR"); if (game->piety < 0) game->piety += 500; game->piety += ALTAR_PRAYER_PIETY + (rand() % ALTAR_PRAYER_PIETY); if (game->piety < 0) { strcat(line, "\n\nYOU ARE LEFT WITH A DISAPPROVING\n" "SENSATION OF EMPTINESS"); pwait(line); } else if (rand() % MAX(1, game->piety) > ALTAR_HEAL_PIETY) { game->piety -= ALTAR_HEAL_PIETY; strcat(line, "\n\n YOU ARE EMBRACED BY\n" " A WARM FEELING! "); pwait(line); draw_board(); refill_hp(ALTAR_EMBRACE_HEAL); } else if (rand() % MAX(1, game->piety) > ALTAR_WISDOM_PIETY) { game->piety -= ALTAR_WISDOM_PIETY; temp = (1 + rand() % game->current_floor) * 100; temp += MAX(0, game->current_floor - 7) * 200; // Find end of string for (p = line; *p != '\0'; p++) { } sprintf(p, "\n\nYOU HAVE BEEN ENLIGHTENED!\n\n" "YOU GET %d EXP", temp); pwait(line); draw_board(); give_exp(temp); } else { pwait(line); } } return; }
/* * Update the weather. */ void weather_update( void ) { char buf[MAX_STRING_LENGTH]; DESCRIPTOR_DATA *d; buf[0] = '\0'; switch ( ++time_info.hour ) { case 5: weather_info.sunlight = SUN_LIGHT; strcat( buf, "The {yday{x has begun.\n\r" ); break; case 6: weather_info.sunlight = SUN_RISE; strcat( buf, "The {Ysun{x rises in the east.\n\r" ); break; case 19: weather_info.sunlight = SUN_SET; strcat( buf, "The {Ysun{x slowly disappears in the west.\n\r" ); break; case 20: weather_info.sunlight = SUN_DARK; strcat( buf, "The {Dnight{x has begun.\n\r" ); break; case 24: time_info.hour = 0; time_info.day++; break; } if ( time_info.day >= 35 ) { time_info.day = 0; time_info.month++; } if ( time_info.month >= 12 ) { time_info.month = 0; time_info.year++; } /* * Weather change. */ switch ( weather_info.sky ) { default: weather_info.sky = SKY_CLOUDLESS; break; case SKY_CLOUDLESS: if ((number_chance(10))&& (time_info.hour <= 6) ) { weather_info.sky = SKY_FOGGY; } else if (number_chance(15)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(30)) { weather_info.sky = SKY_RAINING; } else if (number_chance(45)) { weather_info.sky = SKY_CLOUDLESS; } break; case SKY_CLOUDY: if (number_chance(15)) { weather_info.sky = SKY_SNOWING; } else if (number_chance(15)) { weather_info.sky = SKY_HAILSTORM; } else if (number_chance(15)) { weather_info.sky = SKY_THUNDERSTORM; } else if (number_chance(15)) { weather_info.sky = SKY_ICESTORM; } else if (number_chance(15)) { weather_info.sky = SKY_CLOUDLESS; } else if (number_chance(25)) { weather_info.sky = SKY_CLOUDY; } case SKY_RAINING: if (number_chance(15)) { weather_info.sky = SKY_LIGHTNING; lightning ( ); } else if (number_chance(10)) { weather_info.sky = SKY_HAILSTORM; hail(); } else if (number_chance(10)) { weather_info.sky = SKY_THUNDERSTORM; } else if (number_chance(10)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(55)) { weather_info.sky = SKY_RAINING; } break; case SKY_SNOWING: if (number_chance(15)) { weather_info.sky = SKY_BLIZZARD; } else if (number_chance(15)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(15)) { weather_info.sky = SKY_RAINING; } else if (number_chance(55)) { weather_info.sky = SKY_SNOWING; } break; case SKY_LIGHTNING: if (number_chance(15)) { weather_info.sky = SKY_THUNDERSTORM; } else if (number_chance(15)) { weather_info.sky = SKY_RAINING; } else if (number_chance(15)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(15)) { weather_info.sky = SKY_HAILSTORM; } else if (number_chance(40)) { weather_info.sky = SKY_LIGHTNING; } break; case SKY_FOGGY: if (number_chance(45)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(55)) { fog(); weather_info.sky = SKY_FOGGY; break; } case SKY_THUNDERSTORM: if (number_chance(15)) { weather_info.sky = SKY_RAINING; } else if (number_chance(15)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(15)) { weather_info.sky = SKY_LIGHTNING; } else if (number_chance(15)) { weather_info.sky = SKY_HAILSTORM; hail (); } else if (number_chance(40)) { weather_info.sky = SKY_THUNDERSTORM; } break; case SKY_HAILSTORM: if (number_chance(15)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(30)) { weather_info.sky = SKY_RAINING; } else if (number_chance(55)) { weather_info.sky = SKY_HAILSTORM; hail(); } break; case SKY_ICESTORM: if (number_chance(15)) { weather_info.sky = SKY_CLOUDY; } else if (number_chance(15)) { weather_info.sky = SKY_BLIZZARD; } else if (number_chance(15)) { weather_info.sky = SKY_SNOWING; } else if (number_chance(55)) { ice(); weather_info.sky = SKY_ICESTORM; } break; case SKY_BLIZZARD: if (number_chance(15)) { weather_info.sky = SKY_SNOWING; } else if (number_chance(15)) { blizzard(); weather_info.sky = SKY_ICESTORM; ice(); } else if (number_chance(15)) { blizzard(); weather_info.sky = SKY_CLOUDY; } else if (number_chance(55)) { blizzard(); weather_info.sky = SKY_BLIZZARD; } break; } if ( buf[0] != '\0' ) { for ( d = descriptor_list; d != NULL; d = d->next ) { if ( d->connected == CON_PLAYING && IS_OUTDOORS(d->character) && IS_AWAKE(d->character) ) send_to_char( buf, d->character ); } } return; }
void WeatherManager::HandleWeatherEvent(psWeatherGameEvent* event) { { CS::Threading::MutexScopedLock lock(eventsMutex); events.Delete(event); // Delete this from our "db" } // See if we want to ignore this event for(size_t i = 0; i < ignored.GetSize(); i++) { if(event == ignored[i]) { ignored.DeleteIndex(i); return; } } switch(event->type) { case psWeatherMessage::SNOW: case psWeatherMessage::RAIN: { event->si->current_rain_drops = event->value; Notify4(LOG_WEATHER,"New %s in sector '%s': %d",event->type == psWeatherMessage::SNOW ? "snow" : "rain", event->si->name.GetData(),event->value); psWeatherMessage::NetWeatherInfo info; info.has_downfall = true; info.downfall_is_snow = (event->type == psWeatherMessage::SNOW); info.has_fog = true; info.has_lightning = false; info.downfall_drops = event->value; // Save current fog and calculate new. if(event->value) { // Only save the fog 'history' once. After that we just override. if(!event->si->densitySaved) { event->si->fog_density_old = event->si->fog_density; event->si->densitySaved = true; } // Set fog colour if there's not already fog. if(!event->si->fog_density) { event->si->r = 255; event->si->g = 255; event->si->b = 255; } if(info.downfall_drops < 8000) { // Calculate fog to be linear in range 0 to 200 event->si->fog_density = (int)(200.0f*(info.downfall_drops-1000.0f)/8000.0f); } else { event->si->fog_density = 200; } } else if(event->si->fog_density) { // Restore fog, if the fog wasn't turned off. event->si->fog_density = event->si->fog_density_old; event->si->densitySaved = false; } info.fog_density = event->si->fog_density; info.r = event->si->r; info.g = event->si->g; info.b = event->si->b; info.sector = event->sector; if(event->fade) { info.downfall_fade = event->fade; info.fog_fade = event->fade; } else { if(event->value) { info.downfall_fade = event->si->GetRandomWeatherFadeIn((unsigned int)event->type); info.fog_fade = info.downfall_fade; } else { info.downfall_fade = event->si->GetRandomWeatherFadeOut((unsigned int)event->type); info.fog_fade = info.downfall_fade; } } Notify4(LOG_WEATHER,"Drops: %d Density: %d Sector: %s\n", info.downfall_drops,info.fog_density,info.sector.GetDataSafe()); psWeatherMessage rain(0,info); if(rain.valid) psserver->GetEventManager()->Broadcast(rain.msg,NetBase::BC_EVERYONE); else { Bug1("Could not create valid psWeatherMessage (rain) for broadcast.\n"); } // Make sure we don't have any other events in this sector that will disturb // Simple case is when event types are equal. In addition we have to test // for the mutal exclusive case where we are changing from snow to rain or // rain to snow. { CS::Threading::MutexScopedLock lock(eventsMutex); for(size_t i = 0; i < events.GetSize(); i++) { psWeatherGameEvent* evt = events[i]; if(evt->sector == event->sector && (evt->type == event->type || ((evt->type == psWeatherMessage::RAIN || evt->type == psWeatherMessage::SNOW) && (event->type == psWeatherMessage::RAIN || event->type == psWeatherMessage::SNOW)))) { ignored.Push(evt); // Ignore when the eventmanager handles the event events.DeleteIndex(i); i--; Notify4(LOG_WEATHER,"Removed disturbing event for sector '%s' (%d,%d)", evt->sector.GetData(),evt->value,evt->duration); } } } if(event->value) // Queue event to turn off rain/snow. { if(event->type != psWeatherMessage::SNOW) event->si->is_raining = true; else event->si->is_snowing = true; if(event->si->GetWeatherEnabled((unsigned int) psWeatherMessage::LIGHTNING) && event->value > 2000 && event->si->is_raining) { // Queue lightning during rain storm here first QueueNextEvent(event->si->GetRandomWeatherGap((unsigned int) psWeatherMessage::LIGHTNING), psWeatherMessage::LIGHTNING, 0, 0, 0, event->si->name, event->si, event->clientnum); } // Queue event to stop rain/snow int duration; if(event->duration != -1) { if(event->duration) { duration = event->duration; } else { duration = event->si->GetRandomWeatherDuration((unsigned int) event->type); } QueueNextEvent(duration, event->type, 0, 0, event->fade, event->si->name, event->si); } } else // Stop rain/snow. { if(event->type== psWeatherMessage::SNOW) event->si->is_snowing = false; else event->si->is_raining = false; // Queue event to turn on again later if enabled StartWeather(event->si); } break; } case psWeatherMessage::FOG: { // Update sector weather info event->si->fog_density = event->value; event->si->r = event->cr; event->si->g = event->cg; event->si->b = event->cb; // Update the clients psWeatherMessage::NetWeatherInfo info; info.has_downfall = false; info.downfall_is_snow = false; info.has_fog = true; info.has_lightning = false; info.sector = event->si->name; info.fog_density = event->si->fog_density; info.r = event->cr; info.g = event->cg; info.b = event->cb; info.downfall_drops = 0; info.downfall_fade = 0; Notify3(LOG_WEATHER,"New Fog in sector '%s': %d", event->si->name.GetData(), event->value); // Save the fade in so we can reverse it when fading out. if(event->fade) { event->si->fogFade = event->fade; } else { // We're removing fog, so removed the 'saved' flag. event->si->densitySaved = false; } info.fog_fade = event->si->fogFade; psWeatherMessage fog(0,info); if(fog.valid) psserver->GetEventManager()->Broadcast(fog.msg,NetBase::BC_EVERYONE); else { Bug1("Could not create valid psWeatherMessage (fog) for broadcast.\n"); } if(event->value) // Queue event to turn off fog. { // Queue event to stop rain/snow int duration; if(event->duration != -1) { if(event->duration) { duration = event->duration; } else { duration = event->si->GetRandomWeatherDuration((unsigned int) event->type); } QueueNextEvent(duration, event->type, 0, 0, event->si->GetRandomWeatherFadeOut((unsigned int)psWeatherMessage::FOG), event->si->name, event->si); } } else // Stop fog. { // Queue event to turn on again later if enabled StartWeather(event->si, psWeatherMessage::FOG); } break; } case psWeatherMessage::LIGHTNING: { if(event->si->is_raining) { Notify2(LOG_WEATHER,"Lightning in sector '%s'",event->sector.GetData()); psWeatherMessage::NetWeatherInfo info; info.has_downfall = false; info.downfall_is_snow = false; info.has_fog = false; info.has_lightning = true; info.sector = event->sector; info.fog_fade = info.downfall_fade = 0; info.r = info.g = info.b = 0; info.downfall_drops = info.fog_density = 0; psWeatherMessage lightning(0,info, event->clientnum); if(lightning.valid) { psserver->GetEventManager()->Broadcast(lightning.msg); } else { Bug1("Could not create valid psWeatherMessage (lightning) for broadcast.\n"); } if(event->si->is_raining && event->si->GetWeatherEnabled((unsigned int) psWeatherMessage::LIGHTNING)) { QueueNextEvent(event->si->GetRandomWeatherGap((unsigned int) psWeatherMessage::LIGHTNING), psWeatherMessage::LIGHTNING, 0, 0, 0, event->si->name, event->si, event->clientnum); } } break; } case psWeatherMessage::DAYNIGHT: { QueueNextEvent(GAME_MINUTE_IN_TICKS, psWeatherMessage::DAYNIGHT, 0, 0, 0, NULL, NULL); gameTimeMinute++; if(gameTimeMinute >= 60) { gameTimeMinute = 0; gameTimeHour++; if(gameTimeHour >= 24) { gameTimeHour = 0; gameTimeDay++; if(gameTimeDay >= monthLengths[gameTimeMonth-1]+1) { gameTimeDay = 1; gameTimeMonth++; if(gameTimeMonth >= MONTH_COUNT+1) { gameTimeMonth = 1; gameTimeYear++; } } } // Only save and broadcast every game hour. SaveGameTime(); BroadcastGameTime(); } else { // Super clients should get the time every minute BroadcastGameTimeSuperclients(); } break; } default: { break; } } }