예제 #1
0
/**
**	Parse unit-type.
**
**	@param list	List describing missile.
*/
local SCM CclUnitType(SCM list)
{
    SCM value;
    int type;

    return list;

    //	Slot
    value=gh_car(list);
    type=gh_scm2int(value);
    list=gh_cdr(list);
    DebugLevel3("UnitType: %d\n",type);

    //	Name
    value=gh_car(list);
    UnitTypes[type].Name=gh_scm2newstr(value,NULL);
    list=gh_cdr(list);

    //	Graphics
    value=gh_car(list);

    //	FIXME: more ...

    return list;
}
InputAxis* 
AxisFactory::create(SCM lst)
{
  while(gh_pair_p(lst))
    {
      SCM sym  = gh_car(lst);
      SCM data = gh_cdr(lst);
      
      if (gh_equal_p(sym, gh_symbol2scm("joystick-axis")))
        {
          return create_joystick_axis(data);
        }
      if (gh_equal_p(sym, gh_symbol2scm("button-axis")))
        {
          return create_button_axis(data);
        }
      else
        {
          throw FeuerkraftError("AxisFactory::create: parse error");
        }

      lst = gh_cdr(lst);
    }
  return 0;
}
예제 #3
0
/**
**	Define race mapping from original number to internal symbol
**
**	@param list	List of all names.
*/
local SCM CclDefineRaceWcNames(SCM list)
{
    int i;
    char** cp;

    if( (cp=RaceWcNames) ) {		// Free all old names
	while( *cp ) {
	    free(*cp++);
	}
	free(RaceWcNames);
    }

    //
    //	Get new table.
    //
    i=gh_length(list);
    RaceWcNames=cp=malloc((i+1)*sizeof(char*));
    while( i-- ) {
	*cp++=gh_scm2newstr(gh_car(list),NULL);
	list=gh_cdr(list);
    }
    *cp=NULL;

    return SCM_UNSPECIFIED;
}
GridMapData::GridMapData (SCM desc)
{
  grid_width  = -1;
  grid_height = -1;
  
  while (!gh_null_p (desc))
    {
      SCM symbol = gh_caar(desc);
      SCM data   = gh_cdar(desc);

      if (gh_equal_p (gh_symbol2scm ("file"), symbol))
        {
          parse_from_file (data);
        }
      else
        {
          std::cout << "GridMapData: Unknown data type: '" << std::flush;
          gh_display (symbol);
          std::cout << "' with data: " << std::flush;
          gh_display (data);
          std::cout << std::endl;
          return;
        }

      desc = gh_cdr (desc);
    }
}
예제 #5
0
/**
**	Parse missile-type.
**
**	@param list	List describing missile.
*/
local SCM CclMissileType(SCM list)
{
    SCM value;
    int type;

    //	Slot
    value=gh_car(list);
    type=gh_scm2int(value);
    if( type>=MissileTypeMax ) {
	fprintf(stderr,"Wrong type %d\n",type);
	return list;
    }
    list=gh_cdr(list);
    DebugLevel3("MissileType: %d\n",type);

    //	Name
    value=gh_car(list);
    MissileTypes[type].Name=gh_scm2newstr(value,NULL);
    list=gh_cdr(list);

    //	File
    value=gh_car(list);
    MissileTypes[type].File=gh_scm2newstr(value,NULL);
    list=gh_cdr(list);

    // Width,Height
    value=gh_car(list);
    MissileTypes[type].Width=gh_scm2int(value);
    list=gh_cdr(list);
    value=gh_car(list);
    MissileTypes[type].Height=gh_scm2int(value);
    list=gh_cdr(list);

    // Sound impact
    value=gh_car(list);
#ifdef WITH_SOUND
    if (ccl_sound_p(value)) {
	MissileTypes[type].ImpactSound.Sound=ccl_sound_id(value);
    } else
#endif
    if (!gh_boolean_p(value) ||  gh_scm2bool(value) ) {
	fprintf(stderr,"Wrong argument in MissileType\n");
    }
    list=gh_cdr(list);

    // FIXME: class, speed not written!!!

    return list;
}
예제 #6
0
/**
**	Define the used font colors.
*/
local SCM CclDefineFontColors(SCM list)
{
    int i;
    int j;
    SCM value;
    SCM temp;

    for (i = 0; i < 16; ++i) {
	value = gh_car(list);
	list = gh_cdr(list);

	if (gh_vector_length(value) != 7) {
	    fprintf(stderr, "Wrong vector length\n");
	}
	for (j = 0; j < 7; ++j) {
	    temp = gh_vector_ref(value, gh_int2scm(j));
	    FontColors[i][j] = gh_scm2int(temp);
	}
    }

    return SCM_UNSPECIFIED;
}
int
building_create_type(const char* name, SCM lst)
{
  AList alist;
  
  while(!gh_null_p(lst))
    {
      SCM key   = gh_car(lst);

      if (gh_null_p(gh_cdr(lst)))
        {
          std::cout << "Missing argument to keyword!" << std::endl;
        }

      SCM value = gh_cadr(lst);

      if (gh_boolean_p(value))
        {
          alist.set_bool(Guile::keyword2string(key), gh_scm2bool(value));
        }
      else if (gh_number_p(value))
        {
          alist.set_int(Guile::keyword2string(key), gh_scm2int(value));
        }
      else if (gh_string_p(value))
        {
          alist.set_string(Guile::keyword2string(key), Guile::scm2string(value));
        }
      else
        {
          std::cout << "BuildingCommands: unknown argumnent type" << std::endl;
        }

      lst = gh_cddr(lst);
    }

  return BuildingTypeManager::current()->register_factory(new CustomBuildingFactory(name, alist));
}
예제 #8
0
/**
**	Parse the player configuration.
**
**	@param list	Tagged list of all informations.
*/
local SCM CclPlayer(SCM list)
{
    SCM value;
    SCM sublist;
    Player* player;
    int i;
    char* str;

    i=gh_scm2int(gh_car(list));
    player=&Players[i];
    if( NumPlayers<=i ) {
	NumPlayers=i+1;
    }
    player->Player = i;
    player->Color=PlayerColors[i];
    if( !(player->Units=(Unit**)calloc(UnitMax,sizeof(Unit*))) ) {
	DebugLevel0("Not enough memory to create player %d.\n" _C_ i);

	return SCM_UNSPECIFIED;
    }
    list=gh_cdr(list);

    //
    //	Parse the list:	(still everything could be changed!)
    //
    while( !gh_null_p(list) ) {

	value=gh_car(list);
	list=gh_cdr(list);

	if( gh_eq_p(value,gh_symbol2scm("name")) ) {
	    player->Name=gh_scm2newstr(gh_car(list),NULL);
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("type")) ) {
	    value=gh_car(list);
	    list=gh_cdr(list);
	    if( gh_eq_p(value,gh_symbol2scm("neutral")) ) {
		player->Type=PlayerNeutral;
	    } else if( gh_eq_p(value,gh_symbol2scm("nobody")) ) {
		player->Type=PlayerNobody;
	    } else if( gh_eq_p(value,gh_symbol2scm("computer")) ) {
		player->Type=PlayerComputer;
	    } else if( gh_eq_p(value,gh_symbol2scm("person")) ) {
		player->Type=PlayerPerson;
	    } else if( gh_eq_p(value,gh_symbol2scm("rescue-passive")) ) {
		player->Type=PlayerRescuePassive;
	    } else if( gh_eq_p(value,gh_symbol2scm("rescue-active")) ) {
		player->Type=PlayerRescueActive;
	    } else {
	       // FIXME: this leaves a half initialized player
	       errl("Unsupported tag",value);
	    }
	} else if( gh_eq_p(value,gh_symbol2scm("race")) ) {
	    str=gh_scm2newstr(gh_car(list),NULL);
	    if( RaceWcNames ) {
		for( i=0; RaceWcNames[i]; ++i ) {
		    if( !strcmp(str,RaceWcNames[i]) ) {
			player->RaceName=RaceWcNames[i];
			player->Race=i;
			break;
		    }
		}
	    }
	    free(str);
	    if( !RaceWcNames || !RaceWcNames[i] ) {
	       // FIXME: this leaves a half initialized player
	       errl("Unsupported tag",gh_car(list));
	    }
#if 0
	    player->RaceName=str=gh_scm2newstr(gh_car(list),NULL);
	    if( !strcmp(str,"human") ) {
		player->Race=PlayerRaceHuman;
	    } else if( !strcmp(str,"orc") ) {
		player->Race=PlayerRaceOrc;
	    } else if( !strcmp(str,"neutral") ) {
		player->Race=PlayerRaceNeutral;
	    } else {
	       // FIXME: this leaves a half initialized player
	       errl("Unsupported tag",gh_car(list));
	    }
#endif
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("ai")) ) {
	    player->AiNum=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("team")) ) {
	    player->Team=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("enemy")) ) {
	    str=gh_scm2newstr(gh_car(list),NULL);
	    list=gh_cdr(list);
	    for( i=0; i<PlayerMax && *str; ++i,++str ) {
		if( *str=='-' || *str=='_' || *str==' ' ) {
		    player->Enemy&=~(1<<i);
		} else {
		    player->Enemy|=(1<<i);
		}
	    }
	} else if( gh_eq_p(value,gh_symbol2scm("allied")) ) {
	    str=gh_scm2newstr(gh_car(list),NULL);
	    list=gh_cdr(list);
	    for( i=0; i<PlayerMax && *str; ++i,++str ) {
		if( *str=='-' || *str=='_' || *str==' ' ) {
		    player->Allied&=~(1<<i);
		} else {
		    player->Allied|=(1<<i);
		}
	    }
	} else if( gh_eq_p(value,gh_symbol2scm("shared-vision")) ) {
	    str=gh_scm2newstr(gh_car(list),NULL);
	    list=gh_cdr(list);
	    for( i=0; i<PlayerMax && *str; ++i,++str ) {
		if( *str=='-' || *str=='_' || *str==' ' ) {
		    player->SharedVision&=~(1<<i);
		} else {
		    player->SharedVision|=(1<<i);
		}
	    }
	} else if( gh_eq_p(value,gh_symbol2scm("start")) ) {
	    value=gh_car(list);
	    list=gh_cdr(list);
	    player->StartX=gh_scm2int(gh_car(value));
	    player->StartY=gh_scm2int(gh_cadr(value));
	} else if( gh_eq_p(value,gh_symbol2scm("resources")) ) {
	    sublist=gh_car(list);
	    list=gh_cdr(list);
	    while( !gh_null_p(sublist) ) {

		value=gh_car(sublist);
		sublist=gh_cdr(sublist);

		for( i=0; i<MaxCosts; ++i ) {
		    if( gh_eq_p(value,gh_symbol2scm((char*)DefaultResourceNames[i])) ) {
			player->Resources[i]=gh_scm2int(gh_car(sublist));
			break;
		    }
		}
		if( i==MaxCosts ) {
		   // FIXME: this leaves a half initialized player
		   errl("Unsupported tag",value);
		}
		sublist=gh_cdr(sublist);
	    }
	} else if( gh_eq_p(value,gh_symbol2scm("incomes")) ) {
	    sublist=gh_car(list);
	    list=gh_cdr(list);
	    while( !gh_null_p(sublist) ) {

		value=gh_car(sublist);
		sublist=gh_cdr(sublist);

		for( i=0; i<MaxCosts; ++i ) {
		    if( gh_eq_p(value,gh_symbol2scm((char*)DefaultResourceNames[i])) ) {
			player->Incomes[i]=gh_scm2int(gh_car(sublist));
			break;
		    }
		}
		if( i==MaxCosts ) {
		   // FIXME: this leaves a half initialized player
		   errl("Unsupported tag",value);
		}
		sublist=gh_cdr(sublist);
	    }
	} else if( gh_eq_p(value,gh_symbol2scm("ai-enabled")) ) {
	    player->AiEnabled=1;
	} else if( gh_eq_p(value,gh_symbol2scm("ai-disabled")) ) {
	    player->AiEnabled=0;
	} else if( gh_eq_p(value,gh_symbol2scm("food")) ) {
	    player->Food=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("food-unit-limit")) ) {
	    player->FoodUnitLimit=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("building-limit")) ) {
	    player->BuildingLimit=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("total-unit-limit")) ) {
	    player->TotalUnitLimit=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("score")) ) {
	    player->Score=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("total-units")) ) {
	    player->TotalUnits=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("total-buildings")) ) {
	    player->TotalBuildings=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("total-razings")) ) {
	    player->TotalRazings=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("total-kills")) ) {
	    player->TotalKills=gh_scm2int(gh_car(list));
	    list=gh_cdr(list);
	} else if( gh_eq_p(value,gh_symbol2scm("total-resources")) ) {
	    sublist=gh_car(list);
	    list=gh_cdr(list);
	    i=gh_length(sublist);
	    if( i!=MaxCosts ) {
		fprintf(stderr,"Wrong number of total-resources %d\n",i);
	    }
	    i=0;
	    while( !gh_null_p(sublist) ) {
		if( i<MaxCosts ) {
		    player->TotalResources[i]=gh_scm2int(gh_car(sublist));
		}
		sublist=gh_cdr(sublist);
		++i;
	    }
	    player->TotalUnits=gh_scm2int(gh_car(list));
	} else if( gh_eq_p(value,gh_symbol2scm("timers")) ) {
	    sublist=gh_car(list);
	    list=gh_cdr(list);
	    i=gh_length(sublist);
	    if( i!=UpgradeMax ) {
		fprintf(stderr,"Wrong upgrade timer length %d\n",i);
	    }

	    i=0;
	    while( !gh_null_p(sublist) ) {
		if( i<UpgradeMax ) {
		    player->UpgradeTimers.Upgrades[i]=
			    gh_scm2int(gh_car(sublist));
		}
		sublist=gh_cdr(sublist);
		++i;
	    }
	} else {
	   // FIXME: this leaves a half initialized player
	   errl("Unsupported tag",value);
	}
    }

    return SCM_UNSPECIFIED;
}
예제 #9
0
/**
**	Parse a clone map.
**
**	@param list	list of tuples keyword data
*/
local SCM CclCloneMap(SCM list)
{
    SCM value;
    SCM name;
    SCM data;

    //
    //	Parse the list:	(still everything could be changed!)
    //
    while( !gh_null_p(list) ) {

	value=gh_car(list);
	//gh_display(value);
	//gh_newline();
	if( gh_list_p(value) ) {
	    name=gh_car(value);
	    data=gh_cdr(value);
	    if( !gh_symbol_p(name) ) {
		fprintf(stderr,"symbol expected\n");
		return list;
	    }
	    if( gh_eq_p(name,gh_symbol2scm("version")) ) {
		DebugLevel1("VERSION:\n");
		gh_display(data);
		gh_newline();
		// FIXME:
	    } else if( gh_eq_p(name,gh_symbol2scm("description")) ) {
		DebugLevel1("DESCRIPTION:\n");
		gh_display(data);
		gh_newline();
		// FIXME:
	    } else if( gh_eq_p(name,gh_symbol2scm("terrain")) ) {
		int terrain;

		DebugLevel1("TERRAIN:\n");
		gh_display(data);
		gh_newline();
		value=gh_car(data);
		data=gh_cdr(data);
		terrain=gh_scm2int(value);
		TheMap.Terrain=terrain;
		// FIXME:
	    } else if( gh_eq_p(name,gh_symbol2scm("dimension")) ) {
		int width;
		int height;

		DebugLevel1("DIMENSION:\n");
		gh_display(data);
		gh_newline();
		value=gh_car(data);
		width=gh_scm2int(value);
		data=gh_cdr(data);
		value=gh_car(data);
		height=gh_scm2int(value);
		TheMap.Width=width;
		TheMap.Height=height;

		TheMap.Fields=calloc(width*height,sizeof(*TheMap.Fields));
		InitUnitCache();

	    } else if( gh_eq_p(name,gh_symbol2scm("tiles")) ) {
		int i;
		int l;

		DebugLevel1("TILES:\n");
		value=gh_car(data);
		if( !gh_vector_p(value) ) {
		    fprintf(stderr,"vector expected\n");
		    return SCM_UNSPECIFIED;
		}
		l=gh_vector_length(value);
		if( l!=TheMap.Width*TheMap.Height ) {
		    fprintf(stderr,"Wrong tile table length %d\n",l);
		}
		for( i=0; i<l; ++i ) {
		    TheMap.Fields[i].Tile=
			    Tilesets[TilesetSummer].Table[
				gh_scm2int(gh_vector_ref(value,gh_int2scm(i)))
			    ];
		}
	    } else {
		;
	    }
	} else {
	    fprintf(stderr,"list expected\n");
	    return list;
	}

	list=gh_cdr(list);
    }

    return list;
}
예제 #10
0
/**
**	Parse the construction.
**
**	@param list	List describing the construction.
**
**	@note make this more flexible
*/
local SCM CclDefineConstruction(SCM list)
{
    SCM value;
    SCM sublist;
    char* str;
    Construction* construction;
    Construction** cop;
    int i;

    //	Slot identifier

    str=gh_scm2newstr(gh_car(list),NULL);
    list=gh_cdr(list);

    for( i=0; ConstructionWcNames[i]; ++i ) {
        if( !strcmp(ConstructionWcNames[i],str) ) {
            break;
        }
    }
    if( !ConstructionWcNames[i] ) {
        DebugLevel0Fn("Construction not found.\n");
        free(str);
        return SCM_UNSPECIFIED;
    }

    if( (cop=Constructions)==NULL ) {
        Constructions=malloc(2*sizeof(Construction*));
        Constructions[0]=calloc(1,sizeof(Construction));
        Constructions[1]=NULL;
        construction=Constructions[0];
    } else {
        for( i=0; *cop; ++i,++cop ) {
        }
        Constructions=realloc(Constructions,(i+2)*sizeof(Construction*));
        Constructions[i]=calloc(1,sizeof(Construction));
        Constructions[i+1]=NULL;
        construction=Constructions[i];
    }
    construction->OType=ConstructionType;
    construction->Ident=str;

    //
    //	Parse the arguments, in tagged format.
    //
    while( !gh_null_p(list) ) {
        value=gh_car(list);
        list=gh_cdr(list);
        if( gh_eq_p(value,gh_symbol2scm("files")) ) {
            sublist=gh_car(list);

            //
            //	Parse the tilesets
            //
            while( !gh_null_p(sublist) ) {
                str=gh_scm2newstr(gh_car(sublist),NULL);

                // FIXME: use a general get tileset function here!
                i=0;
                if( strcmp(str,"default") ) {
                    for( ; i<NumTilesets; ++i ) {
                        if( !strcmp(str,Tilesets[i]->Ident) ) {
                            break;
                        }
                        if( !strcmp(str,Tilesets[i]->Class) ) {
                            break;
                        }
                    }
                    if( i==NumTilesets ) {
                        fprintf(stderr,"Tileset `%s' not available\n",str);
                        errl("tileset not available",gh_car(sublist));
                    }
                }
                sublist=gh_cdr(sublist);
                free(str);
                free(construction->File[i]);
                construction->File[i]=gh_scm2newstr(gh_car(sublist),NULL);
                sublist=gh_cdr(sublist);
            }

        } else if( gh_eq_p(value,gh_symbol2scm("size")) ) {
            value=gh_car(list);
            construction->Width=gh_scm2int(gh_car(value));
            value=gh_cdr(value);
            construction->Height=gh_scm2int(gh_car(value));

        } else if( gh_eq_p(value,gh_symbol2scm("shadow")) ) {
            sublist=gh_car(list);
            while( !gh_null_p(sublist) ) {
                value=gh_car(sublist);
                sublist=gh_cdr(sublist);

                if( gh_eq_p(value,gh_symbol2scm("file")) ) {
                    construction->ShadowFile=gh_scm2newstr(gh_car(sublist),NULL);
                } else if( gh_eq_p(value,gh_symbol2scm("width")) ) {
                    construction->ShadowWidth=gh_scm2int(gh_car(sublist));
                } else if( gh_eq_p(value,gh_symbol2scm("height")) ) {
                    construction->ShadowHeight=gh_scm2int(gh_car(sublist));
                } else {
                    errl("Unsupported shadow tag",value);
                }
                sublist=gh_cdr(sublist);
            }
        } else {
            // FIXME: this leaves a half initialized construction
            errl("Unsupported tag",value);
        }
        list=gh_cdr(list);
    }

    return SCM_UNSPECIFIED;
}
예제 #11
0
파일: gh.c 프로젝트: SawfishWM/librep
repv gh_cdddr(repv x)
{
    return gh_cdr (gh_cdr (gh_cdr (x)));
}
예제 #12
0
파일: gh.c 프로젝트: SawfishWM/librep
repv gh_cdadr(repv x)
{
    return gh_cdr (gh_car (gh_cdr (x)));
}