Пример #1
0
std::string Component::getString() {
	// This will hold our return value
	std::string sentence;

	int componentId = _type.getId();

	if (isInverted()) {
		sentence += "do NOT ";
	}

	SpecifierPtr sp1 = getSpecifier(Specifier::FIRST_SPECIFIER);
	SpecifierPtr sp2 = getSpecifier(Specifier::SECOND_SPECIFIER);

	if (componentId == ComponentType::COMP_KILL().getId()) {
		// First add the verb
		sentence += "kill";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_KO().getId()) {
		// First add the verb
		sentence += "knockout";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_AI_FIND_ITEM().getId()) {
		// First add the verb
		sentence += "let AI find item:";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_AI_FIND_BODY().getId()) {
		sentence += "let AI find body:";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";

		sentence += " (amount: " + getArgument(0) + ")";
	}
	else if (componentId == ComponentType::COMP_ALERT().getId()) {
		sentence += "alert";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";

		// Add the alert level info
		sentence += " " + getArgument(0) + " times to a minimum alert level of " + getArgument(1);
	}
	else if (componentId == ComponentType::COMP_DESTROY().getId()) {
		sentence += "destroy";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_ITEM().getId()) {
		sentence += "acquire";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_PICKPOCKET().getId()) {
		sentence += "pickpocket";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_LOCATION().getId()) {
		sentence += "let the target";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";

		sentence += " be at location";
		sentence += (sp2) ? (" " + sp2->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_INFO_LOCATION().getId()) {
		sentence += "let the target";

		// Add the Specifier details, if any
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";

		sentence += " be at info_location";
		sentence += (sp2) ? (" " + sp2->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_CUSTOM_ASYNC().getId()) {
		sentence += "controlled by external script";
	}
	else if (componentId == ComponentType::COMP_CUSTOM_CLOCKED().getId()) {
		sentence += "call the script function ";
		sentence += getArgument(0);
	}
	else if (componentId == ComponentType::COMP_DISTANCE().getId()) {
		sentence += "let the entities " + getArgument(0);
		sentence += " and " + getArgument(1) + " get closer than ";
		sentence += getArgument(2) + " units";
	}
	else if (componentId == ComponentType::COMP_READABLE_OPENED().getId())
	{
		sentence += "open the readable ";
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_READABLE_CLOSED().getId())
	{
		sentence += "close the readable ";
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}
	else if (componentId == ComponentType::COMP_READABLE_PAGE_REACHED().getId())
	{
		sentence += "view page " + getArgument(0) + " of readable ";
		sentence += (sp1) ? (" " + sp1->getSentence(*this)) : "";
	}

	if (getClockInterval() > 0) {
		sentence += " (check interval: " + string::to_string(getClockInterval()) + " seconds)";
	}

	// Convert the first character of the sentence to upper case
	if (!sentence.empty()) {
		std::string c(sentence.begin(), sentence.begin()+1);
		sentence[0] = string::to_upper_copy(c)[0];

		// Append a full stop at the end of the sentence
		if (sentence[sentence.length() - 1] != '.') {
			sentence.append(".");
		}
	}

	// Replace all double-space characters with one single space
	string::replace_all(sentence, "  ", " ");

    return sentence;
}
Пример #2
0
int main(int argc, char *argv[] )
{
	/*** get calling argument ***/
  	char *filePrefix;
	getArgument(argc, argv, &filePrefix); /* check argument and set filePrefix if needed */

	/*** input and output file pointers ***/
	FILE *fpInput;
	FILE *fpOutput;

	/*** input and output buffers ***/
	word32_t reflectionCoefficient; /* in Q31 */
	word16_t LSFCoefficients[NB_LSP_COEFF];
	int16_t autocorrelationExponent;
	word32_t autocorrelationCoefficients[NB_LSP_COEFF+3];
	word16_t signalBuffer[82]; /* used for input and output, in Q0 */

	/*** inits ***/
	/* open the input file */
	if ( (fpInput = fopen(argv[1], "r")) == NULL) {
		printf("%s - Error: can't open file  %s\n", argv[0], argv[1]);
		exit(-1);
	}

	/* create the output file(filename is the same than input file with the .out extension) */
	char *outputFile = malloc((strlen(filePrefix)+5)*sizeof(char));
	sprintf(outputFile, "%s.out",filePrefix);
	if ( (fpOutput = fopen(outputFile, "w")) == NULL) {
		printf("%s - Error: can't create file  %s\n", argv[0], outputFile);
		exit(-1);
	}
	
	/*** init of the tested bloc ***/
	bcg729VADChannelContextStruct *VADChannelContext = initBcg729VADChannel();

	/*** initialisation complete ***/


	/*** loop over input file ***/
	while(1) /* infinite loop, escape condition is in the reading of data */
	{
		int i;
		uint8_t vad;

		/* read the input data until we have some */
		if (fscanf(fpInput,"%d",&reflectionCoefficient) != 1) break;
		for (i=0; i<10; i++) {
			if (fscanf(fpInput,",%hd",(int16_t *)&(LSFCoefficients[i])) != 1) break;
		}
		if (fscanf(fpInput,",%hd",&autocorrelationExponent) != 1) break;
		for (i=0; i<13; i++) {
			if (fscanf(fpInput,",%d",&(autocorrelationCoefficients[i])) != 1) break;
		}
		for (i=0; i<82; i++) {
			if (fscanf(fpInput,",%hd",(int16_t *)&(signalBuffer[i])) != 1) break;
		}

		/* call the tested function: output will replace the input in the buffer */
		vad = bcg729_vad(VADChannelContext, reflectionCoefficient, LSFCoefficients, autocorrelationCoefficients, autocorrelationExponent, &(signalBuffer[1]));

		/* write the output to the output file */
		//fprintf(fpOutput,"%d", (int16_t)randomGeneratorSeed);
		fprintf(fpOutput,"%d\n", vad);

	}
	exit (0);
}
varInst *Mission::call_omap(missionNode *node,int mode){

  //varInst *viret=new varInst;
  varInst *viret=NULL;

  if(mode==SCRIPT_PARSE){
    string cmd=node->attr_value("name");
    node->script.method_id=module_omap_map[cmd];
  }

   callback_module_omap_type method_id=(callback_module_omap_type) node->script.method_id;


  if(method_id==CMT_OMAP_new){
    
    viret=call_omap_new(node,mode);

    return viret;
  }
  else{
    varInst *ovi=getObjectArg(node,mode);
    omap_t *my_object=getOMapObject(node,mode,ovi);

    if(method_id==CMT_OMAP_delete){
      if(mode==SCRIPT_RUN){

	omap_t::iterator iter;

	for(iter=my_object->begin();iter!=my_object->end();iter++){
	  string varname=(*iter).first ;
	  varInst *vi=(*iter).second;
	  deleteVarInst(vi,true);
	}
	my_object->clear();
	delete my_object;
      }
      viret=newVarInst(VI_TEMP);
      viret->type=VAR_VOID;
    }
    else if(method_id==CMT_OMAP_set){
      missionNode *snode=getArgument(node,mode,2);
      //varInst *vi=doVariable(snode,mode); // should be getObjExpr
      varInst *var_vi=checkExpression(snode,mode); // should be getObjExpr
      
      string name=getStringArgument(node,mode,1);

      debug(3,node,mode,"omap set");

      if(mode==SCRIPT_RUN){
	varInst *push_vi=newVarInst(VI_IN_OBJECT);
	push_vi->type=var_vi->type;
	assignVariable(push_vi,var_vi);

	(*my_object)[name]=push_vi;
	//printf("setting [%s] type %d\n",name.c_str(),push_vi->type);
      }

      deleteVarInst(var_vi);
      viret=newVarInst(VI_TEMP);
      viret->type=VAR_VOID;
      //return viret;
    }
    else if(method_id==CMT_OMAP_get){
      debug(3,node,mode,"omap.get");

      string name=getStringArgument(node,mode,1);

      viret=newVarInst(VI_TEMP);
      viret->type=VAR_ANY;

      if(mode==SCRIPT_RUN){
	varInst *back_vi=(*my_object)[name];
	assignVariable(viret,back_vi);
	//	printf("viret type=%d back_vi type=%d\n",viret->type,back_vi->type);
	if(back_vi->type>10){
	  assert(0);
	}
	deleteVarInst(back_vi); // this won't delete it
      }
    }
    else if(method_id==CMT_OMAP_toxml){
      if(node->subnodes.size()!=1){
	fatalError(node,mode,"olist.toxml needs no arguments");
	assert(0);
      }

      debug(3,node,mode,"omap.toxml");

      if(mode==SCRIPT_RUN){
	//call_olist_toxml(node,mode,ovi);
      }

      viret =newVarInst(VI_TEMP);
      viret->type=VAR_VOID;
    }
    else if(method_id==CMT_OMAP_size){
      if(node->subnodes.size()!=1){
	fatalError(node,mode,"olist.size needs one arguments");
	assert(0);
      }

      debug(3,node,mode,"omap.size");

      viret=newVarInst(VI_TEMP);

      if(mode==SCRIPT_RUN){
	int len=my_object->size();
	viret->int_val=len;
      }

      viret->type=VAR_INT;
      //return viret;
    }
    else{
      fatalError(node,mode,"unknown command "+node->script.name+" for callback omap");
      assert(0);
    }
    
    deleteVarInst(ovi);
    return viret;
  } // else (objects)

  return NULL; // never reach
}
Пример #4
0
Options::Status Options::parse(int argc, const char **argv) {
    bool test = false;
    bool recursive = false;
    bool ultra = false;
    bool forceStdout = false;
    // Local copy of input files, which are pointers into argv.
    std::vector<const char *> localInputFiles;
    for (int i = 1; i < argc; ++i) {
        const char *arg = argv[i];
        // Protect against empty arguments
        if (arg[0] == 0) {
            continue;
        }
        // Everything after "--" is an input file
        if (!std::strcmp(arg, "--")) {
            ++i;
            std::copy(argv + i, argv + argc, std::back_inserter(localInputFiles));
            break;
        }
        // Long arguments that don't have a short option
        {
            bool isLongOption = true;
            if (!std::strcmp(arg, "--rm")) {
                keepSource = false;
            } else if (!std::strcmp(arg, "--ultra")) {
                ultra = true;
                maxWindowLog = 0;
            } else if (!std::strcmp(arg, "--no-check")) {
                checksum = false;
            } else if (!std::strcmp(arg, "--sparse")) {
                writeMode = WriteMode::Sparse;
                notSupported("Sparse mode");
                return Status::Failure;
            } else if (!std::strcmp(arg, "--no-sparse")) {
                writeMode = WriteMode::Regular;
                notSupported("Sparse mode");
                return Status::Failure;
            } else if (!std::strcmp(arg, "--dictID")) {
                notSupported(arg);
                return Status::Failure;
            } else if (!std::strcmp(arg, "--no-dictID")) {
                notSupported(arg);
                return Status::Failure;
            } else {
                isLongOption = false;
            }
            if (isLongOption) {
                continue;
            }
        }
        // Arguments with a short option simply set their short option.
        const char *options = nullptr;
        if (!std::strcmp(arg, "--processes")) {
            options = "p";
        } else if (!std::strcmp(arg, "--version")) {
            options = "V";
        } else if (!std::strcmp(arg, "--help")) {
            options = "h";
        } else if (!std::strcmp(arg, "--decompress")) {
            options = "d";
        } else if (!std::strcmp(arg, "--force")) {
            options = "f";
        } else if (!std::strcmp(arg, "--stdout")) {
            options = "c";
        } else if (!std::strcmp(arg, "--keep")) {
            options = "k";
        } else if (!std::strcmp(arg, "--verbose")) {
            options = "v";
        } else if (!std::strcmp(arg, "--quiet")) {
            options = "q";
        } else if (!std::strcmp(arg, "--check")) {
            options = "C";
        } else if (!std::strcmp(arg, "--test")) {
            options = "t";
        } else if (arg[0] == '-' && arg[1] != 0) {
            options = arg + 1;
        } else {
            localInputFiles.emplace_back(arg);
            continue;
        }
        assert(options != nullptr);

        bool finished = false;
        while (!finished && *options != 0) {
            // Parse the compression level
            if (*options >= '0' && *options <= '9') {
                compressionLevel = parseUnsigned(&options);
                continue;
            }

            switch (*options) {
            case 'h':
            case 'H':
                usage();
                return Status::Message;
            case 'V':
                std::fprintf(stderr, "PZSTD version: %s.\n", ZSTD_VERSION_STRING);
                return Status::Message;
            case 'p': {
                finished = true;
                const char *optionArgument = getArgument(options, argv, i, argc);
                if (optionArgument == nullptr) {
                    return Status::Failure;
                }
                if (*optionArgument < '0' || *optionArgument > '9') {
                    std::fprintf(stderr, "Option -p expects a number, but %s provided\n",
                                 optionArgument);
                    return Status::Failure;
                }
                numThreads = parseUnsigned(&optionArgument);
                if (*optionArgument != 0) {
                    std::fprintf(stderr,
                                 "Option -p expects a number, but %u%s provided\n",
                                 numThreads, optionArgument);
                    return Status::Failure;
                }
                break;
            }
            case 'o': {
                finished = true;
                const char *optionArgument = getArgument(options, argv, i, argc);
                if (optionArgument == nullptr) {
                    return Status::Failure;
                }
                outputFile = optionArgument;
                break;
            }
            case 'C':
                checksum = true;
                break;
            case 'k':
                keepSource = true;
                break;
            case 'd':
                decompress = true;
                break;
            case 'f':
                overwrite = true;
                forceStdout = true;
                break;
            case 't':
                test = true;
                decompress = true;
                break;
#ifdef UTIL_HAS_CREATEFILELIST
            case 'r':
                recursive = true;
                break;
#endif
            case 'c':
                outputFile = kStdOut;
                forceStdout = true;
                break;
            case 'v':
                ++verbosity;
                break;
            case 'q':
                --verbosity;
                // Ignore them for now
                break;
            // Unsupported options from Zstd
            case 'D':
            case 's':
                notSupported("Zstd dictionaries.");
                return Status::Failure;
            case 'b':
            case 'e':
            case 'i':
            case 'B':
                notSupported("Zstd benchmarking options.");
                return Status::Failure;
            default:
                std::fprintf(stderr, "Invalid argument: %s\n", arg);
                return Status::Failure;
            }
            if (!finished) {
                ++options;
            }
        } // while (*options != 0);
    }   // for (int i = 1; i < argc; ++i);

    // Input file defaults to standard input if not provided.
    if (localInputFiles.empty()) {
        localInputFiles.emplace_back(kStdIn);
    }

    // Check validity of input files
    if (localInputFiles.size() > 1) {
        const auto it = std::find(localInputFiles.begin(), localInputFiles.end(),
                                  std::string{kStdIn});
        if (it != localInputFiles.end()) {
            std::fprintf(
                stderr,
                "Cannot specify standard input when handling multiple files\n");
            return Status::Failure;
        }
    }
    if (localInputFiles.size() > 1 || recursive) {
        if (!outputFile.empty() && outputFile != nullOutput) {
            std::fprintf(
                stderr,
                "Cannot specify an output file when handling multiple inputs\n");
            return Status::Failure;
        }
    }

    // Translate input files/directories into files to (de)compress
    if (recursive) {
        char *scratchBuffer = nullptr;
        unsigned numFiles = 0;
        const char **files =
            UTIL_createFileList(localInputFiles.data(), localInputFiles.size(),
                                &scratchBuffer, &numFiles);
        if (files == nullptr) {
            std::fprintf(stderr, "Error traversing directories\n");
            return Status::Failure;
        }
        auto guard =
            makeScopeGuard([&] { UTIL_freeFileList(files, scratchBuffer); });
        if (numFiles == 0) {
            std::fprintf(stderr, "No files found\n");
            return Status::Failure;
        }
        inputFiles.resize(numFiles);
        std::copy(files, files + numFiles, inputFiles.begin());
    } else {
        inputFiles.resize(localInputFiles.size());
        std::copy(localInputFiles.begin(), localInputFiles.end(),
                  inputFiles.begin());
    }
    localInputFiles.clear();
    assert(!inputFiles.empty());

    // If reading from standard input, default to standard output
    if (inputFiles[0] == kStdIn && outputFile.empty()) {
        assert(inputFiles.size() == 1);
        outputFile = "-";
    }

    if (inputFiles[0] == kStdIn && IS_CONSOLE(stdin)) {
        assert(inputFiles.size() == 1);
        std::fprintf(stderr, "Cannot read input from interactive console\n");
        return Status::Failure;
    }
    if (outputFile == "-" && IS_CONSOLE(stdout) && !(forceStdout && decompress)) {
        std::fprintf(stderr, "Will not write to console stdout unless -c or -f is "
                     "specified and decompressing\n");
        return Status::Failure;
    }

    // Check compression level
    {
        unsigned maxCLevel =
            ultra ? ZSTD_maxCLevel() : kMaxNonUltraCompressionLevel;
        if (compressionLevel > maxCLevel || compressionLevel == 0) {
            std::fprintf(stderr, "Invalid compression level %u.\n", compressionLevel);
            return Status::Failure;
        }
    }

    // Check that numThreads is set
    if (numThreads == 0) {
        std::fprintf(stderr, "Invalid arguments: # of threads not specified "
                     "and unable to determine hardware concurrency.\n");
        return Status::Failure;
    }

    // Modify verbosity
    // If we are piping input and output, turn off interaction
    if (inputFiles[0] == kStdIn && outputFile == kStdOut && verbosity == 2) {
        verbosity = 1;
    }
    // If we are in multi-file mode, turn off interaction
    if (inputFiles.size() > 1 && verbosity == 2) {
        verbosity = 1;
    }

    // Set options for test mode
    if (test) {
        outputFile = nullOutput;
        keepSource = true;
    }
    return Status::Success;
}
void ProcessRobotState::execute()
{
	std::string const & aDestination = getArgument("RoutingID");
	if (not m_game->getHasRobotById(aDestination))
	{
		ORWELL_LOG_WARN("This is an invalid destination: " << aDestination);
		return;
	}
	orwell::messages::ServerRobotState const & aRobotStateMsg = static_cast<orwell::messages::ServerRobotState const & >(*m_msg);

	//ORWELL_LOG_INFO("ProcessRobotState::execute : simple relay");

	for (int i = 0; i < aRobotStateMsg.rfid_size() ; ++i)
	{
		std::shared_ptr< orwell::game::Item > aItem = game::Item::GetItemByRfid(aRobotStateMsg.rfid(i).rfid());
		if (not aItem)
		{
			continue;
		}
		switch (aRobotStateMsg.rfid(i).status())
		{
		case messages::Status::ON :
			ORWELL_LOG_INFO("Robot " << aDestination <<
					" records contact with RFID " << aRobotStateMsg.rfid(i).rfid() <<
					" at " << aRobotStateMsg.rfid(i).timestamp());
			m_game->robotIsInContactWith(aDestination, aItem);
			break;
		case messages::Status::OFF :
			ORWELL_LOG_INFO("Robot " << aDestination <<
					" stops contact with RFID " << aRobotStateMsg.rfid(i).rfid() <<
					" at " << aRobotStateMsg.rfid(i).timestamp());
			m_game->robotDropsContactWith(aDestination, aItem);
			break;
		}
	}
	for (int i = 0; i < aRobotStateMsg.colour_size() ; ++i)
	{
		std::shared_ptr< orwell::game::Item > aItem = game::Item::GetItemByColor(aRobotStateMsg.colour(i).colour());
		if (not aItem)
		{
			continue;
		}
		switch (aRobotStateMsg.colour(i).status())
		{
		case messages::Status::ON :
			ORWELL_LOG_INFO("Robot " << aDestination <<
					" records contact with Colour tag " << aRobotStateMsg.colour(i).colour() <<
					" at " << aRobotStateMsg.colour(i).timestamp());
			m_game->robotIsInContactWith(aDestination, aItem);
			break;
		case messages::Status::OFF :
			ORWELL_LOG_INFO("Robot " << aDestination <<
					" stops contact with Colour tag " << aRobotStateMsg.colour(i).colour() <<
					" at " << aRobotStateMsg.colour(i).timestamp());
			m_game->robotDropsContactWith(aDestination, aItem);
			break;
		}
	}

	//todo : what do we forward to the player ?
	// forward this message to each controler
	//RawMessage aForward(aDestination, "RobotState", aRobotStateMsg.SerializeAsString());
	//m_publisher->send( aForward );
}