home *** CD-ROM | disk | FTP | other *** search
/ Superpower (Alt) / SUPERPOWER.iso / q / util / mbq312 / procs.c next >
Encoding:
Text File  |  1996-07-16  |  8.3 KB  |  331 lines

  1. char temp[1024];
  2.  
  3. void insertnewbrush(void)
  4. {
  5.     brush[numbrushes].x=-50;
  6.     brush[numbrushes].y=-50;
  7.     brush[numbrushes].z=-50;
  8.     brush[numbrushes].xl=50;
  9.     brush[numbrushes].yl=50;
  10.     brush[numbrushes].zl=50;
  11.     strcpy(&brush[numbrushes].texture,&defaulttex);
  12.     curbrush=numbrushes;
  13.     numbrushes++;
  14. }
  15.  
  16. void drawbrushes(void)
  17. {
  18. unsigned char b;
  19. int vx,vy,vz,vxl,vyl,vzl;
  20.  
  21.     cleardevice();
  22.     for (b=0;b<numbrushes;b++) {
  23.  
  24.         setcolor(7);
  25.         if (b==curbrush) setcolor(12);
  26.             if (curview==0) if (zoommode==1) rectangle(brush[b].x+xdiv,brush[b].y+ydiv,brush[b].xl+xdiv,brush[b].yl+ydiv);
  27.                 else rectangle((brush[b].x / zoommode)+xdiv,(brush[b].y / zoommode)+ydiv,(brush[b].xl / zoommode)+xdiv,(brush[b].yl / zoommode)+ydiv);
  28.  
  29.             if (curview==1) if (zoommode==1) rectangle(brush[b].y+xdiv,(brush[b].z*-1)+ydiv,brush[b].yl+xdiv,(brush[b].zl*-1)+ydiv);
  30.                 else rectangle((brush[b].y / zoommode)+xdiv,((brush[b].z / zoommode)*-1)+ydiv,(brush[b].yl / zoommode)+xdiv,((brush[b].zl / zoommode)*-1)+ydiv);
  31.  
  32.             if (curview==2) if (zoommode==1) rectangle(brush[b].x+xdiv,(brush[b].z*-1)+ydiv,brush[b].xl+xdiv,(brush[b].zl*-1)+ydiv);
  33.                 else rectangle((brush[b].x / zoommode)+xdiv,((brush[b].z / zoommode)*-1)+ydiv,(brush[b].xl / zoommode)+xdiv,((brush[b].zl / zoommode)*-1)+ydiv);
  34.  
  35.         setcolor(12);
  36.             if (curview==0) if (zoommode==1) rectangle(brush[curbrush].x+xdiv,brush[curbrush].y+ydiv,brush[curbrush].xl+xdiv,brush[curbrush].yl+ydiv);
  37.                 else rectangle((brush[curbrush].x / zoommode)+xdiv,(brush[curbrush].y / zoommode)+ydiv,(brush[curbrush].xl / zoommode)+xdiv,(brush[curbrush].yl / zoommode)+ydiv);
  38.  
  39.             if (curview==1) if (zoommode==1) rectangle(brush[curbrush].y+xdiv,(brush[curbrush].z*-1)+ydiv,brush[curbrush].yl+xdiv,(brush[curbrush].zl*-1)+ydiv);
  40.                 else rectangle((brush[curbrush].y / zoommode)+xdiv,((brush[curbrush].z / zoommode)*-1)+ydiv,(brush[curbrush].yl / zoommode)+xdiv,((brush[curbrush].zl / zoommode)*-1)+ydiv);
  41.  
  42.             if (curview==2) if (zoommode==1) rectangle(brush[curbrush].x+xdiv,(brush[curbrush].z*-1)+ydiv,brush[curbrush].xl+xdiv,(brush[curbrush].zl*-1)+ydiv);
  43.                 else rectangle((brush[curbrush].x / zoommode)+xdiv,((brush[curbrush].z / zoommode)*-1)+ydiv,(brush[curbrush].xl / zoommode)+xdiv,((brush[curbrush].zl / zoommode)*-1)+ydiv);
  44.  
  45.         setcolor(8);
  46.         line(0,470,0,479); line(0,479,10,479);
  47.  
  48.         if (curview==0) {
  49.             outtextxy(0,459,"x");
  50.             outtextxy(10,469,"y");
  51.         }
  52.  
  53.         if (curview==1) {
  54.             outtextxy(0,459,"y");
  55.             outtextxy(10,469,"z");
  56.         }
  57.  
  58.         if (curview==2) {
  59.             outtextxy(0,459,"x");
  60.             outtextxy(10,469,"z");
  61.         }
  62.     }
  63.  
  64.  
  65.     strcpy(&workstr,"zm: ");
  66.     strcat(&workstr,itoa(zoommode,temp,10));
  67.     outtextxy(30,469,workstr);
  68.  
  69.     strcpy(&workstr,itoa((brush[curbrush].x-brush[curbrush].xl)*-1,temp,10));
  70.     strcat(&workstr," ");
  71.     strcat(&workstr,itoa((brush[curbrush].y-brush[curbrush].yl)*-1,temp,10));
  72.     strcat(&workstr," ");
  73.     strcat(&workstr,itoa((brush[curbrush].z-brush[curbrush].zl)*-1,temp,10));
  74.     strcat(&workstr," ");
  75.     strcat(&workstr,brush[curbrush].texture);
  76.  
  77.     outtextxy(80,469,workstr);
  78.  
  79.     if (movemode==1) outtextxy(20,459,"M");
  80.     putpixel(0+xdiv,0+ydiv,15);
  81. }
  82.  
  83. void getnewdefaulttexture()
  84. {
  85.     outtextxy(0,40,"Enter default texture for new inserted brushes: ");
  86.     gotoxy(1,1);
  87.     gets(defaulttex);
  88.     if (numbrushes>0) drawbrushes(); else cleardevice();
  89. }
  90.  
  91. /* this is VERY buggy, i think (not sure) */
  92. void deletecurbrush(void)
  93. {
  94. unsigned char i;
  95.  
  96.     if (numbrushes>1) {
  97.     for (i=curbrush;i<numbrushes-2;i++) brush[i]=brush[i+1];
  98.     numbrushes--;
  99.     if (curbrush>=numbrushes) curbrush=0;
  100.     }
  101.     else outtextxy(0,0,"gotta have at least one brush...");
  102. }
  103.  
  104.  
  105.  
  106. void getnewmoverate(void)
  107. {        
  108.         outtextxy(0,40,"Enter new moverate: ");
  109.     gotoxy(1,1);
  110.     gets(temp);
  111.     moverate = atoi(temp);
  112.     if (numbrushes>0) drawbrushes();
  113.         else cleardevice();
  114. }
  115.  
  116. void save(void)
  117. {
  118.     FILE *f;
  119.     FILE *e;
  120.     cube_t c;
  121.     ent_t  en;
  122.     char saveas[20];
  123.     char fstring[20];
  124.     unsigned char i;
  125.  
  126.     if (numbrushes>0) {
  127.         outtextxy(0,40,"Do not give an extension!  save as: ");
  128.         gotoxy(0,0);
  129.         gets(saveas);
  130.         strcpy(&fstring,&saveas);
  131.         strcat(&fstring,".qck");
  132.         f = fopen(fstring,"wb");
  133.         for (i=0;i<numbrushes;i++) {
  134.             c = brush[i];
  135.             strcpy(&temp,&c.texture);
  136.             c.texture[0] = strlen(&temp);
  137.             strcpy(&c.texture[1],&temp);
  138.             fwrite(&c, sizeof(c), 1, f);
  139.         }
  140.         fclose(f);
  141.  
  142.         strcpy(&fstring,&saveas);
  143.         strcat(&fstring,".ent");
  144.         e = fopen(fstring,"wb");
  145.         for (i=0;i<numentities;i++) {
  146.             en = entity[i];
  147.             strcpy(&temp,&en.class);
  148.             en.class[0] = strlen(&temp);
  149.             strcpy(&en.class[1],&temp);
  150.             fwrite(&en, sizeof(en), 1, e);
  151.         }
  152.         fclose(e);
  153.         drawbrushes();
  154.         outtextxy(0,0,"Saved...");
  155.     }
  156.     else outtextxy(0,0,"nothing to save.");
  157. }
  158.  
  159. void insertnewentity(void)
  160. {
  161.  
  162.     strcpy(&entity[numentities].class,"info_player_start");
  163.     entity[numentities].ox=0;
  164.     entity[numentities].oy=0;
  165.     entity[numentities].oz=0;
  166.     entity[numentities].angle=0;
  167.     curentity=numentities;
  168.     numentities++;
  169. }
  170.  
  171. void load(void)
  172. {
  173.     FILE *f;
  174.     FILE *e;
  175.     char saveas[20];
  176.     char fstring[20];
  177.     unsigned char i;
  178.     char l[256];
  179.     cube_t c;
  180.     ent_t  en;
  181.  
  182.     outtextxy(0,40,"load brush and entity data (use shift-l for brushes only): ");
  183.     gotoxy(0,0);
  184.     gets(l);
  185.     if (l=="") goto alldone;
  186.     strcpy(&fstring,&l);
  187.     strcat(&fstring,".qck");
  188.     f = fopen(fstring,"rb");
  189.     numbrushes=0;
  190.     do {
  191.         if (fread(&c, sizeof(c), 1, f)==1) {
  192.             insertnewbrush();
  193.             brush[numbrushes-1]=c;
  194.             strcpy(&temp,c.texture);
  195.             temp[c.texture[0]+1]=0;
  196.             strcpy(&brush[numbrushes-1].texture[0],&temp[1]);
  197.         }
  198.     } while (!feof(f));
  199.     fclose(f);
  200.  
  201.     strcpy(&fstring,&l);
  202.     strcat(&fstring,".ent");
  203.     e = fopen(fstring,"rb");
  204.     numentities=0;
  205.     do {
  206.         if (fread(&en, sizeof(en), 1, e)==1) {
  207.             insertnewentity();
  208.             entity[numentities-1]=en;
  209.             strcpy(&temp,en.class);
  210.             temp[en.class[0]+1]=0;
  211.             strcpy(&entity[numentities-1].class[0],&temp[1]);
  212.         }
  213.     } while (!feof(e));
  214.     fclose(e);
  215.     alldone:
  216. }
  217.  
  218. void oldload(void)
  219. {
  220.     FILE *f;
  221.     char l[20];
  222.     char fstring[256];
  223.     unsigned char i;
  224.     cube_t c;
  225.  
  226.     outtextxy(0,40,"brushes only load: ");
  227.     gotoxy(0,0);
  228.     gets(l);
  229.     if (l=="") goto alldone;
  230.  
  231.     strcpy(&fstring,&l);
  232.     f = fopen(fstring,"rb");
  233.     numbrushes=0;
  234.     do {
  235.         if (fread(&c, sizeof(c), 1, f)==1) {
  236.             insertnewbrush();
  237.             brush[numbrushes-1]=c;
  238.             strcpy(&temp,c.texture);
  239.             temp[c.texture[0]+1]=0;
  240.             strcpy(&brush[numbrushes-1].texture[0],&temp[1]);
  241.         }
  242.     } while (!feof(f));
  243.     fclose(f);
  244.  
  245.     itoa(numbrushes,l,10);
  246.     strcpy(&workstr,"Loaded ");
  247.     strcat(&workstr,&l);
  248.     strcat(&workstr," brushes");
  249.     curview=0;
  250.     drawbrushes();
  251.     outtextxy(0,0,workstr);
  252. alldone:
  253. }
  254.  
  255.  
  256. void texture(void)
  257. {
  258.     char t[256];
  259.  
  260.     if (numbrushes>0) {
  261.         outtextxy(0,40,"New texture for this brush: ");
  262.         gotoxy(0,0);
  263.         gets(t);
  264.         strcpy(&brush[curbrush].texture,&t);
  265.     }
  266. }
  267.  
  268.  
  269. void drawentities(void)
  270. {
  271.     unsigned char e;
  272.     unsigned char r;
  273.  
  274.     r=2;
  275.     setcolor(7);
  276.     if (numentities>0) {
  277.         for (e=0;e<numentities;e++) {
  278.             if (curview==0) circle((entity[e].ox / zoommode)+xdiv,(entity[e].oy / zoommode)+ydiv,r);
  279.             if (curview==1) circle((entity[e].oy / zoommode)+xdiv,((entity[e].oz / zoommode)*-1)+ydiv,r);
  280.             if (curview==2) circle((entity[e].ox / zoommode)+xdiv,((entity[e].oz / zoommode)*-1)+ydiv,r);
  281.         }
  282.  
  283.         setcolor(12);
  284.  
  285.         if (curview==0) circle((entity[curentity].ox / zoommode)+xdiv,(entity[curentity].oy / zoommode)+ydiv,r);
  286.         if (curview==1) circle((entity[curentity].oy / zoommode)+xdiv,((entity[curentity].oz / zoommode)*-1)+ydiv,r);
  287.         if (curview==2) circle((entity[curentity].ox / zoommode)+xdiv,((entity[curentity].oz / zoommode)*-1)+ydiv,r);
  288.  
  289.         strcpy(&workstr,"Angle: ");
  290.         strcat(&workstr,itoa(entity[curentity].angle,temp,10));
  291.         outtextxy(400,459,workstr);
  292.         strcpy(&workstr,"Class: ");
  293.         strcat(&workstr,entity[curentity].class);
  294.         outtextxy(400,469,workstr);
  295.  
  296.     }
  297. }
  298.  
  299. void curentityangle(void)
  300. {
  301.     char s[256];
  302.     int i;
  303.  
  304.     if (numentities>0) {
  305.         outtextxy(0,40,"New angle for this entity: ");
  306.         gotoxy(0,0);
  307.         gets(s);
  308.         if (s=="") i=0;
  309.             else i = atoi(s);
  310.         entity[curentity].angle=i;
  311.     }
  312.     drawbrushes();
  313.     drawentities();
  314. }
  315.  
  316. void curentityclass(void)
  317. {
  318.     char s[256];
  319.  
  320.     if (numentities>0) {
  321.         outtextxy(0,40,"New classname for this entity: ");
  322.         gotoxy(0,0);
  323.         gets(s);
  324.         if (s=="") strcpy(&s,"info_player_start");
  325.             else strcpy(&entity[curentity].class,&s);
  326.     }
  327.     drawbrushes();
  328.     drawentities();
  329. }
  330.  
  331.