From d3b4f237ec3f6b89da79227c0c32d7e2537640b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Thu, 22 Jun 2023 18:15:10 +0200 Subject: [PATCH] =?UTF-8?q?!OSDN:#47828:S=C5=82awomir=20Lach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add user counter support diff --git a/common/fc_types.h b/common/fc_types.h index 31d71745d3..b247317c22 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -118,6 +118,8 @@ enum output_type_id { #define SPECENUM_VALUE2NAME "Celebration" #define SPECENUM_VALUE3 CB_CITY_DISORDER_TURNS #define SPECENUM_VALUE3NAME "Disorder" +#define SPECENUM_VALUE4 CB_USER +#define SPECENUM_VALUE4NAME "User" #define SPECENUM_COUNT COUNTER_BEHAVIOUR_LAST #include "specenum_gen.h" diff --git a/meson.build b/meson.build index 04a4faed5a..88786b5d04 100644 --- a/meson.build +++ b/meson.build @@ -1161,6 +1161,8 @@ server_lib = static_library('fc_server', 'server/scripting/api_fcdb_auth.c', 'server/scripting/api_fcdb_base.c', 'server/scripting/api_fcdb_specenum.c', + 'server/scripting/api_server_counters.c', + 'server/scripting/api_server_counters.h', 'server/scripting/api_server_base.c', 'server/scripting/api_server_edit.c', 'server/scripting/api_server_game_methods.c', diff --git a/server/scripting/Makefile.am b/server/scripting/Makefile.am index ba6aae7e65..5e27d4d1fe 100644 --- a/server/scripting/Makefile.am +++ b/server/scripting/Makefile.am @@ -21,6 +21,8 @@ AM_CPPFLAGS = \ # tolua_[fcdb|server]_gen.[ch] are now distributed to aid in cross-compiling. # See PR#13571. dist_libscripting_server_la_SOURCES = \ + api_server_counters.c \ + api_server_counters.h \ api_server_base.c \ api_server_base.h \ api_server_edit.c \ diff --git a/server/scripting/api_server_counters.c b/server/scripting/api_server_counters.c new file mode 100644 index 0000000000..5a4b2021d5 --- /dev/null +++ b/server/scripting/api_server_counters.c @@ -0,0 +1,47 @@ +/***************************************************************************** + Freeciv - Copyright (C) 2023 - The Freeciv Project + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*****************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +/* common */ +#include "city.h" +#include "counters.h" +#include "name_translation.h" + +/* common/scriptcore */ +#include "luascript.h" + +/* server */ +#include "cityturn.h" + +#include "api_server_counters.h" + +void api_counter_increase(lua_State *L,Counter *c, City *city) +{ + LUASCRIPT_CHECK_ARG_NIL(L, city, 3, City, ); + + city->counter_values[counter_index(c)]++; + + city_counters_refresh(city); +} + +void api_counter_zero(lua_State *L,Counter *c, City *city) +{ + LUASCRIPT_CHECK_ARG_NIL(L, city, 3, City, ); + + city->counter_values[counter_index(c)] = 0; + + city_counters_refresh(city); +} diff --git a/server/scripting/api_server_counters.h b/server/scripting/api_server_counters.h new file mode 100644 index 0000000000..3404b22334 --- /dev/null +++ b/server/scripting/api_server_counters.h @@ -0,0 +1,24 @@ +/***************************************************************************** + Freeciv - Copyright (C) 2023 - The Freeciv Project + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*****************************************************************************/ + +#ifndef FC__API_GAME_COUNTERS_H +#define FC__API_GAME_COUNTERS_H + +/* common/scriptcore */ +#include "luascript_types.h" + +struct lua_State; + +void api_counter_increase(lua_State *L,Counter *c, City *city); +void api_counter_zero(lua_State *L,Counter *c, City *city); +#endif diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index e9115de6bd..4dda9b069c 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -32,6 +32,7 @@ $#include "commands.h" $#include "console.h" /* server/scripting */ +$#include "api_server_counters.h" $#include "api_server_edit.h" $#include "api_server_base.h" $#include "api_server_luadata.h" @@ -56,6 +57,11 @@ module server { } } +module Counter { + void api_counter_increase @ increase (lua_State *L,Counter *c, City *city); + void api_counter_zero @ zero (lua_State *L,Counter *c, City *city); +} + /* Notify module. */ module notify { void api_notify_embassies_msg -- 2.41.0