Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add files via upload #490

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add files via upload #490

wants to merge 2 commits into from

Conversation

EnockNitti
Copy link

Adding AStar for improved function when using "goto" command

@SWY1985
Copy link
Owner

SWY1985 commented Aug 22, 2018

Hi! Thanks for your Pull Request. I would love to merge the AStar code into CivOne, but it would need to be an optional patch that can be enabled via the Setup screen, with the 'original' algorithm being the default.
If you need pointers on how to make these changes, please let me know.

@EnockNitti
Copy link
Author

EnockNitti commented Aug 23, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Aug 23, 2018

In the file src/Settings.cs, you can add a patch setting, according to existing patches:

CivOne/src/Settings.cs

Lines 133 to 229 in b6db419

// Patches
internal bool RevealWorld
{
get => _revealWorld;
set
{
_revealWorld = value;
SetSetting("RevealWorld", _revealWorld ? "1" : "0");
Common.ReloadSettings = true;
}
}
internal bool RightSideBar
{
get => _rightSideBar;
set
{
_rightSideBar = value;
SetSetting("SideBar", _rightSideBar ? "1" : "0");
Common.ReloadSettings = true;
}
}
internal bool DebugMenu
{
get => _debugMenu;
set
{
_debugMenu = value;
SetSetting("DebugMenu", _debugMenu ? "1" : "0");
Common.ReloadSettings = true;
}
}
internal bool DeityEnabled
{
get => _deityEnabled;
set
{
_deityEnabled = value;
SetSetting("DeityEnabled", _deityEnabled ? "1" : "0");
Common.ReloadSettings = true;
}
}
internal bool ArrowHelper
{
get => _arrowHelper;
set
{
_arrowHelper = value;
SetSetting("ArrowHelper", _arrowHelper ? "1" : "0");
Common.ReloadSettings = true;
}
}
internal bool CustomMapSize
{
get => _customMapSize;
set
{
_customMapSize = value;
SetSetting("CustomMapSize", _customMapSize ? "1" : "0");
Common.ReloadSettings = true;
}
}
public CursorType CursorType
{
get
{
if (Runtime.Settings.Free && _cursorType == CursorType.Default)
return CursorType.Builtin;
return _cursorType;
}
internal set
{
_cursorType = value;
string saveValue = ((int)_cursorType).ToString();
SetSetting("CursorType", saveValue);
Cursor.ClearCache();
Common.ReloadSettings = true;
}
}
internal DestroyAnimation DestroyAnimation
{
get => _destroyAnimation;
set
{
_destroyAnimation = value;
string saveValue = ((int)_destroyAnimation).ToString();
SetSetting("DestroyAnimation", saveValue);
Common.ReloadSettings = true;
}
}

In the file src/Screens/Setup.cs, you need to add a menu entry for the patch:

CivOne/src/Screens/Setup.cs

Lines 176 to 235 in b6db419

private void PatchesMenu(int activeItem = 0) => CreateMenu("Patches", activeItem,
MenuItem.Create($"Reveal world: {Settings.RevealWorld.YesNo()}").OnSelect(GotoMenu(RevealWorldMenu)),
MenuItem.Create($"Side bar location: {(Settings.RightSideBar ? "right" : "left")}").OnSelect(GotoMenu(SideBarMenu)),
MenuItem.Create($"Debug menu: {Settings.DebugMenu.YesNo()}").OnSelect(GotoMenu(DebugMenuMenu)),
MenuItem.Create($"Cursor type: {Settings.CursorType.ToText()}").OnSelect(GotoMenu(CursorTypeMenu)),
MenuItem.Create($"Destroy animation: {Settings.DestroyAnimation.ToText()}").OnSelect(GotoMenu(DestroyAnimationMenu)),
MenuItem.Create($"Enable Deity difficulty: {Settings.DeityEnabled.YesNo()}").OnSelect(GotoMenu(DeityEnabledMenu)),
MenuItem.Create($"Enable (no keypad) arrow helper: {Settings.ArrowHelper.YesNo()}").OnSelect(GotoMenu(ArrowHelperMenu)),
MenuItem.Create($"Custom map sizes (experimental): {Settings.CustomMapSize.YesNo()}").OnSelect(GotoMenu(CustomMapSizeMenu)),
MenuItem.Create("Back").OnSelect(GotoMenu(MainMenu, 1))
);
private void RevealWorldMenu() => CreateMenu("Reveal world", GotoMenu(PatchesMenu, 0),
MenuItem.Create($"{false.YesNo()} (default)").OnSelect((s, a) => Settings.RevealWorld = false).SetActive(() => !Settings.RevealWorld),
MenuItem.Create(true.YesNo()).OnSelect((s, a) => Settings.RevealWorld = true).SetActive(() => Settings.RevealWorld),
MenuItem.Create("Back")
);
private void SideBarMenu() => CreateMenu("Side bar location", GotoMenu(PatchesMenu, 1),
MenuItem.Create("Left (default)").OnSelect((s, a) => Settings.RightSideBar = false).SetActive(() => !Settings.RightSideBar),
MenuItem.Create("Right").OnSelect((s, a) => Settings.RightSideBar = true).SetActive(() => Settings.RightSideBar),
MenuItem.Create("Back")
);
private void DebugMenuMenu() => CreateMenu("Show debug menu", GotoMenu(PatchesMenu, 2),
MenuItem.Create($"{false.YesNo()} (default)").OnSelect((s, a) => Settings.DebugMenu = false).SetActive(() => !Settings.DebugMenu),
MenuItem.Create(true.YesNo()).OnSelect((s, a) => Settings.DebugMenu = true).SetActive(() => Settings.DebugMenu),
MenuItem.Create("Back")
);
private void CursorTypeMenu() => CreateMenu("Mouse cursor type", GotoMenu(PatchesMenu, 3),
MenuItem.Create(Default.ToText()).OnSelect((s, a) => Settings.CursorType = Default).SetActive(() => Settings.CursorType == Default && FileSystem.DataFilesExist(FileSystem.MouseCursorFiles)).SetEnabled(FileSystem.DataFilesExist(FileSystem.MouseCursorFiles)),
MenuItem.Create(Builtin.ToText()).OnSelect((s, a) => Settings.CursorType = Builtin).SetActive(() => Settings.CursorType == Builtin || (Settings.CursorType == Default && !FileSystem.DataFilesExist(FileSystem.MouseCursorFiles))),
MenuItem.Create(Native.ToText()).OnSelect((s, a) => Settings.CursorType = Native).SetActive(() => Settings.CursorType == Native),
MenuItem.Create("Back")
);
private void DestroyAnimationMenu() => CreateMenu("Destroy animation", GotoMenu(PatchesMenu, 4),
MenuItem.Create(Sprites.ToText()).OnSelect((s, a) => Settings.DestroyAnimation = Sprites).SetActive(() => Settings.DestroyAnimation == Sprites),
MenuItem.Create(Noise.ToText()).OnSelect((s, a) => Settings.DestroyAnimation = Noise).SetActive(() => Settings.DestroyAnimation == Noise),
MenuItem.Create("Back")
);
private void DeityEnabledMenu() => CreateMenu("Enable Deity difficulty", GotoMenu(PatchesMenu, 5),
MenuItem.Create($"{false.YesNo()} (default)").OnSelect((s, a) => Settings.DeityEnabled = false).SetActive(() => !Settings.DeityEnabled),
MenuItem.Create(true.YesNo()).OnSelect((s, a) => Settings.DeityEnabled = true).SetActive(() => Settings.DeityEnabled),
MenuItem.Create("Back")
);
private void ArrowHelperMenu() => CreateMenu("Enable (no keypad) arrow helper", GotoMenu(PatchesMenu, 6),
MenuItem.Create($"{false.YesNo()} (default)").OnSelect((s, a) => Settings.ArrowHelper = false).SetActive(() => !Settings.ArrowHelper),
MenuItem.Create(true.YesNo()).OnSelect((s, a) => Settings.ArrowHelper = true).SetActive(() => Settings.ArrowHelper),
MenuItem.Create("Back")
);
private void CustomMapSizeMenu() => CreateMenu("Custom map sizes (experimental)", GotoMenu(PatchesMenu, 7),
MenuItem.Create($"{false.YesNo()} (default)").OnSelect((s, a) => Settings.CustomMapSize = false).SetActive(() => !Settings.CustomMapSize),
MenuItem.Create(true.YesNo()).OnSelect((s, a) => Settings.CustomMapSize = true).SetActive(() => Settings.CustomMapSize),
MenuItem.Create("Back")
);

It would be best to create a new Enum for use with your patch, for example:

public enum PathFindingAlgorithm
{
    Default = 0,
    AStar = 1,
}

Then, you can create a switch statement where you check the value of Settings.{yourSettingName} or Settings.Instance.{yourSettingName}, and add the current en the new code under the appropriate case.

I think this should work.

@EnockNitti
Copy link
Author

EnockNitti commented Aug 23, 2018 via email

@EnockNitti
Copy link
Author

EnockNitti commented Aug 29, 2018 via email

@EnockNitti
Copy link
Author

EnockNitti commented Aug 29, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Aug 30, 2018

Hi! I'm sorry I didn't have time to review your changes yet. Hopefully tomorrow.

I had a quick look. The PathFinding setting gets saved, but not loaded on startup. You should add the GetSettings code in the Settings constructor, here:

CivOne/src/Settings.cs

Lines 392 to 424 in b6db419

private Settings()
{
CreateDirectories();
// Read settings
GetSetting("WindowTitle", ref _windowTitle);
GetSetting<GraphicsMode>("GraphicsMode", ref _graphicsMode);
GetSetting("FullScreen", ref _fullScreen);
GetSetting("SideBar", ref _rightSideBar);
GetSetting("Scale", ref _scale, 1, 4);
GetSetting<AspectRatio>("AspectRatio", ref _aspectRatio);
GetSetting("Sound", ref _sound);
if (!GetSetting("ExpandWidth", ref _scale, 320, 512) || !GetSetting("ExpandHeight", ref _scale, 200, 384))
{
_expandWidth = -1;
_expandHeight = -1;
}
GetSetting("RevealWorld", ref _revealWorld);
GetSetting("DebugMenu", ref _debugMenu);
GetSetting("DeityEnabled", ref _deityEnabled);
GetSetting("ArrowHelper", ref _arrowHelper);
GetSetting("CustomMapSize", ref _customMapSize);
GetSetting<CursorType>("CursorType", ref _cursorType);
GetSetting<DestroyAnimation>("DestroyAnimation", ref _destroyAnimation);
GetSetting<GameOption>("GameInstantAdvice", ref _instantAdvice);
GetSetting<GameOption>("GameAutoSave", ref _autoSave);
GetSetting<GameOption>("GameEndOfTurn", ref _endOfTurn);
GetSetting<GameOption>("GameAnimations", ref _animations);
GetSetting<GameOption>("GameSound", ref _sound);
GetSetting<GameOption>("GameEnemyMoves", ref _enemyMoves);
GetSetting<GameOption>("GameCivilopediaText", ref _civilopediaText);
GetSetting<GameOption>("GamePalace", ref _palace);
}

@EnockNitti
Copy link
Author

EnockNitti commented Aug 30, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Aug 30, 2018

I noticed this too, it looks like GitHub treats them as new files, and on GitHub it looks like the files in the root folder instead of the "src" folder, but that's not what I see when I look at your repository. I don't know why it's doing that.

If you've used VScode, the line endings should be correct.

Can you please add (copy) the file header to the new .cs files that you've added? I think I'll be able to review and merge your code tomorrow evening.

@EnockNitti
Copy link
Author

EnockNitti commented Sep 8, 2018 via email

@EnockNitti
Copy link
Author

EnockNitti commented Sep 30, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Oct 1, 2018

Are you still working with this project or has other aspects of life got higher priority ?

Hi John,

At the moment, work on this project is not the highest priority for me. The project is not dead, but I've got loads of other things (mainly my work) taking up my time. I'm so sorry.
I'll try to review your code later this week, and I am hoping (intending) to get some work done this month.

@EnockNitti
Copy link
Author

EnockNitti commented Oct 1, 2018 via email

@EnockNitti
Copy link
Author

EnockNitti commented Oct 3, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Oct 3, 2018

There are known problems with loading/saving games.
Can you report a bug for this, please?

@EnockNitti
Copy link
Author

EnockNitti commented Oct 3, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Oct 3, 2018

Please, report a bug for this: https://github.com/SWY1985/CivOne/issues

@EnockNitti
Copy link
Author

EnockNitti commented Oct 3, 2018 via email

@SWY1985
Copy link
Owner

SWY1985 commented Apr 10, 2019

Hi, I'm so sorry, I haven't had a lot of time lately. I'm getting back into the code and I will merge your code soon.

@EnockNitti
Copy link
Author

EnockNitti commented Apr 11, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants