From 5efdaf915a0897378883a47d5fc1db29f0d6ced7 Mon Sep 17 00:00:00 2001 From: driAn Date: Fri, 22 Aug 2008 18:59:13 +0000 Subject: [PATCH] flag dropping, proper position rounding git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2351 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entities.cpp | 20 +++++++++++++++----- source/src/tools.cpp | 1 + source/src/tools.h | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 45a49057..8f869ca0 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -331,14 +331,24 @@ void flagdropped(int flag, int action, short x, short y, short z) p.o.y = y; p.o.z = z; p.vel.z = -0.8f; - loopi(100) + p.aboveeye = p.eyeheight = p.radius = 0.0f; + + bool oldcancollide = false; + if(f.actor) { - moveplayer(&p, 10, true, 50); // calc drop position + oldcancollide = f.actor->cancollide; + f.actor->cancollide = false; // avoid collision with owner + } + loopi(100) // perform physics steps + { + moveplayer(&p, 10, true, 50); if(p.stuck) break; } - f.flag->x = (short)p.o.x; - f.flag->y = (short)p.o.y; - f.flag->z = (short)p.o.z; + if(f.actor) f.actor->cancollide = oldcancollide; // restore settings + + f.flag->x = (short)round(p.o.x); + f.flag->y = (short)round(p.o.y); + f.flag->z = (short)round(p.o.z); if(f.flag->z < hdr.waterlevel) f.flag->z = (short) hdr.waterlevel; f.flag->spawned = true; f.ack = true; diff --git a/source/src/tools.cpp b/source/src/tools.cpp index ae68d95c..162847ff 100644 --- a/source/src/tools.cpp +++ b/source/src/tools.cpp @@ -277,4 +277,5 @@ bool isbigendian() return !(*((char *)(&one))); } +inline float round(float x) { return floor(x + 0.5f); } diff --git a/source/src/tools.h b/source/src/tools.h index bb9453a4..30e0418b 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -508,6 +508,7 @@ extern bool cmpb(void *b, int n, enet_uint32 c); extern bool cmpf(char *fn, enet_uint32 c); extern void endianswap(void *, int, int); extern bool isbigendian(); +extern inline float round(float x); #endif