The Dink Network

Re: Blue Knight Ally

October 2nd 2007, 06:33 AM
wizardb.gif
Endy
Peasant He/Him United States
 
After seeing the post about having a useful ally Dink I managed to come up with this script for a blue knight ally that'll attack enemies based on proximity, cool to watch as the knight selectivly hunts down his enemies. Should be useful for giving allies additional smarts. Could even create a whole battle by employing several at once.

Anyways here's the code, still kinda rough... Any suggestions would be appreciated.

//Blue Knight Ally
//hunts down enemies based on proximity
//returns to standby mode afterwards

void main( void )
{
int &distA = 600;
int &mcounter;
int &sight;
int &enmy
sp_brain(&current_sprite, 9);
sp_speed(&current_sprite, 2);
sp_range(&current_sprite, 45);
sp_distance(&current_sprite, 55);
sp_timing(&current_sprite, 33);
sp_base_walk(&current_sprite, 280);
// sp_base_death(&current_sprite, xxx);
// This enemy just uses base_walk+5 as it's death frame.
sp_defense(&current_sprite, 4);
sp_strength(&current_sprite, 10);
sp_hitpoints(&current_sprite, 90);
set_smooth_follow(1);
goto sight;
}

void sight ( void )
{
sight:
int &sprite = 0;
//gotta compare 2 distances at a time higher distance loses, then goes on to next one

loop:

&sprite = get_next_sprite_with_this_brain(9, &current_sprite, &sprite);

if (&sprite > 0)

{

//others stuff
int &dx = sp_x(&sprite, -1 );
int &dy = sp_y(&sprite, -1 );
//self info
int &x = sp_x(&current_sprite, -1);
int &y = sp_y(&current_sprite, -1);
&x -= &dx;
&y -= &dy;
&x * &x;
&y * &y;
&y += &x;
int &dist = math_sqrt(&y);

//below finds the cloest enemy
if (&dist <= &distA)
{
&distA = &dist;
&enmy = &sprite;
}

&sight = get_rand_sprite_with_this_brain(9, &current_sprite);

if (&enmy == 0)
{
sp_target(&current_sprite, &sight);
}

//say(" &distA &enmy &sprite ", &sprite);

//Increment &sprite so we start with the next sprite

&sprite += 1;

goto loop;

}
else
{
//very improtant to reset
//my knight was having spasms without it
int &distA = 600;
}

&sight = get_rand_sprite_with_this_brain(9, &current_sprite);

//goes to dink if no monsters; otherwise attacks random monster
if (&sight != 0)
{
sp_base_attack(&current_sprite, 730);
sp_target(&current_sprite, &enmy);
//say(" &distA &enmy &sprite ", &current_sprite);
}

if (&sight == 0)
{
sp_base_attack(&current_sprite, -1);
sp_target(&current_sprite, 1);

//Dinks stuff
int &dx = sp_x(1, -1 );
int &dy = sp_y(1, -1 );
//self info
int &x = sp_x(&current_sprite, -1);
int &y = sp_y(&current_sprite, -1);
//pythagorian's theorm, eternally handy
&x -= &dx;
&y -= &dy;
&x * &x;
&y * &y;
&y += &x;
int &dist = math_sqrt(&y);

if (&dist <= 65)
{
sp_brain(&current_sprite, 16);
}
if (&dist >= 80)
{
sp_brain(&current_sprite, 9);
}

}

}
wait(600);
goto sight;
}

void attack( void )
{
playsound(36, 22050,0,&current_sprite, 0);
&mcounter = random(1000,0);
sp_attack_wait(&current_sprite, &mcounter);
goto sight;
}

void hit( void )`
{
playsound(28, 22050,0,&current_sprite, 0);
if (&enemy_sprite > 1)
{
sp_target(&current_sprite, &enemy_sprite);
}
goto sight;
}
}

void die( void )
{
&save_x = sp_x(&current_sprite, -1);
&save_y = sp_y(&current_sprite, -1);
external("emake","large");

int &hold = sp_editor_num(&current_sprite);
if (&hold != 0)
editor_type(&hold, 6);
}
October 2nd 2007, 07:43 PM
sob_scorpy.gif
DinkDude95
Peasant He/Him Australia
The guy with the cute D-Mod. 
Looks good. I didn't read through it all, perhaps I'll do it later. Otherwise, keep up the good work. I'm lovin' it!