Browse Source

Fixed random crashes caused by random artifact starting bonus.

DjWarmonger 15 năm trước cách đây
mục cha
commit
740c227d6c
1 tập tin đã thay đổi với 16 bổ sung20 xóa
  1. 16 20
      lib/CGameState.cpp

+ 16 - 20
lib/CGameState.cpp

@@ -1444,26 +1444,22 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 			}
 		case bartifact:
 			{
-				//TODO: FIX IT!
-
-// 				if(!k->second.heroes.size())
-// 				{
-// 					tlog5 << "Cannot give starting artifact - no heroes!" << std::endl;
-// 					break;
-// 				}
-// 				CArtifact *toGive;
-// 				do 
-// 				{
-// 					toGive = VLC->arth->treasures[ran() % VLC->arth->treasures.size()];
-// 				} while (!map->allowedArtifact[toGive->id]);
-// 				CGHeroInstance *hero = k->second.heroes[0];
-// 				std::vector<ui16>::iterator slot = vstd::findFirstNot(hero->artifWorn,toGive->possibleSlots);
-// 				if(slot!=toGive->possibleSlots.end())
-// 				{
-// 					VLC->arth->equipArtifact(hero->artifWorn, *slot, toGive->id, &hero->bonuses);
-// 				}
-// 				else
-// 					hero->giveArtifact(toGive->id);
+ 				if(!k->second.heroes.size())
+				{
+					tlog5 << "Cannot give starting artifact - no heroes!" << std::endl;
+					break;
+				}
+ 				CArtifact *toGive;
+ 				toGive = VLC->arth->artifacts[VLC->arth->getRandomArt (CArtifact::ART_TREASURE)];
+
+				CGHeroInstance *hero = k->second.heroes[0];
+				std::vector<ui16>::iterator slot = vstd::findFirstNot (hero->artifWorn, toGive->possibleSlots);
+				if(slot!=toGive->possibleSlots.end())
+				{
+					VLC->arth->equipArtifact(hero->artifWorn, *slot, toGive->id, &hero->bonuses);
+				}
+				else
+ 					hero->giveArtifact(toGive->id);
 			}
 		}
 	}