OU_VEHI.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OU_VEHI.CPP
  21. //Description : Unit Vehicle
  22. #include <OWORLD.h>
  23. #include <OUNITRES.h>
  24. #include <OU_VEHI.h>
  25. //--------- Begin of function UnitVehicle::set_combat_level ---------//
  26. //
  27. void UnitVehicle::set_combat_level(int combatLevel)
  28. {
  29. skill.combat_level = combatLevel;
  30. UnitInfo* unitInfo = unit_res[unit_id];
  31. max_hit_points = unit_res[unitInfo->vehicle_id]->hit_points +
  32. unit_res[unitInfo->solider_id]->hit_points * combatLevel / 100;
  33. hit_points = min(hit_points, max_hit_points);
  34. }
  35. //-------- End of function UnitVehicle::set_combat_level -----------//
  36. //--------- Begin of function UnitVehicle::dismount ---------//
  37. //
  38. // The solider unit dismount from the vehicle.
  39. //
  40. // This unit is decomposed into two units: the solider and the vehicle.
  41. //
  42. void UnitVehicle::dismount()
  43. {
  44. err_when( !unit_res[unit_id]->solider_id );
  45. UnitInfo* unitInfo = unit_res[unit_id];
  46. SpriteInfo* soliderSpriteInfo = sprite_res[ unit_res[unitInfo->solider_id]->sprite_id ];
  47. //--- calc the hit points of the solider and the vehicle after deforming ---//
  48. float soliderHitPoints = hit_points * solider_hit_points / (solider_hit_points+vehicle_hit_points);
  49. float vehicleHitPoints = hit_points * vehicle_hit_points / (solider_hit_points+vehicle_hit_points);
  50. soliderHitPoints = max(1, soliderHitPoints);
  51. vehicleHitPoints = max(1, vehicleHitPoints);
  52. //-------- add the solider unit ---------//
  53. //---- look for an empty location for the unit to stand ----//
  54. int xLoc=next_x_loc(), yLoc=next_y_loc();
  55. if( !world.locate_space( xLoc, yLoc, xLoc+sprite_info->loc_width-1,
  56. yLoc+sprite_info->loc_height-1, soliderSpriteInfo->loc_width, soliderSpriteInfo->loc_height ) )
  57. {
  58. return;
  59. }
  60. int unitRecno = unit_array.add_unit(unitInfo->solider_id, nation_recno,
  61. rank_id, loyalty, xLoc, yLoc);
  62. Unit* unitPtr = unit_array[unitRecno];
  63. unitPtr->skill = skill;
  64. unitPtr->set_combat_level(skill.combat_level);
  65. unitPtr->hit_points = soliderHitPoints;
  66. //-------- delete current unit ----------//
  67. int curXLoc = next_x_loc(), curYLoc = next_y_loc();
  68. unit_array.del(sprite_recno); // delete the vehicle (e.g. horse)
  69. //------- add the vehicle unit ----------//
  70. unitRecno = unit_array.add_unit(unitInfo->vehicle_id, 0, 0, 0, curXLoc, curYLoc);
  71. unit_array[unitRecno]->hit_points = vehicleHitPoints;
  72. }
  73. //-------- End of function UnitVehicle::dismount -----------//