Commit graph

135 commits

Author SHA1 Message Date
ephphatha
13c54102e0 Combine Add*Door functions
There's a bit of common code, but most of the initialisation logic relies on globals or other functions defined in objects.cpp so it's not really appropriate to move these wholesale into a member of the Object class.
2021-12-30 10:26:46 +01:00
ephphatha
279fbe32b3 Tidy up checks for missile collision with objects/tiles
This was repeated in multiple places with essentially identical logic. Can expose the existing missiles.cpp function to capture the use in scrollrt.cpp
2021-12-28 16:01:37 +01:00
ephphatha
77a783098d Use ObjectAtPosition when checking if an item can be dropped
This extracts some of the common object logic from ItemSpaceOk and CanPut, these functions are almost identical except for the way players and monsters are checked...
2021-12-28 16:01:37 +01:00
ephphatha
a0019d289d Use Point based object lookups in themes.cpp
Move bookstand lookup inside coinflip if statement, minimises the scope of that pointer.

Co-authored-by: Anders Jenbo <anders@jenbo.dk>
2021-12-28 16:01:37 +01:00
ephphatha
379d6e87b3 Move ObjectAtPosition to objects.cpp and make it return a pointer
All set maps initialise objects as expected so dObject has the correct ID already, no need to iterate over all active objects. Also by returning a pointer we can use this function to test if an object exists at the target position.

While on msvc int8_t is typedefed to signed char we might as well match the expected data type for the dObject array
2021-12-28 16:01:37 +01:00
Gleb Mazovetskiy
076b0c0c05 Overhaul tests
1. Adds a `libdevilution_so` target when tests are enabled.
2. Each test file is now a separate binary target linked against `libdevilutionx_so` (can now run tests in parallel).
3. Tests are now defined in a separate `test/CMakeLists.txt` file.
4. Building the tests is now controlled by the standard `BUILD_TESTING` option (defined by CTest).
5. Tests are now built by default.
6. On CI, test errors are now reported.

Also:

* `.clang-format`: Enable SortIncludes in tests
* `path_test.cpp`: Fix -Wsign-compare
2021-12-16 20:26:51 +00:00
Gleb Mazovetskiy
7e1fea6f76 clang-format all files in {Source,test}/
Also includes a few manual tweaks to comments and newlines for better results.

