pulse.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* $Id: pulse.c,v 1.14 2001/05/06 07:23:34 kilobug Exp $ */
  2. #include <private.h>
  3. #include <server.h>
  4. #include <action.h>
  5. #include <game.h>
  6. float get_pulse_team(float x, float y, int team_id)
  7. {
  8. float result = 0, r, agl;
  9. akx_t *akx;
  10. akx_pulse_t *pulse;
  11. int i;
  12. for (i = 0 ; i < gl_config->nb_objects ; i++)
  13. {
  14. akx = &gl_objects[i].akx;
  15. if (((akx->team_id == team_id) ||
  16. ((akx->team_id != -team_id) && (team_id < 0) && (akx->team_id))) &&
  17. (akx->type == obj_akx) &&
  18. (akx->action.type == act_akx_pulse))
  19. {
  20. pulse = &akx->action.act.pulse;
  21. if ((x != akx->x) || (y != akx->y))
  22. {
  23. r = dist(pulse->x, pulse->y, akx->x, akx->y);
  24. if (r >= dist(x, y, akx->x, akx->y))
  25. {
  26. agl = angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
  27. if (agl <= (pulse->angle / 2))
  28. {
  29. result += akx->energy / (1 + r * pulse->angle / 2);
  30. }
  31. }
  32. /* else
  33. printf("AGL : D(%f %f) A(%f %f) P(%f %f)%f\n", x, y, akx->x, akx->y, pulse->x, pulse->y, agl);*/
  34. }
  35. }
  36. }
  37. return result;
  38. }
  39. float get_pulse_id(float x, float y, int akx_id)
  40. {
  41. float result = 0, r, agl;
  42. akx_t *akx;
  43. akx_pulse_t *pulse;
  44. akx = &gl_objects[akx_id].akx;
  45. if (akx->action.type == act_akx_pulse)
  46. {
  47. pulse = &akx->action.act.pulse;
  48. if ((x != akx->x) || (y != akx->y))
  49. {
  50. r = dist(pulse->x, pulse->y, akx->x, akx->y);
  51. if (r >= dist(x, y, akx->x, akx->y))
  52. {
  53. agl = angle(x, y, akx->x, akx->y, pulse->x, pulse->y);
  54. if (agl <= (pulse->angle / 2))
  55. {
  56. result += akx->energy / (1 + r * pulse->angle / 2);
  57. }
  58. }
  59. }
  60. }
  61. return result;
  62. }
  63. float get_pulse_foe(float x, float y, int team_id)
  64. {
  65. return get_pulse_team(x, y, -team_id);
  66. }
  67. float get_pulse_total(float x, float y, int team_id)
  68. {
  69. return get_pulse_team(x, y, team_id) - get_pulse_foe(x, y, team_id);
  70. }