From 003fc8fff2eb5dec7f2d9d699b124c9eaf109713 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 c765cfa9fd..4f29810e29 100644 --- a/common/fc_types.h +++ b/common/fc_types.h @@ -116,6 +116,10 @@ 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 ded74b7b38..934218786a 100644 --- a/meson.build +++ b/meson.build @@ -1461,6 +1461,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 2a3218c756..5df9a43cd3 100644 --- a/server/scripting/Makefile.am +++ b/server/scripting/Makefile.am @@ -22,6 +22,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..85e7445974 --- /dev/null +++ b/server/scripting/api_server_counters.c @@ -0,0 +1,64 @@ +/***************************************************************************** + 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" + + +/**********************************************************************//** + Increase value of the given counter for given city. +**************************************************************************/ +void api_counter_increase(lua_State *L, Counter *c, City *city) +{ + LUASCRIPT_CHECK_ARG_NIL(L, city, 3, City, ); + + if (CB_USER != c->type) { + fc_print("[CB_USER == c->type] Lua: cannot change non-user counter"); + return; + } + + city->counter_values[counter_index(c)]++; + + city_counters_refresh(city); +} + +/**********************************************************************//** + Reset value of the given counter for given city. +**************************************************************************/ +void api_counter_zero(lua_State *L, Counter *c, City *city) +{ + LUASCRIPT_CHECK_ARG_NIL(L, city, 3, City, ); + + if (CB_USER != c->type) { + fc_print("[CB_USER == c->type] Lua: cannot change non-user counter"); + return; + } + + 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..d4500ae02a --- /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 /* FCAPI_GAME_COUNTERS_H */ diff --git a/server/scripting/tolua_server.pkg b/server/scripting/tolua_server.pkg index 8db60fdd09..09b55f7538 100644 --- a/server/scripting/tolua_server.pkg +++ b/server/scripting/tolua_server.pkg @@ -56,6 +56,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.43.0