Browse Source

Move code around to be more logical, a bit of cleanup, some name changes.
Also now use a nifty CMake Module to get version from git tags

Signed-off-by: Godzil <godzil@godzil.net>

Godzil 6 years ago
parent
commit
b2254d86d8

+ 20 - 0
CMakeLists.txt

@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8)
 
 project(ThePulsars)
 
+# External cmake modules
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
+
+# Options for the project
 option(BUILD_SERVER "Build server" ON)
 # Currently does not build, do no enable
 option(BUILD_GCLIENT "Build graphical client" OFF)
@@ -13,6 +17,22 @@ option(ENABLE_EFENCE "Enable ElectricFence" OFF)
 add_compile_options(-Wall -Werror)
 include_directories(include)
 
+# Get version from Git
+include(GetGitRevisionDescription)
+git_describe(VERSION --tags --dirty=-dirty)
+
+#parse the version information into pieces.
+string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
+string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
+string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_MICRO "${VERSION}")
+string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+-(.*)" "\\1" VERSION_SHA1 "${VERSION}")
+
+add_compile_options(-DV_MAJOR=${VERSION_MAJOR})
+add_compile_options(-DV_MINOR=${VERSION_MINOR})
+add_compile_options(-DV_MICRO=${VERSION_MICRO})
+add_compile_options(-DV_SHA=${VERSION_SHA1})
+
+
 #add_subdirectory(pulsarnet)
 
 if (BUILD_SERVER)

+ 168 - 0
cmake/GetGitRevisionDescription.cmake

@@ -0,0 +1,168 @@
+# - Returns a version string from Git
+#
+# These functions force a re-configure on each git commit so that you can
+# trust the values of the variables in your build system.
+#
+#  get_git_head_revision(<refspecvar> <hashvar> [<additional arguments to git describe> ...])
+#
+# Returns the refspec and sha hash of the current head revision
+#
+#  git_describe(<var> [<additional arguments to git describe> ...])
+#
+# Returns the results of git describe on the source tree, and adjusting
+# the output so that it tests false if an error occurs.
+#
+#  git_get_exact_tag(<var> [<additional arguments to git describe> ...])
+#
+# Returns the results of git describe --exact-match on the source tree,
+# and adjusting the output so that it tests false if there was no exact
+# matching tag.
+#
+#  git_local_changes(<var>)
+#
+# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
+# Uses the return code of "git diff-index --quiet HEAD --".
+# Does not regard untracked files.
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+if(__get_git_revision_description)
+    return()
+endif()
+set(__get_git_revision_description YES)
+
+# We must run the following at "include" time, not at function call time,
+# to find the path to this module rather than the path to a calling list file
+get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+function(get_git_head_revision _refspecvar _hashvar)
+    set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+    set(GIT_DIR "${GIT_PARENT_DIR}/.git")
+    while(NOT EXISTS "${GIT_DIR}")	# .git dir not found, search parent directories
+        set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}")
+        get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH)
+        if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT)
+            # We have reached the root directory, we are not in git
+            set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+            set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+            return()
+        endif()
+        set(GIT_DIR "${GIT_PARENT_DIR}/.git")
+    endwhile()
+    # check if this is a submodule
+    if(NOT IS_DIRECTORY ${GIT_DIR})
+        file(READ ${GIT_DIR} submodule)
+        string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
+        get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
+        get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
+    endif()
+    set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
+    if(NOT EXISTS "${GIT_DATA}")
+        file(MAKE_DIRECTORY "${GIT_DATA}")
+    endif()
+
+    if(NOT EXISTS "${GIT_DIR}/HEAD")
+        return()
+    endif()
+    set(HEAD_FILE "${GIT_DATA}/HEAD")
+    configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY)
+
+    configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
+            "${GIT_DATA}/grabRef.cmake"
+            @ONLY)
+    include("${GIT_DATA}/grabRef.cmake")
+
+    set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
+    set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
+endfunction()
+
+function(git_describe _var)
+    if(NOT GIT_FOUND)
+        find_package(Git QUIET)
+    endif()
+    get_git_head_revision(refspec hash)
+    if(NOT GIT_FOUND)
+        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+    if(NOT hash)
+        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+
+    # TODO sanitize
+    #if((${ARGN}" MATCHES "&&") OR
+    #	(ARGN MATCHES "||") OR
+    #	(ARGN MATCHES "\\;"))
+    #	message("Please report the following error to the project!")
+    #	message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
+    #endif()
+
+    message(STATUS "Arguments to execute_process: ${ARGN}")
+
+    execute_process(COMMAND
+            "${GIT_EXECUTABLE}"
+            describe
+            #${hash}
+            ${ARGN}
+            WORKING_DIRECTORY
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            RESULT_VARIABLE
+            res
+            OUTPUT_VARIABLE
+            out
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT res EQUAL 0)
+        set(out "${out}-${res}-NOTFOUND")
+    endif()
+
+    set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
+
+function(git_get_exact_tag _var)
+    git_describe(out --exact-match ${ARGN})
+    set(${_var} "${out}" PARENT_SCOPE)
+endfunction()
+
+function(git_local_changes _var)
+    if(NOT GIT_FOUND)
+        find_package(Git QUIET)
+    endif()
+    get_git_head_revision(refspec hash)
+    if(NOT GIT_FOUND)
+        set(${_var} "GIT-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+    if(NOT hash)
+        set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE)
+        return()
+    endif()
+
+    execute_process(COMMAND
+            "${GIT_EXECUTABLE}"
+            diff-index --quiet HEAD --
+            WORKING_DIRECTORY
+            "${CMAKE_CURRENT_SOURCE_DIR}"
+            RESULT_VARIABLE
+            res
+            OUTPUT_VARIABLE
+            out
+            ERROR_QUIET
+            OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(res EQUAL 0)
+        set(${_var} "CLEAN" PARENT_SCOPE)
+    else()
+        set(${_var} "DIRTY" PARENT_SCOPE)
+    endif()
+endfunction()

+ 41 - 0
cmake/GetGitRevisionDescription.cmake.in

@@ -0,0 +1,41 @@
+#
+# Internal file for GetGitRevisionDescription.cmake
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright Iowa State University 2009-2010.
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+set(HEAD_HASH)
+
+file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
+
+string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
+if(HEAD_CONTENTS MATCHES "ref")
+	# named branch
+	string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
+	if(EXISTS "@GIT_DIR@/${HEAD_REF}")
+		configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
+	else()
+		configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
+		file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
+		if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
+			set(HEAD_HASH "${CMAKE_MATCH_1}")
+		endif()
+	endif()
+else()
+	# detached HEAD
+	configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
+endif()
+
+if(NOT HEAD_HASH)
+	file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
+	string(STRIP "${HEAD_HASH}" HEAD_HASH)
+endif()

+ 4 - 4
server/CMakeLists.txt

@@ -5,11 +5,11 @@ project(PulsarServer)
 set(TARGET server)
 
 set(TARGET_HEADER_FILES include/action.h include/client.h include/conf.h include/erreur.h include/exec.h include/game.h
-        include/ipc.h include/message.h include/network.h include/parser.h include/private.h include/plugins.h
-        include/public.h include/server.h)
+        include/ipc.h include/message.h include/network.h include/parser.h include/objects.h include/player.h
+        include/public.h include/server.h include/pulse.h include/map.h include/time.h)
 
-add_executable(${TARGET} main.c init.c plugins.c exec.c ipc.c client.c message.c parser.c map.c map_parser.c bouvier.c
-        game.c time.c pulse.c objects.c network.c network_connect.c ${TARGET_HEADER_FILES})
+add_executable(${TARGET} main.c init.c player.c exec.c ipc.c client.c message.c parser.c map.c map_parser.c bouvier.c
+        game.c time.c pulse.c objects.c network.c network_connect.c ${TARGET_HEADER_FILES} conf.c)
 
 target_include_directories(${TARGET} PRIVATE include)
 

+ 134 - 133
server/client.c

@@ -2,10 +2,11 @@
 
 #include <general.h>
 
+#include <map.h>
+#include <pulse.h>
 #include <server.h>
 #include <conf.h>
-#include <game.h>
-#include <private.h>
+#include <objects.h>
 #include <action.h>
 #include <erreur.h>
 #include <bits/mathcalls.h>
@@ -29,25 +30,25 @@ static boolean_t is_visible(int team_id, float x, float y)
 
 static boolean_t is_obj_visible(int team_id, int id)
 {
-   if (gl_objects[id].obj.team_id == team_id)
+   if (glbObjects[id].obj.team_id == team_id)
    {
       return True;
    }
-   return is_visible(team_id, gl_objects[id].obj.x, gl_objects[id].obj.y);
+   return is_visible(team_id, glbObjects[id].obj.x, glbObjects[id].obj.y);
 }
 
 void set_default_action_r4d2(int r4d2_id)
 {
-   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_move;
-   gl_objects[r4d2_id].r4d2.action.act.move.x = gl_objects[r4d2_id].r4d2.x;
-   gl_objects[r4d2_id].r4d2.action.act.move.y = gl_objects[r4d2_id].r4d2.y;
+   glbObjects[r4d2_id].r4d2.action.type = act_r4d2_move;
+   glbObjects[r4d2_id].r4d2.action.act.move.x = glbObjects[r4d2_id].r4d2.x;
+   glbObjects[r4d2_id].r4d2.action.act.move.y = glbObjects[r4d2_id].r4d2.y;
 }
 
 void set_default_action_akx(int akx_id)
 {
-   gl_objects[akx_id].akx.action.type = act_akx_move;
-   gl_objects[akx_id].akx.action.act.move.x = gl_objects[akx_id].akx.x;
-   gl_objects[akx_id].akx.action.act.move.y = gl_objects[akx_id].akx.y;
+   glbObjects[akx_id].akx.action.type = act_akx_move;
+   glbObjects[akx_id].akx.action.act.move.x = glbObjects[akx_id].akx.x;
+   glbObjects[akx_id].akx.action.act.move.y = glbObjects[akx_id].akx.y;
 }
 
 int time_get_left()
@@ -59,31 +60,31 @@ int error_get()
 {
    int foo;
 
-   foo = gl_player->error;
-   gl_player->error = NONE;
+   foo = glbPlayer->error;
+   glbPlayer->error = NONE;
    return foo;
 }
 
 int score_get()
 {
-   return (int)gl_player->score;
+   return (int)glbPlayer->score;
 }
 
 static boolean_t validate_object(int obj_id, obj_type_t type)
 {
    if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return False;
    }
-   if (!is_obj_visible(gl_player->team_id, obj_id))
+   if (!is_obj_visible(glbPlayer->team_id, obj_id))
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return False;
    }
-   if (gl_objects[obj_id].obj.type != type)
+   if (glbObjects[obj_id].obj.type != type)
    {
-      gl_player->error = TYPE_ERROR;
+      glbPlayer->error = TYPE_ERROR;
       return False;
    }
    return True;
@@ -93,12 +94,12 @@ static boolean_t validate_object_nosee(int obj_id, obj_type_t type)
 {
    if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return False;
    }
-   if (gl_objects[obj_id].obj.type != type)
+   if (glbObjects[obj_id].obj.type != type)
    {
-      gl_player->error = TYPE_ERROR;
+      glbPlayer->error = TYPE_ERROR;
       return False;
    }
    return True;
@@ -108,24 +109,24 @@ static boolean_t validate_object_owner(int obj_id, obj_type_t type)
 {
    if ((obj_id >= gl_config->nb_objects) || (obj_id < 0))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return False;
    }
-   if (gl_objects[obj_id].obj.team_id != gl_player->team_id)
+   if (glbObjects[obj_id].obj.team_id != glbPlayer->team_id)
    {
-      if ((gl_objects[obj_id].obj.team_id == 0) && (type == obj_r4d2))
+      if ((glbObjects[obj_id].obj.team_id == 0) && (type == obj_r4d2))
       {
-         gl_player->error = DESTROYED;
+         glbPlayer->error = DESTROYED;
       }
       else
       {
-         gl_player->error = NOT_YOURS;
+         glbPlayer->error = NOT_YOURS;
       }
       return False;
    }
-   if (gl_objects[obj_id].obj.type != type)
+   if (glbObjects[obj_id].obj.type != type)
    {
-      gl_player->error = TYPE_ERROR;
+      glbPlayer->error = TYPE_ERROR;
       return False;
    }
    return True;
@@ -137,12 +138,12 @@ int r4d2_get_team(int r4d2_id)
    {
       return -1;
    }
-   if (gl_objects[r4d2_id].obj.team_id == 0)
+   if (glbObjects[r4d2_id].obj.team_id == 0)
    {
-      gl_player->error = DESTROYED;
+      glbPlayer->error = DESTROYED;
       return -1;
    }
-   return gl_objects[r4d2_id].obj.team_id;
+   return glbObjects[r4d2_id].obj.team_id;
 }
 
 float r4d2_get_pos_x(int r4d2_id)
@@ -151,7 +152,7 @@ float r4d2_get_pos_x(int r4d2_id)
    {
       return -1;
    }
-   return gl_objects[r4d2_id].obj.x;
+   return glbObjects[r4d2_id].obj.x;
 }
 
 float r4d2_get_pos_y(int r4d2_id)
@@ -160,7 +161,7 @@ float r4d2_get_pos_y(int r4d2_id)
    {
       return -1;
    }
-   return gl_objects[r4d2_id].obj.y;
+   return glbObjects[r4d2_id].obj.y;
 }
 
 int r4d2_get_status(int r4d2_id)
@@ -169,7 +170,7 @@ int r4d2_get_status(int r4d2_id)
    {
       return -1;
    }
-   return gl_objects[r4d2_id].r4d2.action.type;
+   return glbObjects[r4d2_id].r4d2.action.type;
 }
 
 float r4d2_get_speed()
@@ -206,16 +207,16 @@ int r4d2_move(int r4d2_id, float x, float y)
 {
    if (!finitef(x) || !finitef(y))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    if (!validate_object_owner(r4d2_id, obj_r4d2))
    {
       return -1;
    }
-   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_move;
-   gl_objects[r4d2_id].r4d2.action.act.move.x = x;
-   gl_objects[r4d2_id].r4d2.action.act.move.y = y;
+   glbObjects[r4d2_id].r4d2.action.type = act_r4d2_move;
+   glbObjects[r4d2_id].r4d2.action.act.move.x = x;
+   glbObjects[r4d2_id].r4d2.action.act.move.y = y;
 
    return 0;
 }
@@ -230,26 +231,26 @@ int r4d2_take_akx(int r4d2_id, int target_id)
    {
       return -1;
    }
-   if (dist(gl_objects[r4d2_id].r4d2.x,
-            gl_objects[r4d2_id].r4d2.y,
-            gl_objects[target_id].akx.x,
-            gl_objects[target_id].akx.y) > DIST_MIN_TAKE)
+   if (map_get_dist(glbObjects[r4d2_id].r4d2.x,
+                    glbObjects[r4d2_id].r4d2.y,
+                    glbObjects[target_id].akx.x,
+                    glbObjects[target_id].akx.y) > DIST_MIN_TAKE)
    {
       set_default_action_r4d2(r4d2_id);
-      gl_player->error = POS_OUT_OF_RANGE;
+      glbPlayer->error = POS_OUT_OF_RANGE;
       return -1;
    }
-   if (gl_objects[r4d2_id].r4d2.action.type == act_r4d2_take_akx)
+   if (glbObjects[r4d2_id].r4d2.action.type == act_r4d2_take_akx)
    {
       return 0;
    }
-   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_take_akx;
-   gl_objects[r4d2_id].r4d2.action.act.take_akx.target_id = target_id;
-   gl_objects[r4d2_id].r4d2.action.act.take_akx.turn_need =
+   glbObjects[r4d2_id].r4d2.action.type = act_r4d2_take_akx;
+   glbObjects[r4d2_id].r4d2.action.act.take_akx.target_id = target_id;
+   glbObjects[r4d2_id].r4d2.action.act.take_akx.turn_need =
            gl_config->turn_take_akx;
-   if (gl_objects[target_id].akx.team_id != 0)
+   if (glbObjects[target_id].akx.team_id != 0)
    {
-      gl_objects[r4d2_id].r4d2.action.act.take_akx.turn_need +=
+      glbObjects[r4d2_id].r4d2.action.act.take_akx.turn_need +=
               gl_config->turn_untake_akx;
    }
    return 0;
@@ -267,35 +268,35 @@ int r4d2_take_r4d2(int r4d2_id, int target_id)
    }
    if (target_id == r4d2_id)
    {
-      gl_player->error = INVALID_TARGET;
+      glbPlayer->error = INVALID_TARGET;
       return -1;
    }
-   if ((gl_objects[target_id].obj.team_id == 0) ||
-       (gl_objects[target_id].obj.team_id > gl_config->nb_players))
+   if ((glbObjects[target_id].obj.team_id == 0) ||
+       (glbObjects[target_id].obj.team_id > gl_config->nb_players))
    {
-      gl_player->error = DESTROYED;
+      glbPlayer->error = DESTROYED;
       return -1;
    }
-   if (dist(gl_objects[r4d2_id].r4d2.x,
-            gl_objects[r4d2_id].r4d2.y,
-            gl_objects[target_id].r4d2.x,
-            gl_objects[target_id].r4d2.y) > DIST_MIN_TAKE)
+   if (map_get_dist(glbObjects[r4d2_id].r4d2.x,
+                    glbObjects[r4d2_id].r4d2.y,
+                    glbObjects[target_id].r4d2.x,
+                    glbObjects[target_id].r4d2.y) > DIST_MIN_TAKE)
    {
       set_default_action_r4d2(r4d2_id);
-      gl_player->error = POS_OUT_OF_RANGE;
+      glbPlayer->error = POS_OUT_OF_RANGE;
       return -1;
    }
-   if (gl_objects[r4d2_id].r4d2.action.type == act_r4d2_take_r4d2)
+   if (glbObjects[r4d2_id].r4d2.action.type == act_r4d2_take_r4d2)
    {
       return 0;
    }
-   gl_objects[r4d2_id].r4d2.action.type = act_r4d2_take_r4d2;
-   gl_objects[r4d2_id].r4d2.action.act.take_r4d2.target_id = target_id;
-   gl_objects[r4d2_id].r4d2.action.act.take_r4d2.turn_need =
+   glbObjects[r4d2_id].r4d2.action.type = act_r4d2_take_r4d2;
+   glbObjects[r4d2_id].r4d2.action.act.take_r4d2.target_id = target_id;
+   glbObjects[r4d2_id].r4d2.action.act.take_r4d2.turn_need =
            gl_config->turn_take_r4d2;
-   if (gl_objects[target_id].r4d2.team_id != 0)
+   if (glbObjects[target_id].r4d2.team_id != 0)
    {
-      gl_objects[r4d2_id].r4d2.action.act.take_r4d2.turn_need +=
+      glbObjects[r4d2_id].r4d2.action.act.take_r4d2.turn_need +=
               gl_config->turn_untake_r4d2;
    }
    return 0;
@@ -312,16 +313,16 @@ static int get_nearest_not(float x, float y, int id, int team_id,
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
       if ((cpt != id) &&
-          (gl_objects[cpt].obj.team_id != team_id) &&
-          (gl_objects[cpt].obj.type == target_type))
+          (glbObjects[cpt].obj.team_id != team_id) &&
+          (glbObjects[cpt].obj.type == target_type))
       {
-         if ((target_type != obj_r4d2) || (gl_objects[cpt].obj.team_id != 0))
+         if ((target_type != obj_r4d2) || (glbObjects[cpt].obj.team_id != 0))
          {
-            if (is_obj_visible(gl_player->team_id, cpt))
+            if (is_obj_visible(glbPlayer->team_id, cpt))
             {
-               dist_temp = dist(x, y,
-                                gl_objects[cpt].obj.x,
-                                gl_objects[cpt].obj.y);
+               dist_temp = map_get_dist(x, y,
+                                        glbObjects[cpt].obj.x,
+                                        glbObjects[cpt].obj.y);
                if (dist_temp < dist_nearest)
                {
                   nearest = cpt;
@@ -351,16 +352,16 @@ static int get_nearest_plot(float x, float y, int id, int team_id,
       for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
       {
          if ((cpt != id) &&
-             (gl_objects[cpt].obj.team_id == team_id) &&
-             (gl_objects[cpt].obj.type == target_type))
+             (glbObjects[cpt].obj.team_id == team_id) &&
+             (glbObjects[cpt].obj.type == target_type))
          {
-            if ((target_type != obj_r4d2) || (gl_objects[cpt].obj.team_id > 0))
+            if ((target_type != obj_r4d2) || (glbObjects[cpt].obj.team_id > 0))
             {
-               if (is_obj_visible(gl_player->team_id, cpt))
+               if (is_obj_visible(glbPlayer->team_id, cpt))
                {
-                  dist_temp = dist(x, y,
-                                   gl_objects[cpt].obj.x,
-                                   gl_objects[cpt].obj.y);
+                  dist_temp = map_get_dist(x, y,
+                                           glbObjects[cpt].obj.x,
+                                           glbObjects[cpt].obj.y);
                   if (dist_temp < dist_nearest)
                   {
                      nearest = cpt;
@@ -376,8 +377,8 @@ static int get_nearest_plot(float x, float y, int id, int team_id,
 
 int get_nearest(int id, int team_id, obj_type_t target_type)
 {
-   return get_nearest_plot(gl_objects[id].obj.x,
-                           gl_objects[id].obj.y,
+   return get_nearest_plot(glbObjects[id].obj.x,
+                           glbObjects[id].obj.y,
                            id, team_id, target_type);
 }
 
@@ -387,7 +388,7 @@ int akx_get_team(int akx_id)
    {
       return -1;
    }
-   return gl_objects[akx_id].obj.team_id;
+   return glbObjects[akx_id].obj.team_id;
 }
 
 float akx_get_pos_x(int akx_id)
@@ -396,7 +397,7 @@ float akx_get_pos_x(int akx_id)
    {
       return -1;
    }
-   return gl_objects[akx_id].obj.x;
+   return glbObjects[akx_id].obj.x;
 }
 
 float akx_get_pos_y(int akx_id)
@@ -405,7 +406,7 @@ float akx_get_pos_y(int akx_id)
    {
       return -1;
    }
-   return gl_objects[akx_id].obj.y;
+   return glbObjects[akx_id].obj.y;
 }
 
 int akx_get_status(int akx_id)
@@ -414,7 +415,7 @@ int akx_get_status(int akx_id)
    {
       return -1;
    }
-   return gl_objects[akx_id].akx.action.type;
+   return glbObjects[akx_id].akx.action.type;
 }
 
 
@@ -447,17 +448,17 @@ int akx_move(int akx_id, float x, float y)
 {
    if (!finitef(x) || !finitef(y))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    if (!validate_object_owner(akx_id, obj_akx))
    {
       return -1;
    }
-   gl_objects[akx_id].akx.action.type = act_akx_move;
-   gl_objects[akx_id].akx.action.act.move.x = x;
-   gl_objects[akx_id].akx.action.act.move.y = y;
-   gl_objects[akx_id].akx.change = True;
+   glbObjects[akx_id].akx.action.type = act_akx_move;
+   glbObjects[akx_id].akx.action.act.move.x = x;
+   glbObjects[akx_id].akx.action.act.move.y = y;
+   glbObjects[akx_id].akx.change = True;
    return 0;
 }
 
@@ -465,24 +466,24 @@ int akx_pulse(int akx_id, float x, float y, float angle)
 {
    if (!finitef(x) || !finitef(y) || !finitef(angle))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    if (!validate_object_owner(akx_id, obj_akx))
    {
       return -1;
    }
-   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   if (glbObjects[akx_id].akx.action.type != act_akx_pulse)
    {
-      gl_objects[akx_id].akx.action.act.pulse.x = gl_objects[akx_id].obj.x;
-      gl_objects[akx_id].akx.action.act.pulse.y = gl_objects[akx_id].obj.y;
-      gl_objects[akx_id].akx.energy = 0;
+      glbObjects[akx_id].akx.action.act.pulse.x = glbObjects[akx_id].obj.x;
+      glbObjects[akx_id].akx.action.act.pulse.y = glbObjects[akx_id].obj.y;
+      glbObjects[akx_id].akx.energy = 0;
    }
-   gl_objects[akx_id].akx.action.type = act_akx_pulse;
-   gl_objects[akx_id].akx.action.act.pulse.new_x = x;
-   gl_objects[akx_id].akx.action.act.pulse.new_y = y;
-   gl_objects[akx_id].akx.action.act.pulse.new_angle = CLAMP(angle, MIN_ANGLE, MAX_ANGLE);
-   gl_objects[akx_id].akx.change = True;
+   glbObjects[akx_id].akx.action.type = act_akx_pulse;
+   glbObjects[akx_id].akx.action.act.pulse.new_x = x;
+   glbObjects[akx_id].akx.action.act.pulse.new_y = y;
+   glbObjects[akx_id].akx.action.act.pulse.new_angle = CLAMP(angle, MIN_ANGLE, MAX_ANGLE);
+   glbObjects[akx_id].akx.change = True;
    return 0;
 }
 
@@ -492,12 +493,12 @@ float akx_pulse_angle(int akx_id)
    {
       return -1;
    }
-   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   if (glbObjects[akx_id].akx.action.type != act_akx_pulse)
    {
-      gl_player->error = INVALID_TARGET;
+      glbPlayer->error = INVALID_TARGET;
       return -1;
    }
-   return gl_objects[akx_id].akx.action.act.pulse.angle;
+   return glbObjects[akx_id].akx.action.act.pulse.angle;
 }
 
 float akx_pulse_destx(int akx_id)
@@ -506,12 +507,12 @@ float akx_pulse_destx(int akx_id)
    {
       return -1;
    }
-   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   if (glbObjects[akx_id].akx.action.type != act_akx_pulse)
    {
-      gl_player->error = INVALID_TARGET;
+      glbPlayer->error = INVALID_TARGET;
       return -1;
    }
-   return gl_objects[akx_id].akx.action.act.pulse.x;
+   return glbObjects[akx_id].akx.action.act.pulse.x;
 }
 
 float akx_pulse_desty(int akx_id)
@@ -520,12 +521,12 @@ float akx_pulse_desty(int akx_id)
    {
       return -1;
    }
-   if (gl_objects[akx_id].akx.action.type != act_akx_pulse)
+   if (glbObjects[akx_id].akx.action.type != act_akx_pulse)
    {
-      gl_player->error = INVALID_TARGET;
+      glbPlayer->error = INVALID_TARGET;
       return -1;
    }
-   return gl_objects[akx_id].akx.action.act.pulse.y;
+   return glbObjects[akx_id].akx.action.act.pulse.y;
 }
 
 int akx_link(int akx_id, int target_id)
@@ -540,13 +541,13 @@ int akx_link(int akx_id, int target_id)
    }
    if (target_id == akx_id)
    {
-      gl_player->error = INVALID_TARGET;
+      glbPlayer->error = INVALID_TARGET;
       return -1;
    }
-   gl_objects[akx_id].akx.change = True;
+   glbObjects[akx_id].akx.change = True;
    set_default_action_akx(akx_id);
-   gl_objects[akx_id].akx.action.type = act_akx_link;
-   gl_objects[akx_id].akx.action.act.link.target_id = target_id;
+   glbObjects[akx_id].akx.action.type = act_akx_link;
+   glbObjects[akx_id].akx.action.act.link.target_id = target_id;
    return 0;
 }
 
@@ -556,13 +557,13 @@ int map_get_nearest_akx(int id, int team_id)
 
    if (id >= gl_config->nb_objects)
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    nearest = get_nearest(id, team_id, obj_akx);
    if (nearest == id)
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return -1;
    }
    return nearest;
@@ -574,13 +575,13 @@ int map_get_nearest_akx_plot(float x, float y, int team_id)
 
    if (!finitef(x) || !finitef(y))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    nearest = get_nearest_plot(x, y, -1, team_id, obj_akx);
    if (nearest == -1)
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return -1;
    }
    return nearest;
@@ -592,13 +593,13 @@ int map_get_nearest_r4d2_plot(float x, float y, int team_id)
 
    if (!finitef(x) || !finitef(y))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    nearest = get_nearest_plot(x, y, -1, team_id, obj_r4d2);
    if (nearest == -1)
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return -1;
    }
    return nearest;
@@ -610,13 +611,13 @@ int map_get_nearest_r4d2(int id, int team_id)
 
    if (id >= gl_config->nb_objects)
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    nearest = get_nearest(id, team_id, obj_r4d2);
    if (nearest == id)
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return -1;
    }
    return nearest;
