Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
autumn_rrs
autumn_agent_2023
Commits
32a48f0e
Commit
32a48f0e
authored
Nov 01, 2023
by
K20014
Browse files
CommandExecuter調査途中
parent
f6734e74
Changes
11
Show whitespace changes
Inline
Side-by-side
config/module.cfg
View file @
32a48f0e
...
@@ -11,7 +11,9 @@ DefaultTacticsFireBrigade.HumanDetector : sample_team.module.complex.SampleHuman
...
@@ -11,7 +11,9 @@ DefaultTacticsFireBrigade.HumanDetector : sample_team.module.complex.SampleHuman
DefaultTacticsFireBrigade.Search : sample_team.module.complex.SampleSearch
DefaultTacticsFireBrigade.Search : sample_team.module.complex.SampleSearch
DefaultTacticsFireBrigade.ExtActionFireRescue : adf.impl.extaction.DefaultExtActionFireRescue
DefaultTacticsFireBrigade.ExtActionFireRescue : adf.impl.extaction.DefaultExtActionFireRescue
DefaultTacticsFireBrigade.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
DefaultTacticsFireBrigade.ExtActionMove : adf.impl.extaction.DefaultExtActionMove
DefaultTacticsFireBrigade.CommandExecutorFire : adf.impl.centralized.DefaultCommandExecutorFire
## DefaultTacticsFireBrigade.CommandExecutorFire : adf.impl.centralized.DefaultCommandExecutorFire
## DefaultTacticsFireBrigade.CommandExecutorFire : autumn_2023.centralized.DefaultCommandExecutorFire2
DefaultTacticsFireBrigade.CommandExecutorFire : autumn_2023.centralized.DefaultCommandExecutorFire
DefaultTacticsFireBrigade.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout
DefaultTacticsFireBrigade.CommandExecutorScout : adf.impl.centralized.DefaultCommandExecutorScout
## DefaultTacticsPoliceForce
## DefaultTacticsPoliceForce
...
...
src/main/java/autumn_2023/centralized/.DS_Store
0 → 100644
View file @
32a48f0e
File added
src/main/java/autumn_2023/centralized/DefaultCommandExecutorAmbulance.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
AMBULANCE_TEAM
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
CIVILIAN
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.action.common.ActionMove
;
import
adf.core.agent.action.common.ActionRest
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
import
adf.core.component.extaction.ExtAction
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Objects
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandExecutorAmbulance
extends
CommandExecutor
<
CommandAmbulance
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_REST
=
CommandAmbulance
.
ACTION_REST
;
private
static
final
int
ACTION_MOVE
=
CommandAmbulance
.
ACTION_MOVE
;
private
static
final
int
ACTION_RESCUE
=
CommandAmbulance
.
ACTION_RESCUE
;
private
static
final
int
ACTION_LOAD
=
CommandAmbulance
.
ACTION_LOAD
;
private
static
final
int
ACTION_UNLOAD
=
CommandAmbulance
.
ACTION_UNLOAD
;
private
static
final
int
ACTION_AUTONOMY
=
CommandAmbulance
.
ACTION_AUTONOMY
;
private
PathPlanning
pathPlanning
;
private
ExtAction
actionTransport
;
private
ExtAction
actionExtMove
;
private
int
commandType
;
private
EntityID
target
;
private
EntityID
commanderID
;
public
DefaultCommandExecutorAmbulance
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
commandType
=
ACTION_UNKNOWN
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"DefaultCommandExecutorAmbulance.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
this
.
actionTransport
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorAmbulance.ExtActionTransport"
,
"adf.impl.extaction.DefaultExtActionTransport"
);
this
.
actionExtMove
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorAmbulance.ExActionMove"
,
"adf.impl.extaction.DefaultExtActionMove"
);
break
;
}
}
@Override
public
CommandExecutor
setCommand
(
CommandAmbulance
command
)
{
EntityID
agentID
=
this
.
agentInfo
.
getID
();
if
(
command
.
isToIDDefined
()
&&
Objects
.
requireNonNull
(
command
.
getToID
())
.
getValue
()
==
agentID
.
getValue
())
{
this
.
commandType
=
command
.
getAction
();
this
.
target
=
command
.
getTargetID
();
this
.
commanderID
=
command
.
getSenderID
();
}
return
this
;
}
@Override
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
updateInfo
(
messageManager
);
this
.
actionTransport
.
updateInfo
(
messageManager
);
this
.
actionExtMove
.
updateInfo
(
messageManager
);
if
(
this
.
isCommandCompleted
())
{
if
(
this
.
commandType
!=
ACTION_UNKNOWN
)
{
messageManager
.
addMessage
(
new
MessageReport
(
true
,
true
,
false
,
this
.
commanderID
));
if
(
this
.
commandType
==
ACTION_LOAD
)
{
this
.
commandType
=
ACTION_UNLOAD
;
this
.
target
=
null
;
}
else
{
this
.
commandType
=
ACTION_UNKNOWN
;
this
.
target
=
null
;
this
.
commanderID
=
null
;
}
}
}
return
this
;
}
@Override
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
precompute
(
precomputeData
);
this
.
actionTransport
.
precompute
(
precomputeData
);
this
.
actionExtMove
.
precompute
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
resume
(
precomputeData
);
this
.
actionTransport
.
resume
(
precomputeData
);
this
.
actionExtMove
.
resume
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
preparate
();
this
.
actionTransport
.
preparate
();
this
.
actionExtMove
.
preparate
();
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
this
.
result
=
null
;
switch
(
this
.
commandType
)
{
case
ACTION_REST:
EntityID
position
=
this
.
agentInfo
.
getPosition
();
if
(
this
.
target
==
null
)
{
Collection
<
EntityID
>
refuges
=
this
.
worldInfo
.
getEntityIDsOfType
(
REFUGE
);
if
(
refuges
.
contains
(
position
))
{
this
.
result
=
new
ActionRest
();
}
else
{
this
.
pathPlanning
.
setFrom
(
position
);
this
.
pathPlanning
.
setDestination
(
refuges
);
List
<
EntityID
>
path
=
this
.
pathPlanning
.
calc
().
getResult
();
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
this
.
result
=
new
ActionMove
(
path
);
}
else
{
this
.
result
=
new
ActionRest
();
}
}
return
this
;
}
if
(
position
.
getValue
()
!=
this
.
target
.
getValue
())
{
List
<
EntityID
>
path
=
this
.
pathPlanning
.
getResult
(
position
,
this
.
target
);
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
this
.
result
=
new
ActionMove
(
path
);
return
this
;
}
}
this
.
result
=
new
ActionRest
();
return
this
;
case
ACTION_MOVE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_RESCUE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_LOAD:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_UNLOAD:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_AUTONOMY:
if
(
this
.
target
==
null
)
{
return
this
;
}
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
instanceof
Area
)
{
if
(
this
.
agentInfo
.
someoneOnBoard
()
==
null
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
else
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
else
if
(
targetEntity
instanceof
Human
)
{
this
.
result
=
this
.
actionTransport
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
return
this
;
}
private
boolean
isCommandCompleted
()
{
Human
agent
=
(
Human
)
this
.
agentInfo
.
me
();
switch
(
this
.
commandType
)
{
case
ACTION_REST:
if
(
this
.
target
==
null
)
{
return
(
agent
.
getDamage
()
==
0
);
}
if
(
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
))
.
getStandardURN
()
==
REFUGE
)
{
if
(
agent
.
getPosition
().
getValue
()
==
this
.
target
.
getValue
())
{
return
(
agent
.
getDamage
()
==
0
);
}
}
return
false
;
case
ACTION_MOVE:
return
this
.
target
==
null
||
this
.
agentInfo
.
getPosition
()
.
getValue
()
==
this
.
target
.
getValue
();
case
ACTION_RESCUE:
if
(
this
.
target
==
null
)
{
return
true
;
}
Human
human
=
(
Human
)
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
));
return
human
.
isBuriednessDefined
()
&&
human
.
getBuriedness
()
==
0
||
(
human
.
isHPDefined
()
&&
human
.
getHP
()
==
0
);
case
ACTION_LOAD:
if
(
this
.
target
==
null
)
{
return
true
;
}
Human
human1
=
(
Human
)
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
));
if
((
human1
.
isHPDefined
()
&&
human1
.
getHP
()
==
0
))
{
return
true
;
}
if
(
human1
.
getStandardURN
()
!=
CIVILIAN
)
{
this
.
commandType
=
ACTION_RESCUE
;
return
this
.
isCommandCompleted
();
}
if
(
human1
.
isPositionDefined
())
{
EntityID
position
=
human1
.
getPosition
();
if
(
this
.
worldInfo
.
getEntityIDsOfType
(
AMBULANCE_TEAM
)
.
contains
(
position
))
{
return
true
;
}
else
if
(
this
.
worldInfo
.
getEntity
(
position
)
.
getStandardURN
()
==
REFUGE
)
{
return
true
;
}
}
return
false
;
case
ACTION_UNLOAD:
if
(
this
.
target
!=
null
)
{
StandardEntity
entity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
entity
!=
null
&&
entity
instanceof
Area
)
{
if
(
this
.
target
.
getValue
()
!=
this
.
agentInfo
.
getPosition
()
.
getValue
())
{
return
false
;
}
}
}
return
(
this
.
agentInfo
.
someoneOnBoard
()
==
null
);
case
ACTION_AUTONOMY:
if
(
this
.
target
!=
null
)
{
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
instanceof
Area
)
{
this
.
commandType
=
this
.
agentInfo
.
someoneOnBoard
()
==
null
?
ACTION_MOVE
:
ACTION_UNLOAD
;
return
this
.
isCommandCompleted
();
}
else
if
(
targetEntity
instanceof
Human
)
{
Human
h
=
(
Human
)
targetEntity
;
if
((
h
.
isHPDefined
()
&&
h
.
getHP
()
==
0
))
{
return
true
;
}
this
.
commandType
=
h
.
getStandardURN
()
==
CIVILIAN
?
ACTION_LOAD
:
ACTION_RESCUE
;
return
this
.
isCommandCompleted
();
}
}
return
true
;
}
return
true
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandExecutorFire.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
CIVILIAN
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.action.common.ActionMove
;
import
adf.core.agent.action.common.ActionRest
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
import
adf.core.component.extaction.ExtAction
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Objects
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandExecutorFire
extends
CommandExecutor
<
CommandAmbulance
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_REST
=
CommandAmbulance
.
ACTION_REST
;
private
static
final
int
ACTION_MOVE
=
CommandAmbulance
.
ACTION_MOVE
;
private
static
final
int
ACTION_RESCUE
=
CommandAmbulance
.
ACTION_RESCUE
;
private
static
final
int
ACTION_AUTONOMY
=
CommandAmbulance
.
ACTION_AUTONOMY
;
private
PathPlanning
pathPlanning
;
private
ExtAction
actionFireRescue
;
private
ExtAction
actionExtMove
;
private
int
commandType
;
private
EntityID
target
;
private
EntityID
commanderID
;
public
DefaultCommandExecutorFire
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
commandType
=
ACTION_UNKNOWN
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"DefaultCommandExecutorFire.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
this
.
actionFireRescue
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorFire.ExtActionFireRescue"
,
"adf.impl.extaction.DefaultExtActionFireRescue"
);
this
.
actionExtMove
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorFire.ExtActionMove"
,
"adf.impl.extaction.DefaultExtActionMove"
);
break
;
}
}
@Override
public
CommandExecutor
setCommand
(
CommandAmbulance
command
)
{
System
.
out
.
println
(
"CommandAmbulance setCommand 動いてるぜ"
);
EntityID
agentID
=
this
.
agentInfo
.
getID
();
if
(
command
.
isToIDDefined
()
&&
Objects
.
requireNonNull
(
command
.
getToID
())
.
getValue
()
==
agentID
.
getValue
())
{
this
.
commandType
=
command
.
getAction
();
this
.
target
=
command
.
getTargetID
();
this
.
commanderID
=
command
.
getSenderID
();
}
return
this
;
}
@Override
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
System
.
out
.
println
(
"CommandAmbulance 動いてるぜ"
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
updateInfo
(
messageManager
);
this
.
actionFireRescue
.
updateInfo
(
messageManager
);
this
.
actionExtMove
.
updateInfo
(
messageManager
);
if
(
this
.
isCommandCompleted
())
{
if
(
this
.
commandType
!=
ACTION_UNKNOWN
)
{
messageManager
.
addMessage
(
new
MessageReport
(
true
,
true
,
false
,
this
.
commanderID
));
this
.
commandType
=
ACTION_UNKNOWN
;
this
.
target
=
null
;
this
.
commanderID
=
null
;
}
}
return
this
;
}
@Override
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
precompute
(
precomputeData
);
this
.
actionFireRescue
.
precompute
(
precomputeData
);
this
.
actionExtMove
.
precompute
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
resume
(
precomputeData
);
this
.
actionFireRescue
.
resume
(
precomputeData
);
this
.
actionExtMove
.
resume
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
preparate
();
this
.
actionFireRescue
.
preparate
();
this
.
actionExtMove
.
preparate
();
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
this
.
result
=
null
;
switch
(
this
.
commandType
)
{
case
ACTION_REST:
EntityID
position
=
this
.
agentInfo
.
getPosition
();
if
(
this
.
target
==
null
)
{
Collection
<
EntityID
>
refuges
=
this
.
worldInfo
.
getEntityIDsOfType
(
REFUGE
);
if
(
refuges
.
contains
(
position
))
{
this
.
result
=
new
ActionRest
();
}
else
{
this
.
pathPlanning
.
setFrom
(
position
);
this
.
pathPlanning
.
setDestination
(
refuges
);
List
<
EntityID
>
path
=
this
.
pathPlanning
.
calc
().
getResult
();
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
this
.
result
=
new
ActionMove
(
path
);
}
else
{
this
.
result
=
new
ActionRest
();
}
}
return
this
;
}
if
(
position
.
getValue
()
!=
this
.
target
.
getValue
())
{
List
<
EntityID
>
path
=
this
.
pathPlanning
.
getResult
(
position
,
this
.
target
);
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
this
.
result
=
new
ActionMove
(
path
);
return
this
;
}
}
this
.
result
=
new
ActionRest
();
return
this
;
case
ACTION_MOVE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_RESCUE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionFireRescue
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_AUTONOMY:
if
(
this
.
target
==
null
)
{
return
this
;
}
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
instanceof
Area
)
{
this
.
result
=
this
.
actionExtMove
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
else
if
(
targetEntity
instanceof
Human
)
{
this
.
result
=
this
.
actionFireRescue
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
return
this
;
}
private
boolean
isCommandCompleted
()
{
Human
agent
=
(
Human
)
this
.
agentInfo
.
me
();
switch
(
this
.
commandType
)
{
case
ACTION_REST:
if
(
this
.
target
==
null
)
{
return
(
agent
.
getDamage
()
==
0
);
}
if
(
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
))
.
getStandardURN
()
==
REFUGE
)
{
if
(
agent
.
getPosition
().
getValue
()
==
this
.
target
.
getValue
())
{
return
(
agent
.
getDamage
()
==
0
);
}
}
return
false
;
case
ACTION_MOVE:
return
this
.
target
==
null
||
this
.
agentInfo
.
getPosition
()
.
getValue
()
==
this
.
target
.
getValue
();
case
ACTION_RESCUE:
if
(
this
.
target
==
null
)
{
return
true
;
}
Human
human
=
(
Human
)
Objects
.
requireNonNull
(
this
.
worldInfo
.
getEntity
(
this
.
target
));
return
human
.
isBuriednessDefined
()
&&
human
.
getBuriedness
()
==
0
||
(
human
.
isHPDefined
()
&&
human
.
getHP
()
==
0
);
case
ACTION_AUTONOMY:
if
(
this
.
target
!=
null
)
{
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
instanceof
Area
)
{
this
.
commandType
=
ACTION_MOVE
;
return
this
.
isCommandCompleted
();
}
else
if
(
targetEntity
instanceof
Human
)
{
Human
h
=
(
Human
)
targetEntity
;
if
((
h
.
isHPDefined
()
&&
h
.
getHP
()
==
0
))
{
return
true
;
}
if
(
h
.
getStandardURN
()
==
CIVILIAN
)
{
this
.
commandType
=
ACTION_RESCUE
;
}
return
this
.
isCommandCompleted
();
}
}
return
true
;
}
return
true
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandExecutorFire2.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandFire
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
public
class
DefaultCommandExecutorFire2
extends
CommandExecutor
<
CommandFire
>
{
public
DefaultCommandExecutorFire2
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
}
@Override
public
CommandExecutor
setCommand
(
CommandFire
command
)
{
return
this
;
}
@Override
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
System
.
out
.
println
(
"Command Fire 動いてるぜ"
);
return
this
;
}
@Override
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
preparate
()
{
super
.
preparate
();
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
return
this
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandExecutorPolice.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
BLOCKADE
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.action.Action
;
import
adf.core.agent.action.common.ActionMove
;
import
adf.core.agent.action.common.ActionRest
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandPolice
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
import
adf.core.component.extaction.ExtAction
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
java.util.List
;
import
java.util.Objects
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Blockade
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.PoliceForce
;
import
rescuecore2.standard.entities.Road
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandExecutorPolice
extends
CommandExecutor
<
CommandPolice
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_REST
=
CommandPolice
.
ACTION_REST
;
private
static
final
int
ACTION_MOVE
=
CommandPolice
.
ACTION_MOVE
;
private
static
final
int
ACTION_CLEAR
=
CommandPolice
.
ACTION_CLEAR
;
private
static
final
int
ACTION_AUTONOMY
=
CommandPolice
.
ACTION_AUTONOMY
;
private
int
commandType
;
private
EntityID
target
;
private
EntityID
commanderID
;
private
PathPlanning
pathPlanning
;
private
ExtAction
actionExtClear
;
private
ExtAction
actionExtMove
;
public
DefaultCommandExecutorPolice
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
commandType
=
ACTION_UNKNOWN
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"DefaultCommandExecutorPolice.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
this
.
actionExtClear
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorPolice.ExtActionClear"
,
"adf.impl.extaction.DefaultExtActionClear"
);
this
.
actionExtMove
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorPolice.ExtActionMove"
,
"adf.impl.extaction.DefaultExtActionMove"
);
break
;
}
}
@Override
public
CommandExecutor
setCommand
(
CommandPolice
command
)
{
EntityID
agentID
=
this
.
agentInfo
.
getID
();
if
(
command
.
isToIDDefined
()
&&
Objects
.
requireNonNull
(
command
.
getToID
())
.
getValue
()
==
agentID
.
getValue
())
{
this
.
commandType
=
command
.
getAction
();
this
.
target
=
command
.
getTargetID
();
this
.
commanderID
=
command
.
getSenderID
();
}
return
this
;
}
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
precompute
(
precomputeData
);
this
.
actionExtClear
.
precompute
(
precomputeData
);
this
.
actionExtMove
.
precompute
(
precomputeData
);
return
this
;
}
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
resume
(
precomputeData
);
this
.
actionExtClear
.
resume
(
precomputeData
);
this
.
actionExtMove
.
resume
(
precomputeData
);
return
this
;
}
public
CommandExecutor
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
preparate
();
this
.
actionExtClear
.
preparate
();
this
.
actionExtMove
.
preparate
();
return
this
;
}
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
updateInfo
(
messageManager
);
this
.
actionExtClear
.
updateInfo
(
messageManager
);
this
.
actionExtMove
.
updateInfo
(
messageManager
);
if
(
this
.
isCommandCompleted
())
{
if
(
this
.
commandType
!=
ACTION_UNKNOWN
)
{
messageManager
.
addMessage
(
new
MessageReport
(
true
,
true
,
false
,
this
.
commanderID
));
this
.
commandType
=
ACTION_UNKNOWN
;
this
.
target
=
null
;
this
.
commanderID
=
null
;
}
}
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
this
.
result
=
null
;
EntityID
position
=
this
.
agentInfo
.
getPosition
();
switch
(
this
.
commandType
)
{
case
ACTION_REST:
if
(
this
.
target
==
null
)
{
if
(
worldInfo
.
getEntity
(
position
).
getStandardURN
()
!=
REFUGE
)
{
this
.
pathPlanning
.
setFrom
(
position
);
this
.
pathPlanning
.
setDestination
(
this
.
worldInfo
.
getEntityIDsOfType
(
REFUGE
));
List
<
EntityID
>
path
=
this
.
pathPlanning
.
calc
().
getResult
();
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
Action
action
=
this
.
actionExtClear
.
setTarget
(
path
.
get
(
path
.
size
()
-
1
)).
calc
().
getAction
();
if
(
action
==
null
)
{
action
=
new
ActionMove
(
path
);
}
this
.
result
=
action
;
return
this
;
}
}
}
else
if
(
position
.
getValue
()
!=
this
.
target
.
getValue
())
{
List
<
EntityID
>
path
=
this
.
pathPlanning
.
getResult
(
position
,
this
.
target
);
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
Action
action
=
this
.
actionExtClear
.
setTarget
(
path
.
get
(
path
.
size
()
-
1
)).
calc
().
getAction
();
if
(
action
==
null
)
{
action
=
new
ActionMove
(
path
);
}
this
.
result
=
action
;
return
this
;
}
}
this
.
result
=
new
ActionRest
();
return
this
;
case
ACTION_MOVE:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionExtClear
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_CLEAR:
if
(
this
.
target
!=
null
)
{
this
.
result
=
this
.
actionExtClear
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
return
this
;
case
ACTION_AUTONOMY:
if
(
this
.
target
==
null
)
{
return
this
;
}
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
.
getStandardURN
()
==
REFUGE
)
{
PoliceForce
agent
=
(
PoliceForce
)
this
.
agentInfo
.
me
();
if
(
agent
.
getDamage
()
>
0
)
{
if
(
position
.
getValue
()
!=
this
.
target
.
getValue
())
{
List
<
EntityID
>
path
=
this
.
pathPlanning
.
getResult
(
position
,
this
.
target
);
if
(
path
!=
null
&&
path
.
size
()
>
0
)
{
Action
action
=
this
.
actionExtClear
.
setTarget
(
path
.
get
(
path
.
size
()
-
1
)).
calc
().
getAction
();
if
(
action
==
null
)
{
action
=
new
ActionMove
(
path
);
}
this
.
result
=
action
;
return
this
;
}
}
this
.
result
=
new
ActionRest
();
}
else
{
this
.
result
=
this
.
actionExtClear
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
else
if
(
targetEntity
instanceof
Area
)
{
this
.
result
=
this
.
actionExtClear
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
return
this
;
}
else
if
(
targetEntity
instanceof
Human
)
{
Human
h
=
(
Human
)
targetEntity
;
if
((
h
.
isHPDefined
()
&&
h
.
getHP
()
==
0
))
{
return
this
;
}
if
(
h
.
isPositionDefined
()
&&
this
.
worldInfo
.
getPosition
(
h
)
instanceof
Area
)
{
this
.
target
=
h
.
getPosition
();
this
.
result
=
this
.
actionExtClear
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
else
if
(
targetEntity
.
getStandardURN
()
==
BLOCKADE
)
{
Blockade
blockade
=
(
Blockade
)
targetEntity
;
if
(
blockade
.
isPositionDefined
())
{
this
.
target
=
blockade
.
getPosition
();
this
.
result
=
this
.
actionExtClear
.
setTarget
(
this
.
target
).
calc
()
.
getAction
();
}
}
}
return
this
;
}
private
boolean
isCommandCompleted
()
{
PoliceForce
agent
=
(
PoliceForce
)
this
.
agentInfo
.
me
();
switch
(
this
.
commandType
)
{
case
ACTION_REST:
if
(
this
.
target
==
null
)
{
return
(
agent
.
getDamage
()
==
0
);
}
if
(
this
.
worldInfo
.
getEntity
(
this
.
target
).
getStandardURN
()
==
REFUGE
)
{
if
(
agent
.
getPosition
().
getValue
()
==
this
.
target
.
getValue
())
{
return
(
agent
.
getDamage
()
==
0
);
}
}
return
false
;
case
ACTION_MOVE:
return
this
.
target
==
null
||
(
this
.
agentInfo
.
getPosition
()
.
getValue
()
==
this
.
target
.
getValue
());
case
ACTION_CLEAR:
if
(
this
.
target
==
null
)
{
return
true
;
}
StandardEntity
entity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
entity
instanceof
Road
)
{
Road
road
=
(
Road
)
entity
;
if
(
road
.
isBlockadesDefined
())
{
return
road
.
getBlockades
().
isEmpty
();
}
if
(
this
.
agentInfo
.
getPosition
().
getValue
()
!=
this
.
target
.
getValue
())
{
return
false
;
}
}
return
true
;
case
ACTION_AUTONOMY:
if
(
this
.
target
!=
null
)
{
StandardEntity
targetEntity
=
this
.
worldInfo
.
getEntity
(
this
.
target
);
if
(
targetEntity
.
getStandardURN
()
==
REFUGE
)
{
this
.
commandType
=
agent
.
getDamage
()
>
0
?
ACTION_REST
:
ACTION_CLEAR
;
return
this
.
isCommandCompleted
();
}
else
if
(
targetEntity
instanceof
Area
)
{
this
.
commandType
=
ACTION_CLEAR
;
return
this
.
isCommandCompleted
();
}
else
if
(
targetEntity
instanceof
Human
)
{
Human
h
=
(
Human
)
targetEntity
;
if
((
h
.
isHPDefined
()
&&
h
.
getHP
()
==
0
))
{
return
true
;
}
if
(
h
.
isPositionDefined
()
&&
this
.
worldInfo
.
getPosition
(
h
)
instanceof
Area
)
{
this
.
target
=
h
.
getPosition
();
this
.
commandType
=
ACTION_CLEAR
;
return
this
.
isCommandCompleted
();
}
}
else
if
(
targetEntity
.
getStandardURN
()
==
BLOCKADE
)
{
Blockade
blockade
=
(
Blockade
)
targetEntity
;
if
(
blockade
.
isPositionDefined
())
{
this
.
target
=
blockade
.
getPosition
();
this
.
commandType
=
ACTION_CLEAR
;
return
this
.
isCommandCompleted
();
}
}
}
return
true
;
}
return
true
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandExecutorScout.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.action.common.ActionMove
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandScout
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.worldmodel.AbstractEntity
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandExecutorScout
extends
CommandExecutor
<
CommandScout
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_SCOUT
=
1
;
private
PathPlanning
pathPlanning
;
private
int
type
;
private
Collection
<
EntityID
>
scoutTargets
;
private
EntityID
commanderID
;
public
DefaultCommandExecutorScout
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
type
=
ACTION_UNKNOWN
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"DefaultCommandExecutorScout.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
break
;
}
}
@Override
public
CommandExecutor
setCommand
(
CommandScout
command
)
{
EntityID
agentID
=
this
.
agentInfo
.
getID
();
if
(
command
.
isToIDDefined
()
&&
(
Objects
.
requireNonNull
(
command
.
getToID
())
.
getValue
()
==
agentID
.
getValue
()))
{
EntityID
target
=
command
.
getTargetID
();
if
(
target
==
null
)
{
target
=
this
.
agentInfo
.
getPosition
();
}
this
.
type
=
ACTION_SCOUT
;
this
.
commanderID
=
command
.
getSenderID
();
this
.
scoutTargets
=
new
HashSet
<>();
this
.
scoutTargets
.
addAll
(
worldInfo
.
getObjectsInRange
(
target
,
command
.
getRange
()).
stream
()
.
filter
(
e
->
e
instanceof
Area
&&
e
.
getStandardURN
()
!=
REFUGE
)
.
map
(
AbstractEntity:
:
getID
).
collect
(
Collectors
.
toList
()));
}
return
this
;
}
@Override
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
updateInfo
(
messageManager
);
if
(
this
.
isCommandCompleted
())
{
if
(
this
.
type
!=
ACTION_UNKNOWN
)
{
messageManager
.
addMessage
(
new
MessageReport
(
true
,
true
,
false
,
this
.
commanderID
));
this
.
type
=
ACTION_UNKNOWN
;
this
.
scoutTargets
=
null
;
this
.
commanderID
=
null
;
}
}
return
this
;
}
@Override
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
precompute
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
resume
(
precomputeData
);
return
this
;
}
@Override
public
CommandExecutor
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
preparate
();
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
this
.
result
=
null
;
if
(
this
.
type
==
ACTION_SCOUT
)
{
if
(
this
.
scoutTargets
==
null
||
this
.
scoutTargets
.
isEmpty
())
{
return
this
;
}
this
.
pathPlanning
.
setFrom
(
this
.
agentInfo
.
getPosition
());
this
.
pathPlanning
.
setDestination
(
this
.
scoutTargets
);
List
<
EntityID
>
path
=
this
.
pathPlanning
.
calc
().
getResult
();
if
(
path
!=
null
)
{
this
.
result
=
new
ActionMove
(
path
);
}
}
return
this
;
}
private
boolean
isCommandCompleted
()
{
if
(
this
.
type
==
ACTION_SCOUT
)
{
if
(
this
.
scoutTargets
!=
null
)
{
this
.
scoutTargets
.
removeAll
(
this
.
worldInfo
.
getChanged
().
getChangedEntities
());
}
return
(
this
.
scoutTargets
==
null
||
this
.
scoutTargets
.
isEmpty
());
}
return
true
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandExecutorScoutPolice.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
static
rescuecore2
.
standard
.
entities
.
StandardEntityURN
.
REFUGE
;
import
adf.core.agent.action.Action
;
import
adf.core.agent.action.common.ActionMove
;
import
adf.core.agent.communication.MessageManager
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandScout
;
import
adf.core.agent.communication.standard.bundle.centralized.MessageReport
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.agent.precompute.PrecomputeData
;
import
adf.core.component.centralized.CommandExecutor
;
import
adf.core.component.extaction.ExtAction
;
import
adf.core.component.module.algorithm.PathPlanning
;
import
java.util.Collection
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.worldmodel.AbstractEntity
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandExecutorScoutPolice
extends
CommandExecutor
<
CommandScout
>
{
private
static
final
int
ACTION_UNKNOWN
=
-
1
;
private
static
final
int
ACTION_SCOUT
=
1
;
private
PathPlanning
pathPlanning
;
private
ExtAction
actionExtClear
;
private
int
commandType
;
private
Collection
<
EntityID
>
scoutTargets
;
private
EntityID
commanderID
;
public
DefaultCommandExecutorScoutPolice
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
commandType
=
ACTION_UNKNOWN
;
this
.
scoutTargets
=
new
HashSet
<>();
this
.
commanderID
=
null
;
switch
(
scenarioInfo
.
getMode
())
{
case
PRECOMPUTATION_PHASE:
case
PRECOMPUTED:
case
NON_PRECOMPUTE:
this
.
pathPlanning
=
moduleManager
.
getModule
(
"DefaultCommandExecutorScoutPolice.PathPlanning"
,
"adf.impl.module.algorithm.DijkstraPathPlanning"
);
this
.
actionExtClear
=
moduleManager
.
getExtAction
(
"DefaultCommandExecutorScoutPolice.ExtActionClear"
,
"adf.impl.extaction.DefaultExtActionClear"
);
break
;
}
}
@Override
public
CommandExecutor
<
CommandScout
>
setCommand
(
CommandScout
command
)
{
EntityID
agentID
=
this
.
agentInfo
.
getID
();
if
(
command
.
isToIDDefined
()
&&
(
Objects
.
requireNonNull
(
command
.
getToID
())
.
getValue
()
==
agentID
.
getValue
()))
{
EntityID
target
=
command
.
getTargetID
();
if
(
target
==
null
)
{
target
=
this
.
agentInfo
.
getPosition
();
}
this
.
commandType
=
ACTION_SCOUT
;
this
.
commanderID
=
command
.
getSenderID
();
this
.
scoutTargets
=
new
HashSet
<>();
this
.
scoutTargets
.
addAll
(
worldInfo
.
getObjectsInRange
(
target
,
command
.
getRange
()).
stream
()
.
filter
(
e
->
e
instanceof
Area
&&
e
.
getStandardURN
()
!=
REFUGE
)
.
map
(
AbstractEntity:
:
getID
).
collect
(
Collectors
.
toList
()));
}
return
this
;
}
public
CommandExecutor
precompute
(
PrecomputeData
precomputeData
)
{
super
.
precompute
(
precomputeData
);
if
(
this
.
getCountPrecompute
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
precompute
(
precomputeData
);
this
.
actionExtClear
.
precompute
(
precomputeData
);
return
this
;
}
public
CommandExecutor
resume
(
PrecomputeData
precomputeData
)
{
super
.
resume
(
precomputeData
);
if
(
this
.
getCountResume
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
resume
(
precomputeData
);
this
.
actionExtClear
.
resume
(
precomputeData
);
return
this
;
}
public
CommandExecutor
preparate
()
{
super
.
preparate
();
if
(
this
.
getCountPreparate
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
preparate
();
this
.
actionExtClear
.
preparate
();
return
this
;
}
public
CommandExecutor
updateInfo
(
MessageManager
messageManager
)
{
super
.
updateInfo
(
messageManager
);
if
(
this
.
getCountUpdateInfo
()
>=
2
)
{
return
this
;
}
this
.
pathPlanning
.
updateInfo
(
messageManager
);
this
.
actionExtClear
.
updateInfo
(
messageManager
);
if
(
this
.
isCommandCompleted
())
{
if
(
this
.
commandType
!=
ACTION_UNKNOWN
)
{
messageManager
.
addMessage
(
new
MessageReport
(
true
,
true
,
false
,
this
.
commanderID
));
this
.
commandType
=
ACTION_UNKNOWN
;
this
.
scoutTargets
=
new
HashSet
<>();
this
.
commanderID
=
null
;
}
}
return
this
;
}
@Override
public
CommandExecutor
calc
()
{
this
.
result
=
null
;
EntityID
position
=
this
.
agentInfo
.
getPosition
();
if
(
this
.
commandType
==
ACTION_SCOUT
)
{
if
(
this
.
scoutTargets
==
null
||
this
.
scoutTargets
.
isEmpty
())
{
return
this
;
}
this
.
pathPlanning
.
setFrom
(
position
);
this
.
pathPlanning
.
setDestination
(
this
.
scoutTargets
);
List
<
EntityID
>
path
=
this
.
pathPlanning
.
calc
().
getResult
();
if
(
path
!=
null
)
{
EntityID
target
=
path
.
size
()
>
0
?
path
.
get
(
path
.
size
()
-
1
)
:
position
;
Action
action
=
this
.
actionExtClear
.
setTarget
(
target
).
calc
()
.
getAction
();
if
(
action
==
null
)
{
action
=
new
ActionMove
(
path
);
}
this
.
result
=
action
;
}
}
return
this
;
}
private
boolean
isCommandCompleted
()
{
if
(
this
.
commandType
==
ACTION_SCOUT
)
{
if
(
this
.
scoutTargets
!=
null
)
{
this
.
scoutTargets
.
removeAll
(
this
.
worldInfo
.
getChanged
().
getChangedEntities
());
}
return
(
this
.
scoutTargets
==
null
||
this
.
scoutTargets
.
isEmpty
());
}
return
true
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandPickerAmbulance.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandAmbulance
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandScout
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.component.centralized.CommandPicker
;
import
adf.core.component.communication.CommunicationMessage
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Map
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.standard.entities.StandardEntityURN
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandPickerAmbulance
extends
CommandPicker
{
private
int
scoutDistance
;
private
Collection
<
CommunicationMessage
>
messages
;
private
Map
<
EntityID
,
EntityID
>
allocationData
;
public
DefaultCommandPickerAmbulance
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
messages
=
new
ArrayList
<>();
this
.
allocationData
=
null
;
this
.
scoutDistance
=
developData
.
getInteger
(
"adf.impl.centralized.DefaultCommandPickerAmbulance.scoutDistance"
,
40000
);
}
@Override
public
CommandPicker
setAllocatorResult
(
Map
<
EntityID
,
EntityID
>
allocationData
)
{
this
.
allocationData
=
allocationData
;
return
this
;
}
@Override
public
CommandPicker
calc
()
{
this
.
messages
.
clear
();
if
(
this
.
allocationData
==
null
)
{
return
this
;
}
for
(
EntityID
agentID
:
this
.
allocationData
.
keySet
())
{
StandardEntity
agent
=
this
.
worldInfo
.
getEntity
(
agentID
);
if
(
agent
!=
null
&&
agent
.
getStandardURN
()
==
StandardEntityURN
.
AMBULANCE_TEAM
)
{
StandardEntity
target
=
this
.
worldInfo
.
getEntity
(
this
.
allocationData
.
get
(
agentID
));
if
(
target
!=
null
)
{
if
(
target
instanceof
Human
)
{
CommandAmbulance
command
=
new
CommandAmbulance
(
true
,
agentID
,
target
.
getID
(),
CommandAmbulance
.
ACTION_AUTONOMY
);
this
.
messages
.
add
(
command
);
}
else
if
(
target
instanceof
Area
)
{
CommandScout
command
=
new
CommandScout
(
true
,
agentID
,
target
.
getID
(),
this
.
scoutDistance
);
this
.
messages
.
add
(
command
);
}
}
}
}
return
this
;
}
@Override
public
Collection
<
CommunicationMessage
>
getResult
()
{
return
this
.
messages
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandPickerFire.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandFire
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandScout
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.component.centralized.CommandPicker
;
import
adf.core.component.communication.CommunicationMessage
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Map
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.Human
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.standard.entities.StandardEntityURN
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandPickerFire
extends
CommandPicker
{
private
int
scoutDistance
;
private
Collection
<
CommunicationMessage
>
messages
;
private
Map
<
EntityID
,
EntityID
>
allocationData
;
public
DefaultCommandPickerFire
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
messages
=
new
ArrayList
<>();
this
.
allocationData
=
null
;
this
.
scoutDistance
=
developData
.
getInteger
(
"adf.impl.centralized.DefaultCommandPickerFire.scoutDistance"
,
40000
);
}
@Override
public
CommandPicker
setAllocatorResult
(
Map
<
EntityID
,
EntityID
>
allocationData
)
{
this
.
allocationData
=
allocationData
;
return
this
;
}
@Override
public
CommandPicker
calc
()
{
this
.
messages
.
clear
();
if
(
this
.
allocationData
==
null
)
{
return
this
;
}
for
(
EntityID
agentID
:
this
.
allocationData
.
keySet
())
{
StandardEntity
agent
=
this
.
worldInfo
.
getEntity
(
agentID
);
if
(
agent
!=
null
&&
agent
.
getStandardURN
()
==
StandardEntityURN
.
FIRE_BRIGADE
)
{
StandardEntity
target
=
this
.
worldInfo
.
getEntity
(
this
.
allocationData
.
get
(
agentID
));
if
(
target
!=
null
)
{
if
(
target
instanceof
Human
)
{
CommandFire
command
=
new
CommandFire
(
true
,
agentID
,
target
.
getID
(),
CommandFire
.
ACTION_AUTONOMY
);
this
.
messages
.
add
(
command
);
}
else
if
(
target
instanceof
Area
)
{
CommandScout
command
=
new
CommandScout
(
true
,
agentID
,
target
.
getID
(),
this
.
scoutDistance
);
this
.
messages
.
add
(
command
);
}
}
}
}
return
this
;
}
@Override
public
Collection
<
CommunicationMessage
>
getResult
()
{
return
this
.
messages
;
}
}
\ No newline at end of file
src/main/java/autumn_2023/centralized/DefaultCommandPickerPolice.java
0 → 100644
View file @
32a48f0e
package
autumn_2023.centralized
;
import
adf.core.agent.communication.standard.bundle.centralized.CommandPolice
;
import
adf.core.agent.develop.DevelopData
;
import
adf.core.agent.info.AgentInfo
;
import
adf.core.agent.info.ScenarioInfo
;
import
adf.core.agent.info.WorldInfo
;
import
adf.core.agent.module.ModuleManager
;
import
adf.core.component.centralized.CommandPicker
;
import
adf.core.component.communication.CommunicationMessage
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Map
;
import
rescuecore2.standard.entities.Area
;
import
rescuecore2.standard.entities.StandardEntity
;
import
rescuecore2.standard.entities.StandardEntityURN
;
import
rescuecore2.worldmodel.EntityID
;
public
class
DefaultCommandPickerPolice
extends
CommandPicker
{
private
Collection
<
CommunicationMessage
>
messages
;
private
Map
<
EntityID
,
EntityID
>
allocationData
;
public
DefaultCommandPickerPolice
(
AgentInfo
ai
,
WorldInfo
wi
,
ScenarioInfo
si
,
ModuleManager
moduleManager
,
DevelopData
developData
)
{
super
(
ai
,
wi
,
si
,
moduleManager
,
developData
);
this
.
messages
=
new
ArrayList
<>();
this
.
allocationData
=
null
;
}
@Override
public
CommandPicker
setAllocatorResult
(
Map
<
EntityID
,
EntityID
>
allocationData
)
{
this
.
allocationData
=
allocationData
;
return
this
;
}
@Override
public
CommandPicker
calc
()
{
this
.
messages
.
clear
();
if
(
this
.
allocationData
==
null
)
{
return
this
;
}
for
(
EntityID
agentID
:
this
.
allocationData
.
keySet
())
{
StandardEntity
agent
=
this
.
worldInfo
.
getEntity
(
agentID
);
if
(
agent
!=
null
&&
agent
.
getStandardURN
()
==
StandardEntityURN
.
POLICE_FORCE
)
{
StandardEntity
target
=
this
.
worldInfo
.
getEntity
(
this
.
allocationData
.
get
(
agentID
));
if
(
target
!=
null
)
{
if
(
target
instanceof
Area
)
{
CommandPolice
command
=
new
CommandPolice
(
true
,
agentID
,
target
.
getID
(),
CommandPolice
.
ACTION_AUTONOMY
);
this
.
messages
.
add
(
command
);
}
}
}
}
return
this
;
}
@Override
public
Collection
<
CommunicationMessage
>
getResult
()
{
return
this
.
messages
;
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment