-
Notifications
You must be signed in to change notification settings - Fork 74
Natural mob spawn #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Natural mob spawn #237
Changes from 2 commits
60fecbc
621dfca
433f76d
427122e
abff8ea
3707404
dd60485
ea5091b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,28 @@ | ||
| #include "EntityCategories.hpp" | ||
|
|
||
| const EntityCategories::CategoriesMask EntityCategories::maskEnums[] = | ||
| { | ||
| ENTITY, | ||
| MOB, | ||
| PATHFINDER_MOB, | ||
| UNKNOWN, | ||
| MONSTER, | ||
| ANIMAL, | ||
| WATER_ANIMAL, | ||
| TAMABLE_ANIMAL, | ||
| AMBIENT, | ||
| UNDEAD_MOB, | ||
| ZOMBIE_MONSTER, | ||
| ARTHROPOD, | ||
| MINECART, | ||
| SKELETON_MONSTER, | ||
| EQUINE_ANIMAL, | ||
| PROJECTILE, | ||
| ABSTRACT_ARROW, | ||
| VILLAGER_BASE | ||
| }; | ||
| const int EntityCategories::maskEnumCount = sizeof(EntityCategories::maskEnums) / sizeof(const EntityCategories::CategoriesMask); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this an unsigned int.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call this |
||
|
|
||
| EntityCategories::EntityCategories(CategoriesMask categoriesMask) | ||
| { | ||
| m_categoriesMask = categoriesMask; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,14 @@ | |
| MobCategory MobCategory::monster = MobCategory(EntityCategories(EntityCategories::MONSTER), 10, 20, nullptr, false); | ||
| MobCategory MobCategory::creature = MobCategory(EntityCategories(EntityCategories::ANIMAL), 10, 15, nullptr, true); | ||
| MobCategory MobCategory::waterCreature = MobCategory(EntityCategories(EntityCategories::WATER_ANIMAL), 5, 10, nullptr, true); | ||
| const MobCategory MobCategory::values[] = { | ||
| MobCategory::monster, | ||
| MobCategory::creature, | ||
|
|
||
| const MobCategory* MobCategory::all[] = { | ||
| &MobCategory::monster, | ||
| &MobCategory::creature, | ||
| //MobCategory::waterCreature | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add ampersand within comment. |
||
| }; | ||
| const int MobCategory::numValues = sizeof(MobCategory::values) / sizeof(MobCategory); | ||
|
|
||
| const int MobCategory::allCount = sizeof(MobCategory::all) / sizeof(const MobCategory*); | ||
|
|
||
| MobCategory::MobCategory(const EntityCategories& baseType, int unknown, int max, const Material* material, bool friendly) | ||
| : m_baseType(baseType) | ||
|
|
@@ -27,15 +29,3 @@ void MobCategory::initMobCategories() | |
| MobCategory::creature.m_pSpawnPositionMaterial = Material::air; | ||
| MobCategory::waterCreature.m_pSpawnPositionMaterial = Material::water; | ||
| } | ||
|
|
||
| MobCategory& MobCategory::GetCategoryByIndex(MobCategory::ID i) | ||
| { | ||
| switch (i) | ||
| { | ||
| case MobCategory::CREATURE: | ||
| return MobCategory::creature; | ||
| case MobCategory::MONSTER: | ||
| default: | ||
| return MobCategory::monster; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,8 @@ Mob* MobFactory::CreateMob(EntityType::ID entityType, Level *level) | |
| } | ||
| } | ||
|
|
||
| void MobFactory::initMobLists() { | ||
| void MobFactory::initMobLists() | ||
| { | ||
| // format: ID, spawnrate | ||
|
|
||
| monsterList.insert(std::make_pair(EntityType::SPIDER, 10)); | ||
rep-stosd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -59,9 +60,11 @@ void MobFactory::initMobLists() { | |
| waterCreatureList.insert(std::make_pair(EntityType::SQUID, 10)); | ||
| } | ||
|
|
||
| const std::map<EntityType::ID, int>& MobFactory::GetMobListOfCategory(EntityCategories::CategoriesMask category) { | ||
| return category == EntityCategories::MONSTER ? monsterList : | ||
| category == EntityCategories::ANIMAL ? creatureList : | ||
| const std::map<EntityType::ID, int>& MobFactory::GetMobListOfCategory(const EntityCategories& category) | ||
| { | ||
| EntityCategories::CategoriesMask mask = category.getCategoryMask(); | ||
| return mask == EntityCategories::MONSTER ? monsterList : | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be better as a map or a switch statement, just a suggestion.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to be fetching the mask manually, you can just compare the |
||
| mask == EntityCategories::ANIMAL ? creatureList : | ||
| nullCreatureList; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -772,8 +772,14 @@ void Level::setTilesDirty(const TilePos& min, const TilePos& max) | |
|
|
||
| void Level::entityAdded(Entity* pEnt) | ||
| { | ||
| // save for a bit | ||
| EntityCategories::CategoriesMask mask = pEnt->getDescriptor().getCategories().getCategoryMask(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't bother fetching the |
||
| m_entityTypeCounts[mask]++; | ||
| for (int i = 0; i < EntityCategories::maskEnumCount; i++ ) | ||
| { | ||
| EntityCategories::CategoriesMask category = EntityCategories::maskEnums[i]; | ||
| if ((mask & category) == category) | ||
| m_entityCountsByCategory[category]++; | ||
| } | ||
|
|
||
| for (std::vector<LevelListener*>::iterator it = m_levelListeners.begin(); it != m_levelListeners.end(); it++) | ||
| { | ||
|
|
@@ -786,7 +792,12 @@ void Level::entityAdded(Entity* pEnt) | |
| void Level::entityRemoved(Entity* pEnt) | ||
| { | ||
| EntityCategories::CategoriesMask mask = pEnt->getDescriptor().getCategories().getCategoryMask(); | ||
rep-stosd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| m_entityTypeCounts[mask]++; | ||
| for (int i = 0; i < EntityCategories::maskEnumCount; i++ ) | ||
| { | ||
| EntityCategories::CategoriesMask category = EntityCategories::maskEnums[i]; | ||
| if ((mask & category) == category) | ||
| m_entityCountsByCategory[category]--; | ||
| } | ||
|
|
||
| for (std::vector<LevelListener*>::iterator it = m_levelListeners.begin(); it != m_levelListeners.end(); it++) | ||
| { | ||
|
|
@@ -1950,7 +1961,7 @@ float Level::getSunAngle(float f) const | |
| return (float(M_PI) * getTimeOfDay(f)) * 2; | ||
| } | ||
|
|
||
| int Level::countInstanceOfType(EntityCategories::CategoriesMask category) | ||
| int Level::getEntityCount(const EntityCategories& category) | ||
| { | ||
| return m_entityTypeCounts[category]; | ||
| return m_entityCountsByCategory[category.getCategoryMask()]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still not sure how indexing by a bitmask would allow this to work correctly. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,7 +195,7 @@ class Level : public LevelSource | |
| bool hasNeighborSignal(const TilePos& pos) const; | ||
|
|
||
|
|
||
| int countInstanceOfType(EntityCategories::CategoriesMask); | ||
| int getEntityCount(const EntityCategories&); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this return an unsigned int. |
||
|
|
||
| #ifdef ENH_IMPROVED_SAVING | ||
| void saveUnsavedChunks(); | ||
|
|
@@ -236,6 +236,6 @@ class Level : public LevelSource | |
| PathFinder* m_pPathFinder; | ||
| MobSpawner* m_pMobSpawner; | ||
|
|
||
| std::map<EntityCategories::CategoriesMask, int> m_entityTypeCounts; | ||
| std::map<EntityCategories::CategoriesMask, int> m_entityCountsByCategory; | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this
all