fork(1) download
  1. //BEGIN DESCRIPTION
  2. //END DESCRIPTION
  3.  
  4. //BEGIN INCLUDES
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdbool.h>
  8. #include <time.h>
  9. #include <string.h>
  10. //END INCLUDES
  11.  
  12. //BEGIN CPP DEFINITIONS
  13. #define RARITY_GRADES 3
  14.  
  15. //COLORS
  16. //https://e...content-available-to-author-only...a.org/wiki/ANSI_escape_code#Colors
  17. //END CPP DEFINITIONS
  18.  
  19. //BEGIN DATASTRUCTURES
  20. struct grade{
  21. char name[30];
  22. int dr;
  23. };
  24. struct grade rarity[RARITY_GRADES];
  25.  
  26. struct drops{
  27. char name[30];
  28. struct grade rarity[RARITY_GRADES];
  29. };
  30. struct drops helmet1;
  31.  
  32. struct monster{
  33. char name[30];
  34. int droprate;
  35. // int hp;
  36. struct drops items;
  37. };
  38. struct monster barbar;
  39. //END DATASTRUCTURES
  40.  
  41. //BEGIN GLOBALS
  42. //END GLOBALS
  43.  
  44. //BEGIN FUNCTION PROTOTYPES
  45. void monster_dies(struct monster);
  46. bool drop(struct monster);
  47. void item(struct monster);
  48. //END FUNCTION PROTOTYPES
  49.  
  50. /* DEFINED PROGRESS GOALS
  51.  *
  52.  * todo todo todo
  53.  *
  54.  */
  55.  
  56. //BEGIN MAIN FUNCTION
  57. int main(void)
  58. {
  59.  
  60. //BEGIN INIT
  61. srand (time(NULL));
  62. strcpy(rarity[0].name , "Junk");
  63. rarity[0].dr= 0;
  64. strcpy(rarity[1].name , "Magic");
  65. rarity[1].dr= 89;
  66. strcpy(rarity[2].name , "Ancient Artefact");
  67. rarity[2].dr= 98;
  68. int i;
  69. for (i=0; i<RARITY_GRADES; i++){
  70. helmet1.rarity[i]=rarity[i];
  71. }
  72. strcpy(helmet1.name, "Wonderhelm");
  73.  
  74. strcpy(barbar.name , "Barbar");
  75. barbar.droprate=30;
  76. barbar.items=helmet1;
  77.  
  78.  
  79.  
  80. //END INIT
  81.  
  82. for (i=0; i<100; i++){
  83. monster_dies(barbar);
  84. }
  85.  
  86.  
  87. //BEGIN CLEAN UP
  88. //END CLEAN UP
  89. return EXIT_SUCCESS;
  90. }
  91. //END MAIN FUNCTION
  92.  
  93. //BEGIN FUNCTIONS
  94. void monster_dies(struct monster entity)
  95. {
  96. //monster dies sound
  97. //monster dies animation
  98. if (drop(entity))
  99. item(entity);
  100. else
  101. printf("%s dropped nothing!\n",entity.name);
  102. //set respawn timer
  103. }
  104.  
  105. bool drop(struct monster entity)
  106. {
  107. if (rand()%100 < entity.droprate){
  108. // printf("Monster dropped something!\n");
  109. return true;
  110. }
  111. return false;
  112. }
  113.  
  114. void item(struct monster entity)
  115. {
  116. printf("%s dropped %s in ",entity.name,entity.items.name);
  117. int rn;
  118. rn=rand()%100;
  119.  
  120. if(rn>entity.items.rarity[2].dr)
  121. printf( "%s",entity.items.rarity[2].name);
  122. else if (rn>entity.items.rarity[1].dr)
  123. printf( "%s",entity.items.rarity[1].name);
  124. else
  125. printf( "%s",entity.items.rarity[0].name);
  126. printf( " rarity\n");
  127.  
  128. }
  129. //END FUNCTIONS
  130.  
  131.  
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Ancient Artefact rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped Wonderhelm in Junk rarity
Barbar dropped nothing!
Barbar dropped nothing!
Barbar dropped nothing!