Skip to content

Commit 0d3e02e

Browse files
committed
adding a coba use object using admin
1 parent a803082 commit 0d3e02e

File tree

8 files changed

+23001
-0
lines changed

8 files changed

+23001
-0
lines changed

JvmClient/src/jvmMain/java/uuspaceagent/UUSeAgentState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public void updateState(String agentId) {
113113
// get the new WOM. Currently it does not include agent's extended properties, so we add them
114114
// explicitly here:
115115
WorldModel newWom = env().observe() ;
116+
116117
//System.out.println(">>>-- agent pos as received from SE:" + newWom.position);
117118
// HACK: SE gives generated-id to the agent, replace that:
118119
newWom.agentId = this.agentId ;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package uuspaceagent;
2+
3+
import eu.iv4xr.framework.mainConcepts.WorldEntity;
4+
import org.junit.jupiter.api.Test;
5+
import spaceEngineers.controller.useobject.UseObjectExtensions;
6+
import spaceEngineers.model.*;
7+
8+
import static uuspaceagent.TestUtils.loadSE;
9+
10+
/**
11+
* For trying out use-block primitive from SE.
12+
*/
13+
public class Coba_UseObject {
14+
15+
@Test
16+
public void test() throws InterruptedException {
17+
18+
var state = loadSE("myworld-3 with open door X").snd;
19+
20+
state.useSystemTimeForTimeStamping = true ;
21+
22+
state.updateState(state.agentId);
23+
24+
WorldEntity agentInfo = state.worldmodel.elements.get(state.agentId) ;
25+
System.out.println("** Agent's info: " + PrintInfos.showWorldEntity(agentInfo));
26+
WorldEntity target = SEBlockFunctions.findClosestBlock(state.worldmodel, "SurvivalKitLarge", 10) ;
27+
System.out.println("** target: " + PrintInfos.showWorldEntity(target));
28+
29+
// Using a survival-kit to heal the agent. Making use of the
30+
// admin-feature-shortcut:
31+
for (int k=0; k<100; k++) {
32+
// run a loop to heal
33+
state.env().getController().getAdmin().getCharacter().use(target.id, 0,
34+
UseObject.Companion.getManipulate());
35+
//Thread.sleep(20);
36+
state.updateState(state.agentId);
37+
float h = (Float) state.val("health") ;
38+
float h0 = (Float) state.before("health") ;
39+
agentInfo = state.get(state.agentId) ;
40+
long t = agentInfo.timestamp ;
41+
long t0 = agentInfo.getPreviousState().timestamp ;
42+
System.out.println(">>> healing: " + (h - h0) + "/" + (t - t0));
43+
}
44+
45+
Thread.sleep(2000);
46+
47+
// for closing the Terminal-screen, if you experiment with
48+
// an action that open a terminal (above)
49+
/*
50+
try {
51+
52+
state.env().getController().getScreens().getTerminal().close();
53+
}
54+
catch(Exception e) {
55+
// the terminal was not open
56+
}
57+
*/
58+
59+
state.updateState(state.agentId);
60+
agentInfo = state.worldmodel.elements.get(state.agentId) ;
61+
System.out.println("** Agent's info: " + PrintInfos.showWorldEntity(agentInfo));
62+
63+
}
64+
}

0 commit comments

Comments
 (0)