Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enemy AI
- // ListTileScoring
- // To contain id of every tile in level
- // GridTileScoring
- // x = Map data structure, containing:
- // tile id, tile x and y, any occupant, whether it can be traversed or not, and if so its move cost,
- // tile type, status, alternated list of abilities and targets, and score
- // y = Score
- ListTileScoring = ds_list_create();
- var GridTileScoring = ds_grid_create(instance_number(oTile),2);
- //var GridTileScoring = ds_grid_create(2,instance_number(oTile));
- ListTileMaps = ds_list_create();
- // Work through list, building a map for each tile of all details and options
- // Add the tile's map and tile's score to GridTileScoring
- var ListPos = 0;
- for (CheckX = 0; CheckX < oGenRoom.GridWidth; CheckX = CheckX + 1) {
- // Looping through for as long as CheckY is less than GridHeight:
- for (CheckY = 0; CheckY < oGenRoom.GridHeight; CheckY = CheckY + 1) {
- // Establish map and variables
- var MapTileScoring = ds_map_create();
- //var TileID; // This is object_index, not a simple number like other map IDs
- var TileGridX; // oGenRoom.Grid GridX
- var TileGridY; // oGenRoom.Grid GridX
- var TileOccupant; // Occupant id, or noone
- var TilePassable; // Boolean
- var TileMoveCost; // Number value, real
- var TileType; // Grass, water, etc
- var TileHeight; // Integer, real
- var TileEffect; // Burning, etc, or noone
- //var TileListActions; // Alternated (divisible by 2) list of abilities and targets
- //var TileScore; // Score for movement, according to all of the above
- TileID = oGenRoom.Grid[# CheckX, CheckY];
- TileGridX = oGenRoom.Grid[# CheckX, CheckY].GridX;
- TileGridY = oGenRoom.Grid[# CheckX, CheckY].GridY;
- TileOccupant = oGenRoom.Grid[# CheckX, CheckY].Occupant;
- TilePassable = oGenRoom.Grid[# CheckX, CheckY].Passable;
- TileMoveCost = oGenRoom.Grid[# CheckX, CheckY].MoveCost;
- TileType = oGenRoom.Grid[# CheckX, CheckY].TileType;
- TileHeight = oGenRoom.Grid[# CheckX, CheckY].Height;
- TileEffect = oGenRoom.Grid[# CheckX, CheckY].Effect;
- TileListActions = ds_list_create();
- TileScore = scrTileScore(oGenRoom.Grid[# CheckX, CheckY],0);
- with oGenRoom.Grid[# CheckX, CheckY] {
- TileScore = other.TileScore;
- }
- // Add variables to map
- ds_map_add(MapTileScoring, "TileID", TileID);
- ds_map_add(MapTileScoring, "TileGridX", TileGridX);
- ds_map_add(MapTileScoring, "TileGridY", TileGridY);
- ds_map_add(MapTileScoring, "TileOccupant", TileOccupant);
- ds_map_add(MapTileScoring, "TilePassable", TilePassable);
- ds_map_add(MapTileScoring, "TileMoveCost", TileMoveCost);
- ds_map_add(MapTileScoring, "TileType", TileType);
- ds_map_add(MapTileScoring, "TileHeight", TileHeight);
- ds_map_add(MapTileScoring, "TileEffect", TileEffect);
- ds_map_add(MapTileScoring, "TileListActions", TileListActions);
- ds_map_add(MapTileScoring, "TileScore", TileScore);
- // Add map to list and grid, add score to grid
- ds_list_add(ListTileMaps,MapTileScoring);
- ds_grid_add(GridTileScoring,ListPos,0,MapTileScoring);
- ds_grid_add(GridTileScoring,ListPos,1,TileScore);
- ListPos = ListPos + 1;
- }
- CheckY = 0;
- //ListPos = ListPos + 1;
- }
- // Once all tiles are in GridTileScoring, sort grid by score
- ds_grid_sort(GridTileScoring,1,false);
- // Apply margin dependent on enemy capability to top # of options, and choose one
- // **** DISABLED FOR TESTING ****
- // Set size of list of best options to choose from based on enemy difficulty (ie modifier minus 0 to 5, 5 being smartest enemy)
- // This many options from the top down are added to a list (so long as they exist)
- // Then desired tile is chosen by random number, 0 to this list's length - 1
- /**///
- /*
- var DifficultyModifier = 1;
- ListBestTiles = ds_list_create();
- var i;
- for (i = 0; i < DifficultyModifier; i = i + 1) {
- // Delete tiles with TileCurrentScore = false from list
- // Store map
- var BestTileMapCurrent = ds_grid_get(GridTileScoring, 0, i);
- // Pull tile id from map, add to ListBestTiles
- ds_list_add(ListBestTiles,BestTileMapCurrent[? "TileID"]);
- }
- DesiredTileID = ds_list_find_value(ListBestTiles,irandom_range(0,ds_list_size(ListBestTiles)-1));
- var DesiredTile;
- // When DesiredTile is chosen, find its map in ListTileScoring
- var TileIndex = scrFindTile(DesiredTileID);
- // Once found...
- if (TileIndex > -1) {
- var data = ds_list_find_value(ListTileMaps,TileIndex);
- DesiredTile = oGenRoom.Grid[# ds_map_find_value(data, "TileGridX"), ds_map_find_value(data,"TileGridY")];
- }
- */
- // Store desired tile id
- var DesiredTileMap = ds_grid_get(GridTileScoring,0,0);
- //var DesiredTileMap = GridTileScoring[# 0, 0];
- //var DesiredTile = oGenRoom.Grid[# Selected.UICharacterNumber,Selected.UICharacterNumber];
- //var DesiredTile = oGenRoom.Grid[# ds_map_find_value(DesiredTileMap,"TileGridX"),ds_map_find_value(DesiredTileMap,"TileGridY")];
- var DesiredTile = ds_map_find_value(DesiredTileMap,"TileID");
- // From map, pull TileListActions
- DesiredTileListActions = ds_list_create();
- // If there are abilities and targets listed...
- if !ds_list_empty(ds_map_find_value(DesiredTileMap, "TileListActions")) {
- ds_list_copy(DesiredTileListActions,ds_map_find_value(DesiredTileMap, "TileListActions"));
- // Choose an even number for ability to perform, + 1 is the target of that ability
- var DTLAI = irandom_range(0,ds_list_size(DesiredTileListActions));
- // Even number -- DTLAI = ability name
- // DTLAI + 1 = target character
- if DTLAI mod 2 == 0 {
- AbilityQueued = ds_list_find_value(DesiredTileListActions,DTLAI);
- var DesiredTarget = ds_list_find_value(DesiredTileListActions,DTLAI + 1);
- TargetAttackTile = DesiredTarget.TileCurrent;
- }
- // Odd number -- target
- else if DTLAI mod 2 == 1 {
- AbilityQueued = ds_list_find_value(DesiredTileListActions,DTLAI - 1);
- var DesiredTarget = ds_list_find_value(DesiredTileListActions,DTLAI);
- TargetAttackTile = DesiredTarget.TileCurrent;
- }
- }
- // Else if there are no abilities and targets listed...
- else {
- TargetAttackTile = noone;
- AbilityQueued = noone;
- }
- // Set TargetAttackTile
- //TargetAttackTile = ds_list_find_index(DesiredTileListActions,oGenRoom.Grid[# DesiredTarget.GridX, DesiredTarget.GridY]);
- // Queue action and move to tile as necessary
- // Generate list of tiles from those within our single move range
- scrMovementRangeAI(oGenRoom.Grid[#Selected.GridX,Selected.GridY],Selected.Move,Selected.Actions);
- // If desired tile is within movement range...
- if DesiredTile.MoveTile == true {
- // Build path of movement with priority queue
- //Current = TargetMoveTile;
- Current = DesiredTile;
- Path = ds_priority_create();
- with Selected {
- StackPath = ds_stack_create();
- ds_stack_push(StackPath,other.Current);
- }
- // Add current tile to the queue
- ds_priority_add(Path, Current, Current.GScore);
- // Step through each tile from path parent to path parent, connecting the path
- // until the first tile in the path has a link, or "PathParent"
- while (Current.PathParent != noone) {
- // Add PathParent tile to queue. Priority = PathParent's GScore
- ds_priority_add(Path,Current.PathParent,Current.PathParent.GScore);
- // Set Current to Current's PathParent, then repeat
- Current = Current.PathParent;
- // Add each tile to the path stack
- with Selected {
- ds_stack_push(StackPath,other.Current);
- }
- }
- do {
- // Delete lowest priority tile (closest to character), store id in Current
- Current = ds_priority_delete_min(Path);
- // Add current tile's sprite coords to character's path
- path_add_point(Selected.MovementPath, Current.x, Current.y, 100);
- //path_add_point(Selected.MovementPath, Current.x, (Current.y - Current.HeightOffset), 100);
- }
- until
- ds_priority_empty(Path);
- // Destroy queue
- ds_priority_destroy(Path);
- // If destination tile is not the same as old tile...
- if oGenRoom.Grid[#Current.GridX,Current.GridY] != oGenRoom.Grid[#Selected.GridX,Selected.GridY] {
- // Reduce Selected's actions according to distance
- // Blue into yellow - 2 Actions spent
- if Current.GScore > Selected.Move {
- Selected.Actions = Selected.Actions - 2;
- Selected.AbilityQueued = noone;
- Selected.TargetAttackTile = noone;
- }
- // Blue into blue - 1 Action spent
- else if Current.GScore <= Selected.Move {
- Selected.Actions = Selected.Actions - 1;
- // Set ability, even if "noone"
- Selected.AbilityQueued = AbilityQueued;
- // Set target tile, even if "noone"
- //if ds_list_empty(ArrayTileScoring[ArrayCheck,2]) == false {
- Selected.TargetAttackTile = TargetAttackTile;
- }
- // Clear previous tile of occupant
- oGenRoom.Grid[#Selected.GridX,Selected.GridY].Occupant = noone;
- // Update character's grid coords with chosen tile's coords
- Selected.GridX = Current.GridX;
- Selected.GridY = Current.GridY;
- // Update destination tile's status for arrival
- Current.Occupant = Selected;
- // Add destination tile to end of stack
- with Selected {
- ds_stack_push(StackPath,other.Current);
- }
- // Send character on path to destination
- Selected.State = "BeginPath";
- }
- // Else skip straight to BeginAbility state
- else {
- // Set ability, even if "noone"
- Selected.AbilityQueued = AbilityQueued;
- // Set target tile, even if "noone"
- if TargetAttackTile != noone {
- Selected.TargetAttackTile = TargetAttackTile;
- }
- else {
- Selected.AbilityQueued = noone;
- Selected.TargetAttackTile = noone;
- }
- Selected.State = "BeginAbility";
- }
- }
- // If desired tile is not within movement range, move to closest move tile to desired tile
- else {
- // Placeholder end turn
- Selected.AbilityQueued = noone;
- Selected.TargetAttackTile = noone;
- Selected.State = "BeginAbility";
- }
- // Destroy data structures
- ds_list_destroy(ListTileScoring);
- ds_grid_destroy(GridTileScoring);
- ds_list_destroy(ListTileMaps);
- //ds_list_destroy(ListBestTiles);
- ds_list_destroy(DesiredTileListActions);
- // End turn
- //// NEW ////
- // Add all tiles on level to grid
- // One column to hold a map with all tile details, second to hold the tile's score
- // Work through every tile, perform checks, apply score
- // Sort grid by second column, the score
- // Choose a tile at top of grid/list based on difficulty modifier
- // If chosen tile has an associated ability and target, queue them
- // At this point store a esired queued action, or noone;
- // Tile scoring factors (unmodified by individual traits):
- // Actions that can be taken (enemies hit, allies not hit, allies buffed)
- // Occupant (allied, enemy, obstacle, objective)
- // Occupant adjacent (allied, enemy, obstacle, objective)
- // No hazard
- // No hazard adjacent
- // Difficulty of terrain
- // Proximity/distance to allies, enemies
- // Height difference
- // Height
- // End turn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement