senarioCtrl.cpp

00001 /*
00002   シナリオ処理
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "senarioCtrl.h"
00008 #include <string.h>
00009 #include <stdlib.h>
00010 
00011 #define PARSE_DELIM " \t\n"
00012 
00013 
00014 SenarioCtrl::SenarioCtrl(void) : isLoaded(false) {
00015 }
00016 
00017 
00018 void SenarioCtrl::loadFile(const char *fileName) {
00019   
00020   FILE *fd = fopen(fileName, "r");
00021   if (fd == NULL) {
00022     //perror(fileName);
00023     return;
00024   }
00025   
00026   // シナリオファイルを解析
00027   char buffer[SENARIO_FILE_WIDTH_MAX];
00028   while (fgets(buffer, SENARIO_FILE_WIDTH_MAX-1,fd) > 0) {
00029     if ((buffer[0] == '#') || (strlen(buffer) <= 1)) {
00030       continue;
00031     }
00032 
00033     char *tok = strtok(buffer, PARSE_DELIM);
00034     if (!strcmp(tok, "MAP:")) {
00035       field.w = atoi(strtok(NULL, PARSE_DELIM));
00036       field.h = atoi(strtok(NULL, PARSE_DELIM"x"));
00037 
00038     } else if (!strcmp(tok, "UNIT:")) {
00039       char *unit_file = strtok(NULL, PARSE_DELIM);
00040       char *dir_delim = rindex(fileName, '/');
00041       char *file_path = unit_file;
00042       if (dir_delim != NULL) {
00043         int dir_path_length = dir_delim - fileName + 1;
00044         file_path = (char *)malloc(strlen(unit_file) + dir_path_length + 1);
00045         strncpy(file_path, fileName, dir_path_length);
00046         strcpy(&file_path[dir_path_length], unit_file);
00047       }
00048       //fprintf(stderr, "file_path: %s\n", file_path);
00049       UnitCtrl::loadFile(units, file_path);
00050     }
00051   }
00052 
00053   isLoaded = true;
00054   fclose(fd);
00055 }
00056 
00057 
00058 void SenarioCtrl::tickDown(void) {
00059 }
00060 
00061 
00062 void SenarioCtrl::setUserInput(UserInput ui) {
00063 }
00064 

Generated on Mon Apr 13 22:52:01 2009 by  doxygen 1.5.7.1