Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/lvl_script_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
*/
/******************************************************************************/
#include "pre_inc.h"
#include "lvl_script_lib.h"
#include "lvl_script_conditions.h"
#include "lvl_script_commands.h"

#include "globals.h"
#include "thing_factory.h"
#include "thing_physics.h"
#include "thing_navigate.h"
#include "config_creature.h"
#include "creature_states_pray.h"
#include "dungeon_data.h"
#include "gui_msgs.h"
#include "lvl_filesdk1.h"
#include "creature_states_pray.h"
#include "lvl_script_lib.h"
#include "lvl_script_conditions.h"
#include "lvl_script_commands.h"
#include "magic_powers.h"
#include "config_creature.h"
#include "gui_msgs.h"
#include "room_util.h"
#include "thing_factory.h"
#include "thing_navigate.h"
#include "thing_physics.h"

#include "post_inc.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -117,6 +119,16 @@ struct Thing *script_process_new_object(ThingModel tngmodel, MapSubtlCoord stl_x
case ObjMdl_GoldBag:
thing->valuable.gold_stored = arg;
break;
default:
struct ObjectConfigStats* objst = get_object_model_stats(tngmodel);
if (objst->genre == OCtg_GoldHoard)
{
if (arg > 0)
{
thing->valuable.gold_stored = arg;
}
check_and_asimilate_thing_by_room(thing);
}
}
return thing;
}
Expand Down
3 changes: 2 additions & 1 deletion src/room_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -2938,7 +2938,7 @@ void kill_room_contents_at_subtile(struct Room *room, PlayerNumber plyr_idx, Map
{
struct Thing *gldtng;
gldtng = find_gold_hoard_at(stl_x, stl_y);
if (!thing_is_invalid(gldtng))
while (!thing_is_invalid(gldtng)) //Normally there is just a single hoard at a slab, but mapmakers may place more.
{
room->capacity_used_for_storage -= gldtng->valuable.gold_stored;
dungeon = get_dungeon(plyr_idx);
Expand All @@ -2947,6 +2947,7 @@ void kill_room_contents_at_subtile(struct Room *room, PlayerNumber plyr_idx, Map
}
drop_gold_pile(gldtng->valuable.gold_stored, &gldtng->mappos);
delete_thing_structure(gldtng, 0);
gldtng = find_gold_hoard_at(stl_x, stl_y);
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions src/room_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ void change_slab_owner_from_script(MapSlabCoord slb_x, MapSlabCoord slb_y, Playe
* @note Used capacity of the room don't have to be updated here, as it is re-computed later.
* @return True if the thing was either assimilated or left intact, false if it was deleted.
*/
short check_and_asimilate_thing_by_room(struct Thing *thing)
TbBool check_and_asimilate_thing_by_room(struct Thing *thing)
{
struct Room *room;
if (thing_is_dragged_or_pulled(thing))
Expand All @@ -418,10 +418,18 @@ short check_and_asimilate_thing_by_room(struct Thing *thing)
if (thing_is_gold_hoard(thing))
{
room = get_room_thing_is_on(thing);
long wealth_size_holds = game.conf.rules[room->owner].game.gold_per_hoard / get_wealth_size_types_count();
unsigned long gold_value = wealth_size_holds * max(1, get_wealth_size_of_gold_hoard_object(thing));
unsigned long value_left;
unsigned long value_added;
GoldAmount wealth_size_holds = game.conf.rules[room->owner].game.gold_per_hoard / get_wealth_size_types_count();
GoldAmount gold_value = thing->valuable.gold_stored;
if (gold_value == 0)
{
gold_value = wealth_size_holds* max(1, get_wealth_size_of_gold_hoard_object(thing));
}
else
{
thing->valuable.gold_stored = 0;
}
GoldAmount value_left;
GoldAmount value_added;
if (room_is_invalid(room) || !room_role_matches(room->kind, RoRoF_GoldStorage))
{
// No room - delete it, hoard cannot exist outside treasure room
Expand Down
2 changes: 1 addition & 1 deletion src/room_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void process_rooms(void);
TbBool delete_room_slab(MapSlabCoord slb_x, MapSlabCoord slb_y, TbBool is_destroyed);
TbBool replace_slab_from_script(MapSlabCoord slb_x, MapSlabCoord slb_y, unsigned char slabkind);
void change_slab_owner_from_script(MapSlabCoord slb_x, MapSlabCoord slb_y, PlayerNumber plyr_idx);
short check_and_asimilate_thing_by_room(struct Thing *thing);
TbBool check_and_asimilate_thing_by_room(struct Thing *thing);
EventIndex update_cannot_find_room_of_role_wth_spare_capacity_event(PlayerNumber plyr_idx, struct Thing *creatng, RoomRole rrole);
void query_room(struct Room *room);
/******************************************************************************/
Expand Down
6 changes: 3 additions & 3 deletions src/thing_objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ GoldAmount add_gold_to_treasure_room_slab(MapSlabCoord slb_x, MapSlabCoord slb_y
return gold_store;
}

long gold_being_dropped_at_treasury(struct Thing *thing, struct Room *room)
GoldAmount gold_being_dropped_at_treasury(struct Thing *thing, struct Room *room)
{
GoldAmount gold_store = thing->valuable.gold_stored;
{
Expand Down Expand Up @@ -1967,7 +1967,7 @@ struct Thing *create_gold_hoarde(struct Room *room, const struct Coord3d *pos, G
* @param amount Amount of gold to be added.
* @return Gives amount really added to the hoard.
*/
long add_gold_to_hoarde(struct Thing *gldtng, struct Room *room, GoldAmount amount)
GoldAmount add_gold_to_hoarde(struct Thing *gldtng, struct Room *room, GoldAmount amount)
{
GoldAmount wealth_size_holds = game.conf.rules[room->owner].game.gold_per_hoard / get_wealth_size_types_count();
GoldAmount max_hoard_size_in_room = wealth_size_holds * room->total_capacity / room->slabs_count;
Expand Down Expand Up @@ -2019,7 +2019,7 @@ long add_gold_to_hoarde(struct Thing *gldtng, struct Room *room, GoldAmount amou
* @param amount Amount of gold to be taken.
* @return Gives amount really taken from the hoard.
*/
long remove_gold_from_hoarde(struct Thing *gldtng, struct Room *room, GoldAmount amount)
GoldAmount remove_gold_from_hoarde(struct Thing *gldtng, struct Room *room, GoldAmount amount)
{
if (amount <= 0) {
return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/thing_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ int get_wealth_size_types_count(void);
struct Thing *create_gold_hoard_object(const struct Coord3d *pos, PlayerNumber plyr_idx, GoldAmount value);
struct Thing *find_gold_hoard_at(MapSubtlCoord stl_x, MapSubtlCoord stl_y);
struct Thing *create_gold_hoarde(struct Room *room, const struct Coord3d *pos, GoldAmount value);
long add_gold_to_hoarde(struct Thing *thing, struct Room *room, GoldAmount amount);
long remove_gold_from_hoarde(struct Thing *thing, struct Room *room, GoldAmount amount);
long gold_being_dropped_at_treasury(struct Thing* thing, struct Room* room);
GoldAmount add_gold_to_hoarde(struct Thing *thing, struct Room *room, GoldAmount amount);
GoldAmount remove_gold_from_hoarde(struct Thing *thing, struct Room *room, GoldAmount amount);
GoldAmount gold_being_dropped_at_treasury(struct Thing* thing, struct Room* room);

struct Thing *drop_gold_pile(long value, struct Coord3d *pos);
struct Thing *create_gold_pot_at(long pos_x, long pos_y, PlayerNumber plyr_idx);
Expand Down
Loading