C++ - Random line read


SUBMITTED BY: Guest

DATE: Nov. 20, 2013, 8:48 p.m.

FORMAT: Text only

SIZE: 4.0 kB

HITS: 911

  1. DWORD cFindEvent::GetRandomPosition()
  2. {
  3. //---------------------------------------------------------------------------------------
  4. FILE * garew = fopen (MobCoords,"r");
  5. //---------------------------------------------------------------------------------------
  6. char temp[1024];
  7. int i = 0;
  8. int j = 0;
  9. int licz = rand() % 100;
  10. //---------------------------------------------------------------------------------------
  11. while ( !feof(garew) && i <= licz)
  12. {
  13. //-----------------------------------------------------------------------------------
  14. fgets(temp , 1024 , garew );
  15. //-----------------------------------------------------------------------------------
  16. if(temp[0] != '/' && temp[1] != '/')
  17. {
  18. //-------------------------------------------------------------------------------
  19. sscanf(temp,"%d %d %d", &DayMap, &DayX, &DayY);
  20. if(DayMap >= 0)
  21. {
  22. //---------------------------------------------------------------------------
  23. i++;
  24. //---------------------------------------------------------------------------
  25. }
  26. //-------------------------------------------------------------------------------
  27. }
  28. //-----------------------------------------------------------------------------------
  29. }
  30. //---------------------------------------------------------------------------------------
  31. fclose(garew);
  32. //---------------------------------------------------------------------------------------
  33. FILE * garew2 = fopen (MobCoords,"r");
  34. //---------------------------------------------------------------------------------------
  35. if(licz > i)
  36. {
  37. //-----------------------------------------------------------------------------------
  38. int licz2 = rand() % i;
  39. //-----------------------------------------------------------------------------------
  40. while ( j <= licz2 )
  41. {
  42. //-------------------------------------------------------------------------------
  43. fgets(temp , 1024 , garew2 );
  44. //-------------------------------------------------------------------------------
  45. if(temp[0] != '/' && temp[1] != '/')
  46. {
  47. //---------------------------------------------------------------------------
  48. sscanf(temp,"%d %d %d", &DayMap, &DayX, &DayY);
  49. if(DayMap >= 0)
  50. {
  51. //-----------------------------------------------------------------------
  52. j++;
  53. //-----------------------------------------------------------------------
  54. }
  55. //---------------------------------------------------------------------------
  56. }
  57. //-------------------------------------------------------------------------------
  58. }
  59. //-----------------------------------------------------------------------------------
  60. }
  61. //---------------------------------------------------------------------------------------
  62. fclose(garew2);
  63. //---------------------------------------------------------------------------------------
  64. DWORD Reward = DNState.DayBossIndex=CreateMobInXY(21,DayMap,DayX,DayY);
  65. Chat.MessageAll(0,0,NULL,"The monster entered the coordinates: %d x %d", DayX, DayY);;
  66. //---------------------------------------------------------------------------------------
  67. return Reward;
  68. //---------------------------------------------------------------------------------------
  69. }

comments powered by Disqus