-
Notifications
You must be signed in to change notification settings - Fork 8
Change start command to take strings #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This makes it possible to execute the start command like this:
/start castle dm ffa duel
Most modes have an alias, like dm for deathmatch. The old way of using
this command with numbers still works, but the difference is that the
command takes strings instead of numbers for mode and muts. This
probably doesn't make any difference since types are implicitly
converted in cubescript.
|
How about (as an alternative) using the existing commands like |
|
maybe instead call it |
|
I'm not so sure about my initial assumption any more. Looks like this new command does not use the voting system. But... maybe it should? I would enjoy being able to vote my favorite modes properly using the commands. |
They use the |
This allows mixing numeric and names.
This makes it possible to use those commands and easily specify additional mutators as argument using strings.
|
In these latest commits I have made it possible to use strings with |
|
I'm sure @MoonPadUSer can assist with that. |
|
@robalni you can get the number of arguments in cubescript by using |
|
I know how to get the number of arguments. What I tried to do was to get a list of the arguments in a short way. |
|
You mean smth else than doing ? |
|
The best would be something to put instead of |
|
Keeping them short is not as much of a priority as being able to use them without |
|
I made a command that returns a list of all arguments. I don't understand cubescript very well but I got it to work after a bit of brute force. :) |
|
I just checked the cubescript code and it looks ok, no complaints from my side |
| { | ||
| nextmode = atoi(mode_str); | ||
| } | ||
| else if(mode_str && *mode_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer proper pointer comparisons. Please replace with e.g.,
| else if(mode_str && *mode_str) | |
| else if(mode_str != nullptr && *mode_str != '\0') |
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually try to follow the existing style when I write code. What are we trying to do here? Are we trying to change the style of the code? Then what's the new style that we should follow?
| {"bb", G_BOMBER}, | ||
| {"race", G_RACE}, | ||
| }; | ||
| static const struct {const char *name; int val; int modes;} mut_names[] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be a struct array. Come on, we've got the power of C++ 11/14. Why not make it an std::set<std::string, std::pair<size_t, size_t>> or so? There is really no reason to use anonymous structs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a struct array? I like it when code is simple and easy to understand. Why should I put a wrapper around my char array (called std::string) that might allocate it on the heap and do some other undefined things when I don't need that? And why should I do similar thing with the whole array? It might even be slower. I never add things to these arrays either so they don't need to grow. They are just static data.
| else if(mode_str && *mode_str) | ||
| { | ||
| bool found_one = false; | ||
| for(auto possible_mode : mode_names) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be const auto or even const auto&.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a proper map will also eliminate the need to implement a custom linear search. If you wanted, you could've even used std::find_if here if you used an std::vector.
| } | ||
| //ICOMMAND(0, sendmap, "", (), sendmap()); | ||
|
|
||
| static void startcmd(char *map, char *mode_str, char *muts_str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could likely use std::string instead of these char arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could but that doesn't give me any benefit. The only change it would make is that I would have to type ".c_str()" more inside the function. (ok maybe I can skip a strcmp)
This makes it possible to execute the start command like this:
Most modes have an alias, like dm for deathmatch. The old way of using
this command with numbers still works, but the difference is that the
command takes strings instead of numbers for mode and muts. This
probably doesn't make any difference since types are implicitly
converted in cubescript.