| 1336 | #endif |
| 1337 | |
| 1338 | void modifyvar(const char *name, int arg, char op) |
| 1339 | { |
| 1340 | ident *id = idents->access(name); |
| 1341 | if(!id) return; |
| 1342 | if(identaccessdenied(id)) |
| 1343 | { |
| 1344 | conoutf("not allowed in this execution context: %s", id->name); |
| 1345 | scripterr(); |
| 1346 | return; |
| 1347 | } |
| 1348 | if((id->type == ID_VAR && id->minval > id->maxval) || (id->type == ID_FVAR && id->minvalf > id->maxvalf)) { conoutf("variable %s is read-only", id->name); return; } |
| 1349 | int val = 0; |
| 1350 | switch(id->type) |
| 1351 | { |
| 1352 | case ID_VAR: val = *id->storage.i; break; |
| 1353 | case ID_FVAR: val = int(*id->storage.f); break; |
| 1354 | case ID_SVAR: { { if(id->getfun) ((void (__cdecl *)())id->getfun)(); } val = ATOI(*id->storage.s); break; } |
| 1355 | case ID_ALIAS: val = ATOI(id->action); break; |
| 1356 | default: return; |
| 1357 | } |
| 1358 | switch(op) |
| 1359 | { |
| 1360 | case '+': val += arg; break; |
| 1361 | case '-': val -= arg; break; |
| 1362 | case '*': val *= arg; break; |
| 1363 | case '/': val = arg ? val / arg : 0; break; |
| 1364 | } |
| 1365 | switch(id->type) |
| 1366 | { |
| 1367 | case ID_VAR: *id->storage.i = clamp(val, id->minval, id->maxval); break; |
| 1368 | case ID_FVAR: *id->storage.f = clamp((float)val, id->minvalf, id->maxvalf); break; |
| 1369 | case ID_SVAR: { string str; itoa(str, val); *id->storage.s = exchangestr(*id->storage.s, str); break; } |
| 1370 | case ID_ALIAS: { string str; itoa(str, val); alias(name, str); return; } |
| 1371 | } |
| 1372 | if(id->fun) ((void (__cdecl *)())id->fun)(); |
| 1373 | } |
| 1374 | |
| 1375 | void addeq(char *name, int *arg) { modifyvar(name, *arg, '+'); } COMMANDN(+=, addeq, "si"); |
| 1376 | void subeq(char *name, int *arg) { modifyvar(name, *arg, '-'); } COMMANDN(-=, subeq, "si"); |
no test coverage detected