#include "mech.h"
#include "mech.events.h"
#include "autopilot.h"
#include "coolmenu.h"
#include "mycool.h"
#include "p.mech.utils.h"
Include dependency graph for autopilot_core.c:
Go to the source code of this file.
Defines | |
#define | AI_COMMAND_DLLIST_START 51 |
#define | AI_COMMAND_DLLIST_END 63 |
#define | outbyte(a) tmpb=(a); fwrite(&tmpb, 1, 1, file); |
#define | CHESA(a, b, c, d) |
#define | CHELO(a, b, c, d) |
#define | SPECIAL_FREE 0 |
#define | SPECIAL_ALLOC 1 |
Functions | |
static command_node * | auto_create_command_node () |
void | auto_destroy_command_node (command_node *node) |
static void | auto_write_command_node (FILE *file, command_node *node) |
static command_node * | auto_read_command_node (FILE *file) |
void | auto_save_commands (FILE *file, AUTO *autopilot) |
void | auto_load_commands (FILE *file, AUTO *autopilot) |
int | auto_valid_progline (AUTO *a, int p) |
static char * | auto_show_command (command_node *node) |
void | auto_delcommand (dbref player, void *data, char *buffer) |
void | auto_jump (dbref player, void *data, char *buffer) |
void | auto_addcommand (dbref player, void *data, char *buffer) |
void | auto_listcommands (dbref player, void *data, char *buffer) |
void | auto_eventstats (dbref player, void *data, char *buffer) |
static int | auto_pilot_on (AUTO *autopilot) |
void | auto_stop_pilot (AUTO *autopilot) |
void | auto_set_comtitle (AUTO *autopilot, MECH *mech) |
void | auto_init (AUTO *autopilot, MECH *mech) |
void | auto_engage (dbref player, void *data, char *buffer) |
void | auto_disengage (dbref player, void *data, char *buffer) |
void | auto_goto_next_command (AUTO *autopilot, int time) |
char * | auto_get_command_arg (AUTO *autopilot, int command_number, int arg_number) |
int | auto_get_command_enum (AUTO *autopilot, int command_number) |
void | auto_newautopilot (dbref key, void **data, int selector) |
void | auto_heartbeat (AUTO *autopilot) |
Variables | |
ACOM | acom [AUTO_NUM_COMMANDS+1] |
char * | muxevent_names [] |
unsigned int | global_tick |
#define AI_COMMAND_DLLIST_END 63 |
Definition at line 22 of file autopilot_core.c.
Referenced by auto_load_commands(), and auto_save_commands().
#define AI_COMMAND_DLLIST_START 51 |
Definition at line 21 of file autopilot_core.c.
Referenced by auto_load_commands(), and auto_save_commands().
#define CHELO | ( | a, | |||
b, | |||||
c, | |||||
d | ) |
Value:
if ((tmpb=fread(a,b,c,d)) != c) \ { fprintf (stderr, "Error loading dllist\n"); \ fflush(stderr); exit(1); }
Definition at line 30 of file autopilot_core.c.
Referenced by auto_load_commands(), auto_read_command_node(), load_mapdynamic(), loadrepairs(), and map_load_bits().
#define CHESA | ( | a, | |||
b, | |||||
c, | |||||
d | ) |
Value:
if ((tmpb=fwrite(a,b,c,d)) != c) \ { fprintf (stderr, "Error writing dllist\n"); \ fflush(stderr); exit(1); }
Definition at line 26 of file autopilot_core.c.
Referenced by auto_save_commands(), auto_write_command_node(), map_save_bits(), save_event(), save_mapdynamic(), and saverepairs().
#define outbyte | ( | a | ) | tmpb=(a); fwrite(&tmpb, 1, 1, file); |
Definition at line 24 of file autopilot_core.c.
Referenced by auto_save_commands(), map_save_bits(), save_mapdynamic(), and save_mapobjs().
#define SPECIAL_ALLOC 1 |
Definition at line 876 of file autopilot_core.c.
Referenced by auto_newautopilot(), newfreemap(), newfreemech(), newfreemechrep(), NewSpecialObject(), and newturret().
#define SPECIAL_FREE 0 |
Definition at line 875 of file autopilot_core.c.
Referenced by auto_newautopilot(), DisposeSpecialObject(), newfreemap(), and newfreemech().
void auto_addcommand | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 449 of file autopilot_core.c.
References acom, ACOM::ai_command_function, command_node_t::ai_command_function, ACOM::argcount, command_node_t::argcount, command_node_t::args, args, auto_create_command_node(), auto_show_command(), AUTOPILOT_MAX_ARGS, ACOM::command_enum, command_node_t::command_enum, AUTO::commands, dllist_create_node(), dllist_insert_end(), DOCHECK, first_parseattribute(), name, ACOM::name, notify, notify_printf(), and proper_explodearguments().
Referenced by auto_com_event(), auto_radio_command_dfollow(), auto_radio_command_dgoto(), auto_radio_command_dropoff(), auto_radio_command_embark(), auto_radio_command_enterbase(), auto_radio_command_follow(), auto_radio_command_goto(), auto_radio_command_leavebase(), auto_radio_command_ogoto(), and auto_radio_command_pickup().
00450 { 00451 00452 AUTO *autopilot = (AUTO *) data; 00453 char *args[AUTOPILOT_MAX_ARGS]; /* args[0] is the command the rest are 00454 args for the command */ 00455 char *command; /* temp string to get the name of the command */ 00456 int argc; 00457 int i, j; 00458 00459 command_node *temp_command_node; 00460 dllist_node *temp_dllist_node; 00461 00462 /* Clear the Args */ 00463 memset(args, 0, sizeof(char *) * AUTOPILOT_MAX_ARGS); 00464 00465 command = first_parseattribute(buffer); 00466 00467 /* Look at the buffer and try and get the command */ 00468 for(i = 0; acom[i].name; i++) { 00469 if((!strncmp(command, acom[i].name, strlen(command))) && 00470 (!strncmp(acom[i].name, command, strlen(acom[i].name)))) 00471 break; 00472 } 00473 00474 /* Free the command string we dont need it anymore */ 00475 free(command); 00476 00477 /* Make sure its a valid command */ 00478 DOCHECK(!acom[i].name, "Invalid Command!"); 00479 00480 /* Get the arguments for the command */ 00481 if(acom[i].argcount > 0) { 00482 00483 /* Parse the buffer for commands 00484 * Its argcount + 1 because we are parsing the command + its 00485 * arguments */ 00486 argc = proper_explodearguments(buffer, args, acom[i].argcount + 1); 00487 00488 if(argc != acom[i].argcount + 1) { 00489 00490 /* Free the args before we quit */ 00491 for(j = 0; j < AUTOPILOT_MAX_ARGS; j++) { 00492 if(args[j]) 00493 free(args[j]); 00494 } 00495 notify(player, "Not the proper number of arguments!"); 00496 return; 00497 00498 } 00499 00500 } else { 00501 00502 /* Copy the command to the first arg */ 00503 args[0] = strdup(acom[i].name); 00504 00505 } 00506 00507 /* Build the command node */ 00508 temp_command_node = auto_create_command_node(); 00509 00510 for(j = 0; j < AUTOPILOT_MAX_ARGS; j++) { 00511 if(args[j]) 00512 temp_command_node->args[j] = args[j]; 00513 } 00514 00515 temp_command_node->argcount = acom[i].argcount; 00516 temp_command_node->command_enum = acom[i].command_enum; 00517 temp_command_node->ai_command_function = acom[i].ai_command_function; 00518 00519 /* Add the command to the list */ 00520 temp_dllist_node = dllist_create_node(temp_command_node); 00521 dllist_insert_end(autopilot->commands, temp_dllist_node); 00522 00523 /* Let the player know it worked */ 00524 notify_printf(player, "Command Added: %s", 00525 auto_show_command(temp_command_node)); 00526 00527 }
static command_node* auto_create_command_node | ( | ) | [static] |
Definition at line 38 of file autopilot_core.c.
References command_node_t::ai_command_function.
Referenced by auto_addcommand(), and auto_read_command_node().
00039 { 00040 00041 command_node *temp; 00042 00043 temp = malloc(sizeof(command_node)); 00044 if(temp == NULL) 00045 return NULL; 00046 00047 memset(temp, 0, sizeof(command_node)); 00048 temp->ai_command_function = NULL; 00049 00050 return temp; 00051 00052 }
void auto_delcommand | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 326 of file autopilot_core.c.
References auto_destroy_command_node(), AUTO::commands, dllist_head(), dllist_remove(), dllist_remove_node_at_pos(), dllist_size(), MBUF_SIZE, AUTO::mynum, notify, notify_printf(), Readnum, and SendAI.
Referenced by auto_radio_command_reset().
00327 { 00328 00329 int p, i; 00330 AUTO *autopilot = (AUTO *) data; 00331 int remove_all_commands = 0; 00332 command_node *temp_command_node; 00333 char error_buf[MBUF_SIZE]; 00334 00335 /* Make sure they specified an argument */ 00336 if(!*buffer) { 00337 notify(player, "No argument used : Usage delcommand [num]\n"); 00338 notify_printf(player, "Must be within the range" 00339 " 1 to %d or -1 for all\n", 00340 dllist_size(autopilot->commands)); 00341 return; 00342 } 00343 00344 /* Make sure its a number */ 00345 if(Readnum(p, buffer)) { 00346 notify_printf(player, "Invalid Argument : Must be within the range" 00347 " 1 to %d or -1 for all\n", 00348 dllist_size(autopilot->commands)); 00349 return; 00350 } 00351 00352 /* Check if its a valid command position 00353 * If its -1 means remove all */ 00354 if(p == -1) { 00355 remove_all_commands = 1; 00356 } else if((p > dllist_size(autopilot->commands)) || (p < 1)) { 00357 notify_printf(player, "Invalid Argument : Must be within the range" 00358 " 1 to %d or -1 for all\n", 00359 dllist_size(autopilot->commands)); 00360 return; 00361 } 00362 00366 /* Now remove the node(s) */ 00367 if(!remove_all_commands) { 00368 00369 /* Remove the node at pos */ 00370 temp_command_node = 00371 (command_node *) dllist_remove_node_at_pos(autopilot->commands, 00372 p); 00373 00374 if(!temp_command_node) { 00375 snprintf(error_buf, MBUF_SIZE, 00376 "Internal AI Error: Trying to remove" 00377 " Command #%d from AI #%d but the command node doesn't exist\n", 00378 p, autopilot->mynum); 00379 SendAI(error_buf); 00380 } 00381 00382 /* Destroy the command_node */ 00383 auto_destroy_command_node(temp_command_node); 00384 00385 notify_printf(player, "Command #%d Successfully Removed\n", p); 00386 00387 } else { 00388 00389 /* Remove ALL the commands */ 00390 while (dllist_size(autopilot->commands)) { 00391 00392 /* Remove the first node on the list and get the data 00393 * from it */ 00394 temp_command_node = 00395 (command_node *) dllist_remove(autopilot->commands, 00396 dllist_head(autopilot-> 00397 commands)); 00398 00399 /* Make sure the command node exists */ 00400 if(!temp_command_node) { 00401 00402 snprintf(error_buf, MBUF_SIZE, 00403 "Internal AI Error: Trying to remove" 00404 " the first command from AI #%d but the command node doesn't exist\n", 00405 autopilot->mynum); 00406 SendAI(error_buf); 00407 00408 } else { 00409 00410 /* Destroy the command node */ 00411 auto_destroy_command_node(temp_command_node); 00412 00413 } 00414 00415 } 00416 00417 notify(player, "All the commands have been removed.\n"); 00418 00419 } 00420 00421 }
void auto_destroy_command_node | ( | command_node * | node | ) |
Definition at line 57 of file autopilot_core.c.
References command_node_t::args, and AUTOPILOT_MAX_ARGS.
Referenced by auto_delcommand(), auto_goto_next_command(), auto_newautopilot(), and newfreemech().
00058 { 00059 00060 int i; 00061 00062 /* Free the args */ 00063 for(i = 0; i < AUTOPILOT_MAX_ARGS; i++) { 00064 if(node->args[i]) { 00065 free(node->args[i]); 00066 node->args[i] = NULL; 00067 } 00068 } 00069 00070 /* Free the node */ 00071 free(node); 00072 00073 return; 00074 00075 }
void auto_disengage | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 722 of file autopilot_core.c.
References auto_pilot_on(), auto_stop_pilot(), DOCHECK, and notify.
Referenced by auto_radio_command_reset().
00723 { 00724 00725 AUTO *autopilot = (AUTO *) data; 00726 00727 DOCHECK(!auto_pilot_on(autopilot), 00728 "The autopilot's already offline! You have to engage it first."); 00729 00730 auto_stop_pilot(autopilot); 00731 notify(player, "Autopilot has been disengaged."); 00732 00733 return; 00734 00735 }
void auto_engage | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 689 of file autopilot_core.c.
References auto_com_event(), auto_init(), auto_pilot_on(), auto_set_comtitle(), AUTOEVENT, AUTOPILOT_NC_DELAY, DOCHECK, EVENT_AUTOCOM, getMech(), Location, MECH::mapindex, AUTO::mapindex, MechAuto, AUTO::mymech, AUTO::mymechnum, AUTO::mynum, and notify.
Referenced by auto_radio_command_dfollow(), auto_radio_command_dgoto(), auto_radio_command_dropoff(), auto_radio_command_embark(), auto_radio_command_enterbase(), auto_radio_command_follow(), auto_radio_command_goto(), auto_radio_command_heading(), auto_radio_command_leavebase(), auto_radio_command_ogoto(), auto_radio_command_pickup(), auto_radio_command_reset(), and auto_radio_command_stop().
00690 { 00691 00692 AUTO *autopilot = (AUTO *) data; 00693 MECH *mech; 00694 00695 autopilot->mymech = mech = 00696 getMech((autopilot->mymechnum = Location(autopilot->mynum))); 00697 DOCHECK(!autopilot, "Internal error! - Bad AI object!"); 00698 DOCHECK(!mech, "Error: The autopilot isn't inside a 'mech!"); 00699 DOCHECK(auto_pilot_on(autopilot), 00700 "The autopilot's already online! You have to disengage it first."); 00701 00702 if(MechAuto(mech) <= 0) 00703 auto_init(autopilot, mech); 00704 MechAuto(mech) = autopilot->mynum; 00705 00706 if(MechAuto(mech) > 0) 00707 auto_set_comtitle(autopilot, mech); 00708 00709 autopilot->mapindex = mech->mapindex; 00710 00711 notify(player, "Engaging autopilot..."); 00712 AUTOEVENT(autopilot, EVENT_AUTOCOM, auto_com_event, AUTOPILOT_NC_DELAY, 00713 0); 00714 00715 return; 00716 00717 }
void auto_eventstats | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 578 of file autopilot_core.c.
References FIRST_AUTO_EVENT, LAST_AUTO_EVENT, muxevent_count_type_data(), muxevent_names, notify, notify_printf(), and total.
00579 { 00580 00581 AUTO *autopilot = (AUTO *) data; 00582 int i, j, total; 00583 00584 notify(player, "Events by type: "); 00585 notify(player, "-------------------------------"); 00586 00587 total = 0; 00588 00589 for(i = FIRST_AUTO_EVENT; i <= LAST_AUTO_EVENT; i++) { 00590 00591 if((j = muxevent_count_type_data(i, (void *) autopilot))) { 00592 notify_printf(player, "%-20s%d", muxevent_names[i], j); 00593 total += j; 00594 } 00595 00596 } 00597 00598 if(total) { 00599 notify(player, "-------------------------------"); 00600 notify_printf(player, "%d total", total); 00601 } 00602 00603 }
char* auto_get_command_arg | ( | AUTO * | autopilot, | |
int | command_number, | |||
int | arg_number | |||
) |
Definition at line 777 of file autopilot_core.c.
References command_node_t::args, AUTOPILOT_MAX_ARGS, AUTO::commands, dllist_get_node(), dllist_size(), MBUF_SIZE, AUTO::mynum, SendAI, and strndup().
Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_command_autogun(), auto_command_embark(), auto_command_pickup(), auto_command_roam(), auto_command_speed(), auto_dumbfollow_event(), auto_dumbgoto_event(), auto_enter_event(), auto_goto_event(), and auto_leave_event().
00779 { 00780 00781 char *argument; 00782 command_node *temp_command_node; 00783 char error_buf[MBUF_SIZE]; 00784 00785 if(command_number > dllist_size(autopilot->commands)) { 00786 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to " 00787 "access Command #%d for AI #%d but it doesn't exist", 00788 command_number, autopilot->mynum); 00789 SendAI(error_buf); 00790 return NULL; 00791 } 00792 00793 if(arg_number >= AUTOPILOT_MAX_ARGS) { 00794 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to " 00795 "access Arg #%d for AI #%d Command #%d but its greater" 00796 " then AUTOPILOT_MAX_ARGS (%d)", 00797 arg_number, autopilot->mynum, command_number, 00798 AUTOPILOT_MAX_ARGS); 00799 SendAI(error_buf); 00800 return NULL; 00801 } 00802 00803 temp_command_node = (command_node *) dllist_get_node(autopilot->commands, 00804 command_number); 00805 00808 if(!temp_command_node->args[arg_number]) { 00809 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to " 00810 "access Arg #%d for AI #%d Command #%d but it doesn't exist", 00811 autopilot->mynum, arg_number, command_number); 00812 SendAI(error_buf); 00813 return NULL; 00814 } 00815 00816 argument = strndup(temp_command_node->args[arg_number], MBUF_SIZE); 00817 00818 return argument; 00819 00820 }
int auto_get_command_enum | ( | AUTO * | autopilot, | |
int | command_number | |||
) |
Definition at line 826 of file autopilot_core.c.
References AUTO_NUM_COMMANDS, command_node_t::command_enum, AUTO::commands, dllist_get_node(), dllist_size(), MBUF_SIZE, AUTO::mynum, and SendAI.
Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_astar_roam_event(), auto_cal_mapindex(), auto_com_event(), auto_dumbfollow_event(), auto_dumbgoto_event(), auto_enter_event(), and auto_leave_event().
00827 { 00828 00829 int command_enum; 00830 command_node *temp_command_node; 00831 char error_buf[MBUF_SIZE]; 00832 00833 /* Make sure there are commands */ 00834 if(dllist_size(autopilot->commands) <= 0) { 00835 return -1; 00836 } 00837 00838 if(command_number <= 0) { 00839 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to " 00840 "access a command (%d) for AI #%d that can't be on a list", 00841 command_number, autopilot->mynum); 00842 SendAI(error_buf); 00843 return -1; 00844 } 00845 00846 /* Make sure the command is on the list */ 00847 if(command_number > dllist_size(autopilot->commands)) { 00848 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to " 00849 "access Command #%d for AI #%d but it doesn't exist", 00850 autopilot->mynum, command_number); 00851 SendAI(error_buf); 00852 return -1; 00853 } 00854 00855 temp_command_node = (command_node *) dllist_get_node(autopilot->commands, 00856 command_number); 00857 00860 command_enum = temp_command_node->command_enum; 00861 00862 /* If its a bad enum value we have a problem */ 00863 if((command_enum >= AUTO_NUM_COMMANDS) || (command_enum < 0)) { 00864 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Command ENUM for" 00865 " AI #%d Command Number #%d doesn't exist\n", 00866 autopilot->mynum, command_number); 00867 SendAI(error_buf); 00868 return -1; 00869 } 00870 00871 return command_enum; 00872 00873 }
void auto_goto_next_command | ( | AUTO * | autopilot, | |
int | time | |||
) |
Definition at line 740 of file autopilot_core.c.
References AUTO_COM, auto_destroy_command_node(), AUTO::commands, dllist_head(), dllist_remove(), dllist_size(), MBUF_SIZE, AUTO::mynum, and SendAI.
Referenced by auto_astar_follow_event(), auto_astar_goto_event(), auto_astar_roam_event(), auto_com_event(), auto_command_roam(), auto_command_startup(), auto_dumbfollow_event(), auto_dumbgoto_event(), auto_enter_event(), auto_goto_event(), and auto_leave_event().
00741 { 00742 00743 command_node *temp_command_node; 00744 char error_buf[MBUF_SIZE]; 00745 00746 if(dllist_size(autopilot->commands) < 0) { 00747 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to remove" 00748 " the first command from AI #%d but the command list is empty\n", 00749 autopilot->mynum); 00750 SendAI(error_buf); 00751 return; 00752 } 00753 00754 temp_command_node = (command_node *) dllist_remove(autopilot->commands, 00755 dllist_head(autopilot-> 00756 commands)); 00757 00758 if(!temp_command_node) { 00759 snprintf(error_buf, MBUF_SIZE, "Internal AI Error: Trying to remove" 00760 " the first command from AI #%d but the command node doesn't exist\n", 00761 autopilot->mynum); 00762 SendAI(error_buf); 00763 return; 00764 } 00765 00766 auto_destroy_command_node(temp_command_node); 00767 00768 /* Fire off the AUTO_COM event */ 00769 AUTO_COM(autopilot, time); 00770 00771 }
void auto_heartbeat | ( | AUTO * | autopilot | ) |
Definition at line 966 of file autopilot_core.c.
References auto_gun_event(), AUTO_PROFILE_TICK, auto_sensor_event(), auto_update_profile_event(), global_tick, AUTO::mymech, and AUTO::weaplist.
Referenced by heartbeat_dispatch().
00966 { 00967 if(!autopilot->mymech) return; 00968 auto_sensor_event(autopilot); 00969 if(autopilot->weaplist == NULL || global_tick % AUTO_PROFILE_TICK == 0) 00970 auto_update_profile_event(autopilot); 00971 auto_gun_event(autopilot); 00972 }
Definition at line 659 of file autopilot_core.c.
References AUTO::auto_cdist, AUTO::auto_cmode, AUTO::auto_fweight, AUTO::auto_goweight, AUTO_GUN_UPDATE_TICK, AUTO::auto_nervous, AUTOPILOT_CHASETARG_UPDATE_TICK, AUTOPILOT_FOLLOW_UPDATE_TICK, AUTO::chase_target, AUTO::chasetarg_update_tick, AUTO::flags, AUTO::follow_update_tick, AUTO::ofsx, AUTO::ofsy, AUTO::speed, AUTO::target, AUTO::target_score, AUTO::target_threshold, and AUTO::target_update_tick.
Referenced by auto_engage(), and auto_radio_command_reset().
00660 { 00661 00662 autopilot->ofsx = 0; /* Positional - angle */ 00663 autopilot->ofsy = 0; /* Positional - distance */ 00664 autopilot->auto_cmode = 1; /* CHARGE! */ 00665 autopilot->auto_cdist = 2; /* Attempt to avoid kicking distance */ 00666 autopilot->auto_nervous = 0; 00667 autopilot->auto_goweight = 44; /* We're mainly concentrating on fighting */ 00668 autopilot->auto_fweight = 55; 00669 autopilot->speed = 100; /* Reset to full speed */ 00670 autopilot->flags = 0; 00671 00672 /* Target Stuff */ 00673 autopilot->target = -2; 00674 autopilot->target_score = 0; 00675 autopilot->target_threshold = 50; 00676 autopilot->target_update_tick = AUTO_GUN_UPDATE_TICK; 00677 00678 /* Follow & Chase target stuff */ 00679 autopilot->chase_target = -10; 00680 autopilot->chasetarg_update_tick = AUTOPILOT_CHASETARG_UPDATE_TICK; 00681 autopilot->follow_update_tick = AUTOPILOT_FOLLOW_UPDATE_TICK; 00682 00683 }
void auto_jump | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 427 of file autopilot_core.c.
References auto_valid_progline(), DOCHECK, notify, notify_printf(), PG, Readnum, and skipws.
00428 { 00429 int p; 00430 AUTO *a = (AUTO *) data; 00431 00432 notify(player, "jump has been temporarly disabled till I can figure out" 00433 " how I want to change it - Dany"); 00434 #if 0 00435 skipws(buffer); 00436 DOCHECK(!*buffer, "Argument expected!"); 00437 DOCHECK(Readnum(p, buffer), "Invalid argument - single number expected."); 00438 /* Find out if it's valid position */ 00439 DOCHECK(!auto_valid_progline(a, p), 00440 "Invalid : Argument out of range, or argument, not command."); 00441 PG(a) = p; 00442 notify_printf(player, "Program Counter set to #%d.", p); 00443 #endif 00444 }
void auto_listcommands | ( | dbref | player, | |
void * | data, | |||
char * | buffer | |||
) |
Definition at line 532 of file autopilot_core.c.
References addline, auto_show_command(), c, AUTO::commands, dllist_get_node(), dllist_size(), AUTO::flags, KillCoolMenu(), Location, AUTO::mapindex, MBUF_SIZE, AUTO::mymechnum, AUTO::mynum, Name(), ShowCoolMenu(), AUTO::speed, and vsi.
00533 { 00534 00535 AUTO *autopilot = (AUTO *) data; 00536 coolmenu *c = NULL; 00537 char buf[MBUF_SIZE]; 00538 int i, count = 0; 00539 00540 addline(); 00541 00542 snprintf(buf, MBUF_SIZE, "Autopilot data for %s", Name(autopilot->mynum)); 00543 vsi(buf); 00544 00545 snprintf(buf, MBUF_SIZE, "Controling unit %s", 00546 Name(Location(autopilot->mynum))); 00547 vsi(buf); 00548 00549 addline(); 00550 00551 snprintf(buf, MBUF_SIZE, "MyRef: #%d MechRef: #%d MapIndex: #%d " 00552 "FSpeed: %d %% (Flag:%d)", autopilot->mynum, 00553 autopilot->mymechnum, autopilot->mapindex, autopilot->speed, 00554 autopilot->flags); 00555 vsi(buf); 00556 00557 addline(); 00558 00559 if(dllist_size(autopilot->commands)) { 00560 00561 for(i = 1; i <= dllist_size(autopilot->commands); i++) { 00562 snprintf(buf, MBUF_SIZE, "#%-3d %s", i, 00563 auto_show_command((command_node *) 00564 dllist_get_node(autopilot->commands, 00565 i))); 00566 vsi(buf); 00567 } 00568 00569 } else { 00570 vsi("No commands have been queued to date."); 00571 } 00572 00573 addline(); 00574 ShowCoolMenu(player, c); 00575 KillCoolMenu(c); 00576 }
void auto_load_commands | ( | FILE * | file, | |
AUTO * | autopilot | |||
) |
Definition at line 211 of file autopilot_core.c.
References AI_COMMAND_DLLIST_END, AI_COMMAND_DLLIST_START, auto_read_command_node(), CHELO, AUTO::commands, dllist_create_list(), dllist_create_node(), dllist_insert_end(), and AUTO::mynum.
00212 { 00213 00214 int i; /* Our Counter */ 00215 unsigned char tmpb; /* Our temp int we use when reading */ 00216 unsigned int size; /* The size of our command list */ 00217 00218 dllist_node *temp_dllist_node; 00219 command_node *temp_command_node; 00220 00221 /* Alloc a dllist to the AI for commands */ 00222 autopilot->commands = dllist_create_list(); 00223 00224 /* If we can't even read the file don't bother 00225 * with the rest */ 00226 if(feof(file)) 00227 return; 00228 00229 /* Loop for the beginning tag */ 00230 fread(&tmpb, 1, 1, file); 00231 if(tmpb != AI_COMMAND_DLLIST_START) { 00232 fprintf(stderr, "Unable to locate START for reading data" 00233 " for AI #%d\n", autopilot->mynum); 00234 fflush(stderr); 00235 exit(1); 00236 } 00237 00238 /* Read in size of dllist */ 00239 CHELO(&size, sizeof(size), 1, file); 00240 00241 /* if size is bigger then zero means we have to read 00242 * in some command nodes */ 00243 if(size > 0) { 00244 00245 /* Loop through the list and add the nodes */ 00246 for(i = 1; i <= size; i++) { 00247 00248 temp_command_node = auto_read_command_node(file); 00249 temp_dllist_node = dllist_create_node(temp_command_node); 00250 dllist_insert_end(autopilot->commands, temp_dllist_node); 00251 00252 } 00253 00254 } 00255 00256 /* Look for the end tag */ 00257 fread(&tmpb, 1, 1, file); 00258 if(tmpb != AI_COMMAND_DLLIST_END) { 00259 fprintf(stderr, "Unable to locate END for reading data" 00260 " for AI #%d\n", autopilot->mynum); 00261 fflush(stderr); 00262 exit(1); 00263 } 00264 00265 return; 00266 00267 }
void auto_newautopilot | ( | dbref | key, | |
void ** | data, | |||
int | selector | |||
) |
Definition at line 882 of file autopilot_core.c.
References AUTO::astar_path, auto_destroy_astar_path(), auto_destroy_command_node(), auto_destroy_weaplist(), AUTO_PROFILE_MAX_SIZE, auto_stop_pilot(), AUTO::commands, dllist_create_list(), dllist_destroy_list(), dllist_head(), dllist_remove(), dllist_size(), getMech(), MechAuto, AUTO::mymechnum, AUTO::mynum, AUTO::profile, rb_destroy(), SPECIAL_ALLOC, SPECIAL_FREE, AUTO::speed, and AUTO::weaplist.
00883 { 00884 00885 AUTO *autopilot = *data; 00886 MECH *mech; 00887 command_node *temp; 00888 int i; 00889 00890 switch (selector) { 00891 case SPECIAL_ALLOC: 00892 00893 /* Allocate the command list */ 00894 autopilot->commands = dllist_create_list(); 00895 00896 /* Make sure certain things are set NULL */ 00897 autopilot->astar_path = NULL; 00898 autopilot->weaplist = NULL; 00899 00900 for(i = 0; i < AUTO_PROFILE_MAX_SIZE; i++) { 00901 autopilot->profile[i] = NULL; 00902 } 00903 00904 /* And some things not set null */ 00905 autopilot->speed = 100; 00906 00907 break; 00908 00909 case SPECIAL_FREE: 00910 00911 /* Make sure the AI is stopped */ 00912 auto_stop_pilot(autopilot); 00913 00914 /* Go through the list and remove any leftover nodes */ 00915 while (dllist_size(autopilot->commands)) { 00916 00917 /* Remove the first node on the list and get the data 00918 * from it */ 00919 temp = (command_node *) dllist_remove(autopilot->commands, 00920 dllist_head(autopilot-> 00921 commands)); 00922 00923 /* Destroy the command node */ 00924 auto_destroy_command_node(temp); 00925 00926 } 00927 00928 /* Destroy the list */ 00929 dllist_destroy_list(autopilot->commands); 00930 autopilot->commands = NULL; 00931 00932 /* Destroy any astar path list thats on the AI */ 00933 auto_destroy_astar_path(autopilot); 00934 00935 /* Destroy profile array */ 00936 for(i = 0; i < AUTO_PROFILE_MAX_SIZE; i++) { 00937 if(autopilot->profile[i]) { 00938 rb_destroy(autopilot->profile[i]); 00939 } 00940 autopilot->profile[i] = NULL; 00941 } 00942 00943 /* Destroy weaponlist */ 00944 auto_destroy_weaplist(autopilot); 00945 00946 /* Finally reset the AI value on its unit if 00947 * it needs to */ 00948 if((mech = getMech(autopilot->mymechnum))) { 00949 00950 /* Just incase another AI has taken over */ 00951 if(MechAuto(mech) == autopilot->mynum) { 00952 MechAuto(mech) = -1; 00953 } 00954 00955 } 00956 00957 break; 00958 00959 } 00960 00961 }
static int auto_pilot_on | ( | AUTO * | autopilot | ) | [static] |
Definition at line 608 of file autopilot_core.c.
References AUTOPILOT_AUTOGUN, AUTOPILOT_GUNZOMBIE, AUTOPILOT_PILZOMBIE, FIRST_AUTO_EVENT, LAST_AUTO_EVENT, and muxevent_count_type_data().
Referenced by auto_disengage(), and auto_engage().
00609 { 00610 00611 int i, j, count = 0; 00612 00613 for(i = FIRST_AUTO_EVENT; i <= LAST_AUTO_EVENT; i++) 00614 if((j = muxevent_count_type_data(i, (void *) autopilot))) 00615 count += j; 00616 00617 if(!count) { 00618 return autopilot->flags & (AUTOPILOT_AUTOGUN | AUTOPILOT_GUNZOMBIE | 00619 AUTOPILOT_PILZOMBIE); 00620 } 00621 00622 return count; 00623 00624 }
static command_node* auto_read_command_node | ( | FILE * | file | ) | [static] |
Definition at line 110 of file autopilot_core.c.
References acom, ACOM::ai_command_function, command_node_t::ai_command_function, command_node_t::argcount, command_node_t::args, auto_create_command_node(), CHELO, ACOM::command_enum, command_node_t::command_enum, MBUF_SIZE, name, ACOM::name, and strndup().
Referenced by auto_load_commands().
00111 { 00112 00113 unsigned char size; /* Number of Arguments to read */ 00114 char buf[MBUF_SIZE]; /* Buffer to store the strings */ 00115 int i; /* Counter */ 00116 unsigned short tmpb; /* Store the number of bytes read */ 00117 00118 command_node *temp_command_node; 00119 00120 /* Allocate a command node */ 00121 temp_command_node = auto_create_command_node(); 00122 00123 /* Zero the Buffer */ 00124 memset(buf, '\0', sizeof(buf)); 00125 00126 /* Read the Number of Arguments we're storing */ 00127 CHELO(&size, 1, sizeof(size), file); 00128 temp_command_node->argcount = size; 00129 00130 /* Loop through the arguments and store them */ 00131 for(i = 0; i <= size; i++) { 00132 00133 CHELO(&buf, 1, sizeof(buf), file); 00134 temp_command_node->args[i] = strndup(buf, MBUF_SIZE); 00135 00136 } 00137 00138 /* Make sure there is a command */ 00139 if(!temp_command_node->args[0]) { 00140 fprintf(stderr, "Error loading command node from file - " 00141 "no command found\n"); 00142 exit(1); 00143 } 00144 00145 /* Get the command_enum and the command_function */ 00146 for(i = 0; acom[i].name; i++) { 00147 if((!strncmp(temp_command_node->args[0], acom[i].name, 00148 strlen(temp_command_node->args[0]))) && 00149 (!strncmp(acom[i].name, temp_command_node->args[0], 00150 strlen(acom[i].name)))) 00151 break; 00152 } 00153 00154 if(!acom[i].name) { 00155 fprintf(stderr, "Error loading command node from file - " 00156 "Invalid Command\n"); 00157 exit(1); 00158 } 00159 00160 temp_command_node->command_enum = acom[i].command_enum; 00161 temp_command_node->ai_command_function = acom[i].ai_command_function; 00162 00163 return temp_command_node; 00164 00165 }
void auto_save_commands | ( | FILE * | file, | |
AUTO * | autopilot | |||
) |
Definition at line 172 of file autopilot_core.c.
References AI_COMMAND_DLLIST_END, AI_COMMAND_DLLIST_START, auto_write_command_node(), CHESA, AUTO::commands, dllist_get_node(), dllist_size(), and outbyte.
Referenced by save_autopilot_data().
00173 { 00174 00175 int i; /* Our Counter */ 00176 unsigned char tmpb; /* Our temp int we use when writing */ 00177 unsigned int size; /* The size of our command list */ 00178 00179 command_node *temp_command_node; 00180 00181 /* Print the Start Code */ 00182 outbyte(AI_COMMAND_DLLIST_START); 00183 00184 /* Write the size of our list */ 00185 size = dllist_size(autopilot->commands); 00186 CHESA(&size, sizeof(size), 1, file); 00187 00188 /* Check the size of the list, if there are commands save them */ 00189 if(dllist_size(autopilot->commands) > 0) { 00190 00191 /* Ok there stuff here so lets write it */ 00192 for(i = 1; i <= dllist_size(autopilot->commands); i++) { 00193 temp_command_node = 00194 (command_node *) dllist_get_node(autopilot->commands, i); 00195 auto_write_command_node(file, temp_command_node); 00196 } 00197 00198 } 00199 00200 /* Print the Stop Code */ 00201 outbyte(AI_COMMAND_DLLIST_END); 00202 00203 return; 00204 00205 }
Definition at line 645 of file autopilot_core.c.
References LBUF_SIZE, mech_set_channeltitle(), MechIDS(), MechType_Ref, and AUTO::mynum.
Referenced by auto_engage().
00646 { 00647 00648 char buf[LBUF_SIZE]; 00649 00650 snprintf(buf, LBUF_SIZE, "a=%s/%s", MechType_Ref(mech), MechIDS(mech, 1)); 00651 mech_set_channeltitle(autopilot->mynum, mech, buf); 00652 00653 }
static char* auto_show_command | ( | command_node * | node | ) | [static] |
Definition at line 304 of file autopilot_core.c.
References command_node_t::args, AUTOPILOT_MAX_ARGS, and MBUF_SIZE.
Referenced by auto_addcommand(), and auto_listcommands().
00305 { 00306 00307 static char buf[MBUF_SIZE]; 00308 int i; 00309 00310 snprintf(buf, MBUF_SIZE, "%-10s", node->args[0]); 00311 00312 /* Loop through the args and print the commands */ 00313 for(i = 1; i < AUTOPILOT_MAX_ARGS; i++) 00314 if(node->args[i]) { 00315 strncat(buf, " ", MBUF_SIZE); 00316 strncat(buf, node->args[i], MBUF_SIZE); 00317 } 00318 00319 return buf; 00320 00321 }
void auto_stop_pilot | ( | AUTO * | autopilot | ) |
Definition at line 629 of file autopilot_core.c.
References AUTOPILOT_AUTOGUN, AUTOPILOT_GUNZOMBIE, AUTOPILOT_PILZOMBIE, FIRST_AUTO_EVENT, AUTO::flags, LAST_AUTO_EVENT, and muxevent_remove_type_data().
Referenced by auto_disengage(), auto_newautopilot(), and newfreemech().
00630 { 00631 00632 int i; 00633 00634 autopilot->flags &= ~(AUTOPILOT_AUTOGUN | AUTOPILOT_GUNZOMBIE 00635 | AUTOPILOT_PILZOMBIE); 00636 00637 for(i = FIRST_AUTO_EVENT; i <= LAST_AUTO_EVENT; i++) 00638 muxevent_remove_type_data(i, (void *) autopilot); 00639 00640 }
int auto_valid_progline | ( | AUTO * | a, | |
int | p | |||
) |
Definition at line 288 of file autopilot_core.c.
References acom, ACOM::argcount, and AUTO::commands.
Referenced by auto_com_event(), and auto_jump().
00289 { 00290 int i; 00291 #if 0 00292 for(i = 0; i < a->first_free; i += (acom[a->commands[i]].argcount + 1)) 00293 if(i == p) 00294 return 1; 00295 #endif 00296 return 0; 00297 }
static void auto_write_command_node | ( | FILE * | file, | |
command_node * | node | |||
) | [static] |
Definition at line 81 of file autopilot_core.c.
References command_node_t::argcount, command_node_t::args, CHESA, and MBUF_SIZE.
Referenced by auto_save_commands().
00082 { 00083 00084 unsigned char size; /* Number of Arguments to save */ 00085 char buf[MBUF_SIZE]; /* Buffer to write the strings */ 00086 int i; /* Counter */ 00087 unsigned short tmpb; /* Store the number of bytes written */ 00088 00089 /* Zero the Buffer */ 00090 memset(buf, '\0', sizeof(buf)); 00091 00092 /* Write the Number of Arguments we're storing */ 00093 size = node->argcount; 00094 CHESA(&size, 1, sizeof(size), file); 00095 00096 /* Loop through the args and write them */ 00097 for(i = 0; i <= size; i++) { 00098 strncpy(buf, node->args[i], MBUF_SIZE); 00099 CHESA(&buf, 1, sizeof(buf), file); 00100 } 00101 00102 return; 00103 00104 }
Definition at line 40 of file autopilot_commands.c.
Referenced by auto_addcommand(), auto_read_command_node(), and auto_valid_progline().
unsigned int global_tick |
char* muxevent_names[] |
Referenced by auto_eventstats(), and debug_EventTypes().