Newer
Older
var startup_path='.';
try { throw new Error() } catch(e) { startup_path=e.fileName }
startup_path=startup_path.replace(/[\/\\][^\/\\]*$/,'');
startup_path=backslash(startup_path);
load("recordfile.js");
load("lockfile.js");
load(startup_path+"filename.js");
load(fname("gamesettings.js"));
var Settings=new GameSettings();
load(fname("structs.js"));
var on_at=time();
var i;
var Commodities=[
{
name:"Ore"
,abbr:"Ore"
,disp:"Ore......."
,price:10
}
,{
name:"Organics"
,abbr:"Org"
,disp:"Organics.."
,price:20
}
,{
name:"Equipment"
,abbr:"Equ"
,disp:"Equipment."
,price:35
}
];
var sectors=new RecordFile(fname("sectors.dat"), SectorProperties);
var ports=new RecordFile(fname("ports.dat"), PortProperties);
var players=new RecordFile(fname("players.dat"), PlayerProperties);
var playerLocation=new RecordFile(fname("player-loc.dat"), PlayerLocation);
var teams=new RecordFile(fname("teams.dat"), TeamProperties);
var planets=new RecordFile(fname("planets.dat"), PlanetProperties);
var twmsg=new File(fname("twmesg.dat"));
var twopeng=new File(fname("twopeng.dat"));
twopeng.open("a", true);
twmsg.open("a", true);
var twpmsg=new RecordFile(fname("twpmesg.dat"), PlayerMessageProperties);
var twrmsg=new RecordFile(fname("twrmesg.dat"), RadioMessageProperties);
var cabals=new RecordFile(fname("cabal.dat"), CabalProperties);
var today=system.datestr(system.datestr());
js.on_exit("do_exit()");
/* Run maintenance */
if(Settings.MaintLastRan != system.datestr()) {
Settings.MaintLastRan = system.datestr();
Settings.save();
console.attributes="Y";
console.writeln("Running maintence program...");
console.crlf();
console.crlf();
console.writeln("Trade Wars maintence program");
console.writeln(" by Chris Sherrick (PTL)");
console.crlf();
console.writeln("This program is run once per day.");
twmsg.writeln(system.timestr()+": "+user.alias+": Maintence program ran");
console.writeln("Deleting inactive players");
var oldest_allowed=today-Settings.DaysInactivity*86400;
for(i=1; i<players.length; i++) {
var p=players.Get(i);
if(p.UserNumber > 0) {
if((!file_exists(system.data_dir+format("user/%04d.tw2",p.UserNumber))) || (system.datestr(p.LastOnDay) < oldest_allowed && p.KilledBy != 0)) {
DeletePlayer(p)
}
}
}
console.crlf();
MoveCabal();
RankPlayers();
}
console.attributes="C";
console.crlf();
console.crlf();
console.center("Trade Wars (v.ii)");
console.center("By Chris Sherrick (PTL)");
console.center("Copyright 1986 Chris Sherrick");
console.crlf();
console.center(system.name);
console.center("Sysop "+system.operator);
console.crlf();
console.crlf();
console.printfile(fname("twopeng.asc"));
if(file_exists(fname("twopeng.dat")))
console.printfile(fname("twopeng.dat"));
console.crlf();
console.attributes="W";
console.writeln("Initializing...");
console.writeln("Searching my records for your name.");
var player;
var firstnew;
for(i=1; i<players.length; i++) {
player=players.Get(i);
if(player.UserNumber == user.number && (!file_exists(system.data_dir+format("user/%04d.tw2",player.UserNumber))))
DeletePlayer(player);
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
if(player.UserNumber==0 && firstnew==undefined)
firstnew=player;
if(player.UserNumber == user.number)
break;
}
if(player==undefined || player.UserNumber!=user.number) {
console.attributes="G";
console.writeln("I can't find your record, so I am assuming you are a new player.");
console.attributes="M";
console.writeln("Entering a new player...");
player=firstnew;
if(player==undefined) {
console.writeln("I'm sorry but the game is full.");
console.writeln("Please leave a message for the Sysop so");
console.writeln("he can save a space for you when one opens up.");
twmsg.writeln(system.timestr()+": New player not allowed - game full.");
exit(0);
}
console.crlf();
console.writeln("Notice: If you don't play this game for "+Settings.DaysInactivity+" days, you will");
console.writeln("be deleted to make room for someone else.");
console.crlf();
console.writeln("Your ship is being initialized.");
/* Lock the player file and mark us online... */
if(!Lock(players.file.name, bbs.node_num, true, 10)) {
console.writeln("!!!Unable to lock player data!");
twmsg.writeln("!!!Unable to lock player data!");
exit(1);
}
player.ReInit();
player.Online=true;
player.Put();
Unlock(players.file.name);
twmsg.writeln(system.timestr()+" "+user.alias+": New Player logged on");
Instructions();
}
else {
/* Lock the player file and mark us online... */
if(!Lock(players.file.name, bbs.node_num, true, 10)) {
console.writeln("!!!Unable to lock player data!");
twmsg.writeln("!!!Unable to lock player data!");
exit(1);
}
player.Online=true;
player.Put();
Unlock(players.file.name);
console.crlf(); /* TODO: BASIC magic... N$ appears empty tw2.bas: 242 */
twmsg.writeln(system.timestr()+" "+user.alias+": Logged on");
if(today < system.datestr(player.LastOnDay)) {
console.writeln("I'm sorry, but you won't be allowed on for another " + parseInt((system.datestr(player.LastOnDay)-today)/86400) + " day(s)");
exit(0);
}
if(today==system.datestr(player.LastOnDay)) {
if(player.KilledBy != -99) {
console.writeln("You have been on today.");
if(player.TurnsLeft<1) {
console.writeln("You don't have any turns left today. You will be allowed to play tomorrow.");
exit(0);
}
if(player.KilledBy==player.Record) {
console.writeln("You killed yourself today. You will be allowed to play tomorrow.");
exit(0);
}
console.writeln("The following happened to your ship since your last time on:");
var count=0;
for(i=0; i<twpmsg.length; i++) {
var msg=twpmsg.Get(i);
if(msg.To==player.Record && !msg.Read) {
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
count++;
if(msg.From==-98)
console.writeln("A deleted player destroyed "+msg.Destroyed+" fighters.");
else if(msg.From==-1) {
console.attributes="R";
console.writeln("The Cabal destroyed "+msg.Destroyed+" fighters.");
}
else {
var otherplayer=players.Get(msg.From);
console.writeln(otherplayer.Alias+" "+(otherplayer.TeamNumber?" Team["+otherplayer.TeamNumber+"] ":"")+"destroyed "+msg.Destroyed+" of your fighters.");
}
msg.Read=true;
msg.Put();
}
}
if(count==0)
console.writeln("Nothing");
}
}
else {
player.TurnsLeft=Settings.TurnsPerDay;
}
player.LastOnDay=system.datestr();
if(player.KilledBy != 0) {
switch(player.KilledBy) {
case player.Record:
console.attributes="R";
console.writeln("You managed to kill yourself on your last time on.");
break;
case -1:
console.attributes="R";
console.writeln("You have been killed by the Cabal!");
break;
case -98:
console.writeln("You have been killed by a deleted player.");
break;
default:
var otherplayer=players.Get(player.KilledBy);
console.writeln(otherplayer.Alias+" destroyed your ship!");
break;
}
player.ReInit();
}
}
file_touch(system.data_dir+format("user/%04d.tw2",player.UserNumber))
ReadRadio();
if(player.Sector < 1 || player.Sector >= sectors.length) {
console.writeln("You are being moved to sector 1");
player.Sector=1;
}
location=playerLocation.Get(player.Record);
location.Sector=player.Sector;
location.Put();
if(player.Credits > 25000) {
console.crlf();
console.writeln("Tax time! You are being taxed 5000 credits to help support the resistance");
console.writeln("against the evil Cabal.");
player.Credits -= 5000;
}
var exit_tw2=false;
while(player.KilledBy==0 && exit_tw2==false) {
if(EnterSector()) {
if(CheckSector())
Menu();
}
}
function Menu()
{
/* 22000 */
while(1) {
console.crlf();
console.write("Command (?=Help)? ");
var valid=new Array('A','C','D',/*'E' TODO: Editor ,*/'F','G','I','L','M','P','Q','T','Z','?');
var sector=sectors.Get(player.Sector);
var i;
for(i=0; i<sector.Warps.length; i++) {
if(sector.Warps[i]>0)
valid.push(sector.Warps[i].toString());
}
var inp=InputFunc(valid)
switch(inp) {
case '':
console.writeln("? = Help");
break;
case 'A':
/* 25000 */
console.writeln("<Attack>");
var count=0;
var i;
if(player.Fighters < 1) {
console.writeln("You don't have any fighters.");
break;
}
for(i=1;i<players.length; i++) {
var otherloc=playerLocation.Get(i);
var otherplayer=players.Get(i);
if(otherplayer.Sector==player.Sector
&& otherplayer.Record!=player.Record
&& otherplayer.KilledBy!=0
&& otherplayer.UserNumber!=0
&& !otherplayer.Online) {
count++;
console.write("Attack "+otherplayer.Alias+" (Y/N)[Y]? ");
if(GetKeyEcho()!='N') {
console.writeln("<Yes>");
break;
}
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
}
}
otherplayer=null;
}
if(otherplayer!=null) {
DoBattle(otherplayer, otherplayer.TeamNumber > 0);
if(otherplayer.Fighters==0) {
KilledBy(otherplayer, player, true);
/* 15600 player salvages ship from otherplayer */
var salvaged=parseInt(otherplayer.Holds/4)+1;
if(player.Holds + salvaged > 50)
salvaged=50-player.Holds;
if(salvaged < 1)
console.writeln("You destroyed the ship, but you can't salvage anything from it");
else {
var j;
console.writeln("You destroyed the ship and salvaged these cargo holds:");
var holds=new Array(Commodities.length+1);
for(i=0; i<holds.length+1; i++)
holds[i]=0;
for(i=0; i<otherplayer.Holds; i++) {
var limit=0;
var r=random(otherplayer.Holds)+1;
for(j=0; j<Commodities.length; j++) {
limit += otherplayer.Commodities[j];
if(r<limit) {
otherplayer.Commodities[j]--;
holds[j]++;
r=0;
break;
}
}
if(r==0)
holds[Commodities.length]++;
}
if(holds[Commodities.length]>0) {
console.writeln(" "+holds[Commodities.length]+" empty.");
player.Holds+=holds[Commodities.length];
}
for(j=0; j<Commodities.length; j++) {
if(holds[j]>0) {
console.writeln(" "+holds[j]+" with "+Commodities[j].name.toLowerCase()+".");
player.Holds+=holds[j];
player.Commodities[j]+=holds[j];
}
}
}
}
}
else {
if(count)
console.writeln("There are no other ships in here");
else
console.writeln("There are no ships here to attack.");
}
break;
case 'C':
/* 33640 */
console.writeln("<Computer>");
console.crlf();
console.writeln("<Computer activated>");
var showhelp=true;
var exitcomputer=false;
while(!exitcomputer) {
if(showhelp) {
console.crlf();
console.printfile(fname("computer.asc"));
console.write("Computer command (?=help)? ");
switch(InputFunc(['?','1','2','3','4','5'])) {
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
case '?':
showhelp=true;
break;
case '1':
/* 33990 */
console.crlf();
console.attributes="Y";
console.writeln("<Computer deactivated>");
exitcomputer=true;
break;
case '2':
/* 33780 */
console.write("What sector number is the port in? ");
var sec=console.getnum(sectors.length-1);
if(sec > 0 && sec < sectors.length) {
var sector=sectors.Get(sec);
if(sector.Port==0 || (sector.Fighters>0 && sector.Fighters!=player.Record)) {
console.crlf();
console.writeln("I have no information about that port.");
break;
}
if(sec==1) {
SolReport();
}
else {
PortReport(sector);
}
}
break;
case '3':
/* 33830 */
console.write("What sector do you want to get to? ");
var sec=console.getnum(sectors.length-1);
if(sec > 0 && sec < sectors.length) {
if(sec==player.Sector) {
console.writeln("You are in that sector.");
break;
}
console.crlf();
console.writeln("Computing shortest path.");
var path=ShortestPath(player.Sector, sec);
if(path==null) {
console.writeln("There was an error in computation between sectors.");
}
else {
console.writeln("The shortest path from sector "+player.Sector+" to sector "+sec+" is:");
var i;
for(i in path) {
if(i!=0)
console.write(" - ");
console.write(path[i]);
}
}
}
break;
case '4':
/* 33900 */
console.crlf();
console.write("Ranking Players.");
var ranked=RankPlayers();
console.crlf();
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
console.writeln("Player Rankings: "+system.timestr());
console.writeln("Rank Value Team Player");
console.writeln("==== ============= ====== ======")
for(rank in ranked) {
var p=players.Get(ranked[rank].Record);
console.writeln(format("%4d %13d %-6s %s"
,rank+1
,ranked[rank].Score
,p.TeamNumber==0?"":format(" %-2d "
,p.TeamNumber),p.Alias));
}
break;
case '5':
/* 33960 */
console.crlf();
console.writeln("Warming up sub-space radio.");
mswait(500);
console.crlf();
console.write("Who do you wish to send this message to (search string)? ");
var sendto=console.getstr(42);
var p=MatchPlayer(sendto);
if(p==null)
break;
console.writeln("Tuning in to " + p.Alias + "'s frequency.");
console.crlf();
console.writeln("Due to the distances involved, messages are limited to 74 chars.");
console.writeln("Pressing [ENTER] with no input quits");
console.writeln(" [------------------------------------------------------------------------]");
var msg=console.getstr(74);
if(msg==null)
break;
msg=msg.replace(/\s*$/,'');
if(msg=='')
break;
RadioMessage(player.Record, p.Record, msg);
break;
default:
console.crlf();
console.writeln("Invalid command. Enter ? for help");
}
}
break;
case 'D':
console.writeln("<Display>");
DisplaySector(player.Sector);
break;
// case 'E':
// /* TODO: 22800 */
// if(user.level < 90)
// break;
// console.writeln("<TW Editor>");
// console.write("Do you wish to use the editor? Y/N [N] ");
// switch(GetKeyEcho()) {
// case 'Y':
// console.writeln("Running Tradewars ][ Editor...");
// /* TODO: TWEdit */
// }
// break;
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
case 'F':
/* 24000 */
console.writeln("<Drop/Take Fighters>");
if(player.Sector < 8) {
console.writeln("You can't leave fighters in the Union (sectors 1-7)");
break;
}
var sector=sectors.Get(player.Sector);
if(sector.Fighters > 0 && sector.FighterOwner != player.Record) {
console.writeln("There are already fighters in this sector!");
break;
}
console.writeln("You have " + (player.Fighters+sector.Fighters) + " fighters available.");
console.write("How many fighters do you want defending this sector? ");
var newf=player.Fighters+sector.Fighters;
if(newf > 9999)
newf=9999;
var newf=console.getnum(newf);
if(newf >= 0 && newf <=player.Fighters+sector.Fighters) {
if((player.Fighters+sector.Fighters)-newf > 9999) {
console.writeln("Too many ships in your fleet! You are limited to 9999");
break;
}
player.Fighters=(player.Fighters+sector.Fighters)-newf;
sector.Fighters=newf;
if(sector.Fighters > 0)
sector.FighterOwner=player.Record;
sector.Put();
player.Put();
console.writeln("Done. You have " + player.Fighters + " fighter(s) in your fleet.");
}
break;
case 'G':
/* 27500 */
console.writeln("<Gamble>");
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
console.writeln("You have "+player.Credits+" credits.");
console.writeln("How much do you want to gamble at double or nothing (50-50 odds)");
console.write("[0]? ");
var gamble=console.getnum(player.Credits > 99999?99999:player.Credits);
if(gamble > 0 && gamble <=player.Credits) {
console.write("Flipping the coin...");
mswait(250);
if(random(2)==1) {
console.crlf();
player.Credits-=gamble;
console.writeln("Sorry, you lost.");
}
else {
console.crlf();
player.Credits+=gamble;
console.writeln("You won!");
}
player.Put();
console.writeln("You now have "+player.Credits+" credits.");
}
break;
case 'I':
console.writeln("<Info>");
PlayerInfo(player.Record);
break;
case 'L':
/* 31000 */
console.writeln("<Land/Create planet>");
console.crlf();
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
console.writeln("Landing...");
var sector=sectors.Get(player.Sector);
var planet=null;
if(sector.Planet==0) {
/* TODO: Race condition? */
CreatePlanet(sector);
}
else {
/* 32310 */
/* Lock the planet file and ensure we can land... */
if(!Lock(planets.file.name, bbs.node_num, true, 5)) {
console.writeln("The spaceport is busy. Try again later.");
break;
}
planet=planets.Get(sector.Planet);
if(planet.OccupiedBy != 0) {
console.writeln("The spaceport is busy. Try again later.");
Unlock(planets.file.name);
break;
}
planet.OccupiedBy=player.Record;
planet.Put();
Unlock(ports.file.name);
player.Landed=true;
player.Put();
Production(planet);
PlanetReport(planet);
PlanetMenu(planet);
if(!Lock(planets.file.name, bbs.node_num, true, 10))
twmsg.writeln("!!! Error locking ports file!");
planet.OccupiedBy=0;
planet.Put();
Unlock(planets.file.name);
player.Landed=false;
player.Put();
}
break;
case 'M':
/* 23000 */
console.writeln("<Move>");
if(player.TurnsLeft < 1) {
console.writeln("I'm sorry but you don't have any turns left.");
break;
}
console.write("Warps lead to: ");
var sector=sectors.Get(player.Sector);
var i;
var count=0;
for(i=0; i<sector.Warps.length; i++) {
if(sector.Warps[i]>0) {
if(count>0)
console.write(", ");
console.write(sector.Warps[i]);
count++;
}
}
console.crlf();
console.write("To which sector? ");
var to=console.getnum(sectors.length-1);
if(MoveTo(to))
return;
break;
case 'P':
console.writeln("<Port>");
console.crlf();
console.writeln("Docking...");
if(player.TurnsLeft<1) {
console.writeln("Sorry, but you don't have any turns left.");
break;
}
var sector=sectors.Get(player.Sector);
if(sector.Port<1) {
console.writeln("There are no ports in this sector.");
break;
}
player.TurnsLeft--;
player.Ported=true;
player.Put();
console.writeln("One turn deducted");
if(player.Sector==1) {
/* 33200 */
var prices=SolReport();
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
console.writeln("You have " + player.Credits + " credits.");
console.crlf();
/* Holds */
var maxbuy=parseInt(player.Credits/prices[0]);
if(player.Holds+maxbuy>50)
maxbuy=50-player.Holds;
if(maxbuy > 0) {
console.write("How many holds do you want to buy [0]? ");
var buy=console.getnum(maxbuy);
if(buy>0) {
player.Holds+=buy;
player.Credits -= buy*prices[0];
player.Put();
console.writeln("You have " + player.Credits + " credits.");
}
}
/* Fighters */
var maxbuy=parseInt(player.Credits/prices[1]);
if(player.Fighters+maxbuy>9999)
maxbuy=9999-player.Fighters;
if(maxbuy > 0) {
console.write("How many fighters do you want to buy [0]? ");
var buy=console.getnum(maxbuy);
if(buy>0) {
player.Fighters+=buy;
player.Credits -= buy*prices[1];
player.Put();
console.writeln("You have " + player.Credits + " credits.");
}
}
/* Turns */
var maxbuy=parseInt(player.Credits/prices[2]);
if(maxbuy > 0) {
console.write("How many turns do you want to buy [0]? ");
var buy=console.getnum(maxbuy);
if(buy>0) {
player.TurnsLeft+=buy;
player.Credits -= buy*prices[2];
player.Put();
console.writeln("You have " + player.Credits + " credits.");
}
}
}
else {
var sector=sectors.Get(player.Sector);
/* Lock the port file and ensure we can dock... */
if(!Lock(ports.file.name, bbs.node_num, true, 5)) {
console.writeln("The port is busy. Try again later.");
break;
}
var port=ports.Get(sector.Port);
if(port.OccupiedBy != 0) {
console.writeln("The port is busy. Try again later.");
Unlock(ports.file.name);
break;
}
port.OccupiedBy=player.Record;
port.Put();
Unlock(ports.file.name);
Production(port);
var sale=PortReport(sector);
var count=0;
console.writeln();
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
/* Sell... */
for(i=0; i<Commodities.length; i++) {
if(sale[i].Vary < 0) {
var amount=Transact(i, sale[i].Price, sale[i].Vary, sale[i].Number);
if(amount >= 0) {
count++;
port.Commodities[i] += amount;
port.Put();
}
}
}
/* Buy... */
for(i=0; i<Commodities.length; i++) {
if(sale[i].Vary > 0) {
var amount=Transact(i, sale[i].Price, sale[i].Vary, sale[i].Number);
if(amount >= 0) {
count++;
port.Commodities[i] -= amount;
port.Put();
}
}
}
if(count==0) {
console.attributes="IC";
console.writeln("You don't have anything they want, and they don't have anything you can buy");
console.attributes="C";
}
if(!Lock(ports.file.name, bbs.node_num, true, 10))
twmsg.writeln("!!! Error locking ports file!");
port.OccupiedBy=0;
port.Put();
Unlock(ports.file.name);
}
player.Ported=false;
player.Put();
break;
case 'T':
/* 32799 */
console.writeln("<Team menu>");
TeamMenu();
break;
case '?':
console.attributes="C";
console.writeln("<Help>");
console.crlf();
console.printfile(fname("main.asc"));
break;
case 'Z':
console.writeln("<Instructions>");
Instructions();
break;
case 'Q':
console.attributes="W";
console.writeln("<Quit>");
console.attributes="W";
console.write("Are you sure (Y/N)? ");
if(console.getkeys("YN")=='Y') {
exit_tw2=true;
return;
}
break;
default:
if(inp.search(/^[0-9]*$/)!=-1) {
if(MoveTo(parseInt(inp)))
return;
}
break;
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
}
}
}
function CheckSector()
{
if(player.Sector==85) {
console.crlf();
console.attributes="W";
console.writeln("Congratulations! You've defeated the cabal and gained 100,000 points!");
player.Points += 100000;
player.Put();
console.writeln("Unfortunately, victory is fleeting...");
var sector=sectors.Get(85);
sector.Fighters=3000;
sector.FighterOwner=-1;
sector.Put();
twopeng.writeln("Congratulations go to "+player.Alias+
" who invaded the Cabal empire on " + system.datestr() +
" and received 100,000 points!");
return(false);
}
return(true);
}
function EnterSector() /* 20000 */
{
var sector=sectors.Get(player.Sector);
var fighterteam=-1;
console.attributes="Y";
DisplaySector(sector.Record);
if(sector.FighterOwner > 0) {
var otherplayer=players.Get(sector.FighterOwner);
if(otherplayer.TeamNumber > 0)
fighterteam=otherplayer.TeamNumber;
}
while(sector.FighterOwner != player.Record && sector.Fighters > 0 && fighterteam != player.TeamNumber) {
console.writeln("You have to destroy the fighters before you can enter this sector.");
console.writeln("Fighters: "+player.Fighters+" / "+sector.Fighters);
console.write("Option? (A,D,I,Q,R,?):? ");
switch(InputFunc(['A','D','I','Q','R','?'])) {
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
case 'A':
console.writeln("<Attack>");
var otherteam=false;
if(sector.FighterOwner > 0) {
var otherplayer=players.Get(sector.FighterOwner);
if(otherplayer.TeamNumber>0)
otherteam-true;
}
var killed=DoBattle(sector, otherteam);
if(killed > 0) {
player.Points+=k*100;
console.writeln("You just recieved "+(k*100)+" points for that.");
}
if(sector.Fighters==0)
console.writeln("You destroyed all the fighters.");
break;
case 'D':
console.writeln("<Display>");
DisplaySector(player.Sector);
break;
case 'I':
console.writeln("<Info>");
PlayerInfo(player.Record);
break;
case 'Q':
console.write("Are you sure (Y/N)? ");
if(console.getkeys("YN")=='Y') {
exit_tw2=true;
return(false);
}
break;
case 'R':
console.writeln("<Retreat>");
if(player.LastIn<1 || player.LastIn>=sectors.length)
player.LastIn=random(sectors.length-1)+1;
if(player.Fighters<1) {
if(random(2)==1) {
console.writeln("You escaped!");
player.Sector=player.LastIn;
player.Put();
location.Sector=player.Sector; location.Put();
return(false);
}
console.attributes="R";
console.writeln("You didn't escape!");
console.writeln("Your ship has been destroyed!");
console.crlf();
console.attributes="R";
console.writeln("You will start over tomorrow with a new ship.");
KilledBy(player, player, true);
return(false);
}
else {
player.Fighters--;
console.writeln("You have "+player.Fighters+" fighter(s) left.");
player.Sector=player.LastIn;
player.Put();
location.Sector=player.Sector; location.Put();
return(false);
}
break;
case '':
console.writeln("?=<Help>");
break;
case '?':
console.writeln("<Help>");
console.crlf();
console.printfile(fname("entersector.asc"));
break;
default:
console.crlf();
console.writeln("Invalid command. ? = Help");
}
}
return(true);
}
function PlayerInfo(num)
{
var p=players.Get(num);
console.attributes="HW";
console.write(" Pilot's Name: "+p.Alias);
if(p.PlayerNumber>0)
console.write(" Team ["+p.TeamNumber+"]");
console.crlf();
console.attributes="HG";
console.writeln("Sector Location: "+p.Sector);
console.writeln(" Turns left: "+p.TurnsLeft);
console.writeln(" Cargo Holds: "+p.Holds);
console.attributes="HR";
var i;
for(i=0; i<Commodities.length; i++)
console.writeln(" # with "+Commodities[i].abbr+": "+p.Commodities[i]+" ");
console.attributes="HM";
console.writeln(" Credits: "+p.Credits);
console.writeln(" Door points: "+p.Points);
}
function DisplaySector(secnum)
{
var sector=sectors.Get(secnum);
var i;
var count=0;
console.crlf();
console.attributes="HY";
console.writeln("Sector "+secnum);
console.attributes="HR";
console.write("Port ");
if(sector.Port > 0) {
var port=ports.Get(sector.Port);
console.write(port.Name+", class "+port.Class)
}
else
console.write("None");
console.crlf();
if(sector.Planet) {
var planet=planets.Get(sector.Planet);
console.attributes="HC";
console.writeln("Other Ships");
console.attributes="C";
for(i=1;i<players.length;i++) {
var otherloc=playerLocation.Get(i);
if(otherloc.Sector==secnum) {
var otherplayer=players.Get(i);
if(otherplayer.UserNumber > 0 && otherplayer.Sector==secnum) {
if(otherplayer.Record==player.Record)
continue;
if(otherplayer.KilledBy!=0)
continue;
count++;
console.crlf();
console.write(" "+otherplayer.Alias);
if(otherplayer.TeamNumber>0)
console.write(" Team ["+otherplayer.TeamNumber+"]");
console.write(" with "+otherplayer.Fighters+" fighters");
if(otherplayer.Landed)
console.write(" (on planet)");
else if(otherplayer.Ported)
console.write(" (docked)");
else if(otherplayer.Online)
console.write(" (online)");
}
}
}
if(count==0)
console.attributes="HG";
console.writeln("Fighters defending sector");
console.attributes="G";
if(sector.Fighters==0)
if(sector.FighterOwner<0)
console.writeln(" (Cabal)");
else if(sector.FighterOwner==player.Record)
console.writeln(" (yours)");
else {
var otherplayer=players.Get(sector.FighterOwner);
console.write(" (belong to "+otherplayer.Alias);
if(otherplayer.TeamNumber)