PDA

View Full Version : A Fix for Zone Weather and New No KIll Feature


WildcardX
12-20-2006, 03:41 PM
I have a fix for the weather in zones. This will prevent it from raining in dungeons that have no weather and the weather will only be the weather the zone weather column specifies, else it will be a clear blue day!

I also have implemented a feature that will allow server ops to prevent players from engaging in combat in specified zones. Plane of Knowledge, for example, is not a zone that allows combat.

I have tested the following code myself and it appears to work as I expected. Please integrate this code with the server's CVS code base. Thanks!


diff -u c:\temp\old/aggro.cpp c:\temp\new/aggro.cpp
--- c:\temp\old/aggro.cpp 2006-10-30 21:04:24.000000000 -0600
+++ c:\temp\new/aggro.cpp 2006-12-20 18:29:51.937500000 -0600
@@ -28,6 +28,8 @@
#include "StringIDs.h"
#include <iostream>

+//extern Zone* zone;
+
//#define LOSDEBUG 6

//look around a client for things which might aggro the client.
@@ -427,6 +429,9 @@
// NPC *npc1, *npc2;
int reverse;

+ if(!zone->CanDoCombat())
+ return false;
+
// some special cases
if(!target)
return false;
diff -u c:\temp\old/zone.cpp c:\temp\new/zone.cpp
--- c:\temp\old/zone.cpp 2006-11-29 00:17:06.000000000 -0600
+++ c:\temp\new/zone.cpp 2006-12-20 21:17:44.890625000 -0600
@@ -149,10 +149,22 @@

//This is a bad way of making it set the type to clear on bootup.
int8 weather=database.GetZoneWeather(zone->GetZoneID());
+
+ /*
if(weather<1 || weather>3)
zone->weather_type=1;
else
zone->weather_type=weather;
+ */
+
+ if(weather)
+ {
+ if(weather < 0 || weather > 3)
+ zone->weather_type = 0;
+ else
+ zone->weather_type = weather;
+ }
+
LogFile->write(EQEMuLog::Debug, "Default weather for zone is:%i", zone->weather_type);
return true;
}
@@ -667,7 +679,7 @@
Weather_Timer = new Timer(((rand()%7200-30)+30)*2000);
Weather_Timer->Start();
LogFile->write(EQEMuLog::Status, "Weather should change in %i seconds",Weather_Timer->GetRemainingTime()/1000);
- weather_type = 1;
+ weather_type = 0;
zone_weather = 0;

aas = NULL;
@@ -878,7 +890,7 @@

