home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
030.lha
/
Ogre
/
Attack.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-10
|
6KB
|
195 lines
#include "ext.h"
static OGRE allocated;
#define PASS 'p'
#define NOPASS '\0'
#define RESOLVE 'r'
#define MISSILE 'm'
#define MAIN 'b'
#define SECONDARY 's'
#define AP 'a'
#define TREAD 't'
attack_def()
{
char moreunits;
int i;
moreunits = TRUE;
zero(&allocated, sizeof(allocated));
init_def_attack();
while (moreunits)
{
moreunits = FALSE;
for (i = 0; i < n_units; i++)
{
/*
* Don't bother attacking if Ogre is immobile - H.O.
*/
if (ogre.movement == 0)
check_over();
if (unit[i].status == OK && !unit[i].fired &&
unit[i].attack > 0 &&
unit[i].range_to_ogre <= unit[i].range)
{
describe_action("Fire",i);
if (get_target(i) == PASS) moreunits = TRUE;
else unit[i].fired = TRUE;
}
}
}
ogre_resolve(&allocated);
}
get_target(i)
int i;
{
char action, invalid;
movecur_unit(i);
do
{
invalid = FALSE;
action = Amiga_getchar();
switch (action)
{
case PASS:
return(PASS);
case MISSILE:
if (ogre.missiles > 0)
{
allocated.missiles += unit[i].attack;
update_odds(action);
}
else
invalid = TRUE;
break;
case MAIN:
if (ogre.main_bats > 0)
{
allocated.main_bats +=unit[i].attack;
update_odds(action);
}
else
invalid = TRUE;
break;
case SECONDARY:
if (ogre.sec_bats > 0)
{
allocated.sec_bats +=unit[i].attack;
update_odds(action);
}
else
invalid = TRUE;
break;
case AP:
if (ogre.ap > 0)
{
allocated.ap += unit[i].attack;
update_odds(action);
}
else
invalid = TRUE;
break;
case TREAD:
if (ogre.treads > 0)
{
allocated.treads += unit[i].attack;
update_odds(action);
}
else
invalid = TRUE;
if (invalid) break;
ogre_resolve(&allocated);
zero(&allocated,sizeof(allocated));
break;
case RESOLVE:
ogre_resolve(&allocated);
zero(&allocated, sizeof(allocated));
return(PASS);
break;
default:
invalid = TRUE;
break;
}
} while (invalid);
return(NOPASS);
}
zero(area, size)
char *area;
int size;
{
int i;
for (i = 0; i < size; i++) area[i] = '\0';
}
update_odds(weapon)
char weapon;
{
char c[80];
static char blanks[10] = {" "};
char *odd_str();
switch (weapon)
{
case MAIN:
movecur(18, 40);
Amiga_puts(blanks);
movecur(18, 40);
sprintf(c,"%d %d (%s)",allocated.main_bats,
DEF_MAIN, odd_str(allocated.main_bats, DEF_MAIN));
Amiga_puts(c);
break;
case SECONDARY:
movecur(19, 40);
Amiga_puts(blanks);
movecur(19,40);
sprintf(c,"%d %d (%s)",allocated.sec_bats,
DEF_SECONDARY, odd_str(allocated.sec_bats,
DEF_SECONDARY));
Amiga_puts(c);
break;
case MISSILE:
movecur(20, 40);
Amiga_puts(blanks);
movecur(20,40);
sprintf(c,"%s", odd_str(allocated.missiles,
DEF_MISSILES));
Amiga_puts(c);
break;
case AP:
movecur(21, 40);
Amiga_puts(blanks);
movecur(21,40);
sprintf(c,"%s",odd_str(allocated.ap,DEF_AP));
Amiga_puts(c);
break;
case TREAD:
movecur(22, 40);
Amiga_puts(blanks);
movecur(22,40);
sprintf(c,"1/1 (%d) ", allocated.treads);
Amiga_puts(c);
break;
}
}