/[projet1]/users/chema/TINE/universe.s
Defence Force logotype

Contents of /users/chema/TINE/universe.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 209 - (show annotations)
Sun Jan 24 17:41:36 2010 UTC (10 years, 2 months ago) by Chema
File size: 15640 byte(s)
Moved energy low message to the main loop, each 64 frames. Removed the patch to avoid sound for that message, as it is no more needed.

Added the extra maneuverability unit.

Tweaked the messages for landing/launching.
1 ;;;;; Functions to create objects and initialize universe.
2
3
4
5 OCEN .word 0000 ;X-coord
6 .word 0000 ;Y-coord
7 .word 1300 ;Z-coord
8
9 OCEN2 .word -1000 ;X-coord
10 .word 1000 ;Y-coord
11 .word 1300 ;Z-coord
12
13
14 ; Creates the environment, based on the data from cpl_system, so
15 ; should be called after _jump on galaxy.s
16
17 CreateEnvironment
18 .(
19 ; Make sure Obj3D is empty
20 jsr _EmptyObj3D
21 ; Create the radar object (number 0)
22 jsr CreateRadar
23 ; Add our ship, which is object number 1 at initial position (fixed)
24 ; This is different depending on whether we are launched from planet,
25 ; or exit hyperspace. This depends on the _docked variable
26
27 lda _docked
28 beq hyper
29
30 ; Create at planet's position
31 jsr planetpos
32 ; With Z a bit closer
33 lda _PosZ+1
34 sec
35 sbc #7
36 sta _PosZ+1
37 jmp createship
38
39 hyper
40 lda #0
41 sta _PosX
42 sta _PosX+1
43 sta _PosY
44 sta _PosY+1
45 lda #<(-16384+6000)
46 sta _PosZ
47 lda #>(-16384+6000)
48 sta _PosZ+1
49
50 createship
51 lda #<_PosX
52 sta tmp0
53 lda #>_PosX
54 sta tmp0+1
55 lda _ship_type
56 jsr AddSpaceObject
57
58 ; Set our ship as view object
59 stx VOB
60
61 lda _docked
62 beq norot
63
64 ; Rotate it 180 deg
65 jsr SetCurOb
66 lda #0
67 tay ; z and y angles 0 deg of rotation
68 ldx #50; ; rotate 180 deg
69 jsr SetMat
70
71 norot
72 ; And initialize all the stuff (equipment...)
73 jsr InitPlayerShip
74
75 jsr planetpos
76 lda #<ONEPLANET
77 ldy #>ONEPLANET
78 jsr addmoonplanet
79
80 ; Now create some moons (between 0 and 3)
81 lda _cpl_system+SEED+1
82 and #%00000011
83 beq moonsdone
84 sta tmp1
85
86 lda _PosX+1
87 sta savpX+1
88 lda _PosY+1
89 sta savpY+1
90 lda _PosZ+1
91 sta savpZ+1
92
93 loop
94 lda _cpl_system+SEED
95 sta tmp
96 jsr moonpos
97 lda _PosX+1
98 sec
99 sbc tmp
100 sta _PosX+1
101
102 lda _cpl_system+SEED+2
103 sta tmp
104 jsr moonpos
105 lda _PosY+1
106 sec
107 sbc tmp
108 sta _PosY+1
109
110 lda _cpl_system+SEED+3
111 sta tmp
112 jsr moonpos
113 lda _PosZ+1
114 sec
115 sbc tmp
116 sta _PosZ+1
117
118 lda #<ONEMOON
119 ldy #>ONEMOON
120 jsr addmoonplanet
121
122
123 savpX
124 lda #0
125 sta _PosX+1
126 savpY
127 lda #0
128 sta _PosY+1
129 savpZ
130 lda #0
131 sta _PosZ+1
132
133
134 dec tmp1
135 bne loop
136
137 moonsdone
138 ; Initialize variables
139 lda #0
140 sta thargoid_counter
141 sta police_counter
142 sta asteroid_counter
143 sta worm_counter
144 sta missile_counter
145
146 sta _ecm_counter
147 sta message_delay
148
149 ;jsr _InitTestCode
150
151 ; Create initial encounters
152 ; Encounters are not created if too close to planet, so
153 ; set_planet_distance should be called afterwards...
154 lda #$ff
155 sta _planet_dist
156
157 ldx #3
158 stx count ; Hope it is not used here
159 loopen
160 jsr random_encounter
161 dec count
162 bpl loopen
163
164 jmp set_planet_distance
165
166 ;rts
167 .)
168
169
170 planetpos
171 .(
172
173 ; Now create the position of the planet (adapted from Elite TNK, but with small variations)
174 lda #0
175 sta _PosZ
176 sta _PosX
177 sta _PosY
178 lda _cpl_system+SEED+1
179 and #%00110000
180 clc
181 adc #$5 ; result number between $5 and $35
182 sta _PosZ+1
183 lsr
184 tax
185 lda _cpl_system+SEED+1
186 ;and #1
187 ;beq noinvert
188 bcc noinvert
189 txa
190 eor #%11110000
191 tax
192 noinvert
193 stx _PosX+1
194 stx _PosY+1
195 rts
196 .)
197
198 addmoonplanet
199 .(
200
201 ldx #<_PosX
202 stx tmp0
203 ldx #>_PosX
204 stx tmp0+1
205
206 ldx #$80 ; Non-moving object
207 jsr AddSpaceObjectDirect
208 lda #255
209 sta _energy,x
210 rts
211 .)
212
213 moonpos
214 .(
215 lda tmp
216 ldx tmp1
217 loop
218 lsr
219 lsr
220 dex
221 bne loop
222 php
223 and #%00000011
224 clc
225 adc #%00000001 ; Result between $1 and $4
226 ;asl
227 ;asl
228 ;tax
229 ;lda tmp
230 plp
231 ;and #1
232 ;beq noinvert2
233 bcc noinvert2
234 ;txa
235 eor #$ff
236 ;tax
237 noinvert2
238 ;stx tmp
239 sta tmp
240 rts
241 .)
242
243
244 ;;;;;;;;;;;;;;; TEST CODE
245 #ifdef 0
246 _InitTestCode
247 .(
248 rts
249 ; Add some ships
250
251 lda #<OCEN
252 sta tmp0
253 lda #>OCEN
254 sta tmp0+1
255 lda #SHIP_ADDER
256 ;lda #SHIP_ANACONDA
257 ;lda #SHIP_COUGAR
258 jsr AddSpaceObject
259 stx savid+1
260 lda _ai_state,x
261 ;ora #(IS_AICONTROLED | FLG_BOUNTYHUNTER)
262 ;ora #(IS_AICONTROLED | FLG_POLICE)
263 ora #(IS_AICONTROLED)
264 sta _ai_state,x
265
266 ;lda #2 ; Planet
267 ;sta _target,x
268 ;lda _flags,x
269 ;ora #FLG_FLY_TO_PLANET
270 ;sta _flags,x
271
272 lda #(HAS_ESCAPEPOD)
273 jsr SetShipEquip
274
275 lda #<OCEN2
276 sta tmp0
277 lda #>OCEN2
278 sta tmp0+1
279 lda #SHIP_ASP
280 ;lda #SHIP_ANACONDA
281 ;lda #SHIP_COUGAR
282 jsr AddSpaceObject
283
284 ; This one will pursue the other :)
285 savid lda #0 ;SMC
286
287 ; make it angry
288 ora #IS_ANGRY
289 sta _target,x
290 lda _ai_state,x
291 ora #IS_AICONTROLED
292 sta _ai_state,x
293
294 lda #(HAS_ESCAPEPOD)
295 jsr SetShipEquip
296
297
298 ;ldx VOB
299 ;sta _target,x
300
301 rts
302 .)
303
304 #endif
305
306 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
307 ; Create random encounters
308 ; Extracted and adapted from Elite TNK
309 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
310
311
312 ;void random_encounter (void)
313
314 random_encounter
315 .(
316 ; If already too many objects, return
317 lda NUMOBJS
318 cmp #10;12
319 bcc cont1
320 rts
321 cont1
322
323 ; if ((ship_count[SHIP_CORIOLIS] != 0) || (ship_count[SHIP_DODEC] != 0))
324 ; return;
325
326 ; If near the planet, then return
327 lda _planet_dist
328 cmp #PDIST_DOCK
329 bcs cont
330 rts
331 cont
332
333 ; if (rand255() == 136)
334 ; {
335 ; if (((int)(universe[0].location.z) & 0x3e) != 0)
336 ; create_thargoid ();
337 ; else
338 ; create_cougar();
339 ;
340 ; return;
341 ; }
342
343 ; Create new random
344 jsr _gen_rnd_number
345 cmp #136
346 bne nothargoid
347 ; Create thargoid or cougar and return
348 ; Thargoid is created if far from planet
349 lda _planet_dist
350 cmp #80
351 bcs thargoid
352 jmp create_cougar
353 thargoid
354 jmp create_thargoid
355 nothargoid
356
357 ; if ((rand255() & 7) == 0)
358 ; {
359 ; create_trader();
360 ; return;
361 ; }
362
363 lda _rnd_seed+3
364 and #3
365 bne notrader
366 ; Change this so more traders on secure systems
367 ; and #7
368 ; cmp _cpl_system+GOVTYPE
369 ; bcs notrader
370 jmp create_trader
371 notrader
372
373 ; check_for_asteroids();
374 jsr check_for_asteroids
375
376 ; check_for_cops();
377 ; if (ship_count[SHIP_VIPER] != 0)
378 ; return;
379
380 jsr check_for_cops
381 /*
382 lda police_counter
383 beq nocops
384 rts
385 nocops
386 */
387
388 ; if (in_battle)
389 ; return;
390
391 ; if ((cmdr.mission == 5) && (rand255() >= 200))
392 ; create_thargoid ();
393
394 ; check_for_others();
395 jmp check_for_others
396
397 .)
398
399 create_cougar
400 .(
401 lda #SHIP_COUGAR
402 ldx _rnd_seed+3
403 bpl nocloack
404 ora #SHIP_NORADAR
405 nocloack
406 jsr create_other_ship
407 cpx #0
408 beq end ; Could not create ship
409
410 lda #(HAS_ECM) ; Cloaking?
411 jsr SetShipEquip
412
413 lda #(IS_AICONTROLED)
414 sta _ai_state,x
415 jsr set_boldness
416
417 jmp set_speed_and_target
418
419 end
420 rts
421 .)
422
423
424
425
426
427 create_thargoid
428 .(
429 ; No more than MAXTHARG Thargoids, please
430 lda thargoid_counter
431 cmp #(MAXTHARG)
432 bcs end
433 lda #SHIP_THARGOID
434 jsr create_other_ship
435 cpx #0
436 beq end ; Could not create ship
437
438 lda #1
439 ora #IS_ANGRY ; set angry flag
440 sta _target,x
441
442
443 lda #(HAS_ECM)
444 jsr SetShipEquip
445
446 lda #(IS_AICONTROLED|FLG_PIRATE)
447 sta _ai_state,x
448 jsr set_boldness
449
450 ; Should add missiles (tharglets) here. Maybe depending on environment stats.
451 ;lda _missiles,x
452 ;ora #%10
453 stx savx+1
454 jsr _gen_rnd_number
455 and #%11
456 savx ldx #0 ;SMC
457 sta _missiles,x
458
459 ; note that there are thargoids on system
460 inc thargoid_counter
461 end
462 rts
463 .)
464
465
466 create_trader
467 .(
468
469 ; type = SHIP_COBRA3 + (rand255() & 3);
470 jsr _gen_rnd_number
471 and #3
472 clc
473 adc #SHIP_BOA
474 jsr create_other_ship
475 cpx #0
476 beq end ; Could not create ship
477
478 ; if (newship != -1)
479 ; {
480 ; universe[newship].rotmat[2].z = -FRAC_ONE;
481 ; universe[newship].rotz = rand255() & 7;
482 ;
483 ; rnd = rand255();
484 ; universe[newship].velocity = (rnd & 31) | 16;
485 ; universe[newship].bravery = rnd / 2;
486 ;
487 ; if (rnd & 1)
488 ; universe[newship].flags |= FLG_HAS_ECM;
489 ;
490 ;// if (rnd & 2)
491 ;// universe[newship].flags |= FLG_ANGRY;
492 ; }
493
494 ; Equip
495 lda _rnd_seed+2
496 lsr
497 bcc noecm
498
499 lda #HAS_ECM
500 ;and #%1111 ; Limit possible equipment
501
502 ; Equip is random, but this includes advanced equipment
503 ; Maybe it is a good idea to limit, for instance, anti-radar.
504 jsr SetShipEquip
505 noecm
506 lda #FLG_INNOCENT
507 sta _flags,x
508
509 lda _ai_state,x
510 ora #FLG_TRADER
511 sta _ai_state,x
512
513 jmp set_speed_and_target
514 end
515 rts
516 .)
517
518
519 set_speed_and_target
520 .(
521 ; Set destination and speed
522 lda _rnd_seed+2
523 bmi noptarget
524 lda #2
525 sta _target,x
526 lda _flags,x
527 ora #FLG_FLY_TO_PLANET
528 sta _flags,x
529 bne set_speed ; allways branches
530 noptarget
531 lsr
532 bcc set_speed
533 ; Set Hyper as target
534 lda _flags,x
535 ora #FLG_FLY_TO_HYPER
536 sta _flags,x
537 +set_speed
538 lda _rnd_seed+2
539 and #%111
540 ora #%100
541 asl
542 sta _speed,x
543 +set_orient
544 ; change its orientation
545 jsr SetCurOb
546 lda _rnd_seed
547 ldx _rnd_seed+1
548 ldy _rnd_seed+3
549 jmp SetMat
550 ;BEWARE X is no more the object's id
551 .)
552
553
554 check_for_asteroids
555 .(
556 ;if ((rand255() >= 35) || (ship_count[SHIP_ASTEROID] >= 3))
557 ; return;
558
559 lda asteroid_counter
560 cmp #3
561 bcs end
562 jsr _gen_rnd_number
563 cmp #35
564 bcs end
565
566 ;if (rand255() > 253)
567 ; type = SHIP_HERMIT;
568 ;else
569 ; type = SHIP_ASTEROID;
570
571 ; lda _rnd_seed
572 ; cmp #254
573 ; bcs hermit
574 lda #SHIP_ASTEROID
575 ; .byt $2c
576 ;hermit
577 ; lda #SHIP_HERMIT
578
579 jsr create_other_ship
580 cpx #0
581 beq end
582
583 inc asteroid_counter
584
585 lda _ai_state,x
586 and #%01111111 ;~(IS_AICONTROLED)
587 sta _ai_state,x
588
589 ; Make it rotate
590 lda #3
591 sta _rotz,x
592
593 ;Set speed and random orientation
594 jmp set_speed
595 end
596 rts
597
598 .)
599
600
601
602 check_for_cops
603 .(
604 lda police_counter
605 cmp #(MAXCOPS)
606 beq end
607
608 ; Check
609 ; if rnd and 7 >= _cpl_system+GOVTYPE
610 ; then rts
611
612 ; Send cops from planet
613 ; They should automatically target you if needed
614
615 jsr _gen_rnd_number
616 and #7
617 cmp _cpl_system+GOVTYPE
618 bcs end
619
620 ldx #2 ; Planet
621 jsr SetCurOb
622 lda #SHIP_VIPER ; Ship to launch
623 jsr LaunchShipFromOther
624 cpx #0
625 beq end ; Couldn't create object
626
627 ; Note it down on cop list
628 lda police_counter
629 tay
630 txa
631 sta police_ids,y
632 inc police_counter
633
634
635 lda #IS_AICONTROLED|FLG_POLICE
636 sta _ai_state,x
637 jsr set_boldness
638 lda #20
639 sta _speed,x
640
641 lda _rnd_seed+2
642 bmi notarp
643 lda #1
644 sta _target,x
645
646 notarp
647 lda #FLG_INNOCENT
648 sta _flags,x
649 jmp set_orient
650 end
651 rts
652
653 .)
654
655 check_for_others
656 .(
657 ; Here goes everything else
658 ; Pirates, Bounties, shuttles...
659 ; Should be based on game internals and some randomizing
660
661 jsr _gen_rnd_number
662 ;lda _rnd_seed+2
663 cmp #90
664 bcc doit
665 rts
666 doit
667 ;lda _rnd_seed
668 and #7
669 sta tmp
670 lda _cpl_system+GOVTYPE
671 cmp tmp
672 bcs nopirates ; govtype >= rnd &7 then no pirates
673
674 pirates
675 ; Generate pirates
676 jmp generate_pirate
677
678 nopirates
679 lda _rnd_seed
680 bmi shuttle
681 ; Gererate Bounty Hunter
682 jmp generate_bounty
683
684 shuttle
685 ; Generate some junk
686 jmp generate_shuttle
687 .)
688
689
690 generate_pirate
691 .(
692 jsr gen_ship_type
693 clc
694 adc #SHIP_BOA
695 jsr generate_pirate_bounty
696 cpx #0
697 bne cont
698 rts
699 cont
700 ; Flag as pirate
701 lda _ai_state,x
702 ora #FLG_PIRATE
703 sta _ai_state,x
704
705 ; Assign target
706 stx savx+1
707 ldx NUMOBJS
708 dex
709 loop
710 cpx savx+1
711 beq next
712 lda _ai_state,x
713 and #%01111111
714 sta tmp+1
715 lda _rnd_seed+1
716 ora _rnd_seed+2
717 ;ora _rnd_seed+3
718 and tmp+1
719 bne chosen
720 next
721 dex
722 bne loop
723 ; Nothing chosen, track the player
724 ldx #1
725 chosen
726 txa
727 savx
728 ldx #0 ; SMC
729 ora #IS_AICONTROLED
730 sta _target,x
731
732 jmp set_boldness
733 .)
734
735 generate_bounty
736 .(
737 jsr gen_ship_type
738 lsr
739 clc
740 adc #SHIP_MORAY
741 jsr generate_pirate_bounty
742 cpx #0
743 bne cont
744 rts
745
746 cont
747 ; Flag as Bounty
748 lda _ai_state,x
749 ora #FLG_BOUNTYHUNTER
750 sta _ai_state,x
751
752 jmp set_boldness
753 .)
754
755
756 generate_pirate_bounty
757 .(
758 sta shiptype+1
759 ; Set cloacking device
760 tax
761 lda _galaxynum
762 cmp #1
763 beq nocloack
764 lda _rnd_seed+3
765 and #%1111
766 bne nocloack
767 txa
768 ora #SHIP_NORADAR ; Not visible
769 tax
770 nocloack
771 txa
772 jsr create_other_ship
773 cpx #0
774 beq end
775
776 ; See if it is to be flagged as slow
777 shiptype
778 lda #0 ; SMC
779 cmp #SHIP_ANACONDA
780 beq slowme
781 cmp #SHIP_WORM
782 bne noslow
783 slowme
784 lda _ai_state,x
785 ora #FLG_SLOW
786 sta _ai_state,x
787 noslow
788 jmp gen_ship_equipment
789 end
790 rts
791 .)
792
793
794 gen_ship_type
795 .(
796 jsr _gen_rnd_number
797 and #%1111 ; a=0..15
798 tax
799 lda _score
800 bne l1
801 dex
802 lda _score+1
803 cmp #80
804 bcc l1
805 dex
806 dex
807 l1 ; a=0..15 - 0..3
808 lda _galaxynum
809 cmp #1
810 bne l2
811 dex
812 dex
813 l2 ; a=0..15 - 0..3 - 0..2
814 txa
815 bpl correct
816 lda #0
817 correct
818 cmp #11
819 bcc correct2
820 lda #10
821 correct2
822 rts
823 .)
824
825 eq_tmp .byt 0
826
827 gen_ship_equipment
828 .(
829 lda #0
830 sta eq_tmp
831
832 ; Must preserve reg X!!!
833 stx savx+1
834
835 ; What is to be added here? Maybe ECM
836 lda _score+1
837 bne nocheckscore
838 lda _score
839 cmp _rnd_seed+2
840 bcc noecm
841 nocheckscore
842 lda _rnd_seed+3
843 ;bpl noecm
844 and #%11
845 bne noecm
846 lda #(HAS_ECM) ; Cloaking?
847 sta eq_tmp
848 noecm
849 ; And escape pod
850 lda _rnd_seed+1
851 bpl nopod
852 lda eq_tmp
853 ora #(HAS_ESCAPEPOD)
854 sta eq_tmp
855 nopod
856
857 ; Equip with selected items
858 lda eq_tmp
859 jsr SetShipEquip
860 savx
861 ldx #0 ; SMC
862 rts
863 .)
864
865 generate_shuttle
866 .(
867 lda _rnd_seed+3
868 and #%1
869 clc
870 adc #SHIP_SHUTTLE ; Ship to launch
871 sta tmp
872
873 lda _rnd_seed
874 bmi from_planet
875 to_planet
876 lda tmp
877 jsr create_other_ship
878 lda #2
879 sta _target,x
880 lda _flags,x
881 ora #FLG_FLY_TO_PLANET|FLG_INNOCENT
882 sta _flags,x
883 bne finish ; allways branches
884 from_planet
885 ldx #2 ; Planet
886 jsr SetCurOb
887 lda tmp
888 jsr LaunchShipFromOther
889 cpx #0
890 beq end ; Couldn't create object
891
892 lda _flags,x
893 ora #FLG_FLY_TO_HYPER|FLG_INNOCENT
894 sta _flags,x
895
896 finish
897 lda #IS_AICONTROLED|FLG_DEFENCELESS|FLG_SLOW
898 sta _ai_state,x
899 end
900 rts
901 .)
902
903
904 ; Create a ship of type passed in reg A
905 ; Returns X with the new ship ID. Zero in X if error.
906 create_other_ship
907 .(
908 pha
909 ; Get player's position
910 ldx #1
911 jsr GetShipPos
912
913 ; Generate new ship a bit far away
914 lda _PosX+1
915 eor #%1111; $17
916 sta _PosX+1
917
918 lda _PosY+1
919 eor #%1111;$17
920 sta _PosY+1
921
922 lda _PosZ+1
923 eor #%1111;$17
924 sta _PosZ+1
925
926 lda _rnd_seed+1
927 bmi noinvertX
928 sec
929 lda #0
930 sbc _PosX
931 sta _PosX
932 lda #0
933 sbc _PosX+1
934 sta _PosX+1
935 noinvertX
936
937 lda _rnd_seed+2
938 bmi noinvertY
939 sec
940 lda #0
941 sbc _PosY
942 sta _PosY
943 lda #0
944 sbc _PosY+1
945 sta _PosY+1
946 noinvertY
947
948 lda _rnd_seed+2
949 bmi noinvertZ
950 sec
951 lda #0
952 sbc _PosZ
953 sta _PosZ
954 lda #0
955 sbc _PosZ+1
956 sta _PosZ+1
957 noinvertZ
958
959
960 lda #<_PosX
961 sta tmp0
962 lda #>_PosX+1
963 sta tmp0+1
964 pla
965 jsr AddSpaceObject
966
967 ; Set number of missiles
968 stx savx+1
969 jsr _gen_rnd_number
970 ora #%11111000
971 savx
972 ldx #0 ;SMC
973 and _missiles,x
974 sta _missiles,x
975
976 lda #(IS_AICONTROLED)
977 sta _ai_state,x
978 rts
979 .)
980
981 set_boldness
982 .(
983 lda _score+1
984 cmp #02
985 bcc end
986
987 ; We are really dangerous, so make enemies bold
988 lda _ai_state,x
989 ora #FLG_BOLD
990 sta _ai_state,x
991 end
992 rts
993 .)
994
995

  ViewVC Help
Powered by ViewVC 1.1.26