Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. ///mining_ai
  2.  
  3. switch(aistate)
  4. {
  5. case "comefromidle":
  6. {
  7. if instance_exists(oStoneBlock)
  8. {
  9. rock = findStone(x,y) //Go to nearest rock
  10. path = path_add()
  11. direction = point_direction(x,y,rock.x,rock.y)
  12. mp_grid_clear_cell(global.aigrid,floor(rock.x/32),floor(rock.y/32))
  13. mp_grid_path(global.aigrid,path,x,y,rock.x,rock.y,true)
  14. path_start(path,walkspeed,0,true)
  15. aistate = "goingtorock"
  16. } else {
  17. oIRCServer.counts[? CurrentJob] -= 1
  18. CurrentJob = "Idle"
  19. }
  20. break
  21. }
  22. case "goingtorock":
  23. {
  24. if path_position = 1 //If Path has ended
  25. {
  26. aistate = "mining"
  27. path_delete(path) //Clearing memory
  28. }
  29. break
  30. }
  31. case "mining":
  32. {
  33. if instance_exists(oStoneBlock)
  34. {
  35. rock = findStone(x,y)
  36. if rock.stonehp > 0 //If stone is still alive, hurt him
  37. {
  38. rock.stonehp -= 5
  39. }
  40. else
  41. {
  42. with rock instance_destroy() //If stone is mined, add stone to inv and destroy Stone
  43. stone += 1
  44. if stone >= 5
  45. {
  46. if instance_exists(oStockpile) //Bring Stone to Stockpile
  47. {
  48. stockpile = instance_nearest(x,y,oStockpile)
  49. path = path_add()
  50. direction = point_direction(x,y,stockpile.x,stockpile.y)
  51. mp_grid_clear_cell(global.aigrid,floor(stockpile.x/32),floor(stockpile.y/32))
  52. mp_grid_path(global.aigrid,path,x,y,stockpile.x,stockpile.y,true)
  53. path_start(path,walkspeed,0,true)
  54. aistate = "goingtostockpile"
  55. }
  56. } else {
  57. if instance_exists(oStoneBlock) //Go to next rock
  58. {
  59. rock = findStone(x,y)
  60. path = path_add()
  61. direction = point_direction(x,y,rock.x,rock.y)
  62. mp_grid_clear_cell(global.aigrid,floor(rock.x/32),floor(rock.y/32))
  63. mp_grid_path(global.aigrid,path,x,y,rock.x,rock.y,true)
  64. path_start(path,walkspeed,0,true)
  65. aistate = "goingtorock"
  66. } else {
  67. stockpile = instance_nearest(x,y,oStockpile) //Bring Stone to Stockpile
  68. path = path_add()
  69. direction = point_direction(x,y,stockpile.x,stockpile.y)
  70. mp_grid_clear_cell(global.aigrid,floor(stockpile.x/32),floor(stockpile.y/32))
  71. mp_grid_path(global.aigrid,path,x,y,stockpile.x,stockpile.y,true)
  72. path_start(path,walkspeed,0,true)
  73. aistate = "goingtostockpile"
  74. }
  75. }
  76. }
  77. }
  78. else
  79. {
  80. oIRCServer.counts[? CurrentJob] -= 1
  81. CurrentJob = "Idle"
  82. }
  83. break
  84. }
  85. case "goingtostockpile":
  86. {
  87. if path_position = 1 //If Path has ended
  88. {
  89. path_delete(path) //Clearing memory
  90. global.stone += stone
  91. stone = 0
  92. if instance_exists(oStoneBlock) //Mine next stoneblock
  93. {
  94. rock = findStone(x,y)
  95. path = path_add()
  96. direction = point_direction(x,y,rock.x,rock.y)
  97. mp_grid_clear_cell(global.aigrid,floor(rock.x/32),floor(rock.y/32))
  98. mp_grid_path(global.aigrid,path,x,y,rock.x,rock.y,true)
  99. path_start(path,walkspeed,0,true)
  100. aistate = "goingtorock"
  101. }
  102. else
  103. {
  104. oIRCServer.counts[? CurrentJob] -= 1
  105. CurrentJob = "Idle"
  106. }
  107. }
  108. break
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement