Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ai/openrac/skills/openrac-level/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ steps of whole tasks.
`screenshot` to see it in the editor.
3. Change with the level's tools, each an undo step: `moby_add` with `on_ground`, `moby_set`,
`moby_remove`; `cutscene_write` for a whole cutscene, `cutscene_add` to grow one;
`cutscene_check` and `cutscene_frame` at the start of each shot.
`cutscene_check` and `cutscene_frame` at the start of each shot. After placing or moving
things, `level_place` with their `names` and `move` (`job_wait`): it sets each one down on its
whole underside, off slopes and out of walls. Never trust a single ground point for a model.
4. `scene_save`, then `level_check` and `job_wait`. Fix each problem it lists (node, why) and
check again until none is left.
5. `level_pack` (`job_wait`), then in the game: `game_start` with the level and `mods` set to the
Expand Down
2 changes: 2 additions & 0 deletions docs/AI_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ server (docs/MCP.md), and to see the result in the game with OpenRAC's game serv
`screenshot` after `view_set` to look.
3. Change with the OpenRAC tools: `moby_add` (with `on_ground`), `moby_set`, `moby_remove`,
`cutscene_write` and `cutscene_add`. Every change is an undo step (`undo` with `steps`).
Then `level_place` with the new things' `names` and `move`: it sets each one down on its whole
underside (no floating, no sinking, none in a wall) and moves a crate off a slope.
4. `scene_save`, then `level_check` and `job_wait`: each refused edit comes with the node's path
and why. Fix and check again until none is left.
5. To play it: `level_play` (the game starts on the level), or `planet_set` then `planet_add` for a
Expand Down
7 changes: 7 additions & 0 deletions docs/LEVEL_EDITOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ like a cutscene's ship) comes as scenery, or moves with a simple move. A moby's
**Behaviour** section (spin, bob, patrol, orbit, face or follow the hero), which
the editor-runtime mod plays.

To set things down on the ground, run `openrac_editor.py place <project>` (or the MCP tool
`level_place`). It looks at each moby's, tie's and shrub's whole underside, not one point: a
floating one is lowered, a sunk crate raised, a plant or rock follows the slope. A crate that
cannot stand level, or stands in a wall, is listed; with `--move` it goes to the nearest good spot
within 4 units. `--check` only lists, `--names` picks nodes, `--water` keeps floating things
afloat. Bolts, flying things and moving characters are left as they are.

## Play from the editor

The editor's toolbar has a big gold **Play Level** button (the Assets plugin, `play.gd`). It saves
Expand Down
1 change: 1 addition & 0 deletions docs/MCP.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ x and y across, z up, headings in degrees):
| `moby_list`, `moby_add`, `moby_set`, `moby_remove` | Mobys: list near a point, add on the ground, move, give a behaviour or pvars, delete |
| `behaviour_list` | The behaviour presets and their numbers |
| `ground_at` | The floor under a point, from the level's collision |
| `level_place` | Sets mobys, ties and shrubs down on their whole underside: no floating, sinking or wall (a job; `move` finds a level spot) |
| `cutscene_list`, `cutscene_get`, `cutscene_remove` | The level's cutscenes as `.cutscene` documents ([CUTSCENE_FORMAT.md](CUTSCENE_FORMAT.md)) |
| `cutscene_write`, `cutscene_add` | Write a whole cutscene, or add shots, actors, lines, sounds and events to one |
| `cutscene_check` | What the game would not take or would skip |
Expand Down
6 changes: 4 additions & 2 deletions openrac/project/addons/openrac_library/mcp_knowledge.gd
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Read openrac://guide/ai first. Then:
2. Look at the level: moby_list, class_list, screenshot after view_set at the places you change.
3. Make it the planet: move, add (moby_add with on_ground) and remove mobys; give some a behaviour
(moby_set); add cutscenes (cutscene_write) for an arrival or a meeting. Keep the hero's start
(the Ratchet moby) somewhere he can stand.
(the Ratchet moby) somewhere he can stand. Then level_place with their names and move
(job_wait), so none floats, sinks or stands in a wall.
4. scene_save, then level_check and job_wait; fix each problem it lists and check again.
5. planet_set with the name, then planet_add and job_wait.
6. With the game's MCP server: game_start on this level with the packed levels, game_step until
Expand Down Expand Up @@ -147,7 +148,8 @@ func place_enemies(args: Dictionary) -> String:

1. class_search for the kind (enemy names) and pick classes that come as own or import.
2. moby_list near the place and ground_at around it, to find open floor away from walls.
3. moby_add each with on_ground, facing where Ratchet comes from (yaw).
3. moby_add each with on_ground, facing where Ratchet comes from (yaw), then level_place with
their names and move (job_wait).
4. scene_save, level_check (job_wait), fix problems.
5. In the game: game_start on the level, game_hero_place near them, game_step 120, game_mobys near
the place (their state should change from idle as Ratchet comes), game_shot.""" % [args.get("what", ""), args.get("where", "")]
Expand Down
48 changes: 46 additions & 2 deletions openrac/project/addons/openrac_library/mcp_tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ func register(on: Object, owner: EditorPlugin) -> void:
+ "launcher play). A job.", {}, [], level_pack, opens_world)
add("level_play", "Saves, packs and starts the game on this level with the edits, as Play level does. A job; "
+ "for pictures and state of the running game use the game's own MCP server (OpenRAC tools/game_mcp.py).", {}, [], level_play, opens_world)
add("level_place", "Sets things down on the ground so none floats, sinks or stands in a wall: a moby, tie or "
+ "shrub is lowered or raised until its whole underside (not one point) touches the floor, plants and rocks "
+ "follow a slope, and with move a made thing (a crate) that cannot stand level goes to the nearest good spot "
+ "within 4 units. Run it after placing or moving anything (moby_add, moby_set, scatter), on those names with "
+ "move. Saves first, then the scene is read again. A job.", {
"names": prop("array", "Only nodes with these names (* and ? patterns). Default: the whole level."),
"move": prop("boolean", "A thing that cannot stand where it is moves to the nearest good spot (default false: only listed)."),
"water": prop("number", "The water's height: things afloat on it stay."),
"check": prop("boolean", "Only list what is off; change nothing.")}, [], level_place)
add("planet_get", "The planet's name in the ship's menu and its id (set once it was added).", {}, [], planet_get, read_only)
add("planet_set", "Names this level as a planet (the ship's menu): plain letters A-Z, digits, spaces and punctuation, "
+ "at most 40 characters. Saved in project.godot.", {"name": prop("string", "The planet's name.")}, ["name"], planet_set)
Expand All @@ -68,7 +77,8 @@ func register(on: Object, owner: EditorPlugin) -> void:
"level": prop("integer", "The level the class comes from (default: this one)."),
"position": prop("array", "[x, y, z] in the game's coordinates. Default: in front of the 3D view."),
"yaw": prop("number", "Heading in degrees about the game's up (default 0)."),
"on_ground": prop("boolean", "Put it on the floor under the position (default false)."),
"on_ground": prop("boolean", "Put it on the floor under the position (default false); level_place with move then "
+ "sets its whole underside down."),
"mode": prop("string", "auto (default), own, import, look, skin or simple (a simple move in place of its logic: behaviour)."),
"behaviour": prop("string", "For mode simple: spin, bob, patrol, orbit, face_hero, follow or wander."),
"host_class": prop("integer", "For mode skin: the class of this level whose logic it runs.")}, ["class"], moby_add)
Expand Down Expand Up @@ -167,7 +177,7 @@ func project_info(_args: Dictionary) -> Variant:
"levels": others}


## Runs openrac_editor.py KIND (check, play) as a job, with EXTRA arguments; the scenes are saved first.
## Runs openrac_editor.py KIND (check, play, place) as a job, with EXTRA arguments; the scenes are saved first.
func run_tool(kind: String, title: String, extra: PackedStringArray = PackedStringArray()) -> Variant:
var command: Variant = Play.command_for(kind, Play.this_level())

Expand Down Expand Up @@ -202,6 +212,17 @@ func parsed(code: int, lines: PackedStringArray, kind: String) -> Dictionary:

var result: Dictionary = {"ok": code == 0 and problems.is_empty(), "kind": kind, "problems": problems, "said": said}

if kind == "place":
# The scene file was written under the editor: read it again (nothing changed with --check).
if at != null and not said.is_empty() and not String(said[-1]).begins_with("would") and not String(said[-1]).begins_with("set 0 "):
EditorInterface.reload_scene_from_path.call_deferred(at.scene_file_path)

if not result["ok"]:
result["error"] = "%d thing(s) cannot stand where they are (why): move them by hand, or run again with move." \
% problems.size() if not problems.is_empty() else ("\n".join(said.slice(-5)) if not said.is_empty() else "It did not run.")

return result

if not result["ok"]:
result["error"] = "%d edit(s) cannot be packed: fix each (path) and check again." % problems.size() \
if not problems.is_empty() else ("\n".join(said.slice(-5)) if not said.is_empty() else "It did not run.")
Expand All @@ -221,6 +242,29 @@ func level_play(_args: Dictionary) -> Variant:
return run_tool("play", "Play level")


func level_place(args: Dictionary) -> Variant:
var extra := PackedStringArray()

if bool(args.get("check", false)):
extra.append("--check")

if bool(args.get("move", false)):
extra.append("--move")

if args.get("water") != null:
extra.append_array(["--water", str(float(args["water"]))])

var only: Variant = args.get("names")

if only is Array and not only.is_empty():
extra.append("--names")

for pattern in only:
extra.append(String(pattern))

return run_tool("place", "Set things down", extra)


func planet_get(_args: Dictionary) -> Dictionary:
PlanetInspector.sync_id()
return {"name": String(ProjectSettings.get_setting("openrac/planet/name", "")),
Expand Down
15 changes: 15 additions & 0 deletions openrac/tools/openrac_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,14 @@ def main() -> None:
sub.add_argument("--data", type=Path, help="the port's game data")
sub.add_argument("--levels", type=Path, help="the port's levels")
sub.add_argument("--no-start", action="store_true", help="pack only: the game is not started")
placing = commands.add_parser("place", help="set a level's mobys, ties and shrubs down on its ground: no "
"floating, no sinking, none in a wall (placement.py)")
placing.add_argument("project", type=Path, help="one level's project (a project per level)")
placing.add_argument("--check", action="store_true", help="only list what is off; change nothing")
placing.add_argument("--names", nargs="+", help="only nodes with these names (* and ? patterns)")
placing.add_argument("--water", type=float, help="the water's height: things afloat on it stay")
placing.add_argument("--move", action="store_true",
help="a made thing (a crate) that cannot stand where it is goes to the nearest good spot")
args = parser.parse_args()
if args.command == "play" and not args.no_start and None in (args.game, args.data, args.levels):
parser.error("play needs --game, --data and --levels (or --no-start)")
Expand All @@ -623,6 +631,13 @@ def main() -> None:
except FormatError as exc:
errors.say(exc)
parser.exit(1, f"openrac_editor: {exc}\n")
if args.command == "place":
import placement
try:
sys.exit(placement.main(args.project.resolve(), args.check, args.names, args.water, args.move))
except OSError as exc:
errors.say(exc)
parser.exit(1, f"openrac_editor: {exc}\n")
if args.command in ("check", "play"):
try:
sys.exit(check_or_play(args))
Expand Down
Loading
Loading