Skip to content

Commit

Permalink
Added P_TryMove3f
Browse files Browse the repository at this point in the history
The function is in the common game plugin and is exported out from the game.
  • Loading branch information
skyjake committed Apr 18, 2011
1 parent 565b0da commit 975e272
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/api/dd_api.h
Expand Up @@ -97,6 +97,7 @@ typedef struct {
// Miscellaneous.
void (*MobjThinker) ();
float (*MobjFriction) (void* mobj); // Returns a friction factor.
boolean (*MobjTryMove3f) (struct mobj_s* mobj, float x, float y, float z);

// Main structure sizes.
size_t mobjSize; // sizeof(mobj_t)
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/common/include/p_map.h
Expand Up @@ -63,6 +63,8 @@ void P_RadiusAttack(mobj_t* spot, mobj_t* source, int damage, int distance,
void P_RadiusAttack(mobj_t* spot, mobj_t* source, int damage, int distance);
#endif

boolean P_TryMove3f(mobj_t* thing, float x, float y, float z);

#if !__JHEXEN__
boolean P_TryMove(mobj_t* thing, float x, float y,
boolean dropoff, boolean slide);
Expand Down
35 changes: 35 additions & 0 deletions doomsday/plugins/common/src/p_map.c
Expand Up @@ -1553,6 +1553,41 @@ boolean P_TryMove(mobj_t* thing, float x, float y, boolean dropoff,
#endif
}

/**
* Attempts to move a mobj to a new 3D position, crossing special lines
* and picking up things.
*
* @note This function is exported from the game plugin.
*
* @param thing Mobj to move.
* @param x New X coordinate.
* @param y New Y coordinate.
* @param z New Z coordinate.
*
* @return @c true, if the move was successful. Otherwise, @c false.
*/
boolean P_TryMove3f(mobj_t* thing, float x, float y, float z)
{
float oldZ = thing->pos[VZ];

// Go to the new Z height.
thing->pos[VZ] = z;

#ifdef __JHEXEN__
if(P_TryMove(thing, x, y))
#else
if(P_TryMove(thing, x, y, false, false))
#endif
{
// The move was successful.
return true;
}

// The move failed, so restore the original position.
thing->pos[VZ] = oldZ;
return false;
}

/**
* \fixme DJS - This routine has gotten way too big, split if(in->isaline)
* to a seperate routine?
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/jdoom/src/d_api.c
Expand Up @@ -37,6 +37,7 @@
#include "hu_menu.h"
#include "xgclass.h"
#include "g_update.h"
#include "p_map.h"
#include "p_mapsetup.h"
#include "p_tick.h"

Expand Down Expand Up @@ -157,6 +158,7 @@ game_export_t *GetGameAPI(game_import_t *imports)
gx.G_Responder = G_Responder;
gx.MobjThinker = P_MobjThinker;
gx.MobjFriction = (float (*)(void *)) P_MobjGetFriction;
gx.MobjTryMove3f = P_TryMove3f;
gx.EndFrame = G_EndFrame;
gx.ConsoleBackground = D_ConsoleBg;
gx.UpdateState = G_UpdateState;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/jdoom64/src/d_api.c
Expand Up @@ -38,6 +38,7 @@
#include "xgclass.h"
#include "g_update.h"
#include "p_mapsetup.h"
#include "p_map.h"
#include "p_tick.h"

// MACROS ------------------------------------------------------------------
Expand Down Expand Up @@ -158,6 +159,7 @@ game_export_t *GetGameAPI(game_import_t *imports)
gx.G_Responder = G_Responder;
gx.MobjThinker = P_MobjThinker;
gx.MobjFriction = (float (*)(void *)) P_MobjGetFriction;
gx.MobjTryMove3f = P_TryMove3f;
gx.EndFrame = G_EndFrame;
gx.ConsoleBackground = D_ConsoleBg;
gx.UpdateState = G_UpdateState;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/jheretic/src/h_api.c
Expand Up @@ -38,6 +38,7 @@
#include "xgclass.h"
#include "g_update.h"
#include "p_mapsetup.h"
#include "p_map.h"
#include "p_tick.h"

// MACROS ------------------------------------------------------------------
Expand Down Expand Up @@ -158,6 +159,7 @@ game_export_t* GetGameAPI(game_import_t* imports)
gx.G_Responder = G_Responder;
gx.MobjThinker = P_MobjThinker;
gx.MobjFriction = (float (*)(void *)) P_MobjGetFriction;
gx.MobjTryMove3f = P_TryMove3f;
gx.EndFrame = G_EndFrame;
gx.ConsoleBackground = H_ConsoleBg;
gx.UpdateState = G_UpdateState;
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/jhexen/src/x_api.c
Expand Up @@ -38,6 +38,7 @@
#include "d_netsv.h"
#include "p_setup.h"
#include "p_mapsetup.h"
#include "p_map.h"

// MACROS ------------------------------------------------------------------

Expand Down Expand Up @@ -157,6 +158,7 @@ game_export_t *GetGameAPI(game_import_t *imports)
gx.G_Responder = G_Responder;
gx.MobjThinker = P_MobjThinker;
gx.MobjFriction = (float (*)(void *)) P_MobjGetFriction;
gx.MobjTryMove3f = P_TryMove3f;
gx.EndFrame = G_EndFrame;
gx.ConsoleBackground = G_ConsoleBg;
gx.UpdateState = G_UpdateState;
Expand Down

0 comments on commit 975e272

Please sign in to comment.