Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Pathfind fix for NPC/MOB and poor old Novalmauge #548

Merged
merged 6 commits into from
Nov 15, 2020

Conversation

Omnione
Copy link
Contributor

@Omnione Omnione commented Apr 29, 2020

• Addition of npcBasicPath to pathfind.lua, this pathfind function requires paths to be set in a linear fashion like this example
local path =
{
[1] = {1.000, 2.000, 3.000},
[2] = {2.000, 2.000, 3.000},
[3] = {3.000, 2.000, 3.000},
[4] = {2.000, 2.000, 3.000}
}
This way the path returns to the origin from the last path point to the first, i.e a circle.
the npcBasicPath will keep track of what path point the npc is on by the newly added m_pathPoint in npcentity.

• As stated above i have added a m_pathPoint to npcentity and given the the entity a getter and setter to help keep track of the npc's path.

• Adjusted Novalmauge's script to reflect the changes.

He's walk animation still seems a bit buggy but its about as good as i could get it.
But atleast it shouldn't crash the server anymore.

This should fix the following bug
Novalmauge causes server crash due to pathing. #493

I affirm:

  • that I agree to Project Topaz's Limited Contributor License Agreement, as written on this date
  • that I've tested my code since the last commit in the PR, and will test after any later commits

Copy link
Contributor

@ibm2431 ibm2431 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General question: I assume that setting speed to 0 actually does cease movement and doesn't cause sliding? I remember that being a question in #319

scripts/zones/Bostaunieux_Oubliette/npcs/Novalmauge.lua Outdated Show resolved Hide resolved
src/map/lua/lua_baseentity.cpp Outdated Show resolved Hide resolved
scripts/zones/Bostaunieux_Oubliette/npcs/Novalmauge.lua Outdated Show resolved Hide resolved
scripts/zones/Bostaunieux_Oubliette/npcs/Novalmauge.lua Outdated Show resolved Hide resolved
scripts/zones/Bostaunieux_Oubliette/npcs/Novalmauge.lua Outdated Show resolved Hide resolved
@ibm2431 ibm2431 added reviewed Has been reviewed by at least one Staff Member hold Requests have been made to merge and removed reviewed Has been reviewed by at least one Staff Member labels May 3, 2020
@ibm2431 ibm2431 changed the base branch from release to pathing June 17, 2020 14:44
Omnione added 5 commits June 21, 2020 22:21
• Addition of npcBasicPath to pathfind.lua, this pathfind function requires paths to be set in a linear fashion like this example
local path =
{
    [1] = {1.000, 2.000, 3.000},
    [2] = {2.000, 2.000, 3.000},
    [3] = {3.000, 2.000, 3.000},
    [4] = {2.000, 2.000, 3.000}
}
This way the path returns to the origin from the last path point to the first, i.e a circle.
the npcBasicPath will keep track of what path point the npc is on by the newly added m_pathPoint in npcentity.

• As stated above i have added a m_pathPoint to npcentity and given the the entity a getter and setter to help keep track of the npc's path.

• Adjusted Novalmauge's script to reflect the changes.

Changed setPathPoint to use uint16 rather than uint8

Stupid tabs

Pathing adjustments

• Added the ability to pass rotations
• Moved m_pathPoint to baseEntity
• Addition of npcBasicPath to pathfind.lua, this pathfind function requires paths to be set in a linear fashion like this example
local path =
{
    [1] = {1.000, 2.000, 3.000},
    [2] = {2.000, 2.000, 3.000},
    [3] = {3.000, 2.000, 3.000},
    [4] = {2.000, 2.000, 3.000}
}
This way the path returns to the origin from the last path point to the first, i.e a circle.
the npcBasicPath will keep track of what path point the npc is on by the newly added m_pathPoint in npcentity.

• As stated above i have added a m_pathPoint to npcentity and given the the entity a getter and setter to help keep track of the npc's path.

• Adjusted Novalmauge's script to reflect the changes.
• Added the ability to pass rotations
• Moved m_pathPoint to baseEntity
Added new pathing options for entity's
First up: pathfind.lua, probly quicker to look at the commenting than me explain that,

changed amost npc's that use pathing to use either basicPath or advancedPath, the advancedPath is the one that stands out as this allows the entity to pass id text and npc id's to automatically look at or speak at a a point in the path, and each point can have a delay.

Added random pathing for the bunnies in Khazam, as they just sat there.

I kept everything the same where i could, but i did have to redo some paths, but that let me cut down on path points also.
• Added a new binding rotateToAngle(), rotates an entity to a given angle, NOTE: must not be moving.

• added the ability to add extra params to a path point when using tpz.path.general, example: 
basic point {x,y,z} 
point with a delay {x,y,z {delay = 10}}
point with delay and rotation {x,y,z, {rot = 35, delay = 10}
point with a rotation only {x,y,z {rot = 120}}, in this case a small delay will automatically be set so the rotation can be applied.

• Updated all npc's that now use the new lua path functions and tested them.
@Omnione Omnione changed the title Pathfind fix for Novalmauge Pathfind fix for NPC/MOB and poor old Novalmauge Aug 3, 2020
Copy link
Contributor

@zach2good zach2good left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it all looks good. There are some styling things I'd like to see fixed and in an ideal world, this would have been much easier to go through and review if you had split out the commits to be logic changes, whitespace/semicolon changes, tabling changes etc.

Sick work 👍

Comment on lines 13 to +25
local path =
{
20.6, 0, -23,
46, 0, -19,
53.5, -1.8, -19,
61, -1.1, -18.6,
67.3, -1.5, -18.6,
90, -0.5, -19
};
{20.600, -0.343, -23.000, {delay = 5}},
{35.431, -0.045, -20.227},
{51.795, -1.790, -18.843},
{58.037, -0.957, -18.724},
{65.919, -1.722, -18.767},
{92.143, -0.451, -16.231, {delay = 5}},
{65.919, -1.722, -18.767},
{58.037, -0.957, -18.724},
{51.795, -1.790, -18.843},
{35.431, -0.045, -20.227},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section really nicely highlights the benefits of this PR!


function onPath(npc)
tpz.path.general(npc, path, tpz.path.flag.WALLHACK, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this "in the wild", I wonder if general is really the right name for the default, regular, general call?

Now that I say the other options, I guess it's as good as all the others 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refactor to tpz.pathing.path(), I don't know how much work that would be?

Comment on lines +10 to +19
{44.000, -11.000, -176.000},
{47.000, -11.000, -179.500},
{44.000, -11.000, -177.000},
{40.500, -11.000, -179.500},
{39.500, -11.000, -176.500},
{41.300, -11.000, -172.300},
{45.000, -11.000, -171.300},
{46.000, -11.000, -173.600},
{42.700, -11.000, -174.300},
{44.000, -11.000, -179.800},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope you were able to automate this process and didn't have to manage all these tables by hand...

int32 pathThrough(lua_State* L); // walk at normal speed through the given points
int32 isFollowingPath(lua_State* L); // checks if the entity is following a path
int32 isFollowingPath(lua_State* L);
int32 rotateToAngle(lua_State* L);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres some borked tab indents around here

@zach2good
Copy link
Contributor

I think you've taken care of all semicolons and random things in Lua, but if you could take a merge of release just to be sure that would be grand

{
auto PNpc = static_cast<CNpcEntity*>(m_PBaseEntity);
uint32 npcID = PNpc->id;
const char* NPCQuery = "SELECT speed FROM npc_list WHERE npcid = %u";
Copy link
Contributor

@TeoTwawki TeoTwawki Aug 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not store the original speed in a localVar instead of re-querying the database?
You can actually get and set localVars from the C++ side too, not just in lua.

Copy link
Contributor

@TeoTwawki TeoTwawki Aug 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For NPCs we could try having the event code itself stop and restart NPC movement. since m_event.target is the NPC entity itself. Mobs we'd still need a script command for stop/start.

TPZ_DEBUG_BREAK_IF(m_PBaseEntity == nullptr);
TPZ_DEBUG_BREAK_IF(m_PBaseEntity->objtype == TYPE_PC);

CBattleEntity* PBattle = (CBattleEntity*)m_PBaseEntity;
Copy link
Contributor

@TeoTwawki TeoTwawki Aug 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_PBaseEntity->speed = 0; actually does work, no need to recast as a battleentity for either mobs or npc's (or players). Which makes this entire function in its current form a duplicate of speed()

Lets improve it by having this function also store the entities current speed to a localVar prior to setting it zero. Then resume path can read that value instead of querying the database every time.

 m_PBaseEntity->SetLocalVar(lua_tostring(L, 1), (uint64_t)lua_tointeger(L, 2));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to place all these in an issue or ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not particularly no. I'd rather see it be changed here and its such a small correction to make instead of unnecessarily adding more iops of our inefficient db connection.

@59blargedy 59blargedy removed the hold Requests have been made to merge label Aug 28, 2020
Copy link
Contributor

@zach2good zach2good left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @Wiggo32 had some things to say about this, putting on hold until they can chime in

@zach2good zach2good added the hold Requests have been made to merge label Sep 3, 2020
@zach2good zach2good changed the base branch from pathing to wip/pathing September 5, 2020 08:46
@zircon-tpl zircon-tpl changed the base branch from wip/pathing to pr/548 November 15, 2020 05:11
@zircon-tpl zircon-tpl changed the base branch from pr/548 to wip/pathing November 15, 2020 05:12
@zircon-tpl zircon-tpl changed the base branch from wip/pathing to pr/548 November 15, 2020 05:13
@zircon-tpl zircon-tpl merged commit b3da71e into project-topaz:pr/548 Nov 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hold Requests have been made to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants