home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / sd-27.zip / sd16.c < prev    next >
C/C++ Source or Header  |  1992-08-10  |  7KB  |  211 lines

  1. /* SD -- square dance caller's helper.
  2.  
  3.     Copyright (C) 1990, 1991, 1992  William B. Ackerman.
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 1, or (at your option)
  8.     any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     This is version 24.0. */
  20.  
  21. /* This defines the following functions:
  22.    phantom_2x4_move
  23. */
  24.  
  25. #include "sd.h"
  26.  
  27.  
  28. /* This handles only the T-boned case.  Other cases are handled elsewhere. */
  29.  
  30. extern void phantom_2x4_move(
  31.    setup *ss,
  32.    int lineflag,
  33.    phantest_kind phantest,
  34.    map_thing *maps,
  35.    parse_block *parseptr,
  36.    setup *result)
  37.  
  38. {
  39.    setup a1v, a2v, a1h, a2h;
  40.    setup b1v, b2v, b1h, b2h;
  41.    setup hpeople, vpeople;
  42.    int i, r, m1, m2;
  43.    int v1flag, v2flag, h1flag, h2flag;
  44.    int vflag, hflag;
  45.    veryshort *map_ptr1, *map_ptr2;
  46.    int finalsetupflags;
  47.  
  48.    warn(warn__tbonephantom);
  49.  
  50.    vflag = 0;
  51.    hflag = 0;
  52.    hpeople = *ss;
  53.    vpeople = *ss;
  54.    clear_people(&hpeople);
  55.    clear_people(&vpeople);
  56.    
  57.    for (i=0; i<16; i++) {
  58.       int temp = ss->people[i].id1;
  59.       if ((temp ^ lineflag) & 1) {
  60.          (void) copy_rot(&hpeople, (i+4) & 017, ss, i, 011);
  61.          hflag |= temp;
  62.       }
  63.       else {
  64.          (void) copy_person(&vpeople, i, ss, i);
  65.          vflag |= temp;
  66.       }
  67.    }
  68.  
  69.    v1flag = 0;
  70.    v2flag = 0;
  71.    h1flag = 0;
  72.    h2flag = 0;
  73.  
  74.    clear_people(result);
  75.    finalsetupflags = 0;
  76.  
  77.    map_ptr1 = maps->map1;
  78.    map_ptr2 = maps->map2;
  79.  
  80.    for (i=0; i<8; i++) {
  81.       m1 = map_ptr2[i];
  82.       m2 = map_ptr1[i];
  83.       v1flag |= copy_rot(&a1v, i, &vpeople, m1, 033);
  84.       v2flag |= copy_rot(&a2v, i, &vpeople, m2, 033);
  85.       h1flag |= copy_rot(&a1h, i, &hpeople, m1, 033);
  86.       h2flag |= copy_rot(&a2h, i, &hpeople, m2, 033);
  87.    }
  88.    
  89.    /* ***** this next stuff doesn't really do the right thing.  If people are T-boned
  90.       but no one sees a violation of bigblock among those with the same orientation
  91.       as himself, it won't complain, even though the total setup violates bigblock. */
  92.  
  93.    if ((vflag && !(v1flag && v2flag)) || (hflag && !(h1flag && h2flag))) {
  94.       /* Only one of the two setups is occupied. */
  95.       switch (phantest) {
  96.          /* **** bug: If T-boned, this message comes out if either orientation of people fails
  97.             to occupy both of their setups.  But it could easily happen that the "phantom lines"
  98.             concept is superfluous for the north-south people but completely meaningful for the
  99.             east-west people. */
  100.          case phantest_both:
  101.             fail("Don't use phantom concept if you don't mean it.");
  102.          case phantest_impossible:
  103.             fail("This is impossible in a symmetric setup!!!!");
  104.          case phantest_first_or_both:
  105.             if (v2flag | h2flag) fail("Don't use phantom concept if you don't mean it.");
  106.             break;
  107.          case phantest_only_first_one:
  108.             if (v2flag | h2flag) fail("Not in correct setup.");
  109.             break;
  110.          case phantest_only_second_one:
  111.             if (v1flag | h1flag) fail("Not in correct setup.");
  112.             break;
  113.       }
  114.    }
  115.    else {
  116.       /* Both of the two setups are occupied. */
  117.       switch (phantest) {
  118.          case phantest_only_one:
  119.          case phantest_only_first_one:
  120.          case phantest_only_second_one:
  121.             fail("Can't find the setup to work in.");
  122.       }
  123.    }
  124.    
  125.    if (v1flag) {
  126.       a1v.kind = s2x4;
  127.       a1v.rotation = 0;
  128.       a1v.setupflags = ss->setupflags | SETUPFLAG__DISTORTED;
  129.       move(&a1v, parseptr, NULLCALLSPEC, 0, FALSE, &b1v);
  130.       finalsetupflags |= b1v.setupflags;
  131.    }
  132.    else
  133.       b1v.kind = nothing;
  134.    
  135.    if (v2flag) {
  136.       a2v.kind = s2x4;
  137.       a2v.rotation = 0;
  138.       a2v.setupflags = ss->setupflags | SETUPFLAG__DISTORTED;
  139.       move(&a2v, parseptr, NULLCALLSPEC, 0, FALSE, &b2v);
  140.       finalsetupflags |= b2v.setupflags;
  141.    }
  142.    else
  143.       b2v.kind = nothing;
  144.    
  145.    if (h1flag) {
  146.       a1h.kind = s2x4;
  147.       a1h.rotation = 0;
  148.       a1h.setupflags = ss->setupflags | SETUPFLAG__DISTORTED;
  149.       move(&a1h, parseptr, NULLCALLSPEC, 0, FALSE, &b1h);
  150.       finalsetupflags |= b1h.setupflags;
  151.    }
  152.    else
  153.       b1h.kind = nothing;
  154.    
  155.    if (h2flag) {
  156.       a2h.kind = s2x4;
  157.       a2h.rotation = 0;
  158.       a2h.setupflags = ss->setupflags | SETUPFLAG__DISTORTED;
  159.       move(&a2h, parseptr, NULLCALLSPEC, 0, FALSE, &b2h);
  160.       finalsetupflags |= b2h.setupflags;
  161.    }
  162.    else
  163.       b2h.kind = nothing;
  164.  
  165.    
  166.    if (b1v.kind != nothing) {
  167.       if (b1v.kind != s2x4) fail("Can't do this call with phantom C/L/W concept.");
  168.       r = b1v.rotation & 3;
  169.       if (r & 1) fail("Can't do shape changer with phantom C/L/W concept.");
  170.       else if (r == 0)
  171.          for (i=0; i<8; i++) install_rot(result, map_ptr2[i], &b1v, i, 011);
  172.       else
  173.          for (i=0; i<8; i++) install_rot(result, map_ptr2[i], &b1v, (i+4) & 7, 033);
  174.    }
  175.    
  176.    if (b2v.kind != nothing) {
  177.       if (b2v.kind != s2x4) fail("Can't do this call with phantom C/L/W concept.");
  178.       r = b2v.rotation & 3;
  179.       if (r & 1) fail("Can't do shape changer with phantom C/L/W concept.");
  180.       else if (r == 0)
  181.          for (i=0; i<8; i++) install_rot(result, map_ptr1[i], &b2v, i, 011);
  182.       else
  183.          for (i=0; i<8; i++) install_rot(result, map_ptr1[i], &b2v, (i+4) & 7, 033);
  184.    }
  185.    
  186.    if (b1h.kind != nothing) {
  187.       if (b1h.kind != s2x4) fail("Can't do this call with phantom C/L/W concept.");
  188.       r = b1h.rotation & 3;
  189.       if (r & 1) fail("Can't do shape changer with phantom C/L/W concept.");
  190.       else if (r == 0)
  191.          for (i=0; i<8; i++) install_person(result, (map_ptr2[i]+12) & 017, &b1h, i);
  192.       else
  193.          for (i=0; i<8; i++) install_rot(result, (map_ptr2[i]+12) & 017, &b1h, (i+4) & 7, 022);
  194.    }
  195.    
  196.    if (b2h.kind != nothing) {
  197.       if (b2h.kind != s2x4) fail("Can't do this call with phantom C/L/W concept.");
  198.       r = b2h.rotation & 3;
  199.       if (r & 1) fail("Can't do shape changer with phantom C/L/W concept.");
  200.       else if (r == 0)
  201.          for (i=0; i<8; i++) install_person(result, (map_ptr1[i]+12) & 017, &b2h, i);
  202.       else
  203.          for (i=0; i<8; i++) install_rot(result, (map_ptr1[i]+12) & 017, &b2h, (i+4) & 7, 022);
  204.    }
  205.    
  206.    result->setupflags = finalsetupflags;
  207.    result->kind = s4x4;
  208.    result->rotation = 0;
  209.    reinstate_rotation(ss, result);
  210. }
  211.