Commit Graph

46 Commits

Author SHA1 Message Date
Aivean 3bb438ff82 change map::remove_field to mark fields as "not alive" deferring their actual removal to the map::process_fields_in_submap
fixes crash in  map::player_in_field (#47308)
2021-02-07 21:31:05 -08:00
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00
Aivean ab52ccb646 fix fd_flame_burst intensity (required by fd_fire_vent)
add new unit tests for fields
2021-01-26 19:34:46 -08:00
Squishums bddb708d67 Fixes activity zone sorting for comestibles in containers. (#45453) 2020-11-27 00:39:52 -08:00
Ivan Zaitsev 163fc540ed Refactored vision_test for extensibility (#44216)
* introduce `map_test_case`: a framework that simplifies tile-setting tests
refactor vision_test.cpp using `map_test_case` framework
add new vision test with thick smoke

* fix clang-tidy warnings

* another clang-tidy fix

* remove mutations that potentially affect vision

* narrow the scope of the overloaded operators
2020-10-02 13:01:44 +03:00
John Bytheway 0fa34012ec Clear z == -1 in tests
The vehicle ramp tests rely on z == -1 being clear, so make sure it is.
2020-08-25 22:01:13 -04:00
Kevin Granade aed0962ad4 [READY] Prevent assertions from hiding failures on mingw-w64 builds. (#42970) 2020-08-20 10:22:11 +03:00
Kevin Granade c5ccf0c2c7 IWYU for tests (#42806) 2020-08-09 09:46:57 +03:00
Kevin Granade 84c5309325 Extract position getter and setters to a facet (#42291) 2020-07-27 02:00:27 +03:00
Kevin Granade 04971e0571 Migrate map references part ten 2020-07-01 23:45:09 +00:00
John Bytheway 9b62400244 Also clear items in clear_map
Failing to do so could break the crafting tests because extra items
might be available for crafting nearby, thus causing the crafting code
to need to ask the player which one to use (which triggers UI code which
aborts in test mode, since there's no UI).
2020-04-13 19:42:14 -04:00
John Bytheway 091e0a40f2 Dedupe clear_vehicles code in map_helpers
There were two implementations of vehicle clearing in map_helpers.cpp.
Refactor them into a single implementation.
2020-04-13 19:42:14 -04:00
John Bytheway e189957ff2 Run IWYU 20200408 (#39364)
* Helper script to run IWYU

* Run IWYU

* Update deprecated headers

* Run IWYU again

* Re-suppress cxxabi.h

This pragma got accidentally removed because it was deemed to be a
comment attached to a #include.

* Remove extra SDL header includes

* Fix ime.cpp headers

Some tweaks to help IWYU not break this file by messing with
platform-specific stuff not relevant on Linux.

* Update game.h

* Move new point.h includes inside #ifdef

* Re-add platform_win.h to mapsharing.cpp

* Apply suggestions from code review

Co-authored-by: ZhilkinSerg <ZhilkinSerg@users.noreply.github.com>
2020-04-10 12:16:19 +03:00
Eric Pierce 37f7fd299a Refactor clear_vehicles and build_test_map
Move both to map_helpers
2020-04-02 21:32:43 -06:00
BevapDin 2a77c82fc3 Remove special placing of monsters for testing.
`game::place_critter` does not "upgrades the monster instantly" anymore. That must be done explicitly.
2019-09-28 22:46:45 +02:00
BevapDin 3a8067f85a Remove game::add_zombie
Call `game::place_critter_at` instead and fast-forward the existing monster by calling `monster::on_load`.
Note that the remaining code from `game::add_zombie` has been moved into `monster::on_load`.
Also note that `monster::spawn` is called from within `place_critter_at`, so the caller does not have to call it.
2019-09-28 22:46:45 +02:00
BevapDin 0be46a7f93 Change game::add_zombie to take a shared_ptr
Change `Creature_tracker::add` accordingly.

Changes the handling of mounted creatures while vertical shifts:
- removes the mount manually to avoid it despawning into the map (and reloading later when the player comes back).
2019-09-28 22:46:45 +02:00
ZhilkinSerg 9d571156a6 Used field type class 2019-07-02 18:49:24 -07:00
John Bytheway 4321c025d2 IWYU 20190629 (#31990)
* Add IWYU pragma: keep

* Run IWYU and astyle

* Run IWYU a second time

* Prevent #include <cxxabi.h>

Unclear why IWYU thinks this is needed.  It isn't, and it causes
problems on Visual Studio.
2019-07-01 12:25:53 +03:00
ZhilkinSerg 97c10768f7 Normalize function names 2019-06-13 14:53:13 -07:00
John Bytheway f3049e5eea Fix missing declarations (#30739)
* Fix missing declarations
Mark functions with no prior declarations as static, and remove the
unused ones.
* Move debug_is_safe_string definition
Put it inside !WIN32 since it's only used there.
2019-05-22 11:00:54 -07:00
KorGgenT f42afc59d4 test includes 2019-05-21 10:25:49 -04:00
John Bytheway 2babc88e9c Clear sky in wipe_map_terrain
For reliable vision tests we need to clear out things in zlevels above
zero to avoid shadows.

Adding that functionality to wipe_map_terrain so that it affects all
tests.

This has some modest performance impact, but I don't think it's too bad.
2019-05-17 10:33:20 +01:00
John Bytheway aff4636618 Run IWYU
Having refactored the type ids into a single header, IWYU is now able to
find many places where other headers can be removed.
2019-05-06 22:47:10 +01:00
John Bytheway cb803be6ea map_helpers: tidy up dead NPCs
In clear_npcs, use game::cleanup_dead to deal with dead NPCs.  This is
important so that g->num_creatures() returns the correct value, which is
checked by some tests.

This also removes them from the overmapbuffer, so we no longer need to
do that separately in this function.
2019-05-05 22:19:44 +01:00
John Bytheway a0ddd0e07f Don't call unload_npcs from tests
Removing the NPCs this way is error-prone, because they still exist but
aren't in the caches, so other game entities can't find them.  Better to
just remove them entirely.
2019-05-05 10:38:24 +01:00
Kevin Granade 7b07949373 Merge pull request #30127 from jbytheway/fix_mingw_monster_error
clear_npcs in monster test
2019-05-01 14:39:26 -07:00
John Bytheway f525187474 Unboard passengers when detaching vehicles 2019-05-01 20:29:44 +01:00
John Bytheway 581edb581b Fix various clear_map issues
After #30051 clear_creatures no longer clears NPCs.  Add a call to do
that in these tests where it is needed.

Also, in clear_map, remove NPCs before vehicles to avoid unboarding
errors (as already hinted at in npc_test.cpp).

Simplify npc_test to use the new improved clear_map.

Ultimately, this is all a workaround for the fact that vehicle detaching
does not properly mark NPCs as not in the vehicle.  That should also be
fixed.
2019-05-01 09:43:26 +01:00
ZhilkinSerg 97f18abad3 Do not rebuild map cache when it is not necessary (#29747)
* Map cache invalidation
2019-05-01 00:26:42 -07:00
John Bytheway 79448f96b9 Use clear_npcs in clear_map (#30051)
* Use clear_npcs in clear_map

clear_map had a similar flaw to the one fixed in #30031 affecting
npc_can_target_player.  Fix it in the same way.

This wasn't obviously affecting any tests, but it makes sense to fix it
pre-emptively.

* Before killing npcs, ensure correct ones loaded

Some tests
(default_overmap_generation_has_non_mandatory_specials_at_origin)
overwrite overmaps, which leads to orphaned NPCs.  Unloading and
reloading the NPCs ensures that all the active NPCs are known to the
overmap.
2019-04-29 20:11:24 -07:00
John Bytheway 8533048196 Properly clear NPCs in NPC tests
The npc_can_target_player test was sometimes failing due to the hostile
NPC choosing to target another NPC instead of the player.

This, in turn, was caused by the clearing of NPCs not being done
properly.  They were unloaded, but then loaded again, and not all were
killed.

Write a new clear_npcs in map_helpers.h which works more reliably, and
call that instead.
2019-04-28 13:35:11 -07:00
John Bytheway e3e7700aef Apply IWYU changes
This is a run of IWYU followed by astyle.
2019-04-22 11:42:51 +01:00
John Bytheway 025a91d646 Clear traps in test clear_map helper
Without this, monsters in the monster speed tests would sometimes get
caught in traps which caused those tests to fail.
2019-01-30 20:06:23 +00:00
ZhilkinSerg c0bce91fa1 Used const where appropriate 2019-01-06 23:00:08 +03:00
John Bytheway 8b0577ea95 Fix map_clear field clearing (#26785)
Was clearing the wrong z-levels, due to not understanding how
OVERMAP_DEPTH worked.

Clearing all of them is rather slow, so just clear the most relevant
ones.
2018-11-21 04:44:22 +00:00
John Bytheway f6af1d1c79 Tidy up map helpers
The clear_map function also moved the player to level -2, which is a
little surprising.  Move that functionality out to a new function.

For each of the places using clear_map, pick either the new or old
version to use as appropriate.

Also, clear fields in clear_map.
2018-11-16 22:32:27 +00:00
John Bytheway 2608c7f95c Test helper to clear fields from map 2018-11-16 22:32:27 +00:00
Kevin Granade bfb222ba5f Make vehicle handling in tests a little more robust. 2018-03-15 02:38:43 +00:00
BevapDin 1df002bb1f Encapsulate some access to game::active_npc
Specifically iterating over all the active npcs is now done via a dedicated `npc_range`.

Also adds a function `game::get_npcs_if` similar to `game::get_creatures_if`.
2017-11-17 19:40:26 -08:00
Kevin Granade 3f0ee83241 Extract creature clearing to its own helper. 2017-10-24 02:59:55 +00:00
Kevin Granade 2e2bee04ff Merge remote-tracking branch 'origin/pr/22101'
* origin/pr/22101:
  Change projectile bouncing to consider all creatures around.
  Remove unused function game::zombie
  Replace game::num_zombies with game::num_creatures
  Move removing dead monsters from the tracker into Creature_tracker.
  Implement monster/creature iterator:
  Call game::get_creature_if instead of iterating over all monsters manually.
  Call game::get_creatures_if to get all matching monsters
  Change mfactions to contain monster pointers instead of indizes
  Avoid repeated calls to game::zombie
  Use vector of pointers instead of indizes in mattack::upgrade.
  Move get_creatures_if into class game.
  Change game::despawn_monster to take the monster as reference
2017-10-16 00:55:39 +00:00
BevapDin 72f0564b63 Implement monster/creature iterator:
Instead of calling `game::num_zombies` and iteration of the range of valid monster indizes and getting the monster references via `game::zombie`, use a range class with iterator interface and range-based for loops.

Code like this:
`
for( size_t i = 0; i < g->num_zombies(); ++i ) {
	monster &critter = g->zombie( i );
	...
}
`
becomes this:
`
for( monster &critter : g->all_monsters() ) {
	...
}
`

The later is much easier to read and to understand.
2017-10-07 22:28:03 +02:00
BevapDin fe5bc004c0 Remove game::mon_at
Change `Creature_tracker::find` to take the position of the monster instead. So instead of calling `mon_at` and passing the returned index to `find`, one calls `find` directly and gets the same data out of it.

Only three places called `game::mon_at`:
- `game::critter_at`: the code of `mon_at` has been inlined there.
- `game::shared_from`: it calls `Creature_tracker::find` with the position now.
- `game::serialize`: two functions `temporary_id` and `from_temporary_id` replace it here.
2017-10-01 17:05:12 +02:00
BevapDin 3b0c8d7d23 Change game::remove_zombie to take a monster reference
Instead of its index.

Also change the matching function in `Creature_tracker` consistently.
2017-10-01 17:05:09 +02:00
Kevin Granade 41fe5bdc92 Extract map test helpers to a seperate module. 2017-09-26 06:42:12 +00:00