@ -146,11 +146,14 @@ void System::motion(GameLevel &level) {
} ) ;
} ) ;
}
}
void System : : distribute_loot ( GameLevel & level , Entity & ent ) {
void System : : distribute_loot ( GameLevel & level , Position target_pos ) {
auto & world = * level . world ;
auto & world = * level . world ;
// BUG: I constantly open a config when I have GameConfig already
auto & config = world . get_the < GameConfig > ( ) ;
auto & config = world . get_the < GameConfig > ( ) ;
int inventory_count = Random : : uniform ( 0 , 3 ) ;
if ( inventory_count > 0 ) {
// do a clone of the things we need, like Position
auto junk_entity = world . entity ( ) ;
ritual : : JunkPile pile ;
ritual : : JunkPile pile ;
auto & junk = config . rituals [ " junk " ] ;
auto & junk = config . rituals [ " junk " ] ;
@ -160,8 +163,6 @@ void System::distribute_loot(GameLevel &level, Entity& ent) {
select_from . contents . push_back ( el . key ( ) ) ;
select_from . contents . push_back ( el . key ( ) ) ;
}
}
int inventory_count = Random : : uniform ( 0 , 3 ) ;
if ( inventory_count > 0 ) {
for ( int i = 0 ; i < inventory_count ; i + + ) {
for ( int i = 0 ; i < inventory_count ; i + + ) {
size_t max_junk = select_from . contents . size ( ) ;
size_t max_junk = select_from . contents . size ( ) ;
auto & item = select_from . contents . at ( Random : : uniform ( size_t ( 0 ) , max_junk - 1 ) ) ;
auto & item = select_from . contents . at ( Random : : uniform ( size_t ( 0 ) , max_junk - 1 ) ) ;
@ -169,13 +170,16 @@ void System::distribute_loot(GameLevel &level, Entity& ent) {
}
}
auto entity_data = config . devices [ " GRAVE_STONE " ] ;
auto entity_data = config . devices [ " GRAVE_STONE " ] ;
components : : configure_entity ( world , ent , entity_data [ " components " ] ) ;
components : : configure_entity ( world , junk_ entity , entity_data [ " components " ] ) ;
world . set < ritual : : JunkPile > ( ent , pile ) ;
world . set < ritual : : JunkPile > ( junk_ entity , pile ) ;
// BUG: inventory_count here isn't really used to remove it
// BUG: inventory_count here isn't really used to remove it
world . set < InventoryItem > ( ent , { inventory_count , entity_data } ) ;
world . set < InventoryItem > ( junk_entity , { inventory_count , entity_data } ) ;
world . set < Position > ( junk_entity , target_pos ) ;
level . collision - > insert ( target_pos . location , junk_entity ) ;
level . world - > send < Events : : GUI > ( Events : : GUI : : ENTITY_SPAWN , junk_entity , { } ) ;
} else {
} else {
dbc : : log ( " DEAD BODY NOT IMPLEMENTED, for now just removing enemy " ) ;
dbc : : log ( " DEAD BODY NOT IMPLEMENTED, for now just removing enemy " ) ;
remove_from_world ( level , ent ) ;
level . collision - > remove ( target_pos . location ) ;
// BUG: should maybe add a component to the world for "dead thing no loot" that
// BUG: should maybe add a component to the world for "dead thing no loot" that
// has no collision or goes away after some kind of animation
// has no collision or goes away after some kind of animation
// Something like:
// Something like:
@ -215,22 +219,18 @@ void System::death(GameLevel &level) {
// NOTE: this could be a separate system but also could be a function in
// NOTE: this could be a separate system but also could be a function in
// components::
// components::
for ( auto ent : dead_things ) {
for ( auto ent : dead_things ) {
// remove their enemy setting
world . remove < Motion > ( ent ) ;
world . remove < Combat > ( ent ) ;
world . remove < EnemyConfig > ( ent ) ;
world . remove < Personality > ( ent ) ;
world . remove < ai : : EntityAI > ( ent ) ;
world . remove < Animation > ( ent ) ;
world . remove < SpriteEffect > ( ent ) ;
world . remove < Sprite > ( ent ) ;
if ( auto snd = world . get_if < Sound > ( ent ) ) {
if ( auto snd = world . get_if < Sound > ( ent ) ) {
sound : : stop ( snd - > attack ) ;
sound : : stop ( snd - > attack ) ;
sound : : play ( snd - > death ) ;
sound : : play ( snd - > death ) ;
}
}
System : : distribute_loot ( level , ent ) ;
auto pos = world . get < Position > ( ent ) ;
// NOTE: distribute loot is responsible for either removing or replacing
// the collision for this entity. It has to do this since it's determining
// if a junkpile goes there or nothing
System : : distribute_loot ( level , pos ) ;
world . destroy ( ent ) ;
}
}
}
}
@ -332,6 +332,10 @@ void System::collision(GameLevel &level) {
}
}
}
}
/*
* This isn ' t for destroying something , but just removing it
* from the world for say , putting into a container or inventory .
*/
void System : : remove_from_world ( GameLevel & level , Entity entity ) {
void System : : remove_from_world ( GameLevel & level , Entity entity ) {
auto & item_pos = level . world - > get < Position > ( entity ) ;
auto & item_pos = level . world - > get < Position > ( entity ) ;
level . collision - > remove ( item_pos . location ) ;
level . collision - > remove ( item_pos . location ) ;