AI Map Compiling
From Mod Wiki
Compiling AI-MAP
Contents |
Basis
Lets start from something easy – lets compile a level with AI and monsters on the map mp_atp. Open the level: first thing to do is to remove all rpoint (those are points of respawn for multyplayer). Moved? Perfect. Creating Spawn elements -> actor and in the Properties lets right the following:
[spawn]
wpn_ak74
Thanks to this the player will have AK74 in weapons after spawn. Next – creating a monster i.e. bloodsucker and put him on the map. Now we need AI map – AI net required for NPCs and monsters in order for them to orientate on the level. Then press Object and click on the earth (now we selected it for following manipulations), next AI Map -> Commands -> Make list from selected, press add in topic AI Map Nodes and add for adding objects on the top-left (kettle) and put nods on the map in order you want (one is enough), press Generate Full. That is all, AI net generated. Must be done: add 1 graph point (Spawns->ai->graph point), you can leave it empty. Save the level, build (build) it.
Do not forget to compile the map, (also do not forget to create X: disk with help of the attached program).
Windows -> start -> run
Write in command line (mp_atp_test is a map name here): xr_lc.bat mp_atp_test
Editing configs
Example: game_maps_single.ltx
[level_maps_single] ... testing_ai //our level name [testing_ai] global_rect = -6,1220.0, 248.0,1481.0 texture = map\map_escape //texture at launch bound_rect = -502.148,-412.284,379.976,474,479 weathers = default //weather game_levels.ltx [levels] ... level190 //our level number [level190] name = testing_ai caption = "testing_ai" offset = 2000.0, 800.0, 1000.0 // our level situated on a global map, X, Y, Z id = 193 //identification number, must be unique game_graphs.ltx 018 = "testing_ai"
Now open AI compiler, specify folder with sdk (.../level_editor, or path to it if it is united with the game). Choose your level. Pass 1st Stage for draft calculation of AI of the map (step 1), or you can choose step 2 if you want to wait longer and calculate hide places for NPCs. Next: building graph and cross-table of the level (step 3), step 4 – graph of the game, step 5 – file . spawn eventually. After all enter gamedata\spawns\ and rename test.spawn to all.spawn.
Important moments 1
While editing config do not forget to specify the real weather there and loading image or it will crash. If you will try to launch the level by following .bat file you will have crash also:
bin\xr_3da.exe -ltx user.ltx -nointro -external -start server(level/single) client(localhost)
Proper .bat file looks like this: @start bin\XR_3DA.exe -start server(%1/single/alife) client(localhost)
Where 1% is name of the level.
Deep learn
Next step – we will learn how to create several levels and make points of transfer between them.
So you have two levels. There is actor on one of them. Lets begin from this level: create ai->level changer, then shape->sphere, enlarge it to needed dimension with help of scale, now switch to editing mode spawn element, select level changer and press commands->attach object, now click on the sphere… This is it: sphere and level changer are linked. Now lets go to bookmark properties, specify the name, i.e. to_atp_2, now we need to write waypoint for return in custom data, in case if a player will refuse to transfer from one location to another (must be). Write this:
[pt_move_if_reject] path = atp_1_way_if_reject //go back in case of rejection of transfer
Put the name of the destination level in Level to change, i.e. atp_2. We have to specify a point in Level Point to change where a player will appear, i.e. start_actor_01. We have finished with level changer on this map. Next. Create graph point or use empty if you have one. Write in it start_actor_01 – we need this point in order to transfer from 2nd level atp_2 to 1st level atp_1. Create one more graph point with name exit_atp_1_01, in location choose i.e. escape. In Connection -> Level name specify level that will be linked with atp_1, in our case it is atp_2, in Connection->Point Name write link point from second level, which we will create later (exit_atp_2_01). First level finished.
Why do we need graph points exit_xx? exit_xxx is connection_point – in order for compilator to know what levels does it links, or in other words: first graph of the level and then all nods are counted from it.
start_actor_xx – point where actor appears after transfer.
Remember we wrote way point in custom data level changer? Now we need to create it. Select Way Points -> press kettle and put one way point near the level changer (by this we created start point of the way), now press point mode and put second one. Press create 1-link if they didn’t linked with an arrow. Now we have a way which we specified in custom data level changer, go to properties and give it the same name that we put in custom data, as you remember atp_1_way_if_reject. Now we finished the first level.
Now open the second level and go ahead… Create a way from two way points according to instructions above and give it a name atp_2_way_if_reject. Create level changer and give it a name to_atp_1, then we write in custom data the following:
[pt_move_if_reject] path = atp_2_way_if_reject //name of the way point
In level to change we specify atp_1 //where we move to with atp_2. In level point to change - start_actor_01 (yes, the one we created in the first level :) )
As well create on atp_2 a graph point with a name start_actor_01. And one more where we write the following:
Name: exit_atp_2_01 Location: "junkyard" //name of the location
Connection:
Level name: atp_1 //first level Point name: exit_atp_1_01 //link point from first level
Do not forget that actor should be only on one location or compiler will show a mistake. Done!... Saving. Recompiling.
Start Ai Compiler and choose one by one our both levels and calculate step 1, check the net. Now create text document and write there:
@start /wait bins\ai\1.exe -g atp_1 @start /wait bins\ai\1.exe -g atp_2
Save it as .bat and launch it. As a result we have level.graph (graph and cross-table) for each level.
Create one more text document and write there:
@start /wait bins\ai\1.exe -m
Save it as .bat and launch it. Now we compiled game.graph from level.graphs. And finally create last .bat for compile of all.spawn:
bins\ai\1.exe -s
Compile it, go to gamedata\spawns\, rename existing spawn in all.spawn, and launch new game. As you see you can transfer from one level to another and back without problems.
Almost forgot – “must do” temporary: before compilation started you should replace other levels of the game except yours to another folder, otherwise there probably will be mistakes whil compiling graphs and spawn.
For compiling all single levels from original game use bat file fullgame.bat . If there will be mistakes with alife press continue. After that do procedures mentioned above, compiling of game.graph, and after that all.spawn.
Adding our level to single player.
Continue. I succeeded to add my test level to the GSC maps.
To start – we need our test level, properly prepared. If you haven’t red the instructions above you will not be able to continue work. Our level must have connection point – then we need to add in it something suitable for our example, i.e. this:
Name: point_test_location_escape // name of connection point
Connection: Level Name:L01_Escape //the level to be connected with Point Name:esc_graph_point_0034 //connection point on escape //explanation how to add it will be //”bellow”.
Done?
Now create one more graph on the level and simply write in its name… i.e. Name: start_actor_01. Then you must add some exclusive thing (i.e. car) on the level. You will know why later. But on the level should not be ACTOR. Save and recompile the level. Compile whole level with help of xrLC, then open AIcompiler and provide steps 1,2 and 3 for our level.
Now we need exceptional tools, in our case we took script from bardak (nickname of VERY good scripter on Russian part of GSC forum – translator’s mark), the script allows us to know at launch of any level level_vertex_id, game_vertex_id, position(coordinates of the player in current moment), direction(coordinates of direction of his “sight”), all these we will need to work with acdc few steps later. Load the game and find appropriate place for a trigger of level transfer and write its parameters on a peace of paper, we will need them later. Properly it should do one more thing: separately get into the level editor , open our level, put ectors directly on the graph start_actor_01, compile the project, pass all steps of compilation in xraicompiler(1,3,4,5,6) do not forget to make backup of game.graph in advance, start new game and write coordinates of level_vertex_id direction but it is too boring, after this you will have to get back to the original game.graph.
So you have to have all the game unpacked, aiwrapper from Bardak installed (read install instruction!!!!) and aicompiler from him.
In the folder with aiwrapper create a .bat file with text:
aiwrapper -extract_spawns
or enter the same text in command line in total commander – by using this key we updated level.spawns of all single levels as they were not updated since first patch. Now learn links.sample in notepad. Nothing clear? Explanation: aiwrapper has very useful key –m2.
-m2 <file> - merge AI-graphs of the maps to global game graph including changes for links from specified file.
In other words with its help we can take any existing graph of GSC which is not reserved and give to it needed figures, i.e. make it a connection point, and then all this will be merged to a whole global game.graph.
Execute aiwrapper -dump_graph graphs.txt by bat or total commander. This command will give us a list of basis picks of AI-graph to the specified file, in other words list of compiled graphs of all single-levels by GSC in file graphs.txt. Find there point esc_graph_point_0034. As you can see it is empty in terms of links which is not the same as in exit_escape_01,02. That means that we can use it. Originally developers put them for bots’ paths, but we will use it for link with our test level.
Create text file links_fixed.txt
[l01_escape] ; adding transfer for AI from Cordon to test level. esc_graph_point_0034 = test_level_x, point_test_location_escape
test_level_x – is a name of our level. point_test_location_escape – connection point on our level. So we add these two parameters to graphpoint on escape, and these parameters transform it to connection point linked to the one on our level; save text file.
You’d better move somewhere unused levels (multyplayer also) for any case. Execute by bat or total commander:
aiwrapper -m2 links_fixed.txt
Waiting for game_graph to get compiled – there should be no mistakes.
Important moments 2
There is more simple way to get calculations of game_vertex_id. In folder UTILS (Bardak’s compiler) there is tool ggtool.pl – utility fro viewing links between levels in game.graph. Copy compiled game.graph to the utility from gamedata/ and execute by bat of through total commander:
ggtool.pl game.graph >svyazi.txt
As a result in file svyazi.txt in () will be specified game_vertex_id for particular level. So you will not need to get dest_game_vertex_id with help of recompiling.
Example: l01_escape (0) --1206.29--> l02_garbage (415)
0 - game_vertex_id, 415 - dest_game_vertex_id, 1206.29 - distance(distance between points), not the one in level_changer, but between connection_points.
Now working on all.spawn
aiwrapper -s
As a result we will have compiled all.spawn of all levels we have in folder levels. This is just a beginning of work. Now we need to edit the received all.spawn and add level_changer on a level of GSC in order to get from it on our level (in our case from escape to test_level_x). Copy received all.spawn to the following place: <place where we unpacked aiwrapper>\utils and create .bat with the following text:
acdc.pl -d all.spawn
As a result we have separated all.spawn in ltxs. We need alife_l01_escape.ltx and in the end of it put:
[unreserved number] ;i.e. 9000 section_name = level_changer name = exit_to_new_location_from_esc ;any_name_in_english, (not reserved only) position = ;here coordinates of level changer placement (situation) ;remember the paper where we have coordinates and parameters? ;see the one where we have coordinates and parameters of escape ;and put them in direction = 0,0,0 ;direction of the sight of the player ;if you want you can put coordinates from the paper game_vertex_id = ;number of peak of game graph, gives first peak of graph on this location ;from paper about escape distance = 14.6999998092651 ;"distance" between level_changer point and point of appearance ;of actor on another level (if consider the Zone as one whole), maybe and 0. level_vertex_id = ;peak of level graph, ‘’’-1’’’ should work, but better ;to put figures that you have on paper object_flags = 0xffffff3e custom_data = <<END [pt_move_if_reject] path = esc_way_test_if_reject END ;custom data, where specified name of waypoint that we will create later ;on the map with help of acdc, and '''custom data''', as in the beginning ;of the article story_id = ;put here unreserved ID, i.e. 8435 shapes = shape0 shape0:type = box shape0:axis_x = 5.8284006118774,0,0 shape0:axis_y = 0,5.0005970001221,0 shape0:axis_z = 0,0,5.3902206420898 shape0:offset = 0,0,0 ;sphere, in our case cub, here exactly our transfer will activate restrictor_type = 3 ;put here all variables for new level dest_game_vertex_id = ;number of graph peak of new location, there the player will be tranfered ;remember '''unique''' object, I asked you to put? ;open '''alife_lxx_unknown.ltx''' and looking for car, take its parameters dest_level_vertex_id = ;peak of level graph of new level ;should work -1, but better take it from the paper you wrote ;with parameters of new level dest_position = ;coordinates of appearance of the player ;take them from the paper, or guess, or use corrected coordinates relating ;to an object on our map, i.e. take coordinates of a tree ;with coordinates 0, 1 , 2, correct them relating to the tree position and ;put i.e. 4, 1, 2 dest_direction = 0,-1.12671363353729,0 ;direction of sight of the player on new map ;по желанию dest_level_name = ;name of the level, in our case it is test_level_x dest_graph_point = ;name of spawn point of the player (of graph, in our case ;start_actor_01)
One more definition of the two parameters for dummies:
game_vertex_id – put as a connection point (graph_point with appropriate configs)
level_vertex_id - graph_point – put as common graph point with unique number without parameters
Put in them unique ID for every level, in some cases just take these two parameters from nearest objects and correct the figures. As a rule level_vertex_id may be -1, but not for all objects, game_vertex_id = level ID.
Got tired? :D But ths is not all. We need to create waypoint, which we had put in custom data level changer. Open way_l01_escape.ltx and write something like:
[esc_way_test_if_reject] points = p0,p1 ;two waypoints p0:name = name_test1 ;waypoint name 1 p0:position = -243.491257,-19.758562,-140.328583 ;its coordinates, put them near coordinates of level_changer ;but not in it, correct the coordinates as in example with the tree. p0:game_vertex_id = 8 p0:level_vertex_id = -1 p0:links = p1(1) p1:name = name_test2 ;name of the 2 waypoints p1:position = -255.491257,-19.758562,-140.328583 ;its coordinates, all the same, but correct them relating to the position of ;waypoint 0, as in this example. p1:game_vertex_id = 9 p1:level_vertex_id = -1
Got it? Now we need only to compile all.spawn, execute by bat or total commander:
acdc.pl -c all.ltx
Now copy received all.spawn.new to gamedata\spawns\ and rename it in all.spawn.
End of tortures Start new game and enjoy your level transfer.
After all
If you want your transfer point to appear on the map of the player, go to the level_tasks.script and to function add_lchanger_location() section like the one bellow:
-- test_level_x local obj = sim:story_object(8435) if obj then level.map_add_object_spot(obj.id, "level_changer", "exit_to_new_location_from_esc") end
In line (obj.id, "level_changer", "exit_to_new_location_from_esc") highlited text – is name of your level_changer, number – its unique story_id on the level, i.e. on escape or your level, list of reserved story_id look in lua_help.script
List of required programs
- AiCompiler 0.1 from Neo
- AiWrapper from bardak
- Info_LVID_GVID script from bardak
- SDK 0.4 from GSC
- SDK Update from Neo + GSC