home *** CD-ROM | disk | FTP | other *** search
- #include "ext.h"
-
- move_ogre()
- {
- init_move_ogre();
- ogre.moves_left = ogre.movement;
- while (ogre.moves_left > 0)
- {
- move_ogre1();
- ogre_ram();
- cycle();
- }
- }
-
- #define INFINITY 32767
-
- move_ogre1()
- {
- int weight[7];
- int i, max;
- char a, b, olda, oldb;
-
- a = ogre.l_hex;
- b = ogre.r_hex;
-
- weight[0] = - INFINITY;
- weight[1] = getweight(a - 1, b - 1);
- weight[2] = getweight(a - 1, b);
- weight[3] = getweight(a, b + 1);
- weight[4] = getweight(a + 1, b + 1);
- weight[5] = getweight(a + 1, b);
- weight[6] = getweight(a, b - 1);
- max = 0;
- for (i = 1; i < 7; ++i)
- if (weight[i] > weight[max]) max = i;
-
- switch (max)
- {
- case 0:
- break;
- case 1:
- --a;
- --b;
- break;
- case 2:
- --a;
- break;
- case 3:
- ++b;
- break;
- case 4:
- ++a;
- ++b;
- break;
- case 5:
- ++a;
- break;
- case 6:
- --b;
- break;
- }
- olda = ogre.l_hex;
- oldb = ogre.r_hex;
- ogre.l_hex = a;
- ogre.r_hex = b;
- update_hex(olda, oldb);
- disp_ogre();
- ogre.moves_left -= 1;
- }
-
- getweight(a, b)
- char a, b;
- {
- int weight, total_attacks, to_target, i;
-
- weight = - range(a, b, unit[0].l_hex, unit[0].r_hex);
- total_attacks = ogre.missiles + ogre.main_bats + ogre.sec_bats;
-
- for (i = 0; i < n_units; ++i)
- {
- if (unit[i].status == DESTROYED) continue;
- to_target = range(a, b, unit[i].l_hex, unit[i].r_hex);
- if (to_target == 0)
- {
- if (unit[i].type == CP) weight = 50;
- else weight = 10 * unit[i].attack;
- break;
- }
- if (total_attacks <= 0) continue;
- if (to_target <= RANGE_MISSILES && ogre.missiles > 0)
- {
- weight += unit[i].attack;
- weight += 4 - unit[i].movement;
- total_attacks -= 1;
- continue;
- }
-
- if (to_target <= RANGE_MAIN && ogre.main_bats > 0)
- {
- weight += unit[i].attack;
- weight += 4 - unit[i].movement;
- total_attacks -= 1;
- continue;
- }
-
- if (to_target <= RANGE_SECONDARY && ogre.sec_bats > 0)
- {
- weight += unit[i].attack;
- weight += 4 - unit[i].movement;
- total_attacks -= 1;
- continue;
- }
-
- if (to_target <= RANGE_AP && ogre.ap > 0 && unit[i].type == INFANTRY ||
- unit[i].type == CP)
- {
- weight += unit[i].attack;
- weight += 4 - unit[i].movement;
- total_attacks -= 1;
- continue;
- }
- }
-
- if (off_map(a, b) || blocked(a, b)) weight = - INFINITY;
-
- return(weight);
- }
-
- #define INCR(i) i = (i == n_units - 1) ? 0 : i + 1
- #define MIN(a, b) (((a) > (b)) ? (a) : (b))
-
- assign_fire_ogre()
- {
- int i, unitno, nmissiles;
-
- init_ogre_attack();
-
- unitno = nextunit(RANGE_AP, 0);
- for (i = 0; i < ogre.ap; ++i)
- {
- if (unit[unitno].range_to_ogre <= RANGE_AP &&
- (unit[unitno].type == CP || unit[unitno].type == INFANTRY))
- {
- unit[unitno].fired += ATK_AP;
- display_attack("AP", unitno);
- }
- unitno = nextunit(RANGE_AP, unitno);
- }
- unitno = nextunit(RANGE_SECONDARY, unitno);
- for (i = 0; i < ogre.sec_bats; ++i)
- {
- if (unit[unitno].range_to_ogre <= RANGE_SECONDARY)
- {
- unit[unitno].fired += ATK_SECONDARY;
- display_attack("secondary battery", unitno);
- }
- unitno = nextunit(RANGE_SECONDARY, unitno);
- }
-
- unitno = nextunit(RANGE_MAIN, unitno);
- for (i = 0; i < ogre.main_bats; ++i)
- {
- if (unit[unitno].range_to_ogre <= RANGE_MAIN)
- {
- unit[unitno].fired += ATK_MAIN;
- display_attack("main battery", unitno);
- }
- unitno = nextunit(RANGE_MAIN, unitno);
- }
-
- unitno = nextunit(RANGE_MISSILES, unitno);
-
- nmissiles = ogre.missiles;
- for (i = 0; i < nmissiles; ++i)
- {
- if (unit[unitno].status != DESTROYED && unit[unitno].type != INFANTRY
- && unit[unitno].range_to_ogre <= RANGE_MISSILES)
- {
- unit[unitno].fired += ATK_MISSILES;
- ogre.missiles -= 1;
- display_attack("missile", unitno);
- disp_ogre_status(FALSE);
- }
- unitno = nextunit(RANGE_MISSILES, unitno);
- }
- }
-
- cycle()
- {
- Delay(60);
- }
-
- display_attack(weapon, target)
- char *weapon;
- int target;
- {
- char c[80];
-
- if (unit[target].status == DESTROYED) return;
- sprintf(c, "Ogre fires %s at unit at hex %d%d ", weapon,
- unit[target].l_hex, unit[target].r_hex);
- movecur(16, 0);
- Amiga_puts(c);
- movecur_hex(unit[target].l_hex, unit[target].r_hex);
- cycle();
- def_resolve(target);
- }
-
- nextunit(range, unitno)
- int range, unitno;
- {
- int start;
-
- start = unitno;
- INCR(unitno);
- while (unitno != start)
- {
- if (range == 1)
- {
- if (unit[unitno].status != DESTROYED &&
- (unit[unitno].type == CP || unit[unitno].type == INFANTRY) &&
- unit[unitno].range_to_ogre <= range)
- return(unitno);
- }
- else
- {
- if (unit[unitno].status != DESTROYED && unit[unitno].range_to_ogre
- <= range) return(unitno);
- }
- INCR(unitno);
- }
- return(unitno);
- }
-