begincreaturescript;
variables;
short c, d, i, target;
short last_abil_time,num_abils;
short r1;
short a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11;
short current_abil;
body;
beginstate INIT_STATE;
last_abil_time = get_current_tick();
num_abils = 0;
if(((get_memory_cell(4)) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 2) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 4) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 8) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 16) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 32) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 64) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 128) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 256) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(4) / 512) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5)) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 2) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 4) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 8) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 16) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 32) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 64) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 128) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 256) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(5) / 512) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6)) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 2) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 4) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 8) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 16) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 32) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 64) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 128) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 256) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(6) / 512) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7)) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 2) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 4) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 8) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 16) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 32) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 64) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 128) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 256) % 2) == 1)
num_abils = num_abils + 1;
if(((get_memory_cell(7) / 512) % 2) == 1)
num_abils = num_abils + 1;
if(num_abils > 12){
print_str_color("abilswitch error: Too many abilities; setting to 0.",1);
num_abils = 0;
}
i = 0;
target = 0;
d = 1;
while(i < 40){
d = d * 2;
c = (i / 10) + 4;
if(i == 10 || i==20 || i==30)
d = 1;
if(((get_memory_cell(c) / d) % 2) == 1){
if(target == 0)
a0 = i;
else if(target == 1)
a1 = i;
else if(target == 2)
a2 = i;
else if(target == 3)
a3 = i;
else if(target == 4)
a4 = i;
else if(target == 5)
a5 = i;
else if(target == 6)
a6 = i;
else if(target == 7)
a7 = i;
else if(target == 8)
a8 = i;
else if(target == 9)
a9 = i;
else if(target == 10)
a10 = i;
else if(target == 11)
a11 = i;
target = target + 1;
}
i = i + 1;
}
if (get_memory_cell(0) == 2)
set_mobility(ME,0);
current_abil = 0;
break;
beginstate DEAD_STATE;
if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
set_flag(get_memory_cell(1),get_memory_cell(2),1);
break;
beginstate START_STATE;
if (target_ok()) {
if (dist_to_char(get_target()) <= 16)
set_state(3);
else set_target(ME,-1);
}
if (select_target(ME,8,0)) {
do_attack();
set_state(3);
}
if (who_hit_me() >= 0) {
set_target(ME,who_hit_me());
do_attack();
set_state(3);
}
if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {
if (get_ran(1,1,100) < 40)
return_to_start(ME,1);
}
else if (get_memory_cell(0) == 0) {
fidget(ME,25);
}
if (am_i_doing_action() == FALSE)
end_combat_turn();
break;
beginstate 3;
if (target_ok() == FALSE)
set_state(START_STATE);
if ((tick_difference(last_abil_time,get_current_tick()) >= 1) &&
((get_memory_cell(4) > 0) || (get_memory_cell(5) > 0) || (get_memory_cell(6) > 0)
|| (get_memory_cell(7) > 0)) && (can_see_char(1000))) {
r1 = get_ran(1,0,num_abils - 1);
if(r1 == 0){
set_special_ability(ME,a0);
current_abil = a0;
}
else if(r1 == 1){
set_special_ability(ME,a1);
current_abil = a1;
}
else if(r1 == 2){
set_special_ability(ME,a2);
current_abil = a2;
}
else if(r1 == 3){
set_special_ability(ME,a3);
current_abil = a3;
}
else if(r1 == 4){
set_special_ability(ME,a4);
current_abil = a4;
}
else if(r1 == 5){
set_special_ability(ME,a5);
current_abil = a5;
}
else if(r1 == 6){
set_special_ability(ME,a6);
current_abil = a6;
}
else if(r1 == 7){
set_special_ability(ME,a7);
current_abil = a7;
}
else if(r1 == 8){
set_special_ability(ME,a8);
current_abil = a8;
}
else if(r1 == 9){
set_special_ability(ME,a9);
current_abil = a9;
}
else if(r1 == 10){
set_special_ability(ME,a10);
current_abil = a10;
}
else if(r1 == 11){
set_special_ability(ME,a11);
current_abil = a11;
}
last_abil_time = get_current_tick();
}
if(current_abil > 0)
do_attack_tactic(1);
else
do_attack();
break;
beginstate TALKING_STATE;
if (get_memory_cell(3) == 0) {
print_str("Talking: It doesn't respond.");
end();
}
begin_talk_mode(get_memory_cell(3));
break