コード例 #1
0
ファイル: cloud.c プロジェクト: evktalo/lacewing
void place_burstlet_burst(int x, int y, int xs, int ys, int burstlets, int min_timeout, int random_timeout, int burst, int random_burst, int pretravel, int colours [5])
{

int i, xs2, ys2, x2, y2;

  for (i = 0; i < burstlets; i ++)
  {
   xs2 = burst + grand(random_burst);
   ys2 = burst + grand(random_burst);
   if (grand(2) == 0)
    xs2 *= -1;
   if (grand(2) == 0)
    ys2 *= -1;
   xs2 += xs;
   ys2 += ys;
   x2 = x + xs2 * pretravel; // or it will just be masked by the main
   y2 = y + ys2 * pretravel; //  explosion

   create_cloud(CLOUD_BURSTLET,
    x2, y2, 0,0, xs2, ys2,
    min_timeout + random_timeout,1,0, 0, 0, 0, colours);
  }


}
コード例 #2
0
gVector3f gDistribution::gSphere()
{
    gnum th = grand() * M_PI * 2.0;
    gnum ph = grand() * M_PI;
    gnum ra = 0.5 * grand();
    return gVector3f(ra * gcos(th) * gsin(ph) + 0.5, ra * gsin(th) * gsin(ph) + 0.5, ra * gcos(ph) + 0.5);
}
コード例 #3
0
ファイル: actor.c プロジェクト: evktalo/overgod
void actor_explodes(int a)
{

 int passing_colours [5];

 passing_colours[0] = TRANS_DRED;
 passing_colours[1] = TRANS_LRED;
 passing_colours[2] = TRANS_YELLOW;

 place_explosion(actor[a].x, actor[a].y, 0,0,//actor[a].x_speed, actor[a].y_speed,
  1500 + crandom(250), passing_colours);
 place_burstlet_burst(actor[a].x, actor[a].y, 0, 0, 4 + grand(3), 2, 6, 1000, 1500,
  4, passing_colours);

 int i;

 if (actor[a].sidekicks != 0)
 {
  for (i = 0; i < actor[a].sidekicks; i ++)
  {
   place_explosion(actor[a].sidekick_x [i], actor[a].sidekick_y [i], 0,0,
    500 + crandom(250), passing_colours);
   place_burstlet_burst(actor[a].sidekick_x [i], actor[a].sidekick_y [i], 0, 0, 2 + grand(3), 2, 6, 1000, 1500,
    4, passing_colours);
  }
  actor[a].sidekicks = 0;
 }

 kill_drive_sounds();
 play_wavf(NWAV_BLAST, 500 + grand(200));

}
コード例 #4
0
ファイル: actor.c プロジェクト: evktalo/overgod
void actor_destroyed(int a, int source)
{

 actor[a].in_play = 0;
 actor[a].spawn_delay = 50;
// actor[a].lock = -1;
// actor[a].turret_lock = -1;

// actor[a].x = grand(arena.max_x - 100000) + 50000;
// actor[a].y = grand(arena.max_y - 100000) + 50000;
 actor[a].next_spawn_x = grand(arena.max_x - 100000) + 50000;
 actor[a].next_spawn_y = grand(arena.max_y - 100000) + 50000;


 int e;

 for (e = 0; e < NO_ENEMIES; e ++)
 {
  if (enemy[e].type == ENEMY_NONE)
   continue;
  if (enemy[e].attacking == a)
   enemy[e].attacking = ATTACK_NONE;
 }

 if (game.type == GAME_DUEL)
 {
  score_duel_kill(a, source);
  return;
 }

 if (game.type == GAME_TIME_ATTACK || game.type == GAME_TIME_ATTACK_COOP)
 {
  arena.time_left -= 33.333 * 30;
  if (arena.time_left < 1)
   arena.time_left = 1;
  return;
 }

  
 if (game.ships_left == 0)
 {
  if (game.users == 1)
   game_is_over();
    else
    {
     if (actor[0].in_play == 0 && actor[1].in_play == 0)
      game_is_over();
    }
 }
 
}
コード例 #5
0
ファイル: actor.c プロジェクト: evktalo/overgod
int hurt_actor(int a, int source, int hurty)
{

 if (actor[a].in_play == 0)
  return 0;
  
//  hurty *= 2;
  
 if (game.type == GAME_DUEL && game.duel_leader_handicap > 0)
 {
  if (player[actor[a].controller].duel_score > player[actor[a].controller == 0].duel_score)
  {
   hurty *= 10 + (player[actor[a].controller].duel_score - player[actor[a].controller == 0].duel_score) * game.duel_leader_handicap;
   hurty /= 10;
  }
 }

 if (actor[a].ability [ABILITY_DEFENCE] [SYMBOL_CIRCLE] > 0
     && actor[a].shield > 0)
 {
  if (actor[a].shield >= 20)
   play_wavf(NWAV_SHIELD, 400 + actor[a].shield * 2);
  if (hurty > actor[a].shield)
  {
   hurty -= actor[a].shield;
   actor[a].shield = 0;
   actor[a].shield_pulse = 2 + actor[a].ability [ABILITY_DEFENCE] [SYMBOL_CIRCLE];
  }
   else
   {
//    play_wavf(NWAV_SHIELD, 400 + actor[a].shield * 2);
    actor[a].shield -= hurty;
    actor[a].shield_pulse = 5 + actor[a].ability [ABILITY_DEFENCE] [SYMBOL_CIRCLE];
    return 0;
   }
//  play_soundf(WAV_SHIELD, 1000);
 }

// return 0;
// shields go here...

// int passing_colours [5];

 actor[a].hurt_pulse = 4;

 if (hurty >= actor[a].armour)
 {
  actor[a].armour = 0;
  actor_explodes(a);
  actor_destroyed(a, source);
  return 0;
 }

 play_wavf(NWAV_BUMP2, 900 + grand(300));

 actor[a].armour -= hurty;
 return 1;

}
コード例 #6
0
ファイル: TREE.CPP プロジェクト: ganeshpaib/CollegePrograms
void main()
{
int opt,item ;
tree_ptr temp,para;
char search;
do
{
	clrscr();
	printf("\npress 1 for maketree");
	printf("\nPress 2 for inorder ");
	printf("\npress 3 for preorder");
	printf("\npress 4 for postorder");
	printf("\npress 5 for level order traversal:");
	printf("\npress 6 for copying binary tree");
	printf("\npress 7 for finding parent of given node");
	printf("\npress 8 for finding deapth of tree");
	printf("\npress 9 for find ancestr of given element");
	printf("\npress 10 for find All The leaf node of the tree");
	printf("\npress 99 for exit");
	printf("\nenter the option");
	scanf("%d",&opt);
	switch(opt)
	{
		case 1:printf("\nenter the item to be inserted:");
		       flushall();
		       scanf("%c",&item);
		       root=insert(item,root) ;
		       break;
		case 2:printf("\nThe inorder expersion is ...");
				inorder(root);
				break;
		case 3:printf("\nThe preorder expersion is...");
				preorder(root);
				break;
		case 4:printf("\nthe postorder expersion is ..");
				postorder(root);
				break;
		case 5:printf("\nThe level order traversal is ..");
				level_order(root);
				break;
		case 6:printf("\nThe copied binary tree is inorder expersion is ..\n");
		       temp=copy(root);
		       inorder(temp);
		       break;
		case 7: parent(root);
			break;
		case 8:depth(dir,ctr);
		       break;
		case 9:grand(root);
		       break;
		case 10:printf("\n");
		       count(root);
		       printf("\nThe no of leaf node  are %d",c);
		       c=0;
		       break;
	}
getch();
}while(opt!=99);
}
コード例 #7
0
ファイル: cloud.c プロジェクト: evktalo/lacewing
void place_speck_burst(int x, int y, int xs, int ys, int specks, int min_timeout, int random_timeout, int scatter, int colours [5])
{

  int i;

  for (i = 0; i < specks; i ++)
  {
   create_cloud(CLOUD_SPECK,
    x,
    y,
    0, 0,
    xs + grand(scatter * 2 + 1) - scatter,
    ys + grand(scatter * 2 + 1) - scatter,
    min_timeout + grand(random_timeout), 1,0,0, 0, 0, colours);
  }

}
コード例 #8
0
ファイル: actor.c プロジェクト: evktalo/overgod
void actor_new_level(int a)
{

 actor[a].in_play = 1;
// actor[a].x = arena.max_x / 2; //grand(arena.max_x - 100000) + 50000;
// actor[a].y = arena.max_y / 2; //grand(arena.max_y - 100000) + 50000;
 actor[a].x = grand(arena.max_x - 100000) + 50000;
 actor[a].y = grand(arena.max_y - 100000) + 50000;
 actor[a].next_spawn_x = actor[a].x;
 actor[a].next_spawn_y = actor[a].y;

// actor[a].sidekicks = 0;
// if (actor[a].upgraded_system [UPG_SIDEKICK] > 0)
//  upgrade_sidekicks(a);
 
 reset_actor(a);
 
}
コード例 #9
0
int main(int argc,char** argv) {
	int i,j,number_jobs,min_lim,max_lim,n;
	if(argc != 4) {
		printf("Command pattern: command \"NUMBER_OF_JOBS\" \"MIN_LIMIT\" \"MAX_LIMIT\"\n");
		return 0;
	}
	srand((unsigned) time(NULL));
	number_jobs = atoi(argv[1]);
	min_lim = atoi(argv[2]);
	max_lim = atoi(argv[3]) + 1;
	for(i=0;i<number_jobs;i++) {
		for(j=0;j<2;j++) {
			n = grand(min_lim,max_lim);
			printf("%d ",n);
		}
		n = grand(min_lim,max_lim);
		printf("%d\n",n);
	}
	return 0;
}
コード例 #10
0
ファイル: menu.c プロジェクト: evktalo/butterfly
void init_menu_circles(void)
{

 int i;

 for (i = 0; i < MENU_CIRCLES; i ++)
 {
   menu_circle_size [i] = 0;

 }

 new_menu_circle = 100 + grand(200);

}
コード例 #11
0
ファイル: cloud.c プロジェクト: evktalo/lacewing
void place_line_burst(int x, int y, int xs, int ys, int specks, int min_timeout, int random_timeout, int burst, int random_burst, int colours [5])
{

  int i, angle, xsp, ysp, burst_speed;

  for (i = 0; i < specks; i ++)
  {
   angle = grand(ANGLE_FULL);
   burst_speed = burst + grand(burst);
   xsp = xs + cos(angle_to_radians(angle)) * burst_speed;
   ysp = ys + sin(angle_to_radians(angle)) * burst_speed;
   x += xsp;
   y += ysp;
   create_cloud(CLOUD_SHRINKING_LINE,
    x,
    y,
    0, 0,
    xsp,
    ysp,
    (min_timeout + grand(random_timeout)) * 10, 10 + grand(6),0,angle, 0, 0, colours);
  }

}
コード例 #12
0
ファイル: g_proc.c プロジェクト: Abstrusle/LCTourn
static void explosion_fragments(al_fixed x, al_fixed y, al_fixed x_speed, al_fixed y_speed, int fragments, int player_index)
{

	int i;
//	struct cloud_struct* cl;
	al_fixed base_fragment_angle = grand(AFX_ANGLE_1);
	int fragment_speed_int;
	al_fixed fragment_speed;
	cart fragment_position;
	cart fragment_vel;
	al_fixed fragment_angle;
	int explode_time;

	for (i = 0; i < fragments; i ++)
	{
  fragment_angle = base_fragment_angle + (AFX_ANGLE_1 * i / fragments) + grand(AFX_ANGLE_8);
  fragment_speed_int = 2 + grand(12);
  fragment_speed = al_itofix(fragment_speed_int);
  fragment_vel.x = fixed_xpart(fragment_angle, fragment_speed);
  fragment_vel.y = fixed_ypart(fragment_angle, fragment_speed);
//  fragment_vel.x = x_speed + fixed_xpart(fragment_angle, fragment_speed);
//  fragment_vel.y = y_speed + fixed_ypart(fragment_angle, fragment_speed);
  fragment_position.x = x + fragment_vel.x * 5;
  fragment_position.y = y + fragment_vel.y * 5;
  explode_time = fragment_speed_int * 5;// + //grand(20) + fragment_speed_int * 4;


  if (!create_fragment(fragment_position, fragment_vel,
																							6 + grand(10), // size
																							explode_time, // explosion_time
																							explode_time + 32, // lifetime
																							player_index)) // colour
			return; // fragment array full.
	}

}
コード例 #13
0
ファイル: patricia.c プロジェクト: andyjsharp/juise
patnode *
patricia_lookup_random (patroot *root)
{
    patnode *current = root->first;
    u_short lasttest = PAT_NOBIT;
  
    if (!current) {
	return(NULL);
    }

    /*
     * Waltz down the tree.  Stop when the bits appear to go backwards.
     */
    do {
	lasttest = current->bit;
	if (grand(2)) {
	    current = current->right;
	} else {
	    current = current->left;
	}
    } while (current->bit > lasttest);

    return(current);
}
コード例 #14
0
ファイル: actor.c プロジェクト: evktalo/overgod
void actor_sidekicks(int a)
{

 int i, xcos2, ysin2;

 int passing_colours [5];

 if (actor[a].sidekick_recycle > 0)
  actor[a].sidekick_recycle --;

 int xcos = cos(angle_to_radians(actor[a].angle)) * GRAIN;
 int ysin = sin(angle_to_radians(actor[a].angle)) * GRAIN;
// int xcos2;// = cos(angle_to_radians(actor[a].angle)) * GRAIN;
// int ysin2;// = sin(angle_to_radians(actor[a].angle)) * GRAIN;

// if (actor[a].sidekicks >= 2)
// {
//  xcos2 = cos(angle_to_radians(actor[a].angle)) * GRAIN;
//  ysin2 = sin(angle_to_radians(actor[a].angle)) * GRAIN;
// }
 
 int target_x, target_y;
 float speed_mult;
 int accel = 0;

 for (i = 0; i < actor[a].sidekicks; i ++)
 {
  switch(i)
  {
   case 0:
    target_x = actor[a].x + (cos(angle_to_radians(actor[a].angle - ANGLE_1_EIGHTH)) * GRAIN * 40);
    target_y = actor[a].y + (sin(angle_to_radians(actor[a].angle - ANGLE_1_EIGHTH)) * GRAIN * 40);
    accel = 22;
    passing_colours [0] = COLOUR_YELLOW8;
    passing_colours [1] = COLOUR_GREEN8;
    passing_colours [2] = COLOUR_GREEN6;
    passing_colours [3] = COLOUR_GREEN4;
    passing_colours [4] = COLOUR_GREEN2;
    break;
   case 1:
    target_x = actor[a].x + (cos(angle_to_radians(actor[a].angle - ANGLE_QUARTER - ANGLE_1_EIGHTH)) * GRAIN * 40);
    target_y = actor[a].y + (sin(angle_to_radians(actor[a].angle - ANGLE_QUARTER - ANGLE_1_EIGHTH)) * GRAIN * 40);
//    target_x = actor[a].x - xcos * 20;
//    target_y = actor[a].y - ysin * 20;
    accel = 22;
    break;
   case 2:
    target_x = actor[a].x + xcos * 40;
    target_y = actor[a].y + ysin * 40;
    accel = 12;
    passing_colours [0] = COLOUR_YELLOW8;
    passing_colours [1] = COLOUR_YELLOW6;
    passing_colours [2] = COLOUR_YELLOW4;
    passing_colours [3] = COLOUR_YELLOW3;
    passing_colours [4] = COLOUR_YELLOW2;
    break;
   case 3:
    target_x = actor[a].x - xcos * 40;
    target_y = actor[a].y - ysin * 40;
    accel = 12;
    break;
  }

  speed_mult = hypot(actor[a].sidekick_y [i] - target_y, actor[a].sidekick_x [i] - target_x) / 600;

  if (speed_mult > 200)
   speed_mult = 200;
   
  speed_mult *= accel;
  speed_mult /= 10;
/*  if (speed_mult < 20 && abs(actor[a].sidekick_x_speed [i]) + abs(actor[a].sidekick_y_speed [i]) < 2000)
  {
   actor[a].sidekick_angle [i] = turn_towards_angle(actor[a].sidekick_angle [i], actor[a].angle + ANGLE_QUARTER, 8);
   actor[a].sidekick_x_speed [i] = 0;
   actor[a].sidekick_y_speed [i] = 0;
  }
   else*/
   {
    actor[a].sidekick_angle [i] = turn_towards_xy(actor[a].sidekick_x [i], actor[a].sidekick_y [i], target_x, target_y, actor[a].sidekick_angle [i], 16);

//  actor[a].sidekick_x_speed [i] = cos(angle_to_radians(actor[a].sidekick_angle [i])) * speed_mult;
//  actor[a].sidekick_y_speed [i] = sin(angle_to_radians(actor[a].sidekick_angle [i])) * speed_mult;

//  actor[a].sidekick_x_speed [i] += cos(angle_to_radians(actor[a].sidekick_angle [i])) * speed_mult;
//  actor[a].sidekick_y_speed [i] += sin(angle_to_radians(actor[a].sidekick_angle [i])) * speed_mult;
    xcos2 = cos(angle_to_radians(actor[a].sidekick_angle [i])) * speed_mult;
    ysin2 = sin(angle_to_radians(actor[a].sidekick_angle [i])) * speed_mult;
    actor[a].sidekick_x_speed [i] += xcos2;
    actor[a].sidekick_y_speed [i] += ysin2;
   }

  actor[a].sidekick_x_speed [i] *= 0.97;
  actor[a].sidekick_y_speed [i] *= 0.97;

  actor[a].sidekick_x [i] += actor[a].sidekick_x_speed [i];
  actor[a].sidekick_y [i] += actor[a].sidekick_y_speed [i];

  if (grand(12) == 0 && abs(actor[a].sidekick_x_speed [i]) + abs(actor[a].sidekick_y_speed [i]) > 1000)
  {
   create_cloud(CLOUD_SPECK,
    actor[a].sidekick_x [i] - xcos2 * 37,
    actor[a].sidekick_y [i] - ysin2 * 37,
    0, 0,
    actor[a].sidekick_x_speed [i] - (xcos2 * 10) + (100 - grand(51)),
    actor[a].sidekick_y_speed [i] - (ysin2 * 10) + (100 - grand(51)),
    10 + grand(11),1,0, 0, 0, 0, passing_colours);
  }
  

 }


}
コード例 #15
0
ファイル: actor.c プロジェクト: evktalo/overgod
int detect_collision_actor_enemies(int a)
{
 if (actor[a].grace_period > 0 || actor[a].in_play == 0)
  return -1;

 int x2 = actor[a].x - actor[a].x_speed;
 int y2 = actor[a].y - actor[a].y_speed;
 int i;

 int angle1, angle2, angle3;
 int total_speed;
 int difference;
 int collision_velocity = 0;
 int hurty = 0;
 int passing_colours [5];

 int xs2, ys2;

 for (i = 0; i < NO_ENEMIES; i ++)
 {
  if (enemy[i].type == ENEMY_NONE)
   continue;
  if (enemy[i].radius == 0)
  // enemy has no collision radius - dead wanderer etc
   continue;

  if (actor[a].just_collided > 0 && enemy[i].just_collided > 0)
   continue;

  if (hypot(actor[a].x - enemy[i].x, actor[a].y - enemy[i].y) <= actor[a].radius + enemy[i].radius
      || hypot(x2 - enemy[i].x, y2 - enemy[i].y) <= actor[a].radius + enemy[i].radius)
  {
/*   if (actor[a].x_speed == 0)
    tangent = 1000;
     else
      tangent = tan(actor[a].y_speed / actor[a].x_speed);
*/
   switch(enemy[i].type)
   {
/*    case ENEMY_SWERVER:
    case ENEMY_SWERVER2:
    case ENEMY_SWERVER3:
    case ENEMY_BOUNCER:
    case ENEMY_BOUNCER2:
    case ENEMY_BOUNCER3:
    case ENEMY_BOUNCER4:
    case ENEMY_BOUNCER5:
     hurt_enemy(i, 99999, -1, 1);
     return -1;*/

   }


// Really dodgy collision physics...

   collision_velocity = hypot(abs(actor[a].x_speed - enemy[i].x_speed), abs(actor[a].y_speed - enemy[i].y_speed));

// First calculate actor's post-collision velocity:
   angle1 = radians_to_angle(atan2(actor[a].y_speed, actor[a].x_speed));
   angle2 = radians_to_angle(atan2(actor[a].y - enemy[i].y, actor[a].x - enemy[i].x));

   total_speed = hypot(actor[a].y_speed, actor[a].x_speed);

   angle1 += ANGLE_HALF;
   if (angle2 > ANGLE_FULL)
    angle2 -= ANGLE_FULL;

   angle2 += ANGLE_QUARTER;
   if (angle2 > ANGLE_FULL)
    angle2 -= ANGLE_FULL;

/*   if (angle1 < angle2)
   {
    difference = angle2 - angle1;
   }
    else
    {
     difference = angle1 - angle2;
    }

   angle3 = angle1 - difference;*/

   difference = angle2 - angle1;
   angle3 = angle2 - difference; // or +?

   xs2 = actor[a].x_speed;
   ys2 = actor[a].y_speed;

   actor[a].x_speed = cos(angle_to_radians(angle3)) * total_speed;
   actor[a].y_speed = sin(angle_to_radians(angle3)) * total_speed;
//   actor[a].x_speed = cos(angle_to_radians(angle3)) * total_speed;
//   actor[a].y_speed = sin(angle_to_radians(angle3)) * total_speed;

   actor[a].x_speed += (enemy[i].x_speed / 2) * 100 / actor[a].mass;
   actor[a].y_speed += (enemy[i].y_speed / 2) * 100 / actor[a].mass;

// Now the enemy's
   angle1 = radians_to_angle(atan2(enemy[i].y_speed, enemy[i].x_speed));
   angle2 = radians_to_angle(atan2(enemy[i].y - actor[a].y, enemy[i].x - actor[a].x));

   total_speed = hypot(enemy[i].y_speed, enemy[i].x_speed);

   angle1 += ANGLE_HALF;
   if (angle2 > ANGLE_FULL)
    angle2 -= ANGLE_FULL;

   angle2 += ANGLE_QUARTER;
   if (angle2 > ANGLE_FULL)
    angle2 -= ANGLE_FULL;

   difference = angle2 - angle1;
   angle3 = angle2 - difference; // or +?

   enemy[i].x_speed = xpart(angle3, total_speed);//cos(angle_to_radians(angle3)) * total_speed;
   enemy[i].y_speed = ypart(angle3, total_speed);//sin(angle_to_radians(angle3)) * total_speed;

   enemy[i].x_speed += (xs2 * 25) / enemy[i].mass * actor[a].mass / 100;
   enemy[i].y_speed += (ys2 * 25) / enemy[i].mass * actor[a].mass / 100;


   int sanity = 0;
          
   do
   {
    actor[a].x_speed += xpart(angle2, 100);//grand(101) - 50;
    actor[a].y_speed += ypart(angle2, 100);//grand(101) - 50;
    move_actor(a);
    sanity ++;
    if (sanity >= 5000)
     break; // hmm
   } while (hypot(actor[a].x - enemy[i].x, actor[a].y - enemy[i].y) < actor[a].radius + enemy[i].radius);

   actor[a].just_collided = 7;
   enemy[i].just_collided = 7;

   if (actor[a].ship == SHIP_CURVE)
   {
      passing_colours [0] = TRANS_DGREEN;
      passing_colours [1] = TRANS_LGREEN;
      passing_colours [2] = TRANS_YELLOW;
       
      place_explosion(actor[a].x, actor[a].y, 0,0,
       300 + crandom(150), passing_colours);
      blast(actor[a].x, actor[a].y, 40000, 100 + actor[a].total_power * 15, 20000, a);
      blast(enemy[i].x, enemy[i].y, 40000, 0, 2000, OWNER_ENEMY);
      play_wavf(NWAV_BURSTZ, 300 + grand(300));
//   blast(bullet[b].x, bullet[b].y, 30000, 200, 1200, bullet[b].owner);
   }
    else
    {
      passing_colours [0] = TRANS_DGREY;
      passing_colours [1] = TRANS_LGREY;
      passing_colours [2] = TRANS_WHITE;
       
      place_explosion(actor[a].x, actor[a].y, 0,0,
       200 + crandom(150), passing_colours);
     }  

// we cannot have any references to enemy[i] below as it may have been destroyed by the blast
//  call above.
       
   place_explosion(actor[a].x, actor[a].y, 0,0,
    200 + crandom(150), passing_colours);

   play_wavf(NWAV_BUMP, 700 + grand(800));

   hurty = collision_velocity / 30;
   if (hurty > 50)
    hurty = 50;
   
   if (check_shielder(i) == 0 && actor[a].ship != SHIP_CURVE)
   {
    hurt_enemy(i, hurty, a, 1);
    if (enemy[i].hurt_pulse < 4)
     enemy[i].hurt_pulse = 4;
   }
   
   hurt_actor(a, a, hurty);

   break;
/*
   if ((angle1 < angle2 && angle2 > angle1 + ANGLE_HALF)
       || (angle1 > angle2 && angle2 > angle1 - ANGLE_HALF))
   {
    difference =
    angle -= turning;
    if (angle < 0)
     angle += ANGLE_FULL;
   }
    else
    {
     angle += turning;
     if (angle > ANGLE_FULL)
      angle -= ANGLE_FULL;
    }
*/

  }
 
 }

 return -1;

}
コード例 #16
0
ファイル: game.c プロジェクト: evktalo/lacewing
void run_hostile_level()
{
  int hostile_attack, i;

  if (counter % 8 != 0 || grand(3) != 0)
   return;

  hostile_attack = grand(5) + arena.hostile / 100;

  if (hostile_attack > 5)
   hostile_attack = 5;

  int x, y, xs, ys;

//  int colours [4] = {COLOUR_WHITE, COLOUR_BLUE6, COLOUR_BLUE4, COLOUR_BLUE2};
  int colours [4] = {COLOUR_BLUE3, COLOUR_BLUE5, COLOUR_BLUE7, COLOUR_WHITE};
//  int colours [4] = {COLOUR_WHITE, COLOUR_BLUE7, COLOUR_BLUE5, COLOUR_BLUE3};

  play_sound(WAV_HOSTILE);

  for (i = 0; i < hostile_attack; i ++)
  {

   if (grand(2) == 0)
   {
    x = 1000;
    xs = 10000;
    if (grand(2) == 0)
    {
     x = arena.max_x - 1000;
     xs = -10000;
    }
    y = grand(arena.max_y - 20000) + 10000;
    y /= GRID_WIDTH * GRAIN;
    y *= GRID_WIDTH * GRAIN;
    y -= 4000;
    ys = 0;
   }
    else
    {
     y = 2000;
     ys = 10000;
     if (grand(2) == 0)
     {
      y = arena.max_y - 2000;
      ys = -10000;
     }
     x = grand(arena.max_x - 20000) + 10000;
     x /= GRID_WIDTH * GRAIN;
     x *= GRID_WIDTH * GRAIN;
     x -= 4000;
     xs = 0;
    }

   create_bullet(BULLET_HOSTILE, x, y,
    xs, ys, OWNER_ENEMY,
    400, 2000, 400, 0,
    0, 0, colours, 3,0,0,0,0,0);

  }

}
コード例 #17
0
ファイル: actor.c プロジェクト: evktalo/overgod
void drag_actor(int i)
{

// int drag_x, drag_y;
// int new_x_speed, new_y_speed;

/* float drag_mult = 0.015 - (actor[i].ability [ABILITY_DRIVE] [SYMBOL_TRIANGLE] * 0.0015);//game.drag;
 if (actor[i].dragging > 0)
 {
  drag_mult *= (float) actor[i].brake_strength * actor[i].dragging / 20;
 }*/
 //float drag_mult = 0.020 - (actor[i].ability [ABILITY_DRIVE] [SYMBOL_TRIANGLE] * 0.0020);//game.drag;
 
 float drag_mult = 0.025 - (actor[i].ability [ABILITY_DRIVE] [SYMBOL_TRIANGLE] * 0.0025);//game.drag;

 if (actor[i].dragging > 0)
 {
  drag_mult *= (float) actor[i].brake_strength * actor[i].dragging / 23;
 }

 int angle = radians_to_angle(atan2(actor[i].y_speed, actor[i].x_speed));
 actor[i].moving_angle = angle;
 float dragged = hypot(abs(actor[i].x_speed), abs(actor[i].y_speed)) * drag_mult;

 if (actor[i].dragging == 0 && actor[i].ability [ABILITY_DRIVE] [SYMBOL_TRIANGLE] != 0)
 {
  if (dragged < 10 + actor[i].ability [ABILITY_DRIVE] [SYMBOL_TRIANGLE] * 5)
  {
   dragged /= 5 + actor[i].ability [ABILITY_DRIVE] [SYMBOL_TRIANGLE];
  }
 }

 float change = cos(angle_to_radians(angle)) * dragged;
 actor[i].x_speed -= change;// * game[0].drag;

 change = sin(angle_to_radians(angle)) * dragged;
 actor[i].y_speed -= change;// * game[0].drag;

 if (actor[i].dragging == 20)
 {
  if (abs(actor[i].x_speed) < 20 && abs(actor[i].y_speed) < 20)
  {
   actor[i].x_speed = 0;
   actor[i].y_speed = 0;
  }
 }


 if (actor[i].dragging == 20 && grand(100) + 70 < dragged)
 {
  int passing_colours [5] = {COLOUR_YELLOW8, COLOUR_ORANGE8, COLOUR_RED8, COLOUR_RED6, COLOUR_RED4};
  create_cloud(CLOUD_SPECK,
  actor[i].x + grand(10001) - 5000,
  actor[i].y + grand(10001) - 5000,
   0, 0,
//   actor[a].x_speed + x_accel * 20 + (300 - grand(601)),
//   actor[a].y_speed + y_accel * 20 + (300 - grand(601)),
   0, 0,
   10 + grand(11),1,0, 0, 0, 0, passing_colours);
 }

 if (dragged > 250 - (actor[i].dragging == 20) * 150)
 {
   player[actor[i].controller].screen_shake_x += grand((dragged - 100) * 60) - ((dragged - 100) * 30);
   player[actor[i].controller].screen_shake_y += grand((dragged - 100) * 60) - ((dragged - 100) * 30);
//   player[actor[i].controller].screen_shake_x += grand(3500) - 1750;
//   player[actor[i].controller].screen_shake_y += grand(3500) - 1750;
//  if (dragged > 60)
// {
   
// }
 }

 actor[i].drag_amount = dragged;// * game[0].drag;
/*
 if (actor[i].drag_amount < 2)
  return;


 actor[i].x_speed = new_x_speed;
 actor[i].y_speed = new_y_speed;
*/
}
コード例 #18
0
ファイル: CRex.cpp プロジェクト: gitkobaya/ABC
/**
 * <PRE>
 *    適応的実数値交叉AREXを実行します。
 * </PRE>
 * @author kobayashi
 * @since 2016/6/10
 * @version 1.0
 */
