/** ** 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; }
/** ** 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; }
void GridMapData::parse_from_file (SCM desc) { /* GridMaps will always get a one pixel boarder with the base enviroment */ char* str = gh_scm2newstr(gh_car (desc), 0); std::cout << "Loading from: " << str << std::endl; std::string filename = str; #ifndef WIN32 free (str); #endif provider = CL_PNGProvider (path_manager.complete("missions/" + filename)); provider.lock (); //FIXME:Display2 assert (provider.is_indexed ()); grid_width = provider.get_width () + 2; grid_height = provider.get_height () + 2; grid_data.resize (grid_width * grid_height); for (int i = 0; i < grid_height * grid_width; ++i) grid_data[i] = GT_SAND; // FIXME: should be variable not hardcoded! unsigned char* buffer = static_cast<unsigned char*>(provider.get_data ()); for (int y = 0; y < provider.get_height (); ++y) for (int x = 0; x < provider.get_width (); ++x) grid_data[(x + 1) + ((y+1) * grid_width)] = static_cast<GroundType>(buffer[x + (provider.get_width () * y)]); provider.unlock (); }
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; }
/** ** Dump some AI debug informations. ** ** @param l Lua state. */ static int CclAiDump(lua_State *l) { LuaCheckArgs(l, 0); // // Script // printf("------\n"); for (int i = 0; i < MaxCosts; ++i) { printf("%s(%4d) ", DefaultResourceNames[i].c_str(), AiPlayer->Player->Resources[i]); } printf("\n"); printf("%d:", AiPlayer->Player->Index); #if 0 gh_display(gh_car(AiPlayer->Script)); #endif // // Requests // size_t n = AiPlayer->UnitTypeRequests.size(); printf("UnitTypeRequests(%u):\n", static_cast<unsigned int>(n)); for (size_t i = 0; i < n; ++i) { printf("%s ", AiPlayer->UnitTypeRequests[i].Type->Ident.c_str()); } printf("\n"); n = AiPlayer->UpgradeToRequests.size(); printf("UpgradeToRequests(%u):\n", static_cast<unsigned int>(n)); for (size_t i = 0; i < n; ++i) { printf("%s ", AiPlayer->UpgradeToRequests[i]->Ident.c_str()); } printf("\n"); n = AiPlayer->ResearchRequests.size(); printf("ResearchRequests(%u):\n", static_cast<unsigned int>(n)); for (size_t i = 0; i < n; ++i) { printf("%s ", AiPlayer->ResearchRequests[i]->Ident.c_str()); } printf("\n"); // Building queue printf("Building queue:\n"); for (size_t i = 0; i < AiPlayer->UnitTypeBuilt.size(); ++i) { const AiBuildQueue &queue = AiPlayer->UnitTypeBuilt[i]; printf("%s(%d/%d) ", queue.Type->Ident.c_str(), queue.Made, queue.Want); } printf("\n"); // PrintForce for (size_t i = 0; i < AiPlayer->Force.Size(); ++i) { printf("Force(%u%s%s):\n", static_cast<unsigned int>(i), AiPlayer->Force[i].Completed ? ",complete" : ",recruit", AiPlayer->Force[i].Attacking ? ",attack" : ""); for (size_t j = 0; j < AiPlayer->Force[i].UnitTypes.size(); ++j) { const AiUnitType &aut = AiPlayer->Force[i].UnitTypes[j]; printf("%s(%d) ", aut.Type->Ident.c_str(), aut.Want); } printf("\n"); } lua_pushboolean(l, 0); return 1; }
InputAxis* AxisFactory::create_button_axis(SCM lst) { InputButton* left = ButtonFactory::create(gh_car(lst)); InputButton* right = ButtonFactory::create(gh_cadr(lst)); return new ButtonAxis(left, right); }
InputAxis* AxisFactory::create_joystick_axis(SCM lst) { int device_num = gh_scm2int(gh_car(lst)); int axis_num = gh_scm2int(gh_cadr(lst)); if (device_num >= 0 && device_num < CL_Joystick::get_device_count()) return new InputAxisInputDevice(CL_Joystick::get_device(device_num), axis_num); else { throw FeuerkraftError("Error: AxisFactory::create_joystick_axis: " + Guile::scm2string(lst)); return 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; }
/** ** 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)); }
/** ** 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; }
/** ** 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; }
/** ** 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; }
repv gh_cddar(repv x) { return gh_cdr (gh_cdr (gh_car (x))); }
repv gh_caaar(repv x) { return gh_car (gh_car (gh_car (x))); }