IFO Spawns

Welcome in the osRose emulator Project.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

Re: IFO Spawns

Postby Maxxon on Tue May 13, 2008 11:58 pm

lmame wrote:
Drakia wrote:Which traversing?


I don't really know how spawns are working server side. If it's like the traversing of players or stuff, it could take quite some time.


Well you can do it the hard way and stick with looping through everything till you found something, or you can add to each Mob a pointer to its spawn structure and save the looping. Costs memory, but saves time :P

edit: edited the horrible english i wrote a bit.
Last edited by Maxxon on Wed May 14, 2008 11:23 am, edited 1 time in total.
Image
an anymous comment on a program called reloader:
what if a fatal error happens, will it restart it?
User avatar
Maxxon
Hawker's pet
Hawker's pet
 
Posts: 1305
Joined: Sat Nov 10, 2007 12:42 pm

Re: IFO Spawns

Postby lmame on Wed May 14, 2008 2:01 am

Yeah that was my question :) since the original devs from osrose loved traversing everywhere a lot.
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: IFO Spawns

Postby Drakia on Wed May 14, 2008 2:18 am

Well, when loading there's a lot of loops of course, but that's kinda needed, unless you only want to load one spawn point ;)
My favorite skill is scaring new users away.
If you haven't SEARCHED expect me to yell at you.
Image
Drakia
ospRose dev team
ospRose dev team
 
Posts: 1614
Joined: Tue Sep 18, 2007 6:53 am
Location: Nanaimo, BC, Canada

Re: IFO Spawns

Postby lmame on Wed May 14, 2008 2:19 am

Oh no loading is fine :)
I was rather speaking in game ;) like you know when searching a player name, proximity list, stuff like that. Those ones are taking a lot of CPU (expecially the proximity test).
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: IFO Spawns

Postby Drakia on Wed May 14, 2008 2:22 am

Ah, yes they would, cause it's gotta go through every player and do a circle compare on their x/y, right?

Here are the instructions for the current code I have. This isn't the best code, but it seems to work ok. It still needs a lot of work, and is nowhere near production ready, this is for devs only. You'll need to import the attached SQL file into your database. I'll be throwing this into the SVN (Unactivated, of course, so it won't actually affect anything) at some point, just need to double check that I have all the #ifdef's I need in there properly :)
This is now in the SVN, but disabled (uncomment the #define in sockets.h to enable it). Attached is also a picture of what the old spawn system looks like at the same place where I took a picture of my spawn system.

So, a few things that need working on. Fish swim on land, this is a problem with the current mob movement system I think. Not sure what other problems there are, if you run into any let me know.

[Update]
I just updated this to the current system implemented in OSpRose :D

[Update #2]
Ok, so tac mobs only spawn after tacPoint basic mobs have been killed. Also it now uses the amount field in mobs to spawn multiple of the same mob.

DataTypes.h
--------------------
Find:


Before, Add:
  1. #ifdef USEIFO
  2. struct CMob {
  3.   UINT id;
  4.   UINT mobId;
  5.   bool tactical;
  6.   UINT amount;
  7.   CNPCData* thisnpc;
  8.     CMDrops* mobdrop;
  9.     CMDrops* mapdrop;
  10. };
  11.  
  12. struct CMobGroup {
  13.   UINT id;
  14.   UINT map;
  15.   UINT limit;
  16.   UINT active;
  17.   UINT tacticalpoints;
  18.   UINT respawntime;
  19.   UINT basicKills;
  20.   fPoint point;
  21.   UINT range;
  22.   clock_t lastRespawnTime;
  23.   vector<CMob*> basicMobs;
  24.   vector<CMob*> tacMobs;
  25. };
  26. #endif



ExtraFunctions.cpp
--------------------
Find:
  1. // delete a spawn
  2. bool CWorldServer::DeleteSpawn( CSpawnArea* spawn )


Before, Add:
  1. #ifdef USEIFO
  2. CMobGroup* CWorldServer::GetMobGroup(UINT id, UINT map ) {
  3.   if (map != 0) {
  4.     for (unsigned j = 0; j < MapList.Index[map]->MobGroupList.size(); j++) {
  5.       CMobGroup* thisgroup = MapList.Index[map]->MobGroupList.at(j);
  6.       if (thisgroup->id == id)
  7.         return thisgroup;
  8.     }
  9.   } else {
  10.     for (map = 0; map < MapList.Map.size(); map++) {
  11.       for (unsigned j = 0; j < MapList.Index[map]->MobGroupList.size(); j++) {
  12.         CMobGroup* thisgroup = MapList.Index[map]->MobGroupList.at(j);
  13.         if (thisgroup->id == id)
  14.           return thisgroup;
  15.       }
  16.     }
  17.   }
  18.   return NULL;
  19. }
  20. #endif


Find:
  1. if( id = thisnpc->id ){return thisnpc;}


Replace With:
  1. if( id == thisnpc->id ){return thisnpc;}



MapFunctions.cpp
------------------
Find:
  1. void CMap::RespawnMonster( )
  2. {


After, Add:


Find (Last closing bracket for the function):


Before, Add:
  1. #else
  2.     for (UINT j = 0; j < MobGroupList.size(); j++) {
  3.       CMobGroup* thisgroup = MobGroupList.at(j);
  4.       clock_t rtime = clock() - thisgroup->lastRespawnTime;
  5.       if (rtime < thisgroup->respawntime*CLOCKS_PER_SEC || thisgroup->active >= thisgroup->limit)
  6.         continue;
  7.       for (UINT k = thisgroup->active; k < thisgroup->limit; k++) {
  8.         CMob *thismob;
  9.         if (thisgroup->tacMobs.size() > 0 && thisgroup->basicKills > thisgroup->tacticalpoints) {
  10.           UINT mobId = (UINT)(rand() % thisgroup->tacMobs.size());
  11.           thismob = thisgroup->tacMobs.at(mobId);
  12.           thisgroup->basicKills = 0;
  13.         } else {
  14.           UINT mobId = (UINT)(rand() % thisgroup->basicMobs.size());
  15.           thismob = thisgroup->basicMobs.at(mobId);
  16.         }
  17.         for (UINT i = 0; i < thismob->amount; i++) {
  18.           fPoint position = GServer->RandInCircle( thisgroup->point, thisgroup->range );
  19.           AddMonster( thismob->mobId, position, 0, thismob->mobdrop, thismob->mapdrop, thisgroup->id );
  20.         }
  21.       }
  22.     }
  23. #endif



Startup.cpp
-----------------
Find:
  1. bool CWorldServer::LoadMonsterSpawn( )


Before, Add:
  1. #ifdef USEIFO
  2. bool CWorldServer::LoadMobGroups() {
  3.   Log(MSG_LOAD, "MobGroups data    " );
  4.   vector<CMobGroup*> mobGroups;
  5.   MYSQL_ROW row;
  6.   bool flag = true;
  7.   char* tmp = NULL;
  8.   MYSQL_RES *result = DB->QStore("SELECT id, map, x, y, range, respawntime, `limit`, tacticalpoints, moblist FROM list_mobgroups");
  9.   if (result == NULL) return false;
  10.   while (row = mysql_fetch_row(result)) {
  11.     CMobGroup* thisgroup = new (nothrow) CMobGroup;
  12.     if (thisgroup == NULL) {
  13.       Log(MSG_ERROR, "Error allocating memory");
  14.       DB->QFree();
  15.       return false;
  16.     }
  17.     thisgroup->id = atoi(row[0]);
  18.     thisgroup->map = atoi(row[1]);
  19.     thisgroup->point.x = atof(row[2]);
  20.     thisgroup->point.y = atof(row[3]);
  21.     thisgroup->range = atoi(row[4]);
  22.     thisgroup->respawntime = atoi(row[5]);
  23.     thisgroup->limit = atoi(row[6]);
  24.     thisgroup->tacticalpoints = atoi(row[7]);
  25.     char* mobList = row[8];
  26.  
  27.     thisgroup->lastRespawnTime = clock();
  28.     thisgroup->active = 0;
  29.  
  30.     thisgroup->basicMobs.clear();
  31.     thisgroup->tacMobs.clear();
  32.  
  33.     // Fill in basic/tac mobs
  34.     tmp = strtok(mobList, ",|");
  35.     while (tmp != NULL) {
  36.       int mobId = atoi(tmp);
  37.       tmp = strtok(NULL, ",|");
  38.       if (tmp == NULL) {
  39.         Log(MSG_ERROR, "MobGroup %i is invalid", thisgroup->id);
  40.         flag = false;
  41.         break;
  42.       }
  43.       int amount = atoi(tmp);
  44.       tmp = strtok(NULL, ",|");
  45.       if (tmp == NULL) {
  46.         Log(MSG_ERROR, "MobGroup %i is invalid", thisgroup->id);
  47.         flag = false;
  48.         break;
  49.       }
  50.       int tactical = atoi(tmp);
  51.       CMob *thismob = new (nothrow) CMob;
  52.       if (thismob == NULL) {
  53.         Log(MSG_ERROR, "Error allocating memory");
  54.         DB->QFree();
  55.         return false;
  56.       }
  57.       thismob->amount = amount;
  58.       thismob->tactical = tactical;
  59.       thismob->mobId = mobId;
  60.       thismob->thisnpc = GetNPCDataByID( thismob->mobId );
  61.       thismob->mapdrop = GetDropData( thisgroup->map );
  62.       thismob->mobdrop = GetDropData( thismob->thisnpc->dropid );
  63.       if (thismob->thisnpc == NULL) {
  64.         Log(MSG_WARNING, "Invalid mobId - Mob %i will not be added", atoi(row[0]));
  65.         delete thismob;
  66.         continue;
  67.       }
  68.       if (thismob->tactical)
  69.         thisgroup->tacMobs.push_back(thismob);
  70.       else
  71.         thisgroup->basicMobs.push_back(thismob);
  72.       tmp = strtok(NULL, ",|");
  73.     }
  74.     if (!flag) {
  75.       delete thisgroup;
  76.       continue;
  77.     }
  78.     MapList.Index[thisgroup->map]->MobGroupList.push_back(thisgroup);
  79.     mobGroups.push_back(thisgroup);
  80.     }
  81.     DB->QFree( );
  82.     return true;
  83. }
  84. #endif


Find:
  1. bool CWorldServer::LoadMonsters( )
  2. {
  3.     Log( MSG_LOAD, "Monsters Spawn       " );
  4.     // Do our monster spawnin


After, Add:


Find:


Before, Add:
  1. #else
  2.     for (UINT i = 0; i < MapList.Map.size(); i++) {
  3.       CMap *thismap = MapList.Map.at(i);
  4.       for (UINT j = 0; j < thismap->MobGroupList.size(); j++) {
  5.         CMobGroup* thisgroup = thismap->MobGroupList.at(j);
  6.         // Load some basic mobs onto map
  7.         for (UINT k = 0; k < thisgroup->limit; k++) {
  8.           UINT mobId = (UINT)(rand() % thisgroup->basicMobs.size());
  9.           CMob* thismob = thisgroup->basicMobs.at(mobId);
  10.           for (UINT l = 0; l < thismob->amount; l++) {
  11.             fPoint position = RandInCircle( thisgroup->point, thisgroup->range );
  12.             thismap->AddMonster( thismob->mobId, position, 0, thismob->mobdrop, thismob->mapdrop, thisgroup->id );
  13.           }
  14.         }
  15.       }
  16.     }
  17. #endif


Find:
  1. newzone->MonsterSpawnList.clear();


After, Add:
  1. #ifdef USEIFO
  2.         newzone->MobGroupList.clear();
  3. #endif



WorldMap.cpp
----------------
Find:
  1. MonsterSpawnList.clear();


After, Add:
  1. #ifdef USEIFO
  2.     MobGroupList.clear();
  3. #endif


Find:
  1.        delete RespawnList.at(i);


After, Add:
  1. #ifdef USEIFO
  2.     for(UINT i = 0; i < MobGroupList.size(); i++) {
  3.       CMobGroup *thisgroup = MobGroupList.at(i);
  4.       for (UINT j = 0; j < thisgroup->basicMobs.size(); j++)
  5.         delete thisgroup->basicMobs.at(j);
  6.       for (UINT j = 0; j < thisgroup->tacMobs.size(); j++)
  7.         delete thisgroup->tacMobs.at(j);
  8.       delete thisgroup;
  9.     }
  10. #endif


Find:
  1.        CSpawnArea* thisspawn = GServer->GetSpawnArea( spawnid, this->id );
  2.         if(thisspawn!=NULL)
  3.             thisspawn->amon++;


Replace With:
  1. #ifndef USEIFO
  2.         CSpawnArea* thisspawn = GServer->GetSpawnArea( spawnid, this->id );
  3.         if(thisspawn!=NULL)
  4.             thisspawn->amon++;
  5. #else
  6.         CMobGroup* thisgroup = GServer->GetMobGroup( spawnid, this->id );
  7.         if(thisgroup!=NULL)
  8.             thisgroup->active++;
  9. #endif


Find:
  1.        CSpawnArea* thisspawn = GServer->GetSpawnArea( monster->Position->respawn, monster->Position->Map );
  2.         if(thisspawn!=NULL)
  3.         {
  4.             if(thisspawn->amon >= thisspawn->max)// reset spawn timer if the spawn is full
  5.                 thisspawn->lastRespawnTime = clock();
  6.             thisspawn->amon--;
  7.         }

Replace With:
  1. #ifndef USEIFO
  2.         CSpawnArea* thisspawn = GServer->GetSpawnArea( monster->Position->respawn, monster->Position->Map );
  3.         if(thisspawn!=NULL)
  4.         {
  5.             if(thisspawn->amon >= thisspawn->max)// reset spawn timer if the spawn is full
  6.                 thisspawn->lastRespawnTime = clock();
  7.             thisspawn->amon--;
  8.         }
  9. #else
  10.         CMobGroup* thisgroup = GServer->GetMobGroup( monster->Position->respawn, monster->Position->Map );
  11.         if(thisgroup!=NULL)
  12.         {
  13.             if(thisgroup->active >= thisgroup->limit)// reset spawn timer if the spawn is full
  14.                 thisgroup->lastRespawnTime = clock();
  15.             thisgroup->active--;
  16.             thisgroup->basicKills++;
  17.         }
  18. #endif



WorldMap.h
----------------
Find:
  1.    vector<CSpawnArea*>         MonsterSpawnList; // Monster spawn in this map  


After, Add:
  1. #ifdef USEIFO
  2.     vector<CMobGroup*>          MobGroupList; // Spawn "Zones"
  3. #endif



WorldServer.cpp
---------------
Find:
  1.    LoadMonsterSpawn( );


Replace With:
  1. #ifndef USEIFO
  2.     LoadMonsterSpawn( );
  3. #else
  4.     LoadMobGroups( );
  5. #endif


WorldServer.h
-----------------
Find:
  1.        CSpawnArea* GetSpawnArea( UINT id, UINT map=0 );


After, Add:
  1. #ifdef USEIFO
  2.         CMobGroup* GetMobGroup( UINT id, UINT map=0 );
  3. #endif


Find:
  1.        bool LoadMonsterSpawn( );


After, Add:
  1. #ifdef USEIFO
  2.         bool LoadMobGroups( );
  3. #endif


Common/Sockets.h (Only do this to enable the IFO based spawns)
----------------------
Find:
  1. #define __ROSE_SOCKETS__

After, Add:
Attachments
mobgroup.zip
(47.58 KiB) Downloaded 402 times
OldSpawn.jpg
Last edited by Drakia on Thu May 15, 2008 8:53 pm, edited 4 times in total.
My favorite skill is scaring new users away.
If you haven't SEARCHED expect me to yell at you.
Image
Drakia
ospRose dev team
ospRose dev team
 
Posts: 1614
Joined: Tue Sep 18, 2007 6:53 am
Location: Nanaimo, BC, Canada

Re: IFO Spawns

Postby Blackdpd on Wed May 14, 2008 5:04 am

well at least im going to try this out but first im going to need to update to rev 13 im still using from irose... like on rev 9 i think
so i will try it after school.
and tell you everything when i run up to something ok?
there is one thing i like to say on pre-evo your level was not white was it. at least not what i remember. it was yellow like its on irose. just telling and asking. ;)

well Good Job Drakia i can see your all into it :D
and you like to do it i see.

( im kinda like a mindreader, just kidding )

Blackdpd `
User avatar
Blackdpd
El Verloon Marshall
El Verloon Marshall
 
Posts: 900
Joined: Sun Jan 27, 2008 10:06 pm
Location: The Netherlands

Re: IFO Spawns

Postby Drakia on Wed May 14, 2008 5:09 am

If you update to Rev 13, it's already in the code, just needs the one #define in sockets.h uncommented to enable it.

Let me know if there's any problems :)

And my level is white... Atleast in the 112 client it is.
My favorite skill is scaring new users away.
If you haven't SEARCHED expect me to yell at you.
Image
Drakia
ospRose dev team
ospRose dev team
 
Posts: 1614
Joined: Tue Sep 18, 2007 6:53 am
Location: Nanaimo, BC, Canada

Re: IFO Spawns

Postby Blackdpd on Wed May 14, 2008 5:10 am

Drakia wrote:If you update to Rev 13, it's already in the code, just needs the one #define in sockets.h uncommented to enable it.

Let me know if there's any problems :)


as i said i will try it tomorrow ;) i have exams today and kinda looking it trough and i need to update my server files cus im still at rev 9.

anyway its going good :D

yes i mean is that soposed to be like that : white i thought it was yellow.
maybe from the updates they had but now you cant update the 112 client :?
anything else i dont know...

Blackdpd `
User avatar
Blackdpd
El Verloon Marshall
El Verloon Marshall
 
Posts: 900
Joined: Sun Jan 27, 2008 10:06 pm
Location: The Netherlands

Re: IFO Spawns

Postby Drakia on Wed May 14, 2008 5:35 am

I've got Rob using this build with IFO spawns enabled, and he said all the mobs are looking well placed :)
My favorite skill is scaring new users away.
If you haven't SEARCHED expect me to yell at you.
Image
Drakia
ospRose dev team
ospRose dev team
 
Posts: 1614
Joined: Tue Sep 18, 2007 6:53 am
Location: Nanaimo, BC, Canada

Re: IFO Spawns

Postby Blackdpd on Wed May 14, 2008 6:13 am

when i saw your pic i think so too . but still i wanna see more it brings back memory's :D

Blackdpd `
User avatar
Blackdpd
El Verloon Marshall
El Verloon Marshall
 
Posts: 900
Joined: Sun Jan 27, 2008 10:06 pm
Location: The Netherlands

PreviousNext

Return to Support - OspRose Emulator

Who is online

Users browsing this forum: No registered users and 8 guests

cron