There's a lot wrong with C++. Frankly, the primary positive thing about the language is its templates allow far more abstract programming than any other major computer language. Unfortunately, that feature is typically underused (as it is here), and weaker portions are used instead.I wee'd too early. I'm really spoiled by high level languages. Something as simple as putting a message that says "I'm now considering Agriculture" into my log turned out to be too much for me.
So, this is what I want to do: in the beginning of the loop of bestTech, I want to log what tech is currently being considered. This is where the trouble started. There is no getter for getting the tech's name. Instead of writing that, I decided to go with the tech's quote, which should make it perfectly obvious what tech the AI is looking at as well. So merrily I went about logging the current tech's getQuote... when I ran into a problem of converting from one char type to another.
ONE CHAR TYPE TO ANOTHER? What the hell is wrong with C++!
Anyhoo, I googled, and I've read things for hours, and my brain hurts and I can't figure this out, so I thought I'd ask for help again (maybe someone other than Kael? I would hate to take away time from Fire's completion).
This is my error:
CvPlayerAI.cpp:2072: error C2664: 'CvDLLUtilityIFaceBase::logMsg' : cannot convert parameter 2 from 'const wchar *' to 'const TCHAR *'
:: === Build finished: 1 errors, 0 warnings ===
Now I've googled, and I've found out that TCHAR is MS's magical way of saying "char if it's not a unicode environment, wchar_t if it is". (Right so far? :/) I'm really not sure what logMsg does expect. A simple ascii string would make most sense, of course. I've tried a LOT of things until I've at least found one way to get it to compile:
Code:char temp; temp = CHAR(GC.getTechInfo((TechTypes)iI).getQuote()); gDLL->logMsg("mylog.log", &temp);
However, this ends me up with broken characters in my log, so straight CHAR conversion doesn't seem to work.
Can someone tell me off the top of their head what the conversion I'm looking for is? I've wrestled with wcstombs, but it's stronger than me. And probably not what I'm looking for anyway. Help?
Let me go through this in detail (first with what is actually happening):
Code:
char temp;
Code:
temp = CHAR(GC.getTechInfo((TechTypes)iI).getQuote());
CHAR() is a function that performs conversion into a single (8-bit) character from a wchar (actually, I'm not certain of this; this function is a pain to look up via a web interface, which is what I have here). This conversion looses most (or all) of your information (and should return a warning).
Code:
gDLL->logMsg("mylog.log", &temp);
So this code successfully prints out some of the execution code (and one desired byte) as the log string. How do we get what you want? 2 options I can see, I'll spout the easier one. (Note that wcstombs can work, but it's kind of ugly.)
Asuming that the objective is to convert wchar * to char *, I'd probably use wstring.
So the code would look like this:
Code:
wchar wztemp[1024];
temp = GC.getTechInfo((TechTypes)iI).getQuote();
wstring wstemp = wztemp; // I'm not certain how well this conversion works. you may need to use this instead: wstring wstemp = (wchar *)wztemp;
gDLL->logMsg("mylog.log", wstemp.c_str());
Or you could remove the code in the middle; part of the conversion is already written:
Code:
wstring wstemp;
wstemp = GC.getTechInfo((TechTypes)iI).pyGetQuote();
gDLL->logMsg("mylog.log", wstemp.c_str());
Note that in either of these cases, is #include <string> is not before the given code, you'll need it. It appears that this is included everywhere here, so I don't think that this is an issue.
The final thing to note is that you can get the name; it's just called a description. For example, try:
Code:
wstring wstemp;
wstemp = GC.getTechInfo((TechTypes)iI).pyGetDescription();
gDLL->logMsg("mylog.log", wstemp.c_str());