@@ -638,8 +639,8 @@ int count_unit(int team_id, int obj_type)
 
    for (i = 0 ; i < gl_config->nb_objects ; i++)
    {
-      if ((gl_objects[i].obj.team_id == team_id) &&
-          (gl_objects[i].obj.type == obj_type))
+      if ((glbObjects[i].obj.team_id == team_id) &&
+          (glbObjects[i].obj.type == obj_type))
       {
          cpt++;
       }
@@ -654,7 +655,7 @@ int count_akx(int team_id)
 
 int map_count_my_akx()
 {
-   return count_akx(gl_player->team_id);
+   return count_akx(glbPlayer->team_id);
 }
 
 int count_r4d2(int team_id)
@@ -674,19 +675,19 @@ float map_get_size_y()
 
 int map_count_my_r4d2()
 {
-   return count_r4d2(gl_player->team_id);
+   return count_r4d2(glbPlayer->team_id);
 }
 
 float map_get_pulse(int team_id, float x, float y)
 {
    if (!finitef(x) || !finitef(y))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
-   if (!is_visible(gl_player->team_id, x, y))
+   if (!is_visible(glbPlayer->team_id, x, y))
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return -1;
    }
    return get_pulse_team(x, y, team_id);
@@ -696,22 +697,22 @@ float map_get_pulse_id(int akx_id, float x, float y)
 {
    if (!finitef(x) || !finitef(y))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
    if ((akx_id >= gl_config->nb_objects) || (akx_id < 0))
    {
-      gl_player->error = NBR_OUT_OF_RANGE;
+      glbPlayer->error = NBR_OUT_OF_RANGE;
       return -1;
    }
-   if (!is_visible(gl_player->team_id, x, y))
+   if (!is_visible(glbPlayer->team_id, x, y))
    {
-      gl_player->error = NOT_VISIBLE;
+      glbPlayer->error = NOT_VISIBLE;
       return -1;
    }
-   if (gl_objects[akx_id].obj.type != obj_akx)
+   if (glbObjects[akx_id].obj.type != obj_akx)
    {
-      gl_player->error = TYPE_ERROR;
+      glbPlayer->error = TYPE_ERROR;
       return -1;
    }
    return get_pulse_id(x, y, akx_id);

+ 55 - 0
server/conf.c

@@ -0,0 +1,55 @@
+//
+// Created by mlt on 29/01/18.
+//
+
+#include <conf.h>
+#include <ipc.h>
+
+#define	CONF_DEFAULT_PORT	    (4242)
+#define CONF_DEFAULT_MAP	    "./default.map"
+#define CONF_DEFAULT_NBTURNS	(420)
+#define CONF_DEFAULT_TURN_MSEC	(200)
+#define	DEF_TURN_TAKE_AKX	    (5)
+#define	DEF_TURN_UNTAKE_AKX	    (5)
+#define	DEF_TURN_TAKE_R4D2	    (5)
+#define	DEF_TURN_UNTAKE_R4D2	(5)
+#define	DEF_R4D2_SPEED		    (2.0F)
+#define	DEF_AKX_SPEED		    (0.1F)
+#define	DEF_PULSE_POWER		    (1000.0F)
+#define	DEF_SEE_POWER		    (1.0F)
+#define	DEF_PULSE_COEF		    (1.0F)
+#define	DEF_SIZE_X		        (1)
+#define	DEF_SIZE_Y		        (1)
+#define	DEF_DESTROY_SPEED	    (-1.0F)
+
+conf_t *gl_config;
+
+conf_t *conf_set_default(conf_t *res)
+{
+   res->verbose = False;
+   res->quiet = False;
+   res->gfx = False;
+   res->map_name = CONF_DEFAULT_MAP;
+   res->nb_turns = CONF_DEFAULT_NBTURNS;
+   res->turn_msec = CONF_DEFAULT_TURN_MSEC;
+   res->turn_take_akx = DEF_TURN_TAKE_AKX;
+   res->turn_untake_akx = DEF_TURN_UNTAKE_AKX;
+   res->turn_take_r4d2 = DEF_TURN_TAKE_R4D2;
+   res->turn_untake_r4d2 = DEF_TURN_UNTAKE_R4D2;
+   res->r4d2_speed = DEF_R4D2_SPEED;
+   res->akx_speed = DEF_AKX_SPEED;
+   res->pulse_power = DEF_PULSE_POWER;
+   res->see_power = DEF_SEE_POWER;
+   res->destroy_speed = DEF_DESTROY_SPEED;
+   res->pulse_coef = DEF_PULSE_COEF;
+   res->nb_akx = res->nb_r4d2 = res->nb_objects = 0;
+   res->size_x = DEF_SIZE_X;
+   res->size_y = DEF_SIZE_Y;
+   res->players = NULL;
+   res->nb_players = 0;
+   res->turn_num = 0;
+   res->sand_file = NULL;
+   res->port = CONF_DEFAULT_PORT;
+   res->pub = True;
+   return res;
+}

+ 47 - 46
server/exec.c

@@ -4,11 +4,12 @@
 
 #include <server.h>
 #include <client.h>
-#include <private.h>
+#include <objects.h>
 #include <memory.h>
 #include <stdlib.h>
 #include <action.h>
-#include <game.h>
+#include <map.h>
+#include <pulse.h>
 #include <exec.h>
 #include <network.h>
 
@@ -60,7 +61,7 @@ void check_conflict_akx(int akx_id)
    bzero(nbr_r4d2, gl_config->nb_players * sizeof(int));
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      temp = gl_objects + cpt;
+      temp = glbObjects + cpt;
       if (temp->obj.type == obj_r4d2)
       {
          if (temp->r4d2.action.type == act_r4d2_take_akx)
@@ -75,7 +76,7 @@ void check_conflict_akx(int akx_id)
    winner = get_max(nbr_r4d2, gl_config->nb_players);
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      temp = gl_objects + cpt;
+      temp = glbObjects + cpt;
       if (temp->obj.type == obj_r4d2)
       {
          if (temp->r4d2.action.type == act_r4d2_take_akx)
@@ -103,7 +104,7 @@ void check_conflict_r4d2(int r4d2_id)
    bzero(nbr_r4d2, gl_config->nb_players * sizeof(int));
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      temp = gl_objects + cpt;
+      temp = glbObjects + cpt;
       if (temp->obj.type == obj_r4d2)
       {
          if (temp->r4d2.action.type == act_r4d2_take_r4d2)
@@ -118,7 +119,7 @@ void check_conflict_r4d2(int r4d2_id)
    winner = get_max(nbr_r4d2, gl_config->nb_players);
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      temp = gl_objects + cpt;
+      temp = glbObjects + cpt;
       if (temp->obj.type == obj_r4d2)
       {
          if (temp->r4d2.action.type == act_r4d2_take_r4d2)
@@ -143,7 +144,7 @@ void check_conflict()
 
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      temp = gl_objects + cpt;
+      temp = glbObjects + cpt;
       if (temp->obj.type == obj_r4d2)
       {
          if (temp->r4d2.action.type == act_r4d2_take_akx)
@@ -183,17 +184,17 @@ void check_take()
 
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      it = gl_objects + cpt;
+      it = glbObjects + cpt;
       if (it->obj.type == obj_r4d2)
       {
          switch (it->r4d2.action.type)
          {
          case act_r4d2_take_akx:
             tid = it->r4d2.action.act.take_akx.target_id;
-            if (dist(gl_objects[cpt].r4d2.x,
-                     gl_objects[cpt].r4d2.y,
-                     gl_objects[tid].akx.x,
-                     gl_objects[tid].akx.y)
+            if (map_get_dist(glbObjects[cpt].r4d2.x,
+                             glbObjects[cpt].r4d2.y,
+                             glbObjects[tid].akx.x,
+                             glbObjects[tid].akx.y)
                 > DIST_MIN_TAKE)
             {
                set_default_action_r4d2(cpt);
@@ -201,10 +202,10 @@ void check_take()
             break;
          case act_r4d2_take_r4d2:
             tid = it->r4d2.action.act.take_r4d2.target_id;
-            if (dist(gl_objects[cpt].r4d2.x,
-                     gl_objects[cpt].r4d2.y,
-                     gl_objects[tid].r4d2.x,
-                     gl_objects[tid].r4d2.y)
+            if (map_get_dist(glbObjects[cpt].r4d2.x,
+                             glbObjects[cpt].r4d2.y,
+                             glbObjects[tid].r4d2.x,
+                             glbObjects[tid].r4d2.y)
                 > DIST_MIN_TAKE)
             {
                set_default_action_r4d2(cpt);
@@ -225,64 +226,64 @@ void exec_objects()
    check_conflict();
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      if (gl_objects[cpt].obj.type == obj_r4d2)
+      if (glbObjects[cpt].obj.type == obj_r4d2)
       {
-         exec_destroy(&(gl_objects[cpt].r4d2));
+         exec_destroy(&(glbObjects[cpt].r4d2));
       }
    }
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      if (gl_objects[cpt].obj.type == obj_akx)
+      if (glbObjects[cpt].obj.type == obj_akx)
       {
-         if (gl_objects[cpt].akx.action.type == act_akx_move)
+         if (glbObjects[cpt].akx.action.type == act_akx_move)
          {
-            exec_akx_move(&(gl_objects[cpt].akx));
+            exec_akx_move(&(glbObjects[cpt].akx));
          }
       }
-      else if ((gl_objects[cpt].obj.type == obj_r4d2) &&
-               (gl_objects[cpt].r4d2.action.type == act_r4d2_move))
+      else if ((glbObjects[cpt].obj.type == obj_r4d2) &&
+               (glbObjects[cpt].r4d2.action.type == act_r4d2_move))
       {
-         exec_r4d2_move(&(gl_objects[cpt].r4d2));
+         exec_r4d2_move(&(glbObjects[cpt].r4d2));
       }
    }
    /* AJOUT MATHIAS */
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      if (gl_objects[cpt].obj.type == obj_akx)
+      if (glbObjects[cpt].obj.type == obj_akx)
       {
-         exec_akx_reset_energy(&(gl_objects[cpt].akx));
+         exec_akx_reset_energy(&(glbObjects[cpt].akx));
       }
    }
 
 
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      if ((gl_objects[cpt].obj.type == obj_akx) &&
-          (gl_objects[cpt].akx.action.type == act_akx_link))
+      if ((glbObjects[cpt].obj.type == obj_akx) &&
+          (glbObjects[cpt].akx.action.type == act_akx_link))
       {
-         exec_akx_link(&(gl_objects[cpt].akx));
+         exec_akx_link(&(glbObjects[cpt].akx));
       }
    }
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      if (gl_objects[cpt].obj.type == obj_r4d2)
+      if (glbObjects[cpt].obj.type == obj_r4d2)
       {
-         if (gl_objects[cpt].r4d2.action.type == act_r4d2_take_akx)
+         if (glbObjects[cpt].r4d2.action.type == act_r4d2_take_akx)
          {
-            exec_r4d2_take_akx(&gl_objects[cpt].r4d2);
+            exec_r4d2_take_akx(&glbObjects[cpt].r4d2);
          }
-         else if (gl_objects[cpt].r4d2.action.type == act_r4d2_take_r4d2)
+         else if (glbObjects[cpt].r4d2.action.type == act_r4d2_take_r4d2)
          {
-            exec_r4d2_take_r4d2(&gl_objects[cpt].r4d2);
+            exec_r4d2_take_r4d2(&glbObjects[cpt].r4d2);
          }
       }
    }
    for (cpt = 0 ; cpt < gl_config->nb_objects ; cpt++)
    {
-      if ((gl_objects[cpt].obj.type == obj_akx) &&
-          (gl_objects[cpt].akx.action.type == act_akx_pulse))
+      if ((glbObjects[cpt].obj.type == obj_akx) &&
+          (glbObjects[cpt].akx.action.type == act_akx_pulse))
       {
-         exec_akx_pulse(&(gl_objects[cpt].akx));
+         exec_akx_pulse(&(glbObjects[cpt].akx));
       }
    }
 
@@ -407,8 +408,8 @@ void exec_r4d2_take_r4d2(r4d2_t *r4d2)
    r4d2->action.act.take_r4d2.turn_need--;
    if (r4d2->action.act.take_r4d2.turn_need <= 0)
    {
-      gl_objects[r4d2->action.act.take_r4d2.target_id].obj.change = True;
-      gl_objects[r4d2->action.act.take_r4d2.target_id].obj.team_id = r4d2->team_id;
+      glbObjects[r4d2->action.act.take_r4d2.target_id].obj.change = True;
+      glbObjects[r4d2->action.act.take_r4d2.target_id].obj.team_id = r4d2->team_id;
       r4d2->action.type = act_r4d2_move;
       r4d2->action.act.move.x = r4d2->x;
       r4d2->action.act.move.y = r4d2->y;
@@ -420,8 +421,8 @@ void exec_r4d2_take_akx(r4d2_t *r4d2)
    r4d2->action.act.take_akx.turn_need--;
    if (r4d2->action.act.take_akx.turn_need <= 0)
    {
-      gl_objects[r4d2->action.act.take_akx.target_id].obj.change = True;
-      gl_objects[r4d2->action.act.take_akx.target_id].obj.team_id = r4d2->team_id;
+      glbObjects[r4d2->action.act.take_akx.target_id].obj.change = True;
+      glbObjects[r4d2->action.act.take_akx.target_id].obj.team_id = r4d2->team_id;
       r4d2->action.type = act_r4d2_move;
       r4d2->action.act.move.x = r4d2->x;
       r4d2->action.act.move.y = r4d2->y;
@@ -447,17 +448,17 @@ void exec_akx_link(akx_t *akx)
 {
    float dst;
 
-   if (akx->team_id != gl_objects[akx->action.act.link.target_id].obj.team_id)
+   if (akx->team_id != glbObjects[akx->action.act.link.target_id].obj.team_id)
    {
-      gl_objects[akx->id].obj.change = True;
+      glbObjects[akx->id].obj.change = True;
       set_default_action_akx(akx->id);
       return;
    }
 
-   dst = dist(akx->x, akx->y, gl_objects[akx->action.act.link.target_id].obj.x,
-              gl_objects[akx->action.act.link.target_id].obj.y);
+   dst = map_get_dist(akx->x, akx->y, glbObjects[akx->action.act.link.target_id].obj.x,
+                      glbObjects[akx->action.act.link.target_id].obj.y);
 
-   gl_objects[akx->action.act.link.target_id].akx.energy += akx->energy / (1 + sqrt(dst));
+   glbObjects[akx->action.act.link.target_id].akx.energy += akx->energy / (1 + sqrt(dst));
 
    akx->energy = gl_config->pulse_power;
 }

+ 17 - 20
server/game.c

@@ -10,27 +10,24 @@
 #include <unistd.h>
 
 #include <server.h>
-#include <private.h>
+#include <objects.h>
 #include <public.h>
 #include <client.h>
 #include <stdlib.h>
 #include <message.h>
 #include <exec.h>
+#include <time.h>
 
 #include <general.h>
 
-item_t *gl_objects;
-player_t *gl_player;
-conf_t *gl_config;
-
 static void signal_usr1(int foo)
 {
 }
 
 static void client_died(int foo)
 {
-   gl_player->alive = False;
-   printf("%d: died.\n", gl_player->team_id);
+   glbPlayer->alive = False;
+   printf("%d: died.\n", glbPlayer->team_id);
    fflush(stdout);
    wait(NULL);
 }
@@ -40,26 +37,26 @@ static void play_turn(int turn_num)
    int i;
 
    start_timer();
-   if (gl_player->new)
+   if (glbPlayer->new)
    {
-      player_init(gl_player, gl_player->team_id);
-      gl_player->new = False;
+      player_init(glbPlayer, glbPlayer->team_id);
+      glbPlayer->new = False;
    }
    else
    {
-      player_new_turn(gl_player, turn_num);
+      player_new_turn(glbPlayer, turn_num);
 
       for (i = 0 ; i < gl_config->nb_objects ; i++)
       {
-         if (gl_objects[i].obj.team_id == gl_player->team_id)
+         if (glbObjects[i].obj.team_id == glbPlayer->team_id)
          {
-            switch (gl_objects[i].obj.type)
+            switch (glbObjects[i].obj.type)
             {
             case obj_akx:
-               player_turn_akx(gl_player, gl_objects[i].obj.id);
+               player_turn_akx(glbPlayer, glbObjects[i].obj.id);
                break;
             case obj_r4d2:
-               player_turn_r4d2(gl_player, gl_objects[i].obj.id);
+               player_turn_r4d2(glbPlayer, glbObjects[i].obj.id);
                break;
             }
          }
@@ -101,7 +98,7 @@ void start_client(player_t *player, int turn_num)
       close(player->pipe_write);
       close(player->pipe_read);
       player->new = True;
-      gl_player = player;
+      glbPlayer = player;
       rl.rlim_cur = rl.rlim_max = 16 * 1024 * 1024;
       setrlimit(RLIMIT_DATA, &rl);
       while (True)
@@ -122,7 +119,7 @@ void turn_client(player_t *play)
    }
    else
    {
-      start_client(gl_player, gl_config->turn_num);
+      start_client(glbPlayer, gl_config->turn_num);
    }
 }
 
@@ -147,7 +144,7 @@ int check_done()
 }
 
 /* lanceur de partie */
-void launch_game(conf_t *conf)
+void game_launch(conf_t *conf)
 {
    GSList *l;
    int i;
@@ -189,12 +186,12 @@ void launch_game(conf_t *conf)
 
          for (i = 0 ; i < conf->nb_objects ; i++)
          {
-            gl_objects[i].obj.change = False;
+            glbObjects[i].obj.change = False;
          }
 
          for (l = conf->players ; l != NULL ; l = l->next)
          {
-            gl_player = l->data;
+            glbPlayer = l->data;
             turn_client(l->data);
          }
 

+ 2 - 17
server/include/conf.h

@@ -43,23 +43,8 @@ typedef struct _conf_t
   sigset_t	*mask;
 } conf_t;
 
-extern conf_t	*gl_config;
+extern conf_t *gl_config;
 
-#define	CONF_DEFAULT_PORT	4242
-#define CONF_DEFAULT_MAP	"./default.map"
-#define CONF_DEFAULT_NBTURNS	420
-#define CONF_DEFAULT_TURN_MSEC	200
-#define	DEF_TURN_TAKE_AKX	5
-#define	DEF_TURN_UNTAKE_AKX	5
-#define	DEF_TURN_TAKE_R4D2	5
-#define	DEF_TURN_UNTAKE_R4D2	5
-#define	DEF_R4D2_SPEED		2.0
-#define	DEF_AKX_SPEED		0.1
-#define	DEF_PULSE_POWER		1000.0
-#define	DEF_SEE_POWER		1.0
-#define	DEF_PULSE_COEF		1.0
-#define	DEF_SIZE_X		1
-#define	DEF_SIZE_Y		1
-#define	DEF_DESTROY_SPEED	-1.0
+conf_t *conf_set_default(conf_t *res);
 
 #endif

+ 4 - 6
server/include/game.h

@@ -3,12 +3,10 @@
 #ifndef __PROLO_GAME_H__
 #define __PROLO_GAME_H__
 
-float dist(float x1, float y1, float x2, float y2);
-float angle(float x, float y, float x1, float y1, float x2, float y2);
+#include "conf.h"
+#include "player.h"
 
-float get_pulse_team(float x, float y, int team_id);
-float get_pulse_id(float x, float y, int akx_id);
-float get_pulse_foe(float x, float y, int team_id);
-float get_pulse_total(float x, float y, int team_id);
+void game_launch(conf_t *conf);
+void start_client(player_t *player, int turn_num);
 
 #endif

+ 16 - 0
server/include/map.h

@@ -0,0 +1,16 @@
+//
+// Created by mlt on 29/01/18.
+//
+
+#ifndef THEPULSARS_MAP_H
+#define THEPULSARS_MAP_H
+
+#include "conf.h"
+
+/* Map parser functions */
+void load_map(conf_t *conf);
+
+float map_get_dist(float x1, float y1, float x2, float y2);
+float map_get_angle(float x, float y, float x1, float y1, float x2, float y2);
+
+#endif /* THEPULSARS_MAP_H */

+ 1 - 1
server/include/network.h

@@ -5,7 +5,7 @@
 
 #include <stdio.h>
 #include <general.h>
-#include "private.h"
+#include "objects.h"
 
 typedef struct _gfx_client_t
 {

+ 1 - 2
server/include/private.h → server/include/objects.h

@@ -59,10 +59,9 @@ typedef union _item_t
     r4d2_t r4d2;
 } item_t;
 
-extern item_t *gl_objects;
+extern item_t *glbObjects;
 
 void new_akx(float x, float y, int id);
-
 void new_r4d2(float x, float y, int id);
 
 #endif

+ 11 - 14
server/include/plugins.h → server/include/player.h

@@ -5,15 +5,16 @@
 
 #include "conf.h"
 
-typedef void (prolo_callback_t)(int);
-
-typedef void (prolo_callback2_t)(int, int);
-
-typedef struct _player_t
+typedef struct player_t
 {
     const char *name;
-    prolo_callback2_t *init;
-    prolo_callback_t *new_turn, *turn_akx, *turn_r4d2;
+
+    /* Function exported by the player module */
+    void (*init)(int team, int nbPlayers);
+    void (*new_turn)(int turn);
+    void (*akx_turn)(int id);
+    void (*r4d2_turn)(int id);
+
     float score;
     int team_id;
     int time_turn;
@@ -28,17 +29,13 @@ typedef struct _player_t
     boolean_t alive;
 } player_t;
 
-player_t *new_player(const char *libname, const char *name, int id,
-                     conf_t *conf);
-
-void destroy_player(player_t *player);
+extern player_t *glbPlayer;
 
+player_t *player_new(const char *libname, const char *name, int id, conf_t *conf);
+void player_destroy(player_t *player);
 void player_init(player_t *p, int team_id);
-
 void player_new_turn(player_t *p, int turn_num);
-
 void player_turn_akx(player_t *p, int akx_id);
-
 void player_turn_r4d2(player_t *p, int r4d2_id);
 
 #endif

+ 44 - 50
server/include/public.h

@@ -8,17 +8,17 @@
 */
 
 /* Turn function */
-int	turn_number(void); /* nombre de tour total */
-int	turn_counter(void); /* numero du tour en cour */
+int turn_number(void); /* nombre de tour total */
+int turn_counter(void); /* numero du tour en cour */
 
 /* Time function */
-int	time_get_left(void);
+int time_get_left(void);
 
 /* Score function */
-int	score_get(void);
+int score_get(void);
 
 /* Error function */
-int	error_get(void);
+int error_get(void);
 
 /*
 ** Specific functions
@@ -29,57 +29,51 @@ int	error_get(void);
   team_id = 0	=> sauvage
   team_id > 0	=> uniquement team_id
 */
-  
 
 /* R4D2 */
-int	r4d2_get_team(int r4d2_id);
-float	r4d2_get_pos_x(int r4d2_id);
-float	r4d2_get_pos_y(int r4d2_id);
-int	r4d2_get_status(int r4d2_id);
-float	r4d2_get_speed(void);
-float	r4d2_get_destroy_speed(void);
-
-int	r4d2_turn_take_r4d2(void);
-int	r4d2_turn_untake_r4d2(void);
-int	r4d2_turn_take_akx(void);
-int	r4d2_turn_untake_akx(void);
-
-int	r4d2_move(int r4d2_id, float dx, float dy);
-int	r4d2_take_akx(int r4d2_id, int akx_id);
-int	r4d2_take_r4d2(int r4d2_id, int target_id);
+int r4d2_get_team(int r4d2_id);
+float r4d2_get_pos_x(int r4d2_id);
+float r4d2_get_pos_y(int r4d2_id);
+int r4d2_get_status(int r4d2_id);
+float r4d2_get_speed(void);
+float r4d2_get_destroy_speed(void);
+int r4d2_turn_take_r4d2(void);
+int r4d2_turn_untake_r4d2(void);
+int r4d2_turn_take_akx(void);
+int r4d2_turn_untake_akx(void);
+int r4d2_move(int r4d2_id, float dx, float dy);
+int r4d2_take_akx(int r4d2_id, int akx_id);
+int r4d2_take_r4d2(int r4d2_id, int target_id);
 
 /* Anakronox */
-int	akx_get_team(int akx_id);
-float	akx_get_pos_x(int akx_id);
-float	akx_get_pos_y(int akx_id);
-int	akx_get_status(int akx_id);
-
-float	akx_pulse_angle(int akx_id);
-float	akx_pulse_destx(int akx_id);
-float	akx_pulse_desty(int akx_id);
-
-float	akx_get_speed(void);
-float	akx_get_power(void);
-float	akx_get_pulse_coef(void);
-float	akx_get_see_power(void);
-
-int	akx_move(int akx_id, float dx, float dy);
-int	akx_pulse(int akx_id, float dx, float dy, float angle);
-int	akx_link(int akx_id, int target_id);
+int akx_get_team(int akx_id);
+float akx_get_pos_x(int akx_id);
+float akx_get_pos_y(int akx_id);
+int akx_get_status(int akx_id);
+float akx_pulse_angle(int akx_id);
+float akx_pulse_destx(int akx_id);
+float akx_pulse_desty(int akx_id);
+float akx_get_speed(void);
+float akx_get_power(void);
+float akx_get_pulse_coef(void);
+float akx_get_see_power(void);
+int akx_move(int akx_id, float dx, float dy);
+int akx_pulse(int akx_id, float dx, float dy, float angle);
+int akx_link(int akx_id, int target_id);
 
 /* Map */
-float	map_get_size_x(void);
-float	map_get_size_y(void);
-float	map_get_pulse(int team_id, float x, float y);
-float	map_get_pulse_id(int akx_id, float x, float y);
-int	map_count_akx(void);
-int	map_count_r4d2(void);
-int	map_count_my_akx(void);
-int	map_count_my_r4d2(void);
-int	map_get_nearest_akx_plot(float x, float y, int team_id);
-int	map_get_nearest_r4d2_plot(float x, float y, int team_id);
-int	map_get_nearest_akx(int id, int team_id);
-int	map_get_nearest_r4d2(int id, int team_id);
+float map_get_size_x(void);
+float map_get_size_y(void);
+float map_get_pulse(int team_id, float x, float y);
+float map_get_pulse_id(int akx_id, float x, float y);
+int map_count_akx(void);
+int map_count_r4d2(void);
+int map_count_my_akx(void);
+int map_count_my_r4d2(void);
+int map_get_nearest_akx_plot(float x, float y, int team_id);
+int map_get_nearest_r4d2_plot(float x, float y, int team_id);
+int map_get_nearest_akx(int id, int team_id);
+int map_get_nearest_r4d2(int id, int team_id);
 
 #endif
 

+ 13 - 0
server/include/pulse.h

@@ -0,0 +1,13 @@
+//
+// Created by mlt on 29/01/18.
+//
+
+#ifndef THEPULSARS_PULSE_H
+#define THEPULSARS_PULSE_H
+
+float get_pulse_team(float x, float y, int team_id);
+float get_pulse_id(float x, float y, int akx_id);
+float get_pulse_foe(float x, float y, int team_id);
+float get_pulse_total(float x, float y, int team_id);
+
+#endif /* THEPULSARS_PULSE_H */

+ 2 - 14
server/include/server.h

@@ -3,21 +3,9 @@
 #ifndef __PROLO_SERVER_H__
 #define __PROLO_SERVER_H__
 
-#include <plugins.h>
+#include <player.h>
 #include <conf.h>
 
-extern player_t *gl_player;
-
-/* Initialization functions */
-conf_t *init(int argc, char **argv);
-void launch_game(conf_t *conf);
-void load_map(conf_t *conf);
-void start_client(player_t *player, int turn_num);
-
-/* Time functions */
-void start_timer();
-void stop_timer();
-int time_left();
-void abort();
+void server_abort();
 
 #endif

+ 13 - 0
server/include/time.h

@@ -0,0 +1,13 @@
+//
+// Created by mlt on 29/01/18.
+//
+
+#ifndef THEPULSARS_TIME_H
+#define THEPULSARS_TIME_H
+
+/* Time functions */
+void start_timer();
+void stop_timer();
+int time_left();
+
+#endif /* THEPULSARS_TIME_H */

+ 0 - 196
server/init.c

@@ -1,198 +1,2 @@
-/* $Id */
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <string.h>
 
-#include <server.h>
-#include <conf.h>
-#include <network.h>
-#include <ipc.h>
 
-#include <general.h>
-#include <libgen.h>
-
-/* TODO: Port the shared memory system */
-
-
-static conf_t *get_default_conf()
-{
-   conf_t *res;
-
-   res = shm_alloc(sizeof(*res), get_shm_conf_id());
-   res->verbose = False;
-   res->quiet = False;
-   res->gfx = False;
-   res->map_name = CONF_DEFAULT_MAP;
-   res->nb_turns = CONF_DEFAULT_NBTURNS;
-   res->turn_msec = CONF_DEFAULT_TURN_MSEC;
-   res->turn_take_akx = DEF_TURN_TAKE_AKX;
-   res->turn_untake_akx = DEF_TURN_UNTAKE_AKX;
-   res->turn_take_r4d2 = DEF_TURN_TAKE_R4D2;
-   res->turn_untake_r4d2 = DEF_TURN_UNTAKE_R4D2;
-   res->r4d2_speed = DEF_R4D2_SPEED;
-   res->akx_speed = DEF_AKX_SPEED;
-   res->pulse_power = DEF_PULSE_POWER;
-   res->see_power = DEF_SEE_POWER;
-   res->destroy_speed = DEF_DESTROY_SPEED;
-   res->pulse_coef = DEF_PULSE_COEF;
-   res->nb_akx = res->nb_r4d2 = res->nb_objects = 0;
-   res->size_x = DEF_SIZE_X;
-   res->size_y = DEF_SIZE_Y;
-   res->players = NULL;
-   res->nb_players = 0;
-   res->turn_num = 0;
-   res->sand_file = NULL;
-   res->port = CONF_DEFAULT_PORT;
-   res->pub = True;
-   return res;
-}
-
-static void cmdline_add_player(const char *str, conf_t *conf)
-{
-   char *name, *filename;
-   char *p;
-   static int id = 1;
-
-   name = strdup(str);
-   p = strchr(name, ':');
-   if (p == NULL)
-   {
-      filename = name;
-      name = strdup(basename(filename));
-   }
-   else
-   {
-      *p = 0;
-      filename = strdup(p + 1);
-   }
-   conf->players = g_slist_prepend(conf->players, new_player(filename, name, id++, conf));
-}
-
-static void help(char **argv)
-{
-   printf("%s", "Serveur Prologin version 0.9\n");
-   printf("\n");
-   printf("Syntaxe: %s [options] [-m carte] nom:fichier ...\n", argv[0]);
-   printf("\nOptions:\n");
-   printf("  -v     \t Mode verbose.\n");
-   printf("  -q     \t Supprime les messages des clients.\n");
-   printf("  -n val \t Nombre de tours que dure la partie.\n");
-   printf("  -t val \t Nombre de milliseconde pas tour.\n");
-   printf("  -m     \t Fichier carte.\n");
-   printf("\nOptions graphiques:\n");
-   printf("  -g     \t Accepte les clients graphiques.\n");
-   printf("  -P     \t Mode prive.\n");
-   printf("  -p val \t Port pour les clients graphiques (4242).\n");
-}
-
-static conf_t *parse_cmdline(int argc, char **argv)
-{
-   int i;
-   conf_t *res;
-
-   res = get_default_conf();
-   for (i = 1 ; i < argc ; i++)
-   {
-      if (argv[i][0] == '-')
-      {
-         switch (argv[i][1])
-         {
-         case 'h':
-            help(argv);
-            exit(0);
-         case 'P':
-            res->pub = False;
-            break;
-         case 'v':
-            res->verbose = True;
-            break;
-         case 'g':
-            res->gfx = True;
-            break;
-         case 'q':
-            res->quiet = True;
-            break;
-         case 'n':
-            i++;
-            if (i == argc)
-            {
-               printf("-n requiert un argument.\n");
-               return NULL;
-            }
-            res->nb_turns = atoi(argv[i]);
-            break;
-         case 't':
-            i++;
-            if (i == argc)
-            {
-               printf("-t requiert un argument.\n");
-               return NULL;
-            }
-            res->turn_msec = atoi(argv[i]);
-            break;
-         case 'p':
-            i++;
-            if (i == argc)
-            {
-               printf("-p requiert un argument.\n");
-               return NULL;
-            }
-            res->port = atoi(argv[i]);
-            break;
-         case 'm':
-            i++;
-            if (i == argc)
-            {
-               printf("-m requiert un argument.\n");
-               return NULL;
-            }
-            res->map_name = argv[i];
-            break;
-         }
-      }
-      else
-      {
-         cmdline_add_player(argv[i], res);
-      }
-   }
-   res->nb_players = g_slist_length(res->players);
-   return res;
-}
-
-conf_t *init(int argc, char **argv)
-{
-   conf_t *conf;
-   sigset_t mask2;
-
-   if (argc < 2)
-   {
-      help(argv);
-      return NULL;
-   }
-   gl_config = conf = parse_cmdline(argc, argv);
-   if (conf == NULL)
-   {
-      return NULL;
-   }
-   //atexit(clean_shm);
-   load_map(conf);
-   gfx_init();
-   sigprocmask(0, NULL, &mask2);
-   sigaddset(&mask2, SIGUSR1);
-   sigaddset(&mask2, SIGCHLD);
-   conf->mask = malloc(sizeof(*conf->mask));
-   sigprocmask(SIG_SETMASK, &mask2, conf->mask);
-   signal(SIGINT, exit);
-   return conf;
-}
-
-void abort()
-{
-   fflush(stdout);
-   fflush(stderr);
-   fprintf(stdout, "\nBye!\n");
-   fflush(stdout);
-   exit(1);
-}

+ 6 - 6
server/ipc.c

@@ -25,7 +25,7 @@ int get_shm_key(char c)
       return i;
    }
    perror("ftok");
-   abort();
+   server_abort();
 }
 
 int get_shm_conf_id()
@@ -54,13 +54,13 @@ void *shm_alloc(int size, int id)
       if ((shmid = shmget(id, size, 0)) == -1)
       {
          perror("shmget");
-         abort();
+         server_abort();
       }
    }
    if ((res = shmat(shmid, 0, 0)) == (void *)-1)
    {
       perror("shmat");
-      abort();
+      server_abort();
    }
    shm_memory_list = g_slist_prepend(shm_memory_list, GINT_TO_POINTER(shmid));
    return res;
@@ -76,10 +76,10 @@ void clean_shm()
    }
    for (l = gl_config->players ; l != NULL ; l = l->next)
    {
-      gl_player = l->data;
-      if (gl_player->pid)
+      glbPlayer = l->data;
+      if (glbPlayer->pid)
       {
-         kill(gl_player->pid, SIGKILL);
+         kill(glbPlayer->pid, SIGKILL);
       }
    }
    for (l = shm_memory_list ; l != NULL ; l = l->next)

+ 162 - 8
server/main.c

@@ -1,14 +1,29 @@
-/* $Id: main.c,v 1.11 2001/05/02 11:04:27 kilobug Exp $ */
+/*
+ * _________          _______    _______           _       _______  _______  _______  _______
+ * \__   __/|\     /|(  ____ \  (  ____ )|\     /|( \     (  ____ \(  ___  )(  ____ )(  ____ \
+ *    ) (   | )   ( || (    \/  | (    )|| )   ( || (     | (    \/| (   ) || (    )|| (    \/
+ *    | |   | (___) || (__      | (____)|| |   | || |     | (_____ | (___) || (____)|| (_____
+ *    | |   |  ___  ||  __)     |  _____)| |   | || |     (_____  )|  ___  ||     __)(_____  )
+ *    | |   | (   ) || (        | (      | |   | || |           ) || (   ) || (\ (         ) |
+ *    | |   | )   ( || (____/\  | )      | (___) || (____/Y\____) || )   ( || ) \ \__/\____) |
+ *    )_(   |/     \|(_______/  |/       (_______)(_______|_______)|/     \||/   \__/\_______)
+ *
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 #include <signal.h>
 
 #include <server.h>
 #include <network.h>
 #include <conf.h>
-#include <plugins.h>
+#include <player.h>
+#include <game.h>
+#include <libgen.h>
+#include <ipc.h>
+#include <map.h>
 
 
 #ifdef ENABLE_GPC
@@ -16,6 +31,116 @@ void init_Gpc(int argc, char **argv, char **arge);
 void init_Init();
 #endif
 
+static void cmdline_add_player(const char *str, conf_t *conf)
+{
+   char *name, *filename;
+   char *p;
+   static int id = 1;
+
+   name = strdup(str);
+   p = strchr(name, ':');
+   if (p == NULL)
+   {
+      filename = name;
+      name = strdup(basename(filename));
+   }
+   else
+   {
+      *p = 0;
+      filename = strdup(p + 1);
+   }
+   conf->players = g_slist_prepend(conf->players, player_new(filename, name, id++, conf));
+}
+
+static void help(char **argv)
+{
+   printf("Serveur Prologin version %d.%d.%d\n", V_MAJOR, V_MINOR, V_MICRO);
+   printf("\n");
+   printf("Syntaxe: %s [options] [-m carte] nom:fichier ...\n", argv[0]);
+   printf("\nOptions:\n");
+   printf("  -v     \t Mode verbose.\n");
+   printf("  -q     \t Supprime les messages des clients.\n");
+   printf("  -n val \t Nombre de tours que dure la partie.\n");
+   printf("  -t val \t Nombre de milliseconde pas tour.\n");
+   printf("  -m     \t Fichier carte.\n");
+   printf("\nOptions graphiques:\n");
+   printf("  -g     \t Accepte les clients graphiques.\n");
+   printf("  -P     \t Mode prive.\n");
+   printf("  -p val \t Port pour les clients graphiques (4242).\n");
+}
+
+static conf_t *parse_cmdline(int argc, char **argv)
+{
+   int i;
+   conf_t *res;
+
+   res = shm_alloc(sizeof(*res), get_shm_conf_id());
+
+   res = conf_set_default(res);
+
+   for (i = 1 ; i < argc ; i++)
+   {
+      if (argv[i][0] == '-')
+      {
+         switch (argv[i][1])
+         {
+         default:
+         case 'h': help(argv); exit(0);
+         case 'P': res->pub = False; break;
+         case 'v': res->verbose = True; break;
+         case 'g': res->gfx = True; break;
+         case 'q': res->quiet = True; break;
+
+         case 'n':
+            i++;
+            if (i == argc)
+            {
+               printf("-n requiert un argument.\n");
+               return NULL;
+            }
+            res->nb_turns = atoi(argv[i]);
+            break;
+
+         case 't':
+            i++;
+            if (i == argc)
+            {
+               printf("-t requiert un argument.\n");
+               return NULL;
+            }
+            res->turn_msec = atoi(argv[i]);
+            break;
+
+         case 'p':
+            i++;
+            if (i == argc)
+            {
+               printf("-p requiert un argument.\n");
+               return NULL;
+            }
+            res->port = atoi(argv[i]);
+            break;
+
+         case 'm':
+            i++;
+            if (i == argc)
+            {
+               printf("-m requiert un argument.\n");
+               return NULL;
+            }
+            res->map_name = argv[i];
+            break;
+         }
+      }
+      else
+      {
+         cmdline_add_player(argv[i], res);
+      }
+   }
+   res->nb_players = g_slist_length(res->players);
+   return res;
+}
+
 int main(int argc, char **argv, char **arge)
 {
    conf_t *conf = NULL;
@@ -27,19 +152,39 @@ int main(int argc, char **argv, char **arge)
    init_Init();
 #endif
 
-   conf = init(argc, argv);
+
+   sigset_t mask2;
+
+   if (argc < 2)
+   {
+      help(argv);
+      return NULL;
+   }
+   gl_config = conf = parse_cmdline(argc, argv);
    if (conf == NULL)
    {
-      abort();
+      server_abort();
    }
 
-   launch_game(conf);
+   atexit(clean_shm);
+
+   load_map(conf);
+   gfx_init();
+
+   sigprocmask(0, NULL, &mask2);
+   sigaddset(&mask2, SIGUSR1);
+   sigaddset(&mask2, SIGCHLD);
+   conf->mask = malloc(sizeof(*conf->mask));
+   sigprocmask(SIG_SETMASK, &mask2, conf->mask);
+   signal(SIGINT, exit);
+
+   game_launch(conf);
 
    for (l = conf->players ; l != NULL ; l = l->next)
    {
-      gl_player = l->data;
-      fprintf(stdout, "Player %d : %f\n", gl_player->team_id,
-              gl_player->score);
+      glbPlayer = l->data;
+      fprintf(stdout, "Player %d : %f\n", glbPlayer->team_id,
+              glbPlayer->score);
       fflush(stdout);
    }
 
@@ -57,3 +202,12 @@ int main(int argc, char **argv, char **arge)
 
    return 0;
 }
+
+void server_abort()
+{
+   fflush(stdout);
+   fflush(stderr);
+   fprintf(stdout, "---ABORT---\nBye!\n");
+   fflush(stdout);
+   exit(1);
+}

+ 4 - 37
server/map.c

@@ -6,50 +6,17 @@
 ** General map functions 
 */
 
-float dist(float x1, float y1, float x2, float y2)
+float map_get_dist(float x1, float y1, float x2, float y2)
 {
    return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
 }
 
-/*  float a, b, c, res;
-
- a = sqrt(dist(x, y, x1, y1));
- b = sqrt(dist(x, y, x2, y2));
- c = fabs((x1 - x) * (x2 - x) + (y1 - y) * (y2 - y)) * b;
- if (a)
-   res = acos(CLAMP(c / a, -1, 1));
- else
-   res = M_PI;
-   return res;
-float ac2, ab2, bc2, ac, ab, cosin;
-
-
-bc2 = SQR(x1 - x2) + SQR(y1 - y2);
-ab2 = SQR(x - x1) + SQR(y - y1);
-ac2 = SQR(x - x2) + SQR(y - y2);
-
-ac = (float)sqrt(ac2);
-ab = (float)sqrt(ab2);
-
-printf("BC2:%f AB2:%f AC2:%f AC:%f AB:%f\n", bc2, ab2, ac2, ac, ab);
-
-if (!ac | !ab)
-  return 0;
-cosin = (bc2 - ab2 - ac2) / (2 * ac * ab);
-printf("NUM: %f DEN: %f\n", bc2 - ab2 - ac2, 2 * ac * ab);
-printf("COS:%f\n", cosin);
-if (ABS(cosin) <= 1)
-  return (float)acos(cosin);
-return 0;
-*/
-
-
-float angle(float x, float y, float x1, float y1, float x2, float y2)
+float map_get_angle(float x, float y, float x1, float y1, float x2, float y2)
 {                  // a              // b                // c
    float f, d1, d2;
 
-   d1 = sqrtf(dist(x1, y1, x, y));
-   d2 = sqrtf(dist(x1, y1, x2, y2));
+   d1 = sqrtf(map_get_dist(x1, y1, x, y));
+   d2 = sqrtf(map_get_dist(x1, y1, x2, y2));
 
    if ((d1 == 0) || (d2 == 0))
    {

+ 7 - 7
server/map_parser.c

@@ -8,7 +8,7 @@
 #include <unistd.h>
 
 #include <server.h>
-#include <private.h>
+#include <objects.h>
 #include <ipc.h>
 
 /* TODO: This is going to be painful to remove GLIB */
@@ -110,12 +110,12 @@ static void map_load_value(GScanner *scan, conf_t *conf, int id)
    switch (type)
    {
    case G_TOKEN_SYMBOL:
-      gl_objects[id].obj.team_id = parser_get_symbol_as_int(scan);
+      glbObjects[id].obj.team_id = parser_get_symbol_as_int(scan);
       parser_check_type(scan, g_scanner_get_next_token(scan),
                         G_TOKEN_SEMICOLON);
       break;
    case G_TOKEN_INT:
-      gl_objects[id].obj.team_id = g_scanner_cur_value(scan).v_int;
+      glbObjects[id].obj.team_id = g_scanner_cur_value(scan).v_int;
       parser_check_type(scan, g_scanner_get_next_token(scan),
                         G_TOKEN_SEMICOLON);
       break;
@@ -126,9 +126,9 @@ static void map_load_value(GScanner *scan, conf_t *conf, int id)
                             TRUE);
       abort();
    }
-   if (gl_objects[id].obj.team_id > conf->nb_players)
+   if (glbObjects[id].obj.team_id > conf->nb_players)
    {
-      gl_objects[id].obj.team_id = 0;
+      glbObjects[id].obj.team_id = 0;
    }
 #endif
 }
@@ -270,7 +270,7 @@ void load_map(conf_t *conf)
    {
       fprintf(stderr, "Erreur: impossible d'ouvrir la carte (%s): %s\n",
               conf->map_name, strerror(errno));
-      abort();
+      server_abort();
    }
 #if 0
    scan = g_scanner_new(NULL);
@@ -290,7 +290,7 @@ void load_map(conf_t *conf)
 
    map_load_header(scan, conf);
 
-   gl_objects = shm_alloc(sizeof(*gl_objects) * conf->nb_objects,
+   glbObjects = shm_alloc(sizeof(*glbObjects) * conf->nb_objects,
                           get_shm_world_id());
    map_load_data(scan, conf);
 

+ 4 - 4
server/message.c

@@ -11,7 +11,7 @@
 
 #include <general.h>
 
-void init_fd_set(fd_set *fds)
+static void init_fd_set(fd_set *fds)
 {
    GSList *l;
    player_t *player;
@@ -25,7 +25,7 @@ void init_fd_set(fd_set *fds)
    }
 }
 
-int get_max_player_fd(fd_set *fds, FILE **tab_fds)
+static int get_max_player_fd(fd_set *fds, FILE **tab_fds)
 {
    GSList *l;
    player_t *player;
@@ -47,7 +47,7 @@ int get_max_player_fd(fd_set *fds, FILE **tab_fds)
    return max;
 }
 
-void test_file_fd(fd_set *fds, FILE **tab_fds)
+static void test_file_fd(fd_set *fds, FILE **tab_fds)
 {
    GSList *l;
    player_t *player;
@@ -80,7 +80,7 @@ void test_file_fd(fd_set *fds, FILE **tab_fds)
 
 static boolean_t gl_stop = False;
 
-void messager_exit(int foo)
+static void messager_exit(int foo)
 {
    gl_stop = True;
 }

+ 4 - 4
server/network.c

@@ -8,10 +8,10 @@
 
 #include <pulsarnet.h>
 #include <general.h>
-#include <private.h>
+#include <objects.h>
 #include <action.h>
 
-void gfx_trash_client(net_type_t get, net_type_t wanted, void *data)
+static void gfx_trash_client(net_type_t get, net_type_t wanted, void *data)
 {
    gfx_client_t *cl;
 
@@ -98,10 +98,10 @@ static boolean_t gfx_do_send_updates(void *data, void *foo)
    }
    for (i = 0 ; i < gl_config->nb_objects ; i++)
    {
-      if (gl_objects[i].obj.change)
+      if (glbObjects[i].obj.change)
       {
          net_wr_string(cl->wsock, "UOB");
-         obj = gl_objects + i;
+         obj = glbObjects + i;
          net_wr_int(cl->wsock, obj->obj.id);
          gfx_write_object(cl->wsock, obj);
       }

+ 2 - 2
server/network_connect.c

@@ -7,7 +7,7 @@
 
 #include <server.h>
 #include <network.h>
-#include <private.h>
+#include <objects.h>
 
 #include <general.h>
 #include <pulsarnet.h>
@@ -46,7 +46,7 @@ static void gfx_send_map(gfx_client_t *cl)
    }
    for (i = 0 ; i < gl_config->nb_objects ; i++)
    {
-      obj = gl_objects + i;
+      obj = glbObjects + i;
       net_wr_string(cl->wsock, "OBJ");
       net_wr_int(cl->wsock, obj->obj.id);
       net_wr_int(cl->wsock, obj->obj.type);

+ 4 - 4
server/objects.c

@@ -1,18 +1,18 @@
 /* $Id: objects.c,v 1.5 2001/04/06 17:36:55 glop Exp $ */
 
 #include <server.h>
-#include <private.h>
+#include <objects.h>
 #include <client.h>
 
 #include <general.h>
 
-
+item_t *glbObjects;
 
 void new_akx(float x, float y, int id)
 {
    item_t *res;
 
-   res = gl_objects + id;
+   res = glbObjects + id;
    res->akx.change = False;
    res->akx.x = x;
    res->akx.y = y;
@@ -27,7 +27,7 @@ void new_r4d2(float x, float y, int id)
 {
    item_t *res;
 
-   res = gl_objects + id;
+   res = glbObjects + id;
    res->r4d2.change = False;
    res->r4d2.x = x;
    res->r4d2.y = y;

+ 4 - 4
server/parser.c

@@ -7,7 +7,7 @@ void parser_check_type(GScanner *scan, GTokenType type, GTokenType wanted)
   if (type != wanted)
     {
       g_scanner_unexp_token(scan, wanted, NULL, NULL, NULL, NULL, TRUE);
-      abort();
+      server_abort();
     }
 }
 
@@ -38,7 +38,7 @@ int parser_get_int(GScanner *scan)
     default:
       g_scanner_unexp_token(scan, G_TOKEN_INT, NULL, NULL, NULL, 
 			    NULL, TRUE);
-      abort();      
+      server_abort();
     }
 }
 
@@ -56,7 +56,7 @@ double parser_get_float(GScanner *scan)
     default:
       g_scanner_unexp_token(scan, G_TOKEN_FLOAT, NULL, NULL, NULL, 
 			    NULL, TRUE);
-      abort();      
+      server_abort();
     }
 }
 
@@ -71,7 +71,7 @@ char *parser_get_string(GScanner *scan)
     default:
       g_scanner_unexp_token(scan, G_TOKEN_STRING, NULL, NULL, NULL, 
 			    NULL, TRUE);
-      abort();
+      server_abort();
     }
 }
 

+ 5 - 4
server/plugins.c → server/player.c

@@ -8,6 +8,7 @@
 #include <general.h>
 #include <ipc.h>
 
+player_t *glbPlayer;
 
 static void *get_symbol(GModule *hdl, const char *name, boolean_t stop_error)
 {
@@ -29,7 +30,7 @@ static void *get_symbol(GModule *hdl, const char *name, boolean_t stop_error)
    return p;
 }
 
-player_t *new_player(const char *libname, const char *name, int id,
+player_t *player_new(const char *libname, const char *name, int id,
                      conf_t *conf)
 {
    player_t *player;
@@ -41,7 +42,7 @@ player_t *new_player(const char *libname, const char *name, int id,
    if (!g_module_supported())
    {
       fprintf(stderr, "%s\n", "Fatal error : Dynamic library not supported!");
-      abort();
+      server_abort();
    }
    player->team_id = id;
    player->name = name;
@@ -53,7 +54,7 @@ player_t *new_player(const char *libname, const char *name, int id,
    {
       fprintf(stderr, "Dynamic library error : %s : %s\n",
               libname, g_module_error());
-      abort();
+      server_abort();
    }
    caml = get_symbol(player->handle, "caml_startup", False);
    if (caml)
@@ -71,7 +72,7 @@ player_t *new_player(const char *libname, const char *name, int id,
    return player;
 }
 
-void destroy_player(player_t *player)
+void player_destroy(player_t *player)
 {
    g_module_close(player->handle);
    free(player);

+ 10 - 11
server/pulse.c

@@ -1,9 +1,8 @@
 /* $Id: pulse.c,v 1.14 2001/05/06 07:23:34 kilobug Exp $ */
 
-#include <private.h>
+#include <objects.h>
 #include <server.h>
-#include <action.h>
-#include <game.h>
+#include <map.h>
 
 float get_pulse_team(float x, float y, int team_id)
 {
@@ -14,7 +13,7 @@ float get_pulse_team(float x, float y, int team_id)
 
    for (i = 0 ; i < gl_config->nb_objects ; i++)
    {
-      akx = &gl_objects[i].akx;
+      akx = &glbObjects[i].akx;
       if (((akx->team_id == team_id) ||
            ((akx->team_id != -team_id) && (team_id < 0) && (akx->team_id))) &&
           (akx->type == obj_akx) &&
@@ -23,10 +22,10 @@ float get_pulse_team(float x, float y, int team_id)
          pulse = &akx->action.act.pulse;
          if ((x != akx->x) || (y != akx->y))
          {
-            r = dist(pulse->x, pulse->y, akx->x, akx->y);
-            if (r >= dist(x, y, akx->x, akx->y))
+            r = map_get_dist(pulse->x, pulse->y, akx->x, akx->y);
+            if (r >= map_get_dist(x, y, akx->x, akx->y))
             {
-               agl = angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
+               agl = map_get_angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
                if (agl <= (pulse->angle / 2))
                {
                   result += akx->energy / (1 + r * pulse->angle / 2);
@@ -46,16 +45,16 @@ float get_pulse_id(float x, float y, int akx_id)
    akx_t *akx;
    akx_pulse_t *pulse;
 
-   akx = &gl_objects[akx_id].akx;
+   akx = &glbObjects[akx_id].akx;
    if (akx->action.type == act_akx_pulse)
    {
       pulse = &akx->action.act.pulse;
       if ((x != akx->x) || (y != akx->y))
       {
-         r = dist(pulse->x, pulse->y, akx->x, akx->y);
-         if (r >= dist(x, y, akx->x, akx->y))
+         r = map_get_dist(pulse->x, pulse->y, akx->x, akx->y);
+         if (r >= map_get_dist(x, y, akx->x, akx->y))
          {
-            agl = angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
+            agl = map_get_angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
             if (agl <= (pulse->angle / 2))
             {
                result += akx->energy / (1 + r * pulse->angle / 2);

+ 1 - 1
server/time.c

@@ -9,7 +9,7 @@
 
 void timer_timeout(int foo)
 {
-   printf("%d: timeout.\n", gl_player->team_id);
+   printf("%d: timeout.\n", glbPlayer->team_id);
    fflush(stdout);
    kill(getpid(), SIGKILL);
 }