void CRex::vARex()
{
	CRexException cre;
	int i,j,k;
	int iLoc;
	int iMaxSize = 0;
	int iOverLapLoc = 0;
	int iTemp = 0;
	double lfSigma = 0.0;
	double l;
	double lAvgDist = 0.0;
	double lfTemp = 0.0;
	std::vector<Rank_t> stlFitProb;
	std::vector<Rank_t> stlParentFitProb;
	Rank_t tTempRankData;
	std::vector<int> stlSelectParentLoc;

	int i1stGenLoc = 0;
	int i2ndGenLoc = 0;
	
/* JGGモデル */

	try
	{
		// 親をランダムにNp個選択します。
		for( i = iGenNumber-1; i >= 0 ; i-- )
		{
			iLoc = (int)((i+1)*rnd());
			iTemp = piParentLoc[i];
			piParentLoc[i] = piParentLoc[iLoc];
			piParentLoc[iLoc] = iTemp;
			if( i <= iParentNumber )
			{
				// 親データを適応度でソートするため、データを代入します。
				tTempRankData.lfFitProb = pflfConstraintFunction( pplfGens[piParentLoc[i]], iGenVector );
				tTempRankData.iLoc = piParentLoc[i];
				stlParentFitProb.push_back( tTempRankData );
			}
		}
	
		std::sort( stlParentFitProb.begin(), stlParentFitProb.end(), CCompareToRank() );
	
		// 重心及び交叉中心降下を算出します。
		for( j = 0;j < iGenVector; j++ )
		{
			plfCentroid[j] = 0.0;
			plfCentroidSteep[j] = 0.0;
			for( i = 0;i < iParentNumber; i++ )
			{
				plfCentroid[j] += pplfGens[stlParentFitProb.at(i).iLoc][j];
				plfCentroidSteep[j] += 2.0*(double)(iParentNumber+1-(i+1))*pplfGens[stlParentFitProb.at(i).iLoc][j];
			}
			plfCentroid[j] /= (double)iParentNumber;
			plfCentroidSteep[j] /= (double)(iParentNumber*(iParentNumber+1));
		}
	// REX(RealCoded Emsanble )を実行します。交叉回数Nc回実行し、Nc個の子供を生成します。
		// 統計量遺伝における普遍分散を算出します。
		lfSigma = 1.0/(double)sqrt( (double)iParentNumber-1 );
//		lfSigma = sqrt(3.0/(double)(iParentNumber));

		for( i = 0;i < iChildrenNumber; i++ )
		{
			// 正規乱数により乱数を発生させます。
			for( j = 0;j < iParentNumber; j++ )
			{
				plfNormalizeRand[j] = grand(lfSigma, 0.0);
//				plfNormalizeRand[j] = lfSigma*(2.0*rnd()-1.0);
				if( iDistanceFlag == 2 ) pplfNormalizeRand[i][j] = plfNormalizeRand[j];
			}
			for( k = 0;k < iGenVector; k++ )
			{
			// REXを実行して、子供を生成します。
				plfTempVector[k] = 0.0;
				for( j = 0;j < iParentNumber; j++ )
					plfTempVector[k] += plfNormalizeRand[j] * ( pplfGens[stlParentFitProb.at(j).iLoc][k] - plfCentroid[k] );
				pplfChildren[i][k] = plfCentroidSteep[k] + lfAlpha*plfTempVector[k];
			}
			// 評価値をNp個算出します。
			tTempRankData.lfFitProb = pflfConstraintFunction( pplfChildren[i], iGenVector );
			tTempRankData.iLoc = i;
			stlFitProb.push_back( tTempRankData );
		}
		
		// 目的関数値によるソートを実施します。
		std::sort( stlFitProb.begin(), stlFitProb.end(), CCompareToRank() );

		// 拡張率適応度を計算します。
		if( iDistanceFlag == 1 )
		{
			// 交叉の中心を求めます。
			// 評価値上位μα個の子供の中心を求めます。
			for( j = 0;j < iGenVector; j++ )
			{
				plfChildrenCentroid[j] = 0.0;
				plfUpperEvalChildrenCentroid[j] = 0.0;
				for( i = 0;i < iChildrenNumber; i++ )
				{
					plfChildrenCentroid[j] += pplfChildren[stlFitProb.at(i).iLoc][j];
					plfUpperEvalChildrenCentroid[j] += pplfChildren[stlFitProb.at(i).iLoc][j];
				}
				plfChildrenCentroid[j] /= (double)(iChildrenNumber);
				plfUpperEvalChildrenCentroid[j] /= (double)iUpperEvalChildrenNumber;
			}
			vAerEuclide( stlParentFitProb );
		}
		else if( iDistanceFlag == 2 )
		{
			vAerMahalanobis( stlFitProb );
		}
#if 1
		// 親を入れ替えます。(JGGモデルの場合は親はすべて変更するものとします。)
		for( i = 0; i < iParentNumber; i++ )
			for( j = 0;j < iGenVector; j++ )
				pplfGens[stlParentFitProb.at(i).iLoc][j] = pplfChildren[stlFitProb.at(i).iLoc][j];
		// 現在の最良位置を取得します。
#else
		vSelectGens( pplfChildren, &i1stGenLoc, &i2ndGenLoc );
		for( j = 0;j < iGenVector; j++ )
		{
			pplfGens[stlParentFitProb.at(0).iLoc][j] = pplfChildren[i1stGenLoc][j];
			pplfGens[stlParentFitProb.at(1).iLoc][j] = pplfChildren[i2ndGenLoc][j];
		}
#endif
		iBestLoc = stlParentFitProb.at(0).iLoc;
	}
	catch(...)
	{
		cre.SetErrorInfo( REX_ARRAY_INDEX_ERROR, "vImplement", "CRex", "配列範囲外参照をしました。", __LINE__ );
		throw( cre );
	}
	stlParentFitProb.clear();
	stlFitProb.clear();
}
コード例 #19
0
ファイル: actor.c プロジェクト: evktalo/overgod
// called at start of each game
void init_actor(int a, int type)
{
 int i,j;

 actor[a].type = ACTORTYPE_SHIP; // redundant
 actor[a].ship = type;
 actor[a].radius = 9000;
 actor[a].edge_radius = 5000;
// actor[a].turning = 70; now calculated dynamically
 actor[a].thrust = 0;
 actor[a].slide = 50;
 actor[a].mass = 100;
 actor[a].x = grand(494000) + 50000;
 actor[a].y = grand(495000) + 50000;
 actor[a].next_spawn_x = actor[a].x;
 actor[a].next_spawn_y = actor[a].y;

 for (i = 0; i < 4; i ++)
 {
  for (j = 0; j < 4; j ++)
  {
   actor[a].ability [i] [j] = 0;  
  } 
 }
 
 actor[a].total_power = 0;

// for (j = 0; j < NO_UPGRADES; j ++)
// {
//  actor[a].upgrades [j] = 0;
//  actor[a].upgrade_specials [j] = 0;
// }
// for (j = 0; j < MAX_UPGRADES; j ++)
// {
//actor[a].upgraded_system [j] = 0;
// }
// for (j = 0; j < 9; j ++)
// {
//  actor[a].upgrade_structure [j] = upgrades [actor[a].ship] [j];
//  actor[a].upgrade_specials [j] = 0;
// }
/* actor[a].upgrade_structure [0] = UPG_NONE;
 actor[a].upgrade_structure [1] = UPG_SPEED;
 actor[a].upgrade_structure [2] = UPG_SLIDE;
 actor[a].upgrade_structure [3] = UPG_RETRO;
 actor[a].upgrade_structure [4] = UPG_SIDEKICK;
 actor[a].upgrade_structure [5] = UPG_ROCKET;
 actor[a].upgrade_structure [6] = UPG_PROJECT;
 actor[a].upgrade_structure [7] = UPG_WARHEAD;
 actor[a].upgrade_structure [8] = UPG_SPECIAL;*/
 actor[a].upgrade_slot = 0;
 actor[a].brakes = BRAKES_DRAG;
 actor[a].brake_strength = 5;
 actor[a].max_armour = 1000;
 if (game.type == GAME_DUEL)
 {
  actor[a].max_armour = duel_armour(actor[a].max_armour, game.duel_handicap [actor[a].controller]);
 }
 actor[a].armour = actor[a].max_armour;
 actor[a].max_shield = 0;
 actor[a].shield = 0;
 actor[a].spawn_delay = 50;
 actor[a].grace_period = 0;
 actor[a].secondary = SECOND_NONE;//D_ORB;//SECONDARY_NONE;
 actor[a].sidekicks = 0;

// actor[a].exhaust_distance_x = 14;
// actor[a].exhaust_distance_y = 15;
 actor[a].exhaust_distance_x = 10;
 actor[a].exhaust_distance_y = 10;
 actor[a].flash_distance = 5000;

 switch(actor[a].ship)
 {
  case SHIP_SMALL:
   actor[a].radius = 7000;
   actor[a].edge_radius = 3000;
   actor[a].exhaust_distance_x = 7;
   actor[a].exhaust_distance_y = 7;
   break;
  case SHIP_HORSESHOE:
   actor[a].exhaust_distance_x = 4;
   actor[a].exhaust_distance_y = 4;
   break;
  case SHIP_FINS:
   actor[a].exhaust_distance_x = 9;
   actor[a].exhaust_distance_y = 9;
   break;
  case SHIP_RETRO:
   actor[a].exhaust_distance_x = 9;
   actor[a].exhaust_distance_y = 9;
   break;
  case SHIP_ROUND:
   actor[a].exhaust_distance_x = 9;
   actor[a].exhaust_distance_y = 9;
   break;
  case SHIP_ORBITAL:
   actor[a].exhaust_distance_x = 1;
   actor[a].exhaust_distance_y = 1;
   actor[a].mass = 400;
   break;
  case SHIP_CURVE:
   actor[a].exhaust_distance_x = 3;
   actor[a].exhaust_distance_y = 3;
   break;
   
 /*
  case SHIP_LACEWING:
  actor[a].exhaust_distance_x = 1;
  actor[a].exhaust_distance_y = 0;
  actor[a].flash_distance = 4000;
  break;
  case SHIP_AETHER:
  actor[a].exhaust_distance_x = 1;
  actor[a].exhaust_distance_y = 0;
  actor[a].flash_distance = 7000;
  break;
  case SHIP_DESPOT:
  actor[a].exhaust_distance_x = 1;
  actor[a].exhaust_distance_y = 0;
  break;
  case SHIP_CAPYBARA:
  actor[a].exhaust_distance_x = 6;
  actor[a].exhaust_distance_y = 5;
  actor[a].flash_distance = 6000;
  break;
  case SHIP_LENTIL:
  actor[a].exhaust_distance_x = 6;
  actor[a].exhaust_distance_y = 5;
  break;
  case SHIP_HOOKWORM:
  actor[a].exhaust_distance_x = 8;
  actor[a].exhaust_distance_y = 7;
  actor[a].flash_distance = 3000;
  break;
  case SHIP_PORKUPINE:
  actor[a].exhaust_distance_x = 8;
  actor[a].exhaust_distance_y = 7;
  actor[a].flash_distance = 4000;
  break;
  case SHIP_SCORPION:
  actor[a].exhaust_distance_x = 4;
  actor[a].exhaust_distance_y = 3;
  actor[a].flash_distance = 4000;
  break;
  case SHIP_TORTFEASOR:
  actor[a].exhaust_distance_x = 4;
  actor[a].exhaust_distance_y = 3;
  actor[a].flash_distance = 9000;
  break;
  case SHIP_RUMSFELD:
  actor[a].exhaust_distance_x = 4;
  actor[a].exhaust_distance_y = 3;
  break;
  case SHIP_PRONG:
  actor[a].flash_distance = 1000;
  break;
  case SHIP_GODBOTHERER:
  actor[a].exhaust_distance_x = 3;
  actor[a].exhaust_distance_y = 2;
  actor[a].flash_distance = 5000;
  break;
  case SHIP_BOTULUS:
  actor[a].exhaust_distance_x = 3;
  actor[a].exhaust_distance_y = 2;
  actor[a].flash_distance = 6000;
  break;
  case SHIP_SLIDEWINDER:
  actor[a].exhaust_distance_x = 1;
  actor[a].exhaust_distance_y = 0;
  actor[a].flash_distance = 4000;
  break;
  case SHIP_DOOM:
  actor[a].exhaust_distance_x = 7;
  actor[a].exhaust_distance_y = 6;
  actor[a].flash_distance = 8000;
  break;
  */
 }

 
 actor[a].retro_distance_x = 5;
 actor[a].retro_distance_y = 4;
 actor[a].slide_distance_x = 5;
 actor[a].slide_distance_y = 4;
// actor[a].exhaust_displacement = 0;

 actor[a].primary = WPN_DARTS;
}
コード例 #20
0
ファイル: avec_draw_test.C プロジェクト: joukov/Avec
void avec_draw_test_tmultigraph()
{
  //Create some Avecs for drawing
  Avec x1(100,0,7); Avec y1=sin(x1); Avec y2=cos(x1);
  x1.SetName("x1");
  y1.SetName("sin(x)");
  y2.SetName("cos(x)");
  Avec x2(100,1.5, 8.5); Avec y3=cos(x2);
  Avec dy4=grand(Avec(10),0.2);
  Avec dy5=grand(Avec(10),0.1);
  Avec x3(10,0,7); Avec y4=sin(x3)+dy4; Avec y5=cos(x3)+dy5;
  Avec err4(10,0.2);
  Avec err5(10,0.1);

  std::cout << "Testing drawing of single Avec" << endl;
  // Test for single Avec drawing
  TCanvas* c1=new TCanvas("cv_sing","avec_draw test single");
  c1->Divide(2,2);

  // Single Avec
  c1->cd(1);
  //avec_draw(y1,"Avec","x","y","AL",1,"avec_draw_test_1");
  avec_draw(y1,"Avec","x");

  // Single Avec against Avec
  c1->cd(2);
  //avec_draw(x1, y1,"Avec \% Avec","x","y","AL",1,"avec_draw_test_2"); // All parameters passed
  avec_draw(x1, y1); //Shortest possible version 

  // Single Avec with Errors against Avec
  c1->cd(3);
  avec_draw(x3, y4, y5, err4, "Avec \% Avec with Errors","x","y","AP");


  std::cout << "Testing TMultiGraphs" << endl;
  // Test for TMultiGraph
  TCanvas* c2=new TCanvas("cv_mgr","multigraph test");
  c2->Divide(2,2);

  // Draw set of Avecs against one Avec
  c2->cd(1);
  avec_draw(x1,(y1 | y2),"Set of Avecs \% Avec","XTitle","YTitle");

  // Draw set of Avecs against set of Avecs
  c2->cd(2);
  avec_draw((x1 | x2),(y1 | y3),"Set of Avecs \% Set of Avecs","XTitle","YTitle","AL");

  // Draw set of Avecs with errors against set of Avecs
  c2->cd(3);
  TMultiGraph* mgr = avec_draw(x3, (y4 | y5),(err4 | err5),"Set of Avecs with errors \% Avec","XTitle","YTitle","AP");

  // Draw columns in Avec2D against one Avec
  c2->cd(4);
  Avec2D y2D;
  y2D.push_back(y1);
  y2D.push_back(y2);
  avec_draw(x1,y2D,"Avec2D \% Avec","XTitle","YTitle");
  
  
  TCanvas* c2=new TCanvas("cv_mgr_2","Test MultiGraph Palette");

  Avec px(100, 0, TMath::TwoPi());
  std::vector<Avec> vy;
  for(double coeff = 1.0; coeff <= 3.0; coeff += 0.1) vy.push_back( coeff * sin(px)); 
  Avec py1 = sin(px);
  Avec py2 = 1.1 * sin(px);
  Avec py3 = 1.2 * sin(px);
  Avec py4 = 1.3 * sin(px);
  Avec py5 = 1.4 * sin(px);
  Avec py6 = 1.5 * sin(px);
  Avec py7 = 1.6 * sin(px);
  Avec py8 = 1.7 * sin(px);
  Avec py9 = 1.8 * sin(px);
  Avec py10 = 1.9 * sin(px);
  //avec_draw(px, (py1|py2|py3|py4|py5|py6|py7|py8|py9|py10), "", "", "", "ALP");
  avec_draw(px, vy, "", "x", "y", "ALP");


/*   TLegend* leg = new TLegend(0.4,0.5,0.89,0.89); */
/*   //leg->SetTextFont(72); */
/*   leg->SetTextSize(0.08); */
/*   leg->SetHeader("Avec Legend"); */
/*   leg->AddEntry(mgr->GetListOfGraphs()->At(0),"Avec 1","P"); */
/*   leg->AddEntry(mgr->GetListOfGraphs()->At(1),"Avec 2","P"); */
/*   leg->Draw(); */

}
コード例 #21
0
ファイル: actor.c プロジェクト: evktalo/overgod
void run_actors(void)
{
 int i;

 for (i = 0; i < NO_ACTORS; i ++)
 {
  if (actor[i].type == ACTORTYPE_NONE)
   continue;
  if (actor[i].in_play == 0)
  {
   
   actor[i].x_speed = 0;
   actor[i].y_speed = 0;
   if (actor[i].spawn_delay > 0)
   {
    actor[i].spawn_delay --;
    continue;
   }
   if (game.ships_left > 0)
   {
    if (arena.game_over == 0)
     spawn_actor(i); // ships_left will be non-zero for time attack games.
   } 
     else
      continue;
  }
//  actor[i].energy += actor[i].recharge;
//  if (actor[i].energy >= actor[i].max_energy)
//   actor[i].energy = actor[i].max_energy;

   if (actor[i].screen_shake_time > 0)
   {
    if (actor[i].screen_shake_time > 4)
    {
     player[actor[i].controller].screen_shake_x = grand(7501) - 3250;
     player[actor[i].controller].screen_shake_y = grand(7501) - 3250;
    }
     else
     {
      player[actor[i].controller].screen_shake_x = grand(3500) - 1750;
      player[actor[i].controller].screen_shake_y = grand(3500) - 1750;
     } 
    actor[i].screen_shake_time --;
   }
    else
    {
     player[actor[i].controller].screen_shake_x = 0;
     player[actor[i].controller].screen_shake_y = 0;
    }
// screen_shake needs to be first, as many things below can affect it and we don't want them wiped.
   
  if (actor[i].repairing > 0)
  {
   actor[i].repairing --;
   if (actor[i].armour < actor[i].max_armour)
    actor[i].armour += 5;
   if (actor[i].armour > actor[i].max_armour)
    actor[i].armour = actor[i].max_armour;
// + play a sound?
  }

  if (actor[i].ship == SHIP_ROUND && counter % 7 == 0)
  {
   if (actor[i].armour < actor[i].max_armour)
    actor[i].armour += 1;
  }


  if (actor[i].grace_period > 0)
   actor[i].grace_period --;
  if (actor[i].hurt_pulse > 0)
   actor[i].hurt_pulse --;
  if (actor[i].recycle1 > 0)
   actor[i].recycle1 --;
  if (actor[i].recycle2 > 0)
   actor[i].recycle2 --;
   
  if (actor[i].turret_recycle > 0)
   actor[i].turret_recycle --;
  if (actor[i].sidekick_recycle > 0)
   actor[i].sidekick_recycle --;
  if (actor[i].heavy_recycle > 0)
   actor[i].heavy_recycle --;
  if (actor[i].backfire_recycle > 0)
   actor[i].backfire_recycle --;
   
  if (actor[i].secondary_burst > 0)
   continue_secondary_burst(i); 
   
  if (actor[i].just_upgraded_timeout > 0)
   actor[i].just_upgraded_timeout --;
  if (actor[i].just_collided > 0)
   actor[i].just_collided --;
  move_actor(i);
  detect_collision_actor_enemies(i);
  detect_collision_actor_pickups(i);
  if (actor[i].upgraded_system [UPG_SEEKER] > 0)
   acquire_target(i);
//  if (actor[i].upgraded_system [UPG_TURRET] > 0)
//   acquire_turret_target(i);
//  if (actor[i].ship == SHIP_ORBITAL && actor[i].total_power > 0)
//   actor_orbital(i);
  if (actor[i].ability [ABILITY_DEFENCE] [SYMBOL_CIRCLE] > 0)
   actor_shield(i);
//  if (actor[i].upgraded_system [UPG_SIDEKICK] > 0)
//   actor_sidekicks(i);
  if (actor[i].drive_sound [DRIVE_THRUST] > 0)
   actor[i].drive_sound [DRIVE_THRUST] --;
  if (actor[i].drive_sound [DRIVE_SLIDE] > 0)
   actor[i].drive_sound [DRIVE_SLIDE] --;
  if (actor[i].drive_sound [DRIVE_RETRO] > 0)
   actor[i].drive_sound [DRIVE_RETRO] --;
 }

}
コード例 #22
0
ファイル: selunit.c プロジェクト: YoshikazuNakahara/Unixv7x86
selunit()
{
	char fnam[20], s[50];
	static char dobuff[50];
	char posslev[20][20];
	int diff[20], i, k, m, n, best, alts;
	FILE *f;
	char zb[200];
	static char saved[20];

	while (ask) {
		printf("What lesson? ");
		fflush(stdout);
		gets(dobuff);
		if (strcmp(dobuff, "bye") == 0)
			wrapup(0);
		level = todo = dobuff;
		sprintf(s, "../../%s/L%s", sname, dobuff);
		if (access(s, 04) == 0)
			return;
		printf("no such lesson\n");
	}
	alts = 0;
retry:
	f=scrin;
	if (f==NULL) {
		sprintf(fnam, "../../%s/L%s", sname, level);
		f = fopen(fnam, "r");
		if (f==NULL) {
			fprintf(stderr, "No script for lesson %s.\n", level);
			wrapup(1);
		}
		while (fgets(zb, 200, f)) {
			trim(zb);
			if (strcmp(zb, "#next")==0)
				break;
		}
	}
	if (feof(f)) {
		printf("Congratulations; you have finished this sequence.\n");
		fflush(stdout);
		todo = 0;
		return;
	}
	for(i=0; fgets(s, 50, f); i++) {
		sscanf(s, "%s %d", posslev[i], &diff[i]);
	}
	best = -1;
	/* cycle through lessons from random start */
	/* first try the current place, failing that back up to
	     last place there are untried alternatives (but only one backup) */
	n = grand()%i;
	for(k=0; k<i; k++) {
		m = (n+k)%i;
		if (already(posslev[m],0)) continue;
		if (best<0) best=m;
		/* real alternatives */
		alts++;
		if (abs(diff[m]-speed) < abs(diff[best]-speed))
			best=m;
	}
	if (best < 0 && nsave) {
		nsave--;
		strcpy(level, saved);
		goto retry;
	}
	if (best <0) {
		/* lessons exhausted or missing */
		printf("Sorry, there are no alternative lessons at this stage.\n");
		printf("See someone for help.\n");
		fflush(stdout);
		todo = 0;
		return;
	}
	strcpy (dobuff, posslev[best]);
	if (alts>1) {
		nsave=1;
		strcpy (saved, level);
	}
	todo = dobuff;
	fclose(f);
}
コード例 #23
0
gnum gDistribution::gDefault()
{
    return grand();
}
コード例 #24
0
ファイル: patricia.c プロジェクト: andyjsharp/juise
main (int argc, char *argv[])
{
    patroot *root;
    testnode *test;
    patnode *node, *next, *prev;
    int i;
    long adds, dels, total, badds, bdels;
    int special_on, special_key;

    root = patricia_init_root(sizeof(int));
    if (!root) {
	printf("root malloc failed\n");
	exit(1);
    }

    adds = 0;
    dels = 0;
    total = 0;
    badds = 0;
    bdels = 0;
    special_on = FALSE;
    special_key = SPECIAL;
    while (TRUE) {
	switch(grand(4)) {
	case 0:				/* Add a node */
	default:
	    if (total >= MAXNODECOUNT) {
		break;
	    }
	    test = malloc(sizeof(testnode));
	    if (!test) {
		printf("node malloc failed\n");
		exit(1);
	    }
	    patricia_node_init(&test->patricia);

	    /*
	     * Generate a key not in the tree.
	     */
	    do {
		test->key = grand_log2(32);
	    } while (patricia_lookup_inline(root, (u_char *)&test->key));

	    if (test->key == special_key) {
		special_on = TRUE;
	    }

	    if (!patricia_add(root, &test->patricia)) {

		printf("node add failed\n");
		exit(1);
	    }

	    if (patricia_lookup_inline(root, (u_char *)&test->key) !=
		&test->patricia) {
		printf("lookup after add failed, key %x\n",
		       test->key);
		exit(1);
	    }
	    total++;
	    adds++;
	    if (adds == BHA) {
		badds++;
		adds = 0;
	    }

	    if ((adds % OPREPORT) == 0) {
		printf("%ub %u adds, %u total\n", badds, adds, total);
	    }

	    if (special_on) {
		if (patricia_lookup_inline(root,
					   (u_char *)&special_key) == NULL)
		{
		    printf("special failure after add, key %x\n",
			   test->key);
		    exit(1);
		}
	    }
	    break;
	case 1:				/* Do a lookup */
	    node = patricia_lookup_random(root);
	    if (!node) {
		assert(total == 0);
		break;
	    }
	    if (patricia_lookup_inline(root, (u_char *)&node->key) !=
		node) {
		printf("lookup failed, key %x\n", pat_to_test(node)->key);
		exit(1);
	    }

	    i = grand_log2(32);		/* Test lookup_geq */
	    node = patricia_lookup_geq(root, (u_char *)&i);
	    if (node) {
		if (i == pat_to_test(node)->key) {
		    break;
		} else if (ntohl(pat_to_test(node)->key) < ntohl(i)) {
		    printf("geq failure 1\n");
		    exit(1);
		}
		prev = patricia_get_previous(root, node);
		if (!prev) {
		    break;
		}
		if (ntohl(pat_to_test(prev)->key) < ntohl(i)) {
		    break;
		}
		printf("geq failure 2\n");
		exit(1);
	    } else {
		node = patricia_lookup_greatest(root);
		if (!node) {
		    break;
		}
		if (ntohl(pat_to_test(node)->key) >= ntohl(i)) {
		    printf("geq failure 3\n");
		    exit(1);
		}
	    }
	    break;
	    
	case 2:				/* Do a delete */
	    node = patricia_lookup_random(root);
	    if (!node) {
		assert(total == 0);
		break;
	    }
	    if (!patricia_delete(root, node)) {
		printf("delete failed, key %x\n", node->key);
		exit(1);
	    }

	    if (special_on) {
		if (pat_to_test(node)->key == special_key) {
		    special_on = FALSE;
		} else {
		    if (patricia_lookup_inline(root,
					       (u_char *)&special_key) == NULL)
		    {
			printf("special failure after delete, key %x\n",
			       pat_to_test(node)->key);
			exit(1);
		    }
		}
	    }
	    free(pat_to_test(node));
	    dels++;
	    total--;
	    if (dels == BHA) {
		bdels++;
		dels = 0;
	    }
	    if ((dels % OPREPORT) == 0) {
		printf("%ub %u dels, %u total\n", bdels, dels, total);
	    }

	    break;
	case 3:				/* Tree traversal */
	    test_count = 0;
	    patricia_traversal(root, test_callback);
	    if (test_count) {
		test_count--;		/* Don't count the root twice */
	    }
	    if (test_count != total) {
		printf("%u total, %u found\n", total, test_count);
		exit(1);
	    }

	    /*
	     * Test get next.
	     */
	    test_count = 0;
	    node = patricia_lookup_least(root);
	    if (node) {
		test_count++;
		prev = patricia_get_previous(root, node);
		if (prev) {
		    printf("node previous to first");
		    exit(1);
		}
		    
/*		printf("least %x, total %d\n", pat_to_test(node)->key,
		total); */
		for (next = patricia_get_next(root, node);
		     next;
		     node = next, next = patricia_get_next(root, next)) {
		    test_count++;
		    if (ntohl(pat_to_test(node)->key) >=
			ntohl(pat_to_test(next)->key)) {
			printf("out of order %x %x\n",
			       pat_to_test(node)->key,
			       pat_to_test(next)->key);
			exit(1);
		    }
		    prev = patricia_get_previous(root, next);
		    if (prev != node) {
			printf("previous not same as get previous");
			exit(1);
		    }
/*		    printf("next %x\n", pat_to_test(next)->key); */
		}
	    }
	    if (test_count != total) {
		printf("%u total, %u found via get next\n", total, test_count);
		exit(1);
	    }
	    break;
	}

    }
    exit(0);
}
コード例 #25
0
ファイル: CRex.cpp プロジェクト: gitkobaya/rcga
void CRex::vRexStar()
{
	CRexException cre;
	int i,j,k;
	int iLoc;
	int iMaxSize = 0;
	int iOverLapLoc = 0;
	double lfSigma = 0.0;
	std::vector<Rank_t> stlFitProb;
	Rank_t tTempRankData;
	std::vector<int> stlSelectParentLoc;
	
/* JGGモデル */

	try
	{
		// 親をランダムにNp個選択します。
		for(;;)
		{
			iLoc = mrand() % iGenNumber;
			// 選択した親と重なっていないか調査します。
			iOverLapLoc = -1;
			for( i = 0;i < (unsigned int)stlSelectParentLoc.size(); i++ )
			{
				if( stlSelectParentLoc.at(i) == iLoc )
				{
					iOverLapLoc = i;
					break;
				}
			}
			// 重なっていなければ、位置を追加します。
			if( iOverLapLoc == -1 )
			{
				stlSelectParentLoc.push_back( iLoc );
				iMaxSize++;
			}
			// 指定した親の数になったら終了します。
			if( iMaxSize == iParentNumber ) break;
		}
		// 重心を算出します。
		for( i = 0;i < iGenVector; i++ )
		{
			plfCentroid[i] = 0.0;
		}
		for( i = 0;i < iParentNumber; i++ )
		{
			for( j = 0;j < iGenVector; j++ )
			{
				plfCentroid[j] += ( pplfGens[stlSelectParentLoc.at(i)][j] );
			}
		}
		for( i = 0;i < iParentNumber; i++ )
		{
			plfCentroid[j] /= (double)iParentNumber;
		}
	// REX(RealCoded Emsanble )を実行します。交叉回数Nc回実行し、Nc個の子供を生成します。
		// 統計量遺伝における普遍分散を算出します。
		lfSigma = 1.0/(double)sqrt( (double)iParentNumber );
		
		for( i = 0;i < iChildrenNumber; i++ )
		{
			// 正規乱数により乱数を発生させます。
			for( j = 0;j < iParentNumber; j++ )
			{
				plfNormalizeRand[j] = grand(lfSigma, 0.0);
			}
			for( j = 0;j < iGenVector; j++ )
			{
				plfTempVector[j] = 0.0;
				plfChildVector[j] = 0.0;
			}
			for( j = 0;j < iParentNumber; j++ )
			{
			// REXを実行して、子供を生成します。
				for( k = 0;k < iGenVector; k++ )
				{
					plfTempVector[k] += plfNormalizeRand[j] * ( pplfGens[stlSelectParentLoc.at(j)][k] - plfCentroid[k] );
				}
			}
			for( k = 0;k < iGenVector; k++ )
			{
				plfChildVector[k] = plfCentroid[k] + plfTempVector[k];
			}
			for( j = 0;j < iGenVector; j++ )
			{
				pplfChildren[i][j] = plfChildVector[j];
			}
		}
		
		// 評価値をNp個算出します。
		for( i = 0;i < iChildrenNumber; i++ )
		{
			tTempRankData.lfFitProb = pflfConstraintFunction( pplfChildren[i], iGenVector );
			tTempRankData.iLoc = i;
			stlFitProb.push_back( tTempRankData );
		}
		// 目的関数値によるソートを実施します。
		std::sort( stlFitProb.begin(), stlFitProb.end(), CCompareToRank() );
		// 親を入れ替えます。(JGGモデルの場合は親はすべて変更するものとします。)
		for( i = 0; i < iParentNumber; i++ )
		{
			for( j = 0;j < iGenVector; j++ )
			{
				pplfGens[stlSelectParentLoc.at(i)][j] = pplfChildren[stlFitProb[i].iLoc][j];
			}
		}
	}
	catch(...)
	{
		cre.SetErrorInfo( REX_ARRAY_INDEX_ERROR, "vImplement", "CRex", "配列範囲外参照をしました。", __LINE__ );
		throw( cre );
	}
	stlSelectParentLoc.clear();
}
コード例 #26
0
ファイル: cloud.c プロジェクト: evktalo/lacewing
void manage_cloud(int c)
{

 int passing_colours [5];

//   int x_gain = 0;
//   int y_gain = 0;
//   char angle_change;

//   if (cloud[c].timeout > 0)
//   {
    cloud[c].timeout -= cloud[c].tickrate;
    cloud[c].tickrate += cloud[c].delta_tickrate;
//   }

   if (cloud[c].timeout <= 0)
   {
    destroy_cloud(c);
    return;
   }

   switch(cloud[c].type)
   {
    case CLOUD_BURSTLET:
//     place_explosion(cloud[c].x, cloud[c].y, 0, 0, , cloud[c].colours);
     passing_colours [0] = cloud[c].colour [1]; // was [0]
   
     create_cloud(CLOUD_MED_TRANS_CIRCLE,
      cloud[c].x, cloud[c].y, 0, 0, 0, 0,
      50 + grand(300),0,3, 0, 0, 0, passing_colours);
//     passing_colours [0] = cloud[c].colour [1];

//     create_cloud(CLOUD_MED_TRANS_CIRCLE,
//      cloud[c].x, cloud[c].y, 0, 0, 0, 0, size,-40,15, 0, 0, 0, passing_colours);

     passing_colours [0] = cloud[c].colour [2];

     create_cloud(CLOUD_MED_TRANS_CIRCLE,
      cloud[c].x, cloud[c].y, 0, 0, 0, 0,
      50 + grand(300),0,6, 0, 0, 0, passing_colours);
     break;
    case CLOUD_SPAWNER:
     if (cloud[c].timeout % 2 == 0)
     {
       int cangle = grand(ANGLE_FULL);
       int cx = cloud[c].x + cos(angle_to_radians(cangle)) * grand(cloud[c].status * 100);
       int cy = cloud[c].y + sin(angle_to_radians(cangle)) * grand(cloud[c].status * 100);
//       create_cloud(CLOUD_MED_TRANS_CIRCLE,
//        cloud[c].x, cloud[c].y, 0, 0, 0, 0,
//        50 + grand(300),0,3, 0, 0, 0, passing_colours);
       place_explosion_with_smoke(
//        cloud[c].x - cloud[c].status * 100 + grand(cloud[c].status * 200),
//        cloud[c].y - cloud[c].status * 100 + grand(cloud[c].status * 200),
          cx, cy,
          0, 0, grand(cloud[c].status) + 250, cloud[c].colour);
       if (cloud[c].timeout % 8 == 0)
        play_sound_pos(WAV_MINEBANG, 200 + grand(200), 200, cx, cy);

     }
     break;
   }

   if (move_cloud(c, 1) == 0)
    return;

 drag_cloud(c);

}
コード例 #27
0
ファイル: menu.c プロジェクト: evktalo/butterfly
void run_menu_circles(void)
{

 new_menu_circle --;

 int i;

 if (new_menu_circle == 0)
 {
  for (i = 0; i < MENU_CIRCLES; i ++)
  {
   if (menu_circle_size [i] == 0)
   {
    menu_circle_max_size [i] = 500 + grand(1000) + grand(i * 100 + 1);
    menu_circle_size [i] = 1;
    menu_circle_grow_rate [i] = 10 + grand(10);
    menu_circle_rad [i] = 40 + grand(10) + i * 80 + (i * i);
    menu_circle_rot [i] = 1;
    if (grand(2))
     menu_circle_rot [i] = -1;
    if (i < 5 && grand(4) == 0)
     menu_circle_rot [i] *= 2;
      else
      {
       if (i < 3 && grand(4) == 0)
        menu_circle_rot [i] *= 3;
      }
    menu_circle_angle [i] = grand(ANGLE_1);
    menu_circle_number [i] = 2 + grand(2) + grand(2) + grand(i + 1);

    minicircle_size [i] = 0;
    minicircle_max_size [i] = 300 + grand(400);
    if (menu_circle_max_size [i] < 800)
     minicircle_max_size [i] = 100 + grand(300);
    minicircle_distance [i] = grand(20);

    new_menu_circle = 100 + grand(150);
    break;
   }
  }

 }

 int j;

 for (i = 0; i < MENU_CIRCLES; i ++)
 {
  if (menu_circle_size [i] == 0)
   break;

  if (menu_circle_size [i] < menu_circle_max_size [i])
   menu_circle_size [i] += menu_circle_grow_rate [i];
    else
    {
      if (minicircle_size [i] < minicircle_max_size [i])
       minicircle_size [i] += 10;
    }

  menu_circle_angle [i] += menu_circle_rot [i];
  menu_circle_angle [i] &= 1023;


  for (j = 0; j < menu_circle_number [i]; j ++)
  {
   draw_menu_circle(i, j);

  }
 }

}
コード例 #28
0
gVector2f gDistribution::gDisk()
{
    gnum th = grand() * M_PI * 2.0;
    gnum ra = 0.5 * grand();
    return gVector2f(ra * gcos(th) + 0.5, ra * gsin(th) + 0.5);
}
コード例 #29
0
ファイル: game.c プロジェクト: evktalo/overgod
void run_hostile_level()
{
  int hostile_attack, i, angle;
  int x, y, xs, ys;

  
//  colours_for_cloud [0] = TRANS_DRED;

 for (i = 0; i < arena.eyes_on_level; i ++)
 {
  angle = grand(ANGLE_FULL);
  xs = 2000 + grand(2000);
  simple_cloud_trans(arena.eye_colour3, arena.eye_x [i], arena.eye_y [i],
   xpart(angle, xs), ypart(angle, xs), 400);   
 }


//  if (counter % 8 != 0 || grand(3) != 0)
  if (counter % 8 != 0 || grand(2000) > arena.hostile)
   return;

  hostile_attack = grand(5) + arena.hostile / 100;

  if (hostile_attack > 5)
   hostile_attack = 5;

  int colours [4] = {COLOUR_BLUE3, COLOUR_BLUE5, COLOUR_BLUE7, COLOUR_WHITE};

//  play_wavf(WAV_);
//   enemy_soundf(e, NWAV_SZAP, 100 + grand(5));
// play_wav_pos(NWAV_BURSTZL, 600, 255, xs, ys);

//  do
//  {
   i = grand(arena.eyes_on_level);
   if (arena.eye_x [i] == 0)
    return;
//  } while (arena.eye_x [i] != 0); 
  
//  angle = grand(ANGLE_FULL);
  int target = -1;
  if (actor[0].in_play == 1 && actor[1].in_play == 1)
   target = grand(2);
    else
    {
     if (actor[0].in_play == 1)
      target = 0;
     if (actor[1].in_play == 1)
      target = 1;
    }

  if (target == -1)
   return;

  angle = radians_to_angle(atan2(actor[target].y - arena.eye_y [i], actor[target].x - arena.eye_x [i]));
 
  x = arena.eye_x [i] + xpart(angle, 5000);
  y = arena.eye_y [i] + ypart(angle, 5000);

  play_wav_pos(NWAV_SZAP, 50 + grand(10), 200, x, y);

  xs = xpart(angle, 15000);
  ys = ypart(angle, 15000);
  simple_cloud_trans(TRANS_WHITE, x, y, 0, 0, 400);

   create_bullet(BULLET_HOSTILE, x, y,
    xs, ys, OWNER_ENEMY,
    400, 2000, 40, 0,
    0, 0, colours, 3,0,0,0,0,0);

}
コード例 #30
0
gVector2f gDistribution::gCircle()
{
    gnum th = grand() * M_PI * 2.0;
    return gVector2f(0.5 * gcos(th) + 0.5, 0.5 * gsin(th) + 0.5);
}