home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 July / Disc 2 / PCU0703CD2.iso / entertn / demos / files / ron.exe / scenario / scriptlibrary / tut_lib.bhs
Encoding:
Text File  |  2003-04-29  |  11.6 KB  |  402 lines

  1. /////////////////
  2. //tut_lib.bhs
  3. //Joshua Mitnick
  4. //July 11, 2002
  5. /////////////////
  6.  
  7. /**********************************************************************/
  8. /*Use these descriptions as a template for your own specific scenarios*/
  9. /**********************************************************************/
  10.  
  11. //civil_war_by_percent (1, 2, 50);
  12. //50% of Player 1's military units will switch over to Player 2's team.
  13.  
  14. //civil_war_by_number (1, 2, 4);
  15. //4 of Player 1's military units will switch over to Player 2's team.
  16.  
  17. //city_rebellio (2, "Orleans", 10);
  18. //The city of Orleans and all units and buildings within a 10 tile radius
  19. //will switch to Player 2's team.
  20.  
  21. //all_object_type_selected (Player, "Light Camel");
  22. //Player has selected all of the Light Camels
  23.  
  24. /*****************************************************************/
  25.  
  26. //============================================================
  27. scenario civil_war_by_percent (Empire, Rebels, percent) {
  28.   total_military = num_military_units (Empire);
  29.   amount_of_rebels = (real)total_military * ((real) percent/100.0);
  30.   for (i = 0; i < amount_of_rebels; i ++) {
  31.     Unit_ID = find_military (Empire);
  32.     new_id = switch_teams (Rebels, Empire, Unit_ID);
  33.   }
  34.   return amount_of_rebels;
  35. }
  36. //============================================================
  37.  
  38.  
  39. //============================================================
  40. scenario all_gen_entrench (Player) {
  41.   num_of_generals = num_type (Player, "General");
  42.   for (i = 0; i < num_of_generals; i ++) {
  43.     general_entrench (Player, find_unit (Player, "General"));
  44.   }
  45.   return num_of_generals;
  46. }
  47. //============================================================
  48.  
  49.  
  50. //============================================================
  51. scenario civil_war_by_number (Empire, Rebels, amount_of_rebels) {
  52.   for(i = 0; i < amount_of_rebels; i ++) {
  53.     Unit_ID = find_military (Empire);
  54.     new_id = switch_teams (Rebels, Empire, Unit_ID);
  55.   }
  56. }
  57. //============================================================
  58.  
  59.  
  60. //============================================================
  61. scenario city_rebellion (Rebels, City_Name, Radius) {
  62.   City_ID = find_city_id (City_Name);
  63.   City_Owner = find_city_owner (City_Name);
  64.   City_ID = switch_teams (Rebels, City_Owner, City_ID);
  65.   Counter = 0;
  66.   while (any_object_near_build (City_Owner, 1, Rebels, City_ID, Radius)) {
  67.     if (object_near_build (City_Owner, Counter, Rebels, City_ID, Radius)) {
  68.       new_id = switch_teams (Rebels, City_Owner, Counter);
  69.     }
  70.     Counter ++;
  71.   }
  72. }
  73. //============================================================
  74.  
  75.  
  76. scenario all_object_type_selected (Player, Unit) {
  77.     all_selected = true;
  78.   Repeat_ID = find_unit (Player, Unit);
  79.   Count = 1;
  80.     if (Repeat_ID == -1){
  81.         all_selected = false;
  82.     }
  83.     else{
  84.         while (Repeat_ID != find_unit (Player, Unit)){
  85.             ++ Count;
  86.         }
  87.       if (!object_selected (Player, Repeat_ID)){
  88.           all_selected = false;
  89.       }
  90.         for (UnitCount = 0; UnitCount < Count; ++ UnitCount){
  91.             UnitID = find_unit (Player, Unit);
  92.             if (!object_selected (Player, UnitID)){
  93.                 all_selected = false;
  94.             }    
  95.       }
  96.     }
  97.     return all_selected;
  98. }
  99.  
  100. //============================================================
  101. scenario all_object_type_onscreen_selected (Player, Unit) {
  102.   
  103.   for( i = 0; i < num_type( Player, Unit); i++ ) {
  104.     unit_id = find_unit( Player, Unit );
  105.     unit_x  = object_position_x( Player, unit_id );
  106.     unit_y  = object_position_y( Player, unit_id );
  107.     if( !object_selected( Player, unit_id ) && is_on_screen( unit_x, unit_y) ) {
  108.       return false;
  109.     }
  110.   }
  111.  
  112.   return true;
  113.   
  114.   /*
  115.   all_selected = true;
  116.   Repeat_ID = find_unit (Player, Unit);
  117.   Count = 1;
  118.     if (Repeat_ID == -1){
  119.         all_selected = false;
  120.     }
  121.     else{
  122.         while (Repeat_ID != find_unit (Player, Unit)){
  123.             ++ Count;
  124.         }
  125.       if (!object_selected (Player, Repeat_ID)){
  126.           all_selected = false;
  127.       }
  128.         for (UnitCount = 0; UnitCount < Count; ++ UnitCount){
  129.             UnitID = find_unit (Player, Unit);
  130.             if (!object_selected (Player, UnitID)){
  131.                 all_selected = false;
  132.             }    
  133.       }
  134.     }
  135.     return all_selected;
  136.   */
  137. }
  138.  
  139. //============================================================
  140.  
  141. scenario all_unit_type_near( Player, Type, loc_x, loc_y, distance ) {
  142.   for( object_index = 0; object_index < num_type( Player, Type ); object_index++ ) {
  143.     object_id = find_unit( Player, Type );
  144.     if( !object_near( Player, object_id, loc_x, loc_y, distance ) ) {
  145.       return false;
  146.     }
  147.   }
  148.  
  149.   return true;
  150. }
  151.  
  152. //============================================================
  153.  
  154. scenario all_military_near( Player, loc_x, loc_y, distance ) {
  155.   for( object_index = 0; object_index < num_military_units(Player); object_index++ ) {
  156.     object_id = find_military( Player);
  157.     if( !object_near( Player, object_id, loc_x, loc_y, distance ) ) {
  158.       return false;
  159.     }
  160.   }
  161.  
  162.   return true;
  163. }
  164.  
  165. //============================================================
  166.  
  167. scenario any_unit_type_near( Player, Type, loc_x, loc_y, distance ) {
  168.   for( i = 0; i < num_type( Player, Type ); i++ ) {
  169.     object_id = find_unit( Player, Type );
  170.     if( object_near( Player, object_id, loc_x, loc_y, distance ) ) {
  171.       return true;
  172.     }
  173.   }
  174.  
  175.   return false;
  176. }
  177.  
  178.  
  179. //============================================================
  180. scenario all_military_selected (Player) {
  181.     all_selected = true;
  182.   NumUnits = num_military_units (Player);
  183.     for (Count = 0; Count < NumUnits; Count ++ ){
  184.         UnitID = find_military (Player);
  185.         if (! object_selected (Player,UnitID)){
  186.             all_selected = false;
  187.         }
  188.     }
  189.     return all_selected;
  190. }
  191.  
  192. //============================================================
  193. scenario all_type_active( who, type ) {
  194.   for( i = 0; i < num_type( who, type ); i++ ) {
  195.     unit_id = find_unit( who, type );
  196.     if( is_idle( who, unit_id ) ) {
  197.       return 0;
  198.     }
  199.   }
  200.  
  201.   return 1;
  202. }
  203.  
  204. //============================================================
  205.  
  206. scenario all_type_patrolling( who, type ) {
  207.   for( i = 0; i < num_type( who, type ); i++ ) {
  208.     unit_id = find_all_unit( who, type ) ;
  209.     if( !has_patrol_order( who, unit_id ) ) {
  210.       return 0;
  211.     }
  212.   }
  213.  
  214.   return 1;
  215. }
  216.  
  217. //============================================================
  218.  
  219. scenario all_type_attacking( who, type ) {
  220.   for( i = 0; i < num_type( who, type ); i++ ) {
  221.     unit_id = find_all_unit( who, type ) ;
  222.     if( !has_attack_order( who, unit_id ) ) {
  223.       return 0;
  224.     }
  225.   }
  226.  
  227.   return 1;
  228. }
  229.  
  230. //============================================================
  231. scenario capture_building_type (Captor, Captee, BuildingType, CapturePoint,PostCaptHealth, Message){
  232.   Captured = false;
  233.   FirstID = find_build (Captee, BuildingType);
  234.   LoopID = FirstID;
  235.   NumBuild = num_type (Captee,BuildingType);
  236.   if (LoopID != -1){
  237.     for (Count = 0; Count < NumBuild; ++ Count){
  238.       BuildHealth = object_health (Captee,LoopID);
  239.       if (BuildHealth < CapturePoint){ 
  240.         NewID = switch_teams (Captor,Captee,LoopID);
  241.         set_object_health (Captor,NewID, PostCaptHealth);
  242.         print_game_msg (Message);
  243.         Captured = true;
  244.       }
  245.       LoopID = find_build (Captee,BuildingType);
  246.     }
  247.   }
  248.   return Captured;
  249. }
  250. //============================================================
  251.  
  252.  
  253. //============================================================
  254. scenario capture_building (Captor,Captee,BuildingID, CapturePoint,PostCaptHealth, Message,Captured){
  255.   BuildHealth = object_health (Captee,BuildingID);
  256.   if (BuildHealth < CapturePoint && ! Captured){
  257.     NewID = switch_teams (Captor,Captee,BuildingID);
  258.     set_object_health (Captor,NewID,PostCaptHealth);
  259.     print_game_msg (Message);
  260.     Captured = true;
  261.   }
  262.   return Captured;
  263. }
  264. //============================================================
  265.  
  266. //============================================================
  267. scenario num_object_type_selected (Player, Type) {
  268.   MAX = num_type (Player, Type);
  269.   num = 0;
  270.   for (i = 0; i < MAX; i ++) {
  271.     ID = find_unit (Player, Type);
  272.     if (object_selected (Player, ID)) {
  273.       num ++;
  274.     }
  275.   }
  276.   return num;
  277. }
  278. //============================================================
  279.  
  280. //============================================================
  281. scenario kill_percent_of_military (Player, percent) {
  282.   total_military = num_military_units (Player);
  283.   count = 0;
  284.   for (i = 0; i < (real)total_military * ((real) percent/100.0); i ++) {
  285.     kill_unit (Player, find_military (Player));
  286.     count ++;
  287.   }
  288.   return count;
  289. }
  290. //============================================================
  291.  
  292.  
  293. //============================================================
  294. scenario type_has_target_order (Player, type) {
  295.   has_order = false;
  296.   ID = -1;
  297.   for (i = 0; i < num_type (Player, type); i ++) {
  298.     ID = find_unit (Player, type);
  299.     if (has_target_order (Player, ID)) {
  300.       has_order = true;
  301.     }
  302.   }
  303.   return has_order;
  304. }
  305. //============================================================
  306.  
  307.  
  308. //============================================================
  309. scenario are_any_decoyed (Player) {
  310.   decoyed = false;
  311.   ID = -1;
  312.   for (i = 0; i < num_military_units (Player); i ++) {
  313.     ID = find_military (Player);
  314.     if (is_decoy (Player, ID)){
  315.       decoyed = true;
  316.     }
  317.   }
  318.   return decoyed;
  319. }
  320. //============================================================
  321.  
  322.  
  323. //============================================================
  324. scenario are_any_entrenched (Player) {
  325.   entrenched = false;
  326.   ID = -1;
  327.   for (i = 0; i < num_military_units (Player); i ++) {
  328.     ID = find_military (Player);
  329.     if (is_entrenched (Player, ID)){
  330.       entrenched = true;
  331.     }
  332.   }
  333.   return entrenched;
  334. }
  335. //============================================================
  336.  
  337. //============================================================
  338. scenario city_revolt (Player, city_name){
  339.     city_id = find_city_id(city_name);
  340.     city_owner = find_city_owner(city_name);
  341.     new_city_id = switch_teams (Player, city_owner, city_id);
  342.     set_object_health(Player, new_city_id, 75);
  343.     give_good(Player, "Food", 200);
  344.     give_good(Player, "Wealth", 200);
  345.     give_good(Player, "Metal", 100);
  346.     give_good(Player, "Gold", 200);
  347.     x = object_position_x(Player, new_city_id);
  348.     y = object_position_y(Player, new_city_id);
  349.     unit = rand_int(2, 4);
  350.     create_unit(Player, x, y, "Militia", unit);
  351.     chance = rand_int(0, 1);
  352.     if (chance){
  353.         chance = rand_int(0, 1);
  354.         if (chance){
  355.             unit = rand_int(2, 4);
  356.             create_unit(Player, x, y, "Slingers", unit);
  357.         }
  358.         else {
  359.             unit = rand_int(4, 8);
  360.             create_unit(Player, x, y, "Hoplites", unit);
  361.             create_unit(Player, x, y, "Catapult", 1);
  362.         }
  363.     }
  364. }
  365.  
  366. //============================================================
  367.  
  368. scenario cutscene_begin() {
  369.   ui_hide();
  370.   mouse_selection_disable();
  371.   hotkey_selection_disable();
  372.   scrolling_lock();
  373.   zooming_lock();
  374. }
  375.  
  376. //============================================================
  377.  
  378. scenario cutscene_end() {
  379.   ui_show();
  380.   mouse_selection_enable();
  381.   hotkey_selection_enable();
  382.   scrolling_unlock();
  383.   zooming_unlock();
  384. }
  385.  
  386. //============================================================
  387. /*
  388.   SAMPLE CODE:
  389.   if (FRENCH2 == find_city_owner ("Paris")){
  390.     NumUnits = num_civilian_units (FRENCH1) + num_military_units (FRENCH1);
  391.     for (Count = 0; Count < NumUnits; ++ Count){
  392.       NapX = object_position_x (FRENCH1,NapoleanID);
  393.       NapY = object_position_y (FRENCH1,NapoleanID);
  394.       UnitID = find_unit (FRENCH2,"");
  395.       if (object_near (FRENCH2,UnitID,NapX,NapY,NapRadius)){
  396.         switch_teams (FRENCH1,FRENCH2,UnitID);
  397.       }
  398.     }
  399.   }
  400. */
  401. //============================================================
  402. /*****************************************************************/