Advertisement
Guest User

shit code

a guest
Jun 18th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // if combat range > 1500, it most definitely means they are a sniper.
  2.         // !== In any state ==!
  3.         if aiTaggedBy != noone { //attack people you are tagged by (currently broken)
  4.             switch(aiClass) {
  5.                 case class.soldier:{
  6.                     aiMarkedEnemy = aiTaggedBy;
  7.                     aiStatus = aiState.attack;
  8.                     aiTaggedBy = noone;
  9.                     break;
  10.                 }
  11.                 case class.sniper: {
  12.                     aiMarkedEnemy = noone;
  13.                     aiStatus = aiState.attack;
  14.                     aiTaggedBy = noone;
  15.                     break;
  16.                 }
  17.                 case class.medical: {
  18.                     break;
  19.                 }
  20.                 default: {
  21.                     aiMarkedEnemy = aiTaggedBy;
  22.                     aiStatus = aiState.attack;
  23.                     aiTaggedBy = noone;
  24.                     break;
  25.                 }
  26.             }
  27.         }
  28.        
  29.         if position_meeting(x,y,entitySolid) { //anti-wallstick
  30.             x+= 10;
  31.         }
  32.        
  33.         if aiObjective[? "objective"] != noone and aiStatus != aiState.attack { //inclusive objective assignment
  34.             aiStatus = aiState.do_assigned_objective;
  35.         }
  36.        
  37.         if ds_exists(aiAssignedTask,ds_type_map) and aiStatus != aiState.do_assigned_objective and aiStatus != aiState.attack and aiClass == class.constructor {
  38.             aiStatus = aiState.do_assigned_task;
  39.         }
  40.        
  41.         if aiMarkedHealTarget != noone {
  42.             if aiMarkedHealTarget.entityHealth <= 0 {
  43.                 aiActivateChangePath = false
  44.                 path_end();
  45.             }
  46.         }
  47.        
  48.         if aiClass == class.medical { //inclusive medic healing (within task zone)
  49.             aiHeal = false
  50.            
  51.             if aiNearestFriendly != noone and aiNearestFriendly != self {
  52.                 aiMarkedHealTarget = aiNearestFriendly
  53.                
  54.                 lookPosition = point_direction(x,y,aiMarkedHealTarget.x,aiMarkedHealTarget.y)
  55.                
  56.                 if aiObjective[? "objective"] == noone {
  57.                     if distance_to_object(aiMarkedHealTarget) <= 64 {
  58.                         aiActivateChangePath = false
  59.                         path_end();
  60.                     }
  61.                 }
  62.                
  63.                 if path_index == -1 and aiObjective[? "objective"] == noone {
  64.                     if distance_to_object(aiMarkedHealTarget) > 64 {
  65.                         ai_change_path(aiMarkedHealTarget.x,aiMarkedHealTarget.y)
  66.                     }
  67.                 }
  68.                
  69.                 aiHeal = (distance_to_object(aiMarkedHealTarget) < aiTaskRange)
  70.                
  71.                 if aiHeal {
  72.                     aiMarkedHealTarget.entityHealth = clamp(aiMarkedHealTarget.entityHealth + aiHealSpeed,0,aiMarkedHealTarget.entityHealthMax);
  73.                 }
  74.             }
  75.         }
  76.    
  77.         switch(aiStatus) {
  78.             case aiState.idle: { //non-inclusive orders
  79.                 //THIS IS IMPLEMENTED PRIORIETY ORDER
  80.                 //Higher if's are higher prioriety
  81.                
  82.                 if entityCamera.follow == self and aiLastDirective != aiState.idle {
  83.                     print(string(id) + " Picking new directive... (aiState.idle)")
  84.                    
  85.                 }
  86.                 aiLastDirective = aiState.idle
  87.                
  88.                 if !ds_exists(aiAssignedTask,ds_type_map) and ds_queue_size(aiQueuedTasks[aiTeam]) > 0 and aiClass == class.constructor {
  89.                     aiAssignedTask = ds_queue_head(aiQueuedTasks[aiTeam])
  90.                     ds_queue_dequeue(aiQueuedTasks[aiTeam]);
  91.                     //print("ok")
  92.                     break;
  93.                 }
  94.                
  95.                 if path_index != -1 {
  96.                     lookPosition = point_direction(x,y,aiGotoPos[0],aiGotoPos[1]);
  97.                 }
  98.                
  99.                 break;
  100.             }
  101.            
  102.             case aiState.do_assigned_task: {
  103.                 switch(aiAssignedTask[? "taskid"]) {
  104.                     case aiTask.build: {
  105.                         if aiBuildTarget == noone and ds_queue_size(aiQueuedTasks[aiTeam]) > 0 {
  106.                             aiBuildTarget = aiAssignedTask[? "instance"]
  107.                         }
  108.                
  109.                         if aiLastTask != aiTask.build {
  110.                             path_end();
  111.                             if entityCamera.follow == self {
  112.                                 print(string(id) + " I have been directed to build.")
  113.                             }
  114.                         }
  115.                
  116.                         aiLastTask = aiTask.build
  117.                
  118.                         if instance_exists(aiBuildTarget) == false {
  119.                             aiStatus = aiState.idle
  120.                             aiAssignedTask = noone;
  121.                             aiBuildTarget = noone;
  122.                             break;
  123.                         }
  124.                
  125.                         var touch = collision_rectangle(x-48,y-48,x+48,y+48,aiBuildTarget,false,true)
  126.                
  127.                         if path_index == -1 and touch == noone and aiBuildTarget != noone {
  128.                             ai_change_path(aiBuildTarget.x+16,aiBuildTarget.y+16)
  129.                         }
  130.                
  131.                         if aiBuildTarget != noone {
  132.                             lookPosition = point_direction(x,y,aiBuildTarget.x,aiBuildTarget.y)
  133.                         }
  134.                
  135.                         if touch and aiBuildTarget != noone  {
  136.                             aiBuildTarget.buildingLevel++
  137.                             path_end()
  138.                    
  139.                             if aiBuildTarget.buildingLevel > aiBuildTarget.buildingMaxLevel {
  140.                                 instance_create_depth(aiBuildTarget.x+get_build_offset("x",aiBuildTarget.buildID),aiBuildTarget.y+get_build_offset("y",aiBuildTarget.buildID),0,get_build_object(aiBuildTarget.buildID))
  141.                                 mp_grid_add_instances(global.grid,aiBuildTarget,false);
  142.                                 instance_destroy(aiBuildTarget)
  143.                                 aiBuildTarget = noone
  144.                                 aiStatus = aiState.idle
  145.                                 aiAssignedTask = noone;
  146.                             }
  147.                         }
  148.                         break;
  149.                     }
  150.                     case aiTask.takeReqMatToObj: {
  151.                         if aiPickupTarget == noone {
  152.                             aiPickupTarget = get_world_item(aiAssignedTask[? "matid"],aiTeam)
  153.                         }
  154.                        
  155.                         if aiPickupTarget != noone {
  156.                             if ds_exists(aiAssignedTask,ds_type_map) == true { // Check whether the object to build
  157.                                 if instance_exists(aiAssignedTask[? "instance"]) == false {
  158.                                     ds_map_destroy(aiAssignedTask)
  159.                                     aiAssignedTask = noone;
  160.                                     aiPickupTarget = noone;
  161.                                     aiStatus = aiState.idle;
  162.                                     break;
  163.                                 }
  164.                             } else {
  165.                                 aiAssignedTask = noone;
  166.                                 aiPickupTarget = noone;
  167.                                 aiStatus = aiState.idle;
  168.                                 break;
  169.                             }
  170.                            
  171.                             var aiGiveTarget = aiAssignedTask[? "instance"]
  172.                            
  173.                             if ds_exists(aiPickupTarget,ds_type_map) == true {
  174.                                 if instance_exists(aiAssignedTask[? "instance"]) == false {
  175.                                 ds_map_destroy(aiPickupTarget);
  176.                                     aiAssignedTask = noone;
  177.                                     aiPickupTarget = noone;
  178.                                     aiStatus = aiState.idle;
  179.                                     break;
  180.                                 }
  181.                                
  182.                             } else {
  183.                                 aiAssignedTask = noone;
  184.                                 aiPickupTarget = noone;
  185.                                 aiStatus = aiState.idle;
  186.                                 break;
  187.                             }
  188.                            
  189.                             var aiGetTarget = aiPickupTarget[? "instance"]
  190.                            
  191.                             var touch
  192.                            
  193.                             if aiHoldingItem == noone {
  194.                                 touch = collision_rectangle(x-48,y-48,x+48,y+48,aiGetTarget,false,true);
  195.                             } else {
  196.                                 touch = collision_rectangle(x-48,y-48,x+48,y+48,aiGiveTarget,false,true);
  197.                             }
  198.                            
  199.                             if path_index == -1 and touch == noone and aiPickupTarget != noone {
  200.                                 if aiHoldingItem == noone {
  201.                                     ai_change_path(aiGetTarget.x,aiGetTarget.y)
  202.                                 } else {
  203.                                     ai_change_path(aiGiveTarget.x,aiGiveTarget.y);
  204.                                 }
  205.                             }
  206.                            
  207.                             if touch != noone {
  208.                                
  209.                                
  210.                                 if aiHoldingItem == noone {
  211.                                     var count = clamp(aiPickupTarget[? "quantity"],0,aiAssignedTask[? "quantity"]);
  212.                                    
  213.                                     if count < aiAssignedTask[? "quantity"] {
  214.                                         var newTask = ds_map_create();
  215.                                         ds_map_copy(newTask,aiAssignedTask);
  216.                                         newTask[? "quantity"] -= count;
  217.                                        
  218.                                         ds_queue_enqueue(aiQueuedTasks[aiTeam],newTask);
  219.                                     }
  220.                                    
  221.                                     var newQuant = aiPickupTarget[? "quantity"] - count;
  222.                                     aiHoldingItem = ds_map_create();
  223.                                     ds_map_copy(aiHoldingItem,aiPickupTarget);
  224.                                     aiHoldingItem[? "quantity"] = count
  225.                                     update_world_item(aiGetTarget,newQuant);
  226.                                 } else {
  227.                                    
  228.                                 }
  229.                             }
  230.                         } else {
  231.                             ds_queue_enqueue(aiQueuedTasks[aiTeam],aiAssignedTask)
  232.                             aiAssignedTask = noone;
  233.                             aiStatus = aiState.idle
  234.                         }
  235.                         break;
  236.                     }
  237.                 }
  238.             }
  239.            
  240.             case aiState.do_assigned_objective: {
  241.                 switch(aiObjective[? "objective"]) {
  242.                     case aiAssignedObjective.move_to_pos: {
  243.                         if aiObjective[? "objActive"] == false {
  244.                             path_end();
  245.                             aiObjective[? "objActive"] = true;
  246.                         }
  247.                        
  248.                         var ax = aiObjective[? "associatePointX"];
  249.                         var ay = aiObjective[? "associatePointY"];
  250.                        
  251.                         if path_index == -1 {
  252.                             ai_change_path(ax,ay);
  253.                         }
  254.                        
  255.                         lookPosition = point_direction(x,y,ax,ay)
  256.                        
  257.                         if distance_to_point(ax,ay) < 16 {
  258.                             aiObjective[? "objective"] = noone;
  259.                             aiStatus = aiState.idle;
  260.                             path_end();
  261.                         }
  262.                        
  263.                         break;
  264.                     }
  265.                     case aiAssignedObjective.return_to_base: {
  266.                         if aiObjective[? "objActive"] == false {
  267.                             path_end();
  268.                             aiObjective[? "objActive"] = true;
  269.                         }
  270.                        
  271.                         var ax = controllerGame.aiTeamRespawn[aiTeam].x;
  272.                         var ay = controllerGame.aiTeamRespawn[aiTeam].y;
  273.                        
  274.                         if path_index == -1 {
  275.                             ai_change_path(ax,ay);
  276.                         }
  277.                        
  278.                         lookPosition = point_direction(x,y,ax,ay)
  279.                        
  280.                         if distance_to_point(ax,ay) < 16 {
  281.                             aiObjective[? "objective"] = noone;
  282.                             aiStatus = aiState.idle;
  283.                             path_end();
  284.                         }
  285.                        
  286.                         break;
  287.                     }
  288.                 }
  289.                 break;
  290.             }
  291.        
  292.             // !== Attack ==!
  293.             case aiState.attack: {
  294.                 if aiMarkedEnemy == noone {
  295.                     aiStatus = aiState.idle;
  296.                     break;
  297.                 }
  298.                
  299.                 if aiLastDirective != aiState.attack {
  300.                     path_end();
  301.                    
  302.                     if entityCamera.follow == self {
  303.                         print(string(id) + " I have been directed to attack")
  304.                     }
  305.                 }
  306.                 aiLastDirective = aiState.attack
  307.                 //if aiMarkedEnemy.xprevious != aiMarkedEnemy.x and aiMarkedEnemy.yprevious != aiMarkedEnemy.y {
  308.                
  309.                 //}
  310.                 if !instance_exists(aiMarkedEnemy) {
  311.                     aiMarkedEnemy = noone;
  312.                     aiFire = false;
  313.                     path_end()
  314.                     break;
  315.                 }
  316.            
  317.                 if (distance_to_object(aiMarkedEnemy) > aiCombatRange) {
  318.                     aiMarkedEnemy = noone;
  319.                     aiFire = false;
  320.                     path_end()
  321.                     break;
  322.                 }
  323.                
  324.                 if collision_line(x,y,aiMarkedEnemy.x,aiMarkedEnemy.y,entitySolid,false,true) == noone {
  325.                     aiFire = true
  326.                    
  327.                     if path_index == -1 {
  328.                         aiLastSeen[0] = aiMarkedEnemy.x
  329.                         aiLastSeen[1] = aiMarkedEnemy.y
  330.                        
  331.                         var _x,_y
  332.                        
  333.                         //var distanceToEnemy = distance_to_object(aiMarkedEnemy)
  334.                        
  335.                         if aiCombatRange <= 1500 {
  336.                             _x = aiMarkedEnemy.x + lengthdir_x(aiCombatRange*0.3,point_direction(aiMarkedEnemy.x,aiMarkedEnemy.y,x,y) + irandom_range(-20,20))
  337.                             _y = aiMarkedEnemy.y + lengthdir_y(aiCombatRange*0.3,point_direction(aiMarkedEnemy.x,aiMarkedEnemy.y,x,y) + irandom_range(-20,20))
  338.                         } else {
  339.                             path_end();
  340.                             _x = x;
  341.                             _y = y;
  342.                         }
  343.                    
  344.                         ai_change_path(_x,_y)
  345.                     }
  346.                 } else {
  347.                     aiFire = false;
  348.                     if path_index == -1 {
  349.                         ai_change_path(aiMarkedEnemy.x,aiMarkedEnemy.y)
  350.                     }
  351.                 }
  352.  
  353.            
  354.                 lookPosition = point_direction(x,y,aiMarkedEnemy.x,aiMarkedEnemy.y)
  355.                 aiTarget = image_angle
  356.            
  357.                 aiFire = true
  358.            
  359.                 if aiMarkedEnemy.entityHealth <= 0 {
  360.                     aiMarkedEnemy = noone;
  361.                     path_end()
  362.                     aiStatus = aiState.idle
  363.                     aiFire = false;
  364.                 }
  365.                 break;
  366.             }
  367.             // !== Defence ==!
  368.             case aiState.defend_object: {
  369.            
  370.                 break;
  371.             }
  372.        
  373.             // !== Fleeing ==!
  374.             case aiState.flee: {
  375.                 if aiLastDirective != aiState.flee {
  376.                     path_end();
  377.                     if entityCamera.follow == self {
  378.                         print(string(id) + " I have been directed to flee!")
  379.                     }
  380.                 }
  381.                
  382.                 aiLastDirective = aiState.flee
  383.                
  384.                 if aiNearestEnemy == noone {
  385.                     aiStatus = aiState.idle;
  386.                     break;
  387.                 }
  388.                
  389.                 lookPosition = point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y)
  390.                
  391.                
  392.                 var dis = aiFleeRange - distance_to_object(aiNearestEnemy)
  393.  
  394.                 var xdir = x + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
  395.                 var ydir = y + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
  396.                
  397.                 if path_index == -1 {
  398.                     ai_change_path(clamp(xdir,0,room_width),clamp(ydir,0,room_height));
  399.                 }
  400.                
  401.                 if distance_to_object(aiNearestEnemy) > aiFleeRange or aiNearestEnemy.entityHealth <= 0 {
  402.                     aiStatus = aiState.idle;
  403.                 }
  404.                
  405.                 aiFire = false
  406.                 break;
  407.             }
  408.             case aiState.flee_attack: {
  409.                 if aiLastDirective != aiState.flee {
  410.                     path_end();
  411.                     if entityCamera.follow == self {
  412.                         print(string(id) + " I have been directed to flee_attack!")
  413.                     }
  414.                 }
  415.                
  416.                 aiLastDirective = aiState.flee
  417.                
  418.                 if aiNearestEnemy == noone {
  419.                     aiStatus = aiState.idle;
  420.                     break;
  421.                 }
  422.                
  423.                 lookPosition = point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y)
  424.                
  425.                 aiFire = true
  426.                 aiTarget = image_angle
  427.            
  428.                 var dis = aiFleeRange - distance_to_object(aiNearestEnemy)
  429.  
  430.                 var xdir = x + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
  431.                 var ydir = y + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
  432.                
  433.                 if path_index == -1 {
  434.                     ai_change_path(clamp(xdir,0,room_width),clamp(ydir,0,room_height));
  435.                 }
  436.                
  437.                 if distance_to_object(aiNearestEnemy) > aiFleeAttackRange or aiNearestEnemy.entityHealth <= 0 {
  438.                     aiStatus = aiState.idle;
  439.                     aiFire = false
  440.                 }
  441.                 break;
  442.             }
  443.        
  444.             // !== Misc ==!
  445.             case aiState.build: {
  446.                
  447.                 break;
  448.             }
  449.             case aiState.panic: {
  450.            
  451.                 break;
  452.             }
  453.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement