Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Onuralp SEZER
Game Library
Commits
9ad8b0a5
Commit
9ad8b0a5
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
port more of the action system over for use in AI module
parent
94e7f7d9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/fggl/grid/actions.hpp
+77
-0
77 additions, 0 deletions
include/fggl/grid/actions.hpp
include/fggl/grid/hexgrid.hpp
+7
-52
7 additions, 52 deletions
include/fggl/grid/hexgrid.hpp
include/fggl/grid/tokens.hpp
+88
-0
88 additions, 0 deletions
include/fggl/grid/tokens.hpp
with
172 additions
and
52 deletions
include/fggl/grid/actions.hpp
0 → 100644
+
77
−
0
View file @
9ad8b0a5
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 19/12/22.
//
#ifndef FGGL_GRID_ACTIONS_H
#define FGGL_GRID_ACTIONS_H
#include
<cstdint>
#include
<variant>
#include
"fggl/grid/hexagon.hpp"
#include
"fggl/grid/tokens.hpp"
#include
"fggl/util/safety.hpp"
namespace
fggl
::
grid
{
template
<
typename
State
,
typename
Target
>
class
ActionType
;
template
<
typename
State
,
typename
Target
>
class
Action
{
public:
virtual
void
progress
(
State
*
state
)
=
0
;
virtual
bool
isDone
()
=
0
;
};
template
<
typename
State
,
typename
Target
>
class
InstantAction
:
public
Action
<
State
,
Target
>
{
public:
void
progress
(
State
*
state
)
final
;
bool
isDone
()
final
;
private:
ActionType
<
State
,
Target
>*
m_action
;
TokenIdentifer
m_actor
;
Target
m_target
;
};
template
<
typename
State
,
typename
Target
>
class
DurativeAction
:
public
Action
<
State
,
Target
>
{
public:
void
progress
(
State
*
state
)
final
;
bool
isDone
()
final
;
private:
ActionType
<
State
,
Target
>*
m_action
;
TokenIdentifer
m_actor
;
Target
m_target
;
uint64_t
m_completionRound
;
};
template
<
typename
State
,
typename
Target
>
class
ActionType
{
public:
virtual
bool
canApply
(
const
State
*
state
,
TokenIdentifer
actor
,
Target
target
)
=
0
;
virtual
void
apply
(
State
*
state
,
TokenIdentifer
actor
,
Target
target
)
=
0
;
virtual
Action
<
State
,
Target
>
ground
(
TokenIdentifer
actor
,
Target
target
)
=
0
;
};
}
// namespace fggl::grid
#endif //FGGL_GRID_ACTIONS_H
This diff is collapsed.
Click to expand it.
include/fggl/grid/hexgrid.hpp
+
7
−
52
View file @
9ad8b0a5
...
@@ -23,65 +23,20 @@
...
@@ -23,65 +23,20 @@
#include
<set>
#include
<set>
#include
<optional>
#include
<optional>
#include
<utility>
#include
<utility>
#include
<variant>
#include
"fggl/grid/hexagon.hpp"
#include
"fggl/grid/hexagon.hpp"
#include
"fggl/grid/tokens.hpp"
#include
"fggl/grid/actions.hpp"
#include
"fggl/math/types.hpp"
#include
"fggl/math/types.hpp"
namespace
fggl
::
grid
{
namespace
fggl
::
grid
{
class
TokenType
{
class
HexGrid
;
public:
using
PropType
=
int64_t
;
inline
void
setProperty
(
util
::
GUID
name
,
PropType
newVal
)
{
m_properties
[
name
]
=
newVal
;
}
[[
nodiscard
]]
inline
PropType
getProperty
(
util
::
GUID
name
,
PropType
unsetVal
=
0
)
const
{
try
{
return
m_properties
.
at
(
name
);
}
catch
(
std
::
out_of_range
&
e
)
{
return
unsetVal
;
}
}
private
:
std
::
map
<
util
::
GUID
,
PropType
>
m_properties
;
std
::
map
<
util
::
GUID
,
uint64_t
>
m_cost
;
};
class
Token
{
public:
Token
()
=
default
;
explicit
Token
(
std
::
shared_ptr
<
TokenType
>
type
)
:
m_type
(
std
::
move
(
type
))
{}
inline
void
setProperty
(
util
::
GUID
name
,
TokenType
::
PropType
newVal
)
{
m_properties
[
name
]
=
newVal
;
}
[[
nodiscard
]]
inline
TokenType
::
PropType
getProperty
(
util
::
GUID
name
,
TokenType
::
PropType
unsetVal
=
0
)
const
{
try
{
auto
prop
=
m_properties
.
at
(
name
);
return
prop
;
}
catch
(
std
::
out_of_range
&
ex
)
{
return
m_type
->
getProperty
(
name
,
unsetVal
);
}
}
[[
nodiscard
]]
using
HexTarget
=
std
::
variant
<
TokenIdentifer
,
IntHex
>
;
inline
TokenType
::
PropType
getPropertyDirect
(
util
::
GUID
name
,
TokenType
::
PropType
unsetVal
=
0
)
const
{
using
HexAction
=
Action
<
HexGrid
,
HexTarget
>
;
try
{
auto
prop
=
m_properties
.
at
(
name
);
return
prop
;
}
catch
(
std
::
out_of_range
&
ex
)
{
return
unsetVal
;
}
}
private
:
std
::
shared_ptr
<
TokenType
>
m_type
;
std
::
map
<
util
::
GUID
,
TokenType
::
PropType
>
m_properties
;
};
struct
MaterialData
{
struct
MaterialData
{
std
::
string
name
;
std
::
string
name
;
...
...
This diff is collapsed.
Click to expand it.
include/fggl/grid/tokens.hpp
0 → 100644
+
88
−
0
View file @
9ad8b0a5
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 19/12/22.
//
#ifndef FGGL_GRID_TOKENS_HPP
#define FGGL_GRID_TOKENS_HPP
#include
<cstdint>
#include
<map>
#include
"fggl/util/guid.hpp"
namespace
fggl
::
grid
{
using
TokenIdentifer
=
fggl
::
util
::
OpaqueName
<
uint64_t
,
struct
Token
>
;
class
TokenType
{
public:
using
PropType
=
int64_t
;
inline
void
setProperty
(
util
::
GUID
name
,
PropType
newVal
)
{
m_properties
[
name
]
=
newVal
;
}
[[
nodiscard
]]
inline
PropType
getProperty
(
util
::
GUID
name
,
PropType
unsetVal
=
0
)
const
{
try
{
return
m_properties
.
at
(
name
);
}
catch
(
std
::
out_of_range
&
e
)
{
return
unsetVal
;
}
}
private
:
std
::
map
<
util
::
GUID
,
PropType
>
m_properties
;
std
::
map
<
util
::
GUID
,
uint64_t
>
m_cost
;
};
class
Token
{
public:
Token
()
=
default
;
explicit
Token
(
std
::
shared_ptr
<
TokenType
>
type
)
:
m_type
(
std
::
move
(
type
))
{}
inline
void
setProperty
(
util
::
GUID
name
,
TokenType
::
PropType
newVal
)
{
m_properties
[
name
]
=
newVal
;
}
[[
nodiscard
]]
inline
TokenType
::
PropType
getProperty
(
util
::
GUID
name
,
TokenType
::
PropType
unsetVal
=
0
)
const
{
try
{
auto
prop
=
m_properties
.
at
(
name
);
return
prop
;
}
catch
(
std
::
out_of_range
&
ex
)
{
return
m_type
->
getProperty
(
name
,
unsetVal
);
}
}
[[
nodiscard
]]
inline
TokenType
::
PropType
getPropertyDirect
(
util
::
GUID
name
,
TokenType
::
PropType
unsetVal
=
0
)
const
{
try
{
auto
prop
=
m_properties
.
at
(
name
);
return
prop
;
}
catch
(
std
::
out_of_range
&
ex
)
{
return
unsetVal
;
}
}
private
:
TokenIdentifer
m_id
;
std
::
shared_ptr
<
TokenType
>
m_type
;
std
::
map
<
util
::
GUID
,
TokenType
::
PropType
>
m_properties
;
};
}
// namespace fggl::grid
#endif //FGGL_GRID_TOKENS_HPP
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment