Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7185 siemargl 1
#include 
2
#include "sst.h"
3
 
4
void prelim(void) {
5
	skip(2);
6
	prout("-SUPER- STAR TREK");
7
	skip(1);
8
	prout("Latest update-21 Sept 78");
9
	skip(1);
10
	prout("Версия перевода от 27 февраля 18");
11
	skip(1);
12
}
13
 
14
void freeze(int boss) {
15
	char *x, *y;
16
	FILE *fp;
17
	int key;
18
	if (boss) {
19
		strcpy(citem, "emsave.trk");
20
	}
21
	else {
22
		if ((key = scan()) == IHEOL) {
23
			/* proutn("File name(9 characters maximum): "); */
24
			proutn("Имя файла(9 символов максимум): ");
25
			key = scan();
26
		}
27
		if (key != IHALPHA) {
28
			huh();
29
			return;
30
		}
31
		chew();
32
		if (strchr(citem, '.') == NULL) {
33
			strcat(citem, ".trk");
34
		}
35
	}
36
	if ((fp = fopen(citem, "wb")) == NULL) {
37
		/* proutn("Can't freeze game as file "); */
38
		proutn("Невозможно сохранить игру в файл ");
39
		proutn(citem);
40
		skip(1);
41
		return;
42
	}
43
	fwrite(&d, sizeof(d), 1, fp);
44
	fwrite(&snapsht, sizeof(snapsht), 1, fp);
45
	fwrite(quad, sizeof(quad), 1, fp);
46
	fwrite(kx, sizeof(kx), 1, fp);
47
	fwrite(ky, sizeof(ky), 1, fp);
48
	fwrite(starch, sizeof(starch), 1, fp);
49
	fwrite(kpower, sizeof(kpower), 1, fp);
50
	fwrite(kdist, sizeof(kdist), 1, fp);
51
	fwrite(kavgd, sizeof(kavgd), 1, fp);
52
	fwrite(damage, sizeof(damage), 1, fp);
53
	fwrite(future, sizeof(future), 1, fp);
54
	fwrite(&a, sizeof(a), 1, fp);
55
	fwrite(passwd, sizeof(passwd), 1, fp);
56
 
57
	fclose(fp);
58
 
59
	/* I hope that's enough! */
60
}
61
 
62
 
63
void thaw(void) {
64
	char *x, *y;
65
	FILE *fp;
66
	int key;
67
 
68
	passwd[0] = '\0';
69
	if ((key = scan()) == IHEOL) {
70
		proutn("Имя файла: ");/*File name*/
71
		key = scan();
72
	}
73
	if (key != IHALPHA) {
74
		huh();
75
		return;
76
	}
77
	chew();
78
	if (strchr(citem, '.') == NULL) {
79
		strcat(citem, ".trk");
80
	}
81
	if ((fp = fopen(citem, "rb")) == NULL) {
82
		proutn("Не могу найти файл ");/*Can't find game file*/
83
		proutn(citem);
84
		skip(1);
85
		return;
86
	}
87
	fread(&d, sizeof(d), 1, fp);
88
	fread(&snapsht, sizeof(snapsht), 1, fp);
89
	fread(quad, sizeof(quad), 1, fp);
90
	fread(kx, sizeof(kx), 1, fp);
91
	fread(ky, sizeof(ky), 1, fp);
92
	fread(starch, sizeof(starch), 1, fp);
93
	fread(kpower, sizeof(kpower), 1, fp);
94
	fread(kdist, sizeof(kdist), 1, fp);
95
	fread(kavgd, sizeof(kavgd), 1, fp);
96
	fread(damage, sizeof(damage), 1, fp);
97
	fread(future, sizeof(future), 1, fp);
98
	fread(&a, sizeof(a), 1, fp);
99
	fread(passwd, sizeof(passwd), 1, fp);
100
 
101
	fclose(fp);
102
 
103
	/* I hope that's enough! */
104
}
105
 
106
void abandn(void) {
107
	int nb, l;
108
 
109
	chew();
110
	if (condit==IHDOCKED) {
111
		if (ship!=IHE) {
112
			/* prout("You cannot abandon Ye Faerie Queene."); */
113
			prout("Вы неможете покинуть Королеву Фей.");
114
			return;
115
		}
116
	}
117
	else {
118
		/* Must take shuttle craft to exit */
119
		if (damage[DSHUTTL]==-1) {
120
			/* prout("Ye Faerie Queene has no shuttle craft."); */
121
			prout("На Королеве Фей отсутствует шаттл.");
122
			return;
123
		}
124
		if (damage[DSHUTTL]<0) {
125
			/* prout("Shuttle craft now serving Big Mac's."); */
126
			prout("Шаттл теперь используется для развозки БигМаков.");
127
			return;
128
		}
129
		if (damage[DSHUTTL]>0) {
130
			/* prout("Shuttle craft damaged."); */
131
			prout("Шаттл поврежден.");
132
			return;
133
		}
134
		if (landed==1) {
135
			/* prout("You must be aboard the Enterprise."); */
136
			prout("Вы должны быть на борту Энтерпрайза.");
137
			return;
138
		}
139
		if (iscraft!=1) {
140
			/* prout("Shuttle craft not currently available."); */
141
			prout("Шаттл в настоящий момент недоступен.");
142
			return;
143
		}
144
		/* Print abandon ship messages */
145
		skip(1);
146
		/* prouts("***ABANDON SHIP!  ABANDON SHIP!"); */
147
		prouts("***ЭВАКУАЦИЯ!  ЭВАКУАЦИЯ!");
148
		skip(1);
149
		/* prouts("***ALL HANDS ABANDON SHIP!"); */
150
		prouts("***ВСЕМ НЕМЕДЛЕННО ПОКИНУТЬ КОРАБЛЬ!");
151
		skip(2);
152
/* 		prout("Captain and crew escape in shuttle craft.");
153
		prout("Remainder of ship's complement beam down");
154
		prout("to nearest habitable planet.");
155
 */		prout("Капитан и экипаж покинули корабль на шаттле.");
156
		prout("Остатки корабля упали на");
157
		prout("близлежащую населенную планету.");
158
		if (d.rembase==0) {
159
			/* Ops! no place to go... */
160
			finish(FABANDN);
161
			return;
162
		}
163
		/* If at least one base left, give 'em the Faerie Queene */
164
		skip(1);
165
		icrystl = 0; /* crystals are lost */
166
		nprobes = 0; /* No probes */
167
/* 		prout("You are captured by Klingons and released to");
168
		prout("the Federation in a prisoner-of-war exchange.");
169
 */		prout("Вы были захвачены клингонами и отправлены");
170
		prout("в Федерацию по программе обмена пленными.");
171
		nb = Rand()*d.rembase+1;
172
		/* Set up quadrant and position FQ adjacient to base */
173
		if (quadx!=d.baseqx[nb] || quady!=d.baseqy[nb]) {
174
			quadx = d.baseqx[nb];
175
			quady = d.baseqy[nb];
176
			sectx = secty = 5;
177
			newqad(1);
178
		}
179
		for (;;) {
180
			/* position next to base by trial and error */
181
			quad[sectx][secty] = IHDOT;
182
			for (l = 1; l <= 10; l++) {
183
				sectx = 3.0*Rand() - 1.0 + basex;
184
				secty = 3.0*Rand() - 1.0 + basey;
185
				if (sectx >= 1 && sectx <= 10 &&
186
					secty >= 1 && secty <= 10 &&
187
					quad[sectx][secty] == IHDOT) break;
188
			}
189
			if (l < 11) break; /* found a spot */
190
			sectx=5;
191
			secty=5;
192
			newqad(1);
193
		}
194
	}
195
	/* Get new commission */
196
	quad[sectx][secty] = ship = IHF;
197
/* 	prout("Starfleet puts you in command of another ship,");
198
	prout("the Faerie Queene, which is antiquated but,");
199
	prout("still useable.");
200
 */	prout("Звездное Командование выдало под Ваше руководство");
201
	prout("Королеву Фей, корабль хоть и устаревший,");
202
	prout("но в неплохом состоянии.");
203
	/* if (icrystl!=0) prout("The dilithium crystals have been moved."); */
204
	if (icrystl!=0) prout("Дилитиевые кристаллы перенесены.");
205
	imine=0;
206
	iscraft=0; /* Gallileo disappears */
207
#ifdef CAPTURE
208
	brigcapacity = 300; // Less capacity now
209
	brigfree = brigcapacity;
210
#endif
211
#ifdef CLOAKING
212
    iscloaked = iscloaking = FALSE;
213
#endif
214
	/* Resupply ship */
215
	condit=IHDOCKED;
216
	for (l = 1; l <= ndevice; l++) damage[l] = 0.0;
217
	damage[DSHUTTL] = -1;
218
	energy = inenrg = 3000.0;
219
	shield = inshld = 1250.0;
220
	torps = intorps = 6;
221
	lsupres=inlsr=3.0;
222
	shldup=0;
223
	warpfac=5.0;
224
	wfacsq=25.0;
225
	return;
226
}
227
 
228
void setup(void) {
229
	int i,j, krem, klumper;
230
	int ix, iy;
231
	alldone = gamewon = 0;
232
#ifdef DEBUG
233
	idebug = 0;
234
#endif
235
	//  Decide how many of everything
236
	if (choose()) return; // frozen game
237
	// Prepare the Enterprise
238
	ship = IHE;
239
	energy = inenrg = 5000.0;
240
	shield = inshld = 2500.0;
241
	shldchg = shldup = 0;
242
	inlsr = 4.0;
243
	lsupres = 4.0;
244
	iran8(&quadx, &quady);
245
	iran10(§x, §y);
246
	torps = intorps = 10;
247
	nprobes = (int)(3.0*Rand() + 2.0);	/* Give them 2-4 of these wonders */
248
	warpfac = 5.0;
249
	wfacsq = warpfac * warpfac;
250
	for (i=0; i <= ndevice; i++) damage[i] = 0.0;
251
	// Set up assorted game parameters
252
	batx = baty = 0;
253
	d.date = indate = 100.0*(int)(31.0*Rand()+20.0);
254
	d.killk = d.killc = nkinks = nhelp = resting = casual = d.nromkl = 0;
255
// Added d.starkl=0 6/2015
256
    isatb = iscate = imine = icrystl = icraft = d.nsckill = d.nplankl = d.starkl = 0;
257
	iscraft = 1;
258
	landed = -1;
259
	alive = 1;
260
	docfac = 0.25;
261
	for (i = 1; i <= 8; i++)
262
		for (j = 1; j <= 8; j++) d.newstuf[i][j] = starch[i][j] = 0;
263
	// Initialize times for extraneous events
264
	future[FSNOVA] = d.date + expran(0.5 * intime);
265
	future[FTBEAM] = d.date + expran(1.5 * (intime / d.remcom));
266
	future[FSNAP] = d.date + 1.0 + Rand(); // Force an early snapshot
267
	future[FBATTAK] = d.date + expran(0.3*intime);
268
	future[FCDBAS] = 1e30;
269
	future[FSCMOVE] = d.nscrem ? d.date+0.2777 : 1e30;
270
	future[FSCDBAS] = 1e30;
271
	future[FDSPROB] = 1e30;
272
	// Starchart is functional
273
	stdamtim = 1e30;
274
	// Put stars in the galaxy
275
	instar = 0;
276
	for (i=1; i<=8; i++)
277
		for (j=1; j<=8; j++) {
278
			int k = Rand()*9.0 + 1.0;
279
			instar += k;
280
			d.galaxy[i][j] = k;
281
		}
282
	// Locate star bases in galaxy
283
	for (i = 1; i <= inbase; i++) {
284
		int contflag;
285
		do {
286
			do iran8(&ix, &iy);
287
			while (d.galaxy[ix][iy] >= 10);
288
			contflag = FALSE;
289
			for (j = i-1; j > 0; j--) {
290
				/* Improved placement algorithm to spread out bases */
291
				double distq = square(ix-d.baseqx[j]) + square(iy-d.baseqy[j]);
292
				if (distq < 6.0*(6-inbase) && Rand() < 0.75) {
293
					contflag = TRUE;
294
#ifdef DEBUG
295
					printf("DEBUG: Abandoning base #%d at %d-%d\n", i, ix, iy);
296
#endif
297
					break;
298
				}
299
#ifdef DEBUG
300
				else if (distq < 6.0 * (6-inbase)) {
301
					printf("DEBUG: saving base #%d, close to #%d\n", i, j);
302
				}
303
#endif
304
			}
305
		} while (contflag);
306
 
307
		d.baseqx[i] = ix;
308
		d.baseqy[i] = iy;
309
		starch[ix][iy] = -1;
310
		d.galaxy[ix][iy] += 10;
311
	}
312
	// Position ordinary Klingon Battle Cruisers
313
	krem = inkling - incom - d.nscrem;
314
	klumper = 0.25*skill*(9.0-length)+1.0;
315
	if (klumper > 9) klumper = 9; // Can't have more than 9 in quadrant
316
	do {
317
		double r = Rand();
318
		int klump = (1.0 - r*r)*klumper;
319
		if (klump > krem) klump = krem;
320
		krem -= klump;
321
		klump *= 100;
322
		do iran8(&ix, &iy);
323
		while (d.galaxy[ix][iy] + klump >= 1000);
324
		d.galaxy[ix][iy] += klump;
325
	} while (krem > 0);
326
	// Position Klingon Commander Ships
327
#ifdef DEBUG
328
	klumper = 1;
329
#endif
330
	for (i = 1; i <= incom; i++) {
331
		do {
332
			do { /* IF debugging, put commanders by bases, always! */
333
#ifdef DEBUG
334
				if (idebug && klumper <= inbase) {
335
					ix = d.baseqx[klumper];
336
					iy = d.baseqy[klumper];
337
					klumper++;
338
				}
339
				else
340
#endif
341
					iran8(&ix, &iy);
342
			}
343
			while ((d.galaxy[ix][iy] < 99 && Rand() < 0.75)||
344
				   d.galaxy[ix][iy]>899);
345
			// check for duplicate
346
			for (j = 1; j < i; j++)
347
				if (d.cx[j]==ix && d.cy[j]==iy) break;
348
		} while (j < i);
349
		d.galaxy[ix][iy] += 100;
350
		d.cx[i] = ix;
351
		d.cy[i] = iy;
352
	}
353
	// Locate planets in galaxy
354
	for (i = 1; i <= inplan; i++) {
355
		do iran8(&ix, &iy);
356
		while (d.newstuf[ix][iy] > 0);
357
		d.newstuf[ix][iy] = 1;
358
		d.plnets[i].x = ix;
359
		d.plnets[i].y = iy;
360
		d.plnets[i].pclass = Rand()*3.0 + 1.0; // Planet class M N or O
361
		d.plnets[i].crystals = 1.5*Rand();		// 1 in 3 chance of crystals
362
		d.plnets[i].known = 0;
363
	}
364
	// Locate Romulans
365
	for (i = 1; i <= d.nromrem; i++) {
366
		iran8(&ix, &iy);
367
		d.newstuf[ix][iy] += 10;
368
	}
369
	// Locate the Super Commander
370
	if (d.nscrem > 0) {
371
		do iran8(&ix, &iy);
372
		while (d.galaxy[ix][iy] >= 900);
373
		d.isx = ix;
374
		d.isy = iy;
375
		d.galaxy[ix][iy] += 100;
376
	}
377
	// Place thing (in tournament game, thingx == -1, don't want one!)
378
	if (Rand() < 0.1 && thingx != -1) {
379
		iran8(&thingx, &thingy);
380
	}
381
	else {
382
		thingx = thingy = 0;
383
	}
384
 
385
//	idate = date;
386
	skip(3);
387
	d.snap = 0;
388
 
389
	if (skill == SNOVICE) {
390
		/* printf("It is stardate %d. The Federation is being attacked by\n", */
391
/* 			   (int)d.date);
392
		printf("a deadly Klingon invasion force. As captain of the United\n"
393
			   "Starship U.S.S. Enterprise, it is your mission to seek out\n"
394
			   "and destroy this invasion force of %d battle cruisers.\n",
395
			   inkling);
396
		printf("You have an initial allotment of %d stardates to complete\n"
397
			   "your mission.  As you proceed you may be given more time.\n\n"
398
			   "You will have %d supporting starbases.\n"
399
			   "Starbase locations-  ",
400
			   (int)intime, inbase);
401
 */		printf("Звездная дата %d. Федерация атакована смертельно опасным\n",
402
			   (int)d.date);
403
		printf("флотом вторжения клингонов. Как капитан корабля Звездного\n"
404
			   "Флота Ю.С.С. Энтерпрайз, ваше задание найти и уничтожить\n"
405
			   "вторгшиеся силы в количестве %d линейных крейсеров.\n",
406
			   inkling);
407
		printf("Вам первоначально отведено %d звездных лет на завершение\n"
408
			   "миссии.  По ходу выполнения время может быть увеличено.\n\n"
409
			   "Также Вы располагаете %d станций поддержки.\n"
410
			   "Местоположение станций-  ",
411
			   (int)intime, inbase);
412
	}
413
	else {
414
/* 		printf("Stardate %d.\n\n"
415
			   "%d Klingons,\nan unknown number of Romulans\n",
416
			   (int)d.date, inkling);
417
		if (d.nscrem) printf("and one (GULP) Super-Commander.\n");
418
		printf("%d stardates\n%d starbases in  ",(int)intime, inbase);
419
 */		printf("Звездная дата %d.\n\n"
420
			   "%d клингонов,\nи неизвестное количество ромуланцев\n",
421
			   (int)d.date, inkling);
422
		if (d.nscrem) printf("и один (черт) СуперКоммандер.\n");
423
		printf("%d звездных лет\n%d станций в точках  ",(int)intime, inbase);
424
	}
425
	for (i = 1; i <= inbase; i++) {
426
		cramlc(0, d.baseqx[i], d.baseqy[i]);
427
		if (i < inbase) proutn("  ");
428
	}
429
	skip(2);
430
	/* proutn("The Enterprise is currently in"); */
431
	proutn("Энтерпрайз находится в точке");
432
	cramlc(1, quadx, quady);
433
	proutn(" ");
434
	cramlc(2, sectx, secty);
435
	skip(2);
436
	/* prout("Good Luck!"); */
437
	prout("Удачи!");
438
	if (d.nscrem) proutn("  ОНА ВАМ ПРИГОДИТСЯ.");/*YOU'LL NEED IT*/
439
	skip(1);
440
	newqad(0);
441
	if (nenhere) shldup=1.0;
442
	if (neutz) attack(0);	// bad luck to start in a Romulan Neutral Zone
443
}
444
 
445
int choose(void) {
446
	tourn = 0;
447
	thawed = 0;
448
	skill = 0;
449
	length = 0;
450
	while (TRUE) {
451
		if (fromcommandline) /* Can start with command line options */
452
			fromcommandline = 0;
453
		else
454
			prout("[Все команды в игре отдаются на английском языке.\n Допустимо сокращать до двух первых букв.]");
455
			/* proutn("Would you like a regular, tournament, or frozen game?"); */
456
			proutn("Вы начинаете обычную(regular), турнирную(tournament), \nили сохраненную(frozen) игру?");
457
		scan();
458
		if (strlen(citem)==0) continue; // Try again
459
		if (isit("tournament")) {
460
			while (scan() == IHEOL) {
461
				/* proutn("Type in tournament number-"); */
462
				proutn("Наберите номер турнира-");
463
			}
464
			if (aaitem == 0) {
465
				chew();
466
				continue; // We don't want a blank entry
467
			}
468
			tourn = (int)aaitem;
469
			thingx = -1;
470
			srand((unsigned int)(int)aaitem);
471
			break;
472
		}
473
		if (isit("frozen")) {
474
			thaw();
475
			chew();
476
			if (*passwd==0) continue;
477
			randomize();
478
			Rand(); Rand(); Rand(); Rand();
479
			if (!alldone) thawed = 1; // No plaque if not finished
480
			report(1);
481
			return TRUE;
482
		}
483
		if (isit("regular")) {
484
			skip(2);
485
			randomize();
486
			Rand(); Rand(); Rand(); Rand();
487
			break;
488
		}
489
		proutn("Что еще за \"");/*What is*/
490
		proutn(citem);
491
		prout("\"?");
492
		chew();
493
	}
494
	while (length==0 || skill==0) {
495
		if (scan() == IHALPHA) {
496
			if (isit("short")) length = 1;
497
			else if (isit("medium")) length = 2;
498
			else if (isit("long")) length = 4;
499
			else if (isit("novice")) skill = SNOVICE;
500
			else if (isit("fair")) skill = SFAIR;
501
			else if (isit("good")) skill = SGOOD;
502
			else if (isit("expert")) skill = SEXPERT;
503
			else if (isit("emeritus")) skill = SEMERITUS;
504
			else {
505
				proutn("Что еще за \"");/*What is*/
506
				proutn(citem);
507
				prout("\"?");
508
			}
509
		}
510
		else {
511
			chew();
512
/* 			if (length==0) proutn("Would you like a Short, Medium, or Long game? ");
513
			else if (skill == 0) proutn("Are you a Novice, Fair, Good, Expert, or Emeritus player?");
514
 */			if (length==0) proutn("Вы предпочитаете короткую (short), среднюю (medium), или длинную(long) игру? ");
515
			else if (skill == 0) proutn("Вы игрок уровня Новичок(novice), Салага(fair), Отличник(good), Эксперт(expert), или Эмеритус(emeritus)?");
516
		}
517
	}
518
	while (TRUE) {
519
		scan();
520
		strcpy(passwd, citem);
521
		chew();
522
		if (*passwd != 0) break;
523
		/* proutn("Please type in a secret password (9 characters maximum)-"); */
524
		proutn("Введите секретный пароль (9 символов максимум)-");
525
	}
526
#ifdef DEBUG
527
	if (strcmp(passwd, "debug")==0) idebug = 1;
528
#endif
529
 
530
	// Use parameters to generate initial values of things
531
	damfac = 0.5 * skill;
532
	d.rembase = 3.0*Rand()+2.0;
533
	inbase = d.rembase;
534
	inplan = (PLNETMAX/2) + (PLNETMAX/2+1)*Rand();
535
	d.nromrem = (2.0+Rand())*skill;
536
	d.nscrem = (skill > SFAIR? 1 : 0);
537
	d.remtime = 7.0 * length;
538
	intime = d.remtime;
539
	d.remkl = 2.0*intime*((skill+1 - 2*Rand())*skill*0.1+.15); // d.remkl and inkling includes commanders and SC
540
	inkling = d.remkl;
541
	incom = skill + 0.0625*inkling*Rand();
542
	d.remcom= min(10, incom);
543
	incom = d.remcom;
544
	d.remres = (inkling+4*incom)*intime;
545
	inresor = d.remres;
546
	if (inkling > 50) {
547
		inbase = (d.rembase += 1);
548
    }
549
#ifdef CAPTURE
550
	brigcapacity = 400;
551
    brigfree = brigcapacity;
552
    kcaptured = 0; // TAA fix 6/2015
553
#endif
554
#ifdef CLOAKING
555
    ncviol = 0; // TAA fix 6/2015
556
    iscloaked = FALSE;
557
    iscloaking = FALSE;
558
#endif
559
	return FALSE;
560
}
561
 
562
void dropin(int iquad, int *ix, int *iy) {
563
	do iran10(ix, iy);
564
	while (quad[*ix][*iy] != IHDOT);
565
	quad[*ix][*iy] = iquad;
566
}
567
 
568
void newcnd(void) {
569
	condit = IHGREEN;
570
	if (energy < 1000.0) condit = IHYELLOW;
571
	if (d.galaxy[quadx][quady] > 99 || d.newstuf[quadx][quady] > 9)
572
		condit = IHRED;
573
}
574
 
575
 
576
void newqad(int shutup) {
577
	int quadnum = d.galaxy[quadx][quady];
578
	int newnum = d.newstuf[quadx][quady];
579
	int i, j, ix, iy, nplan;
580
 
581
	iattak = 1;
582
	justin = 1;
583
	basex = basey = 0;
584
	klhere = 0;
585
	comhere = 0;
586
	plnetx = plnety = 0;
587
	ishere = 0;
588
	irhere = 0;
589
	iplnet = 0;
590
	nenhere = 0;
591
	neutz = 0;
592
	inorbit = 0;
593
	landed = -1;
594
	ientesc = 0;
595
	ithere = 0;
596
    iseenit = 0;
597
 
598
#ifdef CLOAKING
599
    isviolreported = FALSE;
600
#endif
601
	if (iscate) {
602
		// Attempt to escape Super-commander, so tbeam back!
603
		iscate = 0;
604
		ientesc = 1;
605
	}
606
	// Clear quadrant
607
	for (i=1; i <= 10; i++)
608
		for (j=1; j <= 10; j++) quad[i][j] = IHDOT;
609
	// cope with supernova
610
	if (quadnum > 999) {
611
		return;
612
	}
613
	klhere = quadnum/100;
614
	irhere = newnum/10;
615
	nplan = newnum%10;
616
	nenhere = klhere + irhere;
617
 
618
	// Position Starship
619
	quad[sectx][secty] = ship;
620
 
621
	// Decide if quadrant needs a Tholian
622
	if ((skill <  SGOOD && Rand() <= 0.02) ||   /* Lighten up if skill is low */
623
		(skill == SGOOD && Rand() <= 0.05) ||
624
		(skill > SGOOD && Rand() <= 0.08)
625
#ifdef DEBUG
626
		|| strcmp(passwd, "tholianx")==0
627
#endif
628
		) {
629
		do {
630
			ithx = Rand() > 0.5 ? 10 : 1;
631
			ithy = Rand() > 0.5 ? 10 : 1;
632
		} while (quad[ithx][ithy] != IHDOT);
633
		quad[ithx][ithy] = IHT;
634
		ithere = 1;
635
		/* Reserve unocupied corners */
636
		if (quad[1][1]==IHDOT) quad[1][1] = 'X';
637
		if (quad[1][10]==IHDOT) quad[1][10] = 'X';
638
		if (quad[10][1]==IHDOT) quad[10][1] = 'X';
639
		if (quad[10][10]==IHDOT) quad[10][10] = 'X';
640
	}
641
 
642
	if (quadnum >= 100) {
643
		// Position ordinary Klingons
644
		quadnum -= 100*klhere;
645
		for (i = 1; i <= klhere; i++) {
646
			dropin(IHK, &ix, &iy);
647
			kx[i] = ix;
648
			ky[i] = iy;
649
			kdist[i] = kavgd[i] = sqrt(square(sectx-ix) + square(secty-iy));
650
			kpower[i] = Rand()*150.0 +300.0 +25.0*skill;
651
		}
652
		// If we need a commander, promote a Klingon
653
		for (i = 1; i <= d.remcom ; i++)
654
			if (d.cx[i]==quadx && d.cy[i]==quady) break;
655
 
656
		if (i <= d.remcom) {
657
			quad[ix][iy] = IHC;
658
			kpower[klhere] = 950.0+400.0*Rand()+50.0*skill;
659
			comhere = 1;
660
		}
661
 
662
		// If we need a super-commander, promote a Klingon
663
		if (quadx == d.isx && quady == d.isy) {
664
			quad[kx[1]][ky[1]] = IHS;
665
			kpower[1] = 1175.0 + 400.0*Rand() + 125.0*skill;
666
			iscate = 1;
667
			ishere = 1;
668
		}
669
	}
670
	// Put in Romulans if needed
671
	for (i = klhere+1; i <= nenhere; i++) {
672
		dropin(IHR, &ix, &iy);
673
		kx[i] = ix;
674
		ky[i] = iy;
675
		kdist[i] = kavgd[i] = sqrt(square(sectx-ix) + square(secty-iy));
676
		kpower[i] = Rand()*400.0 + 450.0 + 50.0*skill;
677
	}
678
	sortkl();
679
	// If quadrant needs a starbase, put it in
680
	if (quadnum >= 10) {
681
		quadnum -= 10;
682
		dropin(IHB, &basex, &basey);
683
	}
684
 
685
	if (nplan) {
686
		// If quadrant needs a planet, put it in
687
		for (i=1; i <= inplan; i++)
688
			if (d.plnets[i].x == quadx && d.plnets[i].y == quady) break;
689
		if (i <= inplan) {
690
			iplnet = i;
691
			dropin(IHP, &plnetx, &plnety);
692
		}
693
	}
694
	// Check for condition
695
	newcnd();
696
	// And finally the stars
697
	for (i = 1; i <= quadnum; i++) dropin(IHSTAR, &ix, &iy);
698
 
699
	// Check for RNZ
700
	if (irhere > 0 && klhere == 0 && basex == 0) {
701
		neutz = 1;
702
		if (REPORTS) {
703
			skip(1);
704
/* 			prout("LT. UHURA- \"Captain, an urgent message.");
705
			prout("  I'll put it on audio.\"  CLICK");
706
			skip(1);
707
			prout("INTRUDER! YOU HAVE VIOLATED THE ROMULAN NEUTRAL ZONE.");
708
			prout("LEAVE AT ONCE, OR YOU WILL BE DESTROYED!");
709
 */			prout("Лейтенант Ухура- \"Капитан, срочное сообщение.");
710
			prout("  Я включу на громкую связь.\"  CLICK");
711
			skip(1);
712
			prout("НАРУШИТЕЛЬ! ВЫ ВТОРГЛИСЬ В НЕЙТРАЛЬНУЮ ЗОНУ РОМУЛАН.");
713
			prout("НЕМЕДЛЕННО УЛЕТАЙТЕ, ИЛИ БУДЕТЕ УНИЧТОЖЕНЫ!");
714
		}
715
	}
716
 
717
	if (shutup==0) {
718
		// Put in THING if needed
719
		if (thingx == quadx && thingy == quady) {
720
			dropin(IHQUEST, &ix, &iy);
721
			thingx = thingy = 0; // Transient
722
			if (damage[DSRSENS] == 0.0) {
723
				skip(1);
724
/* 				prout("MR. SPOCK- \"Captain, this is most unusual.");
725
				prout("    Please examine your short-range scan.\"");
726
 */				prout("МИСТЕР СПОК- \"Капитан, это очень странно.");
727
				prout("    Пожалуйста посмотрите на ближний сканер.\"");
728
			}
729
		}
730
	}
731
 
732
	// Put in a few black holes
733
	for (i = 1; i <= 3; i++)
734
		if (Rand() > 0.5) dropin(IHBLANK, &ix, &iy);
735
 
736
	// Take out X's in corners if Tholian present
737
	if (ithere) {
738
		if (quad[1][1]=='X') quad[1][1] = IHDOT;
739
		if (quad[1][10]=='X') quad[1][10] = IHDOT;
740
		if (quad[10][1]=='X') quad[10][1] = IHDOT;
741
		if (quad[10][10]=='X') quad[10][10] = IHDOT;
742
	}
743
}
744
 
745
void sortkl(void) {
746
	double t;
747
	int sw, j, k;
748
 
749
	// The author liked bubble sort. So we will use it. :-(
750
 
751
	if (nenhere < 2) return;
752
 
753
	do {
754
		sw = FALSE;
755
		for (j = 1; j < nenhere; j++)
756
			if (kdist[j] > kdist[j+1]) {
757
				sw = TRUE;
758
				t = kdist[j];
759
				kdist[j] = kdist[j+1];
760
				kdist[j+1] = t;
761
				t = kavgd[j];
762
				kavgd[j] = kavgd[j+1];
763
				kavgd[j+1] = t;
764
				k = kx[j];
765
				kx[j] = kx[j+1];
766
				kx[j+1] = k;
767
				k = ky[j];
768
				ky[j] = ky[j+1];
769
				ky[j+1] = k;
770
				t = kpower[j];
771
				kpower[j] = kpower[j+1];
772
				kpower[j+1] = t;
773
			}
774
	} while (sw);
775
}