Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // if combat range > 1500, it most definitely means they are a sniper.
- // !== In any state ==!
- if aiTaggedBy != noone { //attack people you are tagged by (currently broken)
- switch(aiClass) {
- case class.soldier:{
- aiMarkedEnemy = aiTaggedBy;
- aiStatus = aiState.attack;
- aiTaggedBy = noone;
- break;
- }
- case class.sniper: {
- aiMarkedEnemy = noone;
- aiStatus = aiState.attack;
- aiTaggedBy = noone;
- break;
- }
- case class.medical: {
- break;
- }
- default: {
- aiMarkedEnemy = aiTaggedBy;
- aiStatus = aiState.attack;
- aiTaggedBy = noone;
- break;
- }
- }
- }
- if position_meeting(x,y,entitySolid) { //anti-wallstick
- x+= 10;
- }
- if aiObjective[? "objective"] != noone and aiStatus != aiState.attack { //inclusive objective assignment
- aiStatus = aiState.do_assigned_objective;
- }
- if ds_exists(aiAssignedTask,ds_type_map) and aiStatus != aiState.do_assigned_objective and aiStatus != aiState.attack and aiClass == class.constructor {
- aiStatus = aiState.do_assigned_task;
- }
- if aiMarkedHealTarget != noone {
- if aiMarkedHealTarget.entityHealth <= 0 {
- aiActivateChangePath = false
- path_end();
- }
- }
- if aiClass == class.medical { //inclusive medic healing (within task zone)
- aiHeal = false
- if aiNearestFriendly != noone and aiNearestFriendly != self {
- aiMarkedHealTarget = aiNearestFriendly
- lookPosition = point_direction(x,y,aiMarkedHealTarget.x,aiMarkedHealTarget.y)
- if aiObjective[? "objective"] == noone {
- if distance_to_object(aiMarkedHealTarget) <= 64 {
- aiActivateChangePath = false
- path_end();
- }
- }
- if path_index == -1 and aiObjective[? "objective"] == noone {
- if distance_to_object(aiMarkedHealTarget) > 64 {
- ai_change_path(aiMarkedHealTarget.x,aiMarkedHealTarget.y)
- }
- }
- aiHeal = (distance_to_object(aiMarkedHealTarget) < aiTaskRange)
- if aiHeal {
- aiMarkedHealTarget.entityHealth = clamp(aiMarkedHealTarget.entityHealth + aiHealSpeed,0,aiMarkedHealTarget.entityHealthMax);
- }
- }
- }
- switch(aiStatus) {
- case aiState.idle: { //non-inclusive orders
- //THIS IS IMPLEMENTED PRIORIETY ORDER
- //Higher if's are higher prioriety
- if entityCamera.follow == self and aiLastDirective != aiState.idle {
- print(string(id) + " Picking new directive... (aiState.idle)")
- }
- aiLastDirective = aiState.idle
- if !ds_exists(aiAssignedTask,ds_type_map) and ds_queue_size(aiQueuedTasks[aiTeam]) > 0 and aiClass == class.constructor {
- aiAssignedTask = ds_queue_head(aiQueuedTasks[aiTeam])
- ds_queue_dequeue(aiQueuedTasks[aiTeam]);
- //print("ok")
- break;
- }
- if path_index != -1 {
- lookPosition = point_direction(x,y,aiGotoPos[0],aiGotoPos[1]);
- }
- break;
- }
- case aiState.do_assigned_task: {
- switch(aiAssignedTask[? "taskid"]) {
- case aiTask.build: {
- if aiBuildTarget == noone and ds_queue_size(aiQueuedTasks[aiTeam]) > 0 {
- aiBuildTarget = aiAssignedTask[? "instance"]
- }
- if aiLastTask != aiTask.build {
- path_end();
- if entityCamera.follow == self {
- print(string(id) + " I have been directed to build.")
- }
- }
- aiLastTask = aiTask.build
- if instance_exists(aiBuildTarget) == false {
- aiStatus = aiState.idle
- aiAssignedTask = noone;
- aiBuildTarget = noone;
- break;
- }
- var touch = collision_rectangle(x-48,y-48,x+48,y+48,aiBuildTarget,false,true)
- if path_index == -1 and touch == noone and aiBuildTarget != noone {
- ai_change_path(aiBuildTarget.x+16,aiBuildTarget.y+16)
- }
- if aiBuildTarget != noone {
- lookPosition = point_direction(x,y,aiBuildTarget.x,aiBuildTarget.y)
- }
- if touch and aiBuildTarget != noone {
- aiBuildTarget.buildingLevel++
- path_end()
- if aiBuildTarget.buildingLevel > aiBuildTarget.buildingMaxLevel {
- 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))
- mp_grid_add_instances(global.grid,aiBuildTarget,false);
- instance_destroy(aiBuildTarget)
- aiBuildTarget = noone
- aiStatus = aiState.idle
- aiAssignedTask = noone;
- }
- }
- break;
- }
- case aiTask.takeReqMatToObj: {
- if aiPickupTarget == noone {
- aiPickupTarget = get_world_item(aiAssignedTask[? "matid"],aiTeam)
- }
- if aiPickupTarget != noone {
- if ds_exists(aiAssignedTask,ds_type_map) == true { // Check whether the object to build
- if instance_exists(aiAssignedTask[? "instance"]) == false {
- ds_map_destroy(aiAssignedTask)
- aiAssignedTask = noone;
- aiPickupTarget = noone;
- aiStatus = aiState.idle;
- break;
- }
- } else {
- aiAssignedTask = noone;
- aiPickupTarget = noone;
- aiStatus = aiState.idle;
- break;
- }
- var aiGiveTarget = aiAssignedTask[? "instance"]
- if ds_exists(aiPickupTarget,ds_type_map) == true {
- if instance_exists(aiAssignedTask[? "instance"]) == false {
- ds_map_destroy(aiPickupTarget);
- aiAssignedTask = noone;
- aiPickupTarget = noone;
- aiStatus = aiState.idle;
- break;
- }
- } else {
- aiAssignedTask = noone;
- aiPickupTarget = noone;
- aiStatus = aiState.idle;
- break;
- }
- var aiGetTarget = aiPickupTarget[? "instance"]
- var touch
- if aiHoldingItem == noone {
- touch = collision_rectangle(x-48,y-48,x+48,y+48,aiGetTarget,false,true);
- } else {
- touch = collision_rectangle(x-48,y-48,x+48,y+48,aiGiveTarget,false,true);
- }
- if path_index == -1 and touch == noone and aiPickupTarget != noone {
- if aiHoldingItem == noone {
- ai_change_path(aiGetTarget.x,aiGetTarget.y)
- } else {
- ai_change_path(aiGiveTarget.x,aiGiveTarget.y);
- }
- }
- if touch != noone {
- if aiHoldingItem == noone {
- var count = clamp(aiPickupTarget[? "quantity"],0,aiAssignedTask[? "quantity"]);
- if count < aiAssignedTask[? "quantity"] {
- var newTask = ds_map_create();
- ds_map_copy(newTask,aiAssignedTask);
- newTask[? "quantity"] -= count;
- ds_queue_enqueue(aiQueuedTasks[aiTeam],newTask);
- }
- var newQuant = aiPickupTarget[? "quantity"] - count;
- aiHoldingItem = ds_map_create();
- ds_map_copy(aiHoldingItem,aiPickupTarget);
- aiHoldingItem[? "quantity"] = count
- update_world_item(aiGetTarget,newQuant);
- } else {
- }
- }
- } else {
- ds_queue_enqueue(aiQueuedTasks[aiTeam],aiAssignedTask)
- aiAssignedTask = noone;
- aiStatus = aiState.idle
- }
- break;
- }
- }
- }
- case aiState.do_assigned_objective: {
- switch(aiObjective[? "objective"]) {
- case aiAssignedObjective.move_to_pos: {
- if aiObjective[? "objActive"] == false {
- path_end();
- aiObjective[? "objActive"] = true;
- }
- var ax = aiObjective[? "associatePointX"];
- var ay = aiObjective[? "associatePointY"];
- if path_index == -1 {
- ai_change_path(ax,ay);
- }
- lookPosition = point_direction(x,y,ax,ay)
- if distance_to_point(ax,ay) < 16 {
- aiObjective[? "objective"] = noone;
- aiStatus = aiState.idle;
- path_end();
- }
- break;
- }
- case aiAssignedObjective.return_to_base: {
- if aiObjective[? "objActive"] == false {
- path_end();
- aiObjective[? "objActive"] = true;
- }
- var ax = controllerGame.aiTeamRespawn[aiTeam].x;
- var ay = controllerGame.aiTeamRespawn[aiTeam].y;
- if path_index == -1 {
- ai_change_path(ax,ay);
- }
- lookPosition = point_direction(x,y,ax,ay)
- if distance_to_point(ax,ay) < 16 {
- aiObjective[? "objective"] = noone;
- aiStatus = aiState.idle;
- path_end();
- }
- break;
- }
- }
- break;
- }
- // !== Attack ==!
- case aiState.attack: {
- if aiMarkedEnemy == noone {
- aiStatus = aiState.idle;
- break;
- }
- if aiLastDirective != aiState.attack {
- path_end();
- if entityCamera.follow == self {
- print(string(id) + " I have been directed to attack")
- }
- }
- aiLastDirective = aiState.attack
- //if aiMarkedEnemy.xprevious != aiMarkedEnemy.x and aiMarkedEnemy.yprevious != aiMarkedEnemy.y {
- //}
- if !instance_exists(aiMarkedEnemy) {
- aiMarkedEnemy = noone;
- aiFire = false;
- path_end()
- break;
- }
- if (distance_to_object(aiMarkedEnemy) > aiCombatRange) {
- aiMarkedEnemy = noone;
- aiFire = false;
- path_end()
- break;
- }
- if collision_line(x,y,aiMarkedEnemy.x,aiMarkedEnemy.y,entitySolid,false,true) == noone {
- aiFire = true
- if path_index == -1 {
- aiLastSeen[0] = aiMarkedEnemy.x
- aiLastSeen[1] = aiMarkedEnemy.y
- var _x,_y
- //var distanceToEnemy = distance_to_object(aiMarkedEnemy)
- if aiCombatRange <= 1500 {
- _x = aiMarkedEnemy.x + lengthdir_x(aiCombatRange*0.3,point_direction(aiMarkedEnemy.x,aiMarkedEnemy.y,x,y) + irandom_range(-20,20))
- _y = aiMarkedEnemy.y + lengthdir_y(aiCombatRange*0.3,point_direction(aiMarkedEnemy.x,aiMarkedEnemy.y,x,y) + irandom_range(-20,20))
- } else {
- path_end();
- _x = x;
- _y = y;
- }
- ai_change_path(_x,_y)
- }
- } else {
- aiFire = false;
- if path_index == -1 {
- ai_change_path(aiMarkedEnemy.x,aiMarkedEnemy.y)
- }
- }
- lookPosition = point_direction(x,y,aiMarkedEnemy.x,aiMarkedEnemy.y)
- aiTarget = image_angle
- aiFire = true
- if aiMarkedEnemy.entityHealth <= 0 {
- aiMarkedEnemy = noone;
- path_end()
- aiStatus = aiState.idle
- aiFire = false;
- }
- break;
- }
- // !== Defence ==!
- case aiState.defend_object: {
- break;
- }
- // !== Fleeing ==!
- case aiState.flee: {
- if aiLastDirective != aiState.flee {
- path_end();
- if entityCamera.follow == self {
- print(string(id) + " I have been directed to flee!")
- }
- }
- aiLastDirective = aiState.flee
- if aiNearestEnemy == noone {
- aiStatus = aiState.idle;
- break;
- }
- lookPosition = point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y)
- var dis = aiFleeRange - distance_to_object(aiNearestEnemy)
- var xdir = x + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
- var ydir = y + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
- if path_index == -1 {
- ai_change_path(clamp(xdir,0,room_width),clamp(ydir,0,room_height));
- }
- if distance_to_object(aiNearestEnemy) > aiFleeRange or aiNearestEnemy.entityHealth <= 0 {
- aiStatus = aiState.idle;
- }
- aiFire = false
- break;
- }
- case aiState.flee_attack: {
- if aiLastDirective != aiState.flee {
- path_end();
- if entityCamera.follow == self {
- print(string(id) + " I have been directed to flee_attack!")
- }
- }
- aiLastDirective = aiState.flee
- if aiNearestEnemy == noone {
- aiStatus = aiState.idle;
- break;
- }
- lookPosition = point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y)
- aiFire = true
- aiTarget = image_angle
- var dis = aiFleeRange - distance_to_object(aiNearestEnemy)
- var xdir = x + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
- var ydir = y + lengthdir_x(dis,point_direction(x,y,aiNearestEnemy.x,aiNearestEnemy.y) + 180)
- if path_index == -1 {
- ai_change_path(clamp(xdir,0,room_width),clamp(ydir,0,room_height));
- }
- if distance_to_object(aiNearestEnemy) > aiFleeAttackRange or aiNearestEnemy.entityHealth <= 0 {
- aiStatus = aiState.idle;
- aiFire = false
- }
- break;
- }
- // !== Misc ==!
- case aiState.build: {
- break;
- }
- case aiState.panic: {
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement