BasicBlock.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #include "BasicBlocks.h"
  2. BasicBlock::BasicBlock(const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos)
  3. : Block(zType, zTool, pos, false)
  4. {}
  5. bool BasicBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
  6. {
  7. return 0;
  8. }
  9. void BasicBlock::onPostTick()
  10. {}
  11. BasicBlockType::BasicBlockType(int typeId, int itemTypeId)
  12. : BlockType(typeId, 0),
  13. itemType(itemTypeId),
  14. transparent(0),
  15. passable(0),
  16. maxHp(100.f),
  17. hardness(1.f),
  18. zTool(0),
  19. speedModifier(1.f),
  20. interactable(1)
  21. {}
  22. void BasicBlockType::createSuperBlock(Block* zBlock, Item* zItem) const
  23. {
  24. if (zItem)
  25. BlockType::createSuperBlock(zBlock, zItem);
  26. else
  27. {
  28. BasicBlock* block = dynamic_cast<BasicBlock*>(zBlock);
  29. if (!block)
  30. throw "DirtBlockType::createSuperBlock was called with a block witch is not an instance of BasicBlock";
  31. block->transparent = transparent;
  32. block->passable = passable;
  33. block->hp = maxHp;
  34. block->maxHP = maxHp;
  35. block->hardness = hardness;
  36. block->zTool = zTool;
  37. block->speedModifier = speedModifier;
  38. block->interactable = interactable;
  39. }
  40. }
  41. Block* BasicBlockType::createBlock(Framework::Vec3<int> position) const
  42. {
  43. return new BasicBlock(this, 0, position);
  44. }
  45. Item* BasicBlockType::createItem() const
  46. {
  47. return StaticRegistry<ItemType>::INSTANCE.zElement(itemType)->createItem();
  48. }
  49. // Dirt
  50. DirtBlockType::DirtBlockType()
  51. : BasicBlockType(ID, DirtBlockItemType::ID)
  52. {
  53. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  54. }
  55. DirtBlockItemType::DirtBlockItemType()
  56. : BasicBlockItemType(ID, "Dirt", 0, 0)
  57. {}
  58. Item* DirtBlockItemType::createItem() const
  59. {
  60. BasicBlockItem* item = new BasicBlockItem(this, DirtBlockType::INSTANCE, "Dirt");
  61. initializeItem(item, 0, 0, 100, 100, 1, 0, 1);
  62. return item;
  63. }
  64. // Stone
  65. StoneBlockType::StoneBlockType()
  66. : BasicBlockType(ID, StoneBlockItemType::ID)
  67. {
  68. hardness = 2.f;
  69. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  70. }
  71. StoneBlockItemType::StoneBlockItemType()
  72. : BasicBlockItemType(ID, "Stone", 0, 0)
  73. {}
  74. Item* StoneBlockItemType::createItem() const
  75. {
  76. BasicBlockItem* item = new BasicBlockItem(this, StoneBlockType::INSTANCE, "Stone");
  77. initializeItem(item, 0, 0, 100, 100, 2, 0, 1);
  78. return item;
  79. }
  80. // Sand
  81. SandBlockType::SandBlockType()
  82. : BasicBlockType(ID, SandBlockItemType::ID)
  83. {
  84. hardness = 0.5f;
  85. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  86. }
  87. SandBlockItemType::SandBlockItemType()
  88. : BasicBlockItemType(ID, "Sand", 0, 0)
  89. {}
  90. Item* SandBlockItemType::createItem() const
  91. {
  92. BasicBlockItem* item = new BasicBlockItem(this, SandBlockType::INSTANCE, "Sand");
  93. initializeItem(item, 0, 0, 100, 100, 0.5f, 0, 1);
  94. return item;
  95. }
  96. // Oak Wood
  97. OakBlockType::OakBlockType()
  98. : BasicBlockType(ID, OakBlockItemType::ID)
  99. {
  100. hardness = 1.5f;
  101. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  102. }
  103. OakBlockItemType::OakBlockItemType()
  104. : BasicBlockItemType(ID, "Oak", 0, 0)
  105. {}
  106. Item* OakBlockItemType::createItem() const
  107. {
  108. BasicBlockItem* item = new BasicBlockItem(this, OakBlockType::INSTANCE, "Oak");
  109. initializeItem(item, 0, 0, 100, 100, 1.5f, 0, 1);
  110. return item;
  111. }
  112. // Leaves Wood
  113. LeavesBlockType::LeavesBlockType()
  114. : BasicBlockType(ID, LeavesBlockItemType::ID)
  115. {
  116. hardness = 0.1f;
  117. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  118. }
  119. LeavesBlockItemType::LeavesBlockItemType()
  120. : BasicBlockItemType(ID, "Leaves", 0, 0)
  121. {}
  122. Item* LeavesBlockItemType::createItem() const
  123. {
  124. BasicBlockItem* item = new BasicBlockItem(this, LeavesBlockType::INSTANCE, "Leaves");
  125. initializeItem(item, 0, 0, 100, 100, 0.1f, 0, 1);
  126. return item;
  127. }
  128. // Gravel
  129. GravelBlockType::GravelBlockType()
  130. : BasicBlockType(ID, GravelBlockItemType::ID)
  131. {
  132. hardness = 0.75f;
  133. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  134. }
  135. GravelBlockItemType::GravelBlockItemType()
  136. : BasicBlockItemType(ID, "Gravel", 0, 0)
  137. {}
  138. Item* GravelBlockItemType::createItem() const
  139. {
  140. BasicBlockItem* item = new BasicBlockItem(this, GravelBlockType::INSTANCE, "Gravel");
  141. initializeItem(item, 0, 0, 100, 100, 0.75f, 0, 1);
  142. return item;
  143. }
  144. // Granite
  145. GraniteBlockType::GraniteBlockType()
  146. : BasicBlockType(ID, GraniteBlockItemType::ID)
  147. {
  148. hardness = 3.f;
  149. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  150. }
  151. GraniteBlockItemType::GraniteBlockItemType()
  152. : BasicBlockItemType(ID, "Granite", 0, 0)
  153. {}
  154. Item* GraniteBlockItemType::createItem() const
  155. {
  156. BasicBlockItem* item = new BasicBlockItem(this, GraniteBlockType::INSTANCE, "Granite");
  157. initializeItem(item, 0, 0, 100, 100, 3.f, 0, 1);
  158. return item;
  159. }
  160. // Cobble
  161. CobbleBlockType::CobbleBlockType()
  162. : BasicBlockType(ID, CobbleBlockItemType::ID)
  163. {
  164. hardness = 1.f;
  165. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  166. }
  167. CobbleBlockItemType::CobbleBlockItemType()
  168. : BasicBlockItemType(ID, "Cobble", 0, 0)
  169. {}
  170. Item* CobbleBlockItemType::createItem() const
  171. {
  172. BasicBlockItem* item = new BasicBlockItem(this, CobbleBlockType::INSTANCE, "Cobble");
  173. initializeItem(item, 0, 0, 100, 100, 1.f, 0, 1);
  174. return item;
  175. }
  176. // Birch Wood
  177. BirchBlockType::BirchBlockType()
  178. : BasicBlockType(ID, BirchBlockItemType::ID)
  179. {
  180. hardness = 1.5f;
  181. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  182. }
  183. BirchBlockItemType::BirchBlockItemType()
  184. : BasicBlockItemType(ID, "Birch", 0, 0)
  185. {}
  186. Item* BirchBlockItemType::createItem() const
  187. {
  188. BasicBlockItem* item = new BasicBlockItem(this, BirchBlockType::INSTANCE, "Birch");
  189. initializeItem(item, 0, 0, 100, 100, 1.5f, 0, 1);
  190. return item;
  191. }
  192. // Beech Wood
  193. BeechBlockType::BeechBlockType()
  194. : BasicBlockType(ID, BeechBlockItemType::ID)
  195. {
  196. hardness = 1.5f;
  197. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  198. }
  199. BeechBlockItemType::BeechBlockItemType()
  200. : BasicBlockItemType(ID, "Beech", 0, 0)
  201. {}
  202. Item* BeechBlockItemType::createItem() const
  203. {
  204. BasicBlockItem* item = new BasicBlockItem(this, BeechBlockType::INSTANCE, "Beech");
  205. initializeItem(item, 0, 0, 100, 100, 1.5f, 0, 1);
  206. return item;
  207. }
  208. // Basalt
  209. BasaltBlockType::BasaltBlockType()
  210. : BasicBlockType(ID, BasaltBlockItemType::ID)
  211. {
  212. hardness = 2.f;
  213. defaultBlock = createBlockAt({ 0, 0, 0 }, 0);
  214. }
  215. BasaltBlockItemType::BasaltBlockItemType()
  216. : BasicBlockItemType(ID, "Basalt", 0, 0)
  217. {}
  218. Item* BasaltBlockItemType::createItem() const
  219. {
  220. BasicBlockItem* item = new BasicBlockItem(this, BasaltBlockType::INSTANCE, "Basalt");
  221. initializeItem(item, 0, 0, 100, 100, 2.f, 0, 1);
  222. return item;
  223. }