bool Zone::LoadZoneCFG(const char* filename, bool DontLoadDefault) {
memset(&newzone_data, 0, sizeof(NewZone_Struct));
- if(!database.GetZoneCFG(database.GetZoneID(filenam e), &newzone_data, can_bind)) {
+ if(!database.GetZoneCFG(database.GetZoneID(filenam e), &newzone_data, can_bind, can_combat)) {
cout << "Error while loading Zone Config!\n";
cout << "IF YOU HAVENT DONE SO, SOURCE THE ZONECFG.SQL FILE!!!!!!\n";
return false;
@@ -1020,33 +1032,40 @@
guildwars.Update();
#endif

- if(Weather_Timer->Check()){
+ if(Weather_Timer->Check())
+ {
Weather_Timer->Disable();
int16 tmpweather =rand()%100;
- int8 type=weather_type-1;
- //0 normal, 1 rainy, 2 snowy
- if(type!=2){
- if(zone_weather==type && tmpweather>80)
- zone_weather=2;
- else if(zone_weather==type)
- zone_weather=type+1;
- else
- zone_weather=type; //default to zones default
- }
- else{
- if(zone_weather==2 && tmpweather>80)
- zone_weather=1;
- else if(zone_weather==2)
- zone_weather=0;
- else
- zone_weather=2; //default to zones default
+
+ if(weather_type != 0)
+ {
+ if(tmpweather)
+ {
+ if(tmpweather > 80)
+ {
+ // A change in the weather....
+ int8 tmpOldWeather = zone_weather;
+
+ if(zone_weather == 0)
+ zone_weather = weather_type;
+ else
+ zone_weather = 0;
+
+ LogFile->write(EQEMuLog::Debug, "The weather has changed. Old weather was = %i. New weather is = %i", tmpOldWeather, zone_weather);
+ }
+ else
+ LogFile->write(EQEMuLog::Debug, "The weather is not going to change. Chance was = %i\%", tmpweather);
+ }
}
+
this->weatherSend();
safe_delete(Weather_Timer);
- if(zone_weather==type) //stopping, reset to large timer
+
+ if(zone_weather==weather_type) //stopping, reset to large timer
Weather_Timer= new Timer(((rand()%(7170))+30)*2000);
else
Weather_Timer= new Timer(((rand()%(570))+30)*1000);
+
Weather_Timer->Start();
LogFile->write(EQEMuLog::Status, "Weather should change in %i seconds",Weather_Timer->GetRemainingTime()/1000);
}
@@ -1761,3 +1780,5 @@
entity_list.QueueClients(0, outapp);
safe_delete(outapp);
}
+
+
diff -u c:\temp\old/zone.h c:\temp\new/zone.h
--- c:\temp\old/zone.h 2006-10-15 15:48:20.000000000 -0500
+++ c:\temp\new/zone.h 2006-12-20 18:29:30.734375000 -0600
@@ -161,6 +161,7 @@
void weatherProc();
void weatherSend();
bool CanBind() const { return(can_bind); }
+ bool CanDoCombat() const { return(can_combat); }

time_t weather_timer;
int8 weather_type;
@@ -192,6 +193,7 @@
float psafe_x, psafe_y, psafe_z;
int32 pMaxClients;
bool can_bind;
+ bool can_combat;

int totalAAs;
SendAA_Struct **aas; //array of AA structs
diff -u c:\temp\old/zonedb.cpp c:\temp\new/zonedb.cpp
--- c:\temp\old/zonedb.cpp 2006-12-01 22:41:48.000000000 -0600
+++ c:\temp\new/zonedb.cpp 2006-12-20 13:25:27.952801600 -0600
@@ -75,7 +75,7 @@
return true;
}

-bool ZoneDatabase::GetZoneCFG(int32 zoneid, NewZone_Struct *zone_data, bool &can_bind) {
+bool ZoneDatabase::GetZoneCFG(int32 zoneid, NewZone_Struct *zone_data, bool &can_bind, bool &can_combat) {
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
@@ -88,7 +88,7 @@
"fog_red3,fog_green3,fog_blue3,fog_minclip3,fog_max clip3,"
"fog_red4,fog_green4,fog_blue4,fog_minclip4,fog_max clip4,"
"sky,zone_exp_multiplier,safe_x,safe_y,safe_z,under world,"
- "minclip,maxclip,time_type,canbind"
+ "minclip,maxclip,time_type,canbind,cancombat"
" from zone where zoneidnumber=%i",zoneid), errbuf, &result)) {
safe_delete_array(query);
while((row = mysql_fetch_row(result))) {
@@ -118,6 +118,7 @@
zone_data->gravity = 0.4;

can_bind = atoi(row[r++])==0?false:true;
+ can_combat = atoi(row[r++])==0?false:true;

good = true;
}
diff -u c:\temp\old/zonedb.h c:\temp\new/zonedb.h
--- c:\temp\old/zonedb.h 2006-12-01 22:41:48.000000000 -0600
+++ c:\temp\new/zonedb.h 2006-12-20 18:12:55.125000000 -0600
@@ -149,7 +149,7 @@
/*
* Zone related
*/
- bool GetZoneCFG(int32 zoneid, NewZone_Struct *data, bool &can_bind);
+ bool GetZoneCFG(int32 zoneid, NewZone_Struct *data, bool &can_bind, bool &can_combat);
bool SaveZoneCFG(int32 zoneid,NewZone_Struct* zd);
bool DumpZoneState();
sint8 LoadZoneState(const char* zonename, LinkedList<Spawn2*>& spawn2_list);



And the following SQL is necessary for the code above....


ALTER TABLE `zone` ADD `cancombat` tinyint(4) NOT NULL default '1';
UPDATE `zone` SET `cancombat` = 0 WHERE short_name = 'nexus';
UPDATE `zone` SET `cancombat` = 0 WHERE short_name = 'poknowledge';
UPDATE `zone` SET `cancombat` = 0 WHERE short_name = 'potranquility';


Enjoy!

John Adams
12-21-2006, 07:25 AM
That rocks. Is it normal that the weather changes to often, too? I noticed it starts snowing on me, and I set the weather off. 5 seconds later, it's snowing again. So annoying, I hotkeyed #weather 0.

If the frequency is normal, then ok. If not, can it be adjusted to be a little less annoying? Thanks!

quadroplex
06-07-2008, 01:57 AM
on my server the weather doesnt randomly change at all it always stays sunny so to speak was the random weather feature scrapped?

Angelox
06-07-2008, 06:58 AM
Thanks for the fix Wildcardx very much appreciated - very nice to see you back!

Aramid
06-07-2008, 08:02 AM
I hope you realize that the code in this thread is over 18 months old.

quadroplex
06-07-2008, 09:36 AM
yeah i know that but its only one of a few weather related threads thats why i posted in this to see if they scrapped the randomized weather deal

eq4me
06-07-2008, 11:03 AM
This Patch went in four days after WildcardX posted it. But from looking at the source and changelog it was heavily modified after that.

From the Changelog:

==2/11/2007
WildcardX: Further enhancements to zone weather system to reduce the amount of work necessary to perform weather and to make it more logical.
==1/29/2007
WildcardX: Cleaned up zone weather code for better efficiency. Weather checks will be more frequent when their is snow or rain and less frequent when the sun is out.
WildcardX: Made weather log messages more consistent and informative.
WildcardX: Clients entering a zone will now receive a weather packet. This will ensure all clients in the same zone will experience the same weather.
==12/24/2006
KLS: (WildcardX) Fix for zone weather, should no longer rain in places with no set weather, such as dungeons.

Btw.: And I too thought that WildcardX had choose to come back. Damn thread necromancy. :(

quadroplex
06-07-2008, 11:23 AM
yeah but for some reason and i cant figure it out i looked in the source, and didnt see any reason why it wouldnt work, but the weather in zones with weather set to 1 2 or 3 never change its just plain wierd

Aramid
06-07-2008, 02:10 PM
yeah i know that but its only one of a few weather related threads thats why i posted in this to see if they scrapped the randomized weather deal

I said this for Angelox, who thanked him for the code and was glad to see him back!