Co-authored-by: Anders Jenbo <anders@jenbo.dk>
2021-11-24 23:44:12 +01:00
Andrew James
8104432db4
Use object reference (and self-id lookup) for BreakBarrel 2021-11-08 00:51:16 +01:00
Andrew James
021c7a652f
Add helpers for checking object type (#3357)
* Add helper to test if an object is a trap source
* Add helper to test if an object is a barrel
* Add helper to test if an object is a crucifix
* Add helpers to check if an object is a chest (and statuses)
* Add helpers to check if an object is a (basic) shrine
2021-11-06 18:32:52 +01:00
Andrew James
7dcc6d15f7
Update some quest object activation functions to use references (#3356)
- rename with a hopefully more descriptive name
2021-11-01 15:48:54 +01:00
ephphatha
d2940e8f7f Update GetObjectStr to take a const Object&
Brings it in line with GetItemStr
2021-11-01 12:44:46 +01:00
ephphatha
6d545868d2 Move objectIsDisabled to a member function
While it does reference a global configuration option it's mainly concerned with the properties of the object itself, so makes sense to be a member of the object class.
2021-10-31 14:21:57 +01:00
ephphatha
e98b80c992 Remove declaration of private/anonymous function
Never used outside objects.cpp so it was rightly moved into the anonymous namespace, but the header was not updated at the time.
2021-10-29 14:16:17 +02:00
Juliano Leal Goncalves
ef74b6f92d 🚚 Rename 'ObjectStruct' to 'Object' 2021-09-02 05:45:44 +02:00
Juliano Leal Goncalves
20db8d1a11 🚚 Rename 'MonsterStruct' to 'Monster' 2021-09-01 22:26:37 +02:00
Anders Jenbo
069249f318 🚚 Move local function to anonymous namespace i-p 2021-07-19 05:44:20 +02:00
ephphatha
7de18d27cf Extract door object type test to ObjectStruct method
This removes the direct reference to _object_id values in path.cpp, that enum is now only used in objects.h/cpp
2021-07-17 17:35:58 +02:00
Anders Jenbo
77b72da276 ♻️Use monster by reference when possible 2021-07-14 20:22:35 -07:00
Anders Jenbo
ef6275caac Clean up private function names 2021-07-12 17:59:22 -07:00
ephphatha
a842d07dab Combine duplicated initialisation logic for quest book objects 2021-07-11 05:09:13 -07:00
ephphatha
cc3572af81 Update BookLever related functions to use Rectangle.
This is mainly to help isolate functionality in the hopes of adding a specialised object class for this type of object as suggested by @julealgon in https://github.com/diasurgical/devilutionX/pull/2344#discussion_r667415019

For example, AddSCambBook performs almost the same logic but uses var6 instead of var8 for the trigger condition/identifier.
2021-07-11 05:09:13 -07:00
ephphatha
e25d287ba9 Move SetObjMapRange to a member function
Due to the way this function is used it was easiest to also change ObjIndex to return a reference to the object instead of the index. Also added an explicit conversion from Size to Displacement to make one of the uses slightly cleaner to express.
2021-07-10 19:11:30 -07:00
Andrew James
af60158274
Object by reference in SyncObjectAnimation functions (#2344) 2021-07-10 14:03:44 +02:00
ephphatha
b680e3fef1 Align end comment markers for doxygen comments
Including a bunch from previous PRs (since I was responsible for the broken formatting for most 😓)
2021-07-09 18:00:15 +02:00
ephphatha
19ae61811f Refactor AddObject to take Point instead of int x/y 2021-07-09 17:58:34 +02:00
ephphatha
6f40f0dd88 Refactor ObjSetMicro to take a Point parameter 2021-07-09 18:52:50 +10:00
Anders Jenbo
467b74dc06 Rename object globals 2021-07-08 02:01:14 -07:00
Anders Jenbo
7e737cfa96 Merge remote-tracking branch 'refs/remotes/devilution/master' 2021-07-03 01:44:45 +02:00
Andrew James
20190ee687
Update random number functions to avoid IB (#2226)
* Update random number functions to avoid IB

Most calls to set seed were using uint32_t already, there were a few variables which were better served by having their type changed from signed to unsigned. The one exception is ItemStruct::_iSeed. This is an identifier that also happens to be used as a seed occasionally so a comment was added documenting this exception.

Includes suggested style changes for Source/towners.h; Source/towners.cpp; Source/msg.h; Source/multi.h
2021-06-27 10:37:09 +02:00
Anders Jenbo
790f42d078 Clang-tidy: readability-inconsistent-declaration-parameter-name 2021-06-27 01:06:00 +02:00
Gleb Mazovetskiy
f9f301b054 🚚 engine.h: Extract Point, Direction, clamp
`engine.h` is getting quite bloated. Moves this code to their own files.
2021-06-21 01:36:20 -07:00
ephphatha
0c99ae0206 Add descriptive name and comments for the Na-Krul spell tome check function 2021-06-13 13:54:30 +02:00
Anders Jenbo
9e2206a673 Format code 2021-05-21 14:12:31 +02:00
Anders Jenbo
8eb9c930fe
🚨 Fix remaning GCC warnings (#1929) 2021-05-11 09:34:45 +02:00
Anders Jenbo
f579b2f287 Handle cel/cl2 files as byte arrays 2021-05-06 13:17:54 +02:00
Anders Jenbo
fa0b286693 ♻️Typed file loading
Tthis gives us the option to specify what type a file should be loaded
as, avoidng the need to case it and does some automatic checks on the
fitness of the data, while making the process simpler.

If no type is given then the type will be set to std::byte which limit
what operations can be performed on the data.
2021-05-04 19:08:37 +02:00
obligaron
239a43cc1c
Remove "AnimWidth2" expect for missiles (#1680) 2021-04-25 13:32:33 +02:00
Jmgr
c33182d6de Modernize deprecated headers 2021-04-25 02:50:31 +02:00
Anders Jenbo
2bd13451a1 ♻️Apply point positioning to all remaning entities 2021-04-25 01:25:48 +02:00
Anders Jenbo
7912e510f0 🎨 Clean up overuse of SDL types 2021-04-24 17:07:07 +02:00
Xadhoom
bf908da5bc Add option to disable clicking on character crippling shrines 2021-04-19 12:22:44 +02:00
Anders Jenbo
6e1a106a38 🚚 Move header we implement into the project 2021-04-16 01:04:54 +02:00
Anders Jenbo
f450d6a125 🚚 Move defines to there proper files 2021-04-16 01:04:54 +02:00
Anders Jenbo
61244c4d93 ♻️ Rearange and apply more enums 2021-04-10 05:24:01 +02:00
Anders Jenbo
93d42b62b8 ♻️ Change BOOL to bool 2021-04-09 15:13:02 +02:00
Anders Jenbo
b1ffdca0a3 ♻️ make better use of enums 2021-04-08 20:29:16 +02:00
Anders Jenbo
af96de4038 ♻️ Move a large part of enums to there respective headers 2021-04-08 19:20:55 +02:00
Anders Jenbo
433edc63ea ♻️ Consistently use pragma once to guard the headers 2021-04-06 15:21:25 +02:00
Anders Jenbo
bfb3c11c2b 🎨 Change namespace to devilution 2021-04-06 15:21:25 +02:00
Anders Jenbo
630e507f63 🚚 Apply namespace 2021-04-06 15:21:25 +02:00