Bladeren bron

altered once_mobspawn a bit (got from Freya, tested)

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@1194 54d463be-8e91-2dee-dedb-b68131a5f0ec
Lupus 20 jaren geleden
bovenliggende
commit
84ecc09c0c
1 gewijzigde bestanden met toevoegingen van 20 en 5 verwijderingen
  1. 20 5
      src/map/mob.c

+ 20 - 5
src/map/mob.c

@@ -121,6 +121,7 @@ int mob_once_spawn(struct map_session_data *sd,char *mapname,
 {
 	struct mob_data *md=NULL;
 	int m,count,lv=255,r=class_;
+	int c,j=0;
 
 	if( sd )
 		lv=sd->status.base_level;
@@ -152,14 +153,28 @@ int mob_once_spawn(struct map_session_data *sd,char *mapname,
 //		if(battle_config.etc_log)
 //			printf("mobclass=%d try=%d\n",class_,i);
 	}
-
-	if(sd){
-		if(x<=0) x=sd->bl.x;
-		if(y<=0) y=sd->bl.y;
-	}else if(x<=0 || y<=0){
+	if (sd) { //even if the coords were wrong, spawn mob anyways (but look for most suitable coords first) Got from Freya [Lupus]
+		if (x <= 0 || y <= 0) {
+			if (x <= 0) x = sd->bl.x + rand() % 3 - 1;
+			if (y <= 0) y = sd->bl.y + rand() % 3 - 1;
+			if ((c = map_getcell(m, x, y)) == 1 || c == 5) {
+				x = sd->bl.x;
+				y = sd->bl.y;
+			}
+		}
+	} else if (x <= 0 || y <= 0) {
 		printf("mob_once_spawn: %i at %s x:%i y:%i\n ??\n",class_,map[m].name,x,y); //got idea from Freya [Lupus]
+		do {
+			x = rand() % (map[m].xs - 2) + 1;
+			y = rand() % (map[m].ys - 2) + 1;
+		} while (((c = map_getcell(m, x, y)) == 1 || c == 5) && j++ < 64);
+		if (c == 1 || c == 5) { // not solved?
+			x = 0;
+			y = 0;
+		}
 	}
 
+
 	for(count=0;count<amount;count++){
 		md=(struct mob_data *)aCalloc(1,sizeof(struct mob_data));
 		memset(md, '\0', sizeof *md);