Various cleanups.
* Added and cleaned up comments.
* Added checks to prevent map server crashes.
* Cleaned up some reports from CPPCheck.
* Other various stylization cleanups.
Various cleanups.
* Updated comments for chat.c and pet.c files.
* Cleaned up various other comments and stylization.
Item Updates:
* Changed type of some box-type items, from '11' to '18'
* Corrected some Aegis names
* Uncommented some item packages
* Updated item_db_re.sql file

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
Pathfinding now works exactly as on the client
- This should solve most of the position lag problems, especially ones that caused monsters to suddenly appear next to you (happened especially often when using icewall)
- Added a new heap implementation to db.h (POP2, PUSH2, SIFTUP, SIFTDOWN, UPDATE) that simulates the heap that the client uses, there was no other way to reproduce 100% exact behavior
- I recommend using the old heap implementation for everything else
- Updated path.c to use the new heap macros and also fixed the order in which the different possible directions are pushed into heap
- Special thanks to rversteegen for helping me with various tests and the heap implementation
- Special thanks to ultramage for providing info that helped us narrowing down the possible variables
Monster skill use behavior, ranges, position lag fixes
- Updated monster skill use behavior so monsters use skills the same way and at the same rhythm as official servers (bugreport:009326), the changes include:
 * Unified the "monster can't move by default" and the "monster trapped" code as it really should behave exactly the same
 * Fixed a bug that caused the "monster skill use" routine to be called 20 times more often than it should in some situations
 * When a monster attacks you and you run away from it, the monster will now check if it has a ranged skill on "attack" state before switching to chase state
 * Monsters will now always do a normal attack before using "attack" state skills
 * Fixed a bug that caused monsters to switch to idle mode and never use their chase skills when they get hit continuously
 * Changed default for skillrange_from_weapon from 30 (all but player) to 0 (none); monsters will now use all skills at the skill range and not at their own attack range, if they get tanked from farther away than skill range, they won't use these skills
- Updated ranges to work as on official servers (bugreport:009326), the changes include:
 * Implemented new functions "check_distance_client" and "distance_client", that instead of the server-sided square range system use the circular one that the client uses; these functions should be used for units that send their commands via the client (players mostly)
 * Applied the new distance algorithm to some player-specific range checks, players will now have a circular attack range that reflects their attack range on the client; this makes it impossible to hack the client for more diagonal range
 * Removed the arbitrary +1 range bonus at range checks; as monsters now react fluently, they won't need it anymore, that means a monster with for example 4 attack range will now only attack targets within a 9x9 area around it, the moment you step out of this area, the attacks will stop (if the monster can move it will follow you); as for players, the extra cell attack range when on a linear line to the target now is integrated into the distance algorithm, that means a player with attack range 4 can attack from 5 cells away when directly on line with a monster, but no longer diagonally as range is circular for players now
 * Implemented a new "step action" feature to reflect official chase range behavior; when an attack or skill is used inside the attack range, it will act exactly as now, the skill is used once the signal from the client was received; however, if an attack or skill is used outside the attack range, the player should move into the chase area which is 1 cell inside the attack range border; the client actually sends us where to use the attack / skill from, but previously we just dropped that information the moment an attack request came; now instead of stopping the player instantly on an attack request, the player will continue moving to the target cell and then automatically use the command received earlier (it will be remembered); this change was absolutely necessary as the client sends the attack request slightly before attack range is reached, execution on official servers only takes place on every full cell moved; the new system copies this behavior
- Implemented an improved hit-lock system (bugreport:007460), the changes include:
 * MVPs are no longer immune to being stopped by a hit unless they used Endure
 * When hitting any unit, it will stop for its "dMotion" interval, exactly at the end of "dMotion" it will continue walking (official behavior); this helps getting more "move" packets to be displayed
 * The unit that was hit will be immune to being stopped for another "dMotion" interval, this allows to slow down any units by hitting them frequently, but makes it almost impossible to completely stop them forever (depends a lot of ASPD and dMotion value); this does not affect special hit-lock properties (some skills and events should set delay anyway)
 * The unit that was hit will no longer be "pulled" to the next cell; this caused a lot of position lag, it should be much better now
