home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
games
/
bsl.zip
/
S1.SL
next >
Wrap
Text File
|
1989-11-15
|
4KB
|
146 lines
/* s1.sl -- test strategy for begin ----------------------------------------*/
#include "vocab.h"
#define TRUE 1
#define FALSE 0
#define TRY_TACTIC_TURNS 6
declare Enemy; /* Object we are attacking */
declare Main; /* Task ID of our main */
declare Me; /* Our Object */
declare Weapons, Helm, Engineering, Threat, Success, Tactic;
#include "weapons.sl"
#include "tactic.sl"
#include "engine.sl"
#include "helm.sl"
/* ThreatTask -- choose who to attack --------------------------------------*/
/* */
/* Messages understood by main: */
/* */
/*--------------------------------------------------------------------------*/
function ThreatTask()
{
declare Enemy, OldEnemy;
for (;;) {
Enemy = MaxThreat();
if (?Enemy) {
if (!?OldEnemy || Enemy != OldEnemy) {
OldEnemy = Enemy;
send( Main, [NEW_ENEMY, Enemy] );
}
}
else
send(Main, [NO_ENEMY]);
suspend;
}
}
/* SuccessTask -- determine success of current tactics ---------------------*/
function SuccessTask()
{
declare MyHits, HisHits;
declare MyStartHits, HisStartHits;
declare Message;
declare Turn;
declare TryingStrategy;
TryingStrategy = FALSE;
for (;;) {
if (message()) {
Message = receive();
switch (Message[0]) {
case NEW_TACTIC:
Turn = 0;
TryingStrategy = TRUE;
MyStartHits = TotalHits(Me);
HisStartHits = TotalHits(Enemy);
break;
default:
Say(["(SuccessTask) unknown message starting with ", Message[0]]);
break;
}
}
if (TryingStrategy) {
MyHits = TotalHits(Me) - MyStartHits;
HisHits = TotalHits(Enemy) - HisStartHits;
if (++Turn > TRY_TACTIC_TURNS && MyHits > HisHits) {
send(Main, [NOT_WORKING]);
TryingStrategy = FALSE;
}
}
suspend;
}
}
/* main program -- select enemy and kill him -------------------------------*/
/* */
/* Messages understood by main: */
/* */
/* NEW_ENEMY <object> */
/* NO_ENEMY */
/* TRY_NEW_TACTIC */
/* */
/*--------------------------------------------------------------------------*/
function main()
{
declare Message;
Me = ThisObject();
Main = thistask();
Weapons = spawn WeaponsTask();
Helm = spawn HelmTask();
Engineering = spawn EngineeringTask();
Threat = spawn ThreatTask();
Success = spawn SuccessTask();
Tactic = spawn TacticTask();
LoadTorps(350);
send(Weapons, [OPEN_FIRE]);
for (;;) {
Message = receive();
switch (Message[0]) {
case NEW_ENEMY:
Enemy = Message[1];
send(Weapons, [TARGET, Enemy]);
send(Success, [NEW_TACTIC]);
send(Tactic, [NEW_TACTIC]);
break;
case NO_ENEMY:
send(Weapons, [HOLD_FIRE]);
break;
case NOT_WORKING:
send(Tactic, [NEW_TACTIC]);
send(Success, [NEW_TACTIC]);
break;
default:
Say(["(main) unknown message starting with ", Message[0]]);
break;
}
}
}