123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include <math.h>
- #include <time.h>
- #include "c:\netnow\hmistd.h"
- #include "c:\netnow\netnow.h"
- #include "c:\netnow\vdata.h"
- #include "c:\netnow\vchat.h"
- #include "c:\sos\include\sosm.h"
- #include "network.h"
- #include "defines.h"
- #include "mouse.h"
- //#include <iostream.h>
- //#include <dos.h>
- unsigned char machine_no;
- // Player vars
- volatile int Team_A,Team_B;
- volatile int Teams[MAX_NET_USERS],Players[MAX_NET_USERS];
- int TeamChoice,PlayerChoice;
- // General vars
- char old_mf;
- int netsetup_on; // In network setup
- int network_on; // Network on flag / No of network players
- int onetwork_on;
- short wConsoleNode; // Network ID for machine
- short master; // Network ID for master
- volatile int active_nodes;
- volatile int net_quit;
- int num_of_users=0;
- // Packet types
- packet_header in_header;
- packet_header p_header;
- packet_data p_data;
- packet_seed test_seed;
- packet_single test_single;
- packet_multiple test_multiple;
- //volatile packet_multiple copy_multiple[512];
- volatile int writeptr;
- volatile int readptr;
- volatile packet_single user_inp; // Temp input data
- // Internal network vars
- _NETNOW_NODE_ADDR address[MAX_NET_USERS]; // Station addresses that we know about.
- _NETNOW_NODE_ADDR laddress; // Local machines address
- volatile int net_players[16];
- volatile int start_multiple; // No of players master has sent to
- volatile int received_seed; //
- volatile int frame_number;
- volatile int slave_pause=FALSE;
- volatile int NetDone;
- // Timer vars
- volatile int count;
- volatile int tick;
- volatile int ftick;
- int game_speed;
- // Richards
- volatile int hold_loop;
- // User input arrays
- struct user_config{
- short type;
- short control;
- int inp_x;
- int inp_y;
- int inp_ox;
- int inp_oy;
- short inp_fb;
- char chng;
- signed char plr;
- };
- volatile struct user_config users[MAX_NET_USERS];
- struct user_vectors_i{
- short x_f1;
- short y_f2;
- };
- volatile struct user_vectors_i users_dir_i[512][MAX_NET_USERS];
- int icth,isth; // viewing angle in integers
- // Vars taken from Andy's code (mostly input stuff)
- volatile char paused;
- volatile char pause_request;
- volatile char keys[256];
- volatile char key_togs[256];
- signed char key1[6];
- signed char key2[6];
- unsigned short joy1_cnt_x,joy1_cnt_y;
- unsigned short joy2_cnt_x,joy2_cnt_y;
- int joy1_max_x,joy1_max_y,joy1_min_x,joy1_min_y;
- int joy2_max_x,joy2_max_y,joy2_min_x,joy2_min_y;
- volatile int joy1_x=0;
- volatile int joy1_y=0;
- volatile int joy1_fire=0;
- volatile int joy2_x=0;
- volatile int joy2_y=0;
- volatile int joy2_fire=0;
- volatile char joy1_move=0;
- volatile char joy2_move=0;
- char joystick1_on=FALSE;
- char joystick2_on=FALSE;
- char digital_joy1=FALSE;
- char digital_joy2=FALSE;
- struct joy_struct {
- int FireA1,FireA2,JoyAX,JoyAY;
- int FireB1,FireB2,JoyBX,JoyBY;
- };
- /*
- struct rjoy_struct {
- unsigned short x1;
- unsigned short y1;
- unsigned short x2;
- unsigned short y2;
- unsigned short sw;
- };
-
- volatile struct rjoy_struct rjoy_pos;
- */
- volatile struct joy_struct joy_pos;
- unsigned short dead_zone=25; // percentage
- volatile int ux1,ux2,wptr,rptr;
- /********************/
- /* INPUT ROUTINES */
- /********************/
- /////////////////
- // JOYSTICKS //
- //Function to gather joystick data and return in a joystick structure
- int x1ok=1; // These values indicate whether the axes are connected or not...
- int y1ok=2; // for calibration they should be initialised.
- int x2ok=4;
- int y2ok=8;
- int bitaccept=15; // Above values OR'ed
- #define JOY_TIMEOUT 65535
- extern void __far JoyRead3(void *);
- extern void __far JoyRead2(void *);
- extern void __far JoyRead1(void *);
- /******************************************************************************
- ******************************************************************************/
- /*
- void ConvJoys()
- {
- joy_pos.FireA1=!((rjoy_pos.sw>>4)&1);
- joy_pos.FireA2=!((rjoy_pos.sw>>5)&1);
- joy_pos.FireB1=!((rjoy_pos.sw>>6)&1);
- joy_pos.FireB2=!((rjoy_pos.sw>>7)&1);
- joy_pos.JoyAX=rjoy_pos.x1;
- joy_pos.JoyAY=rjoy_pos.y1;
- joy_pos.JoyBX=rjoy_pos.x2;
- joy_pos.JoyBY=rjoy_pos.y2;
- }
- */
- /******************************************************************************
- ******************************************************************************/
- /*
- void ReadJoys()
- {
- if (joystick1_on && joystick2_on)
- // Two joysticks plugged in...
- {
- JoyRead3(&rjoy_pos);
- ConvJoys();
- }
- else
- {
- if (joystick1_on)
- // Port 1 joystick only...
- {
- JoyRead1(&rjoy_pos);
- ConvJoys();
- }
- else
- // Port 2 joystick only...
- {
- if (joystick2_on)
- {
- JoyRead2(&rjoy_pos);
- ConvJoys();
- }
- }
- }
- }
- */
- void ReadJoys(struct joy_struct *JoyData)
- {
- //read joysticks for calibration - always returns!
- int XJA=-1,YJA=-1,XJB=-1,YJB=-1,Fire,FireA,FireB,j;
- int timecount=0;
- int x1read,y1read,x2read,y2read;
- Fire=((int)inp(0x201) ^ 255)>>4;
- FireA=Fire & 3;
- FireB=(Fire>>2) & 3;
- JoyData->FireA1=FireA & 1;
- JoyData->FireA2=FireA>>1;
- JoyData->FireB1=FireB & 1;
- JoyData->FireB2=FireB>>1;
- XJA=0;
- YJA=0;
- XJB=0;
- YJB=0;
- _disable();
- outp(0x201,255); //Request a reading from the joystick port
- x1read=x1ok;
- y1read=y1ok;
- x2read=x2ok;
- y2read=y2ok;
- do
- {
- j=(int)inp(0x201); //read the current port status
- if (x1ok)
- if (x1read=(j & 1)) XJA++; //increase X counter
- if (y1ok)
- if (y1read=(j & 2)) YJA++; //increase Y counter
- if (x2ok)
- if (x2read=(j & 4)) XJB++; //increase X counter
- if (y2ok)
- if (y2read=(j & 8)) YJB++; //increase Y counter
- timecount++;
- }
- while((j & bitaccept) && timecount<JOY_TIMEOUT); //this will cause time out during calibration if not connected!
- _enable();
- if (!x1read)
- JoyData->JoyAX=XJA;
- else
- {
- JoyData->JoyAX=0;
- x1ok=0; //timed out - stop reading!
- bitaccept=x1ok | y1ok | x2ok | y2ok;
- }
- if (!y1read)
- JoyData->JoyAY=YJA;
- else
- {
- JoyData->JoyAY=0;
- y1ok=0;
- bitaccept=x1ok | y1ok | x2ok | y2ok;
- }
- if (!x2read)
- JoyData->JoyBX=XJB;
- else
- {
- JoyData->JoyBX=0;
- x2ok=0;
- bitaccept=x1ok | y1ok | x2ok | y2ok;
- }
- if (!y2read)
- JoyData->JoyBY=YJB;
- else
- {
- JoyData->JoyBY=0;
- y2ok=0;
- bitaccept=x1ok | y1ok | x2ok | y2ok;
- }
- }
- void read_joy1(unsigned short *x, unsigned short *y, unsigned char *sw)
- {
- *x=joy_pos.JoyAX;
- *y=joy_pos.JoyAY;
- *sw=joy_pos.FireA1|(joy_pos.FireA2<<1);
- }
- void read_joy2(unsigned short *x, unsigned short *y, unsigned char *sw)
- {
- *x=joy_pos.JoyBX;
- *y=joy_pos.JoyBY;
- *sw=joy_pos.FireB1|(joy_pos.FireB2<<1);
- }
- void read_joystick(char j, unsigned short *x, unsigned short *y, unsigned char *sw)
- {
- ReadJoys(&joy_pos);
- if (!j)
- read_joy1(x,y,sw);
- else
- read_joy2(x,y,sw);
- }
- void get_joy_max_min(char j)
- {
- int i;
- unsigned short x,y;
- unsigned char butt;
- unsigned short max_x=0;
- unsigned short min_x=65535;
- unsigned short max_y=0;
- unsigned short min_y=65535;
- do
- {
- read_joystick(j,&x,&y,&butt);
- if (x>max_x)
- max_x=x;
- if (x<min_x)
- min_x=x;
- if (y>max_y)
- max_y=y;
- if (y<min_y)
- min_y=y;
- // STRANGE???? Need this software loop to get normal range values from joystick!
- // Shrug....
- for (i=0; i<200000; i++)
- {
- i+=1;
- i-=1;
- }
- }while(!(butt&3));
- if (!j)
- {
- joy1_max_x=max_x;
- joy1_max_y=max_y;
- joy1_min_x=min_x;
- joy1_min_y=min_y;
- }
- else
- {
- joy2_max_x=max_x;
- joy2_max_y=max_y;
- joy2_min_x=min_x;
- joy2_min_y=min_y;
- }
- }
- void calibrate_joy(char j,unsigned short *x,unsigned short *y)
- {
- unsigned short left,right,up,down;
- unsigned char butt;
- unsigned short max_x,min_x,max_y,min_y;
- float dead_zone=0.6; // 33% dead_zone!
- char str[40];
- printf("\nPlease circle joystick %d now...\n",j+1);
- get_joy_max_min(j);
- if (!j)
- {
- left=joy1_min_x;
- right=joy1_max_x;
- up=joy1_min_y;
- down=joy1_max_y;
- }
- else
- {
- left=joy2_min_x;
- right=joy2_max_x;
- up=joy2_min_y;
- down=joy2_max_y;
- }
- printf("Left %d\n",left);
- printf("Right %d\n",right);
- printf("Up %d\n",up);
- printf("Down %d\n",down);
- printf("\nNow centre joystick %d and press fire...\n",j+1);
- if (!j)
- {
- do
- {
- read_joystick(0,x,y,&butt);
- }while(butt&3);
- do
- {
- read_joystick(0,x,y,&butt);
- }while(!(butt&3));
- }
- else
- {
- do
- {
- read_joystick(1,x,y,&butt);
- }while(butt&3);
- do
- {
- read_joystick(1,x,y,&butt);
- }while(!(butt&3));
- }
- }
- int sqrt_i(int a)
- {
- int x,d,b;
- int bt=0x80000000;
-
- if (a <= 0) return (0);
-
- for (b=32; b>0; b--)
- {
- if (a&bt)
- break;
- else
- bt>>=1;
- }
- x=1<<(b>>1);
- while (d = ((((x * x - a) / x) + 1) >> 1))
- x-=d;
- return (x);
- }
- void normalise_joy_i(volatile int *x,volatile int *y)
- {
- int d;
- d=(((*x)*(*x))+((*y)*(*y)));
- d<<=12;
- if (d>0)
- {
- d=sqrt_i(d);
- *x<<=21;
- *x/=d;
- *y<<=21;
- *y/=d;
- }
- else
- {
- *x=*y=0;
- }
- }
- int calc_dist_i(int x,int y)
- {
- return (sqrt_i(x*x+y*y));
- }
- void get_joy_dir1(volatile int *x,volatile int *y,volatile int *f)
- {
- unsigned short rx,ry;
- unsigned char sw;
- int d;
- *x=*y=0;
- read_joy1(&rx,&ry,&sw);
- *x=rx-joy1_cnt_x;
- *y=ry-joy1_cnt_y;
- ux1=*x;
- ux2=*y;
- d=calc_dist_i((joy1_max_x-joy1_min_x),(joy1_max_y-joy1_min_y))*dead_zone/200;
- if (calc_dist_i(*x,*y)<d)
- {
- joy1_move=FALSE;
- *x=*y=0;
- }
- else
- {
- joy1_move=TRUE;
- normalise_joy_i(x,y);
- }
- if (digital_joy1)
- {
- if (!joy1_move)
- {
- *x=*y=0;
- }
- else
- {
- int d=0;
- if (*y>=0)
- {
- if (*x>=0)
- {
- if (*x>*y)
- {
- if (*x>((*y)*2))
- {
- *x=TUNIT;
- *y=0;
- }
- else
- {
- *x=TDIAG;
- *y=TDIAG;
- }
- }
- else
- {
- if (*y>((*x)*2))
- {
- *x=0;
- *y=TUNIT;
- }
- else
- {
- *x=TDIAG;
- *y=TDIAG;
- }
- }
- }
- else
- {
- if (-*x>*y)
- {
- if (-*x>((*y)*2))
- {
- *x=-TUNIT;
- *y=0;
- }
- else
- {
- *x=-TDIAG;
- *y=TDIAG;
- }
- }
- else
- {
- if (*y>(-(*x)*2))
- {
- *x=0;
- *y=TUNIT;
- }
- else
- {
- *x=-TDIAG;
- *y=TDIAG;
- }
- }
- }
- }
- else
- {
- if (*x>=0)
- {
- if (*x>-*y)
- {
- if (x>(-(*y)*2))
- {
- *x=TUNIT;
- *y=0;
- }
- else
- {
- *x=TDIAG;
- *y=-TDIAG;
- }
- }
- else
- {
- if (-*y>((*x)*2))
- {
- *x=0;
- *y=-TUNIT;
- }
- else
- {
- *x=TDIAG;
- *y=-TDIAG;
- }
- }
- }
- else
- {
- if (-*x>-*y)
- {
- if (-*x>(-*y*2))
- {
- *x=TUNIT;
- *y=0;
- }
- else
- {
- *x=-TDIAG;
- *y=-TDIAG;
- }
- }
- else
- {
- if (-*y>(-(*x)*2))
- {
- *x=0;
- *y=-TUNIT;
- }
- else
- {
- *x=-TDIAG;
- *y=-TDIAG;
- }
- }
- }
- }
- }
- }
- *f=sw;
- }
- void get_joy_dir2(volatile int *x,volatile int *y,volatile int *f)
- {
- unsigned short rx,ry;
- unsigned char sw;
- int d;
- *x=*y=0;
- read_joy2(&rx,&ry,&sw);
- *x=rx-joy2_cnt_x;
- *y=ry-joy2_cnt_y;
- d=calc_dist_i((joy2_max_x-joy2_min_x),(joy2_max_y-joy2_min_y))*dead_zone/200;
- if (calc_dist_i(*x,*y)<d)
- {
- joy2_move=FALSE;
- *x=*y=0;
- }
- else
- {
- joy2_move=TRUE;
- normalise_joy_i(x,y);
- }
- if (digital_joy2)
- {
- if (!joy2_move)
- {
- *x=*y=0;
- }
- else
- {
- int d=0;
- if (*y>=0)
- {
- if (*x>=0)
- {
- if (*x>*y)
- {
- if (*x>((*y)*2))
- {
- *x=TUNIT;
- *y=0;
- }
- else
- {
- *x=TDIAG;
- *y=TDIAG;
- }
- }
- else
- {
- if (*y>((*x)*2))
- {
- *x=0;
- *y=TUNIT;
- }
- else
- {
- *x=TDIAG;
- *y=TDIAG;
- }
- }
- }
- else
- {
- if (-*x>*y)
- {
- if (-*x>((*y)*2))
- {
- *x=-TUNIT;
- *y=0;
- }
- else
- {
- *x=-TDIAG;
- *y=TDIAG;
- }
- }
- else
- {
- if (*y>(-(*x)*2))
- {
- *x=0;
- *y=TUNIT;
- }
- else
- {
- *x=-TDIAG;
- *y=TDIAG;
- }
- }
- }
- }
- else
- {
- if (*x>=0)
- {
- if (*x>-*y)
- {
- if (x>(-(*y)*2))
- {
- *x=TUNIT;
- *y=0;
- }
- else
- {
- *x=TDIAG;
- *y=-TDIAG;
- }
- }
- else
- {
- if (-*y>((*x)*2))
- {
- *x=0;
- *y=-TUNIT;
- }
- else
- {
- *x=TDIAG;
- *y=-TDIAG;
- }
- }
- }
- else
- {
- if (-*x>-*y)
- {
- if (-*x>(-*y*2))
- {
- *x=TUNIT;
- *y=0;
- }
- else
- {
- *x=-TDIAG;
- *y=-TDIAG;
- }
- }
- else
- {
- if (-*y>(-(*x)*2))
- {
- *x=0;
- *y=-TUNIT;
- }
- else
- {
- *x=-TDIAG;
- *y=-TDIAG;
- }
- }
- }
- }
- }
- }
- *f=sw;
- }
- /////////////
- // MOUSE //
- void get_mouse_dir(volatile struct user_config *user)
- {
- int x,y;
- ReportMouse();
- x=Mouse.x-160;
- y=Mouse.y-100;
- x<<=15;
- x/=160;
- y<<=15;
- y/=100;
- user->inp_fb=Mouse.b;
- user->inp_x=x;
- user->inp_y=y;
- MouseXYset(160,100); // reset mouse origin.
- }
- ////////////////
- // KEYBOARD //
- short get_key_code(signed char *ks)
- {
- int i;
- short k=0;
- signed short ki;
- for (i=0; i<6; i++)
- {
- ki=*ks++;
- if (ki<0)
- {
- ki=SPECIALK-ki;
- if (keys[ki])
- k+=(1<<i);
- }
- else
- if (keys[ki])
- k+=(1<<i);
- }
- return(k);
- }
- void get_key_dir(volatile struct user_config *user,signed char *kb)
- {
- short k;
- k=get_key_code(kb);
- user->inp_fb=FALSE;
- if (k>=32) // Fire 2
- {
- user->inp_fb=2;
- k-=32;
- }
- if (k>=16) // Fire 1
- {
- user->inp_fb+=1;
- k-=16;
- }
- switch(k)
- {
- case(0):
- user->inp_x=0;
- user->inp_y=0;
- break;
- case(1):
- user->inp_x=0;
- user->inp_y=-32768;
- break;
- case(2):
- user->inp_x=0;
- user->inp_y=32767;
- break;
-
- case(4):
- user->inp_x=-32768;
- user->inp_y=0;
- break;
- case(5):
- user->inp_x=-TDIAG;
- user->inp_y=-TDIAG;
- break;
- case(6):
- user->inp_x=-TDIAG;
- user->inp_y=TDIAG;
- break;
- case(7):
- user->inp_x=-32768;
- user->inp_y=0;
- break;
- case(8):
- user->inp_x=32767;
- user->inp_y=0;
- break;
- case(9):
- user->inp_x=TDIAG;
- user->inp_y=-TDIAG;
- break;
- case(10):
- user->inp_x=TDIAG;
- user->inp_y=TDIAG;
- break;
- case(11):
- user->inp_x=32767;
- user->inp_y=0;
- break;
- case(13):
- user->inp_x=0;
- user->inp_y=-32768;
- break;
- case(14):
- user->inp_x=0;
- user->inp_y=32767;
- break;
- default:
- user->inp_x=0;
- user->inp_y=0;
- break;
- }
- }
- ///////////////
- // GENERAL //
- void get_user_inputs()
- {
- int i;
- ReadJoys(&joy_pos);
- for (i=0; i<num_of_users; i++)
- {
- switch(users[i].control)
- {
- case(JOY1_CTRL):
- get_joy_dir1(&joy1_x,&joy1_y,&joy1_fire);
- users[i].inp_x=joy1_x;
- users[i].inp_y=joy1_y;
- users[i].inp_fb=joy1_fire;
- break;
-
- case(JOY2_CTRL):
- get_joy_dir2(&joy2_x,&joy2_y,&joy2_fire);
- users[i].inp_x=joy2_x;
- users[i].inp_y=joy2_y;
- users[i].inp_fb=joy2_fire;
- break;
-
- case(KEY1_CTRL):
- get_key_dir(&users[i],key1);
- break;
- case(KEY2_CTRL):
- get_key_dir(&users[i],key2);
- break;
- case(MOUSE_CTRL):
- get_mouse_dir(&users[i]);
- break;
- }
- }
- }
- void process_user_inputs()
- {
- int x,y,i,a,b;
- for (i=0; i<num_of_users; i++)
- {
- if (users[i].type && users[i].control!=NET_CTRL) // Not computer or net guy
- {
- x=users[i].inp_x;
- y=users[i].inp_y;
- a=x*icth;
- b=y*isth;
- a=(a-b)>>15;
- if (a<-32767)
- a=-32767;
- if (a>32767)
- a=32767;
- users_dir_i[writeptr][i].x_f1=a;
- a=y*icth;
- b=x*isth;
- a=(a+b)>>15;
- if (a<-32767)
- a=-32767;
- if (a>32767)
- a=32767;
- users_dir_i[writeptr][i].y_f2=a;
- users_dir_i[writeptr][i].x_f1&=0xfffe;
- users_dir_i[writeptr][i].x_f1|=(users[i].inp_fb&1);
- users_dir_i[writeptr][i].y_f2&=0xfffe;
- users_dir_i[writeptr][i].y_f2|=((users[i].inp_fb&2)>>1);
- users[i].inp_ox=x;
- users[i].inp_oy=y;
- }
- }
- }
- /**************************/
- /* INTERRUPT TIMER CODE */
- /**************************/
- unsigned int NetworkHandle; // Handle for this timer routine
- void __far nethandler(void)
- {
- int i;
- count++;
- ftick+=game_speed;
- if (ftick>=TIMER_SPEED)
- {
- do
- ftick-=TIMER_SPEED;
- while (ftick>TIMER_SPEED);
- tick++;
- hold_loop=1; //ACTIVE
- if (!old_mf)
- {
- if (netsetup_on) // If in network setup...
- {
- if (network_on)
- NetInitialisation(); // Scan for new nodes and player data
- }
- else
- {
- if (network_on) // If a network game...
- {
- if (wConsoleNode==master) // If master...
- {
- if ( start_multiple==network_on-1 ) // If all data sent last frame
- {
- for (i=0;i<MAX_NET_USERS;i++)
- {
- users_dir_i[writeptr][i].x_f1=users_dir_i[(writeptr-1)&511][i].x_f1; // Copy all last input data for defaults
- users_dir_i[writeptr][i].y_f2=users_dir_i[(writeptr-1)&511][i].y_f2; // ...
- }
- get_user_inputs(); // Read own input data..
- process_user_inputs();
- if (!(tick&7)) putch('.');
- receive_all_singles(); // Receive input data from all other machines
- }
- if (active_nodes==network_on) // Only start transmitting when ready
- {
- if (start_multiple!=network_on-1 || !paused) // Stop sending if paused, and block fully transmitted
- {
- send_multiple();
- if ( start_multiple==network_on-1 ) // If block fully transmitted, move to next
- {
- writeptr++;
- writeptr&=511;
- }
- }
- }
- }
- else // If slave...
- {
- get_user_inputs(); // Read own input data
- process_user_inputs();
- for (i=0; i<network_on; i++)
- if (users[i].type && users[i].control!=NET_CTRL && // If local human user,...
- (users_dir_i[writeptr][i].x_f1!=users_dir_i[(writeptr-1)&511][i].x_f1 || // and input has changed...
- users_dir_i[writeptr][i].y_f2!=users_dir_i[(writeptr-1)&511][i].y_f2) )
- send_single(i); // then send to master
- receive_multiple(); // Receive all input data from master
- }
- }
- else // If not a network game...
- {
- if (!paused) // and not paused...
- {
- get_user_inputs();
- process_user_inputs();
- writeptr++;
- writeptr&=511; // Move to next block
- }
- }
- }
- }
- }
- }
- // Wait for next interrupt
- void TickPause()
- {
- int tcount;
- tcount=count;
- while (count<=tcount+TIMER_FRAC);
- }
- /********************/
- /* RECEIVING DATA */
- /********************/
- // Routine for master to receive all input data types.
- void receive_all_singles()
- {
- packet_header *header;
- packet_single *data;
- packet_info info;
- PSTR pPacket;
- if (network_on)
- {
- header=&in_header;
- while (hmiNETNOWGetHeader((PSTR)header,sizeof(packet_header),&pPacket))
- {
- switch(header->type)
- {
- case NET_ONLINE:
- hmiNETNOWGetBlock(pPacket,(PSTR) &info,sizeof(packet_info));
- // Master receiving data
- break;
- case NET_SINGLE:
- data=&users_dir_i[writeptr][header->player];
- hmiNETNOWGetBlock(pPacket,(PSTR)data,sizeof(packet_single));
- break;
- case NET_READY:
- puts("NET_READY received.");
- active_nodes++;
- break;
- case NET_QUIT:
- hmiNETNOWPostListen();
- send_quit(); // All quit if anyone quits!
- break;
- case NET_PAUSE:
- slave_pause=TRUE;
- break;
- }
- hmiNETNOWPostListen();
- }
- }
- }
- // Routine for slaves to receive all input data types.
- void receive_multiple()
- {
- packet_header *header;
- packet_multiple *data;
- packet_single *sing;
- packet_seed *seed;
- packet_info info;
- packet_pause pausep;
- PSTR pPacket;
- if (network_on)
- {
- header=&in_header;
- sing=&test_single;
- seed=&test_seed;
- while (hmiNETNOWGetHeader((PSTR)header,sizeof(packet_header),&pPacket))
- {
- switch(header->type)
- {
- case NET_ONLINE:
- hmiNETNOWGetBlock(pPacket,(PSTR) &info,sizeof(packet_info));
- // Slave receiving data
- break;
- case NET_MULTIPLE:
- data=(packet_multiple *)users_dir_i[writeptr];
- hmiNETNOWGetBlock(pPacket,(PSTR)data,sizeof(packet_multiple));
- writeptr++;
- writeptr&=511;
- if (!net_quit) active_nodes=network_on;
- break;
- case NET_SEED:
- // Slave receiving seed
- hmiNETNOWGetBlock(pPacket,(PSTR)seed,sizeof(packet_seed));
- received_seed=seed->num?seed->num:1;
- break;
- case NET_QUIT:
- net_quit=TRUE;
- break;
- case NET_PAUSE:
- hmiNETNOWGetBlock(pPacket,(PSTR) &pausep,sizeof(packet_pause));
- paused=pausep.paused;
- break;
- }
- hmiNETNOWPostListen();
- }
- }
- }
- /******************/
- /* SENDING DATA */
- /******************/
- //Master transmits all input data, sends NET_MULTIPLE header and multiple packet
- void send_multiple()
- {
- packet_header *header;
- packet_multiple *data;
- int i,sent;
- if (network_on)
- {
- header=&p_header;
- data=&test_multiple;
- header->player=wConsoleNode;
- header->type=NET_MULTIPLE;
- header->frame=frame_number;
- frame_number++;
- // data=(packet_single *)users_dir_i[writeptr];
- for (i=0;i<network_on;i++)
- {
- data->inp[i].x=users_dir_i[writeptr][i].x_f1;
- data->inp[i].y=users_dir_i[writeptr][i].y_f2;
- }
- i=abs(start_multiple);
- sent=TRUE;
- while (i>=0 && sent)
- {
- if (i!=master)
- sent=hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,sizeof(packet_multiple),i);
- else
- sent=TRUE;
- if (sent) i--;
- }
- if (sent) start_multiple=network_on-1;
- else start_multiple=-i;
- }
- }
- // Slave sends own input data, send NET_SINGLE header and input packet to master
- void send_single(int plyr)
- {
- packet_header *header;
- packet_single *data;
- int wait;
- if (network_on)
- {
- header=&p_header;
- data=&test_single;
- header->player=wConsoleNode;
- header->type=NET_SINGLE;
- data=(packet_single *)&users_dir_i[writeptr][plyr];
- // do
- wait=hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,sizeof(packet_single),master);
- // while( !wait );
- }
- }
- // Slave is ready to play, send NET_READY header and null data packet to master
- void send_ready()
- {
- packet_header *header;
- packet_data *data;
- if (network_on)
- {
- header=&p_header;
- data=&p_data;
- header->player=wConsoleNode;
- header->type=NET_READY;
- if (wConsoleNode==master)
- active_nodes++; // If master just increase active nodes
- else
- {puts("NET_READY sent.");
- while( !hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,0,master) );
- }
- }
- }
- // Master sends a random seed, send NET_SEED header and seed packet to slaves
- void send_seed(int num)
- {
- packet_header *header;
- packet_seed *data;
- int i;
- if (network_on)
- {
- header=&p_header;
- data=&test_seed;
- header->player=wConsoleNode;
- header->type=NET_SEED;
- data->num=num;
- for (i=0;i<network_on;i++)
- if (i!=master)
- while( !hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,sizeof(packet_seed),i) );
- // puts("Net_seed sent");
- }
- }
- // Send a message, send NET_MESSAGE header and message packet containing string (watch maximum length) to everyone
- void send_mes(char *m)
- {
- packet_header *header;
- packet_data *data;
- WORD head_size,data_size;
- int i;
- if (network_on)
- {
- header=&p_header;
- data=&p_data;
- strcpy(data->mes,m);
- header->player=wConsoleNode;
- header->type=NET_MESSAGE;
- for (i=0;i<network_on;i++)
- {
- if (i!=wConsoleNode)
- while( !hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,sizeof(packet_data),i) );
- }
- }
- }
- // Player is to quit, send NET_QUIT header and null data packet, if master quits, all nodes quit
- void send_quit()
- {
- packet_header *header;
- packet_data *data;
- WORD head_size,data_size;
- int i;
- if (network_on)
- {
- header=&p_header;
- data=&p_data;
- header->player=wConsoleNode;
- header->type=NET_QUIT;
- if (wConsoleNode==master)
- {
- for (i=0;i<network_on;i++)
- if (i!=wConsoleNode)
- while( !hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,0,i) );
- net_quit=TRUE;
- }
- else while( !hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) data,0,master) );
- }
- }
- // Send pause request, send NET_PAUSE header and pause packet to master
- void send_pause()
- {
- packet_header header;
- packet_pause data;
- if (network_on)
- {
- header.type=NET_PAUSE;
- data.paused=!paused; //request to invert! (not used by master - simply inverts its copy!)
- while (!hmiNETNOWSendData((PSTR) &header,sizeof(packet_header),(PSTR) &data,sizeof(packet_pause),master));
- }
- }
- // Transmit pause to slaves, send NET_PAUSE header and pause packet to all slaves
- void transmitpausetoslaves(void)
- {
- //transmit new pause status to slaves
- packet_header header;
- packet_pause data;
- int i;
- if (network_on)
- {
- header.type=NET_PAUSE;
- data.paused=paused; //request to invert!
- for (i=0;i<network_on;i++)
- if (i!=master)
- while (!hmiNETNOWSendData((PSTR) &header,sizeof(packet_header),(PSTR) &data,sizeof(packet_pause),i));
- }
- }
- /****************************/
- /* INITIALISE/SYNCHRONISE */
- /****************************/
- // Send initialisation data to or from newly logged on node (broadcast message necessary, others must discard)
- void TransmitInit(void)
- {
- packet_header header;
- packet_info info;
- if (network_on)
- {
- // Send address & data
- info.address=laddress;
- info.Team_A=Team_A;
- info.Team_B=Team_B;
- info.Team=TeamChoice;
- info.Player=PlayerChoice;
- header.type=NET_ONLINE;
- while (!hmiNETNOWSendData((PSTR) &header,sizeof(packet_header),(PSTR) &info,sizeof(packet_info),_NETNOW_BROADCAST));
- }
- }
- // Finds if supplied address is in address list
- int FindAddress(_NETNOW_NODE_ADDR daddress)
- {
- int duplic=-1;
- int i,j;
- char diff;
- char *a1,*a2;
- int sizeaddress;
- sizeaddress=sizeof(_NETNOW_NODE_ADDR);
- for (i=0;i<network_on;i++)
- {
- diff=FALSE;
- for (j=0;j<sizeaddress;j++)
- {
- a1=(char *) &address[i];
- a2=(char *) &daddress;
- if (*(a1+j)!=*(a2+j)) diff=TRUE;
- }
- if (!diff) { duplic=i; break; }
- }
- return (duplic);
- }
- void NetInitialisation()
- {
- packet_header header;
- packet_info info;
- packet_seed *seed;
- PSTR pPacket;
- _NETNOW_NODE_ADDR taddress;
- int error,Node;
- int i;
- seed=&test_seed;
- // wNETNodes=network_on;
- while (hmiNETNOWGetHeader((PSTR) &header,sizeof(packet_header),&pPacket))
- {
- switch(header.type)
- {
- // Received online broadcast...
- case NET_ONLINE:
- hmiNETNOWGetBlock(pPacket,(PSTR) &info,sizeof(packet_info));
- // Have we already added this node (will happen a lot because this is a broadcast message)
- if (FindAddress(info.address)<0 && !NetDone)
- {
- // This is a new node - add it in.
- error=hmiNETNOWAddNode(&info.address);
- switch(error)
- {
- case _NETNOW_ADD_COMPLETE:
- hmiNETNOWSortNodes();
- address[network_on]=info.address;
- if (info.Team_A>=0) Team_A=info.Team_A,Team_B=info.Team_B;
- Teams[network_on]=info.Team;
- Players[network_on]=info.Player;
- network_on++;
- // Send own data back through a NET_ONLINE message, those already on will ignore!!!
- TransmitInit();
- break;
- case _NETNOW_ADD_DUPLICATE:
- exit(1);
- break;
- case _NETNOW_ADD_LIST_FULL:
- exit(1);
- break;
- default:
- break;
- }
- }
- break;
- // Received go message, find node number; no more people can log on now.
- case NET_GO:
- if (!net_players[header.player])
- {
- NetDone++;
- net_players[header.player]=TRUE;
- // if (NetDone<=1)
- // {
- // SendNetDone();
- // FoundNodes();
- // SendPlayerInfo();
- // }
- }
- break;
- // Received initialisation info (team or player choices)
- case NET_INFO:
- hmiNETNOWGetBlock(pPacket,(PSTR) &info,sizeof(packet_info));
- // Set up player data
- if (info.Team_A>=0)
- {
- Team_A=info.Team_A;
- Team_B=info.Team_B;
- }
- else
- {
- Node=FindAddress(info.address);
- if (header.player>=0)
- {
- // Informant has sent his node value, swap own data structures to match...
- taddress=address[Node];
- address[Node]=address[header.player];
- address[header.player]=taddress;
- Teams[Node]=Teams[header.player];
- Players[Node]=Players[header.player];
- Node=header.player;
- }
- Teams[Node]=info.Team;
- Players[Node]=info.Player;
- }
- break;
- // Received seed from master
- case NET_SEED:
- // puts("Net_seed found");
- hmiNETNOWGetBlock(pPacket,(PSTR)seed,sizeof(packet_seed));
- received_seed=seed->num?seed->num:1;
- break;
- // Received quit command from master
- case NET_QUIT:
- puts("Net_quit found");
-
- net_quit=TRUE;
- break;
- }
- hmiNETNOWPostListen();
- }
- }
- // Finished waiting for new nodes, find no of nodes and own node number
- void FoundNodes()
- {
- if (master!=0)
- {
- network_on=hmiNETNOWGetActiveNodes(); // Get active nodes
- wConsoleNode=hmiNETNOWGetConsoleNode(); // Get console node
- master=0;
- // num_of_users=network_on;
- start_multiple=network_on-1;
- }
- }
- // Player presses start
- void SendNetDone()
- {
- packet_header header;
- packet_data data;
- int i,node,tval;
- NetDone++;
- FoundNodes();
- node=FindAddress(laddress);
- address[node]=address[wConsoleNode];
- address[wConsoleNode]=laddress;
- tval=Teams[node];
- Teams[node]=Teams[wConsoleNode];
- Teams[wConsoleNode]=tval;
- tval=Players[node];
- Players[node]=Players[wConsoleNode];
- Players[wConsoleNode]=tval;
- net_players[wConsoleNode]=TRUE;
- header.player=wConsoleNode;
- header.type=NET_GO;
- for (i=0;i<network_on;i++)
- if (i!=wConsoleNode)
- while (!hmiNETNOWSendData((PSTR) &header,sizeof(packet_header),(PSTR) &data,0,i));
- SendPlayerInfo();
- }
- void SendTeamInfo()
- {
- packet_header *header;
- packet_info info;
- int i;
- if (network_on)
- {
- header=&p_header;
- // Set up team data
- info.Team_A=Team_A;
- info.Team_B=Team_B;
- header->type=NET_INFO;
- for (i=0;i<network_on;i++)
- if (i!=wConsoleNode)
- while (!hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) &info,sizeof(packet_info),i));
- }
- }
- void SendPlayerInfo()
- {
- packet_header *header;
- packet_info info;
- int i;
- if (network_on)
- {
- header=&p_header;
- // Set up player data
- info.Team_A=info.Team_B=-1;
- info.Team=TeamChoice;
- info.Player=PlayerChoice;
- info.address=address[(wConsoleNode<0) ? 0 : wConsoleNode];
- header->player=wConsoleNode;
- header->type=NET_INFO;
- for (i=0;i<network_on;i++)
- if (i!=wConsoleNode)
- while( !hmiNETNOWSendData((PSTR) header,sizeof(packet_header),(PSTR) &info,sizeof(packet_info),i) );
- }
- }
- void pausehandler()
- {
- if (pause_request)
- {
- if (!network_on)
- {
- paused=!paused;
- }
- else
- {
- if (wConsoleNode==master)
- {
- //master initiated pause.
- paused=!paused;
- transmitpausetoslaves(); //all machines will pause
- }
- else
- {
- send_pause(); //send pause to master
- }
- }
- pause_request=FALSE;
- }
- if (network_on && slave_pause && wConsoleNode==master)
- {
- //master received a request to pause from slave
- paused=!paused;
- transmitpausetoslaves();
- slave_pause=FALSE;
- }
- }
- /*****************/
- /* NETWORK SETUP */
- /*****************/
- int Initialise_Network()
- {
- int i;
- // active_nodes=1; // if no network 1 player.
- net_quit=FALSE;
- master=-1;
- wConsoleNode=-1;
- if (network_on)
- {
- received_seed=FALSE;
- frame_number=0;
- active_nodes=0; //reset if network on.
- // puts ("INTIALIZING NETWORK.");
- if ( hmiNETNOWInitSystem( 16 ) != _NETNOW_NO_ERROR )
- {
- // puts( "ERROR: NetNOW! could not locate IPX or NetBIOS!" );
- network_on=FALSE;
- netsetup_on=FALSE;
- old_mf=TRUE;
- return(-1); //...
- }
- else
- {
- // puts( "NetNOW! system initialized!" );
- // Check for information display
- if ( wNETInfoFlag )
- switch( hmiNETNOWGetNetworkType() )
- {
- case _NETNOW_IPX :
- // display type
- // puts( "Network is using a IPX based protocol." );
- break;
- case _NETNOW_NETBIOS:
- // display type
- // puts( "Network is using a NetBIOS based protocol." );
- break;
- }
- while (hmiNETNOWPostListen());
- for (i=0;i<MAX_NET_USERS;i++) net_players[i]=FALSE;
- hmiNETNOWGetNetworkAddr(&laddress); //read this nodes address.
- address[0]=laddress;
- TransmitInit(); //send NET_ONLINE (with address) as a broadcast to other machines
- NetDone=0;
- network_on=onetwork_on=1;
- }
- }
- return (0);
- }
- void close_network()
- {
- packet_header *header;
- PSTR pPacket;
- short head_size;
- if (network_on)
- {
- // puts("Resetting network.");
- header=&in_header;
- hmiNETNOWPostListen();
- while (hmiNETNOWGetHeader((PSTR)header,sizeof(packet_header),&pPacket)) hmiNETNOWPostListen();
- hmiNETNOWUnInitSystem();
- // puts("Network removed.");
- }
- netsetup_on=FALSE;
- network_on=FALSE;
- old_mf=TRUE;
- master=-1;
- }
- int Poll_Network()
- {
- static scount=0;
- int i,s;
- // if (!(count&127)) putch('.');
- // if (keys[0x13]) {close_network();exit(1);}
- if (NetDone<network_on)
- {
- return (-1);
- if (onetwork_on!=network_on)
- {
- for (i=onetwork_on;i<network_on;i++)
- printf("\nFound node %d\n",i);
- onetwork_on=network_on;
- }
- return (-1);
- }
- else
- {
- if (wConsoleNode==master)
- {
- if (!(s=clock()&0xffff)) s=1;
- send_seed(s);
- }
- else
- while(!(s=received_seed));
- return (s);
- }
- }
- int Start_Network_Game()
- {
- int i;
- Team_A=-1;
- Team_B=-1;
- for (i=0; i<MAX_NET_USERS; i++)
- {
- Teams[i]=-1;
- Players[i]=-1;
- }
- TeamChoice=-1;
- PlayerChoice=-1;
- network_on=netsetup_on=TRUE;
- old_mf=FALSE;
- return (Initialise_Network());
- }
- void Network_Play_Ready()
- {
- if (network_on)
- {
- send_ready();
- while (active_nodes<network_on); // escape key?
- }
- }
- void Quit_Network_Play()
- {
- if (network_on)
- {
- send_quit();
- while (!net_quit); // Timeout??
- active_nodes=0;
- }
- }
- void End_Network_Game()
- {
- if (network_on)
- close_network();
- }
- int NetTest()
- {
- int i,Starts,Seed,stick;
- char TeamsSelected,ChoiceAltered,StartPressed;
- //...whatever front end stuff comes first...
- // There are variables Team_A & Team_B for teams playing, TeamChoice for this players choice from these
- // two, (value 0 or 1), PlayerChoice is the player in the team chosen, 1 to 11 (1 indicates auto-player).
- // The variable network_on is the number of players currently logged on to the game, and the arrays
- // Teams[] and Players[] give the current selections of all the players from 0 to network_on-1, (Note, which is
- // your entry in this array is NOT stored!), you may also want to use the local variable Starts (see below)
- if (Start_Network_Game()<0) // Initialises Team_A, Team_B, TeamChoice & PlayerChoice and starts network
- {
- old_mf=1;
- return(-1);
- }
- TickPause();
- stick=tick;
- // Choose teams to play
- while (Team_A<0) // Wait until they are chosen (add escape key?)
- {
- TeamsSelected=1; // Your condition
- // If local user sets Team_A & Team_B first send them using SendTeamInfo()
- if (TeamsSelected)
- {
- Team_A=14;Team_B=0;
- SendTeamInfo();
- }
- TickPause();
- Poll_Network();
- }
- //printf("\nTeam %d plays team %d\n",Team_A,Team_B);
- // Teams are chosen, allow player to choose team to play for and player to control...
- // 2 is added to TeamChoice when player presses start
- // puts("Choose team, 'A' or 'B', then press return");
- do
- {
- // If start has been pressed, no further selection allowed
- if (TeamChoice<2)
- {
- // Your condition
- ChoiceAltered=machine_no;
- // if (keys[0x1e]) ChoiceAltered=1;
- // if (keys[0x30]) ChoiceAltered=2;
- // If local user alters TeamChoice or PlayerChoice then call SendPlayerInfo();
- // Must check Players and Teams arrays to make sure no-one else has chosen the same
- if (ChoiceAltered)
- {
- TeamChoice=ChoiceAltered-1;
- // if (TeamChoice==0) puts("Team A chosen");
- // else puts("Team B chosen");
- PlayerChoice=1;
- SendPlayerInfo();
- }
- // Your condition
- StartPressed=1;//(keys[0x1c]);
-
- // If the start button is pressed and team is chosen add 2 to TeamChoice...
- if (TeamChoice>=0 && PlayerChoice>=0 && StartPressed)
- {
- // puts("OK, now waiting for others to start");
- TeamChoice+=2;
- SendPlayerInfo();
- }
- }
- TickPause();
- Poll_Network();
- // Condition indicating selection complete (player chosen + start button), perhaps Starts should be displayed
- Starts=0;
- for (i=0;i<network_on;i++)
- if (Teams[i]>=2) Starts++;
- } while ((Starts<network_on || Starts<=1) && tick<stick+10*20); // Must be more than one player!
- if (tick<stick+10*20)
- {
- // Final syncronisation (sorts nodes and sets random seed)
- SendNetDone();
- while ((Seed=Poll_Network())<0); // (Add escape key?)
- netsetup_on=FALSE;
- // Remove start flags from team data
- for (i=0;i<network_on;i++)
- Teams[i]-=2;
- // Now set Andy's data structures from the network variables
- // printf("\nTeam %d plays team %d\n",Team_A,Team_B);
- // printf("This node is %d\n",wConsoleNode);
- // printf("This node chose team %d, player %d\n",TeamChoice,PlayerChoice);
- // for (i=0;i<network_on;i++)
- // printf("Node %d plays team %d, player %d\n",i,Teams[i],Players[i]);
- // printf("Seed is %d\n",Seed);
- }
- else
- {
- End_Network_Game(); // Cleans up network stuff
- old_mf=1;
- return (-1);
- }
- // ...call the game...
- // ...whetever front end stuff comes after...
- return (0);
- }
- void crap()
- {
- printf(" net %d %d \n",*(int *)&users[0].inp_x,&users[0].inp_x);
- }
|