- Fixed Sightrasher missing its variable cast time in Renewal
Code optimization and bug fixes
- Removed redundant code
- Fixed two small bugs in the distance_client calculation
- Improved the "step action" system added in the last commit
  * Added a "unit_step_timer" that is now used for all step actions; now even skills will always be executed at "full cell" (if you don't lag)
  * The "step action" system will no longer mess with anything and rather just call the normal attack/skill functions that are also called by the client; this removes a lot of unneeded code and also works a lot better since the existing functions have been bug-tested the most; this also fixes a problem with the "auto-follow if you can't reach target" system
More code optimizations
- Added a new function unit_stop_stepaction which completely cleans up a planned action
- The new function will now be called when a new action request is received and when changing the map
- Removed setting of "chaserange" as part of the step action system as it's no longer used
- Changed check_distance functions to return "bool" rather than "int"
- Special thanks to Cydh for pointing out possible optimizations
Random walking, monster target dropping
- Implemented official behavior for random walking of monsters (bugreport:9340)
  * Updated the interval between walks from 3-6 seconds to 4-5 seconds
  * Added a define MIN_RANDOMWALKTIME that is now used anywhere the interval is applied so it's easier to change
  * Monsters will no longer attempt to walk to the cell they are currently standing on (note: still requires a proper "no cell stacking" implementation)
  * Monsters will only target a cell within a 15x15 area around them
- Moved the "mob_ai" 0x008 configuration setting to mob_unlocktarget, so it applies to all cases of monsters unlocking targets
- Cleaned up the unit_stop_attack and unit_stop_stepaction functions
  * unit_stop_attack now makes sure that the target is always set to 0, even if no attack timer currently exists
  * replaced several calls of unit_set_target that set target to 0 with unit_stop_attack, this is important because the attack timer should always be deleted at the same time the target is set to 0
  * this also fixes the problem that caused monsters to sometimes drop their target after an attack
Minor monster walk and skill use fixes
- Fixed a bug that caused monsters to never use their idle skills even if the define MOB_LAZYSKILLPERC was set
* The default value of the define is now 100% for spotted mobs and 0% for non-spotted mobs as on official servers
* On officials, spotted monsters also use skills when nobody is on the map (healing up, metamorphing), but I decided to not implement this out of performance reasons for now; needs to be discussed as this would prevent the exploit of players leaving the map to heal up SP and then coming back to kill an MVP
- Monsters now use complex path searching for their random walk, so they can also walk around corners now (OFFICIAL_WALKPATH still applies!)
- Fixed spotted monsters using their "walk" skills even if nobody is on the map
- Monsters will no longer stop when using "walk" skills (they are supposed to be used while walking)
Monster idle skills, chase, final cleanups
- Spotted monsters will now use their idle skills even if no players are on the map
* This is official behavior and allows them to metamorph and heal up even if nobody is on the map
* I originally had concerns about the performance, but as the dynamic mobs option is enabled by default and set to 5 minutes, monsters will only stay "spotted" for 5 minutes when nobody is on the map anyway, this doesn't cost much extra performance
- Increased chase range of monsters by 2
* Tested this thoroughly and the effective chase range is actually 2 cells larger than listed in the "Range3" column
* Special thanks to ultramage and Michieru for helping me testing this
- Some final cleanups in the unit_stop_attack and unit_stop_stepaction functions
* Special thanks to icxbb-xx for pointing these out
MVP item drop mode setting added
- Added a new configuration setting "item_drop_mvp_mode"
* By default "item_drop_mvp_mode" is set to official order (0) which is always starting at first, then going to the second if the first didn't drop and only checking the third if the second didn't drop either
* @mobinfo will now properly consider this and display the effective chance, so if the MVP has 3 MVP item drops at 50%, the first item will display the chance 50%, the second 25% and the third 12.5%, this should help a lot against drop rate confusion (e.g. players wondering why always only the first item drops when all three are displayed at 100%); this only applies to official order (0)
* When "item_drop_mvp_mode" is set to random order (1), MVP item drops are checked in random order, but if one MVP item drops, the process will be canceled, so you will never get more than one MVP item no matter how high the drop rate is
* When "item_drop_mvp_mode" is set to all items (2), all MVP item drops are checked and have a chance to drop, regardless of other MVP items already being dropped or not (i.e. there is a chance that the player gets all 3 MVP items)
Official Icewall implementation and other fixes
- Reverted all the icewall-related changes done in SVN r15777 and following as testing shows they aren't official and are actually pretty exploitable (bugreport:7412)
- Instead implemented the official icewall characteristic that monsters can only leave an icewall cell to the west or south, the changes include:
  * The "sight" path check no longer checks for the current cell so standing on an icewall allows you to see/attack into any direction
  * The path finding will still ignore the current cell as before but the walk routine will not allow to walk east or north while standing on an icewall cell
  * This leads monsters in the situation where they go through an AI loop not allowing them to escape the icewall (if their target is north or east of them)
  * Monster in this situation will use idle skills and if they get attacked will use their rudeattacked skills if available, similar to traps like Spiderweb
  * Added a configuration icewall_walk_block that allows to configure how long a monster should go through the AI loop before the server allows it any movement, this "safety" system is official and seems to equal about 75 AI loops; if you want to disable the whole icewall system so that monsters don't get stuck in icewall at all, just set this to 0
  * Here are videos from jRO showing how this system works: http://ragdo.blog56.fc2.com/blog-entry-763.html
- Implemented the official calculation for "direction"; now you will be considered horizontal/vertical/diagonally aligned with a target cell in the exact same way as on official servers, this is for example used to determine whether an icewall or a firewall should be horizontal, vertical or diagonal; the only thing that is still unofficial is the default direction (officially always "west"); effectively now there are more situations considered diagonal than before
- Fixed a compiler warning (converting double to float)
- Further cleanups on the idle skill use code for immobile monsters and monsters near a player but without a target (now skill using will always go via mob_unlocktarget)
  * This also fixes that monsters switched to idle mode and start to use idle skills one second too late
- Merged config option knockback_left from Hercules
  * Now the default direction is "east" and consequently the knockback direction is "west" when standing
  * This means if the source cell (ground target center or position of caster) is on the same cell as the target, it will be knocked back to the west
  * This also can effect other things like how an object is placed when cast on the cell you are currently standing on
  * If you disable the option it will use the old behavior and use the direction of the unit as default direction (and backwards as knock direction)
  * Special thanks to kisuka and Michieru for the original implementation: https://github.com/HerculesWS/Hercules/commit/2b8d5013ea8ba9904d157c773f12495bbca8ca80
- Optimized the knockback / instant movement code
  * clif_blown will now call both clif_slide and then clif_fixpos, this is what Aegis does when any instant movement effect occurs and ensures proper updating of the position
  * skill_blown will call clif_blown and ensures the correct client information already, so it's no longer necessary to manually call clif_slide and clif_fixpos after it
  * replaced all calls of clif_slide and then clif_fixpos in row with a single call of clif_blown, makes the code look a lot cleaner
  * I tested over 20 knockback situations including knockback of frozen target and it worked fine for me, please report if there is still anything wrong (was why fixpos commented in the first place?)
* Fixed bonus_script doesn't remove Status Icon when timer is over (bugreport:9341)
* Some little code stylization

Signed-off-by: Cydh Ramdh <house.bad@gmail.com>
Small Icewall implementation improvement
- Now monsters will walk into an icewall from the south and west if they already started moving to that cell
  * This will make it slightly easier to trap a monster in an icewall (this is official as can be seen in the videos I linked in the main commit)
  * This only applies if the icewall_walk_block configuration setting was not set to 0 (disabled)
Weapon endow removal updated
- Now weapon endow effects will no longer be removed when unequipping / changing a shield (bugreport:1490)
- Now weapon endow effects will be removed when dual wielding and unequipping / changing one of the two weapons
Corrected Ancient Gold Decoration description (bugreport 9154)

Signed-off-by: Capuche <capucrath@gmail.com>
Bug Fixes
* Fixed Decoration of Music status when equipping the headgear. (bugreport:9342)
* Fixed Warg Dash giving Endure when it shouldn't. (bugreport:9337)
* Fixed Mado Gear skill item requirements. (bugreport:9335)
* Fixed Super Novice Spirit being able to be casted by all classes. (bugreport:9344)
* Fixed Masquerade - Ignorance to work on monsters. (bugreport:8099)
* Fixed Voice of Siren duration depending on level of character. (bugreport:9289)
* Fixed Spirit Sympathy SP requirement reduction when summoning an Element. (bugreport:9329)
Map server crash fixes
- Fixed two parts of the code that could lead to a map server crash
Sight Blaster and other skill fixes, magic reflect, crash, trap display and monster behavior fixes
- Fixed cast time of Sightrasher in pre-renewal (700ms -> 500ms)
- Official Sight Blaster behavior (bugreport:6945, partially bugreport:144)
  * Sight Blaster's AoE is now 3x3 even in pre-renewal (it was originally larger so it hits traps before they trigger)
  * Sight Blaster will now prevent traps from triggering as long as they are knocked back
  * Fixed a bug that caused Sight Blaster to not work on traps and ice walls at all
  * Sight Blaster will no longer expire when the attack was reflected
  * Sight Blaster will now expire when hitting an ice wall
  * Sight Blaster will now properly protect you from being attacked from its AoE range
- Sight, Ruwach and Sight Blaster will now check for a target every 20ms (previously every 250ms)
- Step action will now be canceled when being knocked back (skills won't be executed anymore when knocked out of range)
- When knock back magic is reflected it will no longer lead to the caster being knocked back (related to bugreport:6945)
- Activated traps can no longer be hit
- Fixed a problem that left "trap ghosts" forever on the screen when a trap was knocked out of the screen
- Fixed three more potential map server crashes
- Monster behavior fixes
  * Monsters will no longer be able to do normal attacks when hiding
  * If out of any reason a monster on "attack" state can't move and can't do normal attacks, it will now use "attack" state skills
  * The order of monster thought processing is now equal to official servers