Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.

Commit 1611dcd

Browse files
committed
Add Nullkiller AI support
1 parent a13dc5c commit 1611dcd

15 files changed

+156
-12
lines changed

project/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath "com.android.tools.build:gradle:7.0.1"
8+
classpath 'com.android.tools.build:gradle:7.3.0'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Aug 31 19:45:20 EEST 2021
1+
#Tue Sep 27 21:00:27 EEST 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

project/vcmi-app/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ android {
3434
LoadSigningConfig(PROJECT_PATH_BASE)
3535
}
3636

37+
sourceSets {
38+
main {
39+
jniLibs.srcDirs = ["${PROJECT_PATH_BASE}/ext-output"]
40+
}
41+
}
42+
3743
buildTypes {
3844
release {
3945
minifyEnabled false
@@ -56,6 +62,7 @@ android {
5662

5763
externalNativeBuild {
5864
cmake {
65+
version "3.18.0+"
5966
path file('cmake-scripts/CMakeLists.txt')
6067
}
6168
}
@@ -71,6 +78,7 @@ android {
7178
dimension "vcmi"
7279
externalNativeBuild {
7380
cmake {
81+
version "3.18+"
7482
targets "vcmi",
7583
"vcmiserver",
7684
"vcmiclient"
@@ -81,6 +89,7 @@ android {
8189
dimension "vcmi"
8290
externalNativeBuild {
8391
cmake {
92+
version "3.18+"
8493
targets "boost-datetime",
8594
"boost-system",
8695
"boost-filesystem",
@@ -96,6 +105,7 @@ android {
96105
dimension "vcmi"
97106
externalNativeBuild {
98107
cmake {
108+
version "3.18+"
99109
targets "boost-datetime",
100110
"boost-system",
101111
"boost-filesystem",

project/vcmi-app/cmake-scripts/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.4.1)
1+
cmake_minimum_required(VERSION 3.17)
22

33
set(CMAKE_MODULE_PATH "${VCMI_ROOT}/project/vcmi-app/cmake-scripts;${VCMI_ROOT}/ext/vcmi/cmake_modules")
44
include(VCMIUtils)

project/vcmi-app/cmake-scripts/lib.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ project(vcmi)
22

33
add_subdirectory(${VCMI_PATH_VCMI}/AI/BattleAI ${VCMI_PATH_VCMI}/out/battleai)
44
add_subdirectory(${VCMI_PATH_VCMI}/AI/VCAI ${VCMI_PATH_VCMI}/out/vcai)
5+
add_subdirectory(${VCMI_PATH_VCMI}/AI/Nullkiller ${VCMI_PATH_VCMI}/out/nullkiller)
56
get_directory_property(LOCAL_BATTLEAI_SRCS DIRECTORY ${VCMI_PATH_VCMI}/AI/BattleAI DEFINITION battleAI_SRCS)
67
get_directory_property(LOCAL_VCAI_SRCS DIRECTORY ${VCMI_PATH_VCMI}/AI/VCAI DEFINITION VCAI_SRCS)
8+
get_directory_property(LOCAL_NULLKILLER_SRCS DIRECTORY ${VCMI_PATH_VCMI}/AI/Nullkiller DEFINITION Nullkiller_SRCS)
79
list(REMOVE_ITEM LOCAL_BATTLEAI_SRCS main.cpp)
810
list(REMOVE_ITEM LOCAL_VCAI_SRCS main.cpp)
11+
list(REMOVE_ITEM LOCAL_NULLKILLER_SRCS main.cpp)
912
prepend(VCMILIB_ADDITIONAL_SRC_BATTLEAI ${VCMI_PATH_VCMI}/AI/BattleAI ${LOCAL_BATTLEAI_SRCS})
1013
prepend(VCMILIB_ADDITIONAL_SRC_VCAI ${VCMI_PATH_VCMI}/AI/VCAI ${LOCAL_VCAI_SRCS})
14+
prepend(VCMILIB_ADDITIONAL_SRC_NULLKILLER ${VCMI_PATH_VCMI}/AI/Nullkiller ${LOCAL_NULLKILLER_SRCS})
1115

12-
set(VCMILIB_ADDITIONAL_SOURCES ${VCMILIB_ADDITIONAL_SRC_BATTLEAI} ${VCMILIB_ADDITIONAL_SRC_VCAI})
16+
set(VCMILIB_ADDITIONAL_SOURCES ${VCMILIB_ADDITIONAL_SRC_BATTLEAI} ${VCMILIB_ADDITIONAL_SRC_VCAI} ${VCMILIB_ADDITIONAL_SRC_NULLKILLER})
17+
18+
set(MAIN_LIB_DIR "${VCMI_PATH_VCMI}/lib")
19+
include(VCMI_lib)
1320

1421
add_subdirectory(${VCMI_PATH_VCMI}/lib ${VCMI_PATH_VCMI}/out/lib)
1522

@@ -20,5 +27,6 @@ target_include_directories(vcmi PRIVATE ${VCMI_PATH_VCMI}/include)
2027
target_include_directories(vcmi PRIVATE ${VCMI_PATH_VCMI})
2128
target_include_directories(vcmi PRIVATE ${VCMI_PATH_VCMI}/AI/FuzzyLite/fuzzylite)
2229
target_include_directories(vcmi PRIVATE ${VCMI_ROOT}/ext/SDL2/core/include)
30+
target_include_directories(vcmi PRIVATE ${VCMI_ROOT}/ext/oneTBB/include)
2331

2432
set_target_properties(vcmi PROPERTIES OUTPUT_NAME vcmi-lib)

project/vcmi-app/cmake-scripts/main-app.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function(build_vcmi)
5151
add_library(Boost::boost INTERFACE IMPORTED)
5252
set(FFMPEG_LIBRARIES ffmpeg::avcodec ffmpeg::avdevice ffmpeg::avfilter ffmpeg::avformat ffmpeg::avutil ffmpeg::swresample ffmpeg::swscale smpeg2::smpeg2 postproc::postproc x264::x264)
5353
set(SDL_CLIENT_LIBRARIES SDL2::SDL2 SDL2::Image SDL2::Mixer SDL2::TTF)
54-
set(SYSTEM_LIBS ${SYSTEM_LIBS} ${syslib_log} ZLIB::ZLIB fuzzylite::fuzzylite)
54+
set(SYSTEM_LIBS ${SYSTEM_LIBS} ${syslib_log} ZLIB::ZLIB fuzzylite::fuzzylite TBB::tbb)
5555
set(Boost_LIBRARIES Boost::system Boost::filesystem Boost::date_time Boost::thread Boost::program_options Boost::locale)
5656

5757
include(lib)
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
337452bc70fe7b22b869c4e38095f3f0
1+
437bf5959de11659d1d06341aaaa4390

project/vcmi-app/src/main/java/eu/vcmi/vcmi/ActivityLauncher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import androidx.core.app.ActivityCompat;
2323
import eu.vcmi.vcmi.content.AsyncLauncherInitialization;
24+
import eu.vcmi.vcmi.settings.AdventureAiController;
2425
import eu.vcmi.vcmi.settings.CodepageSettingController;
2526
import eu.vcmi.vcmi.settings.DoubleConfig;
2627
import eu.vcmi.vcmi.settings.LauncherSettingController;
@@ -54,6 +55,7 @@ public class ActivityLauncher extends ActivityWithToolbar
5455
private LauncherSettingController<Float, SharedPrefs> mCtrlPointerMulti;
5556
private LauncherSettingController<Integer, Config> mCtrlSoundVol;
5657
private LauncherSettingController<Integer, Config> mCtrlMusicVol;
58+
private LauncherSettingController<String, Config> mAiController;
5759

5860
private final AsyncLauncherInitialization.ILauncherCallbacks mInitCallbacks = new AsyncLauncherInitialization.ILauncherCallbacks()
5961
{
@@ -185,6 +187,7 @@ private void initSettingsGui()
185187
mCtrlPointerMulti = new PointerMultiplierSettingController(this).init(R.id.launcher_btn_pointer_multi, mPrefs);
186188
mCtrlSoundVol = new SoundSettingController(this).init(R.id.launcher_btn_volume_sound, mConfig);
187189
mCtrlMusicVol = new MusicSettingController(this).init(R.id.launcher_btn_volume_music, mConfig);
190+
mAiController = new AdventureAiController(this).init(R.id.launcher_btn_adventure_ai, mConfig);
188191

189192
mActualSettings.clear();
190193
mActualSettings.add(mCtrlCodepage);
@@ -193,6 +196,7 @@ private void initSettingsGui()
193196
mActualSettings.add(mCtrlPointerMulti);
194197
mActualSettings.add(mCtrlSoundVol);
195198
mActualSettings.add(mCtrlMusicVol);
199+
mActualSettings.add(mAiController);
196200

197201
mCtrlStart.hide(); // start is initially hidden, until we confirm that everything is okay via AsyncLauncherInitialization
198202
}
@@ -249,6 +253,7 @@ private void onConfigUpdated()
249253
updateCtrlConfig(mCtrlPointerMulti, mPrefs);
250254
updateCtrlConfig(mCtrlSoundVol, mConfig);
251255
updateCtrlConfig(mCtrlMusicVol, mConfig);
256+
updateCtrlConfig(mAiController, mConfig);
252257
}
253258

254259
private <TSetting, TConf> void updateCtrlConfig(

project/vcmi-app/src/main/java/eu/vcmi/vcmi/Config.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,19 @@ public class Config
3030
public boolean mSwipeEnabled;
3131
public int mVolumeSound;
3232
public int mVolumeMusic;
33+
private String adventureAi;
3334
private JSONObject mRawObject;
3435

3536
private boolean mIsModified;
3637

37-
private static JSONObject accessGeneralNode(final JSONObject baseObj)
38+
private static JSONObject accessNode(final JSONObject baseObj, String type)
3839
{
3940
if (baseObj == null)
4041
{
4142
return null;
4243
}
4344

44-
return baseObj.optJSONObject("general");
45+
return baseObj.optJSONObject(type);
4546
}
4647

4748
private static JSONObject accessScreenResNode(final JSONObject baseObj)
@@ -74,11 +75,14 @@ public static Config load(final JSONObject obj)
7475
{
7576
Log.v("loading config from json: " + obj.toString());
7677
final Config config = new Config();
77-
final JSONObject general = accessGeneralNode(obj);
78+
final JSONObject general = accessNode(obj, "general");
79+
final JSONObject server = accessNode(obj, "server");
7880
config.mCodepage = loadEntry(general, "encoding", DEFAULT_CODEPAGE);
7981
config.mVolumeSound = loadEntry(general, "sound", DEFAULT_SOUND_VALUE);
8082
config.mVolumeMusic = loadEntry(general, "music", DEFAULT_MUSIC_VALUE);
8183
config.mSwipeEnabled = loadEntry(general, "swipe", false);
84+
config.adventureAi = loadEntry(server, "playerAI", "VCAI");
85+
8286
final JSONObject screenRes = accessScreenResNode(obj);
8387
config.mResolutionWidth = loadEntry(screenRes, "width", DEFAULT_SCREEN_RES_W);
8488
config.mResolutionHeight = loadEntry(screenRes, "height", DEFAULT_SCREEN_RES_H);
@@ -145,29 +149,51 @@ private boolean needsSaving(final File location)
145149

146150
private String toJson() throws JSONException
147151
{
148-
final JSONObject generalNode = accessGeneralNode(mRawObject);
152+
final JSONObject generalNode = accessNode(mRawObject, "general");
153+
final JSONObject serverNode = accessNode(mRawObject, "server");
149154
final JSONObject screenResNode = accessScreenResNode(mRawObject);
150155

151156
final JSONObject root = mRawObject == null ? new JSONObject() : mRawObject;
152157
final JSONObject general = generalNode == null ? new JSONObject() : generalNode;
153158
final JSONObject video = new JSONObject();
154159
final JSONObject screenRes = screenResNode == null ? new JSONObject() : screenResNode;
160+
final JSONObject server = serverNode == null ? new JSONObject() : serverNode;
161+
155162
if (mCodepage != null)
156163
{
157164
general.put("encoding", mCodepage);
158165
}
166+
159167
general.put("swipe", mSwipeEnabled);
160168
general.put("music", mVolumeMusic);
161169
general.put("sound", mVolumeSound);
162170
root.put("general", general);
163171

172+
if(this.adventureAi != null)
173+
{
174+
server.put("playerAI", this.adventureAi);
175+
root.put("server", server);
176+
}
177+
164178
if (mResolutionHeight > 0 && mResolutionWidth > 0)
165179
{
166180
screenRes.put("width", mResolutionWidth);
167181
screenRes.put("height", mResolutionHeight);
168182
video.put("screenRes", screenRes);
169183
root.put("video", video);
170184
}
185+
171186
return root.toString();
172187
}
188+
189+
public void setAdventureAi(String ai)
190+
{
191+
adventureAi = ai;
192+
mIsModified = true;
193+
}
194+
195+
public String getAdventureAi()
196+
{
197+
return this.adventureAi == null ? "VCAI" : this.adventureAi;
198+
}
173199
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package eu.vcmi.vcmi.settings;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
import eu.vcmi.vcmi.Config;
5+
import eu.vcmi.vcmi.R;
6+
7+
/**
8+
* @author F
9+
*/
10+
public class AdventureAiController extends LauncherSettingWithDialogController<String, Config>
11+
{
12+
public AdventureAiController(final AppCompatActivity activity)
13+
{
14+
super(activity);
15+
}
16+
17+
@Override
18+
protected LauncherSettingDialog<String> dialog()
19+
{
20+
return new AdventureAiSelectionDialog();
21+
}
22+
23+
@Override
24+
public void onItemChosen(final String item)
25+
{
26+
mConfig.setAdventureAi(item);
27+
updateContent();
28+
}
29+
30+
@Override
31+
protected String mainText()
32+
{
33+
return mActivity.getString(R.string.launcher_btn_adventure_ai_title);
34+
}
35+
36+
@Override
37+
protected String subText()
38+
{
39+
if (mConfig == null)
40+
{
41+
return "";
42+
}
43+
44+
return mConfig.getAdventureAi();
45+
}
46+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package eu.vcmi.vcmi.settings;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import eu.vcmi.vcmi.R;
7+
8+
/**
9+
* @author F
10+
*/
11+
public class AdventureAiSelectionDialog extends LauncherSettingDialog<String>
12+
{
13+
private static final List<String> AVAILABLE_AI = new ArrayList<>();
14+
15+
static
16+
{
17+
AVAILABLE_AI.add("VCAI");
18+
AVAILABLE_AI.add("Nullkiller");
19+
}
20+
21+
public AdventureAiSelectionDialog()
22+
{
23+
super(AVAILABLE_AI);
24+
}
25+
26+
@Override
27+
protected int dialogTitleResId()
28+
{
29+
return R.string.launcher_btn_adventure_ai_title;
30+
}
31+
32+
@Override
33+
protected CharSequence itemName(final String item)
34+
{
35+
return item;
36+
}
37+
}

project/vcmi-app/src/main/res/layout/activity_launcher.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
android:id="@+id/launcher_btn_res"
7272
layout="@layout/inc_launcher_btn" />
7373

74+
<include
75+
android:id="@+id/launcher_btn_adventure_ai"
76+
layout="@layout/inc_launcher_btn" />
77+
7478
<include
7579
android:id="@+id/launcher_btn_cp"
7680
layout="@layout/inc_launcher_btn" />

project/vcmi-app/src/main/res/raw/authors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VCMI PROJECT CODE CONTRIBUTORS:
1+
VCMI PROJECT CODE CONTRIBUTORS:
22

33
Michał Urbańczyk aka Tow, <[email protected]>
44
* project originator; programming, making releases, website
@@ -78,3 +78,9 @@ Andrii Danylchenko
7878

7979
Dmitry Orlov, <[email protected]>
8080
* special buildings support in fan towns, new features and bug fixes
81+
82+
Andrey Cherkas aka nordsoft, <[email protected]>
83+
* new terrain support, random map generator features and various bug fixes
84+
85+
Andrey Filipenkov aka kambala-decapitator, <[email protected]>
86+
* iOS support, macOS improvements, various bug fixes

project/vcmi-app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<string name="launcher_btn_pointermulti_subtitle">Currently: %1$s</string>
2424
<string name="launcher_btn_sound_title">Sound volume</string>
2525
<string name="launcher_btn_music_title">Music volume</string>
26+
<string name="launcher_btn_adventure_ai">Adventure AI</string>
27+
<string name="launcher_btn_adventure_ai_title">Change adventure AI</string>
2628
<string name="launcher_version">Current launcher version: %1$s</string>
2729
<string name="launcher_error_vcmi_data_root_created">VCMI created folder \'%1$s\' (in %2$s). Place your H3 data files there (so that you have a folder %1$s/Data and %1$s/Mp3 etc) and restart the application.</string>
2830
<string name="launcher_error_vcmi_data_root_failed">Could not create VCMI data folder in %1$s.</string>

0 commit comments

Comments
 (0)