[ScryMUD] SVN Commit Info r926 - trunk/mud/grrmud/server
scrymud at wanfear.com
scrymud at wanfear.com
Fri Jun 8 11:52:36 PDT 2007
Author: gingon
Date: 2007-06-08 11:52:35 -0700 (Fri, 08 Jun 2007)
New Revision: 926
Added:
trunk/mud/grrmud/server/weather.cc
trunk/mud/grrmud/server/weather.h
Modified:
trunk/mud/grrmud/server/Makefile
trunk/mud/grrmud/server/command5.cc
trunk/mud/grrmud/server/command5.h
trunk/mud/grrmud/server/commands.cc
trunk/mud/grrmud/server/const.cc
trunk/mud/grrmud/server/const.h
trunk/mud/grrmud/server/critter.cc
trunk/mud/grrmud/server/critter.h
trunk/mud/grrmud/server/gen_cmds.spec
trunk/mud/grrmud/server/grrmud.cc
trunk/mud/grrmud/server/misc.cc
trunk/mud/grrmud/server/misc.h
trunk/mud/grrmud/server/misc2.cc
trunk/mud/grrmud/server/misc2.h
trunk/mud/grrmud/server/object.cc
trunk/mud/grrmud/server/object.h
trunk/mud/grrmud/server/room.cc
trunk/mud/grrmud/server/room.h
Log:
Support for weather added. includes 13 weather types, 8 temperatures, 5 wind speeds and 9 climate types! Chance of stuff happening under certain weather conditions. Uses roomflags 38 for setting weather on, and flags 39-46 for setting climates.special thanks to Ed and Loki for spending hours pouring over strange code with me with this.
Modified: trunk/mud/grrmud/server/Makefile
===================================================================
--- trunk/mud/grrmud/server/Makefile 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/Makefile 2007-06-08 18:52:35 UTC (rev 926)
@@ -22,7 +22,7 @@
script.o SkillSpell.o zone.o rm_parse.o rm_cmds.o obj_parse.o \
obj_cmds.o BuildInfo.o BugEntry.o MudStats.o clients.o ServerConfig.o \
mapper.o regex.o protocol_handler.o telnet_handler.o hegemon_handler.o \
-pfile_maint.o
+pfile_maint.o weather.o
grrmud_TARG = grrmud
Modified: trunk/mud/grrmud/server/command5.cc
===================================================================
--- trunk/mud/grrmud/server/command5.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/command5.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -50,6 +50,7 @@
#include "regex.h"
#include "telnet_handler.h"
#include "hegemon_handler.h"
+#include "weather.h"
int test(critter& pc) {
String buf;
@@ -3484,3 +3485,69 @@
}
+int changeweather(critter& pc){
+
+ if(pc.pc && pc.pc->imm_data){
+ weather.update();
+ return 1;
+ }
+ else pc.show("Eh?");
+ return -1;
+}
+
+int setweather(const String* climate_str, const String* weather_str, critter& pc){
+
+ if(pc.pc && pc.pc->imm_data){
+ int c =0,w = 0;
+ if(climate_str->Strlen() && weather_str->Strlen()){
+ while(c<MAX_CLIMATES){
+ if(!strcasecmp(*climate_str,climate_strings[c])){
+ break;
+ }
+ ++c;
+ }
+ if(c >=MAX_CLIMATES){
+ pc.show("error: unknown climate type.\n");
+ return -1;
+ }
+ while(w<MAX_WEATHER){
+ if(!strcasecmp(*weather_str,weather_strings[w])){
+ break;
+ }
+ ++w;
+ }
+ if(w >= MAX_WEATHER){
+ pc.show("error: unknown weather type.\n");
+ return -1;
+ }
+ weather.changeWeather((ClimateType)c,(WeatherType)w);
+ }
+ else pc.show("You must specify a climate type and weather type\n");
+ return -11;
+ }
+ else {pc.show("Eh?");
+ return -1;}
+ return 1;
+}
+
+int weatherreport(critter& pc){
+
+ if(pc.pc && pc.pc->imm_data){
+
+ String buf(100);
+
+ int i=0;
+ while(i< MAX_CLIMATES){
+ Sprintf(buf, "Climate: %s Weather: %s Wind: %s,Temperature: %s\n",
+ climate_strings[i], weather_strings[weather.climates[i].weather],
+ wind_strings[weather.climates[i].wind],
+ temperature_strings[weather.climates[i].temperature]);
+
+ ++i;
+ pc.show(buf);
+ }
+ return 1;
+ }
+ else pc.show("Eh?");
+ return -1;
+}
Modified: trunk/mud/grrmud/server/command5.h
===================================================================
--- trunk/mud/grrmud/server/command5.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/command5.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -157,6 +157,10 @@
void client_command(const String* vict, critter& pc);
int set_veh_croom(int vhcl, int rm, critter& pc);
+
+int weatherreport(critter& pc);
+int changeweather(critter& pc);
+int setweather(const String* climate_str, const String* weather_str, critter& pc);
#endif
Modified: trunk/mud/grrmud/server/commands.cc
===================================================================
--- trunk/mud/grrmud/server/commands.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/commands.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -735,6 +735,7 @@
else
show("\n", pc);
}//else
+ pc.showWeather(rm);
if (pc.shouldDoAutoExits()) { //if autoexit set
auto_exit(pc);
}//if
Modified: trunk/mud/grrmud/server/const.cc
===================================================================
--- trunk/mud/grrmud/server/const.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/const.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -28,7 +28,9 @@
#include "critter.h"
#include "room.h"
#include "object.h"
+#include "weather.h"
+Weather weather;// weather manager
/** All the words and phrases that one deems useless to the
* cause of humane communication goes here.
@@ -339,7 +341,7 @@
"!imm",//1
"!god",//2
"is_perm_dark",//3
- "weather",//4
+ "sunlight",//4
"!ranged_comm",//5
"!mag_exit",//6
"is_haven", //7
@@ -372,7 +374,17 @@
"!foreign_mob_wander",//34
"has_proc_script",//35
"coliseum",//36
- "is_vehicle"//37
+ "is_vehicle",//37
+ "is_climate_temperate",//38
+ "is_climate_savanah",//39
+ "is_climate_mountain",//40
+ "is_climate_snowymountain",//41
+ "is_climate_sandydesert",//42
+ "is_climate_dirtdesert",//43
+ "is_climate_swamp",//44
+ "is_climate_tropical",//45
+ "is_climate_arctic",//46
+ "has_weather" //47
};
const BitfieldNames ROOM_FLAGS_NAMES(sizeof(r_names)/sizeof(const char*),
r_names, "Room Flags:");
Modified: trunk/mud/grrmud/server/const.h
===================================================================
--- trunk/mud/grrmud/server/const.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/const.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -37,6 +37,7 @@
#include <LogStream.h>
#include <PtrArray.h>
#include "ServerConfig.h"
+#include "weather.h"
enum proc_types {
PROCTYPE_GIVE,
@@ -343,42 +344,54 @@
};
enum room_flags {
- ROOMFLAG_NO_RESTRICTIONS,
- ROOMFLAG_NO_IMM,
- ROOMFLAG_NO_GOD,
- ROOMFLAG_IS_PERM_DARK,
- ROOMFLAG_WEATHER,
- ROOMFLAG_NO_SHOUT,
- ROOMFLAG_NO_MAGICAL_EXIT,
- ROOMFLAG_IS_HAVEN,
- ROOMFLAG_NO_PK,
- ROOMFLAG_NO_MAGIC,
- ROOMFLAG_NO_MOB,
- ROOMFLAG_NO_POTIONS,
- ROOMFLAG_NO_STAFFS,
- ROOMFLAG_NO_MORTALS,
- ROOMFLAG_NORMALLY_DARK,
- ROOMFLAG_SHALLOW_WATER,
- ROOMFLAG_DEEP_WATER,
- ROOMFLAG_SWAMP,
- ROOMFLAG_NEED_FLY,
- ROOMFLAG_NEED_BOAT,
- ROOMFLAG_NEED_CLIMB,
- ROOMFLAG_IS_ZLOCKED,
- ROOMFLAG_IS_TOTAL_LOADED,
- ROOMFLAG_IS_USED,
- ROOMFLAG_NO_MAGICAL_ENTRY,
- ROOMFLAG_NO_VEHICLES,
- ROOMFLAG_CRAMPED,
- ROOMFLAG_NO_RANGED_ATTACK,
- ROOMFLAG_NEED_DIVE,
- ROOMFLAG_USED_IN_TRACK,
- ROOMFLAG_CAN_CAMP,
- ROOMFLAG_NOT_COMPLETE,
- ROOMFLAG_HAS_KEYWORDS,
- ROOMFLAG_NO_WANDERING_MOBS,
- ROOMFLAG_NO_FOREIGN_WANDERING_MOBS,
- ROOMFLAG_HAS_PROC_SCRIPT
+ ROOMFLAG_NO_RESTRICTIONS, //0
+ ROOMFLAG_NO_IMM, //1
+ ROOMFLAG_NO_GOD, //2
+ ROOMFLAG_IS_PERM_DARK, //3
+ ROOMFLAG_SUNLIGHT, //4
+ ROOMFLAG_NO_SHOUT, //5
+ ROOMFLAG_NO_MAGICAL_EXIT, //6
+ ROOMFLAG_IS_HAVEN, //7
+ ROOMFLAG_NO_PK, //8
+ ROOMFLAG_NO_MAGIC, //9
+ ROOMFLAG_NO_MOB, //10
+ ROOMFLAG_NO_POTIONS, //11
+ ROOMFLAG_NO_STAFFS, //12
+ ROOMFLAG_NO_MORTALS, //13
+ ROOMFLAG_NORMALLY_DARK, //14
+ ROOMFLAG_SHALLOW_WATER, //15
+ ROOMFLAG_DEEP_WATER, //16
+ ROOMFLAG_SWAMP, //17
+ ROOMFLAG_NEED_FLY, //18
+ ROOMFLAG_NEED_BOAT, //19
+ ROOMFLAG_NEED_CLIMB, //20
+ ROOMFLAG_IS_ZLOCKED, //21
+ ROOMFLAG_IS_TOTAL_LOADED, //22
+ ROOMFLAG_IS_USED, //23
+ ROOMFLAG_NO_MAGICAL_ENTRY, //24
+ ROOMFLAG_NO_VEHICLES, //25
+ ROOMFLAG_CRAMPED, //26
+ ROOMFLAG_NO_RANGED_ATTACK, //27
+ ROOMFLAG_NEED_DIVE, //28
+ ROOMFLAG_USED_IN_TRACK, //29
+ ROOMFLAG_CAN_CAMP, //30
+ ROOMFLAG_NOT_COMPLETE, //31
+ ROOMFLAG_HAS_KEYWORDS, //32
+ ROOMFLAG_NO_WANDERING_MOBS, //33
+ ROOMFLAG_NO_FOREIGN_WANDERING_MOBS, //34
+ ROOMFLAG_HAS_PROC_SCRIPT, //35
+ ROOMFLAG_COLISEUM, //36
+ ROOMFLAG_IS_VEHICLE, //37
+ ROOMFLAG_CLIMATE_TEMPERATE,//38
+ ROOMFLAG_CLIMATE_SAVANAH,//39
+ ROOMFLAG_CLIMATE_MOUNTAIN,//40
+ ROOMFLAG_CLIMATE_SNOWYMOUNTAIN,//41
+ ROOMFLAG_CLIMATE_SANDYDESERT,//42
+ ROOMFLAG_CLIMATE_DIRTDESERT,//43
+ ROOMFLAG_CLIMATE_SWAMP,//44
+ ROOMFLAG_CLIMATE_TROPICAL,//45
+ ROOMFLAG_CLIMATE_ARCTIC,//46
+ ROOMFLAG_HAS_WEATHER //47
};
enum vehicle_flags {
@@ -1711,4 +1724,6 @@
extern const char* seasons[];
+extern Weather weather;
+
#endif
Modified: trunk/mud/grrmud/server/critter.cc
===================================================================
--- trunk/mud/grrmud/server/critter.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/critter.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -44,6 +44,7 @@
#include "clients.h"
#include "telnet_handler.h"
#include "hegemon_handler.h"
+#include "weather.h"
const char* PcPositionStrings[] = {"stand", "sit", "rest", "sleep", "meditate",
"stun", "dead", "prone"};
@@ -4329,11 +4330,11 @@
MOV = i;
}
-void critter::show(const char* msg, hilite_type hl_type) {
+void critter::show(const char* msg, hilite_type hl_type) const {
::show(msg, *this, hl_type);
}
-void critter::show(CSentryE which_string, hilite_type hl_type) {
+void critter::show(CSentryE which_string, hilite_type hl_type) const {
show(CSHandler::getString(which_string, getLanguageChoice()), hl_type);
}
@@ -5067,84 +5068,84 @@
return &UNKNOWN;
}
-String* critter::getSayColor() {
+String* critter::getSayColor() const {
if (pc) {
return &(pc->say_str);
}
return &NULL_STRING;
}
-String* critter::getYellColor() {
+String* critter::getYellColor() const {
if (pc) {
return &(pc->yell_str);
}
return &NULL_STRING;
}
-String* critter::getTellColor() {
+String* critter::getTellColor() const {
if (pc) {
return &(pc->tell_str);
}
return &NULL_STRING;
}
-String* critter::getGossipColor() {
+String* critter::getGossipColor() const {
if (pc) {
return &(pc->gos_str);
}
return &NULL_STRING;
}
-String* critter::getDescColor() {
+String* critter::getDescColor() const {
if (pc) {
return &(pc->desc_str);
}
return &NULL_STRING;
}
-String* critter::getObjListColor() {
+String* critter::getObjListColor() const {
if (pc) {
return &(pc->obj_list_str);
}
return &NULL_STRING;
}
-String* critter::getMobListColor() {
+String* critter::getMobListColor() const {
if (pc) {
return &(pc->mob_list_str);
}
return &NULL_STRING;
}
-String* critter::getDefaultColor() { //for foreground
+String* critter::getDefaultColor() const { //for foreground
if (pc) {
return &(pc->dflt_str);
}
return &NULL_STRING;
}
-String* critter::getBackGroundColor() {
+String* critter::getBackGroundColor() const {
if (pc) {
return &(pc->bk_str);
}
return &NULL_STRING;
}
-String* critter::getBattleColor() {
+String* critter::getBattleColor() const {
if (pc) {
return &(pc->battle_str);
}
return &NULL_STRING;
}
-String* critter::getRoomColor() {
+String* critter::getRoomColor() const {
if (pc) {
return &(pc->room_str);
}
return &NULL_STRING;
}
-int critter::isUsingColor() {
+int critter::isUsingColor() const {
return pc && pc->pc_data_flags.get(26);
}
@@ -5974,3 +5975,59 @@
return ret_val;
}//critter::combatBonusVal()
+
+void critter::showWeather(room &rm) const {
+ String buf(200);
+ WeatherType rmweather;
+ WindType rmwind;
+ TemperatureType rmtemp;
+ if((pc || isPossessed()) && rm.hasWeather()){
+ rmweather = rm.getWeather();
+ rmwind = rm.getWind();
+ rmtemp = rm.getTemperature();
+ // if(rmwind = wndNONE) return;
+ switch(rmweather){
+ case wNONE:
+ return;
+ case thunderstorm:
+ case sandstorm:
+ case hailstorm:
+ case blizzard:
+ Sprintf(buf,"It is %s and there is a %s with %s.\n",
+ temperature_strings[rmtemp],
+ weather_strings[rmweather],wind_strings[rmwind]);
+ break;
+ default:
+ Sprintf(buf,"It is %s and %s with %s.\n",
+ temperature_strings[rmtemp],
+ weather_strings[rmweather],wind_strings[rmwind]);
+ }
+ show(buf);
+ }
+}
+
+bool critter::canSee(critter& mob){
+ if(detect(getSeeBit(),mob.getVisBit())){
+ return true;
+ }
+ return false;
+}
+bool critter::canSee(int vis_bit){
+ if(detect(getSeeBit(), vis_bit)){
+ return true;
+ }
+ return false;
+}
+bool critter::canSee(object& obj){
+ if(detect(getSeeBit(), obj.getVisBit())){
+ return true;
+ }
+ return false;
+}
+
+bool critter::canSee(door& dr){
+ if(detect(getSeeBit(), dr.getVisBit())){
+ return true;
+ }
+ return false;
+}
Modified: trunk/mud/grrmud/server/critter.h
===================================================================
--- trunk/mud/grrmud/server/critter.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/critter.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -41,6 +41,7 @@
#include "lang_strings.h"
#include "battle.h"
#include "protocol_handler.h"
+#include "weather.h"
///******************** temp crit data *****************************///
@@ -964,7 +965,7 @@
int isUsingClient() const ;
bool setClient(int which);
int whichClient();
- int isUsingColor();
+ int isUsingColor() const;
int isBrief();
int shouldSeeInventory();
int shouldShowVnums();
@@ -1000,17 +1001,17 @@
int getBenevolence() const;
int isSentinel() const;
- String* getSayColor();
- String* getYellColor();
- String* getTellColor();
- String* getGossipColor();
- String* getDescColor();
- String* getObjListColor();
- String* getMobListColor();
- String* getDefaultColor(); //for foreground
- String* getBackGroundColor();
- String* getBattleColor();
- String* getRoomColor();
+ String* getSayColor() const;
+ String* getYellColor() const;
+ String* getTellColor() const;
+ String* getGossipColor() const;
+ String* getDescColor() const;
+ String* getObjListColor() const;
+ String* getMobListColor() const;
+ String* getDefaultColor() const; //for foreground
+ String* getBackGroundColor() const;
+ String* getBattleColor() const;
+ String* getRoomColor() const;
int isNamed(const String& str) const ;
int isGagged();
@@ -1110,8 +1111,8 @@
void releasePageBreak() { if (pc) PC_FLAGS.turn_off(23); }
int isInPageBreak() const { return (pc && PC_FLAGS.get(23)); }
- void show(const char* msg, hilite_type hl_type = HL_DEF);
- void show(CSentryE, hilite_type hl_type = HL_DEF); //Pick language of choice, if available.
+ void show(const char* msg, hilite_type hl_type = HL_DEF) const;
+ void show(CSentryE, hilite_type hl_type = HL_DEF) const; //Pick language of choice, if available.
object* loseInv(object* obj); //returns the object removed. (or NULL)
void loseObjectFromGame(object* obj);
@@ -1162,6 +1163,14 @@
int takeDamage(int adamage, int type, critter &agg);
int takeDamage(int damage, int type);
float combatBonusVal(bool is_aggressor);
+
+ void showWeather(room &rm) const;
+
+ bool canSee(critter& mob);
+ bool canSee(int vis_bit);
+ bool canSee(object& obj);
+ bool canSee(door& dr);
+
};//class critter
Modified: trunk/mud/grrmud/server/gen_cmds.spec
===================================================================
--- trunk/mud/grrmud/server/gen_cmds.spec 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/gen_cmds.spec 2007-06-08 18:52:35 UTC (rev 926)
@@ -227,6 +227,8 @@
# IMM Commands - C
chance ~
return (chance( i, j, k));
+changeweather ~
+changeweather(pc);
ch_ddesc ~
return ch_ddesc(i, pc);
ch_kdesc ~
@@ -850,6 +852,8 @@
return set_veh_croom(i, j, pc);
set_veh_stop ~
return set_veh_stop(i, j, &(cooked_strs[1]), pc);
+setweather ~
+setweather(&(cooked_strs[1]), &(cooked_strs[2]), pc);
set_zflag ~
return set_zflag(i, &(cooked_strs[1]), pc);
show_zones ~
@@ -1017,6 +1021,8 @@
withdraw ~
return withdraw(i, cooked_strs[1], j, cooked_strs[2], pc);
# IMM Commands - W
+weatherreport ~
+weatherreport(pc);
wc *channels ~
NOP
wizchat *channels ~
Modified: trunk/mud/grrmud/server/grrmud.cc
===================================================================
--- trunk/mud/grrmud/server/grrmud.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/grrmud.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -399,7 +399,7 @@
void sig_term_handler(int signo) {
//reestablish signal handler
if ((signo != SIGSEGV) && (signo != SIGBUS) && (signo != SIGIOT)) {
- cerr << "Got signal: " << signo << " NOT setting to default handler." << endl;
+ /cerr << "Got signal: " << signo << " NOT setting to default handler." << endl;
signal(signo, (&sig_term_handler));
}
else {
Modified: trunk/mud/grrmud/server/misc.cc
===================================================================
--- trunk/mud/grrmud/server/misc.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/misc.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -344,7 +344,7 @@
config.year++;
config.day = 1;
}//if
-
+ weather.update();
config.writeDynamic("dynamic.cfg");
}//do_tick
@@ -466,7 +466,7 @@
//that never regen. I'll be watching the effects of this change closely and
//will most likely adjust the algorithms based on what I discover.
void do_regeneration_pcs() {
- float adj = 1.0, posn_mod, align_mod = 1.0;
+ float adj = 1.0, posn_mod, align_mod = 1.0, env_mod = 1.0;
Cell<critter*> crit_cell;
pc_list.head(crit_cell);
critter* crit_ptr;
@@ -475,6 +475,10 @@
while ((crit_ptr = crit_cell.next())) {
+ if(crit_ptr->getCurRoom()->getWeather()!= wNONE){
+ env_mod = weather_regen_mods[crit_ptr->getCurRoom()->getWeather()] *
+ temperature_regen_mods[crit_ptr->getCurRoom()->getTemperature()];
+ }
//no regen if we're fighting
if ( crit_ptr->isFighting() ) {
continue;
@@ -506,7 +510,7 @@
crit_ptr->HP += (int)((((((float)(crit_ptr->CON) + 5.0) / 15.0) *
(((float)(crit_ptr->HP_MAX)) / 9.0) *
posn_mod * (((float)(crit_ptr->HP_REGEN)) / 100.0)
- * adj + 10.0)/6.0)+1.0);
+ * adj + 10.0)/6.0)*env_mod+1.0);
}
// if we are affected by remove karma we get no mana
@@ -525,7 +529,7 @@
(((float)(crit_ptr->MA_MAX)) / 7.0) *
(((float)(crit_ptr->MA_REGEN)) / 100.0) *
align_mod *
- adj + 4.0)/6.0)+1.0);
+ adj + 4.0)/6.0)*env_mod+1.0);
}
/* Lose 5 mov points if you're idleing in deep water without a boat or
@@ -539,7 +543,7 @@
tmp_mov = (int)(((((((float)(crit_ptr->DEX)) + 5.0) / 16.0) *
posn_mod * adj *
(((float)(crit_ptr->MV_MAX)) / 3.0) *
- (((float)(crit_ptr->MV_REGEN)) / 100.0) + 3.0)/6.0)+1.0);
+ (((float)(crit_ptr->MV_REGEN)) / 100.0) + 3.0)/6.0)*env_mod+1.0);
crit_ptr->MOV += tmp_mov;
}
@@ -1843,7 +1847,7 @@
}//gain spell_affected_by
-void show(const char* message, critter& pc, hilite_type hl_type) {
+void show(const char* message, const critter& pc, hilite_type hl_type) {
//log(message);
String *output;
@@ -1868,7 +1872,11 @@
snooper->show(buf2);
}//if snoop
- pc.setDoPrompt(TRUE);
+ //In theory we'd probably better to make critter::setDoPrompt() appear
+ //const and declare the prompt flag to be Mutable.
+ critter& t_pc = const_cast<critter&>(pc);
+ t_pc.setDoPrompt(true);
+
if (!message)
return;
@@ -2907,7 +2915,7 @@
return false;
}
-String *colorize(const char *message, critter &pc, hilite_type hl_type)
+String *colorize(const char *message, const critter &pc, hilite_type hl_type)
{
static String output;
Modified: trunk/mud/grrmud/server/misc.h
===================================================================
--- trunk/mud/grrmud/server/misc.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/misc.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -98,7 +98,7 @@
int detect(int see_bit, int vis_bit); //does bit comparison
-void show(const char* message, critter& pc, hilite_type hl_type = HL_DEF);
+void show(const char* message, const critter& pc, hilite_type hl_type = HL_DEF);
void show_all_but_2(critter& A, critter& B, const char* message,
room& rm, hilite_type hl_type = HL_DEF);
void show_all(const char* msg, const room& rm);
@@ -192,7 +192,7 @@
int mia_mobs(int i_th, critter &pc);
int mia_objects(int i_th, critter &pc);
-String *colorize(const char *input, critter &pc, hilite_type hl_type);
+String *colorize(const char *input, const critter &pc, hilite_type hl_type);
#endif
Modified: trunk/mud/grrmud/server/misc2.cc
===================================================================
--- trunk/mud/grrmud/server/misc2.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/misc2.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -45,8 +45,8 @@
#include <signal.h>
#include <LogStream.h>
#include "SkillSpell.h"
+#include <string.h>
-
// Attempt to load the player-run shop owner of that number.
// Returns a newly allocated SMOB, or NULL if a problem is
// encountered.
@@ -2213,33 +2213,48 @@
}
+/*template <typename T> void DistProbMatrix<T>::add(T value, unsigned int weight){
+ size += weight;
+ matrix.reserve(size);
+ for(unsigned int i = 0; i < weight; i++){
+ matrix.push_back(value);
+ }
-void DistProbMatrix::add(int value, unsigned int weight){
- int* tmp = NULL;
- unsigned int tmp_size = 0;
- unsigned int i = 0;
-
- tmp_size = weight + size;
- tmp = new int[tmp_size];
-
- if(size != 0){
- while(i < size){
- tmp[i] = matrix[i];
- ++i;
+// cout << "Beging DistProbMatrix::add matrix = " << matrix << " size:" << size << " weight:" << weight << " value:" << value << endl;
+ if(matrix == NULL){ // we're a fresh instance
+ matrix = new int[weight];
+ cout << "new matrix = " << matrix;
+ memset(matrix, value, weight);
+ cout << "matrix data:" << endl;
+// for(unsigned int idx = 0; idx < size; idx++){
+// cout << "idx:" << idx << "matrix value: "<< *(matrix + (idx*sizeof(int)));
+// }
+ size = weight;
+ return;
+ } else{ //adding to existing
+ unsigned int tmp_size = size+weight; //size for new matrix
+ int* tmp_matrix = new int[size+weight]; // new matrix
+ cout << "old matrix: " << matrix << " new matrix:" << tmp_matrix << " old size:" << size << " new size:" << tmp_size << endl;
+ memcpy(tmp_matrix, &value, weight); // copy the old one over
+ memset((tmp_matrix+size-1), value, weight); //set the new values
+ for(unsigned int idx = 0; idx < tmp_size; idx++){
+ if(*(tmp_matrix + (idx*sizeof(int))) > 13){
+ cout << "idx: " << idx << "matrix value: "<< *(tmp_matrix + (idx*sizeof(int))) << endl;
+ }
}
- delete matrix;
+ delete[] matrix; // kill the old one
+ matrix = tmp_matrix;
+ size = tmp_size;
}
+} */
- while(i < tmp_size){
- tmp[i] = value;
- ++i;
- }
-
- matrix = tmp;
- size = tmp_size;
-}
+
+void combine_weights(int* target, const float* in, unsigned int length){
-int DistProbMatrix::get(){
- return matrix[(rand() % size)-1];
+ unsigned int i =0;
+
+ while(i < length){
+ target[i] *= in[i];
+ ++i;
+ }
}
-
Modified: trunk/mud/grrmud/server/misc2.h
===================================================================
--- trunk/mud/grrmud/server/misc2.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/misc2.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -34,8 +34,8 @@
#include "critter.h"
#include "door.h"
#include "room.h"
+#include <vector>
-
int core_dump(const char* msg);
short a_will_help_b_against_c(critter& a, critter& b, critter& pc);
void lose_fly(critter& pc, short do_msg = FALSE);
@@ -179,16 +179,24 @@
//distributed probability matrix code
//only handles single dimension probability matrices
//multidimension would be nice though...
+template <typename T>
class DistProbMatrix {
private:
- int* matrix; //stores pointer to probability matrix
- unsigned int size; // can only support MAX_INT entries
+ vector<T> matrix; //stores pointer to probability matrix
+ unsigned int size;
public:
- void add(int size, unsigned int weight);
- int get();
+ void add(T value, unsigned int weight){
+ size += weight;
+ matrix.reserve(size);
+ for(unsigned int i = 0; i < weight; i++){
+ matrix.push_back(value);
+ }
+ }
+ T get(){return matrix[(rand()%(size-1))];}
- DistProbMatrix(){size = 0;matrix = NULL;}
- ~DistProbMatrix(){delete matrix;}
-};
+ DistProbMatrix(){size = 0;}
+};
+void combine_weights(int* target, const float* in, unsigned int length);
+
#endif
Modified: trunk/mud/grrmud/server/object.cc
===================================================================
--- trunk/mud/grrmud/server/object.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/object.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -1908,3 +1908,11 @@
}//while
return retval;
}
+
+int object::getVisBit(){
+ return cur_stats[0];
+}
+
+void object::setVisBit(int vis_bit){
+ cur_stats[0] = vis_bit;
+}
Modified: trunk/mud/grrmud/server/object.h
===================================================================
--- trunk/mud/grrmud/server/object.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/object.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -369,6 +369,9 @@
void checkForProc(String& cmd, String& arg1, critter& actor,
int targ, room& cur_room, int sanity = 0);
+ int getVisBit();
+ void setVisBit(int vis_bit);
+
}; // class object
Modified: trunk/mud/grrmud/server/room.cc
===================================================================
--- trunk/mud/grrmud/server/room.cc 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/room.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -40,8 +40,8 @@
#include "load_wld.h"
#include "Filters.h"
#include <map>
+#include "weather.h"
-
int KeywordPair::_cnt = 0;
void KeywordPair::show(int idx, critter& pc) {
@@ -454,7 +454,7 @@
room_flags.set(ROOMFLAG_NO_IMM, atoi(row[ROOMTBL_NO_IMM]));
room_flags.set(ROOMFLAG_NO_GOD, atoi(row[ROOMTBL_NO_GOD]));
room_flags.set(ROOMFLAG_IS_PERM_DARK, atoi(row[ROOMTBL_IS_PERM_DARK]));
- room_flags.set(ROOMFLAG_WEATHER, atoi(row[ROOMTBL_WEATHER]));
+ room_flags.set(ROOMFLAG_SUNLIGHT, atoi(row[ROOMTBL_WEATHER]));
room_flags.set(ROOMFLAG_NO_SHOUT, atoi(row[ROOMTBL_NO_SHOUT]));
room_flags.set(ROOMFLAG_NO_MAGICAL_EXIT, atoi(row[ROOMTBL_NO_MAGICAL_EXIT]));
room_flags.set(ROOMFLAG_IS_HAVEN, atoi(row[ROOMTBL_IS_HAVEN]));
@@ -1330,7 +1330,7 @@
values+=room_flags.get(ROOMFLAG_NO_IMM)+", ";
values+=room_flags.get(ROOMFLAG_NO_GOD)+", ";
values+=room_flags.get(ROOMFLAG_IS_PERM_DARK)+", ";
- values+=room_flags.get(ROOMFLAG_WEATHER)+", ";
+ values+=room_flags.get(ROOMFLAG_SUNLIGHT)+", ";
values+=room_flags.get(ROOMFLAG_NO_SHOUT)+", ";
values+=room_flags.get(ROOMFLAG_NO_MAGICAL_EXIT)+", ";
values+=room_flags.get(ROOMFLAG_IS_HAVEN)+", ";
@@ -2852,3 +2852,65 @@
}
return vb;
}
+
+
+WeatherType room::getWeather() const {
+
+ if(!hasWeather()) return wNONE;
+
+ if(getFlag(38)){ //temperate
+ return weather.climates[0].weather;
+ }else if(getFlag(39)){ //savanah
+ return weather.climates[1].weather;
+ }else if(getFlag(40)){ //mountain
+ return weather.climates[2].weather;
+ }else if(getFlag(41)){ //snowymountain
+ return weather.climates[3].weather;
+ }else if(getFlag(42)){ //sandydesrt
+ return weather.climates[4].weather;
+ }else if(getFlag(43)){ //dirtdesert
+ return weather.climates[5].weather;
+ }else if(getFlag(44)){ //swamp
+ return weather.climates[6].weather;
+ }else if(getFlag(45)){ //tropical
+ return weather.climates[7].weather;
+ }else if(getFlag(46)){ //arctic
+ return weather.climates[8].weather;
+ } else return wNONE;
+
+}
+
+WindType room::getWind() const {
+ //NOTE FOR ED: the following line is what we were looking for!!!!
+ //return weather.climates[getWeather()].wind;
+ return weather.climates[getClimate()].wind;
+}
+
+TemperatureType room::getTemperature() const {
+ return weather.climates[getClimate()].temperature;
+}
+
+ClimateType room::getClimate() const{
+
+ if(!hasWeather()) return cNONE;
+
+ if(getFlag(38)){ //temperate
+ return temperate;
+ }else if(getFlag(39)){ //savanah
+ return savanah;
+ }else if(getFlag(40)){ //mountain
+ return mountain;
+ }else if(getFlag(41)){ //snowymountain
+ return snowymountain;
+ }else if(getFlag(42)){ //sandydesrt
+ return sandydesert;
+ }else if(getFlag(43)){ //dirtdesert
+ return dirtdesert;
+ }else if(getFlag(44)){ //swamp
+ return swamp;
+ }else if(getFlag(45)){ //tropical
+ return tropical;
+ }else if(getFlag(46)){ //arctic
+ return arctic;
+ } else return cNONE;
+}
Modified: trunk/mud/grrmud/server/room.h
===================================================================
--- trunk/mud/grrmud/server/room.h 2007-06-08 02:38:41 UTC (rev 925)
+++ trunk/mud/grrmud/server/room.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -174,7 +174,7 @@
int isNoMagEntry() const { return room_flags.get(24); }
int isNoMagExit() const { return room_flags.get(6); }
int isPermDark() const { return room_flags.get(3); }
- int hasWeather() const { return room_flags.get(4); }
+ int hasSunlight() const { return room_flags.get(4); }
int isNoMob() const { return room_flags.get(10); }
int isNoPotion() const { return room_flags.get(11); }
int isNoMagic() const { return room_flags.get(9); }
@@ -205,7 +205,7 @@
void flipFlag(int flg) { room_flags.flip(flg); }
void setTotalLoaded(int on_off) { room_flags.set(22, on_off); }
void setFlag(int flg, int posn) { room_flags.set(flg, posn); }
- int getFlag(int flg) { return room_flags.get(flg); }
+ int getFlag(int flg) const { return room_flags.get(flg); }
const PtrList<critter>& getCrits() { return critters; }
@@ -344,6 +344,12 @@
int makeReadyForAreaSpell();
critter* findNextProcMob();
critter* findNextSpellCritter();
+
+ WeatherType getWeather() const;
+ WindType getWind() const;
+ TemperatureType getTemperature() const;
+ ClimateType getClimate() const;
+ int hasWeather() const { return room_flags.get(47); }
}; // class room
#endif
Added: trunk/mud/grrmud/server/weather.cc
===================================================================
--- trunk/mud/grrmud/server/weather.cc (rev 0)
+++ trunk/mud/grrmud/server/weather.cc 2007-06-08 18:52:35 UTC (rev 926)
@@ -0,0 +1,612 @@
+//ScryMUD Server Code
+//Copyright (C) 1998 Ben Greear
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// To contact the Author, Ben Greear: greear at cyberhighway.net, (preferred)
+// greearb at agcs.com
+//
+
+///******************** weather.cc *****************************///
+
+#include "classes.h"
+#include "misc.h"
+#include "misc2.h"
+#include "const.h"
+#include <PtrArray.h>
+#include "BuildInfo.h"
+#include "weather.h"
+#include <string2.h>
+#include <assert.h>
+#include <stdio.h>
+#include <vector>
+//TODO fix critter.isSleeping()
+//TODO make wNONE, cNONE, tNONE valid array indexes
+//TODO make int_to_enum inline funciton
+
+//climate weather base
+const int temperate_weights[] = { 520,130,130,65,55,48,32,20,10,65,48,32,0};
+const int savanah_weights[] = { 520,100,90,32,28,24,16,10,5,5,0,0,0};
+const int mountain_weights[] = { 520,130,130,65,51,44,40,20,10,80,60,40,0};
+const int snowymountain_weights[] = { 520,130,130,32,25,22,20,20,10,130,96,64,0};
+const int sandydesert_weights[] = { 540,40,30,3,2,1,1,0,0,0,0,0,80};
+const int dirtdesert_weights[] = { 600,40,30,3,2,1,1,0,0,0,0,0,0};
+const int swamp_weights[] = { 400,150,150,85,75,68,32,20,10,16,8,4,0};
+const int tropical_weights[] = { 520,130,130,65,55,48,32,10,5,0,0,0,0};
+const int arctic_weights[] = { 540,130,110,3,2,1,1,0,0,80,60,40,0};
+
+//current weather weights
+const float clear_weights[] = { 1,1,1,1,1,1,1,1,1,1,1,1,1};
+const float cloudy_weights[] = { 1,3,2,1.5,1.25,1.125,1,1,1,1.5,1.25,1.125,1};
+const float overcast_weights[] = { 1,2,3,2,1.5,1.25,1.125,1,1,2,1.5,1.25,1};
+const float drizzle_weights[] = { 1,1.5,2,3,1.5,1.25,1.125,1.1,1.1,1,1,1,0};
+const float rain_weights[] = { 0.8,1.25,1.5,2,3,2,1.5,1.25,1.1,0.8,0.8,0.7,0};
+const float heavyrain_weights[] = { 0.6,1,1.25,1.5,2,3,1.6,1,1,0.6,0.6,0.5,0};
+const float thunderstorm_weights[] = { 0.4,0.8,1,1.25,1.5,2,3,1.2,1.2,0.5,0.5,0.5,0};
+const float hail_weights[] = { 0.6,1,1.25,1.5,2,3,2,1.5,1.5,0.5,0.5,0.5,0};
+const float hailstorm_weights[] = { 0.4,0.8,1.5,2,2.5,2.5,1.5,1.5,0.35,0.35,0.35,0.35,0};
+const float lightsnow_weights[] = { 1,1.6,2,1.2,1.1,1,0.8,0,0,3,2,1.25,0};
+const float heavysnow_weights[] = { 0.6,1.4,1.6,1,0.7,0.5,0.4,0,0,2,3,1.5,0};
+const float blizzard_weights[] = { 0.6,1.4,1.6,0.6,0.5,0.3,0.2,0,0,1.5,2,2.5,0};
+const float sandstorm_weights[] = { 0.5,1,1,1,1,1,1,0,0,0,0,0,2};
+const float* weather_weights[]= { clear_weights, cloudy_weights,
+ overcast_weights,drizzle_weights,rain_weights,heavyrain_weights,
+ thunderstorm_weights,hail_weights,hailstorm_weights,lightsnow_weights,
+ heavysnow_weights,blizzard_weights,sandstorm_weights};
+
+//weather season weights
+const float spring_weights[] = { 1,2,2,2,2,2,2,1.5,1.5,0.25,0.1,0,1};
+const float summer_weights[] = { 1,1,1,1,1.2,1.25,2,1,1,0,0,0,1};
+const float fall_weights[] = { 1,1,1,1,1,1,1,0.5,0.5,1,1,1,1};
+const float winter_weights[] = { 1.3,1,1,0.75,0.75,0.75,.75,1,1,2,2,2,1};
+const float* season_weights[] = { spring_weights,summer_weights, fall_weights,
+ winter_weights};
+
+//climate temperature weights
+const int temperate_temp_weights[] = { 1,30,40,100,100,100,40,30,0};
+const int savanah_temp_weights[] = { 0,10,20,40,80,100,80,40,0};
+const int mountain_temp_weights[] = {10,40,80,100,60,20,0,0,0};
+const int snowymountain_temp_weights[] = { 30,60,100,60,20,10,0,0,0};
+const int sandydesert_temp_weights[] = { 0,0,0,0,20,40,100,100,20};
+const int dirtdesert_temp_weights[] = { 0,0,0,0,20,40,100,100,20};
+const int swamp_temp_weights[] = { 0,20,30,100,100,100,40,30,0};
+const int tropical_temp_weights[] = { 0,10,20,60,100,100,20,0,0};
+const int arctic_temp_weights[] = { 65,85,100,40,10,0,0,0,0};
+
+//weather temperature weights
+const float clear_temp_weights[] = { 1,1,1,1,1,1,1,1,1};
+const float cloudy_temp_weights[] = { 1.05,1.05,1.05,1,0.95,0.95,0.95,0.90,0.90};
+const float overcast_temp_weights[] = { 1.1,1.1,1.1,1.05,1,0.95,0.9,0.8,0.7};
+const float drizzle_temp_weights[] = { 1.2,1.2,1.15,1.1,1,0.95,0.85,0.75,0.7};
+const float rain_temp_weights[] = { 1.25,1.25,1.2,1.15,.95,0.85,0.75,0.7,0.65};
+const float heavyrain_temp_weights[] = { 1.25,1.25,1.25,1.25,1,0.85,0.75,0.7,0.65};
+const float thunderstorm_temp_weights[] = { 1.3,1.3,1.2,1.1,.95,0.80,0.70,0.65,0.6};
+const float hail_temp_weights[] = { 1.25,1.25,1.2,1.15,.95,0.85,0.75,0.7,0.65};
+const float hailstorm_temp_weights[] = { 1.25,1.25,1.25,1.25,1,0.85,0.75,0.7,0.65};
+const float lightsnow_temp_weights[] = { 1,1,1,1,0,0,0,0,0};
+const float heavysnow_temp_weights[] = { 1.15,1.1,1.05,1,0,0,0,0,0};
+const float blizzard_temp_weights[] = { 1.25,1.15,1,1,0,0,0,0,0};
+const float sandstorm_temp_weights[] = { 1,1,1,1,1,1,1,1,1};
+const float* weather_temp_weights[] = { clear_temp_weights, cloudy_temp_weights,
+ overcast_temp_weights, drizzle_temp_weights, rain_temp_weights,
+ heavyrain_temp_weights, thunderstorm_temp_weights, hail_temp_weights,
+ hailstorm_temp_weights, lightsnow_temp_weights, heavysnow_temp_weights,
+ blizzard_temp_weights, sandstorm_temp_weights };
+
+//season temperature weights
+const float spring_temp_weights[] = { 1,1,1,1,1,1,1,1,1,1,1,1,1};
+const float summer_temp_weights[] = { 1,1,1,1,1.2,1.25,2,1,1,0,0,0,1};
+const float fall_temp_weights[] = { 1,1,1,1,1,1,1,0.5,0.5,1,1,1,1};
+const float winter_temp_weights[] = { 1.3,1,1,0.75,0.75,0.75,.75,1,1,2,2,2,1};
+const float* season_temp_weights[] = {spring_temp_weights, summer_temp_weights,
+ fall_temp_weights,winter_temp_weights};
+
+//wind range
+const int wind_min[] = {0,0,0,0,5,16,0,16,0,5,12,16,30};
+const int wind_max[] = {30,30,30,30,30,35,65,30,65,30,35,65,70};
+
+//name strings
+const char* climate_strings[] = {"temperate","savanah","mountain",
+ "snowy mountain","sandy desert","dirt desert","swamp","tropical","arctic"};
+const char* weather_strings[] = {"clear","cloudy","overcast","drizzling",
+ "raining", "raining heavily","thunder storm","hailing","hail storm",
+ "snowing gently", "snowing heavily","blizzard","sandstorm"};
+const char* wind_strings[] = {"no wind", "a gentle breeze", "light winds",
+ "moderate winds", "strong winds", "gale-force winds"};
+const char* temperature_strings[] = {"freezing","very cold","cold","chilly",
+ "pleasent","warm","hot","very hot","burning hot"};
+
+//regen and mv usage mods
+const float weather_regen_mods[] = {1,1,1,1,0.95,0.9,0.8,0.9,0.8,0.95,0.9,0.8};
+const float temperature_regen_mods[] = {0.6,0.75,0.9,0.95,1,0.95,0.9,0.7,0.6};
+const float weather_mv_mods[] = {1,1,1,1,1.1,1.25,1.5,1.25,1.5,1.1,1.25,1.25};
+const float temperature_mv_mods[] = {1.4,1.25,1.25,1.1,1.05,1,1.05,1.1,1.3,1.4};
+
+TemperatureType int_to_temperature_enum(unsigned int i){
+ switch(i){
+ case 0:
+ return freezing;
+ case 1:
+ return verycold;
+ case 2:
+ return cold;
+ case 3:
+ return chilly;
+ case 4:
+ return pleasant;
+ case 5:
+ return warm;
+ case 6:
+ return hot;
+ case 7:
+ return veryhot;
+ case 8:
+ return burninghot;
+ default:
+ return tNONE;
+ }
+}
+
+WindType int_to_wind_enum(unsigned int i){
+ // note that this works differantly from all the rest
+ if(i <= 5){
+ return nowind;
+ } else if (i <=15){
+ return gentlebreeze;
+ } else if (i <=25){
+ return lightwind;
+ } else if (i <= 35){
+ return windy;
+ } else if (i <= 60){
+ return verywindy;
+ } else {return gale; }
+}
+
+ClimateType int_to_climate_enum(unsigned int i){
+ ClimateType c;
+
+ switch(i){
+ case 0:
+ c = temperate;
+ break;
+ case 1:
+ c = savanah;
+ break;
+ case 2:
+ c = mountain;
+ break;
+ case 3:
+ c = snowymountain;
+ break;
+ case 4:
+ c = sandydesert;
+ break;
+ case 5:
+ c = dirtdesert;
+ break;
+ case 6:
+ c = swamp;
+ break;
+ case 7:
+ c = tropical;
+ break;
+ case 8:
+ c = arctic;
+ break;
+ default:
+ c = cNONE;
+ }
+ return c;
+}
+
+WeatherType int_to_weather_enum(int i){
+
+ WeatherType w;
+
+ switch(i){
+ case 0:
+ w = clear;
+ break;
+ case 1:
+ w = cloudy;
+ break;
+ case 2:
+ w = overcast;
+ break;
+ case 3:
+ w = drizzle;
+ break;
+ case 4:
+ w = rain;
+ break;
+ case 5:
+ w = heavyrain;
+ break;
+ case 6:
+ w = thunderstorm;
+ break;
+ case 7:
+ w = hail;
+ break;
+ case 8:
+ w = hailstorm;
+ break;
+ case 9:
+ w = lightsnow;
+ break;
+ case 10:
+ w = heavysnow;
+ break;
+ case 11:
+ w = blizzard;
+ break;
+ case 12:
+ w = sandstorm;
+ break;
+ default:
+ w = wNONE;
+ }
+ return w;
+}
+
+Weather::Weather(){
+ for(int i=0;i<MAX_CLIMATES;i++) {
+ climates[i].weather = clear;
+ climates[i].windamount = 0;
+ climates[i].wind = nowind;
+ climates[i].climate = static_cast<ClimateType>(i);
+
+ switch(int_to_climate_enum(i)){ //so we can use the enum names
+ case temperate:
+ climates[i].weather_base = temperate_weights;
+ climates[i].temperature_base = temperate_temp_weights;
+ break;
+ case savanah:
+ climates[i].weather_base = savanah_weights;
+ climates[i].temperature_base = savanah_temp_weights;
+ break;
+ case mountain:
+ climates[i].weather_base = mountain_weights;
+ climates[i].temperature_base = mountain_temp_weights;
+ break;
+ case snowymountain:
+ climates[i].weather_base = mountain_weights;
+ climates[i].temperature_base = snowymountain_temp_weights;
+ break;
+ case sandydesert:
+ climates[i].weather_base = sandydesert_weights;
+ climates[i].temperature_base = sandydesert_temp_weights;
+ break;
+ case dirtdesert:
+ climates[i].weather_base = dirtdesert_weights;
+ climates[i].temperature_base = dirtdesert_temp_weights;
+ break;
+ case swamp:
+ climates[i].weather_base = swamp_weights;
+ climates[i].temperature_base = swamp_temp_weights;
+ break;
+ case tropical:
+ climates[i].weather_base = tropical_weights;
+ climates[i].temperature_base = tropical_temp_weights;
+ break;
+ case arctic:
+ climates[i].weather_base = arctic_weights;
+ climates[i].temperature_base = arctic_temp_weights;
+ break;
+ default:
+ abort();
+ break;
+ };
+ }//for
+}
+
+void Weather::update(){
+
+ int i = 0;
+ while(i < MAX_CLIMATES){
+ //increasing chance of weather change over time,
+ // max of 20 in game hours of a particular weather
+ //if(climates[i].weather_time * 5 > rand()%100){
+ // memcpy(&c,&i,sizeof(ClimateType));
+ changeWeather(int_to_climate_enum(i));
+ //}
+
+ //wind changes faster than weather does, max of 4 in game hours
+ //if(20 + climates[i].wind_time * 20 > rand()%100){
+ // changeWind(i);
+ //}
+ ++i;
+ }
+}
+
+void Weather::changeWeather(ClimateType i, WeatherType tw){
+// this will randomly change weather or set it to the specified type
+ unsigned int idx = 0;
+ int weights[MAX_WEATHER];
+ DistProbMatrix<WeatherType> weather_prob;
+ DistProbMatrix<TemperatureType> temp_prob;
+ int tweights[MAX_TEMP];
+
+ //grab base weights for weather and temp
+ memcpy(weights,climates[i].weather_base,MAX_WEATHER*sizeof(int));
+ memcpy(tweights,climates[i].temperature_base,MAX_TEMP*sizeof(int));
+ //combine current weather weights with base weather
+ combine_weights(weights,weather_weights[climates[i].weather],MAX_WEATHER);
+ // combine season weights for weather and temperature
+ combine_weights(weights,season_weights[get_season(config.day)],
+ MAX_WEATHER);
+ combine_weights(tweights,season_temp_weights[get_season(config.day)],
+ MAX_TEMP);
+
+ if(tw == wNONE){
+ //build the weather probability matrix
+ while(idx < MAX_WEATHER){
+ if(weights[idx]!=0) weather_prob.add(int_to_weather_enum(idx),weights[idx]);
+ ++idx;
+ }
+ //get our weather
+ climates[i].weather = weather_prob.get();
+ }else climates[i].weather = tw;
+ //we have our new weather, so we can combine weather and temp weights
+ combine_weights(tweights,weather_temp_weights[i],MAX_TEMP);
+
+ //build temp prob matrix
+ idx =0;
+ while(idx < MAX_TEMP){
+ if(weights[idx] != 0) temp_prob.add(int_to_temperature_enum(idx),tweights[idx]);
+ ++idx;
+ }
+ climates[i].temperature = temp_prob.get();
+
+ //get our wind values
+ climates[i].windamount = 1+wind_min[i] +
+ (rand()%(wind_max[i]-wind_min[i]));
+
+ //set our wind enum
+ climates[i].wind = int_to_wind_enum(climates[i].windamount);
+
+
+
+ //if it's hailing, let's smack some people
+ if(climates[i].weather == hail || climates[i].weather == hailstorm){
+ Cell<critter*> cll(pc_list);
+ critter* pc;
+ critter* crit_ptr;
+ room* rm;
+ String buf(100);
+ unsigned int dam;
+ int prob=8; // set the prob unrealisticaly low so as to not annoy players
+
+ if(climates[i].weather == hail){
+ prob = 5;
+ }
+
+ while((pc = cll.next())){
+ if(!pc->isImmort() || !pc->isNoHassle()){
+ rm = pc->getCurRoom();
+ if(rm->getClimate() == i){
+ if((rand()%20 + 1)>prob){
+ if(d(1,pc->DEX) > d(1,20)){
+ Cell<critter*> rcll(rm->getCrits()); //holds mob s in room
+ dam = d(1,5);
+ pc->takeDamage(dam,NORMAL);
+ switch(dam){
+ case 1:
+ case 2:
+ case 3:
+ if(pc->isSleeping()){
+ pc->setPosn(POS_REST);
+ pc->show("You are awakened by a piece of hail hitting you!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ Sprintf(buf, "%S is woken up by being hit with a piece of hail!\n",
+ pc->getName(crit_ptr->SEE_BIT));
+ crit_ptr->show(buf);
+ }
+ }
+ }else if(pc->isMeditating()){
+ pc->setPosn(POS_REST);
+ pc->show("Your meditation is broken by a stinging sensation!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ Sprintf(buf, "%S's meditation is broken by a small piece of hail!!\n",
+ pc->getName(crit_ptr->SEE_BIT));
+ crit_ptr->show(buf);
+ }
+ }
+ }else{
+ pc->show("A small piece of hail hits you!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ Sprintf(buf, "A small piece of hails hits %S!\n",
+ pc->getName(crit_ptr->SEE_BIT));
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ break;
+ case 4:
+ case 5:
+ if(pc->isSleeping()){
+ pc->setPosn(POS_REST);
+ pc->show("You are awakened by a stringing sensation!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ Sprintf(buf, "%S is woken up by being hit with a large piece of hail!\n",
+ pc->getName(crit_ptr->SEE_BIT));
+ crit_ptr->show(buf);
+ }
+ }
+ }else if(pc->isMeditating()){
+ pc->setPosn(POS_REST);
+ pc->show("A stinging sensation breaks your meditation\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ Sprintf(buf, "%S's meditation is disrupted by a large peice of hail !\n",
+ pc->getName(crit_ptr->SEE_BIT));
+ crit_ptr->show(buf);
+ }
+ }
+ }else{
+ pc->show("A large piece of hail hits you!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ Sprintf(buf, "A large piece of hails hits %S!\n",
+ pc->getName(crit_ptr->SEE_BIT));
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ break;
+ }
+ } else {
+ Cell<critter*> rcll(rm->getCrits()); //holds mobs in room
+ if(pc->isSleeping() || pc->isMeditating()){
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ if(crit_ptr->canSee(*pc)){
+ Sprintf(buf,
+ "%S is nearly hit hit by a piece of hail!\n",
+ pc->getName());
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ }else{
+ pc->show("You barely avoid being hit by a piece of hail!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ if(crit_ptr->canSee(*pc)){
+ Sprintf(buf,
+ "%S barely avoids being hit by a piece of hail!\n",
+ pc->getName());
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(climates[i].weather == thunderstorm){
+
+ Cell<critter*> cll(pc_list);
+ critter* pc;
+ critter* crit_ptr;
+ room* rm;
+ String buf(100);
+ int dam;
+
+ if(d(1,100) <=50 ){//50% chance of thunder
+ while((pc = cll.next())){
+ rm = pc->getCurRoom();
+ if(rm->getClimate() == i){
+ if(d(1,1000) == 1){
+ Cell<critter*> rcll(rm->getCrits());
+ dam = d(3,30);
+ //struck by lightning
+ pc->takeDamage(dam, ELECTRICITY);
+ if(pc->isSleeping()){
+ pc->setPosn(POS_REST);
+ pc->show("You awaken to the intense pain of being struck by lightning!\n");
+
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ if(crit_ptr->canSee(*pc)){
+ Sprintf(buf,
+ "%S is struck by lightning!!\n",
+ pc->getName());
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ }else if(pc->isMeditating()){
+ pc->setPosn(POS_REST);
+ pc->show("You meditation is broken by a bolt of lightning striking you!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ if(crit_ptr->canSee(*pc)){
+ Sprintf(buf,
+ "%S is struck by lightning!!\n",
+ pc->getName());
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ }else {
+ pc->show("You've been struck by lightning!\n");
+ while((crit_ptr = rcll.next())){
+ if(crit_ptr != pc){
+ if(crit_ptr->canSee(*pc)){
+ Sprintf(buf,
+ "%S is struck by lightning!!\n",
+ pc->getName());
+ crit_ptr->show(buf);
+ }
+ }
+ }
+ }
+ }
+ else{
+ if(pc->isSleeping()){
+ pc->setPosn(POS_REST);
+ pc->show("The crash of nearby thunder awakens you!\n");
+ } else if(pc->isMeditating()){
+ if(d(1,100) < get_percent_lrnd(MEDITATION_SKILL_NUM, *pc)){
+ //do nothing right now
+ }else{
+ pc->setPosn(POS_REST);
+ pc->show("A loud crash of thunder breaks your meditation!\n");
+ }
+ } else{
+ pc->show("A brief flash of lightning is followed a crash of thunder!\n");
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+bool Weather::isRaining(ClimateType c) const {
+
+ switch(climates[c].weather){
+ case drizzle:
+ case rain:
+ case heavyrain:
+ case thunderstorm:
+ case hail:
+ case hailstorm:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool Weather::isSnowing(ClimateType c) const {
+
+ switch(climates[c].weather){
+ case lightsnow:
+ case heavysnow:
+ case blizzard:
+ return true;
+ default:
+ return false;
+ }
+}
Added: trunk/mud/grrmud/server/weather.h
===================================================================
--- trunk/mud/grrmud/server/weather.h (rev 0)
+++ trunk/mud/grrmud/server/weather.h 2007-06-08 18:52:35 UTC (rev 926)
@@ -0,0 +1,200 @@
+//
+//ScryMUD Server Code
+//
+//This program is free software; you can redistribute it and/or
+//modify it under the terms of the GNU General Public License
+//as published by the Free Software Foundation; either version 2
+//of the License, or (at your option) any later version.
+//
+//This program is distributed in the hope that it will be useful,
+//but WITHOUT ANY WARRANTY; without even the implied warranty of
+//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+//GNU General Public License for more details.
+//
+//You should have received a copy of the GNU General Public License
+//along with this program; if not, write to the Free Software
+//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+// To contact the Author, Ben Greear: greear at cyberhighway.net, (preferred)
+// greearb at agcs.com
+//
+///******************** weaher.h *****************************///
+
+#ifndef __WEATHER_INCLUDE
+#define __WEATHER_INCLUDE
+
+//we don't actually use most of these defines
+//climate types
+#define CTEMPERATE 0
+#define CSAVANAH 1
+#define CMOUNTAIN 2
+#define CSNOWYMOUNTAIN 3
+#define CSANDYDESERT 4
+#define CDIRTDESERT 5
+#define CSWAMP 6
+#define CTROPCIAL 7
+#define CARCTIC 8
+//weather types
+#define WCLEAR 0
+#define WCLOUDY 1
+#define WOVERCAST 2
+#define WDIRZZLE 3
+#define WRAIN 4
+#define WHEAVYRAIN 5
+#define WTHUNDERSTORM 6
+#define WHAIL 7
+#define WHAILSTORM 8
+#define WLIGHTSOW 9
+#define WHEAVYSNOW 10
+#define WBLIZZARD 11
+#define WSANDSTORM 12
+//temperature types
+#define TFREEZING 0
+#define TVERYCOLD 1
+#define TCOLD 2
+#define TCHILLY 3
+#define TPLEASENT 4
+#define TWARM 5
+#define THOT 6
+#define TVERYHOT 7
+#define TBURNINGHOT 8
+//fog types
+#define FNONE 0
+#define FLIGHT 1
+#define FMEDIUM 2
+#define FHEAVY 3
+//wind types
+#define WDNONE 0
+#define WDGENTLE 1
+#define WDLIGHT 2
+#define WDMODERATE 3
+#define WDHEAVY 4
+#define WDGALE 5
+
+//we do use these ones
+#define MAX_CLIMATES 9
+#define MAX_WEATHER 13
+#define MAX_FOG 4
+#define MAX_WIND 6
+#define MAX_TEMP 9
+
+
+extern const int temperate_weights[];
+extern const int savanah_weights[];
+extern const int mountain_weights[];
+extern const int snowymountain_weights[];
+extern const int sandydesert_weights[];
+extern const int dirtdesert_weights[];
+extern const int swamp_weights[];
+extern const int tropical_weights[];
+extern const int arctic_weights[];
+
+extern const float clear_weights[];
+extern const float cloudy_weights[];
+extern const float overcast_weights[];
+extern const float drizzle_weights[];
+extern const float rain_weights[];
+extern const float heavyrain_weights[];
+extern const float thunderstorm_weights[];
+extern const float hail_weights[];
+extern const float hailstorm_weights[];
+extern const float lightsnow_weights[];
+extern const float heavysnow_weights[];
+extern const float blizzard_weights[];
+extern const float sandstorm_weights[];
+extern const float* weather_weights[];
+
+extern const float spring_weights[];
+extern const float summer_weights[];
+extern const float fall_weights[];
+extern const float winter_weights[];
+extern const float* season_weights[];
+//temperature
+extern const int temperate_temp_weights[];
+extern const int savanah_temp_weights[];
+extern const int mountain_temp_weights[];
+extern const int snowymountain_temp_weights[];
+extern const int sandydesert_temp_weights[];
+extern const int dirtdesert_temp_weights[];
+extern const int swamp_temp_weights[];
+extern const int tropical_temp_weights[];
+extern const int arctic_temp_weights[];
+
+extern const float clear_temp_weights[];
+extern const float cloudy_temp_weights[];
+extern const float overcast_temp_weights[];
+extern const float drizzle_temp_weights[];
+extern const float rain_temp_weights[];
+extern const float heavyrain_temp_weights[];
+extern const float thunderstorm_temp_weights[];
+extern const float hail_temp_weights[];
+extern const float hailstorm_temp_weights[];
+extern const float lightsnow_temp_weights[];
+extern const float heavysnow_temp_weights[];
+extern const float blizzard_temp_weights[];
+extern const float sandstorm_temp_weights[];
+extern const float* weather_temp_weights[];
+
+extern const float spring_temp_weights[];
+extern const float summer_temp_weights[];
+extern const float fall_temp_weights[];
+extern const float winter_temp_weights[];
+extern const float* season_temp_weights[];
+
+//wind
+extern const int wind_min[];
+extern const int wind_max[];
+//strings
+extern const char* climate_strings[];
+extern const char* weather_strings[];
+extern const char* wind_strings[];
+extern const char* temperature_strings[];
+//mods
+extern const float weather_regen_mods[];
+extern const float temperature_regen_mods[];
+extern const float weather_mv_mods[];
+extern const float temperature_mv_mods[];
+
+//enum FogType {none = 0, lightfog, mediumfog, heavyfog};
+
+enum WeatherType {clear =0, cloudy, overcast, drizzle,
+ rain, heavyrain, thunderstorm, hail, hailstorm, lightsnow, heavysnow,
+ blizzard, sandstorm, wNONE};
+
+enum WindType {nowind = 0, gentlebreeze, lightwind, windy, verywindy, gale,
+ wndNONE};
+
+enum ClimateType {temperate = 0, savanah, mountain, snowymountain, sandydesert,
+ dirtdesert, swamp, tropical, arctic, cNONE};
+
+enum TemperatureType {freezing=0, verycold, cold, chilly, pleasant,
+ warm, hot, veryhot, burninghot, tNONE};
+
+struct Climate{
+ ClimateType climate;
+ unsigned int windamount;
+ WeatherType weather;
+ WindType wind;
+ TemperatureType temperature;
+ //store these here so we don't need a big switch in changeWeather
+ const int* weather_base;
+ const int* temperature_base;
+};
+
+class Weather{
+public:
+ Climate climates[MAX_CLIMATES];
+ void update();
+ void changeWeather(ClimateType i,WeatherType tw = wNONE);
+ bool isRaining(ClimateType c) const;
+ bool isSnowing(ClimateType c) const;
+// void changeWind(int i);
+// int weather_base[MAX_CLIMATES][MAX_WEATHER];
+ Weather();
+};
+
+TemperatureType int_to_temperature_enum(unsigned int i);
+WindType int_to_wind_enum(unsigned int i);
+ClimateType int_to_climate_enum(unsigned int i);
+WeatherType int_to_weather_enum(int i);
+#endif
More information about the ScryMUD
mailing list