#GENERAL
*name = add("spawn_cave", num_to_str(avar("spawn_cave_id")));
*faction = "spawn";

*rad        = 6.0;
*mass       = 50000000.0;
*elasticity = 0.3;
*drag       = 0.5;
*friction   = 4.0;
*hardness   = 1.0;

*model = "npc_spawn-o-pod_01";
*model_col = colorRGB(0.2, 0.1, 0.1);
*model_rot = 0.0;
*model_scale = 6.0;
*bleed_rate = 3.0;
*leak_decal_vec = {"decals/big_blood_01.tga"};
*dam_part_vec = {"blood_01"};

#ATTRIBUTE "attract";
#BASE      20.0;
#ATTRIBUTE "leak";
#BASE      0.0;
#ATTRIBUTE "speed";
#BASE      0.0;
#ATTRIBUTE "power";
#BASE      0.0;
#ATTRIBUTE "health";
#BASE      2500.0;
#ATTRIBUTE "res";
#BASE      1.0;
#ATTRIBUTE "rot_speed";
#BASE      30.0;
#ATTRIBUTE "exp";
#BASE      0.0;
#ATTRIBUTE "spawn_id";
#BASE      avar("spawn_cave_id");
#ATTRIBUTE "spawn_init";
#BASE      avar("spawn_cave_init");
#ATTRIBUTE "spawn_wait";
#BASE      avar("spawn_cave_wait");
#ATTRIBUTE "spawn_release";
#BASE      avar("spawn_cave_release");
#ATTRIBUTE "spawn_r_wait";
#BASE      avar("spawn_cave_r_wait");
#ATTRIBUTE "spawned";
#BASE      0.0;
#ATTRIBUTE "spawn_max";
#BASE      avar("spawn_cave_max");
#ATTRIBUTE "spawn_total";
#BASE      0.0;

#ON_DAMAGE

  sound_play( add("monsters/spit_0", num_to_str(rand(1, 4.99)), ".wav"), this_x(), this_y(), 1 );

#ON_DEATH

  explosion_make(this_x(), this_y(), 8.0, 1.0, 0);
  sound_play("city/explode3.wav", this_x(), this_y(), 1);
  script_load(add("forest/spawn_cave_dead", num_to_str(this_get_attribute("spawn_id"))));

#CONTROL "script";
##BEGIN

#SEQUENCE "base";
# wait (.001);
# this_item_make( "banana_04", 1 );
  this_item_make( "coin_03", 1 );
# seq_jump("start");

#SEQUENCE "start";
# avar(add("monster_type", num_to_str(this_get_attribute("spawn_id"))), avar("monster_type"));
  char_make(avar("monster_type"), rand(500, 550), rand(500, 550), avar(add("monster_type", num_to_str(this_get_attribute("spawn_id")))), 1 );
# avar(add("monster_typeb", num_to_str(this_get_attribute("spawn_id"))), avar("monster_typeb"));
  char_make(avar("monster_typeb"), rand(500, 550), rand(500, 550), avar(add("monster_typeb", num_to_str(this_get_attribute("spawn_id")))), 1 );
# seq_jump("spawn");

#SEQUENCE "spawn";
# var func = nop;
  func = if(or(geq(this_get_attribute("spawned"), this_get_attribute("spawn_init")), eq(avar("spawn_off"), 1), geq(this_get_attribute("spawn_total"), this_get_attribute("spawn_max"))), seq_jump, nop);
  func("cycle");
// Fade into the spawning anim.
# animate( "prep_spawn", 1, 1, 0.2 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.5 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.3 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 2.4 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 3.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 4.0 );
  wait( 0.05, 1 );
# sound_play("monsters/raise.wav", this_x(), this_y(), this_z() );
  animate( "prep_spawn", 1, 1, 5.5 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 10, 1, 8.0 );
  wait( 0.05, 1 );

// Do the spawning anim.
# animate( "spawn", 1, 1, 100.0 );
  wait( 0.92, 1 );
# char_clone(avar(add("monster_type", num_to_str(this_get_attribute("spawn_id")))), add(this_x(), rand(-4,4)), add(this_y(), rand(4,8)));
  wait( 0.97, 1 );

// Fade out the spawning anim.
# animate( "prep_spawn", 1, 1, 5.5 );
  animate( "spawn", 1, 1, 0.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 4.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 3.0 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 2.4 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 1.3 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.9 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.5 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.2 );
  wait( 0.05, 1 );
# animate( "prep_spawn", 1, 1, 0.0 );
  wait( 0.05, 1 );

// Wait for good measure.
//# wait( 4 );
# this_set_attribute("spawned", add(this_get_attribute("spawned"), 1));
  this_set_attribute("spawn_total", add(this_get_attribute("spawn_total"), 1));
  avar("total_spawn", add(avar("total_spawn"), 1));
# wait( 0.01 );

#SEQUENCE "cycle";
# wait( this_get_attribute("spawn_wait") );
# this_set_attribute("spawned", 0);
# seq_jump("spawn");

##END