pulse.c 2.1 KB

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