Advertisement
Venrob

Enemy Permadeath System (Semi-incomplete)

Jan 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. typedef DEFINE const int;
  2. typedef CONFIG const int;
  3.  
  4. CONFIG NUM_MAPS = 1;
  5. CONFIG NUM_BOOL_PER_INT = 8; //May be able to go safely up to 16... 8 is safe though
  6. //
  7. DEFINE NUM_ENEMY_PER_SCREEN = 10;
  8. DEFINE NUM_ENEMY_PER_MAP = NUM_ENEMY_PER_SCREEN * 128;
  9. DEFINE NUM_ENEMIES = NUM_MAPS * NUM_ENEMY_PER_MAP;
  10. DEFINE NUM_BOOL = NUM_ENEMIES/NUM_BOOL_PER_INT;
  11. int enemyStore[NUM_ENEMIES];//Do not modify
  12. int enemyDead[NUM_BOOL];//Do not modify
  13.  
  14. //Each index of this is the enemy from that screen index of the current screen. Make sure to check their `->isValid()` before using!
  15. npc screenEnemies[10];
  16.  
  17. //Call this before `while(true)` in global active
  18. void __loadEnemiesFromQuest()
  19. {
  20. for(int map = 1; map <= NUM_MAPS; ++map)
  21. {
  22. for(int screen = 0x00; screen < 0x80; ++screen)
  23. {
  24. mapdata m = Game->LoadMapData(map,screen);
  25. for(int q = 0; q < 10; ++q)
  26. {
  27. enemyStore[(map*NUM_ENEMY_PER_MAP)+(screen*NUM_ENEMY_PER_SCREEN)+q] = m->Enemy[q];
  28. m->Enemy[q] = 0;
  29. }
  30. }
  31. }
  32. }
  33.  
  34. //Call this somewhere in your global active, to check if enemies are dead, and make them stay dead permanently.
  35. //Make sure it is called AFTER spawnEnemies()!!!
  36. void __checkEnemyDeath()
  37. {
  38. if(Link->Action == LA_SCROLLING) return;
  39. for(int q = 0; q < 10; ++q)
  40. {
  41. if(!screenEnemies[q]->isValid())
  42. {
  43. killEnemy(q);
  44. }
  45. }
  46. }
  47.  
  48. void killEnemy(int map, int screen, int index)
  49. {
  50. int temp = (map*NUM_ENEMY_PER_MAP)+(screen*NUM_ENEMY_PER_SCREEN)+index;
  51. enemyDead[Floor(temp/8.0)] |= 1<<(temp%8);
  52. }
  53.  
  54. void killEnemy(int index)
  55. {
  56. killEnemy(Game->GetCurMap(), Game->GetCurScreen(), index);
  57. }
  58.  
  59. void reviveEnemy(int map, int screen, int index)
  60. {
  61. int temp = (map*NUM_ENEMY_PER_MAP)+(screen*NUM_ENEMY_PER_SCREEN)+index;
  62. enemyDead[Floor(temp/8.0)] &= ~(1<<(temp%8));
  63. }
  64.  
  65. void reviveEnemy(int index)
  66. {
  67. reviveEnemy(Game->GetCurMap(), Game->GetCurScreen(), index);
  68. }
  69.  
  70. bool isDead(int map, int screen, int index)
  71. {
  72. int temp = (map*NUM_ENEMY_PER_MAP)+(screen*NUM_ENEMY_PER_SCREEN)+index;
  73. return (enemyDead[Floor(temp/8.0)] & (1<<(temp%8))) > 0;
  74. }
  75.  
  76. bool isDead(int index)
  77. {
  78. isDead(Game->GetCurMap(), Game->GetCurScreen(), index);
  79. }
  80.  
  81. void spawnEnemies()
  82. {
  83. if(Link->Action == LA_SCROLLING) return;
  84. DEFINE MAPINDEX = (Game->GetCurMap()*NUM_ENEMY_PER_MAP)+(Game->GetCurScreen()*NUM_ENEMY_PER_SCREEN)
  85. for(int q = 0; q < 10; ++q)
  86. {
  87. if(enemyStore[MAPINDEX+q] && !isDead(q))
  88. {
  89. npc n = Screen->CreateNPC(enemyStore[MAPINDEX+q]);
  90. positionEnemy(n, q);
  91. screenEnemies[q] = n;
  92. }
  93. else
  94. {
  95. screenEnemies[q] = Debug->Null();
  96. }
  97. }
  98. }
  99.  
  100. void positionEnemy(npc n, int index)
  101. {
  102. //Write your own code here for positioning enemies which spawn. Each enemy will be passed to this function.
  103. //The index is the enemy's screen index, for things like enemy placement flags to be checked.
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement