improved sniping

fixed bots never choice camping tactic, due to agression level oveflow
cosmetic changes
This commit is contained in:
jeefo 2016-01-30 13:15:50 +03:00
commit 9e5c1540f9
13 changed files with 336 additions and 310 deletions

160
include/platform.h Normal file
View file

@ -0,0 +1,160 @@
//
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
// Copyright (c) YaPB Development Team.
//
// This software is licensed under the BSD-style license.
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
// http://yapb.jeefo.net/license
//
#pragma once
// detects the build platform
#if defined (__linux__) || defined (__debian__) || defined (__linux)
#define PLATFORM_LINUX 1
#elif defined (__APPLE__)
#define PLATFORM_OSX 1
#elif defined (_WIN32)
#define PLATFORM_WIN32 1
#endif
// detects the compiler
#if defined (_MSC_VER)
#define COMPILER_VISUALC _MSC_VER
#elif defined (__MINGW32__)
#define COMPILER_MINGW32 __MINGW32__
#endif
// configure export macros
#if defined (COMPILER_VISUALC) || defined (COMPILER_MINGW32)
#define export extern "C" __declspec (dllexport)
#elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX)
#define export extern "C" __attribute__((visibility("default")))
#else
#error "Can't configure export macros. Compiler unrecognized."
#endif
// operating system specific macros, functions and typedefs
#ifdef PLATFORM_WIN32
#include <direct.h>
#define DLL_ENTRYPOINT int STDCALL DllMain (HINSTANCE, DWORD dwReason, LPVOID)
#define DLL_DETACHING (dwReason == DLL_PROCESS_DETACH)
#define DLL_RETENTRY return TRUE
#if defined (COMPILER_VISUALC)
#define DLL_GIVEFNPTRSTODLL extern "C" void STDCALL
#elif defined (COMPILER_MINGW32)
#define DLL_GIVEFNPTRSTODLL export void STDCALL
#endif
// specify export parameter
#if defined (COMPILER_VISUALC) && (COMPILER_VISUALC > 1000)
#pragma comment (linker, "/EXPORT:GiveFnptrsToDll=_GiveFnptrsToDll@8,@1")
#pragma comment (linker, "/SECTION:.data,RW")
#endif
typedef int (FAR *EntityAPI_t) (gamefuncs_t *, int);
typedef int (FAR *NewEntityAPI_t) (newgamefuncs_t *, int *);
typedef int (FAR *BlendAPI_t) (int, void **, void *, float (*)[3][4], float (*)[128][3][4]);
typedef void (STDCALL *FuncPointers_t) (enginefuncs_t *, globalvars_t *);
typedef void (FAR *EntityPtr_t) (entvars_t *);
#elif defined (PLATFORM_LINUX) || defined (PLATFORM_OSX)
#include <unistd.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#define DLL_ENTRYPOINT __attribute__((destructor)) void _fini (void)
#define DLL_DETACHING TRUE
#define DLL_RETENTRY return
#define DLL_GIVEFNPTRSTODLL extern "C" void __attribute__((visibility("default")))
#if defined (__ANDROID__)
#define PLATFORM_ANDROID 1
#endif
typedef int (*EntityAPI_t) (gamefuncs_t *, int);
typedef int (*NewEntityAPI_t) (newgamefuncs_t *, int *);
typedef int (*BlendAPI_t) (int, void **, void *, float (*)[3][4], float (*)[128][3][4]);
typedef void (*FuncPointers_t) (enginefuncs_t *, globalvars_t *);
typedef void (*EntityPtr_t) (entvars_t *);
#else
#error "Platform unrecognized."
#endif
// library wrapper
class Library
{
private:
void *m_ptr;
public:
Library (const char *fileName)
{
m_ptr = NULL;
if (fileName == NULL)
return;
LoadLib (fileName);
}
~Library (void)
{
if (!IsLoaded ())
return;
#ifdef PLATFORM_WIN32
FreeLibrary ((HMODULE) m_ptr);
#else
dlclose (m_ptr);
#endif
}
public:
inline void *LoadLib (const char *fileName)
{
#ifdef PLATFORM_WIN32
m_ptr = LoadLibrary (fileName);
#else
m_ptr = dlopen (fileName, RTLD_NOW);
#endif
return m_ptr;
}
template <typename R> R GetFuncAddr (const char *function)
{
if (!IsLoaded ())
return NULL;
#ifdef PLATFORM_WIN32
return reinterpret_cast <R> (GetProcAddress (static_cast <HMODULE> (m_ptr), function));
#else
return reinterpret_cast <R> (dlsym (m_ptr, function));
#endif
}
template <typename R> R GetHandle (void)
{
return (R) m_ptr;
}
inline bool IsLoaded (void) const
{
return m_ptr != NULL;
}
};